summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim van der Riet <kpvdr@apache.org>2013-02-28 16:14:30 +0000
committerKim van der Riet <kpvdr@apache.org>2013-02-28 16:14:30 +0000
commit9c73ef7a5ac10acd6a50d5d52bd721fc2faa5919 (patch)
tree2a890e1df09e5b896a9b4168a7b22648f559a1f2
parent172d9b2a16cfb817bbe632d050acba7e31401cd2 (diff)
downloadqpid-python-asyncstore.tar.gz
Update from trunk r1375509 through r1450773asyncstore
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/asyncstore@1451244 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--KEYS55
-rw-r--r--QPID_VERSION.txt2
-rwxr-xr-xbin/release.sh29
-rw-r--r--cpp/BuildInstallSettings.cmake316
-rw-r--r--cpp/CMakeLists.txt35
-rw-r--r--cpp/INSTALL80
-rw-r--r--cpp/Makefile.am9
-rw-r--r--cpp/bindings/CMakeLists.txt67
-rw-r--r--cpp/bindings/qmf/CMakeLists.txt37
-rw-r--r--cpp/bindings/qmf/Makefile.am1
-rw-r--r--cpp/bindings/qmf/python/CMakeLists.txt29
-rw-r--r--cpp/bindings/qmf/python/Makefile.am2
-rw-r--r--cpp/bindings/qmf/python/python.i2
-rw-r--r--cpp/bindings/qmf/ruby/CMakeLists.txt6
-rw-r--r--cpp/bindings/qmf/ruby/Makefile.am2
-rw-r--r--cpp/bindings/qmf/ruby/qmf.rb14
-rw-r--r--cpp/bindings/qmf/ruby/ruby.i2
-rw-r--r--cpp/bindings/qmf2/CMakeLists.txt37
-rw-r--r--cpp/bindings/qmf2/Makefile.am1
-rw-r--r--cpp/bindings/qmf2/examples/cpp/Makefile.am11
-rw-r--r--cpp/bindings/qmf2/python/CMakeLists.txt31
-rw-r--r--cpp/bindings/qmf2/python/Makefile.am4
-rw-r--r--cpp/bindings/qmf2/python/python.i4
-rw-r--r--cpp/bindings/qmf2/ruby/CMakeLists.txt6
-rw-r--r--cpp/bindings/qmf2/ruby/Makefile.am4
-rw-r--r--cpp/bindings/qmf2/ruby/ruby.i6
-rw-r--r--cpp/bindings/qpid/CMakeLists.txt41
-rw-r--r--cpp/bindings/qpid/Makefile.am13
-rw-r--r--cpp/bindings/qpid/dotnet/configure-windows.ps141
-rw-r--r--cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs28
-rw-r--r--cpp/bindings/qpid/dotnet/msvc9/org.apache.qpid.messaging.sessionreceiver.sln2
-rw-r--r--cpp/bindings/qpid/dotnet/src/Receiver.cpp31
-rw-r--r--cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs34
-rw-r--r--cpp/bindings/qpid/examples/perl/README26
-rwxr-xr-x[-rw-r--r--]cpp/bindings/qpid/examples/perl/client.pl72
-rwxr-xr-x[-rw-r--r--]cpp/bindings/qpid/examples/perl/drain.pl136
-rwxr-xr-x[-rw-r--r--]cpp/bindings/qpid/examples/perl/hello_world.pl30
-rwxr-xr-x[-rw-r--r--]cpp/bindings/qpid/examples/perl/hello_xml.pl35
-rwxr-xr-x[-rw-r--r--]cpp/bindings/qpid/examples/perl/map_receiver.pl28
-rwxr-xr-x[-rw-r--r--]cpp/bindings/qpid/examples/perl/map_sender.pl46
-rwxr-xr-x[-rw-r--r--]cpp/bindings/qpid/examples/perl/server.pl53
-rwxr-xr-x[-rw-r--r--]cpp/bindings/qpid/examples/perl/spout.pl132
-rw-r--r--cpp/bindings/qpid/perl/CMakeLists.txt13
-rw-r--r--cpp/bindings/qpid/perl/ChangeLog6
-rw-r--r--cpp/bindings/qpid/perl/LICENSE206
-rw-r--r--cpp/bindings/qpid/perl/Makefile.PL13
-rw-r--r--cpp/bindings/qpid/perl/README15
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid/messaging/Address.pm338
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid/messaging/Connection.pm291
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid/messaging/Duration.pm204
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid/messaging/Message.pm584
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid/messaging/Receiver.pm317
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid/messaging/Sender.pm258
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid/messaging/Session.pm473
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid/messaging/codec.pm53
-rw-r--r--cpp/bindings/qpid/perl/lib/qpid_messaging.pm95
-rw-r--r--cpp/bindings/qpid/perl/perl.i4
-rw-r--r--cpp/bindings/qpid/perl/qpid.pm22
-rw-r--r--cpp/bindings/qpid/perl/t/Address.t102
-rw-r--r--cpp/bindings/qpid/perl/t/Duration.t124
-rw-r--r--cpp/bindings/qpid/perl/t/Message.t286
-rw-r--r--cpp/bindings/qpid/perl/t/utils.pm38
-rw-r--r--cpp/bindings/qpid/python/CMakeLists.txt13
-rw-r--r--cpp/bindings/qpid/python/Makefile.am4
-rw-r--r--cpp/bindings/qpid/python/python.i4
-rw-r--r--cpp/bindings/qpid/qpid.i70
-rw-r--r--cpp/bindings/qpid/ruby/CMakeLists.txt6
-rw-r--r--cpp/bindings/qpid/ruby/ChangeLog4
-rw-r--r--cpp/bindings/qpid/ruby/LICENSE4
-rw-r--r--cpp/bindings/qpid/ruby/Makefile.am4
-rw-r--r--cpp/bindings/qpid/ruby/README.rdoc38
-rw-r--r--cpp/bindings/qpid/ruby/Rakefile137
-rw-r--r--cpp/bindings/qpid/ruby/TODO15
-rw-r--r--cpp/bindings/qpid/ruby/examples/client.rb6
-rw-r--r--cpp/bindings/qpid/ruby/examples/drain.rb2
-rw-r--r--cpp/bindings/qpid/ruby/examples/hello_world.rb2
-rw-r--r--cpp/bindings/qpid/ruby/examples/map_receiver.rb2
-rw-r--r--cpp/bindings/qpid/ruby/examples/map_sender.rb2
-rw-r--r--cpp/bindings/qpid/ruby/examples/server.rb2
-rw-r--r--cpp/bindings/qpid/ruby/examples/spout.rb2
-rw-r--r--cpp/bindings/qpid/ruby/ext/cqpid/extconf.rb3
-rw-r--r--cpp/bindings/qpid/ruby/features/creating_a_receiver.feature2
-rw-r--r--cpp/bindings/qpid/ruby/features/creating_a_sender.feature2
-rw-r--r--cpp/bindings/qpid/ruby/features/step_definitions/address_steps.rb13
-rw-r--r--cpp/bindings/qpid/ruby/features/support/env.rb2
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid.rb29
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/address.rb187
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/connection.rb162
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/duration.rb95
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/encoding.rb60
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/errors.rb33
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/message.rb368
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/receiver.rb186
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/sender.rb152
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/session.rb271
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid/version.rb31
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging.rb82
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging/address.rb200
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging/connection.rb189
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging/duration.rb128
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb75
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb353
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging/receiver.rb177
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging/sender.rb135
-rw-r--r--cpp/bindings/qpid/ruby/lib/qpid_messaging/session.rb264
-rw-r--r--cpp/bindings/qpid/ruby/qpid_messaging.gemspec28
-rw-r--r--cpp/bindings/qpid/ruby/ruby.i6
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb87
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb191
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb56
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb292
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb353
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid_messaging/address_spec.rb87
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid_messaging/connection_spec.rb191
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid_messaging/duration_spec.rb83
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid_messaging/encoding_spec.rb (renamed from cpp/bindings/qpid/ruby/spec/qpid/encoding_spec.rb)0
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb305
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid_messaging/receiver_spec.rb (renamed from cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb)0
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid_messaging/sender_spec.rb (renamed from cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb)0
-rw-r--r--cpp/bindings/qpid/ruby/spec/qpid_messaging/session_spec.rb353
-rw-r--r--cpp/bindings/qpid/ruby/spec/spec_helper.rb3
-rw-r--r--cpp/bindings/swig_perl_typemaps.i330
-rw-r--r--cpp/bld-winsdk.ps16
-rw-r--r--cpp/configure.ac21
-rw-r--r--cpp/design_docs/broker-acl-work.txt152
-rw-r--r--cpp/design_docs/new-ha-design.txt119
-rw-r--r--cpp/docs/api/CMakeLists.txt6
-rwxr-xr-xcpp/etc/qpidd-primary.in2
-rw-r--r--cpp/etc/sasl2/qpidd.conf30
-rw-r--r--cpp/examples/makedist.mk1
-rw-r--r--cpp/examples/messaging/CMakeLists.txt24
-rw-r--r--cpp/examples/messaging/Makefile.am11
-rw-r--r--cpp/examples/messaging/extra_dist/CMakeLists.txt62
-rw-r--r--cpp/examples/messaging/extra_dist/Makefile30
-rw-r--r--cpp/examples/messaging/spout.cpp1
-rw-r--r--cpp/examples/old_api/direct/Makefile.am6
-rw-r--r--cpp/examples/old_api/failover/Makefile.am6
-rw-r--r--cpp/examples/old_api/fanout/Makefile.am2
-rw-r--r--cpp/examples/old_api/pub-sub/Makefile.am4
-rw-r--r--cpp/examples/old_api/request-response/Makefile.am4
-rw-r--r--cpp/examples/old_api/tradedemo/Makefile.am6
-rw-r--r--cpp/examples/old_api/xml-exchange/Makefile.am6
-rw-r--r--cpp/examples/qmf-console/Makefile.am10
-rw-r--r--cpp/include/qmf/qmf2.i (renamed from cpp/bindings/qmf2/qmf2.i)0
-rw-r--r--cpp/include/qmf/qmfengine.i (renamed from cpp/bindings/qmf/qmfengine.i)0
-rw-r--r--cpp/include/qpid/Options.h5
-rw-r--r--cpp/include/qpid/Url.h7
-rw-r--r--cpp/include/qpid/client/ConnectionSettings.h6
-rw-r--r--cpp/include/qpid/client/FailoverManager.h1
-rw-r--r--cpp/include/qpid/framing/FieldValue.h13
-rw-r--r--cpp/include/qpid/framing/ProtocolVersion.h11
-rw-r--r--cpp/include/qpid/log/Logger.h5
-rw-r--r--cpp/include/qpid/management/Manageable.h6
-rw-r--r--cpp/include/qpid/management/ManagementObject.h15
-rw-r--r--cpp/include/qpid/messaging/Message.h2
-rw-r--r--cpp/include/qpid/qpid.i101
-rw-r--r--cpp/include/qpid/swig_perl_typemaps.i335
-rw-r--r--cpp/include/qpid/swig_python_typemaps.i (renamed from cpp/bindings/swig_python_typemaps.i)0
-rw-r--r--cpp/include/qpid/swig_ruby_typemaps.i (renamed from cpp/bindings/swig_ruby_typemaps.i)0
-rw-r--r--cpp/include/qpid/sys/IOHandle.h15
-rw-r--r--cpp/include/qpid/sys/SystemInfo.h25
-rw-r--r--cpp/include/qpid/sys/posix/PrivatePosix.h22
-rw-r--r--cpp/include/qpid/types/Variant.h1
-rwxr-xr-xcpp/managementgen/qmf-gen2
-rwxr-xr-xcpp/managementgen/qmfgen/generate.py11
-rwxr-xr-xcpp/managementgen/qmfgen/schema.py7
-rw-r--r--cpp/managementgen/qmfgen/templates/Class.h36
-rw-r--r--cpp/managementgen/qmfgen/templates/Event.h21
-rw-r--r--cpp/managementgen/qmfgen/templates/Package.h6
-rw-r--r--cpp/src/CMakeLists.txt200
-rw-r--r--cpp/src/Makefile.am158
-rw-r--r--cpp/src/acl.mk4
-rw-r--r--cpp/src/amqp.cmake127
-rw-r--r--cpp/src/asyncstore.cmake1
-rw-r--r--cpp/src/config.h.cmake2
-rw-r--r--cpp/src/finddb.cmake74
-rwxr-xr-xcpp/src/generate.sh67
-rw-r--r--cpp/src/ha.mk5
-rw-r--r--cpp/src/legacystore.cmake157
-rw-r--r--cpp/src/posix/QpiddBroker.cpp20
-rw-r--r--cpp/src/qpid/Modules.cpp49
-rw-r--r--cpp/src/qpid/Modules.h2
-rw-r--r--cpp/src/qpid/NullSaslServer.cpp86
-rw-r--r--cpp/src/qpid/NullSaslServer.h49
-rw-r--r--cpp/src/qpid/Options.cpp96
-rw-r--r--cpp/src/qpid/Sasl.h2
-rw-r--r--cpp/src/qpid/SaslFactory.cpp213
-rw-r--r--cpp/src/qpid/SaslFactory.h3
-rw-r--r--cpp/src/qpid/SaslServer.h48
-rw-r--r--cpp/src/qpid/Url.cpp13
-rw-r--r--cpp/src/qpid/UrlArray.h6
-rw-r--r--cpp/src/qpid/acl/Acl.cpp62
-rw-r--r--cpp/src/qpid/acl/Acl.h17
-rw-r--r--cpp/src/qpid/acl/AclConnectionCounter.cpp212
-rw-r--r--cpp/src/qpid/acl/AclConnectionCounter.h11
-rw-r--r--cpp/src/qpid/acl/AclData.cpp146
-rw-r--r--cpp/src/qpid/acl/AclData.h46
-rw-r--r--cpp/src/qpid/acl/AclPlugin.cpp5
-rw-r--r--cpp/src/qpid/acl/AclReader.cpp168
-rw-r--r--cpp/src/qpid/acl/AclReader.h12
-rw-r--r--cpp/src/qpid/acl/AclResourceCounter.cpp165
-rw-r--r--cpp/src/qpid/acl/AclResourceCounter.h78
-rw-r--r--cpp/src/qpid/acl/AclTopicMatch.h2
-rw-r--r--cpp/src/qpid/acl/AclValidator.cpp16
-rw-r--r--cpp/src/qpid/acl/management-schema.xml4
-rw-r--r--cpp/src/qpid/agent/ManagementAgentImpl.cpp42
-rw-r--r--cpp/src/qpid/agent/ManagementAgentImpl.h6
-rw-r--r--cpp/src/qpid/amqp/CharSequence.cpp47
-rw-r--r--cpp/src/qpid/amqp/CharSequence.h49
-rw-r--r--cpp/src/qpid/amqp/Codec.h83
-rw-r--r--cpp/src/qpid/amqp/Constructor.h42
-rw-r--r--cpp/src/qpid/amqp/Decoder.cpp545
-rw-r--r--cpp/src/qpid/amqp/Decoder.h99
-rw-r--r--cpp/src/qpid/amqp/Descriptor.cpp52
-rw-r--r--cpp/src/qpid/amqp/Descriptor.h54
-rw-r--r--cpp/src/qpid/amqp/Encoder.cpp402
-rw-r--r--cpp/src/qpid/amqp/Encoder.h149
-rw-r--r--cpp/src/qpid/amqp/ListReader.h103
-rw-r--r--cpp/src/qpid/amqp/LoggingReader.h64
-rw-r--r--cpp/src/qpid/amqp/MapReader.cpp289
-rw-r--r--cpp/src/qpid/amqp/MapReader.h104
-rw-r--r--cpp/src/qpid/amqp/MessageEncoder.cpp313
-rw-r--r--cpp/src/qpid/amqp/MessageEncoder.h100
-rw-r--r--cpp/src/qpid/amqp/MessageId.cpp69
-rw-r--r--cpp/src/qpid/amqp/MessageId.h54
-rw-r--r--cpp/src/qpid/amqp/MessageReader.cpp759
-rw-r--r--cpp/src/qpid/amqp/MessageReader.h301
-rw-r--r--cpp/src/qpid/amqp/Reader.h80
-rw-r--r--cpp/src/qpid/amqp/Sasl.cpp136
-rw-r--r--cpp/src/qpid/amqp/Sasl.h54
-rw-r--r--cpp/src/qpid/amqp/SaslClient.cpp154
-rw-r--r--cpp/src/qpid/amqp/SaslClient.h54
-rw-r--r--cpp/src/qpid/amqp/SaslServer.cpp183
-rw-r--r--cpp/src/qpid/amqp/SaslServer.h50
-rw-r--r--cpp/src/qpid/amqp/descriptors.h88
-rw-r--r--cpp/src/qpid/amqp/typecodes.h115
-rw-r--r--cpp/src/qpid/amqp_0_10/Connection.cpp9
-rw-r--r--cpp/src/qpid/amqp_0_10/Connection.h7
-rw-r--r--cpp/src/qpid/asyncStore/OperationQueue.cpp2
-rw-r--r--cpp/src/qpid/asyncStore/Plugin.cpp9
-rw-r--r--cpp/src/qpid/broker/AclModule.h27
-rw-r--r--cpp/src/qpid/broker/Bridge.cpp65
-rw-r--r--cpp/src/qpid/broker/Bridge.h5
-rw-r--r--cpp/src/qpid/broker/Broker.cpp286
-rw-r--r--cpp/src/qpid/broker/Broker.h99
-rw-r--r--cpp/src/qpid/broker/ConfigurationObserver.h4
-rw-r--r--cpp/src/qpid/broker/Connection.cpp78
-rw-r--r--cpp/src/qpid/broker/Connection.h59
-rw-r--r--cpp/src/qpid/broker/ConnectionFactory.cpp61
-rw-r--r--cpp/src/qpid/broker/ConnectionFactory.h51
-rw-r--r--cpp/src/qpid/broker/ConnectionHandler.cpp50
-rw-r--r--cpp/src/qpid/broker/ConnectionState.cpp38
-rw-r--r--cpp/src/qpid/broker/ConnectionState.h32
-rw-r--r--cpp/src/qpid/broker/Consumer.h9
-rw-r--r--cpp/src/qpid/broker/ConsumerFactory.h7
-rw-r--r--cpp/src/qpid/broker/DeliverableMessage.cpp5
-rw-r--r--cpp/src/qpid/broker/DeliverableMessage.h1
-rw-r--r--cpp/src/qpid/broker/DeliveryAdapter.h0
-rw-r--r--cpp/src/qpid/broker/DirectExchange.cpp2
-rw-r--r--cpp/src/qpid/broker/DtxManager.cpp41
-rw-r--r--cpp/src/qpid/broker/DtxManager.h18
-rw-r--r--cpp/src/qpid/broker/DtxWorkRecord.cpp23
-rw-r--r--cpp/src/qpid/broker/DtxWorkRecord.h13
-rw-r--r--cpp/src/qpid/broker/Exchange.cpp42
-rw-r--r--cpp/src/qpid/broker/Exchange.h13
-rw-r--r--cpp/src/qpid/broker/ExchangeRegistry.cpp44
-rw-r--r--cpp/src/qpid/broker/ExchangeRegistry.h25
-rw-r--r--cpp/src/qpid/broker/FanOutExchange.cpp2
-rw-r--r--cpp/src/qpid/broker/HeadersExchange.cpp14
-rw-r--r--cpp/src/qpid/broker/HeadersExchange.h3
-rw-r--r--cpp/src/qpid/broker/LegacyLVQ.cpp0
-rw-r--r--cpp/src/qpid/broker/LegacyLVQ.h0
-rw-r--r--cpp/src/qpid/broker/Link.cpp259
-rw-r--r--cpp/src/qpid/broker/Link.h20
-rw-r--r--cpp/src/qpid/broker/LinkRegistry.cpp94
-rw-r--r--cpp/src/qpid/broker/LinkRegistry.h15
-rw-r--r--cpp/src/qpid/broker/Lvq.cpp2
-rw-r--r--cpp/src/qpid/broker/Message.cpp12
-rw-r--r--cpp/src/qpid/broker/Message.h4
-rw-r--r--cpp/src/qpid/broker/MessageGroupManager.cpp110
-rw-r--r--cpp/src/qpid/broker/MessageGroupManager.h16
-rw-r--r--cpp/src/qpid/broker/MessageStore.h14
-rw-r--r--cpp/src/qpid/broker/MessageStoreModule.cpp5
-rw-r--r--cpp/src/qpid/broker/MessageStoreModule.h1
-rw-r--r--cpp/src/qpid/broker/Messages.h7
-rw-r--r--cpp/src/qpid/broker/NullMessageStore.cpp2
-rw-r--r--cpp/src/qpid/broker/NullMessageStore.h1
-rw-r--r--cpp/src/qpid/broker/Protocol.cpp70
-rw-r--r--cpp/src/qpid/broker/Protocol.h82
-rw-r--r--cpp/src/qpid/broker/Queue.cpp145
-rw-r--r--cpp/src/qpid/broker/Queue.h47
-rw-r--r--cpp/src/qpid/broker/QueueCleaner.cpp33
-rw-r--r--cpp/src/qpid/broker/QueueCleaner.h20
-rw-r--r--cpp/src/qpid/broker/QueueFlowLimit.cpp87
-rw-r--r--cpp/src/qpid/broker/QueueFlowLimit.h19
-rw-r--r--cpp/src/qpid/broker/QueueObserver.h1
-rw-r--r--cpp/src/qpid/broker/QueueRegistry.cpp42
-rw-r--r--cpp/src/qpid/broker/QueueRegistry.h10
-rw-r--r--cpp/src/qpid/broker/QueueSettings.cpp14
-rw-r--r--cpp/src/qpid/broker/QueueSettings.h6
-rw-r--r--cpp/src/qpid/broker/RecoverableExchange.h3
-rw-r--r--cpp/src/qpid/broker/RecoverableMessage.h3
-rw-r--r--cpp/src/qpid/broker/RecoverableMessageImpl.h49
-rw-r--r--cpp/src/qpid/broker/RecoveryManagerImpl.cpp40
-rw-r--r--cpp/src/qpid/broker/RecoveryManagerImpl.h4
-rw-r--r--cpp/src/qpid/broker/SaslAuthenticator.cpp17
-rw-r--r--cpp/src/qpid/broker/SecureConnection.cpp2
-rw-r--r--cpp/src/qpid/broker/SecureConnection.h2
-rw-r--r--cpp/src/qpid/broker/SecureConnectionFactory.cpp14
-rw-r--r--cpp/src/qpid/broker/SemanticState.cpp167
-rw-r--r--cpp/src/qpid/broker/SemanticState.h217
-rw-r--r--cpp/src/qpid/broker/SessionAdapter.cpp28
-rw-r--r--cpp/src/qpid/broker/SessionHandler.cpp12
-rw-r--r--cpp/src/qpid/broker/SessionHandler.h12
-rw-r--r--cpp/src/qpid/broker/SessionState.cpp32
-rw-r--r--cpp/src/qpid/broker/SessionState.h22
-rw-r--r--cpp/src/qpid/broker/StatefulQueueObserver.h63
-rw-r--r--cpp/src/qpid/broker/System.cpp4
-rw-r--r--cpp/src/qpid/broker/System.h4
-rw-r--r--cpp/src/qpid/broker/TopicExchange.cpp2
-rw-r--r--cpp/src/qpid/broker/TxAccept.h3
-rw-r--r--cpp/src/qpid/broker/TxOpVisitor.h0
-rw-r--r--cpp/src/qpid/broker/TxPublish.cpp0
-rw-r--r--cpp/src/qpid/broker/TxPublish.h0
-rw-r--r--cpp/src/qpid/broker/Vhost.cpp4
-rw-r--r--cpp/src/qpid/broker/Vhost.h4
-rw-r--r--cpp/src/qpid/broker/amqp/Connection.cpp247
-rw-r--r--cpp/src/qpid/broker/amqp/Connection.h73
-rw-r--r--cpp/src/qpid/broker/amqp/DataReader.cpp187
-rw-r--r--cpp/src/qpid/broker/amqp/DataReader.h53
-rw-r--r--cpp/src/qpid/broker/amqp/Filter.cpp150
-rw-r--r--cpp/src/qpid/broker/amqp/Filter.h63
-rw-r--r--cpp/src/qpid/broker/amqp/Header.cpp65
-rw-r--r--cpp/src/qpid/broker/amqp/Header.h50
-rw-r--r--cpp/src/qpid/broker/amqp/ManagedConnection.cpp98
-rw-r--r--cpp/src/qpid/broker/amqp/ManagedConnection.h59
-rw-r--r--cpp/src/qpid/broker/amqp/ManagedOutgoingLink.cpp70
-rw-r--r--cpp/src/qpid/broker/amqp/ManagedOutgoingLink.h53
-rw-r--r--cpp/src/qpid/broker/amqp/ManagedSession.cpp88
-rw-r--r--cpp/src/qpid/broker/amqp/ManagedSession.h59
-rw-r--r--cpp/src/qpid/broker/amqp/Message.cpp264
-rw-r--r--cpp/src/qpid/broker/amqp/Message.h148
-rw-r--r--cpp/src/qpid/broker/amqp/NodeProperties.cpp179
-rw-r--r--cpp/src/qpid/broker/amqp/NodeProperties.h71
-rw-r--r--cpp/src/qpid/broker/amqp/Outgoing.cpp244
-rw-r--r--cpp/src/qpid/broker/amqp/Outgoing.h108
-rw-r--r--cpp/src/qpid/broker/amqp/ProtocolPlugin.cpp117
-rw-r--r--cpp/src/qpid/broker/amqp/Sasl.cpp167
-rw-r--r--cpp/src/qpid/broker/amqp/Sasl.h72
-rw-r--r--cpp/src/qpid/broker/amqp/Session.cpp332
-rw-r--r--cpp/src/qpid/broker/amqp/Session.h87
-rw-r--r--cpp/src/qpid/broker/amqp/Translation.cpp241
-rw-r--r--cpp/src/qpid/broker/amqp/Translation.h58
-rw-r--r--cpp/src/qpid/broker/amqp_0_10/MessageTransfer.cpp13
-rw-r--r--cpp/src/qpid/broker/amqp_0_10/MessageTransfer.h1
-rw-r--r--cpp/src/qpid/broker/windows/SaslAuthenticator.cpp1
-rw-r--r--cpp/src/qpid/broker/windows/SslProtocolFactory.cpp729
-rw-r--r--cpp/src/qpid/client/ConnectionHandler.cpp8
-rw-r--r--cpp/src/qpid/client/ConnectionImpl.cpp20
-rw-r--r--cpp/src/qpid/client/FailoverManager.cpp3
-rw-r--r--cpp/src/qpid/client/LoadPlugins.cpp2
-rw-r--r--cpp/src/qpid/client/LoadPlugins.h4
-rw-r--r--cpp/src/qpid/client/QueueOptions.cpp4
-rw-r--r--cpp/src/qpid/client/RdmaConnector.cpp6
-rw-r--r--cpp/src/qpid/client/SessionImpl.cpp108
-rw-r--r--cpp/src/qpid/client/SessionImpl.h19
-rw-r--r--cpp/src/qpid/client/SslConnector.cpp106
-rw-r--r--cpp/src/qpid/client/TCPConnector.cpp25
-rw-r--r--cpp/src/qpid/client/TCPConnector.h7
-rw-r--r--cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp3
-rw-r--r--cpp/src/qpid/client/windows/ClientDllMain.cpp22
-rw-r--r--cpp/src/qpid/client/windows/SslConnector.cpp20
-rw-r--r--cpp/src/qpid/framing/FieldValue.cpp14
-rw-r--r--cpp/src/qpid/framing/FrameSet.h8
-rw-r--r--cpp/src/qpid/framing/Handler.h43
-rw-r--r--cpp/src/qpid/framing/ProtocolInitiation.cpp31
-rw-r--r--cpp/src/qpid/framing/ProtocolVersion.cpp8
-rw-r--r--cpp/src/qpid/ha/AlternateExchangeSetter.h4
-rw-r--r--cpp/src/qpid/ha/Backup.cpp106
-rw-r--r--cpp/src/qpid/ha/Backup.h20
-rw-r--r--cpp/src/qpid/ha/BrokerInfo.cpp24
-rw-r--r--cpp/src/qpid/ha/BrokerInfo.h8
-rw-r--r--cpp/src/qpid/ha/BrokerReplicator.cpp606
-rw-r--r--cpp/src/qpid/ha/BrokerReplicator.h52
-rw-r--r--cpp/src/qpid/ha/ConnectionObserver.cpp6
-rw-r--r--cpp/src/qpid/ha/ConnectionObserver.h2
-rw-r--r--cpp/src/qpid/ha/HaBroker.cpp252
-rw-r--r--cpp/src/qpid/ha/HaBroker.h62
-rw-r--r--cpp/src/qpid/ha/HaPlugin.cpp26
-rw-r--r--cpp/src/qpid/ha/Membership.cpp113
-rw-r--r--cpp/src/qpid/ha/Membership.h45
-rw-r--r--cpp/src/qpid/ha/Primary.cpp122
-rw-r--r--cpp/src/qpid/ha/Primary.h23
-rw-r--r--cpp/src/qpid/ha/QueueGuard.cpp94
-rw-r--r--cpp/src/qpid/ha/QueueGuard.h12
-rw-r--r--cpp/src/qpid/ha/QueueRange.h11
-rw-r--r--cpp/src/qpid/ha/QueueReplicator.cpp161
-rw-r--r--cpp/src/qpid/ha/QueueReplicator.h18
-rw-r--r--cpp/src/qpid/ha/RemoteBackup.cpp53
-rw-r--r--cpp/src/qpid/ha/RemoteBackup.h22
-rw-r--r--cpp/src/qpid/ha/ReplicatingSubscription.cpp57
-rw-r--r--cpp/src/qpid/ha/ReplicatingSubscription.h17
-rw-r--r--cpp/src/qpid/ha/ReplicationTest.cpp39
-rw-r--r--cpp/src/qpid/ha/ReplicationTest.h26
-rw-r--r--cpp/src/qpid/ha/Role.h55
-rw-r--r--cpp/src/qpid/ha/Settings.h16
-rw-r--r--cpp/src/qpid/ha/StandAlone.h45
-rw-r--r--cpp/src/qpid/ha/StatusCheck.cpp132
-rw-r--r--cpp/src/qpid/ha/StatusCheck.h71
-rw-r--r--cpp/src/qpid/ha/types.cpp6
-rw-r--r--cpp/src/qpid/ha/types.h1
-rw-r--r--cpp/src/qpid/legacystore/BindingDbt.cpp50
-rw-r--r--cpp/src/qpid/legacystore/BindingDbt.h56
-rw-r--r--cpp/src/qpid/legacystore/BufferValue.cpp56
-rw-r--r--cpp/src/qpid/legacystore/BufferValue.h46
-rw-r--r--cpp/src/qpid/legacystore/Cursor.h50
-rw-r--r--cpp/src/qpid/legacystore/DataTokenImpl.cpp28
-rw-r--r--cpp/src/qpid/legacystore/DataTokenImpl.h47
-rw-r--r--cpp/src/qpid/legacystore/IdDbt.cpp42
-rw-r--r--cpp/src/qpid/legacystore/IdDbt.h42
-rw-r--r--cpp/src/qpid/legacystore/IdSequence.cpp40
-rw-r--r--cpp/src/qpid/legacystore/IdSequence.h44
-rw-r--r--cpp/src/qpid/legacystore/JournalImpl.cpp633
-rw-r--r--cpp/src/qpid/legacystore/JournalImpl.h265
-rw-r--r--cpp/src/qpid/legacystore/MessageStoreImpl.cpp1732
-rw-r--r--cpp/src/qpid/legacystore/MessageStoreImpl.h380
-rw-r--r--cpp/src/qpid/legacystore/PreparedTransaction.cpp81
-rw-r--r--cpp/src/qpid/legacystore/PreparedTransaction.h74
-rw-r--r--cpp/src/qpid/legacystore/StoreException.h56
-rw-r--r--cpp/src/qpid/legacystore/StorePlugin.cpp81
-rw-r--r--cpp/src/qpid/legacystore/TxnCtxt.cpp184
-rw-r--r--cpp/src/qpid/legacystore/TxnCtxt.h117
-rw-r--r--cpp/src/qpid/legacystore/jrnl/aio.cpp41
-rw-r--r--cpp/src/qpid/legacystore/jrnl/aio.h153
-rw-r--r--cpp/src/qpid/legacystore/jrnl/aio_callback.h57
-rw-r--r--cpp/src/qpid/legacystore/jrnl/cvar.cpp33
-rw-r--r--cpp/src/qpid/legacystore/jrnl/cvar.h87
-rw-r--r--cpp/src/qpid/legacystore/jrnl/data_tok.cpp194
-rw-r--r--cpp/src/qpid/legacystore/jrnl/data_tok.h172
-rw-r--r--cpp/src/qpid/legacystore/jrnl/deq_hdr.h141
-rw-r--r--cpp/src/qpid/legacystore/jrnl/deq_rec.cpp459
-rw-r--r--cpp/src/qpid/legacystore/jrnl/deq_rec.h103
-rw-r--r--cpp/src/qpid/legacystore/jrnl/enq_hdr.h165
-rw-r--r--cpp/src/qpid/legacystore/jrnl/enq_map.cpp183
-rw-r--r--cpp/src/qpid/legacystore/jrnl/enq_map.h127
-rw-r--r--cpp/src/qpid/legacystore/jrnl/enq_rec.cpp638
-rw-r--r--cpp/src/qpid/legacystore/jrnl/enq_rec.h116
-rw-r--r--cpp/src/qpid/legacystore/jrnl/enums.h108
-rw-r--r--cpp/src/qpid/legacystore/jrnl/fcntl.cpp375
-rw-r--r--cpp/src/qpid/legacystore/jrnl/fcntl.h156
-rw-r--r--cpp/src/qpid/legacystore/jrnl/file_hdr.h211
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jcfg.h91
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jcntl.cpp984
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jcntl.h722
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jdir.cpp463
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jdir.h379
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jerrno.cpp253
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jerrno.h173
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jexception.cpp183
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jexception.h142
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jinf.cpp540
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jinf.h133
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jrec.cpp119
-rw-r--r--cpp/src/qpid/legacystore/jrnl/jrec.h183
-rw-r--r--cpp/src/qpid/legacystore/jrnl/lp_map.cpp82
-rw-r--r--cpp/src/qpid/legacystore/jrnl/lp_map.h83
-rw-r--r--cpp/src/qpid/legacystore/jrnl/lpmgr.cpp226
-rw-r--r--cpp/src/qpid/legacystore/jrnl/lpmgr.h303
-rw-r--r--cpp/src/qpid/legacystore/jrnl/pmgr.cpp215
-rw-r--r--cpp/src/qpid/legacystore/jrnl/pmgr.h142
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rcvdat.h181
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rec_hdr.h143
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rec_tail.h98
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rfc.cpp82
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rfc.h193
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rmgr.cpp698
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rmgr.h114
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rrfc.cpp125
-rw-r--r--cpp/src/qpid/legacystore/jrnl/rrfc.h179
-rw-r--r--cpp/src/qpid/legacystore/jrnl/slock.cpp33
-rw-r--r--cpp/src/qpid/legacystore/jrnl/slock.h85
-rw-r--r--cpp/src/qpid/legacystore/jrnl/smutex.cpp33
-rw-r--r--cpp/src/qpid/legacystore/jrnl/smutex.h64
-rw-r--r--cpp/src/qpid/legacystore/jrnl/time_ns.cpp55
-rw-r--r--cpp/src/qpid/legacystore/jrnl/time_ns.h105
-rw-r--r--cpp/src/qpid/legacystore/jrnl/txn_hdr.h125
-rw-r--r--cpp/src/qpid/legacystore/jrnl/txn_map.cpp256
-rw-r--r--cpp/src/qpid/legacystore/jrnl/txn_map.h159
-rw-r--r--cpp/src/qpid/legacystore/jrnl/txn_rec.cpp447
-rw-r--r--cpp/src/qpid/legacystore/jrnl/txn_rec.h101
-rw-r--r--cpp/src/qpid/legacystore/jrnl/wmgr.cpp1051
-rw-r--r--cpp/src/qpid/legacystore/jrnl/wmgr.h147
-rw-r--r--cpp/src/qpid/legacystore/jrnl/wrfc.cpp162
-rw-r--r--cpp/src/qpid/legacystore/jrnl/wrfc.h154
-rw-r--r--cpp/src/qpid/legacystore/management-schema.xml99
-rw-r--r--cpp/src/qpid/log/Logger.cpp16
-rw-r--r--cpp/src/qpid/management/ManagementAgent.cpp1110
-rw-r--r--cpp/src/qpid/management/ManagementAgent.h183
-rw-r--r--cpp/src/qpid/messaging/Connection.cpp27
-rw-r--r--cpp/src/qpid/messaging/ConnectionOptions.cpp121
-rw-r--r--cpp/src/qpid/messaging/ConnectionOptions.h51
-rw-r--r--cpp/src/qpid/messaging/Message.cpp28
-rw-r--r--cpp/src/qpid/messaging/MessageImpl.cpp161
-rw-r--r--cpp/src/qpid/messaging/MessageImpl.h53
-rw-r--r--cpp/src/qpid/messaging/ProtocolRegistry.cpp73
-rw-r--r--cpp/src/qpid/messaging/ProtocolRegistry.h42
-rw-r--r--cpp/src/qpid/messaging/ReceiverImpl.h2
-rw-r--r--cpp/src/qpid/messaging/SenderImpl.h1
-rw-r--r--cpp/src/qpid/messaging/amqp/AddressHelper.cpp182
-rw-r--r--cpp/src/qpid/messaging/amqp/AddressHelper.h57
-rw-r--r--cpp/src/qpid/messaging/amqp/ConnectionContext.cpp612
-rw-r--r--cpp/src/qpid/messaging/amqp/ConnectionContext.h150
-rw-r--r--cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp84
-rw-r--r--cpp/src/qpid/messaging/amqp/ConnectionHandle.h58
-rw-r--r--cpp/src/qpid/messaging/amqp/DriverImpl.cpp74
-rw-r--r--cpp/src/qpid/messaging/amqp/DriverImpl.h60
-rw-r--r--cpp/src/qpid/messaging/amqp/EncodedMessage.cpp263
-rw-r--r--cpp/src/qpid/messaging/amqp/EncodedMessage.h177
-rw-r--r--cpp/src/qpid/messaging/amqp/ReceiverContext.cpp146
-rw-r--r--cpp/src/qpid/messaging/amqp/ReceiverContext.h68
-rw-r--r--cpp/src/qpid/messaging/amqp/ReceiverHandle.cpp106
-rw-r--r--cpp/src/qpid/messaging/amqp/ReceiverHandle.h63
-rw-r--r--cpp/src/qpid/messaging/amqp/Sasl.cpp157
-rw-r--r--cpp/src/qpid/messaging/amqp/Sasl.h72
-rw-r--r--cpp/src/qpid/messaging/amqp/SenderContext.cpp363
-rw-r--r--cpp/src/qpid/messaging/amqp/SenderContext.h90
-rw-r--r--cpp/src/qpid/messaging/amqp/SenderHandle.cpp75
-rw-r--r--cpp/src/qpid/messaging/amqp/SenderHandle.h58
-rw-r--r--cpp/src/qpid/messaging/amqp/SessionContext.cpp156
-rw-r--r--cpp/src/qpid/messaging/amqp/SessionContext.h81
-rw-r--r--cpp/src/qpid/messaging/amqp/SessionHandle.cpp148
-rw-r--r--cpp/src/qpid/messaging/amqp/SessionHandle.h64
-rw-r--r--cpp/src/qpid/messaging/amqp/SslTransport.cpp160
-rw-r--r--cpp/src/qpid/messaging/amqp/SslTransport.h74
-rw-r--r--cpp/src/qpid/messaging/amqp/TcpTransport.cpp162
-rw-r--r--cpp/src/qpid/messaging/amqp/TcpTransport.h71
-rw-r--r--cpp/src/qpid/messaging/amqp/Transport.cpp50
-rw-r--r--cpp/src/qpid/messaging/amqp/Transport.h48
-rw-r--r--cpp/src/qpid/messaging/amqp/TransportContext.h47
-rw-r--r--cpp/src/qpid/store/CMakeLists.txt7
-rw-r--r--cpp/src/qpid/store/MessageStorePlugin.cpp6
-rw-r--r--cpp/src/qpid/store/MessageStorePlugin.h26
-rw-r--r--cpp/src/qpid/store/StorageProvider.h14
-rw-r--r--cpp/src/qpid/store/ms-clfs/MSSqlClfsProvider.cpp20
-rw-r--r--cpp/src/qpid/store/ms-sql/MSSqlProvider.cpp19
-rw-r--r--cpp/src/qpid/store/ms-sql/MessageRecordset.cpp2
-rw-r--r--cpp/src/qpid/sys/AggregateOutput.cpp13
-rw-r--r--cpp/src/qpid/sys/AggregateOutput.h4
-rw-r--r--cpp/src/qpid/sys/AsynchIO.h10
-rw-r--r--cpp/src/qpid/sys/AsynchIOHandler.cpp54
-rw-r--r--cpp/src/qpid/sys/AsynchIOHandler.h9
-rw-r--r--cpp/src/qpid/sys/ClusterSafe.cpp66
-rw-r--r--cpp/src/qpid/sys/ClusterSafe.h87
-rw-r--r--cpp/src/qpid/sys/Codec.h2
-rw-r--r--cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h1
-rwxr-xr-xcpp/src/qpid/sys/FileSysDir.h9
-rw-r--r--cpp/src/qpid/sys/OutputControl.h9
-rw-r--r--cpp/src/qpid/sys/ProtocolFactory.h2
-rw-r--r--cpp/src/qpid/sys/RdmaIOPlugin.cpp11
-rw-r--r--cpp/src/qpid/sys/SecurityLayer.h4
-rw-r--r--cpp/src/qpid/sys/SecuritySettings.h2
-rw-r--r--cpp/src/qpid/sys/Socket.h56
-rw-r--r--cpp/src/qpid/sys/SocketAddress.h3
-rw-r--r--cpp/src/qpid/sys/SslPlugin.cpp289
-rw-r--r--cpp/src/qpid/sys/TCPIOPlugin.cpp136
-rw-r--r--cpp/src/qpid/sys/Timer.cpp21
-rw-r--r--cpp/src/qpid/sys/Timer.h6
-rw-r--r--cpp/src/qpid/sys/TimerWarnings.cpp6
-rw-r--r--cpp/src/qpid/sys/alloca.h42
-rw-r--r--cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.cpp10
-rw-r--r--cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.h4
-rw-r--r--cpp/src/qpid/sys/epoll/EpollPoller.cpp10
-rw-r--r--cpp/src/qpid/sys/posix/AsynchIO.cpp67
-rw-r--r--cpp/src/qpid/sys/posix/BSDSocket.cpp264
-rw-r--r--cpp/src/qpid/sys/posix/BSDSocket.h113
-rwxr-xr-xcpp/src/qpid/sys/posix/FileSysDir.cpp26
-rw-r--r--cpp/src/qpid/sys/posix/IOHandle.cpp15
-rw-r--r--cpp/src/qpid/sys/posix/PollableCondition.cpp7
-rw-r--r--cpp/src/qpid/sys/posix/PosixPoller.cpp8
-rw-r--r--cpp/src/qpid/sys/posix/Socket.cpp263
-rw-r--r--cpp/src/qpid/sys/posix/SocketAddress.cpp5
-rwxr-xr-xcpp/src/qpid/sys/posix/SystemInfo.cpp133
-rw-r--r--cpp/src/qpid/sys/rdma/rdma_wrap.cpp22
-rw-r--r--cpp/src/qpid/sys/rdma/rdma_wrap.h11
-rwxr-xr-xcpp/src/qpid/sys/solaris/SystemInfo.cpp31
-rw-r--r--cpp/src/qpid/sys/ssl/SslHandler.cpp217
-rw-r--r--cpp/src/qpid/sys/ssl/SslHandler.h85
-rw-r--r--cpp/src/qpid/sys/ssl/SslIo.cpp470
-rw-r--r--cpp/src/qpid/sys/ssl/SslIo.h193
-rw-r--r--cpp/src/qpid/sys/ssl/SslSocket.cpp182
-rw-r--r--cpp/src/qpid/sys/ssl/SslSocket.h32
-rw-r--r--cpp/src/qpid/sys/ssl/util.cpp19
-rw-r--r--cpp/src/qpid/sys/windows/AsynchIO.cpp79
-rw-r--r--cpp/src/qpid/sys/windows/FileSysDir.cpp35
-rwxr-xr-xcpp/src/qpid/sys/windows/IOHandle.cpp13
-rwxr-xr-xcpp/src/qpid/sys/windows/IoHandlePrivate.h17
-rwxr-xr-xcpp/src/qpid/sys/windows/IocpPoller.cpp4
-rw-r--r--cpp/src/qpid/sys/windows/PollableCondition.cpp11
-rw-r--r--cpp/src/qpid/sys/windows/QpidDllMain.h72
-rw-r--r--cpp/src/qpid/sys/windows/Socket.cpp292
-rw-r--r--cpp/src/qpid/sys/windows/SslAsynchIO.cpp20
-rw-r--r--cpp/src/qpid/sys/windows/SslAsynchIO.h5
-rwxr-xr-xcpp/src/qpid/sys/windows/SystemInfo.cpp65
-rwxr-xr-xcpp/src/qpid/sys/windows/Thread.cpp23
-rw-r--r--cpp/src/qpid/sys/windows/WinSocket.cpp276
-rw-r--r--cpp/src/qpid/sys/windows/WinSocket.h118
-rw-r--r--cpp/src/qpid/types/Variant.cpp25
-rw-r--r--cpp/src/qpidd.cpp44
-rw-r--r--cpp/src/qpidd.h3
-rw-r--r--cpp/src/rdma.cmake16
-rw-r--r--cpp/src/ssl.cmake9
-rw-r--r--cpp/src/ssl.mk17
-rw-r--r--cpp/src/tests/.valgrind.supp23
-rw-r--r--cpp/src/tests/BrokerMgmtAgent.cpp979
-rw-r--r--cpp/src/tests/CMakeLists.txt108
-rw-r--r--cpp/src/tests/ClusterFailover.cpp115
-rw-r--r--cpp/src/tests/ClusterFixture.cpp160
-rw-r--r--cpp/src/tests/ClusterFixture.h115
-rw-r--r--cpp/src/tests/DispatcherTest.cpp5
-rw-r--r--cpp/src/tests/FieldTable.cpp1
-rw-r--r--cpp/src/tests/ForkedBroker.cpp157
-rw-r--r--cpp/src/tests/ForkedBroker.h82
-rw-r--r--cpp/src/tests/InitialStatusMap.cpp239
-rw-r--r--cpp/src/tests/Makefile.am46
-rw-r--r--cpp/src/tests/MessageUtils.h5
-rw-r--r--cpp/src/tests/MessagingSessionTests.cpp53
-rw-r--r--cpp/src/tests/PartialFailure.cpp291
-rw-r--r--cpp/src/tests/PollerTest.cpp9
-rw-r--r--cpp/src/tests/QueueTest.cpp1
-rw-r--r--cpp/src/tests/StoreStatus.cpp117
-rw-r--r--cpp/src/tests/SystemInfo.cpp16
-rw-r--r--cpp/src/tests/Variant.cpp10
-rwxr-xr-xcpp/src/tests/acl.py688
-rwxr-xr-xcpp/src/tests/benchmark95
-rw-r--r--cpp/src/tests/brokertest.py102
-rw-r--r--cpp/src/tests/cluster_authentication_soak.cpp310
-rwxr-xr-xcpp/src/tests/cluster_failover19
-rwxr-xr-xcpp/src/tests/cluster_python_tests28
-rw-r--r--cpp/src/tests/cluster_python_tests_failing.txt4
-rwxr-xr-xcpp/src/tests/cluster_read_credit29
-rw-r--r--cpp/src/tests/cluster_test.cpp1231
-rwxr-xr-xcpp/src/tests/cluster_test_logs.py123
-rw-r--r--cpp/src/tests/cluster_test_scripts/README.txt20
-rwxr-xr-xcpp/src/tests/cluster_test_scripts/cluster_check37
-rwxr-xr-xcpp/src/tests/cluster_test_scripts/cluster_start56
-rwxr-xr-xcpp/src/tests/cluster_test_scripts/cluster_stop38
-rwxr-xr-xcpp/src/tests/cluster_test_scripts/config_example.sh44
-rwxr-xr-xcpp/src/tests/cluster_test_scripts/perftest54
-rw-r--r--cpp/src/tests/cluster_tests.fail3
-rwxr-xr-xcpp/src/tests/cluster_tests.py1834
-rwxr-xr-xcpp/src/tests/clustered_replication_test111
-rwxr-xr-xcpp/src/tests/cpg_check.sh.in38
-rwxr-xr-xcpp/src/tests/dynamic_log_hires_timestamp75
-rw-r--r--cpp/src/tests/failover_soak.cpp827
-rwxr-xr-xcpp/src/tests/federated_cluster_test153
-rwxr-xr-xcpp/src/tests/federated_cluster_test_with_node_failure23
-rwxr-xr-xcpp/src/tests/federation.py106
-rwxr-xr-xcpp/src/tests/federation_sys.py1251
-rwxr-xr-xcpp/src/tests/ha_store_tests.py130
-rwxr-xr-xcpp/src/tests/ha_test.py304
-rwxr-xr-xcpp/src/tests/ha_tests.py1097
-rwxr-xr-xcpp/src/tests/ipv6_test40
-rw-r--r--cpp/src/tests/legacystore/.valgrind.supp35
-rw-r--r--cpp/src/tests/legacystore/.valgrindrc7
-rw-r--r--cpp/src/tests/legacystore/CMakeLists.txt117
-rw-r--r--cpp/src/tests/legacystore/MessageUtils.h105
-rw-r--r--cpp/src/tests/legacystore/OrderingTest.cpp168
-rw-r--r--cpp/src/tests/legacystore/SimpleTest.cpp497
-rw-r--r--cpp/src/tests/legacystore/TestFramework.cpp30
-rw-r--r--cpp/src/tests/legacystore/TestFramework.h37
-rw-r--r--cpp/src/tests/legacystore/TransactionalTest.cpp351
-rw-r--r--cpp/src/tests/legacystore/TwoPhaseCommitTest.cpp675
-rw-r--r--cpp/src/tests/legacystore/clean.sh32
-rw-r--r--cpp/src/tests/legacystore/persistence.py574
-rw-r--r--cpp/src/tests/legacystore/run_long_python_tests21
-rw-r--r--cpp/src/tests/legacystore/run_python_tests64
-rw-r--r--cpp/src/tests/legacystore/run_short_python_tests21
-rw-r--r--cpp/src/tests/legacystore/run_test69
-rw-r--r--cpp/src/tests/legacystore/start_broker25
-rw-r--r--cpp/src/tests/legacystore/stop_broker46
-rw-r--r--cpp/src/tests/legacystore/system_test.sh51
-rw-r--r--cpp/src/tests/legacystore/tests_env.sh260
-rw-r--r--cpp/src/tests/legacystore/unit_test.cpp28
-rw-r--r--cpp/src/tests/legacystore/unit_test.h69
-rwxr-xr-xcpp/src/tests/long_cluster_tests.py38
-rwxr-xr-xcpp/src/tests/qpid-cluster-benchmark2
-rwxr-xr-xcpp/src/tests/qpid-cpp-benchmark10
-rw-r--r--cpp/src/tests/qpid-receive.cpp2
-rw-r--r--cpp/src/tests/qpid-send.cpp2
-rwxr-xr-xcpp/src/tests/qpid-test-cluster109
-rwxr-xr-xcpp/src/tests/reliable_replication_test84
-rwxr-xr-xcpp/src/tests/replication_test182
-rwxr-xr-xcpp/src/tests/restart_cluster38
-rwxr-xr-xcpp/src/tests/run_acl_tests18
-rwxr-xr-xcpp/src/tests/run_cluster_authentication_soak27
-rwxr-xr-xcpp/src/tests/run_cluster_authentication_test27
-rwxr-xr-xcpp/src/tests/run_cluster_test27
-rwxr-xr-xcpp/src/tests/run_cluster_tests39
-rwxr-xr-xcpp/src/tests/run_failover_soak39
-rwxr-xr-xcpp/src/tests/run_federation_sys_tests28
-rwxr-xr-xcpp/src/tests/run_long_cluster_tests24
-rwxr-xr-xcpp/src/tests/sasl_fed_ex92
-rwxr-xr-xcpp/src/tests/sasl_fed_ex_dynamic_cluster30
-rwxr-xr-xcpp/src/tests/sasl_fed_ex_link_cluster29
-rwxr-xr-xcpp/src/tests/sasl_fed_ex_queue_cluster29
-rwxr-xr-xcpp/src/tests/sasl_fed_ex_route_cluster29
-rwxr-xr-xcpp/src/tests/ssl_test26
-rwxr-xr-xcpp/src/tests/start_cluster43
-rwxr-xr-xcpp/src/tests/start_cluster_hosts70
-rwxr-xr-xcpp/src/tests/stop_cluster33
-rw-r--r--cpp/src/tests/storePerftools/asyncPerf/PerfTest.cpp2
-rw-r--r--cpp/src/tests/test_env.ps1.in2
-rw-r--r--cpp/src/tests/test_env.sh.in4
-rw-r--r--cpp/src/tests/test_store.cpp6
-rw-r--r--cpp/src/tests/testagent.mk2
-rw-r--r--cpp/src/tests/testlib.py766
-rwxr-xr-xcpp/src/tests/verify_cluster_objects107
-rw-r--r--cpp/src/versions.cmake1
-rw-r--r--cpp/src/windows/QpiddBroker.cpp48
-rw-r--r--cpp/src/xml.mk2
-rw-r--r--cpp/xml/cluster.xml339
-rw-r--r--doc/book/src/Makefile.inc2
-rw-r--r--doc/book/src/cpp-broker/AMQP-Messaging-Broker-CPP-Book.xml1
-rw-r--r--doc/book/src/cpp-broker/Active-Active-Cluster.xml561
-rw-r--r--doc/book/src/cpp-broker/Active-Passive-Cluster.xml236
-rw-r--r--doc/book/src/cpp-broker/Security.xml979
-rw-r--r--doc/book/src/java-broker/AMQP-Messaging-Broker-Java-Book.xml71
-rw-r--r--doc/book/src/java-broker/Add-New-Users.xml237
-rw-r--r--doc/book/src/java-broker/Broker-Configuration-Guide.xml28
-rw-r--r--doc/book/src/java-broker/Configure-ACLs.xml441
-rw-r--r--doc/book/src/java-broker/Configure-Java-Qpid-to-use-a-SSL-connection.xml84
-rw-r--r--doc/book/src/java-broker/Configure-Log4j-CompositeRolling-Appender.xml150
-rw-r--r--doc/book/src/java-broker/Configure-the-Broker-via-config.xml.xml71
-rw-r--r--doc/book/src/java-broker/Configure-the-Virtual-Hosts-via-virtualhosts.xml.xml131
-rw-r--r--doc/book/src/java-broker/Configuring-Management-Users.xml117
-rw-r--r--doc/book/src/java-broker/Configuring-Qpid-JMX-Management-Console.xml181
-rw-r--r--doc/book/src/java-broker/Debug-using-log4j.xml298
-rw-r--r--doc/book/src/java-broker/HA-Guide.xml1008
-rw-r--r--doc/book/src/java-broker/How-to-Tune-M3-Java-Broker-Performance.xml172
-rw-r--r--doc/book/src/java-broker/How-to-Use-SlowConsumerDisconnect.xml280
-rw-r--r--doc/book/src/java-broker/Java-Broker-Concepts-Authentication-Providers.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Concepts-Exchanges.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Concepts-Other-Services.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Concepts-Ports.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Concepts-Protocols.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Concepts-Queues.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Concepts-Virtual-Hosts.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Concepts.xml32
-rw-r--r--doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Config-Files.xml178
-rw-r--r--doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-JMX.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Other-Tooling.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-REST-API.xml263
-rw-r--r--doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Web-Console.xml35
-rw-r--r--doc/book/src/java-broker/Java-Broker-Configuring-And-Managing.xml30
-rw-r--r--doc/book/src/java-broker/Java-Broker-Exchanges-Binding-Arguments.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Exchanges.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Feature-Guide.xml84
-rw-r--r--doc/book/src/java-broker/Java-Broker-Getting-Started.xml140
-rw-r--r--doc/book/src/java-broker/Java-Broker-High-Availability.xml1005
-rw-r--r--doc/book/src/java-broker/Java-Broker-Installation.xml185
-rw-r--r--doc/book/src/java-broker/Java-Broker-Introduction.xml89
-rw-r--r--doc/book/src/java-broker/Java-Broker-Miscellaneous.xml80
-rw-r--r--doc/book/src/java-broker/Java-Broker-Queues-Messaging-Groups.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Queues-OtherTypes.xml276
-rw-r--r--doc/book/src/java-broker/Java-Broker-Queues.xml27
-rw-r--r--doc/book/src/java-broker/Java-Broker-Runtime-Alerts.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Runtime-Disk-Space-Management-Producer-Flow-Control.xml228
-rw-r--r--doc/book/src/java-broker/Java-Broker-Runtime-Disk-Space-Management.xml27
-rw-r--r--doc/book/src/java-broker/Java-Broker-Runtime-Handling-Undeliverable-Messages.xml169
-rw-r--r--doc/book/src/java-broker/Java-Broker-Runtime-Log-Files.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Runtime-Producer-Transaction-Timeout.xml181
-rw-r--r--doc/book/src/java-broker/Java-Broker-Runtime.xml30
-rw-r--r--doc/book/src/java-broker/Java-Broker-Security-ACLs.xml536
-rw-r--r--doc/book/src/java-broker/Java-Broker-Security-Authentication-Providers.xml320
-rw-r--r--doc/book/src/java-broker/Java-Broker-Security-Group-Providers.xml73
-rw-r--r--doc/book/src/java-broker/Java-Broker-Security-SSL.xml119
-rw-r--r--doc/book/src/java-broker/Java-Broker-Security-Users-And-Groups.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Security.xml30
-rw-r--r--doc/book/src/java-broker/Java-Broker-Stores-BDB-Store.xml94
-rw-r--r--doc/book/src/java-broker/Java-Broker-Stores-Derby-Store.xml56
-rw-r--r--doc/book/src/java-broker/Java-Broker-Stores-HA-BDB-Store.xml62
-rw-r--r--doc/book/src/java-broker/Java-Broker-Stores-Memory-Store.xml61
-rw-r--r--doc/book/src/java-broker/Java-Broker-Stores-SQL-Store.xml26
-rw-r--r--doc/book/src/java-broker/Java-Broker-Stores.xml30
-rw-r--r--doc/book/src/java-broker/Java-Broker-Virtual-Hosts.xml25
-rw-r--r--doc/book/src/java-broker/Java-Environment-Variables.xml84
-rw-r--r--doc/book/src/java-broker/Management-Console-Security.xml251
-rw-r--r--doc/book/src/java-broker/OtherQueueTypes.xml274
-rw-r--r--doc/book/src/java-broker/Producer-Flow-Control.xml217
-rw-r--r--doc/book/src/java-broker/Qpid-JMX-Management-Console-FAQ.xml96
-rw-r--r--doc/book/src/java-broker/Qpid-JMX-Management-Console-User-Guide.xml793
-rw-r--r--doc/book/src/java-broker/Qpid-JMX-Management-Console.xml53
-rw-r--r--doc/book/src/java-broker/Qpid-Java-Broker-Management-CLI.xml159
-rw-r--r--doc/book/src/java-broker/Qpid-Java-Build-How-To.xml365
-rw-r--r--doc/book/src/java-broker/Qpid-Java-FAQ.xml890
-rw-r--r--doc/book/src/java-broker/Qpid-Management-Features.xml185
-rw-r--r--doc/book/src/java-broker/Qpid-Troubleshooting-Guide.xml156
-rw-r--r--doc/book/src/java-broker/Topic-Configuration.xml107
-rw-r--r--doc/book/src/java-broker/commonEntities.xml39
-rw-r--r--doc/book/src/java-broker/images/3113098.pngbin9805 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113099.pngbin12882 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113100.pngbin38529 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113101.pngbin45933 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113102.pngbin7126 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113103.pngbin34693 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113104.pngbin61810 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113105.pngbin26365 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113106.pngbin45911 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113107.pngbin31789 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113108.pngbin39198 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113109.pngbin13295 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113110.pngbin38715 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113111.pngbin52694 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113112.pngbin39276 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113113.pngbin46459 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113114.pngbin64661 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113115.pngbin38902 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113116.pngbin9252 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113117.pngbin40855 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113118.pngbin13796 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/3113119.pngbin39115 -> 0 bytes
-rw-r--r--doc/book/src/java-broker/images/HA-BDBHAMessageStore-MBean-jconsole.pngbin52500 -> 52533 bytes
-rw-r--r--doc/book/src/java-broker/images/Management-Web-Console.pngbin0 -> 62590 bytes
-rw-r--r--doc/book/src/programming/Programming-In-Apache-Qpid-Book.xml6510
-rw-r--r--doc/book/src/programming/Programming-In-Apache-Qpid.xml6530
-rw-r--r--doc/book/xsl/html-custom.xsl2
-rw-r--r--extras/dispatch/CMakeLists.txt99
-rw-r--r--extras/dispatch/include/qpid/dispatch/agent.h108
-rw-r--r--extras/dispatch/include/qpid/dispatch/alloc.h72
-rw-r--r--extras/dispatch/include/qpid/dispatch/buffer.h79
-rw-r--r--extras/dispatch/include/qpid/dispatch/container.h129
-rw-r--r--extras/dispatch/include/qpid/dispatch/ctools.h146
-rw-r--r--extras/dispatch/include/qpid/dispatch/hash.h37
-rw-r--r--extras/dispatch/include/qpid/dispatch/iovec.h32
-rw-r--r--extras/dispatch/include/qpid/dispatch/iterator.h113
-rw-r--r--extras/dispatch/include/qpid/dispatch/log.h31
-rw-r--r--extras/dispatch/include/qpid/dispatch/message.h165
-rw-r--r--extras/dispatch/include/qpid/dispatch/router.h35
-rw-r--r--extras/dispatch/include/qpid/dispatch/server.h403
-rw-r--r--extras/dispatch/include/qpid/dispatch/threading.h45
-rw-r--r--extras/dispatch/include/qpid/dispatch/timer.h86
-rw-r--r--extras/dispatch/include/qpid/dispatch/user_fd.h121
-rw-r--r--extras/dispatch/router/CMakeLists.txt31
-rw-r--r--extras/dispatch/router/src/main.c122
-rw-r--r--extras/dispatch/site/css/style.css280
-rw-r--r--extras/dispatch/site/images/arch.diabin0 -> 1352 bytes
-rw-r--r--extras/dispatch/site/images/arch.pngbin0 -> 6170 bytes
-rw-r--r--extras/dispatch/site/includes/footer.include7
-rw-r--r--extras/dispatch/site/includes/header.include6
-rw-r--r--extras/dispatch/site/includes/menu.include68
-rwxr-xr-xextras/dispatch/site/index.html101
-rw-r--r--extras/dispatch/src/agent.c151
-rw-r--r--extras/dispatch/src/alloc.c210
-rw-r--r--extras/dispatch/src/alloc_private.h26
-rw-r--r--extras/dispatch/src/auth.c75
-rw-r--r--extras/dispatch/src/auth.h27
-rw-r--r--extras/dispatch/src/buffer.c83
-rw-r--r--extras/dispatch/src/container.c616
-rw-r--r--extras/dispatch/src/hash.c223
-rw-r--r--extras/dispatch/src/iovec.c81
-rw-r--r--extras/dispatch/src/iterator.c268
-rw-r--r--extras/dispatch/src/log.c56
-rw-r--r--extras/dispatch/src/message.c1120
-rw-r--r--extras/dispatch/src/message_private.h94
-rw-r--r--extras/dispatch/src/posix/threading.c126
-rw-r--r--extras/dispatch/src/router_node.c424
-rw-r--r--extras/dispatch/src/server.c903
-rw-r--r--extras/dispatch/src/server_private.h96
-rw-r--r--extras/dispatch/src/timer.c236
-rw-r--r--extras/dispatch/src/timer_private.h51
-rw-r--r--extras/dispatch/src/work_queue.c132
-rw-r--r--extras/dispatch/src/work_queue.h33
-rw-r--r--extras/dispatch/tests/CMakeLists.txt34
-rw-r--r--extras/dispatch/tests/alloc_test.c86
-rw-r--r--extras/dispatch/tests/message_test.c119
-rw-r--r--extras/dispatch/tests/run_tests.c36
-rw-r--r--extras/dispatch/tests/server_test.c195
-rw-r--r--extras/dispatch/tests/test_case.h36
-rw-r--r--extras/dispatch/tests/timer_test.c388
-rw-r--r--extras/dispatch/tests/tool_test.c159
-rwxr-xr-xextras/qmf/setup.py2
-rw-r--r--extras/qmf/src/py/qmf/console.py22
-rw-r--r--gentools/LICENSE202
-rw-r--r--gentools/NOTICE2
-rw-r--r--gentools/README.txt61
-rwxr-xr-xgentools/build37
-rw-r--r--gentools/build.xml43
-rw-r--r--gentools/lib/LICENSE0
-rw-r--r--gentools/lib/NOTICE0
-rw-r--r--gentools/lib/README.txt0
-rw-r--r--gentools/lib/velocity-1.4.jarbin361173 -> 0 bytes
-rw-r--r--gentools/lib/velocity-dep-1.4.jarbin517761 -> 0 bytes
-rw-r--r--gentools/templ.cpp/method/MethodBodyClass.h.tmpl112
-rw-r--r--gentools/templ.cpp/model/AMQP_ClientOperations.h.tmpl82
-rw-r--r--gentools/templ.cpp/model/AMQP_ClientProxy.cpp.tmpl52
-rw-r--r--gentools/templ.cpp/model/AMQP_ClientProxy.h.tmpl75
-rw-r--r--gentools/templ.cpp/model/AMQP_Constants.h.tmpl34
-rw-r--r--gentools/templ.cpp/model/AMQP_HighestVersion.h.tmpl42
-rw-r--r--gentools/templ.cpp/model/AMQP_MethodVersionMap.cpp.tmpl62
-rw-r--r--gentools/templ.cpp/model/AMQP_MethodVersionMap.h.tmpl57
-rw-r--r--gentools/templ.cpp/model/AMQP_ServerOperations.h.tmpl83
-rw-r--r--gentools/templ.cpp/model/AMQP_ServerProxy.cpp.tmpl51
-rw-r--r--gentools/templ.cpp/model/AMQP_ServerProxy.h.tmpl74
-rw-r--r--gentools/templ.java/PropertyContentHeaderClass.tmpl208
-rw-r--r--gentools/templ.java/method/version/MethodBodyClass.vm190
-rw-r--r--gentools/templ.java/model/ProtocolVersionListClass.vm154
-rw-r--r--gentools/templ.java/model/version/AmqpConstantsClass.vm37
-rw-r--r--gentools/templ.java/model/version/MethodRegistryClass.vm145
-rw-r--r--gentools/xml-src/amqp-0.10.test.xml4241
-rw-r--r--gentools/xml-src/amqp-0.8.test.xml3959
-rw-r--r--gentools/xml-src/amqp-0.9.test.xml4282
-rw-r--r--gentools/xml-src/cluster-0.9.test.xml59
-rw-r--r--java/.gitignore1
-rw-r--r--java/amqp-1-0-client-jms/build.xml3
-rw-r--r--java/amqp-1-0-client-jms/example/build.xml28
-rw-r--r--java/amqp-1-0-client-jms/resources/LICENSE204
-rw-r--r--java/amqp-1-0-client-jms/resources/NOTICE5
-rw-r--r--java/amqp-1-0-client-jms/resources/README.txt7
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionFactoryImpl.java79
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionImpl.java172
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/DecodedDestination.java47
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageConsumerImpl.java6
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageImpl.java183
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageProducerImpl.java5
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ObjectMessageImpl.java20
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueBrowserImpl.java151
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueReceiverImpl.java2
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/SessionImpl.java20
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java2
-rw-r--r--java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/jndi/PropertiesFileInitialContextFactory.java3
-rw-r--r--java/amqp-1-0-client/build.xml3
-rw-r--r--java/amqp-1-0-client/example/build.xml28
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Command.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Command.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Demo.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Demo.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Dump.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Dump.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Filereceiver.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Filereceiver.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Filesender.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Filesender.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Receive.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Receive.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Request.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Request.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Respond.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Respond.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Send.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Send.java)0
-rw-r--r--java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Util.java (renamed from java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Util.java)0
-rw-r--r--java/amqp-1-0-client/resources/LICENSE204
-rw-r--r--java/amqp-1-0-client/resources/NOTICE5
-rw-r--r--java/amqp-1-0-client/resources/README.txt7
-rw-r--r--java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Connection.java115
-rw-r--r--java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/ReadBytes.java77
-rw-r--r--java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Receiver.java35
-rw-r--r--java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/SendBytes.java331
-rw-r--r--java/amqp-1-0-common/resources/LICENSE204
-rw-r--r--java/amqp-1-0-common/resources/NOTICE5
-rw-r--r--java/amqp-1-0-common/resources/README.txt7
-rw-r--r--java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java27
-rw-r--r--java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/AMQFrame.java8
-rw-r--r--java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/ConnectionHandler.java23
-rw-r--r--java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java13
-rw-r--r--java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/Delivery.java4
-rw-r--r--java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ReceivingLinkEndpoint.java24
-rwxr-xr-xjava/bdbstore/bin/backup.sh5
-rw-r--r--java/bdbstore/build.xml17
-rw-r--r--java/bdbstore/jmx/MANIFEST.MF20
-rw-r--r--java/bdbstore/jmx/build.xml6
-rw-r--r--java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBean.java3
-rw-r--r--java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java11
-rw-r--r--java/bdbstore/jmx/src/main/resources/META-INF/services/org.apache.qpid.server.jmx.MBeanProvider18
-rw-r--r--java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java36
-rw-r--r--java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java12
-rw-r--r--java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanTest.java3
-rw-r--r--java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java169
-rw-r--r--java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java4
-rw-r--r--java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreFactory.java41
-rw-r--r--java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java4
-rw-r--r--java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java41
-rw-r--r--java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/CommitThreadWrapper.java31
-rw-r--r--java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory20
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java2
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java74
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java2
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgradeTestPreparer.java62
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java127
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterBlackboxTest.java6
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java36
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/MessageStoreCreatorTest.java44
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java39
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4to5Test.java47
-rw-r--r--java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6Test.java63
-rw-r--r--java/bdbstore/src/test/resources/upgrade/bdbstore-v4/test-store/00000000.jdbbin1361990 -> 1366145 bytes
-rw-r--r--java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000000.jdbbin1361990 -> 1366145 bytes
-rw-r--r--java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000001.jdbbin1333643 -> 1336563 bytes
-rw-r--r--java/broker-plugins/access-control/MANIFEST.MF41
-rw-r--r--java/broker-plugins/access-control/build.xml6
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java7
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AclAction.java102
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AclRulePredicates.java102
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Action.java114
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ClientAction.java88
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java12
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java184
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Rule.java44
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/RuleSet.java113
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/AccessControlFirewallException.java47
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/FirewallRule.java26
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/FirewallRuleFactory.java33
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/HostnameFirewallRule.java156
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/InetNetwork.java177
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/NetworkFirewallRule.java117
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/logging/AccessControl_logmessages.properties2
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControl.java116
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControlActivator.java41
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControlConfiguration.java83
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java122
-rw-r--r--java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java59
-rw-r--r--java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlFactory19
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/AclActionTest.java66
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/AclRulePredicatesTest.java87
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/ActionTest.java95
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/ClientActionTest.java79
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java463
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/RuleTest.java53
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/firewall/HostnameFirewallRuleTest.java99
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/firewall/NetworkFirewallRuleTest.java115
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/AccessControlTest.java355
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java69
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlTest.java368
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/PlainConfigurationTest.java394
-rw-r--r--java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java92
-rw-r--r--java/broker-plugins/firewall/MANIFEST.MF34
-rw-r--r--java/broker-plugins/firewall/build.xml34
-rw-r--r--java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/config/FirewallException.java46
-rw-r--r--java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/config/FirewallRule.java136
-rw-r--r--java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/Firewall.java137
-rw-r--r--java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/FirewallActivator.java41
-rw-r--r--java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/FirewallConfiguration.java103
-rw-r--r--java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java322
-rw-r--r--java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java294
-rw-r--r--java/broker-plugins/management-http/MANIFEST.MF70
-rw-r--r--java/broker-plugins/management-http/build.xml51
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java416
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java41
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/Management.java248
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ManagementActivator.java73
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ManagementConfiguration.java77
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/DefinedFileServlet.java2
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/FileServlet.java5
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/ExchangesServlet.java208
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/VhostsServlet.java118
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java447
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java15
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogoutServlet.java65
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java8
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java41
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java38
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java95
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java9
-rw-r--r--java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/session/LoginLogoutReporter.java103
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/authenticationprovider/showPrincipalDatabaseAuthenticationManager.html2
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/group/addGroupMember.html37
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/group/showGroup.html30
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/groupprovider/addGroup.html38
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/groupprovider/showFileGroupManager.html28
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/index.html90
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/authorization/sasl.js59
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js7
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Exchange.js2
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/GroupProvider.js109
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js4
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js8
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/group/Group.js204
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/group/addGroupMember.js108
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/groupprovider/FileGroupManager.js251
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/treeView.js6
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/management.html92
-rw-r--r--java/broker-plugins/management-http/src/main/java/resources/showGroupProvider.html25
-rw-r--r--java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory19
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java61
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/Asserts.java249
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/AuthenticationProviderRestTest.java73
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BindingRestTest.java129
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BrokerRestHttpsTest.java86
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BrokerRestTest.java118
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConnectionRestTest.java213
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ExchangeRestTest.java87
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsRestTest.java42
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/MessagesRestTest.java354
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/PortRestTest.java61
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QpidRestTestCase.java245
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QueueRestTest.java225
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslRestTest.java42
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureRestTest.java115
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/UserRestTest.java112
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostRestTest.java434
-rw-r--r--java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/session/LoginLogoutReporterTest.java74
-rw-r--r--java/broker-plugins/management-jmx/MANIFEST.MF66
-rw-r--r--java/broker-plugins/management-jmx/build.xml20
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/CustomRMIServerSocketFactory.java68
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXActivator.java136
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXConfiguration.java76
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java407
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java343
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java49
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXService.java193
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java101
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanProvider.java5
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporter.java95
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameAccessor.java26
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameCachingRMIJRMPServer.java100
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConfigurationManagementMBean.java56
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBean.java53
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java5
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java66
-rw-r--r--java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java5
-rw-r--r--java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory19
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java60
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogActorTest.java170
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporterTest.java101
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java6
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java124
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java149
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java317
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/QueueManagementTest.java696
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java204
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java251
-rw-r--r--java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java39
-rwxr-xr-xjava/broker/bin/qpid-server4
-rw-r--r--java/broker/bin/qpid-server.bat4
-rw-r--r--java/broker/build.xml30
-rw-r--r--java/broker/etc/broker_example.acl94
-rw-r--r--java/broker/etc/config.xml106
-rw-r--r--java/broker/etc/groups29
-rw-r--r--java/broker/etc/log4j.xml23
-rwxr-xr-xjava/broker/src/main/java/broker.bnd2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/CompletionCode.java36
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/ManagementExchange.java586
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFBrokerRequestCommand.java82
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFBrokerResponseCommand.java45
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFClass.java156
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFClassIndicationCommand.java48
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFClassQueryCommand.java105
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFCommand.java54
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandCompletionCommand.java63
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandDecoder.java98
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandHeader.java63
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFEventClass.java42
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFEventCommand.java47
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFEventSeverity.java33
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFGetQueryCommand.java205
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFMessage.java256
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFMethod.java157
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodInvocation.java26
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodRequestCommand.java95
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodResponseCommand.java76
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFObject.java81
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFObjectClass.java44
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFOperation.java67
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFPackage.java67
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFPackageIndicationCommand.java44
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFPackageQueryCommand.java98
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFProperty.java120
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFSchemaRequestCommand.java102
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFSchemaResponseCommand.java81
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFService.java2086
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFStatistic.java61
-rw-r--r--java/broker/src/main/java/org/apache/qpid/qmf/QMFType.java53
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java193
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/Broker.java376
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java156
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/Main.java255
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java74
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/ProtocolInclusion.java74
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/TransactionTimeoutHelper.java69
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/binding/Binding.java13
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/binding/BindingFactory.java25
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfig.java41
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfigType.java114
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfig.java48
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfigType.java170
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfig.java71
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigType.java145
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java102
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java54
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigObjectType.java30
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigProperty.java66
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java201
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java203
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java98
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java54
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java35
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObject.java37
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java28
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfig.java49
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfigType.java146
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfig.java60
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigType.java115
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigurationPlugin.java29
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java37
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfig.java56
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfigType.java137
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfig.java86
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfigType.java123
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java45
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java28
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java1031
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java90
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfig.java55
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfigType.java137
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfig.java47
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfigType.java140
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfig.java42
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigImpl.java137
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigType.java132
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfig.java78
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfiguration.java270
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfig.java32
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfigType.java99
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java197
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java111
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java329
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java488
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java38
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionConfiguration.java86
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionPolicyConfiguration.java74
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionQueueConfiguration.java163
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java55
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java139
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java112
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java74
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java40
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java66
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java52
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java44
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java40
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java51
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java711
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java327
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java205
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java41
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java67
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java78
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java74
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java324
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java32
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java101
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java1
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java42
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java53
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java18
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java1
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java37
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java36
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java51
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java36
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java52
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java41
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java53
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/federation/Bridge.java913
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/federation/BrokerLink.java692
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java19
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java29
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java13
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java5
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java14
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java7
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java68
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java5
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java62
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java62
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingFacade.java579
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java579
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties11
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/logging/subjects/LogSubjectFormat.java8
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java11
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java14
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/Broker.java124
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java1
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java22
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/Group.java52
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/GroupMember.java52
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java55
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java51
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/Model.java8
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java52
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/Port.java22
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java97
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/Transport.java26
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java65
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java15
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/User.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java22
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java271
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java198
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java152
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java251
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java199
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java77
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java15
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java807
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java63
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java16
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java25
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java550
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/HTTPPortAdapter.java273
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java48
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java169
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java222
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java56
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java19
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java43
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java332
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java9
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterImpl.java117
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java28
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java31
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java36
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java28
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java32
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java72
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java51
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java91
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties135
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java32
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java32
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java403
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java99
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java3
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java92
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java12
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java149
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java63
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java68
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java9
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java104
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java22
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java26
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java39
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/queue/InboundMessageAdapter.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java32
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryImpl.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java103
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java624
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/registry/BrokerConfigAdapter.java195
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java42
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java94
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java57
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java122
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java45
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/security/AuthorizationHolder.java12
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java235
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java47
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java75
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java30
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/SubjectCreator.java137
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java206
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectType.java7
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java43
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java86
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipal.java127
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticationResult.java75
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/SubjectAuthenticationResult.java76
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/UsernamePrincipal.java77
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java2
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java169
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java71
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java92
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java40
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java15
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java32
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java203
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java42
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java92
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java40
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/IAuthenticationManagerRegistry.java59
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java88
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java39
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java42
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java249
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java254
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java69
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java88
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipal.java99
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java1
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipal.java99
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServer.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java6
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java287
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java147
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java51
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/group/GroupDatabase.java34
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java40
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipal.java100
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java54
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java89
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java33
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/store/ConfigurationRecoveryHandler.java14
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStore.java11
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java3
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStoreFactory.java39
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java66
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreFactory.java28
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/NullMessageStore.java22
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/State.java4
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java350
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java41
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java40
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java37
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java81
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java55
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java76
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java153
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java15
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/txn/AsyncAutoCommitTransaction.java9
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/txn/AutoCommitTransaction.java11
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/txn/DistributedTransaction.java20
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/txn/LocalTransaction.java77
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java11
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java361
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java22
-rwxr-xr-xjava/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java56
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java173
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java213
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/ConfiguredQueueBindingListener.java105
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetection.java174
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java61
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java42
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java28
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/logging/SlowConsumerDetection_logmessages.properties23
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/logging/TopicDeletePolicy_logmessages.properties22
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicy.java141
-rw-r--r--java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfiguration.java82
-rw-r--r--java/broker/src/main/java/org/apache/qpid/slowconsumerdetection/policies/SlowConsumerPolicyPlugin.java29
-rw-r--r--java/broker/src/main/java/org/apache/qpid/slowconsumerdetection/policies/SlowConsumerPolicyPluginFactory.java27
-rw-r--r--java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory19
-rw-r--r--java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory24
-rw-r--r--java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType22
-rw-r--r--java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory19
-rw-r--r--java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory20
-rw-r--r--java/broker/src/main/resources/initial-store.json58
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java103
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java181
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/MainTest.java170
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/TransactionTimeoutHelperTest.java203
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java71
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java144
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerPropertiesTest.java51
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/MockConnectionConfig.java171
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java157
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java1766
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/TopicConfigurationTest.java131
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java155
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java210
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java210
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java405
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java62
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java97
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java111
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java117
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java108
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java124
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java392
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java216
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java341
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java83
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java296
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java54
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java226
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersBindingTest.java28
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java16
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java53
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java5
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java150
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java26
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/AbstractManagementActorTest.java86
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java66
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java35
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java7
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java94
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java40
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java12
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java13
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingFacadeTest.java245
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java243
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java13
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java23
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/messages/ManagementConsoleMessagesTest.java21
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java47
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java17
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java1
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java26
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java16
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java16
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java15
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java24
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java189
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/model/UUIDGeneratorTest.java6
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java85
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java212
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java129
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java94
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java55
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java28
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java42
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java50
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java28
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java68
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java28
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/queue/InboundMessageAdapterTest.java97
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java34
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java74
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java27
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java104
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/SubjectCreatorTest.java138
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipalTest.java147
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipalTestHelper.java54
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticationResultTest.java112
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/TestPrincipalUtils.java49
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/UsernamePrincipalTest.java70
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java2
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java2
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java158
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java47
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java304
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactoryTest.java111
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java58
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactoryTest.java111
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java364
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java48
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java183
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipalTest.java86
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java6
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalUtils.java48
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java123
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupDatabaseTest.java456
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java77
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java197
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.java80
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalTest.java88
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java119
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java10
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreCreatorTest.java39
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java51
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java13
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java17
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java79
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java56
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java48
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/txn/AsyncAutoCommitTransactionTest.java2
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/txn/AutoCommitTransactionTest.java8
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/txn/LocalTransactionTest.java127
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java6
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java209
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java372
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java121
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java69
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java107
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionConfigurationTest.java347
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionPolicyConfigurationTest.java105
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionQueueConfigurationTest.java186
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfigurationTest.java89
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyTest.java294
-rw-r--r--java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm19
-rw-r--r--java/build.deps22
-rw-r--r--java/build.xml6
-rw-r--r--java/client/build.xml2
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/Drain.java2
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/ListReceiver.java101
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/ListSender.java86
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/Spout.java1
-rwxr-xr-xjava/client/src/main/java/client.bnd2
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java9
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnection.java50
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java2
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java36
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java50
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java2
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQDestination.java101
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQSession.java225
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java408
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java177
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQTopic.java4
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java19
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java23
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java22
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java100
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java44
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java30
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/HeartbeatListener.java37
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/XASessionImpl.java2
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java24
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java21
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedListMessage.java935
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedListMessageFactory.java44
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java9
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/JMSStreamMessage.java5
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java1
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/messaging/address/AddressHelper.java203
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/messaging/address/Link.java90
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/messaging/address/Node.java85
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java152
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java9
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatDiagnostics.java125
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java64
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java10
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java7
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java18
-rw-r--r--java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java17
-rw-r--r--java/client/src/main/java/org/apache/qpid/jms/ListMessage.java55
-rw-r--r--java/client/src/main/java/org/apache/qpid/jms/MessageProducer.java14
-rw-r--r--java/client/src/main/java/org/apache/qpid/jms/Session.java3
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java67
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/AMQSession_0_10Test.java15
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java6
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/message/AMQPEncodedListMessageUnitTest.java153
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/messaging/address/AddressHelperTest.java146
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/security/DynamicSaslRegistrarTest.java140
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java42
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java128
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java120
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java14
-rw-r--r--java/common.xml11
-rwxr-xr-xjava/common/bin/qpid-run8
-rw-r--r--java/common/build.xml21
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpClass.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpClass.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpClassMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpConstant.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpConstant.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpDomain.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpDomain.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpField.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpField.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpMethod.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpMethod.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpModel.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpModel.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpParseException.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpParseException.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpVersion.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpVersion.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java (renamed from gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/BitFieldGenerateMethod.java (renamed from gentools/src/org/apache/qpid/gentools/BitFieldGenerateMethod.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/CommandGenerateMethod.java (renamed from gentools/src/org/apache/qpid/gentools/CommandGenerateMethod.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/ConsolidatedField.java (renamed from gentools/src/org/apache/qpid/gentools/ConsolidatedField.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/CppGenerator.java (renamed from gentools/src/org/apache/qpid/gentools/CppGenerator.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/DotnetGenerator.java (renamed from gentools/src/org/apache/qpid/gentools/DotnetGenerator.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/GenerateMethod.java (renamed from gentools/src/org/apache/qpid/gentools/GenerateMethod.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/Generator.java (renamed from gentools/src/org/apache/qpid/gentools/Generator.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/JavaGenerator.java (renamed from gentools/src/org/apache/qpid/gentools/JavaGenerator.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/LanguageConverter.java (renamed from gentools/src/org/apache/qpid/gentools/LanguageConverter.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/Main.java (renamed from gentools/src/org/apache/qpid/gentools/Main.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java (renamed from gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/NodeAware.java (renamed from gentools/src/org/apache/qpid/gentools/NodeAware.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/Printable.java (renamed from gentools/src/org/apache/qpid/gentools/Printable.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java (renamed from gentools/src/org/apache/qpid/gentools/SingleVersionClass.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/SingleVersionField.java (renamed from gentools/src/org/apache/qpid/gentools/SingleVersionField.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java (renamed from gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java (renamed from gentools/src/org/apache/qpid/gentools/SingleVersionModel.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java (renamed from gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/Utils.java (renamed from gentools/src/org/apache/qpid/gentools/Utils.java)0
-rw-r--r--java/common/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java (renamed from gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java)0
-rw-r--r--java/common/protocol-version.xml70
-rwxr-xr-xjava/common/src/main/java/common.bnd2
-rw-r--r--java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java15
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java19
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/FieldTable.java1
-rw-r--r--java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java27
-rw-r--r--java/common/src/main/java/org/apache/qpid/protocol/ProtocolEngine.java5
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/Connection.java88
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java8
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/ServerDelegate.java5
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/Session.java22
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/NetworkConnection.java4
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java5
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/Ticker.java29
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/TransportActivity.java33
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/io/IdleTimeoutTicker.java87
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkConnection.java31
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java51
-rw-r--r--java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java100
-rw-r--r--java/common/src/main/java/org/apache/qpid/url/BindingURL.java3
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/FileUtils.java13
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/NetMatcher.java300
-rw-r--r--java/common/src/test/java/org/apache/qpid/framing/FieldTableTest.java938
-rw-r--r--java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java980
-rw-r--r--java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java10
-rw-r--r--java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java90
-rw-r--r--java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java7
-rw-r--r--java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java12
-rw-r--r--java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java5
-rw-r--r--java/common/src/test/java/org/apache/qpid/transport/network/io/IdleTimeoutTickerTest.java257
-rw-r--r--java/ivy.nexus.xml42
-rw-r--r--java/ivy.retrieve.xml3
-rw-r--r--java/ivysettings.retrieve.xml2
-rw-r--r--java/jca/README-JBOSS-EAP6.txt183
-rw-r--r--java/jca/README-JBOSS.txt26
-rw-r--r--java/jca/build.xml25
-rw-r--r--java/jca/rar/src/main/resources/META-INF/jboss-ra.xml (renamed from java/jca/src/main/resources/META-INF/jboss-ra.xml)0
-rwxr-xr-xjava/jca/rar/src/main/resources/META-INF/ra.xml (renamed from java/jca/src/main/resources/META-INF/ra.xml)0
-rw-r--r--java/jca/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxy.java73
-rw-r--r--java/management/common/src/main/java/management-common.bnd2
-rw-r--r--java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ConfigurationManagement.java41
-rw-r--r--java/management/example/src/main/java/org/apache/qpid/example/jmxexample/AddQueue.java41
-rw-r--r--java/module.xml208
-rw-r--r--java/perftests/build.xml2
-rw-r--r--java/perftests/etc/chartdefs/1001-MessageSize-Transient-ByteSec.chartdef37
-rw-r--r--java/perftests/etc/chartdefs/1001-MessageSize-Transient.chartdef32
-rw-r--r--java/perftests/etc/chartdefs/1002-MessageSize-Persistent-ByteSec.chartdef37
-rw-r--r--java/perftests/etc/chartdefs/1002-MessageSize-Persistent.chartdef32
-rw-r--r--java/perftests/etc/chartdefs/1003-MessageSize-Transient-MsgSec.chartdef37
-rw-r--r--java/perftests/etc/chartdefs/1004-MessageSize-Persistent-MsgSec.chartdef37
-rw-r--r--java/perftests/etc/chartdefs/1011-VaryingNumberOfProducers-AutoAck.chartdef47
-rw-r--r--java/perftests/etc/chartdefs/1011-VaryingNumberOfProducers.chartdef40
-rw-r--r--java/perftests/etc/chartdefs/1012-VaryingNumberOfConsumers-AutoAck.chartdef47
-rw-r--r--java/perftests/etc/chartdefs/1012-VaryingNumberOfConsumers.chartdef40
-rw-r--r--java/perftests/etc/chartdefs/1015-VaryingNumberOfProducers-SessionTrans.chartdef47
-rw-r--r--java/perftests/etc/chartdefs/1016-VaryingNumberOfConsumers-SessionTrans.chartdef47
-rw-r--r--java/perftests/etc/chartdefs/1021-AcknowledgementModes-Persistent.chartdef13
-rw-r--r--java/perftests/etc/chartdefs/1022-AcknowledgementModes-Transient.chartdef10
-rw-r--r--java/perftests/etc/chartdefs/1030-BatchSize-Equal.chartdef37
-rw-r--r--java/perftests/etc/chartdefs/1030-BatchSize.chartdef33
-rw-r--r--java/perftests/etc/chartdefs/1031-BatchSize-Unequal.chartdef53
-rw-r--r--java/perftests/etc/chartdefs/1040-QueueTypes.chartdef10
-rw-r--r--java/perftests/etc/chartdefs/1050-VaryingNumberOfProducerSessionsSingleConnection.chartdef49
-rw-r--r--java/perftests/etc/chartdefs/1300-QueueConsumersWithNonOverlappingSelectors-Transient.chartdef37
-rw-r--r--java/perftests/etc/chartdefs/1301-QueueConsumersWithNonOverlappingSelectors-Persistent.chartdef43
-rw-r--r--java/perftests/etc/chartdefs/1302-QueueConsumersWithOverlappingSelectors-Transient.chartdef36
-rw-r--r--java/perftests/etc/chartdefs/1303-QueueConsumersWithOverlappingSelectors-Persistent.chartdef42
-rw-r--r--java/perftests/etc/chartdefs/1500-Topic-NumberOfConsumers.chartdef11
-rw-r--r--java/perftests/etc/chartdefs/1501-Topic-NumberOfTopics.chartdef11
-rw-r--r--java/perftests/etc/chartdefs/1502-Topic-Persistence.chartdef13
-rw-r--r--java/perftests/etc/chartdefs/1503-Topic-AckModes.chartdef13
-rw-r--r--java/perftests/etc/chartdefs/2001-Latency-MessageSize-Transient.chartdef6
-rw-r--r--java/perftests/etc/chartdefs/2002-Latency-MessageSize-Persistent.chartdef6
-rw-r--r--java/perftests/etc/chartdefs/2011-Latency-QueuesWithNonOverlappingSelectors-Transient.chartdef6
-rw-r--r--java/perftests/etc/chartdefs/2012-Latency-QueuesWithOverlappingSelectors-Transient.chartdef6
-rw-r--r--java/perftests/etc/chartdefs/2021-Latency-QueuesWithNonOverlappingSelectors-Persistent.chartdef6
-rw-r--r--java/perftests/etc/chartdefs/2022-Latency-QueuesWithOverlappingSelectors-Persistent.chartdef6
-rw-r--r--java/perftests/etc/chartdefs/2031-Latency-VaryingNumberOfParticipants.chartdef7
-rw-r--r--java/perftests/etc/chartdefs/2041-Latency-QueueTypes.chartdef6
-rw-r--r--java/perftests/etc/chartdefs/timeseries/1001-Large-Messages-Transient.chartdef29
-rw-r--r--java/perftests/etc/chartdefs/timeseries/1002-Large-Messages-Persistent.chartdef29
-rw-r--r--java/perftests/etc/chartdefs/timeseries/1011-MultipleProducersAndConsumers-Persistent.chartdef30
-rw-r--r--java/perftests/etc/chartdefs/timeseries/1030-Batch-Size-Small.chartdef30
-rw-r--r--java/perftests/etc/chartdefs/timeseries/1031-Batch-Size-Large.chartdef30
-rw-r--r--java/perftests/etc/chartdefs/timeseries/1040-SortedQueue.chartdef30
-rw-r--r--java/perftests/etc/perftests-jndi.properties4
-rwxr-xr-xjava/perftests/etc/run-perftests.sh37
-rw-r--r--java/perftests/etc/testdefs/BatchSize.js102
-rw-r--r--java/perftests/etc/testdefs/BatchSize.json84
-rw-r--r--java/perftests/etc/testdefs/BatchSizeConsumerVaries.js102
-rw-r--r--java/perftests/etc/testdefs/BatchSizeProducerVaries.js102
-rw-r--r--java/perftests/etc/testdefs/QueueConsumersWithNonOverlappingSelectors.js120
-rw-r--r--java/perftests/etc/testdefs/QueueConsumersWithOverlappingSelectors.js131
-rw-r--r--java/perftests/etc/testdefs/Topic-AckModes.js9
-rw-r--r--java/perftests/etc/testdefs/Topic-NumberOfConsumers.js4
-rw-r--r--java/perftests/etc/testdefs/Topic-NumberOfTopics.js4
-rw-r--r--java/perftests/etc/testdefs/Topic-Persistence.js8
-rw-r--r--java/perftests/etc/testdefs/VaryingNumberOfParticipants.json272
-rw-r--r--java/perftests/etc/testdefs/VaryingNumberOfProducerSessionsSingleConnection.js95
-rwxr-xr-xjava/perftests/etc/visualisation-timeseries.sh33
-rwxr-xr-xjava/perftests/etc/visualisation.sh35
-rw-r--r--java/perftests/example/brokerconfig/log4j.xml2
-rw-r--r--java/perftests/example/perftests-jndi.properties3
-rwxr-xr-xjava/perftests/example/run.sh2
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java6
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/ConfigFileHelper.java11
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/ControllerRunner.java84
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/ResultsFileWriter.java112
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/client/ConsumerParticipant.java17
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java10
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java56
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java36
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/controller/ResultsForAllTests.java21
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ConsumerConfig.java6
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ParticipantConfig.java4
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java2
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/db/ResultsDbWriter.java467
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java64
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java4
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java5
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java101
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java5
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/message/ConsumerParticipantResult.java4
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateConsumerCommand.java11
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateParticpantCommand.java11
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttribute.java42
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantResult.java54
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/message/ProducerParticipantResult.java4
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ITestResult.java2
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregator.java11
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregator.java24
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/results/formatting/CSVFormater.java89
-rw-r--r--java/perftests/src/main/java/org/apache/qpid/disttest/results/formatting/CSVFormatter.java91
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java8
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java85
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java4
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java15
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java25
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java34
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java8
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java4
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java6
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java6
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java4
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java4
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java6
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java44
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java10
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java4
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js22
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java9
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java4
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js22
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java7
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java2
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java158
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java11
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsTestFixture.java138
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java5
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java30
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java4
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java45
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormaterTest.java146
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormatterTest.java62
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java6
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv4
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java42
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java6
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java13
-rw-r--r--java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties3
-rw-r--r--java/perftests/visualisation-jfc/build.xml4
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java2
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java67
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java2
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java2
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java72
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java60
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryStrokeAndPaintApplier.java41
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java4
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ColorFactory.java66
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java2
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java2
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesPainter.java63
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesStrokeAndPaintApplier.java35
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java111
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarChartBuilder.java114
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesHolder.java70
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesLineChartBuilder.java59
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java70
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java12
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java6
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java27
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java7
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/DatasetHolder.java37
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilder.java141
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java157
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGenerator.java81
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java15
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java30
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRow.java98
-rw-r--r--java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java44
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilderTest.java125
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java13
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java130
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ColorFactoryTest.java42
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesBuilderCallbackTest.java72
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java13
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java32
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilderTest.java94
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java103
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGeneratorTest.java85
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRowTest.java64
-rw-r--r--java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/ChartWriterTest.java35
-rwxr-xr-xjava/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/expected-chart-summary.html14
-rw-r--r--java/systests/build.xml4
-rw-r--r--java/systests/etc/config-systests-bdb-settings.xml26
-rw-r--r--java/systests/etc/config-systests-bdb.xml29
-rw-r--r--java/systests/etc/config-systests-derby-mem-settings.xml26
-rw-r--r--java/systests/etc/config-systests-derby-mem.xml29
-rw-r--r--java/systests/etc/config-systests-derby-settings.xml26
-rw-r--r--java/systests/etc/config-systests-derby.xml29
-rw-r--r--java/systests/etc/config-systests-firewall-2.xml83
-rw-r--r--java/systests/etc/config-systests-firewall-3.xml85
-rw-r--r--java/systests/etc/config-systests-firewall-settings.xml30
-rw-r--r--java/systests/etc/config-systests-firewall.xml30
-rw-r--r--java/systests/etc/config-systests-settings.xml103
-rw-r--r--java/systests/etc/config-systests.json64
-rw-r--r--java/systests/etc/groups-systests29
-rw-r--r--java/systests/etc/virtualhosts-systests-bdb-settings.xml26
-rw-r--r--java/systests/etc/virtualhosts-systests-derby-mem-settings.xml25
-rw-r--r--java/systests/etc/virtualhosts-systests-derby-settings.xml25
-rw-r--r--java/systests/etc/virtualhosts-systests-settings.xml125
-rw-r--r--java/systests/src/main/java/org/apache/qpid/client/AMQQueueDeferredOrderingTest.java12
-rw-r--r--java/systests/src/main/java/org/apache/qpid/client/HeartbeatTest.java116
-rw-r--r--java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java51
-rw-r--r--java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java285
-rw-r--r--java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java291
-rw-r--r--java/systests/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxyTest.java120
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java8
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java124
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java75
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java237
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java39
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java42
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java52
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java98
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java8
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java15
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java2
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java5
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java23
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java34
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLTest.java44
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java184
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java38
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java283
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java89
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java31
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java6
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/GlobalQueuesTest.java223
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/GlobalTopicsTest.java31
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/MergeConfigurationTest.java109
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/SubscriptionTest.java146
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/TestingBaseCase.java240
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/TopicTest.java85
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java126
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java (renamed from java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java)0
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java147
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java (renamed from java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java)0
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java330
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/QueueManagementTest.java778
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java210
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java260
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java37
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java270
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java73
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java121
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java130
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java69
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java120
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/ConnectionRestTest.java213
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/ExchangeRestTest.java87
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java160
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java109
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/LogRecordsRestTest.java42
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/MessagesRestTest.java354
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java64
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java84
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/QueueRestTest.java225
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java452
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java435
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java114
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java99
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java576
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java197
-rw-r--r--java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java200
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/client/RollbackOrderTest.java20
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java200
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java25
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java3
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java6
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java101
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java168
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java13
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java236
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java399
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java4
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java2
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java2
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java28
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java19
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java79
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java61
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java26
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java62
-rwxr-xr-x[-rw-r--r--]java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java502
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/QpidClientConnectionHelper.java295
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java219
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java30
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/TestUtils.java54
-rw-r--r--java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java39
-rwxr-xr-xjava/test-profiles/CPPExcludes24
-rw-r--r--java/test-profiles/Excludes1
-rwxr-xr-xjava/test-profiles/Java010Excludes6
-rw-r--r--java/test-profiles/JavaTransientExcludes2
-rw-r--r--java/test-profiles/cpp.ssl.excludes2
-rw-r--r--java/test-profiles/java-bdb-spawn.0-10.testprofile6
-rw-r--r--java/test-profiles/java-bdb-spawn.0-8.testprofile6
-rw-r--r--java/test-profiles/java-bdb-spawn.0-9-1.testprofile6
-rw-r--r--java/test-profiles/java-bdb-spawn.0-9.testprofile6
-rw-r--r--java/test-profiles/java-bdb.0-10.testprofile6
-rw-r--r--java/test-profiles/java-bdb.0-8.testprofile6
-rw-r--r--java/test-profiles/java-bdb.0-9-1.testprofile6
-rw-r--r--java/test-profiles/java-bdb.0-9.testprofile6
-rw-r--r--java/test-profiles/java-dby-mem.0-10.testprofile8
-rw-r--r--java/test-profiles/java-dby-mem.0-8.testprofile8
-rw-r--r--java/test-profiles/java-dby-mem.0-9-1.testprofile8
-rw-r--r--java/test-profiles/java-dby-mem.0-9.testprofile8
-rw-r--r--java/test-profiles/java-dby-spawn.0-10.testprofile6
-rw-r--r--java/test-profiles/java-dby-spawn.0-8.testprofile6
-rw-r--r--java/test-profiles/java-dby-spawn.0-9-1.testprofile6
-rw-r--r--java/test-profiles/java-dby-spawn.0-9.testprofile6
-rw-r--r--java/test-profiles/java-dby.0-10.testprofile6
-rw-r--r--java/test-profiles/java-dby.0-8.testprofile6
-rw-r--r--java/test-profiles/java-dby.0-9-1.testprofile6
-rw-r--r--java/test-profiles/java-dby.0-9.testprofile6
-rw-r--r--java/test-profiles/java-mms-spawn.0-10.testprofile5
-rw-r--r--java/test-profiles/java-mms-spawn.0-8.testprofile5
-rw-r--r--java/test-profiles/java-mms-spawn.0-9-1.testprofile5
-rw-r--r--java/test-profiles/java-mms-spawn.0-9.testprofile5
-rw-r--r--java/test-profiles/java-mms.0-10.testprofile5
-rw-r--r--java/test-profiles/java-mms.0-8.testprofile5
-rw-r--r--java/test-profiles/java-mms.0-9-1.testprofile5
-rw-r--r--java/test-profiles/java-mms.0-9.testprofile5
-rw-r--r--java/test-profiles/testprofile.defaults13
-rw-r--r--packaging/windows/INSTALL_NOTES.html8
-rw-r--r--packaging/windows/installer.proj8
-rw-r--r--packaging/windows/qpidc.wxs20
-rw-r--r--python/examples/README.txt5
-rwxr-xr-xpython/examples/api/receive194
-rwxr-xr-xpython/examples/api/send281
-rw-r--r--python/examples/api/statistics.py139
-rw-r--r--python/qpid/client.py10
-rw-r--r--python/qpid/connection08.py41
-rw-r--r--python/qpid/delegates.py20
-rw-r--r--python/qpid/messaging/driver.py19
-rw-r--r--python/qpid/messaging/endpoints.py2
-rw-r--r--python/qpid/messaging/transports.py36
-rw-r--r--python/qpid/testlib.py6
-rw-r--r--python/qpid/tests/__init__.py1
-rw-r--r--python/qpid/tests/util.py46
-rw-r--r--python/qpid/util.py26
-rwxr-xr-xpython/setup.py2
-rw-r--r--specs/management-schema.xml20
-rwxr-xr-xtests/setup.py2
-rw-r--r--tests/src/py/qpid_tests/broker_0_10/management.py24
-rw-r--r--tests/src/py/qpid_tests/broker_0_8/basic.py47
-rw-r--r--tests/src/py/qpid_tests/broker_0_9/__init__.py2
-rw-r--r--tests/src/py/qpid_tests/broker_0_9/messageheader.py35
-rwxr-xr-xtools/setup.py2
-rwxr-xr-xtools/src/py/qpid-cluster6
-rwxr-xr-xtools/src/py/qpid-config10
-rwxr-xr-xtools/src/py/qpid-ha11
-rwxr-xr-xtools/src/py/qpid-printevents6
-rwxr-xr-xtools/src/py/qpid-queue-stats5
-rwxr-xr-xtools/src/py/qpid-route6
-rwxr-xr-xtools/src/py/qpid-stat10
-rw-r--r--wcf/samples/Channel/HelloWorld/HelloWorld.cs1
2071 files changed, 122354 insertions, 96504 deletions
diff --git a/KEYS b/KEYS
index 8fb029ba20..ca3ef4d0fd 100644
--- a/KEYS
+++ b/KEYS
@@ -426,3 +426,58 @@ U6nOKyS2R4/y+0s1J85amn4YHTUhOHYRnQAEckX8DB0UtCP15FSmrN3aOBp7hbvm
MxumwmEHVDFpDpKCCnJa9A==
=Uryx
-----END PGP PUBLIC KEY BLOCK-----
+pub 4096R/845FD0AC 2012-11-06
+uid Ted Ross (CODE SIGNING KEY) <tross@apache.org>
+sub 4096R/59780337 2012-11-06
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+Version: GnuPG v1.4.12 (GNU/Linux)
+
+mQINBFCZY/EBEACWoKgXLUAPsunBvW6CpfAiif706gJAO+Svlg5QX7BWaYEl1yhj
+/x1MXCtiEgcDZMv+dBPXkLRNQpyxVe+wrYCFTLhZIfQHtWyd8kzphRQHL+igmiC0
+jC5y5ZutMTFnVgeHls4A80lKSJe+gcd2CdbxeVIEf8i1OLIVGLj6a+bNgfFLiL5K
+W297G+Xi8EYSccXqo9S/hleih7FTIioHeyJd/BBJI5eQIJVTz9cjaC1A3/tzluFO
+zu8fpVHRWY2jRd/pz/TkVbcpwPPMhS7vPzFMIexrs0LhGEn2C4D0XN82niA19as6
+KwKhJdiUX4vAowikX0U96CySY4H5pboq74wVYyq9kKqdNL0OlV79cCwwMkvjk7fn
+ANiBYLV/N3FQur349/QroUo5MtHgQP5mv/OSLBS00KHdhjRUCJfCiGkimU9LlWP3
+xaLZWPFgeA8tCzmsnpjFTbyFk0Ar/MaQvHVDK8ks52Vo7mvBo+b8VF+NsYis58pM
+EvjEBdAJhooB43aCIfTszEZYPSnSoOCr1l6TGNpj5m7TzxMbHGNOW3xKQxtKSHmY
+pWr8lEylknI+KZR7IAwf2NrjcJThVRv6ccwXFDP6H4hljEsSTlqOPh+rLpqbdmQe
+FEuakQFZALQhAsQyiJaogymLbrqCgVBVzpXdiX2+1TPiZps+VRaaQUd+HwARAQAB
+tC5UZWQgUm9zcyAoQ09ERSBTSUdOSU5HIEtFWSkgPHRyb3NzQGFwYWNoZS5vcmc+
+iQI3BBMBAgAhAhsDAh4BAheABQJQmWToBQsJCAcDBRUKCQgLBRYCAwEAAAoJEOaX
+VceEX9CsPsIP/igNMqFCDC+1xuK9oWgzp1WHT3yG6PsqTMh6fKRtD2wa0VTkcY4f
+BzoaJyK956tfQxMygcyhzGoj/Y7Oz6lsgIHKLVck64pqj5+heQJHaXjGIoqsUWQ2
+xyH/TkbXAK97BK2HBPAxla4qdB+mudUYspw6cfXRlRooNaBmlVTLP1F8j5HDNqb/
+ALz3fHcQfwFsTRSZVq89XZVROAYTygor1eLya7JxdTZdOIPJTeDocPRe3GR6BDDJ
+/mioXG9UEYIg/3Z6oWWTzkBCyV8LYef+Zg471bVsz4c4tut7DZClCA4eUJA3nLBD
+jMBJrEhzEGrfMaDVND+oFxPl4O/5Hw/jmG/EiGEA2OAAwh8ZgjXlpDrhlAAkHiVp
+2riTMMqDxBdbq8BZWhTqj7ZxB+CDMqr5t5LQb/GjHVXfmH8kfv/3z/PXoPwmMx6N
+nuMmDPkUy996ak2UYoVLNt4JVFEFqN2Zl/2MCOpCOs9L83FmGz5bbKnQ5dF7x566
+2woH31x+yplPP5jeFe9cgPnRgDrfbFqSBwBFmK+SAVTDtW3aOVAfOnVLq7M3+Q+q
+AWzs+hWA4pflQDpA6dtffUJ0xlAyGzUHnB8atfqf9bwcUBzdGybyf5Cg4QwZqSxt
+HX1Lj8Ba/FIT52pmyPF5YT6xdgZRk96JGpiraaNiTkZ0o22aabJ0QGtguQINBFCZ
+Y/EBEADHkmcxZjY6msJQfe6GQZ5k96pC3LJ0oa/1P1qAtLKONFt8WnaCOLlD4ozz
+8M1WXNMfZdVXD4rRs6FR62MshjRlVdcG59Eyi3q1UxH1tseJacUqkyuXapq41zi1
+ZDOtZPvPJHtiyyG0tS/Uu3Xk2HP7/ECVOMittis9++/BSXyVr9fap09ADWWYAIP7
+t8JZDfUPnEALYs0u9ofOjuEJh6aB1RFqmiVy1PMjHvxcz9AmMYN+AILIJgr2KS7N
+Swh43o8JSOf0503bwkTP6n6uv3g0/CyK60UI5BNJVn7PEuOVWoLcMSYBVRI04lwm
+B19T0QUR3ulUIJy43BAFX4nk3QIFbDdXehhbXP/1bBN87CyMMJRN4zAqR9Tg/pD7
+ZJDUdlXaZ+4WW/A43oYfqx1kBFJQN5Xvxb6KCVWTvw6wIGNxSG2gioYVyXqIbed/
+mZJ5FHJA/ZRvbN7MCaF1Yf34ERodueG7DhXm5HHUQqYyt0yTFHJbLybyNQz3fuob
+RvBsBrzIHGowgyI+18rq2fIDv/zWxjwHlwdhPjrehh0yO9BYfPtIYkmu3U7ddMrk
+p8mTLhQBYeduLXp6DuflGLjmwdjEfqyXRWJxtscgvhQaArL+srmqu1sVl7vqZHXO
+4m20i+ogjsmsfXM6f6NfRph4yKpgW2RVtZVRhZuprzVEFryB3QARAQABiQIfBBgB
+AgAJBQJQmWPxAhsMAAoJEOaXVceEX9CsRQAP/10ySvtgjW1phfpC8wDlG/BG1VVQ
+Edhr+vmWQS69wM47HDV28YKjSPGc+OrGiUbWm/pePg9LWg6IMU3SPiRStORNbBEP
+WtTRFo9P5XyfulN9/KR4m1BtUjdmaXFpT0WomR5zpJ3Mq5bgJfFffCWt3+WWqedg
+H22Ti+TesDS4dE8fplUWEHTFaKOUQJSbTs2nDKVxc86v6ssgkPvSupMUtz5mSZS5
+lUnf7MfVLdcaYvOeB52pXaPbXJqejM/NfOwPZMEP6v9tUgRbeN+FvyU3ozFlfUaZ
+MbZNahYz6h6YCdK+Uk9Jor0IB5vUgGKiKWikR/3pIxNzlBAFXwi/sTwUEKZjBPlZ
+6if8EIJ8S44xuVuPyPaNaUVJp8PlAvY/jzCCe1yuFsyI3e7iwIS8ykUt9ntmQQ2C
+s/l0XX+GQ8eDrTN2yALKszQ59M0KEKC+YWZRrAP2ZJRf4odBYTHIULI9PftTdztb
+EP1CZqvRNrvdrhX4zY3XCn4CS5dSnCvf6mFZpYvR0G1TeK0sBlMhNefaVmZ9BWd9
+fJ9FLilcEh7TgbhNSd5z1EAuljniwSnj3nN929fh82PgB2yON2m1ZvQfvrNL15Hm
+EiP9S9DGf3NdGjeO6RWzJvuUv+9lYsL3gI3gcKy7EOem+7VqAGiU3m0MOsb40Odg
+YUWAO6m/prr2Y/Qg
+=G9bq
+-----END PGP PUBLIC KEY BLOCK-----
diff --git a/QPID_VERSION.txt b/QPID_VERSION.txt
index caa4836d8e..5320adc1c9 100644
--- a/QPID_VERSION.txt
+++ b/QPID_VERSION.txt
@@ -1 +1 @@
-0.19
+0.21
diff --git a/bin/release.sh b/bin/release.sh
index ecd00f4f18..c6a3f43496 100755
--- a/bin/release.sh
+++ b/bin/release.sh
@@ -37,6 +37,7 @@ usage()
echo "--source|-e : Generate the source artefact"
echo "--cpp |-c : Generate the CPP artefacts"
echo "--java |-j : Generate the java artefacts"
+ echo "--perl |-r : Generate the Perl artefacts"
echo "--python|-p : Generate the python artefacts"
echo "--wcf |-w : Generate the WCF artefacts"
echo "--tools |-t : Generate the tools artefacts"
@@ -53,6 +54,7 @@ all_artefacts()
CPP="CPP"
JAVA="JAVA"
+ PERL="PERL"
PYTHON="PYTHON"
WCF="WCF"
TOOLS="TOOLS"
@@ -94,6 +96,9 @@ for arg in $* ; do
--java|-j)
JAVA="JAVA"
;;
+ --perl|-r)
+ PERL="PERL"
+ ;;
--python|-p)
PYTHON="PYTHON"
;;
@@ -146,7 +151,7 @@ echo REV:$REV
echo VER:$VER
# If nothing is specified then do it all
-if [ -z "${CLEAN}${PREPARE}${CPP}${JAVA}${PYTHON}${QMF}${TOOLS}${WCF}${SOURCE}${SIGN}${UPLOAD}" ] ; then
+if [ -z "${CLEAN}${PREPARE}${CPP}${JAVA}${PERL}${PYTHON}${QMF}${TOOLS}${WCF}${SOURCE}${SIGN}${UPLOAD}" ] ; then
PREPARE="PREPARE"
all_artefacts
SIGN="SIGN"
@@ -184,6 +189,27 @@ if [ "SOURCE" == "$SOURCE" ] ; then
tar -czf artifacts/qpid-${VER}.tar.gz qpid-${VER}
fi
+if [ "PERL" == "$PERL" ]; then
+ pushd qpid-${VER}/cpp/bindings/qpid
+ make
+ popd
+ mkdir qpid-${VER}/perl-qpid-${VER}
+ cp qpid-${VER}/cpp/bindings/qpid/perl/perl.i \
+ qpid-${VER}/cpp/bindings/qpid/perl/*pm \
+ qpid-${VER}/cpp/bindings/qpid/perl/LICENSE \
+ qpid-${VER}/cpp/bindings/qpid/perl/Makefile.PL \
+ qpid-${VER}/cpp/bindings/qpid/perl/t/*.t \
+ qpid-${VER}/perl-qpid-${VER}
+ cp -r qpid-${VER}/cpp/bindings/qpid/perl/lib \
+ qpid-${VER}/perl-qpid-${VER}
+ mkdir qpid-${VER}/perl-qpid-${VER}/examples
+ cp qpid-${VER}/cpp/bindings/qpid/examples/perl/* \
+ qpid-${VER}/perl-qpid-${VER}/examples
+ pushd qpid-${VER}
+ tar -czf ../artifacts/perl-qpid-${VER}.tar.gz perl-qpid-${VER}
+ popd
+fi
+
if [ "PYTHON" == "$PYTHON" ] ; then
tar -czf artifacts/qpid-python-${VER}.tar.gz qpid-${VER}/python qpid-${VER}/specs
fi
@@ -231,7 +257,6 @@ if [ "JAVA" == "$JAVA" ] ; then
cp -a qpid-${VER}/java/management/common/release/maven artifacts/
cp -a qpid-${VER}/java/amqp-1-0-common/release/maven artifacts/
cp -a qpid-${VER}/java/broker-plugins/access-control/release/maven artifacts/
- cp -a qpid-${VER}/java/broker-plugins/firewall/release/maven artifacts/
cp -a qpid-${VER}/java/broker-plugins/management-jmx/release/maven artifacts/
cp -a qpid-${VER}/java/broker-plugins/management-http/release/maven artifacts/
cp -a qpid-${VER}/java/bdbstore/jmx/release/maven artifacts/
diff --git a/cpp/BuildInstallSettings.cmake b/cpp/BuildInstallSettings.cmake
index 3da1d89bfe..dfa88022d9 100644
--- a/cpp/BuildInstallSettings.cmake
+++ b/cpp/BuildInstallSettings.cmake
@@ -1,25 +1,25 @@
-#
-# 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.
-#
-
-# Settings related to the Qpid build and install CMake/CTest/CPack procedure.
-# These are used by both the C++ and WCF components.
-
+#
+# 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.
+#
+
+# Settings related to the Qpid build and install CMake/CTest/CPack procedure.
+# These are used by both the C++ and WCF components.
+
# Parse the version from QPID_VERSION.txt.
# Use the top level qpid/ file if we're in an SVN checkout, source dir otherwise.
if(EXISTS "${PROJECT_SOURCE_DIR}/../QPID_VERSION.txt")
@@ -31,121 +31,157 @@ else()
endif(EXISTS "${PROJECT_SOURCE_DIR}/../QPID_VERSION.txt")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\n" "\\1" QPID_VERSION_MAJOR "${QPID_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\n" "\\2" QPID_VERSION_MINOR "${QPID_VERSION}")
-
-# When doing installs, there are a number of components that the item can
-# be associated with. Since there may be different sets of components desired
-# for the various platforms, the component names are defined here. When
-# setting the COMPONENT in an install directive, use these to ensure that
-# the item is installed correctly.
-
-if (WIN32)
- # Install types; these defines the component sets that are installed.
- # Each component (below) indicates which of these install type(s) it is
- # included in. The user can refine the components at install time.
- set (CPACK_ALL_INSTALL_TYPES Broker Development Full)
-
- set (QPID_COMPONENT_COMMON Common)
- set (CPACK_COMPONENT_COMMON_INSTALL_TYPES Broker Development Full)
- set (CPACK_COMPONENT_COMMON_DISPLAY_NAME "Required common runtime items")
- set (CPACK_COMPONENT_COMMON_DESCRIPTION
- "Run-time library common to all runtime components in Qpid.\nThis item is required by both broker and client components.")
-
- set (QPID_COMPONENT_BROKER Broker)
- set (CPACK_COMPONENT_BROKER_DEPENDS Common)
- set (CPACK_COMPONENT_BROKER_INSTALL_TYPES Broker Full)
- set (CPACK_COMPONENT_BROKER_DISPLAY_NAME "Broker")
- set (CPACK_COMPONENT_BROKER_DESCRIPTION
- "Messaging broker; controls message flow within the system.\nAt least one broker is required to run any messaging application.")
-
- set (QPID_COMPONENT_CLIENT Client)
- set (CPACK_COMPONENT_CLIENT_DEPENDS Common)
- set (CPACK_COMPONENT_CLIENT_INSTALL_TYPES Development Full)
- set (CPACK_COMPONENT_CLIENT_DISPLAY_NAME "Client runtime libraries")
- set (CPACK_COMPONENT_CLIENT_DESCRIPTION
- "Runtime library components required to build and execute a client application.")
-
- set (QPID_COMPONENT_CLIENT_INCLUDE ClientInclude)
- set (CPACK_COMPONENT_CLIENTINCLUDE_INSTALL_TYPES Development Full)
- set (CPACK_COMPONENT_CLIENTINCLUDE_DISPLAY_NAME
- "Client programming header files")
- set (CPACK_COMPONENT_CLIENTINCLUDE_DESCRIPTION
- "C++ header files required to build any Qpid messaging application.")
-
- set (QPID_COMPONENT_EXAMPLES Examples)
- set (CPACK_COMPONENT_EXAMPLES_INSTALL_TYPES Development Full)
- set (CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "C++ Client programming examples")
- set (CPACK_COMPONENT_EXAMPLES_DESCRIPTION
- "Example source code for using the C++ Client.")
-
- set (QPID_COMPONENT_QMF QMF)
- set (CPACK_COMPONENT_QMF_INSTALL_TYPES Development Full)
- set (CPACK_COMPONENT_QMF_DISPLAY_NAME
- "Qpid Management Framework (QMF)")
- set (CPACK_COMPONENT_QMF_DESCRIPTION
- "QMF Agent allows you to embed QMF management in your program.\nQMF Console allows you to build management programs using QMF.")
-
- set (QPID_INSTALL_BINDIR bin CACHE STRING
- "Directory to install user executables")
- set (QPID_INSTALL_CONFDIR conf CACHE STRING
- "Directory to install configuration files")
- set (QPID_INSTALL_SASLDIR conf CACHE STRING
- "Directory to install SASL configuration files")
- set (QPID_INSTALL_DATADIR conf CACHE STRING
- "Directory to install read-only arch.-independent data root")
- set (QPID_INSTALL_EXAMPLESDIR examples CACHE STRING
- "Directory to install programming examples in")
- set (QPID_INSTALL_HTMLDIR docs/api/html CACHE STRING
- "Directory to install HTML documentation")
- set (QPID_INSTALL_INCLUDEDIR include CACHE STRING
- "Directory to install programming header files")
- set (QPID_INSTALL_LIBDIR bin CACHE STRING
- "Directory to install library files")
- set (QPID_INSTALL_SBINDIR bin CACHE STRING
- "Directory to install system admin executables")
- set (QPIDC_MODULE_DIR plugins/client CACHE STRING
- "Directory to load client plug-in modules from")
- set (QPIDD_MODULE_DIR plugins/broker CACHE STRING
- "Directory to load broker plug-in modules from")
-endif (WIN32)
-
-if (UNIX)
- set (QPID_COMPONENT_BROKER runtime)
- set (QPID_COMPONENT_CLIENT runtime)
- set (QPID_COMPONENT_COMMON runtime)
- set (CPACK_COMPONENT_RUNTIME_DISPLAY_NAME
- "Items required to run broker and/or client programs")
- set (QPID_COMPONENT_CLIENT_INCLUDE development)
- set (QPID_COMPONENT_EXAMPLES development)
- set (QPID_COMPONENT_QMF development)
- set (CPACK_COMPONENT_DEVELOPMENT_DISPLAY_NAME
- "Items required to build new C++ Qpid client programs")
-
- set (QPID_INSTALL_BINDIR bin CACHE STRING
- "Directory to install user executables")
- set (QPID_INSTALL_CONFDIR etc/qpid CACHE STRING
- "Directory to install configuration files")
- set (QPID_INSTALL_DATADIR share/qpid CACHE STRING
- "Directory to install read-only arch.-independent data root")
- set (QPID_INSTALL_SASLDIR etc/sasl2 CACHE STRING
- "Directory to install SASL configuration files")
- set (QPID_INSTALL_EXAMPLESDIR share/examples CACHE STRING
- "Directory to install programming examples in")
- set (QPID_INSTALL_HTMLDIR html CACHE STRING
- "Directory to install HTML documentation")
- set (QPID_INSTALL_INCLUDEDIR include CACHE STRING
- "Directory to install programming header files")
- set (QPID_INSTALL_LIBDIR lib CACHE STRING
- "Directory to install library files")
- set (QPID_INSTALL_SBINDIR sbin CACHE STRING
- "Directory to install system admin executables")
- set (QPIDC_MODULE_DIR ${QPID_INSTALL_LIBDIR}/qpid/client CACHE STRING
- "Directory to load client plug-in modules from")
- set (QPIDD_MODULE_DIR ${QPID_INSTALL_LIBDIR}/qpid/daemon CACHE STRING
- "Directory to load broker plug-in modules from")
- set (QPID_LIBEXEC_DIR libexec/qpid CACHE STRING
- "Directory for executables used by qpid libs")
- set (QPID_LOCALSTATE_DIR var CACHE STRING
- "Directory to store local state data")
- set (QPID_MAN_DIR man CACHE STRING
- "Directory to install manual files")
-endif (UNIX)
+set (QPID_VERSION_FULL "${QPID_VERSION_MAJOR}.${QPID_VERSION_MINOR}")
+
+# When doing installs, there are a number of components that the item can
+# be associated with. Since there may be different sets of components desired
+# for the various platforms, the component names are defined here. When
+# setting the COMPONENT in an install directive, use these to ensure that
+# the item is installed correctly.
+
+if (WIN32)
+ # Install types; these defines the component sets that are installed.
+ # Each component (below) indicates which of these install type(s) it is
+ # included in. The user can refine the components at install time.
+ set (CPACK_ALL_INSTALL_TYPES Broker Development Full)
+
+ set (QPID_COMPONENT_COMMON Common)
+ set (CPACK_COMPONENT_COMMON_INSTALL_TYPES Broker Development Full)
+ set (CPACK_COMPONENT_COMMON_DISPLAY_NAME "Required common runtime items")
+ set (CPACK_COMPONENT_COMMON_DESCRIPTION
+ "Run-time library common to all runtime components in Qpid.\nThis item is required by both broker and client components.")
+
+ set (QPID_COMPONENT_BROKER Broker)
+ set (CPACK_COMPONENT_BROKER_DEPENDS Common)
+ set (CPACK_COMPONENT_BROKER_INSTALL_TYPES Broker Full)
+ set (CPACK_COMPONENT_BROKER_DISPLAY_NAME "Broker")
+ set (CPACK_COMPONENT_BROKER_DESCRIPTION
+ "Messaging broker; controls message flow within the system.\nAt least one broker is required to run any messaging application.")
+
+ set (QPID_COMPONENT_CLIENT Client)
+ set (CPACK_COMPONENT_CLIENT_DEPENDS Common)
+ set (CPACK_COMPONENT_CLIENT_INSTALL_TYPES Development Full)
+ set (CPACK_COMPONENT_CLIENT_DISPLAY_NAME "Client runtime libraries")
+ set (CPACK_COMPONENT_CLIENT_DESCRIPTION
+ "Runtime library components required to build and execute a client application.")
+
+ set (QPID_COMPONENT_CLIENT_INCLUDE ClientInclude)
+ set (CPACK_COMPONENT_CLIENTINCLUDE_INSTALL_TYPES Development Full)
+ set (CPACK_COMPONENT_CLIENTINCLUDE_DISPLAY_NAME
+ "Client programming header files")
+ set (CPACK_COMPONENT_CLIENTINCLUDE_DESCRIPTION
+ "C++ header files required to build any Qpid messaging application.")
+
+ set (QPID_COMPONENT_EXAMPLES Examples)
+ set (CPACK_COMPONENT_EXAMPLES_INSTALL_TYPES Development Full)
+ set (CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "C++ Client programming examples")
+ set (CPACK_COMPONENT_EXAMPLES_DESCRIPTION
+ "Example source code for using the C++ Client.")
+
+ set (QPID_COMPONENT_QMF QMF)
+ set (CPACK_COMPONENT_QMF_INSTALL_TYPES Development Full)
+ set (CPACK_COMPONENT_QMF_DISPLAY_NAME
+ "Qpid Management Framework (QMF)")
+ set (CPACK_COMPONENT_QMF_DESCRIPTION
+ "QMF Agent allows you to embed QMF management in your program.\nQMF Console allows you to build management programs using QMF.")
+
+ set (QPID_INSTALL_BINDIR bin CACHE STRING
+ "Directory to install user executables")
+ set (QPID_INSTALL_CONFDIR conf CACHE STRING
+ "Directory to install configuration files")
+ set (QPID_INSTALL_SASLDIR conf CACHE STRING
+ "Directory to install SASL configuration files")
+ set (QPID_INSTALL_DATADIR conf CACHE STRING
+ "Directory to install read-only arch.-independent data root")
+ set (QPID_INSTALL_EXAMPLESDIR examples CACHE STRING
+ "Directory to install programming examples in")
+ set (QPID_INSTALL_DOCDIR docs CACHE STRING
+ "Directory to install documentation")
+ set (QPID_INSTALL_INCLUDEDIR include CACHE STRING
+ "Directory to install programming header files")
+ set (QPID_INSTALL_LIBDIR bin CACHE STRING
+ "Directory to install library files")
+ set (QPID_INSTALL_SBINDIR bin CACHE STRING
+ "Directory to install system admin executables")
+ set (QPID_INSTALL_TESTDIR bin CACHE STRING
+ "Directory for test executables")
+ set (QPIDC_MODULE_DIR plugins/client CACHE STRING
+ "Directory to load client plug-in modules from")
+ set (QPIDD_MODULE_DIR plugins/broker CACHE STRING
+ "Directory to load broker plug-in modules from")
+
+# function to get absolute path from a variable that may be relative to the
+# install prefix - For Windows we can never know the absolute install prefix
+# as this is decided at install time so this just returns the input path
+ function(set_absolute_install_path var input)
+ set (${var} ${input} PARENT_SCOPE)
+ endfunction(set_absolute_install_path)
+
+ set (INCLUDE_INSTALL_DIR ${QPID_INSTALL_INCLUDEDIR})
+ set (LIB_INSTALL_DIR ${QPID_INSTALL_INCLUDEDIR})
+endif (WIN32)
+
+if (UNIX)
+# function to get absolute path from a variable that may be relative to the
+# install prefix
+function(set_absolute_install_path var input)
+ if (${input} MATCHES "^/.*")
+ set (${var} ${input} PARENT_SCOPE)
+ else ()
+ set (${var} ${CMAKE_INSTALL_PREFIX}/${input} PARENT_SCOPE)
+ endif ()
+endfunction(set_absolute_install_path)
+
+# Figure out the default library suffix
+if (NOT DEFINED LIB_SUFFIX)
+ get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
+ if (${LIB64} STREQUAL "TRUE" AND ${CMAKE_SIZEOF_VOID_P} STREQUAL "8")
+ set(LIB_SUFFIX 64)
+ else()
+ set(LIB_SUFFIX "")
+ endif()
+endif()
+
+# In rpm builds the build sets some variables:
+# CMAKE_INSTALL_PREFIX - this is a standard cmake variable
+# INCLUDE_INSTALL_DIR
+# LIB_INSTALL_DIR
+# SYSCONF_INSTALL_DIR
+# SHARE_INSTALL_DIR
+# So make these cached variables and the specific variables non cached and
+# derived from them.
+ set (INCLUDE_INSTALL_DIR include CACHE PATH "Include file directory")
+ set (LIB_INSTALL_DIR lib${LIB_SUFFIX} CACHE PATH "Library object file directory")
+ set (SYSCONF_INSTALL_DIR etc CACHE PATH "System read only configuration directory")
+ set (SHARE_INSTALL_DIR share CACHE PATH "Shared read only data directory")
+ set (DOC_INSTALL_DIR ${SHARE_INSTALL_DIR}/doc/${CMAKE_PROJECT_NAME}-${QPID_VERSION_FULL} CACHE PATH "Shared read only data directory")
+
+ set (QPID_COMPONENT_BROKER runtime)
+ set (QPID_COMPONENT_CLIENT runtime)
+ set (QPID_COMPONENT_COMMON runtime)
+ set (CPACK_COMPONENT_RUNTIME_DISPLAY_NAME
+ "Items required to run broker and/or client programs")
+ set (QPID_COMPONENT_CLIENT_INCLUDE development)
+ set (QPID_COMPONENT_EXAMPLES development)
+ set (QPID_COMPONENT_QMF development)
+ set (CPACK_COMPONENT_DEVELOPMENT_DISPLAY_NAME
+ "Items required to build new C++ Qpid client programs")
+
+ # These are always relative to $CMAKE_INSTALL_PREFIX
+ set (QPID_INSTALL_BINDIR bin)
+ set (QPID_INSTALL_SBINDIR sbin)
+ set (QPID_INSTALL_TESTDIR libexec/qpid/tests) # Directory for test executables
+ set (QPID_INSTALL_CONFDIR ${SYSCONF_INSTALL_DIR}/qpid)
+ set (QPID_INSTALL_SASLDIR ${SYSCONF_INSTALL_DIR}/sasl2)
+ set (QPID_INSTALL_DATADIR ${SHARE_INSTALL_DIR}/qpid)
+ set (QPID_INSTALL_EXAMPLESDIR ${SHARE_INSTALL_DIR}/examples)
+ set (QPID_INSTALL_DOCDIR ${DOC_INSTALL_DIR}) # Directory to install documentation
+ set (QPID_INSTALL_INCLUDEDIR ${INCLUDE_INSTALL_DIR})
+ set (QPID_INSTALL_LIBDIR ${LIB_INSTALL_DIR})
+ set (QPID_LOCALSTATE_DIR var) # Directory to store local state data
+ set (QPID_MAN_DIR man) # Directory to install manual files
+ set (QPID_INSTALL_SYSTEMDDIR usr/lib/systemd/system) # Systemd service files
+
+ set_absolute_install_path (QPIDC_MODULE_DIR ${QPID_INSTALL_LIBDIR}/qpid/client) # Directory to load client plug-in modules from
+ set_absolute_install_path (QPIDD_MODULE_DIR ${QPID_INSTALL_LIBDIR}/qpid/daemon) # Directory to load broker plug-in modules from
+endif (UNIX)
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index ada8f165ee..f9b3be6099 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -25,6 +25,12 @@ endif(COMMAND cmake_policy)
include(BuildInstallSettings.cmake)
+if (${CMAKE_VERSION} VERSION_LESS "2.8.0")
+ set (OPTIONAL_ARG "")
+else()
+ set (OPTIONAL_ARG OPTIONAL)
+endif()
+
set (qpidc_version ${QPID_VERSION_MAJOR}.${QPID_VERSION_MINOR})
enable_testing()
@@ -54,12 +60,22 @@ if (WIN32)
set (CPACK_PACKAGE_EXECUTABLES "")
endif (WIN32)
-set (QPIDC_CONF_FILE ${QPID_INSTALL_CONFDIR}/qpidc.conf CACHE STRING
+set_absolute_install_path (QPIDC_CONF_PATH ${QPID_INSTALL_CONFDIR}/qpidc.conf)
+set_absolute_install_path (QPIDD_CONF_PATH ${QPID_INSTALL_CONFDIR}/qpidd.conf)
+set (QPIDC_CONF_FILE ${QPIDC_CONF_PATH} CACHE STRING
"Name of the Qpid client configuration file")
-set (QPIDD_CONF_FILE ${QPID_INSTALL_CONFDIR}/qpidd.conf CACHE STRING
+set (QPIDD_CONF_FILE ${QPIDD_CONF_PATH} CACHE STRING
"Name of the Qpid broker configuration file")
-install(FILES LICENSE NOTICE DESTINATION ${CMAKE_INSTALL_PREFIX})
+install(FILES LICENSE NOTICE DESTINATION ${QPID_INSTALL_DOCDIR})
+install(FILES include/qpid/qpid.i
+ include/qpid/swig_perl_typemaps.i
+ include/qpid/swig_python_typemaps.i
+ include/qpid/swig_ruby_typemaps.i
+ DESTINATION ${QPID_INSTALL_DATADIR}/qpid)
+install(FILES include/qmf/qmfengine.i
+ include/qmf/qmf2.i
+ DESTINATION ${QPID_INSTALL_INCLUDEDIR}/qmf)
if (WIN32)
set (CMAKE_DEBUG_POSTFIX "d")
@@ -76,12 +92,19 @@ set(CPACK_PACKAGE_VERSION_MINOR "${QPID_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "qpidc-${qpidc_version}")
+# Add custom target for docs since we don't include a cmake file there directly.
+# If we can't use OPTIONAL in the install command then we have to make the docs
+# every time so that the install target succeeds
+if (OPTIONAL_ARG)
+ add_custom_target(docs)
+else (OPTIONAL_ARG)
+ add_custom_target(docs ALL)
+endif (OPTIONAL_ARG)
+
add_subdirectory(managementgen)
add_subdirectory(src)
add_subdirectory(etc)
-add_subdirectory(bindings/qpid)
-add_subdirectory(bindings/qmf)
-add_subdirectory(bindings/qmf2)
+add_subdirectory(bindings)
add_subdirectory(docs/api)
add_subdirectory(docs/man)
add_subdirectory(examples)
diff --git a/cpp/INSTALL b/cpp/INSTALL
index dbd41c7cc1..c503f8de19 100644
--- a/cpp/INSTALL
+++ b/cpp/INSTALL
@@ -10,7 +10,6 @@ Table of Contents
2.2. How to Install
2.2.1. Using Package Management Tools
2.2.2. From Source
- a. openais
b. boost
c. autotools
2.3. Important Environment Variable Settings
@@ -25,7 +24,7 @@ Table of Contents
1. Introduction
===============
-Note that the daemon and client API can be installed separately.
+Note that the daemon and client API can be installed separately.
This document describes how to build the Qpid/C++ broker and client, either
from a checkout of the source or from a source distribution, on Linux/UNIX.
@@ -55,13 +54,9 @@ a source distribution:
to get 1.32 working in the svn tree though that is only recommended as
a last resort.
-Optional cluster functionality requires ONE of:
- * openais <http://openais.org> (0.80.3)
- * corosync <http://corosync.org> (1.0.0.rc1)
-
- Optional XML exchange requires:
- * xqilla <http://xqilla.sourceforge.net/HomePage> (2.0.0)
- * xerces-c <http://xerces.apache.org/xerces-c/> (2.7.0)
+Optional XML exchange requires:
+ * xqilla <http://xqilla.sourceforge.net/HomePage> (2.0.0)
+ * xerces-c <http://xerces.apache.org/xerces-c/> (2.7.0)
Optional SSL support requires:
* nss <http://www.mozilla.org/projects/security/pki/nss/>
@@ -95,8 +90,8 @@ the following must also be installed:
* ruby-devel
* python-devel
* swig <http://www.swig.org> (1.3.35)
-
-UUID problems:
+
+UUID problems:
In some earlier Linux releases (such as Fedora 11), the uuid/uuid.h
file is located in the e2fsprogs-devel package instead of
libuuid-devel. If you are using an older Linux release and run into a
@@ -114,13 +109,6 @@ package management tool. For example on Fedora:
# yum install boost-devel libuuid-devel pkgconfig gcc-c++ make autoconf automake ruby libtool help2man doxygen graphviz
-The optional clustering packages changed name in Fedora 10. On Fedora 9 or earlier:
- # yum install openais-devel cman-devel
-On Fedora 10 or later
- # yum install corosync-devel cmanlib-devel
-On Fedora 12 they changed again:
- # yum install corosynclib-devel clusterlib-devel
-
For SASL and SSL, include
# yum install cyrus-sasl-devel nss-devel nspr-devel
@@ -147,55 +135,9 @@ It is recommended that you create a directory to install them to, for example,
# ./configure --prefix=~/qpid-tools
# make install
-The exceptions are openais and boost.
-
-a. openais
-==========
-
-If ais is shipped with you platform and you have 0.80.3-x or later, skip
-builing ais
-
-To build ais: Unpack the source distribution and do:
- # make
- # sudo make install DESTDIR=
- # sudo ldconfig
-
-This will install in the standard places (/usr/lib, /usr/include etc.)
-
-Configuring ais:
-
-Edit /etc/ais/openais.conf and modify the "bindnetaddr" setting
-to your hosts IP address. Do not use 127.0.0.1.
+The exception is boost.
-Make sure the UDP port set for mcastport in openais.conf (5405 by
-default) is not blocked by your firewall. Disable the firewall or
-configure it to allow this port for UDP.
-
-Finally start the ais daemon (must be done as root):
- # sudo /sbin/aisexec
-
-Note that to run the AIS tests your primary group must be "ais". You
-can change your primary group with the usermod command or set it
-temporarily with the newgrp command.
-
-Troubleshooting tips:
-
-If aisexec goes into a loop printing "entering GATHER state", verify
-your firewall is allowing UDP traffic on the mcastport set in
-openais.conf.
-
-If aisexec reports "got nodejoin message 127.0.0.1" verify the
-bindnetaddr in openais.conf is an active local IP address. ifconfig
-will list local addresses.
-
-When aisexec is working correctly, the start-up log messages will end
-with "entering OPERATIONAL state." and "got nodejoin message <ip
-address>" where <ip address> is the local IP address specified for
-bindnetaddr in openais.conf.
-
-For further info on openais http://openais.org/
-
-b. boost
+boost
========
1. Unpack boost-jam.
2. Add bjam in the unpacked directory to your path.
@@ -358,8 +300,8 @@ To try it out "make doxygen" then open doxygen/html/index.html.
==================
When building, get the following on configure
configure: error: Package requirements (apr-1 >= 1.2.2) were not met:
-
+
No package 'apr-1' found
-
-The following has not been set
+
+The following has not been set
export PKG_CONFIG_PATH=$HOME/qpid-tools/lib/pkgconfig:/usr/lib/pkgconfig
diff --git a/cpp/Makefile.am b/cpp/Makefile.am
index 9f4b8e2082..f17170e109 100644
--- a/cpp/Makefile.am
+++ b/cpp/Makefile.am
@@ -24,9 +24,10 @@ ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = \
LICENSE NOTICE README.txt SSL RELEASE_NOTES DESIGN \
- xml/cluster.xml INSTALL-WINDOWS CMakeLists.txt BuildInstallSettings.cmake \
- packaging/NSIS QPID_VERSION.txt bindings/swig_python_typemaps.i \
- bindings/swig_ruby_typemaps.i bindings/swig_perl_typemaps.i
+ INSTALL-WINDOWS CMakeLists.txt BuildInstallSettings.cmake \
+ packaging/NSIS QPID_VERSION.txt bindings/CMakeLists.txt \
+ include/qpid/swig_python_typemaps.i include/qpid/swig_ruby_typemaps.i include/qpid/swig_perl_typemaps.i \
+ include/qpid/qpid.i include/qmf/qmfengine.i include/qmf/qmf2.i
SUBDIRS = managementgen etc src docs/api docs/man examples bindings/qmf bindings/qpid bindings/qmf2
@@ -36,4 +37,4 @@ libtool: $(LIBTOOL_DEPS)
check-long: all
$(MAKE) -C src/tests check-long
- \ No newline at end of file
+
diff --git a/cpp/bindings/CMakeLists.txt b/cpp/bindings/CMakeLists.txt
new file mode 100644
index 0000000000..3d44ef01cd
--- /dev/null
+++ b/cpp/bindings/CMakeLists.txt
@@ -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.
+#
+
+
+include(FindSWIG)
+include(UseSWIG)
+include(FindRuby)
+include(FindPythonLibs)
+include(FindPerlLibs)
+
+set (SWIG_MINIMUM_VERSION "1.3.32")
+
+if (SWIG_FOUND)
+ if (${SWIG_VERSION} VERSION_LESS ${SWIG_MINIMUM_VERSION})
+ message("Found Swig < ${SWIG_MINIMUM_VERSION} - skipping language bindings")
+ else()
+ set(CMAKE_SWIG_FLAGS "-w361,362,401,467,503")
+
+ if (PYTHONLIBS_FOUND)
+ execute_process(COMMAND ${PYTHON_EXECUTABLE}
+ -c "from distutils.sysconfig import get_python_lib; print get_python_lib(True, prefix='${CMAKE_INSTALL_PREFIX}')"
+ OUTPUT_VARIABLE PYTHON_SITEARCH_PACKAGES
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ add_subdirectory(qpid/python)
+ add_subdirectory(qmf2/python)
+ add_subdirectory(qmf/python)
+ endif (PYTHONLIBS_FOUND)
+
+ if (RUBY_FOUND)
+ execute_process(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "puts RbConfig::CONFIG['prefix']"
+ OUTPUT_VARIABLE RUBY_PREFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REPLACE ${RUBY_PREFIX} ${CMAKE_INSTALL_PREFIX} RUBY_PFX_ARCH_DIR ${RUBY_ARCH_DIR})
+
+ add_subdirectory(qpid/ruby)
+ add_subdirectory(qmf2/ruby)
+ add_subdirectory(qmf/ruby)
+ endif (RUBY_FOUND)
+
+ if (PERLLIBS_FOUND)
+ execute_process(COMMAND ${PERL_EXECUTABLE} "-V::prefix:"
+ OUTPUT_VARIABLE QPERL_PREFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX REPLACE "'(.*)'" "\\1" PERL_PREFIX ${QPERL_PREFIX})
+ string(REPLACE ${PERL_PREFIX} ${CMAKE_INSTALL_PREFIX} PERL_PFX_ARCHLIB ${PERL_ARCHLIB})
+
+ add_subdirectory(qpid/perl)
+ endif (PERLLIBS_FOUND)
+ endif (${SWIG_VERSION} VERSION_LESS ${SWIG_MINIMUM_VERSION})
+endif (SWIG_FOUND)
diff --git a/cpp/bindings/qmf/CMakeLists.txt b/cpp/bindings/qmf/CMakeLists.txt
deleted file mode 100644
index 5e40539e80..0000000000
--- a/cpp/bindings/qmf/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,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.
-#
-
-
-include(FindSWIG)
-include(UseSWIG)
-include(FindRuby)
-include(FindPythonLibs)
-include(FindPerlLibs)
-
-if (SWIG_FOUND)
- set(CMAKE_SWIG_FLAGS "-w362,401")
-
- if (PYTHONLIBS_FOUND)
- add_subdirectory(python)
- endif (PYTHONLIBS_FOUND)
-
- if (RUBY_FOUND)
- add_subdirectory(ruby)
- endif (RUBY_FOUND)
-endif (SWIG_FOUND)
diff --git a/cpp/bindings/qmf/Makefile.am b/cpp/bindings/qmf/Makefile.am
index dd77ab080c..ee4ff1d3c1 100644
--- a/cpp/bindings/qmf/Makefile.am
+++ b/cpp/bindings/qmf/Makefile.am
@@ -19,7 +19,6 @@
if HAVE_SWIG
-EXTRA_DIST = CMakeLists.txt qmfengine.i
SUBDIRS = tests
if HAVE_RUBY_DEVEL
diff --git a/cpp/bindings/qmf/python/CMakeLists.txt b/cpp/bindings/qmf/python/CMakeLists.txt
index 9bc6b2e878..1768df7f85 100644
--- a/cpp/bindings/qmf/python/CMakeLists.txt
+++ b/cpp/bindings/qmf/python/CMakeLists.txt
@@ -21,7 +21,7 @@
## Use Swig to generate a literal binding to the C++ API
##------------------------------------------------------
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i PROPERTIES CPLUSPLUS ON)
-set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i PROPERTIES SWIG_FLAGS "-I${qpid-cpp_SOURCE_DIR}/include")
+set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i PROPERTIES SWIG_FLAGS "-I${qpid-cpp_SOURCE_DIR}/include;-I${qpid-cpp_SOURCE_DIR}/bindings")
swig_add_module(qmfengine_python python ${CMAKE_CURRENT_SOURCE_DIR}/python.i)
swig_link_libraries(qmfengine_python qmf qmfconsole ${PYTHON_LIBRARIES})
@@ -31,28 +31,23 @@ set_source_files_properties(${swig_generated_file_fullname} PROPERTIES COMPILE_F
##------------------------------------
## Install the complete Python binding
##------------------------------------
-execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
-install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile qmfengine.py
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
-install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile qmfengine.py
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/qmf.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
-install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile qmf.py
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
-install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile qmf.py
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmfengine.py
- ${CMAKE_CURRENT_BINARY_DIR}/qmfengine.pyc
- ${CMAKE_CURRENT_BINARY_DIR}/qmfengine.pyo
${CMAKE_CURRENT_SOURCE_DIR}/qmf.py
- ${CMAKE_CURRENT_BINARY_DIR}/qmf.pyc
- ${CMAKE_CURRENT_BINARY_DIR}/qmf.pyo
- DESTINATION ${PYTHON_SITE_PACKAGES}
+ DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/_qmfengine_python.so
RENAME _qmfengine.so
- DESTINATION ${PYTHON_SITE_PACKAGES}
+ DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
+# Python compile the installed modules
+install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile qmfengine.py
+ WORKING_DIRECTORY ${PYTHON_SITEARCH_PACKAGES})")
+install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile qmfengine.py
+ WORKING_DIRECTORY ${PYTHON_SITEARCH_PACKAGES})")
+install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile qmf.py
+ WORKING_DIRECTORY ${PYTHON_SITEARCH_PACKAGES})")
+install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile qmf.py
+ WORKING_DIRECTORY ${PYTHON_SITEARCH_PACKAGES})")
diff --git a/cpp/bindings/qmf/python/Makefile.am b/cpp/bindings/qmf/python/Makefile.am
index bcef8c6b53..07f3c1072b 100644
--- a/cpp/bindings/qmf/python/Makefile.am
+++ b/cpp/bindings/qmf/python/Makefile.am
@@ -29,7 +29,7 @@ EXTRA_DIST = CMakeLists.txt python.i
BUILT_SOURCES = $(generated_file_list)
SWIG_FLAGS = -w362,401
-$(generated_file_list): $(srcdir)/python.i $(srcdir)/../qmfengine.i
+$(generated_file_list): $(srcdir)/python.i
$(SWIG) -c++ -python $(SWIG_FLAGS) $(INCLUDES) $(QPID_CXXFLAGS) -I$(top_srcdir)/src/qmf -I/usr/include -o qmfengine.cpp $(srcdir)/python.i
pylibdir = $(pyexecdir)
diff --git a/cpp/bindings/qmf/python/python.i b/cpp/bindings/qmf/python/python.i
index 5e25d155f9..118d0d3dbd 100644
--- a/cpp/bindings/qmf/python/python.i
+++ b/cpp/bindings/qmf/python/python.i
@@ -139,5 +139,5 @@
-%include "../qmfengine.i"
+%include "qmf/qmfengine.i"
diff --git a/cpp/bindings/qmf/ruby/CMakeLists.txt b/cpp/bindings/qmf/ruby/CMakeLists.txt
index 702606139b..1fb2542e46 100644
--- a/cpp/bindings/qmf/ruby/CMakeLists.txt
+++ b/cpp/bindings/qmf/ruby/CMakeLists.txt
@@ -22,7 +22,9 @@
##------------------------------------------------------
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/ruby.i PROPERTIES CPLUSPLUS ON)
-include_directories(${RUBY_INCLUDE_DIRS} ${qpid-cpp_SOURCE_DIR}/include)
+include_directories(${RUBY_INCLUDE_DIRS}
+ ${qpid-cpp_SOURCE_DIR}/include
+ ${qpid-cpp_SOURCE_DIR}/bindings)
swig_add_module(qmfengine_ruby ruby ${CMAKE_CURRENT_SOURCE_DIR}/ruby.i)
swig_link_libraries(qmfengine_ruby qmf qmfconsole ${RUBY_LIBRARY})
@@ -32,6 +34,6 @@ swig_link_libraries(qmfengine_ruby qmf qmfconsole ${RUBY_LIBRARY})
##----------------------------------
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libqmfengine_ruby.so
RENAME qmfengine.so
- DESTINATION ${RUBY_ARCH_DIR}
+ DESTINATION ${RUBY_PFX_ARCH_DIR}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
diff --git a/cpp/bindings/qmf/ruby/Makefile.am b/cpp/bindings/qmf/ruby/Makefile.am
index 1c7f67edb3..33393aeda0 100644
--- a/cpp/bindings/qmf/ruby/Makefile.am
+++ b/cpp/bindings/qmf/ruby/Makefile.am
@@ -29,7 +29,7 @@ rubylibdir = $(RUBY_LIB)
dist_rubylib_DATA = qmf.rb
-qmfengine.cpp: $(srcdir)/ruby.i $(srcdir)/../qmfengine.i
+qmfengine.cpp: $(srcdir)/ruby.i
$(SWIG) -ruby -c++ $(SWIG_FLAGS) $(INCLUDES) $(QPID_CXXFLAGS) -I/usr/include -o qmfengine.cpp $(srcdir)/ruby.i
rubylibarchdir = $(RUBY_LIB_ARCH)
diff --git a/cpp/bindings/qmf/ruby/qmf.rb b/cpp/bindings/qmf/ruby/qmf.rb
index 9fbd50cbf6..d05127db4b 100644
--- a/cpp/bindings/qmf/ruby/qmf.rb
+++ b/cpp/bindings/qmf/ruby/qmf.rb
@@ -319,9 +319,7 @@ module Qmf
eventImpl.sessionContext.handler.sess_event_recv(eventImpl.sessionContext, eventImpl.message)
end
rescue Exception => ex
- puts "Event Exception: #{ex}"
if bt_count < 2
- puts ex.backtrace
bt_count += 1
end
end
@@ -1251,9 +1249,7 @@ module Qmf
when Qmfengine::ConsoleEvent::METHOD_RESPONSE
end
rescue Exception => ex
- puts "Exception caught in callback: #{ex}"
if @bt_count < 2
- puts ex.backtrace
@bt_count += 1
end
end
@@ -1381,14 +1377,13 @@ module Qmf
end
def conn_event_connected()
- puts "Console Connection Established..."
@session = Session.new(@conn, "qmfc-%s.%d" % [Socket.gethostname, Process::pid], self)
@impl.sessionOpened(@session.handle)
do_events
end
def conn_event_disconnected(error)
- puts "Console Connection Lost"
+
end
def conn_event_visit
@@ -1396,12 +1391,10 @@ module Qmf
end
def sess_event_session_closed(context, error)
- puts "Console Session Lost"
@impl.sessionClosed()
end
def sess_event_recv(context, message)
- puts "Unexpected RECV Event" if not @operational
@impl.handleRcvMessage(message)
do_events
end
@@ -1510,14 +1503,13 @@ module Qmf
end
def conn_event_connected()
- puts "Agent Connection Established..."
@session = Session.new(@conn, "qmfa-%s.%d" % [Socket.gethostname, Process::pid], self)
@impl.newSession
do_events
end
def conn_event_disconnected(error)
- puts "Agent Connection Lost"
+
end
def conn_event_visit
@@ -1525,7 +1517,7 @@ module Qmf
end
def sess_event_session_closed(context, error)
- puts "Agent Session Lost"
+
end
def sess_event_recv(context, message)
diff --git a/cpp/bindings/qmf/ruby/ruby.i b/cpp/bindings/qmf/ruby/ruby.i
index 0101861100..2854aa0c7e 100644
--- a/cpp/bindings/qmf/ruby/ruby.i
+++ b/cpp/bindings/qmf/ruby/ruby.i
@@ -102,5 +102,5 @@
}
-%include "../qmfengine.i"
+%include "qmf/qmfengine.i"
diff --git a/cpp/bindings/qmf2/CMakeLists.txt b/cpp/bindings/qmf2/CMakeLists.txt
deleted file mode 100644
index 5e40539e80..0000000000
--- a/cpp/bindings/qmf2/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,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.
-#
-
-
-include(FindSWIG)
-include(UseSWIG)
-include(FindRuby)
-include(FindPythonLibs)
-include(FindPerlLibs)
-
-if (SWIG_FOUND)
- set(CMAKE_SWIG_FLAGS "-w362,401")
-
- if (PYTHONLIBS_FOUND)
- add_subdirectory(python)
- endif (PYTHONLIBS_FOUND)
-
- if (RUBY_FOUND)
- add_subdirectory(ruby)
- endif (RUBY_FOUND)
-endif (SWIG_FOUND)
diff --git a/cpp/bindings/qmf2/Makefile.am b/cpp/bindings/qmf2/Makefile.am
index 9a03a5cd21..0f50e757a2 100644
--- a/cpp/bindings/qmf2/Makefile.am
+++ b/cpp/bindings/qmf2/Makefile.am
@@ -19,7 +19,6 @@
if HAVE_SWIG
-EXTRA_DIST = CMakeLists.txt qmf2.i
SUBDIRS = examples/cpp
if HAVE_RUBY_DEVEL
diff --git a/cpp/bindings/qmf2/examples/cpp/Makefile.am b/cpp/bindings/qmf2/examples/cpp/Makefile.am
index 062fbd0a85..8bf56ead91 100644
--- a/cpp/bindings/qmf2/examples/cpp/Makefile.am
+++ b/cpp/bindings/qmf2/examples/cpp/Makefile.am
@@ -21,16 +21,19 @@ INCLUDE = -I$(top_srcdir)/include
AM_CPPFLAGS = $(INCLUDE)
+TYPES_LIB=$(top_builddir)/src/libqpidtypes.la
+MESSAGING_LIB=$(top_builddir)/src/libqpidmessaging.la
+
noinst_PROGRAMS=agent event_driven_list_agents list_agents print_events
agent_SOURCES=agent.cpp
-agent_LDADD=$(top_builddir)/src/libqmf2.la
+agent_LDADD=$(top_builddir)/src/libqmf2.la $(TYPES_LIB) $(MESSAGING_LIB)
list_agents_SOURCES=list_agents.cpp
-list_agents_LDADD=$(top_builddir)/src/libqmf2.la
+list_agents_LDADD=$(top_builddir)/src/libqmf2.la $(MESSAGING_LIB)
event_driven_list_agents_SOURCES=event_driven_list_agents.cpp
-event_driven_list_agents_LDADD=$(top_builddir)/src/libqmf2.la
+event_driven_list_agents_LDADD=$(top_builddir)/src/libqmf2.la $(MESSAGING_LIB)
print_events_SOURCES=print_events.cpp
-print_events_LDADD=$(top_builddir)/src/libqmf2.la
+print_events_LDADD=$(top_builddir)/src/libqmf2.la $(TYPES_LIB) $(MESSAGING_LIB)
diff --git a/cpp/bindings/qmf2/python/CMakeLists.txt b/cpp/bindings/qmf2/python/CMakeLists.txt
index 2e71ca34e7..1c8447116e 100644
--- a/cpp/bindings/qmf2/python/CMakeLists.txt
+++ b/cpp/bindings/qmf2/python/CMakeLists.txt
@@ -21,7 +21,7 @@
## Use Swig to generate a literal binding to the C++ API
##------------------------------------------------------
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i PROPERTIES CPLUSPLUS ON)
-set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i PROPERTIES SWIG_FLAGS "-I${qpid-cpp_SOURCE_DIR}/include")
+set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i PROPERTIES SWIG_FLAGS "-I${qpid-cpp_SOURCE_DIR}/include;-I${qpid-cpp_SOURCE_DIR}/bindings")
swig_add_module(cqmf2_python python ${CMAKE_CURRENT_SOURCE_DIR}/python.i)
swig_link_libraries(cqmf2_python qmf2 ${PYTHON_LIBRARIES})
@@ -31,28 +31,23 @@ set_source_files_properties(${swig_generated_file_fullname} PROPERTIES COMPILE_F
##------------------------------------
## Install the complete Python binding
##------------------------------------
-execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
-install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile cqmf2.py
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
-install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile cqmf2.py
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
-file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/qmf2.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
-install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile qmf2.py
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
-install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile qmf2.py
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cqmf2.py
- ${CMAKE_CURRENT_BINARY_DIR}/cqmf2.pyc
- ${CMAKE_CURRENT_BINARY_DIR}/cqmf2.pyo
- ${CMAKE_CURRENT_BINARY_DIR}/qmf2.py
- ${CMAKE_CURRENT_BINARY_DIR}/qmf2.pyc
- ${CMAKE_CURRENT_BINARY_DIR}/qmf2.pyo
- DESTINATION ${PYTHON_SITE_PACKAGES}
+ ${CMAKE_CURRENT_SOURCE_DIR}/qmf2.py
+ DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/_cqmf2_python.so
RENAME _cqmf2.so
- DESTINATION ${PYTHON_SITE_PACKAGES}
+ DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
+# Python compile the installed modules
+install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile cqmf2.py
+ WORKING_DIRECTORY ${PYTHON_SITEARCH_PACKAGES})")
+install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile cqmf2.py
+ WORKING_DIRECTORY ${PYTHON_SITEARCH_PACKAGES})")
+install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile qmf2.py
+ WORKING_DIRECTORY ${PYTHON_SITEARCH_PACKAGES})")
+install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile qmf2.py
+ WORKING_DIRECTORY ${PYTHON_SITEARCH_PACKAGES})")
diff --git a/cpp/bindings/qmf2/python/Makefile.am b/cpp/bindings/qmf2/python/Makefile.am
index 591c1408c0..309e8f8dad 100644
--- a/cpp/bindings/qmf2/python/Makefile.am
+++ b/cpp/bindings/qmf2/python/Makefile.am
@@ -19,7 +19,7 @@
if HAVE_PYTHON_DEVEL
-INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src $(QMF_INCLUDES)
+INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/bindings -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src $(QMF_INCLUDES)
generated_file_list = \
cqmf2.cpp \
@@ -29,7 +29,7 @@ EXTRA_DIST = CMakeLists.txt python.i
BUILT_SOURCES = $(generated_file_list)
SWIG_FLAGS = -w362,401
-$(generated_file_list): $(srcdir)/python.i $(srcdir)/../qmf2.i $(srcdir)/../../swig_python_typemaps.i
+$(generated_file_list): $(srcdir)/python.i
$(SWIG) -c++ -python $(SWIG_FLAGS) $(INCLUDES) $(QPID_CXXFLAGS) -I/usr/include -o cqmf2.cpp $(srcdir)/python.i
pylibdir = $(pyexecdir)
diff --git a/cpp/bindings/qmf2/python/python.i b/cpp/bindings/qmf2/python/python.i
index 02dd1632b0..6b5326f8cf 100644
--- a/cpp/bindings/qmf2/python/python.i
+++ b/cpp/bindings/qmf2/python/python.i
@@ -19,7 +19,7 @@
%module cqmf2
%include "std_string.i"
-%include "../../swig_python_typemaps.i"
+%include "qpid/swig_python_typemaps.i"
/* Define the general-purpose exception handling */
%exception {
@@ -37,5 +37,5 @@
}
}
-%include "../qmf2.i"
+%include "qmf/qmf2.i"
diff --git a/cpp/bindings/qmf2/ruby/CMakeLists.txt b/cpp/bindings/qmf2/ruby/CMakeLists.txt
index 1cb969f7dc..70b3e917f9 100644
--- a/cpp/bindings/qmf2/ruby/CMakeLists.txt
+++ b/cpp/bindings/qmf2/ruby/CMakeLists.txt
@@ -22,7 +22,9 @@
##------------------------------------------------------
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/ruby.i PROPERTIES CPLUSPLUS ON)
-include_directories(${RUBY_INCLUDE_DIRS} ${qpid-cpp_SOURCE_DIR}/include)
+include_directories(${RUBY_INCLUDE_DIRS}
+ ${qpid-cpp_SOURCE_DIR}/include
+ ${qpid-cpp_SOURCE_DIR}/bindings)
swig_add_module(cqmf2_ruby ruby ${CMAKE_CURRENT_SOURCE_DIR}/ruby.i)
swig_link_libraries(cqmf2_ruby qmf2 ${RUBY_LIBRARY})
@@ -32,7 +34,7 @@ swig_link_libraries(cqmf2_ruby qmf2 ${RUBY_LIBRARY})
##----------------------------------
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcqmf2_ruby.so
RENAME cqmf2.so
- DESTINATION ${RUBY_ARCH_DIR}
+ DESTINATION ${RUBY_PFX_ARCH_DIR}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
diff --git a/cpp/bindings/qmf2/ruby/Makefile.am b/cpp/bindings/qmf2/ruby/Makefile.am
index a03bd6d5e6..9952edb972 100644
--- a/cpp/bindings/qmf2/ruby/Makefile.am
+++ b/cpp/bindings/qmf2/ruby/Makefile.am
@@ -19,7 +19,7 @@
if HAVE_RUBY_DEVEL
-INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src $(QMF_INCLUDES)
+INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/bindings -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src $(QMF_INCLUDES)
EXTRA_DIST = CMakeLists.txt ruby.i
BUILT_SOURCES = cqmf2.cpp
@@ -27,7 +27,7 @@ SWIG_FLAGS = -w362,401
rubylibdir = $(RUBY_LIB)
-cqmf2.cpp: $(srcdir)/ruby.i $(srcdir)/../qmf2.i $(srcdir)/../../swig_ruby_typemaps.i
+cqmf2.cpp: $(srcdir)/ruby.i
$(SWIG) -ruby -c++ $(SWIG_FLAGS) $(INCLUDES) $(QPID_CXXFLAGS) -I/usr/include -o cqmf2.cpp $(srcdir)/ruby.i
rubylibarchdir = $(RUBY_LIB_ARCH)
diff --git a/cpp/bindings/qmf2/ruby/ruby.i b/cpp/bindings/qmf2/ruby/ruby.i
index 1070c65a44..0254017555 100644
--- a/cpp/bindings/qmf2/ruby/ruby.i
+++ b/cpp/bindings/qmf2/ruby/ruby.i
@@ -18,8 +18,10 @@
*/
%module cqmf2
+/* Ruby doesn't have a != operator*/
+#pragma SWIG nowarn=378
%include "std_string.i"
-%include "../../swig_ruby_typemaps.i"
+%include "qpid/swig_ruby_typemaps.i"
/* Define the general-purpose exception handling */
%exception {
@@ -32,4 +34,4 @@
}
}
-%include "../qmf2.i"
+%include "qmf/qmf2.i"
diff --git a/cpp/bindings/qpid/CMakeLists.txt b/cpp/bindings/qpid/CMakeLists.txt
deleted file mode 100644
index 7c9f76f991..0000000000
--- a/cpp/bindings/qpid/CMakeLists.txt
+++ /dev/null
@@ -1,41 +0,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.
-#
-
-
-include(FindSWIG)
-include(UseSWIG)
-include(FindRuby)
-include(FindPythonLibs)
-include(FindPerlLibs)
-
-if (SWIG_FOUND)
- set(CMAKE_SWIG_FLAGS "-w361,362,401,467,503")
-
- if (PYTHONLIBS_FOUND)
- add_subdirectory(python)
- endif (PYTHONLIBS_FOUND)
-
- if (RUBY_FOUND)
- add_subdirectory(ruby)
- endif (RUBY_FOUND)
-
- if (PERLLIBS_FOUND)
- add_subdirectory(perl)
- endif (PERLLIBS_FOUND)
-endif (SWIG_FOUND)
diff --git a/cpp/bindings/qpid/Makefile.am b/cpp/bindings/qpid/Makefile.am
index ae81696f27..aace6f2d95 100644
--- a/cpp/bindings/qpid/Makefile.am
+++ b/cpp/bindings/qpid/Makefile.am
@@ -21,8 +21,6 @@ SUBDIRS = dotnet
if HAVE_SWIG
-EXTRA_DIST = CMakeLists.txt qpid.i
-
if HAVE_RUBY_DEVEL
SUBDIRS += ruby
endif
@@ -33,18 +31,18 @@ endif
if HAVE_PERL_DEVEL
-INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src -I$(PERL_INC)
+INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/bindings -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src -I$(PERL_INC)
-EXTRA_DIST += perl/perl.i perl/CMakeLists.txt
+EXTRA_DIST = perl/perl.i perl/CMakeLists.txt
BUILT_SOURCES = perl/cqpid_perl.cpp
SWIG_FLAGS = -w362,401
-perl/cqpid_perl.cpp: $(srcdir)/perl/perl.i $(srcdir)/qpid.i $(srcdir)/../swig_perl_typemaps.i
+perl/cqpid_perl.cpp: $(srcdir)/perl/perl.i
$(SWIG) -perl -c++ $(SWIG_FLAGS) $(INCLUDES) $(QPID_CXXFLAGS) -I/usr/include -o perl/cqpid_perl.cpp $(srcdir)/perl/perl.i
perl/Makefile: perl/cqpid_perl.cpp
cd perl; \
- $(PERL) Makefile.PL PREFIX=$(prefix) LIB=$(PERL_ARCHLIB) ; \
+ $(PERL) Makefile.PL PREFIX=$(prefix) ; \
cd ..
all-local: perl/Makefile
@@ -54,7 +52,7 @@ all-local: perl/Makefile
install-exec-local:
cd perl ; \
- $(MAKE) pure_install DESTDIR=$(prefix) ; \
+ $(MAKE) pure_install ; \
cd ..
clean-local:
@@ -72,7 +70,6 @@ maintainer-clean-local:
$(PERL) maintainer-clean ; \
cd ..
-DISTCLEANFILES = perl/Makefile.PL
CLEANFILES = perl/cqpid_perl.cpp perl/Makefile.old perl/cqpid_perl.pm
endif
diff --git a/cpp/bindings/qpid/dotnet/configure-windows.ps1 b/cpp/bindings/qpid/dotnet/configure-windows.ps1
index 162ac272b4..60b2b539bd 100644
--- a/cpp/bindings/qpid/dotnet/configure-windows.ps1
+++ b/cpp/bindings/qpid/dotnet/configure-windows.ps1
@@ -24,8 +24,8 @@
# This script configures a qpid\cpp developer build environment under Windows
# to enable working with cpp\bindings\qpid\dotnet binding source code.
#
-# * Supports multiple versions of Visual Studio (VS2008, VS2010) as CMake
-# generator.
+# * Supports multiple versions of Visual Studio (VS2008, VS2010, VS2012)
+# as CMake generator.
#
# * Supports 32-bit and/or 64-bit development platforms.
#
@@ -148,10 +148,11 @@ $global:txtWH = 'Write-Host'
#############################
# Visual Studio version selection dialog items and choice
#
-[array]$global:VsVersionCmakeChoiceList = "Visual Studio 2010", "Visual Studio 2008"
+[array]$global:VsVersionCmakeChoiceList = "Visual Studio 2012", "Visual Studio 2010", "Visual Studio 2008"
$global:vsVersion = ''
$global:cmakeGenerator = ''
$global:vsSubdir = ''
+$global:cmakeCompiler = ''
#############################
# Select-Folder
@@ -352,18 +353,26 @@ ECHO Environment set for $slnName $studioVersion $vsPlatform $nBits-bit developm
function Return-DropDown {
if ($DropDown.SelectedItem -ne $null) {
$global:vsVersion = $DropDown.SelectedItem.ToString()
- if ($global:vsVersion -eq 'Visual Studio 2010') {
- $global:cmakeGenerator = "Visual Studio 10"
- $global:vsSubdir = "msvc10"
+ if ($global:vsVersion -eq 'Visual Studio 2012') {
+ $global:cmakeGenerator = "Visual Studio 11"
+ $global:vsSubdir = "msvc11"
+ $global:cmakeCompiler = "-vc110"
} else {
- if ($global:vsVersion -eq 'Visual Studio 2008') {
- $global:cmakeGenerator = "Visual Studio 9 2008"
- $global:vsSubdir = "msvc9"
- } else {
- Write-Host "Visual Studio must be 2008 or 2010"
- exit
- }
- }
+ if ($global:vsVersion -eq 'Visual Studio 2010') {
+ $global:cmakeGenerator = "Visual Studio 10"
+ $global:vsSubdir = "msvc10"
+ $global:cmakeCompiler = "-vc100"
+ } else {
+ if ($global:vsVersion -eq 'Visual Studio 2008') {
+ $global:cmakeGenerator = "Visual Studio 9 2008"
+ $global:vsSubdir = "msvc9"
+ $global:cmakeCompiler = "-vc90"
+ } else {
+ Write-Host "Visual Studio must be 2008, 2010, or 2012"
+ exit
+ }
+ }
+ }
$Form.Close()
Write-Host "Selected generator: $global:cmakeGenerator"
}
@@ -496,7 +505,7 @@ if ($make32) {
$env:BOOST_ROOT = "$boost32"
cd "$build32"
Write-Host "Running 32-bit CMake in $build32 ..."
- CMake -G "$global:cmakeGenerator" "-DCMAKE_INSTALL_PREFIX=install_x86" $cppDir
+ CMake -G "$global:cmakeGenerator" "-DGEN_DOXYGEN=No" "-DCMAKE_INSTALL_PREFIX=install_x86" "-DBoost_COMPILER=$global:cmakeCompiler" $cppDir
} else {
Write-Host "Skipped 32-bit CMake."
}
@@ -508,7 +517,7 @@ if ($make64) {
$env:BOOST_ROOT = "$boost64"
cd "$build64"
Write-Host "Running 64-bit CMake in $build64"
- CMake -G "$global:cmakeGenerator Win64" "-DCMAKE_INSTALL_PREFIX=install_x64" $cppDir
+ CMake -G "$global:cmakeGenerator Win64" "-DGEN_DOXYGEN=No" "-DCMAKE_INSTALL_PREFIX=install_x64" "-DBoost_COMPILER=$global:cmakeCompiler" $cppDir
} else {
Write-Host "Skipped 64-bit CMake."
}
diff --git a/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs b/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs
index b1ba949e07..3bc22b2ce8 100644
--- a/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs
+++ b/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.cs
@@ -153,6 +153,21 @@ namespace Org.Apache.Qpid.Messaging.Examples
/// <summary>
+ /// SessionReceiver implements the ISessionReceiver interface.
+ /// It is the exception function that receives all exception messages
+ /// It may be called any time server is running.
+ /// It is always called on server's private thread.
+ /// After this is called then the sessionReceiver and private thread are closed.
+ /// </summary>
+ /// <param name="exception">The exception.</param>
+ public void SessionException(Exception exception)
+ {
+ // A typical application will take more action here.
+ Console.WriteLine("{0} Exception caught.", exception.ToString());
+ }
+
+
+ /// <summary>
/// Usage
/// </summary>
/// <param name="url">Connection target</param>
@@ -259,8 +274,17 @@ namespace Org.Apache.Qpid.Messaging.Examples
//
// Close the receiver and the connection.
//
- receiver.Close();
- connection.Close();
+ try
+ {
+ receiver.Close();
+ connection.Close();
+ }
+ catch (Exception exception)
+ {
+ // receiver or connection may throw if they closed in error.
+ // A typical application will take more action here.
+ Console.WriteLine("{0} Closing exception caught.", exception.ToString());
+ }
return 0;
}
}
diff --git a/cpp/bindings/qpid/dotnet/msvc9/org.apache.qpid.messaging.sessionreceiver.sln b/cpp/bindings/qpid/dotnet/msvc9/org.apache.qpid.messaging.sessionreceiver.sln
index 9ed7d4df3a..112511e5e5 100644
--- a/cpp/bindings/qpid/dotnet/msvc9/org.apache.qpid.messaging.sessionreceiver.sln
+++ b/cpp/bindings/qpid/dotnet/msvc9/org.apache.qpid.messaging.sessionreceiver.sln
@@ -21,7 +21,7 @@ Microsoft Visual Studio Solution File, Format Version 10.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Org.Apache.Qpid.Messaging", "..\src\msvc9\org.apache.qpid.messaging.vcproj", "{AA5A3B83-5F98-406D-A01C-5A921467A57D}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "org.apache.qpid.messaging.sessionreceiver", "..\src\msvc9\sessionreceiver\org.apache.qpid.messaging.sessionreceiver.csproj", "{B0A51CEC-30A2-4C2E-90BE-AE95107EAA05}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "org.apache.qpid.messaging.sessionreceiver", "..\src\sessionreceiver\msvc9\org.apache.qpid.messaging.sessionreceiver.csproj", "{B0A51CEC-30A2-4C2E-90BE-AE95107EAA05}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/cpp/bindings/qpid/dotnet/src/Receiver.cpp b/cpp/bindings/qpid/dotnet/src/Receiver.cpp
index bbd7dd4c52..43bb7dd3cb 100644
--- a/cpp/bindings/qpid/dotnet/src/Receiver.cpp
+++ b/cpp/bindings/qpid/dotnet/src/Receiver.cpp
@@ -344,9 +344,34 @@ namespace Messaging {
void Receiver::Close()
{
- msclr::lock lk(privateLock);
- ThrowIfDisposed();
+ System::Exception ^ newException = nullptr;
+ Message ^ newMessage = nullptr;
- nativeObjPtr->close();
+ try
+ {
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
+ nativeObjPtr->close();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+ finally
+ {
+ if (newException != nullptr)
+ {
+ if (newMessage != nullptr)
+ {
+ delete newMessage;
+ }
+ }
+ }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
}}}}
diff --git a/cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs b/cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs
index 680732068f..a15a8d60fe 100644
--- a/cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs
+++ b/cpp/bindings/qpid/dotnet/src/sessionreceiver/sessionreceiver.cs
@@ -37,6 +37,7 @@ namespace Org.Apache.Qpid.Messaging.SessionReceiver
public interface ISessionReceiver
{
void SessionReceiver(Receiver receiver, Message message);
+ void SessionException(Exception exception);
}
@@ -67,25 +68,32 @@ namespace Org.Apache.Qpid.Messaging.SessionReceiver
{
Receiver rcvr;
Message msg;
-
- keepRunning = true;
- while (keepRunning)
+ try
{
- rcvr = session.NextReceiver(DurationConstants.SECOND);
-
- if (null != rcvr)
+ keepRunning = true;
+ while (keepRunning)
{
- if (keepRunning)
+ rcvr = session.NextReceiver(DurationConstants.SECOND);
+
+ if (null != rcvr)
{
- msg = rcvr.Fetch(DurationConstants.SECOND);
- this.callback.SessionReceiver(rcvr, msg);
+ if (keepRunning)
+ {
+ msg = rcvr.Fetch(DurationConstants.SECOND);
+ this.callback.SessionReceiver(rcvr, msg);
+ }
}
+ //else
+ // receive timed out
+ // EventEngine exits the nextReceiver() function periodically
+ // in order to test the keepRunning flag
}
- //else
- // receive timed out
- // EventEngine exits the nextReceiver() function periodically
- // in order to test the keepRunning flag
}
+ catch (Exception e)
+ {
+ this.callback.SessionException(e);
+ }
+
// Private thread is now exiting.
}
diff --git a/cpp/bindings/qpid/examples/perl/README b/cpp/bindings/qpid/examples/perl/README
deleted file mode 100644
index 1e113f1fa0..0000000000
--- a/cpp/bindings/qpid/examples/perl/README
+++ /dev/null
@@ -1,26 +0,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.
-
-
-The examples in this directory are written against the raw Perl
-binding ("cqpid"). This binding is identical to the C++ messaging (in
-namespace qpid::messaging).
-
-It is desired that a layer will be written over this interface (called
-"qpid") that provides a more Perl-specific API. When this occurs,
-these examples will be changed to use the new Perl API.
-
diff --git a/cpp/bindings/qpid/examples/perl/client.pl b/cpp/bindings/qpid/examples/perl/client.pl
index 19d9d3f14f..586beb787e 100644..100755
--- a/cpp/bindings/qpid/examples/perl/client.pl
+++ b/cpp/bindings/qpid/examples/perl/client.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -20,47 +20,59 @@
use strict;
use warnings;
-use cqpid_perl;
+use qpid;
-my $url = ( @ARGV == 1 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672";
-my $connectionOptions = ( @ARGV > 1 ) ? $ARGV[1] : "";
+my $url = ( @ARGV == 1 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672";
+my $connectionOptions = ( @ARGV > 1 ) ? $ARGV[1] : "";
-
-my $connection = new cqpid_perl::Connection($url, $connectionOptions);
+# creates a new connection instance
+my $connection = new qpid::messaging::Connection( $url, $connectionOptions );
eval {
-$connection->open();
-my $session = $connection->createSession();
+ # open the connection and create a session for interacting with it
+ $connection->open();
-my $sender = $session->createSender("service_queue");
+ my $session = $connection->create_session();
+ my $sender = $session->create_sender("service_queue");
-#create temp queue & receiver...
-my $responseQueue = new cqpid_perl::Address("#response-queue; {create:always, delete:always}");
-my $receiver = $session->createReceiver($responseQueue);
+ # create an address and receiver for incoming messages
+ # the queue will be created always, and will be deleted
+ # when the receive disconnects
+ my $responseQueue = new qpid::messaging::Address(
+ "#response-queue; {create:always, delete:always}");
+ my $receiver = $session->create_receiver($responseQueue);
-#Now send some messages...
+ # Now send some messages...
-my @s = (
- "Twas brillig, and the slithy toves",
- "Did gire and gymble in the wabe.",
- "All mimsy were the borogroves,",
- "And the mome raths outgrabe."
- );
+ my @s = (
+ "Twas brillig, and the slithy toves",
+ "Did gire and gymble in the wabe.",
+ "All mimsy were the borogroves,",
+ "And the mome raths outgrabe."
+ );
-my $request = new cqpid_perl::Message();
-$request->setReplyTo($responseQueue);
-for (my $i=0; $i<4; $i++) {
- $request->setContent($s[$i]);
- $sender->send($request);
- my $response = $receiver->fetch();
- print $request->getContent() . " -> " . $response->getContent() . "\n";
-}
+ # create the message object, and set a reply-to address
+ # so that the server knows where to send responses
+ # the message object will be reused to send each line
+ my $request = new qpid::messaging::Message();
+ $request->set_reply_to($responseQueue);
+ for ( my $i = 0 ; $i < 4 ; $i++ ) {
+ $request->set_content( $s[$i] );
+ $sender->send($request);
+
+ # wait for the response to the last line sent
+ # the message will be taken directly from the
+ # broker's queue rather than waiting for it
+ # to be queued locally
+ my $response = $receiver->fetch();
+ print $request->get_content() . " -> "
+ . $response->get_content() . "\n";
+ }
-$connection->close();
+ # close the connection
+ $connection->close();
};
if ($@) {
die $@;
}
-
-
diff --git a/cpp/bindings/qpid/examples/perl/drain.pl b/cpp/bindings/qpid/examples/perl/drain.pl
index 60ac0c50ed..f7a710c485 100644..100755
--- a/cpp/bindings/qpid/examples/perl/drain.pl
+++ b/cpp/bindings/qpid/examples/perl/drain.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -20,79 +20,135 @@
use strict;
use warnings;
-use cqpid_perl;
+use qpid;
use Getopt::Long;
+use Pod::Usage;
-my $url = "127.0.0.1";
-my $timeout = 60;
-my $forever = 0;
-my $count = 1;
+my $url = "127.0.0.1";
+my $timeout = 0;
+my $forever = 0;
+my $count = 0;
my $connectionOptions = "";
-my $address = "amq.direct";
+my $address = "amq.direct";
+my $help;
my $result = GetOptions(
- "broker|b=s" => \ $url,
- "timeout|t=i" => \ $timeout,
- "forever|f" => \ $forever,
- "connection-options=s" => \ $connectionOptions,
- "count|c=i" => \ $count,
-);
-
-if (! $result) {
- print "Usage: perl drain.pl [OPTIONS]\n";
-}
+ "broker|b=s" => \$url,
+ "timeout|t=i" => \$timeout,
+ "forever|f" => \$forever,
+ "connection-options=s" => \$connectionOptions,
+ "count|c=i" => \$count,
+ "help|h" => \$help
+) || pod2usage( -verbose => 0 );
+
+pod2usage( -verbose => 1 ) if $help;
-if ($#ARGV ge 0) {
- $address = $ARGV[0]
+if ( $#ARGV ge 0 ) {
+ $address = $ARGV[0];
}
sub getTimeout {
- return ($forever) ? $cqpid_perl::Duration::FOREVER : new cqpid_perl::Duration($timeout*1000);
+
+ # returns either the named duration FOREVER if the
+ # forever cmdline argument was used, otherwise creates
+ # a new Duration of the specified length
+ return ($forever)
+ ? qpid::messaging::Duration::FOREVER
+ : new qpid::messaging::Duration( $timeout * 1000 );
}
+sub printProperties {
+ my $h = shift();
+ return qq[{${\(join', ',map"'$_': '$h->{$_}'",keys%$h)}}];
+}
-my $connection = new cqpid_perl::Connection($url, $connectionOptions);
+# create a connection object
+my $connection = new qpid::messaging::Connection( $url, $connectionOptions );
eval {
+ # open the connection, then create a session and receiver
$connection->open();
- my $session = $connection->createSession();
- my $receiver = $session->createReceiver($address);
+ my $session = $connection->create_session();
+ my $receiver = $session->create_receiver($address);
my $timeout = getTimeout();
+ my $message = new qpid::messaging::Message();
+ my $i = 0;
+
+ for ( ; ; ) {
+ eval { $message = $receiver->fetch($timeout); };
- my $message = new cqpid_perl::Message();
- my $i = 0;
+ if ($@) {
+ last;
+ }
+
+ # check if the message was on that was redelivered
+ my $redelivered =
+ ( $message->get_redelivered ) ? "redelivered=True, " : "";
+ print "Message("
+ . $redelivered
+ . "properties="
+ . printProperties( $message->get_properties() )
+ . ", content='";
- while($receiver->fetch($message, $timeout)) {
- print "Message(properties=" . $message->getProperties() . ",content='";
- if ($message->getContentType() eq "amqp/map") {
- my $content = cqpid_perl::decodeMap($message);
- map{ print "\n$_ => $content->{$_}"; } keys %{$content};
+ # if the message content was a map, then we will print
+ # it out as a series of name => value pairs
+ if ( $message->get_content_type() eq "amqp/map" ) {
+ my $content = $message->get_content();
+ map { print "\n$_ => $content->{$_}"; } keys %{$content};
}
else {
- print $message->getContent();
+ # it's not a map, so just print the content as a string
+ print $message->get_content();
}
print "')\n";
-
- my $replyto = $message->getReplyTo();
- if ($replyto->getName()) {
- print "Replying to " . $message->getReplyTo()->str() . "...\n";
- my $sender = $session->createSender($replyto);
- my $response = new cqpid_perl::Message("received by the server.");
+
+ # if the message had a reply-to address, then we'll send a
+ # response back letting the send know the message was processed
+ my $replyto = $message->get_reply_to();
+ if ( $replyto->get_name() ) {
+ print "Replying to " . $message->get_reply_to()->str() . "...\n";
+
+ # create a temporary sender for the specified queue
+ my $sender = $session->create_sender($replyto);
+ my $response =
+ new qpid::messaging::Message("received by the server.");
$sender->send($response);
}
+
+ # acknowledge all messages received on this queue so far
$session->acknowledge();
- if ($count and (++$i ==$count)) {
+ if ( $count and ( ++$i == $count ) ) {
last;
}
}
+
+ # close everything to clean up
$receiver->close();
$session->close();
$connection->close();
};
if ($@) {
- $connection->close();
- die $@;
+ $connection->close();
+ die $@;
}
+__END__
+
+=head1 NAME
+
+drain - Drains messages from the specified address
+
+=head1 SYNOPSIS
+
+ Options:
+ -h, --help show this message
+ -b VALUE, --broker VALUE url of broker to connect to
+ -t VALUE, --timeout VALUE timeout in seconds to wait before exiting
+ -f, --forever ignore timeout and wait forever
+ --connection-options VALUE connection options string in the form {name1:value1, name2:value2}
+ -c VALUE, --count VALUE number of messages to read before exiting
+
+=cut
+
diff --git a/cpp/bindings/qpid/examples/perl/hello_world.pl b/cpp/bindings/qpid/examples/perl/hello_world.pl
index a96b98a002..6ec7d52f1f 100644..100755
--- a/cpp/bindings/qpid/examples/perl/hello_world.pl
+++ b/cpp/bindings/qpid/examples/perl/hello_world.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -21,35 +21,35 @@ use strict;
use warnings;
use Data::Dumper;
-use cqpid_perl;
+use qpid;
my $broker = ( @ARGV > 0 ) ? $ARGV[0] : "localhost:5672";
my $address = ( @ARGV > 1 ) ? $ARGV[0] : "amq.topic";
my $connectionOptions = ( @ARGV > 2 ) ? $ARGV[1] : "";
-my $connection = new cqpid_perl::Connection($broker, $connectionOptions);
+# create a connection
+my $connection = new qpid::messaging::Connection( $broker, $connectionOptions );
eval {
+ # open the connection and create a session, and both a sender a receive
$connection->open();
- my $session = $connection->createSession();
- my $receiver = $session->createReceiver($address);
- my $sender = $session->createSender($address);
+ my $session = $connection->create_session();
- $sender->send(new cqpid_perl::Message("Hello world!"));
+ my $receiver = $session->create_receiver($address);
+ my $sender = $session->create_sender($address);
- #my $duration = new cqpid_perl::Duration(1000);
- #print ">>>" . $duration->getMilliseconds() . "\n";
+ # send a simple message
+ $sender->send( new qpid::messaging::Message("Hello world!") );
- my $message = $receiver->fetch($cqpid_perl::Duration::SECOND);
+ # receive the message, fetching it directly from the broker
+ my $message = $receiver->fetch(qpid::messaging::Duration::SECOND);
- #$message->setDurable(1);
- #print "Durable: " . $message->getDurable() . "\n";
- #print Dumper($message->getProperties());
-
- print $message->getContent() . "\n";
+ # output the message content, then acknowledge it
+ print $message->get_content() . "\n";
$session->acknowledge();
+ # close the connection
$connection->close();
};
diff --git a/cpp/bindings/qpid/examples/perl/hello_xml.pl b/cpp/bindings/qpid/examples/perl/hello_xml.pl
index cebf2ceee6..8d77c4b2b8 100644..100755
--- a/cpp/bindings/qpid/examples/perl/hello_xml.pl
+++ b/cpp/bindings/qpid/examples/perl/hello_xml.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -20,7 +20,7 @@
use strict;
use warnings;
-use cqpid_perl;
+use qpid;
my $broker = ( @ARGV > 0 ) ? $ARGV[0] : "localhost:5672";
my $connectionOptions = ( @ARGV > 1 ) ? $ARGV[1] : "";
@@ -36,23 +36,25 @@ END
my $address = <<END;
xml-exchange; {
-create: always,
+create: always,
node: { type: topic, x-declare: { type: xml } },
link: {
x-bindings: [{ exchange: xml-exchange, key: weather, arguments: { xquery:" $query" } }]
}}
END
-
-my $connection = new cqpid_perl::Connection($broker, $connectionOptions);
+# create a connection object
+my $connection = new qpid::messaging::Connection( $broker, $connectionOptions );
eval {
+ # open the connection, then create from it a session
+ # from the session, create a receiver to handle incoming messages
$connection->open();
- my $session = $connection->createSession();
+ my $session = $connection->create_session();
+ my $receiver = $session->create_receiver($address);
- my $receiver = $session->createReceiver($address);
-
- my $message = new cqpid_perl::Message();
+ # create a message and set its contentn
+ my $message = new qpid::messaging::Message();
my $content = <<END;
<weather>
@@ -62,14 +64,19 @@ eval {
<dewpoint>35</dewpoint>
</weather>
END
-
- $message->setContent($content);
- my $sender = $session->createSender('xml-exchange/weather');
+
+ $message->set_content($content);
+
+ # create a sender for the xml-exchange/weater topic
+ # then send the message
+ my $sender = $session->create_sender('xml-exchange/weather');
$sender->send($message);
-
+
+ # wait for the response and then output it to the screen
my $response = $receiver->fetch();
- print $response->getContent() . "\n";
+ print $response->get_content() . "\n";
+ # close the connection
$connection->close();
};
diff --git a/cpp/bindings/qpid/examples/perl/map_receiver.pl b/cpp/bindings/qpid/examples/perl/map_receiver.pl
index 2e2611e38f..a538adf380 100644..100755
--- a/cpp/bindings/qpid/examples/perl/map_receiver.pl
+++ b/cpp/bindings/qpid/examples/perl/map_receiver.pl
@@ -1,4 +1,4 @@
-#! /usr/bin/perl5
+#! /usr/bin/env perl
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -21,25 +21,33 @@ use strict;
use warnings;
use Data::Dumper;
-use cqpid_perl;
+use qpid;
-my $url = ( @ARGV > 0 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672";
-my $address = ( @ARGV > 1 ) ? $ARGV[0] : "message_queue; {create: always}";
+my $url = ( @ARGV > 0 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672";
+my $address = ( @ARGV > 1 ) ? $ARGV[0] : "message_queue; {create: always}";
my $connectionOptions = ( @ARGV > 2 ) ? $ARGV[1] : "";
-my $connection = new cqpid_perl::Connection($url, $connectionOptions);
+# create a connection object
+my $connection = new qpid::messaging::Connection( $url, $connectionOptions );
eval {
+ # open the connection, then create a session from it
$connection->open();
- my $session = $connection->createSession();
- my $receiver = $session->createReceiver($address);
+ my $session = $connection->create_session();
- my $content = cqpid_perl::decodeMap($receiver->fetch());
- #my $content = cqpid_perl::decodeList($receiver->fetch());
-
+ # create a receiver for the session, subscribed the the specified queue
+ my $receiver = $session->create_receiver($address);
+ # wait for a message to appear in the queue
+ my $message = $receiver->fetch();
+
+ # display the content of the message
+ my $content = $message->get_content();
print Dumper($content);
+ # acknowledge the message, removing it from the queue
$session->acknowledge();
+
+ # close everything, cleaning up
$receiver->close();
$connection->close();
};
diff --git a/cpp/bindings/qpid/examples/perl/map_sender.pl b/cpp/bindings/qpid/examples/perl/map_sender.pl
index 4107cd48b9..27063ef780 100644..100755
--- a/cpp/bindings/qpid/examples/perl/map_sender.pl
+++ b/cpp/bindings/qpid/examples/perl/map_sender.pl
@@ -1,4 +1,4 @@
-#! /usr/bin/perl5
+#! /usr/bin/env perl
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -21,29 +21,39 @@ use strict;
use warnings;
use Data::Dumper;
-use cqpid_perl;
+use qpid;
-my $url = ( @ARGV > 0 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672";
-my $address = ( @ARGV > 1 ) ? $ARGV[1] : "message_queue; {create: always}";
+my $url = ( @ARGV > 0 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672";
+my $address = ( @ARGV > 1 ) ? $ARGV[1] : "message_queue; {create: always}";
my $connectionOptions = ( @ARGV > 2 ) ? $ARGV[2] : "";
-my $connection = new cqpid_perl::Connection($url, $connectionOptions);
+# create a new connection object
+my $connection = new qpid::messaging::Connection( $url, $connectionOptions );
eval {
- $connection->open();
-
- my $session = $connection->createSession();
- my $sender = $session->createSender($address);
-
- my $message = new cqpid_perl::Message();
- my $content = { id => 987654321,
- name => "Widget",
- percent => sprintf("%.2f", 0.99),
- colours => [ qw (red green white) ],
- };
- cqpid_perl::encode($content, $message);
- $sender->send($message, 1);
+ # open the connection and create a session
+ $connection->open();
+ my $session = $connection->create_session();
+
+ # create a sender and connect it to the supplied address string
+ my $sender = $session->create_sender($address);
+
+ # create a message and set the content to be a map of values
+ my $message = new qpid::messaging::Message();
+ my $content = {
+ id => 987654321,
+ name => "Widget",
+ percent => sprintf( "%.2f", 0.99 ),
+ colours => [qw (red green white)],
+ };
+ $message->set_content($content);
+
+ # send the message
+ $sender->send( $message, 1 );
+
+ # close the connection and session
+ $session->close();
$connection->close();
};
diff --git a/cpp/bindings/qpid/examples/perl/server.pl b/cpp/bindings/qpid/examples/perl/server.pl
index b14da565b9..be43655aeb 100644..100755
--- a/cpp/bindings/qpid/examples/perl/server.pl
+++ b/cpp/bindings/qpid/examples/perl/server.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -20,43 +20,64 @@
use strict;
use warnings;
-use cqpid_perl;
+use qpid;
-my $url = ( @ARGV == 1 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672";
-my $connectionOptions = ( @ARGV > 1 ) ? $ARGV[1] : "";
+my $url = ( @ARGV == 1 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672";
+my $connectionOptions = ( @ARGV > 1 ) ? $ARGV[1] : "";
-
-my $connection = new cqpid_perl::Connection($url, $connectionOptions);
+# create a connection object
+my $connection = new qpid::messaging::Connection( $url, $connectionOptions );
eval {
+
+ # connect to the broker and create a session
$connection->open();
- my $session = $connection->createSession();
+ my $session = $connection->create_session();
- my $receiver = $session->createReceiver("service_queue; {create: always}");
+ # create a receiver for accepting incoming messages
+ my $receiver = $session->create_receiver("service_queue; {create: always}");
+ # go into an infinite loop to receive messages and process them
while (1) {
+
+ # wait for the next message to be processed
my $request = $receiver->fetch();
- my $address = $request->getReplyTo();
+
+
+ # get the address for sending replies
+ # if no address was supplised then we can't really respond, so
+ # only process when one is present
+ my $address = $request->get_reply_to();
if ($address) {
- my $sender = $session->createSender($address);
- my $s = $request->getContent();
+
+ # a temporary sender for sending to the response queue
+ my $sender = $session->create_sender($address);
+ my $s = $request->get_content();
$s = uc($s);
- my $response = new cqpid_perl::Message($s);
+
+ # create the response message and send it
+ my $response = new qpid::messaging::Message($s);
$sender->send($response);
- print "Processed request: " . $request->getContent() . " -> " . $response->getContent() . "\n";
+ print "Processed request: "
+ . $request->get_content() . " -> "
+ . $response->get_content() . "\n";
+
+ # acknowledge the message since it was processed
$session->acknowledge();
}
else {
- print "Error: no reply address specified for request: " . $request->getContent() . "\n";
+ print "Error: no reply address specified for request: "
+ . $request->get_content() . "\n";
$session->reject($request);
}
}
-$connection->close();
+ # close connections to clean up
+ $session->close();
+ $connection->close();
};
if ($@) {
die $@;
}
-
diff --git a/cpp/bindings/qpid/examples/perl/spout.pl b/cpp/bindings/qpid/examples/perl/spout.pl
index 7365e732bf..d8ac860143 100644..100755
--- a/cpp/bindings/qpid/examples/perl/spout.pl
+++ b/cpp/bindings/qpid/examples/perl/spout.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -20,117 +20,145 @@
use strict;
use warnings;
-use cqpid_perl;
+use qpid;
use Getopt::Long;
+use Pod::Usage;
use Time::Local;
-my $url = "127.0.0.1";
+my $url = "127.0.0.1";
my $timeout = 0;
my $count = 1;
my $id = "";
my $replyto = "";
my @properties;
my @entries;
-my $content = "";
+my $content = "";
my $connectionOptions = "";
-my $address = "amq.direct";
+my $address = "amq.direct";
+my $help;
my $result = GetOptions(
- "broker|b=s" => \ $url,
- "timeout|t=i" => \ $timeout,
- "count|c=i" => \ $count,
- "id|i=s" => \ $id,
- "replyto=s" => \ $replyto,
- "property|p=s@" => \ @properties,
- "map|m=s@" => \ @entries,
- "content=s" => \ $content,
- "connection-options=s" => \ $connectionOptions,
-);
-
-
-if (! $result) {
- print "Usage: perl drain.pl [OPTIONS]\n";
+ "broker|b=s" => \$url,
+ "timeout|t=i" => \$timeout,
+ "count|c=i" => \$count,
+ "id|i=s" => \$id,
+ "replyto=s" => \$replyto,
+ "property|p=s@" => \@properties,
+ "map|m=s@" => \@entries,
+ "content=s" => \$content,
+ "connection-options=s" => \$connectionOptions,
+ "help|h" => \$help
+) || pod2usage( -verbose => 0 );
+
+pod2usage( -verbose => 1 ) if $help;
+
+if ( $#ARGV ge 0 ) {
+ $address = $ARGV[0];
}
-
-if ($#ARGV ge 0) {
- $address = $ARGV[0]
-}
-
-
sub setEntries {
my ($content) = @_;
foreach (@entries) {
- my ($name, $value) = split("=", $_);
+ my ( $name, $value ) = split( "=", $_ );
$content->{$name} = $value;
}
}
-
sub setProperties {
my ($message) = @_;
foreach (@properties) {
- my ($name, $value) = split("=", $_);
- $message->getProperties()->{$name} = $value;
+ my ( $name, $value ) = split( "=", $_ );
+ $message->setProperty( $name, $value );
}
}
-my $connection = new cqpid_perl::Connection($url, $connectionOptions);
+# create a connection object
+my $connection = new qpid::messaging::Connection( $url, $connectionOptions );
eval {
+ # open the connection, create a session and then a sender
$connection->open();
- my $session = $connection->createSession();
- my $sender = $session->createSender($address);
+ my $session = $connection->create_session();
+ my $sender = $session->create_sender($address);
- my $message = new cqpid_perl::Message();
+ # create a message to be sent
+ my $message = new qpid::messaging::Message();
setProperties($message) if (@properties);
if (@entries) {
my $content = {};
setEntries($content);
- cqpid_perl::encode($content, $message);
+ $message->set_content($content);
}
elsif ($content) {
- $message->setContent($content);
- $message->setContentType("text/plain");
+ $message->set_content($content);
+ $message->set_content_type("text/plain");
}
+ # if a reply-to address was supplied, then create a receiver from the
+ # session and wait for a response to be sent
my $receiver;
if ($replyto) {
- my $responseQueue = new cqpid_perl::Address($replyto);
- $receiver = $session->createReceiver($responseQueue);
- $message->setReplyTo($responseQueue);
+ my $responseQueue = new qpid::messaging::Address($replyto);
+ $receiver = $session->create_receiver($responseQueue);
+ $message->set_reply_to($responseQueue);
}
my $start = localtime;
- my @s = split(/[:\s]/, $start);
- my $s = "$s[3]$s[4]$s[5]";
- my $n = $s;
-
- for (my $i = 0;
- ($i < $count || $count == 0) and
- ($timeout == 0 || abs($n - $s) < $timeout);
- $i++) {
+ my @s = split( /[:\s]/, $start );
+ my $s = "$s[3]$s[4]$s[5]";
+ my $n = $s;
+
+ for (
+ my $i = 0 ;
+ ( $i < $count || $count == 0 )
+ and ( $timeout == 0 || abs( $n - $s ) < $timeout ) ;
+ $i++
+ )
+ {
$sender->send($message);
if ($receiver) {
+ print "Waiting for a response.\n";
my $response = $receiver->fetch();
- print "$i -> " . $response->getContent() . "\n";
+ print "$i -> " . $response->get_content() . "\n";
}
my $now = localtime;
- my @n = split(/[:\s]/, $now);
- my $n = "$n[3]$n[4]$n[5]";
+ my @n = split( /[:\s]/, $now );
+ my $n = "$n[3]$n[4]$n[5]";
}
$session->sync();
$connection->close();
};
if ($@) {
- $connection->close();
- die $@;
+ $connection->close();
+ die $@;
}
+__END__
+
+=head1 NAME
+
+spout - Send messages to the specified address
+
+=head1 SYNOPSIS
+
+ Usage: spout [OPTIONS] ADDRESS
+
+ Options:
+ -h, --help show this message
+ -b VALUE, --broker VALUE url of broker to connect to
+ -t VALUE, --timeout VALUE exit after the specified time
+ -c VALUE, --count VALUE stop after count messageshave been sent, zero disables
+ -i VALUE, --id VALUE use the supplied id instead of generating one
+ --replyto VALUE specify reply-to value
+ -P VALUE, --property VALUE specify message property
+ -M VALUE, --map VALUE specify entry for map content
+ --content VALUE specify textual content
+ --connection-options VALUE connection options string in the form {name1:value1, name2:value2}
+=cut
diff --git a/cpp/bindings/qpid/perl/CMakeLists.txt b/cpp/bindings/qpid/perl/CMakeLists.txt
index 0d66c144db..a1380fa4d0 100644
--- a/cpp/bindings/qpid/perl/CMakeLists.txt
+++ b/cpp/bindings/qpid/perl/CMakeLists.txt
@@ -21,18 +21,25 @@
## Use Swig to generate a literal binding to the C++ API
##------------------------------------------------------
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/perl.i PROPERTIES CPLUSPLUS ON)
-set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/perl.i PROPERTIES SWIG_FLAGS "-I${qpid-cpp_SOURCE_DIR}/include")
+set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/perl.i
+ PROPERTIES SWIG_FLAGS "-I${qpid-cpp_SOURCE_DIR}/include;-I${qpid-cpp_SOURCE_DIR}/include;-I${qpid-cpp_SOURCE_DIR}/bindings")
swig_add_module(cqpid_perl perl ${CMAKE_CURRENT_SOURCE_DIR}/perl.i)
swig_link_libraries(cqpid_perl qpidmessaging qpidtypes qmf2 ${PERL_LIBRARY})
-set_source_files_properties(${swig_generated_file_fullname} PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -I${PERL_INCLUDE_PATH} -I${qpid-cpp_SOURCE_DIR}/include")
+set_source_files_properties(${swig_generated_file_fullname} PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
+include_directories(${PERL_INCLUDE_PATH}
+ ${qpid-cpp_SOURCE_DIR}/include
+ ${qpid-cpp_SOURCE_DIR}/bindings)
##----------------------------------
## Install the complete Perl binding
##----------------------------------
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcqpid_perl.so
${CMAKE_CURRENT_BINARY_DIR}/cqpid_perl.pm
- DESTINATION ${PERL_ARCHLIB}
+ ${CMAKE_CURRENT_SOURCE_DIR}/qpid.pm
+ ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE
+ ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.PL
+ DESTINATION ${PERL_PFX_ARCHLIB}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
diff --git a/cpp/bindings/qpid/perl/ChangeLog b/cpp/bindings/qpid/perl/ChangeLog
new file mode 100644
index 0000000000..72685443b1
--- /dev/null
+++ b/cpp/bindings/qpid/perl/ChangeLog
@@ -0,0 +1,6 @@
+Version 0.22 (TBA):
+ * QPID-4466: qpid::messaging::Duration now supports multiplication
+ * QPID-4416: Messages with embedded nulls won't break on getContentPtr
+ * QPID-4505: Provides unit tests for Address, Duration and Message
+ * QPID-4504: Broke up the Per classes into separate source modules
+ * QPID-4580: Added perldoc markup to each source module
diff --git a/cpp/bindings/qpid/perl/LICENSE b/cpp/bindings/qpid/perl/LICENSE
new file mode 100644
index 0000000000..bc46b77047
--- /dev/null
+++ b/cpp/bindings/qpid/perl/LICENSE
@@ -0,0 +1,206 @@
+=========================================================================
+== Apache License ==
+=========================================================================
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
diff --git a/cpp/bindings/qpid/perl/Makefile.PL b/cpp/bindings/qpid/perl/Makefile.PL
new file mode 100644
index 0000000000..7a4d7f03dc
--- /dev/null
+++ b/cpp/bindings/qpid/perl/Makefile.PL
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use ExtUtils::MakeMaker;
+use Config;
+
+WriteMakefile(
+ NAME => 'cqpid_perl',
+ PREREQ_PM => {},
+ LIBS => ["-lqpidmessaging -lqpidtypes"],
+ C => ['cqpid_perl.cpp'],
+);
diff --git a/cpp/bindings/qpid/perl/README b/cpp/bindings/qpid/perl/README
new file mode 100644
index 0000000000..ca5a96e539
--- /dev/null
+++ b/cpp/bindings/qpid/perl/README
@@ -0,0 +1,15 @@
+Qpid Perl Language Bindings
+===========================
+
+How to get help
+===============
+
+You can use the perldoc command to display API help for working with Qpid.
+
+ perldoc qpid_messaging.pm
+
+will show a simple example application written in Perl that uses the APIs.
+From there you can display the individual module documentation by typing:
+
+ perldoc [module]
+
diff --git a/cpp/bindings/qpid/perl/lib/qpid/messaging/Address.pm b/cpp/bindings/qpid/perl/lib/qpid/messaging/Address.pm
new file mode 100644
index 0000000000..d417770b1c
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid/messaging/Address.pm
@@ -0,0 +1,338 @@
+#
+# 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.
+#
+
+=pod
+
+=head1 NAME
+
+qpid::messaging::Address
+
+=head1 DESCRIPTION
+
+An B<Address> represents an address to which messages can be sent or
+from which they can be received.
+
+=head2 THE ADDRESS STRING
+
+An address can be described suing the following pattern:
+
+E<lt>addressE<gt> [ / E<lt>subjectE<gt> ]= ; [ { E<lt>keyE<gt> : E<lt>valueE<gt> , ... } ]
+
+where B<address> is a simple name and B<subject> is a subject or subject
+pattern.
+
+=head3 ADDRESS OPTIONS
+
+The options, encluded in curly braces, are key:value pairs delimited by a comma.
+The values can be nested maps also enclosed in curly braces. Or they can be
+lists of values, where they are contained within square brackets but still comma
+delimited, such as:
+
+ [value1,value2,value3]
+
+The following are the list of supported options:
+
+=over
+
+=item B<create>
+
+Indicates if the address should be created; values are B<always>, B<never>,
+B<sender> or B<receiver>
+
+=item B<assert>
+
+Indicates whether or not to assert any specified node properties; values are
+B<always>, B<never>, B<sender> or B<receiver>
+
+=item B<delete>
+
+Indicates whether or not to delete the addressed node when a sender or receiver
+is cancelled; values are B<always>, B<never>, B<sender> or B<receiver>
+
+=item B<node>
+
+A nested map describing properties for the addressed node. Properties are
+B<type> (B<topic> or B<queue>), B<durable> (a boolean), B<x-declare> (a nested
+map of AMQP 0.10-specific options) and B<x-bindings> (a nested list which
+specifies a queue, exchange or a binding key and arguments).
+
+=item B<link>
+
+=item B<mode>
+
+=back
+
+=cut
+
+package qpid::messaging::Address;
+
+use overload (
+ 'bool' => \& boolify,
+ '""' => \& stringify,
+ );
+
+sub boolify {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return length($impl->getName());
+}
+
+sub stringify {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $self->str();
+}
+
+sub str {
+ my ($self) = @_;
+
+ return $self->get_implementation()->str();
+}
+
+=pod
+
+=head1 CONSTRUCTOR
+
+Creates an B<Address>
+
+=over
+
+=item $address = new qpid::messaging::Address( addr )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * addr
+
+The address string.
+
+=back
+
+=cut
+sub new {
+ my ($class) = @_;
+ my ($self) = {};
+
+ # 2 args: either a string address or a cqpid_perl::Address
+ # 3+ args: name + subject + options + type
+ if (@_ eq 2) {
+ my $address = $_[1];
+
+ if (ref($address) eq 'cqpid_perl::Address') {
+ $self->{_impl} = $address;
+ } else {
+ $self->{_impl} = new cqpid_perl::Address($_[1]);
+ }
+ } elsif (@_ >= 4) {
+ my $impl = new cqpid_perl::Address($_[1], $_[2], $_[3]);
+
+ $impl->setType($_[4]) if @_ >= 5;
+
+ $self->{_impl} = $impl;
+ } else {
+ die "You must specify an address."
+ }
+
+ bless $self, $class;
+ return $self;
+}
+
+sub get_implementation {
+ my ($self) = @_;
+ return $self->{_impl};
+}
+
+=pod
+
+=head1 ATTRIBUTES
+
+=cut
+
+=pod
+
+=head2 NAME
+
+The name portion of the address.
+
+=over
+
+=item $address->set_name( name )
+
+=item $name = $address->get_name
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * name
+
+See the address string explanation.
+
+=back
+
+=cut
+sub set_name {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->setName($_[1]);
+}
+
+sub get_name {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getName();
+}
+
+=pod
+
+=head2 SUBJECT
+
+The subject portion of the address.
+
+=over
+
+=item $address->set_subject( subject )
+
+=item $subject = $address->get_subject
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * subject
+
+See the address string explanation.
+
+=back
+
+=cut
+sub set_subject {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->setSubject($_[1]);
+}
+
+sub get_subject {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getSubject;
+}
+
+=pod
+
+=head2 OPTIONS
+
+The address options.
+
+=over
+
+=item $address->set_options( options )
+
+=item @opts = $address->get_options
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * options
+
+The set of name:value pairs for the address. See the address string explanation.
+
+=back
+
+=cut
+sub set_options {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $options = $_[1];
+
+ die "Options cannot be null" if !defined($options);
+
+ $impl->setOptions($_[1]);
+}
+
+sub get_options {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getOptions;
+}
+
+=pod
+
+=head2 TYPE
+
+The type of the address determines how B<Sender> and B<Receiver> objects are
+constructed for it. It also affects how a b<reply-to> address is encoded.
+
+If no type is specified then it willb e determined by querying the broker.
+Explicitly setting the type prevents this.
+
+=over
+
+=item $address->set_type( type )
+
+=item $type = $address->get_type
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * type
+
+Values can be either B<queue> or B<type>.
+
+=back
+
+=cut
+sub set_type {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $type = $_[1];
+
+ die "Type must be defined" if !defined($type);
+
+ $impl->setType($type);
+}
+
+sub get_type {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getType;
+}
+
+1;
diff --git a/cpp/bindings/qpid/perl/lib/qpid/messaging/Connection.pm b/cpp/bindings/qpid/perl/lib/qpid/messaging/Connection.pm
new file mode 100644
index 0000000000..6d478cdf0c
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid/messaging/Connection.pm
@@ -0,0 +1,291 @@
+#
+# 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.
+#
+
+=pod
+
+=head1 NAME
+
+qpid::messaging::Connection
+
+=head1 DESCRIPTION
+
+A B<qpid::messaging::Connection> represents a network connection to a remote
+endpoint.
+
+=cut
+
+package qpid::messaging::Connection;
+
+=pod
+
+=head1 CONSTRUCTOR
+
+=over
+
+=item $conn = new qpid::messaging::Connection
+
+=item $conn = new qpid::messaging::Connection( url )
+
+=item $conn = new qpid::messaging::Connection( url, options )
+
+Creates a connection object. Raises a C<MessagingError> if an invalid
+connection option is used.
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * url
+
+The URL for the broker. See B<qpid::messaging::Address> for more on
+ address strings
+
+=item * options
+
+The connection options.
+
+=back
+
+=cut
+
+sub new {
+ my ($class) = @_;
+ my $self = {
+ _url => $_[1] || "localhost:5672",
+ _options => $_[2] || {},
+ _impl => $_[3],
+ };
+
+ bless $self, $class;
+ return $self;
+}
+
+=pod
+
+=head1 ACTIONS
+
+=cut
+
+
+=pod
+
+=head2 OPENING AND CLOSING CONNECTIONS
+
+=cut
+
+
+=pod
+
+=over
+
+=item $conn->open
+
+Establishes the connection to the broker.
+
+=back
+
+=cut
+sub open {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ # if we have an implementation instance then use it, otherwise
+ # create a new implementation instance
+ unless (defined($impl)) {
+ my $url = $self->{_url};
+ my ($options) = $self->{_options};
+
+ $impl = new cqpid_perl::Connection($url, $options);
+ $self->{_impl} = $impl
+ }
+
+ $impl->open() unless $impl->isOpen()
+}
+
+=pod
+
+=over
+
+=item $conn->is_open
+
+Reports whether the connection is open.
+
+=back
+
+=cut
+sub is_open {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ if (defined($impl) && $impl->isOpen()) {
+ 1;
+ } else {
+ 0;
+ }
+}
+
+=pod
+
+=over
+
+=item $conn->close
+
+Closes the connection.
+
+=back
+
+=cut
+sub close {
+ my ($self) = @_;
+
+ if ($self->is_open) {
+ my $impl = $self->{_impl};
+
+ $impl->close;
+ $self->{_impl} = undef;
+ }
+}
+
+=pod
+
+=head2 SESSIONS
+
+=cut
+
+
+=pod
+
+=over
+
+=item $session = $conn->create_session
+
+=item $conn->create_session( name )
+
+Creates a new session.
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * name
+
+Specifies a name for the session.
+
+=back
+
+=cut
+sub create_session {
+ my ($self) = @_;
+
+ die "No connection available." unless ($self->open);
+
+ my $impl = $self->{_impl};
+ my $name = $_[1] || "";
+ my $session = $impl->createSession($name);
+
+ return new qpid::messaging::Session($session, $self);
+}
+
+=pod
+
+=over
+
+=item $session = $conn->create_transactional_session
+
+=item $session = $conn->create_transaction_session( name )
+
+Creates a transactional session.
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * name
+
+Specifies a name for the session.
+
+=back
+
+=cut
+sub create_transactional_session {
+ my ($self) = @_;
+
+ die "No connection available." unless ($self->open);
+
+ my $impl = $self->{_impl};
+ my $name = $_[1] || "";
+ my $session = $impl->createTransactionalSession($name);
+
+ return new qpid::messaging::Session($session, $self);
+}
+
+=pod
+
+=over
+
+=item $session = $conn->get_session( name )
+
+Returns the session with the specified name.
+
+=over
+
+=item $name
+
+The name given to the session when it was created.
+
+=back
+
+=back
+
+=cut
+sub get_session {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getSession($_[1]);
+}
+
+=pod
+
+=over
+
+=item $uname = $conn->get_authenticated_username
+
+Returns the username user to authenticate with the broker.
+
+If the conneciton did not use authentication credentials, then the
+username returned is "anonymous".
+
+=back
+
+=cut
+sub get_authenticated_username {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getAuthenticatedUsername;
+}
+
+1;
diff --git a/cpp/bindings/qpid/perl/lib/qpid/messaging/Duration.pm b/cpp/bindings/qpid/perl/lib/qpid/messaging/Duration.pm
new file mode 100644
index 0000000000..7d05daeeab
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid/messaging/Duration.pm
@@ -0,0 +1,204 @@
+#
+# 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.
+#
+
+=pod
+
+=head1 NAME
+
+qpid::messaging::Duration
+
+=head1 DESCRIPTION
+
+A B<qpid::messaging::Duration> represents a period of time in milliseconds.
+
+=head1 NAMED DURATIONS
+
+The following named durations are available as constants
+
+=over
+
+=item B<FOREVER>
+
+The maximum wait time, equal to the maximum integer value for the platform.
+Effective this will wait forever.
+
+=item B<IMMEDIATE>
+
+An alias for 0 milliseconds.
+
+=item B<SECOND>
+
+An alias for 1,000 milliseconds.
+
+=item B<MINUTE>
+
+An alias for 60,000 milliseconds.
+
+=back
+
+=cut
+
+package qpid::messaging::Duration;
+
+=pod
+
+=head1 OPERATORS
+
+=cut
+
+use overload (
+ "*" => \&multiply,
+ "==" => \&equalify,
+ "!=" => \&unequalify,
+ );
+
+=pod
+
+=over
+
+=item $doubled = $duration * $factor
+
+=item $doubled = $duration * 2
+
+Multiplies the duration and returns a new instance.
+
+=over
+
+=item $factor
+
+A factor for multiplying the duration.
+
+=back
+
+=back
+
+=cut
+sub multiply {
+ my ($self) = @_;
+ my $factor = $_[1];
+
+ die "Factor must be non-negative values" if !defined($factor) || ($factor < 0);
+
+ my $duration = $self->{_impl} * $factor;
+
+ return new qpid::messaging::Duration($duration);
+}
+
+sub equalify {
+ my ($self) = @_;
+ my $that = $_[1];
+
+ return 0 if !defined($that) || !UNIVERSAL::isa($that, 'qpid::messaging::Duration');;
+
+ return ($self->get_milliseconds() == $that->get_milliseconds()) ? 1 : 0;
+}
+
+sub unequalify {
+ my ($self) = @_;
+ my $that = $_[1];
+
+ return 1 if !defined($that) || !UNIVERSAL::isa($that, 'qpid::messaging::Duration');;
+
+ return ($self->get_milliseconds() != $that->get_milliseconds()) ? 1 : 0;
+}
+
+=pod
+
+=head1 CONSTRUCTOR
+
+Creates a new instance.
+
+=over
+
+=item duration = new qpid::messaging::Duration( time )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * time
+
+The duration in B<milliseconds>.
+
+=back
+
+=cut
+sub new {
+ my ($class) = @_;
+ my $duration = $_[1];
+
+ die "Duration time period must be defined" if !defined($duration);
+
+ if (!UNIVERSAL::isa($duration, 'cqpid_perl::Duration')) {
+ die "Duration must be non-negative" if $duration < 0;
+ $duration = new cqpid_perl::Duration($duration);
+ }
+
+ my ($self) = {
+ _impl => $duration,
+ };
+
+ bless $self, $class;
+ return $self;
+}
+
+=pod
+
+=head1 ATTRIBUTES
+
+=cut
+
+
+=pod
+
+=head2 MILLISECONDS
+
+The length of time is measured in milliseconds.
+
+=over
+
+=item time = $duration->get_milliseconds
+
+=back
+
+=cut
+sub get_milliseconds {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getMilliseconds();
+}
+
+sub get_implementation {
+ my ($self) = @_;
+
+ return $self->{_impl};
+}
+
+# TODO: Need a better way to define FOREVER
+use constant {
+ FOREVER => new qpid::messaging::Duration(1000000),
+ IMMEDIATE => new qpid::messaging::Duration(0),
+ SECOND => new qpid::messaging::Duration(1000),
+ MINUTE => new qpid::messaging::Duration(60000),
+};
+
+1;
diff --git a/cpp/bindings/qpid/perl/lib/qpid/messaging/Message.pm b/cpp/bindings/qpid/perl/lib/qpid/messaging/Message.pm
new file mode 100644
index 0000000000..6437290244
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid/messaging/Message.pm
@@ -0,0 +1,584 @@
+#
+# 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.
+#
+
+=pod
+
+=head1 NAME
+
+qpid::messaging::Message
+
+=head1 DESCRIPTION
+
+A B<qpid::messaging::Message> a routable piece of information.
+
+=cut
+
+package qpid::messaging::Message;
+
+
+=pod
+
+=head1 CONSTRUCTOR
+
+Creates a B<Message>.
+
+=over
+
+=item $msg = new qpid::messaging::Message
+
+=item $msg = new qpid::messaging::Message( $content )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * $content
+
+The message's content.
+
+=back
+
+=cut
+sub new {
+ my ($class) = @_;
+ my $content = $_[1] if (@_ > 1);
+ my $impl = $_[2] if (@_ > 2);
+ my ($self) = {
+ _content => $content || "",
+ _impl => $impl || undef,
+ };
+
+ unless (defined($self->{_impl})) {
+ my $impl = new cqpid_perl::Message($self->{_content});
+
+ $self->{_impl} = $impl;
+ }
+
+ bless $self, $class;
+ return $self;
+}
+
+sub get_implementation {
+ my ($self) = @_;
+
+ return $self->{_impl};
+}
+
+
+=pod
+
+=head1 ATTRIBUTES
+
+=cut
+
+=pod
+
+=head2 REPLY TO ADDRESS
+
+The reply-to address tells a receiver where to send any responses.
+
+=over
+
+=item $msg->set_reply_to( "#reqly-queue;{create:always}" )
+
+=item $msg->set_reply_to( address )
+
+=item $address = $msg->get_reply_to
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * address
+
+The address. Can be either an instance of B<qpid::messaging::Address> or else an
+address string.
+
+=back
+
+=cut
+sub set_reply_to {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $address = $_[1];
+
+ # if the address was a string, then wrap it
+ # in a qpid::messaging::Address instance
+ if (!UNIVERSAL::isa($address, 'qpid::messaging::Address')) {
+ $address = new qpid::messaging::Address($_[1]);
+ }
+
+ $impl->setReplyTo($address->get_implementation());
+}
+
+sub get_reply_to {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return new qpid::messaging::Address($impl->getReplyTo());
+}
+
+=pod
+
+=head2 SUBJECT
+
+=over
+
+=item $msg->set_subject( "responses" )
+
+=item $msg->set_subject( subject )
+
+=item $subject = $msg->get_subject
+
+=back
+
+=cut
+sub set_subject {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->setSubject($_[1]);
+}
+
+sub get_subject {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getSubject;
+}
+
+=pod
+
+=head2 CONTENT TYPE
+
+This should be set by the sending application and indicates to the
+recipients of the message how to interpret or decide the content.
+
+By default, only dictionaries and maps are automatically given a content
+type. If this content type is replaced then retrieving the content will
+not behave correctly.
+
+=over
+
+=item $msg->set_content_type( content_type )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * content_type
+
+The content type. For a list this would be C<amqp/list> and for a hash it is
+C<amqp/map>.
+
+=back
+
+=cut
+sub set_content_type {
+ my ($self) = @_;
+ my $type = $_[1];
+
+ my $impl = $self->{_impl};
+ $impl->setContentType($type);
+}
+
+sub get_content_type {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getContentType;
+}
+
+=pod
+
+=head2 MESSAGE ID
+
+A message id must be a UUID type. A non-UUID value will be converted
+to a zero UUID, thouygh a blank ID will be left untouched.
+
+=over
+
+=item $msg->set_message_id( id )
+
+=item $id = $msg->get_message_id
+
+=back
+
+=cut
+sub set_message_id {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $id = $_[1];
+
+ die "message id must be defined" if !defined($id);
+
+ $impl->setMessageId($id);
+}
+
+sub get_message_id {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getMessageId;
+}
+
+=pod
+
+=head2 USER ID
+
+The user id should, in general, be the user-id which was used when
+authenticating the connection itself, as the messaging infrastructure
+will verify this.
+
+See B<qpid::messaging::Address#authenticated_username>.
+
+=over
+
+=item $msg->set_user_id( id )
+
+=item $id = $msg->get_user_id
+
+=back
+
+=cut
+sub set_user_id {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->setUserId($_[1]);
+}
+
+sub get_user_id {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getUserId;
+}
+
+=pod
+
+=head2 CORRELATION ID
+
+The correlation id can be used as part of a protocol for message exchange
+patterns; e.g., a request-response pattern might require the correlation id
+of the request and hte response to match, or it might use the message id of
+the request as the correlation id on the response.
+
+B<NOTE:> If the id is not a string then the id is setup using the object's
+string representation.
+
+=over
+
+=item $msg->set_correlation_id( id )
+
+=item $id = $msg->get_correlation_id
+
+=back
+
+=cut
+sub set_correlation_id {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->setCorrelationId($_[1]);
+}
+
+sub get_correlation_id {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getCorrelationId;
+}
+
+=pod
+
+=head2 PRIORITY
+
+The priority may be used by the messaging infrastructure to prioritize
+delivery of messages with higher priority.
+
+B<NOTE:> If the priority is not an integer type then it is set using the
+object's integer represtation. If the integer value is greater than an
+8-bit value then only 8-bits are used.
+
+=over
+
+=item $msg->set_priority( priority )
+
+=item $priority = $msg->get_priority
+
+=back
+
+=cut
+sub set_priority {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $priority = $_[1];
+
+ die "Priority must be provided" if !defined($priority);
+
+ $priority = int($priority);
+ die "Priority must be non-negative" if $priority < 0;
+
+ $impl->setPriority($priority);
+}
+
+sub get_priority {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getPriority;
+}
+
+=pod
+
+=head2 TIME TO LIVE
+
+This can be used by the messaging infrastructure to discard messages
+that are no longer of relevance.
+
+=over
+
+=item $msg->set_ttl( ttl )
+
+=item $ttl = $msg->get_ttl
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * ttl
+
+A B<qpid::messaging::Duration> instance. If it is not, then a new instance
+is created using the integer value for the argument.
+
+A B<negative> value is treated as the equipment of
+B<qpid::messaging::Duration::FOREVER>.
+
+=back
+
+=cut
+sub set_ttl {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $duration = $_[1];
+
+ die "Duration must be provided" if !defined($duration);
+ if (!UNIVERSAL::isa($duration, 'qpid::messaging::Duration')) {
+ $duration = int($duration);
+
+ if ($duration < 0) {
+ $duration = qpid::messaging::Duration::FOREVER;
+ } elsif ($duration == 0) {
+ $duration = qpid::messaging::Duration::IMMEDIATE;
+ } else {
+ $duration = new qpid::messaging::Duration(int($duration));
+ }
+ }
+
+ $impl->setTtl($duration->get_implementation());
+}
+
+sub get_ttl {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return new qpid::messaging::Duration($impl->getTtl);
+}
+
+=pod
+
+=head2 DURABILITY
+
+The durability of a B<Message> is a hint to the messaging infrastructure that
+the message should be persisted or otherwise stored. This helps to ensure that
+the message is not lost due to failures or a shutdown.
+
+=over
+
+=item $msg->set_durable( 1 )
+
+=item $durable = $msg->get_durable
+
+=back
+
+=cut
+sub set_durable {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $durable = $_[1];
+
+ die "Durable must be specified" if !defined($durable);
+
+ $impl->setDurable($durable);
+}
+
+sub get_durable {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getDurable;
+}
+
+=pod
+
+=head2 REDELIVERED
+
+This is a hint to the messaging infrastructure that if de-duplication is
+required, that this message should be examined to determine if it is a
+duplicate.
+
+=over
+
+=item $msg->set_redelivered( 1 )
+
+=item $redelivered = $msg->get_redelivered
+
+=back
+
+=cut
+sub set_redelivered {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $redelivered = $_[1];
+
+ die "Redelivered must be specified" if !defined($redelivered);
+
+ $impl->setRedelivered($redelivered);
+}
+
+sub get_redelivered {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getRedelivered;
+}
+
+=pod
+
+=head2 PROPERTIES
+
+Named properties for the message are name/value pairs.
+
+=over
+
+=item $msg->set_property( name, value )
+
+=item $value = $msg->get_property( name )
+
+=item @props = $msg->get_properties
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * name
+
+The property name.
+
+=item * value
+
+The property value.
+
+=back
+
+=cut
+sub set_property {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ my $key = $_[1];
+ my $value = $_[2];
+
+ $impl->setProperty($key, $value);
+}
+
+sub get_properties {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getProperties;
+}
+
+=pod
+
+=head2 CONTENT
+
+The message content.
+
+=begin _private
+
+TODO: Need to make the content automatically encode and decode for
+hashes and lists.
+
+=end _private
+
+=over
+
+=item $msg->set_content( content )
+
+=item $content = $msg->get_content
+
+=item $length = $msg->get_content_size
+
+=back
+
+=cut
+sub set_content {
+ my ($self) = @_;
+ my $content = $_[1];
+ my $impl = $self->{_impl};
+
+ die "Content must be provided" if !defined($content);
+
+ $self->{_content} = $content;
+
+ qpid::messaging::encode($content, $self);
+}
+
+sub get_content {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+ $content = $self->{_content} || undef;
+
+ if(!defined($content)) {
+ $content = qpid::messaging::decode($self);
+ $self->{_content} = $content;
+ }
+
+ return $content;
+}
+
+sub get_content_size {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getContentSize;
+}
+
+1;
diff --git a/cpp/bindings/qpid/perl/lib/qpid/messaging/Receiver.pm b/cpp/bindings/qpid/perl/lib/qpid/messaging/Receiver.pm
new file mode 100644
index 0000000000..c3bc4bb8a8
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid/messaging/Receiver.pm
@@ -0,0 +1,317 @@
+#
+# 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.
+#
+
+=pod
+
+=head1 NAME
+
+qpid::messaging::Receiver
+
+=head1 DESCRIPTION
+
+A B<qpid::messaging::Receiver> is the entity though which messages are received.
+
+An instance can only be created using an active (i.e., not previously closed)
+B<qpid::messaging::Session>.
+
+=head1 EXAMPLE
+
+ # create a connection and a session
+ my $conn = new qpid::messaging::Connection("mybroker:5672");
+ conn->open;
+ my $session = $conn->create_session;
+
+ # create a receiver that listens on the "updates" topic of "alerts"
+ my $recv = $session->create_receiver("alerts/updates");
+
+ # set the local queue size to hold a maximum of 100 messages
+ $recv->set_capacity(100);
+
+ # wait for an incoming message and process it
+ my $incoming = $recv->get;
+ process($incoming)
+
+=cut
+
+package qpid::messaging::Receiver;
+
+sub new {
+ my ($class) = @_;
+ my ($self) = {
+ _impl => $_[1],
+ _session => $_[2],
+ };
+
+ die "Must provide an implementation." unless defined($self->{_impl});
+ die "Must provide a Session." unless defined($self->{_session});
+
+ bless $self, $class;
+ return $self;
+}
+
+=pod
+
+=head1 ACTIONS
+
+=cut
+
+
+=pod
+
+There are two ways to retrieve messages: from the local queue or from the
+remote queue.
+
+=head2 GETTING FROM THE LOCAL QUEUE
+
+Messages can be held locally in message queues.
+
+=over
+
+=item $incoming = $receiver->get
+
+=item $incoming = $receiver->get( timeout)
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * timeout
+
+The period of time to wait for a message before raising an exception. If no
+period of time is specified then the default is to wait B<forever>.
+
+=back
+
+=cut
+sub get {
+ my ($self) = @_;
+ my $duration = $_[1];
+ my $impl = $self->{_impl};
+
+ $duration = $duration->get_implementation() if defined($duration);
+
+ my $message = undef;
+
+ if (defined($duration)) {
+ $message = $impl->get($duration);
+ } else {
+ $message = $impl->get;
+ }
+}
+
+=pod
+
+=head2 FETCHING FROM THE REMOTE QUEUE
+
+Messages held in the remote queue must be fetched from the broker in order
+to be processed.
+
+=over
+
+=item $incoming = $receiver->fetch
+
+=item $incoming = $receiver->fetch( time )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * timeout
+
+The period of time to wait for a message before raising an exception. If no
+period of time is specified then the default is to wait B<forever>.
+
+=back
+
+=cut
+sub fetch {
+ my ($self) = @_;
+ my $duration = $_[1];
+ my $impl = $self->{_impl};
+ my $message = undef;
+
+ if (defined($duration)) {
+ $message = $impl->fetch($duration->get_implementation());
+ } else {
+ $message = $impl->fetch;
+ }
+
+ return new qpid::messaging::Message("", $message);
+}
+
+=pod
+
+=head2 CLOSING THE RECEIVER
+
+=over
+
+=item receiver->close
+
+Closes the receiver.
+
+=back
+
+=cut
+sub close {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->close;
+}
+
+=pod
+
+=head1 ATTRIBUTES
+
+=cut
+
+
+=pod
+
+=head2 CAPACITY
+
+The maximum number of messages that are prefected and held locally is
+determined by the capacity of the receiver.
+
+=over
+
+=item $receiver->set_capacity( size )
+
+=item $size = $receiver->get_capacity
+
+=back
+
+=cut
+sub set_capacity {
+ my ($self) = @_;
+ my $capacity = $_[1];
+ my $impl = $self->{_impl};
+
+ $impl->setCapacity($capacity);
+}
+
+sub get_capacity {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getCapacity;
+}
+
+=pod
+
+=head2 AVAILABLE
+
+The number of messages waiting in the local queue.
+
+The value is always in the range 0 <= B<available> <= B<capacity>.
+
+=over
+
+=item $count = $receiver->get_available
+
+=back
+
+=cut
+
+sub get_available {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getAvailable;
+}
+
+=pod
+
+=over
+
+=item $count = $receiver->get_unsettled
+
+Returns the number of messages that have been received and acknowledged but
+whose acknowledgements have not been confirmed by the sender.
+
+=back
+
+=cut
+sub get_unsettled {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getUnsettled;
+}
+
+=pod
+
+=over
+
+=item $name = $receiver->get_name
+
+Returns the name of the receiver.
+
+=back
+
+=cut
+sub get_name {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getName;
+}
+
+=pod
+
+=over
+
+=item $session = $receiver->get_session
+
+Returns the B<qpid::messaging::Session> instance from which this
+receiver was created.
+
+=back
+
+=cut
+sub get_session {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->{_session};
+}
+
+=pod
+
+=over
+
+=item $receiver->is_closed
+
+Returns whether the receiver is closed.
+
+=back
+
+=cut
+sub is_closed {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->isClosed;
+}
+
+1;
diff --git a/cpp/bindings/qpid/perl/lib/qpid/messaging/Sender.pm b/cpp/bindings/qpid/perl/lib/qpid/messaging/Sender.pm
new file mode 100644
index 0000000000..5d0896ff79
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid/messaging/Sender.pm
@@ -0,0 +1,258 @@
+#
+# 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.
+#
+
+=pod
+
+=head1 NAME
+
+qpid::messaging::Sender
+
+=head1 DESCRIPTION
+
+A B<qpid::messaging::Sender> is the entity through which messages are sent.
+
+An instance can only be created using an active (i.e., not previously closed)
+B<qpid::messaging::Session>.
+
+=head1 EXAMPLE
+
+ # create a connection and a session
+ my $conn = new qpid::messaging::Connection("mybroker:5672");
+ conn->open;
+ my $session = $conn->create_session;
+
+ # create a sender that posts messages to the "updates" queue
+ my $sender = $session->create_sender "updates;{create:always}"
+
+ # begin sending updates
+ while( 1 ) {
+ my $content = wait_for_event;
+ $sender->send(new qpid::messaging::Message($content));
+ }
+
+=cut
+
+package qpid::messaging::Sender;
+
+sub new {
+ my ($class) = @_;
+ my ($self) = {
+ _impl => $_[1],
+ _session => $_[2],
+ };
+
+ die "Must provide an implementation." unless defined($self->{_impl});
+ die "Must provide a Session." unless defined($self->{_session});
+
+ bless $self, $class;
+ return $self;
+}
+
+=pod
+
+=head1 ACTIONS
+
+=cut
+
+
+=pod
+
+=head2 SENDING MESSAGES
+
+=over
+
+=item $sender->send( message )
+
+=item $sender->send( message, block)
+
+Sends a message, optionally blocking until the message is received by
+the broker.
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * message
+
+The message to be sent.
+
+=item * block
+
+If true then blocks until the message is received.
+
+=back
+
+=cut
+sub send {
+ my ($self) = @_;
+ my $message = $_[1];
+ my $sync = $_[2] || 0;
+
+ die "No message to send." unless defined($message);
+
+ my $impl = $self->{_impl};
+
+ $impl->send($message->get_implementation, $sync);
+}
+
+=pod
+
+=head2 CLOSING THE SENDER
+
+=item sender->close
+
+Closes the sender.
+
+This does not affect the ownering B<Session> or B<Connection>
+
+=back
+
+=cut
+sub close {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->close;
+}
+
+=pod
+
+=head1 ATTRIBUTES
+
+=cut
+
+=pod
+
+=head2 CAPACITY
+
+The capacity is the number of outoing messages that can be held pending
+confirmation of receipt by the broker.
+
+=over
+
+=item sender->set_capacity( size )
+
+=item $size = sender->get_capacity
+
+=back
+
+=back
+
+=cut
+sub set_capacity {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->setCapacity($_[1]);
+}
+
+sub get_capacity {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getCapacity;
+}
+
+=pod
+
+=head2 UNSETTLED
+
+The number of messages sent that are pending receipt confirmation by the broker.
+
+=over
+
+=item $count = sender->get_unsettled
+
+=back
+
+=cut
+sub get_unsettled {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getUnsettled;
+}
+
+=pod
+
+=head2 AVAILABLE
+
+The available slots for sending messages.
+
+This differences form B<capacity> in that it is the available slots in the
+senders capacity for holding outgoing messages. The difference between
+capacity and available is the number of messages that have no been delivered
+yet.
+
+=over
+
+=item $slots = sender->get_available
+
+=back
+
+=cut
+sub get_available {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getAvailable();
+}
+
+=pod
+
+=head2 NAME
+
+The human-readable name for this sender.
+
+=over
+
+=item $name = sender-get_name
+
+=back
+
+=cut
+sub get_name {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getName;
+}
+
+=pod
+
+=head2 SESSION
+
+The owning session from which the sender was created.
+
+=over
+
+=item $session = $sender->get_session
+
+=back
+
+=cut
+sub get_session {
+ my ($self) = @_;
+
+ return $self->{_session};
+}
+
+1;
diff --git a/cpp/bindings/qpid/perl/lib/qpid/messaging/Session.pm b/cpp/bindings/qpid/perl/lib/qpid/messaging/Session.pm
new file mode 100644
index 0000000000..af85731685
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid/messaging/Session.pm
@@ -0,0 +1,473 @@
+#
+# 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.
+#
+
+=pod
+
+=head1 NAME
+
+qpid::messaging::Session
+
+=head1 DESCRIPTION
+
+A B<qpid::messaging::Session> represents a distinct conversation between end
+points. They are created from an active (i.e, not closed) B<Connection>.
+
+A session is used to acknowledge individual or all messages that have
+passed through it, as well as for creating senders and receivers for conversing.
+=cut
+package qpid::messaging::Session;
+
+sub new {
+ my ($class) = @_;
+ my ($self) = {
+ _impl => $_[1],
+ _conn => $_[2],
+ };
+
+ die "Must provide an implementation." unless defined($self->{_impl});
+ die "Must provide a Connection." unless defined($self->{_conn});
+
+ bless $self, $class;
+ return $self;
+}
+
+=pod
+
+=head1 ACTIONS
+
+=cut
+
+
+=pod
+
+=head2 CLOSING THE SESSION
+
+=over
+
+=item $session->close
+
+=back
+
+=cut
+sub close {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->close;
+}
+
+=pod
+
+=head2 TRANSACTIONS
+
+Transactions can be rolled back or committed.
+
+=over
+
+=item $session->commit
+
+=item $session->rollback
+
+=back
+
+=cut
+sub commit {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->commit;
+}
+
+sub rollback {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->rollback;
+}
+
+=pod
+
+=head2 MESSAGE DISPOSITIONS
+
+=cut
+
+
+=pod
+
+=over
+
+=item $session->acknowledge( msg )
+
+Acknowledges that a specific message that has been received.
+
+=back
+
+=begin _private
+
+TODO: How to handle acknowledging a specific message?
+
+=end _private
+
+=cut
+sub acknowledge {
+ my ($self) = @_;
+ my $sync = $_[1] || 0;
+
+ my $impl = $self->{_impl};
+
+ $impl->acknowledge($sync);
+}
+
+=pod
+
+=over
+
+=item $session->reject( msg )
+
+Rejects the specified message. A reject message will not be redelivered.
+
+=back
+
+=cut
+sub reject {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->reject($_[1]);
+}
+
+=pod
+
+=over
+
+=item $session->release( msg )
+
+Releases the specified message, which allows the broker to attempt to
+redeliver it.
+
+=back
+
+=cut
+sub release {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->release($_[1]);
+}
+
+=pod
+
+=over
+
+=item $session->sync
+
+=item $session->sync( block )
+
+Requests synchronization with the broker.
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * block
+
+If true, then the call blocks until the process completes.
+
+=back
+
+=cut
+sub sync {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ if(defined($_[1])) {
+ $impl->sync($_[1]);
+ } else {
+ $impl->sync;
+ }
+}
+
+=pod
+
+=head2 SENDERS AND RECEIVERS
+
+=cut
+
+
+=pod
+
+=over
+
+=item $sender = $session->create_sender( address )
+
+Creates a new sender.
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * address
+
+The sender address. See B<qpid::messaging::Address> for more details
+
+=back
+
+=cut
+sub create_sender {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ my $address = $_[1];
+
+ if (ref($address) eq "qpid::messaging::Address") {
+ my $temp = $address->get_implementation();
+ $address = $temp;
+ }
+ my $send_impl = $impl->createSender($address);
+
+ return new qpid::messaging::Sender($send_impl, $self);
+}
+
+=pod
+
+=over
+
+=item $sender = $session->get_session( name )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * name
+
+The name of the sender.
+
+Raises an exception when no sender with that name exists.
+
+=back
+
+=cut
+sub get_sender {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ my $send_impl = $impl->getSender($_[1]);
+ my $sender = undef;
+
+ if (defined($send_impl)) {
+ $sender = new qpid::messaging::Sender($send_impl, $self);
+ }
+
+ return $sender;
+}
+
+=pod
+
+=over
+
+=item $receiver = $session->create_receiver( address )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * address
+
+The receiver address. see B<qpid::messaging::Address> for more details.
+
+=back
+
+=cut
+sub create_receiver {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ my $address = $_[1];
+
+ if (ref($address) eq "qpid::messaging::Address") {
+ $address = $address->get_implementation();
+ }
+ my $recv_impl = $impl->createReceiver($address);
+
+ return new qpid::messaging::Receiver($recv_impl, $self);
+}
+
+=pod
+
+=over
+
+=item $receiver = $session->get_receiver( name )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * name
+
+The name of the receiver.
+
+=back
+
+=cut
+sub get_receiver {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ my $recv_impl = $impl->getReceiver($_[1]);
+ my $receiver = undef;
+
+ if (defined($recv_impl)) {
+ $receiver = new qpid::messaging::Receiver($recv_impl, $self);
+ }
+
+ return $receiver;
+}
+
+=pod
+
+=head1 ATTRIBUTES
+
+=cut
+
+
+=pod
+
+=head2 RECEIVABLE
+
+The total number of receivable messages, and messages already received,
+by receivers associated with this session.
+
+=over
+
+=item $session->get_receivable
+
+=back
+
+=cut
+sub get_receivable {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getReceivable;
+}
+
+=pod
+
+=head2 UNSETTLED ACKNOWLEDGEMENTS
+
+The number of messages that have been acknowledged by this session whose
+acknowledgements have not been confirmed as processed by the broker.
+
+=over
+
+=item $session->get_unsettled_acks
+
+=back
+
+=cut
+sub get_unsettled_acks {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->getUnsettledAcks;
+}
+
+=pod
+
+=head2 NEXT RECEIVER
+
+The next receiver is the one, created by this session, that has any pending
+local messages.
+
+If no receivers are found within the timeout then a B<MessagingException> is
+raised.
+
+=over
+
+=item $session->get_next_receiver
+
+=item $session->get_next_receiver( timeout )
+
+=back
+
+=head3 ARGUMENTS
+
+=over
+
+=item * timeout
+
+The period of time to wait for a receiver to be found. If no period of time is
+specified then the default is to wait B<forever>.
+
+=back
+
+=cut
+sub get_next_receiver {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ my $timeout = $_[1] || qpid::messaging::Duration::FOREVER;
+
+ return $impl->getNextReceiver($timeout);
+}
+
+=pod
+
+=head2 CONNECTION
+
+=over
+
+=item $conn = $session->get_connection
+
+Returns the owning connection for the session.
+
+=back
+
+=cut
+sub get_connection {
+ my ($self) = @_;
+
+ return $self->{_conn};
+}
+
+sub has_error {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ return $impl->hasError;
+}
+
+sub check_for_error {
+ my ($self) = @_;
+ my $impl = $self->{_impl};
+
+ $impl->checkForError;
+}
+
+1;
diff --git a/cpp/bindings/qpid/perl/lib/qpid/messaging/codec.pm b/cpp/bindings/qpid/perl/lib/qpid/messaging/codec.pm
new file mode 100644
index 0000000000..c9d6845eb9
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid/messaging/codec.pm
@@ -0,0 +1,53 @@
+#
+# 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 qpid::messaging;
+
+sub encode {
+ my $content = $_[0];
+ my $message = $_[1];
+ my $impl = $message->get_implementation();
+
+ if(UNIVERSAL::isa($content, "HASH")) {
+ cqpid_perl::encode($content, $impl, "amqp/map");
+ } elsif(UNIVERSAL::isa($content, "ARRAY")) {
+ cqpid_perl::encode($content, $impl, "amqp/list");
+ } else {
+ $message->get_implementation()->setContent($content);
+ }
+}
+
+sub decode {
+ my $message = $_[0];
+ my $impl = $message->get_implementation();
+ my $content_type = $impl->getContentType();
+
+ if($content_type eq "amqp/map") {
+ $result = cqpid_perl::decodeMap($impl);
+ } elsif($content_type eq "amqp/list") {
+ $result = cqpid_perl::decodeList($impl);
+ } else {
+ $result = $impl->getContent();
+ }
+
+ return $result;
+}
+
+1;
+
diff --git a/cpp/bindings/qpid/perl/lib/qpid_messaging.pm b/cpp/bindings/qpid/perl/lib/qpid_messaging.pm
new file mode 100644
index 0000000000..e6a2681c15
--- /dev/null
+++ b/cpp/bindings/qpid/perl/lib/qpid_messaging.pm
@@ -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.
+#
+
+use strict;
+use warnings;
+use cqpid_perl;
+
+package qpid::messaging;
+
+use qpid::messaging::codec;
+use qpid::messaging::Address;
+use qpid::messaging::Duration;
+use qpid::messaging::Message;
+use qpid::messaging::Receiver;
+use qpid::messaging::Sender;
+use qpid::messaging::Session;
+use qpid::messaging::Connection;
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+qpid::messaging
+
+=head1 DESCRIPTION
+
+The Qpid Messaging framework is an enterprise messaging framework
+based on the open-source AMQP protocol.
+
+=head1 EXAMPLE
+
+Here is a simple example application. It creates a link to a broker located
+on a system named C<broker.myqpiddomain.com>. It then creates a new messaging
+queue named C<qpid-examples> and publishes a message to it. It then consumes
+that same message and closes the connection.
+
+ use strict;
+ use warnings;
+
+ use qpid;
+
+ # create a connection, open it and then create a session named "session1"
+ my $conn = new qpid::messaging::Connection("broker.myqpiddomain.com");
+ $conn->open();
+ my $session = $conn->create_session("session1");
+
+ # create a sender and a receiver
+ # the sender marks the queue as one that is deleted when the sender disconnects
+ my $send = $session->create_sender("qpid-examples;{create:always}");
+ my $recv = $session->create_receiver("qpid-examples");
+
+ # create an outgoing message and send it
+ my $outgoing = new qpid::messaging::Message();
+ $outgoing->set_content("The time is " . localtime(time)");
+ $send->send($outgoing);
+
+ # set the receiver's capacity to 10 and then check out many messages are pending
+ $recv->set_capacity(10);
+ print "There are " . $recv->get_available . " messages waiting.\n";
+
+ # get the nextwaitingmessage, which should be in the local queue now,
+ # and output the contents
+ my $incoming = $recv->fetch();
+ print "Received the following message: " . $incoming->get_content() . "\n";
+ # the output should be the text that was sent earlier
+
+ # acknowledge the message, letting the sender know the message was received
+ printf "The sender currently has " . $send->get_unsettled . " message(s) pending.\n";
+ # should report 1 unsettled message
+ $session->acknowledge(); # acknowledges all pending messages
+ print "Now sender currently has " . $send->get_unsettled . " message(s) pending.\n";
+ # should report 0 unsettled messages
+
+ # close the connection
+ $conn->close
diff --git a/cpp/bindings/qpid/perl/perl.i b/cpp/bindings/qpid/perl/perl.i
index 38ac91761f..0d118ae0fb 100644
--- a/cpp/bindings/qpid/perl/perl.i
+++ b/cpp/bindings/qpid/perl/perl.i
@@ -19,7 +19,7 @@
%module cqpid_perl
%include "std_string.i"
-%include "../../swig_perl_typemaps.i"
+%include "qpid/swig_perl_typemaps.i"
/* Define the general-purpose exception handling */
%exception {
@@ -31,5 +31,5 @@
}
}
-%include "../qpid.i"
+%include "qpid/qpid.i"
diff --git a/cpp/bindings/qpid/perl/qpid.pm b/cpp/bindings/qpid/perl/qpid.pm
new file mode 100644
index 0000000000..88b98353a8
--- /dev/null
+++ b/cpp/bindings/qpid/perl/qpid.pm
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+use qpid_messaging;
+
+1;
diff --git a/cpp/bindings/qpid/perl/t/Address.t b/cpp/bindings/qpid/perl/t/Address.t
new file mode 100644
index 0000000000..4e74f8cad2
--- /dev/null
+++ b/cpp/bindings/qpid/perl/t/Address.t
@@ -0,0 +1,102 @@
+#!/usr/bin/env perl -w
+#
+# 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.
+#
+
+use Test::More qw(no_plan);
+use Test::Exception;
+
+require 'utils.pm';
+
+# verify that qpid is available
+BEGIN { use_ok( 'qpid' ); }
+require_ok ('qpid' );
+
+# construction
+# address cannot be null
+dies_ok (sub {new qpid::messaging::Address(undef);},
+ "Address cannot be null");
+
+# can use an address
+my $address = new qpid::messaging::Address("0.0.0.0");
+ok ($address, "Can be created with an arbitrary address");
+
+# name
+# name cannot be null
+dies_ok (sub {$address->set_name(undef);},
+ "Name cannot be null");
+
+# name can be an empty string
+$address->set_name("");
+ok ($address->get_name() eq "",
+ "Name can be empty");
+
+# name can be an arbitrary string
+my $name = random_string(25);
+$address->set_name($name);
+ok ($address->get_name() eq $name,
+ "Name can be an arbitrary string");
+
+# subject
+# cannot be null
+dies_ok (sub {$address->set_subject(undef);},
+ "Subject cannot be null");
+
+# can be an empty string
+$address->set_subject("");
+ok ($address->get_subject() eq "",
+ "Subject can be empty");
+
+# can be an arbitrary string
+my $subject = random_string(64);
+$address->set_subject($subject);
+ok ($address->get_subject() eq $subject,
+ "Subject can be an arbitrary string");
+
+# options
+# options cannot be null
+dies_ok (sub {$address->set_options(undef);},
+ "Options cannot be null");
+
+# options can be an empty hash
+$address->set_options({});
+ok (eq_hash($address->get_options(), {}),
+ "Options can be an empty hash");
+
+# options cannot be arbitrary values
+my %options = ("create", "always", "delete", "always");
+$address->set_options(\%options);
+ok (eq_hash($address->get_options(), \%options),
+ "Options can be arbitrary keys");
+
+# type
+# cannot be null
+dies_ok (sub {$address->set_type(undef);},
+ "Type cannot be null");
+
+# can be an empty string
+$address->set_type("");
+ok ($address->get_type() eq "",
+ "Type can be an empty string");
+
+# can be an arbitrary string
+my $type = random_string(16);
+$address->set_type($type);
+ok ($address->get_type() eq $type,
+ "Type can be an arbitrary type");
+
diff --git a/cpp/bindings/qpid/perl/t/Duration.t b/cpp/bindings/qpid/perl/t/Duration.t
new file mode 100644
index 0000000000..6975e8006f
--- /dev/null
+++ b/cpp/bindings/qpid/perl/t/Duration.t
@@ -0,0 +1,124 @@
+#!/usr/bin/env perl -w
+#
+# 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.
+#
+
+use Test::More qw(no_plan);
+use Test::Exception;
+
+require 'utils.pm';
+
+# verify that qpid is available
+BEGIN { use_ok( 'qpid' ); }
+require_ok ('qpid' );
+
+# milliseconds
+# duration cannot be null
+{
+ dies_ok (sub {new qpid::messaging::Duration(undef);},
+ "Durations cannot have null time periods");
+}
+
+# duration cannot be negative
+{
+ my $period = 0 - (int(rand(65535)) + 1);
+ dies_ok(sub {new qpid::messaging::Duration($period);},
+ "Duration times cannot be negative");
+}
+
+# duration can be an arbitrary value
+{
+ my $period = int(rand(65535));
+ my $duration = new qpid::messaging::Duration($period);
+ ok ($duration->get_milliseconds() == $period,
+ "Milliseconds are properly stored and fetched");
+}
+
+# multiplier
+# cannot multiply by null
+dies_ok(sub {qpid::messaging::Duration::FOREVER * undef;},
+ "Cannot multiply a duration times a null");
+
+# cannot multiply by a negative
+dies_ok (sub {qpid::messaging::Duration::MINUTE * -2;},
+ "Duration cannot be multiplied by a negative");
+
+# multiply by zero returns a zero time period
+{
+ my $result = qpid::messaging::Duration::MINUTE * 0;
+
+ ok ($result->get_milliseconds() == 0,
+ "Multiplying duration by 0 returns a 0 duration");
+}
+
+# multiply by arbitrary values works
+{
+ my $factor = int(1 + rand(100));
+ my $result = qpid::messaging::Duration::MINUTE * $factor;
+ ok ($result->get_milliseconds() == 60000 * $factor,
+ "Multiplying by a factor returns a new Duration with that period");
+}
+
+# equality
+# always fails with null
+ok (!(qpid::messaging::Duration::MINUTE == undef),
+ "Duration is never equal to null");
+
+# never equal to a non-duration class
+ok (!(qpid::messaging::Duration::MINUTE == random_string(12)),
+ "Duration is never equal to a non-Duration");
+
+# works with self
+ok (qpid::messaging::Duration::MINUTE == qpid::messaging::Duration::MINUTE,
+ "Duration is always equal to itself");
+
+# fails with non-equal instance
+ok (!(qpid::messaging::Duration::MINUTE == qpid::messaging::Duration::SECOND),
+ "Duration non-equality works");
+
+# works with equal instance
+{
+ my $result = qpid::messaging::Duration::MINUTE * 0;
+ ok ($result == qpid::messaging::Duration::IMMEDIATE,
+ "Equality comparison works correctly");
+}
+
+# non-equality
+# always not equal to null
+ok (qpid::messaging::Duration::MINUTE != undef,
+ "Always unequal to null");
+
+# always not equal to a non-duration class
+ok (qpid::messaging::Duration::MINUTE != random_string(64),
+ "Always unequal to a non-duration class");
+
+# not unequal to itself
+ok (!(qpid::messaging::Duration::MINUTE != qpid::messaging::Duration::MINUTE),
+ "Never unequal to itself");
+
+# not unequal to an equal instance
+{
+ my $duration = qpid::messaging::Duration::MINUTE * 1;
+ ok (!(qpid::messaging::Duration::MINUTE != $duration),
+ "Never unequal to an equal instance");
+}
+
+# works with unequal instances
+ok (qpid::messaging::Duration::MINUTE != qpid::messaging::Duration::FOREVER,
+ "Always unequal to a non-equal instance");
+
diff --git a/cpp/bindings/qpid/perl/t/Message.t b/cpp/bindings/qpid/perl/t/Message.t
new file mode 100644
index 0000000000..15baafb446
--- /dev/null
+++ b/cpp/bindings/qpid/perl/t/Message.t
@@ -0,0 +1,286 @@
+#!/usr/bin/env perl -w
+#
+# 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.
+#
+
+use Test::More qw(no_plan);
+use Test::Exception;
+
+require 'utils.pm';
+
+# verify that qpid is available
+BEGIN { use_ok( 'qpid' ); }
+require_ok ('qpid' );
+
+# Create a new message
+my $message = new qpid::messaging::Message();
+isa_ok($message, 'qpid::messaging::Message');
+
+# reply to
+# rejects an null address
+dies_ok (sub {$message->set_reply_to(undef);},
+ "Reply to cannot be null.");
+
+# can handle a string address
+$message->set_reply_to("test");
+ok ($message->get_reply_to()->str() eq "test",
+ "Reply to can be set");
+
+# subject
+# cannot have an null subject
+dies_ok (sub {$message->set_subject(undef);},
+ "Subject cannot be null");
+
+# can have an empty subject
+$message->set_subject("");
+ok ($message->get_subject() eq "",
+ "Subject can be empty");
+
+# can have a subject
+my $subject = random_string(16);
+$message->set_subject($subject);
+ok ($message->get_subject() eq $subject,
+ "Subject can be set.");
+
+# content type
+# cannot have an null content type
+dies_ok (sub {$message->set_content_type(undef);},
+ "Content type must be defined.");
+
+# can an empty content type
+$message->set_content_type("");
+ok ($message->get_content_type() eq "",
+ "Content type can be empty");
+
+# can have an arbitrary content type
+my $content_type = random_string(10);
+$message->set_content_type($content_type);
+ok ($message->get_content_type() eq $content_type,
+ "Content type can be arbitrary");
+
+# can be for a map
+$content_type = "amqp/map";
+$message->set_content_type($content_type);
+ok ($message->get_content_type() eq $content_type,
+ "Content type can be for a map");
+
+# message id
+# cannot be null
+dies_ok (sub {$message->set_message_id(undef);},
+ "Message id cannot be null");
+
+# can be an empty string
+$message->set_message_id("");
+ok ($message->get_message_id() eq "",
+ "Message id can be empty");
+
+# can be an arbitrary string
+my $id = random_string(32);
+$message->set_message_id($id);
+ok ($message->get_message_id() eq $id,
+ "Message id can be an arbitrary string");
+
+# can be a UUID
+$id = generate_uuid();
+$message->set_message_id($id);
+ok ($message->get_message_id() eq $id,
+ "Message id can be a valid UUID");
+
+# user id
+# cannot be null
+dies_ok (sub {$message->set_user_id(undef);},
+ "User id cannot be null");
+
+# can be an empty string
+my $user_id = "";
+$message->set_user_id($user_id);
+ok ($message->get_user_id() eq $user_id,
+ "User id can be empty");
+
+# can be an arbitrary string
+$id = random_string(65);
+$message->set_user_id($user_id);
+ok ($message->get_user_id() eq $user_id,
+ "User id can be an arbitrary string");
+
+# correlation id
+# cannot be null
+dies_ok (sub {$message->set_correlation_id(undef);},
+ "Correlation id cannot be null");
+
+# can be empty
+my $correlation_id = "";
+$message->set_correlation_id($correlation_id);
+ok ($message->get_correlation_id() eq $correlation_id,
+ "Correlation id can be an empty string");
+
+# can be an arbitrary string
+$correlation_id = random_string(32);
+$message->set_correlation_id($correlation_id);
+ok ($message->get_correlation_id() eq $correlation_id,
+ "Correlation id can be an arbitrary string");
+
+# priority
+# cannot be nul
+dies_ok (sub {$message->set_priority(undef);},
+ "Priority cannot be null");
+
+# cannot be negative
+my $priority = 0 - (rand(2**8) + 1);
+dies_ok (sub {$message->set_priority($priority);},
+ "Priority cannot be negative");
+
+# can be 0
+$message->set_priority(0);
+ok ($message->get_priority() == 0,
+ "Priority can be zero");
+
+# can be an arbitrary value
+$priority = int(rand(2**8) + 1);
+$message->set_priority($priority);
+ok ($message->get_priority() == $priority,
+ "Priority can be any positive value");
+
+# ttl
+# cannot be null
+dies_ok (sub {$message->set_ttl(undef);},
+ "TTL cannot be null");
+
+# can be a duration
+$message->set_ttl(qpid::messaging::Duration::FOREVER);
+ok ($message->get_ttl()->get_milliseconds() == qpid::messaging::Duration::FOREVER->get_milliseconds(),
+ "TTL can be a Duration");
+
+# if numeric, is converted to a duration
+my $duration = rand(65535);
+$message->set_ttl($duration);
+ok ($message->get_ttl()->get_milliseconds() == int($duration),
+ "TTL can be any arbitrary duration");
+
+# if 0 it's converted to IMMEDIATE
+$message->set_ttl(0);
+ok ($message->get_ttl()->get_milliseconds() == qpid::messaging::Duration::IMMEDIATE->get_milliseconds(),
+ "TTL of 0 is converted to IMMEDIATE");
+
+# if negative it's converted to FOREVER
+$message->set_ttl(0 - (rand(65535) + 1));
+ok ($message->get_ttl()->get_milliseconds() == qpid::messaging::Duration::FOREVER->get_milliseconds(),
+ "TTL of <0 is converted to FOREVER");
+
+# durable
+# cannot be null
+dies_ok (sub {$message->set_durable(undef);},
+ "Durable cannot be null");
+
+# can be set to true
+$message->set_durable(1);
+ok ($message->get_durable(),
+ "Durable can be true");
+
+# can be set to false
+$message->set_durable(0);
+ok (!$message->get_durable(),
+ "Durable can be false");
+
+# redelivered
+# redelivered cannot be null
+dies_ok (sub {$message->set_redelivered(undef);},
+ "Redelivered cannot be null");
+
+# can be set to true
+$message->set_redelivered(1);
+ok ($message->get_redelivered(),
+ "Redelivered can be true");
+
+# can be set to false
+$message->set_redelivered(0);
+ok (!$message->get_redelivered(),
+ "Redelivered can be false");
+
+# properties
+# can retrieve all properties
+my $properties = $message->get_properties();
+ok (UNIVERSAL::isa($properties, 'HASH'),
+ "Returns the properties as a hash map");
+
+# property
+# setting a property using a null key fails
+dies_ok (sub {$message->set_property(undef, "bar");},
+ "Property cannot have a null key");
+
+# setting a property with a null value succeeds
+my $key = random_string(16);
+$message->set_property($key, undef);
+ok (!$message->get_properties()->{$key},
+ "Properties can have null values");
+
+# setting a property succeeds
+my $value = random_string(255);
+$message->set_property($key, $value);
+ok ($message->get_properties()->{$key} eq $value,
+ "Messages can have arbitrary property values");
+
+# content
+# cannot be null
+dies_ok (sub {$message->set_content(undef);},
+ "Content cannot be null");
+
+# can be an empty string
+$message->set_content("");
+ok ($message->get_content() eq "",
+ "Content can be an empty string");
+
+# can be an arbitrary string
+my $content = random_string(255);
+$message->set_content($content);
+ok ($message->get_content() eq $content,
+ "Content can be an arbitrary string");
+
+# Embedded nulls should be handled properly
+$content = { id => 1234, name => "With\x00null" };
+qpid::messaging::encode($content, $message);
+my $map = qpid::messaging::decode_map($message);
+ok ($map->{name} eq "With\x00null",
+ "Nulls embedded in map values work.");
+
+# Unicode strings shouldn't be broken
+$content = { id => 1234, name => "Euro=\x{20AC}" };
+qpid::messaging::encode($content, $message);
+$map = qpid::messaging::decode_map($message);
+ok ($map->{name} eq "Euro=\x{20AC}",
+ "Unicode strings encoded correctly.");
+
+# Setting the content as a hash automatically encodes it
+($content) = {"id" => "1234", "name" => "qpid"};
+$message->set_content($content);
+ok ($message->get_content_type() eq "amqp/map",
+ "Hashes are automatically encoded correctly");
+
+# Setting the content as a list automatically encodes it
+my @acontent = (1, 2, 3, 4);
+$message->set_content(\@acontent);
+ok ($message->get_content_type() eq "amqp/list",
+ "Lists are automatically encoded correctly");
+
+# content size
+# content size is correct
+my $content_size = int(rand(256));
+$content = random_string($content_size);
+$message->set_content($content);
+ok ($message->get_content_size() == $content_size,
+ "Content size is correct");
diff --git a/cpp/bindings/qpid/perl/t/utils.pm b/cpp/bindings/qpid/perl/t/utils.pm
new file mode 100644
index 0000000000..db8093d324
--- /dev/null
+++ b/cpp/bindings/qpid/perl/t/utils.pm
@@ -0,0 +1,38 @@
+# 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.
+#
+
+use Digest::MD5;
+
+sub random_string
+{
+ my $len=$_[0];
+ my @chars=('a'..'z','A'..'Z','0'..'9','_');
+ my $result;
+
+ foreach (1..$len) {
+ $result .= $chars[rand @chars];
+ }
+ return $result;
+}
+
+sub generate_uuid
+{
+ return Digest::MD5::md5_base64( rand );
+}
+
+1;
diff --git a/cpp/bindings/qpid/python/CMakeLists.txt b/cpp/bindings/qpid/python/CMakeLists.txt
index 9cb40162a5..2693475dea 100644
--- a/cpp/bindings/qpid/python/CMakeLists.txt
+++ b/cpp/bindings/qpid/python/CMakeLists.txt
@@ -21,17 +21,20 @@
## Use Swig to generate a literal binding to the C++ API
##------------------------------------------------------
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i PROPERTIES CPLUSPLUS ON)
-set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i PROPERTIES SWIG_FLAGS "-I${qpid-cpp_SOURCE_DIR}/include")
+set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/python.i
+ PROPERTIES SWIG_FLAGS "-I${qpid-cpp_SOURCE_DIR}/include;-I${qpid-cpp_SOURCE_DIR}/bindings")
swig_add_module(cqpid_python python ${CMAKE_CURRENT_SOURCE_DIR}/python.i)
swig_link_libraries(cqpid_python qpidmessaging qpidtypes qmf2 ${PYTHON_LIBRARIES})
-set_source_files_properties(${swig_generated_file_fullname} PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -I${PYTHON_INCLUDE_PATH} -I${qpid-cpp_SOURCE_DIR}/include")
+set_source_files_properties(${swig_generated_file_fullname} PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
+include_directories(${PYTHON_INCLUDE_PATH}
+ ${qpid-cpp_SOURCE_DIR}/include
+ ${qpid-cpp_SOURCE_DIR}/bindings)
##------------------------------------
## Install the complete Python binding
##------------------------------------
-execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile cqpid.py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile cqpid.py
@@ -39,12 +42,12 @@ install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile cqpi
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cqpid.py
${CMAKE_CURRENT_BINARY_DIR}/cqpid.pyc
${CMAKE_CURRENT_BINARY_DIR}/cqpid.pyo
- DESTINATION ${PYTHON_SITE_PACKAGES}
+ DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/_cqpid_python.so
RENAME _cqpid.so
- DESTINATION ${PYTHON_SITE_PACKAGES}
+ DESTINATION ${PYTHON_SITEARCH_PACKAGES}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
diff --git a/cpp/bindings/qpid/python/Makefile.am b/cpp/bindings/qpid/python/Makefile.am
index 432fe7e764..d27cc8b3a2 100644
--- a/cpp/bindings/qpid/python/Makefile.am
+++ b/cpp/bindings/qpid/python/Makefile.am
@@ -19,7 +19,7 @@
if HAVE_PYTHON_DEVEL
-INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src/qmf -I$(top_srcdir)/src -I$(top_builddir)/src
+INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/bindings -I$(top_builddir)/include -I$(top_srcdir)/src/qmf -I$(top_srcdir)/src -I$(top_builddir)/src
generated_file_list = \
cqpid.cpp \
@@ -29,7 +29,7 @@ EXTRA_DIST = CMakeLists.txt python.i
BUILT_SOURCES = $(generated_file_list)
SWIG_FLAGS = -w362,401
-$(generated_file_list): $(srcdir)/python.i $(srcdir)/../qpid.i $(srcdir)/../../swig_python_typemaps.i
+$(generated_file_list): $(srcdir)/python.i
$(SWIG) -c++ -python $(SWIG_FLAGS) $(INCLUDES) $(QPID_CXXFLAGS) -I$(top_srcdir)/src/qmf -I/usr/include -o cqpid.cpp $(srcdir)/python.i
pylibdir = $(pyexecdir)
diff --git a/cpp/bindings/qpid/python/python.i b/cpp/bindings/qpid/python/python.i
index 4d8a64b376..148cad5e63 100644
--- a/cpp/bindings/qpid/python/python.i
+++ b/cpp/bindings/qpid/python/python.i
@@ -19,7 +19,7 @@
%module cqpid
%include "std_string.i"
-%include "../../swig_python_typemaps.i"
+%include "qpid/swig_python_typemaps.i"
/* Needed for get/setPriority methods. Surprising SWIG 1.3.40 doesn't
* convert uint8_t by default. */
@@ -159,7 +159,7 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
%rename(_setTtl) qpid::messaging::Message::setTtl;
-%include "../qpid.i"
+%include "qpid/qpid.i"
%extend qpid::messaging::Connection {
%pythoncode %{
diff --git a/cpp/bindings/qpid/qpid.i b/cpp/bindings/qpid/qpid.i
deleted file mode 100644
index 352bafa3c8..0000000000
--- a/cpp/bindings/qpid/qpid.i
+++ /dev/null
@@ -1,70 +0,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.
- */
-
-%{
-
-#include <qpid/messaging/exceptions.h>
-#include <qpid/messaging/Address.h>
-#include <qpid/messaging/Connection.h>
-#include <qpid/messaging/Session.h>
-#include <qpid/messaging/Receiver.h>
-#include <qpid/messaging/Sender.h>
-#include <qpid/messaging/Message.h>
-#include <qpid/messaging/Duration.h>
-#include <qpid/messaging/FailoverUpdates.h>
-
-//
-// Wrapper functions for map-decode and list-decode. This allows us to avoid
-// the complexity of output parameter mapping.
-//
-qpid::types::Variant::Map& decodeMap(const qpid::messaging::Message& msg) {
- static qpid::types::Variant::Map map;
- map.clear();
- qpid::messaging::decode(msg, map);
- return map;
-}
-
-qpid::types::Variant::List& decodeList(const qpid::messaging::Message& msg) {
- static qpid::types::Variant::List list;
- list.clear();
- qpid::messaging::decode(msg, list);
- return list;
-}
-
-%}
-
-%include <qpid/ImportExport.h>
-%include <qpid/messaging/ImportExport.h>
-%include <qpid/messaging/Address.h>
-%include <qpid/messaging/Duration.h>
-%include <qpid/messaging/Message.h>
-%include <qpid/messaging/Receiver.h>
-%include <qpid/messaging/Sender.h>
-%include <qpid/messaging/Session.h>
-%include <qpid/messaging/Connection.h>
-%include <qpid/messaging/FailoverUpdates.h>
-
-qpid::types::Variant::Map& decodeMap(const qpid::messaging::Message&);
-qpid::types::Variant::List& decodeList(const qpid::messaging::Message&);
-
-
-%{
-
-%};
-
diff --git a/cpp/bindings/qpid/ruby/CMakeLists.txt b/cpp/bindings/qpid/ruby/CMakeLists.txt
index 9b32ff5728..564f5655c8 100644
--- a/cpp/bindings/qpid/ruby/CMakeLists.txt
+++ b/cpp/bindings/qpid/ruby/CMakeLists.txt
@@ -31,7 +31,9 @@ set(GEM_OUTPUT_FILE ${GEM_OUTPUT_PATH}/pkg/qpid-${qpidc_version}.0.gem)
##------------------------------------------------------
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/ruby.i PROPERTIES CPLUSPLUS ON)
-include_directories(${RUBY_INCLUDE_DIRS} ${qpid-cpp_SOURCE_DIR}/include)
+include_directories(${RUBY_INCLUDE_DIRS}
+ ${qpid-cpp_SOURCE_DIR}/include
+ ${qpid-cpp_SOURCE_DIR}/bindings)
swig_add_module(cqpid_ruby ruby ${CMAKE_CURRENT_SOURCE_DIR}/ruby.i)
swig_link_libraries(cqpid_ruby qpidmessaging qpidtypes qmf2 ${RUBY_LIBRARY})
@@ -43,7 +45,7 @@ set_source_files_properties(${swig_generated_file_fullname} PROPERTIES COMPILE_F
##----------------------------------
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcqpid_ruby.so
RENAME cqpid.so
- DESTINATION ${RUBY_ARCH_DIR}
+ DESTINATION ${RUBY_PFX_ARCH_DIR}
COMPONENT ${QPID_COMPONENT_CLIENT}
)
diff --git a/cpp/bindings/qpid/ruby/ChangeLog b/cpp/bindings/qpid/ruby/ChangeLog
new file mode 100644
index 0000000000..03813053d2
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/ChangeLog
@@ -0,0 +1,4 @@
+Verison 0.22:
+ * Qpid::Messaging::Address can use an address string on creation.
+ * Qpid::Messaging::Message can use an address string for reply_to.
+ * Removed errors.rb and the KeyError and SessionNameException errors.
diff --git a/cpp/bindings/qpid/ruby/LICENSE b/cpp/bindings/qpid/ruby/LICENSE
index 232fd660d6..261eeb9e9f 100644
--- a/cpp/bindings/qpid/ruby/LICENSE
+++ b/cpp/bindings/qpid/ruby/LICENSE
@@ -1,7 +1,3 @@
-=========================================================================
-== Apache License ==
-=========================================================================
-
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
diff --git a/cpp/bindings/qpid/ruby/Makefile.am b/cpp/bindings/qpid/ruby/Makefile.am
index a2a5dd76bd..398449c7ed 100644
--- a/cpp/bindings/qpid/ruby/Makefile.am
+++ b/cpp/bindings/qpid/ruby/Makefile.am
@@ -19,7 +19,7 @@
if HAVE_RUBY_DEVEL
-INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src
+INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/bindings -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src
EXTRA_DIST = CMakeLists.txt ruby.i
BUILT_SOURCES = cqpid.cpp
@@ -27,7 +27,7 @@ SWIG_FLAGS = -w362,401
rubylibdir = $(RUBY_LIB)
-cqpid.cpp: $(srcdir)/ruby.i $(srcdir)/../qpid.i $(srcdir)/../../swig_ruby_typemaps.i
+cqpid.cpp: $(srcdir)/ruby.i
$(SWIG) -ruby -c++ $(SWIG_FLAGS) $(INCLUDES) $(QPID_CXXFLAGS) -I/usr/include -o cqpid.cpp $(srcdir)/ruby.i
rubylibarchdir = $(RUBY_LIB_ARCH)
diff --git a/cpp/bindings/qpid/ruby/README.rdoc b/cpp/bindings/qpid/ruby/README.rdoc
index 5c60a15588..fce87ac3e1 100644
--- a/cpp/bindings/qpid/ruby/README.rdoc
+++ b/cpp/bindings/qpid/ruby/README.rdoc
@@ -1,45 +1,41 @@
-= Qpid - Open Source AMQP Messaging
+= Qpid - Ruby language bindings for the Qpid messaging framework.
-Qpid is an cross-platform enterprise messaging system.
-
-Version :: 0.19.0
+Qpid is a cross-platform enterprise messaging system based on the open-source
+AMQP protocol.
= Links
Documents :: http://qpid.apache.org/
-= Installation
+= Building The Gemfile
+
+== Prerequisites
-You can install Qpid with the following command.
+You need to have the Qpid client libraries installed along with the related
+development files (headers, etc). To install them, please see:
- $ gem install qpid
+http://cwiki.apache.org/qpid/developer-pages.html
-== Building The Native Code
+== Gemfile Creation
-The Qpid gem requires that you have available the Qpid libraries and
-development header files. To install them, please see:
+Simply type:
-http://cwiki.apache.org/qpid/developer-pages.html
+ $ gem build qpid_messaging.gemspec
-If you are building the gem within the Qpid development environment
-itself, you can specify the location of the Qpid headers and
-libraries with:
+This will produce a gemfile name qpid_messaging-${VERSION}.gem.
-$ ruby extconfig.rb --with-qpid-lib=[path to libqpidclient.so, etc.]
-$ make
+== Installation
-== Examples
+You can install Qpid with the following command:
-Take a look at the integration tests for examples on how to leverage
-the messaging capabilities of Qpid in your Ruby applications.
+ $ gem install qpid_messaging-${VERSION}.gem
== License
Licensed to the Apache Software Foundation (ASF) under one or more
contributor licensing agreements.
-Author:: Darryl L. Pierce (mailto:dpierce@redhat.com)
-Copyright:: Copyright (c) 2011, Red Hat, Inc.
+Author:: Apache Qpid Project
Homepage:: http://qpid.apache.org
License:: Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html
diff --git a/cpp/bindings/qpid/ruby/Rakefile b/cpp/bindings/qpid/ruby/Rakefile
deleted file mode 100644
index 99c3e13c83..0000000000
--- a/cpp/bindings/qpid/ruby/Rakefile
+++ /dev/null
@@ -1,137 +0,0 @@
-# Rakefile for Qpid -*- ruby -*-
-#
-# 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.
-#
-
-task :noop
-
-# look for a root directory for out-of-tree builds
-
-OUTPUT_DIR=ENV["OUTPUT_DIR"] || "."
-
-require "rubygems"
-require "rubygems/package_task"
-
-require "rake/clean"
-require "rake/extensiontask"
-require "rake/rdoctask"
-require "rake/testtask"
-
-require "cucumber/rake/task"
-require "spec/rake/spectask"
-
-CLOBBER.include("pkg")
-
-load "./lib/qpid/version.rb"
-
-#-------------
-# Gem Details.
-#-------------
-
-NAME = "qpid"
-# VERSION = Qpid::VERSION
-AUTHOR = "Darryl L. Pierce"
-EMAIL = "dpierce@redhat.com"
-HOMEPAGE = "http://qpid.apache.org"
-SUMMARY = "Qpid is an enterprise messaging framework."
-
-desc "Default: run all tests."
-task :default => :test
-
-desc "Runs all tests."
-task :test => :"test:all"
-
-#---------------
-# Testing tasks.
-#---------------
-
-namespace :test do
-
- desc "Run RSpec tests."
- Spec::Rake::SpecTask.new do |t|
- t.ruby_opts = ['-rtest/unit']
- t.spec_files = FileList["spec/**/*_spec.rb"]
- t.rcov = true
- t.rcov_opts = [
- '--exclude', 'lib\/qpid.rb,spec\/,lib\/ruby',
- ]
- end
-
- desc "Run all tests (default)."
- task :all => [:spec, :features]
-
- Cucumber::Rake::Task.new(:features) do |t|
- t.libs = ["lib", "ext/nonblockio"]
- t.cucumber_opts = "--format progress"
- end
-
-end
-
-#---------------------
-# Documentation tasks.
-#---------------------
-
-Rake::RDocTask.new(:rdoc => "rdoc",
- :clobber_rdoc => "rdoc:clean",
- :rerdoc => "rdoc:force") do |rd|
- rd.main = "README.rdoc"
- rd.options << "--all"
- rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
-end
-
-#-----------------
-# Package the gem.
-#-----------------
-
-spec = Gem::Specification.new do |s|
- s.name = NAME
- s.version = Qpid::VERSION
- s.platform = Gem::Platform::RUBY
- s.extra_rdoc_files = ["README.rdoc"]
- s.summary = SUMMARY
- s.description = s.summary
- s.author = AUTHOR
- s.email = EMAIL
- s.homepage = HOMEPAGE
-
- s.extensions = FileList["ext/**/extconf.rb"]
-
- s.require_path = "lib"
- # DEPRECATED s.autorequire = NAME
- s.files = FileList["LICENSE",
- "README.rdoc",
- "Rakefile",
- "TODO",
- "lib/**/*.rb",
- "test/**/*.rb",
- "examples/**/*.rb",
- "ext/**/*",
- "features/**/*",
- "spec/**/*"]
-end
-
-Gem::PackageTask.new(spec) do |pkg|
- pkg.package_dir = "#{OUTPUT_DIR}/pkg"
-end
-
-#------------------
-# Build native code
-#------------------
-
-Rake::ExtensionTask.new("cqpid", spec)
-
diff --git a/cpp/bindings/qpid/ruby/TODO b/cpp/bindings/qpid/ruby/TODO
index 454aac9200..db2aca0195 100644
--- a/cpp/bindings/qpid/ruby/TODO
+++ b/cpp/bindings/qpid/ruby/TODO
@@ -1,7 +1,12 @@
-TODO Items
------------------------------------------------------------------------------
+Qpid Ruby bindigns TODO List
+==============================================================================
-Version 0.11.0:
- * Deliver the Ruby bindings as a gem.
- * Rework the blocking tasks to not bring the main thread to a halt.
+Beyond this simple laundry list, you can find the list of bugs and
+enhancements to be fixed by going to the Apache Qpid JIRA instance:
+ http://issues.apache.org/jira/browse/QPID
+
+
+Fixes & Improvements
+==============================================================================
+* Fix the threading issues with blocking I/O calls (Receiver get/fetch).
diff --git a/cpp/bindings/qpid/ruby/examples/client.rb b/cpp/bindings/qpid/ruby/examples/client.rb
index 86ec1b7254..f400acfd13 100644
--- a/cpp/bindings/qpid/ruby/examples/client.rb
+++ b/cpp/bindings/qpid/ruby/examples/client.rb
@@ -19,7 +19,7 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-require 'qpid'
+require 'qpid_messaging'
if __FILE__ == $0
broker = ARGV[1] || "amqp:tcp:localhost:5672"
@@ -29,9 +29,7 @@ if __FILE__ == $0
connection.open
session = connection.create_session
sender = session.create_sender "service_queue"
- response_queue = Qpid::Messaging::Address.new("#response-queue", "",
- :create => :always,
- :delete => :always)
+ response_queue = Qpid::Messaging::Address.new("#response-queue;{create:always}")
receiver = session.create_receiver response_queue
["Twas brillig, and the slithy toves",
diff --git a/cpp/bindings/qpid/ruby/examples/drain.rb b/cpp/bindings/qpid/ruby/examples/drain.rb
index 9e8f699e8b..8e506ea5cd 100644
--- a/cpp/bindings/qpid/ruby/examples/drain.rb
+++ b/cpp/bindings/qpid/ruby/examples/drain.rb
@@ -19,7 +19,7 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-require 'qpid'
+require 'qpid_messaging'
require 'optparse'
options = {
diff --git a/cpp/bindings/qpid/ruby/examples/hello_world.rb b/cpp/bindings/qpid/ruby/examples/hello_world.rb
index c014fb8bd5..1f4954dde9 100644
--- a/cpp/bindings/qpid/ruby/examples/hello_world.rb
+++ b/cpp/bindings/qpid/ruby/examples/hello_world.rb
@@ -19,7 +19,7 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-require 'qpid'
+require 'qpid_messaging'
# This is your classic Hello World application, written in
# Ruby, that uses Qpid. It demonstrates how to send and
diff --git a/cpp/bindings/qpid/ruby/examples/map_receiver.rb b/cpp/bindings/qpid/ruby/examples/map_receiver.rb
index e08bd295ba..16704dd48e 100644
--- a/cpp/bindings/qpid/ruby/examples/map_receiver.rb
+++ b/cpp/bindings/qpid/ruby/examples/map_receiver.rb
@@ -19,7 +19,7 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-require 'qpid'
+require 'qpid_messaging'
broker = ARGV[0] || "amqp:tcp:127.0.0.1:5672"
address = ARGV[1] || "message_queue; {create: always}"
diff --git a/cpp/bindings/qpid/ruby/examples/map_sender.rb b/cpp/bindings/qpid/ruby/examples/map_sender.rb
index 3fb7ca58e3..1908774c31 100644
--- a/cpp/bindings/qpid/ruby/examples/map_sender.rb
+++ b/cpp/bindings/qpid/ruby/examples/map_sender.rb
@@ -19,7 +19,7 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-require 'qpid'
+require 'qpid_messaging'
broker = ARGV[0] || "amqp:tcp:127.0.0.1:5672"
address = ARGV[1] || "message_queue; {create: always}"
diff --git a/cpp/bindings/qpid/ruby/examples/server.rb b/cpp/bindings/qpid/ruby/examples/server.rb
index 0cc0e30216..a589bea799 100644
--- a/cpp/bindings/qpid/ruby/examples/server.rb
+++ b/cpp/bindings/qpid/ruby/examples/server.rb
@@ -19,7 +19,7 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-require 'qpid'
+require 'qpid_messaging'
if __FILE__ == $0
broker = ARGV[0] || "amqp:tcp:localhost:5672"
diff --git a/cpp/bindings/qpid/ruby/examples/spout.rb b/cpp/bindings/qpid/ruby/examples/spout.rb
index ecc47fb15a..71c04d8709 100644
--- a/cpp/bindings/qpid/ruby/examples/spout.rb
+++ b/cpp/bindings/qpid/ruby/examples/spout.rb
@@ -19,7 +19,7 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-require 'qpid'
+require 'qpid_messaging'
require 'optparse'
options = {
diff --git a/cpp/bindings/qpid/ruby/ext/cqpid/extconf.rb b/cpp/bindings/qpid/ruby/ext/cqpid/extconf.rb
index 90292d4bec..fc9e65d562 100644
--- a/cpp/bindings/qpid/ruby/ext/cqpid/extconf.rb
+++ b/cpp/bindings/qpid/ruby/ext/cqpid/extconf.rb
@@ -26,9 +26,10 @@
require 'mkmf'
# Setup the build environment.
-$CFLAGS = "-fPIC -fno-inline -x c++"
+$CFLAGS = "-fPIC -fno-inline -x c++ -lstdc++"
REQUIRED_LIBRARIES = [
+ 'stdc++',
'qpidclient',
'qpidcommon',
'qpidmessaging',
diff --git a/cpp/bindings/qpid/ruby/features/creating_a_receiver.feature b/cpp/bindings/qpid/ruby/features/creating_a_receiver.feature
index 1f758153af..def686f881 100644
--- a/cpp/bindings/qpid/ruby/features/creating_a_receiver.feature
+++ b/cpp/bindings/qpid/ruby/features/creating_a_receiver.feature
@@ -25,5 +25,5 @@ Feature: Creating a receiver
Scenario: Using an Address object
Given an open session
- And an Address with the name "create-receiver-test" and subject "foo" and option "create" set to "always" and "delete" set to "always"
+ And an Address with the string "create-receiver-test;{create:always}"
Then creating a receiver with an Address succeeds
diff --git a/cpp/bindings/qpid/ruby/features/creating_a_sender.feature b/cpp/bindings/qpid/ruby/features/creating_a_sender.feature
index 1c09ff837d..c12b10e054 100644
--- a/cpp/bindings/qpid/ruby/features/creating_a_sender.feature
+++ b/cpp/bindings/qpid/ruby/features/creating_a_sender.feature
@@ -21,5 +21,5 @@ Feature: Creating a sender
Scenario: Using an Address object
Given an open session
- And an Address with the name "my-queue" and subject "my-subject" and option "create" set to "always"
+ And an Address with the string "my-queue/my-subject;{create:always}"
Then creating a sender with an Address succeeds
diff --git a/cpp/bindings/qpid/ruby/features/step_definitions/address_steps.rb b/cpp/bindings/qpid/ruby/features/step_definitions/address_steps.rb
index 0531e5ee69..a7eca6f9ce 100644
--- a/cpp/bindings/qpid/ruby/features/step_definitions/address_steps.rb
+++ b/cpp/bindings/qpid/ruby/features/step_definitions/address_steps.rb
@@ -17,15 +17,6 @@
# under the License.
#
-Given /^an Address with the name "([^"]*)" and subject "([^"]*)" and option "([^"]*)" set to "([^"]*)"$/ do |name, subject, key, value|
- options = Hash.new
- options["#{key}"] = "#{value}"
- @address = Qpid::Messaging::Address.new "#{name}", "#{subject}", options
-end
-
-Given /^an Address with the name "([^"]*)" and subject "([^"]*)" and option "([^"]*)" set to "([^"]*)" and "([^"]*)" set to "([^"]*)"$/ do |name, subject, key1, value1, key2, value2|
- options = Hash.new
- options["#{key1}"] = "#{value1}"
- options["#{key2}"] = "#{value2}"
- @address = Qpid::Messaging::Address.new "#{name}", "#{subject}", options
+Given /^an Address with the string "(.*?)"$/ do |address|
+ @address = Qpid::Messaging::Address.new "#{address}"
end
diff --git a/cpp/bindings/qpid/ruby/features/support/env.rb b/cpp/bindings/qpid/ruby/features/support/env.rb
index 1d15f56fc9..cc0097ca8b 100644
--- a/cpp/bindings/qpid/ruby/features/support/env.rb
+++ b/cpp/bindings/qpid/ruby/features/support/env.rb
@@ -19,4 +19,4 @@
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../../lib")
-require 'qpid'
+require 'qpid_messaging'
diff --git a/cpp/bindings/qpid/ruby/lib/qpid.rb b/cpp/bindings/qpid/ruby/lib/qpid.rb
deleted file mode 100644
index 1f00c136c1..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid.rb
+++ /dev/null
@@ -1,29 +0,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.
-#
-
-require 'qpid/errors'
-require 'qpid/duration'
-require 'qpid/address'
-require 'qpid/encoding'
-require 'qpid/message'
-require 'qpid/sender'
-require 'qpid/receiver'
-require 'qpid/session'
-require 'qpid/connection'
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/address.rb b/cpp/bindings/qpid/ruby/lib/qpid/address.rb
deleted file mode 100644
index 266d8668d6..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/address.rb
+++ /dev/null
@@ -1,187 +0,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.
-#
-
-require 'cqpid'
-
-module Qpid
-
- module Messaging
-
- # Address represents an address to which messages can be sent or from
- # which they can be received.
- #
- # An Address can be described using the following pattern:
- #
- # <address> [ / <subject> ] ; [ { <key> : <value> , ... } ]
- #
- # where *address* is a simple name and *subject* is a subject or subject
- # pattern.
- #
- # The options, enclosed in curly braces, are key:value pairs delimited by
- # a comma. The values can be nested maps also enclosed in curly braces.
- # Or they can be lists of values, where they are contained within square
- # brackets but still comma delimited, such as:
- #
- # [value1,value2,value3]
- #
- # The following are the list of supported options:
- #
- # [:create]
- # Indicates if the address should be created; values are *always*,
- # *never*, *sender* or *reciever*.
- #
- # [:assert]
- # Indicates whether or not to assert any specified node properties;
- # values are *always*, *never*, *sender* or *receiver*.
- #
- # [:delete]
- # Indicates whether or not to delete the addressed node when a sender
- # or receiver is cancelled; values are *always*, *never*, *sender* or
- # *receiver*.
- #
- # [:node]
- # A nested map describing properties for the addressed node. Properties
- # are *type* (*topic* or *queue*), *durable* (a boolean), *x-declare*
- # (a nested map of amqp 0.10-specific options) and *x-bindings*. (nested
- # list which specifies a queue, exchange or a binding key and arguments.
- #
- # [:link]
- # A nested map through which properties of the link can be specified;
- # properties are *durable*, *reliability*, *x-declare*, *x-subscribe*
- # and *x-bindings*.
- #
- # [:mode]
- # (*For receivers only*) indicates whether the receiver should consume
- # or browse messages; values are *consume* (the default) and *browse*.
- #
- class Address
-
- # Creates a new +Address+ object.
- #
- # ==== Options
- #
- # * name - The name for the +Address+.
- # * subject - The subject for the +Address+
- # * :create - See the class documentation.
- # * :assert - See the class documentation.
- # * :delete - See the class documentation.
- # * :node - See the class documentation.
- # * :link - See the class documentation.
- # * :mode - See the class documentation.
- #
- # ==== Examples
- #
- # addr = Qpid::Messaging::Address.new "my-queue"
- # addr = Qpid::Messaging::Address.new "my-queue", "testing", :create => :always
- #
- def initialize(name, subject, options = {}, _type = "", address_impl = nil)
- @address_impl = address_impl || Cqpid::Address.new(name, subject, convert_options(options), _type)
- end
-
- def address_impl # :nodoc:
- @address_impl
- end
-
- # Returns the name for the +Address+.
- #
- # ==== Examples
- #
- # puts "The address name is #{addr.name}."
- #
- def name; @address_impl.getName; end
-
- # Sets the name for the +Address+.
- #
- # ==== Examples
- #
- # addr.name = "my-new-queue"
- #
- def name=(name); @address_impl.setName name; end
-
- # Returns the subject for the +Address+.
- #
- # ==== Examples
- #
- # puts "The subject is #{addr.subject}."
- #
- def subject; @address_impl.getSubject; end
-
- # Sets the subject for the +Address+.
- #
- # ==== Examples
- #
- # addr.subject = "testing"
- #
- def subject=(subject); @address_impl.setSubject(subject); end
-
- # Returns the type for the +Address+.
- #
- # ==== Examples
- #
- # puts "The address is a #{address.address_type}."
- #
- #---
- # We cannot use "type" since that clashes with the Ruby object.type
- # identifier.
- def address_type; @address_impl.getType; end
-
- # Sets the type for the +Address+.
- #
- # The type of the address determines how +Sender+ and +Receiver+ objects
- # are constructed for it. If no type is specified then it will be
- # determined by querying the broker.
- #
- # ===== Options
- #
- # * type - the address type
- #
- def address_type=(type); @address_impl.setType(type); end
-
- # Returns the options.
- def options; @address_impl.getOptions; end
-
- # Sets the options for the address.
- #
- # *NOTE:* See the class documentation for more details on options.
- #
- # ==== Examples
- #
- # addr.options = :create => :always
- #
- def options=(options = {}); @address_impl.setOptions(convert_options(options)); end
-
- def to_s # :nodoc:
- @address_impl.str
- end
-
- private
-
- def convert_options(options)
- result = {}
- options.each_pair {|key, value| result[key.to_s] = value.to_s}
-
- return result
- end
-
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/connection.rb b/cpp/bindings/qpid/ruby/lib/qpid/connection.rb
deleted file mode 100644
index 12669bc947..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/connection.rb
+++ /dev/null
@@ -1,162 +0,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.
-#
-
-require 'cqpid'
-
-module Qpid
-
- module Messaging
-
- # Establishes a connection to a remote endpoint.
- class Connection
-
- attr_reader :options # :nodoc:
-
- # Creates a connection object, but does not actually connect to
- # the specified location.
- #
- # ==== Options
- #
- # :url - the URL for the broker (def. +"localhost"+)
- # :options - connection options (def. +{}+)
- #
- # ==== Controlling Reconnect Behavior
- #
- # The following connection options can be used to configure
- # the reconnection behavior for this connection.
- #
- # * :username
- # * :password
- # * :heartbeat
- # * :tcp_nodelay
- # * :sasl_mechanism
- # * :sasl_service
- # * :sasl_min_ssf
- # * :sasl_max_ssf
- # * :transport
- # * :reconnect - +true+ or +false+; indicates wehtehr to attempt reconnections
- # * :reconnect_timeout - the number of seconds to attempt reconnecting
- # * :reconnect_limit - the number of retries before reporting failure
- # * :reconnect_interval_min - initial delay, in seconds, before attempting a reconnection
- # * :reconnect_interval_max - number of seconds to wait before additional reconnect attempts
- # * :reconnect_interval - shorthand for setting both min and max values
- # * :reconnect_urls - a list of alternate URLs to use for reconnection attempts
- #
- # ==== Examples
- #
- # conn = Qpid::Messaging::Connnection.new
- # conn = Qpid::Messaging::Connection.new :url => "amqp:tcp:broker1.domain.com:5672"
- # conn = Qpid::Messaging::Connection.new :options => {:username => "login", :password => "password"}
- #
- def initialize(opts = {})
- @url = opts[:url] || "localhost"
- @options = convert_options(opts[:options] || {})
- @connection_impl = opts[:impl] || Cqpid::Connection.new(@url, @options)
- end
-
- def connection_impl # :nodoc:
- @connection_impl
- end
-
- # Establishes the connection.
- #
- # ==== Examples
- #
- # conn.open unless conn.open?
- #
- def open
- @connection_impl.open
- end
-
- # Reports whether the connection is open.
- #
- # ==== Examples
- #
- # conn.close if conn.open?
- #
- def open?; true && !@connection_impl.nil? && @connection_impl.isOpen; end
-
- # Closes the connection.
- def close; @connection_impl.close; end
-
- # Creates a new session.
- #
- # ==== Arguments
- #
- # * :name - specifies the name for this session
- # * :transactional - if +true+ then a creates a transaction session (def. +false+)
- #
- # ==== Examples
- #
- # session = conn.create_session :name => "session1"
- # session = conn.create_session :transaction => true
- #
- def create_session(args = {})
- name = args[:name] || ""
- if open?
- if args[:transactional]
- session = @connection_impl.createTransactionalSession name
- else
- session = @connection_impl.createSession name
- end
- return Session.new(self, session)
- else
- raise RuntimeError.new "No connection available."
- end
- end
-
- # Returns a session for the specified session name.
- #
- # ==== Examples
- #
- # begin
- # session = conn.session "mysession"
- # rescue SessionNameException => error
- # puts "No such session."
- # end
- #
- def session name
- begin
- session_impl = @connection_impl.getSession name
- Qpid::Messaging::Session.new self, session_impl if session_impl
- rescue
- raise Qpid::Messaging::SessionNameException.new "No such session: #{name}"
- end
- end
-
- # Returns the username used to authenticate with the connection.
- def authenticated_username; @connection_impl.getAuthenticatedUsername if open?; end
-
- private
-
- def convert_options(options)
- result = {}
- unless options.nil? || options.empty?
- options.each_pair {|key, value| result[key.to_s] = value.to_s}
- end
-
- return result
- end
-
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/duration.rb b/cpp/bindings/qpid/ruby/lib/qpid/duration.rb
deleted file mode 100644
index e1ddd79cb6..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/duration.rb
+++ /dev/null
@@ -1,95 +0,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.
-#
-
-require 'cqpid'
-
-module Qpid
-
- module Messaging
-
- # A Duration represents a period of time in milliseconds
- #
- # It defines the following named values as symbols:
- #
- # [:FOREVER]
- # The maximum integer value for the platform. Effectively this will wait
- # forever.
- #
- # [:IMMEDIATE]
- # An alias for 0 milliseconds.
- #
- # [:SECOND]
- # An alias for 1,000 milliseconds.
- #
- # [:MINUTE]
- # And alias for 60,000 millisecons.
- #
- class Duration
-
- # Creates a Duration with the specified length, in milliseconds.
- #
- # ==== Options
- #
- # * length - The duration in milliseconds.
- #
- # ==== Examples
- #
- # # Wait up to 10 seconds for an incoming message
- # receiver.get Qpid::Messaging::Duration.new 10000
- #
- def initialize length
- @duration_impl = Cqpid::Duration.new length
- end
-
- def duration_impl # :nodoc:
- @duration_impl
- end
-
- # Returns the period of time in milliseconds
- #
- # ==== Examples
- #
- # duration = Qpid::Messaging::Duration.new :length => 5000
- # puts "Waiting #{duration.milliseconds} ms for a message."
- # msg = receiver.fetch duration
- #
- def milliseconds
- @duration_impl.getMilliseconds
- end
-
- def self.add_item(key, value) # :nodoc:
- @hash ||= {}
- @hash[key] = Duration.new value
- end
-
- def self.const_missing(key) # :nodoc:
- @hash[key]
- end
-
- self.add_item :FOREVER, Cqpid::Duration.FOREVER.getMilliseconds
- self.add_item :IMMEDIATE, Cqpid::Duration.IMMEDIATE.getMilliseconds
- self.add_item :SECOND, Cqpid::Duration.SECOND.getMilliseconds
- self.add_item :MINUTE, Cqpid::Duration.MINUTE.getMilliseconds
-
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/encoding.rb b/cpp/bindings/qpid/ruby/lib/qpid/encoding.rb
deleted file mode 100644
index 2f20fab18e..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/encoding.rb
+++ /dev/null
@@ -1,60 +0,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.
-#
-
-require 'cqpid'
-
-module Qpid
-
- module Messaging
-
- # Encodes the supplied content into the given message.
- def self.encode content, message, encoding = nil
- prepared = content
- case content
- when Hash
- prepared = {}
- content.each_pair do |key,value|
- prepared[key.to_s] = value.to_s
- end
- Cqpid::encode prepared, message.message_impl
- when Array
- prepared = []
- content.each {|value| prepared << value.to_s}
- Cqpid::encode prepared, message.message_impl
- end
- end
-
- # Decodes and returns the message's content.
- def self.decode(message, content_type = nil)
- content_type = message.content_type unless content_type
-
- case content_type
- when "amqp/map"
- Cqpid.decodeMap message.message_impl
- when "amqp/list"
- Cqpid.decodeList message.message_impl
- end
-
- message.content
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/errors.rb b/cpp/bindings/qpid/ruby/lib/qpid/errors.rb
deleted file mode 100644
index c98eb1ac12..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/errors.rb
+++ /dev/null
@@ -1,33 +0,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.
-#
-
-module Qpid
-
- module Messaging
-
- class KeyError < RuntimeError; end
-
- class SessionNameException < Exception
- def initialize(msg); super(msg); end
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/message.rb b/cpp/bindings/qpid/ruby/lib/qpid/message.rb
deleted file mode 100644
index edef0ac2a0..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/message.rb
+++ /dev/null
@@ -1,368 +0,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.
-#
-
-require 'cqpid'
-
-module Qpid
-
- module Messaging
-
- # A +Message+ represents an routable piece of information.
- #
- # The content for a message is automatically encoded and decoded.
- #
- class Message
-
- # Creates a new instance of +Message+.
- #
- # ==== Options
- #
- # * :content - The content.
- #
- # ==== Examples
- #
- # message = Qpid::Messaging::Message.new :content => "This is a message."
- #
- def initialize(args = {})
- @message_impl = (args[:impl] if args[:impl]) || nil
- @message_impl = Cqpid::Message.new if @message_impl.nil?
- @content = nil
- args = {} if args.nil?
- self.content = args[:content] if args[:content]
- end
-
- def message_impl # :nodoc:
- @message_impl
- end
-
- # Sets the address to which replies should be sent for the +Message+.
- #
- # *NOTE:* The address must be an instance of Address.
- #
- # ==== Options
- #
- # * address - an instance of +Address+
- #
- # ==== Examples
- #
- # msg.reply_to = Qpid:Messaging::Address.new "my-responses"
- #
- def reply_to=(address)
- raise ArgumentError, "Agument must be an Address" unless address.is_a? Qpid::Messaging::Address
- @message_impl.setReplyTo address.address_impl
- end
-
- # Returns the reply to address for the +Message+.
- #
- def reply_to
- address_impl = @message_impl.getReplyTo
- # only return an address if a reply to was specified
- Qpid::Messaging::Address.new(nil, nil, nil, nil, address_impl) if address_impl
- end
-
- # Sets the subject for the +Message+.
- #
- # ==== Options
- #
- # * subject - the subject
- #
- # ==== Examples
- #
- # msg.subject = "mysubject"
- #
- def subject=(subject); @message_impl.setSubject subject; end
-
- # Returns the subject of the +Message+.
- #
- # ==== Options
- #
- # puts "The subject is #{msg.subject}"
- #
- def subject; @message_impl.getSubject; end
-
- # Sets the content type for the +Message+.
- #
- # This should be set by the sending applicaton and indicates to
- # recipients of the message how to interpret or decode the content.
- #
- # By default, only dictionaries and maps are automatically given a content
- # type. If this content type is replaced then retrieving the content will
- # not behave correctly.
- #
- # ==== Options
- #
- # * content_type - the content type.
- #
- def content_type=(content_type); @message_impl.setContentType content_type; end
-
- # Returns the content type for the +Message+.
- #
- # ==== Examples
- #
- # case msg.content_type
- # when "myapp/image"
- # ctl.handle_image msg
- # end
- # when "myapp/audio"
- # ctl.handle_audio msg
- # end
- # end
- #
- def content_type; @message_impl.getContentType; end
-
- # Sets the message id.
- #
- # *NOTE:* this field must be a UUID type currently. A non-UUID value will
- # be converted to a zero UUID, though a blank ID will be left untouched.
- #
- # ==== Options
- #
- # * id - the id
- #
- # ==== Examples
- #
- #
- def message_id=(message_id); @message_impl.setMessageId message_id.to_s; end
-
- # Returns the message id.
- #
- # See +message_id=+ for details.
- def message_id; @message_impl.getMessageId; end
-
- # Sets the user id for the +Message+.
- #
- # This should in general be the user-id which was used when authenticating
- # the connection itself, as the messaging infrastructure will verify
- # this.
- #
- # See +Qpid::Messaging::Connection.authenticated_username+
- #
- # *NOTE:* If the id is not a +String+ then the id is set using
- # the object's string representation.
- #
- # ==== Options
- #
- # * id - the id
- #
- def user_id=(user_id); @message_impl.setUserId user_id; end
-
- # Returns the user id for the +Message+.
- #
- # See +user_id=+ for details.
- #
- def user_id; @message_impl.getUserId; end
-
- # Sets the correlation id of the +Message+.
- #
- # The correlation id can be used as part of a protocol for message
- # exchange patterns; e.g., a requestion-response pattern might require
- # the correlation id of the request and the response to match, or it
- # might use the message id of the request as the correlation id on
- # the response
- #
- # *NOTE:* If the id is not a +String+ then the id is setup using
- # the object's string representation.
- #
- # ==== Options
- #
- # * id - the id
- #
- def correlation_id=(correlation_id); @message_impl.setCorrelationId correlation_id; end
-
- # Returns the correlation id of the +Message+.
- #
- # *NOTE:* See +correlation_id=+ for details.
- #
- def correlation_id; @message_impl.getCorrelationId; end
-
- # Sets the priority of the +Message+.
- #
- # This may be used by the messaging infrastructure to prioritize
- # delivery of messages with higher priority.
- #
- # *NOTE:* If the priority is not an integer type then it is set using
- # the object's integer representation. If the integer value is greater
- # than 8-bits then only the first 8-bits are used.
- #
- # ==== Options
- #
- # * priority - the priority
- #
- def priority=(priority); @message_impl.setPriority priority; end
-
- # Returns the priority for the +Message+.
- #
- def priority; @message_impl.getPriority; end
-
- # Sets the time-to-live in milliseconds.
- #
- # ==== Options
- #
- # * duration - the number of milliseconds
- #
- def ttl=(duration)
- if duration.is_a? Qpid::Messaging::Duration
- @message_impl.setTtl duration.duration_impl
- else
- @message_impl.setTtl Cqpid::Duration.new duration.to_i
- end
- end
-
- # Returns the time-to-live in milliseconds.
- def ttl; Qpid::Messaging::Duration.new @message_impl.getTtl.getMilliseconds; end
-
- # Sets the durability of the +Message+.
- #
- # This is a hint to the messaging infrastructure that the message
- # should be persisted or otherwise stored. This helps to ensure
- # that th emessage is not lost during to failures or a shutdown.
- #
- # ==== Options
- #
- # * durable - the durability flag (def. false)
- #
- def durable=(durable); @message_impl.setDurable durable; end
-
- # Returns the durability for the +Message+.
- #
- def durable; @message_impl.getDurable; end
-
- # This is a hint to the messaging infrastructure that if de-duplication
- # is required, that this message should be examined to determine if it
- # is a duplicate.
- #
- # ==== Options
- #
- # * redelivered - sets the redelivered state (def. false)
- #
- # ==== Examples
- #
- # # processed is an array of processed message ids
- # msg.redelivered = true if processed.include? msg.message_id
- #
- def redelivered=(redelivered); @message_impl.setRedelivered redelivered; end
-
- # Returns whether the +Message+ has been marked as redelivered.
- #
- def redelivered; @message_impl.getRedelivered; end
-
- # Returns all named properties.
- #
- # *NOTE:* It is recommended to use the []= method for
- # retrieving and setting properties. Using this method may
- # result in non-deterministic behavior.
- #
- def properties; @message_impl.getProperties; end
-
- # Returns the value for the named property.
- #
- # ==== Options
- #
- # * name - the property name
- #
- # ==== Examples
- #
- # # use of message properties to mark a message as digitally signed
- # verify(msg) if msg[:signed]
- #
- def [](key); self.properties[key.to_s]; end
-
- # Assigns a value to the named property.
- #
- # *NOTE:* Both the key or the value may be a symbol, but they will
- # both be converted to a +String+ for ease of transport.
- #
- # ==== Options
- #
- # * name - the property name
- # * value - the property value
- def []=(key, value); @message_impl.setProperty(key.to_s, value.to_s); end
-
- # Sets the content for the +Message+.
- #
- # Content is automatically encoded for Array and Hash types. Other types
- # need to set their own content types (via +content_type+) in order to
- # specify how recipients should process the content.
- #
- # ==== Options
- #
- # * content - the content
- #
- # ==== Examples
- #
- # msg.content = "This is a simple message." # a simple message
- # msg.content = {:foo => :bar} # content is automatically encoded
- #
- def content=(content)
- content_type = nil
- @content = content
- case @content
- when Hash
- content_type = "amqp/map"
- new_content = {}
- content.each_pair{|key, value| new_content[key.to_s] = value.to_s}
- @content = new_content
- when Array
- new_content = []
- content_type = "amqp/list"
- content.each {|element| new_content << element.to_s}
- @content = new_content
- end
- if content_type.nil?
- @message_impl.setContent @content
- else
- Qpid::Messaging.encode @content, self, content_type
- end
- end
-
- # Returns the content of the +Message+.
- #
- # Content is automatically decoded based on the specified content type.
- # If the content type is application-specific, then no decoding is
- # performed and the content is returnedas a +String+ representation.
- #
- # For example, if an array of integers are sent, then the receiver will
- # find the message content to be an array of String objects, where each
- # String is a representation of the sent integer value.
- #
- def content
- if @content.nil?
- @content = @message_impl.getContent
-
- # decode the content is necessary if it
- # has an encoded content type
- if ["amqp/list", "amqp/map"].include? @message_impl.getContentType
- @content = Qpid::Messaging.decode(self,
- @message_impl.getContentType)
- end
-
- end
- @content
- end
-
- # Returns the content's size.
- #
- def content_size; @message_impl.getContentSize; end
-
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb b/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb
deleted file mode 100644
index 0ce16309ed..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb
+++ /dev/null
@@ -1,186 +0,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.
-#
-
-require 'cqpid'
-
-require 'qpid/duration'
-
-module Qpid
-
- module Messaging
-
- # Receiver is the entity through which messages are received.
- #
- # An instance of Receiver can only be created using an active (not
- # previously closed) Session.
- #
- # ==== Example
- #
- # conn = Qpid::Messaging::Connection.new :url => "mybroker:5762"
- # conn.open
- # session = conn.create_session
- # receiver = session.create_receiver "my-sender-queue"
- class Receiver
-
- def initialize(session, receiver_impl) # :nodoc:
- @session = session
- @receiver_impl = receiver_impl
- end
-
- def receiver_impl # :nodoc:
- @receiver_impl
- end
-
- # Retrieves a message from the local queue, or waits for up to
- # the duration specified for one to become available.
- #
- # If a block is given, then it will be invaked after the next message
- # is received or the call times out, passing in the message or nil
- # respectively.
- #
- # ==== Options
- # * duration - the timeout to wait (def. Duration::FOREVER)
- #
- # ==== Examples
- #
- # msg = rcvr.get # Uses the default timeout of forever
- #
- # msg = rcvr.get Qpid::Messaging::Duration::IMMEDIATE # returns a message or exits immediately
- #
- # # passes in a block to handle the received message
- # rcvr.get Qpid::Messaging::Duration::SECOND do |message|
- # if message.nil?
- # puts "No message was received."
- # else
- # puts "Received this message: #{message.content}"
- # end
- # end
- def get(duration = Qpid::Messaging::Duration::FOREVER)
- message_impl = @receiver_impl.get duration.duration_impl
- create_message_wrapper message_impl unless message_impl.nil?
- end
-
- # Retrieves a message from the receiver's subscription, or waits
- # for up to the duration specified for one to become available.
- #
- # If a block is given, then it will be invaked after the next message
- # is received or the call times out, passing in the message or nil
- # respectively.
- #
- # ==== Options
- # * duration - the timeout to wait (def. Duration::FOREVER)
- #
- # ==== Examples
- #
- # msg = rcvr.fetch # Uses the default timeout of forever
- #
- # msg = rcvr.fetch Qpid::Messaging::Duration::IMMEDIATE # returns a message or exits immediately
- #
- # # passes in a block to handle the received message
- # rcvr.fetch Qpid::Messaging::Duration::SECOND do |message|
- # if message.nil?
- # puts "No message was received."
- # else
- # puts "Received this message: #{message.content}"
- # end
- # end
- def fetch(duration = Qpid::Messaging::Duration::FOREVER)
- message_impl = @receiver_impl.fetch duration.duration_impl
- create_message_wrapper message_impl unless message_impl.nil?
- end
-
- # Sets the capacity for this +Receiver+.
- #
- # ==== Options
- #
- # * capacity - the capacity
- #
- # ==== Examples
- #
- # receiver.capacity = 50 # sets the incoming capacity to 50 messages
- #
- def capacity=(capacity); @receiver_impl.setCapacity capacity; end
-
- # Returns the capacity.
- #
- #
- # The capacity is the numnber of incoming messages that can be held
- # locally before being fetched.
- #
- # ==== Examples
- #
- # puts "The receiver can hold #{rcv.capacity} messages."
- #
- def capacity; @receiver_impl.getCapacity; end
-
- # Returns the number of slots for receiving messages.
- #
- # This differs from +capacity+ in that it is the available slots in
- # the capacity for holding incoming messages, where available <= capacity.
- #
- # ==== Examples
- #
- # puts "You can receive #{rcv.available} messages before blocking."
- #
- def available; @receiver_impl.getAvailable; end
-
- # Returns the number of messages that have been received and acknowledged
- # but whose acknowledgements have not been confirmed by the sender.
- #
- # ==== Examples
- #
- # puts "You have #{rcv.unsettled} messages to be confirmed."
- #
- def unsettled; @receiver_impl.getUnsettled; end
-
- # Closes this +Receiver+.
- #
- # This does not affect the +Session+.
- def close; @receiver_impl.close; end
-
- # Returns whether the receiver is closed.
- #
- # ==== Examples
- #
- # recv.close unless recv.closed?
- #
- def closed?; @receiver_impl.isClosed; end
-
- # Returns the name of this +Receiver+.
- #
- # ==== Examples
- #
- # puts "Receiver: #{recv.name}"
- def name; @receiver_impl.getName; end
-
- # Returns the Session for this +Receiver+.
- def session; @session; end
-
- private
-
- def create_message_wrapper message_impl # :nodoc:
- Qpid::Messaging::Message.new(:impl => message_impl)
- end
-
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/sender.rb b/cpp/bindings/qpid/ruby/lib/qpid/sender.rb
deleted file mode 100644
index 97227622f5..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/sender.rb
+++ /dev/null
@@ -1,152 +0,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.
-#
-
-module Qpid
-
- module Messaging
-
- # Sender is the entity through which messages sent.
- #
- # An instance of Sender can only be created using an active (not previously
- # closed) Session.
- #
- # ==== Examples
- #
- # conn = Qpid::Messaging::Connection.new :url => "mybroker:5762"
- # conn.open
- # session = conn.create_session
- # sender = session.create_session "my-sender-queue;{create:always}"
- class Sender
-
- def initialize(session, sender_impl) # :nodoc:
- @session = session
- @sender_impl = sender_impl
- end
-
- def sender_impl # :nodoc:
- @sender_impl
- end
-
- # Sends a message.
- #
- # If a block is given, then it will be invoked after the message
- # is sent.
- #
- # ==== Options
- #
- # * message - The message to send.
- # * :sync - See note below on synching.
- #
- # ==== Synching
- #
- # If :sync => true, then the call will block until the broker confirms
- # receipt of the message. Otherwise it will only block for available
- # capacity; i.e., until pending is equal to capacity.
- #
- # ==== Examples
- #
- # sender.send message do |message|
- # puts "Message sent: #{message.content}"
- # end
- #
- def send(message, args = {}, &block)
- sync = args[:sync] || false
- @sender_impl.send message.message_impl, sync
- block.call message unless block.nil?
- end
-
- # Closes this +Sender+.
- #
- # This does not affect the +Session+.
- def close; @sender_impl.close; end
-
- # Returns the human-readable name for this +Sender+.
- #
- # ==== Examples
- #
- # puts "Sender: #{sender.name}"
- #
- def name; @sender_impl.getName; end
-
- # Sets the capacity for this +Sender+.
- #
- # The capacity is the number of outgoing messages that can be held
- # pending confirmation or receipt by the broker.
- #
- # ==== Options
- #
- # * capacity - the capacity
- #
- # ==== Examples
- #
- # sender.capacity = 50 # sets the outgoing capacity to 50 messages
- #
- def capacity=(capacity); @sender_impl.setCapacity capacity; end
-
- # Returns the capacity.
- #
- # The capacity is the total number of outgoing messages that can be
- # sent before a called to +send+ begins to block by default.
- #
- # ==== Examples
- #
- # puts "You can send a maximum of #{sender.capacity} messages."
- #
- def capacity; @sender_impl.getCapacity; end
-
- # Returns the number of messages sent that are pending receipt
- # confirmation by the broker.
- #
- # ==== Examples
- #
- # if sender.unsettled > 0
- # puts "There are #{sender.unsettled} messages pending."
- # end
- #
- def unsettled; @sender_impl.getUnsettled; end
-
- # Returns the available slots for sending messages.
- #
- # This differs from +capacity+ in that it is the available slots in
- # the senders capacity for holding outgoing messages. The difference
- # between capacity and available is the number of messages that
- # have not been delivered yet.
- #
- # ==== Examples
- #
- # puts "You can send #{sender.available} messages before blocking."
- #
- def available
- @sender_impl.getAvailable
- end
-
- # Returns the +Session+ for this sender.
- #
- # ==== Examples
- #
- # recv.session.close if done
- #
- def session; @session; end
-
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/session.rb b/cpp/bindings/qpid/ruby/lib/qpid/session.rb
deleted file mode 100644
index feb8aa5bb4..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/session.rb
+++ /dev/null
@@ -1,271 +0,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.
-#
-
-require 'cqpid'
-
-require 'qpid/errors'
-
-module Qpid
-
- module Messaging
-
- # A Session represents a distinct conversation between end points.
- class Session
-
- def initialize(connection, session) # :nodoc:
- @connection = connection
- @session_impl = session
- @senders = Hash.new
- @receivers = Hash.new
- end
-
- def session_impl # :nodoc:
- @session_impl
- end
-
- # Returns the +Connection+ associated with this session.
- def connection
- @connection
- end
-
- # Creates a new endpoint for sending messages.
- #
- # The +address+ can either be an instance +Address+ or else a
- # string that describes an address endpoint.
- #
- # ==== Arguments
- #
- # * +address+ The end point address.
- #
- # ==== Examples
- #
- # sender = session.create_sender "my-queue;{create:always}"
- #
- def create_sender(address)
- _address = address
-
- if address.class == Qpid::Messaging::Address
- _address = address.address_impl
- end
-
- sender_impl = @session_impl.createSender(_address)
- sender_name = sender_impl.getName
-
- @senders[sender_name] = Qpid::Messaging::Sender.new(self, sender_impl)
-
- @senders[sender_name]
- end
-
- # Retrieves the +Sender+ with the specified name.
- #
- # The +Sender+ must have been previously created using
- # the +create_sender+ method.
- #
- # ==== Arguments
- #
- # * +name+ The +Sender+ name.
- #
- # ==== Examples
- #
- # sender = session.sender "my-queue"
- #
- def sender(name)
- raise Qpid::Messaging::KeyError, "No such sender: #{name}" unless @senders.has_key? name
-
- @senders[name]
- end
-
- # Creates a new endpoint for receiving messages.
- #
- # The +address+ can either be an instance +Address+ or else a
- # string that describes an address endpoint.
- #
- # ==== Arguments
- #
- # * +address+ The end point address.
- #
- # ==== Examples
- #
- # receiver = session.create_receiver "my-queue"
- #
- def create_receiver(address)
- result = nil
- receiver_impl = nil
-
- if address.class == Qpid::Messaging::Address
- address_impl = address.address_impl
- receiver_impl = @session_impl.createReceiver address_impl
- else
- receiver_impl = @session_impl.createReceiver(address)
- end
-
- receiver_name = receiver_impl.getName
-
- @receivers[receiver_name] = Qpid::Messaging::Receiver.new self, receiver_impl
-
- @receivers[receiver_name]
- end
-
- # Retrieves the +Receiver+ with the specified name.
- #
- # The +Receiver+ must have been previously created using
- # the +create_receiver+ method.
- #
- # ==== Arguments
- #
- # * +name+ The +Receiver+ name.
- #
- # ==== Examples
- #
- # receiver = session.receiver "my-queue"
- #
- def receiver(name)
- raise Qpid::Messaging::KeyError, "No such receiver: #{name}" unless @receivers.has_key? name
-
- @receivers[name]
- end
-
- # Closes the +Session+ and all associated +Sender+ and +Receiver+ instances.
- #
- # NOTE: All +Session+ instances for a +Connection+ are closed when the
- # +Connection+ is closed.
- def close; @session_impl.close; end
-
- # Commits any pending transactions for a transactional session.
- def commit; @session_impl.commit; end
-
- # Rolls back any uncommitted transactions on a transactional session.
- def rollback; @session_impl.rollback; end
-
- # Acknowledges one or more outstanding messages that have been received
- # on this session.
- #
- # ==== Arguments
- #
- # * :message - if specified, then only the +Message+ specified is acknowledged
- # * :sync - if true then the call will block until processed by the server (def. false)
- #
- # ==== Examples
- #
- # session.acknowledge # acknowledges all received messages
- # session.acknowledge :message => message # acknowledge one message
- # session.acknowledge :sync => true # blocks until the call completes
- #
- #--
- # TODO: Add an optional block to be used for blocking calls.
- #++
- def acknowledge(args = {})
- sync = args[:sync] || false
- message = args[:message] if args[:message]
-
- unless message.nil?
- @session_impl.acknowledge message.message_impl, sync
- else
- @session_impl.acknowledge sync
- end
- end
-
- # Rejects the specified message. A rejected message will not be
- # redelivered.
- #
- # NOTE: A message cannot be rejected once it has been acknowledged.
- def reject(message); @session_impl.reject message.message_impl; end
-
- # Releases the message, which allows the broker to attempt to
- # redeliver it.
- #
- # NOTE: A message connot be released once it has been acknowled.
- def release(message); @session_impl.release message.message_impl; end
-
- # Requests synchronization with the server.
- #
- # ==== Arguments
- #
- # * :block - if true then the call blocks until the server acknowledges it (def. false)
- #
- #--
- # TODO: Add an optional block to be used for blocking calls.
- #++
- def sync(args = {})
- block = args[:block] || false
- @session_impl.sync block
- end
-
- # Returns the total number of receivable messages, and messages already
- # received, by +Receiver+ instances associated with this +Session+.
- def receivable; @session_impl.getReceivable; end
-
- # Returns the number of messages that have been acknowledged by this session
- # whose acknowledgements have not been confirmed as processed by the server.
- def unsettled_acks; @session_impl.getUnsettledAcks; end
-
- # Fetches the +Receiver+ for the next message.
- #
- # ==== Arguments
- #
- # * timeout - time to wait for a +Receiver+ before timing out
- #
- # ==== Examples
- #
- # recv = session.next_receiver # wait forever for the next +Receiver+
- # # execute a block on the next receiver
- # session.next_receiver do |recv|
- # msg = recv.get
- # puts "Received message: #{msg.content}"
- # end
- def next_receiver(timeout = Qpid::Messaging::Duration::FOREVER, &block)
- receiver_impl = @session_impl.nextReceiver(timeout.duration_impl)
-
- unless receiver_impl.nil?
- recv = Qpid::Messaging::Receiver.new self, receiver_impl
- block.call recv unless block.nil?
- end
-
- return recv
- end
-
- # Returns true if there were exceptions on this session.
- #
- # ==== Examples
- #
- # puts "There were session errors." if @session.errors?
- def errors?; @session_impl.hasError; end
-
- # If the +Session+ has been rendered invalid due to some exception,
- # this method will result in that exception being raised.
- #
- # If none have occurred, then no exceptions are raised.
- #
- # ==== Examples
- #
- # if @session.errors?
- # begin
- # @session.errors
- # rescue Exception => error
- # puts "An error occurred: #{error}"
- # end
- # end
- def errors; @session_impl.checkError; end
-
- end
-
- end
-
-end
-
diff --git a/cpp/bindings/qpid/ruby/lib/qpid/version.rb b/cpp/bindings/qpid/ruby/lib/qpid/version.rb
deleted file mode 100644
index 39524e428f..0000000000
--- a/cpp/bindings/qpid/ruby/lib/qpid/version.rb
+++ /dev/null
@@ -1,31 +0,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.
-#
-
-module Qpid
-
- module Version
-
- NUMBERS = [MAJOR = 0,
- MINOR = 17,
- BUILD = 0]
- end
-
- VERSION = Version::NUMBERS.join('.')
-
-end
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging.rb
new file mode 100644
index 0000000000..2b5348f298
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging.rb
@@ -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.
+#++
+
+require 'cqpid'
+require 'qpid_messaging/duration'
+require 'qpid_messaging/address'
+require 'qpid_messaging/encoding'
+require 'qpid_messaging/message'
+require 'qpid_messaging/sender'
+require 'qpid_messaging/receiver'
+require 'qpid_messaging/session'
+require 'qpid_messaging/connection'
+
+module Qpid
+
+ # The Qpid Messaging framework is an enterprise messaging framework
+ # based on the open-source AMQP protocol.
+ #
+ # ==== Example Application
+ #
+ # Here is a simple example application. It creates a link to a broker located
+ # on a system named *broker.myqpiddomain.com*. It then creates a new messaging
+ # queue named "qpid-examples" and publishes a message to it. It then consumes
+ # that same message and closes the connection.
+ #
+ # require 'rubygems'
+ # gem 'qpid_messaging'
+ # require 'qpid_messaging'
+ #
+ # # create a connection, open it and then create a session named "session1"
+ # conn = Qpid::Messaging::Connection.new :name => "broker.myqpiddomain.com"
+ # conn.open
+ # session = conn.create_session "session1"
+ #
+ # # create a sender and a receiver
+ # # the sender marks the queue as one that is deleted when trhe sender disconnects
+ # send = session.create_sender "qpid-examples;{create:always,delete:always}"
+ # recv = session.create_receiver "qpid-examples"
+ #
+ # # create an outgoing message and send it
+ # outgoing = Qpid::Messaging::Message.new :content => "The time is #{Time.new}"
+ # sender.send outgoing
+ #
+ # # set the receiver's capacity to 10 and then check out many messages are pending
+ # recv.capacity = 10
+ # puts "There are #{recv.available} messages waiting." # should report 1 message
+ #
+ # # get the nextwaiting message, which should be in the local queue now,
+ # # and output the contents
+ # incoming = recv.get Qpid::Messaging::Duration::IMMEDIATE
+ # puts "Received the following message: #{incoming.content}"
+ # # the output should be the text that was sent earlier
+ #
+ # # acknowledge the message, letting the sender know the message was received
+ # puts "The sender currently has #{send.unsettled} message(s) pending."
+ # # should report 1 unsettled message
+ # session.acknowledge incoming # acknowledge the received message
+ # puts "Now sender currently has #{send.unsettled} message(s) pending."
+ # # should report 0 unsettled messages
+ #
+ # # close the connection
+ # conn.close
+ #
+ module Messaging; end
+
+end
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/address.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/address.rb
new file mode 100644
index 0000000000..0879f0fcd1
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/address.rb
@@ -0,0 +1,200 @@
+#--
+# 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.
+#++
+
+module Qpid
+
+ module Messaging
+
+ # Address represents an address to which messages can be sent or from
+ # which they can be received.
+ #
+ # == The +Address+ String
+ #
+ # An +Address+ can be described using the following pattern:
+ #
+ # <address> [ / <subject> ] ; [ { <key> : <value> , ... } ]
+ #
+ # where *address* is a simple name and *subject* is a subject or subject
+ # pattern.
+ #
+ # === Options
+ #
+ # The options, enclosed in curly braces, are key:value pairs delimited by
+ # a comma. The values can be nested maps also enclosed in curly braces.
+ # Or they can be lists of values, where they are contained within square
+ # brackets but still comma delimited, such as:
+ #
+ # [value1,value2,value3]
+ #
+ # The following are the list of supported options:
+ #
+ # [create]
+ # Indicates if the address should be created; values are *always*,
+ # *never*, *sender* or *reciever*.
+ #
+ # [assert]
+ # Indicates whether or not to assert any specified node properties;
+ # values are *always*, *never*, *sender* or *receiver*.
+ #
+ # [delete]
+ # Indicates whether or not to delete the addressed node when a sender
+ # or receiver is cancelled; values are *always*, *never*, *sender* or
+ # *receiver*.
+ #
+ # [node]
+ # A nested map describing properties for the addressed node. Properties
+ # are *type* (*topic* or *queue*), *durable* (a boolean), *x-declare*
+ # (a nested map of amqp 0.10-specific options) and *x-bindings* (nested
+ # list which specifies a queue, exchange or a binding key and arguments).
+ #
+ # [link]
+ # A nested map through which properties of the link can be specified;
+ # properties are *durable*, *reliability*, *x-declare*, *x-subscribe*
+ # and *x-bindings*.
+ #
+ # [mode]
+ # (*For receivers only*) indicates whether the receiver should consume
+ # or browse messages; values are *consume* (the default) and *browse*.
+ class Address
+
+ # Creates a new +Address+ from an address string.
+ #
+ # ==== Attributes
+ #
+ # * +address+ - the address string
+ #
+ # ==== Examples
+ #
+ # # create a new address for a queue named "my-queue" that will
+ # # be created if it doesn't already exist
+ # addr = Qpid::Messaging::Address.new "my-queue;{create:always}"
+ #
+ def initialize(address, address_impl = nil)
+ @address_impl = address_impl || Cqpid::Address.new(address)
+ end
+
+ def address_impl # :nodoc:
+ @address_impl
+ end
+
+ # Returns the name for the +Address+.
+ #
+ # ==== Examples
+ #
+ # # display the name of the address
+ # addr = Qpid::Messaging::Address.new "foo;{create:always}"
+ # # outputs the word 'foo'
+ # puts addr.name
+ #
+ def name; @address_impl.getName; end
+
+ # Sets the name for the +Address+.
+ #
+ # ==== Examples
+ #
+ # # create a new address with the name "my-queue"
+ # addr = Qpid::Messaging::Address.new "my-queue/my-subject;{create:always}"
+ # # changes the name to "my-new-queue"
+ # addr.name = "my-new-queue"
+ #
+ def name=(name); @address_impl.setName name; end
+
+ # Returns the subject for the +Address+.
+ #
+ # ==== Examples
+ #
+ # # creates a new address with the subject "bar"
+ # addr = Qpid::Messaging::Address.new "my-queue/bar;{create:always}"
+ #
+ def subject; @address_impl.getSubject; end
+
+ # Sets the subject for the +Address+.
+ #
+ # ==== Examples
+ #
+ # # creates an address with the subject "example"
+ # addr = Qpid::Messaging::Address.new "my-queue/example;{create:always}"
+ # # changes the subject to "test"
+ # addr.subject = "test"
+ #
+ def subject=(subject); @address_impl.setSubject(subject); end
+
+ # Returns the type for the +Address+.
+ #--
+ # We cannot use "type" since that clashes with the Ruby object.type
+ # identifier.
+ #++
+ def address_type; @address_impl.getType; end
+
+ # Sets the type for the +Address+.
+ #
+ # The type of the address determines how +Sender+ and +Receiver+ objects
+ # are constructed for it. It also affects how a reply-to address is
+ # encoded.
+ #
+ # If no type is specified then it will be determined by querying the
+ # broker. Explicitly setting the type prevents this.
+ #
+ # Values are either *queue* or *topic*.
+ #
+ # ==== Options
+ #
+ # * +type+ - the address type
+ #
+ # ==== Examples
+ #
+ # # creates an queue address
+ # addr = Qpid::Messaging::Address.new "my-queue;{create:always}"
+ # addr.address_type = "queue"
+ #
+ def address_type=(type); @address_impl.setType(type); end
+
+ # Returns the options.
+ def options; @address_impl.getOptions; end
+
+ # Sets the options for the address.
+ #
+ # *NOTE:* See the class documentation for more details on options.
+ #
+ # ==== Examples
+ #
+ # addr.options = :create => :always
+ # addr.options = :create => :always, :delete => :always
+ #
+ def options=(options = {}); @address_impl.setOptions(convert_options(options)); end
+
+ def to_s # :nodoc:
+ @address_impl.str
+ end
+
+ private
+
+ def convert_options(options)
+ result = {}
+ options.each_pair {|key, value| result[key.to_s] = value.to_s}
+
+ return result
+ end
+
+ end
+
+ end
+
+end
+
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/connection.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/connection.rb
new file mode 100644
index 0000000000..6d637a1665
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/connection.rb
@@ -0,0 +1,189 @@
+#--
+# 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.
+#++
+
+module Qpid
+
+ module Messaging
+
+ # A +Connection+ represents a network connection to a remote endpoint.
+ class Connection
+
+ attr_reader :options # :nodoc:
+
+ # Creates a connection object. Raises a MessagingError if an invalid
+ # connection option is used.
+ #
+ # == Options
+ #
+ # * +:url+ - the URL for the broker
+ # * +:options+ - connection options
+ #
+ # == Controlling Reconnect Behavior
+ #
+ # The following connection options can be used to configure
+ # the reconnection behavior for this connection.
+ #
+ # * +:username+ - the authentication username
+ # * +:password+ - the authentication password
+ # * +:heartbeat+
+ # * +:tcp_nodelay+
+ # * +:sasl_mechanism+
+ # * +:sasl_service+
+ # * +:sasl_min_ssf+
+ # * +:sasl_max_ssf+
+ # * +:transport+
+ # * +:reconnect+ - indicates whether to attempt reconnections
+ # * +:reconnect_timeout+ - the number of seconds to attempt reconnecting
+ # * +:reconnect_limit+ - the number of retries before reporting failure
+ # * +:reconnect_interval_min+ - initial delay, in seconds, before attempting a reconnection
+ # * +:reconnect_interval_max+ - number of seconds to wait before additional reconnect attempts
+ # * +:reconnect_interval+ - shorthand for setting both min and max values
+ # * +:reconnect_urls+ - a list of alternate URLs to use for reconnection attempts
+ #
+ # == Examples
+ #
+ # # creates a connection to the broker running local *localhost*
+ # conn = Qpid::Messaging::Connnection.new
+ # # creates a connection to *broker1.domain.com* on port *5672*
+ # conn = Qpid::Messaging::Connection.new :url => "amqp:tcp:broker1.domain.com:5672"
+ # # creates a connection to localhost with the specified authentication credentials
+ # conn = Qpid::Messaging::Connection.new :options => {:username => "login", :password => "password"}
+ #
+ def initialize(opts = {})
+ @url = opts[:url] || "localhost"
+ @options = Qpid::Messaging.stringify(opts[:options] || {})
+ @connection_impl = opts[:impl] || Cqpid::Connection.new(@url, @options)
+ end
+
+ def connection_impl # :nodoc:
+ @connection_impl
+ end
+
+ # Establishes the connection.
+ #
+ # == Examples
+ #
+ # # open a connection if it's not already open
+ # conn.open unless conn.open?
+ #
+ def open
+ @connection_impl.open
+ end
+
+ # Reports whether the connection is open.
+ #
+ # == Examples
+ #
+ # # close the connection if it's not already closed
+ # conn.close if conn.open?
+ #
+ def open?; true && !@connection_impl.nil? && @connection_impl.isOpen; end
+
+ # Closes the connection.
+ #
+ # == Examples
+ #
+ # # close a connection
+ # conn.close
+ #
+ def close; @connection_impl.close; end
+
+ # Creates a new session.
+ #
+ # == Arguments
+ #
+ # * +:name+ - specifies the name for this session
+ # * +:transactional+ - if +true+ then a creates a transaction session (def. +false+)
+ #
+ # == Examples
+ #
+ # # create a session named 'session1'
+ # session = conn.create_session :name => "session1"
+ # # create a transactional session
+ # session = conn.create_session :transaction => true
+ #
+ def create_session(args = {})
+ name = args[:name] || ""
+ if open?
+ if args[:transactional]
+ session = @connection_impl.createTransactionalSession name
+ else
+ session = @connection_impl.createSession name
+ end
+ return Session.new(self, session)
+ else
+ raise RuntimeError.new "No connection available."
+ end
+ end
+
+ # Returns a Session with the given name. Raises an exception if no
+ # session with the given name exists.
+ #
+ # == Options
+ #
+ # * +name+ - the existing session's name
+ #
+ # == Examples
+ #
+ # # retrieve a session named 'mysession' from the current connection
+ # name = "my-session"
+ # # if no such session exists then catchh the exception raised
+ # begin
+ # session = conn.session name
+ # rescue MessagingException => error
+ # puts "No such session: #{name}."
+ # end
+ #
+ def session name
+ session_impl = @connection_impl.getSession name
+ Qpid::Messaging::Session.new self, session_impl if session_impl
+ end
+
+ # Returns the username used to authenticate with the connection.
+ #
+ # If the connection did not user authentication credentials, then the
+ # username returned is "anonymous".
+ #
+ # == Examples
+ #
+ # # create a new connection for user "qpiduser"
+ # conn = Qpid::Messaging::Connection.new :username => "qpiduser"
+ # conn.open
+ # # displays the authenticate username
+ # puts "Connected as #{conn.authenticated_username}" # should say 'qpiduser'
+ #
+ def authenticated_username; @connection_impl.getAuthenticatedUsername if open?; end
+
+ private
+
+ def convert_options(options)
+ result = {}
+ unless options.nil? || options.empty?
+ options.each_pair {|key, value| result[key.to_s] = value.to_s}
+ end
+
+ return result
+ end
+
+ end
+
+ end
+
+end
+
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/duration.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/duration.rb
new file mode 100644
index 0000000000..11c903dade
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/duration.rb
@@ -0,0 +1,128 @@
+#--
+# 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.
+#++
+
+module Qpid
+
+ module Messaging
+
+ # A Duration represents a period of time in milliseconds
+ #
+ # == Named Durations
+ #
+ # The following named +Durations+ are available as symbols:
+ #
+ # [FOREVER]
+ # The maximum integer value for the platform. Effectively this will wait
+ # forever.
+ #
+ # [IMMEDIATE]
+ # An alias for 0 milliseconds.
+ #
+ # [SECOND]
+ # An alias for 1,000 milliseconds.
+ #
+ # [MINUTE]
+ # And alias for 60,000 millisecons.
+ #
+ class Duration
+
+ # Creates a Duration with the specified length, in milliseconds.
+ #
+ # ==== Options
+ #
+ # * +length+ - The duration in +milliseconds+.
+ #
+ # ==== Examples
+ #
+ # # creates a duration of 15 seconds
+ # # REMEMBER: Duration deals in milliseconds
+ # delay = Qpid::Messaging::Duration.new 15000
+ #
+ def initialize length
+ @duration_impl = Cqpid::Duration.new length
+ end
+
+ def duration_impl # :nodoc:
+ @duration_impl
+ end
+
+ # Returns the period of time in +milliseconds+.
+ #
+ # ==== Examples
+ #
+ # # doubling growth in waiting for messages in a loop
+ # do loop
+ # set the base duration waiting length
+ # timeout = Qpid::Messaging::Duration::SECOND
+ # msg = nil
+ # # loop until we receive a message
+ # while msg.nil?
+ # puts "Waiting #{timeout.milliseconds}ms"
+ # msg = recv.get timeout
+ # # if nothing was received, double the duration
+ # if msg.nil?
+ # # double out timeout
+ # timeout = timeout * 2
+ # else
+ # # do something with the message
+ # puts "Received: #{msg.content}"
+ # end
+ # end
+ # end
+ #
+ def milliseconds
+ @duration_impl.getMilliseconds
+ end
+
+ # Multiplies the duration of the +Duration+ and returns a new instance.
+ #
+ # Raises exceptions on a negative factor. Returns
+ # Qpid::Messaging::Duration::IMMEDIATE when the factor is 0.
+ #
+ # ==== Examples
+ #
+ # # return a duration that is 2 minutes (120,000 ms)
+ # twominutes = Qpid::Messaging::Duration::MINUTE * 2
+ #
+ def *(factor)
+ raise TypeError.new "Factors must be non-zero positive values" if factor < 0
+ return Qpid::Messaging::Duration::IMMEDIATE if factor.zero?
+ Qpid::Messaging::Duration.new((self.milliseconds * factor).floor)
+ end
+
+ def self.add_item(key, value) # :nodoc:
+ @hash ||= {}
+ @hash[key] = Duration.new value
+ end
+
+ def self.const_missing(key) # :nodoc:
+ @hash[key]
+ end
+
+ self.add_item :FOREVER, Cqpid::Duration.FOREVER.getMilliseconds
+ self.add_item :IMMEDIATE, Cqpid::Duration.IMMEDIATE.getMilliseconds
+ self.add_item :SECOND, Cqpid::Duration.SECOND.getMilliseconds
+ self.add_item :MINUTE, Cqpid::Duration.MINUTE.getMilliseconds
+
+ end
+
+ end
+
+end
+
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb
new file mode 100644
index 0000000000..ac0fbc32a7
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb
@@ -0,0 +1,75 @@
+#--
+# 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.
+#++
+
+module Qpid
+
+ module Messaging
+
+ # Encodes the supplied content into the given message.
+ def self.encode content, message, encoding = nil # :nodoc:
+ Cqpid::encode content, message.message_impl, encoding
+ end
+
+ # Decodes and returns the message's content.
+ def self.decode(message, content_type = nil) # :nodoc:
+ content_type = message.content_type if content_type.nil?
+
+ case content_type
+ when "amqp/map"
+ return Cqpid.decodeMap message.message_impl
+ when "amqp/list"
+ return Cqpid.decodeList message.message_impl
+ end
+
+ message.content
+ end
+
+ # Takes as input any type and converts anything that's a symbol
+ # into a string.
+ def self.stringify(value) # :nodoc:
+ # set the default value
+ result = value
+
+ case value
+
+ when Symbol
+ result = value.to_s
+
+ when Hash
+ result = {}
+ value.each_pair do |key, value|
+ result[stringify(key)] = stringify(value)
+ end
+
+ when Array
+ result = []
+ value.each do |element|
+ result << stringify(element)
+ end
+
+ end
+
+ return result
+
+ end
+
+ end
+
+end
+
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb
new file mode 100644
index 0000000000..e167800455
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb
@@ -0,0 +1,353 @@
+#--
+# 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.
+#++
+
+module Qpid
+
+ module Messaging
+
+ # A +Message+ represents an routable piece of information.
+ class Message
+
+ # Creates a +Message+.
+ #
+ # ==== Options
+ #
+ # * +:content+ - the content
+ #
+ # ==== Examples
+ #
+ # # create a simple message and sends it
+ # message = Qpid::Messaging::Message.new :content => "This is a message."
+ # sender.send message
+ #
+ def initialize(args = {})
+ @message_impl = (args[:impl] if args[:impl]) || nil
+ @message_impl = Cqpid::Message.new if @message_impl.nil?
+ @content = nil
+ args = {} if args.nil?
+ self.content = args[:content] if args[:content]
+ end
+
+ def message_impl # :nodoc:
+ @message_impl
+ end
+
+ # Sets the reply-to address.
+ #
+ # The address can either be an instance of Address or else and
+ # address string.
+ #
+ # ==== Options
+ #
+ # * +address+ - the address
+ #
+ # ==== Examples
+ #
+ # # set replies using an Address
+ # msg.reply_to = Qpid:Messaging::Address.new "my-responses"
+ # # set replies using an address string
+ # msg.reply_to = "my-feed/responses"
+ #
+ def reply_to=(address)
+ address = Qpid::Messaging::Address.new "#{address}" if !address.is_a? Qpid::Messaging::Address
+
+ @message_impl.setReplyTo address.address_impl
+ end
+
+ # Returns the reply to address for the +Message+.
+ def reply_to
+ address_impl = @message_impl.getReplyTo
+ # only return an address if a reply to was specified
+ Qpid::Messaging::Address.new(nil, address_impl) if address_impl
+ end
+
+ # Sets the subject for the +Message+.
+ #
+ # ==== Options
+ #
+ # * +subject+ - the subject
+ def subject=(subject); @message_impl.setSubject subject; end
+
+ # Returns the subject of the +Message+.
+ def subject; @message_impl.getSubject; end
+
+ # Sets the content type for the +Message+.
+ #
+ # This should be set by the sending application and indicates to the
+ # recipients of the message how to interpret or decode the content.
+ #
+ # By default, only dictionaries and maps are automatically given a content
+ # type. If this content type is replaced then retrieving the content will
+ # not behave correctly.
+ #
+ # ==== Options
+ #
+ # * +content_type+ - the content type
+ #
+ # ==== Examples
+ #
+ # # send base64 encoded data in a mesage
+ # msg = Qpid::Messaging::Message.new :content = "UXBpZCBSdWxlcyEK"
+ # msg.content_type = "application/base64"
+ #
+ def content_type=(content_type); @message_impl.setContentType content_type; end
+
+ # Returns the content type for the +Message+.
+ def content_type; @message_impl.getContentType; end
+
+ # Sets the message id.
+ #
+ # *NOTE:* this field must be a UUID type currently. A non-UUID value will
+ # be converted to a zero UUID, though a blank ID will be left untouched.
+ #
+ # ==== Options
+ #
+ # * +id+ - the id
+ #
+ # ==== Examples
+ #
+ # # this example only works in Ruby >= 1.9, for 1.8 use a UUID library
+ # require 'SecureRandom'
+ # msg.message_id = SecureRandom.uuid
+ #
+ def message_id=(message_id); @message_impl.setMessageId message_id.to_s; end
+
+ # Returns the message id.
+ def message_id; @message_impl.getMessageId; end
+
+ # Sets the user id for the +Message+.
+ #
+ # This should in general be the user-id which was used when authenticating
+ # the connection itself, as the messaging infrastructure will verify
+ # this.
+ #
+ # See Qpid::Messaging::Connection.authenticated_username
+ #
+ # *NOTE:* If the id is not a +String+ then the id is set using
+ # the object's string representation.
+ #
+ # ==== Options
+ #
+ # * +id+ - the id
+ #
+ def user_id=(user_id); @message_impl.setUserId user_id; end
+
+ # Returns the user id for the +Message+.
+ def user_id; @message_impl.getUserId; end
+
+ # Sets the correlation id of the +Message+.
+ #
+ # The correlation id can be used as part of a protocol for message
+ # exchange patterns; e.g., a request-response pattern might require
+ # the correlation id of the request and the response to match, or it
+ # might use the message id of the request as the correlation id on
+ # the response.
+ #
+ # *NOTE:* If the id is not a +String+ then the id is setup using
+ # the object's string representation.
+ #
+ # ==== Options
+ #
+ # * +id+ - the id
+ #
+ def correlation_id=(correlation_id); @message_impl.setCorrelationId correlation_id; end
+
+ # Returns the correlation id of the +Message+.
+ def correlation_id; @message_impl.getCorrelationId; end
+
+ # Sets the priority of the +Message+.
+ #
+ # This may be used by the messaging infrastructure to prioritize
+ # delivery of messages with higher priority.
+ #
+ # *NOTE:* If the priority is not an integer type then it is set using
+ # the object's integer representation. If the integer value is greater
+ # than 8-bits then only the first 8-bits are used.
+ #
+ # ==== Options
+ #
+ # * +priority+ - the priority
+ #
+ def priority=(priority); @message_impl.setPriority priority; end
+
+ # Returns the priority for the +Message+.
+ def priority; @message_impl.getPriority; end
+
+ # Sets the time-to-live in milliseconds.
+ #
+ # This can be used by the messaging infrastructure to discard messages
+ # that are no longer of relevance.
+ #
+ # ==== Options
+ #
+ # * +duration+ - the number of milliseconds
+ #
+ def ttl=(duration)
+ if duration.is_a? Qpid::Messaging::Duration
+ @message_impl.setTtl duration.duration_impl
+ else
+ @message_impl.setTtl Cqpid::Duration.new duration.to_i
+ end
+ end
+
+ # Returns the time-to-live in milliseconds.
+ def ttl; Qpid::Messaging::Duration.new @message_impl.getTtl.getMilliseconds; end
+
+ # Sets the durability of the +Message+.
+ #
+ # This is a hint to the messaging infrastructure that the message
+ # should be persisted or otherwise stored. This helps to ensure
+ # that the message is not lost due to failures or a shutdown.
+ #
+ # ==== Options
+ #
+ # * +durable+ - the durability flag (def. false)
+ #
+ def durable=(durable); @message_impl.setDurable durable; end
+
+ # Returns the durability for the +Message+.
+ def durable; @message_impl.getDurable; end
+
+ # This is a hint to the messaging infrastructure that if de-duplication
+ # is required, that this message should be examined to determine if it
+ # is a duplicate.
+ #
+ # ==== Options
+ #
+ # * +redelivered+ - sets the redelivered state (def. false)
+ #
+ # ==== Examples
+ #
+ # # processed is a collection of messages already received
+ # msg.redelivered = true if processed.include? msg.message_id
+ #
+ def redelivered=(redelivered); @message_impl.setRedelivered redelivered; end
+
+ # Returns whether the +Message+ has been marked as redelivered.
+ def redelivered; @message_impl.getRedelivered; end
+
+ # Returns all named properties.
+ #
+ # *NOTE:* It is recommended to use the []= method for
+ # retrieving and setting properties. Using this method may
+ # result in non-deterministic behavior.
+ def properties; @message_impl.getProperties; end
+
+ # Returns the value for the named property.
+ #
+ # ==== Options
+ #
+ # * +name+ - the property name
+ #
+ # ==== Examples
+ #
+ # # use of message properties to mark a message as digitally signed
+ # verify(msg) if msg[:signed]
+ #
+ def [](key); self.properties[key.to_s]; end
+
+ # Assigns a value to the named property.
+ #
+ # A property's name or value, if a symbol, will be converted to a string
+ # representation. However, you will still be able to access them using
+ # a symbol for the name.
+ #
+ # ==== Options
+ #
+ # * +name+ - the property name
+ # * +value+ - the property value
+ #
+ # ==== Examples
+ #
+ # # set the signed attribute on a message and then retrieve it
+ # msg[:signed] = true # sets "signed" => true
+ # puts "It's signed" if msg["signed"] # outputs "It's signed"
+ #
+ def []=(key, value)
+ @message_impl.setProperty(key.to_s,
+ Qpid::Messaging.stringify(value))
+ end
+
+ # Sets the content for the +Message+.
+ #
+ # Content is automatically encoded for Array and Hash types. Other types
+ # need to set their own content types (via content_type) in order to
+ # specify how recipients should process the content.
+ #
+ # ==== Options
+ #
+ # * +content+ - the content
+ #
+ # ==== Examples
+ #
+ # # set a simple content for a message
+ # msg.content = "This is a simple message."
+ # # sets content that is automatically encoded
+ # msg.content = {:foo => :bar}
+ #
+ def content=(content)
+ content_type = nil
+ @content = Qpid::Messaging.stringify(content)
+ case @content
+ when Hash
+ content_type = "amqp/map"
+ when Array
+ content_type = "amqp/list"
+ end
+ if content_type.nil?
+ @message_impl.setContent @content
+ else
+ Qpid::Messaging.encode @content, self, content_type
+ end
+ end
+
+ # Returns the content of the +Message+.
+ #
+ # Content is automatically decoded based on the specified content type.
+ # If the content type is application-specific, then no decoding is
+ # performed and the content is returnedas a +String+ representation.
+ #
+ # For example, if an array of integers are sent, then the receiver will
+ # find the message content to be an array of String objects, where each
+ # String is a representation of the sent integer value.
+ #
+ def content
+ if @content.nil?
+ @content = @message_impl.getContent
+
+ # decode the content is necessary if it
+ # has an encoded content type
+ if ["amqp/list", "amqp/map"].include? @message_impl.getContentType
+ @content = Qpid::Messaging.decode(self,
+ @message_impl.getContentType)
+ end
+
+ end
+ @content
+ end
+
+ # Returns the content's size in bytes.
+ def content_size; @message_impl.getContentSize; end
+
+ end
+
+ end
+
+end
+
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/receiver.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/receiver.rb
new file mode 100644
index 0000000000..05ee925212
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/receiver.rb
@@ -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.
+#++
+
+module Qpid
+
+ module Messaging
+
+ # +Receiver+ is the entity through which messages are received.
+ #
+ # An instance of +Receiver+ can only be created using an active (i.e., not
+ # previously closed) Session. See Qpid::Messaging::Session.create_receiver
+ # for more details.
+ #
+ # ==== Example
+ #
+ # # create a connection and a session
+ # conn = Qpid::Messaging::Connection.new :url => "mybroker:5762"
+ # conn.open
+ # session = conn.create_session
+ #
+ # # create a receiver that listens on the "updates" topic of "alerts"
+ # receiver = session.create_receiver "alerts/updates"
+ #
+ # # wait for an incoming message and process it
+ # incoming = receiver.get Qpid::Messaging::Duration::FOREVER
+ # process(incoming)
+ #
+ class Receiver
+
+ def initialize(session, receiver_impl) # :nodoc:
+ @session = session
+ @receiver_impl = receiver_impl
+ end
+
+ def receiver_impl # :nodoc:
+ @receiver_impl
+ end
+
+ # Retrieves a message from the local queue, or waits for up to
+ # the duration specified for one to become available.
+ #
+ # If no message is received within the specified time then a
+ # MessagingException is raised.
+ #
+ # ==== Options
+ #
+ # * duration - the timeout to wait
+ #
+ # ==== Examples
+ #
+ # # retrieves a message, also handles exceptions raised on no messages
+ # begin
+ # # checks for a message, returning immediately
+ # msg = recv.get Qpid::Messaging::Duration::IMMEDIATE
+ # puts "Received this message: #{message.content}"
+ # rescue
+ # puts "No messages available.
+ # end
+ #
+ def get(duration = Qpid::Messaging::Duration::FOREVER)
+ message_impl = @receiver_impl.get duration.duration_impl
+ create_message_wrapper message_impl unless message_impl.nil?
+ end
+
+ # Retrieves a message from the receiver's subscription, or waits
+ # for up to the duration specified for one to become available.
+ #
+ # If no message is fetched within the specified time then a
+ # MessagingException is raised.
+ #
+ # ==== Options
+ #
+ # * duration - the timeout to wait (def. Duration::FOREVER)
+ #
+ # ==== Examples
+ #
+ # # retrieves a message, also handles exceptions raised on no messages
+ # begin
+ # # checks for a message, times out after one second
+ # msg = recv.fetch Qpid::Messaging::Duration::SECOND
+ # puts "Fetched this message: #{message.content}"
+ # rescue
+ # puts "No messages available.
+ # end
+ #
+ def fetch(duration = Qpid::Messaging::Duration::FOREVER)
+ message_impl = @receiver_impl.fetch duration.duration_impl
+ create_message_wrapper message_impl unless message_impl.nil?
+ end
+
+ # Sets the capacity.
+ #
+ # The capacity of a +Receiver+ is the number of Messages that can be
+ # pre-fetched from the broker and held locally. If capacity is 0 then
+ # messages will never be pre-fetched and all messages must instead be
+ # retrieved using #fetch.
+ #
+ # ==== Options
+ #
+ # * capacity - the capacity
+ #
+ # ==== Examples
+ #
+ # # create a receiver and give it a capacity of 50
+ # recv = session.create_receiver "alerts/minor"
+ # recv.capacity = 50
+ #
+ def capacity=(capacity); @receiver_impl.setCapacity capacity; end
+
+ # Returns the capacity.
+ def capacity; @receiver_impl.getCapacity; end
+
+ # Returns the number of messages locally held.
+ #
+ # The available is always 0 <= available <= capacity.
+ #
+ # If the #capacity is set to 0 then available will always be 0.
+ #
+ # ==== Examples
+ #
+ # # output the number of messages waiting while processing
+ # loop do
+ # puts "There are #{recv.available} messages pending..."
+ # # wait forever (the default) for the next message
+ # msg = recv.get
+ # # process the message
+ # dispatch_message msg
+ # end
+ #
+ def available; @receiver_impl.getAvailable; end
+
+ # Returns the number of messages that have been received and acknowledged
+ # but whose acknowledgements have not been confirmed by the sender.
+ def unsettled; @receiver_impl.getUnsettled; end
+
+ # Closes this +Receiver+.
+ #
+ # This does not affect the owning Session or Connection.
+ def close; @receiver_impl.close; end
+
+ # Returns whether the +Receiver+ is closed.
+ def closed?; @receiver_impl.isClosed; end
+
+ # Returns the name of this +Receiver+.
+ def name; @receiver_impl.getName; end
+
+ # Returns the owning Session for this +Receiver+.
+ def session; @session; end
+
+ private
+
+ def create_message_wrapper message_impl # :nodoc:
+ Qpid::Messaging::Message.new(:impl => message_impl)
+ end
+
+ end
+
+ end
+
+end
+
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/sender.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/sender.rb
new file mode 100644
index 0000000000..4ce1393dc7
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/sender.rb
@@ -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.
+#++
+
+module Qpid
+
+ module Messaging
+
+ # +Sender+ is the entity through which messages are sent.
+ #
+ # An instance of +Sender+ can only be created using an active (not previously
+ # closed) Session. See Qpid::Messaging::Session.create_sender for more details.
+ #
+ # ==== Examples
+ #
+ # # create a connection
+ # conn = Qpid::Messaging::Connection.new "mybroker:5672"
+ # conn.open
+ #
+ # if conn.open?
+ #
+ # # create a session
+ # session = conn.create_session
+ #
+ # # create a sender that posts messages to the "updates" queue
+ # sender = session.create_sender "updates;{create:always}
+ #
+ # # begin sending updates
+ # loop do
+ # # wait for the next event content then send it
+ # content = wait_for_event
+ # sender.send Qpid::Messaging::Message.new :content => content
+ # end
+ # end
+ #
+ class Sender
+
+ def initialize(session, sender_impl) # :nodoc:
+ @session = session
+ @sender_impl = sender_impl
+ end
+
+ def sender_impl # :nodoc:
+ @sender_impl
+ end
+
+ # Sends a message, optionally blocking until the message is received
+ # by the broker.
+ #
+ # ==== Options
+ #
+ # * +message+ - The message to send.
+ # * +:sync+ - Block until received. See note below on synching.
+ #
+ # ==== Synching
+ #
+ # If :sync => true, then the call will block until the broker confirms
+ # receipt of the message. Otherwise it will only block for available
+ # capacity; i.e., until pending is equal to capacity.
+ #
+ # ==== Examples
+ #
+ # # send a message
+ # outgoing = Qpid::Messaging::Message.new :content => content
+ # sender.send outgoing
+ #
+ # # send a message, wait for confirmation from the broker
+ # outgoing = Qpid::Messaging::Message.new :content => content
+ # sender.send outgoing, :sync => true
+ #
+ def send(message, args = {}, &block)
+ sync = args[:sync] || false
+ @sender_impl.send message.message_impl, sync
+ block.call message unless block.nil?
+ end
+
+ # Closes this +Sender+.
+ #
+ # This does not affect the owning Session or Connection.
+ def close; @sender_impl.close; end
+
+ # Returns the human-readable name for this +Sender+.
+ def name; @sender_impl.getName; end
+
+ # Sets the capacity for this +Sender+.
+ #
+ # The capacity is the number of outgoing messages that can be held
+ # pending confirmation of receipt by the broker.
+ #
+ # ==== Options
+ #
+ # * +capacity+ - the capacity
+ def capacity=(capacity); @sender_impl.setCapacity capacity; end
+
+ # Returns the capacity.
+ def capacity; @sender_impl.getCapacity; end
+
+ # Returns the number of messages sent that are pending receipt
+ # confirmation by the broker.
+ def unsettled; @sender_impl.getUnsettled; end
+
+ # Returns the available slots for sending messages.
+ #
+ # This differs from +capacity+ in that it is the available slots in
+ # the senders capacity for holding outgoing messages. The difference
+ # between capacity and available is the number of messages that
+ # have not been delivered yet.
+ def available
+ @sender_impl.getAvailable
+ end
+
+ # Returns the Session for this sender.
+ def session; @session; end
+
+ end
+
+ end
+
+end
+
diff --git a/cpp/bindings/qpid/ruby/lib/qpid_messaging/session.rb b/cpp/bindings/qpid/ruby/lib/qpid_messaging/session.rb
new file mode 100644
index 0000000000..7e6e11f654
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/lib/qpid_messaging/session.rb
@@ -0,0 +1,264 @@
+#--
+# 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.
+#++
+
+module Qpid
+
+ module Messaging
+
+ # A +Session+ represents a distinct conversation between end points. They are
+ # created from an active (i.e., not closed) Connection.
+ #
+ # A +Session+ is used to acknowledge individual or all messages that have
+ # passed through it
+ class Session
+
+ def initialize(connection, session) # :nodoc:
+ @connection = connection
+ @session_impl = session
+ end
+
+ def session_impl # :nodoc:
+ @session_impl
+ end
+
+ # Returns the Connection associated with this session.
+ def connection
+ @connection
+ end
+
+ # Creates a new endpoint for sending messages.
+ #
+ # The address can either be an instance Address or else an
+ # address string.
+ #
+ # ==== Arguments
+ #
+ # * +address+ - the end point address.
+ def create_sender(address)
+ _address = address
+
+ if address.class == Qpid::Messaging::Address
+ _address = address.address_impl
+ end
+
+ sender_impl = @session_impl.createSender(_address)
+ sender_name = sender_impl.getName
+
+ Qpid::Messaging::Sender.new(self, sender_impl)
+ end
+
+ # Retrieves the Sender with the specified name.
+ #
+ # Raises an exception if no such Sender exists.
+ #
+ # ==== Arguments
+ #
+ # * +name+ - the name of the Sender
+ def sender(name)
+ Qpid::Messaging::Sender.new self, @session_impl.getSender(name)
+ end
+
+ # Creates a new endpoint for receiving messages.
+ #
+ # The +address+ can either be an instance Address or else an
+ # address string.
+ #
+ # ==== Arguments
+ #
+ # * +address+ - the end point address.
+ def create_receiver(address)
+ result = nil
+ receiver_impl = nil
+
+ if address.class == Qpid::Messaging::Address
+ address_impl = address.address_impl
+ receiver_impl = @session_impl.createReceiver address_impl
+ else
+ receiver_impl = @session_impl.createReceiver(address)
+ end
+
+ Qpid::Messaging::Receiver.new self, receiver_impl
+ end
+
+ # Retrieves the +Receiver+ with the specified name, or nil if no such
+ # Receiver exists.
+ #
+ # ==== Arguments
+ #
+ # * +name+ - the name of the Receiver
+ def receiver(name)
+ Qpid::Messaging::Receiver.new self, @session_impl.getReceiver(name)
+ end
+
+ # Closes the +Session+ and all associated +Sender+ and +Receiver+ instances.
+ #
+ # *NOTE:* All +Session+ instances for a Connection are closed when the
+ # Connection is closed. But closing a +Session+ does not affect the
+ # owning Connection.
+ def close; @session_impl.close; end
+
+ # Commits any pending transactions for a transactional session.
+ def commit; @session_impl.commit; end
+
+ # Rolls back any uncommitted transactions on a transactional session.
+ def rollback; @session_impl.rollback; end
+
+ # Acknowledges one or more outstanding messages that have been received
+ # on this session.
+ #
+ # ==== Arguments
+ #
+ # * +options+ - the set of options
+ #
+ # ==== Options
+ #
+ # * :message - if specified, then only that Message is acknowledged
+ # * :sync - if true, the call will block until processed by the broker
+ #
+ # ==== Examples
+ #
+ # # acknowledge all received messages
+ # session.acknowledge
+ #
+ # # acknowledge a single message
+ # session.acknowledge :message => message
+ #
+ # # acknowledge all messages, wait until the call finishes
+ # session.acknowledge :sync => true
+ #
+ #--
+ # TODO: Add an optional block to be used for blocking calls.
+ #++
+ def acknowledge(options = {})
+ sync = options[:sync] || false
+ message = options[:message] if options[:message]
+
+ unless message.nil?
+ @session_impl.acknowledge message.message_impl, sync
+ else
+ @session_impl.acknowledge sync
+ end
+ end
+
+ # Rejects the specified message. A rejected message will not be
+ # redelivered.
+ #
+ # NOTE: A message cannot be rejected once it has been acknowledged.
+ def reject(message); @session_impl.reject message.message_impl; end
+
+ # Releases the message, which allows the broker to attempt to
+ # redeliver it.
+ #
+ # NOTE: A message connot be released once it has been acknowled.
+ def release(message); @session_impl.release message.message_impl; end
+
+ # Requests synchronization with the broker.
+ #
+ # ==== Arguments
+ #
+ # * +options+ - the list of options
+ #
+ # ==== Options
+ #
+ # * +:block+ - if true, the call blocks until the broker acknowledges it
+ #
+ #--
+ # TODO: Add an optional block to be used for blocking calls.
+ #++
+ def sync(args = {})
+ block = args[:block] || false
+ @session_impl.sync block
+ end
+
+ # Returns the total number of receivable messages, and messages already
+ # received, by Receiver instances associated with this +Session+.
+ def receivable; @session_impl.getReceivable; end
+
+ # Returns the number of messages that have been acknowledged by this
+ # +Session+ whose acknowledgements have not been confirmed as processed
+ # by the broker.
+ def unsettled_acks; @session_impl.getUnsettledAcks; end
+
+ # Fetches the next Receiver with a message pending. Waits the specified
+ # number of milliseconds before timing out.
+ #
+ # For a Receiver to be returned, it must have a capacity > 0 and have
+ # Messages locally queued.
+ #
+ # If no Receiver is found within the time out period, then a MessageError
+ # is raised.
+ #
+ # ==== Arguments
+ #
+ # * +timeout+ - the duration
+ #
+ # ==== Examples
+ #
+ # loop do
+ #
+ # begin
+ # # wait a maximum of one minute for the next receiver to be ready
+ # recv = session.next_receiver Qpid::Messaging::Duration::MINUTE
+ #
+ # # get and dispatch the message
+ # msg = recv.get
+ # dispatch_message msg
+ #
+ # rescue
+ # puts "No receivers were returned"
+ # end
+ #
+ # end
+ def next_receiver(timeout = Qpid::Messaging::Duration::FOREVER, &block)
+ receiver_impl = @session_impl.nextReceiver(timeout.duration_impl)
+
+ unless receiver_impl.nil?
+ recv = Qpid::Messaging::Receiver.new self, receiver_impl
+ block.call recv unless block.nil?
+ end
+
+ return recv
+ end
+
+ # Returns true if there were exceptions on this session.
+ def errors?; @session_impl.hasError; end
+
+ # If the +Session+ has been rendered invalid due to some exception,
+ # this method will result in that exception being raised.
+ #
+ # If none have occurred, then no exceptions are raised.
+ #
+ # ==== Examples
+ #
+ # # show any errors that occurred during the Session
+ # if @session.errors?
+ # begin
+ # @session.errors
+ # rescue Exception => error
+ # puts "An error occurred: #{error}"
+ # end
+ # end
+ def errors; @session_impl.checkError; end
+
+ end
+
+ end
+
+end
+
diff --git a/cpp/bindings/qpid/ruby/qpid_messaging.gemspec b/cpp/bindings/qpid/ruby/qpid_messaging.gemspec
new file mode 100644
index 0000000000..06e3f48cb8
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/qpid_messaging.gemspec
@@ -0,0 +1,28 @@
+# -*- encoding: utf-8 -*-
+lib = File.expand_path('lib/', __FILE__)
+$:.unshift lib unless $:.include?(lib)
+
+# Generate the Swig wrapper
+system "swig -ruby -c++ -I../../../include -I../../ -o ext/cqpid/cqpid.cpp ruby.i"
+
+Gem::Specification.new do |s|
+ s.name = "qpid_messaging"
+ s.version = "0.22.0"
+ s.platform = Gem::Platform::RUBY
+ s.authors = "Apache Qpid Project"
+ s.email = "dev@qpid.apache.org"
+ s.homepage = "http://qpid.apache.org"
+ s.summary = "Qpid is an enterprise messaging framework."
+ s.description = s.summary
+
+ s.extensions = "ext/cqpid/extconf.rb"
+ s.files = Dir["LICENSE",
+ "ChangeLog",
+ "README.rdoc",
+ "TODO",
+ "lib/**/*.rb",
+ "ext/**/*",
+ ]
+ s.require_path = 'lib'
+end
+
diff --git a/cpp/bindings/qpid/ruby/ruby.i b/cpp/bindings/qpid/ruby/ruby.i
index 76463f7ddd..3d686c2ddb 100644
--- a/cpp/bindings/qpid/ruby/ruby.i
+++ b/cpp/bindings/qpid/ruby/ruby.i
@@ -18,8 +18,10 @@
*/
%module cqpid
+/* Ruby doesn't have a != operator*/
+#pragma SWIG nowarn=378
%include "std_string.i"
-%include "../../swig_ruby_typemaps.i"
+%include "qpid/swig_ruby_typemaps.i"
/* Define the general-purpose exception handling */
%exception {
@@ -32,5 +34,5 @@
}
}
-%include "../qpid.i"
+%include "qpid/qpid.i"
diff --git a/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb
deleted file mode 100644
index 784fb6fe77..0000000000
--- a/cpp/bindings/qpid/ruby/spec/qpid/address_spec.rb
+++ /dev/null
@@ -1,87 +0,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.
-#
-
-require 'spec_helper'
-
-module Qpid
-
- module Messaging
-
- describe Address do
-
- before(:each) do
- @address = Qpid::Messaging::Address.new "my-name", "my-subject", :create => :always
- end
-
- it "stores the name, subject and options when created" do
- name = @address.name
- subject = @address.subject
- create = @address.options["create"]
-
- name.should == "my-name"
- subject.should == "my-subject"
- create.should == "always"
- end
-
- it "can update the name" do
- @address.name = "new-name"
-
- name = @address.name
-
- name.should == "new-name"
- end
-
- it "can update the subject" do
- @address.subject = "new-subject"
-
- subject = @address.subject
-
- subject.should == "new-subject"
- end
-
- it "can update the type" do
- @address.address_type = "routed"
-
- type = @address.address_type
-
- type.should == "routed"
- end
-
- it "can update the options" do
- @address.options[:create] = :never
-
- create = @address.options["create"]
-
- create.should == "always"
- end
-
- it "can return a string representation" do
- address = Qpid::Messaging::Address.new "foo", "bar", :create => :always, :link => :durable
- result = address.to_s
-
- result.should =~ /foo\/bar/
- result.should =~ /create:always/
- result.should =~ /link:durable/
- end
-
- end
-
- end
-
-end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb
deleted file mode 100644
index a2f5b7e898..0000000000
--- a/cpp/bindings/qpid/ruby/spec/qpid/connection_spec.rb
+++ /dev/null
@@ -1,191 +0,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.
-#
-
-require 'spec_helper'
-
-module Qpid
-
- module Messaging
-
- describe Connection do
-
- before(:each) do
- @session_impl = double('Cqpid::Session')
- @connection_impl = double('Cqpid::Connection')
-
- @connection = Qpid::Messaging::Connection.new :impl => @connection_impl
- end
-
- it "accepts options on construction" do
- expect {
- connection = Qpid::Messaging::Connection.new :options => {:username => "foo"}
-
- connection.options.should include("username")
- }.should_not raise_error
- end
-
- it "returns the underlying implementation" do
- impl = @connection.connection_impl
-
- impl.should == @connection_impl
- end
-
- it "opens the connection" do
- @connection_impl.should_receive(:open)
-
- @connection.open
- end
-
- it "closes the connection" do
- @connection_impl.should_receive(:close)
-
- @connection.close
- end
-
- it "retrieves a session by name" do
- @connection_impl.should_receive(:getSession).
- with("farkle").
- and_return(@session_impl)
-
- session = @connection.session "farkle"
-
- session.session_impl.should == @session_impl
- end
-
- it "raises an error when a session name is invalid" do
- @connection_impl.should_receive(:getSession).
- with("farkle").
- and_raise(RuntimeError)
-
- expect {
- @connection.session "farkle"
- }.to raise_error(SessionNameException)
- end
-
- ####################################################################
- # test conditions for when a connection is not connected to a broker
- ####################################################################
- describe "when closed" do
-
- before(:each) do
- @connection_impl.should_receive(:isOpen).
- and_return(false)
- end
-
- it "returns false when not connected to a broker" do
- open = @connection.open?
-
- open.should == false
- end
-
- it "should raise an error when creating a session on a closed connection" do
- expect {
- @connection.create_session
- }.to raise_error(RuntimeError)
- end
-
- it "raises an error when creating a transactional session on a closed connection" do
- expect {
- @connection.create_session :transactional => true
- }.to raise_error(RuntimeError)
- end
-
- it "raises an error when creating a named session on a closed connection" do
- expect {
- @connection.create_session :name => "test", :transactional => true
- }.to raise_error(RuntimeError)
- end
-
- it "returns a null username when not connected" do
- username = @connection.authenticated_username
-
- username.should be_nil
- end
-
- end
-
- #########################################################
- # test conditions for when a connection must be connected
- #########################################################
- describe "when connected" do
-
- before(:each) do
- @connection_impl.should_receive(:isOpen).
- and_return(true)
- end
-
- it "returns true when connected to a broker" do
- open = @connection.open?
-
- open.should == true
- end
-
- it "creates a session" do
- @connection_impl.should_receive(:createSession).
- and_return(@session_impl)
-
- session = @connection.create_session
-
- session.session_impl.should == @session_impl
- end
-
- it "creates a named session with a name when provided" do
- @connection_impl.should_receive(:createSession).with("farkle").
- and_return(@session_impl)
-
- session = @connection.create_session :name => "farkle"
-
- session.session_impl.should == @session_impl
- end
-
- it "creates a transactional session when specified" do
- @connection_impl.should_receive(:createTransactionalSession).
- and_return(@session_impl)
-
- session = @connection.create_session :transactional => true
-
- session.session_impl.should == @session_impl
- end
-
- it "creates a named transactional session when specified" do
- @connection_impl.should_receive(:createTransactionalSession).
- with("farkle").
- and_return(@session_impl)
-
- session = @connection.create_session :transactional => true, :name => "farkle"
-
- session.session_impl.should == @session_impl
- end
-
- it "returns the authenticated username when connected" do
- @connection_impl.should_receive(:getAuthenticatedUsername).
- and_return("mcpierce")
-
- username = @connection.authenticated_username
-
- username.should == "mcpierce"
- end
-
- end
-
- end
-
- end
-
-end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb
deleted file mode 100644
index 4980b6ffe7..0000000000
--- a/cpp/bindings/qpid/ruby/spec/qpid/duration_spec.rb
+++ /dev/null
@@ -1,56 +0,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.
-#
-
-require 'spec_helper'
-
-module Qpid
-
- module Messaging
-
- describe Duration do
-
- before(:each) do
- @duration = Qpid::Messaging::Duration::SECOND
- end
-
- it "returns the underlying implementation" do
- impl = @duration.duration_impl
-
- impl.should_not be_nil
- end
-
- it "can create a duration with a millisecond value" do
- duration = Qpid::Messaging::Duration.new 500
-
- milliseconds = duration.milliseconds
-
- milliseconds.should == 500
- end
-
- it "returns the time in milliseconds" do
- milliseconds = @duration.milliseconds
-
- milliseconds.should == 1000
- end
-
- end
-
- end
-
-end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb
deleted file mode 100644
index e34e58f563..0000000000
--- a/cpp/bindings/qpid/ruby/spec/qpid/message_spec.rb
+++ /dev/null
@@ -1,292 +0,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.
-#
-
-require 'spec_helper'
-
-module Qpid
-
- module Messaging
-
- describe Message do
-
- before(:each) do
- @message = Qpid::Messaging::Message.new :content => "My content"
- end
-
- it "returns its implementation" do
- impl = @message.message_impl
-
- impl.class.should == Cqpid::Message
- end
-
- it "can set the reply to address" do
- address = Qpid::Messaging::Address.new "my-queue", ""
-
- @message.reply_to = address
-
- reply_to = @message.reply_to
-
- reply_to.name.should == address.name
- end
-
- it "should store the content when created" do
- content = @message.content
-
- content.should == "My content"
- end
-
- it "should properly encode a map when created" do
- message = Qpid::Messaging::Message.new :content => {"foo" => "bar"}
-
- content = message.content
- content_type = message.content_type
-
- content_type.should == "amqp/map"
- content.class == Hash
- content["foo"].should == "bar"
- end
-
- it "should properly encode a list when created" do
- message = Qpid::Messaging::Message.new :content => ["foo", "bar"]
-
- content = message.content
- content_type = message.content_type
-
- content_type.should == "amqp/list"
- content.class == Array
- content.should include("foo")
- content.should include("bar")
- end
-
- it "should store the subject" do
- @message.subject = "new-subject"
-
- subject = @message.subject
-
- subject.should == "new-subject"
- end
-
- it "should update the content type" do
- @message.content_type = "amqp/audio"
-
- content_type = @message.content_type
-
- content_type.should == "amqp/audio"
- end
-
- it "should store the message id" do
- @message.message_id = "foo"
-
- id = @message.message_id
-
- id.should == "foo"
- end
-
- it "should store the user id" do
- @message.user_id = "foo"
-
- id = @message.user_id
-
- id.should == "foo"
- end
-
- it "should store the correlation id" do
- @message.correlation_id = "message1"
-
- id = @message.correlation_id
-
- id.should == "message1"
- end
-
- it "should store the priority" do
- @message.priority = 7
-
- priority = @message.priority
-
- priority.should == 7
- end
-
- it "should accept a Duration as the time to live" do
- @message.ttl = Qpid::Messaging::Duration::SECOND
-
- ttl = @message.ttl
-
- ttl.milliseconds.should == Qpid::Messaging::Duration::SECOND.milliseconds
- end
-
- it "should accept an integer value as the time to live" do
- @message.ttl = 15000
-
- ttl = @message.ttl
-
- ttl.milliseconds.should == 15000
- end
-
- it "should update the durable flag" do
- @message.durable = true
-
- durable = @message.durable
-
- durable.should == true
- end
-
- it "should update the redelivered flag" do
- @message.redelivered = true
-
- redelivered = @message.redelivered
-
- redelivered.should == true
- end
-
- it "should store a property" do
- property = @message[:test_property]
-
- property.should == nil
-
- @message[:test_property] = "test_value1"
-
- property = @message[:test_property]
-
- property.should == "test_value1"
- end
-
- it "should convert a symbol property value to a string" do
- @message[:test_property] = :test_value2
-
- property = @message[:test_property]
-
- property.should == "test_value2"
- end
-
- it "should convert a symbol property name to a string" do
- @message[:test_property] = "test_value3"
-
- property = @message["test_property"]
-
- property.should == "test_value3"
- end
-
- it "should store text content" do
- @message.content = "This is the content."
-
- content = @message.content
-
- content.should == "This is the content."
- end
-
- it "should store list content" do
- list = ["foo", "bar"]
-
- @message.content = list
-
- content = @message.content
- content_type = @message.content_type
-
- content.should == list
- content_type.should == "amqp/list"
- end
-
- it "should convert symbol list elements to strings" do
- @message.content = [:farkle]
-
- content = @message.content.first
-
- content.should == "farkle"
- end
-
- it "should store map content" do
- map = {"foo" => "bar"}
-
- @message.content = map
-
- content = @message.content
- content_type = @message.content_type
-
- content.should == map
- content_type.should == "amqp/map"
- end
-
- it "should convert symbol map elements to strings" do
- @message.content = {:first_name => :qpid}
-
- content = @message.content["first_name"]
-
- content.should == "qpid"
- end
-
- describe "with content from the underlying implementation" do
-
- before(:each) do
- @message_impl = double("Cqpid::Message")
- @message = Qpid::Messaging::Message.new :impl => @message_impl
- end
-
- it "should return simple text content" do
- @message_impl.should_receive(:getContent).
- and_return("my content")
- @message_impl.should_receive(:getContentType).
- and_return("")
-
- content = @message.content
-
- content.should == "my content"
- end
-
- it "should decode a list" do
- list = ["first", "second"]
-
- @message_impl.should_receive(:getContent).
- and_return(list)
- @message_impl.should_receive(:getContentType).
- twice.
- and_return("amqp/list")
- Qpid::Messaging.stub!(:decode).
- with(@message, "amqp/list").
- and_return(list)
-
- content = @message.content
-
- content.should == list
- end
-
- it "should decode a map" do
- map = {"first" => "second"}
-
- @message_impl.should_receive(:getContent).
- and_return(map)
- @message_impl.should_receive(:getContentType).
- twice.
- and_return("amqp/map")
- Qpid::Messaging.stub!(:decode).
- with(@message, "amqp/map").
- and_return(map)
-
- content = @message.content
-
- content.should == map
- end
-
-
- end
-
- end
-
- end
-
-end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb
deleted file mode 100644
index 0b103a31e6..0000000000
--- a/cpp/bindings/qpid/ruby/spec/qpid/session_spec.rb
+++ /dev/null
@@ -1,353 +0,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.
-#
-
-require 'spec_helper'
-
-module Qpid
-
- module Messaging
-
- describe Session do
-
- before(:each) do
- @connection = double("Qpid::Messaging::Connection")
- @session_impl = double("Cqpid::Session")
- @session = Qpid::Messaging::Session.new @connection, @session_impl
- @sender_impl = double("Cqpid::Sender")
- @receiver_impl = double("Cqpid::Receiver")
- end
-
- it "returns its implementation" do
- impl = @session.session_impl
-
- impl.should == @session_impl
- end
-
- it "returns its connection" do
- connection = @session.connection
-
- connection.should == @connection
- end
-
- it "creates a Sender from an Address" do
- address = Qpid::Messaging::Address.new "my-queu", "", :create => :always
-
- @session_impl.should_receive(:createSender).
- with(address.address_impl).
- and_return(@sender_impl)
- @sender_impl.should_receive(:getName).
- and_return("my-queue")
-
- sender = @session.create_sender address
-
- sender.sender_impl.should == @sender_impl
- end
-
- it "creates a Sender from an address string" do
- address = "my-queue;{create:true}"
-
- @session_impl.should_receive(:createSender).
- with(address).
- and_return(@sender_impl)
- @sender_impl.should_receive(:getName).
- and_return("my-queue")
-
- sender = @session.create_sender address
-
- sender.sender_impl.should == @sender_impl
- end
-
- #######################################
- # scenarios involing an existing Sender
- #######################################
- describe "when retrieving a Sender by name" do
-
- before(:each) do
- address = "my-queue;{create:always}"
- @name = "my-queue"
-
- @session_impl.should_receive(:createSender).
- with(address).
- and_return(@sender_impl)
- @sender_impl.should_receive(:getName).
- and_return(@name)
-
- @sender = @session.create_sender address
- end
-
- it "works when the name is valid" do
- sender = @session.sender @name
-
- sender.should == @sender
- end
-
- it "raises an error when the name is invalid" do
- expect {
- @session.sender @name.reverse
- }.to raise_error(Qpid::Messaging::KeyError)
- end
-
- end
-
- it "creates a Receiver from an Address" do
- address = Qpid::Messaging::Address.new "my-queue", ""
-
- @session_impl.should_receive(:createReceiver).
- with(address.address_impl).
- and_return(@receiver_impl)
- @receiver_impl.should_receive(:getName).
- and_return("my-queue")
-
- receiver = @session.create_receiver address
-
- receiver.receiver_impl.should == @receiver_impl
- end
-
- it "creates a Receiver from an address string" do
- address = "my-queue"
-
- @session_impl.should_receive(:createReceiver).
- with(address).
- and_return(@receiver_impl)
- @receiver_impl.should_receive(:getName).
- and_return("my-queue")
-
- receiver = @session.create_receiver address
-
- receiver.receiver_impl.should == @receiver_impl
- end
-
- #########################################
- # scenarios involving an existing Receiver
- ##########################################
- describe "when retrieving a Receiver by name" do
-
- before(:each) do
- address = "my-queue"
- @name = "my-queue"
-
- @session_impl.should_receive(:createReceiver).
- with(address).
- and_return(@receiver_impl)
- @receiver_impl.should_receive(:getName).
- and_return(@name)
-
- @receiver = @session.create_receiver address
- end
-
- it "works with a valid name" do
- receiver = @session.receiver @name
-
- receiver.should == @receiver
- end
-
- it "raises an error when the name is invalid" do
- expect {
- @session.receiver @name.reverse
- }.to raise_error(Qpid::Messaging::KeyError)
- end
-
- end
-
- it "closes the session" do
- @session_impl.should_receive(:close)
-
- @session.close
- end
-
- it "commits a pending transaction" do
- @session_impl.should_receive(:commit)
-
- @session.commit
- end
-
- it "rolls back an uncommitted transaction" do
- @session_impl.should_receive(:rollback)
-
- @session.rollback
- end
-
- it "acknowledges all received messages" do
- @session_impl.should_receive(:acknowledge).
- with(false)
-
- @session.acknowledge
- end
-
- it "acknowledges all messages synchronously" do
- @session_impl.should_receive(:acknowledge).
- with(true)
-
- @session.acknowledge :sync => true
- end
-
- it "acknowledges all messages asynchronously" do
- @session_impl.should_receive(:acknowledge).
- with(false)
-
- @session.acknowledge :sync => false
- end
-
- ######################################
- # Scenarios involving a single message
- ######################################
- describe "with a single message" do
-
- before(:each) do
- @message = Qpid::Messaging::Message.new :content => "Testing"
- end
-
- it "can acknowledge asynchronously by default" do
- @session_impl.should_receive(:acknowledge).
- with(@message.message_impl, false)
-
- @session.acknowledge :message => @message
- end
-
- it "can acknowledge synchronously" do
- @session_impl.should_receive(:acknowledge).
- with(@message.message_impl, true)
-
- @session.acknowledge :message => @message, :sync => true
- end
-
- it "can acknowledge asynchronously" do
- @session_impl.should_receive(:acknowledge).
- with(@message.message_impl, false)
-
- @session.acknowledge :message => @message, :sync => false
- end
-
- it "can reject it" do
- @session_impl.should_receive(:reject).
- with(@message.message_impl)
-
- @session.reject @message
- end
-
- it "can release it" do
- @session_impl.should_receive(:release).
- with(@message.message_impl)
-
- @session.release @message
- end
-
- end
-
- it "does not block by default when synchronizating with the broker" do
- @session_impl.should_receive(:sync).
- with(false)
-
- @session.sync
- end
-
- it "can block while synchronizing with the broker" do
- @session_impl.should_receive(:sync).
- with(true)
-
- @session.sync :block => true
- end
-
- it "can not block while synchronizing with the broker" do
- @session_impl.should_receive(:sync).
- with(false)
-
- @session.sync :block => false
- end
-
- it "returns the number of messages that are receivable" do
- @session_impl.should_receive(:getReceivable).
- and_return(15)
-
- receivable = @session.receivable
-
- receivable.should == 15
- end
-
- it "returns the number of unsettled messages" do
- @session_impl.should_receive(:getUnsettledAcks).
- and_return(25)
-
- unsettled = @session.unsettled_acks
-
- unsettled.should == 25
- end
-
- it "waits forever by default for the next Receiver with messages" do
- @session_impl.should_receive(:nextReceiver).
- with(Qpid::Messaging::Duration::FOREVER.duration_impl).
- and_return(@receiver_impl)
-
- receiver = @session.next_receiver
-
- receiver.receiver_impl.should == @receiver_impl
- end
-
- it "uses the specified time when waiting for the next Receiver with messages" do
- @session_impl.should_receive(:nextReceiver).
- with(Qpid::Messaging::Duration::SECOND.duration_impl).
- and_return(@receiver_impl)
-
- receiver = @session.next_receiver Qpid::Messaging::Duration::SECOND
-
- receiver.receiver_impl.should == @receiver_impl
- end
-
- it "returns nil when no Receiver has messages within the timeout period" do
- @session_impl.should_receive(:nextReceiver).
- with(Qpid::Messaging::Duration::MINUTE.duration_impl).
- and_return(nil)
-
- receiver = @session.next_receiver Qpid::Messaging::Duration::MINUTE
-
- receiver.should be_nil
- end
-
- it "returns true when there are errors on the session" do
- @session_impl.should_receive(:hasError).
- and_return(true)
-
- errors = @session.errors?
-
- errors.should be_true
- end
-
- it "returns false when there are no errors on the session" do
- @session_impl.should_receive(:hasError).
- and_return(false)
-
- errors = @session.errors?
-
- errors.should be_false
- end
-
- it "causes exceptions to be raised when there are errors" do
- @session_impl.should_receive(:checkError).
- and_raise(RuntimeError)
-
- expect {
- @session.errors
- }.to raise_error(RuntimeError)
- end
-
- end
-
- end
-
-end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid_messaging/address_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid_messaging/address_spec.rb
new file mode 100644
index 0000000000..05c97ddf30
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/spec/qpid_messaging/address_spec.rb
@@ -0,0 +1,87 @@
+#
+# 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.
+#
+
+require 'spec_helper'
+
+module Qpid
+
+ module Messaging
+
+ describe Address do
+
+ before(:each) do
+ @address = Qpid::Messaging::Address.new "my-name/my-subject;{create:always}"
+ end
+
+ it "stores the name, subject and options when created" do
+ name = @address.name
+ subject = @address.subject
+ create = @address.options["create"]
+
+ name.should == "my-name"
+ subject.should == "my-subject"
+ create.should == "always"
+ end
+
+ it "can update the name" do
+ @address.name = "new-name"
+
+ name = @address.name
+
+ name.should == "new-name"
+ end
+
+ it "can update the subject" do
+ @address.subject = "new-subject"
+
+ subject = @address.subject
+
+ subject.should == "new-subject"
+ end
+
+ it "can update the type" do
+ @address.address_type = "routed"
+
+ type = @address.address_type
+
+ type.should == "routed"
+ end
+
+ it "can update the options" do
+ @address.options[:create] = :never
+
+ create = @address.options["create"]
+
+ create.should == "always"
+ end
+
+ it "can return a string representation" do
+ address = Qpid::Messaging::Address.new "foo/bar:{create:always,link:durable}"
+ result = address.to_s
+
+ result.should =~ /foo\/bar/
+ result.should =~ /create:always/
+ result.should =~ /link:durable/
+ end
+
+ end
+
+ end
+
+end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid_messaging/connection_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid_messaging/connection_spec.rb
new file mode 100644
index 0000000000..811abf36e9
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/spec/qpid_messaging/connection_spec.rb
@@ -0,0 +1,191 @@
+#
+# 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.
+#
+
+require 'spec_helper'
+
+module Qpid
+
+ module Messaging
+
+ describe Connection do
+
+ before(:each) do
+ @session_impl = double('Cqpid::Session')
+ @connection_impl = double('Cqpid::Connection')
+
+ @connection = Qpid::Messaging::Connection.new :impl => @connection_impl
+ end
+
+ it "accepts options on construction" do
+ expect {
+ connection = Qpid::Messaging::Connection.new :options => {:username => "foo"}
+
+ connection.options.should include("username")
+ }.to_not raise_error
+ end
+
+ it "returns the underlying implementation" do
+ impl = @connection.connection_impl
+
+ impl.should == @connection_impl
+ end
+
+ it "opens the connection" do
+ @connection_impl.should_receive(:open)
+
+ @connection.open
+ end
+
+ it "closes the connection" do
+ @connection_impl.should_receive(:close)
+
+ @connection.close
+ end
+
+ it "retrieves a session by name" do
+ @connection_impl.should_receive(:getSession).
+ with("farkle").
+ and_return(@session_impl)
+
+ session = @connection.session "farkle"
+
+ session.session_impl.should == @session_impl
+ end
+
+ it "raises an error when a session name is invalid" do
+ @connection_impl.should_receive(:getSession).
+ with("farkle").
+ and_raise(RuntimeError)
+
+ expect {
+ @connection.session "farkle"
+ }.to raise_error(SessionNameException)
+ end
+
+ ####################################################################
+ # test conditions for when a connection is not connected to a broker
+ ####################################################################
+ describe "when closed" do
+
+ before(:each) do
+ @connection_impl.should_receive(:isOpen).
+ and_return(false)
+ end
+
+ it "returns false when not connected to a broker" do
+ open = @connection.open?
+
+ open.should == false
+ end
+
+ it "should raise an error when creating a session on a closed connection" do
+ expect {
+ @connection.create_session
+ }.to raise_error(RuntimeError)
+ end
+
+ it "raises an error when creating a transactional session on a closed connection" do
+ expect {
+ @connection.create_session :transactional => true
+ }.to raise_error(RuntimeError)
+ end
+
+ it "raises an error when creating a named session on a closed connection" do
+ expect {
+ @connection.create_session :name => "test", :transactional => true
+ }.to raise_error(RuntimeError)
+ end
+
+ it "returns a null username when not connected" do
+ username = @connection.authenticated_username
+
+ username.should be_nil
+ end
+
+ end
+
+ #########################################################
+ # test conditions for when a connection must be connected
+ #########################################################
+ describe "when connected" do
+
+ before(:each) do
+ @connection_impl.should_receive(:isOpen).
+ and_return(true)
+ end
+
+ it "returns true when connected to a broker" do
+ open = @connection.open?
+
+ open.should == true
+ end
+
+ it "creates a session" do
+ @connection_impl.should_receive(:createSession).
+ and_return(@session_impl)
+
+ session = @connection.create_session
+
+ session.session_impl.should == @session_impl
+ end
+
+ it "creates a named session with a name when provided" do
+ @connection_impl.should_receive(:createSession).with("farkle").
+ and_return(@session_impl)
+
+ session = @connection.create_session :name => "farkle"
+
+ session.session_impl.should == @session_impl
+ end
+
+ it "creates a transactional session when specified" do
+ @connection_impl.should_receive(:createTransactionalSession).
+ and_return(@session_impl)
+
+ session = @connection.create_session :transactional => true
+
+ session.session_impl.should == @session_impl
+ end
+
+ it "creates a named transactional session when specified" do
+ @connection_impl.should_receive(:createTransactionalSession).
+ with("farkle").
+ and_return(@session_impl)
+
+ session = @connection.create_session :transactional => true, :name => "farkle"
+
+ session.session_impl.should == @session_impl
+ end
+
+ it "returns the authenticated username when connected" do
+ @connection_impl.should_receive(:getAuthenticatedUsername).
+ and_return("mcpierce")
+
+ username = @connection.authenticated_username
+
+ username.should == "mcpierce"
+ end
+
+ end
+
+ end
+
+ end
+
+end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid_messaging/duration_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid_messaging/duration_spec.rb
new file mode 100644
index 0000000000..202332d232
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/spec/qpid_messaging/duration_spec.rb
@@ -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.
+#
+
+require 'spec_helper'
+
+module Qpid
+
+ module Messaging
+
+ describe Duration do
+
+ before(:each) do
+ @duration = Qpid::Messaging::Duration::SECOND
+ end
+
+ it "returns the underlying implementation" do
+ impl = @duration.duration_impl
+
+ impl.should_not be_nil
+ end
+
+ it "can create a duration with a millisecond value" do
+ duration = Qpid::Messaging::Duration.new 500
+
+ milliseconds = duration.milliseconds
+
+ milliseconds.should == 500
+ end
+
+ it "returns the time in milliseconds" do
+ milliseconds = @duration.milliseconds
+
+ milliseconds.should == 1000
+ end
+
+ it "raises an error when multiplied by a negative" do
+ expect {
+ twomin = Qpid::Messaging::Duration::MINUTE * -2
+ }.to raise_error
+ end
+
+ it "returns IMMEDIATE if the factor is zero" do
+ result = Qpid::Messaging::Duration::MINUTE * 0
+ result.should be(Qpid::Messaging::Duration::IMMEDIATE)
+ end
+
+ it "fractional factors return a reduced duration" do
+ factor = rand(1)
+ first = Qpid::Messaging::Duration::MINUTE
+ second = first * factor
+
+ second.milliseconds.should == ((first.milliseconds * factor).floor)
+ end
+
+ it "can return a multiple of its duration" do
+ factor = rand(10).floor
+ first = Qpid::Messaging::Duration.new(rand(10).floor * 10000)
+ second = first * factor
+
+ second.milliseconds.should == first.milliseconds * factor
+ end
+
+ end
+
+ end
+
+end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid/encoding_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid_messaging/encoding_spec.rb
index 58b8447278..58b8447278 100644
--- a/cpp/bindings/qpid/ruby/spec/qpid/encoding_spec.rb
+++ b/cpp/bindings/qpid/ruby/spec/qpid_messaging/encoding_spec.rb
diff --git a/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb
new file mode 100644
index 0000000000..be19b3591e
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb
@@ -0,0 +1,305 @@
+#
+# 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.
+#
+
+require 'spec_helper'
+
+module Qpid
+
+ module Messaging
+
+ describe Message do
+
+ before(:each) do
+ @message = Qpid::Messaging::Message.new :content => "My content"
+ end
+
+ it "returns its implementation" do
+ impl = @message.message_impl
+
+ impl.class.should == Cqpid::Message
+ end
+
+ it "can set the reply to address" do
+ address = Qpid::Messaging::Address.new "my-queue;{create:always}"
+
+ @message.reply_to = address
+
+ reply_to = @message.reply_to
+
+ reply_to.name.should == address.name
+ end
+
+ it "can set the reply to from an address string" do
+ name = "my-queue"
+ subject = "responses"
+ address = "#{name}/#{subject}"
+
+ @message.reply_to = address
+
+ reply_to = @message.reply_to
+
+ reply_to.name.should == name
+ reply_to.subject.should == subject
+ end
+
+ it "should store the content when created" do
+ content = @message.content
+
+ content.should == "My content"
+ end
+
+ it "should properly encode a map when created" do
+ message = Qpid::Messaging::Message.new :content => {"foo" => "bar"}
+
+ content = message.content
+ content_type = message.content_type
+
+ content_type.should == "amqp/map"
+ content.class == Hash
+ content["foo"].should == "bar"
+ end
+
+ it "should properly encode a list when created" do
+ message = Qpid::Messaging::Message.new :content => ["foo", "bar"]
+
+ content = message.content
+ content_type = message.content_type
+
+ content_type.should == "amqp/list"
+ content.class == Array
+ content.should include("foo")
+ content.should include("bar")
+ end
+
+ it "should store the subject" do
+ @message.subject = "new-subject"
+
+ subject = @message.subject
+
+ subject.should == "new-subject"
+ end
+
+ it "should update the content type" do
+ @message.content_type = "amqp/audio"
+
+ content_type = @message.content_type
+
+ content_type.should == "amqp/audio"
+ end
+
+ it "should store the message id" do
+ @message.message_id = "foo"
+
+ id = @message.message_id
+
+ id.should == "foo"
+ end
+
+ it "should store the user id" do
+ @message.user_id = "foo"
+
+ id = @message.user_id
+
+ id.should == "foo"
+ end
+
+ it "should store the correlation id" do
+ @message.correlation_id = "message1"
+
+ id = @message.correlation_id
+
+ id.should == "message1"
+ end
+
+ it "should store the priority" do
+ @message.priority = 7
+
+ priority = @message.priority
+
+ priority.should == 7
+ end
+
+ it "should accept a Duration as the time to live" do
+ @message.ttl = Qpid::Messaging::Duration::SECOND
+
+ ttl = @message.ttl
+
+ ttl.milliseconds.should == Qpid::Messaging::Duration::SECOND.milliseconds
+ end
+
+ it "should accept an integer value as the time to live" do
+ @message.ttl = 15000
+
+ ttl = @message.ttl
+
+ ttl.milliseconds.should == 15000
+ end
+
+ it "should update the durable flag" do
+ @message.durable = true
+
+ durable = @message.durable
+
+ durable.should == true
+ end
+
+ it "should update the redelivered flag" do
+ @message.redelivered = true
+
+ redelivered = @message.redelivered
+
+ redelivered.should == true
+ end
+
+ it "should store a property" do
+ property = @message[:test_property]
+
+ property.should == nil
+
+ @message[:test_property] = "test_value1"
+
+ property = @message[:test_property]
+
+ property.should == "test_value1"
+ end
+
+ it "should convert a symbol property value to a string" do
+ @message[:test_property] = :test_value2
+
+ property = @message[:test_property]
+
+ property.should == "test_value2"
+ end
+
+ it "should convert a symbol property name to a string" do
+ @message[:test_property] = "test_value3"
+
+ property = @message["test_property"]
+
+ property.should == "test_value3"
+ end
+
+ it "should store text content" do
+ @message.content = "This is the content."
+
+ content = @message.content
+
+ content.should == "This is the content."
+ end
+
+ it "should store list content" do
+ list = ["foo", "bar"]
+
+ @message.content = list
+
+ content = @message.content
+ content_type = @message.content_type
+
+ content.should == list
+ content_type.should == "amqp/list"
+ end
+
+ it "should convert symbol list elements to strings" do
+ @message.content = [:farkle]
+
+ content = @message.content.first
+
+ content.should == "farkle"
+ end
+
+ it "should store map content" do
+ map = {"foo" => "bar"}
+
+ @message.content = map
+
+ content = @message.content
+ content_type = @message.content_type
+
+ content.should == map
+ content_type.should == "amqp/map"
+ end
+
+ it "should convert symbol map elements to strings" do
+ @message.content = {:first_name => :qpid}
+
+ content = @message.content["first_name"]
+
+ content.should == "qpid"
+ end
+
+ describe "with content from the underlying implementation" do
+
+ before(:each) do
+ @message_impl = double("Cqpid::Message")
+ @message = Qpid::Messaging::Message.new :impl => @message_impl
+ end
+
+ it "should return simple text content" do
+ @message_impl.should_receive(:getContent).
+ and_return("my content")
+ @message_impl.should_receive(:getContentType).
+ and_return("")
+
+ content = @message.content
+
+ content.should == "my content"
+ end
+
+ it "should decode a list" do
+ list = ["first", "second"]
+
+ @message_impl.should_receive(:getContent).
+ and_return(list)
+ @message_impl.should_receive(:getContentType).
+ twice.
+ and_return("amqp/list")
+ Qpid::Messaging.stub!(:decode).
+ with(@message, "amqp/list").
+ and_return(list)
+
+ content = @message.content
+
+ content.should == list
+ end
+
+ it "should decode a map" do
+ map = {"first" => "second"}
+
+ @message_impl.should_receive(:getContent).
+ and_return(map)
+ @message_impl.should_receive(:getContentType).
+ twice.
+ and_return("amqp/map")
+ Qpid::Messaging.stub!(:decode).
+ with(@message, "amqp/map").
+ and_return(map)
+
+ content = @message.content
+
+ content.should == map
+ end
+
+
+ end
+
+ end
+
+ end
+
+end
diff --git a/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid_messaging/receiver_spec.rb
index 81ae935dcb..81ae935dcb 100644
--- a/cpp/bindings/qpid/ruby/spec/qpid/receiver_spec.rb
+++ b/cpp/bindings/qpid/ruby/spec/qpid_messaging/receiver_spec.rb
diff --git a/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid_messaging/sender_spec.rb
index fa3a2a5b1f..fa3a2a5b1f 100644
--- a/cpp/bindings/qpid/ruby/spec/qpid/sender_spec.rb
+++ b/cpp/bindings/qpid/ruby/spec/qpid_messaging/sender_spec.rb
diff --git a/cpp/bindings/qpid/ruby/spec/qpid_messaging/session_spec.rb b/cpp/bindings/qpid/ruby/spec/qpid_messaging/session_spec.rb
new file mode 100644
index 0000000000..754e2ca88f
--- /dev/null
+++ b/cpp/bindings/qpid/ruby/spec/qpid_messaging/session_spec.rb
@@ -0,0 +1,353 @@
+#
+# 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.
+#
+
+require 'spec_helper'
+
+module Qpid
+
+ module Messaging
+
+ describe Session do
+
+ before(:each) do
+ @connection = double("Qpid::Messaging::Connection")
+ @session_impl = double("Cqpid::Session")
+ @session = Qpid::Messaging::Session.new @connection, @session_impl
+ @sender_impl = double("Cqpid::Sender")
+ @receiver_impl = double("Cqpid::Receiver")
+ end
+
+ it "returns its implementation" do
+ impl = @session.session_impl
+
+ impl.should == @session_impl
+ end
+
+ it "returns its connection" do
+ connection = @session.connection
+
+ connection.should == @connection
+ end
+
+ it "creates a Sender from an Address" do
+ address = Qpid::Messaging::Address.new "my-queue;{create:always}"
+
+ @session_impl.should_receive(:createSender).
+ with(address.address_impl).
+ and_return(@sender_impl)
+ @sender_impl.should_receive(:getName).
+ and_return("my-queue")
+
+ sender = @session.create_sender address
+
+ sender.sender_impl.should == @sender_impl
+ end
+
+ it "creates a Sender from an address string" do
+ address = "my-queue;{create:true}"
+
+ @session_impl.should_receive(:createSender).
+ with(address).
+ and_return(@sender_impl)
+ @sender_impl.should_receive(:getName).
+ and_return("my-queue")
+
+ sender = @session.create_sender address
+
+ sender.sender_impl.should == @sender_impl
+ end
+
+ #######################################
+ # scenarios involing an existing Sender
+ #######################################
+ describe "when retrieving a Sender by name" do
+
+ before(:each) do
+ address = "my-queue;{create:always}"
+ @name = "my-queue"
+
+ @session_impl.should_receive(:createSender).
+ with(address).
+ and_return(@sender_impl)
+ @sender_impl.should_receive(:getName).
+ and_return(@name)
+
+ @sender = @session.create_sender address
+ end
+
+ it "works when the name is valid" do
+ sender = @session.sender @name
+
+ sender.should == @sender
+ end
+
+ it "raises an error when the name is invalid" do
+ expect {
+ @session.sender @name.reverse
+ }.to raise_error(Qpid::Messaging::KeyError)
+ end
+
+ end
+
+ it "creates a Receiver from an Address" do
+ address = Qpid::Messaging::Address.new "my-queue", ""
+
+ @session_impl.should_receive(:createReceiver).
+ with(address.address_impl).
+ and_return(@receiver_impl)
+ @receiver_impl.should_receive(:getName).
+ and_return("my-queue")
+
+ receiver = @session.create_receiver address
+
+ receiver.receiver_impl.should == @receiver_impl
+ end
+
+ it "creates a Receiver from an address string" do
+ address = "my-queue"
+
+ @session_impl.should_receive(:createReceiver).
+ with(address).
+ and_return(@receiver_impl)
+ @receiver_impl.should_receive(:getName).
+ and_return("my-queue")
+
+ receiver = @session.create_receiver address
+
+ receiver.receiver_impl.should == @receiver_impl
+ end
+
+ #########################################
+ # scenarios involving an existing Receiver
+ ##########################################
+ describe "when retrieving a Receiver by name" do
+
+ before(:each) do
+ address = "my-queue"
+ @name = "my-queue"
+
+ @session_impl.should_receive(:createReceiver).
+ with(address).
+ and_return(@receiver_impl)
+ @receiver_impl.should_receive(:getName).
+ and_return(@name)
+
+ @receiver = @session.create_receiver address
+ end
+
+ it "works with a valid name" do
+ receiver = @session.receiver @name
+
+ receiver.should == @receiver
+ end
+
+ it "raises an error when the name is invalid" do
+ expect {
+ @session.receiver @name.reverse
+ }.to raise_error(Qpid::Messaging::KeyError)
+ end
+
+ end
+
+ it "closes the session" do
+ @session_impl.should_receive(:close)
+
+ @session.close
+ end
+
+ it "commits a pending transaction" do
+ @session_impl.should_receive(:commit)
+
+ @session.commit
+ end
+
+ it "rolls back an uncommitted transaction" do
+ @session_impl.should_receive(:rollback)
+
+ @session.rollback
+ end
+
+ it "acknowledges all received messages" do
+ @session_impl.should_receive(:acknowledge).
+ with(false)
+
+ @session.acknowledge
+ end
+
+ it "acknowledges all messages synchronously" do
+ @session_impl.should_receive(:acknowledge).
+ with(true)
+
+ @session.acknowledge :sync => true
+ end
+
+ it "acknowledges all messages asynchronously" do
+ @session_impl.should_receive(:acknowledge).
+ with(false)
+
+ @session.acknowledge :sync => false
+ end
+
+ ######################################
+ # Scenarios involving a single message
+ ######################################
+ describe "with a single message" do
+
+ before(:each) do
+ @message = Qpid::Messaging::Message.new :content => "Testing"
+ end
+
+ it "can acknowledge asynchronously by default" do
+ @session_impl.should_receive(:acknowledge).
+ with(@message.message_impl, false)
+
+ @session.acknowledge :message => @message
+ end
+
+ it "can acknowledge synchronously" do
+ @session_impl.should_receive(:acknowledge).
+ with(@message.message_impl, true)
+
+ @session.acknowledge :message => @message, :sync => true
+ end
+
+ it "can acknowledge asynchronously" do
+ @session_impl.should_receive(:acknowledge).
+ with(@message.message_impl, false)
+
+ @session.acknowledge :message => @message, :sync => false
+ end
+
+ it "can reject it" do
+ @session_impl.should_receive(:reject).
+ with(@message.message_impl)
+
+ @session.reject @message
+ end
+
+ it "can release it" do
+ @session_impl.should_receive(:release).
+ with(@message.message_impl)
+
+ @session.release @message
+ end
+
+ end
+
+ it "does not block by default when synchronizating with the broker" do
+ @session_impl.should_receive(:sync).
+ with(false)
+
+ @session.sync
+ end
+
+ it "can block while synchronizing with the broker" do
+ @session_impl.should_receive(:sync).
+ with(true)
+
+ @session.sync :block => true
+ end
+
+ it "can not block while synchronizing with the broker" do
+ @session_impl.should_receive(:sync).
+ with(false)
+
+ @session.sync :block => false
+ end
+
+ it "returns the number of messages that are receivable" do
+ @session_impl.should_receive(:getReceivable).
+ and_return(15)
+
+ receivable = @session.receivable
+
+ receivable.should == 15
+ end
+
+ it "returns the number of unsettled messages" do
+ @session_impl.should_receive(:getUnsettledAcks).
+ and_return(25)
+
+ unsettled = @session.unsettled_acks
+
+ unsettled.should == 25
+ end
+
+ it "waits forever by default for the next Receiver with messages" do
+ @session_impl.should_receive(:nextReceiver).
+ with(Qpid::Messaging::Duration::FOREVER.duration_impl).
+ and_return(@receiver_impl)
+
+ receiver = @session.next_receiver
+
+ receiver.receiver_impl.should == @receiver_impl
+ end
+
+ it "uses the specified time when waiting for the next Receiver with messages" do
+ @session_impl.should_receive(:nextReceiver).
+ with(Qpid::Messaging::Duration::SECOND.duration_impl).
+ and_return(@receiver_impl)
+
+ receiver = @session.next_receiver Qpid::Messaging::Duration::SECOND
+
+ receiver.receiver_impl.should == @receiver_impl
+ end
+
+ it "returns nil when no Receiver has messages within the timeout period" do
+ @session_impl.should_receive(:nextReceiver).
+ with(Qpid::Messaging::Duration::MINUTE.duration_impl).
+ and_return(nil)
+
+ receiver = @session.next_receiver Qpid::Messaging::Duration::MINUTE
+
+ receiver.should be_nil
+ end
+
+ it "returns true when there are errors on the session" do
+ @session_impl.should_receive(:hasError).
+ and_return(true)
+
+ errors = @session.errors?
+
+ errors.should be_true
+ end
+
+ it "returns false when there are no errors on the session" do
+ @session_impl.should_receive(:hasError).
+ and_return(false)
+
+ errors = @session.errors?
+
+ errors.should be_false
+ end
+
+ it "causes exceptions to be raised when there are errors" do
+ @session_impl.should_receive(:checkError).
+ and_raise(RuntimeError)
+
+ expect {
+ @session.errors
+ }.to raise_error(RuntimeError)
+ end
+
+ end
+
+ end
+
+end
diff --git a/cpp/bindings/qpid/ruby/spec/spec_helper.rb b/cpp/bindings/qpid/ruby/spec/spec_helper.rb
index 90084963f4..865e60e0e2 100644
--- a/cpp/bindings/qpid/ruby/spec/spec_helper.rb
+++ b/cpp/bindings/qpid/ruby/spec/spec_helper.rb
@@ -17,5 +17,4 @@
# under the License.
#
-require 'qpid'
-require 'cqpid'
+require 'qpid_messaging'
diff --git a/cpp/bindings/swig_perl_typemaps.i b/cpp/bindings/swig_perl_typemaps.i
deleted file mode 100644
index 831576a7d4..0000000000
--- a/cpp/bindings/swig_perl_typemaps.i
+++ /dev/null
@@ -1,330 +0,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.
- */
-
-%wrapper %{
-
-#include <stdarg.h>
-
- SV* MapToPerl(const qpid::types::Variant::Map*);
- SV* ListToPerl(const qpid::types::Variant::List*);
- void PerlToMap(SV*, qpid::types::Variant::Map*);
- void PerlToList(SV*, qpid::types::Variant::List*);
-
- qpid::types::Variant PerlToVariant(SV* value) {
- if (SvROK(value)) {
- if (SvTYPE(SvRV(value)) == SVt_PVHV) {
- qpid::types::Variant::Map map;
- PerlToMap(value, &map);
- return qpid::types::Variant(map);
- }
- else if (SvTYPE(SvRV(value)) == SVt_PVAV) {
- qpid::types::Variant::List list;
- PerlToList(value, &list);
- return qpid::types::Variant(list);
- }
- }
- else {
- if (SvIOK(value)) {
- return qpid::types::Variant((int64_t) SvIV(value));
- }
- else if (SvNOK(value)) {
- return qpid::types::Variant((float)SvNV(value));
- }
- else if (SvPOK(value)) {
- return qpid::types::Variant(std::string(SvPV_nolen(value)));
- }
- }
- return qpid::types::Variant();
- }
-
- SV* VariantToPerl(const qpid::types::Variant* v) {
- SV* result = newSV(0);
- try {
- switch (v->getType()) {
- case qpid::types::VAR_VOID: {
- sv_setiv(result, (IV)0);
- break;
- }
- case qpid::types::VAR_BOOL : {
- result = boolSV(v->asBool());
- break;
- }
- case qpid::types::VAR_UINT8 :
- case qpid::types::VAR_UINT16 :
- case qpid::types::VAR_UINT32 : {
- sv_setuv(result, (UV)v->asUint32());
- break;
- }
- case qpid::types::VAR_UINT64 : {
- sv_setuv(result, (UV)v->asUint64());
- break;
- }
- case qpid::types::VAR_INT8 :
- case qpid::types::VAR_INT16 :
- case qpid::types::VAR_INT32 : {
- sv_setiv(result, (IV)v->asInt32());
- break;
- }
- case qpid::types::VAR_INT64 : {
- sv_setiv(result, (IV)v->asInt64());
- break;
- }
- case qpid::types::VAR_FLOAT : {
- sv_setnv(result, (double)v->asFloat());
- break;
- }
- case qpid::types::VAR_DOUBLE : {
- sv_setnv(result, (double)v->asDouble());
- break;
- }
- case qpid::types::VAR_STRING : {
- const std::string val(v->asString());
- result = newSVpvn(val.c_str(), val.size());
- break;
- }
- case qpid::types::VAR_MAP : {
- result = MapToPerl(&(v->asMap()));
- break;
- }
- case qpid::types::VAR_LIST : {
- result = ListToPerl(&(v->asList()));
- break;
- }
- case qpid::types::VAR_UUID : {
- }
- }
- } catch (qpid::types::Exception& ex) {
- Perl_croak(aTHX_ ex.what());
- }
-
- return result;
- }
-
- SV* MapToPerl(const qpid::types::Variant::Map* map) {
- SV *result = newSV(0);
- HV *hv = (HV *)sv_2mortal((SV *)newHV());
- qpid::types::Variant::Map::const_iterator iter;
- for (iter = map->begin(); iter != map->end(); iter++) {
- const std::string key(iter->first);
- SV* perlval = VariantToPerl(&(iter->second));
- hv_store(hv, key.c_str(), key.size(), perlval, 0);
- }
- SvSetSV(result, newRV_noinc((SV *)hv));
- return result;
- }
-
- SV* ListToPerl(const qpid::types::Variant::List* list) {
- SV* result = newSV(0);
- AV* av = (AV *)sv_2mortal((SV *)newAV());
- qpid::types::Variant::List::const_iterator iter;
- for (iter = list->begin(); iter != list->end(); iter++) {
- SV* perlval = VariantToPerl(&(*iter));
- av_push(av, perlval);
- }
- SvSetSV(result, newRV_noinc((SV *)av));
- return result;
- }
-
- void PerlToMap(SV* hash, qpid::types::Variant::Map* map) {
- map->clear();
- HV* hv = (HV *)SvRV(hash);
- HE* he;
- while((he = hv_iternext(hv)) != NULL) {
- SV* svkey = HeSVKEY_force(he);
- SV* svval = HeVAL(he);
- (*map)[std::string(SvPV_nolen(svkey))] = PerlToVariant(svval);
- }
- }
-
- void PerlToList(SV* ary, qpid::types::Variant::List* list) {
- list->clear();
- AV * av = (AV *)SvRV(ary);
- I32 len = av_len(av) + 1;
- if (len > 0) {
- for (I32 i = 0; i < len; i++) {
- list->push_back(PerlToVariant(*av_fetch(av, i, 0)));
- }
- }
- }
-%}
-
-%typemap (in) void * {
- $1 = (void *)SvIV($input);
-}
-
-%typemap (out) void * {
- sv_setiv($result, (IV)$1);
- argvi++;
-}
-
-%typemap (in) uint16_t, uint32_t, uint64_t {
- if (SvIOK($input)) {
- $1 = ($1_ltype)SvUV($input);
- }
- else {
- SWIG_exception_fail(SWIG_ValueError, "not an integer");
- }
-}
-
-%typemap (out) uint16_t, uint32_t, uint64_t {
- sv_setuv($result, (UV)$1);
- argvi++;
-}
-
-%typemap (in) int32_t, int64_t {
- if (SvIOK($input)) {
- $1 = ($1_ltype)SvIV($input);
- }
- else {
- SWIG_exception_fail(SWIG_ValueError, "not an integer");
- }
-}
-
-%typemap (out) int32_t, int64_t {
- sv_setiv($result, (IV)$1);
- argvi++;
-}
-
-%typemap(in) bool {
- $1 = (bool)SvTRUE($input);
-}
-
-%typemap (out) bool {
- $result = boolSV($1);
- argvi++;
-}
-
-
-%typemap (typecheck, precedence=SWIG_TYPECHECK_UINT64) uint64_t {
- $1 = SvIOK($input) ? 1 : 0;
-}
-
-%typemap (typecheck, precedence=SWIG_TYPECHECK_UINT32) uint32_t {
- $1 = SvIOK($input) ? 1 : 0;
-}
-
-
-/*
- * Variant types: C++ --> Perl
- */
-%typemap(out) qpid::types::Variant::Map {
- $result = MapToPerl(&$1);
- argvi++;
-}
-
-%typemap(out) qpid::types::Variant::Map& {
- $result = MapToPerl($1);
- argvi++;
-}
-
-%typemap(out) qpid::types::Variant::List {
- $result = ListToPerl(&$1);
- argvi++;
-}
-
-%typemap(out) qpid::types::Variant::List& {
- $result = ListToPerl($1);
- argvi++;
-}
-
-%typemap(out) qpid::types::Variant& {
- $result = VariantToPerl($1);
- argvi++;
-}
-
-
-/*
- * Variant types: Perl --> C++
- */
-%typemap(in) qpid::types::Variant& {
- $1 = new qpid::types::Variant(PerlToVariant($input));
-}
-
-%typemap(in) qpid::types::Variant::Map& {
- $1 = new qpid::types::Variant::Map();
- PerlToMap($input, $1);
-
-}
-
-%typemap(in) qpid::types::Variant::List& {
- $1 = new qpid::types::Variant::List();
- PerlToList($input, $1);
-
-}
-
-%typemap(in) const qpid::types::Variant::Map const & {
- $1 = new qpid::types::Variant::Map();
- PerlToMap($input, $1);
-}
-
-%typemap(in) const qpid::types::Variant::List const & {
- $1 = new qpid::types::Variant::List();
- PerlToList($input, $1);
-}
-
-%typemap(freearg) qpid::types::Variant& {
- delete $1;
-}
-
-%typemap(freearg) qpid::types::Variant::Map& {
- delete $1;
-}
-
-%typemap(freearg) qpid::types::Variant::List& {
- delete $1;
-}
-
-
-/*
- * Variant types: typecheck maps
- */
-%typemap(typecheck) qpid::types::Variant::Map& {
- $1 = (SvTYPE(SvRV($input)) == SVt_PVHV) ? 1 : 0;
-}
-
-%typemap(typecheck) qpid::types::Variant::List& {
- $1 = (SvTYPE(SvRV($input)) == SVt_PVAV) ? 1 : 0;
-}
-
-%typemap(typecheck) qpid::types::Variant& {
- $1 = (SvIOK($input) ||
- SvNOK($input) ||
- SvPOK($input) ) ? 1 : 0;
-}
-
-%typemap(typecheck) const qpid::types::Variant::Map const & {
- $1 = (SvTYPE(SvRV($input)) == SVt_PVHV) ? 1 : 0;
-}
-
-%typemap(typecheck) const qpid::types::Variant::List const & {
- $1 = (SvTYPE(SvRV($input)) == SVt_PVAV) ? 1 : 0;
-}
-
-%typemap(typecheck) const qpid::types::Variant const & {
- $1 = (SvIOK($input) ||
- SvNOK($input) ||
- SvPOK($input) ) ? 1 : 0;
-}
-
-/* No boolean type for perl.
- Boolean is simply and integer in perl
-*/
-%typecheck(SWIG_TYPECHECK_BOOL) bool {
- $1 = (SvIOK($input)) ? 1 : 0;
-}
diff --git a/cpp/bld-winsdk.ps1 b/cpp/bld-winsdk.ps1
index 1cae658675..eac771f707 100644
--- a/cpp/bld-winsdk.ps1
+++ b/cpp/bld-winsdk.ps1
@@ -245,13 +245,7 @@ function BuildAPlatform
'bin/boost_regex*.*',
'bin/boost',
'conf',
- 'examples/direct',
- 'examples/failover',
- 'examples/fanout',
- 'examples/pub-sub',
'examples/qmf-console',
- 'examples/request-response',
- 'examples/tradedemo',
'examples/*.sln',
'examples/*.vcproj',
'examples/messaging/*.vcproj',
diff --git a/cpp/configure.ac b/cpp/configure.ac
index c4e55f90de..f3681073fd 100644
--- a/cpp/configure.ac
+++ b/cpp/configure.ac
@@ -29,6 +29,10 @@ AC_PROG_CXX
AC_USE_SYSTEM_EXTENSIONS
AC_LANG([C++])
+# Check whether a C++ was found (AC_PROG_CXX sets $CXX to "g++" even when it
+# doesn't exist)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],[],[AC_MSG_ERROR([No C++ compiler found])])
+
# Check for optional use of help2man
AC_CHECK_PROG([HELP2MAN], [help2man], [help2man])
AC_ARG_WITH([help2man],
@@ -146,7 +150,7 @@ AM_CONDITIONAL([HAS_RPMLINT], [test -n "$RPMLINT"])
AC_CHECK_PROG([RUBY], [ruby], [ruby])
# Swig binding generator is needed for the script (Ruby, Python, etc.) bindings.
-AC_PROG_SWIG(1.3.26)
+AC_PROG_SWIG(1.3.32)
test ! -x "$SWIG" && SWIG=""
AC_ARG_WITH([swig],
[AS_HELP_STRING([--with-swig], [Use swig to generate qmf bindings.])],
@@ -210,10 +214,11 @@ AS_IF([test -n "$PYTHON"], [
# location
AC_MSG_WARN([Didn't find Python 2.7 developer libs - looking for older version])
PYTHON_INC=$($PYTHON -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_inc()')
- AC_CHECK_LIB([python$PYTHON_VERSION],[Py_Initialize])
+ AC_CHECK_LIB([python$PYTHON_VERSION],[Py_Initialize],[
+ PYTHON_LIBS="-lpython$PYTHON_VERSION"
+ ])
AC_CHECK_FILE(["$PYTHON_INC/Python.h"],[
PYTHON_CFLAGS="-I$PYTHON_INC"
- PYTHON_LIBS="-lpython$PYTHON_VERSION"
have_python_dev=yes
],[
if test yes = "$with_python" ; then
@@ -296,6 +301,15 @@ AS_IF([test "x$WANT_SASL" != xno],
AM_CONDITIONAL([HAVE_SASL], [test "x$have_sasl" = xyes])
AC_SUBST([SASL_PASSWD])
+# Allow integration against external AMQP 1.0 protocol engine
+AC_ARG_WITH([proton], AS_HELP_STRING([--with-proton], [Build with the proton toolkit for AMQP 1.0 support]))
+
+AS_IF([test "x$with_proton" = "xyes"], [
+ PKG_CHECK_MODULES([PROTON], [libqpid-proton])
+])
+AM_CONDITIONAL([HAVE_PROTON], [test "x$with_proton" = "xyes"])
+
+
# Setup --with-xml/--without-xml as arguments to configure
use_xml=yes
want_xml=check
@@ -525,7 +539,6 @@ AC_CONFIG_FILES([
managementgen/Makefile
etc/Makefile
src/Makefile
- src/tests/cpg_check.sh
src/tests/Makefile
src/tests/test_env.sh
src/tests/install_env.sh
diff --git a/cpp/design_docs/broker-acl-work.txt b/cpp/design_docs/broker-acl-work.txt
new file mode 100644
index 0000000000..e89e446a56
--- /dev/null
+++ b/cpp/design_docs/broker-acl-work.txt
@@ -0,0 +1,152 @@
+-*-org-*-
+# 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.
+
+The broker is accumulating ACL features and additions. This document describes the features and some of the strategies and decisions made along the way.
+
+These changes are not coordinated with the Java Broker.
+
+Queue Limit Property Settings
+=============================
+
+Customer Goal: Prevent users from making queues too small or too big
+in memory and on disk.
+
+* Add property limit settings to CREATE QUEUE Acl rules.
+
+User Option Acl Limit Property Units
+--------------- ---------------------- ---------------
+qpid.max_size queuemaxsizelowerlimit bytes
+ queuemaxsizeupperlimit bytes
+qpid.max_count queuemaxcountlowerlimit messages
+ queuemaxcountupperlimit messages
+qpid.file_size filemaxsizelowerlimit pages (64Kb per page)
+ filemaxsizeupperlimit pages (64Kb per page)
+qpid.file_count filemaxcountlowerlimit files
+ filemaxcountupperlimit files
+
+
+* Change rule match behavior to accomodate limit settings
+
+** Normal properties upon seeing a mismatch cause the Acl rule processor to go on to the next rule. Property limit settings do not cause a rule mismatch.
+** When property limit checks are violated the effect is to demote an allow rule into a deny rule. Property limit checks are ignored in deny rules.
+
+Routingkey Wildcard Match
+=========================
+
+Customer Goal: Allow users to bind, unbind, access, and publish with wildcards in the routingkey property. A single trailing * wildcard match is insufficient.
+
+* Acl rule processing uses the broker's topic exchange match logic when matching any exchange rule with a "routingkey" property.
+
+* Acl rule writers get to use the same rich matching logic that the broker uses when, for instance, it decides which topic exchange binding keys satisfy an incoming message's routing key.
+
+User Name and Domain Name Symbol Substitution
+=============================================
+
+Customer Goal: Create rules that allow users to access resources only when the user's name is embedded in the resource name.
+
+* The Acl rule processor defines keywords which are substituted with the user's user and domain name.
+
+* User name substitution is allowed in the Acl file anywhere that text is supplied for a property value.
+
+In the following table an authenticated user bob@QPID.COM has his substitution keywords expanded.
+
+| Keyword | Expansion |
+|---------------+--------------|
+| ${userdomain} | bob_QPID_COM |
+| ${user} | bob |
+| ${domain} | QPID_COM |
+
+* User names are normalized by changing asterisk '*' and period '.' to underscores. This allows substitution to work with routingkey specfications.
+
+* The Acl processor matches ${userdomain} before matching either ${user} or ${domain}. Rules that specify ${user}_${domain} will never match.
+
+Resource Quotas
+===============
+
+The Acl module provides broker command line switches to limit users' access to queues and connections.
+
+| Command Line Option | Specified Quota | Default |
+|------------------------------+--------------------------+---------|
+| --max-connections-per-user N | connections by user name | 0 |
+| --max-connections-per-IP N | connections by host name | 0 |
+| --max-queues-per-user N | queues by user name | 0 |
+
+* Allowed values for N are 0..65535
+
+* An option value of zero (0) disables that limit check.
+
+* Connections per-user are counted using the authenticated user name. The user may be logged in from any location but resource counts are aggregated under the user's name.
+
+* Connections per-IP are identified by the <broker-ip><broker-port>-<client-ip><client-port> tuple. This is the same string used by broker management to index connections.
+
+** With this scheme hosts may be identified by several names such as localhost, 127.0.0.1, or ::1. A separate counted set of connections is allowed for each name.
+
+** Connections per-ip are counted regardless of the credentials provided with each connection. A user may be allowed 20 connections but if the per-ip limit is 5 then that user may connect from any single host only five times.
+
+Acl Management Interface
+========================
+
+* Acl Lookup Query Methods
+
+The Acl module provides two QMF management methods that allow users to query the Acl authorization interface.
+
+ Method: Lookup
+ Argument Type Direction Unit Description
+ ========================================================
+ userId long-string I
+ action long-string I
+ object long-string I
+ objectName long-string I
+ propertyMap field-table I
+ result long-string O
+
+ Method: LookupPublish
+ Argument Type Direction Unit Description
+ =========================================================
+ userId long-string I
+ exchangeName long-string I
+ routingKey long-string I
+ result long-string O
+
+The Lookup method is a general query for any action, object, and set of properties.
+The LookupPublish method is the optimized, per-message fastpath query.
+
+In both methods the result is one of: allow, deny, allow-log, or deny-log.
+
+Example:
+
+The upstream Jira https://issues.apache.org/jira/browse/QPID-3918 has several attachment files that demonstrate how to use the query feature.
+
+ acl-test-01.rules.acl is the Acl file to run in the qpidd broker.
+ acl-test-01.py is the test script that queries the Acl.
+ acl-test-01.log is what the console prints when the test script runs.
+
+The script performs 355 queries using the Acl Lookup query methods.
+
+* Management Properties and Statistics
+
+The following properties and statistics have been added to reflect command line settings in effect and Acl quota denial activity.
+
+Element Type Access Unit Notes Description
+==================================================================================================
+maxConnections uint16 ReadOnly Maximum allowed connections
+maxConnectionsPerIp uint16 ReadOnly Maximum allowed connections
+maxConnectionsPerUser uint16 ReadOnly Maximum allowed connections
+maxQueuesPerUser uint16 ReadOnly Maximum allowed queues
+connectionDenyCount uint64 Number of connections denied
+queueQuotaDenyCount uint64 Number of queue creations denied
diff --git a/cpp/design_docs/new-ha-design.txt b/cpp/design_docs/new-ha-design.txt
index acca1720b4..df6c7242eb 100644
--- a/cpp/design_docs/new-ha-design.txt
+++ b/cpp/design_docs/new-ha-design.txt
@@ -84,12 +84,6 @@ retry on a single address to fail over. Alternatively we will also
support configuring a fixed list of broker addresses when qpid is run
outside of a resource manager.
-Aside: Cold-standby is also possible using rgmanager with shared
-storage for the message store (e.g. GFS). If the broker fails, another
-broker is started on a different node and and recovers from the
-store. This bears investigation but the store recovery times are
-likely too long for failover.
-
** Replicating configuration
New queues and exchanges and their bindings also need to be replicated.
@@ -109,13 +103,9 @@ configuration.
Explicit exchange/queue qpid.replicate argument:
- none: the object is not replicated
- configuration: queues, exchanges and bindings are replicated but messages are not.
-- messages: configuration and messages are replicated.
-
-TODO: provide configurable default for qpid.replicate
+- all: configuration and messages are replicated.
-[GRS: current prototype relies on queue sequence for message identity
-so selectively replicating certain messages on a given queue would be
-challenging. Selectively replicating certain queues however is trivial.]
+Set configurable default all/configuration/none
** Inconsistent errors
@@ -125,12 +115,13 @@ eliminates the need to stall the whole cluster till an error is
resolved. We still have to handle inconsistent store errors when store
and cluster are used together.
-We have 2 options (configurable) for handling inconsistent errors,
+We have 3 options (configurable) for handling inconsistent errors,
on the backup that fails to store a message from primary we can:
- Abort the backup broker allowing it to be re-started.
- Raise a critical error on the backup broker but carry on with the message lost.
-We can configure the option to abort or carry on per-queue, we
-will also provide a broker-wide configurable default.
+- Reset and re-try replication for just the affected queue.
+
+We will provide some configurable options in this regard.
** New backups connecting to primary.
@@ -156,8 +147,8 @@ In backup mode, brokers reject connections normal client connections
so clients will fail over to the primary. HA admin tools mark their
connections so they are allowed to connect to backup brokers.
-Clients discover the primary by re-trying connection to the client URL
-until the successfully connect to the primary. In the case of a
+Clients discover the primary by re-trying connection to all addresses in the client URL
+until they successfully connect to the primary. In the case of a
virtual IP they re-try the same address until it is relocated to the
primary. In the case of a list of IPs the client tries each in
turn. Clients do multiple retries over a configured period of time
@@ -168,12 +159,6 @@ is a separate broker URL for brokers since they often will connect
over a different network. The broker URL has to be a list of real
addresses rather than a virtual address.
-Brokers have the following states:
-- connecting: Backup broker trying to connect to primary - loops retrying broker URL.
-- catchup: Backup connected to primary, catching up on pre-existing configuration & messages.
-- ready: Backup fully caught-up, ready to take over as primary.
-- primary: Acting as primary, serving clients.
-
** Interaction with rgmanager
rgmanager interacts with qpid via 2 service scripts: backup &
@@ -190,8 +175,8 @@ the primary state. Backups discover the primary, connect and catch up.
*** Failover
-primary broker or node fails. Backup brokers see disconnect and go
-back to connecting mode.
+primary broker or node fails. Backup brokers see the disconnect and
+start trying to re-connect to the new primary.
rgmanager notices the failure and starts the primary service on a new node.
This tells qpidd to go to primary mode. Backups re-connect and catch up.
@@ -225,71 +210,30 @@ to become a ready backup.
** Interaction with the store.
-Clean shutdown: entire cluster is shut down cleanly by an admin tool:
-- primary stops accepting client connections till shutdown is complete.
-- backups come fully up to speed with primary state.
-- all shut down marking stores as 'clean' with an identifying UUID.
-
-After clean shutdown the cluster can re-start automatically as all nodes
-have equivalent stores. Stores starting up with the wrong UUID will fail.
-
-Stored status: clean(UUID)/dirty, primary/backup, generation number.
-- All stores are marked dirty except after a clean shutdown.
-- Generation number: passed to backups and incremented by new primary.
-
-After total crash must manually identify the "best" store, provide admin tool.
-Best = highest generation number among stores in primary state.
-
-Recovering from total crash: all brokers will refuse to start as all stores are dirty.
-Check the stores manually to find the best one, then either:
-1. Copy stores:
- - copy good store to all hosts
- - restart qpidd on all hosts.
-2. Erase stores:
- - Erase the store on all other hosts.
- - Restart qpidd on the good store and wait for it to become primary.
- - Restart qpidd on all other hosts.
-
-Broker startup with store:
-- Dirty: refuse to start
-- Clean:
- - Start and load from store.
- - When connecting as backup, check UUID matches primary, shut down if not.
-- Empty: start ok, no UUID check with primary.
+Needs more detail:
-* Current Limitations
+We want backup brokers to be able to user their stored messages on restart
+so they don't have to download everything from priamary.
+This requires a HA sequence number to be stored with the message
+so the backup can identify which messages are in common with the primary.
-(In no particular order at present)
+This will work very similarly to the way live backups can use in-memory
+messages to reduce the download.
-For message replication:
+Need to determine which broker is chosen as initial primary based on currency of
+stores. Probably using stored generation numbers and status flags. Ideally
+automated with rgmanager, or some intervention might be reqiured.
-LM1a - On failover, backups delete their queues and download the full queue state from the
-primary. There was code to use messags already on the backup for re-synchronisation, it
-was removed in early development (r1214490) to simplify the logic while getting basic
-replication working. It needs to be re-introduced.
+* Current Limitations
-LM1b - This re-synchronisation does not handle the case where a newly elected primary is *behind*
-one of the other backups. To address this I propose a new event for restting the sequence
-that the new primary would send out on detecting that a replicating browser is ahead of
-it, requesting that the replica revert back to a particular sequence number. The replica
-on receiving this event would then discard (i.e. dequeue) all the messages ahead of that
-sequence number and reset the counter to correctly sequence any subsequently delivered
-messages.
+(In no particular order at present)
-LM2 - There is a need to handle wrap-around of the message sequence to avoid
-confusing the resynchronisation where a replica has been disconnected
-for a long time, sufficient for the sequence numbering to wrap around.
+For message replication (missing items have been fixed)
LM3 - Transactional changes to queue state are not replicated atomically.
-LM4 - Acknowledgements are confirmed to clients before the message has been
-dequeued from replicas or indeed from the local store if that is
-asynchronous.
-
-LM5 - During failover, messages (re)published to a queue before there are
-the requisite number of replication subscriptions established will be
-confirmed to the publisher before they are replicated, leaving them
-vulnerable to a loss of the new primary before they are replicated.
+LM4 - (No worse than store) Acknowledgements are confirmed to clients before the message
+has been dequeued from replicas or indeed from the local store if that is asynchronous.
LM6 - persistence: In the event of a total cluster failure there are
no tools to automatically identify the "latest" store.
@@ -323,21 +267,11 @@ case (b) can be addressed in a simple manner through tooling but case
(c) would require changes to the broker to allow client to simply
determine when the command has fully propagated.
-LC3 - Queues that are not in the query response received when a
-replica establishes a propagation subscription but exist locally are
-not deleted. I.e. Deletion of queues/exchanges while a replica is not
-connected will not be propagated. Solution is to delete any queues
-marked for propagation that exist locally but do not show up in the
-query response.
-
LC4 - It is possible on failover that the new primary did not
previously receive a given QMF event while a backup did (sort of an
analogous situation to LM1 but without an easy way to detect or remedy
it).
-LC5 - Need richer control over which queues/exchanges are propagated, and
-which are not.
-
LC6 - The events and query responses are not fully synchronized.
In particular it *is* possible to not receive a delete event but
@@ -356,12 +290,11 @@ LC6 - The events and query responses are not fully synchronized.
LC7 Federated links from the primary will be lost in failover, they will not be re-connected on
the new primary. Federation links to the primary can fail over.
-LC8 Only plain FIFO queues can be replicated. LVQs and ring queues are not yet supported.
-
LC9 The "last man standing" feature of the old cluster is not available.
* Benefits compared to previous cluster implementation.
+- Allows per queue/exchange control over what is replicated.
- Does not depend on openais/corosync, does not require multicast.
- Can be integrated with different resource managers: for example rgmanager, PaceMaker, Veritas.
- Can be ported to/implemented in other environments: e.g. Java, Windows
diff --git a/cpp/docs/api/CMakeLists.txt b/cpp/docs/api/CMakeLists.txt
index 21e6f51caf..828d706b91 100644
--- a/cpp/docs/api/CMakeLists.txt
+++ b/cpp/docs/api/CMakeLists.txt
@@ -30,11 +30,13 @@ if (GEN_DOXYGEN)
${CMAKE_CURRENT_BINARY_DIR}/developer.doxygen)
add_custom_target (docs-user-api COMMAND ${DOXYGEN_EXECUTABLE} user.doxygen)
add_custom_target (docs-developer COMMAND ${DOXYGEN_EXECUTABLE} developer.doxygen)
+ add_dependencies (docs docs-developer docs-user-api)
# HTML files are generated to ./html - put those in the install.
install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/
- DESTINATION ${QPID_INSTALL_HTMLDIR}
- COMPONENT ${QPID_COMPONENT_CLIENT_INCLUDE})
+ DESTINATION ${QPID_INSTALL_DOCDIR}/api/html
+ COMPONENT ${QPID_COMPONENT_CLIENT_INCLUDE}
+ ${OPTIONAL_ARG})
if (CPACK_GENERATOR STREQUAL "NSIS")
set (CPACK_NSIS_MENU_LINKS
"${QPID_INSTALL_HTMLDIR}/index.html" "Qpid C++ API Documentation"
diff --git a/cpp/etc/qpidd-primary.in b/cpp/etc/qpidd-primary.in
index 39700bead3..da0c0c2771 100755
--- a/cpp/etc/qpidd-primary.in
+++ b/cpp/etc/qpidd-primary.in
@@ -57,7 +57,7 @@ if [[ !(-x $QPID_HA) ]]; then
fi
status() {
- if $QPID_HA -b localhost:$QPID_PORT status --expect=primary ; then
+ if $QPID_HA -b localhost:$QPID_PORT status --is-primary ; then
echo "qpidd is primary"
else
echo "qpidd is not primary"
diff --git a/cpp/etc/sasl2/qpidd.conf b/cpp/etc/sasl2/qpidd.conf
index 0872bc251b..3d13a6d650 100644
--- a/cpp/etc/sasl2/qpidd.conf
+++ b/cpp/etc/sasl2/qpidd.conf
@@ -18,33 +18,31 @@
#
#
#---------------------------------
-# Mechanisms and Users
+# SASL Mechanisms and Users
#---------------------------------
#
-# This default qpidd configuration allows for only SASL ANONYMOUS authentication.
-# To additionally enable DIGEST-MD5 authentication:
-#
-# 1. edit the mech_list below to read
-# mech_list: DIGEST-MD5 ANONYMOUS
-#
-# 2. To add new a new user+password to the sasldb file:
-# echo $PASSWD | saslpasswd2 -c -p -f $SASLTEST_DB -u QPID $USERNAME
+# This default mech list allows for PLAIN, but that
+# mechanism sends credentials in the clear, and is normally
+# only used along with SSL transport-layer security.
#
+# This default also permits DIGEST-MD5, but you must have
+# a user and password defined in your sasldb file to use
+# this mechanism. ( See notes below. )
#
# PLEASE NOTE
# For production messaging systems, a high-security mechanism such as
-# DIGEST-MD5 or PLAIN+SSL should be enabled.
+# DIGEST-MD5 or PLAIN+SSL should be used.
#
#
pwcheck_method: auxprop
auxprop_plugin: sasldb
sasldb_path: /var/lib/qpidd/qpidd.sasldb
-mech_list: ANONYMOUS
+mech_list: ANONYMOUS DIGEST-MD5 EXTERNAL PLAIN
#---------------------------------
-# Other Notes
+# Please Note
#---------------------------------
#
# 1. If you use a nonstandard location for your sasl_config directory,
@@ -60,15 +58,19 @@ mech_list: ANONYMOUS
# /var/lib/qpidd/qpidd.sasldb
#
# 3. You can see what usernames have been stored in the sasldb, with the
-# sasldblistusers2 command.
+# command "sasldblistusers2 -f /var/lib/qpidd/qpidd.sasldb"
#
# 4. The REALM is important and should be the same as the --realm
# option to the broker. This lets the broker properly find the user in
# the sasldb file.
#
# 5. The sasldb file must be readable by the user running the qpidd
-# daemon, and should be readable only by that user.
+# daemon, ( the user name is qpidd ) and should be readable only
+# by that user.
#
+# 6. The EXTERNAL mechanism allows you to use SSL transport layer
+# security. In that case, you can also set the broker option
+# --ssl-require-client-authentication .
diff --git a/cpp/examples/makedist.mk b/cpp/examples/makedist.mk
index c494af5e8f..9a1568d427 100644
--- a/cpp/examples/makedist.mk
+++ b/cpp/examples/makedist.mk
@@ -20,6 +20,7 @@
AM_CXXFLAGS = $(WARNING_CFLAGS)
INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include
CLIENT_LIB=$(top_builddir)/src/libqpidclient.la
+COMMON_LIB=$(top_builddir)/src/libqpidcommon.la
CONSOLE_LIB=$(top_builddir)/src/libqmfconsole.la
CLIENTFLAGS=-lqpidclient
CONSOLEFLAGS=-lqmfconsole
diff --git a/cpp/examples/messaging/CMakeLists.txt b/cpp/examples/messaging/CMakeLists.txt
index 03ed2daaad..25651e525b 100644
--- a/cpp/examples/messaging/CMakeLists.txt
+++ b/cpp/examples/messaging/CMakeLists.txt
@@ -26,9 +26,13 @@ macro(add_messaging_example example)
target_link_libraries(${example} qpidmessaging ${_boost_libs_needed})
# For installs, don't install the built example; that would be pointless.
# Install the things a user needs to build the example on-site.
- install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${example}.cpp ${CMAKE_CURRENT_SOURCE_DIR}/OptionParser.h ${CMAKE_CURRENT_SOURCE_DIR}/OptionParser.cpp
- DESTINATION ${QPID_INSTALL_EXAMPLESDIR}/messaging
- COMPONENT ${QPID_COMPONENT_EXAMPLES})
+ install (FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/${example}.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/OptionParser.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/OptionParser.cpp
+ DESTINATION ${QPID_INSTALL_EXAMPLESDIR}/messaging
+ COMPONENT ${QPID_COMPONENT_EXAMPLES})
+
if (MSVC)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/messaging_${example}.vcproj
DESTINATION ${QPID_INSTALL_EXAMPLESDIR}/messaging
@@ -57,7 +61,19 @@ install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/hello_world.cpp
add_executable(hello_xml hello_xml.cpp)
set_target_properties(hello_xml PROPERTIES OUTPUT_NAME hello_xml)
target_link_libraries(hello_xml qpidmessaging)
-install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/hello_xml.cpp
+
+install (FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/extra_dist/CMakeLists.txt
+ ${CMAKE_CURRENT_SOURCE_DIR}/OptionParser.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/OptionParser.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hello_world.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/hello_xml.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/drain.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/spout.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/map_receiver.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/map_sender.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/client.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/server.cpp
DESTINATION ${QPID_INSTALL_EXAMPLESDIR}/messaging
COMPONENT ${QPID_COMPONENT_EXAMPLES})
diff --git a/cpp/examples/messaging/Makefile.am b/cpp/examples/messaging/Makefile.am
index 298d65e6f1..5fefb37f8a 100644
--- a/cpp/examples/messaging/Makefile.am
+++ b/cpp/examples/messaging/Makefile.am
@@ -22,6 +22,7 @@ examplesdir=$(pkgdatadir)/examples/messaging
AM_CXXFLAGS = $(WARNING_CFLAGS)
INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include
CLIENT_LIB=$(top_builddir)/src/libqpidmessaging.la
+TYPES_LIB=$(top_builddir)/src/libqpidtypes.la
CLIENTFLAGS=-lqpidmessaging
noinst_PROGRAMS=drain spout client server map_sender map_receiver hello_world hello_xml
@@ -33,10 +34,10 @@ hello_xml_SOURCES=hello_xml.cpp
hello_xml_LDADD=$(CLIENT_LIB)
drain_SOURCES=drain.cpp OptionParser.h OptionParser.cpp
-drain_LDADD=$(CLIENT_LIB)
+drain_LDADD=$(CLIENT_LIB) $(TYPES_LIB)
spout_SOURCES=spout.cpp OptionParser.h OptionParser.cpp
-spout_LDADD=$(CLIENT_LIB)
+spout_LDADD=$(CLIENT_LIB) $(TYPES_LIB)
client_SOURCES=client.cpp
client_LDADD=$(CLIENT_LIB)
@@ -45,10 +46,10 @@ server_SOURCES=server.cpp
server_LDADD=$(CLIENT_LIB)
map_sender_SOURCES=map_sender.cpp
-map_sender_LDADD=$(CLIENT_LIB)
+map_sender_LDADD=$(CLIENT_LIB) $(TYPES_LIB)
map_receiver_SOURCES=map_receiver.cpp
-map_receiver_LDADD=$(CLIENT_LIB)
+map_receiver_LDADD=$(CLIENT_LIB) $(TYPES_LIB)
examples_DATA= \
hello_world.cpp \
@@ -61,7 +62,7 @@ examples_DATA= \
server.cpp \
map_sender.cpp \
map_receiver.cpp \
- extra_dist/Makefile
+ extra_dist/CMakeLists.txt
EXTRA_DIST= \
$(examples_DATA) \
diff --git a/cpp/examples/messaging/extra_dist/CMakeLists.txt b/cpp/examples/messaging/extra_dist/CMakeLists.txt
new file mode 100644
index 0000000000..88df55337c
--- /dev/null
+++ b/cpp/examples/messaging/extra_dist/CMakeLists.txt
@@ -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.
+#
+
+cmake_minimum_required (VERSION 2.6)
+
+project (Examples)
+
+# drain and spout have explicit Boost.program_options usage in them, so be
+# sure that lib is linked in.
+
+macro(add_messaging_example example)
+ add_executable(${example} ${example}.cpp OptionParser.cpp)
+ set_target_properties(${example} PROPERTIES OUTPUT_NAME ${example})
+ target_link_libraries(${example} qpidtypes qpidmessaging ${_boost_libs_needed})
+ # For installs, don't install the built example; that would be pointless.
+ # Install the things a user needs to build the example on-site.
+ install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${example}.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/OptionParser.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/OptionParser.cpp
+ DESTINATION ${QPID_INSTALL_EXAMPLESDIR}/messaging
+ COMPONENT ${QPID_COMPONENT_EXAMPLES})
+ if (MSVC)
+ install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/messaging_${example}.vcproj
+ DESTINATION ${QPID_INSTALL_EXAMPLESDIR}/messaging
+ COMPONENT ${QPID_COMPONENT_EXAMPLES})
+ endif (MSVC)
+
+endmacro(add_messaging_example)
+
+add_messaging_example(drain)
+add_messaging_example(spout)
+
+add_messaging_example(map_receiver)
+add_messaging_example(map_sender)
+
+add_messaging_example(client)
+add_messaging_example(server)
+
+# These don't need Boost or OptionParser
+add_executable(hello_world hello_world.cpp)
+set_target_properties(hello_world PROPERTIES OUTPUT_NAME hello_world)
+target_link_libraries(hello_world qpidmessaging)
+
+add_executable(hello_xml hello_xml.cpp)
+set_target_properties(hello_xml PROPERTIES OUTPUT_NAME hello_xml)
+target_link_libraries(hello_xml qpidmessaging)
diff --git a/cpp/examples/messaging/extra_dist/Makefile b/cpp/examples/messaging/extra_dist/Makefile
deleted file mode 100644
index 8dd7f658f7..0000000000
--- a/cpp/examples/messaging/extra_dist/Makefile
+++ /dev/null
@@ -1,30 +0,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.
-#
-CXX=g++
-CXXFLAGS=-g -O2
-LDFLAGS=-lqpidmessaging
-
-all: drain spout client server map_sender map_receiver hello_world
-
-drain: drain.o OptionParser.o
-
-spout: spout.o OptionParser.o
-
-clean:
- rm -f drain spout client server map_sender map_receiver hello_world *.o
diff --git a/cpp/examples/messaging/spout.cpp b/cpp/examples/messaging/spout.cpp
index cd11a7ad81..72fcdc7c65 100644
--- a/cpp/examples/messaging/spout.cpp
+++ b/cpp/examples/messaging/spout.cpp
@@ -91,6 +91,7 @@ struct Options : OptionParser
std::string value;
if (nameval(property, name, value)) {
message.getProperties()[name] = value;
+ message.getProperties()[name].setEncoding("utf8");
} else {
message.getProperties()[name] = Variant();
}
diff --git a/cpp/examples/old_api/direct/Makefile.am b/cpp/examples/old_api/direct/Makefile.am
index 24f783fcc7..18957c84f4 100644
--- a/cpp/examples/old_api/direct/Makefile.am
+++ b/cpp/examples/old_api/direct/Makefile.am
@@ -23,13 +23,13 @@ include $(top_srcdir)/examples/makedist.mk
noinst_PROGRAMS=direct_producer listener declare_queues
direct_producer_SOURCES=direct_producer.cpp
-direct_producer_LDADD=$(CLIENT_LIB)
+direct_producer_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
listener_SOURCES=listener.cpp
-listener_LDADD=$(CLIENT_LIB)
+listener_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
declare_queues_SOURCES=declare_queues.cpp
-declare_queues_LDADD=$(CLIENT_LIB)
+declare_queues_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
examples_DATA= \
direct_producer.cpp \
diff --git a/cpp/examples/old_api/failover/Makefile.am b/cpp/examples/old_api/failover/Makefile.am
index 8b1da80f2c..60e99b9ed6 100644
--- a/cpp/examples/old_api/failover/Makefile.am
+++ b/cpp/examples/old_api/failover/Makefile.am
@@ -24,13 +24,13 @@ include $(top_srcdir)/examples/makedist.mk
noinst_PROGRAMS=declare_queues resuming_receiver replaying_sender
declare_queues_SOURCES=declare_queues.cpp
-declare_queues_LDADD=$(CLIENT_LIB)
+declare_queues_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
resuming_receiver_SOURCES=resuming_receiver.cpp
-resuming_receiver_LDADD=$(CLIENT_LIB)
+resuming_receiver_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
replaying_sender_SOURCES=replaying_sender.cpp
-replaying_sender_LDADD=$(CLIENT_LIB)
+replaying_sender_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
examples_DATA= \
declare_queues.cpp \
diff --git a/cpp/examples/old_api/fanout/Makefile.am b/cpp/examples/old_api/fanout/Makefile.am
index 3ab43b0279..06e84b47b6 100644
--- a/cpp/examples/old_api/fanout/Makefile.am
+++ b/cpp/examples/old_api/fanout/Makefile.am
@@ -26,7 +26,7 @@ fanout_producer_SOURCES=fanout_producer.cpp
fanout_producer_LDADD=$(CLIENT_LIB)
listener_SOURCES=listener.cpp
-listener_LDADD=$(CLIENT_LIB)
+listener_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
examples_DATA= \
fanout_producer.cpp \
diff --git a/cpp/examples/old_api/pub-sub/Makefile.am b/cpp/examples/old_api/pub-sub/Makefile.am
index 8f42ee0211..e8e19e4c32 100644
--- a/cpp/examples/old_api/pub-sub/Makefile.am
+++ b/cpp/examples/old_api/pub-sub/Makefile.am
@@ -24,10 +24,10 @@ include $(top_srcdir)/examples/makedist.mk
noinst_PROGRAMS=topic_listener topic_publisher
topic_listener_SOURCES=topic_listener.cpp
-topic_listener_LDADD=$(CLIENT_LIB)
+topic_listener_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
topic_publisher_SOURCES=topic_publisher.cpp
-topic_publisher_LDADD=$(CLIENT_LIB)
+topic_publisher_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
examples_DATA= \
topic_listener.cpp \
diff --git a/cpp/examples/old_api/request-response/Makefile.am b/cpp/examples/old_api/request-response/Makefile.am
index f48762da51..cf10ae81db 100644
--- a/cpp/examples/old_api/request-response/Makefile.am
+++ b/cpp/examples/old_api/request-response/Makefile.am
@@ -24,10 +24,10 @@ include $(top_srcdir)/examples/makedist.mk
noinst_PROGRAMS=client server
client_SOURCES=client.cpp
-client_LDADD=$(CLIENT_LIB)
+client_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
server_SOURCES=server.cpp
-server_LDADD=$(CLIENT_LIB)
+server_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
examples_DATA= \
server.cpp \
diff --git a/cpp/examples/old_api/tradedemo/Makefile.am b/cpp/examples/old_api/tradedemo/Makefile.am
index 445b15b367..9932d87a6b 100644
--- a/cpp/examples/old_api/tradedemo/Makefile.am
+++ b/cpp/examples/old_api/tradedemo/Makefile.am
@@ -24,13 +24,13 @@ include $(top_srcdir)/examples/makedist.mk
noinst_PROGRAMS=topic_listener topic_publisher declare_queues
topic_listener_SOURCES=topic_listener.cpp
-topic_listener_LDADD=$(CLIENT_LIB)
+topic_listener_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
topic_publisher_SOURCES=topic_publisher.cpp
-topic_publisher_LDADD=$(CLIENT_LIB)
+topic_publisher_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
declare_queues_SOURCES=declare_queues.cpp
-declare_queues_LDADD=$(CLIENT_LIB)
+declare_queues_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
examples_DATA= \
diff --git a/cpp/examples/old_api/xml-exchange/Makefile.am b/cpp/examples/old_api/xml-exchange/Makefile.am
index 3e1082cdb2..d4bc6ba233 100644
--- a/cpp/examples/old_api/xml-exchange/Makefile.am
+++ b/cpp/examples/old_api/xml-exchange/Makefile.am
@@ -24,13 +24,13 @@ include $(top_srcdir)/examples/makedist.mk
noinst_PROGRAMS=declare_queues xml_producer listener
declare_queues_SOURCES=declare_queues.cpp
-declare_queues_LDADD=$(CLIENT_LIB)
+declare_queues_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
xml_producer_SOURCES=xml_producer.cpp
-xml_producer_LDADD=$(CLIENT_LIB)
+xml_producer_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
listener_SOURCES=listener.cpp
-listener_LDADD=$(CLIENT_LIB)
+listener_LDADD=$(CLIENT_LIB) $(COMMON_LIB)
EXTRA_DIST= \
README.txt \
diff --git a/cpp/examples/qmf-console/Makefile.am b/cpp/examples/qmf-console/Makefile.am
index f4cbb7633c..060147e9a4 100644
--- a/cpp/examples/qmf-console/Makefile.am
+++ b/cpp/examples/qmf-console/Makefile.am
@@ -25,19 +25,19 @@ include $(top_srcdir)/examples/makedist.mk
noinst_PROGRAMS=console printevents ping queuestats cluster-qmon
console_SOURCES=console.cpp
-console_LDADD=$(CONSOLE_LIB)
+console_LDADD=$(CONSOLE_LIB) -lqpidcommon -lqpidclient
printevents_SOURCES=printevents.cpp
-printevents_LDADD=$(CONSOLE_LIB)
+printevents_LDADD=$(CONSOLE_LIB) -lqpidcommon -lqpidclient
ping_SOURCES=ping.cpp
-ping_LDADD=$(CONSOLE_LIB)
+ping_LDADD=$(CONSOLE_LIB) -lqpidcommon -lqpidclient
queuestats_SOURCES=queuestats.cpp
-queuestats_LDADD=$(CONSOLE_LIB)
+queuestats_LDADD=$(CONSOLE_LIB) -lqpidcommon -lqpidclient
cluster_qmon_SOURCES=cluster-qmon.cpp
-cluster_qmon_LDADD=$(CONSOLE_LIB)
+cluster_qmon_LDADD=$(CONSOLE_LIB) -lqpidcommon -lqpidclient
examples_DATA= \
console.cpp \
diff --git a/cpp/bindings/qmf2/qmf2.i b/cpp/include/qmf/qmf2.i
index 0f573fe3e6..0f573fe3e6 100644
--- a/cpp/bindings/qmf2/qmf2.i
+++ b/cpp/include/qmf/qmf2.i
diff --git a/cpp/bindings/qmf/qmfengine.i b/cpp/include/qmf/qmfengine.i
index eb350115a3..eb350115a3 100644
--- a/cpp/bindings/qmf/qmfengine.i
+++ b/cpp/include/qmf/qmfengine.i
diff --git a/cpp/include/qpid/Options.h b/cpp/include/qpid/Options.h
index 0bbe7b704f..feef5d8b98 100644
--- a/cpp/include/qpid/Options.h
+++ b/cpp/include/qpid/Options.h
@@ -149,6 +149,11 @@ struct Options : public po::options_description {
const std::string& configfile=std::string(),
bool allowUnknown = false);
+ /**
+ * Tests for presence of argc/argv switch
+ */
+ QPID_COMMON_EXTERN bool findArg(int argc, char const* const* argv,
+ const std::string& theArg);
boost::program_options::options_description_easy_init addOptions() {
return add_options();
diff --git a/cpp/include/qpid/Url.h b/cpp/include/qpid/Url.h
index b3ff9576e2..f9ed87c24b 100644
--- a/cpp/include/qpid/Url.h
+++ b/cpp/include/qpid/Url.h
@@ -32,13 +32,6 @@ namespace qpid {
/** An AMQP URL contains a list of addresses */
struct Url : public std::vector<Address> {
- /** Url with the hostname as returned by gethostname(2) */
- QPID_COMMON_EXTERN static Url getHostNameUrl(uint16_t port);
-
- /** Url with local IP address(es), may be more than one address
- * on a multi-homed host. */
- QPID_COMMON_EXTERN static Url getIpAddressesUrl(uint16_t port);
-
struct Invalid : public Exception { QPID_COMMON_EXTERN Invalid(const std::string& s); };
/** Convert to string form. */
diff --git a/cpp/include/qpid/client/ConnectionSettings.h b/cpp/include/qpid/client/ConnectionSettings.h
index 2b6b86f891..a0c209badf 100644
--- a/cpp/include/qpid/client/ConnectionSettings.h
+++ b/cpp/include/qpid/client/ConnectionSettings.h
@@ -23,6 +23,7 @@
*/
#include "qpid/client/ClientImportExport.h"
+#include "qpid/framing/FieldTable.h"
#include "qpid/sys/IntegerTypes.h"
#include <string>
@@ -127,6 +128,11 @@ struct QPID_CLIENT_CLASS_EXTERN ConnectionSettings {
* settings. Used only when a client connects to the broker.
*/
std::string sslCertName;
+
+ /**
+ * Passed as client-propreties on opening the connecction.
+ */
+ framing::FieldTable clientProperties;
};
}} // namespace qpid::client
diff --git a/cpp/include/qpid/client/FailoverManager.h b/cpp/include/qpid/client/FailoverManager.h
index d3a0dbc976..bc739fd0f5 100644
--- a/cpp/include/qpid/client/FailoverManager.h
+++ b/cpp/include/qpid/client/FailoverManager.h
@@ -87,6 +87,7 @@ class QPID_CLIENT_CLASS_EXTERN FailoverManager
* attempted
*/
QPID_CLIENT_EXTERN FailoverManager(const ConnectionSettings& settings, ReconnectionStrategy* strategy = 0);
+ QPID_CLIENT_EXTERN ~FailoverManager();
/**
* Return the current connection if open or attept to reconnect to
* the specified list of urls. If no list is specified the list of
diff --git a/cpp/include/qpid/framing/FieldValue.h b/cpp/include/qpid/framing/FieldValue.h
index 458de62fdf..e964da495a 100644
--- a/cpp/include/qpid/framing/FieldValue.h
+++ b/cpp/include/qpid/framing/FieldValue.h
@@ -175,11 +175,19 @@ class FixedWidthValue : public FieldValue::Data {
return v;
}
uint8_t* rawOctets() { return octets; }
- uint8_t* rawOctets() const { return octets; }
+ const uint8_t* rawOctets() const { return octets; }
void print(std::ostream& o) const { o << "F" << width << ":"; };
};
+class UuidData : public FixedWidthValue<16> {
+ public:
+ UuidData();
+ UuidData(const unsigned char* bytes);
+ bool convertsToString() const;
+ std::string getString() const;
+};
+
template <class T, int W>
inline T FieldValue::getIntegerValue() const
{
@@ -356,7 +364,7 @@ class Var16Value : public FieldValue {
class Var32Value : public FieldValue {
public:
QPID_COMMON_EXTERN Var32Value(const std::string& v, uint8_t code);
-};
+ };
class Struct32Value : public FieldValue {
public:
@@ -453,6 +461,7 @@ class ListValue : public FieldValue {
class UuidValue : public FieldValue {
public:
+ QPID_COMMON_EXTERN UuidValue();
QPID_COMMON_EXTERN UuidValue(const unsigned char*);
};
diff --git a/cpp/include/qpid/framing/ProtocolVersion.h b/cpp/include/qpid/framing/ProtocolVersion.h
index 26d628e41c..309e543516 100644
--- a/cpp/include/qpid/framing/ProtocolVersion.h
+++ b/cpp/include/qpid/framing/ProtocolVersion.h
@@ -36,21 +36,28 @@ class QPID_COMMON_CLASS_EXTERN ProtocolVersion
private:
uint8_t major_;
uint8_t minor_;
+ uint8_t protocol_;
public:
- explicit ProtocolVersion(uint8_t _major=0, uint8_t _minor=0)
- : major_(_major), minor_(_minor) {}
+ explicit ProtocolVersion(uint8_t _major=0, uint8_t _minor=0, uint8_t _protocol=0)
+ : major_(_major), minor_(_minor), protocol_(_protocol) {}
QPID_COMMON_INLINE_EXTERN uint8_t getMajor() const { return major_; }
QPID_COMMON_INLINE_EXTERN void setMajor(uint8_t major) { major_ = major; }
QPID_COMMON_INLINE_EXTERN uint8_t getMinor() const { return minor_; }
QPID_COMMON_INLINE_EXTERN void setMinor(uint8_t minor) { minor_ = minor; }
+ QPID_COMMON_INLINE_EXTERN uint8_t getProtocol() const { return protocol_; }
+ QPID_COMMON_INLINE_EXTERN void setProtocol(uint8_t protocol) { protocol_ = protocol; }
QPID_COMMON_EXTERN const std::string toString() const;
QPID_COMMON_EXTERN ProtocolVersion& operator=(ProtocolVersion p);
QPID_COMMON_EXTERN bool operator==(ProtocolVersion p) const;
QPID_COMMON_INLINE_EXTERN bool operator!=(ProtocolVersion p) const { return ! (*this == p); }
+ QPID_COMMON_EXTERN static uint8_t AMQP;
+ QPID_COMMON_EXTERN static uint8_t LEGACY_AMQP;
+ QPID_COMMON_EXTERN static uint8_t TLS;
+ QPID_COMMON_EXTERN static uint8_t SASL;
};
} // namespace framing
diff --git a/cpp/include/qpid/log/Logger.h b/cpp/include/qpid/log/Logger.h
index 9464fa52dd..8c4beb0785 100644
--- a/cpp/include/qpid/log/Logger.h
+++ b/cpp/include/qpid/log/Logger.h
@@ -95,6 +95,11 @@ class QPID_COMMON_CLASS_EXTERN Logger : private boost::noncopyable {
/** Get the options used to configure the logger. */
QPID_COMMON_INLINE_EXTERN const Options& getOptions() const { return options; }
+ /** Get the hires timestamp setting */
+ QPID_COMMON_EXTERN bool getHiresTimestamp();
+
+ /** Set the hires timestamp setting */
+ QPID_COMMON_EXTERN void setHiresTimestamp(bool setting);
private:
typedef boost::ptr_vector<Output> Outputs;
diff --git a/cpp/include/qpid/management/Manageable.h b/cpp/include/qpid/management/Manageable.h
index 1e5cd8bc42..ede5c29e43 100644
--- a/cpp/include/qpid/management/Manageable.h
+++ b/cpp/include/qpid/management/Manageable.h
@@ -55,7 +55,11 @@ class QPID_COMMON_EXTERN Manageable
//
// This accessor function returns a pointer to the management object.
//
- virtual ManagementObject* GetManagementObject(void) const = 0;
+#ifdef _IN_QPID_BROKER
+ virtual ManagementObject::shared_ptr GetManagementObject() const = 0;
+#else
+ virtual ManagementObject* GetManagementObject() const = 0;
+#endif
// Every "Manageable" object must implement ManagementMethod. This
// function is called when a remote management client invokes a method
diff --git a/cpp/include/qpid/management/ManagementObject.h b/cpp/include/qpid/management/ManagementObject.h
index 16bf21038c..93fbec7bc7 100644
--- a/cpp/include/qpid/management/ManagementObject.h
+++ b/cpp/include/qpid/management/ManagementObject.h
@@ -25,10 +25,13 @@
#include "qpid/management/Mutex.h"
#include "qpid/types/Variant.h"
-
#include <map>
#include <vector>
+#ifdef _IN_QPID_BROKER
+#include <boost/shared_ptr.hpp>
+#endif
+
namespace qpid {
namespace management {
@@ -155,6 +158,10 @@ protected:
QPID_COMMON_EXTERN uint32_t writeTimestampsSize() const;
public:
+#ifdef _IN_QPID_BROKER
+ typedef boost::shared_ptr<ManagementObject> shared_ptr;
+#endif
+
QPID_COMMON_EXTERN static const uint8_t MD5_LEN = 16;
QPID_COMMON_EXTERN static int maxThreads;
//typedef void (*writeSchemaCall_t) (qpid::framing::Buffer&);
@@ -227,8 +234,10 @@ protected:
//QPID_COMMON_EXTERN void mapDecode(const types::Variant::Map& map);
};
-typedef std::map<ObjectId, ManagementObject*> ManagementObjectMap;
-typedef std::vector<ManagementObject*> ManagementObjectVector;
+#ifdef _IN_QPID_BROKER
+typedef std::map<ObjectId, ManagementObject::shared_ptr> ManagementObjectMap;
+typedef std::vector<ManagementObject::shared_ptr> ManagementObjectVector;
+#endif
}}
diff --git a/cpp/include/qpid/messaging/Message.h b/cpp/include/qpid/messaging/Message.h
index e89a6ce02f..5b14c7cf27 100644
--- a/cpp/include/qpid/messaging/Message.h
+++ b/cpp/include/qpid/messaging/Message.h
@@ -34,7 +34,7 @@ namespace messaging {
class Address;
class Codec;
-struct MessageImpl;
+class MessageImpl;
/** \ingroup messaging
* Representation of a message.
diff --git a/cpp/include/qpid/qpid.i b/cpp/include/qpid/qpid.i
new file mode 100644
index 0000000000..28a9064ebb
--- /dev/null
+++ b/cpp/include/qpid/qpid.i
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+/*
+ * Need some magic to wrap getContentPtr, otherwise it could return char *
+ * containing NULL, which would be incorrectly interpreted as end of string
+ */
+%extend qpid::messaging::Message
+{
+ mystr getContentPtr()
+ {
+ mystr s;
+ s.ptr = self->getContentPtr();
+ s.len = self->getContentSize();
+ return s;
+ }
+}
+%ignore qpid::messaging::Message::getContentPtr;
+%typemap(out,fragment="SWIG_FromCharPtrAndSize") (mystr) {
+ %append_output(SWIG_FromCharPtrAndSize($1.ptr, $1.len));
+}
+
+%{
+
+struct mystr
+{
+ size_t len;
+ const char *ptr;
+};
+
+#include <qpid/messaging/exceptions.h>
+#include <qpid/messaging/Address.h>
+#include <qpid/messaging/Connection.h>
+#include <qpid/messaging/Session.h>
+#include <qpid/messaging/Receiver.h>
+#include <qpid/messaging/Sender.h>
+#include <qpid/messaging/Message.h>
+#include <qpid/messaging/Duration.h>
+#include <qpid/messaging/FailoverUpdates.h>
+
+//
+// Wrapper functions for map-decode and list-decode. This allows us to avoid
+// the complexity of output parameter mapping.
+//
+qpid::types::Variant::Map& decodeMap(const qpid::messaging::Message& msg) {
+ static qpid::types::Variant::Map map;
+ map.clear();
+ qpid::messaging::decode(msg, map);
+ return map;
+}
+
+qpid::types::Variant::List& decodeList(const qpid::messaging::Message& msg) {
+ static qpid::types::Variant::List list;
+ list.clear();
+ qpid::messaging::decode(msg, list);
+ return list;
+}
+
+%}
+
+%include <qpid/ImportExport.h>
+%include <qpid/messaging/ImportExport.h>
+%include <qpid/messaging/Address.h>
+%include <qpid/messaging/Duration.h>
+%include <qpid/messaging/Message.h>
+%include <qpid/messaging/Receiver.h>
+%include <qpid/messaging/Sender.h>
+%include <qpid/messaging/Session.h>
+%include <qpid/messaging/Connection.h>
+%include <qpid/messaging/FailoverUpdates.h>
+
+qpid::types::Variant::Map& decodeMap(const qpid::messaging::Message&);
+qpid::types::Variant::List& decodeList(const qpid::messaging::Message&);
+
+
+%{
+
+%};
+
+%extend qpid::messaging::Duration {
+ qpid::messaging::Duration __mul__(uint64_t multiplier) {
+ return qpid::messaging::Duration(self->getMilliseconds() * multiplier);
+ }
+};
+
diff --git a/cpp/include/qpid/swig_perl_typemaps.i b/cpp/include/qpid/swig_perl_typemaps.i
new file mode 100644
index 0000000000..7730b69ce7
--- /dev/null
+++ b/cpp/include/qpid/swig_perl_typemaps.i
@@ -0,0 +1,335 @@
+/*
+ * 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.
+ */
+
+%wrapper %{
+
+#include <stdarg.h>
+
+ SV* MapToPerl(const qpid::types::Variant::Map*);
+ SV* ListToPerl(const qpid::types::Variant::List*);
+ void PerlToMap(SV*, qpid::types::Variant::Map*);
+ void PerlToList(SV*, qpid::types::Variant::List*);
+
+ qpid::types::Variant PerlToVariant(SV* value) {
+ if (SvROK(value)) {
+ if (SvTYPE(SvRV(value)) == SVt_PVHV) {
+ qpid::types::Variant::Map map;
+ PerlToMap(value, &map);
+ return qpid::types::Variant(map);
+ }
+ else if (SvTYPE(SvRV(value)) == SVt_PVAV) {
+ qpid::types::Variant::List list;
+ PerlToList(value, &list);
+ return qpid::types::Variant(list);
+ }
+ }
+ else {
+ if (SvIOK(value)) {
+ return qpid::types::Variant((int64_t) SvIV(value));
+ }
+ else if (SvNOK(value)) {
+ return qpid::types::Variant((float)SvNV(value));
+ }
+ else if (SvPOK(value)) {
+ STRLEN len;
+ char *ptr = SvPV(value, len);
+ qpid::types::Variant v = qpid::types::Variant(std::string(ptr,len));
+ if (SvUTF8(value)) {
+ v.setEncoding("utf8");
+ }
+ return v;
+ }
+ }
+ return qpid::types::Variant();
+ }
+
+ SV* VariantToPerl(const qpid::types::Variant* v) {
+ SV* result = newSV(0);
+ try {
+ switch (v->getType()) {
+ case qpid::types::VAR_VOID: {
+ sv_setiv(result, (IV)0);
+ break;
+ }
+ case qpid::types::VAR_BOOL : {
+ result = boolSV(v->asBool());
+ break;
+ }
+ case qpid::types::VAR_UINT8 :
+ case qpid::types::VAR_UINT16 :
+ case qpid::types::VAR_UINT32 : {
+ sv_setuv(result, (UV)v->asUint32());
+ break;
+ }
+ case qpid::types::VAR_UINT64 : {
+ sv_setuv(result, (UV)v->asUint64());
+ break;
+ }
+ case qpid::types::VAR_INT8 :
+ case qpid::types::VAR_INT16 :
+ case qpid::types::VAR_INT32 : {
+ sv_setiv(result, (IV)v->asInt32());
+ break;
+ }
+ case qpid::types::VAR_INT64 : {
+ sv_setiv(result, (IV)v->asInt64());
+ break;
+ }
+ case qpid::types::VAR_FLOAT : {
+ sv_setnv(result, (double)v->asFloat());
+ break;
+ }
+ case qpid::types::VAR_DOUBLE : {
+ sv_setnv(result, (double)v->asDouble());
+ break;
+ }
+ case qpid::types::VAR_STRING : {
+ const std::string val(v->asString());
+ result = newSVpvn(val.c_str(), val.size());
+ if( v->getEncoding() == "utf8" ) {
+ SvUTF8_on(result);
+ }
+ break;
+ }
+ case qpid::types::VAR_MAP : {
+ result = MapToPerl(&(v->asMap()));
+ break;
+ }
+ case qpid::types::VAR_LIST : {
+ result = ListToPerl(&(v->asList()));
+ break;
+ }
+ case qpid::types::VAR_UUID : {
+ }
+ }
+ } catch (qpid::types::Exception& ex) {
+ Perl_croak(aTHX_ ex.what());
+ }
+
+ return result;
+ }
+
+ SV* MapToPerl(const qpid::types::Variant::Map* map) {
+ HV *hv = newHV();
+ qpid::types::Variant::Map::const_iterator iter;
+ for (iter = map->begin(); iter != map->end(); iter++) {
+ const std::string key(iter->first);
+ SV* perlval = VariantToPerl(&(iter->second));
+ hv_store(hv, key.c_str(), key.size(), perlval, 0);
+ }
+ return sv_2mortal(newRV_noinc((SV *)hv));
+ }
+
+ SV* ListToPerl(const qpid::types::Variant::List* list) {
+ AV* av = newAV();
+ qpid::types::Variant::List::const_iterator iter;
+ for (iter = list->begin(); iter != list->end(); iter++) {
+ SV* perlval = VariantToPerl(&(*iter));
+ av_push(av, perlval);
+ }
+ return sv_2mortal(newRV_noinc((SV *)av));
+ }
+
+ void PerlToMap(SV* hash, qpid::types::Variant::Map* map) {
+ map->clear();
+ HV* hv = (HV *)SvRV(hash);
+ HE* he;
+ while((he = hv_iternext(hv)) != NULL) {
+ SV* svkey = HeSVKEY_force(he);
+ SV* svval = HeVAL(he);
+ (*map)[std::string(SvPV_nolen(svkey))] = PerlToVariant(svval);
+ }
+ }
+
+ void PerlToList(SV* ary, qpid::types::Variant::List* list) {
+ list->clear();
+ AV * av = (AV *)SvRV(ary);
+ I32 len = av_len(av) + 1;
+ if (len > 0) {
+ for (I32 i = 0; i < len; i++) {
+ list->push_back(PerlToVariant(*av_fetch(av, i, 0)));
+ }
+ }
+ }
+%}
+
+%typemap (in) void * {
+ $1 = (void *)SvIV($input);
+}
+
+%typemap (out) void * {
+ sv_setiv($result, (IV)$1);
+ argvi++;
+}
+
+%typemap (in) uint8_t, uint16_t, uint32_t, uint64_t {
+ if (SvIOK($input)) {
+ $1 = ($1_ltype)SvUV($input);
+ }
+ else {
+ SWIG_exception_fail(SWIG_ValueError, "not an integer");
+ }
+}
+
+%typemap (out) uint8_t, uint16_t, uint32_t, uint64_t {
+ sv_setuv($result, (UV)$1);
+ argvi++;
+}
+
+%typemap (in) int8_t, int16_t, int32_t, int64_t {
+ if (SvIOK($input)) {
+ $1 = ($1_ltype)SvIV($input);
+ }
+ else {
+ SWIG_exception_fail(SWIG_ValueError, "not an integer");
+ }
+}
+
+%typemap (out) int8_t, int16_t, int32_t, int64_t {
+ sv_setiv($result, (IV)$1);
+ argvi++;
+}
+
+%typemap(in) bool {
+ $1 = (bool)SvTRUE($input);
+}
+
+%typemap (out) bool {
+ $result = boolSV($1);
+ argvi++;
+}
+
+
+%typemap (typecheck, precedence=SWIG_TYPECHECK_UINT64) uint64_t {
+ $1 = SvIOK($input) ? 1 : 0;
+}
+
+%typemap (typecheck, precedence=SWIG_TYPECHECK_UINT32) uint32_t {
+ $1 = SvIOK($input) ? 1 : 0;
+}
+
+
+/*
+ * Variant types: C++ --> Perl
+ */
+%typemap(out) qpid::types::Variant::Map {
+ $result = MapToPerl(&$1);
+ argvi++;
+}
+
+%typemap(out) qpid::types::Variant::Map& {
+ $result = MapToPerl($1);
+ argvi++;
+}
+
+%typemap(out) qpid::types::Variant::List {
+ $result = ListToPerl(&$1);
+ argvi++;
+}
+
+%typemap(out) qpid::types::Variant::List& {
+ $result = ListToPerl($1);
+ argvi++;
+}
+
+%typemap(out) qpid::types::Variant& {
+ $result = VariantToPerl($1);
+ argvi++;
+}
+
+
+/*
+ * Variant types: Perl --> C++
+ */
+%typemap(in) qpid::types::Variant& {
+ $1 = new qpid::types::Variant(PerlToVariant($input));
+}
+
+%typemap(in) qpid::types::Variant::Map& {
+ $1 = new qpid::types::Variant::Map();
+ PerlToMap($input, $1);
+
+}
+
+%typemap(in) qpid::types::Variant::List& {
+ $1 = new qpid::types::Variant::List();
+ PerlToList($input, $1);
+
+}
+
+%typemap(in) const qpid::types::Variant::Map const & {
+ $1 = new qpid::types::Variant::Map();
+ PerlToMap($input, $1);
+}
+
+%typemap(in) const qpid::types::Variant::List const & {
+ $1 = new qpid::types::Variant::List();
+ PerlToList($input, $1);
+}
+
+%typemap(freearg) qpid::types::Variant& {
+ delete $1;
+}
+
+%typemap(freearg) qpid::types::Variant::Map& {
+ delete $1;
+}
+
+%typemap(freearg) qpid::types::Variant::List& {
+ delete $1;
+}
+
+
+/*
+ * Variant types: typecheck maps
+ */
+%typemap(typecheck) qpid::types::Variant::Map& {
+ $1 = (SvTYPE(SvRV($input)) == SVt_PVHV) ? 1 : 0;
+}
+
+%typemap(typecheck) qpid::types::Variant::List& {
+ $1 = (SvTYPE(SvRV($input)) == SVt_PVAV) ? 1 : 0;
+}
+
+%typemap(typecheck) qpid::types::Variant& {
+ $1 = (SvIOK($input) ||
+ SvNOK($input) ||
+ SvPOK($input) ) ? 1 : 0;
+}
+
+%typemap(typecheck) const qpid::types::Variant::Map const & {
+ $1 = (SvTYPE(SvRV($input)) == SVt_PVHV) ? 1 : 0;
+}
+
+%typemap(typecheck) const qpid::types::Variant::List const & {
+ $1 = (SvTYPE(SvRV($input)) == SVt_PVAV) ? 1 : 0;
+}
+
+%typemap(typecheck) const qpid::types::Variant const & {
+ $1 = (SvIOK($input) ||
+ SvNOK($input) ||
+ SvPOK($input) ) ? 1 : 0;
+}
+
+/* No boolean type for perl.
+ Boolean is simply and integer in perl
+*/
+%typecheck(SWIG_TYPECHECK_BOOL) bool {
+ $1 = (SvIOK($input)) ? 1 : 0;
+}
diff --git a/cpp/bindings/swig_python_typemaps.i b/cpp/include/qpid/swig_python_typemaps.i
index 25a4e46b18..25a4e46b18 100644
--- a/cpp/bindings/swig_python_typemaps.i
+++ b/cpp/include/qpid/swig_python_typemaps.i
diff --git a/cpp/bindings/swig_ruby_typemaps.i b/cpp/include/qpid/swig_ruby_typemaps.i
index 1a07cc86b0..1a07cc86b0 100644
--- a/cpp/bindings/swig_ruby_typemaps.i
+++ b/cpp/include/qpid/swig_ruby_typemaps.i
diff --git a/cpp/include/qpid/sys/IOHandle.h b/cpp/include/qpid/sys/IOHandle.h
index 45fc8c240a..06ae65f879 100644
--- a/cpp/include/qpid/sys/IOHandle.h
+++ b/cpp/include/qpid/sys/IOHandle.h
@@ -22,8 +22,6 @@
*
*/
-#include "qpid/CommonImportExport.h"
-
namespace qpid {
namespace sys {
@@ -31,18 +29,7 @@ namespace sys {
* This is a class intended to abstract the Unix concept of file descriptor
* or the Windows concept of HANDLE
*/
-class PollerHandle;
-class IOHandlePrivate;
-class IOHandle {
- friend class PollerHandle;
- friend class IOHandlePrivate;
-
-protected:
- IOHandlePrivate* const impl;
-
- IOHandle(IOHandlePrivate*);
- QPID_COMMON_EXTERN virtual ~IOHandle();
-};
+class IOHandle;
}}
diff --git a/cpp/include/qpid/sys/SystemInfo.h b/cpp/include/qpid/sys/SystemInfo.h
index 24bc099d75..1b5720a5f0 100644
--- a/cpp/include/qpid/sys/SystemInfo.h
+++ b/cpp/include/qpid/sys/SystemInfo.h
@@ -47,16 +47,23 @@ QPID_COMMON_EXTERN long concurrency();
QPID_COMMON_EXTERN bool getLocalHostname (Address &address);
/**
- * Get the (possibly multiple) local IP addresses of this host
- * using the specified port.
+ * Get the names of all the network interfaces connected to
+ * this host.
+ * @param names Receives the list of interface names
*/
-QPID_COMMON_EXTERN void getLocalIpAddresses (uint16_t port, std::vector<Address> &addrList);
+QPID_COMMON_EXTERN void getInterfaceNames(std::vector<std::string>& names );
/**
- * Return true if host names an address of the local host.
- *@param host host name or IP address.
+ * Get strings for each of the IP addresses associated with a named network
+ * interface.
+ * If there is no interface of that name an empty list will be returned.
+ *
+ * @param interface The name of the network interface
+ * @param addresses The list of the strings for the IP addresses are pushed on the back of this parameter
+ * to get just the list you need to clear the vector before using it.
+ * @return true if an interface of the correct name was found, false otherwise
*/
-QPID_COMMON_EXTERN bool isLocalHost(const std::string& host);
+QPID_COMMON_EXTERN bool getInterfaceAddresses(const std::string& interface, std::vector<std::string>& addresses);
/**
* Retrieve system identifiers and versions. This is information that can
@@ -90,6 +97,12 @@ QPID_COMMON_EXTERN uint32_t getParentProcessId();
*/
QPID_COMMON_EXTERN std::string getProcessName();
+/**
+ * Can thread related primitives be trusted during runtime house-cleaning?
+ * (i.e. static destructors, atexit()).
+ */
+QPID_COMMON_EXTERN bool threadSafeShutdown();
+
}}} // namespace qpid::sys::SystemInfo
diff --git a/cpp/include/qpid/sys/posix/PrivatePosix.h b/cpp/include/qpid/sys/posix/PrivatePosix.h
index 79cb950275..0f59fe3176 100644
--- a/cpp/include/qpid/sys/posix/PrivatePosix.h
+++ b/cpp/include/qpid/sys/posix/PrivatePosix.h
@@ -23,7 +23,6 @@
*/
#include "qpid/sys/Time.h"
-#include "qpid/sys/IOHandle.h"
struct timespec;
struct timeval;
@@ -41,32 +40,21 @@ Duration toTime(const struct timespec& ts);
class SocketAddress;
const struct addrinfo& getAddrInfo(const SocketAddress&);
-// Private fd related implementation details
-class IOHandlePrivate {
+// Posix fd as an IOHandle
+class IOHandle {
public:
- IOHandlePrivate(int f = -1) :
- fd(f)
+ IOHandle(int fd0 = -1) :
+ fd(fd0)
{}
int fd;
};
-int toFd(const IOHandlePrivate* h);
-
-// Posix fd as an IOHandle
-class PosixIOHandle : public IOHandle {
-public:
- PosixIOHandle(int fd) :
- IOHandle(new IOHandlePrivate(fd))
- {}
-};
-
// Dummy IOHandle for places it's required in the API
// but we promise not to actually try to do any operations on the IOHandle
class NullIOHandle : public IOHandle {
public:
- NullIOHandle() :
- IOHandle(new IOHandlePrivate)
+ NullIOHandle()
{}
};
diff --git a/cpp/include/qpid/types/Variant.h b/cpp/include/qpid/types/Variant.h
index 3493559777..e6bfd6bc0a 100644
--- a/cpp/include/qpid/types/Variant.h
+++ b/cpp/include/qpid/types/Variant.h
@@ -177,6 +177,7 @@ QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant& val
QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::Map& map);
QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::List& list);
QPID_TYPES_EXTERN bool operator==(const Variant& a, const Variant& b);
+QPID_TYPES_EXTERN bool operator!=(const Variant& a, const Variant& b);
#endif
}} // namespace qpid::types
diff --git a/cpp/managementgen/qmf-gen b/cpp/managementgen/qmf-gen
index 2f0cc0d8fd..fc2f284578 100755
--- a/cpp/managementgen/qmf-gen
+++ b/cpp/managementgen/qmf-gen
@@ -68,9 +68,11 @@ vargs = {}
if opts.brokerplugin:
vargs["agentHeaderDir"] = "management"
vargs["genQmfV1"] = True
+ vargs["genForBroker"] = True
else:
vargs["agentHeaderDir"] = "agent"
vargs["genQmfV1"] = None
+ vargs["genForBroker"] = None
if opts.qpidlogs:
vargs["genLogs"] = True
diff --git a/cpp/managementgen/qmfgen/generate.py b/cpp/managementgen/qmfgen/generate.py
index 61111be01d..a7ad43cc30 100755
--- a/cpp/managementgen/qmfgen/generate.py
+++ b/cpp/managementgen/qmfgen/generate.py
@@ -307,11 +307,22 @@ class Generator:
def testGenLogs (self, variables):
return variables["genLogs"]
+ def testInBroker (self, variables):
+ return variables['genForBroker']
+
def genDisclaimer (self, stream, variables):
prefix = variables["commentPrefix"]
stream.write (prefix + " This source file was created by a code generator.\n")
stream.write (prefix + " Please do not edit.")
+ def genExternClass (self, stream, variables):
+ if variables['genForBroker']:
+ stream.write("QPID_BROKER_CLASS_EXTERN")
+
+ def genExternMethod (self, stream, variables):
+ if variables['genForBroker']:
+ stream.write("QPID_BROKER_EXTERN")
+
def fileExt (self, path):
dot = path.rfind (".")
if dot == -1:
diff --git a/cpp/managementgen/qmfgen/schema.py b/cpp/managementgen/qmfgen/schema.py
index dc8ffae446..7bf161dc2b 100755
--- a/cpp/managementgen/qmfgen/schema.py
+++ b/cpp/managementgen/qmfgen/schema.py
@@ -1476,8 +1476,11 @@ class SchemaClass:
def genMethodIdDeclarations (self, stream, variables):
number = 1
+ ext = ""
+ if variables['genForBroker']:
+ ext = "QPID_BROKER_EXTERN "
for method in self.methods:
- stream.write (" QPID_BROKER_EXTERN static const uint32_t METHOD_" + method.getName().upper() +\
+ stream.write (" " + ext + "static const uint32_t METHOD_" + method.getName().upper() +\
" = %d;\n" % number)
number = number + 1
@@ -1521,7 +1524,7 @@ class SchemaClass:
for config in self.properties:
if config.isParentRef == 1:
stream.write (config.getName () + \
- " = _parent->GetManagementObject ()->getObjectId ();")
+ " = _parent->GetManagementObject()->getObjectId();")
return
def genSchemaMD5 (self, stream, variables):
diff --git a/cpp/managementgen/qmfgen/templates/Class.h b/cpp/managementgen/qmfgen/templates/Class.h
index 95939f3d03..cd43cef7f4 100644
--- a/cpp/managementgen/qmfgen/templates/Class.h
+++ b/cpp/managementgen/qmfgen/templates/Class.h
@@ -24,7 +24,11 @@
/*MGEN:Root.Disclaimer*/
#include "qpid/management/ManagementObject.h"
+/*MGEN:IF(Root.InBroker)*/
#include "qmf/BrokerImportExport.h"
+#include <boost/shared_ptr.hpp>
+/*MGEN:ENDIF*/
+#include <limits>
namespace qpid {
namespace management {
@@ -35,7 +39,7 @@ namespace qpid {
namespace qmf {
/*MGEN:Class.OpenNamespaces*/
-QPID_BROKER_CLASS_EXTERN class /*MGEN:Class.NameCap*/ : public ::qpid::management::ManagementObject
+/*MGEN:Root.ExternClass*/ class /*MGEN:Class.NameCap*/ : public ::qpid::management::ManagementObject
{
private:
@@ -76,22 +80,26 @@ QPID_BROKER_CLASS_EXTERN class /*MGEN:Class.NameCap*/ : public ::qpid::managemen
void aggregatePerThreadStats(struct PerThreadStats*) const;
/*MGEN:ENDIF*/
public:
- QPID_BROKER_EXTERN static void writeSchema(std::string& schema);
- QPID_BROKER_EXTERN void mapEncodeValues(::qpid::types::Variant::Map& map,
+/*MGEN:IF(Root.InBroker)*/
+ typedef boost::shared_ptr</*MGEN:Class.NameCap*/> shared_ptr;
+/*MGEN:ENDIF*/
+
+ /*MGEN:Root.ExternMethod*/ static void writeSchema(std::string& schema);
+ /*MGEN:Root.ExternMethod*/ void mapEncodeValues(::qpid::types::Variant::Map& map,
bool includeProperties=true,
bool includeStatistics=true);
- QPID_BROKER_EXTERN void mapDecodeValues(const ::qpid::types::Variant::Map& map);
- QPID_BROKER_EXTERN void doMethod(std::string& methodName,
+ /*MGEN:Root.ExternMethod*/ void mapDecodeValues(const ::qpid::types::Variant::Map& map);
+ /*MGEN:Root.ExternMethod*/ void doMethod(std::string& methodName,
const ::qpid::types::Variant::Map& inMap,
::qpid::types::Variant::Map& outMap,
const std::string& userId);
- QPID_BROKER_EXTERN std::string getKey() const;
+ /*MGEN:Root.ExternMethod*/ std::string getKey() const;
/*MGEN:IF(Root.GenQMFv1)*/
- QPID_BROKER_EXTERN uint32_t writePropertiesSize() const;
- QPID_BROKER_EXTERN void readProperties(const std::string& buf);
- QPID_BROKER_EXTERN void writeProperties(std::string& buf) const;
- QPID_BROKER_EXTERN void writeStatistics(std::string& buf, bool skipHeaders = false);
- QPID_BROKER_EXTERN void doMethod(std::string& methodName,
+ /*MGEN:Root.ExternMethod*/ uint32_t writePropertiesSize() const;
+ /*MGEN:Root.ExternMethod*/ void readProperties(const std::string& buf);
+ /*MGEN:Root.ExternMethod*/ void writeProperties(std::string& buf) const;
+ /*MGEN:Root.ExternMethod*/ void writeStatistics(std::string& buf, bool skipHeaders = false);
+ /*MGEN:Root.ExternMethod*/ void doMethod(std::string& methodName,
const std::string& inBuf,
std::string& outBuf,
const std::string& userId);
@@ -104,15 +112,15 @@ QPID_BROKER_CLASS_EXTERN class /*MGEN:Class.NameCap*/ : public ::qpid::managemen
bool hasInst() { return false; }
/*MGEN:ENDIF*/
- QPID_BROKER_EXTERN /*MGEN:Class.NameCap*/(
+ /*MGEN:Root.ExternMethod*/ /*MGEN:Class.NameCap*/(
::qpid::management::ManagementAgent* agent,
::qpid::management::Manageable* coreObject/*MGEN:Class.ParentArg*//*MGEN:Class.ConstructorArgs*/);
- QPID_BROKER_EXTERN ~/*MGEN:Class.NameCap*/();
+ /*MGEN:Root.ExternMethod*/ ~/*MGEN:Class.NameCap*/();
/*MGEN:Class.SetGeneralReferenceDeclaration*/
- QPID_BROKER_EXTERN static void registerSelf(
+ /*MGEN:Root.ExternMethod*/ static void registerSelf(
::qpid::management::ManagementAgent* agent);
std::string& getPackageName() const { return packageName; }
diff --git a/cpp/managementgen/qmfgen/templates/Event.h b/cpp/managementgen/qmfgen/templates/Event.h
index 592ae08c73..e5f5f53c1f 100644
--- a/cpp/managementgen/qmfgen/templates/Event.h
+++ b/cpp/managementgen/qmfgen/templates/Event.h
@@ -24,36 +24,41 @@
/*MGEN:Root.Disclaimer*/
#include "qpid/management/ManagementEvent.h"
+/*MGEN:IF(Root.InBroker)*/
#include "qmf/BrokerImportExport.h"
+/*MGEN:ENDIF*/
namespace qmf {
/*MGEN:Event.OpenNamespaces*/
-QPID_BROKER_CLASS_EXTERN class Event/*MGEN:Event.NameCap*/ : public ::qpid::management::ManagementEvent
+/*MGEN:Root.ExternClass*/ class Event/*MGEN:Event.NameCap*/ : public ::qpid::management::ManagementEvent
{
private:
static void writeSchema (std::string& schema);
- static std::string packageName;
- static std::string eventName;
static uint8_t md5Sum[MD5_LEN];
+ /*MGEN:Root.ExternMethod*/ static std::string packageName;
+ /*MGEN:Root.ExternMethod*/ static std::string eventName;
/*MGEN:Event.ArgDeclarations*/
public:
writeSchemaCall_t getWriteSchemaCall(void) { return writeSchema; }
- QPID_BROKER_EXTERN Event/*MGEN:Event.NameCap*/(/*MGEN:Event.ConstructorArgs*/);
- QPID_BROKER_EXTERN ~Event/*MGEN:Event.NameCap*/() {};
+ /*MGEN:Root.ExternMethod*/ Event/*MGEN:Event.NameCap*/(/*MGEN:Event.ConstructorArgs*/);
+ /*MGEN:Root.ExternMethod*/ ~Event/*MGEN:Event.NameCap*/() {};
static void registerSelf(::qpid::management::ManagementAgent* agent);
std::string& getPackageName() const { return packageName; }
std::string& getEventName() const { return eventName; }
uint8_t* getMd5Sum() const { return md5Sum; }
uint8_t getSeverity() const { return /*MGEN:Event.Severity*/; }
- QPID_BROKER_EXTERN void encode(std::string& buffer) const;
- QPID_BROKER_EXTERN void mapEncode(::qpid::types::Variant::Map& map) const;
+ /*MGEN:Root.ExternMethod*/ void encode(std::string& buffer) const;
+ /*MGEN:Root.ExternMethod*/ void mapEncode(::qpid::types::Variant::Map& map) const;
- QPID_BROKER_EXTERN static bool match(const std::string& evt, const std::string& pkg);
+ /*MGEN:Root.ExternMethod*/ static bool match(const std::string& evt, const std::string& pkg);
+ static std::pair<std::string,std::string> getFullName() {
+ return std::make_pair(packageName, eventName);
+ }
};
}/*MGEN:Event.CloseNamespaces*/
diff --git a/cpp/managementgen/qmfgen/templates/Package.h b/cpp/managementgen/qmfgen/templates/Package.h
index 3a42f12f9d..3260b03cce 100644
--- a/cpp/managementgen/qmfgen/templates/Package.h
+++ b/cpp/managementgen/qmfgen/templates/Package.h
@@ -24,7 +24,9 @@
/*MGEN:Root.Disclaimer*/
#include "qpid//*MGEN:Class.AgentHeaderLocation*//ManagementAgent.h"
+/*MGEN:IF(Root.InBroker)*/
#include "qmf/BrokerImportExport.h"
+/*MGEN:ENDIF*/
namespace qmf {
/*MGEN:Class.OpenNamespaces*/
@@ -32,8 +34,8 @@ namespace qmf {
class Package
{
public:
- QPID_BROKER_EXTERN Package (::qpid::management::ManagementAgent* agent);
- QPID_BROKER_EXTERN ~Package () {}
+ /*MGEN:Root.ExternMethod*/ Package (::qpid::management::ManagementAgent* agent);
+ /*MGEN:Root.ExternMethod*/ ~Package () {}
};
}/*MGEN:Class.CloseNamespaces*/
diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt
index 9b641558f8..6fa4b23eea 100644
--- a/cpp/src/CMakeLists.txt
+++ b/cpp/src/CMakeLists.txt
@@ -208,6 +208,7 @@ execute_process(COMMAND ${RUBY_EXECUTABLE} -I ${rgen_dir} ${rgen_dir}/generate $
set(mgmt_specs ${AMQP_SPEC_DIR}/management-schema.xml
${CMAKE_CURRENT_SOURCE_DIR}/qpid/acl/management-schema.xml
${CMAKE_CURRENT_SOURCE_DIR}/qpid/ha/management-schema.xml
+# ${CMAKE_CURRENT_SOURCE_DIR}/qpid/legacystore/management-schema.xml
)
set(mgen_dir ${qpid-cpp_SOURCE_DIR}/managementgen)
set(regen_mgmt OFF)
@@ -271,16 +272,28 @@ if (CMAKE_COMPILER_IS_GNUCXX)
set (WARNING_FLAGS
"-Werror -pedantic -Wall -Wextra -Wno-shadow -Wpointer-arith -Wcast-qual -Wcast-align -Wno-long-long -Wvolatile-register-var -Winvalid-pch -Wno-system-headers -Woverloaded-virtual")
- set (GCC_CATCH_UNDEFINED "-Wl,--no-undefined")
+ set (CATCH_UNDEFINED "-Wl,--no-undefined")
# gcc on SunOS uses native linker whose "-z defs" is too fussy
if (CMAKE_SYSTEM_NAME STREQUAL SunOS)
- set (GCC_CATCH_UNDEFINED "")
+ set (CATCH_UNDEFINED "")
endif (CMAKE_SYSTEM_NAME STREQUAL SunOS)
+ set (COMPILER_FLAGS "-fvisibility-inlines-hidden")
+ # gcc 4.1.2 on RHEL 5 needs -Wno-attributes to avoid an error that's fixed
+ # in later gcc versions.
+ execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
+ OUTPUT_VARIABLE GCC_VERSION)
+ if (GCC_VERSION VERSION_EQUAL 4.1.2)
+ set (HIDE_SYMBOL_FLAGS "-fvisibility=hidden -Wno-attributes")
+ else (GCC_VERSION VERSION_EQUAL 4.1.2)
+ set (HIDE_SYMBOL_FLAGS "-fvisibility=hidden")
+ endif (GCC_VERSION VERSION_EQUAL 4.1.2)
endif (CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro)
set (COMPILER_FLAGS "-library=stlport4 -mt")
set (WARNING_FLAGS "+w")
+ set (CATCH_UNDEFINED "")
+ set (HIDE_SYMBOL_FLAGS "")
endif (CMAKE_CXX_COMPILER_ID STREQUAL SunPro)
option(ENABLE_WARNINGS "Enable lots of compiler warnings (recommended)" ON)
@@ -293,9 +306,9 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS} ${WARNING_FLAGS}")
# Expand a bit from the basic Find_Boost; be specific about what's needed.
# Boost.system is sometimes needed; it's handled separately, below.
if (CMAKE_SYSTEM_NAME STREQUAL Windows)
- set (Boost_components filesystem program_options date_time thread unit_test_framework regex)
+ set (Boost_components program_options date_time thread unit_test_framework regex)
else (CMAKE_SYSTEM_NAME STREQUAL Windows)
- set (Boost_components filesystem program_options unit_test_framework)
+ set (Boost_components program_options unit_test_framework)
endif (CMAKE_SYSTEM_NAME STREQUAL Windows)
# Visual Studio 2010 requires boost 1.45 or better.
@@ -303,7 +316,10 @@ endif (CMAKE_SYSTEM_NAME STREQUAL Windows)
# where Boost 1.45 is supported, or we can just accept some versions using
# the Additional_versions variable.
if (NOT DEFINED Boost_ADDITIONAL_VERSIONS)
- set (Boost_ADDITIONAL_VERSIONS "1.45" "1.45.0" "1.46" "1.46.0" "1.47" "1.47.0")
+ set (Boost_ADDITIONAL_VERSIONS
+ "1.45" "1.45.0" "1.46" "1.46.0" "1.47" "1.47.0"
+ "1.48" "1.48.0" "1.49" "1.49.0" "1.50" "1.50.0"
+ "1.51" "1.51.0" "1.52" "1.52.0" "1.53" "1.53.0")
endif (NOT DEFINED Boost_ADDITIONAL_VERSIONS)
find_package(Boost 1.33 REQUIRED COMPONENTS ${Boost_components})
@@ -328,10 +344,6 @@ if (NOT Boost_PROGRAM_OPTIONS_LIBRARY)
set(Boost_PROGRAM_OPTIONS_LIBRARY boost_program_options)
endif (NOT Boost_PROGRAM_OPTIONS_LIBRARY)
-if (NOT Boost_FILESYSTEM_LIBRARY)
- set(Boost_FILESYSTEM_LIBRARY boost_filesystem)
-endif (NOT Boost_FILESYSTEM_LIBRARY)
-
if (NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY)
set(Boost_UNIT_TEST_FRAMEWORK_LIBRARY boost_unit_test_framework)
endif (NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY)
@@ -357,7 +369,6 @@ option(QPID_LINK_BOOST_DYNAMIC "Link with dynamic Boost libs (OFF to link static
if (MSVC)
install (PROGRAMS
${Boost_DATE_TIME_LIBRARY_DEBUG} ${Boost_DATE_TIME_LIBRARY_RELEASE}
- ${Boost_FILESYSTEM_LIBRARY_DEBUG} ${Boost_FILESYSTEM_LIBRARY_RELEASE}
${Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG} ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE}
${Boost_REGEX_LIBRARY_DEBUG} ${Boost_REGEX_LIBRARY_RELEASE}
${Boost_THREAD_LIBRARY_DEBUG} ${Boost_THREAD_LIBRARY_RELEASE}
@@ -378,10 +389,6 @@ if (MSVC)
string (REPLACE .lib .dll
_boost_date_time_release ${Boost_DATE_TIME_LIBRARY_RELEASE})
string (REPLACE .lib .dll
- _boost_filesystem_debug ${Boost_FILESYSTEM_LIBRARY_DEBUG})
- string (REPLACE .lib .dll
- _boost_filesystem_release ${Boost_FILESYSTEM_LIBRARY_RELEASE})
- string (REPLACE .lib .dll
_boost_program_options_debug ${Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG})
string (REPLACE .lib .dll
_boost_program_options_release ${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE})
@@ -404,7 +411,6 @@ if (MSVC)
endif (NOT Boost_VERSION LESS 103500)
install (PROGRAMS
${_boost_date_time_debug} ${_boost_date_time_release}
- ${_boost_filesystem_debug} ${_boost_filesystem_release}
${_boost_program_options_debug} ${_boost_program_options_release}
${_boost_regex_debug} ${_boost_regex_release}
${_boost_system_debug} ${_boost_system_release}
@@ -453,7 +459,6 @@ if (MSVC)
set(Boost_DATE_TIME_LIBRARY "")
set(Boost_THREAD_LIBRARY "")
set(Boost_PROGRAM_OPTIONS_LIBRARY "")
- set(Boost_FILESYSTEM_LIBRARY "")
set(Boost_UNIT_TEST_FRAMEWORK_LIBRARY "")
set(Boost_REGEX_LIBRARY "")
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/windows/resources )
@@ -571,13 +576,11 @@ if (BUILD_XML)
qpid/xml/XmlExchange.cpp
qpid/xml/XmlExchange.h
qpid/xml/XmlExchangePlugin.cpp)
- set_target_properties (xml PROPERTIES PREFIX "")
target_link_libraries (xml xerces-c xqilla qpidbroker pthread)
- if (CMAKE_COMPILER_IS_GNUCXX)
- set_target_properties (xml PROPERTIES
- PREFIX ""
- LINK_FLAGS ${GCC_CATCH_UNDEFINED})
- endif (CMAKE_COMPILER_IS_GNUCXX)
+ set_target_properties (xml PROPERTIES
+ PREFIX ""
+ COMPILE_DEFINITIONS _IN_QPID_BROKER
+ LINK_FLAGS "${CATCH_UNDEFINED}")
install (TARGETS xml
DESTINATION ${QPIDD_MODULE_DIR}
COMPONENT ${QPID_COMPONENT_BROKER})
@@ -600,6 +603,8 @@ if (BUILD_ACL)
qpid/acl/AclPlugin.cpp
qpid/acl/AclReader.cpp
qpid/acl/AclReader.h
+ qpid/acl/AclResourceCounter.cpp
+ qpid/acl/AclResourceCounter.h
qpid/acl/AclValidator.cpp
qpid/acl/AclValidator.h
)
@@ -608,13 +613,11 @@ if (BUILD_ACL)
# the qpidbroker platform-specific source list.
if (NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
add_library (acl MODULE ${acl_SOURCES})
- set_target_properties (acl PROPERTIES PREFIX "")
target_link_libraries (acl qpidbroker ${Boost_PROGRAM_OPTIONS_LIBRARY})
- if (CMAKE_COMPILER_IS_GNUCXX)
- set_target_properties (acl PROPERTIES
- PREFIX ""
- LINK_FLAGS "${GCC_CATCH_UNDEFINED}")
- endif (CMAKE_COMPILER_IS_GNUCXX)
+ set_target_properties (acl PROPERTIES
+ PREFIX ""
+ COMPILE_DEFINITIONS _IN_QPID_BROKER
+ LINK_FLAGS "${CATCH_UNDEFINED}")
install (TARGETS acl
DESTINATION ${QPIDD_MODULE_DIR}
COMPONENT ${QPID_COMPONENT_BROKER})
@@ -652,6 +655,8 @@ if (BUILD_HA)
qpid/ha/ReplicatingSubscription.cpp
qpid/ha/ReplicatingSubscription.h
qpid/ha/Settings.h
+ qpid/ha/StatusCheck.cpp
+ qpid/ha/StatusCheck.h
qpid/ha/types.cpp
qpid/ha/types.h
qpid/ha/RemoteBackup.cpp
@@ -659,8 +664,8 @@ if (BUILD_HA)
)
add_library (ha MODULE ${ha_SOURCES})
- set_target_properties (ha PROPERTIES PREFIX "")
- target_link_libraries (ha qpidtypes qpidcommon qpidbroker)
+ set_target_properties (ha PROPERTIES PREFIX "" COMPILE_DEFINITIONS _IN_QPID_BROKER)
+ target_link_libraries (ha qpidtypes qpidcommon qpidbroker qpidmessaging)
if (CMAKE_COMPILER_IS_GNUCXX)
set_target_properties (ha PROPERTIES
PREFIX ""
@@ -680,6 +685,9 @@ include (ssl.cmake)
# Check for optional async store build requirements
#include (asyncstore.cmake)
+# Check for optional AMQP 1.0 support requirements
+include (amqp.cmake)
+
# Check for syslog capabilities not present on all systems
check_symbol_exists (LOG_AUTHPRIV "sys/syslog.h" HAVE_LOG_AUTHPRIV)
check_symbol_exists (LOG_FTP "sys/syslog.h" HAVE_LOG_FTP)
@@ -744,7 +752,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL Windows)
qpid/sys/windows/PipeHandle.cpp
qpid/sys/windows/PollableCondition.cpp
qpid/sys/windows/Shlib.cpp
- qpid/sys/windows/Socket.cpp
+ qpid/sys/windows/WinSocket.cpp
qpid/sys/windows/SocketAddress.cpp
qpid/sys/windows/StrError.cpp
qpid/sys/windows/SystemInfo.cpp
@@ -755,7 +763,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL Windows)
)
set (qpidcommon_platform_LIBS
- ${Boost_THREAD_LIBRARY} ${windows_ssl_libs} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ws2_32 )
+ ${Boost_THREAD_LIBRARY} ${windows_ssl_libs} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_SYSTEM_LIBRARY} ws2_32 )
set (qpidbroker_platform_SOURCES
qpid/broker/windows/BrokerDefaults.cpp
qpid/broker/windows/SaslAuthenticator.cpp
@@ -767,6 +775,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL Windows)
)
set (qpidclient_platform_SOURCES
${sslclient_windows_SOURCES}
+ qpid/client/windows/ClientDllMain.cpp
)
set (qpidclient_platform_LIBS
${windows_ssl_libs}
@@ -803,10 +812,8 @@ else (CMAKE_SYSTEM_NAME STREQUAL Windows)
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
add_definitions(-pthread)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
- if (CMAKE_COMPILER_IS_GNUCXX)
- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GCC_CATCH_UNDEFINED} -pthread")
- set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pthread")
- endif (CMAKE_COMPILER_IS_GNUCXX)
+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CATCH_UNDEFINED} -pthread")
+ set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pthread")
# On Linux override memory status module
set (qpid_memstat_module
qpid/sys/posix/MemStat.cpp
@@ -848,7 +855,7 @@ else (CMAKE_SYSTEM_NAME STREQUAL Windows)
qpid/sys/posix/PollableCondition.cpp
qpid/sys/posix/Shlib.cpp
qpid/log/posix/SinkOptions.cpp
- qpid/sys/posix/Socket.cpp
+ qpid/sys/posix/BSDSocket.cpp
qpid/sys/posix/SocketAddress.cpp
qpid/sys/posix/StrError.cpp
qpid/sys/posix/Thread.cpp
@@ -860,7 +867,6 @@ else (CMAKE_SYSTEM_NAME STREQUAL Windows)
)
set (qpidcommon_platform_LIBS
${Boost_PROGRAM_OPTIONS_LIBRARY}
- ${Boost_FILESYSTEM_LIBRARY}
${CMAKE_DL_LIBS}
)
@@ -900,6 +906,7 @@ set (qpidcommon_SOURCES
qpid/StringUtils.cpp
qpid/Url.cpp
qpid/UrlArray.cpp
+ qpid/NullSaslServer.cpp
qpid/amqp_0_10/SessionHandler.cpp
qpid/framing/AccumulatedAck.cpp
qpid/framing/AMQBody.cpp
@@ -937,7 +944,6 @@ set (qpidcommon_SOURCES
qpid/management/ManagementObject.cpp
qpid/sys/AggregateOutput.cpp
qpid/sys/AsynchIOHandler.cpp
- qpid/sys/ClusterSafe.cpp
qpid/sys/Dispatcher.cpp
qpid/sys/DispatchHandle.cpp
qpid/sys/Runnable.cpp
@@ -945,6 +951,32 @@ set (qpidcommon_SOURCES
qpid/sys/Timer.cpp
qpid/sys/TimerWarnings.cpp
qpid/amqp_0_10/Codecs.cpp
+ qpid/amqp/CharSequence.h
+ qpid/amqp/CharSequence.cpp
+ qpid/amqp/Decoder.h
+ qpid/amqp/Decoder.cpp
+ qpid/amqp/Descriptor.h
+ qpid/amqp/Descriptor.cpp
+ qpid/amqp/Encoder.h
+ qpid/amqp/Encoder.cpp
+ qpid/amqp/MapReader.h
+ qpid/amqp/MapReader.cpp
+ qpid/amqp/MessageEncoder.h
+ qpid/amqp/MessageEncoder.cpp
+ qpid/amqp/MessageId.h
+ qpid/amqp/MessageId.cpp
+ qpid/amqp/MessageReader.h
+ qpid/amqp/MessageReader.cpp
+ qpid/amqp/Reader.h
+ qpid/amqp/Sasl.h
+ qpid/amqp/Sasl.cpp
+ qpid/amqp/SaslClient.h
+ qpid/amqp/SaslClient.cpp
+ qpid/amqp/SaslServer.h
+ qpid/amqp/SaslServer.cpp
+ qpid/messaging/amqp/Transport.h
+ qpid/messaging/amqp/Transport.cpp
+ qpid/messaging/amqp/TransportContext.h
${qpid_memstat_module}
)
add_msvc_version (qpidcommon library dll)
@@ -1029,26 +1061,12 @@ install (DIRECTORY ../include/qpid
PATTERN ".svn" EXCLUDE)
install_pdb (qpidclient ${QPID_COMPONENT_CLIENT})
-
-set (qpidmessaging_SOURCES
- ${qpidmessaging_platform_SOURCES}
- qpid/messaging/Address.cpp
+set (qpidmessaging_SOURCES_hidden
qpid/messaging/AddressParser.h
- qpid/messaging/AddressParser.cpp
- qpid/messaging/Connection.cpp
qpid/messaging/ConnectionImpl.h
- qpid/messaging/Duration.cpp
- qpid/messaging/exceptions.cpp
- qpid/messaging/Message.cpp
- qpid/messaging/MessageImpl.h
- qpid/messaging/MessageImpl.cpp
- qpid/messaging/Receiver.cpp
qpid/messaging/ReceiverImpl.h
- qpid/messaging/Session.cpp
qpid/messaging/SessionImpl.h
- qpid/messaging/Sender.cpp
qpid/messaging/SenderImpl.h
- qpid/messaging/FailoverUpdates.cpp
qpid/client/amqp0_10/AcceptTracker.h
qpid/client/amqp0_10/AcceptTracker.cpp
qpid/client/amqp0_10/AddressResolution.h
@@ -1068,6 +1086,33 @@ set (qpidmessaging_SOURCES
qpid/client/amqp0_10/SenderImpl.h
qpid/client/amqp0_10/SenderImpl.cpp
)
+set_source_files_properties(
+ ${qpidmessaging_SOURCES_hidden}
+ PROPERTIES
+ COMPILE_FLAGS "${HIDE_SYMBOL_FLAGS}")
+
+set (qpidmessaging_SOURCES
+ ${qpidmessaging_platform_SOURCES}
+ ${qpidmessaging_SOURCES_hidden}
+ qpid/messaging/Address.cpp
+ qpid/messaging/AddressParser.cpp # The functions in here are not in the public interface, but qmf uses them
+ qpid/messaging/Connection.cpp
+ qpid/messaging/Duration.cpp
+ qpid/messaging/exceptions.cpp
+ qpid/messaging/FailoverUpdates.cpp
+ qpid/messaging/Message.cpp
+ qpid/messaging/Receiver.cpp
+ qpid/messaging/Session.cpp
+ qpid/messaging/Sender.cpp
+ #functions from the following are not in the public interface but are used by the AMQP 1.0 client module
+ qpid/messaging/ConnectionOptions.h
+ qpid/messaging/ConnectionOptions.cpp
+ qpid/messaging/MessageImpl.h
+ qpid/messaging/MessageImpl.cpp
+ qpid/messaging/ProtocolRegistry.cpp
+ qpid/messaging/amqp/EncodedMessage.h
+ qpid/messaging/amqp/EncodedMessage.cpp
+)
add_msvc_version (qpidmessaging library dll)
add_library (qpidmessaging SHARED ${qpidmessaging_SOURCES})
@@ -1116,6 +1161,7 @@ set (qpidbroker_SOURCES
qpid/broker/MessageDeque.cpp
qpid/broker/MessageMap.cpp
qpid/broker/PriorityQueue.cpp
+ qpid/broker/Protocol.cpp
qpid/broker/Queue.cpp
qpid/broker/QueueCleaner.cpp
qpid/broker/QueueListeners.cpp
@@ -1130,7 +1176,7 @@ set (qpidbroker_SOURCES
qpid/broker/ConfigHandle.cpp
qpid/broker/Connection.cpp
qpid/broker/ConnectionHandler.cpp
- qpid/broker/ConnectionFactory.cpp
+ qpid/broker/ConnectionState.cpp
qpid/broker/DeliverableMessage.cpp
qpid/broker/DeliveryRecord.cpp
qpid/broker/DirectExchange.cpp
@@ -1203,7 +1249,7 @@ set (qpidbroker_SOURCES
add_msvc_version (qpidbroker library dll)
add_library (qpidbroker SHARED ${qpidbroker_SOURCES})
target_link_libraries (qpidbroker qpidcommon ${qpidbroker_platform_LIBS})
-set_target_properties (qpidbroker PROPERTIES VERSION ${qpidbroker_version})
+set_target_properties (qpidbroker PROPERTIES VERSION ${qpidbroker_version} COMPILE_DEFINITIONS _IN_QPID_BROKER)
if (MSVC)
set_target_properties (qpidbroker PROPERTIES COMPILE_FLAGS /wd4290)
endif (MSVC)
@@ -1220,8 +1266,8 @@ set (qpidd_SOURCES
)
add_msvc_version (qpidd application exe)
add_executable (qpidd ${qpidd_SOURCES})
-target_link_libraries (qpidd qpidbroker qpidcommon ${Boost_PROGRAM_OPTIONS_LIBRARY}
- ${Boost_FILESYSTEM_LIBRARY})
+target_link_libraries (qpidd qpidbroker qpidcommon ${Boost_PROGRAM_OPTIONS_LIBRARY})
+set_target_properties (qpidd PROPERTIES COMPILE_DEFINITIONS _IN_QPID_BROKER)
install (TARGETS qpidd RUNTIME
DESTINATION ${QPID_INSTALL_SBINDIR}
COMPONENT ${QPID_COMPONENT_BROKER})
@@ -1443,13 +1489,16 @@ install (FILES ${qmfconsole_HEADERS}
install_pdb (qmfconsole ${QPID_COMPONENT_QMF})
+#
+# Legacy store
+#
+#include (legacystore.cmake)
+
# This is only really needed until all the trunk builds (Linux, UNIX, Windows)
# are all on cmake only. This is because cmake builds always have a config.h
# file whereas older builds only have config.h on autoconf-generated builds.
add_definitions(-DHAVE_CONFIG_H)
-add_definitions(-DBOOST_FILESYSTEM_VERSION=2)
-
# Now create the config file from all the info learned above.
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config.h)
@@ -1457,21 +1506,21 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
add_subdirectory(tests)
# Support for pkg-config
-if (UNIX)
- add_custom_target(pkgconfig ALL echo DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/qpid.pc)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qpid.pc.in
- ${CMAKE_CURRENT_BINARY_DIR}/qpid.pc)
- install (FILES ${CMAKE_CURRENT_BINARY_DIR}/qpid.pc
- DESTINATION ${QPID_INSTALL_LIBDIR}/pkgconfig
- COMPONENT ${QPID_COMPONENT_COMMON})
-
- add_dependencies(pkgconfig ${CMAKE_CURRENT_BINARY_DIR}/qmf2.pc)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qmf2.pc.in
- ${CMAKE_CURRENT_BINARY_DIR}/qmf2.pc)
- install (FILES ${CMAKE_CURRENT_BINARY_DIR}/qmf2.pc
- DESTINATION ${QPID_INSTALL_LIBDIR}/pkgconfig
- COMPONENT ${QPID_COMPONENT_COMMON})
-endif (UNIX)
+
+# Compatible variable names used in the pkg config files also for autoconf
+set (prefix ${CMAKE_INSTALL_PREFIX})
+set (exec_prefix ${CMAKE_INSTALL_PREFIX})
+set_absolute_install_path (libdir ${LIB_INSTALL_DIR})
+set_absolute_install_path (includedir ${INCLUDE_INSTALL_DIR})
+set (VERSION ${QPID_VERSION})
+
+#add_custom_target(pkgconfig ALL echo DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/qpid.pc)
+#add_dependencies(pkgconfig ${CMAKE_CURRENT_BINARY_DIR}/qmf2.pc)
+configure_file(qpid.pc.in ${CMAKE_CURRENT_BINARY_DIR}/qpid.pc @ONLY)
+configure_file(qmf2.pc.in ${CMAKE_CURRENT_BINARY_DIR}/qmf2.pc @ONLY)
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/qpid.pc ${CMAKE_CURRENT_BINARY_DIR}/qmf2.pc
+ DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
+ COMPONENT ${QPID_COMPONENT_COMMON})
# Async Store support
# -------------------
@@ -1482,3 +1531,4 @@ endif (UNIX)
# corrected separately, and when it is, this can be moved up to the location
# of the other module includes.
include (asyncstore.cmake)
+
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am
index a65230b091..82ad151d2f 100644
--- a/cpp/src/Makefile.am
+++ b/cpp/src/Makefile.am
@@ -25,6 +25,7 @@ SUBDIRS = . tests
windows_dist = \
qpid/client/windows/SaslFactory.cpp \
qpid/client/windows/SslConnector.cpp \
+ qpid/client/windows/ClientDllMain.cpp \
qpid/log/windows/SinkOptions.cpp \
qpid/log/windows/SinkOptions.h \
../include/qpid/sys/windows/check.h \
@@ -42,9 +43,9 @@ windows_dist = \
qpid/sys/windows/PollableCondition.cpp \
qpid/sys/windows/PipeHandle.cpp \
../include/qpid/sys/windows/Mutex.h \
+ qpid/sys/windows/QpidDllMain.h \
qpid/sys/windows/Shlib.cpp \
qpid/sys/windows/SocketAddress.cpp \
- qpid/sys/windows/Socket.cpp \
qpid/sys/windows/SslAsynchIO.cpp \
qpid/sys/windows/SslAsynchIO.h \
qpid/sys/windows/StrError.cpp \
@@ -54,6 +55,8 @@ windows_dist = \
../include/qpid/sys/windows/Time.h \
qpid/sys/windows/uuid.cpp \
qpid/sys/windows/uuid.h \
+ qpid/sys/windows/WinSocket.cpp \
+ qpid/sys/windows/WinSocket.h \
windows/QpiddBroker.cpp \
windows/SCM.h \
windows/SCM.cpp \
@@ -127,7 +130,6 @@ INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(srcdir) -I=$(bu
# Destination for intalled programs and tests defined here
#
qpidexecdir = $(libexecdir)/qpid
-AM_CXXFLAGS += -DQPID_LIBEXEC_DIR=\"$(qpidexecdir)\"
qpidexec_PROGRAMS =
qpidexec_SCRIPTS =
qpidtestdir = $(qpidexecdir)/tests
@@ -136,15 +138,16 @@ qpidtest_SCRIPTS =
tmoduleexecdir = $(libdir)/qpid/tests
tmoduleexec_LTLIBRARIES=
-AM_CXXFLAGS += -DBOOST_FILESYSTEM_VERSION=2
+BROKER_CXXFLAGS = -D_IN_QPID_BROKER
## Automake macros to build libraries and executables.
-qpidd_CXXFLAGS = $(AM_CXXFLAGS) -DQPIDD_MODULE_DIR=\"$(dmoduleexecdir)\" -DQPIDD_CONF_FILE=\"$(sysconfdir)/qpidd.conf\" -DQPIDC_CONF_FILE=\"$(confdir)/qpidc.conf\"
+qpidd_CXXFLAGS = $(AM_CXXFLAGS) $(BROKER_CXXFLAGS) -DQPIDD_MODULE_DIR=\"$(dmoduleexecdir)\" -DQPIDD_CONF_FILE=\"$(sysconfdir)/qpidd.conf\" -DQPIDC_CONF_FILE=\"$(confdir)/qpidc.conf\"
libqpidclient_la_CXXFLAGS = $(AM_CXXFLAGS) -DQPIDC_MODULE_DIR=\"$(cmoduleexecdir)\" -DQPIDC_CONF_FILE=\"$(confdir)/qpidc.conf\"
qpidd_LDADD = \
libqpidbroker.la \
- libqpidcommon.la
+ libqpidcommon.la \
+ -lboost_program_options
posix_qpidd_src = posix/QpiddBroker.cpp
@@ -157,7 +160,8 @@ qpidd_SOURCES = qpidd.cpp qpidd.h $(posix_qpidd_src)
libqpidcommon_la_SOURCES += \
qpid/log/posix/SinkOptions.cpp \
qpid/sys/posix/IOHandle.cpp \
- qpid/sys/posix/Socket.cpp \
+ qpid/sys/posix/BSDSocket.cpp \
+ qpid/sys/posix/BSDSocket.h \
qpid/sys/posix/SocketAddress.cpp \
qpid/sys/posix/AsynchIO.cpp \
qpid/sys/posix/FileSysDir.cpp \
@@ -208,6 +212,7 @@ posix_broker_src = \
lib_LTLIBRARIES = libqpidtypes.la libqpidcommon.la libqpidbroker.la libqpidclient.la libqpidmessaging.la
+
# Definitions for client and daemon plugins
PLUGINLDFLAGS=-no-undefined -module -avoid-version
confdir=$(sysconfdir)/qpid
@@ -254,7 +259,7 @@ rdma_la_LIBADD = \
-libverbs
rdma_la_LDFLAGS = $(PLUGINLDFLAGS)
rdma_la_CXXFLAGS = \
- $(AM_CXXFLAGS) -Wno-missing-field-initializers
+ $(AM_CXXFLAGS) -Wno-missing-field-initializers -D_IN_QPID_BROKER
dmoduleexec_LTLIBRARIES += \
rdma.la
@@ -290,8 +295,10 @@ endif
EXTRA_DIST +=\
CMakeLists.txt \
config.h.cmake \
+ amqp.cmake \
rdma.cmake \
ssl.cmake \
+ legacystore.cmake \
managementgen.cmake \
rubygen.cmake \
versions.cmake \
@@ -331,7 +338,6 @@ EXTRA_DIST +=\
libqpidcommon_la_LIBADD = \
libqpidtypes.la \
-lboost_program_options \
- -lboost_filesystem \
-luuid \
-lpthread \
$(LIB_DLOPEN) \
@@ -357,6 +363,9 @@ libqpidcommon_la_SOURCES += \
qpid/Sasl.h \
qpid/SaslFactory.cpp \
qpid/SaslFactory.h \
+ qpid/SaslServer.h \
+ qpid/NullSaslServer.h \
+ qpid/NullSaslServer.cpp \
qpid/Serializer.h \
qpid/SessionId.cpp \
qpid/SessionState.cpp \
@@ -462,8 +471,6 @@ libqpidcommon_la_SOURCES += \
qpid/sys/AtomicValue_gcc.h \
qpid/sys/AtomicValue_mutex.h \
qpid/sys/BlockingQueue.h \
- qpid/sys/ClusterSafe.h \
- qpid/sys/ClusterSafe.cpp \
qpid/sys/Codec.h \
qpid/sys/ConnectionCodec.h \
qpid/sys/ConnectionInputHandler.h \
@@ -506,10 +513,48 @@ libqpidcommon_la_SOURCES += \
qpid/sys/TimerWarnings.cpp \
qpid/sys/TimerWarnings.h \
qpid/sys/Waitable.h \
- qpid/sys/alloca.h \
qpid/sys/uuid.h \
qpid/sys/unordered_map.h \
- qpid/amqp_0_10/Codecs.cpp
+ qpid/amqp_0_10/Codecs.cpp \
+ qpid/amqp/CharSequence.h \
+ qpid/amqp/CharSequence.cpp \
+ qpid/amqp/Codec.h \
+ qpid/amqp/Constructor.h \
+ qpid/amqp/Decoder.h \
+ qpid/amqp/Decoder.cpp \
+ qpid/amqp/Descriptor.h \
+ qpid/amqp/Descriptor.cpp \
+ qpid/amqp/descriptors.h \
+ qpid/amqp/Encoder.h \
+ qpid/amqp/Encoder.cpp \
+ qpid/amqp/ListReader.h \
+ qpid/amqp/LoggingReader.h \
+ qpid/amqp/MapReader.h \
+ qpid/amqp/MapReader.cpp \
+ qpid/amqp/MessageEncoder.h \
+ qpid/amqp/MessageEncoder.cpp \
+ qpid/amqp/MessageId.h \
+ qpid/amqp/MessageId.cpp \
+ qpid/amqp/MessageReader.h \
+ qpid/amqp/MessageReader.cpp \
+ qpid/amqp/Reader.h \
+ qpid/amqp/Sasl.h \
+ qpid/amqp/Sasl.cpp \
+ qpid/amqp/SaslClient.h \
+ qpid/amqp/SaslClient.cpp \
+ qpid/amqp/SaslServer.h \
+ qpid/amqp/SaslServer.cpp \
+ qpid/amqp/typecodes.h
+
+#libqpidcommon is not really the 'right' place for the Transport
+#interface, which is only used in 1.0 impl of messaging API, but this
+#lets the 1.0 SSL support be included in the existing sslconnector lib
+#which in turn addresses common ssl needs in qpidclient and
+#qpidmessaging:
+libqpidcommon_la_SOURCES += \
+ qpid/messaging/amqp/Transport.h \
+ qpid/messaging/amqp/Transport.cpp \
+ qpid/messaging/amqp/TransportContext.h
if HAVE_SASL
libqpidcommon_la_SOURCES += qpid/sys/cyrus/CyrusSecurityLayer.h
@@ -537,10 +582,9 @@ libqpidbroker_la_SOURCES = \
qpid/broker/BrokerImportExport.h \
qpid/broker/Connection.cpp \
qpid/broker/Connection.h \
- qpid/broker/ConnectionFactory.cpp \
- qpid/broker/ConnectionFactory.h \
qpid/broker/ConnectionHandler.cpp \
qpid/broker/ConnectionHandler.h \
+ qpid/broker/ConnectionState.cpp \
qpid/broker/ConnectionState.h \
qpid/broker/ConnectionToken.h \
qpid/broker/Consumer.h \
@@ -610,6 +654,8 @@ libqpidbroker_la_SOURCES = \
qpid/broker/MessageStoreModule.h \
qpid/broker/PriorityQueue.h \
qpid/broker/PriorityQueue.cpp \
+ qpid/broker/Protocol.h \
+ qpid/broker/Protocol.cpp \
qpid/broker/NameGenerator.cpp \
qpid/broker/NameGenerator.h \
qpid/broker/NullMessageStore.cpp \
@@ -659,6 +705,7 @@ libqpidbroker_la_SOURCES = \
qpid/broker/RecoveryManager.h \
qpid/broker/RecoveryManagerImpl.cpp \
qpid/broker/RecoveryManagerImpl.h \
+ qpid/broker/RecoverableMessageImpl.h \
qpid/broker/RetryList.cpp \
qpid/broker/RetryList.h \
qpid/broker/SaslAuthenticator.cpp \
@@ -683,7 +730,6 @@ libqpidbroker_la_SOURCES = \
qpid/broker/SessionState.h \
qpid/broker/SignalHandler.cpp \
qpid/broker/SignalHandler.h \
- qpid/broker/StatefulQueueObserver.h \
qpid/broker/System.cpp \
qpid/broker/System.h \
qpid/broker/ThresholdAlerts.cpp \
@@ -716,6 +762,76 @@ libqpidbroker_la_SOURCES = \
QPIDBROKER_VERSION_INFO = 2:0:0
libqpidbroker_la_LDFLAGS = -version-info $(QPIDBROKER_VERSION_INFO)
+libqpidbroker_la_CXXFLAGS=$(AM_CXXFLAGS) $(BROKER_CXXFLAGS)
+
+if HAVE_PROTON
+
+dmoduleexec_LTLIBRARIES += amqp.la
+amqp_la_LIBADD = libqpidcommon.la
+amqp_la_SOURCES = \
+ qpid/broker/amqp/Connection.h \
+ qpid/broker/amqp/Connection.cpp \
+ qpid/broker/amqp/DataReader.h \
+ qpid/broker/amqp/DataReader.cpp \
+ qpid/broker/amqp/Filter.h \
+ qpid/broker/amqp/Filter.cpp \
+ qpid/broker/amqp/Header.h \
+ qpid/broker/amqp/Header.cpp \
+ qpid/broker/amqp/ManagedConnection.h \
+ qpid/broker/amqp/ManagedConnection.cpp \
+ qpid/broker/amqp/ManagedSession.h \
+ qpid/broker/amqp/ManagedSession.cpp \
+ qpid/broker/amqp/ManagedOutgoingLink.h \
+ qpid/broker/amqp/ManagedOutgoingLink.cpp \
+ qpid/broker/amqp/Message.h \
+ qpid/broker/amqp/Message.cpp \
+ qpid/broker/amqp/NodeProperties.h \
+ qpid/broker/amqp/NodeProperties.cpp \
+ qpid/broker/amqp/Outgoing.h \
+ qpid/broker/amqp/Outgoing.cpp \
+ qpid/broker/amqp/ProtocolPlugin.cpp \
+ qpid/broker/amqp/Sasl.h \
+ qpid/broker/amqp/Sasl.cpp \
+ qpid/broker/amqp/Session.h \
+ qpid/broker/amqp/Session.cpp \
+ qpid/broker/amqp/Translation.h \
+ qpid/broker/amqp/Translation.cpp
+
+amqp_la_CXXFLAGS=$(AM_CXXFLAGS) $(BROKER_CXXFLAGS) $(PROTON_CFLAGS)
+amqp_la_LDFLAGS = $(PLUGINLDFLAGS) $(PROTON_LIBS)
+
+cmoduleexec_LTLIBRARIES += amqpc.la
+amqpc_la_LIBADD = libqpidcommon.la
+amqpc_la_SOURCES = \
+ qpid/messaging/amqp/AddressHelper.h \
+ qpid/messaging/amqp/AddressHelper.cpp \
+ qpid/messaging/amqp/ConnectionContext.h \
+ qpid/messaging/amqp/ConnectionContext.cpp \
+ qpid/messaging/amqp/ConnectionHandle.h \
+ qpid/messaging/amqp/ConnectionHandle.cpp \
+ qpid/messaging/amqp/DriverImpl.h \
+ qpid/messaging/amqp/DriverImpl.cpp \
+ qpid/messaging/amqp/ReceiverContext.h \
+ qpid/messaging/amqp/ReceiverContext.cpp \
+ qpid/messaging/amqp/ReceiverHandle.h \
+ qpid/messaging/amqp/ReceiverHandle.cpp \
+ qpid/messaging/amqp/Sasl.h \
+ qpid/messaging/amqp/Sasl.cpp \
+ qpid/messaging/amqp/SenderContext.h \
+ qpid/messaging/amqp/SenderContext.cpp \
+ qpid/messaging/amqp/SenderHandle.h \
+ qpid/messaging/amqp/SenderHandle.cpp \
+ qpid/messaging/amqp/SessionContext.h \
+ qpid/messaging/amqp/SessionContext.cpp \
+ qpid/messaging/amqp/SessionHandle.h \
+ qpid/messaging/amqp/SessionHandle.cpp \
+ qpid/messaging/amqp/TcpTransport.h \
+ qpid/messaging/amqp/TcpTransport.cpp
+
+amqpc_la_CXXFLAGS=$(AM_CXXFLAGS) $(PROTON_CFLAGS)
+amqpc_la_LDFLAGS = $(PLUGINLDFLAGS) $(PROTON_LIBS)
+
+endif #HAVE_PROTON
libqpidclient_la_LIBADD = libqpidcommon.la -luuid
@@ -793,12 +909,16 @@ libqpidmessaging_la_SOURCES = \
qpid/messaging/AddressParser.h \
qpid/messaging/AddressParser.cpp \
qpid/messaging/Connection.cpp \
+ qpid/messaging/ConnectionOptions.h \
+ qpid/messaging/ConnectionOptions.cpp \
qpid/messaging/Duration.cpp \
qpid/messaging/exceptions.cpp \
qpid/messaging/Message.cpp \
qpid/messaging/MessageImpl.h \
qpid/messaging/MessageImpl.cpp \
qpid/messaging/PrivateImplRef.h \
+ qpid/messaging/ProtocolRegistry.h \
+ qpid/messaging/ProtocolRegistry.cpp \
qpid/messaging/Sender.cpp \
qpid/messaging/Receiver.cpp \
qpid/messaging/Session.cpp \
@@ -807,6 +927,8 @@ libqpidmessaging_la_SOURCES = \
qpid/messaging/ReceiverImpl.h \
qpid/messaging/SessionImpl.h \
qpid/messaging/FailoverUpdates.cpp \
+ qpid/messaging/amqp/EncodedMessage.h \
+ qpid/messaging/amqp/EncodedMessage.cpp \
qpid/client/amqp0_10/AcceptTracker.h \
qpid/client/amqp0_10/AcceptTracker.cpp \
qpid/client/amqp0_10/AddressResolution.h \
@@ -832,6 +954,7 @@ libqpidmessaging_la_LDFLAGS = -version-info $(QPIDMESSAGING_VERSION_INFO)
# NOTE: only public header files (which should be in ../include)
# should go in this list. Private headers should go in the SOURCES
# list for one of the libraries or executables that includes it.
+# Also included are the swig descriptor files.
nobase_include_HEADERS += \
../include/qpid/Address.h \
@@ -918,7 +1041,10 @@ nobase_include_HEADERS += \
../include/qpid/types/Exception.h \
../include/qpid/types/Uuid.h \
../include/qpid/types/Variant.h \
- ../include/qpid/types/ImportExport.h
+ ../include/qpid/types/ImportExport.h \
+ ../include/qpid/qpid.i \
+ ../include/qmf/qmfengine.i \
+ ../include/qmf/qmf2.i
# Create the default data directory
install-data-local:
diff --git a/cpp/src/acl.mk b/cpp/src/acl.mk
index 0301f8c754..87821a3741 100644
--- a/cpp/src/acl.mk
+++ b/cpp/src/acl.mk
@@ -31,6 +31,9 @@ acl_la_SOURCES = \
qpid/acl/AclPlugin.cpp \
qpid/acl/AclReader.cpp \
qpid/acl/AclReader.h \
+ qpid/acl/AclResourceCounter.cpp \
+ qpid/acl/AclResourceCounter.h \
+ qpid/acl/AclTopicMatch.h \
qpid/acl/AclValidator.cpp \
qpid/acl/AclValidator.h
@@ -40,4 +43,5 @@ if SUNOS
endif
acl_la_LDFLAGS = $(PLUGINLDFLAGS)
+acl_la_CXXFLAGS = $(AM_CXXFLAGS) -D_IN_QPID_BROKER
diff --git a/cpp/src/amqp.cmake b/cpp/src/amqp.cmake
new file mode 100644
index 0000000000..718e6fe342
--- /dev/null
+++ b/cpp/src/amqp.cmake
@@ -0,0 +1,127 @@
+#
+# 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.
+#
+
+# Optional AMQP1.0 support. Requires proton toolkit.
+
+include(FindPkgConfig)
+
+pkg_check_modules(PROTON libqpid-proton)
+
+set (amqp_default ${amqp_force})
+if (PROTON_FOUND)
+ message(STATUS "Qpid proton found, amqp 1.0 support enabled")
+ set (amqp_default ON)
+else (PROTON_FOUND)
+ message(STATUS "Qpid proton not found, amqp 1.0 support not enabled")
+endif (PROTON_FOUND)
+
+option(BUILD_AMQP "Build with support for AMQP 1.0" ${amqp_default})
+if (BUILD_AMQP)
+
+ if (NOT PROTON_FOUND)
+ message(FATAL_ERROR "Qpid proton not found, required for amqp 1.0 support")
+ endif (NOT PROTON_FOUND)
+
+ foreach(f ${PROTON_CFLAGS})
+ set (PROTON_COMPILE_FLAGS "${PROTON_COMPILE_FLAGS} ${f}")
+ endforeach(f)
+
+ foreach(f ${PROTON_LDFLAGS})
+ set (PROTON_LINK_FLAGS "${PROTON_LINK_FLAGS} ${f}")
+ endforeach(f)
+
+
+ set (amqp_SOURCES
+ qpid/broker/amqp/Connection.h
+ qpid/broker/amqp/Connection.cpp
+ qpid/broker/amqp/DataReader.h
+ qpid/broker/amqp/DataReader.cpp
+ qpid/broker/amqp/Filter.h
+ qpid/broker/amqp/Filter.cpp
+ qpid/broker/amqp/Header.h
+ qpid/broker/amqp/Header.cpp
+ qpid/broker/amqp/ManagedConnection.h
+ qpid/broker/amqp/ManagedConnection.cpp
+ qpid/broker/amqp/ManagedSession.h
+ qpid/broker/amqp/ManagedSession.cpp
+ qpid/broker/amqp/ManagedOutgoingLink.h
+ qpid/broker/amqp/ManagedOutgoingLink.cpp
+ qpid/broker/amqp/Message.h
+ qpid/broker/amqp/Message.cpp
+ qpid/broker/amqp/NodeProperties.h
+ qpid/broker/amqp/NodeProperties.cpp
+ qpid/broker/amqp/Outgoing.h
+ qpid/broker/amqp/Outgoing.cpp
+ qpid/broker/amqp/ProtocolPlugin.cpp
+ qpid/broker/amqp/Sasl.h
+ qpid/broker/amqp/Sasl.cpp
+ qpid/broker/amqp/Session.h
+ qpid/broker/amqp/Session.cpp
+ qpid/broker/amqp/Translation.h
+ qpid/broker/amqp/Translation.cpp
+ )
+ add_library (amqp MODULE ${amqp_SOURCES})
+ target_link_libraries (amqp qpidbroker qpidcommon)
+ set_target_properties (amqp PROPERTIES
+ PREFIX ""
+ COMPILE_FLAGS "${PROTON_COMPILE_FLAGS}"
+ LINK_FLAGS "${PROTON_LINK_FLAGS}")
+ set_target_properties (amqp PROPERTIES COMPILE_DEFINITIONS _IN_QPID_BROKER)
+ install (TARGETS amqp
+ DESTINATION ${QPIDD_MODULE_DIR}
+ COMPONENT ${QPID_COMPONENT_BROKER})
+
+
+ set (amqpc_SOURCES
+ qpid/messaging/amqp/AddressHelper.h
+ qpid/messaging/amqp/AddressHelper.cpp
+ qpid/messaging/amqp/ConnectionContext.h
+ qpid/messaging/amqp/ConnectionContext.cpp
+ qpid/messaging/amqp/ConnectionHandle.h
+ qpid/messaging/amqp/ConnectionHandle.cpp
+ qpid/messaging/amqp/DriverImpl.h
+ qpid/messaging/amqp/DriverImpl.cpp
+ qpid/messaging/amqp/ReceiverContext.h
+ qpid/messaging/amqp/ReceiverContext.cpp
+ qpid/messaging/amqp/ReceiverHandle.h
+ qpid/messaging/amqp/ReceiverHandle.cpp
+ qpid/messaging/amqp/Sasl.h
+ qpid/messaging/amqp/Sasl.cpp
+ qpid/messaging/amqp/SenderContext.h
+ qpid/messaging/amqp/SenderContext.cpp
+ qpid/messaging/amqp/SenderHandle.h
+ qpid/messaging/amqp/SenderHandle.cpp
+ qpid/messaging/amqp/SessionContext.h
+ qpid/messaging/amqp/SessionContext.cpp
+ qpid/messaging/amqp/SessionHandle.h
+ qpid/messaging/amqp/SessionHandle.cpp
+ qpid/messaging/amqp/TcpTransport.h
+ qpid/messaging/amqp/TcpTransport.cpp
+ )
+ add_library (amqpc MODULE ${amqpc_SOURCES})
+ target_link_libraries (amqpc qpidclient qpidcommon)
+ set_target_properties (amqpc PROPERTIES
+ PREFIX ""
+ COMPILE_FLAGS "${PROTON_COMPILE_FLAGS}"
+ LINK_FLAGS "${PROTON_LINK_FLAGS}")
+ install (TARGETS amqpc
+ DESTINATION ${QPIDC_MODULE_DIR}
+ COMPONENT ${QPID_COMPONENT_CLIENT})
+
+endif (BUILD_AMQP)
diff --git a/cpp/src/asyncstore.cmake b/cpp/src/asyncstore.cmake
index 477091a927..017b8fb880 100644
--- a/cpp/src/asyncstore.cmake
+++ b/cpp/src/asyncstore.cmake
@@ -91,6 +91,7 @@ if (UNIX)
PREFIX ""
OUTPUT_NAME asyncStore
SOVERSION ${asyncStore_version}
+ COMPILE_DEFINITIONS _IN_QPID_BROKER
)
target_link_libraries (asyncStore
aio
diff --git a/cpp/src/config.h.cmake b/cpp/src/config.h.cmake
index f55f68afde..5c8c56c749 100644
--- a/cpp/src/config.h.cmake
+++ b/cpp/src/config.h.cmake
@@ -37,8 +37,6 @@
#cmakedefine QPIDC_MODULE_DIR "${QPIDC_MODULE_DIR}"
#cmakedefine QPIDD_MODULE_DIR "${QPIDD_MODULE_DIR}"
-#cmakedefine QPID_LIBEXEC_DIR "${QPID_LIBEXEC_DIR}"
-
#define QPID_SHLIB_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}"
#define QPID_MODULE_PREFIX
#cmakedefine QPID_DEBUG_POSTFIX "${QPID_DEBUG_POSTFIX}"
diff --git a/cpp/src/finddb.cmake b/cpp/src/finddb.cmake
new file mode 100644
index 0000000000..fad827cffe
--- /dev/null
+++ b/cpp/src/finddb.cmake
@@ -0,0 +1,74 @@
+#
+# 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.
+#
+#
+
+if(UNIX)
+# - Find BerkeleyDB
+# Find the BerkeleyDB includes and library
+# This module defines
+# DB_INCLUDE_DIR, where to find db.h, etc.
+# DB_LIBRARIES, the libraries needed to use BerkeleyDB.
+# DB_FOUND, If false, do not try to use BerkeleyDB.
+# also defined, but not for general use are
+# DB_LIBRARY, where to find the BerkeleyDB library.
+
+FIND_PATH(DB_INCLUDE_DIR db.h
+ /usr/local/include/db4
+ /usr/local/include
+ /usr/include/db4
+ /usr/include
+)
+
+SET(DB_NAMES ${DB_NAMES} db_cxx)
+FIND_LIBRARY(DB_LIBRARY
+ NAMES ${DB_NAMES}
+ PATHS /usr/lib /usr/local/lib
+)
+
+IF (DB_LIBRARY AND DB_INCLUDE_DIR)
+ SET(DB_LIBRARIES ${DB_LIBRARY})
+ SET(DB_FOUND "YES")
+ELSE (DB_LIBRARY AND DB_INCLUDE_DIR)
+ UNSET( DB_FOUND )
+ENDIF (DB_LIBRARY AND DB_INCLUDE_DIR)
+
+
+IF (DB_FOUND)
+ IF (NOT DB_FIND_QUIETLY)
+ MESSAGE(STATUS "Found BerkeleyDB: ${DB_LIBRARIES}")
+ ENDIF (NOT DB_FIND_QUIETLY)
+ELSE (DB_FOUND)
+ IF (DB_FIND_REQUIRED)
+ MESSAGE(FATAL_ERROR "Could not find BerkeleyDB library")
+ ENDIF (DB_FIND_REQUIRED)
+ENDIF (DB_FOUND)
+
+# Deprecated declarations.
+SET (NATIVE_DB_INCLUDE_PATH ${DB_INCLUDE_DIR} )
+GET_FILENAME_COMPONENT (NATIVE_DB_LIB_PATH ${DB_LIBRARY} PATH)
+
+MARK_AS_ADVANCED(
+ DB_LIBRARY
+ DB_INCLUDE_DIR
+)
+
+else(UNIX)
+ MESSAGE(STATUS "BerkeleyDB is ignored on non-Unix platforms")
+ UNSET( DB_FOUND )
+endif(UNIX) \ No newline at end of file
diff --git a/cpp/src/generate.sh b/cpp/src/generate.sh
deleted file mode 100755
index 581a45ff7f..0000000000
--- a/cpp/src/generate.sh
+++ /dev/null
@@ -1,67 +0,0 @@
-# !/bin/sh
-
-# 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.
-#
-
-# Generate code from AMQP specification.
-# specs and gentools_dir are set by Makefile
-#
-set -e
-
-test -z "$JAVA" && JAVA=java ;
-test -z "$JAVAC" && JAVAC=javac ;
-
-srcdir=`dirname $0`
-checkspecs() {
- for s in $specs; do test -f $s || return 1; done
- return 0
-}
-
-# Can we generate code?
-if { test -d $gentools_dir && checkspecs &&
- which $JAVA && which $JAVAC; } > /dev/null;
-then
- echo "Generating code."
- mkdir -p gen/qpid/framing
- ( cd $gentools_dir/src && $JAVAC `find -name '*.java' -print` ; )
- $JAVA -cp $gentools_dir/src org.apache.qpid.gentools.Main \
- -c -o gen/qpid/framing -t $gentools_dir/templ.cpp $specs
- GENERATED=yes
-fi
-
-# Print a Makefile variable assignment.
-make_assign() {
- echo -n "$1 = "; shift
- prefix=$1; shift
- for f in $*; do echo "\\" ; echo -n " $prefix$f "; done
- echo
-}
-
-# Generate a Makefile fragment
-(
- make_assign "generated_cpp" "" `find gen -name '*.cpp' -print`
- make_assign "generated_h" "" `find gen -name '*.h' -print`
- if test x$GENERATED = xyes; then
- make_assign "generator" "" $specs \
- `find ../gentools \( -name '*.java' -o -name '*.tmpl' \) -print`
- fi
-) > generate.mk-t
-mv generate.mk-t $srcdir/generate.mk
-
-
-
diff --git a/cpp/src/ha.mk b/cpp/src/ha.mk
index 96a3d872e4..31b3bc243d 100644
--- a/cpp/src/ha.mk
+++ b/cpp/src/ha.mk
@@ -50,10 +50,13 @@ ha_la_SOURCES = \
qpid/ha/ReplicationTest.cpp \
qpid/ha/ReplicationTest.h \
qpid/ha/Settings.h \
+ qpid/ha/StatusCheck.cpp \
+ qpid/ha/StatusCheck.h \
qpid/ha/RemoteBackup.cpp \
qpid/ha/RemoteBackup.h \
qpid/ha/types.cpp \
qpid/ha/types.h
-ha_la_LIBADD = libqpidbroker.la
+ha_la_LIBADD = libqpidbroker.la libqpidmessaging.la
ha_la_LDFLAGS = $(PLUGINLDFLAGS)
+ha_la_CXXFLAGS = $(AM_CXXFLAGS) -D_IN_QPID_BROKER
diff --git a/cpp/src/legacystore.cmake b/cpp/src/legacystore.cmake
new file mode 100644
index 0000000000..10a166f50c
--- /dev/null
+++ b/cpp/src/legacystore.cmake
@@ -0,0 +1,157 @@
+#
+# 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.
+#
+#
+# Legacy store library CMake fragment, to be included in CMakeLists.txt
+#
+
+if (DEFINED legacystore_force)
+ set (legacystore_default ${legacystore_force})
+else (DEFINED legacystore_force)
+ set (legacystore_default OFF)
+ if (UNIX)
+ #
+ # Find required BerkelyDB
+ #
+ include (finddb.cmake)
+ if (DB_FOUND)
+ #
+ # find libaio
+ #
+ CHECK_LIBRARY_EXISTS (aio io_queue_init "" HAVE_AIO)
+ CHECK_INCLUDE_FILES (libaio.h HAVE_AIO_H)
+ if (HAVE_AIO AND HAVE_AIO_H)
+ #
+ # find libuuid
+ #
+ CHECK_LIBRARY_EXISTS (uuid uuid_compare "" HAVE_UUID)
+ CHECK_INCLUDE_FILES(uuid/uuid.h HAVE_UUID_H)
+ IF (HAVE_UUID AND HAVE_UUID_H)
+ #
+ # allow legacystore to be built
+ #
+ set (legacystore_default ON)
+ ENDIF (HAVE_UUID AND HAVE_UUID_H)
+ endif (HAVE_AIO AND HAVE_AIO_H)
+ endif (DB_FOUND)
+ endif (UNIX)
+endif (DEFINED legacystore_force)
+
+option(BUILD_LEGACYSTORE "Build legacystore persistent store" ${legacystore_default})
+
+if (BUILD_LEGACYSTORE)
+ if (NOT UNIX)
+ message(FATAL_ERROR "Legacystore produced only on Unix platforms")
+ endif (NOT UNIX)
+ if (NOT DB_FOUND)
+ message(FATAL_ERROR "Legacystore requires BerkeleyDB which is absent.")
+ endif (NOT DB_FOUND)
+ if (NOT HAVE_AIO)
+ message(FATAL_ERROR "Legacystore requires libaio which is absent.")
+ endif (NOT HAVE_AIO)
+ if (NOT HAVE_AIO_H)
+ message(FATAL_ERROR "Legacystore requires libaio.h which is absent.")
+ endif (NOT HAVE_AIO_H)
+ if (NOT HAVE_UUID)
+ message(FATAL_ERROR "Legacystore requires uuid which is absent.")
+ endif (NOT HAVE_UUID)
+ if (NOT HAVE_UUID_H)
+ message(FATAL_ERROR "Legacystore requires uuid.h which is absent.")
+ endif (NOT HAVE_UUID_H)
+
+ # Journal source files
+ set (legacy_jrnl_SOURCES
+ qpid/legacystore/jrnl/aio.cpp
+ qpid/legacystore/jrnl/cvar.cpp
+ qpid/legacystore/jrnl/data_tok.cpp
+ qpid/legacystore/jrnl/deq_rec.cpp
+ qpid/legacystore/jrnl/enq_map.cpp
+ qpid/legacystore/jrnl/enq_rec.cpp
+ qpid/legacystore/jrnl/fcntl.cpp
+ qpid/legacystore/jrnl/jcntl.cpp
+ qpid/legacystore/jrnl/jdir.cpp
+ qpid/legacystore/jrnl/jerrno.cpp
+ qpid/legacystore/jrnl/jexception.cpp
+ qpid/legacystore/jrnl/jinf.cpp
+ qpid/legacystore/jrnl/jrec.cpp
+ qpid/legacystore/jrnl/lp_map.cpp
+ qpid/legacystore/jrnl/lpmgr.cpp
+ qpid/legacystore/jrnl/pmgr.cpp
+ qpid/legacystore/jrnl/rmgr.cpp
+ qpid/legacystore/jrnl/rfc.cpp
+ qpid/legacystore/jrnl/rrfc.cpp
+ qpid/legacystore/jrnl/slock.cpp
+ qpid/legacystore/jrnl/smutex.cpp
+ qpid/legacystore/jrnl/time_ns.cpp
+ qpid/legacystore/jrnl/txn_map.cpp
+ qpid/legacystore/jrnl/txn_rec.cpp
+ qpid/legacystore/jrnl/wmgr.cpp
+ qpid/legacystore/jrnl/wrfc.cpp
+ )
+
+ # legacyStore source files
+ set (legacy_store_SOURCES
+ qpid/legacystore/StorePlugin.cpp
+ qpid/legacystore/BindingDbt.cpp
+ qpid/legacystore/BufferValue.cpp
+ qpid/legacystore/DataTokenImpl.cpp
+ qpid/legacystore/IdDbt.cpp
+ qpid/legacystore/IdSequence.cpp
+ qpid/legacystore/JournalImpl.cpp
+ qpid/legacystore/MessageStoreImpl.cpp
+ qpid/legacystore/PreparedTransaction.cpp
+ qpid/legacystore/TxnCtxt.cpp
+ )
+
+ # legacyStore include directories
+ get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
+ set (legacy_include_DIRECTORIES
+ ${dirs}
+ ${CMAKE_CURRENT_SOURCE_DIR}/qpid/legacystore
+ )
+
+ if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/db-inc.h)
+ message(STATUS "Including BDB from ${DB_INCLUDE_DIR}/db_cxx.h")
+ file(WRITE
+ ${CMAKE_CURRENT_BINARY_DIR}/db-inc.h
+ "#include <${DB_INCLUDE_DIR}/db_cxx.h>")
+ endif()
+
+ add_library (legacystore SHARED
+ ${legacy_jrnl_SOURCES}
+ ${legacy_store_SOURCES}
+ ${legacy_qmf_SOURCES}
+ )
+
+ set_target_properties (legacystore PROPERTIES
+ PREFIX ""
+ COMPILE_DEFINITIONS _IN_QPID_BROKER
+ OUTPUT_NAME legacystore
+ SOVERSION ${legacystore_version}
+ INCLUDE_DIRECTORIES "${legacy_include_DIRECTORIES}"
+ )
+
+ target_link_libraries (legacystore
+ aio
+ uuid
+ qpidcommon qpidtypes qpidbroker
+ ${DB_LIBRARY}
+ )
+else (BUILD_LEGACYSTORE)
+ message(STATUS "Legacystore is excluded from build.")
+endif (BUILD_LEGACYSTORE)
diff --git a/cpp/src/posix/QpiddBroker.cpp b/cpp/src/posix/QpiddBroker.cpp
index 76e3bb6674..a681a6d18d 100644
--- a/cpp/src/posix/QpiddBroker.cpp
+++ b/cpp/src/posix/QpiddBroker.cpp
@@ -48,6 +48,10 @@ BootstrapOptions::BootstrapOptions(const char* argv0)
add(log);
}
+void BootstrapOptions::usage() const {
+ cout << "Usage: qpidd [OPTIONS]" << endl << endl << *this << endl;
+}
+
namespace {
const std::string TCP = "tcp";
}
@@ -111,17 +115,17 @@ void QpiddOptions::usage() const {
// Set the broker pointer on the signal handler, then reset at end of scope.
// This is to ensure that the signal handler doesn't keep a broker
// reference after main() has returned.
-//
+//
struct ScopedSetBroker {
ScopedSetBroker(const boost::intrusive_ptr<Broker>& broker) {
qpid::broker::SignalHandler::setBroker(broker.get());
}
~ScopedSetBroker() { qpid::broker::SignalHandler::setBroker(0); }
};
-
+
struct QpiddDaemon : public Daemon {
QpiddPosixOptions *options;
-
+
QpiddDaemon(std::string pidDir, QpiddPosixOptions *opts)
: Daemon(pidDir), options(opts) {}
@@ -129,7 +133,7 @@ struct QpiddDaemon : public Daemon {
void parent() {
uint16_t port = wait(options->daemon.wait);
if (options->parent->broker.port == 0 || options->daemon.transport != TCP)
- cout << port << endl;
+ cout << port << endl;
}
/** Code for forked child process */
@@ -140,7 +144,7 @@ struct QpiddDaemon : public Daemon {
uint16_t port=brokerPtr->getPort(options->daemon.transport);
ready(port); // Notify parent.
if (options->parent->broker.enableMgmt && (options->parent->broker.port == 0 || options->daemon.transport != TCP)) {
- dynamic_cast<qmf::org::apache::qpid::broker::Broker*>(brokerPtr->GetManagementObject())->set_port(port);
+ boost::dynamic_pointer_cast<qmf::org::apache::qpid::broker::Broker>(brokerPtr->GetManagementObject())->set_port(port);
}
brokerPtr->run();
}
@@ -162,12 +166,12 @@ int QpiddBroker::execute (QpiddOptions *options) {
QPID_LOG(notice, "Cannot stop broker: " << e.what());
return 1;
}
- if (pid < 0)
+ if (pid < 0)
return 1;
if (myOptions->daemon.check)
cout << pid << endl;
if (myOptions->daemon.quit) {
- if (kill(pid, SIGINT) < 0)
+ if (kill(pid, SIGINT) < 0)
throw Exception("Failed to stop daemon: " + qpid::sys::strError(errno));
// Wait for the process to die before returning
int retry=10000; // Try up to 10 seconds
@@ -196,7 +200,7 @@ int QpiddBroker::execute (QpiddOptions *options) {
uint16_t port = brokerPtr->getPort(myOptions->daemon.transport);
cout << port << endl;
if (options->broker.enableMgmt) {
- dynamic_cast<qmf::org::apache::qpid::broker::Broker*>(brokerPtr->GetManagementObject())->set_port(port);
+ boost::dynamic_pointer_cast<qmf::org::apache::qpid::broker::Broker>(brokerPtr->GetManagementObject())->set_port(port);
}
}
brokerPtr->run();
diff --git a/cpp/src/qpid/Modules.cpp b/cpp/src/qpid/Modules.cpp
index 727e05d212..049ededaa7 100644
--- a/cpp/src/qpid/Modules.cpp
+++ b/cpp/src/qpid/Modules.cpp
@@ -24,11 +24,7 @@
#include "qpid/Exception.h"
#include "qpid/log/Statement.h"
#include "qpid/sys/Shlib.h"
-
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-
-namespace fs=boost::filesystem;
+#include "qpid/sys/FileSysDir.h"
namespace {
@@ -43,7 +39,7 @@ inline std::string& suffix() {
}
bool isShlibName(const std::string& name) {
- return name.find (suffix()) == name.length() - suffix().length();
+ return name.substr(name.size()-suffix().size()) == suffix();
}
}
@@ -59,39 +55,40 @@ ModuleOptions::ModuleOptions(const std::string& defaultModuleDir)
("no-module-dir", optValue(noLoad), "Don't load modules from module directory");
}
-void tryShlib(const char* libname_, bool noThrow) {
- std::string libname(libname_);
- if (!isShlibName(libname)) libname += suffix();
+void tryShlib(const std::string& libname) {
+ sys::Shlib shlib( isShlibName(libname) ? libname : (libname + suffix()));
+}
+
+namespace {
+
+void tryOnlyShlib(const std::string& libname) throw() {
try {
- sys::Shlib shlib(libname);
+ if (isShlibName(libname)) sys::Shlib shlib( libname );
}
catch (const std::exception& /*e*/) {
- if (!noThrow)
- throw;
}
}
+}
+
void loadModuleDir (std::string dirname, bool isDefault)
{
- fs::path dirPath (dirname, fs::native);
- if (!fs::exists (dirPath))
+ sys::FileSysDir dirPath (dirname);
+
+ bool exists;
+ try
{
- if (isDefault)
- return;
- throw Exception ("Directory not found: " + dirname);
+ exists = dirPath.exists();
+ } catch (Exception& e) {
+ throw Exception ("Invalid value for module-dir: " + e.getMessage());
}
- if (!fs::is_directory(dirPath))
- {
- throw Exception ("Invalid value for module-dir: " + dirname + " is not a directory");
+ if (!exists) {
+ if (isDefault) return;
+ throw Exception ("Directory not found: " + dirname);
}
- fs::directory_iterator endItr;
- for (fs::directory_iterator itr (dirPath); itr != endItr; ++itr)
- {
- if (!fs::is_directory(*itr) && isShlibName(itr->string()))
- tryShlib (itr->string().data(), true);
- }
+ dirPath.forEachFile(&tryOnlyShlib);
}
} // namespace qpid
diff --git a/cpp/src/qpid/Modules.h b/cpp/src/qpid/Modules.h
index 159dd156c1..9fb91d60eb 100644
--- a/cpp/src/qpid/Modules.h
+++ b/cpp/src/qpid/Modules.h
@@ -36,7 +36,7 @@ struct ModuleOptions : public qpid::Options {
QPID_COMMON_EXTERN ModuleOptions(const std::string& defaultModuleDir);
};
-QPID_COMMON_EXTERN void tryShlib(const char* libname, bool noThrow);
+QPID_COMMON_EXTERN void tryShlib(const std::string& libname);
QPID_COMMON_EXTERN void loadModuleDir (std::string dirname, bool isDefault);
} // namespace qpid
diff --git a/cpp/src/qpid/NullSaslServer.cpp b/cpp/src/qpid/NullSaslServer.cpp
new file mode 100644
index 0000000000..40bd9ebbc6
--- /dev/null
+++ b/cpp/src/qpid/NullSaslServer.cpp
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "NullSaslServer.h"
+#include "qpid/log/Statement.h"
+#include "qpid/sys/SecurityLayer.h"
+#include <assert.h>
+#include <boost/format.hpp>
+
+namespace qpid {
+NullSaslServer::NullSaslServer(const std::string& r) : realm(r) {}
+NullSaslServer::Status NullSaslServer::start(const std::string& mechanism, const std::string* response, std::string& /*challenge*/)
+{
+ if (mechanism == "PLAIN") {
+ if (response) {
+ std::string uid;
+ std::string::size_type i = response->find((char)0);
+ if (i == 0 && response->size() > 1) {
+ //no authorization id; use authentication id
+ i = response->find((char)0, 1);
+ if (i != std::string::npos) uid = response->substr(1, i-1);
+ } else if (i != std::string::npos) {
+ //authorization id is first null delimited field
+ uid = response->substr(0, i);
+ } else {
+ QPID_LOG(error, "Invalid PLAIN request, null delimiter not found in response data");
+ return FAIL;
+ }
+ if (!uid.empty()) {
+ //append realm if it has not already been added
+ i = uid.find(realm);
+ if (i == std::string::npos || realm.size() + i < uid.size()) {
+ uid = boost::str(boost::format("%1%@%2%") % uid % realm);
+ }
+ userid = uid;
+ }
+ return OK;
+ } else {
+ QPID_LOG(error, "Invalid PLAIN request, expected response containing user credentials");
+ return FAIL;
+ }
+ } else if (mechanism == "ANONYMOUS") {
+ userid = "anonymous";
+ return OK;
+ } else {
+ return FAIL;
+ }
+}
+
+NullSaslServer::Status NullSaslServer::step(const std::string* /*response*/, std::string& /*challenge*/)
+{
+ assert(false);
+ return FAIL;
+}
+std::string NullSaslServer::getMechanisms()
+{
+ return std::string("ANONYMOUS PLAIN");
+}
+std::string NullSaslServer::getUserid()
+{
+ return userid;
+}
+
+std::auto_ptr<qpid::sys::SecurityLayer> NullSaslServer::getSecurityLayer(size_t)
+{
+ return std::auto_ptr<qpid::sys::SecurityLayer>();
+}
+
+} // namespace qpid
diff --git a/cpp/src/qpid/NullSaslServer.h b/cpp/src/qpid/NullSaslServer.h
new file mode 100644
index 0000000000..810defe574
--- /dev/null
+++ b/cpp/src/qpid/NullSaslServer.h
@@ -0,0 +1,49 @@
+#ifndef QPID_NULLSASLSERVER_H
+#define QPID_NULLSASLSERVER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/SaslServer.h"
+
+namespace qpid {
+
+/**
+ * Dummy implementation of the SASL server role. This will advertise
+ * ANONYMOUS and PLAIN, and parse the reponse data for those
+ * accordingly, but will make no attempt to actually authenticate
+ * users.
+ */
+class NullSaslServer : public SaslServer
+{
+ public:
+ NullSaslServer(const std::string& realm);
+ Status start(const std::string& mechanism, const std::string* response, std::string& challenge);
+ Status step(const std::string* response, std::string& challenge);
+ std::string getMechanisms();
+ std::string getUserid();
+ std::auto_ptr<qpid::sys::SecurityLayer> getSecurityLayer(size_t);
+ private:
+ std::string realm;
+ std::string userid;
+};
+} // namespace qpid
+
+#endif /*!QPID_NULLSASLSERVER_H*/
diff --git a/cpp/src/qpid/Options.cpp b/cpp/src/qpid/Options.cpp
index 35787aa8f3..c0e955e2b3 100644
--- a/cpp/src/qpid/Options.cpp
+++ b/cpp/src/qpid/Options.cpp
@@ -41,13 +41,13 @@ struct EnvOptMapper {
return desc->long_name().size() == env.size() &&
std::equal(env.begin(), env.end(), desc->long_name().begin(), &matchChar);
}
-
+
static bool matchCase(const string& env, boost::shared_ptr<po::option_description> desc) {
return env == desc->long_name();
}
-
+
EnvOptMapper(const Options& o) : opts(o) {}
-
+
string operator()(const string& envVar) {
static const std::string prefix("QPID_");
if (envVar.substr(0, prefix.size()) == prefix) {
@@ -74,31 +74,60 @@ struct EnvOptMapper {
}
- string configFileLine (string& line) {
-
- if ( isComment ( line ) )
- return string();
+ void badArg ( string& line ) {
+ ostringstream msg;
+ msg << "Bad argument: |" << line << "|\n";
+ throw Exception(msg.str());
+ }
+
+
+ string configFileLine (string& line, bool allowUnknowns=true) {
- size_t pos = line.find ('=');
- if (pos == string::npos)
+ if ( isComment ( line ) ) {
return string();
+ }
+
+ size_t pos = line.find ('=');
+ if (pos == string::npos) {
+ if ( allowUnknowns ) {
+ return string();
+ }
+ else {
+ badArg ( line );
+ }
+ }
string key = line.substr (0, pos);
#if (BOOST_VERSION >= 103300)
typedef const std::vector< boost::shared_ptr<po::option_description> > OptDescs;
- OptDescs::const_iterator i =
+ OptDescs::const_iterator i =
find_if(opts.options().begin(), opts.options().end(), boost::bind(matchCase, key, _1));
if (i != opts.options().end())
return string (line) + "\n";
- else
- return string();
+ else {
+ if ( allowUnknowns ) {
+ return string();
+ }
+ else {
+ badArg ( line );
+ }
+ }
#else
- // Use 'count' to see if this option exists. Using 'find' will SEGV or hang
- // if the option has not been defined yet.
+ // Use 'count' to see if this option exists. Using 'find' will
+ // SEGV or hang if the option has not been defined yet.
if ( opts.count(key.c_str()) > 0 )
return string ( line ) + "\n";
- else
- return string ( );
+ else {
+ if ( allowUnknowns ) {
+ return string ( );
+ }
+ else {
+ badArg ( line );
+ }
+ }
#endif
+ // Control will not arrive here, but the compiler things it could.
+ // Calls to badArg(), that I used above, throw.
+ return string();
}
const Options& opts;
@@ -109,8 +138,8 @@ std::string prettyArg(const std::string& name, const std::string& value) {
return value.empty() ? name+" " : name+" ("+value+") ";
}
-Options::Options(const string& name) :
- po::options_description(name)
+Options::Options(const string& name) :
+ po::options_description(name)
{
}
@@ -150,6 +179,7 @@ void Options::parse(int argc, char const* const* argv, const std::string& config
if (!configFile.empty()) {
parsing="configuration file "+configFile;
ifstream conf(configFile.c_str());
+ conf.peek();
if (conf.good()) {
// Remove this hack when we get a stable version of boost that
// can allow unregistered options in config files.
@@ -159,7 +189,7 @@ void Options::parse(int argc, char const* const* argv, const std::string& config
while (!conf.eof()) {
string line;
getline (conf, line);
- filtered << mapper.configFileLine (line);
+ filtered << mapper.configFileLine (line, allowUnknown);
}
po::store(po::parse_config_file(filtered, *this), vm);
@@ -197,5 +227,33 @@ CommonOptions::CommonOptions(const string& name, const string& configfile, const
}
+
+bool Options::findArg(int argc, char const* const* argv, const std::string& theArg)
+{
+ const string parsing("command line options");
+ bool result(false);
+ try {
+ if (argc > 0 && argv != 0) {
+ po::command_line_parser clp = po::command_line_parser(argc, const_cast<char**>(argv)).
+ options(*this).allow_unregistered();
+ po::parsed_options opts = clp.run();
+
+ for (std::vector< po::basic_option<char> >::iterator
+ i = opts.options.begin(); i != opts.options.end(); i++) {
+ if (theArg.compare(i->string_key) == 0) {
+ result = true;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+ catch (const std::exception& e) {
+ ostringstream msg;
+ msg << "Error in " << parsing << ": " << e.what() << endl;
+ throw Exception(msg.str());
+ }
+}
+
} // namespace qpid
diff --git a/cpp/src/qpid/Sasl.h b/cpp/src/qpid/Sasl.h
index 4d579fa051..efda92d718 100644
--- a/cpp/src/qpid/Sasl.h
+++ b/cpp/src/qpid/Sasl.h
@@ -34,7 +34,7 @@ struct SecuritySettings;
}
/**
- * Interface to SASL support. This class is implemented by platform-specific
+ * Interface to support for the SASL client role. This class is implemented by platform-specific
* SASL providers.
*/
class Sasl
diff --git a/cpp/src/qpid/SaslFactory.cpp b/cpp/src/qpid/SaslFactory.cpp
index a8d1f94c1e..4d81a793ee 100644
--- a/cpp/src/qpid/SaslFactory.cpp
+++ b/cpp/src/qpid/SaslFactory.cpp
@@ -7,9 +7,9 @@
* 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
@@ -18,7 +18,9 @@
* under the License.
*
*/
-#include "qpid//SaslFactory.h"
+#include "qpid/SaslFactory.h"
+#include "qpid/SaslServer.h"
+#include "qpid/NullSaslServer.h"
#include <map>
#include <string.h>
@@ -32,6 +34,7 @@ namespace qpid {
//Null implementation
+
SaslFactory::SaslFactory() {}
SaslFactory::~SaslFactory() {}
@@ -50,6 +53,12 @@ std::auto_ptr<Sasl> SaslFactory::create( const std::string &, const std::string
return std::auto_ptr<Sasl>();
}
+std::auto_ptr<SaslServer> SaslFactory::createServer(const std::string& realm, bool /*encryptionRequired*/, const qpid::sys::SecuritySettings&)
+{
+ std::auto_ptr<SaslServer> server(new NullSaslServer(realm));
+ return server;
+}
+
qpid::sys::Mutex SaslFactory::lock;
std::auto_ptr<SaslFactory> SaslFactory::instance;
@@ -140,6 +149,22 @@ typedef int CallbackProc();
qpid::sys::Mutex SaslFactory::lock;
std::auto_ptr<SaslFactory> SaslFactory::instance;
+class CyrusSaslServer : public SaslServer
+{
+ public:
+ CyrusSaslServer(const std::string& realm, bool encryptionRequired, const qpid::sys::SecuritySettings& external);
+ ~CyrusSaslServer();
+ Status start(const std::string& mechanism, const std::string* response, std::string& challenge);
+ Status step(const std::string* response, std::string& challenge);
+ std::string getMechanisms();
+ std::string getUserid();
+ std::auto_ptr<qpid::sys::SecurityLayer> getSecurityLayer(size_t);
+ private:
+ std::string realm;
+ std::string userid;
+ sasl_conn_t *sasl_conn;
+};
+
SaslFactory::SaslFactory()
{
sasl_callback_t* callbacks = 0;
@@ -169,6 +194,12 @@ std::auto_ptr<Sasl> SaslFactory::create(const std::string & username, const std:
return sasl;
}
+std::auto_ptr<SaslServer> SaslFactory::createServer(const std::string& realm, bool encryptionRequired, const qpid::sys::SecuritySettings& external)
+{
+ std::auto_ptr<SaslServer> server(new CyrusSaslServer(realm, encryptionRequired, external));
+ return server;
+}
+
CyrusSasl::CyrusSasl(const std::string & username, const std::string & password, const std::string & serviceName, const std::string & hostName, int minSsf, int maxSsf, bool allowInteraction)
: conn(0), settings(username, password, serviceName, hostName, minSsf, maxSsf), allowInteraction(allowInteraction)
{
@@ -377,7 +408,180 @@ std::auto_ptr<SecurityLayer> CyrusSasl::getSecurityLayer(uint16_t maxFrameSize)
std::auto_ptr<SecurityLayer> securityLayer;
if (ssf) {
QPID_LOG(info, "Installing security layer, SSF: "<< ssf);
- securityLayer = std::auto_ptr<SecurityLayer>(new CyrusSecurityLayer(conn, maxFrameSize));
+ securityLayer = std::auto_ptr<SecurityLayer>(new CyrusSecurityLayer(conn, maxFrameSize, ssf));
+ }
+ return securityLayer;
+}
+
+CyrusSaslServer::CyrusSaslServer(const std::string& r, bool encryptionRequired, const qpid::sys::SecuritySettings& external) : realm(r), sasl_conn(0)
+{
+ int code = sasl_server_new(BROKER_SASL_NAME, /* Service name */
+ NULL, /* Server FQDN, gethostname() */
+ realm.c_str(), /* Authentication realm */
+ NULL, /* Local IP, needed for some mechanism */
+ NULL, /* Remote IP, needed for some mechanism */
+ NULL, /* Callbacks */
+ 0, /* Connection flags */
+ &sasl_conn);
+
+ if (SASL_OK != code) {
+ QPID_LOG(error, "SASL: Connection creation failed: [" << code << "] " << sasl_errdetail(sasl_conn));
+
+ // TODO: Change this to an exception signaling
+ // server error, when one is available
+ throw qpid::framing::ConnectionForcedException("Unable to perform authentication");
+ }
+
+ sasl_security_properties_t secprops;
+
+ //TODO: should the actual SSF values be configurable here?
+ secprops.min_ssf = encryptionRequired ? 10: 0;
+ secprops.max_ssf = 256;
+
+ // If the transport provides encryption, notify the SASL library of
+ // the key length and set the ssf range to prevent double encryption.
+ QPID_LOG(debug, "External ssf=" << external.ssf << " and auth=" << external.authid);
+ sasl_ssf_t external_ssf = (sasl_ssf_t) external.ssf;
+ if (external_ssf) {
+ int result = sasl_setprop(sasl_conn, SASL_SSF_EXTERNAL, &external_ssf);
+ if (result != SASL_OK) {
+ throw framing::InternalErrorException(QPID_MSG("SASL error: unable to set external SSF: " << result));
+ }
+
+ secprops.max_ssf = secprops.min_ssf = 0;
+ }
+
+ QPID_LOG(debug, "min_ssf: " << secprops.min_ssf <<
+ ", max_ssf: " << secprops.max_ssf <<
+ ", external_ssf: " << external_ssf );
+
+ if (!external.authid.empty()) {
+ const char* external_authid = external.authid.c_str();
+ int result = sasl_setprop(sasl_conn, SASL_AUTH_EXTERNAL, external_authid);
+ if (result != SASL_OK) {
+ throw framing::InternalErrorException(QPID_MSG("SASL error: unable to set external auth: " << result));
+ }
+
+ QPID_LOG(debug, "external auth detected and set to " << external_authid);
+ }
+ secprops.maxbufsize = 65535;
+ secprops.property_names = 0;
+ secprops.property_values = 0;
+ secprops.security_flags = 0; /* or SASL_SEC_NOANONYMOUS etc as appropriate */
+ /*
+ * The nodict flag restricts SASL authentication mechanisms
+ * to those that are not susceptible to dictionary attacks.
+ * They are:
+ * SRP
+ * PASSDSS-3DES-1
+ * EXTERNAL
+ */
+ if (external.nodict) secprops.security_flags |= SASL_SEC_NODICTIONARY;
+ int result = sasl_setprop(sasl_conn, SASL_SEC_PROPS, &secprops);
+ if (result != SASL_OK) {
+ throw framing::InternalErrorException(QPID_MSG("SASL error: " << result));
+ }
+}
+
+CyrusSaslServer::~CyrusSaslServer()
+{
+ if (sasl_conn) {
+ sasl_dispose(&sasl_conn);
+ sasl_conn = 0;
+ }
+}
+
+CyrusSaslServer::Status CyrusSaslServer::start(const std::string& mechanism, const std::string* response, std::string& chllng)
+{
+ const char *challenge;
+ unsigned int challenge_len;
+
+ // This should be at same debug level as mech list in getMechanisms().
+ QPID_LOG(info, "SASL: Starting authentication with mechanism: " << mechanism);
+ int code = sasl_server_start(sasl_conn,
+ mechanism.c_str(),
+ (response ? response->c_str() : 0), (response ? response->size() : 0),
+ &challenge, &challenge_len);
+ switch (code) {
+ case SASL_OK:
+ return SaslServer::OK;
+ case SASL_CONTINUE:
+ chllng = std::string(challenge, challenge_len);
+ return SaslServer::CHALLENGE;
+ case SASL_NOMECH:
+ QPID_LOG(info, "Unsupported mechanism: " << mechanism);
+ default:
+ return SaslServer::FAIL;
+ }
+}
+
+CyrusSaslServer::Status CyrusSaslServer::step(const std::string* response, std::string& chllng)
+{
+ const char *challenge;
+ unsigned int challenge_len;
+
+ int code = sasl_server_step(sasl_conn,
+ (response ? response->c_str() : 0), (response ? response->size() : 0),
+ &challenge, &challenge_len);
+
+ switch (code) {
+ case SASL_OK:
+ return SaslServer::OK;
+ case SASL_CONTINUE:
+ chllng = std::string(challenge, challenge_len);
+ return SaslServer::CHALLENGE;
+ default:
+ return SaslServer::FAIL;
+ }
+
+}
+std::string CyrusSaslServer::getMechanisms()
+{
+ const char *separator = " ";
+ const char *list;
+ unsigned int list_len;
+ int count;
+
+ int code = sasl_listmech(sasl_conn, NULL,
+ "", separator, "",
+ &list, &list_len,
+ &count);
+
+ if (SASL_OK != code) {
+ QPID_LOG(info, "SASL: Mechanism listing failed: " << sasl_errdetail(sasl_conn));
+
+ // TODO: Change this to an exception signaling
+ // server error, when one is available
+ throw qpid::framing::ConnectionForcedException("Mechanism listing failed");
+ } else {
+ std::string mechanisms(list, list_len);
+ QPID_LOG(info, "SASL: Mechanism list: " << mechanisms);
+ return mechanisms;
+ }
+}
+std::string CyrusSaslServer::getUserid()
+{
+ const void* ptr;
+ int code = sasl_getprop(sasl_conn, SASL_USERNAME, &ptr);
+ if (SASL_OK == code) {
+ userid = static_cast<const char*>(ptr);
+ } else {
+ QPID_LOG(warning, "Failed to retrieve sasl username");
+ }
+ return userid;
+}
+
+std::auto_ptr<SecurityLayer> CyrusSaslServer::getSecurityLayer(size_t maxFrameSize)
+{
+ const void* value(0);
+ int result = sasl_getprop(sasl_conn, SASL_SSF, &value);
+ if (result != SASL_OK) {
+ throw framing::InternalErrorException(QPID_MSG("SASL error: " << sasl_errdetail(sasl_conn)));
+ }
+ uint ssf = *(reinterpret_cast<const unsigned*>(value));
+ std::auto_ptr<SecurityLayer> securityLayer;
+ if (ssf) {
+ securityLayer = std::auto_ptr<SecurityLayer>(new CyrusSecurityLayer(sasl_conn, maxFrameSize, ssf));
}
return securityLayer;
}
@@ -428,7 +632,6 @@ int getPasswordFromSettings(sasl_conn_t* conn, void* context, int /*id*/, sasl_s
return SASL_FAIL;
}
}
-
} // namespace qpid
#endif
diff --git a/cpp/src/qpid/SaslFactory.h b/cpp/src/qpid/SaslFactory.h
index 8554597147..da7e892f1d 100644
--- a/cpp/src/qpid/SaslFactory.h
+++ b/cpp/src/qpid/SaslFactory.h
@@ -26,7 +26,7 @@
#include <memory>
namespace qpid {
-
+class SaslServer;
/**
* Factory for instances of the Sasl interface through which Sasl
* support is provided to a ConnectionHandler.
@@ -35,6 +35,7 @@ class SaslFactory
{
public:
QPID_COMMON_EXTERN std::auto_ptr<Sasl> create(const std::string & userName, const std::string & password, const std::string & serviceName, const std::string & hostName, int minSsf, int maxSsf, bool allowInteraction=true );
+ QPID_COMMON_EXTERN std::auto_ptr<SaslServer> createServer(const std::string& realm, bool encryptionRequired, const qpid::sys::SecuritySettings&);
QPID_COMMON_EXTERN static SaslFactory& getInstance();
QPID_COMMON_EXTERN ~SaslFactory();
private:
diff --git a/cpp/src/qpid/SaslServer.h b/cpp/src/qpid/SaslServer.h
new file mode 100644
index 0000000000..a707a468eb
--- /dev/null
+++ b/cpp/src/qpid/SaslServer.h
@@ -0,0 +1,48 @@
+#ifndef QPID_SASLSERVER_H
+#define QPID_SASLSERVER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <string>
+#include <memory>
+
+namespace qpid {
+namespace sys {
+class SecurityLayer;
+}
+/**
+ *
+ */
+class SaslServer
+{
+ public:
+ typedef enum {OK, FAIL, CHALLENGE} Status;
+ virtual ~SaslServer() {}
+ virtual Status start(const std::string& mechanism, const std::string* response, std::string& challenge) = 0;
+ virtual Status step(const std::string* response, std::string& challenge) = 0;
+ virtual std::string getMechanisms() = 0;
+ virtual std::string getUserid() = 0;
+ virtual std::auto_ptr<qpid::sys::SecurityLayer> getSecurityLayer(size_t) = 0;
+ private:
+};
+} // namespace qpid
+
+#endif /*!QPID_SASLSERVER_H*/
diff --git a/cpp/src/qpid/Url.cpp b/cpp/src/qpid/Url.cpp
index 840f46e928..21de32aaa3 100644
--- a/cpp/src/qpid/Url.cpp
+++ b/cpp/src/qpid/Url.cpp
@@ -64,19 +64,6 @@ class ProtocolTags {
Url::Invalid::Invalid(const string& s) : Exception(s) {}
-Url Url::getHostNameUrl(uint16_t port) {
- Address address("tcp", std::string(), port);
- if (!sys::SystemInfo::getLocalHostname(address))
- throw Url::Invalid(QPID_MSG("Cannot get host name: " << qpid::sys::strError(errno)));
- return Url(address);
-}
-
-Url Url::getIpAddressesUrl(uint16_t port) {
- Url url;
- sys::SystemInfo::getLocalIpAddresses(port, url);
- return url;
-}
-
string Url::str() const {
if (cache.empty() && !this->empty()) {
ostringstream os;
diff --git a/cpp/src/qpid/UrlArray.h b/cpp/src/qpid/UrlArray.h
index ce9e42f248..f0065f0f0c 100644
--- a/cpp/src/qpid/UrlArray.h
+++ b/cpp/src/qpid/UrlArray.h
@@ -1,5 +1,5 @@
-#ifndef QPID_CLUSTER_URLARRAY_H
-#define QPID_CLUSTER_URLARRAY_H
+#ifndef QPID_URLARRAY_H
+#define QPID_URLARRAY_H
/*
*
@@ -33,4 +33,4 @@ QPID_COMMON_EXTERN std::vector<Url> urlArrayToVector(const framing::Array& array
QPID_COMMON_EXTERN framing::Array vectorToUrlArray(const std::vector<Url>& urls);
} // namespace qpid
-#endif /* !QPID_CLUSTER_URLARRAY_H */
+#endif /* !QPID_URLARRAY_H */
diff --git a/cpp/src/qpid/acl/Acl.cpp b/cpp/src/qpid/acl/Acl.cpp
index 89c4b3402a..31ad9a38ac 100644
--- a/cpp/src/qpid/acl/Acl.cpp
+++ b/cpp/src/qpid/acl/Acl.cpp
@@ -18,11 +18,13 @@
#include "qpid/acl/Acl.h"
#include "qpid/acl/AclConnectionCounter.h"
+#include "qpid/acl/AclResourceCounter.h"
#include "qpid/acl/AclData.h"
#include "qpid/acl/AclValidator.h"
#include "qpid/sys/Mutex.h"
#include "qpid/broker/Broker.h"
+#include "qpid/broker/Connection.h"
#include "qpid/Plugin.h"
#include "qpid/Options.h"
#include "qpid/log/Logger.h"
@@ -32,6 +34,7 @@
#include "qmf/org/apache/qpid/acl/Package.h"
#include "qmf/org/apache/qpid/acl/EventAllow.h"
#include "qmf/org/apache/qpid/acl/EventConnectionDeny.h"
+#include "qmf/org/apache/qpid/acl/EventQueueQuotaDeny.h"
#include "qmf/org/apache/qpid/acl/EventDeny.h"
#include "qmf/org/apache/qpid/acl/EventFileLoaded.h"
#include "qmf/org/apache/qpid/acl/EventFileLoadFailed.h"
@@ -50,19 +53,29 @@ using qpid::management::Manageable;
using qpid::management::Args;
namespace _qmf = qmf::org::apache::qpid::acl;
-Acl::Acl (AclValues& av, Broker& b): aclValues(av), broker(&b), transferAcl(false), mgmtObject(0),
- connectionCounter(new ConnectionCounter(*this, aclValues.aclMaxConnectPerUser, aclValues.aclMaxConnectPerIp, aclValues.aclMaxConnectTotal))
-{
+Acl::Acl (AclValues& av, Broker& b): aclValues(av), broker(&b), transferAcl(false),
+ connectionCounter(new ConnectionCounter(*this, aclValues.aclMaxConnectPerUser, aclValues.aclMaxConnectPerIp, aclValues.aclMaxConnectTotal)),
+ resourceCounter(new ResourceCounter(*this, aclValues.aclMaxQueuesPerUser)){
+
+ if (aclValues.aclMaxConnectPerUser > AclData::getConnectMaxSpec())
+ throw Exception("--connection-limit-per-user switch cannot be larger than " + AclData::getMaxConnectSpecStr());
+ if (aclValues.aclMaxConnectPerIp > AclData::getConnectMaxSpec())
+ throw Exception("--connection-limit-per-ip switch cannot be larger than " + AclData::getMaxConnectSpecStr());
+ if (aclValues.aclMaxConnectTotal > AclData::getConnectMaxSpec())
+ throw Exception("--max-connections switch cannot be larger than " + AclData::getMaxConnectSpecStr());
+ if (aclValues.aclMaxQueuesPerUser > AclData::getConnectMaxSpec())
+ throw Exception("--max-queues-per-user switch cannot be larger than " + AclData::getMaxConnectSpecStr());
agent = broker->getManagementAgent();
if (agent != 0){
_qmf::Package packageInit(agent);
- mgmtObject = new _qmf::Acl (agent, this, broker);
+ mgmtObject = _qmf::Acl::shared_ptr(new _qmf::Acl (agent, this, broker));
agent->addObject (mgmtObject);
mgmtObject->set_maxConnections(aclValues.aclMaxConnectTotal);
mgmtObject->set_maxConnectionsPerIp(aclValues.aclMaxConnectPerIp);
mgmtObject->set_maxConnectionsPerUser(aclValues.aclMaxConnectPerUser);
+ mgmtObject->set_maxQueuesPerUser(aclValues.aclMaxQueuesPerUser);
}
std::string errorString;
if (!readAclFile(errorString)){
@@ -84,6 +97,15 @@ void Acl::reportConnectLimit(const std::string user, const std::string addr)
}
+void Acl::reportQueueLimit(const std::string user, const std::string queueName)
+{
+ if (mgmtObject!=0)
+ mgmtObject->inc_queueQuotaDenyCount();
+
+ agent->raiseEvent(_qmf::EventQueueQuotaDeny(user, queueName));
+}
+
+
bool Acl::authorise(
const std::string& id,
const Action& action,
@@ -126,13 +148,29 @@ bool Acl::authorise(
bool Acl::approveConnection(const qpid::broker::Connection& conn)
{
- return connectionCounter->approveConnection(conn);
+ const std::string& userName(conn.getUserId());
+ uint16_t connectionLimit(0);
+
+ boost::shared_ptr<AclData> dataLocal;
+ {
+ Mutex::ScopedLock locker(dataLock);
+ dataLocal = data; //rcu copy
+ }
+
+ bool enforcingConnQuotas = dataLocal->getConnQuotaForUser(userName, &connectionLimit);
+
+ return connectionCounter->approveConnection(conn, enforcingConnQuotas, connectionLimit);
+}
+
+bool Acl::approveCreateQueue(const std::string& userId, const std::string& queueName)
+{
+ return resourceCounter->approveCreateQueue(userId, queueName);
}
-void Acl::setUserId(const qpid::broker::Connection& connection, const std::string& username)
+void Acl::recordDestroyQueue(const std::string& queueName)
{
- connectionCounter->setUserId(connection, username);
+ resourceCounter->recordDestroyQueue(queueName);
}
@@ -190,7 +228,7 @@ bool Acl::readAclFile(std::string& errorText)
bool Acl::readAclFile(std::string& aclFile, std::string& errorText) {
boost::shared_ptr<AclData> d(new AclData);
- AclReader ar;
+ AclReader ar(aclValues.aclMaxConnectPerUser);
if (ar.read(aclFile, d)){
agent->raiseEvent(_qmf::EventFileLoadFailed("", ar.getError()));
errorText = ar.getError();
@@ -211,6 +249,10 @@ bool Acl::readAclFile(std::string& aclFile, std::string& errorText) {
QPID_LOG(debug,"ACL: Transfer ACL is Enabled!");
}
+ if (data->enforcingConnectionQuotas()){
+ QPID_LOG(debug, "ACL: Connection quotas are Enabled.");
+ }
+
data->aclSource = aclFile;
if (mgmtObject!=0){
mgmtObject->set_transferAcl(transferAcl?1:0);
@@ -300,9 +342,9 @@ Acl::~Acl(){
broker->getConnectionObservers().remove(connectionCounter);
}
-ManagementObject* Acl::GetManagementObject(void) const
+ManagementObject::shared_ptr Acl::GetManagementObject(void) const
{
- return (ManagementObject*) mgmtObject;
+ return mgmtObject;
}
Manageable::status_t Acl::ManagementMethod (uint32_t methodId, Args& args, string& text)
diff --git a/cpp/src/qpid/acl/Acl.h b/cpp/src/qpid/acl/Acl.h
index 4787934275..ea3c6586a3 100644
--- a/cpp/src/qpid/acl/Acl.h
+++ b/cpp/src/qpid/acl/Acl.h
@@ -43,12 +43,14 @@ class Connection;
namespace acl {
class ConnectionCounter;
+class ResourceCounter;
struct AclValues {
std::string aclFile;
uint16_t aclMaxConnectPerUser;
uint16_t aclMaxConnectPerIp;
uint16_t aclMaxConnectTotal;
+ uint16_t aclMaxQueuesPerUser;
};
@@ -60,10 +62,11 @@ private:
broker::Broker* broker;
bool transferAcl;
boost::shared_ptr<AclData> data;
- qmf::org::apache::qpid::acl::Acl* mgmtObject; // mgnt owns lifecycle
+ qmf::org::apache::qpid::acl::Acl::shared_ptr mgmtObject;
qpid::management::ManagementAgent* agent;
mutable qpid::sys::Mutex dataLock;
boost::shared_ptr<ConnectionCounter> connectionCounter;
+ boost::shared_ptr<ResourceCounter> resourceCounter;
public:
Acl (AclValues& av, broker::Broker& b);
@@ -72,11 +75,16 @@ public:
* issue management counts and alerts for denied connections
*/
void reportConnectLimit(const std::string user, const std::string addr);
+ void reportQueueLimit(const std::string user, const std::string queueName);
inline virtual bool doTransferAcl() {
return transferAcl;
};
+ inline virtual uint16_t getMaxConnectTotal() {
+ return aclValues.aclMaxConnectTotal;
+ };
+
// create specilied authorise methods for cases that need faster matching as needed.
virtual bool authorise(
const std::string& id,
@@ -92,9 +100,10 @@ public:
const std::string& ExchangeName,
const std::string& RoutingKey);
+ // Resource quota tracking
virtual bool approveConnection(const broker::Connection& connection);
-
- virtual void setUserId(const broker::Connection& connection, const std::string& username);
+ virtual bool approveCreateQueue(const std::string& userId, const std::string& queueName);
+ virtual void recordDestroyQueue(const std::string& queueName);
virtual ~Acl();
private:
@@ -108,7 +117,7 @@ private:
bool readAclFile(std::string& aclFile, std::string& errorText);
Manageable::status_t lookup (management::Args& args, std::string& text);
Manageable::status_t lookupPublish(management::Args& args, std::string& text);
- virtual qpid::management::ManagementObject* GetManagementObject(void) const;
+ virtual qpid::management::ManagementObject::shared_ptr GetManagementObject(void) const;
virtual management::Manageable::status_t ManagementMethod (uint32_t methodId, management::Args& args, std::string& text);
};
diff --git a/cpp/src/qpid/acl/AclConnectionCounter.cpp b/cpp/src/qpid/acl/AclConnectionCounter.cpp
index 8c6e3eef6e..875137bf55 100644
--- a/cpp/src/qpid/acl/AclConnectionCounter.cpp
+++ b/cpp/src/qpid/acl/AclConnectionCounter.cpp
@@ -85,32 +85,32 @@ bool ConnectionCounter::limitApproveLH(
//
// countConnectionLH
//
-// Increment the name's count in map and return a comparison against the limit.
-// called with dataLock already taken
+// Increment the name's count in map and return an optional comparison
+// against a connection limit.
+// Called with dataLock already taken.
//
bool ConnectionCounter::countConnectionLH(
connectCountsMap_t& theMap,
const std::string& theName,
uint16_t theLimit,
- bool emitLog) {
+ bool emitLog,
+ bool enforceLimit) {
bool result(true);
uint16_t count(0);
- if (theLimit > 0) {
- connectCountsMap_t::iterator eRef = theMap.find(theName);
- if (eRef != theMap.end()) {
- count = (uint16_t)(*eRef).second + 1;
- (*eRef).second = count;
- result = count <= theLimit;
- } else {
- theMap[theName] = count = 1;
- }
- if (emitLog) {
- QPID_LOG(trace, "ACL ConnectionApprover user=" << theName
- << " limit=" << theLimit
- << " curValue=" << count
- << " result=" << (result ? "allow" : "deny"));
- }
+ connectCountsMap_t::iterator eRef = theMap.find(theName);
+ if (eRef != theMap.end()) {
+ count = (uint16_t)(*eRef).second + 1;
+ (*eRef).second = count;
+ result = (enforceLimit ? count <= theLimit : true);
+ } else {
+ theMap[theName] = count = 1;
+ }
+ if (emitLog) {
+ QPID_LOG(trace, "ACL ConnectionApprover user=" << theName
+ << " limit=" << theLimit
+ << " curValue=" << count
+ << " result=" << (result ? "allow" : "deny"));
}
return result;
}
@@ -123,23 +123,21 @@ bool ConnectionCounter::countConnectionLH(
// called with dataLock already taken
//
void ConnectionCounter::releaseLH(
- connectCountsMap_t& theMap, const std::string& theName, uint16_t theLimit) {
-
- if (theLimit > 0) {
- connectCountsMap_t::iterator eRef = theMap.find(theName);
- if (eRef != theMap.end()) {
- uint16_t count = (uint16_t) (*eRef).second;
- assert (count > 0);
- if (1 == count) {
- theMap.erase (eRef);
- } else {
- (*eRef).second = count - 1;
- }
+ connectCountsMap_t& theMap, const std::string& theName) {
+
+ connectCountsMap_t::iterator eRef = theMap.find(theName);
+ if (eRef != theMap.end()) {
+ uint16_t count = (uint16_t) (*eRef).second;
+ assert (count > 0);
+ if (1 == count) {
+ theMap.erase (eRef);
} else {
- // User had no connections.
- QPID_LOG(notice, "ACL ConnectionCounter Connection for '" << theName
- << "' not found in connection count pool");
+ (*eRef).second = count - 1;
}
+ } else {
+ // User had no connections.
+ QPID_LOG(notice, "ACL ConnectionCounter Connection for '" << theName
+ << "' not found in connection count pool");
}
}
@@ -161,7 +159,7 @@ void ConnectionCounter::connection(broker::Connection& connection) {
connectProgressMap[connection.getMgmtId()] = C_CREATED;
// Count the connection from this host.
- (void) countConnectionLH(connectByHostMap, hostName, hostLimit, false);
+ (void) countConnectionLH(connectByHostMap, hostName, hostLimit, false, false);
}
@@ -180,8 +178,7 @@ void ConnectionCounter::closed(broker::Connection& connection) {
// Normal case: connection was created and opened.
// Decrement user in-use counts
releaseLH(connectByNameMap,
- connection.getUserId(),
- nameLimit);
+ connection.getUserId());
} else {
// Connection was created but not opened.
// Don't decrement user count.
@@ -189,8 +186,7 @@ void ConnectionCounter::closed(broker::Connection& connection) {
// Decrement host in-use count.
releaseLH(connectByHostMap,
- getClientHost(connection.getMgmtId()),
- hostLimit);
+ getClientHost(connection.getMgmtId()));
// destroy connection progress indicator
connectProgressMap.erase(eRef);
@@ -211,7 +207,10 @@ void ConnectionCounter::closed(broker::Connection& connection) {
// check total connections, connections from IP, connections by user and
// disallow if over any limit
//
-bool ConnectionCounter::approveConnection(const broker::Connection& connection)
+bool ConnectionCounter::approveConnection(
+ const broker::Connection& connection,
+ bool enforcingConnectionQuotas,
+ uint16_t connectionUserQuota )
{
const std::string& hostName(getClientHost(connection.getMgmtId()));
const std::string& userName( connection.getUserId());
@@ -220,122 +219,53 @@ bool ConnectionCounter::approveConnection(const broker::Connection& connection)
// Bump state from CREATED to OPENED
(void) countConnectionLH(connectProgressMap, connection.getMgmtId(),
- C_OPENED, false);
+ C_OPENED, false, false);
// Approve total connections
bool okTotal = true;
if (totalLimit > 0) {
okTotal = totalCurrentConnections <= totalLimit;
- if (!connection.isShadow()) {
- QPID_LOG(trace, "ACL ConnectionApprover totalLimit=" << totalLimit
- << " curValue=" << totalCurrentConnections
- << " result=" << (okTotal ? "allow" : "deny"));
- }
+ QPID_LOG(trace, "ACL ConnectionApprover totalLimit=" << totalLimit
+ << " curValue=" << totalCurrentConnections
+ << " result=" << (okTotal ? "allow" : "deny"));
}
// Approve by IP host connections
- bool okByIP = limitApproveLH(connectByHostMap, hostName, hostLimit, !connection.isShadow());
+ bool okByIP = limitApproveLH(connectByHostMap, hostName, hostLimit, true);
// Count and Approve the connection by the user
- bool okByUser = countConnectionLH(connectByNameMap, userName, nameLimit, !connection.isShadow());
-
- if (!connection.isShadow()) {
- // Emit separate log for each disapproval
- if (!okTotal) {
- QPID_LOG(error, "Client max total connection count limit of " << totalLimit
- << " exceeded by '"
- << connection.getMgmtId() << "', user: '"
- << userName << "'. Connection refused");
- }
- if (!okByIP) {
- QPID_LOG(error, "Client max per-host connection count limit of "
- << hostLimit << " exceeded by '"
- << connection.getMgmtId() << "', user: '"
- << userName << "'. Connection refused.");
- }
- if (!okByUser) {
- QPID_LOG(error, "Client max per-user connection count limit of "
- << nameLimit << " exceeded by '"
- << connection.getMgmtId() << "', user: '"
- << userName << "'. Connection refused.");
- }
-
- // Count/Event once for each disapproval
- bool result = okTotal && okByIP && okByUser;
- if (!result) {
- acl.reportConnectLimit(userName, hostName);
- }
-
- return result;
- } else {
- // Always allow shadow connections
- if (!okTotal) {
- QPID_LOG(warning, "Client max total connection count limit of " << totalLimit
- << " exceeded by '"
- << connection.getMgmtId() << "', user: '"
- << userName << "' but still within tolerance. Cluster connection allowed");
- }
- if (!okByIP) {
- QPID_LOG(warning, "Client max per-host connection count limit of "
- << hostLimit << " exceeded by '"
- << connection.getMgmtId() << "', user: '"
- << userName << "' but still within tolerance. Cluster connection allowed");
- }
- if (!okByUser) {
- QPID_LOG(warning, "Client max per-user connection count limit of "
- << nameLimit << " exceeded by '"
- << connection.getMgmtId() << "', user: '"
- << userName << "' but still within tolerance. Cluster connection allowed");
- }
- if (okTotal && okByIP && okByUser) {
- QPID_LOG(debug, "Cluster client connection: '"
- << connection.getMgmtId() << "', user '"
- << userName << "' allowed");
- }
- return true;
+ bool okByUser = countConnectionLH(connectByNameMap, userName,
+ connectionUserQuota, true,
+ enforcingConnectionQuotas);
+
+ // Emit separate log for each disapproval
+ if (!okTotal) {
+ QPID_LOG(error, "Client max total connection count limit of " << totalLimit
+ << " exceeded by '"
+ << connection.getMgmtId() << "', user: '"
+ << userName << "'. Connection refused");
+ }
+ if (!okByIP) {
+ QPID_LOG(error, "Client max per-host connection count limit of "
+ << hostLimit << " exceeded by '"
+ << connection.getMgmtId() << "', user: '"
+ << userName << "'. Connection refused.");
+ }
+ if (!okByUser) {
+ QPID_LOG(error, "Client max per-user connection count limit of "
+ << connectionUserQuota << " exceeded by '"
+ << connection.getMgmtId() << "', user: '"
+ << userName << "'. Connection refused.");
}
-}
-
-
-//
-// setUserId
-// On cluster shadow connections, track a new user id for this connection.
-//
-void ConnectionCounter::setUserId(const broker::Connection& connection,
- const std::string& username)
-{
- Mutex::ScopedLock locker(dataLock);
- connectCountsMap_t::iterator eRef = connectProgressMap.find(connection.getMgmtId());
- if (eRef != connectProgressMap.end()) {
- if ((*eRef).second == C_OPENED){
- // Connection has been opened so that current user has been counted
- if (connection.isShadow()) {
- // This is a shadow connection and therefore receives userId changes
- QPID_LOG(debug, "Changing User ID for cluster connection: "
- << connection.getMgmtId() << ", old user:'" << connection.getUserId()
- << "', new user:'" << username << "'");
-
- // Decrement user in-use count for old userId
- releaseLH(connectByNameMap,
- connection.getUserId(),
- nameLimit);
- // Increment user in-use count for new userId
- (void) countConnectionLH(connectByNameMap, username, nameLimit, false);
- } else {
- QPID_LOG(warning, "Changing User ID for non-cluster connections is not supported: "
- << connection.getMgmtId() << ", old user " << connection.getUserId()
- << ", new user " << username);
- }
- } else {
- // connection exists but has not been opened.
- // setUserId is called in normal course. The user gets counted when connection is opened.
- }
- } else {
- // Connection does not exist.
+ // Count/Event once for each disapproval
+ bool result = okTotal && okByIP && okByUser;
+ if (!result) {
+ acl.reportConnectLimit(userName, hostName);
}
-}
+ return result;
+}
//
// getClientIp - given a connection's mgmtId return the client host part.
diff --git a/cpp/src/qpid/acl/AclConnectionCounter.h b/cpp/src/qpid/acl/AclConnectionCounter.h
index 54fa6933ff..e8ef35c1ba 100644
--- a/cpp/src/qpid/acl/AclConnectionCounter.h
+++ b/cpp/src/qpid/acl/AclConnectionCounter.h
@@ -77,12 +77,12 @@ private:
bool countConnectionLH(connectCountsMap_t& theMap,
const std::string& theName,
uint16_t theLimit,
- bool emitLog);
+ bool emitLog,
+ bool enforceLimit);
/** Release a connection */
void releaseLH(connectCountsMap_t& theMap,
- const std::string& theName,
- uint16_t theLimit);
+ const std::string& theName);
public:
ConnectionCounter(Acl& acl, uint16_t nl, uint16_t hl, uint16_t tl);
@@ -93,8 +93,9 @@ public:
void closed(broker::Connection& connection);
// Connection counting
- bool approveConnection(const broker::Connection& conn);
- void setUserId(const broker::Connection& connection, const std::string& username);
+ bool approveConnection(const broker::Connection& conn,
+ bool enforcingConnectionQuotas,
+ uint16_t connectionLimit );
};
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/acl/AclData.cpp b/cpp/src/qpid/acl/AclData.cpp
index 7c14d0985d..ca866ab7d3 100644
--- a/cpp/src/qpid/acl/AclData.cpp
+++ b/cpp/src/qpid/acl/AclData.cpp
@@ -25,11 +25,19 @@ namespace qpid {
namespace acl {
//
- // Instantiate the substitution keyword string
+ // Instantiate the keyword strings
//
- const std::string AclData::USER_SUBSTITUTION_KEYWORD = "${user}";
- const std::string AclData::DOMAIN_SUBSTITUTION_KEYWORD = "${domain}";
- const std::string AclData::USERDOMAIN_SUBSTITUTION_KEYWORD = "${userdomain}";
+ const std::string AclData::ACL_KEYWORD_USER_SUBST = "${user}";
+ const std::string AclData::ACL_KEYWORD_DOMAIN_SUBST = "${domain}";
+ const std::string AclData::ACL_KEYWORD_USERDOMAIN_SUBST = "${userdomain}";
+ const std::string AclData::ACL_KEYWORD_ALL = "all";
+ const std::string AclData::ACL_KEYWORD_ACL = "acl";
+ const std::string AclData::ACL_KEYWORD_GROUP = "group";
+ const std::string AclData::ACL_KEYWORD_QUOTA = "quota";
+ const std::string AclData::ACL_KEYWORD_QUOTA_CONNECTIONS = "connections";
+ const char AclData::ACL_SYMBOL_WILDCARD = '*';
+ const std::string AclData::ACL_KEYWORD_WILDCARD = "*";
+ const char AclData::ACL_SYMBOL_LINE_CONTINUATION = '\\';
//
// constructor
@@ -37,7 +45,9 @@ namespace acl {
AclData::AclData():
decisionMode(qpid::acl::DENY),
transferAcl(false),
- aclSource("UNKNOWN")
+ aclSource("UNKNOWN"),
+ connQuotaRulesExist(false),
+ connQuotaRuleSettings(new quotaRuleSet)
{
for (unsigned int cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++)
{
@@ -60,6 +70,9 @@ namespace acl {
}
delete[] actionList[cnt];
}
+ transferAcl = false;
+ connQuotaRulesExist = false;
+ connQuotaRuleSettings->clear();
}
@@ -73,7 +86,7 @@ namespace acl {
const std::string& lookupStr)
{
// allow wildcard on the end of rule strings...
- if (ruleStr.data()[ruleStr.size()-1]=='*')
+ if (ruleStr.data()[ruleStr.size()-1]==ACL_SYMBOL_WILDCARD)
{
return ruleStr.compare(0,
ruleStr.size()-1,
@@ -124,7 +137,7 @@ namespace acl {
// If individual actorId not found then find a rule set for '*'.
if (itrRule == actionList[action][objType]->end())
- itrRule = actionList[action][objType]->find("*");
+ itrRule = actionList[action][objType]->find(ACL_KEYWORD_WILDCARD);
if (itrRule != actionList[action][objType]->end())
{
@@ -199,6 +212,16 @@ namespace acl {
lookupParamItr = params->find(PROP_MAXQUEUESIZE);
break;
+ case acl::SPECPROP_MAXFILECOUNTUPPERLIMIT:
+ case acl::SPECPROP_MAXFILECOUNTLOWERLIMIT:
+ lookupParamItr = params->find(PROP_MAXFILECOUNT);
+ break;
+
+ case acl::SPECPROP_MAXFILESIZEUPPERLIMIT:
+ case acl::SPECPROP_MAXFILESIZELOWERLIMIT:
+ lookupParamItr = params->find(PROP_MAXFILESIZE);
+ break;
+
default:
lookupParamItr = params->find((Property)rulePropMapItr->first);
break;
@@ -222,6 +245,8 @@ namespace acl {
{
case acl::SPECPROP_MAXQUEUECOUNTUPPERLIMIT:
case acl::SPECPROP_MAXQUEUESIZEUPPERLIMIT:
+ case acl::SPECPROP_MAXFILECOUNTUPPERLIMIT:
+ case acl::SPECPROP_MAXFILESIZEUPPERLIMIT:
limitChecked &=
compareIntMax(
rulePropMapItr->first,
@@ -231,6 +256,8 @@ namespace acl {
case acl::SPECPROP_MAXQUEUECOUNTLOWERLIMIT:
case acl::SPECPROP_MAXQUEUESIZELOWERLIMIT:
+ case acl::SPECPROP_MAXFILECOUNTLOWERLIMIT:
+ case acl::SPECPROP_MAXFILESIZELOWERLIMIT:
limitChecked &=
compareIntMin(
rulePropMapItr->first,
@@ -241,14 +268,31 @@ namespace acl {
default:
bool result;
if ((SPECPROP_ALTERNATE == rulePropMapItr->first && rsItr->ruleHasUserSub[PROP_ALTERNATE]) ||
- (SPECPROP_ROUTINGKEY == rulePropMapItr->first && rsItr->ruleHasUserSub[PROP_ROUTINGKEY]) ||
(SPECPROP_QUEUENAME == rulePropMapItr->first && rsItr->ruleHasUserSub[PROP_QUEUENAME]))
{
// These properties are allowed to have username substitution
std::string sName(rulePropMapItr->second);
substituteUserId(sName, id);
result = matchProp(sName, lookupParamItr->second);
- } else {
+ }
+ else if (SPECPROP_ROUTINGKEY == rulePropMapItr->first)
+ {
+ // Routing key is allowed to have username substitution
+ // and it gets topic exchange matching
+ if (rsItr->ruleHasUserSub[PROP_ROUTINGKEY])
+ {
+ std::string sKey(lookupParamItr->second);
+ substituteKeywords(sKey, id);
+ result = rsItr->matchRoutingKey(sKey);
+ }
+ else
+ {
+ result = rsItr->matchRoutingKey(lookupParamItr->second);
+ }
+ }
+ else
+ {
+ // Rules without substitution
result = matchProp(rulePropMapItr->second, lookupParamItr->second);
}
@@ -359,7 +403,7 @@ namespace acl {
AclData::actObjItr itrRule = actionList[action][objType]->find(id);
if (itrRule == actionList[action][objType]->end())
- itrRule = actionList[action][objType]->find("*");
+ itrRule = actionList[action][objType]->find(ACL_KEYWORD_WILDCARD);
if (itrRule != actionList[action][objType]->end() )
{
@@ -405,9 +449,9 @@ namespace acl {
if (match && rsItr->pubRoutingKeyInRule)
{
- if ((routingKey.find(USER_SUBSTITUTION_KEYWORD, 0) != std::string::npos) ||
- (routingKey.find(DOMAIN_SUBSTITUTION_KEYWORD, 0) != std::string::npos) ||
- (routingKey.find(USERDOMAIN_SUBSTITUTION_KEYWORD, 0) != std::string::npos))
+ if ((routingKey.find(ACL_KEYWORD_USER_SUBST, 0) != std::string::npos) ||
+ (routingKey.find(ACL_KEYWORD_DOMAIN_SUBST, 0) != std::string::npos) ||
+ (routingKey.find(ACL_KEYWORD_USERDOMAIN_SUBST, 0) != std::string::npos))
{
// The user is not allowed to present a routing key with the substitution key in it
QPID_LOG(debug, "ACL: Rule: " << rsItr->rawRuleNum <<
@@ -458,6 +502,62 @@ namespace acl {
}
+
+ //
+ //
+ //
+ void AclData::setConnQuotaRuleSettings (
+ bool rulesExist, boost::shared_ptr<quotaRuleSet> quotaPtr)
+ {
+ connQuotaRulesExist = rulesExist;
+ connQuotaRuleSettings = quotaPtr;
+ }
+
+
+ //
+ // getConnQuotaForUser
+ //
+ // Return the true or false value of connQuotaRulesExist,
+ // indicating whether any kind of lookup was done or not.
+ //
+ // When lookups are performed return the result value of
+ // 1. The user's setting else
+ // 2. The 'all' user setting else
+ // 3. Zero
+ // When lookups are not performed then return a result value of Zero.
+ //
+ bool AclData::getConnQuotaForUser(const std::string& theUserName,
+ uint16_t* theResult) const {
+ if (connQuotaRulesExist) {
+ // look for this user explicitly
+ quotaRuleSetItr nameItr = (*connQuotaRuleSettings).find(theUserName);
+ if (nameItr != (*connQuotaRuleSettings).end()) {
+ QPID_LOG(trace, "ACL: Connection quota for user " << theUserName
+ << " explicitly set to : " << (*nameItr).second);
+ *theResult = (*nameItr).second;
+ } else {
+ // Look for the 'all' user
+ nameItr = (*connQuotaRuleSettings).find(ACL_KEYWORD_ALL);
+ if (nameItr != (*connQuotaRuleSettings).end()) {
+ QPID_LOG(trace, "ACL: Connection quota for user " << theUserName
+ << " chosen through value for 'all' : " << (*nameItr).second);
+ *theResult = (*nameItr).second;
+ } else {
+ // Neither userName nor "all" found.
+ QPID_LOG(trace, "ACL: Connection quota for user " << theUserName
+ << " absent in quota settings. Return value : 0");
+ *theResult = 0;
+ }
+ }
+ } else {
+ // Rules do not exist
+ QPID_LOG(trace, "ACL: Connection quota for user " << theUserName
+ << " unavailable; quota settings are not specified. Return value : 0");
+ *theResult = 0;
+ }
+ return connQuotaRulesExist;
+ }
+
//
//
//
@@ -607,8 +707,8 @@ namespace acl {
// Given an Acl rule and an authenticated userId
// do the keyword substitutions on the rule.
//
- void AclData::AclData::substituteUserId(std::string& ruleString,
- const std::string& userId)
+ void AclData::substituteUserId(std::string& ruleString,
+ const std::string& userId)
{
size_t locDomSeparator(0);
std::string user("");
@@ -625,9 +725,9 @@ namespace acl {
domain = normalizeUserId(userId.substr(locDomSeparator+1));
}
- substituteString(ruleString, USER_SUBSTITUTION_KEYWORD, user);
- substituteString(ruleString, DOMAIN_SUBSTITUTION_KEYWORD, domain);
- substituteString(ruleString, USERDOMAIN_SUBSTITUTION_KEYWORD, userdomain);
+ substituteString(ruleString, ACL_KEYWORD_USER_SUBST, user);
+ substituteString(ruleString, ACL_KEYWORD_DOMAIN_SUBST, domain);
+ substituteString(ruleString, ACL_KEYWORD_USERDOMAIN_SUBST, userdomain);
}
@@ -640,8 +740,8 @@ namespace acl {
// topic key lookups where the keyword string proper is in the
// topic key search tree.
//
- void AclData::AclData::substituteKeywords(std::string& ruleString,
- const std::string& userId)
+ void AclData::substituteKeywords(std::string& ruleString,
+ const std::string& userId)
{
size_t locDomSeparator(0);
std::string user("");
@@ -658,8 +758,8 @@ namespace acl {
domain = normalizeUserId(userId.substr(locDomSeparator+1));
}
std::string oRule(ruleString);
- substituteString(ruleString, userdomain, USERDOMAIN_SUBSTITUTION_KEYWORD);
- substituteString(ruleString, user, USER_SUBSTITUTION_KEYWORD);
- substituteString(ruleString, domain, DOMAIN_SUBSTITUTION_KEYWORD);
+ substituteString(ruleString, userdomain, ACL_KEYWORD_USERDOMAIN_SUBST);
+ substituteString(ruleString, user, ACL_KEYWORD_USER_SUBST);
+ substituteString(ruleString, domain, ACL_KEYWORD_DOMAIN_SUBST);
}
}}
diff --git a/cpp/src/qpid/acl/AclData.h b/cpp/src/qpid/acl/AclData.h
index b4b13c44b6..43cb5193f5 100644
--- a/cpp/src/qpid/acl/AclData.h
+++ b/cpp/src/qpid/acl/AclData.h
@@ -111,6 +111,8 @@ public:
typedef std::map<std::string, ruleSet > actionObject; // user
typedef actionObject::iterator actObjItr;
typedef actionObject* aclAction;
+ typedef std::map<std::string, uint16_t> quotaRuleSet; // <username, N>
+ typedef quotaRuleSet::const_iterator quotaRuleSetItr;
// Action*[] -> Object*[] -> map<user -> set<Rule> >
aclAction* actionList[qpid::acl::ACTIONSIZE];
@@ -134,9 +136,18 @@ public:
bool matchProp(const std::string & src, const std::string& src1);
void clear ();
- static const std::string USER_SUBSTITUTION_KEYWORD;
- static const std::string DOMAIN_SUBSTITUTION_KEYWORD;
- static const std::string USERDOMAIN_SUBSTITUTION_KEYWORD;
+ static const std::string ACL_KEYWORD_USER_SUBST;
+ static const std::string ACL_KEYWORD_DOMAIN_SUBST;
+ static const std::string ACL_KEYWORD_USERDOMAIN_SUBST;
+ static const std::string ACL_KEYWORD_ALL;
+ static const std::string ACL_KEYWORD_ACL;
+ static const std::string ACL_KEYWORD_GROUP;
+ static const std::string ACL_KEYWORD_QUOTA;
+ static const std::string ACL_KEYWORD_QUOTA_CONNECTIONS;
+ static const char ACL_SYMBOL_WILDCARD;
+ static const std::string ACL_KEYWORD_WILDCARD;
+ static const char ACL_SYMBOL_LINE_CONTINUATION;
+
void substituteString(std::string& targetString,
const std::string& placeholder,
const std::string& replacement);
@@ -146,6 +157,31 @@ public:
void substituteKeywords(std::string& ruleString,
const std::string& userId);
+ // Per user connection quotas extracted from acl rule file
+ // Set by reader
+ void setConnQuotaRuleSettings (bool, boost::shared_ptr<quotaRuleSet>);
+ // Get by connection approvers
+ bool enforcingConnectionQuotas() { return connQuotaRulesExist; }
+ bool getConnQuotaForUser(const std::string&, uint16_t*) const;
+
+ /** getConnectMaxSpec
+ * Connection quotas are held in uint16_t variables.
+ * This function specifies the largest value that a user is allowed
+ * to declare for a connection quota. The upper limit serves two
+ * purposes: 1. It leaves room for magic numbers that may be declared
+ * by keyword names in Acl files and not have those numbers conflict
+ * with innocent user declared values, and 2. It makes the unsigned
+ * math very close to _MAX work reliably with no risk of accidental
+ * wrapping back to zero.
+ */
+ static uint16_t getConnectMaxSpec() {
+ return 65530;
+ }
+ static std::string getMaxConnectSpecStr() {
+ return "65530";
+ }
+
+
AclData();
virtual ~AclData();
@@ -157,6 +193,10 @@ private:
bool compareIntMin(const qpid::acl::SpecProperty theProperty,
const std::string theAclValue,
const std::string theLookupValue);
+
+ // Per-user connection quota
+ bool connQuotaRulesExist;
+ boost::shared_ptr<quotaRuleSet> connQuotaRuleSettings; // Map of user-to-N values from rule file
};
}} // namespace qpid::acl
diff --git a/cpp/src/qpid/acl/AclPlugin.cpp b/cpp/src/qpid/acl/AclPlugin.cpp
index ebf5e90afe..c666eb5420 100644
--- a/cpp/src/qpid/acl/AclPlugin.cpp
+++ b/cpp/src/qpid/acl/AclPlugin.cpp
@@ -42,9 +42,10 @@ struct AclOptions : public Options {
values.aclMaxConnectTotal = 500;
addOptions()
("acl-file", optValue(values.aclFile, "FILE"), "The policy file to load from, loaded from data dir")
+ ("connection-limit-per-user", optValue(values.aclMaxConnectPerUser, "N"), "The maximum number of connections allowed per user. 0 implies no limit.")
("max-connections" , optValue(values.aclMaxConnectTotal, "N"), "The maximum combined number of connections allowed. 0 implies no limit.")
- ("max-connections-per-user", optValue(values.aclMaxConnectPerUser, "N"), "The maximum number of connections allowed per user. 0 implies no limit.")
- ("max-connections-per-ip" , optValue(values.aclMaxConnectPerIp, "N"), "The maximum number of connections allowed per host IP address. 0 implies no limit.")
+ ("connection-limit-per-ip" , optValue(values.aclMaxConnectPerIp, "N"), "The maximum number of connections allowed per host IP address. 0 implies no limit.")
+ ("max-queues-per-user", optValue(values.aclMaxQueuesPerUser, "N"), "The maximum number of queues allowed per user. 0 implies no limit.")
;
}
};
diff --git a/cpp/src/qpid/acl/AclReader.cpp b/cpp/src/qpid/acl/AclReader.cpp
index fae67d0325..7eb9b82c64 100644
--- a/cpp/src/qpid/acl/AclReader.cpp
+++ b/cpp/src/qpid/acl/AclReader.cpp
@@ -24,6 +24,7 @@
#include <sstream>
#include "qpid/log/Statement.h"
#include "qpid/Exception.h"
+#include <boost/lexical_cast.hpp>
#include <iomanip> // degug
#include <iostream> // debug
@@ -95,7 +96,7 @@ namespace acl {
<< cnt << " " << (*i)->toString());
if (!foundmode && (*i)->actionAll && (*i)->names.size() == 1
- && (*((*i)->names.begin())).compare("*") == 0) {
+ && (*((*i)->names.begin())).compare(AclData::ACL_KEYWORD_WILDCARD) == 0) {
d->decisionMode = (*i)->res;
QPID_LOG(debug, "ACL: FoundMode "
<< AclHelper::getAclResultStr(d->decisionMode));
@@ -105,13 +106,23 @@ namespace acl {
// Record which properties have the user substitution string
for (pmCitr pItr=rule.props.begin(); pItr!=rule.props.end(); pItr++) {
- if ((pItr->second.find(AclData::USER_SUBSTITUTION_KEYWORD, 0) != std::string::npos) ||
- (pItr->second.find(AclData::DOMAIN_SUBSTITUTION_KEYWORD, 0) != std::string::npos) ||
- (pItr->second.find(AclData::USERDOMAIN_SUBSTITUTION_KEYWORD, 0) != std::string::npos)) {
+ if ((pItr->second.find(AclData::ACL_KEYWORD_USER_SUBST, 0) != std::string::npos) ||
+ (pItr->second.find(AclData::ACL_KEYWORD_DOMAIN_SUBST, 0) != std::string::npos) ||
+ (pItr->second.find(AclData::ACL_KEYWORD_USERDOMAIN_SUBST, 0) != std::string::npos)) {
rule.ruleHasUserSub[pItr->first] = true;
}
}
+ // Find possible routingkey property and cache its pattern
+ for (pmCitr pItr=rule.props.begin(); pItr!=rule.props.end(); pItr++) {
+ if (acl::SPECPROP_ROUTINGKEY == pItr->first)
+ {
+ rule.pubRoutingKeyInRule = true;
+ rule.pubRoutingKey = (std::string)pItr->second;
+ rule.addTopicTest(rule.pubRoutingKey);
+ }
+ }
+
// Action -> Object -> map<user -> set<Rule> >
std::ostringstream actionstr;
for (int acnt = ((*i)->actionAll ? 0 : (*i)->action);
@@ -126,13 +137,6 @@ namespace acl {
// Go through the rule properties and find the name and the key.
// If found then place them specially for the lookup engine.
for (pmCitr pItr=(*i)->props.begin(); pItr!=(*i)->props.end(); pItr++) {
- if (acl::SPECPROP_ROUTINGKEY == pItr->first)
- {
- rule.pubRoutingKeyInRule = true;
- rule.pubRoutingKey = (std::string)pItr->second;
- rule.addTopicTest(rule.pubRoutingKey);
- break;
- }
if (acl::SPECPROP_NAME == pItr->first)
{
rule.pubExchNameInRule = true;
@@ -164,7 +168,7 @@ namespace acl {
// add users and Rule to object set
bool allNames = false;
// check to see if names.begin is '*'
- if ((*(*i)->names.begin()).compare("*") == 0)
+ if ((*(*i)->names.begin()).compare(AclData::ACL_KEYWORD_WILDCARD) == 0)
allNames = true;
for (nsCitr itr = (allNames ? names.begin() : (*i)->names.begin());
@@ -196,7 +200,7 @@ namespace acl {
objstr << AclHelper::getObjectTypeStr((ObjectType) ocnt) << ",";
}
- bool allNames = ((*(*i)->names.begin()).compare("*") == 0);
+ bool allNames = ((*(*i)->names.begin()).compare(AclData::ACL_KEYWORD_WILDCARD) == 0);
std::ostringstream userstr;
for (nsCitr itr = (allNames ? names.begin() : (*i)->names.begin());
itr != (allNames ? names.end() : (*i)->names.end());
@@ -215,12 +219,15 @@ namespace acl {
<< "}" );
}
}
+
+ // connection quota
+ d->setConnQuotaRuleSettings(connQuotaRulesExist, connQuota);
}
void AclReader::aclRule::processName(const std::string& name, const groupMap& groups) {
- if (name.compare("all") == 0) {
- names.insert("*");
+ if (name.compare(AclData::ACL_KEYWORD_ALL) == 0) {
+ names.insert(AclData::ACL_KEYWORD_WILDCARD);
} else {
gmCitr itr = groups.find(name);
if (itr == groups.end()) {
@@ -231,9 +238,13 @@ namespace acl {
}
}
- AclReader::AclReader() : lineNumber(0), contFlag(false), validationMap(new AclHelper::objectMap) {
+ AclReader::AclReader(uint16_t theCliMaxConnPerUser) : lineNumber(0), contFlag(false),
+ validationMap(new AclHelper::objectMap),
+ cliMaxConnPerUser (theCliMaxConnPerUser),
+ connQuotaRulesExist(false),
+ connQuota(new AclData::quotaRuleSet) {
AclHelper::loadValidationMap(validationMap);
- names.insert("*");
+ names.insert(AclData::ACL_KEYWORD_WILDCARD);
}
AclReader::~AclReader() {}
@@ -251,6 +262,11 @@ namespace acl {
errorStream << "Unable to open ACL file \"" << fn << "\": eof=" << (ifs.eof()?"T":"F") << "; fail=" << (ifs.fail()?"T":"F") << "; bad=" << (ifs.bad()?"T":"F");
return -1;
}
+ // Propagate nonzero per-user max connection setting from CLI
+ if (cliMaxConnPerUser > 0) {
+ (*connQuota)[AclData::ACL_KEYWORD_ACL] = cliMaxConnPerUser;
+ }
+ // Loop to process the Acl file
try {
bool err = false;
while (ifs.good()) {
@@ -279,6 +295,7 @@ namespace acl {
}
printNames();
printRules();
+ printConnectionQuotas();
loadDecisionData(d);
return 0;
@@ -289,7 +306,7 @@ namespace acl {
std::vector<std::string> toks;
// Check for continuation
- char* contCharPtr = std::strrchr(line, '\\');
+ char* contCharPtr = std::strrchr(line, AclData::ACL_SYMBOL_LINE_CONTINUATION);
bool cont = contCharPtr != 0;
if (cont) *contCharPtr = 0;
@@ -300,10 +317,12 @@ namespace acl {
return false;
}
- if (numToks && (toks[0].compare("group") == 0 || contFlag)) {
+ if (numToks && (toks[0].compare(AclData::ACL_KEYWORD_GROUP) == 0 || contFlag)) {
ret = processGroupLine(toks, cont);
- } else if (numToks && toks[0].compare("acl") == 0) {
+ } else if (numToks && toks[0].compare(AclData::ACL_KEYWORD_ACL) == 0) {
ret = processAclLine(toks);
+ } else if (numToks && toks[0].compare(AclData::ACL_KEYWORD_QUOTA) == 0) {
+ ret = processQuotaLine(toks);
} else {
// Check for whitespace only line, ignore these
bool ws = true;
@@ -314,7 +333,10 @@ namespace acl {
ret = true;
} else {
errorStream << ACL_FORMAT_ERR_LOG_PREFIX << "Line : " << lineNumber
- << ", Non-continuation line must start with \"group\" or \"acl\".";
+ << ", Non-continuation line must start with \""
+ << AclData::ACL_KEYWORD_GROUP << "\", \""
+ << AclData::ACL_KEYWORD_ACL << "\". or \""
+ << AclData::ACL_KEYWORD_QUOTA << "\".";
ret = false;
}
}
@@ -334,6 +356,102 @@ namespace acl {
return cnt;
}
+
+ // Process 'quota' rule lines
+ // Return true if the line is successfully processed without errors
+ bool AclReader::processQuotaLine(tokList& toks) {
+ const unsigned toksSize = toks.size();
+ const unsigned minimumSize = 3;
+ if (toksSize < minimumSize) {
+ errorStream << ACL_FORMAT_ERR_LOG_PREFIX << "Line : " << lineNumber
+ << ", Insufficient tokens for quota definition.";
+ return false;
+ }
+
+ if (toks[1].compare(AclData::ACL_KEYWORD_QUOTA_CONNECTIONS) == 0) {
+ return processQuotaConnLine(toks);
+ } else {
+ errorStream << ACL_FORMAT_ERR_LOG_PREFIX << "Line : " << lineNumber
+ << ", Quota type \"" << toks[1] << "\" unrecognized.";
+ return false;
+ }
+ }
+
+
+ // Process 'quota connections' rule lines
+ // Return true if the line is successfully processed without errors
+ bool AclReader::processQuotaConnLine(tokList& toks) {
+ const unsigned toksSize = toks.size();
+
+ uint16_t nConns(0);
+ try {
+ nConns = boost::lexical_cast<uint16_t>(toks[2]);
+ } catch(const boost::bad_lexical_cast&) {
+ errorStream << ACL_FORMAT_ERR_LOG_PREFIX << "Line : " << lineNumber
+ << ", Connection quota value \"" << toks[2]
+ << "\" cannot be converted to a 16-bit unsigned integer.";
+ return false;
+ }
+
+ // limit check the connection setting
+ if (nConns > AclData::getConnectMaxSpec())
+ {
+ errorStream << ACL_FORMAT_ERR_LOG_PREFIX << "Line : " << lineNumber
+ << ", Connection quota value \"" << toks[2]
+ << "\" exceeds maximum configuration setting of "
+ << AclData::getConnectMaxSpec();
+ return false;
+ }
+
+ // Apply the connection count to all names in rule
+ for (unsigned idx = 3; idx < toksSize; idx++) {
+ if (groups.find(toks[idx]) == groups.end()) {
+ // This is the name of an individual, not a group
+ (*connQuota)[toks[idx]] = nConns;
+ } else {
+ if (!processQuotaConnGroup(toks[idx], nConns))
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ // Process 'quota connections' group expansion
+ // Return true if the quota is applied to all members of the group
+ bool AclReader::processQuotaConnGroup(const std::string& theGroup, uint16_t theQuota) {
+ gmCitr citr = groups.find(theGroup);
+
+ if (citr == groups.end()) {
+ errorStream << ACL_FORMAT_ERR_LOG_PREFIX << "Line : " << lineNumber
+ << ", Failed to expand group \"" << theGroup << "\".";
+ return false;
+ }
+
+ for (nsCitr gni=citr->second->begin(); gni!=citr->second->end(); gni++) {
+ if (groups.find(*gni) == groups.end()) {
+ (*connQuota)[*gni] = theQuota;
+ } else {
+ if (!processQuotaConnGroup(*gni, theQuota))
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ void AclReader::printConnectionQuotas() const {
+ QPID_LOG(debug, "ACL: connection quota: " << (*connQuota).size() << " rules found:");
+ int cnt = 1;
+ for (AclData::quotaRuleSetItr itr=(*connQuota).begin();
+ itr != (*connQuota).end();
+ ++itr,++cnt) {
+ QPID_LOG(debug, "ACL: quota " << cnt << " : " << (*itr).second
+ << " connections for " << (*itr).first)
+ }
+ }
+
+
// Return true if the line is successfully processed without errors
// If cont is true, then groupName must be set to the continuation group name
bool AclReader::processGroupLine(tokList& toks, const bool cont) {
@@ -459,8 +577,8 @@ namespace acl {
return false;
}
- bool actionAllFlag = toks[3].compare("all") == 0;
- bool userAllFlag = toks[2].compare("all") == 0;
+ bool actionAllFlag = toks[3].compare(AclData::ACL_KEYWORD_ALL) == 0;
+ bool userAllFlag = toks[2].compare(AclData::ACL_KEYWORD_ALL) == 0;
Action action;
if (actionAllFlag) {
@@ -489,7 +607,7 @@ namespace acl {
}
if (toksSize >= 5) { // object name-value pair
- if (toks[4].compare("all") == 0) {
+ if (toks[4].compare(AclData::ACL_KEYWORD_ALL) == 0) {
rule->setObjectTypeAll();
} else {
try {
@@ -523,7 +641,7 @@ namespace acl {
}
}
// Check if name (toks[2]) is group; if not, add as name of individual
- if (toks[2].compare("all") != 0) {
+ if (toks[2].compare(AclData::ACL_KEYWORD_ALL) != 0) {
if (groups.find(toks[2]) == groups.end()) {
addName(toks[2]);
}
diff --git a/cpp/src/qpid/acl/AclReader.h b/cpp/src/qpid/acl/AclReader.h
index 6351c1e509..1fa374c59c 100644
--- a/cpp/src/qpid/acl/AclReader.h
+++ b/cpp/src/qpid/acl/AclReader.h
@@ -28,6 +28,7 @@
#include <sstream>
#include <memory>
#include "qpid/acl/AclData.h"
+#include "qpid/acl/Acl.h"
#include "qpid/broker/AclModule.h"
namespace qpid {
@@ -96,7 +97,7 @@ class AclReader {
std::ostringstream errorStream;
public:
- AclReader();
+ AclReader(uint16_t cliMaxConnPerUser);
virtual ~AclReader();
int read(const std::string& fn, boost::shared_ptr<AclData> d); // return=0 for success
std::string getError();
@@ -116,8 +117,17 @@ class AclReader {
void printRules() const; // debug aid
bool isValidUserName(const std::string& name);
+ bool processQuotaLine(tokList& toks);
+ bool processQuotaConnLine(tokList& toks);
+ bool processQuotaConnGroup(const std::string&, uint16_t);
+ void printConnectionQuotas() const;
+
static bool isValidGroupName(const std::string& name);
static nvPair splitNameValuePair(const std::string& nvpString);
+
+ const uint16_t cliMaxConnPerUser;
+ bool connQuotaRulesExist;
+ boost::shared_ptr<AclData::quotaRuleSet> connQuota;
};
}} // namespace qpid::acl
diff --git a/cpp/src/qpid/acl/AclResourceCounter.cpp b/cpp/src/qpid/acl/AclResourceCounter.cpp
new file mode 100644
index 0000000000..66dfd0777e
--- /dev/null
+++ b/cpp/src/qpid/acl/AclResourceCounter.cpp
@@ -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.
+ *
+ */
+
+#include "AclResourceCounter.h"
+#include "Acl.h"
+#include "qpid/log/Statement.h"
+#include "qpid/sys/Mutex.h"
+#include <assert.h>
+#include <sstream>
+
+using namespace qpid::sys;
+
+namespace qpid {
+namespace acl {
+
+//
+// This module approves various resource creation requests:
+// Queues
+//
+
+
+//
+//
+//
+ResourceCounter::ResourceCounter(Acl& a, uint16_t ql) :
+ acl(a), queueLimit(ql) {}
+
+ResourceCounter::~ResourceCounter() {}
+
+
+//
+// limitApproveLH
+//
+// Resource creation approver.
+// If user is under limit increment count and return true.
+// Called with lock held.
+//
+bool ResourceCounter::limitApproveLH(
+ const std::string& theTitle,
+ countsMap_t& theMap,
+ const std::string& theName,
+ uint16_t theLimit,
+ bool emitLog) {
+
+ bool result(true);
+ if (theLimit > 0) {
+ uint16_t count;
+ countsMap_t::iterator eRef = theMap.find(theName);
+ if (eRef != theMap.end()) {
+ count = (uint16_t)(*eRef).second;
+ result = count < theLimit;
+ if (result) {
+ count += 1;
+ (*eRef).second = count;
+ }
+ } else {
+ // Not found
+ theMap[theName] = count = 1;
+ }
+ if (emitLog) {
+ QPID_LOG(trace, theTitle << theName
+ << " limit=" << theLimit
+ << " curValue=" << count
+ << " result=" << (result ? "allow" : "deny"));
+ }
+ }
+ return result;
+}
+
+
+//
+// releaseLH
+//
+// Decrement the name's count in map.
+// called with dataLock already taken
+//
+void ResourceCounter::releaseLH(
+ const std::string& theTitle, countsMap_t& theMap, const std::string& theName, uint16_t theLimit) {
+
+ if (theLimit > 0) {
+ countsMap_t::iterator eRef = theMap.find(theName);
+ if (eRef != theMap.end()) {
+ uint16_t count = (uint16_t) (*eRef).second;
+ assert (count > 0);
+ if (1 == count) {
+ theMap.erase (eRef);
+ } else {
+ (*eRef).second = count - 1;
+ }
+ } else {
+ // User had no connections.
+ QPID_LOG(notice, theTitle << theName
+ << "' not found in resource count pool");
+ }
+ }
+}
+
+
+//
+// approveCreateQueue
+// Count an attempted queue creation by this user.
+// Disapprove if over limit.
+//
+bool ResourceCounter::approveCreateQueue(const std::string& userId, const std::string& queueName)
+{
+ Mutex::ScopedLock locker(dataLock);
+
+ bool okByQ = limitApproveLH("ACL Queue creation approver. userId:", queuePerUserMap, userId, queueLimit, true);
+
+ if (okByQ) {
+ // Queue is owned by this userId
+ queueOwnerMap[queueName] = userId;
+
+ QPID_LOG(trace, "ACL create queue approved for user '" << userId
+ << "' queue '" << queueName << "'");
+ } else {
+
+ QPID_LOG(error, "Client max queue count limit of " << queueLimit
+ << " exceeded by '" << userId << "' creating queue '"
+ << queueName << "'. Queue creation denied.");
+
+ acl.reportQueueLimit(userId, queueName);
+ }
+ return okByQ;
+}
+
+
+//
+// recordDestroyQueue
+// Return a destroyed queue to a user's quota
+//
+void ResourceCounter::recordDestroyQueue(const std::string& queueName)
+{
+ Mutex::ScopedLock locker(dataLock);
+
+ queueOwnerMap_t::iterator eRef = queueOwnerMap.find(queueName);
+ if (eRef != queueOwnerMap.end()) {
+ releaseLH("ACL resource counter: Queue owner for queue '", queuePerUserMap, (*eRef).second, queueLimit);
+
+ queueOwnerMap.erase(eRef);
+ } else {
+ QPID_LOG(notice, "ACL resource counter: Queue '" << queueName
+ << "' not found in queue owner map");
+ }
+}
+
+}} // namespace qpid::acl
diff --git a/cpp/src/qpid/acl/AclResourceCounter.h b/cpp/src/qpid/acl/AclResourceCounter.h
new file mode 100644
index 0000000000..f5995eb961
--- /dev/null
+++ b/cpp/src/qpid/acl/AclResourceCounter.h
@@ -0,0 +1,78 @@
+#ifndef QPID_ACL_RESOURCECOUNTER_H
+#define QPID_ACL_RESOURCECOUNTER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/sys/Mutex.h"
+#include <boost/iterator/iterator_concepts.hpp>
+
+#include <map>
+
+namespace qpid {
+
+namespace acl {
+class Acl;
+
+ /**
+ * Approve or disapprove resource creation requests
+ */
+class ResourceCounter
+{
+private:
+ typedef std::map<std::string, uint32_t> countsMap_t;
+ typedef std::map<std::string, std::string> queueOwnerMap_t;
+
+ Acl& acl;
+ uint16_t queueLimit;
+ qpid::sys::Mutex dataLock;
+
+ /** Records queueName-queueUserId */
+ queueOwnerMap_t queueOwnerMap;
+
+ /** Records queue-by-owner counts */
+ countsMap_t queuePerUserMap;
+
+ /** Return approval for proposed resource creation */
+ bool limitApproveLH(const std::string& theTitle,
+ countsMap_t& theMap,
+ const std::string& theName,
+ uint16_t theLimit,
+ bool emitLog);
+
+ /** Release a connection */
+ void releaseLH(const std::string& theTitle,
+ countsMap_t& theMap,
+ const std::string& theName,
+ uint16_t theLimit);
+
+public:
+ ResourceCounter(Acl& acl, uint16_t ql);
+ ~ResourceCounter();
+
+ // Queue counting
+ bool approveCreateQueue(const std::string& userId, const std::string& queueName);
+ void recordDestroyQueue(const std::string& queueName);
+};
+
+}} // namespace qpid::acl
+
+#endif /*!QPID_ACL_RESOURCECOUNTER_H*/
diff --git a/cpp/src/qpid/acl/AclTopicMatch.h b/cpp/src/qpid/acl/AclTopicMatch.h
index 486c229ad5..654d1d63d4 100644
--- a/cpp/src/qpid/acl/AclTopicMatch.h
+++ b/cpp/src/qpid/acl/AclTopicMatch.h
@@ -30,7 +30,7 @@ namespace qpid {
namespace broker {
// Class for executing topic exchange routing key matching rules in
-// Acl code the allows or denies users publishing to an exchange.
+// Acl code. Allows or denies users publishing to an exchange.
class TopicExchange::TopicExchangeTester {
class boundNode;
diff --git a/cpp/src/qpid/acl/AclValidator.cpp b/cpp/src/qpid/acl/AclValidator.cpp
index 85f0f7c240..73b49b2959 100644
--- a/cpp/src/qpid/acl/AclValidator.cpp
+++ b/cpp/src/qpid/acl/AclValidator.cpp
@@ -94,6 +94,22 @@ namespace acl {
boost::shared_ptr<PropertyType>(
new IntPropertyType(0,std::numeric_limits<int64_t>::max()))));
+ validators.insert(Validator(acl::SPECPROP_MAXFILESIZELOWERLIMIT,
+ boost::shared_ptr<PropertyType>(
+ new IntPropertyType(0,std::numeric_limits<int64_t>::max()))));
+
+ validators.insert(Validator(acl::SPECPROP_MAXFILESIZEUPPERLIMIT,
+ boost::shared_ptr<PropertyType>(
+ new IntPropertyType(0,std::numeric_limits<int64_t>::max()))));
+
+ validators.insert(Validator(acl::SPECPROP_MAXFILECOUNTLOWERLIMIT,
+ boost::shared_ptr<PropertyType>(
+ new IntPropertyType(0,std::numeric_limits<int64_t>::max()))));
+
+ validators.insert(Validator(acl::SPECPROP_MAXFILECOUNTUPPERLIMIT,
+ boost::shared_ptr<PropertyType>(
+ new IntPropertyType(0,std::numeric_limits<int64_t>::max()))));
+
std::string policyTypes[] = {"ring", "ring_strict", "flow_to_disk", "reject"};
std::vector<std::string> v(policyTypes, policyTypes + sizeof(policyTypes) / sizeof(std::string));
validators.insert(Validator(acl::SPECPROP_POLICYTYPE,
diff --git a/cpp/src/qpid/acl/management-schema.xml b/cpp/src/qpid/acl/management-schema.xml
index f52c251bed..2ac20bb324 100644
--- a/cpp/src/qpid/acl/management-schema.xml
+++ b/cpp/src/qpid/acl/management-schema.xml
@@ -25,8 +25,10 @@
<property name="maxConnections" type="uint16" access="RO" desc="Maximum allowed connections"/>
<property name="maxConnectionsPerIp" type="uint16" access="RO" desc="Maximum allowed connections"/>
<property name="maxConnectionsPerUser" type="uint16" access="RO" desc="Maximum allowed connections"/>
+ <property name="maxQueuesPerUser" type="uint16" access="RO" desc="Maximum allowed queues"/>
<statistic name="aclDenyCount" type="count64" unit="request" desc="Number of ACL requests denied"/>
<statistic name="connectionDenyCount" type="count64" unit="connection" desc="Number of connections denied"/>
+ <statistic name="queueQuotaDenyCount" type="count64" unit="queue" desc="Number of queue creations denied"/>
<method name="reloadACLFile" desc="Reload the ACL file"/>
@@ -70,11 +72,13 @@
<arg name="reason" type="lstr"/>
<arg name="userId" type="sstr"/>
<arg name="clientAddr" type="sstr"/>
+ <arg name="queueName" type="sstr"/>
</eventArguments>
<event name="allow" sev="inform" args="userId, action, objectType, objectName, arguments"/>
<event name="deny" sev="notice" args="userId, action, objectType, objectName, arguments"/>
<event name="connectionDeny" sev="notice" args="userId, clientAddr"/>
+ <event name="queueQuotaDeny" sev="notice" args="userId, queueName"/>
<event name="fileLoaded" sev="inform" args="userId"/>
<event name="fileLoadFailed" sev="error" args="userId, reason"/>
diff --git a/cpp/src/qpid/agent/ManagementAgentImpl.cpp b/cpp/src/qpid/agent/ManagementAgentImpl.cpp
index 09b7fa58e9..a48789973a 100644
--- a/cpp/src/qpid/agent/ManagementAgentImpl.cpp
+++ b/cpp/src/qpid/agent/ManagementAgentImpl.cpp
@@ -654,7 +654,10 @@ void ManagementAgentImpl::invokeMethodRequest(const string& body, const string&
void ManagementAgentImpl::handleGetQuery(const string& body, const string& cid, const string& rte, const string& rtk)
{
- moveNewObjectsLH();
+ {
+ sys::Mutex::ScopedLock lock(agentLock);
+ moveNewObjectsLH(lock);
+ }
Variant::Map inMap;
Variant::Map::const_iterator i;
@@ -985,14 +988,37 @@ ManagementAgentImpl::PackageMap::iterator ManagementAgentImpl::findOrAddPackage(
return result.first;
}
-void ManagementAgentImpl::moveNewObjectsLH()
+// note well: caller must hold agentLock when calling this!
+void ManagementAgentImpl::moveNewObjectsLH(const sys::Mutex::ScopedLock& /*agentLock*/)
{
sys::Mutex::ScopedLock lock(addLock);
- for (ObjectMap::iterator iter = newManagementObjects.begin();
- iter != newManagementObjects.end();
- iter++)
- managementObjects[iter->first] = iter->second;
- newManagementObjects.clear();
+ ObjectMap::iterator newObj = newManagementObjects.begin();
+ while (newObj != newManagementObjects.end()) {
+ // before adding a new mgmt object, check for duplicates:
+ ObjectMap::iterator oldObj = managementObjects.find(newObj->first);
+ if (oldObj == managementObjects.end()) {
+ managementObjects[newObj->first] = newObj->second;
+ newManagementObjects.erase(newObj++); // post inc iterator safe!
+ } else {
+ // object exists with same object id. This may be legit, for example, when a
+ // recently deleted object is re-added before the mgmt poll runs.
+ if (newObj->second->isDeleted()) {
+ // @TODO fixme: we missed an add-delete for the new object
+ QPID_LOG(warning, "Mgmt Object deleted before update sent, oid=" << newObj->first);
+ newManagementObjects.erase(newObj++); // post inc iterator safe!
+ } else if (oldObj->second->isDeleted()) {
+ // skip adding newObj, try again later once oldObj has been cleaned up by poll
+ ++newObj;
+ } else {
+ // real bad - two objects exist with same OID. This is a bug in the application
+ QPID_LOG(error, "Detected two Mgmt Objects using the same object id! oid=" << newObj->first
+ << ", this is bad!");
+ // what to do here? Can't erase an active obj - owner has a pointer to it.
+ // for now I punt. Maybe the flood of log messages will get someone's attention :P
+ ++newObj;
+ }
+ }
+ }
}
void ManagementAgentImpl::addClassLocal(uint8_t classKind,
@@ -1060,7 +1086,7 @@ void ManagementAgentImpl::periodicProcessing()
if (!connected)
return;
- moveNewObjectsLH();
+ moveNewObjectsLH(lock);
//
// Clear the been-here flag on all objects in the map.
diff --git a/cpp/src/qpid/agent/ManagementAgentImpl.h b/cpp/src/qpid/agent/ManagementAgentImpl.h
index 53f3c13a91..4c97bc89da 100644
--- a/cpp/src/qpid/agent/ManagementAgentImpl.h
+++ b/cpp/src/qpid/agent/ManagementAgentImpl.h
@@ -92,10 +92,6 @@ class ManagementAgentImpl : public ManagementAgent, public client::MessageListen
uint16_t getInterval() { return interval; }
void periodicProcessing();
- // these next are here to support the hot-wiring of state between clustered brokers
- uint64_t getNextObjectId(void) { return nextObjectId; }
- void setNextObjectId(uint64_t o) { nextObjectId = o; }
-
uint16_t getBootSequence(void) { return bootSequence; }
void setBootSequence(uint16_t b) { bootSequence = b; }
@@ -261,7 +257,7 @@ class ManagementAgentImpl : public ManagementAgent, public client::MessageListen
void storeData(bool requested=false);
void retrieveData(std::string& vendor, std::string& product, std::string& inst);
PackageMap::iterator findOrAddPackage(const std::string& name);
- void moveNewObjectsLH();
+ void moveNewObjectsLH(const sys::Mutex::ScopedLock& agentLock);
void addClassLocal (uint8_t classKind,
PackageMap::iterator pIter,
const std::string& className,
diff --git a/cpp/src/qpid/amqp/CharSequence.cpp b/cpp/src/qpid/amqp/CharSequence.cpp
new file mode 100644
index 0000000000..857ec7e587
--- /dev/null
+++ b/cpp/src/qpid/amqp/CharSequence.cpp
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "CharSequence.h"
+
+namespace qpid {
+namespace amqp {
+
+void CharSequence::init()
+{
+ data = 0;
+ size = 0;
+}
+
+CharSequence::operator bool() const
+{
+ return data && size;
+}
+std::string CharSequence::str() const
+{
+ return std::string(data, size);
+}
+
+CharSequence CharSequence::create(const char* data, size_t size)
+{
+ CharSequence c = {data, size};
+ return c;
+}
+
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/CharSequence.h b/cpp/src/qpid/amqp/CharSequence.h
new file mode 100644
index 0000000000..307a4b1537
--- /dev/null
+++ b/cpp/src/qpid/amqp/CharSequence.h
@@ -0,0 +1,49 @@
+#ifndef QPID_AMQP_CHARSEQUENCE_H
+#define QPID_AMQP_CHARSEQUENCE_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <stddef.h>
+#include <string>
+#include "qpid/CommonImportExport.h"
+
+namespace qpid {
+namespace amqp {
+
+/**
+ * Simple record of a particular sequence of chars/bytes. The memroy
+ * referenced is assumed to be owned by some other entity, this is
+ * merely a pointer into a (segment of) it.
+ */
+struct CharSequence
+{
+ const char* data;
+ size_t size;
+
+ QPID_COMMON_EXTERN operator bool() const;
+ QPID_COMMON_EXTERN std::string str() const;
+ QPID_COMMON_EXTERN void init();
+
+ QPID_COMMON_EXTERN static CharSequence create(const char* data, size_t size);
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_CHARSEQUENCE_H*/
diff --git a/cpp/src/qpid/amqp/Codec.h b/cpp/src/qpid/amqp/Codec.h
new file mode 100644
index 0000000000..c91cd0a96b
--- /dev/null
+++ b/cpp/src/qpid/amqp/Codec.h
@@ -0,0 +1,83 @@
+#ifndef QPID_AMQP_CODEC_H
+#define QPID_AMQP_CODEC_H
+
+/*
+ *
+ * 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.
+ *
+ */
+namespace qpid {
+namespace amqp {
+
+/**
+ *
+ */
+class Codec
+{
+ public:
+
+
+
+ private:
+
+ struct Constructor
+ {
+ uint8_t code;
+ Descriptor descriptor;
+ bool isDescribed;
+ };
+
+ Constructor readConstructor(Decoder decoder, Reader reader)
+ {
+ Constructor result;
+ result.code = decoder.readCode();
+ if (code == DESCRIPTOR) {
+ result.isDescribed = true;
+ result.descriptor = decoder.readDescriptor();
+ result.code = decoder.readCode();
+ } else {
+ result.isDescribed = false;
+ }
+ return result;
+ }
+};
+
+Codec::Descriptor Codec::Decoder::readDescriptor()
+{
+ uint8_t code = decoder.readCode();
+ switch(code) {
+ case SYMBOL8:
+ return Descriptor(readSequence8());
+ case SYMBOL32:
+ return Descriptor(readSequence32());
+ case ULONG:
+ return Descriptor(readULong());
+ case ULONG_SMALL:
+ return Descriptor((uint64_t) readUByte());
+ case ULONG_ZERO:
+ return Descriptor((uint64_t) 0);
+ default:
+ throw qpid::Exception("Expected descriptor of type ulong or symbol; found " << code);
+ }
+}
+
+Codec::Descriptor::Descriptor(uint64_t id) : value.id(id), type(NUMERIC) {}
+Codec::Descriptor::Descriptor(const CharSequence& symbol) : value.symbol(symbol), type(SYMBOLIC) {}
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_CODEC_H*/
diff --git a/cpp/src/qpid/amqp/Constructor.h b/cpp/src/qpid/amqp/Constructor.h
new file mode 100644
index 0000000000..444e455670
--- /dev/null
+++ b/cpp/src/qpid/amqp/Constructor.h
@@ -0,0 +1,42 @@
+#ifndef QPID_AMQP_CONSTRUCTOR_H
+#define QPID_AMQP_CONSTRUCTOR_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/Descriptor.h"
+namespace qpid {
+namespace amqp {
+
+/**
+ * Representation of an AMQP 1.0 type 'constructor' (i.e. a type code
+ * with an optional descriptor)
+ */
+struct Constructor
+{
+ uint8_t code;
+ Descriptor descriptor;
+ bool isDescribed;
+
+ Constructor(uint8_t c) : code(c), descriptor(0), isDescribed(false) {}
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_CONSTRUCTOR_H*/
diff --git a/cpp/src/qpid/amqp/Decoder.cpp b/cpp/src/qpid/amqp/Decoder.cpp
new file mode 100644
index 0000000000..9c577e6c92
--- /dev/null
+++ b/cpp/src/qpid/amqp/Decoder.cpp
@@ -0,0 +1,545 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/Decoder.h"
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/amqp/Constructor.h"
+#include "qpid/amqp/Descriptor.h"
+#include "qpid/amqp/Reader.h"
+#include "qpid/amqp/typecodes.h"
+#include "qpid/types/Uuid.h"
+#include "qpid/types/Variant.h"
+#include "qpid/log/Statement.h"
+#include "qpid/Exception.h"
+
+namespace qpid {
+namespace amqp {
+
+using namespace qpid::amqp::typecodes;
+
+Decoder::Decoder(const char* d, size_t s) : start(d), size(s), position(0) {}
+
+namespace {
+class MapBuilder : public Reader
+{
+ public:
+ void onNull(const Descriptor*)
+ {
+ qpid::types::Variant v;
+ handle(v, NULL_NAME);
+ }
+ void onBoolean(bool v, const Descriptor*)
+ {
+ handle(v, BOOLEAN_NAME);
+ }
+ void onUByte(uint8_t v, const Descriptor*)
+ {
+ handle(v, UBYTE_NAME);
+ }
+ void onUShort(uint16_t v, const Descriptor*)
+ {
+ handle(v, USHORT_NAME);
+ }
+ void onUInt(uint32_t v, const Descriptor*)
+ {
+ handle(v, UINT_NAME);
+ }
+ void onULong(uint64_t v, const Descriptor*)
+ {
+ handle(v, ULONG_NAME);
+ }
+ void onByte(int8_t v, const Descriptor*)
+ {
+ handle(v, BYTE_NAME);
+ }
+ void onShort(int16_t v, const Descriptor*)
+ {
+ handle(v, SHORT_NAME);
+ }
+ void onInt(int32_t v, const Descriptor*)
+ {
+ handle(v, INT_NAME);
+ }
+ void onLong(int64_t v, const Descriptor*)
+ {
+ handle(v, LONG_NAME);
+ }
+ void onFloat(float v, const Descriptor*)
+ {
+ handle(v, FLOAT_NAME);
+ }
+ void onDouble(double v, const Descriptor*)
+ {
+ handle(v, DOUBLE_NAME);
+ }
+ void onUuid(const CharSequence& v, const Descriptor*)
+ {
+ handle(v, UUID_NAME);
+ }
+ void onTimestamp(int64_t v, const Descriptor*)
+ {
+ handle(v, TIMESTAMP_NAME);
+ }
+ void onBinary(const CharSequence& v, const Descriptor*)
+ {
+ handle(v);
+ }
+ void onString(const CharSequence& v, const Descriptor*)
+ {
+ handle(v);
+ }
+ void onSymbol(const CharSequence& v, const Descriptor*)
+ {
+ handle(v);
+ }
+ MapBuilder(qpid::types::Variant::Map& m) : map(m), state(KEY) {}
+ private:
+ qpid::types::Variant::Map& map;
+ enum {KEY, SKIP, VALUE} state;
+ std::string key;
+
+ template <typename T> void handle(T value, const std::string& name)
+ {
+ switch (state) {
+ case KEY:
+ QPID_LOG(warning, "Ignoring key of type " << name);
+ state = SKIP;
+ break;
+ case VALUE:
+ map[key] = value;
+ case SKIP:
+ state = KEY;
+ break;
+ }
+ }
+ void handle(const CharSequence& value)
+ {
+ switch (state) {
+ case KEY:
+ key = value.str();
+ state = VALUE;
+ break;
+ case VALUE:
+ map[key] = value.str();
+ case SKIP:
+ state = KEY;
+ break;
+ }
+ }
+};
+}
+void Decoder::readMap(qpid::types::Variant::Map& map)
+{
+ MapBuilder builder(map);
+ read(builder);
+}
+
+qpid::types::Variant::Map Decoder::readMap()
+{
+ qpid::types::Variant::Map map;
+ readMap(map);
+ return map;
+}
+
+void Decoder::read(Reader& reader)
+{
+ while (available() && reader.proceed()) {
+ readOne(reader);
+ }
+}
+
+void Decoder::readOne(Reader& reader)
+{
+ const char* temp = start + position;
+ Constructor c = readConstructor();
+ if (c.isDescribed) reader.onDescriptor(c.descriptor, temp);
+ readValue(reader, c.code, c.isDescribed ? &c.descriptor : 0);
+}
+
+void Decoder::readValue(Reader& reader, uint8_t code, const Descriptor* descriptor)
+{
+ switch(code) {
+ case NULL_VALUE:
+ reader.onNull(descriptor);
+ break;
+ case BOOLEAN:
+ reader.onBoolean(readBoolean(), descriptor);
+ break;
+ case BOOLEAN_TRUE:
+ reader.onBoolean(true, descriptor);
+ break;
+ case BOOLEAN_FALSE:
+ reader.onBoolean(false, descriptor);
+ break;
+ case UBYTE:
+ reader.onUByte(readUByte(), descriptor);
+ break;
+ case USHORT:
+ reader.onUShort(readUShort(), descriptor);
+ break;
+ case UINT:
+ reader.onUInt(readUInt(), descriptor);
+ break;
+ case UINT_SMALL:
+ reader.onUInt(readUByte(), descriptor);
+ break;
+ case UINT_ZERO:
+ reader.onUInt(0, descriptor);
+ break;
+ case ULONG:
+ reader.onULong(readULong(), descriptor);
+ break;
+ case ULONG_SMALL:
+ reader.onULong(readUByte(), descriptor);
+ break;
+ case ULONG_ZERO:
+ reader.onULong(0, descriptor);
+ break;
+ case BYTE:
+ reader.onByte(readByte(), descriptor);
+ break;
+ case SHORT:
+ reader.onShort(readShort(), descriptor);
+ break;
+ case INT:
+ reader.onInt(readInt(), descriptor);
+ break;
+ case INT_SMALL:
+ reader.onInt(readByte(), descriptor);
+ break;
+ case LONG:
+ reader.onLong(readLong(), descriptor);
+ break;
+ case LONG_SMALL:
+ reader.onLong(readByte(), descriptor);
+ break;
+ case FLOAT:
+ reader.onFloat(readFloat(), descriptor);
+ break;
+ case DOUBLE:
+ reader.onDouble(readDouble(), descriptor);
+ break;
+ case UUID:
+ reader.onUuid(readRawUuid(), descriptor);
+ break;
+ case TIMESTAMP:
+ reader.onTimestamp(readLong(), descriptor);
+ break;
+
+ case BINARY8:
+ reader.onBinary(readSequence8(), descriptor);
+ break;
+ case BINARY32:
+ reader.onBinary(readSequence32(), descriptor);
+ break;
+ case STRING8:
+ reader.onString(readSequence8(), descriptor);
+ break;
+ case STRING32:
+ reader.onString(readSequence32(), descriptor);
+ break;
+ case SYMBOL8:
+ reader.onSymbol(readSequence8(), descriptor);
+ break;
+ case SYMBOL32:
+ reader.onSymbol(readSequence32(), descriptor);
+ break;
+
+ case LIST0:
+ reader.onStartList(0, CharSequence::create(0, 0), descriptor);
+ reader.onEndList(0, descriptor);
+ break;
+ case LIST8:
+ readList8(reader, descriptor);
+ break;
+ case LIST32:
+ readList32(reader, descriptor);
+ break;
+ case MAP8:
+ readMap8(reader, descriptor);
+ break;
+ case MAP32:
+ readMap32(reader, descriptor);
+ break;
+ case ARRAY8:
+ readArray8(reader, descriptor);
+ break;
+ case ARRAY32:
+ readArray32(reader, descriptor);
+ break;
+ default:
+ break;
+ }
+}
+
+void Decoder::readList8(Reader& reader, const Descriptor* descriptor)
+{
+ uint8_t size = readUByte();
+ uint8_t count = readUByte();
+ readList(reader, size-sizeof(size), count, descriptor);
+}
+
+void Decoder::readList32(Reader& reader, const Descriptor* descriptor)
+{
+ uint32_t size = readUInt();
+ uint32_t count = readUInt();
+ readList(reader, size-sizeof(size), count, descriptor);
+}
+
+void Decoder::readMap8(Reader& reader, const Descriptor* descriptor)
+{
+ uint8_t size = readUByte();
+ uint8_t count = readUByte();
+ readMap(reader, size-sizeof(size), count, descriptor);
+}
+
+void Decoder::readMap32(Reader& reader, const Descriptor* descriptor)
+{
+ uint32_t size = readUInt();
+ uint32_t count = readUInt();
+ readMap(reader, size-sizeof(size), count, descriptor);
+}
+
+void Decoder::readArray8(Reader& reader, const Descriptor* descriptor)
+{
+ uint8_t size = readUByte();
+ uint8_t count = readUByte();
+ readArray(reader, size-sizeof(size), count, descriptor);
+}
+
+void Decoder::readArray32(Reader& reader, const Descriptor* descriptor)
+{
+ uint32_t size = readUInt();
+ uint32_t count = readUInt();
+ readArray(reader, size-sizeof(size), count, descriptor);
+}
+
+void Decoder::readList(Reader& reader, uint32_t size, uint32_t count, const Descriptor* descriptor)
+{
+ if (reader.onStartList(count, CharSequence::create(data(), size), descriptor)) {
+ for (uint32_t i = 0; i < count; ++i) {
+ readOne(reader);
+ }
+ reader.onEndList(count, descriptor);
+ } else {
+ //skip
+ advance(size);
+ }
+}
+void Decoder::readMap(Reader& reader, uint32_t size, uint32_t count, const Descriptor* descriptor)
+{
+ if (reader.onStartMap(count, CharSequence::create(data(), size), descriptor)) {
+ for (uint32_t i = 0; i < count; ++i) {
+ readOne(reader);
+ }
+ reader.onEndMap(count, descriptor);
+ } else {
+ //skip
+ advance(size);
+ }
+}
+
+void Decoder::readArray(Reader& reader, uint32_t size, uint32_t count, const Descriptor* descriptor)
+{
+ size_t temp = position;
+ Constructor constructor = readConstructor();
+ CharSequence raw = CharSequence::create(data(), size-(position-temp));
+ if (reader.onStartArray(count, raw, constructor, descriptor)) {
+ for (uint32_t i = 0; i < count; ++i) {
+ readValue(reader, constructor.code, constructor.isDescribed ? &constructor.descriptor : 0);
+ }
+ reader.onEndArray(count, descriptor);
+ } else {
+ //skip
+ advance(raw.size);
+ }
+}
+
+
+Constructor Decoder::readConstructor()
+{
+ Constructor result(readCode());
+ if (result.code == DESCRIPTOR) {
+ result.isDescribed = true;
+ result.descriptor = readDescriptor();
+ result.code = readCode();
+ } else {
+ result.isDescribed = false;
+ }
+ return result;
+}
+
+Descriptor Decoder::readDescriptor()
+{
+ uint8_t code = readCode();
+ switch(code) {
+ case SYMBOL8:
+ return Descriptor(readSequence8());
+ case SYMBOL32:
+ return Descriptor(readSequence32());
+ case ULONG:
+ return Descriptor(readULong());
+ case ULONG_SMALL:
+ return Descriptor((uint64_t) readUByte());
+ case ULONG_ZERO:
+ return Descriptor((uint64_t) 0);
+ default:
+ throw qpid::Exception(QPID_MSG("Expected descriptor of type ulong or symbol; found " << code));
+ }
+}
+
+void Decoder::advance(size_t n)
+{
+ if (n > available()) throw qpid::Exception(QPID_MSG("Out of Bounds"));
+ position += n;
+}
+
+const char* Decoder::data()
+{
+ return start + position;
+}
+
+size_t Decoder::available()
+{
+ return size - position;
+}
+
+uint8_t Decoder::readCode()
+{
+ return readUByte();
+}
+
+bool Decoder::readBoolean()
+{
+ return readUByte();
+}
+
+uint8_t Decoder::readUByte()
+{
+ return static_cast<uint8_t>(start[position++]);
+}
+
+uint16_t Decoder::readUShort()
+{
+ uint16_t hi = (unsigned char) start[position++];
+ hi = hi << 8;
+ hi |= (unsigned char) start[position++];
+ return hi;
+}
+
+uint32_t Decoder::readUInt()
+{
+ uint32_t a = (unsigned char) start[position++];
+ uint32_t b = (unsigned char) start[position++];
+ uint32_t c = (unsigned char) start[position++];
+ uint32_t d = (unsigned char) start[position++];
+ a = a << 24;
+ a |= b << 16;
+ a |= c << 8;
+ a |= d;
+ return a;
+}
+
+uint64_t Decoder::readULong()
+{
+ uint64_t hi =readUInt();
+ uint64_t lo = readUInt();
+ hi = hi << 32;
+ return hi | lo;
+}
+
+int8_t Decoder::readByte()
+{
+ return (int8_t) readUByte();
+}
+
+int16_t Decoder::readShort()
+{
+ return (int16_t) readUShort();
+}
+
+int32_t Decoder::readInt()
+{
+ return (int32_t) readUInt();
+}
+
+int64_t Decoder::readLong()
+{
+ return (int64_t) readULong();
+}
+
+float Decoder::readFloat()
+{
+ union {
+ uint32_t i;
+ float f;
+ } val;
+ val.i = readUInt();
+ return val.f;
+}
+
+double Decoder::readDouble()
+{
+ union {
+ uint64_t i;
+ double f;
+ } val;
+ val.i = readULong();
+ return val.f;
+}
+
+CharSequence Decoder::readSequence8()
+{
+ CharSequence s;
+ s.size = readUByte();
+ s.data = start + position;
+ advance(s.size);
+ return s;
+}
+
+CharSequence Decoder::readSequence32()
+{
+ CharSequence s;
+ s.size = readUInt();
+ s.data = start + position;
+ advance(s.size);
+ return s;
+}
+
+qpid::types::Uuid Decoder::readUuid()
+{
+ qpid::types::Uuid uuid(start + position);
+ advance(16);
+ return uuid;
+}
+
+CharSequence Decoder::readRawUuid()
+{
+ CharSequence s;
+ s.data = start + position;
+ s.size = 16;
+ advance(s.size);
+ return s;
+}
+
+size_t Decoder::getPosition() const { return position; }
+size_t Decoder::getSize() const { return size; }
+void Decoder::resetSize(size_t s) { size = s; }
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/Decoder.h b/cpp/src/qpid/amqp/Decoder.h
new file mode 100644
index 0000000000..7ddfe0f17f
--- /dev/null
+++ b/cpp/src/qpid/amqp/Decoder.h
@@ -0,0 +1,99 @@
+#ifndef QPID_AMQP_DECODER_H
+#define QPID_AMQP_DECODER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/sys/IntegerTypes.h"
+#include "qpid/CommonImportExport.h"
+#include <map>
+#include <string>
+#include <stddef.h>
+
+namespace qpid {
+namespace types {
+class Uuid;
+class Variant;
+}
+namespace amqp {
+struct CharSequence;
+struct Constructor;
+struct Descriptor;
+class Reader;
+
+/**
+ * Class to assist in decoding an AMQP encoded data-stream.
+ */
+class Decoder
+{
+ public:
+ QPID_COMMON_EXTERN Decoder(const char*, size_t);
+
+ QPID_COMMON_EXTERN size_t available();
+ QPID_COMMON_EXTERN uint8_t readCode();
+
+ QPID_COMMON_EXTERN bool readBoolean();
+ QPID_COMMON_EXTERN uint8_t readUByte();
+ QPID_COMMON_EXTERN uint16_t readUShort();
+ QPID_COMMON_EXTERN uint32_t readUInt();
+ QPID_COMMON_EXTERN uint64_t readULong();
+ QPID_COMMON_EXTERN int8_t readByte();
+ QPID_COMMON_EXTERN int16_t readShort();
+ QPID_COMMON_EXTERN int32_t readInt();
+ QPID_COMMON_EXTERN int64_t readLong();
+ QPID_COMMON_EXTERN float readFloat();
+ QPID_COMMON_EXTERN double readDouble();
+ QPID_COMMON_EXTERN qpid::types::Uuid readUuid();
+ QPID_COMMON_EXTERN CharSequence readSequence8();
+ QPID_COMMON_EXTERN CharSequence readSequence32();
+ QPID_COMMON_EXTERN Descriptor readDescriptor();
+ QPID_COMMON_EXTERN void read(Reader& reader);
+
+ QPID_COMMON_EXTERN void readMap(std::map<std::string, qpid::types::Variant>&);
+ QPID_COMMON_EXTERN std::map<std::string, qpid::types::Variant> readMap();
+ QPID_COMMON_EXTERN void advance(size_t);
+ QPID_COMMON_EXTERN size_t getPosition() const;
+ QPID_COMMON_EXTERN void resetSize(size_t size);
+ QPID_COMMON_EXTERN size_t getSize() const;
+
+ private:
+ const char* const start;
+ size_t size;
+ size_t position;
+
+ void readOne(Reader& reader);
+ void readValue(Reader& reader, uint8_t code, const Descriptor* descriptor);
+ void readList(Reader& reader, uint32_t size, uint32_t count, const Descriptor* descriptor);
+ void readMap(Reader& reader, uint32_t size, uint32_t count, const Descriptor* descriptor);
+ void readArray(Reader& reader, uint32_t size, uint32_t count, const Descriptor* descriptor);
+ void readList8(Reader& reader, const Descriptor* descriptor);
+ void readList32(Reader& reader, const Descriptor* descriptor);
+ void readMap8(Reader& reader, const Descriptor* descriptor);
+ void readMap32(Reader& reader, const Descriptor* descriptor);
+ void readArray8(Reader& reader, const Descriptor* descriptor);
+ void readArray32(Reader& reader, const Descriptor* descriptor);
+ CharSequence readRawUuid();
+ Constructor readConstructor();
+ const char* data();
+
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_DECODER_H*/
diff --git a/cpp/src/qpid/amqp/Descriptor.cpp b/cpp/src/qpid/amqp/Descriptor.cpp
new file mode 100644
index 0000000000..087e87c5e6
--- /dev/null
+++ b/cpp/src/qpid/amqp/Descriptor.cpp
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "Descriptor.h"
+
+namespace qpid {
+namespace amqp {
+Descriptor::Descriptor(uint64_t code) : type(NUMERIC) { value.code = code; }
+Descriptor::Descriptor(const CharSequence& symbol) : type(SYMBOLIC) { value.symbol = symbol; }
+bool Descriptor::match(const std::string& symbol, uint64_t code) const
+{
+ switch (type) {
+ case SYMBOLIC:
+ return symbol.compare(0, symbol.size(), value.symbol.data, value.symbol.size) == 0;
+ case NUMERIC:
+ return code == value.code;
+ }
+ return false;
+}
+
+
+std::ostream& operator<<(std::ostream& os, const Descriptor& d)
+{
+ switch (d.type) {
+ case Descriptor::SYMBOLIC:
+ if (d.value.symbol.data && d.value.symbol.size) os << std::string(d.value.symbol.data, d.value.symbol.size);
+ else os << "null";
+ break;
+ case Descriptor::NUMERIC:
+ os << d.value.code;
+ break;
+ }
+ return os;
+}
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/Descriptor.h b/cpp/src/qpid/amqp/Descriptor.h
new file mode 100644
index 0000000000..c36aa38ee3
--- /dev/null
+++ b/cpp/src/qpid/amqp/Descriptor.h
@@ -0,0 +1,54 @@
+#ifndef QPID_AMQP_DESCRIPTOR_H
+#define QPID_AMQP_DESCRIPTOR_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/sys/IntegerTypes.h"
+#include <ostream>
+
+namespace qpid {
+namespace amqp {
+
+/**
+ * Representation of an AMQP 1.0 type descriptor.
+ */
+struct Descriptor
+{
+ union {
+ CharSequence symbol;
+ uint64_t code;
+ } value;
+ enum {
+ NUMERIC,
+ SYMBOLIC
+ } type;
+
+ Descriptor(uint64_t code);
+ Descriptor(const CharSequence& symbol);
+ bool match(const std::string&, uint64_t) const;
+};
+
+std::ostream& operator<<(std::ostream& os, const Descriptor& d);
+
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_DESCRIPTOR_H*/
diff --git a/cpp/src/qpid/amqp/Encoder.cpp b/cpp/src/qpid/amqp/Encoder.cpp
new file mode 100644
index 0000000000..6599f70811
--- /dev/null
+++ b/cpp/src/qpid/amqp/Encoder.cpp
@@ -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.
+ *
+ */
+#include "qpid/amqp/Encoder.h"
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/amqp/Descriptor.h"
+#include "qpid/amqp/typecodes.h"
+#include "qpid/types/Uuid.h"
+#include "qpid/log/Statement.h"
+#include "qpid/Exception.h"
+#include <assert.h>
+#include <string.h>
+
+namespace qpid {
+namespace amqp {
+
+namespace {
+template <typename T> size_t encode(char* data, T i);
+template <> size_t encode<uint8_t>(char* data, uint8_t i)
+{
+ *data = i;
+ return 1;
+}
+template <> size_t encode<uint16_t>(char* data, uint16_t i)
+{
+ uint16_t b = i;
+ size_t position(0);
+ data[position++] = (uint8_t) (0xFF & (b >> 8));
+ data[position++] = (uint8_t) (0xFF & b);
+ return position;
+}
+template <> size_t encode<uint32_t>(char* data, uint32_t i)
+{
+ uint32_t b = i;
+ size_t position(0);
+ data[position++] = (uint8_t) (0xFF & (b >> 24));
+ data[position++] = (uint8_t) (0xFF & (b >> 16));
+ data[position++] = (uint8_t) (0xFF & (b >> 8));
+ data[position++] = (uint8_t) (0xFF & b);
+ return position;
+}
+template <> size_t encode<uint64_t>(char* data, uint64_t i)
+{
+ uint32_t hi = i >> 32;
+ uint32_t lo = i;
+ size_t r(0);
+ r += encode(data, hi);
+ r += encode(data + r, lo);
+ return r;
+}
+template<typename T> struct Backfill
+{
+ T size;
+ T count;
+ char* location;
+};
+
+template<typename T> void end(T count, void* token, char* current)
+{
+ Backfill<T> b;
+ b.location = (char*) token;
+ b.size = (T) (current - b.location) - sizeof(b.size);
+ b.count = count;
+ b.location += encode<T>(b.location, b.size);
+ encode<T>(b.location, b.count);
+}
+}
+char* Encoder::skip(size_t n)
+{
+ char* current = data + position;
+ check(n);
+ position += n;
+ return current;
+}
+
+void Encoder::write(bool b)
+{
+ check(sizeof(b));
+ position += encode<uint8_t>(data+position, b ? 1u : 0u);
+}
+void Encoder::write(uint8_t i)
+{
+ check(sizeof(i));
+ position += encode<uint8_t>(data+position, i);
+}
+void Encoder::write(uint16_t i)
+{
+ check(sizeof(i));
+ position += encode<uint16_t>(data+position, i);
+}
+void Encoder::write(uint32_t i)
+{
+ check(sizeof(i));
+ position += encode<uint32_t>(data+position, i);
+}
+void Encoder::write(uint64_t i)
+{
+ check(sizeof(i));
+ position += encode<uint64_t>(data+position, i);
+}
+void Encoder::write(int8_t i)
+{
+ check(sizeof(i));
+ position += encode(data+position, (uint8_t) i);
+}
+void Encoder::write(int16_t i)
+{
+ check(sizeof(i));
+ position += encode(data+position, (uint16_t) i);
+}
+void Encoder::write(int32_t i)
+{
+ check(sizeof(i));
+ position += encode(data+position, (uint32_t) i);
+}
+void Encoder::write(int64_t i)
+{
+ check(sizeof(i));
+ position += encode(data+position, (uint64_t) i);
+}
+void Encoder::write(float f)
+{
+ check(sizeof(f));
+ union {
+ uint32_t i;
+ float f;
+ } val;
+
+ val.f = f;
+ write(val.i);
+}
+void Encoder::write(double d)
+{
+ check(sizeof(d));
+ union {
+ uint64_t i;
+ double d;
+ } val;
+
+ val.d = d;
+ write(val.i);
+}
+void Encoder::write(const qpid::types::Uuid& uuid)
+{
+ writeBytes((const char*) uuid.data(), uuid.size());
+}
+
+void Encoder::writeBytes(const char* bytes, size_t count)
+{
+ check(count);
+ ::memcpy(data + position, bytes, count);
+ position += count;
+}
+
+void Encoder::writeCode(uint8_t code)
+{
+ write(code);
+}
+
+void Encoder::writeNull(const Descriptor* d)
+{
+ if (d) writeDescriptor(*d);
+ writeCode(typecodes::NULL_VALUE);
+}
+void Encoder::writeBoolean(bool b, const Descriptor* d)
+{
+ if (d) writeDescriptor(*d);
+ writeCode(b ? typecodes::BOOLEAN_TRUE : typecodes::BOOLEAN_FALSE);
+}
+void Encoder::writeUByte(uint8_t i, const Descriptor* d)
+{
+ write(i, typecodes::UBYTE, d);
+}
+
+void Encoder::writeUShort(uint16_t i, const Descriptor* d)
+{
+ write(i, typecodes::USHORT, d);
+}
+
+void Encoder::writeUInt(uint32_t i, const Descriptor* d)
+{
+ if (i == 0) {
+ if (d) writeDescriptor(*d);
+ writeCode(typecodes::UINT_ZERO);
+ } else {
+ if (i < 256) {
+ write((uint8_t) i, typecodes::UINT_SMALL, d);
+ } else {
+ write(i, typecodes::UINT, d);
+ }
+ }
+}
+
+void Encoder::writeULong(uint64_t i, const Descriptor* d)
+{
+ if (i == 0) {
+ if (d) writeDescriptor(*d);
+ writeCode(typecodes::ULONG_ZERO);
+ } else {
+ if (i < 256) {
+ write((uint8_t) i, typecodes::ULONG_SMALL, d);
+ } else {
+ write(i, typecodes::ULONG, d);
+ }
+ }
+}
+
+void Encoder::writeByte(int8_t i, const Descriptor* d)
+{
+ write((uint8_t) i, typecodes::LONG, d);
+}
+
+void Encoder::writeShort(int16_t i, const Descriptor* d)
+{
+ write((uint16_t) i, typecodes::SHORT, d);
+}
+
+void Encoder::writeInt(int32_t i, const Descriptor* d)
+{
+ write((uint32_t) i, typecodes::INT, d);
+}
+
+void Encoder::writeLong(int64_t i, const Descriptor* d)
+{
+ write((uint64_t) i, typecodes::LONG, d);
+}
+
+void Encoder::writeFloat(float f, const Descriptor* d)
+{
+ write(f, typecodes::FLOAT, d);
+}
+
+void Encoder::writeDouble(double f, const Descriptor* d)
+{
+ write(f, typecodes::DOUBLE, d);
+}
+
+void Encoder::writeUuid(const qpid::types::Uuid& uuid, const Descriptor* d)
+{
+ write(uuid, typecodes::UUID, d);
+}
+
+void Encoder::write(const CharSequence& v, std::pair<uint8_t, uint8_t> codes, const Descriptor* d)
+{
+ if (d) writeDescriptor(*d);
+ if (v.size < 256) {
+ writeCode(codes.first);
+ write((uint8_t) v.size);
+ } else {
+ writeCode(codes.second);
+ write((uint32_t) v.size);
+ }
+ writeBytes(v.data, v.size);
+}
+
+void Encoder::write(const std::string& v, std::pair<uint8_t, uint8_t> codes, const Descriptor* d)
+{
+ if (d) writeDescriptor(*d);
+ if (v.size() < 256) {
+ writeCode(codes.first);
+ write((uint8_t) v.size());
+ } else {
+ writeCode(codes.second);
+ write((uint32_t) v.size());
+ }
+ writeBytes(v.data(), v.size());
+}
+
+void Encoder::writeSymbol(const CharSequence& v, const Descriptor* d)
+{
+ write(v, typecodes::SYMBOL, d);
+}
+
+void Encoder::writeSymbol(const std::string& v, const Descriptor* d)
+{
+ write(v, typecodes::SYMBOL, d);
+}
+
+void Encoder::writeString(const CharSequence& v, const Descriptor* d)
+{
+ write(v, typecodes::STRING, d);
+}
+
+void Encoder::writeString(const std::string& v, const Descriptor* d)
+{
+ write(v, typecodes::STRING, d);
+}
+
+void Encoder::writeBinary(const CharSequence& v, const Descriptor* d)
+{
+ write(v, typecodes::BINARY, d);
+}
+
+void Encoder::writeBinary(const std::string& v, const Descriptor* d)
+{
+ write(v, typecodes::BINARY, d);
+}
+
+void* Encoder::startList8(const Descriptor* d)
+{
+ return start<uint8_t>(typecodes::LIST8, d);
+}
+
+void* Encoder::startList32(const Descriptor* d)
+{
+ return start<uint32_t>(typecodes::LIST32, d);
+}
+
+void Encoder::endList8(uint8_t count, void* token)
+{
+ end<uint8_t>(count, token, data+position);
+}
+
+void Encoder::endList32(uint32_t count, void* token)
+{
+ end<uint32_t>(count, token, data+position);
+}
+
+void* Encoder::startMap8(const Descriptor* d)
+{
+ return start<uint8_t>(typecodes::MAP8, d);
+}
+
+void* Encoder::startMap32(const Descriptor* d)
+{
+ return start<uint32_t>(typecodes::MAP32, d);
+}
+
+void Encoder::endMap8(uint8_t count, void* token)
+{
+ end<uint8_t>(count, token, data+position);
+}
+
+void Encoder::endMap32(uint32_t count, void* token)
+{
+ end<uint32_t>(count, token, data+position);
+}
+
+
+void* Encoder::startArray8(const Constructor& c, const Descriptor* d)
+{
+ return startArray<uint8_t>(typecodes::ARRAY8, d, c);
+}
+
+void* Encoder::startArray32(const Constructor& c, const Descriptor* d)
+{
+ return startArray<uint8_t>(typecodes::ARRAY32, d, c);
+}
+
+void Encoder::endArray8(size_t count, void* token)
+{
+ end<uint8_t>(count, token, data+position);
+}
+
+void Encoder::endArray32(size_t count, void* token)
+{
+ end<uint32_t>(count, token, data+position);
+}
+
+
+void Encoder::writeDescriptor(const Descriptor& d)
+{
+ writeCode(typecodes::DESCRIPTOR);
+ switch (d.type) {
+ case Descriptor::NUMERIC:
+ writeULong(d.value.code, 0);
+ break;
+ case Descriptor::SYMBOLIC:
+ writeSymbol(d.value.symbol, 0);
+ break;
+ }
+}
+void Encoder::check(size_t s)
+{
+ if (position + s > size) {
+ QPID_LOG(notice, "Buffer overflow for write of size " << s << " to buffer of size " << size << " at position " << position);
+ assert(false);
+ throw qpid::Exception("Buffer overflow in encoder!");
+ }
+}
+Encoder::Encoder(char* d, size_t s) : data(d), size(s), position(0) {}
+size_t Encoder::getPosition() { return position; }
+void Encoder::resetPosition(size_t p) { assert(p <= size); position = p; }
+
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/Encoder.h b/cpp/src/qpid/amqp/Encoder.h
new file mode 100644
index 0000000000..e2938a002a
--- /dev/null
+++ b/cpp/src/qpid/amqp/Encoder.h
@@ -0,0 +1,149 @@
+#ifndef QPID_AMQP_ENCODER_H
+#define QPID_AMQP_ENCODER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/sys/IntegerTypes.h"
+#include "qpid/amqp/Constructor.h"
+#include <stddef.h>
+#include <string>
+
+namespace qpid {
+namespace types {
+class Uuid;
+}
+namespace amqp {
+struct CharSequence;
+struct Descriptor;
+
+/**
+ * Class to help create AMQP encoded data.
+ */
+class Encoder
+{
+ public:
+ void writeCode(uint8_t);
+
+ void write(bool);
+ void write(uint8_t);
+ void write(uint16_t);
+ void write(uint32_t);
+ void write(uint64_t);
+ void write(int8_t);
+ void write(int16_t);
+ void write(int32_t);
+ void write(int64_t);
+ void write(float);
+ void write(double);
+ void write(const qpid::types::Uuid&);
+
+ void writeNull(const Descriptor* d=0);
+ void writeBoolean(bool, const Descriptor* d=0);
+ void writeUByte(uint8_t, const Descriptor* d=0);
+ void writeUShort(uint16_t, const Descriptor* d=0);
+ void writeUInt(uint32_t, const Descriptor* d=0);
+ void writeULong(uint64_t, const Descriptor* d=0);
+ void writeByte(int8_t, const Descriptor* d=0);
+ void writeShort(int16_t, const Descriptor* d=0);
+ void writeInt(int32_t, const Descriptor* d=0);
+ void writeLong(int64_t, const Descriptor* d=0);
+ void writeFloat(float, const Descriptor* d=0);
+ void writeDouble(double, const Descriptor* d=0);
+ void writeUuid(const qpid::types::Uuid&, const Descriptor* d=0);
+
+ void writeSymbol(const CharSequence&, const Descriptor* d=0);
+ void writeSymbol(const std::string&, const Descriptor* d=0);
+ void writeString(const CharSequence&, const Descriptor* d=0);
+ void writeString(const std::string&, const Descriptor* d=0);
+ void writeBinary(const CharSequence&, const Descriptor* d=0);
+ void writeBinary(const std::string&, const Descriptor* d=0);
+
+ void* startList8(const Descriptor* d=0);
+ void* startList32(const Descriptor* d=0);
+ void endList8(uint8_t count, void*);
+ void endList32(uint32_t count, void*);
+
+ void* startMap8(const Descriptor* d=0);
+ void* startMap32(const Descriptor* d=0);
+ void endMap8(uint8_t count, void*);
+ void endMap32(uint32_t count, void*);
+
+ void* startArray8(const Constructor&, const Descriptor* d=0);
+ void* startArray32(const Constructor&, const Descriptor* d=0);
+ void endArray8(size_t count, void*);
+ void endArray32(size_t count, void*);
+
+ void writeDescriptor(const Descriptor&);
+ Encoder(char* data, size_t size);
+ size_t getPosition();
+ void resetPosition(size_t p);
+ char* skip(size_t);
+ void writeBytes(const char* bytes, size_t count);
+ virtual ~Encoder() {}
+ private:
+ char* data;
+ size_t size;
+ size_t position;
+
+ void write(const CharSequence& v, std::pair<uint8_t, uint8_t> codes, const Descriptor* d);
+ void write(const std::string& v, std::pair<uint8_t, uint8_t> codes, const Descriptor* d);
+ void check(size_t);
+
+ template<typename T> void write(T value, uint8_t code, const Descriptor* d)
+ {
+ if (d) writeDescriptor(*d);
+ writeCode(code);
+ write(value);
+ }
+
+ template<typename T> void write(T value, std::pair<uint8_t, uint8_t> codes, const Descriptor* d)
+ {
+ if (value < 256) {
+ write((uint8_t) value, codes.first, d);
+ } else {
+ write(value, codes.second, d);
+ }
+ }
+
+ template<typename T> void* start(uint8_t code, const Descriptor* d)
+ {
+ if (d) writeDescriptor(*d);
+ writeCode(code);
+ //skip size and count, will backfill on end
+ return skip(sizeof(T)/*size*/ + sizeof(T)/*count*/);
+ }
+
+ template<typename T> void* startArray(uint8_t code, const Descriptor* d, const Constructor& c)
+ {
+ void* token = start<T>(code, d);
+ if (c.isDescribed) {
+ writeDescriptor(c.descriptor);
+ }
+ check(1);
+ writeCode(c.code);
+ return token;
+ }
+
+};
+
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_ENCODER_H*/
diff --git a/cpp/src/qpid/amqp/ListReader.h b/cpp/src/qpid/amqp/ListReader.h
new file mode 100644
index 0000000000..dce874bf2f
--- /dev/null
+++ b/cpp/src/qpid/amqp/ListReader.h
@@ -0,0 +1,103 @@
+#ifndef QPID_AMQP_LISTREADER_H
+#define QPID_AMQP_LISTREADER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "Reader.h"
+
+namespace qpid {
+namespace amqp {
+
+/**
+ * Utility to assist in reading AMQP encoded lists
+ */
+class ListReader : public Reader
+{
+ public:
+ ListReader() : index(0), level(0) {}
+ virtual ~ListReader() {}
+ virtual void onNull(const Descriptor* descriptor) { getReader().onNull(descriptor); }
+ virtual void onBoolean(bool v, const Descriptor* descriptor) { getReader().onBoolean(v, descriptor); }
+ virtual void onUByte(uint8_t v, const Descriptor* descriptor) { getReader().onUByte(v, descriptor); }
+ virtual void onUShort(uint16_t v, const Descriptor* descriptor) { getReader().onUShort(v, descriptor); }
+ virtual void onUInt(uint32_t v, const Descriptor* descriptor) { getReader().onUInt(v, descriptor); }
+ virtual void onULong(uint64_t v, const Descriptor* descriptor) { getReader().onULong(v, descriptor); }
+ virtual void onByte(int8_t v, const Descriptor* descriptor) { getReader().onByte(v, descriptor); }
+ virtual void onShort(int16_t v, const Descriptor* descriptor) { getReader().onShort(v, descriptor); }
+ virtual void onInt(int32_t v, const Descriptor* descriptor) { getReader().onInt(v, descriptor); }
+ virtual void onLong(int64_t v, const Descriptor* descriptor) { getReader().onLong(v, descriptor); }
+ virtual void onFloat(float v, const Descriptor* descriptor) { getReader().onFloat(v, descriptor); }
+ virtual void onDouble(double v, const Descriptor* descriptor) { getReader().onDouble(v, descriptor); }
+ virtual void onUuid(const CharSequence& v, const Descriptor* descriptor) { getReader().onUuid(v, descriptor); }
+ virtual void onTimestamp(int64_t v, const Descriptor* descriptor) { getReader().onTimestamp(v, descriptor); }
+
+ virtual void onBinary(const CharSequence& v, const Descriptor* descriptor) { getReader().onBinary(v, descriptor); }
+ virtual void onString(const CharSequence& v, const Descriptor* descriptor) { getReader().onString(v, descriptor); }
+ virtual void onSymbol(const CharSequence& v, const Descriptor* descriptor) { getReader().onSymbol(v, descriptor); }
+
+ virtual bool onStartList(uint32_t count, const CharSequence& v, const Descriptor* descriptor)
+ {
+ ++level;
+ getReader().onStartList(count, v, descriptor);
+ return false;
+ }
+ virtual void onEndList(uint32_t count, const Descriptor* descriptor)
+ {
+ --level;
+ getReader().onEndList(count, descriptor);
+ }
+ virtual bool onStartMap(uint32_t count, const CharSequence& v, const Descriptor* descriptor)
+ {
+ ++level;
+ getReader().onStartMap(count, v, descriptor);
+ return false;
+ }
+ virtual void onEndMap(uint32_t count, const Descriptor* descriptor)
+ {
+ --level;
+ getReader().onEndList(count, descriptor);
+ }
+ virtual bool onStartArray(uint32_t count, const CharSequence& v, const Constructor& c, const Descriptor* descriptor)
+ {
+ ++level;
+ getReader().onStartArray(count, v, c, descriptor);
+ return false;
+ }
+ virtual void onEndArray(uint32_t count, const Descriptor* descriptor)
+ {
+ --level;
+ getReader().onEndList(count, descriptor);
+ }
+ private:
+ size_t index;
+ size_t level;
+ Reader& getReader()
+ {
+ Reader& r = getReader(index);
+ if (level == 0) ++index;
+ return r;
+ }
+ protected:
+ virtual Reader& getReader(size_t i) = 0;
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_LISTREADER_H*/
diff --git a/cpp/src/qpid/amqp/LoggingReader.h b/cpp/src/qpid/amqp/LoggingReader.h
new file mode 100644
index 0000000000..ed5cab1cbd
--- /dev/null
+++ b/cpp/src/qpid/amqp/LoggingReader.h
@@ -0,0 +1,64 @@
+#ifndef QPID_AMQP_LOGGINGREADER_H
+#define QPID_AMQP_LOGGINGREADER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "Reader.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace amqp {
+
+class LoggingReader : public Reader
+{
+ public:
+ virtual ~LoggingReader() {}
+ virtual void onNull(const Descriptor*) { if (!ignoreNull()) QPID_LOG(warning, prefix() << "null" << suffix()); }
+ virtual void onBoolean(bool, const Descriptor*) { QPID_LOG(warning, prefix() << "boolean" << suffix()); }
+ virtual void onUByte(uint8_t, const Descriptor*) { QPID_LOG(warning, prefix() << "ubyte" << suffix()); }
+ virtual void onUShort(uint16_t, const Descriptor*) { QPID_LOG(warning, prefix() << "ushort" << suffix()); }
+ virtual void onUInt(uint32_t, const Descriptor*) { QPID_LOG(warning, prefix() << "uint" << suffix()); }
+ virtual void onULong(uint64_t, const Descriptor*) { QPID_LOG(warning, prefix() << "ulong" << suffix()); }
+ virtual void onByte(int8_t, const Descriptor*) { QPID_LOG(warning, prefix() << "byte" << suffix()); }
+ virtual void onShort(int16_t, const Descriptor*) { QPID_LOG(warning, prefix() << "short" << suffix()); }
+ virtual void onInt(int32_t, const Descriptor*) { QPID_LOG(warning, prefix() << "int" << suffix()); }
+ virtual void onLong(int64_t, const Descriptor*) { QPID_LOG(warning, prefix() << "long" << suffix()); }
+ virtual void onFloat(float, const Descriptor*) { QPID_LOG(warning, prefix() << "float" << suffix()); }
+ virtual void onDouble(double, const Descriptor*) { QPID_LOG(warning, prefix() << "double" << suffix()); }
+ virtual void onUuid(const CharSequence&, const Descriptor*) { QPID_LOG(warning, prefix() << "uuid" << suffix()); }
+ virtual void onTimestamp(int64_t, const Descriptor*) { QPID_LOG(warning, prefix() << "timestamp" << suffix()); }
+
+ virtual void onBinary(const CharSequence&, const Descriptor*) { QPID_LOG(warning, prefix() << "binary" << suffix()); }
+ virtual void onString(const CharSequence&, const Descriptor*) { QPID_LOG(warning, prefix() << "string" << suffix()); }
+ virtual void onSymbol(const CharSequence&, const Descriptor*) { QPID_LOG(warning, prefix() << "symbol" << suffix()); }
+
+ virtual bool onStartList(uint32_t, const CharSequence&, const Descriptor*) { QPID_LOG(warning, prefix() << "list" << suffix()); return recursive; }
+ virtual bool onStartMap(uint32_t, const CharSequence&, const Descriptor*) { QPID_LOG(warning, prefix() << "map" << suffix()); return recursive; }
+ virtual bool onStartArray(uint32_t, const CharSequence&, const Constructor&, const Descriptor*) { QPID_LOG(warning, prefix() << "array" << suffix()); return recursive; }
+ protected:
+ virtual bool recursive() { return true; }
+ virtual bool ignoreNull() { return true; }
+ virtual std::string prefix() = 0;
+ virtual std::string suffix() = 0;
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_LOGGINGREADER_H*/
diff --git a/cpp/src/qpid/amqp/MapReader.cpp b/cpp/src/qpid/amqp/MapReader.cpp
new file mode 100644
index 0000000000..2bace74d34
--- /dev/null
+++ b/cpp/src/qpid/amqp/MapReader.cpp
@@ -0,0 +1,289 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/MapReader.h"
+#include "qpid/Exception.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace amqp {
+
+void MapReader::onNull(const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onNullValue(key, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+void MapReader::onBoolean(bool v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onBooleanValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onUByte(uint8_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onUByteValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onUShort(uint16_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onUShortValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onUInt(uint32_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onUIntValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onULong(uint64_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onULongValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onByte(int8_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onByteValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onShort(int16_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onShortValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onInt(int32_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onIntValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onLong(int64_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onLongValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onFloat(float v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onFloatValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onDouble(double v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onDoubleValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onUuid(const CharSequence& v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onUuidValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onTimestamp(int64_t v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onTimestampValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onBinary(const CharSequence& v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onBinaryValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onString(const CharSequence& v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onStringValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key, got string " << v.str()));
+ }
+}
+
+void MapReader::onSymbol(const CharSequence& v, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onSymbolValue(key, v, d);
+ key.data = 0; key.size = 0;
+ } else {
+ key = v;
+ }
+}
+
+bool MapReader::onStartList(uint32_t count, const CharSequence&, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ bool step = onStartListValue(key, count, d);
+ key.data = 0; key.size = 0;
+ return step;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+ return true;
+}
+
+bool MapReader::onStartMap(uint32_t count, const CharSequence&, const Descriptor* d)
+{
+ if (level++) {
+ if (key) {
+ bool step = onStartMapValue(key, count, d);
+ key.data = 0; key.size = 0;
+ return step;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+ }
+ return true;
+}
+
+bool MapReader::onStartArray(uint32_t count, const CharSequence&, const Constructor& c, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ bool step = onStartArrayValue(key, count, c, d);
+ key.data = 0; key.size = 0;
+ return step;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+ return true;
+}
+
+void MapReader::onEndList(uint32_t count, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onEndListValue(key, count, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+void MapReader::onEndMap(uint32_t count, const Descriptor* d)
+{
+ if (--level) {
+ onEndMapValue(key, count, d);
+ key.data = 0; key.size = 0;
+ }
+}
+
+void MapReader::onEndArray(uint32_t count, const Descriptor* d)
+{
+ if (!level) throw qpid::Exception(QPID_MSG("Expecting map as top level datum"));
+ if (key) {
+ onEndArrayValue(key, count, d);
+ key.data = 0; key.size = 0;
+ } else {
+ throw qpid::Exception(QPID_MSG("Expecting symbol as key"));
+ }
+}
+
+MapReader::MapReader() : level(0)
+{
+ key.data = 0; key.size = 0;
+}
+
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/MapReader.h b/cpp/src/qpid/amqp/MapReader.h
new file mode 100644
index 0000000000..fe8f65b30c
--- /dev/null
+++ b/cpp/src/qpid/amqp/MapReader.h
@@ -0,0 +1,104 @@
+#ifndef QPID_AMQP_MAPREADER_H
+#define QPID_AMQP_MAPREADER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "Reader.h"
+#include "CharSequence.h"
+#include <string>
+
+namespace qpid {
+namespace amqp {
+
+/**
+ * Reading AMQP 1.0 encoded data which is constrained to be a symbol
+ * keyeed map. The keys are assumed never to be described, the values
+ * may be.
+ */
+class MapReader : public Reader
+{
+ public:
+ virtual void onNullValue(const CharSequence& /*key*/, const Descriptor*) {}
+ virtual void onBooleanValue(const CharSequence& /*key*/, bool, const Descriptor*) {}
+ virtual void onUByteValue(const CharSequence& /*key*/, uint8_t, const Descriptor*) {}
+ virtual void onUShortValue(const CharSequence& /*key*/, uint16_t, const Descriptor*) {}
+ virtual void onUIntValue(const CharSequence& /*key*/, uint32_t, const Descriptor*) {}
+ virtual void onULongValue(const CharSequence& /*key*/, uint64_t, const Descriptor*) {}
+ virtual void onByteValue(const CharSequence& /*key*/, int8_t, const Descriptor*) {}
+ virtual void onShortValue(const CharSequence& /*key*/, int16_t, const Descriptor*) {}
+ virtual void onIntValue(const CharSequence& /*key*/, int32_t, const Descriptor*) {}
+ virtual void onLongValue(const CharSequence& /*key*/, int64_t, const Descriptor*) {}
+ virtual void onFloatValue(const CharSequence& /*key*/, float, const Descriptor*) {}
+ virtual void onDoubleValue(const CharSequence& /*key*/, double, const Descriptor*) {}
+ virtual void onUuidValue(const CharSequence& /*key*/, const CharSequence&, const Descriptor*) {}
+ virtual void onTimestampValue(const CharSequence& /*key*/, int64_t, const Descriptor*) {}
+
+ virtual void onBinaryValue(const CharSequence& /*key*/, const CharSequence&, const Descriptor*) {}
+ virtual void onStringValue(const CharSequence& /*key*/, const CharSequence&, const Descriptor*) {}
+ virtual void onSymbolValue(const CharSequence& /*key*/, const CharSequence&, const Descriptor*) {}
+
+ /**
+ * @return true to step into elements of the compound value, false
+ * to skip over it
+ */
+ virtual bool onStartListValue(const CharSequence& /*key*/, uint32_t /*count*/, const Descriptor*) { return true; }
+ virtual bool onStartMapValue(const CharSequence& /*key*/, uint32_t /*count*/, const Descriptor*) { return true; }
+ virtual bool onStartArrayValue(const CharSequence& /*key*/, uint32_t /*count*/, const Constructor&, const Descriptor*) { return true; }
+ virtual void onEndListValue(const CharSequence& /*key*/, uint32_t /*count*/, const Descriptor*) {}
+ virtual void onEndMapValue(const CharSequence& /*key*/, uint32_t /*count*/, const Descriptor*) {}
+ virtual void onEndArrayValue(const CharSequence& /*key*/, uint32_t /*count*/, const Descriptor*) {}
+
+
+ //this class implements the Reader interface, thus acting as a transformer into a more map oriented scheme
+ void onNull(const Descriptor*);
+ void onBoolean(bool, const Descriptor*);
+ void onUByte(uint8_t, const Descriptor*);
+ void onUShort(uint16_t, const Descriptor*);
+ void onUInt(uint32_t, const Descriptor*);
+ void onULong(uint64_t, const Descriptor*);
+ void onByte(int8_t, const Descriptor*);
+ void onShort(int16_t, const Descriptor*);
+ void onInt(int32_t, const Descriptor*);
+ void onLong(int64_t, const Descriptor*);
+ void onFloat(float, const Descriptor*);
+ void onDouble(double, const Descriptor*);
+ void onUuid(const CharSequence&, const Descriptor*);
+ void onTimestamp(int64_t, const Descriptor*);
+
+ void onBinary(const CharSequence&, const Descriptor*);
+ void onString(const CharSequence&, const Descriptor*);
+ void onSymbol(const CharSequence&, const Descriptor*);
+
+ bool onStartList(uint32_t /*count*/, const CharSequence&, const Descriptor*);
+ bool onStartMap(uint32_t /*count*/, const CharSequence&, const Descriptor*);
+ bool onStartArray(uint32_t /*count*/, const CharSequence&, const Constructor&, const Descriptor*);
+ void onEndList(uint32_t /*count*/, const Descriptor*);
+ void onEndMap(uint32_t /*count*/, const Descriptor*);
+ void onEndArray(uint32_t /*count*/, const Descriptor*);
+
+ MapReader();
+ private:
+ CharSequence key;
+ size_t level;
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_MAPREADER_H*/
diff --git a/cpp/src/qpid/amqp/MessageEncoder.cpp b/cpp/src/qpid/amqp/MessageEncoder.cpp
new file mode 100644
index 0000000000..852ad29635
--- /dev/null
+++ b/cpp/src/qpid/amqp/MessageEncoder.cpp
@@ -0,0 +1,313 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/MessageEncoder.h"
+#include "qpid/amqp/descriptors.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace amqp {
+
+namespace {
+size_t optimisable(const MessageEncoder::Header& msg)
+{
+ if (msg.getDeliveryCount()) return 5;
+ else if (msg.isFirstAcquirer()) return 4;
+ else if (msg.hasTtl()) return 3;
+ else if (msg.getPriority() != 4) return 2;
+ else if (msg.isDurable()) return 1;
+ else return 0;
+}
+
+size_t optimisable(const MessageEncoder::Properties& msg)
+{
+ if (msg.hasReplyToGroupId()) return 13;
+ else if (msg.hasGroupSequence()) return 12;
+ else if (msg.hasGroupId()) return 11;
+ else if (msg.hasCreationTime()) return 10;
+ else if (msg.hasAbsoluteExpiryTime()) return 9;
+ else if (msg.hasContentEncoding()) return 8;
+ else if (msg.hasContentType()) return 7;
+ else if (msg.hasCorrelationId()) return 6;
+ else if (msg.hasReplyTo()) return 5;
+ else if (msg.hasSubject()) return 4;
+ else if (msg.hasTo()) return 3;
+ else if (msg.hasUserId()) return 2;
+ else if (msg.hasMessageId()) return 1;
+ else return 0;
+}
+size_t encodedSize(const std::string& s)
+{
+ size_t total = s.size();
+ if (total > 255) total += 4;
+ else total += 1;
+ return total;
+}
+const std::string BINARY("binary");
+}
+
+void MessageEncoder::writeHeader(const Header& msg)
+{
+ size_t fields(optimise ? optimisable(msg) : 5);
+ if (fields) {
+ void* token = startList8(&qpid::amqp::message::HEADER);
+ writeBoolean(msg.isDurable());
+ if (fields > 1) writeUByte(msg.getPriority());
+
+ if (msg.getTtl()) writeUInt(msg.getTtl());
+ else if (fields > 2) writeNull();
+
+ if (msg.isFirstAcquirer()) writeBoolean(true);
+ else if (fields > 3) writeNull();
+
+ if (msg.getDeliveryCount()) writeUInt(msg.getDeliveryCount());
+ else if (fields > 4) writeNull();
+ endList8(fields, token);
+ }
+}
+
+
+void MessageEncoder::writeProperties(const Properties& msg)
+{
+ size_t fields(optimise ? optimisable(msg) : 13);
+ if (fields) {
+ void* token = startList32(&qpid::amqp::message::PROPERTIES);
+ if (msg.hasMessageId()) writeString(msg.getMessageId());
+ else writeNull();
+
+ if (msg.hasUserId()) writeBinary(msg.getUserId());
+ else if (fields > 1) writeNull();
+
+ if (msg.hasTo()) writeString(msg.getTo());
+ else if (fields > 2) writeNull();
+
+ if (msg.hasSubject()) writeString(msg.getSubject());
+ else if (fields > 3) writeNull();
+
+ if (msg.hasReplyTo()) writeString(msg.getReplyTo());
+ else if (fields > 4) writeNull();
+
+ if (msg.hasCorrelationId()) writeString(msg.getCorrelationId());
+ else if (fields > 5) writeNull();
+
+ if (msg.hasContentType()) writeSymbol(msg.getContentType());
+ else if (fields > 6) writeNull();
+
+ if (msg.hasContentEncoding()) writeSymbol(msg.getContentEncoding());
+ else if (fields > 7) writeNull();
+
+ if (msg.hasAbsoluteExpiryTime()) writeLong(msg.getAbsoluteExpiryTime());
+ else if (fields > 8) writeNull();
+
+ if (msg.hasCreationTime()) writeLong(msg.getCreationTime());
+ else if (fields > 9) writeNull();
+
+ if (msg.hasGroupId()) writeString(msg.getGroupId());
+ else if (fields > 10) writeNull();
+
+ if (msg.hasGroupSequence()) writeUInt(msg.getGroupSequence());
+ else if (fields > 11) writeNull();
+
+ if (msg.hasReplyToGroupId()) writeString(msg.getReplyToGroupId());
+ else if (fields > 12) writeNull();
+
+ endList32(fields, token);
+ }
+}
+
+void MessageEncoder::writeApplicationProperties(const qpid::types::Variant::Map& properties)
+{
+ writeApplicationProperties(properties, !optimise || properties.size()*2 > 255 || getEncodedSizeForElements(properties) > 255);
+}
+
+void MessageEncoder::writeApplicationProperties(const qpid::types::Variant::Map& properties, bool large)
+{
+ writeMap(properties, &qpid::amqp::message::APPLICATION_PROPERTIES, large);
+}
+
+void MessageEncoder::writeMap(const qpid::types::Variant::Map& properties, const Descriptor* d, bool large)
+{
+ void* token = large ? startMap32(d) : startMap8(d);
+ for (qpid::types::Variant::Map::const_iterator i = properties.begin(); i != properties.end(); ++i) {
+ writeString(i->first);
+ switch (i->second.getType()) {
+ case qpid::types::VAR_MAP:
+ case qpid::types::VAR_LIST:
+ //not allowed (TODO: revise, only strictly true for application-properties) whereas this is now a more general method)
+ QPID_LOG(warning, "Ignoring nested map/list; not allowed in application-properties for AMQP 1.0");
+ case qpid::types::VAR_VOID:
+ writeNull();
+ break;
+ case qpid::types::VAR_BOOL:
+ writeBoolean(i->second);
+ break;
+ case qpid::types::VAR_UINT8:
+ writeUByte(i->second);
+ break;
+ case qpid::types::VAR_UINT16:
+ writeUShort(i->second);
+ break;
+ case qpid::types::VAR_UINT32:
+ writeUInt(i->second);
+ break;
+ case qpid::types::VAR_UINT64:
+ writeULong(i->second);
+ break;
+ case qpid::types::VAR_INT8:
+ writeByte(i->second);
+ break;
+ case qpid::types::VAR_INT16:
+ writeShort(i->second);
+ break;
+ case qpid::types::VAR_INT32:
+ writeInt(i->second);
+ break;
+ case qpid::types::VAR_INT64:
+ writeULong(i->second);
+ break;
+ case qpid::types::VAR_FLOAT:
+ writeFloat(i->second);
+ break;
+ case qpid::types::VAR_DOUBLE:
+ writeDouble(i->second);
+ break;
+ case qpid::types::VAR_STRING:
+ if (i->second.getEncoding() == BINARY) {
+ writeBinary(i->second);
+ } else {
+ writeString(i->second);
+ }
+ break;
+ case qpid::types::VAR_UUID:
+ writeUuid(i->second);
+ break;
+ }
+ }
+ if (large) endMap32(properties.size()*2, token);
+ else endMap8(properties.size()*2, token);
+}
+
+size_t MessageEncoder::getEncodedSize(const Header& h, const Properties& p, const qpid::types::Variant::Map& ap, const std::string& d)
+{
+ //NOTE: this does not take optional optimisation into account,
+ //i.e. it is a 'worst case' estimate for required buffer space
+ size_t total(0);
+
+ //header:
+ total += 3/*descriptor*/ + 1/*code*/ + 1/*size*/ + 1/*count*/ + 5/*codes for each field*/;
+ if (h.getPriority() != 4) total += 1;
+ if (h.getDeliveryCount()) total += 4;
+ if (h.hasTtl()) total += 4;
+ return total + getEncodedSize(p, ap, d);
+}
+
+size_t MessageEncoder::getEncodedSize(const Properties& p, const qpid::types::Variant::Map& ap, const std::string& d)
+{
+ //NOTE: this does not take optional optimisation into account,
+ //i.e. it is a 'worst case' estimate for required buffer space
+ size_t total(0);
+
+ //properties:
+ total += 3/*descriptor*/ + 1/*code*/ + 4/*size*/ + 4/*count*/ + 13/*codes for each field*/;
+ if (p.hasMessageId()) total += encodedSize(p.getMessageId());
+ if (p.hasUserId()) total += encodedSize(p.getUserId());
+ if (p.hasTo()) total += encodedSize(p.getTo());
+ if (p.hasSubject()) total += encodedSize(p.getSubject());
+ if (p.hasReplyTo()) total += encodedSize(p.getReplyTo());
+ if (p.hasCorrelationId()) total += encodedSize(p.getCorrelationId());
+ if (p.hasContentType()) total += encodedSize(p.getContentType());
+ if (p.hasContentEncoding()) total += encodedSize(p.getContentEncoding());
+ if (p.hasAbsoluteExpiryTime()) total += 8;
+ if (p.hasCreationTime()) total += 8;
+ if (p.hasGroupId()) total += encodedSize(p.getGroupId());
+ if (p.hasGroupSequence()) total += 4;
+ if (p.hasReplyToGroupId()) total += encodedSize(p.getReplyToGroupId());
+
+
+ //application-properties:
+ total += 3/*descriptor*/ + getEncodedSize(ap, true);
+ //body:
+ if (d.size()) total += 3/*descriptor*/ + 1/*code*/ + encodedSize(d);
+
+ return total;
+}
+
+size_t MessageEncoder::getEncodedSizeForElements(const qpid::types::Variant::Map& map)
+{
+ size_t total = 0;
+ for (qpid::types::Variant::Map::const_iterator i = map.begin(); i != map.end(); ++i) {
+ total += 1/*code*/ + encodedSize(i->first);
+
+ switch (i->second.getType()) {
+ case qpid::types::VAR_MAP:
+ case qpid::types::VAR_LIST:
+ case qpid::types::VAR_VOID:
+ case qpid::types::VAR_BOOL:
+ total += 1;
+ break;
+
+ case qpid::types::VAR_UINT8:
+ case qpid::types::VAR_INT8:
+ total += 2;
+ break;
+
+ case qpid::types::VAR_UINT16:
+ case qpid::types::VAR_INT16:
+ total += 3;
+ break;
+
+ case qpid::types::VAR_UINT32:
+ case qpid::types::VAR_INT32:
+ case qpid::types::VAR_FLOAT:
+ total += 5;
+ break;
+
+ case qpid::types::VAR_UINT64:
+ case qpid::types::VAR_INT64:
+ case qpid::types::VAR_DOUBLE:
+ total += 9;
+ break;
+
+ case qpid::types::VAR_UUID:
+ total += 17;
+ break;
+
+ case qpid::types::VAR_STRING:
+ total += 1/*code*/ + encodedSize(i->second);
+ break;
+ }
+ }
+ return total;
+}
+
+
+size_t MessageEncoder::getEncodedSize(const qpid::types::Variant::Map& map, bool alwaysUseLargeMap)
+{
+ size_t total = getEncodedSizeForElements(map);
+
+ //its not just the count that determines whether we can use a small map, but the aggregate size:
+ if (alwaysUseLargeMap || map.size()*2 > 255 || total > 255) total += 4/*size*/ + 4/*count*/;
+ else total += 1/*size*/ + 1/*count*/;
+
+ total += 1 /*code for map itself*/;
+
+ return total;
+}
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/MessageEncoder.h b/cpp/src/qpid/amqp/MessageEncoder.h
new file mode 100644
index 0000000000..3db0763e8a
--- /dev/null
+++ b/cpp/src/qpid/amqp/MessageEncoder.h
@@ -0,0 +1,100 @@
+#ifndef QPID_AMQP_MESSAGEENCODER_H
+#define QPID_AMQP_MESSAGEENCODER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/Encoder.h"
+#include "qpid/types/Variant.h"
+
+namespace qpid {
+namespace amqp {
+
+/**
+ *
+ */
+class MessageEncoder : public Encoder
+{
+ public:
+ class Header
+ {
+ public:
+ virtual ~Header() {}
+ virtual bool isDurable() const = 0;
+ virtual uint8_t getPriority() const = 0;
+ virtual bool hasTtl() const = 0;
+ virtual uint32_t getTtl() const = 0;
+ virtual bool isFirstAcquirer() const = 0;
+ virtual uint32_t getDeliveryCount() const = 0;
+ };
+
+ class Properties
+ {
+ public:
+ virtual ~Properties() {}
+ virtual bool hasMessageId() const = 0;
+ virtual std::string getMessageId() const = 0;
+ virtual bool hasUserId() const = 0;
+ virtual std::string getUserId() const = 0;
+ virtual bool hasTo() const = 0;
+ virtual std::string getTo() const = 0;
+ virtual bool hasSubject() const = 0;
+ virtual std::string getSubject() const = 0;
+ virtual bool hasReplyTo() const = 0;
+ virtual std::string getReplyTo() const = 0;
+ virtual bool hasCorrelationId() const = 0;
+ virtual std::string getCorrelationId() const = 0;
+ virtual bool hasContentType() const = 0;
+ virtual std::string getContentType() const = 0;
+ virtual bool hasContentEncoding() const = 0;
+ virtual std::string getContentEncoding() const = 0;
+ virtual bool hasAbsoluteExpiryTime() const = 0;
+ virtual int64_t getAbsoluteExpiryTime() const = 0;
+ virtual bool hasCreationTime() const = 0;
+ virtual int64_t getCreationTime() const = 0;
+ virtual bool hasGroupId() const = 0;
+ virtual std::string getGroupId() const = 0;
+ virtual bool hasGroupSequence() const = 0;
+ virtual uint32_t getGroupSequence() const = 0;
+ virtual bool hasReplyToGroupId() const = 0;
+ virtual std::string getReplyToGroupId() const = 0;
+ };
+
+ MessageEncoder(char* d, size_t s, bool o=false) : Encoder(d, s), optimise(o) {}
+ void writeHeader(const Header&);
+ void writeProperties(const Properties&);
+ void writeApplicationProperties(const qpid::types::Variant::Map& properties);
+ void writeApplicationProperties(const qpid::types::Variant::Map& properties, bool useLargeMap);
+
+ void writeMap(const qpid::types::Variant::Map& map, const Descriptor*, bool useLargeMap);
+
+ static size_t getEncodedSize(const Header&, const Properties&, const qpid::types::Variant::Map&, const std::string&);
+ static size_t getEncodedSize(const Properties&, const qpid::types::Variant::Map&, const std::string&);
+ static size_t getEncodedSize(const qpid::types::Variant::Map&, bool useLargeMap);
+ static size_t getEncodedSize(const qpid::types::Variant::Map&);
+
+ private:
+ bool optimise;
+
+ static size_t getEncodedSizeForElements(const qpid::types::Variant::Map&);
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_MESSAGEENCODER_H*/
diff --git a/cpp/src/qpid/amqp/MessageId.cpp b/cpp/src/qpid/amqp/MessageId.cpp
new file mode 100644
index 0000000000..e6f6f4a231
--- /dev/null
+++ b/cpp/src/qpid/amqp/MessageId.cpp
@@ -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.
+ *
+ */
+#include "qpid/amqp/MessageId.h"
+#include <assert.h>
+#include <boost/lexical_cast.hpp>
+
+namespace qpid {
+namespace amqp {
+
+MessageId::MessageId() : type(BYTES)
+{
+ value.bytes.data = 0;
+ value.bytes.size = 0;
+}
+void MessageId::assign(std::string& s) const
+{
+ switch (type) {
+ case BYTES:
+ if (value.bytes) s.assign(value.bytes.data, value.bytes.size);
+ break;
+ case UUID:
+ s = qpid::types::Uuid(value.bytes).str();
+ break;
+ case ULONG:
+ s = boost::lexical_cast<std::string>(value.ulong);
+ break;
+ }
+}
+
+void MessageId::set(qpid::amqp::CharSequence bytes, qpid::types::VariantType t)
+{
+ switch (t) {
+ case qpid::types::VAR_STRING:
+ type = BYTES;
+ break;
+ case qpid::types::VAR_UUID:
+ type = UUID;
+ assert(bytes.size == 16);
+ break;
+ default:
+ assert(false);
+ }
+ value.bytes = bytes;
+}
+void MessageId::set(uint64_t ulong)
+{
+ type = ULONG;
+ value.ulong = ulong;
+}
+
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/MessageId.h b/cpp/src/qpid/amqp/MessageId.h
new file mode 100644
index 0000000000..ee440f3011
--- /dev/null
+++ b/cpp/src/qpid/amqp/MessageId.h
@@ -0,0 +1,54 @@
+#ifndef QPID_AMQP_MESSAGEID_H
+#define QPID_AMQP_MESSAGEID_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/types/Variant.h"
+#include "qpid/CommonImportExport.h"
+
+namespace qpid {
+namespace amqp {
+
+struct MessageId
+{
+ union
+ {
+ qpid::amqp::CharSequence bytes;
+ uint64_t ulong;
+ } value;
+ enum
+ {
+ BYTES,
+ UUID,
+ ULONG
+ } type;
+
+ QPID_COMMON_EXTERN MessageId();
+ QPID_COMMON_EXTERN void assign(std::string&) const;
+ QPID_COMMON_EXTERN void set(qpid::amqp::CharSequence bytes, qpid::types::VariantType t);
+ QPID_COMMON_EXTERN void set(uint64_t ulong);
+
+};
+
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_MESSAGEID_H*/
diff --git a/cpp/src/qpid/amqp/MessageReader.cpp b/cpp/src/qpid/amqp/MessageReader.cpp
new file mode 100644
index 0000000000..1550fa1977
--- /dev/null
+++ b/cpp/src/qpid/amqp/MessageReader.cpp
@@ -0,0 +1,759 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/MessageReader.h"
+#include "qpid/amqp/Descriptor.h"
+#include "qpid/amqp/descriptors.h"
+#include "qpid/types/Uuid.h"
+#include "qpid/types/Variant.h"
+#include "qpid/log/Statement.h"
+
+using namespace qpid::amqp::message;
+
+namespace qpid {
+namespace amqp {
+namespace {
+
+//header fields:
+const size_t DURABLE(0);
+const size_t PRIORITY(1);
+const size_t TTL(2);
+const size_t FIRST_ACQUIRER(3);
+const size_t DELIVERY_COUNT(4);
+
+//properties fields:
+const size_t MESSAGE_ID(0);
+const size_t USER_ID(1);
+const size_t TO(2);
+const size_t SUBJECT(3);
+const size_t REPLY_TO(4);
+const size_t CORRELATION_ID(5);
+const size_t CONTENT_TYPE(6);
+const size_t CONTENT_ENCODING(7);
+const size_t ABSOLUTE_EXPIRY_TIME(8);
+const size_t CREATION_TIME(9);
+const size_t GROUP_ID(10);
+const size_t GROUP_SEQUENCE(11);
+const size_t REPLY_TO_GROUP_ID(12);
+
+}
+
+/*
+Reader& MessageReader::HeaderReader::getReader(size_t index)
+{
+ switch (index) {
+ case DURABLE: return durableReader;
+ case PRIORITY: return priorityReader;
+ case TTL: return ttlReader;
+ case FIRST_ACQUIRER: return firstAcquirerReader;
+ case DELIVERY_COUNT: return deliveryCountReader;
+ default: return noSuchFieldReader;
+ }
+}
+
+Reader& MessageReader::PropertiesReader::getReader(size_t index)
+{
+ switch (index) {
+ case MESSAGE_ID: return messageIdReader;
+ case USER_ID: return userIdReader;
+ case TO: return toReader;
+ case SUBJECT: return subjectReader;
+ case REPLY_TO: return replyToReader;
+ case CORRELATION_ID: return correlationIdReader;
+ case CONTENT_TYPE: return contentTypeReader;
+ case CONTENT_ENCODING: return contentEncodingReader;
+ case ABSOLUTE_EXPIRY_TIME: return absoluteExpiryTimeReader;
+ case CREATION_TIME: return creationTimeReader;
+ case GROUP_ID: return groupIdReader;
+ case GROUP_SEQUENCE: return groupSequenceReader;
+ case REPLY_TO_GROUP_ID: return replyToGroupIdReader;
+ default: return noSuchFieldReader;
+ }
+}
+*/
+
+MessageReader::HeaderReader::HeaderReader(MessageReader& p) : parent(p), index(0) {}
+void MessageReader::HeaderReader::onBoolean(bool v, const Descriptor*) // durable, first-acquirer
+{
+ if (index == DURABLE) {
+ parent.onDurable(v);
+ } else if (index == FIRST_ACQUIRER) {
+ parent.onFirstAcquirer(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got boolean at index " << index << " of headers");
+ }
+ ++index;
+}
+void MessageReader::HeaderReader::onUByte(uint8_t v, const Descriptor*) // priority
+{
+ if (index == PRIORITY) {
+ parent.onPriority(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got ubyte at index " << index << " of headers");
+ }
+ ++index;
+}
+void MessageReader::HeaderReader::onUInt(uint32_t v, const Descriptor*) // ttl, delivery-count
+{
+ if (index == TTL) {
+ parent.onTtl(v);
+ } else if (index == DELIVERY_COUNT) {
+ parent.onDeliveryCount(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got uint at index " << index << " of headers");
+ }
+ ++index;
+}
+void MessageReader::HeaderReader::onNull(const Descriptor*)
+{
+ ++index;
+}
+
+MessageReader::PropertiesReader::PropertiesReader(MessageReader& p) : parent(p), index(0) {}
+void MessageReader::PropertiesReader::onUuid(const CharSequence& v, const Descriptor*) // message-id, correlation-id
+{
+ if (index == MESSAGE_ID) {
+ parent.onMessageId(v, qpid::types::VAR_UUID);
+ } else if (index == CORRELATION_ID) {
+ parent.onCorrelationId(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got uuid at index " << index << " of properties");
+ }
+ ++index;
+}
+void MessageReader::PropertiesReader::onULong(uint64_t v, const Descriptor*) // message-id, correlation-id
+{
+ if (index == MESSAGE_ID) {
+ parent.onMessageId(v);
+ } else if (index == CORRELATION_ID) {
+ parent.onCorrelationId(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got long at index " << index << " of properties");
+ }
+ ++index;
+}
+void MessageReader::PropertiesReader::onBinary(const CharSequence& v, const Descriptor*) // message-id, correlation-id, user-id
+{
+ if (index == MESSAGE_ID) {
+ parent.onMessageId(v, qpid::types::VAR_STRING);
+ } else if (index == CORRELATION_ID) {
+ parent.onCorrelationId(v);
+ } else if (index == USER_ID) {
+ parent.onUserId(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got binary at index " << index << " of properties");
+ }
+ ++index;
+}
+void MessageReader::PropertiesReader::onString(const CharSequence& v, const Descriptor*) // message-id, correlation-id, group-id, reply-to-group-id, subject, to, reply-to
+{
+ if (index == MESSAGE_ID) {
+ parent.onMessageId(v);
+ } else if (index == CORRELATION_ID) {
+ parent.onCorrelationId(v);
+ } else if (index == GROUP_ID) {
+ parent.onGroupId(v);
+ } else if (index == REPLY_TO_GROUP_ID) {
+ parent.onReplyToGroupId(v);
+ } else if (index == SUBJECT) {
+ parent.onSubject(v);
+ } else if (index == TO) {
+ parent.onTo(v);
+ } else if (index == REPLY_TO) {
+ parent.onReplyTo(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got string at index " << index << " of properties");
+ }
+ ++index;
+}
+void MessageReader::PropertiesReader::onSymbol(const CharSequence& v, const Descriptor*) // content-type, content-encoding
+{
+ if (index == CONTENT_TYPE) {
+ parent.onContentType(v);
+ } else if (index == CONTENT_ENCODING) {
+ parent.onContentEncoding(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got symbol at index " << index << " of properties");
+ }
+ ++index;
+}
+void MessageReader::PropertiesReader::onTimestamp(int64_t v, const Descriptor*) // absolute-expiry-time, creation-time
+{
+ if (index == ABSOLUTE_EXPIRY_TIME) {
+ parent.onAbsoluteExpiryTime(v);
+ } else if (index == CREATION_TIME) {
+ parent.onCreationTime(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got timestamp at index " << index << " of properties");
+ }
+ ++index;
+}
+void MessageReader::PropertiesReader::onUInt(uint32_t v, const Descriptor*) // group-sequence
+{
+ if (index == GROUP_SEQUENCE) {
+ parent.onGroupSequence(v);
+ } else {
+ QPID_LOG(warning, "Unexpected message format, got uint at index " << index << " of properties");
+ }
+ ++index;
+}
+void MessageReader::PropertiesReader::onNull(const Descriptor*)
+{
+ ++index;
+}
+
+/*
+MessageReader::DurableReader::DurableReader(MessageReader& p) : parent(p) {}
+void MessageReader::DurableReader::onBoolean(bool v, const Descriptor*)
+{
+ parent.onDurable(v);
+}
+MessageReader::PriorityReader::PriorityReader(MessageReader& p) : parent(p) {}
+void MessageReader::PriorityReader::onUByte(uint8_t v, const Descriptor*)
+{
+ parent.onPriority(v);
+}
+MessageReader::TtlReader::TtlReader(MessageReader& p) : parent(p) {}
+void MessageReader::TtlReader::onUInt(uint32_t v, const Descriptor*)
+{
+ parent.onTtl(v);
+}
+MessageReader::FirstAcquirerReader::FirstAcquirerReader(MessageReader& p) : parent(p) {}
+void MessageReader::FirstAcquirerReader::onBoolean(bool v, const Descriptor*)
+{
+ parent.onFirstAcquirer(v);
+}
+MessageReader::DeliveryCountReader::DeliveryCountReader(MessageReader& p) : parent(p) {}
+void MessageReader::DeliveryCountReader::onUInt(uint32_t v, const Descriptor*)
+{
+ parent.onDeliveryCount(v);
+}
+MessageReader::MessageIdReader::MessageIdReader(MessageReader& p) : parent(p) {}
+void MessageReader::MessageIdReader::onUuid(const qpid::types::Uuid& v, const Descriptor*)
+{
+ parent.onMessageId(v);
+}
+void MessageReader::MessageIdReader::onULong(uint64_t v, const Descriptor*)
+{
+ parent.onMessageId(v);
+}
+void MessageReader::MessageIdReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onMessageId(v);
+}
+void MessageReader::MessageIdReader::onBinary(const CharSequence& v, const Descriptor*)
+{
+ parent.onMessageId(v);
+}
+MessageReader::UserIdReader::UserIdReader(MessageReader& p) : parent(p) {}
+void MessageReader::UserIdReader::onBinary(const CharSequence& v, const Descriptor*)
+{
+ parent.onUserId(v);
+}
+MessageReader::ToReader::ToReader(MessageReader& p) : parent(p) {}
+void MessageReader::ToReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onTo(v);
+}
+MessageReader::SubjectReader::SubjectReader(MessageReader& p) : parent(p) {}
+void MessageReader::SubjectReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onSubject(v);
+}
+MessageReader::ReplyToReader::ReplyToReader(MessageReader& p) : parent(p) {}
+void MessageReader::ReplyToReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onReplyTo(v);
+}
+MessageReader::CorrelationIdReader::CorrelationIdReader(MessageReader& p) : parent(p) {}
+void MessageReader::CorrelationIdReader::onUuid(const qpid::types::Uuid& v, const Descriptor*)
+{
+ parent.onCorrelationId(v);
+}
+void MessageReader::CorrelationIdReader::onULong(uint64_t v, const Descriptor*)
+{
+ parent.onCorrelationId(v);
+}
+void MessageReader::CorrelationIdReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onCorrelationId(v);
+}
+void MessageReader::CorrelationIdReader::onBinary(const CharSequence& v, const Descriptor*)
+{
+ parent.onCorrelationId(v);
+}
+MessageReader::ContentTypeReader::ContentTypeReader(MessageReader& p) : parent(p) {}
+void MessageReader::ContentTypeReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onContentType(v);
+}
+MessageReader::ContentEncodingReader::ContentEncodingReader(MessageReader& p) : parent(p) {}
+void MessageReader::ContentEncodingReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onContentEncoding(v);
+}
+MessageReader::AbsoluteExpiryTimeReader::AbsoluteExpiryTimeReader(MessageReader& p) : parent(p) {}
+void MessageReader::AbsoluteExpiryTimeReader::onTimestamp(int64_t v, const Descriptor*)
+{
+ parent.onAbsoluteExpiryTime(v);
+}
+MessageReader::CreationTimeReader::CreationTimeReader(MessageReader& p) : parent(p) {}
+void MessageReader::CreationTimeReader::onTimestamp(int64_t v, const Descriptor*)
+{
+ parent.onCreationTime(v);
+}
+MessageReader::GroupIdReader::GroupIdReader(MessageReader& p) : parent(p) {}
+void MessageReader::GroupIdReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onGroupId(v);
+}
+MessageReader::GroupSequenceReader::GroupSequenceReader(MessageReader& p) : parent(p) {}
+void MessageReader::GroupSequenceReader::onUInt(uint32_t v, const Descriptor*)
+{
+ parent.onGroupSequence(v);
+}
+MessageReader::ReplyToGroupIdReader::ReplyToGroupIdReader(MessageReader& p) : parent(p) {}
+void MessageReader::ReplyToGroupIdReader::onString(const CharSequence& v, const Descriptor*)
+{
+ parent.onReplyToGroupId(v);
+}
+*/
+
+//header, properties, amqp-sequence, amqp-value
+bool MessageReader::onStartList(uint32_t count, const CharSequence& raw, const Descriptor* descriptor)
+{
+ if (delegate) {
+ return delegate->onStartList(count, raw, descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got no descriptor for list.");
+ return false;
+ } else if (descriptor->match(HEADER_SYMBOL, HEADER_CODE)) {
+ delegate = &headerReader;
+ return true;
+ } else if (descriptor->match(PROPERTIES_SYMBOL, PROPERTIES_CODE)) {
+ delegate = &propertiesReader;
+ return true;
+ } else if (descriptor->match(AMQP_SEQUENCE_SYMBOL, AMQP_SEQUENCE_CODE) || descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ onBody(raw, *descriptor);
+ return false;
+ } else {
+ QPID_LOG(warning, "Unexpected described list: " << *descriptor);
+ return false;
+ }
+ }
+}
+void MessageReader::onEndList(uint32_t count, const Descriptor* descriptor)
+{
+ if (delegate) {
+ if (descriptor && (descriptor->match(HEADER_SYMBOL, HEADER_CODE) || descriptor->match(PROPERTIES_SYMBOL, PROPERTIES_CODE))) {
+ delegate = 0;
+ } else {
+ delegate->onEndList(count, descriptor);
+ }
+ }
+}
+
+//delivery-annotations, message-annotations, application-properties, amqp-value
+bool MessageReader::onStartMap(uint32_t count, const CharSequence& raw, const Descriptor* descriptor)
+{
+ if (delegate) {
+ return delegate->onStartMap(count, raw, descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got no descriptor for map.");
+ return false;
+ } else if (descriptor->match(DELIVERY_ANNOTATIONS_SYMBOL, DELIVERY_ANNOTATIONS_CODE)) {
+ onDeliveryAnnotations(raw);
+ return false;
+ } else if (descriptor->match(MESSAGE_ANNOTATIONS_SYMBOL, MESSAGE_ANNOTATIONS_CODE)) {
+ onMessageAnnotations(raw);
+ return false;
+ } else if (descriptor->match(FOOTER_SYMBOL, FOOTER_CODE)) {
+ onFooter(raw);
+ return false;
+ } else if (descriptor->match(APPLICATION_PROPERTIES_SYMBOL, APPLICATION_PROPERTIES_CODE)) {
+ onApplicationProperties(raw);
+ return false;
+ } else if (descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ onBody(raw, *descriptor);
+ return false;
+ } else {
+ QPID_LOG(warning, "Unexpected described map: " << *descriptor);
+ return false;
+ }
+ }
+}
+
+void MessageReader::onEndMap(uint32_t count, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onEndMap(count, descriptor);
+ }
+}
+
+//data, amqp-value
+void MessageReader::onBinary(const CharSequence& bytes, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onBinary(bytes, descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got binary value with no descriptor.");
+ } else if (descriptor->match(DATA_SYMBOL, DATA_CODE) || descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ onBody(bytes, *descriptor);
+ } else {
+ QPID_LOG(warning, "Unexpected binary value with descriptor: " << *descriptor);
+ }
+ }
+
+}
+
+//amqp-value
+void MessageReader::onNull(const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onNull(descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant v;
+ onBody(v, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got null value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected null value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+void MessageReader::onString(const CharSequence& v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onString(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ onBody(v, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got string value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected string value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+void MessageReader::onSymbol(const CharSequence& v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onSymbol(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ onBody(v, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got symbol value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected symbol value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onBoolean(bool v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onBoolean(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got boolean value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected boolean value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onUByte(uint8_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onUByte(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got ubyte value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected ubyte value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onUShort(uint16_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onUShort(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got ushort value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected ushort value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onUInt(uint32_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onUInt(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got uint value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected uint value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onULong(uint64_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onULong(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got ulong value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected ulong value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onByte(int8_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onByte(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got byte value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected byte value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onShort(int16_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onShort(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got short value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected short value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onInt(int32_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onInt(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got int value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected int value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onLong(int64_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onLong(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got long value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected long value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onFloat(float v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onFloat(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got float value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected float value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onDouble(double v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onDouble(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got double value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected double value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onUuid(const CharSequence& v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onUuid(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ onBody(v, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got uuid value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected uuid value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+void MessageReader::onTimestamp(int64_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onTimestamp(v, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ qpid::types::Variant body = v;
+ onBody(body, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got timestamp value with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected timestamp value with descriptor: " << *descriptor);
+ }
+ }
+ }
+}
+
+bool MessageReader::onStartArray(uint32_t count, const CharSequence& raw, const Constructor& constructor, const Descriptor* descriptor)
+{
+ if (delegate) {
+ return delegate->onStartArray(count, raw, constructor, descriptor);
+ } else {
+ if (descriptor && descriptor->match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE)) {
+ onBody(raw, *descriptor);
+ } else {
+ if (!descriptor) {
+ QPID_LOG(warning, "Expected described type but got array with no descriptor.");
+ } else {
+ QPID_LOG(warning, "Unexpected array with descriptor: " << *descriptor);
+ }
+ }
+ return false;
+ }
+}
+
+void MessageReader::onEndArray(uint32_t v, const Descriptor* descriptor)
+{
+ if (delegate) {
+ delegate->onEndArray(v, descriptor);
+ }
+}
+
+MessageReader::MessageReader() : headerReader(*this), propertiesReader(*this), delegate(0)
+{
+ bare.init();
+}
+
+void MessageReader::onDescriptor(const Descriptor& descriptor, const char* position)
+{
+ if (bare.data) {
+ if (descriptor.match(FOOTER_SYMBOL, FOOTER_CODE)) {
+ bare.size = position - bare.data;
+ }
+ } else {
+ if (descriptor.match(PROPERTIES_SYMBOL, PROPERTIES_CODE) || descriptor.match(APPLICATION_PROPERTIES_SYMBOL, APPLICATION_PROPERTIES_CODE)
+ || descriptor.match(AMQP_SEQUENCE_SYMBOL, AMQP_SEQUENCE_CODE) || descriptor.match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE) || descriptor.match(DATA_SYMBOL, DATA_CODE)) {
+ bare.data = position;
+ }
+ }
+}
+
+CharSequence MessageReader::getBareMessage() const { return bare; }
+
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/MessageReader.h b/cpp/src/qpid/amqp/MessageReader.h
new file mode 100644
index 0000000000..5d26b288f5
--- /dev/null
+++ b/cpp/src/qpid/amqp/MessageReader.h
@@ -0,0 +1,301 @@
+#ifndef QPID_AMQP_MESSAGEREADER_H
+#define QPID_AMQP_MESSAGEREADER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/amqp/Reader.h"
+#include "qpid/amqp/ListReader.h"
+#include "qpid/types/Variant.h"
+#include "qpid/CommonImportExport.h"
+
+namespace qpid {
+namespace amqp {
+
+/**
+ * Reader for an AMQP 1.0 message
+ */
+class MessageReader : public Reader
+{
+ public:
+ QPID_COMMON_EXTERN MessageReader();
+
+ //header, properties, amqp-sequence, amqp-value
+ QPID_COMMON_EXTERN bool onStartList(uint32_t, const CharSequence&, const Descriptor*);
+ QPID_COMMON_EXTERN void onEndList(uint32_t, const Descriptor*);
+
+ //delivery-annotations, message-annotations, application-headers, amqp-value
+ QPID_COMMON_EXTERN bool onStartMap(uint32_t, const CharSequence&, const Descriptor*);
+ QPID_COMMON_EXTERN void onEndMap(uint32_t, const Descriptor*);
+
+ //data, amqp-value
+ QPID_COMMON_EXTERN void onBinary(const CharSequence&, const Descriptor*);
+
+ //amqp-value
+ QPID_COMMON_EXTERN void onNull(const Descriptor*);
+ QPID_COMMON_EXTERN void onString(const CharSequence&, const Descriptor*);
+ QPID_COMMON_EXTERN void onSymbol(const CharSequence&, const Descriptor*);
+ QPID_COMMON_EXTERN void onBoolean(bool, const Descriptor*);
+ QPID_COMMON_EXTERN void onUByte(uint8_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onUShort(uint16_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onUInt(uint32_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onULong(uint64_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onByte(int8_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onShort(int16_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onInt(int32_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onLong(int64_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onFloat(float, const Descriptor*);
+ QPID_COMMON_EXTERN void onDouble(double, const Descriptor*);
+ QPID_COMMON_EXTERN void onUuid(const CharSequence&, const Descriptor*);
+ QPID_COMMON_EXTERN void onTimestamp(int64_t, const Descriptor*);
+ QPID_COMMON_EXTERN bool onStartArray(uint32_t, const CharSequence&, const Constructor&, const Descriptor*);
+ QPID_COMMON_EXTERN void onEndArray(uint32_t, const Descriptor*);
+ QPID_COMMON_EXTERN void onDescriptor(const Descriptor&, const char*);
+
+ //header:
+ virtual void onDurable(bool) = 0;
+ virtual void onPriority(uint8_t) = 0;
+ virtual void onTtl(uint32_t) = 0;
+ virtual void onFirstAcquirer(bool) = 0;
+ virtual void onDeliveryCount(uint32_t) = 0;
+
+ //properties:
+ virtual void onMessageId(uint64_t) = 0;
+ virtual void onMessageId(const CharSequence&, qpid::types::VariantType) = 0;
+ virtual void onUserId(const CharSequence&) = 0;
+ virtual void onTo(const CharSequence&) = 0;
+ virtual void onSubject(const CharSequence&) = 0;
+ virtual void onReplyTo(const CharSequence&) = 0;
+ virtual void onCorrelationId(uint64_t) = 0;
+ virtual void onCorrelationId(const CharSequence&, qpid::types::VariantType) = 0;
+ virtual void onContentType(const CharSequence&) = 0;
+ virtual void onContentEncoding(const CharSequence&) = 0;
+ virtual void onAbsoluteExpiryTime(int64_t) = 0;
+ virtual void onCreationTime(int64_t) = 0;
+ virtual void onGroupId(const CharSequence&) = 0;
+ virtual void onGroupSequence(uint32_t) = 0;
+ virtual void onReplyToGroupId(const CharSequence&) = 0;
+
+ virtual void onApplicationProperties(const CharSequence&) = 0;
+ virtual void onDeliveryAnnotations(const CharSequence&) = 0;
+ virtual void onMessageAnnotations(const CharSequence&) = 0;
+ virtual void onBody(const CharSequence&, const Descriptor&) = 0;
+ virtual void onBody(const qpid::types::Variant&, const Descriptor&) = 0;
+ virtual void onFooter(const CharSequence&) = 0;
+
+ QPID_COMMON_EXTERN CharSequence getBareMessage() const;
+
+ private:
+ /*
+ class DurableReader : public Reader
+ {
+ public:
+ DurableReader(MessageReader&);
+ void onBoolean(bool v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class PriorityReader : public Reader
+ {
+ public:
+ PriorityReader(MessageReader&);
+ void onUByte(uint8_t v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class TtlReader : public Reader
+ {
+ public:
+ TtlReader(MessageReader&);
+ void onUInt(uint32_t v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class FirstAcquirerReader : public Reader
+ {
+ public:
+ FirstAcquirerReader(MessageReader&);
+ void onBoolean(bool v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class DeliveryCountReader : public Reader
+ {
+ public:
+ DeliveryCountReader(MessageReader&);
+ void onUInt(uint32_t v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+
+ class MessageIdReader : public Reader
+ {
+ public:
+ MessageIdReader(MessageReader&);
+ void onUuid(const qpid::types::Uuid& v, const Descriptor*);
+ void onULong(uint64_t v, const Descriptor*);
+ void onString(const CharSequence& v, const Descriptor*);
+ void onBinary(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class UserIdReader : public Reader
+ {
+ public:
+ UserIdReader(MessageReader&);
+ void onBinary(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class ToReader : public Reader
+ {
+ public:
+ ToReader(MessageReader&);
+ void onString(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class SubjectReader : public Reader
+ {
+ public:
+ SubjectReader(MessageReader&);
+ void onString(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class ReplyToReader : public Reader
+ {
+ public:
+ ReplyToReader(MessageReader&);
+ void onString(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class CorrelationIdReader : public Reader
+ {
+ public:
+ CorrelationIdReader(MessageReader&);
+ void onUuid(const qpid::types::Uuid& v, const Descriptor*);
+ void onULong(uint64_t v, const Descriptor*);
+ void onString(const CharSequence& v, const Descriptor*);
+ void onBinary(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class ContentTypeReader : public Reader
+ {
+ public:
+ ContentTypeReader(MessageReader&);
+ void onString(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class ContentEncodingReader : public Reader
+ {
+ public:
+ ContentEncodingReader(MessageReader&);
+ void onString(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class AbsoluteExpiryTimeReader : public Reader
+ {
+ public:
+ AbsoluteExpiryTimeReader(MessageReader&);
+ void onTimestamp(int64_t v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class CreationTimeReader : public Reader
+ {
+ public:
+ CreationTimeReader(MessageReader&);
+ void onTimestamp(int64_t v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class GroupIdReader : public Reader
+ {
+ public:
+ GroupIdReader(MessageReader&);
+ void onString(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class GroupSequenceReader : public Reader
+ {
+ public:
+ GroupSequenceReader(MessageReader&);
+ void onUInt(uint32_t v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ class ReplyToGroupIdReader : public Reader
+ {
+ public:
+ ReplyToGroupIdReader(MessageReader&);
+ void onString(const CharSequence& v, const Descriptor*);
+ private:
+ MessageReader& parent;
+ };
+ */
+
+ class HeaderReader : public Reader //public ListReader
+ {
+ public:
+ //Reader& getReader(size_t index);
+
+ HeaderReader(MessageReader&);
+ void onBoolean(bool v, const Descriptor*); // durable, first-acquirer
+ void onUByte(uint8_t v, const Descriptor*); // priority
+ void onUInt(uint32_t v, const Descriptor*); // ttl, delivery-count
+ void onNull(const Descriptor*);
+ private:
+ MessageReader& parent;
+ size_t index;
+ };
+ class PropertiesReader : public Reader //public ListReader
+ {
+ public:
+ //Reader& getReader(size_t index);
+
+ PropertiesReader(MessageReader&);
+ void onUuid(const CharSequence& v, const Descriptor*); // message-id, correlation-id
+ void onULong(uint64_t v, const Descriptor*); // message-id, correlation-id
+ void onBinary(const CharSequence& v, const Descriptor*); // message-id, correlation-id, user-id
+ void onString(const CharSequence& v, const Descriptor*); // message-id, correlation-id, group-id, reply-to-group-id, subject, to, reply-to
+ void onSymbol(const CharSequence& v, const Descriptor*); // content-type, content-encoding
+ void onTimestamp(int64_t v, const Descriptor*); // absolute-expiry-time, creation-time
+ void onUInt(uint32_t v, const Descriptor*); // group-sequence
+ void onNull(const Descriptor*);
+ private:
+ MessageReader& parent;
+ size_t index;
+ };
+ HeaderReader headerReader;
+ PropertiesReader propertiesReader;
+ Reader* delegate;
+ CharSequence bare;
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_MESSAGEREADER_H*/
diff --git a/cpp/src/qpid/amqp/Reader.h b/cpp/src/qpid/amqp/Reader.h
new file mode 100644
index 0000000000..64019d1521
--- /dev/null
+++ b/cpp/src/qpid/amqp/Reader.h
@@ -0,0 +1,80 @@
+#ifndef QPID_AMQP_READER_H
+#define QPID_AMQP_READER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/sys/IntegerTypes.h"
+#include <stddef.h>
+
+namespace qpid {
+namespace amqp {
+struct CharSequence;
+struct Constructor;
+struct Descriptor;
+
+/**
+ * Allows an event-driven, callback-based approach to processing an
+ * AMQP encoded data stream. By sublassing and implementing the
+ * methods of interest, readers can be constructed for different
+ * contexts.
+ */
+class Reader
+{
+ public:
+ virtual ~Reader() {}
+ virtual void onNull(const Descriptor*) {}
+ virtual void onBoolean(bool, const Descriptor*) {}
+ virtual void onUByte(uint8_t, const Descriptor*) {}
+ virtual void onUShort(uint16_t, const Descriptor*) {}
+ virtual void onUInt(uint32_t, const Descriptor*) {}
+ virtual void onULong(uint64_t, const Descriptor*) {}
+ virtual void onByte(int8_t, const Descriptor*) {}
+ virtual void onShort(int16_t, const Descriptor*) {}
+ virtual void onInt(int32_t, const Descriptor*) {}
+ virtual void onLong(int64_t, const Descriptor*) {}
+ virtual void onFloat(float, const Descriptor*) {}
+ virtual void onDouble(double, const Descriptor*) {}
+ virtual void onUuid(const CharSequence&, const Descriptor*) {}
+ virtual void onTimestamp(int64_t, const Descriptor*) {}
+
+ virtual void onBinary(const CharSequence&, const Descriptor*) {}
+ virtual void onString(const CharSequence&, const Descriptor*) {}
+ virtual void onSymbol(const CharSequence&, const Descriptor*) {}
+
+ /**
+ * @return true to get elements of the compound value, false
+ * to skip over it
+ */
+ virtual bool onStartList(uint32_t /*count*/, const CharSequence&, const Descriptor*) { return true; }
+ virtual bool onStartMap(uint32_t /*count*/, const CharSequence&, const Descriptor*) { return true; }
+ virtual bool onStartArray(uint32_t /*count*/, const CharSequence&, const Constructor&, const Descriptor*) { return true; }
+ virtual void onEndList(uint32_t /*count*/, const Descriptor*) {}
+ virtual void onEndMap(uint32_t /*count*/, const Descriptor*) {}
+ virtual void onEndArray(uint32_t /*count*/, const Descriptor*) {}
+
+ virtual void onDescriptor(const Descriptor&, const char*) {}
+
+ virtual bool proceed() { return true; }
+ private:
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_READER_H*/
diff --git a/cpp/src/qpid/amqp/Sasl.cpp b/cpp/src/qpid/amqp/Sasl.cpp
new file mode 100644
index 0000000000..7b0779fe94
--- /dev/null
+++ b/cpp/src/qpid/amqp/Sasl.cpp
@@ -0,0 +1,136 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/Sasl.h"
+#include "qpid/amqp/Decoder.h"
+#include "qpid/amqp/Descriptor.h"
+#include "qpid/amqp/Encoder.h"
+#include "qpid/log/Statement.h"
+#include "qpid/framing/Buffer.h"
+#include "qpid/framing/ProtocolVersion.h"
+#include "qpid/framing/ProtocolInitiation.h"
+#include <string.h>
+
+namespace qpid {
+namespace amqp {
+
+Sasl::Sasl(const std::string& i) : id(i), buffer(2*512/*AMQP 1.0's MAX_MIN_FRAME_SIZE - is this enough though?*/), encoder(&buffer[0], buffer.size()) {}
+Sasl::~Sasl() {}
+
+void* Sasl::startFrame()
+{
+ //write sasl frame header, leaving 4 bytes for total size
+ char* start = encoder.skip(4);
+ encoder.write((uint8_t) 0x02);//data offset
+ encoder.write((uint8_t) 0x01);//frame type
+ encoder.write((uint16_t) 0x0000);//ignored
+ return start;
+}
+
+void Sasl::endFrame(void* frame)
+{
+ //now backfill the frame size
+ char* start = (char*) frame;
+ char* current = &buffer[encoder.getPosition()];
+ uint32_t frameSize = current - start;
+ Encoder backfill(start, 4);
+ backfill.write(frameSize);
+ QPID_LOG(trace, "Completed encoding of frame of " << frameSize << " bytes");
+}
+
+
+std::size_t Sasl::read(const char* data, size_t available)
+{
+ size_t consumed = 0;
+ while (available - consumed > 4/*framesize*/) {
+ Decoder decoder(data+consumed, available-consumed);
+ //read frame-header
+ uint32_t frameSize = decoder.readUInt();
+ if (frameSize > decoder.getSize()) break;//don't have all the data for this frame yet
+
+ QPID_LOG(trace, "Reading SASL frame of size " << frameSize);
+ decoder.resetSize(frameSize);
+ uint8_t dataOffset = decoder.readUByte();
+ uint8_t frameType = decoder.readUByte();
+ if (frameType != 0x01) {
+ QPID_LOG(error, "Expected SASL frame; got type " << frameType);
+ }
+ uint16_t ignored = decoder.readUShort();
+ if (ignored) {
+ QPID_LOG(info, "Got non null bytes at end of SASL frame header");
+ }
+
+ //body is at offset 4*dataOffset from the start
+ size_t skip = dataOffset*4 - 8;
+ if (skip) {
+ QPID_LOG(info, "Offset for sasl frame was not as expected");
+ decoder.advance(skip);
+ }
+ decoder.read(*this);
+ consumed += decoder.getPosition();
+ }
+ return consumed;
+}
+
+std::size_t Sasl::write(char* data, size_t size)
+{
+ size_t available = encoder.getPosition();
+ if (available) {
+ size_t encoded = available > size ? size : available;
+ ::memcpy(data, &buffer[0], encoded);
+ size_t remainder = encoder.getPosition() - encoded;
+ if (remainder) {
+ //shuffle
+ ::memcpy(&buffer[0], &buffer[size], remainder);
+ }
+ encoder.resetPosition(remainder);
+ return encoded;
+ } else {
+ return 0;
+ }
+}
+
+std::size_t Sasl::readProtocolHeader(const char* buffer, std::size_t size)
+{
+ framing::ProtocolInitiation pi(qpid::framing::ProtocolVersion(1,0,qpid::framing::ProtocolVersion::SASL));
+ if (size >= pi.encodedSize()) {
+ qpid::framing::Buffer out(const_cast<char*>(buffer), size);
+ pi.decode(out);
+ QPID_LOG_CAT(debug, protocol, id << " read protocol header: " << pi);
+ return pi.encodedSize();
+ } else {
+ return 0;
+ }
+}
+std::size_t Sasl::writeProtocolHeader(char* buffer, std::size_t size)
+{
+ framing::ProtocolInitiation pi(qpid::framing::ProtocolVersion(1,0,qpid::framing::ProtocolVersion::SASL));
+ if (size >= pi.encodedSize()) {
+ QPID_LOG_CAT(debug, protocol, id << " writing protocol header: " << pi);
+ qpid::framing::Buffer out(buffer, size);
+ pi.encode(out);
+ return pi.encodedSize();
+ } else {
+ QPID_LOG_CAT(warning, protocol, id << " insufficient buffer for protocol header: " << size)
+ return 0;
+ }
+}
+
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/Sasl.h b/cpp/src/qpid/amqp/Sasl.h
new file mode 100644
index 0000000000..558f6071fc
--- /dev/null
+++ b/cpp/src/qpid/amqp/Sasl.h
@@ -0,0 +1,54 @@
+#ifndef QPID_AMQP_SASL_H
+#define QPID_AMQP_SASL_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/Encoder.h"
+#include "qpid/amqp/Reader.h"
+#include <string>
+#include <vector>
+
+namespace qpid {
+namespace amqp {
+
+/**
+ * Base for SASL client and server utilities
+ */
+class Sasl : protected Reader
+{
+ public:
+ Sasl(const std::string& id);
+ virtual ~Sasl();
+ std::size_t read(const char* data, size_t available);
+ std::size_t write(char* data, size_t available);
+ std::size_t readProtocolHeader(const char* buffer, std::size_t size);
+ std::size_t writeProtocolHeader(char* buffer, std::size_t size);
+ protected:
+ const std::string id;
+ std::vector<char> buffer;
+ Encoder encoder;
+
+ void* startFrame();
+ void endFrame(void*);
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_SASL_H*/
diff --git a/cpp/src/qpid/amqp/SaslClient.cpp b/cpp/src/qpid/amqp/SaslClient.cpp
new file mode 100644
index 0000000000..69660e9294
--- /dev/null
+++ b/cpp/src/qpid/amqp/SaslClient.cpp
@@ -0,0 +1,154 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "qpid/amqp/SaslClient.h"
+#include "qpid/amqp/Decoder.h"
+#include "qpid/amqp/Descriptor.h"
+#include "qpid/amqp/descriptors.h"
+#include "qpid/amqp/Encoder.h"
+#include "qpid/log/Statement.h"
+
+using namespace qpid::amqp::sasl;
+
+namespace qpid {
+namespace amqp {
+
+SaslClient::SaslClient(const std::string& id) : Sasl(id) {}
+SaslClient::~SaslClient() {}
+void SaslClient::init(const std::string& mechanism, const std::string* response, const std::string* hostname)
+{
+ void* frame = startFrame();
+
+ void* token = encoder.startList32(&SASL_INIT);
+ encoder.writeSymbol(mechanism);
+ if (response) encoder.writeBinary(*response);
+ else encoder.writeNull();
+ if (hostname) encoder.writeString(*hostname);
+ else encoder.writeNull();
+ encoder.endList32(3, token);
+
+ endFrame(frame);
+ QPID_LOG_CAT(debug, protocol, id << " Sent SASL-INIT(" << mechanism << ", " << (response ? *response : "null") << ", " << (hostname ? *hostname : "null") << ")");
+}
+void SaslClient::response(const std::string* r)
+{
+ void* frame = startFrame();
+
+ void* token = encoder.startList32(&SASL_RESPONSE);
+ if (r) encoder.writeBinary(*r);
+ else encoder.writeNull();
+ encoder.endList32(1, token);
+
+ endFrame(frame);
+ QPID_LOG_CAT(debug, protocol, id << " Sent SASL-RESPONSE(" << (r ? *r : "null") << ")");
+}
+
+
+namespace {
+const std::string SPACE(" ");
+class SaslMechanismsReader : public Reader
+{
+ public:
+ SaslMechanismsReader(SaslClient& c) : client(c), expected(0) {}
+ void onSymbol(const CharSequence& mechanism, const Descriptor*)
+ {
+ if (expected) {
+ mechanisms << mechanism.str() << SPACE;
+ } else {
+ client.mechanisms(mechanism.str());
+ }
+ }
+ bool onStartArray(uint32_t count, const CharSequence&, const Constructor&, const Descriptor*)
+ {
+ expected = count;
+ return true;
+ }
+ void onEndArray(uint32_t, const Descriptor*)
+ {
+ client.mechanisms(mechanisms.str());
+ }
+ private:
+ SaslClient& client;
+ uint32_t expected;
+ std::stringstream mechanisms;
+};
+class SaslChallengeReader : public Reader
+{
+ public:
+ SaslChallengeReader(SaslClient& c) : client(c) {}
+ void onNull(const Descriptor*) { client.challenge(); }
+ void onBinary(const CharSequence& c, const Descriptor*) { client.challenge(c.str()); }
+ private:
+ SaslClient& client;
+};
+class SaslOutcomeReader : public Reader
+{
+ public:
+ SaslOutcomeReader(SaslClient& c, bool e) : client(c), expectExtraData(e) {}
+ void onUByte(uint8_t c, const Descriptor*)
+ {
+ if (expectExtraData) code = c;
+ else client.outcome(c);
+ }
+ void onBinary(const CharSequence& extra, const Descriptor*) { client.outcome(code, extra.str()); }
+ void onNull(const Descriptor*) { client.outcome(code); }
+ private:
+ SaslClient& client;
+ bool expectExtraData;
+ uint8_t code;
+};
+}
+
+bool SaslClient::onStartList(uint32_t count, const CharSequence& arguments, const Descriptor* descriptor)
+{
+ if (!descriptor) {
+ QPID_LOG(error, "Expected described type in SASL negotiation but got no descriptor");
+ } else if (descriptor->match(SASL_MECHANISMS_SYMBOL, SASL_MECHANISMS_CODE)) {
+ QPID_LOG(trace, "Reading SASL-MECHANISMS");
+ Decoder decoder(arguments.data, arguments.size);
+ if (count != 1) QPID_LOG(error, "Invalid SASL-MECHANISMS frame; exactly one field expected, got " << count);
+ SaslMechanismsReader reader(*this);
+ decoder.read(reader);
+ } else if (descriptor->match(SASL_CHALLENGE_SYMBOL, SASL_CHALLENGE_CODE)) {
+ QPID_LOG(trace, "Reading SASL-CHALLENGE");
+ Decoder decoder(arguments.data, arguments.size);
+ if (count != 1) QPID_LOG(error, "Invalid SASL-CHALLENGE frame; exactly one field expected, got " << count);
+ SaslChallengeReader reader(*this);
+ decoder.read(reader);
+ } else if (descriptor->match(SASL_OUTCOME_SYMBOL, SASL_OUTCOME_CODE)) {
+ QPID_LOG(trace, "Reading SASL-OUTCOME");
+ Decoder decoder(arguments.data, arguments.size);
+ if (count == 1) {
+ SaslOutcomeReader reader(*this, false);
+ decoder.read(reader);
+ } else if (count == 2) {
+ SaslOutcomeReader reader(*this, true);
+ decoder.read(reader);
+ } else {
+ QPID_LOG(error, "Invalid SASL-OUTCOME frame; got " << count << " fields");
+ }
+ } else {
+ QPID_LOG(error, "Unexpected descriptor in SASL negotiation: " << *descriptor);
+ }
+ return false;
+}
+
+
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/SaslClient.h b/cpp/src/qpid/amqp/SaslClient.h
new file mode 100644
index 0000000000..9f3eefadc2
--- /dev/null
+++ b/cpp/src/qpid/amqp/SaslClient.h
@@ -0,0 +1,54 @@
+#ifndef QPID_AMQP_SASLCLIENT_H
+#define QPID_AMQP_SASLCLIENT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/Sasl.h"
+
+namespace qpid {
+namespace amqp {
+
+/**
+ * Utility for decoding and encoding SASL frames by the peer acting as
+ * the SASL client.
+ */
+class SaslClient : public Sasl
+{
+ public:
+ SaslClient(const std::string& id);
+ virtual ~SaslClient();
+ virtual void mechanisms(const std::string&) = 0;
+ virtual void challenge(const std::string&) = 0;
+ virtual void challenge() = 0; //null != empty string
+ virtual void outcome(uint8_t result, const std::string&) = 0;
+ virtual void outcome(uint8_t result) = 0;
+
+ void init(const std::string& mechanism, const std::string* response, const std::string* hostname);
+ void response(const std::string*);
+
+ private:
+ bool onStartList(uint32_t count, const CharSequence& arguments, const Descriptor* descriptor);
+
+};
+
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_SASLCLIENT_H*/
diff --git a/cpp/src/qpid/amqp/SaslServer.cpp b/cpp/src/qpid/amqp/SaslServer.cpp
new file mode 100644
index 0000000000..403730ad69
--- /dev/null
+++ b/cpp/src/qpid/amqp/SaslServer.cpp
@@ -0,0 +1,183 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/SaslServer.h"
+#include "qpid/amqp/Constructor.h"
+#include "qpid/amqp/Decoder.h"
+#include "qpid/amqp/Descriptor.h"
+#include "qpid/amqp/descriptors.h"
+#include "qpid/amqp/Encoder.h"
+#include "qpid/amqp/typecodes.h"
+#include "qpid/log/Statement.h"
+#include "qpid/StringUtils.h"
+#include <limits>
+#include <vector>
+
+using namespace qpid::amqp::sasl;
+using namespace qpid::amqp::typecodes;
+
+namespace qpid {
+namespace amqp {
+namespace {
+const std::string SPACE(" ");
+const std::string NULL_("NULL");
+}
+
+SaslServer::SaslServer(const std::string& id) : Sasl(id) {}
+SaslServer::~SaslServer() {}
+
+void SaslServer::mechanisms(const std::string& mechanisms)
+{
+ void* frameToken = startFrame();
+
+ std::vector<std::string> parts = split(mechanisms, SPACE);
+ void* listToken = encoder.startList32(&SASL_MECHANISMS);
+ if (parts.size() > 1) {
+ void* arrayToken = encoder.startArray8(Constructor(SYMBOL8));
+ for (std::vector<std::string>::const_iterator i = parts.begin();i != parts.end(); ++i) {
+ uint8_t size = i->size() > std::numeric_limits<uint8_t>::max() ? std::numeric_limits<uint8_t>::max() : i->size();
+ encoder.write(size);
+ encoder.writeBytes(i->data(), size);
+ }
+ encoder.endArray8(parts.size(), arrayToken);
+ } else {
+ encoder.writeSymbol(mechanisms);
+ }
+ encoder.endList32(1, listToken);
+
+ endFrame(frameToken);
+ QPID_LOG_CAT(debug, protocol, id << " Sent SASL-MECHANISMS(" << mechanisms << ") " << encoder.getPosition());
+}
+void SaslServer::challenge(const std::string* c)
+{
+ void* frameToken = startFrame();
+
+ void* listToken = encoder.startList32(&SASL_CHALLENGE);
+ if (c) encoder.writeBinary(*c);
+ else encoder.writeNull();
+ encoder.endList32(1, listToken);
+
+ endFrame(frameToken);
+ QPID_LOG_CAT(debug, protocol, id << " Sent SASL-CHALLENGE(" << (c ? *c : NULL_) << ") " << encoder.getPosition());
+}
+void SaslServer::completed(bool succeeded)
+{
+ void* frameToken = startFrame();
+
+ void* listToken = encoder.startList8(&SASL_OUTCOME);
+ encoder.writeUByte(succeeded ? 0 : 1);
+ encoder.endList8(1, listToken);
+
+ endFrame(frameToken);
+ QPID_LOG_CAT(debug, protocol, id << " Sent SASL-OUTCOME(" << (succeeded ? 0 : 1) << ") " << encoder.getPosition());
+}
+
+namespace {
+class SaslInitReader : public Reader
+{
+ public:
+ SaslInitReader(SaslServer& s, uint32_t e) : server(s), expected(e), hasResponse(false), index(0) {}
+ void onNull(const Descriptor*)
+ {
+ ++index;
+ if (index == 2) {
+ if (--expected == 0) {
+ server.init(mechanism, 0, 0);
+ }
+ } else if (index == 3) {
+ server.init(mechanism, hasResponse ? &response : 0, 0);
+ } else {
+ QPID_LOG(warning, "Unexpected sequence of fields for SASL-INIT: got null for field " << index);
+ }
+ }
+ void onBinary(const CharSequence& r, const Descriptor*)
+ {
+ if (++index != 2) QPID_LOG(warning, "Unexpected sequence of fields for SASL-INIT: got binary for field " << index);
+ response = r.str();
+ hasResponse = true;
+ if (--expected == 0) {
+ server.init(mechanism, &response, 0);
+ }
+ }
+ void onString(const CharSequence& h, const Descriptor*)
+ {
+ if (--expected || ++index != 3) {
+ QPID_LOG(warning, "Unexpected sequence of fields for SASL-INIT: got string for field " << index);
+ } else {
+ std::string hostname = h.str();
+ server.init(mechanism, hasResponse ? &response : 0, &hostname);
+ }
+ }
+ void onSymbol(const CharSequence& m, const Descriptor*)
+ {
+ if (++index != 1) QPID_LOG(warning, "Unexpected sequence of fields for SASL-INIT: got symbol for field " << index);
+ if (--expected) {
+ mechanism = m.str();
+ } else {
+ server.init(m.str(), 0, 0);
+ }
+ }
+ private:
+ SaslServer& server;
+ uint32_t expected;
+ std::string mechanism;
+ std::string response;
+ bool hasResponse;
+ uint32_t index;
+};
+
+class SaslResponseReader : public Reader
+{
+ public:
+ SaslResponseReader(SaslServer& s) : server(s) {}
+ void onNull(const Descriptor*) { server.response(0); }
+ void onBinary(const CharSequence& r, const Descriptor*)
+ {
+ std::string s = r.str();
+ server.response(&s);
+ }
+ private:
+ SaslServer& server;
+};
+}
+
+bool SaslServer::onStartList(uint32_t count, const CharSequence& arguments, const Descriptor* descriptor)
+{
+ if (!descriptor) {
+ QPID_LOG(error, "Expected described type in SASL negotiation but got no descriptor");
+ } else if (descriptor->match(SASL_INIT_SYMBOL, SASL_INIT_CODE)) {
+ QPID_LOG(trace, "Reading SASL-INIT");
+ Decoder decoder(arguments.data, arguments.size);
+ if (count < 1 || count > 3) QPID_LOG(error, "Invalid SASL-INIT frame; got " << count << " fields");
+ SaslInitReader reader(*this, count);
+ decoder.read(reader);
+ } else if (descriptor->match(SASL_RESPONSE_SYMBOL, SASL_RESPONSE_CODE)) {
+ QPID_LOG(trace, "Reading SASL-RESPONSE (" << std::string(arguments.data, arguments.size) << ") " << count << " elements");
+ Decoder decoder(arguments.data, arguments.size);
+ if (count != 1) QPID_LOG(error, "Invalid SASL-RESPONSE frame; exactly one field expected, got " << count);
+ SaslResponseReader reader(*this);
+ decoder.read(reader);
+ } else {
+ QPID_LOG(error, "Unexpected descriptor in SASL negotiation: " << *descriptor);
+ }
+ return false;
+}
+
+}} // namespace qpid::amqp
diff --git a/cpp/src/qpid/amqp/SaslServer.h b/cpp/src/qpid/amqp/SaslServer.h
new file mode 100644
index 0000000000..43b960454f
--- /dev/null
+++ b/cpp/src/qpid/amqp/SaslServer.h
@@ -0,0 +1,50 @@
+#ifndef QPID_AMQP_SASLSERVER_H
+#define QPID_AMQP_SASLSERVER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/Sasl.h"
+
+namespace qpid {
+namespace amqp {
+
+/**
+ * Utility for decoding and encoding SASL frames by the peer acting as
+ * the SASL server.
+ */
+class SaslServer : public Sasl
+{
+ public:
+ SaslServer(const std::string& id);
+ virtual ~SaslServer();
+ virtual void init(const std::string& mechanism, const std::string* response, const std::string* hostname) = 0;
+ virtual void response(const std::string*) = 0;
+
+ void mechanisms(const std::string& mechanisms);
+ void challenge(const std::string*);
+ void completed(bool succeeded);
+
+ private:
+ bool onStartList(uint32_t count, const CharSequence& arguments, const Descriptor* descriptor);
+};
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_SASLSERVER_H*/
diff --git a/cpp/src/qpid/amqp/descriptors.h b/cpp/src/qpid/amqp/descriptors.h
new file mode 100644
index 0000000000..19a8985433
--- /dev/null
+++ b/cpp/src/qpid/amqp/descriptors.h
@@ -0,0 +1,88 @@
+#ifndef QPID_AMQP_DESCRIPTORS_H
+#define QPID_AMQP_DESCRIPTORS_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "Descriptor.h"
+
+namespace qpid {
+namespace amqp {
+
+namespace message {
+const std::string HEADER_SYMBOL("amqp:header:list");
+const std::string PROPERTIES_SYMBOL("amqp:properties:list");
+const std::string DELIVERY_ANNOTATIONS_SYMBOL("amqp:delivery-annotations:map");
+const std::string MESSAGE_ANNOTATIONS_SYMBOL("amqp:message-annotations:map");
+const std::string APPLICATION_PROPERTIES_SYMBOL("amqp:application-properties:map");
+const std::string AMQP_SEQUENCE_SYMBOL("amqp:amqp-sequence:list");
+const std::string AMQP_VALUE_SYMBOL("amqp:amqp-sequence:*");
+const std::string DATA_SYMBOL("amqp:data:binary");
+const std::string FOOTER_SYMBOL("amqp:footer:map");
+
+const uint64_t HEADER_CODE(0x70);
+const uint64_t DELIVERY_ANNOTATIONS_CODE(0x71);
+const uint64_t MESSAGE_ANNOTATIONS_CODE(0x72);
+const uint64_t PROPERTIES_CODE(0x73);
+const uint64_t APPLICATION_PROPERTIES_CODE(0x74);
+const uint64_t DATA_CODE(0x75);
+const uint64_t AMQP_SEQUENCE_CODE(0x76);
+const uint64_t AMQP_VALUE_CODE(0x77);
+const uint64_t FOOTER_CODE(0x78);
+
+const Descriptor HEADER(HEADER_CODE);
+const Descriptor DELIVERY_ANNOTATIONS(DELIVERY_ANNOTATIONS_CODE);
+const Descriptor MESSAGE_ANNOTATIONS(MESSAGE_ANNOTATIONS_CODE);
+const Descriptor PROPERTIES(PROPERTIES_CODE);
+const Descriptor APPLICATION_PROPERTIES(APPLICATION_PROPERTIES_CODE);
+const Descriptor DATA(DATA_CODE);
+}
+
+namespace sasl {
+const std::string SASL_MECHANISMS_SYMBOL("amqp:sasl-mechanisms:list");
+const std::string SASL_INIT_SYMBOL("amqp:sasl-init:list");
+const std::string SASL_CHALLENGE_SYMBOL("amqp:sasl-challenge:list");
+const std::string SASL_RESPONSE_SYMBOL("amqp:sasl-response:list");
+const std::string SASL_OUTCOME_SYMBOL("amqp:sasl-outcome:list");
+
+const uint64_t SASL_MECHANISMS_CODE(0x40);
+const uint64_t SASL_INIT_CODE(0x41);
+const uint64_t SASL_CHALLENGE_CODE(0x42);
+const uint64_t SASL_RESPONSE_CODE(0x43);
+const uint64_t SASL_OUTCOME_CODE(0x44);
+
+const Descriptor SASL_MECHANISMS(SASL_MECHANISMS_CODE);
+const Descriptor SASL_INIT(SASL_INIT_CODE);
+const Descriptor SASL_CHALLENGE(SASL_CHALLENGE_CODE);
+const Descriptor SASL_RESPONSE(SASL_RESPONSE_CODE);
+const Descriptor SASL_OUTCOME(SASL_OUTCOME_CODE);
+}
+
+namespace filters {
+const std::string LEGACY_DIRECT_FILTER_SYMBOL("apache.org:legacy-amqp-direct-binding:string");
+const std::string LEGACY_TOPIC_FILTER_SYMBOL("apache.org:legacy-amqp-direct-binding:string");
+
+const uint64_t LEGACY_DIRECT_FILTER_CODE(0x0000468C00000000ULL);
+const uint64_t LEGACY_TOPIC_FILTER_CODE(0x0000468C00000001ULL);
+}
+
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_DESCRIPTORS_H*/
diff --git a/cpp/src/qpid/amqp/typecodes.h b/cpp/src/qpid/amqp/typecodes.h
new file mode 100644
index 0000000000..3c6bd17b97
--- /dev/null
+++ b/cpp/src/qpid/amqp/typecodes.h
@@ -0,0 +1,115 @@
+#ifndef QPID_AMQP_TYPECODES_H
+#define QPID_AMQP_TYPECODES_H
+
+/*
+ *
+ * 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.
+ *
+ */
+namespace qpid {
+namespace amqp {
+
+namespace typecodes
+{
+const uint8_t DESCRIPTOR(0x0);
+
+const uint8_t NULL_VALUE(0x40);
+
+const uint8_t BOOLEAN(0x56);
+const uint8_t BOOLEAN_TRUE(0x41);
+const uint8_t BOOLEAN_FALSE(0x42);
+
+const uint8_t UBYTE(0x50);
+const uint8_t USHORT(0x60);
+const uint8_t UINT(0x70);
+const uint8_t UINT_SMALL(0x52);
+const uint8_t UINT_ZERO(0x43);
+const uint8_t ULONG(0x80);
+const uint8_t ULONG_SMALL(0x53);
+const uint8_t ULONG_ZERO(0x44);
+
+const uint8_t BYTE(0x51);
+const uint8_t SHORT(0x61);
+const uint8_t INT(0x71);
+const uint8_t INT_SMALL(0x54);
+const uint8_t LONG(0x81);
+const uint8_t LONG_SMALL(0x55);
+
+const uint8_t FLOAT(0x72);
+const uint8_t DOUBLE(0x82);
+
+const uint8_t DECIMAL32(0x74);
+const uint8_t DECIMAL64(0x84);
+const uint8_t DECIMAL128(0x94);
+
+const uint8_t CHAR_UTF32(0x73);
+const uint8_t TIMESTAMP(0x83);
+const uint8_t UUID(0x98);
+
+const uint8_t BINARY8(0xa0);
+const uint8_t BINARY32(0xb0);
+const uint8_t STRING8(0xa1);
+const uint8_t STRING32(0xb1);
+const uint8_t SYMBOL8(0xa3);
+const uint8_t SYMBOL32(0xb3);
+
+typedef std::pair<uint8_t, uint8_t> CodePair;
+const CodePair SYMBOL(SYMBOL8, SYMBOL32);
+const CodePair STRING(STRING8, STRING32);
+const CodePair BINARY(BINARY8, BINARY32);
+
+const uint8_t LIST0(0x45);
+const uint8_t LIST8(0xc0);
+const uint8_t LIST32(0xd0);
+const uint8_t MAP8(0xc1);
+const uint8_t MAP32(0xd1);
+const uint8_t ARRAY8(0xe0);
+const uint8_t ARRAY32(0xf0);
+
+
+const std::string NULL_NAME("null");
+const std::string BOOLEAN_NAME("name");
+
+const std::string UBYTE_NAME("ubyte");
+const std::string USHORT_NAME("ushort");
+const std::string UINT_NAME("uint");
+const std::string ULONG_NAME("ulong");
+
+const std::string BYTE_NAME("byte");
+const std::string SHORT_NAME("short");
+const std::string INT_NAME("int");
+const std::string LONG_NAME("long");
+
+const std::string FLOAT_NAME("float");
+const std::string DOUBLE_NAME("double");
+
+const std::string TIMESTAMP_NAME("timestamp");
+const std::string UUID_NAME("uuid");
+
+const std::string BINARY_NAME("binary");
+const std::string STRING_NAME("string");
+const std::string SYMBOL_NAME("symbol");
+
+const std::string LIST_NAME("list");
+const std::string MAP_NAME("map");
+const std::string ARRAY_NAME("array");
+}
+
+}} // namespace qpid::amqp
+
+#endif /*!QPID_AMQP_TYPECODES_H*/
diff --git a/cpp/src/qpid/amqp_0_10/Connection.cpp b/cpp/src/qpid/amqp_0_10/Connection.cpp
index ceeaadf70c..5312c40f2a 100644
--- a/cpp/src/qpid/amqp_0_10/Connection.cpp
+++ b/cpp/src/qpid/amqp_0_10/Connection.cpp
@@ -74,14 +74,14 @@ bool Connection::isClosed() const {
return pushClosed && popClosed;
}
-size_t Connection::encode(const char* buffer, size_t size) {
+size_t Connection::encode(char* buffer, size_t size) {
{ // Swap frameQueue data into workQueue to avoid holding lock while we encode.
Mutex::ScopedLock l(frameQueueLock);
if (popClosed) return 0; // Can't pop any more frames.
assert(workQueue.empty());
workQueue.swap(frameQueue);
}
- framing::Buffer out(const_cast<char*>(buffer), size);
+ framing::Buffer out(buffer, size);
if (!isClient && !initialized) {
framing::ProtocolInitiation pi(getVersion());
pi.encode(out);
@@ -119,7 +119,6 @@ size_t Connection::encode(const char* buffer, size_t size) {
void Connection::abort() { output.abort(); }
void Connection::activateOutput() { output.activateOutput(); }
-void Connection::giveReadCredit(int32_t credit) { output.giveReadCredit(credit); }
void Connection::close() {
// No more frames can be pushed onto the queue.
@@ -146,10 +145,6 @@ framing::ProtocolVersion Connection::getVersion() const {
return version;
}
-void Connection::setVersion(const framing::ProtocolVersion& v) {
- version = v;
-}
-
size_t Connection::getBuffered() const {
Mutex::ScopedLock l(frameQueueLock);
return buffered;
diff --git a/cpp/src/qpid/amqp_0_10/Connection.h b/cpp/src/qpid/amqp_0_10/Connection.h
index 995d824796..92ae5a3dd3 100644
--- a/cpp/src/qpid/amqp_0_10/Connection.h
+++ b/cpp/src/qpid/amqp_0_10/Connection.h
@@ -61,21 +61,16 @@ class Connection : public sys::ConnectionCodec,
QPID_BROKER_EXTERN Connection(sys::OutputControl&, const std::string& id, bool isClient);
QPID_BROKER_EXTERN void setInputHandler(std::auto_ptr<sys::ConnectionInputHandler> c);
size_t decode(const char* buffer, size_t size);
- size_t encode(const char* buffer, size_t size);
+ size_t encode(char* buffer, size_t size);
bool isClosed() const;
bool canEncode();
void abort();
void activateOutput();
- void giveReadCredit(int32_t);
void closed(); // connection closed by peer.
void close(); // closing from this end.
void send(framing::AMQFrame&);
framing::ProtocolVersion getVersion() const;
size_t getBuffered() const;
-
- /** Used by cluster code to set a special version on "update" connections. */
- // FIXME aconway 2009-07-30: find a cleaner mechanism for this.
- void setVersion(const framing::ProtocolVersion&);
};
}} // namespace qpid::amqp_0_10
diff --git a/cpp/src/qpid/asyncStore/OperationQueue.cpp b/cpp/src/qpid/asyncStore/OperationQueue.cpp
index dff5387827..9dea055223 100644
--- a/cpp/src/qpid/asyncStore/OperationQueue.cpp
+++ b/cpp/src/qpid/asyncStore/OperationQueue.cpp
@@ -51,7 +51,7 @@ OperationQueue::handle(const OperationQueue::OpQueue::Batch& e) {
try {
for (OpQueue::Batch::const_iterator i = e.begin(); i != e.end(); ++i) {
// DEBUG: kpvdr
-std::cout << "#### OperationQueue::handle(): op=" << (*i)->getOpStr() << std::endl << std::flush;
+//std::cout << "#### OperationQueue::handle(): op=" << (*i)->getOpStr() << std::endl << std::flush;
(*i)->executeOp(); // Do store work here
}
} catch (const std::exception& e) {
diff --git a/cpp/src/qpid/asyncStore/Plugin.cpp b/cpp/src/qpid/asyncStore/Plugin.cpp
index 7395fc9b87..666db2120f 100644
--- a/cpp/src/qpid/asyncStore/Plugin.cpp
+++ b/cpp/src/qpid/asyncStore/Plugin.cpp
@@ -54,13 +54,8 @@ Plugin::initialize(Target& target) {
Broker* broker = dynamic_cast<Broker*>(&target);
if (!broker || !m_store) return;
- // Not done in earlyInitialize as the Broker::isInCluster test won't work there.
- if (broker->isInCluster()) {
- QPID_LOG(info, "asyncStore: Part of cluster: Disabling management instrumentation");
- } else {
- QPID_LOG(info, "asyncStore: Enabling management instrumentation");
- m_store->initManagement(broker);
- }
+ QPID_LOG(info, "asyncStore: Enabling management instrumentation");
+ m_store->initManagement(broker);
}
void
diff --git a/cpp/src/qpid/broker/AclModule.h b/cpp/src/qpid/broker/AclModule.h
index 4caf8ed3ce..c01697ace9 100644
--- a/cpp/src/qpid/broker/AclModule.h
+++ b/cpp/src/qpid/broker/AclModule.h
@@ -79,6 +79,8 @@ namespace acl {
PROP_POLICYTYPE,
PROP_MAXQUEUESIZE,
PROP_MAXQUEUECOUNT,
+ PROP_MAXFILESIZE,
+ PROP_MAXFILECOUNT,
PROPERTYSIZE // PROPERTYSIZE must be last in list
};
@@ -102,7 +104,11 @@ namespace acl {
SPECPROP_MAXQUEUESIZELOWERLIMIT,
SPECPROP_MAXQUEUESIZEUPPERLIMIT,
SPECPROP_MAXQUEUECOUNTLOWERLIMIT,
- SPECPROP_MAXQUEUECOUNTUPPERLIMIT };
+ SPECPROP_MAXQUEUECOUNTUPPERLIMIT,
+ SPECPROP_MAXFILESIZELOWERLIMIT,
+ SPECPROP_MAXFILESIZEUPPERLIMIT,
+ SPECPROP_MAXFILECOUNTLOWERLIMIT,
+ SPECPROP_MAXFILECOUNTUPPERLIMIT };
// AclResult shared between ACL spec and ACL authorise interface
enum AclResult {
@@ -126,6 +132,8 @@ namespace broker {
// doTransferAcl pervents time consuming ACL calls on a per-message basis.
virtual bool doTransferAcl()=0;
+ virtual uint16_t getMaxConnectTotal()=0;
+
virtual bool authorise(
const std::string& id,
const acl::Action& action,
@@ -147,9 +155,10 @@ namespace broker {
*/
virtual bool approveConnection (const Connection& connection)=0;
- /** Change connection's counted userId
+ /** Approve queue creation by counting per-user.
*/
- virtual void setUserId(const Connection& connection, const std::string& username)=0;
+ virtual bool approveCreateQueue(const std::string& userId, const std::string& queueName)=0;
+ virtual void recordDestroyQueue(const std::string& queueName)=0;
virtual ~AclModule() {};
};
@@ -222,6 +231,8 @@ namespace acl {
if (str.compare("policytype") == 0) return PROP_POLICYTYPE;
if (str.compare("maxqueuesize") == 0) return PROP_MAXQUEUESIZE;
if (str.compare("maxqueuecount") == 0) return PROP_MAXQUEUECOUNT;
+ if (str.compare("maxfilesize") == 0) return PROP_MAXFILESIZE;
+ if (str.compare("maxfilecount") == 0) return PROP_MAXFILECOUNT;
throw qpid::Exception(str);
}
static inline std::string getPropertyStr(const Property p) {
@@ -240,6 +251,8 @@ namespace acl {
case PROP_POLICYTYPE: return "policytype";
case PROP_MAXQUEUESIZE: return "maxqueuesize";
case PROP_MAXQUEUECOUNT: return "maxqueuecount";
+ case PROP_MAXFILESIZE: return "maxfilesize";
+ case PROP_MAXFILECOUNT: return "maxfilecount";
default: assert(false); // should never get here
}
return "";
@@ -261,6 +274,10 @@ namespace acl {
if (str.compare("queuemaxsizeupperlimit") == 0) return SPECPROP_MAXQUEUESIZEUPPERLIMIT;
if (str.compare("queuemaxcountlowerlimit") == 0) return SPECPROP_MAXQUEUECOUNTLOWERLIMIT;
if (str.compare("queuemaxcountupperlimit") == 0) return SPECPROP_MAXQUEUECOUNTUPPERLIMIT;
+ if (str.compare("filemaxsizelowerlimit") == 0) return SPECPROP_MAXFILESIZELOWERLIMIT;
+ if (str.compare("filemaxsizeupperlimit") == 0) return SPECPROP_MAXFILESIZEUPPERLIMIT;
+ if (str.compare("filemaxcountlowerlimit") == 0) return SPECPROP_MAXFILECOUNTLOWERLIMIT;
+ if (str.compare("filemaxcountupperlimit") == 0) return SPECPROP_MAXFILECOUNTUPPERLIMIT;
// Allow old names in ACL file as aliases for newly-named properties
if (str.compare("maxqueuesize") == 0) return SPECPROP_MAXQUEUESIZEUPPERLIMIT;
if (str.compare("maxqueuecount") == 0) return SPECPROP_MAXQUEUECOUNTUPPERLIMIT;
@@ -284,6 +301,10 @@ namespace acl {
case SPECPROP_MAXQUEUESIZEUPPERLIMIT: return "queuemaxsizeupperlimit";
case SPECPROP_MAXQUEUECOUNTLOWERLIMIT: return "queuemaxcountlowerlimit";
case SPECPROP_MAXQUEUECOUNTUPPERLIMIT: return "queuemaxcountupperlimit";
+ case SPECPROP_MAXFILESIZELOWERLIMIT: return "filemaxsizelowerlimit";
+ case SPECPROP_MAXFILESIZEUPPERLIMIT: return "filemaxsizeupperlimit";
+ case SPECPROP_MAXFILECOUNTLOWERLIMIT: return "filemaxcountlowerlimit";
+ case SPECPROP_MAXFILECOUNTUPPERLIMIT: return "filemaxcountupperlimit";
default: assert(false); // should never get here
}
return "";
diff --git a/cpp/src/qpid/broker/Bridge.cpp b/cpp/src/qpid/broker/Bridge.cpp
index 4604ac643f..75aba70ae8 100644
--- a/cpp/src/qpid/broker/Bridge.cpp
+++ b/cpp/src/qpid/broker/Bridge.cpp
@@ -19,6 +19,8 @@
*
*/
#include "qpid/broker/Bridge.h"
+
+#include "qpid/broker/Broker.h"
#include "qpid/broker/FedOps.h"
#include "qpid/broker/ConnectionState.h"
#include "qpid/broker/Connection.h"
@@ -49,6 +51,11 @@ using qpid::management::ManagementAgent;
using std::string;
namespace _qmf = qmf::org::apache::qpid::broker;
+namespace {
+const std::string QPID_REPLICATE("qpid.replicate");
+const std::string NONE("none");
+}
+
namespace qpid {
namespace broker {
@@ -60,7 +67,7 @@ void Bridge::PushHandler::handle(framing::AMQFrame& frame)
Bridge::Bridge(const std::string& _name, Link* _link, framing::ChannelId _id,
CancellationListener l, const _qmf::ArgsLinkBridge& _args,
InitializeCallback init, const std::string& _queueName, const string& ae) :
- link(_link), channel(_id), args(_args), mgmtObject(0),
+ link(_link), channel(_id), args(_args),
listener(l), name(_name),
queueName(_queueName.empty() ? "qpid.bridge_queue_" + name + "_" + link->getBroker()->getFederationTag()
: _queueName),
@@ -71,10 +78,10 @@ Bridge::Bridge(const std::string& _name, Link* _link, framing::ChannelId _id,
{
ManagementAgent* agent = link->getBroker()->getManagementAgent();
if (agent != 0) {
- mgmtObject = new _qmf::Bridge
+ mgmtObject = _qmf::Bridge::shared_ptr(new _qmf::Bridge
(agent, this, link, name, args.i_durable, args.i_src, args.i_dest,
args.i_key, args.i_srcIsQueue, args.i_srcIsLocal,
- args.i_tag, args.i_excludes, args.i_dynamic, args.i_sync);
+ args.i_tag, args.i_excludes, args.i_dynamic, args.i_sync));
mgmtObject->set_channelId(channel);
agent->addObject(mgmtObject);
}
@@ -121,28 +128,30 @@ void Bridge::create(Connection& c, AsyncStore* const store)
peer->getMessage().flow(args.i_dest, 1, 0xFFFFFFFF);
QPID_LOG(debug, "Activated bridge " << name << " for route from queue " << args.i_src << " to " << args.i_dest);
} else {
- FieldTable queueSettings;
-
- if (args.i_tag.size()) {
- queueSettings.setString("qpid.trace.id", args.i_tag);
- } else {
- const string& peerTag = c.getFederationPeerTag();
- if (peerTag.size())
- queueSettings.setString("qpid.trace.id", peerTag);
+ if (!useExistingQueue) {
+ FieldTable queueSettings;
+
+ if (args.i_tag.size()) {
+ queueSettings.setString("qpid.trace.id", args.i_tag);
+ } else {
+ const string& peerTag = c.getFederationPeerTag();
+ if (peerTag.size())
+ queueSettings.setString("qpid.trace.id", peerTag);
+ }
+
+ if (args.i_excludes.size()) {
+ queueSettings.setString("qpid.trace.exclude", args.i_excludes);
+ } else {
+ const string& localTag = link->getBroker()->getFederationTag();
+ if (localTag.size())
+ queueSettings.setString("qpid.trace.exclude", localTag);
+ }
+
+ bool durable = false;//should this be an arg, or would we use srcIsQueue for durable queues?
+ bool exclusive = true; // only exclusive if the queue is owned by the bridge
+ bool autoDelete = exclusive && !durable;//auto delete transient queues?
+ peer->getQueue().declare(queueName, altEx, false, durable, exclusive, autoDelete, queueSettings);
}
-
- if (args.i_excludes.size()) {
- queueSettings.setString("qpid.trace.exclude", args.i_excludes);
- } else {
- const string& localTag = link->getBroker()->getFederationTag();
- if (localTag.size())
- queueSettings.setString("qpid.trace.exclude", localTag);
- }
-
- bool durable = false;//should this be an arg, or would we use srcIsQueue for durable queues?
- bool exclusive = !useExistingQueue; // only exclusive if the queue is owned by the bridge
- bool autoDelete = exclusive && !durable;//auto delete transient queues?
- peer->getQueue().declare(queueName, altEx, false, durable, exclusive, autoDelete, queueSettings);
if (!args.i_dynamic)
peer->getExchange().bind(queueName, args.i_src, args.i_key, FieldTable());
peer->getMessage().subscribe(queueName, args.i_dest, (useExistingQueue && args.i_sync) ? 0 : 1, 0, false, "", 0, options);
@@ -296,9 +305,9 @@ uint32_t Bridge::encodedSize() const
+ 2; // sync
}
-management::ManagementObject* Bridge::GetManagementObject (void) const
+management::ManagementObject::shared_ptr Bridge::GetManagementObject(void) const
{
- return (management::ManagementObject*) mgmtObject;
+ return mgmtObject;
}
management::Manageable::status_t Bridge::ManagementMethod(uint32_t methodId,
@@ -331,6 +340,7 @@ void Bridge::propagateBinding(const string& key, const string& tagList,
}
string newTagList(tagList + string(tagList.empty() ? "" : ",") + localTag);
+ bindArgs.setString(QPID_REPLICATE, NONE);
bindArgs.setString(qpidFedOp, op);
bindArgs.setString(qpidFedTags, newTagList);
if (origin.empty())
@@ -366,8 +376,7 @@ void Bridge::ioThreadPropagateBinding(const string& queue, const string& exchang
if (resetProxy()) {
peer->getExchange().bind(queue, exchange, key, args);
} else {
- QPID_LOG(error, "Cannot propagate binding for dynamic bridge as session has been detached, deleting dynamic bridge");
- close();
+ // link's periodic maintenance visit will attempt to recover
}
}
diff --git a/cpp/src/qpid/broker/Bridge.h b/cpp/src/qpid/broker/Bridge.h
index 04ac585d80..893febdf92 100644
--- a/cpp/src/qpid/broker/Bridge.h
+++ b/cpp/src/qpid/broker/Bridge.h
@@ -65,6 +65,7 @@ class Bridge : public PersistableConfig,
QPID_BROKER_EXTERN void close();
bool isDurable() { return args.i_durable; }
+ framing::ChannelId getChannel() const { return channel; }
Link *getLink() const { return link; }
const std::string getSrc() const { return args.i_src; }
const std::string getDest() const { return args.i_dest; }
@@ -72,7 +73,7 @@ class Bridge : public PersistableConfig,
bool isDetached() const { return detached; }
- management::ManagementObject* GetManagementObject() const;
+ management::ManagementObject::shared_ptr GetManagementObject() const;
management::Manageable::status_t ManagementMethod(uint32_t methodId,
management::Args& args,
std::string& text);
@@ -128,7 +129,7 @@ class Bridge : public PersistableConfig,
Link* const link;
const framing::ChannelId channel;
qmf::org::apache::qpid::broker::ArgsLinkBridge args;
- qmf::org::apache::qpid::broker::Bridge* mgmtObject;
+ qmf::org::apache::qpid::broker::Bridge::shared_ptr mgmtObject;
CancellationListener listener;
std::string name;
std::string queueName;
diff --git a/cpp/src/qpid/broker/Broker.cpp b/cpp/src/qpid/broker/Broker.cpp
index 08606516d4..49e80689fc 100644
--- a/cpp/src/qpid/broker/Broker.cpp
+++ b/cpp/src/qpid/broker/Broker.cpp
@@ -20,6 +20,8 @@
*/
#include "qpid/broker/Broker.h"
+
+#include "qpid/broker/AclModule.h"
#include "qpid/broker/AsyncResultHandle.h"
#include "qpid/broker/ConfigAsyncContext.h"
#include "qpid/broker/ConfigHandle.h"
@@ -27,9 +29,7 @@
#include "qpid/broker/DirectExchange.h"
#include "qpid/broker/FanOutExchange.h"
#include "qpid/broker/HeadersExchange.h"
-//#include "qpid/broker/MessageStoreModule.h"
-//#include "qpid/broker/NullMessageStore.h"
-//#include "qpid/broker/RecoveryAsyncContext.h"
+#include "qpid/broker/NameGenerator.h"
#include "qpid/broker/RecoveryManagerImpl.h"
#include "qpid/broker/SaslAuthenticator.h"
#include "qpid/broker/SecureConnectionFactory.h"
@@ -43,6 +43,7 @@
#include "qpid/broker/MessageGroupManager.h"
#include "qmf/org/apache/qpid/broker/Package.h"
+#include "qmf/org/apache/qpid/broker/ArgsBrokerConnect.h"
#include "qmf/org/apache/qpid/broker/ArgsBrokerCreate.h"
#include "qmf/org/apache/qpid/broker/ArgsBrokerDelete.h"
#include "qmf/org/apache/qpid/broker/ArgsBrokerQuery.h"
@@ -50,12 +51,12 @@
#include "qmf/org/apache/qpid/broker/ArgsBrokerGetLogLevel.h"
#include "qmf/org/apache/qpid/broker/ArgsBrokerQueueMoveMessages.h"
#include "qmf/org/apache/qpid/broker/ArgsBrokerSetLogLevel.h"
+#include "qmf/org/apache/qpid/broker/ArgsBrokerGetLogHiresTimestamp.h"
+#include "qmf/org/apache/qpid/broker/ArgsBrokerSetLogHiresTimestamp.h"
#include "qmf/org/apache/qpid/broker/ArgsBrokerSetTimestampConfig.h"
#include "qmf/org/apache/qpid/broker/ArgsBrokerGetTimestampConfig.h"
#include "qmf/org/apache/qpid/broker/EventExchangeDeclare.h"
#include "qmf/org/apache/qpid/broker/EventExchangeDelete.h"
-#include "qmf/org/apache/qpid/broker/EventQueueDeclare.h"
-#include "qmf/org/apache/qpid/broker/EventQueueDelete.h"
#include "qmf/org/apache/qpid/broker/EventBind.h"
#include "qmf/org/apache/qpid/broker/EventUnbind.h"
#include "qpid/amqp_0_10/Codecs.h"
@@ -75,6 +76,7 @@
#include "qpid/sys/Dispatcher.h"
#include "qpid/sys/Thread.h"
#include "qpid/sys/Time.h"
+#include "qpid/sys/Timer.h"
#include "qpid/sys/ConnectionInputHandler.h"
#include "qpid/sys/ConnectionInputHandlerFactory.h"
#include "qpid/sys/TimeoutHandler.h"
@@ -110,6 +112,17 @@ namespace _qmf = qmf::org::apache::qpid::broker;
namespace qpid {
namespace broker {
+const std::string empty;
+const std::string amq_direct("amq.direct");
+const std::string amq_topic("amq.topic");
+const std::string amq_fanout("amq.fanout");
+const std::string amq_match("amq.match");
+const std::string qpid_management("qpid.management");
+const std::string knownHostsNone("none");
+
+// static
+Broker* Broker::thisBroker;
+
Broker::Options::Options(const std::string& name) :
qpid::Options(name),
noDataDir(0),
@@ -127,6 +140,7 @@ Broker::Options::Options(const std::string& name) :
queueLimit(100*1048576/*100M default limit*/),
tcpNoDelay(false),
requireEncrypted(false),
+ knownHosts(knownHostsNone),
qmf2Support(true),
qmf1Support(true),
queueFlowStopRatio(80),
@@ -136,7 +150,7 @@ Broker::Options::Options(const std::string& name) :
timestampRcvMsgs(false), // set the 0.10 timestamp delivery property
linkMaintenanceInterval(2),
linkHeartbeatInterval(120),
- maxNegotiateTime(2000) // 2s
+ maxNegotiateTime(10000) // 10s
{
int c = sys::SystemInfo::concurrency();
workerThreads=c+1;
@@ -152,6 +166,7 @@ Broker::Options::Options(const std::string& name) :
("data-dir", optValue(dataDir,"DIR"), "Directory to contain persistent data generated by the broker")
("no-data-dir", optValue(noDataDir), "Don't use a data directory. No persistent configuration will be loaded or stored")
("port,p", optValue(port,"PORT"), "Tells the broker to listen on PORT")
+ ("interface", optValue(listenInterfaces, "<interface name>|<interface address>"), "Which network interfaces to use to listen for incoming connections")
("worker-threads", optValue(workerThreads, "N"), "Sets the broker thread pool size")
("connection-backlog", optValue(connectionBacklog, "N"), "Sets the connection backlog limit for the server socket")
("mgmt-enable,m", optValue(enableMgmt,"yes|no"), "Enable Management")
@@ -175,23 +190,27 @@ Broker::Options::Options(const std::string& name) :
("default-event-threshold-ratio", optValue(queueThresholdEventRatio, "%age of limit"), "The ratio of any specified queue limit at which an event will be raised")
("default-message-group", optValue(defaultMsgGroup, "GROUP-IDENTIFER"), "Group identifier to assign to messages delivered to a message group queue that do not contain an identifier.")
("enable-timestamp", optValue(timestampRcvMsgs, "yes|no"), "Add current time to each received message.")
- ("link-maintenace-interval", optValue(linkMaintenanceInterval, "SECONDS"))
- ("link-heartbeat-interval", optValue(linkHeartbeatInterval, "SECONDS"))
- ("max-negotiate-time", optValue(maxNegotiateTime, "MilliSeconds"), "Maximum time a connection can take to send the initial protocol negotiation")
+ ("link-maintenance-interval", optValue(linkMaintenanceInterval, "SECONDS"),
+ "Interval to check link health and re-connect if need be")
+ ("link-heartbeat-interval", optValue(linkHeartbeatInterval, "SECONDS"),
+ "Heartbeat interval for a federation link")
+ ("max-negotiate-time", optValue(maxNegotiateTime, "MILLISECONDS"), "Maximum time a connection can take to send the initial protocol negotiation")
("federation-tag", optValue(fedTag, "NAME"), "Override the federation tag")
;
}
-const std::string empty;
-const std::string amq_direct("amq.direct");
-const std::string amq_topic("amq.topic");
-const std::string amq_fanout("amq.fanout");
-const std::string amq_match("amq.match");
-const std::string qpid_management("qpid.management");
-const std::string knownHostsNone("none");
+namespace {
+// Arguments to declare a non-replicated exchange.
+framing::FieldTable noReplicateArgs() {
+ framing::FieldTable args;
+ args.setString("qpid.replicate", "none");
+ return args;
+}
+}
Broker::Broker(const Broker::Options& conf) :
poller(new Poller),
+ timer(new qpid::sys::Timer),
config(conf),
managementAgent(conf.enableMgmt ? new ManagementAgent(conf.qmf1Support,
conf.qmf2Support)
@@ -205,21 +224,18 @@ Broker::Broker(const Broker::Options& conf) :
exchanges(this),
links(this),
factory(new SecureConnectionFactory(*this)),
- dtxManager(timer),
+ dtxManager(*timer.get()),
sessionManager(
qpid::SessionState::Configuration(
conf.replayFlushLimit*1024, // convert kb to bytes.
conf.replayHardLimit*1024),
*this),
- mgmtObject(0),
- queueCleaner(queues, &timer),
- recovery(true),
- inCluster(false),
- clusterUpdatee(false),
+ queueCleaner(queues, timer.get()),
+ recoveryInProgress(false),
expiryPolicy(new ExpiryPolicy),
- getKnownBrokers(boost::bind(&Broker::getKnownBrokersImpl, this)),
- deferDelivery(boost::bind(&Broker::deferDeliveryImpl, this, _1, _2))
+ getKnownBrokers(boost::bind(&Broker::getKnownBrokersImpl, this))
{
+ thisBroker = this;
try {
if (conf.enableMgmt) {
QPID_LOG(info, "Management enabled");
@@ -231,7 +247,7 @@ Broker::Broker(const Broker::Options& conf) :
System* system = new System (dataDir.isEnabled() ? dataDir.getPath() : string(), this);
systemObject = System::shared_ptr(system);
- mgmtObject = new _qmf::Broker(managementAgent.get(), this, system, "amqp-broker");
+ mgmtObject = _qmf::Broker::shared_ptr(new _qmf::Broker(managementAgent.get(), this, system, "amqp-broker"));
mgmtObject->set_systemRef(system->GetManagementObject()->getObjectId());
mgmtObject->set_port(conf.port);
mgmtObject->set_workerThreads(conf.workerThreads);
@@ -281,28 +297,26 @@ Broker::Broker(const Broker::Options& conf) :
// if (NullMessageStore::isNullStore(store.get()))
// setStore();
- exchanges.declare(empty, DirectExchange::typeName); // Default exchange.
+ framing::FieldTable args;
+
+ // Default exchnge is not replicated.
+ exchanges.declare(empty, DirectExchange::typeName, false, noReplicateArgs());
// if (store.get() != 0) {
if (asyncStore.get() != 0) {
- // The cluster plug-in will setRecovery(false) on all but the first
- // broker to join a cluster.
- if (getRecovery()) {
QPID_LOG(info, "Store recovery starting")
- RecoveryManagerImpl recoverer(queues, exchanges, links, dtxManager);
+ RecoveryManagerImpl recoverer(queues, exchanges, links, dtxManager, protocolRegistry);
RecoveryHandle rh = asyncStore->createRecoveryHandle();
- boost::shared_ptr<RecoveryAsyncContext> rac(new RecoveryAsyncContext(recoverer, &recoverComplete, &asyncResultQueue));
+ boost::shared_ptr<RecoveryAsyncContext> rac(new RecoveryAsyncContext(recoverer, &recoverCompleteCb, &asyncResultQueue));
asyncStore->submitRecover(rh, rac);
-// store->recover(recoverer);
- }
- else {
- QPID_LOG(notice, "Cluster recovery: recovered journal data discarded and journal files pushed down");
-// store->truncateInit(true); // save old files in subdir
- asyncStore->initialize(true, true);
- }
+// RecoveryManagerImpl recoverer(
+// queues, exchanges, links, dtxManager, protocolRegistry);
+// recoveryInProgress = true;
+// store->recover(recoverer);
+// recoveryInProgress = false;
}
// debug
- else QPID_LOG(info, ">>>> No store!!!!")
+// else QPID_LOG(info, ">>>> No store!!!!")
//ensure standard exchanges exist (done after recovery from store)
declareStandardExchange(amq_direct, DirectExchange::typeName);
@@ -311,7 +325,7 @@ Broker::Broker(const Broker::Options& conf) :
declareStandardExchange(amq_match, HeadersExchange::typeName);
if(conf.enableMgmt) {
- exchanges.declare(qpid_management, ManagementTopicExchange::typeName);
+ exchanges.declare(qpid_management, ManagementTopicExchange::typeName, false, noReplicateArgs());
Exchange::shared_ptr mExchange = exchanges.get(qpid_management);
Exchange::shared_ptr dExchange = exchanges.get(amq_direct);
managementAgent->setExchange(mExchange, dExchange);
@@ -320,8 +334,10 @@ Broker::Broker(const Broker::Options& conf) :
std::string qmfTopic("qmf.default.topic");
std::string qmfDirect("qmf.default.direct");
- std::pair<Exchange::shared_ptr, bool> topicPair(exchanges.declare(qmfTopic, ManagementTopicExchange::typeName));
- std::pair<Exchange::shared_ptr, bool> directPair(exchanges.declare(qmfDirect, ManagementDirectExchange::typeName));
+ std::pair<Exchange::shared_ptr, bool> topicPair(
+ exchanges.declare(qmfTopic, ManagementTopicExchange::typeName, false, noReplicateArgs()));
+ std::pair<Exchange::shared_ptr, bool> directPair(
+ exchanges.declare(qmfDirect, ManagementDirectExchange::typeName, false, noReplicateArgs()));
boost::dynamic_pointer_cast<ManagementDirectExchange>(directPair.first)->setManagmentAgent(managementAgent.get(), 2);
boost::dynamic_pointer_cast<ManagementTopicExchange>(topicPair.first)->setManagmentAgent(managementAgent.get(), 2);
@@ -349,19 +365,17 @@ Broker::Broker(const Broker::Options& conf) :
// Initialize plugins
Plugin::initializeAll(*this);
- if (managementAgent.get()) managementAgent->pluginsInitialized();
+ if(conf.enableMgmt) {
+ if (getAcl()) {
+ mgmtObject->set_maxConns(getAcl()->getMaxConnectTotal());
+ }
+ }
if (conf.queueCleanInterval) {
queueCleaner.start(conf.queueCleanInterval * qpid::sys::TIME_SEC);
}
- //initialize known broker urls (TODO: add support for urls for other transports (SSL, RDMA)):
- if (conf.knownHosts.empty()) {
- boost::shared_ptr<ProtocolFactory> factory = getProtocolFactory(TCP_TRANSPORT);
- if (factory) {
- knownBrokers.push_back ( qpid::Url::getIpAddressesUrl ( factory->getPort() ) );
- }
- } else if (conf.knownHosts != knownHostsNone) {
+ if (!conf.knownHosts.empty() && conf.knownHosts != knownHostsNone) {
knownBrokers.push_back(Url(conf.knownHosts));
}
@@ -375,11 +389,14 @@ void Broker::declareStandardExchange(const std::string& name, const std::string&
{
// bool storeEnabled = store.get() != NULL;
bool storeEnabled = asyncStore.get() != NULL;
- std::pair<Exchange::shared_ptr, bool> status = exchanges.declare(name, type, storeEnabled);
+ framing::FieldTable args;
+ // Standard exchanges are not replicated.
+ std::pair<Exchange::shared_ptr, bool> status =
+ exchanges.declare(name, type, storeEnabled, noReplicateArgs());
if (status.second && storeEnabled) {
// store->create(*status.first, framing::FieldTable ());
ConfigHandle ch = asyncStore->createConfigHandle();
- boost::shared_ptr<BrokerAsyncContext> bc(new ConfigAsyncContext(&configureComplete, &asyncResultQueue));
+ boost::shared_ptr<BrokerAsyncContext> bc(new ConfigAsyncContext(&configureCompleteCb, &asyncResultQueue));
asyncStore->submitCreate(ch, status.first.get(), bc);
}
}
@@ -420,11 +437,20 @@ void Broker::setStore () {
}
// static
+void Broker::recoverCompleteCb(const AsyncResultHandle* const arh) {
+ thisBroker->recoverComplete(arh);
+}
+
void Broker::recoverComplete(const AsyncResultHandle* const arh) {
+ recoveryInProgress = false;
std::cout << "@@@@ Broker: Recover complete: err=" << arh->getErrNo() << "; msg=\"" << arh->getErrMsg() << "\"" << std::endl;
}
// static
+void Broker::configureCompleteCb(const AsyncResultHandle* const arh) {
+ thisBroker->configureComplete(arh);
+}
+
void Broker::configureComplete(const AsyncResultHandle* const arh) {
std::cout << "@@@@ Broker: Configure complete: err=" << arh->getErrNo() << "; msg=\"" << arh->getErrMsg() << "\"" << std::endl;
}
@@ -464,13 +490,13 @@ Broker::~Broker() {
finalize(); // Finalize any plugins.
if (config.auth)
SaslAuthenticator::fini();
- timer.stop();
+ timer->stop();
QPID_LOG(notice, "Shut down");
}
-ManagementObject* Broker::GetManagementObject(void) const
+ManagementObject::shared_ptr Broker::GetManagementObject(void) const
{
- return (ManagementObject*) mgmtObject;
+ return mgmtObject;
}
Manageable* Broker::GetVhostObject(void) const
@@ -536,7 +562,7 @@ Manageable::status_t Broker::ManagementMethod (uint32_t methodId,
_qmf::ArgsBrokerQueueMoveMessages& moveArgs=
dynamic_cast<_qmf::ArgsBrokerQueueMoveMessages&>(args);
QPID_LOG (debug, "Broker::queueMoveMessages()");
- if (queueMoveMessages(moveArgs.i_srcQueue, moveArgs.i_destQueue, moveArgs.i_qty, moveArgs.i_filter))
+ if (queueMoveMessages(moveArgs.i_srcQueue, moveArgs.i_destQueue, moveArgs.i_qty, moveArgs.i_filter) >= 0)
status = Manageable::STATUS_OK;
else
return Manageable::STATUS_PARAMETER_INVALID;
@@ -584,7 +610,22 @@ Manageable::status_t Broker::ManagementMethod (uint32_t methodId,
status = setTimestampConfig(a.i_receive, getManagementExecutionContext());
break;
}
- default:
+
+ case _qmf::Broker::METHOD_GETLOGHIRESTIMESTAMP:
+ {
+ dynamic_cast<_qmf::ArgsBrokerGetLogHiresTimestamp&>(args).o_logHires = getLogHiresTimestamp();
+ QPID_LOG (debug, "Broker::getLogHiresTimestamp()");
+ status = Manageable::STATUS_OK;
+ break;
+ }
+ case _qmf::Broker::METHOD_SETLOGHIRESTIMESTAMP:
+ {
+ setLogHiresTimestamp(dynamic_cast<_qmf::ArgsBrokerSetLogHiresTimestamp&>(args).i_logHires);
+ QPID_LOG (debug, "Broker::setLogHiresTimestamp()");
+ status = Manageable::STATUS_OK;
+ break;
+ }
+ default:
QPID_LOG (debug, "Broker ManagementMethod not implemented: id=" << methodId << "]");
status = Manageable::STATUS_NOT_IMPLEMENTED;
break;
@@ -750,7 +791,7 @@ void Broker::createObject(const std::string& type, const std::string& name,
else extensions[i->first] = i->second;
}
framing::FieldTable arguments;
- amqp_0_10::translate(extensions, arguments);
+ qpid::amqp_0_10::translate(extensions, arguments);
try {
std::pair<boost::shared_ptr<Exchange>, bool> result =
@@ -772,7 +813,7 @@ void Broker::createObject(const std::string& type, const std::string& name,
else extensions[i->first] = i->second;
}
framing::FieldTable arguments;
- amqp_0_10::translate(extensions, arguments);
+ qpid::amqp_0_10::translate(extensions, arguments);
bind(binding.queue, binding.exchange, binding.key, arguments, userId, connectionId);
@@ -1008,6 +1049,18 @@ std::string Broker::getLogLevel()
return level;
}
+void Broker::setLogHiresTimestamp(bool enabled)
+{
+ QPID_LOG(notice, "Changing log hires timestamp to " << enabled);
+ qpid::log::Logger::instance().setHiresTimestamp(enabled);
+}
+
+bool Broker::getLogHiresTimestamp()
+{
+ return qpid::log::Logger::instance().getHiresTimestamp();
+}
+
+
boost::shared_ptr<ProtocolFactory> Broker::getProtocolFactory(const std::string& name) const {
ProtocolFactoryMap::const_iterator i
= name.empty() ? protocolFactories.begin() : protocolFactories.find(name);
@@ -1036,39 +1089,29 @@ void Broker::accept() {
}
void Broker::connect(
+ const std::string& name,
const std::string& host, const std::string& port, const std::string& transport,
- boost::function2<void, int, std::string> failed,
- sys::ConnectionCodec::Factory* f)
+ boost::function2<void, int, std::string> failed)
{
boost::shared_ptr<ProtocolFactory> pf = getProtocolFactory(transport);
- if (pf) pf->connect(poller, host, port, f ? f : factory.get(), failed);
+ if (pf) pf->connect(poller, name, host, port, factory.get(), failed);
else throw NoSuchTransportException(QPID_MSG("Unsupported transport type: " << transport));
}
-void Broker::connect(
- const Url& url,
- boost::function2<void, int, std::string> failed,
- sys::ConnectionCodec::Factory* f)
-{
- url.throwIfEmpty();
- const Address& addr=url[0];
- connect(addr.host, boost::lexical_cast<std::string>(addr.port), addr.protocol, failed, f);
-}
-
-uint32_t Broker::queueMoveMessages(
+int32_t Broker::queueMoveMessages(
const std::string& srcQueue,
const std::string& destQueue,
uint32_t qty,
const Variant::Map& filter)
{
- Queue::shared_ptr src_queue = queues.find(srcQueue);
- if (!src_queue)
- return 0;
- Queue::shared_ptr dest_queue = queues.find(destQueue);
- if (!dest_queue)
- return 0;
-
- return src_queue->move(dest_queue, qty, &filter);
+ Queue::shared_ptr src_queue = queues.find(srcQueue);
+ if (!src_queue)
+ return -1;
+ Queue::shared_ptr dest_queue = queues.find(destQueue);
+ if (!dest_queue)
+ return -1;
+
+ return (int32_t) src_queue->move(dest_queue, qty, &filter);
}
@@ -1083,12 +1126,6 @@ Broker::getKnownBrokersImpl()
bool Broker::deferDeliveryImpl(const std::string&, const Message&)
{ return false; }
-void Broker::setClusterTimer(std::auto_ptr<sys::Timer> t) {
- clusterTimer = t;
- queueCleaner.setTimer(clusterTimer.get());
- dtxManager.setTimer(*clusterTimer.get());
-}
-
const std::string Broker::TCP_TRANSPORT("tcp");
@@ -1109,9 +1146,14 @@ std::pair<boost::shared_ptr<Queue>, bool> Broker::createQueue(
params.insert(make_pair(acl::PROP_POLICYTYPE, settings.dropMessagesAtLimit ? "ring" : "reject"));
params.insert(make_pair(acl::PROP_MAXQUEUECOUNT, boost::lexical_cast<string>(settings.maxDepth.getCount())));
params.insert(make_pair(acl::PROP_MAXQUEUESIZE, boost::lexical_cast<string>(settings.maxDepth.getSize())));
+ params.insert(make_pair(acl::PROP_MAXFILECOUNT, boost::lexical_cast<string>(settings.maxFileCount)));
+ params.insert(make_pair(acl::PROP_MAXFILESIZE, boost::lexical_cast<string>(settings.maxFileSize)));
if (!acl->authorise(userId,acl::ACT_CREATE,acl::OBJ_QUEUE,name,&params) )
throw framing::UnauthorizedAccessException(QPID_MSG("ACL denied queue create request from " << userId));
+
+ if (!acl->approveCreateQueue(userId,name) )
+ throw framing::UnauthorizedAccessException(QPID_MSG("ACL denied queue create request from " << userId));
}
Exchange::shared_ptr alternate;
@@ -1120,21 +1162,12 @@ std::pair<boost::shared_ptr<Queue>, bool> Broker::createQueue(
if (!alternate) throw framing::NotFoundException(QPID_MSG("Alternate exchange does not exist: " << alternateExchange));
}
- std::pair<Queue::shared_ptr, bool> result = queues.declare(name, settings, alternate);
+ std::pair<Queue::shared_ptr, bool> result =
+ queues.declare(name, settings, alternate, false/*recovering*/,
+ owner, connectionId, userId);
if (result.second) {
//add default binding:
result.first->bind(exchanges.getDefault(), name, qpid::framing::FieldTable());
-
- if (managementAgent.get()) {
- //TODO: debatable whether we should raise an event here for
- //create when this is a 'declare' event; ideally add a create
- //event instead?
- managementAgent->raiseEvent(
- _qmf::EventQueueDeclare(connectionId, userId, name,
- settings.durable, owner, settings.autodelete, alternateExchange,
- settings.asMap(),
- "created"));
- }
QPID_LOG_CAT(debug, model, "Create queue. name:" << name
<< " user:" << userId
<< " rhost:" << connectionId
@@ -1149,6 +1182,10 @@ std::pair<boost::shared_ptr<Queue>, bool> Broker::createQueue(
void Broker::deleteQueue(const std::string& name, const std::string& userId,
const std::string& connectionId, QueueFunctor check)
{
+ QPID_LOG_CAT(debug, model, "Deleting queue. name:" << name
+ << " user:" << userId
+ << " rhost:" << connectionId
+ );
if (acl && !acl->authorise(userId,acl::ACT_DELETE,acl::OBJ_QUEUE,name,NULL)) {
throw framing::UnauthorizedAccessException(QPID_MSG("ACL denied queue delete request from " << userId));
}
@@ -1156,19 +1193,13 @@ void Broker::deleteQueue(const std::string& name, const std::string& userId,
Queue::shared_ptr queue = queues.find(name);
if (queue) {
if (check) check(queue);
- queues.destroy(name);
+ if (acl)
+ acl->recordDestroyQueue(name);
+ queues.destroy(name, connectionId, userId);
queue->destroyed();
} else {
throw framing::NotFoundException(QPID_MSG("Delete failed. No such queue: " << name));
}
-
- if (managementAgent.get())
- managementAgent->raiseEvent(_qmf::EventQueueDelete(connectionId, userId, name));
- QPID_LOG_CAT(debug, model, "Delete queue. name:" << name
- << " user:" << userId
- << " rhost:" << connectionId
- );
-
}
std::pair<Exchange::shared_ptr, bool> Broker::createExchange(
@@ -1196,33 +1227,16 @@ std::pair<Exchange::shared_ptr, bool> Broker::createExchange(
}
std::pair<Exchange::shared_ptr, bool> result;
- result = exchanges.declare(name, type, durable, arguments);
+ result = exchanges.declare(
+ name, type, durable, arguments, alternate, connectionId, userId);
if (result.second) {
- if (alternate) {
- result.first->setAlternate(alternate);
- alternate->incAlternateUsers();
- }
if (durable) {
// store->create(*result.first, arguments);
ConfigHandle ch = asyncStore->createConfigHandle();
result.first->setHandle(ch);
- boost::shared_ptr<BrokerAsyncContext> bc(new ConfigAsyncContext(&configureComplete, &asyncResultQueue));
+ boost::shared_ptr<BrokerAsyncContext> bc(new ConfigAsyncContext(&configureCompleteCb, &asyncResultQueue));
asyncStore->submitCreate(ch, result.first.get(), bc);
}
- if (managementAgent.get()) {
- //TODO: debatable whether we should raise an event here for
- //create when this is a 'declare' event; ideally add a create
- //event instead?
- managementAgent->raiseEvent(_qmf::EventExchangeDeclare(connectionId,
- userId,
- name,
- type,
- alternateExchange,
- durable,
- false,
- ManagementAgent::toMap(arguments),
- "created"));
- }
QPID_LOG_CAT(debug, model, "Create exchange. name:" << name
<< " user:" << userId
<< " rhost:" << connectionId
@@ -1236,6 +1250,9 @@ std::pair<Exchange::shared_ptr, bool> Broker::createExchange(
void Broker::deleteExchange(const std::string& name, const std::string& userId,
const std::string& connectionId)
{
+ QPID_LOG_CAT(debug, model, "Deleting exchange. name:" << name
+ << " user:" << userId
+ << " rhost:" << connectionId);
if (acl) {
if (!acl->authorise(userId,acl::ACT_DELETE,acl::OBJ_EXCHANGE,name,NULL) )
throw framing::UnauthorizedAccessException(QPID_MSG("ACL denied exchange delete request from " << userId));
@@ -1246,21 +1263,15 @@ void Broker::deleteExchange(const std::string& name, const std::string& userId,
}
Exchange::shared_ptr exchange(exchanges.get(name));
if (!exchange) throw framing::NotFoundException(QPID_MSG("Delete failed. No such exchange: " << name));
- if (exchange->inUseAsAlternate()) throw framing::NotAllowedException(QPID_MSG("Exchange in use as alternate-exchange."));
+ if (exchange->inUseAsAlternate()) throw framing::NotAllowedException(QPID_MSG("Cannot delete " << name <<", in use as alternate-exchange."));
// if (exchange->isDurable()) store->destroy(*exchange);
if (exchange->isDurable()) {
- boost::shared_ptr<BrokerAsyncContext> bc(new ConfigAsyncContext(&configureComplete, &asyncResultQueue));
+ boost::shared_ptr<BrokerAsyncContext> bc(new ConfigAsyncContext(&configureCompleteCb, &asyncResultQueue));
asyncStore->submitDestroy(exchange->getHandle(), bc);
exchange->resetHandle();
}
if (exchange->getAlternate()) exchange->getAlternate()->decAlternateUsers();
- exchanges.destroy(name);
-
- if (managementAgent.get())
- managementAgent->raiseEvent(_qmf::EventExchangeDelete(connectionId, userId, name));
- QPID_LOG_CAT(debug, model, "Delete exchange. name:" << name
- << " user:" << userId
- << " rhost:" << connectionId);
+ exchanges.destroy(name, connectionId, userId);
}
void Broker::bind(const std::string& queueName,
@@ -1298,6 +1309,7 @@ void Broker::bind(const std::string& queueName,
QPID_LOG_CAT(debug, model, "Create binding. exchange:" << exchangeName
<< " queue:" << queueName
<< " key:" << key
+ << " arguments:" << arguments
<< " user:" << userId
<< " rhost:" << connectionId);
}
diff --git a/cpp/src/qpid/broker/Broker.h b/cpp/src/qpid/broker/Broker.h
index 698d446bca..468da8983a 100644
--- a/cpp/src/qpid/broker/Broker.h
+++ b/cpp/src/qpid/broker/Broker.h
@@ -25,40 +25,30 @@
#include "qpid/broker/AsyncResultQueueImpl.h"
#include "qpid/broker/AsyncStore.h"
#include "qpid/broker/BrokerImportExport.h"
-#include "qpid/broker/ConnectionFactory.h"
-#include "qpid/broker/ConnectionToken.h"
-#include "qpid/broker/DirectExchange.h"
+
+#include "qpid/DataDir.h"
+#include "qpid/Options.h"
+#include "qpid/Plugin.h"
#include "qpid/broker/DtxManager.h"
#include "qpid/broker/ExchangeRegistry.h"
//#include "qpid/broker/MessageStore.h"
+#include "qpid/broker/Protocol.h"
#include "qpid/broker/QueueRegistry.h"
#include "qpid/broker/LinkRegistry.h"
#include "qpid/broker/SessionManager.h"
#include "qpid/broker/QueueCleaner.h"
#include "qpid/broker/Vhost.h"
#include "qpid/broker/System.h"
-#include "qpid/broker/ExpiryPolicy.h"
#include "qpid/broker/ConsumerFactory.h"
#include "qpid/broker/ConnectionObservers.h"
#include "qpid/broker/ConfigurationObservers.h"
#include "qpid/management/Manageable.h"
-#include "qpid/management/ManagementAgent.h"
-#include "qmf/org/apache/qpid/broker/Broker.h"
-#include "qmf/org/apache/qpid/broker/ArgsBrokerConnect.h"
-#include "qpid/Options.h"
-#include "qpid/Plugin.h"
-#include "qpid/DataDir.h"
-#include "qpid/framing/FrameHandler.h"
-#include "qpid/framing/OutputHandler.h"
-#include "qpid/framing/ProtocolInitiation.h"
-#include "qpid/sys/Runnable.h"
-#include "qpid/sys/Timer.h"
-#include "qpid/types/Variant.h"
-#include "qpid/RefCounted.h"
-#include "qpid/broker/AclModule.h"
+#include "qpid/sys/ConnectionCodec.h"
#include "qpid/sys/Mutex.h"
+#include "qpid/sys/Runnable.h"
#include <boost/intrusive_ptr.hpp>
+
#include <string>
#include <vector>
@@ -67,12 +57,14 @@ namespace qpid {
namespace sys {
class ProtocolFactory;
class Poller;
+class Timer;
}
struct Url;
namespace broker {
+class AclModule;
class ConnectionState;
class ExpiryPolicy;
class Message;
@@ -103,6 +95,7 @@ class Broker : public sys::Runnable, public Plugin::Target,
bool noDataDir;
std::string dataDir;
uint16_t port;
+ std::vector<std::string> listenInterfaces;
int workerThreads;
int connectionBacklog;
bool enableMgmt;
@@ -139,10 +132,15 @@ class Broker : public sys::Runnable, public Plugin::Target,
void declareStandardExchange(const std::string& name, const std::string& type);
void setStore ();
- static void recoverComplete(const AsyncResultHandle* const);
- static void configureComplete(const AsyncResultHandle* const);
+ static void recoverCompleteCb(const AsyncResultHandle* const);
+ static void configureCompleteCb(const AsyncResultHandle* const);
+ static Broker* thisBroker;
+ void recoverComplete(const AsyncResultHandle* const arh);
+ void configureComplete(const AsyncResultHandle* const arh);
void setLogLevel(const std::string& level);
std::string getLogLevel();
+ void setLogHiresTimestamp(bool enabled);
+ bool getLogHiresTimestamp();
void createObject(const std::string& type, const std::string& name,
const qpid::types::Variant::Map& properties, bool strict, const ConnectionState* context);
void deleteObject(const std::string& type, const std::string& name,
@@ -158,8 +156,7 @@ class Broker : public sys::Runnable, public Plugin::Target,
Manageable::status_t setTimestampConfig(const bool receive,
const ConnectionState* context);
boost::shared_ptr<sys::Poller> poller;
- sys::Timer timer;
- std::auto_ptr<sys::Timer> clusterTimer;
+ std::auto_ptr<sys::Timer> timer;
Options config;
std::auto_ptr<management::ManagementAgent> managementAgent;
ProtocolFactoryMap protocolFactories;
@@ -178,7 +175,7 @@ class Broker : public sys::Runnable, public Plugin::Target,
boost::shared_ptr<sys::ConnectionCodec::Factory> factory;
DtxManager dtxManager;
SessionManager sessionManager;
- qmf::org::apache::qpid::broker::Broker* mgmtObject;
+ qmf::org::apache::qpid::broker::Broker::shared_ptr mgmtObject;
Vhost::shared_ptr vhostObject;
System::shared_ptr systemObject;
QueueCleaner queueCleaner;
@@ -187,10 +184,10 @@ class Broker : public sys::Runnable, public Plugin::Target,
bool deferDeliveryImpl(const std::string& queue,
const Message& msg);
std::string federationTag;
- bool recovery;
- bool inCluster, clusterUpdatee;
+ bool recoveryInProgress;
boost::intrusive_ptr<ExpiryPolicy> expiryPolicy;
ConsumerFactories consumerFactories;
+ ProtocolRegistry protocolRegistry;
mutable sys::Mutex linkClientPropertiesLock;
framing::FieldTable linkClientProperties;
@@ -233,6 +230,7 @@ class Broker : public sys::Runnable, public Plugin::Target,
DataDir& getDataDir() { return dataDir; }
Options& getOptions() { return config; }
AsyncResultQueueImpl& getAsyncResultQueue() { return asyncResultQueue; }
+ ProtocolRegistry& getProtocolRegistry() { return protocolRegistry; }
void setExpiryPolicy(const boost::intrusive_ptr<ExpiryPolicy>& e) { expiryPolicy = e; }
boost::intrusive_ptr<ExpiryPolicy> getExpiryPolicy() { return expiryPolicy; }
@@ -240,7 +238,7 @@ class Broker : public sys::Runnable, public Plugin::Target,
SessionManager& getSessionManager() { return sessionManager; }
const std::string& getFederationTag() const { return federationTag; }
- QPID_BROKER_EXTERN management::ManagementObject* GetManagementObject() const;
+ QPID_BROKER_EXTERN management::ManagementObject::shared_ptr GetManagementObject() const;
QPID_BROKER_EXTERN management::Manageable* GetVhostObject() const;
QPID_BROKER_EXTERN management::Manageable::status_t ManagementMethod(
uint32_t methodId, management::Args& args, std::string& text);
@@ -253,19 +251,17 @@ class Broker : public sys::Runnable, public Plugin::Target,
QPID_BROKER_EXTERN void accept();
/** Create a connection to another broker. */
- void connect(const std::string& host, const std::string& port,
+ void connect(const std::string& name,
+ const std::string& host, const std::string& port,
const std::string& transport,
- boost::function2<void, int, std::string> failed,
- sys::ConnectionCodec::Factory* =0);
- /** Create a connection to another broker. */
- void connect(const Url& url,
- boost::function2<void, int, std::string> failed,
- sys::ConnectionCodec::Factory* =0);
+ boost::function2<void, int, std::string> failed);
/** Move messages from one queue to another.
A zero quantity means to move all messages
+ Return -1 if one of the queues does not exist, otherwise
+ the number of messages moved.
*/
- QPID_BROKER_EXTERN uint32_t queueMoveMessages(
+ QPID_BROKER_EXTERN int32_t queueMoveMessages(
const std::string& srcQueue,
const std::string& destQueue,
uint32_t qty,
@@ -277,46 +273,17 @@ class Broker : public sys::Runnable, public Plugin::Target,
/** Expose poller so plugins can register their descriptors. */
QPID_BROKER_EXTERN boost::shared_ptr<sys::Poller> getPoller();
- boost::shared_ptr<sys::ConnectionCodec::Factory> getConnectionFactory() { return factory; }
- void setConnectionFactory(boost::shared_ptr<sys::ConnectionCodec::Factory> f) { factory = f; }
-
/** Timer for local tasks affecting only this broker */
- sys::Timer& getTimer() { return timer; }
-
- /** Timer for tasks that must be synchronized if we are in a cluster */
- sys::Timer& getClusterTimer() { return clusterTimer.get() ? *clusterTimer : timer; }
- QPID_BROKER_EXTERN void setClusterTimer(std::auto_ptr<sys::Timer>);
+ sys::Timer& getTimer() { return *timer; }
boost::function<std::vector<Url> ()> getKnownBrokers;
static QPID_BROKER_EXTERN const std::string TCP_TRANSPORT;
- void setRecovery(bool set) { recovery = set; }
- bool getRecovery() const { return recovery; }
-
- /** True of this broker is part of a cluster.
- * Only valid after early initialization of plugins is complete.
- */
- bool isInCluster() const { return inCluster; }
- void setInCluster(bool set) { inCluster = set; }
-
- /** True if this broker is joining a cluster and in the process of
- * receiving a state update.
- */
- bool isClusterUpdatee() const { return clusterUpdatee; }
- void setClusterUpdatee(bool set) { clusterUpdatee = set; }
+ bool inRecovery() const { return recoveryInProgress; }
management::ManagementAgent* getManagementAgent() { return managementAgent.get(); }
- /**
- * Never true in a stand-alone broker. In a cluster, return true
- * to defer delivery of messages deliveredg in a cluster-unsafe
- * context.
- *@return true if delivery of a message should be deferred.
- */
- boost::function<bool (const std::string& queue,
- const Message& msg)> deferDelivery;
-
bool isAuthenticating ( ) { return config.auth; }
bool isTimestamping() { return config.timestampRcvMsgs; }
@@ -371,8 +338,10 @@ class Broker : public sys::Runnable, public Plugin::Target,
QPID_BROKER_EXTERN framing::FieldTable getLinkClientProperties() const;
QPID_BROKER_EXTERN void setLinkClientProperties(const framing::FieldTable&);
+ QPID_BROKER_EXTERN uint16_t getLinkHearbeatInterval() { return config.linkHeartbeatInterval; }
/** Information identifying this system */
boost::shared_ptr<const System> getSystem() const { return systemObject; }
+ friend class StatusCheckThread;
};
}}
diff --git a/cpp/src/qpid/broker/ConfigurationObserver.h b/cpp/src/qpid/broker/ConfigurationObserver.h
index 701043db40..789490e08c 100644
--- a/cpp/src/qpid/broker/ConfigurationObserver.h
+++ b/cpp/src/qpid/broker/ConfigurationObserver.h
@@ -38,6 +38,10 @@ class Exchange;
/**
* Observer for changes to configuration (aka wiring)
+ *
+ * NOTE: create and destroy functions are called with
+ * the registry lock held. This is necessary to ensure
+ * they are called in the correct sequence.
*/
class ConfigurationObserver
{
diff --git a/cpp/src/qpid/broker/Connection.cpp b/cpp/src/qpid/broker/Connection.cpp
index e68c906cc2..df1a23f882 100644
--- a/cpp/src/qpid/broker/Connection.cpp
+++ b/cpp/src/qpid/broker/Connection.cpp
@@ -25,9 +25,9 @@
#include "qpid/broker/Bridge.h"
#include "qpid/broker/Broker.h"
#include "qpid/broker/Queue.h"
-#include "qpid/broker/AclModule.h"
+#include "qpid/management/ManagementAgent.h"
#include "qpid/sys/SecuritySettings.h"
-#include "qpid/sys/ClusterSafe.h"
+#include "qpid/sys/Timer.h"
#include "qpid/log/Statement.h"
#include "qpid/ptr_map.h"
@@ -86,20 +86,14 @@ Connection::Connection(ConnectionOutputHandler* out_,
std::string& mgmtId_,
const qpid::sys::SecuritySettings& external,
bool link_,
- uint64_t objectId_,
- bool shadow_,
- bool delayManagement,
- bool authenticated_
+ uint64_t objectId_
) :
ConnectionState(out_, broker_),
securitySettings(external),
- shadow(shadow_),
- authenticated(authenticated_),
adapter(*this, link_),
link(link_),
mgmtClosing(false),
mgmtId(mgmtId_),
- mgmtObject(0),
links(broker_.getLinks()),
agent(0),
timer(broker_.getTimer()),
@@ -109,11 +103,6 @@ Connection::Connection(ConnectionOutputHandler* out_,
{
outboundTracker.wrap(out);
broker.getConnectionObservers().connection(*this);
- // In a cluster, allow adding the management object to be delayed.
- if (!delayManagement) addManagementObject();
-}
-
-void Connection::addManagementObject() {
assert(agent == 0);
assert(mgmtObject == 0);
Manageable* parent = broker.GetVhostObject();
@@ -121,8 +110,7 @@ void Connection::addManagementObject() {
agent = broker.getManagementAgent();
if (agent != 0) {
// TODO set last bool true if system connection
- mgmtObject = new _qmf::Connection(agent, this, parent, mgmtId, !link, false);
- mgmtObject->set_shadow(shadow);
+ mgmtObject = _qmf::Connection::shared_ptr(new _qmf::Connection(agent, this, parent, mgmtId, !link, false, "AMQP 0-10"));
agent->addObject(mgmtObject, objectId);
}
ConnectionState::setUrl(mgmtId);
@@ -139,13 +127,11 @@ void Connection::requestIOProcessing(boost::function0<void> callback)
Connection::~Connection()
{
if (mgmtObject != 0) {
- mgmtObject->resourceDestroy();
- // In a cluster, Connections destroyed during shutdown are in
- // a cluster-unsafe context. Don't raise an event in that case.
- if (!link && isClusterSafe())
- agent->raiseEvent(_qmf::EventClientDisconnect(mgmtId, ConnectionState::getUserId()));
+ if (!link)
+ agent->raiseEvent(_qmf::EventClientDisconnect(mgmtId, ConnectionState::getUserId(), mgmtObject->get_remoteProperties()));
QPID_LOG_CAT(debug, model, "Delete connection. user:" << ConnectionState::getUserId()
<< " rhost:" << mgmtId );
+ mgmtObject->resourceDestroy();
}
broker.getConnectionObservers().closed(*this);
@@ -188,8 +174,7 @@ bool isMessage(const AMQMethodBody* method)
void Connection::recordFromServer(const framing::AMQFrame& frame)
{
- // Don't record management stats in cluster-unsafe contexts
- if (mgmtObject != 0 && isClusterSafe())
+ if (mgmtObject != 0)
{
qmf::org::apache::qpid::broker::Connection::PerThreadStats *cStats = mgmtObject->getStatistics();
cStats->framesToClient += 1;
@@ -203,8 +188,7 @@ void Connection::recordFromServer(const framing::AMQFrame& frame)
void Connection::recordFromClient(const framing::AMQFrame& frame)
{
- // Don't record management stats in cluster-unsafe contexts
- if (mgmtObject != 0 && isClusterSafe())
+ if (mgmtObject != 0)
{
qmf::org::apache::qpid::broker::Connection::PerThreadStats *cStats = mgmtObject->getStatistics();
cStats->framesFromClient += 1;
@@ -279,28 +263,7 @@ void Connection::notifyConnectionForced(const string& text)
void Connection::setUserId(const string& userId)
{
- // Account for changing userId
- AclModule* acl = broker.getAcl();
- if (acl)
- {
- acl->setUserId(*this, userId);
- }
-
ConnectionState::setUserId(userId);
- // In a cluster, the cluster code will raise the connect event
- // when the connection is replicated to the cluster.
- if (!broker.isInCluster()) raiseConnectEvent();
-}
-
-void Connection::raiseConnectEvent() {
- if (mgmtObject != 0) {
- mgmtObject->set_authIdentity(userId);
- agent->raiseEvent(_qmf::EventClientConnect(mgmtId, userId));
- }
-
- QPID_LOG_CAT(debug, model, "Create connection. user:" << userId
- << " rhost:" << mgmtId );
-
}
void Connection::setUserProxyAuth(bool b)
@@ -327,19 +290,6 @@ void Connection::close(connection::CloseCode code, const string& text)
getOutput().close();
}
-// Send a close to the client but keep the channels. Used by cluster.
-void Connection::sendClose() {
- if (heartbeatTimer)
- heartbeatTimer->cancel();
- if (timeoutTimer)
- timeoutTimer->cancel();
- if (linkHeartbeatTimer) {
- linkHeartbeatTimer->cancel();
- }
- adapter.close(connection::CLOSE_CODE_NORMAL, "OK");
- getOutput().close();
-}
-
void Connection::idleOut(){}
void Connection::idleIn(){}
@@ -364,9 +314,6 @@ void Connection::closed(){ // Physically closed, suspend open sessions.
void Connection::doIoCallbacks() {
if (!isOpen()) return; // Don't process IO callbacks until we are open.
ScopedLock<Mutex> l(ioCallbackLock);
- // Although IO callbacks execute in the connection thread context, they are
- // not cluster safe because they are queued for execution in non-IO threads.
- ClusterUnsafeScope cus;
while (!ioCallbacks.empty()) {
boost::function0<void> cb = ioCallbacks.front();
ioCallbacks.pop();
@@ -413,9 +360,9 @@ SessionHandler& Connection::getChannel(ChannelId id) {
return *ptr_map_ptr(i);
}
-ManagementObject* Connection::GetManagementObject(void) const
+ManagementObject::shared_ptr Connection::GetManagementObject(void) const
{
- return (ManagementObject*) mgmtObject;
+ return mgmtObject;
}
Manageable::status_t Connection::ManagementMethod(uint32_t methodId, Args&, string&)
@@ -499,7 +446,7 @@ void Connection::abort()
void Connection::setHeartbeatInterval(uint16_t heartbeat)
{
setHeartbeat(heartbeat);
- if (heartbeat > 0 && !isShadow()) {
+ if (heartbeat > 0) {
if (!heartbeatTimer) {
heartbeatTimer = new ConnectionHeartbeatTask(heartbeat, timer, *this);
timer.add(heartbeatTimer);
@@ -535,7 +482,6 @@ void Connection::OutboundFrameTracker::close() { next->close(); }
size_t Connection::OutboundFrameTracker::getBuffered() const { return next->getBuffered(); }
void Connection::OutboundFrameTracker::abort() { next->abort(); }
void Connection::OutboundFrameTracker::activateOutput() { next->activateOutput(); }
-void Connection::OutboundFrameTracker::giveReadCredit(int32_t credit) { next->giveReadCredit(credit); }
void Connection::OutboundFrameTracker::send(framing::AMQFrame& f)
{
next->send(f);
diff --git a/cpp/src/qpid/broker/Connection.h b/cpp/src/qpid/broker/Connection.h
index d01599ce54..5c4d7132be 100644
--- a/cpp/src/qpid/broker/Connection.h
+++ b/cpp/src/qpid/broker/Connection.h
@@ -30,24 +30,13 @@
#include "qpid/broker/BrokerImportExport.h"
#include "qpid/broker/ConnectionHandler.h"
#include "qpid/broker/ConnectionState.h"
-#include "qpid/broker/SessionHandler.h"
-#include "qmf/org/apache/qpid/broker/Connection.h"
-#include "qpid/Exception.h"
-#include "qpid/RefCounted.h"
-#include "qpid/framing/AMQFrame.h"
-#include "qpid/framing/AMQP_ClientProxy.h"
-#include "qpid/framing/AMQP_ServerOperations.h"
-#include "qpid/framing/ProtocolVersion.h"
-#include "qpid/management/ManagementAgent.h"
-#include "qpid/management/Manageable.h"
-#include "qpid/ptr_map.h"
-#include "qpid/sys/AggregateOutput.h"
#include "qpid/sys/ConnectionInputHandler.h"
-#include "qpid/sys/ConnectionOutputHandler.h"
#include "qpid/sys/SecuritySettings.h"
-#include "qpid/sys/Socket.h"
-#include "qpid/sys/TimeoutHandler.h"
#include "qpid/sys/Mutex.h"
+#include "qpid/RefCounted.h"
+#include "qpid/ptr_map.h"
+
+#include "qmf/org/apache/qpid/broker/Connection.h"
#include <boost/ptr_container/ptr_map.hpp>
#include <boost/bind.hpp>
@@ -55,11 +44,17 @@
#include <algorithm>
namespace qpid {
+namespace sys {
+class Timer;
+class TimerTask;
+}
namespace broker {
class Broker;
class LinkRegistry;
+class Queue;
class SecureConnection;
+class SessionHandler;
struct ConnectionTimeoutTask;
class Connection : public sys::ConnectionInputHandler,
@@ -83,10 +78,7 @@ class Connection : public sys::ConnectionInputHandler,
const std::string& mgmtId,
const qpid::sys::SecuritySettings&,
bool isLink = false,
- uint64_t objectId = 0,
- bool shadow=false,
- bool delayManagement = false,
- bool authenticated=true);
+ uint64_t objectId = 0);
~Connection ();
@@ -112,7 +104,7 @@ class Connection : public sys::ConnectionInputHandler,
void closeChannel(framing::ChannelId channel);
// Manageable entry points
- management::ManagementObject* GetManagementObject (void) const;
+ management::ManagementObject::shared_ptr GetManagementObject(void) const;
management::Manageable::status_t
ManagementMethod (uint32_t methodId, management::Args& args, std::string&);
@@ -130,7 +122,6 @@ class Connection : public sys::ConnectionInputHandler,
void notifyConnectionForced(const std::string& text);
void setUserId(const std::string& uid);
- void raiseConnectEvent();
// credentials for connected client
const std::string& getUserId() const { return ConnectionState::getUserId(); }
@@ -144,27 +135,14 @@ class Connection : public sys::ConnectionInputHandler,
void setHeartbeatInterval(uint16_t heartbeat);
void sendHeartbeat();
void restartTimeout();
-
+
template <class F> void eachSessionHandler(F f) {
for (ChannelMap::iterator i = channels.begin(); i != channels.end(); ++i)
f(*ptr_map_ptr(i));
}
- void sendClose();
void setSecureConnection(SecureConnection* secured);
- /** True if this is a shadow connection in a cluster. */
- bool isShadow() const { return shadow; }
-
- /** True if this connection is authenticated */
- bool isAuthenticated() const { return authenticated; }
-
- // Used by cluster to update connection status
- sys::AggregateOutput& getOutputTasks() { return outputTasks; }
-
- /** Cluster delays adding management object in the constructor then calls this. */
- void addManagementObject();
-
const qpid::sys::SecuritySettings& getExternalSecuritySettings() const
{
return securitySettings;
@@ -176,9 +154,6 @@ class Connection : public sys::ConnectionInputHandler,
bool isLink() { return link; }
void startLinkHeartbeatTimeoutTask();
- // Used by cluster during catch-up, see cluster::OutputInterceptor
- void doIoCallbacks();
-
void setClientProperties(const framing::FieldTable& cp) { clientProperties = cp; }
const framing::FieldTable& getClientProperties() const { return clientProperties; }
@@ -188,15 +163,13 @@ class Connection : public sys::ConnectionInputHandler,
ChannelMap channels;
qpid::sys::SecuritySettings securitySettings;
- bool shadow;
- bool authenticated;
ConnectionHandler adapter;
const bool link;
bool mgmtClosing;
const std::string mgmtId;
sys::Mutex ioCallbackLock;
std::queue<boost::function0<void> > ioCallbacks;
- qmf::org::apache::qpid::broker::Connection* mgmtObject;
+ qmf::org::apache::qpid::broker::Connection::shared_ptr mgmtObject;
LinkRegistry& links;
management::ManagementAgent* agent;
sys::Timer& timer;
@@ -218,7 +191,6 @@ class Connection : public sys::ConnectionInputHandler,
size_t getBuffered() const;
void abort();
void activateOutput();
- void giveReadCredit(int32_t credit);
void send(framing::AMQFrame&);
void wrap(sys::ConnectionOutputHandlerPtr&);
private:
@@ -228,10 +200,11 @@ class Connection : public sys::ConnectionInputHandler,
OutboundFrameTracker outboundTracker;
void sent(const framing::AMQFrame& f);
+ void doIoCallbacks();
public:
- qmf::org::apache::qpid::broker::Connection* getMgmtObject() { return mgmtObject; }
+ qmf::org::apache::qpid::broker::Connection::shared_ptr getMgmtObject() { return mgmtObject; }
};
}}
diff --git a/cpp/src/qpid/broker/ConnectionFactory.cpp b/cpp/src/qpid/broker/ConnectionFactory.cpp
deleted file mode 100644
index d5d24ca629..0000000000
--- a/cpp/src/qpid/broker/ConnectionFactory.cpp
+++ /dev/null
@@ -1,61 +0,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.
- *
- */
-#include "qpid/broker/ConnectionFactory.h"
-#include "qpid/framing/ProtocolVersion.h"
-#include "qpid/amqp_0_10/Connection.h"
-#include "qpid/broker/Connection.h"
-#include "qpid/sys/SecuritySettings.h"
-#include "qpid/log/Statement.h"
-
-namespace qpid {
-namespace broker {
-
-using framing::ProtocolVersion;
-using qpid::sys::SecuritySettings;
-typedef std::auto_ptr<amqp_0_10::Connection> ConnectionPtr;
-typedef std::auto_ptr<sys::ConnectionInputHandler> InputPtr;
-
-ConnectionFactory::ConnectionFactory(Broker& b) : broker(b) {}
-
-ConnectionFactory::~ConnectionFactory() {}
-
-sys::ConnectionCodec*
-ConnectionFactory::create(ProtocolVersion v, sys::OutputControl& out, const std::string& id,
- const SecuritySettings& external) {
- if (v == ProtocolVersion(0, 10)) {
- ConnectionPtr c(new amqp_0_10::Connection(out, id, false));
- c->setInputHandler(InputPtr(new broker::Connection(c.get(), broker, id, external, false)));
- return c.release();
- }
- return 0;
-}
-
-sys::ConnectionCodec*
-ConnectionFactory::create(sys::OutputControl& out, const std::string& id,
- const SecuritySettings& external) {
- // used to create connections from one broker to another
- ConnectionPtr c(new amqp_0_10::Connection(out, id, true));
- c->setInputHandler(InputPtr(new broker::Connection(c.get(), broker, id, external, true)));
- return c.release();
-}
-
-
-}} // namespace qpid::broker
diff --git a/cpp/src/qpid/broker/ConnectionFactory.h b/cpp/src/qpid/broker/ConnectionFactory.h
deleted file mode 100644
index 7c1a9a08e1..0000000000
--- a/cpp/src/qpid/broker/ConnectionFactory.h
+++ /dev/null
@@ -1,51 +0,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.
- *
- */
-#ifndef _ConnectionFactory_
-#define _ConnectionFactory_
-
-#include "qpid/sys/ConnectionCodec.h"
-
-namespace qpid {
-namespace broker {
-class Broker;
-
-class ConnectionFactory : public sys::ConnectionCodec::Factory
-{
- public:
- ConnectionFactory(Broker& b);
-
- virtual ~ConnectionFactory();
-
- sys::ConnectionCodec*
- create(framing::ProtocolVersion, sys::OutputControl&, const std::string& id,
- const qpid::sys::SecuritySettings&);
-
- sys::ConnectionCodec*
- create(sys::OutputControl&, const std::string& id, const qpid::sys::SecuritySettings&);
-
- private:
- Broker& broker;
-};
-
-}}
-
-
-#endif
diff --git a/cpp/src/qpid/broker/ConnectionHandler.cpp b/cpp/src/qpid/broker/ConnectionHandler.cpp
index 06f442a47f..977c706ebd 100644
--- a/cpp/src/qpid/broker/ConnectionHandler.cpp
+++ b/cpp/src/qpid/broker/ConnectionHandler.cpp
@@ -20,8 +20,10 @@
*
*/
-#include "qpid/SaslFactory.h"
#include "qpid/broker/ConnectionHandler.h"
+
+#include "qpid/SaslFactory.h"
+#include "qpid/broker/Broker.h"
#include "qpid/broker/Connection.h"
#include "qpid/broker/SecureConnection.h"
#include "qpid/Url.h"
@@ -30,8 +32,10 @@
#include "qpid/framing/enum.h"
#include "qpid/framing/FieldValue.h"
#include "qpid/log/Statement.h"
+#include "qpid/management/ManagementAgent.h"
#include "qpid/sys/SecurityLayer.h"
#include "qpid/broker/AclModule.h"
+#include "qpid/amqp_0_10/Codecs.h"
#include "qmf/org/apache/qpid/broker/EventClientConnectFail.h"
using namespace qpid;
@@ -148,6 +152,24 @@ void ConnectionHandler::Handler::startOk(const framing::FieldTable& /*clientProp
void ConnectionHandler::Handler::startOk(const ConnectionStartOkBody& body)
{
+ const framing::FieldTable& clientProperties = body.getClientProperties();
+ qmf::org::apache::qpid::broker::Connection::shared_ptr mgmtObject = connection.getMgmtObject();
+
+ if (mgmtObject != 0) {
+ string procName = clientProperties.getAsString(CLIENT_PROCESS_NAME);
+ uint32_t pid = clientProperties.getAsInt(CLIENT_PID);
+ uint32_t ppid = clientProperties.getAsInt(CLIENT_PPID);
+
+ types::Variant::Map properties;
+ qpid::amqp_0_10::translate(clientProperties, properties);
+ mgmtObject->set_remoteProperties(properties);
+ if (!procName.empty())
+ mgmtObject->set_remoteProcessName(procName);
+ if (pid != 0)
+ mgmtObject->set_remotePid(pid);
+ if (ppid != 0)
+ mgmtObject->set_remoteParentPid(ppid);
+ }
try {
authenticator->start(body.getMechanism(), body.hasResponse() ? &body.getResponse() : 0);
} catch (std::exception& /*e*/) {
@@ -160,8 +182,9 @@ void ConnectionHandler::Handler::startOk(const ConnectionStartOkBody& body)
string uid;
authenticator->getError(error);
authenticator->getUid(uid);
- if (agent) {
- agent->raiseEvent(_qmf::EventClientConnectFail(connection.getMgmtId(), uid, error));
+ if (agent && mgmtObject) {
+ agent->raiseEvent(_qmf::EventClientConnectFail(connection.getMgmtId(), uid, error,
+ mgmtObject->get_remoteProperties()));
}
QPID_LOG_CAT(debug, model, "Failed connection. rhost:" << connection.getMgmtId()
<< " user:" << uid
@@ -169,9 +192,8 @@ void ConnectionHandler::Handler::startOk(const ConnectionStartOkBody& body)
}
throw;
}
- const framing::FieldTable& clientProperties = body.getClientProperties();
- connection.setClientProperties(clientProperties);
+ connection.setClientProperties(clientProperties);
connection.setFederationLink(clientProperties.get(QPID_FED_LINK));
if (clientProperties.isSet(QPID_FED_TAG)) {
connection.setFederationPeerTag(clientProperties.getAsString(QPID_FED_TAG));
@@ -187,19 +209,6 @@ void ConnectionHandler::Handler::startOk(const ConnectionStartOkBody& body)
}
QPID_LOG(info, "Connection is a federation link");
}
-
- if (connection.getMgmtObject() != 0) {
- string procName = clientProperties.getAsString(CLIENT_PROCESS_NAME);
- uint32_t pid = clientProperties.getAsInt(CLIENT_PID);
- uint32_t ppid = clientProperties.getAsInt(CLIENT_PPID);
-
- if (!procName.empty())
- connection.getMgmtObject()->set_remoteProcessName(procName);
- if (pid != 0)
- connection.getMgmtObject()->set_remotePid(pid);
- if (ppid != 0)
- connection.getMgmtObject()->set_remoteParentPid(ppid);
- }
}
void ConnectionHandler::Handler::secureOk(const string& response)
@@ -216,8 +225,9 @@ void ConnectionHandler::Handler::secureOk(const string& response)
string uid;
authenticator->getError(error);
authenticator->getUid(uid);
- if (agent) {
- agent->raiseEvent(_qmf::EventClientConnectFail(connection.getMgmtId(), uid, error));
+ if (agent && connection.getMgmtObject()) {
+ agent->raiseEvent(_qmf::EventClientConnectFail(connection.getMgmtId(), uid, error,
+ connection.getMgmtObject()->get_remoteProperties()));
}
QPID_LOG_CAT(debug, model, "Failed connection. rhost:" << connection.getMgmtId()
<< " user:" << uid
diff --git a/cpp/src/qpid/broker/ConnectionState.cpp b/cpp/src/qpid/broker/ConnectionState.cpp
new file mode 100644
index 0000000000..c6a8317c2b
--- /dev/null
+++ b/cpp/src/qpid/broker/ConnectionState.cpp
@@ -0,0 +1,38 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/broker/ConnectionState.h"
+
+#include "qpid/broker/Broker.h"
+
+namespace qpid {
+namespace broker {
+
+void ConnectionState::setUserId(const std::string& uid) {
+ userId = uid;
+ size_t at = userId.find('@');
+ userName = userId.substr(0, at);
+ isDefaultRealm = (
+ at!= std::string::npos &&
+ getBroker().getOptions().realm == userId.substr(at+1,userId.size()));
+}
+
+}}
diff --git a/cpp/src/qpid/broker/ConnectionState.h b/cpp/src/qpid/broker/ConnectionState.h
index 4dfd86fd8e..a8d6e82210 100644
--- a/cpp/src/qpid/broker/ConnectionState.h
+++ b/cpp/src/qpid/broker/ConnectionState.h
@@ -21,18 +21,22 @@
#ifndef _ConnectionState_
#define _ConnectionState_
-#include <vector>
-
+#include "qpid/broker/ConnectionToken.h"
#include "qpid/sys/AggregateOutput.h"
#include "qpid/sys/ConnectionOutputHandlerPtr.h"
#include "qpid/framing/ProtocolVersion.h"
#include "qpid/management/Manageable.h"
#include "qpid/Url.h"
-#include "qpid/broker/Broker.h"
+
+#include <boost/function.hpp>
+#include <vector>
+
namespace qpid {
namespace broker {
+class Broker;
+
class ConnectionState : public ConnectionToken, public management::Manageable
{
protected:
@@ -46,9 +50,8 @@ class ConnectionState : public ConnectionToken, public management::Manageable
framemax(65535),
heartbeat(0),
heartbeatmax(120),
- userProxyAuth(false), // Can proxy msgs with non-matching auth ids when true (used by federation links & clustering)
+ userProxyAuth(false), // Can proxy msgs with non-matching auth ids when true (used by federation links)
federationLink(true),
- clusterOrderOut(0),
isDefaultRealm(false)
{}
@@ -62,14 +65,7 @@ class ConnectionState : public ConnectionToken, public management::Manageable
void setHeartbeat(uint16_t hb) { heartbeat = hb; }
void setHeartbeatMax(uint16_t hbm) { heartbeatmax = hbm; }
- virtual void setUserId(const std::string& uid) {
- userId = uid;
- size_t at = userId.find('@');
- userName = userId.substr(0, at);
- isDefaultRealm = (
- at!= std::string::npos &&
- getBroker().getOptions().realm == userId.substr(at+1,userId.size()));
- }
+ virtual void setUserId(const std::string& uid);
const std::string& getUserId() const { return userId; }
@@ -102,15 +98,6 @@ class ConnectionState : public ConnectionToken, public management::Manageable
framing::ProtocolVersion getVersion() const { return version; }
void setOutputHandler(qpid::sys::ConnectionOutputHandler* o) { out.set(o); }
- /**
- * If the broker is part of a cluster, this is a handler provided
- * by cluster code. It ensures consistent ordering of commands
- * that are sent based on criteria that are not predictably
- * ordered cluster-wide, e.g. a timer firing.
- */
- framing::FrameHandler* getClusterOrderOutput() { return clusterOrderOut; }
- void setClusterOrderOutput(framing::FrameHandler& fh) { clusterOrderOut = &fh; }
-
virtual void requestIOProcessing (boost::function0<void>) = 0;
protected:
@@ -124,7 +111,6 @@ class ConnectionState : public ConnectionToken, public management::Manageable
bool federationLink;
std::string federationPeerTag;
std::vector<Url> knownHosts;
- framing::FrameHandler* clusterOrderOut;
std::string userName;
bool isDefaultRealm;
};
diff --git a/cpp/src/qpid/broker/Consumer.h b/cpp/src/qpid/broker/Consumer.h
index 64fc4288af..662b0f937d 100644
--- a/cpp/src/qpid/broker/Consumer.h
+++ b/cpp/src/qpid/broker/Consumer.h
@@ -79,6 +79,15 @@ class Consumer : public QueueCursor {
*/
virtual bool hideDeletedError() { return false; }
+ /** If false, the consumer is not counted for purposes of auto-deletion or
+ * immediate messages. This is used for "system" consumers that are created
+ * by the broker for internal purposes as opposed to consumers that are
+ * created by normal clients.
+ */
+ virtual bool isCounted() { return true; }
+
+ QueueCursor getCursor() const { return *this; }
+ void setCursor(const QueueCursor& qc) { static_cast<QueueCursor&>(*this) = qc; }
protected:
//framing::SequenceNumber position;
diff --git a/cpp/src/qpid/broker/ConsumerFactory.h b/cpp/src/qpid/broker/ConsumerFactory.h
index abd39fb3f8..1c0f2571e2 100644
--- a/cpp/src/qpid/broker/ConsumerFactory.h
+++ b/cpp/src/qpid/broker/ConsumerFactory.h
@@ -25,11 +25,14 @@
// TODO aconway 2011-11-25: it's ugly exposing SemanticState::ConsumerImpl in public.
// Refactor to use a more abstract interface.
-#include "qpid/broker/SemanticState.h"
+#include <boost/shared_ptr.hpp>
namespace qpid {
namespace broker {
+class SemanticState;
+class SemanticStateConsumerImpl;
+
/**
* Base class for consumer factoires. Plugins can register a
* ConsumerFactory via Broker:: getConsumerFactories() Each time a
@@ -41,7 +44,7 @@ class ConsumerFactory
public:
virtual ~ConsumerFactory() {}
- virtual boost::shared_ptr<SemanticState::ConsumerImpl> create(
+ virtual boost::shared_ptr<SemanticStateConsumerImpl> create(
SemanticState* parent,
const std::string& name, boost::shared_ptr<Queue> queue,
bool ack, bool acquire, bool exclusive, const std::string& tag,
diff --git a/cpp/src/qpid/broker/DeliverableMessage.cpp b/cpp/src/qpid/broker/DeliverableMessage.cpp
index be4b7f0796..31823709ce 100644
--- a/cpp/src/qpid/broker/DeliverableMessage.cpp
+++ b/cpp/src/qpid/broker/DeliverableMessage.cpp
@@ -36,8 +36,3 @@ Message& DeliverableMessage::getMessage()
{
return msg;
}
-
-uint64_t DeliverableMessage::contentSize()
-{
- return msg.getContentSize();
-}
diff --git a/cpp/src/qpid/broker/DeliverableMessage.h b/cpp/src/qpid/broker/DeliverableMessage.h
index d6d6bf5265..6e8275770d 100644
--- a/cpp/src/qpid/broker/DeliverableMessage.h
+++ b/cpp/src/qpid/broker/DeliverableMessage.h
@@ -36,7 +36,6 @@ namespace qpid {
QPID_BROKER_EXTERN DeliverableMessage(const Message& msg, TxBuffer* txn);
QPID_BROKER_EXTERN virtual void deliverTo(const boost::shared_ptr<Queue>& queue);
QPID_BROKER_EXTERN Message& getMessage();
- QPID_BROKER_EXTERN uint64_t contentSize();
virtual ~DeliverableMessage(){}
};
}
diff --git a/cpp/src/qpid/broker/DeliveryAdapter.h b/cpp/src/qpid/broker/DeliveryAdapter.h
deleted file mode 100644
index e69de29bb2..0000000000
--- a/cpp/src/qpid/broker/DeliveryAdapter.h
+++ /dev/null
diff --git a/cpp/src/qpid/broker/DirectExchange.cpp b/cpp/src/qpid/broker/DirectExchange.cpp
index b1130c3ec0..6aef1c2168 100644
--- a/cpp/src/qpid/broker/DirectExchange.cpp
+++ b/cpp/src/qpid/broker/DirectExchange.cpp
@@ -70,7 +70,7 @@ bool DirectExchange::bind(Queue::shared_ptr queue, const string& routingKey, con
if (args == 0 || fedOp.empty() || fedOp == fedOpBind) {
Mutex::ScopedLock l(lock);
- Binding::shared_ptr b(new Binding(routingKey, queue, this, FieldTable(), fedOrigin));
+ Binding::shared_ptr b(new Binding(routingKey, queue, this, args ? *args : FieldTable(), fedOrigin));
BoundKey& bk = bindings[routingKey];
if (exclusiveBinding) bk.queues.clear();
diff --git a/cpp/src/qpid/broker/DtxManager.cpp b/cpp/src/qpid/broker/DtxManager.cpp
index c55771c4e6..3b23ea2900 100644
--- a/cpp/src/qpid/broker/DtxManager.cpp
+++ b/cpp/src/qpid/broker/DtxManager.cpp
@@ -27,6 +27,9 @@
#include "qpid/ptr_map.h"
#include <boost/format.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+
#include <iostream>
using boost::intrusive_ptr;
@@ -35,6 +38,30 @@ using qpid::ptr_map_ptr;
using namespace qpid::broker;
using namespace qpid::framing;
+namespace {
+ typedef boost::function0<void> FireFunction;
+ struct DtxCleanup : public qpid::sys::TimerTask
+ {
+ FireFunction fireFunction;
+
+ DtxCleanup(uint32_t timeout, FireFunction f);
+ void fire();
+ };
+
+ DtxCleanup::DtxCleanup(uint32_t _timeout, FireFunction f)
+ : TimerTask(qpid::sys::Duration(_timeout * qpid::sys::TIME_SEC),"DtxCleanup"), fireFunction(f){}
+
+ void DtxCleanup::fire()
+ {
+ try {
+ fireFunction();
+ } catch (qpid::ConnectionException& /*e*/) {
+ //assume it was explicitly cleaned up after a call to prepare, commit or rollback
+ }
+ }
+
+}
+
//DtxManager::DtxManager(qpid::sys::Timer& t) : store(0), timer(&t) {}
DtxManager::DtxManager(qpid::sys::Timer& t) : asyncTxnStore(0), timer(&t) {}
@@ -158,19 +185,7 @@ void DtxManager::timedout(const std::string& xid)
} else {
ptr_map_ptr(i)->timedout();
//TODO: do we want to have a timed task to cleanup, or can we rely on an explicit completion?
- //timer.add(intrusive_ptr<TimerTask>(new DtxCleanup(60*30/*30 mins*/, *this, xid)));
- }
-}
-
-DtxManager::DtxCleanup::DtxCleanup(uint32_t _timeout, DtxManager& _mgr, const std::string& _xid)
- : TimerTask(qpid::sys::Duration(_timeout * qpid::sys::TIME_SEC),"DtxCleanup"), mgr(_mgr), xid(_xid) {}
-
-void DtxManager::DtxCleanup::fire()
-{
- try {
- mgr.remove(xid);
- } catch (ConnectionException& /*e*/) {
- //assume it was explicitly cleaned up after a call to prepare, commit or rollback
+ //timer->add(new DtxCleanup(60*30/*30 mins*/, boost::bind(&DtxManager::remove, this, xid)));
}
}
diff --git a/cpp/src/qpid/broker/DtxManager.h b/cpp/src/qpid/broker/DtxManager.h
index cbc66d6391..82f7ebb9ac 100644
--- a/cpp/src/qpid/broker/DtxManager.h
+++ b/cpp/src/qpid/broker/DtxManager.h
@@ -32,20 +32,15 @@
#include "qpid/ptr_map.h"
namespace qpid {
+namespace sys {
+class Timer;
+}
+
namespace broker {
class DtxManager{
typedef boost::ptr_map<std::string, DtxWorkRecord> WorkMap;
- struct DtxCleanup : public sys::TimerTask
- {
- DtxManager& mgr;
- const std::string& xid;
-
- DtxCleanup(uint32_t timeout, DtxManager& mgr, const std::string& xid);
- void fire();
- };
-
WorkMap work;
// TransactionalStore* store;
AsyncTransactionalStore* asyncTxnStore;
@@ -71,11 +66,6 @@ public:
void setStore(AsyncTransactionalStore* const ats);
void setTimer(sys::Timer& t) { timer = &t; }
- // Used by cluster for replication.
- template<class F> void each(F f) const {
- for (WorkMap::const_iterator i = work.begin(); i != work.end(); ++i)
- f(*ptr_map_ptr(i));
- }
DtxWorkRecord* getWork(const std::string& xid);
bool exists(const std::string& xid);
static std::string convert(const framing::Xid& xid);
diff --git a/cpp/src/qpid/broker/DtxWorkRecord.cpp b/cpp/src/qpid/broker/DtxWorkRecord.cpp
index 924f953eb8..13eaf4e568 100644
--- a/cpp/src/qpid/broker/DtxWorkRecord.cpp
+++ b/cpp/src/qpid/broker/DtxWorkRecord.cpp
@@ -20,7 +20,10 @@
*/
#include "qpid/broker/DtxWorkRecord.h"
#include "qpid/broker/DtxManager.h"
+#include "qpid/broker/DtxTimeout.h"
#include "qpid/framing/reply_exceptions.h"
+#include "qpid/sys/Timer.h"
+
#include <boost/format.hpp>
#include <boost/mem_fn.hpp>
using boost::mem_fn;
@@ -39,6 +42,12 @@ DtxWorkRecord::~DtxWorkRecord()
}
}
+void DtxWorkRecord::setTimeout(boost::intrusive_ptr<DtxTimeout> t)
+{ timeout = t; }
+
+boost::intrusive_ptr<DtxTimeout> DtxWorkRecord::getTimeout()
+{ return timeout; }
+
bool DtxWorkRecord::prepare()
{
Mutex::ScopedLock locker(lock);
@@ -182,17 +191,3 @@ void DtxWorkRecord::timedout()
}
abort();
}
-
-size_t DtxWorkRecord::indexOf(const DtxBuffer::shared_ptr& buf) {
- Work::iterator i = std::find(work.begin(), work.end(), buf);
- if (i == work.end()) throw NotFoundException(
- QPID_MSG("Can't find DTX buffer for xid: " << buf->getXid()));
- return i - work.begin();
-}
-
-DtxBuffer::shared_ptr DtxWorkRecord::operator[](size_t i) const {
- if (i > work.size())
- throw NotFoundException(
- QPID_MSG("Can't find DTX buffer " << i << " for xid: " << xid));
- return work[i];
-}
diff --git a/cpp/src/qpid/broker/DtxWorkRecord.h b/cpp/src/qpid/broker/DtxWorkRecord.h
index 579579df2d..84344533d9 100644
--- a/cpp/src/qpid/broker/DtxWorkRecord.h
+++ b/cpp/src/qpid/broker/DtxWorkRecord.h
@@ -24,7 +24,6 @@
#include "qpid/broker/AsyncStore.h"
#include "qpid/broker/BrokerImportExport.h"
#include "qpid/broker/DtxBuffer.h"
-#include "qpid/broker/DtxTimeout.h"
#include "qpid/broker/TransactionalStore.h"
#include "qpid/framing/amqp_types.h"
@@ -39,6 +38,8 @@
namespace qpid {
namespace broker {
+struct DtxTimeout;
+
/**
* Represents the work done under a particular distributed transaction
* across potentially multiple channels. Identified by a xid. Allows
@@ -74,19 +75,13 @@ public:
QPID_BROKER_EXTERN void add(DtxBuffer::shared_ptr ops);
void recover(std::auto_ptr<TPCTransactionContext> txn, DtxBuffer::shared_ptr ops);
void timedout();
- void setTimeout(boost::intrusive_ptr<DtxTimeout> t) { timeout = t; }
- boost::intrusive_ptr<DtxTimeout> getTimeout() { return timeout; }
+ void setTimeout(boost::intrusive_ptr<DtxTimeout> t);
+ boost::intrusive_ptr<DtxTimeout> getTimeout();
std::string getXid() const { return xid; }
bool isCompleted() const { return completed; }
bool isRolledback() const { return rolledback; }
bool isPrepared() const { return prepared; }
bool isExpired() const { return expired; }
-
- // Used by cluster update;
- size_t size() const { return work.size(); }
- DtxBuffer::shared_ptr operator[](size_t i) const;
- uint32_t getTimeout() const { return timeout? timeout->timeout : 0; }
- size_t indexOf(const DtxBuffer::shared_ptr&);
};
}} // qpid::broker
diff --git a/cpp/src/qpid/broker/Exchange.cpp b/cpp/src/qpid/broker/Exchange.cpp
index 2414981481..855a69af98 100644
--- a/cpp/src/qpid/broker/Exchange.cpp
+++ b/cpp/src/qpid/broker/Exchange.cpp
@@ -167,19 +167,19 @@ void Exchange::routeIVE(){
Exchange::Exchange (const string& _name, Manageable* parent, Broker* b) :
name(_name), durable(false), alternateUsers(0), persistenceId(0), sequence(false),
- sequenceNo(0), ive(false), mgmtExchange(0), brokerMgmtObject(0), broker(b), destroyed(false)
+ sequenceNo(0), ive(false), broker(b), destroyed(false)
{
if (parent != 0 && broker != 0)
{
ManagementAgent* agent = broker->getManagementAgent();
if (agent != 0)
{
- mgmtExchange = new _qmf::Exchange (agent, this, parent, _name);
+ mgmtExchange = _qmf::Exchange::shared_ptr(new _qmf::Exchange (agent, this, parent, _name));
mgmtExchange->set_durable(durable);
mgmtExchange->set_autoDelete(false);
agent->addObject(mgmtExchange, 0, durable);
if (broker)
- brokerMgmtObject = (qmf::org::apache::qpid::broker::Broker*) broker->GetManagementObject();
+ brokerMgmtObject = boost::dynamic_pointer_cast<qmf::org::apache::qpid::broker::Broker>(broker->GetManagementObject());
}
}
}
@@ -187,20 +187,20 @@ Exchange::Exchange (const string& _name, Manageable* parent, Broker* b) :
Exchange::Exchange(const string& _name, bool _durable, const qpid::framing::FieldTable& _args,
Manageable* parent, Broker* b)
: name(_name), durable(_durable), alternateUsers(0), persistenceId(0),
- args(_args), sequence(false), sequenceNo(0), ive(false), mgmtExchange(0), brokerMgmtObject(0), broker(b), destroyed(false)
+ args(_args), sequence(false), sequenceNo(0), ive(false), broker(b), destroyed(false)
{
if (parent != 0 && broker != 0)
{
ManagementAgent* agent = broker->getManagementAgent();
if (agent != 0)
{
- mgmtExchange = new _qmf::Exchange (agent, this, parent, _name);
+ mgmtExchange = _qmf::Exchange::shared_ptr(new _qmf::Exchange (agent, this, parent, _name));
mgmtExchange->set_durable(durable);
mgmtExchange->set_autoDelete(false);
mgmtExchange->set_arguments(ManagementAgent::toMap(args));
agent->addObject(mgmtExchange, 0, durable);
if (broker)
- brokerMgmtObject = (qmf::org::apache::qpid::broker::Broker*) broker->GetManagementObject();
+ brokerMgmtObject = boost::dynamic_pointer_cast<qmf::org::apache::qpid::broker::Broker>(broker->GetManagementObject());
}
}
@@ -212,8 +212,6 @@ Exchange::Exchange(const string& _name, bool _durable, const qpid::framing::Fiel
ive = _args.get(qpidIVE);
if (ive) {
- if (broker && broker->isInCluster())
- throw framing::NotImplementedException("Cannot use Initial Value Exchanges in a cluster");
QPID_LOG(debug, "Configured exchange " << _name << " with Initial Value");
}
}
@@ -227,6 +225,7 @@ Exchange::~Exchange ()
void Exchange::setAlternate(Exchange::shared_ptr _alternate)
{
alternate = _alternate;
+ alternate->incAlternateUsers();
if (mgmtExchange != 0) {
if (alternate.get() != 0)
mgmtExchange->set_altExchange(alternate->GetManagementObject()->getObjectId());
@@ -296,9 +295,9 @@ void Exchange::recoveryComplete(ExchangeRegistry& exchanges)
}
}
-ManagementObject* Exchange::GetManagementObject (void) const
+ManagementObject::shared_ptr Exchange::GetManagementObject (void) const
{
- return (ManagementObject*) mgmtExchange;
+ return mgmtExchange;
}
void Exchange::registerDynamicBridge(DynamicBridge* db, AsyncStore* const store)
@@ -347,16 +346,16 @@ void Exchange::propagateFedOp(const string& routingKey, const string& tags, cons
Exchange::Binding::Binding(const string& _key, Queue::shared_ptr _queue, Exchange* _parent,
FieldTable _args, const string& _origin, ConfigHandle _cfgHandle)
- : parent(_parent), queue(_queue), key(_key), args(_args), origin(_origin), cfgHandle(_cfgHandle), mgmtBinding(0)
+ : parent(_parent), queue(_queue), key(_key), args(_args), origin(_origin), cfgHandle(_cfgHandle)
{
}
Exchange::Binding::~Binding ()
{
if (mgmtBinding != 0) {
- ManagementObject* mo = queue->GetManagementObject();
+ _qmf::Queue::shared_ptr mo = boost::dynamic_pointer_cast<_qmf::Queue>(queue->GetManagementObject());
if (mo != 0)
- static_cast<_qmf::Queue*>(mo)->dec_bindingCount();
+ mo->dec_bindingCount();
mgmtBinding->resourceDestroy ();
}
}
@@ -369,25 +368,25 @@ void Exchange::Binding::startManagement()
if (broker != 0) {
ManagementAgent* agent = broker->getManagementAgent();
if (agent != 0) {
- ManagementObject* mo = queue->GetManagementObject();
+ _qmf::Queue::shared_ptr mo = boost::dynamic_pointer_cast<_qmf::Queue>(queue->GetManagementObject());
if (mo != 0) {
management::ObjectId queueId = mo->getObjectId();
- mgmtBinding = new _qmf::Binding
- (agent, this, (Manageable*) parent, queueId, key, ManagementAgent::toMap(args));
+ mgmtBinding = _qmf::Binding::shared_ptr(new _qmf::Binding
+ (agent, this, (Manageable*) parent, queueId, key, ManagementAgent::toMap(args)));
if (!origin.empty())
mgmtBinding->set_origin(origin);
agent->addObject(mgmtBinding);
- static_cast<_qmf::Queue*>(mo)->inc_bindingCount();
+ mo->inc_bindingCount();
}
}
}
}
}
-ManagementObject* Exchange::Binding::GetManagementObject () const
+ManagementObject::shared_ptr Exchange::Binding::GetManagementObject () const
{
- return (ManagementObject*) mgmtBinding;
+ return mgmtBinding;
}
uint64_t Exchange::Binding::getSize() { return 0; } // TODO: kpvdr: implement persistence
@@ -434,5 +433,10 @@ bool Exchange::routeWithAlternate(Deliverable& msg)
return msg.delivered;
}
+void Exchange::setArgs(const framing::FieldTable& newArgs) {
+ args = newArgs;
+ if (mgmtExchange) mgmtExchange->set_arguments(ManagementAgent::toMap(args));
+}
+
}}
diff --git a/cpp/src/qpid/broker/Exchange.h b/cpp/src/qpid/broker/Exchange.h
index df6d5d05a4..2c85e826ab 100644
--- a/cpp/src/qpid/broker/Exchange.h
+++ b/cpp/src/qpid/broker/Exchange.h
@@ -55,14 +55,14 @@ public:
const framing::FieldTable args;
std::string origin;
ConfigHandle cfgHandle;
- qmf::org::apache::qpid::broker::Binding* mgmtBinding;
+ qmf::org::apache::qpid::broker::Binding::shared_ptr mgmtBinding;
Binding(const std::string& key, boost::shared_ptr<Queue> queue, Exchange* parent = 0,
framing::FieldTable args = framing::FieldTable(), const std::string& origin = std::string(),
ConfigHandle cfgHandle = ConfigHandle());
~Binding();
void startManagement();
- management::ManagementObject* GetManagementObject() const;
+ management::ManagementObject::shared_ptr GetManagementObject() const;
// DataSource implementation - allows for persistence
uint64_t getSize();
@@ -170,8 +170,8 @@ protected:
}
};
- qmf::org::apache::qpid::broker::Exchange* mgmtExchange;
- qmf::org::apache::qpid::broker::Broker* brokerMgmtObject;
+ qmf::org::apache::qpid::broker::Exchange::shared_ptr mgmtExchange;
+ qmf::org::apache::qpid::broker::Broker::shared_ptr brokerMgmtObject;
public:
typedef boost::shared_ptr<Exchange> shared_ptr;
@@ -184,7 +184,8 @@ public:
const std::string& getName() const { return name; }
bool isDurable() { return durable; }
- qpid::framing::FieldTable& getArgs() { return args; }
+ QPID_BROKER_EXTERN const qpid::framing::FieldTable& getArgs() const { return args; }
+ QPID_BROKER_EXTERN void setArgs(const framing::FieldTable&);
QPID_BROKER_EXTERN Exchange::shared_ptr getAlternate() { return alternate; }
QPID_BROKER_EXTERN void setAlternate(Exchange::shared_ptr _alternate);
@@ -221,7 +222,7 @@ public:
static QPID_BROKER_EXTERN Exchange::shared_ptr decode(ExchangeRegistry& exchanges, framing::Buffer& buffer);
// Manageable entry points
- QPID_BROKER_EXTERN management::ManagementObject* GetManagementObject(void) const;
+ QPID_BROKER_EXTERN management::ManagementObject::shared_ptr GetManagementObject(void) const;
// Federation hooks
class DynamicBridge {
diff --git a/cpp/src/qpid/broker/ExchangeRegistry.cpp b/cpp/src/qpid/broker/ExchangeRegistry.cpp
index b31c7bd7b8..645918d526 100644
--- a/cpp/src/qpid/broker/ExchangeRegistry.cpp
+++ b/cpp/src/qpid/broker/ExchangeRegistry.cpp
@@ -29,20 +29,26 @@
#include "qpid/management/ManagementDirectExchange.h"
#include "qpid/management/ManagementTopicExchange.h"
#include "qpid/framing/reply_exceptions.h"
+#include "qmf/org/apache/qpid/broker/EventExchangeDeclare.h"
+#include "qmf/org/apache/qpid/broker/EventExchangeDelete.h"
using namespace qpid::broker;
using namespace qpid::sys;
using std::pair;
using std::string;
using qpid::framing::FieldTable;
+using qpid::management::ManagementAgent;
+namespace _qmf = qmf::org::apache::qpid::broker;
pair<Exchange::shared_ptr, bool> ExchangeRegistry::declare(const string& name, const string& type){
return declare(name, type, false, FieldTable());
}
-pair<Exchange::shared_ptr, bool> ExchangeRegistry::declare(const string& name, const string& type,
- bool durable, const FieldTable& args){
+pair<Exchange::shared_ptr, bool> ExchangeRegistry::declare(
+ const string& name, const string& type, bool durable, const FieldTable& args,
+ Exchange::shared_ptr alternate, const string& connectionId, const string& userId)
+{
Exchange::shared_ptr exchange;
std::pair<Exchange::shared_ptr, bool> result;
{
@@ -73,31 +79,55 @@ pair<Exchange::shared_ptr, bool> ExchangeRegistry::declare(const string& name, c
}
exchanges[name] = exchange;
result = std::pair<Exchange::shared_ptr, bool>(exchange, true);
+ if (alternate) exchange->setAlternate(alternate);
+ // Call exchangeCreate inside the lock to ensure correct ordering.
+ if (broker) broker->getConfigurationObservers().exchangeCreate(exchange);
} else {
result = std::pair<Exchange::shared_ptr, bool>(i->second, false);
}
+ if (broker && broker->getManagementAgent()) {
+ // Call raiseEvent inside the lock to ensure correct ordering.
+ broker->getManagementAgent()->raiseEvent(
+ _qmf::EventExchangeDeclare(
+ connectionId,
+ userId,
+ name,
+ type,
+ alternate ? alternate->getName() : string(),
+ durable,
+ false,
+ ManagementAgent::toMap(result.first->getArgs()),
+ result.second ? "created" : "existing"));
+ }
}
- if (broker && exchange) broker->getConfigurationObservers().exchangeCreate(exchange);
return result;
}
-void ExchangeRegistry::destroy(const string& name){
+void ExchangeRegistry::destroy(
+ const string& name, const string& connectionId, const string& userId)
+{
if (name.empty() ||
(name.find("amq.") == 0 &&
(name == "amq.direct" || name == "amq.fanout" || name == "amq.topic" || name == "amq.match")) ||
name == "qpid.management")
throw framing::NotAllowedException(QPID_MSG("Cannot delete default exchange: '" << name << "'"));
- Exchange::shared_ptr exchange;
{
RWlock::ScopedWlock locker(lock);
ExchangeMap::iterator i = exchanges.find(name);
if (i != exchanges.end()) {
- exchange = i->second;
+ if (broker) {
+ // Call exchangeDestroy and raiseEvent inside the lock to ensure
+ // correct ordering.
+ broker->getConfigurationObservers().exchangeDestroy(i->second);
+ if (broker->getManagementAgent())
+ broker->getManagementAgent()->raiseEvent(
+ _qmf::EventExchangeDelete(connectionId, userId, name));
+ }
i->second->destroy();
exchanges.erase(i);
+
}
}
- if (broker && exchange) broker->getConfigurationObservers().exchangeDestroy(exchange);
}
Exchange::shared_ptr ExchangeRegistry::find(const string& name){
diff --git a/cpp/src/qpid/broker/ExchangeRegistry.h b/cpp/src/qpid/broker/ExchangeRegistry.h
index c5d2483a23..df4c24da39 100644
--- a/cpp/src/qpid/broker/ExchangeRegistry.h
+++ b/cpp/src/qpid/broker/ExchangeRegistry.h
@@ -46,14 +46,23 @@ class ExchangeRegistry{
bool, const qpid::framing::FieldTable&, qpid::management::Manageable*, qpid::broker::Broker*> FactoryFunction;
ExchangeRegistry (Broker* b = 0) : parent(0), broker(b) {}
- QPID_BROKER_EXTERN std::pair<Exchange::shared_ptr, bool> declare
- (const std::string& name, const std::string& type);
- QPID_BROKER_EXTERN std::pair<Exchange::shared_ptr, bool> declare
- (const std::string& name,
- const std::string& type,
- bool durable,
- const qpid::framing::FieldTable& args = framing::FieldTable());
- QPID_BROKER_EXTERN void destroy(const std::string& name);
+ QPID_BROKER_EXTERN std::pair<Exchange::shared_ptr, bool> declare(
+ const std::string& name, const std::string& type);
+
+ QPID_BROKER_EXTERN std::pair<Exchange::shared_ptr, bool> declare(
+ const std::string& name,
+ const std::string& type,
+ bool durable,
+ const qpid::framing::FieldTable& args = framing::FieldTable(),
+ Exchange::shared_ptr alternate = Exchange::shared_ptr(),
+ const std::string& connectionId = std::string(),
+ const std::string& userId = std::string());
+
+ QPID_BROKER_EXTERN void destroy(
+ const std::string& name,
+ const std::string& connectionId = std::string(),
+ const std::string& userId = std::string());
+
QPID_BROKER_EXTERN Exchange::shared_ptr getDefault();
/**
diff --git a/cpp/src/qpid/broker/FanOutExchange.cpp b/cpp/src/qpid/broker/FanOutExchange.cpp
index 941d909778..4ccb44ce53 100644
--- a/cpp/src/qpid/broker/FanOutExchange.cpp
+++ b/cpp/src/qpid/broker/FanOutExchange.cpp
@@ -54,7 +54,7 @@ bool FanOutExchange::bind(Queue::shared_ptr queue, const string& /*key*/, const
bool propagate = false;
if (args == 0 || fedOp.empty() || fedOp == fedOpBind) {
- Binding::shared_ptr binding (new Binding ("", queue, this, FieldTable(), fedOrigin));
+ Binding::shared_ptr binding (new Binding ("", queue, this, args ? *args : FieldTable(), fedOrigin));
if (bindings.add_unless(binding, MatchQueue(queue))) {
binding->startManagement();
propagate = fedBinding.addOrigin(queue->getName(), fedOrigin);
diff --git a/cpp/src/qpid/broker/HeadersExchange.cpp b/cpp/src/qpid/broker/HeadersExchange.cpp
index 76ffa7a922..7edd54bc24 100644
--- a/cpp/src/qpid/broker/HeadersExchange.cpp
+++ b/cpp/src/qpid/broker/HeadersExchange.cpp
@@ -48,6 +48,7 @@ namespace {
const std::string empty;
// federation related args and values
+ const std::string QPID_RESERVED("qpid.");
const std::string qpidFedOp("qpid.fed.op");
const std::string qpidFedTags("qpid.fed.tags");
const std::string qpidFedOrigin("qpid.fed.origin");
@@ -200,8 +201,8 @@ bool HeadersExchange::bind(Queue::shared_ptr queue, const string& bindingKey, co
//matching (they are internally added properties
//controlling binding propagation but not relevant to
//actual routing)
- Binding::shared_ptr binding (new Binding (bindingKey, queue, this, extra_args));
- BoundKey bk(binding);
+ Binding::shared_ptr binding (new Binding (bindingKey, queue, this, args ? *args : FieldTable()));
+ BoundKey bk(binding, extra_args);
if (bindings.add_unless(bk, MatchArgs(queue, &extra_args))) {
binding->startManagement();
propagate = bk.fedBinding.addOrigin(queue->getName(), fedOrigin);
@@ -282,7 +283,7 @@ void HeadersExchange::route(Deliverable& msg)
Bindings::ConstPtr p = bindings.snapshot();
if (p.get()) {
for (std::vector<BoundKey>::const_iterator i = p->begin(); i != p->end(); ++i) {
- Matcher matcher(i->binding->args);
+ Matcher matcher(i->args);
msg.getMessage().processProperties(matcher);
if (matcher.matches()) {
b->push_back(i->binding);
@@ -298,7 +299,7 @@ bool HeadersExchange::isBound(Queue::shared_ptr queue, const string* const, cons
Bindings::ConstPtr p = bindings.snapshot();
if (p.get()){
for (std::vector<BoundKey>::const_iterator i = p->begin(); i != p->end(); ++i) {
- if ( (!args || equal((*i).binding->args, *args)) && (!queue || (*i).binding->queue == queue)) {
+ if ( (!args || equal((*i).args, *args)) && (!queue || (*i).binding->queue == queue)) {
return true;
}
}
@@ -315,10 +316,7 @@ void HeadersExchange::getNonFedArgs(const FieldTable* args, FieldTable& nonFedAr
for (qpid::framing::FieldTable::ValueMap::const_iterator i=args->begin(); i != args->end(); ++i)
{
- const string & name(i->first);
- if (name == qpidFedOp ||
- name == qpidFedTags ||
- name == qpidFedOrigin)
+ if (i->first.find(QPID_RESERVED) == 0)
{
continue;
}
diff --git a/cpp/src/qpid/broker/HeadersExchange.h b/cpp/src/qpid/broker/HeadersExchange.h
index 10bf9c8c0b..93e3929563 100644
--- a/cpp/src/qpid/broker/HeadersExchange.h
+++ b/cpp/src/qpid/broker/HeadersExchange.h
@@ -38,8 +38,9 @@ class HeadersExchange : public virtual Exchange {
struct BoundKey
{
Binding::shared_ptr binding;
+ qpid::framing::FieldTable args;
FedBinding fedBinding;
- BoundKey(Binding::shared_ptr binding_) : binding(binding_) {}
+ BoundKey(Binding::shared_ptr binding_, const qpid::framing::FieldTable& args_) : binding(binding_), args(args_) {}
};
struct MatchArgs
diff --git a/cpp/src/qpid/broker/LegacyLVQ.cpp b/cpp/src/qpid/broker/LegacyLVQ.cpp
deleted file mode 100644
index e69de29bb2..0000000000
--- a/cpp/src/qpid/broker/LegacyLVQ.cpp
+++ /dev/null
diff --git a/cpp/src/qpid/broker/LegacyLVQ.h b/cpp/src/qpid/broker/LegacyLVQ.h
deleted file mode 100644
index e69de29bb2..0000000000
--- a/cpp/src/qpid/broker/LegacyLVQ.h
+++ /dev/null
diff --git a/cpp/src/qpid/broker/Link.cpp b/cpp/src/qpid/broker/Link.cpp
index 9727040c9b..bb5d5cb678 100644
--- a/cpp/src/qpid/broker/Link.cpp
+++ b/cpp/src/qpid/broker/Link.cpp
@@ -30,8 +30,10 @@
#include "qpid/log/Statement.h"
#include "qpid/framing/enum.h"
#include "qpid/framing/reply_exceptions.h"
+#include "qpid/framing/amqp_types.h"
#include "qpid/broker/AclModule.h"
#include "qpid/broker/Exchange.h"
+#include "qpid/broker/NameGenerator.h"
#include "qpid/UrlArray.h"
namespace qpid {
@@ -148,12 +150,12 @@ Link::Link(const string& _name,
host(_host), port(_port), transport(_transport),
durable(_durable),
authMechanism(_authMechanism), username(_username), password(_password),
- persistenceId(0), mgmtObject(0), broker(_broker), state(0),
+ persistenceId(0), broker(_broker), state(0),
visitCount(0),
currentInterval(1),
- closing(false),
reconnectNext(0), // Index of next address for reconnecting in url.
- channelCounter(1),
+ nextFreeChannel(1),
+ freeChannels(1, framing::CHANNEL_MAX),
connection(0),
agent(0),
listener(l),
@@ -166,19 +168,15 @@ Link::Link(const string& _name,
agent = broker->getManagementAgent();
if (agent != 0)
{
- mgmtObject = new _qmf::Link(agent, this, parent, name, durable);
+ mgmtObject = _qmf::Link::shared_ptr(new _qmf::Link(agent, this, parent, name, durable));
mgmtObject->set_host(host);
mgmtObject->set_port(port);
mgmtObject->set_transport(transport);
agent->addObject(mgmtObject, 0, durable);
}
}
- if (links->isPassive()) {
- setStateLH(STATE_PASSIVE);
- } else {
- setStateLH(STATE_WAITING);
- startConnectionLH();
- }
+ setStateLH(STATE_WAITING);
+ startConnectionLH();
broker->getTimer().add(timerTask);
if (failover) {
@@ -212,9 +210,6 @@ void Link::setStateLH (int newState)
state = newState;
- if (hideManagement())
- return;
-
switch (state)
{
case STATE_WAITING : mgmtObject->set_state("Waiting"); break;
@@ -222,7 +217,7 @@ void Link::setStateLH (int newState)
case STATE_OPERATIONAL : mgmtObject->set_state("Operational"); break;
case STATE_FAILED : mgmtObject->set_state("Failed"); break;
case STATE_CLOSED : mgmtObject->set_state("Closed"); break;
- case STATE_PASSIVE : mgmtObject->set_state("Passive"); break;
+ case STATE_CLOSING : mgmtObject->set_state("Closing"); break;
}
}
@@ -233,40 +228,39 @@ void Link::startConnectionLH ()
// Set the state before calling connect. It is possible that connect
// will fail synchronously and call Link::closed before returning.
setStateLH(STATE_CONNECTING);
- broker->connect (host, boost::lexical_cast<std::string>(port), transport,
+ broker->connect (name, host, boost::lexical_cast<std::string>(port), transport,
boost::bind (&Link::closed, this, _1, _2));
- QPID_LOG (debug, "Inter-broker link connecting to " << host << ":" << port);
+ QPID_LOG (info, "Inter-broker link connecting to " << host << ":" << port);
} catch(const std::exception& e) {
QPID_LOG(error, "Link connection to " << host << ":" << port << " failed: "
<< e.what());
setStateLH(STATE_WAITING);
- if (!hideManagement())
- mgmtObject->set_lastError (e.what());
+ mgmtObject->set_lastError (e.what());
}
}
void Link::established(Connection* c)
{
- if (state == STATE_PASSIVE) return;
stringstream addr;
addr << host << ":" << port;
QPID_LOG (info, "Inter-broker link established to " << addr.str());
- if (!hideManagement() && agent)
+ if (agent)
agent->raiseEvent(_qmf::EventBrokerLinkUp(addr.str()));
- bool isClosing = false;
+ bool isClosing = true;
{
Mutex::ScopedLock mutex(lock);
- setStateLH(STATE_OPERATIONAL);
- currentInterval = 1;
- visitCount = 0;
- connection = c;
- isClosing = closing;
+ if (state != STATE_CLOSING) {
+ isClosing = false;
+ setStateLH(STATE_OPERATIONAL);
+ currentInterval = 1;
+ visitCount = 0;
+ connection = c;
+ c->requestIOProcessing (boost::bind(&Link::ioThreadProcessing, this));
+ }
}
if (isClosing)
destroy();
- else // Process any IO tasks bridges added before established.
- c->requestIOProcessing (boost::bind(&Link::ioThreadProcessing, this));
}
@@ -291,11 +285,12 @@ class DetachedCallback : public SessionHandler::ErrorListener {
};
}
-void Link::opened() {
+void Link::opened()
+{
Mutex::ScopedLock mutex(lock);
- if (!connection) return;
+ if (!connection || state != STATE_OPERATIONAL) return;
- if (!hideManagement() && connection->GetManagementObject()) {
+ if (connection->GetManagementObject()) {
mgmtObject->set_connectionRef(connection->GetManagementObject()->getObjectId());
}
@@ -350,37 +345,43 @@ void Link::opened() {
}
}
+
+// called when connection attempt fails (see startConnectionLH)
void Link::closed(int, std::string text)
{
- Mutex::ScopedLock mutex(lock);
QPID_LOG (info, "Inter-broker link disconnected from " << host << ":" << port << " " << text);
- connection = 0;
+ bool isClosing = false;
+ {
+ Mutex::ScopedLock mutex(lock);
+
+ connection = 0;
- if (!hideManagement()) {
mgmtObject->set_connectionRef(qpid::management::ObjectId());
if (state == STATE_OPERATIONAL && agent) {
stringstream addr;
addr << host << ":" << port;
agent->raiseEvent(_qmf::EventBrokerLinkDown(addr.str()));
}
- }
- for (Bridges::iterator i = active.begin(); i != active.end(); i++) {
- (*i)->closed();
- created.push_back(*i);
- }
- active.clear();
+ for (Bridges::iterator i = active.begin(); i != active.end(); i++) {
+ (*i)->closed();
+ created.push_back(*i);
+ }
+ active.clear();
- if (state != STATE_FAILED && state != STATE_PASSIVE)
- {
- setStateLH(STATE_WAITING);
- if (!hideManagement())
+ if (state == STATE_CLOSING) {
+ isClosing = true;
+ } else if (state != STATE_FAILED) {
+ setStateLH(STATE_WAITING);
mgmtObject->set_lastError (text);
+ }
}
+ if (isClosing) destroy();
}
-// Called in connection IO thread, cleans up the connection before destroying Link
+// Cleans up the connection before destroying Link. Must be called in connection thread
+// if the connection is active. Caller Note well: may call "delete this"!
void Link::destroy ()
{
Bridges toDelete;
@@ -410,7 +411,9 @@ void Link::destroy ()
for (Bridges::iterator i = toDelete.begin(); i != toDelete.end(); i++)
(*i)->close();
toDelete.clear();
- listener(this); // notify LinkRegistry that this Link has been destroyed
+ // notify LinkRegistry that this Link has been destroyed. Will result in "delete
+ // this" if LinkRegistry is holding the last shared pointer to *this
+ listener(this);
}
void Link::add(Bridge::shared_ptr bridge)
@@ -452,7 +455,7 @@ void Link::ioThreadProcessing()
{
Mutex::ScopedLock mutex(lock);
- if (state != STATE_OPERATIONAL || closing)
+ if (state != STATE_OPERATIONAL)
return;
// check for bridge session errors and recover
@@ -489,9 +492,9 @@ void Link::ioThreadProcessing()
void Link::maintenanceVisit ()
{
Mutex::ScopedLock mutex(lock);
- if (closing) return;
- if (state == STATE_WAITING)
- {
+
+ switch (state) {
+ case STATE_WAITING:
visitCount++;
if (visitCount >= currentInterval)
{
@@ -504,11 +507,17 @@ void Link::maintenanceVisit ()
startConnectionLH();
}
}
+ break;
+
+ case STATE_OPERATIONAL:
+ if ((!active.empty() || !created.empty() || !cancellations.empty()) &&
+ connection && connection->isOpen())
+ connection->requestIOProcessing (boost::bind(&Link::ioThreadProcessing, this));
+ break;
+
+ default: // no-op for all other states
+ break;
}
- else if (state == STATE_OPERATIONAL &&
- (!active.empty() || !created.empty() || !cancellations.empty()) &&
- connection && connection->isOpen())
- connection->requestIOProcessing (boost::bind(&Link::ioThreadProcessing, this));
}
void Link::reconnectLH(const Address& a)
@@ -517,14 +526,13 @@ void Link::reconnectLH(const Address& a)
port = a.port;
transport = a.protocol;
- if (!hideManagement()) {
- stringstream errorString;
- errorString << "Failing over to " << a;
- mgmtObject->set_lastError(errorString.str());
- mgmtObject->set_host(host);
- mgmtObject->set_port(port);
- mgmtObject->set_transport(transport);
- }
+ stringstream errorString;
+ errorString << "Failing over to " << a;
+ mgmtObject->set_lastError(errorString.str());
+ mgmtObject->set_host(host);
+ mgmtObject->set_port(port);
+ mgmtObject->set_transport(transport);
+
startConnectionLH();
}
@@ -541,26 +549,56 @@ bool Link::tryFailoverLH() {
return false;
}
-// Management updates for a link are inconsistent in a cluster, so they are
-// suppressed.
-bool Link::hideManagement() const {
- return !mgmtObject || ( broker && broker->isInCluster());
+// Allocate channel from link free pool
+framing::ChannelId Link::nextChannel()
+{
+ Mutex::ScopedLock mutex(lock);
+ if (!freeChannels.empty()) {
+ // A free channel exists.
+ for (framing::ChannelId i = 1; i <= framing::CHANNEL_MAX; i++)
+ {
+ // extract proposed free channel
+ framing::ChannelId c = nextFreeChannel;
+ // calculate next free channel
+ if (framing::CHANNEL_MAX == nextFreeChannel)
+ nextFreeChannel = 1;
+ else
+ nextFreeChannel += 1;
+ // if proposed channel is free, use it
+ if (freeChannels.contains(c))
+ {
+ freeChannels -= c;
+ QPID_LOG(debug, "Link " << name << " allocates channel: " << c);
+ return c;
+ }
+ }
+ assert (false);
+ }
+
+ throw Exception(Msg() << "Link " << name << " channel pool is empty");
}
-uint Link::nextChannel()
+// Return channel to link free pool
+void Link::returnChannel(framing::ChannelId c)
{
Mutex::ScopedLock mutex(lock);
- if (channelCounter >= framing::CHANNEL_MAX)
- channelCounter = 1;
- return channelCounter++;
+ QPID_LOG(debug, "Link " << name << " frees channel: " << c);
+ freeChannels += c;
}
void Link::notifyConnectionForced(const string text)
{
- Mutex::ScopedLock mutex(lock);
- setStateLH(STATE_FAILED);
- if (!hideManagement())
- mgmtObject->set_lastError(text);
+ bool isClosing = false;
+ {
+ Mutex::ScopedLock mutex(lock);
+ if (state == STATE_CLOSING) {
+ isClosing = true;
+ } else {
+ setStateLH(STATE_FAILED);
+ mgmtObject->set_lastError(text);
+ }
+ }
+ if (isClosing) destroy();
}
void Link::setPersistenceId(uint64_t id) const
@@ -643,21 +681,32 @@ uint32_t Link::encodedSize() const
+ password.size() + 1;
}
-ManagementObject* Link::GetManagementObject (void) const
+ManagementObject::shared_ptr Link::GetManagementObject(void) const
{
- return (ManagementObject*) mgmtObject;
+ return mgmtObject;
}
void Link::close() {
QPID_LOG(debug, "Link::close(), link=" << name );
- Mutex::ScopedLock mutex(lock);
- if (!closing) {
- closing = true;
- if (state != STATE_CONNECTING && connection) {
- //connection can only be closed on the connections own IO processing thread
- connection->requestIOProcessing(boost::bind(&Link::destroy, this));
+ bool destroy_now = false;
+ {
+ Mutex::ScopedLock mutex(lock);
+ if (state != STATE_CLOSING) {
+ int old_state = state;
+ setStateLH(STATE_CLOSING);
+ if (connection) {
+ //connection can only be closed on the connections own IO processing thread
+ connection->requestIOProcessing(boost::bind(&Link::destroy, this));
+ } else if (old_state == STATE_CONNECTING) {
+ // cannot destroy Link now since a connection request is outstanding.
+ // destroy the link after we get a response (see Link::established,
+ // Link::closed, Link::notifyConnectionForced, etc).
+ } else {
+ destroy_now = true;
+ }
}
}
+ if (destroy_now) destroy();
}
@@ -701,22 +750,6 @@ Manageable::status_t Link::ManagementMethod (uint32_t op, Args& args, string& te
return Manageable::STATUS_UNKNOWN_METHOD;
}
-void Link::setPassive(bool passive)
-{
- Mutex::ScopedLock mutex(lock);
- if (passive) {
- setStateLH(STATE_PASSIVE);
- } else {
- if (state == STATE_PASSIVE) {
- setStateLH(STATE_WAITING);
- } else {
- QPID_LOG(warning, "Ignoring attempt to activate non-passive link "
- << host << ":" << port);
- }
- }
-}
-
-
/** utility to clean up connection resources correctly */
void Link::closeConnection( const std::string& reason)
{
@@ -752,28 +785,6 @@ namespace {
const std::string FAILOVER_INDEX("failover-index");
}
-void Link::getState(framing::FieldTable& state) const
-{
- state.clear();
- Mutex::ScopedLock mutex(lock);
- if (!url.empty()) {
- state.setString(FAILOVER_ADDRESSES, url.str());
- state.setInt(FAILOVER_INDEX, reconnectNext);
- }
-}
-
-void Link::setState(const framing::FieldTable& state)
-{
- Mutex::ScopedLock mutex(lock);
- if (state.isSet(FAILOVER_ADDRESSES)) {
- Url failovers(state.getAsString(FAILOVER_ADDRESSES));
- setUrl(failovers);
- }
- if (state.isSet(FAILOVER_INDEX)) {
- reconnectNext = state.getAsInt(FAILOVER_INDEX);
- }
-}
-
std::string Link::createName(const std::string& transport,
const std::string& host,
uint16_t port)
@@ -784,14 +795,6 @@ std::string Link::createName(const std::string& transport,
return linkName.str();
}
-
-bool Link::pendingConnection(const std::string& _host, uint16_t _port) const
-{
- Mutex::ScopedLock mutex(lock);
- return (isConnecting() && _port == port && _host == host);
-}
-
-
const std::string Link::exchangeTypeName("qpid.LinkExchange");
}} // namespace qpid::broker
diff --git a/cpp/src/qpid/broker/Link.h b/cpp/src/qpid/broker/Link.h
index f0cb90e73b..01ddc68d97 100644
--- a/cpp/src/qpid/broker/Link.h
+++ b/cpp/src/qpid/broker/Link.h
@@ -69,12 +69,11 @@ class Link : public PersistableConfig, public management::Manageable {
std::string username;
std::string password;
mutable uint64_t persistenceId;
- qmf::org::apache::qpid::broker::Link* mgmtObject;
+ qmf::org::apache::qpid::broker::Link::shared_ptr mgmtObject;
Broker* broker;
int state;
uint32_t visitCount;
uint32_t currentInterval;
- bool closing;
Url url; // URL can contain many addresses.
size_t reconnectNext; // Index for next re-connect attempt
@@ -82,7 +81,8 @@ class Link : public PersistableConfig, public management::Manageable {
Bridges created; // Bridges pending creation
Bridges active; // Bridges active
Bridges cancellations; // Bridges pending cancellation
- uint channelCounter;
+ framing::ChannelId nextFreeChannel;
+ RangeSet<framing::ChannelId> freeChannels;
Connection* connection;
management::ManagementAgent* agent;
boost::function<void(Link*)> listener;
@@ -97,7 +97,7 @@ class Link : public PersistableConfig, public management::Manageable {
static const int STATE_OPERATIONAL = 3;
static const int STATE_FAILED = 4;
static const int STATE_CLOSED = 5;
- static const int STATE_PASSIVE = 6;
+ static const int STATE_CLOSING = 6; // Waiting for outstanding connect to complete first
static const uint32_t MAX_INTERVAL = 32;
@@ -106,7 +106,6 @@ class Link : public PersistableConfig, public management::Manageable {
void destroy(); // Cleanup connection before link goes away
void ioThreadProcessing(); // Called on connection's IO thread by request
bool tryFailoverLH(); // Called during maintenance visit
- bool hideManagement() const;
void reconnectLH(const Address&); //called by LinkRegistry
// connection management (called by LinkRegistry)
@@ -115,7 +114,6 @@ class Link : public PersistableConfig, public management::Manageable {
void closed(int, std::string); // Called when connection goes away
void notifyConnectionForced(const std::string text);
void closeConnection(const std::string& reason);
- bool pendingConnection(const std::string& host, uint16_t port) const; // is Link trying to connect to this remote?
friend class LinkRegistry; // to call established, opened, closed
@@ -151,7 +149,8 @@ class Link : public PersistableConfig, public management::Manageable {
bool isDurable() { return durable; }
void maintenanceVisit ();
- uint nextChannel();
+ framing::ChannelId nextChannel(); // allocate channel from link free pool
+ void returnChannel(framing::ChannelId); // return channel to link free pool
void add(Bridge::shared_ptr);
void cancel(Bridge::shared_ptr);
@@ -165,7 +164,6 @@ class Link : public PersistableConfig, public management::Manageable {
std::string getPassword() { return password; }
Broker* getBroker() { return broker; }
- void setPassive(bool p);
bool isConnecting() const { return state == STATE_CONNECTING; }
// PersistableConfig:
@@ -181,17 +179,13 @@ class Link : public PersistableConfig, public management::Manageable {
static bool isEncodedLink(const std::string& key);
// Manageable entry points
- management::ManagementObject* GetManagementObject(void) const;
+ management::ManagementObject::shared_ptr GetManagementObject(void) const;
management::Manageable::status_t ManagementMethod(uint32_t, management::Args&, std::string&);
// manage the exchange owned by this link
static const std::string exchangeTypeName;
static boost::shared_ptr<Exchange> linkExchangeFactory(const std::string& name);
- // replicate internal state of this Link for clustering
- void getState(framing::FieldTable& state) const;
- void setState(const framing::FieldTable& state);
-
/** create a name for a link (if none supplied by user config) */
static std::string createName(const std::string& transport,
const std::string& host,
diff --git a/cpp/src/qpid/broker/LinkRegistry.cpp b/cpp/src/qpid/broker/LinkRegistry.cpp
index a79081b8ed..d048b9c05f 100644
--- a/cpp/src/qpid/broker/LinkRegistry.cpp
+++ b/cpp/src/qpid/broker/LinkRegistry.cpp
@@ -19,8 +19,10 @@
*
*/
#include "qpid/broker/LinkRegistry.h"
-#include "qpid/broker/Link.h"
+
+#include "qpid/broker/Broker.h"
#include "qpid/broker/Connection.h"
+#include "qpid/broker/Link.h"
#include "qpid/log/Statement.h"
#include <iostream>
#include <boost/format.hpp>
@@ -42,8 +44,8 @@ namespace _qmf = qmf::org::apache::qpid::broker;
// factored: The persistence element should be factored separately
LinkRegistry::LinkRegistry () :
broker(0),
-// parent(0), store(0), passive(false),
- parent(0), asyncStore(0), passive(false),
+// parent(0), store(0),
+ parent(0), asyncStore(0),
realm("")
{
}
@@ -60,7 +62,8 @@ class LinkRegistryConnectionObserver : public ConnectionObserver {
LinkRegistry::LinkRegistry (Broker* _broker) :
broker(_broker),
- parent(0), asyncStore(0), passive(false),
+// parent(0), store(0),
+ parent(0), asyncStore(0),
realm(broker->getOptions().realm)
{
broker->getConnectionObservers().add(
@@ -118,10 +121,9 @@ pair<Link::shared_ptr, bool> LinkRegistry::declare(const string& name,
boost::bind(&LinkRegistry::linkDestroyed, this, _1),
durable, authMechanism, username, password, broker,
parent, failover));
-// if (durable && store) store->create(*link);
- if (durable && asyncStore) {
-// store->create(*link);
- // TODO: kpvdr: async create config (link)
+ if (durable && asyncStore && !broker->inRecovery()) {
+ //store->create(*link);
+ // TODO: kpvdr: async create config (link)
}
links[name] = link;
pendingLinks[name] = link;
@@ -218,9 +220,8 @@ pair<Bridge::shared_ptr, bool> LinkRegistry::declare(const std::string& name,
args, init, queueName, altExchange));
bridges[name] = bridge;
link.add(bridge);
-// if (durable && store)
- if (durable && asyncStore) {
-// store->create(*bridge);
+ if (durable && asyncStore && !broker->inRecovery()) {
+ //store->create(*bridge);
// TODO: kpvdr: Async create config (bridge)
}
@@ -264,6 +265,7 @@ void LinkRegistry::destroyBridge(Bridge *bridge)
Link *link = b->second->getLink();
if (link) {
link->cancel(b->second);
+ link->returnChannel( bridge->getChannel() );
}
// if (b->second->isDurable())
if (b->second->isDurable()) {
@@ -283,38 +285,6 @@ AsyncStore* LinkRegistry::getStore() const {
return asyncStore;
}
-namespace {
- void extractHostPort(const std::string& connId, std::string *host, uint16_t *port)
- {
- // Extract host and port of remote broker from connection id string.
- //
- // TODO aconway 2011-02-01: centralize code that constructs/parses connection
- // management IDs. Currently sys:: protocol factories and IO plugins construct the
- // IDs and LinkRegistry parses them.
- // KAG: current connection id format assumed:
- // "localhost:port-remotehost:port". In the case of IpV6, the host addresses are
- // contained within brackets "[...]", example:
- // connId="[::1]:36859-[::1]:48603". Liberal use of "asserts" provided to alert us
- // if this assumption changes!
- size_t separator = connId.find('-');
- assert(separator != std::string::npos);
- std::string remote = connId.substr(separator+1, std::string::npos);
- separator = remote.rfind(":");
- assert(separator != std::string::npos);
- *host = remote.substr(0, separator);
- // IPv6 - host is bracketed by "[]", strip them
- if ((*host)[0] == '[' && (*host)[host->length() - 1] == ']') {
- *host = host->substr(1, host->length() - 2);
- }
- try {
- *port = boost::lexical_cast<uint16_t>(remote.substr(separator+1, std::string::npos));
- } catch (const boost::bad_lexical_cast&) {
- QPID_LOG(error, "Invalid format for connection identifier! '" << connId << "'");
- assert(false);
- }
- }
-}
-
/** find the Link that corresponds to the given connection */
Link::shared_ptr LinkRegistry::findLink(const std::string& connId)
{
@@ -334,19 +304,15 @@ void LinkRegistry::notifyConnection(const std::string& key, Connection* c)
// create a mapping from connection id to link
QPID_LOG(debug, "LinkRegistry::notifyConnection(); key=" << key );
std::string host;
- uint16_t port = 0;
- extractHostPort( key, &host, &port );
Link::shared_ptr link;
{
Mutex::ScopedLock locker(lock);
- for (LinkMap::iterator l = pendingLinks.begin(); l != pendingLinks.end(); ++l) {
- if (l->second->pendingConnection(host, port)) {
- link = l->second;
- pendingLinks.erase(l);
- connections[key] = link->getName();
- QPID_LOG(debug, "LinkRegistry:: found pending =" << link->getName());
- break;
- }
+ LinkMap::iterator l = pendingLinks.find(key);
+ if (l != pendingLinks.end()) {
+ link = l->second;
+ pendingLinks.erase(l);
+ connections[key] = link->getName();
+ QPID_LOG(debug, "LinkRegistry:: found pending =" << link->getName());
}
}
@@ -461,26 +427,4 @@ std::string LinkRegistry::getAuthIdentity(const std::string& key)
return link->getUsername();
}
-
-void LinkRegistry::setPassive(bool p)
-{
- Mutex::ScopedLock locker(lock);
- passive = p;
- if (passive) { QPID_LOG(info, "Passivating links"); }
- else { QPID_LOG(info, "Activating links"); }
- for (LinkMap::iterator i = links.begin(); i != links.end(); i++) {
- i->second->setPassive(passive);
- }
-}
-
-void LinkRegistry::eachLink(boost::function<void(boost::shared_ptr<Link>)> f) {
- Mutex::ScopedLock locker(lock);
- for (LinkMap::iterator i = links.begin(); i != links.end(); ++i) f(i->second);
-}
-
-void LinkRegistry::eachBridge(boost::function<void(boost::shared_ptr<Bridge>)> f) {
- Mutex::ScopedLock locker(lock);
- for (BridgeMap::iterator i = bridges.begin(); i != bridges.end(); ++i) f(i->second);
-}
-
}} // namespace qpid::broker
diff --git a/cpp/src/qpid/broker/LinkRegistry.h b/cpp/src/qpid/broker/LinkRegistry.h
index 17f45a60c8..6689ceda0f 100644
--- a/cpp/src/qpid/broker/LinkRegistry.h
+++ b/cpp/src/qpid/broker/LinkRegistry.h
@@ -54,7 +54,6 @@ namespace broker {
management::Manageable* parent;
// MessageStore* store;
AsyncStore* asyncStore;
- bool passive;
std::string realm;
boost::shared_ptr<Link> findLink(const std::string& key);
@@ -147,20 +146,6 @@ namespace broker {
QPID_BROKER_EXTERN std::string getPassword (const std::string& key);
QPID_BROKER_EXTERN std::string getHost (const std::string& key);
QPID_BROKER_EXTERN uint16_t getPort (const std::string& key);
-
- /**
- * Called to alter passive state. In passive state the links
- * and bridges managed by a link registry will be recorded and
- * updated but links won't actually establish connections and
- * bridges won't therefore pull or push any messages.
- */
- QPID_BROKER_EXTERN void setPassive(bool);
- QPID_BROKER_EXTERN bool isPassive() { return passive; }
-
- /** Iterate over each link in the registry. Used for cluster updates. */
- QPID_BROKER_EXTERN void eachLink(boost::function<void(boost::shared_ptr<Link>)> f);
- /** Iterate over each bridge in the registry. Used for cluster updates. */
- QPID_BROKER_EXTERN void eachBridge(boost::function<void(boost::shared_ptr< Bridge>)> f);
};
}
}
diff --git a/cpp/src/qpid/broker/Lvq.cpp b/cpp/src/qpid/broker/Lvq.cpp
index f5e66c8a74..9d6923e560 100644
--- a/cpp/src/qpid/broker/Lvq.cpp
+++ b/cpp/src/qpid/broker/Lvq.cpp
@@ -20,7 +20,6 @@
*/
#include "Lvq.h"
#include "MessageMap.h"
-#include "qpid/sys/ClusterSafe.h"
#include "qpid/sys/Monitor.h"
namespace qpid {
@@ -35,7 +34,6 @@ Lvq::Lvq(const std::string& n, std::auto_ptr<MessageMap> m, const QueueSettings&
void Lvq::push(Message& message, bool isRecovery)
{
- qpid::sys::assertClusterSafe();
QueueListeners::NotificationSet copy;
Message old;
bool removed;
diff --git a/cpp/src/qpid/broker/Message.cpp b/cpp/src/qpid/broker/Message.cpp
index c48e9bcfa4..431f4291ff 100644
--- a/cpp/src/qpid/broker/Message.cpp
+++ b/cpp/src/qpid/broker/Message.cpp
@@ -131,6 +131,18 @@ uint64_t Message::getTtl() const
}
}
+bool Message::getTtl(uint64_t ttl) const
+{
+ if (encoding->getTtl(ttl) && expiration < FAR_FUTURE) {
+ sys::Duration remaining(sys::AbsTime::now(), getExpiration());
+ // convert from ns to ms; set to 0 if expired
+ ttl = (int64_t(remaining) >= 1000000 ? int64_t(remaining)/1000000 : 0);
+ return true;
+ } else {
+ return false;
+ }
+}
+
void Message::computeExpiration(const boost::intrusive_ptr<ExpiryPolicy>& e)
{
//TODO: this is still quite 0-10 specific...
diff --git a/cpp/src/qpid/broker/Message.h b/cpp/src/qpid/broker/Message.h
index 599819d7b6..b999a7d5a3 100644
--- a/cpp/src/qpid/broker/Message.h
+++ b/cpp/src/qpid/broker/Message.h
@@ -61,7 +61,6 @@ public:
virtual std::string getPropertyAsString(const std::string& key) const = 0;
virtual std::string getAnnotationAsString(const std::string& key) const = 0;
virtual bool getTtl(uint64_t&) const = 0;
- virtual bool hasExpiration() const = 0;
virtual std::string getContent() const = 0;
virtual void processProperties(MapHandler&) const = 0;
virtual std::string getUserId() const = 0;
@@ -92,6 +91,7 @@ public:
sys::AbsTime getExpiration() const { return expiration; }
void setExpiration(sys::AbsTime exp) { expiration = exp; }
uint64_t getTtl() const;
+ bool getTtl(uint64_t) const;
/** set the timestamp delivery property to the current time-of-day */
QPID_BROKER_EXTERN void setTimestamp();
@@ -125,7 +125,7 @@ public:
QPID_BROKER_EXTERN const qpid::types::Variant::Map& getAnnotations() const;
std::string getUserId() const;
- QPID_BROKER_EXTERN std::string getContent() const;//TODO: may be better to get rid of this...
+ QPID_BROKER_EXTERN std::string getContent() const;//Used for ha, management, when content needs to be decoded
QPID_BROKER_EXTERN boost::intrusive_ptr<AsyncCompletion> getIngressCompletion() const;
QPID_BROKER_EXTERN boost::intrusive_ptr<PersistableMessage> getPersistentContext() const;
diff --git a/cpp/src/qpid/broker/MessageGroupManager.cpp b/cpp/src/qpid/broker/MessageGroupManager.cpp
index 47e40a4794..c083e4ee0f 100644
--- a/cpp/src/qpid/broker/MessageGroupManager.cpp
+++ b/cpp/src/qpid/broker/MessageGroupManager.cpp
@@ -302,19 +302,6 @@ void MessageGroupManager::setDefaults(const std::string& groupId) // static
defaultGroupId = groupId;
}
-/** Cluster replication:
-
- state map format:
-
- { "group-state": [ {"name": <group-name>,
- "owner": <consumer-name>-or-empty,
- "acquired-ct": <acquired count>,
- "positions": [Seqnumbers, ... ]},
- {...}
- ]
- }
-*/
-
namespace {
const std::string GROUP_NAME("name");
const std::string GROUP_OWNER("owner");
@@ -324,100 +311,3 @@ namespace {
const std::string GROUP_STATE("group-state");
}
-
-/** Runs on UPDATER to snapshot current state */
-void MessageGroupManager::getState(qpid::framing::FieldTable& state ) const
-{
- using namespace qpid::framing;
- state.clear();
- framing::Array groupState(TYPE_CODE_MAP);
- for (GroupMap::const_iterator g = messageGroups.begin();
- g != messageGroups.end(); ++g) {
-
- framing::FieldTable group;
- group.setString(GROUP_NAME, g->first);
- group.setString(GROUP_OWNER, g->second.owner);
- group.setInt(GROUP_ACQUIRED_CT, g->second.acquired);
- framing::Array positions(TYPE_CODE_UINT32);
- framing::Array acquiredMsgs(TYPE_CODE_BOOLEAN);
- for (GroupState::MessageFifo::const_iterator p = g->second.members.begin();
- p != g->second.members.end(); ++p) {
- positions.push_back(framing::Array::ValuePtr(new IntegerValue( p->position )));
- acquiredMsgs.push_back(framing::Array::ValuePtr(new BoolValue( p->acquired )));
- }
- group.setArray(GROUP_POSITIONS, positions);
- group.setArray(GROUP_ACQUIRED_MSGS, acquiredMsgs);
- groupState.push_back(framing::Array::ValuePtr(new FieldTableValue(group)));
- }
- state.setArray(GROUP_STATE, groupState);
-
- QPID_LOG(debug, "Queue \"" << qName << "\": replicating message group state, key=" << groupIdHeader);
-}
-
-
-/** called on UPDATEE to set state from snapshot */
-void MessageGroupManager::setState(const qpid::framing::FieldTable& state)
-{
- using namespace qpid::framing;
- messageGroups.clear();
- freeGroups.clear();
- cachedGroup = 0;
-
- framing::Array groupState(TYPE_CODE_MAP);
-
- bool ok = state.getArray(GROUP_STATE, groupState);
- if (!ok) {
- QPID_LOG(error, "Unable to find message group state information for queue \"" <<
- qName << "\": cluster inconsistency error!");
- return;
- }
-
- for (framing::Array::const_iterator g = groupState.begin();
- g != groupState.end(); ++g) {
- framing::FieldTable group;
- ok = framing::getEncodedValue<FieldTable>(*g, group);
- if (!ok) {
- QPID_LOG(error, "Invalid message group state information for queue \"" <<
- qName << "\": table encoding error!");
- return;
- }
- MessageGroupManager::GroupState state;
- if (!group.isSet(GROUP_NAME) || !group.isSet(GROUP_OWNER) || !group.isSet(GROUP_ACQUIRED_CT)) {
- QPID_LOG(error, "Invalid message group state information for queue \"" <<
- qName << "\": fields missing error!");
- return;
- }
- state.group = group.getAsString(GROUP_NAME);
- state.owner = group.getAsString(GROUP_OWNER);
- state.acquired = group.getAsInt(GROUP_ACQUIRED_CT);
- framing::Array positions(TYPE_CODE_UINT32);
- ok = group.getArray(GROUP_POSITIONS, positions);
- if (!ok) {
- QPID_LOG(error, "Invalid message group state information for queue \"" <<
- qName << "\": position encoding error!");
- return;
- }
- framing::Array acquiredMsgs(TYPE_CODE_BOOLEAN);
- ok = group.getArray(GROUP_ACQUIRED_MSGS, acquiredMsgs);
- if (!ok || positions.count() != acquiredMsgs.count()) {
- QPID_LOG(error, "Invalid message group state information for queue \"" <<
- qName << "\": acquired flag encoding error!");
- return;
- }
-
- Array::const_iterator a = acquiredMsgs.begin();
- for (Array::const_iterator p = positions.begin(); p != positions.end(); ++p) {
- GroupState::MessageState mState((*p)->getIntegerValue<uint32_t, 4>());
- mState.acquired = (*a++)->getIntegerValue<bool>();
- state.members.push_back(mState);
- }
-
- messageGroups[state.group] = state;
- if (!state.owned()) {
- assert(state.members.size());
- freeGroups[state.members.front().position] = &messageGroups[state.group];
- }
- }
-
- QPID_LOG(debug, "Queue \"" << qName << "\": message group state replicated, key =" << groupIdHeader)
-}
diff --git a/cpp/src/qpid/broker/MessageGroupManager.h b/cpp/src/qpid/broker/MessageGroupManager.h
index fe39e007b5..bf45e776c8 100644
--- a/cpp/src/qpid/broker/MessageGroupManager.h
+++ b/cpp/src/qpid/broker/MessageGroupManager.h
@@ -25,11 +25,12 @@
/* for managing message grouping on Queues */
#include "qpid/broker/BrokerImportExport.h"
-#include "qpid/broker/StatefulQueueObserver.h"
+#include "qpid/broker/QueueObserver.h"
#include "qpid/broker/MessageDistributor.h"
#include "qpid/framing/SequenceNumber.h"
#include "qpid/sys/unordered_map.h"
+#include "boost/shared_ptr.hpp"
#include <deque>
namespace qpid {
@@ -39,8 +40,9 @@ class QueueObserver;
struct QueueSettings;
class MessageDistributor;
class Messages;
+class Consumer;
-class MessageGroupManager : public StatefulQueueObserver, public MessageDistributor
+class MessageGroupManager : public QueueObserver, public MessageDistributor
{
static std::string defaultGroupId; // assigned if no group id header present
@@ -101,10 +103,10 @@ class MessageGroupManager : public StatefulQueueObserver, public MessageDistribu
MessageGroupManager(const std::string& header, const std::string& _qName,
Messages& container, unsigned int _timestamp=0 )
- : StatefulQueueObserver(std::string("MessageGroupManager:") + header),
- groupIdHeader( header ), timestamp(_timestamp), messages(container), qName(_qName),
- hits(0), misses(0),
- lastMsg(0), cachedGroup(0) {}
+ : groupIdHeader( header ), timestamp(_timestamp), messages(container),
+ qName(_qName),
+ hits(0), misses(0),
+ lastMsg(0), cachedGroup(0) {}
virtual ~MessageGroupManager();
// QueueObserver iface
@@ -114,8 +116,6 @@ class MessageGroupManager : public StatefulQueueObserver, public MessageDistribu
void dequeued( const Message& qm );
void consumerAdded( const Consumer& ) {};
void consumerRemoved( const Consumer& ) {};
- void getState(qpid::framing::FieldTable& state ) const;
- void setState(const qpid::framing::FieldTable&);
// MessageDistributor iface
bool acquire(const std::string& c, Message& );
diff --git a/cpp/src/qpid/broker/MessageStore.h b/cpp/src/qpid/broker/MessageStore.h
index 5e339574fd..d6a7cea18b 100644
--- a/cpp/src/qpid/broker/MessageStore.h
+++ b/cpp/src/qpid/broker/MessageStore.h
@@ -49,20 +49,6 @@ class MessageStore : public TransactionalStore, public Recoverable {
public:
/**
- * If called after initialization but before recovery, will discard the database
- * content and reinitialize as though it were a new installation. If the parameter
- * saveStoreContent is true, the content of the store will be saved in such a way
- * that the truncate can be reversed. This is used when cluster nodes recover and
- * must get their content from a cluster sync rather than directly from the store.
- *
- * @param saveStoreContent If true, will move content of the store to a backup
- * location where they may be restored later if needed. It is
- * not necessary to save more than one prior version of the
- * store.
- */
- virtual void truncateInit(const bool saveStoreContent = false) = 0;
-
- /**
* Record the existence of a durable queue
*/
virtual void create(PersistableQueue& queue,
diff --git a/cpp/src/qpid/broker/MessageStoreModule.cpp b/cpp/src/qpid/broker/MessageStoreModule.cpp
index 4309ee8524..9214f5a732 100644
--- a/cpp/src/qpid/broker/MessageStoreModule.cpp
+++ b/cpp/src/qpid/broker/MessageStoreModule.cpp
@@ -44,11 +44,6 @@ MessageStoreModule::~MessageStoreModule()
bool MessageStoreModule::init(const Options*) { return true; }
-void MessageStoreModule::truncateInit(const bool pushDownStoreFiles)
-{
- TRANSFER_EXCEPTION(store->truncateInit(pushDownStoreFiles));
-}
-
void MessageStoreModule::create(PersistableQueue& queue, const FieldTable& args)
{
TRANSFER_EXCEPTION(store->create(queue, args));
diff --git a/cpp/src/qpid/broker/MessageStoreModule.h b/cpp/src/qpid/broker/MessageStoreModule.h
index e5c271f4fa..89d6ebdecb 100644
--- a/cpp/src/qpid/broker/MessageStoreModule.h
+++ b/cpp/src/qpid/broker/MessageStoreModule.h
@@ -44,7 +44,6 @@ class MessageStoreModule : public MessageStore
MessageStoreModule(boost::shared_ptr<MessageStore>& store);
bool init(const Options* options);
- void truncateInit(const bool pushDownStoreFiles = false);
std::auto_ptr<TransactionContext> begin();
std::auto_ptr<TPCTransactionContext> begin(const std::string& xid);
void prepare(TPCTransactionContext& txn);
diff --git a/cpp/src/qpid/broker/Messages.h b/cpp/src/qpid/broker/Messages.h
index a94ac7e0bf..cd846a4973 100644
--- a/cpp/src/qpid/broker/Messages.h
+++ b/cpp/src/qpid/broker/Messages.h
@@ -91,13 +91,6 @@ class Messages
virtual Message* find(const QueueCursor&) = 0;
/**
- * Add an already acquired message to the queue.
- * Used by a cluster updatee to replicate acquired messages from the updater.
- * Only need be implemented by subclasses that keep track of
- * acquired messages.
- */
- //virtual void updateAcquired(const QueuedMessage&) { }
- /**
* Apply, the functor to each message held
*/
virtual void foreach(Functor) = 0;
diff --git a/cpp/src/qpid/broker/NullMessageStore.cpp b/cpp/src/qpid/broker/NullMessageStore.cpp
index 209941875a..a038c4db63 100644
--- a/cpp/src/qpid/broker/NullMessageStore.cpp
+++ b/cpp/src/qpid/broker/NullMessageStore.cpp
@@ -54,8 +54,6 @@ NullMessageStore::NullMessageStore() : nextPersistenceId(1) {}
bool NullMessageStore::init(const Options* /*options*/) {return true;}
-void NullMessageStore::truncateInit(const bool /*pushDownStoreFiles*/) {}
-
void NullMessageStore::create(PersistableQueue& queue, const framing::FieldTable& /*args*/)
{
queue.setPersistenceId(nextPersistenceId++);
diff --git a/cpp/src/qpid/broker/NullMessageStore.h b/cpp/src/qpid/broker/NullMessageStore.h
index 799bf6b368..4b108e0331 100644
--- a/cpp/src/qpid/broker/NullMessageStore.h
+++ b/cpp/src/qpid/broker/NullMessageStore.h
@@ -47,7 +47,6 @@ class QPID_BROKER_CLASS_EXTERN NullMessageStore : public MessageStore
QPID_BROKER_EXTERN NullMessageStore();
QPID_BROKER_EXTERN virtual bool init(const Options* options);
- QPID_BROKER_EXTERN virtual void truncateInit(const bool pushDownStoreFiles = false);
QPID_BROKER_EXTERN virtual std::auto_ptr<TransactionContext> begin();
QPID_BROKER_EXTERN virtual std::auto_ptr<TPCTransactionContext> begin(const std::string& xid);
QPID_BROKER_EXTERN virtual void prepare(TPCTransactionContext& txn);
diff --git a/cpp/src/qpid/broker/Protocol.cpp b/cpp/src/qpid/broker/Protocol.cpp
new file mode 100644
index 0000000000..e236698142
--- /dev/null
+++ b/cpp/src/qpid/broker/Protocol.cpp
@@ -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.
+ *
+ */
+#include "Protocol.h"
+#include "qpid/sys/ConnectionCodec.h"
+#include "qpid/broker/amqp_0_10/MessageTransfer.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace broker {
+
+qpid::sys::ConnectionCodec* ProtocolRegistry::create(const qpid::framing::ProtocolVersion& v, qpid::sys::OutputControl& o, const std::string& id, const qpid::sys::SecuritySettings& s)
+{
+ qpid::sys::ConnectionCodec* codec = 0;
+ for (Protocols::const_iterator i = protocols.begin(); !codec && i != protocols.end(); ++i) {
+ codec = i->second->create(v, o, id, s);
+ }
+ return codec;
+}
+boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> ProtocolRegistry::translate(const Message& m)
+{
+ boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> transfer;
+ const qpid::broker::amqp_0_10::MessageTransfer* ptr = dynamic_cast<const qpid::broker::amqp_0_10::MessageTransfer*>(&m.getEncoding());
+ if (ptr) transfer = boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer>(ptr);
+ for (Protocols::const_iterator i = protocols.begin(); !transfer && i != protocols.end(); ++i) {
+ transfer = i->second->translate(m);
+ }
+ if (!transfer) throw new Exception("Could not convert message into 0-10");
+ return transfer;
+}
+boost::shared_ptr<RecoverableMessage> ProtocolRegistry::recover(qpid::framing::Buffer& b)
+{
+ boost::shared_ptr<RecoverableMessage> msg;
+ for (Protocols::const_iterator i = protocols.begin(); !msg && i != protocols.end(); ++i) {
+ msg = i->second->recover(b);
+ }
+ return msg;
+}
+
+ProtocolRegistry::~ProtocolRegistry()
+{
+ for (Protocols::const_iterator i = protocols.begin(); i != protocols.end(); ++i) {
+ delete i->second;
+ }
+ protocols.clear();
+}
+void ProtocolRegistry::add(const std::string& key, Protocol* protocol)
+{
+ protocols[key] = protocol;
+ QPID_LOG(info, "Loaded protocol " << key);
+}
+
+}} // namespace qpid::broker
diff --git a/cpp/src/qpid/broker/Protocol.h b/cpp/src/qpid/broker/Protocol.h
new file mode 100644
index 0000000000..2f268748fb
--- /dev/null
+++ b/cpp/src/qpid/broker/Protocol.h
@@ -0,0 +1,82 @@
+#ifndef QPID_BROKER_PROTOCOL_H
+#define QPID_BROKER_PROTOCOL_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <map>
+#include <string>
+#include <boost/shared_ptr.hpp>
+#include <boost/intrusive_ptr.hpp>
+
+namespace qpid {
+namespace sys {
+class ConnectionCodec;
+class OutputControl;
+struct SecuritySettings;
+}
+namespace framing {
+class Buffer;
+class ProtocolVersion;
+}
+namespace broker {
+class Message;
+class RecoverableMessage;
+namespace amqp_0_10 {
+class MessageTransfer;
+}
+
+/**
+ * A simple abstraction allowing pluggable protocol(s)
+ * (versions). AMQP 0-10 is considered the default. Alternatives must
+ * provide a ConnectionCodec for encoding/decoding the protocol in
+ * full, a means of translating the native message format of that
+ * protocol into AMQP 0-10 and a means of recovering durable messages
+ * from disk.
+ */
+class Protocol
+{
+ public:
+ virtual ~Protocol() {}
+ virtual qpid::sys::ConnectionCodec* create(const qpid::framing::ProtocolVersion&, qpid::sys::OutputControl&, const std::string&, const qpid::sys::SecuritySettings&) = 0;
+ virtual boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> translate(const Message&) = 0;
+ virtual boost::shared_ptr<RecoverableMessage> recover(qpid::framing::Buffer&) = 0;
+
+ private:
+};
+
+class ProtocolRegistry : public Protocol
+{
+ public:
+ qpid::sys::ConnectionCodec* create(const qpid::framing::ProtocolVersion&, qpid::sys::OutputControl&, const std::string&, const qpid::sys::SecuritySettings&);
+ boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> translate(const Message&);
+ boost::shared_ptr<RecoverableMessage> recover(qpid::framing::Buffer&);
+
+ ~ProtocolRegistry();
+ void add(const std::string&, Protocol*);
+ private:
+ //name may be useful for descriptive purposes or even for some
+ //limited manipulation of ordering
+ typedef std::map<std::string, Protocol*> Protocols;
+ Protocols protocols;
+};
+}} // namespace qpid::broker
+
+#endif /*!QPID_BROKER_PROTOCOL_H*/
diff --git a/cpp/src/qpid/broker/Queue.cpp b/cpp/src/qpid/broker/Queue.cpp
index f595b81724..bab6f2ea55 100644
--- a/cpp/src/qpid/broker/Queue.cpp
+++ b/cpp/src/qpid/broker/Queue.cpp
@@ -44,9 +44,9 @@
#include "qpid/framing/reply_exceptions.h"
#include "qpid/framing/FieldTable.h"
#include "qpid/framing/FieldValue.h"
-#include "qpid/sys/ClusterSafe.h"
#include "qpid/sys/Monitor.h"
#include "qpid/sys/Time.h"
+#include "qpid/sys/Timer.h"
#include "qpid/types/Variant.h"
#include "qmf/org/apache/qpid/broker/ArgsQueuePurge.h"
#include "qmf/org/apache/qpid/broker/ArgsQueueReroute.h"
@@ -79,8 +79,8 @@ namespace
{
inline void mgntEnqStats(const Message& msg,
- _qmf::Queue* mgmtObject,
- _qmf::Broker* brokerMgmtObject)
+ _qmf::Queue::shared_ptr mgmtObject,
+ _qmf::Broker::shared_ptr brokerMgmtObject)
{
if (mgmtObject != 0) {
_qmf::Queue::PerThreadStats *qStats = mgmtObject->getStatistics();
@@ -103,8 +103,8 @@ inline void mgntEnqStats(const Message& msg,
}
inline void mgntDeqStats(const Message& msg,
- _qmf::Queue* mgmtObject,
- _qmf::Broker* brokerMgmtObject)
+ _qmf::Queue::shared_ptr mgmtObject,
+ _qmf::Broker::shared_ptr brokerMgmtObject)
{
if (mgmtObject != 0){
_qmf::Queue::PerThreadStats *qStats = mgmtObject->getStatistics();
@@ -166,13 +166,11 @@ void Queue::TxPublish::rollback() throw()
}
Queue::Queue(const string& _name, const QueueSettings& _settings,
-// MessageStore* const _store,
AsyncStore* const _asyncStore,
Manageable* parent,
Broker* b) :
name(_name),
-// store(_store),
asyncStore(_asyncStore),
owner(0),
consumerCount(0),
@@ -183,8 +181,6 @@ Queue::Queue(const string& _name, const QueueSettings& _settings,
messages(new MessageDeque()),
persistenceId(0),
settings(b ? merge(_settings, b->getOptions()) : _settings),
- mgmtObject(0),
- brokerMgmtObject(0),
eventMode(0),
broker(b),
deleted(false),
@@ -199,27 +195,24 @@ Queue::Queue(const string& _name, const QueueSettings& _settings,
qpid::amqp_0_10::translate(settings.asMap(), encodableSettings);
if (parent != 0 && broker != 0) {
ManagementAgent* agent = broker->getManagementAgent();
-
if (agent != 0) {
-// mgmtObject = new _qmf::Queue(agent, this, parent, _name, _store != 0, settings.autodelete);
- mgmtObject = new _qmf::Queue(agent, this, parent, _name, _asyncStore != 0, settings.autodelete);
+ mgmtObject = _qmf::Queue::shared_ptr(
+ new _qmf::Queue(agent, this, parent, _name, _asyncStore != 0, settings.autodelete));
mgmtObject->set_arguments(settings.asMap());
-// agent->addObject(mgmtObject, 0, store != 0);
agent->addObject(mgmtObject, 0, asyncStore != 0);
- brokerMgmtObject = (qmf::org::apache::qpid::broker::Broker*) broker->GetManagementObject();
+ brokerMgmtObject = boost::dynamic_pointer_cast<_qmf::Broker>(broker->GetManagementObject());
if (brokerMgmtObject)
brokerMgmtObject->inc_queueCount();
}
}
+
+ if ( settings.isBrowseOnly ) {
+ QPID_LOG ( info, "Queue " << name << " is browse-only." );
+ }
}
Queue::~Queue()
{
- if (mgmtObject != 0) {
- mgmtObject->resourceDestroy();
- if (brokerMgmtObject)
- brokerMgmtObject->dec_queueCount();
- }
}
bool isLocalTo(const OwnershipToken* token, const Message& msg)
@@ -246,9 +239,6 @@ void Queue::deliver(Message msg, TxBuffer* txn){
//'link' for whatever protocol is used; that would let protocol
//specific stuff be kept out the queue
- // Check for deferred delivery in a cluster.
- if (broker && broker->deferDelivery(name, msg))
- return;
if (broker::amqp_0_10::MessageTransfer::isImmediateDeliveryRequired(msg) && getConsumerCount() == 0) {
if (alternateExchange) {
DeliverableMessage deliverable(msg, 0);
@@ -307,7 +297,6 @@ void Queue::process(Message& msg)
void Queue::release(const QueueCursor& position, bool markRedelivered)
{
- assertClusterSafe();
QueueListeners::NotificationSet copy;
{
Mutex::ScopedLock locker(messageLock);
@@ -333,7 +322,6 @@ bool Queue::dequeueMessageAt(const SequenceNumber& position)
boost::intrusive_ptr<PersistableMessage> pmsg;
{
Mutex::ScopedLock locker(messageLock);
- assertClusterSafe();
QPID_LOG(debug, "Attempting to dequeue message at " << position);
QueueCursor cursor;
Message* msg = messages->find(position, &cursor);
@@ -353,7 +341,6 @@ bool Queue::dequeueMessageAt(const SequenceNumber& position)
bool Queue::acquire(const QueueCursor& position, const std::string& consumer)
{
Mutex::ScopedLock locker(messageLock);
- assertClusterSafe();
Message* msg;
msg = messages->find(position);
@@ -375,12 +362,13 @@ bool Queue::acquire(const QueueCursor& position, const std::string& consumer)
bool Queue::getNextMessage(Message& m, Consumer::shared_ptr& c)
{
- checkNotDeleted(c);
+ if (!checkNotDeleted(c)) return false;
QueueListeners::NotificationSet set;
while (true) {
//TODO: reduce lock scope
Mutex::ScopedLock locker(messageLock);
- Message* msg = messages->next(*c);
+ QueueCursor cursor = c->getCursor(); // Save current position.
+ Message* msg = messages->next(*c); // Advances c.
if (msg) {
if (msg->hasExpired()) {
QPID_LOG(debug, "Message expired from queue '" << name << "'");
@@ -419,6 +407,7 @@ bool Queue::getNextMessage(Message& m, Consumer::shared_ptr& c)
} else {
//message(s) are available but consumer hasn't got enough credit
QPID_LOG(debug, "Consumer can't currently accept message from '" << name << "'");
+ c->setCursor(cursor); // Restore cursor, will try again with credit
if (c->preAcquires()) {
//let someone else try
listeners.populate(set);
@@ -480,7 +469,6 @@ bool Queue::find(SequenceNumber pos, Message& msg) const
void Queue::consume(Consumer::shared_ptr c, bool requestExclusive)
{
- assertClusterSafe();
{
Mutex::ScopedLock locker(messageLock);
// NOTE: consumerCount is actually a count of all
@@ -488,6 +476,11 @@ void Queue::consume(Consumer::shared_ptr c, bool requestExclusive)
// Check for exclusivity of acquiring consumers.
size_t acquiringConsumers = consumerCount - browserCount;
if (c->preAcquires()) {
+ if(settings.isBrowseOnly) {
+ throw NotAllowedException(
+ QPID_MSG("Queue " << name << " is browse only. Refusing acquiring consumer."));
+ }
+
if(exclusive) {
throw ResourceLockedException(
QPID_MSG("Queue " << getName()
@@ -502,22 +495,29 @@ void Queue::consume(Consumer::shared_ptr c, bool requestExclusive)
}
}
}
- else
+ else if(c->isCounted()) {
browserCount++;
- consumerCount++;
- //reset auto deletion timer if necessary
- if (settings.autoDeleteDelay && autoDeleteTask) {
- autoDeleteTask->cancel();
}
- observeConsumerAdd(*c, locker);
+ if(c->isCounted()) {
+ consumerCount++;
+
+ //reset auto deletion timer if necessary
+ if (settings.autoDeleteDelay && autoDeleteTask) {
+ autoDeleteTask->cancel();
+ }
+
+ observeConsumerAdd(*c, locker);
+ }
+ }
+ if (mgmtObject != 0 && c->isCounted()) {
+ mgmtObject->inc_consumerCount();
}
- if (mgmtObject != 0)
- mgmtObject->inc_consumerCount ();
}
void Queue::cancel(Consumer::shared_ptr c)
{
removeListener(c);
+ if(c->isCounted())
{
Mutex::ScopedLock locker(messageLock);
consumerCount--;
@@ -525,8 +525,9 @@ void Queue::cancel(Consumer::shared_ptr c)
if(exclusive) exclusive = 0;
observeConsumerRemove(*c, locker);
}
- if (mgmtObject != 0)
- mgmtObject->dec_consumerCount ();
+ if (mgmtObject != 0 && c->isCounted()) {
+ mgmtObject->dec_consumerCount();
+ }
}
/**
@@ -733,7 +734,6 @@ uint32_t Queue::move(const Queue::shared_ptr destq, uint32_t qty,
void Queue::push(Message& message, bool /*isRecovery*/)
{
- assertClusterSafe();
QueueListeners::NotificationSet copy;
{
Mutex::ScopedLock locker(messageLock);
@@ -1101,8 +1101,16 @@ void Queue::destroyed()
notifyDeleted();
{
Mutex::ScopedLock lock(messageLock);
+ for_each(observers.begin(), observers.end(),
+ boost::bind(&QueueObserver::destroy, _1));
observers.clear();
}
+
+ if (mgmtObject != 0) {
+ mgmtObject->resourceDestroy();
+ if (brokerMgmtObject)
+ brokerMgmtObject->dec_queueCount();
+ }
}
void Queue::notifyDeleted()
@@ -1136,7 +1144,7 @@ void Queue::setPersistenceId(uint64_t _persistenceId) const
{
if (mgmtObject != 0 && persistenceId == 0 && externalQueueStore)
{
- ManagementObject* childObj = externalQueueStore->GetManagementObject();
+ ManagementObject::shared_ptr childObj = externalQueueStore->GetManagementObject();
if (childObj != 0)
childObj->setReference(mgmtObject->getObjectId());
}
@@ -1180,6 +1188,7 @@ Queue::shared_ptr Queue::restore( QueueRegistry& queues, Buffer& buffer )
void Queue::setAlternateExchange(boost::shared_ptr<Exchange> exchange)
{
alternateExchange = exchange;
+ alternateExchange->incAlternateUsers();
if (mgmtObject) {
if (exchange.get() != 0)
mgmtObject->set_altExchange(exchange->GetManagementObject()->getObjectId());
@@ -1197,14 +1206,10 @@ void tryAutoDeleteImpl(Broker& broker, Queue::shared_ptr queue, const std::strin
{
if (broker.getQueues().destroyIf(queue->getName(),
boost::bind(boost::mem_fn(&Queue::canAutoDelete), queue))) {
- QPID_LOG(debug, "Auto-deleting " << queue->getName());
- queue->destroyed();
-
- if (broker.getManagementAgent())
- broker.getManagementAgent()->raiseEvent(_qmf::EventQueueDelete(connectionId, userId, queue->getName()));
- QPID_LOG_CAT(debug, model, "Delete queue. name:" << queue->getName()
+ QPID_LOG_CAT(debug, model, "Auto-delete queue: " << queue->getName()
<< " user:" << userId
<< " rhost:" << connectionId );
+ queue->destroyed();
}
}
@@ -1233,7 +1238,7 @@ void Queue::tryAutoDelete(Broker& broker, Queue::shared_ptr queue, const std::st
if (queue->settings.autoDeleteDelay && queue->canAutoDelete()) {
AbsTime time(now(), Duration(queue->settings.autoDeleteDelay * TIME_SEC));
queue->autoDeleteTask = boost::intrusive_ptr<qpid::sys::TimerTask>(new AutoDeleteTask(broker, queue, connectionId, userId, time));
- broker.getClusterTimer().add(queue->autoDeleteTask);
+ broker.getTimer().add(queue->autoDeleteTask);
QPID_LOG(debug, "Timed auto-delete for " << queue->getName() << " initiated");
} else {
tryAutoDeleteImpl(broker, queue, connectionId, userId);
@@ -1290,7 +1295,7 @@ void Queue::setExternalQueueStore(ExternalQueueStore* inst) {
externalQueueStore = inst;
if (inst) {
- ManagementObject* childObj = inst->GetManagementObject();
+ ManagementObject::shared_ptr childObj = inst->GetManagementObject();
if (childObj != 0 && mgmtObject != 0)
childObj->setReference(mgmtObject->getObjectId());
}
@@ -1378,9 +1383,9 @@ void Queue::countLoadedFromDisk(uint64_t size) const
}
-ManagementObject* Queue::GetManagementObject (void) const
+ManagementObject::shared_ptr Queue::GetManagementObject(void) const
{
- return (ManagementObject*) mgmtObject;
+ return mgmtObject;
}
Manageable::status_t Queue::ManagementMethod (uint32_t methodId, Args& args, string& etext)
@@ -1459,6 +1464,16 @@ SequenceNumber Queue::getPosition() {
return sequence;
}
+void Queue::getRange(framing::SequenceNumber& front, framing::SequenceNumber& back,
+ SubscriptionType type)
+{
+ Mutex::ScopedLock locker(messageLock);
+ QueueCursor cursor(type);
+ back = sequence;
+ Message* message = messages->next(cursor);
+ front = message ? message->getSequence() : back+1;
+}
+
int Queue::getEventMode() { return eventMode; }
void Queue::recoveryComplete(ExchangeRegistry& exchanges)
@@ -1493,20 +1508,11 @@ void Queue::observeEnqueue(const Message& m, const Mutex::ScopedLock&)
mgntEnqStats(m, mgmtObject, brokerMgmtObject);
}
-// Note: accessing listeners outside of lock is dangerous. Caller must ensure the queue's
-// state is not changed while listeners is referenced.
-QueueListeners& Queue::getListeners() { return listeners; }
-
-// Note: accessing messages outside of lock is dangerous. Caller must ensure the queue's
-// state is not changed while messages is referenced.
-Messages& Queue::getMessages() { return *messages; }
-const Messages& Queue::getMessages() const { return *messages; }
-
-void Queue::checkNotDeleted(const Consumer::shared_ptr& c)
+bool Queue::checkNotDeleted(const Consumer::shared_ptr& c)
{
- if (deleted && !c->hideDeletedError()) {
+ if (deleted && !c->hideDeletedError())
throw ResourceDeletedException(QPID_MSG("Queue " << getName() << " has been deleted."));
- }
+ return !deleted;
}
void Queue::addObserver(boost::shared_ptr<QueueObserver> observer)
@@ -1641,7 +1647,7 @@ Queue::UsageBarrier::UsageBarrier(Queue& q) : parent(q), count(0) {}
bool Queue::UsageBarrier::acquire()
{
- Monitor::ScopedLock l(parent.messageLock); /** @todo: use a dedicated lock instead of messageLock */
+ Monitor::ScopedLock l(usageLock);
if (parent.deleted) {
return false;
} else {
@@ -1652,15 +1658,20 @@ bool Queue::UsageBarrier::acquire()
void Queue::UsageBarrier::release()
{
- Monitor::ScopedLock l(parent.messageLock);
- if (--count == 0) parent.messageLock.notifyAll();
+ Monitor::ScopedLock l(usageLock);
+ if (--count == 0) usageLock.notifyAll();
}
void Queue::UsageBarrier::destroy()
{
- Monitor::ScopedLock l(parent.messageLock);
+ Monitor::ScopedLock l(usageLock);
parent.deleted = true;
- while (count) parent.messageLock.wait();
+ while (count) usageLock.wait();
+}
+
+void Queue::addArgument(const string& key, const types::Variant& value) {
+ settings.original.insert(types::Variant::Map::value_type(key, value));
+ if (mgmtObject != 0) mgmtObject->set_arguments(settings.asMap());
}
}}
diff --git a/cpp/src/qpid/broker/Queue.h b/cpp/src/qpid/broker/Queue.h
index 1294f813aa..bb713eba2b 100644
--- a/cpp/src/qpid/broker/Queue.h
+++ b/cpp/src/qpid/broker/Queue.h
@@ -38,7 +38,6 @@
#include "qpid/framing/SequenceNumber.h"
#include "qpid/sys/AtomicValue.h"
#include "qpid/sys/Monitor.h"
-#include "qpid/sys/Timer.h"
#include "qpid/management/Manageable.h"
#include "qmf/org/apache/qpid/broker/Queue.h"
#include "qmf/org/apache/qpid/broker/Broker.h"
@@ -56,6 +55,9 @@
#include <algorithm>
namespace qpid {
+namespace sys {
+class TimerTask;
+}
namespace broker {
class Broker;
class Exchange;
@@ -83,6 +85,7 @@ class Queue : public boost::enable_shared_from_this<Queue>,
{
Queue& parent;
uint count;
+ qpid::sys::Monitor usageLock;
UsageBarrier(Queue&);
bool acquire();
@@ -142,18 +145,18 @@ class Queue : public boost::enable_shared_from_this<Queue>,
* o consumerCount (TBD: move under separate lock)
* o Queue::UsageBarrier (TBD: move under separate lock)
*/
- mutable qpid::sys::Monitor messageLock;
+ mutable qpid::sys::Mutex messageLock;
mutable qpid::sys::Mutex ownershipLock;
mutable uint64_t persistenceId;
- const QueueSettings settings;
+ QueueSettings settings;
qpid::framing::FieldTable encodableSettings;
QueueDepth current;
QueueBindings bindings;
std::string alternateExchangeName;
boost::shared_ptr<Exchange> alternateExchange;
framing::SequenceNumber sequence;
- qmf::org::apache::qpid::broker::Queue* mgmtObject;
- qmf::org::apache::qpid::broker::Broker* brokerMgmtObject;
+ qmf::org::apache::qpid::broker::Queue::shared_ptr mgmtObject;
+ qmf::org::apache::qpid::broker::Broker::shared_ptr brokerMgmtObject;
sys::AtomicValue<uint32_t> dequeueSincePurge; // Count dequeues since last purge.
int eventMode;
Observers observers;
@@ -189,7 +192,7 @@ class Queue : public boost::enable_shared_from_this<Queue>,
int getEventMode();
void dequeueFromStore(boost::intrusive_ptr<PersistableMessage>);
void abandoned(const Message& message);
- void checkNotDeleted(const Consumer::shared_ptr&);
+ bool checkNotDeleted(const Consumer::shared_ptr&);
void notifyDeleted();
uint32_t remove(uint32_t maxCount, MessagePredicate, MessageFunctor, SubscriptionType);
virtual bool checkDepth(const QueueDepth& increment, const Message&);
@@ -338,7 +341,7 @@ class Queue : public boost::enable_shared_from_this<Queue>,
* exclusive owner
*/
static Queue::shared_ptr restore(QueueRegistry& queues, framing::Buffer& buffer);
- static void tryAutoDelete(Broker& broker, Queue::shared_ptr, const std::string& connectionId, const std::string& userId);
+ QPID_BROKER_EXTERN static void tryAutoDelete(Broker& broker, Queue::shared_ptr, const std::string& connectionId, const std::string& userId);
virtual void setExternalQueueStore(ExternalQueueStore* inst);
@@ -352,7 +355,7 @@ class Queue : public boost::enable_shared_from_this<Queue>,
QPID_BROKER_EXTERN void countLoadedFromDisk(uint64_t size) const;
// Manageable entry points
- QPID_BROKER_EXTERN management::ManagementObject* GetManagementObject (void) const;
+ QPID_BROKER_EXTERN management::ManagementObject::shared_ptr GetManagementObject(void) const;
management::Manageable::status_t
QPID_BROKER_EXTERN ManagementMethod (uint32_t methodId, management::Args& args, std::string& text);
QPID_BROKER_EXTERN void query(::qpid::types::Variant::Map&) const;
@@ -382,15 +385,30 @@ class Queue : public boost::enable_shared_from_this<Queue>,
*
* The _caller_ must ensure that any messages after pos have been dequeued.
*
- * Used by HA/cluster code for queue replication.
+ * Used by HA code for queue replication.
*/
QPID_BROKER_EXTERN void setPosition(framing::SequenceNumber pos);
/**
*@return sequence number for the back of the queue. The next message pushed
- * will be at getPosition+1
+ * will be at getPosition()+1
*/
QPID_BROKER_EXTERN framing::SequenceNumber getPosition();
+
+ /**
+ * Set front and back.
+ * If the queue is empty then front = back+1 (the first message to
+ * consume will be the next message pushed.)
+ *
+ *@param front = Position of first message to consume.
+ *@param back = getPosition(), next message pushed will be getPosition()+1
+ *@param type Subscription type to use to determine the front.
+ */
+ QPID_BROKER_EXTERN void getRange(
+ framing::SequenceNumber& front, framing::SequenceNumber& back,
+ SubscriptionType type=CONSUMER
+ );
+
QPID_BROKER_EXTERN void addObserver(boost::shared_ptr<QueueObserver>);
QPID_BROKER_EXTERN void removeObserver(boost::shared_ptr<QueueObserver>);
QPID_BROKER_EXTERN void insertSequenceNumbers(const std::string& key);
@@ -399,11 +417,6 @@ class Queue : public boost::enable_shared_from_this<Queue>,
*/
QPID_BROKER_EXTERN void recoveryComplete(ExchangeRegistry& exchanges);
- // For cluster update
- QPID_BROKER_EXTERN QueueListeners& getListeners();
- QPID_BROKER_EXTERN Messages& getMessages();
- QPID_BROKER_EXTERN const Messages& getMessages() const;
-
/**
* Reserve space in policy for an enqueued message that
* has been recovered in the prepared state (dtx only)
@@ -420,6 +433,10 @@ class Queue : public boost::enable_shared_from_this<Queue>,
uint32_t getDequeueSincePurge() { return dequeueSincePurge.get(); }
QPID_BROKER_EXTERN void setDequeueSincePurge(uint32_t value);
+
+ /** Add an argument to be included in management messages about this queue. */
+ QPID_BROKER_EXTERN void addArgument(const std::string& key, const types::Variant& value);
+
friend class QueueFactory;
};
}
diff --git a/cpp/src/qpid/broker/QueueCleaner.cpp b/cpp/src/qpid/broker/QueueCleaner.cpp
index 838bc28be8..8d9e3f43dd 100644
--- a/cpp/src/qpid/broker/QueueCleaner.cpp
+++ b/cpp/src/qpid/broker/QueueCleaner.cpp
@@ -18,15 +18,36 @@
* under the License.
*
*/
-#include "qpid/broker/Queue.h"
#include "qpid/broker/QueueCleaner.h"
#include "qpid/broker/Broker.h"
+#include "qpid/broker/Queue.h"
+#include "qpid/sys/Timer.h"
+
+#include <boost/function.hpp>
#include <boost/bind.hpp>
namespace qpid {
namespace broker {
+namespace {
+ typedef boost::function0<void> FireFunction;
+ class Task : public sys::TimerTask
+ {
+ public:
+ Task(FireFunction f, sys::Duration duration);
+ void fire();
+ private:
+ FireFunction fireFunction;
+ };
+
+ Task::Task(FireFunction f, qpid::sys::Duration d) : sys::TimerTask(d,"QueueCleaner"), fireFunction(f) {}
+
+ void Task::fire()
+ {
+ fireFunction();
+ }
+}
QueueCleaner::QueueCleaner(QueueRegistry& q, sys::Timer* t) : queues(q), timer(t) {}
QueueCleaner::~QueueCleaner()
@@ -37,7 +58,7 @@ QueueCleaner::~QueueCleaner()
void QueueCleaner::start(qpid::sys::Duration p)
{
period = p;
- task = new Task(*this, p);
+ task = new Task(boost::bind(&QueueCleaner::fired, this), p);
timer->add(task);
}
@@ -45,14 +66,6 @@ void QueueCleaner::setTimer(qpid::sys::Timer* timer) {
this->timer = timer;
}
-
-QueueCleaner::Task::Task(QueueCleaner& p, qpid::sys::Duration d) : sys::TimerTask(d,"QueueCleaner"), parent(p) {}
-
-void QueueCleaner::Task::fire()
-{
- parent.fired();
-}
-
namespace {
struct CollectQueues
{
diff --git a/cpp/src/qpid/broker/QueueCleaner.h b/cpp/src/qpid/broker/QueueCleaner.h
index ffebfe3e1b..896af1dcd5 100644
--- a/cpp/src/qpid/broker/QueueCleaner.h
+++ b/cpp/src/qpid/broker/QueueCleaner.h
@@ -23,9 +23,17 @@
*/
#include "qpid/broker/BrokerImportExport.h"
-#include "qpid/sys/Timer.h"
+#include "qpid/sys/Time.h"
+
+#include <boost/intrusive_ptr.hpp>
namespace qpid {
+
+namespace sys {
+ class Timer;
+ class TimerTask;
+}
+
namespace broker {
class QueueRegistry;
@@ -39,16 +47,8 @@ class QueueCleaner
QPID_BROKER_EXTERN ~QueueCleaner();
QPID_BROKER_EXTERN void start(sys::Duration period);
QPID_BROKER_EXTERN void setTimer(sys::Timer* timer);
- private:
- class Task : public sys::TimerTask
- {
- public:
- Task(QueueCleaner& parent, sys::Duration duration);
- void fire();
- private:
- QueueCleaner& parent;
- };
+ private:
boost::intrusive_ptr<sys::TimerTask> task;
QueueRegistry& queues;
sys::Timer* timer;
diff --git a/cpp/src/qpid/broker/QueueFlowLimit.cpp b/cpp/src/qpid/broker/QueueFlowLimit.cpp
index 11b9cbae63..9b2e31c925 100644
--- a/cpp/src/qpid/broker/QueueFlowLimit.cpp
+++ b/cpp/src/qpid/broker/QueueFlowLimit.cpp
@@ -29,7 +29,6 @@
#include "qpid/log/Statement.h"
#include "qpid/sys/Mutex.h"
#include "qpid/broker/SessionState.h"
-#include "qpid/sys/ClusterSafe.h"
#include "qmf/org/apache/qpid/broker/Queue.h"
@@ -66,10 +65,10 @@ namespace {
QueueFlowLimit::QueueFlowLimit(Queue *_queue,
uint32_t _flowStopCount, uint32_t _flowResumeCount,
uint64_t _flowStopSize, uint64_t _flowResumeSize)
- : StatefulQueueObserver(std::string("QueueFlowLimit")), queue(_queue), queueName("<unknown>"),
+ : queue(_queue), queueName("<unknown>"),
flowStopCount(_flowStopCount), flowResumeCount(_flowResumeCount),
flowStopSize(_flowStopSize), flowResumeSize(_flowResumeSize),
- flowStopped(false), count(0), size(0), queueMgmtObj(0), broker(0)
+ flowStopped(false), count(0), size(0), broker(0)
{
uint32_t maxCount(0);
uint64_t maxSize(0);
@@ -79,7 +78,7 @@ QueueFlowLimit::QueueFlowLimit(Queue *_queue,
if (queue->getSettings().maxDepth.hasCount()) maxCount = queue->getSettings().maxDepth.getCount();
if (queue->getSettings().maxDepth.hasCount()) maxSize = queue->getSettings().maxDepth.getSize();
broker = queue->getBroker();
- queueMgmtObj = dynamic_cast<_qmfBroker::Queue*> (queue->GetManagementObject());
+ queueMgmtObj = boost::dynamic_pointer_cast<_qmfBroker::Queue> (queue->GetManagementObject());
if (queueMgmtObj) {
queueMgmtObj->set_flowStopped(isFlowControlActive());
}
@@ -130,11 +129,6 @@ void QueueFlowLimit::enqueued(const Message& msg)
}
if (flowStopped || !index.empty()) {
- // ignore flow control if we are populating the queue due to cluster replication:
- if (broker && broker->isClusterUpdatee()) {
- QPID_LOG(trace, "Queue \"" << queueName << "\": ignoring flow control for msg pos=" << msg.getSequence());
- return;
- }
QPID_LOG(trace, "Queue \"" << queueName << "\": setting flow control for msg pos=" << msg.getSequence());
msg.getPersistentContext()->getIngressCompletion().startCompleter(); // don't complete until flow resumes
bool unique;
@@ -297,79 +291,8 @@ QueueFlowLimit *QueueFlowLimit::createLimit(Queue *queue, const QueueSettings& s
return 0;
}
-/* Cluster replication */
-
-namespace {
- /** pack a set of sequence number ranges into a framing::Array */
- void buildSeqRangeArray(qpid::framing::Array *seqs,
- const qpid::framing::SequenceNumber& first,
- const qpid::framing::SequenceNumber& last)
- {
- seqs->push_back(qpid::framing::Array::ValuePtr(new Unsigned32Value(first)));
- seqs->push_back(qpid::framing::Array::ValuePtr(new Unsigned32Value(last)));
- }
-}
-
-/** Runs on UPDATER to snapshot current state */
-void QueueFlowLimit::getState(qpid::framing::FieldTable& state ) const
-{
- sys::Mutex::ScopedLock l(indexLock);
- state.clear();
-
- framing::SequenceSet ss;
- if (!index.empty()) {
- /* replicate the set of messages pending flow control */
- for (std::map<framing::SequenceNumber, Message >::const_iterator itr = index.begin();
- itr != index.end(); ++itr) {
- ss.add(itr->first);
- }
- framing::Array seqs(TYPE_CODE_UINT32);
- typedef boost::function<void(framing::SequenceNumber, framing::SequenceNumber)> arrayBuilder;
- ss.for_each((arrayBuilder)boost::bind(&buildSeqRangeArray, &seqs, _1, _2));
- state.setArray("pendingMsgSeqs", seqs);
- }
- QPID_LOG(debug, "Queue \"" << queueName << "\": flow limit replicating pending msgs, range=" << ss);
-}
-
-
-/** called on UPDATEE to set state from snapshot */
-void QueueFlowLimit::setState(const qpid::framing::FieldTable& state)
-{
- sys::Mutex::ScopedLock l(indexLock);
- index.clear();
-
- framing::SequenceSet fcmsg;
- framing::Array seqArray(TYPE_CODE_UINT32);
- if (state.getArray("pendingMsgSeqs", seqArray)) {
- assert((seqArray.count() & 0x01) == 0); // must be even since they are sequence ranges
- framing::Array::const_iterator i = seqArray.begin();
- while (i != seqArray.end()) {
- framing::SequenceNumber first((*i)->getIntegerValue<uint32_t, 4>());
- ++i;
- framing::SequenceNumber last((*i)->getIntegerValue<uint32_t, 4>());
- ++i;
- fcmsg.add(first, last);
- for (SequenceNumber seq = first; seq <= last; ++seq) {
- Message msg;
- queue->find(seq, msg); // fyi: may not be found if msg is acquired & unacked
- bool unique;
- unique = index.insert(std::pair<framing::SequenceNumber, Message >(seq, msg)).second;
- // Like this to avoid tripping up unused variable warning when NDEBUG set
- if (!unique) assert(unique);
- }
- }
- }
-
- flowStopped = index.size() != 0;
- if (queueMgmtObj) {
- queueMgmtObj->set_flowStopped(isFlowControlActive());
- }
- QPID_LOG(debug, "Queue \"" << queueName << "\": flow limit replicated the pending msgs, range=" << fcmsg)
-}
-
-
namespace qpid {
- namespace broker {
+namespace broker {
std::ostream& operator<<(std::ostream& out, const QueueFlowLimit& f)
{
@@ -378,6 +301,6 @@ std::ostream& operator<<(std::ostream& out, const QueueFlowLimit& f)
return out;
}
- }
+}
}
diff --git a/cpp/src/qpid/broker/QueueFlowLimit.h b/cpp/src/qpid/broker/QueueFlowLimit.h
index 1bcc388ceb..b9aa09ec3a 100644
--- a/cpp/src/qpid/broker/QueueFlowLimit.h
+++ b/cpp/src/qpid/broker/QueueFlowLimit.h
@@ -26,19 +26,13 @@
#include <iostream>
#include <memory>
#include "qpid/broker/BrokerImportExport.h"
-#include "qpid/broker/StatefulQueueObserver.h"
+#include "qpid/broker/QueueObserver.h"
#include "qpid/framing/FieldTable.h"
#include "qpid/framing/SequenceNumber.h"
#include "qpid/sys/AtomicValue.h"
#include "qpid/sys/Mutex.h"
+#include "qmf/org/apache/qpid/broker/Queue.h"
-namespace qmf {
-namespace org {
-namespace apache {
-namespace qpid {
-namespace broker {
- class Queue;
-}}}}}
namespace _qmfBroker = qmf::org::apache::qpid::broker;
namespace qpid {
@@ -46,6 +40,7 @@ namespace broker {
class Broker;
class Queue;
+class Message;
struct QueueSettings;
/**
@@ -55,7 +50,7 @@ struct QueueSettings;
* passing _either_ level may turn flow control ON, but _both_ must be
* below level before flow control will be turned OFF.
*/
- class QueueFlowLimit : public StatefulQueueObserver
+ class QueueFlowLimit : public QueueObserver
{
static uint64_t defaultMaxSize;
static uint defaultFlowStopRatio;
@@ -90,10 +85,6 @@ struct QueueSettings;
QPID_BROKER_EXTERN void acquired(const Message&) {};
QPID_BROKER_EXTERN void requeued(const Message&) {};
- /** for clustering: */
- QPID_BROKER_EXTERN void getState(qpid::framing::FieldTable&) const;
- QPID_BROKER_EXTERN void setState(const qpid::framing::FieldTable&);
-
uint32_t getFlowStopCount() const { return flowStopCount; }
uint32_t getFlowResumeCount() const { return flowResumeCount; }
uint64_t getFlowStopSize() const { return flowStopSize; }
@@ -118,7 +109,7 @@ struct QueueSettings;
std::map<framing::SequenceNumber, Message > index;
mutable qpid::sys::Mutex indexLock;
- _qmfBroker::Queue *queueMgmtObj;
+ _qmfBroker::Queue::shared_ptr queueMgmtObj;
const Broker *broker;
diff --git a/cpp/src/qpid/broker/QueueObserver.h b/cpp/src/qpid/broker/QueueObserver.h
index 29e867253e..2ba98f6945 100644
--- a/cpp/src/qpid/broker/QueueObserver.h
+++ b/cpp/src/qpid/broker/QueueObserver.h
@@ -69,6 +69,7 @@ class QueueObserver
virtual void requeued(const Message&) = 0;
virtual void consumerAdded( const Consumer& ) {};
virtual void consumerRemoved( const Consumer& ) {};
+ virtual void destroy() {};
private:
};
}} // namespace qpid::broker
diff --git a/cpp/src/qpid/broker/QueueRegistry.cpp b/cpp/src/qpid/broker/QueueRegistry.cpp
index eb525b6727..2fdcf3b8e6 100644
--- a/cpp/src/qpid/broker/QueueRegistry.cpp
+++ b/cpp/src/qpid/broker/QueueRegistry.cpp
@@ -23,10 +23,14 @@
#include "qpid/broker/QueueRegistry.h"
#include "qpid/broker/Exchange.h"
#include "qpid/log/Statement.h"
+#include "qpid/management/ManagementAgent.h"
#include "qpid/framing/reply_exceptions.h"
+#include "qmf/org/apache/qpid/broker/EventQueueDeclare.h"
+#include "qmf/org/apache/qpid/broker/EventQueueDelete.h"
#include <sstream>
#include <assert.h>
+namespace _qmf = qmf::org::apache::qpid::broker;
using namespace qpid::broker;
using namespace qpid::sys;
using std::string;
@@ -44,7 +48,10 @@ QueueRegistry::declare(const string& name, const QueueSettings& settings,
bool recovering/*true if this declare is a
result of recovering queue
definition from persistent
- record*/)
+ record*/,
+ const OwnershipToken* owner,
+ std::string connectionId,
+ std::string userId)
{
std::pair<Queue::shared_ptr, bool> result;
{
@@ -53,25 +60,38 @@ QueueRegistry::declare(const string& name, const QueueSettings& settings,
if (i == queues.end()) {
Queue::shared_ptr queue = create(name, settings);
//Move this to factory also?
- if (alternate) {
+ if (alternate)
queue->setAlternateExchange(alternate);//need to do this *before* create
- alternate->incAlternateUsers();
- }
if (!recovering) {
//create persistent record if required
queue->create();
}
queues[name] = queue;
+ // NOTE: raiseEvent and queueCreate must be called with the lock held in
+ // order to ensure events are generated in the correct order.
+ // Call queueCreate before raiseEvents so it can add arguments that
+ // will be included in the management event.
+ if (getBroker()) getBroker()->getConfigurationObservers().queueCreate(queue);
result = std::pair<Queue::shared_ptr, bool>(queue, true);
} else {
result = std::pair<Queue::shared_ptr, bool>(i->second, false);
}
+ if (getBroker() && getBroker()->getManagementAgent()) {
+ getBroker()->getManagementAgent()->raiseEvent(
+ _qmf::EventQueueDeclare(
+ connectionId, userId, name,
+ settings.durable, owner, settings.autodelete,
+ alternate ? alternate->getName() : string(),
+ result.first->getSettings().asMap(),
+ result.second ? "created" : "existing"));
+ }
}
- if (getBroker() && result.second) getBroker()->getConfigurationObservers().queueCreate(result.first);
return result;
}
-void QueueRegistry::destroy(const string& name) {
+void QueueRegistry::destroy(
+ const string& name, const string& connectionId, const string& userId)
+{
Queue::shared_ptr q;
{
qpid::sys::RWlock::ScopedWlock locker(lock);
@@ -79,9 +99,17 @@ void QueueRegistry::destroy(const string& name) {
if (i != queues.end()) {
q = i->second;
queues.erase(i);
+ if (getBroker()) {
+ // NOTE: queueDestroy and raiseEvent must be called with the
+ // lock held in order to ensure events are generated
+ // in the correct order.
+ getBroker()->getConfigurationObservers().queueDestroy(q);
+ if (getBroker()->getManagementAgent())
+ getBroker()->getManagementAgent()->raiseEvent(
+ _qmf::EventQueueDelete(connectionId, userId, name));
+ }
}
}
- if (getBroker() && q) getBroker()->getConfigurationObservers().queueDestroy(q);
}
Queue::shared_ptr QueueRegistry::find(const string& name){
diff --git a/cpp/src/qpid/broker/QueueRegistry.h b/cpp/src/qpid/broker/QueueRegistry.h
index ada76f9cca..0170c441b3 100644
--- a/cpp/src/qpid/broker/QueueRegistry.h
+++ b/cpp/src/qpid/broker/QueueRegistry.h
@@ -59,7 +59,9 @@ class QueueRegistry : QueueFactory {
const std::string& name,
const QueueSettings& settings,
boost::shared_ptr<Exchange> alternateExchange = boost::shared_ptr<Exchange>(),
- bool recovering = false);
+ bool recovering = false,
+ const OwnershipToken* owner = 0,
+ std::string connectionId=std::string(), std::string userId=std::string());
/**
* Destroy the named queue.
@@ -73,7 +75,11 @@ class QueueRegistry : QueueFactory {
* subsequent calls to find or declare with the same name.
*
*/
- QPID_BROKER_EXTERN void destroy(const std::string& name);
+ QPID_BROKER_EXTERN void destroy(
+ const std::string& name,
+ const std::string& connectionId=std::string(),
+ const std::string& userId=std::string());
+
template <class Test> bool destroyIf(const std::string& name, Test test)
{
if (test()) {
diff --git a/cpp/src/qpid/broker/QueueSettings.cpp b/cpp/src/qpid/broker/QueueSettings.cpp
index 91616636f1..b92a81bcf3 100644
--- a/cpp/src/qpid/broker/QueueSettings.cpp
+++ b/cpp/src/qpid/broker/QueueSettings.cpp
@@ -33,10 +33,13 @@ namespace broker {
namespace {
const std::string MAX_COUNT("qpid.max_count");
const std::string MAX_SIZE("qpid.max_size");
+const std::string MAX_FILE_COUNT("qpid.file_count");
+const std::string MAX_FILE_SIZE("qpid.file_size");
const std::string POLICY_TYPE("qpid.policy_type");
const std::string POLICY_TYPE_REJECT("reject");
const std::string POLICY_TYPE_RING("ring");
const std::string NO_LOCAL("no-local");
+const std::string BROWSE_ONLY("qpid.browse-only");
const std::string TRACE_ID("qpid.trace.id");
const std::string TRACE_EXCLUDES("qpid.trace.exclude");
const std::string LVQ_KEY("qpid.last_value_queue_key");
@@ -74,12 +77,14 @@ const QueueSettings::Aliases QueueSettings::aliases;
QueueSettings::QueueSettings(bool d, bool a) :
durable(d),
autodelete(a),
+ isTemporary(false),
priorities(0),
defaultFairshare(0),
shareGroups(false),
addTimestamp(false),
dropMessagesAtLimit(false),
noLocal(false),
+ isBrowseOnly(false),
autoDeleteDelay(0),
alertRepeatInterval(60)
{}
@@ -106,6 +111,9 @@ bool QueueSettings::handle(const std::string& key, const qpid::types::Variant& v
} else if (key == NO_LOCAL) {
noLocal = value;
return true;
+ } else if (key == BROWSE_ONLY) {
+ isBrowseOnly = value;
+ return true;
} else if (key == TRACE_ID) {
traceId = value.asString();
return true;
@@ -163,6 +171,12 @@ bool QueueSettings::handle(const std::string& key, const qpid::types::Variant& v
} else if (key == ALERT_SIZE) {
alertThreshold.setSize(value);
return true;
+ } else if (key == MAX_FILE_COUNT && value.asUint64() > 0) {
+ maxFileCount = value.asUint64();
+ return false; // 'handle' here and also pass to store
+ } else if (key == MAX_FILE_SIZE && value.asUint64() > 0) {
+ maxFileSize = value.asUint64();
+ return false; // 'handle' here and also pass to store
} else {
return false;
}
diff --git a/cpp/src/qpid/broker/QueueSettings.h b/cpp/src/qpid/broker/QueueSettings.h
index 2443624615..62d34db5cb 100644
--- a/cpp/src/qpid/broker/QueueSettings.h
+++ b/cpp/src/qpid/broker/QueueSettings.h
@@ -43,6 +43,7 @@ struct QueueSettings
bool durable;
bool autodelete;
+ bool isTemporary;
//basic queue types:
std::string lvqKey;
@@ -59,6 +60,7 @@ struct QueueSettings
bool dropMessagesAtLimit;//aka ring queue policy
bool noLocal;
+ bool isBrowseOnly;
std::string traceId;
std::string traceExcludes;
uint64_t autoDeleteDelay;//queueTtl?
@@ -71,6 +73,10 @@ struct QueueSettings
QueueDepth alertThreshold;
int64_t alertRepeatInterval;
+ //file limits checked by Acl and shared with storeSettings
+ uint64_t maxFileSize;
+ uint64_t maxFileCount;
+
//yuck, yuck
qpid::framing::FieldTable storeSettings;
std::map<std::string, qpid::types::Variant> original;
diff --git a/cpp/src/qpid/broker/RecoverableExchange.h b/cpp/src/qpid/broker/RecoverableExchange.h
index 6bda1e2617..2302a7d925 100644
--- a/cpp/src/qpid/broker/RecoverableExchange.h
+++ b/cpp/src/qpid/broker/RecoverableExchange.h
@@ -45,6 +45,9 @@ public:
const std::string& routingKey,
qpid::framing::FieldTable&,
AsyncStore* const store) = 0;
+
+ virtual std::string getName() const = 0;
+
virtual ~RecoverableExchange() {};
};
diff --git a/cpp/src/qpid/broker/RecoverableMessage.h b/cpp/src/qpid/broker/RecoverableMessage.h
index c98857ceb0..aafcd756d5 100644
--- a/cpp/src/qpid/broker/RecoverableMessage.h
+++ b/cpp/src/qpid/broker/RecoverableMessage.h
@@ -22,12 +22,14 @@
*
*/
+#include <boost/intrusive_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include "qpid/framing/amqp_types.h"
#include "qpid/framing/Buffer.h"
namespace qpid {
namespace broker {
+class ExpiryPolicy;
/**
* The interface through which messages are reloaded on recovery.
@@ -38,6 +40,7 @@ public:
typedef boost::shared_ptr<RecoverableMessage> shared_ptr;
virtual void setPersistenceId(uint64_t id) = 0;
virtual void setRedelivered() = 0;
+ virtual void computeExpiration(const boost::intrusive_ptr<ExpiryPolicy>& e) = 0;
/**
* Used by store to determine whether to load content on recovery
* or let message load its own content as and when it requires it.
diff --git a/cpp/src/qpid/broker/RecoverableMessageImpl.h b/cpp/src/qpid/broker/RecoverableMessageImpl.h
new file mode 100644
index 0000000000..a46f5a3676
--- /dev/null
+++ b/cpp/src/qpid/broker/RecoverableMessageImpl.h
@@ -0,0 +1,49 @@
+#ifndef QPID_BROKER_RECOVERABLEMESSAGEIMPL_H
+#define QPID_BROKER_RECOVERABLEMESSAGEIMPL_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "RecoverableMessage.h"
+
+namespace qpid {
+namespace broker {
+class DtxBuffer;
+class Message;
+class Queue;
+
+class RecoverableMessageImpl : public RecoverableMessage
+{
+ Message msg;
+public:
+ RecoverableMessageImpl(const Message& _msg);
+ ~RecoverableMessageImpl() {};
+ void setPersistenceId(uint64_t id);
+ void setRedelivered();
+ void computeExpiration(const boost::intrusive_ptr<ExpiryPolicy>& ep);
+ bool loadContent(uint64_t available);
+ void decodeContent(framing::Buffer& buffer);
+ void recover(boost::shared_ptr<Queue> queue);
+ void enqueue(boost::shared_ptr<DtxBuffer> buffer, boost::shared_ptr<Queue> queue);
+ void dequeue(boost::shared_ptr<DtxBuffer> buffer, boost::shared_ptr<Queue> queue);
+};
+}} // namespace qpid::broker
+
+#endif /*!QPID_BROKER_RECOVERABLEMESSAGEIMPL_H*/
diff --git a/cpp/src/qpid/broker/RecoveryManagerImpl.cpp b/cpp/src/qpid/broker/RecoveryManagerImpl.cpp
index f3e1639ca5..901b3ad15a 100644
--- a/cpp/src/qpid/broker/RecoveryManagerImpl.cpp
+++ b/cpp/src/qpid/broker/RecoveryManagerImpl.cpp
@@ -25,6 +25,8 @@
#include "qpid/broker/Queue.h"
#include "qpid/broker/Link.h"
#include "qpid/broker/Bridge.h"
+#include "qpid/broker/Protocol.h"
+#include "qpid/broker/RecoverableMessageImpl.h"
#include "qpid/broker/RecoveredEnqueue.h"
#include "qpid/broker/RecoveredDequeue.h"
#include "qpid/broker/amqp_0_10/MessageTransfer.h"
@@ -38,26 +40,11 @@ namespace qpid {
namespace broker {
RecoveryManagerImpl::RecoveryManagerImpl(QueueRegistry& _queues, ExchangeRegistry& _exchanges, LinkRegistry& _links,
- DtxManager& _dtxMgr)
- : queues(_queues), exchanges(_exchanges), links(_links), dtxMgr(_dtxMgr) {}
+ DtxManager& _dtxMgr, ProtocolRegistry& p)
+ : queues(_queues), exchanges(_exchanges), links(_links), dtxMgr(_dtxMgr), protocols(p) {}
RecoveryManagerImpl::~RecoveryManagerImpl() {}
-class RecoverableMessageImpl : public RecoverableMessage
-{
- Message msg;
-public:
- RecoverableMessageImpl(const Message& _msg);
- ~RecoverableMessageImpl() {};
- void setPersistenceId(uint64_t id);
- void setRedelivered();
- bool loadContent(uint64_t available);
- void decodeContent(framing::Buffer& buffer);
- void recover(Queue::shared_ptr queue);
- void enqueue(DtxBuffer::shared_ptr buffer, Queue::shared_ptr queue);
- void dequeue(DtxBuffer::shared_ptr buffer, Queue::shared_ptr queue);
-};
-
class RecoverableQueueImpl : public RecoverableQueue
{
Queue::shared_ptr queue;
@@ -82,6 +69,7 @@ public:
RecoverableExchangeImpl(Exchange::shared_ptr _exchange, QueueRegistry& _queues) : exchange(_exchange), queues(_queues) {}
void setPersistenceId(uint64_t id);
void bind(const std::string& queue, const std::string& routingKey, qpid::framing::FieldTable& args, AsyncStore* const store);
+ string getName() const { return exchange->getName(); }
};
class RecoverableConfigImpl : public RecoverableConfig
@@ -130,10 +118,15 @@ RecoverableQueue::shared_ptr RecoveryManagerImpl::recoverQueue(framing::Buffer&
RecoverableMessage::shared_ptr RecoveryManagerImpl::recoverMessage(framing::Buffer& buffer)
{
- //TODO: determine encoding/version actually used
- boost::intrusive_ptr<qpid::broker::amqp_0_10::MessageTransfer> transfer(new qpid::broker::amqp_0_10::MessageTransfer());
- transfer->decodeHeader(buffer);
- return RecoverableMessage::shared_ptr(new RecoverableMessageImpl(Message(transfer, transfer)));
+ framing::Buffer sniffer(buffer.getPointer(), buffer.available());
+ RecoverableMessage::shared_ptr m = protocols.recover(sniffer);
+ if (m) {
+ return m;
+ } else {
+ boost::intrusive_ptr<qpid::broker::amqp_0_10::MessageTransfer> transfer(new qpid::broker::amqp_0_10::MessageTransfer());
+ transfer->decodeHeader(buffer);
+ return RecoverableMessage::shared_ptr(new RecoverableMessageImpl(Message(transfer, transfer)));
+ }
}
RecoverableTransaction::shared_ptr RecoveryManagerImpl::recoverTransaction(const std::string& xid,
@@ -193,6 +186,11 @@ void RecoverableMessageImpl::setRedelivered()
msg.deliver();//increment delivery count (but at present that isn't recorded durably)
}
+void RecoverableMessageImpl::computeExpiration(const boost::intrusive_ptr<ExpiryPolicy>& ep)
+{
+ msg.computeExpiration(ep);
+}
+
void RecoverableQueueImpl::recover(RecoverableMessage::shared_ptr msg)
{
dynamic_pointer_cast<RecoverableMessageImpl>(msg)->recover(queue);
diff --git a/cpp/src/qpid/broker/RecoveryManagerImpl.h b/cpp/src/qpid/broker/RecoveryManagerImpl.h
index 7fca0be194..f824f4a540 100644
--- a/cpp/src/qpid/broker/RecoveryManagerImpl.h
+++ b/cpp/src/qpid/broker/RecoveryManagerImpl.h
@@ -30,15 +30,17 @@
namespace qpid {
namespace broker {
+class ProtocolRegistry;
class RecoveryManagerImpl : public RecoveryManager{
QueueRegistry& queues;
ExchangeRegistry& exchanges;
LinkRegistry& links;
DtxManager& dtxMgr;
+ ProtocolRegistry& protocols;
public:
RecoveryManagerImpl(QueueRegistry& queues, ExchangeRegistry& exchanges, LinkRegistry& links,
- DtxManager& dtxMgr);
+ DtxManager& dtxMgr, ProtocolRegistry&);
~RecoveryManagerImpl();
RecoverableExchange::shared_ptr recoverExchange(framing::Buffer& buffer);
diff --git a/cpp/src/qpid/broker/SaslAuthenticator.cpp b/cpp/src/qpid/broker/SaslAuthenticator.cpp
index 2d7c820b63..8211657e04 100644
--- a/cpp/src/qpid/broker/SaslAuthenticator.cpp
+++ b/cpp/src/qpid/broker/SaslAuthenticator.cpp
@@ -24,6 +24,7 @@
#endif
#include "qpid/broker/AclModule.h"
+#include "qpid/broker/Broker.h"
#include "qpid/broker/Connection.h"
#include "qpid/log/Statement.h"
#include "qpid/framing/reply_exceptions.h"
@@ -169,14 +170,8 @@ void SaslAuthenticator::fini(void)
std::auto_ptr<SaslAuthenticator> SaslAuthenticator::createAuthenticator(Connection& c )
{
if (c.getBroker().getOptions().auth) {
- // The cluster creates non-authenticated connections for internal shadow connections
- // that are never connected to an external client.
- if ( !c.isAuthenticated() )
- return std::auto_ptr<SaslAuthenticator>(
- new NullAuthenticator(c, c.getBroker().getOptions().requireEncrypted));
- else
- return std::auto_ptr<SaslAuthenticator>(
- new CyrusAuthenticator(c, c.getBroker().getOptions().requireEncrypted));
+ return std::auto_ptr<SaslAuthenticator>(
+ new CyrusAuthenticator(c, c.getBroker().getOptions().requireEncrypted));
} else {
QPID_LOG(debug, "SASL: No Authentication Performed");
return std::auto_ptr<SaslAuthenticator>(new NullAuthenticator(c, c.getBroker().getOptions().requireEncrypted));
@@ -424,7 +419,7 @@ void CyrusAuthenticator::start(const string& mechanism, const string* response)
&challenge, &challenge_len);
processAuthenticationStep(code, challenge, challenge_len);
- qmf::org::apache::qpid::broker::Connection* cnxMgmt = connection.getMgmtObject();
+ qmf::org::apache::qpid::broker::Connection::shared_ptr cnxMgmt = connection.getMgmtObject();
if ( cnxMgmt )
cnxMgmt->set_saslMechanism(mechanism);
}
@@ -505,9 +500,9 @@ std::auto_ptr<SecurityLayer> CyrusAuthenticator::getSecurityLayer(uint16_t maxFr
uint ssf = *(reinterpret_cast<const unsigned*>(value));
std::auto_ptr<SecurityLayer> securityLayer;
if (ssf) {
- securityLayer = std::auto_ptr<SecurityLayer>(new CyrusSecurityLayer(sasl_conn, maxFrameSize));
+ securityLayer = std::auto_ptr<SecurityLayer>(new CyrusSecurityLayer(sasl_conn, maxFrameSize, ssf));
}
- qmf::org::apache::qpid::broker::Connection* cnxMgmt = connection.getMgmtObject();
+ qmf::org::apache::qpid::broker::Connection::shared_ptr cnxMgmt = connection.getMgmtObject();
if ( cnxMgmt )
cnxMgmt->set_saslSsf(ssf);
return securityLayer;
diff --git a/cpp/src/qpid/broker/SecureConnection.cpp b/cpp/src/qpid/broker/SecureConnection.cpp
index 5c1ebf3e8b..59ac9ef132 100644
--- a/cpp/src/qpid/broker/SecureConnection.cpp
+++ b/cpp/src/qpid/broker/SecureConnection.cpp
@@ -43,7 +43,7 @@ size_t SecureConnection::decode(const char* buffer, size_t size)
}
}
-size_t SecureConnection::encode(const char* buffer, size_t size)
+size_t SecureConnection::encode(char* buffer, size_t size)
{
if (secured) {
return securityLayer->encode(buffer, size);
diff --git a/cpp/src/qpid/broker/SecureConnection.h b/cpp/src/qpid/broker/SecureConnection.h
index 1547faae1e..632087350e 100644
--- a/cpp/src/qpid/broker/SecureConnection.h
+++ b/cpp/src/qpid/broker/SecureConnection.h
@@ -43,7 +43,7 @@ class SecureConnection : public qpid::sys::ConnectionCodec
public:
SecureConnection();
size_t decode(const char* buffer, size_t size);
- size_t encode(const char* buffer, size_t size);
+ size_t encode(char* buffer, size_t size);
bool canEncode();
void closed();
bool isClosed() const;
diff --git a/cpp/src/qpid/broker/SecureConnectionFactory.cpp b/cpp/src/qpid/broker/SecureConnectionFactory.cpp
index 757f6efc59..7bc2c94d1c 100644
--- a/cpp/src/qpid/broker/SecureConnectionFactory.cpp
+++ b/cpp/src/qpid/broker/SecureConnectionFactory.cpp
@@ -19,19 +19,21 @@
*
*/
#include "qpid/broker/SecureConnectionFactory.h"
-#include "qpid/framing/ProtocolVersion.h"
+
#include "qpid/amqp_0_10/Connection.h"
+#include "qpid/broker/Broker.h"
#include "qpid/broker/Connection.h"
#include "qpid/broker/SecureConnection.h"
-#include "qpid/sys/SecuritySettings.h"
+#include "qpid/framing/ProtocolVersion.h"
#include "qpid/log/Statement.h"
+#include "qpid/sys/SecuritySettings.h"
namespace qpid {
namespace broker {
using framing::ProtocolVersion;
using qpid::sys::SecuritySettings;
-typedef std::auto_ptr<amqp_0_10::Connection> CodecPtr;
+typedef std::auto_ptr<qpid::amqp_0_10::Connection> CodecPtr;
typedef std::auto_ptr<SecureConnection> SecureConnectionPtr;
typedef std::auto_ptr<Connection> ConnectionPtr;
typedef std::auto_ptr<sys::ConnectionInputHandler> InputPtr;
@@ -43,12 +45,14 @@ SecureConnectionFactory::create(ProtocolVersion v, sys::OutputControl& out, cons
const SecuritySettings& external) {
if (v == ProtocolVersion(0, 10)) {
SecureConnectionPtr sc(new SecureConnection());
- CodecPtr c(new amqp_0_10::Connection(out, id, false));
+ CodecPtr c(new qpid::amqp_0_10::Connection(out, id, false));
ConnectionPtr i(new broker::Connection(c.get(), broker, id, external, false));
i->setSecureConnection(sc.get());
c->setInputHandler(InputPtr(i.release()));
sc->setCodec(std::auto_ptr<sys::ConnectionCodec>(c));
return sc.release();
+ } else {
+ return broker.getProtocolRegistry().create(v, out, id, external);
}
return 0;
}
@@ -58,7 +62,7 @@ SecureConnectionFactory::create(sys::OutputControl& out, const std::string& id,
const SecuritySettings& external) {
// used to create connections from one broker to another
SecureConnectionPtr sc(new SecureConnection());
- CodecPtr c(new amqp_0_10::Connection(out, id, true));
+ CodecPtr c(new qpid::amqp_0_10::Connection(out, id, true));
ConnectionPtr i(new broker::Connection(c.get(), broker, id, external, true ));
i->setSecureConnection(sc.get());
c->setInputHandler(InputPtr(i.release()));
diff --git a/cpp/src/qpid/broker/SemanticState.cpp b/cpp/src/qpid/broker/SemanticState.cpp
index 5fc9a1a932..751b3ff709 100644
--- a/cpp/src/qpid/broker/SemanticState.cpp
+++ b/cpp/src/qpid/broker/SemanticState.cpp
@@ -20,6 +20,8 @@
*/
#include "qpid/broker/SessionState.h"
+
+#include "qpid/broker/Broker.h"
#include "qpid/broker/Connection.h"
#include "qpid/broker/DeliverableMessage.h"
#include "qpid/broker/DtxAck.h"
@@ -35,12 +37,14 @@
#include "qpid/framing/SequenceSet.h"
#include "qpid/framing/IsInSequenceSet.h"
#include "qpid/log/Statement.h"
-#include "qpid/sys/ClusterSafe.h"
+#include "qpid/management/ManagementAgent.h"
#include "qpid/ptr_map.h"
#include "qpid/broker/AclModule.h"
+#include "qpid/broker/FedOps.h"
#include <boost/bind.hpp>
#include <boost/format.hpp>
+#include <boost/tuple/tuple_comparison.hpp>
#include <iostream>
#include <sstream>
@@ -49,6 +53,11 @@
#include <assert.h>
+namespace {
+const std::string X_SCOPE("x-scope");
+const std::string SESSION("session");
+}
+
namespace qpid {
namespace broker {
@@ -88,6 +97,7 @@ void SemanticState::closed() {
if (dtxBuffer.get()) {
dtxBuffer->fail();
}
+ unbindSessionBindings();
requeue();
//now unsubscribe, which may trigger queue deletion and thus
@@ -277,7 +287,7 @@ void SemanticState::record(const DeliveryRecord& delivery)
const std::string QPID_SYNC_FREQUENCY("qpid.sync_frequency");
-SemanticState::ConsumerImpl::ConsumerImpl(SemanticState* _parent,
+SemanticStateConsumerImpl::SemanticStateConsumerImpl(SemanticState* _parent,
const string& _name,
Queue::shared_ptr _queue,
bool ack,
@@ -303,7 +313,7 @@ Consumer(_name, type),
notifyEnabled(true),
syncFrequency(_arguments.getAsInt(QPID_SYNC_FREQUENCY)),
deliveryCount(0),
- mgmtObject(0)
+ protocols(parent->getSession().getBroker().getProtocolRegistry())
{
if (parent != 0 && queue.get() != 0 && queue->GetManagementObject() !=0)
{
@@ -312,20 +322,20 @@ Consumer(_name, type),
if (agent != 0)
{
- mgmtObject = new _qmf::Subscription(agent, this, ms , queue->GetManagementObject()->getObjectId(), getTag(),
- !acquire, ackExpected, exclusive, ManagementAgent::toMap(arguments));
+ mgmtObject = _qmf::Subscription::shared_ptr(new _qmf::Subscription(agent, this, ms , queue->GetManagementObject()->getObjectId(), getTag(),
+ !acquire, ackExpected, exclusive, ManagementAgent::toMap(arguments)));
agent->addObject (mgmtObject);
mgmtObject->set_creditMode("WINDOW");
}
}
}
-ManagementObject* SemanticState::ConsumerImpl::GetManagementObject (void) const
+ManagementObject::shared_ptr SemanticStateConsumerImpl::GetManagementObject (void) const
{
- return (ManagementObject*) mgmtObject;
+ return mgmtObject;
}
-Manageable::status_t SemanticState::ConsumerImpl::ManagementMethod (uint32_t methodId, Args&, string&)
+Manageable::status_t SemanticStateConsumerImpl::ManagementMethod (uint32_t methodId, Args&, string&)
{
Manageable::status_t status = Manageable::STATUS_UNKNOWN_METHOD;
@@ -335,24 +345,23 @@ Manageable::status_t SemanticState::ConsumerImpl::ManagementMethod (uint32_t met
}
-OwnershipToken* SemanticState::ConsumerImpl::getSession()
+OwnershipToken* SemanticStateConsumerImpl::getSession()
{
return &(parent->session);
}
-bool SemanticState::ConsumerImpl::deliver(const QueueCursor& cursor, const Message& msg)
+bool SemanticStateConsumerImpl::deliver(const QueueCursor& cursor, const Message& msg)
{
return deliver(cursor, msg, shared_from_this());
}
-bool SemanticState::ConsumerImpl::deliver(const QueueCursor& cursor, const Message& msg, boost::shared_ptr<Consumer> consumer)
+bool SemanticStateConsumerImpl::deliver(const QueueCursor& cursor, const Message& msg, boost::shared_ptr<Consumer> consumer)
{
- assertClusterSafe();
allocateCredit(msg);
+ boost::intrusive_ptr<const amqp_0_10::MessageTransfer> transfer = protocols.translate(msg);
DeliveryRecord record(cursor, msg.getSequence(), queue, getTag(),
- consumer, acquire, !ackExpected, credit.isWindowMode(), amqp_0_10::MessageTransfer::getRequiredCredit(msg));
+ consumer, acquire, !ackExpected, credit.isWindowMode(), transfer->getRequiredCredit());
bool sync = syncFrequency && ++deliveryCount >= syncFrequency;
if (sync) deliveryCount = 0;//reset
- const amqp_0_10::MessageTransfer* transfer = dynamic_cast<const amqp_0_10::MessageTransfer*>(&msg.getEncoding());
record.setId(parent->session.deliver(*transfer, getTag(), msg.isRedelivered(), msg.getTtl(), msg.getTimestamp(),
ackExpected ? message::ACCEPT_MODE_EXPLICIT : message::ACCEPT_MODE_NONE,
@@ -370,27 +379,26 @@ bool SemanticState::ConsumerImpl::deliver(const QueueCursor& cursor, const Messa
return true;
}
-bool SemanticState::ConsumerImpl::filter(const Message&)
+bool SemanticStateConsumerImpl::filter(const Message&)
{
return true;
}
-bool SemanticState::ConsumerImpl::accept(const Message& msg)
+bool SemanticStateConsumerImpl::accept(const Message& msg)
{
- assertClusterSafe();
// TODO aconway 2009-06-08: if we have byte & message credit but
// checkCredit fails because the message is to big, we should
// remain on queue's listener list for possible smaller messages
// in future.
//
- blocked = !(filter(msg) && checkCredit(msg));
+ blocked = !checkCredit(msg);
return !blocked;
}
namespace {
struct ConsumerName {
- const SemanticState::ConsumerImpl& consumer;
- ConsumerName(const SemanticState::ConsumerImpl& ci) : consumer(ci) {}
+ const SemanticStateConsumerImpl& consumer;
+ ConsumerName(const SemanticStateConsumerImpl& ci) : consumer(ci) {}
};
ostream& operator<<(ostream& o, const ConsumerName& pc) {
@@ -399,26 +407,27 @@ ostream& operator<<(ostream& o, const ConsumerName& pc) {
}
}
-void SemanticState::ConsumerImpl::allocateCredit(const Message& msg)
+void SemanticStateConsumerImpl::allocateCredit(const Message& msg)
{
- assertClusterSafe();
Credit original = credit;
- credit.consume(1, qpid::broker::amqp_0_10::MessageTransfer::getRequiredCredit(msg));
+ boost::intrusive_ptr<const amqp_0_10::MessageTransfer> transfer = protocols.translate(msg);
+ credit.consume(1, transfer->getRequiredCredit());
QPID_LOG(debug, "Credit allocated for " << ConsumerName(*this)
<< ", was " << original << " now " << credit);
}
-bool SemanticState::ConsumerImpl::checkCredit(const Message& msg)
+bool SemanticStateConsumerImpl::checkCredit(const Message& msg)
{
- bool enoughCredit = credit.check(1, qpid::broker::amqp_0_10::MessageTransfer::getRequiredCredit(msg));
+ boost::intrusive_ptr<const amqp_0_10::MessageTransfer> transfer = protocols.translate(msg);
+ bool enoughCredit = credit.check(1, transfer->getRequiredCredit());
QPID_LOG(debug, "Subscription " << ConsumerName(*this) << " has " << (enoughCredit ? "sufficient " : "insufficient")
- << " credit for message of " << qpid::broker::amqp_0_10::MessageTransfer::getRequiredCredit(msg) << " bytes: "
+ << " credit for message of " << transfer->getRequiredCredit() << " bytes: "
<< credit);
return enoughCredit;
}
-SemanticState::ConsumerImpl::~ConsumerImpl()
+SemanticStateConsumerImpl::~SemanticStateConsumerImpl()
{
if (mgmtObject != 0)
mgmtObject->resourceDestroy ();
@@ -437,9 +446,9 @@ void SemanticState::cancel(ConsumerImpl::shared_ptr c)
Queue::shared_ptr queue = c->getQueue();
if(queue) {
queue->cancel(c);
- if (queue->canAutoDelete() && !queue->hasExclusiveOwner()) {
+ // Only run auto-delete for counted consumers.
+ if (c->isCounted() && queue->canAutoDelete() && !queue->hasExclusiveOwner())
Queue::tryAutoDelete(session.getBroker(), queue, connectionId, userID);
- }
}
c->cancel();
}
@@ -491,9 +500,8 @@ void SemanticState::requestDispatch()
i->second->requestDispatch();
}
-void SemanticState::ConsumerImpl::requestDispatch()
+void SemanticStateConsumerImpl::requestDispatch()
{
- assertClusterSafe();
if (blocked) {
parent->session.getConnection().outputTasks.addOutputTask(this);
parent->session.getConnection().outputTasks.activateOutput();
@@ -510,7 +518,7 @@ bool SemanticState::complete(DeliveryRecord& delivery)
return delivery.isRedundant();
}
-void SemanticState::ConsumerImpl::complete(DeliveryRecord& delivery)
+void SemanticStateConsumerImpl::complete(DeliveryRecord& delivery)
{
if (!delivery.isComplete()) {
delivery.complete();
@@ -535,7 +543,7 @@ SessionContext& SemanticState::getSession() { return session; }
const SessionContext& SemanticState::getSession() const { return session; }
-const SemanticState::ConsumerImpl::shared_ptr SemanticState::find(const std::string& destination) const
+const SemanticStateConsumerImpl::shared_ptr SemanticState::find(const std::string& destination) const
{
ConsumerImpl::shared_ptr consumer;
if (!find(destination, consumer)) {
@@ -592,37 +600,33 @@ void SemanticState::stop(const std::string& destination)
find(destination)->stop();
}
-void SemanticState::ConsumerImpl::setWindowMode()
+void SemanticStateConsumerImpl::setWindowMode()
{
- assertClusterSafe();
credit.setWindowMode(true);
if (mgmtObject){
mgmtObject->set_creditMode("WINDOW");
}
}
-void SemanticState::ConsumerImpl::setCreditMode()
+void SemanticStateConsumerImpl::setCreditMode()
{
- assertClusterSafe();
credit.setWindowMode(false);
if (mgmtObject){
mgmtObject->set_creditMode("CREDIT");
}
}
-void SemanticState::ConsumerImpl::addByteCredit(uint32_t value)
+void SemanticStateConsumerImpl::addByteCredit(uint32_t value)
{
- assertClusterSafe();
credit.addByteCredit(value);
}
-void SemanticState::ConsumerImpl::addMessageCredit(uint32_t value)
+void SemanticStateConsumerImpl::addMessageCredit(uint32_t value)
{
- assertClusterSafe();
credit.addMessageCredit(value);
}
-bool SemanticState::ConsumerImpl::haveCredit()
+bool SemanticStateConsumerImpl::haveCredit()
{
if (credit) {
return true;
@@ -632,21 +636,20 @@ bool SemanticState::ConsumerImpl::haveCredit()
}
}
-bool SemanticState::ConsumerImpl::doDispatch()
+bool SemanticStateConsumerImpl::doDispatch()
{
return queue->dispatch(shared_from_this());
}
-void SemanticState::ConsumerImpl::flush()
+void SemanticStateConsumerImpl::flush()
{
while(haveCredit() && doDispatch())
;
credit.cancel();
}
-void SemanticState::ConsumerImpl::stop()
+void SemanticStateConsumerImpl::stop()
{
- assertClusterSafe();
credit.cancel();
}
@@ -700,7 +703,7 @@ void SemanticState::reject(DeliveryId first, DeliveryId last)
getSession().setUnackedCount(unacked.size());
}
-bool SemanticState::ConsumerImpl::doOutput()
+bool SemanticStateConsumerImpl::doOutput()
{
try {
return haveCredit() && doDispatch();
@@ -709,28 +712,26 @@ bool SemanticState::ConsumerImpl::doOutput()
}
}
-void SemanticState::ConsumerImpl::enableNotify()
+void SemanticStateConsumerImpl::enableNotify()
{
Mutex::ScopedLock l(lock);
- assertClusterSafe();
notifyEnabled = true;
}
-void SemanticState::ConsumerImpl::disableNotify()
+void SemanticStateConsumerImpl::disableNotify()
{
Mutex::ScopedLock l(lock);
notifyEnabled = false;
}
-bool SemanticState::ConsumerImpl::isNotifyEnabled() const {
+bool SemanticStateConsumerImpl::isNotifyEnabled() const {
Mutex::ScopedLock l(lock);
return notifyEnabled;
}
-void SemanticState::ConsumerImpl::notify()
+void SemanticStateConsumerImpl::notify()
{
Mutex::ScopedLock l(lock);
- assertClusterSafe();
if (notifyEnabled) {
parent->session.getConnection().outputTasks.addOutputTask(this);
parent->session.getConnection().outputTasks.activateOutput();
@@ -755,7 +756,6 @@ isInSequenceSetAnd(const SequenceSet& s, Predicate p) {
}
void SemanticState::accepted(const SequenceSet& commands) {
- assertClusterSafe();
if (txBuffer.get()) {
//in transactional mode, don't dequeue or remove, just
//maintain set of acknowledged messages:
@@ -815,4 +815,63 @@ void SemanticState::detached()
}
}
+void SemanticState::addBinding(const string& queueName, const string& exchangeName,
+ const string& routingKey, const framing::FieldTable& arguments)
+{
+ QPID_LOG (debug, "SemanticState::addBinding ["
+ << "queue=" << queueName << ", "
+ << "exchange=" << exchangeName << ", "
+ << "key=" << routingKey << ", "
+ << "args=" << arguments << "]");
+ std::string fedOp = arguments.getAsString(qpidFedOp);
+ if ((arguments.isSet(qpidFedOp)) && (fedOp.empty())) {
+ fedOp = fedOpBind;
+ }
+ std::string fedOrigin = arguments.getAsString(qpidFedOrigin);
+ if ((arguments.getAsString(X_SCOPE) == SESSION) || (fedOp == fedOpBind)) {
+ bindings.insert(boost::make_tuple(queueName, exchangeName, routingKey, fedOrigin));
+ }
+ else if (fedOp == fedOpUnbind) {
+ bindings.erase(boost::make_tuple(queueName, exchangeName, routingKey, fedOrigin));
+ }
+}
+
+void SemanticState::removeBinding(const string& queueName, const string& exchangeName,
+ const string& routingKey)
+{
+ QPID_LOG (debug, "SemanticState::removeBinding ["
+ << "queue=" << queueName << ", "
+ << "exchange=" << exchangeName << ", "
+ << "key=" << routingKey)
+ bindings.erase(boost::make_tuple(queueName, exchangeName, routingKey, ""));
+}
+
+void SemanticState::unbindSessionBindings()
+{
+ //unbind session-scoped bindings
+ for (Bindings::iterator i = bindings.begin(); i != bindings.end(); i++) {
+ QPID_LOG (debug, "SemanticState::unbindSessionBindings ["
+ << "queue=" << i->get<0>() << ", "
+ << "exchange=" << i->get<1>()<< ", "
+ << "key=" << i->get<2>() << ", "
+ << "fedOrigin=" << i->get<3>() << "]");
+ try {
+ std::string fedOrigin = i->get<3>();
+ if (!fedOrigin.empty()) {
+ framing::FieldTable fedArguments;
+ fedArguments.setString(qpidFedOp, fedOpUnbind);
+ fedArguments.setString(qpidFedOrigin, fedOrigin);
+ session.getBroker().bind(i->get<0>(), i->get<1>(), i->get<2>(), fedArguments,
+ userID, connectionId);
+ } else {
+ session.getBroker().unbind(i->get<0>(), i->get<1>(), i->get<2>(),
+ userID, connectionId);
+ }
+ }
+ catch (...) {
+ }
+ }
+ bindings.clear();
+}
+
}} // namespace qpid::broker
diff --git a/cpp/src/qpid/broker/SemanticState.h b/cpp/src/qpid/broker/SemanticState.h
index 9add663e24..ec48ca4753 100644
--- a/cpp/src/qpid/broker/SemanticState.h
+++ b/cpp/src/qpid/broker/SemanticState.h
@@ -46,10 +46,12 @@
#include <list>
#include <map>
+#include <set>
#include <vector>
#include <boost/enable_shared_from_this.hpp>
#include <boost/cast.hpp>
+#include <boost/tuple/tuple.hpp>
namespace qpid {
namespace broker {
@@ -57,6 +59,7 @@ namespace broker {
class Exchange;
//class MessageStore;
class AsyncStore;
+class ProtocolRegistry;
class SessionContext;
class SessionState;
@@ -74,104 +77,18 @@ class SessionState;
* called when a client's socket is ready to write data.
*
*/
+class SemanticStateConsumerImpl;
class SemanticState : private boost::noncopyable {
- public:
- class ConsumerImpl : public Consumer, public sys::OutputTask,
- public boost::enable_shared_from_this<ConsumerImpl>,
- public management::Manageable
- {
- protected:
- mutable qpid::sys::Mutex lock;
- SemanticState* const parent;
- private:
- const boost::shared_ptr<Queue> queue;
- const bool ackExpected;
- const bool acquire;
- bool blocked;
- bool exclusive;
- std::string resumeId;
- const std::string tag; // <destination> from AMQP 0-10 Message.subscribe command
- uint64_t resumeTtl;
- framing::FieldTable arguments;
- Credit credit;
- bool notifyEnabled;
- const int syncFrequency;
- int deliveryCount;
- qmf::org::apache::qpid::broker::Subscription* mgmtObject;
-
- bool checkCredit(const Message& msg);
- void allocateCredit(const Message& msg);
- bool haveCredit();
-
- protected:
- QPID_BROKER_EXTERN virtual bool doDispatch();
- size_t unacked() { return parent->unacked.size(); }
- QPID_BROKER_EXTERN bool deliver(const QueueCursor&, const Message&, boost::shared_ptr<Consumer>);
-
- public:
- typedef boost::shared_ptr<ConsumerImpl> shared_ptr;
-
- QPID_BROKER_EXTERN ConsumerImpl(SemanticState* parent,
- const std::string& name, boost::shared_ptr<Queue> queue,
- bool ack, SubscriptionType type, bool exclusive,
- const std::string& tag, const std::string& resumeId,
- uint64_t resumeTtl, const framing::FieldTable& arguments);
- QPID_BROKER_EXTERN ~ConsumerImpl();
- QPID_BROKER_EXTERN OwnershipToken* getSession();
- QPID_BROKER_EXTERN bool deliver(const QueueCursor&, const Message&);
- QPID_BROKER_EXTERN bool filter(const Message&);
- QPID_BROKER_EXTERN bool accept(const Message&);
- QPID_BROKER_EXTERN void cancel() {}
-
- QPID_BROKER_EXTERN void disableNotify();
- QPID_BROKER_EXTERN void enableNotify();
- QPID_BROKER_EXTERN void notify();
- QPID_BROKER_EXTERN bool isNotifyEnabled() const;
-
- QPID_BROKER_EXTERN void requestDispatch();
-
- QPID_BROKER_EXTERN void setWindowMode();
- QPID_BROKER_EXTERN void setCreditMode();
- QPID_BROKER_EXTERN void addByteCredit(uint32_t value);
- QPID_BROKER_EXTERN void addMessageCredit(uint32_t value);
- QPID_BROKER_EXTERN void flush();
- QPID_BROKER_EXTERN void stop();
- QPID_BROKER_EXTERN void complete(DeliveryRecord&);
- boost::shared_ptr<Queue> getQueue() const { return queue; }
- bool isBlocked() const { return blocked; }
- bool setBlocked(bool set) { std::swap(set, blocked); return set; }
-
- QPID_BROKER_EXTERN bool doOutput();
-
- Credit& getCredit() { return credit; }
- const Credit& getCredit() const { return credit; }
- bool isAckExpected() const { return ackExpected; }
- bool isAcquire() const { return acquire; }
- bool isExclusive() const { return exclusive; }
- std::string getResumeId() const { return resumeId; };
- const std::string& getTag() const { return tag; }
- uint64_t getResumeTtl() const { return resumeTtl; }
- uint32_t getDeliveryCount() const { return deliveryCount; }
- void setDeliveryCount(uint32_t _deliveryCount) { deliveryCount = _deliveryCount; }
- const framing::FieldTable& getArguments() const { return arguments; }
-
- SemanticState& getParent() { return *parent; }
- const SemanticState& getParent() const { return *parent; }
-
- void acknowledged(const DeliveryRecord&) {}
-
- // manageable entry points
- QPID_BROKER_EXTERN management::ManagementObject*
- GetManagementObject(void) const;
-
- QPID_BROKER_EXTERN management::Manageable::status_t
- ManagementMethod(uint32_t methodId, management::Args& args, std::string& text);
- };
+ friend class SemanticStateConsumerImpl;
+ public:
+ typedef SemanticStateConsumerImpl ConsumerImpl;
typedef std::map<std::string, DtxBuffer::shared_ptr> DtxBufferMap;
private:
- typedef std::map<std::string, ConsumerImpl::shared_ptr> ConsumerImplMap;
+ typedef std::map<std::string, boost::shared_ptr<ConsumerImpl> > ConsumerImplMap;
+ typedef boost::tuple<std::string, std::string, std::string, std::string> Binding;
+ typedef std::set<Binding> Bindings;
SessionState& session;
ConsumerImplMap consumers;
@@ -189,13 +106,16 @@ class SemanticState : private boost::noncopyable {
//needed for queue delete events in auto-delete:
const std::string connectionId;
+ Bindings bindings;
+
void checkDtxTimeout();
bool complete(DeliveryRecord&);
AckRange findRange(DeliveryId first, DeliveryId last);
void requestDispatch();
- void cancel(ConsumerImpl::shared_ptr);
- void disable(ConsumerImpl::shared_ptr);
+ void cancel(boost::shared_ptr<ConsumerImpl>);
+ void disable(boost::shared_ptr<ConsumerImpl>);
+ void unbindSessionBindings();
public:
@@ -205,8 +125,8 @@ class SemanticState : private boost::noncopyable {
SessionContext& getSession();
const SessionContext& getSession() const;
- const ConsumerImpl::shared_ptr find(const std::string& destination) const;
- bool find(const std::string& destination, ConsumerImpl::shared_ptr&) const;
+ const boost::shared_ptr<ConsumerImpl> find(const std::string& destination) const;
+ bool find(const std::string& destination, boost::shared_ptr<ConsumerImpl>&) const;
/**
* Get named queue, never returns 0.
@@ -257,11 +177,6 @@ class SemanticState : private boost::noncopyable {
void detached();
void closed();
- // Used by cluster to re-create sessions
- template <class F> void eachConsumer(F f) {
- for(ConsumerImplMap::iterator i = consumers.begin(); i != consumers.end(); ++i)
- f(i->second);
- }
DeliveryRecords& getUnacked() { return unacked; }
framing::SequenceSet getAccumulatedAck() const { return accumulatedAck; }
TxBuffer::shared_ptr getTxBuffer() const { return txBuffer; }
@@ -271,6 +186,104 @@ class SemanticState : private boost::noncopyable {
void setAccumulatedAck(const framing::SequenceSet& s) { accumulatedAck = s; }
void record(const DeliveryRecord& delivery);
DtxBufferMap& getSuspendedXids() { return suspendedXids; }
+
+ void addBinding(const std::string& queueName, const std::string& exchangeName,
+ const std::string& routingKey, const framing::FieldTable& arguments);
+ void removeBinding(const std::string& queueName, const std::string& exchangeName,
+ const std::string& routingKey);
+};
+
+class SemanticStateConsumerImpl : public Consumer, public sys::OutputTask,
+ public boost::enable_shared_from_this<SemanticStateConsumerImpl>,
+ public management::Manageable
+{
+ protected:
+ mutable qpid::sys::Mutex lock;
+ SemanticState* const parent;
+ private:
+ const boost::shared_ptr<Queue> queue;
+ const bool ackExpected;
+ const bool acquire;
+ bool blocked;
+ bool exclusive;
+ std::string resumeId;
+ const std::string tag; // <destination> from AMQP 0-10 Message.subscribe command
+ uint64_t resumeTtl;
+ framing::FieldTable arguments;
+ Credit credit;
+ bool notifyEnabled;
+ const int syncFrequency;
+ int deliveryCount;
+ qmf::org::apache::qpid::broker::Subscription::shared_ptr mgmtObject;
+ ProtocolRegistry& protocols;
+
+ bool checkCredit(const Message& msg);
+ void allocateCredit(const Message& msg);
+ bool haveCredit();
+
+ protected:
+ QPID_BROKER_EXTERN virtual bool doDispatch();
+ size_t unacked() { return parent->unacked.size(); }
+ QPID_BROKER_EXTERN bool deliver(const QueueCursor&, const Message&, boost::shared_ptr<Consumer>);
+
+ public:
+ typedef boost::shared_ptr<SemanticStateConsumerImpl> shared_ptr;
+
+ QPID_BROKER_EXTERN SemanticStateConsumerImpl(SemanticState* parent,
+ const std::string& name, boost::shared_ptr<Queue> queue,
+ bool ack, SubscriptionType type, bool exclusive,
+ const std::string& tag, const std::string& resumeId,
+ uint64_t resumeTtl, const framing::FieldTable& arguments);
+ QPID_BROKER_EXTERN ~SemanticStateConsumerImpl();
+ QPID_BROKER_EXTERN OwnershipToken* getSession();
+ QPID_BROKER_EXTERN bool deliver(const QueueCursor&, const Message&);
+ QPID_BROKER_EXTERN bool filter(const Message&);
+ QPID_BROKER_EXTERN bool accept(const Message&);
+ QPID_BROKER_EXTERN void cancel() {}
+
+ QPID_BROKER_EXTERN void disableNotify();
+ QPID_BROKER_EXTERN void enableNotify();
+ QPID_BROKER_EXTERN void notify();
+ QPID_BROKER_EXTERN bool isNotifyEnabled() const;
+
+ QPID_BROKER_EXTERN void requestDispatch();
+
+ QPID_BROKER_EXTERN void setWindowMode();
+ QPID_BROKER_EXTERN void setCreditMode();
+ QPID_BROKER_EXTERN void addByteCredit(uint32_t value);
+ QPID_BROKER_EXTERN void addMessageCredit(uint32_t value);
+ QPID_BROKER_EXTERN void flush();
+ QPID_BROKER_EXTERN void stop();
+ QPID_BROKER_EXTERN void complete(DeliveryRecord&);
+ boost::shared_ptr<Queue> getQueue() const { return queue; }
+ bool isBlocked() const { return blocked; }
+ bool setBlocked(bool set) { std::swap(set, blocked); return set; }
+
+ QPID_BROKER_EXTERN bool doOutput();
+
+ Credit& getCredit() { return credit; }
+ const Credit& getCredit() const { return credit; }
+ bool isAckExpected() const { return ackExpected; }
+ bool isAcquire() const { return acquire; }
+ bool isExclusive() const { return exclusive; }
+ std::string getResumeId() const { return resumeId; };
+ const std::string& getTag() const { return tag; }
+ uint64_t getResumeTtl() const { return resumeTtl; }
+ uint32_t getDeliveryCount() const { return deliveryCount; }
+ void setDeliveryCount(uint32_t _deliveryCount) { deliveryCount = _deliveryCount; }
+ const framing::FieldTable& getArguments() const { return arguments; }
+
+ SemanticState& getParent() { return *parent; }
+ const SemanticState& getParent() const { return *parent; }
+
+ void acknowledged(const DeliveryRecord&) {}
+
+ // manageable entry points
+ QPID_BROKER_EXTERN management::ManagementObject::shared_ptr
+ GetManagementObject(void) const;
+
+ QPID_BROKER_EXTERN management::Manageable::status_t
+ ManagementMethod(uint32_t methodId, management::Args& args, std::string& text);
};
}} // namespace qpid::broker
diff --git a/cpp/src/qpid/broker/SessionAdapter.cpp b/cpp/src/qpid/broker/SessionAdapter.cpp
index cb2fe15b58..1ea18ea472 100644
--- a/cpp/src/qpid/broker/SessionAdapter.cpp
+++ b/cpp/src/qpid/broker/SessionAdapter.cpp
@@ -16,7 +16,10 @@
*
*/
#include "qpid/broker/SessionAdapter.h"
+
+#include "qpid/broker/Broker.h"
#include "qpid/broker/Connection.h"
+#include "qpid/broker/DtxTimeout.h"
#include "qpid/broker/Queue.h"
#include "qpid/Exception.h"
#include "qpid/framing/reply_exceptions.h"
@@ -98,17 +101,6 @@ void SessionAdapter::ExchangeHandlerImpl::declare(const string& exchange, const
//exchange already there, not created
checkType(response.first, type);
checkAlternate(response.first, alternate);
- ManagementAgent* agent = getBroker().getManagementAgent();
- if (agent)
- agent->raiseEvent(_qmf::EventExchangeDeclare(getConnection().getUrl(),
- getConnection().getUserId(),
- exchange,
- type,
- alternateExchange,
- durable,
- false,
- ManagementAgent::toMap(args),
- "existing"));
QPID_LOG_CAT(debug, model, "Create exchange. name:" << exchange
<< " user:" << getConnection().getUserId()
<< " rhost:" << getConnection().getUrl()
@@ -165,12 +157,14 @@ void SessionAdapter::ExchangeHandlerImpl::bind(const string& queueName,
{
getBroker().bind(queueName, exchangeName, routingKey, arguments,
getConnection().getUserId(), getConnection().getUrl());
+ state.addBinding(queueName, exchangeName, routingKey, arguments);
}
void SessionAdapter::ExchangeHandlerImpl::unbind(const string& queueName,
const string& exchangeName,
const string& routingKey)
{
+ state.removeBinding(queueName, exchangeName, routingKey);
getBroker().unbind(queueName, exchangeName, routingKey,
getConnection().getUserId(), getConnection().getUrl());
}
@@ -300,6 +294,8 @@ void SessionAdapter::QueueHandlerImpl::declare(const string& name, const string&
} catch (const qpid::types::Exception& e) {
throw InvalidArgumentException(e.what());
}
+ // Identify queues that won't survive a failover.
+ settings.isTemporary = exclusive && autoDelete && !settings.autoDeleteDelay;
std::pair<Queue::shared_ptr, bool> queue_created =
getBroker().createQueue(name, settings,
@@ -318,11 +314,6 @@ void SessionAdapter::QueueHandlerImpl::declare(const string& name, const string&
if (exclusive && queue->setExclusiveOwner(&session)) {
exclusiveQueues.push_back(queue);
}
- ManagementAgent* agent = getBroker().getManagementAgent();
- if (agent)
- agent->raiseEvent(_qmf::EventQueueDeclare(getConnection().getUrl(), getConnection().getUserId(),
- name, durable, exclusive, autoDelete, alternateExchange, ManagementAgent::toMap(arguments),
- "existing"));
QPID_LOG_CAT(debug, model, "Create queue. name:" << name
<< " user:" << getConnection().getUserId()
<< " rhost:" << getConnection().getUrl()
@@ -422,6 +413,11 @@ SessionAdapter::MessageHandlerImpl::subscribe(const string& queueName,
if(!destination.empty() && state.exists(destination))
throw NotAllowedException(QPID_MSG("Consumer tags must be unique"));
+ if (queue->getSettings().isBrowseOnly && acquireMode == 0) {
+ QPID_LOG(info, "Overriding request to consume from browse-only queue " << queue->getName());
+ acquireMode = 1;
+ }
+
// We allow browsing (acquireMode == 1) of exclusive queues, this is required by HA.
if (queue->hasExclusiveOwner() && !queue->isExclusiveOwner(&session) && acquireMode == 0)
throw ResourceLockedException(QPID_MSG("Cannot subscribe to exclusive queue "
diff --git a/cpp/src/qpid/broker/SessionHandler.cpp b/cpp/src/qpid/broker/SessionHandler.cpp
index 9888d12be2..a6b008647f 100644
--- a/cpp/src/qpid/broker/SessionHandler.cpp
+++ b/cpp/src/qpid/broker/SessionHandler.cpp
@@ -19,8 +19,9 @@
*/
#include "qpid/broker/SessionHandler.h"
-#include "qpid/broker/SessionState.h"
+#include "qpid/broker/Broker.h"
#include "qpid/broker/Connection.h"
+#include "qpid/broker/SessionState.h"
#include "qpid/log/Statement.h"
#include <boost/bind.hpp>
@@ -34,9 +35,7 @@ using namespace qpid::sys;
SessionHandler::SessionHandler(Connection& c, ChannelId ch)
: qpid::amqp_0_10::SessionHandler(&c.getOutput(), ch),
connection(c),
- proxy(out),
- clusterOrderProxy(c.getClusterOrderOutput() ?
- new SetChannelProxy(ch, c.getClusterOrderOutput()) : 0)
+ proxy(out)
{}
SessionHandler::~SessionHandler() {}
@@ -110,10 +109,7 @@ void SessionHandler::attachAs(const std::string& name)
{
SessionId id(connection.getUserId(), name);
SessionState::Configuration config = connection.broker.getSessionManager().getSessionConfig();
- // Delay creating management object till attached(). In a cluster,
- // only the active link broker calls attachAs but all brokers
- // receive the subsequent attached() call.
- session.reset(new SessionState(connection.getBroker(), *this, id, config, true));
+ session.reset(new SessionState(connection.getBroker(), *this, id, config));
sendAttach(false);
}
diff --git a/cpp/src/qpid/broker/SessionHandler.h b/cpp/src/qpid/broker/SessionHandler.h
index 21c736fa37..d42b7838bb 100644
--- a/cpp/src/qpid/broker/SessionHandler.h
+++ b/cpp/src/qpid/broker/SessionHandler.h
@@ -71,17 +71,6 @@ class SessionHandler : public qpid::amqp_0_10::SessionHandler {
framing::AMQP_ClientProxy& getProxy() { return proxy; }
const framing::AMQP_ClientProxy& getProxy() const { return proxy; }
- /**
- * If commands are sent based on the local time (e.g. in timers), they don't have
- * a well-defined ordering across cluster nodes.
- * This proxy is for sending such commands. In a clustered broker it will take steps
- * to synchronize command order across the cluster. In a stand-alone broker
- * it is just a synonym for getProxy()
- */
- framing::AMQP_ClientProxy& getClusterOrderProxy() {
- return clusterOrderProxy.get() ? *clusterOrderProxy : proxy;
- }
-
virtual void handleDetach();
void attached(const std::string& name);//used by 'pushing' inter-broker bridges
void attachAs(const std::string& name);//used by 'pulling' inter-broker bridges
@@ -108,7 +97,6 @@ class SessionHandler : public qpid::amqp_0_10::SessionHandler {
Connection& connection;
framing::AMQP_ClientProxy proxy;
std::auto_ptr<SessionState> session;
- std::auto_ptr<SetChannelProxy> clusterOrderProxy;
boost::shared_ptr<ErrorListener> errorListener;
};
diff --git a/cpp/src/qpid/broker/SessionState.cpp b/cpp/src/qpid/broker/SessionState.cpp
index 944cbad0aa..d71134548a 100644
--- a/cpp/src/qpid/broker/SessionState.cpp
+++ b/cpp/src/qpid/broker/SessionState.cpp
@@ -25,7 +25,6 @@
#include "qpid/broker/DeliveryRecord.h"
#include "qpid/broker/SessionManager.h"
#include "qpid/broker/SessionHandler.h"
-#include "qpid/sys/ClusterSafe.h"
#include "qpid/framing/AMQContentBody.h"
#include "qpid/framing/AMQHeaderBody.h"
#include "qpid/framing/AMQMethodBody.h"
@@ -54,15 +53,14 @@ namespace _qmf = qmf::org::apache::qpid::broker;
SessionState::SessionState(
Broker& b, SessionHandler& h, const SessionId& id,
- const SessionState::Configuration& config, bool delayManagement)
+ const SessionState::Configuration& config)
: qpid::SessionState(id, config),
broker(b), handler(&h),
semanticState(*this),
adapter(semanticState),
- mgmtObject(0),
asyncCommandCompleter(new AsyncCommandCompleter(this))
{
- if (!delayManagement) addManagementObject();
+ addManagementObject();
attach(h);
}
@@ -72,8 +70,8 @@ void SessionState::addManagementObject() {
if (parent != 0) {
ManagementAgent* agent = getBroker().getManagementAgent();
if (agent != 0) {
- mgmtObject = new _qmf::Session
- (agent, this, parent, getId().getName());
+ mgmtObject = _qmf::Session::shared_ptr(new _qmf::Session
+ (agent, this, parent, getId().getName()));
mgmtObject->set_attached (0);
mgmtObject->set_detachedLifespan (0);
mgmtObject->clr_expireTime();
@@ -145,14 +143,9 @@ void SessionState::activateOutput() {
getConnection().outputTasks.activateOutput();
}
-void SessionState::giveReadCredit(int32_t credit) {
- if (isAttached())
- getConnection().outputTasks.giveReadCredit(credit);
-}
-
-ManagementObject* SessionState::GetManagementObject (void) const
+ManagementObject::shared_ptr SessionState::GetManagementObject(void) const
{
- return (ManagementObject*) mgmtObject;
+ return mgmtObject;
}
Manageable::status_t SessionState::ManagementMethod (uint32_t methodId,
@@ -251,11 +244,6 @@ void SessionState::completeRcvMsg(SequenceNumber id,
bool requiresAccept,
bool requiresSync)
{
- // Mark this as a cluster-unsafe scope since it can be called in
- // journal threads or connection threads as part of asynchronous
- // command completion.
- sys::ClusterUnsafeScope cus;
-
bool callSendCompletion = false;
receiverCompleted(id);
if (requiresAccept)
@@ -340,15 +328,9 @@ void SessionState::readyToSend() {
Broker& SessionState::getBroker() { return broker; }
// Session resume is not fully implemented so it is useless to set a
-// non-0 timeout. Moreover it creates problems in a cluster because
-// dead sessions are kept and interfere with failover.
+// non-0 timeout.
void SessionState::setTimeout(uint32_t) { }
-framing::AMQP_ClientProxy& SessionState::getClusterOrderProxy() {
- return handler->getClusterOrderProxy();
-}
-
-
// Current received command is an execution.sync command.
// Complete this command only when all preceding commands have completed.
// (called via the invoker() in handleCommand() above)
diff --git a/cpp/src/qpid/broker/SessionState.h b/cpp/src/qpid/broker/SessionState.h
index 5e3a77d7ed..a531ec9fc6 100644
--- a/cpp/src/qpid/broker/SessionState.h
+++ b/cpp/src/qpid/broker/SessionState.h
@@ -41,6 +41,7 @@
#include <boost/scoped_ptr.hpp>
#include <boost/intrusive_ptr.hpp>
+#include <queue>
#include <set>
#include <vector>
#include <ostream>
@@ -73,7 +74,7 @@ class SessionState : public qpid::SessionState,
{
public:
SessionState(Broker&, SessionHandler&, const SessionId&,
- const SessionState::Configuration&, bool delayManagement=false);
+ const SessionState::Configuration&);
~SessionState();
bool isAttached() const { return handler; }
@@ -98,7 +99,6 @@ class SessionState : public qpid::SessionState,
/** OutputControl **/
void abort();
void activateOutput();
- void giveReadCredit(int32_t);
void senderCompleted(const framing::SequenceSet& ranges);
@@ -110,17 +110,12 @@ class SessionState : public qpid::SessionState,
const qpid::types::Variant::Map& annotations, bool sync);
// Manageable entry points
- management::ManagementObject* GetManagementObject (void) const;
+ management::ManagementObject::shared_ptr GetManagementObject(void) const;
management::Manageable::status_t
ManagementMethod (uint32_t methodId, management::Args& args, std::string&);
void readyToSend();
- // Used by cluster to create replica sessions.
- SemanticState& getSemanticState() { return semanticState; }
- boost::intrusive_ptr<qpid::broker::amqp_0_10::MessageTransfer> getMessageInProgress() { return msgBuilder.getMessage(); }
- SessionAdapter& getSessionAdapter() { return adapter; }
-
const SessionId& getSessionId() const { return getId(); }
// Used by ExecutionHandler sync command processing. Notifies
@@ -153,22 +148,13 @@ class SessionState : public qpid::SessionState,
void sendAcceptAndCompletion();
- /**
- * If commands are sent based on the local time (e.g. in timers), they don't have
- * a well-defined ordering across cluster nodes.
- * This proxy is for sending such commands. In a clustered broker it will take steps
- * to synchronize command order across the cluster. In a stand-alone broker
- * it is just a synonym for getProxy()
- */
- framing::AMQP_ClientProxy& getClusterOrderProxy();
-
Broker& broker;
SessionHandler* handler;
sys::AbsTime expiry; // Used by SessionManager.
SemanticState semanticState;
SessionAdapter adapter;
MessageBuilder msgBuilder;
- qmf::org::apache::qpid::broker::Session* mgmtObject;
+ qmf::org::apache::qpid::broker::Session::shared_ptr mgmtObject;
qpid::framing::SequenceSet accepted;
// sequence numbers for pending received Execution.Sync commands
diff --git a/cpp/src/qpid/broker/StatefulQueueObserver.h b/cpp/src/qpid/broker/StatefulQueueObserver.h
deleted file mode 100644
index c682d460b7..0000000000
--- a/cpp/src/qpid/broker/StatefulQueueObserver.h
+++ /dev/null
@@ -1,63 +0,0 @@
-#ifndef QPID_BROKER_STATEFULQUEUEOBSERVER_H
-#define QPID_BROKER_STATEFULQUEUEOBSERVER_H
-
-/*
- *
- * 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.
- *
- */
-#include "qpid/broker/QueueObserver.h"
-#include "qpid/framing/FieldTable.h"
-
-namespace qpid {
-namespace broker {
-
-/**
- * Specialized type of QueueObserver that maintains internal state that has to
- * be replicated across clustered brokers.
- */
-class StatefulQueueObserver : public QueueObserver
-{
- public:
- StatefulQueueObserver(std::string _id) : id(_id) {}
- virtual ~StatefulQueueObserver() {}
-
- /** This identifier must uniquely identify this particular observer amoung
- * all observers on a queue. For cluster replication, this id will be used
- * to identify the peer queue observer for synchronization across
- * brokers.
- */
- const std::string& getId() const { return id; }
-
- /** This method should return the observer's internal state as an opaque
- * map.
- */
- virtual void getState(qpid::framing::FieldTable& state ) const = 0;
-
- /** The input map represents the internal state of the peer observer that
- * this observer should synchonize to.
- */
- virtual void setState(const qpid::framing::FieldTable&) = 0;
-
-
- private:
- std::string id;
-};
-}} // namespace qpid::broker
-
-#endif /*!QPID_BROKER_STATEFULQUEUEOBSERVER_H*/
diff --git a/cpp/src/qpid/broker/System.cpp b/cpp/src/qpid/broker/System.cpp
index fa8df6406b..8d54427fdc 100644
--- a/cpp/src/qpid/broker/System.cpp
+++ b/cpp/src/qpid/broker/System.cpp
@@ -31,7 +31,7 @@ using namespace qpid::broker;
using namespace std;
namespace _qmf = qmf::org::apache::qpid::broker;
-System::System (string _dataDir, Broker* broker) : mgmtObject(0)
+System::System (string _dataDir, Broker* broker)
{
ManagementAgent* agent = broker ? broker->getManagementAgent() : 0;
@@ -64,7 +64,7 @@ System::System (string _dataDir, Broker* broker) : mgmtObject(0)
}
}
- mgmtObject = new _qmf::System(agent, this, types::Uuid(systemId.c_array()));
+ mgmtObject = _qmf::System::shared_ptr(new _qmf::System(agent, this, types::Uuid(systemId.c_array())));
qpid::sys::SystemInfo::getSystemId (osName,
nodeName,
release,
diff --git a/cpp/src/qpid/broker/System.h b/cpp/src/qpid/broker/System.h
index 6847c662ae..52643fb2d5 100644
--- a/cpp/src/qpid/broker/System.h
+++ b/cpp/src/qpid/broker/System.h
@@ -35,7 +35,7 @@ class System : public management::Manageable
{
private:
- qmf::org::apache::qpid::broker::System* mgmtObject;
+ qmf::org::apache::qpid::broker::System::shared_ptr mgmtObject;
framing::Uuid systemId;
std::string osName, nodeName, release, version, machine;
@@ -45,7 +45,7 @@ class System : public management::Manageable
System (std::string _dataDir, Broker* broker = 0);
- management::ManagementObject* GetManagementObject (void) const
+ management::ManagementObject::shared_ptr GetManagementObject(void) const
{ return mgmtObject; }
diff --git a/cpp/src/qpid/broker/TopicExchange.cpp b/cpp/src/qpid/broker/TopicExchange.cpp
index 38d8f255ac..0badd1621c 100644
--- a/cpp/src/qpid/broker/TopicExchange.cpp
+++ b/cpp/src/qpid/broker/TopicExchange.cpp
@@ -179,7 +179,7 @@ bool TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, cons
}
}
- Binding::shared_ptr binding (new Binding (routingPattern, queue, this, FieldTable(), fedOrigin));
+ Binding::shared_ptr binding (new Binding (routingPattern, queue, this, args ? *args : FieldTable(), fedOrigin));
binding->startManagement();
bk->bindingVector.push_back(binding);
nBindings++;
diff --git a/cpp/src/qpid/broker/TxAccept.h b/cpp/src/qpid/broker/TxAccept.h
index a59e69a85f..daf192285a 100644
--- a/cpp/src/qpid/broker/TxAccept.h
+++ b/cpp/src/qpid/broker/TxAccept.h
@@ -71,9 +71,6 @@ namespace qpid {
virtual void commit() throw();
virtual void rollback() throw();
virtual ~TxAccept(){}
-
- // Used by cluster replication.
- const framing::SequenceSet& getAcked() const { return acked; }
};
}
}
diff --git a/cpp/src/qpid/broker/TxOpVisitor.h b/cpp/src/qpid/broker/TxOpVisitor.h
deleted file mode 100644
index e69de29bb2..0000000000
--- a/cpp/src/qpid/broker/TxOpVisitor.h
+++ /dev/null
diff --git a/cpp/src/qpid/broker/TxPublish.cpp b/cpp/src/qpid/broker/TxPublish.cpp
deleted file mode 100644
index e69de29bb2..0000000000
--- a/cpp/src/qpid/broker/TxPublish.cpp
+++ /dev/null
diff --git a/cpp/src/qpid/broker/TxPublish.h b/cpp/src/qpid/broker/TxPublish.h
deleted file mode 100644
index e69de29bb2..0000000000
--- a/cpp/src/qpid/broker/TxPublish.h
+++ /dev/null
diff --git a/cpp/src/qpid/broker/Vhost.cpp b/cpp/src/qpid/broker/Vhost.cpp
index a9ca3b42ab..e72118b570 100644
--- a/cpp/src/qpid/broker/Vhost.cpp
+++ b/cpp/src/qpid/broker/Vhost.cpp
@@ -29,7 +29,7 @@ namespace qpid { namespace management {
class Manageable;
}}
-Vhost::Vhost (qpid::management::Manageable* parentBroker, Broker* broker) : mgmtObject(0)
+Vhost::Vhost (qpid::management::Manageable* parentBroker, Broker* broker)
{
if (parentBroker != 0 && broker != 0)
{
@@ -37,7 +37,7 @@ Vhost::Vhost (qpid::management::Manageable* parentBroker, Broker* broker) : mgmt
if (agent != 0)
{
- mgmtObject = new _qmf::Vhost(agent, this, parentBroker, "/");
+ mgmtObject = _qmf::Vhost::shared_ptr(new _qmf::Vhost(agent, this, parentBroker, "/"));
agent->addObject(mgmtObject, 0, true);
}
}
diff --git a/cpp/src/qpid/broker/Vhost.h b/cpp/src/qpid/broker/Vhost.h
index 9554d641c2..599b821870 100644
--- a/cpp/src/qpid/broker/Vhost.h
+++ b/cpp/src/qpid/broker/Vhost.h
@@ -32,7 +32,7 @@ class Vhost : public management::Manageable
{
private:
- qmf::org::apache::qpid::broker::Vhost* mgmtObject;
+ qmf::org::apache::qpid::broker::Vhost::shared_ptr mgmtObject;
public:
@@ -40,7 +40,7 @@ class Vhost : public management::Manageable
Vhost (management::Manageable* parentBroker, Broker* broker = 0);
- management::ManagementObject* GetManagementObject (void) const
+ management::ManagementObject::shared_ptr GetManagementObject (void) const
{ return mgmtObject; }
void setFederationTag(const std::string& tag);
};
diff --git a/cpp/src/qpid/broker/amqp/Connection.cpp b/cpp/src/qpid/broker/amqp/Connection.cpp
new file mode 100644
index 0000000000..1f135cf931
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Connection.cpp
@@ -0,0 +1,247 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "Connection.h"
+#include "Session.h"
+#include "qpid/Exception.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/framing/Buffer.h"
+#include "qpid/framing/ProtocolInitiation.h"
+#include "qpid/framing/ProtocolVersion.h"
+#include "qpid/log/Statement.h"
+#include "qpid/sys/OutputControl.h"
+#include <sstream>
+extern "C" {
+#include <proton/engine.h>
+#include <proton/error.h>
+}
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+Connection::Connection(qpid::sys::OutputControl& o, const std::string& i, qpid::broker::Broker& b, bool saslInUse)
+ : ManagedConnection(b, i),
+ connection(pn_connection()),
+ transport(pn_transport()),
+ out(o), id(i), broker(b), haveOutput(true)
+{
+ if (pn_transport_bind(transport, connection)) {
+ //error
+ }
+ out.activateOutput();
+ bool enableTrace(false);
+ QPID_LOG_TEST_CAT(trace, protocol, enableTrace);
+ if (enableTrace) pn_transport_trace(transport, PN_TRACE_FRM);
+
+ if (!saslInUse) {
+ //feed in a dummy AMQP 1.0 header as engine expects one, but
+ //we already read it (if sasl is in use we read the sasl
+ //header,not the AMQP 1.0 header).
+ std::vector<char> protocolHeader(8);
+ qpid::framing::ProtocolInitiation pi(getVersion());
+ qpid::framing::Buffer buffer(&protocolHeader[0], protocolHeader.size());
+ pi.encode(buffer);
+ pn_transport_input(transport, &protocolHeader[0], protocolHeader.size());
+
+ //wont get a userid, so set a dummy one on the ManagedConnection to trigger event
+ setUserid("no authentication used");
+ }
+}
+
+
+Connection::~Connection()
+{
+
+ pn_transport_free(transport);
+ pn_connection_free(connection);
+}
+
+pn_transport_t* Connection::getTransport()
+{
+ return transport;
+}
+size_t Connection::decode(const char* buffer, size_t size)
+{
+ QPID_LOG(trace, id << " decode(" << size << ")")
+ //TODO: Fix pn_engine_input() to take const buffer
+ ssize_t n = pn_transport_input(transport, const_cast<char*>(buffer), size);
+ if (n > 0 || n == PN_EOS) {
+ //If engine returns EOS, have no way of knowing how many bytes
+ //it processed, but can assume none need to be reprocessed so
+ //consider them all read:
+ if (n == PN_EOS) n = size;
+ QPID_LOG_CAT(debug, network, id << " decoded " << n << " bytes from " << size)
+ process();
+ pn_transport_tick(transport, 0);
+ if (!haveOutput) {
+ haveOutput = true;
+ out.activateOutput();
+ }
+ return n;
+ } else if (n == PN_ERR) {
+ throw qpid::Exception(QPID_MSG("Error on input: " << getError()));
+ } else {
+ return 0;
+ }
+}
+
+size_t Connection::encode(char* buffer, size_t size)
+{
+ QPID_LOG(trace, "encode(" << size << ")")
+ ssize_t n = pn_transport_output(transport, buffer, size);
+ if (n > 0) {
+ QPID_LOG_CAT(debug, network, id << " encoded " << n << " bytes from " << size)
+ haveOutput = true;
+ return n;
+ } else if (n == PN_EOS) {
+ haveOutput = size;
+ return size;//Is this right?
+ } else if (n == PN_ERR) {
+ throw qpid::Exception(QPID_MSG("Error on output: " << getError()));
+ } else {
+ haveOutput = false;
+ return 0;
+ }
+}
+bool Connection::canEncode()
+{
+ for (Sessions::iterator i = sessions.begin();i != sessions.end(); ++i) {
+ if (i->second->dispatch()) haveOutput = true;
+ }
+ process();
+ //TODO: proper handling of time in and out of tick
+ pn_transport_tick(transport, 0);
+ QPID_LOG_CAT(trace, network, id << " canEncode(): " << haveOutput)
+ return haveOutput;
+}
+void Connection::closed()
+{
+ //TODO: tear down sessions and associated links
+ for (Sessions::iterator i = sessions.begin(); i != sessions.end(); ++i) {
+ i->second->close();
+ }
+}
+bool Connection::isClosed() const
+{
+ return pn_connection_state(connection) & PN_REMOTE_CLOSED;
+}
+framing::ProtocolVersion Connection::getVersion() const
+{
+ return qpid::framing::ProtocolVersion(1,0);
+}
+namespace {
+pn_state_t REQUIRES_OPEN = PN_LOCAL_UNINIT | PN_REMOTE_ACTIVE;
+pn_state_t REQUIRES_CLOSE = PN_LOCAL_ACTIVE | PN_REMOTE_CLOSED;
+}
+
+void Connection::process()
+{
+ QPID_LOG(trace, id << " process()");
+ if ((pn_connection_state(connection) & REQUIRES_OPEN) == REQUIRES_OPEN) {
+ QPID_LOG_CAT(debug, model, id << " connection opened");
+ pn_connection_set_container(connection, broker.getFederationTag().c_str());
+ pn_connection_open(connection);
+ }
+
+ for (pn_session_t* s = pn_session_head(connection, REQUIRES_OPEN); s; s = pn_session_next(s, REQUIRES_OPEN)) {
+ QPID_LOG_CAT(debug, model, id << " session begun");
+ pn_session_open(s);
+ boost::shared_ptr<Session> ssn(new Session(s, broker, *this, out));
+ sessions[s] = ssn;
+ }
+ for (pn_link_t* l = pn_link_head(connection, REQUIRES_OPEN); l; l = pn_link_next(l, REQUIRES_OPEN)) {
+ pn_link_open(l);
+
+ Sessions::iterator session = sessions.find(pn_link_session(l));
+ if (session == sessions.end()) {
+ QPID_LOG(error, id << " Link attached on unknown session!");
+ } else {
+ try {
+ session->second->attach(l);
+ QPID_LOG_CAT(debug, protocol, id << " link " << l << " attached on " << pn_link_session(l));
+ } catch (const std::exception& e) {
+ QPID_LOG_CAT(error, protocol, "Error on attach: " << e.what());
+ //TODO: set error details on detach when that is exposed via engine API
+ pn_link_close(l);
+ }
+ }
+ }
+
+ //handle deliveries
+ for (pn_delivery_t* delivery = pn_work_head(connection); delivery; delivery = pn_work_next(delivery)) {
+ pn_link_t* link = pn_delivery_link(delivery);
+ if (pn_link_is_receiver(link)) {
+ Sessions::iterator i = sessions.find(pn_link_session(link));
+ if (i != sessions.end()) {
+ i->second->incoming(link, delivery);
+ } else {
+ pn_delivery_update(delivery, PN_REJECTED);
+ }
+ } else { //i.e. SENDER
+ Sessions::iterator i = sessions.find(pn_link_session(link));
+ if (i != sessions.end()) {
+ QPID_LOG(trace, id << " handling outgoing delivery for " << link << " on session " << pn_link_session(link));
+ i->second->outgoing(link, delivery);
+ } else {
+ QPID_LOG(error, id << " Got delivery for non-existent session: " << pn_link_session(link) << ", link: " << link);
+ }
+ }
+ }
+
+
+ for (pn_link_t* l = pn_link_head(connection, REQUIRES_CLOSE); l; l = pn_link_next(l, REQUIRES_CLOSE)) {
+ pn_link_close(l);
+ Sessions::iterator session = sessions.find(pn_link_session(l));
+ if (session == sessions.end()) {
+ QPID_LOG(error, id << " peer attempted to detach link on unknown session!");
+ } else {
+ session->second->detach(l);
+ QPID_LOG_CAT(debug, model, id << " link detached");
+ }
+ }
+ for (pn_session_t* s = pn_session_head(connection, REQUIRES_CLOSE); s; s = pn_session_next(s, REQUIRES_CLOSE)) {
+ pn_session_close(s);
+ Sessions::iterator i = sessions.find(s);
+ if (i != sessions.end()) {
+ i->second->close();
+ sessions.erase(i);
+ QPID_LOG_CAT(debug, model, id << " session ended");
+ } else {
+ QPID_LOG(error, id << " peer attempted to close unrecognised session");
+ }
+ }
+ if ((pn_connection_state(connection) & REQUIRES_CLOSE) == REQUIRES_CLOSE) {
+ QPID_LOG_CAT(debug, model, id << " connection closed");
+ pn_connection_close(connection);
+ }
+}
+
+std::string Connection::getError()
+{
+ std::stringstream text;
+ pn_error_t* cerror = pn_connection_error(connection);
+ if (cerror) text << "connection error " << pn_error_text(cerror);
+ pn_error_t* terror = pn_transport_error(transport);
+ if (terror) text << "transport error " << pn_error_text(terror);
+ return text.str();
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Connection.h b/cpp/src/qpid/broker/amqp/Connection.h
new file mode 100644
index 0000000000..8af209af7a
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Connection.h
@@ -0,0 +1,73 @@
+#ifndef QPID_BROKER_AMQP1_CONNECTION_H
+#define QPID_BROKER_AMQP1_CONNECTION_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/sys/ConnectionCodec.h"
+#include "qpid/broker/amqp/ManagedConnection.h"
+#include <map>
+#include <boost/shared_ptr.hpp>
+
+struct pn_connection_t;
+struct pn_session_t;
+struct pn_transport_t;
+
+namespace qpid {
+namespace broker {
+
+class Broker;
+
+namespace amqp {
+
+class Session;
+/**
+ * AMQP 1.0 protocol support for broker
+ */
+class Connection : public sys::ConnectionCodec, public ManagedConnection
+{
+ public:
+ Connection(qpid::sys::OutputControl& out, const std::string& id, qpid::broker::Broker& broker, bool saslInUse);
+ ~Connection();
+ size_t decode(const char* buffer, size_t size);
+ size_t encode(char* buffer, size_t size);
+ bool canEncode();
+
+ void closed();
+ bool isClosed() const;
+
+ framing::ProtocolVersion getVersion() const;
+ pn_transport_t* getTransport();
+ private:
+ typedef std::map<pn_session_t*, boost::shared_ptr<Session> > Sessions;
+ pn_connection_t* connection;
+ pn_transport_t* transport;
+ qpid::sys::OutputControl& out;
+ const std::string id;
+ qpid::broker::Broker& broker;
+ bool haveOutput;
+ Sessions sessions;
+
+ void process();
+ std::string getError();
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP1_CONNECTION_H*/
diff --git a/cpp/src/qpid/broker/amqp/DataReader.cpp b/cpp/src/qpid/broker/amqp/DataReader.cpp
new file mode 100644
index 0000000000..519dd71c9c
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/DataReader.cpp
@@ -0,0 +1,187 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "DataReader.h"
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/amqp/Descriptor.h"
+#include "qpid/log/Statement.h"
+#include <string>
+extern "C" {
+#include <proton/engine.h>
+}
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+namespace {
+qpid::amqp::CharSequence convert(pn_bytes_t in)
+{
+ qpid::amqp::CharSequence out;
+ out.data = in.start;
+ out.size = in.size;
+ return out;
+}
+
+qpid::amqp::CharSequence convert(pn_uuid_t in)
+{
+ qpid::amqp::CharSequence out;
+ out.data = in.bytes;
+ out.size = 16;
+ return out;
+}
+}
+
+DataReader::DataReader(qpid::amqp::Reader& r) : reader(r) {}
+
+void DataReader::read(pn_data_t* data)
+{
+ /*
+ while (pn_data_next(data)) {
+ readOne(data);
+ }
+ */
+ do {
+ readOne(data);
+ } while (pn_data_next(data));
+}
+void DataReader::readOne(pn_data_t* data)
+{
+ qpid::amqp::Descriptor descriptor(0);
+ bool described = pn_data_is_described(data);
+ if (described) {
+ pn_data_enter(data);
+ pn_data_next(data);
+ if (pn_data_type(data) == PN_ULONG) {
+ descriptor = qpid::amqp::Descriptor(pn_data_get_ulong(data));
+ } else if (pn_data_type(data) == PN_SYMBOL) {
+ descriptor = qpid::amqp::Descriptor(convert(pn_data_get_symbol(data)));
+ } else {
+ QPID_LOG(notice, "Ignoring descriptor of type " << pn_data_type(data));
+ }
+ pn_data_next(data);
+ }
+ switch (pn_data_type(data)) {
+ case PN_NULL:
+ reader.onNull(described ? &descriptor : 0);
+ break;
+ case PN_BOOL:
+ reader.onBoolean(pn_data_get_bool(data), described ? &descriptor : 0);
+ break;
+ case PN_UBYTE:
+ reader.onUByte(pn_data_get_ubyte(data), described ? &descriptor : 0);
+ break;
+ case PN_BYTE:
+ reader.onByte(pn_data_get_byte(data), described ? &descriptor : 0);
+ break;
+ case PN_USHORT:
+ reader.onUShort(pn_data_get_ushort(data), described ? &descriptor : 0);
+ break;
+ case PN_SHORT:
+ reader.onShort(pn_data_get_short(data), described ? &descriptor : 0);
+ break;
+ case PN_UINT:
+ reader.onUInt(pn_data_get_uint(data), described ? &descriptor : 0);
+ break;
+ case PN_INT:
+ reader.onInt(pn_data_get_int(data), described ? &descriptor : 0);
+ break;
+ case PN_CHAR:
+ pn_data_get_char(data);
+ break;
+ case PN_ULONG:
+ reader.onULong(pn_data_get_ulong(data), described ? &descriptor : 0);
+ break;
+ case PN_LONG:
+ reader.onLong(pn_data_get_long(data), described ? &descriptor : 0);
+ break;
+ case PN_TIMESTAMP:
+ reader.onTimestamp(pn_data_get_timestamp(data), described ? &descriptor : 0);
+ break;
+ case PN_FLOAT:
+ reader.onFloat(pn_data_get_float(data), described ? &descriptor : 0);
+ break;
+ case PN_DOUBLE:
+ reader.onDouble(pn_data_get_double(data), described ? &descriptor : 0);
+ break;
+ case PN_DECIMAL32:
+ pn_data_get_decimal32(data);
+ break;
+ case PN_DECIMAL64:
+ pn_data_get_decimal64(data);
+ break;
+ case PN_DECIMAL128:
+ pn_data_get_decimal128(data);
+ break;
+ case PN_UUID:
+ reader.onUuid(convert(pn_data_get_uuid(data)), described ? &descriptor : 0);
+ break;
+ case PN_BINARY:
+ reader.onBinary(convert(pn_data_get_binary(data)), described ? &descriptor : 0);
+ break;
+ case PN_STRING:
+ reader.onString(convert(pn_data_get_string(data)), described ? &descriptor : 0);
+ break;
+ case PN_SYMBOL:
+ reader.onSymbol(convert(pn_data_get_symbol(data)), described ? &descriptor : 0);
+ break;
+ case PN_DESCRIBED:
+ break;
+ case PN_ARRAY:
+ readArray(data, described ? &descriptor : 0);
+ break;
+ case PN_LIST:
+ readList(data, described ? &descriptor : 0);
+ break;
+ case PN_MAP:
+ readMap(data, described ? &descriptor : 0);
+ break;
+ }
+ if (described) pn_data_exit(data);
+}
+
+void DataReader::readArray(pn_data_t* /*data*/, const qpid::amqp::Descriptor* /*descriptor*/)
+{
+ //not yet implemented
+}
+
+void DataReader::readList(pn_data_t* data, const qpid::amqp::Descriptor* descriptor)
+{
+ size_t count = pn_data_get_list(data);
+ reader.onStartList(count, qpid::amqp::CharSequence(), descriptor);
+ pn_data_enter(data);
+ for (size_t i = 0; i < count && pn_data_next(data); ++i) {
+ read(data);
+ }
+ pn_data_exit(data);
+ reader.onEndList(count, descriptor);
+}
+
+void DataReader::readMap(pn_data_t* data, const qpid::amqp::Descriptor* descriptor)
+{
+ size_t count = pn_data_get_map(data);
+ reader.onStartMap(count, qpid::amqp::CharSequence(), descriptor);
+ pn_data_enter(data);
+ for (size_t i = 0; i < count && pn_data_next(data); ++i) {
+ read(data);
+ }
+ pn_data_exit(data);
+ reader.onEndMap(count, descriptor);
+}
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/DataReader.h b/cpp/src/qpid/broker/amqp/DataReader.h
new file mode 100644
index 0000000000..024507e7f2
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/DataReader.h
@@ -0,0 +1,53 @@
+#ifndef QPID_BROKER_AMQP_DATAREADER_H
+#define QPID_BROKER_AMQP_DATAREADER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/Reader.h"
+
+struct pn_data_t;
+
+namespace qpid {
+namespace amqp {
+struct Descriptor;
+}
+namespace broker {
+namespace amqp {
+
+/**
+ * Allows use of Reader interface to read pn_data_t* data.
+ */
+class DataReader
+{
+ public:
+ DataReader(qpid::amqp::Reader& reader);
+ void read(pn_data_t*);
+ private:
+ qpid::amqp::Reader& reader;
+
+ void readOne(pn_data_t*);
+ void readMap(pn_data_t*, const qpid::amqp::Descriptor*);
+ void readList(pn_data_t*, const qpid::amqp::Descriptor*);
+ void readArray(pn_data_t*, const qpid::amqp::Descriptor*);
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_DATAREADER_H*/
diff --git a/cpp/src/qpid/broker/amqp/Filter.cpp b/cpp/src/qpid/broker/amqp/Filter.cpp
new file mode 100644
index 0000000000..38baba0df1
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Filter.cpp
@@ -0,0 +1,150 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/Filter.h"
+#include "qpid/broker/amqp/DataReader.h"
+#include "qpid/broker/DirectExchange.h"
+#include "qpid/broker/TopicExchange.h"
+#include "qpid/amqp/descriptors.h"
+#include "qpid/log/Statement.h"
+extern "C" {
+#include <proton/engine.h>
+}
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+void Filter::read(pn_data_t* data)
+{
+ try {
+ DataReader reader(*this);
+ reader.read(data);
+ } catch (const std::exception& e) {
+ QPID_LOG(warning, "Error parsing filter: " << e.what());
+ }
+}
+
+void Filter::write(pn_data_t* data)
+{
+ pn_data_put_map(data);
+ pn_data_enter(data);
+ subjectFilter.write(data);
+ pn_data_exit(data);
+}
+
+void Filter::onStringValue(const qpid::amqp::CharSequence& key, const qpid::amqp::CharSequence& value, const qpid::amqp::Descriptor* descriptor)
+{
+ StringFilter filter;
+ filter.key = std::string(key.data, key.size);
+ filter.value = std::string(value.data, value.size);
+ if (descriptor) {
+ filter.described = true;
+ filter.descriptor = *descriptor;
+ if (descriptor->match(qpid::amqp::filters::LEGACY_TOPIC_FILTER_SYMBOL, qpid::amqp::filters::LEGACY_TOPIC_FILTER_CODE)
+ || descriptor->match(qpid::amqp::filters::LEGACY_DIRECT_FILTER_SYMBOL, qpid::amqp::filters::LEGACY_DIRECT_FILTER_CODE)) {
+ setSubjectFilter(filter);
+ } else {
+ QPID_LOG(notice, "Skipping unrecognised string filter with key " << filter.key << " and descriptor " << filter.descriptor);
+ }
+ } else {
+ setSubjectFilter(filter);
+ }
+}
+
+bool Filter::hasSubjectFilter() const
+{
+ return !subjectFilter.value.empty();
+}
+
+std::string Filter::getSubjectFilter() const
+{
+ return subjectFilter.value;
+}
+
+
+void Filter::setSubjectFilter(const StringFilter& filter)
+{
+ if (hasSubjectFilter()) {
+ QPID_LOG(notice, "Skipping filter with key " << filter.key << "; subject filter already set");
+ } else {
+ subjectFilter = filter;
+ }
+}
+
+void Filter::bind(boost::shared_ptr<Exchange> exchange, boost::shared_ptr<Queue> queue)
+{
+ subjectFilter.bind(exchange, queue);
+}
+
+Filter::StringFilter::StringFilter() : described(false), descriptor(0) {}
+namespace {
+pn_bytes_t convert(const std::string& in)
+{
+ pn_bytes_t out;
+ out.start = const_cast<char*>(in.data());
+ out.size = in.size();
+ return out;
+}
+pn_bytes_t convert(const qpid::amqp::CharSequence& in)
+{
+ pn_bytes_t out;
+ out.start = const_cast<char*>(in.data);
+ out.size = in.size;
+ return out;
+}
+}
+void Filter::StringFilter::write(pn_data_t* data)
+{
+ pn_data_put_symbol(data, convert(key));
+ if (described) {
+ pn_data_put_described(data);
+ pn_data_enter(data);
+ switch (descriptor.type) {
+ case qpid::amqp::Descriptor::NUMERIC:
+ pn_data_put_ulong(data, descriptor.value.code);
+ break;
+ case qpid::amqp::Descriptor::SYMBOLIC:
+ pn_data_put_symbol(data, convert(descriptor.value.symbol));
+ break;
+ }
+ }
+ pn_data_put_string(data, convert(value));
+ if (described) pn_data_exit(data);
+}
+
+void Filter::StringFilter::bind(boost::shared_ptr<Exchange> exchange, boost::shared_ptr<Queue> queue)
+{
+ if (described && exchange->getType() == DirectExchange::typeName
+ && descriptor.match(qpid::amqp::filters::LEGACY_TOPIC_FILTER_SYMBOL, qpid::amqp::filters::LEGACY_TOPIC_FILTER_CODE)) {
+ QPID_LOG(info, "Using legacy topic filter as a direct matching filter for " << exchange->getName());
+ if (descriptor.type == qpid::amqp::Descriptor::NUMERIC) {
+ descriptor = qpid::amqp::Descriptor(qpid::amqp::filters::LEGACY_DIRECT_FILTER_CODE);
+ } else {
+ qpid::amqp::CharSequence symbol;
+ symbol.data = qpid::amqp::filters::LEGACY_DIRECT_FILTER_SYMBOL.data();
+ symbol.size = qpid::amqp::filters::LEGACY_DIRECT_FILTER_SYMBOL.size();
+ descriptor = qpid::amqp::Descriptor(symbol);
+ }
+ }
+ exchange->bind(queue, value, 0);
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Filter.h b/cpp/src/qpid/broker/amqp/Filter.h
new file mode 100644
index 0000000000..20cceb372a
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Filter.h
@@ -0,0 +1,63 @@
+#ifndef QPID_BROKER_AMQP_FILTER_H
+#define QPID_BROKER_AMQP_FILTER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/MapReader.h"
+#include "qpid/amqp/Descriptor.h"
+#include <boost/shared_ptr.hpp>
+
+struct pn_data_t;
+namespace qpid {
+namespace broker {
+class Exchange;
+class Queue;
+namespace amqp {
+
+
+class Filter : qpid::amqp::MapReader
+{
+ public:
+ void read(pn_data_t*);
+ void write(pn_data_t*);
+ bool hasSubjectFilter() const;
+ std::string getSubjectFilter() const;
+ void bind(boost::shared_ptr<Exchange> exchange, boost::shared_ptr<Queue> queue);
+ private:
+ struct StringFilter
+ {
+ bool described;
+ qpid::amqp::Descriptor descriptor;
+ std::string key;
+ std::string value;
+ StringFilter();
+ void write(pn_data_t*);
+ void bind(boost::shared_ptr<Exchange> exchange, boost::shared_ptr<Queue> queue);
+ };
+
+ void onStringValue(const qpid::amqp::CharSequence& key, const qpid::amqp::CharSequence& value, const qpid::amqp::Descriptor* descriptor);
+ void setSubjectFilter(const StringFilter&);
+
+ StringFilter subjectFilter;
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_FILTER_H*/
diff --git a/cpp/src/qpid/broker/amqp/Header.cpp b/cpp/src/qpid/broker/amqp/Header.cpp
new file mode 100644
index 0000000000..493e757a56
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Header.cpp
@@ -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.
+ *
+ */
+#include "qpid/broker/amqp/Header.h"
+#include "qpid/broker/Message.h"
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+bool Header::isDurable() const
+{
+ return message.isPersistent();
+}
+
+uint8_t Header::getPriority() const
+{
+ return message.getPriority();
+}
+
+bool Header::hasTtl() const
+{
+ uint64_t dummy(0);
+ return message.getTtl(dummy);
+}
+
+uint32_t Header::getTtl() const
+{
+ uint64_t ttl(0);
+ message.getTtl(ttl);
+ if (ttl > std::numeric_limits<uint32_t>::max()) return std::numeric_limits<uint32_t>::max();
+ else return (uint32_t) ttl;
+}
+
+bool Header::isFirstAcquirer() const
+{
+ return false;//TODO
+}
+
+uint32_t Header::getDeliveryCount() const
+{
+ return message.getDeliveryCount();
+}
+
+Header::Header(const qpid::broker::Message& m) : message(m) {}
+
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Header.h b/cpp/src/qpid/broker/amqp/Header.h
new file mode 100644
index 0000000000..6e4f763028
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Header.h
@@ -0,0 +1,50 @@
+#ifndef QPID_BROKER_AMQP_HEADER_H
+#define QPID_BROKER_AMQP_HEADER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/MessageEncoder.h"
+
+namespace qpid {
+namespace broker {
+class Message;
+namespace amqp {
+
+/**
+ * Adapts the broker current message abstraction to provide that
+ * required by the AMQP 1.0 message encoder.
+ */
+class Header : public qpid::amqp::MessageEncoder::Header
+{
+ public:
+ Header(const qpid::broker::Message&);
+ bool isDurable() const;
+ uint8_t getPriority() const;
+ bool hasTtl() const;
+ uint32_t getTtl() const;
+ bool isFirstAcquirer() const;
+ uint32_t getDeliveryCount() const;
+ private:
+ const qpid::broker::Message& message;
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_HEADER_H*/
diff --git a/cpp/src/qpid/broker/amqp/ManagedConnection.cpp b/cpp/src/qpid/broker/amqp/ManagedConnection.cpp
new file mode 100644
index 0000000000..0253ba5552
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/ManagedConnection.cpp
@@ -0,0 +1,98 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/ManagedConnection.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/management/ManagementAgent.h"
+#include "qpid/log/Statement.h"
+#include "qmf/org/apache/qpid/broker/EventClientConnect.h"
+#include "qmf/org/apache/qpid/broker/EventClientDisconnect.h"
+
+namespace _qmf = qmf::org::apache::qpid::broker;
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+ManagedConnection::ManagedConnection(Broker& broker, const std::string i) : id(i), agent(0)
+{
+ //management integration:
+ agent = broker.getManagementAgent();
+ if (agent != 0) {
+ qpid::management::Manageable* parent = broker.GetVhostObject();
+ // TODO set last bool true if system connection
+ connection = _qmf::Connection::shared_ptr(new _qmf::Connection(agent, this, parent, id, true, false, "AMQP 1.0"));
+ connection->set_shadow(false);
+ agent->addObject(connection);
+ }
+}
+
+ManagedConnection::~ManagedConnection()
+{
+ if (agent && connection) {
+ agent->raiseEvent(_qmf::EventClientDisconnect(id, userid, connection->get_remoteProperties()));
+ connection->resourceDestroy();
+ }
+ QPID_LOG_CAT(debug, model, "Delete connection. user:" << userid << " rhost:" << id);
+}
+
+void ManagedConnection::setUserid(const std::string& uid)
+{
+ userid = uid;
+ if (agent && connection) {
+ connection->set_authIdentity(userid);
+ agent->raiseEvent(_qmf::EventClientConnect(id, userid, connection->get_remoteProperties()));
+ }
+ QPID_LOG_CAT(debug, model, "Create connection. user:" << userid << " rhost:" << id );
+}
+
+void ManagedConnection::setSaslMechanism(const std::string& mechanism)
+{
+ connection->set_saslMechanism(mechanism);
+}
+
+void ManagedConnection::setSaslSsf(int ssf)
+{
+ connection->set_saslSsf(ssf);
+}
+
+qpid::management::ManagementObject::shared_ptr ManagedConnection::GetManagementObject() const
+{
+ return connection;
+}
+
+std::string ManagedConnection::getId() const { return id; }
+std::string ManagedConnection::getUserid() const { return userid; }
+
+bool ManagedConnection::isLocal(const ConnectionToken* t) const
+{
+ return this == t;
+}
+void ManagedConnection::outgoingMessageSent()
+{
+ if (connection) connection->inc_msgsToClient();
+}
+
+void ManagedConnection::incomingMessageReceived()
+{
+ if (connection) connection->inc_msgsFromClient();
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/ManagedConnection.h b/cpp/src/qpid/broker/amqp/ManagedConnection.h
new file mode 100644
index 0000000000..e2d0376918
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/ManagedConnection.h
@@ -0,0 +1,59 @@
+#ifndef QPID_BROKER_AMQP_MANAGEDCONNECTION_H
+#define QPID_BROKER_AMQP_MANAGEDCONNECTION_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/management/Manageable.h"
+#include "qpid/broker/ConnectionToken.h"
+#include "qmf/org/apache/qpid/broker/Connection.h"
+
+namespace qpid {
+namespace management {
+class ManagementAgent;
+class ManagementObject;
+}
+namespace broker {
+class Broker;
+namespace amqp {
+
+class ManagedConnection : public qpid::management::Manageable, public ConnectionToken
+{
+ public:
+ ManagedConnection(Broker& broker, const std::string id);
+ virtual ~ManagedConnection();
+ void setUserid(const std::string&);
+ std::string getId() const;
+ std::string getUserid() const;
+ void setSaslMechanism(const std::string&);
+ void setSaslSsf(int);
+ qpid::management::ManagementObject::shared_ptr GetManagementObject() const;
+ bool isLocal(const ConnectionToken* t) const;
+ void incomingMessageReceived();
+ void outgoingMessageSent();
+ private:
+ const std::string id;
+ std::string userid;
+ qmf::org::apache::qpid::broker::Connection::shared_ptr connection;
+ qpid::management::ManagementAgent* agent;
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_MANAGEDCONNECTION_H*/
diff --git a/cpp/src/qpid/broker/amqp/ManagedOutgoingLink.cpp b/cpp/src/qpid/broker/amqp/ManagedOutgoingLink.cpp
new file mode 100644
index 0000000000..f36a1e8da4
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/ManagedOutgoingLink.cpp
@@ -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.
+ *
+ */
+#include "ManagedOutgoingLink.h"
+#include "qpid/broker/amqp/ManagedSession.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/broker/Queue.h"
+#include "qpid/types/Variant.h"
+#include "qpid/management/ManagementAgent.h"
+#include "qpid/log/Statement.h"
+
+namespace _qmf = qmf::org::apache::qpid::broker;
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+ManagedOutgoingLink::ManagedOutgoingLink(Broker& broker, Queue& q, ManagedSession& p, const std::string i, bool topic)
+ : parent(p), id(i)
+{
+ qpid::management::ManagementAgent* agent = broker.getManagementAgent();
+ if (agent) {
+ subscription = _qmf::Subscription::shared_ptr(new _qmf::Subscription(agent, this, &p, q.GetManagementObject()->getObjectId(), id,
+ false/*FIXME*/, true/*FIXME*/, topic, qpid::types::Variant::Map()));
+ agent->addObject(subscription);
+ subscription->set_creditMode("n/a");
+ }
+}
+ManagedOutgoingLink::~ManagedOutgoingLink()
+{
+ if (subscription != 0) subscription->resourceDestroy();
+}
+
+qpid::management::ManagementObject::shared_ptr ManagedOutgoingLink::GetManagementObject() const
+{
+ return subscription;
+}
+
+void ManagedOutgoingLink::outgoingMessageSent()
+{
+ if (subscription) { subscription->inc_delivered(); }
+ parent.outgoingMessageSent();
+}
+void ManagedOutgoingLink::outgoingMessageAccepted()
+{
+ parent.outgoingMessageAccepted();
+}
+void ManagedOutgoingLink::outgoingMessageRejected()
+{
+ parent.outgoingMessageRejected();
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/ManagedOutgoingLink.h b/cpp/src/qpid/broker/amqp/ManagedOutgoingLink.h
new file mode 100644
index 0000000000..20a1095db2
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/ManagedOutgoingLink.h
@@ -0,0 +1,53 @@
+#ifndef QPID_BROKER_AMQP_MANAGEDOUTGOINGLINK_H
+#define QPID_BROKER_AMQP_MANAGEDOUTGOINGLINK_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/management/Manageable.h"
+#include "qmf/org/apache/qpid/broker/Subscription.h"
+
+namespace qpid {
+namespace management {
+class ManagementObject;
+}
+namespace broker {
+class Broker;
+class Queue;
+namespace amqp {
+class ManagedSession;
+
+class ManagedOutgoingLink : public qpid::management::Manageable
+{
+ public:
+ ManagedOutgoingLink(Broker& broker, Queue&, ManagedSession& parent, const std::string id, bool topic);
+ virtual ~ManagedOutgoingLink();
+ qpid::management::ManagementObject::shared_ptr GetManagementObject() const;
+ void outgoingMessageSent();
+ void outgoingMessageAccepted();
+ void outgoingMessageRejected();
+ private:
+ ManagedSession& parent;
+ const std::string id;
+ qmf::org::apache::qpid::broker::Subscription::shared_ptr subscription;
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_MANAGEDOUTGOINGLINK_H*/
diff --git a/cpp/src/qpid/broker/amqp/ManagedSession.cpp b/cpp/src/qpid/broker/amqp/ManagedSession.cpp
new file mode 100644
index 0000000000..9bef0e842b
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/ManagedSession.cpp
@@ -0,0 +1,88 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/ManagedSession.h"
+#include "qpid/broker/amqp/ManagedConnection.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/management/ManagementAgent.h"
+#include "qpid/log/Statement.h"
+
+namespace _qmf = qmf::org::apache::qpid::broker;
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+ManagedSession::ManagedSession(Broker& broker, ManagedConnection& p, const std::string i) : parent(p), id(i), unacked(0)
+{
+ qpid::management::ManagementAgent* agent = broker.getManagementAgent();
+ if (agent != 0) {
+ session = _qmf::Session::shared_ptr(new _qmf::Session(agent, this, broker.GetVhostObject(), id));
+ session->set_attached(true);
+ session->set_detachedLifespan(0);
+ session->clr_expireTime();
+ session->set_connectionRef(parent.GetManagementObject()->getObjectId());
+ agent->addObject(session);
+ }
+}
+
+ManagedSession::~ManagedSession()
+{
+ if (session) session->resourceDestroy();
+}
+
+qpid::management::ManagementObject::shared_ptr ManagedSession::GetManagementObject() const
+{
+ return session;
+}
+
+bool ManagedSession::isLocal(const ConnectionToken* t) const
+{
+ return &parent == t;
+}
+
+void ManagedSession::outgoingMessageSent()
+{
+ if (session) session->set_unackedMessages(++unacked);
+ parent.outgoingMessageSent();
+}
+void ManagedSession::outgoingMessageAccepted()
+{
+ if (session) session->set_unackedMessages(--unacked);
+}
+void ManagedSession::outgoingMessageRejected()
+{
+ if (session) session->set_unackedMessages(--unacked);
+}
+
+void ManagedSession::incomingMessageReceived()
+{
+ parent.incomingMessageReceived();
+}
+void ManagedSession::incomingMessageAccepted()
+{
+
+}
+void ManagedSession::incomingMessageRejected()
+{
+
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/ManagedSession.h b/cpp/src/qpid/broker/amqp/ManagedSession.h
new file mode 100644
index 0000000000..1f56964bb6
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/ManagedSession.h
@@ -0,0 +1,59 @@
+#ifndef QPID_BROKER_AMQP_MANAGEDSESSION_H
+#define QPID_BROKER_AMQP_MANAGEDSESSION_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/management/Manageable.h"
+#include "qmf/org/apache/qpid/broker/Session.h"
+#include "qpid/broker/ConnectionToken.h"
+#include "qpid/broker/OwnershipToken.h"
+
+namespace qpid {
+namespace management {
+class ManagementObject;
+}
+namespace broker {
+class Broker;
+namespace amqp {
+class ManagedConnection;
+
+class ManagedSession : public qpid::management::Manageable, public OwnershipToken
+{
+ public:
+ ManagedSession(Broker& broker, ManagedConnection& parent, const std::string id);
+ virtual ~ManagedSession();
+ qpid::management::ManagementObject::shared_ptr GetManagementObject() const;
+ bool isLocal(const ConnectionToken* t) const;
+ void incomingMessageReceived();
+ void incomingMessageAccepted();
+ void incomingMessageRejected();
+ void outgoingMessageSent();
+ void outgoingMessageAccepted();
+ void outgoingMessageRejected();
+ private:
+ ManagedConnection& parent;
+ const std::string id;
+ qmf::org::apache::qpid::broker::Session::shared_ptr session;
+ size_t unacked;
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_MANAGEDSESSION_H*/
diff --git a/cpp/src/qpid/broker/amqp/Message.cpp b/cpp/src/qpid/broker/amqp/Message.cpp
new file mode 100644
index 0000000000..a4c346e131
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Message.cpp
@@ -0,0 +1,264 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "Message.h"
+#include "qpid/amqp/Decoder.h"
+#include "qpid/amqp/descriptors.h"
+#include "qpid/amqp/MessageEncoder.h"
+#include "qpid/log/Statement.h"
+#include "qpid/framing/Buffer.h"
+#include <string.h>
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+namespace {
+std::string empty;
+}
+
+std::string Message::getRoutingKey() const
+{
+ std::string v;
+ v.assign(subject.data, subject.size);
+ return v;
+}
+std::string Message::getUserId() const
+{
+ std::string v;
+ v.assign(userId.data, userId.size);
+ return v;
+}
+
+bool Message::isPersistent() const
+{
+ return durable && durable.get();
+}
+bool Message::getTtl(uint64_t& t) const
+{
+ if (!ttl) {
+ return false;
+ } else {
+ t = ttl.get();
+ return true;
+ }
+}
+
+uint8_t Message::getPriority() const
+{
+ if (!priority) return 4;
+ else return priority.get();
+}
+
+std::string Message::getPropertyAsString(const std::string& /*key*/) const { return empty; }
+std::string Message::getAnnotationAsString(const std::string& /*key*/) const { return empty; }
+void Message::processProperties(MapHandler&) const {}
+
+//getContentSize() is primarily used in stats about the number of
+//bytes enqueued/dequeued etc, not sure whether this is the right name
+//and whether it should indeed only be the content that is thus
+//measured
+uint64_t Message::getContentSize() const { return data.size(); }
+//getContent() is used primarily for decoding qmf messages in management and ha
+std::string Message::getContent() const { return empty; }
+
+Message::Message(size_t size) : data(size)
+{
+ deliveryAnnotations.init();
+ messageAnnotations.init();
+ bareMessage.init();
+
+ userId.init();
+ to.init();
+ subject.init();
+ replyTo.init();
+ contentType.init();
+ contentEncoding.init();
+
+ applicationProperties.init();
+ body.init();
+ footer.init();
+}
+char* Message::getData() { return &data[0]; }
+const char* Message::getData() const { return &data[0]; }
+size_t Message::getSize() const { return data.size(); }
+
+qpid::amqp::MessageId Message::getMessageId() const
+{
+ return messageId;
+}
+qpid::amqp::CharSequence Message::getReplyTo() const
+{
+ return replyTo;
+}
+qpid::amqp::MessageId Message::getCorrelationId() const
+{
+ return correlationId;
+}
+qpid::amqp::CharSequence Message::getContentType() const
+{
+ return contentType;
+}
+qpid::amqp::CharSequence Message::getContentEncoding() const
+{
+ return contentEncoding;
+}
+
+qpid::amqp::CharSequence Message::getDeliveryAnnotations() const
+{
+ return deliveryAnnotations;
+}
+qpid::amqp::CharSequence Message::getMessageAnnotations() const
+{
+ return messageAnnotations;
+}
+qpid::amqp::CharSequence Message::getApplicationProperties() const
+{
+ return applicationProperties;
+}
+qpid::amqp::CharSequence Message::getBareMessage() const
+{
+ return bareMessage;
+}
+qpid::amqp::CharSequence Message::getBody() const
+{
+ return body;
+}
+qpid::amqp::CharSequence Message::getFooter() const
+{
+ return footer;
+}
+
+void Message::scan()
+{
+ qpid::amqp::Decoder decoder(getData(), getSize());
+ decoder.read(*this);
+ bareMessage = qpid::amqp::MessageReader::getBareMessage();
+ if (bareMessage.data && !bareMessage.size) {
+ bareMessage.size = getSize() - (bareMessage.data - getData());
+ }
+}
+
+const Message& Message::get(const qpid::broker::Message& message)
+{
+ const Message* m = dynamic_cast<const Message*>(&message.getEncoding());
+ if (!m) throw qpid::Exception("Translation not yet implemented!!");
+ return *m;
+}
+
+void Message::onDurable(bool b) { durable = b; }
+void Message::onPriority(uint8_t i) { priority = i; }
+void Message::onTtl(uint32_t i) { ttl = i; }
+void Message::onFirstAcquirer(bool b) { firstAcquirer = b; }
+void Message::onDeliveryCount(uint32_t i) { deliveryCount = i; }
+
+void Message::onMessageId(uint64_t v) { messageId.set(v); }
+void Message::onMessageId(const qpid::amqp::CharSequence& v, qpid::types::VariantType t) { messageId.set(v, t); }
+void Message::onUserId(const qpid::amqp::CharSequence& v) { userId = v; }
+void Message::onTo(const qpid::amqp::CharSequence& v) { to = v; }
+void Message::onSubject(const qpid::amqp::CharSequence& v) { subject = v; }
+void Message::onReplyTo(const qpid::amqp::CharSequence& v) { replyTo = v; }
+void Message::onCorrelationId(uint64_t v) { correlationId.set(v); }
+void Message::onCorrelationId(const qpid::amqp::CharSequence& v, qpid::types::VariantType t) { correlationId.set(v, t);}
+void Message::onContentType(const qpid::amqp::CharSequence& v) { contentType = v; }
+void Message::onContentEncoding(const qpid::amqp::CharSequence& v) { contentEncoding = v; }
+void Message::onAbsoluteExpiryTime(int64_t) {}
+void Message::onCreationTime(int64_t) {}
+void Message::onGroupId(const qpid::amqp::CharSequence&) {}
+void Message::onGroupSequence(uint32_t) {}
+void Message::onReplyToGroupId(const qpid::amqp::CharSequence&) {}
+
+void Message::onApplicationProperties(const qpid::amqp::CharSequence& v) { applicationProperties = v; }
+void Message::onDeliveryAnnotations(const qpid::amqp::CharSequence& v) { deliveryAnnotations = v; }
+void Message::onMessageAnnotations(const qpid::amqp::CharSequence& v) { messageAnnotations = v; }
+void Message::onBody(const qpid::amqp::CharSequence& v, const qpid::amqp::Descriptor&) { body = v; }
+void Message::onBody(const qpid::types::Variant&, const qpid::amqp::Descriptor&) {}
+void Message::onFooter(const qpid::amqp::CharSequence& v) { footer = v; }
+
+
+//PersistableMessage interface:
+void Message::encode(framing::Buffer& buffer) const
+{
+ buffer.putLong(0);//4-byte format indicator
+ buffer.putRawData((const uint8_t*) getData(), getSize());
+ QPID_LOG(debug, "Encoded 1.0 message of " << getSize() << " bytes, including " << bareMessage.size << " bytes of 'bare message'");
+}
+uint32_t Message::encodedSize() const
+{
+ return 4/*format indicator*/ + data.size();
+}
+//in 1.0 the binary header/content makes less sense and in any case
+//the functionality that split originally supported (i.e. lazy-loaded
+//messages) is no longer in use; for 1.0 we therefore treat the whole
+//content as 'header' and load it in the first stage.
+uint32_t Message::encodedHeaderSize() const
+{
+ return encodedSize();
+}
+void Message::decodeHeader(framing::Buffer& buffer)
+{
+ if (buffer.available() != getSize()) {
+ QPID_LOG(warning, "1.0 Message buffer was " << data.size() << " bytes, but " << buffer.available() << " bytes are available. Resizing.");
+ data.resize(buffer.available());
+ }
+ buffer.getRawData((uint8_t*) getData(), getSize());
+ scan();
+ QPID_LOG(debug, "Decoded 1.0 message of " << getSize() << " bytes, including " << bareMessage.size << " bytes of 'bare message'");
+}
+void Message::decodeContent(framing::Buffer& /*buffer*/) {}
+
+boost::intrusive_ptr<PersistableMessage> Message::merge(const std::map<std::string, qpid::types::Variant>& annotations) const
+{
+ //message- or delivery- annotations? would have to determine that from the name, for now assume always message-annotations
+ size_t extra = 0;
+ if (messageAnnotations) {
+ //TODO: actual merge required
+ } else {
+ //add whole new section
+ extra = qpid::amqp::MessageEncoder::getEncodedSize(annotations, true);
+ }
+ boost::intrusive_ptr<Message> copy(new Message(data.size()+extra));
+ size_t position(0);
+ if (deliveryAnnotations) {
+ ::memcpy(&copy->data[position], deliveryAnnotations.data, deliveryAnnotations.size);
+ position += deliveryAnnotations.size;
+ }
+ if (messageAnnotations) {
+ //TODO: actual merge required
+ ::memcpy(&copy->data[position], messageAnnotations.data, messageAnnotations.size);
+ position += messageAnnotations.size;
+ } else {
+ qpid::amqp::MessageEncoder encoder(&copy->data[position], extra);
+ encoder.writeMap(annotations, &qpid::amqp::message::MESSAGE_ANNOTATIONS, true);
+ position += extra;
+ }
+ if (bareMessage) {
+ ::memcpy(&copy->data[position], bareMessage.data, bareMessage.size);
+ position += bareMessage.size;
+ }
+ if (footer) {
+ ::memcpy(&copy->data[position], footer.data, footer.size);
+ position += footer.size;
+ }
+ copy->scan();
+ return copy;
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Message.h b/cpp/src/qpid/broker/amqp/Message.h
new file mode 100644
index 0000000000..cc3406f72a
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Message.h
@@ -0,0 +1,148 @@
+#ifndef QPID_BROKER_AMQP_MESSAGE_H
+#define QPID_BROKER_AMQP_MESSAGE_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/Message.h"
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/amqp/MessageId.h"
+#include "qpid/amqp/MessageReader.h"
+#include <boost/optional.hpp>
+
+namespace qpid {
+namespace framing {
+class Buffer;
+}
+namespace broker {
+namespace amqp {
+
+/**
+ * Represents an AMQP 1.0 format message
+ */
+class Message : public qpid::broker::Message::Encoding, private qpid::amqp::MessageReader, public qpid::broker::PersistableMessage
+{
+ public:
+ //Encoding interface:
+ std::string getRoutingKey() const;
+ bool isPersistent() const;
+ uint8_t getPriority() const;
+ uint64_t getContentSize() const;
+ std::string getPropertyAsString(const std::string& key) const;
+ std::string getAnnotationAsString(const std::string& key) const;
+ bool getTtl(uint64_t&) const;
+ std::string getContent() const;
+ void processProperties(MapHandler&) const;
+ std::string getUserId() const;
+
+ qpid::amqp::MessageId getMessageId() const;
+ qpid::amqp::CharSequence getReplyTo() const;
+ qpid::amqp::MessageId getCorrelationId() const;
+ qpid::amqp::CharSequence getContentType() const;
+ qpid::amqp::CharSequence getContentEncoding() const;
+
+ qpid::amqp::CharSequence getDeliveryAnnotations() const;
+ qpid::amqp::CharSequence getMessageAnnotations() const;
+ qpid::amqp::CharSequence getApplicationProperties() const;
+ qpid::amqp::CharSequence getBareMessage() const;
+ qpid::amqp::CharSequence getBody() const;
+ qpid::amqp::CharSequence getFooter() const;
+
+ Message(size_t size);
+ char* getData();
+ const char* getData() const;
+ size_t getSize() const;
+ void scan();
+
+ //PersistableMessage interface:
+ void encode(framing::Buffer& buffer) const;
+ uint32_t encodedSize() const;
+ void decodeHeader(framing::Buffer& buffer);
+ void decodeContent(framing::Buffer& buffer);
+ uint32_t encodedHeaderSize() const;
+ boost::intrusive_ptr<PersistableMessage> merge(const std::map<std::string, qpid::types::Variant>& annotations) const;
+
+ static const Message& get(const qpid::broker::Message&);
+ private:
+ std::vector<char> data;
+
+ //header:
+ boost::optional<bool> durable;
+ boost::optional<uint8_t> priority;
+ boost::optional<uint32_t> ttl;
+ boost::optional<bool> firstAcquirer;
+ boost::optional<uint32_t> deliveryCount;
+ //annotations:
+ qpid::amqp::CharSequence deliveryAnnotations;
+ qpid::amqp::CharSequence messageAnnotations;
+
+ qpid::amqp::CharSequence bareMessage;//properties, application-properties and content
+ //properties:
+ qpid::amqp::MessageId messageId;
+ qpid::amqp::CharSequence userId;
+ qpid::amqp::CharSequence to;
+ qpid::amqp::CharSequence subject;
+ qpid::amqp::CharSequence replyTo;
+ qpid::amqp::MessageId correlationId;
+ qpid::amqp::CharSequence contentType;
+ qpid::amqp::CharSequence contentEncoding;
+
+ //application-properties:
+ qpid::amqp::CharSequence applicationProperties;
+
+ //body:
+ qpid::amqp::CharSequence body;
+
+ //footer:
+ qpid::amqp::CharSequence footer;
+
+ //header:
+ void onDurable(bool b);
+ void onPriority(uint8_t i);
+ void onTtl(uint32_t i);
+ void onFirstAcquirer(bool b);
+ void onDeliveryCount(uint32_t i);
+ //properties:
+ void onMessageId(uint64_t);
+ void onMessageId(const qpid::amqp::CharSequence&, qpid::types::VariantType);
+ void onUserId(const qpid::amqp::CharSequence& v);
+ void onTo(const qpid::amqp::CharSequence& v);
+ void onSubject(const qpid::amqp::CharSequence& v);
+ void onReplyTo(const qpid::amqp::CharSequence& v);
+ void onCorrelationId(uint64_t);
+ void onCorrelationId(const qpid::amqp::CharSequence&, qpid::types::VariantType);
+ void onContentType(const qpid::amqp::CharSequence& v);
+ void onContentEncoding(const qpid::amqp::CharSequence& v);
+ void onAbsoluteExpiryTime(int64_t i);
+ void onCreationTime(int64_t);
+ void onGroupId(const qpid::amqp::CharSequence&);
+ void onGroupSequence(uint32_t);
+ void onReplyToGroupId(const qpid::amqp::CharSequence&);
+
+ void onApplicationProperties(const qpid::amqp::CharSequence&);
+ void onDeliveryAnnotations(const qpid::amqp::CharSequence&);
+ void onMessageAnnotations(const qpid::amqp::CharSequence&);
+ void onBody(const qpid::amqp::CharSequence&, const qpid::amqp::Descriptor&);
+ void onBody(const qpid::types::Variant&, const qpid::amqp::Descriptor&);
+ void onFooter(const qpid::amqp::CharSequence&);
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_MESSAGE_H*/
diff --git a/cpp/src/qpid/broker/amqp/NodeProperties.cpp b/cpp/src/qpid/broker/amqp/NodeProperties.cpp
new file mode 100644
index 0000000000..eea7612cb9
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/NodeProperties.cpp
@@ -0,0 +1,179 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/NodeProperties.h"
+#include "qpid/broker/amqp/DataReader.h"
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/types/Variant.h"
+#include "qpid/broker/QueueSettings.h"
+#include "qpid/log/Statement.h"
+
+using qpid::amqp::CharSequence;
+using qpid::amqp::Descriptor;
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+namespace {
+//distribution modes:
+const std::string MOVE("move");
+const std::string COPY("copy");
+const std::string SUPPORTED_DIST_MODES("supported-dist-modes");
+
+//AMQP 0-10 standard parameters:
+const std::string DURABLE("durable");
+const std::string AUTO_DELETE("auto-delete");
+const std::string ALTERNATE_EXCHANGE("alternate-exchange");
+const std::string EXCHANGE_TYPE("exchange-type");
+}
+
+NodeProperties::NodeProperties() : queue(true), durable(false), autoDelete(false), exchangeType("topic") {}
+
+void NodeProperties::read(pn_data_t* data)
+{
+ DataReader reader(*this);
+ reader.read(data);
+}
+
+void NodeProperties::process(const std::string& key, const qpid::types::Variant& value)
+{
+ QPID_LOG(notice, "Processing node property " << key << " = " << value);
+ if (key == SUPPORTED_DIST_MODES) {
+ if (value == MOVE) queue = true;
+ else if (value == COPY) queue = false;
+ } else if (key == DURABLE) {
+ durable = value;
+ } else if (key == AUTO_DELETE) {
+ autoDelete = value;
+ } else if (key == ALTERNATE_EXCHANGE) {
+ alternateExchange = value.asString();
+ } else if (key == EXCHANGE_TYPE) {
+ exchangeType = value.asString();
+ } else {
+ properties[key] = value;
+ }
+}
+
+void NodeProperties::onNullValue(const CharSequence& key, const Descriptor*)
+{
+ process(key.str(), qpid::types::Variant());
+}
+
+void NodeProperties::onBooleanValue(const CharSequence& key, bool value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onUByteValue(const CharSequence& key, uint8_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onUShortValue(const CharSequence& key, uint16_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onUIntValue(const CharSequence& key, uint32_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onULongValue(const CharSequence& key, uint64_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onByteValue(const CharSequence& key, int8_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onShortValue(const CharSequence& key, int16_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onIntValue(const CharSequence& key, int32_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onLongValue(const CharSequence& key, int64_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onFloatValue(const CharSequence& key, float value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onDoubleValue(const CharSequence& key, double value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onUuidValue(const CharSequence& key, const CharSequence& value, const Descriptor*)
+{
+ process(key.str(), value.str());
+}
+
+void NodeProperties::onTimestampValue(const CharSequence& key, int64_t value, const Descriptor*)
+{
+ process(key.str(), value);
+}
+
+void NodeProperties::onStringValue(const CharSequence& key, const CharSequence& value, const Descriptor*)
+{
+ process(key.str(), value.str());
+}
+
+void NodeProperties::onSymbolValue(const CharSequence& key, const CharSequence& value, const Descriptor*)
+{
+ process(key.str(), value.str());
+}
+
+QueueSettings NodeProperties::getQueueSettings()
+{
+ QueueSettings settings(durable, autoDelete);
+ qpid::types::Variant::Map unused;
+ settings.populate(properties, unused);
+ return settings;
+}
+
+bool NodeProperties::isQueue() const
+{
+ return queue;
+}
+bool NodeProperties::isDurable() const
+{
+ return durable;
+}
+std::string NodeProperties::getExchangeType() const
+{
+ return exchangeType;
+}
+std::string NodeProperties::getAlternateExchange() const
+{
+ return alternateExchange;
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/NodeProperties.h b/cpp/src/qpid/broker/amqp/NodeProperties.h
new file mode 100644
index 0000000000..b81d1d712c
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/NodeProperties.h
@@ -0,0 +1,71 @@
+#ifndef QPID_BROKER_AMQP_NODEPROPERTIES_H
+#define QPID_BROKER_AMQP_NODEPROPERTIES_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/MapReader.h"
+#include "qpid/types/Variant.h"
+
+struct pn_data_t;
+namespace qpid {
+namespace broker {
+struct QueueSettings;
+namespace amqp {
+
+class NodeProperties : public qpid::amqp::MapReader
+{
+ public:
+ NodeProperties();
+ void read(pn_data_t*);
+ void onNullValue(const qpid::amqp::CharSequence&, const qpid::amqp::Descriptor*);
+ void onBooleanValue(const qpid::amqp::CharSequence&, bool, const qpid::amqp::Descriptor*);
+ void onUByteValue(const qpid::amqp::CharSequence&, uint8_t, const qpid::amqp::Descriptor*);
+ void onUShortValue(const qpid::amqp::CharSequence&, uint16_t, const qpid::amqp::Descriptor*);
+ void onUIntValue(const qpid::amqp::CharSequence&, uint32_t, const qpid::amqp::Descriptor*);
+ void onULongValue(const qpid::amqp::CharSequence&, uint64_t, const qpid::amqp::Descriptor*);
+ void onByteValue(const qpid::amqp::CharSequence&, int8_t, const qpid::amqp::Descriptor*);
+ void onShortValue(const qpid::amqp::CharSequence&, int16_t, const qpid::amqp::Descriptor*);
+ void onIntValue(const qpid::amqp::CharSequence&, int32_t, const qpid::amqp::Descriptor*);
+ void onLongValue(const qpid::amqp::CharSequence&, int64_t, const qpid::amqp::Descriptor*);
+ void onFloatValue(const qpid::amqp::CharSequence&, float, const qpid::amqp::Descriptor*);
+ void onDoubleValue(const qpid::amqp::CharSequence&, double, const qpid::amqp::Descriptor*);
+ void onUuidValue(const qpid::amqp::CharSequence&, const qpid::amqp::CharSequence&, const qpid::amqp::Descriptor*);
+ void onTimestampValue(const qpid::amqp::CharSequence&, int64_t, const qpid::amqp::Descriptor*);
+ void onStringValue(const qpid::amqp::CharSequence&, const qpid::amqp::CharSequence&, const qpid::amqp::Descriptor*);
+ void onSymbolValue(const qpid::amqp::CharSequence&, const qpid::amqp::CharSequence&, const qpid::amqp::Descriptor*);
+ bool isQueue() const;
+ QueueSettings getQueueSettings();
+ bool isDurable() const;
+ std::string getExchangeType() const;
+ std::string getAlternateExchange() const;
+ private:
+ bool queue;
+ bool durable;
+ bool autoDelete;
+ std::string exchangeType;
+ std::string alternateExchange;
+ qpid::types::Variant::Map properties;
+
+ void process(const std::string&, const qpid::types::Variant&);
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_NODEPROPERTIES_H*/
diff --git a/cpp/src/qpid/broker/amqp/Outgoing.cpp b/cpp/src/qpid/broker/amqp/Outgoing.cpp
new file mode 100644
index 0000000000..9605cacac1
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Outgoing.cpp
@@ -0,0 +1,244 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/Outgoing.h"
+#include "qpid/broker/amqp/Header.h"
+#include "qpid/broker/amqp/Translation.h"
+#include "qpid/broker/Queue.h"
+#include "qpid/broker/TopicKeyNode.h"
+#include "qpid/sys/OutputControl.h"
+#include "qpid/amqp/MessageEncoder.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+Outgoing::Outgoing(Broker& broker, boost::shared_ptr<Queue> q, pn_link_t* l, ManagedSession& session, qpid::sys::OutputControl& o, bool topic)
+ : Consumer(pn_link_name(l), /*FIXME*/CONSUMER),
+ ManagedOutgoingLink(broker, *q, session, pn_link_name(l), topic),
+ exclusive(topic),
+ queue(q), deliveries(5000), link(l), out(o),
+ current(0), outstanding(0),
+ buffer(1024)/*used only for header at present*/
+{
+ for (size_t i = 0 ; i < deliveries.capacity(); ++i) {
+ deliveries[i].init(i);
+ }
+}
+
+void Outgoing::init()
+{
+ queue->consume(shared_from_this(), exclusive);//may throw exception
+}
+
+bool Outgoing::dispatch()
+{
+ QPID_LOG(trace, "Dispatching to " << getName() << ": " << pn_link_credit(link));
+ if (canDeliver()) {
+ if (queue->dispatch(shared_from_this())) {
+ return true;
+ } else {
+ pn_link_drained(link);
+ QPID_LOG(debug, "No message available on " << queue->getName());
+ }
+ } else {
+ QPID_LOG(debug, "Can't deliver to " << getName() << " from " << queue->getName() << ": " << pn_link_credit(link));
+ }
+ return false;
+}
+
+void Outgoing::write(const char* data, size_t size)
+{
+ pn_link_send(link, data, size);
+}
+
+void Outgoing::handle(pn_delivery_t* delivery)
+{
+ pn_delivery_tag_t tag = pn_delivery_tag(delivery);
+ size_t i = *reinterpret_cast<const size_t*>(tag.bytes);
+ Record& r = deliveries[i];
+ if (pn_delivery_writable(delivery)) {
+ assert(r.msg);
+ assert(!r.delivery);
+ r.delivery = delivery;
+ //write header
+ qpid::amqp::MessageEncoder encoder(&buffer[0], buffer.size());
+ encoder.writeHeader(Header(r.msg));
+ write(&buffer[0], encoder.getPosition());
+ Translation t(r.msg);
+ t.write(*this);
+ if (pn_link_advance(link)) {
+ --outstanding;
+ outgoingMessageSent();
+ QPID_LOG(debug, "Sent message " << r.msg.getSequence() << " from " << queue->getName() << ", index=" << r.index);
+ } else {
+ QPID_LOG(error, "Failed to send message " << r.msg.getSequence() << " from " << queue->getName() << ", index=" << r.index);
+ }
+ }
+ if (pn_delivery_updated(delivery)) {
+ assert(r.delivery == delivery);
+ r.disposition = pn_delivery_remote_state(delivery);
+ if (r.disposition) {
+ switch (r.disposition) {
+ case PN_ACCEPTED:
+ //TODO: only if consuming
+ queue->dequeue(0, r.cursor);
+ outgoingMessageAccepted();
+ break;
+ case PN_REJECTED:
+ queue->reject(r.cursor);
+ outgoingMessageRejected();
+ break;
+ case PN_RELEASED:
+ queue->release(r.cursor, false);//TODO: for PN_RELEASED, delivery count should not be incremented
+ outgoingMessageRejected();//TODO: not quite true...
+ break;
+ case PN_MODIFIED:
+ queue->release(r.cursor, true);//TODO: proper handling of modified
+ outgoingMessageRejected();//TODO: not quite true...
+ break;
+ default:
+ QPID_LOG(warning, "Unhandled disposition: " << r.disposition);
+ }
+ //TODO: ony settle once any dequeue on store has completed
+ pn_delivery_settle(delivery);
+ r.reset();
+ }
+ }
+}
+
+bool Outgoing::canDeliver()
+{
+ return deliveries[current].delivery == 0 && pn_link_credit(link) > outstanding;
+}
+
+void Outgoing::detached()
+{
+ QPID_LOG(debug, "Detaching outgoing link from " << queue->getName());
+ queue->cancel(shared_from_this());
+ //TODO: release in a clearer order?
+ for (size_t i = 0 ; i < deliveries.capacity(); ++i) {
+ if (deliveries[i].msg) queue->release(deliveries[i].cursor, true);
+ }
+ Queue::tryAutoDelete(*queue->getBroker(), queue, "", "");
+}
+
+//Consumer interface:
+bool Outgoing::deliver(const QueueCursor& cursor, const qpid::broker::Message& msg)
+{
+ Record& r = deliveries[current++];
+ if (current >= deliveries.capacity()) current = 0;
+ r.cursor = cursor;
+ r.msg = msg;
+ pn_delivery(link, r.tag);
+ QPID_LOG(debug, "Requested delivery of " << r.msg.getSequence() << " from " << queue->getName() << ", index=" << r.index);
+ ++outstanding;
+ return true;
+}
+
+void Outgoing::notify()
+{
+ QPID_LOG(trace, "Notification received for " << queue->getName());
+ out.activateOutput();
+}
+
+bool Outgoing::accept(const qpid::broker::Message&)
+{
+ return true;
+}
+
+void Outgoing::setSubjectFilter(const std::string& f)
+{
+ subjectFilter = f;
+}
+
+namespace {
+
+bool match(TokenIterator& filter, TokenIterator& target)
+{
+ bool wild = false;
+ while (!filter.finished())
+ {
+ if (filter.match1('*')) {
+ if (target.finished()) return false;
+ //else move to next word in filter target
+ filter.next();
+ target.next();
+ } else if (filter.match1('#')) {
+ // i.e. filter word is '#' which can match a variable number of words in the target
+ filter.next();
+ if (filter.finished()) return true;
+ else if (target.finished()) return false;
+ wild = true;
+ } else {
+ //filter word needs to match target exactly
+ if (target.finished()) return false;
+ std::string word;
+ target.pop(word);
+ if (filter.match(word)) {
+ wild = false;
+ filter.next();
+ } else if (!wild) {
+ return false;
+ }
+ }
+ }
+ return target.finished();
+}
+bool match(const std::string& filter, const std::string& target)
+{
+ TokenIterator lhs(filter);
+ TokenIterator rhs(target);
+ return match(lhs, rhs);
+}
+}
+
+bool Outgoing::filter(const qpid::broker::Message& m)
+{
+ return subjectFilter.empty() || subjectFilter == m.getRoutingKey() || match(subjectFilter, m.getRoutingKey());
+}
+
+void Outgoing::cancel() {}
+
+void Outgoing::acknowledged(const qpid::broker::DeliveryRecord&) {}
+
+qpid::broker::OwnershipToken* Outgoing::getSession()
+{
+ return 0;
+}
+
+Outgoing::Record::Record() : delivery(0), disposition(0), index(0) {}
+void Outgoing::Record::init(size_t i)
+{
+ index = i;
+ tag.bytes = reinterpret_cast<const char*>(&index);
+ tag.size = sizeof(index);
+}
+void Outgoing::Record::reset()
+{
+ cursor = QueueCursor();
+ msg = qpid::broker::Message();
+ delivery = 0;
+ disposition = 0;
+}
+
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Outgoing.h b/cpp/src/qpid/broker/amqp/Outgoing.h
new file mode 100644
index 0000000000..a8450a48cf
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Outgoing.h
@@ -0,0 +1,108 @@
+#ifndef QPID_BROKER_AMQP1_OUTGOING_H
+#define QPID_BROKER_AMQP1_OUTGOING_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/Message.h"
+#include "qpid/broker/amqp/ManagedOutgoingLink.h"
+#include "qpid/broker/Consumer.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+extern "C" {
+#include <proton/engine.h>
+}
+
+namespace qpid {
+namespace sys {
+class OutputControl;
+}
+namespace broker {
+class Broker;
+class Queue;
+namespace amqp {
+class ManagedSession;
+template <class T>
+class CircularArray
+{
+ public:
+ CircularArray(size_t l) : limit(l), data(new T[limit]) {}
+ T& operator[](size_t i) { return data[i]; }
+ size_t capacity() { return limit; }
+ ~CircularArray() { delete [] data; }
+ private:
+ const size_t limit;
+ T* const data;
+ size_t next;
+};
+
+/**
+ *
+ */
+class Outgoing : public qpid::broker::Consumer, public boost::enable_shared_from_this<Outgoing>, public ManagedOutgoingLink
+{
+ public:
+ Outgoing(Broker&,boost::shared_ptr<Queue> q, pn_link_t* l, ManagedSession&, qpid::sys::OutputControl& o, bool topic);
+ void setSubjectFilter(const std::string&);
+ void init();
+ bool dispatch();
+ void write(const char* data, size_t size);
+ void handle(pn_delivery_t* delivery);
+ bool canDeliver();
+ void detached();
+
+ //Consumer interface:
+ bool deliver(const QueueCursor& cursor, const qpid::broker::Message& msg);
+ void notify();
+ bool accept(const qpid::broker::Message&);
+ bool filter(const qpid::broker::Message&);
+ void cancel();
+ void acknowledged(const qpid::broker::DeliveryRecord&);
+ qpid::broker::OwnershipToken* getSession();
+
+ private:
+
+ struct Record
+ {
+ QueueCursor cursor;
+ qpid::broker::Message msg;
+ pn_delivery_t* delivery;
+ int disposition;
+ size_t index;
+ pn_delivery_tag_t tag;
+
+ Record();
+ void init(size_t i);
+ void reset();
+ };
+
+ const bool exclusive;
+ boost::shared_ptr<Queue> queue;
+ CircularArray<Record> deliveries;
+ pn_link_t* link;
+ qpid::sys::OutputControl& out;
+ size_t current;
+ int outstanding;
+ std::vector<char> buffer;
+ std::string subjectFilter;
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP1_OUTGOING_H*/
diff --git a/cpp/src/qpid/broker/amqp/ProtocolPlugin.cpp b/cpp/src/qpid/broker/amqp/ProtocolPlugin.cpp
new file mode 100644
index 0000000000..711592257c
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/ProtocolPlugin.cpp
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/Plugin.h"
+#include "qpid/SaslFactory.h"
+#include "qpid/NullSaslServer.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/broker/Message.h"
+#include "qpid/broker/Protocol.h"
+#include "qpid/broker/RecoverableMessage.h"
+#include "qpid/broker/RecoverableMessageImpl.h"
+#include "qpid/broker/amqp/Connection.h"
+#include "qpid/broker/amqp/Message.h"
+#include "qpid/broker/amqp/Sasl.h"
+#include "qpid/broker/amqp/Translation.h"
+#include "qpid/broker/amqp_0_10/MessageTransfer.h"
+#include "qpid/framing/Buffer.h"
+#include "qpid/framing/ProtocolVersion.h"
+#include "qpid/sys/ConnectionCodec.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+class ProtocolImpl : public Protocol
+{
+ public:
+ ProtocolImpl(Broker& b) : broker(b) {}
+ qpid::sys::ConnectionCodec* create(const qpid::framing::ProtocolVersion&, qpid::sys::OutputControl&, const std::string&, const qpid::sys::SecuritySettings&);
+ boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> translate(const qpid::broker::Message&);
+ boost::shared_ptr<RecoverableMessage> recover(qpid::framing::Buffer&);
+ private:
+ Broker& broker;
+};
+
+struct ProtocolPlugin : public Plugin
+{
+ void earlyInitialize(Plugin::Target& target)
+ {
+ //need to register protocol before recovery from store
+ broker::Broker* broker = dynamic_cast<qpid::broker::Broker*>(&target);
+ if (broker) {
+ broker->getProtocolRegistry().add("AMQP 1.0", new ProtocolImpl(*broker));
+ }
+ }
+
+ void initialize(Plugin::Target&) {}
+};
+
+ProtocolPlugin instance; // Static initialization
+
+qpid::sys::ConnectionCodec* ProtocolImpl::create(const qpid::framing::ProtocolVersion& v, qpid::sys::OutputControl& out, const std::string& id, const qpid::sys::SecuritySettings& external)
+{
+ if (v == qpid::framing::ProtocolVersion(1, 0)) {
+ if (v.getProtocol() == qpid::framing::ProtocolVersion::SASL) {
+ if (broker.getOptions().auth) {
+ QPID_LOG(info, "Using AMQP 1.0 (with SASL layer)");
+ return new qpid::broker::amqp::Sasl(out, id, broker, qpid::SaslFactory::getInstance().createServer(broker.getOptions().realm, broker.getOptions().requireEncrypted, external));
+ } else {
+ std::auto_ptr<SaslServer> authenticator(new qpid::NullSaslServer(broker.getOptions().realm));
+ QPID_LOG(info, "Using AMQP 1.0 (with dummy SASL layer)");
+ return new qpid::broker::amqp::Sasl(out, id, broker, authenticator);
+ }
+ } else {
+ if (broker.getOptions().auth) {
+ throw qpid::Exception("SASL layer required!");
+ } else {
+ QPID_LOG(info, "Using AMQP 1.0 (no SASL layer)");
+ return new qpid::broker::amqp::Connection(out, id, broker, false);
+ }
+ }
+ }
+ return 0;
+}
+
+boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> ProtocolImpl::translate(const qpid::broker::Message& m)
+{
+ qpid::broker::amqp::Translation t(m);
+ return t.getTransfer();
+}
+
+boost::shared_ptr<RecoverableMessage> ProtocolImpl::recover(qpid::framing::Buffer& buffer)
+{
+ QPID_LOG(debug, "Recovering, checking for 1.0 message format indicator...");
+ uint32_t format = buffer.getLong();
+ if (format == 0) {
+ QPID_LOG(debug, "Recovered message IS in 1.0 format");
+ //this is a 1.0 format message
+ boost::intrusive_ptr<qpid::broker::amqp::Message> m(new qpid::broker::amqp::Message(buffer.available()));
+ m->decodeHeader(buffer);
+ return RecoverableMessage::shared_ptr(new RecoverableMessageImpl(qpid::broker::Message(m, m)));
+ } else {
+ QPID_LOG(debug, "Recovered message is NOT in 1.0 format");
+ return RecoverableMessage::shared_ptr();
+ }
+}
+
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Sasl.cpp b/cpp/src/qpid/broker/amqp/Sasl.cpp
new file mode 100644
index 0000000000..4b89e7b15d
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Sasl.cpp
@@ -0,0 +1,167 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/Sasl.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/log/Statement.h"
+#include "qpid/framing/ProtocolInitiation.h"
+#include "qpid/sys/OutputControl.h"
+#include "qpid/sys/SecurityLayer.h"
+#include <boost/format.hpp>
+#include <vector>
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+Sasl::Sasl(qpid::sys::OutputControl& o, const std::string& id, qpid::broker::Broker& broker, std::auto_ptr<qpid::SaslServer> auth)
+ : qpid::amqp::SaslServer(id), out(o), connection(out, id, broker, true),
+ authenticator(auth),
+ state(INCOMPLETE), writeHeader(true), haveOutput(true)
+{
+ out.activateOutput();
+ mechanisms(authenticator->getMechanisms());
+}
+
+Sasl::~Sasl() {}
+
+size_t Sasl::decode(const char* buffer, size_t size)
+{
+ if (state == AUTHENTICATED) {
+ if (securityLayer.get()) return securityLayer->decode(buffer, size);
+ else return connection.decode(buffer, size);
+ } else if (state == INCOMPLETE && size) {
+ size_t decoded = read(buffer, size);
+ QPID_LOG(trace, id << " Sasl::decode(" << size << "): " << decoded);
+ return decoded;
+ } else {
+ return 0;
+ }
+}
+
+size_t Sasl::encode(char* buffer, size_t size)
+{
+ if (state == AUTHENTICATED) {
+ if (securityLayer.get()) return securityLayer->encode(buffer, size);
+ else return connection.encode(buffer, size);
+ } else {
+ size_t encoded = 0;
+ if (writeHeader) {
+ encoded += writeProtocolHeader(buffer, size);
+ if (!encoded) return 0;
+ writeHeader = false;
+ }
+ if (encoded < size) {
+ encoded += write(buffer + encoded, size - encoded);
+ }
+ if (state == SUCCESS_PENDING) {
+ state = AUTHENTICATED;
+ } else if (state == FAILURE_PENDING) {
+ state = FAILED;
+ } else {
+ haveOutput = (encoded == size);
+ }
+ QPID_LOG(trace, id << " Sasl::encode(" << size << "): " << encoded);
+ return encoded;
+ }
+}
+
+bool Sasl::canEncode()
+{
+ if (state == AUTHENTICATED) {
+ if (securityLayer.get()) return securityLayer->canEncode();
+ else return connection.canEncode();
+ } else {
+ return haveOutput;
+ }
+}
+
+void Sasl::closed()
+{
+ if (state == AUTHENTICATED) {
+ connection.closed();
+ } else {
+ QPID_LOG(info, id << " Connection closed prior to authentication completing");
+ state = FAILED;
+ }
+}
+bool Sasl::isClosed() const
+{
+ if (state == AUTHENTICATED) {
+ return connection.isClosed();
+ } else {
+ return state == FAILED;
+ }
+}
+
+framing::ProtocolVersion Sasl::getVersion() const
+{
+ return connection.getVersion();
+}
+namespace {
+const std::string EMPTY;
+}
+
+void Sasl::init(const std::string& mechanism, const std::string* response, const std::string* /*hostname*/)
+{
+ QPID_LOG_CAT(debug, protocol, id << " Received SASL-INIT(" << mechanism << ", " << (response ? *response : EMPTY) << ")");
+ //TODO: what should we do with hostname here?
+ std::string c;
+ respond(authenticator->start(mechanism, response, c), c);
+ connection.setSaslMechanism(mechanism);
+}
+
+void Sasl::response(const std::string* r)
+{
+ QPID_LOG_CAT(debug, protocol, id << " Received SASL-RESPONSE(" << (r ? *r : EMPTY) << ")");
+ std::string c;
+ respond(authenticator->step(r, c), c);
+}
+
+void Sasl::respond(qpid::SaslServer::Status status, const std::string& chllnge)
+{
+ switch (status) {
+ case qpid::SaslServer::OK:
+ connection.setUserid(authenticator->getUserid());
+ completed(true);
+ //can't set authenticated & failed until we have actually sent the outcome
+ state = SUCCESS_PENDING;
+ securityLayer = authenticator->getSecurityLayer(65535);
+ if (securityLayer.get()) {
+ QPID_LOG_CAT(info, security, id << " Security layer installed");
+ securityLayer->init(&connection);
+ connection.setSaslSsf(securityLayer->getSsf());
+ }
+ QPID_LOG_CAT(info, security, id << " Authenticated as " << authenticator->getUserid());
+ break;
+ case qpid::SaslServer::FAIL:
+ completed(false);
+ state = FAILURE_PENDING;
+ QPID_LOG_CAT(info, security, id << " Failed to authenticate");
+ break;
+ case qpid::SaslServer::CHALLENGE:
+ challenge(&chllnge);
+ QPID_LOG_CAT(info, security, id << " Challenge issued");
+ break;
+ }
+ haveOutput = true;
+ out.activateOutput();
+}
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Sasl.h b/cpp/src/qpid/broker/amqp/Sasl.h
new file mode 100644
index 0000000000..079128be02
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Sasl.h
@@ -0,0 +1,72 @@
+#ifndef QPID_BROKER_AMQP_SASL_H
+#define QPID_BROKER_AMQP_SASL_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/Connection.h"
+#include "qpid/SaslServer.h"
+#include "qpid/amqp/SaslServer.h"
+#include "qpid/sys/ConnectionCodec.h"
+#include <memory>
+namespace qpid {
+namespace sys {
+class SecurityLayer;
+}
+namespace broker {
+namespace amqp {
+
+/**
+ * An AMQP 1.0 SASL Security Layer for authentication and optionally
+ * encryption.
+ */
+class Sasl : public sys::ConnectionCodec, qpid::amqp::SaslServer
+{
+ public:
+ Sasl(qpid::sys::OutputControl& out, const std::string& id, qpid::broker::Broker& broker, std::auto_ptr<qpid::SaslServer> authenticator);
+ ~Sasl();
+
+ size_t decode(const char* buffer, size_t size);
+ size_t encode(char* buffer, size_t size);
+ bool canEncode();
+
+ void closed();
+ bool isClosed() const;
+
+ framing::ProtocolVersion getVersion() const;
+ private:
+ qpid::sys::OutputControl& out;
+ Connection connection;
+ std::auto_ptr<qpid::sys::SecurityLayer> securityLayer;
+ std::auto_ptr<qpid::SaslServer> authenticator;
+ enum {
+ INCOMPLETE, SUCCESS_PENDING, FAILURE_PENDING, AUTHENTICATED, FAILED
+ } state;
+
+ bool writeHeader;
+ bool haveOutput;
+
+ void init(const std::string& mechanism, const std::string* response, const std::string* hostname);
+ void response(const std::string*);
+ void respond(qpid::SaslServer::Status status, const std::string& challenge);
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_SASL_H*/
diff --git a/cpp/src/qpid/broker/amqp/Session.cpp b/cpp/src/qpid/broker/amqp/Session.cpp
new file mode 100644
index 0000000000..fabe609473
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Session.cpp
@@ -0,0 +1,332 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "Session.h"
+#include "Outgoing.h"
+#include "Message.h"
+#include "ManagedConnection.h"
+#include "qpid/broker/AsyncCompletion.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/broker/DeliverableMessage.h"
+#include "qpid/broker/Exchange.h"
+#include "qpid/broker/DirectExchange.h"
+#include "qpid/broker/TopicExchange.h"
+#include "qpid/broker/FanOutExchange.h"
+#include "qpid/broker/Message.h"
+#include "qpid/broker/Queue.h"
+#include "qpid/broker/TopicExchange.h"
+#include "qpid/broker/amqp/Filter.h"
+#include "qpid/broker/amqp/NodeProperties.h"
+#include "qpid/framing/AMQFrame.h"
+#include "qpid/framing/FieldTable.h"
+#include "qpid/framing/MessageTransferBody.h"
+#include "qpid/log/Statement.h"
+#include <boost/intrusive_ptr.hpp>
+#include <boost/format.hpp>
+#include <map>
+#include <sstream>
+extern "C" {
+#include <proton/engine.h>
+}
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+
+class Target
+{
+ public:
+ Target(pn_link_t* l) : credit(100), window(0), link(l) {}
+ virtual ~Target() {}
+ bool flow();
+ bool needFlow();
+ virtual void handle(qpid::broker::Message& m) = 0;//TODO: revise this for proper message
+ protected:
+ const uint32_t credit;
+ uint32_t window;
+ pn_link_t* link;
+};
+
+class Queue : public Target
+{
+ public:
+ Queue(boost::shared_ptr<qpid::broker::Queue> q, pn_link_t* l) : Target(l), queue(q) {}
+ void handle(qpid::broker::Message& m);
+ private:
+ boost::shared_ptr<qpid::broker::Queue> queue;
+};
+
+class Exchange : public Target
+{
+ public:
+ Exchange(boost::shared_ptr<qpid::broker::Exchange> e, pn_link_t* l) : Target(l), exchange(e) {}
+ void handle(qpid::broker::Message& m);
+ private:
+ boost::shared_ptr<qpid::broker::Exchange> exchange;
+};
+
+Session::Session(pn_session_t* s, qpid::broker::Broker& b, ManagedConnection& c, qpid::sys::OutputControl& o)
+ : ManagedSession(b, c, (boost::format("%1%") % s).str()), session(s), broker(b), connection(c), out(o), deleted(false) {}
+
+
+Session::ResolvedNode Session::resolve(const std::string name, pn_terminus_t* terminus)
+{
+ ResolvedNode node;
+ node.exchange = broker.getExchanges().find(name);
+ node.queue = broker.getQueues().find(name);
+ if (!node.queue && !node.exchange && pn_terminus_is_dynamic(terminus)) {
+ //TODO: handle dynamic creation
+ //is it a queue or an exchange?
+ NodeProperties properties;
+ properties.read(pn_terminus_properties(terminus));
+ if (properties.isQueue()) {
+ node.queue = broker.createQueue(name, properties.getQueueSettings(), this, properties.getAlternateExchange(), connection.getUserid(), connection.getId()).first;
+ } else {
+ qpid::framing::FieldTable args;
+ node.exchange = broker.createExchange(name, properties.getExchangeType(), properties.isDurable(), properties.getAlternateExchange(),
+ args, connection.getUserid(), connection.getId()).first;
+ }
+ } else if (node.queue && node.exchange) {
+ QPID_LOG_CAT(warning, protocol, "Ambiguous node name; " << name << " could be queue or exchange, assuming queue");
+ node.exchange.reset();
+ }
+ return node;
+}
+
+void Session::attach(pn_link_t* link)
+{
+ if (pn_link_is_sender(link)) {
+ pn_terminus_t* source = pn_link_remote_source(link);
+ //i.e a subscription
+ if (pn_terminus_get_type(source) == PN_UNSPECIFIED) {
+ throw qpid::Exception("No source specified!");/*invalid-field?*/
+ }
+ std::string name = pn_terminus_get_address(source);
+ QPID_LOG(debug, "Received attach request for outgoing link from " << name);
+ pn_terminus_set_address(pn_link_source(link), name.c_str());
+
+ ResolvedNode node = resolve(name, source);
+ Filter filter;
+ filter.read(pn_terminus_filter(source));
+
+ if (node.queue) {
+ boost::shared_ptr<Outgoing> q(new Outgoing(broker, node.queue, link, *this, out, false));
+ q->init();
+ if (filter.hasSubjectFilter()) {
+ q->setSubjectFilter(filter.getSubjectFilter());
+ }
+ senders[link] = q;
+ } else if (node.exchange) {
+ QueueSettings settings(false, true);
+ //TODO: populate settings from source details when available from engine
+ boost::shared_ptr<qpid::broker::Queue> queue
+ = broker.createQueue(name + qpid::types::Uuid(true).str(), settings, this, "", connection.getUserid(), connection.getId()).first;
+ if (filter.hasSubjectFilter()) {
+ filter.bind(node.exchange, queue);
+ filter.write(pn_terminus_filter(pn_link_source(link)));
+ } else if (node.exchange->getType() == FanOutExchange::typeName) {
+ node.exchange->bind(queue, std::string(), 0);
+ } else if (node.exchange->getType() == TopicExchange::typeName) {
+ node.exchange->bind(queue, "#", 0);
+ } else {
+ throw qpid::Exception("Exchange type requires a filter: " + node.exchange->getType());/*not-supported?*/
+ }
+ boost::shared_ptr<Outgoing> q(new Outgoing(broker, queue, link, *this, out, true));
+ senders[link] = q;
+ q->init();
+ } else {
+ pn_terminus_set_type(pn_link_source(link), PN_UNSPECIFIED);
+ throw qpid::Exception("Node not found: " + name);/*not-found*/
+ }
+ QPID_LOG(debug, "Outgoing link attached");
+ } else {
+ pn_terminus_t* target = pn_link_remote_target(link);
+ if (pn_terminus_get_type(target) == PN_UNSPECIFIED) {
+ throw qpid::Exception("No target specified!");/*invalid field?*/
+ }
+ std::string name = pn_terminus_get_address(target);
+ QPID_LOG(debug, "Received attach request for incoming link to " << name);
+ pn_terminus_set_address(pn_link_target(link), name.c_str());
+
+ ResolvedNode node = resolve(name, target);
+
+ if (node.queue) {
+ boost::shared_ptr<Target> q(new Queue(node.queue, link));
+ targets[link] = q;
+ } else if (node.exchange) {
+ boost::shared_ptr<Target> e(new Exchange(node.exchange, link));
+ targets[link] = e;
+ } else {
+ pn_terminus_set_type(pn_link_target(link), PN_UNSPECIFIED);
+ throw qpid::Exception("Node not found: " + name);/*not-found*/
+ }
+ QPID_LOG(debug, "Incoming link attached");
+ }
+}
+
+void Session::detach(pn_link_t* link)
+{
+ if (pn_link_is_sender(link)) {
+ Senders::iterator i = senders.find(link);
+ if (i != senders.end()) {
+ i->second->detached();
+ senders.erase(i);
+ QPID_LOG(debug, "Outgoing link detached");
+ }
+ } else {
+ targets.erase(link);
+ QPID_LOG(debug, "Incoming link detached");
+ }
+}
+namespace {
+ class Transfer : public qpid::broker::AsyncCompletion::Callback
+ {
+ public:
+ Transfer(pn_delivery_t* d, boost::shared_ptr<Session> s) : delivery(d), session(s) {}
+ void completed(bool sync) { session->accepted(delivery, sync); }
+ boost::intrusive_ptr<qpid::broker::AsyncCompletion::Callback> clone()
+ {
+ boost::intrusive_ptr<qpid::broker::AsyncCompletion::Callback> copy(new Transfer(delivery, session));
+ return copy;
+ }
+ private:
+ pn_delivery_t* delivery;
+ boost::shared_ptr<Session> session;
+ };
+}
+
+void Session::accepted(pn_delivery_t* delivery, bool sync)
+{
+ if (sync) {
+ //this is on IO thread
+ pn_delivery_update(delivery, PN_ACCEPTED);
+ pn_delivery_settle(delivery);//do we need to check settlement modes/orders?
+ incomingMessageAccepted();
+ } else {
+ //this is not on IO thread, need to delay processing until on IO thread
+ qpid::sys::Mutex::ScopedLock l(lock);
+ if (!deleted) {
+ completed.push_back(delivery);
+ out.activateOutput();
+ }
+ }
+}
+
+void Session::incoming(pn_link_t* link, pn_delivery_t* delivery)
+{
+ pn_delivery_tag_t tag = pn_delivery_tag(delivery);
+ QPID_LOG(debug, "received delivery: " << std::string(tag.bytes, tag.size));
+ boost::intrusive_ptr<Message> received(new Message(pn_delivery_pending(delivery)));
+ /*ssize_t read = */pn_link_recv(link, received->getData(), received->getSize());
+ received->scan();
+ pn_link_advance(link);
+
+ qpid::broker::Message message(received, received);
+
+ incomingMessageReceived();
+ Targets::iterator target = targets.find(link);
+ if (target == targets.end()) {
+ QPID_LOG(error, "Received message on unknown link");
+ pn_delivery_update(delivery, PN_REJECTED);
+ pn_delivery_settle(delivery);//do we need to check settlement modes/orders?
+ incomingMessageRejected();
+ } else {
+ target->second->handle(message);
+ received->begin();
+ Transfer t(delivery, shared_from_this());
+ received->end(t);
+ if (target->second->needFlow()) out.activateOutput();
+ }
+}
+void Session::outgoing(pn_link_t* link, pn_delivery_t* delivery)
+{
+ Senders::iterator sender = senders.find(link);
+ if (sender == senders.end()) {
+ QPID_LOG(error, "Delivery returned for unknown link");
+ } else {
+ sender->second->handle(delivery);
+ }
+}
+
+bool Session::dispatch()
+{
+ bool output(false);
+ for (Senders::iterator s = senders.begin(); s != senders.end(); ++s) {
+ if (s->second->dispatch()) output = true;
+ }
+ if (completed.size()) {
+ output = true;
+ std::deque<pn_delivery_t*> copy;
+ {
+ qpid::sys::Mutex::ScopedLock l(lock);
+ completed.swap(copy);
+ }
+ for (std::deque<pn_delivery_t*>::iterator i = copy.begin(); i != copy.end(); ++i) {
+ accepted(*i, true);
+ }
+ }
+ for (Targets::iterator t = targets.begin(); t != targets.end(); ++t) {
+ if (t->second->flow()) output = true;
+ }
+
+ return output;
+}
+
+void Session::close()
+{
+ for (Senders::iterator i = senders.begin(); i != senders.end(); ++i) {
+ i->second->detached();
+ }
+ senders.clear();
+ targets.clear();//at present no explicit cleanup required for targets
+ QPID_LOG(debug, "Session closed, all senders cancelled.");
+ qpid::sys::Mutex::ScopedLock l(lock);
+ deleted = true;
+}
+
+void Queue::handle(qpid::broker::Message& message)
+{
+ queue->deliver(message);
+ --window;
+}
+
+void Exchange::handle(qpid::broker::Message& message)
+{
+ DeliverableMessage deliverable(message, 0);
+ exchange->route(deliverable);
+ --window;
+}
+
+bool Target::flow()
+{
+ bool issue = window < credit;
+ if (issue) {
+ pn_link_flow(link, credit - window);//TODO: proper flow control
+ window = credit;
+ }
+ return issue;
+}
+
+bool Target::needFlow()
+{
+ return window <= (credit/2);
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Session.h b/cpp/src/qpid/broker/amqp/Session.h
new file mode 100644
index 0000000000..7dbdaf05fc
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Session.h
@@ -0,0 +1,87 @@
+#ifndef QPID_BROKER_AMQP1_SESSION_H
+#define QPID_BROKER_AMQP1_SESSION_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/sys/Mutex.h"
+#include "qpid/sys/OutputControl.h"
+#include "qpid/broker/amqp/ManagedSession.h"
+#include <deque>
+#include <map>
+#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+
+struct pn_delivery_t;
+struct pn_link_t;
+struct pn_session_t;
+struct pn_terminus_t;
+
+namespace qpid {
+namespace broker {
+
+class Broker;
+class Exchange;
+class Queue;
+
+namespace amqp {
+
+class ManagedConnection;
+class Outgoing;
+class Target;
+/**
+ *
+ */
+class Session : public ManagedSession, public boost::enable_shared_from_this<Session>
+{
+ public:
+ Session(pn_session_t*, qpid::broker::Broker&, ManagedConnection&, qpid::sys::OutputControl&);
+ void attach(pn_link_t*);
+ void detach(pn_link_t*);
+ void incoming(pn_link_t*, pn_delivery_t*);
+ void outgoing(pn_link_t*, pn_delivery_t*);
+ bool dispatch();
+ void close();
+
+ //called when a transfer is completly processed (e.g.including stored on disk)
+ void accepted(pn_delivery_t*, bool sync);
+ private:
+ typedef std::map<pn_link_t*, boost::shared_ptr<Outgoing> > Senders;
+ typedef std::map<pn_link_t*, boost::shared_ptr<Target> > Targets;
+ pn_session_t* session;
+ qpid::broker::Broker& broker;
+ ManagedConnection& connection;
+ qpid::sys::OutputControl& out;
+ Targets targets;
+ Senders senders;
+ std::deque<pn_delivery_t*> completed;
+ bool deleted;
+ qpid::sys::Mutex lock;
+ struct ResolvedNode
+ {
+ boost::shared_ptr<qpid::broker::Exchange> exchange;
+ boost::shared_ptr<qpid::broker::Queue> queue;
+ };
+
+ ResolvedNode resolve(const std::string name, pn_terminus_t* terminus);
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP1_SESSION_H*/
diff --git a/cpp/src/qpid/broker/amqp/Translation.cpp b/cpp/src/qpid/broker/amqp/Translation.cpp
new file mode 100644
index 0000000000..ca2094b965
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Translation.cpp
@@ -0,0 +1,241 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/broker/amqp/Translation.h"
+#include "qpid/broker/amqp/Outgoing.h"
+#include "qpid/broker/amqp_0_10/MessageTransfer.h"
+#include "qpid/amqp/Decoder.h"
+#include "qpid/amqp/descriptors.h"
+#include "qpid/amqp/MessageEncoder.h"
+#include "qpid/amqp_0_10/Codecs.h"
+#include "qpid/types/Variant.h"
+#include "qpid/framing/MessageTransferBody.h"
+#include "qpid/log/Statement.h"
+#include <boost/lexical_cast.hpp>
+
+namespace qpid {
+namespace broker {
+namespace amqp {
+namespace {
+
+const std::string EMPTY;
+const std::string FORWARD_SLASH("/");
+
+std::string translate(const qpid::framing::ReplyTo r)
+{
+ if (r.hasExchange()) {
+ if (r.hasRoutingKey()) return r.getExchange() + FORWARD_SLASH + r.getRoutingKey();
+ else return r.getExchange();
+ } else return r.getRoutingKey();
+}
+std::string translate(const qpid::amqp::CharSequence& chars)
+{
+ if (chars.data && chars.size) return std::string(chars.data, chars.size);
+ else return EMPTY;
+}
+bool setMessageId(qpid::framing::MessageProperties& m, const qpid::amqp::CharSequence& chars)
+{
+ if (chars.data && chars.size) {
+ if (chars.size == 16) {
+ m.setMessageId(qpid::framing::Uuid(chars.data));
+ return true;
+ } else {
+ std::istringstream in(translate(chars));
+ qpid::framing::Uuid uuid;
+ in >> uuid;
+ if (!in.fail()) {
+ m.setMessageId(uuid);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+class Properties_0_10 : public qpid::amqp::MessageEncoder::Properties
+{
+ public:
+ bool hasMessageId() const { return messageProperties && messageProperties->hasMessageId(); }
+ std::string getMessageId() const { return messageProperties ? messageProperties->getMessageId().str() : EMPTY; }
+ bool hasUserId() const { return messageProperties && messageProperties->hasUserId(); }
+ std::string getUserId() const { return messageProperties ? messageProperties->getUserId() : EMPTY; }
+ bool hasTo() const { return getDestination().size() || hasSubject(); }
+ std::string getTo() const { return getDestination().size() ? getDestination() : getSubject(); }
+ bool hasSubject() const { return deliveryProperties && getDestination().size() && deliveryProperties->hasRoutingKey(); }
+ std::string getSubject() const { return deliveryProperties && getDestination().size() ? deliveryProperties->getRoutingKey() : EMPTY; }
+ bool hasReplyTo() const { return messageProperties && messageProperties->hasReplyTo(); }
+ std::string getReplyTo() const { return messageProperties ? translate(messageProperties->getReplyTo()) : EMPTY; }
+ bool hasCorrelationId() const { return messageProperties && messageProperties->hasCorrelationId(); }
+ std::string getCorrelationId() const { return messageProperties ? messageProperties->getCorrelationId() : EMPTY; }
+ bool hasContentType() const { return messageProperties && messageProperties->hasContentType(); }
+ std::string getContentType() const { return messageProperties ? messageProperties->getContentType() : EMPTY; }
+ bool hasContentEncoding() const { return messageProperties && messageProperties->hasContentEncoding(); }
+ std::string getContentEncoding() const { return messageProperties ? messageProperties->getContentEncoding() : EMPTY; }
+ bool hasAbsoluteExpiryTime() const { return deliveryProperties && deliveryProperties->hasExpiration(); }
+ int64_t getAbsoluteExpiryTime() const { return deliveryProperties ? deliveryProperties->getExpiration() : 0; }
+ bool hasCreationTime() const { return false; }
+ int64_t getCreationTime() const { return 0; }
+ bool hasGroupId() const {return false; }
+ std::string getGroupId() const { return EMPTY; }
+ bool hasGroupSequence() const { return false; }
+ uint32_t getGroupSequence() const { return 0; }
+ bool hasReplyToGroupId() const { return false; }
+ std::string getReplyToGroupId() const { return EMPTY; }
+
+ const qpid::framing::FieldTable& getApplicationProperties() { return messageProperties->getApplicationHeaders(); }
+ Properties_0_10(const qpid::broker::amqp_0_10::MessageTransfer& t) : transfer(t),
+ messageProperties(transfer.getProperties<qpid::framing::MessageProperties>()),
+ deliveryProperties(transfer.getProperties<qpid::framing::DeliveryProperties>())
+ {}
+ private:
+ const qpid::broker::amqp_0_10::MessageTransfer& transfer;
+ const qpid::framing::MessageProperties* messageProperties;
+ const qpid::framing::DeliveryProperties* deliveryProperties;
+
+ std::string getDestination() const
+ {
+ return transfer.getMethod<qpid::framing::MessageTransferBody>()->getDestination();
+ }
+};
+}
+
+Translation::Translation(const qpid::broker::Message& m) : original(m) {}
+
+
+boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> Translation::getTransfer()
+{
+ boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> t =
+ boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer>(dynamic_cast<const qpid::broker::amqp_0_10::MessageTransfer*>(&original.getEncoding()));
+ if (t) {
+ return t;//no translation required
+ } else {
+ const Message* message = dynamic_cast<const Message*>(&original.getEncoding());
+ if (message) {
+ //translate 1.0 message into 0-10
+ boost::intrusive_ptr<qpid::broker::amqp_0_10::MessageTransfer> transfer(new qpid::broker::amqp_0_10::MessageTransfer());
+ qpid::framing::AMQFrame method((qpid::framing::MessageTransferBody(qpid::framing::ProtocolVersion(), EMPTY, 0, 0)));
+ qpid::framing::AMQFrame header((qpid::framing::AMQHeaderBody()));
+ qpid::framing::AMQFrame content((qpid::framing::AMQContentBody()));
+ method.setEof(false);
+ header.setBof(false);
+ header.setEof(false);
+ content.setBof(false);
+
+ transfer->getFrames().append(method);
+ transfer->getFrames().append(header);
+
+ qpid::amqp::CharSequence body = message->getBody();
+ content.castBody<qpid::framing::AMQContentBody>()->getData().assign(body.data, body.size);
+ transfer->getFrames().append(content);
+
+ qpid::framing::MessageProperties* props =
+ transfer->getFrames().getHeaders()->get<qpid::framing::MessageProperties>(true);
+ props->setContentLength(body.size);
+
+ qpid::amqp::MessageId mid = message->getMessageId();
+ qpid::framing::Uuid uuid;
+ switch (mid.type) {
+ case qpid::amqp::MessageId::UUID:
+ case qpid::amqp::MessageId::BYTES:
+ if (mid.value.bytes.size == 0) break;
+ if (setMessageId(*props, mid.value.bytes)) break;
+ case qpid::amqp::MessageId::ULONG:
+ QPID_LOG(info, "Skipping message id in translation from 1.0 to 0-10 as it is not a UUID");
+ break;
+ }
+
+ qpid::amqp::MessageId cid = message->getCorrelationId();
+ switch (cid.type) {
+ case qpid::amqp::MessageId::UUID:
+ assert(cid.value.bytes.size = 16);
+ props->setCorrelationId(qpid::framing::Uuid(cid.value.bytes.data).str());
+ break;
+ case qpid::amqp::MessageId::BYTES:
+ if (cid.value.bytes.size) {
+ props->setCorrelationId(translate(cid.value.bytes));
+ }
+ break;
+ case qpid::amqp::MessageId::ULONG:
+ props->setCorrelationId(boost::lexical_cast<std::string>(cid.value.ulong));
+ break;
+ }
+ // TODO: ReplyTo - there is no way to reliably determine
+ // the type of the node from just its name, unless we
+ // query the brokers registries
+
+ if (message->getContentType()) props->setContentType(translate(message->getContentType()));
+ if (message->getContentEncoding()) props->setContentEncoding(translate(message->getContentEncoding()));
+ props->setUserId(message->getUserId());
+ // TODO: FieldTable applicationHeaders;
+ qpid::amqp::CharSequence ap = message->getApplicationProperties();
+ if (ap) {
+ qpid::amqp::Decoder d(ap.data, ap.size);
+ qpid::amqp_0_10::translate(d.readMap(), props->getApplicationHeaders());
+ }
+
+ qpid::framing::DeliveryProperties* dp =
+ transfer->getFrames().getHeaders()->get<qpid::framing::DeliveryProperties>(true);
+ dp->setPriority(message->getPriority());
+ if (message->isPersistent()) dp->setDeliveryMode(2);
+ if (message->getRoutingKey().size()) dp->setRoutingKey(message->getRoutingKey());
+
+ return transfer.get();
+ } else {
+ throw qpid::Exception("Could not write message data in AMQP 0-10 format");
+ }
+ }
+}
+
+void Translation::write(Outgoing& out)
+{
+ const Message* message = dynamic_cast<const Message*>(&original.getEncoding());
+ if (message) {
+ //write annotations
+ //TODO: merge in any newly added annotations
+ qpid::amqp::CharSequence deliveryAnnotations = message->getDeliveryAnnotations();
+ qpid::amqp::CharSequence messageAnnotations = message->getMessageAnnotations();
+ if (deliveryAnnotations.size) out.write(deliveryAnnotations.data, deliveryAnnotations.size);
+ if (messageAnnotations.size) out.write(messageAnnotations.data, messageAnnotations.size);
+ //write bare message
+ qpid::amqp::CharSequence bareMessage = message->getBareMessage();
+ if (bareMessage.size) out.write(bareMessage.data, bareMessage.size);
+ //write footer:
+ qpid::amqp::CharSequence footer = message->getFooter();
+ if (footer.size) out.write(footer.data, footer.size);
+ } else {
+ const qpid::broker::amqp_0_10::MessageTransfer* transfer = dynamic_cast<const qpid::broker::amqp_0_10::MessageTransfer*>(&original.getEncoding());
+ if (transfer) {
+ Properties_0_10 properties(*transfer);
+ qpid::types::Variant::Map applicationProperties;
+ qpid::amqp_0_10::translate(properties.getApplicationProperties(), applicationProperties);
+ std::string content = transfer->getContent();
+ size_t size = qpid::amqp::MessageEncoder::getEncodedSize(properties, applicationProperties, content);
+ std::vector<char> buffer(size);
+ qpid::amqp::MessageEncoder encoder(&buffer[0], buffer.size());
+ encoder.writeProperties(properties);
+ encoder.writeApplicationProperties(applicationProperties);
+ encoder.writeBinary(content, &qpid::amqp::message::DATA);
+ out.write(&buffer[0], encoder.getPosition());
+ } else {
+ QPID_LOG(error, "Could not write message data in AMQP 1.0 format");
+ }
+ }
+}
+
+}}} // namespace qpid::broker::amqp
diff --git a/cpp/src/qpid/broker/amqp/Translation.h b/cpp/src/qpid/broker/amqp/Translation.h
new file mode 100644
index 0000000000..64d96560e3
--- /dev/null
+++ b/cpp/src/qpid/broker/amqp/Translation.h
@@ -0,0 +1,58 @@
+#ifndef QPID_BROKER_AMQP_TRANSLATION_H
+#define QPID_BROKER_AMQP_TRANSLATION_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <boost/intrusive_ptr.hpp>
+
+namespace qpid {
+namespace broker {
+class Message;
+namespace amqp_0_10 {
+class MessageTransfer;
+}
+namespace amqp {
+
+class Outgoing;
+/**
+ *
+ */
+class Translation
+{
+ public:
+ Translation(const qpid::broker::Message& message);
+
+ /**
+ * @returns a pointer to an AMQP 0-10 message transfer suitable
+ * for sending on an 0-10 session, translating from 1.0 as
+ * necessary
+ */
+ boost::intrusive_ptr<const qpid::broker::amqp_0_10::MessageTransfer> getTransfer();
+ /**
+ * Writes the AMQP 1.0 bare message and any annotations, translating from 0-10 if necessary
+ */
+ void write(Outgoing&);
+ private:
+ const qpid::broker::Message& original;
+};
+}}} // namespace qpid::broker::amqp
+
+#endif /*!QPID_BROKER_AMQP_TRANSLATION_H*/
diff --git a/cpp/src/qpid/broker/amqp_0_10/MessageTransfer.cpp b/cpp/src/qpid/broker/amqp_0_10/MessageTransfer.cpp
index cac4434c48..b78b69b2d6 100644
--- a/cpp/src/qpid/broker/amqp_0_10/MessageTransfer.cpp
+++ b/cpp/src/qpid/broker/amqp_0_10/MessageTransfer.cpp
@@ -29,6 +29,7 @@
#include "qpid/framing/TypeFilter.h"
#include "qpid/framing/SendContent.h"
#include "qpid/log/Statement.h"
+#include "boost/lexical_cast.hpp"
using namespace qpid::framing;
@@ -51,7 +52,12 @@ std::string MessageTransfer::getAnnotationAsString(const std::string& key) const
{
const qpid::framing::MessageProperties* mp = getProperties<qpid::framing::MessageProperties>();
if (mp && mp->hasApplicationHeaders()) {
- return mp->getApplicationHeaders().getAsString(key);
+ FieldTable::ValuePtr value = mp->getApplicationHeaders().get(key);
+ if (value) {
+ if (value->convertsTo<std::string>()) return value->get<std::string>();
+ else if (value->convertsTo<int>()) return boost::lexical_cast<std::string>(value->get<int>());
+ }
+ return std::string();
} else {
return std::string();
}
@@ -116,11 +122,6 @@ void MessageTransfer::computeRequiredCredit()
requiredCredit = sum.getSize();
cachedRequiredCredit = true;
}
-uint32_t MessageTransfer::getRequiredCredit(const qpid::broker::Message& msg)
-{
- //TODO: may need to reflect annotations and other modifications in this also
- return get(msg).getRequiredCredit();
-}
qpid::framing::FrameSet& MessageTransfer::getFrames()
{
diff --git a/cpp/src/qpid/broker/amqp_0_10/MessageTransfer.h b/cpp/src/qpid/broker/amqp_0_10/MessageTransfer.h
index 590e389518..9e432235e6 100644
--- a/cpp/src/qpid/broker/amqp_0_10/MessageTransfer.h
+++ b/cpp/src/qpid/broker/amqp_0_10/MessageTransfer.h
@@ -109,7 +109,6 @@ class MessageTransfer : public qpid::broker::Message::Encoding, public qpid::bro
QPID_BROKER_EXTERN bool isLastQMFResponse(const std::string correlation) const;
static bool isImmediateDeliveryRequired(const qpid::broker::Message& message);
- static uint32_t getRequiredCredit(const qpid::broker::Message&);
static MessageTransfer& get(qpid::broker::Message& message) {
return *dynamic_cast<MessageTransfer*>(&message.getEncoding());
}
diff --git a/cpp/src/qpid/broker/windows/SaslAuthenticator.cpp b/cpp/src/qpid/broker/windows/SaslAuthenticator.cpp
index 40e74be018..c04d037a6e 100644
--- a/cpp/src/qpid/broker/windows/SaslAuthenticator.cpp
+++ b/cpp/src/qpid/broker/windows/SaslAuthenticator.cpp
@@ -23,6 +23,7 @@
// accessing authentication mechanisms, analogous to Cyrus SASL.
#include "qpid/broker/Connection.h"
+#include "qpid/broker/Broker.h"
#include "qpid/log/Statement.h"
#include "qpid/framing/reply_exceptions.h"
#include "qpid/framing/FieldValue.h"
diff --git a/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp b/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp
index 420e04e832..a07afe45ae 100644
--- a/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp
+++ b/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp
@@ -1,352 +1,379 @@
-/*
- *
- * 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.
- *
- */
-
-#include "qpid/sys/ProtocolFactory.h"
-
-#include "qpid/Plugin.h"
-#include "qpid/broker/Broker.h"
-#include "qpid/log/Statement.h"
-#include "qpid/sys/AsynchIOHandler.h"
-#include "qpid/sys/ConnectionCodec.h"
-#include "qpid/sys/Socket.h"
-#include "qpid/sys/SocketAddress.h"
-#include "qpid/sys/SystemInfo.h"
-#include "qpid/sys/windows/SslAsynchIO.h"
-
-#include <boost/bind.hpp>
-#include <boost/ptr_container/ptr_vector.hpp>
-#include <memory>
-
-// security.h needs to see this to distinguish from kernel use.
-#define SECURITY_WIN32
-#include <security.h>
-#include <Schnlsp.h>
-#undef SECURITY_WIN32
-
-
-namespace qpid {
-namespace sys {
-
-class Timer;
-
-namespace windows {
-
-struct SslServerOptions : qpid::Options
-{
- std::string certStore;
- std::string certStoreLocation;
- std::string certName;
- uint16_t port;
- bool clientAuth;
-
- SslServerOptions() : qpid::Options("SSL Options"),
- certStore("My"),
- certStoreLocation("CurrentUser"),
- certName("localhost"),
- port(5671),
- clientAuth(false)
- {
- qpid::Address me;
- if (qpid::sys::SystemInfo::getLocalHostname(me))
- certName = me.host;
-
- addOptions()
- ("ssl-cert-store", optValue(certStore, "NAME"), "Local store name from which to obtain certificate")
- ("ssl-cert-store-location", optValue(certStoreLocation, "NAME"),
- "Local store name location for certificates ( CurrentUser | LocalMachine | CurrentService )")
- ("ssl-cert-name", optValue(certName, "NAME"), "Name of the certificate to use")
- ("ssl-port", optValue(port, "PORT"), "Port on which to listen for SSL connections")
- ("ssl-require-client-authentication", optValue(clientAuth),
- "Forces clients to authenticate in order to establish an SSL connection");
- }
-};
-
-class SslProtocolFactory : public qpid::sys::ProtocolFactory {
- boost::ptr_vector<Socket> listeners;
- boost::ptr_vector<AsynchAcceptor> acceptors;
- Timer& brokerTimer;
- uint32_t maxNegotiateTime;
- uint16_t listeningPort;
- const bool tcpNoDelay;
- std::string brokerHost;
- const bool clientAuthSelected;
- std::auto_ptr<qpid::sys::AsynchAcceptor> acceptor;
- ConnectFailedCallback connectFailedCallback;
- CredHandle credHandle;
-
- public:
- SslProtocolFactory(const SslServerOptions&, const std::string& host, const std::string& port,
- int backlog, bool nodelay,
- Timer& timer, uint32_t maxTime);
- ~SslProtocolFactory();
- void accept(sys::Poller::shared_ptr, sys::ConnectionCodec::Factory*);
- void connect(sys::Poller::shared_ptr, const std::string& host, const std::string& port,
- sys::ConnectionCodec::Factory*,
- ConnectFailedCallback failed);
-
- uint16_t getPort() const;
- bool supports(const std::string& capability);
-
- private:
- void connectFailed(const qpid::sys::Socket&,
- int err,
- const std::string& msg);
- void established(sys::Poller::shared_ptr,
- const qpid::sys::Socket&,
- sys::ConnectionCodec::Factory*,
- bool isClient);
-};
-
-// Static instance to initialise plugin
-static struct SslPlugin : public Plugin {
- SslServerOptions options;
-
- Options* getOptions() { return &options; }
-
- void earlyInitialize(Target&) {
- }
-
- void initialize(Target& target) {
- broker::Broker* broker = dynamic_cast<broker::Broker*>(&target);
- // Only provide to a Broker
- if (broker) {
- try {
- const broker::Broker::Options& opts = broker->getOptions();
- ProtocolFactory::shared_ptr protocol(new SslProtocolFactory(options,
- "", boost::lexical_cast<std::string>(options.port),
- opts.connectionBacklog, opts.tcpNoDelay,
- broker->getTimer(), opts.maxNegotiateTime));
- QPID_LOG(notice, "Listening for SSL connections on TCP port " << protocol->getPort());
- broker->registerProtocolFactory("ssl", protocol);
- } catch (const std::exception& e) {
- QPID_LOG(error, "Failed to initialise SSL listener: " << e.what());
- }
- }
- }
-} sslPlugin;
-
-SslProtocolFactory::SslProtocolFactory(const SslServerOptions& options,
- const std::string& host, const std::string& port,
- int backlog, bool nodelay,
- Timer& timer, uint32_t maxTime)
- : brokerTimer(timer),
- maxNegotiateTime(maxTime),
- tcpNoDelay(nodelay),
- clientAuthSelected(options.clientAuth) {
-
- // Make sure that certificate store is good before listening to sockets
- // to avoid having open and listening sockets when there is no cert store
- SecInvalidateHandle(&credHandle);
-
- // Get the certificate for this server.
- DWORD flags = 0;
- std::string certStoreLocation = options.certStoreLocation;
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/sys/ProtocolFactory.h"
+
+#include "qpid/Plugin.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/log/Statement.h"
+#include "qpid/sys/AsynchIOHandler.h"
+#include "qpid/sys/ConnectionCodec.h"
+#include "qpid/sys/Socket.h"
+#include "qpid/sys/SocketAddress.h"
+#include "qpid/sys/SystemInfo.h"
+#include "qpid/sys/windows/SslAsynchIO.h"
+
+#include <boost/bind.hpp>
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <memory>
+
+// security.h needs to see this to distinguish from kernel use.
+#define SECURITY_WIN32
+#include <security.h>
+#include <Schnlsp.h>
+#undef SECURITY_WIN32
+
+
+namespace qpid {
+namespace sys {
+
+class Timer;
+
+namespace windows {
+
+struct SslServerOptions : qpid::Options
+{
+ std::string certStore;
+ std::string certStoreLocation;
+ std::string certName;
+ uint16_t port;
+ bool clientAuth;
+
+ SslServerOptions() : qpid::Options("SSL Options"),
+ certStore("My"),
+ certStoreLocation("CurrentUser"),
+ certName("localhost"),
+ port(5671),
+ clientAuth(false)
+ {
+ qpid::Address me;
+ if (qpid::sys::SystemInfo::getLocalHostname(me))
+ certName = me.host;
+
+ addOptions()
+ ("ssl-cert-store", optValue(certStore, "NAME"), "Local store name from which to obtain certificate")
+ ("ssl-cert-store-location", optValue(certStoreLocation, "NAME"),
+ "Local store name location for certificates ( CurrentUser | LocalMachine | CurrentService )")
+ ("ssl-cert-name", optValue(certName, "NAME"), "Name of the certificate to use")
+ ("ssl-port", optValue(port, "PORT"), "Port on which to listen for SSL connections")
+ ("ssl-require-client-authentication", optValue(clientAuth),
+ "Forces clients to authenticate in order to establish an SSL connection");
+ }
+};
+
+class SslProtocolFactory : public qpid::sys::ProtocolFactory {
+ boost::ptr_vector<Socket> listeners;
+ boost::ptr_vector<AsynchAcceptor> acceptors;
+ Timer& brokerTimer;
+ uint32_t maxNegotiateTime;
+ uint16_t listeningPort;
+ const bool tcpNoDelay;
+ std::string brokerHost;
+ const bool clientAuthSelected;
+ std::auto_ptr<qpid::sys::AsynchAcceptor> acceptor;
+ ConnectFailedCallback connectFailedCallback;
+ CredHandle credHandle;
+
+ public:
+ SslProtocolFactory(const qpid::broker::Broker::Options& opts, const SslServerOptions&, Timer& timer);
+ ~SslProtocolFactory();
+ void accept(sys::Poller::shared_ptr, sys::ConnectionCodec::Factory*);
+ void connect(sys::Poller::shared_ptr, const std::string& name, const std::string& host, const std::string& port,
+ sys::ConnectionCodec::Factory*,
+ ConnectFailedCallback failed);
+
+ uint16_t getPort() const;
+
+ private:
+ void connectFailed(const qpid::sys::Socket&,
+ int err,
+ const std::string& msg);
+ void establishedIncoming(sys::Poller::shared_ptr, const qpid::sys::Socket&, sys::ConnectionCodec::Factory*);
+ void establishedOutgoing(sys::Poller::shared_ptr, const qpid::sys::Socket&, sys::ConnectionCodec::Factory*, std::string& );
+ void establishedCommon(sys::Poller::shared_ptr, sys::AsynchIOHandler*, sys::AsynchIO*, const qpid::sys::Socket&);
+};
+
+// Static instance to initialise plugin
+static struct SslPlugin : public Plugin {
+ SslServerOptions options;
+
+ Options* getOptions() { return &options; }
+
+ void earlyInitialize(Target&) {
+ }
+
+ void initialize(Target& target) {
+ broker::Broker* broker = dynamic_cast<broker::Broker*>(&target);
+ // Only provide to a Broker
+ if (broker) {
+ try {
+ const broker::Broker::Options& opts = broker->getOptions();
+ ProtocolFactory::shared_ptr protocol(new SslProtocolFactory(opts, options, broker->getTimer()));
+ QPID_LOG(notice, "Listening for SSL connections on TCP port " << protocol->getPort());
+ broker->registerProtocolFactory("ssl", protocol);
+ } catch (const std::exception& e) {
+ QPID_LOG(error, "Failed to initialise SSL listener: " << e.what());
+ }
+ }
+ }
+} sslPlugin;
+
+namespace {
+ // Expand list of Interfaces and addresses to a list of addresses
+ std::vector<std::string> expandInterfaces(const std::vector<std::string>& interfaces) {
+ std::vector<std::string> addresses;
+ // If there are no specific interfaces listed use a single "" to listen on every interface
+ if (interfaces.empty()) {
+ addresses.push_back("");
+ return addresses;
+ }
+ for (unsigned i = 0; i < interfaces.size(); ++i) {
+ const std::string& interface = interfaces[i];
+ if (!(SystemInfo::getInterfaceAddresses(interface, addresses))) {
+ // We don't have an interface of that name -
+ // Check for IPv6 ('[' ']') brackets and remove them
+ // then pass to be looked up directly
+ if (interface[0]=='[' && interface[interface.size()-1]==']') {
+ addresses.push_back(interface.substr(1, interface.size()-2));
+ } else {
+ addresses.push_back(interface);
+ }
+ }
+ }
+ return addresses;
+ }
+}
+
+SslProtocolFactory::SslProtocolFactory(const qpid::broker::Broker::Options& opts, const SslServerOptions& options, Timer& timer)
+ : brokerTimer(timer),
+ maxNegotiateTime(opts.maxNegotiateTime),
+ tcpNoDelay(opts.tcpNoDelay),
+ clientAuthSelected(options.clientAuth) {
+
+ // Make sure that certificate store is good before listening to sockets
+ // to avoid having open and listening sockets when there is no cert store
+ SecInvalidateHandle(&credHandle);
+
+ // Get the certificate for this server.
+ DWORD flags = 0;
+ std::string certStoreLocation = options.certStoreLocation;
std::transform(certStoreLocation.begin(), certStoreLocation.end(), certStoreLocation.begin(), ::tolower);
- if (certStoreLocation == "currentuser") {
- flags = CERT_SYSTEM_STORE_CURRENT_USER;
- } else if (certStoreLocation == "localmachine") {
- flags = CERT_SYSTEM_STORE_LOCAL_MACHINE;
- } else if (certStoreLocation == "currentservice") {
- flags = CERT_SYSTEM_STORE_CURRENT_SERVICE;
- } else {
- QPID_LOG(error, "Unrecognised SSL certificate store location: " << options.certStoreLocation
- << " - Using default location");
- }
- HCERTSTORE certStoreHandle;
- certStoreHandle = ::CertOpenStore(CERT_STORE_PROV_SYSTEM_A,
- X509_ASN_ENCODING,
- 0,
- flags |
- CERT_STORE_READONLY_FLAG,
- options.certStore.c_str());
- if (!certStoreHandle)
- throw qpid::Exception(QPID_MSG("Opening store " << options.certStore << " " << qpid::sys::strError(GetLastError())));
-
- PCCERT_CONTEXT certContext;
- certContext = ::CertFindCertificateInStore(certStoreHandle,
- X509_ASN_ENCODING,
- 0,
- CERT_FIND_SUBJECT_STR_A,
- options.certName.c_str(),
- NULL);
- if (certContext == NULL) {
- int err = ::GetLastError();
- ::CertCloseStore(certStoreHandle, 0);
- throw qpid::Exception(QPID_MSG("Locating certificate " << options.certName << " in store " << options.certStore << " " << qpid::sys::strError(GetLastError())));
- throw QPID_WINDOWS_ERROR(err);
- }
-
- SCHANNEL_CRED cred;
- memset(&cred, 0, sizeof(cred));
- cred.dwVersion = SCHANNEL_CRED_VERSION;
- cred.cCreds = 1;
- cred.paCred = &certContext;
- SECURITY_STATUS status = ::AcquireCredentialsHandle(NULL,
- UNISP_NAME,
- SECPKG_CRED_INBOUND,
- NULL,
- &cred,
- NULL,
- NULL,
- &credHandle,
- NULL);
- if (status != SEC_E_OK)
- throw QPID_WINDOWS_ERROR(status);
- ::CertFreeCertificateContext(certContext);
- ::CertCloseStore(certStoreHandle, 0);
-
- // Listen to socket(s)
- SocketAddress sa(host, port);
-
- // We must have at least one resolved address
- QPID_LOG(info, "SSL Listening to: " << sa.asString())
- Socket* s = new Socket;
- listeningPort = s->listen(sa, backlog);
- listeners.push_back(s);
-
- // Try any other resolved addresses
- while (sa.nextAddress()) {
- QPID_LOG(info, "SSL Listening to: " << sa.asString())
- Socket* s = new Socket;
- s->listen(sa, backlog);
- listeners.push_back(s);
- }
-}
-
-SslProtocolFactory::~SslProtocolFactory() {
- ::FreeCredentialsHandle(&credHandle);
-}
-
-void SslProtocolFactory::connectFailed(const qpid::sys::Socket&,
- int err,
- const std::string& msg) {
- if (connectFailedCallback)
- connectFailedCallback(err, msg);
-}
-
-void SslProtocolFactory::established(sys::Poller::shared_ptr poller,
- const qpid::sys::Socket& s,
- sys::ConnectionCodec::Factory* f,
- bool isClient) {
- sys::AsynchIOHandler* async = new sys::AsynchIOHandler(s.getFullAddress(), f);
-
- if (tcpNoDelay) {
- s.setTcpNoDelay();
- QPID_LOG(info,
- "Set TCP_NODELAY on connection to " << s.getPeerAddress());
- }
-
- SslAsynchIO *aio;
- if (isClient) {
- async->setClient();
- aio =
- new qpid::sys::windows::ClientSslAsynchIO(brokerHost,
- s,
- credHandle,
- boost::bind(&AsynchIOHandler::readbuff, async, _1, _2),
- boost::bind(&AsynchIOHandler::eof, async, _1),
- boost::bind(&AsynchIOHandler::disconnect, async, _1),
- boost::bind(&AsynchIOHandler::closedSocket, async, _1, _2),
- boost::bind(&AsynchIOHandler::nobuffs, async, _1),
- boost::bind(&AsynchIOHandler::idle, async, _1));
- }
- else {
- aio =
- new qpid::sys::windows::ServerSslAsynchIO(clientAuthSelected,
- s,
- credHandle,
- boost::bind(&AsynchIOHandler::readbuff, async, _1, _2),
- boost::bind(&AsynchIOHandler::eof, async, _1),
- boost::bind(&AsynchIOHandler::disconnect, async, _1),
- boost::bind(&AsynchIOHandler::closedSocket, async, _1, _2),
- boost::bind(&AsynchIOHandler::nobuffs, async, _1),
- boost::bind(&AsynchIOHandler::idle, async, _1));
- }
-
- async->init(aio, brokerTimer, maxNegotiateTime);
- aio->start(poller);
-}
-
-uint16_t SslProtocolFactory::getPort() const {
- return listeningPort; // Immutable no need for lock.
-}
-
-void SslProtocolFactory::accept(sys::Poller::shared_ptr poller,
- sys::ConnectionCodec::Factory* fact) {
- for (unsigned i = 0; i<listeners.size(); ++i) {
- acceptors.push_back(
- AsynchAcceptor::create(listeners[i],
- boost::bind(&SslProtocolFactory::established, this, poller, _1, fact, false)));
- acceptors[i].start(poller);
- }
-}
-
-void SslProtocolFactory::connect(sys::Poller::shared_ptr poller,
- const std::string& host,
- const std::string& port,
- sys::ConnectionCodec::Factory* fact,
- ConnectFailedCallback failed)
-{
- SCHANNEL_CRED cred;
- memset(&cred, 0, sizeof(cred));
- cred.dwVersion = SCHANNEL_CRED_VERSION;
- SECURITY_STATUS status = ::AcquireCredentialsHandle(NULL,
- UNISP_NAME,
- SECPKG_CRED_OUTBOUND,
- NULL,
- &cred,
- NULL,
- NULL,
- &credHandle,
- NULL);
- if (status != SEC_E_OK)
- throw QPID_WINDOWS_ERROR(status);
-
- brokerHost = host;
- // Note that the following logic does not cause a memory leak.
- // The allocated Socket is freed either by the AsynchConnector
- // upon connection failure or by the AsynchIO upon connection
- // shutdown. The allocated AsynchConnector frees itself when it
- // is no longer needed.
- qpid::sys::Socket* socket = new qpid::sys::Socket();
- connectFailedCallback = failed;
- AsynchConnector::create(*socket,
- host,
- port,
- boost::bind(&SslProtocolFactory::established,
- this, poller, _1, fact, true),
- boost::bind(&SslProtocolFactory::connectFailed,
- this, _1, _2, _3));
-}
-
-namespace
-{
-const std::string SSL = "ssl";
-}
-
-bool SslProtocolFactory::supports(const std::string& capability)
-{
- std::string s = capability;
- transform(s.begin(), s.end(), s.begin(), tolower);
- return s == SSL;
-}
-
-}}} // namespace qpid::sys::windows
+ if (certStoreLocation == "currentuser") {
+ flags = CERT_SYSTEM_STORE_CURRENT_USER;
+ } else if (certStoreLocation == "localmachine") {
+ flags = CERT_SYSTEM_STORE_LOCAL_MACHINE;
+ } else if (certStoreLocation == "currentservice") {
+ flags = CERT_SYSTEM_STORE_CURRENT_SERVICE;
+ } else {
+ QPID_LOG(error, "Unrecognised SSL certificate store location: " << options.certStoreLocation
+ << " - Using default location");
+ }
+ HCERTSTORE certStoreHandle;
+ certStoreHandle = ::CertOpenStore(CERT_STORE_PROV_SYSTEM_A,
+ X509_ASN_ENCODING,
+ 0,
+ flags |
+ CERT_STORE_READONLY_FLAG,
+ options.certStore.c_str());
+ if (!certStoreHandle)
+ throw qpid::Exception(QPID_MSG("Opening store " << options.certStore << " " << qpid::sys::strError(GetLastError())));
+
+ PCCERT_CONTEXT certContext;
+ certContext = ::CertFindCertificateInStore(certStoreHandle,
+ X509_ASN_ENCODING,
+ 0,
+ CERT_FIND_SUBJECT_STR_A,
+ options.certName.c_str(),
+ NULL);
+ if (certContext == NULL) {
+ int err = ::GetLastError();
+ ::CertCloseStore(certStoreHandle, 0);
+ throw qpid::Exception(QPID_MSG("Locating certificate " << options.certName << " in store " << options.certStore << " " << qpid::sys::strError(GetLastError())));
+ throw QPID_WINDOWS_ERROR(err);
+ }
+
+ SCHANNEL_CRED cred;
+ memset(&cred, 0, sizeof(cred));
+ cred.dwVersion = SCHANNEL_CRED_VERSION;
+ cred.cCreds = 1;
+ cred.paCred = &certContext;
+ SECURITY_STATUS status = ::AcquireCredentialsHandle(NULL,
+ UNISP_NAME,
+ SECPKG_CRED_INBOUND,
+ NULL,
+ &cred,
+ NULL,
+ NULL,
+ &credHandle,
+ NULL);
+ if (status != SEC_E_OK)
+ throw QPID_WINDOWS_ERROR(status);
+ ::CertFreeCertificateContext(certContext);
+ ::CertCloseStore(certStoreHandle, 0);
+
+ std::vector<std::string> addresses = expandInterfaces(opts.listenInterfaces);
+ if (addresses.empty()) {
+ // We specified some interfaces, but couldn't find addresses for them
+ QPID_LOG(warning, "TCP/TCP6: No specified network interfaces found: Not Listening");
+ listeningPort = 0;
+ }
+
+ for (unsigned i = 0; i<addresses.size(); ++i) {
+ QPID_LOG(debug, "Using interface: " << addresses[i]);
+ SocketAddress sa(addresses[i], boost::lexical_cast<std::string>(options.port));
+
+
+ // We must have at least one resolved address
+ QPID_LOG(info, "SSL Listening to: " << sa.asString())
+ Socket* s = createSocket();
+ listeningPort = s->listen(sa, opts.connectionBacklog);
+ listeners.push_back(s);
+
+ // Try any other resolved addresses
+ while (sa.nextAddress()) {
+ QPID_LOG(info, "SSL Listening to: " << sa.asString())
+ Socket* s = createSocket();
+ s->listen(sa, opts.connectionBacklog);
+ listeners.push_back(s);
+ }
+ }
+}
+
+SslProtocolFactory::~SslProtocolFactory() {
+ ::FreeCredentialsHandle(&credHandle);
+}
+
+void SslProtocolFactory::connectFailed(const qpid::sys::Socket&,
+ int err,
+ const std::string& msg) {
+ if (connectFailedCallback)
+ connectFailedCallback(err, msg);
+}
+
+void SslProtocolFactory::establishedIncoming(sys::Poller::shared_ptr poller,
+ const qpid::sys::Socket& s,
+ sys::ConnectionCodec::Factory* f) {
+ sys::AsynchIOHandler* async = new sys::AsynchIOHandler(s.getFullAddress(), f, false, false);
+
+ sys::AsynchIO *aio =
+ new qpid::sys::windows::ServerSslAsynchIO(
+ clientAuthSelected,
+ s,
+ credHandle,
+ boost::bind(&AsynchIOHandler::readbuff, async, _1, _2),
+ boost::bind(&AsynchIOHandler::eof, async, _1),
+ boost::bind(&AsynchIOHandler::disconnect, async, _1),
+ boost::bind(&AsynchIOHandler::closedSocket, async, _1, _2),
+ boost::bind(&AsynchIOHandler::nobuffs, async, _1),
+ boost::bind(&AsynchIOHandler::idle, async, _1));
+
+ establishedCommon(poller, async, aio, s);
+}
+
+void SslProtocolFactory::establishedOutgoing(sys::Poller::shared_ptr poller,
+ const qpid::sys::Socket& s,
+ sys::ConnectionCodec::Factory* f,
+ std::string& name) {
+ sys::AsynchIOHandler* async = new sys::AsynchIOHandler(name, f, true, false);
+
+ sys::AsynchIO *aio =
+ new qpid::sys::windows::ClientSslAsynchIO(
+ brokerHost,
+ s,
+ credHandle,
+ boost::bind(&AsynchIOHandler::readbuff, async, _1, _2),
+ boost::bind(&AsynchIOHandler::eof, async, _1),
+ boost::bind(&AsynchIOHandler::disconnect, async, _1),
+ boost::bind(&AsynchIOHandler::closedSocket, async, _1, _2),
+ boost::bind(&AsynchIOHandler::nobuffs, async, _1),
+ boost::bind(&AsynchIOHandler::idle, async, _1));
+
+ establishedCommon(poller, async, aio, s);
+}
+
+void SslProtocolFactory::establishedCommon(sys::Poller::shared_ptr poller,
+ sys::AsynchIOHandler* async,
+ sys::AsynchIO* aio,
+ const qpid::sys::Socket& s) {
+ if (tcpNoDelay) {
+ s.setTcpNoDelay();
+ QPID_LOG(info,
+ "Set TCP_NODELAY on connection to " << s.getPeerAddress());
+ }
+
+ async->init(aio, brokerTimer, maxNegotiateTime);
+ aio->start(poller);
+}
+
+uint16_t SslProtocolFactory::getPort() const {
+ return listeningPort; // Immutable no need for lock.
+}
+
+void SslProtocolFactory::accept(sys::Poller::shared_ptr poller,
+ sys::ConnectionCodec::Factory* fact) {
+ for (unsigned i = 0; i<listeners.size(); ++i) {
+ acceptors.push_back(
+ AsynchAcceptor::create(listeners[i],
+ boost::bind(&SslProtocolFactory::establishedIncoming, this, poller, _1, fact)));
+ acceptors[i].start(poller);
+ }
+}
+
+void SslProtocolFactory::connect(sys::Poller::shared_ptr poller,
+ const std::string& name,
+ const std::string& host,
+ const std::string& port,
+ sys::ConnectionCodec::Factory* fact,
+ ConnectFailedCallback failed)
+{
+ SCHANNEL_CRED cred;
+ memset(&cred, 0, sizeof(cred));
+ cred.dwVersion = SCHANNEL_CRED_VERSION;
+ SECURITY_STATUS status = ::AcquireCredentialsHandle(NULL,
+ UNISP_NAME,
+ SECPKG_CRED_OUTBOUND,
+ NULL,
+ &cred,
+ NULL,
+ NULL,
+ &credHandle,
+ NULL);
+ if (status != SEC_E_OK)
+ throw QPID_WINDOWS_ERROR(status);
+
+ brokerHost = host;
+ // Note that the following logic does not cause a memory leak.
+ // The allocated Socket is freed either by the AsynchConnector
+ // upon connection failure or by the AsynchIO upon connection
+ // shutdown. The allocated AsynchConnector frees itself when it
+ // is no longer needed.
+ qpid::sys::Socket* socket = createSocket();
+ connectFailedCallback = failed;
+ AsynchConnector::create(*socket,
+ host,
+ port,
+ boost::bind(&SslProtocolFactory::establishedOutgoing,
+ this, poller, _1, fact, name),
+ boost::bind(&SslProtocolFactory::connectFailed,
+ this, _1, _2, _3));
+}
+
+}}} // namespace qpid::sys::windows
diff --git a/cpp/src/qpid/client/ConnectionHandler.cpp b/cpp/src/qpid/client/ConnectionHandler.cpp
index 91838d8e8b..4f88cb97ee 100644
--- a/cpp/src/qpid/client/ConnectionHandler.cpp
+++ b/cpp/src/qpid/client/ConnectionHandler.cpp
@@ -82,9 +82,11 @@ void ConnectionHandler::Adapter::handle(qpid::framing::AMQFrame& f)
handler.out(f);
}
-ConnectionHandler::ConnectionHandler(const ConnectionSettings& s, ProtocolVersion& v, Bounds& b)
- : StateManager(NOT_STARTED), ConnectionSettings(s), outHandler(*this, b), proxy(outHandler),
- errorCode(CLOSE_CODE_NORMAL), version(v)
+ConnectionHandler::ConnectionHandler(
+ const ConnectionSettings& s, ProtocolVersion& v, Bounds& b)
+ : StateManager(NOT_STARTED), ConnectionSettings(s),
+ outHandler(*this, b), proxy(outHandler), errorCode(CLOSE_CODE_NORMAL), version(v),
+ properties(s.clientProperties)
{
insist = true;
diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp
index 85b0e8303e..0abfbe09ec 100644
--- a/cpp/src/qpid/client/ConnectionImpl.cpp
+++ b/cpp/src/qpid/client/ConnectionImpl.cpp
@@ -128,15 +128,17 @@ public:
// and we can't do that before we're unloaded as we can't
// restart the Poller after shutting it down
~IOThread() {
- std::vector<Thread> threads;
- {
- ScopedLock<Mutex> l(threadLock);
- if (poller_)
- poller_->shutdown();
- t.swap(threads);
- }
- for (std::vector<Thread>::iterator i = threads.begin(); i != threads.end(); ++i) {
- i->join();
+ if (SystemInfo::threadSafeShutdown()) {
+ std::vector<Thread> threads;
+ {
+ ScopedLock<Mutex> l(threadLock);
+ if (poller_)
+ poller_->shutdown();
+ t.swap(threads);
+ }
+ for (std::vector<Thread>::iterator i = threads.begin(); i != threads.end(); ++i) {
+ i->join();
+ }
}
}
};
diff --git a/cpp/src/qpid/client/FailoverManager.cpp b/cpp/src/qpid/client/FailoverManager.cpp
index 9405765b47..f27aeb5b52 100644
--- a/cpp/src/qpid/client/FailoverManager.cpp
+++ b/cpp/src/qpid/client/FailoverManager.cpp
@@ -34,6 +34,9 @@ using qpid::sys::Duration;
FailoverManager::FailoverManager(const ConnectionSettings& s,
ReconnectionStrategy* rs) : settings(s), strategy(rs), state(IDLE) {}
+FailoverManager::~FailoverManager()
+{}
+
void FailoverManager::execute(Command& c)
{
bool retry = false;
diff --git a/cpp/src/qpid/client/LoadPlugins.cpp b/cpp/src/qpid/client/LoadPlugins.cpp
index d76e1d458e..c5d8924014 100644
--- a/cpp/src/qpid/client/LoadPlugins.cpp
+++ b/cpp/src/qpid/client/LoadPlugins.cpp
@@ -48,7 +48,7 @@ struct LoadtimeInitialise {
for (vector<string>::iterator iter = moduleOptions.load.begin();
iter != moduleOptions.load.end();
iter++)
- qpid::tryShlib (iter->data(), false);
+ qpid::tryShlib (*iter);
if (!moduleOptions.noLoad) {
bool isDefault = defaultPath == moduleOptions.loadDir;
diff --git a/cpp/src/qpid/client/LoadPlugins.h b/cpp/src/qpid/client/LoadPlugins.h
index 0be4ae9f0c..0b398f6831 100644
--- a/cpp/src/qpid/client/LoadPlugins.h
+++ b/cpp/src/qpid/client/LoadPlugins.h
@@ -22,10 +22,12 @@
#ifndef _LoadPlugins_
#define _LoadPlugins_
+#include "qpid/client/ClientImportExport.h"
+
namespace qpid {
namespace client {
-void theModuleLoader();
+QPID_CLIENT_EXTERN void theModuleLoader();
}}
diff --git a/cpp/src/qpid/client/QueueOptions.cpp b/cpp/src/qpid/client/QueueOptions.cpp
index f4c1483859..460f3f5490 100644
--- a/cpp/src/qpid/client/QueueOptions.cpp
+++ b/cpp/src/qpid/client/QueueOptions.cpp
@@ -49,8 +49,8 @@ QueueOptions::~QueueOptions()
void QueueOptions::setSizePolicy(QueueSizePolicy sp, uint64_t maxSize, uint32_t maxCount)
{
- if (maxCount) setInt(strMaxCountKey, maxCount);
- if (maxSize) setInt(strMaxSizeKey, maxSize);
+ if (maxCount) setUInt64(strMaxCountKey, maxCount);
+ if (maxSize) setUInt64(strMaxSizeKey, maxSize);
if (maxSize || maxCount){
switch (sp)
{
diff --git a/cpp/src/qpid/client/RdmaConnector.cpp b/cpp/src/qpid/client/RdmaConnector.cpp
index 21143a1a75..9b6dcd645d 100644
--- a/cpp/src/qpid/client/RdmaConnector.cpp
+++ b/cpp/src/qpid/client/RdmaConnector.cpp
@@ -109,7 +109,7 @@ class RdmaConnector : public Connector, public sys::Codec
const qpid::sys::SecuritySettings* getSecuritySettings() { return 0; }
size_t decode(const char* buffer, size_t size);
- size_t encode(const char* buffer, size_t size);
+ size_t encode(char* buffer, size_t size);
bool canEncode();
public:
@@ -371,9 +371,9 @@ bool RdmaConnector::canEncode()
return aio->writable() && (lastEof || currentSize >= maxFrameSize);
}
-size_t RdmaConnector::encode(const char* buffer, size_t size)
+size_t RdmaConnector::encode(char* buffer, size_t size)
{
- framing::Buffer out(const_cast<char*>(buffer), size);
+ framing::Buffer out(buffer, size);
size_t bytesWritten(0);
{
Mutex::ScopedLock l(lock);
diff --git a/cpp/src/qpid/client/SessionImpl.cpp b/cpp/src/qpid/client/SessionImpl.cpp
index 91e728d5ae..01e614e041 100644
--- a/cpp/src/qpid/client/SessionImpl.cpp
+++ b/cpp/src/qpid/client/SessionImpl.cpp
@@ -7,9 +7,9 @@
* 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
@@ -61,9 +61,7 @@ SessionImpl::SessionImpl(const std::string& name, boost::shared_ptr<ConnectionIm
ioHandler(*this),
proxy(ioHandler),
nextIn(0),
- nextOut(0),
- doClearDeliveryPropertiesExchange(true),
- autoDetach(true)
+ nextOut(0)
{
channel.next = connection.get();
}
@@ -72,12 +70,10 @@ SessionImpl::~SessionImpl() {
{
Lock l(state);
if (state != DETACHED && state != DETACHING) {
- if (autoDetach) {
- QPID_LOG(warning, "Session was not closed cleanly: " << id);
- // Inform broker but don't wait for detached as that deadlocks.
- // The detached will be ignored as the channel will be invalid.
- try { detach(); } catch (...) {} // ignore errors.
- }
+ QPID_LOG(warning, "Session was not closed cleanly: " << id);
+ // Inform broker but don't wait for detached as that deadlocks.
+ // The detached will be ignored as the channel will be invalid.
+ try { detach(); } catch (...) {} // ignore errors.
setState(DETACHED);
handleClosed();
state.waitWaiters();
@@ -136,10 +132,10 @@ void SessionImpl::resume(boost::shared_ptr<ConnectionImpl>) // user thread
void SessionImpl::suspend() //user thread
{
Lock l(state);
- detach();
+ detach();
}
-void SessionImpl::detach() //call with lock held
+void SessionImpl::detach() //call with lock held
{
if (state == ATTACHED) {
setState(DETACHING);
@@ -149,8 +145,8 @@ void SessionImpl::detach() //call with lock held
uint16_t SessionImpl::getChannel() const // user thread
-{
- return channel;
+{
+ return channel;
}
void SessionImpl::setChannel(uint16_t c) // user thread
@@ -182,7 +178,7 @@ void SessionImpl::waitForCompletionImpl(const SequenceNumber& id) //call with lo
bool SessionImpl::isComplete(const SequenceNumber& id)
{
- Lock l(state);
+ Lock l(state);
return !incompleteOut.contains(id);
}
@@ -219,7 +215,7 @@ framing::SequenceNumber SessionImpl::getCompleteUpTo()
return --firstIncomplete;
}
-struct MarkCompleted
+struct MarkCompleted
{
const SequenceNumber& id;
SequenceSet& completedIn;
@@ -230,7 +226,7 @@ struct MarkCompleted
{
if (id >= end) {
completedIn.add(start, end);
- } else if (id >= start) {
+ } else if (id >= start) {
completedIn.add(start, id);
}
}
@@ -244,13 +240,13 @@ void SessionImpl::markCompleted(const SequenceSet& ids, bool notifyPeer)
completedIn.add(ids);
if (notifyPeer) {
sendCompletion();
- }
+ }
}
void SessionImpl::markCompleted(const SequenceNumber& id, bool cumulative, bool notifyPeer)
{
Lock l(state);
- if (cumulative) {
+ if (cumulative) {
//everything in incompleteIn less than or equal to id is now complete
MarkCompleted f(id, completedIn);
incompleteIn.for_each(f);
@@ -260,11 +256,11 @@ void SessionImpl::markCompleted(const SequenceNumber& id, bool cumulative, bool
incompleteIn.remove(completedIn);
} else if (incompleteIn.contains(id)) {
incompleteIn.remove(id);
- completedIn.add(id);
+ completedIn.add(id);
}
if (notifyPeer) {
sendCompletion();
- }
+ }
}
void SessionImpl::setException(const sys::ExceptionHolder& ex) {
@@ -310,42 +306,24 @@ namespace {
struct SendContentFn {
FrameHandler& handler;
void operator()(const AMQFrame& f) {
- if (!f.getMethod())
+ if (!f.getMethod())
handler(const_cast<AMQFrame&>(f));
}
SendContentFn(FrameHandler& h) : handler(h) {}
};
-// Adaptor to make FrameSet look like MethodContent; used in cluster update client
-struct MethodContentAdaptor : MethodContent
-{
- AMQHeaderBody header;
- const std::string content;
-
- MethodContentAdaptor(const FrameSet& f) : header(*f.getHeaders()), content(f.getContent()) {}
-
- const AMQHeaderBody& getHeader() const
- {
- return header;
- }
- const std::string& getData() const
- {
- return content;
- }
-};
-
}
-
-Future SessionImpl::send(const AMQBody& command, const FrameSet& content, bool reframe) {
+
+Future SessionImpl::send(const AMQBody& command, const FrameSet& content) {
Acquire a(sendLock);
SequenceNumber id = nextOut++;
{
Lock l(state);
- checkOpen();
+ checkOpen();
incompleteOut.add(id);
}
Future f(id);
- if (command.getMethod()->resultExpected()) {
+ if (command.getMethod()->resultExpected()) {
Lock l(state);
//result listener must be set before the command is sent
f.setFutureResult(results.listenForResult(id));
@@ -353,14 +331,8 @@ Future SessionImpl::send(const AMQBody& command, const FrameSet& content, bool r
AMQFrame frame(command);
frame.setEof(false);
handleOut(frame);
-
- if (reframe) {
- MethodContentAdaptor c(content);
- sendContent(c);
- } else {
- SendContentFn send(out);
- content.map(send);
- }
+ SendContentFn send(out);
+ content.map(send);
return f;
}
@@ -375,11 +347,11 @@ Future SessionImpl::sendCommand(const AMQBody& command, const MethodContent* con
SequenceNumber id = nextOut++;
{
Lock l(state);
- checkOpen();
+ checkOpen();
incompleteOut.add(id);
}
Future f(id);
- if (command.getMethod()->resultExpected()) {
+ if (command.getMethod()->resultExpected()) {
Lock l(state);
//result listener must be set before the command is sent
f.setFutureResult(results.listenForResult(id));
@@ -399,23 +371,13 @@ void SessionImpl::sendContent(const MethodContent& content)
{
AMQFrame header(content.getHeader());
- // doClearDeliveryPropertiesExchange is set by cluster update client so
- // it can send messages with delivery-properties.exchange set.
- //
- if (doClearDeliveryPropertiesExchange) {
- // Normal client is not allowed to set the delivery-properties.exchange
- // so clear it here.
- AMQHeaderBody* headerp = static_cast<AMQHeaderBody*>(header.getBody());
- if (headerp && headerp->get<DeliveryProperties>())
- headerp->get<DeliveryProperties>(true)->clearExchangeFlag();
- }
header.setFirstSegment(false);
uint64_t data_length = content.getData().length();
if(data_length > 0){
header.setLastSegment(false);
- handleOut(header);
+ handleOut(header);
/*Note: end of frame marker included in overhead but not in size*/
- const uint32_t frag_size = maxFrameSize - AMQFrame::frameOverhead();
+ const uint32_t frag_size = maxFrameSize - AMQFrame::frameOverhead();
if(data_length < frag_size){
AMQFrame frame((AMQContentBody(content.getData())));
@@ -442,7 +404,7 @@ void SessionImpl::sendContent(const MethodContent& content)
}
}
} else {
- handleOut(header);
+ handleOut(header);
}
}
@@ -462,7 +424,7 @@ bool isContentFrame(AMQFrame& frame)
{
AMQBody* body = frame.getBody();
uint8_t type = body->type();
- return type == HEADER_BODY || type == CONTENT_BODY || isMessageMethod(body);
+ return type == HEADER_BODY || type == CONTENT_BODY || isMessageMethod(body);
}
void SessionImpl::handleIn(AMQFrame& frame) // network thread
@@ -585,7 +547,7 @@ void SessionImpl::timeout(uint32_t t)
void SessionImpl::commandPoint(const framing::SequenceNumber& id, uint64_t offset)
{
if (offset) throw NotImplementedException("Non-zero byte offset not yet supported for command-point");
-
+
Lock l(state);
nextIn = id;
}
@@ -677,10 +639,10 @@ void SessionImpl::exception(uint16_t errorCode,
{
Lock l(state);
setExceptionLH(createSessionException(errorCode, description));
- QPID_LOG(warning, "Exception received from broker: " << exceptionHolder.what()
+ QPID_LOG(warning, "Exception received from broker: " << exceptionHolder.what()
<< " [caused by " << commandId << " " << classCode << ":" << commandCode << "]");
- if (detachedLifetime)
+ if (detachedLifetime)
setTimeout(0);
}
@@ -748,6 +710,4 @@ boost::shared_ptr<ConnectionImpl> SessionImpl::getConnection()
return connection;
}
-void SessionImpl::disableAutoDetach() { autoDetach = false; }
-
}}
diff --git a/cpp/src/qpid/client/SessionImpl.h b/cpp/src/qpid/client/SessionImpl.h
index 4f9213a00a..e6ea8e6b90 100644
--- a/cpp/src/qpid/client/SessionImpl.h
+++ b/cpp/src/qpid/client/SessionImpl.h
@@ -87,15 +87,7 @@ public:
Future send(const framing::AMQBody& command);
Future send(const framing::AMQBody& command, const framing::MethodContent& content);
- /**
- * This method takes the content as a FrameSet; if reframe=false,
- * the caller is resposnible for ensuring that the header and
- * content frames in that set are correct for this connection
- * (right flags, right fragmentation etc). If reframe=true, then
- * the header and content from the frameset will be copied and
- * reframed correctly for the connection.
- */
- QPID_CLIENT_EXTERN Future send(const framing::AMQBody& command, const framing::FrameSet& content, bool reframe=false);
+ QPID_CLIENT_EXTERN Future send(const framing::AMQBody& command, const framing::FrameSet& content);
void sendRawFrame(framing::AMQFrame& frame);
Demux& getDemux();
@@ -125,11 +117,6 @@ public:
*/
boost::shared_ptr<ConnectionImpl> getConnection();
- void setDoClearDeliveryPropertiesExchange(bool b=true) { doClearDeliveryPropertiesExchange = b; }
-
- /** Suppress sending detach in destructor. Used by cluster to build session state */
- void disableAutoDetach();
-
private:
enum State {
INACTIVE,
@@ -225,10 +212,6 @@ private:
SessionState sessionState;
- bool doClearDeliveryPropertiesExchange;
-
- bool autoDetach;
-
friend class client::SessionHandler;
};
diff --git a/cpp/src/qpid/client/SslConnector.cpp b/cpp/src/qpid/client/SslConnector.cpp
index c2081a88f2..11707eb3f7 100644
--- a/cpp/src/qpid/client/SslConnector.cpp
+++ b/cpp/src/qpid/client/SslConnector.cpp
@@ -30,8 +30,9 @@
#include "qpid/framing/AMQFrame.h"
#include "qpid/framing/InitiationHandler.h"
#include "qpid/sys/ssl/util.h"
-#include "qpid/sys/ssl/SslIo.h"
+#include "qpid/sys/AsynchIO.h"
#include "qpid/sys/ssl/SslSocket.h"
+#include "qpid/sys/SocketAddress.h"
#include "qpid/sys/Dispatcher.h"
#include "qpid/sys/Poller.h"
#include "qpid/sys/SecuritySettings.h"
@@ -72,23 +73,28 @@ class SslConnector : public Connector
sys::ssl::SslSocket socket;
- sys::ssl::SslIO* aio;
+ sys::AsynchConnector* connector;
+ sys::AsynchIO* aio;
std::string identifier;
Poller::shared_ptr poller;
SecuritySettings securitySettings;
~SslConnector();
- void readbuff(qpid::sys::ssl::SslIO&, qpid::sys::ssl::SslIOBufferBase*);
- void writebuff(qpid::sys::ssl::SslIO&);
+ void readbuff(AsynchIO&, AsynchIOBufferBase*);
+ void writebuff(AsynchIO&);
void writeDataBlock(const framing::AMQDataBlock& data);
- void eof(qpid::sys::ssl::SslIO&);
- void disconnected(qpid::sys::ssl::SslIO&);
+ void eof(AsynchIO&);
+ void disconnected(AsynchIO&);
void connect(const std::string& host, const std::string& port);
+ void connected(const sys::Socket&);
+ void connectFailed(const std::string& msg);
+
void close();
void send(framing::AMQFrame& frame);
- void abort() {} // TODO: Need to fix for heartbeat timeouts to work
+ void abort();
+ void connectAborted();
void setInputHandler(framing::InputHandler* handler);
void setShutdownHandler(sys::ShutdownHandler* handler);
@@ -96,10 +102,10 @@ class SslConnector : public Connector
framing::OutputHandler* getOutputHandler();
const std::string& getIdentifier() const;
const SecuritySettings* getSecuritySettings();
- void socketClosed(qpid::sys::ssl::SslIO&, const qpid::sys::ssl::SslSocket&);
+ void socketClosed(AsynchIO&, const Socket&);
size_t decode(const char* buffer, size_t size);
- size_t encode(const char* buffer, size_t size);
+ size_t encode(char* buffer, size_t size);
bool canEncode();
public:
@@ -164,32 +170,46 @@ SslConnector::~SslConnector() {
close();
}
-void SslConnector::connect(const std::string& host, const std::string& port){
+void SslConnector::connect(const std::string& host, const std::string& port) {
Mutex::ScopedLock l(lock);
assert(closed);
- try {
- socket.connect(host, port);
- } catch (const std::exception& e) {
- socket.close();
- throw TransportFailure(e.what());
- }
-
+ connector = AsynchConnector::create(
+ socket,
+ host, port,
+ boost::bind(&SslConnector::connected, this, _1),
+ boost::bind(&SslConnector::connectFailed, this, _3));
closed = false;
- aio = new SslIO(socket,
- boost::bind(&SslConnector::readbuff, this, _1, _2),
- boost::bind(&SslConnector::eof, this, _1),
- boost::bind(&SslConnector::disconnected, this, _1),
- boost::bind(&SslConnector::socketClosed, this, _1, _2),
- 0, // nobuffs
- boost::bind(&SslConnector::writebuff, this, _1));
+
+ connector->start(poller);
+}
+
+void SslConnector::connected(const Socket&) {
+ connector = 0;
+ aio = AsynchIO::create(socket,
+ boost::bind(&SslConnector::readbuff, this, _1, _2),
+ boost::bind(&SslConnector::eof, this, _1),
+ boost::bind(&SslConnector::disconnected, this, _1),
+ boost::bind(&SslConnector::socketClosed, this, _1, _2),
+ 0, // nobuffs
+ boost::bind(&SslConnector::writebuff, this, _1));
aio->createBuffers(maxFrameSize);
- identifier = str(format("[%1% %2%]") % socket.getLocalPort() % socket.getPeerAddress());
+ identifier = str(format("[%1%]") % socket.getFullAddress());
ProtocolInitiation init(version);
writeDataBlock(init);
aio->start(poller);
}
+void SslConnector::connectFailed(const std::string& msg) {
+ connector = 0;
+ QPID_LOG(warning, "Connect failed: " << msg);
+ socket.close();
+ if (!closed)
+ closed = true;
+ if (shutdownHandler)
+ shutdownHandler->shutdown();
+}
+
void SslConnector::close() {
Mutex::ScopedLock l(lock);
if (!closed) {
@@ -199,13 +219,31 @@ void SslConnector::close() {
}
}
-void SslConnector::socketClosed(SslIO&, const SslSocket&) {
+void SslConnector::socketClosed(AsynchIO&, const Socket&) {
if (aio)
aio->queueForDeletion();
if (shutdownHandler)
shutdownHandler->shutdown();
}
+void SslConnector::connectAborted() {
+ connector->stop();
+ connectFailed("Connection timedout");
+}
+
+void SslConnector::abort() {
+ // Can't abort a closed connection
+ if (!closed) {
+ if (aio) {
+ // Established connection
+ aio->requestCallback(boost::bind(&SslConnector::eof, this, _1));
+ } else if (connector) {
+ // We're still connecting
+ connector->requestCallback(boost::bind(&SslConnector::connectAborted, this));
+ }
+ }
+}
+
void SslConnector::setInputHandler(InputHandler* handler){
input = handler;
}
@@ -255,7 +293,7 @@ void SslConnector::send(AMQFrame& frame) {
}
}
-void SslConnector::writebuff(SslIO& /*aio*/)
+void SslConnector::writebuff(AsynchIO& /*aio*/)
{
// It's possible to be disconnected and be writable
if (closed)
@@ -265,7 +303,7 @@ void SslConnector::writebuff(SslIO& /*aio*/)
return;
}
- SslIO::BufferBase* buffer = aio->getQueuedBuffer();
+ AsynchIOBufferBase* buffer = aio->getQueuedBuffer();
if (buffer) {
size_t encoded = encode(buffer->bytes, buffer->byteCount);
@@ -285,9 +323,9 @@ bool SslConnector::canEncode()
}
// Called in IO thread.
-size_t SslConnector::encode(const char* buffer, size_t size)
+size_t SslConnector::encode(char* buffer, size_t size)
{
- framing::Buffer out(const_cast<char*>(buffer), size);
+ framing::Buffer out(buffer, size);
size_t bytesWritten(0);
{
Mutex::ScopedLock l(lock);
@@ -304,7 +342,7 @@ size_t SslConnector::encode(const char* buffer, size_t size)
return bytesWritten;
}
-void SslConnector::readbuff(SslIO& aio, SslIO::BufferBase* buff)
+void SslConnector::readbuff(AsynchIO& aio, AsynchIOBufferBase* buff)
{
int32_t decoded = decode(buff->bytes+buff->dataStart, buff->dataCount);
// TODO: unreading needs to go away, and when we can cope
@@ -343,7 +381,7 @@ size_t SslConnector::decode(const char* buffer, size_t size)
}
void SslConnector::writeDataBlock(const AMQDataBlock& data) {
- SslIO::BufferBase* buff = aio->getQueuedBuffer();
+ AsynchIOBufferBase* buff = aio->getQueuedBuffer();
assert(buff);
framing::Buffer out(buff->bytes, buff->byteCount);
data.encode(out);
@@ -351,11 +389,11 @@ void SslConnector::writeDataBlock(const AMQDataBlock& data) {
aio->queueWrite(buff);
}
-void SslConnector::eof(SslIO&) {
+void SslConnector::eof(AsynchIO&) {
close();
}
-void SslConnector::disconnected(SslIO&) {
+void SslConnector::disconnected(AsynchIO&) {
close();
socketClosed(*aio, socket);
}
diff --git a/cpp/src/qpid/client/TCPConnector.cpp b/cpp/src/qpid/client/TCPConnector.cpp
index a5c6465bad..783742764b 100644
--- a/cpp/src/qpid/client/TCPConnector.cpp
+++ b/cpp/src/qpid/client/TCPConnector.cpp
@@ -72,12 +72,13 @@ TCPConnector::TCPConnector(Poller::shared_ptr p,
closed(true),
shutdownHandler(0),
input(0),
+ socket(createSocket()),
connector(0),
aio(0),
poller(p)
{
QPID_LOG(debug, "TCPConnector created for " << version);
- settings.configureSocket(socket);
+ settings.configureSocket(*socket);
}
TCPConnector::~TCPConnector() {
@@ -88,7 +89,7 @@ void TCPConnector::connect(const std::string& host, const std::string& port) {
Mutex::ScopedLock l(lock);
assert(closed);
connector = AsynchConnector::create(
- socket,
+ *socket,
host, port,
boost::bind(&TCPConnector::connected, this, _1),
boost::bind(&TCPConnector::connectFailed, this, _3));
@@ -99,7 +100,7 @@ void TCPConnector::connect(const std::string& host, const std::string& port) {
void TCPConnector::connected(const Socket&) {
connector = 0;
- aio = AsynchIO::create(socket,
+ aio = AsynchIO::create(*socket,
boost::bind(&TCPConnector::readbuff, this, _1, _2),
boost::bind(&TCPConnector::eof, this, _1),
boost::bind(&TCPConnector::disconnected, this, _1),
@@ -116,7 +117,7 @@ void TCPConnector::start(sys::AsynchIO* aio_) {
aio->createBuffers(maxFrameSize);
- identifier = str(format("[%1%]") % socket.getFullAddress());
+ identifier = str(format("[%1%]") % socket->getFullAddress());
}
void TCPConnector::initAmqp() {
@@ -127,7 +128,7 @@ void TCPConnector::initAmqp() {
void TCPConnector::connectFailed(const std::string& msg) {
connector = 0;
QPID_LOG(warning, "Connect failed: " << msg);
- socket.close();
+ socket->close();
if (!closed)
closed = true;
if (shutdownHandler)
@@ -150,6 +151,11 @@ void TCPConnector::socketClosed(AsynchIO&, const Socket&) {
shutdownHandler->shutdown();
}
+void TCPConnector::connectAborted() {
+ connector->stop();
+ connectFailed("Connection timedout");
+}
+
void TCPConnector::abort() {
// Can't abort a closed connection
if (!closed) {
@@ -158,8 +164,7 @@ void TCPConnector::abort() {
aio->requestCallback(boost::bind(&TCPConnector::eof, this, _1));
} else if (connector) {
// We're still connecting
- connector->stop();
- connectFailed("Connection timedout");
+ connector->requestCallback(boost::bind(&TCPConnector::connectAborted, this));
}
}
}
@@ -245,9 +250,9 @@ bool TCPConnector::canEncode()
}
// Called in IO thread.
-size_t TCPConnector::encode(const char* buffer, size_t size)
+size_t TCPConnector::encode(char* buffer, size_t size)
{
- framing::Buffer out(const_cast<char*>(buffer), size);
+ framing::Buffer out(buffer, size);
size_t bytesWritten(0);
{
Mutex::ScopedLock l(lock);
@@ -318,7 +323,7 @@ void TCPConnector::eof(AsynchIO&) {
void TCPConnector::disconnected(AsynchIO&) {
close();
- socketClosed(*aio, socket);
+ socketClosed(*aio, *socket);
}
void TCPConnector::activateSecurityLayer(std::auto_ptr<qpid::sys::SecurityLayer> sl)
diff --git a/cpp/src/qpid/client/TCPConnector.h b/cpp/src/qpid/client/TCPConnector.h
index c0bc26028d..63af3b878a 100644
--- a/cpp/src/qpid/client/TCPConnector.h
+++ b/cpp/src/qpid/client/TCPConnector.h
@@ -35,7 +35,7 @@
#include "qpid/sys/Thread.h"
#include <boost/shared_ptr.hpp>
-#include <boost/weak_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
#include <deque>
#include <string>
@@ -66,7 +66,7 @@ class TCPConnector : public Connector, public sys::Codec
sys::ShutdownHandler* shutdownHandler;
framing::InputHandler* input;
- sys::Socket socket;
+ boost::scoped_ptr<sys::Socket> socket;
sys::AsynchConnector* connector;
sys::AsynchIO* aio;
@@ -80,6 +80,7 @@ class TCPConnector : public Connector, public sys::Codec
void close();
void send(framing::AMQFrame& frame);
void abort();
+ void connectAborted();
void setInputHandler(framing::InputHandler* handler);
void setShutdownHandler(sys::ShutdownHandler* handler);
@@ -90,7 +91,7 @@ class TCPConnector : public Connector, public sys::Codec
const qpid::sys::SecuritySettings* getSecuritySettings() { return 0; }
size_t decode(const char* buffer, size_t size);
- size_t encode(const char* buffer, size_t size);
+ size_t encode(char* buffer, size_t size);
bool canEncode();
protected:
diff --git a/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp b/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp
index aaebec0720..f43119ea4c 100644
--- a/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp
+++ b/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp
@@ -26,6 +26,7 @@
#include "qpid/framing/Uuid.h"
#include "qpid/log/Statement.h"
#include "qpid/Url.h"
+#include "qpid/amqp_0_10/Codecs.h"
#include <boost/intrusive_ptr.hpp>
#include <vector>
#include <sstream>
@@ -156,6 +157,8 @@ void ConnectionImpl::setOption(const std::string& name, const Variant& value)
settings.sslCertName = value.asString();
} else if (name == "x-reconnect-on-limit-exceeded" || name == "x_reconnect_on_limit_exceeded") {
reconnectOnLimitExceeded = value;
+ } else if (name == "client-properties") {
+ amqp_0_10::translate(value.asMap(), settings.clientProperties);
} else {
throw qpid::messaging::MessagingException(QPID_MSG("Invalid option: " << name << " not recognised"));
}
diff --git a/cpp/src/qpid/client/windows/ClientDllMain.cpp b/cpp/src/qpid/client/windows/ClientDllMain.cpp
new file mode 100644
index 0000000000..d636489908
--- /dev/null
+++ b/cpp/src/qpid/client/windows/ClientDllMain.cpp
@@ -0,0 +1,22 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/sys/windows/QpidDllMain.h"
diff --git a/cpp/src/qpid/client/windows/SslConnector.cpp b/cpp/src/qpid/client/windows/SslConnector.cpp
index 2aa31e8202..e1f34e7aea 100644
--- a/cpp/src/qpid/client/windows/SslConnector.cpp
+++ b/cpp/src/qpid/client/windows/SslConnector.cpp
@@ -71,6 +71,8 @@ class SslConnector : public qpid::client::TCPConnector
void redirectReadbuff(qpid::sys::AsynchIO&, qpid::sys::AsynchIOBufferBase*);
void redirectWritebuff(qpid::sys::AsynchIO&);
void redirectEof(qpid::sys::AsynchIO&);
+ void redirectDisconnect(qpid::sys::AsynchIO&);
+ void redirectSocketClosed(qpid::sys::AsynchIO&, const qpid::sys::Socket&);
public:
SslConnector(boost::shared_ptr<qpid::sys::Poller>,
@@ -79,7 +81,6 @@ public:
ConnectionImpl*);
virtual void connect(const std::string& host, const std::string& port);
virtual void connected(const Socket&);
- unsigned int getSSF();
};
// Static constructor which registers connector here
@@ -124,6 +125,14 @@ void SslConnector::redirectEof(qpid::sys::AsynchIO& a) {
eof(a);
}
+void SslConnector::redirectDisconnect(qpid::sys::AsynchIO& a) {
+ disconnected(a);
+}
+
+void SslConnector::redirectSocketClosed(qpid::sys::AsynchIO& a, const qpid::sys::Socket& s) {
+ socketClosed(a, s);
+}
+
SslConnector::SslConnector(boost::shared_ptr<qpid::sys::Poller> p,
framing::ProtocolVersion ver,
const ConnectionSettings& settings,
@@ -164,8 +173,8 @@ void SslConnector::connected(const Socket& s) {
credHandle,
boost::bind(&SslConnector::redirectReadbuff, this, _1, _2),
boost::bind(&SslConnector::redirectEof, this, _1),
- boost::bind(&SslConnector::redirectEof, this, _1),
- 0, // closed
+ boost::bind(&SslConnector::redirectDisconnect, this, _1),
+ boost::bind(&SslConnector::redirectSocketClosed, this, _1, _2),
0, // nobuffs
boost::bind(&SslConnector::redirectWritebuff, this, _1),
boost::bind(&SslConnector::negotiationDone, this, _1));
@@ -173,9 +182,4 @@ void SslConnector::connected(const Socket& s) {
shim->start(poller);
}
-unsigned int SslConnector::getSSF()
-{
- return shim->getSslKeySize();
-}
-
}}} // namespace qpid::client::windows
diff --git a/cpp/src/qpid/framing/FieldValue.cpp b/cpp/src/qpid/framing/FieldValue.cpp
index ce5a50117c..4abed0f77f 100644
--- a/cpp/src/qpid/framing/FieldValue.cpp
+++ b/cpp/src/qpid/framing/FieldValue.cpp
@@ -23,6 +23,7 @@
#include "qpid/framing/Buffer.h"
#include "qpid/framing/Endian.h"
#include "qpid/framing/List.h"
+#include "qpid/framing/Uuid.h"
#include "qpid/framing/reply_exceptions.h"
#include "qpid/Msg.h"
@@ -43,7 +44,9 @@ void FieldValue::setType(uint8_t type)
data.reset(new EncodedValue<List>());
} else if (typeOctet == 0xAA) {
data.reset(new EncodedValue<Array>());
- } else {
+ } else if (typeOctet == 0x48) {
+ data.reset(new UuidData());
+ } else {
uint8_t lenType = typeOctet >> 4;
switch(lenType){
case 0:
@@ -213,9 +216,12 @@ Integer8Value::Integer8Value(int8_t v) :
Integer16Value::Integer16Value(int16_t v) :
FieldValue(0x11, new FixedWidthValue<2>(v))
{}
-UuidValue::UuidValue(const unsigned char* v) :
- FieldValue(0x48, new FixedWidthValue<16>(v))
-{}
+
+UuidData::UuidData() {}
+UuidData::UuidData(const unsigned char* bytes) : FixedWidthValue<16>(bytes) {}
+bool UuidData::convertsToString() const { return true; }
+std::string UuidData::getString() const { return Uuid(rawOctets()).str(); }
+UuidValue::UuidValue(const unsigned char* v) : FieldValue(0x48, new UuidData(v)) {}
void FieldValue::print(std::ostream& out) const {
data->print(out);
diff --git a/cpp/src/qpid/framing/FrameSet.h b/cpp/src/qpid/framing/FrameSet.h
index 3b9f60950b..9640abb7ac 100644
--- a/cpp/src/qpid/framing/FrameSet.h
+++ b/cpp/src/qpid/framing/FrameSet.h
@@ -1,3 +1,5 @@
+#ifndef QPID_FRAMING_FRAMESET_H
+#define QPID_FRAMING_FRAMESET_H
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -18,6 +20,7 @@
* under the License.
*
*/
+
#include <string>
#include "qpid/InlineVector.h"
#include "qpid/framing/amqp_framing.h"
@@ -25,9 +28,6 @@
#include "qpid/framing/SequenceNumber.h"
#include "qpid/CommonImportExport.h"
-#ifndef _FrameSet_
-#define _FrameSet_
-
namespace qpid {
namespace framing {
@@ -117,4 +117,4 @@ public:
}
-#endif
+#endif /*!QPID_FRAMING_FRAMESET_H*/
diff --git a/cpp/src/qpid/framing/Handler.h b/cpp/src/qpid/framing/Handler.h
index fa8db36f49..e0c0e59d09 100644
--- a/cpp/src/qpid/framing/Handler.h
+++ b/cpp/src/qpid/framing/Handler.h
@@ -49,29 +49,12 @@ struct Handler {
* Functor<F>(f) will copy f.
* Functor<F&>(f) will only take a reference to x.
*/
- template <class F> class Functor : public Handler<T> {
- public:
- Functor(F f, Handler<T>* next=0) : Handler<T>(next), functor(f) {}
- void handle(T t) { functor(t); }
- private:
- F functor;
- };
+ template <class F> class Functor;
/** Adapt a member function of X as a Handler.
* Only holds a reference to its target, not a copy.
*/
- template <class X, void (X::*F)(T)>
- class MemFunRef : public Handler<T> {
- public:
- MemFunRef(X& x, Handler<T>* next=0) : Handler(next), target(&x) {}
- void handle(T t) { (target->*F)(t); }
-
- /** Allow calling with -> syntax */
- MemFunRef* operator->() { return this; }
-
- private:
- X* target;
- };
+ template <class X, void (X::*F)(T)> class MemFunRef;
/** Interface for a handler that implements a
* pair of in/out handle operations.
@@ -94,7 +77,29 @@ struct Handler {
};
};
+template <class T>
+template <class F>
+class Handler<T>::Functor : public Handler<T> {
+ public:
+ Functor(F f, Handler<T>* next=0) : Handler<T>(next), functor(f) {}
+ void handle(T t) { functor(t); }
+ private:
+ F functor;
+};
+
+template <class T>
+template <class X, void (X::*F)(T)>
+class Handler<T>::MemFunRef : public Handler<T> {
+ public:
+ MemFunRef(X& x, Handler<T>* next=0) : Handler(next), target(&x) {}
+ void handle(T t) { (target->*F)(t); }
+
+ /** Allow calling with -> syntax */
+ MemFunRef* operator->() { return this; }
+ private:
+ X* target;
+};
}}
#endif /*!QPID_FRAMING_HANDLER_H*/
diff --git a/cpp/src/qpid/framing/ProtocolInitiation.cpp b/cpp/src/qpid/framing/ProtocolInitiation.cpp
index 00ddb55a3b..19cb3f0e3d 100644
--- a/cpp/src/qpid/framing/ProtocolInitiation.cpp
+++ b/cpp/src/qpid/framing/ProtocolInitiation.cpp
@@ -38,10 +38,17 @@ void ProtocolInitiation::encode(Buffer& buffer) const {
buffer.putOctet('M');
buffer.putOctet('Q');
buffer.putOctet('P');
- buffer.putOctet(1);//class
- buffer.putOctet(1);//instance
- buffer.putOctet(version.getMajor());
- buffer.putOctet(version.getMinor());
+ if (version.getMajor() == 1) {
+ buffer.putOctet(version.getProtocol());
+ buffer.putOctet(version.getMajor());
+ buffer.putOctet(version.getMinor());
+ buffer.putOctet(0);//revision
+ } else {
+ buffer.putOctet(1);//class
+ buffer.putOctet(1);//instance
+ buffer.putOctet(version.getMajor());
+ buffer.putOctet(version.getMinor());
+ }
}
bool ProtocolInitiation::decode(Buffer& buffer){
@@ -50,10 +57,18 @@ bool ProtocolInitiation::decode(Buffer& buffer){
buffer.getOctet();//M
buffer.getOctet();//Q
buffer.getOctet();//P
- buffer.getOctet();//class
- buffer.getOctet();//instance
- version.setMajor(buffer.getOctet());
- version.setMinor(buffer.getOctet());
+ uint8_t protocolClass = buffer.getOctet();//class
+ version.setProtocol(protocolClass);
+ if (protocolClass == 1) {
+ //old (pre-1.0) style
+ buffer.getOctet();//instance
+ version.setMajor(buffer.getOctet());
+ version.setMinor(buffer.getOctet());
+ } else {
+ version.setMajor(buffer.getOctet());
+ version.setMinor(buffer.getOctet());
+ buffer.getOctet();//revision
+ }
return true;
}else{
return false;
diff --git a/cpp/src/qpid/framing/ProtocolVersion.cpp b/cpp/src/qpid/framing/ProtocolVersion.cpp
index c63cddb4cc..174fc3e65b 100644
--- a/cpp/src/qpid/framing/ProtocolVersion.cpp
+++ b/cpp/src/qpid/framing/ProtocolVersion.cpp
@@ -27,6 +27,10 @@ const std::string ProtocolVersion::toString() const
{
std::stringstream ss;
ss << major_ << "-" << minor_;
+ if (major_ == 1) {
+ if (protocol_ == SASL) ss << " (SASL)";
+ else if (protocol_ == TLS) ss << " (TLS)";
+ }
return ss.str();
}
@@ -42,3 +46,7 @@ bool ProtocolVersion::operator==(ProtocolVersion p) const
return major_ == p.major_ && minor_ == p.minor_;
}
+uint8_t ProtocolVersion::AMQP(0);
+uint8_t ProtocolVersion::LEGACY_AMQP(1);
+uint8_t ProtocolVersion::TLS(2);
+uint8_t ProtocolVersion::SASL(3);
diff --git a/cpp/src/qpid/ha/AlternateExchangeSetter.h b/cpp/src/qpid/ha/AlternateExchangeSetter.h
index 08690e68bc..2386a01084 100644
--- a/cpp/src/qpid/ha/AlternateExchangeSetter.h
+++ b/cpp/src/qpid/ha/AlternateExchangeSetter.h
@@ -43,12 +43,14 @@ class AlternateExchangeSetter
AlternateExchangeSetter(broker::ExchangeRegistry& er) : exchanges(er) {}
+ /** If altEx is already known, call setter(altEx) now else save for later */
void setAlternate(const std::string& altEx, const SetFunction& setter) {
- broker::Exchange::shared_ptr ex = exchanges.find(altEx);
+ boost::shared_ptr<broker::Exchange> ex = exchanges.find(altEx);
if (ex) setter(ex); // Set immediately.
else setters.insert(Setters::value_type(altEx, setter)); // Save for later.
}
+ /** Add an exchange and call any setters that are waiting for it. */
void addExchange(boost::shared_ptr<broker::Exchange> exchange) {
// Update the setters for this exchange
std::pair<Setters::iterator, Setters::iterator> range = setters.equal_range(exchange->getName());
diff --git a/cpp/src/qpid/ha/Backup.cpp b/cpp/src/qpid/ha/Backup.cpp
index 6852a58b0c..2affc12bf6 100644
--- a/cpp/src/qpid/ha/Backup.cpp
+++ b/cpp/src/qpid/ha/Backup.cpp
@@ -20,9 +20,12 @@
*/
#include "Backup.h"
#include "BrokerReplicator.h"
+#include "ConnectionObserver.h"
#include "HaBroker.h"
+#include "Primary.h"
#include "ReplicatingSubscription.h"
#include "Settings.h"
+#include "StatusCheck.h"
#include "qpid/Url.h"
#include "qpid/amqp_0_10/Codecs.h"
#include "qpid/broker/Bridge.h"
@@ -44,28 +47,38 @@ using namespace framing;
using namespace broker;
using types::Variant;
using std::string;
+using sys::Mutex;
Backup::Backup(HaBroker& hb, const Settings& s) :
- logPrefix("Backup: "), haBroker(hb), broker(hb.getBroker()), settings(s)
+ logPrefix("Backup: "), membership(hb.getMembership()), stopped(false),
+ haBroker(hb), broker(hb.getBroker()), settings(s),
+ statusCheck(
+ new StatusCheck(
+ logPrefix, broker.getLinkHearbeatInterval(), hb.getBrokerInfo()))
{
- // Empty brokerUrl means delay initialization until seBrokertUrl() is called.
- if (!s.brokerUrl.empty()) initialize(Url(s.brokerUrl));
+ // Set link properties to tag outgoing links.
+ framing::FieldTable linkProperties = broker.getLinkClientProperties();
+ linkProperties.setTable(
+ ConnectionObserver::BACKUP_TAG, hb.getBrokerInfo().asFieldTable());
+ broker.setLinkClientProperties(linkProperties);
}
-void Backup::initialize(const Url& brokers) {
- if (brokers.empty()) throw Url::Invalid("HA broker URL is empty");
- QPID_LOG(info, logPrefix << "Connecting to cluster, broker URL: " << brokers);
- string protocol = brokers[0].protocol.empty() ? "tcp" : brokers[0].protocol;
- types::Uuid uuid(true);
- // Declare the link
- std::pair<Link::shared_ptr, bool> result = broker.getLinks().declare(
- broker::QPID_NAME_PREFIX + string("ha.link.") + uuid.str(),
- brokers[0].host, brokers[0].port, protocol,
- false, // durable
- settings.mechanism, settings.username, settings.password,
- false); // no amq.failover - don't want to use client URL.
- {
- sys::Mutex::ScopedLock l(lock);
+void Backup::setBrokerUrl(const Url& brokers) {
+ if (brokers.empty()) return;
+ Mutex::ScopedLock l(lock);
+ if (stopped) return;
+ if (haBroker.getStatus() == JOINING) statusCheck->setUrl(brokers);
+ if (!link) { // Not yet initialized
+ QPID_LOG(info, logPrefix << "Connecting to cluster, broker URL: " << brokers);
+ string protocol = brokers[0].protocol.empty() ? "tcp" : brokers[0].protocol;
+ types::Uuid uuid(true);
+ std::pair<Link::shared_ptr, bool> result;
+ result = broker.getLinks().declare(
+ broker::QPID_NAME_PREFIX + string("ha.link.") + uuid.str(),
+ brokers[0].host, brokers[0].port, protocol,
+ false, // durable
+ settings.mechanism, settings.username, settings.password,
+ false); // no amq.failover - don't want to use client URL.
link = result.first;
replicator.reset(new BrokerReplicator(haBroker, link));
replicator->initialize();
@@ -74,36 +87,57 @@ void Backup::initialize(const Url& brokers) {
link->setUrl(brokers); // Outside the lock, once set link doesn't change.
}
-Backup::~Backup() {
+void Backup::stop(Mutex::ScopedLock&) {
+ if (stopped) return;
+ stopped = true;
+ QPID_LOG(debug, logPrefix << "Leaving backup role.");
if (link) link->close();
- if (replicator.get()) broker.getExchanges().destroy(replicator->getName());
+ if (replicator.get()) {
+ replicator->shutdown();
+ replicator.reset();
+ }
}
-// Called via management.
-void Backup::setBrokerUrl(const Url& url) {
- // Ignore empty URLs seen during start-up for some tests.
- if (url.empty()) return;
- bool linkSet = false;
+Role* Backup::recover(Mutex::ScopedLock&) {
+ BrokerInfo::Set backups;
{
- sys::Mutex::ScopedLock l(lock);
- linkSet = link;
+ Mutex::ScopedLock l(lock);
+ if (stopped) return 0;
+ stop(l); // Stop backup activity before starting primary.
+ QPID_LOG(notice, "Promoting to primary: " << haBroker.getBrokerInfo());
+ // Reset membership before allowing backups to connect.
+ backups = membership.otherBackups();
+ membership.clear();
+ return new Primary(haBroker, backups);
}
- if (linkSet)
- link->setUrl(url); // Outside lock, once set link doesn't change
- else
- initialize(url); // Deferred initialization
}
-void Backup::setStatus(BrokerStatus status) {
- switch (status) {
- case READY:
- QPID_LOG(notice, logPrefix << "Ready to become primary.");
+Role* Backup::promote() {
+ Mutex::ScopedLock l(lock);
+ if (stopped) return 0;
+ switch (haBroker.getStatus()) {
+ case JOINING:
+ if (statusCheck->canPromote()) return recover(l);
+ else {
+ QPID_LOG(error,
+ logPrefix << "Joining active cluster, cannot be promoted.");
+ throw Exception("Joining active cluster, cannot be promoted.");
+ }
break;
case CATCHUP:
- QPID_LOG(notice, logPrefix << "Catching up on primary, cannot be promoted.");
+ QPID_LOG(error, logPrefix << "Still catching up, cannot be promoted.");
+ throw Exception("Still catching up, cannot be promoted.");
+ break;
+ case READY: return recover(l); break;
default:
- assert(0);
+ assert(0); // Not a valid state for the Backup role..
}
+ return 0; // Keep compiler happy
+}
+
+Backup::~Backup() {
+ Mutex::ScopedLock l(lock);
+ stop(l);
}
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/Backup.h b/cpp/src/qpid/ha/Backup.h
index 4f2d5babde..4943ca5e2e 100644
--- a/cpp/src/qpid/ha/Backup.h
+++ b/cpp/src/qpid/ha/Backup.h
@@ -22,6 +22,7 @@
*
*/
+#include "Role.h"
#include "Settings.h"
#include "qpid/Url.h"
#include "qpid/sys/Mutex.h"
@@ -38,30 +39,41 @@ namespace ha {
class Settings;
class BrokerReplicator;
class HaBroker;
+class StatusCheck;
+class Membership;
/**
- * State associated with a backup broker. Manages connections to primary.
+ * Backup role: Manages connections to primary, replicates management events and queue contents.
*
* THREAD SAFE
*/
-class Backup
+class Backup : public Role
{
public:
Backup(HaBroker&, const Settings&);
~Backup();
+
+ std::string getLogPrefix() const { return logPrefix; }
+
void setBrokerUrl(const Url&);
- void setStatus(BrokerStatus);
+
+ Role* promote();
private:
- void initialize(const Url&);
+ void stop(sys::Mutex::ScopedLock&);
+ Role* recover(sys::Mutex::ScopedLock&);
+
std::string logPrefix;
+ Membership& membership;
sys::Mutex lock;
+ bool stopped;
HaBroker& haBroker;
broker::Broker& broker;
Settings settings;
boost::shared_ptr<broker::Link> link;
boost::shared_ptr<BrokerReplicator> replicator;
+ std::auto_ptr<StatusCheck> statusCheck;
};
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/BrokerInfo.cpp b/cpp/src/qpid/ha/BrokerInfo.cpp
index c8bd1a14be..8efed91b17 100644
--- a/cpp/src/qpid/ha/BrokerInfo.cpp
+++ b/cpp/src/qpid/ha/BrokerInfo.cpp
@@ -33,27 +33,22 @@ namespace qpid {
namespace ha {
namespace {
-std::string SYSTEM_ID="system-id";
-std::string HOST_NAME="host-name";
-std::string PORT="port";
-std::string STATUS="status";
+const std::string SYSTEM_ID="system-id";
+const std::string HOST_NAME="host-name";
+const std::string PORT="port";
+const std::string STATUS="status";
}
using types::Uuid;
using types::Variant;
using framing::FieldTable;
-BrokerInfo::BrokerInfo(const std::string& host, uint16_t port_, const types::Uuid& id) :
- hostName(host), port(port_), systemId(id)
-{
- updateLogId();
-}
+BrokerInfo::BrokerInfo() : port(0), status(JOINING) {}
-void BrokerInfo::updateLogId() {
- std::ostringstream o;
- o << hostName << ":" << port;
- logId = o.str();
-}
+BrokerInfo::BrokerInfo(const types::Uuid& id, BrokerStatus s,
+ const std::string& host, uint16_t port_) :
+ hostName(host), port(port_), systemId(id), status(s)
+{}
FieldTable BrokerInfo::asFieldTable() const {
Variant::Map m = asMap();
@@ -91,7 +86,6 @@ void BrokerInfo::assign(const Variant::Map& m) {
hostName = get(m, HOST_NAME).asString();
port = get(m, PORT).asUint16();
status = BrokerStatus(get(m, STATUS).asUint8());
- updateLogId();
}
std::ostream& operator<<(std::ostream& o, const BrokerInfo& b) {
diff --git a/cpp/src/qpid/ha/BrokerInfo.h b/cpp/src/qpid/ha/BrokerInfo.h
index 642f7c1361..40358336b0 100644
--- a/cpp/src/qpid/ha/BrokerInfo.h
+++ b/cpp/src/qpid/ha/BrokerInfo.h
@@ -43,8 +43,9 @@ class BrokerInfo
typedef std::set<BrokerInfo> Set;
typedef std::map<types::Uuid, BrokerInfo> Map;
- BrokerInfo() {}
- BrokerInfo(const std::string& host, uint16_t port_, const types::Uuid& id);
+ BrokerInfo();
+ BrokerInfo(const types::Uuid& id, BrokerStatus,
+ const std::string& host=std::string(), uint16_t port=0);
BrokerInfo(const framing::FieldTable& ft) { assign(ft); }
BrokerInfo(const types::Variant::Map& m) { assign(m); }
@@ -52,7 +53,6 @@ class BrokerInfo
std::string getHostName() const { return hostName; }
BrokerStatus getStatus() const { return status; }
uint16_t getPort() const { return port; }
- std::string getLogId() const { return logId; }
void setStatus(BrokerStatus s) { status = s; }
@@ -66,8 +66,6 @@ class BrokerInfo
bool operator<(const BrokerInfo x) const { return systemId < x.systemId; }
private:
- void updateLogId();
- std::string logId;
std::string hostName;
uint16_t port;
types::Uuid systemId;
diff --git a/cpp/src/qpid/ha/BrokerReplicator.cpp b/cpp/src/qpid/ha/BrokerReplicator.cpp
index 3a3c9c2954..983b976d76 100644
--- a/cpp/src/qpid/ha/BrokerReplicator.cpp
+++ b/cpp/src/qpid/ha/BrokerReplicator.cpp
@@ -23,16 +23,19 @@
#include "QueueReplicator.h"
#include "qpid/broker/Broker.h"
#include "qpid/broker/Connection.h"
+#include "qpid/broker/ConnectionObserver.h"
#include "qpid/broker/Queue.h"
#include "qpid/broker/QueueSettings.h"
#include "qpid/broker/Link.h"
#include "qpid/broker/amqp_0_10/MessageTransfer.h"
#include "qpid/framing/FieldTable.h"
+#include "qpid/framing/FieldValue.h"
#include "qpid/log/Statement.h"
#include "qpid/amqp_0_10/Codecs.h"
#include "qpid/broker/SessionHandler.h"
#include "qpid/framing/reply_exceptions.h"
#include "qpid/framing/MessageTransferBody.h"
+#include "qpid/framing/reply_exceptions.h"
#include "qmf/org/apache/qpid/broker/EventBind.h"
#include "qmf/org/apache/qpid/broker/EventUnbind.h"
#include "qmf/org/apache/qpid/broker/EventExchangeDeclare.h"
@@ -41,6 +44,7 @@
#include "qmf/org/apache/qpid/broker/EventQueueDelete.h"
#include "qmf/org/apache/qpid/broker/EventSubscribe.h"
#include "qmf/org/apache/qpid/ha/EventMembersUpdate.h"
+#include <boost/bind.hpp>
#include <algorithm>
#include <sstream>
#include <iostream>
@@ -57,23 +61,25 @@ using qmf::org::apache::qpid::broker::EventQueueDeclare;
using qmf::org::apache::qpid::broker::EventQueueDelete;
using qmf::org::apache::qpid::broker::EventSubscribe;
using qmf::org::apache::qpid::ha::EventMembersUpdate;
+using qpid::broker::amqp_0_10::MessageTransfer;
using namespace framing;
-using std::string;
+using namespace std;
using std::ostream;
using types::Variant;
using namespace broker;
namespace {
-const string QPID_CONFIGURATION_REPLICATOR("qpid.configuration-replicator");
+const string QPID_CONFIGURATION_REPLICATOR("qpid.broker-replicator");
const string CLASS_NAME("_class_name");
const string EVENT("_event");
const string OBJECT_NAME("_object_name");
const string PACKAGE_NAME("_package_name");
const string QUERY_RESPONSE("_query_response");
-const string SCHEMA_ID("_schema_id");
const string VALUES("_values");
+const string SCHEMA_ID("_schema_id");
+const string WHAT("_what");
const string ALTEX("altEx");
const string ALTEXCHANGE("altExchange");
@@ -81,24 +87,27 @@ const string ARGS("args");
const string ARGUMENTS("arguments");
const string AUTODEL("autoDel");
const string AUTODELETE("autoDelete");
-const string EXCL("excl");
-const string EXCLUSIVE("exclusive");
const string BIND("bind");
-const string UNBIND("unbind");
const string BINDING("binding");
+const string BINDING_KEY("bindingKey");
const string CREATED("created");
const string DISP("disp");
+const string DEST("dest");
const string DURABLE("durable");
const string EXCHANGE("exchange");
+const string EXCL("excl");
+const string EXCLUSIVE("exclusive");
const string EXNAME("exName");
const string EXTYPE("exType");
+const string HA_BROKER("habroker");
const string KEY("key");
const string NAME("name");
+const string PARTIAL("partial");
const string QNAME("qName");
const string QUEUE("queue");
const string TYPE("type");
-const string HA_BROKER("habroker");
-const string PARTIAL("partial");
+const string UNBIND("unbind");
+const string CONSUMER_COUNT("consumerCount");
const string AGENT_EVENT_BROKER("agent.ind.event.org_apache_qpid_broker.#");
const string AGENT_EVENT_HA("agent.ind.event.org_apache_qpid_ha.#");
@@ -107,10 +116,6 @@ const string QMF_CONTENT("qmf.content");
const string QMF_DEFAULT_TOPIC("qmf.default.topic");
const string QMF_OPCODE("qmf.opcode");
-const string _WHAT("_what");
-const string _CLASS_NAME("_class_name");
-const string _PACKAGE_NAME("_package_name");
-const string _SCHEMA_ID("_schema_id");
const string OBJECT("OBJECT");
const string ORG_APACHE_QPID_BROKER("org.apache.qpid.broker");
const string ORG_APACHE_QPID_HA("org.apache.qpid.ha");
@@ -118,21 +123,18 @@ const string QMF_DEFAULT_DIRECT("qmf.default.direct");
const string _QUERY_REQUEST("_query_request");
const string BROKER("broker");
const string MEMBERS("members");
-
-template <class T> bool match(Variant::Map& schema) {
- return T::match(schema[CLASS_NAME], schema[PACKAGE_NAME]);
-}
+const string AUTO_DELETE_TIMEOUT("qpid.auto_delete_timeout");
void sendQuery(const string& packageName, const string& className, const string& queueName,
SessionHandler& sessionHandler)
{
framing::AMQP_ServerProxy peer(sessionHandler.out);
Variant::Map request;
- request[_WHAT] = OBJECT;
+ request[WHAT] = OBJECT;
Variant::Map schema;
- schema[_CLASS_NAME] = className;
- schema[_PACKAGE_NAME] = packageName;
- request[_SCHEMA_ID] = schema;
+ schema[CLASS_NAME] = className;
+ schema[PACKAGE_NAME] = packageName;
+ request[SCHEMA_ID] = schema;
AMQFrame method((MessageTransferBody(ProtocolVersion(), QMF_DEFAULT_DIRECT, 0, 0)));
method.setBof(true);
@@ -170,19 +172,144 @@ Variant::Map asMapVoid(const Variant& value) {
}
} // namespace
+// Listens for errors on the bridge session.
+class BrokerReplicator::ErrorListener : public SessionHandler::ErrorListener {
+ public:
+ ErrorListener(const std::string& lp, BrokerReplicator& br) :
+ logPrefix(lp), brokerReplicator(br) {}
+
+ void connectionException(framing::connection::CloseCode, const std::string& msg) {
+ QPID_LOG(error, logPrefix << "Connection error: " << msg);
+ }
+ void channelException(framing::session::DetachCode, const std::string& msg) {
+ QPID_LOG(error, logPrefix << "Channel error: " << msg);
+ }
+ void executionException(framing::execution::ErrorCode, const std::string& msg) {
+ QPID_LOG(error, logPrefix << "Execution error: " << msg);
+ }
+ void detach() {
+ QPID_LOG(debug, logPrefix << "Session detached.");
+ }
+
+ private:
+ std::string logPrefix;
+ BrokerReplicator& brokerReplicator;
+};
+
+class BrokerReplicator::ConnectionObserver : public broker::ConnectionObserver
+{
+ public:
+ ConnectionObserver(BrokerReplicator& br) : brokerReplicator(br) {}
+ virtual void connection(Connection&) {}
+ virtual void opened(Connection&) {}
+
+ virtual void closed(Connection& c) {
+ if (brokerReplicator.link && &c == brokerReplicator.connection)
+ brokerReplicator.disconnected();
+ }
+ virtual void forced(Connection& c, const std::string& /*message*/) { closed(c); }
+ private:
+ BrokerReplicator& brokerReplicator;
+};
+
+/** Keep track of queues or exchanges during the update process to solve 2
+ * problems.
+ *
+ * 1. Once all responses are processed, remove any queues/exchanges
+ * that were not mentioned as they no longer exist on the primary.
+ *
+ * 2. During the update if we see an event for an object we should
+ * ignore any subsequent responses for that object as they are out
+ * of date.
+ */
+class BrokerReplicator::UpdateTracker {
+ public:
+ typedef std::set<std::string> Names;
+ typedef boost::function<void (const std::string&)> CleanFn;
+
+ UpdateTracker(const std::string& type_, // "queue" or "exchange"
+ CleanFn f, const ReplicationTest& rt)
+ : type(type_), cleanFn(f), repTest(rt) {}
+
+ /** Destructor cleans up remaining initial queues. */
+ ~UpdateTracker() {
+ // Don't throw in a destructor.
+ try { for_each(initial.begin(), initial.end(), cleanFn); }
+ catch (const std::exception& e) {
+ QPID_LOG(error, "Error in cleanup of lost objects: " << e.what());
+ }
+ }
+
+ /** Add an exchange name */
+ void addExchange(Exchange::shared_ptr ex) {
+ if (repTest.getLevel(*ex))
+ initial.insert(ex->getName());
+ }
+
+ /** Add a queue name. */
+ void addQueue(Queue::shared_ptr q) {
+ if (repTest.getLevel(*q))
+ initial.insert(q->getName());
+ }
+
+ /** Received an event for name */
+ void event(const std::string& name) {
+ initial.erase(name); // no longer a candidate for deleting
+ events.insert(name); // we have seen an event for this name
+ }
+
+ /** Received a response for name.
+ *@return true if this response should be processed, false if we have
+ *already seen an event for this object.
+ */
+ bool response(const std::string& name) {
+ initial.erase(name); // no longer a candidate for deleting
+ return events.find(name) == events.end(); // true if no event seen yet.
+ }
+
+ private:
+ void clean(const std::string& name) {
+ QPID_LOG(info, "Backup updated, deleting " << type << " " << name);
+ cleanFn(name);
+ }
+
+ std::string type;
+ Names initial, events;
+ CleanFn cleanFn;
+ ReplicationTest repTest;
+};
+
BrokerReplicator::BrokerReplicator(HaBroker& hb, const boost::shared_ptr<Link>& l)
: Exchange(QPID_CONFIGURATION_REPLICATOR),
- logPrefix("Backup: "), replicationTest(hb.getReplicationTest()),
- haBroker(hb), broker(hb.getBroker()), link(l),
+ logPrefix("Backup: "), replicationTest(NONE),
+ haBroker(hb), broker(hb.getBroker()),
+ exchanges(broker.getExchanges()), queues(broker.getQueues()),
+ link(l),
initialized(false),
- alternates(hb.getBroker().getExchanges())
-{}
+ alternates(hb.getBroker().getExchanges()),
+ connection(0)
+{
+ connectionObserver.reset(new ConnectionObserver(*this));
+ broker.getConnectionObservers().add(connectionObserver);
+ framing::FieldTable args = getArgs();
+ args.setString(QPID_REPLICATE, printable(NONE).str());
+ setArgs(args);
+
+ dispatch[EventQueueDeclare::getFullName()] = &BrokerReplicator::doEventQueueDeclare;
+ dispatch[EventQueueDelete::getFullName()] = &BrokerReplicator::doEventQueueDelete;
+ dispatch[EventExchangeDeclare::getFullName()] = &BrokerReplicator::doEventExchangeDeclare;
+ dispatch[EventExchangeDelete::getFullName()] = &BrokerReplicator::doEventExchangeDelete;
+ dispatch[EventBind::getFullName()] = &BrokerReplicator::doEventBind;
+ dispatch[EventUnbind::getFullName()] = &BrokerReplicator::doEventUnbind;
+ dispatch[EventMembersUpdate::getFullName()] = &BrokerReplicator::doEventMembersUpdate;
+ dispatch[EventSubscribe::getFullName()] = &BrokerReplicator::doEventSubscribe;
+}
void BrokerReplicator::initialize() {
// Can't do this in the constructor because we need a shared_ptr to this.
types::Uuid uuid(true);
const std::string name(QPID_CONFIGURATION_REPLICATOR + ".bridge." + uuid.str());
- broker.getLinks().declare(
+ std::pair<Bridge::shared_ptr, bool> result = broker.getLinks().declare(
name, // name for bridge
*link, // parent
false, // durable
@@ -195,21 +322,47 @@ void BrokerReplicator::initialize() {
"", // excludes
false, // dynamic
0, // sync?
- // shared_ptr keeps this in memory until outstanding initializeBridge
+ // shared_ptr keeps this in memory until outstanding connected
// calls are run.
- boost::bind(&BrokerReplicator::initializeBridge, shared_from_this(), _1, _2)
+ boost::bind(&BrokerReplicator::connected, shared_from_this(), _1, _2)
);
+ assert(result.second);
+ result.first->setErrorListener(
+ boost::shared_ptr<ErrorListener>(new ErrorListener(logPrefix, *this)));
}
-BrokerReplicator::~BrokerReplicator() { }
+BrokerReplicator::~BrokerReplicator() { shutdown(); }
+
+namespace {
+void collectQueueReplicators(
+ const boost::shared_ptr<Exchange> ex, set<boost::shared_ptr<QueueReplicator> >& collect)
+{
+ boost::shared_ptr<QueueReplicator> qr(boost::dynamic_pointer_cast<QueueReplicator>(ex));
+ if (qr) collect.insert(qr);
+}
+} // namespace
+
+void BrokerReplicator::shutdown() {
+ // NOTE: this is called in a QMF dispatch thread, not the Link's connection
+ // thread. It's OK to be unlocked because it doesn't use any mutable state,
+ // it only calls thread safe functions objects belonging to the Broker.
+
+ // Unregister with broker objects:
+ if (connectionObserver) {
+ broker.getConnectionObservers().remove(connectionObserver);
+ connectionObserver.reset();
+ }
+ broker.getExchanges().destroy(getName());
+}
// This is called in the connection IO thread when the bridge is started.
-void BrokerReplicator::initializeBridge(Bridge& bridge, SessionHandler& sessionHandler) {
+void BrokerReplicator::connected(Bridge& bridge, SessionHandler& sessionHandler) {
// Use the credentials of the outgoing Link connection for creating queues,
// exchanges etc. We know link->getConnection() is non-zero because we are
// being called in the connections thread context.
//
- assert(link->getConnection());
+ connection = link->getConnection();
+ assert(connection);
userId = link->getConnection()->getUserId();
remoteHost = link->getConnection()->getUrl();
@@ -221,6 +374,19 @@ void BrokerReplicator::initializeBridge(Bridge& bridge, SessionHandler& sessionH
<< " status:" << printable(haBroker.getStatus()));
initialized = true;
+ exchangeTracker.reset(
+ new UpdateTracker("exchange",
+ boost::bind(&BrokerReplicator::deleteExchange, this, _1),
+ replicationTest));
+ exchanges.eachExchange(
+ boost::bind(&UpdateTracker::addExchange, exchangeTracker.get(), _1));
+
+ queueTracker.reset(
+ new UpdateTracker("queue",
+ boost::bind(&BrokerReplicator::deleteQueue, this, _1, true),
+ replicationTest));
+ queues.eachQueue(boost::bind(&UpdateTracker::addQueue, queueTracker.get(), _1));
+
framing::AMQP_ServerProxy peer(sessionHandler.out);
const qmf::org::apache::qpid::broker::ArgsLinkBridge& args(bridge.getArgs());
@@ -231,9 +397,14 @@ void BrokerReplicator::initializeBridge(Bridge& bridge, SessionHandler& sessionH
peer.getExchange().bind(queueName, QMF_DEFAULT_TOPIC, AGENT_EVENT_BROKER, FieldTable());
peer.getExchange().bind(queueName, QMF_DEFAULT_TOPIC, AGENT_EVENT_HA, FieldTable());
//subscribe to the queue
- peer.getMessage().subscribe(queueName, args.i_dest, 1, 0, false, "", 0, FieldTable());
- peer.getMessage().flow(args.i_dest, 0, 0xFFFFFFFF);
- peer.getMessage().flow(args.i_dest, 1, 0xFFFFFFFF);
+ FieldTable arguments;
+ arguments.setInt(QueueReplicator::QPID_SYNC_FREQUENCY, 1); // FIXME aconway 2012-05-22: optimize?
+ peer.getMessage().subscribe(
+ queueName, args.i_dest, 1/*accept-none*/, 0/*pre-acquired*/,
+ false/*exclusive*/, "", 0, arguments);
+ peer.getMessage().setFlowMode(args.i_dest, 1); // Window
+ peer.getMessage().flow(args.i_dest, 0, haBroker.getSettings().getFlowMessages());
+ peer.getMessage().flow(args.i_dest, 1, haBroker.getSettings().getFlowBytes());
// Issue a query request for queues, exchanges, bindings and the habroker
// using event queue as the reply-to address
@@ -247,12 +418,12 @@ void BrokerReplicator::route(Deliverable& msg) {
// We transition from JOINING->CATCHUP on the first message received from the primary.
// Until now we couldn't be sure if we had a good connection to the primary.
if (haBroker.getStatus() == JOINING) {
- haBroker.setStatus(CATCHUP);
+ haBroker.getMembership().setStatus(CATCHUP);
QPID_LOG(notice, logPrefix << "Connected to primary " << primary);
}
Variant::List list;
try {
- if (!qpid::broker::amqp_0_10::MessageTransfer::isQMFv2(msg.getMessage()))
+ if (!MessageTransfer::isQMFv2(msg.getMessage()))
throw Exception("Unexpected message, not QMF2 event or query response.");
// decode as list
string content = msg.getMessage().getContent();
@@ -264,13 +435,9 @@ void BrokerReplicator::route(Deliverable& msg) {
QPID_LOG(trace, "Broker replicator event: " << map);
Variant::Map& schema = map[SCHEMA_ID].asMap();
Variant::Map& values = map[VALUES].asMap();
- if (match<EventQueueDeclare>(schema)) doEventQueueDeclare(values);
- else if (match<EventQueueDelete>(schema)) doEventQueueDelete(values);
- else if (match<EventExchangeDeclare>(schema)) doEventExchangeDeclare(values);
- else if (match<EventExchangeDelete>(schema)) doEventExchangeDelete(values);
- else if (match<EventBind>(schema)) doEventBind(values);
- else if (match<EventUnbind>(schema)) doEventUnbind(values);
- else if (match<EventMembersUpdate>(schema)) doEventMembersUpdate(values);
+ EventKey key(schema[PACKAGE_NAME], schema[CLASS_NAME]);
+ EventDispatchMap::iterator j = dispatch.find(key);
+ if (j != dispatch.end()) (this->*(j->second))(values);
}
} else if (msg.getMessage().getPropertyAsString(QMF_OPCODE) == QUERY_RESPONSE) {
for (Variant::List::iterator i = list.begin(); i != list.end(); ++i) {
@@ -285,15 +452,21 @@ void BrokerReplicator::route(Deliverable& msg) {
else if (type == BINDING) doResponseBind(values);
else if (type == HA_BROKER) doResponseHaBroker(values);
}
- if (qpid::broker::amqp_0_10::MessageTransfer::isLastQMFResponse(msg.getMessage(), EXCHANGE)) {
- // We have received all of the exchange response.
+ if (MessageTransfer::isLastQMFResponse(msg.getMessage(), EXCHANGE)) {
+ QPID_LOG(debug, logPrefix << "All exchange responses received.")
+ exchangeTracker.reset(); // Clean up exchanges that no longer exist in the primary
alternates.clear();
}
+ if (MessageTransfer::isLastQMFResponse(msg.getMessage(), QUEUE)) {
+ QPID_LOG(debug, logPrefix << "All queue responses received.");
+ queueTracker.reset(); // Clean up queues that no longer exist in the primary
+ }
}
} catch (const std::exception& e) {
- QPID_LOG(critical, logPrefix << "Configuration failed: " << e.what()
- << ": while handling: " << list);
- haBroker.shutdown();
+;
+ haBroker.shutdown(
+ QPID_MSG(logPrefix << "Configuration replication failed: "
+ << e.what() << ": while handling: " << list));
throw;
}
}
@@ -301,31 +474,22 @@ void BrokerReplicator::route(Deliverable& msg) {
void BrokerReplicator::doEventQueueDeclare(Variant::Map& values) {
Variant::Map argsMap = asMapVoid(values[ARGS]);
- bool autoDel = values[AUTODEL].asBool();
- bool excl = values[EXCL].asBool();
- if (values[DISP] == CREATED && replicationTest.isReplicated(CONFIGURATION, argsMap, autoDel, excl)) {
+ if (values[DISP] == CREATED && replicationTest.getLevel(argsMap)) {
string name = values[QNAME].asString();
QueueSettings settings(values[DURABLE].asBool(), values[AUTODEL].asBool());
+ QPID_LOG(debug, logPrefix << "Queue declare event: " << name);
+ if (queueTracker.get()) queueTracker->event(name);
framing::FieldTable args;
qpid::amqp_0_10::translate(argsMap, args);
// If we already have a queue with this name, replace it.
// The queue was definitely created on the primary.
- if (broker.getQueues().find(name)) {
- QPID_LOG(warning, logPrefix << "Replacing exsiting queue: " << name);
- broker.getQueues().destroy(name);
- stopQueueReplicator(name);
+ if (queues.find(name)) {
+ QPID_LOG(warning, logPrefix << "Declare event, replacing exsiting queue: "
+ << name);
+ deleteQueue(name);
}
- settings.populate(args, settings.storeSettings);
- std::pair<boost::shared_ptr<Queue>, bool> result =
- broker.createQueue(
- name,
- settings,
- 0 /*i.e. no owner regardless of exclusivity on master*/,
- values[ALTEX].asString(),
- userId,
- remoteHost);
- assert(result.second); // Should be true since we destroyed existing queue above
- startQueueReplicator(result.first);
+ replicateQueue(name, values[DURABLE].asBool(), values[AUTODEL].asBool(), args,
+ values[ALTEX].asString());
}
}
@@ -333,7 +497,7 @@ boost::shared_ptr<QueueReplicator> BrokerReplicator::findQueueReplicator(
const std::string& qname)
{
string rname = QueueReplicator::replicatorName(qname);
- boost::shared_ptr<broker::Exchange> ex = broker.getExchanges().find(rname);
+ boost::shared_ptr<broker::Exchange> ex = exchanges.find(rname);
return boost::dynamic_pointer_cast<QueueReplicator>(ex);
}
@@ -341,79 +505,85 @@ void BrokerReplicator::doEventQueueDelete(Variant::Map& values) {
// The remote queue has already been deleted so replicator
// sessions may be closed by a "queue deleted" exception.
string name = values[QNAME].asString();
- boost::shared_ptr<Queue> queue = broker.getQueues().find(name);
- if (queue && replicationTest.replicateLevel(queue->getSettings().storeSettings)) {
+ boost::shared_ptr<Queue> queue = queues.find(name);
+ if (queue && replicationTest.getLevel(*queue)) {
QPID_LOG(debug, logPrefix << "Queue delete event: " << name);
- stopQueueReplicator(name);
- broker.deleteQueue(name, userId, remoteHost);
+ if (queueTracker.get()) queueTracker->event(name);
+ deleteQueue(name);
}
}
void BrokerReplicator::doEventExchangeDeclare(Variant::Map& values) {
Variant::Map argsMap(asMapVoid(values[ARGS]));
- if (!replicationTest.replicateLevel(argsMap)) return; // Not a replicated exchange.
- if (values[DISP] == CREATED && replicationTest.replicateLevel(argsMap)) {
+ if (values[DISP] == CREATED && replicationTest.getLevel(argsMap)) {
string name = values[EXNAME].asString();
QPID_LOG(debug, logPrefix << "Exchange declare event: " << name);
+ if (exchangeTracker.get()) exchangeTracker->event(name);
framing::FieldTable args;
qpid::amqp_0_10::translate(argsMap, args);
// If we already have a exchange with this name, replace it.
// The exchange was definitely created on the primary.
- if (broker.getExchanges().find(name)) {
- broker.getExchanges().destroy(name);
- QPID_LOG(warning, logPrefix << "Replaced exsiting exchange: " << name);
+ if (exchanges.find(name)) {
+ deleteExchange(name);
+ QPID_LOG(warning, logPrefix << "Declare event, replacing existing exchange: "
+ << name);
}
- boost::shared_ptr<Exchange> exchange =
- createExchange(name, values[EXTYPE].asString(), values[DURABLE].asBool(), args, values[ALTEX].asString());
- assert(exchange);
+ CreateExchangeResult result = createExchange(
+ name, values[EXTYPE].asString(), values[DURABLE].asBool(), args,
+ values[ALTEX].asString());
+ replicatedExchanges.insert(name);
+ assert(result.second);
}
}
void BrokerReplicator::doEventExchangeDelete(Variant::Map& values) {
string name = values[EXNAME].asString();
- boost::shared_ptr<Exchange> exchange = broker.getExchanges().find(name);
+ boost::shared_ptr<Exchange> exchange = exchanges.find(name);
if (!exchange) {
- QPID_LOG(warning, logPrefix << "Exchange delete event, does not exist: " << name);
- } else if (!replicationTest.replicateLevel(exchange->getArgs())) {
+ QPID_LOG(warning, logPrefix << "Exchange delete event, not found: " << name);
+ } else if (!replicationTest.getLevel(*exchange)) {
QPID_LOG(warning, logPrefix << "Exchange delete event, not replicated: " << name);
} else {
QPID_LOG(debug, logPrefix << "Exchange delete event:" << name);
- broker.deleteExchange(name, userId, remoteHost);
+ if (exchangeTracker.get()) exchangeTracker->event(name);
+ deleteExchange(name);
+ replicatedExchanges.erase(name);
}
}
void BrokerReplicator::doEventBind(Variant::Map& values) {
boost::shared_ptr<Exchange> exchange =
- broker.getExchanges().find(values[EXNAME].asString());
+ exchanges.find(values[EXNAME].asString());
boost::shared_ptr<Queue> queue =
- broker.getQueues().find(values[QNAME].asString());
- // We only replicate binds for a replicated queue to replicated
- // exchange that both exist locally.
- if (exchange && replicationTest.replicateLevel(exchange->getArgs()) &&
- queue && replicationTest.replicateLevel(queue->getSettings().storeSettings))
+ queues.find(values[QNAME].asString());
+ framing::FieldTable args;
+ qpid::amqp_0_10::translate(asMapVoid(values[ARGS]), args);
+ // We only replicate binds for a replicated queue to replicated exchange
+ // that both exist locally. Respect the replication level set in the
+ // bind arguments, but replicate by default.
+ if (exchange && replicationTest.getLevel(*exchange) &&
+ queue && replicationTest.getLevel(*queue) &&
+ ReplicationTest(ALL).getLevel(args))
{
- framing::FieldTable args;
- qpid::amqp_0_10::translate(asMapVoid(values[ARGS]), args);
string key = values[KEY].asString();
QPID_LOG(debug, logPrefix << "Bind event: exchange=" << exchange->getName()
<< " queue=" << queue->getName()
- << " key=" << key);
+ << " key=" << key
+ << " args=" << args);
exchange->bind(queue, key, &args, 0);
}
}
void BrokerReplicator::doEventUnbind(Variant::Map& values) {
boost::shared_ptr<Exchange> exchange =
- broker.getExchanges().find(values[EXNAME].asString());
+ exchanges.find(values[EXNAME].asString());
boost::shared_ptr<Queue> queue =
- broker.getQueues().find(values[QNAME].asString());
+ queues.find(values[QNAME].asString());
// We only replicate unbinds for a replicated queue to replicated
// exchange that both exist locally.
- if (exchange && replicationTest.replicateLevel(exchange->getArgs()) &&
- queue && replicationTest.replicateLevel(queue->getSettings().storeSettings))
+ if (exchange && replicationTest.getLevel(*exchange) &&
+ queue && replicationTest.getLevel(*queue))
{
- framing::FieldTable args;
- qpid::amqp_0_10::translate(asMapVoid(values[ARGS]), args);
string key = values[KEY].asString();
QPID_LOG(debug, logPrefix << "Unbind event: exchange=" << exchange->getName()
<< " queue=" << queue->getName()
@@ -424,7 +594,17 @@ void BrokerReplicator::doEventUnbind(Variant::Map& values) {
void BrokerReplicator::doEventMembersUpdate(Variant::Map& values) {
Variant::List members = values[MEMBERS].asList();
- haBroker.setMembership(members);
+ setMembership(members);
+}
+
+void BrokerReplicator::doEventSubscribe(Variant::Map& values) {
+ // Ignore queue replicator subscriptions.
+ if (QueueReplicator::isReplicatorName(values[DEST].asString())) return;
+ boost::shared_ptr<QueueReplicator> qr = findQueueReplicator(values[QNAME]);
+ if (qr) {
+ qr->setSubscribed();
+ QPID_LOG(debug, logPrefix << "Subscribe event: " << values[QNAME]);
+ }
}
namespace {
@@ -441,40 +621,68 @@ string getAltExchange(const types::Variant& var) {
}
else return string();
}
+
+Variant getHaUuid(const Variant::Map& map) {
+ Variant::Map::const_iterator i = map.find(QPID_HA_UUID);
+ return i == map.end() ? Variant() : i->second;
}
+} // namespace
+
+
void BrokerReplicator::doResponseQueue(Variant::Map& values) {
Variant::Map argsMap(asMapVoid(values[ARGUMENTS]));
- if (!replicationTest.isReplicated(
- CONFIGURATION,
- values[ARGUMENTS].asMap(),
- values[AUTODELETE].asBool(),
- values[EXCLUSIVE].asBool()))
- return;
+ if (!replicationTest.getLevel(argsMap)) return;
string name(values[NAME].asString());
+ if (!queueTracker.get())
+ throw Exception(QPID_MSG("Unexpected queue response: " << values));
+ if (!queueTracker->response(name)) return; // Response is out-of-date
QPID_LOG(debug, logPrefix << "Queue response: " << name);
+ // If we see a queue with the same name as one we have, but not the same UUID,
+ // then replace the one we have.
+ boost::shared_ptr<Queue> queue = queues.find(name);
+ if (queue && getHaUuid(queue->getSettings().original) != getHaUuid(argsMap)) {
+ QPID_LOG(warning, logPrefix << "UUID mismatch, replacing queue: "
+ << name);
+ deleteQueue(name);
+ }
framing::FieldTable args;
qpid::amqp_0_10::translate(argsMap, args);
- boost::shared_ptr<Queue> queue =
- createQueue(name, values[DURABLE].asBool(), values[AUTODELETE].asBool(), args,
- getAltExchange(values[ALTEXCHANGE]));
- // It is normal for the queue to already exist if we are failing over.
- if (queue) startQueueReplicator(queue);
- else QPID_LOG(debug, logPrefix << "Queue already replicated: " << name);
+ boost::shared_ptr<QueueReplicator> qr = replicateQueue(
+ name, values[DURABLE].asBool(), values[AUTODELETE].asBool(), args,
+ getAltExchange(values[ALTEXCHANGE]));
+ if (qr) {
+ Variant::Map::const_iterator i = values.find(CONSUMER_COUNT);
+ if (i != values.end() && isIntegerType(i->second.getType())) {
+ if (i->second.asInt64()) qr->setSubscribed();
+ }
+ }
}
void BrokerReplicator::doResponseExchange(Variant::Map& values) {
Variant::Map argsMap(asMapVoid(values[ARGUMENTS]));
- if (!replicationTest.replicateLevel(argsMap)) return;
+ if (!replicationTest.getLevel(argsMap)) return;
string name = values[NAME].asString();
+ if (!exchangeTracker.get())
+ throw Exception(QPID_MSG("Unexpected exchange response: " << values));
+ if (!exchangeTracker->response(name)) return; // Response is out of date.
QPID_LOG(debug, logPrefix << "Exchange response: " << name);
framing::FieldTable args;
qpid::amqp_0_10::translate(argsMap, args);
- boost::shared_ptr<Exchange> exchange = createExchange(
+ // If we see an exchange with the same name as one we have, but not the same UUID,
+ // then replace the one we have.
+ boost::shared_ptr<Exchange> exchange = exchanges.find(name);
+ if (exchange &&
+ exchange->getArgs().getAsString(QPID_HA_UUID) != args.getAsString(QPID_HA_UUID))
+ {
+ QPID_LOG(warning, logPrefix << "UUID mismatch, replacing exchange: "
+ << name);
+ deleteExchange(name);
+ }
+ CreateExchangeResult result = createExchange(
name, values[TYPE].asString(), values[DURABLE].asBool(), args,
getAltExchange(values[ALTEXCHANGE]));
- // It is normal for the exchange to already exist if we are failing over.
- QPID_LOG_IF(debug, !exchange, logPrefix << "Exchange already replicated: " << name);
+ replicatedExchanges.insert(name);
}
namespace {
@@ -501,19 +709,25 @@ const std::string QUEUE_REF("queueRef");
void BrokerReplicator::doResponseBind(Variant::Map& values) {
std::string exName = getRefName(EXCHANGE_REF_PREFIX, values[EXCHANGE_REF]);
std::string qName = getRefName(QUEUE_REF_PREFIX, values[QUEUE_REF]);
- boost::shared_ptr<Exchange> exchange = broker.getExchanges().find(exName);
- boost::shared_ptr<Queue> queue = broker.getQueues().find(qName);
+ boost::shared_ptr<Exchange> exchange = exchanges.find(exName);
+ boost::shared_ptr<Queue> queue = queues.find(qName);
- // Automatically replicate binding if queue and exchange exist and are replicated
- if (exchange && replicationTest.replicateLevel(exchange->getArgs()) &&
- queue && replicationTest.replicateLevel(queue->getSettings().storeSettings))
+ framing::FieldTable args;
+ qpid::amqp_0_10::translate(asMapVoid(values[ARGUMENTS]), args);
+
+ // Automatically replicate binding if queue and exchange exist and are replicated.
+ // Respect replicate setting in binding args but default to replicated.
+ if (exchange && replicationTest.getLevel(*exchange) &&
+ queue && replicationTest.getLevel(*queue) &&
+ ReplicationTest(ALL).getLevel(args))
{
- string key = values[KEY].asString();
+ string key = values[BINDING_KEY].asString();
QPID_LOG(debug, logPrefix << "Bind response: exchange:" << exName
<< " queue:" << qName
- << " key:" << key);
- framing::FieldTable args;
- qpid::amqp_0_10::translate(asMapVoid(values[ARGUMENTS]), args);
+ << " key:" << key
+ << " args:" << args);
+// framing::FieldTable args;
+// qpid::amqp_0_10::translate(asMapVoid(values[ARGUMENTS]), args);
exchange->bind(queue, key, &args, 0);
}
}
@@ -527,42 +741,65 @@ void BrokerReplicator::doResponseHaBroker(Variant::Map& values) {
try {
QPID_LOG(trace, logPrefix << "HA Broker response: " << values);
ReplicateLevel mine = haBroker.getSettings().replicateDefault.get();
- ReplicateLevel primary = replicationTest.replicateLevel(
- values[REPLICATE_DEFAULT].asString());
+ ReplicateLevel primary = replicationTest.getLevel(values[REPLICATE_DEFAULT].asString());
if (mine != primary)
throw Exception(QPID_MSG("Replicate default on backup (" << mine
<< ") does not match primary (" << primary << ")"));
- haBroker.setMembership(values[MEMBERS].asList());
+ setMembership(values[MEMBERS].asList());
} catch (const std::exception& e) {
- QPID_LOG(critical, logPrefix << "Invalid HA Broker response: " << e.what()
- << ": " << values);
- haBroker.shutdown();
+ haBroker.shutdown(
+ QPID_MSG(logPrefix << "Invalid HA Broker response: " << e.what()
+ << ": " << values));
+
throw;
}
}
-void BrokerReplicator::startQueueReplicator(const boost::shared_ptr<Queue>& queue)
+boost::shared_ptr<QueueReplicator> BrokerReplicator::startQueueReplicator(
+ const boost::shared_ptr<Queue>& queue)
{
- if (replicationTest.replicateLevel(queue->getSettings().storeSettings) == ALL) {
+ if (replicationTest.getLevel(*queue) == ALL) {
boost::shared_ptr<QueueReplicator> qr(
new QueueReplicator(haBroker, queue, link));
- if (!broker.getExchanges().registerExchange(qr))
+ if (!exchanges.registerExchange(qr))
throw Exception(QPID_MSG("Duplicate queue replicator " << qr->getName()));
qr->activate();
+ return qr;
}
+ return boost::shared_ptr<QueueReplicator>();
}
-void BrokerReplicator::stopQueueReplicator(const std::string& name) {
- boost::shared_ptr<QueueReplicator> qr = findQueueReplicator(name);
- if (qr) {
- qr->deactivate();
- // QueueReplicator's bridge is now queued for destruction but may not
- // actually be destroyed.
- broker.getExchanges().destroy(qr->getName());
+void BrokerReplicator::deleteQueue(const std::string& name, bool purge) {
+ Queue::shared_ptr queue = queues.find(name);
+ if (queue) {
+ // Purge before deleting to ensure that we don't reroute any
+ // messages. Any reroutes will be done at the primary and
+ // replicated as normal.
+ if (purge) queue->purge(0, boost::shared_ptr<Exchange>());
+ broker.deleteQueue(name, userId, remoteHost);
+ QPID_LOG(debug, logPrefix << "Queue deleted: " << name);
+ }
+}
+
+void BrokerReplicator::deleteExchange(const std::string& name) {
+ try {
+ boost::shared_ptr<broker::Exchange> exchange = exchanges.find(name);
+ if (!exchange) {
+ QPID_LOG(warning, logPrefix << "Cannot delete exchange, not found: " << name);
+ return;
+ }
+ if (exchange->inUseAsAlternate()) {
+ QPID_LOG(warning, "Cannot delete exchange, in use as alternate: " << name);
+ return;
+ }
+ broker.deleteExchange(name, userId, remoteHost);
+ QPID_LOG(debug, logPrefix << "Exchange deleted: " << name);
+ } catch (const framing::NotFoundException&) {
+ QPID_LOG(debug, logPrefix << "Exchange not found for deletion: " << name);
}
}
-boost::shared_ptr<Queue> BrokerReplicator::createQueue(
+boost::shared_ptr<QueueReplicator> BrokerReplicator::replicateQueue(
const std::string& name,
bool durable,
bool autodelete,
@@ -571,7 +808,7 @@ boost::shared_ptr<Queue> BrokerReplicator::createQueue(
{
QueueSettings settings(durable, autodelete);
settings.populate(arguments, settings.storeSettings);
- std::pair<boost::shared_ptr<Queue>, bool> result =
+ CreateQueueResult result =
broker.createQueue(
name,
settings,
@@ -579,24 +816,23 @@ boost::shared_ptr<Queue> BrokerReplicator::createQueue(
string(), // Set alternate exchange below
userId,
remoteHost);
- if (result.second) {
- if (!alternateExchange.empty()) {
- alternates.setAlternate(
- alternateExchange, boost::bind(&Queue::setAlternateExchange, result.first, _1));
- }
- return result.first;
+ boost::shared_ptr<QueueReplicator> qr;
+ if (!findQueueReplicator(name)) qr = startQueueReplicator(result.first);
+ if (result.second && !alternateExchange.empty()) {
+ alternates.setAlternate(
+ alternateExchange, boost::bind(&Queue::setAlternateExchange, result.first, _1));
}
- else return boost::shared_ptr<Queue>();
+ return qr;
}
-boost::shared_ptr<Exchange> BrokerReplicator::createExchange(
+BrokerReplicator::CreateExchangeResult BrokerReplicator::createExchange(
const std::string& name,
const std::string& type,
bool durable,
const qpid::framing::FieldTable& args,
const std::string& alternateExchange)
{
- std::pair<boost::shared_ptr<Exchange>, bool> result =
+ CreateExchangeResult result =
broker.createExchange(
name,
type,
@@ -605,15 +841,12 @@ boost::shared_ptr<Exchange> BrokerReplicator::createExchange(
args,
userId,
remoteHost);
- if (result.second) {
- alternates.addExchange(result.first);
- if (!alternateExchange.empty()) {
- alternates.setAlternate(
- alternateExchange, boost::bind(&Exchange::setAlternate, result.first, _1));
- }
- return result.first;
+ alternates.addExchange(result.first);
+ if (!alternateExchange.empty()) {
+ alternates.setAlternate(
+ alternateExchange, boost::bind(&Exchange::setAlternate, result.first, _1));
}
- else return boost::shared_ptr<Exchange>();
+ return result;
}
bool BrokerReplicator::bind(boost::shared_ptr<Queue>, const string&, const framing::FieldTable*, qpid::broker::AsyncStore* const) { return false; }
@@ -626,4 +859,61 @@ void BrokerReplicator::write(char* /*target*/) {}
string BrokerReplicator::getType() const { return QPID_CONFIGURATION_REPLICATOR; }
+void BrokerReplicator::autoDeleteCheck(boost::shared_ptr<Exchange> ex) {
+ boost::shared_ptr<QueueReplicator> qr(boost::dynamic_pointer_cast<QueueReplicator>(ex));
+ if (!qr) return;
+ assert(qr);
+ if (qr->getQueue()->isAutoDelete() && qr->isSubscribed()) {
+ if (qr->getQueue()->getSettings().autoDeleteDelay) {
+ // Start the auto-delete timer
+ Queue::tryAutoDelete(broker, qr->getQueue(), remoteHost, userId);
+ }
+ else {
+ // Delete immediately. Don't purge, the primary is gone so we need
+ // to reroute the deleted messages.
+ deleteQueue(qr->getQueue()->getName(), false);
+ }
+ }
+}
+
+// Callback function for accumulating exchange candidates
+namespace {
+ void exchangeAccumulatorCallback(vector<boost::shared_ptr<Exchange> >& c, const Exchange::shared_ptr& i) {
+ c.push_back(i);
+ }
+}
+
+void BrokerReplicator::disconnected() {
+ QPID_LOG(info, logPrefix << "Disconnected from " << primary);
+ connection = 0;
+ // Clean up auto-delete queues
+ vector<boost::shared_ptr<Exchange> > collect;
+ // Make a copy so we can work outside the ExchangeRegistry lock
+ exchanges.eachExchange(
+ boost::bind(&exchangeAccumulatorCallback, boost::ref(collect), _1));
+ for_each(collect.begin(), collect.end(),
+ boost::bind(&BrokerReplicator::autoDeleteCheck, this, _1));
+}
+
+void BrokerReplicator::setMembership(const Variant::List& brokers) {
+ Membership& membership(haBroker.getMembership());
+ membership.assign(brokers);
+ // Check if the primary has signalled a change in my status:
+ // from CATCHUP to READY when we are caught up.
+ // from READY TO CATCHUP if we are timed out during fail-over.
+ BrokerInfo info;
+ if (membership.get(membership.getSelf(), info)) {
+ BrokerStatus oldStatus = haBroker.getStatus();
+ BrokerStatus newStatus = info.getStatus();
+ if (oldStatus == CATCHUP && newStatus == READY) {
+ QPID_LOG(info, logPrefix << logPrefix << "Caught-up and ready");
+ haBroker.getMembership().setStatus(READY);
+ }
+ else if (oldStatus == READY && newStatus == CATCHUP) {
+ QPID_LOG(info, logPrefix << logPrefix << "No longer ready, catching up");
+ haBroker.getMembership().setStatus(CATCHUP);
+ }
+ }
+}
+
}} // namespace broker
diff --git a/cpp/src/qpid/ha/BrokerReplicator.h b/cpp/src/qpid/ha/BrokerReplicator.h
index f6983e8719..a42d607263 100644
--- a/cpp/src/qpid/ha/BrokerReplicator.h
+++ b/cpp/src/qpid/ha/BrokerReplicator.h
@@ -31,6 +31,7 @@
#include "qpid/management/ManagementObject.h"
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
+#include <set>
namespace qpid {
@@ -40,6 +41,9 @@ class Broker;
class Link;
class Bridge;
class SessionHandler;
+class Connection;
+class QueueRegistry;
+class ExchangeRegistry;
}
namespace framing {
@@ -58,7 +62,9 @@ class QueueReplicator;
* exchanges and bindings to replicate the primary.
* It also creates QueueReplicators for newly replicated queues.
*
- * THREAD UNSAFE: Only called in Link connection thread, no need for locking.
+ * THREAD UNSAFE:
+ * All members except shutdown are only called in the Link's connection thread context.
+ * shutdown() does not use any mutable state.
*
*/
class BrokerReplicator : public broker::Exchange,
@@ -76,6 +82,7 @@ class BrokerReplicator : public broker::Exchange,
bool unbind(boost::shared_ptr<broker::Queue>, const std::string&, const framing::FieldTable*, qpid::broker::AsyncStore* const store);
void route(broker::Deliverable&);
bool isBound(boost::shared_ptr<broker::Queue>, const std::string* const, const framing::FieldTable* const);
+ void shutdown();
// DataSource interface - used to write persistence data to async store
uint64_t getSize();
@@ -83,8 +90,20 @@ class BrokerReplicator : public broker::Exchange,
private:
typedef boost::shared_ptr<QueueReplicator> QueueReplicatorPtr;
+ typedef std::pair<boost::shared_ptr<broker::Queue>, bool> CreateQueueResult;
+ typedef std::pair<boost::shared_ptr<broker::Exchange>, bool> CreateExchangeResult;
- void initializeBridge(broker::Bridge&, broker::SessionHandler&);
+ typedef std::pair<std::string,std::string> EventKey;
+ typedef void (BrokerReplicator::*DispatchFunction)(types::Variant::Map&);
+ typedef std::map<EventKey, DispatchFunction> EventDispatchMap;
+
+ typedef std::map<std::string, QueueReplicatorPtr> QueueReplicatorMap;
+
+ class UpdateTracker;
+ class ErrorListener;
+ class ConnectionObserver;
+
+ void connected(broker::Bridge&, broker::SessionHandler&);
void doEventQueueDeclare(types::Variant::Map& values);
void doEventQueueDelete(types::Variant::Map& values);
@@ -93,6 +112,7 @@ class BrokerReplicator : public broker::Exchange,
void doEventBind(types::Variant::Map&);
void doEventUnbind(types::Variant::Map&);
void doEventMembersUpdate(types::Variant::Map&);
+ void doEventSubscribe(types::Variant::Map&);
void doResponseQueue(types::Variant::Map& values);
void doResponseExchange(types::Variant::Map& values);
@@ -100,32 +120,50 @@ class BrokerReplicator : public broker::Exchange,
void doResponseHaBroker(types::Variant::Map& values);
QueueReplicatorPtr findQueueReplicator(const std::string& qname);
- void startQueueReplicator(const boost::shared_ptr<broker::Queue>&);
- void stopQueueReplicator(const std::string& name);
+ QueueReplicatorPtr startQueueReplicator(const boost::shared_ptr<broker::Queue>&);
- boost::shared_ptr<broker::Queue> createQueue(
+ QueueReplicatorPtr replicateQueue(
const std::string& name,
bool durable,
bool autodelete,
const qpid::framing::FieldTable& arguments,
const std::string& alternateExchange);
- boost::shared_ptr<broker::Exchange> createExchange(
+ CreateExchangeResult createExchange(
const std::string& name,
const std::string& type,
bool durable,
const qpid::framing::FieldTable& args,
const std::string& alternateExchange);
+ bool deactivate(boost::shared_ptr<broker::Exchange> ex, bool destroy);
+ void deleteQueue(const std::string& name, bool purge=true);
+ void deleteExchange(const std::string& name);
+
+ void autoDeleteCheck(boost::shared_ptr<broker::Exchange>);
+
+ void disconnected();
+
+ void setMembership(const types::Variant::List&); // Set membership from list.
+
std::string logPrefix;
- std::string userId, remoteHost;
ReplicationTest replicationTest;
+ std::string userId, remoteHost;
HaBroker& haBroker;
broker::Broker& broker;
+ broker::ExchangeRegistry& exchanges;
+ broker::QueueRegistry& queues;
boost::shared_ptr<broker::Link> link;
bool initialized;
AlternateExchangeSetter alternates;
qpid::Address primary;
+ typedef std::set<std::string> StringSet;
+ StringSet replicatedExchanges; // exchanges that have been replicated.
+ broker::Connection* connection;
+ EventDispatchMap dispatch;
+ std::auto_ptr<UpdateTracker> queueTracker;
+ std::auto_ptr<UpdateTracker> exchangeTracker;
+ boost::shared_ptr<ConnectionObserver> connectionObserver;
};
}} // namespace qpid::broker
diff --git a/cpp/src/qpid/ha/ConnectionObserver.cpp b/cpp/src/qpid/ha/ConnectionObserver.cpp
index 81ba3e4301..775222efd3 100644
--- a/cpp/src/qpid/ha/ConnectionObserver.cpp
+++ b/cpp/src/qpid/ha/ConnectionObserver.cpp
@@ -30,7 +30,7 @@ namespace qpid {
namespace ha {
ConnectionObserver::ConnectionObserver(HaBroker& hb, const types::Uuid& uuid)
- : haBroker(hb), logPrefix("Connections: "), self(uuid) {}
+ : haBroker(hb), logPrefix("Backup: "), self(uuid) {}
bool ConnectionObserver::getBrokerInfo(const broker::Connection& connection, BrokerInfo& info) {
framing::FieldTable ft;
@@ -41,9 +41,11 @@ bool ConnectionObserver::getBrokerInfo(const broker::Connection& connection, Bro
return false;
}
-void ConnectionObserver::setObserver(const ObserverPtr& o){
+void ConnectionObserver::setObserver(const ObserverPtr& o, const std::string& newlogPrefix)
+{
sys::Mutex::ScopedLock l(lock);
observer = o;
+ logPrefix = newlogPrefix;
}
ConnectionObserver::ObserverPtr ConnectionObserver::getObserver() {
diff --git a/cpp/src/qpid/ha/ConnectionObserver.h b/cpp/src/qpid/ha/ConnectionObserver.h
index e3a6d1154a..5374660dbe 100644
--- a/cpp/src/qpid/ha/ConnectionObserver.h
+++ b/cpp/src/qpid/ha/ConnectionObserver.h
@@ -55,7 +55,7 @@ class ConnectionObserver : public broker::ConnectionObserver
ConnectionObserver(HaBroker& haBroker, const types::Uuid& self);
- void setObserver(const ObserverPtr&);
+ void setObserver(const ObserverPtr&, const std::string& logPrefix);
ObserverPtr getObserver();
void opened(broker::Connection& connection);
diff --git a/cpp/src/qpid/ha/HaBroker.cpp b/cpp/src/qpid/ha/HaBroker.cpp
index ffbcb684bc..590db7efa5 100644
--- a/cpp/src/qpid/ha/HaBroker.cpp
+++ b/cpp/src/qpid/ha/HaBroker.cpp
@@ -26,6 +26,7 @@
#include "QueueReplicator.h"
#include "ReplicatingSubscription.h"
#include "Settings.h"
+#include "StandAlone.h"
#include "qpid/amqp_0_10/Codecs.h"
#include "qpid/Exception.h"
#include "qpid/broker/Broker.h"
@@ -41,7 +42,6 @@
#include "qmf/org/apache/qpid/ha/ArgsHaBrokerReplicate.h"
#include "qmf/org/apache/qpid/ha/ArgsHaBrokerSetBrokersUrl.h"
#include "qmf/org/apache/qpid/ha/ArgsHaBrokerSetPublicUrl.h"
-#include "qmf/org/apache/qpid/ha/EventMembersUpdate.h"
#include "qpid/log/Statement.h"
#include <boost/shared_ptr.hpp>
@@ -54,134 +54,100 @@ using namespace std;
using types::Variant;
using types::Uuid;
using sys::Mutex;
+using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
// Called in Plugin::earlyInitialize
HaBroker::HaBroker(broker::Broker& b, const Settings& s)
- : logPrefix("Broker: "),
- broker(b),
- systemId(broker.getSystem()->getSystemId().data()),
+ : systemId(b.getSystem()->getSystemId().data()),
settings(s),
+ broker(b),
observer(new ConnectionObserver(*this, systemId)),
- mgmtObject(0),
- status(STANDALONE),
- membership(systemId),
- replicationTest(s.replicateDefault.get())
+ role(new StandAlone),
+ membership(BrokerInfo(systemId, STANDALONE), *this)
{
// If we are joining a cluster we must start excluding clients now,
// otherwise there's a window for a client to connect before we get to
// initialize()
if (settings.cluster) {
- QPID_LOG(debug, logPrefix << "Rejecting client connections.");
- observer->setObserver(boost::shared_ptr<broker::ConnectionObserver>(
- new BackupConnectionExcluder));
+ QPID_LOG(debug, "Broker startup, rejecting client connections.");
+ shared_ptr<broker::ConnectionObserver> excluder(new BackupConnectionExcluder);
+ observer->setObserver(excluder, "Backup: ");
broker.getConnectionObservers().add(observer);
}
}
+namespace {
+const std::string NONE("none");
+bool isNone(const std::string& x) { return x.empty() || x == NONE; }
+}
+
// Called in Plugin::initialize
void HaBroker::initialize() {
-
// FIXME aconway 2012-07-19: assumes there's a TCP transport with a meaningful port.
- brokerInfo = BrokerInfo(
- broker.getSystem()->getNodeName(),
- broker.getPort(broker::Broker::TCP_TRANSPORT),
- systemId);
-
- QPID_LOG(notice, logPrefix << "Initializing: " << brokerInfo);
+ membership.add(
+ BrokerInfo(
+ membership.getSelf(),
+ settings.cluster ? JOINING : membership.getStatus(),
+ broker.getSystem()->getNodeName(),
+ broker.getPort(broker::Broker::TCP_TRANSPORT)
+ )
+ );
+ QPID_LOG(notice, "Initializing: " << membership.getInfo());
// Set up the management object.
ManagementAgent* ma = broker.getManagementAgent();
if (settings.cluster && !ma)
throw Exception("Cannot start HA: management is disabled");
_qmf::Package packageInit(ma);
- mgmtObject = new _qmf::HaBroker(ma, this, "ha-broker");
+ mgmtObject = _qmf::HaBroker::shared_ptr(new _qmf::HaBroker(ma, this, "ha-broker"));
mgmtObject->set_replicateDefault(settings.replicateDefault.str());
mgmtObject->set_systemId(systemId);
ma->addObject(mgmtObject);
+ membership.setMgmtObject(mgmtObject);
// Register a factory for replicating subscriptions.
broker.getConsumerFactories().add(
- boost::shared_ptr<ReplicatingSubscription::Factory>(
+ shared_ptr<ReplicatingSubscription::Factory>(
new ReplicatingSubscription::Factory()));
// If we are in a cluster, start as backup in joining state.
if (settings.cluster) {
- status = JOINING;
- backup.reset(new Backup(*this, settings));
+ assert(membership.getStatus() == JOINING);
+ role.reset(new Backup(*this, settings));
broker.getKnownBrokers = boost::bind(&HaBroker::getKnownBrokers, this);
+ if (!isNone(settings.publicUrl)) setPublicUrl(Url(settings.publicUrl));
+ if (!isNone(settings.brokerUrl)) setBrokerUrl(Url(settings.brokerUrl));
}
-
- if (!settings.clientUrl.empty()) setClientUrl(Url(settings.clientUrl));
- if (!settings.brokerUrl.empty()) setBrokerUrl(Url(settings.brokerUrl));
-
-
- // NOTE: lock is not needed in a constructor, but create one
- // to pass to functions that have a ScopedLock parameter.
- Mutex::ScopedLock l(lock);
- statusChanged(l);
}
HaBroker::~HaBroker() {
- QPID_LOG(notice, logPrefix << "Shut down: " << brokerInfo);
+ QPID_LOG(notice, role->getLogPrefix() << "Shut down");
broker.getConnectionObservers().remove(observer);
}
-void HaBroker::recover() {
- auto_ptr<Backup> b;
- {
- Mutex::ScopedLock l(lock);
- // No longer replicating, close link. Note: link must be closed before we
- // setStatus(RECOVERING) as that will remove our broker info from the
- // outgoing link properties so we won't recognize self-connects.
- b = backup;
- }
- b.reset(); // Call destructor outside of lock.
- BrokerInfo::Set backups;
- {
- Mutex::ScopedLock l(lock);
- setStatus(RECOVERING, l);
- backups = membership.otherBackups();
- membership.reset(brokerInfo);
- // Drop the lock, new Primary may call back on activate.
- }
- // Outside of lock, may call back on activate()
- primary.reset(new Primary(*this, backups)); // Starts primary-ready check.
-}
-
-// Called back from Primary active check.
-void HaBroker::activate() { setStatus(ACTIVE); }
-
Manageable::status_t HaBroker::ManagementMethod (uint32_t methodId, Args& args, string&) {
switch (methodId) {
case _qmf::HaBroker::METHOD_PROMOTE: {
- switch (getStatus()) {
- case JOINING: recover(); break;
- case CATCHUP:
- QPID_LOG(error, logPrefix << "Still catching up, cannot be promoted.");
- throw Exception("Still catching up, cannot be promoted.");
- break;
- case READY: recover(); break;
- case RECOVERING: break;
- case ACTIVE: break;
- case STANDALONE: break;
- }
- break;
+ Role* r = role->promote();
+ if (r) role.reset(r);
+ break;
}
case _qmf::HaBroker::METHOD_SETBROKERSURL: {
setBrokerUrl(Url(dynamic_cast<_qmf::ArgsHaBrokerSetBrokersUrl&>(args).i_url));
break;
}
case _qmf::HaBroker::METHOD_SETPUBLICURL: {
- setClientUrl(Url(dynamic_cast<_qmf::ArgsHaBrokerSetPublicUrl&>(args).i_url));
+ setPublicUrl(Url(dynamic_cast<_qmf::ArgsHaBrokerSetPublicUrl&>(args).i_url));
break;
}
case _qmf::HaBroker::METHOD_REPLICATE: {
_qmf::ArgsHaBrokerReplicate& bq_args =
dynamic_cast<_qmf::ArgsHaBrokerReplicate&>(args);
- QPID_LOG(debug, logPrefix << "Replicate individual queue "
+ QPID_LOG(debug, role->getLogPrefix() << "Replicate individual queue "
<< bq_args.i_queue << " from " << bq_args.i_broker);
- boost::shared_ptr<broker::Queue> queue = broker.getQueues().get(bq_args.i_queue);
+ shared_ptr<broker::Queue> queue = broker.getQueues().get(bq_args.i_queue);
Url url(bq_args.i_broker);
string protocol = url[0].protocol.empty() ? "tcp" : url[0].protocol;
Uuid uuid(true);
@@ -191,10 +157,10 @@ Manageable::status_t HaBroker::ManagementMethod (uint32_t methodId, Args& args,
false, // durable
settings.mechanism, settings.username, settings.password,
false); // no amq.failover - don't want to use client URL.
- boost::shared_ptr<broker::Link> link = result.first;
+ shared_ptr<broker::Link> link = result.first;
link->setUrl(url);
// Create a queue replicator
- boost::shared_ptr<QueueReplicator> qr(
+ shared_ptr<QueueReplicator> qr(
new QueueReplicator(*this, queue, link));
qr->activate();
broker.getExchanges().registerExchange(qr);
@@ -207,31 +173,23 @@ Manageable::status_t HaBroker::ManagementMethod (uint32_t methodId, Args& args,
return Manageable::STATUS_OK;
}
-void HaBroker::setClientUrl(const Url& url) {
+void HaBroker::setPublicUrl(const Url& url) {
Mutex::ScopedLock l(lock);
- if (url.empty()) throw Exception("Invalid empty URL for HA client failover");
- clientUrl = url;
- updateClientUrl(l);
-}
-
-void HaBroker::updateClientUrl(Mutex::ScopedLock&) {
- Url url = clientUrl.empty() ? brokerUrl : clientUrl;
- if (url.empty()) throw Url::Invalid("HA client URL is empty");
+ publicUrl = url;
mgmtObject->set_publicUrl(url.str());
knownBrokers.clear();
knownBrokers.push_back(url);
- QPID_LOG(debug, logPrefix << "Setting client URL to: " << url);
+ QPID_LOG(debug, role->getLogPrefix() << "Setting public URL to: " << url);
}
void HaBroker::setBrokerUrl(const Url& url) {
- Mutex::ScopedLock l(lock);
- if (url.empty()) throw Url::Invalid("HA broker URL is empty");
- brokerUrl = url;
- mgmtObject->set_brokersUrl(brokerUrl.str());
- QPID_LOG(info, logPrefix << "Broker URL set to: " << url);
- if (backup.get()) backup->setBrokerUrl(brokerUrl);
- // Updating broker URL also updates defaulted client URL:
- if (clientUrl.empty()) updateClientUrl(l);
+ {
+ Mutex::ScopedLock l(lock);
+ brokerUrl = url;
+ mgmtObject->set_brokersUrl(brokerUrl.str());
+ QPID_LOG(info, role->getLogPrefix() << "Brokers URL set to: " << url);
+ }
+ role->setBrokerUrl(url); // Oustside lock
}
std::vector<Url> HaBroker::getKnownBrokers() const {
@@ -239,116 +197,14 @@ std::vector<Url> HaBroker::getKnownBrokers() const {
return knownBrokers;
}
-void HaBroker::shutdown() {
- QPID_LOG(critical, logPrefix << "Critical error, shutting down.");
+void HaBroker::shutdown(const std::string& message) {
+ QPID_LOG(critical, message);
broker.shutdown();
+ throw Exception(message);
}
BrokerStatus HaBroker::getStatus() const {
- Mutex::ScopedLock l(lock);
- return status;
-}
-
-void HaBroker::setStatus(BrokerStatus newStatus) {
- Mutex::ScopedLock l(lock);
- setStatus(newStatus, l);
-}
-
-namespace {
-bool checkTransition(BrokerStatus from, BrokerStatus to) {
- // Legal state transitions. Initial state is JOINING, ACTIVE is terminal.
- static const BrokerStatus TRANSITIONS[][2] = {
- { JOINING, CATCHUP }, // Connected to primary
- { JOINING, RECOVERING }, // Chosen as initial primary.
- { CATCHUP, READY }, // Caught up all queues, ready to take over.
- { READY, RECOVERING }, // Chosen as new primary
- { READY, CATCHUP }, // Timed out failing over, demoted to catch-up.
- { RECOVERING, ACTIVE } // All expected backups are ready
- };
- static const size_t N = sizeof(TRANSITIONS)/sizeof(TRANSITIONS[0]);
- for (size_t i = 0; i < N; ++i) {
- if (TRANSITIONS[i][0] == from && TRANSITIONS[i][1] == to)
- return true;
- }
- return false;
-}
-} // namespace
-
-void HaBroker::setStatus(BrokerStatus newStatus, Mutex::ScopedLock& l) {
- QPID_LOG(info, logPrefix << "Status change: "
- << printable(status) << " -> " << printable(newStatus));
- bool legal = checkTransition(status, newStatus);
- assert(legal);
- if (!legal) {
- QPID_LOG(critical, logPrefix << "Illegal state transition: "
- << printable(status) << " -> " << printable(newStatus));
- shutdown();
- }
- status = newStatus;
- statusChanged(l);
-}
-
-void HaBroker::statusChanged(Mutex::ScopedLock& l) {
- mgmtObject->set_status(printable(status).str());
- brokerInfo.setStatus(status);
- setLinkProperties(l);
-}
-
-void HaBroker::membershipUpdated(Mutex::ScopedLock&) {
- QPID_LOG(info, logPrefix << "Membership changed: " << membership);
- Variant::List brokers = membership.asList();
- mgmtObject->set_members(brokers);
- broker.getManagementAgent()->raiseEvent(_qmf::EventMembersUpdate(brokers));
-}
-
-void HaBroker::setMembership(const Variant::List& brokers) {
- Mutex::ScopedLock l(lock);
- membership.assign(brokers);
- QPID_LOG(info, logPrefix << "Membership update: " << membership);
- BrokerInfo info;
- // Update my status to what the primary says it is. The primary can toggle
- // status between READY and CATCHUP based on the state of our subscriptions.
- if (membership.get(systemId, info) && status != info.getStatus()) {
- setStatus(info.getStatus(), l);
- if (backup.get()) backup->setStatus(status);
- }
- membershipUpdated(l);
-}
-
-void HaBroker::resetMembership(const BrokerInfo& b) {
- Mutex::ScopedLock l(lock);
- membership.reset(b);
- QPID_LOG(debug, logPrefix << "Membership reset to: " << membership);
- membershipUpdated(l);
-}
-
-void HaBroker::addBroker(const BrokerInfo& b) {
- Mutex::ScopedLock l(lock);
- membership.add(b);
- QPID_LOG(debug, logPrefix << "Membership add: " << b);
- membershipUpdated(l);
-}
-
-void HaBroker::removeBroker(const Uuid& id) {
- Mutex::ScopedLock l(lock);
- membership.remove(id);
- QPID_LOG(debug, logPrefix << "Membership remove: " << id);
- membershipUpdated(l);
-}
-
-void HaBroker::setLinkProperties(Mutex::ScopedLock&) {
- framing::FieldTable linkProperties = broker.getLinkClientProperties();
- if (isBackup(status)) {
- // If this is a backup then any outgoing links are backup
- // links and need to be tagged.
- linkProperties.setTable(ConnectionObserver::BACKUP_TAG, brokerInfo.asFieldTable());
- }
- else {
- // If this is a primary then any outgoing links are federation links
- // and should not be tagged.
- linkProperties.erase(ConnectionObserver::BACKUP_TAG);
- }
- broker.setLinkClientProperties(linkProperties);
+ return membership.getStatus();
}
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/HaBroker.h b/cpp/src/qpid/ha/HaBroker.h
index 7dabe6e35b..6b15c88e0a 100644
--- a/cpp/src/qpid/ha/HaBroker.h
+++ b/cpp/src/qpid/ha/HaBroker.h
@@ -25,14 +25,12 @@
#include "BrokerInfo.h"
#include "Membership.h"
#include "types.h"
-#include "ReplicationTest.h"
#include "Settings.h"
#include "qpid/Url.h"
#include "qpid/sys/Mutex.h"
#include "qmf/org/apache/qpid/ha/HaBroker.h"
#include "qpid/management/Manageable.h"
#include "qpid/types/Variant.h"
-#include <memory>
#include <set>
#include <boost/shared_ptr.hpp>
@@ -54,11 +52,15 @@ namespace ha {
class Backup;
class ConnectionObserver;
class Primary;
-
+class Role;
/**
* HA state and actions associated with a HA broker. Holds all the management info.
*
* THREAD SAFE: may be called in arbitrary broker IO or timer threads.
+
+ * NOTE: HaBroker and Role subclasses follow this lock hierarchy:
+ * - HaBroker MUST NOT hold its own lock across calls Role subclasses.
+ * - Role subclasses MAY hold their locks accross calls to HaBroker.
*/
class HaBroker : public management::Manageable
{
@@ -71,66 +73,46 @@ class HaBroker : public management::Manageable
void initialize();
// Implement Manageable.
- qpid::management::ManagementObject* GetManagementObject() const { return mgmtObject; }
+ qpid::management::ManagementObject::shared_ptr GetManagementObject() const { return mgmtObject; }
management::Manageable::status_t ManagementMethod (
uint32_t methodId, management::Args& args, std::string& text);
broker::Broker& getBroker() { return broker; }
const Settings& getSettings() const { return settings; }
- /** Shut down the broker. Caller should log a critical error message. */
- void shutdown();
+ /** Shut down the broker because of a critical error. */
+ void shutdown(const std::string& message);
BrokerStatus getStatus() const;
- void setStatus(BrokerStatus);
- void activate();
-
- Backup* getBackup() { return backup.get(); }
- ReplicationTest getReplicationTest() const { return replicationTest; }
-
boost::shared_ptr<ConnectionObserver> getObserver() { return observer; }
- const BrokerInfo& getBrokerInfo() const { return brokerInfo; }
-
- void setMembership(const types::Variant::List&); // Set membership from list.
- void resetMembership(const BrokerInfo& b); // Reset to contain just one member.
- void addBroker(const BrokerInfo& b); // Add a broker to the membership.
- void removeBroker(const types::Uuid& id); // Remove a broker from membership.
-
+ BrokerInfo getBrokerInfo() const { return membership.getInfo(); }
+ Membership& getMembership() { return membership; }
types::Uuid getSystemId() const { return systemId; }
private:
- void setClientUrl(const Url&);
+
+ void setPublicUrl(const Url&);
void setBrokerUrl(const Url&);
void updateClientUrl(sys::Mutex::ScopedLock&);
- bool isPrimary(sys::Mutex::ScopedLock&) { return !backup.get(); }
-
- void setStatus(BrokerStatus, sys::Mutex::ScopedLock&);
- void recover();
- void statusChanged(sys::Mutex::ScopedLock&);
- void setLinkProperties(sys::Mutex::ScopedLock&);
-
std::vector<Url> getKnownBrokers() const;
- void membershipUpdated(sys::Mutex::ScopedLock&);
-
- std::string logPrefix;
- broker::Broker& broker;
- types::Uuid systemId;
+ // Immutable members
+ const types::Uuid systemId;
const Settings settings;
+ // Member variables protected by lock
mutable sys::Mutex lock;
- boost::shared_ptr<ConnectionObserver> observer; // Used by Backup and Primary
- std::auto_ptr<Backup> backup;
- std::auto_ptr<Primary> primary;
- qmf::org::apache::qpid::ha::HaBroker* mgmtObject;
- Url clientUrl, brokerUrl;
+ Url publicUrl, brokerUrl;
std::vector<Url> knownBrokers;
- BrokerStatus status;
- BrokerInfo brokerInfo;
+
+ // Independently thread-safe member variables
+ broker::Broker& broker;
+ qmf::org::apache::qpid::ha::HaBroker::shared_ptr mgmtObject;
+ boost::shared_ptr<ConnectionObserver> observer; // Used by Backup and Primary
+ boost::shared_ptr<Role> role;
Membership membership;
- ReplicationTest replicationTest;
};
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/HaPlugin.cpp b/cpp/src/qpid/ha/HaPlugin.cpp
index f7fe553d9b..d26b466847 100644
--- a/cpp/src/qpid/ha/HaPlugin.cpp
+++ b/cpp/src/qpid/ha/HaPlugin.cpp
@@ -33,9 +33,11 @@ struct Options : public qpid::Options {
addOptions()
("ha-cluster", optValue(settings.cluster, "yes|no"),
"Join a HA active/passive cluster.")
+ ("ha-queue-replication", optValue(settings.queueReplication, "yes|no"),
+ "Enable replication of specific queues without joining a cluster")
("ha-brokers-url", optValue(settings.brokerUrl,"URL"),
"URL with address of each broker in the cluster.")
- ("ha-public-url", optValue(settings.clientUrl,"URL"),
+ ("ha-public-url", optValue(settings.publicUrl,"URL"),
"URL advertized to clients to connect to the cluster.")
("ha-replicate",
optValue(settings.replicateDefault, "LEVEL"),
@@ -48,6 +50,10 @@ struct Options : public qpid::Options {
"Authentication mechanism for connections between HA brokers")
("ha-backup-timeout", optValue(settings.backupTimeout, "SECONDS"),
"Maximum time to wait for an expected backup to connect and become ready.")
+ ("ha-flow-messages", optValue(settings.flowMessages, "N"),
+ "Flow control message count limit for replication, 0 means no limit")
+ ("ha-flow-bytes", optValue(settings.flowBytes, "N"),
+ "Flow control byte limit for replication, 0 means no limit")
;
}
};
@@ -64,17 +70,23 @@ struct HaPlugin : public Plugin {
void earlyInitialize(Plugin::Target& target) {
broker::Broker* broker = dynamic_cast<broker::Broker*>(&target);
- if (broker) {
- // Must create the HaBroker in earlyInitialize so it can set up its
- // connection observer before clients start connecting.
- haBroker.reset(new ha::HaBroker(*broker, settings));
- broker->addFinalizer(boost::bind(&HaPlugin::finalize, this));
+ if (broker && (settings.cluster || settings.queueReplication)) {
+ if (!broker->getManagementAgent()) {
+ QPID_LOG(info, "HA plugin disabled because management is disabled");
+ if (settings.cluster)
+ throw Exception("Cannot start HA: management is disabled");
+ } else {
+ // Must create the HaBroker in earlyInitialize so it can set up its
+ // connection observer before clients start connecting.
+ haBroker.reset(new ha::HaBroker(*broker, settings));
+ broker->addFinalizer(boost::bind(&HaPlugin::finalize, this));
+ }
}
}
void initialize(Plugin::Target& target) {
broker::Broker* broker = dynamic_cast<broker::Broker*>(&target);
- if (broker) haBroker->initialize();
+ if (broker && haBroker.get()) haBroker->initialize();
}
void finalize() {
diff --git a/cpp/src/qpid/ha/Membership.cpp b/cpp/src/qpid/ha/Membership.cpp
index 74580f9b1e..6c64d86fd7 100644
--- a/cpp/src/qpid/ha/Membership.cpp
+++ b/cpp/src/qpid/ha/Membership.cpp
@@ -19,6 +19,12 @@
*
*/
#include "Membership.h"
+#include "HaBroker.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/management/ManagementAgent.h"
+#include "qpid/types/Variant.h"
+#include "qmf/org/apache/qpid/ha/EventMembersUpdate.h"
+#include "qmf/org/apache/qpid/ha/HaBroker.h"
#include <boost/bind.hpp>
#include <iostream>
#include <iterator>
@@ -26,37 +32,58 @@
namespace qpid {
namespace ha {
+namespace _qmf = ::qmf::org::apache::qpid::ha;
-void Membership::reset(const BrokerInfo& b) {
+using sys::Mutex;
+using types::Variant;
+
+Membership::Membership(const BrokerInfo& info, HaBroker& b)
+ : haBroker(b), self(info.getSystemId())
+{
+ brokers[self] = info;
+}
+
+void Membership::clear() {
+ Mutex::ScopedLock l(lock);
+ BrokerInfo me = brokers[self];
brokers.clear();
- brokers[b.getSystemId()] = b;
+ brokers[self] = me;
}
void Membership::add(const BrokerInfo& b) {
+ Mutex::ScopedLock l(lock);
brokers[b.getSystemId()] = b;
+ update(l);
}
void Membership::remove(const types::Uuid& id) {
+ Mutex::ScopedLock l(lock);
+ if (id == self) return; // Never remove myself
BrokerInfo::Map::iterator i = brokers.find(id);
if (i != brokers.end()) {
brokers.erase(i);
- }
+ update(l);
+ }
}
bool Membership::contains(const types::Uuid& id) {
+ Mutex::ScopedLock l(lock);
return brokers.find(id) != brokers.end();
}
void Membership::assign(const types::Variant::List& list) {
- brokers.clear();
+ Mutex::ScopedLock l(lock);
+ clear();
for (types::Variant::List::const_iterator i = list.begin(); i != list.end(); ++i) {
BrokerInfo b(i->asMap());
brokers[b.getSystemId()] = b;
}
+ update(l);
}
types::Variant::List Membership::asList() const {
+ Mutex::ScopedLock l(lock);
types::Variant::List list;
for (BrokerInfo::Map::const_iterator i = brokers.begin(); i != brokers.end(); ++i)
list.push_back(i->second.asMap());
@@ -64,6 +91,7 @@ types::Variant::List Membership::asList() const {
}
BrokerInfo::Set Membership::otherBackups() const {
+ Mutex::ScopedLock l(lock);
BrokerInfo::Set result;
for (BrokerInfo::Map::const_iterator i = brokers.begin(); i != brokers.end(); ++i)
if (i->second.getStatus() == READY && i->second.getSystemId() != self)
@@ -71,15 +99,84 @@ BrokerInfo::Set Membership::otherBackups() const {
return result;
}
-bool Membership::get(const types::Uuid& id, BrokerInfo& result) {
- BrokerInfo::Map::iterator i = brokers.find(id);
+bool Membership::get(const types::Uuid& id, BrokerInfo& result) const {
+ Mutex::ScopedLock l(lock);
+ BrokerInfo::Map::const_iterator i = brokers.find(id);
if (i == brokers.end()) return false;
result = i->second;
return true;
}
-std::ostream& operator<<(std::ostream& o, const Membership& members) {
- return o << members.brokers;
+void Membership::update(Mutex::ScopedLock& l) {
+ QPID_LOG(info, "Membership: " << brokers);
+ Variant::List brokers = asList();
+ if (mgmtObject) mgmtObject->set_status(printable(getStatus(l)).str());
+ if (mgmtObject) mgmtObject->set_members(brokers);
+ haBroker.getBroker().getManagementAgent()->raiseEvent(
+ _qmf::EventMembersUpdate(brokers));
+}
+
+void Membership::setMgmtObject(boost::shared_ptr<_qmf::HaBroker> mo) {
+ Mutex::ScopedLock l(lock);
+ mgmtObject = mo;
+ update(l);
+}
+
+
+namespace {
+bool checkTransition(BrokerStatus from, BrokerStatus to) {
+ // Legal state transitions. Initial state is JOINING, ACTIVE is terminal.
+ static const BrokerStatus TRANSITIONS[][2] = {
+ { STANDALONE, JOINING }, // Initialization of backup broker
+ { JOINING, CATCHUP }, // Connected to primary
+ { JOINING, RECOVERING }, // Chosen as initial primary.
+ { CATCHUP, READY }, // Caught up all queues, ready to take over.
+ { READY, RECOVERING }, // Chosen as new primary
+ { READY, CATCHUP }, // Timed out failing over, demoted to catch-up.
+ { RECOVERING, ACTIVE } // All expected backups are ready
+ };
+ static const size_t N = sizeof(TRANSITIONS)/sizeof(TRANSITIONS[0]);
+ for (size_t i = 0; i < N; ++i) {
+ if (TRANSITIONS[i][0] == from && TRANSITIONS[i][1] == to)
+ return true;
+ }
+ return false;
+}
+} // namespace
+
+void Membership::setStatus(BrokerStatus newStatus) {
+ BrokerStatus status = getStatus();
+ QPID_LOG(info, "Status change: "
+ << printable(status) << " -> " << printable(newStatus));
+ bool legal = checkTransition(status, newStatus);
+ if (!legal) {
+ haBroker.shutdown(QPID_MSG("Illegal state transition: " << printable(status)
+ << " -> " << printable(newStatus)));
+ }
+
+ Mutex::ScopedLock l(lock);
+ brokers[self].setStatus(newStatus);
+ if (mgmtObject) mgmtObject->set_status(printable(newStatus).str());
+ update(l);
+}
+
+BrokerStatus Membership::getStatus() const {
+ Mutex::ScopedLock l(lock);
+ return getStatus(l);
+}
+
+BrokerStatus Membership::getStatus(sys::Mutex::ScopedLock&) const {
+ BrokerInfo::Map::const_iterator i = brokers.find(self);
+ assert(i != brokers.end());
+ return i->second.getStatus();
+}
+
+BrokerInfo Membership::getInfo() const {
+ Mutex::ScopedLock l(lock);
+ BrokerInfo::Map::const_iterator i = brokers.find(self);
+ assert(i != brokers.end());
+ return i->second;
}
+// FIXME aconway 2013-01-23: move to .h?
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/Membership.h b/cpp/src/qpid/ha/Membership.h
index 8406dccd5d..956569fbd8 100644
--- a/cpp/src/qpid/ha/Membership.h
+++ b/cpp/src/qpid/ha/Membership.h
@@ -24,45 +24,72 @@
#include "BrokerInfo.h"
#include "types.h"
-#include "qpid/framing/Uuid.h"
#include "qpid/log/Statement.h"
+#include "qpid/sys/Mutex.h"
#include "qpid/types/Variant.h"
#include <boost/function.hpp>
#include <set>
#include <vector>
#include <iosfwd>
+
+namespace qmf { namespace org { namespace apache { namespace qpid { namespace ha {
+class HaBroker;
+}}}}}
+
namespace qpid {
+
+namespace broker {
+class Broker;
+}
+
+namespace types {
+class Uuid;
+}
+
namespace ha {
+class HaBroker;
/**
* Keep track of the brokers in the membership.
- * THREAD UNSAFE: caller must serialize
+ * Send management when events on membership changes.
+ * THREAD SAFE
*/
class Membership
{
public:
- Membership(const types::Uuid& self_) : self(self_) {}
+ Membership(const BrokerInfo& info, HaBroker&);
- void reset(const BrokerInfo& b); ///< Reset to contain just one member.
+ void setMgmtObject(boost::shared_ptr<qmf::org::apache::qpid::ha::HaBroker>);
+
+ void clear(); ///< Clear all but self.
void add(const BrokerInfo& b);
void remove(const types::Uuid& id);
bool contains(const types::Uuid& id);
+
/** Return IDs of all READY backups other than self */
BrokerInfo::Set otherBackups() const;
void assign(const types::Variant::List&);
types::Variant::List asList() const;
- bool get(const types::Uuid& id, BrokerInfo& result);
+ bool get(const types::Uuid& id, BrokerInfo& result) const;
+
+ types::Uuid getSelf() const { return self; }
+ BrokerInfo getInfo() const;
+ BrokerStatus getStatus() const;
+ void setStatus(BrokerStatus s);
private:
- types::Uuid self;
+ void update(sys::Mutex::ScopedLock&);
+ BrokerStatus getStatus(sys::Mutex::ScopedLock&) const;
+
+ mutable sys::Mutex lock;
+ HaBroker& haBroker;
+ boost::shared_ptr<qmf::org::apache::qpid::ha::HaBroker> mgmtObject;
+ const types::Uuid self;
BrokerInfo::Map brokers;
- friend std::ostream& operator<<(std::ostream&, const Membership&);
};
-std::ostream& operator<<(std::ostream&, const Membership&);
-
}} // namespace qpid::ha
#endif /*!QPID_HA_MEMBERSHIP_H*/
diff --git a/cpp/src/qpid/ha/Primary.cpp b/cpp/src/qpid/ha/Primary.cpp
index e4bf9671b8..93dbbbea85 100644
--- a/cpp/src/qpid/ha/Primary.cpp
+++ b/cpp/src/qpid/ha/Primary.cpp
@@ -31,6 +31,8 @@
#include "qpid/broker/Connection.h"
#include "qpid/broker/Queue.h"
#include "qpid/framing/FieldTable.h"
+#include "qpid/framing/FieldValue.h"
+#include "qpid/framing/Uuid.h"
#include "qpid/log/Statement.h"
#include "qpid/sys/Timer.h"
#include <boost/bind.hpp>
@@ -39,6 +41,8 @@ namespace qpid {
namespace ha {
using sys::Mutex;
+using namespace std;
+using namespace framing;
namespace {
@@ -58,6 +62,8 @@ class PrimaryConfigurationObserver : public broker::ConfigurationObserver
PrimaryConfigurationObserver(Primary& p) : primary(p) {}
void queueCreate(const Primary::QueuePtr& q) { primary.queueCreate(q); }
void queueDestroy(const Primary::QueuePtr& q) { primary.queueDestroy(q); }
+ void exchangeCreate(const Primary::ExchangePtr& q) { primary.exchangeCreate(q); }
+ void exchangeDestroy(const Primary::ExchangePtr& q) { primary.exchangeDestroy(q); }
private:
Primary& primary;
};
@@ -76,8 +82,11 @@ class ExpectedBackupTimerTask : public sys::TimerTask {
Primary* Primary::instance = 0;
Primary::Primary(HaBroker& hb, const BrokerInfo::Set& expect) :
- haBroker(hb), logPrefix("Primary: "), active(false)
+ haBroker(hb), membership(hb.getMembership()),
+ logPrefix("Primary: "), active(false),
+ replicationTest(hb.getSettings().replicateDefault.get())
{
+ hb.getMembership().setStatus(RECOVERING);
assert(instance == 0);
instance = this; // Let queue replicators find us.
if (expect.empty()) {
@@ -89,11 +98,10 @@ Primary::Primary(HaBroker& hb, const BrokerInfo::Set& expect) :
// the QueueGuards are created.
QPID_LOG(notice, logPrefix << "Promoted to primary. Expected backups: " << expect);
for (BrokerInfo::Set::const_iterator i = expect.begin(); i != expect.end(); ++i) {
- boost::shared_ptr<RemoteBackup> backup(
- new RemoteBackup(*i, haBroker.getReplicationTest(), false));
+ boost::shared_ptr<RemoteBackup> backup(new RemoteBackup(*i, 0));
backups[i->getSystemId()] = backup;
if (!backup->isReady()) expectedBackups.insert(backup);
- backup->setInitialQueues(hb.getBroker().getQueues(), true); // Create guards
+ backup->setCatchupQueues(hb.getBroker().getQueues(), true); // Create guards
}
// Set timeout for expected brokers to connect and become ready.
sys::Duration timeout(int64_t(hb.getSettings().backupTimeout*sys::TIME_SEC));
@@ -102,14 +110,21 @@ Primary::Primary(HaBroker& hb, const BrokerInfo::Set& expect) :
hb.getBroker().getTimer().add(timerTask);
}
+
+ // Remove backup tag property from outgoing link properties.
+ framing::FieldTable linkProperties = hb.getBroker().getLinkClientProperties();
+ linkProperties.erase(ConnectionObserver::BACKUP_TAG);
+ hb.getBroker().setLinkClientProperties(linkProperties);
+
configurationObserver.reset(new PrimaryConfigurationObserver(*this));
haBroker.getBroker().getConfigurationObservers().add(configurationObserver);
Mutex::ScopedLock l(lock); // We are now active as a configurationObserver
checkReady(l);
+
// Allow client connections
connectionObserver.reset(new PrimaryConnectionObserver(*this));
- haBroker.getObserver()->setObserver(connectionObserver);
+ haBroker.getObserver()->setObserver(connectionObserver, logPrefix);
}
Primary::~Primary() {
@@ -122,7 +137,7 @@ void Primary::checkReady(Mutex::ScopedLock&) {
active = true;
Mutex::ScopedUnlock u(lock); // Don't hold lock across callback
QPID_LOG(notice, logPrefix << "Finished waiting for backups, primary is active.");
- haBroker.activate();
+ membership.setStatus(ACTIVE);
}
}
@@ -130,7 +145,7 @@ void Primary::checkReady(BackupMap::iterator i, Mutex::ScopedLock& l) {
if (i != backups.end() && i->second->reportReady()) {
BrokerInfo info = i->second->getBrokerInfo();
info.setStatus(READY);
- haBroker.addBroker(info);
+ membership.add(info);
if (expectedBackups.erase(i->second)) {
QPID_LOG(info, logPrefix << "Expected backup is ready: " << info);
checkReady(l);
@@ -155,9 +170,10 @@ void Primary::timeoutExpectedBackups() {
expectedBackups.erase(i++);
backups.erase(info.getSystemId());
rb->cancel();
- // Downgrade the broker to CATCHUP
+ // Downgrade the broker's status to CATCHUP
+ // The broker will get this status change when it eventually connects.
info.setStatus(CATCHUP);
- haBroker.addBroker(info);
+ membership.add(info);
}
else ++i;
}
@@ -178,46 +194,78 @@ void Primary::readyReplica(const ReplicatingSubscription& rs) {
}
}
+// NOTE: Called with queue registry lock held.
void Primary::queueCreate(const QueuePtr& q) {
- // Throw if there is an invalid replication level in the queue settings.
- haBroker.getReplicationTest().replicateLevel(q->getSettings().storeSettings);
- Mutex::ScopedLock l(lock);
- for (BackupMap::iterator i = backups.begin(); i != backups.end(); ++i) {
- i->second->queueCreate(q);
- checkReady(i, l);
+ // Set replication argument.
+ ReplicateLevel level = replicationTest.useLevel(*q);
+ QPID_LOG(debug, logPrefix << "Created queue " << q->getName()
+ << " replication: " << printable(level));
+ q->addArgument(QPID_REPLICATE, printable(level).str());
+ if (level) {
+ // Give each queue a unique id to avoid confusion of same-named queues.
+ q->addArgument(QPID_HA_UUID, types::Variant(Uuid(true)));
+ Mutex::ScopedLock l(lock);
+ for (BackupMap::iterator i = backups.begin(); i != backups.end(); ++i) {
+ i->second->queueCreate(q);
+ checkReady(i, l);
+ }
}
}
+// NOTE: Called with queue registry lock held.
void Primary::queueDestroy(const QueuePtr& q) {
+ QPID_LOG(debug, logPrefix << "Destroyed queue " << q->getName());
Mutex::ScopedLock l(lock);
for (BackupMap::iterator i = backups.begin(); i != backups.end(); ++i)
i->second->queueDestroy(q);
checkReady(l);
}
+// NOTE: Called with exchange registry lock held.
+void Primary::exchangeCreate(const ExchangePtr& ex) {
+ ReplicateLevel level = replicationTest.useLevel(*ex);
+ QPID_LOG(debug, logPrefix << "Created exchange " << ex->getName()
+ << " replication: " << printable(level));
+ FieldTable args = ex->getArgs();
+ args.setString(QPID_REPLICATE, printable(level).str()); // Set replication arg.
+ if (level) {
+ // Give each exchange a unique id to avoid confusion of same-named exchanges.
+ args.set(QPID_HA_UUID, FieldTable::ValuePtr(new UuidValue(&Uuid(true)[0])));
+ }
+ ex->setArgs(args);
+}
+
+// NOTE: Called with exchange registry lock held.
+void Primary::exchangeDestroy(const ExchangePtr& ex) {
+ QPID_LOG(debug, logPrefix << "Destroyed exchange " << ex->getName());
+ // Do nothing
+ }
+
void Primary::opened(broker::Connection& connection) {
BrokerInfo info;
if (ha::ConnectionObserver::getBrokerInfo(connection, info)) {
Mutex::ScopedLock l(lock);
BackupMap::iterator i = backups.find(info.getSystemId());
if (i == backups.end()) {
- QPID_LOG(debug, logPrefix << "New backup connected: " << info);
- boost::shared_ptr<RemoteBackup> backup(
- new RemoteBackup(info, haBroker.getReplicationTest(), true));
+ QPID_LOG(info, logPrefix << "New backup connected: " << info);
+ boost::shared_ptr<RemoteBackup> backup(new RemoteBackup(info, &connection));
{
// Avoid deadlock with queue registry lock.
Mutex::ScopedUnlock u(lock);
- backup->setInitialQueues(haBroker.getBroker().getQueues(), false);
+ backup->setCatchupQueues(haBroker.getBroker().getQueues(), false);
}
backups[info.getSystemId()] = backup;
+ i = backups.find(info.getSystemId());
}
else {
- QPID_LOG(debug, logPrefix << "Known backup connected: " << info);
- i->second->setConnected(true);
- checkReady(i, l);
+ QPID_LOG(info, logPrefix << "Known backup connected: " << info);
+ i->second->setConnection(&connection);
}
- if (info.getStatus() == JOINING) info.setStatus(CATCHUP);
- haBroker.addBroker(info);
+ if (info.getStatus() == JOINING) {
+ info.setStatus(CATCHUP);
+ membership.add(info);
+ }
+ if (i != backups.end()) checkReady(i, l);
}
else
QPID_LOG(debug, logPrefix << "Accepted client connection "
@@ -225,19 +273,20 @@ void Primary::opened(broker::Connection& connection) {
}
void Primary::closed(broker::Connection& connection) {
- // NOTE: It is possible for a backup connection to be rejected while we are
- // a backup, but closed() is called after we have become primary.
- //
- // For this reason we do not remove from the backups map here, the backups
- // map holds all the backups we know about whether connected or not.
- //
- Mutex::ScopedLock l(lock);
BrokerInfo info;
if (ha::ConnectionObserver::getBrokerInfo(connection, info)) {
- QPID_LOG(debug, logPrefix << "Backup disconnected: " << info);
- haBroker.removeBroker(info.getSystemId());
+ Mutex::ScopedLock l(lock);
BackupMap::iterator i = backups.find(info.getSystemId());
- if (i != backups.end()) i->second->setConnected(false);
+ // NOTE: It is possible for a backup connection to be rejected while we
+ // are a backup, but closed() is called after we have become primary.
+ // Checking isConnected() lets us ignore such spurious closes.
+ if (i != backups.end() && i->second->isConnected()) {
+ QPID_LOG(info, logPrefix << "Backup disconnected: " << info);
+ membership.remove(info.getSystemId());
+ expectedBackups.erase(i->second);
+ backups.erase(i);
+ checkReady(l);
+ }
}
}
@@ -249,4 +298,9 @@ boost::shared_ptr<QueueGuard> Primary::getGuard(const QueuePtr& q, const BrokerI
return i == backups.end() ? boost::shared_ptr<QueueGuard>() : i->second->guard(q);
}
+Role* Primary::promote() {
+ QPID_LOG(info, "Ignoring promotion, already primary: " << haBroker.getBrokerInfo());
+ return 0;
+}
+
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/Primary.h b/cpp/src/qpid/ha/Primary.h
index 26883f4416..ff85837882 100644
--- a/cpp/src/qpid/ha/Primary.h
+++ b/cpp/src/qpid/ha/Primary.h
@@ -24,6 +24,8 @@
#include "types.h"
#include "BrokerInfo.h"
+#include "ReplicationTest.h"
+#include "Role.h"
#include "qpid/sys/Mutex.h"
#include <boost/shared_ptr.hpp>
#include <boost/intrusive_ptr.hpp>
@@ -48,6 +50,7 @@ class HaBroker;
class ReplicatingSubscription;
class RemoteBackup;
class QueueGuard;
+class Membership;
/**
* State associated with a primary broker:
@@ -56,22 +59,30 @@ class QueueGuard;
*
* THREAD SAFE: called concurrently in arbitrary connection threads.
*/
-class Primary
+class Primary : public Role
{
public:
typedef boost::shared_ptr<broker::Queue> QueuePtr;
+ typedef boost::shared_ptr<broker::Exchange> ExchangePtr;
static Primary* get() { return instance; }
Primary(HaBroker& hb, const BrokerInfo::Set& expectedBackups);
~Primary();
+ // Role implementation
+ std::string getLogPrefix() const { return logPrefix; }
+ Role* promote();
+ void setBrokerUrl(const Url&) {}
+
void readyReplica(const ReplicatingSubscription&);
void removeReplica(const std::string& q);
// Called via ConfigurationObserver
void queueCreate(const QueuePtr&);
void queueDestroy(const QueuePtr&);
+ void exchangeCreate(const ExchangePtr&);
+ void exchangeDestroy(const ExchangePtr&);
// Called via ConnectionObserver
void opened(broker::Connection& connection);
@@ -91,17 +102,19 @@ class Primary
sys::Mutex lock;
HaBroker& haBroker;
+ Membership& membership;
std::string logPrefix;
bool active;
+ ReplicationTest replicationTest;
+
/**
* Set of expected backups that must be ready before we declare ourselves
- * active
+ * active. These are backups that were known and ready before the primary
+ * crashed. As new primary we expect them to re-connect.
*/
BackupSet expectedBackups;
/**
- * Map of all the remote backups we know about: any expected backups plus
- * all actual backups that have connected. We do not remove entries when a
- * backup disconnects. @see Primary::closed()
+ * Map of all the expected backups plus all connected backups.
*/
BackupMap backups;
boost::shared_ptr<broker::ConnectionObserver> connectionObserver;
diff --git a/cpp/src/qpid/ha/QueueGuard.cpp b/cpp/src/qpid/ha/QueueGuard.cpp
index 77e1f81a38..d06d88ca29 100644
--- a/cpp/src/qpid/ha/QueueGuard.cpp
+++ b/cpp/src/qpid/ha/QueueGuard.cpp
@@ -50,10 +50,10 @@ class QueueGuard::QueueObserver : public broker::QueueObserver
QueueGuard::QueueGuard(broker::Queue& q, const BrokerInfo& info)
- : queue(q), subscription(0)
+ : cancelled(false), queue(q), subscription(0)
{
std::ostringstream os;
- os << "Primary guard " << queue.getName() << "@" << info.getLogId() << ": ";
+ os << "Primary guard " << queue.getName() << "@" << info << ": ";
logPrefix = os.str();
observer.reset(new QueueObserver(*this));
queue.addObserver(observer);
@@ -66,45 +66,31 @@ QueueGuard::~QueueGuard() { cancel(); }
// NOTE: Called with message lock held.
void QueueGuard::enqueued(const Message& m) {
// Delay completion
- QPID_LOG(trace, logPrefix << "Delayed completion of " << m);
+ QPID_LOG(trace, logPrefix << "Delayed completion of " << m.getSequence());
+ Mutex::ScopedLock l(lock);
+ if (cancelled) return; // Don't record enqueues after we are cancelled.
+ assert(delayed.find(m.getSequence()) == delayed.end());
+ delayed[m.getSequence()] = m.getIngressCompletion();
m.getIngressCompletion()->startCompleter();
- {
- Mutex::ScopedLock l(lock);
- if (!delayed.insert(Delayed::value_type(m.getSequence(), m.getIngressCompletion())).second) {
- QPID_LOG(critical, logPrefix << "Second enqueue for message with sequence " << m.getSequence());
- assert(false);
- }
- }
}
// NOTE: Called with message lock held.
void QueueGuard::dequeued(const Message& m) {
QPID_LOG(trace, logPrefix << "Dequeued " << m);
- ReplicatingSubscription* rs=0;
- {
- Mutex::ScopedLock l(lock);
- rs = subscription;
- }
- if (rs) rs->dequeued(m);
- complete(m.getSequence());
-}
-
-void QueueGuard::completeRange(Delayed::iterator begin, Delayed::iterator end) {
- for (Delayed::iterator i = begin; i != end; ++i) {
- QPID_LOG(trace, logPrefix << "Completed " << i->first);
- i->second->finishCompleter();
- }
+ Mutex::ScopedLock l(lock);
+ if (subscription) subscription->dequeued(m);
+ complete(m.getSequence(), l);
}
void QueueGuard::cancel() {
queue.removeObserver(observer);
- Delayed removed;
- {
- Mutex::ScopedLock l(lock);
- if (delayed.empty()) return; // No need if no delayed messages.
- delayed.swap(removed);
+ Mutex::ScopedLock l(lock);
+ if (cancelled) return;
+ cancelled = true;
+ for (Delayed::iterator i = delayed.begin(); i != delayed.end();) {
+ complete(i, l);
+ delayed.erase(i++);
}
- completeRange(removed.begin(), removed.end());
}
void QueueGuard::attach(ReplicatingSubscription& rs) {
@@ -113,38 +99,36 @@ void QueueGuard::attach(ReplicatingSubscription& rs) {
}
bool QueueGuard::subscriptionStart(SequenceNumber position) {
- Delayed removed;
- {
- Mutex::ScopedLock l(lock);
- // Complete any messages before or at the ReplicatingSubscription start position.
- // Those messages are already on the backup.
- for (Delayed::iterator i = delayed.begin(); i != delayed.end() && i->first <= position;) {
- removed.insert(*i);
- delayed.erase(i++);
- }
+ // Complete any messages before or at the ReplicatingSubscription start position.
+ // Those messages are already on the backup.
+ Mutex::ScopedLock l(lock);
+ Delayed::iterator i = delayed.begin();
+ while(i != delayed.end() && i->first <= position) {
+ complete(i, l);
+ delayed.erase(i++);
}
- completeRange(removed.begin(), removed.end());
return position >= range.back;
}
void QueueGuard::complete(SequenceNumber sequence) {
- boost::intrusive_ptr<broker::AsyncCompletion> m;
- {
- Mutex::ScopedLock l(lock);
- // The same message can be completed twice, by
- // ReplicatingSubscription::acknowledged and dequeued. Remove it
- // from the map so we only call finishCompleter() once
- Delayed::iterator i = delayed.find(sequence);
- if (i != delayed.end()) {
- m = i->second;
- delayed.erase(i);
- }
+ Mutex::ScopedLock l(lock);
+ complete(sequence, l);
+}
+void QueueGuard::complete(SequenceNumber sequence, Mutex::ScopedLock& l) {
+ // The same message can be completed twice, by
+ // ReplicatingSubscription::acknowledged and dequeued. Remove it
+ // from the map so we only call finishCompleter() once
+ Delayed::iterator i = delayed.find(sequence);
+ if (i != delayed.end()) {
+ complete(i, l);
+ delayed.erase(i);
}
- if (m) {
- QPID_LOG(trace, logPrefix << "Completed " << sequence);
- m->finishCompleter();
- }
+}
+
+void QueueGuard::complete(Delayed::iterator i, Mutex::ScopedLock&) {
+ QPID_LOG(trace, logPrefix << "Completed " << i->first);
+ i->second->finishCompleter();
}
}} // namespaces qpid::ha
diff --git a/cpp/src/qpid/ha/QueueGuard.h b/cpp/src/qpid/ha/QueueGuard.h
index 3904b3bd3f..e7ceb351e8 100644
--- a/cpp/src/qpid/ha/QueueGuard.h
+++ b/cpp/src/qpid/ha/QueueGuard.h
@@ -54,6 +54,9 @@ class ReplicatingSubscription;
* THREAD SAFE: Concurrent calls:
* - enqueued() via QueueObserver in arbitrary connection threads.
* - attach(), cancel(), complete() from ReplicatingSubscription in subscription thread.
+ *
+ * Lock Hierarchy: ReplicatingSubscription MUS NOT call QueueGuard with it's lock held
+ * QueueGuard MAY call ReplicatingSubscription with it's lock held.
*/
class QueueGuard {
public:
@@ -104,17 +107,20 @@ class QueueGuard {
private:
class QueueObserver;
+ typedef std::map<framing::SequenceNumber,
+ boost::intrusive_ptr<broker::AsyncCompletion> > Delayed;
+
+ void complete(framing::SequenceNumber, sys::Mutex::ScopedLock &);
+ void complete(Delayed::iterator, sys::Mutex::ScopedLock &);
sys::Mutex lock;
+ bool cancelled;
std::string logPrefix;
broker::Queue& queue;
- typedef std::map<framing::SequenceNumber, boost::intrusive_ptr<broker::AsyncCompletion> > Delayed;
Delayed delayed;
ReplicatingSubscription* subscription;
boost::shared_ptr<QueueObserver> observer;
QueueRange range;
-
- void completeRange(Delayed::iterator begin, Delayed::iterator end);
};
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/QueueRange.h b/cpp/src/qpid/ha/QueueRange.h
index d734326910..f67ac146e6 100644
--- a/cpp/src/qpid/ha/QueueRange.h
+++ b/cpp/src/qpid/ha/QueueRange.h
@@ -24,6 +24,7 @@
#include "ReplicatingSubscription.h"
#include "qpid/broker/Queue.h"
+#include "qpid/broker/QueueCursor.h"
#include "qpid/framing/FieldTable.h"
#include "qpid/framing/SequenceNumber.h"
#include <iostream>
@@ -51,15 +52,7 @@ struct QueueRange {
QueueRange() : front(1), back(0) { } // Empty range.
- QueueRange(broker::Queue& q) {
- if (ReplicatingSubscription::getFront(q, front))
- back = q.getPosition();
- else {
- back = q.getPosition();
- front = back+1; // empty
- }
- assert(front <= back + 1);
- }
+ QueueRange(broker::Queue& q) { q.getRange(front, back, broker::REPLICATOR); }
QueueRange(const framing::FieldTable& args) {
back = args.getAsInt(ReplicatingSubscription::QPID_BACK);
diff --git a/cpp/src/qpid/ha/QueueReplicator.cpp b/cpp/src/qpid/ha/QueueReplicator.cpp
index cac1fdac29..98220b2098 100644
--- a/cpp/src/qpid/ha/QueueReplicator.cpp
+++ b/cpp/src/qpid/ha/QueueReplicator.cpp
@@ -22,12 +22,15 @@
#include "HaBroker.h"
#include "QueueReplicator.h"
#include "ReplicatingSubscription.h"
+#include "Settings.h"
#include "qpid/broker/Bridge.h"
#include "qpid/broker/Broker.h"
#include "qpid/broker/Link.h"
#include "qpid/broker/Queue.h"
+#include "qpid/broker/QueueObserver.h"
#include "qpid/broker/QueueRegistry.h"
#include "qpid/broker/SessionHandler.h"
+#include "qpid/broker/SessionHandler.h"
#include "qpid/framing/SequenceSet.h"
#include "qpid/framing/FieldTable.h"
#include "qpid/log/Statement.h"
@@ -37,43 +40,89 @@
namespace {
const std::string QPID_REPLICATOR_("qpid.replicator-");
const std::string TYPE_NAME("qpid.queue-replicator");
-const std::string QPID_SYNC_FREQUENCY("qpid.sync_frequency");
+const std::string QPID_HA("qpid.ha-");
}
namespace qpid {
namespace ha {
using namespace broker;
using namespace framing;
+using namespace std;
+using sys::Mutex;
-const std::string QPID_HA_EVENT_PREFIX("qpid.ha-event:");
-const std::string QueueReplicator::DEQUEUE_EVENT_KEY(QPID_HA_EVENT_PREFIX+"dequeue");
-const std::string QueueReplicator::POSITION_EVENT_KEY(QPID_HA_EVENT_PREFIX+"position");
+const std::string QueueReplicator::DEQUEUE_EVENT_KEY(QPID_HA+"dequeue");
+const std::string QueueReplicator::POSITION_EVENT_KEY(QPID_HA+"position");
+const std::string QueueReplicator::QPID_SYNC_FREQUENCY("qpid.sync_frequency");
std::string QueueReplicator::replicatorName(const std::string& queueName) {
return QPID_REPLICATOR_ + queueName;
}
+bool QueueReplicator::isReplicatorName(const std::string& name) {
+ return name.compare(0, QPID_REPLICATOR_.size(), QPID_REPLICATOR_) == 0;
+}
+
bool QueueReplicator::isEventKey(const std::string key) {
- const std::string& prefix = QPID_HA_EVENT_PREFIX;
+ const std::string& prefix = QPID_HA;
bool ret = key.size() > prefix.size() && key.compare(0, prefix.size(), prefix) == 0;
return ret;
}
+class QueueReplicator::ErrorListener : public SessionHandler::ErrorListener {
+ public:
+ ErrorListener(const std::string& prefix) : logPrefix(prefix) {}
+ void connectionException(framing::connection::CloseCode, const std::string& msg) {
+ QPID_LOG(error, logPrefix << "Connection error: " << msg);
+ }
+ void channelException(framing::session::DetachCode, const std::string& msg) {
+ QPID_LOG(error, logPrefix << "Channel error: " << msg);
+ }
+ void executionException(framing::execution::ErrorCode, const std::string& msg) {
+ QPID_LOG(error, logPrefix << "Execution error: " << msg);
+ }
+ void detach() {
+ QPID_LOG(debug, logPrefix << "Session detached");
+ }
+ private:
+ std::string logPrefix;
+};
+
+class QueueReplicator::QueueObserver : public broker::QueueObserver {
+ public:
+ QueueObserver(boost::shared_ptr<QueueReplicator> qr) : queueReplicator(qr) {}
+ void enqueued(const Message&) {}
+ void dequeued(const Message&) {}
+ void acquired(const Message&) {}
+ void requeued(const Message&) {}
+ void consumerAdded( const Consumer& ) {}
+ void consumerRemoved( const Consumer& ) {}
+ // Queue observer is destroyed when the queue is.
+ void destroy() { queueReplicator->destroy(); }
+ private:
+ boost::shared_ptr<QueueReplicator> queueReplicator;
+};
+
QueueReplicator::QueueReplicator(HaBroker& hb,
boost::shared_ptr<Queue> q,
boost::shared_ptr<Link> l)
: Exchange(replicatorName(q->getName()), 0, q->getBroker()),
haBroker(hb),
logPrefix("Backup queue "+q->getName()+": "),
- queue(q), link(l), brokerInfo(hb.getBrokerInfo())
+ queue(q), link(l), brokerInfo(hb.getBrokerInfo()), subscribed(false),
+ settings(hb.getSettings())
{
+ args.setString(QPID_REPLICATE, printable(NONE).str());
Uuid uuid(true);
bridgeName = replicatorName(q->getName()) + std::string(".") + uuid.str();
+ framing::FieldTable args = getArgs();
+ args.setString(QPID_REPLICATE, printable(NONE).str());
+ setArgs(args);
}
// This must be separate from the constructor so we can call shared_from_this.
void QueueReplicator::activate() {
- sys::Mutex::ScopedLock l(lock);
+ Mutex::ScopedLock l(lock);
+ if (!queue) return; // Already destroyed
std::pair<Bridge::shared_ptr, bool> result =
queue->getBroker()->getLinks().declare(
bridgeName,
@@ -93,48 +142,57 @@ void QueueReplicator::activate() {
boost::bind(&QueueReplicator::initializeBridge, shared_from_this(), _1, _2)
);
bridge = result.first;
+ bridge->setErrorListener(
+ boost::shared_ptr<ErrorListener>(new ErrorListener(logPrefix)));
+ boost::shared_ptr<QueueObserver> observer(new QueueObserver(shared_from_this()));
+ queue->addObserver(observer);
}
-QueueReplicator::~QueueReplicator() { deactivate(); }
+QueueReplicator::~QueueReplicator() {}
-void QueueReplicator::deactivate() {
- // destroy the route
- sys::Mutex::ScopedLock l(lock);
- if (bridge) {
- bridge->close();
- bridge.reset();
- QPID_LOG(debug, logPrefix << "Deactivated bridge " << bridgeName);
- }
+void QueueReplicator::destroy() {
+ // Called from Queue::destroyed()
+ Mutex::ScopedLock l(lock);
+ if (!bridge) return;
+ QPID_LOG(debug, logPrefix << "Destroyed.");
+ bridge->close();
+ // Need to drop shared pointers to avoid pointer cycles keeping this in memory.
+ queue.reset();
+ link.reset();
+ bridge.reset();
+ getBroker()->getExchanges().destroy(getName());
}
// Called in a broker connection thread when the bridge is created.
void QueueReplicator::initializeBridge(Bridge& bridge, SessionHandler& sessionHandler) {
- sys::Mutex::ScopedLock l(lock);
+ Mutex::ScopedLock l(lock);
+ if (!queue) return; // Already destroyed
AMQP_ServerProxy peer(sessionHandler.out);
const qmf::org::apache::qpid::broker::ArgsLinkBridge& args(bridge.getArgs());
- FieldTable settings;
- settings.setInt(ReplicatingSubscription::QPID_REPLICATING_SUBSCRIPTION, 1);
- settings.setInt(QPID_SYNC_FREQUENCY, 1); // FIXME aconway 2012-05-22: optimize?
- settings.setInt(ReplicatingSubscription::QPID_BACK,
- queue->getPosition());
- settings.setTable(ReplicatingSubscription::QPID_BROKER_INFO,
- brokerInfo.asFieldTable());
- SequenceNumber front;
- if (ReplicatingSubscription::getFront(*queue, front)) {
- settings.setInt(ReplicatingSubscription::QPID_FRONT, front);
- QPID_LOG(debug, "QPID_FRONT for " << queue->getName() << " is " << front);
+ FieldTable arguments;
+ arguments.setInt(ReplicatingSubscription::QPID_REPLICATING_SUBSCRIPTION, 1);
+ arguments.setInt(QPID_SYNC_FREQUENCY, 1); // FIXME aconway 2012-05-22: optimize?
+ arguments.setInt(ReplicatingSubscription::QPID_BACK, queue->getPosition());
+ arguments.setTable(ReplicatingSubscription::QPID_BROKER_INFO,brokerInfo.asFieldTable());
+ SequenceNumber front, back;
+ queue->getRange(front, back, broker::REPLICATOR);
+ if (front <= back) arguments.setInt(ReplicatingSubscription::QPID_FRONT, front);
+ try {
+ peer.getMessage().subscribe(
+ args.i_src, args.i_dest, 0/*accept-explicit*/, 1/*not-acquired*/,
+ false/*exclusive*/, "", 0, arguments);
+ peer.getMessage().setFlowMode(getName(), 1); // Window
+ peer.getMessage().flow(getName(), 0, settings.getFlowMessages());
+ peer.getMessage().flow(getName(), 1, settings.getFlowBytes());
+ }
+ catch(const exception& e) {
+ QPID_LOG(error, QPID_MSG(logPrefix + "Cannot connect to primary: " << e.what()));
+ throw;
}
- peer.getMessage().subscribe(
- args.i_src, args.i_dest, 0/*accept-explicit*/, 1/*not-acquired*/,
- false/*exclusive*/, "", 0, settings);
- // FIXME aconway 2012-05-22: use a finite credit window?
- peer.getMessage().flow(getName(), 0, 0xFFFFFFFF);
- peer.getMessage().flow(getName(), 1, 0xFFFFFFFF);
-
qpid::Address primary;
link->getRemoteAddress(primary);
QPID_LOG(info, logPrefix << "Connected to " << primary << "(" << bridgeName << ")");
- QPID_LOG(trace, logPrefix << "Subscription settings: " << settings);
+ QPID_LOG(trace, logPrefix << "Subscription arguments: " << arguments);
}
namespace {
@@ -147,17 +205,35 @@ template <class T> T decodeContent(Message& m) {
}
}
-void QueueReplicator::dequeue(SequenceNumber n, sys::Mutex::ScopedLock&) {
+void QueueReplicator::dequeue(SequenceNumber n, Mutex::ScopedLock&) {
+ boost::shared_ptr<Queue> q;
+ {
+ Mutex::ScopedLock l(lock);
+ if (!queue) return; // Already destroyed
+ q = queue;
+ }
// Thread safe: only calls thread safe Queue functions.
queue->dequeueMessageAt(n);
}
+namespace {
+bool getSequence(const Message& message, SequenceNumber& result) {
+ result = message.getSequence();
+ return true;
+}
+bool getNext(broker::Queue& q, SequenceNumber position, SequenceNumber& result) {
+ QueueCursor cursor(REPLICATOR);
+ return q.seek(cursor, boost::bind(&getSequence, _1, boost::ref(result)), position+1);
+}
+} // namespace
+
// Called in connection thread of the queues bridge to primary.
void QueueReplicator::route(Deliverable& msg)
{
try {
const std::string& key = msg.getMessage().getRoutingKey();
- sys::Mutex::ScopedLock l(lock);
+ Mutex::ScopedLock l(lock);
+ if (!queue) return; // Already destroyed
if (!isEventKey(key)) {
msg.deliverTo(queue);
// We are on a backup so the queue is not modified except via this.
@@ -176,16 +252,15 @@ void QueueReplicator::route(Deliverable& msg)
<< " to " << position);
// Verify that there are no messages after the new position in the queue.
SequenceNumber next;
- if (ReplicatingSubscription::getNext(*queue, position, next))
- throw Exception("Invalid position move, preceeds messages");
+ if (getNext(*queue, position, next))
+ throw Exception(QPID_MSG(logPrefix << "Invalid position " << position
+ << " preceeds message at " << next));
queue->setPosition(position);
}
// Ignore unknown event keys, may be introduced in later versions.
}
catch (const std::exception& e) {
- QPID_LOG(critical, logPrefix << "Replication failed: " << e.what());
- haBroker.shutdown();
- throw;
+ haBroker.shutdown(QPID_MSG(logPrefix << "Replication failed: " << e.what()));
}
}
diff --git a/cpp/src/qpid/ha/QueueReplicator.h b/cpp/src/qpid/ha/QueueReplicator.h
index 8d8a41a5ba..e8a793f611 100644
--- a/cpp/src/qpid/ha/QueueReplicator.h
+++ b/cpp/src/qpid/ha/QueueReplicator.h
@@ -41,6 +41,7 @@ class Deliverable;
namespace ha {
class HaBroker;
+class Settings;
/**
* Exchange created on a backup broker to replicate a queue on the primary.
@@ -57,7 +58,11 @@ class QueueReplicator : public broker::Exchange,
public:
static const std::string DEQUEUE_EVENT_KEY;
static const std::string POSITION_EVENT_KEY;
+ static const std::string QPID_SYNC_FREQUENCY;
+
static std::string replicatorName(const std::string& queueName);
+ static bool isReplicatorName(const std::string&);
+
/** Test if a string is an event key */
static bool isEventKey(const std::string key);
@@ -68,7 +73,6 @@ class QueueReplicator : public broker::Exchange,
~QueueReplicator();
void activate(); // Call after ctor
- void deactivate(); // Call before dtor
std::string getType() const;
bool bind(boost::shared_ptr<broker::Queue>, const std::string&, const framing::FieldTable*, qpid::broker::AsyncStore* const);
@@ -80,8 +84,18 @@ class QueueReplicator : public broker::Exchange,
uint64_t getSize();
void write(char* target);
+ // Set if the queue has ever been subscribed to, used for auto-delete cleanup.
+ void setSubscribed() { subscribed = true; }
+ bool isSubscribed() { return subscribed; }
+
+ boost::shared_ptr<broker::Queue> getQueue() const { return queue; }
+
private:
+ class ErrorListener;
+ class QueueObserver;
+
void initializeBridge(broker::Bridge& bridge, broker::SessionHandler& sessionHandler);
+ void destroy(); // Called when the queue is destroyed.
void dequeue(framing::SequenceNumber, sys::Mutex::ScopedLock&);
HaBroker& haBroker;
@@ -92,6 +106,8 @@ class QueueReplicator : public broker::Exchange,
boost::shared_ptr<broker::Link> link;
boost::shared_ptr<broker::Bridge> bridge;
BrokerInfo brokerInfo;
+ bool subscribed;
+ const Settings& settings;
};
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/RemoteBackup.cpp b/cpp/src/qpid/ha/RemoteBackup.cpp
index 3421380940..798ade3f73 100644
--- a/cpp/src/qpid/ha/RemoteBackup.cpp
+++ b/cpp/src/qpid/ha/RemoteBackup.cpp
@@ -21,6 +21,7 @@
#include "RemoteBackup.h"
#include "QueueGuard.h"
#include "qpid/broker/Broker.h"
+#include "qpid/broker/Connection.h"
#include "qpid/broker/Queue.h"
#include "qpid/broker/QueueRegistry.h"
#include "qpid/log/Statement.h"
@@ -32,32 +33,45 @@ namespace ha {
using sys::Mutex;
using boost::bind;
-RemoteBackup::RemoteBackup(const BrokerInfo& info, ReplicationTest rt, bool con) :
- logPrefix("Primary: Remote backup "+info.getLogId()+": "),
- brokerInfo(info), replicationTest(rt), connected(con), reportedReady(false)
-{}
+RemoteBackup::RemoteBackup(
+ const BrokerInfo& info, broker::Connection* c
+) : brokerInfo(info), replicationTest(NONE), connection(c), reportedReady(false)
+{
+ std::ostringstream oss;
+ oss << "Primary: Remote backup " << info << ": ";
+ logPrefix = oss.str();
+}
-void RemoteBackup::setInitialQueues(broker::QueueRegistry& queues, bool createGuards)
+void RemoteBackup::setCatchupQueues(broker::QueueRegistry& queues, bool createGuards)
{
- QPID_LOG(debug, logPrefix << "Setting initial queues" << (createGuards ? " and guards" : ""));
- queues.eachQueue(boost::bind(&RemoteBackup::initialQueue, this, _1, createGuards));
+ queues.eachQueue(boost::bind(&RemoteBackup::catchupQueue, this, _1, createGuards));
+ QPID_LOG(debug, logPrefix << "Set " << catchupQueues.size() << " catch-up queues"
+ << (createGuards ? " and guards" : ""));
}
RemoteBackup::~RemoteBackup() { cancel(); }
void RemoteBackup::cancel() {
+ QPID_LOG(debug, logPrefix << "Cancelled " << (connection? "connected":"disconnected")
+ << " backup: " << brokerInfo);
for (GuardMap::iterator i = guards.begin(); i != guards.end(); ++i)
i->second->cancel();
guards.clear();
+ if (connection) {
+ connection->abort();
+ connection = 0;
+ }
}
bool RemoteBackup::isReady() {
- return connected && initialQueues.empty();
+ return connection && catchupQueues.empty();
}
-void RemoteBackup::initialQueue(const QueuePtr& q, bool createGuard) {
- if (replicationTest.isReplicated(ALL, *q)) {
- initialQueues.insert(q);
+void RemoteBackup::catchupQueue(const QueuePtr& q, bool createGuard) {
+ if (replicationTest.getLevel(*q) == ALL) {
+ QPID_LOG(debug, logPrefix << "Catch-up queue"
+ << (createGuard ? " and guard" : "") << ": " << q->getName());
+ catchupQueues.insert(q);
if (createGuard) guards[q].reset(new QueueGuard(*q, brokerInfo));
}
}
@@ -88,21 +102,24 @@ std::ostream& operator<<(std::ostream& o, const QueueSetPrinter& qp) {
}
void RemoteBackup::ready(const QueuePtr& q) {
- initialQueues.erase(q);
- QPID_LOG(debug, logPrefix << "Queue ready: " << q->getName()
- << QueueSetPrinter(", waiting for: ", initialQueues));
- if (isReady()) QPID_LOG(debug, logPrefix << "All queues ready");
+ catchupQueues.erase(q);
+ if (catchupQueues.size()) {
+ QPID_LOG(debug, logPrefix << "Caught up on queue: " << q->getName() << ", "
+ << catchupQueues.size() << " remain to catch up");
+ }
+ else
+ QPID_LOG(debug, logPrefix << "Caught up on queue: " << q->getName() );
}
-// Called via ConfigurationObserver::queueCreate and from initialQueue
+// Called via ConfigurationObserver::queueCreate and from catchupQueue
void RemoteBackup::queueCreate(const QueuePtr& q) {
- if (replicationTest.isReplicated(ALL, *q))
+ if (replicationTest.getLevel(*q) == ALL)
guards[q].reset(new QueueGuard(*q, brokerInfo));
}
// Called via ConfigurationObserver
void RemoteBackup::queueDestroy(const QueuePtr& q) {
- initialQueues.erase(q);
+ catchupQueues.erase(q);
GuardMap::iterator i = guards.find(q);
if (i != guards.end()) {
i->second->cancel();
diff --git a/cpp/src/qpid/ha/RemoteBackup.h b/cpp/src/qpid/ha/RemoteBackup.h
index 8ee776e90b..769c50457e 100644
--- a/cpp/src/qpid/ha/RemoteBackup.h
+++ b/cpp/src/qpid/ha/RemoteBackup.h
@@ -33,6 +33,7 @@ namespace qpid {
namespace broker {
class Queue;
class QueueRegistry;
+class Connection;
}
namespace ha {
@@ -54,20 +55,20 @@ class RemoteBackup
/** Note: isReady() can be true after construction
*@param connected true if the backup is already connected.
*/
- RemoteBackup(const BrokerInfo& info, ReplicationTest, bool connected);
+ RemoteBackup(const BrokerInfo&, broker::Connection*);
~RemoteBackup();
- /** Set the initial queues for all queues in the registry.
- *@createGuards if true create guards also, if false guards will be created on demand.
+ /** Set all queues in the registry as catch-up queues.
+ *@createGuards if true create guards also, if false guards are created on demand.
*/
- void setInitialQueues(broker::QueueRegistry&, bool createGuards);
+ void setCatchupQueues(broker::QueueRegistry&, bool createGuards);
/** Return guard associated with a queue. Used to create ReplicatingSubscription. */
GuardPtr guard(const QueuePtr&);
/** Is the remote backup connected? */
- void setConnected(bool b) { connected=b; }
- bool isConnected() const { return connected; }
+ void setConnection(broker::Connection* c) { connection = c; }
+ bool isConnected() const { return connection; }
/** ReplicatingSubscription associated with queue is ready.
* Note: may set isReady()
@@ -80,7 +81,7 @@ class RemoteBackup
/** Called via ConfigurationObserver. Note: may set isReady() */
void queueDestroy(const QueuePtr&);
- /**@return true when all initial queues for this backup are ready. */
+ /**@return true when all catch-up queues for this backup are ready. */
bool isReady();
/**@return true if isReady() and this is the first call to reportReady */
@@ -94,15 +95,14 @@ class RemoteBackup
typedef std::map<QueuePtr, GuardPtr> GuardMap;
typedef std::set<QueuePtr> QueueSet;
- /** Add queue to guard as an initial queue */
- void initialQueue(const QueuePtr&, bool createGuard);
+ void catchupQueue(const QueuePtr&, bool createGuard);
std::string logPrefix;
BrokerInfo brokerInfo;
ReplicationTest replicationTest;
GuardMap guards;
- QueueSet initialQueues;
- bool connected;
+ QueueSet catchupQueues;
+ broker::Connection* connection;
bool reportedReady;
};
diff --git a/cpp/src/qpid/ha/ReplicatingSubscription.cpp b/cpp/src/qpid/ha/ReplicatingSubscription.cpp
index 6f7519cd1f..933716e8fa 100644
--- a/cpp/src/qpid/ha/ReplicatingSubscription.cpp
+++ b/cpp/src/qpid/ha/ReplicatingSubscription.cpp
@@ -91,25 +91,6 @@ string mask(const string& in)
return DOLLAR + in + INTERNAL;
}
-namespace {
-bool getSequence(const Message& message, SequenceNumber& result)
-{
- result = message.getSequence();
- return true;
-}
-}
-bool ReplicatingSubscription::getNext(
- broker::Queue& q, SequenceNumber from, SequenceNumber& result)
-{
- QueueCursor cursor(REPLICATOR);
- return q.seek(cursor, boost::bind(&getSequence, _1, boost::ref(result)), from);
-}
-
-bool ReplicatingSubscription::getFront(broker::Queue& q, SequenceNumber& front) {
- QueueCursor cursor(REPLICATOR);
- return q.seek(cursor, boost::bind(&getSequence, _1, boost::ref(front)));
-}
-
/* Called by SemanticState::consume to create a consumer */
boost::shared_ptr<broker::SemanticState::ConsumerImpl>
ReplicatingSubscription::Factory::create(
@@ -157,7 +138,7 @@ ReplicatingSubscription::ReplicatingSubscription(
// Set a log prefix message that identifies the remote broker.
ostringstream os;
- os << "Primary " << queue->getName() << "@" << info.getLogId() << ": ";
+ os << "Primary " << queue->getName() << "@" << info << ": ";
logPrefix = os.str();
// NOTE: Once the guard is attached we can have concurrent
@@ -171,6 +152,7 @@ ReplicatingSubscription::ReplicatingSubscription(
guard->attach(*this);
QueueRange backup(arguments); // Remote backup range.
+ QueueRange backupOriginal(backup);
QueueRange primary(guard->getRange()); // Unguarded range when the guard was set.
backupPosition = backup.back;
@@ -207,7 +189,7 @@ ReplicatingSubscription::ReplicatingSubscription(
// queue and hasn't been tampered with then that will be the case.
QPID_LOG(debug, logPrefix << "Subscribed:"
- << " backup:" << backup
+ << " backup:" << backupOriginal << " adjusted backup:" << backup
<< " primary:" << primary
<< " catch-up: " << position << "-" << primary.back
<< "(" << primary.back-position << ")");
@@ -222,9 +204,7 @@ ReplicatingSubscription::ReplicatingSubscription(
}
}
-ReplicatingSubscription::~ReplicatingSubscription() {
- QPID_LOG(debug, logPrefix << "Detroyed replicating subscription");
-}
+ReplicatingSubscription::~ReplicatingSubscription() {}
// Called in subscription's connection thread when the subscription is created.
// Called separate from ctor because sending events requires
@@ -248,19 +228,20 @@ void ReplicatingSubscription::initialize() {
}
// Message is delivered in the subscription's connection thread.
-bool ReplicatingSubscription::deliver(const qpid::broker::QueueCursor& c, const qpid::broker::Message& m) {
- position = m.getSequence();
+bool ReplicatingSubscription::deliver(
+ const qpid::broker::QueueCursor& c, const qpid::broker::Message& m)
+{
try {
- QPID_LOG(trace, logPrefix << "Replicating " << getQueue()->getName() << "[" << m.getSequence() << "]");
+ QPID_LOG(trace, logPrefix << "Replicating " << m.getSequence());
{
Mutex::ScopedLock l(lock);
- //FIXME GRS: position is no longer set//assert(position == m.getSequence());
+ position = m.getSequence();
- // m.getSequence() is the position of the newly enqueued message on local queue.
+ // m.getSequence() is the position of the new message on local queue.
// backupPosition is latest position on backup queue before enqueueing
if (m.getSequence() <= backupPosition)
throw Exception(
- QPID_MSG("Expected position > " << backupPosition
+ QPID_MSG(logPrefix << "Expected position > " << backupPosition
<< " but got " << m.getSequence()));
if (m.getSequence() - backupPosition > 1) {
// Position has advanced because of messages dequeued ahead of us.
@@ -272,7 +253,7 @@ bool ReplicatingSubscription::deliver(const qpid::broker::QueueCursor& c, const
}
return ConsumerImpl::deliver(c, m);
} catch (const std::exception& e) {
- QPID_LOG(critical, logPrefix << "Error replicating " << getQueue()->getName() << "[" << m.getSequence() << "]"
+ QPID_LOG(critical, logPrefix << "Error replicating " << m.getSequence()
<< ": " << e.what());
throw;
}
@@ -292,6 +273,7 @@ void ReplicatingSubscription::setReady() {
// Called in the subscription's connection thread.
void ReplicatingSubscription::cancel()
{
+ QPID_LOG(debug, logPrefix << "Cancelled");
guard->cancel();
ConsumerImpl::cancel();
}
@@ -299,7 +281,7 @@ void ReplicatingSubscription::cancel()
// Consumer override, called on primary in the backup's IO thread.
void ReplicatingSubscription::acknowledged(const broker::DeliveryRecord& r) {
// Finish completion of message, it has been acknowledged by the backup.
- QPID_LOG(trace, logPrefix << "Acknowledged " << getQueue()->getName() << "[" << r.getMessageId() << "]");
+ QPID_LOG(trace, logPrefix << "Acknowledged " << r.getMessageId());
guard->complete(r.getMessageId());
// If next message is protected by the guard then we are ready
if (r.getMessageId() >= guard->getRange().back) setReady();
@@ -328,7 +310,7 @@ void ReplicatingSubscription::sendDequeueEvent(Mutex::ScopedLock&)
// arbitrary connection threads.
void ReplicatingSubscription::dequeued(const Message& m)
{
- QPID_LOG(trace, logPrefix << "Dequeued " << getQueue()->getName() << "[" << m.getSequence() << "]");
+ QPID_LOG(trace, logPrefix << "Dequeued " << m.getSequence());
{
Mutex::ScopedLock l(lock);
dequeues.add(m.getSequence());
@@ -396,7 +378,14 @@ bool ReplicatingSubscription::doDispatch()
Mutex::ScopedLock l(lock);
if (!dequeues.empty()) sendDequeueEvent(l);
}
- return ConsumerImpl::doDispatch();
+ try {
+ return ConsumerImpl::doDispatch();
+ }
+ catch (const std::exception& e) {
+ // FIXME aconway 2012-10-05: detect queue deletion, no warning.
+ QPID_LOG(warning, logPrefix << " exception in dispatch: " << e.what());
+ return false;
+ }
}
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/ReplicatingSubscription.h b/cpp/src/qpid/ha/ReplicatingSubscription.h
index 8a2984846e..7fcb4ccf13 100644
--- a/cpp/src/qpid/ha/ReplicatingSubscription.h
+++ b/cpp/src/qpid/ha/ReplicatingSubscription.h
@@ -61,10 +61,14 @@ class QueueGuard;
*
* Lifecycle: broker::Queue holds shared_ptrs to this as a consumer.
*
+ * Lock Hierarchy: ReplicatingSubscription MUS NOT call QueueGuard with it's lock held
+ * QueueGuard MAY call ReplicatingSubscription with it's lock held.
*/
class ReplicatingSubscription : public broker::SemanticState::ConsumerImpl
{
public:
+ typedef broker::SemanticState::ConsumerImpl ConsumerImpl;
+
struct Factory : public broker::ConsumerFactory {
boost::shared_ptr<broker::SemanticState::ConsumerImpl> create(
broker::SemanticState* parent,
@@ -80,17 +84,6 @@ class ReplicatingSubscription : public broker::SemanticState::ConsumerImpl
static const std::string QPID_FRONT;
static const std::string QPID_BROKER_INFO;
- // TODO aconway 2012-05-23: these don't belong on ReplicatingSubscription
- /** Get position of front message on queue.
- *@return false if queue is empty.
- */
- static bool getFront(broker::Queue&, framing::SequenceNumber& result);
- /** Get next message after from in queue.
- *@return false if none found.
- */
- static bool getNext(broker::Queue&, framing::SequenceNumber from,
- framing::SequenceNumber& result);
-
ReplicatingSubscription(broker::SemanticState* parent,
const std::string& name, boost::shared_ptr<broker::Queue> ,
bool ack, bool acquire, bool exclusive, const std::string& tag,
@@ -114,6 +107,8 @@ class ReplicatingSubscription : public broker::SemanticState::ConsumerImpl
// Hide the "queue deleted" error for a ReplicatingSubscription when a
// queue is deleted, this is normal and not an error.
bool hideDeletedError() { return true; }
+ // Not counted for auto deletion and immediate message purposes.
+ bool isCounted() { return false; }
/** Initialization that must be done separately from construction
* because it requires a shared_ptr to this to exist.
diff --git a/cpp/src/qpid/ha/ReplicationTest.cpp b/cpp/src/qpid/ha/ReplicationTest.cpp
index 88a969dbfd..647523ef2c 100644
--- a/cpp/src/qpid/ha/ReplicationTest.cpp
+++ b/cpp/src/qpid/ha/ReplicationTest.cpp
@@ -19,7 +19,9 @@
*
*/
#include "ReplicationTest.h"
+#include "qpid/log/Statement.h"
#include "qpid/broker/Queue.h"
+#include "qpid/broker/Exchange.h"
#include "qpid/framing/FieldTable.h"
namespace qpid {
@@ -27,48 +29,47 @@ namespace ha {
using types::Variant;
-ReplicateLevel ReplicationTest::replicateLevel(const std::string& str) {
+ReplicateLevel ReplicationTest::getLevel(const std::string& str) {
Enum<ReplicateLevel> rl(replicateDefault);
if (!str.empty()) rl.parse(str);
return rl.get();
}
-ReplicateLevel ReplicationTest::replicateLevel(const framing::FieldTable& f) {
+ReplicateLevel ReplicationTest::getLevel(const framing::FieldTable& f) {
if (f.isSet(QPID_REPLICATE))
- return replicateLevel(f.getAsString(QPID_REPLICATE));
+ return getLevel(f.getAsString(QPID_REPLICATE));
else
return replicateDefault;
}
-ReplicateLevel ReplicationTest::replicateLevel(const Variant::Map& m) {
+ReplicateLevel ReplicationTest::getLevel(const Variant::Map& m) {
Variant::Map::const_iterator i = m.find(QPID_REPLICATE);
if (i != m.end())
- return replicateLevel(i->second.asString());
+ return getLevel(i->second.asString());
else
return replicateDefault;
}
-namespace {
-const std::string AUTO_DELETE_TIMEOUT("qpid.auto_delete_timeout");
+ReplicateLevel ReplicationTest::getLevel(const broker::Queue& q) {
+ const Variant::Map& qmap(q.getSettings().original);
+ Variant::Map::const_iterator i = qmap.find(QPID_REPLICATE);
+ if (i != qmap.end())
+ return getLevel(i->second.asString());
+ else
+ return getLevel(q.getSettings().storeSettings);
}
-bool ReplicationTest::isReplicated(
- ReplicateLevel level, const Variant::Map& args, bool autodelete, bool exclusive)
-{
- bool ignore = autodelete && exclusive && args.find(AUTO_DELETE_TIMEOUT) == args.end();
- return !ignore && replicateLevel(args) >= level;
+ReplicateLevel ReplicationTest::getLevel(const broker::Exchange& ex) {
+ return getLevel(ex.getArgs());
}
-bool ReplicationTest::isReplicated(
- ReplicateLevel level, const framing::FieldTable& args, bool autodelete, bool exclusive)
+ReplicateLevel ReplicationTest::useLevel(const broker::Queue& q)
{
- bool ignore = autodelete && exclusive && !args.isSet(AUTO_DELETE_TIMEOUT);
- return !ignore && replicateLevel(args) >= level;
+ return q.getSettings().isTemporary ? ReplicationTest(NONE).getLevel(q) : getLevel(q);
}
-bool ReplicationTest::isReplicated(ReplicateLevel level, const broker::Queue& q)
-{
- return isReplicated(level, q.getSettings().storeSettings, q.isAutoDelete(), q.hasExclusiveOwner());
+ReplicateLevel ReplicationTest::useLevel(const broker::Exchange& ex) {
+ return ReplicationTest::getLevel(ex);
}
diff --git a/cpp/src/qpid/ha/ReplicationTest.h b/cpp/src/qpid/ha/ReplicationTest.h
index 9f6976a8e4..7d44d82a21 100644
--- a/cpp/src/qpid/ha/ReplicationTest.h
+++ b/cpp/src/qpid/ha/ReplicationTest.h
@@ -30,6 +30,7 @@ namespace qpid {
namespace broker {
class Queue;
+class Exchange;
}
namespace framing {
@@ -47,21 +48,24 @@ class ReplicationTest
ReplicationTest(ReplicateLevel replicateDefault_) :
replicateDefault(replicateDefault_) {}
- // Return the simple replication level, accounting for defaults.
- ReplicateLevel replicateLevel(const std::string& str);
- ReplicateLevel replicateLevel(const framing::FieldTable& f);
- ReplicateLevel replicateLevel(const types::Variant::Map& m);
+ // Get the replication level set on an object, or default if not set.
+ ReplicateLevel getLevel(const std::string& str);
+ ReplicateLevel getLevel(const framing::FieldTable& f);
+ ReplicateLevel getLevel(const types::Variant::Map& m);
+ ReplicateLevel getLevel(const broker::Queue&);
+ ReplicateLevel getLevel(const broker::Exchange&);
+
+ // Calculate level for objects that may not have replication set,
+ // including auto-delete/exclusive settings.
+ ReplicateLevel useLevel(const types::Variant::Map& args, bool autodelete, bool exclusive);
+ ReplicateLevel useLevel(const framing::FieldTable& args, bool autodelete, bool exclusive);
+ ReplicateLevel useLevel(const broker::Queue&);
+ ReplicateLevel useLevel(const broker::Exchange&);
- // Return true if replication for a queue is enabled at level or higher,
- // taking account of default level and queue settings.
- bool isReplicated(ReplicateLevel level,
- const types::Variant::Map& args, bool autodelete, bool exclusive);
- bool isReplicated(ReplicateLevel level,
- const framing::FieldTable& args, bool autodelete, bool exclusive);
- bool isReplicated(ReplicateLevel level, const broker::Queue&);
private:
ReplicateLevel replicateDefault;
};
+
}} // namespace qpid::ha
#endif /*!QPID_HA_REPLICATIONTEST_H*/
diff --git a/cpp/src/qpid/ha/Role.h b/cpp/src/qpid/ha/Role.h
new file mode 100644
index 0000000000..9d6f7cd123
--- /dev/null
+++ b/cpp/src/qpid/ha/Role.h
@@ -0,0 +1,55 @@
+#ifndef QPID_HA_ROLE_H
+#define QPID_HA_ROLE_H
+
+/*
+ *
+ * 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.
+ *
+ */
+
+#include <string>
+
+namespace qpid {
+struct Url;
+
+namespace ha {
+
+/**
+ * A HaBroker has a role, e.g. Primary, Backup, StandAlone.
+ * Role subclasses define the actions of the broker in each role.
+ * The Role interface allows the HaBroker to pass management actions
+ * to be implemented by the role.
+ */
+class Role
+{
+ public:
+ /** Log prefix appropriate to the role */
+ virtual std::string getLogPrefix() const = 0;
+
+ /** QMF promote method handler.
+ * @return The new role if promoted, 0 if not. Caller takes ownership.
+ */
+ virtual Role* promote() = 0;
+
+ virtual void setBrokerUrl(const Url& url) = 0;
+
+ private:
+};
+}} // namespace qpid::ha
+
+#endif /*!QPID_HA_ROLE_H*/
diff --git a/cpp/src/qpid/ha/Settings.h b/cpp/src/qpid/ha/Settings.h
index 37235b5c79..53b61415cf 100644
--- a/cpp/src/qpid/ha/Settings.h
+++ b/cpp/src/qpid/ha/Settings.h
@@ -23,6 +23,7 @@
*/
#include "types.h"
+#include "qpid/sys/IntegerTypes.h"
#include <string>
namespace qpid {
@@ -34,16 +35,25 @@ namespace ha {
class Settings
{
public:
- Settings() : cluster(false), replicateDefault(NONE), backupTimeout(5)
+ Settings() : cluster(false), queueReplication(false),
+ replicateDefault(NONE), backupTimeout(5),
+ flowMessages(100), flowBytes(0)
{}
bool cluster; // True if we are a cluster member.
- std::string clientUrl;
+ bool queueReplication; // True if enabled.
+ std::string publicUrl;
std::string brokerUrl;
Enum<ReplicateLevel> replicateDefault;
std::string username, password, mechanism;
double backupTimeout;
- private:
+
+ uint32_t flowMessages, flowBytes;
+
+ static const uint32_t NO_LIMIT=0xFFFFFFFF;
+ static uint32_t flowValue(uint32_t n) { return n ? n : NO_LIMIT; }
+ uint32_t getFlowMessages() const { return flowValue(flowMessages); }
+ uint32_t getFlowBytes() const { return flowValue(flowBytes); }
};
}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/StandAlone.h b/cpp/src/qpid/ha/StandAlone.h
new file mode 100644
index 0000000000..d052996d40
--- /dev/null
+++ b/cpp/src/qpid/ha/StandAlone.h
@@ -0,0 +1,45 @@
+#ifndef QPID_HA_STANDALONE_H
+#define QPID_HA_STANDALONE_H
+
+/*
+ *
+ * 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.
+ *
+ */
+namespace qpid {
+struct Url;
+
+namespace ha {
+
+/**
+ * Stand-alone role: acts as a stand-alone broker, no clustering.
+ * HA module needed to setting up replication via QMF methods.
+ */
+class StandAlone : public Role
+{
+ public:
+ std::string getLogPrefix() const { return logPrefix; }
+ Role* promote() { return 0; }
+ void setBrokerUrl(const Url&) {}
+
+ private:
+ std::string logPrefix;
+};
+}} // namespace qpid::ha
+
+#endif /*!QPID_HA_STANDALONE_H*/
diff --git a/cpp/src/qpid/ha/StatusCheck.cpp b/cpp/src/qpid/ha/StatusCheck.cpp
new file mode 100644
index 0000000000..17613ce3dd
--- /dev/null
+++ b/cpp/src/qpid/ha/StatusCheck.cpp
@@ -0,0 +1,132 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "StatusCheck.h"
+#include "qpid/log/Statement.h"
+#include "qpid/messaging/Address.h"
+#include "qpid/messaging/Connection.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/messaging/Receiver.h"
+#include "qpid/messaging/Sender.h"
+#include "qpid/messaging/Session.h"
+#include "qpid/types/Variant.h"
+
+namespace qpid {
+namespace ha {
+
+using namespace qpid::messaging;
+using namespace qpid::types;
+using namespace std;
+using namespace sys;
+
+const string HA_BROKER = "org.apache.qpid.ha:habroker:ha-broker";
+
+class StatusCheckThread : public sys::Runnable {
+ public:
+ StatusCheckThread(StatusCheck& sc, const qpid::Address& addr, const BrokerInfo& self)
+ : url(addr), statusCheck(sc), brokerInfo(self) {}
+ void run();
+ private:
+ Url url;
+ StatusCheck& statusCheck;
+ uint16_t linkHeartbeatInterval;
+ BrokerInfo brokerInfo;
+};
+
+void StatusCheckThread::run() {
+ QPID_LOG(debug, statusCheck.logPrefix << "Checking status of " << url);
+ Variant::Map options, clientProperties;
+ clientProperties = brokerInfo.asMap(); // Detect self connections.
+ clientProperties["qpid.ha-admin"] = 1; // Allow connection to backups.
+
+ options["client-properties"] = clientProperties;
+ options["heartbeat"] = statusCheck.linkHeartbeatInterval;
+ Connection c(url.str(), options);
+
+ try {
+ c.open();
+ Session session = c.createSession();
+ messaging::Address responses("#;{create:always,node:{x-declare:{exclusive:True,auto-delete:True,arguments:{'qpid.replicate':none}}}}");
+ Receiver r = session.createReceiver(responses);
+ Sender s = session.createSender("qmf.default.direct/broker");
+ Message request;
+ request.setReplyTo(responses);
+ request.setContentType("amqp/map");
+ request.setProperty("x-amqp-0-10.app-id", "qmf2");
+ request.setProperty("qmf.opcode", "_query_request");
+ Variant::Map oid;
+ oid["_object_name"] = HA_BROKER;
+ Variant::Map content;
+ content["_what"] = "OBJECT";
+ content["_object_id"] = oid;
+ encode(content, request);
+ s.send(request);
+ Message response = r.fetch(statusCheck.linkHeartbeatInterval*Duration::SECOND);
+ session.acknowledge();
+ Variant::List contentIn;
+ decode(response, contentIn);
+ if (contentIn.size() == 1) {
+ Variant::Map details = contentIn.front().asMap()["_values"].asMap();
+ string status = details["status"].getString();
+ if (status != "joining") {
+ statusCheck.setPromote(false);
+ QPID_LOG(info, statusCheck.logPrefix << "Status of " << url << " is "
+ << status << ", this broker will refuse promotion.");
+ }
+ QPID_LOG(debug, statusCheck.logPrefix << "Status of " << url << ": " << status);
+ }
+ } catch(const exception& error) {
+ QPID_LOG(info, "Checking status of " << url << ": " << error.what());
+ }
+ delete this;
+}
+
+StatusCheck::StatusCheck(const string& lp, uint16_t lh, const BrokerInfo& self)
+ : logPrefix(lp), promote(true), linkHeartbeatInterval(lh), brokerInfo(self)
+{}
+
+StatusCheck::~StatusCheck() {
+ // Join any leftovers
+ for (size_t i = 0; i < threads.size(); ++i) threads[i].join();
+}
+
+void StatusCheck::setUrl(const Url& url) {
+ Mutex::ScopedLock l(lock);
+ for (size_t i = 0; i < url.size(); ++i)
+ threads.push_back(Thread(new StatusCheckThread(*this, url[i], brokerInfo)));
+}
+
+bool StatusCheck::canPromote() {
+ Mutex::ScopedLock l(lock);
+ while (!threads.empty()) {
+ Thread t = threads.back();
+ threads.pop_back();
+ Mutex::ScopedUnlock u(lock);
+ t.join();
+ }
+ return promote;
+}
+
+void StatusCheck::setPromote(bool p) {
+ Mutex::ScopedLock l(lock);
+ promote = p;
+}
+
+}} // namespace qpid::ha
diff --git a/cpp/src/qpid/ha/StatusCheck.h b/cpp/src/qpid/ha/StatusCheck.h
new file mode 100644
index 0000000000..997ced4159
--- /dev/null
+++ b/cpp/src/qpid/ha/StatusCheck.h
@@ -0,0 +1,71 @@
+#ifndef QPID_HA_STATUSCHECK_H
+#define QPID_HA_STATUSCHECK_H
+
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "BrokerInfo.h"
+#include "qpid/Url.h"
+#include "qpid/sys/Thread.h"
+#include "qpid/sys/Mutex.h"
+#include "qpid/sys/Runnable.h"
+#include <vector>
+
+namespace qpid {
+namespace ha {
+
+// FIXME aconway 2012-12-21: This solution is incomplete. It will only protect
+// against bad promotion if there are READY brokers when this broker starts.
+// It will not help the situation where brokers became READY after this one starts.
+//
+
+/**
+ * Check whether a JOINING broker can be promoted .
+ *
+ * A JOINING broker can be promoted as long as all the other brokers are also
+ * JOINING. If there are READY brokers in the cluster the JOINING broker should
+ * refuse to promote so that one of the READY brokers can. This situation
+ * only comes about if the primary is dead and no new primary has been promoted.
+ *
+ * THREAD SAFE: setUrl and canPromote are called in arbitrary management threads.
+ */
+class StatusCheck
+{
+ public:
+ StatusCheck(const std::string& logPrefix, uint16_t linkHeartbeatInteval, const BrokerInfo& self);
+ ~StatusCheck();
+ void setUrl(const Url&);
+ bool canPromote();
+
+ private:
+ void setPromote(bool p);
+
+ std::string logPrefix;
+ sys::Mutex lock;
+ std::vector<sys::Thread> threads;
+ bool promote;
+ uint16_t linkHeartbeatInterval;
+ BrokerInfo brokerInfo;
+ friend class StatusCheckThread;
+};
+}} // namespace qpid::ha
+
+#endif /*!QPID_HA_STATUSCHECK_H*/
diff --git a/cpp/src/qpid/ha/types.cpp b/cpp/src/qpid/ha/types.cpp
index 53e2056213..bb4bf83574 100644
--- a/cpp/src/qpid/ha/types.cpp
+++ b/cpp/src/qpid/ha/types.cpp
@@ -33,6 +33,7 @@ namespace ha {
using namespace std;
const string QPID_REPLICATE("qpid.replicate");
+const string QPID_HA_UUID("qpid.ha-uuid");
string EnumBase::str() const {
assert(value < count);
@@ -55,6 +56,11 @@ template <> const char* Enum<ReplicateLevel>::NAMES[] = { "none", "configuration
template <> const size_t Enum<ReplicateLevel>::N = 3;
template <> const char* Enum<BrokerStatus>::NAME = "HA broker status";
+
+// NOTE: Changing status names will have an impact on qpid-ha and
+// the qpidd-primary init script.
+// Don't change them unless you are going to update all dependent code.
+//
template <> const char* Enum<BrokerStatus>::NAMES[] = {
"joining", "catchup", "ready", "recovering", "active", "standalone"
};
diff --git a/cpp/src/qpid/ha/types.h b/cpp/src/qpid/ha/types.h
index 35faf9f624..f8c48afc5a 100644
--- a/cpp/src/qpid/ha/types.h
+++ b/cpp/src/qpid/ha/types.h
@@ -99,6 +99,7 @@ inline bool isBackup(BrokerStatus s) { return !isPrimary(s); }
// String constants.
extern const std::string QPID_REPLICATE;
+extern const std::string QPID_HA_UUID;
/** Define IdSet type, not a typedef so we can overload operator << */
class IdSet : public std::set<types::Uuid> {};
diff --git a/cpp/src/qpid/legacystore/BindingDbt.cpp b/cpp/src/qpid/legacystore/BindingDbt.cpp
new file mode 100644
index 0000000000..a48c156e71
--- /dev/null
+++ b/cpp/src/qpid/legacystore/BindingDbt.cpp
@@ -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.
+ *
+ */
+
+#include "qpid/legacystore/BindingDbt.h"
+
+namespace mrg {
+namespace msgstore {
+
+BindingDbt::BindingDbt(const qpid::broker::PersistableExchange& e, const qpid::broker::PersistableQueue& q, const std::string& k, const qpid::framing::FieldTable& a)
+ : data(new char[encodedSize(e, q, k, a)]),
+ buffer(data, encodedSize(e, q, k, a))
+{
+ buffer.putLongLong(q.getPersistenceId());
+ buffer.putShortString(q.getName());
+ buffer.putShortString(k);
+ buffer.put(a);
+
+ set_data(data);
+ set_size(encodedSize(e, q, k, a));
+}
+
+BindingDbt::~BindingDbt()
+{
+ delete [] data;
+}
+
+uint32_t BindingDbt::encodedSize(const qpid::broker::PersistableExchange& /*not used*/, const qpid::broker::PersistableQueue& q, const std::string& k, const qpid::framing::FieldTable& a)
+{
+ return 8 /*queue id*/ + q.getName().size() + 1 + k.size() + 1 + a.encodedSize();
+}
+
+}}
diff --git a/cpp/src/qpid/legacystore/BindingDbt.h b/cpp/src/qpid/legacystore/BindingDbt.h
new file mode 100644
index 0000000000..63c7cd144e
--- /dev/null
+++ b/cpp/src/qpid/legacystore/BindingDbt.h
@@ -0,0 +1,56 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_BINDINGDBT_H
+#define QPID_LEGACYSTORE_BINDINGDBT_H
+
+#include "db-inc.h"
+#include "qpid/broker/PersistableExchange.h"
+#include "qpid/broker/PersistableQueue.h"
+#include "qpid/framing/Buffer.h"
+#include "qpid/framing/FieldTable.h"
+
+namespace mrg{
+namespace msgstore{
+
+class BindingDbt : public Dbt
+{
+ char* data;
+ qpid::framing::Buffer buffer;
+
+ static uint32_t encodedSize(const qpid::broker::PersistableExchange& e,
+ const qpid::broker::PersistableQueue& q,
+ const std::string& k,
+ const qpid::framing::FieldTable& a);
+
+public:
+ BindingDbt(const qpid::broker::PersistableExchange& e,
+ const qpid::broker::PersistableQueue& q,
+ const std::string& k,
+ const qpid::framing::FieldTable& a);
+
+ virtual ~BindingDbt();
+
+};
+
+}}
+
+#endif // ifndef QPID_LEGACYSTORE_BINDINGDBT_H
diff --git a/cpp/src/qpid/legacystore/BufferValue.cpp b/cpp/src/qpid/legacystore/BufferValue.cpp
new file mode 100644
index 0000000000..fb2c471cd7
--- /dev/null
+++ b/cpp/src/qpid/legacystore/BufferValue.cpp
@@ -0,0 +1,56 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/legacystore/BufferValue.h"
+
+namespace mrg {
+namespace msgstore {
+
+
+
+BufferValue::BufferValue(u_int32_t size, u_int64_t offset)
+ : data(new char[size]),
+ buffer(data, size)
+{
+ set_data(data);
+ set_size(size);
+ set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
+ set_doff(offset);
+ set_dlen(size);
+ set_ulen(size);
+}
+
+BufferValue::BufferValue(const qpid::broker::Persistable& p)
+ : data(new char[p.encodedSize()]),
+ buffer(data, p.encodedSize())
+{
+ p.encode(buffer);
+
+ set_data(data);
+ set_size(p.encodedSize());
+}
+
+BufferValue::~BufferValue()
+{
+ delete [] data;
+}
+
+}}
diff --git a/cpp/src/qpid/legacystore/BufferValue.h b/cpp/src/qpid/legacystore/BufferValue.h
new file mode 100644
index 0000000000..527fbcf577
--- /dev/null
+++ b/cpp/src/qpid/legacystore/BufferValue.h
@@ -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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_BUFFERVALUE_H
+#define QPID_LEGACYSTORE_BUFFERVALUE_H
+
+#include "db-inc.h"
+#include "qpid/broker/Persistable.h"
+#include "qpid/framing/Buffer.h"
+
+namespace mrg{
+namespace msgstore{
+
+class BufferValue : public Dbt
+{
+ char* data;
+
+public:
+ qpid::framing::Buffer buffer;
+
+ BufferValue(u_int32_t size, u_int64_t offset);
+ BufferValue(const qpid::broker::Persistable& p);
+ virtual ~BufferValue();
+};
+
+}}
+
+#endif // ifndef QPID_LEGACYSTORE_BUFFERVALUE_H
diff --git a/cpp/src/qpid/legacystore/Cursor.h b/cpp/src/qpid/legacystore/Cursor.h
new file mode 100644
index 0000000000..0c869c29a0
--- /dev/null
+++ b/cpp/src/qpid/legacystore/Cursor.h
@@ -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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_CURSOR_H
+#define QPID_LEGACYSTORE_CURSOR_H
+
+#include <boost/shared_ptr.hpp>
+#include "db-inc.h"
+
+namespace mrg{
+namespace msgstore{
+
+class Cursor
+{
+ Dbc* cursor;
+public:
+ typedef boost::shared_ptr<Db> db_ptr;
+
+ Cursor() : cursor(0) {}
+ virtual ~Cursor() { if(cursor) cursor->close(); }
+
+ void open(db_ptr db, DbTxn* txn, u_int32_t flags = 0) { db->cursor(txn, &cursor, flags); }
+ void close() { if(cursor) cursor->close(); cursor = 0; }
+ Dbc* get() { return cursor; }
+ Dbc* operator->() { return cursor; }
+ bool next(Dbt& key, Dbt& value) { return cursor->get(&key, &value, DB_NEXT) == 0; }
+ bool current(Dbt& key, Dbt& value) { return cursor->get(&key, &value, DB_CURRENT) == 0; }
+};
+
+}}
+
+#endif // ifndef QPID_LEGACYSTORE_CURSOR_H
diff --git a/cpp/src/qpid/legacystore/DataTokenImpl.cpp b/cpp/src/qpid/legacystore/DataTokenImpl.cpp
new file mode 100644
index 0000000000..796d4c02f0
--- /dev/null
+++ b/cpp/src/qpid/legacystore/DataTokenImpl.cpp
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/legacystore/DataTokenImpl.h"
+
+using namespace mrg::msgstore;
+
+DataTokenImpl::DataTokenImpl():data_tok() {}
+
+DataTokenImpl::~DataTokenImpl() {}
diff --git a/cpp/src/qpid/legacystore/DataTokenImpl.h b/cpp/src/qpid/legacystore/DataTokenImpl.h
new file mode 100644
index 0000000000..e01d471e1b
--- /dev/null
+++ b/cpp/src/qpid/legacystore/DataTokenImpl.h
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_DATATOKENIMPL_H
+#define QPID_LEGACYSTORE_DATATOKENIMPL_H
+
+#include "qpid/legacystore/jrnl/data_tok.h"
+#include "qpid/broker/PersistableMessage.h"
+#include <boost/intrusive_ptr.hpp>
+
+namespace mrg {
+namespace msgstore {
+
+class DataTokenImpl : public journal::data_tok, public qpid::RefCounted
+{
+ private:
+ boost::intrusive_ptr<qpid::broker::PersistableMessage> sourceMsg;
+ public:
+ DataTokenImpl();
+ virtual ~DataTokenImpl();
+
+ inline boost::intrusive_ptr<qpid::broker::PersistableMessage>& getSourceMessage() { return sourceMsg; }
+ inline void setSourceMessage(const boost::intrusive_ptr<qpid::broker::PersistableMessage>& msg) { sourceMsg = msg; }
+};
+
+} // namespace msgstore
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_DATATOKENIMPL_H
diff --git a/cpp/src/qpid/legacystore/IdDbt.cpp b/cpp/src/qpid/legacystore/IdDbt.cpp
new file mode 100644
index 0000000000..d9edaf80e6
--- /dev/null
+++ b/cpp/src/qpid/legacystore/IdDbt.cpp
@@ -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.
+ *
+ */
+
+#include "qpid/legacystore/IdDbt.h"
+
+using namespace mrg::msgstore;
+
+IdDbt::IdDbt() : id(0)
+{
+ init();
+}
+
+IdDbt::IdDbt(u_int64_t _id) : id(_id)
+{
+ init();
+}
+
+void IdDbt::init()
+{
+ set_data(&id);
+ set_size(sizeof(u_int64_t));
+ set_ulen(sizeof(u_int64_t));
+ set_flags(DB_DBT_USERMEM);
+}
diff --git a/cpp/src/qpid/legacystore/IdDbt.h b/cpp/src/qpid/legacystore/IdDbt.h
new file mode 100644
index 0000000000..ecf5922963
--- /dev/null
+++ b/cpp/src/qpid/legacystore/IdDbt.h
@@ -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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_IDDBT_H
+#define QPID_LEGACYSTORE_IDDBT_H
+
+#include "db-inc.h"
+
+namespace mrg{
+namespace msgstore{
+
+class IdDbt : public Dbt
+{
+ void init();
+public:
+ u_int64_t id;
+
+ IdDbt(u_int64_t id);
+ IdDbt();
+};
+
+}}
+
+#endif // ifndef QPID_LEGACYSTORE_IDDBT_H
diff --git a/cpp/src/qpid/legacystore/IdSequence.cpp b/cpp/src/qpid/legacystore/IdSequence.cpp
new file mode 100644
index 0000000000..975b1107e7
--- /dev/null
+++ b/cpp/src/qpid/legacystore/IdSequence.cpp
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/legacystore/IdSequence.h"
+
+using namespace mrg::msgstore;
+using qpid::sys::Mutex;
+
+IdSequence::IdSequence() : id(1) {}
+
+u_int64_t IdSequence::next()
+{
+ Mutex::ScopedLock guard(lock);
+ if (!id) id++; // avoid 0 when folding around
+ return id++;
+}
+
+void IdSequence::reset(uint64_t value)
+{
+ //deliberately not threadsafe, used only on recovery
+ id = value;
+}
diff --git a/cpp/src/qpid/legacystore/IdSequence.h b/cpp/src/qpid/legacystore/IdSequence.h
new file mode 100644
index 0000000000..11d7ff61ca
--- /dev/null
+++ b/cpp/src/qpid/legacystore/IdSequence.h
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_IDSEQUENCE_H
+#define QPID_LEGACYSTORE_IDSEQUENCE_H
+
+#include "qpid/framing/amqp_types.h"
+#include "qpid/sys/Mutex.h"
+#include <sys/types.h>
+
+namespace mrg{
+namespace msgstore{
+
+class IdSequence
+{
+ qpid::sys::Mutex lock;
+ uint64_t id;
+public:
+ IdSequence();
+ uint64_t next();
+ void reset(uint64_t value);
+};
+
+}}
+
+#endif // ifndef QPID_LEGACYSTORE_IDSEQUENCE_H
diff --git a/cpp/src/qpid/legacystore/JournalImpl.cpp b/cpp/src/qpid/legacystore/JournalImpl.cpp
new file mode 100644
index 0000000000..ba3f2aecae
--- /dev/null
+++ b/cpp/src/qpid/legacystore/JournalImpl.cpp
@@ -0,0 +1,633 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/legacystore/JournalImpl.h"
+
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include "qpid/log/Statement.h"
+#include "qpid/management/ManagementAgent.h"
+#include "qmf/org/apache/qpid/legacystore/ArgsJournalExpand.h"
+#include "qmf/org/apache/qpid/legacystore/EventCreated.h"
+#include "qmf/org/apache/qpid/legacystore/EventEnqThresholdExceeded.h"
+#include "qmf/org/apache/qpid/legacystore/EventFull.h"
+#include "qmf/org/apache/qpid/legacystore/EventRecovered.h"
+#include "qpid/sys/Monitor.h"
+#include "qpid/sys/Timer.h"
+#include "qpid/legacystore/StoreException.h"
+
+using namespace mrg::msgstore;
+using namespace mrg::journal;
+using qpid::management::ManagementAgent;
+namespace _qmf = qmf::org::apache::qpid::legacystore;
+
+InactivityFireEvent::InactivityFireEvent(JournalImpl* p, const qpid::sys::Duration timeout):
+ qpid::sys::TimerTask(timeout, "JournalInactive:"+p->id()), _parent(p) {}
+
+void InactivityFireEvent::fire() { qpid::sys::Mutex::ScopedLock sl(_ife_lock); if (_parent) _parent->flushFire(); }
+
+GetEventsFireEvent::GetEventsFireEvent(JournalImpl* p, const qpid::sys::Duration timeout):
+ qpid::sys::TimerTask(timeout, "JournalGetEvents:"+p->id()), _parent(p) {}
+
+void GetEventsFireEvent::fire() { qpid::sys::Mutex::ScopedLock sl(_gefe_lock); if (_parent) _parent->getEventsFire(); }
+
+JournalImpl::JournalImpl(qpid::sys::Timer& timer_,
+ const std::string& journalId,
+ const std::string& journalDirectory,
+ const std::string& journalBaseFilename,
+ const qpid::sys::Duration getEventsTimeout,
+ const qpid::sys::Duration flushTimeout,
+ qpid::management::ManagementAgent* a,
+ DeleteCallback onDelete):
+ jcntl(journalId, journalDirectory, journalBaseFilename),
+ timer(timer_),
+ getEventsTimerSetFlag(false),
+ lastReadRid(0),
+ writeActivityFlag(false),
+ flushTriggeredFlag(true),
+ _xidp(0),
+ _datap(0),
+ _dlen(0),
+ _dtok(),
+ _external(false),
+ deleteCallback(onDelete)
+{
+ getEventsFireEventsPtr = new GetEventsFireEvent(this, getEventsTimeout);
+ inactivityFireEventPtr = new InactivityFireEvent(this, flushTimeout);
+ {
+ timer.start();
+ timer.add(inactivityFireEventPtr);
+ }
+
+ initManagement(a);
+
+ log(LOG_NOTICE, "Created");
+ std::ostringstream oss;
+ oss << "Journal directory = \"" << journalDirectory << "\"; Base file name = \"" << journalBaseFilename << "\"";
+ log(LOG_DEBUG, oss.str());
+}
+
+JournalImpl::~JournalImpl()
+{
+ if (deleteCallback) deleteCallback(*this);
+ if (_init_flag && !_stop_flag){
+ try { stop(true); } // NOTE: This will *block* until all outstanding disk aio calls are complete!
+ catch (const jexception& e) { log(LOG_ERROR, e.what()); }
+ }
+ getEventsFireEventsPtr->cancel();
+ inactivityFireEventPtr->cancel();
+ free_read_buffers();
+
+ if (_mgmtObject.get() != 0) {
+ _mgmtObject->resourceDestroy();
+ _mgmtObject.reset();
+ }
+
+ log(LOG_NOTICE, "Destroyed");
+}
+
+void
+JournalImpl::initManagement(qpid::management::ManagementAgent* a)
+{
+ _agent = a;
+ if (_agent != 0)
+ {
+ _mgmtObject = _qmf::Journal::shared_ptr (
+ new _qmf::Journal(_agent, this));
+
+ _mgmtObject->set_name(_jid);
+ _mgmtObject->set_directory(_jdir.dirname());
+ _mgmtObject->set_baseFileName(_base_filename);
+ _mgmtObject->set_readPageSize(JRNL_RMGR_PAGE_SIZE * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE);
+ _mgmtObject->set_readPages(JRNL_RMGR_PAGES);
+
+ // The following will be set on initialize(), but being properties, these must be set to 0 in the meantime
+ _mgmtObject->set_initialFileCount(0);
+ _mgmtObject->set_dataFileSize(0);
+ _mgmtObject->set_currentFileCount(0);
+ _mgmtObject->set_writePageSize(0);
+ _mgmtObject->set_writePages(0);
+
+ _agent->addObject(_mgmtObject, 0, true);
+ }
+}
+
+
+void
+JournalImpl::initialize(const u_int16_t num_jfiles,
+ const bool auto_expand,
+ const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks,
+ const u_int16_t wcache_num_pages,
+ const u_int32_t wcache_pgsize_sblks,
+ mrg::journal::aio_callback* const cbp)
+{
+ std::ostringstream oss;
+ oss << "Initialize; num_jfiles=" << num_jfiles << " jfsize_sblks=" << jfsize_sblks;
+ oss << " wcache_pgsize_sblks=" << wcache_pgsize_sblks;
+ oss << " wcache_num_pages=" << wcache_num_pages;
+ log(LOG_DEBUG, oss.str());
+ jcntl::initialize(num_jfiles, auto_expand, ae_max_jfiles, jfsize_sblks, wcache_num_pages, wcache_pgsize_sblks, cbp);
+ log(LOG_DEBUG, "Initialization complete");
+
+ if (_mgmtObject.get() != 0)
+ {
+ _mgmtObject->set_initialFileCount(_lpmgr.num_jfiles());
+ _mgmtObject->set_autoExpand(_lpmgr.is_ae());
+ _mgmtObject->set_currentFileCount(_lpmgr.num_jfiles());
+ _mgmtObject->set_maxFileCount(_lpmgr.ae_max_jfiles());
+ _mgmtObject->set_dataFileSize(_jfsize_sblks * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE);
+ _mgmtObject->set_writePageSize(wcache_pgsize_sblks * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE);
+ _mgmtObject->set_writePages(wcache_num_pages);
+ }
+ if (_agent != 0)
+ _agent->raiseEvent(qmf::org::apache::qpid::legacystore::EventCreated(_jid, _jfsize_sblks * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE, _lpmgr.num_jfiles()),
+ qpid::management::ManagementAgent::SEV_NOTE);
+}
+
+void
+JournalImpl::recover(const u_int16_t num_jfiles,
+ const bool auto_expand,
+ const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks,
+ const u_int16_t wcache_num_pages,
+ const u_int32_t wcache_pgsize_sblks,
+ mrg::journal::aio_callback* const cbp,
+ boost::ptr_list<msgstore::PreparedTransaction>* prep_tx_list_ptr,
+ u_int64_t& highest_rid,
+ u_int64_t queue_id)
+{
+ std::ostringstream oss1;
+ oss1 << "Recover; num_jfiles=" << num_jfiles << " jfsize_sblks=" << jfsize_sblks;
+ oss1 << " queue_id = 0x" << std::hex << queue_id << std::dec;
+ oss1 << " wcache_pgsize_sblks=" << wcache_pgsize_sblks;
+ oss1 << " wcache_num_pages=" << wcache_num_pages;
+ log(LOG_DEBUG, oss1.str());
+
+ if (_mgmtObject.get() != 0)
+ {
+ _mgmtObject->set_initialFileCount(_lpmgr.num_jfiles());
+ _mgmtObject->set_autoExpand(_lpmgr.is_ae());
+ _mgmtObject->set_currentFileCount(_lpmgr.num_jfiles());
+ _mgmtObject->set_maxFileCount(_lpmgr.ae_max_jfiles());
+ _mgmtObject->set_dataFileSize(_jfsize_sblks * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE);
+ _mgmtObject->set_writePageSize(wcache_pgsize_sblks * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE);
+ _mgmtObject->set_writePages(wcache_num_pages);
+ }
+
+ if (prep_tx_list_ptr) {
+ // Create list of prepared xids
+ std::vector<std::string> prep_xid_list;
+ for (msgstore::PreparedTransaction::list::iterator i = prep_tx_list_ptr->begin(); i != prep_tx_list_ptr->end(); i++) {
+ prep_xid_list.push_back(i->xid);
+ }
+
+ jcntl::recover(num_jfiles, auto_expand, ae_max_jfiles, jfsize_sblks, wcache_num_pages, wcache_pgsize_sblks,
+ cbp, &prep_xid_list, highest_rid);
+ } else {
+ jcntl::recover(num_jfiles, auto_expand, ae_max_jfiles, jfsize_sblks, wcache_num_pages, wcache_pgsize_sblks,
+ cbp, 0, highest_rid);
+ }
+
+ // Populate PreparedTransaction lists from _tmap
+ if (prep_tx_list_ptr)
+ {
+ for (msgstore::PreparedTransaction::list::iterator i = prep_tx_list_ptr->begin(); i != prep_tx_list_ptr->end(); i++) {
+ txn_data_list tdl = _tmap.get_tdata_list(i->xid); // tdl will be empty if xid not found
+ for (tdl_itr tdl_itr = tdl.begin(); tdl_itr < tdl.end(); tdl_itr++) {
+ if (tdl_itr->_enq_flag) { // enqueue op
+ i->enqueues->add(queue_id, tdl_itr->_rid);
+ } else { // dequeue op
+ i->dequeues->add(queue_id, tdl_itr->_drid);
+ }
+ }
+ }
+ }
+ std::ostringstream oss2;
+ oss2 << "Recover phase 1 complete; highest rid found = 0x" << std::hex << highest_rid;
+ oss2 << std::dec << "; emap.size=" << _emap.size() << "; tmap.size=" << _tmap.size();
+ oss2 << "; journal now read-only.";
+ log(LOG_DEBUG, oss2.str());
+
+ if (_mgmtObject.get() != 0)
+ {
+ _mgmtObject->inc_recordDepth(_emap.size());
+ _mgmtObject->inc_enqueues(_emap.size());
+ _mgmtObject->inc_txn(_tmap.size());
+ _mgmtObject->inc_txnEnqueues(_tmap.enq_cnt());
+ _mgmtObject->inc_txnDequeues(_tmap.deq_cnt());
+ }
+}
+
+void
+JournalImpl::recover_complete()
+{
+ jcntl::recover_complete();
+ log(LOG_DEBUG, "Recover phase 2 complete; journal now writable.");
+ if (_agent != 0)
+ _agent->raiseEvent(qmf::org::apache::qpid::legacystore::EventRecovered(_jid, _jfsize_sblks * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE, _lpmgr.num_jfiles(),
+ _emap.size(), _tmap.size(), _tmap.enq_cnt(), _tmap.deq_cnt()), qpid::management::ManagementAgent::SEV_NOTE);
+}
+
+//#define MAX_AIO_SLEEPS 1000000 // tot: ~10 sec
+//#define AIO_SLEEP_TIME_US 10 // 0.01 ms
+// Return true if content is recovered from store; false if content is external and must be recovered from an external store.
+// Throw exception for all errors.
+bool
+JournalImpl::loadMsgContent(u_int64_t rid, std::string& data, size_t length, size_t offset)
+{
+ qpid::sys::Mutex::ScopedLock sl(_read_lock);
+ if (_dtok.rid() != rid)
+ {
+ // Free any previous msg
+ free_read_buffers();
+
+ // Last read encountered out-of-order rids, check if this rid is in that list
+ bool oooFlag = false;
+ for (std::vector<u_int64_t>::const_iterator i=oooRidList.begin(); i!=oooRidList.end() && !oooFlag; i++) {
+ if (*i == rid) {
+ oooFlag = true;
+ }
+ }
+
+ // TODO: This is a brutal approach - very inefficient and slow. Rather introduce a system of remembering
+ // jumpover points and allow the read to jump back to the first known jumpover point - but this needs
+ // a mechanism in rrfc to accomplish it. Also helpful is a struct containing a journal address - a
+ // combination of lid/offset.
+ // NOTE: The second part of the if stmt (rid < lastReadRid) is required to handle browsing.
+ if (oooFlag || rid < lastReadRid) {
+ _rmgr.invalidate();
+ oooRidList.clear();
+ }
+ _dlen = 0;
+ _dtok.reset();
+ _dtok.set_wstate(DataTokenImpl::ENQ);
+ _dtok.set_rid(0);
+ _external = false;
+ size_t xlen = 0;
+ bool transient = false;
+ bool done = false;
+ bool rid_found = false;
+ while (!done) {
+ iores res = read_data_record(&_datap, _dlen, &_xidp, xlen, transient, _external, &_dtok);
+ switch (res) {
+ case mrg::journal::RHM_IORES_SUCCESS:
+ if (_dtok.rid() != rid) {
+ // Check if this is an out-of-order rid that may impact next read
+ if (_dtok.rid() > rid)
+ oooRidList.push_back(_dtok.rid());
+ free_read_buffers();
+ // Reset data token for next read
+ _dlen = 0;
+ _dtok.reset();
+ _dtok.set_wstate(DataTokenImpl::ENQ);
+ _dtok.set_rid(0);
+ } else {
+ rid_found = _dtok.rid() == rid;
+ lastReadRid = rid;
+ done = true;
+ }
+ break;
+ case mrg::journal::RHM_IORES_PAGE_AIOWAIT:
+ if (get_wr_events(&_aio_cmpl_timeout) == journal::jerrno::AIO_TIMEOUT) {
+ std::stringstream ss;
+ ss << "read_data_record() returned " << mrg::journal::iores_str(res);
+ ss << "; timed out waiting for page to be processed.";
+ throw jexception(mrg::journal::jerrno::JERR__TIMEOUT, ss.str().c_str(), "JournalImpl",
+ "loadMsgContent");
+ }
+ break;
+ default:
+ std::stringstream ss;
+ ss << "read_data_record() returned " << mrg::journal::iores_str(res);
+ throw jexception(mrg::journal::jerrno::JERR__UNEXPRESPONSE, ss.str().c_str(), "JournalImpl",
+ "loadMsgContent");
+ }
+ }
+ if (!rid_found) {
+ std::stringstream ss;
+ ss << "read_data_record() was unable to find rid 0x" << std::hex << rid << std::dec;
+ ss << " (" << rid << "); last rid found was 0x" << std::hex << _dtok.rid() << std::dec;
+ ss << " (" << _dtok.rid() << ")";
+ throw jexception(mrg::journal::jerrno::JERR__RECNFOUND, ss.str().c_str(), "JournalImpl", "loadMsgContent");
+ }
+ }
+
+ if (_external) return false;
+
+ u_int32_t hdr_offs = qpid::framing::Buffer(static_cast<char*>(_datap), sizeof(u_int32_t)).getLong() + sizeof(u_int32_t);
+ if (hdr_offs + offset + length > _dlen) {
+ data.append((const char*)_datap + hdr_offs + offset, _dlen - hdr_offs - offset);
+ } else {
+ data.append((const char*)_datap + hdr_offs + offset, length);
+ }
+ return true;
+}
+
+void
+JournalImpl::enqueue_data_record(const void* const data_buff, const size_t tot_data_len,
+ const size_t this_data_len, data_tok* dtokp, const bool transient)
+{
+ handleIoResult(jcntl::enqueue_data_record(data_buff, tot_data_len, this_data_len, dtokp, transient));
+
+ if (_mgmtObject.get() != 0)
+ {
+ _mgmtObject->inc_enqueues();
+ _mgmtObject->inc_recordDepth();
+ }
+}
+
+void
+JournalImpl::enqueue_extern_data_record(const size_t tot_data_len, data_tok* dtokp,
+ const bool transient)
+{
+ handleIoResult(jcntl::enqueue_extern_data_record(tot_data_len, dtokp, transient));
+
+ if (_mgmtObject.get() != 0)
+ {
+ _mgmtObject->inc_enqueues();
+ _mgmtObject->inc_recordDepth();
+ }
+}
+
+void
+JournalImpl::enqueue_txn_data_record(const void* const data_buff, const size_t tot_data_len,
+ const size_t this_data_len, data_tok* dtokp, const std::string& xid, const bool transient)
+{
+ bool txn_incr = _mgmtObject.get() != 0 ? _tmap.in_map(xid) : false;
+
+ handleIoResult(jcntl::enqueue_txn_data_record(data_buff, tot_data_len, this_data_len, dtokp, xid, transient));
+
+ if (_mgmtObject.get() != 0)
+ {
+ if (!txn_incr) // If this xid was not in _tmap, it will be now...
+ _mgmtObject->inc_txn();
+ _mgmtObject->inc_enqueues();
+ _mgmtObject->inc_txnEnqueues();
+ _mgmtObject->inc_recordDepth();
+ }
+}
+
+void
+JournalImpl::enqueue_extern_txn_data_record(const size_t tot_data_len, data_tok* dtokp,
+ const std::string& xid, const bool transient)
+{
+ bool txn_incr = _mgmtObject.get() != 0 ? _tmap.in_map(xid) : false;
+
+ handleIoResult(jcntl::enqueue_extern_txn_data_record(tot_data_len, dtokp, xid, transient));
+
+ if (_mgmtObject.get() != 0)
+ {
+ if (!txn_incr) // If this xid was not in _tmap, it will be now...
+ _mgmtObject->inc_txn();
+ _mgmtObject->inc_enqueues();
+ _mgmtObject->inc_txnEnqueues();
+ _mgmtObject->inc_recordDepth();
+ }
+}
+
+void
+JournalImpl::dequeue_data_record(data_tok* const dtokp, const bool txn_coml_commit)
+{
+ handleIoResult(jcntl::dequeue_data_record(dtokp, txn_coml_commit));
+
+ if (_mgmtObject.get() != 0)
+ {
+ _mgmtObject->inc_dequeues();
+ _mgmtObject->inc_txnDequeues();
+ _mgmtObject->dec_recordDepth();
+ }
+}
+
+void
+JournalImpl::dequeue_txn_data_record(data_tok* const dtokp, const std::string& xid, const bool txn_coml_commit)
+{
+ bool txn_incr = _mgmtObject.get() != 0 ? _tmap.in_map(xid) : false;
+
+ handleIoResult(jcntl::dequeue_txn_data_record(dtokp, xid, txn_coml_commit));
+
+ if (_mgmtObject.get() != 0)
+ {
+ if (!txn_incr) // If this xid was not in _tmap, it will be now...
+ _mgmtObject->inc_txn();
+ _mgmtObject->inc_dequeues();
+ _mgmtObject->inc_txnDequeues();
+ _mgmtObject->dec_recordDepth();
+ }
+}
+
+void
+JournalImpl::txn_abort(data_tok* const dtokp, const std::string& xid)
+{
+ handleIoResult(jcntl::txn_abort(dtokp, xid));
+
+ if (_mgmtObject.get() != 0)
+ {
+ _mgmtObject->dec_txn();
+ _mgmtObject->inc_txnAborts();
+ }
+}
+
+void
+JournalImpl::txn_commit(data_tok* const dtokp, const std::string& xid)
+{
+ handleIoResult(jcntl::txn_commit(dtokp, xid));
+
+ if (_mgmtObject.get() != 0)
+ {
+ _mgmtObject->dec_txn();
+ _mgmtObject->inc_txnCommits();
+ }
+}
+
+void
+JournalImpl::stop(bool block_till_aio_cmpl)
+{
+ InactivityFireEvent* ifep = dynamic_cast<InactivityFireEvent*>(inactivityFireEventPtr.get());
+ assert(ifep); // dynamic_cast can return null if the cast fails
+ ifep->cancel();
+ jcntl::stop(block_till_aio_cmpl);
+
+ if (_mgmtObject.get() != 0) {
+ _mgmtObject->resourceDestroy();
+ _mgmtObject.reset();
+ }
+}
+
+iores
+JournalImpl::flush(const bool block_till_aio_cmpl)
+{
+ const iores res = jcntl::flush(block_till_aio_cmpl);
+ {
+ qpid::sys::Mutex::ScopedLock sl(_getf_lock);
+ if (_wmgr.get_aio_evt_rem() && !getEventsTimerSetFlag) { setGetEventTimer(); }
+ }
+ return res;
+}
+
+void
+JournalImpl::log(mrg::journal::log_level ll, const std::string& log_stmt) const
+{
+ log(ll, log_stmt.c_str());
+}
+
+void
+JournalImpl::log(mrg::journal::log_level ll, const char* const log_stmt) const
+{
+ switch (ll)
+ {
+ case LOG_TRACE: QPID_LOG(trace, "Journal \"" << _jid << "\": " << log_stmt); break;
+ case LOG_DEBUG: QPID_LOG(debug, "Journal \"" << _jid << "\": " << log_stmt); break;
+ case LOG_INFO: QPID_LOG(info, "Journal \"" << _jid << "\": " << log_stmt); break;
+ case LOG_NOTICE: QPID_LOG(notice, "Journal \"" << _jid << "\": " << log_stmt); break;
+ case LOG_WARN: QPID_LOG(warning, "Journal \"" << _jid << "\": " << log_stmt); break;
+ case LOG_ERROR: QPID_LOG(error, "Journal \"" << _jid << "\": " << log_stmt); break;
+ case LOG_CRITICAL: QPID_LOG(critical, "Journal \"" << _jid << "\": " << log_stmt); break;
+ }
+}
+
+void
+JournalImpl::getEventsFire()
+{
+ qpid::sys::Mutex::ScopedLock sl(_getf_lock);
+ getEventsTimerSetFlag = false;
+ if (_wmgr.get_aio_evt_rem()) { jcntl::get_wr_events(0); }
+ if (_wmgr.get_aio_evt_rem()) { setGetEventTimer(); }
+}
+
+void
+JournalImpl::flushFire()
+{
+ if (writeActivityFlag) {
+ writeActivityFlag = false;
+ flushTriggeredFlag = false;
+ } else {
+ if (!flushTriggeredFlag) {
+ flush();
+ flushTriggeredFlag = true;
+ }
+ }
+ inactivityFireEventPtr->setupNextFire();
+ {
+ timer.add(inactivityFireEventPtr);
+ }
+}
+
+void
+JournalImpl::wr_aio_cb(std::vector<data_tok*>& dtokl)
+{
+ for (std::vector<data_tok*>::const_iterator i=dtokl.begin(); i!=dtokl.end(); i++)
+ {
+ DataTokenImpl* dtokp = static_cast<DataTokenImpl*>(*i);
+ if (/*!is_stopped() &&*/ dtokp->getSourceMessage())
+ {
+ switch (dtokp->wstate())
+ {
+ case data_tok::ENQ:
+ dtokp->getSourceMessage()->enqueueComplete();
+ break;
+ case data_tok::DEQ:
+/* Don't need to signal until we have a way to ack completion of dequeue in AMQP
+ dtokp->getSourceMessage()->dequeueComplete();
+ if ( dtokp->getSourceMessage()->isDequeueComplete() ) // clear id after last dequeue
+ dtokp->getSourceMessage()->setPersistenceId(0);
+*/
+ break;
+ default: ;
+ }
+ }
+ dtokp->release();
+ }
+}
+
+void
+JournalImpl::rd_aio_cb(std::vector<u_int16_t>& /*pil*/)
+{}
+
+void
+JournalImpl::free_read_buffers()
+{
+ if (_xidp) {
+ ::free(_xidp);
+ _xidp = 0;
+ _datap = 0;
+ } else if (_datap) {
+ ::free(_datap);
+ _datap = 0;
+ }
+}
+
+void
+JournalImpl::handleIoResult(const iores r)
+{
+ writeActivityFlag = true;
+ switch (r)
+ {
+ case mrg::journal::RHM_IORES_SUCCESS:
+ return;
+ case mrg::journal::RHM_IORES_ENQCAPTHRESH:
+ {
+ std::ostringstream oss;
+ oss << "Enqueue capacity threshold exceeded on queue \"" << _jid << "\".";
+ log(LOG_WARN, oss.str());
+ if (_agent != 0)
+ _agent->raiseEvent(qmf::org::apache::qpid::legacystore::EventEnqThresholdExceeded(_jid, "Journal enqueue capacity threshold exceeded"),
+ qpid::management::ManagementAgent::SEV_WARN);
+ THROW_STORE_FULL_EXCEPTION(oss.str());
+ }
+ case mrg::journal::RHM_IORES_FULL:
+ {
+ std::ostringstream oss;
+ oss << "Journal full on queue \"" << _jid << "\".";
+ log(LOG_CRITICAL, oss.str());
+ if (_agent != 0)
+ _agent->raiseEvent(qmf::org::apache::qpid::legacystore::EventFull(_jid, "Journal full"), qpid::management::ManagementAgent::SEV_ERROR);
+ THROW_STORE_FULL_EXCEPTION(oss.str());
+ }
+ default:
+ {
+ std::ostringstream oss;
+ oss << "Unexpected I/O response (" << mrg::journal::iores_str(r) << ") on queue " << _jid << "\".";
+ log(LOG_ERROR, oss.str());
+ THROW_STORE_FULL_EXCEPTION(oss.str());
+ }
+ }
+}
+
+qpid::management::Manageable::status_t JournalImpl::ManagementMethod (uint32_t methodId,
+ qpid::management::Args& /*args*/,
+ std::string& /*text*/)
+{
+ Manageable::status_t status = Manageable::STATUS_UNKNOWN_METHOD;
+
+ switch (methodId)
+ {
+ case _qmf::Journal::METHOD_EXPAND :
+ //_qmf::ArgsJournalExpand& eArgs = (_qmf::ArgsJournalExpand&) args;
+
+ // Implement "expand" using eArgs.i_by (expand-by argument)
+
+ status = Manageable::STATUS_NOT_IMPLEMENTED;
+ break;
+ }
+
+ return status;
+}
diff --git a/cpp/src/qpid/legacystore/JournalImpl.h b/cpp/src/qpid/legacystore/JournalImpl.h
new file mode 100644
index 0000000000..7227b2ffd4
--- /dev/null
+++ b/cpp/src/qpid/legacystore/JournalImpl.h
@@ -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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_JOURNALIMPL_H
+#define QPID_LEGACYSTORE_JOURNALIMPL_H
+
+#include <set>
+#include "qpid/legacystore/jrnl/enums.h"
+#include "qpid/legacystore/jrnl/jcntl.h"
+#include "qpid/legacystore/DataTokenImpl.h"
+#include "qpid/legacystore/PreparedTransaction.h"
+#include "qpid/broker/PersistableQueue.h"
+#include "qpid/sys/Timer.h"
+#include "qpid/sys/Time.h"
+#include <boost/ptr_container/ptr_list.hpp>
+#include <boost/intrusive_ptr.hpp>
+#include "qpid/management/Manageable.h"
+#include "qmf/org/apache/qpid/legacystore/Journal.h"
+
+namespace qpid { namespace sys {
+class Timer;
+}}
+
+namespace mrg {
+namespace msgstore {
+
+class JournalImpl;
+
+class InactivityFireEvent : public qpid::sys::TimerTask
+{
+ JournalImpl* _parent;
+ qpid::sys::Mutex _ife_lock;
+
+ public:
+ InactivityFireEvent(JournalImpl* p, const qpid::sys::Duration timeout);
+ virtual ~InactivityFireEvent() {}
+ void fire();
+ inline void cancel() { qpid::sys::Mutex::ScopedLock sl(_ife_lock); _parent = 0; }
+};
+
+class GetEventsFireEvent : public qpid::sys::TimerTask
+{
+ JournalImpl* _parent;
+ qpid::sys::Mutex _gefe_lock;
+
+ public:
+ GetEventsFireEvent(JournalImpl* p, const qpid::sys::Duration timeout);
+ virtual ~GetEventsFireEvent() {}
+ void fire();
+ inline void cancel() { qpid::sys::Mutex::ScopedLock sl(_gefe_lock); _parent = 0; }
+};
+
+class JournalImpl : public qpid::broker::ExternalQueueStore, public mrg::journal::jcntl, public mrg::journal::aio_callback
+{
+ public:
+ typedef boost::function<void (JournalImpl&)> DeleteCallback;
+
+ private:
+// static qpid::sys::Mutex _static_lock;
+// static u_int32_t cnt;
+
+ qpid::sys::Timer& timer;
+ bool getEventsTimerSetFlag;
+ boost::intrusive_ptr<qpid::sys::TimerTask> getEventsFireEventsPtr;
+ qpid::sys::Mutex _getf_lock;
+ qpid::sys::Mutex _read_lock;
+
+ u_int64_t lastReadRid; // rid of last read msg for loadMsgContent() - detects out-of-order read requests
+ std::vector<u_int64_t> oooRidList; // list of out-of-order rids (greater than current rid) encountered during read sequence
+
+ bool writeActivityFlag;
+ bool flushTriggeredFlag;
+ boost::intrusive_ptr<qpid::sys::TimerTask> inactivityFireEventPtr;
+
+ // temp local vars for loadMsgContent below
+ void* _xidp;
+ void* _datap;
+ size_t _dlen;
+ mrg::journal::data_tok _dtok;
+ bool _external;
+
+ qpid::management::ManagementAgent* _agent;
+ qmf::org::apache::qpid::legacystore::Journal::shared_ptr _mgmtObject;
+ DeleteCallback deleteCallback;
+
+ public:
+
+ JournalImpl(qpid::sys::Timer& timer,
+ const std::string& journalId,
+ const std::string& journalDirectory,
+ const std::string& journalBaseFilename,
+ const qpid::sys::Duration getEventsTimeout,
+ const qpid::sys::Duration flushTimeout,
+ qpid::management::ManagementAgent* agent,
+ DeleteCallback deleteCallback=DeleteCallback() );
+
+ virtual ~JournalImpl();
+
+ void initManagement(qpid::management::ManagementAgent* agent);
+
+ void initialize(const u_int16_t num_jfiles,
+ const bool auto_expand,
+ const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks,
+ const u_int16_t wcache_num_pages,
+ const u_int32_t wcache_pgsize_sblks,
+ mrg::journal::aio_callback* const cbp);
+
+ inline void initialize(const u_int16_t num_jfiles,
+ const bool auto_expand,
+ const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks,
+ const u_int16_t wcache_num_pages,
+ const u_int32_t wcache_pgsize_sblks) {
+ initialize(num_jfiles, auto_expand, ae_max_jfiles, jfsize_sblks, wcache_num_pages, wcache_pgsize_sblks,
+ this);
+ }
+
+ void recover(const u_int16_t num_jfiles,
+ const bool auto_expand,
+ const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks,
+ const u_int16_t wcache_num_pages,
+ const u_int32_t wcache_pgsize_sblks,
+ mrg::journal::aio_callback* const cbp,
+ boost::ptr_list<msgstore::PreparedTransaction>* prep_tx_list_ptr,
+ u_int64_t& highest_rid,
+ u_int64_t queue_id);
+
+ inline void recover(const u_int16_t num_jfiles,
+ const bool auto_expand,
+ const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks,
+ const u_int16_t wcache_num_pages,
+ const u_int32_t wcache_pgsize_sblks,
+ boost::ptr_list<msgstore::PreparedTransaction>* prep_tx_list_ptr,
+ u_int64_t& highest_rid,
+ u_int64_t queue_id) {
+ recover(num_jfiles, auto_expand, ae_max_jfiles, jfsize_sblks, wcache_num_pages, wcache_pgsize_sblks,
+ this, prep_tx_list_ptr, highest_rid, queue_id);
+ }
+
+ void recover_complete();
+
+ // Temporary fn to read and save last msg read from journal so it can be assigned
+ // in chunks. To be replaced when coding to do this direct from the journal is ready.
+ // Returns true if the record is extern, false if local.
+ bool loadMsgContent(u_int64_t rid, std::string& data, size_t length, size_t offset = 0);
+
+ // Overrides for write inactivity timer
+ void enqueue_data_record(const void* const data_buff, const size_t tot_data_len,
+ const size_t this_data_len, mrg::journal::data_tok* dtokp,
+ const bool transient = false);
+
+ void enqueue_extern_data_record(const size_t tot_data_len, mrg::journal::data_tok* dtokp,
+ const bool transient = false);
+
+ void enqueue_txn_data_record(const void* const data_buff, const size_t tot_data_len,
+ const size_t this_data_len, mrg::journal::data_tok* dtokp, const std::string& xid,
+ const bool transient = false);
+
+ void enqueue_extern_txn_data_record(const size_t tot_data_len, mrg::journal::data_tok* dtokp,
+ const std::string& xid, const bool transient = false);
+
+ void dequeue_data_record(mrg::journal::data_tok* const dtokp, const bool txn_coml_commit = false);
+
+ void dequeue_txn_data_record(mrg::journal::data_tok* const dtokp, const std::string& xid, const bool txn_coml_commit = false);
+
+ void txn_abort(mrg::journal::data_tok* const dtokp, const std::string& xid);
+
+ void txn_commit(mrg::journal::data_tok* const dtokp, const std::string& xid);
+
+ void stop(bool block_till_aio_cmpl = false);
+
+ // Logging
+ void log(mrg::journal::log_level level, const std::string& log_stmt) const;
+ void log(mrg::journal::log_level level, const char* const log_stmt) const;
+
+ // Overrides for get_events timer
+ mrg::journal::iores flush(const bool block_till_aio_cmpl = false);
+
+ // TimerTask callback
+ void getEventsFire();
+ void flushFire();
+
+ // AIO callbacks
+ virtual void wr_aio_cb(std::vector<mrg::journal::data_tok*>& dtokl);
+ virtual void rd_aio_cb(std::vector<u_int16_t>& pil);
+
+ qpid::management::ManagementObject::shared_ptr GetManagementObject (void) const
+ { return _mgmtObject; }
+
+ qpid::management::Manageable::status_t ManagementMethod (uint32_t,
+ qpid::management::Args&,
+ std::string&);
+
+ void resetDeleteCallback() { deleteCallback = DeleteCallback(); }
+
+ private:
+ void free_read_buffers();
+
+ inline void setGetEventTimer()
+ {
+ getEventsFireEventsPtr->setupNextFire();
+ timer.add(getEventsFireEventsPtr);
+ getEventsTimerSetFlag = true;
+ }
+ void handleIoResult(const mrg::journal::iores r);
+
+ // Management instrumentation callbacks overridden from jcntl
+ inline void instr_incr_outstanding_aio_cnt() {
+ if (_mgmtObject.get() != 0) _mgmtObject->inc_outstandingAIOs();
+ }
+ inline void instr_decr_outstanding_aio_cnt() {
+ if (_mgmtObject.get() != 0) _mgmtObject->dec_outstandingAIOs();
+ }
+
+}; // class JournalImpl
+
+class TplJournalImpl : public JournalImpl
+{
+ public:
+ TplJournalImpl(qpid::sys::Timer& timer,
+ const std::string& journalId,
+ const std::string& journalDirectory,
+ const std::string& journalBaseFilename,
+ const qpid::sys::Duration getEventsTimeout,
+ const qpid::sys::Duration flushTimeout,
+ qpid::management::ManagementAgent* agent) :
+ JournalImpl(timer, journalId, journalDirectory, journalBaseFilename, getEventsTimeout, flushTimeout, agent)
+ {}
+
+ virtual ~TplJournalImpl() {}
+
+ // Special version of read_data_record that ignores transactions - needed when reading the TPL
+ inline mrg::journal::iores read_data_record(void** const datapp, std::size_t& dsize,
+ void** const xidpp, std::size_t& xidsize, bool& transient, bool& external,
+ mrg::journal::data_tok* const dtokp) {
+ return JournalImpl::read_data_record(datapp, dsize, xidpp, xidsize, transient, external, dtokp, true);
+ }
+ inline void read_reset() { _rmgr.invalidate(); }
+}; // class TplJournalImpl
+
+} // namespace msgstore
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JOURNALIMPL_H
diff --git a/cpp/src/qpid/legacystore/MessageStoreImpl.cpp b/cpp/src/qpid/legacystore/MessageStoreImpl.cpp
new file mode 100644
index 0000000000..69e9f48a17
--- /dev/null
+++ b/cpp/src/qpid/legacystore/MessageStoreImpl.cpp
@@ -0,0 +1,1732 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/legacystore/MessageStoreImpl.h"
+
+#include "qpid/legacystore/BindingDbt.h"
+#include "qpid/legacystore/BufferValue.h"
+#include "qpid/legacystore/IdDbt.h"
+#include "qpid/legacystore/jrnl/txn_map.h"
+#include "qpid/framing/FieldValue.h"
+#include "qpid/log/Statement.h"
+#include "qmf/org/apache/qpid/legacystore/Package.h"
+#include "qpid/legacystore/StoreException.h"
+#include <dirent.h>
+#include <db.h>
+
+#define MAX_AIO_SLEEPS 100000 // tot: ~1 sec
+#define AIO_SLEEP_TIME_US 10 // 0.01 ms
+
+namespace _qmf = qmf::org::apache::qpid::legacystore;
+
+namespace mrg {
+namespace msgstore {
+
+
+const std::string MessageStoreImpl::storeTopLevelDir("rhm"); // Sets the top-level store dir name
+// FIXME aconway 2010-03-09: was 10
+qpid::sys::Duration MessageStoreImpl::defJournalGetEventsTimeout(1 * qpid::sys::TIME_MSEC); // 10ms
+qpid::sys::Duration MessageStoreImpl::defJournalFlushTimeout(500 * qpid::sys::TIME_MSEC); // 0.5s
+qpid::sys::Mutex TxnCtxt::globalSerialiser;
+
+MessageStoreImpl::TplRecoverStruct::TplRecoverStruct(const u_int64_t _rid,
+ const bool _deq_flag,
+ const bool _commit_flag,
+ const bool _tpc_flag) :
+ rid(_rid),
+ deq_flag(_deq_flag),
+ commit_flag(_commit_flag),
+ tpc_flag(_tpc_flag)
+{}
+
+MessageStoreImpl::MessageStoreImpl(qpid::broker::Broker* broker_, const char* envpath) :
+ numJrnlFiles(0),
+ autoJrnlExpand(false),
+ autoJrnlExpandMaxFiles(0),
+ jrnlFsizeSblks(0),
+ truncateFlag(false),
+ wCachePgSizeSblks(0),
+ wCacheNumPages(0),
+ tplNumJrnlFiles(0),
+ tplJrnlFsizeSblks(0),
+ tplWCachePgSizeSblks(0),
+ tplWCacheNumPages(0),
+ highestRid(0),
+ isInit(false),
+ envPath(envpath),
+ broker(broker_),
+ mgmtObject(),
+ agent(0)
+{}
+
+u_int16_t MessageStoreImpl::chkJrnlNumFilesParam(const u_int16_t param, const std::string paramName)
+{
+ u_int16_t p = param;
+ if (p < JRNL_MIN_NUM_FILES) {
+ p = JRNL_MIN_NUM_FILES;
+ QPID_LOG(warning, "parameter " << paramName << " (" << param << ") is below allowable minimum (" << JRNL_MIN_NUM_FILES << "); changing this parameter to minimum value.");
+ } else if (p > JRNL_MAX_NUM_FILES) {
+ p = JRNL_MAX_NUM_FILES;
+ QPID_LOG(warning, "parameter " << paramName << " (" << param << ") is above allowable maximum (" << JRNL_MAX_NUM_FILES << "); changing this parameter to maximum value.");
+ }
+ return p;
+}
+
+u_int32_t MessageStoreImpl::chkJrnlFileSizeParam(const u_int32_t param, const std::string paramName, const u_int32_t wCachePgSizeSblks)
+{
+ u_int32_t p = param;
+ u_int32_t min = JRNL_MIN_FILE_SIZE / JRNL_RMGR_PAGE_SIZE;
+ u_int32_t max = JRNL_MAX_FILE_SIZE / JRNL_RMGR_PAGE_SIZE;
+ if (p < min) {
+ p = min;
+ QPID_LOG(warning, "parameter " << paramName << " (" << param << ") is below allowable minimum (" << min << "); changing this parameter to minimum value.");
+ } else if (p > max) {
+ p = max;
+ QPID_LOG(warning, "parameter " << paramName << " (" << param << ") is above allowable maximum (" << max << "); changing this parameter to maximum value.");
+ }
+ if (wCachePgSizeSblks > p * JRNL_RMGR_PAGE_SIZE) {
+ std::ostringstream oss;
+ oss << "Cannot create store with file size less than write page cache size. [file size = " << p << " (" << (p * JRNL_RMGR_PAGE_SIZE / 2) << " kB); write page cache = " << (wCachePgSizeSblks / 2) << " kB]";
+ THROW_STORE_EXCEPTION(oss.str());
+ }
+ return p;
+}
+
+u_int32_t MessageStoreImpl::chkJrnlWrPageCacheSize(const u_int32_t param, const std::string paramName, const u_int16_t jrnlFsizePgs)
+{
+ u_int32_t p = param;
+ switch (p)
+ {
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ case 16:
+ case 32:
+ case 64:
+ case 128:
+ if (jrnlFsizePgs == 1) {
+ p = 64;
+ QPID_LOG(warning, "parameter " << paramName << " (" << param << ") cannot set a page size greater than the journal file size; changing this parameter to the journal file size (" << p << ")");
+ }
+ break;
+ default:
+ if (p == 0) {
+ // For zero value, use default
+ p = JRNL_WMGR_DEF_PAGE_SIZE * JRNL_DBLK_SIZE * JRNL_SBLK_SIZE / 1024;
+ QPID_LOG(warning, "parameter " << paramName << " (" << param << ") must be a power of 2 between 1 and 128; changing this parameter to default value (" << p << ")");
+ } else {
+ // For any positive value, use closest value
+ if (p < 6) p = 4;
+ else if (p < 12) p = 8;
+ else if (p < 24) p = 16;
+ else if (p < 48) p = 32;
+ else if (p < 96) p = 64;
+ else p = 128;
+ QPID_LOG(warning, "parameter " << paramName << " (" << param << ") must be a power of 2 between 1 and 128; changing this parameter to closest allowable value (" << p << ")");
+ }
+ }
+ return p;
+}
+
+u_int16_t MessageStoreImpl::getJrnlWrNumPages(const u_int32_t wrPageSizeKib)
+{
+ u_int32_t wrPageSizeSblks = wrPageSizeKib * 1024 / JRNL_DBLK_SIZE / JRNL_SBLK_SIZE; // convert from KiB to number sblks
+ u_int32_t defTotWCacheSize = JRNL_WMGR_DEF_PAGE_SIZE * JRNL_WMGR_DEF_PAGES; // in sblks. Currently 2014 sblks (1 MiB).
+ switch (wrPageSizeKib)
+ {
+ case 1:
+ case 2:
+ case 4:
+ // 256 KiB total cache
+ return defTotWCacheSize / wrPageSizeSblks / 4;
+ case 8:
+ case 16:
+ // 512 KiB total cache
+ return defTotWCacheSize / wrPageSizeSblks / 2;
+ default: // 32, 64, 128
+ // 1 MiB total cache
+ return defTotWCacheSize / wrPageSizeSblks;
+ }
+}
+
+void MessageStoreImpl::chkJrnlAutoExpandOptions(const StoreOptions* opts,
+ bool& autoJrnlExpand,
+ u_int16_t& autoJrnlExpandMaxFiles,
+ const std::string& autoJrnlExpandMaxFilesParamName,
+ const u_int16_t numJrnlFiles,
+ const std::string& numJrnlFilesParamName)
+{
+ if (!opts->autoJrnlExpand) {
+ // auto-expand disabled
+ autoJrnlExpand = false;
+ autoJrnlExpandMaxFiles = 0;
+ return;
+ }
+ u_int16_t p = opts->autoJrnlExpandMaxFiles;
+ if (numJrnlFiles == JRNL_MAX_NUM_FILES) {
+ // num-jfiles at max; disable auto-expand
+ autoJrnlExpand = false;
+ autoJrnlExpandMaxFiles = 0;
+ QPID_LOG(warning, "parameter " << autoJrnlExpandMaxFilesParamName << " (" << p << ") must be higher than parameter "
+ << numJrnlFilesParamName << " (" << numJrnlFiles << ") which is at the maximum allowable value; disabling auto-expand.");
+ return;
+ }
+ if (p > JRNL_MAX_NUM_FILES) {
+ // auto-expand-max-jfiles higher than max allowable, adjust
+ autoJrnlExpand = true;
+ autoJrnlExpandMaxFiles = JRNL_MAX_NUM_FILES;
+ QPID_LOG(warning, "parameter " << autoJrnlExpandMaxFilesParamName << " (" << p << ") is above allowable maximum ("
+ << JRNL_MAX_NUM_FILES << "); changing this parameter to maximum value.");
+ return;
+ }
+ if (p && p == defAutoJrnlExpandMaxFiles && numJrnlFiles != defTplNumJrnlFiles) {
+ // num-jfiles is different from the default AND max-auto-expand-jfiles is still at default
+ // change value of max-auto-expand-jfiles
+ autoJrnlExpand = true;
+ if (2 * numJrnlFiles <= JRNL_MAX_NUM_FILES) {
+ autoJrnlExpandMaxFiles = 2 * numJrnlFiles <= JRNL_MAX_NUM_FILES ? 2 * numJrnlFiles : JRNL_MAX_NUM_FILES;
+ QPID_LOG(warning, "parameter " << autoJrnlExpandMaxFilesParamName << " adjusted from its default value ("
+ << defAutoJrnlExpandMaxFiles << ") to twice that of parameter " << numJrnlFilesParamName << " (" << autoJrnlExpandMaxFiles << ").");
+ } else {
+ autoJrnlExpandMaxFiles = 2 * numJrnlFiles <= JRNL_MAX_NUM_FILES ? 2 * numJrnlFiles : JRNL_MAX_NUM_FILES;
+ QPID_LOG(warning, "parameter " << autoJrnlExpandMaxFilesParamName << " adjusted from its default to maximum allowable value ("
+ << JRNL_MAX_NUM_FILES << ") because of the value of " << numJrnlFilesParamName << " (" << numJrnlFiles << ").");
+ }
+ return;
+ }
+ // No adjustments req'd, set values
+ autoJrnlExpand = true;
+ autoJrnlExpandMaxFiles = p;
+}
+
+void MessageStoreImpl::initManagement ()
+{
+ if (broker != 0) {
+ agent = broker->getManagementAgent();
+ if (agent != 0) {
+ _qmf::Package packageInitializer(agent);
+ mgmtObject = _qmf::Store::shared_ptr (
+ new _qmf::Store(agent, this, broker));
+
+ mgmtObject->set_location(storeDir);
+ mgmtObject->set_defaultInitialFileCount(numJrnlFiles);
+ mgmtObject->set_defaultDataFileSize(jrnlFsizeSblks / JRNL_RMGR_PAGE_SIZE);
+ mgmtObject->set_tplIsInitialized(false);
+ mgmtObject->set_tplDirectory(getTplBaseDir());
+ mgmtObject->set_tplWritePageSize(tplWCachePgSizeSblks * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE);
+ mgmtObject->set_tplWritePages(tplWCacheNumPages);
+ mgmtObject->set_tplInitialFileCount(tplNumJrnlFiles);
+ mgmtObject->set_tplDataFileSize(tplJrnlFsizeSblks * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE);
+ mgmtObject->set_tplCurrentFileCount(tplNumJrnlFiles);
+
+ agent->addObject(mgmtObject, 0, true);
+
+ // Initialize all existing queues (ie those recovered before management was initialized)
+ for (JournalListMapItr i=journalList.begin(); i!=journalList.end(); i++) {
+ i->second->initManagement(agent);
+ }
+ }
+ }
+}
+
+bool MessageStoreImpl::init(const qpid::Options* options)
+{
+ // Extract and check options
+ const StoreOptions* opts = static_cast<const StoreOptions*>(options);
+ u_int16_t numJrnlFiles = chkJrnlNumFilesParam(opts->numJrnlFiles, "num-jfiles");
+ u_int32_t jrnlFsizePgs = chkJrnlFileSizeParam(opts->jrnlFsizePgs, "jfile-size-pgs");
+ u_int32_t jrnlWrCachePageSizeKib = chkJrnlWrPageCacheSize(opts->wCachePageSizeKib, "wcache-page-size", jrnlFsizePgs);
+ u_int16_t tplNumJrnlFiles = chkJrnlNumFilesParam(opts->tplNumJrnlFiles, "tpl-num-jfiles");
+ u_int32_t tplJrnlFSizePgs = chkJrnlFileSizeParam(opts->tplJrnlFsizePgs, "tpl-jfile-size-pgs");
+ u_int32_t tplJrnlWrCachePageSizeKib = chkJrnlWrPageCacheSize(opts->tplWCachePageSizeKib, "tpl-wcache-page-size", tplJrnlFSizePgs);
+ bool autoJrnlExpand;
+ u_int16_t autoJrnlExpandMaxFiles;
+ chkJrnlAutoExpandOptions(opts, autoJrnlExpand, autoJrnlExpandMaxFiles, "auto-expand-max-jfiles", numJrnlFiles, "num-jfiles");
+
+ // Pass option values to init(...)
+ return init(opts->storeDir, numJrnlFiles, jrnlFsizePgs, opts->truncateFlag, jrnlWrCachePageSizeKib, tplNumJrnlFiles, tplJrnlFSizePgs, tplJrnlWrCachePageSizeKib, autoJrnlExpand, autoJrnlExpandMaxFiles);
+}
+
+// These params, taken from options, are assumed to be correct and verified
+bool MessageStoreImpl::init(const std::string& dir,
+ u_int16_t jfiles,
+ u_int32_t jfileSizePgs,
+ const bool truncateFlag,
+ u_int32_t wCachePageSizeKib,
+ u_int16_t tplJfiles,
+ u_int32_t tplJfileSizePgs,
+ u_int32_t tplWCachePageSizeKib,
+ bool autoJExpand,
+ u_int16_t autoJExpandMaxFiles)
+{
+ if (isInit) return true;
+
+ // Set geometry members (converting to correct units where req'd)
+ numJrnlFiles = jfiles;
+ jrnlFsizeSblks = jfileSizePgs * JRNL_RMGR_PAGE_SIZE;
+ wCachePgSizeSblks = wCachePageSizeKib * 1024 / JRNL_DBLK_SIZE / JRNL_SBLK_SIZE; // convert from KiB to number sblks
+ wCacheNumPages = getJrnlWrNumPages(wCachePageSizeKib);
+ tplNumJrnlFiles = tplJfiles;
+ tplJrnlFsizeSblks = tplJfileSizePgs * JRNL_RMGR_PAGE_SIZE;
+ tplWCachePgSizeSblks = tplWCachePageSizeKib * 1024 / JRNL_DBLK_SIZE / JRNL_SBLK_SIZE; // convert from KiB to number sblks
+ tplWCacheNumPages = getJrnlWrNumPages(tplWCachePageSizeKib);
+ autoJrnlExpand = autoJExpand;
+ autoJrnlExpandMaxFiles = autoJExpandMaxFiles;
+ if (dir.size()>0) storeDir = dir;
+
+ if (truncateFlag)
+ truncateInit(false);
+ else
+ init();
+
+ QPID_LOG(notice, "Store module initialized; store-dir=" << dir);
+ QPID_LOG(info, "> Default files per journal: " << jfiles);
+// TODO: Uncomment these lines when auto-expand is enabled.
+// QPID_LOG(info, "> Auto-expand " << (autoJrnlExpand ? "enabled" : "disabled"));
+// if (autoJrnlExpand) QPID_LOG(info, "> Max auto-expand journal files: " << autoJrnlExpandMaxFiles);
+ QPID_LOG(info, "> Default journal file size: " << jfileSizePgs << " (wpgs)");
+ QPID_LOG(info, "> Default write cache page size: " << wCachePageSizeKib << " (KiB)");
+ QPID_LOG(info, "> Default number of write cache pages: " << wCacheNumPages);
+ QPID_LOG(info, "> TPL files per journal: " << tplNumJrnlFiles);
+ QPID_LOG(info, "> TPL journal file size: " << tplJfileSizePgs << " (wpgs)");
+ QPID_LOG(info, "> TPL write cache page size: " << tplWCachePageSizeKib << " (KiB)");
+ QPID_LOG(info, "> TPL number of write cache pages: " << tplWCacheNumPages);
+
+ return isInit;
+}
+
+void MessageStoreImpl::init()
+{
+ const int retryMax = 3;
+ int bdbRetryCnt = 0;
+ do {
+ if (bdbRetryCnt++ > 0)
+ {
+ closeDbs();
+ ::usleep(1000000); // 1 sec delay
+ QPID_LOG(error, "Previoius BDB store initialization failed, retrying (" << bdbRetryCnt << " of " << retryMax << ")...");
+ }
+
+ try {
+ journal::jdir::create_dir(getBdbBaseDir());
+
+ dbenv.reset(new DbEnv(0));
+ dbenv->set_errpfx("msgstore");
+ dbenv->set_lg_regionmax(256000); // default = 65000
+ dbenv->open(getBdbBaseDir().c_str(), DB_THREAD | DB_CREATE | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_USE_ENVIRON | DB_RECOVER, 0);
+
+ // Databases are constructed here instead of the constructor so that the DB_RECOVER flag can be used
+ // against the database environment. Recover can only be performed if no databases have been created
+ // against the environment at the time of recovery, as recovery invalidates the environment.
+ queueDb.reset(new Db(dbenv.get(), 0));
+ dbs.push_back(queueDb);
+ configDb.reset(new Db(dbenv.get(), 0));
+ dbs.push_back(configDb);
+ exchangeDb.reset(new Db(dbenv.get(), 0));
+ dbs.push_back(exchangeDb);
+ mappingDb.reset(new Db(dbenv.get(), 0));
+ dbs.push_back(mappingDb);
+ bindingDb.reset(new Db(dbenv.get(), 0));
+ dbs.push_back(bindingDb);
+ generalDb.reset(new Db(dbenv.get(), 0));
+ dbs.push_back(generalDb);
+
+ TxnCtxt txn;
+ txn.begin(dbenv.get(), false);
+ try {
+ open(queueDb, txn.get(), "queues.db", false);
+ open(configDb, txn.get(), "config.db", false);
+ open(exchangeDb, txn.get(), "exchanges.db", false);
+ open(mappingDb, txn.get(), "mappings.db", true);
+ open(bindingDb, txn.get(), "bindings.db", true);
+ open(generalDb, txn.get(), "general.db", false);
+ txn.commit();
+ } catch (...) { txn.abort(); throw; }
+ // NOTE: during normal initialization, agent == 0 because the store is initialized before the management infrastructure.
+ // However during a truncated initialization in a cluster, agent != 0. We always pass 0 as the agent for the
+ // TplStore to keep things consistent in a cluster. See https://bugzilla.redhat.com/show_bug.cgi?id=681026
+ tplStorePtr.reset(new TplJournalImpl(broker->getTimer(), "TplStore", getTplBaseDir(), "tpl", defJournalGetEventsTimeout, defJournalFlushTimeout, 0));
+ isInit = true;
+ } catch (const DbException& e) {
+ if (e.get_errno() == DB_VERSION_MISMATCH)
+ {
+ QPID_LOG(error, "Database environment mismatch: This version of db4 does not match that which created the store database.: " << e.what());
+ THROW_STORE_EXCEPTION_2("Database environment mismatch: This version of db4 does not match that which created the store database. "
+ "(If recovery is not important, delete the contents of the store directory. Otherwise, try upgrading the database using "
+ "db_upgrade or using db_recover - but the db4-utils package must also be installed to use these utilities.)", e);
+ }
+ QPID_LOG(error, "BDB exception occurred while initializing store: " << e.what());
+ if (bdbRetryCnt >= retryMax)
+ THROW_STORE_EXCEPTION_2("BDB exception occurred while initializing store", e);
+ } catch (const StoreException&) {
+ throw;
+ } catch (const journal::jexception& e) {
+ QPID_LOG(error, "Journal Exception occurred while initializing store: " << e);
+ THROW_STORE_EXCEPTION_2("Journal Exception occurred while initializing store", e.what());
+ } catch (...) {
+ QPID_LOG(error, "Unknown exception occurred while initializing store.");
+ throw;
+ }
+ } while (!isInit);
+}
+
+void MessageStoreImpl::finalize()
+{
+ if (tplStorePtr.get() && tplStorePtr->is_ready()) tplStorePtr->stop(true);
+ {
+ qpid::sys::Mutex::ScopedLock sl(journalListLock);
+ for (JournalListMapItr i = journalList.begin(); i != journalList.end(); i++)
+ {
+ JournalImpl* jQueue = i->second;
+ jQueue->resetDeleteCallback();
+ if (jQueue->is_ready()) jQueue->stop(true);
+ }
+ }
+
+ if (mgmtObject.get() != 0) {
+ mgmtObject->resourceDestroy();
+ mgmtObject.reset();
+ }
+}
+
+void MessageStoreImpl::truncateInit(const bool saveStoreContent)
+{
+ if (isInit) {
+ {
+ qpid::sys::Mutex::ScopedLock sl(journalListLock);
+ if (journalList.size()) { // check no queues exist
+ std::ostringstream oss;
+ oss << "truncateInit() called with " << journalList.size() << " queues still in existence";
+ THROW_STORE_EXCEPTION(oss.str());
+ }
+ }
+ closeDbs();
+ dbs.clear();
+ if (tplStorePtr->is_ready()) tplStorePtr->stop(true);
+ dbenv->close(0);
+ isInit = false;
+ }
+ std::ostringstream oss;
+ oss << storeDir << "/" << storeTopLevelDir;
+ if (saveStoreContent) {
+ std::string dir = mrg::journal::jdir::push_down(storeDir, storeTopLevelDir, "cluster");
+ QPID_LOG(notice, "Store directory " << oss.str() << " was pushed down (saved) into directory " << dir << ".");
+ } else {
+ mrg::journal::jdir::delete_dir(oss.str().c_str());
+ QPID_LOG(notice, "Store directory " << oss.str() << " was truncated.");
+ }
+ init();
+}
+
+void MessageStoreImpl::chkTplStoreInit()
+{
+ // Prevent multiple threads from late-initializing the TPL
+ qpid::sys::Mutex::ScopedLock sl(tplInitLock);
+ if (!tplStorePtr->is_ready()) {
+ journal::jdir::create_dir(getTplBaseDir());
+ tplStorePtr->initialize(tplNumJrnlFiles, false, 0, tplJrnlFsizeSblks, tplWCacheNumPages, tplWCachePgSizeSblks);
+ if (mgmtObject.get() != 0) mgmtObject->set_tplIsInitialized(true);
+ }
+}
+
+void MessageStoreImpl::open(db_ptr db,
+ DbTxn* txn,
+ const char* file,
+ bool dupKey)
+{
+ if(dupKey) db->set_flags(DB_DUPSORT);
+ db->open(txn, file, 0, DB_BTREE, DB_CREATE | DB_THREAD, 0);
+}
+
+void MessageStoreImpl::closeDbs()
+{
+ for (std::list<db_ptr >::iterator i = dbs.begin(); i != dbs.end(); i++) {
+ (*i)->close(0);
+ }
+ dbs.clear();
+}
+
+MessageStoreImpl::~MessageStoreImpl()
+{
+ finalize();
+ try {
+ closeDbs();
+ } catch (const DbException& e) {
+ QPID_LOG(error, "Error closing BDB databases: " << e.what());
+ } catch (const journal::jexception& e) {
+ QPID_LOG(error, "Error: " << e.what());
+ } catch (const std::exception& e) {
+ QPID_LOG(error, "Error: " << e.what());
+ } catch (...) {
+ QPID_LOG(error, "Unknown error in MessageStoreImpl::~MessageStoreImpl()");
+ }
+
+ if (mgmtObject.get() != 0) {
+ mgmtObject->resourceDestroy();
+ mgmtObject.reset();
+ }
+}
+
+void MessageStoreImpl::create(qpid::broker::PersistableQueue& queue,
+ const qpid::framing::FieldTable& args)
+{
+ checkInit();
+ if (queue.getPersistenceId()) {
+ THROW_STORE_EXCEPTION("Queue already created: " + queue.getName());
+ }
+ JournalImpl* jQueue = 0;
+ qpid::framing::FieldTable::ValuePtr value;
+
+ u_int16_t localFileCount = numJrnlFiles;
+ bool localAutoExpandFlag = autoJrnlExpand;
+ u_int16_t localAutoExpandMaxFileCount = autoJrnlExpandMaxFiles;
+ u_int32_t localFileSizeSblks = jrnlFsizeSblks;
+
+ value = args.get("qpid.file_count");
+ if (value.get() != 0 && !value->empty() && value->convertsTo<int>())
+ localFileCount = chkJrnlNumFilesParam((u_int16_t) value->get<int>(), "qpid.file_count");
+
+ value = args.get("qpid.file_size");
+ if (value.get() != 0 && !value->empty() && value->convertsTo<int>())
+ localFileSizeSblks = chkJrnlFileSizeParam((u_int32_t) value->get<int>(), "qpid.file_size", wCachePgSizeSblks) * JRNL_RMGR_PAGE_SIZE;
+
+ if (queue.getName().size() == 0)
+ {
+ QPID_LOG(error, "Cannot create store for empty (null) queue name - ignoring and attempting to continue.");
+ return;
+ }
+
+ jQueue = new JournalImpl(broker->getTimer(), queue.getName(), getJrnlDir(queue), std::string("JournalData"),
+ defJournalGetEventsTimeout, defJournalFlushTimeout, agent,
+ boost::bind(&MessageStoreImpl::journalDeleted, this, _1));
+ {
+ qpid::sys::Mutex::ScopedLock sl(journalListLock);
+ journalList[queue.getName()]=jQueue;
+ }
+
+ value = args.get("qpid.auto_expand");
+ if (value.get() != 0 && !value->empty() && value->convertsTo<bool>())
+ localAutoExpandFlag = (bool) value->get<bool>();
+
+ value = args.get("qpid.auto_expand_max_jfiles");
+ if (value.get() != 0 && !value->empty() && value->convertsTo<int>())
+ localAutoExpandMaxFileCount = (u_int16_t) value->get<int>();
+
+ queue.setExternalQueueStore(dynamic_cast<qpid::broker::ExternalQueueStore*>(jQueue));
+ try {
+ // init will create the deque's for the init...
+ jQueue->initialize(localFileCount, localAutoExpandFlag, localAutoExpandMaxFileCount, localFileSizeSblks, wCacheNumPages, wCachePgSizeSblks);
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("Queue ") + queue.getName() + ": create() failed: " + e.what());
+ }
+ try {
+ if (!create(queueDb, queueIdSequence, queue)) {
+ THROW_STORE_EXCEPTION("Queue already exists: " + queue.getName());
+ }
+ } catch (const DbException& e) {
+ THROW_STORE_EXCEPTION_2("Error creating queue named " + queue.getName(), e);
+ }
+}
+
+void MessageStoreImpl::destroy(qpid::broker::PersistableQueue& queue)
+{
+ checkInit();
+ destroy(queueDb, queue);
+ deleteBindingsForQueue(queue);
+ qpid::broker::ExternalQueueStore* eqs = queue.getExternalQueueStore();
+ if (eqs) {
+ JournalImpl* jQueue = static_cast<JournalImpl*>(eqs);
+ jQueue->delete_jrnl_files();
+ queue.setExternalQueueStore(0); // will delete the journal if exists
+ {
+ qpid::sys::Mutex::ScopedLock sl(journalListLock);
+ journalList.erase(queue.getName());
+ }
+ }
+}
+
+void MessageStoreImpl::create(const qpid::broker::PersistableExchange& exchange,
+ const qpid::framing::FieldTable& /*args*/)
+{
+ checkInit();
+ if (exchange.getPersistenceId()) {
+ THROW_STORE_EXCEPTION("Exchange already created: " + exchange.getName());
+ }
+ try {
+ if (!create(exchangeDb, exchangeIdSequence, exchange)) {
+ THROW_STORE_EXCEPTION("Exchange already exists: " + exchange.getName());
+ }
+ } catch (const DbException& e) {
+ THROW_STORE_EXCEPTION_2("Error creating exchange named " + exchange.getName(), e);
+ }
+}
+
+void MessageStoreImpl::destroy(const qpid::broker::PersistableExchange& exchange)
+{
+ checkInit();
+ destroy(exchangeDb, exchange);
+ //need to also delete bindings
+ IdDbt key(exchange.getPersistenceId());
+ bindingDb->del(0, &key, DB_AUTO_COMMIT);
+}
+
+void MessageStoreImpl::create(const qpid::broker::PersistableConfig& general)
+{
+ checkInit();
+ if (general.getPersistenceId()) {
+ THROW_STORE_EXCEPTION("General configuration item already created");
+ }
+ try {
+ if (!create(generalDb, generalIdSequence, general)) {
+ THROW_STORE_EXCEPTION("General configuration already exists");
+ }
+ } catch (const DbException& e) {
+ THROW_STORE_EXCEPTION_2("Error creating general configuration", e);
+ }
+}
+
+void MessageStoreImpl::destroy(const qpid::broker::PersistableConfig& general)
+{
+ checkInit();
+ destroy(generalDb, general);
+}
+
+bool MessageStoreImpl::create(db_ptr db,
+ IdSequence& seq,
+ const qpid::broker::Persistable& p)
+{
+ u_int64_t id (seq.next());
+ Dbt key(&id, sizeof(id));
+ BufferValue value (p);
+
+ int status;
+ TxnCtxt txn;
+ txn.begin(dbenv.get(), true);
+ try {
+ status = db->put(txn.get(), &key, &value, DB_NOOVERWRITE);
+ txn.commit();
+ } catch (...) {
+ txn.abort();
+ throw;
+ }
+ if (status == DB_KEYEXIST) {
+ return false;
+ } else {
+ p.setPersistenceId(id);
+ return true;
+ }
+}
+
+void MessageStoreImpl::destroy(db_ptr db, const qpid::broker::Persistable& p)
+{
+ qpid::sys::Mutex::ScopedLock sl(bdbLock);
+ IdDbt key(p.getPersistenceId());
+ db->del(0, &key, DB_AUTO_COMMIT);
+}
+
+
+void MessageStoreImpl::bind(const qpid::broker::PersistableExchange& e,
+ const qpid::broker::PersistableQueue& q,
+ const std::string& k,
+ const qpid::framing::FieldTable& a)
+{
+ checkInit();
+ IdDbt key(e.getPersistenceId());
+ BindingDbt value(e, q, k, a);
+ TxnCtxt txn;
+ txn.begin(dbenv.get(), true);
+ try {
+ put(bindingDb, txn.get(), key, value);
+ txn.commit();
+ } catch (...) {
+ txn.abort();
+ throw;
+ }
+}
+
+void MessageStoreImpl::unbind(const qpid::broker::PersistableExchange& e,
+ const qpid::broker::PersistableQueue& q,
+ const std::string& k,
+ const qpid::framing::FieldTable&)
+{
+ checkInit();
+ deleteBinding(e, q, k);
+}
+
+void MessageStoreImpl::recover(qpid::broker::RecoveryManager& registry)
+{
+ checkInit();
+ txn_list prepared;
+ recoverLockedMappings(prepared);
+
+ queue_index queues;//id->queue
+ exchange_index exchanges;//id->exchange
+ message_index messages;//id->message
+
+ TxnCtxt txn;
+ txn.begin(dbenv.get(), false);
+ try {
+ //read all queues, calls recoversMessages
+ recoverQueues(txn, registry, queues, prepared, messages);
+
+ //recover exchange & bindings:
+ recoverExchanges(txn, registry, exchanges);
+ recoverBindings(txn, exchanges, queues);
+
+ //recover general-purpose configuration
+ recoverGeneral(txn, registry);
+
+ txn.commit();
+ } catch (const DbException& e) {
+ txn.abort();
+ THROW_STORE_EXCEPTION_2("Error on recovery", e);
+ } catch (...) {
+ txn.abort();
+ throw;
+ }
+
+ //recover transactions:
+ for (txn_list::iterator i = prepared.begin(); i != prepared.end(); i++) {
+ const PreparedTransaction pt = *i;
+ if (mgmtObject.get() != 0) {
+ mgmtObject->inc_tplTransactionDepth();
+ mgmtObject->inc_tplTxnPrepares();
+ }
+
+ std::string xid = pt.xid;
+
+ // Restore data token state in TxnCtxt
+ TplRecoverMapCitr citr = tplRecoverMap.find(xid);
+ if (citr == tplRecoverMap.end()) THROW_STORE_EXCEPTION("XID not found in tplRecoverMap");
+
+ // If a record is found that is dequeued but not committed/aborted from tplStore, then a complete() call
+ // was interrupted part way through committing/aborting the impacted queues. Complete this process.
+ bool incomplTplTxnFlag = citr->second.deq_flag;
+
+ if (citr->second.tpc_flag) {
+ // Dtx (2PC) transaction
+ TPCTxnCtxt* tpcc = new TPCTxnCtxt(xid, &messageIdSequence);
+ std::auto_ptr<qpid::broker::TPCTransactionContext> txn(tpcc);
+ tpcc->recoverDtok(citr->second.rid, xid);
+ tpcc->prepare(tplStorePtr.get());
+
+ qpid::broker::RecoverableTransaction::shared_ptr dtx;
+ if (!incomplTplTxnFlag) dtx = registry.recoverTransaction(xid, txn);
+ if (pt.enqueues.get()) {
+ for (LockedMappings::iterator j = pt.enqueues->begin(); j != pt.enqueues->end(); j++) {
+ tpcc->addXidRecord(queues[j->first]->getExternalQueueStore());
+ if (!incomplTplTxnFlag) dtx->enqueue(queues[j->first], messages[j->second]);
+ }
+ }
+ if (pt.dequeues.get()) {
+ for (LockedMappings::iterator j = pt.dequeues->begin(); j != pt.dequeues->end(); j++) {
+ tpcc->addXidRecord(queues[j->first]->getExternalQueueStore());
+ if (!incomplTplTxnFlag) dtx->dequeue(queues[j->first], messages[j->second]);
+ }
+ }
+
+ if (incomplTplTxnFlag) {
+ tpcc->complete(citr->second.commit_flag);
+ }
+ } else {
+ // Local (1PC) transaction
+ boost::shared_ptr<TxnCtxt> opcc(new TxnCtxt(xid, &messageIdSequence));
+ opcc->recoverDtok(citr->second.rid, xid);
+ opcc->prepare(tplStorePtr.get());
+
+ if (pt.enqueues.get()) {
+ for (LockedMappings::iterator j = pt.enqueues->begin(); j != pt.enqueues->end(); j++) {
+ opcc->addXidRecord(queues[j->first]->getExternalQueueStore());
+ }
+ }
+ if (pt.dequeues.get()) {
+ for (LockedMappings::iterator j = pt.dequeues->begin(); j != pt.dequeues->end(); j++) {
+ opcc->addXidRecord(queues[j->first]->getExternalQueueStore());
+ }
+ }
+ if (incomplTplTxnFlag) {
+ opcc->complete(citr->second.commit_flag);
+ } else {
+ completed(*opcc.get(), citr->second.commit_flag);
+ }
+ }
+ }
+ registry.recoveryComplete();
+}
+
+void MessageStoreImpl::recoverQueues(TxnCtxt& txn,
+ qpid::broker::RecoveryManager& registry,
+ queue_index& queue_index,
+ txn_list& prepared,
+ message_index& messages)
+{
+ Cursor queues;
+ queues.open(queueDb, txn.get());
+
+ u_int64_t maxQueueId(1);
+
+ IdDbt key;
+ Dbt value;
+ //read all queues
+ while (queues.next(key, value)) {
+ qpid::framing::Buffer buffer(reinterpret_cast<char*>(value.get_data()), value.get_size());
+ //create a Queue instance
+ qpid::broker::RecoverableQueue::shared_ptr queue = registry.recoverQueue(buffer);
+ //set the persistenceId and update max as required
+ queue->setPersistenceId(key.id);
+
+ const std::string queueName = queue->getName().c_str();
+ JournalImpl* jQueue = 0;
+ if (queueName.size() == 0)
+ {
+ QPID_LOG(error, "Cannot recover empty (null) queue name - ignoring and attempting to continue.");
+ break;
+ }
+ jQueue = new JournalImpl(broker->getTimer(), queueName, getJrnlHashDir(queueName), std::string("JournalData"),
+ defJournalGetEventsTimeout, defJournalFlushTimeout, agent,
+ boost::bind(&MessageStoreImpl::journalDeleted, this, _1));
+ {
+ qpid::sys::Mutex::ScopedLock sl(journalListLock);
+ journalList[queueName] = jQueue;
+ }
+ queue->setExternalQueueStore(dynamic_cast<qpid::broker::ExternalQueueStore*>(jQueue));
+
+ try
+ {
+ long rcnt = 0L; // recovered msg count
+ long idcnt = 0L; // in-doubt msg count
+ u_int64_t thisHighestRid = 0ULL;
+ jQueue->recover(numJrnlFiles, autoJrnlExpand, autoJrnlExpandMaxFiles, jrnlFsizeSblks, wCacheNumPages, wCachePgSizeSblks, &prepared, thisHighestRid, key.id); // start recovery
+ if (highestRid == 0ULL)
+ highestRid = thisHighestRid;
+ else if (thisHighestRid - highestRid < 0x8000000000000000ULL) // RFC 1982 comparison for unsigned 64-bit
+ highestRid = thisHighestRid;
+ recoverMessages(txn, registry, queue, prepared, messages, rcnt, idcnt);
+ QPID_LOG(info, "Recovered queue \"" << queueName << "\": " << rcnt << " messages recovered; " << idcnt << " messages in-doubt.");
+ jQueue->recover_complete(); // start journal.
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("Queue ") + queueName + ": recoverQueues() failed: " + e.what());
+ }
+ //read all messages: done on a per queue basis if using Journal
+
+ queue_index[key.id] = queue;
+ maxQueueId = std::max(key.id, maxQueueId);
+ }
+
+ // NOTE: highestRid is set by both recoverQueues() and recoverTplStore() as
+ // the messageIdSequence is used for both queue journals and the tpl journal.
+ messageIdSequence.reset(highestRid + 1);
+ QPID_LOG(info, "Most recent persistence id found: 0x" << std::hex << highestRid << std::dec);
+
+ queueIdSequence.reset(maxQueueId + 1);
+}
+
+
+void MessageStoreImpl::recoverExchanges(TxnCtxt& txn,
+ qpid::broker::RecoveryManager& registry,
+ exchange_index& index)
+{
+ //TODO: this is a copy&paste from recoverQueues - refactor!
+ Cursor exchanges;
+ exchanges.open(exchangeDb, txn.get());
+
+ u_int64_t maxExchangeId(1);
+ IdDbt key;
+ Dbt value;
+ //read all exchanges
+ while (exchanges.next(key, value)) {
+ qpid::framing::Buffer buffer(reinterpret_cast<char*>(value.get_data()), value.get_size());
+ //create a Exchange instance
+ qpid::broker::RecoverableExchange::shared_ptr exchange = registry.recoverExchange(buffer);
+ if (exchange) {
+ //set the persistenceId and update max as required
+ exchange->setPersistenceId(key.id);
+ index[key.id] = exchange;
+ QPID_LOG(info, "Recovered exchange \"" << exchange->getName() << '"');
+ }
+ maxExchangeId = std::max(key.id, maxExchangeId);
+ }
+ exchangeIdSequence.reset(maxExchangeId + 1);
+}
+
+void MessageStoreImpl::recoverBindings(TxnCtxt& txn,
+ exchange_index& exchanges,
+ queue_index& queues)
+{
+ Cursor bindings;
+ bindings.open(bindingDb, txn.get());
+
+ IdDbt key;
+ Dbt value;
+ while (bindings.next(key, value)) {
+ qpid::framing::Buffer buffer(reinterpret_cast<char*>(value.get_data()), value.get_size());
+ if (buffer.available() < 8) {
+ QPID_LOG(error, "Not enough data for binding: " << buffer.available());
+ THROW_STORE_EXCEPTION("Not enough data for binding");
+ }
+ uint64_t queueId = buffer.getLongLong();
+ std::string queueName;
+ std::string routingkey;
+ qpid::framing::FieldTable args;
+ buffer.getShortString(queueName);
+ buffer.getShortString(routingkey);
+ buffer.get(args);
+ exchange_index::iterator exchange = exchanges.find(key.id);
+ queue_index::iterator queue = queues.find(queueId);
+ if (exchange != exchanges.end() && queue != queues.end()) {
+ //could use the recoverable queue here rather than the name...
+ exchange->second->bind(queueName, routingkey, args);
+ QPID_LOG(info, "Recovered binding exchange=" << exchange->second->getName()
+ << " key=" << routingkey
+ << " queue=" << queueName);
+ } else {
+ //stale binding, delete it
+ QPID_LOG(warning, "Deleting stale binding");
+ bindings->del(0);
+ }
+ }
+}
+
+void MessageStoreImpl::recoverGeneral(TxnCtxt& txn,
+ qpid::broker::RecoveryManager& registry)
+{
+ Cursor items;
+ items.open(generalDb, txn.get());
+
+ u_int64_t maxGeneralId(1);
+ IdDbt key;
+ Dbt value;
+ //read all items
+ while (items.next(key, value)) {
+ qpid::framing::Buffer buffer(reinterpret_cast<char*>(value.get_data()), value.get_size());
+ //create instance
+ qpid::broker::RecoverableConfig::shared_ptr config = registry.recoverConfig(buffer);
+ //set the persistenceId and update max as required
+ config->setPersistenceId(key.id);
+ maxGeneralId = std::max(key.id, maxGeneralId);
+ }
+ generalIdSequence.reset(maxGeneralId + 1);
+}
+
+void MessageStoreImpl::recoverMessages(TxnCtxt& /*txn*/,
+ qpid::broker::RecoveryManager& recovery,
+ qpid::broker::RecoverableQueue::shared_ptr& queue,
+ txn_list& prepared,
+ message_index& messages,
+ long& rcnt,
+ long& idcnt)
+{
+ size_t preambleLength = sizeof(u_int32_t)/*header size*/;
+
+ JournalImpl* jc = static_cast<JournalImpl*>(queue->getExternalQueueStore());
+ DataTokenImpl dtok;
+ size_t readSize = 0;
+ unsigned msg_count = 0;
+
+ // TODO: This optimization to skip reading if there are no enqueued messages to read
+ // breaks the python system test in phase 6 with "Exception: Cannot write lock file"
+ // Figure out what is breaking.
+ //bool read = jc->get_enq_cnt() > 0;
+ bool read = true;
+
+ void* dbuff = NULL; size_t dbuffSize = 0;
+ void* xidbuff = NULL; size_t xidbuffSize = 0;
+ bool transientFlag = false;
+ bool externalFlag = false;
+
+ dtok.set_wstate(DataTokenImpl::ENQ);
+
+ // Read the message from the Journal.
+ try {
+ unsigned aio_sleep_cnt = 0;
+ while (read) {
+ mrg::journal::iores res = jc->read_data_record(&dbuff, dbuffSize, &xidbuff, xidbuffSize, transientFlag, externalFlag, &dtok);
+ readSize = dtok.dsize();
+
+ switch (res)
+ {
+ case mrg::journal::RHM_IORES_SUCCESS: {
+ msg_count++;
+ qpid::broker::RecoverableMessage::shared_ptr msg;
+ char* data = (char*)dbuff;
+
+ unsigned headerSize;
+ if (externalFlag) {
+ msg = getExternMessage(recovery, dtok.rid(), headerSize); // large message external to jrnl
+ } else {
+ headerSize = qpid::framing::Buffer(data, preambleLength).getLong();
+ qpid::framing::Buffer headerBuff(data+ preambleLength, headerSize); /// do we want read size or header size ????
+ msg = recovery.recoverMessage(headerBuff);
+ }
+ msg->setPersistenceId(dtok.rid());
+ // At some future point if delivery attempts are stored, then this call would
+ // become optional depending on that information.
+ msg->setRedelivered();
+ // Reset the TTL for the recovered message
+ msg->computeExpiration(broker->getExpiryPolicy());
+
+ u_int32_t contentOffset = headerSize + preambleLength;
+ u_int64_t contentSize = readSize - contentOffset;
+ if (msg->loadContent(contentSize) && !externalFlag) {
+ //now read the content
+ qpid::framing::Buffer contentBuff(data + contentOffset, contentSize);
+ msg->decodeContent(contentBuff);
+ }
+
+ PreparedTransaction::list::iterator i = PreparedTransaction::getLockedPreparedTransaction(prepared, queue->getPersistenceId(), dtok.rid());
+ if (i == prepared.end()) { // not in prepared list
+ rcnt++;
+ queue->recover(msg);
+ } else {
+ u_int64_t rid = dtok.rid();
+ std::string xid(i->xid);
+ TplRecoverMapCitr citr = tplRecoverMap.find(xid);
+ if (citr == tplRecoverMap.end()) THROW_STORE_EXCEPTION("XID not found in tplRecoverMap");
+
+ // deq present in prepared list: this xid is part of incomplete txn commit/abort
+ // or this is a 1PC txn that must be rolled forward
+ if (citr->second.deq_flag || !citr->second.tpc_flag) {
+ if (jc->is_enqueued(rid, true)) {
+ // Enqueue is non-tx, dequeue tx
+ assert(jc->is_locked(rid)); // This record MUST be locked by a txn dequeue
+ if (!citr->second.commit_flag) {
+ rcnt++;
+ queue->recover(msg); // recover message in abort case only
+ }
+ } else {
+ // Enqueue and/or dequeue tx
+ journal::txn_map& tmap = jc->get_txn_map();
+ journal::txn_data_list txnList = tmap.get_tdata_list(xid); // txnList will be empty if xid not found
+ bool enq = false;
+ bool deq = false;
+ for (journal::tdl_itr j = txnList.begin(); j<txnList.end(); j++) {
+ if (j->_enq_flag && j->_rid == rid) enq = true;
+ else if (!j->_enq_flag && j->_drid == rid) deq = true;
+ }
+ if (enq && !deq && citr->second.commit_flag) {
+ rcnt++;
+ queue->recover(msg); // recover txn message in commit case only
+ }
+ }
+ } else {
+ idcnt++;
+ messages[rid] = msg;
+ }
+ }
+
+ dtok.reset();
+ dtok.set_wstate(DataTokenImpl::ENQ);
+
+ if (xidbuff)
+ ::free(xidbuff);
+ else if (dbuff)
+ ::free(dbuff);
+ aio_sleep_cnt = 0;
+ break;
+ }
+ case mrg::journal::RHM_IORES_PAGE_AIOWAIT:
+ if (++aio_sleep_cnt > MAX_AIO_SLEEPS)
+ THROW_STORE_EXCEPTION("Timeout waiting for AIO in MessageStoreImpl::recoverMessages()");
+ ::usleep(AIO_SLEEP_TIME_US);
+ break;
+ case mrg::journal::RHM_IORES_EMPTY:
+ read = false;
+ break; // done with all messages. (add call in jrnl to test that _emap is empty.)
+ default:
+ std::ostringstream oss;
+ oss << "recoverMessages(): Queue: " << queue->getName() << ": Unexpected return from journal read: " << mrg::journal::iores_str(res);
+ THROW_STORE_EXCEPTION(oss.str());
+ } // switch
+ } // while
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("Queue ") + queue->getName() + ": recoverMessages() failed: " + e.what());
+ }
+}
+
+qpid::broker::RecoverableMessage::shared_ptr MessageStoreImpl::getExternMessage(qpid::broker::RecoveryManager& /*recovery*/,
+ uint64_t /*messageId*/,
+ unsigned& /*headerSize*/)
+{
+ throw mrg::journal::jexception(mrg::journal::jerrno::JERR__NOTIMPL, "MessageStoreImpl", "getExternMessage");
+}
+
+int MessageStoreImpl::enqueueMessage(TxnCtxt& txn,
+ IdDbt& msgId,
+ qpid::broker::RecoverableMessage::shared_ptr& msg,
+ queue_index& index,
+ txn_list& prepared,
+ message_index& messages)
+{
+ Cursor mappings;
+ mappings.open(mappingDb, txn.get());
+
+ IdDbt value;
+
+ int count(0);
+ for (int status = mappings->get(&msgId, &value, DB_SET); status == 0; status = mappings->get(&msgId, &value, DB_NEXT_DUP)) {
+ if (index.find(value.id) == index.end()) {
+ QPID_LOG(warning, "Recovered message for queue that no longer exists");
+ mappings->del(0);
+ } else {
+ qpid::broker::RecoverableQueue::shared_ptr queue = index[value.id];
+ if (PreparedTransaction::isLocked(prepared, value.id, msgId.id)) {
+ messages[msgId.id] = msg;
+ } else {
+ queue->recover(msg);
+ }
+ count++;
+ }
+ }
+ mappings.close();
+ return count;
+}
+
+void MessageStoreImpl::readTplStore()
+{
+ tplRecoverMap.clear();
+ journal::txn_map& tmap = tplStorePtr->get_txn_map();
+ DataTokenImpl dtok;
+ void* dbuff = NULL; size_t dbuffSize = 0;
+ void* xidbuff = NULL; size_t xidbuffSize = 0;
+ bool transientFlag = false;
+ bool externalFlag = false;
+ bool done = false;
+ try {
+ unsigned aio_sleep_cnt = 0;
+ while (!done) {
+ dtok.reset();
+ dtok.set_wstate(DataTokenImpl::ENQ);
+ mrg::journal::iores res = tplStorePtr->read_data_record(&dbuff, dbuffSize, &xidbuff, xidbuffSize, transientFlag, externalFlag, &dtok);
+ switch (res) {
+ case mrg::journal::RHM_IORES_SUCCESS: {
+ // Every TPL record contains both data and an XID
+ assert(dbuffSize>0);
+ assert(xidbuffSize>0);
+ std::string xid(static_cast<const char*>(xidbuff), xidbuffSize);
+ bool is2PC = *(static_cast<char*>(dbuff)) != 0;
+
+ // Check transaction details; add to recover map
+ journal::txn_data_list txnList = tmap.get_tdata_list(xid); // txnList will be empty if xid not found
+ if (!txnList.empty()) { // xid found in tmap
+ unsigned enqCnt = 0;
+ unsigned deqCnt = 0;
+ u_int64_t rid = 0;
+
+ // Assume commit (roll forward) in cases where only prepare has been called - ie only enqueue record exists.
+ // Note: will apply to both 1PC and 2PC transactions.
+ bool commitFlag = true;
+
+ for (journal::tdl_itr j = txnList.begin(); j<txnList.end(); j++) {
+ if (j->_enq_flag) {
+ rid = j->_rid;
+ enqCnt++;
+ } else {
+ commitFlag = j->_commit_flag;
+ deqCnt++;
+ }
+ }
+ assert(enqCnt == 1);
+ assert(deqCnt <= 1);
+ tplRecoverMap.insert(TplRecoverMapPair(xid, TplRecoverStruct(rid, deqCnt == 1, commitFlag, is2PC)));
+ }
+
+ ::free(xidbuff);
+ aio_sleep_cnt = 0;
+ break;
+ }
+ case mrg::journal::RHM_IORES_PAGE_AIOWAIT:
+ if (++aio_sleep_cnt > MAX_AIO_SLEEPS)
+ THROW_STORE_EXCEPTION("Timeout waiting for AIO in MessageStoreImpl::recoverTplStore()");
+ ::usleep(AIO_SLEEP_TIME_US);
+ break;
+ case mrg::journal::RHM_IORES_EMPTY:
+ done = true;
+ break; // done with all messages. (add call in jrnl to test that _emap is empty.)
+ default:
+ std::ostringstream oss;
+ oss << "readTplStore(): Unexpected result from journal read: " << mrg::journal::iores_str(res);
+ THROW_STORE_EXCEPTION(oss.str());
+ } // switch
+ }
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("TPL recoverTplStore() failed: ") + e.what());
+ }
+}
+
+void MessageStoreImpl::recoverTplStore()
+{
+ if (journal::jdir::exists(tplStorePtr->jrnl_dir() + tplStorePtr->base_filename() + ".jinf")) {
+ u_int64_t thisHighestRid = 0ULL;
+ tplStorePtr->recover(tplNumJrnlFiles, false, 0, tplJrnlFsizeSblks, tplWCachePgSizeSblks, tplWCacheNumPages, 0, thisHighestRid, 0);
+ if (highestRid == 0ULL)
+ highestRid = thisHighestRid;
+ else if (thisHighestRid - highestRid < 0x8000000000000000ULL) // RFC 1982 comparison for unsigned 64-bit
+ highestRid = thisHighestRid;
+
+ // Load tplRecoverMap by reading the TPL store
+ readTplStore();
+
+ tplStorePtr->recover_complete(); // start journal.
+ }
+}
+
+void MessageStoreImpl::recoverLockedMappings(txn_list& txns)
+{
+ if (!tplStorePtr->is_ready())
+ recoverTplStore();
+
+ // Abort unprepared xids and populate the locked maps
+ for (TplRecoverMapCitr i = tplRecoverMap.begin(); i != tplRecoverMap.end(); i++) {
+ LockedMappings::shared_ptr enq_ptr;
+ enq_ptr.reset(new LockedMappings);
+ LockedMappings::shared_ptr deq_ptr;
+ deq_ptr.reset(new LockedMappings);
+ txns.push_back(new PreparedTransaction(i->first, enq_ptr, deq_ptr));
+ }
+}
+
+void MessageStoreImpl::collectPreparedXids(std::set<std::string>& xids)
+{
+ if (tplStorePtr->is_ready()) {
+ tplStorePtr->read_reset();
+ readTplStore();
+ } else {
+ recoverTplStore();
+ }
+ for (TplRecoverMapCitr i = tplRecoverMap.begin(); i != tplRecoverMap.end(); i++) {
+ // Discard all txns that are to be rolled forward/back and 1PC transactions
+ if (!i->second.deq_flag && i->second.tpc_flag)
+ xids.insert(i->first);
+ }
+}
+
+void MessageStoreImpl::stage(const boost::intrusive_ptr<qpid::broker::PersistableMessage>& /*msg*/)
+{
+ throw mrg::journal::jexception(mrg::journal::jerrno::JERR__NOTIMPL, "MessageStoreImpl", "stage");
+}
+
+void MessageStoreImpl::destroy(qpid::broker::PersistableMessage& /*msg*/)
+{
+ throw mrg::journal::jexception(mrg::journal::jerrno::JERR__NOTIMPL, "MessageStoreImpl", "destroy");
+}
+
+void MessageStoreImpl::appendContent(const boost::intrusive_ptr<const qpid::broker::PersistableMessage>& /*msg*/,
+ const std::string& /*data*/)
+{
+ throw mrg::journal::jexception(mrg::journal::jerrno::JERR__NOTIMPL, "MessageStoreImpl", "appendContent");
+}
+
+void MessageStoreImpl::loadContent(const qpid::broker::PersistableQueue& queue,
+ const boost::intrusive_ptr<const qpid::broker::PersistableMessage>& msg,
+ std::string& data,
+ u_int64_t offset,
+ u_int32_t length)
+{
+ checkInit();
+ u_int64_t messageId (msg->getPersistenceId());
+
+ if (messageId != 0) {
+ try {
+ JournalImpl* jc = static_cast<JournalImpl*>(queue.getExternalQueueStore());
+ if (jc && jc->is_enqueued(messageId) ) {
+ if (!jc->loadMsgContent(messageId, data, length, offset)) {
+ std::ostringstream oss;
+ oss << "Queue " << queue.getName() << ": loadContent() failed: Message " << messageId << " is extern";
+ THROW_STORE_EXCEPTION(oss.str());
+ }
+ } else {
+ std::ostringstream oss;
+ oss << "Queue " << queue.getName() << ": loadContent() failed: Message " << messageId << " not enqueued";
+ THROW_STORE_EXCEPTION(oss.str());
+ }
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("Queue ") + queue.getName() + ": loadContent() failed: " + e.what());
+ }
+ } else {
+ THROW_STORE_EXCEPTION("Cannot load content. Message not known to store!");
+ }
+}
+
+void MessageStoreImpl::flush(const qpid::broker::PersistableQueue& queue)
+{
+ if (queue.getExternalQueueStore() == 0) return;
+ checkInit();
+ std::string qn = queue.getName();
+ try {
+ JournalImpl* jc = static_cast<JournalImpl*>(queue.getExternalQueueStore());
+ if (jc) {
+ // TODO: check if this result should be used...
+ /*mrg::journal::iores res =*/ jc->flush();
+ }
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("Queue ") + qn + ": flush() failed: " + e.what() );
+ }
+}
+
+void MessageStoreImpl::enqueue(qpid::broker::TransactionContext* ctxt,
+ const boost::intrusive_ptr<qpid::broker::PersistableMessage>& msg,
+ const qpid::broker::PersistableQueue& queue)
+{
+ checkInit();
+ u_int64_t queueId (queue.getPersistenceId());
+ u_int64_t messageId (msg->getPersistenceId());
+ if (queueId == 0) {
+ THROW_STORE_EXCEPTION("Queue not created: " + queue.getName());
+ }
+
+ TxnCtxt implicit;
+ TxnCtxt* txn = 0;
+ if (ctxt) {
+ txn = check(ctxt);
+ } else {
+ txn = &implicit;
+ }
+
+ bool newId = false;
+ if (messageId == 0) {
+ messageId = messageIdSequence.next();
+ msg->setPersistenceId(messageId);
+ newId = true;
+ }
+ store(&queue, txn, msg, newId);
+
+ // add queue* to the txn map..
+ if (ctxt) txn->addXidRecord(queue.getExternalQueueStore());
+}
+
+u_int64_t MessageStoreImpl::msgEncode(std::vector<char>& buff, const boost::intrusive_ptr<qpid::broker::PersistableMessage>& message)
+{
+ u_int32_t headerSize = message->encodedHeaderSize();
+ u_int64_t size = message->encodedSize() + sizeof(u_int32_t);
+ try { buff = std::vector<char>(size); } // long + headers + content
+ catch (const std::exception& e) {
+ std::ostringstream oss;
+ oss << "Unable to allocate memory for encoding message; requested size: " << size << "; error: " << e.what();
+ THROW_STORE_EXCEPTION(oss.str());
+ }
+ qpid::framing::Buffer buffer(&buff[0],size);
+ buffer.putLong(headerSize);
+ message->encode(buffer);
+ return size;
+}
+
+void MessageStoreImpl::store(const qpid::broker::PersistableQueue* queue,
+ TxnCtxt* txn,
+ const boost::intrusive_ptr<qpid::broker::PersistableMessage>& message,
+ bool /*newId*/)
+{
+ std::vector<char> buff;
+ u_int64_t size = msgEncode(buff, message);
+
+ try {
+ if (queue) {
+ boost::intrusive_ptr<DataTokenImpl> dtokp(new DataTokenImpl);
+ dtokp->addRef();
+ dtokp->setSourceMessage(message);
+ dtokp->set_external_rid(true);
+ dtokp->set_rid(message->getPersistenceId()); // set the messageID into the Journal header (record-id)
+
+ JournalImpl* jc = static_cast<JournalImpl*>(queue->getExternalQueueStore());
+ if (txn->getXid().empty()) {
+ jc->enqueue_data_record(&buff[0], size, size, dtokp.get(), !message->isPersistent());
+ } else {
+ jc->enqueue_txn_data_record(&buff[0], size, size, dtokp.get(), txn->getXid(), !message->isPersistent());
+ }
+ } else {
+ THROW_STORE_EXCEPTION(std::string("MessageStoreImpl::store() failed: queue NULL."));
+ }
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("Queue ") + queue->getName() + ": MessageStoreImpl::store() failed: " +
+ e.what());
+ }
+}
+
+void MessageStoreImpl::dequeue(qpid::broker::TransactionContext* ctxt,
+ const boost::intrusive_ptr<qpid::broker::PersistableMessage>& msg,
+ const qpid::broker::PersistableQueue& queue)
+{
+ checkInit();
+ u_int64_t queueId (queue.getPersistenceId());
+ u_int64_t messageId (msg->getPersistenceId());
+ if (queueId == 0) {
+ THROW_STORE_EXCEPTION("Queue \"" + queue.getName() + "\" has null queue Id (has not been created)");
+ }
+ if (messageId == 0) {
+ THROW_STORE_EXCEPTION("Queue \"" + queue.getName() + "\": Dequeuing message with null persistence Id.");
+ }
+
+ TxnCtxt implicit;
+ TxnCtxt* txn = 0;
+ if (ctxt) {
+ txn = check(ctxt);
+ } else {
+ txn = &implicit;
+ }
+
+ // add queue* to the txn map..
+ if (ctxt) txn->addXidRecord(queue.getExternalQueueStore());
+ async_dequeue(ctxt, msg, queue);
+
+ msg->dequeueComplete();
+}
+
+void MessageStoreImpl::async_dequeue(qpid::broker::TransactionContext* ctxt,
+ const boost::intrusive_ptr<qpid::broker::PersistableMessage>& msg,
+ const qpid::broker::PersistableQueue& queue)
+{
+ boost::intrusive_ptr<DataTokenImpl> ddtokp(new DataTokenImpl);
+ ddtokp->setSourceMessage(msg);
+ ddtokp->set_external_rid(true);
+ ddtokp->set_rid(messageIdSequence.next());
+ ddtokp->set_dequeue_rid(msg->getPersistenceId());
+ ddtokp->set_wstate(DataTokenImpl::ENQ);
+ std::string tid;
+ if (ctxt) {
+ TxnCtxt* txn = check(ctxt);
+ tid = txn->getXid();
+ }
+ // Manually increase the ref count, as raw pointers are used beyond this point
+ ddtokp->addRef();
+ try {
+ JournalImpl* jc = static_cast<JournalImpl*>(queue.getExternalQueueStore());
+ if (tid.empty()) {
+ jc->dequeue_data_record(ddtokp.get());
+ } else {
+ jc->dequeue_txn_data_record(ddtokp.get(), tid);
+ }
+ } catch (const journal::jexception& e) {
+ ddtokp->release();
+ THROW_STORE_EXCEPTION(std::string("Queue ") + queue.getName() + ": async_dequeue() failed: " + e.what());
+ }
+}
+
+u_int32_t MessageStoreImpl::outstandingQueueAIO(const qpid::broker::PersistableQueue& /*queue*/)
+{
+ checkInit();
+ return 0;
+}
+
+void MessageStoreImpl::completed(TxnCtxt& txn,
+ bool commit)
+{
+ try {
+ chkTplStoreInit(); // Late initialize (if needed)
+
+ // Nothing to do if not prepared
+ if (txn.getDtok()->is_enqueued()) {
+ txn.incrDtokRef();
+ DataTokenImpl* dtokp = txn.getDtok();
+ dtokp->set_dequeue_rid(dtokp->rid());
+ dtokp->set_rid(messageIdSequence.next());
+ tplStorePtr->dequeue_txn_data_record(txn.getDtok(), txn.getXid(), commit);
+ }
+ txn.complete(commit);
+ if (mgmtObject.get() != 0) {
+ mgmtObject->dec_tplTransactionDepth();
+ if (commit)
+ mgmtObject->inc_tplTxnCommits();
+ else
+ mgmtObject->inc_tplTxnAborts();
+ }
+ } catch (const std::exception& e) {
+ QPID_LOG(error, "Error completing xid " << txn.getXid() << ": " << e.what());
+ throw;
+ }
+}
+
+std::auto_ptr<qpid::broker::TransactionContext> MessageStoreImpl::begin()
+{
+ checkInit();
+ // pass sequence number for c/a
+ return std::auto_ptr<qpid::broker::TransactionContext>(new TxnCtxt(&messageIdSequence));
+}
+
+std::auto_ptr<qpid::broker::TPCTransactionContext> MessageStoreImpl::begin(const std::string& xid)
+{
+ checkInit();
+ IdSequence* jtx = &messageIdSequence;
+ // pass sequence number for c/a
+ return std::auto_ptr<qpid::broker::TPCTransactionContext>(new TPCTxnCtxt(xid, jtx));
+}
+
+void MessageStoreImpl::prepare(qpid::broker::TPCTransactionContext& ctxt)
+{
+ checkInit();
+ TxnCtxt* txn = dynamic_cast<TxnCtxt*>(&ctxt);
+ if(!txn) throw qpid::broker::InvalidTransactionContextException();
+ localPrepare(txn);
+}
+
+void MessageStoreImpl::localPrepare(TxnCtxt* ctxt)
+{
+ try {
+ chkTplStoreInit(); // Late initialize (if needed)
+
+ // This sync is required to ensure multi-queue atomicity - ie all txn data
+ // must hit the disk on *all* queues before the TPL prepare (enq) is written.
+ ctxt->sync();
+
+ ctxt->incrDtokRef();
+ DataTokenImpl* dtokp = ctxt->getDtok();
+ dtokp->set_external_rid(true);
+ dtokp->set_rid(messageIdSequence.next());
+ char tpcFlag = static_cast<char>(ctxt->isTPC());
+ tplStorePtr->enqueue_txn_data_record(&tpcFlag, sizeof(char), sizeof(char), dtokp, ctxt->getXid(), false);
+ ctxt->prepare(tplStorePtr.get());
+ // make sure all the data is written to disk before returning
+ ctxt->sync();
+ if (mgmtObject.get() != 0) {
+ mgmtObject->inc_tplTransactionDepth();
+ mgmtObject->inc_tplTxnPrepares();
+ }
+ } catch (const std::exception& e) {
+ QPID_LOG(error, "Error preparing xid " << ctxt->getXid() << ": " << e.what());
+ throw;
+ }
+}
+
+void MessageStoreImpl::commit(qpid::broker::TransactionContext& ctxt)
+{
+ checkInit();
+ TxnCtxt* txn(check(&ctxt));
+ if (!txn->isTPC()) {
+ if (txn->impactedQueuesEmpty()) return;
+ localPrepare(dynamic_cast<TxnCtxt*>(txn));
+ }
+ completed(*dynamic_cast<TxnCtxt*>(txn), true);
+}
+
+void MessageStoreImpl::abort(qpid::broker::TransactionContext& ctxt)
+{
+ checkInit();
+ TxnCtxt* txn(check(&ctxt));
+ if (!txn->isTPC()) {
+ if (txn->impactedQueuesEmpty()) return;
+ localPrepare(dynamic_cast<TxnCtxt*>(txn));
+ }
+ completed(*dynamic_cast<TxnCtxt*>(txn), false);
+}
+
+TxnCtxt* MessageStoreImpl::check(qpid::broker::TransactionContext* ctxt)
+{
+ TxnCtxt* txn = dynamic_cast<TxnCtxt*>(ctxt);
+ if(!txn) throw qpid::broker::InvalidTransactionContextException();
+ return txn;
+}
+
+void MessageStoreImpl::put(db_ptr db,
+ DbTxn* txn,
+ Dbt& key,
+ Dbt& value)
+{
+ try {
+ int status = db->put(txn, &key, &value, DB_NODUPDATA);
+ if (status == DB_KEYEXIST) {
+ THROW_STORE_EXCEPTION("duplicate data");
+ } else if (status) {
+ THROW_STORE_EXCEPTION(DbEnv::strerror(status));
+ }
+ } catch (const DbException& e) {
+ THROW_STORE_EXCEPTION(e.what());
+ }
+}
+
+void MessageStoreImpl::deleteBindingsForQueue(const qpid::broker::PersistableQueue& queue)
+{
+ TxnCtxt txn;
+ txn.begin(dbenv.get(), true);
+ try {
+ {
+ Cursor bindings;
+ bindings.open(bindingDb, txn.get());
+
+ IdDbt key;
+ Dbt value;
+ while (bindings.next(key, value)) {
+ qpid::framing::Buffer buffer(reinterpret_cast<char*>(value.get_data()), value.get_size());
+ if (buffer.available() < 8) {
+ THROW_STORE_EXCEPTION("Not enough data for binding");
+ }
+ uint64_t queueId = buffer.getLongLong();
+ if (queue.getPersistenceId() == queueId) {
+ bindings->del(0);
+ QPID_LOG(debug, "Deleting binding for " << queue.getName() << " " << key.id << "->" << queueId);
+ }
+ }
+ }
+ txn.commit();
+ } catch (const std::exception& e) {
+ txn.abort();
+ THROW_STORE_EXCEPTION_2("Error deleting bindings", e.what());
+ } catch (...) {
+ txn.abort();
+ throw;
+ }
+ QPID_LOG(debug, "Deleted all bindings for " << queue.getName() << ":" << queue.getPersistenceId());
+}
+
+void MessageStoreImpl::deleteBinding(const qpid::broker::PersistableExchange& exchange,
+ const qpid::broker::PersistableQueue& queue,
+ const std::string& bkey)
+{
+ TxnCtxt txn;
+ txn.begin(dbenv.get(), true);
+ try {
+ {
+ Cursor bindings;
+ bindings.open(bindingDb, txn.get());
+
+ IdDbt key(exchange.getPersistenceId());
+ Dbt value;
+
+ for (int status = bindings->get(&key, &value, DB_SET); status == 0; status = bindings->get(&key, &value, DB_NEXT_DUP)) {
+ qpid::framing::Buffer buffer(reinterpret_cast<char*>(value.get_data()), value.get_size());
+ if (buffer.available() < 8) {
+ THROW_STORE_EXCEPTION("Not enough data for binding");
+ }
+ uint64_t queueId = buffer.getLongLong();
+ if (queue.getPersistenceId() == queueId) {
+ std::string q;
+ std::string k;
+ buffer.getShortString(q);
+ buffer.getShortString(k);
+ if (bkey == k) {
+ bindings->del(0);
+ QPID_LOG(debug, "Deleting binding for " << queue.getName() << " " << key.id << "->" << queueId);
+ }
+ }
+ }
+ }
+ txn.commit();
+ } catch (const std::exception& e) {
+ txn.abort();
+ THROW_STORE_EXCEPTION_2("Error deleting bindings", e.what());
+ } catch (...) {
+ txn.abort();
+ throw;
+ }
+}
+
+std::string MessageStoreImpl::getJrnlBaseDir()
+{
+ std::ostringstream dir;
+ dir << storeDir << "/" << storeTopLevelDir << "/jrnl/" ;
+ return dir.str();
+}
+
+std::string MessageStoreImpl::getBdbBaseDir()
+{
+ std::ostringstream dir;
+ dir << storeDir << "/" << storeTopLevelDir << "/dat/" ;
+ return dir.str();
+}
+
+std::string MessageStoreImpl::getTplBaseDir()
+{
+ std::ostringstream dir;
+ dir << storeDir << "/" << storeTopLevelDir << "/tpl/" ;
+ return dir.str();
+}
+
+std::string MessageStoreImpl::getJrnlDir(const qpid::broker::PersistableQueue& queue) //for exmaple /var/rhm/ + queueDir/
+{
+ return getJrnlHashDir(queue.getName().c_str());
+}
+
+u_int32_t MessageStoreImpl::bHash(const std::string str)
+{
+ // Daniel Bernstein hash fn
+ u_int32_t h = 0;
+ for (std::string::const_iterator i = str.begin(); i < str.end(); i++)
+ h = 33*h + *i;
+ return h;
+}
+
+std::string MessageStoreImpl::getJrnlHashDir(const std::string& queueName) //for exmaple /var/rhm/ + queueDir/
+{
+ std::stringstream dir;
+ dir << getJrnlBaseDir() << std::hex << std::setfill('0') << std::setw(4);
+ dir << (bHash(queueName.c_str()) % 29); // Use a prime number for better distribution across dirs
+ dir << "/" << queueName << "/";
+ return dir.str();
+}
+
+std::string MessageStoreImpl::getStoreDir() const { return storeDir; }
+
+void MessageStoreImpl::journalDeleted(JournalImpl& j) {
+ qpid::sys::Mutex::ScopedLock sl(journalListLock);
+ journalList.erase(j.id());
+}
+
+MessageStoreImpl::StoreOptions::StoreOptions(const std::string& name) :
+ qpid::Options(name),
+ numJrnlFiles(defNumJrnlFiles),
+ autoJrnlExpand(defAutoJrnlExpand),
+ autoJrnlExpandMaxFiles(defAutoJrnlExpandMaxFiles),
+ jrnlFsizePgs(defJrnlFileSizePgs),
+ truncateFlag(defTruncateFlag),
+ wCachePageSizeKib(defWCachePageSize),
+ tplNumJrnlFiles(defTplNumJrnlFiles),
+ tplJrnlFsizePgs(defTplJrnlFileSizePgs),
+ tplWCachePageSizeKib(defTplWCachePageSize)
+{
+ std::ostringstream oss1;
+ oss1 << "Default number of files for each journal instance (queue). [Allowable values: " <<
+ JRNL_MIN_NUM_FILES << " - " << JRNL_MAX_NUM_FILES << "]";
+ std::ostringstream oss2;
+ oss2 << "Default size for each journal file in multiples of read pages (1 read page = 64KiB). [Allowable values: " <<
+ JRNL_MIN_FILE_SIZE / JRNL_RMGR_PAGE_SIZE << " - " << JRNL_MAX_FILE_SIZE / JRNL_RMGR_PAGE_SIZE << "]";
+ std::ostringstream oss3;
+ oss3 << "Number of files for transaction prepared list journal instance. [Allowable values: " <<
+ JRNL_MIN_NUM_FILES << " - " << JRNL_MAX_NUM_FILES << "]";
+ std::ostringstream oss4;
+ oss4 << "Size of each transaction prepared list journal file in multiples of read pages (1 read page = 64KiB) [Allowable values: " <<
+ JRNL_MIN_FILE_SIZE / JRNL_RMGR_PAGE_SIZE << " - " << JRNL_MAX_FILE_SIZE / JRNL_RMGR_PAGE_SIZE << "]";
+ addOptions()
+ ("store-dir", qpid::optValue(storeDir, "DIR"),
+ "Store directory location for persistence (instead of using --data-dir value). "
+ "Required if --no-data-dir is also used.")
+ ("num-jfiles", qpid::optValue(numJrnlFiles, "N"), oss1.str().c_str())
+ ("jfile-size-pgs", qpid::optValue(jrnlFsizePgs, "N"), oss2.str().c_str())
+// TODO: Uncomment these lines when auto-expand is enabled.
+// ("auto-expand", qpid::optValue(autoJrnlExpand, "yes|no"),
+// "If yes|true|1, allows journal to auto-expand by adding additional journal files as needed. "
+// "If no|false|0, the number of journal files will remain fixed (num-jfiles).")
+// ("max-auto-expand-jfiles", qpid::optValue(autoJrnlExpandMaxFiles, "N"),
+// "Maximum number of journal files allowed from auto-expanding; must be greater than --num-jfiles parameter.")
+ ("truncate", qpid::optValue(truncateFlag, "yes|no"),
+ "If yes|true|1, will truncate the store (discard any existing records). If no|false|0, will preserve "
+ "the existing store files for recovery.")
+ ("wcache-page-size", qpid::optValue(wCachePageSizeKib, "N"),
+ "Size of the pages in the write page cache in KiB. "
+ "Allowable values - powers of 2: 1, 2, 4, ... , 128. "
+ "Lower values decrease latency at the expense of throughput.")
+ ("tpl-num-jfiles", qpid::optValue(tplNumJrnlFiles, "N"), oss3.str().c_str())
+ ("tpl-jfile-size-pgs", qpid::optValue(tplJrnlFsizePgs, "N"), oss4.str().c_str())
+ ("tpl-wcache-page-size", qpid::optValue(tplWCachePageSizeKib, "N"),
+ "Size of the pages in the transaction prepared list write page cache in KiB. "
+ "Allowable values - powers of 2: 1, 2, 4, ... , 128. "
+ "Lower values decrease latency at the expense of throughput.")
+ ;
+}
+
+}}
diff --git a/cpp/src/qpid/legacystore/MessageStoreImpl.h b/cpp/src/qpid/legacystore/MessageStoreImpl.h
new file mode 100644
index 0000000000..68aceedfbb
--- /dev/null
+++ b/cpp/src/qpid/legacystore/MessageStoreImpl.h
@@ -0,0 +1,380 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_MESSAGESTOREIMPL_H
+#define QPID_LEGACYSTORE_MESSAGESTOREIMPL_H
+
+#include <string>
+
+#include "db-inc.h"
+#include "qpid/legacystore/Cursor.h"
+#include "qpid/legacystore/IdDbt.h"
+#include "qpid/legacystore/IdSequence.h"
+#include "qpid/legacystore/JournalImpl.h"
+#include "qpid/legacystore/jrnl/jcfg.h"
+#include "qpid/legacystore/PreparedTransaction.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/broker/MessageStore.h"
+#include "qpid/management/Manageable.h"
+#include "qmf/org/apache/qpid/legacystore/Store.h"
+#include "qpid/legacystore/TxnCtxt.h"
+
+// Assume DB_VERSION_MAJOR == 4
+#if (DB_VERSION_MINOR == 2)
+#include <errno.h>
+#define DB_BUFFER_SMALL ENOMEM
+#endif
+
+namespace qpid { namespace sys {
+class Timer;
+}}
+
+namespace mrg {
+namespace msgstore {
+
+/**
+ * An implementation of the MessageStore interface based on Berkeley DB
+ */
+class MessageStoreImpl : public qpid::broker::MessageStore, public qpid::management::Manageable
+{
+ public:
+ typedef boost::shared_ptr<Db> db_ptr;
+ typedef boost::shared_ptr<DbEnv> dbEnv_ptr;
+
+ struct StoreOptions : public qpid::Options {
+ StoreOptions(const std::string& name="Store Options");
+ std::string clusterName;
+ std::string storeDir;
+ u_int16_t numJrnlFiles;
+ bool autoJrnlExpand;
+ u_int16_t autoJrnlExpandMaxFiles;
+ u_int32_t jrnlFsizePgs;
+ bool truncateFlag;
+ u_int32_t wCachePageSizeKib;
+ u_int16_t tplNumJrnlFiles;
+ u_int32_t tplJrnlFsizePgs;
+ u_int32_t tplWCachePageSizeKib;
+ };
+
+ protected:
+ typedef std::map<u_int64_t, qpid::broker::RecoverableQueue::shared_ptr> queue_index;
+ typedef std::map<u_int64_t, qpid::broker::RecoverableExchange::shared_ptr> exchange_index;
+ typedef std::map<u_int64_t, qpid::broker::RecoverableMessage::shared_ptr> message_index;
+
+ typedef LockedMappings::map txn_lock_map;
+ typedef boost::ptr_list<PreparedTransaction> txn_list;
+
+ // Structs for Transaction Recover List (TPL) recover state
+ struct TplRecoverStruct {
+ u_int64_t rid; // rid of TPL record
+ bool deq_flag;
+ bool commit_flag;
+ bool tpc_flag;
+ TplRecoverStruct(const u_int64_t _rid, const bool _deq_flag, const bool _commit_flag, const bool _tpc_flag);
+ };
+ typedef TplRecoverStruct TplRecover;
+ typedef std::pair<std::string, TplRecover> TplRecoverMapPair;
+ typedef std::map<std::string, TplRecover> TplRecoverMap;
+ typedef TplRecoverMap::const_iterator TplRecoverMapCitr;
+
+ typedef std::map<std::string, JournalImpl*> JournalListMap;
+ typedef JournalListMap::iterator JournalListMapItr;
+
+ // Default store settings
+ static const u_int16_t defNumJrnlFiles = 8;
+ static const u_int32_t defJrnlFileSizePgs = 24;
+ static const bool defTruncateFlag = false;
+ static const u_int32_t defWCachePageSize = JRNL_WMGR_DEF_PAGE_SIZE * JRNL_DBLK_SIZE * JRNL_SBLK_SIZE / 1024;
+ static const u_int16_t defTplNumJrnlFiles = 8;
+ static const u_int32_t defTplJrnlFileSizePgs = 24;
+ static const u_int32_t defTplWCachePageSize = defWCachePageSize / 8;
+ // TODO: set defAutoJrnlExpand to true and defAutoJrnlExpandMaxFiles to 16 when auto-expand comes on-line
+ static const bool defAutoJrnlExpand = false;
+ static const u_int16_t defAutoJrnlExpandMaxFiles = 0;
+
+ static const std::string storeTopLevelDir;
+ static qpid::sys::Duration defJournalGetEventsTimeout;
+ static qpid::sys::Duration defJournalFlushTimeout;
+
+ std::list<db_ptr> dbs;
+ dbEnv_ptr dbenv;
+ db_ptr queueDb;
+ db_ptr configDb;
+ db_ptr exchangeDb;
+ db_ptr mappingDb;
+ db_ptr bindingDb;
+ db_ptr generalDb;
+
+ // Pointer to Transaction Prepared List (TPL) journal instance
+ boost::shared_ptr<TplJournalImpl> tplStorePtr;
+ TplRecoverMap tplRecoverMap;
+ qpid::sys::Mutex tplInitLock;
+ JournalListMap journalList;
+ qpid::sys::Mutex journalListLock;
+ qpid::sys::Mutex bdbLock;
+
+ IdSequence queueIdSequence;
+ IdSequence exchangeIdSequence;
+ IdSequence generalIdSequence;
+ IdSequence messageIdSequence;
+ std::string storeDir;
+ u_int16_t numJrnlFiles;
+ bool autoJrnlExpand;
+ u_int16_t autoJrnlExpandMaxFiles;
+ u_int32_t jrnlFsizeSblks;
+ bool truncateFlag;
+ u_int32_t wCachePgSizeSblks;
+ u_int16_t wCacheNumPages;
+ u_int16_t tplNumJrnlFiles;
+ u_int32_t tplJrnlFsizeSblks;
+ u_int32_t tplWCachePgSizeSblks;
+ u_int16_t tplWCacheNumPages;
+ u_int64_t highestRid;
+ bool isInit;
+ const char* envPath;
+ qpid::broker::Broker* broker;
+
+ qmf::org::apache::qpid::legacystore::Store::shared_ptr mgmtObject;
+ qpid::management::ManagementAgent* agent;
+
+
+ // Parameter validation and calculation
+ static u_int16_t chkJrnlNumFilesParam(const u_int16_t param,
+ const std::string paramName);
+ static u_int32_t chkJrnlFileSizeParam(const u_int32_t param,
+ const std::string paramName,
+ const u_int32_t wCachePgSizeSblks = 0);
+ static u_int32_t chkJrnlWrPageCacheSize(const u_int32_t param,
+ const std::string paramName,
+ const u_int16_t jrnlFsizePgs);
+ static u_int16_t getJrnlWrNumPages(const u_int32_t wrPageSizeKib);
+ void chkJrnlAutoExpandOptions(const MessageStoreImpl::StoreOptions* opts,
+ bool& autoJrnlExpand,
+ u_int16_t& autoJrnlExpandMaxFiles,
+ const std::string& autoJrnlExpandMaxFilesParamName,
+ const u_int16_t numJrnlFiles,
+ const std::string& numJrnlFilesParamName);
+
+ void init();
+
+ void recoverQueues(TxnCtxt& txn,
+ qpid::broker::RecoveryManager& recovery,
+ queue_index& index,
+ txn_list& locked,
+ message_index& messages);
+ void recoverMessages(TxnCtxt& txn,
+ qpid::broker::RecoveryManager& recovery,
+ queue_index& index,
+ txn_list& locked,
+ message_index& prepared);
+ void recoverMessages(TxnCtxt& txn,
+ qpid::broker::RecoveryManager& recovery,
+ qpid::broker::RecoverableQueue::shared_ptr& queue,
+ txn_list& locked,
+ message_index& prepared,
+ long& rcnt,
+ long& idcnt);
+ qpid::broker::RecoverableMessage::shared_ptr getExternMessage(qpid::broker::RecoveryManager& recovery,
+ uint64_t mId,
+ unsigned& headerSize);
+ void recoverExchanges(TxnCtxt& txn,
+ qpid::broker::RecoveryManager& recovery,
+ exchange_index& index);
+ void recoverBindings(TxnCtxt& txn,
+ exchange_index& exchanges,
+ queue_index& queues);
+ void recoverGeneral(TxnCtxt& txn,
+ qpid::broker::RecoveryManager& recovery);
+ int enqueueMessage(TxnCtxt& txn,
+ IdDbt& msgId,
+ qpid::broker::RecoverableMessage::shared_ptr& msg,
+ queue_index& index,
+ txn_list& locked,
+ message_index& prepared);
+ void readTplStore();
+ void recoverTplStore();
+ void recoverLockedMappings(txn_list& txns);
+ TxnCtxt* check(qpid::broker::TransactionContext* ctxt);
+ u_int64_t msgEncode(std::vector<char>& buff, const boost::intrusive_ptr<qpid::broker::PersistableMessage>& message);
+ void store(const qpid::broker::PersistableQueue* queue,
+ TxnCtxt* txn,
+ const boost::intrusive_ptr<qpid::broker::PersistableMessage>& message,
+ bool newId);
+ void async_dequeue(qpid::broker::TransactionContext* ctxt,
+ const boost::intrusive_ptr<qpid::broker::PersistableMessage>& msg,
+ const qpid::broker::PersistableQueue& queue);
+ void destroy(db_ptr db,
+ const qpid::broker::Persistable& p);
+ bool create(db_ptr db,
+ IdSequence& seq,
+ const qpid::broker::Persistable& p);
+ void completed(TxnCtxt& txn,
+ bool commit);
+ void deleteBindingsForQueue(const qpid::broker::PersistableQueue& queue);
+ void deleteBinding(const qpid::broker::PersistableExchange& exchange,
+ const qpid::broker::PersistableQueue& queue,
+ const std::string& key);
+
+ void put(db_ptr db,
+ DbTxn* txn,
+ Dbt& key,
+ Dbt& value);
+ void open(db_ptr db,
+ DbTxn* txn,
+ const char* file,
+ bool dupKey);
+ void closeDbs();
+
+ // journal functions
+ void createJrnlQueue(const qpid::broker::PersistableQueue& queue);
+ u_int32_t bHash(const std::string str);
+ std::string getJrnlDir(const qpid::broker::PersistableQueue& queue); //for exmaple /var/rhm/ + queueDir/
+ std::string getJrnlHashDir(const std::string& queueName);
+ std::string getJrnlBaseDir();
+ std::string getBdbBaseDir();
+ std::string getTplBaseDir();
+ inline void checkInit() {
+ // TODO: change the default dir to ~/.qpidd
+ if (!isInit) { init("/tmp"); isInit = true; }
+ }
+ void chkTplStoreInit();
+
+ // debug aid for printing XIDs that may contain non-printable chars
+ static std::string xid2str(const std::string xid) {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ for (unsigned i=0; i<xid.size(); i++) {
+ if (isprint(xid[i]))
+ oss << xid[i];
+ else
+ oss << "/" << std::setw(2) << (int)((char)xid[i]);
+ }
+ return oss.str();
+ }
+
+ public:
+ typedef boost::shared_ptr<MessageStoreImpl> shared_ptr;
+
+ MessageStoreImpl(qpid::broker::Broker* broker, const char* envpath = 0);
+
+ virtual ~MessageStoreImpl();
+
+ bool init(const qpid::Options* options);
+
+ bool init(const std::string& dir,
+ u_int16_t jfiles = defNumJrnlFiles,
+ u_int32_t jfileSizePgs = defJrnlFileSizePgs,
+ const bool truncateFlag = false,
+ u_int32_t wCachePageSize = defWCachePageSize,
+ u_int16_t tplJfiles = defTplNumJrnlFiles,
+ u_int32_t tplJfileSizePgs = defTplJrnlFileSizePgs,
+ u_int32_t tplWCachePageSize = defTplWCachePageSize,
+ bool autoJExpand = defAutoJrnlExpand,
+ u_int16_t autoJExpandMaxFiles = defAutoJrnlExpandMaxFiles);
+
+ void truncateInit(const bool saveStoreContent = false);
+
+ void initManagement ();
+
+ void finalize();
+
+ void create(qpid::broker::PersistableQueue& queue,
+ const qpid::framing::FieldTable& args);
+
+ void destroy(qpid::broker::PersistableQueue& queue);
+
+ void create(const qpid::broker::PersistableExchange& queue,
+ const qpid::framing::FieldTable& args);
+
+ void destroy(const qpid::broker::PersistableExchange& queue);
+
+ void bind(const qpid::broker::PersistableExchange& exchange,
+ const qpid::broker::PersistableQueue& queue,
+ const std::string& key,
+ const qpid::framing::FieldTable& args);
+
+ void unbind(const qpid::broker::PersistableExchange& exchange,
+ const qpid::broker::PersistableQueue& queue,
+ const std::string& key,
+ const qpid::framing::FieldTable& args);
+
+ void create(const qpid::broker::PersistableConfig& config);
+
+ void destroy(const qpid::broker::PersistableConfig& config);
+
+ void recover(qpid::broker::RecoveryManager& queues);
+
+ void stage(const boost::intrusive_ptr<qpid::broker::PersistableMessage>& msg);
+
+ void destroy(qpid::broker::PersistableMessage& msg);
+
+ void appendContent(const boost::intrusive_ptr<const qpid::broker::PersistableMessage>& msg,
+ const std::string& data);
+
+ void loadContent(const qpid::broker::PersistableQueue& queue,
+ const boost::intrusive_ptr<const qpid::broker::PersistableMessage>& msg,
+ std::string& data,
+ uint64_t offset,
+ uint32_t length);
+
+ void enqueue(qpid::broker::TransactionContext* ctxt,
+ const boost::intrusive_ptr<qpid::broker::PersistableMessage>& msg,
+ const qpid::broker::PersistableQueue& queue);
+
+ void dequeue(qpid::broker::TransactionContext* ctxt,
+ const boost::intrusive_ptr<qpid::broker::PersistableMessage>& msg,
+ const qpid::broker::PersistableQueue& queue);
+
+ void flush(const qpid::broker::PersistableQueue& queue);
+
+ u_int32_t outstandingQueueAIO(const qpid::broker::PersistableQueue& queue);
+
+ void collectPreparedXids(std::set<std::string>& xids);
+
+ std::auto_ptr<qpid::broker::TransactionContext> begin();
+
+ std::auto_ptr<qpid::broker::TPCTransactionContext> begin(const std::string& xid);
+
+ void prepare(qpid::broker::TPCTransactionContext& ctxt);
+
+ void localPrepare(TxnCtxt* ctxt);
+
+ void commit(qpid::broker::TransactionContext& ctxt);
+
+ void abort(qpid::broker::TransactionContext& ctxt);
+
+ qpid::management::ManagementObject::shared_ptr GetManagementObject (void) const
+ { return mgmtObject; }
+
+ inline qpid::management::Manageable::status_t ManagementMethod (u_int32_t, qpid::management::Args&, std::string&)
+ { return qpid::management::Manageable::STATUS_OK; }
+
+ std::string getStoreDir() const;
+
+ private:
+ void journalDeleted(JournalImpl&);
+
+}; // class MessageStoreImpl
+
+} // namespace msgstore
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_MESSAGESTOREIMPL_H
diff --git a/cpp/src/qpid/legacystore/PreparedTransaction.cpp b/cpp/src/qpid/legacystore/PreparedTransaction.cpp
new file mode 100644
index 0000000000..50b81e2824
--- /dev/null
+++ b/cpp/src/qpid/legacystore/PreparedTransaction.cpp
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/legacystore/PreparedTransaction.h"
+#include <algorithm>
+
+using namespace mrg::msgstore;
+using std::string;
+
+void LockedMappings::add(queue_id queue, message_id message)
+{
+ locked.push_back(std::make_pair(queue, message));
+}
+
+bool LockedMappings::isLocked(queue_id queue, message_id message)
+{
+ idpair op( std::make_pair(queue, message) );
+ return find(locked.begin(), locked.end(), op) != locked.end();
+}
+
+void LockedMappings::add(LockedMappings::map& map, std::string& key, queue_id queue, message_id message)
+{
+ LockedMappings::map::iterator i = map.find(key);
+ if (i == map.end()) {
+ LockedMappings::shared_ptr ptr(new LockedMappings());
+ i = map.insert(std::make_pair(key, ptr)).first;
+ }
+ i->second->add(queue, message);
+}
+
+bool PreparedTransaction::isLocked(queue_id queue, message_id message)
+{
+ return (enqueues.get() && enqueues->isLocked(queue, message))
+ || (dequeues.get() && dequeues->isLocked(queue, message));
+}
+
+
+bool PreparedTransaction::isLocked(PreparedTransaction::list& txns, queue_id queue, message_id message)
+{
+ for (PreparedTransaction::list::iterator i = txns.begin(); i != txns.end(); i++) {
+ if (i->isLocked(queue, message)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+PreparedTransaction::list::iterator PreparedTransaction::getLockedPreparedTransaction(PreparedTransaction::list& txns, queue_id queue, message_id message)
+{
+ for (PreparedTransaction::list::iterator i = txns.begin(); i != txns.end(); i++) {
+ if (i->isLocked(queue, message)) {
+ return i;
+ }
+ }
+ return txns.end();
+}
+
+PreparedTransaction::PreparedTransaction(const std::string& _xid,
+ LockedMappings::shared_ptr _enqueues,
+ LockedMappings::shared_ptr _dequeues)
+
+ : xid(_xid), enqueues(_enqueues), dequeues(_dequeues) {}
+
diff --git a/cpp/src/qpid/legacystore/PreparedTransaction.h b/cpp/src/qpid/legacystore/PreparedTransaction.h
new file mode 100644
index 0000000000..c5f7b9458a
--- /dev/null
+++ b/cpp/src/qpid/legacystore/PreparedTransaction.h
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_PREPAREDTRANSACTION_H
+#define QPID_LEGACYSTORE_PREPAREDTRANSACTION_H
+
+#include <list>
+#include <map>
+#include <set>
+#include <string>
+#include <boost/shared_ptr.hpp>
+#include <boost/ptr_container/ptr_list.hpp>
+
+namespace mrg{
+namespace msgstore{
+
+typedef u_int64_t queue_id;
+typedef u_int64_t message_id;
+
+class LockedMappings
+{
+public:
+ typedef boost::shared_ptr<LockedMappings> shared_ptr;
+ typedef std::map<std::string, shared_ptr> map;
+ typedef std::pair<queue_id, message_id> idpair;
+ typedef std::list<idpair>::iterator iterator;
+
+ void add(queue_id queue, message_id message);
+ bool isLocked(queue_id queue, message_id message);
+ std::size_t size() { return locked.size(); }
+ iterator begin() { return locked.begin(); }
+ iterator end() { return locked.end(); }
+
+ static void add(LockedMappings::map& map, std::string& key, queue_id queue, message_id message);
+
+private:
+ std::list<idpair> locked;
+};
+
+struct PreparedTransaction
+{
+ typedef boost::ptr_list<PreparedTransaction> list;
+
+ const std::string xid;
+ const LockedMappings::shared_ptr enqueues;
+ const LockedMappings::shared_ptr dequeues;
+
+ PreparedTransaction(const std::string& xid, LockedMappings::shared_ptr enqueues, LockedMappings::shared_ptr dequeues);
+ bool isLocked(queue_id queue, message_id message);
+ static bool isLocked(PreparedTransaction::list& txns, queue_id queue, message_id message);
+ static PreparedTransaction::list::iterator getLockedPreparedTransaction(PreparedTransaction::list& txns, queue_id queue, message_id message);
+};
+
+}}
+
+#endif // ifndef QPID_LEGACYSTORE_PREPAREDTRANSACTION_H
diff --git a/cpp/src/qpid/legacystore/StoreException.h b/cpp/src/qpid/legacystore/StoreException.h
new file mode 100644
index 0000000000..6624aafd5a
--- /dev/null
+++ b/cpp/src/qpid/legacystore/StoreException.h
@@ -0,0 +1,56 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_STOREEXCEPTION_H
+#define QPID_LEGACYSTORE_STOREEXCEPTION_H
+
+#include "qpid/legacystore/IdDbt.h"
+#include <boost/format.hpp>
+
+namespace mrg{
+namespace msgstore{
+
+class StoreException : public std::exception
+{
+ std::string text;
+public:
+ StoreException(const std::string& _text) : text(_text) {}
+ StoreException(const std::string& _text, const DbException& cause) : text(_text + ": " + cause.what()) {}
+ virtual ~StoreException() throw() {}
+ virtual const char* what() const throw() { return text.c_str(); }
+};
+
+class StoreFullException : public StoreException
+{
+public:
+ StoreFullException(const std::string& _text) : StoreException(_text) {}
+ StoreFullException(const std::string& _text, const DbException& cause) : StoreException(_text, cause) {}
+ virtual ~StoreFullException() throw() {}
+
+};
+
+#define THROW_STORE_EXCEPTION(MESSAGE) throw StoreException(boost::str(boost::format("%s (%s:%d)") % (MESSAGE) % __FILE__ % __LINE__))
+#define THROW_STORE_EXCEPTION_2(MESSAGE, EXCEPTION) throw StoreException(boost::str(boost::format("%s (%s:%d)") % (MESSAGE) % __FILE__ % __LINE__), EXCEPTION)
+#define THROW_STORE_FULL_EXCEPTION(MESSAGE) throw StoreFullException(boost::str(boost::format("%s (%s:%d)") % (MESSAGE) % __FILE__ % __LINE__))
+
+}}
+
+#endif // ifndef QPID_LEGACYSTORE_STOREEXCEPTION_H
diff --git a/cpp/src/qpid/legacystore/StorePlugin.cpp b/cpp/src/qpid/legacystore/StorePlugin.cpp
new file mode 100644
index 0000000000..f9b77ce02c
--- /dev/null
+++ b/cpp/src/qpid/legacystore/StorePlugin.cpp
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/broker/Broker.h"
+#include "qpid/Plugin.h"
+#include "qpid/Options.h"
+#include "qpid/DataDir.h"
+#include "qpid/log/Statement.h"
+#include "qpid/legacystore/MessageStoreImpl.h"
+
+using mrg::msgstore::MessageStoreImpl;
+
+namespace qpid {
+namespace broker {
+
+using namespace std;
+
+struct StorePlugin : public Plugin {
+
+ MessageStoreImpl::StoreOptions options;
+ boost::shared_ptr<MessageStoreImpl> store;
+
+ Options* getOptions() { return &options; }
+
+ void earlyInitialize (Plugin::Target& target)
+ {
+ Broker* broker = dynamic_cast<Broker*>(&target);
+ if (!broker) return;
+ store.reset(new MessageStoreImpl(broker));
+ DataDir& dataDir = broker->getDataDir ();
+ if (options.storeDir.empty ())
+ {
+ if (!dataDir.isEnabled ())
+ throw Exception ("msgstore: If --data-dir is blank or --no-data-dir is specified, --store-dir must be present.");
+
+ options.storeDir = dataDir.getPath ();
+ }
+ store->init(&options);
+ boost::shared_ptr<qpid::broker::MessageStore> brokerStore(store);
+ broker->setStore(brokerStore);
+ target.addFinalizer(boost::bind(&StorePlugin::finalize, this));
+ }
+
+ void initialize(Plugin::Target& target)
+ {
+ Broker* broker = dynamic_cast<Broker*>(&target);
+ if (!broker) return;
+ if (!store) return;
+ QPID_LOG(info, "Enabling management instrumentation for the store.");
+ store->initManagement();
+ }
+
+ void finalize()
+ {
+ store.reset();
+ }
+
+ const char* id() {return "StorePlugin";}
+};
+
+static StorePlugin instance; // Static initialization.
+
+}} // namespace qpid::broker
diff --git a/cpp/src/qpid/legacystore/TxnCtxt.cpp b/cpp/src/qpid/legacystore/TxnCtxt.cpp
new file mode 100644
index 0000000000..1db41f4c70
--- /dev/null
+++ b/cpp/src/qpid/legacystore/TxnCtxt.cpp
@@ -0,0 +1,184 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/legacystore/TxnCtxt.h"
+
+#include <sstream>
+
+#include "qpid/legacystore/jrnl/jexception.h"
+#include "qpid/legacystore/StoreException.h"
+
+namespace mrg {
+namespace msgstore {
+
+void TxnCtxt::completeTxn(bool commit) {
+ sync();
+ for (ipqItr i = impactedQueues.begin(); i != impactedQueues.end(); i++) {
+ commitTxn(static_cast<JournalImpl*>(*i), commit);
+ }
+ impactedQueues.clear();
+ if (preparedXidStorePtr)
+ commitTxn(preparedXidStorePtr, commit);
+}
+
+void TxnCtxt::commitTxn(JournalImpl* jc, bool commit) {
+ if (jc && loggedtx) { /* if using journal */
+ boost::intrusive_ptr<DataTokenImpl> dtokp(new DataTokenImpl);
+ dtokp->addRef();
+ dtokp->set_external_rid(true);
+ dtokp->set_rid(loggedtx->next());
+ try {
+ if (commit) {
+ jc->txn_commit(dtokp.get(), getXid());
+ sync();
+ } else {
+ jc->txn_abort(dtokp.get(), getXid());
+ }
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("Error commit") + e.what());
+ }
+ }
+}
+
+// static
+uuid_t TxnCtxt::uuid;
+
+// static
+IdSequence TxnCtxt::uuidSeq;
+
+// static
+bool TxnCtxt::staticInit = TxnCtxt::setUuid();
+
+// static
+bool TxnCtxt::setUuid() {
+ ::uuid_generate(uuid);
+ return true;
+}
+
+TxnCtxt::TxnCtxt(IdSequence* _loggedtx) : loggedtx(_loggedtx), dtokp(new DataTokenImpl), preparedXidStorePtr(0), txn(0) {
+ if (loggedtx) {
+// // Human-readable tid: 53 bytes
+// // uuit_t is a char[16]
+// tid.reserve(53);
+// u_int64_t* u1 = (u_int64_t*)uuid;
+// u_int64_t* u2 = (u_int64_t*)(uuid + sizeof(u_int64_t));
+// std::stringstream s;
+// s << "tid:" << std::hex << std::setfill('0') << std::setw(16) << uuidSeq.next() << ":" << std::setw(16) << *u1 << std::setw(16) << *u2;
+// tid.assign(s.str());
+
+ // Binary tid: 24 bytes
+ tid.reserve(24);
+ u_int64_t c = uuidSeq.next();
+ tid.append((char*)&c, sizeof(c));
+ tid.append((char*)&uuid, sizeof(uuid));
+ }
+}
+
+TxnCtxt::TxnCtxt(std::string _tid, IdSequence* _loggedtx) : loggedtx(_loggedtx), dtokp(new DataTokenImpl), preparedXidStorePtr(0), tid(_tid), txn(0) {}
+
+TxnCtxt::~TxnCtxt() { abort(); }
+
+void TxnCtxt::sync() {
+ if (loggedtx) {
+ try {
+ for (ipqItr i = impactedQueues.begin(); i != impactedQueues.end(); i++)
+ jrnl_flush(static_cast<JournalImpl*>(*i));
+ if (preparedXidStorePtr)
+ jrnl_flush(preparedXidStorePtr);
+ for (ipqItr i = impactedQueues.begin(); i != impactedQueues.end(); i++)
+ jrnl_sync(static_cast<JournalImpl*>(*i), &journal::jcntl::_aio_cmpl_timeout);
+ if (preparedXidStorePtr)
+ jrnl_sync(preparedXidStorePtr, &journal::jcntl::_aio_cmpl_timeout);
+ } catch (const journal::jexception& e) {
+ THROW_STORE_EXCEPTION(std::string("Error during txn sync: ") + e.what());
+ }
+ }
+}
+
+void TxnCtxt::jrnl_flush(JournalImpl* jc) {
+ if (jc && !(jc->is_txn_synced(getXid())))
+ jc->flush();
+}
+
+void TxnCtxt::jrnl_sync(JournalImpl* jc, timespec* timeout) {
+ if (!jc || jc->is_txn_synced(getXid()))
+ return;
+ while (jc->get_wr_aio_evt_rem()) {
+ if (jc->get_wr_events(timeout) == journal::jerrno::AIO_TIMEOUT && timeout)
+ THROW_STORE_EXCEPTION(std::string("Error: timeout waiting for TxnCtxt::jrnl_sync()"));
+ }
+}
+
+void TxnCtxt::begin(DbEnv* env, bool sync) {
+ int err;
+ try { err = env->txn_begin(0, &txn, 0); }
+ catch (const DbException&) { txn = 0; throw; }
+ if (err != 0) {
+ std::ostringstream oss;
+ oss << "Error: Env::txn_begin() returned error code: " << err;
+ THROW_STORE_EXCEPTION(oss.str());
+ }
+ if (sync)
+ globalHolder = AutoScopedLock(new qpid::sys::Mutex::ScopedLock(globalSerialiser));
+}
+
+void TxnCtxt::commit() {
+ if (txn) {
+ txn->commit(0);
+ txn = 0;
+ globalHolder.reset();
+ }
+}
+
+void TxnCtxt::abort(){
+ if (txn) {
+ txn->abort();
+ txn = 0;
+ globalHolder.reset();
+ }
+}
+
+DbTxn* TxnCtxt::get() { return txn; }
+
+bool TxnCtxt::isTPC() { return false; }
+
+const std::string& TxnCtxt::getXid() { return tid; }
+
+void TxnCtxt::addXidRecord(qpid::broker::ExternalQueueStore* queue) { impactedQueues.insert(queue); }
+
+void TxnCtxt::complete(bool commit) { completeTxn(commit); }
+
+bool TxnCtxt::impactedQueuesEmpty() { return impactedQueues.empty(); }
+
+DataTokenImpl* TxnCtxt::getDtok() { return dtokp.get(); }
+
+void TxnCtxt::incrDtokRef() { dtokp->addRef(); }
+
+void TxnCtxt::recoverDtok(const u_int64_t rid, const std::string xid) {
+ dtokp->set_rid(rid);
+ dtokp->set_wstate(DataTokenImpl::ENQ);
+ dtokp->set_xid(xid);
+ dtokp->set_external_rid(true);
+}
+
+TPCTxnCtxt::TPCTxnCtxt(const std::string& _xid, IdSequence* _loggedtx) : TxnCtxt(_loggedtx), xid(_xid) {}
+
+}}
diff --git a/cpp/src/qpid/legacystore/TxnCtxt.h b/cpp/src/qpid/legacystore/TxnCtxt.h
new file mode 100644
index 0000000000..77eaa27cd7
--- /dev/null
+++ b/cpp/src/qpid/legacystore/TxnCtxt.h
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef QPID_LEGACYSTORE_TXNCTXT_H
+#define QPID_LEGACYSTORE_TXNCTXT_H
+
+#include "db-inc.h"
+#include <memory>
+#include <set>
+#include <string>
+
+#include "qpid/legacystore/DataTokenImpl.h"
+#include "qpid/legacystore/IdSequence.h"
+#include "qpid/legacystore/JournalImpl.h"
+#include "qpid/broker/PersistableQueue.h"
+#include "qpid/broker/TransactionalStore.h"
+#include "qpid/sys/Mutex.h"
+#include "qpid/sys/uuid.h"
+
+#include <boost/intrusive_ptr.hpp>
+
+namespace mrg {
+namespace msgstore {
+
+class TxnCtxt : public qpid::broker::TransactionContext
+{
+ protected:
+ static qpid::sys::Mutex globalSerialiser;
+
+ static uuid_t uuid;
+ static IdSequence uuidSeq;
+ static bool staticInit;
+ static bool setUuid();
+
+ typedef std::set<qpid::broker::ExternalQueueStore*> ipqdef;
+ typedef ipqdef::iterator ipqItr;
+ typedef std::auto_ptr<qpid::sys::Mutex::ScopedLock> AutoScopedLock;
+
+ ipqdef impactedQueues; // list of Queues used in the txn
+ IdSequence* loggedtx;
+ boost::intrusive_ptr<DataTokenImpl> dtokp;
+ AutoScopedLock globalHolder;
+ JournalImpl* preparedXidStorePtr;
+
+ /**
+ * local txn id, if non XA.
+ */
+ std::string tid;
+ DbTxn* txn;
+
+ virtual void completeTxn(bool commit);
+ void commitTxn(JournalImpl* jc, bool commit);
+ void jrnl_flush(JournalImpl* jc);
+ void jrnl_sync(JournalImpl* jc, timespec* timeout);
+
+ public:
+ TxnCtxt(IdSequence* _loggedtx=NULL);
+ TxnCtxt(std::string _tid, IdSequence* _loggedtx);
+ virtual ~TxnCtxt();
+
+ /**
+ * Call to make sure all the data for this txn is written to safe store
+ *
+ *@return if the data successfully synced.
+ */
+ void sync();
+ void begin(DbEnv* env, bool sync = false);
+ void commit();
+ void abort();
+ DbTxn* get();
+ virtual bool isTPC();
+ virtual const std::string& getXid();
+
+ void addXidRecord(qpid::broker::ExternalQueueStore* queue);
+ inline void prepare(JournalImpl* _preparedXidStorePtr) { preparedXidStorePtr = _preparedXidStorePtr; }
+ void complete(bool commit);
+ bool impactedQueuesEmpty();
+ DataTokenImpl* getDtok();
+ void incrDtokRef();
+ void recoverDtok(const u_int64_t rid, const std::string xid);
+};
+
+
+class TPCTxnCtxt : public TxnCtxt, public qpid::broker::TPCTransactionContext
+{
+ protected:
+ const std::string xid;
+
+ public:
+ TPCTxnCtxt(const std::string& _xid, IdSequence* _loggedtx);
+ inline virtual bool isTPC() { return true; }
+ inline virtual const std::string& getXid() { return xid; }
+};
+
+}}
+
+#endif // ifndef QPID_LEGACYSTORE_TXNCTXT_H
+
+
diff --git a/cpp/src/qpid/legacystore/jrnl/aio.cpp b/cpp/src/qpid/legacystore/jrnl/aio.cpp
new file mode 100644
index 0000000000..ffbddd887e
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/aio.cpp
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file aio.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::aio (libaio interface
+ * encapsulation). See comments in file aio.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/aio.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/aio.h b/cpp/src/qpid/legacystore/jrnl/aio.h
new file mode 100644
index 0000000000..b1de5f79f7
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/aio.h
@@ -0,0 +1,153 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file aio.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains an encapsulation of the libaio interface used
+ * by the journal.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_AIO_H
+#define QPID_LEGACYSTORE_JRNL_AIO_H
+
+#include <libaio.h>
+#include <cstring>
+#include <sys/types.h>
+#include <string.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+typedef iocb aio_cb;
+typedef io_event aio_event;
+
+/**
+ * \brief This class is a C++ wrapper class for the libaio functions used by the journal. Note that only those
+ * functions used by the journal are included here. This is not a complete implementation of all libaio functions.
+ */
+class aio
+{
+public:
+ static inline int queue_init(int maxevents, io_context_t* ctxp)
+ {
+ return ::io_queue_init(maxevents, ctxp);
+ }
+
+ static inline int queue_release(io_context_t ctx)
+ {
+ return ::io_queue_release(ctx);
+ }
+
+ static inline int submit(io_context_t ctx, long nr, aio_cb* aios[])
+ {
+ return ::io_submit(ctx, nr, aios);
+ }
+
+ static inline int getevents(io_context_t ctx, long min_nr, long nr, aio_event* events, timespec* const timeout)
+ {
+ return ::io_getevents(ctx, min_nr, nr, events, timeout);
+ }
+
+ /**
+ * \brief This function allows iocbs to be initialized with a pointer that can be re-used. This prepares an
+ * aio_cb struct for read use. (This is a wrapper for libaio's ::io_prep_pread() function.)
+ *
+ * \param aiocbp Pointer to the aio_cb struct to be prepared.
+ * \param fd File descriptor to be used for read.
+ * \param buf Pointer to buffer in which read data is to be placed.
+ * \param count Number of bytes to read - buffer must be large enough.
+ * \param offset Offset within file from which data will be read.
+ */
+ static inline void prep_pread(aio_cb* aiocbp, int fd, void* buf, std::size_t count, int64_t offset)
+ {
+ ::io_prep_pread(aiocbp, fd, buf, count, offset);
+ }
+
+ /**
+ * \brief Special version of libaio's io_prep_pread() which preserves the value of the data pointer. This allows
+ * iocbs to be initialized with a pointer that can be re-used. This prepares a aio_cb struct for read use.
+ *
+ * \param aiocbp Pointer to the aio_cb struct to be prepared.
+ * \param fd File descriptor to be used for read.
+ * \param buf Pointer to buffer in which read data is to be placed.
+ * \param count Number of bytes to read - buffer must be large enough.
+ * \param offset Offset within file from which data will be read.
+ */
+ static inline void prep_pread_2(aio_cb* aiocbp, int fd, void* buf, std::size_t count, int64_t offset)
+ {
+ std::memset((void*) ((char*) aiocbp + sizeof(void*)), 0, sizeof(aio_cb) - sizeof(void*));
+ aiocbp->aio_fildes = fd;
+ aiocbp->aio_lio_opcode = IO_CMD_PREAD;
+ aiocbp->aio_reqprio = 0;
+ aiocbp->u.c.buf = buf;
+ aiocbp->u.c.nbytes = count;
+ aiocbp->u.c.offset = offset;
+ }
+
+ /**
+ * \brief This function allows iocbs to be initialized with a pointer that can be re-used. This function prepares
+ * an aio_cb struct for write use. (This is a wrapper for libaio's ::io_prep_pwrite() function.)
+ *
+ * \param aiocbp Pointer to the aio_cb struct to be prepared.
+ * \param fd File descriptor to be used for write.
+ * \param buf Pointer to buffer in which data to be written is located.
+ * \param count Number of bytes to write.
+ * \param offset Offset within file to which data will be written.
+ */
+ static inline void prep_pwrite(aio_cb* aiocbp, int fd, void* buf, std::size_t count, int64_t offset)
+ {
+ ::io_prep_pwrite(aiocbp, fd, buf, count, offset);
+ }
+
+ /**
+ * \brief Special version of libaio's io_prep_pwrite() which preserves the value of the data pointer. This allows
+ * iocbs to be initialized with a pointer that can be re-used. This function prepares an aio_cb struct for write
+ * use.
+ *
+ * \param aiocbp Pointer to the aio_cb struct to be prepared.
+ * \param fd File descriptor to be used for write.
+ * \param buf Pointer to buffer in which data to be written is located.
+ * \param count Number of bytes to write.
+ * \param offset Offset within file to which data will be written.
+ */
+ static inline void prep_pwrite_2(aio_cb* aiocbp, int fd, void* buf, std::size_t count, int64_t offset)
+ {
+ std::memset((void*) ((char*) aiocbp + sizeof(void*)), 0, sizeof(aio_cb) - sizeof(void*));
+ aiocbp->aio_fildes = fd;
+ aiocbp->aio_lio_opcode = IO_CMD_PWRITE;
+ aiocbp->aio_reqprio = 0;
+ aiocbp->u.c.buf = buf;
+ aiocbp->u.c.nbytes = count;
+ aiocbp->u.c.offset = offset;
+ }
+};
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_AIO_H
diff --git a/cpp/src/qpid/legacystore/jrnl/aio_callback.h b/cpp/src/qpid/legacystore/jrnl/aio_callback.h
new file mode 100644
index 0000000000..90249278a5
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/aio_callback.h
@@ -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.
+ *
+ */
+
+/**
+ * \file aio_callback.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the definition for the AIO callback function
+ * pointer.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_AIO_CALLBACK_H
+#define QPID_LEGACYSTORE_JRNL_AIO_CALLBACK_H
+
+#include <vector>
+#include <sys/types.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+ class data_tok;
+
+ class aio_callback
+ {
+ public:
+ virtual ~aio_callback() {}
+ virtual void wr_aio_cb(std::vector<data_tok*>& dtokl) = 0;
+ virtual void rd_aio_cb(std::vector<u_int16_t>& pil) = 0;
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_AIO_CALLBACK_H
diff --git a/cpp/src/qpid/legacystore/jrnl/cvar.cpp b/cpp/src/qpid/legacystore/jrnl/cvar.cpp
new file mode 100644
index 0000000000..e4010bf91f
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/cvar.cpp
@@ -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.
+ *
+ */
+
+/**
+ * \file cvar.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::cvar (condition variable). See
+ * comments in file cvar.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/cvar.h"
diff --git a/cpp/src/qpid/legacystore/jrnl/cvar.h b/cpp/src/qpid/legacystore/jrnl/cvar.h
new file mode 100644
index 0000000000..0498e743a2
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/cvar.h
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file cvar.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains a posix condition variable class.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_CVAR_H
+#define QPID_LEGACYSTORE_JRNL_CVAR_H
+
+#include <cstring>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include "qpid/legacystore/jrnl/smutex.h"
+#include "qpid/legacystore/jrnl/time_ns.h"
+#include <pthread.h>
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+ // Ultra-simple thread condition variable class
+ class cvar
+ {
+ private:
+ const smutex& _sm;
+ pthread_cond_t _c;
+ public:
+ inline cvar(const smutex& sm) : _sm(sm) { ::pthread_cond_init(&_c, 0); }
+ inline ~cvar() { ::pthread_cond_destroy(&_c); }
+ inline void wait()
+ {
+ PTHREAD_CHK(::pthread_cond_wait(&_c, _sm.get()), "::pthread_cond_wait", "cvar", "wait");
+ }
+ inline void timedwait(timespec& ts)
+ {
+ PTHREAD_CHK(::pthread_cond_timedwait(&_c, _sm.get(), &ts), "::pthread_cond_timedwait", "cvar", "timedwait");
+ }
+ inline bool waitintvl(const long intvl_ns)
+ {
+ time_ns t; t.now(); t+=intvl_ns;
+ int ret = ::pthread_cond_timedwait(&_c, _sm.get(), &t);
+ if (ret == ETIMEDOUT)
+ return true;
+ PTHREAD_CHK(ret, "::pthread_cond_timedwait", "cvar", "waitintvl");
+ return false;
+ }
+ inline void signal()
+ {
+ PTHREAD_CHK(::pthread_cond_signal(&_c), "::pthread_cond_signal", "cvar", "notify");
+ }
+ inline void broadcast()
+ {
+ PTHREAD_CHK(::pthread_cond_broadcast(&_c), "::pthread_cond_broadcast", "cvar", "broadcast");
+ }
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_CVAR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/data_tok.cpp b/cpp/src/qpid/legacystore/jrnl/data_tok.cpp
new file mode 100644
index 0000000000..ce7206d80d
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/data_tok.cpp
@@ -0,0 +1,194 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file data_tok.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::data_tok (data block token).
+ * See comments in file data_tok.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/data_tok.h"
+
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include "qpid/legacystore/jrnl/slock.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+// Static members
+
+u_int64_t data_tok::_cnt = 0;
+smutex data_tok::_mutex;
+
+data_tok::data_tok():
+ _wstate(NONE),
+ _rstate(UNREAD),
+ _dsize(0),
+ _dblks_written(0),
+ _dblks_read(0),
+ _pg_cnt(0),
+ _fid(0),
+ _rid(0),
+ _xid(),
+ _dequeue_rid(0),
+ _external_rid(false)
+{
+ slock s(_mutex);
+ _icnt = _cnt++;
+}
+
+data_tok::~data_tok() {}
+
+const char*
+data_tok::wstate_str() const
+{
+ return wstate_str(_wstate);
+}
+
+const char*
+data_tok::wstate_str(write_state wstate)
+{
+ switch (wstate)
+ {
+ case NONE:
+ return "NONE";
+ case ENQ_CACHED:
+ return "ENQ_CACHED";
+ case ENQ_PART:
+ return "ENQ_PART";
+ case ENQ_SUBM:
+ return "ENQ_SUBM";
+ case ENQ:
+ return "ENQ";
+ case DEQ_CACHED:
+ return "DEQ_CACHED";
+ case DEQ_PART:
+ return "DEQ_PART";
+ case DEQ_SUBM:
+ return "DEQ_SUBM";
+ case DEQ:
+ return "DEQ";
+ case ABORT_CACHED:
+ return "ABORT_CACHED";
+ case ABORT_PART:
+ return "ABORT_PART";
+ case ABORT_SUBM:
+ return "ABORT_SUBM";
+ case ABORTED:
+ return "ABORTED";
+ case COMMIT_CACHED:
+ return "COMMIT_CACHED";
+ case COMMIT_PART:
+ return "COMMIT_PART";
+ case COMMIT_SUBM:
+ return "COMMIT_SUBM";
+ case COMMITTED:
+ return "COMMITTED";
+ }
+ // Not using default: forces compiler to ensure all cases are covered.
+ return "<wstate unknown>";
+}
+
+const char*
+data_tok::rstate_str() const
+{
+ return rstate_str(_rstate);
+}
+
+const char*
+data_tok::rstate_str(read_state rstate)
+{
+ switch (rstate)
+ {
+ case NONE:
+ return "NONE";
+ case READ_PART:
+ return "READ_PART";
+ case SKIP_PART:
+ return "SKIP_PART";
+ case READ:
+ return "READ";
+ // Not using default: forces compiler to ensure all cases are covered.
+ }
+ return "<rstate unknown>";
+}
+
+void
+data_tok::set_rstate(const read_state rstate)
+{
+ if (_wstate != ENQ && rstate != UNREAD)
+ {
+ std::ostringstream oss;
+ oss << "Attempted to change read state to " << rstate_str(rstate);
+ oss << " while write state is not enqueued (wstate ENQ); wstate=" << wstate_str() << ".";
+ throw jexception(jerrno::JERR_DTOK_ILLEGALSTATE, oss.str(), "data_tok",
+ "set_rstate");
+ }
+ _rstate = rstate;
+}
+
+void
+data_tok::reset()
+{
+ _wstate = NONE;
+ _rstate = UNREAD;
+ _dsize = 0;
+ _dblks_written = 0;
+ _dblks_read = 0;
+ _pg_cnt = 0;
+ _fid = 0;
+ _rid = 0;
+ _xid.clear();
+}
+
+// debug aid
+std::string
+data_tok::status_str() const
+{
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "dtok id=0x" << _icnt << "; ws=" << wstate_str() << "; rs=" << rstate_str();
+ oss << "; fid=0x" << _fid << "; rid=0x" << _rid << "; xid=";
+ for (unsigned i=0; i<_xid.size(); i++)
+ {
+ if (isprint(_xid[i]))
+ oss << _xid[i];
+ else
+ oss << "/" << std::setw(2) << (int)((char)_xid[i]);
+ }
+ oss << "; drid=0x" << _dequeue_rid << " extrid=" << (_external_rid?"T":"F");
+ oss << "; ds=0x" << _dsize << "; dw=0x" << _dblks_written << "; dr=0x" << _dblks_read;
+ oss << " pc=0x" << _pg_cnt;
+ return oss.str();
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/data_tok.h b/cpp/src/qpid/legacystore/jrnl/data_tok.h
new file mode 100644
index 0000000000..e35f069399
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/data_tok.h
@@ -0,0 +1,172 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file data_tok.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::data_tok (data block token).
+ * See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_DATA_TOK_H
+#define QPID_LEGACYSTORE_JRNL_DATA_TOK_H
+
+namespace mrg
+{
+namespace journal
+{
+class data_tok;
+}
+}
+
+#include <cassert>
+#include <cstddef>
+#include "qpid/legacystore/jrnl/smutex.h"
+#include <pthread.h>
+#include <string>
+#include <sys/types.h>
+
+namespace mrg
+{
+
+namespace journal
+{
+
+ /**
+ * \class data_tok
+ * \brief Data block token (data_tok) used to track wstate of a data block through asynchronous
+ * I/O process
+ */
+ class data_tok
+ {
+ public:
+ // TODO: Fix this, separate write state from operation
+ // ie: wstate = NONE, CACHED, PART, SUBM, COMPL
+ // op = ENQUEUE, DEQUEUE, ABORT, COMMIT
+ enum write_state
+ {
+ NONE, ///< Data block not sent to journal
+ ENQ_CACHED, ///< Data block enqueue written to page cache
+ ENQ_PART, ///< Data block part-submitted to AIO, waiting for page buffer to free up
+ ENQ_SUBM, ///< Data block enqueue submitted to AIO
+ ENQ, ///< Data block enqueue AIO write complete (enqueue complete)
+ DEQ_CACHED, ///< Data block dequeue written to page cache
+ DEQ_PART, ///< Data block part-submitted to AIO, waiting for page buffer to free up
+ DEQ_SUBM, ///< Data block dequeue submitted to AIO
+ DEQ, ///< Data block dequeue AIO write complete (dequeue complete)
+ ABORT_CACHED,
+ ABORT_PART,
+ ABORT_SUBM,
+ ABORTED,
+ COMMIT_CACHED,
+ COMMIT_PART,
+ COMMIT_SUBM,
+ COMMITTED
+ };
+
+ enum read_state
+ {
+ UNREAD, ///< Data block not read
+ READ_PART, ///< Data block is part-read; waiting for page buffer to fill
+ SKIP_PART, ///< Prev. dequeued dblock is part-skipped; waiting for page buffer to fill
+ READ ///< Data block is fully read
+ };
+
+ protected:
+ static smutex _mutex;
+ static u_int64_t _cnt;
+ u_int64_t _icnt;
+ write_state _wstate; ///< Enqueued / dequeued state of data
+ read_state _rstate; ///< Read state of data
+ std::size_t _dsize; ///< Data size in bytes
+ u_int32_t _dblks_written; ///< Data blocks read/written
+ u_int32_t _dblks_read; ///< Data blocks read/written
+ u_int32_t _pg_cnt; ///< Page counter - incr for each page containing part of data
+ u_int16_t _fid; ///< FID containing header of enqueue record
+ u_int64_t _rid; ///< RID of data set by enqueue operation
+ std::string _xid; ///< XID set by enqueue operation
+ u_int64_t _dequeue_rid; ///< RID of data set by dequeue operation
+ bool _external_rid; ///< Flag to indicate external setting of rid
+
+ public:
+ data_tok();
+ virtual ~data_tok();
+
+ inline u_int64_t id() const { return _icnt; }
+ inline write_state wstate() const { return _wstate; }
+ const char* wstate_str() const;
+ static const char* wstate_str(write_state wstate);
+ inline read_state rstate() const { return _rstate; }
+ const char* rstate_str() const;
+ static const char* rstate_str(read_state rstate);
+ inline bool is_writable() const { return _wstate == NONE || _wstate == ENQ_PART; }
+ inline bool is_enqueued() const { return _wstate == ENQ; }
+ inline bool is_readable() const { return _wstate == ENQ; }
+ inline bool is_read() const { return _rstate == READ; }
+ inline bool is_dequeueable() const { return _wstate == ENQ || _wstate == DEQ_PART; }
+ inline void set_wstate(const write_state wstate) { _wstate = wstate; }
+ void set_rstate(const read_state rstate);
+ inline std::size_t dsize() const { return _dsize; }
+ inline void set_dsize(std::size_t dsize) { _dsize = dsize; }
+
+ inline u_int32_t dblocks_written() const { return _dblks_written; }
+ inline void incr_dblocks_written(u_int32_t dblks_written)
+ { _dblks_written += dblks_written; }
+ inline void set_dblocks_written(u_int32_t dblks_written) { _dblks_written = dblks_written; }
+
+ inline u_int32_t dblocks_read() const { return _dblks_read; }
+ inline void incr_dblocks_read(u_int32_t dblks_read) { _dblks_read += dblks_read; }
+ inline void set_dblocks_read(u_int32_t dblks_read) { _dblks_read = dblks_read; }
+
+ inline u_int32_t pg_cnt() const { return _pg_cnt; }
+ inline u_int32_t incr_pg_cnt() { return ++_pg_cnt; }
+ inline u_int32_t decr_pg_cnt() { assert(_pg_cnt != 0); return --_pg_cnt; }
+
+ inline u_int16_t fid() const { return _fid; }
+ inline void set_fid(const u_int16_t fid) { _fid = fid; }
+ inline u_int64_t rid() const { return _rid; }
+ inline void set_rid(const u_int64_t rid) { _rid = rid; }
+ inline u_int64_t dequeue_rid() const {return _dequeue_rid; }
+ inline void set_dequeue_rid(const u_int64_t rid) { _dequeue_rid = rid; }
+ inline bool external_rid() const { return _external_rid; }
+ inline void set_external_rid(const bool external_rid) { _external_rid = external_rid; }
+
+ inline bool has_xid() const { return !_xid.empty(); }
+ inline const std::string& xid() const { return _xid; }
+ inline void clear_xid() { _xid.clear(); }
+ inline void set_xid(const std::string& xid) { _xid.assign(xid); }
+ inline void set_xid(const void* xidp, const std::size_t xid_len)
+ { _xid.assign((const char*)xidp, xid_len); }
+
+ void reset();
+
+ // debug aid
+ std::string status_str() const;
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_DATA_TOK_H
diff --git a/cpp/src/qpid/legacystore/jrnl/deq_hdr.h b/cpp/src/qpid/legacystore/jrnl/deq_hdr.h
new file mode 100644
index 0000000000..ae7081eac1
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/deq_hdr.h
@@ -0,0 +1,141 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file deq_hdr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::deq_hdr (dequeue record),
+ * used to dequeue a previously enqueued record.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_DEQ_HDR_H
+#define QPID_LEGACYSTORE_JRNL_DEQ_HDR_H
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/rec_hdr.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for dequeue record.
+ *
+ * Struct for dequeue record. If this record has a non-zero xidsize field (i.e., there is a
+ * valid XID), then this header is followed by the XID of xidsize bytes and a rec_tail. If,
+ * on the other hand, this record has a zero xidsize (i.e., there is no XID), then the rec_tail
+ * is absent.
+ *
+ * Note that this record had its own rid distinct from the rid of the record it is dequeueing.
+ * The rid field below is the rid of the dequeue record itself; the deq-rid field is the rid of a
+ * previous enqueue record being dequeued by this record.
+ *
+ * Record header info in binary format (32 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+ -+
+ * | magic | v | e | flags | |
+ * +---+---+---+---+---+---+---+---+ | struct hdr
+ * | rid | |
+ * +---+---+---+---+---+---+---+---+ -+
+ * | deq-rid |
+ * +---+---+---+---+---+---+---+---+
+ * | xidsize |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct deq_hdr : rec_hdr
+ {
+ u_int64_t _deq_rid; ///< Record ID of dequeued record
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+#endif
+ std::size_t _xidsize; ///< XID size
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+#endif
+ static const u_int16_t DEQ_HDR_TXNCMPLCOMMIT_MASK = 0x10;
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline deq_hdr(): rec_hdr(), _deq_rid(0),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(0)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler0(0)
+#endif
+ {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline deq_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const u_int64_t deq_rid, const std::size_t xidsize, const bool owi,
+ const bool txn_coml_commit = false):
+ rec_hdr(magic, version, rid, owi), _deq_rid(deq_rid),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(xidsize)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler0(0)
+#endif
+ { set_txn_coml_commit(txn_coml_commit); }
+
+
+ inline bool is_txn_coml_commit() const { return _uflag & DEQ_HDR_TXNCMPLCOMMIT_MASK; }
+
+ inline void set_txn_coml_commit(const bool commit)
+ {
+ _uflag = commit ? _uflag | DEQ_HDR_TXNCMPLCOMMIT_MASK :
+ _uflag & (~DEQ_HDR_TXNCMPLCOMMIT_MASK);
+ }
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static std::size_t size() { return sizeof(deq_hdr); }
+ };
+
+#pragma pack()
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_DEQ_HDR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/deq_rec.cpp b/cpp/src/qpid/legacystore/jrnl/deq_rec.cpp
new file mode 100644
index 0000000000..4de412c201
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/deq_rec.cpp
@@ -0,0 +1,459 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file deq_rec.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the code for the mrg::journal::deq_rec (journal dequeue
+ * record) class. See comments in file deq_rec.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "jrnl/deq_rec.h"
+
+#include <cassert>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+deq_rec::deq_rec():
+ _deq_hdr(RHM_JDAT_DEQ_MAGIC, RHM_JDAT_VERSION, 0, 0, 0, false),
+ _xidp(0),
+ _buff(0),
+ _deq_tail(_deq_hdr)
+{}
+
+deq_rec::deq_rec(const u_int64_t rid, const u_int64_t drid, const void* const xidp,
+ const std::size_t xidlen, const bool owi, const bool txn_coml_commit):
+ _deq_hdr(RHM_JDAT_DEQ_MAGIC, RHM_JDAT_VERSION, rid, drid, xidlen, owi, txn_coml_commit),
+ _xidp(xidp),
+ _buff(0),
+ _deq_tail(_deq_hdr)
+{}
+
+deq_rec::~deq_rec()
+{
+ clean();
+}
+
+void
+deq_rec::reset()
+{
+ _deq_hdr._rid = 0;
+ _deq_hdr.set_owi(false);
+ _deq_hdr.set_txn_coml_commit(false);
+ _deq_hdr._deq_rid = 0;
+ _deq_hdr._xidsize = 0;
+ _deq_tail._rid = 0;
+ _xidp = 0;
+ _buff = 0;
+}
+
+void
+deq_rec::reset(const u_int64_t rid, const u_int64_t drid, const void* const xidp,
+ const std::size_t xidlen, const bool owi, const bool txn_coml_commit)
+{
+ _deq_hdr._rid = rid;
+ _deq_hdr.set_owi(owi);
+ _deq_hdr.set_txn_coml_commit(txn_coml_commit);
+ _deq_hdr._deq_rid = drid;
+ _deq_hdr._xidsize = xidlen;
+ _deq_tail._rid = rid;
+ _xidp = xidp;
+ _buff = 0;
+}
+
+u_int32_t
+deq_rec::encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+{
+ assert(wptr != 0);
+ assert(max_size_dblks > 0);
+ if (_xidp == 0)
+ assert(_deq_hdr._xidsize == 0);
+
+ std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+ std::size_t rem = max_size_dblks * JRNL_DBLK_SIZE;
+ std::size_t wr_cnt = 0;
+ if (rec_offs_dblks) // Continuation of split dequeue record (over 2 or more pages)
+ {
+ if (size_dblks(rec_size()) - rec_offs_dblks > max_size_dblks) // Further split required
+ {
+ rec_offs -= sizeof(_deq_hdr);
+ std::size_t wsize = _deq_hdr._xidsize > rec_offs ? _deq_hdr._xidsize - rec_offs : 0;
+ std::size_t wsize2 = wsize;
+ if (wsize)
+ {
+ if (wsize > rem)
+ wsize = rem;
+ std::memcpy(wptr, (const char*)_xidp + rec_offs, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ rec_offs -= _deq_hdr._xidsize - wsize2;
+ if (rem)
+ {
+ wsize = sizeof(_deq_tail) > rec_offs ? sizeof(_deq_tail) - rec_offs : 0;
+ wsize2 = wsize;
+ if (wsize)
+ {
+ if (wsize > rem)
+ wsize = rem;
+ std::memcpy((char*)wptr + wr_cnt, (char*)&_deq_tail + rec_offs, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ rec_offs -= sizeof(_deq_tail) - wsize2;
+ }
+ assert(rem == 0);
+ assert(rec_offs == 0);
+ }
+ else // No further split required
+ {
+ rec_offs -= sizeof(_deq_hdr);
+ std::size_t wsize = _deq_hdr._xidsize > rec_offs ? _deq_hdr._xidsize - rec_offs : 0;
+ if (wsize)
+ {
+ std::memcpy(wptr, (const char*)_xidp + rec_offs, wsize);
+ wr_cnt += wsize;
+ }
+ rec_offs -= _deq_hdr._xidsize - wsize;
+ wsize = sizeof(_deq_tail) > rec_offs ? sizeof(_deq_tail) - rec_offs : 0;
+ if (wsize)
+ {
+ std::memcpy((char*)wptr + wr_cnt, (char*)&_deq_tail + rec_offs, wsize);
+ wr_cnt += wsize;
+#ifdef RHM_CLEAN
+ std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+ std::size_t dblk_rec_size = size_dblks(rec_size() - rec_offs) * JRNL_DBLK_SIZE;
+ std::memset((char*)wptr + wr_cnt, RHM_CLEAN_CHAR, dblk_rec_size - wr_cnt);
+#endif
+ }
+ rec_offs -= sizeof(_deq_tail) - wsize;
+ assert(rec_offs == 0);
+ }
+ }
+ else // Start at beginning of data record
+ {
+ // Assumption: the header will always fit into the first dblk
+ std::memcpy(wptr, (void*)&_deq_hdr, sizeof(_deq_hdr));
+ wr_cnt = sizeof(_deq_hdr);
+ if (size_dblks(rec_size()) > max_size_dblks) // Split required - can only occur with xid
+ {
+ std::size_t wsize;
+ rem -= sizeof(_deq_hdr);
+ if (rem)
+ {
+ wsize = rem >= _deq_hdr._xidsize ? _deq_hdr._xidsize : rem;
+ std::memcpy((char*)wptr + wr_cnt, _xidp, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ if (rem)
+ {
+ wsize = rem >= sizeof(_deq_tail) ? sizeof(_deq_tail) : rem;
+ std::memcpy((char*)wptr + wr_cnt, (void*)&_deq_tail, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ assert(rem == 0);
+ }
+ else // No split required
+ {
+ if (_deq_hdr._xidsize)
+ {
+ std::memcpy((char*)wptr + wr_cnt, _xidp, _deq_hdr._xidsize);
+ wr_cnt += _deq_hdr._xidsize;
+ std::memcpy((char*)wptr + wr_cnt, (void*)&_deq_tail, sizeof(_deq_tail));
+ wr_cnt += sizeof(_deq_tail);
+ }
+#ifdef RHM_CLEAN
+ std::size_t dblk_rec_size = size_dblks(rec_size()) * JRNL_DBLK_SIZE;
+ std::memset((char*)wptr + wr_cnt, RHM_CLEAN_CHAR, dblk_rec_size - wr_cnt);
+#endif
+ }
+ }
+ return size_dblks(wr_cnt);
+}
+
+u_int32_t
+deq_rec::decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+{
+ assert(rptr != 0);
+ assert(max_size_dblks > 0);
+
+ std::size_t rd_cnt = 0;
+ if (rec_offs_dblks) // Continuation of record on new page
+ {
+ const u_int32_t hdr_xid_dblks = size_dblks(deq_hdr::size() + _deq_hdr._xidsize);
+ const u_int32_t hdr_xid_tail_dblks = size_dblks(deq_hdr::size() + _deq_hdr._xidsize +
+ rec_tail::size());
+ const std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+
+ if (hdr_xid_tail_dblks - rec_offs_dblks <= max_size_dblks)
+ {
+ // Remainder of xid fits within this page
+ if (rec_offs - deq_hdr::size() < _deq_hdr._xidsize)
+ {
+ // Part of xid still outstanding, copy remainder of xid and tail
+ const std::size_t xid_offs = rec_offs - deq_hdr::size();
+ const std::size_t xid_rem = _deq_hdr._xidsize - xid_offs;
+ std::memcpy((char*)_buff + xid_offs, rptr, xid_rem);
+ rd_cnt = xid_rem;
+ std::memcpy((void*)&_deq_tail, ((char*)rptr + rd_cnt), sizeof(_deq_tail));
+ chk_tail();
+ rd_cnt += sizeof(_deq_tail);
+ }
+ else
+ {
+ // Tail or part of tail only outstanding, complete tail
+ const std::size_t tail_offs = rec_offs - deq_hdr::size() - _deq_hdr._xidsize;
+ const std::size_t tail_rem = rec_tail::size() - tail_offs;
+ std::memcpy((char*)&_deq_tail + tail_offs, rptr, tail_rem);
+ chk_tail();
+ rd_cnt = tail_rem;
+ }
+ }
+ else if (hdr_xid_dblks - rec_offs_dblks <= max_size_dblks)
+ {
+ // Remainder of xid fits within this page, tail split
+ const std::size_t xid_offs = rec_offs - deq_hdr::size();
+ const std::size_t xid_rem = _deq_hdr._xidsize - xid_offs;
+ std::memcpy((char*)_buff + xid_offs, rptr, xid_rem);
+ rd_cnt += xid_rem;
+ const std::size_t tail_rem = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ if (tail_rem)
+ {
+ std::memcpy((void*)&_deq_tail, ((char*)rptr + xid_rem), tail_rem);
+ rd_cnt += tail_rem;
+ }
+ }
+ else
+ {
+ // Remainder of xid split
+ const std::size_t xid_cp_size = (max_size_dblks * JRNL_DBLK_SIZE);
+ std::memcpy((char*)_buff + rec_offs - deq_hdr::size(), rptr, xid_cp_size);
+ rd_cnt += xid_cp_size;
+ }
+ }
+ else // Start of record
+ {
+ // Get and check header
+ _deq_hdr.hdr_copy(h);
+ rd_cnt = sizeof(rec_hdr);
+ _deq_hdr._deq_rid = *(u_int64_t*)((char*)rptr + rd_cnt);
+ rd_cnt += sizeof(u_int64_t);
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ rd_cnt += sizeof(u_int32_t); // Filler 0
+#endif
+ _deq_hdr._xidsize = *(std::size_t*)((char*)rptr + rd_cnt);
+ rd_cnt = _deq_hdr.size();
+ chk_hdr();
+ if (_deq_hdr._xidsize)
+ {
+ _buff = std::malloc(_deq_hdr._xidsize);
+ MALLOC_CHK(_buff, "_buff", "deq_rec", "decode");
+ const u_int32_t hdr_xid_dblks = size_dblks(deq_hdr::size() + _deq_hdr._xidsize);
+ const u_int32_t hdr_xid_tail_dblks = size_dblks(deq_hdr::size() + _deq_hdr._xidsize +
+ rec_tail::size());
+
+ // Check if record (header + xid + tail) fits within this page, we can check the
+ // tail before the expense of copying data to memory
+ if (hdr_xid_tail_dblks <= max_size_dblks)
+ {
+ // Entire header, xid and tail fits within this page
+ std::memcpy(_buff, (char*)rptr + rd_cnt, _deq_hdr._xidsize);
+ rd_cnt += _deq_hdr._xidsize;
+ std::memcpy((void*)&_deq_tail, (char*)rptr + rd_cnt, sizeof(_deq_tail));
+ rd_cnt += sizeof(_deq_tail);
+ chk_tail();
+ }
+ else if (hdr_xid_dblks <= max_size_dblks)
+ {
+ // Entire header and xid fit within this page, tail split
+ std::memcpy(_buff, (char*)rptr + rd_cnt, _deq_hdr._xidsize);
+ rd_cnt += _deq_hdr._xidsize;
+ const std::size_t tail_rem = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ if (tail_rem)
+ {
+ std::memcpy((void*)&_deq_tail, (char*)rptr + rd_cnt, tail_rem);
+ rd_cnt += tail_rem;
+ }
+ }
+ else
+ {
+ // Header fits within this page, xid split
+ const std::size_t xid_cp_size = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ std::memcpy(_buff, (char*)rptr + rd_cnt, xid_cp_size);
+ rd_cnt += xid_cp_size;
+ }
+ }
+ }
+ return size_dblks(rd_cnt);
+}
+
+bool
+deq_rec::rcv_decode(rec_hdr h, std::ifstream* ifsp, std::size_t& rec_offs)
+{
+ if (rec_offs == 0)
+ {
+ _deq_hdr.hdr_copy(h);
+ ifsp->read((char*)&_deq_hdr._deq_rid, sizeof(u_int64_t));
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ ifsp->ignore(sizeof(u_int32_t)); // _filler0
+#endif
+ ifsp->read((char*)&_deq_hdr._xidsize, sizeof(std::size_t));
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ ifsp->ignore(sizeof(u_int32_t)); // _filler0
+#endif
+ rec_offs = sizeof(_deq_hdr);
+ // Read header, allocate (if req'd) for xid
+ if (_deq_hdr._xidsize)
+ {
+ _buff = std::malloc(_deq_hdr._xidsize);
+ MALLOC_CHK(_buff, "_buff", "enq_rec", "rcv_decode");
+ }
+ }
+ if (rec_offs < sizeof(_deq_hdr) + _deq_hdr._xidsize)
+ {
+ // Read xid (or continue reading xid)
+ std::size_t offs = rec_offs - sizeof(_deq_hdr);
+ ifsp->read((char*)_buff + offs, _deq_hdr._xidsize - offs);
+ std::size_t size_read = ifsp->gcount();
+ rec_offs += size_read;
+ if (size_read < _deq_hdr._xidsize - offs)
+ {
+ assert(ifsp->eof());
+ // As we may have read past eof, turn off fail bit
+ ifsp->clear(ifsp->rdstate()&(~std::ifstream::failbit));
+ assert(!ifsp->fail() && !ifsp->bad());
+ return false;
+ }
+ }
+ if (rec_offs < sizeof(_deq_hdr) +
+ (_deq_hdr._xidsize ? _deq_hdr._xidsize + sizeof(rec_tail) : 0))
+ {
+ // Read tail (or continue reading tail)
+ std::size_t offs = rec_offs - sizeof(_deq_hdr) - _deq_hdr._xidsize;
+ ifsp->read((char*)&_deq_tail + offs, sizeof(rec_tail) - offs);
+ std::size_t size_read = ifsp->gcount();
+ rec_offs += size_read;
+ if (size_read < sizeof(rec_tail) - offs)
+ {
+ assert(ifsp->eof());
+ // As we may have read past eof, turn off fail bit
+ ifsp->clear(ifsp->rdstate()&(~std::ifstream::failbit));
+ assert(!ifsp->fail() && !ifsp->bad());
+ return false;
+ }
+ }
+ ifsp->ignore(rec_size_dblks() * JRNL_DBLK_SIZE - rec_size());
+ if (_deq_hdr._xidsize)
+ chk_tail(); // Throws if tail invalid or record incomplete
+ assert(!ifsp->fail() && !ifsp->bad());
+ return true;
+}
+
+std::size_t
+deq_rec::get_xid(void** const xidpp)
+{
+ if (!_buff)
+ {
+ *xidpp = 0;
+ return 0;
+ }
+ *xidpp = _buff;
+ return _deq_hdr._xidsize;
+}
+
+std::string&
+deq_rec::str(std::string& str) const
+{
+ std::ostringstream oss;
+ oss << "deq_rec: m=" << _deq_hdr._magic;
+ oss << " v=" << (int)_deq_hdr._version;
+ oss << " rid=" << _deq_hdr._rid;
+ oss << " drid=" << _deq_hdr._deq_rid;
+ if (_xidp)
+ oss << " xid=\"" << _xidp << "\"";
+ str.append(oss.str());
+ return str;
+}
+
+std::size_t
+deq_rec::xid_size() const
+{
+ return _deq_hdr._xidsize;
+}
+
+std::size_t
+deq_rec::rec_size() const
+{
+ return deq_hdr::size() + (_deq_hdr._xidsize ? _deq_hdr._xidsize + rec_tail::size() : 0);
+}
+
+void
+deq_rec::chk_hdr() const
+{
+ jrec::chk_hdr(_deq_hdr);
+ if (_deq_hdr._magic != RHM_JDAT_DEQ_MAGIC)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "deq magic: rid=0x" << std::setw(16) << _deq_hdr._rid;
+ oss << ": expected=0x" << std::setw(8) << RHM_JDAT_DEQ_MAGIC;
+ oss << " read=0x" << std::setw(2) << (int)_deq_hdr._magic;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "deq_rec", "chk_hdr");
+ }
+}
+
+void
+deq_rec::chk_hdr(u_int64_t rid) const
+{
+ chk_hdr();
+ jrec::chk_rid(_deq_hdr, rid);
+}
+
+void
+deq_rec::chk_tail() const
+{
+ jrec::chk_tail(_deq_tail, _deq_hdr);
+}
+
+void
+deq_rec::clean()
+{
+ // clean up allocated memory here
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/deq_rec.h b/cpp/src/qpid/legacystore/jrnl/deq_rec.h
new file mode 100644
index 0000000000..d870b658da
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/deq_rec.h
@@ -0,0 +1,103 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/**
+ * \file deq_rec.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the code for the mrg::journal::deq_rec (journal dequeue
+ * record) class. See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_DEQ_REQ_H
+#define QPID_LEGACYSTORE_JRNL_DEQ_REQ_H
+
+namespace mrg
+{
+namespace journal
+{
+class deq_rec;
+}
+}
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/deq_hdr.h"
+#include "qpid/legacystore/jrnl/jrec.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class deq_rec
+ * \brief Class to handle a single journal dequeue record.
+ */
+ class deq_rec : public jrec
+ {
+ private:
+ deq_hdr _deq_hdr; ///< Dequeue header
+ const void* _xidp; ///< xid pointer for encoding (writing to disk)
+ void* _buff; ///< Pointer to buffer to receive data read from disk
+ rec_tail _deq_tail; ///< Record tail, only encoded if XID is present
+
+ public:
+ // constructor used for read operations and xid will have memory allocated
+ deq_rec();
+ // constructor used for write operations, where xid already exists
+ deq_rec(const u_int64_t rid, const u_int64_t drid, const void* const xidp,
+ const std::size_t xidlen, const bool owi, const bool txn_coml_commit);
+ virtual ~deq_rec();
+
+ // Prepare instance for use in reading data from journal
+ void reset();
+ // Prepare instance for use in writing data to journal
+ void reset(const u_int64_t rid, const u_int64_t drid, const void* const xidp,
+ const std::size_t xidlen, const bool owi, const bool txn_coml_commit);
+ u_int32_t encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks);
+ u_int32_t decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks,
+ u_int32_t max_size_dblks);
+ // Decode used for recover
+ bool rcv_decode(rec_hdr h, std::ifstream* ifsp, std::size_t& rec_offs);
+
+ inline bool is_txn_coml_commit() const { return _deq_hdr.is_txn_coml_commit(); }
+ inline u_int64_t rid() const { return _deq_hdr._rid; }
+ inline u_int64_t deq_rid() const { return _deq_hdr._deq_rid; }
+ std::size_t get_xid(void** const xidpp);
+ std::string& str(std::string& str) const;
+ inline std::size_t data_size() const { return 0; } // This record never carries data
+ std::size_t xid_size() const;
+ std::size_t rec_size() const;
+
+ private:
+ virtual void chk_hdr() const;
+ virtual void chk_hdr(u_int64_t rid) const;
+ virtual void chk_tail() const;
+ virtual void clean();
+ }; // class deq_rec
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_DEQ_REQ_H
diff --git a/cpp/src/qpid/legacystore/jrnl/enq_hdr.h b/cpp/src/qpid/legacystore/jrnl/enq_hdr.h
new file mode 100644
index 0000000000..0d1e6116be
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/enq_hdr.h
@@ -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.
+ *
+ */
+
+/**
+ * \file enq_hdr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::enq_hdr (enueue header),
+ * used to start an enqueue record in the journal.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_ENQ_HDR_H
+#define QPID_LEGACYSTORE_JRNL_ENQ_HDR_H
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/rec_hdr.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for enqueue record.
+ *
+ * Struct for enqueue record. In addition to the common data, this header includes both the
+ * xid and data blob sizes.
+ *
+ * This header precedes all enqueue data in journal files.
+ *
+ * Record header info in binary format (32 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+ -+
+ * | magic | v | e | flags | |
+ * +---+---+---+---+---+---+---+---+ | struct hdr
+ * | rid | |
+ * +---+---+---+---+---+---+---+---+ -+
+ * | xidsize |
+ * +---+---+---+---+---+---+---+---+
+ * | dsize |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct enq_hdr : rec_hdr
+ {
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+#endif
+ std::size_t _xidsize; ///< XID size
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler1; ///< Big-endian filler for 32-bit size_t
+#endif
+ std::size_t _dsize; ///< Record data size
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler1; ///< Little-endian filler for 32-bit size_t
+#endif
+ static const u_int16_t ENQ_HDR_TRANSIENT_MASK = 0x10;
+ static const u_int16_t ENQ_HDR_EXTERNAL_MASK = 0x20;
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline enq_hdr(): rec_hdr(),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(0),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+ _dsize(0)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler1(0)
+#endif
+ {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline enq_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const std::size_t xidsize, const std::size_t dsize, const bool owi,
+ const bool transient = false): rec_hdr(magic, version, rid, owi),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(xidsize),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+ _dsize(dsize)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler1(0)
+#endif
+ { set_transient(transient); }
+
+
+ inline bool is_transient() const { return _uflag & ENQ_HDR_TRANSIENT_MASK; }
+
+ inline void set_transient(const bool transient)
+ {
+ _uflag = transient ? _uflag | ENQ_HDR_TRANSIENT_MASK :
+ _uflag & (~ENQ_HDR_TRANSIENT_MASK);
+ }
+
+ inline bool is_external() const { return _uflag & ENQ_HDR_EXTERNAL_MASK; }
+
+ inline void set_external(const bool external)
+ {
+ _uflag = external ? _uflag | ENQ_HDR_EXTERNAL_MASK :
+ _uflag & (~ENQ_HDR_EXTERNAL_MASK);
+ }
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static std::size_t size() { return sizeof(enq_hdr); }
+ };
+
+#pragma pack()
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_ENQ_HDR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/enq_map.cpp b/cpp/src/qpid/legacystore/jrnl/enq_map.cpp
new file mode 100644
index 0000000000..d024b704a7
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/enq_map.cpp
@@ -0,0 +1,183 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file enq_map.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::enq_map (enqueue map). See
+ * comments in file enq_map.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/enq_map.h"
+
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/slock.h"
+#include <sstream>
+
+
+namespace mrg
+{
+namespace journal
+{
+
+// static return/error codes
+int16_t enq_map::EMAP_DUP_RID = -3;
+int16_t enq_map::EMAP_LOCKED = -2;
+int16_t enq_map::EMAP_RID_NOT_FOUND = -1;
+int16_t enq_map::EMAP_OK = 0;
+int16_t enq_map::EMAP_FALSE = 0;
+int16_t enq_map::EMAP_TRUE = 1;
+
+enq_map::enq_map():
+ _map(),
+ _pfid_enq_cnt()
+{}
+
+enq_map::~enq_map() {}
+
+void
+enq_map::set_num_jfiles(const u_int16_t num_jfiles)
+{
+ _pfid_enq_cnt.resize(num_jfiles, 0);
+}
+
+
+int16_t
+enq_map::insert_pfid(const u_int64_t rid, const u_int16_t pfid)
+{
+ return insert_pfid(rid, pfid, false);
+}
+
+int16_t
+enq_map::insert_pfid(const u_int64_t rid, const u_int16_t pfid, const bool locked)
+{
+ std::pair<emap_itr, bool> ret;
+ emap_data_struct rec(pfid, locked);
+ {
+ slock s(_mutex);
+ ret = _map.insert(emap_param(rid, rec));
+ }
+ if (ret.second == false)
+ return EMAP_DUP_RID;
+ _pfid_enq_cnt.at(pfid)++;
+ return EMAP_OK;
+}
+
+int16_t
+enq_map::get_pfid(const u_int64_t rid)
+{
+ slock s(_mutex);
+ emap_itr itr = _map.find(rid);
+ if (itr == _map.end()) // not found in map
+ return EMAP_RID_NOT_FOUND;
+ if (itr->second._lock)
+ return EMAP_LOCKED;
+ return itr->second._pfid;
+}
+
+int16_t
+enq_map::get_remove_pfid(const u_int64_t rid, const bool txn_flag)
+{
+ slock s(_mutex);
+ emap_itr itr = _map.find(rid);
+ if (itr == _map.end()) // not found in map
+ return EMAP_RID_NOT_FOUND;
+ if (itr->second._lock && !txn_flag) // locked, but not a commit/abort
+ return EMAP_LOCKED;
+ u_int16_t pfid = itr->second._pfid;
+ _map.erase(itr);
+ _pfid_enq_cnt.at(pfid)--;
+ return pfid;
+}
+
+bool
+enq_map::is_enqueued(const u_int64_t rid, bool ignore_lock)
+{
+ slock s(_mutex);
+ emap_itr itr = _map.find(rid);
+ if (itr == _map.end()) // not found in map
+ return false;
+ if (!ignore_lock && itr->second._lock) // locked
+ return false;
+ return true;
+}
+
+int16_t
+enq_map::lock(const u_int64_t rid)
+{
+ slock s(_mutex);
+ emap_itr itr = _map.find(rid);
+ if (itr == _map.end()) // not found in map
+ return EMAP_RID_NOT_FOUND;
+ itr->second._lock = true;
+ return EMAP_OK;
+}
+
+int16_t
+enq_map::unlock(const u_int64_t rid)
+{
+ slock s(_mutex);
+ emap_itr itr = _map.find(rid);
+ if (itr == _map.end()) // not found in map
+ return EMAP_RID_NOT_FOUND;
+ itr->second._lock = false;
+ return EMAP_OK;
+}
+
+int16_t
+enq_map::is_locked(const u_int64_t rid)
+{
+ slock s(_mutex);
+ emap_itr itr = _map.find(rid);
+ if (itr == _map.end()) // not found in map
+ return EMAP_RID_NOT_FOUND;
+ return itr->second._lock ? EMAP_TRUE : EMAP_FALSE;
+}
+
+void
+enq_map::rid_list(std::vector<u_int64_t>& rv)
+{
+ rv.clear();
+ {
+ slock s(_mutex);
+ for (emap_itr itr = _map.begin(); itr != _map.end(); itr++)
+ rv.push_back(itr->first);
+ }
+}
+
+void
+enq_map::pfid_list(std::vector<u_int16_t>& fv)
+{
+ fv.clear();
+ {
+ slock s(_mutex);
+ for (emap_itr itr = _map.begin(); itr != _map.end(); itr++)
+ fv.push_back(itr->second._pfid);
+ }
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/enq_map.h b/cpp/src/qpid/legacystore/jrnl/enq_map.h
new file mode 100644
index 0000000000..75404afebe
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/enq_map.h
@@ -0,0 +1,127 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file enq_map.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::enq_map (enqueue map).
+ * See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_ENQ_MAP_H
+#define QPID_LEGACYSTORE_JRNL_ENQ_MAP_H
+
+namespace mrg
+{
+namespace journal
+{
+class enq_map;
+}
+}
+
+#include "qpid/legacystore/jrnl/jexception.h"
+#include "qpid/legacystore/jrnl/smutex.h"
+#include <map>
+#include <pthread.h>
+#include <vector>
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class enq_map
+ * \brief Class for storing the physical file id (pfid) and a transaction locked flag for each enqueued
+ * data block using the record id (rid) as a key. This is the primary mechanism for
+ * deterimining the enqueue low water mark: if a pfid exists in this map, then there is
+ * at least one still-enqueued record in that file. (The transaction map must also be
+ * clear, however.)
+ *
+ * Map rids against pfid and lock status. As records are enqueued, they are added to this
+ * map, and as they are dequeued, they are removed. An enqueue is locked when a transactional
+ * dequeue is pending that has been neither committed nor aborted.
+ * <pre>
+ * key data
+ *
+ * rid1 --- [ pfid, txn_lock ]
+ * rid2 --- [ pfid, txn_lock ]
+ * rid3 --- [ pfid, txn_lock ]
+ * ...
+ * </pre>
+ */
+ class enq_map
+ {
+ public:
+ // return/error codes
+ static int16_t EMAP_DUP_RID;
+ static int16_t EMAP_LOCKED;
+ static int16_t EMAP_RID_NOT_FOUND;
+ static int16_t EMAP_OK;
+ static int16_t EMAP_FALSE;
+ static int16_t EMAP_TRUE;
+
+ private:
+
+ struct emap_data_struct
+ {
+ u_int16_t _pfid;
+ bool _lock;
+ emap_data_struct(const u_int16_t pfid, const bool lock) : _pfid(pfid), _lock(lock) {}
+ };
+ typedef std::pair<u_int64_t, emap_data_struct> emap_param;
+ typedef std::map<u_int64_t, emap_data_struct> emap;
+ typedef emap::iterator emap_itr;
+
+ emap _map;
+ smutex _mutex;
+ std::vector<u_int32_t> _pfid_enq_cnt;
+
+ public:
+ enq_map();
+ virtual ~enq_map();
+
+ void set_num_jfiles(const u_int16_t num_jfiles);
+ inline u_int32_t get_enq_cnt(const u_int16_t pfid) const { return _pfid_enq_cnt.at(pfid); };
+
+ int16_t insert_pfid(const u_int64_t rid, const u_int16_t pfid); // 0=ok; -3=duplicate rid;
+ int16_t insert_pfid(const u_int64_t rid, const u_int16_t pfid, const bool locked); // 0=ok; -3=duplicate rid;
+ int16_t get_pfid(const u_int64_t rid); // >=0=pfid; -1=rid not found; -2=locked
+ int16_t get_remove_pfid(const u_int64_t rid, const bool txn_flag = false); // >=0=pfid; -1=rid not found; -2=locked
+ bool is_enqueued(const u_int64_t rid, bool ignore_lock = false);
+ int16_t lock(const u_int64_t rid); // 0=ok; -1=rid not found
+ int16_t unlock(const u_int64_t rid); // 0=ok; -1=rid not found
+ int16_t is_locked(const u_int64_t rid); // 1=true; 0=false; -1=rid not found
+ inline void clear() { _map.clear(); }
+ inline bool empty() const { return _map.empty(); }
+ inline u_int32_t size() const { return u_int32_t(_map.size()); }
+ void rid_list(std::vector<u_int64_t>& rv);
+ void pfid_list(std::vector<u_int16_t>& fv);
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_ENQ_MAP_H
diff --git a/cpp/src/qpid/legacystore/jrnl/enq_rec.cpp b/cpp/src/qpid/legacystore/jrnl/enq_rec.cpp
new file mode 100644
index 0000000000..468599836b
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/enq_rec.cpp
@@ -0,0 +1,638 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file enq_rec.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the code for the mrg::journal::enq_rec (journal enqueue
+ * record) class. See comments in file enq_rec.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/enq_rec.h"
+
+#include <cassert>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+// Constructor used for read operations, where buf contains preallocated space to receive data.
+enq_rec::enq_rec():
+ jrec(), // superclass
+ _enq_hdr(RHM_JDAT_ENQ_MAGIC, RHM_JDAT_VERSION, 0, 0, 0, false, false),
+ _xidp(0),
+ _data(0),
+ _buff(0),
+ _enq_tail(_enq_hdr)
+{}
+
+// Constructor used for transactional write operations, where dbuf contains data to be written.
+enq_rec::enq_rec(const u_int64_t rid, const void* const dbuf, const std::size_t dlen,
+ const void* const xidp, const std::size_t xidlen, const bool owi, const bool transient):
+ jrec(), // superclass
+ _enq_hdr(RHM_JDAT_ENQ_MAGIC, RHM_JDAT_VERSION, rid, xidlen, dlen, owi, transient),
+ _xidp(xidp),
+ _data(dbuf),
+ _buff(0),
+ _enq_tail(_enq_hdr)
+{}
+
+enq_rec::~enq_rec()
+{
+ clean();
+}
+
+// Prepare instance for use in reading data from journal, where buf contains preallocated space
+// to receive data.
+void
+enq_rec::reset()
+{
+ _enq_hdr._rid = 0;
+ _enq_hdr.set_owi(false);
+ _enq_hdr.set_transient(false);
+ _enq_hdr._xidsize = 0;
+ _enq_hdr._dsize = 0;
+ _xidp = 0;
+ _data = 0;
+ _buff = 0;
+ _enq_tail._rid = 0;
+}
+
+// Prepare instance for use in writing transactional data to journal, where dbuf contains data to
+// be written.
+void
+enq_rec::reset(const u_int64_t rid, const void* const dbuf, const std::size_t dlen,
+ const void* const xidp, const std::size_t xidlen, const bool owi, const bool transient,
+ const bool external)
+{
+ _enq_hdr._rid = rid;
+ _enq_hdr.set_owi(owi);
+ _enq_hdr.set_transient(transient);
+ _enq_hdr.set_external(external);
+ _enq_hdr._xidsize = xidlen;
+ _enq_hdr._dsize = dlen;
+ _xidp = xidp;
+ _data = dbuf;
+ _buff = 0;
+ _enq_tail._rid = rid;
+}
+
+u_int32_t
+enq_rec::encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+{
+ assert(wptr != 0);
+ assert(max_size_dblks > 0);
+ if (_xidp == 0)
+ assert(_enq_hdr._xidsize == 0);
+
+ std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+ std::size_t rem = max_size_dblks * JRNL_DBLK_SIZE;
+ std::size_t wr_cnt = 0;
+ if (rec_offs_dblks) // Continuation of split data record (over 2 or more pages)
+ {
+ if (size_dblks(rec_size()) - rec_offs_dblks > max_size_dblks) // Further split required
+ {
+ rec_offs -= sizeof(_enq_hdr);
+ std::size_t wsize = _enq_hdr._xidsize > rec_offs ? _enq_hdr._xidsize - rec_offs : 0;
+ std::size_t wsize2 = wsize;
+ if (wsize)
+ {
+ if (wsize > rem)
+ wsize = rem;
+ std::memcpy(wptr, (const char*)_xidp + rec_offs, wsize);
+ wr_cnt = wsize;
+ rem -= wsize;
+ }
+ rec_offs -= _enq_hdr._xidsize - wsize2;
+ if (rem && !_enq_hdr.is_external())
+ {
+ wsize = _enq_hdr._dsize > rec_offs ? _enq_hdr._dsize - rec_offs : 0;
+ wsize2 = wsize;
+ if (wsize)
+ {
+ if (wsize > rem)
+ wsize = rem;
+ std::memcpy((char*)wptr + wr_cnt, (const char*)_data + rec_offs, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ rec_offs -= _enq_hdr._dsize - wsize2;
+ }
+ if (rem)
+ {
+ wsize = sizeof(_enq_tail) > rec_offs ? sizeof(_enq_tail) - rec_offs : 0;
+ wsize2 = wsize;
+ if (wsize)
+ {
+ if (wsize > rem)
+ wsize = rem;
+ std::memcpy((char*)wptr + wr_cnt, (char*)&_enq_tail + rec_offs, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ rec_offs -= sizeof(_enq_tail) - wsize2;
+ }
+ assert(rem == 0);
+ assert(rec_offs == 0);
+ }
+ else // No further split required
+ {
+ rec_offs -= sizeof(_enq_hdr);
+ std::size_t wsize = _enq_hdr._xidsize > rec_offs ? _enq_hdr._xidsize - rec_offs : 0;
+ if (wsize)
+ {
+ std::memcpy(wptr, (const char*)_xidp + rec_offs, wsize);
+ wr_cnt += wsize;
+ }
+ rec_offs -= _enq_hdr._xidsize - wsize;
+ wsize = _enq_hdr._dsize > rec_offs ? _enq_hdr._dsize - rec_offs : 0;
+ if (wsize && !_enq_hdr.is_external())
+ {
+ std::memcpy((char*)wptr + wr_cnt, (const char*)_data + rec_offs, wsize);
+ wr_cnt += wsize;
+ }
+ rec_offs -= _enq_hdr._dsize - wsize;
+ wsize = sizeof(_enq_tail) > rec_offs ? sizeof(_enq_tail) - rec_offs : 0;
+ if (wsize)
+ {
+ std::memcpy((char*)wptr + wr_cnt, (char*)&_enq_tail + rec_offs, wsize);
+ wr_cnt += wsize;
+#ifdef RHM_CLEAN
+ std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+ std::size_t dblk_rec_size = size_dblks(rec_size() - rec_offs) * JRNL_DBLK_SIZE;
+ std::memset((char*)wptr + wr_cnt, RHM_CLEAN_CHAR, dblk_rec_size - wr_cnt);
+#endif
+ }
+ rec_offs -= sizeof(_enq_tail) - wsize;
+ assert(rec_offs == 0);
+ }
+ }
+ else // Start at beginning of data record
+ {
+ // Assumption: the header will always fit into the first dblk
+ std::memcpy(wptr, (void*)&_enq_hdr, sizeof(_enq_hdr));
+ wr_cnt = sizeof(_enq_hdr);
+ if (size_dblks(rec_size()) > max_size_dblks) // Split required
+ {
+ std::size_t wsize;
+ rem -= sizeof(_enq_hdr);
+ if (rem)
+ {
+ wsize = rem >= _enq_hdr._xidsize ? _enq_hdr._xidsize : rem;
+ std::memcpy((char*)wptr + wr_cnt, _xidp, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ if (rem && !_enq_hdr.is_external())
+ {
+ wsize = rem >= _enq_hdr._dsize ? _enq_hdr._dsize : rem;
+ std::memcpy((char*)wptr + wr_cnt, _data, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ if (rem)
+ {
+ wsize = rem >= sizeof(_enq_tail) ? sizeof(_enq_tail) : rem;
+ std::memcpy((char*)wptr + wr_cnt, (void*)&_enq_tail, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ assert(rem == 0);
+ }
+ else // No split required
+ {
+ if (_enq_hdr._xidsize)
+ {
+ std::memcpy((char*)wptr + wr_cnt, _xidp, _enq_hdr._xidsize);
+ wr_cnt += _enq_hdr._xidsize;
+ }
+ if (!_enq_hdr.is_external())
+ {
+ std::memcpy((char*)wptr + wr_cnt, _data, _enq_hdr._dsize);
+ wr_cnt += _enq_hdr._dsize;
+ }
+ std::memcpy((char*)wptr + wr_cnt, (void*)&_enq_tail, sizeof(_enq_tail));
+ wr_cnt += sizeof(_enq_tail);
+#ifdef RHM_CLEAN
+ std::size_t dblk_rec_size = size_dblks(rec_size()) * JRNL_DBLK_SIZE;
+ std::memset((char*)wptr + wr_cnt, RHM_CLEAN_CHAR, dblk_rec_size - wr_cnt);
+#endif
+ }
+ }
+ return size_dblks(wr_cnt);
+}
+
+u_int32_t
+enq_rec::decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+{
+ assert(rptr != 0);
+ assert(max_size_dblks > 0);
+
+ std::size_t rd_cnt = 0;
+ if (rec_offs_dblks) // Continuation of record on new page
+ {
+ const u_int32_t hdr_xid_data_size = enq_hdr::size() + _enq_hdr._xidsize +
+ (_enq_hdr.is_external() ? 0 : _enq_hdr._dsize);
+ const u_int32_t hdr_xid_data_tail_size = hdr_xid_data_size + rec_tail::size();
+ const u_int32_t hdr_data_dblks = size_dblks(hdr_xid_data_size);
+ const u_int32_t hdr_tail_dblks = size_dblks(hdr_xid_data_tail_size);
+ const std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+ const std::size_t offs = rec_offs - enq_hdr::size();
+
+ if (hdr_tail_dblks - rec_offs_dblks <= max_size_dblks)
+ {
+ // Remainder of record fits within this page
+ if (offs < _enq_hdr._xidsize)
+ {
+ // some XID still outstanding, copy remainder of XID, data and tail
+ const std::size_t rem = _enq_hdr._xidsize + _enq_hdr._dsize - offs;
+ std::memcpy((char*)_buff + offs, rptr, rem);
+ rd_cnt += rem;
+ std::memcpy((void*)&_enq_tail, ((char*)rptr + rd_cnt), sizeof(_enq_tail));
+ chk_tail();
+ rd_cnt += sizeof(_enq_tail);
+ }
+ else if (offs < _enq_hdr._xidsize + _enq_hdr._dsize && !_enq_hdr.is_external())
+ {
+ // some data still outstanding, copy remainder of data and tail
+ const std::size_t data_offs = offs - _enq_hdr._xidsize;
+ const std::size_t data_rem = _enq_hdr._dsize - data_offs;
+ std::memcpy((char*)_buff + offs, rptr, data_rem);
+ rd_cnt += data_rem;
+ std::memcpy((void*)&_enq_tail, ((char*)rptr + rd_cnt), sizeof(_enq_tail));
+ chk_tail();
+ rd_cnt += sizeof(_enq_tail);
+ }
+ else
+ {
+ // Tail or part of tail only outstanding, complete tail
+ const std::size_t tail_offs = rec_offs - enq_hdr::size() - _enq_hdr._xidsize -
+ _enq_hdr._dsize;
+ const std::size_t tail_rem = rec_tail::size() - tail_offs;
+ std::memcpy((char*)&_enq_tail + tail_offs, rptr, tail_rem);
+ chk_tail();
+ rd_cnt = tail_rem;
+ }
+ }
+ else if (hdr_data_dblks - rec_offs_dblks <= max_size_dblks)
+ {
+ // Remainder of xid & data fits within this page; tail split
+
+ /*
+ * TODO: This section needs revision. Since it is known that the end of the page falls within the
+ * tail record, it is only necessary to write from the current offset to the end of the page under
+ * all circumstances. The multiple if/else combinations may be eliminated, as well as one memcpy()
+ * operation.
+ *
+ * Also note that Coverity has detected a possible memory overwrite in this block. It occurs if
+ * both the following two if() stmsts (numbered) are false. With rd_cnt = 0, this would result in
+ * the value of tail_rem > sizeof(tail_rec). Practically, this could only happen if the start and
+ * end of a page both fall within the same tail record, in which case the tail would have to be
+ * (much!) larger. However, the logic here does not account for this possibility.
+ *
+ * If the optimization above is undertaken, this code would probably be removed.
+ */
+ if (offs < _enq_hdr._xidsize) // 1
+ {
+ // some XID still outstanding, copy remainder of XID and data
+ const std::size_t rem = _enq_hdr._xidsize + _enq_hdr._dsize - offs;
+ std::memcpy((char*)_buff + offs, rptr, rem);
+ rd_cnt += rem;
+ }
+ else if (offs < _enq_hdr._xidsize + _enq_hdr._dsize && !_enq_hdr.is_external()) // 2
+ {
+ // some data still outstanding, copy remainder of data
+ const std::size_t data_offs = offs - _enq_hdr._xidsize;
+ const std::size_t data_rem = _enq_hdr._dsize - data_offs;
+ std::memcpy((char*)_buff + offs, rptr, data_rem);
+ rd_cnt += data_rem;
+ }
+ const std::size_t tail_rem = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ if (tail_rem)
+ {
+ std::memcpy((void*)&_enq_tail, ((char*)rptr + rd_cnt), tail_rem);
+ rd_cnt += tail_rem;
+ }
+ }
+ else
+ {
+ // Since xid and data are contiguous, both fit within current page - copy whole page
+ const std::size_t data_cp_size = (max_size_dblks * JRNL_DBLK_SIZE);
+ std::memcpy((char*)_buff + offs, rptr, data_cp_size);
+ rd_cnt += data_cp_size;
+ }
+ }
+ else // Start of record
+ {
+ // Get and check header
+ _enq_hdr.hdr_copy(h);
+ rd_cnt = sizeof(rec_hdr);
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ rd_cnt += sizeof(u_int32_t); // Filler 0
+#endif
+ _enq_hdr._xidsize = *(std::size_t*)((char*)rptr + rd_cnt);
+ rd_cnt += sizeof(std::size_t);
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ rd_cnt += sizeof(u_int32_t); // Filler 0
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ rd_cnt += sizeof(u_int32_t); // Filler 1
+#endif
+ _enq_hdr._dsize = *(std::size_t*)((char*)rptr + rd_cnt);
+ rd_cnt = _enq_hdr.size();
+ chk_hdr();
+ if (_enq_hdr._xidsize + (_enq_hdr.is_external() ? 0 : _enq_hdr._dsize))
+ {
+ _buff = std::malloc(_enq_hdr._xidsize + (_enq_hdr.is_external() ? 0 : _enq_hdr._dsize));
+ MALLOC_CHK(_buff, "_buff", "enq_rec", "decode");
+
+ const u_int32_t hdr_xid_size = enq_hdr::size() + _enq_hdr._xidsize;
+ const u_int32_t hdr_xid_data_size = hdr_xid_size + (_enq_hdr.is_external() ? 0 : _enq_hdr._dsize);
+ const u_int32_t hdr_xid_data_tail_size = hdr_xid_data_size + rec_tail::size();
+ const u_int32_t hdr_xid_dblks = size_dblks(hdr_xid_size);
+ const u_int32_t hdr_data_dblks = size_dblks(hdr_xid_data_size);
+ const u_int32_t hdr_tail_dblks = size_dblks(hdr_xid_data_tail_size);
+ // Check if record (header + data + tail) fits within this page, we can check the
+ // tail before the expense of copying data to memory
+ if (hdr_tail_dblks <= max_size_dblks)
+ {
+ // Header, xid, data and tail fits within this page
+ if (_enq_hdr._xidsize)
+ {
+ std::memcpy(_buff, (char*)rptr + rd_cnt, _enq_hdr._xidsize);
+ rd_cnt += _enq_hdr._xidsize;
+ }
+ if (_enq_hdr._dsize && !_enq_hdr.is_external())
+ {
+ std::memcpy((char*)_buff + _enq_hdr._xidsize, (char*)rptr + rd_cnt,
+ _enq_hdr._dsize);
+ rd_cnt += _enq_hdr._dsize;
+ }
+ std::memcpy((void*)&_enq_tail, (char*)rptr + rd_cnt, sizeof(_enq_tail));
+ chk_tail();
+ rd_cnt += sizeof(_enq_tail);
+ }
+ else if (hdr_data_dblks <= max_size_dblks)
+ {
+ // Header, xid and data fit within this page, tail split or separated
+ if (_enq_hdr._xidsize)
+ {
+ std::memcpy(_buff, (char*)rptr + rd_cnt, _enq_hdr._xidsize);
+ rd_cnt += _enq_hdr._xidsize;
+ }
+ if (_enq_hdr._dsize && !_enq_hdr.is_external())
+ {
+ std::memcpy((char*)_buff + _enq_hdr._xidsize, (char*)rptr + rd_cnt,
+ _enq_hdr._dsize);
+ rd_cnt += _enq_hdr._dsize;
+ }
+ const std::size_t tail_rem = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ if (tail_rem)
+ {
+ std::memcpy((void*)&_enq_tail, (char*)rptr + rd_cnt, tail_rem);
+ rd_cnt += tail_rem;
+ }
+ }
+ else if (hdr_xid_dblks <= max_size_dblks)
+ {
+ // Header and xid fits within this page, data split or separated
+ if (_enq_hdr._xidsize)
+ {
+ std::memcpy(_buff, (char*)rptr + rd_cnt, _enq_hdr._xidsize);
+ rd_cnt += _enq_hdr._xidsize;
+ }
+ if (_enq_hdr._dsize && !_enq_hdr.is_external())
+ {
+ const std::size_t data_cp_size = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ std::memcpy((char*)_buff + _enq_hdr._xidsize, (char*)rptr + rd_cnt, data_cp_size);
+ rd_cnt += data_cp_size;
+ }
+ }
+ else
+ {
+ // Header fits within this page, xid split or separated
+ const std::size_t data_cp_size = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ std::memcpy(_buff, (char*)rptr + rd_cnt, data_cp_size);
+ rd_cnt += data_cp_size;
+ }
+ }
+ }
+ return size_dblks(rd_cnt);
+}
+
+bool
+enq_rec::rcv_decode(rec_hdr h, std::ifstream* ifsp, std::size_t& rec_offs)
+{
+ if (rec_offs == 0)
+ {
+ // Read header, allocate (if req'd) for xid
+ _enq_hdr.hdr_copy(h);
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ ifsp->ignore(sizeof(u_int32_t)); // _filler0
+#endif
+ ifsp->read((char*)&_enq_hdr._xidsize, sizeof(std::size_t));
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ ifsp->ignore(sizeof(u_int32_t)); // _filler0
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ ifsp->ignore(sizeof(u_int32_t)); // _filler1
+#endif
+ ifsp->read((char*)&_enq_hdr._dsize, sizeof(std::size_t));
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ ifsp->ignore(sizeof(u_int32_t)); // _filler1
+#endif
+ rec_offs = sizeof(_enq_hdr);
+ if (_enq_hdr._xidsize)
+ {
+ _buff = std::malloc(_enq_hdr._xidsize);
+ MALLOC_CHK(_buff, "_buff", "enq_rec", "rcv_decode");
+ }
+ }
+ if (rec_offs < sizeof(_enq_hdr) + _enq_hdr._xidsize)
+ {
+ // Read xid (or continue reading xid)
+ std::size_t offs = rec_offs - sizeof(_enq_hdr);
+ ifsp->read((char*)_buff + offs, _enq_hdr._xidsize - offs);
+ std::size_t size_read = ifsp->gcount();
+ rec_offs += size_read;
+ if (size_read < _enq_hdr._xidsize - offs)
+ {
+ assert(ifsp->eof());
+ // As we may have read past eof, turn off fail bit
+ ifsp->clear(ifsp->rdstate()&(~std::ifstream::failbit));
+ assert(!ifsp->fail() && !ifsp->bad());
+ return false;
+ }
+ }
+ if (!_enq_hdr.is_external())
+ {
+ if (rec_offs < sizeof(_enq_hdr) + _enq_hdr._xidsize + _enq_hdr._dsize)
+ {
+ // Ignore data (or continue ignoring data)
+ std::size_t offs = rec_offs - sizeof(_enq_hdr) - _enq_hdr._xidsize;
+ ifsp->ignore(_enq_hdr._dsize - offs);
+ std::size_t size_read = ifsp->gcount();
+ rec_offs += size_read;
+ if (size_read < _enq_hdr._dsize - offs)
+ {
+ assert(ifsp->eof());
+ // As we may have read past eof, turn off fail bit
+ ifsp->clear(ifsp->rdstate()&(~std::ifstream::failbit));
+ assert(!ifsp->fail() && !ifsp->bad());
+ return false;
+ }
+ }
+ }
+ if (rec_offs < sizeof(_enq_hdr) + _enq_hdr._xidsize +
+ (_enq_hdr.is_external() ? 0 : _enq_hdr._dsize) + sizeof(rec_tail))
+ {
+ // Read tail (or continue reading tail)
+ std::size_t offs = rec_offs - sizeof(_enq_hdr) - _enq_hdr._xidsize;
+ if (!_enq_hdr.is_external())
+ offs -= _enq_hdr._dsize;
+ ifsp->read((char*)&_enq_tail + offs, sizeof(rec_tail) - offs);
+ std::size_t size_read = ifsp->gcount();
+ rec_offs += size_read;
+ if (size_read < sizeof(rec_tail) - offs)
+ {
+ assert(ifsp->eof());
+ // As we may have read past eof, turn off fail bit
+ ifsp->clear(ifsp->rdstate()&(~std::ifstream::failbit));
+ assert(!ifsp->fail() && !ifsp->bad());
+ return false;
+ }
+ }
+ ifsp->ignore(rec_size_dblks() * JRNL_DBLK_SIZE - rec_size());
+ chk_tail(); // Throws if tail invalid or record incomplete
+ assert(!ifsp->fail() && !ifsp->bad());
+ return true;
+}
+
+std::size_t
+enq_rec::get_xid(void** const xidpp)
+{
+ if (!_buff || !_enq_hdr._xidsize)
+ {
+ *xidpp = 0;
+ return 0;
+ }
+ *xidpp = _buff;
+ return _enq_hdr._xidsize;
+}
+
+std::size_t
+enq_rec::get_data(void** const datapp)
+{
+ if (!_buff)
+ {
+ *datapp = 0;
+ return 0;
+ }
+ if (_enq_hdr.is_external())
+ *datapp = 0;
+ else
+ *datapp = (void*)((char*)_buff + _enq_hdr._xidsize);
+ return _enq_hdr._dsize;
+}
+
+std::string&
+enq_rec::str(std::string& str) const
+{
+ std::ostringstream oss;
+ oss << "enq_rec: m=" << _enq_hdr._magic;
+ oss << " v=" << (int)_enq_hdr._version;
+ oss << " rid=" << _enq_hdr._rid;
+ if (_xidp)
+ oss << " xid=\"" << _xidp << "\"";
+ oss << " len=" << _enq_hdr._dsize;
+ str.append(oss.str());
+ return str;
+}
+
+std::size_t
+enq_rec::rec_size() const
+{
+ return rec_size(_enq_hdr._xidsize, _enq_hdr._dsize, _enq_hdr.is_external());
+}
+
+std::size_t
+enq_rec::rec_size(const std::size_t xidsize, const std::size_t dsize, const bool external)
+{
+ if (external)
+ return enq_hdr::size() + xidsize + rec_tail::size();
+ return enq_hdr::size() + xidsize + dsize + rec_tail::size();
+}
+
+void
+enq_rec::set_rid(const u_int64_t rid)
+{
+ _enq_hdr._rid = rid;
+ _enq_tail._rid = rid;
+}
+
+void
+enq_rec::chk_hdr() const
+{
+ jrec::chk_hdr(_enq_hdr);
+ if (_enq_hdr._magic != RHM_JDAT_ENQ_MAGIC)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "enq magic: rid=0x" << std::setw(16) << _enq_hdr._rid;
+ oss << ": expected=0x" << std::setw(8) << RHM_JDAT_ENQ_MAGIC;
+ oss << " read=0x" << std::setw(2) << (int)_enq_hdr._magic;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "enq_rec", "chk_hdr");
+ }
+}
+
+void
+enq_rec::chk_hdr(u_int64_t rid) const
+{
+ chk_hdr();
+ jrec::chk_rid(_enq_hdr, rid);
+}
+
+void
+enq_rec::chk_tail() const
+{
+ jrec::chk_tail(_enq_tail, _enq_hdr);
+}
+
+void
+enq_rec::clean()
+{
+ // clean up allocated memory here
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/enq_rec.h b/cpp/src/qpid/legacystore/jrnl/enq_rec.h
new file mode 100644
index 0000000000..805a96a1aa
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/enq_rec.h
@@ -0,0 +1,116 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file enq_rec.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the code for the mrg::journal::enq_rec (journal enqueue
+ * record) class. See class documentation for details.
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_ENQ_REC_H
+#define QPID_LEGACYSTORE_JRNL_ENQ_REC_H
+
+namespace mrg
+{
+namespace journal
+{
+class enq_rec;
+}
+}
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/enq_hdr.h"
+#include "qpid/legacystore/jrnl/jrec.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class enq_rec
+ * \brief Class to handle a single journal enqueue record.
+ */
+ class enq_rec : public jrec
+ {
+ private:
+ enq_hdr _enq_hdr;
+ const void* _xidp; ///< xid pointer for encoding (for writing to disk)
+ const void* _data; ///< Pointer to data to be written to disk
+ void* _buff; ///< Pointer to buffer to receive data read from disk
+ rec_tail _enq_tail;
+
+ public:
+ /**
+ * \brief Constructor used for read operations.
+ */
+ enq_rec();
+
+ /**
+ * \brief Constructor used for write operations, where mbuf contains data to be written.
+ */
+ enq_rec(const u_int64_t rid, const void* const dbuf, const std::size_t dlen,
+ const void* const xidp, const std::size_t xidlen, const bool owi, const bool transient);
+
+ /**
+ * \brief Destructor
+ */
+ virtual ~enq_rec();
+
+ // Prepare instance for use in reading data from journal, xid and data will be allocated
+ void reset();
+ // Prepare instance for use in writing data to journal
+ void reset(const u_int64_t rid, const void* const dbuf, const std::size_t dlen,
+ const void* const xidp, const std::size_t xidlen, const bool owi, const bool transient,
+ const bool external);
+
+ u_int32_t encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks);
+ u_int32_t decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks,
+ u_int32_t max_size_dblks);
+ // Decode used for recover
+ bool rcv_decode(rec_hdr h, std::ifstream* ifsp, std::size_t& rec_offs);
+
+ std::size_t get_xid(void** const xidpp);
+ std::size_t get_data(void** const datapp);
+ inline bool is_transient() const { return _enq_hdr.is_transient(); }
+ inline bool is_external() const { return _enq_hdr.is_external(); }
+ std::string& str(std::string& str) const;
+ inline std::size_t data_size() const { return _enq_hdr._dsize; }
+ inline std::size_t xid_size() const { return _enq_hdr._xidsize; }
+ std::size_t rec_size() const;
+ static std::size_t rec_size(const std::size_t xidsize, const std::size_t dsize, const bool external);
+ inline u_int64_t rid() const { return _enq_hdr._rid; }
+ void set_rid(const u_int64_t rid);
+
+ private:
+ void chk_hdr() const;
+ void chk_hdr(u_int64_t rid) const;
+ void chk_tail() const;
+ virtual void clean();
+ }; // class enq_rec
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_ENQ_REC_H
diff --git a/cpp/src/qpid/legacystore/jrnl/enums.h b/cpp/src/qpid/legacystore/jrnl/enums.h
new file mode 100644
index 0000000000..169a13fa4d
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/enums.h
@@ -0,0 +1,108 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file enums.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing definitions for namespace mrg::journal enums.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_ENUMS_H
+#define QPID_LEGACYSTORE_JRNL_ENUMS_H
+
+namespace mrg
+{
+namespace journal
+{
+
+ // TODO: Change this to flags, as multiple of these conditions may exist simultaneously
+ /**
+ * \brief Enumeration of possilbe return states from journal read and write operations.
+ */
+ enum _iores
+ {
+ RHM_IORES_SUCCESS = 0, ///< Success: IO operation completed noramlly.
+ RHM_IORES_PAGE_AIOWAIT, ///< IO operation suspended - next page is waiting for AIO.
+ RHM_IORES_FILE_AIOWAIT, ///< IO operation suspended - next file is waiting for AIO.
+ RHM_IORES_EMPTY, ///< During read operations, nothing further is available to read.
+ RHM_IORES_RCINVALID, ///< Read page cache is invalid (ie obsolete or uninitialized)
+ RHM_IORES_ENQCAPTHRESH, ///< Enqueue capacity threshold (limit) reached.
+ RHM_IORES_FULL, ///< During write operations, the journal files are full.
+ RHM_IORES_BUSY, ///< Another blocking operation is in progress.
+ RHM_IORES_TXPENDING, ///< Operation blocked by pending transaction.
+ RHM_IORES_NOTIMPL ///< Function is not yet implemented.
+ };
+ typedef _iores iores;
+
+ static inline const char* iores_str(iores res)
+ {
+ switch (res)
+ {
+ case RHM_IORES_SUCCESS: return "RHM_IORES_SUCCESS";
+ case RHM_IORES_PAGE_AIOWAIT: return "RHM_IORES_PAGE_AIOWAIT";
+ case RHM_IORES_FILE_AIOWAIT: return "RHM_IORES_FILE_AIOWAIT";
+ case RHM_IORES_EMPTY: return "RHM_IORES_EMPTY";
+ case RHM_IORES_RCINVALID: return "RHM_IORES_RCINVALID";
+ case RHM_IORES_ENQCAPTHRESH: return "RHM_IORES_ENQCAPTHRESH";
+ case RHM_IORES_FULL: return "RHM_IORES_FULL";
+ case RHM_IORES_BUSY: return "RHM_IORES_BUSY";
+ case RHM_IORES_TXPENDING: return "RHM_IORES_TXPENDING";
+ case RHM_IORES_NOTIMPL: return "RHM_IORES_NOTIMPL";
+ }
+ return "<iores unknown>";
+ }
+
+ enum _log_level
+ {
+ LOG_TRACE = 0,
+ LOG_DEBUG,
+ LOG_INFO,
+ LOG_NOTICE,
+ LOG_WARN,
+ LOG_ERROR,
+ LOG_CRITICAL
+ };
+ typedef _log_level log_level;
+
+ static inline const char* log_level_str(log_level ll)
+ {
+ switch (ll)
+ {
+ case LOG_TRACE: return "TRACE";
+ case LOG_DEBUG: return "DEBUG";
+ case LOG_INFO: return "INFO";
+ case LOG_NOTICE: return "NOTICE";
+ case LOG_WARN: return "WARN";
+ case LOG_ERROR: return "ERROR";
+ case LOG_CRITICAL: return "CRITICAL";
+ }
+ return "<log level unknown>";
+ }
+
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_ENUMS_H
diff --git a/cpp/src/qpid/legacystore/jrnl/fcntl.cpp b/cpp/src/qpid/legacystore/jrnl/fcntl.cpp
new file mode 100644
index 0000000000..fbb176667e
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/fcntl.cpp
@@ -0,0 +1,375 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file fcntl.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::fcntl (non-logging file
+ * handle), used for controlling journal log files. See comments in file
+ * fcntl.h for details.
+ */
+
+#include "qpid/legacystore/jrnl/fcntl.h"
+
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include <fcntl.h>
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <sstream>
+#include <unistd.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+fcntl::fcntl(const std::string& fbasename, const u_int16_t pfid, const u_int16_t lfid, const u_int32_t jfsize_sblks,
+ const rcvdat* const ro):
+ _fname(),
+ _pfid(pfid),
+ _lfid(lfid),
+ _ffull_dblks(JRNL_SBLK_SIZE * (jfsize_sblks + 1)),
+ _wr_fh(-1),
+ _rec_enqcnt(0),
+ _rd_subm_cnt_dblks(0),
+ _rd_cmpl_cnt_dblks(0),
+ _wr_subm_cnt_dblks(0),
+ _wr_cmpl_cnt_dblks(0),
+ _aio_cnt(0),
+ _fhdr_wr_aio_outstanding(false)
+{
+ initialize(fbasename, pfid, lfid, jfsize_sblks, ro);
+ open_wr_fh();
+}
+
+fcntl::~fcntl()
+{
+ close_wr_fh();
+}
+
+bool
+fcntl::reset(const rcvdat* const ro)
+{
+ rd_reset();
+ return wr_reset(ro);
+}
+
+void
+fcntl::rd_reset()
+{
+ _rd_subm_cnt_dblks = 0;
+ _rd_cmpl_cnt_dblks = 0;
+}
+
+bool
+fcntl::wr_reset(const rcvdat* const ro)
+{
+ if (ro)
+ {
+ if (!ro->_jempty)
+ {
+ if (ro->_lfid == _pfid)
+ {
+ _wr_subm_cnt_dblks = ro->_eo/JRNL_DBLK_SIZE;
+ _wr_cmpl_cnt_dblks = ro->_eo/JRNL_DBLK_SIZE;
+ }
+ else
+ {
+ _wr_subm_cnt_dblks = _ffull_dblks;
+ _wr_cmpl_cnt_dblks = _ffull_dblks;
+ }
+ _rec_enqcnt = ro->_enq_cnt_list[_pfid];
+ return true;
+ }
+ }
+ // Journal overflow test - checks if the file to be reset still contains enqueued records
+ // or outstanding aios
+ if (_rec_enqcnt || _aio_cnt)
+ return false;
+ _wr_subm_cnt_dblks = 0;
+ _wr_cmpl_cnt_dblks = 0;
+ return true;
+}
+
+int
+fcntl::open_wr_fh()
+{
+ if (_wr_fh < 0)
+ {
+ _wr_fh = ::open(_fname.c_str(), O_WRONLY | O_DIRECT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // 0644 -rw-r--r--
+ if (_wr_fh < 0)
+ {
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " lfid=" << _lfid << " file=\"" << _fname << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_FCNTL_OPENWR, oss.str(), "fcntl", "open_fh");
+ }
+ }
+ return _wr_fh;
+}
+
+void
+fcntl::close_wr_fh()
+{
+ if (_wr_fh >= 0)
+ {
+ ::close(_wr_fh);
+ _wr_fh = -1;
+ }
+}
+
+u_int32_t
+fcntl::add_enqcnt(u_int32_t a)
+{
+ _rec_enqcnt += a;
+ return _rec_enqcnt;
+}
+
+u_int32_t
+fcntl::decr_enqcnt()
+{
+ if (_rec_enqcnt == 0)
+ {
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " lfid=" << _lfid;
+ throw jexception(jerrno::JERR__UNDERFLOW, oss.str(), "fcntl", "decr_enqcnt");
+ }
+ return --_rec_enqcnt;
+}
+
+u_int32_t
+fcntl::subtr_enqcnt(u_int32_t s)
+{
+ if (_rec_enqcnt < s)
+ {
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " lfid=" << _lfid << " rec_enqcnt=" << _rec_enqcnt << " decr=" << s;
+ throw jexception(jerrno::JERR__UNDERFLOW, oss.str(), "fcntl", "subtr_enqcnt");
+ }
+ _rec_enqcnt -= s;
+ return _rec_enqcnt;
+}
+
+u_int32_t
+fcntl::add_rd_subm_cnt_dblks(u_int32_t a)
+{
+ if (_rd_subm_cnt_dblks + a > _wr_subm_cnt_dblks)
+ {
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " lfid=" << _lfid << " rd_subm_cnt_dblks=" << _rd_subm_cnt_dblks << " incr=" << a;
+ oss << " wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks;
+ throw jexception(jerrno::JERR_FCNTL_RDOFFSOVFL, oss.str(), "fcntl", "add_rd_subm_cnt_dblks");
+ }
+ _rd_subm_cnt_dblks += a;
+ return _rd_subm_cnt_dblks;
+}
+
+u_int32_t
+fcntl::add_rd_cmpl_cnt_dblks(u_int32_t a)
+{
+ if (_rd_cmpl_cnt_dblks + a > _rd_subm_cnt_dblks)
+ {
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " lfid=" << _lfid << " rd_cmpl_cnt_dblks=" << _rd_cmpl_cnt_dblks << " incr=" << a;
+ oss << " rd_subm_cnt_dblks=" << _rd_subm_cnt_dblks;
+ throw jexception(jerrno::JERR_FCNTL_CMPLOFFSOVFL, oss.str(), "fcntl", "add_rd_cmpl_cnt_dblks");
+ }
+ _rd_cmpl_cnt_dblks += a;
+ return _rd_cmpl_cnt_dblks;
+}
+
+u_int32_t
+fcntl::add_wr_subm_cnt_dblks(u_int32_t a)
+{
+ if (_wr_subm_cnt_dblks + a > _ffull_dblks) // Allow for file header
+ {
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " lfid=" << _lfid << " wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks << " incr=" << a;
+ oss << " fsize=" << _ffull_dblks << " dblks";
+ throw jexception(jerrno::JERR_FCNTL_FILEOFFSOVFL, oss.str(), "fcntl", "add_wr_subm_cnt_dblks");
+ }
+ _wr_subm_cnt_dblks += a;
+ return _wr_subm_cnt_dblks;
+}
+
+u_int32_t
+fcntl::add_wr_cmpl_cnt_dblks(u_int32_t a)
+{
+ if (_wr_cmpl_cnt_dblks + a > _wr_subm_cnt_dblks)
+ {
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " lfid=" << _lfid << " wr_cmpl_cnt_dblks=" << _wr_cmpl_cnt_dblks << " incr=" << a;
+ oss << " wr_subm_cnt_dblks=" << _wr_subm_cnt_dblks;
+ throw jexception(jerrno::JERR_FCNTL_CMPLOFFSOVFL, oss.str(), "fcntl", "add_wr_cmpl_cnt_dblks");
+ }
+ _wr_cmpl_cnt_dblks += a;
+ return _wr_cmpl_cnt_dblks;
+}
+
+u_int16_t
+fcntl::decr_aio_cnt()
+{
+ if(_aio_cnt == 0)
+ {
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " lfid=" << _lfid << " Decremented aio_cnt to below zero";
+ throw jexception(jerrno::JERR__UNDERFLOW, oss.str(), "fcntl", "decr_aio_cnt");
+ }
+ return --_aio_cnt;
+}
+
+// Debug function
+const std::string
+fcntl::status_str() const
+{
+ std::ostringstream oss;
+ oss << "pfid=" << _pfid << " ws=" << _wr_subm_cnt_dblks << " wc=" << _wr_cmpl_cnt_dblks;
+ oss << " rs=" << _rd_subm_cnt_dblks << " rc=" << _rd_cmpl_cnt_dblks;
+ oss << " ec=" << _rec_enqcnt << " ac=" << _aio_cnt;
+ return oss.str();
+}
+
+// Protected functions
+
+void
+fcntl::initialize(const std::string& fbasename, const u_int16_t pfid, const u_int16_t lfid, const u_int32_t jfsize_sblks,
+ const rcvdat* const ro)
+{
+ _pfid = pfid;
+ _lfid = lfid;
+ _fname = filename(fbasename, pfid);
+
+#ifdef RHM_JOWRITE
+ // In test mode, only create file if it does not exist
+ struct stat s;
+ if (::stat(_fname.c_str(), &s))
+ {
+#endif
+ if (ro) // Recovery initialization: set counters only
+ {
+ if (!ro->_jempty)
+ {
+ // For last file only, set write counters to end of last record (the
+ // continuation point); for all others, set to eof.
+ if (ro->_lfid == _pfid)
+ {
+ _wr_subm_cnt_dblks = ro->_eo/JRNL_DBLK_SIZE;
+ _wr_cmpl_cnt_dblks = ro->_eo/JRNL_DBLK_SIZE;
+ }
+ else
+ {
+ _wr_subm_cnt_dblks = _ffull_dblks;
+ _wr_cmpl_cnt_dblks = _ffull_dblks;
+ }
+ // Set the number of enqueued records for this file.
+ _rec_enqcnt = ro->_enq_cnt_list[_pfid];
+ }
+ }
+ else // Normal initialization: create empty journal files
+ create_jfile(jfsize_sblks);
+#ifdef RHM_JOWRITE
+ }
+#endif
+}
+
+std::string
+fcntl::filename(const std::string& fbasename, const u_int16_t pfid)
+{
+ std::ostringstream oss;
+ oss << fbasename << ".";
+ oss << std::setw(4) << std::setfill('0') << std::hex << pfid;
+ oss << "." << JRNL_DATA_EXTENSION;
+ return oss.str();
+}
+
+void
+fcntl::clean_file(const u_int32_t jfsize_sblks)
+{
+ // NOTE: The journal file size is always one sblock bigger than the specified journal
+ // file size, which is the data content size. The extra block is for the journal file
+ // header which precedes all data on each file and is exactly one sblock in size.
+ u_int32_t nsblks = jfsize_sblks + 1;
+
+ // TODO - look at more efficient alternatives to allocating a null block:
+ // 1. mmap() against /dev/zero, but can alignment for O_DIRECT be assured?
+ // 2. ftruncate(), but does this result in a sparse file? If so, then this is no good.
+
+ // Create temp null block for writing
+ const std::size_t sblksize = JRNL_DBLK_SIZE * JRNL_SBLK_SIZE;
+ void* nullbuf = 0;
+ // Allocate no more than 2MB (4096 sblks) as a null buffer
+ const u_int32_t nullbuffsize_sblks = nsblks > 4096 ? 4096 : nsblks;
+ const std::size_t nullbuffsize = nullbuffsize_sblks * sblksize;
+ if (::posix_memalign(&nullbuf, sblksize, nullbuffsize))
+ {
+ std::ostringstream oss;
+ oss << "posix_memalign() failed: size=" << nullbuffsize << " blk_size=" << sblksize;
+ oss << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), "fcntl", "clean_file");
+ }
+ std::memset(nullbuf, 0, nullbuffsize);
+
+ int fh = ::open(_fname.c_str(), O_WRONLY | O_CREAT | O_DIRECT,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // 0644 -rw-r--r--
+ if (fh < 0)
+ {
+ std::free(nullbuf);
+ std::ostringstream oss;
+ oss << "open() failed:" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_FCNTL_OPENWR, oss.str(), "fcntl", "clean_file");
+ }
+
+ while (nsblks > 0)
+ {
+ u_int32_t this_write_sblks = nsblks >= nullbuffsize_sblks ? nullbuffsize_sblks : nsblks;
+ if (::write(fh, nullbuf, this_write_sblks * sblksize) == -1)
+ {
+ ::close(fh);
+ std::free(nullbuf);
+ std::ostringstream oss;
+ oss << "wr_size=" << (this_write_sblks * sblksize) << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_FCNTL_WRITE, oss.str(), "fcntl", "clean_file");
+ }
+ nsblks -= this_write_sblks;
+ }
+
+ // Clean up
+ std::free(nullbuf);
+ if (::close(fh))
+ {
+ std::ostringstream oss;
+ oss << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_FCNTL_CLOSE, oss.str(), "fcntl", "clean_file");
+ }
+}
+
+void
+fcntl::create_jfile(const u_int32_t jfsize_sblks)
+{
+ clean_file(jfsize_sblks);
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/fcntl.h b/cpp/src/qpid/legacystore/jrnl/fcntl.h
new file mode 100644
index 0000000000..a75e3bc84d
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/fcntl.h
@@ -0,0 +1,156 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file fcntl.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::fcntl (non-logging file
+ * handle), used for controlling journal log files. See class documentation for
+ * details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_FCNTL_H
+#define QPID_LEGACYSTORE_JRNL_FCNTL_H
+
+namespace mrg
+{
+namespace journal
+{
+class fcntl;
+}
+}
+
+#include <cstddef>
+#include <string>
+#include "qpid/legacystore/jrnl/rcvdat.h"
+#include <sys/types.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class fcntl
+ * \brief Journal file controller. There is one instance per journal file.
+ */
+ class fcntl
+ {
+ protected:
+ std::string _fname; ///< File name
+ u_int16_t _pfid; ///< Physical file ID (file number in order of creation)
+ u_int16_t _lfid; ///< Logical file ID (ordinal number in ring store)
+ const u_int32_t _ffull_dblks; ///< File size in dblks (incl. file header)
+ int _wr_fh; ///< Write file handle
+ u_int32_t _rec_enqcnt; ///< Count of enqueued records
+ u_int32_t _rd_subm_cnt_dblks; ///< Read file count (data blocks) for submitted AIO
+ u_int32_t _rd_cmpl_cnt_dblks; ///< Read file count (data blocks) for completed AIO
+ u_int32_t _wr_subm_cnt_dblks; ///< Write file count (data blocks) for submitted AIO
+ u_int32_t _wr_cmpl_cnt_dblks; ///< Write file count (data blocks) for completed AIO
+ u_int16_t _aio_cnt; ///< Outstanding AIO operations on this file
+ bool _fhdr_wr_aio_outstanding; ///< Outstanding file header write on this file
+
+ public:
+ // Constructors with implicit initialize() and open()
+ fcntl(const std::string& fbasename, const u_int16_t pfid, const u_int16_t lfid, const u_int32_t jfsize_sblks,
+ const rcvdat* const ro);
+ virtual ~fcntl();
+
+ virtual bool reset(const rcvdat* const ro = 0);
+ virtual void rd_reset();
+ virtual bool wr_reset(const rcvdat* const ro = 0);
+
+ virtual int open_wr_fh();
+ virtual void close_wr_fh();
+ inline bool is_wr_fh_open() const { return _wr_fh >= 0; }
+
+ inline const std::string& fname() const { return _fname; }
+ inline u_int16_t pfid() const { return _pfid; }
+ inline u_int16_t lfid() const { return _lfid; }
+ inline void set_lfid(const u_int16_t lfid) { _lfid = lfid; }
+ inline int wr_fh() const { return _wr_fh; }
+ inline u_int32_t enqcnt() const { return _rec_enqcnt; }
+ inline u_int32_t incr_enqcnt() { return ++_rec_enqcnt; }
+ u_int32_t add_enqcnt(u_int32_t a);
+ u_int32_t decr_enqcnt();
+ u_int32_t subtr_enqcnt(u_int32_t s);
+
+ inline u_int32_t rd_subm_cnt_dblks() const { return _rd_subm_cnt_dblks; }
+ inline std::size_t rd_subm_offs() const { return _rd_subm_cnt_dblks * JRNL_DBLK_SIZE; }
+ u_int32_t add_rd_subm_cnt_dblks(u_int32_t a);
+
+ inline u_int32_t rd_cmpl_cnt_dblks() const { return _rd_cmpl_cnt_dblks; }
+ inline std::size_t rd_cmpl_offs() const { return _rd_cmpl_cnt_dblks * JRNL_DBLK_SIZE; }
+ u_int32_t add_rd_cmpl_cnt_dblks(u_int32_t a);
+
+ inline u_int32_t wr_subm_cnt_dblks() const { return _wr_subm_cnt_dblks; }
+ inline std::size_t wr_subm_offs() const { return _wr_subm_cnt_dblks * JRNL_DBLK_SIZE; }
+ u_int32_t add_wr_subm_cnt_dblks(u_int32_t a);
+
+ inline u_int32_t wr_cmpl_cnt_dblks() const { return _wr_cmpl_cnt_dblks; }
+ inline std::size_t wr_cmpl_offs() const { return _wr_cmpl_cnt_dblks * JRNL_DBLK_SIZE; }
+ u_int32_t add_wr_cmpl_cnt_dblks(u_int32_t a);
+
+ inline u_int16_t aio_cnt() const { return _aio_cnt; }
+ inline u_int16_t incr_aio_cnt() { return ++_aio_cnt; }
+ u_int16_t decr_aio_cnt();
+
+ inline bool wr_fhdr_aio_outstanding() { return _fhdr_wr_aio_outstanding; }
+ inline void set_wr_fhdr_aio_outstanding(const bool wfao) { _fhdr_wr_aio_outstanding = wfao; }
+
+ // Derived helper functions
+
+ inline bool rd_void() const { return _wr_cmpl_cnt_dblks == 0; }
+ inline bool rd_empty() const { return _wr_cmpl_cnt_dblks <= JRNL_SBLK_SIZE; }
+ inline u_int32_t rd_remaining_dblks() const { return _wr_cmpl_cnt_dblks - _rd_subm_cnt_dblks; }
+ inline bool is_rd_full() const { return _wr_cmpl_cnt_dblks == _rd_subm_cnt_dblks; }
+ inline bool is_rd_compl() const { return _wr_cmpl_cnt_dblks == _rd_cmpl_cnt_dblks; }
+ inline u_int32_t rd_aio_outstanding_dblks() const { return _rd_subm_cnt_dblks - _rd_cmpl_cnt_dblks; }
+ inline bool rd_file_rotate() const { return is_rd_full() && is_wr_compl(); }
+
+ inline bool wr_void() const { return _wr_subm_cnt_dblks == 0; }
+ inline bool wr_empty() const { return _wr_subm_cnt_dblks <= JRNL_SBLK_SIZE; }
+ inline u_int32_t wr_remaining_dblks() const { return _ffull_dblks - _wr_subm_cnt_dblks; }
+ inline bool is_wr_full() const { return _ffull_dblks == _wr_subm_cnt_dblks; }
+ inline bool is_wr_compl() const { return _ffull_dblks == _wr_cmpl_cnt_dblks; }
+ inline u_int32_t wr_aio_outstanding_dblks() const { return _wr_subm_cnt_dblks - _wr_cmpl_cnt_dblks; }
+ inline bool wr_file_rotate() const { return is_wr_full(); }
+
+ // Debug aid
+ const std::string status_str() const;
+
+ protected:
+ virtual void initialize(const std::string& fbasename, const u_int16_t pfid, const u_int16_t lfid,
+ const u_int32_t jfsize_sblks, const rcvdat* const ro);
+
+ static std::string filename(const std::string& fbasename, const u_int16_t pfid);
+ void clean_file(const u_int32_t jfsize_sblks);
+ void create_jfile(const u_int32_t jfsize_sblks);
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_FCNTL_H
diff --git a/cpp/src/qpid/legacystore/jrnl/file_hdr.h b/cpp/src/qpid/legacystore/jrnl/file_hdr.h
new file mode 100644
index 0000000000..db20834cbb
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/file_hdr.h
@@ -0,0 +1,211 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file file_hdr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::file_hdr (file
+ * record header), used to start a journal file. It contains some
+ * file metadata and information to aid journal recovery.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_FILE_HDR_H
+#define QPID_LEGACYSTORE_JRNL_FILE_HDR_H
+
+#include <cerrno>
+#include <ctime>
+#include "qpid/legacystore/jrnl/rec_hdr.h"
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for data common to the head of all journal files. In addition to
+ * the common data, this includes the record ID and offset of the first record in
+ * the file.
+ *
+ * This header precedes all data in journal files and occupies the first complete
+ * block in the file. The record ID and offset are updated on each overwrite of the
+ * file.
+ *
+ * File header info in binary format (48 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+ -+
+ * | magic | v | e | flags | |
+ * +---+---+---+---+---+---+---+---+ | struct hdr
+ * | first rid in file | |
+ * +---+---+---+---+---+---+---+---+ -+
+ * | pfid | lfid | reserved (0) |
+ * +---+---+---+---+---+---+---+---+
+ * | fro |
+ * +---+---+---+---+---+---+---+---+
+ * | timestamp (sec) |
+ * +---+---+---+---+---+---+---+---+
+ * | timestamp (ns) |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * pfid = File ID (number used in naming file)
+ * lfid = Logical ID (order used in circular buffer)
+ * fro = First record offset, offset from start of file to first record header
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct file_hdr : rec_hdr
+ {
+ u_int16_t _pfid; ///< Physical file ID (pfid)
+ u_int16_t _lfid; ///< Logical file ID (lfid)
+ u_int32_t _res; ///< Reserved (for alignment/flags)
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+#endif
+ std::size_t _fro; ///< First record offset
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler1; ///< Big-endian filler for 32-bit time_t
+#endif
+ std::time_t _ts_sec; ///< Timestamp of journal initilailization
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler1; ///< Little-endian filler for 32-bit time_t
+#endif
+#if defined(JRNL_BIG_ENDIAN)
+ u_int32_t _filler2; ///< Big endian filler for u_int32_t
+#endif
+ u_int32_t _ts_nsec; ///< Timestamp of journal initilailization
+#if defined(JRNL_LITTLE_ENDIAN)
+ u_int32_t _filler2; ///< Little-endian filler for u_int32_t
+#endif
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline file_hdr(): rec_hdr(), _pfid(0), _lfid(0), _res(0),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _fro(0),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+ _ts_sec(0),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN)
+ _filler2(0),
+#endif
+ _ts_nsec(0)
+#if defined(JRNL_LITTLE_ENDIAN)
+ , _filler2(0)
+#endif
+ {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline file_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const u_int16_t pfid, const u_int16_t lfid, const std::size_t fro,
+ const bool owi, const bool settime = false):
+ rec_hdr(magic, version, rid, owi), _pfid(pfid), _lfid(lfid), _res(0),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _fro(fro),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+ _ts_sec(0),
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ _filler1(0),
+#endif
+#if defined(JRNL_BIG_ENDIAN)
+ _filler2(0),
+#endif
+ _ts_nsec(0)
+#if defined(JRNL_LITTLE_ENDIAN)
+ , _filler2(0)
+#endif
+ { if (settime) set_time(); }
+
+ /**
+ * \brief Gets the current time from the system clock and sets the timestamp in the struct.
+ */
+ inline void set_time()
+ {
+ // TODO: Standardize on method for getting time that does not requrie a context switch.
+ timespec ts;
+ if (::clock_gettime(CLOCK_REALTIME, &ts))
+ {
+ std::ostringstream oss;
+ oss << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR__RTCLOCK, oss.str(), "file_hdr", "set_time");
+ }
+ _ts_sec = ts.tv_sec;
+ _ts_nsec = ts.tv_nsec;
+ }
+
+ /**
+ * \brief Sets the timestamp in the struct to the provided value (in seconds and
+ * nanoseconds).
+ */
+ inline void set_time(timespec& ts)
+ {
+ _ts_sec = ts.tv_sec;
+ _ts_nsec = ts.tv_nsec;
+ }
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static std::size_t size() { return sizeof(file_hdr); }
+ }; // struct file_hdr
+
+#pragma pack()
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_FILE_HDR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/jcfg.h b/cpp/src/qpid/legacystore/jrnl/jcfg.h
new file mode 100644
index 0000000000..0a0d0df28d
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jcfg.h
@@ -0,0 +1,91 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jcfg.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains \#defines that control the implementation details of
+ * the journal.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_JCFG_H
+#define QPID_LEGACYSTORE_JRNL_JCFG_H
+
+#if defined(__i386__) /* little endian, 32 bits */
+#define JRNL_LITTLE_ENDIAN
+#define JRNL_32_BIT
+#elif defined(__PPC__) || defined(__s390__) /* big endian, 32 bits */
+#define JRNL_BIG_ENDIAN
+#define JRNL_32_BIT
+#elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__) /* little endian, 64 bits */
+#define JRNL_LITTLE_ENDIAN
+#define JRNL_64_BIT
+#elif defined(__powerpc64__) || defined(__s390x__) /* big endian, 64 bits */
+#define JRNL_BIG_ENDIAN
+#define JRNL_64_BIT
+#else
+#error endian?
+#endif
+
+
+/**
+* <b>Rule:</b> Data block size (JRNL_DBLK_SIZE) MUST be a power of 2 such that
+* <pre>
+* JRNL_DBLK_SIZE * JRNL_SBLK_SIZE == n * 512 (n = 1,2,3...)
+* </pre>
+* (The disk softblock size is 512 for Linux kernels >= 2.6)
+*/
+#define JRNL_DBLK_SIZE 128 ///< Data block size in bytes (CANNOT BE LESS THAN 32!)
+#define JRNL_SBLK_SIZE 4 ///< Disk softblock size in multiples of JRNL_DBLK_SIZE
+#define JRNL_MIN_FILE_SIZE 128 ///< Min. jrnl file size in sblks (excl. file_hdr)
+#define JRNL_MAX_FILE_SIZE 4194176 ///< Max. jrnl file size in sblks (excl. file_hdr)
+#define JRNL_MIN_NUM_FILES 4 ///< Min. number of journal files
+#define JRNL_MAX_NUM_FILES 64 ///< Max. number of journal files
+#define JRNL_ENQ_THRESHOLD 80 ///< Percent full when enqueue connection will be closed
+
+#define JRNL_RMGR_PAGE_SIZE 128 ///< Journal page size in softblocks
+#define JRNL_RMGR_PAGES 16 ///< Number of pages to use in wmgr
+
+#define JRNL_WMGR_DEF_PAGE_SIZE 64 ///< Journal write page size in softblocks (default)
+#define JRNL_WMGR_DEF_PAGES 32 ///< Number of pages to use in wmgr (default)
+
+#define JRNL_WMGR_MAXDTOKPP 1024 ///< Max. dtoks (data blocks) per page in wmgr
+#define JRNL_WMGR_MAXWAITUS 100 ///< Max. wait time (us) before submitting AIO
+
+#define JRNL_INFO_EXTENSION "jinf" ///< Extension for journal info files
+#define JRNL_DATA_EXTENSION "jdat" ///< Extension for journal data files
+#define RHM_JDAT_TXA_MAGIC 0x614d4852 ///< ("RHMa" in little endian) Magic for dtx abort hdrs
+#define RHM_JDAT_TXC_MAGIC 0x634d4852 ///< ("RHMc" in little endian) Magic for dtx commit hdrs
+#define RHM_JDAT_DEQ_MAGIC 0x644d4852 ///< ("RHMd" in little endian) Magic for deq rec hdrs
+#define RHM_JDAT_ENQ_MAGIC 0x654d4852 ///< ("RHMe" in little endian) Magic for enq rec hdrs
+#define RHM_JDAT_FILE_MAGIC 0x664d4852 ///< ("RHMf" in little endian) Magic for file hdrs
+#define RHM_JDAT_EMPTY_MAGIC 0x784d4852 ///< ("RHMx" in little endian) Magic for empty dblk
+#define RHM_JDAT_VERSION 0x01 ///< Version (of file layout)
+#define RHM_CLEAN_CHAR 0xff ///< Char used to clear empty space on disk
+
+#define RHM_LENDIAN_FLAG 0 ///< Value of little endian flag on disk
+#define RHM_BENDIAN_FLAG 1 ///< Value of big endian flag on disk
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_JCFG_H
diff --git a/cpp/src/qpid/legacystore/jrnl/jcntl.cpp b/cpp/src/qpid/legacystore/jrnl/jcntl.cpp
new file mode 100644
index 0000000000..a03076dca5
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jcntl.cpp
@@ -0,0 +1,984 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jcntl.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Messaging journal top-level control and interface class
+ * mrg::journal::jcntl. See comments in file jcntl.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+
+#include "qpid/legacystore/jrnl/jcntl.h"
+
+#include <algorithm>
+#include <cassert>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+#include "qpid/legacystore/jrnl/file_hdr.h"
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jinf.h"
+#include <limits>
+#include <sstream>
+#include <unistd.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+#define AIO_CMPL_TIMEOUT_SEC 5
+#define AIO_CMPL_TIMEOUT_NSEC 0
+#define FINAL_AIO_CMPL_TIMEOUT_SEC 15
+#define FINAL_AIO_CMPL_TIMEOUT_NSEC 0
+
+// Static
+timespec jcntl::_aio_cmpl_timeout; ///< Timeout for blocking libaio returns
+timespec jcntl::_final_aio_cmpl_timeout; ///< Timeout for blocking libaio returns when stopping or finalizing
+bool jcntl::_init = init_statics();
+bool jcntl::init_statics()
+{
+ _aio_cmpl_timeout.tv_sec = AIO_CMPL_TIMEOUT_SEC;
+ _aio_cmpl_timeout.tv_nsec = AIO_CMPL_TIMEOUT_NSEC;
+ _final_aio_cmpl_timeout.tv_sec = FINAL_AIO_CMPL_TIMEOUT_SEC;
+ _final_aio_cmpl_timeout.tv_nsec = FINAL_AIO_CMPL_TIMEOUT_NSEC;
+ return true;
+}
+
+
+// Functions
+
+jcntl::jcntl(const std::string& jid, const std::string& jdir, const std::string& base_filename):
+ _jid(jid),
+ _jdir(jdir, base_filename),
+ _base_filename(base_filename),
+ _init_flag(false),
+ _stop_flag(false),
+ _readonly_flag(false),
+ _autostop(true),
+ _jfsize_sblks(0),
+ _lpmgr(),
+ _emap(),
+ _tmap(),
+ _rrfc(&_lpmgr),
+ _wrfc(&_lpmgr),
+ _rmgr(this, _emap, _tmap, _rrfc),
+ _wmgr(this, _emap, _tmap, _wrfc),
+ _rcvdat()
+{}
+
+jcntl::~jcntl()
+{
+ if (_init_flag && !_stop_flag)
+ try { stop(true); }
+ catch (const jexception& e) { std::cerr << e << std::endl; }
+ _lpmgr.finalize();
+}
+
+void
+jcntl::initialize(const u_int16_t num_jfiles, const bool ae, const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks, const u_int16_t wcache_num_pages, const u_int32_t wcache_pgsize_sblks,
+ aio_callback* const cbp)
+{
+ _init_flag = false;
+ _stop_flag = false;
+ _readonly_flag = false;
+
+ _emap.clear();
+ _tmap.clear();
+
+ _lpmgr.finalize();
+
+ // Set new file geometry parameters
+ assert(num_jfiles >= JRNL_MIN_NUM_FILES);
+ assert(num_jfiles <= JRNL_MAX_NUM_FILES);
+ _emap.set_num_jfiles(num_jfiles);
+ _tmap.set_num_jfiles(num_jfiles);
+
+ assert(jfsize_sblks >= JRNL_MIN_FILE_SIZE);
+ assert(jfsize_sblks <= JRNL_MAX_FILE_SIZE);
+ _jfsize_sblks = jfsize_sblks;
+
+ // Clear any existing journal files
+ _jdir.clear_dir();
+ _lpmgr.initialize(num_jfiles, ae, ae_max_jfiles, this, &new_fcntl);
+
+ _wrfc.initialize(_jfsize_sblks);
+ _rrfc.initialize();
+ _rrfc.set_findex(0);
+ _rmgr.initialize(cbp);
+ _wmgr.initialize(cbp, wcache_pgsize_sblks, wcache_num_pages, JRNL_WMGR_MAXDTOKPP, JRNL_WMGR_MAXWAITUS);
+
+ // Write info file (<basename>.jinf) to disk
+ write_infofile();
+
+ _init_flag = true;
+}
+
+void
+jcntl::recover(const u_int16_t num_jfiles, const bool ae, const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks, const u_int16_t wcache_num_pages, const u_int32_t wcache_pgsize_sblks,
+// const rd_aio_cb rd_cb, const wr_aio_cb wr_cb, const std::vector<std::string>* prep_txn_list_ptr,
+ aio_callback* const cbp, const std::vector<std::string>* prep_txn_list_ptr,
+ u_int64_t& highest_rid)
+{
+ _init_flag = false;
+ _stop_flag = false;
+ _readonly_flag = false;
+
+ _emap.clear();
+ _tmap.clear();
+
+ _lpmgr.finalize();
+
+ assert(num_jfiles >= JRNL_MIN_NUM_FILES);
+ assert(num_jfiles <= JRNL_MAX_NUM_FILES);
+ assert(jfsize_sblks >= JRNL_MIN_FILE_SIZE);
+ assert(jfsize_sblks <= JRNL_MAX_FILE_SIZE);
+ _jfsize_sblks = jfsize_sblks;
+
+ // Verify journal dir and journal files
+ _jdir.verify_dir();
+ _rcvdat.reset(num_jfiles, ae, ae_max_jfiles);
+
+ rcvr_janalyze(_rcvdat, prep_txn_list_ptr);
+ highest_rid = _rcvdat._h_rid;
+ if (_rcvdat._jfull)
+ throw jexception(jerrno::JERR_JCNTL_RECOVERJFULL, "jcntl", "recover");
+ this->log(LOG_DEBUG, _rcvdat.to_log(_jid));
+
+ _lpmgr.recover(_rcvdat, this, &new_fcntl);
+
+ _wrfc.initialize(_jfsize_sblks, &_rcvdat);
+ _rrfc.initialize();
+ _rrfc.set_findex(_rcvdat.ffid());
+ _rmgr.initialize(cbp);
+ _wmgr.initialize(cbp, wcache_pgsize_sblks, wcache_num_pages, JRNL_WMGR_MAXDTOKPP, JRNL_WMGR_MAXWAITUS,
+ (_rcvdat._lffull ? 0 : _rcvdat._eo));
+
+ _readonly_flag = true;
+ _init_flag = true;
+}
+
+void
+jcntl::recover_complete()
+{
+ if (!_readonly_flag)
+ throw jexception(jerrno::JERR_JCNTL_NOTRECOVERED, "jcntl", "recover_complete");
+ for (u_int16_t i=0; i<_lpmgr.num_jfiles(); i++)
+ _lpmgr.get_fcntlp(i)->reset(&_rcvdat);
+ _wrfc.initialize(_jfsize_sblks, &_rcvdat);
+ _rrfc.initialize();
+ _rrfc.set_findex(_rcvdat.ffid());
+ _rmgr.recover_complete();
+ _readonly_flag = false;
+}
+
+void
+jcntl::delete_jrnl_files()
+{
+ stop(true); // wait for AIO to complete
+ _jdir.delete_dir();
+}
+
+
+iores
+jcntl::enqueue_data_record(const void* const data_buff, const std::size_t tot_data_len,
+ const std::size_t this_data_len, data_tok* dtokp, const bool transient)
+{
+ iores r;
+ check_wstatus("enqueue_data_record");
+ {
+ slock s(_wr_mutex);
+ while (handle_aio_wait(_wmgr.enqueue(data_buff, tot_data_len, this_data_len, dtokp, 0, 0, transient, false), r,
+ dtokp)) ;
+ }
+ return r;
+}
+
+iores
+jcntl::enqueue_extern_data_record(const std::size_t tot_data_len, data_tok* dtokp, const bool transient)
+{
+ iores r;
+ check_wstatus("enqueue_extern_data_record");
+ {
+ slock s(_wr_mutex);
+ while (handle_aio_wait(_wmgr.enqueue(0, tot_data_len, 0, dtokp, 0, 0, transient, true), r, dtokp)) ;
+ }
+ return r;
+}
+
+iores
+jcntl::enqueue_txn_data_record(const void* const data_buff, const std::size_t tot_data_len,
+ const std::size_t this_data_len, data_tok* dtokp, const std::string& xid,
+ const bool transient)
+{
+ iores r;
+ check_wstatus("enqueue_tx_data_record");
+ {
+ slock s(_wr_mutex);
+ while (handle_aio_wait(_wmgr.enqueue(data_buff, tot_data_len, this_data_len, dtokp, xid.data(), xid.size(),
+ transient, false), r, dtokp)) ;
+ }
+ return r;
+}
+
+iores
+jcntl::enqueue_extern_txn_data_record(const std::size_t tot_data_len, data_tok* dtokp,
+ const std::string& xid, const bool transient)
+{
+ iores r;
+ check_wstatus("enqueue_extern_txn_data_record");
+ {
+ slock s(_wr_mutex);
+ while (handle_aio_wait(_wmgr.enqueue(0, tot_data_len, 0, dtokp, xid.data(), xid.size(), transient, true), r,
+ dtokp)) ;
+ }
+ return r;
+}
+
+/* TODO
+iores
+jcntl::get_data_record(const u_int64_t& rid, const std::size_t& dsize, const std::size_t& dsize_avail,
+ const void** const data, bool auto_discard)
+{
+ check_rstatus("get_data_record");
+ return _rmgr.get(rid, dsize, dsize_avail, data, auto_discard);
+} */
+
+/* TODO
+iores
+jcntl::discard_data_record(data_tok* const dtokp)
+{
+ check_rstatus("discard_data_record");
+ return _rmgr.discard(dtokp);
+} */
+
+iores
+jcntl::read_data_record(void** const datapp, std::size_t& dsize, void** const xidpp, std::size_t& xidsize,
+ bool& transient, bool& external, data_tok* const dtokp, bool ignore_pending_txns)
+{
+ check_rstatus("read_data");
+ iores res = _rmgr.read(datapp, dsize, xidpp, xidsize, transient, external, dtokp, ignore_pending_txns);
+ if (res == RHM_IORES_RCINVALID)
+ {
+ get_wr_events(0); // check for outstanding write events
+ iores sres = _rmgr.synchronize(); // flushes all outstanding read events
+ if (sres != RHM_IORES_SUCCESS)
+ return sres;
+ _rmgr.wait_for_validity(&_aio_cmpl_timeout, true); // throw if timeout occurs
+ res = _rmgr.read(datapp, dsize, xidpp, xidsize, transient, external, dtokp, ignore_pending_txns);
+ }
+ return res;
+}
+
+iores
+jcntl::dequeue_data_record(data_tok* const dtokp, const bool txn_coml_commit)
+{
+ iores r;
+ check_wstatus("dequeue_data");
+ {
+ slock s(_wr_mutex);
+ while (handle_aio_wait(_wmgr.dequeue(dtokp, 0, 0, txn_coml_commit), r, dtokp)) ;
+ }
+ return r;
+}
+
+iores
+jcntl::dequeue_txn_data_record(data_tok* const dtokp, const std::string& xid, const bool txn_coml_commit)
+{
+ iores r;
+ check_wstatus("dequeue_data");
+ {
+ slock s(_wr_mutex);
+ while (handle_aio_wait(_wmgr.dequeue(dtokp, xid.data(), xid.size(), txn_coml_commit), r, dtokp)) ;
+ }
+ return r;
+}
+
+iores
+jcntl::txn_abort(data_tok* const dtokp, const std::string& xid)
+{
+ iores r;
+ check_wstatus("txn_abort");
+ {
+ slock s(_wr_mutex);
+ while (handle_aio_wait(_wmgr.abort(dtokp, xid.data(), xid.size()), r, dtokp)) ;
+ }
+ return r;
+}
+
+iores
+jcntl::txn_commit(data_tok* const dtokp, const std::string& xid)
+{
+ iores r;
+ check_wstatus("txn_commit");
+ {
+ slock s(_wr_mutex);
+ while (handle_aio_wait(_wmgr.commit(dtokp, xid.data(), xid.size()), r, dtokp)) ;
+ }
+ return r;
+}
+
+bool
+jcntl::is_txn_synced(const std::string& xid)
+{
+ slock s(_wr_mutex);
+ bool res = _wmgr.is_txn_synced(xid);
+ return res;
+}
+
+int32_t
+jcntl::get_wr_events(timespec* const timeout)
+{
+ stlock t(_wr_mutex);
+ if (!t.locked())
+ return jerrno::LOCK_TAKEN;
+ int32_t res = _wmgr.get_events(pmgr::UNUSED, timeout);
+ return res;
+}
+
+int32_t
+jcntl::get_rd_events(timespec* const timeout)
+{
+ return _rmgr.get_events(pmgr::AIO_COMPLETE, timeout);
+}
+
+void
+jcntl::stop(const bool block_till_aio_cmpl)
+{
+ if (_readonly_flag)
+ check_rstatus("stop");
+ else
+ check_wstatus("stop");
+ _stop_flag = true;
+ if (!_readonly_flag)
+ flush(block_till_aio_cmpl);
+ _rrfc.finalize();
+ _lpmgr.finalize();
+}
+
+u_int16_t
+jcntl::get_earliest_fid()
+{
+ u_int16_t ffid = _wrfc.earliest_index();
+ u_int16_t fid = _wrfc.index();
+ while ( _emap.get_enq_cnt(ffid) == 0 && _tmap.get_txn_pfid_cnt(ffid) == 0 && ffid != fid)
+ {
+ if (++ffid >= _lpmgr.num_jfiles())
+ ffid = 0;
+ }
+ if (!_rrfc.is_active())
+ _rrfc.set_findex(ffid);
+ return ffid;
+}
+
+iores
+jcntl::flush(const bool block_till_aio_cmpl)
+{
+ if (!_init_flag)
+ return RHM_IORES_SUCCESS;
+ if (_readonly_flag)
+ throw jexception(jerrno::JERR_JCNTL_READONLY, "jcntl", "flush");
+ iores res;
+ {
+ slock s(_wr_mutex);
+ res = _wmgr.flush();
+ }
+ if (block_till_aio_cmpl)
+ aio_cmpl_wait();
+ return res;
+}
+
+void
+jcntl::log(log_level ll, const std::string& log_stmt) const
+{
+ log(ll, log_stmt.c_str());
+}
+
+void
+jcntl::log(log_level ll, const char* const log_stmt) const
+{
+ if (ll > LOG_INFO)
+ {
+ std::cout << log_level_str(ll) << ": Journal \"" << _jid << "\": " << log_stmt << std::endl;
+ }
+}
+
+void
+jcntl::chk_wr_frot()
+{
+ if (_wrfc.index() == _rrfc.index())
+ _rmgr.invalidate();
+}
+
+void
+jcntl::fhdr_wr_sync(const u_int16_t lid)
+{
+ fcntl* fcntlp = _lpmgr.get_fcntlp(lid);
+ while (fcntlp->wr_fhdr_aio_outstanding())
+ {
+ if (get_wr_events(&_aio_cmpl_timeout) == jerrno::AIO_TIMEOUT)
+ throw jexception(jerrno::JERR_JCNTL_AIOCMPLWAIT, "jcntl", "fhdr_wr_sync");
+ }
+}
+
+fcntl*
+jcntl::new_fcntl(jcntl* const jcp, const u_int16_t lid, const u_int16_t fid, const rcvdat* const rdp)
+{
+ if (!jcp) return 0;
+ std::ostringstream oss;
+ oss << jcp->jrnl_dir() << "/" << jcp->base_filename();
+ return new fcntl(oss.str(), fid, lid, jcp->jfsize_sblks(), rdp);
+}
+
+// Protected/Private functions
+
+void
+jcntl::check_wstatus(const char* fn_name) const
+{
+ if (!_init_flag)
+ throw jexception(jerrno::JERR__NINIT, "jcntl", fn_name);
+ if (_readonly_flag)
+ throw jexception(jerrno::JERR_JCNTL_READONLY, "jcntl", fn_name);
+ if (_stop_flag)
+ throw jexception(jerrno::JERR_JCNTL_STOPPED, "jcntl", fn_name);
+}
+
+void
+jcntl::check_rstatus(const char* fn_name) const
+{
+ if (!_init_flag)
+ throw jexception(jerrno::JERR__NINIT, "jcntl", fn_name);
+ if (_stop_flag)
+ throw jexception(jerrno::JERR_JCNTL_STOPPED, "jcntl", fn_name);
+}
+
+void
+jcntl::write_infofile() const
+{
+ timespec ts;
+ if (::clock_gettime(CLOCK_REALTIME, &ts))
+ {
+ std::ostringstream oss;
+ oss << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR__RTCLOCK, oss.str(), "jcntl", "write_infofile");
+ }
+ jinf ji(_jid, _jdir.dirname(), _base_filename, _lpmgr.num_jfiles(), _lpmgr.is_ae(), _lpmgr.ae_max_jfiles(),
+ _jfsize_sblks, _wmgr.cache_pgsize_sblks(), _wmgr.cache_num_pages(), ts);
+ ji.write();
+}
+
+void
+jcntl::aio_cmpl_wait()
+{
+ //while (_wmgr.get_aio_evt_rem())
+ while (true)
+ {
+ u_int32_t aer;
+ {
+ slock s(_wr_mutex);
+ aer = _wmgr.get_aio_evt_rem();
+ }
+ if (aer == 0) break; // no events left
+ if (get_wr_events(&_aio_cmpl_timeout) == jerrno::AIO_TIMEOUT)
+ throw jexception(jerrno::JERR_JCNTL_AIOCMPLWAIT, "jcntl", "aio_cmpl_wait");
+ }
+}
+
+bool
+jcntl::handle_aio_wait(const iores res, iores& resout, const data_tok* dtp)
+{
+ resout = res;
+ if (res == RHM_IORES_PAGE_AIOWAIT)
+ {
+ while (_wmgr.curr_pg_blocked())
+ {
+ if (_wmgr.get_events(pmgr::UNUSED, &_aio_cmpl_timeout) == jerrno::AIO_TIMEOUT)
+ {
+ std::ostringstream oss;
+ oss << "get_events() returned JERR_JCNTL_AIOCMPLWAIT; wmgr_status: " << _wmgr.status_str();
+ this->log(LOG_CRITICAL, oss.str());
+ throw jexception(jerrno::JERR_JCNTL_AIOCMPLWAIT, "jcntl", "handle_aio_wait");
+ }
+ }
+ return true;
+ }
+ else if (res == RHM_IORES_FILE_AIOWAIT)
+ {
+ while (_wmgr.curr_file_blocked())
+ {
+ if (_wmgr.get_events(pmgr::UNUSED, &_aio_cmpl_timeout) == jerrno::AIO_TIMEOUT)
+ {
+ std::ostringstream oss;
+ oss << "get_events() returned JERR_JCNTL_AIOCMPLWAIT; wmgr_status: " << _wmgr.status_str();
+ this->log(LOG_CRITICAL, oss.str());
+ throw jexception(jerrno::JERR_JCNTL_AIOCMPLWAIT, "jcntl", "handle_aio_wait");
+ }
+ }
+ _wrfc.wr_reset();
+ resout = RHM_IORES_SUCCESS;
+ data_tok::write_state ws = dtp->wstate();
+ return ws == data_tok::ENQ_PART || ws == data_tok::DEQ_PART || ws == data_tok::ABORT_PART ||
+ ws == data_tok::COMMIT_PART;
+ }
+ return false;
+}
+
+void
+jcntl::rcvr_janalyze(rcvdat& rd, const std::vector<std::string>* prep_txn_list_ptr)
+{
+ jinf ji(_jdir.dirname() + "/" + _base_filename + "." + JRNL_INFO_EXTENSION, true);
+
+ // If the number of files does not tie up with the jinf file from the journal being recovered,
+ // use the jinf data.
+ if (rd._njf != ji.num_jfiles())
+ {
+ std::ostringstream oss;
+ oss << "Recovery found " << ji.num_jfiles() <<
+ " files (different from --num-jfiles value of " << rd._njf << ").";
+ this->log(LOG_WARN, oss.str());
+ rd._njf = ji.num_jfiles();
+ _rcvdat._enq_cnt_list.resize(rd._njf);
+ }
+ _emap.set_num_jfiles(rd._njf);
+ _tmap.set_num_jfiles(rd._njf);
+ if (_jfsize_sblks != ji.jfsize_sblks())
+ {
+ std::ostringstream oss;
+ oss << "Recovery found file size = " << (ji.jfsize_sblks() / JRNL_RMGR_PAGE_SIZE) <<
+ " (different from --jfile-size-pgs value of " <<
+ (_jfsize_sblks / JRNL_RMGR_PAGE_SIZE) << ").";
+ this->log(LOG_WARN, oss.str());
+ _jfsize_sblks = ji.jfsize_sblks();
+ }
+ if (_jdir.dirname().compare(ji.jdir()))
+ {
+ std::ostringstream oss;
+ oss << "Journal file location change: original = \"" << ji.jdir() <<
+ "\"; current = \"" << _jdir.dirname() << "\"";
+ this->log(LOG_WARN, oss.str());
+ ji.set_jdir(_jdir.dirname());
+ }
+
+ try
+ {
+ rd._ffid = ji.get_first_pfid();
+ rd._lfid = ji.get_last_pfid();
+ rd._owi = ji.get_initial_owi();
+ rd._frot = ji.get_frot();
+ rd._jempty = false;
+ ji.get_normalized_pfid_list(rd._fid_list); // _pfid_list
+ }
+ catch (const jexception& e)
+ {
+ if (e.err_code() != jerrno::JERR_JINF_JDATEMPTY) throw;
+ }
+
+ // Restore all read and write pointers and transactions
+ if (!rd._jempty)
+ {
+ u_int16_t fid = rd._ffid;
+ std::ifstream ifs;
+ bool lowi = rd._owi; // local copy of owi to be used during analysis
+ while (rcvr_get_next_record(fid, &ifs, lowi, rd)) ;
+ if (ifs.is_open()) ifs.close();
+
+ // Remove all txns from tmap that are not in the prepared list
+ if (prep_txn_list_ptr)
+ {
+ std::vector<std::string> xid_list;
+ _tmap.xid_list(xid_list);
+ for (std::vector<std::string>::iterator itr = xid_list.begin(); itr != xid_list.end(); itr++)
+ {
+ std::vector<std::string>::const_iterator pitr =
+ std::find(prep_txn_list_ptr->begin(), prep_txn_list_ptr->end(), *itr);
+ if (pitr == prep_txn_list_ptr->end()) // not found in prepared list
+ {
+ txn_data_list tdl = _tmap.get_remove_tdata_list(*itr); // tdl will be empty if xid not found
+ // Unlock any affected enqueues in emap
+ for (tdl_itr i=tdl.begin(); i<tdl.end(); i++)
+ {
+ if (i->_enq_flag) // enq op - decrement enqueue count
+ rd._enq_cnt_list[i->_pfid]--;
+ else if (_emap.is_enqueued(i->_drid, true)) // deq op - unlock enq record
+ {
+ int16_t ret = _emap.unlock(i->_drid);
+ if (ret < enq_map::EMAP_OK) // fail
+ {
+ // enq_map::unlock()'s only error is enq_map::EMAP_RID_NOT_FOUND
+ std::ostringstream oss;
+ oss << std::hex << "_emap.unlock(): drid=0x\"" << i->_drid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "jcntl", "rcvr_janalyze");
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Check for file full condition - add one to _jfsize_sblks to account for file header
+ rd._lffull = rd._eo == (1 + _jfsize_sblks) * JRNL_SBLK_SIZE * JRNL_DBLK_SIZE;
+
+ // Check for journal full condition
+ u_int16_t next_wr_fid = (rd._lfid + 1) % rd._njf;
+ rd._jfull = rd._ffid == next_wr_fid && rd._enq_cnt_list[next_wr_fid] && rd._lffull;
+ }
+}
+
+bool
+jcntl::rcvr_get_next_record(u_int16_t& fid, std::ifstream* ifsp, bool& lowi, rcvdat& rd)
+{
+ std::size_t cum_size_read = 0;
+ void* xidp = 0;
+ rec_hdr h;
+
+ bool hdr_ok = false;
+ std::streampos file_pos;
+ while (!hdr_ok)
+ {
+ if (!ifsp->is_open())
+ {
+ if (!jfile_cycle(fid, ifsp, lowi, rd, true))
+ return false;
+ }
+ file_pos = ifsp->tellg();
+ ifsp->read((char*)&h, sizeof(rec_hdr));
+ if (ifsp->gcount() == sizeof(rec_hdr))
+ hdr_ok = true;
+ else
+ {
+ if (!jfile_cycle(fid, ifsp, lowi, rd, true))
+ return false;
+ }
+ }
+
+ switch(h._magic)
+ {
+ case RHM_JDAT_ENQ_MAGIC:
+ {
+ enq_rec er;
+ u_int16_t start_fid = fid; // fid may increment in decode() if record folds over file boundary
+ if (!decode(er, fid, ifsp, cum_size_read, h, lowi, rd, file_pos))
+ return false;
+ if (!er.is_transient()) // Ignore transient msgs
+ {
+ rd._enq_cnt_list[start_fid]++;
+ if (er.xid_size())
+ {
+ er.get_xid(&xidp);
+ assert(xidp != 0);
+ std::string xid((char*)xidp, er.xid_size());
+ _tmap.insert_txn_data(xid, txn_data(h._rid, 0, start_fid, true));
+ if (_tmap.set_aio_compl(xid, h._rid) < txn_map::TMAP_OK) // fail - xid or rid not found
+ {
+ std::ostringstream oss;
+ oss << std::hex << "_tmap.set_aio_compl: txn_enq xid=\"" << xid << "\" rid=0x" << h._rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "jcntl", "rcvr_get_next_record");
+ }
+ std::free(xidp);
+ }
+ else
+ {
+ if (_emap.insert_pfid(h._rid, start_fid) < enq_map::EMAP_OK) // fail
+ {
+ // The only error code emap::insert_pfid() returns is enq_map::EMAP_DUP_RID.
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << h._rid << " _pfid=0x" << start_fid;
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "jcntl", "rcvr_get_next_record");
+ }
+ }
+ }
+ }
+ break;
+ case RHM_JDAT_DEQ_MAGIC:
+ {
+ deq_rec dr;
+ u_int16_t start_fid = fid; // fid may increment in decode() if record folds over file boundary
+ if (!decode(dr, fid, ifsp, cum_size_read, h, lowi, rd, file_pos))
+ return false;
+ if (dr.xid_size())
+ {
+ // If the enqueue is part of a pending txn, it will not yet be in emap
+ _emap.lock(dr.deq_rid()); // ignore not found error
+ dr.get_xid(&xidp);
+ assert(xidp != 0);
+ std::string xid((char*)xidp, dr.xid_size());
+ _tmap.insert_txn_data(xid, txn_data(dr.rid(), dr.deq_rid(), start_fid, false,
+ dr.is_txn_coml_commit()));
+ if (_tmap.set_aio_compl(xid, dr.rid()) < txn_map::TMAP_OK) // fail - xid or rid not found
+ {
+ std::ostringstream oss;
+ oss << std::hex << "_tmap.set_aio_compl: txn_deq xid=\"" << xid << "\" rid=0x" << dr.rid();
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "jcntl", "rcvr_get_next_record");
+ }
+ std::free(xidp);
+ }
+ else
+ {
+ int16_t enq_fid = _emap.get_remove_pfid(dr.deq_rid(), true);
+ if (enq_fid >= enq_map::EMAP_OK) // ignore not found error
+ rd._enq_cnt_list[enq_fid]--;
+ }
+ }
+ break;
+ case RHM_JDAT_TXA_MAGIC:
+ {
+ txn_rec ar;
+ if (!decode(ar, fid, ifsp, cum_size_read, h, lowi, rd, file_pos))
+ return false;
+ // Delete this txn from tmap, unlock any locked records in emap
+ ar.get_xid(&xidp);
+ assert(xidp != 0);
+ std::string xid((char*)xidp, ar.xid_size());
+ txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
+ for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
+ {
+ if (itr->_enq_flag)
+ rd._enq_cnt_list[itr->_pfid]--;
+ else
+ _emap.unlock(itr->_drid); // ignore not found error
+ }
+ std::free(xidp);
+ }
+ break;
+ case RHM_JDAT_TXC_MAGIC:
+ {
+ txn_rec cr;
+ if (!decode(cr, fid, ifsp, cum_size_read, h, lowi, rd, file_pos))
+ return false;
+ // Delete this txn from tmap, process records into emap
+ cr.get_xid(&xidp);
+ assert(xidp != 0);
+ std::string xid((char*)xidp, cr.xid_size());
+ txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
+ for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
+ {
+ if (itr->_enq_flag) // txn enqueue
+ {
+ if (_emap.insert_pfid(itr->_rid, itr->_pfid) < enq_map::EMAP_OK) // fail
+ {
+ // The only error code emap::insert_pfid() returns is enq_map::EMAP_DUP_RID.
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << itr->_rid << " _pfid=0x" << itr->_pfid;
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "jcntl", "rcvr_get_next_record");
+ }
+ }
+ else // txn dequeue
+ {
+ int16_t enq_fid = _emap.get_remove_pfid(itr->_drid, true);
+ if (enq_fid >= enq_map::EMAP_OK)
+ rd._enq_cnt_list[enq_fid]--;
+ }
+ }
+ std::free(xidp);
+ }
+ break;
+ case RHM_JDAT_EMPTY_MAGIC:
+ {
+ u_int32_t rec_dblks = jrec::size_dblks(sizeof(rec_hdr));
+ ifsp->ignore(rec_dblks * JRNL_DBLK_SIZE - sizeof(rec_hdr));
+ assert(!ifsp->fail() && !ifsp->bad());
+ if (!jfile_cycle(fid, ifsp, lowi, rd, false))
+ return false;
+ }
+ break;
+ case 0:
+ check_journal_alignment(fid, file_pos, rd);
+ return false;
+ default:
+ // Stop as this is the overwrite boundary.
+ check_journal_alignment(fid, file_pos, rd);
+ return false;
+ }
+ return true;
+}
+
+bool
+jcntl::decode(jrec& rec, u_int16_t& fid, std::ifstream* ifsp, std::size_t& cum_size_read,
+ rec_hdr& h, bool& lowi, rcvdat& rd, std::streampos& file_offs)
+{
+ u_int16_t start_fid = fid;
+ std::streampos start_file_offs = file_offs;
+ if (!check_owi(fid, h, lowi, rd, file_offs))
+ return false;
+ bool done = false;
+ while (!done)
+ {
+ try { done = rec.rcv_decode(h, ifsp, cum_size_read); }
+ catch (const jexception& e)
+ {
+// TODO - review this logic and tidy up how rd._lfid is assigned. See new jinf.get_end_file() fn.
+// Original
+// if (e.err_code() != jerrno::JERR_JREC_BADRECTAIL ||
+// fid != (rd._ffid ? rd._ffid - 1 : _num_jfiles - 1)) throw;
+// Tried this, but did not work
+// if (e.err_code() != jerrno::JERR_JREC_BADRECTAIL || h._magic != 0) throw;
+ check_journal_alignment(start_fid, start_file_offs, rd);
+// rd._lfid = start_fid;
+ return false;
+ }
+ if (!done && !jfile_cycle(fid, ifsp, lowi, rd, false))
+ {
+ check_journal_alignment(start_fid, start_file_offs, rd);
+ return false;
+ }
+ }
+ return true;
+}
+
+bool
+jcntl::jfile_cycle(u_int16_t& fid, std::ifstream* ifsp, bool& lowi, rcvdat& rd, const bool jump_fro)
+{
+ if (ifsp->is_open())
+ {
+ if (ifsp->eof() || !ifsp->good())
+ {
+ ifsp->clear();
+ rd._eo = ifsp->tellg(); // remember file offset before closing
+ assert(rd._eo != std::numeric_limits<std::size_t>::max()); // Check for error code -1
+ ifsp->close();
+ if (++fid >= rd._njf)
+ {
+ fid = 0;
+ lowi = !lowi; // Flip local owi
+ }
+ if (fid == rd._ffid) // used up all journal files
+ return false;
+ }
+ }
+ if (!ifsp->is_open())
+ {
+ std::ostringstream oss;
+ oss << _jdir.dirname() << "/" << _base_filename << ".";
+ oss << std::hex << std::setfill('0') << std::setw(4) << fid << "." << JRNL_DATA_EXTENSION;
+ ifsp->clear(); // clear eof flag, req'd for older versions of c++
+ ifsp->open(oss.str().c_str(), std::ios_base::in | std::ios_base::binary);
+ if (!ifsp->good())
+ throw jexception(jerrno::JERR__FILEIO, oss.str(), "jcntl", "jfile_cycle");
+
+ // Read file header
+ file_hdr fhdr;
+ ifsp->read((char*)&fhdr, sizeof(fhdr));
+ assert(ifsp->good());
+ if (fhdr._magic == RHM_JDAT_FILE_MAGIC)
+ {
+ assert(fhdr._lfid == fid);
+ if (!rd._fro)
+ rd._fro = fhdr._fro;
+ std::streamoff foffs = jump_fro ? fhdr._fro : JRNL_DBLK_SIZE * JRNL_SBLK_SIZE;
+ ifsp->seekg(foffs);
+ }
+ else
+ {
+ ifsp->close();
+ return false;
+ }
+ }
+ return true;
+}
+
+bool
+jcntl::check_owi(const u_int16_t fid, rec_hdr& h, bool& lowi, rcvdat& rd, std::streampos& file_pos)
+{
+ if (rd._ffid ? h.get_owi() == lowi : h.get_owi() != lowi) // Overwrite indicator changed
+ {
+ u_int16_t expected_fid = rd._ffid ? rd._ffid - 1 : rd._njf - 1;
+ if (fid == expected_fid)
+ {
+ check_journal_alignment(fid, file_pos, rd);
+ return false;
+ }
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0') << "Magic=0x" << std::setw(8) << h._magic;
+ oss << " fid=0x" << std::setw(4) << fid << " rid=0x" << std::setw(8) << h._rid;
+ oss << " foffs=0x" << std::setw(8) << file_pos;
+ oss << " expected_fid=0x" << std::setw(4) << expected_fid;
+ throw jexception(jerrno::JERR_JCNTL_OWIMISMATCH, oss.str(), "jcntl",
+ "check_owi");
+ }
+ if (rd._h_rid == 0)
+ rd._h_rid = h._rid;
+ else if (h._rid - rd._h_rid < 0x8000000000000000ULL) // RFC 1982 comparison for unsigned 64-bit
+ rd._h_rid = h._rid;
+ return true;
+}
+
+
+void
+jcntl::check_journal_alignment(const u_int16_t fid, std::streampos& file_pos, rcvdat& rd)
+{
+ unsigned sblk_offs = file_pos % (JRNL_DBLK_SIZE * JRNL_SBLK_SIZE);
+ if (sblk_offs)
+ {
+ {
+ std::ostringstream oss;
+ oss << std::hex << "Bad record alignment found at fid=0x" << fid;
+ oss << " offs=0x" << file_pos << " (likely journal overwrite boundary); " << std::dec;
+ oss << (JRNL_SBLK_SIZE - (sblk_offs/JRNL_DBLK_SIZE)) << " filler record(s) required.";
+ this->log(LOG_WARN, oss.str());
+ }
+ const u_int32_t xmagic = RHM_JDAT_EMPTY_MAGIC;
+ std::ostringstream oss;
+ oss << _jdir.dirname() << "/" << _base_filename << ".";
+ oss << std::hex << std::setfill('0') << std::setw(4) << fid << "." << JRNL_DATA_EXTENSION;
+ std::ofstream ofsp(oss.str().c_str(),
+ std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+ if (!ofsp.good())
+ throw jexception(jerrno::JERR__FILEIO, oss.str(), "jcntl", "check_journal_alignment");
+ ofsp.seekp(file_pos);
+ void* buff = std::malloc(JRNL_DBLK_SIZE);
+ assert(buff != 0);
+ std::memcpy(buff, (const void*)&xmagic, sizeof(xmagic));
+ // Normally, RHM_CLEAN must be set before these fills are done, but this is a recover
+ // situation (i.e. performance is not an issue), and it makes the location of the write
+ // clear should inspection of the file be required.
+ std::memset((char*)buff + sizeof(xmagic), RHM_CLEAN_CHAR, JRNL_DBLK_SIZE - sizeof(xmagic));
+
+ while (file_pos % (JRNL_DBLK_SIZE * JRNL_SBLK_SIZE))
+ {
+ ofsp.write((const char*)buff, JRNL_DBLK_SIZE);
+ assert(!ofsp.fail());
+ std::ostringstream oss;
+ oss << std::hex << "Recover phase write: Wrote filler record: fid=0x" << fid << " offs=0x" << file_pos;
+ this->log(LOG_NOTICE, oss.str());
+ file_pos = ofsp.tellp();
+ }
+ ofsp.close();
+ std::free(buff);
+ rd._lfid = fid;
+ if (!rd._frot)
+ rd._ffid = (fid + 1) % rd._njf;
+ this->log(LOG_INFO, "Bad record alignment fixed.");
+ }
+ rd._eo = file_pos;
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/jcntl.h b/cpp/src/qpid/legacystore/jrnl/jcntl.h
new file mode 100644
index 0000000000..294e9ced05
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jcntl.h
@@ -0,0 +1,722 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jcntl.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Messaging journal top-level control and interface class
+ * mrg::journal::jcntl. See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_JCNTL_H
+#define QPID_LEGACYSTORE_JRNL_JCNTL_H
+
+namespace mrg
+{
+namespace journal
+{
+ class jcntl;
+}
+}
+
+#include <cstddef>
+#include <deque>
+#include "qpid/legacystore/jrnl/jdir.h"
+#include "qpid/legacystore/jrnl/fcntl.h"
+#include "qpid/legacystore/jrnl/lpmgr.h"
+#include "qpid/legacystore/jrnl/rcvdat.h"
+#include "qpid/legacystore/jrnl/slock.h"
+#include "qpid/legacystore/jrnl/smutex.h"
+#include "qpid/legacystore/jrnl/rmgr.h"
+#include "qpid/legacystore/jrnl/wmgr.h"
+#include "qpid/legacystore/jrnl/wrfc.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \brief Access and control interface for the journal. This is the top-level class for the
+ * journal.
+ *
+ * This is the top-level journal class; one instance of this class controls one instance of the
+ * journal and all its files and associated control structures. Besides this class, the only
+ * other class that needs to be used at a higher level is the data_tok class, one instance of
+ * which is used per data block written to the journal, and is used to track its status through
+ * the AIO enqueue, read and dequeue process.
+ */
+ class jcntl
+ {
+ protected:
+ /**
+ * \brief Journal ID
+ *
+ * This string uniquely identifies this journal instance. It will most likely be associated
+ * with the identity of the message queue with which it is associated.
+ */
+ // TODO: This is not included in any files at present, add to file_hdr?
+ std::string _jid;
+
+ /**
+ * \brief Journal directory
+ *
+ * This string stores the path to the journal directory. It may be absolute or relative, and
+ * should not end in a file separator character. (e.g. "/fastdisk/jdata" is correct,
+ * "/fastdisk/jdata/" is not.)
+ */
+ jdir _jdir;
+
+ /**
+ * \brief Base filename
+ *
+ * This string contains the base filename used for the journal files. The filenames will
+ * start with this base, and have various sections added to it to derive the final file names
+ * that will be written to disk. No file separator characters should be included here, but
+ * all other legal filename characters are valid.
+ */
+ std::string _base_filename;
+
+ /**
+ * \brief Initialized flag
+ *
+ * This flag starts out set to false, is set to true once this object has been initialized,
+ * either by calling initialize() or recover().
+ */
+ bool _init_flag;
+
+ /**
+ * \brief Stopped flag
+ *
+ * This flag starts out false, and is set to true when stop() is called. At this point, the
+ * journal will no longer accept messages until either initialize() or recover() is called.
+ * There is no way other than through initialization to reset this flag.
+ */
+ // TODO: It would be helpful to distinguish between states stopping and stopped. If stop(true) is called,
+ // then we are stopping, but must wait for all outstanding aios to return before being finally stopped. During
+ // this period, however, no new enqueue/dequeue/read requests may be accepted.
+ bool _stop_flag;
+
+ /**
+ * \brief Read-only state flag used during recover.
+ *
+ * When true, this flag prevents journal write operations (enqueue and dequeue), but
+ * allows read to occur. It is used during recovery, and is reset when recovered() is
+ * called.
+ */
+ bool _readonly_flag;
+
+ /**
+ * \brief If set, calls stop() if the jouranl write pointer overruns dequeue low water
+ * marker. If not set, then attempts to write will throw exceptions until the journal
+ * file low water marker moves to the next journal file.
+ */
+ bool _autostop; ///< Autostop flag - stops journal when overrun occurs
+
+ // Journal control structures
+ u_int32_t _jfsize_sblks; ///< Journal file size in sblks
+ lpmgr _lpmgr; ///< LFID-PFID manager tracks inserted journal files
+ enq_map _emap; ///< Enqueue map for low water mark management
+ txn_map _tmap; ///< Transaction map open transactions
+ rrfc _rrfc; ///< Read journal rotating file controller
+ wrfc _wrfc; ///< Write journal rotating file controller
+ rmgr _rmgr; ///< Read page manager which manages AIO
+ wmgr _wmgr; ///< Write page manager which manages AIO
+ rcvdat _rcvdat; ///< Recovery data used for recovery
+ smutex _wr_mutex; ///< Mutex for journal writes
+
+ public:
+ static timespec _aio_cmpl_timeout; ///< Timeout for blocking libaio returns
+ static timespec _final_aio_cmpl_timeout; ///< Timeout for blocking libaio returns when stopping or finalizing
+
+ /**
+ * \brief Journal constructor.
+ *
+ * Constructor which sets the physical file location and base name.
+ *
+ * \param jid A unique identifier for this journal instance.
+ * \param jdir The directory which will contain the journal files.
+ * \param base_filename The string which will be used to start all journal filenames.
+ */
+ jcntl(const std::string& jid, const std::string& jdir, const std::string& base_filename);
+
+ /**
+ * \brief Destructor.
+ */
+ virtual ~jcntl();
+
+ inline const std::string& id() const { return _jid; }
+ inline const std::string& jrnl_dir() const { return _jdir.dirname(); }
+
+ /**
+ * \brief Initialize the journal for storing data.
+ *
+ * Initialize the journal by creating new journal data files and initializing internal
+ * control structures. When complete, the journal will be empty, and ready to store data.
+ *
+ * <b>NOTE: Any existing journal will be ignored by this operation.</b> To use recover
+ * the data from an existing journal, use recover().
+ *
+ * <b>NOTE: If <i>NULL</i> is passed to the deque pointers, they will be internally created
+ * and deleted.</b>
+ *
+ * <b>NOTE: If <i>NULL</i> is passed to the callbacks, internal default callbacks will be
+ * used.</b>
+ *
+ * \param num_jfiles The number of journal files to be created.
+ * \param auto_expand If true, allows journal file auto-expansion. In this mode, the journal will automatically
+ * add files to the journal if it runs out of space. No more than ae_max_jfiles may be added. If false, then
+ * no files are added and an exception will be thrown if the journal runs out of file space.
+ * \param ae_max_jfiles Upper limit of journal files for auto-expand mode. When auto_expand is true, this is the
+ * maximum total number of files allowed in the journal (original plus those added by auto-expand mode). If
+ * this number of files exist and the journal runs out of space, an exception will be thrown. This number
+ * must be greater than the num_jfiles parameter value but cannot exceed the maximum number of files for a
+ * single journal; if num_jfiles is already at its maximum value, then auto-expand will be disabled.
+ * \param jfsize_sblks The size of each journal file expressed in softblocks.
+ * \param wcache_num_pages The number of write cache pages to create.
+ * \param wcache_pgsize_sblks The size in sblks of each write cache page.
+ * \param cbp Pointer to object containing callback functions for read and write operations. May be 0 (NULL).
+ *
+ * \exception TODO
+ */
+ void initialize(const u_int16_t num_jfiles, const bool auto_expand, const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks, const u_int16_t wcache_num_pages, const u_int32_t wcache_pgsize_sblks,
+ aio_callback* const cbp);
+
+ /**
+ * /brief Initialize journal by recovering state from previously written journal.
+ *
+ * Initialize journal by recovering state from previously written journal. The journal files
+ * are analyzed, and all records that have not been dequeued and that remain in the journal
+ * will be available for reading. The journal is placed in a read-only state until
+ * recovered() is called; any calls to enqueue or dequeue will fail with an exception
+ * in this state.
+ *
+ * <b>NOTE: If <i>NULL</i> is passed to the deque pointers, they will be internally created
+ * and deleted.</b>
+ *
+ * <b>NOTE: If <i>NULL</i> is passed to the callbacks, internal default callbacks will be
+ * used.</b>
+ *
+ * \param num_jfiles The number of journal files to be created.
+ * \param auto_expand If true, allows journal file auto-expansion. In this mode, the journal will automatically
+ * add files to the journal if it runs out of space. No more than ae_max_jfiles may be added. If false, then
+ * no files are added and an exception will be thrown if the journal runs out of file space.
+ * \param ae_max_jfiles Upper limit of journal files for auto-expand mode. When auto_expand is true, this is the
+ * maximum total number of files allowed in the journal (original plus those added by auto-expand mode). If
+ * this number of files exist and the journal runs out of space, an exception will be thrown. This number
+ * must be greater than the num_jfiles parameter value but cannot exceed the maximum number of files for a
+ * single journal; if num_jfiles is already at its maximum value, then auto-expand will be disabled.
+ * \param jfsize_sblks The size of each journal file expressed in softblocks.
+ * \param wcache_num_pages The number of write cache pages to create.
+ * \param wcache_pgsize_sblks The size in sblks of each write cache page.
+ * \param cbp Pointer to object containing callback functions for read and write operations. May be 0 (NULL).
+ * \param prep_txn_list_ptr
+ * \param highest_rid Returns the highest rid found in the journal during recover
+ *
+ * \exception TODO
+ */
+ void recover(const u_int16_t num_jfiles, const bool auto_expand, const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks, const u_int16_t wcache_num_pages, const u_int32_t wcache_pgsize_sblks,
+ aio_callback* const cbp, const std::vector<std::string>* prep_txn_list_ptr, u_int64_t& highest_rid);
+
+ /**
+ * \brief Notification to the journal that recovery is complete and that normal operation
+ * may resume.
+ *
+ * This call notifies the journal that recovery is complete and that normal operation
+ * may resume. The read pointers are reset so that all records read as a part of recover
+ * may be re-read during normal operation. The read-only flag is then reset, allowing
+ * enqueue and dequeue operations to resume.
+ *
+ * \exception TODO
+ */
+ void recover_complete();
+
+ /**
+ * \brief Stops journal and deletes all journal files.
+ *
+ * Clear the journal directory of all journal files matching the base filename.
+ *
+ * \exception TODO
+ */
+ void delete_jrnl_files();
+
+ /**
+ * \brief Enqueue data.
+ *
+ * Enqueue data or part thereof. If a large data block is being written, then it may be
+ * enqueued in parts by setting this_data_len to the size of the data being written in this
+ * call. The total data size must be known in advance, however, as this is written into the
+ * record header on the first record write. The state of the write (i.e. how much has been
+ * written so far) is maintained in the data token dtokp. Partial writes will return in state
+ * ENQ_PART.
+ *
+ * Note that a return value of anything other than RHM_IORES_SUCCESS implies that this write
+ * operation did not complete successfully or was partially completed. The action taken under
+ * these conditions depends on the value of the return. For example, RHM_IORES_AIO_WAIT
+ * implies that all pages in the write page cache are waiting for AIO operations to return,
+ * and that the call should be remade after waiting a bit.
+ *
+ * Example: If a write of 99 kB is divided into three equal parts, then the following states
+ * and returns would characterize a successful operation:
+ * <pre>
+ * dtok. dtok. dtok.
+ * Pperation Return wstate() dsize() written() Comment
+ * -----------------+--------+--------+-------+---------+------------------------------------
+ * NONE 0 0 Value of dtok before op
+ * edr(99000, 33000) SUCCESS ENQ_PART 99000 33000 Enqueue part 1
+ * edr(99000, 33000) AIO_WAIT ENQ_PART 99000 50000 Enqueue part 2, not completed
+ * edr(99000, 33000) SUCCESS ENQ_PART 99000 66000 Enqueue part 2 again
+ * edr(99000, 33000) SUCCESS ENQ 99000 99000 Enqueue part 3
+ * </pre>
+ *
+ * \param data_buff Pointer to data to be enqueued for this enqueue operation.
+ * \param tot_data_len Total data length.
+ * \param this_data_len Amount to be written in this enqueue operation.
+ * \param dtokp Pointer to data token which contains the details of the enqueue operation.
+ * \param transient Flag indicating transient persistence (ie, ignored on recover).
+ *
+ * \exception TODO
+ */
+ iores enqueue_data_record(const void* const data_buff, const std::size_t tot_data_len,
+ const std::size_t this_data_len, data_tok* dtokp, const bool transient = false);
+
+ iores enqueue_extern_data_record(const std::size_t tot_data_len, data_tok* dtokp,
+ const bool transient = false);
+
+ /**
+ * \brief Enqueue data.
+ *
+ * \param data_buff Pointer to data to be enqueued for this enqueue operation.
+ * \param tot_data_len Total data length.
+ * \param this_data_len Amount to be written in this enqueue operation.
+ * \param dtokp Pointer to data token which contains the details of the enqueue operation.
+ * \param xid String containing xid. An empty string (i.e. length=0) will be considered
+ * non-transactional.
+ * \param transient Flag indicating transient persistence (ie, ignored on recover).
+ *
+ * \exception TODO
+ */
+ iores enqueue_txn_data_record(const void* const data_buff, const std::size_t tot_data_len,
+ const std::size_t this_data_len, data_tok* dtokp, const std::string& xid,
+ const bool transient = false);
+ iores enqueue_extern_txn_data_record(const std::size_t tot_data_len, data_tok* dtokp,
+ const std::string& xid, const bool transient = false);
+
+ /* TODO
+ **
+ * \brief Retrieve details of next record to be read without consuming the record.
+ *
+ * Retrieve information about current read record. A pointer to the data is returned, along
+ * with the data size and available data size. Data is considered "available" when the AIO
+ * operations to fill page-cache pages from disk have returned, and is ready for consumption.
+ *
+ * If <i>dsize_avail</i> &lt; <i>dsize</i>, then not all of the data is available or part of
+ * the data is in non-contiguous memory, and a subsequent call will update both the pointer
+ * and <i>dsize_avail</i> if more pages have returned from AIO.
+ *
+ * The <i>dsize_avail</i> parameter will return the amount of data from this record that is
+ * available in the page cache as contiguous memory, even if it spans page cache boundaries.
+ * However, if a record spans the end of the page cache and continues at the beginning, even
+ * if both parts are ready for consumption, then this must be divided into at least two
+ * get_data_record() operations, as the data is contained in at least two non-contiguous
+ * segments of the page cache.
+ *
+ * Once all the available data for a record is exposed, it can not be read again using
+ * this function. It must be consumed prior to getting the next record. This can be done by
+ * calling discard_data_record() or read_data_record(). However, if parameter
+ * <i>auto_discard</i> is set to <b><i>true</i></b>, then this record will be automatically
+ * consumed when the entire record has become available without having to explicitly call
+ * discard_next_data_record() or read_data_record().
+ *
+ * If the current record is an open transactional record, then it cannot be read until it is
+ * committed. If it is aborted, it can never be read. Under this condition, get_data_record()
+ * will return RHM_IORES_TXPENDING, the data pointer will be set to NULL and all data
+ * lengths will be set to 0.
+ *
+ * Example: Read a record of 30k. Assume a read page cache of 10 pages of size 10k starting
+ * at address base_ptr (page0 = base_ptr, page1 = page_ptr+10k, etc.). The first 15k of
+ * the record falls at the end of the page cache, the remaining 15k folded to the beginning.
+ * The current page (page 8) containing 5k is available, the remaining pages which contain
+ * this record are pending AIO return:
+ * <pre>
+ * call dsize
+ * no. dsize avail data ptr Return Comment
+ * ----+-----+-----+------------+--------+--------------------------------------------------
+ * 1 30k 5k base_ptr+85k SUCCESS Initial call, read first 5k
+ * 2 30k 0k base_ptr+90k AIO_WAIT AIO still pending; no further pages avail
+ * 3 30k 10k base_ptr+90k SUCCESS AIO now returned; now read till end of page cache
+ * 4 30k 15k base_ptr SUCCESS data_ptr now pointing to start of page cache
+ * </pre>
+ *
+ * \param rid Reference that returns the record ID (rid)
+ * \param dsize Reference that returns the total data size of the record data .
+ * \param dsize_avail Reference that returns the amount of the data that is available for
+ * consumption.
+ * \param data Pointer to data pointer which will point to the first byte of the next record
+ * data.
+ * \param auto_discard If <b><i>true</i></b>, automatically discard the record being read if
+ * the entire record is available (i.e. dsize == dsize_avail). Otherwise
+ * discard_next_data_record() must be explicitly called.
+ *
+ * \exception TODO
+ *
+ // *** NOT YET IMPLEMENTED ***
+ iores get_data_record(const u_int64_t& rid, const std::size_t& dsize,
+ const std::size_t& dsize_avail, const void** const data, bool auto_discard = false);
+ */
+
+ /* TODO
+ **
+ * \brief Discard (skip) next record to be read without reading or retrieving it.
+ *
+ * \exception TODO
+ *
+ // *** NOT YET IMPLEMENTED ***
+ iores discard_data_record(data_tok* const dtokp);
+ */
+
+ /**
+ * \brief Reads data from the journal. It is the responsibility of the reader to free
+ * the memory that is allocated through this call - see below for details.
+ *
+ * Reads the next non-dequeued data record from the journal.
+ *
+ * <b>Note</b> that this call allocates memory into which the data and XID are copied. It
+ * is the responsibility of the caller to free this memory. The memory for the data and
+ * XID are allocated in a single call, and the XID precedes the data in the memory space.
+ * Thus, where an XID exists, freeing the XID pointer will free both the XID and data memory.
+ * However, if an XID does not exist for the message, the XID pointer xidpp is set to NULL,
+ * and it is the data pointer datapp that must be freed. Should neither an XID nor data be
+ * present (ie an empty record), then no memory is allocated, and both pointers will be NULL.
+ * In this case, there is no need to free memory.
+ *
+ * TODO: Fix this lousy interface. The caller should NOT be required to clean up these
+ * pointers! Rather use a struct, or better still, let the data token carry the data and
+ * xid pointers and lengths, and have the data token both allocate and delete.
+ *
+ * \param datapp Pointer to pointer that will be set to point to memory allocated and
+ * containing the data. Will be set to NULL if the call fails or there is no data
+ * in the record.
+ * \param dsize Ref that will be set to the size of the data. Will be set to 0 if the call
+ * fails or if there is no data in the record.
+ * \param xidpp Pointer to pointer that will be set to point to memory allocated and
+ * containing the XID. Will be set to NULL if the call fails or there is no XID attached
+ * to this record.
+ * \param xidsize Ref that will be set to the size of the XID.
+ * \param transient Ref that will be set true if record is transient.
+ * \param external Ref that will be set true if record is external. In this case, the data
+ * pointer datapp will be set to NULL, but dsize will contain the size of the data.
+ * NOTE: If there is an xid, then xidpp must be freed.
+ * \param dtokp Pointer to data_tok instance for this data, used to track state of data
+ * through journal.
+ * \param ignore_pending_txns When false (default), if the next record to be read is locked
+ * by a pending transaction, the read fails with RHM_IORES_TXPENDING. However, if set
+ * to true, then locks are ignored. This is required for reading of the Transaction
+ * Prepared List (TPL) which may have its entries locked, but may be read from
+ * time-to-time, and needs all its records (locked and unlocked) to be available.
+ *
+ * \exception TODO
+ */
+ iores read_data_record(void** const datapp, std::size_t& dsize, void** const xidpp,
+ std::size_t& xidsize, bool& transient, bool& external, data_tok* const dtokp,
+ bool ignore_pending_txns = false);
+
+ /**
+ * \brief Dequeues (marks as no longer needed) data record in journal.
+ *
+ * Dequeues (marks as no longer needed) data record in journal. Note that it is possible
+ * to use the same data token instance used to enqueue this data; it contains the record ID
+ * needed to correctly mark this data as dequeued in the journal. Otherwise the RID of the
+ * record to be dequeued and the write state of ENQ must be manually set in a new or reset
+ * instance of data_tok.
+ *
+ * \param dtokp Pointer to data_tok instance for this data, used to track state of data
+ * through journal.
+ * \param txn_coml_commit Only used for preparedXID journal. When used for dequeueing
+ * prepared XID list items, sets whether the complete() was called in commit or abort
+ * mode.
+ *
+ * \exception TODO
+ */
+ iores dequeue_data_record(data_tok* const dtokp, const bool txn_coml_commit = false);
+
+ /**
+ * \brief Dequeues (marks as no longer needed) data record in journal.
+ *
+ * Dequeues (marks as no longer needed) data record in journal as part of a transaction.
+ * Note that it is possible to use the same data token instance used to enqueue this data;
+ * it contains the RID needed to correctly mark this data as dequeued in the journal.
+ * Otherwise the RID of the record to be dequeued and the write state of ENQ must be
+ * manually set in a new or reset instance of data_tok.
+ *
+ * \param dtokp Pointer to data_tok instance for this data, used to track state of data
+ * through journal.
+ * \param xid String containing xid. An empty string (i.e. length=0) will be considered
+ * non-transactional.
+ * \param txn_coml_commit Only used for preparedXID journal. When used for dequeueing
+ * prepared XID list items, sets whether the complete() was called in commit or abort
+ * mode.
+ *
+ * \exception TODO
+ */
+ iores dequeue_txn_data_record(data_tok* const dtokp, const std::string& xid, const bool txn_coml_commit = false);
+
+ /**
+ * \brief Abort the transaction for all records enqueued or dequeued with the matching xid.
+ *
+ * Abort the transaction for all records enqueued with the matching xid. All enqueued records
+ * are effectively deleted from the journal, and can not be read. All dequeued records remain
+ * as though they had never been dequeued.
+ *
+ * \param dtokp Pointer to data_tok instance for this data, used to track state of data
+ * through journal.
+ * \param xid String containing xid.
+ *
+ * \exception TODO
+ */
+ iores txn_abort(data_tok* const dtokp, const std::string& xid);
+
+ /**
+ * \brief Commit the transaction for all records enqueued or dequeued with the matching xid.
+ *
+ * Commit the transaction for all records enqueued with the matching xid. All enqueued
+ * records are effectively released for reading and dequeueing. All dequeued records are
+ * removed and can no longer be accessed.
+ *
+ * \param dtokp Pointer to data_tok instance for this data, used to track state of data
+ * through journal.
+ * \param xid String containing xid.
+ *
+ * \exception TODO
+ */
+ iores txn_commit(data_tok* const dtokp, const std::string& xid);
+
+ /**
+ * \brief Check whether all the enqueue records for the given xid have reached disk.
+ *
+ * \param xid String containing xid.
+ *
+ * \exception TODO
+ */
+ bool is_txn_synced(const std::string& xid);
+
+ /**
+ * \brief Forces a check for returned AIO write events.
+ *
+ * Forces a check for returned AIO write events. This is normally performed by enqueue() and
+ * dequeue() operations, but if these operations cease, then this call needs to be made to
+ * force the processing of any outstanding AIO operations.
+ */
+ int32_t get_wr_events(timespec* const timeout);
+
+ /**
+ * \brief Forces a check for returned AIO read events.
+ *
+ * Forces a check for returned AIO read events. This is normally performed by read_data()
+ * operations, but if these operations cease, then this call needs to be made to force the
+ * processing of any outstanding AIO operations.
+ */
+ int32_t get_rd_events(timespec* const timeout);
+
+ /**
+ * \brief Stop the journal from accepting any further requests to read or write data.
+ *
+ * This operation is used to stop the journal. This is the normal mechanism for bringing the
+ * journal to an orderly stop. Any outstanding AIO operations or partially written pages in
+ * the write page cache will by flushed and will complete.
+ *
+ * <b>Note:</b> The journal cannot be restarted without either initializing it or restoring
+ * it.
+ *
+ * \param block_till_aio_cmpl If true, will block the thread while waiting for all
+ * outstanding AIO operations to complete.
+ */
+ void stop(const bool block_till_aio_cmpl = false);
+
+ /**
+ * \brief Force a flush of the write page cache, creating a single AIO write operation.
+ */
+ iores flush(const bool block_till_aio_cmpl = false);
+
+ inline u_int32_t get_enq_cnt() const { return _emap.size(); }
+
+ inline u_int32_t get_wr_aio_evt_rem() const { slock l(_wr_mutex); return _wmgr.get_aio_evt_rem(); }
+
+ inline u_int32_t get_rd_aio_evt_rem() const { return _rmgr.get_aio_evt_rem(); }
+
+ inline u_int32_t get_wr_outstanding_aio_dblks() const
+ { return _wrfc.aio_outstanding_dblks(); }
+
+ inline u_int32_t get_wr_outstanding_aio_dblks(u_int16_t lfid) const
+ { return _lpmgr.get_fcntlp(lfid)->wr_aio_outstanding_dblks(); }
+
+ inline u_int32_t get_rd_outstanding_aio_dblks() const
+ { return _rrfc.aio_outstanding_dblks(); }
+
+ inline u_int32_t get_rd_outstanding_aio_dblks(u_int16_t lfid) const
+ { return _lpmgr.get_fcntlp(lfid)->rd_aio_outstanding_dblks(); }
+
+ inline u_int16_t get_rd_fid() const { return _rrfc.index(); }
+ inline u_int16_t get_wr_fid() const { return _wrfc.index(); }
+ u_int16_t get_earliest_fid();
+
+ /**
+ * \brief Check if a particular rid is enqueued. Note that this function will return
+ * false if the rid is transactionally enqueued and is not committed, or if it is
+ * locked (i.e. transactionally dequeued, but the dequeue has not been committed).
+ */
+ inline bool is_enqueued(const u_int64_t rid, bool ignore_lock = false)
+ { return _emap.is_enqueued(rid, ignore_lock); }
+ inline bool is_locked(const u_int64_t rid)
+ { if (_emap.is_enqueued(rid, true) < enq_map::EMAP_OK) return false; return _emap.is_locked(rid) == enq_map::EMAP_TRUE; }
+ inline void enq_rid_list(std::vector<u_int64_t>& rids) { _emap.rid_list(rids); }
+ inline void enq_xid_list(std::vector<std::string>& xids) { _tmap.xid_list(xids); }
+ inline u_int32_t get_open_txn_cnt() const { return _tmap.size(); }
+ // TODO Make this a const, but txn_map must support const first.
+ inline txn_map& get_txn_map() { return _tmap; }
+
+ /**
+ * \brief Check if the journal is stopped.
+ *
+ * \return <b><i>true</i></b> if the jouranl is stopped;
+ * <b><i>false</i></b> otherwise.
+ */
+ inline bool is_stopped() { return _stop_flag; }
+
+ /**
+ * \brief Check if the journal is ready to read and write data.
+ *
+ * Checks if the journal is ready to read and write data. This function will return
+ * <b><i>true</i></b> if the journal has been either initialized or restored, and the stop()
+ * function has not been called since the initialization.
+ *
+ * Note that the journal may also be stopped if an internal error occurs (such as running out
+ * of data journal file space).
+ *
+ * \return <b><i>true</i></b> if the journal is ready to read and write data;
+ * <b><i>false</i></b> otherwise.
+ */
+ inline bool is_ready() const { return _init_flag && !_stop_flag; }
+
+ inline bool is_read_only() const { return _readonly_flag; }
+
+ /**
+ * \brief Get the journal directory.
+ *
+ * This returns the journal directory as set during initialization. This is the directory
+ * into which the journal files will be written.
+ */
+ inline const std::string& dirname() const { return _jdir.dirname(); }
+
+ /**
+ * \brief Get the journal base filename.
+ *
+ * Get the journal base filename as set during initialization. This is the prefix used in all
+ * journal files of this instance. Note that if more than one instance of the journal shares
+ * the same directory, their base filenames <b>MUST</b> be different or else the instances
+ * will overwrite one another.
+ */
+ inline const std::string& base_filename() const { return _base_filename; }
+
+ inline u_int16_t num_jfiles() const { return _lpmgr.num_jfiles(); }
+
+ inline fcntl* get_fcntlp(const u_int16_t lfid) const { return _lpmgr.get_fcntlp(lfid); }
+
+ inline u_int32_t jfsize_sblks() const { return _jfsize_sblks; }
+
+ // Logging
+ virtual void log(log_level level, const std::string& log_stmt) const;
+ virtual void log(log_level level, const char* const log_stmt) const;
+
+ // FIXME these are _rmgr to _wmgr interactions, remove when _rmgr contains ref to _wmgr:
+ void chk_wr_frot();
+ inline u_int32_t unflushed_dblks() { return _wmgr.unflushed_dblks(); }
+ void fhdr_wr_sync(const u_int16_t lid);
+ inline u_int32_t wr_subm_cnt_dblks(const u_int16_t lfid) const { return _lpmgr.get_fcntlp(lfid)->wr_subm_cnt_dblks(); }
+
+ // Management instrumentation callbacks
+ inline virtual void instr_incr_outstanding_aio_cnt() {}
+ inline virtual void instr_decr_outstanding_aio_cnt() {}
+
+ /**
+ * /brief Static function for creating new fcntl objects for use with obj_arr.
+ */
+ static fcntl* new_fcntl(jcntl* const jcp, const u_int16_t lid, const u_int16_t fid, const rcvdat* const rdp);
+
+ protected:
+ static bool _init;
+ static bool init_statics();
+
+ /**
+ * \brief Check status of journal before allowing write operations.
+ */
+ void check_wstatus(const char* fn_name) const;
+
+ /**
+ * \brief Check status of journal before allowing read operations.
+ */
+ void check_rstatus(const char* fn_name) const;
+
+ /**
+ * \brief Write info file &lt;basefilename&gt;.jinf to disk
+ */
+ void write_infofile() const;
+
+ /**
+ * \brief Call that blocks while waiting for all outstanding AIOs to complete
+ */
+ void aio_cmpl_wait();
+
+ /**
+ * \brief Call that blocks until at least one message returns; used to wait for
+ * AIO wait conditions to clear.
+ */
+ bool handle_aio_wait(const iores res, iores& resout, const data_tok* dtp);
+
+ /**
+ * \brief Analyze journal for recovery.
+ */
+ void rcvr_janalyze(rcvdat& rd, const std::vector<std::string>* prep_txn_list_ptr);
+
+ bool rcvr_get_next_record(u_int16_t& fid, std::ifstream* ifsp, bool& lowi, rcvdat& rd);
+
+ bool decode(jrec& rec, u_int16_t& fid, std::ifstream* ifsp, std::size_t& cum_size_read,
+ rec_hdr& h, bool& lowi, rcvdat& rd, std::streampos& rec_offset);
+
+ bool jfile_cycle(u_int16_t& fid, std::ifstream* ifsp, bool& lowi, rcvdat& rd,
+ const bool jump_fro);
+
+ bool check_owi(const u_int16_t fid, rec_hdr& h, bool& lowi, rcvdat& rd,
+ std::streampos& read_pos);
+
+ void check_journal_alignment(const u_int16_t fid, std::streampos& rec_offset, rcvdat& rd);
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_JCNTL_H
diff --git a/cpp/src/qpid/legacystore/jrnl/jdir.cpp b/cpp/src/qpid/legacystore/jrnl/jdir.cpp
new file mode 100644
index 0000000000..a874c6c945
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jdir.cpp
@@ -0,0 +1,463 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jdir.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::jdir (journal data
+ * directory), used for controlling and manipulating journal data
+ * direcories and files. See comments in file jdir.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/jdir.h"
+
+#include <cstdlib>
+#include <cstring>
+#include <cerrno>
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jcfg.h"
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <sstream>
+#include <sys/stat.h>
+#include <unistd.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+jdir::jdir(const std::string& dirname, const std::string& _base_filename):
+ _dirname(dirname),
+ _base_filename(_base_filename)
+{}
+
+jdir::~jdir()
+{}
+
+// === create_dir ===
+
+void
+jdir::create_dir()
+{
+ create_dir(_dirname);
+}
+
+
+void
+jdir::create_dir(const char* dirname)
+{
+ create_dir(std::string(dirname));
+}
+
+
+void
+jdir::create_dir(const std::string& dirname)
+{
+ std::size_t fdp = dirname.find_last_of('/');
+ if (fdp != std::string::npos)
+ {
+ std::string parent_dir = dirname.substr(0, fdp);
+ if (!exists(parent_dir))
+ create_dir(parent_dir);
+ }
+ if (::mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
+ {
+ if (errno != EEXIST) // Dir exists, ignore
+ {
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_MKDIR, oss.str(), "jdir", "create_dir");
+ }
+ }
+}
+
+
+// === clear_dir ===
+
+void
+jdir::clear_dir(const bool create_flag)
+{
+ clear_dir(_dirname, _base_filename, create_flag);
+}
+
+void
+jdir::clear_dir(const char* dirname, const char* base_filename, const bool create_flag)
+{
+ clear_dir(std::string(dirname), std::string(base_filename), create_flag);
+}
+
+
+void
+jdir::clear_dir(const std::string& dirname, const std::string&
+#ifndef RHM_JOWRITE
+ base_filename
+#endif
+ , const bool create_flag)
+{
+ DIR* dir = ::opendir(dirname.c_str());
+ if (!dir)
+ {
+ if (errno == 2 && create_flag) // ENOENT (No such file or dir)
+ {
+ create_dir(dirname);
+ return;
+ }
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_OPENDIR, oss.str(), "jdir", "clear_dir");
+ }
+#ifndef RHM_JOWRITE
+ struct dirent* entry;
+ bool found = false;
+ std::string bak_dir;
+ while ((entry = ::readdir(dir)) != 0)
+ {
+ // Ignore . and ..
+ if (std::strcmp(entry->d_name, ".") != 0 && std::strcmp(entry->d_name, "..") != 0)
+ {
+ if (std::strlen(entry->d_name) > base_filename.size())
+ {
+ if (std::strncmp(entry->d_name, base_filename.c_str(), base_filename.size()) == 0)
+ {
+ if (!found)
+ {
+ bak_dir = create_bak_dir(dirname, base_filename);
+ found = true;
+ }
+ std::ostringstream oldname;
+ oldname << dirname << "/" << entry->d_name;
+ std::ostringstream newname;
+ newname << bak_dir << "/" << entry->d_name;
+ if (::rename(oldname.str().c_str(), newname.str().c_str()))
+ {
+ ::closedir(dir);
+ std::ostringstream oss;
+ oss << "file=\"" << oldname.str() << "\" dest=\"" <<
+ newname.str() << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_FMOVE, oss.str(), "jdir", "clear_dir");
+ }
+ }
+ }
+ }
+ }
+// FIXME: Find out why this fails with false alarms/errors from time to time...
+// While commented out, there is no error capture from reading dir entries.
+// check_err(errno, dir, dirname, "clear_dir");
+#endif
+ close_dir(dir, dirname, "clear_dir");
+}
+
+// === push_down ===
+
+std::string
+jdir::push_down(const std::string& dirname, const std::string& target_dir, const std::string& bak_dir_base)
+{
+ std::string bak_dir_name = create_bak_dir(dirname, bak_dir_base);
+
+ DIR* dir = ::opendir(dirname.c_str());
+ if (!dir)
+ {
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_OPENDIR, oss.str(), "jdir", "push_down");
+ }
+ // Copy contents of targetDirName into bak dir
+ struct dirent* entry;
+ while ((entry = ::readdir(dir)) != 0)
+ {
+ // Search for targetDirName in storeDirName
+ if (std::strcmp(entry->d_name, target_dir.c_str()) == 0)
+ {
+ std::ostringstream oldname;
+ oldname << dirname << "/" << target_dir;
+ std::ostringstream newname;
+ newname << bak_dir_name << "/" << target_dir;
+ if (::rename(oldname.str().c_str(), newname.str().c_str()))
+ {
+ ::closedir(dir);
+ std::ostringstream oss;
+ oss << "file=\"" << oldname.str() << "\" dest=\"" << newname.str() << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_FMOVE, oss.str(), "jdir", "push_down");
+ }
+ break;
+ }
+ }
+ close_dir(dir, dirname, "push_down");
+ return bak_dir_name;
+}
+
+// === verify_dir ===
+
+void
+jdir::verify_dir()
+{
+ verify_dir(_dirname, _base_filename);
+}
+
+void
+jdir::verify_dir(const char* dirname, const char* base_filename)
+{
+ verify_dir(std::string(dirname), std::string(base_filename));
+}
+
+
+void
+jdir::verify_dir(const std::string& dirname, const std::string& base_filename)
+{
+ if (!is_dir(dirname))
+ {
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\"";
+ throw jexception(jerrno::JERR_JDIR_NOTDIR, oss.str(), "jdir", "verify_dir");
+ }
+
+ // Read jinf file, then verify all journal files are present
+ jinf ji(dirname + "/" + base_filename + "." + JRNL_INFO_EXTENSION, true);
+ for (u_int16_t fnum=0; fnum < ji.num_jfiles(); fnum++)
+ {
+ std::ostringstream oss;
+ oss << dirname << "/" << base_filename << ".";
+ oss << std::setw(4) << std::setfill('0') << std::hex << fnum;
+ oss << "." << JRNL_DATA_EXTENSION;
+ if (!exists(oss.str()))
+ throw jexception(jerrno::JERR_JDIR_NOSUCHFILE, oss.str(), "jdir", "verify_dir");
+ }
+}
+
+
+// === delete_dir ===
+
+void
+jdir::delete_dir(bool children_only)
+{
+ delete_dir(_dirname, children_only);
+}
+
+void
+jdir::delete_dir(const char* dirname, bool children_only)
+{
+ delete_dir(std::string(dirname), children_only);
+}
+
+void
+jdir::delete_dir(const std::string& dirname, bool children_only)
+{
+ struct dirent* entry;
+ struct stat s;
+ DIR* dir = ::opendir(dirname.c_str());
+ if (!dir)
+ {
+ if (errno == ENOENT) // dir does not exist.
+ return;
+
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_OPENDIR, oss.str(), "jdir", "delete_dir");
+ }
+ else
+ {
+ while ((entry = ::readdir(dir)) != 0)
+ {
+ // Ignore . and ..
+ if (std::strcmp(entry->d_name, ".") != 0 && std::strcmp(entry->d_name, "..") != 0)
+ {
+ std::string full_name(dirname + "/" + entry->d_name);
+ if (::lstat(full_name.c_str(), &s))
+ {
+ ::closedir(dir);
+ std::ostringstream oss;
+ oss << "stat: file=\"" << full_name << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_STAT, oss.str(), "jdir", "delete_dir");
+ }
+ if (S_ISREG(s.st_mode) || S_ISLNK(s.st_mode)) // This is a file or slink
+ {
+ if(::unlink(full_name.c_str()))
+ {
+ ::closedir(dir);
+ std::ostringstream oss;
+ oss << "unlink: file=\"" << entry->d_name << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_UNLINK, oss.str(), "jdir", "delete_dir");
+ }
+ }
+ else if (S_ISDIR(s.st_mode)) // This is a dir
+ {
+ delete_dir(full_name);
+ }
+ else // all other types, throw up!
+ {
+ ::closedir(dir);
+ std::ostringstream oss;
+ oss << "file=\"" << entry->d_name << "\" is not a dir, file or slink.";
+ oss << " (mode=0x" << std::hex << s.st_mode << std::dec << ")";
+ throw jexception(jerrno::JERR_JDIR_BADFTYPE, oss.str(), "jdir", "delete_dir");
+ }
+ }
+ }
+
+// FIXME: Find out why this fails with false alarms/errors from time to time...
+// While commented out, there is no error capture from reading dir entries.
+// check_err(errno, dir, dirname, "delete_dir");
+ }
+ // Now dir is empty, close and delete it
+ close_dir(dir, dirname, "delete_dir");
+
+ if (!children_only)
+ if (::rmdir(dirname.c_str()))
+ {
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_RMDIR, oss.str(), "jdir", "delete_dir");
+ }
+}
+
+
+std::string
+jdir::create_bak_dir(const std::string& dirname, const std::string& base_filename)
+{
+ DIR* dir = ::opendir(dirname.c_str());
+ long dir_num = 0L;
+ if (!dir)
+ {
+ std::ostringstream oss;
+ oss << "dir=\"" << dirname << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_OPENDIR, oss.str(), "jdir", "create_bak_dir");
+ }
+ struct dirent* entry;
+ while ((entry = ::readdir(dir)) != 0)
+ {
+ // Ignore . and ..
+ if (std::strcmp(entry->d_name, ".") != 0 && std::strcmp(entry->d_name, "..") != 0)
+ {
+ if (std::strlen(entry->d_name) == base_filename.size() + 10) // Format: basename.bak.XXXX
+ {
+ std::ostringstream oss;
+ oss << "_" << base_filename << ".bak.";
+ if (std::strncmp(entry->d_name, oss.str().c_str(), base_filename.size() + 6) == 0)
+ {
+ long this_dir_num = std::strtol(entry->d_name + base_filename.size() + 6, 0, 16);
+ if (this_dir_num > dir_num)
+ dir_num = this_dir_num;
+ }
+ }
+ }
+ }
+// FIXME: Find out why this fails with false alarms/errors from time to time...
+// While commented out, there is no error capture from reading dir entries.
+// check_err(errno, dir, dirname, "create_bak_dir");
+ close_dir(dir, dirname, "create_bak_dir");
+
+ std::ostringstream dn;
+ dn << dirname << "/_" << base_filename << ".bak." << std::hex << std::setw(4) <<
+ std::setfill('0') << ++dir_num;
+ if (::mkdir(dn.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH))
+ {
+ std::ostringstream oss;
+ oss << "dir=\"" << dn.str() << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_MKDIR, oss.str(), "jdir", "create_bak_dir");
+ }
+ return std::string(dn.str());
+}
+
+bool
+jdir::is_dir(const char* name)
+{
+ struct stat s;
+ if (::stat(name, &s))
+ {
+ std::ostringstream oss;
+ oss << "file=\"" << name << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_STAT, oss.str(), "jdir", "is_dir");
+ }
+ return S_ISDIR(s.st_mode);
+}
+
+bool
+jdir::is_dir(const std::string& name)
+{
+ return is_dir(name.c_str());
+}
+
+bool
+jdir::exists(const char* name)
+{
+ struct stat s;
+ if (::stat(name, &s))
+ {
+ if (errno == ENOENT) // No such dir or file
+ return false;
+ // Throw for any other condition
+ std::ostringstream oss;
+ oss << "file=\"" << name << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_STAT, oss.str(), "jdir", "exists");
+ }
+ return true;
+}
+
+bool
+jdir::exists(const std::string& name)
+{
+ return exists(name.c_str());
+}
+
+void
+jdir::check_err(const int err_num, DIR* dir, const std::string& dir_name, const std::string& fn_name)
+{
+ if (err_num)
+ {
+ std::ostringstream oss;
+ oss << "dir=\"" << dir_name << "\"" << FORMAT_SYSERR(err_num);
+ ::closedir(dir); // Try to close, it makes no sense to trap errors here...
+ throw jexception(jerrno::JERR_JDIR_READDIR, oss.str(), "jdir", fn_name);
+ }
+}
+
+void
+jdir::close_dir(DIR* dir, const std::string& dir_name, const std::string& fn_name)
+{
+ if (::closedir(dir))
+ {
+ std::ostringstream oss;
+ oss << "dir=\"" << dir_name << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JDIR_CLOSEDIR, oss.str(), "jdir", fn_name);
+ }
+}
+
+std::ostream&
+operator<<(std::ostream& os, const jdir& jdir)
+{
+ os << jdir._dirname;
+ return os;
+}
+
+std::ostream&
+operator<<(std::ostream& os, const jdir* jdirPtr)
+{
+ os << jdirPtr->_dirname;
+ return os;
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/jdir.h b/cpp/src/qpid/legacystore/jrnl/jdir.h
new file mode 100644
index 0000000000..e129b794d6
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jdir.h
@@ -0,0 +1,379 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jdir.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::jdir (%journal data
+ * directory), used for controlling and manipulating %journal data
+ * directories and files. See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_JDIR_H
+#define QPID_LEGACYSTORE_JRNL_JDIR_H
+
+namespace mrg
+{
+namespace journal
+{
+class jdir;
+}
+}
+
+#include "qpid/legacystore/jrnl/jinf.h"
+#include <dirent.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class jdir
+ * \brief Class to manage the %journal directory
+ */
+ class jdir
+ {
+ private:
+ std::string _dirname;
+ std::string _base_filename;
+
+ public:
+
+ /**
+ * \brief Sole constructor
+ *
+ * \param dirname Name of directory to be managed.
+ * \param base_filename Filename root used in the creation of %journal files
+ * and sub-directories.
+ */
+ jdir(const std::string& dirname, const std::string& base_filename);
+
+ virtual ~jdir();
+
+
+ /**
+ * \brief Create %journal directory as set in the dirname parameter of the constructor.
+ * Recursive creation is supported.
+ *
+ * \exception jerrno::JERR_JDIR_MKDIR The creation of dirname failed.
+ */
+ void create_dir();
+
+ /**
+ * \brief Static function to create a directory. Recursive creation is supported.
+ *
+ * \param dirname C-string containing name of directory.
+ *
+ * \exception jerrno::JERR_JDIR_MKDIR The creation of dirname failed.
+ */
+ static void create_dir(const char* dirname);
+
+ /**
+ * \brief Static function to create a directory. Recursive creation is supported.
+ *
+ * \param dirname String containing name of directory.
+ *
+ * \exception jerrno::JERR_JDIR_MKDIR The creation of dirname failed.
+ */
+ static void create_dir(const std::string& dirname);
+
+
+ /**
+ * \brief Clear the %journal directory of files matching the base filename
+ * by moving them into a subdirectory. This fn uses the dirname and base_filename
+ * that were set on construction.
+ *
+ * \param create_flag If set, create dirname if it is non-existent, otherwise throw
+ * exception.
+ *
+ * \exception jerrno::JERR_JDIR_OPENDIR The %journal directory could not be opened.
+ * \exception jerrno::JERR_JDIR_FMOVE Moving the files from the %journal directory to the created backup
+ * directory failed.
+ * \exception jerrno::JERR_JDIR_CLOSEDIR The directory handle could not be closed.
+ */
+ void clear_dir(const bool create_flag = true);
+
+ /**
+ * \brief Clear the directory dirname of %journal files matching base_filename
+ * by moving them into a subdirectory.
+ *
+ * \param dirname C-string containing name of %journal directory.
+ * \param base_filename C-string containing base filename of %journal files to be matched
+ * for moving into subdirectory.
+ * \param create_flag If set, create dirname if it is non-existent, otherwise throw
+ * exception
+ *
+ * \exception jerrno::JERR_JDIR_OPENDIR The %journal directory could not be opened.
+ * \exception jerrno::JERR_JDIR_FMOVE Moving the files from the %journal directory to the created backup
+ * directory failed.
+ * \exception jerrno::JERR_JDIR_CLOSEDIR The directory handle could not be closed.
+ */
+ static void clear_dir(const char* dirname, const char* base_filename,
+ const bool create_flag = true);
+
+ /**
+ * \brief Clear the directory dirname of %journal files matching base_filename
+ * by moving them into a subdirectory.
+ *
+ * \param dirname String containing name of %journal directory.
+ * \param base_filename String containing base filename of %journal files to be matched
+ * for moving into subdirectory.
+ * \param create_flag If set, create dirname if it is non-existent, otherwise throw
+ * exception
+ *
+ * \exception jerrno::JERR_JDIR_OPENDIR The %journal directory could not be opened.
+ * \exception jerrno::JERR_JDIR_FMOVE Moving the files from the %journal directory to the created backup
+ * directory failed.
+ * \exception jerrno::JERR_JDIR_CLOSEDIR The directory handle could not be closed.
+ */
+ static void clear_dir(const std::string& dirname, const std::string& base_filename,
+ const bool create_flag = true);
+
+
+
+ /**
+ * \brief Move (push down) the directory target_dir located in directory dirname into a backup directory
+ * named _bak_dir_base.XXXX (note prepended underscore), where XXXX is an increasing hex serial number
+ * starting at 0000.
+ *
+ * \param dirname Full path to directory containing directory to be pushed down.
+ * \param target_dir Name of directory in dirname to be pushed down.
+ * \param bak_dir_base Base name for backup directory to be created in dirname, into which target_dir will be moved.
+ * \return Name of backup dir into which target_dir was pushed.
+ */
+ static std::string push_down(const std::string& dirname, const std::string& target_dir, const std::string& bak_dir_base);
+
+
+ /**
+ * \brief Verify that dirname is a valid %journal directory.
+ *
+ * The validation reads the .%jinf file, and using this information verifies that all the expected %journal
+ * (.jdat) files are present.
+ *
+ * \exception jerrno::JERR_JDIR_NOTDIR dirname is not a directory
+ * \exception jerrno::JERR_JDIR_STAT Could not stat dirname
+ * \exception jerrno::JERR__FILEIO Error reading %jinf file
+ * \exception jerrno::JERR_JINF_CVALIDFAIL Error validating %jinf file
+ * \exception jerrno::JERR_JDIR_NOSUCHFILE Expected jdat file is missing
+ */
+ void verify_dir();
+
+ /**
+ * \brief Verify that dirname is a valid %journal directory.
+ *
+ * The validation reads the .%jinf file, and using this information verifies that all the expected %journal
+ * (.jdat) files are present.
+ *
+ * \param dirname C-string containing name of %journal directory.
+ * \param base_filename C-string containing base filename of %journal files to be matched for moving into sub-directory.
+ *
+ * \exception jerrno::JERR_JDIR_NOTDIR dirname is not a directory
+ * \exception jerrno::JERR_JDIR_STAT Could not stat dirname
+ * \exception jerrno::JERR__FILEIO Error reading %jinf file
+ * \exception jerrno::JERR_JINF_CVALIDFAIL Error validating %jinf file
+ * \exception jerrno::JERR_JDIR_NOSUCHFILE Expected jdat file is missing
+ */
+ static void verify_dir(const char* dirname, const char* base_filename);
+
+ /**
+ * \brief Verify that dirname is a valid %journal directory.
+ *
+ * The validation reads the .%jinf file, and using this information verifies that all the expected %journal
+ * (.jdat) files are present.
+ *
+ * \param dirname String containing name of %journal directory.
+ * \param base_filename String containing base filename of %journal files to be matched for moving into sub-directory.
+ *
+ * \exception jerrno::JERR_JDIR_NOTDIR dirname is not a directory
+ * \exception jerrno::JERR_JDIR_STAT Could not stat dirname
+ * \exception jerrno::JERR__FILEIO Error reading %jinf file
+ * \exception jerrno::JERR_JINF_CVALIDFAIL Error validating %jinf file
+ * \exception jerrno::JERR_JDIR_NOSUCHFILE Expected jdat file is missing
+ */
+ static void verify_dir(const std::string& dirname, const std::string& base_filename);
+
+ /**
+ * \brief Delete the %journal directory and all files and sub--directories that it may
+ * contain. This is equivilent of rm -rf.
+ *
+ * FIXME: links are not handled correctly.
+ *
+ * \param children_only If true, delete only children of dirname, but leave dirname itself.
+ *
+ * \exception jerrno::JERR_JDIR_OPENDIR The %journal directory could not be opened.
+ * \exception jerrno::JERR_JDIR_STAT Could not stat dirname.
+ * \exception jerrno::JERR_JDIR_UNLINK A file could not be deleted.
+ * \exception jerrno::JERR_JDIR_BADFTYPE A dir entry is neiter a file nor a dir.
+ * \exception jerrno::JERR_JDIR_CLOSEDIR The directory handle could not be closed.
+ * \exception jerrno::JERR_JDIR_RMDIR A directory could not be deleted.
+ */
+ void delete_dir(bool children_only = false );
+
+ /**
+ * \brief Delete the %journal directory and all files and sub--directories that it may
+ * contain. This is equivilent of rm -rf.
+ *
+ * FIXME: links are not handled correctly.
+ *
+ * \param dirname C-string containing name of directory to be deleted.
+ * \param children_only If true, delete only children of dirname, but leave dirname itself.
+ *
+ * \exception jerrno::JERR_JDIR_OPENDIR The %journal directory could not be opened.
+ * \exception jerrno::JERR_JDIR_STAT Could not stat dirname.
+ * \exception jerrno::JERR_JDIR_UNLINK A file could not be deleted.
+ * \exception jerrno::JERR_JDIR_BADFTYPE A dir entry is neiter a file nor a dir.
+ * \exception jerrno::JERR_JDIR_CLOSEDIR The directory handle could not be closed.
+ * \exception jerrno::JERR_JDIR_RMDIR A directory could not be deleted.
+ */
+ static void delete_dir(const char* dirname, bool children_only = false);
+
+ /**
+ * \brief Delete the %journal directory and all files and sub--directories that it may
+ * contain. This is equivilent of rm -rf.
+ *
+ * FIXME: links are not handled correctly.
+ *
+ * \param dirname String containing name of directory to be deleted.
+ * \param children_only If true, delete only children of dirname, but leave dirname itself.
+ *
+ * \exception jerrno::JERR_JDIR_OPENDIR The %journal directory could not be opened.
+ * \exception jerrno::JERR_JDIR_STAT Could not stat dirname.
+ * \exception jerrno::JERR_JDIR_UNLINK A file could not be deleted.
+ * \exception jerrno::JERR_JDIR_BADFTYPE A dir entry is neiter a file nor a dir.
+ * \exception jerrno::JERR_JDIR_CLOSEDIR The directory handle could not be closed.
+ * \exception jerrno::JERR_JDIR_RMDIR A directory could not be deleted.
+ */
+ static void delete_dir(const std::string& dirname, bool children_only = false);
+
+ /**
+ * \brief Create bakup directory that is next in sequence and move all %journal files
+ * matching base_filename into it.
+ *
+ * In directory dirname, search for existing backup directory using pattern
+ * "_basename.bak.XXXX" where XXXX is a hexadecimal sequence, and create next directory
+ * based on highest number found. Move all %journal files which match the base_fileaname
+ * parameter into this new backup directory.
+ *
+ * \param dirname String containing name of %journal directory.
+ * \param base_filename String containing base filename of %journal files to be matched
+ * for moving into subdirectory.
+ *
+ * \exception jerrno::JERR_JDIR_OPENDIR The %journal directory could not be opened.
+ * \exception jerrno::JERR_JDIR_CLOSEDIR The directory handle could not be closed.
+ * \exception jerrno::JERR_JDIR_MKDIR The backup directory could not be deleted.
+ */
+ static std::string create_bak_dir(const std::string& dirname,
+ const std::string& base_filename);
+
+ /**
+ * \brief Return the directory name as a string.
+ */
+ inline const std::string& dirname() const { return _dirname; }
+
+ /**
+ * \brief Return the %journal base filename name as a string.
+ */
+ inline const std::string& base_filename() const { return _base_filename; }
+
+ /**
+ * \brief Test whether the named file is a directory.
+ *
+ * \param name Name of file to be tested.
+ * \return <b><i>true</i></b> if the named file is a directory; <b><i>false</i></b>
+ * otherwise.
+ * \exception jerrno::JERR_JDIR_STAT Could not stat name.
+ */
+ static bool is_dir(const char* name);
+
+ /**
+ * \brief Test whether the named file is a directory.
+ *
+ * \param name Name of file to be tested.
+ * \return <b><i>true</i></b> if the named file is a directory; <b><i>false</i></b>
+ * otherwise.
+ * \exception jerrno::JERR_JDIR_STAT Could not stat name.
+ */
+ static bool is_dir(const std::string& name);
+
+
+ /**
+ * \brief Test whether the named entity exists on the filesystem.
+ *
+ * If stat() fails with error ENOENT, then this will return <b><i>false</i></b>. If
+ * stat() succeeds, then <b><i>true</i></b> is returned, irrespective of the file type.
+ * If stat() fails with any other error, an exception is thrown.
+ *
+ * \param name Name of entity to be tested.
+ * \return <b><i>true</i></b> if the named entity exists; <b><i>false</i></b>
+ * otherwise.
+ * \exception jerrno::JERR_JDIR_STAT Could not stat name.
+ */
+ static bool exists(const char* name);
+
+ /**
+ * \brief Test whether the named entity exists on the filesystem.
+ *
+ * If stat() fails with error ENOENT, then this will return <b><i>false</i></b>. If
+ * stat() succeeds, then <b><i>true</i></b> is returned, irrespective of the file type.
+ * If stat() fails with any other error, an exception is thrown.
+ *
+ * \param name Name of entity to be tested.
+ * \return <b><i>true</i></b> if the named entity exists; <b><i>false</i></b>
+ * otherwise.
+ * \exception jerrno::JERR_JDIR_STAT Could not stat name.
+ */
+ static bool exists(const std::string& name);
+
+ /**
+ * \brief Stream operator
+ */
+ friend std::ostream& operator<<(std::ostream& os, const jdir& jdir);
+
+ /**
+ * \brief Stream operator
+ */
+ friend std::ostream& operator<<(std::ostream& os, const jdir* jdirPtr);
+
+ private:
+ /**
+ * \brief Check for error, if non-zero close DIR handle and throw JERR_JDIR_READDIR
+ *
+ * \exception jerrno::JERR_JDIR_READDIR Error while reading contents of dir.
+ */
+ static void check_err(const int err_num, DIR* dir, const std::string& dir_name, const std::string& fn_name);
+
+ /**
+ * \brief Close a DIR handle, throw JERR_JDIR_CLOSEDIR if error occurs during close
+ *
+ * \exception jerrno::JERR_JDIR_CLOSEDIR The directory handle could not be closed.
+ */
+ static void close_dir(DIR* dir, const std::string& dir_name, const std::string& fn_name);
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_JDIR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/jerrno.cpp b/cpp/src/qpid/legacystore/jrnl/jerrno.cpp
new file mode 100644
index 0000000000..4962ce63ab
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jerrno.cpp
@@ -0,0 +1,253 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jerrno.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::jerrno (journal error
+ * codes). See comments in file jerrno.h for details.
+ *
+ * See file jerrno.h for class details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/jerrno.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+std::map<u_int32_t, const char*> jerrno::_err_map;
+std::map<u_int32_t, const char*>::iterator jerrno::_err_map_itr;
+bool jerrno::_initialized = jerrno::__init();
+
+// generic errors
+const u_int32_t jerrno::JERR__MALLOC = 0x0100;
+const u_int32_t jerrno::JERR__UNDERFLOW = 0x0101;
+const u_int32_t jerrno::JERR__NINIT = 0x0102;
+const u_int32_t jerrno::JERR__AIO = 0x0103;
+const u_int32_t jerrno::JERR__FILEIO = 0x0104;
+const u_int32_t jerrno::JERR__RTCLOCK = 0x0105;
+const u_int32_t jerrno::JERR__PTHREAD = 0x0106;
+const u_int32_t jerrno::JERR__TIMEOUT = 0x0107;
+const u_int32_t jerrno::JERR__UNEXPRESPONSE = 0x0108;
+const u_int32_t jerrno::JERR__RECNFOUND = 0x0109;
+const u_int32_t jerrno::JERR__NOTIMPL = 0x010a;
+
+// class jcntl
+const u_int32_t jerrno::JERR_JCNTL_STOPPED = 0x0200;
+const u_int32_t jerrno::JERR_JCNTL_READONLY = 0x0201;
+const u_int32_t jerrno::JERR_JCNTL_AIOCMPLWAIT = 0x0202;
+const u_int32_t jerrno::JERR_JCNTL_UNKNOWNMAGIC = 0x0203;
+const u_int32_t jerrno::JERR_JCNTL_NOTRECOVERED = 0x0204;
+const u_int32_t jerrno::JERR_JCNTL_RECOVERJFULL = 0x0205;
+const u_int32_t jerrno::JERR_JCNTL_OWIMISMATCH = 0x0206;
+
+// class jdir
+const u_int32_t jerrno::JERR_JDIR_NOTDIR = 0x0300;
+const u_int32_t jerrno::JERR_JDIR_MKDIR = 0x0301;
+const u_int32_t jerrno::JERR_JDIR_OPENDIR = 0x0302;
+const u_int32_t jerrno::JERR_JDIR_READDIR = 0x0303;
+const u_int32_t jerrno::JERR_JDIR_CLOSEDIR = 0x0304;
+const u_int32_t jerrno::JERR_JDIR_RMDIR = 0x0305;
+const u_int32_t jerrno::JERR_JDIR_NOSUCHFILE = 0x0306;
+const u_int32_t jerrno::JERR_JDIR_FMOVE = 0x0307;
+const u_int32_t jerrno::JERR_JDIR_STAT = 0x0308;
+const u_int32_t jerrno::JERR_JDIR_UNLINK = 0x0309;
+const u_int32_t jerrno::JERR_JDIR_BADFTYPE = 0x030a;
+
+// class fcntl
+const u_int32_t jerrno::JERR_FCNTL_OPENWR = 0x0400;
+const u_int32_t jerrno::JERR_FCNTL_WRITE = 0x0401;
+const u_int32_t jerrno::JERR_FCNTL_CLOSE = 0x0402;
+const u_int32_t jerrno::JERR_FCNTL_FILEOFFSOVFL = 0x0403;
+const u_int32_t jerrno::JERR_FCNTL_CMPLOFFSOVFL = 0x0404;
+const u_int32_t jerrno::JERR_FCNTL_RDOFFSOVFL = 0x0405;
+
+// class lfmgr
+const u_int32_t jerrno::JERR_LFMGR_BADAEFNUMLIM = 0x0500;
+const u_int32_t jerrno::JERR_LFMGR_AEFNUMLIMIT = 0x0501;
+const u_int32_t jerrno::JERR_LFMGR_AEDISABLED = 0x0502;
+
+// class rrfc
+const u_int32_t jerrno::JERR_RRFC_OPENRD = 0x0600;
+
+// class jrec, enq_rec, deq_rec, txn_rec
+const u_int32_t jerrno::JERR_JREC_BADRECHDR = 0x0700;
+const u_int32_t jerrno::JERR_JREC_BADRECTAIL = 0x0701;
+
+// class wmgr
+const u_int32_t jerrno::JERR_WMGR_BADPGSTATE = 0x0801;
+const u_int32_t jerrno::JERR_WMGR_BADDTOKSTATE = 0x0802;
+const u_int32_t jerrno::JERR_WMGR_ENQDISCONT = 0x0803;
+const u_int32_t jerrno::JERR_WMGR_DEQDISCONT = 0x0804;
+const u_int32_t jerrno::JERR_WMGR_DEQRIDNOTENQ = 0x0805;
+
+// class rmgr
+const u_int32_t jerrno::JERR_RMGR_UNKNOWNMAGIC = 0x0900;
+const u_int32_t jerrno::JERR_RMGR_RIDMISMATCH = 0x0901;
+//const u_int32_t jerrno::JERR_RMGR_FIDMISMATCH = 0x0902;
+const u_int32_t jerrno::JERR_RMGR_ENQSTATE = 0x0903;
+const u_int32_t jerrno::JERR_RMGR_BADRECTYPE = 0x0904;
+
+// class data_tok
+const u_int32_t jerrno::JERR_DTOK_ILLEGALSTATE = 0x0a00;
+// const u_int32_t jerrno::JERR_DTOK_RIDNOTSET = 0x0a01;
+
+// class enq_map, txn_map
+const u_int32_t jerrno::JERR_MAP_DUPLICATE = 0x0b00;
+const u_int32_t jerrno::JERR_MAP_NOTFOUND = 0x0b01;
+const u_int32_t jerrno::JERR_MAP_LOCKED = 0x0b02;
+
+// class jinf
+const u_int32_t jerrno::JERR_JINF_CVALIDFAIL = 0x0c00;
+const u_int32_t jerrno::JERR_JINF_NOVALUESTR = 0x0c01;
+const u_int32_t jerrno::JERR_JINF_BADVALUESTR = 0x0c02;
+const u_int32_t jerrno::JERR_JINF_JDATEMPTY = 0x0c03;
+const u_int32_t jerrno::JERR_JINF_TOOMANYFILES = 0x0c04;
+const u_int32_t jerrno::JERR_JINF_INVALIDFHDR = 0x0c05;
+const u_int32_t jerrno::JERR_JINF_STAT = 0x0c06;
+const u_int32_t jerrno::JERR_JINF_NOTREGFILE = 0x0c07;
+const u_int32_t jerrno::JERR_JINF_BADFILESIZE = 0x0c08;
+const u_int32_t jerrno::JERR_JINF_OWIBAD = 0x0c09;
+const u_int32_t jerrno::JERR_JINF_ZEROLENFILE = 0x0c0a;
+
+// Negative returns for some functions
+const int32_t jerrno::AIO_TIMEOUT = -1;
+const int32_t jerrno::LOCK_TAKEN = -2;
+
+
+// static initialization fn
+
+bool
+jerrno::__init()
+{
+ // generic errors
+ _err_map[JERR__MALLOC] = "JERR__MALLOC: Buffer memory allocation failed.";
+ _err_map[JERR__UNDERFLOW] = "JERR__UNDERFLOW: Underflow error";
+ _err_map[JERR__NINIT] = "JERR__NINIT: Operation on uninitialized class.";
+ _err_map[JERR__AIO] = "JERR__AIO: AIO error.";
+ _err_map[JERR__FILEIO] = "JERR__FILEIO: File read or write failure.";
+ _err_map[JERR__RTCLOCK] = "JERR__RTCLOCK: Reading real-time clock failed.";
+ _err_map[JERR__PTHREAD] = "JERR__PTHREAD: pthread failure.";
+ _err_map[JERR__TIMEOUT] = "JERR__TIMEOUT: Timeout waiting for event.";
+ _err_map[JERR__UNEXPRESPONSE] = "JERR__UNEXPRESPONSE: Unexpected response to call or event.";
+ _err_map[JERR__RECNFOUND] = "JERR__RECNFOUND: Record not found.";
+ _err_map[JERR__NOTIMPL] = "JERR__NOTIMPL: Not implemented";
+
+ // class jcntl
+ _err_map[JERR_JCNTL_STOPPED] = "JERR_JCNTL_STOPPED: Operation on stopped journal.";
+ _err_map[JERR_JCNTL_READONLY] = "JERR_JCNTL_READONLY: Write operation on read-only journal (during recovery).";
+ _err_map[JERR_JCNTL_AIOCMPLWAIT] = "JERR_JCNTL_AIOCMPLWAIT: Timeout waiting for AIOs to complete.";
+ _err_map[JERR_JCNTL_UNKNOWNMAGIC] = "JERR_JCNTL_UNKNOWNMAGIC: Found record with unknown magic.";
+ _err_map[JERR_JCNTL_NOTRECOVERED] = "JERR_JCNTL_NOTRECOVERED: Operation requires recover() to be run first.";
+ _err_map[JERR_JCNTL_RECOVERJFULL] = "JERR_JCNTL_RECOVERJFULL: Journal data files full, cannot write.";
+ _err_map[JERR_JCNTL_OWIMISMATCH] = "JERR_JCNTL_OWIMISMATCH: Overwrite Indicator (OWI) change found in unexpected location.";
+
+ // class jdir
+ _err_map[JERR_JDIR_NOTDIR] = "JERR_JDIR_NOTDIR: Directory name exists but is not a directory.";
+ _err_map[JERR_JDIR_MKDIR] = "JERR_JDIR_MKDIR: Directory creation failed.";
+ _err_map[JERR_JDIR_OPENDIR] = "JERR_JDIR_OPENDIR: Directory open failed.";
+ _err_map[JERR_JDIR_READDIR] = "JERR_JDIR_READDIR: Directory read failed.";
+ _err_map[JERR_JDIR_CLOSEDIR] = "JERR_JDIR_CLOSEDIR: Directory close failed.";
+ _err_map[JERR_JDIR_RMDIR] = "JERR_JDIR_RMDIR: Directory delete failed.";
+ _err_map[JERR_JDIR_NOSUCHFILE] = "JERR_JDIR_NOSUCHFILE: File does not exist.";
+ _err_map[JERR_JDIR_FMOVE] = "JERR_JDIR_FMOVE: File move failed.";
+ _err_map[JERR_JDIR_STAT] = "JERR_JDIR_STAT: File stat failed.";
+ _err_map[JERR_JDIR_UNLINK] = "JERR_JDIR_UNLINK: File delete failed.";
+ _err_map[JERR_JDIR_BADFTYPE] = "JERR_JDIR_BADFTYPE: Bad or unknown file type (stat mode).";
+
+ // class fcntl
+ _err_map[JERR_FCNTL_OPENWR] = "JERR_FCNTL_OPENWR: Unable to open file for write.";
+ _err_map[JERR_FCNTL_WRITE] = "JERR_FCNTL_WRITE: Unable to write to file.";
+ _err_map[JERR_FCNTL_CLOSE] = "JERR_FCNTL_CLOSE: File close failed.";
+ _err_map[JERR_FCNTL_FILEOFFSOVFL] = "JERR_FCNTL_FILEOFFSOVFL: Attempted increase file offset past file size.";
+ _err_map[JERR_FCNTL_CMPLOFFSOVFL] = "JERR_FCNTL_CMPLOFFSOVFL: Attempted increase completed file offset past submitted offset.";
+ _err_map[JERR_FCNTL_RDOFFSOVFL] = "JERR_FCNTL_RDOFFSOVFL: Attempted increase read offset past write offset.";
+
+ // class lfmgr
+ _err_map[JERR_LFMGR_BADAEFNUMLIM] = "JERR_LFMGR_BADAEFNUMLIM: Auto-expand file number limit lower than initial number of journal files.";
+ _err_map[JERR_LFMGR_AEFNUMLIMIT] = "JERR_LFMGR_AEFNUMLIMIT: Exceeded auto-expand file number limit.";
+ _err_map[JERR_LFMGR_AEDISABLED] = "JERR_LFMGR_AEDISABLED: Attempted to expand with auto-expand disabled.";
+
+ // class rrfc
+ _err_map[JERR_RRFC_OPENRD] = "JERR_RRFC_OPENRD: Unable to open file for read.";
+
+ // class jrec, enq_rec, deq_rec, txn_rec
+ _err_map[JERR_JREC_BADRECHDR] = "JERR_JREC_BADRECHDR: Invalid data record header.";
+ _err_map[JERR_JREC_BADRECTAIL] = "JERR_JREC_BADRECTAIL: Invalid data record tail.";
+
+ // class wmgr
+ _err_map[JERR_WMGR_BADPGSTATE] = "JERR_WMGR_BADPGSTATE: Page buffer in illegal state for operation.";
+ _err_map[JERR_WMGR_BADDTOKSTATE] = "JERR_WMGR_BADDTOKSTATE: Data token in illegal state for operation.";
+ _err_map[JERR_WMGR_ENQDISCONT] = "JERR_WMGR_ENQDISCONT: Enqueued new dtok when previous enqueue returned partly completed (state ENQ_PART).";
+ _err_map[JERR_WMGR_DEQDISCONT] = "JERR_WMGR_DEQDISCONT: Dequeued new dtok when previous dequeue returned partly completed (state DEQ_PART).";
+ _err_map[JERR_WMGR_DEQRIDNOTENQ] = "JERR_WMGR_DEQRIDNOTENQ: Dequeue rid is not enqueued.";
+
+ // class rmgr
+ _err_map[JERR_RMGR_UNKNOWNMAGIC] = "JERR_RMGR_UNKNOWNMAGIC: Found record with unknown magic.";
+ _err_map[JERR_RMGR_RIDMISMATCH] = "JERR_RMGR_RIDMISMATCH: RID mismatch between current record and dtok RID";
+ //_err_map[JERR_RMGR_FIDMISMATCH] = "JERR_RMGR_FIDMISMATCH: FID mismatch between emap and rrfc";
+ _err_map[JERR_RMGR_ENQSTATE] = "JERR_RMGR_ENQSTATE: Attempted read when data token wstate was not ENQ";
+ _err_map[JERR_RMGR_BADRECTYPE] = "JERR_RMGR_BADRECTYPE: Attempted operation on inappropriate record type";
+
+ // class data_tok
+ _err_map[JERR_DTOK_ILLEGALSTATE] = "JERR_MTOK_ILLEGALSTATE: Attempted to change to illegal state.";
+ //_err_map[JERR_DTOK_RIDNOTSET] = "JERR_DTOK_RIDNOTSET: Record ID not set.";
+
+ // class enq_map, txn_map
+ _err_map[JERR_MAP_DUPLICATE] = "JERR_MAP_DUPLICATE: Attempted to insert record into map using duplicate key.";
+ _err_map[JERR_MAP_NOTFOUND] = "JERR_MAP_NOTFOUND: Key not found in map.";
+ _err_map[JERR_MAP_LOCKED] = "JERR_MAP_LOCKED: Record ID locked by a pending transaction.";
+
+ // class jinf
+ _err_map[JERR_JINF_CVALIDFAIL] = "JERR_JINF_CVALIDFAIL: Journal compatibility validation failure.";
+ _err_map[JERR_JINF_NOVALUESTR] = "JERR_JINF_NOVALUESTR: No value attribute found in jinf file.";
+ _err_map[JERR_JINF_BADVALUESTR] = "JERR_JINF_BADVALUESTR: Bad format for value attribute in jinf file";
+ _err_map[JERR_JINF_JDATEMPTY] = "JERR_JINF_JDATEMPTY: Journal data files empty.";
+ _err_map[JERR_JINF_TOOMANYFILES] = "JERR_JINF_TOOMANYFILES: Too many journal data files.";
+ _err_map[JERR_JINF_INVALIDFHDR] = "JERR_JINF_INVALIDFHDR: Invalid journal data file header";
+ _err_map[JERR_JINF_STAT] = "JERR_JINF_STAT: Error while trying to stat a journal data file";
+ _err_map[JERR_JINF_NOTREGFILE] = "JERR_JINF_NOTREGFILE: Target journal data file is not a regular file";
+ _err_map[JERR_JINF_BADFILESIZE] = "JERR_JINF_BADFILESIZE: Journal data file is of incorrect or unexpected size";
+ _err_map[JERR_JINF_OWIBAD] = "JERR_JINF_OWIBAD: Journal data files have inconsistent OWI flags; >1 transition found in non-auto-expand or min-size journal";
+ _err_map[JERR_JINF_ZEROLENFILE] = "JERR_JINF_ZEROLENFILE: Journal info file zero length";
+
+ //_err_map[] = "";
+
+ return true;
+}
+
+const char*
+jerrno::err_msg(const u_int32_t err_no) throw ()
+{
+ _err_map_itr = _err_map.find(err_no);
+ if (_err_map_itr == _err_map.end())
+ return "<Unknown error code>";
+ return _err_map_itr->second;
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/jerrno.h b/cpp/src/qpid/legacystore/jrnl/jerrno.h
new file mode 100644
index 0000000000..4c8b71c423
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jerrno.h
@@ -0,0 +1,173 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jerrno.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::jerrno (journal error
+ * codes). See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_JERRNO_H
+#define QPID_LEGACYSTORE_JRNL_JERRNO_H
+
+namespace mrg
+{
+namespace journal
+{
+class jerrno;
+}
+}
+
+#include <map>
+#include <string>
+#include <sys/types.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class jerrno
+ * \brief Class containing static error definitions and static map for error messages.
+ */
+ class jerrno
+ {
+ static std::map<u_int32_t, const char*> _err_map; ///< Map of error messages
+ static std::map<u_int32_t, const char*>::iterator _err_map_itr; ///< Iterator
+ static bool _initialized; ///< Dummy flag, used to initialise map.
+
+ public:
+ // generic errors
+ static const u_int32_t JERR__MALLOC; ///< Buffer memory allocation failed
+ static const u_int32_t JERR__UNDERFLOW; ///< Underflow error
+ static const u_int32_t JERR__NINIT; ///< Operation on uninitialized class
+ static const u_int32_t JERR__AIO; ///< AIO failure
+ static const u_int32_t JERR__FILEIO; ///< File read or write failure
+ static const u_int32_t JERR__RTCLOCK; ///< Reading real-time clock failed
+ static const u_int32_t JERR__PTHREAD; ///< pthread failure
+ static const u_int32_t JERR__TIMEOUT; ///< Timeout waiting for an event
+ static const u_int32_t JERR__UNEXPRESPONSE; ///< Unexpected response to call or event
+ static const u_int32_t JERR__RECNFOUND; ///< Record not found
+ static const u_int32_t JERR__NOTIMPL; ///< Not implemented
+
+ // class jcntl
+ static const u_int32_t JERR_JCNTL_STOPPED; ///< Operation on stopped journal
+ static const u_int32_t JERR_JCNTL_READONLY; ///< Write operation on read-only journal
+ static const u_int32_t JERR_JCNTL_AIOCMPLWAIT; ///< Timeout waiting for AIOs to complete
+ static const u_int32_t JERR_JCNTL_UNKNOWNMAGIC; ///< Found record with unknown magic
+ static const u_int32_t JERR_JCNTL_NOTRECOVERED; ///< Req' recover() to be called first
+ static const u_int32_t JERR_JCNTL_RECOVERJFULL; ///< Journal data files full, cannot write
+ static const u_int32_t JERR_JCNTL_OWIMISMATCH; ///< OWI change found in unexpected location
+
+ // class jdir
+ static const u_int32_t JERR_JDIR_NOTDIR; ///< Exists but is not a directory
+ static const u_int32_t JERR_JDIR_MKDIR; ///< Directory creation failed
+ static const u_int32_t JERR_JDIR_OPENDIR; ///< Directory open failed
+ static const u_int32_t JERR_JDIR_READDIR; ///< Directory read failed
+ static const u_int32_t JERR_JDIR_CLOSEDIR; ///< Directory close failed
+ static const u_int32_t JERR_JDIR_RMDIR; ///< Directory delete failed
+ static const u_int32_t JERR_JDIR_NOSUCHFILE; ///< File does not exist
+ static const u_int32_t JERR_JDIR_FMOVE; ///< File move failed
+ static const u_int32_t JERR_JDIR_STAT; ///< File stat failed
+ static const u_int32_t JERR_JDIR_UNLINK; ///< File delete failed
+ static const u_int32_t JERR_JDIR_BADFTYPE; ///< Bad or unknown file type (stat mode)
+
+ // class fcntl
+ static const u_int32_t JERR_FCNTL_OPENWR; ///< Unable to open file for write
+ static const u_int32_t JERR_FCNTL_WRITE; ///< Unable to write to file
+ static const u_int32_t JERR_FCNTL_CLOSE; ///< File close failed
+ static const u_int32_t JERR_FCNTL_FILEOFFSOVFL; ///< Increased offset past file size
+ static const u_int32_t JERR_FCNTL_CMPLOFFSOVFL; ///< Increased cmpl offs past subm offs
+ static const u_int32_t JERR_FCNTL_RDOFFSOVFL; ///< Increased read offs past write offs
+
+ // class lfmgr
+ static const u_int32_t JERR_LFMGR_BADAEFNUMLIM; ///< Bad auto-expand file number limit
+ static const u_int32_t JERR_LFMGR_AEFNUMLIMIT; ///< Exceeded auto-expand file number limit
+ static const u_int32_t JERR_LFMGR_AEDISABLED; ///< Attempted to expand with auto-expand disabled
+
+ // class rrfc
+ static const u_int32_t JERR_RRFC_OPENRD; ///< Unable to open file for read
+
+ // class jrec, enq_rec, deq_rec, txn_rec
+ static const u_int32_t JERR_JREC_BADRECHDR; ///< Invalid data record header
+ static const u_int32_t JERR_JREC_BADRECTAIL; ///< Invalid data record tail
+
+ // class wmgr
+ static const u_int32_t JERR_WMGR_BADPGSTATE; ///< Page buffer in illegal state.
+ static const u_int32_t JERR_WMGR_BADDTOKSTATE; ///< Data token in illegal state.
+ static const u_int32_t JERR_WMGR_ENQDISCONT; ///< Enq. new dtok when previous part compl.
+ static const u_int32_t JERR_WMGR_DEQDISCONT; ///< Deq. new dtok when previous part compl.
+ static const u_int32_t JERR_WMGR_DEQRIDNOTENQ; ///< Deq. rid not enqueued
+
+ // class rmgr
+ static const u_int32_t JERR_RMGR_UNKNOWNMAGIC; ///< Found record with unknown magic
+ static const u_int32_t JERR_RMGR_RIDMISMATCH; ///< RID mismatch between rec and dtok
+ //static const u_int32_t JERR_RMGR_FIDMISMATCH; ///< FID mismatch between emap and rrfc
+ static const u_int32_t JERR_RMGR_ENQSTATE; ///< Attempted read when wstate not ENQ
+ static const u_int32_t JERR_RMGR_BADRECTYPE; ///< Attempted op on incorrect rec type
+
+ // class data_tok
+ static const u_int32_t JERR_DTOK_ILLEGALSTATE; ///< Attempted to change to illegal state
+// static const u_int32_t JERR_DTOK_RIDNOTSET; ///< Record ID not set
+
+ // class enq_map, txn_map
+ static const u_int32_t JERR_MAP_DUPLICATE; ///< Attempted to insert using duplicate key
+ static const u_int32_t JERR_MAP_NOTFOUND; ///< Key not found in map
+ static const u_int32_t JERR_MAP_LOCKED; ///< rid locked by pending txn
+
+ // class jinf
+ static const u_int32_t JERR_JINF_CVALIDFAIL; ///< Compatibility validation failure
+ static const u_int32_t JERR_JINF_NOVALUESTR; ///< No value attr found in jinf file
+ static const u_int32_t JERR_JINF_BADVALUESTR; ///< Bad format for value attr in jinf file
+ static const u_int32_t JERR_JINF_JDATEMPTY; ///< Journal data files empty
+ static const u_int32_t JERR_JINF_TOOMANYFILES; ///< Too many journal data files
+ static const u_int32_t JERR_JINF_INVALIDFHDR; ///< Invalid file header
+ static const u_int32_t JERR_JINF_STAT; ///< Error while trying to stat a file
+ static const u_int32_t JERR_JINF_NOTREGFILE; ///< Target file is not a regular file
+ static const u_int32_t JERR_JINF_BADFILESIZE; ///< File is of incorrect or unexpected size
+ static const u_int32_t JERR_JINF_OWIBAD; ///< OWI inconsistent (>1 transition in non-ae journal)
+ static const u_int32_t JERR_JINF_ZEROLENFILE; ///< Journal info file is zero length (empty).
+
+ // Negative returns for some functions
+ static const int32_t AIO_TIMEOUT; ///< Timeout waiting for AIO return
+ static const int32_t LOCK_TAKEN; ///< Attempted to take lock, but it was taken by another thread
+ /**
+ * \brief Method to access error message from known error number.
+ */
+ static const char* err_msg(const u_int32_t err_no) throw ();
+
+ private:
+ /**
+ * \brief Static function to initialize map.
+ */
+ static bool __init();
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_JERRNO_H
diff --git a/cpp/src/qpid/legacystore/jrnl/jexception.cpp b/cpp/src/qpid/legacystore/jrnl/jexception.cpp
new file mode 100644
index 0000000000..5c571020e4
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jexception.cpp
@@ -0,0 +1,183 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jexception.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Generic journal exception class mrg::journal::jexception. See comments
+ * in file jexception.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/jexception.h"
+
+#include <iomanip>
+#include <sstream>
+#include "qpid/legacystore/jrnl/jerrno.h"
+
+#define CATLEN(p) MAX_MSG_SIZE - std::strlen(p) - 1
+
+namespace mrg
+{
+namespace journal
+{
+
+jexception::jexception() throw ():
+ std::exception(),
+ _err_code(0)
+{
+ format();
+}
+
+jexception::jexception(const u_int32_t err_code) throw ():
+ std::exception(),
+ _err_code(err_code)
+{
+ format();
+}
+
+jexception::jexception(const char* additional_info) throw ():
+ std::exception(),
+ _err_code(0),
+ _additional_info(additional_info)
+{
+ format();
+}
+
+jexception::jexception(const std::string& additional_info) throw ():
+ std::exception(),
+ _err_code(0),
+ _additional_info(additional_info)
+{
+ format();
+}
+
+jexception::jexception(const u_int32_t err_code, const char* additional_info) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _additional_info(additional_info)
+{
+ format();
+}
+
+jexception::jexception(const u_int32_t err_code, const std::string& additional_info) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _additional_info(additional_info)
+{
+ format();
+}
+
+jexception::jexception(const u_int32_t err_code, const char* throwing_class,
+ const char* throwing_fn) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _throwing_class(throwing_class),
+ _throwing_fn(throwing_fn)
+{
+ format();
+}
+
+jexception::jexception(const u_int32_t err_code, const std::string& throwing_class,
+ const std::string& throwing_fn) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _throwing_class(throwing_class),
+ _throwing_fn(throwing_fn)
+{
+ format();
+}
+
+jexception::jexception(const u_int32_t err_code, const char* additional_info,
+ const char* throwing_class, const char* throwing_fn) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _additional_info(additional_info),
+ _throwing_class(throwing_class),
+ _throwing_fn(throwing_fn)
+{
+ format();
+}
+
+jexception::jexception(const u_int32_t err_code, const std::string& additional_info,
+ const std::string& throwing_class, const std::string& throwing_fn) throw ():
+ std::exception(),
+ _err_code(err_code),
+ _additional_info(additional_info),
+ _throwing_class(throwing_class),
+ _throwing_fn(throwing_fn)
+{
+ format();
+}
+
+jexception::~jexception() throw ()
+{}
+
+void
+jexception::format()
+{
+ const bool ai = !_additional_info.empty();
+ const bool tc = !_throwing_class.empty();
+ const bool tf = !_throwing_fn.empty();
+ std::ostringstream oss;
+ oss << "jexception 0x" << std::hex << std::setfill('0') << std::setw(4) << _err_code << " ";
+ if (tc)
+ {
+ oss << _throwing_class;
+ if (tf)
+ oss << "::";
+ else
+ oss << " ";
+ }
+ if (tf)
+ oss << _throwing_fn << "() ";
+ if (tc || tf)
+ oss << "threw " << jerrno::err_msg(_err_code);
+ if (ai)
+ oss << " (" << _additional_info << ")";
+ _what.assign(oss.str());
+}
+
+const char*
+jexception::what() const throw ()
+{
+ return _what.c_str();
+}
+
+std::ostream&
+operator<<(std::ostream& os, const jexception& je)
+{
+ os << je.what();
+ return os;
+}
+
+std::ostream&
+operator<<(std::ostream& os, const jexception* jePtr)
+{
+ os << jePtr->what();
+ return os;
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/jexception.h b/cpp/src/qpid/legacystore/jrnl/jexception.h
new file mode 100644
index 0000000000..34d8373235
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jexception.h
@@ -0,0 +1,142 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jexception.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Generic journal exception class mrg::journal::jexception (derived
+ * from class std::exception). Intended to serve as a common exception
+ * class for all more speicalized exceptions in the message journal. See
+ * class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_JEXCEPTION_H
+#define QPID_LEGACYSTORE_JRNL_JEXCEPTION_H
+
+namespace mrg
+{
+namespace journal
+{
+class jexception;
+}
+}
+
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <exception>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include <sstream>
+#include <string>
+#include <sys/types.h>
+
+// Macro for formatting commom system errors
+#define FORMAT_SYSERR(errno) " errno=" << errno << " (" << std::strerror(errno) << ")"
+
+#define MALLOC_CHK(ptr, var, cls, fn) if(ptr == 0) { \
+ clean(); \
+ std::ostringstream oss; \
+ oss << var << ": malloc() failed: " << FORMAT_SYSERR(errno); \
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), cls, fn); \
+ }
+
+// TODO: The following is a temporary bug-tracking aid which forces a core.
+// Replace with the commented out version below when BZ484048 is resolved.
+#define PTHREAD_CHK(err, pfn, cls, fn) if(err != 0) { \
+ std::ostringstream oss; \
+ oss << cls << "::" << fn << "(): " << pfn; \
+ errno = err; \
+ ::perror(oss.str().c_str()); \
+ ::abort(); \
+ }
+/*
+#define PTHREAD_CHK(err, pfn, cls, fn) if(err != 0) { \
+ std::ostringstream oss; \
+ oss << pfn << " failed: " << FORMAT_SYSERR(err); \
+ throw jexception(jerrno::JERR__PTHREAD, oss.str(), cls, fn); \
+ }
+*/
+
+#define ASSERT(cond, msg) if(cond == 0) { \
+ std::cerr << msg << std::endl; \
+ ::abort(); \
+ }
+
+namespace mrg
+{
+namespace journal
+{
+ /**
+ * \class jexception
+ * \brief Generic journal exception class
+ */
+ class jexception : public std::exception
+ {
+ private:
+ u_int32_t _err_code;
+ std::string _additional_info;
+ std::string _throwing_class;
+ std::string _throwing_fn;
+ std::string _what;
+ void format();
+
+ public:
+ jexception() throw ();
+
+ jexception(const u_int32_t err_code) throw ();
+
+ jexception(const char* additional_info) throw ();
+ jexception(const std::string& additional_info) throw ();
+
+ jexception(const u_int32_t err_code, const char* additional_info) throw ();
+ jexception(const u_int32_t err_code, const std::string& additional_info) throw ();
+
+ jexception(const u_int32_t err_code, const char* throwing_class, const char* throwing_fn)
+ throw ();
+ jexception(const u_int32_t err_code, const std::string& throwing_class,
+ const std::string& throwing_fn) throw ();
+
+ jexception(const u_int32_t err_code, const char* additional_info,
+ const char* throwing_class, const char* throwing_fn) throw ();
+ jexception(const u_int32_t err_code, const std::string& additional_info,
+ const std::string& throwing_class, const std::string& throwing_fn) throw ();
+
+ virtual ~jexception() throw ();
+ virtual const char* what() const throw (); // override std::exception::what()
+
+ inline u_int32_t err_code() const throw () { return _err_code; }
+ inline const std::string additional_info() const throw () { return _additional_info; }
+ inline const std::string throwing_class() const throw () { return _throwing_class; }
+ inline const std::string throwing_fn() const throw () { return _throwing_fn; }
+
+ friend std::ostream& operator<<(std::ostream& os, const jexception& je);
+ friend std::ostream& operator<<(std::ostream& os, const jexception* jePtr);
+ }; // class jexception
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_JEXCEPTION_H
diff --git a/cpp/src/qpid/legacystore/jrnl/jinf.cpp b/cpp/src/qpid/legacystore/jrnl/jinf.cpp
new file mode 100644
index 0000000000..4117bd3581
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jinf.cpp
@@ -0,0 +1,540 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jinf.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the code for the mrg::journal::jinf class.
+ *
+ * See jinf.h comments for details of this class.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "jrnl/jinf.h"
+
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#include <fstream>
+#include "qpid/legacystore/jrnl/file_hdr.h"
+#include "qpid/legacystore/jrnl/jcntl.h"
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/lp_map.h"
+#include <sstream>
+#include <sys/stat.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+jinf::jinf(const std::string& jinf_filename, bool validate_flag):
+ _jver(0),
+ _filename(jinf_filename),
+ _num_jfiles(0),
+ _ae(false),
+ _ae_max_jfiles(0),
+ _jfsize_sblks(0),
+ _sblk_size_dblks(0),
+ _dblk_size(0),
+ _wcache_pgsize_sblks(0),
+ _wcache_num_pages(0),
+ _rcache_pgsize_sblks(0),
+ _rcache_num_pages(0),
+ _tm_ptr(0),
+ _valid_flag(false),
+ _analyzed_flag(false),
+ _initial_owi(false),
+ _frot(false)
+{
+ read(_filename);
+ if (validate_flag)
+ validate();
+}
+
+jinf::jinf(const std::string& jid, const std::string& jdir, const std::string& base_filename, const u_int16_t num_jfiles,
+ const bool auto_expand, const u_int16_t ae_max_jfiles, const u_int32_t jfsize_sblks,
+ const u_int32_t wcache_pgsize_sblks, const u_int16_t wcache_num_pages, const timespec& ts):
+ _jver(RHM_JDAT_VERSION),
+ _jid(jid),
+ _jdir(jdir),
+ _base_filename(base_filename),
+ _ts(ts),
+ _num_jfiles(num_jfiles),
+ _ae(auto_expand),
+ _ae_max_jfiles(ae_max_jfiles),
+ _jfsize_sblks(jfsize_sblks),
+ _sblk_size_dblks(JRNL_SBLK_SIZE),
+ _dblk_size(JRNL_DBLK_SIZE),
+ _wcache_pgsize_sblks(wcache_pgsize_sblks),
+ _wcache_num_pages(wcache_num_pages),
+ _rcache_pgsize_sblks(JRNL_RMGR_PAGE_SIZE),
+ _rcache_num_pages(JRNL_RMGR_PAGES),
+ _tm_ptr(std::localtime(&ts.tv_sec)),
+ _valid_flag(false),
+ _analyzed_flag(false),
+ _initial_owi(false)
+{
+ set_filename();
+}
+
+jinf::~jinf()
+{}
+
+void
+jinf::validate()
+{
+ bool err = false;
+ std::ostringstream oss;
+ if (_jver != RHM_JDAT_VERSION)
+ {
+ oss << "File \"" << _filename << "\": ";
+ oss << "RHM_JDAT_VERSION mismatch: found=" << (int)_jver;
+ oss << "; required=" << RHM_JDAT_VERSION << std::endl;
+ err = true;
+ }
+ if (_num_jfiles < JRNL_MIN_NUM_FILES)
+ {
+ oss << "File \"" << _filename << "\": ";
+ oss << "Number of journal files too small: found=" << _num_jfiles;
+ oss << "; minimum=" << JRNL_MIN_NUM_FILES << std::endl;
+ err = true;
+ }
+ if (_num_jfiles > JRNL_MAX_NUM_FILES)
+ {
+ oss << "File \"" << _filename << "\": ";
+ oss << "Number of journal files too large: found=" << _num_jfiles;
+ oss << "; maximum=" << JRNL_MAX_NUM_FILES << std::endl;
+ err = true;
+ }
+ if (_ae)
+ {
+ if (_ae_max_jfiles < _num_jfiles)
+ {
+ oss << "File \"" << _filename << "\": ";
+ oss << "Number of journal files exceeds auto-expansion limit: found=" << _num_jfiles;
+ oss << "; maximum=" << _ae_max_jfiles;
+ err = true;
+ }
+ if (_ae_max_jfiles > JRNL_MAX_NUM_FILES)
+ {
+ oss << "File \"" << _filename << "\": ";
+ oss << "Auto-expansion file limit too large: found=" << _ae_max_jfiles;
+ oss << "; maximum=" << JRNL_MAX_NUM_FILES;
+ err = true;
+ }
+ }
+ if (_jfsize_sblks < JRNL_MIN_FILE_SIZE)
+ {
+ oss << "File \"" << _filename << "\": ";
+ oss << "Journal file size too small: found=" << _jfsize_sblks;
+ oss << "; minimum=" << JRNL_MIN_FILE_SIZE << " (sblks)" << std::endl;
+ err = true;
+ }
+ if (_sblk_size_dblks != JRNL_SBLK_SIZE)
+ {
+ oss << "File \"" << _filename << "\": ";
+ oss << "JRNL_SBLK_SIZE mismatch: found=" << _sblk_size_dblks;
+ oss << "; required=" << JRNL_SBLK_SIZE << std::endl;
+ err = true;
+ }
+ if (_dblk_size != JRNL_DBLK_SIZE)
+ {
+ oss << "File \"" << _filename << "\": ";
+ oss << "JRNL_DBLK_SIZE mismatch: found=" << _dblk_size;
+ oss << "; required=" << JRNL_DBLK_SIZE << std::endl;
+ err = true;
+ }
+ if (err)
+ throw jexception(jerrno::JERR_JINF_CVALIDFAIL, oss.str(), "jinf", "validate");
+ _valid_flag = true;
+}
+
+void
+jinf::analyze()
+{
+ lp_map early_map; // map for all owi flags same as pfid 0
+ lp_map late_map; // map for all owi flags opposite to pfid 0
+ bool late_latch = false; // latch for owi switchover
+
+ if (!_valid_flag)
+ validate();
+ bool done = false;
+ for (u_int16_t pfid=0; pfid<_num_jfiles && !done; pfid++)
+ {
+ std::ostringstream oss;
+ if (_jdir.at(_jdir.size() - 1) == '/')
+ oss << _jdir << _base_filename << ".";
+ else
+ oss << _jdir << "/" << _base_filename << ".";
+ oss << std::setw(4) << std::setfill('0') << std::hex << pfid;
+ oss << "." << JRNL_DATA_EXTENSION;
+
+ // Check size of each file is consistent and expected
+ u_int32_t fsize = get_filesize(oss.str());
+ if (fsize != (_jfsize_sblks + 1) * _sblk_size_dblks * _dblk_size)
+ {
+ std::ostringstream oss1;
+ oss1 << "File \"" << oss.str() << "\": size=" << fsize << "; expected=" << ((_jfsize_sblks + 1) * _sblk_size_dblks * _dblk_size);
+ throw jexception(jerrno::JERR_JINF_BADFILESIZE, oss1.str(), "jinf", "analyze");
+ }
+
+ std::ifstream jifs(oss.str().c_str());
+ if (!jifs.good())
+ throw jexception(jerrno::JERR__FILEIO, oss.str(), "jinf", "analyze");
+ file_hdr fhdr;
+ jifs.read((char*)&fhdr, sizeof(fhdr));
+ if (fhdr._magic != RHM_JDAT_FILE_MAGIC) // No file header
+ {
+ if (fhdr._magic != 0)
+ throw jexception(jerrno::JERR_JINF_INVALIDFHDR, oss.str(), "jinf", "analyze");
+ if (!pfid) // pfid 0 == lid 0 cannot be empty
+ throw jexception(jerrno::JERR_JINF_JDATEMPTY, oss.str(), "jinf", "analyze");
+ _frot = true;
+ done = true;
+ }
+ else
+ {
+ assert(pfid == fhdr._pfid);
+ if (pfid == 0)
+ {
+ _initial_owi = fhdr.get_owi();
+ early_map.insert(fhdr._lfid, pfid);
+ }
+ else
+ {
+ if (_initial_owi == fhdr.get_owi())
+ {
+ early_map.insert(fhdr._lfid, pfid);
+ if (late_latch && (!_ae || _num_jfiles == JRNL_MIN_NUM_FILES))
+ throw jexception(jerrno::JERR_JINF_OWIBAD, oss.str(), "jinf", "analyze");
+ }
+ else
+ {
+ late_map.insert(fhdr._lfid, pfid);
+ late_latch = true;
+ }
+ }
+ }
+ jifs.close();
+ } // for (pfid)
+
+ // If this is not the first rotation, all files should be in either early or late maps
+ if (!_frot) assert(early_map.size() + late_map.size() == _num_jfiles);
+
+ _pfid_list.clear();
+ late_map.get_pfid_list(_pfid_list);
+ early_map.get_pfid_list(_pfid_list);
+
+ // Check OWI consistency
+// for (u_int16_t lfid=0; lfid<_num_jfiles && !done; lfid++)
+// {
+// throw jexception(jerrno::JERR_JINF_OWIBAD, oss.str(), "jinf", "analyze");
+// }
+
+ _analyzed_flag = true;
+}
+
+void
+jinf::write()
+{
+ std::ostringstream oss;
+ oss << _jdir << "/" << _base_filename << "." << JRNL_INFO_EXTENSION;
+ std::ofstream of(oss.str().c_str(), std::ofstream::out | std::ofstream::trunc);
+ if (!of.good())
+ throw jexception(jerrno::JERR__FILEIO, oss.str(), "jinf", "write");
+ of << xml_str();
+ of.close();
+}
+
+u_int16_t
+jinf::incr_num_jfiles()
+{
+ if (_num_jfiles >= JRNL_MAX_NUM_FILES)
+ throw jexception(jerrno::JERR_JINF_TOOMANYFILES, "jinf", "incr_num_jfiles");
+ return ++_num_jfiles;
+}
+
+u_int16_t
+jinf::get_first_pfid()
+{
+ if (!_analyzed_flag)
+ analyze();
+ return *_pfid_list.begin();
+}
+
+u_int16_t
+jinf::get_last_pfid()
+{
+ if (!_analyzed_flag)
+ analyze();
+ return *_pfid_list.rbegin();
+}
+
+jinf::pfid_list&
+jinf::get_pfid_list()
+{
+ if (!_analyzed_flag)
+ analyze();
+ return _pfid_list;
+}
+
+void
+jinf::get_normalized_pfid_list(pfid_list& pfid_list)
+{
+ if (!_analyzed_flag)
+ analyze();
+ pfid_list.clear();
+ u_int16_t s = _pfid_list.size();
+ u_int16_t iz = 0; // index of 0 value
+ while (_pfid_list[iz] && iz < s)
+ iz++;
+ assert(_pfid_list[iz] == 0);
+ for (u_int16_t i = iz; i < iz + s; i++)
+ pfid_list.push_back(_pfid_list[i % s]);
+ assert(pfid_list[0] == 0);
+ assert(pfid_list.size() == s);
+}
+
+bool
+jinf::get_initial_owi()
+{
+ if (!_analyzed_flag)
+ analyze();
+ return _initial_owi;
+}
+
+bool
+jinf::get_frot()
+{
+ if (!_analyzed_flag)
+ analyze();
+ return _frot;
+}
+
+std::string
+jinf::to_string() const
+{
+ std::ostringstream oss;
+ oss << std::setfill('0');
+ oss << "Journal ID \"" << _jid << "\" initialized " << (_tm_ptr->tm_year + 1900) << "/";
+ oss << std::setw(2) << (_tm_ptr->tm_mon + 1) << "/" << std::setw(2) << _tm_ptr->tm_mday << " ";
+ oss << std::setw(2) << _tm_ptr->tm_hour << ":" << std::setw(2) << _tm_ptr->tm_min << ":";
+ oss << std::setw(2) << _tm_ptr->tm_sec << "." << std::setw(9) << _ts.tv_nsec << ":" << std::endl;
+ oss << " Journal directory: \"" << _jdir << "\"" << std::endl;
+ oss << " Journal base filename: \"" << _base_filename << "\"" << std::endl;
+ oss << " Journal version: " << (unsigned)_jver << std::endl;
+ oss << " Number of journal files: " << _num_jfiles << std::endl;
+// TODO: Uncomment these lines when auto-expand is enabled.
+// oss << " Auto-expand mode: " << (_ae ? "enabled" : "disabled") << std::endl;
+// if (_ae) oss << " Max. number of journal files (in auto-expand mode): " << _ae_max_jfiles << std::endl;
+ oss << " Journal file size: " << _jfsize_sblks << " sblks" << std::endl;
+ oss << " Softblock size (JRNL_SBLK_SIZE): " << _sblk_size_dblks << " dblks" << std::endl;
+ oss << " Datablock size (JRNL_DBLK_SIZE): " << _dblk_size << " bytes" << std::endl;
+ oss << " Write page size: " << _wcache_pgsize_sblks << " sblks" << std::endl;
+ oss << " Number of write pages: " << _wcache_num_pages << std::endl;
+ oss << " Read page size (JRNL_RMGR_PAGE_SIZE): " << _rcache_pgsize_sblks << " sblks" << std::endl;
+ oss << " Number of read pages (JRNL_RMGR_PAGES): " << _rcache_num_pages << std::endl;
+ return oss.str();
+}
+
+std::string
+jinf::xml_str() const
+{
+ // TODO: This is *not* an XML writer, rather for simplicity, it uses literals. I'm sure a more elegant way can be
+ // found to do this using the real thing...
+
+ std::ostringstream oss;
+ oss << std::setfill('0');
+ oss << "<?xml version=\"1.0\" ?>" << std::endl;
+ oss << "<jrnl>" << std::endl;
+ oss << " <journal_version value=\"" << (unsigned)_jver << "\" />" << std::endl;
+ oss << " <journal_id>" << std::endl;
+ oss << " <id_string value=\"" << _jid << "\" />" << std::endl;
+ oss << " <directory value=\"" << _jdir << "\" />" << std::endl;
+ oss << " <base_filename value=\"" << _base_filename << "\" />" << std::endl;
+ oss << " </journal_id>" << std::endl;
+ oss << " <creation_time>" << std::endl;
+ oss << " <seconds value=\"" << _ts.tv_sec << "\" />" << std::endl;
+ oss << " <nanoseconds value=\"" << _ts.tv_nsec << "\" />" << std::endl;
+ oss << " <string value=\"" << (_tm_ptr->tm_year + 1900) << "/";
+ oss << std::setw(2) << (_tm_ptr->tm_mon + 1) << "/" << std::setw(2) << _tm_ptr->tm_mday << " ";
+ oss << std::setw(2) << _tm_ptr->tm_hour << ":" << std::setw(2) << _tm_ptr->tm_min << ":";
+ oss << std::setw(2) << _tm_ptr->tm_sec << "." << std::setw(9) << _ts.tv_nsec;
+ oss << "\" />" << std::endl;
+ oss << " </creation_time>" << std::endl;
+ oss << " <journal_file_geometry>" << std::endl;
+ oss << " <number_jrnl_files value=\"" << _num_jfiles << "\" />" << std::endl;
+ oss << " <auto_expand value=\"" << (_ae ? "true" : "false") << "\" />" << std::endl;
+ if (_ae) oss << " <auto_expand_max_jrnl_files value=\"" << _ae_max_jfiles << "\" />" << std::endl;
+ oss << " <jrnl_file_size_sblks value=\"" << _jfsize_sblks << "\" />" << std::endl;
+ oss << " <JRNL_SBLK_SIZE value=\"" << _sblk_size_dblks << "\" />" << std::endl;
+ oss << " <JRNL_DBLK_SIZE value=\"" << _dblk_size << "\" />" << std::endl;
+ oss << " </journal_file_geometry>" << std::endl;
+ oss << " <cache_geometry>" << std::endl;
+ oss << " <wcache_pgsize_sblks value=\"" << _wcache_pgsize_sblks << "\" />" << std::endl;
+ oss << " <wcache_num_pages value=\"" << _wcache_num_pages << "\" />" << std::endl;
+ oss << " <JRNL_RMGR_PAGE_SIZE value=\"" << _rcache_pgsize_sblks << "\" />" << std::endl;
+ oss << " <JRNL_RMGR_PAGES value=\"" << _rcache_num_pages << "\" />" << std::endl;
+ oss << " </cache_geometry>" << std::endl;
+ oss << "</jrnl>" << std::endl;
+ return oss.str();
+}
+
+void
+jinf::set_filename()
+{
+ std::ostringstream oss;
+ oss << _jdir << "/" << _base_filename << "." << JRNL_INFO_EXTENSION;
+ _filename = oss.str().c_str();
+}
+
+void
+jinf::read(const std::string& jinf_filename)
+{
+ // TODO: This is *not* an XML reader, rather for simplicity, it is a brute-force line reader which relies on string
+ // recognition. It relies on the format of xml_str() above; it will not handle a XML restructuring.
+ // *** Can it be replaced cheaply by a real XML reader? Should it be, or is this sufficient? ***
+
+ char buff[1024]; // limit of line input length
+ std::ifstream jinfs(jinf_filename.c_str());
+ if (!jinfs.good())
+ throw jexception(jerrno::JERR__FILEIO, jinf_filename.c_str(), "jinf", "read");
+ u_int32_t charcnt = 0;
+ while (jinfs.good())
+ {
+ jinfs.getline(buff, 1023);
+ charcnt += std::strlen(buff);
+ if (std::strstr(buff, "journal_version"))
+ _jver = u_int16_value(buff);
+ else if(std::strstr(buff, "id_string"))
+ string_value(_jid, buff);
+ else if(std::strstr(buff, "directory"))
+ string_value(_jdir, buff);
+ else if(std::strstr(buff, "base_filename"))
+ string_value(_base_filename, buff);
+ else if(std::strstr(buff, "number_jrnl_files"))
+ _num_jfiles = u_int16_value(buff);
+ else if(std::strstr(buff, "auto_expand_max_jrnl_files"))
+ _ae_max_jfiles = u_int16_value(buff);
+ else if(std::strstr(buff, "auto_expand"))
+ _ae = bool_value(buff);
+ else if(std::strstr(buff, "jrnl_file_size_sblks"))
+ _jfsize_sblks = u_int32_value(buff);
+ else if(std::strstr(buff, "JRNL_SBLK_SIZE"))
+ _sblk_size_dblks = u_int16_value(buff);
+ else if(std::strstr(buff, "JRNL_DBLK_SIZE"))
+ _dblk_size = u_int32_value(buff);
+ else if(std::strstr(buff, "wcache_pgsize_sblks"))
+ _wcache_pgsize_sblks = u_int32_value(buff);
+ else if(std::strstr(buff, "wcache_num_pages"))
+ _wcache_num_pages = u_int32_value(buff);
+ else if(std::strstr(buff, "JRNL_RMGR_PAGE_SIZE"))
+ _rcache_pgsize_sblks = u_int32_value(buff);
+ else if(std::strstr(buff, "JRNL_RMGR_PAGES"))
+ _rcache_num_pages = u_int32_value(buff);
+ else if(std::strstr(buff, "nanoseconds"))
+ _ts.tv_nsec = u_int32_value(buff);
+ else if(std::strstr(buff, "seconds"))
+ {
+ _ts.tv_sec = u_int32_value(buff);
+ _tm_ptr = std::localtime(&_ts.tv_sec);
+ }
+ }
+ jinfs.close();
+ if (charcnt == 0)
+ throw jexception(jerrno::JERR_JINF_ZEROLENFILE, jinf_filename.c_str(), "jinf", "read");
+}
+
+bool
+jinf::bool_value(char* line) const
+{
+ return std::strcmp(find_value(line), "true") == 0;
+}
+
+u_int16_t
+jinf::u_int16_value(char* line) const
+{
+ return std::atoi(find_value(line));
+}
+
+u_int32_t
+jinf::u_int32_value(char* line) const
+{
+ return std::atol(find_value(line));
+}
+
+std::string&
+jinf::string_value(std::string& str, char* line) const
+{
+ str.assign(find_value(line));
+ return str;
+}
+
+char*
+jinf::find_value(char* line) const
+{
+ const char* target1_str = "value=\"";
+ int target2_char = '\"';
+ char* t1 = std::strstr(line, target1_str);
+ if (t1 == 0)
+ {
+ std::ostringstream oss;
+ oss << "File \"" << _filename << "\": line=" << line;
+ throw jexception(jerrno::JERR_JINF_NOVALUESTR, oss.str(), "jinf", "find_value");
+ }
+ t1 += std::strlen(target1_str);
+
+ char* t2 = std::strchr(t1, target2_char);
+ if (t2 == 0)
+ {
+ std::ostringstream oss;
+ oss << "File \"" << _filename << "\": line=" << line;
+ throw jexception(jerrno::JERR_JINF_BADVALUESTR, oss.str(), "jinf", "find_value");
+ }
+ *t2 = '\0';
+ return t1;
+}
+
+u_int32_t
+jinf::get_filesize(const std::string& file_name) const
+{
+ struct stat s;
+ if (::stat(file_name.c_str(), &s))
+ {
+ std::ostringstream oss;
+ oss << "stat: file=\"" << file_name << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_JINF_STAT, oss.str(), "jinf", "get_filesize");
+ }
+ if (!S_ISREG(s.st_mode)) // not a regular file,
+ {
+ std::ostringstream oss;
+ oss << "File \"" << file_name << "\" is not a regular file: mode=0x" << std::hex << s.st_mode;
+ throw jexception(jerrno::JERR_JINF_NOTREGFILE, oss.str(), "jinf", "get_filesize");
+ }
+ return u_int32_t(s.st_size);
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/jinf.h b/cpp/src/qpid/legacystore/jrnl/jinf.h
new file mode 100644
index 0000000000..73f5386a19
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jinf.h
@@ -0,0 +1,133 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jinf.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the code for the mrg::journal::jinf class.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_JINF_H
+#define QPID_LEGACYSTORE_JRNL_JINF_H
+
+#include <ctime>
+#include <string>
+#include <sys/types.h>
+#include <vector>
+
+namespace mrg
+{
+namespace journal
+{
+ /**
+ * \class jinf
+ * \brief Class to handle the journal information file &lt;basename&gt;.jinf.
+ */
+ class jinf
+ {
+ public:
+ typedef std::vector<u_int16_t> pfid_list; // pfids
+ typedef pfid_list::const_iterator pfidl_citr;
+
+ private:
+ u_int8_t _jver;
+ std::string _jid;
+ std::string _jdir;
+ std::string _base_filename;
+ std::string _filename;
+ timespec _ts;
+ u_int16_t _num_jfiles;
+ bool _ae;
+ u_int32_t _ae_max_jfiles;
+ u_int32_t _jfsize_sblks;
+ u_int16_t _sblk_size_dblks;
+ u_int32_t _dblk_size;
+ u_int32_t _wcache_pgsize_sblks;
+ u_int16_t _wcache_num_pages;
+ u_int32_t _rcache_pgsize_sblks;
+ u_int16_t _rcache_num_pages;
+ std::tm* _tm_ptr;
+ bool _valid_flag;
+ bool _analyzed_flag;
+ pfid_list _pfid_list;
+ bool _initial_owi;
+ bool _frot;
+
+ public:
+ // constructor for reading existing jinf file
+ jinf(const std::string& jinf_filename, bool validate_flag);
+ // constructor for writing jinf file
+ jinf(const std::string& jid, const std::string& jdir, const std::string& base_filename,
+ const u_int16_t num_jfiles, const bool auto_expand, const u_int16_t ae_max_jfiles,
+ const u_int32_t jfsize_sblks, const u_int32_t wcache_pgsize_sblks, const u_int16_t wcache_num_pages,
+ const timespec& ts);
+ virtual ~jinf();
+
+ void validate();
+ void analyze();
+ void write();
+
+ inline u_int8_t jver() const { return _jver; }
+ inline const std::string& jid() const { return _jid; }
+ inline const std::string& jdir() const { return _jdir; }
+ inline void set_jdir(const std::string& jdir) { _jdir = jdir; }
+ inline const std::string& base_filename() const { return _base_filename; }
+ inline const timespec& ts() const { return _ts; }
+ inline u_int16_t num_jfiles() const { return _num_jfiles; }
+ u_int16_t incr_num_jfiles();
+ inline bool is_ae() const { return _ae; }
+ inline u_int16_t ae_max_jfiles() const { return _ae_max_jfiles; }
+ inline u_int32_t jfsize_sblks() const { return _jfsize_sblks; }
+ inline u_int16_t sblk_size_dblks() const { return _sblk_size_dblks; }
+ inline u_int32_t dblk_size() const { return _dblk_size; }
+ inline u_int32_t wcache_pgsize_sblks() const { return _wcache_pgsize_sblks; }
+ inline u_int16_t wcache_num_pages() const { return _wcache_num_pages; }
+ inline u_int32_t rcache_pgsize_sblks() const { return _rcache_pgsize_sblks; }
+ inline u_int16_t rcache_num_pages() const { return _rcache_num_pages; }
+ u_int16_t get_first_pfid();
+ u_int16_t get_last_pfid();
+ pfid_list& get_pfid_list();
+ void get_normalized_pfid_list(pfid_list& pfid_list);
+ bool get_initial_owi();
+ bool get_frot();
+
+ std::string to_string() const;
+ std::string xml_str() const;
+
+ private:
+ void set_filename();
+ void read(const std::string& jinf_filename);
+ bool bool_value(char* line) const;
+ u_int16_t u_int16_value(char* line) const;
+ u_int32_t u_int32_value(char* line) const;
+ std::string& string_value(std::string& str, char* line) const;
+ char* find_value(char* line) const;
+ u_int32_t get_filesize(const std::string& file_name) const;
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_JINF_H
diff --git a/cpp/src/qpid/legacystore/jrnl/jrec.cpp b/cpp/src/qpid/legacystore/jrnl/jrec.cpp
new file mode 100644
index 0000000000..61b9b6cc9b
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jrec.cpp
@@ -0,0 +1,119 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jrec.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing source code for class mrg::journal::jrec (abstract journal
+ * jrecord). See comments in file jrec.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/jrec.h"
+
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+jrec::jrec() {}
+jrec::~jrec() {}
+
+void
+jrec::chk_hdr(const rec_hdr& hdr)
+{
+ if (hdr._magic == 0)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "enq magic NULL: rid=0x" << hdr._rid;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "jrec", "chk_hdr");
+ }
+ if (hdr._version != RHM_JDAT_VERSION)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "version: rid=0x" << hdr._rid;
+ oss << ": expected=0x" << std::setw(2) << (int)RHM_JDAT_VERSION;
+ oss << " read=0x" << std::setw(2) << (int)hdr._version;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "jrec", "chk_hdr");
+ }
+#if defined (JRNL_LITTLE_ENDIAN)
+ u_int8_t endian_flag = RHM_LENDIAN_FLAG;
+#else
+ u_int8_t endian_flag = RHM_BENDIAN_FLAG;
+#endif
+ if (hdr._eflag != endian_flag)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "endian_flag: rid=" << hdr._rid;
+ oss << ": expected=0x" << std::setw(2) << (int)endian_flag;
+ oss << " read=0x" << std::setw(2) << (int)hdr._eflag;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "jrec", "chk_hdr");
+ }
+}
+
+void
+jrec::chk_rid(const rec_hdr& hdr, const u_int64_t rid)
+{
+ if (hdr._rid != rid)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "rid mismatch: expected=0x" << rid;
+ oss << " read=0x" << hdr._rid;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "jrec", "chk_hdr");
+ }
+}
+
+void
+jrec::chk_tail(const rec_tail& tail, const rec_hdr& hdr)
+{
+ if (tail._xmagic != ~hdr._magic)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "magic: rid=0x" << hdr._rid;
+ oss << ": expected=0x" << ~hdr._magic;
+ oss << " read=0x" << tail._xmagic;
+ throw jexception(jerrno::JERR_JREC_BADRECTAIL, oss.str(), "jrec", "chk_tail");
+ }
+ if (tail._rid != hdr._rid)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "rid: rid=0x" << hdr._rid;
+ oss << ": read=0x" << tail._rid;
+ throw jexception(jerrno::JERR_JREC_BADRECTAIL, oss.str(), "jrec", "chk_tail");
+ }
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/jrec.h b/cpp/src/qpid/legacystore/jrnl/jrec.h
new file mode 100644
index 0000000000..9d0771cabd
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/jrec.h
@@ -0,0 +1,183 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file jrec.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing source code for class mrg::journal::jrec (abstract journal
+ * jrecord). See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_JREC_H
+#define QPID_LEGACYSTORE_JRNL_JREC_H
+
+namespace mrg
+{
+namespace journal
+{
+class jrec;
+}
+}
+
+#include <cstddef>
+#include <fstream>
+#include "qpid/legacystore/jrnl/rec_hdr.h"
+#include "qpid/legacystore/jrnl/rec_tail.h"
+#include <string>
+#include <sys/types.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class jrec
+ * \brief Abstract class for all file jrecords, both data and log. This class establishes
+ * the common data format and structure for these jrecords.
+ */
+ class jrec
+ {
+ public:
+ jrec();
+ virtual ~jrec();
+
+ /**
+ * \brief Encode this instance of jrec into the write buffer at the disk-block-aligned
+ * pointer wptr starting at position rec_offs_dblks in the encoded record to a
+ * maximum size of max_size_dblks.
+ *
+ * This call encodes the content of the data contianed in this instance of jrec into a
+ * disk-softblock-aligned (defined by JRNL_SBLK_SIZE) buffer pointed to by parameter
+ * wptr. No more than paramter max_size_dblks data-blocks may be written to the buffer.
+ * The parameter rec_offs_dblks is the offset in data-blocks within the fully encoded
+ * data block this instance represents at which to start encoding.
+ *
+ * Encoding entails writing the record header (struct enq_hdr), the data and the record tail
+ * (struct enq_tail). The record must be data-block-aligned (defined by JRNL_DBLK_SIZE),
+ * thus any remaining space in the final data-block is ignored; the returned value is the
+ * number of data-blocks consumed from the page by the encode action. Provided the initial
+ * alignment requirements are met, records may be of arbitrary size and may span multiple
+ * data-blocks, disk-blocks and/or pages.
+ *
+ * Since the record size in data-blocks is known, the general usage pattern is to call
+ * encode() as many times as is needed to fully encode the data. Each call to encode()
+ * will encode as much of the record as it can to what remains of the current page cache,
+ * and will return the number of data-blocks actually encoded.
+ *
+ * <b>Example:</b> Assume that record r1 was previously written to page 0, and that this
+ * is an instance representing record r2. Being larger than the page size ps, r2 would span
+ * multiple pages as follows:
+ * <pre>
+ * |<---ps--->|
+ * +----------+----------+----------+----...
+ * | |r2a| r2b | r2c | |
+ * |<-r1-><----------r2----------> |
+ * +----------+----------+----------+----...
+ * page: p0 p1 p2
+ * </pre>
+ * Encoding record r2 will require multiple calls to encode; one for each page which
+ * is involved. Record r2 is divided logically into sections r2a, r2b and r2c at the
+ * points where the page boundaries intersect with the record. Assuming a page size
+ * of ps, the page boundary pointers are represented by their names p0, p1... and the
+ * sizes of the record segments are represented by their names r1, r2a, r2b..., the calls
+ * should be as follows:
+ * <pre>
+ * encode(p0+r1, 0, ps-r1); (returns r2a data-blocks)
+ * encode(p1, r2a, ps); (returns r2b data-blocks which equals ps)
+ * encode(p2, r2a+r2b, ps); (returns r2c data-blocks)
+ * </pre>
+ *
+ * \param wptr Data-block-aligned pointer to position in page buffer where encoding is to
+ * take place.
+ * \param rec_offs_dblks Offset in data-blocks within record from which to start encoding.
+ * \param max_size_dblks Maximum number of data-blocks to write to pointer wptr.
+ * \returns Number of data-blocks encoded.
+ */
+ virtual u_int32_t encode(void* wptr, u_int32_t rec_offs_dblks,
+ u_int32_t max_size_dblks) = 0;
+
+ /**
+ * \brief Decode into this instance of jrec from the read buffer at the disk-block-aligned
+ * pointer rptr starting at position jrec_offs_dblks in the encoded record to a
+ * maximum size of max_size_blks.
+ *
+ * This call decodes a record in the page buffer pointed to by the data-block-aligned
+ * (defined by JRNL_DBLK_SIZE) parameter rptr into this instance of jrec. No more than
+ * paramter max_size_dblks data-blocks may be read from the buffer. The parameter
+ * jrec_offs_dblks is the offset in data-blocks within the encoded record at which to start
+ * decoding.
+ *
+ * Decoding entails reading the record header, the data and the tail. The record is
+ * data-block-aligned (defined by JRNL_DBLK_SIZE); the returned value is the number of
+ * data-blocks read from the buffer by the decode action. As the record data size is only
+ * known once the header is read, the number of calls required to complete reading the
+ * record will depend on the vlaues within this instance which are set when the
+ * header is decoded.
+ *
+ * A non-zero value for jrec_offs_dblks implies that this is not the first call to
+ * decode and the record data will be appended at this offset.
+ *
+ * \param h Reference to instance of struct hdr, already read from page buffer and used
+ * to determine record type
+ * \param rptr Data-block-aligned pointer to position in page buffer where decoding is to
+ * begin.
+ * \param rec_offs_dblks Offset within record from which to start appending the decoded
+ * record.
+ * \param max_size_dblks Maximum number of data-blocks to read from pointer rptr.
+ * \returns Number of data-blocks read (consumed).
+ */
+ virtual u_int32_t decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks,
+ u_int32_t max_size_dblks) = 0;
+
+ virtual bool rcv_decode(rec_hdr h, std::ifstream* ifsp, std::size_t& rec_offs) = 0;
+
+ virtual std::string& str(std::string& str) const = 0;
+ virtual std::size_t data_size() const = 0;
+ virtual std::size_t xid_size() const = 0;
+ virtual std::size_t rec_size() const = 0;
+ inline virtual u_int32_t rec_size_dblks() const { return size_dblks(rec_size()); }
+ static inline u_int32_t size_dblks(const std::size_t size)
+ { return size_blks(size, JRNL_DBLK_SIZE); }
+ static inline u_int32_t size_sblks(const std::size_t size)
+ { return size_blks(size, JRNL_DBLK_SIZE * JRNL_SBLK_SIZE); }
+ static inline u_int32_t size_blks(const std::size_t size, const std::size_t blksize)
+ { return (size + blksize - 1)/blksize; }
+ virtual u_int64_t rid() const = 0;
+
+ protected:
+ virtual void chk_hdr() const = 0;
+ virtual void chk_hdr(u_int64_t rid) const = 0;
+ virtual void chk_tail() const = 0;
+ static void chk_hdr(const rec_hdr& hdr);
+ static void chk_rid(const rec_hdr& hdr, u_int64_t rid);
+ static void chk_tail(const rec_tail& tail, const rec_hdr& hdr);
+ virtual void clean() = 0;
+ }; // class jrec
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_JREC_H
diff --git a/cpp/src/qpid/legacystore/jrnl/lp_map.cpp b/cpp/src/qpid/legacystore/jrnl/lp_map.cpp
new file mode 100644
index 0000000000..8024ddadd2
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/lp_map.cpp
@@ -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.
+ *
+ */
+
+/**
+ * \file lp_map.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::lp_map (logical file map). See
+ * comments in file lp_map.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/lp_map.h"
+
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+lp_map::lp_map() : _map() {}
+lp_map::~lp_map() {}
+
+void
+lp_map::insert(u_int16_t lfid, u_int16_t pfid)
+{
+ lfpair ip = lfpair(lfid, pfid);
+ lfret ret = _map.insert(ip);
+ if (ret.second == false)
+ {
+ std::ostringstream oss;
+ oss << std::hex << "lfid=0x" << lfid << " pfid=0x" << pfid;
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "lp_map", "insert");
+ }
+}
+
+void
+lp_map::get_pfid_list(std::vector<u_int16_t>& pfid_list)
+{
+ for (lp_map_citr_t i = _map.begin(); i != _map.end(); i++)
+ pfid_list.push_back(i->second);
+}
+
+// debug aid
+std::string
+lp_map::to_string()
+{
+ std::ostringstream oss;
+ oss << "{lfid:pfid ";
+ for (lp_map_citr_t i=_map.begin(); i!=_map.end(); i++)
+ {
+ if (i != _map.begin()) oss << ", ";
+ oss << (*i).first << ":" << (*i).second;
+ }
+ oss << "}";
+ return oss.str();
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/lp_map.h b/cpp/src/qpid/legacystore/jrnl/lp_map.h
new file mode 100644
index 0000000000..c43cbc0173
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/lp_map.h
@@ -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.
+ *
+ */
+
+/**
+ * \file lp_map.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::lp_map (logical file map).
+ * See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_LP_MAP_H
+#define QPID_LEGACYSTORE_JRNL_LP_MAP_H
+
+#include <map>
+#include <string>
+#include <sys/types.h>
+#include <vector>
+
+namespace mrg
+{
+namespace journal
+{
+ /**
+ * \class lp_map
+ * \brief Maps the logical file id (lfid) to the physical file id (pfid) in the journal.
+ *
+ * NOTE: NOT THREAD SAFE
+ */
+ class lp_map
+ {
+ public:
+ typedef std::map<u_int16_t, u_int16_t> lp_map_t;
+ typedef lp_map_t::const_iterator lp_map_citr_t;
+ typedef lp_map_t::const_reverse_iterator lp_map_critr_t;
+
+ private:
+ typedef std::pair<u_int16_t, u_int16_t> lfpair;
+ typedef std::pair<lp_map_t::iterator, bool> lfret;
+ lp_map_t _map;
+
+ public:
+ lp_map();
+ virtual ~lp_map();
+
+ void insert(u_int16_t lfid, u_int16_t pfid);
+ inline u_int16_t size() const { return u_int16_t(_map.size()); }
+ inline bool empty() const { return _map.empty(); }
+ inline lp_map_citr_t begin() { return _map.begin(); }
+ inline lp_map_citr_t end() { return _map.end(); }
+ inline lp_map_critr_t rbegin() { return _map.rbegin(); }
+ inline lp_map_critr_t rend() { return _map.rend(); }
+ void get_pfid_list(std::vector<u_int16_t>& pfid_list);
+
+ // debug aid
+ std::string to_string();
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_LP_MAP_H
diff --git a/cpp/src/qpid/legacystore/jrnl/lpmgr.cpp b/cpp/src/qpid/legacystore/jrnl/lpmgr.cpp
new file mode 100644
index 0000000000..d7b0c9f516
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/lpmgr.cpp
@@ -0,0 +1,226 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file lpmgr.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::lpmgr (non-logging file
+ * handle), used for controlling journal log files. See comments in file
+ * lpmgr.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/lpmgr.h"
+
+#include <cassert>
+#include <qpid/legacystore/jrnl/jerrno.h>
+#include <qpid/legacystore/jrnl/jexception.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+lpmgr::lpmgr() : _ae(false), _ae_max_jfiles(0)
+{}
+
+lpmgr::~lpmgr()
+{
+ finalize();
+}
+
+void
+lpmgr::initialize(const u_int16_t num_jfiles,
+ const bool ae,
+ const u_int16_t ae_max_jfiles,
+ jcntl* const jcp,
+ new_obj_fn_ptr fp)
+{
+ assert(jcp != 0);
+ finalize();
+
+ // Validate params
+ if (ae && ae_max_jfiles > 0 && ae_max_jfiles <= num_jfiles)
+ {
+ std::ostringstream oss;
+ oss << "ae_max_jfiles (" << ae_max_jfiles << ") <= num_jfiles (" << num_jfiles << ")";
+ throw jexception(jerrno::JERR_LFMGR_BADAEFNUMLIM, oss.str(), "lpmgr", "initialize");
+ }
+ _ae = ae;
+ _ae_max_jfiles = ae_max_jfiles;
+
+ const std::size_t num_res_files = ae
+ ? (ae_max_jfiles ? ae_max_jfiles : JRNL_MAX_NUM_FILES)
+ : num_jfiles;
+ _fcntl_arr.reserve(num_res_files);
+ append(jcp, fp, num_jfiles);
+}
+
+void
+lpmgr::recover(const rcvdat& rd,
+ jcntl* const jcp,
+ new_obj_fn_ptr fp)
+{
+ assert(jcp != 0);
+ finalize();
+
+ // Validate rd params
+ if (rd._aemjf > 0 && rd._aemjf <= rd._njf)
+ {
+ std::ostringstream oss;
+ oss << "ae_max_jfiles (" << rd._aemjf << ") <= num_jfiles (" << rd._njf << ")";
+ throw jexception(jerrno::JERR_LFMGR_BADAEFNUMLIM, oss.str(), "lpmgr", "recover");
+ }
+ _ae = rd._ae;
+ _ae_max_jfiles = rd._aemjf;
+
+ const std::size_t num_res_files = rd._ae
+ ? (rd._aemjf ? rd._aemjf : JRNL_MAX_NUM_FILES)
+ : rd._njf;
+ _fcntl_arr.reserve(num_res_files);
+ _fcntl_arr.assign(rd._njf, 0);
+ std::vector<u_int16_t> lfid_list(rd._fid_list.size(), 0);
+ for (std::size_t lid = 0; lid < rd._fid_list.size(); lid++)
+ lfid_list[rd._fid_list[lid]] = lid;
+ // NOTE: rd._fid_list may be smaller than rd._njf (journal may be empty or not yet file-cycled)
+ for (std::size_t pfid = 0; pfid < rd._njf; pfid++)
+ if (pfid < rd._fid_list.size())
+ _fcntl_arr[lfid_list[pfid]] = fp(jcp, lfid_list[pfid], pfid, &rd);
+ else
+ _fcntl_arr[pfid] = fp(jcp, pfid, pfid, &rd);
+}
+
+void
+lpmgr::insert(const u_int16_t after_lfid,
+ jcntl* const jcp,
+ new_obj_fn_ptr fp,
+ const u_int16_t num_jfiles)
+{
+ assert(jcp != 0);
+ assert(after_lfid < _fcntl_arr.size());
+ if (!_ae) throw jexception(jerrno::JERR_LFMGR_AEDISABLED, "lpmgr", "insert");
+ if (num_jfiles == 0) return;
+ std::size_t pfid = _fcntl_arr.size();
+ const u_int16_t eff_ae_max_jfiles = _ae_max_jfiles ? _ae_max_jfiles : JRNL_MAX_NUM_FILES;
+ if (pfid + num_jfiles > eff_ae_max_jfiles)
+ {
+ std::ostringstream oss;
+ oss << "num_files=" << pfid << " incr=" << num_jfiles << " limit=" << _ae_max_jfiles;
+ throw jexception(jerrno::JERR_LFMGR_AEFNUMLIMIT, oss.str(), "lpmgr", "insert");
+ }
+ for (std::size_t lid = after_lfid + 1; lid <= after_lfid + num_jfiles; lid++, pfid++)
+ _fcntl_arr.insert(_fcntl_arr.begin() + lid, fp(jcp, lid, pfid, 0));
+ for (std::size_t lid = after_lfid + num_jfiles + 1; lid < _fcntl_arr.size(); lid++)
+ {
+ fcntl* p = _fcntl_arr[lid];
+ assert(p != 0);
+ p->set_lfid(p->lfid() + num_jfiles);
+ }
+}
+
+void
+lpmgr::finalize()
+{
+ for (u_int32_t i = 0; i < _fcntl_arr.size(); i++)
+ delete _fcntl_arr[i];
+ _fcntl_arr.clear();
+ _ae = false;
+ _ae_max_jfiles = 0;
+}
+
+void
+lpmgr::set_ae(const bool ae)
+{
+ if (ae && _ae_max_jfiles > 0 && _ae_max_jfiles <= _fcntl_arr.size())
+ {
+ std::ostringstream oss;
+ oss << "ae_max_jfiles (" << _ae_max_jfiles << ") <= _fcntl_arr.size (" << _fcntl_arr.size() << ")";
+ throw jexception(jerrno::JERR_LFMGR_BADAEFNUMLIM, oss.str(), "lpmgr", "set_ae");
+ }
+ if (ae && _fcntl_arr.max_size() < _ae_max_jfiles)
+ _fcntl_arr.reserve(_ae_max_jfiles ? _ae_max_jfiles : JRNL_MAX_NUM_FILES);
+ _ae = ae;
+}
+
+void
+lpmgr::set_ae_max_jfiles(const u_int16_t ae_max_jfiles)
+{
+ if (_ae && ae_max_jfiles > 0 && ae_max_jfiles <= _fcntl_arr.size())
+ {
+ std::ostringstream oss;
+ oss << "ae_max_jfiles (" << _ae_max_jfiles << ") <= _fcntl_arr.size() (" << _fcntl_arr.size() << ")";
+ throw jexception(jerrno::JERR_LFMGR_BADAEFNUMLIM, oss.str(), "lpmgr", "set_ae_max_jfiles");
+ }
+ if (_ae && _fcntl_arr.max_size() < ae_max_jfiles)
+ _fcntl_arr.reserve(ae_max_jfiles ? ae_max_jfiles : JRNL_MAX_NUM_FILES);
+ _ae_max_jfiles = ae_max_jfiles;
+}
+
+u_int16_t
+lpmgr::ae_jfiles_rem() const
+{
+ if (_ae_max_jfiles > _fcntl_arr.size()) return _ae_max_jfiles - _fcntl_arr.size();
+ if (_ae_max_jfiles == 0) return JRNL_MAX_NUM_FILES - _fcntl_arr.size();
+ return 0;
+}
+
+// Testing functions
+
+void
+lpmgr::get_pfid_list(std::vector<u_int16_t>& pfid_list) const
+{
+ pfid_list.clear();
+ for (std::size_t i = 0; i < _fcntl_arr.size(); i++)
+ pfid_list.push_back(_fcntl_arr[i]->pfid());
+}
+
+void
+lpmgr::get_lfid_list(std::vector<u_int16_t>& lfid_list) const
+{
+ lfid_list.clear();
+ lfid_list.assign(_fcntl_arr.size(), 0);
+ for (std::size_t i = 0; i < _fcntl_arr.size(); i++)
+ lfid_list[_fcntl_arr[i]->pfid()] = i;
+}
+
+// === protected fns ===
+
+void
+lpmgr::append(jcntl* const jcp,
+ new_obj_fn_ptr fp,
+ const u_int16_t num_jfiles)
+{
+ std::size_t s = _fcntl_arr.size();
+ if (_ae_max_jfiles && s + num_jfiles > _ae_max_jfiles)
+ {
+ std::ostringstream oss;
+ oss << "num_files=" << s << " incr=" << num_jfiles << " limit=" << _ae_max_jfiles;
+ throw jexception(jerrno::JERR_LFMGR_AEFNUMLIMIT, oss.str(), "lpmgr", "append");
+ }
+ for (std::size_t i = s; i < s + num_jfiles; i++)
+ _fcntl_arr.push_back(fp(jcp, i, i, 0));
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/lpmgr.h b/cpp/src/qpid/legacystore/jrnl/lpmgr.h
new file mode 100644
index 0000000000..be5c4494cc
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/lpmgr.h
@@ -0,0 +1,303 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file lpmgr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Class mrg::journal::lpmgr. See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_LPMGR_H
+#define QPID_LEGACYSTORE_JRNL_LPMGR_H
+
+namespace mrg
+{
+namespace journal
+{
+ class jcntl;
+ class lpmgr;
+}
+}
+
+#include "qpid/legacystore/jrnl/fcntl.h"
+#include <vector>
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \brief LFID-PFID manager. This class maps the logical file id (lfid) to the physical file id (pfid) so that files
+ * may be inserted into the file ring buffer in (nearly) arbitrary logical locations while the physical ids continue
+ * to be appended. NOTE: NOT THREAD SAFE.
+ *
+ * The entire functionality of the LFID-PFID manager is to maintain an array of pointers to fcntl objects which have
+ * a one-to-one relationship to the physical %journal files. The logical file id (lfid) is used as an index to the
+ * array to read the mapped physical file id (pfid). By altering the order of these pointers within the array, the
+ * mapping of logical to physical files may be altered. This can be used to allow for the logical insertion of
+ * %journal files into a ring buffer, even though the physical file ids must be appended to those that preceded them.
+ *
+ * Since the insert() operation uses after-lfid as its position parameter, it is not possible to insert before lfid
+ * 0 - i.e. It is only possible to insert after an existing lfid. Consequently, lfid 0 and pfid 0 are always
+ * coincident in a %journal. Note, however, that inserting before lfid 0 is logically equivilent to inserting after
+ * the last lfid.
+ *
+ * When one or more files are inserted after a particular lfid, the lfids of the following files are incremented. The
+ * pfids of the inserted files follow those of all existing files, thus leading to a lfid-pfid discreppancy (ie no
+ * longer a one-to-one mapping):
+ *
+ * Example: Before insertion, %journal file headers would look as follows:
+ * <pre>
+ * Logical view (sorted by lfid): Physical view (sorted by pfid):
+ * +---+---+---+---+---+---+ +---+---+---+---+---+---+
+ * pfid --> | 0 | 1 | 2 | 3 | 4 | 5 | pfid --> | 0 | 1 | 2 | 3 | 4 | 5 |
+ * lfid --> | 0 | 1 | 2 | 3 | 4 | 5 | lfid --> | 0 | 1 | 2 | 3 | 4 | 5 |
+ * +---+---+---+---+---+---+ +---+---+---+---+---+---+
+ * </pre>
+ *
+ * After insertion of 2 files after lid 2 (marked with *s):
+ * <pre>
+ * Logical view (sorted by lfid): Physical view (sorted by pfid):
+ * +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
+ * pfid --> | 0 | 1 | 2 |*6*|*7*| 3 | 4 | 5 | pfid --> | 0 | 1 | 2 | 3 | 4 | 5 |*6*|*7*|
+ * lfid --> | 0 | 1 | 2 |*3*|*4*| 5 | 6 | 7 | lfid --> | 0 | 1 | 2 | 5 | 6 | 7 |*3*|*4*|
+ * +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
+ * </pre>
+ *
+ * The insert() function updates the internal map immediately, but the physical files (which have both the pfid and
+ * lfid written into the file header) are only updated as they are overwritten in the normal course of enqueueing
+ * and dequeueing messages. If the %journal should fail after insertion but before the files following those inserted
+ * are overwritten, then duplicate lfids will be present (though no duplicate pfids are possible). The overwrite
+ * indicator (owi) flag and the pfid numbers may be used to resolve the ambiguity and determine the logically earlier
+ * lfid in this case.
+ *
+ * Example: Before insertion, the current active write file being lfid/pfid 2 as determined by the owi flag, %journal
+ * file headers would look as follows:
+ * <pre>
+ * Logical view (sorted by lfid): Physical view (sorted by pfid):
+ * +---+---+---+---+---+---+ +---+---+---+---+---+---+
+ * pfid --> | 0 | 1 | 2 | 3 | 4 | 5 | pfid --> | 0 | 1 | 2 | 3 | 4 | 5 |
+ * lfid --> | 0 | 1 | 2 | 3 | 4 | 5 | lfid --> | 0 | 1 | 2 | 3 | 4 | 5 |
+ * owi --> | t | t | t | f | f | f | owi --> | t | t | t | f | f | f |
+ * +---+---+---+---+---+---+ +---+---+---+---+---+---+
+ * </pre>
+ *
+ * After inserting 2 files after lfid 2 and then 3 (the newly inserted file) - marked with *s:
+ * <pre>
+ * Logical view (sorted by lfid): Physical view (sorted by pfid):
+ * +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
+ * pfid --> | 0 | 1 | 2 |*6*|*7*| 3 | 4 | 5 | pfid --> | 0 | 1 | 2 | 3 | 4 | 5 |*3*|*4*|
+ * lfid --> | 0 | 1 | 2 |*3*|*4*| 3 | 4 | 5 | lfid --> | 0 | 1 | 2 | 3 | 4 | 5 |*3*|*4*|
+ * owi --> | t | t | t | t | t | f | f | f | owi --> | t | t | t | f | f | f | t | t |
+ * +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
+ * </pre>
+ *
+ * If a broker failure occurs at this point, then there are two independent tests that may be made to resolve
+ * duplicate lfids during recovery in such cases:
+ * <ol>
+ * <li>The correct lfid has owi flag that matches that of pfid/lfid 0</li>
+ * <li>The most recently inserted (hence correct) lfid has pfids that are higher than the duplicate that was not
+ * overwritten</li>
+ * </ol>
+ *
+ * NOTE: NOT THREAD SAFE. Provide external thread protection if used in multi-threaded environments.
+ */
+ class lpmgr
+ {
+ public:
+ /**
+ * \brief Function pointer to function that will create a new fcntl object and return its pointer.
+ *
+ * \param jcp Pointer to jcntl instance from which journal file details will be obtained.
+ * \param lfid Logical file ID for new fcntl instance.
+ * \param pfid Physical file ID for file associated with new fcntl instance.
+ * \param rdp Pointer to rcvdat instance which conatins recovery information for new fcntl instance when
+ * recovering an existing file, or null if a new file is to be created.
+ */
+ typedef fcntl* (new_obj_fn_ptr)(jcntl* const jcp,
+ const u_int16_t lfid,
+ const u_int16_t pfid,
+ const rcvdat* const rdp);
+
+ private:
+ bool _ae; ///< Auto-expand mode
+ u_int16_t _ae_max_jfiles; ///< Max file count for auto-expansion; 0 = no limit
+ std::vector<fcntl*> _fcntl_arr; ///< Array of pointers to fcntl objects
+
+ public:
+ lpmgr();
+ virtual ~lpmgr();
+
+ /**
+ * \brief Initialize from scratch for a known number of %journal files. All lfid values are identical to pfid
+ * values (which is normal before any inserts have occurred).
+ *
+ * \param num_jfiles Number of files to be created, and consequently the number of fcntl objects in array
+ * _fcntl_arr.
+ * \param ae If true, allows auto-expansion; if false, disables auto-expansion.
+ * \param ae_max_jfiles The maximum number of files allowed for auto-expansion. Cannot be lower than the current
+ * number of files. However, a zero value disables the limit checks, and allows unlimited
+ * expansion.
+ * \param jcp Pointer to jcntl instance. This is used to find the file path and base filename so that
+ * new files may be created.
+ * \param fp Pointer to function which creates and returns a pointer to a new fcntl object (and hence
+ * causes a new %journal file to be created).
+ */
+ void initialize(const u_int16_t num_jfiles,
+ const bool ae,
+ const u_int16_t ae_max_jfiles,
+ jcntl* const jcp,
+ new_obj_fn_ptr fp);
+
+ /**
+ * \brief Initialize from a known lfid-pfid map pfid_list (within rcvdat param rd), which is usually obtained
+ * from a recover. The index of pfid_list is the logical file id (lfid); the value contained in the vector is
+ * the physical file id (pfid).
+ *
+ * \param rd Ref to rcvdat struct which contains recovery data and the pfid_list.
+ * \param jcp Pointer to jcntl instance. This is used to find the file path and base filename so that
+ * new files may be created.
+ * \param fp Pointer to function which creates and returns a pointer to a new fcntl object (and hence
+ * causes a new %journal file to be created).
+ */
+ void recover(const rcvdat& rd,
+ jcntl* const jcp,
+ new_obj_fn_ptr fp);
+
+ /**
+ * \brief Insert num_jfiles files after lfid index after_lfid. This causes all lfids after after_lfid to be
+ * increased by num_jfiles.
+ *
+ * Note that it is not possible to insert <i>before</i> lfid 0, and thus lfid 0 should always point to pfid 0.
+ * Inserting before lfid 0 is logically equivilent to inserting after the last lfid in a circular buffer.
+ *
+ * \param after_lfid Lid index after which to insert file(s).
+ * \param jcp Pointer to jcntl instance. This is used to find the file path and base filename so that
+ * new files may be created.
+ * \param fp Pointer to function which creates and returns a pointer to a new fcntl object (and hence
+ * causes a new %journal file to be created).
+ * \param num_jfiles The number of files by which to increase.
+ */
+ void insert(const u_int16_t after_lfid,
+ jcntl* const jcp,
+ new_obj_fn_ptr fp,
+ const u_int16_t num_jfiles = 1);
+
+ /**
+ * \brief Clears _fcntl_arr and deletes all fcntl instances.
+ */
+ void finalize();
+
+ /**
+ * \brief Returns true if initialized; false otherwise. After construction, will return false until initialize()
+ * is called; thereafter true until finalize() is called, whereupon it will return false again.
+ *
+ * \return True if initialized; false otherwise.
+ */
+ inline bool is_init() const { return _fcntl_arr.size() > 0; }
+
+ /**
+ * \brief Returns true if auto-expand mode is enabled; false if not.
+ *
+ * \return True if auto-expand mode is enabled; false if not.
+ */
+ inline bool is_ae() const { return _ae; }
+
+ /**
+ * \brief Sets the auto-expand mode to enabled if ae is true, to disabled otherwise. The value of _ae_max_jfiles
+ * must be valid to succeed (i.e. _ae_max_jfiles must be greater than the current number of files or be zero).
+ *
+ * \param ae If true will enable auto-expand mode; if false will disable it.
+ */
+ void set_ae(const bool ae);
+
+ /**
+ * \brief Returns the number of %journal files, including any that were appended or inserted since
+ * initialization.
+ *
+ * \return Number of %journal files if initialized; 0 otherwise.
+ */
+ inline u_int16_t num_jfiles() const { return static_cast<u_int16_t>(_fcntl_arr.size()); }
+
+ /**
+ * \brief Returns the maximum number of files allowed for auto-expansion.
+ *
+ * \return Maximum number of files allowed for auto-expansion. A zero value represents a disabled limit
+ * - i.e. unlimited expansion.
+ */
+ inline u_int16_t ae_max_jfiles() const { return _ae_max_jfiles; }
+
+ /**
+ * \brief Sets the maximum number of files allowed for auto-expansion. A zero value disables the limit.
+ *
+ * \param ae_max_jfiles The maximum number of files allowed for auto-expansion. Cannot be lower than the current
+ * number of files. However, a zero value disables the limit checks, and allows unlimited
+ * expansion.
+ */
+ void set_ae_max_jfiles(const u_int16_t ae_max_jfiles);
+
+ /**
+ * \brief Calculates the number of future files available for auto-expansion.
+ *
+ * \return The number of future files available for auto-expansion.
+ */
+ u_int16_t ae_jfiles_rem() const;
+
+ /**
+ * \brief Get a pointer to fcntl instance for a given lfid.
+ *
+ * \return Pointer to fcntl object corresponding to logical file id lfid, or 0 if lfid is out of range
+ * (greater than number of files in use).
+ */
+ inline fcntl* get_fcntlp(const u_int16_t lfid) const
+ { if (lfid >= _fcntl_arr.size()) return 0; return _fcntl_arr[lfid]; }
+
+ // Testing functions
+ void get_pfid_list(std::vector<u_int16_t>& pfid_list) const;
+ void get_lfid_list(std::vector<u_int16_t>& lfid_list) const;
+
+ protected:
+
+ /**
+ * \brief Append num_jfiles files to the end of the logical and file id sequence. This is similar to extending
+ * the from-scratch initialization.
+ *
+ * \param jcp Pointer to jcntl instance. This is used to find the file path and base filename so that
+ * new files may be created.
+ * \param fp Pointer to function which creates and returns a pointer to a new fcntl object (and hence
+ * causes a new %journal file to be created).
+ * \param num_jfiles The number of files by which to increase.
+ */
+ void append(jcntl* const jcp,
+ new_obj_fn_ptr fp,
+ const u_int16_t num_jfiles = 1);
+
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_LPMGR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/pmgr.cpp b/cpp/src/qpid/legacystore/jrnl/pmgr.cpp
new file mode 100644
index 0000000000..3dc61e2661
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/pmgr.cpp
@@ -0,0 +1,215 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file pmgr.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::pmgr (page manager). See
+ * comments in file pmgr.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/pmgr.h"
+
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include "qpid/legacystore/jrnl/jcfg.h"
+#include "qpid/legacystore/jrnl/jcntl.h"
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include <sstream>
+
+
+namespace mrg
+{
+namespace journal
+{
+
+pmgr::page_cb::page_cb(u_int16_t index):
+ _index(index),
+ _state(UNUSED),
+ _wdblks(0),
+ _rdblks(0),
+ _pdtokl(0),
+ _wfh(0),
+ _rfh(0),
+ _pbuff(0)
+{}
+
+const char*
+pmgr::page_cb::state_str() const
+{
+ switch(_state)
+ {
+ case UNUSED:
+ return "UNUSED";
+ case IN_USE:
+ return "IN_USE";
+ case AIO_PENDING:
+ return "AIO_PENDING";
+ case AIO_COMPLETE:
+ return "AIO_COMPLETE";
+ }
+ return "<unknown>";
+}
+
+const u_int32_t pmgr::_sblksize = JRNL_SBLK_SIZE * JRNL_DBLK_SIZE;
+
+pmgr::pmgr(jcntl* jc, enq_map& emap, txn_map& tmap):
+ _cache_pgsize_sblks(0),
+ _cache_num_pages(0),
+ _jc(jc),
+ _emap(emap),
+ _tmap(tmap),
+ _page_base_ptr(0),
+ _page_ptr_arr(0),
+ _page_cb_arr(0),
+ _aio_cb_arr(0),
+ _aio_event_arr(0),
+ _ioctx(0),
+ _pg_index(0),
+ _pg_cntr(0),
+ _pg_offset_dblks(0),
+ _aio_evt_rem(0),
+ _cbp(0),
+ _enq_rec(),
+ _deq_rec(),
+ _txn_rec()
+{}
+
+pmgr::~pmgr()
+{
+ pmgr::clean();
+}
+
+void
+pmgr::initialize(aio_callback* const cbp, const u_int32_t cache_pgsize_sblks, const u_int16_t cache_num_pages)
+{
+ // As static use of this class keeps old values around, clean up first...
+ pmgr::clean();
+ _pg_index = 0;
+ _pg_cntr = 0;
+ _pg_offset_dblks = 0;
+ _aio_evt_rem = 0;
+ _cache_pgsize_sblks = cache_pgsize_sblks;
+ _cache_num_pages = cache_num_pages;
+ _cbp = cbp;
+
+ // 1. Allocate page memory (as a single block)
+ std::size_t cache_pgsize = _cache_num_pages * _cache_pgsize_sblks * _sblksize;
+ if (::posix_memalign(&_page_base_ptr, _sblksize, cache_pgsize))
+ {
+ clean();
+ std::ostringstream oss;
+ oss << "posix_memalign(): blksize=" << _sblksize << " size=" << cache_pgsize;
+ oss << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), "pmgr", "initialize");
+ }
+ // 2. Allocate array of page pointers
+ _page_ptr_arr = (void**)std::malloc(_cache_num_pages * sizeof(void*));
+ MALLOC_CHK(_page_ptr_arr, "_page_ptr_arr", "pmgr", "initialize");
+
+ // 3. Allocate and initilaize page control block (page_cb) array
+ _page_cb_arr = (page_cb*)std::malloc(_cache_num_pages * sizeof(page_cb));
+ MALLOC_CHK(_page_cb_arr, "_page_cb_arr", "pmgr", "initialize");
+ std::memset(_page_cb_arr, 0, _cache_num_pages * sizeof(page_cb));
+
+ // 5. Allocate IO control block (iocb) array
+ _aio_cb_arr = (aio_cb*)std::malloc(_cache_num_pages * sizeof(aio_cb));
+ MALLOC_CHK(_aio_cb_arr, "_aio_cb_arr", "pmgr", "initialize");
+
+ // 6. Set page pointers in _page_ptr_arr, _page_cb_arr and iocbs to pages within page block
+ for (u_int16_t i=0; i<_cache_num_pages; i++)
+ {
+ _page_ptr_arr[i] = (void*)((char*)_page_base_ptr + _cache_pgsize_sblks * _sblksize * i);
+ _page_cb_arr[i]._index = i;
+ _page_cb_arr[i]._state = UNUSED;
+ _page_cb_arr[i]._pbuff = _page_ptr_arr[i];
+ _page_cb_arr[i]._pdtokl = new std::deque<data_tok*>;
+ _page_cb_arr[i]._pdtokl->clear();
+ _aio_cb_arr[i].data = (void*)&_page_cb_arr[i];
+ }
+
+ // 7. Allocate io_event array, max one event per cache page plus one for each file
+ const u_int16_t max_aio_evts = _cache_num_pages + _jc->num_jfiles();
+ _aio_event_arr = (aio_event*)std::malloc(max_aio_evts * sizeof(aio_event));
+ MALLOC_CHK(_aio_event_arr, "_aio_event_arr", "pmgr", "initialize");
+
+ // 8. Initialize AIO context
+ if (int ret = aio::queue_init(max_aio_evts, &_ioctx))
+ {
+ std::ostringstream oss;
+ oss << "io_queue_init() failed: " << FORMAT_SYSERR(-ret);
+ throw jexception(jerrno::JERR__AIO, oss.str(), "pmgr", "initialize");
+ }
+}
+
+void
+pmgr::clean()
+{
+ // clean up allocated memory here
+
+ if (_ioctx)
+ aio::queue_release(_ioctx);
+
+ std::free(_page_base_ptr);
+ _page_base_ptr = 0;
+
+ if (_page_cb_arr)
+ {
+ for (int i=0; i<_cache_num_pages; i++)
+ delete _page_cb_arr[i]._pdtokl;
+ std::free(_page_ptr_arr);
+ _page_ptr_arr = 0;
+ }
+
+ std::free(_page_cb_arr);
+ _page_cb_arr = 0;
+
+ std::free(_aio_cb_arr);
+ _aio_cb_arr = 0;
+
+ std::free(_aio_event_arr);
+ _aio_event_arr = 0;
+}
+
+const char*
+pmgr::page_state_str(page_state ps)
+{
+ switch (ps)
+ {
+ case UNUSED:
+ return "UNUSED";
+ case IN_USE:
+ return "IN_USE";
+ case AIO_PENDING:
+ return "AIO_PENDING";
+ case AIO_COMPLETE:
+ return "AIO_COMPLETE";
+ }
+ return "<page_state unknown>";
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/pmgr.h b/cpp/src/qpid/legacystore/jrnl/pmgr.h
new file mode 100644
index 0000000000..64115e225e
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/pmgr.h
@@ -0,0 +1,142 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file pmgr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::pmgr (page manager). See
+ * class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_PMGR_H
+#define QPID_LEGACYSTORE_JRNL_PMGR_H
+
+namespace mrg
+{
+namespace journal
+{
+ class pmgr;
+ class jcntl;
+}
+}
+
+#include <deque>
+#include "qpid/legacystore/jrnl/aio.h"
+#include "qpid/legacystore/jrnl/aio_callback.h"
+#include "qpid/legacystore/jrnl/data_tok.h"
+#include "qpid/legacystore/jrnl/deq_rec.h"
+#include "qpid/legacystore/jrnl/enq_map.h"
+#include "qpid/legacystore/jrnl/enq_rec.h"
+#include "qpid/legacystore/jrnl/fcntl.h"
+#include "qpid/legacystore/jrnl/txn_map.h"
+#include "qpid/legacystore/jrnl/txn_rec.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \brief Abstract class for managing either read or write page cache of arbitrary size and
+ * number of cache_num_pages.
+ */
+ class pmgr
+ {
+ public:
+ /**
+ * \brief Enumeration of possible stats of a page within a page cache.
+ */
+ enum page_state
+ {
+ UNUSED, ///< A page is uninitialized, contains no data.
+ IN_USE, ///< Page is in use.
+ AIO_PENDING, ///< An AIO request outstanding.
+ AIO_COMPLETE ///< An AIO request is complete.
+ };
+
+ protected:
+ /**
+ * \brief Page control block, carries control and state information for each page in the
+ * cache.
+ */
+ struct page_cb
+ {
+ u_int16_t _index; ///< Index of this page
+ page_state _state; ///< Status of page
+ u_int64_t _frid; ///< First rid in page (used for fhdr init)
+ u_int32_t _wdblks; ///< Total number of dblks in page so far
+ u_int32_t _rdblks; ///< Total number of dblks in page
+ std::deque<data_tok*>* _pdtokl; ///< Page message tokens list
+ fcntl* _wfh; ///< File handle for incrementing write compl counts
+ fcntl* _rfh; ///< File handle for incrementing read compl counts
+ void* _pbuff; ///< Page buffer
+
+ page_cb(u_int16_t index); ///< Convenience constructor
+ const char* state_str() const; ///< Return state as string for this pcb
+ };
+
+ static const u_int32_t _sblksize; ///< Disk softblock size
+ u_int32_t _cache_pgsize_sblks; ///< Size of page cache cache_num_pages
+ u_int16_t _cache_num_pages; ///< Number of page cache cache_num_pages
+ jcntl* _jc; ///< Pointer to journal controller
+ enq_map& _emap; ///< Ref to enqueue map
+ txn_map& _tmap; ///< Ref to transaction map
+ void* _page_base_ptr; ///< Base pointer to page memory
+ void** _page_ptr_arr; ///< Array of pointers to cache_num_pages in page memory
+ page_cb* _page_cb_arr; ///< Array of page_cb structs
+ aio_cb* _aio_cb_arr; ///< Array of iocb structs
+ aio_event* _aio_event_arr; ///< Array of io_events
+ io_context_t _ioctx; ///< AIO context for read/write operations
+ u_int16_t _pg_index; ///< Index of current page being used
+ u_int32_t _pg_cntr; ///< Page counter; determines if file rotation req'd
+ u_int32_t _pg_offset_dblks; ///< Page offset (used so far) in data blocks
+ u_int32_t _aio_evt_rem; ///< Remaining AIO events
+ aio_callback* _cbp; ///< Pointer to callback object
+
+ enq_rec _enq_rec; ///< Enqueue record used for encoding/decoding
+ deq_rec _deq_rec; ///< Dequeue record used for encoding/decoding
+ txn_rec _txn_rec; ///< Transaction record used for encoding/decoding
+
+ public:
+ pmgr(jcntl* jc, enq_map& emap, txn_map& tmap);
+ virtual ~pmgr();
+
+ virtual int32_t get_events(page_state state, timespec* const timeout, bool flush = false) = 0;
+ inline u_int32_t get_aio_evt_rem() const { return _aio_evt_rem; }
+ static const char* page_state_str(page_state ps);
+ inline u_int32_t cache_pgsize_sblks() const { return _cache_pgsize_sblks; }
+ inline u_int16_t cache_num_pages() const { return _cache_num_pages; }
+
+ protected:
+ virtual void initialize(aio_callback* const cbp, const u_int32_t cache_pgsize_sblks,
+ const u_int16_t cache_num_pages);
+ virtual void rotate_page() = 0;
+ virtual void clean();
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_PMGR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/rcvdat.h b/cpp/src/qpid/legacystore/jrnl/rcvdat.h
new file mode 100644
index 0000000000..a7ef2341f0
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rcvdat.h
@@ -0,0 +1,181 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file rcvdat.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Contains structure for recovery status and offset data.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_RCVDAT_H
+#define QPID_LEGACYSTORE_JRNL_RCVDAT_H
+
+#include <cstddef>
+#include <iomanip>
+#include <map>
+#include "qpid/legacystore/jrnl/jcfg.h"
+#include <sstream>
+#include <sys/types.h>
+#include <vector>
+
+namespace mrg
+{
+namespace journal
+{
+
+ struct rcvdat
+ {
+ u_int16_t _njf; ///< Number of journal files
+ bool _ae; ///< Auto-expand mode
+ u_int16_t _aemjf; ///< Auto-expand mode max journal files
+ bool _owi; ///< Overwrite indicator
+ bool _frot; ///< First rotation flag
+ bool _jempty; ///< Journal data files empty
+ u_int16_t _ffid; ///< First file id
+ std::size_t _fro; ///< First record offset in ffid
+ u_int16_t _lfid; ///< Last file id
+ std::size_t _eo; ///< End offset (first byte past last record)
+ u_int64_t _h_rid; ///< Highest rid found
+ bool _lffull; ///< Last file is full
+ bool _jfull; ///< Journal is full
+ std::vector<u_int16_t> _fid_list; ///< Fid-lid mapping - list of fids in order of lid
+ std::vector<u_int32_t> _enq_cnt_list; ///< Number enqueued records found for each file
+
+ rcvdat():
+ _njf(0),
+ _ae(false),
+ _aemjf(0),
+ _owi(false),
+ _frot(false),
+ _jempty(true),
+ _ffid(0),
+ _fro(0),
+ _lfid(0),
+ _eo(0),
+ _h_rid(0),
+ _lffull(false),
+ _jfull(false),
+ _fid_list(),
+ _enq_cnt_list()
+ {}
+
+ void reset(const u_int16_t num_jfiles, const bool auto_expand, const u_int16_t ae_max_jfiles)
+ {
+ _njf = num_jfiles;
+ _ae = auto_expand;
+ _aemjf = ae_max_jfiles;
+ _owi = false;
+ _frot = false;
+ _jempty = true;
+ _ffid = 0;
+ _fro = 0;
+ _lfid = 0;
+ _eo = 0;
+ _h_rid = 0;
+ _lffull = false;
+ _jfull = false;
+ _fid_list.clear();
+ _enq_cnt_list.clear();
+ _enq_cnt_list.resize(num_jfiles, 0);
+ }
+
+ // Find first fid with enqueued records
+ u_int16_t ffid()
+ {
+ u_int16_t index = _ffid;
+ while (index != _lfid && _enq_cnt_list[index] == 0)
+ {
+ if (++index >= _njf)
+ index = 0;
+ }
+ return index;
+ }
+
+ std::string to_string(const std::string& jid)
+ {
+ std::ostringstream oss;
+ oss << "Recover file analysis (jid=\"" << jid << "\"):" << std::endl;
+ oss << " Number of journal files (_njf) = " << _njf << std::endl;
+ oss << " Auto-expand mode (_ae) = " << (_ae ? "TRUE" : "FALSE") << std::endl;
+ if (_ae) oss << " Auto-expand mode max journal files (_aemjf) = " << _aemjf << std::endl;
+ oss << " Overwrite indicator (_owi) = " << (_owi ? "TRUE" : "FALSE") << std::endl;
+ oss << " First rotation (_frot) = " << (_frot ? "TRUE" : "FALSE") << std::endl;
+ oss << " Journal empty (_jempty) = " << (_jempty ? "TRUE" : "FALSE") << std::endl;
+ oss << " First (earliest) fid (_ffid) = " << _ffid << std::endl;
+ oss << " First record offset in first fid (_fro) = 0x" << std::hex << _fro <<
+ std::dec << " (" << (_fro/JRNL_DBLK_SIZE) << " dblks)" << std::endl;
+ oss << " Last (most recent) fid (_lfid) = " << _lfid << std::endl;
+ oss << " End offset (_eo) = 0x" << std::hex << _eo << std::dec << " (" <<
+ (_eo/JRNL_DBLK_SIZE) << " dblks)" << std::endl;
+ oss << " Highest rid (_h_rid) = 0x" << std::hex << _h_rid << std::dec << std::endl;
+ oss << " Last file full (_lffull) = " << (_lffull ? "TRUE" : "FALSE") << std::endl;
+ oss << " Journal full (_jfull) = " << (_jfull ? "TRUE" : "FALSE") << std::endl;
+ oss << " Normalized fid list (_fid_list) = [";
+ for (std::vector<u_int16_t>::const_iterator i = _fid_list.begin(); i < _fid_list.end(); i++)
+ {
+ if (i != _fid_list.begin()) oss << ", ";
+ oss << *i;
+ }
+ oss << "]" << std::endl;
+ oss << " Enqueued records (txn & non-txn):" << std::endl;
+ for (unsigned i=0; i<_enq_cnt_list.size(); i++)
+ oss << " File " << std::setw(2) << i << ": " << _enq_cnt_list[i] <<
+ std::endl;
+ return oss.str();
+ }
+
+ std::string to_log(const std::string& jid)
+ {
+ std::ostringstream oss;
+ oss << "Recover file analysis (jid=\"" << jid << "\"):";
+ oss << " njf=" << _njf;
+ oss << " ae=" << (_owi ? "T" : "F");
+ oss << " aemjf=" << _aemjf;
+ oss << " owi=" << (_ae ? "T" : "F");
+ oss << " frot=" << (_frot ? "T" : "F");
+ oss << " jempty=" << (_jempty ? "T" : "F");
+ oss << " ffid=" << _ffid;
+ oss << " fro=0x" << std::hex << _fro << std::dec << " (" <<
+ (_fro/JRNL_DBLK_SIZE) << " dblks)";
+ oss << " lfid=" << _lfid;
+ oss << " eo=0x" << std::hex << _eo << std::dec << " (" <<
+ (_eo/JRNL_DBLK_SIZE) << " dblks)";
+ oss << " h_rid=0x" << std::hex << _h_rid << std::dec;
+ oss << " lffull=" << (_lffull ? "T" : "F");
+ oss << " jfull=" << (_jfull ? "T" : "F");
+ oss << " Enqueued records (txn & non-txn): [ ";
+ for (unsigned i=0; i<_enq_cnt_list.size(); i++)
+ {
+ if (i) oss << " ";
+ oss << "fid_" << std::setw(2) << std::setfill('0') << i << "=" << _enq_cnt_list[i];
+ }
+ oss << " ]";
+ return oss.str();
+ }
+ };
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_RCVDAT_H
diff --git a/cpp/src/qpid/legacystore/jrnl/rec_hdr.h b/cpp/src/qpid/legacystore/jrnl/rec_hdr.h
new file mode 100644
index 0000000000..ff6325a760
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rec_hdr.h
@@ -0,0 +1,143 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file rec_hdr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::rec_hdr (record header),
+ * which is a common initial header used for all journal record structures
+ * except the record tail (rec_tail).
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_REC_HDR_H
+#define QPID_LEGACYSTORE_JRNL_REC_HDR_H
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/jcfg.h"
+#include <sys/types.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for data common to the head of all journal files and records.
+ * This includes identification for the file type, the encoding version, endian
+ * indicator and a record ID.
+ *
+ * File header info in binary format (16 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+
+ * | magic | v | e | flags |
+ * +---+---+---+---+---+---+---+---+
+ * | rid |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct rec_hdr
+ {
+ u_int32_t _magic; ///< File type identifier (magic number)
+ u_int8_t _version; ///< File encoding version
+ u_int8_t _eflag; ///< Flag for determining endianness
+ u_int16_t _uflag; ///< User-defined flags
+ u_int64_t _rid; ///< Record ID (rotating 64-bit counter)
+
+ // Global flags
+ static const u_int16_t HDR_OVERWRITE_INDICATOR_MASK = 0x1;
+
+ // Convenience constructors and methods
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline rec_hdr(): _magic(0), _version(0), _eflag(0), _uflag(0), _rid(0) {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline rec_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const bool owi): _magic(magic), _version(version),
+#if defined(JRNL_BIG_ENDIAN)
+ _eflag(RHM_BENDIAN_FLAG),
+#else
+ _eflag(RHM_LENDIAN_FLAG),
+#endif
+ _uflag(owi ? HDR_OVERWRITE_INDICATOR_MASK : 0), _rid(rid) {}
+
+ /**
+ * \brief Convenience copy method.
+ */
+ inline void hdr_copy(const rec_hdr& h)
+ {
+ _magic = h._magic;
+ _version = h._version;
+ _eflag = h._eflag;
+ _uflag = h._uflag;
+ _rid =h._rid;
+ }
+
+ /**
+ * \brief Resets all fields to 0
+ */
+ inline void reset()
+ {
+ _magic = 0;
+ _version = 0;
+ _eflag = 0;
+ _uflag = 0;
+ _rid = 0;
+ }
+
+ inline bool get_owi() const { return _uflag & HDR_OVERWRITE_INDICATOR_MASK; }
+
+ inline void set_owi(const bool owi)
+ {
+ _uflag = owi ? _uflag | HDR_OVERWRITE_INDICATOR_MASK :
+ _uflag & (~HDR_OVERWRITE_INDICATOR_MASK);
+ }
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static std::size_t size() { return sizeof(rec_hdr); }
+ }; // struct rec_hdr
+
+#pragma pack()
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_REC_HDR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/rec_tail.h b/cpp/src/qpid/legacystore/jrnl/rec_tail.h
new file mode 100644
index 0000000000..0c36151927
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rec_tail.h
@@ -0,0 +1,98 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file rec_tail.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::rec_tail (record tail), used to
+ * finalize a persistent record. The presence of a valid tail at the expected
+ * position in the journal file indicates that the record write was completed.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_REC_TAIL_H
+#define QPID_LEGACYSTORE_JRNL_REC_TAIL_H
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/jcfg.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for data common to the tail of all records. The magic number
+ * used here is the binary inverse (1's complement) of the magic used in the
+ * record header; this minimizes possible confusion with other headers that may
+ * be present during recovery. The tail is used with all records that have either
+ * XIDs or data - ie any size-variable content. Currently the only records that
+ * do NOT use the tail are non-transactional dequeues and filler records.
+ *
+ * Record header info in binary format (12 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+
+ * | ~(magic) | rid |
+ * +---+---+---+---+---+---+---+---+
+ * | rid (con't) |
+ * +---+---+---+---+
+ * </pre>
+ */
+ struct rec_tail
+ {
+ u_int32_t _xmagic; ///< Binary inverse (1's complement) of hdr magic number
+ u_int64_t _rid; ///< ID (rotating 64-bit counter)
+
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ inline rec_tail(): _xmagic(0xffffffff), _rid(0) {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction from
+ * existing enq_hdr instance.
+ */
+ inline rec_tail(const rec_hdr& h): _xmagic(~h._magic), _rid(h._rid) {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ inline rec_tail(const u_int32_t xmagic, const u_int64_t rid): _xmagic(xmagic), _rid(rid) {}
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static std::size_t size() { return sizeof(rec_tail); }
+ };
+
+#pragma pack()
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_REC_TAIL_H
diff --git a/cpp/src/qpid/legacystore/jrnl/rfc.cpp b/cpp/src/qpid/legacystore/jrnl/rfc.cpp
new file mode 100644
index 0000000000..9b5ed95e81
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rfc.cpp
@@ -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.
+ *
+ */
+
+/**
+ * \file rfc.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::rfc (rotating
+ * file controller). See comments in file rfc.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/rfc.h"
+
+#include <cassert>
+
+namespace mrg
+{
+namespace journal
+{
+
+rfc::rfc(const lpmgr* lpmp): _lpmp(lpmp), _fc_index(0), _curr_fc(0)
+{}
+
+rfc::~rfc()
+{}
+
+void
+rfc::finalize()
+{
+ unset_findex();
+}
+
+void
+rfc::set_findex(const u_int16_t fc_index)
+{
+ _fc_index = fc_index;
+ _curr_fc = _lpmp->get_fcntlp(fc_index);
+ _curr_fc->rd_reset();
+}
+
+void
+rfc::unset_findex()
+{
+ _fc_index = 0;
+ _curr_fc = 0;
+}
+
+std::string
+rfc::status_str() const
+{
+ if (!_lpmp->is_init())
+ return "state: Uninitialized";
+ if (_curr_fc == 0)
+ return "state: Inactive";
+ std::ostringstream oss;
+ oss << "state: Active";
+ return oss.str();
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/rfc.h b/cpp/src/qpid/legacystore/jrnl/rfc.h
new file mode 100644
index 0000000000..faa5d566ba
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rfc.h
@@ -0,0 +1,193 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file rfc.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::rfc (rotating
+ * file controller). See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_RFC_H
+#define QPID_LEGACYSTORE_JRNL_RFC_H
+
+namespace mrg
+{
+namespace journal
+{
+class rfc;
+}
+}
+
+#include "qpid/legacystore/jrnl/lpmgr.h"
+#include "qpid/legacystore/jrnl/enums.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class rfc
+ * \brief Rotating File Controller (rfc) - Class to handle the manangement of an array of file controllers (fcntl)
+ * objects for use in a circular disk buffer (journal). Each fcntl object corresponds to a file in the journal.
+ *
+ * The following states exist in this class:
+ *
+ * <pre>
+ * is_init() is_active()
+ * +===+ _lpmp.is_init() == false
+ * +---------->| | Uninitialized: _curr_fc == 0 F F
+ * | +-->+===+ --+
+ * | | |
+ * | | |
+ * | finalize() initialize()
+ * | | |
+ * | | |
+ * | +-- +===+<--+ _lpmp.is_init() == true
+ * finalize() | | Inactive: _curr_fc == 0 T F
+ * | +-->+===+ --+
+ * | | |
+ * | | |
+ * | unset_findex() set_findex()
+ * | | |
+ * | | |
+ * | +-- +===+<--+ _lpmp.is_init() == true
+ * +---------- | | Active: _curr_fc != 0 T T
+ * +===+
+ * </pre>
+ *
+ * The Uninitialized state is where the class starts after construction. Once the number of files is known and
+ * the array of file controllers allocated, then initialize() is called to set these, causing the state to move
+ * to Inactive.
+ *
+ * The Inactive state has the file controllers allocated and pointing to their respective journal files, but no
+ * current file controller has been selected. The pointer to the current file controller _curr_fc is null. Once the
+ * index of the active file is known, then calling set_findex() will set the index and internal pointer
+ * to the currently active file controller. This moves the state to Active.
+ *
+ * Note TODO: Comment on sync issues between change in num files in _lpmp and _fc_index/_curr_fc.
+ */
+ class rfc
+ {
+ protected:
+ const lpmgr* _lpmp; ///< Pointer to jcntl's lpmgr instance containing lfid/pfid map and fcntl objects
+ u_int16_t _fc_index; ///< Index of current file controller
+ fcntl* _curr_fc; ///< Pointer to current file controller
+
+ public:
+ rfc(const lpmgr* lpmp);
+ virtual ~rfc();
+
+ /**
+ * \brief Initialize the controller, moving from state Uninitialized to Inactive. The main function of
+ * initialize() is to set the number of files and the pointer to the fcntl array.
+ */
+ virtual inline void initialize() {}
+
+ /**
+ * \brief Reset the controller to Uninitialized state, usually called when the journal is stopped. Once called,
+ * initialize() must be called to reuse an instance.
+ */
+ virtual void finalize();
+
+ /**
+ * \brief Check initialization state: true = Not Uninitialized, ie Initialized or Active; false = Uninitialized.
+ */
+ virtual inline bool is_init() const { return _lpmp->is_init(); }
+
+ /**
+ * \brief Check active state: true = Initialized and _curr_fc not null; false otherwise.
+ */
+ virtual inline bool is_active() const { return _lpmp->is_init() && _curr_fc != 0; }
+
+ /**
+ * \brief Sets the current file index and active fcntl object. Moves to state Active.
+ */
+ virtual void set_findex(const u_int16_t fc_index);
+
+ /**
+ * \brief Nulls the current file index and active fcntl pointer, moves to state Inactive.
+ */
+ virtual void unset_findex();
+
+ /**
+ * \brief Rotate active file controller to next file in rotating file group.
+ * \exception jerrno::JERR__NINIT if called before calling initialize().
+ */
+ virtual iores rotate() = 0;
+
+ /**
+ * \brief Returns the index of the currently active file within the rotating file group.
+ */
+ inline u_int16_t index() const { return _fc_index; }
+
+ /**
+ * \brief Returns the currently active journal file controller within the rotating file group.
+ */
+ inline fcntl* file_controller() const { return _curr_fc; }
+
+ /**
+ * \brief Returns the currently active physical file id (pfid)
+ */
+ inline u_int16_t pfid() const { return _curr_fc->pfid(); }
+
+ // Convenience access methods to current file controller
+ // Note: Do not call when not in active state
+
+ inline u_int32_t enqcnt() const { return _curr_fc->enqcnt(); }
+ inline u_int32_t incr_enqcnt() { return _curr_fc->incr_enqcnt(); }
+ inline u_int32_t incr_enqcnt(const u_int16_t fid) { return _lpmp->get_fcntlp(fid)->incr_enqcnt(); }
+ inline u_int32_t add_enqcnt(const u_int32_t a) { return _curr_fc->add_enqcnt(a); }
+ inline u_int32_t add_enqcnt(const u_int16_t fid, const u_int32_t a)
+ { return _lpmp->get_fcntlp(fid)->add_enqcnt(a); }
+ inline u_int32_t decr_enqcnt(const u_int16_t fid) { return _lpmp->get_fcntlp(fid)->decr_enqcnt(); }
+ inline u_int32_t subtr_enqcnt(const u_int16_t fid, const u_int32_t s)
+ { return _lpmp->get_fcntlp(fid)->subtr_enqcnt(s); }
+
+ virtual inline u_int32_t subm_cnt_dblks() const = 0;
+ virtual inline std::size_t subm_offs() const = 0;
+ virtual inline u_int32_t add_subm_cnt_dblks(u_int32_t a) = 0;
+
+ virtual inline u_int32_t cmpl_cnt_dblks() const = 0;
+ virtual inline std::size_t cmpl_offs() const = 0;
+ virtual inline u_int32_t add_cmpl_cnt_dblks(u_int32_t a) = 0;
+
+ virtual inline bool is_void() const = 0;
+ virtual inline bool is_empty() const = 0;
+ virtual inline u_int32_t remaining_dblks() const = 0;
+ virtual inline bool is_full() const = 0;
+ virtual inline bool is_compl() const = 0;
+ virtual inline u_int32_t aio_outstanding_dblks() const = 0;
+ virtual inline bool file_rotate() const = 0;
+
+ // Debug aid
+ virtual std::string status_str() const;
+ }; // class rfc
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_RFC_H
diff --git a/cpp/src/qpid/legacystore/jrnl/rmgr.cpp b/cpp/src/qpid/legacystore/jrnl/rmgr.cpp
new file mode 100644
index 0000000000..3a11817d1e
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rmgr.cpp
@@ -0,0 +1,698 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file rmgr.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::rmgr (read manager). See
+ * comments in file rmgr.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/rmgr.h"
+
+#include <cassert>
+#include <cerrno>
+#include <cstdlib>
+#include "qpid/legacystore/jrnl/jcntl.h"
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+rmgr::rmgr(jcntl* jc, enq_map& emap, txn_map& tmap, rrfc& rrfc):
+ pmgr(jc, emap, tmap),
+ _rrfc(rrfc),
+ _hdr(),
+ _fhdr_buffer(0),
+ _fhdr_aio_cb_ptr(0),
+ _fhdr_rd_outstanding(false)
+{}
+
+rmgr::~rmgr()
+{
+ rmgr::clean();
+}
+
+void
+rmgr::initialize(aio_callback* const cbp)
+{
+ pmgr::initialize(cbp, JRNL_RMGR_PAGE_SIZE, JRNL_RMGR_PAGES);
+ clean();
+ // Allocate memory for reading file header
+ if (::posix_memalign(&_fhdr_buffer, _sblksize, _sblksize))
+ {
+ std::ostringstream oss;
+ oss << "posix_memalign(): blksize=" << _sblksize << " size=" << _sblksize;
+ oss << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), "rmgr", "initialize");
+ }
+ _fhdr_aio_cb_ptr = new aio_cb;
+ std::memset(_fhdr_aio_cb_ptr, 0, sizeof(aio_cb*));
+}
+
+void
+rmgr::clean()
+{
+ std::free(_fhdr_buffer);
+ _fhdr_buffer = 0;
+
+ if (_fhdr_aio_cb_ptr)
+ {
+ delete _fhdr_aio_cb_ptr;
+ _fhdr_aio_cb_ptr = 0;
+ }
+}
+
+iores
+rmgr::read(void** const datapp, std::size_t& dsize, void** const xidpp, std::size_t& xidsize,
+ bool& transient, bool& external, data_tok* dtokp, bool ignore_pending_txns)
+{
+ iores res = pre_read_check(dtokp);
+ if (res != RHM_IORES_SUCCESS)
+ {
+ set_params_null(datapp, dsize, xidpp, xidsize);
+ return res;
+ }
+
+ if (dtokp->rstate() == data_tok::SKIP_PART)
+ {
+ if (_page_cb_arr[_pg_index]._state != AIO_COMPLETE)
+ {
+ aio_cycle(); // check if rd AIOs returned; initiate new reads if possible
+ return RHM_IORES_PAGE_AIOWAIT;
+ }
+ const iores res = skip(dtokp);
+ if (res != RHM_IORES_SUCCESS)
+ {
+ set_params_null(datapp, dsize, xidpp, xidsize);
+ return res;
+ }
+ }
+ if (dtokp->rstate() == data_tok::READ_PART)
+ {
+ assert(dtokp->rid() == _hdr._rid);
+ void* rptr = (void*)((char*)_page_ptr_arr[_pg_index] + (_pg_offset_dblks * JRNL_DBLK_SIZE));
+ const iores res = read_enq(_hdr, rptr, dtokp);
+ dsize = _enq_rec.get_data(datapp);
+ xidsize = _enq_rec.get_xid(xidpp);
+ transient = _enq_rec.is_transient();
+ external = _enq_rec.is_external();
+ return res;
+ }
+
+ set_params_null(datapp, dsize, xidpp, xidsize);
+ _hdr.reset();
+ // Read header, determine next record type
+ while (true)
+ {
+ if(dblks_rem() == 0 && _rrfc.is_compl() && !_rrfc.is_wr_aio_outstanding())
+ {
+ aio_cycle(); // check if rd AIOs returned; initiate new reads if possible
+ if(dblks_rem() == 0 && _rrfc.is_compl() && !_rrfc.is_wr_aio_outstanding())
+ {
+ if (_jc->unflushed_dblks() > 0)
+ _jc->flush();
+ else if (!_aio_evt_rem)
+ return RHM_IORES_EMPTY;
+ }
+ }
+ if (_page_cb_arr[_pg_index]._state != AIO_COMPLETE)
+ {
+ aio_cycle();
+ return RHM_IORES_PAGE_AIOWAIT;
+ }
+ void* rptr = (void*)((char*)_page_ptr_arr[_pg_index] + (_pg_offset_dblks * JRNL_DBLK_SIZE));
+ std::memcpy(&_hdr, rptr, sizeof(rec_hdr));
+ switch (_hdr._magic)
+ {
+ case RHM_JDAT_ENQ_MAGIC:
+ {
+ _enq_rec.reset(); // sets enqueue rec size
+ // Check if RID of this rec is still enqueued, if so read it, else skip
+ bool is_enq = false;
+ int16_t fid = _emap.get_pfid(_hdr._rid);
+ if (fid < enq_map::EMAP_OK)
+ {
+ bool enforce_txns = !_jc->is_read_only() && !ignore_pending_txns;
+ // Block read for transactionally locked record (only when not recovering)
+ if (fid == enq_map::EMAP_LOCKED && enforce_txns)
+ return RHM_IORES_TXPENDING;
+
+ // (Recover mode only) Ok, not in emap - now search tmap, if present then read
+ is_enq = _tmap.is_enq(_hdr._rid);
+ if (enforce_txns && is_enq)
+ return RHM_IORES_TXPENDING;
+ }
+ else
+ is_enq = true;
+
+ if (is_enq) // ok, this record is enqueued, check it, then read it...
+ {
+ if (dtokp->rid())
+ {
+ if (_hdr._rid != dtokp->rid())
+ {
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << _hdr._rid << "; dtok_rid=0x" << dtokp->rid()
+ << "; dtok_id=0x" << dtokp->id();
+ throw jexception(jerrno::JERR_RMGR_RIDMISMATCH, oss.str(), "rmgr", "read");
+ }
+ }
+ else
+ dtokp->set_rid(_hdr._rid);
+
+// TODO: Add member _fid to pmgr::page_cb which indicates the fid from which this page was
+// populated. When this value is set in wmgr::flush() somewehere, then uncomment the following
+// check:
+// if (fid != _page_cb_arr[_pg_index]._fid)
+// {
+// std::ostringstream oss;
+// oss << std::hex << std::setfill('0');
+// oss << "rid=0x" << std::setw(16) << _hdr._rid;
+// oss << "; emap_fid=0x" << std::setw(4) << fid;
+// oss << "; current_fid=" << _rrfc.fid();
+// throw jexception(jerrno::JERR_RMGR_FIDMISMATCH, oss.str(), "rmgr",
+// "read");
+// }
+
+ const iores res = read_enq(_hdr, rptr, dtokp);
+ dsize = _enq_rec.get_data(datapp);
+ xidsize = _enq_rec.get_xid(xidpp);
+ transient = _enq_rec.is_transient();
+ external = _enq_rec.is_external();
+ return res;
+ }
+ else // skip this record, it is already dequeued
+ consume_xid_rec(_hdr, rptr, dtokp);
+ break;
+ }
+ case RHM_JDAT_DEQ_MAGIC:
+ consume_xid_rec(_hdr, rptr, dtokp);
+ break;
+ case RHM_JDAT_TXA_MAGIC:
+ consume_xid_rec(_hdr, rptr, dtokp);
+ break;
+ case RHM_JDAT_TXC_MAGIC:
+ consume_xid_rec(_hdr, rptr, dtokp);
+ break;
+ case RHM_JDAT_EMPTY_MAGIC:
+ consume_filler();
+ break;
+ default:
+ return RHM_IORES_EMPTY;
+ }
+ }
+}
+
+int32_t
+rmgr::get_events(page_state state, timespec* const timeout, bool flush)
+{
+ if (_aio_evt_rem == 0) // no events to get
+ return 0;
+
+ int32_t ret;
+ if ((ret = aio::getevents(_ioctx, flush ? _aio_evt_rem : 1, _aio_evt_rem/*_cache_num_pages + _jc->num_jfiles()*/, _aio_event_arr, timeout)) < 0)
+ {
+ if (ret == -EINTR) // Interrupted by signal
+ return 0;
+ std::ostringstream oss;
+ oss << "io_getevents() failed: " << std::strerror(-ret) << " (" << ret << ")";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "rmgr", "get_events");
+ }
+ if (ret == 0 && timeout)
+ return jerrno::AIO_TIMEOUT;
+
+ std::vector<u_int16_t> pil;
+ pil.reserve(ret);
+ for (int i=0; i<ret; i++) // Index of returned AIOs
+ {
+ if (_aio_evt_rem == 0)
+ {
+ std::ostringstream oss;
+ oss << "_aio_evt_rem; evt " << (i + 1) << " of " << ret;
+ throw jexception(jerrno::JERR__UNDERFLOW, oss.str(), "rmgr", "get_events");
+ }
+ _aio_evt_rem--;
+ aio_cb* aiocbp = _aio_event_arr[i].obj; // This I/O control block (iocb)
+ page_cb* pcbp = (page_cb*)(aiocbp->data); // This page control block (pcb)
+ long aioret = (long)_aio_event_arr[i].res;
+ if (aioret < 0)
+ {
+ std::ostringstream oss;
+ oss << "AIO read operation failed: " << std::strerror(-aioret) << " (" << aioret << ")";
+ oss << " [pg=" << pcbp->_index << " buf=" << aiocbp->u.c.buf;
+ oss << " rsize=0x" << std::hex << aiocbp->u.c.nbytes;
+ oss << " offset=0x" << aiocbp->u.c.offset << std::dec;
+ oss << " fh=" << aiocbp->aio_fildes << "]";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "rmgr", "get_events");
+ }
+
+ if (pcbp) // Page reads have pcb
+ {
+ if (pcbp->_rfh->rd_subm_cnt_dblks() >= JRNL_SBLK_SIZE) // Detects if write reset of this fcntl obj has occurred.
+ {
+ // Increment the completed read offset
+ // NOTE: We cannot use _rrfc here, as it may have rotated since submitting count.
+ // Use stored pointer to fcntl in the pcb instead.
+ pcbp->_rdblks = aiocbp->u.c.nbytes / JRNL_DBLK_SIZE;
+ pcbp->_rfh->add_rd_cmpl_cnt_dblks(pcbp->_rdblks);
+ pcbp->_state = state;
+ pil[i] = pcbp->_index;
+ }
+ }
+ else // File header reads have no pcb
+ {
+ std::memcpy(&_fhdr, _fhdr_buffer, sizeof(file_hdr));
+ _rrfc.add_cmpl_cnt_dblks(JRNL_SBLK_SIZE);
+
+ u_int32_t fro_dblks = (_fhdr._fro / JRNL_DBLK_SIZE) - JRNL_SBLK_SIZE;
+ // Check fro_dblks does not exceed the write pointers which can happen in some corrupted journal recoveries
+ if (fro_dblks > _jc->wr_subm_cnt_dblks(_fhdr._pfid) - JRNL_SBLK_SIZE)
+ fro_dblks = _jc->wr_subm_cnt_dblks(_fhdr._pfid) - JRNL_SBLK_SIZE;
+ _pg_cntr = fro_dblks / (JRNL_RMGR_PAGE_SIZE * JRNL_SBLK_SIZE);
+ u_int32_t tot_pg_offs_dblks = _pg_cntr * JRNL_RMGR_PAGE_SIZE * JRNL_SBLK_SIZE;
+ _pg_index = _pg_cntr % JRNL_RMGR_PAGES;
+ _pg_offset_dblks = fro_dblks - tot_pg_offs_dblks;
+ _rrfc.add_subm_cnt_dblks(tot_pg_offs_dblks);
+ _rrfc.add_cmpl_cnt_dblks(tot_pg_offs_dblks);
+
+ _fhdr_rd_outstanding = false;
+ _rrfc.set_valid();
+ }
+ }
+
+ // Perform AIO return callback
+ if (_cbp && ret)
+ _cbp->rd_aio_cb(pil);
+ return ret;
+}
+
+void
+rmgr::recover_complete()
+{}
+
+void
+rmgr::invalidate()
+{
+ if (_rrfc.is_valid())
+ _rrfc.set_invalid();
+}
+
+void
+rmgr::flush(timespec* timeout)
+{
+ // Wait for any outstanding AIO read operations to complete before synchronizing
+ while (_aio_evt_rem)
+ {
+ if (get_events(AIO_COMPLETE, timeout) == jerrno::AIO_TIMEOUT) // timed out, nothing returned
+ {
+ throw jexception(jerrno::JERR__TIMEOUT,
+ "Timed out waiting for outstanding read aio to return", "rmgr", "init_validation");
+ }
+ }
+
+ // Reset all read states and pointers
+ for (int i=0; i<_cache_num_pages; i++)
+ _page_cb_arr[i]._state = UNUSED;
+ _rrfc.unset_findex();
+ _pg_index = 0;
+ _pg_offset_dblks = 0;
+}
+
+bool
+rmgr::wait_for_validity(timespec* timeout, const bool throw_on_timeout)
+{
+ bool timed_out = false;
+ while (!_rrfc.is_valid() && !timed_out)
+ {
+ timed_out = get_events(AIO_COMPLETE, timeout) == jerrno::AIO_TIMEOUT;
+ if (timed_out && throw_on_timeout)
+ throw jexception(jerrno::JERR__TIMEOUT, "Timed out waiting for read validity", "rmgr", "wait_for_validity");
+ }
+ return _rrfc.is_valid();
+}
+
+iores
+rmgr::pre_read_check(data_tok* dtokp)
+{
+ if (_aio_evt_rem)
+ get_events(AIO_COMPLETE, 0);
+
+ if (!_rrfc.is_valid())
+ return RHM_IORES_RCINVALID;
+
+ // block reads until outstanding file header read completes as fro is needed to read
+ if (_fhdr_rd_outstanding)
+ return RHM_IORES_PAGE_AIOWAIT;
+
+ if(dblks_rem() == 0 && _rrfc.is_compl() && !_rrfc.is_wr_aio_outstanding())
+ {
+ aio_cycle(); // check if any AIOs have returned
+ if(dblks_rem() == 0 && _rrfc.is_compl() && !_rrfc.is_wr_aio_outstanding())
+ {
+ if (_jc->unflushed_dblks() > 0)
+ _jc->flush();
+ else if (!_aio_evt_rem)
+ return RHM_IORES_EMPTY;
+ }
+ }
+
+ // Check write state of this token is ENQ - required for read
+ if (dtokp)
+ {
+ if (!dtokp->is_readable())
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "dtok_id=0x" << std::setw(8) << dtokp->id();
+ oss << "; dtok_rid=0x" << std::setw(16) << dtokp->rid();
+ oss << "; dtok_wstate=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_RMGR_ENQSTATE, oss.str(), "rmgr", "pre_read_check");
+ }
+ }
+
+ return RHM_IORES_SUCCESS;
+}
+
+iores
+rmgr::read_enq(rec_hdr& h, void* rptr, data_tok* dtokp)
+{
+ if (_page_cb_arr[_pg_index]._state != AIO_COMPLETE)
+ {
+ aio_cycle(); // check if any AIOs have returned
+ return RHM_IORES_PAGE_AIOWAIT;
+ }
+
+ // Read data from this page, first block will have header and data size.
+ u_int32_t dblks_rd = _enq_rec.decode(h, rptr, dtokp->dblocks_read(), dblks_rem());
+ dtokp->incr_dblocks_read(dblks_rd);
+
+ _pg_offset_dblks += dblks_rd;
+
+ // If data still incomplete, move to next page and decode again
+ while (dtokp->dblocks_read() < _enq_rec.rec_size_dblks())
+ {
+ rotate_page();
+ if (_page_cb_arr[_pg_index]._state != AIO_COMPLETE)
+ {
+ dtokp->set_rstate(data_tok::READ_PART);
+ dtokp->set_dsize(_enq_rec.data_size());
+ return RHM_IORES_PAGE_AIOWAIT;
+ }
+
+ rptr = (void*)((char*)_page_ptr_arr[_pg_index]);
+ dblks_rd = _enq_rec.decode(h, rptr, dtokp->dblocks_read(), dblks_rem());
+ dtokp->incr_dblocks_read(dblks_rd);
+ _pg_offset_dblks += dblks_rd;
+ }
+
+ // If we have finished with this page, rotate it
+ if (dblks_rem() == 0)
+ rotate_page();
+
+ // Set the record size in dtokp
+ dtokp->set_rstate(data_tok::READ);
+ dtokp->set_dsize(_enq_rec.data_size());
+ return RHM_IORES_SUCCESS;
+}
+
+void
+rmgr::consume_xid_rec(rec_hdr& h, void* rptr, data_tok* dtokp)
+{
+ if (h._magic == RHM_JDAT_ENQ_MAGIC)
+ {
+ enq_hdr ehdr;
+ std::memcpy(&ehdr, rptr, sizeof(enq_hdr));
+ if (ehdr.is_external())
+ dtokp->set_dsize(ehdr._xidsize + sizeof(enq_hdr) + sizeof(rec_tail));
+ else
+ dtokp->set_dsize(ehdr._xidsize + ehdr._dsize + sizeof(enq_hdr) + sizeof(rec_tail));
+ }
+ else if (h._magic == RHM_JDAT_DEQ_MAGIC)
+ {
+ deq_hdr dhdr;
+ std::memcpy(&dhdr, rptr, sizeof(deq_hdr));
+ if (dhdr._xidsize)
+ dtokp->set_dsize(dhdr._xidsize + sizeof(deq_hdr) + sizeof(rec_tail));
+ else
+ dtokp->set_dsize(sizeof(deq_hdr));
+ }
+ else if (h._magic == RHM_JDAT_TXA_MAGIC || h._magic == RHM_JDAT_TXC_MAGIC)
+ {
+ txn_hdr thdr;
+ std::memcpy(&thdr, rptr, sizeof(txn_hdr));
+ dtokp->set_dsize(thdr._xidsize + sizeof(txn_hdr) + sizeof(rec_tail));
+ }
+ else
+ {
+ std::ostringstream oss;
+ oss << "Record type found = \"" << (char*)&h._magic << "\"";
+ throw jexception(jerrno::JERR_RMGR_BADRECTYPE, oss.str(), "rmgr", "consume_xid_rec");
+ }
+ dtokp->set_dblocks_read(0);
+ skip(dtokp);
+}
+
+void
+rmgr::consume_filler()
+{
+ // Filler (Magic "RHMx") is one dblk by definition
+ _pg_offset_dblks++;
+ if (dblks_rem() == 0)
+ rotate_page();
+}
+
+iores
+rmgr::skip(data_tok* dtokp)
+{
+ u_int32_t dsize_dblks = jrec::size_dblks(dtokp->dsize());
+ u_int32_t tot_dblk_cnt = dtokp->dblocks_read();
+ while (true)
+ {
+ u_int32_t this_dblk_cnt = 0;
+ if (dsize_dblks - tot_dblk_cnt > dblks_rem())
+ this_dblk_cnt = dblks_rem();
+ else
+ this_dblk_cnt = dsize_dblks - tot_dblk_cnt;
+ if (this_dblk_cnt)
+ {
+ dtokp->incr_dblocks_read(this_dblk_cnt);
+ _pg_offset_dblks += this_dblk_cnt;
+ tot_dblk_cnt += this_dblk_cnt;
+ }
+ // If skip still incomplete, move to next page and decode again
+ if (tot_dblk_cnt < dsize_dblks)
+ {
+ if (dblks_rem() == 0)
+ rotate_page();
+ if (_page_cb_arr[_pg_index]._state != AIO_COMPLETE)
+ {
+ dtokp->set_rstate(data_tok::SKIP_PART);
+ return RHM_IORES_PAGE_AIOWAIT;
+ }
+ }
+ else
+ {
+ // Skip complete, put state back to unread
+ dtokp->set_rstate(data_tok::UNREAD);
+ dtokp->set_dsize(0);
+ dtokp->set_dblocks_read(0);
+
+ // If we have finished with this page, rotate it
+ if (dblks_rem() == 0)
+ rotate_page();
+ return RHM_IORES_SUCCESS;
+ }
+ }
+}
+
+iores
+rmgr::aio_cycle()
+{
+ // Perform validity checks
+ if (_fhdr_rd_outstanding) // read of file header still outstanding in aio
+ return RHM_IORES_SUCCESS;
+ if (!_rrfc.is_valid())
+ {
+ // Flush and reset all read states and pointers
+ flush(&jcntl::_aio_cmpl_timeout);
+
+ _jc->get_earliest_fid(); // determine initial file to read; calls _rrfc.set_findex() to set value
+ // If this file has not yet been written to, return RHM_IORES_EMPTY
+ if (_rrfc.is_void() && !_rrfc.is_wr_aio_outstanding())
+ return RHM_IORES_EMPTY;
+ init_file_header_read(); // send off AIO read request for file header
+ return RHM_IORES_SUCCESS;
+ }
+
+ int16_t first_uninit = -1;
+ u_int16_t num_uninit = 0;
+ u_int16_t num_compl = 0;
+ bool outstanding = false;
+ // Index must start with current buffer and cycle around so that first
+ // uninitialized buffer is initialized first
+ for (u_int16_t i=_pg_index; i<_pg_index+_cache_num_pages; i++)
+ {
+ int16_t ci = i % _cache_num_pages;
+ switch (_page_cb_arr[ci]._state)
+ {
+ case UNUSED:
+ if (first_uninit < 0)
+ first_uninit = ci;
+ num_uninit++;
+ break;
+ case IN_USE:
+ break;
+ case AIO_PENDING:
+ outstanding = true;
+ break;
+ case AIO_COMPLETE:
+ num_compl++;
+ break;
+ default:;
+ }
+ }
+ iores res = RHM_IORES_SUCCESS;
+ if (num_uninit)
+ res = init_aio_reads(first_uninit, num_uninit);
+ else if (num_compl == _cache_num_pages) // This condition exists after invalidation
+ res = init_aio_reads(0, _cache_num_pages);
+ if (outstanding)
+ get_events(AIO_COMPLETE, 0);
+ return res;
+}
+
+iores
+rmgr::init_aio_reads(const int16_t first_uninit, const u_int16_t num_uninit)
+{
+ for (int16_t i=0; i<num_uninit; i++)
+ {
+ if (_rrfc.is_void()) // Nothing to do; this file not yet written to
+ break;
+
+ if (_rrfc.subm_offs() == 0)
+ {
+ _rrfc.add_subm_cnt_dblks(JRNL_SBLK_SIZE);
+ _rrfc.add_cmpl_cnt_dblks(JRNL_SBLK_SIZE);
+ }
+
+ // TODO: Future perf improvement: Do a single AIO read for all available file
+ // space into all contiguous empty pages in one AIO operation.
+
+ u_int32_t file_rem_dblks = _rrfc.remaining_dblks();
+ file_rem_dblks -= file_rem_dblks % JRNL_SBLK_SIZE; // round down to closest sblk boundary
+ u_int32_t pg_size_dblks = JRNL_RMGR_PAGE_SIZE * JRNL_SBLK_SIZE;
+ u_int32_t rd_size = file_rem_dblks > pg_size_dblks ? pg_size_dblks : file_rem_dblks;
+ if (rd_size)
+ {
+ int16_t pi = (i + first_uninit) % _cache_num_pages;
+ // TODO: For perf, combine contiguous pages into single read
+ // 1 or 2 AIOs needed depending on whether read block folds
+ aio_cb* aiocbp = &_aio_cb_arr[pi];
+ aio::prep_pread_2(aiocbp, _rrfc.fh(), _page_ptr_arr[pi], rd_size * JRNL_DBLK_SIZE, _rrfc.subm_offs());
+ if (aio::submit(_ioctx, 1, &aiocbp) < 0)
+ throw jexception(jerrno::JERR__AIO, "rmgr", "init_aio_reads");
+ _rrfc.add_subm_cnt_dblks(rd_size);
+ _aio_evt_rem++;
+ _page_cb_arr[pi]._state = AIO_PENDING;
+ _page_cb_arr[pi]._rfh = _rrfc.file_controller();
+ }
+ else // If there is nothing to read for this page, neither will there be for the others...
+ break;
+ if (_rrfc.file_rotate())
+ _rrfc.rotate();
+ }
+ return RHM_IORES_SUCCESS;
+}
+
+void
+rmgr::rotate_page()
+{
+ _page_cb_arr[_pg_index]._rdblks = 0;
+ _page_cb_arr[_pg_index]._state = UNUSED;
+ if (_pg_offset_dblks >= JRNL_RMGR_PAGE_SIZE * JRNL_SBLK_SIZE)
+ {
+ _pg_offset_dblks = 0;
+ _pg_cntr++;
+ }
+ if (++_pg_index >= _cache_num_pages)
+ _pg_index = 0;
+ aio_cycle();
+ _pg_offset_dblks = 0;
+ // This counter is for bookkeeping only, page rotates are handled directly in init_aio_reads()
+ // FIXME: _pg_cntr should be sync'd with aio ops, not use of page as it is now...
+ // Need to move reset into if (_rrfc.file_rotate()) above.
+ if (_pg_cntr >= (_jc->jfsize_sblks() / JRNL_RMGR_PAGE_SIZE))
+ _pg_cntr = 0;
+}
+
+u_int32_t
+rmgr::dblks_rem() const
+{
+ return _page_cb_arr[_pg_index]._rdblks - _pg_offset_dblks;
+}
+
+void
+rmgr::set_params_null(void** const datapp, std::size_t& dsize, void** const xidpp, std::size_t& xidsize)
+{
+ *datapp = 0;
+ dsize = 0;
+ *xidpp = 0;
+ xidsize = 0;
+}
+
+void
+rmgr::init_file_header_read()
+{
+ _jc->fhdr_wr_sync(_rrfc.index()); // wait if the file header write is outstanding
+ int rfh = _rrfc.fh();
+ aio::prep_pread_2(_fhdr_aio_cb_ptr, rfh, _fhdr_buffer, _sblksize, 0);
+ if (aio::submit(_ioctx, 1, &_fhdr_aio_cb_ptr) < 0)
+ throw jexception(jerrno::JERR__AIO, "rmgr", "init_file_header_read");
+ _aio_evt_rem++;
+ _rrfc.add_subm_cnt_dblks(JRNL_SBLK_SIZE);
+ _fhdr_rd_outstanding = true;
+}
+
+/* TODO (sometime in the future)
+const iores
+rmgr::get(const u_int64_t& rid, const std::size_t& dsize, const std::size_t& dsize_avail,
+ const void** const data, bool auto_discard)
+{
+ return RHM_IORES_SUCCESS;
+}
+
+const iores
+rmgr::discard(data_tok* dtokp)
+{
+ return RHM_IORES_SUCCESS;
+}
+*/
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/rmgr.h b/cpp/src/qpid/legacystore/jrnl/rmgr.h
new file mode 100644
index 0000000000..ae4b5f56c8
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rmgr.h
@@ -0,0 +1,114 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file rmgr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::rmgr (read manager). See
+ * class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_RMGR_H
+#define QPID_LEGACYSTORE_JRNL_RMGR_H
+
+namespace mrg
+{
+namespace journal
+{
+class rmgr;
+}
+}
+
+#include <cstring>
+#include "jrnl/enums.h"
+#include "jrnl/file_hdr.h"
+#include "jrnl/pmgr.h"
+#include "jrnl/rec_hdr.h"
+#include "jrnl/rrfc.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \brief Class for managing a read page cache of arbitrary size and number of pages.
+ *
+ * The read page cache works on the principle of filling as many pages as possilbe in advance of
+ * reading the data. This ensures that delays caused by AIO operations are minimized.
+ */
+ class rmgr : public pmgr
+ {
+ private:
+ rrfc& _rrfc; ///< Ref to read rotating file controller
+ rec_hdr _hdr; ///< Header used to determind record type
+
+ void* _fhdr_buffer; ///< Buffer used for fhdr reads
+ aio_cb* _fhdr_aio_cb_ptr; ///< iocb pointer for fhdr reads
+ file_hdr _fhdr; ///< file header instance for reading file headers
+ bool _fhdr_rd_outstanding; ///< true if a fhdr read is outstanding
+
+ public:
+ rmgr(jcntl* jc, enq_map& emap, txn_map& tmap, rrfc& rrfc);
+ virtual ~rmgr();
+
+ using pmgr::initialize;
+ void initialize(aio_callback* const cbp);
+ iores read(void** const datapp, std::size_t& dsize, void** const xidpp,
+ std::size_t& xidsize, bool& transient, bool& external, data_tok* dtokp,
+ bool ignore_pending_txns);
+ int32_t get_events(page_state state, timespec* const timeout, bool flush = false);
+ void recover_complete();
+ inline iores synchronize() { if (_rrfc.is_valid()) return RHM_IORES_SUCCESS; return aio_cycle(); }
+ void invalidate();
+ bool wait_for_validity(timespec* const timeout, const bool throw_on_timeout = false);
+
+ /* TODO (if required)
+ const iores get(const u_int64_t& rid, const std::size_t& dsize, const std::size_t& dsize_avail,
+ const void** const data, bool auto_discard);
+ const iores discard(data_tok* dtok);
+ */
+
+ private:
+ void clean();
+ void flush(timespec* timeout);
+ iores pre_read_check(data_tok* dtokp);
+ iores read_enq(rec_hdr& h, void* rptr, data_tok* dtokp);
+ void consume_xid_rec(rec_hdr& h, void* rptr, data_tok* dtokp);
+ void consume_filler();
+ iores skip(data_tok* dtokp);
+ iores aio_cycle();
+ iores init_aio_reads(const int16_t first_uninit, const u_int16_t num_uninit);
+ void rotate_page();
+ u_int32_t dblks_rem() const;
+ void set_params_null(void** const datapp, std::size_t& dsize, void** const xidpp,
+ std::size_t& xidsize);
+ void init_file_header_read();
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_RMGR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/rrfc.cpp b/cpp/src/qpid/legacystore/jrnl/rrfc.cpp
new file mode 100644
index 0000000000..fc6f5d427f
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rrfc.cpp
@@ -0,0 +1,125 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file rrfc.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::rrfc (rotating
+ * file controller). See comments in file rrfc.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+
+#include "qpid/legacystore/jrnl/rrfc.h"
+
+#include <cerrno>
+#include <fcntl.h>
+#include <unistd.h>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+rrfc::rrfc(const lpmgr* lpmp): rfc(lpmp), _fh(-1), _valid(false)
+{}
+
+rrfc::~rrfc()
+{
+ close_fh();
+}
+
+void
+rrfc::finalize()
+{
+ unset_findex();
+ rfc::finalize();
+}
+
+void
+rrfc::set_findex(const u_int16_t fc_index)
+{
+ rfc::set_findex(fc_index);
+ open_fh(_curr_fc->fname());
+}
+
+void
+rrfc::unset_findex()
+{
+ set_invalid();
+ close_fh();
+ rfc::unset_findex();
+}
+
+iores
+rrfc::rotate()
+{
+ if (!_lpmp->num_jfiles())
+ throw jexception(jerrno::JERR__NINIT, "rrfc", "rotate");
+ u_int16_t next_fc_index = _fc_index + 1;
+ if (next_fc_index == _lpmp->num_jfiles())
+ next_fc_index = 0;
+ set_findex(next_fc_index);
+ return RHM_IORES_SUCCESS;
+}
+
+std::string
+rrfc::status_str() const
+{
+ std::ostringstream oss;
+ oss << "rrfc: " << rfc::status_str();
+ if (is_active())
+ oss << " fcntl[" << _fc_index << "]: " << _curr_fc->status_str();
+ return oss.str();
+}
+
+// === protected functions ===
+
+void
+rrfc::open_fh(const std::string& fn)
+{
+ close_fh();
+ _fh = ::open(fn.c_str(), O_RDONLY | O_DIRECT);
+ if (_fh < 0)
+ {
+ std::ostringstream oss;
+ oss << "file=\"" << fn << "\"" << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR_RRFC_OPENRD, oss.str(), "rrfc", "open_fh");
+ }
+}
+
+void
+rrfc::close_fh()
+{
+ if (_fh >= 0)
+ {
+ ::close(_fh);
+ _fh = -1;
+ }
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/rrfc.h b/cpp/src/qpid/legacystore/jrnl/rrfc.h
new file mode 100644
index 0000000000..5066d6048a
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/rrfc.h
@@ -0,0 +1,179 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file rrfc.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::rrfc (rotating
+ * file controller). See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_RRFC_H
+#define QPID_LEGACYSTORE_JRNL_RRFC_H
+
+namespace mrg
+{
+namespace journal
+{
+class rrfc;
+}
+}
+
+#include "qpid/legacystore/jrnl/fcntl.h"
+#include "qpid/legacystore/jrnl/rfc.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class rrfc
+ * \brief Read Rotating File Controller (rrfc) - Subclassed from pure virtual class rfc. Used to control the read
+ * pipeline in a rotating file buffer or journal. See class rfc for further details.
+ *
+ * The states that exist in this class are identical to class rfc from which it inherits, but in addition, the value
+ * of the read file handle _fh is also considered. The calls to set_findex also opens the file handle _fh to the
+ * active file for reading. Similarly, unset_findex() closes this file handle.
+ *
+ * <pre>
+ * is_init() is_active()
+ * +===+ _lpmp.is_init() == false
+ * +---------->| | Uninitialized: _curr_fc == 0 F F
+ * | +-->+===+ --+ _fh == -1
+ * | | |
+ * | | |
+ * | finalize() initialize()
+ * | | |
+ * | | |
+ * | +-- +===+<--+ _lpmp.is_init() == true
+ * finalize() | | Inactive: _curr_fc == 0 T F
+ * | +-->+===+ --+ _fh == -1
+ * | | |
+ * | | |
+ * | unset_findex() set_findex()
+ * | | |
+ * | | |
+ * | +-- +===+<--+ _lpmp.is_init() == true
+ * +---------- | | Active: _curr_fc != 0 T T
+ * +===+ _fh >= 0
+ * </pre>
+ *
+ * In adition to the states above, class rrfc contains a validity flag. This is operated indepenedently of the state
+ * machine. This flag (_valid) indicates when the read buffers are valid for reading. This is not strictly a state,
+ * but simply a flag used to keep track of the status, and is set/unset with calls to set_valid() and set_invalid()
+ * respectively.
+ */
+ class rrfc : public rfc
+ {
+ protected:
+ int _fh; ///< Read file handle
+ bool _valid; ///< Flag is true when read pages contain vailid data
+
+ public:
+ rrfc(const lpmgr* lpmp);
+ virtual ~rrfc();
+
+ /**
+ * \brief Initialize the controller, moving from state Uninitialized to Initialized. The main function of
+ * initialize() is to set the number of files and the pointer to the fcntl array.
+ */
+ inline void initialize() { rfc::initialize(); _valid = false; }
+
+ /**
+ * \brief Reset the controller to Uninitialized state, usually called when the journal is stopped. Once called,
+ * initialize() must be called to reuse an instance.
+ */
+ void finalize();
+
+ /**
+ * \brief Opens the file handle for reading a particular fid. Moves to state open.
+ */
+ void set_findex(const u_int16_t fc_index);
+
+ /**
+ * \brief Closes the read file handle and nulls the active fcntl pointer. Moves to state closed.
+ */
+ void unset_findex();
+
+ /**
+ * \brief Check the state: true = open; false = closed.
+ */
+ inline bool is_active() const { return _curr_fc != 0 && _fh >= 0; }
+
+ /**
+ * \brief Sets the validity flag which indicates that the read buffers contain valid data for reading.
+ */
+ inline void set_invalid() { _valid = false; }
+
+ /**
+ * \brief Resets the validity flag wich indicates that the read buffers are no longer synchronized and cannot
+ * be read whithout resynchronization.
+ */
+ inline void set_valid() { _valid = true; }
+
+ /**
+ * \brief Checks the read buffer validity status: true = valid, can be read; false = invalid, synchronization
+ * required.
+ */
+ inline bool is_valid() const { return _valid; }
+
+ /**
+ * \brief Rotate active file controller to next file in rotating file group.
+ * \exception jerrno::JERR__NINIT if called before calling initialize().
+ */
+ iores rotate();
+
+ inline int fh() const { return _fh; }
+
+ inline u_int32_t subm_cnt_dblks() const { return _curr_fc->rd_subm_cnt_dblks(); }
+ inline std::size_t subm_offs() const { return _curr_fc->rd_subm_offs(); }
+ inline u_int32_t add_subm_cnt_dblks(u_int32_t a) { return _curr_fc->add_rd_subm_cnt_dblks(a); }
+
+ inline u_int32_t cmpl_cnt_dblks() const { return _curr_fc->rd_cmpl_cnt_dblks(); }
+ inline std::size_t cmpl_offs() const { return _curr_fc->rd_cmpl_offs(); }
+ inline u_int32_t add_cmpl_cnt_dblks(u_int32_t a) { return _curr_fc->add_rd_cmpl_cnt_dblks(a); }
+
+ inline bool is_void() const { return _curr_fc->rd_void(); }
+ inline bool is_empty() const { return _curr_fc->rd_empty(); }
+ inline u_int32_t remaining_dblks() const { return _curr_fc->rd_remaining_dblks(); }
+ inline bool is_full() const { return _curr_fc->is_rd_full(); }
+ inline bool is_compl() const { return _curr_fc->is_rd_compl(); }
+ inline u_int32_t aio_outstanding_dblks() const { return _curr_fc->rd_aio_outstanding_dblks(); }
+ inline bool file_rotate() const { return _curr_fc->rd_file_rotate(); }
+ inline bool is_wr_aio_outstanding() const { return _curr_fc->wr_aio_outstanding_dblks() > 0; }
+
+ // Debug aid
+ std::string status_str() const;
+
+ protected:
+ void open_fh(const std::string& fn);
+ void close_fh();
+ }; // class rrfc
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_RRFC_H
diff --git a/cpp/src/qpid/legacystore/jrnl/slock.cpp b/cpp/src/qpid/legacystore/jrnl/slock.cpp
new file mode 100644
index 0000000000..8f26d349ef
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/slock.cpp
@@ -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.
+ *
+ */
+
+/**
+ * \file slock.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::slock (scoped lock). See
+ * comments in file slock.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/slock.h"
diff --git a/cpp/src/qpid/legacystore/jrnl/slock.h b/cpp/src/qpid/legacystore/jrnl/slock.h
new file mode 100644
index 0000000000..c05b5cf336
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/slock.h
@@ -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.
+ *
+ */
+
+/**
+ * \file slock.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Messaging journal scoped lock class mrg::journal::slock and scoped try-lock
+ * class mrg::journal::stlock.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_SLOCK_H
+#define QPID_LEGACYSTORE_JRNL_SLOCK_H
+
+#include "qpid/legacystore/jrnl/jexception.h"
+#include "qpid/legacystore/jrnl/smutex.h"
+#include <pthread.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+ // Ultra-simple scoped lock class, auto-releases mutex when it goes out-of-scope
+ class slock
+ {
+ protected:
+ const smutex& _sm;
+ public:
+ inline slock(const smutex& sm) : _sm(sm)
+ {
+ PTHREAD_CHK(::pthread_mutex_lock(_sm.get()), "::pthread_mutex_lock", "slock", "slock");
+ }
+ inline ~slock()
+ {
+ PTHREAD_CHK(::pthread_mutex_unlock(_sm.get()), "::pthread_mutex_unlock", "slock", "~slock");
+ }
+ };
+
+ // Ultra-simple scoped try-lock class, auto-releases mutex when it goes out-of-scope
+ class stlock
+ {
+ protected:
+ const smutex& _sm;
+ bool _locked;
+ public:
+ inline stlock(const smutex& sm) : _sm(sm), _locked(false)
+ {
+ int ret = ::pthread_mutex_trylock(_sm.get());
+ _locked = (ret == 0); // check if lock obtained
+ if (!_locked && ret != EBUSY) PTHREAD_CHK(ret, "::pthread_mutex_trylock", "stlock", "stlock");
+ }
+ inline ~stlock()
+ {
+ if (_locked)
+ PTHREAD_CHK(::pthread_mutex_unlock(_sm.get()), "::pthread_mutex_unlock", "stlock", "~stlock");
+ }
+ inline bool locked() const { return _locked; }
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_SLOCK_H
diff --git a/cpp/src/qpid/legacystore/jrnl/smutex.cpp b/cpp/src/qpid/legacystore/jrnl/smutex.cpp
new file mode 100644
index 0000000000..6f8991ca5b
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/smutex.cpp
@@ -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.
+ *
+ */
+
+/**
+ * \file smutex.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::smutex (scoped mutex). See
+ * comments in file smutex.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/smutex.h"
diff --git a/cpp/src/qpid/legacystore/jrnl/smutex.h b/cpp/src/qpid/legacystore/jrnl/smutex.h
new file mode 100644
index 0000000000..def0fb70f6
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/smutex.h
@@ -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.
+ *
+ */
+
+/**
+ * \file smutex.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Messaging journal scoped mutex class mrg::journal::smutex.
+ *
+ * \author Kim van der Riet
+ */
+
+
+#ifndef QPID_LEGACYSTORE_JRNL_SMUTEX_H
+#define QPID_LEGACYSTORE_JRNL_SMUTEX_H
+
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <pthread.h>
+
+namespace mrg
+{
+namespace journal
+{
+
+ // Ultra-simple scoped mutex class that allows a posix mutex to be initialized and destroyed with error checks
+ class smutex
+ {
+ protected:
+ mutable pthread_mutex_t _m;
+ public:
+ inline smutex()
+ {
+ PTHREAD_CHK(::pthread_mutex_init(&_m, 0), "::pthread_mutex_init", "smutex", "smutex");
+ }
+ inline virtual ~smutex()
+ {
+ PTHREAD_CHK(::pthread_mutex_destroy(&_m), "::pthread_mutex_destroy", "smutex", "~smutex");
+ }
+ inline pthread_mutex_t* get() const { return &_m; }
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_SMUTEX_H
diff --git a/cpp/src/qpid/legacystore/jrnl/time_ns.cpp b/cpp/src/qpid/legacystore/jrnl/time_ns.cpp
new file mode 100644
index 0000000000..976068ef68
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/time_ns.cpp
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file time_ns.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Messaging journal time struct mrg::journal::time_ns, derived from
+ * the timespec struct and provided with helper functions.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/time_ns.h"
+
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+const std::string
+time_ns::str(int precision) const
+{
+ const double t = tv_sec + (tv_nsec/1e9);
+ std::ostringstream oss;
+ oss.setf(std::ios::fixed, std::ios::floatfield);
+ oss.precision(precision);
+ oss << t;
+ return oss.str();
+}
+
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/time_ns.h b/cpp/src/qpid/legacystore/jrnl/time_ns.h
new file mode 100644
index 0000000000..a9f69e2631
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/time_ns.h
@@ -0,0 +1,105 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file time_ns.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * Messaging journal time struct mrg::journal::time_ns, derived from
+ * the timespec struct and provided with helper functions.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_TIME_NS_H
+#define QPID_LEGACYSTORE_JRNL_TIME_NS_H
+
+#include <cerrno>
+#include <ctime>
+#include <string>
+
+namespace mrg
+{
+namespace journal
+{
+
+struct time_ns : public timespec
+{
+ inline time_ns() { tv_sec = 0; tv_nsec = 0; }
+ inline time_ns(const std::time_t sec, const long nsec = 0) { tv_sec = sec; tv_nsec = nsec; }
+ inline time_ns(const time_ns& t) { tv_sec = t.tv_sec; tv_nsec = t.tv_nsec; }
+
+ inline void set_zero() { tv_sec = 0; tv_nsec = 0; }
+ inline bool is_zero() const { return tv_sec == 0 && tv_nsec == 0; }
+ inline int now() { if(::clock_gettime(CLOCK_REALTIME, this)) return errno; return 0; }
+ const std::string str(int precision = 6) const;
+
+ inline time_ns& operator=(const time_ns& rhs)
+ { tv_sec = rhs.tv_sec; tv_nsec = rhs.tv_nsec; return *this; }
+ inline time_ns& operator+=(const time_ns& rhs)
+ {
+ tv_nsec += rhs.tv_nsec;
+ if (tv_nsec >= 1000000000L) { tv_sec++; tv_nsec -= 1000000000L; }
+ tv_sec += rhs.tv_sec;
+ return *this;
+ }
+ inline time_ns& operator+=(const long ns)
+ {
+ tv_nsec += ns;
+ if (tv_nsec >= 1000000000L) { tv_sec++; tv_nsec -= 1000000000L; }
+ return *this;
+ }
+ inline time_ns& operator-=(const long ns)
+ {
+ tv_nsec -= ns;
+ if (tv_nsec < 0) { tv_sec--; tv_nsec += 1000000000L; }
+ return *this;
+ }
+ inline time_ns& operator-=(const time_ns& rhs)
+ {
+ tv_nsec -= rhs.tv_nsec;
+ if (tv_nsec < 0) { tv_sec--; tv_nsec += 1000000000L; }
+ tv_sec -= rhs.tv_sec;
+ return *this;
+ }
+ inline const time_ns operator+(const time_ns& rhs)
+ { time_ns t(*this); t += rhs; return t; }
+ inline const time_ns operator-(const time_ns& rhs)
+ { time_ns t(*this); t -= rhs; return t; }
+ inline bool operator==(const time_ns& rhs)
+ { return tv_sec == rhs.tv_sec && tv_nsec == rhs.tv_nsec; }
+ inline bool operator!=(const time_ns& rhs)
+ { return tv_sec != rhs.tv_sec || tv_nsec != rhs.tv_nsec; }
+ inline bool operator>(const time_ns& rhs)
+ { if(tv_sec == rhs.tv_sec) return tv_nsec > rhs.tv_nsec; return tv_sec > rhs.tv_sec; }
+ inline bool operator>=(const time_ns& rhs)
+ { if(tv_sec == rhs.tv_sec) return tv_nsec >= rhs.tv_nsec; return tv_sec >= rhs.tv_sec; }
+ inline bool operator<(const time_ns& rhs)
+ { if(tv_sec == rhs.tv_sec) return tv_nsec < rhs.tv_nsec; return tv_sec < rhs.tv_sec; }
+ inline bool operator<=(const time_ns& rhs)
+ { if(tv_sec == rhs.tv_sec) return tv_nsec <= rhs.tv_nsec; return tv_sec <= rhs.tv_sec; }
+};
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_TIME_NS_H
diff --git a/cpp/src/qpid/legacystore/jrnl/txn_hdr.h b/cpp/src/qpid/legacystore/jrnl/txn_hdr.h
new file mode 100644
index 0000000000..94b812ccec
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/txn_hdr.h
@@ -0,0 +1,125 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file txn_hdr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::txn_hdr (transaction
+ * record header), used to start a transaction (commit or abort) record.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_TXN_HDR_H
+#define QPID_LEGACYSTORE_JRNL_TXN_HDR_H
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/rec_hdr.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+#pragma pack(1)
+
+ /**
+ * \brief Struct for transaction commit and abort records.
+ *
+ * Struct for DTX commit and abort records. Only the magic distinguishes between them. Since
+ * this record must be used in the context of a valid XID, the xidsize field must not be zero.
+ * Immediately following this record is the XID itself which is xidsize bytes long, followed by
+ * a rec_tail.
+ *
+ * Note that this record had its own rid distinct from the rids of the record(s) making up the
+ * transaction it is committing or aborting.
+ *
+ * Record header info in binary format (24 bytes):
+ * <pre>
+ * 0 7
+ * +---+---+---+---+---+---+---+---+ -+
+ * | magic | v | e | flags | |
+ * +---+---+---+---+---+---+---+---+ | struct hdr
+ * | rid | |
+ * +---+---+---+---+---+---+---+---+ -+
+ * | xidsize |
+ * +---+---+---+---+---+---+---+---+
+ * v = file version (If the format or encoding of this file changes, then this
+ * number should be incremented)
+ * e = endian flag, false (0x00) for little endian, true (0x01) for big endian
+ * </pre>
+ *
+ * Note that journal files should be transferable between 32- and 64-bit
+ * hardware of the same endianness, but not between hardware of opposite
+ * entianness without some sort of binary conversion utility. Thus buffering
+ * will be needed for types that change size between 32- and 64-bit compiles.
+ */
+ struct txn_hdr : rec_hdr
+ {
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Big-endian filler for 32-bit size_t
+#endif
+ std::size_t _xidsize; ///< XID size
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ u_int32_t _filler0; ///< Little-endian filler for 32-bit size_t
+#endif
+
+ /**
+ * \brief Default constructor, which sets all values to 0.
+ */
+ txn_hdr(): rec_hdr(),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(0)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler0(0)
+#endif
+ {}
+
+ /**
+ * \brief Convenience constructor which initializes values during construction.
+ */
+ txn_hdr(const u_int32_t magic, const u_int8_t version, const u_int64_t rid,
+ const std::size_t xidsize, const bool owi): rec_hdr(magic, version, rid, owi),
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ _filler0(0),
+#endif
+ _xidsize(xidsize)
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ , _filler0(0)
+#endif
+ {}
+
+ /**
+ * \brief Returns the size of the header in bytes.
+ */
+ inline static std::size_t size() { return sizeof(txn_hdr); }
+ };
+
+#pragma pack()
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_TXN_HDR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/txn_map.cpp b/cpp/src/qpid/legacystore/jrnl/txn_map.cpp
new file mode 100644
index 0000000000..c514670601
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/txn_map.cpp
@@ -0,0 +1,256 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file txn_map.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::txn_map (transaction map). See
+ * comments in file txn_map.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/txn_map.h"
+
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include "qpid/legacystore/jrnl/slock.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+// return/error codes
+int16_t txn_map::TMAP_RID_NOT_FOUND = -2;
+int16_t txn_map::TMAP_XID_NOT_FOUND = -1;
+int16_t txn_map::TMAP_OK = 0;
+int16_t txn_map::TMAP_NOT_SYNCED = 0;
+int16_t txn_map::TMAP_SYNCED = 1;
+
+txn_data_struct::txn_data_struct(const u_int64_t rid, const u_int64_t drid, const u_int16_t pfid,
+ const bool enq_flag, const bool commit_flag):
+ _rid(rid),
+ _drid(drid),
+ _pfid(pfid),
+ _enq_flag(enq_flag),
+ _commit_flag(commit_flag),
+ _aio_compl(false)
+{}
+
+txn_map::txn_map():
+ _map(),
+ _pfid_txn_cnt()
+{}
+
+txn_map::~txn_map() {}
+
+void
+txn_map::set_num_jfiles(const u_int16_t num_jfiles)
+{
+ _pfid_txn_cnt.resize(num_jfiles, 0);
+}
+
+u_int32_t
+txn_map::get_txn_pfid_cnt(const u_int16_t pfid) const
+{
+ return _pfid_txn_cnt.at(pfid);
+}
+
+bool
+txn_map::insert_txn_data(const std::string& xid, const txn_data& td)
+{
+ bool ok = true;
+ slock s(_mutex);
+ xmap_itr itr = _map.find(xid);
+ if (itr == _map.end()) // not found in map
+ {
+ txn_data_list list;
+ list.push_back(td);
+ std::pair<xmap_itr, bool> ret = _map.insert(xmap_param(xid, list));
+ if (!ret.second) // duplicate
+ ok = false;
+ }
+ else
+ itr->second.push_back(td);
+ _pfid_txn_cnt.at(td._pfid)++;
+ return ok;
+}
+
+const txn_data_list
+txn_map::get_tdata_list(const std::string& xid)
+{
+ slock s(_mutex);
+ return get_tdata_list_nolock(xid);
+}
+
+const txn_data_list
+txn_map::get_tdata_list_nolock(const std::string& xid)
+{
+ xmap_itr itr = _map.find(xid);
+ if (itr == _map.end()) // not found in map
+ return _empty_data_list;
+ return itr->second;
+}
+
+const txn_data_list
+txn_map::get_remove_tdata_list(const std::string& xid)
+{
+ slock s(_mutex);
+ xmap_itr itr = _map.find(xid);
+ if (itr == _map.end()) // not found in map
+ return _empty_data_list;
+ txn_data_list list = itr->second;
+ _map.erase(itr);
+ for (tdl_itr i=list.begin(); i!=list.end(); i++)
+ _pfid_txn_cnt.at(i->_pfid)--;
+ return list;
+}
+
+bool
+txn_map::in_map(const std::string& xid)
+{
+ slock s(_mutex);
+ xmap_itr itr= _map.find(xid);
+ return itr != _map.end();
+}
+
+u_int32_t
+txn_map::enq_cnt()
+{
+ return cnt(true);
+}
+
+u_int32_t
+txn_map::deq_cnt()
+{
+ return cnt(true);
+}
+
+u_int32_t
+txn_map::cnt(const bool enq_flag)
+{
+ slock s(_mutex);
+ u_int32_t c = 0;
+ for (xmap_itr i = _map.begin(); i != _map.end(); i++)
+ {
+ for (tdl_itr j = i->second.begin(); j < i->second.end(); j++)
+ {
+ if (j->_enq_flag == enq_flag)
+ c++;
+ }
+ }
+ return c;
+}
+
+int16_t
+txn_map::is_txn_synced(const std::string& xid)
+{
+ slock s(_mutex);
+ xmap_itr itr = _map.find(xid);
+ if (itr == _map.end()) // not found in map
+ return TMAP_XID_NOT_FOUND;
+ bool is_synced = true;
+ for (tdl_itr litr = itr->second.begin(); litr < itr->second.end(); litr++)
+ {
+ if (!litr->_aio_compl)
+ {
+ is_synced = false;
+ break;
+ }
+ }
+ return is_synced ? TMAP_SYNCED : TMAP_NOT_SYNCED;
+}
+
+int16_t
+txn_map::set_aio_compl(const std::string& xid, const u_int64_t rid)
+{
+ slock s(_mutex);
+ xmap_itr itr = _map.find(xid);
+ if (itr == _map.end()) // xid not found in map
+ return TMAP_XID_NOT_FOUND;
+ for (tdl_itr litr = itr->second.begin(); litr < itr->second.end(); litr++)
+ {
+ if (litr->_rid == rid)
+ {
+ litr->_aio_compl = true;
+ return TMAP_OK; // rid found
+ }
+ }
+ // xid present, but rid not found
+ return TMAP_RID_NOT_FOUND;
+}
+
+bool
+txn_map::data_exists(const std::string& xid, const u_int64_t rid)
+{
+ bool found = false;
+ {
+ slock s(_mutex);
+ txn_data_list tdl = get_tdata_list_nolock(xid);
+ tdl_itr itr = tdl.begin();
+ while (itr != tdl.end() && !found)
+ {
+ found = itr->_rid == rid;
+ itr++;
+ }
+ }
+ return found;
+}
+
+bool
+txn_map::is_enq(const u_int64_t rid)
+{
+ bool found = false;
+ {
+ slock s(_mutex);
+ for (xmap_itr i = _map.begin(); i != _map.end() && !found; i++)
+ {
+ txn_data_list list = i->second;
+ for (tdl_itr j = list.begin(); j < list.end() && !found; j++)
+ {
+ if (j->_enq_flag)
+ found = j->_rid == rid;
+ else
+ found = j->_drid == rid;
+ }
+ }
+ }
+ return found;
+}
+
+void
+txn_map::xid_list(std::vector<std::string>& xv)
+{
+ xv.clear();
+ {
+ slock s(_mutex);
+ for (xmap_itr itr = _map.begin(); itr != _map.end(); itr++)
+ xv.push_back(itr->first);
+ }
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/txn_map.h b/cpp/src/qpid/legacystore/jrnl/txn_map.h
new file mode 100644
index 0000000000..6b38564e53
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/txn_map.h
@@ -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.
+ *
+ */
+
+/**
+ * \file txn_map.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::txn_map (transaction map).
+ * See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_TXN_MAP_H
+#define QPID_LEGACYSTORE_JRNL_TXN_MAP_H
+
+namespace mrg
+{
+namespace journal
+{
+ class txn_map;
+}
+}
+
+#include "qpid/legacystore/jrnl/smutex.h"
+#include <map>
+#include <pthread.h>
+#include <string>
+#include <sys/types.h>
+#include <vector>
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \struct txn_data_struct
+ * \brief Struct encapsulating transaction data necessary for processing a transaction
+ * in the journal once it is closed with either a commit or abort.
+ */
+ struct txn_data_struct
+ {
+ u_int64_t _rid; ///< Record id for this operation
+ u_int64_t _drid; ///< Dequeue record id for this operation
+ u_int16_t _pfid; ///< Physical file id, to be used when transferring to emap on commit
+ bool _enq_flag; ///< If true, enq op, otherwise deq op
+ bool _commit_flag; ///< (2PC transactions) Records 2PC complete c/a mode
+ bool _aio_compl; ///< Initially false, set to true when record AIO returns
+ txn_data_struct(const u_int64_t rid, const u_int64_t drid, const u_int16_t pfid,
+ const bool enq_flag, const bool commit_flag = false);
+ };
+ typedef txn_data_struct txn_data;
+ typedef std::vector<txn_data> txn_data_list;
+ typedef txn_data_list::iterator tdl_itr;
+
+ /**
+ * \class txn_map
+ * \brief Class for storing transaction data for each open (ie not committed or aborted)
+ * xid in the store. If aborted, records are discarded; if committed, they are
+ * transferred to the enqueue map.
+ *
+ * The data is encapsulated by struct txn_data_struct. A vector containing the information
+ * for each operation included as part of the same transaction is mapped against the
+ * xid.
+ *
+ * The aio_compl flag is set true as each AIO write operation for the enqueue or dequeue
+ * returns. Checking that all of these flags are true for a given xid is the mechanism
+ * used to determine if the transaction is syncronized (through method is_txn_synced()).
+ *
+ * On transaction commit, then each operation is handled as follows:
+ *
+ * If an enqueue (_enq_flag is true), then the rid and pfid are transferred to the enq_map.
+ * If a dequeue (_enq_flag is false), then the rid stored in the drid field is used to
+ * remove the corresponding record from the enq_map.
+ *
+ * On transaction abort, then each operation is handled as follows:
+ *
+ * If an enqueue (_enq_flag is true), then the data is simply discarded.
+ * If a dequeue (_enq_flag is false), then the lock for the corresponding enqueue in enq_map
+ * (if not a part of the same transaction) is removed, and the data discarded.
+ *
+ * <pre>
+ * key data
+ *
+ * xid1 --- vector< [ rid, drid, pfid, enq_flag, commit_flag, aio_compl ] >
+ * xid2 --- vector< [ rid, drid, pfid, enq_flag, commit_flag, aio_compl ] >
+ * xid3 --- vector< [ rid, drid, pfid, enq_flag, commit_flag, aio_compl ] >
+ * ...
+ * </pre>
+ */
+ class txn_map
+ {
+ public:
+ // return/error codes
+ static int16_t TMAP_RID_NOT_FOUND;
+ static int16_t TMAP_XID_NOT_FOUND;
+ static int16_t TMAP_OK;
+ static int16_t TMAP_NOT_SYNCED;
+ static int16_t TMAP_SYNCED;
+
+ private:
+ typedef std::pair<std::string, txn_data_list> xmap_param;
+ typedef std::map<std::string, txn_data_list> xmap;
+ typedef xmap::iterator xmap_itr;
+
+ xmap _map;
+ smutex _mutex;
+ std::vector<u_int32_t> _pfid_txn_cnt;
+ const txn_data_list _empty_data_list;
+
+ public:
+ txn_map();
+ virtual ~txn_map();
+
+ void set_num_jfiles(const u_int16_t num_jfiles);
+ u_int32_t get_txn_pfid_cnt(const u_int16_t pfid) const;
+ bool insert_txn_data(const std::string& xid, const txn_data& td);
+ const txn_data_list get_tdata_list(const std::string& xid);
+ const txn_data_list get_remove_tdata_list(const std::string& xid);
+ bool in_map(const std::string& xid);
+ u_int32_t enq_cnt();
+ u_int32_t deq_cnt();
+ int16_t is_txn_synced(const std::string& xid); // -1=xid not found; 0=not synced; 1=synced
+ int16_t set_aio_compl(const std::string& xid, const u_int64_t rid); // -2=rid not found; -1=xid not found; 0=done
+ bool data_exists(const std::string& xid, const u_int64_t rid);
+ bool is_enq(const u_int64_t rid);
+ inline void clear() { _map.clear(); }
+ inline bool empty() const { return _map.empty(); }
+ inline size_t size() const { return _map.size(); }
+ void xid_list(std::vector<std::string>& xv);
+ private:
+ u_int32_t cnt(const bool enq_flag);
+ const txn_data_list get_tdata_list_nolock(const std::string& xid);
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_TXN_MAP_H
diff --git a/cpp/src/qpid/legacystore/jrnl/txn_rec.cpp b/cpp/src/qpid/legacystore/jrnl/txn_rec.cpp
new file mode 100644
index 0000000000..918a6ce902
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/txn_rec.cpp
@@ -0,0 +1,447 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file txn_rec.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the code for the mrg::journal::txn_rec (journal dequeue
+ * record) class. See comments in file txn_rec.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/txn_rec.h"
+
+#include <cassert>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include <iomanip>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+txn_rec::txn_rec():
+ _txn_hdr(),
+ _xidp(0),
+ _buff(0),
+ _txn_tail()
+{
+ _txn_hdr._version = RHM_JDAT_VERSION;
+}
+
+txn_rec::txn_rec(const u_int32_t magic, const u_int64_t rid, const void* const xidp,
+ const std::size_t xidlen, const bool owi):
+ _txn_hdr(magic, RHM_JDAT_VERSION, rid, xidlen, owi),
+ _xidp(xidp),
+ _buff(0),
+ _txn_tail(_txn_hdr)
+{}
+
+txn_rec::~txn_rec()
+{
+ clean();
+}
+
+void
+txn_rec::reset(const u_int32_t magic)
+{
+ _txn_hdr._magic = magic;
+ _txn_hdr._rid = 0;
+ _txn_hdr._xidsize = 0;
+ _xidp = 0;
+ _buff = 0;
+ _txn_tail._xmagic = ~magic;
+ _txn_tail._rid = 0;
+}
+
+void
+txn_rec::reset(const u_int32_t magic, const u_int64_t rid, const void* const xidp,
+ const std::size_t xidlen, const bool owi)
+{
+ _txn_hdr._magic = magic;
+ _txn_hdr._rid = rid;
+ _txn_hdr.set_owi(owi);
+ _txn_hdr._xidsize = xidlen;
+ _xidp = xidp;
+ _buff = 0;
+ _txn_tail._xmagic = ~magic;
+ _txn_tail._rid = rid;
+}
+
+u_int32_t
+txn_rec::encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+{
+ assert(wptr != 0);
+ assert(max_size_dblks > 0);
+ assert(_xidp != 0 && _txn_hdr._xidsize > 0);
+
+ std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+ std::size_t rem = max_size_dblks * JRNL_DBLK_SIZE;
+ std::size_t wr_cnt = 0;
+ if (rec_offs_dblks) // Continuation of split dequeue record (over 2 or more pages)
+ {
+ if (size_dblks(rec_size()) - rec_offs_dblks > max_size_dblks) // Further split required
+ {
+ rec_offs -= sizeof(_txn_hdr);
+ std::size_t wsize = _txn_hdr._xidsize > rec_offs ? _txn_hdr._xidsize - rec_offs : 0;
+ std::size_t wsize2 = wsize;
+ if (wsize)
+ {
+ if (wsize > rem)
+ wsize = rem;
+ std::memcpy(wptr, (const char*)_xidp + rec_offs, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ rec_offs -= _txn_hdr._xidsize - wsize2;
+ if (rem)
+ {
+ wsize = sizeof(_txn_tail) > rec_offs ? sizeof(_txn_tail) - rec_offs : 0;
+ wsize2 = wsize;
+ if (wsize)
+ {
+ if (wsize > rem)
+ wsize = rem;
+ std::memcpy((char*)wptr + wr_cnt, (char*)&_txn_tail + rec_offs, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ rec_offs -= sizeof(_txn_tail) - wsize2;
+ }
+ assert(rem == 0);
+ assert(rec_offs == 0);
+ }
+ else // No further split required
+ {
+ rec_offs -= sizeof(_txn_hdr);
+ std::size_t wsize = _txn_hdr._xidsize > rec_offs ? _txn_hdr._xidsize - rec_offs : 0;
+ if (wsize)
+ {
+ std::memcpy(wptr, (const char*)_xidp + rec_offs, wsize);
+ wr_cnt += wsize;
+ }
+ rec_offs -= _txn_hdr._xidsize - wsize;
+ wsize = sizeof(_txn_tail) > rec_offs ? sizeof(_txn_tail) - rec_offs : 0;
+ if (wsize)
+ {
+ std::memcpy((char*)wptr + wr_cnt, (char*)&_txn_tail + rec_offs, wsize);
+ wr_cnt += wsize;
+#ifdef RHM_CLEAN
+ std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+ std::size_t dblk_rec_size = size_dblks(rec_size() - rec_offs) * JRNL_DBLK_SIZE;
+ std::memset((char*)wptr + wr_cnt, RHM_CLEAN_CHAR, dblk_rec_size - wr_cnt);
+#endif
+ }
+ rec_offs -= sizeof(_txn_tail) - wsize;
+ assert(rec_offs == 0);
+ }
+ }
+ else // Start at beginning of data record
+ {
+ // Assumption: the header will always fit into the first dblk
+ std::memcpy(wptr, (void*)&_txn_hdr, sizeof(_txn_hdr));
+ wr_cnt = sizeof(_txn_hdr);
+ if (size_dblks(rec_size()) > max_size_dblks) // Split required
+ {
+ std::size_t wsize;
+ rem -= sizeof(_txn_hdr);
+ if (rem)
+ {
+ wsize = rem >= _txn_hdr._xidsize ? _txn_hdr._xidsize : rem;
+ std::memcpy((char*)wptr + wr_cnt, _xidp, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ if (rem)
+ {
+ wsize = rem >= sizeof(_txn_tail) ? sizeof(_txn_tail) : rem;
+ std::memcpy((char*)wptr + wr_cnt, (void*)&_txn_tail, wsize);
+ wr_cnt += wsize;
+ rem -= wsize;
+ }
+ assert(rem == 0);
+ }
+ else // No split required
+ {
+ std::memcpy((char*)wptr + wr_cnt, _xidp, _txn_hdr._xidsize);
+ wr_cnt += _txn_hdr._xidsize;
+ std::memcpy((char*)wptr + wr_cnt, (void*)&_txn_tail, sizeof(_txn_tail));
+ wr_cnt += sizeof(_txn_tail);
+#ifdef RHM_CLEAN
+ std::size_t dblk_rec_size = size_dblks(rec_size()) * JRNL_DBLK_SIZE;
+ std::memset((char*)wptr + wr_cnt, RHM_CLEAN_CHAR, dblk_rec_size - wr_cnt);
+#endif
+ }
+ }
+ return size_dblks(wr_cnt);
+}
+
+u_int32_t
+txn_rec::decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks)
+{
+ assert(rptr != 0);
+ assert(max_size_dblks > 0);
+
+ std::size_t rd_cnt = 0;
+ if (rec_offs_dblks) // Continuation of record on new page
+ {
+ const u_int32_t hdr_xid_dblks = size_dblks(txn_hdr::size() + _txn_hdr._xidsize);
+ const u_int32_t hdr_xid_tail_dblks = size_dblks(txn_hdr::size() + _txn_hdr._xidsize +
+ rec_tail::size());
+ const std::size_t rec_offs = rec_offs_dblks * JRNL_DBLK_SIZE;
+
+ if (hdr_xid_tail_dblks - rec_offs_dblks <= max_size_dblks)
+ {
+ // Remainder of xid fits within this page
+ if (rec_offs - txn_hdr::size() < _txn_hdr._xidsize)
+ {
+ // Part of xid still outstanding, copy remainder of xid and tail
+ const std::size_t xid_offs = rec_offs - txn_hdr::size();
+ const std::size_t xid_rem = _txn_hdr._xidsize - xid_offs;
+ std::memcpy((char*)_buff + xid_offs, rptr, xid_rem);
+ rd_cnt = xid_rem;
+ std::memcpy((void*)&_txn_tail, ((char*)rptr + rd_cnt), sizeof(_txn_tail));
+ chk_tail();
+ rd_cnt += sizeof(_txn_tail);
+ }
+ else
+ {
+ // Tail or part of tail only outstanding, complete tail
+ const std::size_t tail_offs = rec_offs - txn_hdr::size() - _txn_hdr._xidsize;
+ const std::size_t tail_rem = rec_tail::size() - tail_offs;
+ std::memcpy((char*)&_txn_tail + tail_offs, rptr, tail_rem);
+ chk_tail();
+ rd_cnt = tail_rem;
+ }
+ }
+ else if (hdr_xid_dblks - rec_offs_dblks <= max_size_dblks)
+ {
+ // Remainder of xid fits within this page, tail split
+ const std::size_t xid_offs = rec_offs - txn_hdr::size();
+ const std::size_t xid_rem = _txn_hdr._xidsize - xid_offs;
+ std::memcpy((char*)_buff + xid_offs, rptr, xid_rem);
+ rd_cnt += xid_rem;
+ const std::size_t tail_rem = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ if (tail_rem)
+ {
+ std::memcpy((void*)&_txn_tail, ((char*)rptr + xid_rem), tail_rem);
+ rd_cnt += tail_rem;
+ }
+ }
+ else
+ {
+ // Remainder of xid split
+ const std::size_t xid_cp_size = (max_size_dblks * JRNL_DBLK_SIZE);
+ std::memcpy((char*)_buff + rec_offs - txn_hdr::size(), rptr, xid_cp_size);
+ rd_cnt += xid_cp_size;
+ }
+ }
+ else // Start of record
+ {
+ // Get and check header
+ _txn_hdr.hdr_copy(h);
+ rd_cnt = sizeof(rec_hdr);
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ rd_cnt += sizeof(u_int32_t); // Filler 0
+#endif
+ _txn_hdr._xidsize = *(std::size_t*)((char*)rptr + rd_cnt);
+ rd_cnt = _txn_hdr.size();
+ chk_hdr();
+ _buff = std::malloc(_txn_hdr._xidsize);
+ MALLOC_CHK(_buff, "_buff", "txn_rec", "decode");
+ const u_int32_t hdr_xid_dblks = size_dblks(txn_hdr::size() + _txn_hdr._xidsize);
+ const u_int32_t hdr_xid_tail_dblks = size_dblks(txn_hdr::size() + _txn_hdr._xidsize +
+ rec_tail::size());
+
+ // Check if record (header + xid + tail) fits within this page, we can check the
+ // tail before the expense of copying data to memory
+ if (hdr_xid_tail_dblks <= max_size_dblks)
+ {
+ // Entire header, xid and tail fits within this page
+ std::memcpy(_buff, (char*)rptr + rd_cnt, _txn_hdr._xidsize);
+ rd_cnt += _txn_hdr._xidsize;
+ std::memcpy((void*)&_txn_tail, (char*)rptr + rd_cnt, sizeof(_txn_tail));
+ rd_cnt += sizeof(_txn_tail);
+ chk_tail();
+ }
+ else if (hdr_xid_dblks <= max_size_dblks)
+ {
+ // Entire header and xid fit within this page, tail split
+ std::memcpy(_buff, (char*)rptr + rd_cnt, _txn_hdr._xidsize);
+ rd_cnt += _txn_hdr._xidsize;
+ const std::size_t tail_rem = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ if (tail_rem)
+ {
+ std::memcpy((void*)&_txn_tail, (char*)rptr + rd_cnt, tail_rem);
+ rd_cnt += tail_rem;
+ }
+ }
+ else
+ {
+ // Header fits within this page, xid split
+ const std::size_t xid_cp_size = (max_size_dblks * JRNL_DBLK_SIZE) - rd_cnt;
+ std::memcpy(_buff, (char*)rptr + rd_cnt, xid_cp_size);
+ rd_cnt += xid_cp_size;
+ }
+ }
+ return size_dblks(rd_cnt);
+}
+
+bool
+txn_rec::rcv_decode(rec_hdr h, std::ifstream* ifsp, std::size_t& rec_offs)
+{
+ if (rec_offs == 0)
+ {
+ // Read header, allocate for xid
+ _txn_hdr.hdr_copy(h);
+#if defined(JRNL_BIG_ENDIAN) && defined(JRNL_32_BIT)
+ ifsp->ignore(sizeof(u_int32_t)); // _filler0
+#endif
+ ifsp->read((char*)&_txn_hdr._xidsize, sizeof(std::size_t));
+#if defined(JRNL_LITTLE_ENDIAN) && defined(JRNL_32_BIT)
+ ifsp->ignore(sizeof(u_int32_t)); // _filler0
+#endif
+ rec_offs = sizeof(_txn_hdr);
+ _buff = std::malloc(_txn_hdr._xidsize);
+ MALLOC_CHK(_buff, "_buff", "txn_rec", "rcv_decode");
+ }
+ if (rec_offs < sizeof(_txn_hdr) + _txn_hdr._xidsize)
+ {
+ // Read xid (or continue reading xid)
+ std::size_t offs = rec_offs - sizeof(_txn_hdr);
+ ifsp->read((char*)_buff + offs, _txn_hdr._xidsize - offs);
+ std::size_t size_read = ifsp->gcount();
+ rec_offs += size_read;
+ if (size_read < _txn_hdr._xidsize - offs)
+ {
+ assert(ifsp->eof());
+ // As we may have read past eof, turn off fail bit
+ ifsp->clear(ifsp->rdstate()&(~std::ifstream::failbit));
+ assert(!ifsp->fail() && !ifsp->bad());
+ return false;
+ }
+ }
+ if (rec_offs < sizeof(_txn_hdr) + _txn_hdr._xidsize + sizeof(rec_tail))
+ {
+ // Read tail (or continue reading tail)
+ std::size_t offs = rec_offs - sizeof(_txn_hdr) - _txn_hdr._xidsize;
+ ifsp->read((char*)&_txn_tail + offs, sizeof(rec_tail) - offs);
+ std::size_t size_read = ifsp->gcount();
+ rec_offs += size_read;
+ if (size_read < sizeof(rec_tail) - offs)
+ {
+ assert(ifsp->eof());
+ // As we may have read past eof, turn off fail bit
+ ifsp->clear(ifsp->rdstate()&(~std::ifstream::failbit));
+ assert(!ifsp->fail() && !ifsp->bad());
+ return false;
+ }
+ }
+ ifsp->ignore(rec_size_dblks() * JRNL_DBLK_SIZE - rec_size());
+ chk_tail(); // Throws if tail invalid or record incomplete
+ assert(!ifsp->fail() && !ifsp->bad());
+ return true;
+}
+
+std::size_t
+txn_rec::get_xid(void** const xidpp)
+{
+ if (!_buff)
+ {
+ *xidpp = 0;
+ return 0;
+ }
+ *xidpp = _buff;
+ return _txn_hdr._xidsize;
+}
+
+std::string&
+txn_rec::str(std::string& str) const
+{
+ std::ostringstream oss;
+ if (_txn_hdr._magic == RHM_JDAT_TXA_MAGIC)
+ oss << "dtxa_rec: m=" << _txn_hdr._magic;
+ else
+ oss << "dtxc_rec: m=" << _txn_hdr._magic;
+ oss << " v=" << (int)_txn_hdr._version;
+ oss << " rid=" << _txn_hdr._rid;
+ oss << " xid=\"" << _xidp << "\"";
+ str.append(oss.str());
+ return str;
+}
+
+std::size_t
+txn_rec::xid_size() const
+{
+ return _txn_hdr._xidsize;
+}
+
+std::size_t
+txn_rec::rec_size() const
+{
+ return txn_hdr::size() + _txn_hdr._xidsize + rec_tail::size();
+}
+
+void
+txn_rec::chk_hdr() const
+{
+ jrec::chk_hdr(_txn_hdr);
+ if (_txn_hdr._magic != RHM_JDAT_TXA_MAGIC && _txn_hdr._magic != RHM_JDAT_TXC_MAGIC)
+ {
+ std::ostringstream oss;
+ oss << std::hex << std::setfill('0');
+ oss << "dtx magic: rid=0x" << std::setw(16) << _txn_hdr._rid;
+ oss << ": expected=(0x" << std::setw(8) << RHM_JDAT_TXA_MAGIC;
+ oss << " or 0x" << RHM_JDAT_TXC_MAGIC;
+ oss << ") read=0x" << std::setw(2) << (int)_txn_hdr._magic;
+ throw jexception(jerrno::JERR_JREC_BADRECHDR, oss.str(), "txn_rec", "chk_hdr");
+ }
+}
+
+void
+txn_rec::chk_hdr(u_int64_t rid) const
+{
+ chk_hdr();
+ jrec::chk_rid(_txn_hdr, rid);
+}
+
+void
+txn_rec::chk_tail() const
+{
+ jrec::chk_tail(_txn_tail, _txn_hdr);
+}
+
+void
+txn_rec::clean()
+{
+ // clean up allocated memory here
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/txn_rec.h b/cpp/src/qpid/legacystore/jrnl/txn_rec.h
new file mode 100644
index 0000000000..1a49df1c96
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/txn_rec.h
@@ -0,0 +1,101 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file txn_rec.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * This file contains the code for the mrg::journal::txn_rec (journal data
+ * record) class. See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_TXN_REC_H
+#define QPID_LEGACYSTORE_JRNL_TXN_REC_H
+
+namespace mrg
+{
+namespace journal
+{
+class txn_rec;
+}
+}
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/jrec.h"
+#include "qpid/legacystore/jrnl/txn_hdr.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class txn_rec
+ * \brief Class to handle a single journal DTX commit or abort record.
+ */
+ class txn_rec : public jrec
+ {
+ private:
+ txn_hdr _txn_hdr; ///< transaction header
+ const void* _xidp; ///< xid pointer for encoding (writing to disk)
+ void* _buff; ///< Pointer to buffer to receive data read from disk
+ rec_tail _txn_tail; ///< Record tail
+
+ public:
+ // constructor used for read operations and xid must have memory allocated
+ txn_rec();
+ // constructor used for write operations, where xid already exists
+ txn_rec(const u_int32_t magic, const u_int64_t rid, const void* const xidp,
+ const std::size_t xidlen, const bool owi);
+ virtual ~txn_rec();
+
+ // Prepare instance for use in reading data from journal
+ void reset(const u_int32_t magic);
+ // Prepare instance for use in writing data to journal
+ void reset(const u_int32_t magic, const u_int64_t rid, const void* const xidp,
+ const std::size_t xidlen, const bool owi);
+ u_int32_t encode(void* wptr, u_int32_t rec_offs_dblks, u_int32_t max_size_dblks);
+ u_int32_t decode(rec_hdr& h, void* rptr, u_int32_t rec_offs_dblks,
+ u_int32_t max_size_dblks);
+ // Decode used for recover
+ bool rcv_decode(rec_hdr h, std::ifstream* ifsp, std::size_t& rec_offs);
+
+ std::size_t get_xid(void** const xidpp);
+ std::string& str(std::string& str) const;
+ inline std::size_t data_size() const { return 0; } // This record never carries data
+ std::size_t xid_size() const;
+ std::size_t rec_size() const;
+ inline u_int64_t rid() const { return _txn_hdr._rid; }
+
+ private:
+ void chk_hdr() const;
+ void chk_hdr(u_int64_t rid) const;
+ void chk_tail() const;
+ virtual void clean();
+ }; // class txn_rec
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_TXN_REC_H
diff --git a/cpp/src/qpid/legacystore/jrnl/wmgr.cpp b/cpp/src/qpid/legacystore/jrnl/wmgr.cpp
new file mode 100644
index 0000000000..4353fcfbca
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/wmgr.cpp
@@ -0,0 +1,1051 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file wmgr.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::wmgr (write manager). See
+ * comments in file wmgr.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/wmgr.h"
+
+#include <cassert>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include "qpid/legacystore/jrnl/file_hdr.h"
+#include "qpid/legacystore/jrnl/jcntl.h"
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include <sstream>
+
+namespace mrg
+{
+namespace journal
+{
+
+wmgr::wmgr(jcntl* jc, enq_map& emap, txn_map& tmap, wrfc& wrfc):
+ pmgr(jc, emap, tmap),
+ _wrfc(wrfc),
+ _max_dtokpp(0),
+ _max_io_wait_us(0),
+ _fhdr_base_ptr(0),
+ _fhdr_ptr_arr(0),
+ _fhdr_aio_cb_arr(0),
+ _cached_offset_dblks(0),
+ _jfsize_dblks(0),
+ _jfsize_pgs(0),
+ _num_jfiles(0),
+ _enq_busy(false),
+ _deq_busy(false),
+ _abort_busy(false),
+ _commit_busy(false),
+ _txn_pending_set()
+{}
+
+wmgr::wmgr(jcntl* jc, enq_map& emap, txn_map& tmap, wrfc& wrfc,
+ const u_int32_t max_dtokpp, const u_int32_t max_iowait_us):
+ pmgr(jc, emap, tmap /* , dtoklp */),
+ _wrfc(wrfc),
+ _max_dtokpp(max_dtokpp),
+ _max_io_wait_us(max_iowait_us),
+ _fhdr_base_ptr(0),
+ _fhdr_ptr_arr(0),
+ _fhdr_aio_cb_arr(0),
+ _cached_offset_dblks(0),
+ _jfsize_dblks(0),
+ _jfsize_pgs(0),
+ _num_jfiles(0),
+ _enq_busy(false),
+ _deq_busy(false),
+ _abort_busy(false),
+ _commit_busy(false),
+ _txn_pending_set()
+{}
+
+wmgr::~wmgr()
+{
+ wmgr::clean();
+}
+
+void
+wmgr::initialize(aio_callback* const cbp, const u_int32_t wcache_pgsize_sblks,
+ const u_int16_t wcache_num_pages, const u_int32_t max_dtokpp, const u_int32_t max_iowait_us,
+ std::size_t eo)
+{
+ _enq_busy = false;
+ _deq_busy = false;
+ _abort_busy = false;
+ _commit_busy = false;
+ _max_dtokpp = max_dtokpp;
+ _max_io_wait_us = max_iowait_us;
+
+ initialize(cbp, wcache_pgsize_sblks, wcache_num_pages);
+
+ _jfsize_dblks = _jc->jfsize_sblks() * JRNL_SBLK_SIZE;
+ _jfsize_pgs = _jc->jfsize_sblks() / _cache_pgsize_sblks;
+ assert(_jc->jfsize_sblks() % JRNL_RMGR_PAGE_SIZE == 0);
+
+ if (eo)
+ {
+ const u_int32_t wr_pg_size_dblks = _cache_pgsize_sblks * JRNL_SBLK_SIZE;
+ u_int32_t data_dblks = (eo / JRNL_DBLK_SIZE) - 4; // 4 dblks for file hdr
+ _pg_cntr = data_dblks / wr_pg_size_dblks;
+ _pg_offset_dblks = data_dblks - (_pg_cntr * wr_pg_size_dblks);
+ }
+}
+
+iores
+wmgr::enqueue(const void* const data_buff, const std::size_t tot_data_len,
+ const std::size_t this_data_len, data_tok* dtokp, const void* const xid_ptr,
+ const std::size_t xid_len, const bool transient, const bool external)
+{
+ if (xid_len)
+ assert(xid_ptr != 0);
+
+ if (_deq_busy || _abort_busy || _commit_busy)
+ return RHM_IORES_BUSY;
+
+ if (this_data_len != tot_data_len && !external)
+ return RHM_IORES_NOTIMPL;
+
+ iores res = pre_write_check(WMGR_ENQUEUE, dtokp, xid_len, tot_data_len, external);
+ if (res != RHM_IORES_SUCCESS)
+ return res;
+
+ bool cont = false;
+ if (_enq_busy) // If enqueue() exited last time with RHM_IORES_FULL or RHM_IORES_PAGE_AIOWAIT
+ {
+ if (dtokp->wstate() == data_tok::ENQ_PART)
+ cont = true;
+ else
+ {
+ std::ostringstream oss;
+ oss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_ENQDISCONT, oss.str(), "wmgr", "enqueue");
+ }
+ }
+
+ u_int64_t rid = (dtokp->external_rid() | cont) ? dtokp->rid() : _wrfc.get_incr_rid();
+ _enq_rec.reset(rid, data_buff, tot_data_len, xid_ptr, xid_len, _wrfc.owi(), transient,
+ external);
+ if (!cont)
+ {
+ dtokp->set_rid(rid);
+ dtokp->set_dequeue_rid(0);
+ if (xid_len)
+ dtokp->set_xid(xid_ptr, xid_len);
+ else
+ dtokp->clear_xid();
+ _enq_busy = true;
+ }
+ bool done = false;
+ while (!done)
+ {
+ assert(_pg_offset_dblks < _cache_pgsize_sblks * JRNL_SBLK_SIZE);
+ void* wptr = (void*)((char*)_page_ptr_arr[_pg_index] + _pg_offset_dblks * JRNL_DBLK_SIZE);
+ u_int32_t data_offs_dblks = dtokp->dblocks_written();
+ u_int32_t ret = _enq_rec.encode(wptr, data_offs_dblks,
+ (_cache_pgsize_sblks * JRNL_SBLK_SIZE) - _pg_offset_dblks);
+
+ // Remember fid which contains the record header in case record is split over several files
+ if (data_offs_dblks == 0)
+ dtokp->set_fid(_wrfc.index());
+ _pg_offset_dblks += ret;
+ _cached_offset_dblks += ret;
+ dtokp->incr_dblocks_written(ret);
+ dtokp->incr_pg_cnt();
+ _page_cb_arr[_pg_index]._pdtokl->push_back(dtokp);
+
+ // Is the encoding of this record complete?
+ if (dtokp->dblocks_written() >= _enq_rec.rec_size_dblks())
+ {
+ // TODO: Incorrect - must set state to ENQ_CACHED; ENQ_SUBM is set when AIO returns.
+ dtokp->set_wstate(data_tok::ENQ_SUBM);
+ dtokp->set_dsize(tot_data_len);
+ // Only add this data token to page token list when submit is complete, this way
+ // long multi-page messages have their token on the page containing the END of the
+ // message. AIO callbacks will then only process this token when entire message is
+ // enqueued.
+ _wrfc.incr_enqcnt(dtokp->fid());
+
+ if (xid_len) // If part of transaction, add to transaction map
+ {
+ std::string xid((const char*)xid_ptr, xid_len);
+ _tmap.insert_txn_data(xid, txn_data(rid, 0, dtokp->fid(), true));
+ }
+ else
+ {
+ if (_emap.insert_pfid(rid, dtokp->fid()) < enq_map::EMAP_OK) // fail
+ {
+ // The only error code emap::insert_pfid() returns is enq_map::EMAP_DUP_RID.
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid << " _pfid=0x" << dtokp->fid();
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "wmgr", "enqueue");
+ }
+ }
+
+ done = true;
+ }
+ else
+ dtokp->set_wstate(data_tok::ENQ_PART);
+
+ file_header_check(rid, cont, _enq_rec.rec_size_dblks() - data_offs_dblks);
+ flush_check(res, cont, done);
+ }
+ if (dtokp->wstate() >= data_tok::ENQ_SUBM)
+ _enq_busy = false;
+ return res;
+}
+
+iores
+wmgr::dequeue(data_tok* dtokp, const void* const xid_ptr, const std::size_t xid_len, const bool txn_coml_commit)
+{
+ if (xid_len)
+ assert(xid_ptr != 0);
+
+ if (_enq_busy || _abort_busy || _commit_busy)
+ return RHM_IORES_BUSY;
+
+ iores res = pre_write_check(WMGR_DEQUEUE, dtokp);
+ if (res != RHM_IORES_SUCCESS)
+ return res;
+
+ bool cont = false;
+ if (_deq_busy) // If dequeue() exited last time with RHM_IORES_FULL or RHM_IORES_PAGE_AIOWAIT
+ {
+ if (dtokp->wstate() == data_tok::DEQ_PART)
+ cont = true;
+ else
+ {
+ std::ostringstream oss;
+ oss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_DEQDISCONT, oss.str(), "wmgr", "dequeue");
+ }
+ }
+
+ const bool ext_rid = dtokp->external_rid();
+ u_int64_t rid = (ext_rid | cont) ? dtokp->rid() : _wrfc.get_incr_rid();
+ u_int64_t dequeue_rid = (ext_rid | cont) ? dtokp->dequeue_rid() : dtokp->rid();
+ _deq_rec.reset(rid, dequeue_rid, xid_ptr, xid_len, _wrfc.owi(), txn_coml_commit);
+ if (!cont)
+ {
+ if (!ext_rid)
+ {
+ dtokp->set_rid(rid);
+ dtokp->set_dequeue_rid(dequeue_rid);
+ }
+ if (xid_len)
+ dtokp->set_xid(xid_ptr, xid_len);
+ else
+ dtokp->clear_xid();
+ dequeue_check(dtokp->xid(), dequeue_rid);
+ dtokp->set_dblocks_written(0); // Reset dblks_written from previous op
+ _deq_busy = true;
+ }
+ bool done = false;
+ while (!done)
+ {
+ assert(_pg_offset_dblks < _cache_pgsize_sblks * JRNL_SBLK_SIZE);
+ void* wptr = (void*)((char*)_page_ptr_arr[_pg_index] + _pg_offset_dblks * JRNL_DBLK_SIZE);
+ u_int32_t data_offs_dblks = dtokp->dblocks_written();
+ u_int32_t ret = _deq_rec.encode(wptr, data_offs_dblks,
+ (_cache_pgsize_sblks * JRNL_SBLK_SIZE) - _pg_offset_dblks);
+
+ // Remember fid which contains the record header in case record is split over several files
+ if (data_offs_dblks == 0)
+ dtokp->set_fid(_wrfc.index());
+ _pg_offset_dblks += ret;
+ _cached_offset_dblks += ret;
+ dtokp->incr_dblocks_written(ret);
+ dtokp->incr_pg_cnt();
+ _page_cb_arr[_pg_index]._pdtokl->push_back(dtokp);
+
+ // Is the encoding of this record complete?
+ if (dtokp->dblocks_written() >= _deq_rec.rec_size_dblks())
+ {
+ // TODO: Incorrect - must set state to ENQ_CACHED; ENQ_SUBM is set when AIO returns.
+ dtokp->set_wstate(data_tok::DEQ_SUBM);
+
+ if (xid_len) // If part of transaction, add to transaction map
+ {
+ // If the enqueue is part of a pending txn, it will not yet be in emap
+ _emap.lock(dequeue_rid); // ignore rid not found error
+ std::string xid((const char*)xid_ptr, xid_len);
+ _tmap.insert_txn_data(xid, txn_data(rid, dequeue_rid, dtokp->fid(), false));
+ }
+ else
+ {
+ int16_t fid = _emap.get_remove_pfid(dtokp->dequeue_rid());
+ if (fid < enq_map::EMAP_OK) // fail
+ {
+ if (fid == enq_map::EMAP_RID_NOT_FOUND)
+ {
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "wmgr", "dequeue");
+ }
+ if (fid == enq_map::EMAP_LOCKED)
+ {
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "wmgr", "dequeue");
+ }
+ }
+ _wrfc.decr_enqcnt(fid);
+ }
+
+ done = true;
+ }
+ else
+ dtokp->set_wstate(data_tok::DEQ_PART);
+
+ file_header_check(rid, cont, _deq_rec.rec_size_dblks() - data_offs_dblks);
+ flush_check(res, cont, done);
+ }
+ if (dtokp->wstate() >= data_tok::DEQ_SUBM)
+ _deq_busy = false;
+ return res;
+}
+
+iores
+wmgr::abort(data_tok* dtokp, const void* const xid_ptr, const std::size_t xid_len)
+{
+ // commit and abort MUST have a valid xid
+ assert(xid_ptr != 0 && xid_len > 0);
+
+ if (_enq_busy || _deq_busy || _commit_busy)
+ return RHM_IORES_BUSY;
+
+ iores res = pre_write_check(WMGR_ABORT, dtokp);
+ if (res != RHM_IORES_SUCCESS)
+ return res;
+
+ bool cont = false;
+ if (_abort_busy) // If abort() exited last time with RHM_IORES_FULL or RHM_IORES_PAGE_AIOWAIT
+ {
+ if (dtokp->wstate() == data_tok::ABORT_PART)
+ cont = true;
+ else
+ {
+ std::ostringstream oss;
+ oss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_DEQDISCONT, oss.str(), "wmgr", "abort");
+ }
+ }
+
+ u_int64_t rid = (dtokp->external_rid() | cont) ? dtokp->rid() : _wrfc.get_incr_rid();
+ _txn_rec.reset(RHM_JDAT_TXA_MAGIC, rid, xid_ptr, xid_len, _wrfc.owi());
+ if (!cont)
+ {
+ dtokp->set_rid(rid);
+ dtokp->set_dequeue_rid(0);
+ dtokp->set_xid(xid_ptr, xid_len);
+ dtokp->set_dblocks_written(0); // Reset dblks_written from previous op
+ _abort_busy = true;
+ }
+ bool done = false;
+ while (!done)
+ {
+ assert(_pg_offset_dblks < _cache_pgsize_sblks * JRNL_SBLK_SIZE);
+ void* wptr = (void*)((char*)_page_ptr_arr[_pg_index] + _pg_offset_dblks * JRNL_DBLK_SIZE);
+ u_int32_t data_offs_dblks = dtokp->dblocks_written();
+ u_int32_t ret = _txn_rec.encode(wptr, data_offs_dblks,
+ (_cache_pgsize_sblks * JRNL_SBLK_SIZE) - _pg_offset_dblks);
+
+ // Remember fid which contains the record header in case record is split over several files
+ if (data_offs_dblks == 0)
+ dtokp->set_fid(_wrfc.index());
+ _pg_offset_dblks += ret;
+ _cached_offset_dblks += ret;
+ dtokp->incr_dblocks_written(ret);
+ dtokp->incr_pg_cnt();
+ _page_cb_arr[_pg_index]._pdtokl->push_back(dtokp);
+
+ // Is the encoding of this record complete?
+ if (dtokp->dblocks_written() >= _txn_rec.rec_size_dblks())
+ {
+ dtokp->set_wstate(data_tok::ABORT_SUBM);
+
+ // Delete this txn from tmap, unlock any locked records in emap
+ std::string xid((const char*)xid_ptr, xid_len);
+ txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
+ for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
+ {
+ if (!itr->_enq_flag)
+ _emap.unlock(itr->_drid); // ignore rid not found error
+ if (itr->_enq_flag)
+ _wrfc.decr_enqcnt(itr->_pfid);
+ }
+ std::pair<std::set<std::string>::iterator, bool> res = _txn_pending_set.insert(xid);
+ if (!res.second)
+ {
+ std::ostringstream oss;
+ oss << std::hex << "_txn_pending_set: xid=\"" << xid << "\"";
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "wmgr", "abort");
+ }
+
+ done = true;
+ }
+ else
+ dtokp->set_wstate(data_tok::ABORT_PART);
+
+ file_header_check(rid, cont, _txn_rec.rec_size_dblks() - data_offs_dblks);
+ flush_check(res, cont, done);
+ }
+ if (dtokp->wstate() >= data_tok::ABORT_SUBM)
+ _abort_busy = false;
+ return res;
+}
+
+iores
+wmgr::commit(data_tok* dtokp, const void* const xid_ptr, const std::size_t xid_len)
+{
+ // commit and abort MUST have a valid xid
+ assert(xid_ptr != 0 && xid_len > 0);
+
+ if (_enq_busy || _deq_busy || _abort_busy)
+ return RHM_IORES_BUSY;
+
+ iores res = pre_write_check(WMGR_COMMIT, dtokp);
+ if (res != RHM_IORES_SUCCESS)
+ return res;
+
+ bool cont = false;
+ if (_commit_busy) // If commit() exited last time with RHM_IORES_FULL or RHM_IORES_PAGE_AIOWAIT
+ {
+ if (dtokp->wstate() == data_tok::COMMIT_PART)
+ cont = true;
+ else
+ {
+ std::ostringstream oss;
+ oss << "This data_tok: id=" << dtokp->id() << " state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_DEQDISCONT, oss.str(), "wmgr", "commit");
+ }
+ }
+
+ u_int64_t rid = (dtokp->external_rid() | cont) ? dtokp->rid() : _wrfc.get_incr_rid();
+ _txn_rec.reset(RHM_JDAT_TXC_MAGIC, rid, xid_ptr, xid_len, _wrfc.owi());
+ if (!cont)
+ {
+ dtokp->set_rid(rid);
+ dtokp->set_dequeue_rid(0);
+ dtokp->set_xid(xid_ptr, xid_len);
+ dtokp->set_dblocks_written(0); // Reset dblks_written from previous op
+ _commit_busy = true;
+ }
+ bool done = false;
+ while (!done)
+ {
+ assert(_pg_offset_dblks < _cache_pgsize_sblks * JRNL_SBLK_SIZE);
+ void* wptr = (void*)((char*)_page_ptr_arr[_pg_index] + _pg_offset_dblks * JRNL_DBLK_SIZE);
+ u_int32_t data_offs_dblks = dtokp->dblocks_written();
+ u_int32_t ret = _txn_rec.encode(wptr, data_offs_dblks,
+ (_cache_pgsize_sblks * JRNL_SBLK_SIZE) - _pg_offset_dblks);
+
+ // Remember fid which contains the record header in case record is split over several files
+ if (data_offs_dblks == 0)
+ dtokp->set_fid(_wrfc.index());
+ _pg_offset_dblks += ret;
+ _cached_offset_dblks += ret;
+ dtokp->incr_dblocks_written(ret);
+ dtokp->incr_pg_cnt();
+ _page_cb_arr[_pg_index]._pdtokl->push_back(dtokp);
+
+ // Is the encoding of this record complete?
+ if (dtokp->dblocks_written() >= _txn_rec.rec_size_dblks())
+ {
+ dtokp->set_wstate(data_tok::COMMIT_SUBM);
+
+ // Delete this txn from tmap, process records into emap
+ std::string xid((const char*)xid_ptr, xid_len);
+ txn_data_list tdl = _tmap.get_remove_tdata_list(xid); // tdl will be empty if xid not found
+ for (tdl_itr itr = tdl.begin(); itr != tdl.end(); itr++)
+ {
+ if (itr->_enq_flag) // txn enqueue
+ {
+ if (_emap.insert_pfid(itr->_rid, itr->_pfid) < enq_map::EMAP_OK) // fail
+ {
+ // The only error code emap::insert_pfid() returns is enq_map::EMAP_DUP_RID.
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << itr->_rid << " _pfid=0x" << itr->_pfid;
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "wmgr", "commit");
+ }
+ }
+ else // txn dequeue
+ {
+ int16_t fid = _emap.get_remove_pfid(itr->_drid, true);
+ if (fid < enq_map::EMAP_OK) // fail
+ {
+ if (fid == enq_map::EMAP_RID_NOT_FOUND)
+ {
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "wmgr", "dequeue");
+ }
+ if (fid == enq_map::EMAP_LOCKED)
+ {
+ std::ostringstream oss;
+ oss << std::hex << "rid=0x" << rid;
+ throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "wmgr", "dequeue");
+ }
+ }
+ _wrfc.decr_enqcnt(fid);
+ }
+ }
+ std::pair<std::set<std::string>::iterator, bool> res = _txn_pending_set.insert(xid);
+ if (!res.second)
+ {
+ std::ostringstream oss;
+ oss << std::hex << "_txn_pending_set: xid=\"" << xid << "\"";
+ throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "wmgr", "commit");
+ }
+
+ done = true;
+ }
+ else
+ dtokp->set_wstate(data_tok::COMMIT_PART);
+
+ file_header_check(rid, cont, _txn_rec.rec_size_dblks() - data_offs_dblks);
+ flush_check(res, cont, done);
+ }
+ if (dtokp->wstate() >= data_tok::COMMIT_SUBM)
+ _commit_busy = false;
+ return res;
+}
+
+void
+wmgr::file_header_check(const u_int64_t rid, const bool cont, const u_int32_t rec_dblks_rem)
+{
+ // Has the file header been written (i.e. write pointers still at 0)?
+ if (_wrfc.is_void())
+ {
+ bool file_fit = rec_dblks_rem <= _jfsize_dblks;
+ bool file_full = rec_dblks_rem == _jfsize_dblks;
+ std::size_t fro = 0;
+ if (cont)
+ {
+ if (file_fit && !file_full)
+ fro = (rec_dblks_rem + JRNL_SBLK_SIZE) * JRNL_DBLK_SIZE;
+ }
+ else
+ fro = JRNL_SBLK_SIZE * JRNL_DBLK_SIZE;
+ write_fhdr(rid, _wrfc.index(), _wrfc.index(), fro);
+ }
+}
+
+void
+wmgr::flush_check(iores& res, bool& cont, bool& done)
+{
+ // Is page is full, flush
+ if (_pg_offset_dblks >= _cache_pgsize_sblks * JRNL_SBLK_SIZE)
+ {
+ res = write_flush();
+ assert(res == RHM_IORES_SUCCESS);
+
+ if (_page_cb_arr[_pg_index]._state == AIO_PENDING && !done)
+ {
+ res = RHM_IORES_PAGE_AIOWAIT;
+ done = true;
+ }
+
+ // If file is full, rotate to next file
+ if (_pg_cntr >= _jfsize_pgs)
+ {
+ iores rfres = rotate_file();
+ if (rfres != RHM_IORES_SUCCESS)
+ res = rfres;
+ if (!done)
+ {
+ if (rfres == RHM_IORES_SUCCESS)
+ cont = true;
+ else
+ done = true;
+ }
+ }
+ }
+}
+
+iores
+wmgr::flush()
+{
+ iores res = write_flush();
+ if (_pg_cntr >= _jfsize_pgs)
+ {
+ iores rfres = rotate_file();
+ if (rfres != RHM_IORES_SUCCESS)
+ res = rfres;
+ }
+ return res;
+}
+
+iores
+wmgr::write_flush()
+{
+ iores res = RHM_IORES_SUCCESS;
+ // Don't bother flushing an empty page or one that is still in state AIO_PENDING
+ if (_cached_offset_dblks)
+ {
+ if (_page_cb_arr[_pg_index]._state == AIO_PENDING)
+ res = RHM_IORES_PAGE_AIOWAIT;
+ else
+ {
+ if (_page_cb_arr[_pg_index]._state != IN_USE)
+ {
+ std::ostringstream oss;
+ oss << "pg_index=" << _pg_index << " state=" << _page_cb_arr[_pg_index].state_str();
+ throw jexception(jerrno::JERR_WMGR_BADPGSTATE, oss.str(), "wmgr",
+ "write_flush");
+ }
+
+ // Send current page using AIO
+
+ // In manual flushes, dblks may not coincide with sblks, add filler records ("RHMx")
+ // if necessary.
+ dblk_roundup();
+
+ std::size_t pg_offs = (_pg_offset_dblks - _cached_offset_dblks) * JRNL_DBLK_SIZE;
+ aio_cb* aiocbp = &_aio_cb_arr[_pg_index];
+ aio::prep_pwrite_2(aiocbp, _wrfc.fh(),
+ (char*)_page_ptr_arr[_pg_index] + pg_offs, _cached_offset_dblks * JRNL_DBLK_SIZE,
+ _wrfc.subm_offs());
+ page_cb* pcbp = (page_cb*)(aiocbp->data); // This page control block (pcb)
+ pcbp->_wdblks = _cached_offset_dblks;
+ pcbp->_wfh = _wrfc.file_controller();
+ if (aio::submit(_ioctx, 1, &aiocbp) < 0)
+ throw jexception(jerrno::JERR__AIO, "wmgr", "write_flush");
+ _wrfc.add_subm_cnt_dblks(_cached_offset_dblks);
+ _wrfc.incr_aio_cnt();
+ _aio_evt_rem++;
+ _cached_offset_dblks = 0;
+ _jc->instr_incr_outstanding_aio_cnt();
+
+ rotate_page(); // increments _pg_index, resets _pg_offset_dblks if req'd
+ if (_page_cb_arr[_pg_index]._state == UNUSED)
+ _page_cb_arr[_pg_index]._state = IN_USE;
+ }
+ }
+ get_events(UNUSED, 0);
+ if (_page_cb_arr[_pg_index]._state == UNUSED)
+ _page_cb_arr[_pg_index]._state = IN_USE;
+ return res;
+}
+
+iores
+wmgr::rotate_file()
+{
+ _pg_cntr = 0;
+ iores res = _wrfc.rotate();
+ _jc->chk_wr_frot();
+ return res;
+}
+
+int32_t
+wmgr::get_events(page_state state, timespec* const timeout, bool flush)
+{
+ if (_aio_evt_rem == 0) // no events to get
+ return 0;
+
+ int ret = 0;
+ if ((ret = aio::getevents(_ioctx, flush ? _aio_evt_rem : 1, _aio_evt_rem/*_cache_num_pages + _jc->num_jfiles()*/, _aio_event_arr, timeout)) < 0)
+ {
+ if (ret == -EINTR) // Interrupted by signal
+ return 0;
+ std::ostringstream oss;
+ oss << "io_getevents() failed: " << std::strerror(-ret) << " (" << ret << ")";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "wmgr", "get_events");
+ }
+
+ if (ret == 0 && timeout)
+ return jerrno::AIO_TIMEOUT;
+
+ int32_t tot_data_toks = 0;
+ for (int i=0; i<ret; i++) // Index of returned AIOs
+ {
+ if (_aio_evt_rem == 0)
+ {
+ std::ostringstream oss;
+ oss << "_aio_evt_rem; evt " << (i + 1) << " of " << ret;
+ throw jexception(jerrno::JERR__UNDERFLOW, oss.str(), "wmgr", "get_events");
+ }
+ _aio_evt_rem--;
+ aio_cb* aiocbp = _aio_event_arr[i].obj; // This I/O control block (iocb)
+ page_cb* pcbp = (page_cb*)(aiocbp->data); // This page control block (pcb)
+ long aioret = (long)_aio_event_arr[i].res;
+ if (aioret < 0)
+ {
+ std::ostringstream oss;
+ oss << "AIO write operation failed: " << std::strerror(-aioret) << " (" << aioret << ") [";
+ if (pcbp)
+ oss << "pg=" << pcbp->_index;
+ else
+ {
+ file_hdr* fhp = (file_hdr*)aiocbp->u.c.buf;
+ oss << "fid=" << fhp->_pfid;
+ }
+ oss << " size=" << aiocbp->u.c.nbytes;
+ oss << " offset=" << aiocbp->u.c.offset << " fh=" << aiocbp->aio_fildes << "]";
+ throw jexception(jerrno::JERR__AIO, oss.str(), "wmgr", "get_events");
+ }
+ if (pcbp) // Page writes have pcb
+ {
+ u_int32_t s = pcbp->_pdtokl->size();
+ std::vector<data_tok*> dtokl;
+ dtokl.reserve(s);
+ for (u_int32_t k=0; k<s; k++)
+ {
+ data_tok* dtokp = pcbp->_pdtokl->at(k);
+ if (dtokp->decr_pg_cnt() == 0)
+ {
+ std::set<std::string>::iterator it;
+ switch (dtokp->wstate())
+ {
+ case data_tok::ENQ_SUBM:
+ dtokl.push_back(dtokp);
+ tot_data_toks++;
+ dtokp->set_wstate(data_tok::ENQ);
+ if (dtokp->has_xid())
+ // Ignoring return value here. A non-zero return can signify that the transaction
+ // has committed or aborted, and which was completed prior to the aio returning.
+ _tmap.set_aio_compl(dtokp->xid(), dtokp->rid());
+ break;
+ case data_tok::DEQ_SUBM:
+ dtokl.push_back(dtokp);
+ tot_data_toks++;
+ dtokp->set_wstate(data_tok::DEQ);
+ if (dtokp->has_xid())
+ // Ignoring return value - see note above.
+ _tmap.set_aio_compl(dtokp->xid(), dtokp->rid());
+ break;
+ case data_tok::ABORT_SUBM:
+ dtokl.push_back(dtokp);
+ tot_data_toks++;
+ dtokp->set_wstate(data_tok::ABORTED);
+ it = _txn_pending_set.find(dtokp->xid());
+ if (it == _txn_pending_set.end())
+ {
+ std::ostringstream oss;
+ oss << std::hex << "_txn_pending_set: abort xid=\"";
+ oss << dtokp->xid() << "\"";
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "wmgr",
+ "get_events");
+ }
+ _txn_pending_set.erase(it);
+ break;
+ case data_tok::COMMIT_SUBM:
+ dtokl.push_back(dtokp);
+ tot_data_toks++;
+ dtokp->set_wstate(data_tok::COMMITTED);
+ it = _txn_pending_set.find(dtokp->xid());
+ if (it == _txn_pending_set.end())
+ {
+ std::ostringstream oss;
+ oss << std::hex << "_txn_pending_set: commit xid=\"";
+ oss << dtokp->xid() << "\"";
+ throw jexception(jerrno::JERR_MAP_NOTFOUND, oss.str(), "wmgr",
+ "get_events");
+ }
+ _txn_pending_set.erase(it);
+ break;
+ case data_tok::ENQ_PART:
+ case data_tok::DEQ_PART:
+ case data_tok::ABORT_PART:
+ case data_tok::COMMIT_PART:
+ // ignore these
+ break;
+ default:
+ // throw for anything else
+ std::ostringstream oss;
+ oss << "dtok_id=" << dtokp->id() << " dtok_state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, oss.str(), "wmgr",
+ "get_events");
+ } // switch
+ } // if
+ } // for
+
+ // Increment the completed write offset
+ // NOTE: We cannot use _wrfc here, as it may have rotated since submitting count.
+ // Use stored pointer to fcntl in the pcb instead.
+ pcbp->_wfh->add_wr_cmpl_cnt_dblks(pcbp->_wdblks);
+ pcbp->_wfh->decr_aio_cnt();
+ _jc->instr_decr_outstanding_aio_cnt();
+
+ // Clean up this pcb's data_tok list
+ pcbp->_pdtokl->clear();
+ pcbp->_state = state;
+
+ // Perform AIO return callback
+ if (_cbp && tot_data_toks)
+ _cbp->wr_aio_cb(dtokl);
+ }
+ else // File header writes have no pcb
+ {
+ // get lfid from original file header record, update info for that lfid
+ file_hdr* fhp = (file_hdr*)aiocbp->u.c.buf;
+ u_int32_t lfid = fhp->_lfid;
+ fcntl* fcntlp = _jc->get_fcntlp(lfid);
+ fcntlp->add_wr_cmpl_cnt_dblks(JRNL_SBLK_SIZE);
+ fcntlp->decr_aio_cnt();
+ fcntlp->set_wr_fhdr_aio_outstanding(false);
+ }
+ }
+
+ return tot_data_toks;
+}
+
+bool
+wmgr::is_txn_synced(const std::string& xid)
+{
+ // Ignore xid not found error here
+ if (_tmap.is_txn_synced(xid) == txn_map::TMAP_NOT_SYNCED)
+ return false;
+ // Check for outstanding commit/aborts
+ std::set<std::string>::iterator it = _txn_pending_set.find(xid);
+ return it == _txn_pending_set.end();
+}
+
+void
+wmgr::initialize(aio_callback* const cbp, const u_int32_t wcache_pgsize_sblks, const u_int16_t wcache_num_pages)
+{
+ pmgr::initialize(cbp, wcache_pgsize_sblks, wcache_num_pages);
+ wmgr::clean();
+ _num_jfiles = _jc->num_jfiles();
+ if (::posix_memalign(&_fhdr_base_ptr, _sblksize, _sblksize * _num_jfiles))
+ {
+ wmgr::clean();
+ std::ostringstream oss;
+ oss << "posix_memalign(): blksize=" << _sblksize << " size=" << _sblksize;
+ oss << FORMAT_SYSERR(errno);
+ throw jexception(jerrno::JERR__MALLOC, oss.str(), "wmgr", "initialize");
+ }
+ _fhdr_ptr_arr = (void**)std::malloc(_num_jfiles * sizeof(void*));
+ MALLOC_CHK(_fhdr_ptr_arr, "_fhdr_ptr_arr", "wmgr", "initialize");
+ _fhdr_aio_cb_arr = (aio_cb**)std::malloc(sizeof(aio_cb*) * _num_jfiles);
+ MALLOC_CHK(_fhdr_aio_cb_arr, "_fhdr_aio_cb_arr", "wmgr", "initialize");
+ std::memset(_fhdr_aio_cb_arr, 0, sizeof(aio_cb*) * _num_jfiles);
+ for (u_int16_t i=0; i<_num_jfiles; i++)
+ {
+ _fhdr_ptr_arr[i] = (void*)((char*)_fhdr_base_ptr + _sblksize * i);
+ _fhdr_aio_cb_arr[i] = new aio_cb;
+ }
+ _page_cb_arr[0]._state = IN_USE;
+ _ddtokl.clear();
+ _cached_offset_dblks = 0;
+ _enq_busy = false;
+}
+
+iores
+wmgr::pre_write_check(const _op_type op, const data_tok* const dtokp,
+ const std::size_t xidsize, const std::size_t dsize, const bool external
+ ) const
+{
+ // Check status of current file
+ if (!_wrfc.is_wr_reset())
+ {
+ if (!_wrfc.wr_reset())
+ return RHM_IORES_FULL;
+ }
+
+ // Check status of current page is ok for writing
+ if (_page_cb_arr[_pg_index]._state != IN_USE)
+ {
+ if (_page_cb_arr[_pg_index]._state == UNUSED)
+ _page_cb_arr[_pg_index]._state = IN_USE;
+ else if (_page_cb_arr[_pg_index]._state == AIO_PENDING)
+ return RHM_IORES_PAGE_AIOWAIT;
+ else
+ {
+ std::ostringstream oss;
+ oss << "jrnl=" << _jc->id() << " op=" << _op_str[op];
+ oss << " index=" << _pg_index << " pg_state=" << _page_cb_arr[_pg_index].state_str();
+ throw jexception(jerrno::JERR_WMGR_BADPGSTATE, oss.str(), "wmgr", "pre_write_check");
+ }
+ }
+
+ // operation-specific checks
+ switch (op)
+ {
+ case WMGR_ENQUEUE:
+ {
+ // Check for enqueue reaching cutoff threshold
+ u_int32_t size_dblks = jrec::size_dblks(enq_rec::rec_size(xidsize, dsize,
+ external));
+ if (!_enq_busy && _wrfc.enq_threshold(_cached_offset_dblks + size_dblks))
+ return RHM_IORES_ENQCAPTHRESH;
+ if (!dtokp->is_writable())
+ {
+ std::ostringstream oss;
+ oss << "jrnl=" << _jc->id() << " op=" << _op_str[op];
+ oss << " dtok_id=" << dtokp->id() << " dtok_state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, oss.str(), "wmgr",
+ "pre_write_check");
+ }
+ }
+ break;
+ case WMGR_DEQUEUE:
+ if (!dtokp->is_dequeueable())
+ {
+ std::ostringstream oss;
+ oss << "jrnl=" << _jc->id() << " op=" << _op_str[op];
+ oss << " dtok_id=" << dtokp->id() << " dtok_state=" << dtokp->wstate_str();
+ throw jexception(jerrno::JERR_WMGR_BADDTOKSTATE, oss.str(), "wmgr",
+ "pre_write_check");
+ }
+ break;
+ case WMGR_ABORT:
+ break;
+ case WMGR_COMMIT:
+ break;
+ }
+
+ return RHM_IORES_SUCCESS;
+}
+
+void
+wmgr::dequeue_check(const std::string& xid, const u_int64_t drid)
+{
+ // First check emap
+ bool found = false;
+ int16_t fid = _emap.get_pfid(drid);
+ if (fid < enq_map::EMAP_OK) // fail
+ {
+ if (fid == enq_map::EMAP_RID_NOT_FOUND)
+ {
+ if (xid.size())
+ found = _tmap.data_exists(xid, drid);
+ }
+ else if (fid == enq_map::EMAP_LOCKED)
+ {
+ std::ostringstream oss;
+ oss << std::hex << "drid=0x" << drid;
+ throw jexception(jerrno::JERR_MAP_LOCKED, oss.str(), "wmgr", "dequeue_check");
+ }
+ }
+ else
+ found = true;
+ if (!found)
+ {
+ std::ostringstream oss;
+ oss << "jrnl=" << _jc->id() << " drid=0x" << std::hex << drid;
+ throw jexception(jerrno::JERR_WMGR_DEQRIDNOTENQ, oss.str(), "wmgr", "dequeue_check");
+ }
+}
+
+void
+wmgr::dblk_roundup()
+{
+ const u_int32_t xmagic = RHM_JDAT_EMPTY_MAGIC;
+ u_int32_t wdblks = jrec::size_blks(_cached_offset_dblks, JRNL_SBLK_SIZE) * JRNL_SBLK_SIZE;
+ while (_cached_offset_dblks < wdblks)
+ {
+ void* wptr = (void*)((char*)_page_ptr_arr[_pg_index] + _pg_offset_dblks * JRNL_DBLK_SIZE);
+ std::memcpy(wptr, (const void*)&xmagic, sizeof(xmagic));
+#ifdef RHM_CLEAN
+ std::memset((char*)wptr + sizeof(xmagic), RHM_CLEAN_CHAR, JRNL_DBLK_SIZE - sizeof(xmagic));
+#endif
+ _pg_offset_dblks++;
+ _cached_offset_dblks++;
+ }
+}
+
+void
+wmgr::write_fhdr(u_int64_t rid, u_int16_t fid, u_int16_t lid, std::size_t fro)
+{
+ file_hdr fhdr(RHM_JDAT_FILE_MAGIC, RHM_JDAT_VERSION, rid, fid, lid, fro, _wrfc.owi(), true);
+ std::memcpy(_fhdr_ptr_arr[fid], &fhdr, sizeof(fhdr));
+#ifdef RHM_CLEAN
+ std::memset((char*)_fhdr_ptr_arr[fid] + sizeof(fhdr), RHM_CLEAN_CHAR, _sblksize - sizeof(fhdr));
+#endif
+ aio_cb* aiocbp = _fhdr_aio_cb_arr[fid];
+ aio::prep_pwrite(aiocbp, _wrfc.fh(), _fhdr_ptr_arr[fid], _sblksize, 0);
+ if (aio::submit(_ioctx, 1, &aiocbp) < 0)
+ throw jexception(jerrno::JERR__AIO, "wmgr", "write_fhdr");
+ _aio_evt_rem++;
+ _wrfc.add_subm_cnt_dblks(JRNL_SBLK_SIZE);
+ _wrfc.incr_aio_cnt();
+ _wrfc.file_controller()->set_wr_fhdr_aio_outstanding(true);
+}
+
+void
+wmgr::rotate_page()
+{
+ _page_cb_arr[_pg_index]._state = AIO_PENDING;
+ if (_pg_offset_dblks >= _cache_pgsize_sblks * JRNL_SBLK_SIZE)
+ {
+ _pg_offset_dblks = 0;
+ _pg_cntr++;
+ }
+ if (++_pg_index >= _cache_num_pages)
+ _pg_index = 0;
+}
+
+void
+wmgr::clean()
+{
+ std::free(_fhdr_base_ptr);
+ _fhdr_base_ptr = 0;
+
+ std::free(_fhdr_ptr_arr);
+ _fhdr_ptr_arr = 0;
+
+ if (_fhdr_aio_cb_arr)
+ {
+ for (u_int32_t i=0; i<_num_jfiles; i++)
+ delete _fhdr_aio_cb_arr[i];
+ std::free(_fhdr_aio_cb_arr);
+ _fhdr_aio_cb_arr = 0;
+ }
+}
+
+const std::string
+wmgr::status_str() const
+{
+ std::ostringstream oss;
+ oss << "wmgr: pi=" << _pg_index << " pc=" << _pg_cntr;
+ oss << " po=" << _pg_offset_dblks << " aer=" << _aio_evt_rem;
+ oss << " edac:" << (_enq_busy?"T":"F") << (_deq_busy?"T":"F");
+ oss << (_abort_busy?"T":"F") << (_commit_busy?"T":"F");
+ oss << " ps=[";
+ for (int i=0; i<_cache_num_pages; i++)
+ {
+ switch (_page_cb_arr[i]._state)
+ {
+ case UNUSED: oss << "-"; break;
+ case IN_USE: oss << "U"; break;
+ case AIO_PENDING: oss << "A"; break;
+ case AIO_COMPLETE: oss << "*"; break;
+ default: oss << _page_cb_arr[i]._state;
+ }
+ }
+ oss << "] " << _wrfc.status_str();
+ return oss.str();
+}
+
+// static
+
+const char* wmgr::_op_str[] = {"enqueue", "dequeue", "abort", "commit"};
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/wmgr.h b/cpp/src/qpid/legacystore/jrnl/wmgr.h
new file mode 100644
index 0000000000..8347221b1d
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/wmgr.h
@@ -0,0 +1,147 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file wmgr.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::wmgr (write manager). See
+ * class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_WMGR_H
+#define QPID_LEGACYSTORE_JRNL_WMGR_H
+
+namespace mrg
+{
+namespace journal
+{
+class wmgr;
+}
+}
+
+#include <cstring>
+#include "qpid/legacystore/jrnl/enums.h"
+#include "qpid/legacystore/jrnl/pmgr.h"
+#include "qpid/legacystore/jrnl/wrfc.h"
+#include <set>
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \brief Class for managing a write page cache of arbitrary size and number of pages.
+ *
+ * The write page cache works on the principle of caching the write data within a page until
+ * that page is either full or flushed; this initiates a single AIO write operation to store
+ * the data on disk.
+ *
+ * The maximum disk throughput is achieved by keeping the write operations of uniform size.
+ * Waiting for a page cache to fill achieves this; and in high data volume/throughput situations
+ * achieves the optimal disk throughput. Calling flush() forces a write of the current page cache
+ * no matter how full it is, and disrupts the uniformity of the write operations. This should
+ * normally only be done if throughput drops and there is a danger of a page of unwritten data
+ * waiting around for excessive time.
+ *
+ * The usual tradeoff between data storage latency and throughput performance applies.
+ */
+ class wmgr : public pmgr
+ {
+ private:
+ wrfc& _wrfc; ///< Ref to write rotating file controller
+ u_int32_t _max_dtokpp; ///< Max data writes per page
+ u_int32_t _max_io_wait_us; ///< Max wait in microseconds till submit
+ void* _fhdr_base_ptr; ///< Base pointer to file header memory
+ void** _fhdr_ptr_arr; ///< Array of pointers to file headers memory
+ aio_cb** _fhdr_aio_cb_arr; ///< Array of iocb pointers for file header writes
+ u_int32_t _cached_offset_dblks; ///< Amount of unwritten data in page (dblocks)
+ std::deque<data_tok*> _ddtokl; ///< Deferred dequeue data_tok list
+ u_int32_t _jfsize_dblks; ///< Journal file size in dblks (NOT sblks!)
+ u_int32_t _jfsize_pgs; ///< Journal file size in cache pages
+ u_int16_t _num_jfiles; ///< Number of files used in iocb mallocs
+
+ // TODO: Convert _enq_busy etc into a proper threadsafe lock
+ // TODO: Convert to enum? Are these encodes mutually exclusive?
+ bool _enq_busy; ///< Flag true if enqueue is in progress
+ bool _deq_busy; ///< Flag true if dequeue is in progress
+ bool _abort_busy; ///< Flag true if abort is in progress
+ bool _commit_busy; ///< Flag true if commit is in progress
+
+ enum _op_type { WMGR_ENQUEUE = 0, WMGR_DEQUEUE, WMGR_ABORT, WMGR_COMMIT };
+ static const char* _op_str[];
+
+ enq_rec _enq_rec; ///< Enqueue record used for encoding/decoding
+ deq_rec _deq_rec; ///< Dequeue record used for encoding/decoding
+ txn_rec _txn_rec; ///< Transaction record used for encoding/decoding
+ std::set<std::string> _txn_pending_set; ///< Set containing xids of pending commits/aborts
+
+ public:
+ wmgr(jcntl* jc, enq_map& emap, txn_map& tmap, wrfc& wrfc);
+ wmgr(jcntl* jc, enq_map& emap, txn_map& tmap, wrfc& wrfc, const u_int32_t max_dtokpp,
+ const u_int32_t max_iowait_us);
+ virtual ~wmgr();
+
+ void initialize(aio_callback* const cbp, const u_int32_t wcache_pgsize_sblks,
+ const u_int16_t wcache_num_pages, const u_int32_t max_dtokpp,
+ const u_int32_t max_iowait_us, std::size_t eo = 0);
+ iores enqueue(const void* const data_buff, const std::size_t tot_data_len,
+ const std::size_t this_data_len, data_tok* dtokp, const void* const xid_ptr,
+ const std::size_t xid_len, const bool transient, const bool external);
+ iores dequeue(data_tok* dtokp, const void* const xid_ptr, const std::size_t xid_len,
+ const bool txn_coml_commit);
+ iores abort(data_tok* dtokp, const void* const xid_ptr, const std::size_t xid_len);
+ iores commit(data_tok* dtokp, const void* const xid_ptr, const std::size_t xid_len);
+ iores flush();
+ int32_t get_events(page_state state, timespec* const timeout, bool flush = false);
+ bool is_txn_synced(const std::string& xid);
+ inline bool curr_pg_blocked() const { return _page_cb_arr[_pg_index]._state != UNUSED; }
+ inline bool curr_file_blocked() const { return _wrfc.aio_cnt() > 0; }
+ inline u_int32_t unflushed_dblks() { return _cached_offset_dblks; }
+
+ // Debug aid
+ const std::string status_str() const;
+
+ private:
+ void initialize(aio_callback* const cbp, const u_int32_t wcache_pgsize_sblks,
+ const u_int16_t wcache_num_pages);
+ iores pre_write_check(const _op_type op, const data_tok* const dtokp,
+ const std::size_t xidsize = 0, const std::size_t dsize = 0, const bool external = false)
+ const;
+ void dequeue_check(const std::string& xid, const u_int64_t drid);
+ void file_header_check(const u_int64_t rid, const bool cont, const u_int32_t rec_dblks_rem);
+ void flush_check(iores& res, bool& cont, bool& done);
+ iores write_flush();
+ iores rotate_file();
+ void dblk_roundup();
+ void write_fhdr(u_int64_t rid, u_int16_t fid, u_int16_t lid, std::size_t fro);
+ void rotate_page();
+ void clean();
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_WMGR_H
diff --git a/cpp/src/qpid/legacystore/jrnl/wrfc.cpp b/cpp/src/qpid/legacystore/jrnl/wrfc.cpp
new file mode 100644
index 0000000000..43461b66a3
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/wrfc.cpp
@@ -0,0 +1,162 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ * \file wrfc.cpp
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::wrfc (rotating
+ * file controller). See comments in file wrfc.h for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#include "qpid/legacystore/jrnl/wrfc.h"
+
+#include <cmath>
+#include "qpid/legacystore/jrnl/jerrno.h"
+#include "qpid/legacystore/jrnl/jexception.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+wrfc::wrfc(const lpmgr* lpmp):
+ rfc(lpmp),
+ _fsize_sblks(0),
+ _fsize_dblks(0),
+ _enq_cap_offs_dblks(0),
+ _rid(0),
+ _reset_ok(false),
+ _owi(false),
+ _frot(true)
+{}
+
+wrfc::~wrfc()
+{}
+
+void
+wrfc::initialize(const u_int32_t fsize_sblks, rcvdat* rdp)
+{
+ if (rdp)
+ {
+ _fc_index = rdp->_lfid;
+ _curr_fc = _lpmp->get_fcntlp(_fc_index);
+ _curr_fc->wr_reset(rdp);
+ _rid = rdp->_h_rid + 1;
+ _reset_ok = true;
+ _owi = rdp->_owi;
+ _frot = rdp->_frot;
+ if (rdp->_lffull)
+ rotate();
+ }
+ else
+ {
+ rfc::initialize();
+ rfc::set_findex(0);
+ _rid = 0ULL;
+ _reset_ok = false;
+ }
+ _fsize_sblks = fsize_sblks;
+ _fsize_dblks = fsize_sblks * JRNL_SBLK_SIZE;
+ _enq_cap_offs_dblks = (u_int32_t)std::ceil(_fsize_dblks * _lpmp->num_jfiles() * (100.0 - JRNL_ENQ_THRESHOLD) / 100);
+ // Check the offset is at least one file; if not, make it so
+ if (_enq_cap_offs_dblks < _fsize_dblks)
+ _enq_cap_offs_dblks = _fsize_dblks;
+}
+
+iores wrfc::rotate()
+{
+ if (!_lpmp->num_jfiles())
+ throw jexception(jerrno::JERR__NINIT, "wrfc", "rotate");
+ _fc_index++;
+ if (_fc_index == _lpmp->num_jfiles())
+ {
+ _fc_index = 0;
+ _owi = !_owi;
+ _frot = false;
+ }
+ _curr_fc = _lpmp->get_fcntlp(_fc_index);
+ if (_curr_fc->aio_cnt())
+ return RHM_IORES_FILE_AIOWAIT;
+ if (!wr_reset()) //Checks if file is still in use (ie not fully dequeued yet)
+ return RHM_IORES_FULL;
+ return RHM_IORES_SUCCESS;
+}
+
+u_int16_t wrfc::earliest_index() const
+{
+ if (_frot)
+ return 0;
+ u_int16_t next_index = _fc_index + 1;
+ if (next_index >= _lpmp->num_jfiles())
+ next_index = 0;
+ return next_index;
+}
+
+bool
+wrfc::enq_threshold(const u_int32_t enq_dsize_dblks) const
+{
+ u_int32_t subm_dblks = subm_cnt_dblks(); // includes file hdr if > 0
+ // This compensates for new files which don't have their file headers written yet,
+ // as file header space cannot be included in this calculation.
+ if (subm_dblks != 0)
+ subm_dblks -= 4;
+ u_int32_t fwd_dblks = subm_dblks + enq_dsize_dblks + _enq_cap_offs_dblks;
+ u_int16_t findex = _fc_index;
+ fcntl* fcp = _curr_fc;
+ bool in_use = false;
+ while (fwd_dblks && !(findex != _fc_index && fcp->enqcnt()))
+ {
+ fwd_dblks -= fwd_dblks > _fsize_dblks ? _fsize_dblks : fwd_dblks;
+ if (fwd_dblks)
+ {
+ if (++findex == _lpmp->num_jfiles())
+ findex = 0;
+ fcp = _lpmp->get_fcntlp(findex);
+ }
+ in_use |= fcp->enqcnt() > 0;
+ }
+ // Return true if threshold exceeded
+ return findex != _fc_index && in_use;
+}
+
+bool wrfc::wr_reset()
+{
+ _reset_ok = _curr_fc->reset(); // returns false if full (ie file still contains enqueued recs)
+ return _reset_ok;
+}
+
+// TODO: update this to reflect all status data
+std::string
+wrfc::status_str() const
+{
+ std::ostringstream oss;
+ oss << "wrfc: " << rfc::status_str();
+ if (is_active())
+ oss << " fcntl[" << _fc_index << "]: " << _curr_fc->status_str();
+ return oss.str();
+}
+
+} // namespace journal
+} // namespace mrg
diff --git a/cpp/src/qpid/legacystore/jrnl/wrfc.h b/cpp/src/qpid/legacystore/jrnl/wrfc.h
new file mode 100644
index 0000000000..f0e4e73151
--- /dev/null
+++ b/cpp/src/qpid/legacystore/jrnl/wrfc.h
@@ -0,0 +1,154 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/**
+ * \file wrfc.h
+ *
+ * Qpid asynchronous store plugin library
+ *
+ * File containing code for class mrg::journal::wrfc (write rotating
+ * file controller). See class documentation for details.
+ *
+ * \author Kim van der Riet
+ */
+
+#ifndef QPID_LEGACYSTORE_JRNL_WRFC_H
+#define QPID_LEGACYSTORE_JRNL_WRFC_H
+
+namespace mrg
+{
+namespace journal
+{
+class wrfc;
+}
+}
+
+#include <cstddef>
+#include "qpid/legacystore/jrnl/enums.h"
+#include "qpid/legacystore/jrnl/rrfc.h"
+
+namespace mrg
+{
+namespace journal
+{
+
+ /**
+ * \class wrfc
+ * \brief Class to handle write management of a journal rotating file controller.
+ */
+ class wrfc : public rfc
+ {
+ private:
+ u_int32_t _fsize_sblks; ///< Size of journal files in sblks
+ u_int32_t _fsize_dblks; ///< Size of journal files in dblks
+ u_int32_t _enq_cap_offs_dblks; ///< Enqueue capacity offset
+ u_int64_t _rid; ///< Master counter for record ID (rid)
+ bool _reset_ok; ///< Flag set when reset succeeds
+ bool _owi; ///< Overwrite indicator
+ bool _frot; ///< Flag is true for first rotation, false otherwise
+
+ public:
+ wrfc(const lpmgr* lpmp);
+ virtual ~wrfc();
+
+ /**
+ * \brief Initialize the controller.
+ * \param fsize_sblks Size of each journal file in sblks.
+ * \param rdp Struct carrying restore information. Optional for non-restore use, defaults to 0 (NULL).
+ */
+ using rfc::initialize;
+ void initialize(const u_int32_t fsize_sblks, rcvdat* rdp = 0);
+
+ /**
+ * \brief Rotate active file controller to next file in rotating file group.
+ * \exception jerrno::JERR__NINIT if called before calling initialize().
+ */
+ iores rotate();
+
+ /**
+ * \brief Returns the index of the earliest complete file within the rotating
+ * file group. Unwritten files are excluded. The currently active file is
+ * excluded unless it is the only written file.
+ */
+ u_int16_t earliest_index() const;
+
+ /**
+ * \brief Determines if a proposed write would cause the enqueue threshold to be exceeded.
+ *
+ * The following routine finds whether the next write will take the write pointer to beyond the
+ * enqueue limit threshold. The following illustrates how this is achieved.
+ * <pre>
+ * Current file index: 4 +---+----------+
+ * X's mark still-enqueued records |msg| 1-thresh |
+ * msg = current msg size + unwritten cache +---+----------+
+ * thresh = JRNL_ENQ_THRESHOLD as a fraction ^ V
+ * +-------+-------+-------+-------+--+----+-------+-+-----+-------+
+ * file num ->| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
+ * enq recs ->| X XX |XX XXX |XX XXXX|XXXXXXX|XX | | | X |
+ * +-------+-------+-------+-------+--+----+-------+-+-----+-------+
+ * ^ ^ ^
+ * subm_dblks --+ | |
+ * These files must be free of enqueues
+ * If not, return true.
+ * </pre>
+ * \param enq_dsize_dblks Proposed size of write in dblocks
+ */
+ bool enq_threshold(const u_int32_t enq_dsize_dblks) const;
+
+ inline u_int64_t rid() const { return _rid; }
+ inline u_int64_t get_incr_rid() { return _rid++; }
+ bool wr_reset();
+ inline bool is_wr_reset() const { return _reset_ok; }
+ inline bool owi() const { return _owi; }
+ inline bool frot() const { return _frot; }
+
+ // Convenience access methods to current file controller
+
+ inline int fh() const { return _curr_fc->wr_fh(); }
+
+ inline u_int32_t subm_cnt_dblks() const { return _curr_fc->wr_subm_cnt_dblks(); }
+ inline std::size_t subm_offs() const { return _curr_fc->wr_subm_offs(); }
+ inline u_int32_t add_subm_cnt_dblks(u_int32_t a) { return _curr_fc->add_wr_subm_cnt_dblks(a); }
+
+ inline u_int32_t cmpl_cnt_dblks() const { return _curr_fc->wr_cmpl_cnt_dblks(); }
+ inline std::size_t cmpl_offs() const { return _curr_fc->wr_cmpl_offs(); }
+ inline u_int32_t add_cmpl_cnt_dblks(u_int32_t a) { return _curr_fc->add_wr_cmpl_cnt_dblks(a); }
+
+ inline u_int16_t aio_cnt() const { return _curr_fc->aio_cnt(); }
+ inline u_int16_t incr_aio_cnt() { return _curr_fc->incr_aio_cnt(); }
+ inline u_int16_t decr_aio_cnt() { return _curr_fc->decr_aio_cnt(); }
+
+ inline bool is_void() const { return _curr_fc->wr_void(); }
+ inline bool is_empty() const { return _curr_fc->wr_empty(); }
+ inline u_int32_t remaining_dblks() const { return _curr_fc->wr_remaining_dblks(); }
+ inline bool is_full() const { return _curr_fc->is_wr_full(); };
+ inline bool is_compl() const { return _curr_fc->is_wr_compl(); };
+ inline u_int32_t aio_outstanding_dblks() const { return _curr_fc->wr_aio_outstanding_dblks(); }
+ inline bool file_rotate() const { return _curr_fc->wr_file_rotate(); }
+
+ // Debug aid
+ std::string status_str() const;
+ };
+
+} // namespace journal
+} // namespace mrg
+
+#endif // ifndef QPID_LEGACYSTORE_JRNL_WRFC_H
diff --git a/cpp/src/qpid/legacystore/management-schema.xml b/cpp/src/qpid/legacystore/management-schema.xml
new file mode 100644
index 0000000000..65969f0fb2
--- /dev/null
+++ b/cpp/src/qpid/legacystore/management-schema.xml
@@ -0,0 +1,99 @@
+<schema package="org.apache.qpid.legacystore">
+
+<!--
+ 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.
+-->
+
+ <class name="Store">
+ <property name="brokerRef" type="objId" access="RO" references="qpid.Broker" index="y" parentRef="y"/>
+ <property name="location" type="sstr" access="RO" desc="Logical directory on disk"/>
+ <property name="defaultInitialFileCount" type="uint16" access="RO" unit="file" desc="Default number of files initially allocated to each journal"/>
+ <property name="defaultDataFileSize" type="uint32" access="RO" unit="RdPg" desc="Default size of each journal data file"/>
+ <property name="tplIsInitialized" type="bool" access="RO" desc="Transaction prepared list has been initialized by a transactional prepare"/>
+ <property name="tplDirectory" type="sstr" access="RO" desc="Transaction prepared list directory"/>
+ <property name="tplWritePageSize" type="uint32" access="RO" unit="byte" desc="Page size in transaction prepared list write-page-cache"/>
+ <property name="tplWritePages" type="uint32" access="RO" unit="wpage" desc="Number of pages in transaction prepared list write-page-cache"/>
+ <property name="tplInitialFileCount" type="uint16" access="RO" unit="file" desc="Number of files initially allocated to transaction prepared list journal"/>
+ <property name="tplDataFileSize" type="uint32" access="RO" unit="byte" desc="Size of each journal data file in transaction prepared list journal"/>
+ <property name="tplCurrentFileCount" type="uint32" access="RO" unit="file" desc="Number of files currently allocated to transaction prepared list journal"/>
+
+ <statistic name="tplTransactionDepth" type="hilo32" unit="txn" desc="Number of currently enqueued prepared transactions"/>
+ <statistic name="tplTxnPrepares" type="count64" unit="record" desc="Total transaction prepares on transaction prepared list"/>
+ <statistic name="tplTxnCommits" type="count64" unit="record" desc="Total transaction commits on transaction prepared list"/>
+ <statistic name="tplTxnAborts" type="count64" unit="record" desc="Total transaction aborts on transaction prepared list"/>
+ <statistic name="tplOutstandingAIOs" type="hilo32" unit="aio_op" desc="Number of currently outstanding AIO requests in Async IO system"/>
+ </class>
+
+ <class name="Journal">
+ <property name="queueRef" type="objId" access="RO" references="qpid.Queue" isGeneralReference="y"/>
+ <property name="name" type="sstr" access="RO" index="y"/>
+ <property name="directory" type="sstr" access="RO" desc="Directory containing journal files"/>
+ <property name="baseFileName" type="sstr" access="RO" desc="Base filename prefix for journal"/>
+ <property name="writePageSize" type="uint32" access="RO" unit="byte" desc="Page size in write-page-cache"/>
+ <property name="writePages" type="uint32" access="RO" unit="wpage" desc="Number of pages in write-page-cache"/>
+ <property name="readPageSize" type="uint32" access="RO" unit="byte" desc="Page size in read-page-cache"/>
+ <property name="readPages" type="uint32" access="RO" unit="rpage" desc="Number of pages in read-page-cache"/>
+ <property name="initialFileCount" type="uint16" access="RO" unit="file" desc="Number of files initially allocated to this journal"/>
+ <property name="autoExpand" type="bool" access="RO" desc="Auto-expand enabled"/>
+ <property name="currentFileCount" type="uint16" access="RO" unit="file" desc="Number of files currently allocated to this journal"/>
+ <property name="maxFileCount" type="uint16" access="RO" unit="file" desc="Max number of files allowed for this journal"/>
+ <property name="dataFileSize" type="uint32" access="RO" unit="byte" desc="Size of each journal data file"/>
+
+ <statistic name="recordDepth" type="hilo32" unit="record" desc="Number of currently enqueued records (durable messages)"/>
+ <statistic name="enqueues" type="count64" unit="record" desc="Total enqueued records on journal"/>
+ <statistic name="dequeues" type="count64" unit="record" desc="Total dequeued records on journal"/>
+ <statistic name="txn" type="count32" unit="record" desc="Total open transactions (xids) on journal"/>
+ <statistic name="txnEnqueues" type="count64" unit="record" desc="Total transactional enqueued records on journal"/>
+ <statistic name="txnDequeues" type="count64" unit="record" desc="Total transactional dequeued records on journal"/>
+ <statistic name="txnCommits" type="count64" unit="record" desc="Total transactional commit records on journal"/>
+ <statistic name="txnAborts" type="count64" unit="record" desc="Total transactional abort records on journal"/>
+ <statistic name="outstandingAIOs" type="hilo32" unit="aio_op" desc="Number of currently outstanding AIO requests in Async IO system"/>
+
+<!--
+ The following are not yet "wired up" in JournalImpl.cpp
+-->
+ <statistic name="freeFileCount" type="hilo32" unit="file" desc="Number of files free on this journal. Includes free files trapped in holes."/>
+ <statistic name="availableFileCount" type="hilo32" unit="file" desc="Number of files available to be written. Excluding holes"/>
+ <statistic name="writeWaitFailures" type="count64" unit="record" desc="AIO Wait failures on write"/>
+ <statistic name="writeBusyFailures" type="count64" unit="record" desc="AIO Busy failures on write"/>
+ <statistic name="readRecordCount" type="count64" unit="record" desc="Records read from the journal"/>
+ <statistic name="readBusyFailures" type="count64" unit="record" desc="AIO Busy failures on read"/>
+ <statistic name="writePageCacheDepth" type="hilo32" unit="wpage" desc="Current depth of write-page-cache"/>
+ <statistic name="readPageCacheDepth" type="hilo32" unit="rpage" desc="Current depth of read-page-cache"/>
+
+ <method name="expand" desc="Increase number of files allocated for this journal">
+ <arg name="by" type="uint32" dir="I" desc="Number of files to increase journal size by"/>
+ </method>
+ </class>
+
+ <eventArguments>
+ <arg name="autoExpand" type="bool" desc="Journal auto-expand enabled"/>
+ <arg name="fileSize" type="uint32" desc="Journal file size in bytes"/>
+ <arg name="jrnlId" type="sstr" desc="Journal Id"/>
+ <arg name="numEnq" type="uint32" desc="Number of recovered enqueues"/>
+ <arg name="numFiles" type="uint16" desc="Number of journal files"/>
+ <arg name="numTxn" type="uint32" desc="Number of recovered transactions"/>
+ <arg name="numTxnDeq" type="uint32" desc="Number of recovered transactional dequeues"/>
+ <arg name="numTxnEnq" type="uint32" desc="Number of recovered transactional enqueues"/>
+ <arg name="what" type="sstr" desc="Description of event"/>
+ </eventArguments>
+ <event name="enqThresholdExceeded" sev="warn" args="jrnlId, what"/>
+ <event name="created" sev="notice" args="jrnlId, fileSize, numFiles"/>
+ <event name="full" sev="error" args="jrnlId, what"/>
+ <event name="recovered" sev="notice" args="jrnlId, fileSize, numFiles, numEnq, numTxn, numTxnEnq, numTxnDeq"/>
+</schema>
diff --git a/cpp/src/qpid/log/Logger.cpp b/cpp/src/qpid/log/Logger.cpp
index 7c2e807ca9..7e7e1e94c1 100644
--- a/cpp/src/qpid/log/Logger.cpp
+++ b/cpp/src/qpid/log/Logger.cpp
@@ -177,4 +177,20 @@ void Logger::reconfigure(const std::vector<std::string>& selectors) {
void Logger::setPrefix(const std::string& p) { prefix = p; }
+
+bool Logger::getHiresTimestamp()
+{
+ return flags & HIRES;
+}
+
+
+void Logger::setHiresTimestamp(bool setting)
+{
+ ScopedLock l(lock);
+ if (setting)
+ flags |= HIRES;
+ else
+ flags &= ~HIRES;
+}
+
}} // namespace qpid::log
diff --git a/cpp/src/qpid/management/ManagementAgent.cpp b/cpp/src/qpid/management/ManagementAgent.cpp
index 474c86ed48..86e9d0be8d 100644
--- a/cpp/src/qpid/management/ManagementAgent.cpp
+++ b/cpp/src/qpid/management/ManagementAgent.cpp
@@ -28,12 +28,15 @@
#include "qpid/management/ManagementObject.h"
#include "qpid/broker/DeliverableMessage.h"
#include "qpid/log/Statement.h"
-#include <qpid/broker/Message.h>
+#include "qpid/broker/Message.h"
+#include "qpid/broker/Broker.h"
#include "qpid/framing/MessageTransferBody.h"
#include "qpid/framing/FieldValue.h"
#include "qpid/broker/amqp_0_10/MessageTransfer.h"
#include "qpid/sys/Time.h"
+#include "qpid/sys/Timer.h"
#include "qpid/sys/Thread.h"
+#include "qpid/sys/PollableQueue.h"
#include "qpid/broker/ConnectionState.h"
#include "qpid/broker/AclModule.h"
#include "qpid/types/Variant.h"
@@ -46,6 +49,9 @@
#include <sstream>
#include <typeinfo>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+
namespace qpid {
namespace management {
@@ -62,22 +68,23 @@ namespace _qmf = qmf::org::apache::qpid::broker;
namespace {
- const string defaultVendorName("vendor");
- const string defaultProductName("product");
+const size_t qmfV1BufferSize(65536);
+const string defaultVendorName("vendor");
+const string defaultProductName("product");
- // Create a valid binding key substring by
- // replacing all '.' chars with '_'
- const string keyifyNameStr(const string& name)
- {
- string n2 = name;
+// Create a valid binding key substring by
+// replacing all '.' chars with '_'
+const string keyifyNameStr(const string& name)
+{
+ string n2 = name;
- size_t pos = n2.find('.');
- while (pos != n2.npos) {
- n2.replace(pos, 1, "_");
- pos = n2.find('.', pos);
- }
- return n2;
+ size_t pos = n2.find('.');
+ while (pos != n2.npos) {
+ n2.replace(pos, 1, "_");
+ pos = n2.find('.', pos);
}
+ return n2;
+}
struct ScopedManagementContext
{
@@ -90,6 +97,32 @@ struct ScopedManagementContext
setManagementExecutionContext(0);
}
};
+
+typedef boost::function0<void> FireFunction;
+struct Periodic : public qpid::sys::TimerTask
+{
+ FireFunction fireFunction;
+ qpid::sys::Timer* timer;
+
+ Periodic (FireFunction f, qpid::sys::Timer* t, uint32_t seconds);
+ virtual ~Periodic ();
+ void fire ();
+};
+
+Periodic::Periodic (FireFunction f, qpid::sys::Timer* t, uint32_t _seconds)
+ : TimerTask(sys::Duration((_seconds ? _seconds : 1) * sys::TIME_SEC),
+ "ManagementAgent::periodicProcessing"),
+ fireFunction(f), timer(t) {}
+
+Periodic::~Periodic() {}
+
+void Periodic::fire()
+{
+ setupNextFire();
+ timer->add(this);
+ fireFunction();
+}
+
}
@@ -113,9 +146,8 @@ ManagementAgent::RemoteAgent::~RemoteAgent ()
QPID_LOG(debug, "Remote Agent removed bank=[" << brokerBank << "." << agentBank << "]");
if (mgmtObject != 0) {
mgmtObject->resourceDestroy();
- agent.deleteObjectNowLH(mgmtObject->getObjectId());
- delete mgmtObject;
- mgmtObject = 0;
+ agent.deleteObjectNow(mgmtObject->getObjectId());
+ mgmtObject.reset();
}
}
@@ -124,8 +156,7 @@ ManagementAgent::ManagementAgent (const bool qmfV1, const bool qmfV2) :
startTime(sys::now()),
suppressed(false), disallowAllV1Methods(false),
vendorNameKey(defaultVendorName), productNameKey(defaultProductName),
- qmf1Support(qmfV1), qmf2Support(qmfV2), maxReplyObjs(100),
- msgBuffer(MA_BUFFER_SIZE), memstat(0)
+ qmf1Support(qmfV1), qmf2Support(qmfV2), maxReplyObjs(100)
{
nextObjectId = 1;
brokerBank = 1;
@@ -136,7 +167,7 @@ ManagementAgent::ManagementAgent (const bool qmfV1, const bool qmfV2) :
attrMap["_vendor"] = defaultVendorName;
attrMap["_product"] = defaultProductName;
- memstat = new qmf::org::apache::qpid::broker::Memory(this, 0, "amqp-broker");
+ memstat = _qmf::Memory::shared_ptr(new qmf::org::apache::qpid::broker::Memory(this, 0, "amqp-broker"));
addObject(memstat, "amqp-broker");
}
@@ -155,15 +186,6 @@ ManagementAgent::~ManagementAgent ()
v2Direct.reset();
remoteAgents.clear();
-
- moveNewObjectsLH();
- for (ManagementObjectMap::iterator iter = managementObjects.begin ();
- iter != managementObjects.end ();
- iter++) {
- ManagementObject* object = iter->second;
- delete object;
- }
- managementObjects.clear();
}
}
@@ -176,6 +198,11 @@ void ManagementAgent::configure(const string& _dataDir, bool _publish, uint16_t
broker = _broker;
threadPoolSize = _threads;
ManagementObject::maxThreads = threadPoolSize;
+ sendQueue.reset(
+ new EventQueue(boost::bind(&ManagementAgent::sendEvents, this, _1), broker->getPoller()));
+ sendQueue->start();
+ timer = &broker->getTimer();
+ timer->add(new Periodic(boost::bind(&ManagementAgent::periodicProcessing, this), timer, interval));
// Get from file or generate and save to file.
if (dataDir.empty())
@@ -218,13 +245,6 @@ void ManagementAgent::configure(const string& _dataDir, bool _publish, uint16_t
}
}
-void ManagementAgent::pluginsInitialized() {
- // Do this here so cluster plugin has the chance to set up the timer.
- timer = &broker->getClusterTimer();
- timer->add(new Periodic(*this, interval));
-}
-
-
void ManagementAgent::setName(const string& vendor, const string& product, const string& instance)
{
if (vendor.find(':') != vendor.npos) {
@@ -245,13 +265,13 @@ void ManagementAgent::setName(const string& vendor, const string& product, const
} else
inst = instance;
- name_address = vendor + ":" + product + ":" + inst;
- attrMap["_instance"] = inst;
- attrMap["_name"] = name_address;
+ name_address = vendor + ":" + product + ":" + inst;
+ attrMap["_instance"] = inst;
+ attrMap["_name"] = name_address;
- vendorNameKey = keyifyNameStr(vendor);
- productNameKey = keyifyNameStr(product);
- instanceNameKey = keyifyNameStr(inst);
+ vendorNameKey = keyifyNameStr(vendor);
+ productNameKey = keyifyNameStr(product);
+ instanceNameKey = keyifyNameStr(inst);
}
@@ -316,11 +336,12 @@ void ManagementAgent::registerEvent (const string& packageName,
}
// Deprecated: V1 objects
-ObjectId ManagementAgent::addObject(ManagementObject* object, uint64_t persistId, bool persistent)
+ObjectId ManagementAgent::addObject(ManagementObject::shared_ptr object, uint64_t persistId, bool persistent)
{
uint16_t sequence;
uint64_t objectNum;
+ sys::Mutex::ScopedLock lock(addLock);
sequence = persistent ? 0 : bootSequence;
objectNum = persistId ? persistId : nextObjectId++;
@@ -329,17 +350,14 @@ ObjectId ManagementAgent::addObject(ManagementObject* object, uint64_t persistId
object->setObjectId(objId);
- {
- sys::Mutex::ScopedLock lock(addLock);
- newManagementObjects.push_back(object);
- }
+ newManagementObjects.push_back(object);
QPID_LOG(debug, "Management object (V1) added: " << objId.getV2Key());
return objId;
}
-ObjectId ManagementAgent::addObject(ManagementObject* object,
+ObjectId ManagementAgent::addObject(ManagementObject::shared_ptr object,
const string& key,
bool persistent)
{
@@ -369,12 +387,11 @@ void ManagementAgent::raiseEvent(const ManagementEvent& event, severity_t severi
"emerg", "alert", "crit", "error", "warn",
"note", "info", "debug"
};
- sys::Mutex::ScopedLock lock (userLock);
uint8_t sev = (severity == SEV_DEFAULT) ? event.getSeverity() : (uint8_t) severity;
if (qmf1Support) {
- Buffer outBuffer(eventBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ char buffer[qmfV1BufferSize];
+ Buffer outBuffer(buffer, qmfV1BufferSize);
encodeHeader(outBuffer, 'e');
outBuffer.putShortString(event.getPackageName());
@@ -385,9 +402,7 @@ void ManagementAgent::raiseEvent(const ManagementEvent& event, severity_t severi
string sBuf;
event.encode(sBuf);
outBuffer.putRawData(sBuf);
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, mExchange,
+ sendBuffer(outBuffer, mExchange,
"console.event.1.0." + event.getPackageName() + "." + event.getEventName());
QPID_LOG(debug, "SEND raiseEvent (v1) class=" << event.getPackageName() << "." << event.getEventName());
}
@@ -426,25 +441,11 @@ void ManagementAgent::raiseEvent(const ManagementEvent& event, severity_t severi
Variant::List list_;
list_.push_back(map_);
ListCodec::encode(list_, content);
- sendBufferLH(content, "", headers, "amqp/list", v2Topic, key.str());
+ sendBuffer(content, "", headers, "amqp/list", v2Topic, key.str());
QPID_LOG(debug, "SEND raiseEvent (v2) class=" << event.getPackageName() << "." << event.getEventName());
}
}
-ManagementAgent::Periodic::Periodic (ManagementAgent& _agent, uint32_t _seconds)
- : TimerTask(sys::Duration((_seconds ? _seconds : 1) * sys::TIME_SEC),
- "ManagementAgent::periodicProcessing"),
- agent(_agent) {}
-
-ManagementAgent::Periodic::~Periodic() {}
-
-void ManagementAgent::Periodic::fire()
-{
- setupNextFire();
- agent.timer->add(this);
- agent.periodicProcessing();
-}
-
void ManagementAgent::clientAdded (const string& routingKey)
{
sys::Mutex::ScopedLock lock(userLock);
@@ -480,28 +481,14 @@ void ManagementAgent::clientAdded (const string& routingKey)
while (rkeys.size()) {
char localBuffer[16];
Buffer outBuffer(localBuffer, 16);
- uint32_t outLen;
encodeHeader(outBuffer, 'x');
- outLen = outBuffer.getPosition();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, dExchange, rkeys.front());
+ sendBuffer(outBuffer, dExchange, rkeys.front());
QPID_LOG(debug, "SEND ConsoleAddedIndication to=" << rkeys.front());
rkeys.pop_front();
}
}
-void ManagementAgent::clusterUpdate() {
- // Called on all cluster memebers when a new member joins a cluster.
- // Set clientWasAdded so that on the next periodicProcessing we will do
- // a full update on all cluster members.
- sys::Mutex::ScopedLock l(userLock);
- moveNewObjectsLH(); // keep lists consistent with updater/updatee.
- moveDeletedObjectsLH();
- clientWasAdded = true;
- debugSnapshot("Cluster member joined");
-}
-
void ManagementAgent::encodeHeader (Buffer& buf, uint8_t opcode, uint32_t seq)
{
buf.putOctet ('A');
@@ -523,12 +510,9 @@ bool ManagementAgent::checkHeader (Buffer& buf, uint8_t *opcode, uint32_t *seq)
return h1 == 'A' && h2 == 'M' && h3 == '2';
}
-// NOTE WELL: assumes userLock is held by caller (LH)
-// NOTE EVEN WELLER: drops this lock when delivering the message!!!
-void ManagementAgent::sendBufferLH(Buffer& buf,
- uint32_t length,
- qpid::broker::Exchange::shared_ptr exchange,
- const string& routingKey)
+void ManagementAgent::sendBuffer(Buffer& buf,
+ qpid::broker::Exchange::shared_ptr exchange,
+ const string& routingKey)
{
if (suppressed) {
QPID_LOG(debug, "Suppressing management message to " << routingKey);
@@ -541,6 +525,8 @@ void ManagementAgent::sendBufferLH(Buffer& buf,
AMQFrame header((AMQHeaderBody()));
AMQFrame content((AMQContentBody()));
+ size_t length = buf.getPosition();
+ buf.reset();
content.castBody<AMQContentBody>()->decode(buf, length);
method.setEof(false);
@@ -560,42 +546,30 @@ void ManagementAgent::sendBufferLH(Buffer& buf,
dp->setRoutingKey(routingKey);
transfer->getFrames().append(content);
-
Message msg(transfer, transfer);
msg.setIsManagementMessage(true);
-
- {
- sys::Mutex::ScopedUnlock u(userLock);
-
- DeliverableMessage deliverable (msg, 0);
- try {
- exchange->route(deliverable);
- } catch(exception&) {}
- }
+ sendQueue->push(make_pair(exchange, msg));
buf.reset();
}
-void ManagementAgent::sendBufferLH(Buffer& buf,
- uint32_t length,
- const string& exchange,
- const string& routingKey)
+void ManagementAgent::sendBuffer(Buffer& buf,
+ const string& exchange,
+ const string& routingKey)
{
qpid::broker::Exchange::shared_ptr ex(broker->getExchanges().get(exchange));
if (ex.get() != 0)
- sendBufferLH(buf, length, ex, routingKey);
+ sendBuffer(buf, ex, routingKey);
}
-// NOTE WELL: assumes userLock is held by caller (LH)
-// NOTE EVEN WELLER: drops this lock when delivering the message!!!
-void ManagementAgent::sendBufferLH(const string& data,
- const string& cid,
- const Variant::Map& headers,
- const string& content_type,
- qpid::broker::Exchange::shared_ptr exchange,
- const string& routingKey,
- uint64_t ttl_msec)
+void ManagementAgent::sendBuffer(const string& data,
+ const string& cid,
+ const Variant::Map& headers,
+ const string& content_type,
+ qpid::broker::Exchange::shared_ptr exchange,
+ const string& routingKey,
+ uint64_t ttl_msec)
{
Variant::Map::const_iterator i;
@@ -643,34 +617,27 @@ void ManagementAgent::sendBufferLH(const string& data,
msg.setIsManagementMessage(true);
msg.computeExpiration(broker->getExpiryPolicy());
- {
- sys::Mutex::ScopedUnlock u(userLock);
-
- DeliverableMessage deliverable (msg, 0);
- try {
- exchange->route(deliverable);
- } catch(exception&) {}
- }
+ sendQueue->push(make_pair(exchange, msg));
}
-void ManagementAgent::sendBufferLH(const string& data,
- const string& cid,
- const Variant::Map& headers,
- const string& content_type,
- const string& exchange,
- const string& routingKey,
- uint64_t ttl_msec)
+void ManagementAgent::sendBuffer(const string& data,
+ const string& cid,
+ const Variant::Map& headers,
+ const string& content_type,
+ const string& exchange,
+ const string& routingKey,
+ uint64_t ttl_msec)
{
qpid::broker::Exchange::shared_ptr ex(broker->getExchanges().get(exchange));
if (ex.get() != 0)
- sendBufferLH(data, cid, headers, content_type, ex, routingKey, ttl_msec);
+ sendBuffer(data, cid, headers, content_type, ex, routingKey, ttl_msec);
}
/** Objects that have been added since the last periodic poll are temporarily
* saved in the newManagementObjects list. This allows objects to be
- * added without needing to block on the userLock (addLock is used instead).
+ * added without needing to block on the userLock (objectLock is used instead).
* These new objects need to be integrated into the object database
* (managementObjects) *before* they can be properly managed. This routine
* performs the integration.
@@ -680,34 +647,33 @@ void ManagementAgent::sendBufferLH(const string& data,
* duplicate object ids. To avoid clashes, don't put deleted objects
* into the active object database.
*/
-void ManagementAgent::moveNewObjectsLH()
+void ManagementAgent::moveNewObjects()
{
- sys::Mutex::ScopedLock lock (addLock);
+ sys::Mutex::ScopedLock lock(addLock);
+ sys::Mutex::ScopedLock objLock (objectLock);
while (!newManagementObjects.empty()) {
- ManagementObject *object = newManagementObjects.back();
+ ManagementObject::shared_ptr object = newManagementObjects.back();
newManagementObjects.pop_back();
if (object->isDeleted()) {
DeletedObject::shared_ptr dptr(new DeletedObject(object, qmf1Support, qmf2Support));
pendingDeletedObjs[dptr->getKey()].push_back(dptr);
- delete object;
} else { // add to active object list, check for duplicates.
ObjectId oid = object->getObjectId();
ManagementObjectMap::iterator destIter = managementObjects.find(oid);
if (destIter != managementObjects.end()) {
// duplicate found. It is OK if the old object has been marked
// deleted, just replace the old with the new.
- ManagementObject *oldObj = destIter->second;
- if (oldObj->isDeleted()) {
- DeletedObject::shared_ptr dptr(new DeletedObject(oldObj, qmf1Support, qmf2Support));
- pendingDeletedObjs[dptr->getKey()].push_back(dptr);
- delete oldObj;
- } else {
+ ManagementObject::shared_ptr oldObj = destIter->second;
+ if (!oldObj->isDeleted()) {
// Duplicate non-deleted objects? This is a user error - oids must be unique.
// for now, leak the old object (safer than deleting - may still be referenced)
// and complain loudly...
QPID_LOG(error, "Detected two management objects with the same identifier: " << oid);
+ oldObj->resourceDestroy();
}
+ DeletedObject::shared_ptr dptr(new DeletedObject(oldObj, qmf1Support, qmf2Support));
+ pendingDeletedObjs[dptr->getKey()].push_back(dptr);
// QPID-3666: be sure to replace the -index- also, as non-key members of
// the index object may be different for the new object! So erase the
// entry, rather than []= assign here:
@@ -720,32 +686,41 @@ void ManagementAgent::moveNewObjectsLH()
void ManagementAgent::periodicProcessing (void)
{
-#define BUFSIZE 65536
#define HEADROOM 4096
debugSnapshot("Management agent periodic processing");
sys::Mutex::ScopedLock lock (userLock);
- uint32_t contentSize;
string routingKey;
string sBuf;
- moveNewObjectsLH();
+ moveNewObjects();
//
// If we're publishing updates, get the latest memory statistics and uptime now
//
if (publish) {
uint64_t uptime = sys::Duration(startTime, sys::now());
- static_cast<_qmf::Broker*>(broker->GetManagementObject())->set_uptime(uptime);
- qpid::sys::MemStat::loadMemInfo(memstat);
+ boost::dynamic_pointer_cast<_qmf::Broker>(broker->GetManagementObject())->set_uptime(uptime);
+ qpid::sys::MemStat::loadMemInfo(memstat.get());
+ }
+
+ //
+ // Use a copy of the management object map to avoid holding the objectLock
+ //
+ ManagementObjectVector localManagementObjects;
+ {
+ sys::Mutex::ScopedLock objLock(objectLock);
+ std::transform(managementObjects.begin(), managementObjects.end(),
+ std::back_inserter(localManagementObjects),
+ boost::bind(&ManagementObjectMap::value_type::second, _1));
}
//
// Clear the been-here flag on all objects in the map.
//
- for (ManagementObjectMap::iterator iter = managementObjects.begin();
- iter != managementObjects.end();
+ for (ManagementObjectVector::iterator iter = localManagementObjects.begin();
+ iter != localManagementObjects.end();
iter++) {
- ManagementObject* object = iter->second;
+ ManagementObject::shared_ptr object = *iter;
object->setFlags(0);
if (clientWasAdded) {
object->setForcePublish(true);
@@ -760,22 +735,25 @@ void ManagementAgent::periodicProcessing (void)
// if we sent the active update first, _then_ the delete update, clients
// would incorrectly think the object was deleted. See QPID-2997
//
- bool objectsDeleted = moveDeletedObjectsLH();
+ bool objectsDeleted = moveDeletedObjects();
+ PendingDeletedObjsMap localPendingDeletedObjs;
+ {
+ sys::Mutex::ScopedLock objLock(objectLock);
+ localPendingDeletedObjs.swap(pendingDeletedObjs);
+ }
//
// If we are not publishing updates, just clear the pending deletes. There's no
// need to tell anybody.
//
if (!publish)
- pendingDeletedObjs.clear();
-
- if (!pendingDeletedObjs.empty()) {
- // use a temporary copy of the pending deletes so dropping the lock when
- // the buffer is sent is safe.
- PendingDeletedObjsMap tmp(pendingDeletedObjs);
- pendingDeletedObjs.clear();
+ localPendingDeletedObjs.clear();
- for (PendingDeletedObjsMap::iterator mIter = tmp.begin(); mIter != tmp.end(); mIter++) {
+ ResizableBuffer msgBuffer(qmfV1BufferSize);
+ if (!localPendingDeletedObjs.empty()) {
+ for (PendingDeletedObjsMap::iterator mIter = localPendingDeletedObjs.begin();
+ mIter != localPendingDeletedObjs.end();
+ mIter++) {
std::string packageName;
std::string className;
msgBuffer.reset();
@@ -807,11 +785,10 @@ void ManagementAgent::periodicProcessing (void)
}
if (v1Objs >= maxReplyObjs) {
v1Objs = 0;
- contentSize = msgBuffer.getSize();
stringstream key;
key << "console.obj.1.0." << packageName << "." << className;
- msgBuffer.reset();
- sendBufferLH(msgBuffer, contentSize, mExchange, key.str()); // UNLOCKS USERLOCK
+ size_t contentSize = msgBuffer.getPosition();
+ sendBuffer(msgBuffer, mExchange, key.str());
QPID_LOG(debug, "SEND V1 Multicast ContentInd V1 (delete) to="
<< key.str() << " len=" << contentSize);
}
@@ -840,7 +817,7 @@ void ManagementAgent::periodicProcessing (void)
headers["qmf.content"] = "_data";
headers["qmf.agent"] = name_address;
- sendBufferLH(content, "", headers, "amqp/list", v2Topic, key.str()); // UNLOCKS USERLOCK
+ sendBuffer(content, "", headers, "amqp/list", v2Topic, key.str(), 0);
QPID_LOG(debug, "SEND Multicast ContentInd V2 (delete) to=" << key.str() << " len=" << content.length());
}
}
@@ -850,11 +827,10 @@ void ManagementAgent::periodicProcessing (void)
// send any remaining objects...
if (v1Objs) {
- contentSize = BUFSIZE - msgBuffer.available();
stringstream key;
key << "console.obj.1.0." << packageName << "." << className;
- msgBuffer.reset();
- sendBufferLH(msgBuffer, contentSize, mExchange, key.str()); // UNLOCKS USERLOCK
+ size_t contentSize = msgBuffer.getPosition();
+ sendBuffer(msgBuffer, mExchange, key.str());
QPID_LOG(debug, "SEND V1 Multicast ContentInd V1 (delete) to=" << key.str() << " len=" << contentSize);
}
@@ -877,7 +853,7 @@ void ManagementAgent::periodicProcessing (void)
headers["qmf.content"] = "_data";
headers["qmf.agent"] = name_address;
- sendBufferLH(content, "", headers, "amqp/list", v2Topic, key.str()); // UNLOCKS USERLOCK
+ sendBuffer(content, "", headers, "amqp/list", v2Topic, key.str(), 0);
QPID_LOG(debug, "SEND Multicast ContentInd V2 (delete) to=" << key.str() << " len=" << content.length());
}
}
@@ -885,9 +861,7 @@ void ManagementAgent::periodicProcessing (void)
}
//
- // Process the entire object map. Remember: we drop the userLock each time we call
- // sendBuffer(). This allows the managementObjects map to be altered during the
- // sendBuffer() call, so always restart the search after a sendBuffer() call
+ // Process the entire object map.
//
// If publish is disabled, don't send any updates.
//
@@ -897,14 +871,14 @@ void ManagementAgent::periodicProcessing (void)
uint32_t pcount;
uint32_t scount;
uint32_t v1Objs, v2Objs;
- ManagementObjectMap::iterator baseIter;
+ ManagementObjectVector::iterator baseIter;
std::string packageName;
std::string className;
- for (baseIter = managementObjects.begin();
- baseIter != managementObjects.end();
+ for (baseIter = localManagementObjects.begin();
+ baseIter != localManagementObjects.end();
baseIter++) {
- ManagementObject* baseObject = baseIter->second;
+ ManagementObject::shared_ptr baseObject = *baseIter;
//
// Skip until we find a base object requiring processing...
//
@@ -915,7 +889,7 @@ void ManagementAgent::periodicProcessing (void)
}
}
- if (baseIter == managementObjects.end())
+ if (baseIter == localManagementObjects.end())
break; // done - all objects processed
pcount = scount = 0;
@@ -924,12 +898,12 @@ void ManagementAgent::periodicProcessing (void)
list_.clear();
msgBuffer.reset();
- for (ManagementObjectMap::iterator iter = baseIter;
- iter != managementObjects.end();
+ for (ManagementObjectVector::iterator iter = baseIter;
+ iter != localManagementObjects.end();
iter++) {
msgBuffer.makeAvailable(HEADROOM); // Make sure there's buffer space
- ManagementObject* baseObject = baseIter->second;
- ManagementObject* object = iter->second;
+ ManagementObject::shared_ptr baseObject = *baseIter;
+ ManagementObject::shared_ptr object = *iter;
bool send_stats, send_props;
if (baseObject->isSameClass(*object) && object->getFlags() == 0) {
object->setFlags(1);
@@ -1004,12 +978,11 @@ void ManagementAgent::periodicProcessing (void)
if (pcount || scount) {
if (qmf1Support) {
- contentSize = BUFSIZE - msgBuffer.available();
- if (contentSize > 0) {
+ if (msgBuffer.getPosition() > 0) {
stringstream key;
key << "console.obj.1.0." << packageName << "." << className;
- msgBuffer.reset();
- sendBufferLH(msgBuffer, contentSize, mExchange, key.str()); // UNLOCKS USERLOCK
+ size_t contentSize = msgBuffer.getPosition();
+ sendBuffer(msgBuffer, mExchange, key.str());
QPID_LOG(debug, "SEND V1 Multicast ContentInd to=" << key.str()
<< " props=" << pcount
<< " stats=" << scount
@@ -1035,7 +1008,7 @@ void ManagementAgent::periodicProcessing (void)
headers["qmf.content"] = "_data";
headers["qmf.agent"] = name_address;
- sendBufferLH(content, "", headers, "amqp/list", v2Topic, key.str()); // UNLOCKS USERLOCK
+ sendBuffer(content, "", headers, "amqp/list", v2Topic, key.str(), 0);
QPID_LOG(debug, "SEND Multicast ContentInd to=" << key.str()
<< " props=" << pcount
<< " stats=" << scount
@@ -1045,21 +1018,21 @@ void ManagementAgent::periodicProcessing (void)
}
} // end processing updates for all objects
- if (objectsDeleted) deleteOrphanedAgentsLH();
+ if (objectsDeleted) {
+ sys::Mutex::ScopedLock lock (userLock);
+ deleteOrphanedAgentsLH();
+ }
// heartbeat generation. Note that heartbeats need to be sent even if publish is disabled.
if (qmf1Support) {
- uint32_t contentSize;
- char msgChars[BUFSIZE];
- Buffer msgBuffer(msgChars, BUFSIZE);
+ char msgChars[qmfV1BufferSize];
+ Buffer msgBuffer(msgChars, qmfV1BufferSize);
encodeHeader(msgBuffer, 'h');
msgBuffer.putLongLong(uint64_t(sys::Duration(sys::EPOCH, sys::now())));
- contentSize = BUFSIZE - msgBuffer.available ();
- msgBuffer.reset ();
routingKey = "console.heartbeat.1.0";
- sendBufferLH(msgBuffer, contentSize, mExchange, routingKey);
+ sendBuffer(msgBuffer, mExchange, routingKey);
QPID_LOG(debug, "SEND HeartbeatInd to=" << routingKey);
}
@@ -1087,23 +1060,26 @@ void ManagementAgent::periodicProcessing (void)
// Set TTL (in msecs) on outgoing heartbeat indications based on the interval
// time to prevent stale heartbeats from getting to the consoles.
- sendBufferLH(content, "", headers, "amqp/map", v2Topic, addr_key.str(), interval * 2 * 1000);
+ sendBuffer(content, "", headers, "amqp/map", v2Topic, addr_key.str(), interval * 2 * 1000);
QPID_LOG(debug, "SENT AgentHeartbeat name=" << name_address);
}
}
-void ManagementAgent::deleteObjectNowLH(const ObjectId& oid)
+void ManagementAgent::deleteObjectNow(const ObjectId& oid)
{
- ManagementObjectMap::iterator iter = managementObjects.find(oid);
- if (iter == managementObjects.end())
- return;
- ManagementObject* object = iter->second;
- if (!object->isDeleted())
- return;
+ ManagementObject::shared_ptr object;
+ {
+ sys::Mutex::ScopedLock lock(objectLock);
+ ManagementObjectMap::iterator iter = managementObjects.find(oid);
+ if (iter == managementObjects.end())
+ return;
+ object = iter->second;
+ if (!object->isDeleted())
+ return;
+ managementObjects.erase(oid);
+ }
- // since sendBufferLH drops the userLock, don't call it until we
- // are done manipulating the object.
#define DNOW_BUFSIZE 2048
char msgChars[DNOW_BUFSIZE];
Buffer msgBuffer(msgChars, DNOW_BUFSIZE);
@@ -1139,15 +1115,12 @@ void ManagementAgent::deleteObjectNowLH(const ObjectId& oid)
v2key << "." << instanceNameKey;
}
- object = 0;
- managementObjects.erase(oid);
+ object.reset();
// object deleted, ok to drop lock now.
if (publish && qmf1Support) {
- uint32_t contentSize = msgBuffer.getPosition();
- msgBuffer.reset();
- sendBufferLH(msgBuffer, contentSize, mExchange, v1key.str());
+ sendBuffer(msgBuffer, mExchange, v1key.str());
QPID_LOG(debug, "SEND Immediate(delete) ContentInd to=" << v1key.str());
}
@@ -1160,29 +1133,26 @@ void ManagementAgent::deleteObjectNowLH(const ObjectId& oid)
string content;
ListCodec::encode(list_, content);
- sendBufferLH(content, "", headers, "amqp/list", v2Topic, v2key.str());
+ sendBuffer(content, "", headers, "amqp/list", v2Topic, v2key.str(), 0);
QPID_LOG(debug, "SEND Immediate(delete) ContentInd to=" << v2key.str());
}
}
-void ManagementAgent::sendCommandCompleteLH(const string& replyToKey, uint32_t sequence,
- uint32_t code, const string& text)
+void ManagementAgent::sendCommandComplete(const string& replyToKey, uint32_t sequence,
+ uint32_t code, const string& text)
{
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer (qmfV1BufferSize);
encodeHeader (outBuffer, 'z', sequence);
outBuffer.putLong (code);
outBuffer.putShortString (text);
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND CommandCompleteInd code=" << code << " text=" << text << " to=" <<
replyToKey << " seq=" << sequence);
}
-void ManagementAgent::sendExceptionLH(const string& rte, const string& rtk, const string& cid,
- const string& text, uint32_t code, bool viaLocal)
+void ManagementAgent::sendException(const string& rte, const string& rtk, const string& cid,
+ const string& text, uint32_t code, bool viaLocal)
{
static const string addr_exchange("qmf.default.direct");
@@ -1200,7 +1170,7 @@ void ManagementAgent::sendExceptionLH(const string& rte, const string& rtk, cons
map["_values"] = values;
MapCodec::encode(map, content);
- sendBufferLH(content, cid, headers, "amqp/map", rte, rtk);
+ sendBuffer(content, cid, headers, "amqp/map", rte, rtk);
QPID_LOG(debug, "SENT Exception code=" << code <<" text=" << text);
}
@@ -1211,7 +1181,6 @@ bool ManagementAgent::dispatchCommand (Deliverable& deliverable,
const bool topic,
int qmfVersion)
{
- sys::Mutex::ScopedLock lock (userLock);
Message& msg = ((DeliverableMessage&) deliverable).getMessage ();
if (topic && qmfVersion == 1) {
@@ -1225,23 +1194,23 @@ bool ManagementAgent::dispatchCommand (Deliverable& deliverable,
// schema.#
if (routingKey == "broker") {
- dispatchAgentCommandLH(msg);
+ dispatchAgentCommand(msg);
return false;
}
if (routingKey.length() > 6) {
if (routingKey.compare(0, 9, "agent.1.0") == 0) {
- dispatchAgentCommandLH(msg);
+ dispatchAgentCommand(msg);
return false;
}
if (routingKey.compare(0, 8, "agent.1.") == 0) {
- return authorizeAgentMessageLH(msg);
+ return authorizeAgentMessage(msg);
}
if (routingKey.compare(0, 7, "schema.") == 0) {
- dispatchAgentCommandLH(msg);
+ dispatchAgentCommand(msg);
return true;
}
}
@@ -1253,7 +1222,7 @@ bool ManagementAgent::dispatchCommand (Deliverable& deliverable,
// Intercept messages bound to:
// "console.ind.locate.# - process these messages, and also allow them to be forwarded.
if (routingKey == "console.request.agent_locate") {
- dispatchAgentCommandLH(msg);
+ dispatchAgentCommand(msg);
return true;
}
@@ -1264,7 +1233,7 @@ bool ManagementAgent::dispatchCommand (Deliverable& deliverable,
// "<name_address>" - the broker agent's proper name
// and do not forward them futher
if (routingKey == "broker" || routingKey == name_address) {
- dispatchAgentCommandLH(msg, routingKey == "broker");
+ dispatchAgentCommand(msg, routingKey == "broker");
return false;
}
}
@@ -1273,16 +1242,15 @@ bool ManagementAgent::dispatchCommand (Deliverable& deliverable,
return true;
}
-void ManagementAgent::handleMethodRequestLH(Buffer& inBuffer, const string& replyToKey, uint32_t sequence, const ConnectionToken* connToken)
+void ManagementAgent::handleMethodRequest(Buffer& inBuffer, const string& replyToKey, uint32_t sequence, const ConnectionToken* connToken)
{
- moveNewObjectsLH();
+ moveNewObjects();
string methodName;
string packageName;
string className;
uint8_t hash[16];
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer (qmfV1BufferSize);
AclModule* acl = broker->getAcl();
string inArgs;
@@ -1304,9 +1272,7 @@ void ManagementAgent::handleMethodRequestLH(Buffer& inBuffer, const string& repl
if (disallowAllV1Methods) {
outBuffer.putLong(Manageable::STATUS_FORBIDDEN);
outBuffer.putMediumString("QMFv1 methods forbidden on this broker, use QMFv2");
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND MethodResponse status=FORBIDDEN reason='All QMFv1 Methods Forbidden' seq=" << sequence);
return;
}
@@ -1315,9 +1281,7 @@ void ManagementAgent::handleMethodRequestLH(Buffer& inBuffer, const string& repl
if (i != disallowed.end()) {
outBuffer.putLong(Manageable::STATUS_FORBIDDEN);
outBuffer.putMediumString(i->second);
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND MethodResponse status=FORBIDDEN text=" << i->second << " seq=" << sequence);
return;
}
@@ -1331,30 +1295,34 @@ void ManagementAgent::handleMethodRequestLH(Buffer& inBuffer, const string& repl
if (!acl->authorise(userId, acl::ACT_ACCESS, acl::OBJ_METHOD, methodName, &params)) {
outBuffer.putLong(Manageable::STATUS_FORBIDDEN);
outBuffer.putMediumString(Manageable::StatusText(Manageable::STATUS_FORBIDDEN));
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND MethodResponse status=FORBIDDEN" << " seq=" << sequence);
return;
}
}
- ManagementObjectMap::iterator iter = numericFind(objId);
- if (iter == managementObjects.end() || iter->second->isDeleted()) {
+ ManagementObject::shared_ptr object;
+ {
+ sys::Mutex::ScopedLock lock(objectLock);
+ ManagementObjectMap::iterator iter = numericFind(objId);
+ if (iter != managementObjects.end())
+ object = iter->second;
+ }
+
+ if (!object || object->isDeleted()) {
outBuffer.putLong (Manageable::STATUS_UNKNOWN_OBJECT);
outBuffer.putMediumString(Manageable::StatusText (Manageable::STATUS_UNKNOWN_OBJECT));
} else {
- if ((iter->second->getPackageName() != packageName) ||
- (iter->second->getClassName() != className)) {
+ if ((object->getPackageName() != packageName) ||
+ (object->getClassName() != className)) {
outBuffer.putLong (Manageable::STATUS_PARAMETER_INVALID);
outBuffer.putMediumString(Manageable::StatusText (Manageable::STATUS_PARAMETER_INVALID));
}
else {
uint32_t pos = outBuffer.getPosition();
try {
- sys::Mutex::ScopedUnlock u(userLock);
string outBuf;
- iter->second->doMethod(methodName, inArgs, outBuf, userId);
+ object->doMethod(methodName, inArgs, outBuf, userId);
outBuffer.putRawData(outBuf);
} catch(exception& e) {
outBuffer.setPosition(pos);;
@@ -1364,17 +1332,15 @@ void ManagementAgent::handleMethodRequestLH(Buffer& inBuffer, const string& repl
}
}
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND MethodResponse (v1) to=" << replyToKey << " seq=" << sequence);
}
-void ManagementAgent::handleMethodRequestLH (const string& body, const string& rte, const string& rtk,
- const string& cid, const ConnectionToken* connToken, bool viaLocal)
+void ManagementAgent::handleMethodRequest (const string& body, const string& rte, const string& rtk,
+ const string& cid, const ConnectionToken* connToken, bool viaLocal)
{
- moveNewObjectsLH();
+ moveNewObjects();
string methodName;
Variant::Map inMap;
@@ -1393,8 +1359,8 @@ void ManagementAgent::handleMethodRequestLH (const string& body, const string& r
if ((oid = inMap.find("_object_id")) == inMap.end() ||
(mid = inMap.find("_method_name")) == inMap.end()) {
- sendExceptionLH(rte, rtk, cid, Manageable::StatusText(Manageable::STATUS_PARAMETER_INVALID),
- Manageable::STATUS_PARAMETER_INVALID, viaLocal);
+ sendException(rte, rtk, cid, Manageable::StatusText(Manageable::STATUS_PARAMETER_INVALID),
+ Manageable::STATUS_PARAMETER_INVALID, viaLocal);
return;
}
@@ -1412,16 +1378,22 @@ void ManagementAgent::handleMethodRequestLH (const string& body, const string& r
inArgs = (mid->second).asMap();
}
} catch(exception& e) {
- sendExceptionLH(rte, rtk, cid, e.what(), Manageable::STATUS_EXCEPTION, viaLocal);
+ sendException(rte, rtk, cid, e.what(), Manageable::STATUS_EXCEPTION, viaLocal);
return;
}
- ManagementObjectMap::iterator iter = managementObjects.find(objId);
+ ManagementObject::shared_ptr object;
+ {
+ sys::Mutex::ScopedLock lock(objectLock);
+ ManagementObjectMap::iterator iter = managementObjects.find(objId);
+ if (iter != managementObjects.end())
+ object = iter->second;
+ }
- if (iter == managementObjects.end() || iter->second->isDeleted()) {
+ if (!object || object->isDeleted()) {
stringstream estr;
estr << "No object found with ID=" << objId;
- sendExceptionLH(rte, rtk, cid, estr.str(), 1, viaLocal);
+ sendException(rte, rtk, cid, estr.str(), 1, viaLocal);
return;
}
@@ -1429,34 +1401,33 @@ void ManagementAgent::handleMethodRequestLH (const string& body, const string& r
AclModule* acl = broker->getAcl();
DisallowedMethods::const_iterator i;
- i = disallowed.find(make_pair(iter->second->getClassName(), methodName));
+ i = disallowed.find(make_pair(object->getClassName(), methodName));
if (i != disallowed.end()) {
- sendExceptionLH(rte, rtk, cid, i->second, Manageable::STATUS_FORBIDDEN, viaLocal);
+ sendException(rte, rtk, cid, i->second, Manageable::STATUS_FORBIDDEN, viaLocal);
return;
}
string userId = ((const qpid::broker::ConnectionState*) connToken)->getUserId();
if (acl != 0) {
map<acl::Property, string> params;
- params[acl::PROP_SCHEMAPACKAGE] = iter->second->getPackageName();
- params[acl::PROP_SCHEMACLASS] = iter->second->getClassName();
+ params[acl::PROP_SCHEMAPACKAGE] = object->getPackageName();
+ params[acl::PROP_SCHEMACLASS] = object->getClassName();
if (!acl->authorise(userId, acl::ACT_ACCESS, acl::OBJ_METHOD, methodName, &params)) {
- sendExceptionLH(rte, rtk, cid, Manageable::StatusText(Manageable::STATUS_FORBIDDEN),
- Manageable::STATUS_FORBIDDEN, viaLocal);
+ sendException(rte, rtk, cid, Manageable::StatusText(Manageable::STATUS_FORBIDDEN),
+ Manageable::STATUS_FORBIDDEN, viaLocal);
return;
}
}
// invoke the method
- QPID_LOG(debug, "RECV MethodRequest (v2) class=" << iter->second->getPackageName()
- << ":" << iter->second->getClassName() << " method=" <<
+ QPID_LOG(debug, "RECV MethodRequest (v2) class=" << object->getPackageName()
+ << ":" << object->getClassName() << " method=" <<
methodName << " replyTo=" << rte << "/" << rtk << " objId=" << objId << " inArgs=" << inArgs);
try {
- sys::Mutex::ScopedUnlock u(userLock);
- iter->second->doMethod(methodName, inArgs, callMap, userId);
+ object->doMethod(methodName, inArgs, callMap, userId);
errorCode = callMap["_status_code"].asUint32();
if (errorCode == 0) {
outMap["_arguments"] = Variant::Map();
@@ -1467,62 +1438,59 @@ void ManagementAgent::handleMethodRequestLH (const string& body, const string& r
} else
error = callMap["_status_text"].asString();
} catch(exception& e) {
- sendExceptionLH(rte, rtk, cid, e.what(), Manageable::STATUS_EXCEPTION, viaLocal);
+ sendException(rte, rtk, cid, e.what(), Manageable::STATUS_EXCEPTION, viaLocal);
return;
}
if (errorCode != 0) {
- sendExceptionLH(rte, rtk, cid, error, errorCode, viaLocal);
+ sendException(rte, rtk, cid, error, errorCode, viaLocal);
return;
}
MapCodec::encode(outMap, content);
- sendBufferLH(content, cid, headers, "amqp/map", rte, rtk);
+ sendBuffer(content, cid, headers, "amqp/map", rte, rtk);
QPID_LOG(debug, "SEND MethodResponse (v2) to=" << rte << "/" << rtk << " seq=" << cid << " map=" << outMap);
}
-void ManagementAgent::handleBrokerRequestLH (Buffer&, const string& replyToKey, uint32_t sequence)
+void ManagementAgent::handleBrokerRequest (Buffer&, const string& replyToKey, uint32_t sequence)
{
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer (qmfV1BufferSize);
QPID_LOG(debug, "RECV BrokerRequest replyTo=" << replyToKey);
encodeHeader (outBuffer, 'b', sequence);
uuid.encode (outBuffer);
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND BrokerResponse to=" << replyToKey);
}
-void ManagementAgent::handlePackageQueryLH (Buffer&, const string& replyToKey, uint32_t sequence)
+void ManagementAgent::handlePackageQuery (Buffer&, const string& replyToKey, uint32_t sequence)
{
QPID_LOG(debug, "RECV PackageQuery replyTo=" << replyToKey);
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer (qmfV1BufferSize);
- for (PackageMap::iterator pIter = packages.begin ();
- pIter != packages.end ();
- pIter++)
{
- encodeHeader (outBuffer, 'p', sequence);
- encodePackageIndication (outBuffer, pIter);
+ sys::Mutex::ScopedLock lock(userLock);
+ for (PackageMap::iterator pIter = packages.begin ();
+ pIter != packages.end ();
+ pIter++)
+ {
+ encodeHeader (outBuffer, 'p', sequence);
+ encodePackageIndication (outBuffer, pIter);
+ }
}
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- if (outLen) {
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ if (outBuffer.getPosition() > 0) {
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND PackageInd to=" << replyToKey << " seq=" << sequence);
}
- sendCommandCompleteLH(replyToKey, sequence);
+ sendCommandComplete(replyToKey, sequence);
}
-void ManagementAgent::handlePackageIndLH (Buffer& inBuffer, const string& replyToKey, uint32_t sequence)
+void ManagementAgent::handlePackageInd (Buffer& inBuffer, const string& replyToKey, uint32_t sequence)
{
string packageName;
@@ -1530,10 +1498,11 @@ void ManagementAgent::handlePackageIndLH (Buffer& inBuffer, const string& replyT
QPID_LOG(debug, "RECV PackageInd package=" << packageName << " replyTo=" << replyToKey << " seq=" << sequence);
+ sys::Mutex::ScopedLock lock(userLock);
findOrAddPackageLH(packageName);
}
-void ManagementAgent::handleClassQueryLH(Buffer& inBuffer, const string& replyToKey, uint32_t sequence)
+void ManagementAgent::handleClassQuery(Buffer& inBuffer, const string& replyToKey, uint32_t sequence)
{
string packageName;
@@ -1541,40 +1510,39 @@ void ManagementAgent::handleClassQueryLH(Buffer& inBuffer, const string& replyTo
QPID_LOG(debug, "RECV ClassQuery package=" << packageName << " replyTo=" << replyToKey << " seq=" << sequence);
- PackageMap::iterator pIter = packages.find(packageName);
- if (pIter != packages.end())
+ typedef std::pair<SchemaClassKey, uint8_t> _ckeyType;
+ std::list<_ckeyType> classes;
{
- typedef std::pair<SchemaClassKey, uint8_t> _ckeyType;
- std::list<_ckeyType> classes;
- ClassMap &cMap = pIter->second;
- for (ClassMap::iterator cIter = cMap.begin();
- cIter != cMap.end();
- cIter++) {
- if (cIter->second.hasSchema()) {
- classes.push_back(make_pair(cIter->first, cIter->second.kind));
+ sys::Mutex::ScopedLock lock(userLock);
+ PackageMap::iterator pIter = packages.find(packageName);
+ if (pIter != packages.end())
+ {
+ ClassMap &cMap = pIter->second;
+ for (ClassMap::iterator cIter = cMap.begin();
+ cIter != cMap.end();
+ cIter++) {
+ if (cIter->second.hasSchema()) {
+ classes.push_back(make_pair(cIter->first, cIter->second.kind));
+ }
}
}
+ }
- while (classes.size()) {
- Buffer outBuffer(outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ while (classes.size()) {
+ ResizableBuffer outBuffer(qmfV1BufferSize);
- encodeHeader(outBuffer, 'q', sequence);
- encodeClassIndication(outBuffer, packageName, classes.front().first, classes.front().second);
-
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
- QPID_LOG(debug, "SEND ClassInd class=" << packageName << ":" << classes.front().first.name <<
- "(" << Uuid(classes.front().first.hash) << ") to=" << replyToKey << " seq=" << sequence);
- classes.pop_front();
- }
+ encodeHeader(outBuffer, 'q', sequence);
+ encodeClassIndication(outBuffer, packageName, classes.front().first, classes.front().second);
+ sendBuffer(outBuffer, dExchange, replyToKey);
+ QPID_LOG(debug, "SEND ClassInd class=" << packageName << ":" << classes.front().first.name <<
+ "(" << Uuid(classes.front().first.hash) << ") to=" << replyToKey << " seq=" << sequence);
+ classes.pop_front();
}
- sendCommandCompleteLH(replyToKey, sequence);
+ sendCommandComplete(replyToKey, sequence);
}
-void ManagementAgent::handleClassIndLH (Buffer& inBuffer, const string& replyToKey, uint32_t)
+void ManagementAgent::handleClassInd (Buffer& inBuffer, const string& replyToKey, uint32_t)
{
string packageName;
SchemaClassKey key;
@@ -1587,20 +1555,18 @@ void ManagementAgent::handleClassIndLH (Buffer& inBuffer, const string& replyToK
QPID_LOG(debug, "RECV ClassInd class=" << packageName << ":" << key.name << "(" << Uuid(key.hash) <<
"), replyTo=" << replyToKey);
+ sys::Mutex::ScopedLock lock(userLock);
PackageMap::iterator pIter = findOrAddPackageLH(packageName);
ClassMap::iterator cIter = pIter->second.find(key);
if (cIter == pIter->second.end() || !cIter->second.hasSchema()) {
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer (qmfV1BufferSize);
uint32_t sequence = nextRequestSequence++;
// Schema Request
encodeHeader (outBuffer, 'S', sequence);
outBuffer.putShortString(packageName);
key.encode(outBuffer);
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND SchemaRequest class=" << packageName << ":" << key.name << "(" << Uuid(key.hash) <<
"), to=" << replyToKey << " seq=" << sequence);
@@ -1625,7 +1591,7 @@ void ManagementAgent::SchemaClass::appendSchema(Buffer& buf)
buf.putRawData(reinterpret_cast<uint8_t*>(&data[0]), data.size());
}
-void ManagementAgent::handleSchemaRequestLH(Buffer& inBuffer, const string& rte, const string& rtk, uint32_t sequence)
+void ManagementAgent::handleSchemaRequest(Buffer& inBuffer, const string& rte, const string& rtk, uint32_t sequence)
{
string packageName;
SchemaClassKey key;
@@ -1636,34 +1602,32 @@ void ManagementAgent::handleSchemaRequestLH(Buffer& inBuffer, const string& rte,
QPID_LOG(debug, "RECV SchemaRequest class=" << packageName << ":" << key.name << "(" << Uuid(key.hash) <<
"), replyTo=" << rte << "/" << rtk << " seq=" << sequence);
+ sys::Mutex::ScopedLock lock(userLock);
PackageMap::iterator pIter = packages.find(packageName);
if (pIter != packages.end()) {
ClassMap& cMap = pIter->second;
ClassMap::iterator cIter = cMap.find(key);
if (cIter != cMap.end()) {
- Buffer outBuffer(outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer(qmfV1BufferSize);
SchemaClass& classInfo = cIter->second;
if (classInfo.hasSchema()) {
encodeHeader(outBuffer, 's', sequence);
classInfo.appendSchema(outBuffer);
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, rte, rtk);
+ sendBuffer(outBuffer, rte, rtk);
QPID_LOG(debug, "SEND SchemaResponse to=" << rte << "/" << rtk << " seq=" << sequence);
}
else
- sendCommandCompleteLH(rtk, sequence, 1, "Schema not available");
+ sendCommandComplete(rtk, sequence, 1, "Schema not available");
}
else
- sendCommandCompleteLH(rtk, sequence, 1, "Class key not found");
+ sendCommandComplete(rtk, sequence, 1, "Class key not found");
}
else
- sendCommandCompleteLH(rtk, sequence, 1, "Package not found");
+ sendCommandComplete(rtk, sequence, 1, "Package not found");
}
-void ManagementAgent::handleSchemaResponseLH(Buffer& inBuffer, const string& /*replyToKey*/, uint32_t sequence)
+void ManagementAgent::handleSchemaResponse(Buffer& inBuffer, const string& /*replyToKey*/, uint32_t sequence)
{
string packageName;
SchemaClassKey key;
@@ -1676,6 +1640,7 @@ void ManagementAgent::handleSchemaResponseLH(Buffer& inBuffer, const string& /*r
QPID_LOG(debug, "RECV SchemaResponse class=" << packageName << ":" << key.name << "(" << Uuid(key.hash) << ")" << " seq=" << sequence);
+ sys::Mutex::ScopedLock lock(userLock);
PackageMap::iterator pIter = packages.find(packageName);
if (pIter != packages.end()) {
ClassMap& cMap = pIter->second;
@@ -1690,14 +1655,11 @@ void ManagementAgent::handleSchemaResponseLH(Buffer& inBuffer, const string& /*r
inBuffer.getRawData(reinterpret_cast<uint8_t*>(&cIter->second.data[0]), length);
// Publish a class-indication message
- Buffer outBuffer(outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer(qmfV1BufferSize);
encodeHeader(outBuffer, 'q');
encodeClassIndication(outBuffer, pIter->first, cIter->first, cIter->second.kind);
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, mExchange, "schema.class");
+ sendBuffer(outBuffer, mExchange, "schema.class");
QPID_LOG(debug, "SEND ClassInd class=" << packageName << ":" << key.name << "(" << Uuid(key.hash) << ")" <<
" to=schema.class");
}
@@ -1756,7 +1718,7 @@ void ManagementAgent::deleteOrphanedAgentsLH()
remoteAgents.erase(*dIter);
}
-void ManagementAgent::handleAttachRequestLH (Buffer& inBuffer, const string& replyToKey, uint32_t sequence, const ConnectionToken* connToken)
+void ManagementAgent::handleAttachRequest (Buffer& inBuffer, const string& replyToKey, uint32_t sequence, const ConnectionToken* connToken)
{
string label;
uint32_t requestedBrokerBank, requestedAgentBank;
@@ -1764,12 +1726,14 @@ void ManagementAgent::handleAttachRequestLH (Buffer& inBuffer, const string& rep
ObjectId connectionRef = ((const ConnectionState*) connToken)->GetManagementObject()->getObjectId();
Uuid systemId;
- moveNewObjectsLH();
+ moveNewObjects();
+
+ sys::Mutex::ScopedLock lock(userLock);
deleteOrphanedAgentsLH();
RemoteAgentMap::iterator aIter = remoteAgents.find(connectionRef);
if (aIter != remoteAgents.end()) {
// There already exists an agent on this session. Reject the request.
- sendCommandCompleteLH(replyToKey, sequence, 1, "Connection already has remote agent");
+ sendCommandComplete(replyToKey, sequence, 1, "Connection already has remote agent");
return;
}
@@ -1788,7 +1752,7 @@ void ManagementAgent::handleAttachRequestLH (Buffer& inBuffer, const string& rep
agent->agentBank = assignedBank;
agent->routingKey = replyToKey;
agent->connectionRef = connectionRef;
- agent->mgmtObject = new _qmf::Agent (this, agent.get());
+ agent->mgmtObject = _qmf::Agent::shared_ptr(new _qmf::Agent (this, agent.get()));
agent->mgmtObject->set_connectionRef(agent->connectionRef);
agent->mgmtObject->set_label (label);
agent->mgmtObject->set_registeredTo (broker->GetManagementObject()->getObjectId());
@@ -1801,25 +1765,22 @@ void ManagementAgent::handleAttachRequestLH (Buffer& inBuffer, const string& rep
QPID_LOG(debug, "Remote Agent registered bank=[" << brokerBank << "." << assignedBank << "] replyTo=" << replyToKey);
// Send an Attach Response
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer (qmfV1BufferSize);
encodeHeader (outBuffer, 'a', sequence);
outBuffer.putLong (brokerBank);
outBuffer.putLong (assignedBank);
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND AttachResponse brokerBank=" << brokerBank << " agentBank=" << assignedBank <<
" to=" << replyToKey << " seq=" << sequence);
}
-void ManagementAgent::handleGetQueryLH(Buffer& inBuffer, const string& replyToKey, uint32_t sequence)
+void ManagementAgent::handleGetQuery(Buffer& inBuffer, const string& replyToKey, uint32_t sequence)
{
FieldTable ft;
FieldTable::ValuePtr value;
- moveNewObjectsLH();
+ moveNewObjects();
ft.decode(inBuffer);
@@ -1832,11 +1793,17 @@ void ManagementAgent::handleGetQueryLH(Buffer& inBuffer, const string& replyToKe
return;
ObjectId selector(value->get<string>());
- ManagementObjectMap::iterator iter = numericFind(selector);
- if (iter != managementObjects.end()) {
- ManagementObject* object = iter->second;
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+
+ ManagementObject::shared_ptr object;
+ {
+ sys::Mutex::ScopedLock lock(objectLock);
+ ManagementObjectMap::iterator iter = numericFind(selector);
+ if (iter != managementObjects.end())
+ object = iter->second;
+ }
+
+ if (object) {
+ ResizableBuffer outBuffer (qmfV1BufferSize);
if (object->getConfigChanged() || object->getInstChanged())
object->setUpdateTime();
@@ -1849,89 +1816,80 @@ void ManagementAgent::handleGetQueryLH(Buffer& inBuffer, const string& replyToKe
sBuf.clear();
object->writeStatistics(sBuf, true);
outBuffer.putRawData(sBuf);
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND GetResponse (v1) to=" << replyToKey << " seq=" << sequence);
}
}
- sendCommandCompleteLH(replyToKey, sequence);
+ sendCommandComplete(replyToKey, sequence);
return;
}
string className (value->get<string>());
- std::list<ObjectId>matches;
+ std::list<ManagementObject::shared_ptr> matches;
if (className == "memory")
- qpid::sys::MemStat::loadMemInfo(memstat);
+ qpid::sys::MemStat::loadMemInfo(memstat.get());
if (className == "broker") {
uint64_t uptime = sys::Duration(startTime, sys::now());
- static_cast<_qmf::Broker*>(broker->GetManagementObject())->set_uptime(uptime);
+ boost::dynamic_pointer_cast<_qmf::Broker>(broker->GetManagementObject())->set_uptime(uptime);
}
// build up a set of all objects to be dumped
- for (ManagementObjectMap::iterator iter = managementObjects.begin();
- iter != managementObjects.end();
- iter++) {
- ManagementObject* object = iter->second;
- if (object->getClassName () == className) {
- matches.push_back(object->getObjectId());
+ {
+ sys::Mutex::ScopedLock lock(objectLock);
+ for (ManagementObjectMap::iterator iter = managementObjects.begin();
+ iter != managementObjects.end();
+ iter++) {
+ ManagementObject::shared_ptr object = iter->second;
+ if (object->getClassName () == className) {
+ matches.push_back(object);
+ }
}
}
- // send them (as sendBufferLH drops the userLock)
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ // send them
+ ResizableBuffer outBuffer (qmfV1BufferSize);
while (matches.size()) {
- ObjectId objId = matches.front();
- ManagementObjectMap::iterator oIter = managementObjects.find( objId );
- if (oIter != managementObjects.end()) {
- ManagementObject* object = oIter->second;
-
- if (object->getConfigChanged() || object->getInstChanged())
- object->setUpdateTime();
-
- if (!object->isDeleted()) {
- string sProps, sStats;
- object->writeProperties(sProps);
- object->writeStatistics(sStats, true);
-
- size_t len = 8 + sProps.length() + sStats.length(); // 8 == size of header in bytes.
- if (len > MA_BUFFER_SIZE) {
- QPID_LOG(error, "Object " << objId << " too large for output buffer - discarded!");
- } else {
- if (outBuffer.available() < len) { // not enough room in current buffer, send it.
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey); // drops lock
- QPID_LOG(debug, "SEND GetResponse (v1) to=" << replyToKey << " seq=" << sequence);
- continue; // lock dropped, need to re-find _SAME_ objid as it may have been deleted.
- }
- encodeHeader(outBuffer, 'g', sequence);
- outBuffer.putRawData(sProps);
- outBuffer.putRawData(sStats);
+ ManagementObject::shared_ptr object = matches.front();
+ if (object->getConfigChanged() || object->getInstChanged())
+ object->setUpdateTime();
+
+ if (!object->isDeleted()) {
+ string sProps, sStats;
+ object->writeProperties(sProps);
+ object->writeStatistics(sStats, true);
+
+ size_t len = 8 + sProps.length() + sStats.length(); // 8 == size of header in bytes.
+ if (len > qmfV1BufferSize) {
+ QPID_LOG(error, "Object " << object->getObjectId() << " too large for output buffer - discarded!");
+ } else {
+ if (outBuffer.available() < len) { // not enough room in current buffer, send it.
+ sendBuffer(outBuffer, dExchange, replyToKey);
+ QPID_LOG(debug, "SEND GetResponse (v1) to=" << replyToKey << " seq=" << sequence);
+ continue; // lock dropped, need to re-find _SAME_ objid as it may have been deleted.
}
+ encodeHeader(outBuffer, 'g', sequence);
+ outBuffer.putRawData(sProps);
+ outBuffer.putRawData(sStats);
}
}
matches.pop_front();
}
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- if (outLen) {
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, dExchange, replyToKey);
+ if (outBuffer.getPosition() > 0) {
+ sendBuffer(outBuffer, dExchange, replyToKey);
QPID_LOG(debug, "SEND GetResponse (v1) to=" << replyToKey << " seq=" << sequence);
}
- sendCommandCompleteLH(replyToKey, sequence);
+ sendCommandComplete(replyToKey, sequence);
}
-void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, const string& rtk, const string& cid, bool viaLocal)
+void ManagementAgent::handleGetQuery(const string& body, const string& rte, const string& rtk, const string& cid, bool viaLocal)
{
- moveNewObjectsLH();
+ moveNewObjects();
Variant::Map inMap;
Variant::Map::const_iterator i;
@@ -1950,17 +1908,17 @@ void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, co
*/
i = inMap.find("_what");
if (i == inMap.end()) {
- sendExceptionLH(rte, rtk, cid, "_what element missing in Query");
+ sendException(rte, rtk, cid, "_what element missing in Query");
return;
}
if (i->second.getType() != qpid::types::VAR_STRING) {
- sendExceptionLH(rte, rtk, cid, "_what element is not a string");
+ sendException(rte, rtk, cid, "_what element is not a string");
return;
}
if (i->second.asString() != "OBJECT") {
- sendExceptionLH(rte, rtk, cid, "Query for _what => '" + i->second.asString() + "' not supported");
+ sendException(rte, rtk, cid, "Query for _what => '" + i->second.asString() + "' not supported");
return;
}
@@ -1984,11 +1942,11 @@ void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, co
}
if (className == "memory")
- qpid::sys::MemStat::loadMemInfo(memstat);
+ qpid::sys::MemStat::loadMemInfo(memstat.get());
if (className == "broker") {
uint64_t uptime = sys::Duration(startTime, sys::now());
- static_cast<_qmf::Broker*>(broker->GetManagementObject())->set_uptime(uptime);
+ boost::dynamic_pointer_cast<_qmf::Broker>(broker->GetManagementObject())->set_uptime(uptime);
}
/*
@@ -2000,10 +1958,14 @@ void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, co
Variant::List list_;
ObjectId objId(i->second.asMap());
- ManagementObjectMap::iterator iter = managementObjects.find(objId);
- if (iter != managementObjects.end()) {
- ManagementObject* object = iter->second;
-
+ ManagementObject::shared_ptr object;
+ {
+ sys::Mutex::ScopedLock lock (objectLock);
+ ManagementObjectMap::iterator iter = managementObjects.find(objId);
+ if (iter != managementObjects.end())
+ object = iter->second;
+ }
+ if (object) {
if (object->getConfigChanged() || object->getInstChanged())
object->setUpdateTime();
@@ -2027,7 +1989,7 @@ void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, co
string content;
ListCodec::encode(list_, content);
- sendBufferLH(content, cid, headers, "amqp/list", rte, rtk);
+ sendBuffer(content, cid, headers, "amqp/list", rte, rtk);
QPID_LOG(debug, "SENT QueryResponse (query by object_id) to=" << rte << "/" << rtk);
return;
}
@@ -2037,10 +1999,18 @@ void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, co
Variant::List _subList;
unsigned int objCount = 0;
- for (ManagementObjectMap::iterator iter = managementObjects.begin();
- iter != managementObjects.end();
+ ManagementObjectVector localManagementObjects;
+ {
+ sys::Mutex::ScopedLock objLock(objectLock);
+ std::transform(managementObjects.begin(), managementObjects.end(),
+ std::back_inserter(localManagementObjects),
+ boost::bind(&ManagementObjectMap::value_type::second, _1));
+ }
+
+ for (ManagementObjectVector::iterator iter = localManagementObjects.begin();
+ iter != localManagementObjects.end();
iter++) {
- ManagementObject* object = iter->second;
+ ManagementObject::shared_ptr object = *iter;
if (object->getClassName() == className &&
(packageName.empty() || object->getPackageName() == packageName)) {
@@ -2055,7 +2025,7 @@ void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, co
object->writeTimestamps(map_);
object->mapEncodeValues(values, true, true); // write both stats and properties
- iter->first.mapEncode(oidMap);
+ object->getObjectId().mapEncode(oidMap);
map_["_values"] = values;
map_["_object_id"] = oidMap;
@@ -2080,13 +2050,13 @@ void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, co
string content;
while (_list.size() > 1) {
ListCodec::encode(_list.front().asList(), content);
- sendBufferLH(content, cid, headers, "amqp/list", rte, rtk);
+ sendBuffer(content, cid, headers, "amqp/list", rte, rtk);
_list.pop_front();
QPID_LOG(debug, "SENT QueryResponse (partial, query by schema_id) to=" << rte << "/" << rtk << " len=" << content.length());
}
headers.erase("partial");
ListCodec::encode(_list.size() ? _list.front().asList() : Variant::List(), content);
- sendBufferLH(content, cid, headers, "amqp/list", rte, rtk);
+ sendBuffer(content, cid, headers, "amqp/list", rte, rtk);
QPID_LOG(debug, "SENT QueryResponse (query by schema_id) to=" << rte << "/" << rtk << " len=" << content.length());
return;
}
@@ -2094,12 +2064,12 @@ void ManagementAgent::handleGetQueryLH(const string& body, const string& rte, co
// Unrecognized query - Send empty message to indicate CommandComplete
string content;
ListCodec::encode(Variant::List(), content);
- sendBufferLH(content, cid, headers, "amqp/list", rte, rtk);
+ sendBuffer(content, cid, headers, "amqp/list", rte, rtk);
QPID_LOG(debug, "SENT QueryResponse (empty) to=" << rte << "/" << rtk);
}
-void ManagementAgent::handleLocateRequestLH(const string&, const string& rte, const string& rtk, const string& cid)
+void ManagementAgent::handleLocateRequest(const string&, const string& rte, const string& rtk, const string& cid)
{
QPID_LOG(debug, "RCVD AgentLocateRequest");
@@ -2117,16 +2087,17 @@ void ManagementAgent::handleLocateRequestLH(const string&, const string& rte, co
string content;
MapCodec::encode(map, content);
- sendBufferLH(content, cid, headers, "amqp/map", rte, rtk);
+ sendBuffer(content, cid, headers, "amqp/map", rte, rtk);
clientWasAdded = true;
QPID_LOG(debug, "SENT AgentLocateResponse replyTo=" << rte << "/" << rtk);
}
-bool ManagementAgent::authorizeAgentMessageLH(Message& msg)
+bool ManagementAgent::authorizeAgentMessage(Message& msg)
{
- Buffer inBuffer (inputBuffer, MA_BUFFER_SIZE);
+ sys::Mutex::ScopedLock lock(userLock);
+ ResizableBuffer inBuffer (qmfV1BufferSize);
uint32_t sequence = 0;
bool methodReq = false;
bool mapMsg = false;
@@ -2140,7 +2111,7 @@ bool ManagementAgent::authorizeAgentMessageLH(Message& msg)
// authorized or not. In this case, return true (authorized) if there is no ACL in place,
// otherwise return false;
//
- if (msg.getContentSize() > MA_BUFFER_SIZE)
+ if (msg.getContentSize() > qmfV1BufferSize)
return broker->getAcl() == 0;
inBuffer.putRawData(msg.getContent());
@@ -2149,7 +2120,7 @@ bool ManagementAgent::authorizeAgentMessageLH(Message& msg)
qpid::broker::amqp_0_10::MessageTransfer& transfer(qpid::broker::amqp_0_10::MessageTransfer::get(msg));
const framing::MessageProperties* p =
- transfer.getFrames().getHeaders()->get<framing::MessageProperties>();
+ transfer.getFrames().getHeaders()->get<framing::MessageProperties>();
const framing::FieldTable *headers = p ? &p->getApplicationHeaders() : 0;
@@ -2193,11 +2164,11 @@ bool ManagementAgent::authorizeAgentMessageLH(Message& msg)
}
// look up schema for object to get package and class name
-
+ sys::Mutex::ScopedLock lock(objectLock);
ManagementObjectMap::iterator iter = managementObjects.find(objId);
if (iter == managementObjects.end() || iter->second->isDeleted()) {
- QPID_LOG(debug, "ManagementAgent::authorizeAgentMessageLH: stale object id " <<
+ QPID_LOG(debug, "ManagementAgent::authorizeAgentMessage: stale object id " <<
objId);
return false;
}
@@ -2256,19 +2227,16 @@ bool ManagementAgent::authorizeAgentMessageLH(Message& msg)
cid = p->getCorrelationId();
if (mapMsg) {
- sendExceptionLH(rte, rtk, cid, Manageable::StatusText(Manageable::STATUS_FORBIDDEN),
- Manageable::STATUS_FORBIDDEN, false);
+ sendException(rte, rtk, cid, Manageable::StatusText(Manageable::STATUS_FORBIDDEN),
+ Manageable::STATUS_FORBIDDEN, false);
} else {
- Buffer outBuffer(outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer(qmfV1BufferSize);
encodeHeader(outBuffer, 'm', sequence);
outBuffer.putLong(Manageable::STATUS_FORBIDDEN);
outBuffer.putMediumString(Manageable::StatusText(Manageable::STATUS_FORBIDDEN));
- outLen = MA_BUFFER_SIZE - outBuffer.available();
- outBuffer.reset();
- sendBufferLH(outBuffer, outLen, rte, rtk);
+ sendBuffer(outBuffer, rte, rtk);
}
QPID_LOG(debug, "SEND MethodResponse status=FORBIDDEN" << " seq=" << sequence);
@@ -2280,7 +2248,7 @@ bool ManagementAgent::authorizeAgentMessageLH(Message& msg)
return true;
}
-void ManagementAgent::dispatchAgentCommandLH(Message& msg, bool viaLocal)
+void ManagementAgent::dispatchAgentCommand(Message& msg, bool viaLocal)
{
string rte;
string rtk;
@@ -2295,10 +2263,10 @@ void ManagementAgent::dispatchAgentCommandLH(Message& msg, bool viaLocal)
else
return;
- Buffer inBuffer(inputBuffer, MA_BUFFER_SIZE);
+ ResizableBuffer inBuffer(qmfV1BufferSize);
uint8_t opcode;
- if (msg.getContentSize() > MA_BUFFER_SIZE) {
+ if (msg.getContentSize() > qmfV1BufferSize) {
QPID_LOG(debug, "ManagementAgent::dispatchAgentCommandLH: Message too large: " <<
msg.getContentSize());
return;
@@ -2317,39 +2285,38 @@ void ManagementAgent::dispatchAgentCommandLH(Message& msg, bool viaLocal)
string body;
string cid;
inBuffer.getRawData(body, bufferLen);
+ {
+ if (p && p->hasCorrelationId()) {
+ cid = p->getCorrelationId();
+ }
- if (p && p->hasCorrelationId()) {
- cid = p->getCorrelationId();
+ if (opcode == "_method_request")
+ return handleMethodRequest(body, rte, rtk, cid, msg.getPublisher(), viaLocal);
+ else if (opcode == "_query_request")
+ return handleGetQuery(body, rte, rtk, cid, viaLocal);
+ else if (opcode == "_agent_locate_request")
+ return handleLocateRequest(body, rte, rtk, cid);
}
-
- if (opcode == "_method_request")
- return handleMethodRequestLH(body, rte, rtk, cid, msg.getPublisher(), viaLocal);
- else if (opcode == "_query_request")
- return handleGetQueryLH(body, rte, rtk, cid, viaLocal);
- else if (opcode == "_agent_locate_request")
- return handleLocateRequestLH(body, rte, rtk, cid);
-
QPID_LOG(warning, "Support for QMF Opcode [" << opcode << "] TBD!!!");
return;
}
// old preV2 binary messages
-
while (inBuffer.getPosition() < bufferLen) {
uint32_t sequence;
if (!checkHeader(inBuffer, &opcode, &sequence))
return;
- if (opcode == 'B') handleBrokerRequestLH (inBuffer, rtk, sequence);
- else if (opcode == 'P') handlePackageQueryLH (inBuffer, rtk, sequence);
- else if (opcode == 'p') handlePackageIndLH (inBuffer, rtk, sequence);
- else if (opcode == 'Q') handleClassQueryLH (inBuffer, rtk, sequence);
- else if (opcode == 'q') handleClassIndLH (inBuffer, rtk, sequence);
- else if (opcode == 'S') handleSchemaRequestLH (inBuffer, rte, rtk, sequence);
- else if (opcode == 's') handleSchemaResponseLH (inBuffer, rtk, sequence);
- else if (opcode == 'A') handleAttachRequestLH (inBuffer, rtk, sequence, msg.getPublisher());
- else if (opcode == 'G') handleGetQueryLH (inBuffer, rtk, sequence);
- else if (opcode == 'M') handleMethodRequestLH (inBuffer, rtk, sequence, msg.getPublisher());
+ if (opcode == 'B') handleBrokerRequest (inBuffer, rtk, sequence);
+ else if (opcode == 'P') handlePackageQuery (inBuffer, rtk, sequence);
+ else if (opcode == 'p') handlePackageInd (inBuffer, rtk, sequence);
+ else if (opcode == 'Q') handleClassQuery (inBuffer, rtk, sequence);
+ else if (opcode == 'q') handleClassInd (inBuffer, rtk, sequence);
+ else if (opcode == 'S') handleSchemaRequest (inBuffer, rte, rtk, sequence);
+ else if (opcode == 's') handleSchemaResponse (inBuffer, rtk, sequence);
+ else if (opcode == 'A') handleAttachRequest (inBuffer, rtk, sequence, msg.getPublisher());
+ else if (opcode == 'G') handleGetQuery (inBuffer, rtk, sequence);
+ else if (opcode == 'M') handleMethodRequest (inBuffer, rtk, sequence, msg.getPublisher());
}
}
@@ -2365,14 +2332,11 @@ ManagementAgent::PackageMap::iterator ManagementAgent::findOrAddPackageLH(string
QPID_LOG (debug, "ManagementAgent added package " << name);
// Publish a package-indication message
- Buffer outBuffer (outputBuffer, MA_BUFFER_SIZE);
- uint32_t outLen;
+ ResizableBuffer outBuffer (qmfV1BufferSize);
encodeHeader (outBuffer, 'p');
encodePackageIndication (outBuffer, result.first);
- outLen = MA_BUFFER_SIZE - outBuffer.available ();
- outBuffer.reset ();
- sendBufferLH(outBuffer, outLen, mExchange, "schema.package");
+ sendBuffer(outBuffer, mExchange, "schema.package");
QPID_LOG(debug, "SEND PackageInd package=" << name << " to=schema.package");
return result.first;
@@ -2587,70 +2551,6 @@ void ManagementAgent::SchemaClass::mapDecode(const Variant::Map& _map) {
}
}
-void ManagementAgent::exportSchemas(string& out) {
- Variant::List list_;
- Variant::Map map_, kmap, cmap;
-
- for (PackageMap::const_iterator i = packages.begin(); i != packages.end(); ++i) {
- string name = i->first;
- const ClassMap& classes = i ->second;
- for (ClassMap::const_iterator j = classes.begin(); j != classes.end(); ++j) {
- const SchemaClassKey& key = j->first;
- const SchemaClass& klass = j->second;
- if (klass.writeSchemaCall == 0) { // Ignore built-in schemas.
- // Encode name, schema-key, schema-class
-
- map_.clear();
- kmap.clear();
- cmap.clear();
-
- key.mapEncode(kmap);
- klass.mapEncode(cmap);
-
- map_["_pname"] = name;
- map_["_key"] = kmap;
- map_["_class"] = cmap;
- list_.push_back(map_);
- }
- }
- }
-
- ListCodec::encode(list_, out);
-}
-
-void ManagementAgent::importSchemas(qpid::framing::Buffer& inBuf) {
-
- string buf(inBuf.getPointer(), inBuf.available());
- Variant::List content;
- ListCodec::decode(buf, content);
- Variant::List::const_iterator l;
-
-
- for (l = content.begin(); l != content.end(); l++) {
- string package;
- SchemaClassKey key;
- SchemaClass klass;
- Variant::Map map_, kmap, cmap;
- Variant::Map::const_iterator i;
-
- map_ = l->asMap();
-
- if ((i = map_.find("_pname")) != map_.end()) {
- package = i->second.asString();
-
- if ((i = map_.find("_key")) != map_.end()) {
- key.mapDecode(i->second.asMap());
-
- if ((i = map_.find("_class")) != map_.end()) {
- klass.mapDecode(i->second.asMap());
-
- packages[package][key] = klass;
- }
- }
- }
- }
-}
-
void ManagementAgent::RemoteAgent::mapEncode(Variant::Map& map_) const {
Variant::Map _objId, _values;
@@ -2684,7 +2584,7 @@ void ManagementAgent::RemoteAgent::mapDecode(const Variant::Map& map_) {
connectionRef.mapDecode(i->second.asMap());
}
- mgmtObject = new _qmf::Agent(&agent, this);
+ mgmtObject = _qmf::Agent::shared_ptr(new _qmf::Agent(&agent, this));
if ((i = map_.find("_values")) != map_.end()) {
mgmtObject->mapDecodeValues(i->second.asMap());
@@ -2694,52 +2594,6 @@ void ManagementAgent::RemoteAgent::mapDecode(const Variant::Map& map_) {
mgmtObject->set_connectionRef(connectionRef);
}
-void ManagementAgent::exportAgents(string& out) {
- Variant::List list_;
- Variant::Map map_, omap, amap;
-
- for (RemoteAgentMap::const_iterator i = remoteAgents.begin();
- i != remoteAgents.end();
- ++i)
- {
- // TODO aconway 2010-03-04: see comment in ManagementAgent::RemoteAgent::encode
- boost::shared_ptr<RemoteAgent> agent(i->second);
-
- map_.clear();
- amap.clear();
-
- agent->mapEncode(amap);
- map_["_remote_agent"] = amap;
- list_.push_back(map_);
- }
-
- ListCodec::encode(list_, out);
-}
-
-void ManagementAgent::importAgents(qpid::framing::Buffer& inBuf) {
- string buf(inBuf.getPointer(), inBuf.available());
- Variant::List content;
- ListCodec::decode(buf, content);
- Variant::List::const_iterator l;
- sys::Mutex::ScopedLock lock(userLock);
-
- for (l = content.begin(); l != content.end(); l++) {
- boost::shared_ptr<RemoteAgent> agent(new RemoteAgent(*this));
- Variant::Map map_;
- Variant::Map::const_iterator i;
-
- map_ = l->asMap();
-
- if ((i = map_.find("_remote_agent")) != map_.end()) {
-
- agent->mapDecode(i->second.asMap());
-
- addObject (agent->mgmtObject, 0, false);
- remoteAgents[agent->connectionRef] = agent;
- }
- }
-}
-
namespace {
bool isDeletedMap(const ManagementObjectMap::value_type& value) {
return value.second->isDeleted();
@@ -2818,56 +2672,8 @@ Variant::Map ManagementAgent::toMap(const FieldTable& from)
return map;
}
-
-// Build up a list of the current set of deleted objects that are pending their
-// next (last) publish-ment.
-void ManagementAgent::exportDeletedObjects(DeletedObjectList& outList)
-{
- outList.clear();
-
- sys::Mutex::ScopedLock lock (userLock);
-
- moveNewObjectsLH();
- moveDeletedObjectsLH();
-
- // now copy the pending deletes into the outList
- for (PendingDeletedObjsMap::iterator mIter = pendingDeletedObjs.begin();
- mIter != pendingDeletedObjs.end(); mIter++) {
- for (DeletedObjectList::iterator lIter = mIter->second.begin();
- lIter != mIter->second.end(); lIter++) {
- outList.push_back(*lIter);
- }
- }
-}
-
-// Called by cluster to reset the management agent's list of deleted
-// objects to match the rest of the cluster.
-void ManagementAgent::importDeletedObjects(const DeletedObjectList& inList)
-{
- sys::Mutex::ScopedLock lock (userLock);
- // Clear out any existing deleted objects
- moveNewObjectsLH();
- pendingDeletedObjs.clear();
- ManagementObjectMap::iterator i = managementObjects.begin();
- // Silently drop any deleted objects left over from receiving the update.
- while (i != managementObjects.end()) {
- ManagementObject* object = i->second;
- if (object->isDeleted()) {
- delete object;
- managementObjects.erase(i++);
- }
- else ++i;
- }
- for (DeletedObjectList::const_iterator lIter = inList.begin(); lIter != inList.end(); lIter++) {
-
- std::string classkey((*lIter)->packageName + std::string(":") + (*lIter)->className);
- pendingDeletedObjs[classkey].push_back(*lIter);
- }
-}
-
-
// construct a DeletedObject from a management object.
-ManagementAgent::DeletedObject::DeletedObject(ManagementObject *src, bool v1, bool v2)
+ManagementAgent::DeletedObject::DeletedObject(ManagementObject::shared_ptr src, bool v1, bool v2)
: packageName(src->getPackageName()),
className(src->getClassName())
{
@@ -2903,54 +2709,18 @@ ManagementAgent::DeletedObject::DeletedObject(ManagementObject *src, bool v1, bo
}
}
+// Remove Deleted objects, and save for later publishing...
+bool ManagementAgent::moveDeletedObjects() {
+ typedef vector<pair<ObjectId, ManagementObject::shared_ptr> > DeleteList;
+ sys::Mutex::ScopedLock lock (objectLock);
-// construct a DeletedObject from an encoded representation. Used by
-// clustering to move deleted objects between clustered brokers. See
-// DeletedObject::encode() for the reverse.
-ManagementAgent::DeletedObject::DeletedObject(const std::string& encoded)
-{
- qpid::types::Variant::Map map_;
- MapCodec::decode(encoded, map_);
-
- packageName = map_["_package_name"].getString();
- className = map_["_class_name"].getString();
- objectId = map_["_object_id"].getString();
-
- encodedV1Config = map_["_v1_config"].getString();
- encodedV1Inst = map_["_v1_inst"].getString();
- encodedV2 = map_["_v2_data"].asMap();
-}
-
-
-// encode a DeletedObject to a string buffer. Used by
-// clustering to move deleted objects between clustered brokers. See
-// DeletedObject(const std::string&) for the reverse.
-void ManagementAgent::DeletedObject::encode(std::string& toBuffer)
-{
- qpid::types::Variant::Map map_;
-
-
- map_["_package_name"] = packageName;
- map_["_class_name"] = className;
- map_["_object_id"] = objectId;
-
- map_["_v1_config"] = encodedV1Config;
- map_["_v1_inst"] = encodedV1Inst;
- map_["_v2_data"] = encodedV2;
-
- MapCodec::encode(map_, toBuffer);
-}
-
-// Remove Deleted objects, and save for later publishing...
-bool ManagementAgent::moveDeletedObjectsLH() {
- typedef vector<pair<ObjectId, ManagementObject*> > DeleteList;
DeleteList deleteList;
for (ManagementObjectMap::iterator iter = managementObjects.begin();
iter != managementObjects.end();
++iter)
{
- ManagementObject* object = iter->second;
+ ManagementObject::shared_ptr object = iter->second;
if (object->isDeleted()) deleteList.push_back(*iter);
}
@@ -2959,17 +2729,31 @@ bool ManagementAgent::moveDeletedObjectsLH() {
iter != deleteList.rend();
iter++)
{
- ManagementObject* delObj = iter->second;
+ ManagementObject::shared_ptr delObj = iter->second;
assert(delObj->isDeleted());
DeletedObject::shared_ptr dptr(new DeletedObject(delObj, qmf1Support, qmf2Support));
pendingDeletedObjs[dptr->getKey()].push_back(dptr);
managementObjects.erase(iter->first);
- delete iter->second;
}
return !deleteList.empty();
}
+ManagementAgent::EventQueue::Batch::const_iterator ManagementAgent::sendEvents(
+ const EventQueue::Batch& batch)
+{
+ EventQueue::Batch::const_iterator i;
+ for (i = batch.begin(); i != batch.end(); ++i) {
+ DeliverableMessage deliverable (i->second, 0);
+ try {
+ i->first->route(deliverable);
+ } catch(exception& e) {
+ QPID_LOG(warning, "ManagementAgent failed to route event: " << e.what());
+ }
+ }
+ return i;
+}
+
namespace {
QPID_TSS const qpid::broker::ConnectionState* executionContext = 0;
}
diff --git a/cpp/src/qpid/management/ManagementAgent.h b/cpp/src/qpid/management/ManagementAgent.h
index c7e830dcf5..6de5d1d719 100644
--- a/cpp/src/qpid/management/ManagementAgent.h
+++ b/cpp/src/qpid/management/ManagementAgent.h
@@ -26,7 +26,6 @@
#include "qpid/broker/Exchange.h"
#include "qpid/framing/Uuid.h"
#include "qpid/sys/Mutex.h"
-#include "qpid/sys/Timer.h"
#include "qpid/broker/ConnectionToken.h"
#include "qpid/management/ManagementObject.h"
#include "qpid/management/ManagementEvent.h"
@@ -34,9 +33,11 @@
#include "qmf/org/apache/qpid/broker/Agent.h"
#include "qmf/org/apache/qpid/broker/Memory.h"
#include "qpid/sys/MemStat.h"
+#include "qpid/sys/PollableQueue.h"
#include "qpid/types/Variant.h"
#include <qpid/framing/AMQFrame.h>
#include <qpid/framing/ResizableBuffer.h>
+#include <boost/shared_ptr.hpp>
#include <memory>
#include <string>
#include <map>
@@ -45,6 +46,9 @@ namespace qpid {
namespace broker {
class ConnectionState;
}
+namespace sys {
+class Timer;
+}
namespace management {
class ManagementAgent
@@ -73,11 +77,6 @@ public:
/** Called before plugins are initialized */
void configure (const std::string& dataDir, bool publish, uint16_t interval,
qpid::broker::Broker* broker, int threadPoolSize);
- /** Called after plugins are initialized. */
- void pluginsInitialized();
-
- /** Called by cluster to suppress management output during update. */
- void suppress(bool s) { suppressed = s; }
void setName(const std::string& vendor,
const std::string& product,
@@ -100,18 +99,16 @@ public:
const std::string& eventName,
uint8_t* md5Sum,
ManagementObject::writeSchemaCall_t schemaCall);
- QPID_BROKER_EXTERN ObjectId addObject (ManagementObject* object,
- uint64_t persistId = 0,
- bool persistent = false);
- QPID_BROKER_EXTERN ObjectId addObject (ManagementObject* object,
- const std::string& key,
- bool persistent = false);
+ QPID_BROKER_EXTERN ObjectId addObject (ManagementObject::shared_ptr object,
+ uint64_t persistId = 0,
+ bool persistent = false);
+ QPID_BROKER_EXTERN ObjectId addObject (ManagementObject::shared_ptr object,
+ const std::string& key,
+ bool persistent = false);
QPID_BROKER_EXTERN void raiseEvent(const ManagementEvent& event,
severity_t severity = SEV_DEFAULT);
QPID_BROKER_EXTERN void clientAdded (const std::string& routingKey);
- QPID_BROKER_EXTERN void clusterUpdate();
-
bool dispatchCommand (qpid::broker::Deliverable& msg,
const std::string& routingKey,
const framing::FieldTable* args,
@@ -121,25 +118,6 @@ public:
/** Disallow a method. Attempts to call it will receive an exception with message. */
void disallow(const std::string& className, const std::string& methodName, const std::string& message);
- /** Disallow all QMFv1 methods (used in clustered brokers). */
- void disallowV1Methods() { disallowAllV1Methods = true; }
-
- /** Serialize my schemas as a binary blob into schemaOut */
- void exportSchemas(std::string& schemaOut);
-
- /** Serialize my remote-agent map as a binary blob into agentsOut */
- void exportAgents(std::string& agentsOut);
-
- /** Decode a serialized schemas and add to my schema cache */
- void importSchemas(framing::Buffer& inBuf);
-
- /** Decode a serialized agent map */
- void importAgents(framing::Buffer& inBuf);
-
- // these are in support of the managementSetup-state stuff, for synch'ing clustered brokers
- uint64_t getNextObjectId(void) { return nextObjectId; }
- void setNextObjectId(uint64_t o) { nextObjectId = o; }
-
uint16_t getBootSequence(void) { return bootSequence; }
void setBootSequence(uint16_t b) { bootSequence = b; writeData(); }
@@ -148,20 +126,11 @@ public:
static types::Variant::Map toMap(const framing::FieldTable& from);
- // For Clustering: management objects that have been marked as
- // "deleted", but are waiting for their last published object
- // update are not visible to the cluster replication code. These
- // interfaces allow clustering to gather up all the management
- // objects that are deleted in order to allow all clustered
- // brokers to publish the same set of deleted objects.
-
class DeletedObject {
public:
typedef boost::shared_ptr<DeletedObject> shared_ptr;
- DeletedObject(ManagementObject *, bool v1, bool v2);
- DeletedObject( const std::string &encoded );
+ DeletedObject(ManagementObject::shared_ptr, bool v1, bool v2);
~DeletedObject() {};
- void encode( std::string& toBuffer );
const std::string getKey() const {
// used to batch up objects of the same class type
return std::string(packageName + std::string(":") + className);
@@ -181,22 +150,7 @@ public:
typedef std::vector<DeletedObject::shared_ptr> DeletedObjectList;
- /** returns a snapshot of all currently deleted management objects. */
- void exportDeletedObjects( DeletedObjectList& outList );
-
- /** Import a list of deleted objects to send on next publish interval. */
- void importDeletedObjects( const DeletedObjectList& inList );
-
private:
- struct Periodic : public qpid::sys::TimerTask
- {
- ManagementAgent& agent;
-
- Periodic (ManagementAgent& agent, uint32_t seconds);
- virtual ~Periodic ();
- void fire ();
- };
-
// Storage for tracking remote management agents, attached via the client
// management agent API.
//
@@ -207,9 +161,9 @@ private:
uint32_t agentBank;
std::string routingKey;
ObjectId connectionRef;
- qmf::org::apache::qpid::broker::Agent* mgmtObject;
- RemoteAgent(ManagementAgent& _agent) : agent(_agent), mgmtObject(0) {}
- ManagementObject* GetManagementObject (void) const { return mgmtObject; }
+ qmf::org::apache::qpid::broker::Agent::shared_ptr mgmtObject;
+ RemoteAgent(ManagementAgent& _agent) : agent(_agent) {}
+ ManagementObject::shared_ptr GetManagementObject (void) const { return mgmtObject; }
virtual ~RemoteAgent ();
void mapEncode(qpid::types::Variant::Map& _map) const;
@@ -276,7 +230,7 @@ private:
PackageMap packages;
//
- // Protected by userLock
+ // Protected by objectLock
//
ManagementObjectMap managementObjects;
@@ -288,11 +242,11 @@ private:
framing::Uuid uuid;
//
- // Lock hierarchy: If a thread needs to take both addLock and userLock,
- // it MUST take userLock first, then addLock.
+ // Lock ordering: userLock -> addLock -> objectLock
//
sys::Mutex userLock;
sys::Mutex addLock;
+ sys::Mutex objectLock;
qpid::broker::Exchange::shared_ptr mExchange;
qpid::broker::Exchange::shared_ptr dExchange;
@@ -335,53 +289,51 @@ private:
// list of objects that have been deleted, but have yet to be published
// one final time.
// Indexed by a string composed of the object's package and class name.
- // Protected by userLock.
+ // Protected by objectLock.
typedef std::map<std::string, DeletedObjectList> PendingDeletedObjsMap;
PendingDeletedObjsMap pendingDeletedObjs;
-# define MA_BUFFER_SIZE 65536
- char inputBuffer[MA_BUFFER_SIZE];
- char outputBuffer[MA_BUFFER_SIZE];
- char eventBuffer[MA_BUFFER_SIZE];
- framing::ResizableBuffer msgBuffer;
+ // Pollable queue to serialize event messages
+ typedef std::pair<boost::shared_ptr<broker::Exchange>,
+ broker::Message> ExchangeAndMessage;
+ typedef sys::PollableQueue<ExchangeAndMessage> EventQueue;
//
// Memory statistics object
//
- qmf::org::apache::qpid::broker::Memory *memstat;
+ qmf::org::apache::qpid::broker::Memory::shared_ptr memstat;
void writeData ();
void periodicProcessing (void);
- void deleteObjectNowLH(const ObjectId& oid);
+ void deleteObjectNow(const ObjectId& oid);
void encodeHeader (framing::Buffer& buf, uint8_t opcode, uint32_t seq = 0);
bool checkHeader (framing::Buffer& buf, uint8_t *opcode, uint32_t *seq);
- void sendBufferLH(framing::Buffer& buf,
- uint32_t length,
- qpid::broker::Exchange::shared_ptr exchange,
- const std::string& routingKey);
- void sendBufferLH(framing::Buffer& buf,
- uint32_t length,
- const std::string& exchange,
- const std::string& routingKey);
- void sendBufferLH(const std::string& data,
- const std::string& cid,
- const qpid::types::Variant::Map& headers,
- const std::string& content_type,
- qpid::broker::Exchange::shared_ptr exchange,
- const std::string& routingKey,
- uint64_t ttl_msec = 0);
- void sendBufferLH(const std::string& data,
- const std::string& cid,
- const qpid::types::Variant::Map& headers,
- const std::string& content_type,
- const std::string& exchange,
- const std::string& routingKey,
- uint64_t ttl_msec = 0);
- void moveNewObjectsLH();
- bool moveDeletedObjectsLH();
-
- bool authorizeAgentMessageLH(qpid::broker::Message& msg);
- void dispatchAgentCommandLH(qpid::broker::Message& msg, bool viaLocal=false);
+ EventQueue::Batch::const_iterator sendEvents(const EventQueue::Batch& batch);
+ void sendBuffer(framing::Buffer& buf,
+ qpid::broker::Exchange::shared_ptr exchange,
+ const std::string& routingKey);
+ void sendBuffer(framing::Buffer& buf,
+ const std::string& exchange,
+ const std::string& routingKey);
+ void sendBuffer(const std::string& data,
+ const std::string& cid,
+ const qpid::types::Variant::Map& headers,
+ const std::string& content_type,
+ qpid::broker::Exchange::shared_ptr exchange,
+ const std::string& routingKey,
+ uint64_t ttl_msec = 0);
+ void sendBuffer(const std::string& data,
+ const std::string& cid,
+ const qpid::types::Variant::Map& headers,
+ const std::string& content_type,
+ const std::string& exchange,
+ const std::string& routingKey,
+ uint64_t ttl_msec = 0);
+ void moveNewObjects();
+ bool moveDeletedObjects();
+
+ bool authorizeAgentMessage(qpid::broker::Message& msg);
+ void dispatchAgentCommand(qpid::broker::Message& msg, bool viaLocal=false);
PackageMap::iterator findOrAddPackageLH(std::string name);
void addClassLH(uint8_t kind,
@@ -399,22 +351,22 @@ private:
uint32_t allocateNewBank ();
uint32_t assignBankLH (uint32_t requestedPrefix);
void deleteOrphanedAgentsLH();
- void sendCommandCompleteLH(const std::string& replyToKey, uint32_t sequence,
- uint32_t code = 0, const std::string& text = "OK");
- void sendExceptionLH(const std::string& rte, const std::string& rtk, const std::string& cid, const std::string& text, uint32_t code=1, bool viaLocal=false);
- void handleBrokerRequestLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
- void handlePackageQueryLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
- void handlePackageIndLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
- void handleClassQueryLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
- void handleClassIndLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
- void handleSchemaRequestLH (framing::Buffer& inBuffer, const std::string& replyToEx, const std::string& replyToKey, uint32_t sequence);
- void handleSchemaResponseLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
- void handleAttachRequestLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence, const qpid::broker::ConnectionToken* connToken);
- void handleGetQueryLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
- void handleMethodRequestLH (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence, const qpid::broker::ConnectionToken* connToken);
- void handleGetQueryLH (const std::string& body, const std::string& replyToEx, const std::string& replyToKey, const std::string& cid, bool viaLocal);
- void handleMethodRequestLH (const std::string& body, const std::string& replyToEx, const std::string& replyToKey, const std::string& cid, const qpid::broker::ConnectionToken* connToken, bool viaLocal);
- void handleLocateRequestLH (const std::string& body, const std::string& replyToEx, const std::string &replyToKey, const std::string& cid);
+ void sendCommandComplete(const std::string& replyToKey, uint32_t sequence,
+ uint32_t code = 0, const std::string& text = "OK");
+ void sendException(const std::string& rte, const std::string& rtk, const std::string& cid, const std::string& text, uint32_t code=1, bool viaLocal=false);
+ void handleBrokerRequest (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
+ void handlePackageQuery (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
+ void handlePackageInd (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
+ void handleClassQuery (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
+ void handleClassInd (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
+ void handleSchemaRequest (framing::Buffer& inBuffer, const std::string& replyToEx, const std::string& replyToKey, uint32_t sequence);
+ void handleSchemaResponse (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
+ void handleAttachRequest (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence, const qpid::broker::ConnectionToken* connToken);
+ void handleGetQuery (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence);
+ void handleMethodRequest (framing::Buffer& inBuffer, const std::string& replyToKey, uint32_t sequence, const qpid::broker::ConnectionToken* connToken);
+ void handleGetQuery (const std::string& body, const std::string& replyToEx, const std::string& replyToKey, const std::string& cid, bool viaLocal);
+ void handleMethodRequest (const std::string& body, const std::string& replyToEx, const std::string& replyToKey, const std::string& cid, const qpid::broker::ConnectionToken* connToken, bool viaLocal);
+ void handleLocateRequest (const std::string& body, const std::string& replyToEx, const std::string &replyToKey, const std::string& cid);
size_t validateSchema(framing::Buffer&, uint8_t kind);
@@ -424,6 +376,7 @@ private:
std::string summarizeAgents();
void debugSnapshot(const char* title);
+ std::auto_ptr<EventQueue> sendQueue;
};
void setManagementExecutionContext(const qpid::broker::ConnectionState*);
diff --git a/cpp/src/qpid/messaging/Connection.cpp b/cpp/src/qpid/messaging/Connection.cpp
index bd90aa54a7..fde931038b 100644
--- a/cpp/src/qpid/messaging/Connection.cpp
+++ b/cpp/src/qpid/messaging/Connection.cpp
@@ -7,9 +7,9 @@
* 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
@@ -24,6 +24,7 @@
#include "qpid/messaging/Session.h"
#include "qpid/messaging/SessionImpl.h"
#include "qpid/messaging/PrivateImplRef.h"
+#include "qpid/messaging/ProtocolRegistry.h"
#include "qpid/client/amqp0_10/ConnectionImpl.h"
#include "qpid/log/Statement.h"
@@ -40,22 +41,32 @@ Connection& Connection::operator=(const Connection& c) { return PI::assign(*this
Connection::~Connection() { PI::dtor(*this); }
Connection::Connection(const std::string& url, const std::string& o)
-{
+{
Variant::Map options;
AddressParser parser(o);
if (o.empty() || parser.parseMap(options)) {
- PI::ctor(*this, new qpid::client::amqp0_10::ConnectionImpl(url, options));
+ ConnectionImpl* impl = ProtocolRegistry::create(url, options);
+ if (impl) {
+ PI::ctor(*this, impl);
+ } else {
+ PI::ctor(*this, new qpid::client::amqp0_10::ConnectionImpl(url, options));
+ }
} else {
throw InvalidOptionString("Invalid option string: " + o);
}
}
Connection::Connection(const std::string& url, const Variant::Map& options)
{
- PI::ctor(*this, new qpid::client::amqp0_10::ConnectionImpl(url, options));
+ ConnectionImpl* impl = ProtocolRegistry::create(url, options);
+ if (impl) {
+ PI::ctor(*this, impl);
+ } else {
+ PI::ctor(*this, new qpid::client::amqp0_10::ConnectionImpl(url, options));
+ }
}
Connection::Connection()
-{
+{
Variant::Map options;
std::string url = "amqp:tcp:127.0.0.1:5672";
PI::ctor(*this, new qpid::client::amqp0_10::ConnectionImpl(url, options));
@@ -67,12 +78,12 @@ bool Connection::isOpen() const { return impl->isOpen(); }
void Connection::close() { impl->close(); }
Session Connection::createSession(const std::string& name) { return impl->newSession(false, name); }
Session Connection::createTransactionalSession(const std::string& name)
-{
+{
return impl->newSession(true, name);
}
Session Connection::getSession(const std::string& name) const { return impl->getSession(name); }
void Connection::setOption(const std::string& name, const Variant& value)
-{
+{
impl->setOption(name, value);
}
std::string Connection::getAuthenticatedUsername()
diff --git a/cpp/src/qpid/messaging/ConnectionOptions.cpp b/cpp/src/qpid/messaging/ConnectionOptions.cpp
new file mode 100644
index 0000000000..ecd5ba9693
--- /dev/null
+++ b/cpp/src/qpid/messaging/ConnectionOptions.cpp
@@ -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.
+ *
+ */
+#include "qpid/messaging/ConnectionOptions.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/types/Variant.h"
+#include "qpid/log/Statement.h"
+#include <algorithm>
+#include <limits>
+
+namespace qpid {
+namespace messaging {
+
+namespace {
+double FOREVER(std::numeric_limits<double>::max());
+
+double timeValue(const qpid::types::Variant& value) {
+ if (types::isIntegerType(value.getType()))
+ return double(value.asInt64());
+ return value.asDouble();
+}
+
+void merge(const std::string& value, std::vector<std::string>& list) {
+ if (std::find(list.begin(), list.end(), value) == list.end())
+ list.push_back(value);
+}
+
+void merge(const qpid::types::Variant::List& from, std::vector<std::string>& to)
+{
+ for (qpid::types::Variant::List::const_iterator i = from.begin(); i != from.end(); ++i)
+ merge(i->asString(), to);
+}
+
+}
+
+ConnectionOptions::ConnectionOptions(const std::map<std::string, qpid::types::Variant>& options)
+ : replaceUrls(false), reconnect(false), timeout(FOREVER), limit(-1), minReconnectInterval(0.001), maxReconnectInterval(2),
+ retries(0), reconnectOnLimitExceeded(true)
+{
+ for (qpid::types::Variant::Map::const_iterator i = options.begin(); i != options.end(); ++i) {
+ set(i->first, i->second);
+ }
+}
+
+void ConnectionOptions::set(const std::string& name, const qpid::types::Variant& value)
+{
+ if (name == "reconnect") {
+ reconnect = value;
+ } else if (name == "reconnect-timeout" || name == "reconnect_timeout") {
+ timeout = timeValue(value);
+ } else if (name == "reconnect-limit" || name == "reconnect_limit") {
+ limit = value;
+ } else if (name == "reconnect-interval" || name == "reconnect_interval") {
+ maxReconnectInterval = minReconnectInterval = timeValue(value);
+ } else if (name == "reconnect-interval-min" || name == "reconnect_interval_min") {
+ minReconnectInterval = timeValue(value);
+ } else if (name == "reconnect-interval-max" || name == "reconnect_interval_max") {
+ maxReconnectInterval = timeValue(value);
+ } else if (name == "reconnect-urls-replace" || name == "reconnect_urls_replace") {
+ replaceUrls = value.asBool();
+ } else if (name == "reconnect-urls" || name == "reconnect_urls") {
+ if (replaceUrls) urls.clear();
+ if (value.getType() == qpid::types::VAR_LIST) {
+ merge(value.asList(), urls);
+ } else {
+ merge(value.asString(), urls);
+ }
+ } else if (name == "username") {
+ username = value.asString();
+ } else if (name == "password") {
+ password = value.asString();
+ } else if (name == "sasl-mechanism" || name == "sasl_mechanism" ||
+ name == "sasl-mechanisms" || name == "sasl_mechanisms") {
+ mechanism = value.asString();
+ } else if (name == "sasl-service" || name == "sasl_service") {
+ service = value.asString();
+ } else if (name == "sasl-min-ssf" || name == "sasl_min_ssf") {
+ minSsf = value;
+ } else if (name == "sasl-max-ssf" || name == "sasl_max_ssf") {
+ maxSsf = value;
+ } else if (name == "heartbeat") {
+ heartbeat = value;
+ } else if (name == "tcp-nodelay" || name == "tcp_nodelay") {
+ tcpNoDelay = value;
+ } else if (name == "locale") {
+ locale = value.asString();
+ } else if (name == "max-channels" || name == "max_channels") {
+ maxChannels = value;
+ } else if (name == "max-frame-size" || name == "max_frame_size") {
+ maxFrameSize = value;
+ } else if (name == "bounds") {
+ bounds = value;
+ } else if (name == "transport") {
+ protocol = value.asString();
+ } else if (name == "ssl-cert-name" || name == "ssl_cert_name") {
+ sslCertName = value.asString();
+ } else if (name == "x-reconnect-on-limit-exceeded" || name == "x_reconnect_on_limit_exceeded") {
+ reconnectOnLimitExceeded = value;
+ } else {
+ throw qpid::messaging::MessagingException(QPID_MSG("Invalid option: " << name << " not recognised"));
+ }
+}
+
+}} // namespace qpid::messaging
diff --git a/cpp/src/qpid/messaging/ConnectionOptions.h b/cpp/src/qpid/messaging/ConnectionOptions.h
new file mode 100644
index 0000000000..6786fd4a64
--- /dev/null
+++ b/cpp/src/qpid/messaging/ConnectionOptions.h
@@ -0,0 +1,51 @@
+#ifndef QPID_MESSAGING_CONNECTIONOPTIONS_H
+#define QPID_MESSAGING_CONNECTIONOPTIONS_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/client/ConnectionSettings.h"
+#include <map>
+#include <vector>
+
+namespace qpid {
+namespace types {
+class Variant;
+}
+namespace messaging {
+
+struct ConnectionOptions : qpid::client::ConnectionSettings
+{
+ std::vector<std::string> urls;
+ bool replaceUrls;
+ bool reconnect;
+ double timeout;
+ int32_t limit;
+ double minReconnectInterval;
+ double maxReconnectInterval;
+ int32_t retries;
+ bool reconnectOnLimitExceeded;
+
+ ConnectionOptions(const std::map<std::string, qpid::types::Variant>&);
+ void set(const std::string& name, const qpid::types::Variant& value);
+};
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_CONNECTIONOPTIONS_H*/
diff --git a/cpp/src/qpid/messaging/Message.cpp b/cpp/src/qpid/messaging/Message.cpp
index ef70c103e9..0f03bc8ca3 100644
--- a/cpp/src/qpid/messaging/Message.cpp
+++ b/cpp/src/qpid/messaging/Message.cpp
@@ -46,26 +46,26 @@ const std::string& Message::getSubject() const { return impl->getSubject(); }
void Message::setContentType(const std::string& s) { impl->setContentType(s); }
const std::string& Message::getContentType() const { return impl->getContentType(); }
-void Message::setMessageId(const std::string& id) { impl->messageId = id; }
-const std::string& Message::getMessageId() const { return impl->messageId; }
+void Message::setMessageId(const std::string& id) { impl->setMessageId(id); }
+const std::string& Message::getMessageId() const { return impl->getMessageId(); }
-void Message::setUserId(const std::string& id) { impl->userId = id; }
-const std::string& Message::getUserId() const { return impl->userId; }
+void Message::setUserId(const std::string& id) { impl->setUserId(id); }
+const std::string& Message::getUserId() const { return impl->getUserId(); }
-void Message::setCorrelationId(const std::string& id) { impl->correlationId = id; }
-const std::string& Message::getCorrelationId() const { return impl->correlationId; }
+void Message::setCorrelationId(const std::string& id) { impl->setCorrelationId(id); }
+const std::string& Message::getCorrelationId() const { return impl->getCorrelationId(); }
-uint8_t Message::getPriority() const { return impl->priority; }
-void Message::setPriority(uint8_t priority) { impl->priority = priority; }
+uint8_t Message::getPriority() const { return impl->getPriority(); }
+void Message::setPriority(uint8_t priority) { impl->setPriority(priority); }
-void Message::setTtl(Duration ttl) { impl->ttl = ttl.getMilliseconds(); }
-Duration Message::getTtl() const { return Duration(impl->ttl); }
+void Message::setTtl(Duration ttl) { impl->setTtl(ttl.getMilliseconds()); }
+Duration Message::getTtl() const { return Duration(impl->getTtl()); }
-void Message::setDurable(bool durable) { impl->durable = durable; }
-bool Message::getDurable() const { return impl->durable; }
+void Message::setDurable(bool durable) { impl->setDurable(durable); }
+bool Message::getDurable() const { return impl->isDurable(); }
-bool Message::getRedelivered() const { return impl->redelivered; }
-void Message::setRedelivered(bool redelivered) { impl->redelivered = redelivered; }
+bool Message::getRedelivered() const { return impl->isRedelivered(); }
+void Message::setRedelivered(bool redelivered) { impl->setRedelivered(redelivered); }
const Variant::Map& Message::getProperties() const { return impl->getHeaders(); }
Variant::Map& Message::getProperties() { return impl->getHeaders(); }
diff --git a/cpp/src/qpid/messaging/MessageImpl.cpp b/cpp/src/qpid/messaging/MessageImpl.cpp
index 0601800e46..fc9bc5dfa1 100644
--- a/cpp/src/qpid/messaging/MessageImpl.cpp
+++ b/cpp/src/qpid/messaging/MessageImpl.cpp
@@ -45,28 +45,163 @@ MessageImpl::MessageImpl(const char* chars, size_t count) :
bytes(chars, count),
internalId(0) {}
-void MessageImpl::setReplyTo(const Address& d) { replyTo = d; }
-const Address& MessageImpl::getReplyTo() const { return replyTo; }
+void MessageImpl::setReplyTo(const Address& d)
+{
+ replyTo = d;
+ updated();
+}
+const Address& MessageImpl::getReplyTo() const
+{
+ if (!replyTo && encoded) encoded->getReplyTo(replyTo);
+ return replyTo;
+}
-void MessageImpl::setSubject(const std::string& s) { subject = s; }
-const std::string& MessageImpl::getSubject() const { return subject; }
+void MessageImpl::setSubject(const std::string& s)
+{
+ subject = s;
+ updated();
+}
+const std::string& MessageImpl::getSubject() const
+{
+ if (!subject.size() && encoded) encoded->getSubject(subject);
+ return subject;
+}
-void MessageImpl::setContentType(const std::string& s) { contentType = s; }
-const std::string& MessageImpl::getContentType() const { return contentType; }
+void MessageImpl::setContentType(const std::string& s)
+{
+ contentType = s;
+ updated();
+}
+const std::string& MessageImpl::getContentType() const
+{
+ if (!contentType.size() && encoded) encoded->getContentType(contentType);
+ return contentType;
+}
-const Variant::Map& MessageImpl::getHeaders() const { return headers; }
-Variant::Map& MessageImpl::getHeaders() { return headers; }
-void MessageImpl::setHeader(const std::string& key, const qpid::types::Variant& val) { headers[key] = val; }
+void MessageImpl::setMessageId(const std::string& s)
+{
+ messageId = s;
+ updated();
+}
+const std::string& MessageImpl::getMessageId() const
+{
+ if (!messageId.size() && encoded) encoded->getMessageId(messageId);
+ return messageId;
+}
+void MessageImpl::setUserId(const std::string& s)
+{
+ userId = s;
+ updated();
+}
+const std::string& MessageImpl::getUserId() const
+{
+ if (!userId.size() && encoded) encoded->getUserId(userId);
+ return userId;
+}
+void MessageImpl::setCorrelationId(const std::string& s)
+{
+ correlationId = s;
+ updated();
+}
+const std::string& MessageImpl::getCorrelationId() const
+{
+ if (!correlationId.size() && encoded) encoded->getCorrelationId(correlationId);
+ return correlationId;
+}
+void MessageImpl::setPriority(uint8_t p)
+{
+ priority = p;
+}
+uint8_t MessageImpl::getPriority() const
+{
+ return priority;
+}
+void MessageImpl::setTtl(uint64_t t)
+{
+ ttl = t;
+}
+uint64_t MessageImpl::getTtl() const
+{
+ return ttl;
+}
+void MessageImpl::setDurable(bool d)
+{
+ durable = d;
+}
+bool MessageImpl::isDurable() const
+{
+ return durable;
+}
+void MessageImpl::setRedelivered(bool b)
+{
+ redelivered = b;
+}
+bool MessageImpl::isRedelivered() const
+{
+ return redelivered;
+}
+
+const Variant::Map& MessageImpl::getHeaders() const
+{
+ if (!headers.size() && encoded) encoded->populate(headers);
+ return headers;
+}
+Variant::Map& MessageImpl::getHeaders() {
+ if (!headers.size() && encoded) encoded->populate(headers);
+ updated();
+ return headers;
+}
+void MessageImpl::setHeader(const std::string& key, const qpid::types::Variant& val)
+{
+ headers[key] = val; updated();
+}
//should these methods be on MessageContent?
-void MessageImpl::setBytes(const std::string& c) { bytes = c; }
-void MessageImpl::setBytes(const char* chars, size_t count) { bytes.assign(chars, count); }
-const std::string& MessageImpl::getBytes() const { return bytes; }
-std::string& MessageImpl::getBytes() { return bytes; }
+void MessageImpl::setBytes(const std::string& c)
+{
+ bytes = c;
+ updated();
+}
+void MessageImpl::setBytes(const char* chars, size_t count)
+{
+ bytes.assign(chars, count);
+ updated();
+}
+void MessageImpl::appendBytes(const char* chars, size_t count)
+{
+ bytes.append(chars, count);
+ updated();
+}
+const std::string& MessageImpl::getBytes() const
+{
+ if (!bytes.size() && encoded) encoded->getBody(bytes);
+ return bytes;
+}
+std::string& MessageImpl::getBytes()
+{
+ if (!bytes.size() && encoded) encoded->getBody(bytes);
+ updated();//have to assume body may be edited, invalidating our message
+ return bytes;
+}
void MessageImpl::setInternalId(qpid::framing::SequenceNumber i) { internalId = i; }
qpid::framing::SequenceNumber MessageImpl::getInternalId() { return internalId; }
+void MessageImpl::updated()
+{
+
+ if (!replyTo && encoded) encoded->getReplyTo(replyTo);
+ if (!subject.size() && encoded) encoded->getSubject(subject);
+ if (!contentType.size() && encoded) encoded->getContentType(contentType);
+ if (!messageId.size() && encoded) encoded->getMessageId(messageId);
+ if (!userId.size() && encoded) encoded->getUserId(userId);
+ if (!correlationId.size() && encoded) encoded->getCorrelationId(correlationId);
+ if (!headers.size() && encoded) encoded->populate(headers);
+ if (!bytes.size() && encoded) encoded->getBody(bytes);
+
+ encoded.reset();
+}
+
MessageImpl& MessageImplAccess::get(Message& msg)
{
return *msg.impl;
diff --git a/cpp/src/qpid/messaging/MessageImpl.h b/cpp/src/qpid/messaging/MessageImpl.h
index 57df6b3fda..915c790153 100644
--- a/cpp/src/qpid/messaging/MessageImpl.h
+++ b/cpp/src/qpid/messaging/MessageImpl.h
@@ -24,52 +24,77 @@
#include "qpid/messaging/Address.h"
#include "qpid/types/Variant.h"
#include "qpid/framing/SequenceNumber.h"
+#include "qpid/messaging/amqp/EncodedMessage.h"
+#include <vector>
+#include <boost/shared_ptr.hpp>
namespace qpid {
namespace messaging {
-struct MessageImpl
+class MessageImpl
{
- Address replyTo;
- std::string subject;
- std::string contentType;
- std::string messageId;
- std::string userId;
- std::string correlationId;
+ private:
+ mutable Address replyTo;
+ mutable std::string subject;
+ mutable std::string contentType;
+ mutable std::string messageId;
+ mutable std::string userId;
+ mutable std::string correlationId;
uint8_t priority;
uint64_t ttl;
bool durable;
bool redelivered;
- qpid::types::Variant::Map headers;
+ mutable qpid::types::Variant::Map headers;
- std::string bytes;
+ mutable std::string bytes;
+ boost::shared_ptr<const qpid::messaging::amqp::EncodedMessage> encoded;
qpid::framing::SequenceNumber internalId;
+ void updated();
+ public:
MessageImpl(const std::string& c);
MessageImpl(const char* chars, size_t count);
void setReplyTo(const Address& d);
const Address& getReplyTo() const;
-
+
void setSubject(const std::string& s);
const std::string& getSubject() const;
-
+
void setContentType(const std::string& s);
const std::string& getContentType() const;
-
+
+ void setMessageId(const std::string&);
+ const std::string& getMessageId() const;
+ void setUserId(const std::string& );
+ const std::string& getUserId() const;
+ void setCorrelationId(const std::string& );
+ const std::string& getCorrelationId() const;
+ void setPriority(uint8_t);
+ uint8_t getPriority() const;
+ void setTtl(uint64_t);
+ uint64_t getTtl() const;
+ void setDurable(bool);
+ bool isDurable() const;
+ void setRedelivered(bool);
+ bool isRedelivered() const;
+
+
const qpid::types::Variant::Map& getHeaders() const;
qpid::types::Variant::Map& getHeaders();
void setHeader(const std::string& key, const qpid::types::Variant& val);
-
+
void setBytes(const std::string& bytes);
void setBytes(const char* chars, size_t count);
+ void appendBytes(const char* chars, size_t count);
const std::string& getBytes() const;
std::string& getBytes();
void setInternalId(qpid::framing::SequenceNumber id);
qpid::framing::SequenceNumber getInternalId();
-
+ void setEncoded(boost::shared_ptr<const qpid::messaging::amqp::EncodedMessage> e) { encoded = e; }
+ boost::shared_ptr<const qpid::messaging::amqp::EncodedMessage> getEncoded() const { return encoded; }
};
class Message;
diff --git a/cpp/src/qpid/messaging/ProtocolRegistry.cpp b/cpp/src/qpid/messaging/ProtocolRegistry.cpp
new file mode 100644
index 0000000000..0232da8ae1
--- /dev/null
+++ b/cpp/src/qpid/messaging/ProtocolRegistry.cpp
@@ -0,0 +1,73 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "ProtocolRegistry.h"
+#include "qpid/Exception.h"
+#include "qpid/client/amqp0_10/ConnectionImpl.h"
+#include "qpid/client/LoadPlugins.h"
+#include <map>
+
+using qpid::types::Variant;
+
+namespace qpid {
+namespace messaging {
+namespace {
+typedef std::map<std::string, ProtocolRegistry::Factory*> Registry;
+
+Registry& theRegistry()
+{
+ static Registry factories;
+ return factories;
+}
+
+bool extract(const std::string& key, Variant& value, const Variant::Map& in, Variant::Map& out)
+{
+ bool matched = false;
+ for (Variant::Map::const_iterator i = in.begin(); i != in.end(); ++i) {
+ if (i->first == key) {
+ value = i->second;
+ matched = true;
+ } else {
+ out.insert(*i);
+ }
+ }
+ return matched;
+}
+}
+
+ConnectionImpl* ProtocolRegistry::create(const std::string& url, const Variant::Map& options)
+{
+ qpid::client::theModuleLoader();//ensure modules are loaded
+ Variant name;
+ Variant::Map stripped;
+ if (extract("protocol", name, options, stripped)) {
+ Registry::const_iterator i = theRegistry().find(name.asString());
+ if (i != theRegistry().end()) return (i->second)(url, stripped);
+ else if (name.asString() == "amqp0-10") return new qpid::client::amqp0_10::ConnectionImpl(url, stripped);
+ else throw qpid::Exception("Unsupported protocol: " + name.asString());
+ }
+ return 0;
+}
+void ProtocolRegistry::add(const std::string& name, Factory* factory)
+{
+ theRegistry()[name] = factory;
+}
+
+}} // namespace qpid::messaging
diff --git a/cpp/src/qpid/messaging/ProtocolRegistry.h b/cpp/src/qpid/messaging/ProtocolRegistry.h
new file mode 100644
index 0000000000..bcb62248a5
--- /dev/null
+++ b/cpp/src/qpid/messaging/ProtocolRegistry.h
@@ -0,0 +1,42 @@
+#ifndef QPID_MESSAGING_PROTOCOLREGISTRY_H
+#define QPID_MESSAGING_PROTOCOLREGISTRY_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/types/Variant.h"
+
+namespace qpid {
+namespace messaging {
+class ConnectionImpl;
+/**
+ * Registry for different implementations of the messaging API e.g AMQP 1.0
+ */
+class ProtocolRegistry
+{
+ public:
+ typedef ConnectionImpl* Factory(const std::string& url, const qpid::types::Variant::Map& options);
+ static ConnectionImpl* create(const std::string& url, const qpid::types::Variant::Map& options);
+ static void add(const std::string& name, Factory* factory);
+ private:
+};
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_PROTOCOLREGISTRY_H*/
diff --git a/cpp/src/qpid/messaging/ReceiverImpl.h b/cpp/src/qpid/messaging/ReceiverImpl.h
index 57059bfd28..e450693d2c 100644
--- a/cpp/src/qpid/messaging/ReceiverImpl.h
+++ b/cpp/src/qpid/messaging/ReceiverImpl.h
@@ -22,10 +22,12 @@
*
*/
#include "qpid/RefCounted.h"
+#include "qpid/sys/IntegerTypes.h"
namespace qpid {
namespace messaging {
+class Duration;
class Message;
class MessageListener;
class Session;
diff --git a/cpp/src/qpid/messaging/SenderImpl.h b/cpp/src/qpid/messaging/SenderImpl.h
index a1ca02c72c..d978463fdb 100644
--- a/cpp/src/qpid/messaging/SenderImpl.h
+++ b/cpp/src/qpid/messaging/SenderImpl.h
@@ -22,6 +22,7 @@
*
*/
#include "qpid/RefCounted.h"
+#include "qpid/sys/IntegerTypes.h"
namespace qpid {
namespace messaging {
diff --git a/cpp/src/qpid/messaging/amqp/AddressHelper.cpp b/cpp/src/qpid/messaging/amqp/AddressHelper.cpp
new file mode 100644
index 0000000000..359660dce5
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/AddressHelper.cpp
@@ -0,0 +1,182 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/messaging/amqp/AddressHelper.h"
+#include "qpid/messaging/Address.h"
+#include <vector>
+#include <boost/assign.hpp>
+extern "C" {
+#include <proton/engine.h>
+}
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+using qpid::types::Variant;
+
+namespace {
+//policy types
+const std::string CREATE("create");
+const std::string ASSERT("assert");
+const std::string DELETE("delete");
+
+//policy values
+const std::string ALWAYS("always");
+const std::string NEVER("never");
+const std::string RECEIVER("receiver");
+const std::string SENDER("sender");
+
+const std::string NODE("node");
+const std::string LINK("link");
+
+const std::string TYPE("type");
+const std::string TOPIC("topic");
+const std::string QUEUE("queue");
+
+//distribution modes:
+const std::string MOVE("move");
+const std::string COPY("copy");
+
+const std::string SUPPORTED_DIST_MODES("supported-dist-modes");
+
+
+const std::vector<std::string> RECEIVER_MODES = boost::assign::list_of<std::string>(ALWAYS) (RECEIVER);
+const std::vector<std::string> SENDER_MODES = boost::assign::list_of<std::string>(ALWAYS) (SENDER);
+
+pn_bytes_t convert(const std::string& s)
+{
+ pn_bytes_t result;
+ result.start = const_cast<char*>(s.data());
+ result.size = s.size();
+ return result;
+}
+
+bool bind(const Variant::Map& options, const std::string& name, std::string& variable)
+{
+ Variant::Map::const_iterator j = options.find(name);
+ if (j == options.end()) {
+ return false;
+ } else {
+ variable = j->second.asString();
+ return true;
+ }
+}
+
+bool bind(const Variant::Map& options, const std::string& name, Variant::Map& variable)
+{
+ Variant::Map::const_iterator j = options.find(name);
+ if (j == options.end()) {
+ return false;
+ } else {
+ variable = j->second.asMap();
+ return true;
+ }
+}
+
+bool bind(const Address& address, const std::string& name, std::string& variable)
+{
+ return bind(address.getOptions(), name, variable);
+}
+
+bool bind(const Address& address, const std::string& name, Variant::Map& variable)
+{
+ return bind(address.getOptions(), name, variable);
+}
+
+bool in(const std::string& value, const std::vector<std::string>& choices)
+{
+ for (std::vector<std::string>::const_iterator i = choices.begin(); i != choices.end(); ++i) {
+ if (value == *i) return true;
+ }
+ return false;
+}
+}
+
+AddressHelper::AddressHelper(const Address& address)
+{
+ bind(address, CREATE, createPolicy);
+ bind(address, DELETE, deletePolicy);
+ bind(address, ASSERT, assertPolicy);
+
+ bind(address, NODE, node);
+ bind(address, LINK, link);
+}
+
+bool AddressHelper::createEnabled(CheckMode mode) const
+{
+ return enabled(createPolicy, mode);
+}
+bool AddressHelper::deleteEnabled(CheckMode mode) const
+{
+ return enabled(deletePolicy, mode);
+}
+bool AddressHelper::assertEnabled(CheckMode mode) const
+{
+ return enabled(assertPolicy, mode);
+}
+bool AddressHelper::enabled(const std::string& policy, CheckMode mode) const
+{
+ bool result = false;
+ switch (mode) {
+ case FOR_RECEIVER:
+ result = in(policy, RECEIVER_MODES);
+ break;
+ case FOR_SENDER:
+ result = in(policy, SENDER_MODES);
+ break;
+ }
+ return result;
+}
+
+const qpid::types::Variant::Map& AddressHelper::getNodeProperties() const
+{
+ return node;
+}
+const qpid::types::Variant::Map& AddressHelper::getLinkProperties() const
+{
+ return link;
+}
+
+void AddressHelper::setNodeProperties(pn_terminus_t* terminus)
+{
+ pn_terminus_set_dynamic(terminus, true);
+
+ //properties for dynamically created node:
+ pn_data_t* data = pn_terminus_properties(terminus);
+ if (node.size()) {
+ pn_data_put_map(data);
+ pn_data_enter(data);
+ }
+ for (qpid::types::Variant::Map::const_iterator i = node.begin(); i != node.end(); ++i) {
+ if (i->first == TYPE) {
+ pn_data_put_symbol(data, convert(SUPPORTED_DIST_MODES));
+ pn_data_put_string(data, convert(i->second == TOPIC ? COPY : MOVE));
+ } else {
+ pn_data_put_symbol(data, convert(i->first));
+ pn_data_put_string(data, convert(i->second.asString()));
+ }
+ }
+ if (node.size()) {
+ pn_data_exit(data);
+ }
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/AddressHelper.h b/cpp/src/qpid/messaging/amqp/AddressHelper.h
new file mode 100644
index 0000000000..cd0aa1be9e
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/AddressHelper.h
@@ -0,0 +1,57 @@
+#ifndef QPID_MESSAGING_AMQP_ADDRESSHELPER_H
+#define QPID_MESSAGING_AMQP_ADDRESSHELPER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/types/Variant.h"
+
+struct pn_terminus_t;
+
+namespace qpid {
+namespace messaging {
+class Address;
+namespace amqp {
+
+class AddressHelper
+{
+ public:
+ enum CheckMode {FOR_RECEIVER, FOR_SENDER};
+
+ AddressHelper(const Address& address);
+ bool createEnabled(CheckMode mode) const;
+ bool deleteEnabled(CheckMode mode) const;
+ bool assertEnabled(CheckMode mode) const;
+
+ void setNodeProperties(pn_terminus_t*);
+ const qpid::types::Variant::Map& getNodeProperties() const;
+ const qpid::types::Variant::Map& getLinkProperties() const;
+ private:
+ std::string createPolicy;
+ std::string assertPolicy;
+ std::string deletePolicy;
+ qpid::types::Variant::Map node;
+ qpid::types::Variant::Map link;
+
+ bool enabled(const std::string& policy, CheckMode mode) const;
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_ADDRESSHELPER_H*/
diff --git a/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp b/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp
new file mode 100644
index 0000000000..b2a9b979b6
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp
@@ -0,0 +1,612 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "ConnectionContext.h"
+#include "DriverImpl.h"
+#include "ReceiverContext.h"
+#include "Sasl.h"
+#include "SenderContext.h"
+#include "SessionContext.h"
+#include "Transport.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/messaging/Duration.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/messaging/MessageImpl.h"
+#include "qpid/framing/Buffer.h"
+#include "qpid/framing/ProtocolInitiation.h"
+#include "qpid/framing/Uuid.h"
+#include "qpid/log/Statement.h"
+#include "qpid/sys/Time.h"
+#include <vector>
+extern "C" {
+#include <proton/engine.h>
+}
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+
+ConnectionContext::ConnectionContext(const std::string& u, const qpid::types::Variant::Map& o)
+ : qpid::messaging::ConnectionOptions(o),
+ url(u),
+ engine(pn_transport()),
+ connection(pn_connection()),
+ //note: disabled read/write of header as now handled by engine
+ writeHeader(false),
+ readHeader(false),
+ haveOutput(false),
+ state(DISCONNECTED),
+ codecSwitch(*this)
+{
+ if (pn_transport_bind(engine, connection)) {
+ //error
+ }
+ pn_connection_set_container(connection, "qpid::messaging");//TODO: take this from a connection option
+ bool enableTrace(false);
+ QPID_LOG_TEST_CAT(trace, protocol, enableTrace);
+ if (enableTrace) pn_transport_trace(engine, PN_TRACE_FRM);
+}
+
+ConnectionContext::~ConnectionContext()
+{
+ close();
+ sessions.clear();
+ pn_transport_free(engine);
+ pn_connection_free(connection);
+}
+
+namespace {
+const std::string COLON(":");
+}
+void ConnectionContext::open()
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ if (state != DISCONNECTED) throw qpid::messaging::ConnectionError("Connection was already opened!");
+ if (!driver) driver = DriverImpl::getDefault();
+
+ for (Url::const_iterator i = url.begin(); state != CONNECTED && i != url.end(); ++i) {
+ transport = driver->getTransport(i->protocol, *this);
+ std::stringstream port;
+ port << i->port;
+ id = i->host + COLON + port.str();
+ if (useSasl()) {
+ sasl = std::auto_ptr<Sasl>(new Sasl(id, *this, i->host));
+ }
+ state = CONNECTING;
+ try {
+ QPID_LOG(debug, id << " Connecting ...");
+ transport->connect(i->host, port.str());
+ } catch (const std::exception& e) {
+ QPID_LOG(info, id << " Error while connecting: " << e.what());
+ }
+ while (state == CONNECTING) {
+ lock.wait();
+ }
+ if (state == DISCONNECTED) {
+ QPID_LOG(debug, id << " Failed to connect");
+ transport = boost::shared_ptr<Transport>();
+ } else {
+ QPID_LOG(debug, id << " Connected");
+ }
+ }
+
+ if (state != CONNECTED) throw qpid::messaging::TransportFailure(QPID_MSG("Could not connect to " << url));
+
+ if (sasl.get()) {
+ wakeupDriver();
+ while (!sasl->authenticated()) {
+ QPID_LOG(debug, id << " Waiting to be authenticated...");
+ wait();
+ }
+ QPID_LOG(debug, id << " Authenticated");
+ }
+
+ QPID_LOG(debug, id << " Opening...");
+ pn_connection_open(connection);
+ wakeupDriver(); //want to write
+ while (pn_connection_state(connection) & PN_REMOTE_UNINIT) {
+ wait();
+ }
+ if (!(pn_connection_state(connection) & PN_REMOTE_ACTIVE)) {
+ throw qpid::messaging::ConnectionError("Failed to open connection");
+ }
+ QPID_LOG(debug, id << " Opened");
+}
+
+bool ConnectionContext::isOpen() const
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ return pn_connection_state(connection) & (PN_LOCAL_ACTIVE | PN_REMOTE_ACTIVE);
+}
+
+void ConnectionContext::endSession(boost::shared_ptr<SessionContext> ssn)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ pn_session_close(ssn->session);
+ //TODO: need to destroy session and remove context from map
+ wakeupDriver();
+}
+
+void ConnectionContext::close()
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ if (state != CONNECTED) return;
+ if (!(pn_connection_state(connection) & PN_LOCAL_CLOSED)) {
+ for (SessionMap::iterator i = sessions.begin(); i != sessions.end(); ++i) {
+ //wait for outstanding sends to settle
+ while (!i->second->settled()) {
+ QPID_LOG(debug, "Waiting for sends to settle before closing");
+ wait();//wait until message has been confirmed
+ }
+
+
+ if (!(pn_session_state(i->second->session) & PN_LOCAL_CLOSED)) {
+ pn_session_close(i->second->session);
+ }
+ }
+ pn_connection_close(connection);
+ wakeupDriver();
+ //wait for close to be confirmed by peer?
+ while (!(pn_connection_state(connection) & PN_REMOTE_CLOSED)) {
+ wait();
+ }
+ sessions.clear();
+ }
+ transport->close();
+ while (state != DISCONNECTED) {
+ lock.wait();
+ }
+}
+
+bool ConnectionContext::fetch(boost::shared_ptr<SessionContext> ssn, boost::shared_ptr<ReceiverContext> lnk, qpid::messaging::Message& message, qpid::messaging::Duration timeout)
+{
+ {
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ if (!lnk->capacity) {
+ pn_link_flow(lnk->receiver, 1);
+ wakeupDriver();
+ }
+ }
+ if (get(ssn, lnk, message, timeout)) {
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ if (lnk->capacity) {
+ pn_link_flow(lnk->receiver, 1);//TODO: is this the right approach?
+ wakeupDriver();
+ }
+ return true;
+ } else {
+ {
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ pn_link_drain(lnk->receiver, 0);
+ wakeupDriver();
+ while (pn_link_credit(lnk->receiver) && !pn_link_queued(lnk->receiver)) {
+ QPID_LOG(debug, "Waiting for message or for credit to be drained: credit=" << pn_link_credit(lnk->receiver) << ", queued=" << pn_link_queued(lnk->receiver));
+ wait();
+ }
+ if (lnk->capacity && pn_link_queued(lnk->receiver) == 0) {
+ pn_link_flow(lnk->receiver, lnk->capacity);
+ }
+ }
+ if (get(ssn, lnk, message, qpid::messaging::Duration::IMMEDIATE)) {
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ if (lnk->capacity) {
+ pn_link_flow(lnk->receiver, 1);
+ wakeupDriver();
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+
+qpid::sys::AbsTime convert(qpid::messaging::Duration timeout)
+{
+ qpid::sys::AbsTime until;
+ uint64_t ms = timeout.getMilliseconds();
+ if (ms < (uint64_t) (qpid::sys::TIME_INFINITE/qpid::sys::TIME_MSEC)) {
+ return qpid::sys::AbsTime(qpid::sys::now(), ms * qpid::sys::TIME_MSEC);
+ } else {
+ return qpid::sys::FAR_FUTURE;
+ }
+}
+
+bool ConnectionContext::get(boost::shared_ptr<SessionContext> ssn, boost::shared_ptr<ReceiverContext> lnk, qpid::messaging::Message& message, qpid::messaging::Duration timeout)
+{
+ qpid::sys::AbsTime until(convert(timeout));
+ while (true) {
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ pn_delivery_t* current = pn_link_current((pn_link_t*) lnk->receiver);
+ QPID_LOG(debug, "In ConnectionContext::get(), current=" << current);
+ if (current) {
+ qpid::messaging::MessageImpl& impl = MessageImplAccess::get(message);
+ boost::shared_ptr<EncodedMessage> encoded(new EncodedMessage(pn_delivery_pending(current)));
+ ssize_t read = pn_link_recv(lnk->receiver, encoded->getData(), encoded->getSize());
+ if (read < 0) throw qpid::messaging::MessagingException("Failed to read message");
+ encoded->trim((size_t) read);
+ QPID_LOG(debug, "Received message of " << encoded->getSize() << " bytes: ");
+ encoded->init(impl);
+ impl.setEncoded(encoded);
+ impl.setInternalId(ssn->record(current));
+ pn_link_advance(lnk->receiver);
+ return true;
+ } else if (until > qpid::sys::now()) {
+ wait();
+ } else {
+ return false;
+ }
+ }
+ return false;
+}
+
+void ConnectionContext::acknowledge(boost::shared_ptr<SessionContext> ssn, qpid::messaging::Message* message, bool cumulative)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ if (message) {
+ ssn->acknowledge(MessageImplAccess::get(*message).getInternalId(), cumulative);
+ } else {
+ ssn->acknowledge();
+ }
+ wakeupDriver();
+}
+
+
+void ConnectionContext::attach(boost::shared_ptr<SessionContext> ssn, boost::shared_ptr<SenderContext> lnk)
+{
+ lnk->configure();
+ attach(ssn->session, (pn_link_t*) lnk->sender);
+ if (!pn_link_remote_target((pn_link_t*) lnk->sender)) {
+ std::string msg("No such target : ");
+ msg += lnk->getTarget();
+ throw qpid::messaging::NotFound(msg);
+ }
+}
+
+void ConnectionContext::attach(boost::shared_ptr<SessionContext> ssn, boost::shared_ptr<ReceiverContext> lnk)
+{
+ lnk->configure();
+ attach(ssn->session, lnk->receiver, lnk->capacity);
+ if (!pn_link_remote_source(lnk->receiver)) {
+ std::string msg("No such source : ");
+ msg += lnk->getSource();
+ throw qpid::messaging::NotFound(msg);
+ }
+}
+
+void ConnectionContext::attach(pn_session_t* /*session*/, pn_link_t* link, int credit)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ QPID_LOG(debug, "Attaching link " << link << ", state=" << pn_link_state(link));
+ pn_link_open(link);
+ QPID_LOG(debug, "Link attached " << link << ", state=" << pn_link_state(link));
+ if (credit) pn_link_flow(link, credit);
+ wakeupDriver();
+ while (pn_link_state(link) & PN_REMOTE_UNINIT) {
+ QPID_LOG(debug, "waiting for confirmation of link attach for " << link << ", state=" << pn_link_state(link));
+ wait();
+ }
+}
+
+void ConnectionContext::send(boost::shared_ptr<SenderContext> snd, const qpid::messaging::Message& message, bool sync)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ SenderContext::Delivery* delivery(0);
+ while (!(delivery = snd->send(message))) {
+ QPID_LOG(debug, "Waiting for capacity...");
+ wait();//wait for capacity
+ }
+ wakeupDriver();
+ if (sync) {
+ while (!delivery->accepted()) {
+ QPID_LOG(debug, "Waiting for confirmation...");
+ wait();//wait until message has been confirmed
+ }
+ }
+}
+
+void ConnectionContext::setCapacity(boost::shared_ptr<SenderContext> sender, uint32_t capacity)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ sender->setCapacity(capacity);
+}
+uint32_t ConnectionContext::getCapacity(boost::shared_ptr<SenderContext> sender)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ return sender->getCapacity();
+}
+uint32_t ConnectionContext::getUnsettled(boost::shared_ptr<SenderContext> sender)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ return sender->getUnsettled();
+}
+
+void ConnectionContext::setCapacity(boost::shared_ptr<ReceiverContext> receiver, uint32_t capacity)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ receiver->setCapacity(capacity);
+ pn_link_flow((pn_link_t*) receiver->receiver, receiver->getCapacity());
+ wakeupDriver();
+}
+uint32_t ConnectionContext::getCapacity(boost::shared_ptr<ReceiverContext> receiver)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ return receiver->getCapacity();
+}
+uint32_t ConnectionContext::getAvailable(boost::shared_ptr<ReceiverContext> receiver)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ return receiver->getAvailable();
+}
+uint32_t ConnectionContext::getUnsettled(boost::shared_ptr<ReceiverContext> receiver)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ return receiver->getUnsettled();
+}
+
+void ConnectionContext::activateOutput()
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ wakeupDriver();
+}
+/**
+ * Expects lock to be held by caller
+ */
+void ConnectionContext::wakeupDriver()
+{
+ switch (state) {
+ case CONNECTED:
+ haveOutput = true;
+ transport->activateOutput();
+ QPID_LOG(debug, "wakeupDriver()");
+ break;
+ case DISCONNECTED:
+ case CONNECTING:
+ QPID_LOG(error, "wakeupDriver() called while not connected");
+ break;
+ }
+}
+
+void ConnectionContext::wait()
+{
+ lock.wait();
+ if (state == DISCONNECTED) {
+ throw qpid::messaging::TransportFailure("Disconnected");
+ }
+ //check for any closed links, sessions or indeed the connection
+}
+
+boost::shared_ptr<SessionContext> ConnectionContext::newSession(bool transactional, const std::string& n)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ if (transactional) throw qpid::messaging::MessagingException("Transactions not yet supported");
+ std::string name = n.empty() ? qpid::framing::Uuid(true).str() : n;
+ SessionMap::const_iterator i = sessions.find(name);
+ if (i == sessions.end()) {
+ boost::shared_ptr<SessionContext> s(new SessionContext(connection));
+ s->session = pn_session(connection);
+ pn_session_open(s->session);
+ sessions[name] = s;
+ wakeupDriver();
+ while (pn_session_state(s->session) & PN_REMOTE_UNINIT) {
+ wait();
+ }
+ return s;
+ } else {
+ throw qpid::messaging::KeyError(std::string("Session already exists: ") + name);
+ }
+
+}
+boost::shared_ptr<SessionContext> ConnectionContext::getSession(const std::string& name) const
+{
+ SessionMap::const_iterator i = sessions.find(name);
+ if (i == sessions.end()) {
+ throw qpid::messaging::KeyError(std::string("No such session") + name);
+ } else {
+ return i->second;
+ }
+}
+
+void ConnectionContext::setOption(const std::string& name, const qpid::types::Variant& value)
+{
+ set(name, value);
+}
+
+std::string ConnectionContext::getAuthenticatedUsername()
+{
+ return sasl.get() ? sasl->getAuthenticatedUsername() : std::string();
+}
+
+std::size_t ConnectionContext::decode(const char* buffer, std::size_t size)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ QPID_LOG(trace, id << " decode(" << size << ")");
+ if (readHeader) {
+ size_t decoded = readProtocolHeader(buffer, size);
+ if (decoded < size) {
+ decoded += decode(buffer + decoded, size - decoded);
+ }
+ return decoded;
+ }
+
+ //TODO: Fix pn_engine_input() to take const buffer
+ ssize_t n = pn_transport_input(engine, const_cast<char*>(buffer), size);
+ if (n > 0 || n == PN_EOS) {
+ //If engine returns EOS, have no way of knowing how many bytes
+ //it processed, but can assume none need to be reprocessed so
+ //consider them all read:
+ if (n == PN_EOS) n = size;
+ QPID_LOG_CAT(debug, network, id << " decoded " << n << " bytes from " << size)
+ pn_transport_tick(engine, 0);
+ lock.notifyAll();
+ return n;
+ } else if (n == PN_ERR) {
+ throw qpid::Exception(QPID_MSG("Error on input: " << getError()));
+ } else {
+ return 0;
+ }
+
+}
+std::size_t ConnectionContext::encode(char* buffer, std::size_t size)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ QPID_LOG(trace, id << " encode(" << size << ")");
+ if (writeHeader) {
+ size_t encoded = writeProtocolHeader(buffer, size);
+ if (encoded < size) {
+ encoded += encode(buffer + encoded, size - encoded);
+ }
+ return encoded;
+ }
+
+ ssize_t n = pn_transport_output(engine, buffer, size);
+ if (n > 0) {
+ QPID_LOG_CAT(debug, network, id << " encoded " << n << " bytes from " << size)
+ haveOutput = true;
+ return n;
+ } else if (n == PN_ERR) {
+ throw qpid::Exception(QPID_MSG("Error on output: " << getError()));
+ } else if (n == PN_EOS) {
+ haveOutput = false;
+ return 0;//Is this right?
+ } else {
+ haveOutput = false;
+ return 0;
+ }
+}
+bool ConnectionContext::canEncode()
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ return haveOutput && state == CONNECTED;
+}
+void ConnectionContext::closed()
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ state = DISCONNECTED;
+ lock.notifyAll();
+}
+void ConnectionContext::opened()
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
+ state = CONNECTED;
+ lock.notifyAll();
+}
+bool ConnectionContext::isClosed() const
+{
+ return !isOpen();
+}
+namespace {
+qpid::framing::ProtocolVersion AMQP_1_0_PLAIN(1,0,qpid::framing::ProtocolVersion::AMQP);
+}
+
+std::string ConnectionContext::getError()
+{
+ std::stringstream text;
+ pn_error_t* cerror = pn_connection_error(connection);
+ if (cerror) text << "connection error " << pn_error_text(cerror);
+ pn_error_t* terror = pn_transport_error(engine);
+ if (terror) text << "transport error " << pn_error_text(terror);
+ return text.str();
+}
+
+framing::ProtocolVersion ConnectionContext::getVersion() const
+{
+ return AMQP_1_0_PLAIN;
+}
+
+std::size_t ConnectionContext::readProtocolHeader(const char* buffer, std::size_t size)
+{
+ framing::ProtocolInitiation pi(getVersion());
+ if (size >= pi.encodedSize()) {
+ readHeader = false;
+ qpid::framing::Buffer out(const_cast<char*>(buffer), size);
+ pi.decode(out);
+ QPID_LOG_CAT(debug, protocol, id << " read protocol header: " << pi);
+ return pi.encodedSize();
+ } else {
+ return 0;
+ }
+}
+std::size_t ConnectionContext::writeProtocolHeader(char* buffer, std::size_t size)
+{
+ framing::ProtocolInitiation pi(getVersion());
+ if (size >= pi.encodedSize()) {
+ QPID_LOG_CAT(debug, protocol, id << " writing protocol header: " << pi);
+ writeHeader = false;
+ qpid::framing::Buffer out(buffer, size);
+ pi.encode(out);
+ return pi.encodedSize();
+ } else {
+ QPID_LOG_CAT(debug, protocol, id << " insufficient buffer for protocol header: " << size)
+ return 0;
+ }
+}
+bool ConnectionContext::useSasl()
+{
+ return !(mechanism == "none" || mechanism == "NONE" || mechanism == "None");
+}
+
+qpid::sys::Codec& ConnectionContext::getCodec()
+{
+ return codecSwitch;
+}
+
+ConnectionContext::CodecSwitch::CodecSwitch(ConnectionContext& p) : parent(p) {}
+std::size_t ConnectionContext::CodecSwitch::decode(const char* buffer, std::size_t size)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(parent.lock);
+ size_t decoded = 0;
+ if (parent.sasl.get() && !parent.sasl->authenticated()) {
+ decoded = parent.sasl->decode(buffer, size);
+ if (!parent.sasl->authenticated()) return decoded;
+ }
+ if (decoded < size) {
+ if (parent.sasl.get() && parent.sasl->getSecurityLayer()) decoded += parent.sasl->getSecurityLayer()->decode(buffer+decoded, size-decoded);
+ else decoded += parent.decode(buffer+decoded, size-decoded);
+ }
+ return decoded;
+}
+std::size_t ConnectionContext::CodecSwitch::encode(char* buffer, std::size_t size)
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(parent.lock);
+ size_t encoded = 0;
+ if (parent.sasl.get() && parent.sasl->canEncode()) {
+ encoded += parent.sasl->encode(buffer, size);
+ if (!parent.sasl->authenticated()) return encoded;
+ }
+ if (encoded < size) {
+ if (parent.sasl.get() && parent.sasl->getSecurityLayer()) encoded += parent.sasl->getSecurityLayer()->encode(buffer+encoded, size-encoded);
+ else encoded += parent.encode(buffer+encoded, size-encoded);
+ }
+ return encoded;
+}
+bool ConnectionContext::CodecSwitch::canEncode()
+{
+ qpid::sys::ScopedLock<qpid::sys::Monitor> l(parent.lock);
+ if (parent.sasl.get()) {
+ if (parent.sasl->canEncode()) return true;
+ else if (!parent.sasl->authenticated()) return false;
+ else if (parent.sasl->getSecurityLayer()) return parent.sasl->getSecurityLayer()->canEncode();
+ }
+ return parent.canEncode();
+}
+
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/ConnectionContext.h b/cpp/src/qpid/messaging/amqp/ConnectionContext.h
new file mode 100644
index 0000000000..3718184365
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/ConnectionContext.h
@@ -0,0 +1,150 @@
+#ifndef QPID_MESSAGING_AMQP_CONNECTIONCONTEXT_H
+#define QPID_MESSAGING_AMQP_CONNECTIONCONTEXT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <deque>
+#include <map>
+#include <memory>
+#include <string>
+#include <boost/shared_ptr.hpp>
+#include "qpid/Url.h"
+#include "qpid/messaging/ConnectionOptions.h"
+#include "qpid/sys/AtomicValue.h"
+#include "qpid/sys/ConnectionCodec.h"
+#include "qpid/sys/Monitor.h"
+#include "qpid/types/Variant.h"
+#include "qpid/messaging/amqp/TransportContext.h"
+
+struct pn_connection_t;
+struct pn_link_t;
+struct pn_session_t;
+struct pn_transport_t;
+
+
+namespace qpid {
+namespace framing {
+class ProtocolVersion;
+}
+namespace messaging {
+class Duration;
+class Message;
+namespace amqp {
+
+class DriverImpl;
+class ReceiverContext;
+class Sasl;
+class SessionContext;
+class SenderContext;
+class Transport;
+
+/**
+ *
+ */
+class ConnectionContext : public qpid::sys::ConnectionCodec, public qpid::messaging::ConnectionOptions, public TransportContext
+{
+ public:
+ ConnectionContext(const std::string& url, const qpid::types::Variant::Map& options);
+ ~ConnectionContext();
+ void open();
+ bool isOpen() const;
+ void close();
+ boost::shared_ptr<SessionContext> newSession(bool transactional, const std::string& name);
+ boost::shared_ptr<SessionContext> getSession(const std::string& name) const;
+ void endSession(boost::shared_ptr<SessionContext>);
+ void attach(boost::shared_ptr<SessionContext>, boost::shared_ptr<SenderContext>);
+ void attach(boost::shared_ptr<SessionContext>, boost::shared_ptr<ReceiverContext>);
+ void send(boost::shared_ptr<SenderContext> ctxt, const qpid::messaging::Message& message, bool sync);
+ bool fetch(boost::shared_ptr<SessionContext> ssn, boost::shared_ptr<ReceiverContext> lnk, qpid::messaging::Message& message, qpid::messaging::Duration timeout);
+ bool get(boost::shared_ptr<SessionContext> ssn, boost::shared_ptr<ReceiverContext> lnk, qpid::messaging::Message& message, qpid::messaging::Duration timeout);
+ void acknowledge(boost::shared_ptr<SessionContext> ssn, qpid::messaging::Message* message, bool cumulative);
+
+ void setOption(const std::string& name, const qpid::types::Variant& value);
+ std::string getAuthenticatedUsername();
+
+ void setCapacity(boost::shared_ptr<SenderContext>, uint32_t);
+ uint32_t getCapacity(boost::shared_ptr<SenderContext>);
+ uint32_t getUnsettled(boost::shared_ptr<SenderContext>);
+
+ void setCapacity(boost::shared_ptr<ReceiverContext>, uint32_t);
+ uint32_t getCapacity(boost::shared_ptr<ReceiverContext>);
+ uint32_t getAvailable(boost::shared_ptr<ReceiverContext>);
+ uint32_t getUnsettled(boost::shared_ptr<ReceiverContext>);
+
+
+ void activateOutput();
+ qpid::sys::Codec& getCodec();
+ //ConnectionCodec interface:
+ std::size_t decode(const char* buffer, std::size_t size);
+ std::size_t encode(char* buffer, std::size_t size);
+ bool canEncode();
+ void closed();
+ bool isClosed() const;
+ framing::ProtocolVersion getVersion() const;
+ //additionally, Transport needs:
+ void opened();//signal successful connection
+
+ private:
+ typedef std::map<std::string, boost::shared_ptr<SessionContext> > SessionMap;
+ qpid::Url url;
+
+ boost::shared_ptr<DriverImpl> driver;
+ boost::shared_ptr<Transport> transport;
+
+ pn_transport_t* engine;
+ pn_connection_t* connection;
+ SessionMap sessions;
+ mutable qpid::sys::Monitor lock;
+ bool writeHeader;
+ bool readHeader;
+ bool haveOutput;
+ std::string id;
+ enum {
+ DISCONNECTED,
+ CONNECTING,
+ CONNECTED
+ } state;
+ std::auto_ptr<Sasl> sasl;
+ class CodecSwitch : public qpid::sys::Codec
+ {
+ public:
+ CodecSwitch(ConnectionContext&);
+ std::size_t decode(const char* buffer, std::size_t size);
+ std::size_t encode(char* buffer, std::size_t size);
+ bool canEncode();
+ private:
+ ConnectionContext& parent;
+ };
+ CodecSwitch codecSwitch;
+
+ void wait();
+ void wakeupDriver();
+ void attach(pn_session_t*, pn_link_t*, int credit=0);
+
+ std::size_t readProtocolHeader(const char* buffer, std::size_t size);
+ std::size_t writeProtocolHeader(char* buffer, std::size_t size);
+ std::string getError();
+ bool useSasl();
+};
+
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_CONNECTIONCONTEXT_H*/
diff --git a/cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp b/cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp
new file mode 100644
index 0000000000..0c4ec2bfcb
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp
@@ -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.
+ *
+ */
+#include "ConnectionHandle.h"
+#include "ConnectionContext.h"
+#include "SessionHandle.h"
+#include "qpid/messaging/Session.h"
+#include "qpid/messaging/ProtocolRegistry.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+// Static constructor which registers this implementation in the ProtocolRegistry
+namespace {
+ConnectionImpl* create(const std::string& u, const qpid::types::Variant::Map& o)
+{
+ return new ConnectionHandle(u, o);
+}
+
+struct StaticInit
+{
+ StaticInit()
+ {
+ ProtocolRegistry::add("amqp1.0", &create);
+ };
+} init;
+}
+
+ConnectionHandle::ConnectionHandle(const std::string& url, const qpid::types::Variant::Map& options) : connection(new ConnectionContext(url, options)) {}
+ConnectionHandle::ConnectionHandle(boost::shared_ptr<ConnectionContext> c) : connection(c) {}
+
+void ConnectionHandle::open()
+{
+ connection->open();
+}
+
+bool ConnectionHandle::isOpen() const
+{
+ return connection->isOpen();
+}
+
+void ConnectionHandle::close()
+{
+ connection->close();
+}
+
+Session ConnectionHandle::newSession(bool transactional, const std::string& name)
+{
+ return qpid::messaging::Session(new SessionHandle(connection, connection->newSession(transactional, name)));
+}
+
+Session ConnectionHandle::getSession(const std::string& name) const
+{
+ return qpid::messaging::Session(new SessionHandle(connection, connection->getSession(name)));
+}
+
+void ConnectionHandle::setOption(const std::string& name, const qpid::types::Variant& value)
+{
+ connection->setOption(name, value);
+}
+
+std::string ConnectionHandle::getAuthenticatedUsername()
+{
+ return connection->getAuthenticatedUsername();
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/ConnectionHandle.h b/cpp/src/qpid/messaging/amqp/ConnectionHandle.h
new file mode 100644
index 0000000000..d1eb27f6de
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/ConnectionHandle.h
@@ -0,0 +1,58 @@
+#ifndef QPID_MESSAGING_AMQP_CONNECTIONHANDLE_H
+#define QPID_MESSAGING_AMQP_CONNECTIONHANDLE_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <boost/shared_ptr.hpp>
+#include "qpid/messaging/ConnectionImpl.h"
+#include "qpid/types/Variant.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+class ConnectionContext;
+/**
+ * Handles are directly referenced by applications; Contexts are
+ * referenced by Handles. This allows a graph structure that
+ * remains intact as long as the application references any part
+ * of it, but that can be automatically reclaimed if the whole
+ * graph becomes unreferenced.
+ */
+class ConnectionHandle : public qpid::messaging::ConnectionImpl
+{
+ public:
+ ConnectionHandle(const std::string& url, const qpid::types::Variant::Map& options);
+ ConnectionHandle(boost::shared_ptr<ConnectionContext>);
+ void open();
+ bool isOpen() const;
+ void close();
+ Session newSession(bool transactional, const std::string& name);
+ Session getSession(const std::string& name) const;
+ void setOption(const std::string& name, const qpid::types::Variant& value);
+ std::string getAuthenticatedUsername();
+ private:
+ boost::shared_ptr<ConnectionContext> connection;
+};
+
+}}} // namespace qpid::messaging::amqp_1.0
+
+#endif /*!QPID_MESSAGING_AMQP_CONNECTIONHANDLE_H*/
diff --git a/cpp/src/qpid/messaging/amqp/DriverImpl.cpp b/cpp/src/qpid/messaging/amqp/DriverImpl.cpp
new file mode 100644
index 0000000000..16307b3c22
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/DriverImpl.cpp
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "DriverImpl.h"
+#include "Transport.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/sys/Poller.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+DriverImpl::DriverImpl() : poller(new qpid::sys::Poller)
+{
+ start();
+}
+DriverImpl::~DriverImpl()
+{
+ stop();
+}
+
+void DriverImpl::start()
+{
+ thread = qpid::sys::Thread(*poller);
+ QPID_LOG(debug, "Driver started");
+}
+
+void DriverImpl::stop()
+{
+ QPID_LOG(debug, "Driver stopped");
+ poller->shutdown();
+ thread.join();
+}
+
+boost::shared_ptr<Transport> DriverImpl::getTransport(const std::string& protocol, TransportContext& connection)
+{
+ boost::shared_ptr<Transport> t(Transport::create(protocol, connection, poller));
+ if (!t) throw qpid::messaging::ConnectionError("No such transport: " + protocol);
+ return t;
+}
+
+
+qpid::sys::Mutex DriverImpl::defaultLock;
+boost::weak_ptr<DriverImpl> DriverImpl::theDefault;
+boost::shared_ptr<DriverImpl> DriverImpl::getDefault()
+{
+ qpid::sys::Mutex::ScopedLock l(defaultLock);
+ boost::shared_ptr<DriverImpl> p = theDefault.lock();
+ if (!p) {
+ p = boost::shared_ptr<DriverImpl>(new DriverImpl);
+ theDefault = p;
+ }
+ return p;
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/DriverImpl.h b/cpp/src/qpid/messaging/amqp/DriverImpl.h
new file mode 100644
index 0000000000..354fa1ae35
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/DriverImpl.h
@@ -0,0 +1,60 @@
+#ifndef QPID_MESSAGING_AMQP_DRIVERIMPL_H
+#define QPID_MESSAGING_AMQP_DRIVERIMPL_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/sys/Mutex.h"
+#include "qpid/sys/Thread.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+
+namespace qpid {
+namespace sys {
+class Poller;
+}
+namespace messaging {
+namespace amqp {
+class TransportContext;
+class Transport;
+/**
+ *
+ */
+class DriverImpl
+{
+ public:
+ DriverImpl();
+ ~DriverImpl();
+
+ void start();
+ void stop();
+
+ boost::shared_ptr<Transport> getTransport(const std::string& protocol, TransportContext& connection);
+
+ static boost::shared_ptr<DriverImpl> getDefault();
+ private:
+ boost::shared_ptr<qpid::sys::Poller> poller;
+ qpid::sys::Thread thread;
+ static qpid::sys::Mutex defaultLock;
+ static boost::weak_ptr<DriverImpl> theDefault;
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_DRIVERIMPL_H*/
diff --git a/cpp/src/qpid/messaging/amqp/EncodedMessage.cpp b/cpp/src/qpid/messaging/amqp/EncodedMessage.cpp
new file mode 100644
index 0000000000..54de3eae45
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/EncodedMessage.cpp
@@ -0,0 +1,263 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/messaging/amqp/EncodedMessage.h"
+#include "qpid/messaging/Address.h"
+#include "qpid/messaging/MessageImpl.h"
+#include "qpid/amqp/Decoder.h"
+#include <boost/lexical_cast.hpp>
+#include <string.h>
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+using namespace qpid::amqp;
+
+EncodedMessage::EncodedMessage(size_t s) : size(s), data(size ? new char[size] : 0)
+{
+ init();
+}
+
+EncodedMessage::EncodedMessage() : size(0), data(0)
+{
+ init();
+}
+
+EncodedMessage::EncodedMessage(const EncodedMessage& other) : size(other.size), data(size ? new char[size] : 0)
+{
+ init();
+}
+
+void EncodedMessage::init()
+{
+ //init all CharSequence members
+ deliveryAnnotations.init();
+ messageAnnotations.init();
+ userId.init();
+ to.init();
+ subject.init();
+ replyTo.init();
+ contentType.init();
+ contentEncoding.init();
+ groupId.init();
+ replyToGroupId.init();
+ applicationProperties.init();
+ body.init();
+ footer.init();
+}
+
+EncodedMessage::~EncodedMessage()
+{
+ delete[] data;
+}
+
+size_t EncodedMessage::getSize() const
+{
+ return size;
+}
+void EncodedMessage::trim(size_t t)
+{
+ size = t;
+}
+void EncodedMessage::resize(size_t s)
+{
+ delete[] data;
+ size = s;
+ data = new char[size];
+}
+
+char* EncodedMessage::getData()
+{
+ return data;
+}
+const char* EncodedMessage::getData() const
+{
+ return data;
+}
+
+void EncodedMessage::init(qpid::messaging::MessageImpl& impl)
+{
+ //initial scan of raw data
+ qpid::amqp::Decoder decoder(data, size);
+ InitialScan reader(*this, impl);
+ decoder.read(reader);
+ bareMessage = reader.getBareMessage();
+ if (bareMessage.data && !bareMessage.size) {
+ bareMessage.size = (data + size) - bareMessage.data;
+ }
+
+}
+void EncodedMessage::populate(qpid::types::Variant::Map& map) const
+{
+ //decode application properties
+ if (applicationProperties) {
+ qpid::amqp::Decoder decoder(applicationProperties.data, applicationProperties.size);
+ decoder.readMap(map);
+ }
+ //add in 'x-amqp-' prefixed values
+ if (!!firstAcquirer) {
+ map["x-amqp-first-acquirer"] = firstAcquirer.get();
+ }
+ if (!!deliveryCount) {
+ map["x-amqp-delivery-count"] = deliveryCount.get();
+ }
+ if (to) {
+ map["x-amqp-delivery-count"] = to.str();
+ }
+ if (!!absoluteExpiryTime) {
+ map["x-amqp-absolute-expiry-time"] = absoluteExpiryTime.get();
+ }
+ if (!!creationTime) {
+ map["x-amqp-creation-time"] = creationTime.get();
+ }
+ if (groupId) {
+ map["x-amqp-group-id"] = groupId.str();
+ }
+ if (!!groupSequence) {
+ map["x-amqp-qroup-sequence"] = groupSequence.get();
+ }
+ if (replyToGroupId) {
+ map["x-amqp-reply-to-group-id"] = replyToGroupId.str();
+ }
+ //add in any annotations
+ if (deliveryAnnotations) {
+ qpid::types::Variant::Map& annotations = map["x-amqp-delivery-annotations"].asMap();
+ qpid::amqp::Decoder decoder(deliveryAnnotations.data, deliveryAnnotations.size);
+ decoder.readMap(annotations);
+ }
+ if (messageAnnotations) {
+ qpid::types::Variant::Map& annotations = map["x-amqp-message-annotations"].asMap();
+ qpid::amqp::Decoder decoder(messageAnnotations.data, messageAnnotations.size);
+ decoder.readMap(annotations);
+ }
+}
+qpid::amqp::CharSequence EncodedMessage::getBareMessage() const
+{
+ return bareMessage;
+}
+
+void EncodedMessage::getReplyTo(qpid::messaging::Address& a) const
+{
+ a = qpid::messaging::Address(replyTo.str());
+}
+void EncodedMessage::getSubject(std::string& s) const
+{
+ s.assign(subject.data, subject.size);
+}
+void EncodedMessage::getContentType(std::string& s) const
+{
+ s.assign(contentType.data, contentType.size);
+}
+void EncodedMessage::getUserId(std::string& s) const
+{
+ s.assign(userId.data, userId.size);
+}
+void EncodedMessage::getMessageId(std::string& s) const
+{
+ messageId.assign(s);
+}
+void EncodedMessage::getCorrelationId(std::string& s) const
+{
+ correlationId.assign(s);
+}
+void EncodedMessage::getBody(std::string& s) const
+{
+ s.assign(body.data, body.size);
+}
+
+qpid::amqp::CharSequence EncodedMessage::getBody() const
+{
+ return body;
+}
+
+bool EncodedMessage::hasHeaderChanged(const qpid::messaging::MessageImpl& msg) const
+{
+ if (!durable) {
+ if (msg.isDurable()) return true;
+ } else {
+ if (durable.get() != msg.isDurable()) return true;
+ }
+
+ if (!priority) {
+ if (msg.getPriority() != 4) return true;
+ } else {
+ if (priority.get() != msg.getPriority()) return true;
+ }
+
+ if (msg.getTtl() && (!ttl || msg.getTtl() != ttl.get())) {
+ return true;
+ }
+
+ //first-acquirer can't be changed via Message interface as yet
+
+ if (msg.isRedelivered() && (!deliveryCount || deliveryCount.get() == 0)) {
+ return true;
+ }
+
+ return false;
+}
+
+
+EncodedMessage::InitialScan::InitialScan(EncodedMessage& e, qpid::messaging::MessageImpl& m) : em(e), mi(m)
+{
+ //set up defaults as needed:
+ mi.setPriority(4);
+}
+//header:
+void EncodedMessage::InitialScan::onDurable(bool b) { mi.setDurable(b); em.durable = b; }
+void EncodedMessage::InitialScan::onPriority(uint8_t i) { mi.setPriority(i); em.priority = i; }
+void EncodedMessage::InitialScan::onTtl(uint32_t i) { mi.setTtl(i); em.ttl = i; }
+void EncodedMessage::InitialScan::onFirstAcquirer(bool b) { em.firstAcquirer = b; }
+void EncodedMessage::InitialScan::onDeliveryCount(uint32_t i)
+{
+ mi.setRedelivered(i);
+ em.deliveryCount = i;
+}
+
+//properties:
+void EncodedMessage::InitialScan::onMessageId(uint64_t v) { em.messageId.set(v); }
+void EncodedMessage::InitialScan::onMessageId(const qpid::amqp::CharSequence& v, qpid::types::VariantType t) { em.messageId.set(v, t); }
+void EncodedMessage::InitialScan::onUserId(const qpid::amqp::CharSequence& v) { em.userId = v; }
+void EncodedMessage::InitialScan::onTo(const qpid::amqp::CharSequence& v) { em.to = v; }
+void EncodedMessage::InitialScan::onSubject(const qpid::amqp::CharSequence& v) { em.subject = v; }
+void EncodedMessage::InitialScan::onReplyTo(const qpid::amqp::CharSequence& v) { em.replyTo = v;}
+void EncodedMessage::InitialScan::onCorrelationId(uint64_t v) { em.correlationId.set(v); }
+void EncodedMessage::InitialScan::onCorrelationId(const qpid::amqp::CharSequence& v, qpid::types::VariantType t) { em.correlationId.set(v, t); }
+void EncodedMessage::InitialScan::onContentType(const qpid::amqp::CharSequence& v) { em.contentType = v; }
+void EncodedMessage::InitialScan::onContentEncoding(const qpid::amqp::CharSequence& v) { em.contentEncoding = v; }
+void EncodedMessage::InitialScan::onAbsoluteExpiryTime(int64_t i) { em.absoluteExpiryTime = i; }
+void EncodedMessage::InitialScan::onCreationTime(int64_t i) { em.creationTime = i; }
+void EncodedMessage::InitialScan::onGroupId(const qpid::amqp::CharSequence& v) { em.groupId = v; }
+void EncodedMessage::InitialScan::onGroupSequence(uint32_t i) { em.groupSequence = i; }
+void EncodedMessage::InitialScan::onReplyToGroupId(const qpid::amqp::CharSequence& v) { em.replyToGroupId = v; }
+
+void EncodedMessage::InitialScan::onApplicationProperties(const qpid::amqp::CharSequence& v) { em.applicationProperties = v; }
+void EncodedMessage::InitialScan::onDeliveryAnnotations(const qpid::amqp::CharSequence& v) { em.deliveryAnnotations = v; }
+void EncodedMessage::InitialScan::onMessageAnnotations(const qpid::amqp::CharSequence& v) { em.messageAnnotations = v; }
+void EncodedMessage::InitialScan::onBody(const qpid::amqp::CharSequence& v, const qpid::amqp::Descriptor&)
+{
+ //TODO: how to communicate the type, i.e. descriptor?
+ em.body = v;
+}
+void EncodedMessage::InitialScan::onBody(const qpid::types::Variant&, const qpid::amqp::Descriptor&) {}
+void EncodedMessage::InitialScan::onFooter(const qpid::amqp::CharSequence& v) { em.footer = v; }
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/EncodedMessage.h b/cpp/src/qpid/messaging/amqp/EncodedMessage.h
new file mode 100644
index 0000000000..09a9d948d5
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/EncodedMessage.h
@@ -0,0 +1,177 @@
+#ifndef QPID_MESSAGING_AMQP_ENCODEDMESSAGE_H
+#define QPID_MESSAGING_AMQP_ENCODEDMESSAGE_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/amqp/CharSequence.h"
+#include "qpid/amqp/MessageId.h"
+#include "qpid/amqp/MessageReader.h"
+#include "qpid/sys/IntegerTypes.h"
+#include "qpid/types/Variant.h"
+#include <boost/optional.hpp>
+
+namespace qpid {
+namespace amqp {
+struct Descriptor;
+}
+namespace messaging {
+class Address;
+class MessageImpl;
+namespace amqp {
+
+/**
+ * Used to 'lazy-decode' an AMQP 1.0 message.
+ *
+ * There are four categories of data item:
+ *
+ * (i) simple, fixed width primitives - priority, ttl, durability,
+ * delivery count - for which lazy-decoding doesn't buy much. These
+ * are decoded unconditionally on an initial scan of the message.
+ *
+ * (ii) standard variable length string properties - subject,
+ * message-id, user-id etc - which require conversion to a std::string
+ * for returning to the application. By delaying the conversion of
+ * these to a std::string we can avoid allocation & copying until it
+ * is actually required. The initial scan of the message merely
+ * records the position of these strings within the raw message data.
+ *
+ * (iii) custom, application defined headers. These form a map, and
+ * again, delaying the creation of that map until it is actually
+ * required can be advantageous. The initial scan of the message merely
+ * records the position of this section within the raw message data.
+ *
+ * (iv) the body content. This may be retreived as a std::string, or
+ * as a char*. Avoiding conversion to the string until it is required
+ * is advantageous. The initial scan of the message merely records the
+ * position of this section within the raw message data.
+ *
+ * At present the Message class only explicitly exposes some of the
+ * standard property and headers defined by AMQP 1.0. The remainder
+ * will have to be accessed through the message 'headers' map, using
+ * the 'x-amqp-' prefix.
+ */
+class EncodedMessage
+{
+ public:
+ EncodedMessage();
+ EncodedMessage(size_t);
+ EncodedMessage(const EncodedMessage&);
+ ~EncodedMessage();
+
+
+ size_t getSize() const;
+ char* getData();
+ const char* getData() const;
+ void trim(size_t);
+ void resize(size_t);
+
+ void getReplyTo(qpid::messaging::Address&) const;
+ void getSubject(std::string&) const;
+ void getContentType(std::string&) const;
+ void getMessageId(std::string&) const;
+ void getUserId(std::string&) const;
+ void getCorrelationId(std::string&) const;
+
+ void init(qpid::messaging::MessageImpl&);
+ void populate(qpid::types::Variant::Map&) const;
+ void getBody(std::string&) const;
+ qpid::amqp::CharSequence getBareMessage() const;
+ qpid::amqp::CharSequence getBody() const;
+ bool hasHeaderChanged(const qpid::messaging::MessageImpl&) const;
+ private:
+ size_t size;
+ char* data;
+
+ class InitialScan : public qpid::amqp::MessageReader
+ {
+ public:
+ InitialScan(EncodedMessage& e, qpid::messaging::MessageImpl& m);
+ //header:
+ void onDurable(bool b);
+ void onPriority(uint8_t i);
+ void onTtl(uint32_t i);
+ void onFirstAcquirer(bool b);
+ void onDeliveryCount(uint32_t i);
+ //properties:
+ void onMessageId(uint64_t);
+ void onMessageId(const qpid::amqp::CharSequence&, qpid::types::VariantType);
+ void onUserId(const qpid::amqp::CharSequence& v);
+ void onTo(const qpid::amqp::CharSequence& v);
+ void onSubject(const qpid::amqp::CharSequence& v);
+ void onReplyTo(const qpid::amqp::CharSequence& v);
+ void onCorrelationId(uint64_t);
+ void onCorrelationId(const qpid::amqp::CharSequence&, qpid::types::VariantType);
+ void onContentType(const qpid::amqp::CharSequence& v);
+ void onContentEncoding(const qpid::amqp::CharSequence& v);
+ void onAbsoluteExpiryTime(int64_t i);
+ void onCreationTime(int64_t);
+ void onGroupId(const qpid::amqp::CharSequence&);
+ void onGroupSequence(uint32_t);
+ void onReplyToGroupId(const qpid::amqp::CharSequence&);
+
+ void onApplicationProperties(const qpid::amqp::CharSequence&);
+ void onDeliveryAnnotations(const qpid::amqp::CharSequence&);
+ void onMessageAnnotations(const qpid::amqp::CharSequence&);
+ void onBody(const qpid::amqp::CharSequence&, const qpid::amqp::Descriptor&);
+ void onBody(const qpid::types::Variant&, const qpid::amqp::Descriptor&);
+ void onFooter(const qpid::amqp::CharSequence&);
+ private:
+ EncodedMessage& em;
+ qpid::messaging::MessageImpl& mi;
+ };
+ //header:
+ boost::optional<bool> durable;
+ boost::optional<uint8_t> priority;
+ boost::optional<uint32_t> ttl;
+ boost::optional<bool> firstAcquirer;
+ boost::optional<uint32_t> deliveryCount;
+ //annotations:
+ qpid::amqp::CharSequence deliveryAnnotations;
+ qpid::amqp::CharSequence messageAnnotations;
+
+ qpid::amqp::CharSequence bareMessage;//properties, application-properties and content
+ //properties:
+ qpid::amqp::MessageId messageId;
+ qpid::amqp::CharSequence userId;
+ qpid::amqp::CharSequence to;
+ qpid::amqp::CharSequence subject;
+ qpid::amqp::CharSequence replyTo;
+ qpid::amqp::MessageId correlationId;
+ qpid::amqp::CharSequence contentType;
+ qpid::amqp::CharSequence contentEncoding;
+ boost::optional<int64_t> absoluteExpiryTime;
+ boost::optional<int64_t> creationTime;
+ qpid::amqp::CharSequence groupId;
+ boost::optional<uint32_t> groupSequence;
+ qpid::amqp::CharSequence replyToGroupId;
+ //application-properties:
+ qpid::amqp::CharSequence applicationProperties;
+ qpid::amqp::CharSequence body;
+ //footer:
+ qpid::amqp::CharSequence footer;
+
+ void init();
+ //not implemented:
+ EncodedMessage& operator=(const EncodedMessage&);
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_ENCODEDMESSAGE_H*/
diff --git a/cpp/src/qpid/messaging/amqp/ReceiverContext.cpp b/cpp/src/qpid/messaging/amqp/ReceiverContext.cpp
new file mode 100644
index 0000000000..414793c7fd
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/ReceiverContext.cpp
@@ -0,0 +1,146 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/messaging/amqp/ReceiverContext.h"
+#include "qpid/messaging/amqp/AddressHelper.h"
+#include "qpid/messaging/Duration.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/amqp/descriptors.h"
+extern "C" {
+#include <proton/engine.h>
+}
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+//TODO: proper conversion to wide string for address
+ReceiverContext::ReceiverContext(pn_session_t* session, const std::string& n, const qpid::messaging::Address& a)
+ : name(n),
+ address(a),
+ receiver(pn_receiver(session, name.c_str())),
+ capacity(0) {}
+ReceiverContext::~ReceiverContext()
+{
+ pn_link_free(receiver);
+}
+
+void ReceiverContext::setCapacity(uint32_t c)
+{
+ if (c != capacity) {
+ //stop
+ capacity = c;
+ //reissue credit
+ }
+}
+
+uint32_t ReceiverContext::getCapacity()
+{
+ return capacity;
+}
+
+uint32_t ReceiverContext::getAvailable()
+{
+ uint32_t count(0);
+ for (pn_delivery_t* d = pn_unsettled_head(receiver); d; d = pn_unsettled_next(d)) {
+ ++count;
+ if (d == pn_link_current(receiver)) break;
+ }
+ return count;
+}
+
+uint32_t ReceiverContext::getUnsettled()
+{
+ uint32_t count(0);
+ for (pn_delivery_t* d = pn_unsettled_head(receiver); d; d = pn_unsettled_next(d)) {
+ ++count;
+ }
+ return count;
+}
+
+void ReceiverContext::close()
+{
+
+}
+
+const std::string& ReceiverContext::getName() const
+{
+ return name;
+}
+
+const std::string& ReceiverContext::getSource() const
+{
+ return address.getName();
+}
+namespace {
+pn_bytes_t convert(const std::string& s)
+{
+ pn_bytes_t result;
+ result.start = const_cast<char*>(s.data());
+ result.size = s.size();
+ return result;
+}
+bool hasWildcards(const std::string& key)
+{
+ return key.find('*') != std::string::npos || key.find('#') != std::string::npos;
+}
+
+uint64_t getFilterDescriptor(const std::string& key)
+{
+ return hasWildcards(key) ? qpid::amqp::filters::LEGACY_TOPIC_FILTER_CODE : qpid::amqp::filters::LEGACY_DIRECT_FILTER_CODE;
+}
+}
+
+void ReceiverContext::configure() const
+{
+ configure(pn_link_source(receiver));
+}
+void ReceiverContext::configure(pn_terminus_t* source) const
+{
+ pn_terminus_set_address(source, address.getName().c_str());
+ //dynamic create:
+ AddressHelper helper(address);
+ if (helper.createEnabled(AddressHelper::FOR_RECEIVER)) {
+ helper.setNodeProperties(source);
+ }
+
+ if (!address.getSubject().empty()) {
+ //filter:
+ pn_data_t* filter = pn_terminus_filter(source);
+ pn_data_put_map(filter);
+ pn_data_enter(filter);
+ pn_data_put_symbol(filter, convert("subject"));
+ //TODO: At present inserting described values into the map doesn't seem to work; correct this once resolved
+ //pn_data_put_described(filter);
+ //pn_data_enter(filter);
+ //pn_data_put_ulong(filter, getFilterDescriptor(address.getSubject()));
+ pn_data_put_string(filter, convert(address.getSubject()));
+ //pn_data_exit(filter);
+ pn_data_exit(filter);
+ }
+}
+
+bool ReceiverContext::isClosed() const
+{
+ return false;//TODO
+}
+
+
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/ReceiverContext.h b/cpp/src/qpid/messaging/amqp/ReceiverContext.h
new file mode 100644
index 0000000000..34ecdda6be
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/ReceiverContext.h
@@ -0,0 +1,68 @@
+#ifndef QPID_MESSAGING_AMQP_RECEIVERCONTEXT_H
+#define QPID_MESSAGING_AMQP_RECEIVERCONTEXT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/messaging/Address.h"
+#include <string>
+#include "qpid/sys/IntegerTypes.h"
+
+struct pn_link_t;
+struct pn_session_t;
+struct pn_terminus_t;
+
+namespace qpid {
+namespace messaging {
+
+class Duration;
+class Message;
+
+namespace amqp {
+
+/**
+ *
+ */
+class ReceiverContext
+{
+ public:
+ ReceiverContext(pn_session_t* session, const std::string& name, const qpid::messaging::Address& source);
+ ~ReceiverContext();
+ void setCapacity(uint32_t);
+ uint32_t getCapacity();
+ uint32_t getAvailable();
+ uint32_t getUnsettled();
+ void attach();
+ void close();
+ const std::string& getName() const;
+ const std::string& getSource() const;
+ bool isClosed() const;
+ void configure() const;
+ private:
+ friend class ConnectionContext;
+ const std::string name;
+ const Address address;
+ pn_link_t* receiver;
+ uint32_t capacity;
+ void configure(pn_terminus_t*) const;
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_RECEIVERCONTEXT_H*/
diff --git a/cpp/src/qpid/messaging/amqp/ReceiverHandle.cpp b/cpp/src/qpid/messaging/amqp/ReceiverHandle.cpp
new file mode 100644
index 0000000000..9bf64ebb8d
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/ReceiverHandle.cpp
@@ -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.
+ *
+ */
+#include "ReceiverHandle.h"
+#include "ConnectionContext.h"
+#include "SessionContext.h"
+#include "SessionHandle.h"
+#include "ReceiverContext.h"
+#include "qpid/messaging/Duration.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/messaging/Session.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+ReceiverHandle::ReceiverHandle(boost::shared_ptr<ConnectionContext> c,
+ boost::shared_ptr<SessionContext> s,
+ boost::shared_ptr<ReceiverContext> r
+) : connection(c), session(s), receiver(r) {}
+
+
+bool ReceiverHandle::get(qpid::messaging::Message& message, qpid::messaging::Duration timeout)
+{
+ return connection->get(session, receiver, message, timeout);
+}
+
+qpid::messaging::Message ReceiverHandle::get(qpid::messaging::Duration timeout)
+{
+ qpid::messaging::Message result;
+ if (!get(result, timeout)) throw qpid::messaging::NoMessageAvailable();
+ return result;
+}
+
+bool ReceiverHandle::fetch(qpid::messaging::Message& message, qpid::messaging::Duration timeout)
+{
+ return connection->fetch(session, receiver, message, timeout);
+}
+
+qpid::messaging::Message ReceiverHandle::fetch(qpid::messaging::Duration timeout)
+{
+ qpid::messaging::Message result;
+ if (!fetch(result, timeout)) throw qpid::messaging::NoMessageAvailable();
+ return result;
+}
+
+void ReceiverHandle::setCapacity(uint32_t capacity)
+{
+ connection->setCapacity(receiver, capacity);
+}
+
+uint32_t ReceiverHandle::getCapacity()
+{
+ return connection->getCapacity(receiver);
+}
+
+uint32_t ReceiverHandle::getAvailable()
+{
+ return connection->getAvailable(receiver);
+}
+
+uint32_t ReceiverHandle::getUnsettled()
+{
+ return connection->getUnsettled(receiver);
+}
+
+void ReceiverHandle::close()
+{
+ session->closeReceiver(getName());
+}
+
+const std::string& ReceiverHandle::getName() const
+{
+ return receiver->getName();
+}
+
+qpid::messaging::Session ReceiverHandle::getSession() const
+{
+ //create new SessionHandle instance; i.e. create new handle that shares the same context
+ return qpid::messaging::Session(new SessionHandle(connection, session));
+}
+
+bool ReceiverHandle::isClosed() const
+{
+ return receiver->isClosed();
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/ReceiverHandle.h b/cpp/src/qpid/messaging/amqp/ReceiverHandle.h
new file mode 100644
index 0000000000..a1a6f26025
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/ReceiverHandle.h
@@ -0,0 +1,63 @@
+#ifndef QPID_MESSAGING_AMQP_RECEIVERHANDLE_H
+#define QPID_MESSAGING_AMQP_RECEIVERHANDLE_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <boost/shared_ptr.hpp>
+#include "qpid/messaging/ReceiverImpl.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+class ConnectionContext;
+class SessionContext;
+class ReceiverContext;
+/**
+ *
+ */
+class ReceiverHandle : public qpid::messaging::ReceiverImpl
+{
+ public:
+ ReceiverHandle(boost::shared_ptr<ConnectionContext>,
+ boost::shared_ptr<SessionContext>,
+ boost::shared_ptr<ReceiverContext>
+ );
+ bool get(Message& message, qpid::messaging::Duration timeout);
+ qpid::messaging::Message get(qpid::messaging::Duration timeout);
+ bool fetch(Message& message, qpid::messaging::Duration timeout);
+ qpid::messaging::Message fetch(qpid::messaging::Duration timeout);
+ void setCapacity(uint32_t);
+ uint32_t getCapacity();
+ uint32_t getAvailable();
+ uint32_t getUnsettled();
+ void close();
+ const std::string& getName() const;
+ qpid::messaging::Session getSession() const;
+ bool isClosed() const;
+ private:
+ boost::shared_ptr<ConnectionContext> connection;
+ boost::shared_ptr<SessionContext> session;
+ boost::shared_ptr<ReceiverContext> receiver;
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_RECEIVERHANDLE_H*/
diff --git a/cpp/src/qpid/messaging/amqp/Sasl.cpp b/cpp/src/qpid/messaging/amqp/Sasl.cpp
new file mode 100644
index 0000000000..a8bae1adda
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/Sasl.cpp
@@ -0,0 +1,157 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "ConnectionContext.h"
+#include "qpid/messaging/amqp/Sasl.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/sys/SecurityLayer.h"
+#include "qpid/log/Statement.h"
+#include "qpid/Sasl.h"
+#include "qpid/SaslFactory.h"
+#include "qpid/StringUtils.h"
+#include <sstream>
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+Sasl::Sasl(const std::string& id, ConnectionContext& c, const std::string& hostname_)
+ : qpid::amqp::SaslClient(id), context(c),
+ sasl(qpid::SaslFactory::getInstance().create(c.username, c.password, c.service, hostname_, c.minSsf, c.maxSsf, false)),
+ hostname(hostname_), readHeader(true), writeHeader(true), haveOutput(false), state(NONE) {}
+
+std::size_t Sasl::decode(const char* buffer, std::size_t size)
+{
+ size_t decoded = 0;
+ if (readHeader) {
+ decoded += readProtocolHeader(buffer, size);
+ readHeader = !decoded;
+ }
+ if (state == NONE && decoded < size) {
+ decoded += read(buffer + decoded, size - decoded);
+ }
+ QPID_LOG(trace, id << " Sasl::decode(" << size << "): " << decoded);
+ return decoded;
+}
+
+std::size_t Sasl::encode(char* buffer, std::size_t size)
+{
+ size_t encoded = 0;
+ if (writeHeader) {
+ encoded += writeProtocolHeader(buffer, size);
+ writeHeader = !encoded;
+ }
+ if (encoded < size) {
+ encoded += write(buffer + encoded, size - encoded);
+ }
+ haveOutput = (encoded == size);
+ QPID_LOG(trace, id << " Sasl::encode(" << size << "): " << encoded);
+ return encoded;
+}
+
+bool Sasl::canEncode()
+{
+ QPID_LOG(trace, id << " Sasl::canEncode(): " << writeHeader << " || " << haveOutput);
+ return writeHeader || haveOutput;
+}
+
+void Sasl::mechanisms(const std::string& offered)
+{
+ QPID_LOG_CAT(debug, protocol, id << " Received SASL-MECHANISMS(" << offered << ")");
+ std::string response;
+
+ std::string mechanisms;
+ if (context.mechanism.size()) {
+ std::vector<std::string> allowed = split(context.mechanism, " ");
+ std::vector<std::string> supported = split(offered, " ");
+ std::stringstream intersection;
+ for (std::vector<std::string>::const_iterator i = allowed.begin(); i != allowed.end(); ++i) {
+ if (std::find(supported.begin(), supported.end(), *i) != supported.end()) {
+ intersection << *i << " ";
+ }
+ }
+ mechanisms = intersection.str();
+ } else {
+ mechanisms = offered;
+ }
+
+ if (sasl->start(mechanisms, response)) {
+ init(sasl->getMechanism(), &response, hostname.size() ? &hostname : 0);
+ } else {
+ init(sasl->getMechanism(), 0, hostname.size() ? &hostname : 0);
+ }
+ haveOutput = true;
+ context.activateOutput();
+}
+void Sasl::challenge(const std::string& challenge)
+{
+ QPID_LOG_CAT(debug, protocol, id << " Received SASL-CHALLENGE(" << challenge.size() << " bytes)");
+ std::string r = sasl->step(challenge);
+ response(&r);
+ haveOutput = true;
+ context.activateOutput();
+}
+namespace {
+const std::string EMPTY;
+}
+void Sasl::challenge()
+{
+ QPID_LOG_CAT(debug, protocol, id << " Received SASL-CHALLENGE(null)");
+ std::string r = sasl->step(EMPTY);
+ response(&r);
+}
+void Sasl::outcome(uint8_t result, const std::string& extra)
+{
+ QPID_LOG_CAT(debug, protocol, id << " Received SASL-OUTCOME(" << result << ", " << extra << ")");
+ outcome(result);
+}
+void Sasl::outcome(uint8_t result)
+{
+ QPID_LOG_CAT(debug, protocol, id << " Received SASL-OUTCOME(" << result << ")");
+ if (result) state = FAILED;
+ else state = SUCCEEDED;
+
+ securityLayer = sasl->getSecurityLayer(context.maxFrameSize);
+ if (securityLayer.get()) {
+ securityLayer->init(&context);
+ }
+ context.activateOutput();
+}
+
+qpid::sys::Codec* Sasl::getSecurityLayer()
+{
+ return securityLayer.get();
+}
+
+bool Sasl::authenticated()
+{
+ switch (state) {
+ case SUCCEEDED: return true;
+ case FAILED: throw qpid::messaging::UnauthorizedAccess("Failed to authenticate");
+ case NONE: default: return false;
+ }
+}
+
+std::string Sasl::getAuthenticatedUsername()
+{
+ return sasl->getUserId();
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/Sasl.h b/cpp/src/qpid/messaging/amqp/Sasl.h
new file mode 100644
index 0000000000..6657779fdc
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/Sasl.h
@@ -0,0 +1,72 @@
+#ifndef QPID_MESSAGING_AMQP_SASL_H
+#define QPID_MESSAGING_AMQP_SASL_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/sys/Codec.h"
+#include "qpid/amqp/SaslClient.h"
+#include <memory>
+
+namespace qpid {
+class Sasl;
+namespace sys {
+class SecurityLayer;
+}
+namespace messaging {
+class ConnectionOptions;
+namespace amqp {
+class ConnectionContext;
+
+/**
+ *
+ */
+class Sasl : public qpid::sys::Codec, qpid::amqp::SaslClient
+{
+ public:
+ Sasl(const std::string& id, ConnectionContext& context, const std::string& hostname);
+ std::size_t decode(const char* buffer, std::size_t size);
+ std::size_t encode(char* buffer, std::size_t size);
+ bool canEncode();
+
+ bool authenticated();
+ qpid::sys::Codec* getSecurityLayer();
+ std::string getAuthenticatedUsername();
+ private:
+ ConnectionContext& context;
+ std::auto_ptr<qpid::Sasl> sasl;
+ std::string hostname;
+ bool readHeader;
+ bool writeHeader;
+ bool haveOutput;
+ enum {
+ NONE, FAILED, SUCCEEDED
+ } state;
+ std::auto_ptr<qpid::sys::SecurityLayer> securityLayer;
+
+ void mechanisms(const std::string&);
+ void challenge(const std::string&);
+ void challenge(); //null != empty string
+ void outcome(uint8_t result, const std::string&);
+ void outcome(uint8_t result);
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_SASL_H*/
diff --git a/cpp/src/qpid/messaging/amqp/SenderContext.cpp b/cpp/src/qpid/messaging/amqp/SenderContext.cpp
new file mode 100644
index 0000000000..96c4437b89
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SenderContext.cpp
@@ -0,0 +1,363 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/messaging/amqp/SenderContext.h"
+#include "qpid/messaging/amqp/EncodedMessage.h"
+#include "qpid/messaging/amqp/AddressHelper.h"
+#include "qpid/amqp/descriptors.h"
+#include "qpid/amqp/MessageEncoder.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/messaging/MessageImpl.h"
+#include "qpid/log/Statement.h"
+extern "C" {
+#include <proton/engine.h>
+}
+#include <boost/shared_ptr.hpp>
+#include <string.h>
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+//TODO: proper conversion to wide string for address
+SenderContext::SenderContext(pn_session_t* session, const std::string& n, const qpid::messaging::Address& a)
+ : name(n),
+ address(a),
+ sender(pn_sender(session, n.c_str())), capacity(1000) {}
+
+SenderContext::~SenderContext()
+{
+ pn_link_free(sender);
+}
+
+void SenderContext::close()
+{
+
+}
+
+void SenderContext::setCapacity(uint32_t c)
+{
+ if (c < deliveries.size()) throw qpid::messaging::SenderError("Desired capacity is less than unsettled message count!");
+ capacity = c;
+}
+
+uint32_t SenderContext::getCapacity()
+{
+ return capacity;
+}
+
+uint32_t SenderContext::getUnsettled()
+{
+ return processUnsettled();
+}
+
+const std::string& SenderContext::getName() const
+{
+ return name;
+}
+
+const std::string& SenderContext::getTarget() const
+{
+ return address.getName();
+}
+
+SenderContext::Delivery* SenderContext::send(const qpid::messaging::Message& message)
+{
+ if (processUnsettled() < capacity && pn_link_credit(sender)) {
+ deliveries.push_back(Delivery(nextId++));
+ Delivery& delivery = deliveries.back();
+ delivery.encode(MessageImplAccess::get(message), address);
+ delivery.send(sender);
+ return &delivery;
+ } else {
+ return 0;
+ }
+}
+
+uint32_t SenderContext::processUnsettled()
+{
+ //remove accepted messages from front of deque
+ while (!deliveries.empty() && deliveries.front().accepted()) {
+ deliveries.front().settle();
+ deliveries.pop_front();
+ }
+ return deliveries.size();
+}
+namespace {
+class HeaderAdapter : public qpid::amqp::MessageEncoder::Header
+{
+ public:
+ HeaderAdapter(const qpid::messaging::MessageImpl& impl) : msg(impl) {}
+ virtual bool isDurable() const
+ {
+ return msg.isDurable();
+ }
+ virtual uint8_t getPriority() const
+ {
+ return msg.getPriority();
+ }
+ virtual bool hasTtl() const
+ {
+ return msg.getTtl();
+ }
+ virtual uint32_t getTtl() const
+ {
+ return msg.getTtl();
+ }
+ virtual bool isFirstAcquirer() const
+ {
+ return false;
+ }
+ virtual uint32_t getDeliveryCount() const
+ {
+ return msg.isRedelivered() ? 1 : 0;
+ }
+ private:
+ const qpid::messaging::MessageImpl& msg;
+};
+const std::string EMPTY;
+
+class PropertiesAdapter : public qpid::amqp::MessageEncoder::Properties
+{
+ public:
+ PropertiesAdapter(const qpid::messaging::MessageImpl& impl, const std::string& s) : msg(impl), subject(s) {}
+ bool hasMessageId() const
+ {
+ return getMessageId().size();
+ }
+ std::string getMessageId() const
+ {
+ return msg.getMessageId();
+ }
+
+ bool hasUserId() const
+ {
+ return getUserId().size();
+ }
+
+ std::string getUserId() const
+ {
+ return msg.getUserId();
+ }
+
+ bool hasTo() const
+ {
+ return false;//not yet supported
+ }
+
+ std::string getTo() const
+ {
+ return EMPTY;//not yet supported
+ }
+
+ bool hasSubject() const
+ {
+ return subject.size() || getSubject().size();
+ }
+
+ std::string getSubject() const
+ {
+ return subject.size() ? subject : msg.getSubject();
+ }
+
+ bool hasReplyTo() const
+ {
+ return msg.getReplyTo();
+ }
+
+ std::string getReplyTo() const
+ {
+ return msg.getReplyTo().str();
+ }
+
+ bool hasCorrelationId() const
+ {
+ return getCorrelationId().size();
+ }
+
+ std::string getCorrelationId() const
+ {
+ return msg.getCorrelationId();
+ }
+
+ bool hasContentType() const
+ {
+ return getContentType().size();
+ }
+
+ std::string getContentType() const
+ {
+ return msg.getContentType();
+ }
+
+ bool hasContentEncoding() const
+ {
+ return false;//not yet supported
+ }
+
+ std::string getContentEncoding() const
+ {
+ return EMPTY;//not yet supported
+ }
+
+ bool hasAbsoluteExpiryTime() const
+ {
+ return false;//not yet supported
+ }
+
+ int64_t getAbsoluteExpiryTime() const
+ {
+ return 0;//not yet supported
+ }
+
+ bool hasCreationTime() const
+ {
+ return false;//not yet supported
+ }
+
+ int64_t getCreationTime() const
+ {
+ return 0;//not yet supported
+ }
+
+ bool hasGroupId() const
+ {
+ return false;//not yet supported
+ }
+
+ std::string getGroupId() const
+ {
+ return EMPTY;//not yet supported
+ }
+
+ bool hasGroupSequence() const
+ {
+ return false;//not yet supported
+ }
+
+ uint32_t getGroupSequence() const
+ {
+ return 0;//not yet supported
+ }
+
+ bool hasReplyToGroupId() const
+ {
+ return false;//not yet supported
+ }
+
+ std::string getReplyToGroupId() const
+ {
+ return EMPTY;//not yet supported
+ }
+ private:
+ const qpid::messaging::MessageImpl& msg;
+ const std::string subject;
+};
+
+bool changedSubject(const qpid::messaging::MessageImpl& msg, const qpid::messaging::Address& address)
+{
+ return address.getSubject().size() && address.getSubject() != msg.getSubject();
+}
+
+}
+
+SenderContext::Delivery::Delivery(int32_t i) : id(i), token(0) {}
+
+void SenderContext::Delivery::encode(const qpid::messaging::MessageImpl& msg, const qpid::messaging::Address& address)
+{
+ boost::shared_ptr<const EncodedMessage> original = msg.getEncoded();
+
+ if (original && !changedSubject(msg, address)) { //still have the content as received, send at least the bare message unaltered
+ //do we need to alter the header? are durable, priority, ttl, first-acquirer, delivery-count different from what was received?
+ if (original->hasHeaderChanged(msg)) {
+ //since as yet have no annotations, just write the revised header then the rest of the message as received
+ encoded.resize(16/*max header size*/ + original->getBareMessage().size);
+ qpid::amqp::MessageEncoder encoder(encoded.getData(), encoded.getSize());
+ HeaderAdapter header(msg);
+ encoder.writeHeader(header);
+ ::memcpy(encoded.getData() + encoder.getPosition(), original->getBareMessage().data, original->getBareMessage().size);
+ } else {
+ //since as yet have no annotations, if the header hasn't
+ //changed and we still have the original bare message, can
+ //send the entire content as is
+ encoded.resize(original->getSize());
+ ::memcpy(encoded.getData(), original->getData(), original->getSize());
+ }
+ } else {
+ HeaderAdapter header(msg);
+ PropertiesAdapter properties(msg, address.getSubject());
+ //compute size:
+ encoded.resize(qpid::amqp::MessageEncoder::getEncodedSize(header, properties, msg.getHeaders(), msg.getBytes()));
+ QPID_LOG(debug, "Sending message, buffer is " << encoded.getSize() << " bytes")
+ qpid::amqp::MessageEncoder encoder(encoded.getData(), encoded.getSize());
+ //write header:
+ encoder.writeHeader(header);
+ //write delivery-annotations, write message-annotations (none yet supported)
+ //write properties
+ encoder.writeProperties(properties);
+ //write application-properties
+ encoder.writeApplicationProperties(msg.getHeaders());
+ //write body
+ if (msg.getBytes().size()) encoder.writeBinary(msg.getBytes(), &qpid::amqp::message::DATA);//structured content not yet directly supported
+ if (encoder.getPosition() < encoded.getSize()) {
+ QPID_LOG(debug, "Trimming buffer from " << encoded.getSize() << " to " << encoder.getPosition());
+ encoded.trim(encoder.getPosition());
+ }
+ //write footer (no annotations yet supported)
+ }
+}
+void SenderContext::Delivery::send(pn_link_t* sender)
+{
+ pn_delivery_tag_t tag;
+ tag.size = sizeof(id);
+ tag.bytes = reinterpret_cast<const char*>(&id);
+ token = pn_delivery(sender, tag);
+ pn_link_send(sender, encoded.getData(), encoded.getSize());
+ pn_link_advance(sender);
+}
+
+bool SenderContext::Delivery::accepted()
+{
+ return pn_delivery_remote_state(token) == PN_ACCEPTED;
+}
+void SenderContext::Delivery::settle()
+{
+ pn_delivery_settle(token);
+}
+void SenderContext::configure() const
+{
+ configure(pn_link_target(sender));
+}
+void SenderContext::configure(pn_terminus_t* target) const
+{
+ pn_terminus_set_address(target, address.getName().c_str());
+ //dynamic create:
+ AddressHelper helper(address);
+ if (helper.createEnabled(AddressHelper::FOR_SENDER)) {
+ helper.setNodeProperties(target);
+ }
+}
+
+bool SenderContext::settled()
+{
+ return processUnsettled() == 0;
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/SenderContext.h b/cpp/src/qpid/messaging/amqp/SenderContext.h
new file mode 100644
index 0000000000..3595379e70
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SenderContext.h
@@ -0,0 +1,90 @@
+#ifndef QPID_MESSAGING_AMQP_SENDERCONTEXT_H
+#define QPID_MESSAGING_AMQP_SENDERCONTEXT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <deque>
+#include <string>
+#include <vector>
+#include "qpid/sys/IntegerTypes.h"
+#include "qpid/messaging/Address.h"
+#include "qpid/messaging/amqp/EncodedMessage.h"
+
+struct pn_delivery_t;
+struct pn_link_t;
+struct pn_session_t;
+struct pn_terminus_t;
+
+namespace qpid {
+namespace messaging {
+
+class Message;
+class MessageImpl;
+
+namespace amqp {
+/**
+ *
+ */
+class SenderContext
+{
+ public:
+ class Delivery
+ {
+ public:
+ Delivery(int32_t id);
+ void encode(const qpid::messaging::MessageImpl& message, const qpid::messaging::Address&);
+ void send(pn_link_t*);
+ bool accepted();
+ void settle();
+ private:
+ int32_t id;
+ pn_delivery_t* token;
+ EncodedMessage encoded;
+ };
+
+ SenderContext(pn_session_t* session, const std::string& name, const qpid::messaging::Address& target);
+ ~SenderContext();
+ void close();
+ void setCapacity(uint32_t);
+ uint32_t getCapacity();
+ uint32_t getUnsettled();
+ const std::string& getName() const;
+ const std::string& getTarget() const;
+ Delivery* send(const qpid::messaging::Message& message);
+ void configure() const;
+ bool settled();
+ private:
+ friend class ConnectionContext;
+ typedef std::deque<Delivery> Deliveries;
+
+ const std::string name;
+ const qpid::messaging::Address address;
+ pn_link_t* sender;
+ int32_t nextId;
+ Deliveries deliveries;
+ uint32_t capacity;
+
+ uint32_t processUnsettled();
+ void configure(pn_terminus_t*) const;
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_SENDERCONTEXT_H*/
diff --git a/cpp/src/qpid/messaging/amqp/SenderHandle.cpp b/cpp/src/qpid/messaging/amqp/SenderHandle.cpp
new file mode 100644
index 0000000000..b7168e5b31
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SenderHandle.cpp
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "SenderHandle.h"
+#include "ConnectionContext.h"
+#include "SessionContext.h"
+#include "SessionHandle.h"
+#include "SenderContext.h"
+#include "qpid/messaging/Duration.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/messaging/Message.h"
+#include "qpid/messaging/Session.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+SenderHandle::SenderHandle(boost::shared_ptr<ConnectionContext> c,
+ boost::shared_ptr<SessionContext> s,
+ boost::shared_ptr<SenderContext> sndr
+) : connection(c), session(s), sender(sndr) {}
+
+void SenderHandle::send(const Message& message, bool sync)
+{
+ connection->send(sender, message, sync);
+}
+
+void SenderHandle::close()
+{
+ session->closeSender(getName());
+}
+
+void SenderHandle::setCapacity(uint32_t capacity)
+{
+ connection->setCapacity(sender, capacity);
+}
+
+uint32_t SenderHandle::getCapacity()
+{
+ return connection->getCapacity(sender);
+}
+
+uint32_t SenderHandle::getUnsettled()
+{
+ return connection->getUnsettled(sender);
+}
+
+const std::string& SenderHandle::getName() const
+{
+ return sender->getName();
+}
+
+qpid::messaging::Session SenderHandle::getSession() const
+{
+ return qpid::messaging::Session(new SessionHandle(connection, session));
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/SenderHandle.h b/cpp/src/qpid/messaging/amqp/SenderHandle.h
new file mode 100644
index 0000000000..3c6b666582
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SenderHandle.h
@@ -0,0 +1,58 @@
+#ifndef QPID_MESSAGING_AMQP_SENDERHANDLE_H
+#define QPID_MESSAGING_AMQP_SENDERHANDLE_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <boost/shared_ptr.hpp>
+#include "qpid/messaging/SenderImpl.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+class ConnectionContext;
+class SessionContext;
+class SenderContext;
+/**
+ *
+ */
+class SenderHandle : public qpid::messaging::SenderImpl
+{
+ public:
+ SenderHandle(boost::shared_ptr<ConnectionContext> connection,
+ boost::shared_ptr<SessionContext> session,
+ boost::shared_ptr<SenderContext> sender
+ );
+ void send(const Message& message, bool sync);
+ void close();
+ void setCapacity(uint32_t);
+ uint32_t getCapacity();
+ uint32_t getUnsettled();
+ const std::string& getName() const;
+ Session getSession() const;
+ private:
+ boost::shared_ptr<ConnectionContext> connection;
+ boost::shared_ptr<SessionContext> session;
+ boost::shared_ptr<SenderContext> sender;
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_SENDERHANDLE_H*/
diff --git a/cpp/src/qpid/messaging/amqp/SessionContext.cpp b/cpp/src/qpid/messaging/amqp/SessionContext.cpp
new file mode 100644
index 0000000000..9bdc658bc7
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SessionContext.cpp
@@ -0,0 +1,156 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "SessionContext.h"
+#include "SenderContext.h"
+#include "ReceiverContext.h"
+#include <boost/format.hpp>
+#include "qpid/messaging/Address.h"
+#include "qpid/messaging/Duration.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/log/Statement.h"
+extern "C" {
+#include <proton/engine.h>
+}
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+SessionContext::SessionContext(pn_connection_t* connection) : session(pn_session(connection)) {}
+SessionContext::~SessionContext()
+{
+ senders.clear(); receivers.clear();
+ pn_session_free(session);
+}
+
+boost::shared_ptr<SenderContext> SessionContext::createSender(const qpid::messaging::Address& address)
+{
+ std::string name = address.getName();
+
+ int count = 1;
+ for (SenderMap::const_iterator i = senders.find(name); i != senders.end(); i = senders.find(name)) {
+ name = (boost::format("%1%_%2%") % address.getName() % ++count).str();
+ }
+ boost::shared_ptr<SenderContext> s(new SenderContext(session, name, address));
+ senders[name] = s;
+ return s;
+}
+
+boost::shared_ptr<ReceiverContext> SessionContext::createReceiver(const qpid::messaging::Address& address)
+{
+ std::string name = address.getName();
+
+ int count = 1;
+ for (ReceiverMap::const_iterator i = receivers.find(name); i != receivers.end(); i = receivers.find(name)) {
+ name = (boost::format("%1%_%2%") % address.getName() % ++count).str();
+ }
+ boost::shared_ptr<ReceiverContext> r(new ReceiverContext(session, name, address));
+ receivers[name] = r;
+ return r;
+}
+
+boost::shared_ptr<SenderContext> SessionContext::getSender(const std::string& name) const
+{
+ SenderMap::const_iterator i = senders.find(name);
+ if (i == senders.end()) {
+ throw qpid::messaging::KeyError(std::string("No such sender") + name);
+ } else {
+ return i->second;
+ }
+}
+
+boost::shared_ptr<ReceiverContext> SessionContext::getReceiver(const std::string& name) const
+{
+ ReceiverMap::const_iterator i = receivers.find(name);
+ if (i == receivers.end()) {
+ throw qpid::messaging::KeyError(std::string("No such receiver") + name);
+ } else {
+ return i->second;
+ }
+}
+
+void SessionContext::closeReceiver(const std::string&)
+{
+
+}
+
+void SessionContext::closeSender(const std::string&)
+{
+
+}
+
+boost::shared_ptr<ReceiverContext> SessionContext::nextReceiver(qpid::messaging::Duration /*timeout*/)
+{
+ return boost::shared_ptr<ReceiverContext>();
+}
+
+uint32_t SessionContext::getReceivable()
+{
+ return 0;//TODO
+}
+
+uint32_t SessionContext::getUnsettledAcks()
+{
+ return 0;//TODO
+}
+
+qpid::framing::SequenceNumber SessionContext::record(pn_delivery_t* delivery)
+{
+ qpid::framing::SequenceNumber id = next++;
+ unacked[id] = delivery;
+ QPID_LOG(debug, "Recorded delivery " << id << " -> " << delivery);
+ return id;
+}
+
+void SessionContext::acknowledge(DeliveryMap::iterator begin, DeliveryMap::iterator end)
+{
+ for (DeliveryMap::iterator i = begin; i != end; ++i) {
+ QPID_LOG(debug, "Setting disposition for delivery " << i->first << " -> " << i->second);
+ pn_delivery_update(i->second, PN_ACCEPTED);
+ pn_delivery_settle(i->second);//TODO: different settlement modes?
+ }
+ unacked.erase(begin, end);
+}
+
+void SessionContext::acknowledge()
+{
+ QPID_LOG(debug, "acknowledging all " << unacked.size() << " messages");
+ acknowledge(unacked.begin(), unacked.end());
+}
+
+void SessionContext::acknowledge(const qpid::framing::SequenceNumber& id, bool cumulative)
+{
+ DeliveryMap::iterator i = unacked.find(id);
+ if (i != unacked.end()) {
+ acknowledge(cumulative ? unacked.begin() : i, ++i);
+ }
+}
+
+bool SessionContext::settled()
+{
+ bool result = true;
+ for (SenderMap::iterator i = senders.begin(); i != senders.end(); ++i) {
+ if (!i->second->settled()) result = false;
+ }
+ return result;
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/SessionContext.h b/cpp/src/qpid/messaging/amqp/SessionContext.h
new file mode 100644
index 0000000000..eca30a0e97
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SessionContext.h
@@ -0,0 +1,81 @@
+#ifndef QPID_MESSAGING_AMQP_SESSIONCONTEXT_H
+#define QPID_MESSAGING_AMQP_SESSIONCONTEXT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <map>
+#include <string>
+#include <boost/shared_ptr.hpp>
+#include "qpid/sys/IntegerTypes.h"
+#include "qpid/framing/SequenceNumber.h"
+
+struct pn_connection_t;
+struct pn_session_t;
+struct pn_delivery_t;
+
+namespace qpid {
+namespace messaging {
+
+class Address;
+class Duration;
+
+namespace amqp {
+
+class ConnectionContext;
+class SenderContext;
+class ReceiverContext;
+/**
+ *
+ */
+class SessionContext
+{
+ public:
+ SessionContext(pn_connection_t*);
+ ~SessionContext();
+ boost::shared_ptr<SenderContext> createSender(const qpid::messaging::Address& address);
+ boost::shared_ptr<ReceiverContext> createReceiver(const qpid::messaging::Address& address);
+ boost::shared_ptr<SenderContext> getSender(const std::string& name) const;
+ boost::shared_ptr<ReceiverContext> getReceiver(const std::string& name) const;
+ void closeReceiver(const std::string&);
+ void closeSender(const std::string&);
+ boost::shared_ptr<ReceiverContext> nextReceiver(qpid::messaging::Duration timeout);
+ uint32_t getReceivable();
+ uint32_t getUnsettledAcks();
+ bool settled();
+ private:
+ friend class ConnectionContext;
+ typedef std::map<std::string, boost::shared_ptr<SenderContext> > SenderMap;
+ typedef std::map<std::string, boost::shared_ptr<ReceiverContext> > ReceiverMap;
+ typedef std::map<qpid::framing::SequenceNumber, pn_delivery_t*> DeliveryMap;
+ pn_session_t* session;
+ SenderMap senders;
+ ReceiverMap receivers;
+ DeliveryMap unacked;
+ qpid::framing::SequenceNumber next;
+
+ qpid::framing::SequenceNumber record(pn_delivery_t*);
+ void acknowledge();
+ void acknowledge(const qpid::framing::SequenceNumber& id, bool cummulative);
+ void acknowledge(DeliveryMap::iterator begin, DeliveryMap::iterator end);
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_SESSIONCONTEXT_H*/
diff --git a/cpp/src/qpid/messaging/amqp/SessionHandle.cpp b/cpp/src/qpid/messaging/amqp/SessionHandle.cpp
new file mode 100644
index 0000000000..bf79771ca4
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SessionHandle.cpp
@@ -0,0 +1,148 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "SessionHandle.h"
+#include "ConnectionContext.h"
+#include "ConnectionHandle.h"
+#include "ReceiverContext.h"
+#include "ReceiverHandle.h"
+#include "SenderContext.h"
+#include "SenderHandle.h"
+#include "SessionContext.h"
+#include "qpid/messaging/Connection.h"
+#include "qpid/messaging/Duration.h"
+#include "qpid/messaging/exceptions.h"
+#include "qpid/messaging/Receiver.h"
+#include "qpid/messaging/Sender.h"
+#include "qpid/messaging/Session.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+SessionHandle::SessionHandle(boost::shared_ptr<ConnectionContext> c, boost::shared_ptr<SessionContext> s) : connection(c), session(s) {}
+
+void SessionHandle::commit()
+{
+
+}
+
+void SessionHandle::rollback()
+{
+
+}
+
+void SessionHandle::acknowledge(bool /*sync*/)
+{
+ connection->acknowledge(session, 0, false);
+}
+
+void SessionHandle::acknowledge(qpid::messaging::Message& msg, bool cumulative)
+{
+ //TODO: handle cumulative
+ connection->acknowledge(session, &msg, cumulative);
+}
+
+void SessionHandle::reject(qpid::messaging::Message&)
+{
+
+}
+
+void SessionHandle::release(qpid::messaging::Message&)
+{
+
+}
+
+void SessionHandle::close()
+{
+ connection->endSession(session);
+}
+
+void SessionHandle::sync(bool /*block*/)
+{
+
+}
+
+qpid::messaging::Sender SessionHandle::createSender(const qpid::messaging::Address& address)
+{
+ boost::shared_ptr<SenderContext> sender = session->createSender(address);
+ connection->attach(session, sender);
+ return qpid::messaging::Sender(new SenderHandle(connection, session, sender));
+}
+
+qpid::messaging::Receiver SessionHandle::createReceiver(const qpid::messaging::Address& address)
+{
+ boost::shared_ptr<ReceiverContext> receiver = session->createReceiver(address);
+ connection->attach(session, receiver);
+ return qpid::messaging::Receiver(new ReceiverHandle(connection, session, receiver));
+}
+
+bool SessionHandle::nextReceiver(Receiver& receiver, Duration timeout)
+{
+ boost::shared_ptr<ReceiverContext> r = session->nextReceiver(timeout);
+ if (r) {
+ //TODO: cache handles in this case to avoid frequent allocation
+ receiver = qpid::messaging::Receiver(new ReceiverHandle(connection, session, r));
+ return true;
+ } else {
+ return false;
+ }
+}
+
+qpid::messaging::Receiver SessionHandle::nextReceiver(Duration timeout)
+{
+ qpid::messaging::Receiver r;
+ if (nextReceiver(r, timeout)) return r;
+ else throw qpid::messaging::NoMessageAvailable();
+}
+
+uint32_t SessionHandle::getReceivable()
+{
+ return session->getReceivable();
+}
+
+uint32_t SessionHandle::getUnsettledAcks()
+{
+ return session->getUnsettledAcks();
+}
+
+Sender SessionHandle::getSender(const std::string& name) const
+{
+ return qpid::messaging::Sender(new SenderHandle(connection, session, session->getSender(name)));
+}
+
+Receiver SessionHandle::getReceiver(const std::string& name) const
+{
+ return qpid::messaging::Receiver(new ReceiverHandle(connection, session, session->getReceiver(name)));
+}
+
+Connection SessionHandle::getConnection() const
+{
+ return qpid::messaging::Connection(new ConnectionHandle(connection));
+}
+
+void SessionHandle::checkError()
+{
+
+}
+
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/SessionHandle.h b/cpp/src/qpid/messaging/amqp/SessionHandle.h
new file mode 100644
index 0000000000..5e843aaacc
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SessionHandle.h
@@ -0,0 +1,64 @@
+#ifndef QPID_MESSAGING_AMQP_SESSIONIMPL_H
+#define QPID_MESSAGING_AMQP_SESSIONIMPL_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <boost/shared_ptr.hpp>
+#include "qpid/messaging/SessionImpl.h"
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+class ConnectionContext;
+class SessionContext;
+/**
+ *
+ */
+class SessionHandle : public qpid::messaging::SessionImpl
+{
+ public:
+ SessionHandle(boost::shared_ptr<ConnectionContext>, boost::shared_ptr<SessionContext>);
+ void commit();
+ void rollback();
+ void acknowledge(bool sync);
+ void acknowledge(Message&, bool);
+ void reject(Message&);
+ void release(Message&);
+ void close();
+ void sync(bool block);
+ qpid::messaging::Sender createSender(const Address& address);
+ qpid::messaging::Receiver createReceiver(const Address& address);
+ bool nextReceiver(Receiver& receiver, Duration timeout);
+ qpid::messaging::Receiver nextReceiver(Duration timeout);
+ uint32_t getReceivable();
+ uint32_t getUnsettledAcks();
+ qpid::messaging::Sender getSender(const std::string& name) const;
+ qpid::messaging::Receiver getReceiver(const std::string& name) const;
+ qpid::messaging::Connection getConnection() const;
+ void checkError();
+ private:
+ boost::shared_ptr<ConnectionContext> connection;
+ boost::shared_ptr<SessionContext> session;
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_SESSIONIMPL_H*/
diff --git a/cpp/src/qpid/messaging/amqp/SslTransport.cpp b/cpp/src/qpid/messaging/amqp/SslTransport.cpp
new file mode 100644
index 0000000000..ea2375cb26
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SslTransport.cpp
@@ -0,0 +1,160 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "SslTransport.h"
+#include "TransportContext.h"
+#include "qpid/sys/ssl/SslSocket.h"
+#include "qpid/sys/AsynchIO.h"
+#include "qpid/sys/ConnectionCodec.h"
+#include "qpid/sys/Poller.h"
+#include "qpid/log/Statement.h"
+#include <boost/bind.hpp>
+#include <boost/format.hpp>
+
+using namespace qpid::sys;
+using namespace qpid::sys::ssl;
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+
+// Static constructor which registers connector here
+namespace {
+Transport* create(TransportContext& c, Poller::shared_ptr p)
+{
+ return new SslTransport(c, p);
+}
+
+struct StaticInit
+{
+ StaticInit()
+ {
+ Transport::add("ssl", &create);
+ };
+} init;
+}
+
+
+SslTransport::SslTransport(TransportContext& c, boost::shared_ptr<Poller> p) : context(c), connector(0), aio(0), poller(p) {}
+
+void SslTransport::connect(const std::string& host, const std::string& port)
+{
+ assert(!connector);
+ assert(!aio);
+ connector = AsynchConnector::create(
+ socket,
+ host, port,
+ boost::bind(&SslTransport::connected, this, _1),
+ boost::bind(&SslTransport::failed, this, _3));
+
+ connector->start(poller);
+}
+
+void SslTransport::failed(const std::string& msg)
+{
+ QPID_LOG(debug, "Failed to connect: " << msg);
+ socket.close();
+ context.closed();
+}
+
+void SslTransport::connected(const Socket&)
+{
+ context.opened();
+ aio = AsynchIO::create(socket,
+ boost::bind(&SslTransport::read, this, _1, _2),
+ boost::bind(&SslTransport::eof, this, _1),
+ boost::bind(&SslTransport::disconnected, this, _1),
+ boost::bind(&SslTransport::socketClosed, this, _1, _2),
+ 0, // nobuffs
+ boost::bind(&SslTransport::write, this, _1));
+ aio->createBuffers(std::numeric_limits<uint16_t>::max());//note: AMQP 1.0 _can_ handle large frame sizes
+ id = boost::str(boost::format("[%1%]") % socket.getFullAddress());
+ aio->start(poller);
+}
+
+void SslTransport::read(AsynchIO&, AsynchIO::BufferBase* buffer)
+{
+ int32_t decoded = context.getCodec().decode(buffer->bytes+buffer->dataStart, buffer->dataCount);
+ if (decoded < buffer->dataCount) {
+ // Adjust buffer for used bytes and then "unread them"
+ buffer->dataStart += decoded;
+ buffer->dataCount -= decoded;
+ aio->unread(buffer);
+ } else {
+ // Give whole buffer back to aio subsystem
+ aio->queueReadBuffer(buffer);
+ }
+}
+
+void SslTransport::write(AsynchIO&)
+{
+ if (context.getCodec().canEncode()) {
+ AsynchIO::BufferBase* buffer = aio->getQueuedBuffer();
+ if (buffer) {
+ size_t encoded = context.getCodec().encode(buffer->bytes, buffer->byteCount);
+
+ buffer->dataStart = 0;
+ buffer->dataCount = encoded;
+ aio->queueWrite(buffer);
+ }
+ }
+
+}
+
+void SslTransport::close()
+{
+ QPID_LOG(debug, id << " SslTransport closing...");
+ if (aio)
+ aio->queueWriteClose();
+}
+
+void SslTransport::eof(AsynchIO&)
+{
+ close();
+}
+
+void SslTransport::disconnected(AsynchIO&)
+{
+ close();
+ socketClosed(*aio, socket);
+}
+
+void SslTransport::socketClosed(AsynchIO&, const Socket&)
+{
+ if (aio)
+ aio->queueForDeletion();
+ context.closed();
+ QPID_LOG(debug, id << " Socket closed");
+}
+
+void SslTransport::abort()
+{
+ if (aio) {
+ // Established connection
+ aio->requestCallback(boost::bind(&SslTransport::eof, this, _1));
+ }
+}
+
+void SslTransport::activateOutput()
+{
+ if (aio) aio->notifyPendingWrite();
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/SslTransport.h b/cpp/src/qpid/messaging/amqp/SslTransport.h
new file mode 100644
index 0000000000..f67ab95673
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/SslTransport.h
@@ -0,0 +1,74 @@
+#ifndef QPID_MESSAGING_AMQP_SSLTRANSPORT_H
+#define QPID_MESSAGING_AMQP_SSLTRANSPORT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/messaging/amqp/Transport.h"
+#include "qpid/sys/Mutex.h"
+#include "qpid/sys/ssl/SslSocket.h"
+#include <boost/shared_ptr.hpp>
+
+namespace qpid {
+namespace sys {
+class ConnectionCodec;
+class Poller;
+class AsynchConnector;
+class AsynchIO;
+class AsynchIOBufferBase;
+}
+
+namespace messaging {
+namespace amqp {
+class TransportContext;
+
+class SslTransport : public Transport
+{
+ public:
+ SslTransport(TransportContext&, boost::shared_ptr<qpid::sys::Poller> p);
+
+ void connect(const std::string& host, const std::string& port);
+
+ void activateOutput();
+ void abort();
+ void close();
+
+ private:
+ qpid::sys::ssl::SslSocket socket;
+ TransportContext& context;
+ qpid::sys::AsynchConnector* connector;
+ qpid::sys::AsynchIO* aio;
+ boost::shared_ptr<qpid::sys::Poller> poller;
+ bool closed;
+ std::string id;
+
+ void connected(const qpid::sys::Socket&);
+ void failed(const std::string& msg);
+ void read(qpid::sys::AsynchIO&, qpid::sys::AsynchIOBufferBase*);
+ void write(qpid::sys::AsynchIO&);
+ void eof(qpid::sys::AsynchIO&);
+ void disconnected(qpid::sys::AsynchIO&);
+ void socketClosed(qpid::sys::AsynchIO&, const qpid::sys::Socket&);
+
+ friend class DriverImpl;
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_SSLTRANSPORT_H*/
diff --git a/cpp/src/qpid/messaging/amqp/TcpTransport.cpp b/cpp/src/qpid/messaging/amqp/TcpTransport.cpp
new file mode 100644
index 0000000000..98022d634c
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/TcpTransport.cpp
@@ -0,0 +1,162 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "TcpTransport.h"
+#include "ConnectionContext.h"
+#include "qpid/sys/AsynchIO.h"
+#include "qpid/sys/ConnectionCodec.h"
+#include "qpid/sys/Poller.h"
+#include "qpid/log/Statement.h"
+#include <boost/bind.hpp>
+#include <boost/format.hpp>
+
+using namespace qpid::sys;
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+// Static constructor which registers connector here
+namespace {
+Transport* create(TransportContext& c, Poller::shared_ptr p)
+{
+ return new TcpTransport(c, p);
+}
+
+struct StaticInit
+{
+ StaticInit()
+ {
+ Transport::add("tcp", &create);
+ };
+} init;
+}
+
+TcpTransport::TcpTransport(TransportContext& c, boost::shared_ptr<Poller> p) : socket(createSocket()), context(c), connector(0), aio(0), poller(p) {}
+
+void TcpTransport::connect(const std::string& host, const std::string& port)
+{
+ assert(!connector);
+ assert(!aio);
+ connector = AsynchConnector::create(
+ *socket,
+ host, port,
+ boost::bind(&TcpTransport::connected, this, _1),
+ boost::bind(&TcpTransport::failed, this, _3));
+
+ connector->start(poller);
+}
+
+void TcpTransport::failed(const std::string& msg)
+{
+ QPID_LOG(debug, "Failed to connect: " << msg);
+ connector = 0;
+ socket->close();
+ context.closed();
+}
+
+void TcpTransport::connected(const Socket&)
+{
+ context.opened();
+ connector = 0;
+ aio = AsynchIO::create(*socket,
+ boost::bind(&TcpTransport::read, this, _1, _2),
+ boost::bind(&TcpTransport::eof, this, _1),
+ boost::bind(&TcpTransport::disconnected, this, _1),
+ boost::bind(&TcpTransport::socketClosed, this, _1, _2),
+ 0, // nobuffs
+ boost::bind(&TcpTransport::write, this, _1));
+ aio->createBuffers(std::numeric_limits<uint16_t>::max());//note: AMQP 1.0 _can_ handle large frame sizes
+ id = boost::str(boost::format("[%1%]") % socket->getFullAddress());
+ aio->start(poller);
+}
+
+void TcpTransport::read(AsynchIO&, AsynchIO::BufferBase* buffer)
+{
+ int32_t decoded = context.getCodec().decode(buffer->bytes+buffer->dataStart, buffer->dataCount);
+ if (decoded < buffer->dataCount) {
+ // Adjust buffer for used bytes and then "unread them"
+ buffer->dataStart += decoded;
+ buffer->dataCount -= decoded;
+ aio->unread(buffer);
+ } else {
+ // Give whole buffer back to aio subsystem
+ aio->queueReadBuffer(buffer);
+ }
+}
+
+void TcpTransport::write(AsynchIO&)
+{
+ if (context.getCodec().canEncode()) {
+ AsynchIO::BufferBase* buffer = aio->getQueuedBuffer();
+ if (buffer) {
+ size_t encoded = context.getCodec().encode(buffer->bytes, buffer->byteCount);
+
+ buffer->dataStart = 0;
+ buffer->dataCount = encoded;
+ aio->queueWrite(buffer);
+ }
+ }
+
+}
+
+void TcpTransport::close()
+{
+ QPID_LOG(debug, id << " TcpTransport closing...");
+ if (aio)
+ aio->queueWriteClose();
+}
+
+void TcpTransport::eof(AsynchIO&)
+{
+ close();
+}
+
+void TcpTransport::disconnected(AsynchIO&)
+{
+ close();
+ socketClosed(*aio, *socket);
+}
+
+void TcpTransport::socketClosed(AsynchIO&, const Socket&)
+{
+ if (aio)
+ aio->queueForDeletion();
+ context.closed();
+ QPID_LOG(debug, id << " Socket closed");
+}
+
+void TcpTransport::abort()
+{
+ if (aio) {
+ // Established connection
+ aio->requestCallback(boost::bind(&TcpTransport::eof, this, _1));
+ } else if (connector) {
+ // We're still connecting
+ connector->stop();
+ failed("Connection timedout");
+ }
+}
+
+void TcpTransport::activateOutput()
+{
+ if (aio) aio->notifyPendingWrite();
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/TcpTransport.h b/cpp/src/qpid/messaging/amqp/TcpTransport.h
new file mode 100644
index 0000000000..8c1087abb3
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/TcpTransport.h
@@ -0,0 +1,71 @@
+#ifndef QPID_MESSAGING_AMQP_TCPTRANSPORT_H
+#define QPID_MESSAGING_AMQP_TCPTRANSPORT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/messaging/amqp/Transport.h"
+#include "qpid/sys/Mutex.h"
+#include "qpid/sys/Socket.h"
+#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
+
+namespace qpid {
+namespace sys {
+class ConnectionCodec;
+class AsynchConnector;
+class AsynchIO;
+class AsynchIOBufferBase;
+class Poller;
+}
+namespace messaging {
+namespace amqp {
+class TransportContext;
+
+class TcpTransport : public Transport
+{
+ public:
+ TcpTransport(TransportContext&, boost::shared_ptr<qpid::sys::Poller>);
+
+ void connect(const std::string& host, const std::string& port);
+
+ void activateOutput();
+ void abort();
+ void close();
+
+ private:
+ boost::scoped_ptr<qpid::sys::Socket> socket;
+ TransportContext& context;
+ qpid::sys::AsynchConnector* connector;
+ qpid::sys::AsynchIO* aio;
+ boost::shared_ptr<qpid::sys::Poller> poller;
+ std::string id;
+
+ void connected(const qpid::sys::Socket&);
+ void failed(const std::string& msg);
+ void read(qpid::sys::AsynchIO&, qpid::sys::AsynchIOBufferBase*);
+ void write(qpid::sys::AsynchIO&);
+ void eof(qpid::sys::AsynchIO&);
+ void disconnected(qpid::sys::AsynchIO&);
+ void socketClosed(qpid::sys::AsynchIO&, const qpid::sys::Socket&);
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_TCPTRANSPORT_H*/
diff --git a/cpp/src/qpid/messaging/amqp/Transport.cpp b/cpp/src/qpid/messaging/amqp/Transport.cpp
new file mode 100644
index 0000000000..21f51046b1
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/Transport.cpp
@@ -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.
+ *
+ */
+#include "qpid/messaging/amqp/Transport.h"
+#include "qpid/messaging/amqp/TransportContext.h"
+#include <map>
+#include <string>
+
+namespace qpid {
+namespace messaging {
+namespace amqp {
+namespace {
+typedef std::map<std::string, Transport::Factory*> Registry;
+
+Registry& theRegistry()
+{
+ static Registry factories;
+ return factories;
+}
+}
+
+Transport* Transport::create(const std::string& name, TransportContext& context, boost::shared_ptr<qpid::sys::Poller> poller)
+{
+ Registry::const_iterator i = theRegistry().find(name);
+ if (i != theRegistry().end()) return (i->second)(context, poller);
+ else return 0;
+}
+void Transport::add(const std::string& name, Factory* factory)
+{
+ theRegistry()[name] = factory;
+}
+
+}}} // namespace qpid::messaging::amqp
diff --git a/cpp/src/qpid/messaging/amqp/Transport.h b/cpp/src/qpid/messaging/amqp/Transport.h
new file mode 100644
index 0000000000..ee021f645b
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/Transport.h
@@ -0,0 +1,48 @@
+#ifndef QPID_MESSAGING_AMQP_TRANSPORT_H
+#define QPID_MESSAGING_AMQP_TRANSPORT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/sys/OutputControl.h"
+#include <boost/shared_ptr.hpp>
+
+namespace qpid {
+namespace sys {
+class Poller;
+}
+namespace messaging {
+namespace amqp {
+class TransportContext;
+
+class Transport : public qpid::sys::OutputControl
+{
+ public:
+ virtual ~Transport() {}
+ virtual void connect(const std::string& host, const std::string& port) = 0;
+ virtual void close() = 0;
+
+ typedef Transport* Factory(TransportContext&, boost::shared_ptr<qpid::sys::Poller>);
+ static Transport* create(const std::string& name, TransportContext&, boost::shared_ptr<qpid::sys::Poller>);
+ static void add(const std::string& name, Factory* factory);
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_TRANSPORT_H*/
diff --git a/cpp/src/qpid/messaging/amqp/TransportContext.h b/cpp/src/qpid/messaging/amqp/TransportContext.h
new file mode 100644
index 0000000000..57192b5976
--- /dev/null
+++ b/cpp/src/qpid/messaging/amqp/TransportContext.h
@@ -0,0 +1,47 @@
+#ifndef QPID_MESSAGING_AMQP_TRANSPORTCONTEXT_H
+#define QPID_MESSAGING_AMQP_TRANSPORTCONTEXT_H
+
+/*
+ *
+ * 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.
+ *
+ */
+namespace qpid {
+namespace sys {
+class Codec;
+}
+namespace messaging {
+namespace amqp {
+
+/**
+ * Interface to be supplied by 'users' of Transport interface, in
+ * order to provide codec and handle callbaskc for opening and closing
+ * of connection.
+ */
+class TransportContext
+{
+ public:
+ virtual ~TransportContext() {}
+ virtual qpid::sys::Codec& getCodec() = 0;
+ virtual void closed() = 0;
+ virtual void opened() = 0;
+ private:
+};
+}}} // namespace qpid::messaging::amqp
+
+#endif /*!QPID_MESSAGING_AMQP_TRANSPORTCONTEXT_H*/
diff --git a/cpp/src/qpid/store/CMakeLists.txt b/cpp/src/qpid/store/CMakeLists.txt
index 9abdf0ae3d..31623f8e84 100644
--- a/cpp/src/qpid/store/CMakeLists.txt
+++ b/cpp/src/qpid/store/CMakeLists.txt
@@ -42,6 +42,7 @@ if (CMAKE_COMPILER_IS_GNUCXX)
set_target_properties (store PROPERTIES
PREFIX ""
+ COMPILE_DEFINITIONS _IN_QPID_BROKER
LINK_FLAGS "${GCC_CATCH_UNDEFINED}")
endif (CMAKE_COMPILER_IS_GNUCXX)
@@ -54,7 +55,9 @@ if (CMAKE_SYSTEM_NAME STREQUAL Windows)
endif (MSVC)
endif (CMAKE_SYSTEM_NAME STREQUAL Windows)
-set_target_properties (store PROPERTIES VERSION ${qpidc_version})
+set_target_properties (store PROPERTIES
+ COMPILE_DEFINITIONS _IN_QPID_BROKER
+ VERSION ${qpidc_version})
install (TARGETS store # RUNTIME
DESTINATION ${QPIDD_MODULE_DIR}
COMPONENT ${QPID_COMPONENT_BROKER})
@@ -81,6 +84,7 @@ if (BUILD_MSSQL)
ms-sql/State.cpp
ms-sql/TplRecordset.cpp
ms-sql/VariantHelper.cpp)
+ set_target_properties (mssql_store PROPERTIES COMPILE_DEFINITIONS _IN_QPID_BROKER)
target_link_libraries (mssql_store qpidbroker qpidcommon ${Boost_PROGRAM_OPTIONS_LIBRARY})
install (TARGETS mssql_store # RUNTIME
DESTINATION ${QPIDD_MODULE_DIR}
@@ -110,6 +114,7 @@ if (BUILD_MSCLFS)
ms-sql/State.cpp
ms-sql/VariantHelper.cpp)
include_directories(ms-sql)
+ set_target_properties (msclfs_store PROPERTIES COMPILE_DEFINITIONS _IN_QPID_BROKER)
target_link_libraries (msclfs_store qpidbroker qpidcommon ${Boost_PROGRAM_OPTIONS_LIBRARY} clfsw32.lib)
install (TARGETS msclfs_store # RUNTIME
DESTINATION ${QPIDD_MODULE_DIR}
diff --git a/cpp/src/qpid/store/MessageStorePlugin.cpp b/cpp/src/qpid/store/MessageStorePlugin.cpp
index d72200c2ba..b869ecadbc 100644
--- a/cpp/src/qpid/store/MessageStorePlugin.cpp
+++ b/cpp/src/qpid/store/MessageStorePlugin.cpp
@@ -137,12 +137,6 @@ MessageStorePlugin::providerAvailable(const std::string name,
QPID_LOG(warning, "Storage provider " << name << " duplicate; ignored.");
}
-void
-MessageStorePlugin::truncateInit(const bool /*saveStoreContent*/)
-{
- QPID_LOG(info, "Store: truncateInit");
-}
-
/**
* Record the existence of a durable queue
diff --git a/cpp/src/qpid/store/MessageStorePlugin.h b/cpp/src/qpid/store/MessageStorePlugin.h
index 4a9bb2aecb..1fcde6683d 100644
--- a/cpp/src/qpid/store/MessageStorePlugin.h
+++ b/cpp/src/qpid/store/MessageStorePlugin.h
@@ -24,18 +24,22 @@
#include "qpid/Plugin.h"
#include "qpid/Options.h"
-#include "qpid/broker/Broker.h"
#include "qpid/broker/MessageStore.h"
-#include "qpid/broker/PersistableExchange.h"
-#include "qpid/broker/PersistableMessage.h"
-#include "qpid/broker/PersistableQueue.h"
-#include "qpid/management/Manageable.h"
+//#include "qpid/management/Manageable.h"
#include <string>
using namespace qpid;
namespace qpid {
+
+namespace broker {
+class Broker;
+class PersistableExchange;
+class PersistableMessage;
+class PersistableQueue;
+}
+
namespace store {
class StorageProvider;
@@ -82,18 +86,6 @@ class MessageStorePlugin :
/**
* @name Methods inherited from qpid::broker::MessageStore
*/
- //@{
- /**
- * If called before recovery, will discard the database and reinitialize
- * using an empty store. This is used when cluster nodes recover and
- * must get their content from a cluster sync rather than directly from
- * the store.
- *
- * @param saveStoreContent If true, the store's contents should be
- * saved to a backup location before
- * reinitializing the store content.
- */
- virtual void truncateInit(const bool saveStoreContent = false);
/**
* Record the existence of a durable queue
diff --git a/cpp/src/qpid/store/StorageProvider.h b/cpp/src/qpid/store/StorageProvider.h
index d162cc58ec..de12ffb869 100644
--- a/cpp/src/qpid/store/StorageProvider.h
+++ b/cpp/src/qpid/store/StorageProvider.h
@@ -143,20 +143,6 @@ public:
/**
* @name Methods inherited from qpid::broker::MessageStore
*/
- //@{
- /**
- * If called after init() but before recovery, will discard the database
- * and reinitialize using an empty store dir. If @a pushDownStoreFiles
- * is true, the content of the store dir will be moved to a backup dir
- * inside the store dir. This is used when cluster nodes recover and must
- * get thier content from a cluster sync rather than directly fromt the
- * store.
- *
- * @param pushDownStoreFiles If true, will move content of the store dir
- * into a subdir, leaving the store dir
- * otherwise empty.
- */
- virtual void truncateInit(const bool pushDownStoreFiles = false) = 0;
/**
* Record the existence of a durable queue
diff --git a/cpp/src/qpid/store/ms-clfs/MSSqlClfsProvider.cpp b/cpp/src/qpid/store/ms-clfs/MSSqlClfsProvider.cpp
index 586aaaf980..90785263d3 100644
--- a/cpp/src/qpid/store/ms-clfs/MSSqlClfsProvider.cpp
+++ b/cpp/src/qpid/store/ms-clfs/MSSqlClfsProvider.cpp
@@ -26,6 +26,7 @@
#include <string>
#include <windows.h>
#include <clfsw32.h>
+#include <qpid/broker/Broker.h>
#include <qpid/broker/RecoverableQueue.h>
#include <qpid/log/Statement.h>
#include <qpid/store/MessageStorePlugin.h>
@@ -108,20 +109,6 @@ public:
/**
* @name Methods inherited from qpid::broker::MessageStore
*/
- //@{
- /**
- * If called after init() but before recovery, will discard the database
- * and reinitialize using an empty store dir. If @a pushDownStoreFiles
- * is true, the content of the store dir will be moved to a backup dir
- * inside the store dir. This is used when cluster nodes recover and must
- * get their content from a cluster sync rather than directly from the
- * store.
- *
- * @param pushDownStoreFiles If true, will move content of the store dir
- * into a subdir, leaving the store dir
- * otherwise empty.
- */
- virtual void truncateInit(const bool pushDownStoreFiles = false);
/**
* Record the existence of a durable queue
@@ -467,11 +454,6 @@ MSSqlClfsProvider::activate(MessageStorePlugin &store)
}
void
-MSSqlClfsProvider::truncateInit(const bool pushDownStoreFiles)
-{
-}
-
-void
MSSqlClfsProvider::create(PersistableQueue& queue,
const qpid::framing::FieldTable& /*args needed for jrnl*/)
{
diff --git a/cpp/src/qpid/store/ms-sql/MSSqlProvider.cpp b/cpp/src/qpid/store/ms-sql/MSSqlProvider.cpp
index 7f22db3d02..1432cc8fca 100644
--- a/cpp/src/qpid/store/ms-sql/MSSqlProvider.cpp
+++ b/cpp/src/qpid/store/ms-sql/MSSqlProvider.cpp
@@ -92,20 +92,6 @@ public:
/**
* @name Methods inherited from qpid::broker::MessageStore
*/
- //@{
- /**
- * If called after init() but before recovery, will discard the database
- * and reinitialize using an empty store dir. If @a pushDownStoreFiles
- * is true, the content of the store dir will be moved to a backup dir
- * inside the store dir. This is used when cluster nodes recover and must
- * get thier content from a cluster sync rather than directly fromt the
- * store.
- *
- * @param pushDownStoreFiles If true, will move content of the store dir
- * into a subdir, leaving the store dir
- * otherwise empty.
- */
- virtual void truncateInit(const bool pushDownStoreFiles = false);
/**
* Record the existence of a durable queue
@@ -392,11 +378,6 @@ MSSqlProvider::activate(MessageStorePlugin &store)
}
void
-MSSqlProvider::truncateInit(const bool pushDownStoreFiles)
-{
-}
-
-void
MSSqlProvider::create(PersistableQueue& queue,
const qpid::framing::FieldTable& /*args needed for jrnl*/)
{
diff --git a/cpp/src/qpid/store/ms-sql/MessageRecordset.cpp b/cpp/src/qpid/store/ms-sql/MessageRecordset.cpp
index b62a333df6..495f1a08c2 100644
--- a/cpp/src/qpid/store/ms-sql/MessageRecordset.cpp
+++ b/cpp/src/qpid/store/ms-sql/MessageRecordset.cpp
@@ -147,7 +147,7 @@ MessageRecordset::recover(qpid::broker::RecoveryManager& recoverer,
// Now, do we need the rest of the content?
long contentLength = blobSize - headerFieldLength - headerSize;
- if (msg->loadContent(contentLength)) {
+ if (contentLength > 0 && msg->loadContent(contentLength)) {
BlobAdapter content(contentLength);
content =
rs->Fields->Item["fieldTableBlob"]->GetChunk(contentLength);
diff --git a/cpp/src/qpid/sys/AggregateOutput.cpp b/cpp/src/qpid/sys/AggregateOutput.cpp
index fc95f46fb9..ebc5689ce5 100644
--- a/cpp/src/qpid/sys/AggregateOutput.cpp
+++ b/cpp/src/qpid/sys/AggregateOutput.cpp
@@ -32,8 +32,6 @@ void AggregateOutput::abort() { control.abort(); }
void AggregateOutput::activateOutput() { control.activateOutput(); }
-void AggregateOutput::giveReadCredit(int32_t credit) { control.giveReadCredit(credit); }
-
namespace {
// Clear the busy flag and notify waiting threads in destructor.
struct ScopedBusy {
@@ -51,6 +49,7 @@ bool AggregateOutput::doOutput() {
while (!tasks.empty()) {
OutputTask* t=tasks.front();
tasks.pop_front();
+ taskSet.erase(t);
bool didOutput;
{
// Allow concurrent call to addOutputTask.
@@ -59,7 +58,9 @@ bool AggregateOutput::doOutput() {
didOutput = t->doOutput();
}
if (didOutput) {
- tasks.push_back(t);
+ if (taskSet.insert(t).second) {
+ tasks.push_back(t);
+ }
return true;
}
}
@@ -68,12 +69,15 @@ bool AggregateOutput::doOutput() {
void AggregateOutput::addOutputTask(OutputTask* task) {
Mutex::ScopedLock l(lock);
- tasks.push_back(task);
+ if (taskSet.insert(task).second) {
+ tasks.push_back(task);
+ }
}
void AggregateOutput::removeOutputTask(OutputTask* task) {
Mutex::ScopedLock l(lock);
while (busy) lock.wait();
+ taskSet.erase(task);
tasks.erase(std::remove(tasks.begin(), tasks.end(), task), tasks.end());
}
@@ -81,6 +85,7 @@ void AggregateOutput::removeAll()
{
Mutex::ScopedLock l(lock);
while (busy) lock.wait();
+ taskSet.clear();
tasks.clear();
}
diff --git a/cpp/src/qpid/sys/AggregateOutput.h b/cpp/src/qpid/sys/AggregateOutput.h
index d7c0ff29e3..e9dbd5a4cc 100644
--- a/cpp/src/qpid/sys/AggregateOutput.h
+++ b/cpp/src/qpid/sys/AggregateOutput.h
@@ -28,6 +28,7 @@
#include <algorithm>
#include <deque>
+#include <set>
namespace qpid {
namespace sys {
@@ -44,9 +45,11 @@ namespace sys {
class QPID_COMMON_CLASS_EXTERN AggregateOutput : public OutputTask, public OutputControl
{
typedef std::deque<OutputTask*> TaskList;
+ typedef std::set<OutputTask*> TaskSet;
Monitor lock;
TaskList tasks;
+ TaskSet taskSet;
bool busy;
OutputControl& control;
@@ -56,7 +59,6 @@ class QPID_COMMON_CLASS_EXTERN AggregateOutput : public OutputTask, public Outpu
// These may be called concurrently with any function.
QPID_COMMON_EXTERN void abort();
QPID_COMMON_EXTERN void activateOutput();
- QPID_COMMON_EXTERN void giveReadCredit(int32_t);
QPID_COMMON_EXTERN void addOutputTask(OutputTask* t);
// These functions must not be called concurrently with each other.
diff --git a/cpp/src/qpid/sys/AsynchIO.h b/cpp/src/qpid/sys/AsynchIO.h
index b2eaaac9de..679665f8ad 100644
--- a/cpp/src/qpid/sys/AsynchIO.h
+++ b/cpp/src/qpid/sys/AsynchIO.h
@@ -21,9 +21,11 @@
*
*/
-#include "qpid/sys/IntegerTypes.h"
#include "qpid/CommonImportExport.h"
+#include "qpid/sys/IntegerTypes.h"
+#include "qpid/sys/SecuritySettings.h"
+
#include <string.h>
#include <boost/function.hpp>
@@ -56,6 +58,7 @@ class AsynchConnector {
public:
typedef boost::function1<void, const Socket&> ConnectedCallback;
typedef boost::function3<void, const Socket&, int, const std::string&> FailedCallback;
+ typedef boost::function1<void, AsynchConnector&> RequestCallback;
// Call create() to allocate a new AsynchConnector object with the
// specified poller, addressing, and callbacks.
@@ -70,6 +73,7 @@ public:
FailedCallback failCb);
virtual void start(boost::shared_ptr<Poller> poller) = 0;
virtual void stop() {};
+ virtual void requestCallback(RequestCallback) = 0;
protected:
AsynchConnector() {}
virtual ~AsynchConnector() {}
@@ -155,11 +159,11 @@ public:
virtual void notifyPendingWrite() = 0;
virtual void queueWriteClose() = 0;
virtual bool writeQueueEmpty() = 0;
- virtual void startReading() = 0;
- virtual void stopReading() = 0;
virtual void requestCallback(RequestCallback) = 0;
virtual BufferBase* getQueuedBuffer() = 0;
+ virtual SecuritySettings getSecuritySettings() = 0;
+
protected:
// Derived class manages lifetime; must be constructed using the
// static create() method. Deletes not allowed from outside.
diff --git a/cpp/src/qpid/sys/AsynchIOHandler.cpp b/cpp/src/qpid/sys/AsynchIOHandler.cpp
index 2e117a3fb7..cf08b482e6 100644
--- a/cpp/src/qpid/sys/AsynchIOHandler.cpp
+++ b/cpp/src/qpid/sys/AsynchIOHandler.cpp
@@ -51,15 +51,15 @@ struct ProtocolTimeoutTask : public sys::TimerTask {
}
};
-AsynchIOHandler::AsynchIOHandler(const std::string& id, ConnectionCodec::Factory* f) :
+AsynchIOHandler::AsynchIOHandler(const std::string& id, ConnectionCodec::Factory* f, bool isClient0, bool nodict0) :
identifier(id),
aio(0),
factory(f),
codec(0),
reads(0),
readError(false),
- isClient(false),
- readCredit(InfiniteCredit)
+ isClient(isClient0),
+ nodict(nodict0)
{}
AsynchIOHandler::~AsynchIOHandler() {
@@ -97,25 +97,20 @@ void AsynchIOHandler::abort() {
if (!readError) {
aio->requestCallback(boost::bind(&AsynchIOHandler::eof, this, _1));
}
+ aio->queueWriteClose();
}
void AsynchIOHandler::activateOutput() {
aio->notifyPendingWrite();
}
-// Input side
-void AsynchIOHandler::giveReadCredit(int32_t credit) {
- // Check whether we started in the don't about credit state
- if (readCredit.boolCompareAndSwap(InfiniteCredit, credit))
- return;
- // TODO In theory should be able to use an atomic operation before taking the lock
- // but in practice there seems to be an unexplained race in that case
- ScopedLock<Mutex> l(creditLock);
- if (readCredit.fetchAndAdd(credit) != 0)
- return;
- assert(readCredit.get() >= 0);
- if (readCredit.get() != 0)
- aio->startReading();
+namespace {
+ SecuritySettings getSecuritySettings(AsynchIO* aio, bool nodict)
+ {
+ SecuritySettings settings = aio->getSecuritySettings();
+ settings.nodict = nodict;
+ return settings;
+ }
}
void AsynchIOHandler::readbuff(AsynchIO& , AsynchIO::BufferBase* buff) {
@@ -123,26 +118,6 @@ void AsynchIOHandler::readbuff(AsynchIO& , AsynchIO::BufferBase* buff) {
return;
}
- // Check here for read credit
- if (readCredit.get() != InfiniteCredit) {
- if (readCredit.get() == 0) {
- // FIXME aconway 2009-10-01: Workaround to avoid "false wakeups".
- // readbuff is sometimes called with no credit.
- // This should be fixed somewhere else to avoid such calls.
- aio->unread(buff);
- return;
- }
- // TODO In theory should be able to use an atomic operation before taking the lock
- // but in practice there seems to be an unexplained race in that case
- ScopedLock<Mutex> l(creditLock);
- if (--readCredit == 0) {
- assert(readCredit.get() >= 0);
- if (readCredit.get() == 0) {
- aio->stopReading();
- }
- }
- }
-
++reads;
size_t decoded = 0;
if (codec) { // Already initiated
@@ -168,13 +143,16 @@ void AsynchIOHandler::readbuff(AsynchIO& , AsynchIO::BufferBase* buff) {
QPID_LOG(debug, "RECV [" << identifier << "]: INIT(" << protocolInit << ")");
try {
- codec = factory->create(protocolInit.getVersion(), *this, identifier, SecuritySettings());
+ codec = factory->create(protocolInit.getVersion(), *this, identifier, getSecuritySettings(aio, nodict));
if (!codec) {
//TODO: may still want to revise this...
//send valid version header & close connection.
write(framing::ProtocolInitiation(framing::highestProtocolVersion));
readError = true;
aio->queueWriteClose();
+ } else {
+ //read any further data that may already have been sent
+ decoded += codec->decode(buff->bytes+buff->dataStart+in.getPosition(), buff->dataCount-in.getPosition());
}
} catch (const std::exception& e) {
QPID_LOG(error, e.what());
@@ -223,7 +201,7 @@ void AsynchIOHandler::nobuffs(AsynchIO&) {
void AsynchIOHandler::idle(AsynchIO&){
if (isClient && codec == 0) {
- codec = factory->create(*this, identifier, SecuritySettings());
+ codec = factory->create(*this, identifier, getSecuritySettings(aio, nodict));
write(framing::ProtocolInitiation(codec->getVersion()));
// We've just sent the protocol negotiation so we can cancel the timeout for that
// This is not ideal, because we've not received anything yet, but heartbeats will
diff --git a/cpp/src/qpid/sys/AsynchIOHandler.h b/cpp/src/qpid/sys/AsynchIOHandler.h
index fd0bc140e5..d93e24fd4c 100644
--- a/cpp/src/qpid/sys/AsynchIOHandler.h
+++ b/cpp/src/qpid/sys/AsynchIOHandler.h
@@ -51,24 +51,19 @@ class AsynchIOHandler : public OutputControl {
uint32_t reads;
bool readError;
bool isClient;
- AtomicValue<int32_t> readCredit;
- static const int32_t InfiniteCredit = -1;
- Mutex creditLock;
+ bool nodict;
boost::intrusive_ptr<sys::TimerTask> timeoutTimerTask;
void write(const framing::ProtocolInitiation&);
public:
- QPID_COMMON_EXTERN AsynchIOHandler(const std::string& id, qpid::sys::ConnectionCodec::Factory* f );
+ QPID_COMMON_EXTERN AsynchIOHandler(const std::string& id, qpid::sys::ConnectionCodec::Factory* f, bool isClient, bool nodict);
QPID_COMMON_EXTERN ~AsynchIOHandler();
QPID_COMMON_EXTERN void init(AsynchIO* a, Timer& timer, uint32_t maxTime);
- QPID_COMMON_INLINE_EXTERN void setClient() { isClient = true; }
-
// Output side
QPID_COMMON_EXTERN void abort();
QPID_COMMON_EXTERN void activateOutput();
- QPID_COMMON_EXTERN void giveReadCredit(int32_t credit);
// Input side
QPID_COMMON_EXTERN void readbuff(AsynchIO& aio, AsynchIOBufferBase* buff);
diff --git a/cpp/src/qpid/sys/ClusterSafe.cpp b/cpp/src/qpid/sys/ClusterSafe.cpp
deleted file mode 100644
index dd37615145..0000000000
--- a/cpp/src/qpid/sys/ClusterSafe.cpp
+++ /dev/null
@@ -1,66 +0,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.
- *
- */
-
-#include "ClusterSafe.h"
-#include "qpid/log/Statement.h"
-#include "qpid/sys/Thread.h"
-#include <stdlib.h>
-
-namespace qpid {
-namespace sys {
-
-namespace {
-bool inCluster = false;
-QPID_TSS bool inContext = false;
-}
-
-bool isClusterSafe() { return !inCluster || inContext; }
-
-void assertClusterSafe() {
- if (!isClusterSafe()) {
- QPID_LOG(critical, "Modified cluster state outside of cluster context");
- ::abort();
- }
-}
-
-ClusterSafeScope::ClusterSafeScope() {
- save = inContext;
- inContext = true;
-}
-
-ClusterSafeScope::~ClusterSafeScope() {
- assert(inContext);
- inContext = save;
-}
-
-ClusterUnsafeScope::ClusterUnsafeScope() {
- save = inContext;
- inContext = false;
-}
-
-ClusterUnsafeScope::~ClusterUnsafeScope() {
- assert(!inContext);
- inContext = save;
-}
-
-void enableClusterSafe() { inCluster = true; }
-
-}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/ClusterSafe.h b/cpp/src/qpid/sys/ClusterSafe.h
deleted file mode 100644
index 27e4eb46a5..0000000000
--- a/cpp/src/qpid/sys/ClusterSafe.h
+++ /dev/null
@@ -1,87 +0,0 @@
-#ifndef QPID_SYS_CLUSTERSAFE_H
-#define QPID_SYS_CLUSTERSAFE_H
-
-/*
- *
- * 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.
- *
- */
-
-#include "qpid/CommonImportExport.h"
-
-namespace qpid {
-namespace sys {
-
-/**
- * Assertion to add to code that modifies clustered state.
- *
- * In a non-clustered broker this is a no-op.
- *
- * In a clustered broker, checks that it is being called
- * in a context where it is safe to modify clustered state.
- * If not it aborts the process as this is a serious bug.
- *
- * This function is in the common library rather than the cluster
- * library because it is called by code in the broker library.
- */
-QPID_COMMON_EXTERN void assertClusterSafe();
-
-/**
- * In a non-clustered broker, returns true.
- *
- * In a clustered broker returns true if we are in a context where it
- * is safe to modify cluster state.
- *
- * This function is in the common library rather than the cluster
- * library because it is called by code in the broker library.
- */
-QPID_COMMON_EXTERN bool isClusterSafe();
-
-/**
- * Mark a scope as cluster safe. Sets isClusterSafe in constructor and resets
- * to previous value in destructor.
- */
-class ClusterSafeScope {
- public:
- ClusterSafeScope();
- ~ClusterSafeScope();
- private:
- bool save;
-};
-
-/**
- * Mark a scope as cluster unsafe. Clears isClusterSafe in constructor and resets
- * to previous value in destructor.
- */
-class ClusterUnsafeScope {
- public:
- QPID_COMMON_EXTERN ClusterUnsafeScope();
- QPID_COMMON_EXTERN ~ClusterUnsafeScope();
- private:
- bool save;
-};
-
-/**
- * Enable cluster-safe assertions. By default they are no-ops.
- * Called by cluster code.
- */
-void enableClusterSafe();
-
-}} // namespace qpid::sys
-
-#endif /*!QPID_SYS_CLUSTERSAFE_H*/
diff --git a/cpp/src/qpid/sys/Codec.h b/cpp/src/qpid/sys/Codec.h
index ace721fbcc..e398403e47 100644
--- a/cpp/src/qpid/sys/Codec.h
+++ b/cpp/src/qpid/sys/Codec.h
@@ -42,7 +42,7 @@ class Codec
/** Encode into buffer, return number of bytes encoded */
- virtual std::size_t encode(const char* buffer, std::size_t size) = 0;
+ virtual std::size_t encode(char* buffer, std::size_t size) = 0;
/** Return true if we have data to encode */
virtual bool canEncode() = 0;
diff --git a/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h b/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h
index 95a08d15ae..53d56ad716 100644
--- a/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h
+++ b/cpp/src/qpid/sys/ConnectionOutputHandlerPtr.h
@@ -45,7 +45,6 @@ class ConnectionOutputHandlerPtr : public ConnectionOutputHandler
size_t getBuffered() const { return next->getBuffered(); }
void abort() { next->abort(); }
void activateOutput() { next->activateOutput(); }
- void giveReadCredit(int32_t credit) { next->giveReadCredit(credit); }
void send(framing::AMQFrame& f) { next->send(f); }
private:
diff --git a/cpp/src/qpid/sys/FileSysDir.h b/cpp/src/qpid/sys/FileSysDir.h
index ffe7823f0a..7432fe39c9 100755
--- a/cpp/src/qpid/sys/FileSysDir.h
+++ b/cpp/src/qpid/sys/FileSysDir.h
@@ -54,6 +54,15 @@ class FileSysDir
void mkdir(void);
+ typedef void Callback(const std::string&);
+
+ /**
+ * Call the Callback function for every regular file in the directory
+ *
+ * @param cb Callback function that receives the full path to the file
+ */
+ void forEachFile(Callback cb) const;
+
std::string getPath () { return dirPath; }
};
diff --git a/cpp/src/qpid/sys/OutputControl.h b/cpp/src/qpid/sys/OutputControl.h
index eae99beb0f..0d801e9d16 100644
--- a/cpp/src/qpid/sys/OutputControl.h
+++ b/cpp/src/qpid/sys/OutputControl.h
@@ -1,3 +1,6 @@
+#ifndef QPID_SYS_OUTPUT_CONTROL_H
+#define QPID_SYS_OUTPUT_CONTROL_H
+
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -21,9 +24,6 @@
#include "qpid/sys/IntegerTypes.h"
-#ifndef _OutputControl_
-#define _OutputControl_
-
namespace qpid {
namespace sys {
@@ -33,11 +33,10 @@ namespace sys {
virtual ~OutputControl() {}
virtual void abort() = 0;
virtual void activateOutput() = 0;
- virtual void giveReadCredit(int32_t credit) = 0;
};
}
}
-#endif
+#endif /*!QPID_SYS_OUTPUT_CONTROL_H*/
diff --git a/cpp/src/qpid/sys/ProtocolFactory.h b/cpp/src/qpid/sys/ProtocolFactory.h
index 4d198a92da..236398c111 100644
--- a/cpp/src/qpid/sys/ProtocolFactory.h
+++ b/cpp/src/qpid/sys/ProtocolFactory.h
@@ -42,10 +42,10 @@ class ProtocolFactory : public qpid::SharedObject<ProtocolFactory>
virtual void accept(boost::shared_ptr<Poller>, ConnectionCodec::Factory*) = 0;
virtual void connect(
boost::shared_ptr<Poller>,
+ const std::string& name,
const std::string& host, const std::string& port,
ConnectionCodec::Factory* codec,
ConnectFailedCallback failed) = 0;
- virtual bool supports(const std::string& /*capability*/) { return false; }
};
inline ProtocolFactory::~ProtocolFactory() {}
diff --git a/cpp/src/qpid/sys/RdmaIOPlugin.cpp b/cpp/src/qpid/sys/RdmaIOPlugin.cpp
index b491d28d0a..51cc0ed109 100644
--- a/cpp/src/qpid/sys/RdmaIOPlugin.cpp
+++ b/cpp/src/qpid/sys/RdmaIOPlugin.cpp
@@ -23,6 +23,7 @@
#include "qpid/Plugin.h"
#include "qpid/broker/Broker.h"
+#include "qpid/broker/NameGenerator.h"
#include "qpid/framing/AMQP_HighestVersion.h"
#include "qpid/log/Statement.h"
#include "qpid/sys/rdma/RdmaIO.h"
@@ -67,7 +68,6 @@ class RdmaIOHandler : public OutputControl {
void close();
void abort();
void activateOutput();
- void giveReadCredit(int32_t credit);
void initProtocolOut();
// Input side
@@ -83,7 +83,7 @@ class RdmaIOHandler : public OutputControl {
};
RdmaIOHandler::RdmaIOHandler(Rdma::Connection::intrusive_ptr c, qpid::sys::ConnectionCodec::Factory* f) :
- identifier(c->getFullName()),
+ identifier(broker::QPID_NAME_PREFIX+c->getFullName()),
factory(f),
codec(0),
readError(false),
@@ -199,10 +199,6 @@ void RdmaIOHandler::full(Rdma::AsynchIO&) {
QPID_LOG(debug, "Rdma: buffer full [" << identifier << "]");
}
-// TODO: Dummy implementation of read throttling
-void RdmaIOHandler::giveReadCredit(int32_t) {
-}
-
// The logic here is subtly different from TCP as RDMA is message oriented
// so we define that an RDMA message is a frame - in this case there is no putting back
// of any message remainder - there shouldn't be any. And what we read here can't be
@@ -250,7 +246,7 @@ class RdmaIOProtocolFactory : public ProtocolFactory {
public:
RdmaIOProtocolFactory(int16_t port, int backlog);
void accept(Poller::shared_ptr, ConnectionCodec::Factory*);
- void connect(Poller::shared_ptr, const string& host, const std::string& port, ConnectionCodec::Factory*, ConnectFailedCallback);
+ void connect(Poller::shared_ptr, const std::string& name, const string& host, const std::string& port, ConnectionCodec::Factory*, ConnectFailedCallback);
uint16_t getPort() const;
@@ -371,6 +367,7 @@ void RdmaIOProtocolFactory::connected(Poller::shared_ptr poller, Rdma::Connectio
void RdmaIOProtocolFactory::connect(
Poller::shared_ptr poller,
+ const std::string& /*name*/,
const std::string& host, const std::string& port,
ConnectionCodec::Factory* f,
ConnectFailedCallback failed)
diff --git a/cpp/src/qpid/sys/SecurityLayer.h b/cpp/src/qpid/sys/SecurityLayer.h
index 52bc40e352..317ada16de 100644
--- a/cpp/src/qpid/sys/SecurityLayer.h
+++ b/cpp/src/qpid/sys/SecurityLayer.h
@@ -33,8 +33,12 @@ namespace sys {
class SecurityLayer : public Codec
{
public:
+ SecurityLayer(int ssf_) : ssf(ssf_) {}
+ int getSsf() const { return ssf; }
virtual void init(Codec*) = 0;
virtual ~SecurityLayer() {}
+ private:
+ int ssf;
};
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/SecuritySettings.h b/cpp/src/qpid/sys/SecuritySettings.h
index bfcd08fd0f..d595cad660 100644
--- a/cpp/src/qpid/sys/SecuritySettings.h
+++ b/cpp/src/qpid/sys/SecuritySettings.h
@@ -21,6 +21,8 @@
* under the License.
*
*/
+#include <string>
+
namespace qpid {
namespace sys {
diff --git a/cpp/src/qpid/sys/Socket.h b/cpp/src/qpid/sys/Socket.h
index defec4879c..38183bd5fd 100644
--- a/cpp/src/qpid/sys/Socket.h
+++ b/cpp/src/qpid/sys/Socket.h
@@ -22,7 +22,6 @@
*
*/
-#include "qpid/sys/IOHandle.h"
#include "qpid/sys/IntegerTypes.h"
#include "qpid/CommonImportExport.h"
#include <string>
@@ -31,45 +30,43 @@ namespace qpid {
namespace sys {
class Duration;
+class IOHandle;
class SocketAddress;
-class QPID_COMMON_CLASS_EXTERN Socket : public IOHandle
+class Socket
{
public:
- /** Create a socket wrapper for descriptor. */
- QPID_COMMON_EXTERN Socket();
+ virtual ~Socket() {};
- /** Create a new Socket which is the same address family as this one */
- QPID_COMMON_EXTERN Socket* createSameTypeSocket() const;
+ virtual operator const IOHandle&() const = 0;
/** Set socket non blocking */
- void setNonblocking() const;
+ virtual void setNonblocking() const = 0;
- QPID_COMMON_EXTERN void setTcpNoDelay() const;
+ virtual void setTcpNoDelay() const = 0;
- QPID_COMMON_EXTERN void connect(const std::string& host, const std::string& port) const;
- QPID_COMMON_EXTERN void connect(const SocketAddress&) const;
+ virtual void connect(const SocketAddress&) const = 0;
+ virtual void finishConnect(const SocketAddress&) const = 0;
- QPID_COMMON_EXTERN void close() const;
+ virtual void close() const = 0;
/** Bind to a port and start listening.
*@param port 0 means choose an available port.
*@param backlog maximum number of pending connections.
*@return The bound port.
*/
- QPID_COMMON_EXTERN int listen(const std::string& host = "", const std::string& port = "0", int backlog = 10) const;
- QPID_COMMON_EXTERN int listen(const SocketAddress&, int backlog = 10) const;
+ virtual int listen(const SocketAddress&, int backlog = 10) const = 0;
/**
* Returns an address (host and port) for the remote end of the
* socket
*/
- QPID_COMMON_EXTERN std::string getPeerAddress() const;
+ virtual std::string getPeerAddress() const = 0;
/**
* Returns an address (host and port) for the local end of the
* socket
*/
- QPID_COMMON_EXTERN std::string getLocalAddress() const;
+ virtual std::string getLocalAddress() const = 0;
/**
* Returns the full address of the connection: local and remote host and port.
@@ -80,31 +77,24 @@ public:
* Returns the error code stored in the socket. This may be used
* to determine the result of a non-blocking connect.
*/
- QPID_COMMON_EXTERN int getError() const;
+ virtual int getError() const = 0;
/** Accept a connection from a socket that is already listening
* and has an incoming connection
*/
- QPID_COMMON_EXTERN Socket* accept() const;
+ virtual Socket* accept() const = 0;
- // TODO The following are raw operations, maybe they need better wrapping?
- QPID_COMMON_EXTERN int read(void *buf, size_t count) const;
- QPID_COMMON_EXTERN int write(const void *buf, size_t count) const;
+ virtual int read(void *buf, size_t count) const = 0;
+ virtual int write(const void *buf, size_t count) const = 0;
-private:
- /** Create socket */
- void createSocket(const SocketAddress&) const;
-
-public:
- /** Construct socket with existing handle */
- Socket(IOHandlePrivate*);
-
-protected:
- mutable std::string localname;
- mutable std::string peername;
- mutable bool nonblocking;
- mutable bool nodelay;
+ /* Transport security related: */
+ virtual int getKeyLen() const = 0;
+ virtual std::string getClientAuthId() const = 0;
};
+/** Make the default socket for whatever platform we are executing on
+ */
+QPID_COMMON_EXTERN Socket* createSocket();
+
}}
#endif /*!_sys_Socket_h*/
diff --git a/cpp/src/qpid/sys/SocketAddress.h b/cpp/src/qpid/sys/SocketAddress.h
index dcca109d94..a4da5cca79 100644
--- a/cpp/src/qpid/sys/SocketAddress.h
+++ b/cpp/src/qpid/sys/SocketAddress.h
@@ -44,11 +44,12 @@ public:
QPID_COMMON_EXTERN bool nextAddress();
QPID_COMMON_EXTERN std::string asString(bool numeric=true) const;
+ QPID_COMMON_EXTERN std::string getHost() const;
QPID_COMMON_EXTERN void setAddrInfoPort(uint16_t port);
QPID_COMMON_EXTERN static std::string asString(::sockaddr const * const addr, size_t addrlen);
QPID_COMMON_EXTERN static uint16_t getPort(::sockaddr const * const addr);
-
+
private:
std::string host;
diff --git a/cpp/src/qpid/sys/SslPlugin.cpp b/cpp/src/qpid/sys/SslPlugin.cpp
index 069e97758e..a40da24eb8 100644
--- a/cpp/src/qpid/sys/SslPlugin.cpp
+++ b/cpp/src/qpid/sys/SslPlugin.cpp
@@ -22,19 +22,19 @@
#include "qpid/sys/ProtocolFactory.h"
#include "qpid/Plugin.h"
-#include "qpid/sys/ssl/check.h"
-#include "qpid/sys/ssl/util.h"
-#include "qpid/sys/ssl/SslHandler.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/broker/NameGenerator.h"
+#include "qpid/log/Statement.h"
#include "qpid/sys/AsynchIOHandler.h"
#include "qpid/sys/AsynchIO.h"
-#include "qpid/sys/ssl/SslIo.h"
+#include "qpid/sys/ssl/util.h"
#include "qpid/sys/ssl/SslSocket.h"
-#include "qpid/broker/Broker.h"
-#include "qpid/log/Statement.h"
+#include "qpid/sys/SocketAddress.h"
+#include "qpid/sys/SystemInfo.h"
+#include "qpid/sys/Poller.h"
#include <boost/bind.hpp>
-#include <memory>
-
+#include <boost/ptr_container/ptr_vector.hpp>
namespace qpid {
namespace sys {
@@ -64,38 +64,32 @@ struct SslServerOptions : ssl::SslOptions
}
};
-template <class T>
-class SslProtocolFactoryTmpl : public ProtocolFactory {
- private:
-
- typedef SslAcceptorTmpl<T> SslAcceptor;
-
+class SslProtocolFactory : public ProtocolFactory {
+ boost::ptr_vector<Socket> listeners;
+ boost::ptr_vector<AsynchAcceptor> acceptors;
Timer& brokerTimer;
uint32_t maxNegotiateTime;
+ uint16_t listeningPort;
const bool tcpNoDelay;
- T listener;
- const uint16_t listeningPort;
- std::auto_ptr<SslAcceptor> acceptor;
bool nodict;
public:
- SslProtocolFactoryTmpl(const SslServerOptions&, int backlog, bool nodelay, Timer& timer, uint32_t maxTime);
+ SslProtocolFactory(const qpid::broker::Broker::Options& opts, const SslServerOptions& options,
+ Timer& timer);
void accept(Poller::shared_ptr, ConnectionCodec::Factory*);
- void connect(Poller::shared_ptr, const std::string& host, const std::string& port,
+ void connect(Poller::shared_ptr, const std::string& name, const std::string& host, const std::string& port,
ConnectionCodec::Factory*,
- boost::function2<void, int, std::string> failed);
+ ConnectFailedCallback);
uint16_t getPort() const;
- bool supports(const std::string& capability);
private:
- void established(Poller::shared_ptr, const Socket&, ConnectionCodec::Factory*,
- bool isClient);
+ void establishedIncoming(Poller::shared_ptr, const Socket&, ConnectionCodec::Factory*);
+ void establishedOutgoing(Poller::shared_ptr, const Socket&, ConnectionCodec::Factory*, const std::string&);
+ void establishedCommon(AsynchIOHandler*, Poller::shared_ptr , const Socket&);
+ void connectFailed(const Socket&, int, const std::string&, ConnectFailedCallback);
};
-typedef SslProtocolFactoryTmpl<SslSocket> SslProtocolFactory;
-typedef SslProtocolFactoryTmpl<SslMuxSocket> SslMuxProtocolFactory;
-
// Static instance to initialise plugin
static struct SslPlugin : public Plugin {
@@ -124,7 +118,7 @@ static struct SslPlugin : public Plugin {
}
}
}
-
+
void initialize(Target& target) {
QPID_LOG(trace, "Initialising SSL plugin");
broker::Broker* broker = dynamic_cast<broker::Broker*>(&target);
@@ -139,19 +133,16 @@ static struct SslPlugin : public Plugin {
const broker::Broker::Options& opts = broker->getOptions();
- ProtocolFactory::shared_ptr protocol(options.multiplex ?
- static_cast<ProtocolFactory*>(new SslMuxProtocolFactory(options,
- opts.connectionBacklog,
- opts.tcpNoDelay,
- broker->getTimer(), opts.maxNegotiateTime)) :
- static_cast<ProtocolFactory*>(new SslProtocolFactory(options,
- opts.connectionBacklog,
- opts.tcpNoDelay,
- broker->getTimer(), opts.maxNegotiateTime)));
- QPID_LOG(notice, "Listening for " <<
- (options.multiplex ? "SSL or TCP" : "SSL") <<
- " connections on TCP port " <<
- protocol->getPort());
+ ProtocolFactory::shared_ptr protocol(
+ static_cast<ProtocolFactory*>(new SslProtocolFactory(opts, options, broker->getTimer())));
+
+ if (protocol->getPort()!=0 ) {
+ QPID_LOG(notice, "Listening for " <<
+ (options.multiplex ? "SSL or TCP" : "SSL") <<
+ " connections on TCP/TCP6 port " <<
+ protocol->getPort());
+ }
+
broker->registerProtocolFactory("ssl", protocol);
} catch (const std::exception& e) {
QPID_LOG(error, "Failed to initialise SSL plugin: " << e.what());
@@ -161,99 +152,133 @@ static struct SslPlugin : public Plugin {
}
} sslPlugin;
-template <class T>
-SslProtocolFactoryTmpl<T>::SslProtocolFactoryTmpl(const SslServerOptions& options, int backlog, bool nodelay, Timer& timer, uint32_t maxTime) :
+namespace {
+ // Expand list of Interfaces and addresses to a list of addresses
+ std::vector<std::string> expandInterfaces(const std::vector<std::string>& interfaces) {
+ std::vector<std::string> addresses;
+ // If there are no specific interfaces listed use a single "" to listen on every interface
+ if (interfaces.empty()) {
+ addresses.push_back("");
+ return addresses;
+ }
+ for (unsigned i = 0; i < interfaces.size(); ++i) {
+ const std::string& interface = interfaces[i];
+ if (!(SystemInfo::getInterfaceAddresses(interface, addresses))) {
+ // We don't have an interface of that name -
+ // Check for IPv6 ('[' ']') brackets and remove them
+ // then pass to be looked up directly
+ if (interface[0]=='[' && interface[interface.size()-1]==']') {
+ addresses.push_back(interface.substr(1, interface.size()-2));
+ } else {
+ addresses.push_back(interface);
+ }
+ }
+ }
+ return addresses;
+ }
+}
+
+SslProtocolFactory::SslProtocolFactory(const qpid::broker::Broker::Options& opts, const SslServerOptions& options,
+ Timer& timer) :
brokerTimer(timer),
- maxNegotiateTime(maxTime),
- tcpNoDelay(nodelay), listeningPort(listener.listen(options.port, backlog, options.certName, options.clientAuth)),
+ maxNegotiateTime(opts.maxNegotiateTime),
+ tcpNoDelay(opts.tcpNoDelay),
nodict(options.nodict)
-{}
-
-void SslEstablished(Poller::shared_ptr poller, const qpid::sys::SslSocket& s,
- ConnectionCodec::Factory* f, bool isClient,
- Timer& timer, uint32_t maxTime, bool tcpNoDelay, bool nodict) {
- qpid::sys::ssl::SslHandler* async = new qpid::sys::ssl::SslHandler(s.getFullAddress(), f, nodict);
-
- if (tcpNoDelay) {
- s.setTcpNoDelay(tcpNoDelay);
- QPID_LOG(info, "Set TCP_NODELAY on connection to " << s.getPeerAddress());
+{
+ std::vector<std::string> addresses = expandInterfaces(opts.listenInterfaces);
+ if (addresses.empty()) {
+ // We specified some interfaces, but couldn't find addresses for them
+ QPID_LOG(warning, "SSL: No specified network interfaces found: Not Listening");
+ listeningPort = 0;
}
- if (isClient) {
- async->setClient();
+ for (unsigned i = 0; i<addresses.size(); ++i) {
+ QPID_LOG(debug, "Using interface: " << addresses[i]);
+ SocketAddress sa(addresses[i], boost::lexical_cast<std::string>(options.port));
+
+ // We must have at least one resolved address
+ QPID_LOG(info, "Listening to: " << sa.asString())
+ Socket* s = options.multiplex ?
+ new SslMuxSocket(options.certName, options.clientAuth) :
+ new SslSocket(options.certName, options.clientAuth);
+ uint16_t lport = s->listen(sa, opts.connectionBacklog);
+ QPID_LOG(debug, "Listened to: " << lport);
+ listeners.push_back(s);
+
+ listeningPort = lport;
+
+ // Try any other resolved addresses
+ while (sa.nextAddress()) {
+ // Hack to ensure that all listening connections are on the same port
+ sa.setAddrInfoPort(listeningPort);
+ QPID_LOG(info, "Listening to: " << sa.asString())
+ Socket* s = options.multiplex ?
+ new SslMuxSocket(options.certName, options.clientAuth) :
+ new SslSocket(options.certName, options.clientAuth);
+ uint16_t lport = s->listen(sa, opts.connectionBacklog);
+ QPID_LOG(debug, "Listened to: " << lport);
+ listeners.push_back(s);
+ }
}
-
- qpid::sys::ssl::SslIO* aio = new qpid::sys::ssl::SslIO(s,
- boost::bind(&qpid::sys::ssl::SslHandler::readbuff, async, _1, _2),
- boost::bind(&qpid::sys::ssl::SslHandler::eof, async, _1),
- boost::bind(&qpid::sys::ssl::SslHandler::disconnect, async, _1),
- boost::bind(&qpid::sys::ssl::SslHandler::closedSocket, async, _1, _2),
- boost::bind(&qpid::sys::ssl::SslHandler::nobuffs, async, _1),
- boost::bind(&qpid::sys::ssl::SslHandler::idle, async, _1));
-
- async->init(aio,timer, maxTime);
- aio->start(poller);
-}
-
-template <>
-void SslProtocolFactory::established(Poller::shared_ptr poller, const Socket& s,
- ConnectionCodec::Factory* f, bool isClient) {
- const SslSocket *sslSock = dynamic_cast<const SslSocket*>(&s);
-
- SslEstablished(poller, *sslSock, f, isClient, brokerTimer, maxNegotiateTime, tcpNoDelay, nodict);
}
-template <class T>
-uint16_t SslProtocolFactoryTmpl<T>::getPort() const {
- return listeningPort; // Immutable no need for lock.
+void SslProtocolFactory::establishedIncoming(Poller::shared_ptr poller, const Socket& s,
+ ConnectionCodec::Factory* f) {
+ AsynchIOHandler* async = new AsynchIOHandler(broker::QPID_NAME_PREFIX+s.getFullAddress(), f, false, false);
+ establishedCommon(async, poller, s);
}
-template <class T>
-void SslProtocolFactoryTmpl<T>::accept(Poller::shared_ptr poller,
- ConnectionCodec::Factory* fact) {
- acceptor.reset(
- new SslAcceptor(listener,
- boost::bind(&SslProtocolFactoryTmpl<T>::established,
- this, poller, _1, fact, false)));
- acceptor->start(poller);
+void SslProtocolFactory::establishedOutgoing(Poller::shared_ptr poller, const Socket& s,
+ ConnectionCodec::Factory* f, const std::string& name) {
+ AsynchIOHandler* async = new AsynchIOHandler(name, f, true, false);
+ establishedCommon(async, poller, s);
}
-template <>
-void SslMuxProtocolFactory::established(Poller::shared_ptr poller, const Socket& s,
- ConnectionCodec::Factory* f, bool isClient) {
- const SslSocket *sslSock = dynamic_cast<const SslSocket*>(&s);
-
- if (sslSock) {
- SslEstablished(poller, *sslSock, f, isClient, brokerTimer, maxNegotiateTime, tcpNoDelay, nodict);
- return;
- }
-
- AsynchIOHandler* async = new AsynchIOHandler(s.getFullAddress(), f);
-
+void SslProtocolFactory::establishedCommon(AsynchIOHandler* async, Poller::shared_ptr poller, const Socket& s) {
if (tcpNoDelay) {
s.setTcpNoDelay();
QPID_LOG(info, "Set TCP_NODELAY on connection to " << s.getPeerAddress());
}
- if (isClient) {
- async->setClient();
- }
- AsynchIO* aio = AsynchIO::create
- (s,
- boost::bind(&AsynchIOHandler::readbuff, async, _1, _2),
- boost::bind(&AsynchIOHandler::eof, async, _1),
- boost::bind(&AsynchIOHandler::disconnect, async, _1),
- boost::bind(&AsynchIOHandler::closedSocket, async, _1, _2),
- boost::bind(&AsynchIOHandler::nobuffs, async, _1),
- boost::bind(&AsynchIOHandler::idle, async, _1));
+ AsynchIO* aio = AsynchIO::create(
+ s,
+ boost::bind(&AsynchIOHandler::readbuff, async, _1, _2),
+ boost::bind(&AsynchIOHandler::eof, async, _1),
+ boost::bind(&AsynchIOHandler::disconnect, async, _1),
+ boost::bind(&AsynchIOHandler::closedSocket, async, _1, _2),
+ boost::bind(&AsynchIOHandler::nobuffs, async, _1),
+ boost::bind(&AsynchIOHandler::idle, async, _1));
async->init(aio, brokerTimer, maxNegotiateTime);
aio->start(poller);
}
-template <class T>
-void SslProtocolFactoryTmpl<T>::connect(
+uint16_t SslProtocolFactory::getPort() const {
+ return listeningPort; // Immutable no need for lock.
+}
+
+void SslProtocolFactory::accept(Poller::shared_ptr poller,
+ ConnectionCodec::Factory* fact) {
+ for (unsigned i = 0; i<listeners.size(); ++i) {
+ acceptors.push_back(
+ AsynchAcceptor::create(listeners[i],
+ boost::bind(&SslProtocolFactory::establishedIncoming, this, poller, _1, fact)));
+ acceptors[i].start(poller);
+ }
+}
+
+void SslProtocolFactory::connectFailed(
+ const Socket& s, int ec, const std::string& emsg,
+ ConnectFailedCallback failedCb)
+{
+ failedCb(ec, emsg);
+ s.close();
+ delete &s;
+}
+
+void SslProtocolFactory::connect(
Poller::shared_ptr poller,
+ const std::string& name,
const std::string& host, const std::string& port,
ConnectionCodec::Factory* fact,
ConnectFailedCallback failed)
@@ -264,31 +289,23 @@ void SslProtocolFactoryTmpl<T>::connect(
// shutdown. The allocated SslConnector frees itself when it
// is no longer needed.
- qpid::sys::ssl::SslSocket* socket = new qpid::sys::ssl::SslSocket();
- new SslConnector(*socket, poller, host, port,
- boost::bind(&SslProtocolFactoryTmpl<T>::established, this, poller, _1, fact, true),
- failed);
-}
-
-namespace
-{
-const std::string SSL = "ssl";
-}
-
-template <>
-bool SslProtocolFactory::supports(const std::string& capability)
-{
- std::string s = capability;
- transform(s.begin(), s.end(), s.begin(), tolower);
- return s == SSL;
-}
-
-template <>
-bool SslMuxProtocolFactory::supports(const std::string& capability)
-{
- std::string s = capability;
- transform(s.begin(), s.end(), s.begin(), tolower);
- return s == SSL || s == "tcp";
+ Socket* socket = new qpid::sys::ssl::SslSocket();
+ try {
+ AsynchConnector* c = AsynchConnector::create(
+ *socket,
+ host,
+ port,
+ boost::bind(&SslProtocolFactory::establishedOutgoing,
+ this, poller, _1, fact, name),
+ boost::bind(&SslProtocolFactory::connectFailed,
+ this, _1, _2, _3, failed));
+ c->start(poller);
+ } catch (std::exception&) {
+ // TODO: Design question - should we do the error callback and also throw?
+ int errCode = socket->getError();
+ connectFailed(*socket, errCode, strError(errCode), failed);
+ throw;
+ }
}
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/TCPIOPlugin.cpp b/cpp/src/qpid/sys/TCPIOPlugin.cpp
index ed7cc3748d..1ef8708cd0 100644
--- a/cpp/src/qpid/sys/TCPIOPlugin.cpp
+++ b/cpp/src/qpid/sys/TCPIOPlugin.cpp
@@ -20,15 +20,17 @@
*/
#include "qpid/sys/ProtocolFactory.h"
-#include "qpid/sys/AsynchIOHandler.h"
-#include "qpid/sys/AsynchIO.h"
#include "qpid/Plugin.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/broker/NameGenerator.h"
+#include "qpid/log/Statement.h"
+#include "qpid/sys/AsynchIOHandler.h"
+#include "qpid/sys/AsynchIO.h"
#include "qpid/sys/Socket.h"
#include "qpid/sys/SocketAddress.h"
+#include "qpid/sys/SystemInfo.h"
#include "qpid/sys/Poller.h"
-#include "qpid/broker/Broker.h"
-#include "qpid/log/Statement.h"
#include <boost/bind.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
@@ -47,20 +49,19 @@ class AsynchIOProtocolFactory : public ProtocolFactory {
const bool tcpNoDelay;
public:
- AsynchIOProtocolFactory(const std::string& host, const std::string& port,
- int backlog, bool nodelay,
- Timer& timer, uint32_t maxTime,
- bool shouldListen);
+ AsynchIOProtocolFactory(const qpid::broker::Broker::Options& opts, Timer& timer, bool shouldListen);
void accept(Poller::shared_ptr, ConnectionCodec::Factory*);
- void connect(Poller::shared_ptr, const std::string& host, const std::string& port,
+ void connect(Poller::shared_ptr, const std::string& name,
+ const std::string& host, const std::string& port,
ConnectionCodec::Factory*,
ConnectFailedCallback);
uint16_t getPort() const;
private:
- void established(Poller::shared_ptr, const Socket&, ConnectionCodec::Factory*,
- bool isClient);
+ void establishedIncoming(Poller::shared_ptr, const Socket&, ConnectionCodec::Factory*);
+ void establishedOutgoing(Poller::shared_ptr, const Socket&, ConnectionCodec::Factory*, const std::string&);
+ void establishedCommon(AsynchIOHandler*, Poller::shared_ptr , const Socket&);
void connectFailed(const Socket&, int, const std::string&, ConnectFailedCallback);
};
@@ -93,14 +94,9 @@ static class TCPIOPlugin : public Plugin {
bool shouldListen = !sslMultiplexEnabled();
ProtocolFactory::shared_ptr protocolt(
- new AsynchIOProtocolFactory(
- "", boost::lexical_cast<std::string>(opts.port),
- opts.connectionBacklog,
- opts.tcpNoDelay,
- broker->getTimer(), opts.maxNegotiateTime,
- shouldListen));
-
- if (shouldListen) {
+ new AsynchIOProtocolFactory(opts, broker->getTimer(),shouldListen));
+
+ if (shouldListen && protocolt->getPort()!=0 ) {
QPID_LOG(notice, "Listening on TCP/TCP6 port " << protocolt->getPort());
}
@@ -109,54 +105,93 @@ static class TCPIOPlugin : public Plugin {
}
} tcpPlugin;
-AsynchIOProtocolFactory::AsynchIOProtocolFactory(const std::string& host, const std::string& port,
- int backlog, bool nodelay,
- Timer& timer, uint32_t maxTime,
- bool shouldListen) :
+namespace {
+ // Expand list of Interfaces and addresses to a list of addresses
+ std::vector<std::string> expandInterfaces(const std::vector<std::string>& interfaces) {
+ std::vector<std::string> addresses;
+ // If there are no specific interfaces listed use a single "" to listen on every interface
+ if (interfaces.empty()) {
+ addresses.push_back("");
+ return addresses;
+ }
+ for (unsigned i = 0; i < interfaces.size(); ++i) {
+ const std::string& interface = interfaces[i];
+ if (!(SystemInfo::getInterfaceAddresses(interface, addresses))) {
+ // We don't have an interface of that name -
+ // Check for IPv6 ('[' ']') brackets and remove them
+ // then pass to be looked up directly
+ if (interface[0]=='[' && interface[interface.size()-1]==']') {
+ addresses.push_back(interface.substr(1, interface.size()-2));
+ } else {
+ addresses.push_back(interface);
+ }
+ }
+ }
+ return addresses;
+ }
+}
+
+AsynchIOProtocolFactory::AsynchIOProtocolFactory(const qpid::broker::Broker::Options& opts, Timer& timer, bool shouldListen) :
brokerTimer(timer),
- maxNegotiateTime(maxTime),
- tcpNoDelay(nodelay)
+ maxNegotiateTime(opts.maxNegotiateTime),
+ tcpNoDelay(opts.tcpNoDelay)
{
if (!shouldListen) {
- listeningPort = boost::lexical_cast<uint16_t>(port);
+ listeningPort = boost::lexical_cast<uint16_t>(opts.port);
return;
}
- SocketAddress sa(host, port);
-
- // We must have at least one resolved address
- QPID_LOG(info, "Listening to: " << sa.asString())
- Socket* s = new Socket;
- uint16_t lport = s->listen(sa, backlog);
- QPID_LOG(debug, "Listened to: " << lport);
- listeners.push_back(s);
+ std::vector<std::string> addresses = expandInterfaces(opts.listenInterfaces);
+ if (addresses.empty()) {
+ // We specified some interfaces, but couldn't find addresses for them
+ QPID_LOG(warning, "TCP/TCP6: No specified network interfaces found: Not Listening");
+ listeningPort = 0;
+ }
- listeningPort = lport;
+ for (unsigned i = 0; i<addresses.size(); ++i) {
+ QPID_LOG(debug, "Using interface: " << addresses[i]);
+ SocketAddress sa(addresses[i], boost::lexical_cast<std::string>(opts.port));
- // Try any other resolved addresses
- while (sa.nextAddress()) {
- // Hack to ensure that all listening connections are on the same port
- sa.setAddrInfoPort(listeningPort);
+ // We must have at least one resolved address
QPID_LOG(info, "Listening to: " << sa.asString())
- Socket* s = new Socket;
- uint16_t lport = s->listen(sa, backlog);
+ Socket* s = createSocket();
+ uint16_t lport = s->listen(sa, opts.connectionBacklog);
QPID_LOG(debug, "Listened to: " << lport);
listeners.push_back(s);
+
+ listeningPort = lport;
+
+ // Try any other resolved addresses
+ while (sa.nextAddress()) {
+ // Hack to ensure that all listening connections are on the same port
+ sa.setAddrInfoPort(listeningPort);
+ QPID_LOG(info, "Listening to: " << sa.asString())
+ Socket* s = createSocket();
+ uint16_t lport = s->listen(sa, opts.connectionBacklog);
+ QPID_LOG(debug, "Listened to: " << lport);
+ listeners.push_back(s);
+ }
}
+}
+void AsynchIOProtocolFactory::establishedIncoming(Poller::shared_ptr poller, const Socket& s,
+ ConnectionCodec::Factory* f) {
+ AsynchIOHandler* async = new AsynchIOHandler(broker::QPID_NAME_PREFIX+s.getFullAddress(), f, false, false);
+ establishedCommon(async, poller, s);
}
-void AsynchIOProtocolFactory::established(Poller::shared_ptr poller, const Socket& s,
- ConnectionCodec::Factory* f, bool isClient) {
- AsynchIOHandler* async = new AsynchIOHandler(s.getFullAddress(), f);
+void AsynchIOProtocolFactory::establishedOutgoing(Poller::shared_ptr poller, const Socket& s,
+ ConnectionCodec::Factory* f, const std::string& name) {
+ AsynchIOHandler* async = new AsynchIOHandler(name, f, true, false);
+ establishedCommon(async, poller, s);
+}
+void AsynchIOProtocolFactory::establishedCommon(AsynchIOHandler* async, Poller::shared_ptr poller, const Socket& s) {
if (tcpNoDelay) {
s.setTcpNoDelay();
QPID_LOG(info, "Set TCP_NODELAY on connection to " << s.getPeerAddress());
}
- if (isClient)
- async->setClient();
AsynchIO* aio = AsynchIO::create
(s,
boost::bind(&AsynchIOHandler::readbuff, async, _1, _2),
@@ -179,7 +214,7 @@ void AsynchIOProtocolFactory::accept(Poller::shared_ptr poller,
for (unsigned i = 0; i<listeners.size(); ++i) {
acceptors.push_back(
AsynchAcceptor::create(listeners[i],
- boost::bind(&AsynchIOProtocolFactory::established, this, poller, _1, fact, false)));
+ boost::bind(&AsynchIOProtocolFactory::establishedIncoming, this, poller, _1, fact)));
acceptors[i].start(poller);
}
}
@@ -195,6 +230,7 @@ void AsynchIOProtocolFactory::connectFailed(
void AsynchIOProtocolFactory::connect(
Poller::shared_ptr poller,
+ const std::string& name,
const std::string& host, const std::string& port,
ConnectionCodec::Factory* fact,
ConnectFailedCallback failed)
@@ -204,14 +240,14 @@ void AsynchIOProtocolFactory::connect(
// upon connection failure or by the AsynchIO upon connection
// shutdown. The allocated AsynchConnector frees itself when it
// is no longer needed.
- Socket* socket = new Socket();
+ Socket* socket = createSocket();
try {
AsynchConnector* c = AsynchConnector::create(
*socket,
host,
port,
- boost::bind(&AsynchIOProtocolFactory::established,
- this, poller, _1, fact, true),
+ boost::bind(&AsynchIOProtocolFactory::establishedOutgoing,
+ this, poller, _1, fact, name),
boost::bind(&AsynchIOProtocolFactory::connectFailed,
this, _1, _2, _3, failed));
c->start(poller);
diff --git a/cpp/src/qpid/sys/Timer.cpp b/cpp/src/qpid/sys/Timer.cpp
index 973c6bd8b7..f8eef2c9ec 100644
--- a/cpp/src/qpid/sys/Timer.cpp
+++ b/cpp/src/qpid/sys/Timer.cpp
@@ -96,18 +96,13 @@ void TimerTask::cancel() {
state = CANCELLED;
}
-void TimerTask::setFired() {
- // Set nextFireTime to just before now, making readyToFire() true.
- nextFireTime = AbsTime(sys::now(), Duration(-1));
-}
-
-
+// TODO AStitcher 21/08/09 The threshholds for emitting warnings are a little arbitrary
Timer::Timer() :
active(false),
late(50 * TIME_MSEC),
overran(2 * TIME_MSEC),
lateCancel(500 * TIME_MSEC),
- warn(5 * TIME_SEC)
+ warn(60 * TIME_SEC)
{
start();
}
@@ -133,7 +128,6 @@ public:
}
};
-// TODO AStitcher 21/08/09 The threshholds for emitting warnings are a little arbitrary
void Timer::run()
{
Monitor::ScopedLock l(monitor);
@@ -151,10 +145,6 @@ void Timer::run()
{
TimerTaskCallbackScope s(*t);
if (s) {
- {
- Monitor::ScopedUnlock u(monitor);
- drop(t);
- }
if (delay > lateCancel) {
QPID_LOG(debug, t->name << " cancelled timer woken up " <<
delay / TIME_MSEC << "ms late");
@@ -171,8 +161,8 @@ void Timer::run()
if (!tasks.empty()) {
overrun = Duration(tasks.top()->nextFireTime, end);
}
- bool warningsEnabled;
- QPID_LOG_TEST(warning, warningsEnabled);
+ bool warningsEnabled; // TimerWarning enabled
+ QPID_LOG_TEST(debug, warningsEnabled); // TimerWarning emitted at debug level
if (warningsEnabled) {
if (overrun > overran) {
if (delay > overran) // if delay is significant to an overrun.
@@ -235,9 +225,6 @@ void Timer::fire(boost::intrusive_ptr<TimerTask> t) {
}
}
-// Provided for subclasses: called when a task is droped.
-void Timer::drop(boost::intrusive_ptr<TimerTask>) {}
-
bool operator<(const intrusive_ptr<TimerTask>& a,
const intrusive_ptr<TimerTask>& b)
{
diff --git a/cpp/src/qpid/sys/Timer.h b/cpp/src/qpid/sys/Timer.h
index 5731b8d977..5045009609 100644
--- a/cpp/src/qpid/sys/Timer.h
+++ b/cpp/src/qpid/sys/Timer.h
@@ -67,10 +67,6 @@ class TimerTask : public RefCounted {
std::string getName() const { return name; }
- // Move the nextFireTime so readyToFire is true.
- // Used by the cluster, where tasks are fired on cluster events, not on local time.
- QPID_COMMON_EXTERN void setFired();
-
protected:
// Must be overridden with callback
virtual void fire() = 0;
@@ -99,7 +95,7 @@ class Timer : private Runnable {
protected:
QPID_COMMON_EXTERN virtual void fire(boost::intrusive_ptr<TimerTask> task);
- QPID_COMMON_EXTERN virtual void drop(boost::intrusive_ptr<TimerTask> task);
+
// Allow derived classes to change the late/overran thresholds.
Duration late;
Duration overran;
diff --git a/cpp/src/qpid/sys/TimerWarnings.cpp b/cpp/src/qpid/sys/TimerWarnings.cpp
index 85e26da54a..00fb0d9db6 100644
--- a/cpp/src/qpid/sys/TimerWarnings.cpp
+++ b/cpp/src/qpid/sys/TimerWarnings.cpp
@@ -56,18 +56,18 @@ void TimerWarnings::log() {
std::string task = i->first;
TaskStats& stats = i->second;
if (stats.lateDelay.count)
- QPID_LOG(info, task << " task late "
+ QPID_LOG(debug, task << " task late "
<< stats.lateDelay.count << " times by "
<< stats.lateDelay.average()/TIME_MSEC << "ms on average.");
if (stats.overranOverrun.count)
- QPID_LOG(info, task << " task overran "
+ QPID_LOG(debug, task << " task overran "
<< stats.overranOverrun.count << " times by "
<< stats.overranOverrun.average()/TIME_MSEC << "ms (taking "
<< stats.overranTime.average() << "ns) on average.");
if (stats.lateAndOverranOverrun.count)
- QPID_LOG(info, task << " task late and overran "
+ QPID_LOG(debug, task << " task late and overran "
<< stats.lateAndOverranOverrun.count << " times: late "
<< stats.lateAndOverranDelay.average()/TIME_MSEC << "ms, overran "
<< stats.lateAndOverranOverrun.average()/TIME_MSEC << "ms (taking "
diff --git a/cpp/src/qpid/sys/alloca.h b/cpp/src/qpid/sys/alloca.h
deleted file mode 100644
index b3f59b7c3f..0000000000
--- a/cpp/src/qpid/sys/alloca.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef QPID_SYS_ALLOCA_H
-#define QPID_SYS_ALLOCA_H
-
-/*
- * 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.
- *
- */
-
-#if (defined(_WINDOWS) || defined (WIN32))
-# include <malloc.h>
-
-# if defined(_MSC_VER)
-# ifdef alloc
-# undef alloc
-# endif
-# define alloc _alloc
-# ifdef alloca
-# undef alloca
-# endif
-# define alloca _alloca
-# endif
-#endif
-#if !defined _WINDOWS && !defined WIN32
-# include <alloca.h>
-#endif
-
-#endif /*!QPID_SYS_ALLOCA_H*/
diff --git a/cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.cpp b/cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.cpp
index 29b91f3e7a..79d9d08a59 100644
--- a/cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.cpp
+++ b/cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.cpp
@@ -29,8 +29,8 @@ namespace qpid {
namespace sys {
namespace cyrus {
-CyrusSecurityLayer::CyrusSecurityLayer(sasl_conn_t* c, uint16_t maxFrameSize) :
- conn(c), decrypted(0), decryptedSize(0), encrypted(0), encryptedSize(0), codec(0), maxInputSize(0),
+CyrusSecurityLayer::CyrusSecurityLayer(sasl_conn_t* c, uint16_t maxFrameSize, int ssf) :
+ SecurityLayer(ssf), conn(c), decrypted(0), decryptedSize(0), encrypted(0), encryptedSize(0), codec(0), maxInputSize(0),
decodeBuffer(maxFrameSize), encodeBuffer(maxFrameSize), encoded(0)
{
const void* value(0);
@@ -68,7 +68,7 @@ size_t CyrusSecurityLayer::decode(const char* input, size_t size)
return size;
}
-size_t CyrusSecurityLayer::encode(const char* buffer, size_t size)
+size_t CyrusSecurityLayer::encode(char* buffer, size_t size)
{
size_t processed = 0;//records how many bytes have been written to buffer
do {
@@ -92,12 +92,12 @@ size_t CyrusSecurityLayer::encode(const char* buffer, size_t size)
//can't fit all encrypted data in the buffer we've
//been given, copy in what we can and hold on to the
//rest until the next call
- ::memcpy(const_cast<char*>(buffer + processed), encrypted, remaining);
+ ::memcpy(buffer + processed, encrypted, remaining);
processed += remaining;
encrypted += remaining;
encryptedSize -= remaining;
} else {
- ::memcpy(const_cast<char*>(buffer + processed), encrypted, encryptedSize);
+ ::memcpy(buffer + processed, encrypted, encryptedSize);
processed += encryptedSize;
encrypted = 0;
encryptedSize = 0;
diff --git a/cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.h b/cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.h
index 1645cf1a58..ae86ba5569 100644
--- a/cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.h
+++ b/cpp/src/qpid/sys/cyrus/CyrusSecurityLayer.h
@@ -37,9 +37,9 @@ namespace cyrus {
class CyrusSecurityLayer : public qpid::sys::SecurityLayer
{
public:
- CyrusSecurityLayer(sasl_conn_t*, uint16_t maxFrameSize);
+ CyrusSecurityLayer(sasl_conn_t*, uint16_t maxFrameSize, int ssf);
size_t decode(const char* buffer, size_t size);
- size_t encode(const char* buffer, size_t size);
+ size_t encode(char* buffer, size_t size);
bool canEncode();
void init(qpid::sys::Codec*);
private:
diff --git a/cpp/src/qpid/sys/epoll/EpollPoller.cpp b/cpp/src/qpid/sys/epoll/EpollPoller.cpp
index c23403c66d..6fdf99637f 100644
--- a/cpp/src/qpid/sys/epoll/EpollPoller.cpp
+++ b/cpp/src/qpid/sys/epoll/EpollPoller.cpp
@@ -20,7 +20,6 @@
*/
#include "qpid/sys/Poller.h"
-#include "qpid/sys/IOHandle.h"
#include "qpid/sys/Mutex.h"
#include "qpid/sys/AtomicCount.h"
#include "qpid/sys/DeletionManager.h"
@@ -64,12 +63,12 @@ class PollerHandlePrivate {
};
::__uint32_t events;
- const IOHandlePrivate* ioHandle;
+ const IOHandle* ioHandle;
PollerHandle* pollerHandle;
FDStat stat;
Mutex lock;
- PollerHandlePrivate(const IOHandlePrivate* h, PollerHandle* p) :
+ PollerHandlePrivate(const IOHandle* h, PollerHandle* p) :
events(0),
ioHandle(h),
pollerHandle(p),
@@ -77,7 +76,7 @@ class PollerHandlePrivate {
}
int fd() const {
- return toFd(ioHandle);
+ return ioHandle->fd;
}
bool isActive() const {
@@ -138,7 +137,7 @@ class PollerHandlePrivate {
};
PollerHandle::PollerHandle(const IOHandle& h) :
- impl(new PollerHandlePrivate(h.impl, this))
+ impl(new PollerHandlePrivate(&h, this))
{}
PollerHandle::~PollerHandle() {
@@ -385,6 +384,7 @@ void PollerPrivate::resetMode(PollerHandlePrivate& eh) {
int rc = ::epoll_ctl(epollFd, EPOLL_CTL_MOD, eh.fd(), &epe);
// If something has closed the fd in the meantime try adding it back
if (rc ==-1 && errno == ENOENT) {
+ eh.setIdle(); // Reset our handle as if starting from scratch
rc = ::epoll_ctl(epollFd, EPOLL_CTL_ADD, eh.fd(), &epe);
}
QPID_POSIX_CHECK(rc);
diff --git a/cpp/src/qpid/sys/posix/AsynchIO.cpp b/cpp/src/qpid/sys/posix/AsynchIO.cpp
index 31355627cd..353a55f50c 100644
--- a/cpp/src/qpid/sys/posix/AsynchIO.cpp
+++ b/cpp/src/qpid/sys/posix/AsynchIO.cpp
@@ -143,6 +143,7 @@ class AsynchConnector : public qpid::sys::AsynchConnector,
private:
void connComplete(DispatchHandle& handle);
+ void requestedCall(RequestCallback rCb);
private:
ConnectedCallback connCallback;
@@ -158,6 +159,7 @@ public:
FailedCallback failCb);
void start(Poller::shared_ptr poller);
void stop();
+ void requestCallback(RequestCallback rCb);
};
AsynchConnector::AsynchConnector(const Socket& s,
@@ -191,11 +193,30 @@ void AsynchConnector::stop()
stopWatch();
}
+void AsynchConnector::requestCallback(RequestCallback callback) {
+ // TODO creating a function object every time isn't all that
+ // efficient - if this becomes heavily used do something better (what?)
+ assert(callback);
+ DispatchHandle::call(boost::bind(&AsynchConnector::requestedCall, this, callback));
+}
+
+void AsynchConnector::requestedCall(RequestCallback callback) {
+ assert(callback);
+ callback(*this);
+}
+
void AsynchConnector::connComplete(DispatchHandle& h)
{
int errCode = socket.getError();
if (errCode == 0) {
h.stopWatch();
+ try {
+ socket.finishConnect(sa);
+ } catch (const std::exception& e) {
+ failCallback(socket, 0, e.what());
+ DispatchHandle::doDelete();
+ return;
+ }
connCallback(socket);
} else {
// Retry while we cause an immediate exception
@@ -247,10 +268,9 @@ public:
virtual void notifyPendingWrite();
virtual void queueWriteClose();
virtual bool writeQueueEmpty();
- virtual void startReading();
- virtual void stopReading();
virtual void requestCallback(RequestCallback);
virtual BufferBase* getQueuedBuffer();
+ virtual SecuritySettings getSecuritySettings();
private:
~AsynchIO();
@@ -282,13 +302,6 @@ private:
* thread processing this handle.
*/
volatile bool writePending;
- /**
- * This records whether we've been reading is flow controlled:
- * it's safe as a simple boolean as the only way to be stopped
- * is in calls only allowed in the callback context, the only calls
- * checking it are also in calls only allowed in callback context.
- */
- volatile bool readingStopped;
};
AsynchIO::AsynchIO(const Socket& s,
@@ -307,8 +320,7 @@ AsynchIO::AsynchIO(const Socket& s,
idleCallback(iCb),
socket(s),
queuedClose(false),
- writePending(false),
- readingStopped(false) {
+ writePending(false) {
s.setNonblocking();
}
@@ -344,7 +356,7 @@ void AsynchIO::queueReadBuffer(BufferBase* buff) {
bool queueWasEmpty = bufferQueue.empty();
bufferQueue.push_back(buff);
- if (queueWasEmpty && !readingStopped)
+ if (queueWasEmpty)
DispatchHandle::rewatchRead();
}
@@ -354,7 +366,7 @@ void AsynchIO::unread(BufferBase* buff) {
bool queueWasEmpty = bufferQueue.empty();
bufferQueue.push_front(buff);
- if (queueWasEmpty && !readingStopped)
+ if (queueWasEmpty)
DispatchHandle::rewatchRead();
}
@@ -386,17 +398,6 @@ bool AsynchIO::writeQueueEmpty() {
return writeQueue.empty();
}
-// This can happen outside the callback context
-void AsynchIO::startReading() {
- readingStopped = false;
- DispatchHandle::rewatchRead();
-}
-
-void AsynchIO::stopReading() {
- readingStopped = true;
- DispatchHandle::unwatchRead();
-}
-
void AsynchIO::requestCallback(RequestCallback callback) {
// TODO creating a function object every time isn't all that
// efficient - if this becomes heavily used do something better (what?)
@@ -429,11 +430,6 @@ AsynchIO::BufferBase* AsynchIO::getQueuedBuffer() {
* to put it in and reading is not stopped by flow control.
*/
void AsynchIO::readable(DispatchHandle& h) {
- if (readingStopped) {
- // We have been flow controlled.
- QPID_PROBE1(asynchio_read_flowcontrolled, &h);
- return;
- }
AbsTime readStartTime = AbsTime::now();
size_t total = 0;
int readCalls = 0;
@@ -455,12 +451,6 @@ void AsynchIO::readable(DispatchHandle& h) {
total += rc;
readCallback(*this, buff);
- if (readingStopped) {
- // We have been flow controlled.
- QPID_PROBE4(asynchio_read_finished_flowcontrolled, &h, duration, total, readCalls);
- break;
- }
-
if (rc != readCount) {
// If we didn't fill the read buffer then time to stop reading
QPID_PROBE4(asynchio_read_finished_done, &h, duration, total, readCalls);
@@ -626,6 +616,13 @@ void AsynchIO::close(DispatchHandle& h) {
}
}
+SecuritySettings AsynchIO::getSecuritySettings() {
+ SecuritySettings settings;
+ settings.ssf = socket.getKeyLen();
+ settings.authid = socket.getClientAuthId();
+ return settings;
+}
+
} // namespace posix
AsynchAcceptor* AsynchAcceptor::create(const Socket& s,
diff --git a/cpp/src/qpid/sys/posix/BSDSocket.cpp b/cpp/src/qpid/sys/posix/BSDSocket.cpp
new file mode 100644
index 0000000000..7c31b13ae9
--- /dev/null
+++ b/cpp/src/qpid/sys/posix/BSDSocket.cpp
@@ -0,0 +1,264 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/sys/posix/BSDSocket.h"
+
+#include "qpid/sys/SocketAddress.h"
+#include "qpid/sys/posix/check.h"
+#include "qpid/sys/posix/PrivatePosix.h"
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/errno.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <netdb.h>
+#include <cstdlib>
+#include <string.h>
+
+namespace qpid {
+namespace sys {
+
+namespace {
+std::string getName(int fd, bool local)
+{
+ ::sockaddr_storage name_s; // big enough for any socket address
+ ::sockaddr* name = (::sockaddr*)&name_s;
+ ::socklen_t namelen = sizeof(name_s);
+
+ if (local) {
+ QPID_POSIX_CHECK( ::getsockname(fd, name, &namelen) );
+ } else {
+ QPID_POSIX_CHECK( ::getpeername(fd, name, &namelen) );
+ }
+
+ return SocketAddress::asString(name, namelen);
+}
+
+uint16_t getLocalPort(int fd)
+{
+ ::sockaddr_storage name_s; // big enough for any socket address
+ ::sockaddr* name = (::sockaddr*)&name_s;
+ ::socklen_t namelen = sizeof(name_s);
+
+ QPID_POSIX_CHECK( ::getsockname(fd, name, &namelen) );
+
+ return SocketAddress::getPort(name);
+}
+}
+
+BSDSocket::BSDSocket() :
+ fd(-1),
+ handle(new IOHandle),
+ nonblocking(false),
+ nodelay(false)
+{}
+
+Socket* createSocket()
+{
+ return new BSDSocket;
+}
+
+BSDSocket::BSDSocket(int fd0) :
+ fd(fd0),
+ handle(new IOHandle(fd)),
+ nonblocking(false),
+ nodelay(false)
+{}
+
+BSDSocket::~BSDSocket()
+{}
+
+BSDSocket::operator const IOHandle&() const
+{
+ return *handle;
+}
+
+void BSDSocket::createSocket(const SocketAddress& sa) const
+{
+ int& socket = fd;
+ if (socket != -1) BSDSocket::close();
+ int s = ::socket(getAddrInfo(sa).ai_family, getAddrInfo(sa).ai_socktype, 0);
+ if (s < 0) throw QPID_POSIX_ERROR(errno);
+ socket = s;
+ *handle = IOHandle(s);
+
+ try {
+ if (nonblocking) setNonblocking();
+ if (nodelay) setTcpNoDelay();
+ if (getAddrInfo(sa).ai_family == AF_INET6) {
+ int flag = 1;
+ int result = ::setsockopt(socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&flag, sizeof(flag));
+ QPID_POSIX_CHECK(result);
+ }
+ } catch (std::exception&) {
+ ::close(s);
+ socket = -1;
+ *handle = IOHandle();
+ throw;
+ }
+}
+
+void BSDSocket::setNonblocking() const {
+ int& socket = fd;
+ nonblocking = true;
+ if (socket != -1) {
+ QPID_POSIX_CHECK(::fcntl(socket, F_SETFL, O_NONBLOCK));
+ }
+}
+
+void BSDSocket::setTcpNoDelay() const
+{
+ int& socket = fd;
+ nodelay = true;
+ if (socket != -1) {
+ int flag = 1;
+ int result = ::setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
+ QPID_POSIX_CHECK(result);
+ }
+}
+
+void BSDSocket::connect(const SocketAddress& addr) const
+{
+ // The display name for an outbound connection needs to be the name that was specified
+ // for the address rather than a resolved IP address as we don't know which of
+ // the IP addresses is actually the one that will be connected to.
+ peername = addr.asString(false);
+
+ // However the string we compare with the local port must be numeric or it might not
+ // match when it should as getLocalAddress() will always be numeric
+ std::string connectname = addr.asString();
+
+ createSocket(addr);
+
+ const int& socket = fd;
+ // TODO the correct thing to do here is loop on failure until you've used all the returned addresses
+ if ((::connect(socket, getAddrInfo(addr).ai_addr, getAddrInfo(addr).ai_addrlen) < 0) &&
+ (errno != EINPROGRESS)) {
+ throw Exception(QPID_MSG(strError(errno) << ": " << peername));
+ }
+ // When connecting to a port on the same host which no longer has
+ // a process associated with it, the OS occasionally chooses the
+ // remote port (which is unoccupied) as the port to bind the local
+ // end of the socket, resulting in a "circular" connection.
+ //
+ // Raise an error if we see such a connection, since we know there is
+ // no listener on the peer address.
+ //
+ if (getLocalAddress() == connectname) {
+ close();
+ throw Exception(QPID_MSG("Connection refused: " << peername));
+ }
+}
+
+void BSDSocket::finishConnect(const SocketAddress&) const
+{
+}
+
+void
+BSDSocket::close() const
+{
+ int& socket = fd;
+ if (socket == -1) return;
+ if (::close(socket) < 0) throw QPID_POSIX_ERROR(errno);
+ socket = -1;
+ *handle = IOHandle();
+}
+
+int BSDSocket::listen(const SocketAddress& sa, int backlog) const
+{
+ createSocket(sa);
+
+ const int& socket = fd;
+ int yes=1;
+ QPID_POSIX_CHECK(::setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)));
+
+ if (::bind(socket, getAddrInfo(sa).ai_addr, getAddrInfo(sa).ai_addrlen) < 0)
+ throw Exception(QPID_MSG("Can't bind to port " << sa.asString() << ": " << strError(errno)));
+ if (::listen(socket, backlog) < 0)
+ throw Exception(QPID_MSG("Can't listen on port " << sa.asString() << ": " << strError(errno)));
+
+ return getLocalPort(socket);
+}
+
+Socket* BSDSocket::accept() const
+{
+ int afd = ::accept(fd, 0, 0);
+ if ( afd >= 0) {
+ BSDSocket* s = new BSDSocket(afd);
+ s->localname = localname;
+ return s;
+ }
+ else if (errno == EAGAIN)
+ return 0;
+ else throw QPID_POSIX_ERROR(errno);
+}
+
+int BSDSocket::read(void *buf, size_t count) const
+{
+ return ::read(fd, buf, count);
+}
+
+int BSDSocket::write(const void *buf, size_t count) const
+{
+ return ::write(fd, buf, count);
+}
+
+std::string BSDSocket::getPeerAddress() const
+{
+ if (peername.empty()) {
+ peername = getName(fd, false);
+ }
+ return peername;
+}
+
+std::string BSDSocket::getLocalAddress() const
+{
+ if (localname.empty()) {
+ localname = getName(fd, true);
+ }
+ return localname;
+}
+
+int BSDSocket::getError() const
+{
+ int result;
+ socklen_t rSize = sizeof (result);
+
+ if (::getsockopt(fd, SOL_SOCKET, SO_ERROR, &result, &rSize) < 0)
+ throw QPID_POSIX_ERROR(errno);
+
+ return result;
+}
+
+int BSDSocket::getKeyLen() const
+{
+ return 0;
+}
+
+std::string BSDSocket::getClientAuthId() const
+{
+ return std::string();
+}
+
+}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/posix/BSDSocket.h b/cpp/src/qpid/sys/posix/BSDSocket.h
new file mode 100644
index 0000000000..862d36c1b9
--- /dev/null
+++ b/cpp/src/qpid/sys/posix/BSDSocket.h
@@ -0,0 +1,113 @@
+#ifndef QPID_SYS_BSDSOCKET_H
+#define QPID_SYS_BSDSOCKET_H
+
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/sys/Socket.h"
+#include "qpid/sys/IntegerTypes.h"
+#include "qpid/CommonImportExport.h"
+#include <string>
+
+#include <boost/scoped_ptr.hpp>
+
+namespace qpid {
+namespace sys {
+
+class Duration;
+class IOHandle;
+class SocketAddress;
+
+namespace ssl {
+class SslMuxSocket;
+}
+
+class QPID_COMMON_CLASS_EXTERN BSDSocket : public Socket
+{
+public:
+ /** Create a socket wrapper for descriptor. */
+ QPID_COMMON_EXTERN BSDSocket();
+ QPID_COMMON_EXTERN ~BSDSocket();
+
+ QPID_COMMON_EXTERN operator const IOHandle&() const;
+
+ /** Set socket non blocking */
+ QPID_COMMON_EXTERN virtual void setNonblocking() const;
+
+ QPID_COMMON_EXTERN virtual void setTcpNoDelay() const;
+
+ QPID_COMMON_EXTERN virtual void connect(const SocketAddress&) const;
+ QPID_COMMON_EXTERN virtual void finishConnect(const SocketAddress&) const;
+
+ QPID_COMMON_EXTERN virtual void close() const;
+
+ /** Bind to a port and start listening.
+ *@return The bound port number
+ */
+ QPID_COMMON_EXTERN virtual int listen(const SocketAddress&, int backlog = 10) const;
+
+ /**
+ * Returns an address (host and port) for the remote end of the
+ * socket
+ */
+ QPID_COMMON_EXTERN std::string getPeerAddress() const;
+ /**
+ * Returns an address (host and port) for the local end of the
+ * socket
+ */
+ QPID_COMMON_EXTERN std::string getLocalAddress() const;
+
+ /**
+ * Returns the error code stored in the socket. This may be used
+ * to determine the result of a non-blocking connect.
+ */
+ QPID_COMMON_EXTERN int getError() const;
+
+ /** Accept a connection from a socket that is already listening
+ * and has an incoming connection
+ */
+ QPID_COMMON_EXTERN virtual Socket* accept() const;
+
+ // TODO The following are raw operations, maybe they need better wrapping?
+ QPID_COMMON_EXTERN virtual int read(void *buf, size_t count) const;
+ QPID_COMMON_EXTERN virtual int write(const void *buf, size_t count) const;
+
+ QPID_COMMON_EXTERN int getKeyLen() const;
+ QPID_COMMON_EXTERN std::string getClientAuthId() const;
+
+protected:
+ /** Create socket */
+ void createSocket(const SocketAddress&) const;
+
+ mutable int fd;
+ mutable boost::scoped_ptr<IOHandle> handle;
+ mutable std::string localname;
+ mutable std::string peername;
+ mutable bool nonblocking;
+ mutable bool nodelay;
+
+ /** Construct socket with existing handle */
+ BSDSocket(int fd);
+ friend class qpid::sys::ssl::SslMuxSocket; // Needed for this constructor
+};
+
+}}
+#endif /*!QPID_SYS_BSDSOCKET_H*/
diff --git a/cpp/src/qpid/sys/posix/FileSysDir.cpp b/cpp/src/qpid/sys/posix/FileSysDir.cpp
index 22dc487e74..cec580164d 100755
--- a/cpp/src/qpid/sys/posix/FileSysDir.cpp
+++ b/cpp/src/qpid/sys/posix/FileSysDir.cpp
@@ -18,6 +18,7 @@
#include "qpid/sys/FileSysDir.h"
#include "qpid/sys/StrError.h"
+#include "qpid/log/Statement.h"
#include "qpid/Exception.h"
#include <sys/types.h>
@@ -25,6 +26,8 @@
#include <fcntl.h>
#include <cerrno>
#include <unistd.h>
+#include <dirent.h>
+#include <stdlib.h>
namespace qpid {
namespace sys {
@@ -51,4 +54,27 @@ void FileSysDir::mkdir(void)
throw Exception ("Can't create directory: " + dirPath);
}
+void FileSysDir::forEachFile(Callback cb) const {
+
+ ::dirent** namelist;
+
+ int n = scandir(dirPath.c_str(), &namelist, 0, alphasort);
+ if (n == -1) throw Exception (strError(errno) + ": Can't scan directory: " + dirPath);
+
+ for (int i = 0; i<n; ++i) {
+ std::string fullpath = dirPath + "/" + namelist[i]->d_name;
+ // Filter out non files/stat problems etc.
+ struct ::stat s;
+ // Can't throw here without leaking memory, so just do nothing with
+ // entries for which stat() fails.
+ if (!::stat(fullpath.c_str(), &s)) {
+ if (S_ISREG(s.st_mode)) {
+ cb(fullpath);
+ }
+ }
+ ::free(namelist[i]);
+ }
+ ::free(namelist);
+}
+
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/posix/IOHandle.cpp b/cpp/src/qpid/sys/posix/IOHandle.cpp
index 9c049ee1de..d3f502a63c 100644
--- a/cpp/src/qpid/sys/posix/IOHandle.cpp
+++ b/cpp/src/qpid/sys/posix/IOHandle.cpp
@@ -19,26 +19,11 @@
*
*/
-#include "qpid/sys/IOHandle.h"
-
#include "qpid/sys/posix/PrivatePosix.h"
namespace qpid {
namespace sys {
-int toFd(const IOHandlePrivate* h)
-{
- return h->fd;
-}
-
NullIOHandle DummyIOHandle;
-IOHandle::IOHandle(IOHandlePrivate* h) :
- impl(h)
-{}
-
-IOHandle::~IOHandle() {
- delete impl;
-}
-
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/posix/PollableCondition.cpp b/cpp/src/qpid/sys/posix/PollableCondition.cpp
index abff8a5be8..aa129faf20 100644
--- a/cpp/src/qpid/sys/posix/PollableCondition.cpp
+++ b/cpp/src/qpid/sys/posix/PollableCondition.cpp
@@ -21,7 +21,6 @@
#include "qpid/sys/PollableCondition.h"
#include "qpid/sys/DispatchHandle.h"
-#include "qpid/sys/IOHandle.h"
#include "qpid/sys/posix/PrivatePosix.h"
#include "qpid/Exception.h"
@@ -58,14 +57,14 @@ PollableConditionPrivate::PollableConditionPrivate(
const sys::PollableCondition::Callback& cb,
sys::PollableCondition& parent,
const boost::shared_ptr<sys::Poller>& poller
-) : IOHandle(new sys::IOHandlePrivate), cb(cb), parent(parent)
+) : cb(cb), parent(parent)
{
int fds[2];
if (::pipe(fds) == -1)
throw ErrnoException(QPID_MSG("Can't create PollableCondition"));
- impl->fd = fds[0];
+ fd = fds[0];
writeFd = fds[1];
- if (::fcntl(impl->fd, F_SETFL, O_NONBLOCK) == -1)
+ if (::fcntl(fd, F_SETFL, O_NONBLOCK) == -1)
throw ErrnoException(QPID_MSG("Can't create PollableCondition"));
if (::fcntl(writeFd, F_SETFL, O_NONBLOCK) == -1)
throw ErrnoException(QPID_MSG("Can't create PollableCondition"));
diff --git a/cpp/src/qpid/sys/posix/PosixPoller.cpp b/cpp/src/qpid/sys/posix/PosixPoller.cpp
index eb0c3384d1..ae839b2e20 100644
--- a/cpp/src/qpid/sys/posix/PosixPoller.cpp
+++ b/cpp/src/qpid/sys/posix/PosixPoller.cpp
@@ -88,12 +88,12 @@ class PollerHandlePrivate {
};
short events;
- const IOHandlePrivate* ioHandle;
+ const IOHandle* ioHandle;
PollerHandle* pollerHandle;
FDStat stat;
Mutex lock;
- PollerHandlePrivate(const IOHandlePrivate* h, PollerHandle* p) :
+ PollerHandlePrivate(const IOHandle* h, PollerHandle* p) :
events(0),
ioHandle(h),
pollerHandle(p),
@@ -101,7 +101,7 @@ class PollerHandlePrivate {
}
int fd() const {
- return toFd(ioHandle);
+ return ioHandle->fd;
}
bool isActive() const {
@@ -162,7 +162,7 @@ class PollerHandlePrivate {
};
PollerHandle::PollerHandle(const IOHandle& h) :
- impl(new PollerHandlePrivate(h.impl, this))
+ impl(new PollerHandlePrivate(&h, this))
{}
PollerHandle::~PollerHandle() {
diff --git a/cpp/src/qpid/sys/posix/Socket.cpp b/cpp/src/qpid/sys/posix/Socket.cpp
deleted file mode 100644
index 77ae1af60c..0000000000
--- a/cpp/src/qpid/sys/posix/Socket.cpp
+++ /dev/null
@@ -1,263 +0,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.
- *
- */
-
-#include "qpid/sys/Socket.h"
-
-#include "qpid/sys/SocketAddress.h"
-#include "qpid/sys/posix/check.h"
-#include "qpid/sys/posix/PrivatePosix.h"
-
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/errno.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <cstdlib>
-#include <string.h>
-
-namespace qpid {
-namespace sys {
-
-namespace {
-std::string getName(int fd, bool local)
-{
- ::sockaddr_storage name_s; // big enough for any socket address
- ::sockaddr* name = (::sockaddr*)&name_s;
- ::socklen_t namelen = sizeof(name_s);
-
- if (local) {
- QPID_POSIX_CHECK( ::getsockname(fd, name, &namelen) );
- } else {
- QPID_POSIX_CHECK( ::getpeername(fd, name, &namelen) );
- }
-
- return SocketAddress::asString(name, namelen);
-}
-
-uint16_t getLocalPort(int fd)
-{
- ::sockaddr_storage name_s; // big enough for any socket address
- ::sockaddr* name = (::sockaddr*)&name_s;
- ::socklen_t namelen = sizeof(name_s);
-
- QPID_POSIX_CHECK( ::getsockname(fd, name, &namelen) );
-
- return SocketAddress::getPort(name);
-}
-}
-
-Socket::Socket() :
- IOHandle(new IOHandlePrivate),
- nonblocking(false),
- nodelay(false)
-{}
-
-Socket::Socket(IOHandlePrivate* h) :
- IOHandle(h),
- nonblocking(false),
- nodelay(false)
-{}
-
-void Socket::createSocket(const SocketAddress& sa) const
-{
- int& socket = impl->fd;
- if (socket != -1) Socket::close();
- int s = ::socket(getAddrInfo(sa).ai_family, getAddrInfo(sa).ai_socktype, 0);
- if (s < 0) throw QPID_POSIX_ERROR(errno);
- socket = s;
-
- try {
- if (nonblocking) setNonblocking();
- if (nodelay) setTcpNoDelay();
- if (getAddrInfo(sa).ai_family == AF_INET6) {
- int flag = 1;
- int result = ::setsockopt(socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&flag, sizeof(flag));
- QPID_POSIX_CHECK(result);
- }
- } catch (std::exception&) {
- ::close(s);
- socket = -1;
- throw;
- }
-}
-
-Socket* Socket::createSameTypeSocket() const {
- int& socket = impl->fd;
- // Socket currently has no actual socket attached
- if (socket == -1)
- return new Socket;
-
- ::sockaddr_storage sa;
- ::socklen_t salen = sizeof(sa);
- QPID_POSIX_CHECK(::getsockname(socket, (::sockaddr*)&sa, &salen));
- int s = ::socket(sa.ss_family, SOCK_STREAM, 0); // Currently only work with SOCK_STREAM
- if (s < 0) throw QPID_POSIX_ERROR(errno);
- return new Socket(new IOHandlePrivate(s));
-}
-
-void Socket::setNonblocking() const {
- int& socket = impl->fd;
- nonblocking = true;
- if (socket != -1) {
- QPID_POSIX_CHECK(::fcntl(socket, F_SETFL, O_NONBLOCK));
- }
-}
-
-void Socket::setTcpNoDelay() const
-{
- int& socket = impl->fd;
- nodelay = true;
- if (socket != -1) {
- int flag = 1;
- int result = ::setsockopt(impl->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
- QPID_POSIX_CHECK(result);
- }
-}
-
-void Socket::connect(const std::string& host, const std::string& port) const
-{
- SocketAddress sa(host, port);
- connect(sa);
-}
-
-void Socket::connect(const SocketAddress& addr) const
-{
- // The display name for an outbound connection needs to be the name that was specified
- // for the address rather than a resolved IP address as we don't know which of
- // the IP addresses is actually the one that will be connected to.
- peername = addr.asString(false);
-
- // However the string we compare with the local port must be numeric or it might not
- // match when it should as getLocalAddress() will always be numeric
- std::string connectname = addr.asString();
-
- createSocket(addr);
-
- const int& socket = impl->fd;
- // TODO the correct thing to do here is loop on failure until you've used all the returned addresses
- if ((::connect(socket, getAddrInfo(addr).ai_addr, getAddrInfo(addr).ai_addrlen) < 0) &&
- (errno != EINPROGRESS)) {
- throw Exception(QPID_MSG(strError(errno) << ": " << peername));
- }
- // When connecting to a port on the same host which no longer has
- // a process associated with it, the OS occasionally chooses the
- // remote port (which is unoccupied) as the port to bind the local
- // end of the socket, resulting in a "circular" connection.
- //
- // This seems like something the OS should prevent but I have
- // confirmed that sporadic hangs in
- // cluster_tests.LongTests.test_failover on RHEL5 are caused by
- // such a circular connection.
- //
- // Raise an error if we see such a connection, since we know there is
- // no listener on the peer address.
- //
- if (getLocalAddress() == connectname) {
- close();
- throw Exception(QPID_MSG("Connection refused: " << peername));
- }
-}
-
-void
-Socket::close() const
-{
- int& socket = impl->fd;
- if (socket == -1) return;
- if (::close(socket) < 0) throw QPID_POSIX_ERROR(errno);
- socket = -1;
-}
-
-int Socket::listen(const std::string& host, const std::string& port, int backlog) const
-{
- SocketAddress sa(host, port);
- return listen(sa, backlog);
-}
-
-int Socket::listen(const SocketAddress& sa, int backlog) const
-{
- createSocket(sa);
-
- const int& socket = impl->fd;
- int yes=1;
- QPID_POSIX_CHECK(::setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)));
-
- if (::bind(socket, getAddrInfo(sa).ai_addr, getAddrInfo(sa).ai_addrlen) < 0)
- throw Exception(QPID_MSG("Can't bind to port " << sa.asString() << ": " << strError(errno)));
- if (::listen(socket, backlog) < 0)
- throw Exception(QPID_MSG("Can't listen on port " << sa.asString() << ": " << strError(errno)));
-
- return getLocalPort(socket);
-}
-
-Socket* Socket::accept() const
-{
- int afd = ::accept(impl->fd, 0, 0);
- if ( afd >= 0) {
- Socket* s = new Socket(new IOHandlePrivate(afd));
- s->localname = localname;
- return s;
- }
- else if (errno == EAGAIN)
- return 0;
- else throw QPID_POSIX_ERROR(errno);
-}
-
-int Socket::read(void *buf, size_t count) const
-{
- return ::read(impl->fd, buf, count);
-}
-
-int Socket::write(const void *buf, size_t count) const
-{
- return ::write(impl->fd, buf, count);
-}
-
-std::string Socket::getPeerAddress() const
-{
- if (peername.empty()) {
- peername = getName(impl->fd, false);
- }
- return peername;
-}
-
-std::string Socket::getLocalAddress() const
-{
- if (localname.empty()) {
- localname = getName(impl->fd, true);
- }
- return localname;
-}
-
-int Socket::getError() const
-{
- int result;
- socklen_t rSize = sizeof (result);
-
- if (::getsockopt(impl->fd, SOL_SOCKET, SO_ERROR, &result, &rSize) < 0)
- throw QPID_POSIX_ERROR(errno);
-
- return result;
-}
-
-}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/posix/SocketAddress.cpp b/cpp/src/qpid/sys/posix/SocketAddress.cpp
index 344bd28669..cd23442226 100644
--- a/cpp/src/qpid/sys/posix/SocketAddress.cpp
+++ b/cpp/src/qpid/sys/posix/SocketAddress.cpp
@@ -102,6 +102,11 @@ std::string SocketAddress::asString(bool numeric) const
return asString(ai.ai_addr, ai.ai_addrlen);
}
+std::string SocketAddress::getHost() const
+{
+ return host;
+}
+
bool SocketAddress::nextAddress() {
bool r = currentAddrInfo->ai_next != 0;
if (r)
diff --git a/cpp/src/qpid/sys/posix/SystemInfo.cpp b/cpp/src/qpid/sys/posix/SystemInfo.cpp
index cfd2c64aee..ea7f521f2b 100755
--- a/cpp/src/qpid/sys/posix/SystemInfo.cpp
+++ b/cpp/src/qpid/sys/posix/SystemInfo.cpp
@@ -21,7 +21,6 @@
#include "qpid/log/Statement.h"
#include "qpid/sys/SystemInfo.h"
#include "qpid/sys/posix/check.h"
-#include <set>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/utsname.h>
@@ -33,6 +32,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
+#include <map>
#include <netdb.h>
#include <string.h>
@@ -77,84 +77,70 @@ inline bool isLoopback(const ::sockaddr* addr) {
}
}
-void SystemInfo::getLocalIpAddresses (uint16_t port,
- std::vector<Address> &addrList) {
- ::ifaddrs* ifaddr = 0;
- QPID_POSIX_CHECK(::getifaddrs(&ifaddr));
- for (::ifaddrs* ifap = ifaddr; ifap != 0; ifap = ifap->ifa_next) {
- if (ifap->ifa_addr == 0) continue;
- if (isLoopback(ifap->ifa_addr)) continue;
- int family = ifap->ifa_addr->sa_family;
- switch (family) {
- case AF_INET6: {
- // Ignore link local addresses as:
- // * The scope id is illegal in URL syntax
- // * Clients won't be able to use a link local address
- // without adding their own (potentially different) scope id
- sockaddr_in6* sa6 = (sockaddr_in6*)((void*)ifap->ifa_addr);
- if (IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr)) break;
- // Fallthrough
- }
- case AF_INET: {
- char dispName[NI_MAXHOST];
- int rc = ::getnameinfo(
- ifap->ifa_addr,
- (family == AF_INET)
- ? sizeof(struct sockaddr_in)
- : sizeof(struct sockaddr_in6),
- dispName, sizeof(dispName),
- 0, 0, NI_NUMERICHOST);
- if (rc != 0) {
- throw QPID_POSIX_ERROR(rc);
- }
- string addr(dispName);
- addrList.push_back(Address(TCP, addr, port));
- break;
- }
- default:
- continue;
+namespace {
+ inline socklen_t sa_len(::sockaddr* sa)
+ {
+ switch (sa->sa_family) {
+ case AF_INET:
+ return sizeof(struct sockaddr_in);
+ case AF_INET6:
+ return sizeof(struct sockaddr_in6);
+ default:
+ return sizeof(struct sockaddr_storage);
}
}
- ::freeifaddrs(ifaddr);
- if (addrList.empty()) {
- addrList.push_back(Address(TCP, LOOPBACK, port));
+ inline bool isInetOrInet6(::sockaddr* sa) {
+ switch (sa->sa_family) {
+ case AF_INET:
+ case AF_INET6:
+ return true;
+ default:
+ return false;
+ }
+ }
+ typedef std::map<std::string, std::vector<std::string> > InterfaceInfo;
+ std::map<std::string, std::vector<std::string> > cachedInterfaces;
+
+ void cacheInterfaceInfo() {
+ // Get interface info
+ ::ifaddrs* interfaceInfo;
+ QPID_POSIX_CHECK( ::getifaddrs(&interfaceInfo) );
+
+ char name[NI_MAXHOST];
+ for (::ifaddrs* info = interfaceInfo; info != 0; info = info->ifa_next) {
+
+ // Only use IPv4/IPv6 interfaces
+ if (!isInetOrInet6(info->ifa_addr)) continue;
+
+ int rc=::getnameinfo(info->ifa_addr, sa_len(info->ifa_addr),
+ name, sizeof(name), 0, 0,
+ NI_NUMERICHOST);
+ if (rc >= 0) {
+ std::string address(name);
+ cachedInterfaces[info->ifa_name].push_back(address);
+ } else {
+ throw qpid::Exception(QPID_MSG(gai_strerror(rc)));
+ }
+ }
+ ::freeifaddrs(interfaceInfo);
}
}
-namespace {
-struct AddrInfo {
- struct addrinfo* ptr;
- AddrInfo(const std::string& host) : ptr(0) {
- ::addrinfo hints;
- ::memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC; // Allow both IPv4 and IPv6
- if (::getaddrinfo(host.c_str(), NULL, &hints, &ptr) != 0)
- ptr = 0;
- }
- ~AddrInfo() { if (ptr) ::freeaddrinfo(ptr); }
-};
+bool SystemInfo::getInterfaceAddresses(const std::string& interface, std::vector<std::string>& addresses) {
+ if ( cachedInterfaces.empty() ) cacheInterfaceInfo();
+ InterfaceInfo::iterator i = cachedInterfaces.find(interface);
+ if ( i==cachedInterfaces.end() ) return false;
+ std::copy(i->second.begin(), i->second.end(), std::back_inserter(addresses));
+ return true;
}
-bool SystemInfo::isLocalHost(const std::string& host) {
- std::vector<Address> myAddrs;
- getLocalIpAddresses(0, myAddrs);
- std::set<string> localHosts;
- for (std::vector<Address>::const_iterator i = myAddrs.begin(); i != myAddrs.end(); ++i)
- localHosts.insert(i->host);
- // Resolve host
- AddrInfo ai(host);
- if (!ai.ptr) return false;
- for (struct addrinfo *res = ai.ptr; res != NULL; res = res->ai_next) {
- if (isLoopback(res->ai_addr)) return true;
- // Get string form of IP addr
- char addr[NI_MAXHOST] = "";
- int error = ::getnameinfo(res->ai_addr, res->ai_addrlen, addr, NI_MAXHOST, NULL, 0,
- NI_NUMERICHOST | NI_NUMERICSERV);
- if (error) return false;
- if (localHosts.find(addr) != localHosts.end()) return true;
+void SystemInfo::getInterfaceNames(std::vector<std::string>& names ) {
+ if ( cachedInterfaces.empty() ) cacheInterfaceInfo();
+
+ for (InterfaceInfo::const_iterator i = cachedInterfaces.begin(); i!=cachedInterfaces.end(); ++i) {
+ names.push_back(i->first);
}
- return false;
}
void SystemInfo::getSystemId (std::string &osName,
@@ -205,4 +191,11 @@ string SystemInfo::getProcessName()
return value;
}
+// Always true. Only Windows has exception cases.
+bool SystemInfo::threadSafeShutdown()
+{
+ return true;
+}
+
+
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/rdma/rdma_wrap.cpp b/cpp/src/qpid/sys/rdma/rdma_wrap.cpp
index efe454c5be..889ee9ff75 100644
--- a/cpp/src/qpid/sys/rdma/rdma_wrap.cpp
+++ b/cpp/src/qpid/sys/rdma/rdma_wrap.cpp
@@ -105,7 +105,7 @@ namespace Rdma {
}
QueuePair::QueuePair(boost::shared_ptr< ::rdma_cm_id > i) :
- qpid::sys::IOHandle(new qpid::sys::IOHandlePrivate),
+ handle(new qpid::sys::IOHandle),
pd(allocPd(i->verbs)),
cchannel(mkCChannel(i->verbs)),
scq(mkCq(i->verbs, DEFAULT_CQ_ENTRIES, 0, cchannel.get())),
@@ -113,7 +113,7 @@ namespace Rdma {
outstandingSendEvents(0),
outstandingRecvEvents(0)
{
- impl->fd = cchannel->fd;
+ handle->fd = cchannel->fd;
// Set cq context to this QueuePair object so we can find
// ourselves again
@@ -163,6 +163,11 @@ namespace Rdma {
// The buffers vectors automatically deletes all the buffers we've allocated
}
+ QueuePair::operator qpid::sys::IOHandle&() const
+ {
+ return *handle;
+ }
+
// Create buffers to use for writing
void QueuePair::createSendBuffers(int sendBufferCount, int bufferSize, int reserved)
{
@@ -359,11 +364,11 @@ namespace Rdma {
// Wrap the passed in rdma_cm_id with a Connection
// this basically happens only on connection request
Connection::Connection(::rdma_cm_id* i) :
- qpid::sys::IOHandle(new qpid::sys::IOHandlePrivate),
+ handle(new qpid::sys::IOHandle),
id(mkId(i)),
context(0)
{
- impl->fd = id->channel->fd;
+ handle->fd = id->channel->fd;
// Just overwrite the previous context as it will
// have come from the listening connection
@@ -372,12 +377,12 @@ namespace Rdma {
}
Connection::Connection() :
- qpid::sys::IOHandle(new qpid::sys::IOHandlePrivate),
+ handle(new qpid::sys::IOHandle),
channel(mkEChannel()),
id(mkId(channel.get(), this, RDMA_PS_TCP)),
context(0)
{
- impl->fd = channel->fd;
+ handle->fd = channel->fd;
}
Connection::~Connection() {
@@ -385,6 +390,11 @@ namespace Rdma {
id->context = 0;
}
+ Connection::operator qpid::sys::IOHandle&() const
+ {
+ return *handle;
+ }
+
void Connection::ensureQueuePair() {
assert(id.get());
diff --git a/cpp/src/qpid/sys/rdma/rdma_wrap.h b/cpp/src/qpid/sys/rdma/rdma_wrap.h
index 8e3429027b..5f84793a5b 100644
--- a/cpp/src/qpid/sys/rdma/rdma_wrap.h
+++ b/cpp/src/qpid/sys/rdma/rdma_wrap.h
@@ -28,6 +28,7 @@
#include "qpid/sys/Mutex.h"
#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/ptr_container/ptr_deque.hpp>
@@ -116,9 +117,10 @@ namespace Rdma {
// Wrapper for a queue pair - this has the functionality for
// putting buffers on the receive queue and for sending buffers
// to the other end of the connection.
- class QueuePair : public qpid::sys::IOHandle, public qpid::RefCounted {
+ class QueuePair : public qpid::RefCounted {
friend class Connection;
+ boost::scoped_ptr< qpid::sys::IOHandle > handle;
boost::shared_ptr< ::ibv_pd > pd;
boost::shared_ptr< ::ibv_mr > smr;
boost::shared_ptr< ::ibv_mr > rmr;
@@ -139,6 +141,8 @@ namespace Rdma {
public:
typedef boost::intrusive_ptr<QueuePair> intrusive_ptr;
+ operator qpid::sys::IOHandle&() const;
+
// Create a buffers to use for writing
void createSendBuffers(int sendBufferCount, int dataSize, int headerSize);
@@ -195,7 +199,8 @@ namespace Rdma {
// registered buffers can't be shared between different connections
// (this can only happen between connections on the same controller in any case,
// so needs careful management if used)
- class Connection : public qpid::sys::IOHandle, public qpid::RefCounted {
+ class Connection : public qpid::RefCounted {
+ boost::scoped_ptr< qpid::sys::IOHandle > handle;
boost::shared_ptr< ::rdma_event_channel > channel;
boost::shared_ptr< ::rdma_cm_id > id;
QueuePair::intrusive_ptr qp;
@@ -216,6 +221,8 @@ namespace Rdma {
public:
typedef boost::intrusive_ptr<Connection> intrusive_ptr;
+ operator qpid::sys::IOHandle&() const;
+
static intrusive_ptr make();
static intrusive_ptr find(::rdma_cm_id* i);
diff --git a/cpp/src/qpid/sys/solaris/SystemInfo.cpp b/cpp/src/qpid/sys/solaris/SystemInfo.cpp
index e5856f55e6..0e754e048b 100755
--- a/cpp/src/qpid/sys/solaris/SystemInfo.cpp
+++ b/cpp/src/qpid/sys/solaris/SystemInfo.cpp
@@ -60,31 +60,6 @@ bool SystemInfo::getLocalHostname(Address &address) {
static const string LOCALHOST("127.0.0.1");
static const string TCP("tcp");
-void SystemInfo::getLocalIpAddresses(uint16_t port,
- std::vector<Address> &addrList) {
- int s = socket(PF_INET, SOCK_STREAM, 0);
- for (int i=1;;i++) {
- struct lifreq ifr;
- ifr.lifr_index = i;
- if (::ioctl(s, SIOCGIFADDR, &ifr) < 0) {
- break;
- }
- struct sockaddr *sa = static_cast<struct sockaddr *>((void *) &ifr.lifr_addr);
- if (sa->sa_family != AF_INET) {
- // TODO: Url parsing currently can't cope with IPv6 addresses, defer for now
- break;
- }
- struct sockaddr_in *sin = static_cast<struct sockaddr_in *>((void *)sa);
- std::string addr(inet_ntoa(sin->sin_addr));
- if (addr != LOCALHOST)
- addrList.push_back(Address(TCP, addr, port));
- }
- if (addrList.empty()) {
- addrList.push_back(Address(TCP, LOCALHOST, port));
- }
- close (s);
-}
-
void SystemInfo::getSystemId(std::string &osName,
std::string &nodeName,
std::string &release,
@@ -126,4 +101,10 @@ string SystemInfo::getProcessName()
return value;
}
+// Always true. Only Windows has exception cases.
+bool SystemInfo::threadSafeShutdown()
+{
+ return true;
+}
+
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/ssl/SslHandler.cpp b/cpp/src/qpid/sys/ssl/SslHandler.cpp
deleted file mode 100644
index eeb8c26a76..0000000000
--- a/cpp/src/qpid/sys/ssl/SslHandler.cpp
+++ /dev/null
@@ -1,217 +0,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.
- *
- */
-#include "qpid/sys/ssl/SslHandler.h"
-#include "qpid/sys/ssl/SslIo.h"
-#include "qpid/sys/ssl/SslSocket.h"
-#include "qpid/sys/Timer.h"
-#include "qpid/framing/AMQP_HighestVersion.h"
-#include "qpid/framing/ProtocolInitiation.h"
-#include "qpid/log/Statement.h"
-
-#include <boost/bind.hpp>
-
-namespace qpid {
-namespace sys {
-namespace ssl {
-
-
-struct ProtocolTimeoutTask : public sys::TimerTask {
- SslHandler& handler;
- std::string id;
-
- ProtocolTimeoutTask(const std::string& i, const Duration& timeout, SslHandler& h) :
- TimerTask(timeout, "ProtocolTimeout"),
- handler(h),
- id(i)
- {}
-
- void fire() {
- // If this fires it means that we didn't negotiate the connection in the timeout period
- // Schedule closing the connection for the io thread
- QPID_LOG(error, "Connection " << id << " No protocol received closing");
- handler.abort();
- }
-};
-
-SslHandler::SslHandler(std::string id, ConnectionCodec::Factory* f, bool _nodict) :
- identifier(id),
- aio(0),
- factory(f),
- codec(0),
- readError(false),
- isClient(false),
- nodict(_nodict)
-{}
-
-SslHandler::~SslHandler() {
- if (codec)
- codec->closed();
- if (timeoutTimerTask)
- timeoutTimerTask->cancel();
- delete codec;
-}
-
-void SslHandler::init(SslIO* a, Timer& timer, uint32_t maxTime) {
- aio = a;
-
- // Start timer for this connection
- timeoutTimerTask = new ProtocolTimeoutTask(identifier, maxTime*TIME_MSEC, *this);
- timer.add(timeoutTimerTask);
-
- // Give connection some buffers to use
- aio->createBuffers();
-}
-
-void SslHandler::write(const framing::ProtocolInitiation& data)
-{
- QPID_LOG(debug, "SENT [" << identifier << "]: INIT(" << data << ")");
- SslIO::BufferBase* buff = aio->getQueuedBuffer();
- assert(buff);
- framing::Buffer out(buff->bytes, buff->byteCount);
- data.encode(out);
- buff->dataCount = data.encodedSize();
- aio->queueWrite(buff);
-}
-
-void SslHandler::abort() {
- // Don't disconnect if we're already disconnecting
- if (!readError) {
- aio->requestCallback(boost::bind(&SslHandler::eof, this, _1));
- }
-}
-void SslHandler::activateOutput() {
- aio->notifyPendingWrite();
-}
-
-void SslHandler::giveReadCredit(int32_t) {
- // FIXME aconway 2008-12-05: not yet implemented.
-}
-
-// Input side
-void SslHandler::readbuff(SslIO& , SslIO::BufferBase* buff) {
- if (readError) {
- return;
- }
- size_t decoded = 0;
- if (codec) { // Already initiated
- try {
- decoded = codec->decode(buff->bytes+buff->dataStart, buff->dataCount);
- }catch(const std::exception& e){
- QPID_LOG(error, e.what());
- readError = true;
- aio->queueWriteClose();
- }
- }else{
- framing::Buffer in(buff->bytes+buff->dataStart, buff->dataCount);
- framing::ProtocolInitiation protocolInit;
- if (protocolInit.decode(in)) {
- // We've just got the protocol negotiation so we can cancel the timeout for that
- timeoutTimerTask->cancel();
-
- decoded = in.getPosition();
- QPID_LOG(debug, "RECV [" << identifier << "]: INIT(" << protocolInit << ")");
- try {
- codec = factory->create(protocolInit.getVersion(), *this, identifier, getSecuritySettings(aio));
- if (!codec) {
- //TODO: may still want to revise this...
- //send valid version header & close connection.
- write(framing::ProtocolInitiation(framing::highestProtocolVersion));
- readError = true;
- aio->queueWriteClose();
- }
- } catch (const std::exception& e) {
- QPID_LOG(error, e.what());
- readError = true;
- aio->queueWriteClose();
- }
- }
- }
- // TODO: unreading needs to go away, and when we can cope
- // with multiple sub-buffers in the general buffer scheme, it will
- if (decoded != size_t(buff->dataCount)) {
- // Adjust buffer for used bytes and then "unread them"
- buff->dataStart += decoded;
- buff->dataCount -= decoded;
- aio->unread(buff);
- } else {
- // Give whole buffer back to aio subsystem
- aio->queueReadBuffer(buff);
- }
-}
-
-void SslHandler::eof(SslIO&) {
- QPID_LOG(debug, "DISCONNECTED [" << identifier << "]");
- if (codec) codec->closed();
- aio->queueWriteClose();
-}
-
-void SslHandler::closedSocket(SslIO&, const SslSocket& s) {
- // If we closed with data still to send log a warning
- if (!aio->writeQueueEmpty()) {
- QPID_LOG(warning, "CLOSING [" << identifier << "] unsent data (probably due to client disconnect)");
- }
- delete &s;
- aio->queueForDeletion();
- delete this;
-}
-
-void SslHandler::disconnect(SslIO& a) {
- // treat the same as eof
- eof(a);
-}
-
-// Notifications
-void SslHandler::nobuffs(SslIO&) {
-}
-
-void SslHandler::idle(SslIO&){
- if (isClient && codec == 0) {
- codec = factory->create(*this, identifier, getSecuritySettings(aio));
- write(framing::ProtocolInitiation(codec->getVersion()));
- // We've just sent the protocol negotiation so we can cancel the timeout for that
- // This is not ideal, because we've not received anything yet, but heartbeats will
- // be active soon
- timeoutTimerTask->cancel();
- return;
- }
- if (codec == 0) return;
- if (!codec->canEncode()) {
- return;
- }
- SslIO::BufferBase* buff = aio->getQueuedBuffer();
- if (buff) {
- size_t encoded=codec->encode(buff->bytes, buff->byteCount);
- buff->dataCount = encoded;
- aio->queueWrite(buff);
- }
- if (codec->isClosed())
- aio->queueWriteClose();
-}
-
-SecuritySettings SslHandler::getSecuritySettings(SslIO* aio)
-{
- SecuritySettings settings = aio->getSecuritySettings();
- settings.nodict = nodict;
- return settings;
-}
-
-
-}}} // namespace qpid::sys::ssl
diff --git a/cpp/src/qpid/sys/ssl/SslHandler.h b/cpp/src/qpid/sys/ssl/SslHandler.h
deleted file mode 100644
index 14814b0281..0000000000
--- a/cpp/src/qpid/sys/ssl/SslHandler.h
+++ /dev/null
@@ -1,85 +0,0 @@
-#ifndef QPID_SYS_SSL_SSLHANDLER_H
-#define QPID_SYS_SSL_SSLHANDLER_H
-
-/*
- *
- * 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.
- *
- */
-
-#include "qpid/sys/ConnectionCodec.h"
-#include "qpid/sys/OutputControl.h"
-
-#include <boost/intrusive_ptr.hpp>
-
-namespace qpid {
-
-namespace framing {
- class ProtocolInitiation;
-}
-
-namespace sys {
-
-class Timer;
-class TimerTask;
-
-namespace ssl {
-
-class SslIO;
-struct SslIOBufferBase;
-class SslSocket;
-
-class SslHandler : public OutputControl {
- std::string identifier;
- SslIO* aio;
- ConnectionCodec::Factory* factory;
- ConnectionCodec* codec;
- bool readError;
- bool isClient;
- bool nodict;
- boost::intrusive_ptr<sys::TimerTask> timeoutTimerTask;
-
- void write(const framing::ProtocolInitiation&);
- qpid::sys::SecuritySettings getSecuritySettings(SslIO* aio);
-
- public:
- SslHandler(std::string id, ConnectionCodec::Factory* f, bool nodict);
- ~SslHandler();
- void init(SslIO* a, Timer& timer, uint32_t maxTime);
-
- void setClient() { isClient = true; }
-
- // Output side
- void abort();
- void activateOutput();
- void giveReadCredit(int32_t);
-
- // Input side
- void readbuff(SslIO& aio, SslIOBufferBase* buff);
- void eof(SslIO& aio);
- void disconnect(SslIO& aio);
-
- // Notifications
- void nobuffs(SslIO& aio);
- void idle(SslIO& aio);
- void closedSocket(SslIO& aio, const SslSocket& s);
-};
-
-}}} // namespace qpid::sys::ssl
-
-#endif /*!QPID_SYS_SSL_SSLHANDLER_H*/
diff --git a/cpp/src/qpid/sys/ssl/SslIo.cpp b/cpp/src/qpid/sys/ssl/SslIo.cpp
deleted file mode 100644
index bbfb703170..0000000000
--- a/cpp/src/qpid/sys/ssl/SslIo.cpp
+++ /dev/null
@@ -1,470 +0,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.
- *
- */
-
-#include "qpid/sys/ssl/SslIo.h"
-#include "qpid/sys/ssl/SslSocket.h"
-#include "qpid/sys/ssl/check.h"
-
-#include "qpid/sys/Time.h"
-#include "qpid/sys/posix/check.h"
-#include "qpid/log/Statement.h"
-
-// TODO The basic algorithm here is not really POSIX specific and with a bit more abstraction
-// could (should) be promoted to be platform portable
-#include <unistd.h>
-#include <sys/socket.h>
-#include <signal.h>
-#include <errno.h>
-#include <string.h>
-
-#include <boost/bind.hpp>
-
-namespace qpid {
-namespace sys {
-namespace ssl {
-
-namespace {
-
-/*
- * Make *process* not generate SIGPIPE when writing to closed
- * pipe/socket (necessary as default action is to terminate process)
- */
-void ignoreSigpipe() {
- ::signal(SIGPIPE, SIG_IGN);
-}
-
-/*
- * We keep per thread state to avoid locking overhead. The assumption is that
- * on average all the connections are serviced by all the threads so the state
- * recorded in each thread is about the same. If this turns out not to be the
- * case we could rebalance the info occasionally.
- */
-__thread int threadReadTotal = 0;
-__thread int threadReadCount = 0;
-__thread int threadWriteTotal = 0;
-__thread int threadWriteCount = 0;
-__thread int64_t threadMaxIoTimeNs = 2 * 1000000; // start at 2ms
-}
-
-/*
- * Asynch Acceptor
- */
-
-template <class T>
-SslAcceptorTmpl<T>::SslAcceptorTmpl(const T& s, Callback callback) :
- acceptedCallback(callback),
- handle(s, boost::bind(&SslAcceptorTmpl<T>::readable, this, _1), 0, 0),
- socket(s) {
-
- s.setNonblocking();
- ignoreSigpipe();
-}
-
-template <class T>
-SslAcceptorTmpl<T>::~SslAcceptorTmpl()
-{
- handle.stopWatch();
-}
-
-template <class T>
-void SslAcceptorTmpl<T>::start(Poller::shared_ptr poller) {
- handle.startWatch(poller);
-}
-
-/*
- * We keep on accepting as long as there is something to accept
- */
-template <class T>
-void SslAcceptorTmpl<T>::readable(DispatchHandle& h) {
- Socket* s;
- do {
- errno = 0;
- // TODO: Currently we ignore the peers address, perhaps we should
- // log it or use it for connection acceptance.
- try {
- s = socket.accept();
- if (s) {
- acceptedCallback(*s);
- } else {
- break;
- }
- } catch (const std::exception& e) {
- QPID_LOG(error, "Could not accept socket: " << e.what());
- }
- } while (true);
-
- h.rewatch();
-}
-
-// Explicitly instantiate the templates we need
-template class SslAcceptorTmpl<SslSocket>;
-template class SslAcceptorTmpl<SslMuxSocket>;
-
-/*
- * Asynch Connector
- */
-
-SslConnector::SslConnector(const SslSocket& s,
- Poller::shared_ptr poller,
- std::string hostname,
- std::string port,
- ConnectedCallback connCb,
- FailedCallback failCb) :
- DispatchHandle(s,
- 0,
- boost::bind(&SslConnector::connComplete, this, _1),
- boost::bind(&SslConnector::connComplete, this, _1)),
- connCallback(connCb),
- failCallback(failCb),
- socket(s)
-{
- //TODO: would be better for connect to be performed on a
- //non-blocking socket, but that doesn't work at present so connect
- //blocks until complete
- try {
- socket.connect(hostname, port);
- socket.setNonblocking();
- startWatch(poller);
- } catch(std::exception& e) {
- failure(-1, std::string(e.what()));
- }
-}
-
-void SslConnector::connComplete(DispatchHandle& h)
-{
- int errCode = socket.getError();
-
- h.stopWatch();
- if (errCode == 0) {
- connCallback(socket);
- DispatchHandle::doDelete();
- } else {
- // TODO: This need to be fixed as strerror isn't thread safe
- failure(errCode, std::string(::strerror(errCode)));
- }
-}
-
-void SslConnector::failure(int errCode, std::string message)
-{
- if (failCallback)
- failCallback(errCode, message);
-
- socket.close();
- delete &socket;
-
- DispatchHandle::doDelete();
-}
-
-/*
- * Asynch reader/writer
- */
-SslIO::SslIO(const SslSocket& s,
- ReadCallback rCb, EofCallback eofCb, DisconnectCallback disCb,
- ClosedCallback cCb, BuffersEmptyCallback eCb, IdleCallback iCb) :
-
- DispatchHandle(s,
- boost::bind(&SslIO::readable, this, _1),
- boost::bind(&SslIO::writeable, this, _1),
- boost::bind(&SslIO::disconnected, this, _1)),
- readCallback(rCb),
- eofCallback(eofCb),
- disCallback(disCb),
- closedCallback(cCb),
- emptyCallback(eCb),
- idleCallback(iCb),
- socket(s),
- queuedClose(false),
- writePending(false) {
-
- s.setNonblocking();
-}
-
-SslIO::~SslIO() {
-}
-
-void SslIO::queueForDeletion() {
- DispatchHandle::doDelete();
-}
-
-void SslIO::start(Poller::shared_ptr poller) {
- DispatchHandle::startWatch(poller);
-}
-
-void SslIO::createBuffers(uint32_t size) {
- // Allocate all the buffer memory at once
- bufferMemory.reset(new char[size*BufferCount]);
-
- // Create the Buffer structs in a vector
- // And push into the buffer queue
- buffers.reserve(BufferCount);
- for (uint32_t i = 0; i < BufferCount; i++) {
- buffers.push_back(BufferBase(&bufferMemory[i*size], size));
- queueReadBuffer(&buffers[i]);
- }
-}
-
-void SslIO::queueReadBuffer(BufferBase* buff) {
- assert(buff);
- buff->dataStart = 0;
- buff->dataCount = 0;
- bufferQueue.push_back(buff);
- DispatchHandle::rewatchRead();
-}
-
-void SslIO::unread(BufferBase* buff) {
- assert(buff);
- if (buff->dataStart != 0) {
- memmove(buff->bytes, buff->bytes+buff->dataStart, buff->dataCount);
- buff->dataStart = 0;
- }
- bufferQueue.push_front(buff);
- DispatchHandle::rewatchRead();
-}
-
-void SslIO::queueWrite(BufferBase* buff) {
- assert(buff);
- // If we've already closed the socket then throw the write away
- if (queuedClose) {
- bufferQueue.push_front(buff);
- return;
- } else {
- writeQueue.push_front(buff);
- }
- writePending = false;
- DispatchHandle::rewatchWrite();
-}
-
-void SslIO::notifyPendingWrite() {
- writePending = true;
- DispatchHandle::rewatchWrite();
-}
-
-void SslIO::queueWriteClose() {
- queuedClose = true;
- DispatchHandle::rewatchWrite();
-}
-
-void SslIO::requestCallback(RequestCallback callback) {
- // TODO creating a function object every time isn't all that
- // efficient - if this becomes heavily used do something better (what?)
- assert(callback);
- DispatchHandle::call(boost::bind(&SslIO::requestedCall, this, callback));
-}
-
-void SslIO::requestedCall(RequestCallback callback) {
- assert(callback);
- callback(*this);
-}
-
-/** Return a queued buffer if there are enough
- * to spare
- */
-SslIO::BufferBase* SslIO::getQueuedBuffer() {
- // Always keep at least one buffer (it might have data that was "unread" in it)
- if (bufferQueue.size()<=1)
- return 0;
- BufferBase* buff = bufferQueue.back();
- assert(buff);
- buff->dataStart = 0;
- buff->dataCount = 0;
- bufferQueue.pop_back();
- return buff;
-}
-
-/*
- * We keep on reading as long as we have something to read and a buffer to put
- * it in
- */
-void SslIO::readable(DispatchHandle& h) {
- AbsTime readStartTime = AbsTime::now();
- do {
- // (Try to) get a buffer
- if (!bufferQueue.empty()) {
- // Read into buffer
- BufferBase* buff = bufferQueue.front();
- assert(buff);
- bufferQueue.pop_front();
- errno = 0;
- int readCount = buff->byteCount-buff->dataCount;
- int rc = socket.read(buff->bytes + buff->dataCount, readCount);
- if (rc > 0) {
- buff->dataCount += rc;
- threadReadTotal += rc;
-
- readCallback(*this, buff);
- if (rc != readCount) {
- // If we didn't fill the read buffer then time to stop reading
- break;
- }
-
- // Stop reading if we've overrun our timeslot
- if (Duration(readStartTime, AbsTime::now()) > threadMaxIoTimeNs) {
- break;
- }
-
- } else {
- // Put buffer back (at front so it doesn't interfere with unread buffers)
- bufferQueue.push_front(buff);
- assert(buff);
-
- // Eof or other side has gone away
- if (rc == 0 || errno == ECONNRESET) {
- eofCallback(*this);
- h.unwatchRead();
- break;
- } else if (errno == EAGAIN) {
- // We have just put a buffer back so we know
- // we can carry on watching for reads
- break;
- } else {
- // Report error then just treat as a socket disconnect
- QPID_LOG(error, "Error reading socket: " << getErrorString(PR_GetError()));
- eofCallback(*this);
- h.unwatchRead();
- break;
- }
- }
- } else {
- // Something to read but no buffer
- if (emptyCallback) {
- emptyCallback(*this);
- }
- // If we still have no buffers we can't do anything more
- if (bufferQueue.empty()) {
- h.unwatchRead();
- break;
- }
-
- }
- } while (true);
-
- ++threadReadCount;
- return;
-}
-
-/*
- * We carry on writing whilst we have data to write and we can write
- */
-void SslIO::writeable(DispatchHandle& h) {
- AbsTime writeStartTime = AbsTime::now();
- do {
- // See if we've got something to write
- if (!writeQueue.empty()) {
- // Write buffer
- BufferBase* buff = writeQueue.back();
- writeQueue.pop_back();
- errno = 0;
- assert(buff->dataStart+buff->dataCount <= buff->byteCount);
- int rc = socket.write(buff->bytes+buff->dataStart, buff->dataCount);
- if (rc >= 0) {
- threadWriteTotal += rc;
-
- // If we didn't write full buffer put rest back
- if (rc != buff->dataCount) {
- buff->dataStart += rc;
- buff->dataCount -= rc;
- writeQueue.push_back(buff);
- break;
- }
-
- // Recycle the buffer
- queueReadBuffer(buff);
-
- // Stop writing if we've overrun our timeslot
- if (Duration(writeStartTime, AbsTime::now()) > threadMaxIoTimeNs) {
- break;
- }
- } else {
- // Put buffer back
- writeQueue.push_back(buff);
- if (errno == ECONNRESET || errno == EPIPE) {
- // Just stop watching for write here - we'll get a
- // disconnect callback soon enough
- h.unwatchWrite();
- break;
- } else if (errno == EAGAIN) {
- // We have just put a buffer back so we know
- // we can carry on watching for writes
- break;
- } else {
- QPID_LOG(error, "Error writing to socket: " << getErrorString(PR_GetError()));
- h.unwatchWrite();
- break;
- }
- }
- } else {
- // If we're waiting to close the socket then can do it now as there is nothing to write
- if (queuedClose) {
- close(h);
- break;
- }
- // Fd is writable, but nothing to write
- if (idleCallback) {
- writePending = false;
- idleCallback(*this);
- }
- // If we still have no buffers to write we can't do anything more
- if (writeQueue.empty() && !writePending && !queuedClose) {
- h.unwatchWrite();
- // The following handles the case where writePending is
- // set to true after the test above; in this case its
- // possible that the unwatchWrite overwrites the
- // desired rewatchWrite so we correct that here
- if (writePending)
- h.rewatchWrite();
- break;
- }
- }
- } while (true);
-
- ++threadWriteCount;
- return;
-}
-
-void SslIO::disconnected(DispatchHandle& h) {
- // If we've already queued close do it instead of disconnected callback
- if (queuedClose) {
- close(h);
- } else if (disCallback) {
- disCallback(*this);
- h.unwatch();
- }
-}
-
-/*
- * Close the socket and callback to say we've done it
- */
-void SslIO::close(DispatchHandle& h) {
- h.stopWatch();
- socket.close();
- if (closedCallback) {
- closedCallback(*this, socket);
- }
-}
-
-SecuritySettings SslIO::getSecuritySettings() {
- SecuritySettings settings;
- settings.ssf = socket.getKeyLen();
- settings.authid = socket.getClientAuthId();
- return settings;
-}
-
-}}}
diff --git a/cpp/src/qpid/sys/ssl/SslIo.h b/cpp/src/qpid/sys/ssl/SslIo.h
deleted file mode 100644
index f3112bfa65..0000000000
--- a/cpp/src/qpid/sys/ssl/SslIo.h
+++ /dev/null
@@ -1,193 +0,0 @@
-#ifndef _sys_ssl_SslIO
-#define _sys_ssl_SslIO
-/*
- *
- * 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.
- *
- */
-
-#include "qpid/sys/DispatchHandle.h"
-#include "qpid/sys/SecuritySettings.h"
-
-#include <boost/function.hpp>
-#include <boost/shared_array.hpp>
-#include <deque>
-
-namespace qpid {
-namespace sys {
-
-class Socket;
-
-namespace ssl {
-
-class SslSocket;
-
-/*
- * Asynchronous ssl acceptor: accepts connections then does a callback
- * with the accepted fd
- */
-template <class T>
-class SslAcceptorTmpl {
-public:
- typedef boost::function1<void, const Socket&> Callback;
-
-private:
- Callback acceptedCallback;
- qpid::sys::DispatchHandle handle;
- const T& socket;
-
-public:
- SslAcceptorTmpl(const T& s, Callback callback);
- ~SslAcceptorTmpl();
- void start(qpid::sys::Poller::shared_ptr poller);
-
-private:
- void readable(qpid::sys::DispatchHandle& handle);
-};
-
-/*
- * Asynchronous ssl connector: starts the process of initiating a
- * connection and invokes a callback when completed or failed.
- */
-class SslConnector : private qpid::sys::DispatchHandle {
-public:
- typedef boost::function1<void, const SslSocket&> ConnectedCallback;
- typedef boost::function2<void, int, std::string> FailedCallback;
-
-private:
- ConnectedCallback connCallback;
- FailedCallback failCallback;
- const SslSocket& socket;
-
-public:
- SslConnector(const SslSocket& socket,
- Poller::shared_ptr poller,
- std::string hostname,
- std::string port,
- ConnectedCallback connCb,
- FailedCallback failCb = 0);
-
-private:
- void connComplete(DispatchHandle& handle);
- void failure(int, std::string);
-};
-
-struct SslIOBufferBase {
- char* bytes;
- int32_t byteCount;
- int32_t dataStart;
- int32_t dataCount;
-
- SslIOBufferBase(char* const b, const int32_t s) :
- bytes(b),
- byteCount(s),
- dataStart(0),
- dataCount(0)
- {}
-
- virtual ~SslIOBufferBase()
- {}
-};
-
-/*
- * Asychronous reader/writer:
- * Reader accepts buffers to read into; reads into the provided buffers
- * and then does a callback with the buffer and amount read. Optionally it can callback
- * when there is something to read but no buffer to read it into.
- *
- * Writer accepts a buffer and queues it for writing; can also be given
- * a callback for when writing is "idle" (ie fd is writable, but nothing to write)
- *
- * The class is implemented in terms of DispatchHandle to allow it to be deleted by deleting
- * the contained DispatchHandle
- */
-class SslIO : private qpid::sys::DispatchHandle {
-public:
- typedef SslIOBufferBase BufferBase;
-
- typedef boost::function2<void, SslIO&, BufferBase*> ReadCallback;
- typedef boost::function1<void, SslIO&> EofCallback;
- typedef boost::function1<void, SslIO&> DisconnectCallback;
- typedef boost::function2<void, SslIO&, const SslSocket&> ClosedCallback;
- typedef boost::function1<void, SslIO&> BuffersEmptyCallback;
- typedef boost::function1<void, SslIO&> IdleCallback;
- typedef boost::function1<void, SslIO&> RequestCallback;
-
- SslIO(const SslSocket& s,
- ReadCallback rCb, EofCallback eofCb, DisconnectCallback disCb,
- ClosedCallback cCb = 0, BuffersEmptyCallback eCb = 0, IdleCallback iCb = 0);
-private:
- ReadCallback readCallback;
- EofCallback eofCallback;
- DisconnectCallback disCallback;
- ClosedCallback closedCallback;
- BuffersEmptyCallback emptyCallback;
- IdleCallback idleCallback;
- const SslSocket& socket;
- std::deque<BufferBase*> bufferQueue;
- std::deque<BufferBase*> writeQueue;
- std::vector<BufferBase> buffers;
- boost::shared_array<char> bufferMemory;
- bool queuedClose;
- /**
- * This flag is used to detect and handle concurrency between
- * calls to notifyPendingWrite() (which can be made from any thread) and
- * the execution of the writeable() method (which is always on the
- * thread processing this handle.
- */
- volatile bool writePending;
-
-public:
- /*
- * Size of IO buffers - this is the maximum possible frame size + 1
- */
- const static uint32_t MaxBufferSize = 65536;
-
- /*
- * Number of IO buffers allocated - I think the code can only use 2 -
- * 1 for reading and 1 for writing, allocate 4 for safety
- */
- const static uint32_t BufferCount = 4;
-
- void queueForDeletion();
-
- void start(qpid::sys::Poller::shared_ptr poller);
- void createBuffers(uint32_t size = MaxBufferSize);
- void queueReadBuffer(BufferBase* buff);
- void unread(BufferBase* buff);
- void queueWrite(BufferBase* buff);
- void notifyPendingWrite();
- void queueWriteClose();
- bool writeQueueEmpty() { return writeQueue.empty(); }
- void requestCallback(RequestCallback);
- BufferBase* getQueuedBuffer();
-
- qpid::sys::SecuritySettings getSecuritySettings();
-
-private:
- ~SslIO();
- void readable(qpid::sys::DispatchHandle& handle);
- void writeable(qpid::sys::DispatchHandle& handle);
- void disconnected(qpid::sys::DispatchHandle& handle);
- void requestedCall(RequestCallback);
- void close(qpid::sys::DispatchHandle& handle);
-};
-
-}}}
-
-#endif // _sys_ssl_SslIO
diff --git a/cpp/src/qpid/sys/ssl/SslSocket.cpp b/cpp/src/qpid/sys/ssl/SslSocket.cpp
index 30234bb686..a328e49c13 100644
--- a/cpp/src/qpid/sys/ssl/SslSocket.cpp
+++ b/cpp/src/qpid/sys/ssl/SslSocket.cpp
@@ -20,6 +20,7 @@
*/
#include "qpid/sys/ssl/SslSocket.h"
+#include "qpid/sys/SocketAddress.h"
#include "qpid/sys/ssl/check.h"
#include "qpid/sys/ssl/util.h"
#include "qpid/Exception.h"
@@ -52,28 +53,6 @@ namespace sys {
namespace ssl {
namespace {
-std::string getService(int fd, bool local)
-{
- ::sockaddr_storage name; // big enough for any socket address
- ::socklen_t namelen = sizeof(name);
-
- int result = -1;
- if (local) {
- result = ::getsockname(fd, (::sockaddr*)&name, &namelen);
- } else {
- result = ::getpeername(fd, (::sockaddr*)&name, &namelen);
- }
-
- QPID_POSIX_CHECK(result);
-
- char servName[NI_MAXSERV];
- if (int rc=::getnameinfo((::sockaddr*)&name, namelen, 0, 0,
- servName, sizeof(servName),
- NI_NUMERICHOST | NI_NUMERICSERV) != 0)
- throw QPID_POSIX_ERROR(rc);
- return servName;
-}
-
const std::string DOMAIN_SEPARATOR("@");
const std::string DC_SEPARATOR(".");
const std::string DC("DC");
@@ -101,14 +80,18 @@ std::string getDomainFromSubject(std::string subject)
}
return domain;
}
-
}
-SslSocket::SslSocket() : socket(0), prototype(0)
+SslSocket::SslSocket(const std::string& certName, bool clientAuth) :
+ nssSocket(0), certname(certName), prototype(0)
{
- impl->fd = ::socket (PF_INET, SOCK_STREAM, 0);
- if (impl->fd < 0) throw QPID_POSIX_ERROR(errno);
- socket = SSL_ImportFD(0, PR_ImportTCPSocket(impl->fd));
+ //configure prototype socket:
+ prototype = SSL_ImportFD(0, PR_NewTCPSocket());
+
+ if (clientAuth) {
+ NSS_CHECK(SSL_OptionSet(prototype, SSL_REQUEST_CERTIFICATE, PR_TRUE));
+ NSS_CHECK(SSL_OptionSet(prototype, SSL_REQUIRE_CERTIFICATE, PR_TRUE));
+ }
}
/**
@@ -116,25 +99,44 @@ SslSocket::SslSocket() : socket(0), prototype(0)
* returned from accept. Because we use posix accept rather than
* PR_Accept, we have to reset the handshake.
*/
-SslSocket::SslSocket(IOHandlePrivate* ioph, PRFileDesc* model) : Socket(ioph), socket(0), prototype(0)
+SslSocket::SslSocket(int fd, PRFileDesc* model) : BSDSocket(fd), nssSocket(0), prototype(0)
{
- socket = SSL_ImportFD(model, PR_ImportTCPSocket(impl->fd));
- NSS_CHECK(SSL_ResetHandshake(socket, true));
+ nssSocket = SSL_ImportFD(model, PR_ImportTCPSocket(fd));
+ NSS_CHECK(SSL_ResetHandshake(nssSocket, PR_TRUE));
}
void SslSocket::setNonblocking() const
{
+ if (!nssSocket) {
+ BSDSocket::setNonblocking();
+ return;
+ }
PRSocketOptionData option;
option.option = PR_SockOpt_Nonblocking;
option.value.non_blocking = true;
- PR_SetSocketOption(socket, &option);
+ PR_SetSocketOption(nssSocket, &option);
}
-void SslSocket::connect(const std::string& host, const std::string& port) const
+void SslSocket::setTcpNoDelay() const
{
- std::stringstream namestream;
- namestream << host << ":" << port;
- connectname = namestream.str();
+ if (!nssSocket) {
+ BSDSocket::setTcpNoDelay();
+ return;
+ }
+ PRSocketOptionData option;
+ option.option = PR_SockOpt_NoDelay;
+ option.value.no_delay = true;
+ PR_SetSocketOption(nssSocket, &option);
+}
+
+void SslSocket::connect(const SocketAddress& addr) const
+{
+ BSDSocket::connect(addr);
+}
+
+void SslSocket::finishConnect(const SocketAddress& addr) const
+{
+ nssSocket = SSL_ImportFD(0, PR_ImportTCPSocket(fd));
void* arg;
// Use the connection's cert-name if it has one; else use global cert-name
@@ -145,75 +147,48 @@ void SslSocket::connect(const std::string& host, const std::string& port) const
} else {
arg = const_cast<char*>(SslOptions::global.certName.c_str());
}
- NSS_CHECK(SSL_GetClientAuthDataHook(socket, NSS_GetClientAuthData, arg));
- NSS_CHECK(SSL_SetURL(socket, host.data()));
-
- char hostBuffer[PR_NETDB_BUF_SIZE];
- PRHostEnt hostEntry;
- PR_CHECK(PR_GetHostByName(host.data(), hostBuffer, PR_NETDB_BUF_SIZE, &hostEntry));
- PRNetAddr address;
- int value = PR_EnumerateHostEnt(0, &hostEntry, boost::lexical_cast<PRUint16>(port), &address);
- if (value < 0) {
- throw Exception(QPID_MSG("Error getting address for host: " << ErrorString()));
- } else if (value == 0) {
- throw Exception(QPID_MSG("Could not resolve address for host."));
- }
- PR_CHECK(PR_Connect(socket, &address, PR_INTERVAL_NO_TIMEOUT));
- NSS_CHECK(SSL_ForceHandshake(socket));
+ NSS_CHECK(SSL_GetClientAuthDataHook(nssSocket, NSS_GetClientAuthData, arg));
+
+ url = addr.getHost();
+ NSS_CHECK(SSL_SetURL(nssSocket, url.data()));
+
+ NSS_CHECK(SSL_ResetHandshake(nssSocket, PR_FALSE));
+ NSS_CHECK(SSL_ForceHandshake(nssSocket));
}
void SslSocket::close() const
{
- if (impl->fd > 0) {
- PR_Close(socket);
- impl->fd = -1;
+ if (!nssSocket) {
+ BSDSocket::close();
+ return;
+ }
+ if (fd > 0) {
+ PR_Close(nssSocket);
+ fd = -1;
}
}
-int SslSocket::listen(uint16_t port, int backlog, const std::string& certName, bool clientAuth) const
+int SslSocket::listen(const SocketAddress& sa, int backlog) const
{
- //configure prototype socket:
- prototype = SSL_ImportFD(0, PR_NewTCPSocket());
- if (clientAuth) {
- NSS_CHECK(SSL_OptionSet(prototype, SSL_REQUEST_CERTIFICATE, PR_TRUE));
- NSS_CHECK(SSL_OptionSet(prototype, SSL_REQUIRE_CERTIFICATE, PR_TRUE));
- }
-
//get certificate and key (is this the correct way?)
- CERTCertificate *cert = PK11_FindCertFromNickname(const_cast<char*>(certName.c_str()), 0);
- if (!cert) throw Exception(QPID_MSG("Failed to load certificate '" << certName << "'"));
+ std::string cName( (certname == "") ? "localhost.localdomain" : certname);
+ CERTCertificate *cert = PK11_FindCertFromNickname(const_cast<char*>(cName.c_str()), 0);
+ if (!cert) throw Exception(QPID_MSG("Failed to load certificate '" << cName << "'"));
SECKEYPrivateKey *key = PK11_FindKeyByAnyCert(cert, 0);
if (!key) throw Exception(QPID_MSG("Failed to retrieve private key from certificate"));
NSS_CHECK(SSL_ConfigSecureServer(prototype, cert, key, NSS_FindCertKEAType(cert)));
SECKEY_DestroyPrivateKey(key);
CERT_DestroyCertificate(cert);
- //bind and listen
- const int& socket = impl->fd;
- int yes=1;
- QPID_POSIX_CHECK(setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)));
- struct sockaddr_in name;
- name.sin_family = AF_INET;
- name.sin_port = htons(port);
- name.sin_addr.s_addr = 0;
- if (::bind(socket, (struct sockaddr*)&name, sizeof(name)) < 0)
- throw Exception(QPID_MSG("Can't bind to port " << port << ": " << strError(errno)));
- if (::listen(socket, backlog) < 0)
- throw Exception(QPID_MSG("Can't listen on port " << port << ": " << strError(errno)));
-
- socklen_t namelen = sizeof(name);
- if (::getsockname(socket, (struct sockaddr*)&name, &namelen) < 0)
- throw QPID_POSIX_ERROR(errno);
-
- return ntohs(name.sin_port);
+ return BSDSocket::listen(sa, backlog);
}
-SslSocket* SslSocket::accept() const
+Socket* SslSocket::accept() const
{
QPID_LOG(trace, "Accepting SSL connection.");
- int afd = ::accept(impl->fd, 0, 0);
+ int afd = ::accept(fd, 0, 0);
if ( afd >= 0) {
- return new SslSocket(new IOHandlePrivate(afd), prototype);
+ return new SslSocket(afd, prototype);
} else if (errno == EAGAIN) {
return 0;
} else {
@@ -297,17 +272,22 @@ static bool isSslStream(int afd) {
return isSSL2Handshake || isSSL3Handshake;
}
+SslMuxSocket::SslMuxSocket(const std::string& certName, bool clientAuth) :
+ SslSocket(certName, clientAuth)
+{
+}
+
Socket* SslMuxSocket::accept() const
{
- int afd = ::accept(impl->fd, 0, 0);
+ int afd = ::accept(fd, 0, 0);
if (afd >= 0) {
QPID_LOG(trace, "Accepting connection with optional SSL wrapper.");
if (isSslStream(afd)) {
QPID_LOG(trace, "Accepted SSL connection.");
- return new SslSocket(new IOHandlePrivate(afd), prototype);
+ return new SslSocket(afd, prototype);
} else {
QPID_LOG(trace, "Accepted Plaintext connection.");
- return new Socket(new IOHandlePrivate(afd));
+ return new BSDSocket(afd);
}
} else if (errno == EAGAIN) {
return 0;
@@ -318,32 +298,12 @@ Socket* SslMuxSocket::accept() const
int SslSocket::read(void *buf, size_t count) const
{
- return PR_Read(socket, buf, count);
+ return PR_Read(nssSocket, buf, count);
}
int SslSocket::write(const void *buf, size_t count) const
{
- return PR_Write(socket, buf, count);
-}
-
-uint16_t SslSocket::getLocalPort() const
-{
- return std::atoi(getService(impl->fd, true).c_str());
-}
-
-uint16_t SslSocket::getRemotePort() const
-{
- return atoi(getService(impl->fd, true).c_str());
-}
-
-void SslSocket::setTcpNoDelay(bool nodelay) const
-{
- if (nodelay) {
- PRSocketOptionData option;
- option.option = PR_SockOpt_NoDelay;
- option.value.no_delay = true;
- PR_SetSocketOption(socket, &option);
- }
+ return PR_Write(nssSocket, buf, count);
}
void SslSocket::setCertName(const std::string& name)
@@ -359,7 +319,7 @@ int SslSocket::getKeyLen() const
int keySize = 0;
SECStatus rc;
- rc = SSL_SecurityStatus( socket,
+ rc = SSL_SecurityStatus( nssSocket,
&enabled,
NULL,
NULL,
@@ -374,7 +334,7 @@ int SslSocket::getKeyLen() const
std::string SslSocket::getClientAuthId() const
{
std::string authId;
- CERTCertificate* cert = SSL_PeerCertificate(socket);
+ CERTCertificate* cert = SSL_PeerCertificate(nssSocket);
if (cert) {
authId = CERT_GetCommonName(&(cert->subject));
/*
diff --git a/cpp/src/qpid/sys/ssl/SslSocket.h b/cpp/src/qpid/sys/ssl/SslSocket.h
index eabadcbe23..fc97059cfd 100644
--- a/cpp/src/qpid/sys/ssl/SslSocket.h
+++ b/cpp/src/qpid/sys/ssl/SslSocket.h
@@ -23,7 +23,7 @@
*/
#include "qpid/sys/IOHandle.h"
-#include "qpid/sys/Socket.h"
+#include "qpid/sys/posix/BSDSocket.h"
#include <nspr.h>
#include <string>
@@ -37,55 +37,54 @@ class Duration;
namespace ssl {
-class SslSocket : public qpid::sys::Socket
+class SslSocket : public qpid::sys::BSDSocket
{
public:
- /** Create a socket wrapper for descriptor. */
- SslSocket();
+ /** Create a socket wrapper for descriptor.
+ *@param certName name of certificate to use to identify the socket
+ */
+ SslSocket(const std::string& certName = "", bool clientAuth = false);
/** Set socket non blocking */
void setNonblocking() const;
/** Set tcp-nodelay */
- void setTcpNoDelay(bool nodelay) const;
+ void setTcpNoDelay() const;
/** Set SSL cert-name. Allows the cert-name to be set per
* connection, overriding global cert-name settings from
* NSSInit().*/
void setCertName(const std::string& certName);
- void connect(const std::string& host, const std::string& port) const;
+ void connect(const SocketAddress&) const;
+ void finishConnect(const SocketAddress&) const;
void close() const;
/** Bind to a port and start listening.
*@param port 0 means choose an available port.
*@param backlog maximum number of pending connections.
- *@param certName name of certificate to use to identify the server
*@return The bound port.
*/
- int listen(uint16_t port = 0, int backlog = 10, const std::string& certName = "localhost.localdomain", bool clientAuth = false) const;
+ int listen(const SocketAddress&, int backlog = 10) const;
/**
* Accept a connection from a socket that is already listening
* and has an incoming connection
*/
- SslSocket* accept() const;
+ virtual Socket* accept() const;
// TODO The following are raw operations, maybe they need better wrapping?
int read(void *buf, size_t count) const;
int write(const void *buf, size_t count) const;
- uint16_t getLocalPort() const;
- uint16_t getRemotePort() const;
-
int getKeyLen() const;
std::string getClientAuthId() const;
protected:
- mutable std::string connectname;
- mutable PRFileDesc* socket;
+ mutable PRFileDesc* nssSocket;
std::string certname;
+ mutable std::string url;
/**
* 'model' socket, with configuration to use when importing
@@ -94,13 +93,14 @@ protected:
*/
mutable PRFileDesc* prototype;
- SslSocket(IOHandlePrivate* ioph, PRFileDesc* model);
- friend class SslMuxSocket;
+ SslSocket(int fd, PRFileDesc* model);
+ friend class SslMuxSocket; // Needed for this constructor
};
class SslMuxSocket : public SslSocket
{
public:
+ SslMuxSocket(const std::string& certName = "", bool clientAuth = false);
Socket* accept() const;
};
diff --git a/cpp/src/qpid/sys/ssl/util.cpp b/cpp/src/qpid/sys/ssl/util.cpp
index 3078e894df..de5d638b09 100644
--- a/cpp/src/qpid/sys/ssl/util.cpp
+++ b/cpp/src/qpid/sys/ssl/util.cpp
@@ -31,8 +31,6 @@
#include <iostream>
#include <fstream>
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
namespace qpid {
namespace sys {
@@ -82,15 +80,14 @@ SslOptions SslOptions::global;
char* readPasswordFromFile(PK11SlotInfo*, PRBool retry, void*)
{
const std::string& passwordFile = SslOptions::global.certPasswordFile;
- if (retry || passwordFile.empty() || !boost::filesystem::exists(passwordFile)) {
- return 0;
- } else {
- std::ifstream file(passwordFile.c_str());
- std::string password;
- file >> password;
- return PL_strdup(password.c_str());
- }
-}
+ if (retry || passwordFile.empty()) return 0;
+ std::ifstream file(passwordFile.c_str());
+ if (!file) return 0;
+
+ std::string password;
+ file >> password;
+ return PL_strdup(password.c_str());
+}
void initNSS(const SslOptions& options, bool server)
{
diff --git a/cpp/src/qpid/sys/windows/AsynchIO.cpp b/cpp/src/qpid/sys/windows/AsynchIO.cpp
index 355acbe0e6..b36ee9f941 100644
--- a/cpp/src/qpid/sys/windows/AsynchIO.cpp
+++ b/cpp/src/qpid/sys/windows/AsynchIO.cpp
@@ -24,6 +24,8 @@
#include "qpid/sys/AsynchIO.h"
#include "qpid/sys/Mutex.h"
#include "qpid/sys/Socket.h"
+#include "qpid/sys/windows/WinSocket.h"
+#include "qpid/sys/SocketAddress.h"
#include "qpid/sys/Poller.h"
#include "qpid/sys/Thread.h"
#include "qpid/sys/Time.h"
@@ -50,8 +52,8 @@ namespace {
* The function pointers for AcceptEx and ConnectEx need to be looked up
* at run time.
*/
-const LPFN_ACCEPTEX lookUpAcceptEx(const qpid::sys::Socket& s) {
- SOCKET h = toSocketHandle(s);
+const LPFN_ACCEPTEX lookUpAcceptEx(const qpid::sys::IOHandle& io) {
+ SOCKET h = io.fd;
GUID guidAcceptEx = WSAID_ACCEPTEX;
DWORD dwBytes = 0;
LPFN_ACCEPTEX fnAcceptEx;
@@ -93,12 +95,14 @@ private:
AsynchAcceptor::Callback acceptedCallback;
const Socket& socket;
+ const SOCKET wSocket;
const LPFN_ACCEPTEX fnAcceptEx;
};
AsynchAcceptor::AsynchAcceptor(const Socket& s, Callback callback)
: acceptedCallback(callback),
socket(s),
+ wSocket(IOHandle(s).fd),
fnAcceptEx(lookUpAcceptEx(s)) {
s.setNonblocking();
@@ -121,8 +125,8 @@ void AsynchAcceptor::restart(void) {
this,
socket);
BOOL status;
- status = fnAcceptEx(toSocketHandle(socket),
- toSocketHandle(*result->newSocket),
+ status = fnAcceptEx(wSocket,
+ IOHandle(*result->newSocket).fd,
result->addressBuffer,
0,
AsynchAcceptResult::SOCKADDRMAXLEN,
@@ -133,16 +137,30 @@ void AsynchAcceptor::restart(void) {
}
+Socket* createSameTypeSocket(const Socket& sock) {
+ SOCKET socket = IOHandle(sock).fd;
+ // Socket currently has no actual socket attached
+ if (socket == INVALID_SOCKET)
+ return new WinSocket;
+
+ ::sockaddr_storage sa;
+ ::socklen_t salen = sizeof(sa);
+ QPID_WINSOCK_CHECK(::getsockname(socket, (::sockaddr*)&sa, &salen));
+ SOCKET s = ::socket(sa.ss_family, SOCK_STREAM, 0); // Currently only work with SOCK_STREAM
+ if (s == INVALID_SOCKET) throw QPID_WINDOWS_ERROR(WSAGetLastError());
+ return new WinSocket(s);
+}
+
AsynchAcceptResult::AsynchAcceptResult(AsynchAcceptor::Callback cb,
AsynchAcceptor *acceptor,
- const Socket& listener)
+ const Socket& lsocket)
: callback(cb), acceptor(acceptor),
- listener(toSocketHandle(listener)),
- newSocket(listener.createSameTypeSocket()) {
+ listener(IOHandle(lsocket).fd),
+ newSocket(createSameTypeSocket(lsocket)) {
}
void AsynchAcceptResult::success(size_t /*bytesTransferred*/) {
- ::setsockopt (toSocketHandle(*newSocket),
+ ::setsockopt (IOHandle(*newSocket).fd,
SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT,
(char*)&listener,
@@ -180,6 +198,7 @@ public:
ConnectedCallback connCb,
FailedCallback failCb = 0);
void start(Poller::shared_ptr poller);
+ void requestCallback(RequestCallback rCb);
};
AsynchConnector::AsynchConnector(const Socket& sock,
@@ -195,7 +214,7 @@ AsynchConnector::AsynchConnector(const Socket& sock,
void AsynchConnector::start(Poller::shared_ptr)
{
try {
- socket.connect(hostname, port);
+ socket.connect(SocketAddress(hostname, port));
socket.setNonblocking();
connCallback(socket);
} catch(std::exception& e) {
@@ -205,6 +224,13 @@ void AsynchConnector::start(Poller::shared_ptr)
}
}
+// This can never be called in the current windows code as connect
+// is blocking and requestCallback only makes sense if connect is
+// non-blocking with the results returned via a poller callback.
+void AsynchConnector::requestCallback(RequestCallback rCb)
+{
+}
+
} // namespace windows
AsynchAcceptor* AsynchAcceptor::create(const Socket& s,
@@ -260,8 +286,6 @@ public:
virtual void notifyPendingWrite();
virtual void queueWriteClose();
virtual bool writeQueueEmpty();
- virtual void startReading();
- virtual void stopReading();
virtual void requestCallback(RequestCallback);
/**
@@ -272,6 +296,8 @@ public:
*/
virtual BufferBase* getQueuedBuffer();
+ virtual SecuritySettings getSecuritySettings(void);
+
private:
ReadCallback readCallback;
EofCallback eofCallback;
@@ -319,6 +345,12 @@ private:
void close(void);
/**
+ * startReading initiates reading, readComplete() is
+ * called when the read completes.
+ */
+ void startReading();
+
+ /**
* readComplete is called when a read request is complete.
*
* @param result Results of the operation.
@@ -362,7 +394,7 @@ class CallbackHandle : public IOHandle {
public:
CallbackHandle(AsynchIoResult::Completer completeCb,
AsynchIO::RequestCallback reqCb = 0) :
- IOHandle(new IOHandlePrivate (INVALID_SOCKET, completeCb, reqCb))
+ IOHandle(INVALID_SOCKET, completeCb, reqCb)
{}
};
@@ -515,7 +547,7 @@ void AsynchIO::startReading() {
DWORD bytesReceived = 0, flags = 0;
InterlockedIncrement(&opsInProgress);
readInProgress = true;
- int status = WSARecv(toSocketHandle(socket),
+ int status = WSARecv(IOHandle(socket).fd,
const_cast<LPWSABUF>(result->getWSABUF()), 1,
&bytesReceived,
&flags,
@@ -537,15 +569,6 @@ void AsynchIO::startReading() {
return;
}
-// stopReading was added to prevent a race condition with read-credit on Linux.
-// It may or may not be required on windows.
-//
-// AsynchIOHandler::readbuff() calls stopReading() inside the same
-// critical section that protects startReading() in
-// AsynchIOHandler::giveReadCredit().
-//
-void AsynchIO::stopReading() {}
-
// Queue the specified callback for invocation from an I/O thread.
void AsynchIO::requestCallback(RequestCallback callback) {
// This method is generally called from a processing thread; transfer
@@ -613,7 +636,7 @@ void AsynchIO::startWrite(AsynchIO::BufferBase* buff) {
buff,
buff->dataCount);
DWORD bytesSent = 0;
- int status = WSASend(toSocketHandle(socket),
+ int status = WSASend(IOHandle(socket).fd,
const_cast<LPWSABUF>(result->getWSABUF()), 1,
&bytesSent,
0,
@@ -639,6 +662,13 @@ void AsynchIO::close(void) {
notifyClosed();
}
+SecuritySettings AsynchIO::getSecuritySettings() {
+ SecuritySettings settings;
+ settings.ssf = socket.getKeyLen();
+ settings.authid = socket.getClientAuthId();
+ return settings;
+}
+
void AsynchIO::readComplete(AsynchReadResult *result) {
int status = result->getStatus();
size_t bytes = result->getTransferred();
@@ -683,7 +713,8 @@ void AsynchIO::writeComplete(AsynchWriteResult *result) {
else {
// An error... if it's a connection close, ignore it - it will be
// noticed and handled on a read completion any moment now.
- // What to do with real error??? Save the Buffer?
+ // What to do with real error??? Save the Buffer? TBD.
+ queueReadBuffer(buff); // All done; back to the pool
}
}
diff --git a/cpp/src/qpid/sys/windows/FileSysDir.cpp b/cpp/src/qpid/sys/windows/FileSysDir.cpp
index 88f1637d48..e090747715 100644
--- a/cpp/src/qpid/sys/windows/FileSysDir.cpp
+++ b/cpp/src/qpid/sys/windows/FileSysDir.cpp
@@ -24,6 +24,9 @@
#include <sys/stat.h>
#include <direct.h>
#include <errno.h>
+#include <windows.h>
+#include <strsafe.h>
+
namespace qpid {
namespace sys {
@@ -50,4 +53,36 @@ void FileSysDir::mkdir(void)
throw Exception ("Can't create directory: " + dirPath);
}
+void FileSysDir::forEachFile(Callback cb) const {
+
+ WIN32_FIND_DATAA findFileData;
+ char szDir[MAX_PATH];
+ size_t dirPathLength;
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+
+ // create dirPath+"\*" in szDir
+ StringCchLength (dirPath.c_str(), MAX_PATH, &dirPathLength);
+
+ if (dirPathLength > (MAX_PATH - 3)) {
+ throw Exception ("Directory path is too long: " + dirPath);
+ }
+
+ StringCchCopy(szDir, MAX_PATH, dirPath.c_str());
+ StringCchCat(szDir, MAX_PATH, TEXT("\\*"));
+
+ // Special work for first file
+ hFind = FindFirstFileA(szDir, &findFileData);
+ if (INVALID_HANDLE_VALUE == hFind) {
+ return;
+ }
+
+ // process everything that isn't a directory
+ do {
+ if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
+ std::string fileName(findFileData.cFileName);
+ cb(fileName);
+ }
+ } while (FindNextFile(hFind, &findFileData) != 0);
+}
+
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/windows/IOHandle.cpp b/cpp/src/qpid/sys/windows/IOHandle.cpp
index 250737cb99..19a1c44875 100755
--- a/cpp/src/qpid/sys/windows/IOHandle.cpp
+++ b/cpp/src/qpid/sys/windows/IOHandle.cpp
@@ -19,24 +19,11 @@
*
*/
-#include "qpid/sys/IOHandle.h"
#include "qpid/sys/windows/IoHandlePrivate.h"
#include <windows.h>
namespace qpid {
namespace sys {
-SOCKET toFd(const IOHandlePrivate* h)
-{
- return h->fd;
-}
-
-IOHandle::IOHandle(IOHandlePrivate* h) :
- impl(h)
-{}
-
-IOHandle::~IOHandle() {
- delete impl;
-}
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/windows/IoHandlePrivate.h b/cpp/src/qpid/sys/windows/IoHandlePrivate.h
index 5943db5cc7..4529ad93ec 100755
--- a/cpp/src/qpid/sys/windows/IoHandlePrivate.h
+++ b/cpp/src/qpid/sys/windows/IoHandlePrivate.h
@@ -38,15 +38,14 @@ namespace sys {
// completer from an I/O thread. If the callback mechanism is used, there
// can be a RequestCallback set - this carries the callback object through
// from AsynchIO::requestCallback() through to the I/O completion processing.
-class IOHandlePrivate {
- friend QPID_COMMON_EXTERN SOCKET toSocketHandle(const Socket& s);
- static IOHandlePrivate* getImpl(const IOHandle& h);
-
+class IOHandle {
public:
- IOHandlePrivate(SOCKET f = INVALID_SOCKET,
- windows::AsynchIoResult::Completer cb = 0,
- AsynchIO::RequestCallback reqCallback = 0) :
- fd(f), event(cb), cbRequest(reqCallback)
+ IOHandle(SOCKET f = INVALID_SOCKET,
+ windows::AsynchIoResult::Completer cb = 0,
+ AsynchIO::RequestCallback reqCallback = 0) :
+ fd(f),
+ event(cb),
+ cbRequest(reqCallback)
{}
SOCKET fd;
@@ -54,8 +53,6 @@ public:
AsynchIO::RequestCallback cbRequest;
};
-QPID_COMMON_EXTERN SOCKET toSocketHandle(const Socket& s);
-
}}
#endif /* _sys_windows_IoHandlePrivate_h */
diff --git a/cpp/src/qpid/sys/windows/IocpPoller.cpp b/cpp/src/qpid/sys/windows/IocpPoller.cpp
index c81cef87b0..ecb33c5517 100755
--- a/cpp/src/qpid/sys/windows/IocpPoller.cpp
+++ b/cpp/src/qpid/sys/windows/IocpPoller.cpp
@@ -22,7 +22,7 @@
#include "qpid/sys/Poller.h"
#include "qpid/sys/Mutex.h"
#include "qpid/sys/Dispatcher.h"
-
+#include "qpid/sys/IOHandle.h"
#include "qpid/sys/windows/AsynchIoResult.h"
#include "qpid/sys/windows/IoHandlePrivate.h"
#include "qpid/sys/windows/check.h"
@@ -55,7 +55,7 @@ class PollerHandlePrivate {
};
PollerHandle::PollerHandle(const IOHandle& h) :
- impl(new PollerHandlePrivate(toSocketHandle(static_cast<const Socket&>(h)), h.impl->event, h.impl->cbRequest))
+ impl(new PollerHandlePrivate(h.fd, h.event, h.cbRequest))
{}
PollerHandle::~PollerHandle() {
diff --git a/cpp/src/qpid/sys/windows/PollableCondition.cpp b/cpp/src/qpid/sys/windows/PollableCondition.cpp
index bb637be0a6..3e2a5fb36c 100644
--- a/cpp/src/qpid/sys/windows/PollableCondition.cpp
+++ b/cpp/src/qpid/sys/windows/PollableCondition.cpp
@@ -52,14 +52,14 @@ private:
PollableCondition& parent;
boost::shared_ptr<sys::Poller> poller;
LONG isSet;
+ LONG isDispatching;
};
PollableConditionPrivate::PollableConditionPrivate(const sys::PollableCondition::Callback& cb,
sys::PollableCondition& parent,
const boost::shared_ptr<sys::Poller>& poller)
- : IOHandle(new sys::IOHandlePrivate(INVALID_SOCKET,
- boost::bind(&PollableConditionPrivate::dispatch, this, _1))),
- cb(cb), parent(parent), poller(poller), isSet(0)
+ : IOHandle(INVALID_SOCKET, boost::bind(&PollableConditionPrivate::dispatch, this, _1)),
+ cb(cb), parent(parent), poller(poller), isSet(0), isDispatching(0)
{
}
@@ -78,7 +78,12 @@ void PollableConditionPrivate::poke()
void PollableConditionPrivate::dispatch(windows::AsynchIoResult *result)
{
delete result; // Poller::monitorHandle() allocates this
+ // If isDispatching is already set, just return. Else, enter.
+ if (::InterlockedCompareExchange(&isDispatching, 1, 0) == 1)
+ return;
cb(parent);
+ LONG oops = ::InterlockedDecrement(&isDispatching); // Result must be 0
+ assert(!oops);
if (isSet)
poke();
}
diff --git a/cpp/src/qpid/sys/windows/QpidDllMain.h b/cpp/src/qpid/sys/windows/QpidDllMain.h
new file mode 100644
index 0000000000..74eaf0256a
--- /dev/null
+++ b/cpp/src/qpid/sys/windows/QpidDllMain.h
@@ -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.
+ *
+ */
+
+/*
+ * Include this file once in each DLL that relies on SystemInfo.h:
+ * threadSafeShutdown(). Note that Thread.cpp has a more elaborate
+ * DllMain, that also provides this functionality separately.
+ *
+ * Teardown is in the reverse order of the DLL dependencies used
+ * during the load phase. The calls to DllMain and the static
+ * destructors are from the same thread, so no locking is necessary
+ * and there is no downside to an invocation of DllMain by multiple
+ * Qpid DLLs.
+ */
+
+#ifdef _DLL
+
+#include <qpid/ImportExport.h>
+#include <windows.h>
+
+namespace qpid {
+namespace sys {
+namespace windows {
+
+QPID_IMPORT bool processExiting;
+QPID_IMPORT bool libraryUnloading;
+
+}}} // namespace qpid::sys::SystemInfo
+
+
+BOOL APIENTRY DllMain(HMODULE hm, DWORD reason, LPVOID reserved) {
+ switch (reason) {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ break;
+
+ case DLL_PROCESS_DETACH:
+ // Remember how the process is terminating this DLL.
+ if (reserved != NULL) {
+ qpid::sys::windows::processExiting = true;
+ // Danger: all threading suspect, including indirect use of malloc or locks.
+ // Think twice before adding more functionality here.
+ return TRUE;
+ }
+ else {
+ qpid::sys::windows::libraryUnloading = true;
+ }
+ break;
+ }
+ return TRUE;
+}
+
+
+#endif
diff --git a/cpp/src/qpid/sys/windows/Socket.cpp b/cpp/src/qpid/sys/windows/Socket.cpp
deleted file mode 100644
index a4374260cc..0000000000
--- a/cpp/src/qpid/sys/windows/Socket.cpp
+++ /dev/null
@@ -1,292 +0,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.
- *
- */
-
-#include "qpid/sys/Socket.h"
-
-#include "qpid/sys/SocketAddress.h"
-#include "qpid/sys/windows/check.h"
-#include "qpid/sys/windows/IoHandlePrivate.h"
-
-// Ensure we get all of winsock2.h
-#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501
-#endif
-
-#include <winsock2.h>
-
-namespace qpid {
-namespace sys {
-
-// Need to initialize WinSock. Ideally, this would be a singleton or embedded
-// in some one-time initialization function. I tried boost singleton and could
-// not get it to compile (and others located in google had the same problem).
-// So, this simple static with an interlocked increment will do for known
-// use cases at this time. Since this will only shut down winsock at process
-// termination, there may be some problems with client programs that also
-// expect to load and unload winsock, but we'll see...
-// If someone does get an easy-to-use singleton sometime, converting to it
-// may be preferable.
-
-namespace {
-
-static LONG volatile initialized = 0;
-
-class WinSockSetup {
- // : public boost::details::pool::singleton_default<WinSockSetup> {
-
-public:
- WinSockSetup() {
- LONG timesEntered = InterlockedIncrement(&initialized);
- if (timesEntered > 1)
- return;
- err = 0;
- WORD wVersionRequested;
- WSADATA wsaData;
-
- /* Request WinSock 2.2 */
- wVersionRequested = MAKEWORD(2, 2);
- err = WSAStartup(wVersionRequested, &wsaData);
- }
-
- ~WinSockSetup() {
- WSACleanup();
- }
-
-public:
- int error(void) const { return err; }
-
-protected:
- DWORD err;
-};
-
-static WinSockSetup setup;
-
-std::string getName(SOCKET fd, bool local)
-{
- ::sockaddr_storage name_s; // big enough for any socket address
- ::sockaddr* name = (::sockaddr*)&name_s;
- ::socklen_t namelen = sizeof(name_s);
-
- if (local) {
- QPID_WINSOCK_CHECK(::getsockname(fd, name, &namelen));
- } else {
- QPID_WINSOCK_CHECK(::getpeername(fd, name, &namelen));
- }
-
- return SocketAddress::asString(name, namelen);
-}
-
-uint16_t getLocalPort(int fd)
-{
- ::sockaddr_storage name_s; // big enough for any socket address
- ::sockaddr* name = (::sockaddr*)&name_s;
- ::socklen_t namelen = sizeof(name_s);
-
- QPID_WINSOCK_CHECK(::getsockname(fd, name, &namelen));
-
- return SocketAddress::getPort(name);
-}
-} // namespace
-
-Socket::Socket() :
- IOHandle(new IOHandlePrivate),
- nonblocking(false),
- nodelay(false)
-{}
-
-Socket::Socket(IOHandlePrivate* h) :
- IOHandle(h),
- nonblocking(false),
- nodelay(false)
-{}
-
-void Socket::createSocket(const SocketAddress& sa) const
-{
- SOCKET& socket = impl->fd;
- if (socket != INVALID_SOCKET) Socket::close();
-
- SOCKET s = ::socket (getAddrInfo(sa).ai_family,
- getAddrInfo(sa).ai_socktype,
- 0);
- if (s == INVALID_SOCKET) throw QPID_WINDOWS_ERROR(WSAGetLastError());
- socket = s;
-
- try {
- if (nonblocking) setNonblocking();
- if (nodelay) setTcpNoDelay();
- } catch (std::exception&) {
- ::closesocket(s);
- socket = INVALID_SOCKET;
- throw;
- }
-}
-
-Socket* Socket::createSameTypeSocket() const {
- SOCKET& socket = impl->fd;
- // Socket currently has no actual socket attached
- if (socket == INVALID_SOCKET)
- return new Socket;
-
- ::sockaddr_storage sa;
- ::socklen_t salen = sizeof(sa);
- QPID_WINSOCK_CHECK(::getsockname(socket, (::sockaddr*)&sa, &salen));
- SOCKET s = ::socket(sa.ss_family, SOCK_STREAM, 0); // Currently only work with SOCK_STREAM
- if (s == INVALID_SOCKET) throw QPID_WINDOWS_ERROR(WSAGetLastError());
- return new Socket(new IOHandlePrivate(s));
-}
-
-void Socket::setNonblocking() const {
- u_long nonblock = 1;
- QPID_WINSOCK_CHECK(ioctlsocket(impl->fd, FIONBIO, &nonblock));
-}
-
-void Socket::connect(const std::string& host, const std::string& port) const
-{
- SocketAddress sa(host, port);
- connect(sa);
-}
-
-void
-Socket::connect(const SocketAddress& addr) const
-{
- peername = addr.asString(false);
-
- createSocket(addr);
-
- const SOCKET& socket = impl->fd;
- int err;
- WSASetLastError(0);
- if ((::connect(socket, getAddrInfo(addr).ai_addr, getAddrInfo(addr).ai_addrlen) != 0) &&
- ((err = ::WSAGetLastError()) != WSAEWOULDBLOCK))
- throw qpid::Exception(QPID_MSG(strError(err) << ": " << peername));
-}
-
-void
-Socket::close() const
-{
- SOCKET& socket = impl->fd;
- if (socket == INVALID_SOCKET) return;
- QPID_WINSOCK_CHECK(closesocket(socket));
- socket = INVALID_SOCKET;
-}
-
-
-int Socket::write(const void *buf, size_t count) const
-{
- const SOCKET& socket = impl->fd;
- int sent = ::send(socket, (const char *)buf, count, 0);
- if (sent == SOCKET_ERROR)
- return -1;
- return sent;
-}
-
-int Socket::read(void *buf, size_t count) const
-{
- const SOCKET& socket = impl->fd;
- int received = ::recv(socket, (char *)buf, count, 0);
- if (received == SOCKET_ERROR)
- return -1;
- return received;
-}
-
-int Socket::listen(const std::string& host, const std::string& port, int backlog) const
-{
- SocketAddress sa(host, port);
- return listen(sa, backlog);
-}
-
-int Socket::listen(const SocketAddress& addr, int backlog) const
-{
- createSocket(addr);
-
- const SOCKET& socket = impl->fd;
- BOOL yes=1;
- QPID_WINSOCK_CHECK(setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)));
-
- if (::bind(socket, getAddrInfo(addr).ai_addr, getAddrInfo(addr).ai_addrlen) == SOCKET_ERROR)
- throw Exception(QPID_MSG("Can't bind to " << addr.asString() << ": " << strError(WSAGetLastError())));
- if (::listen(socket, backlog) == SOCKET_ERROR)
- throw Exception(QPID_MSG("Can't listen on " <<addr.asString() << ": " << strError(WSAGetLastError())));
-
- return getLocalPort(socket);
-}
-
-Socket* Socket::accept() const
-{
- SOCKET afd = ::accept(impl->fd, 0, 0);
- if (afd != INVALID_SOCKET)
- return new Socket(new IOHandlePrivate(afd));
- else if (WSAGetLastError() == EAGAIN)
- return 0;
- else throw QPID_WINDOWS_ERROR(WSAGetLastError());
-}
-
-std::string Socket::getPeerAddress() const
-{
- if (peername.empty()) {
- peername = getName(impl->fd, false);
- }
- return peername;
-}
-
-std::string Socket::getLocalAddress() const
-{
- if (localname.empty()) {
- localname = getName(impl->fd, true);
- }
- return localname;
-}
-
-int Socket::getError() const
-{
- int result;
- socklen_t rSize = sizeof (result);
-
- QPID_WINSOCK_CHECK(::getsockopt(impl->fd, SOL_SOCKET, SO_ERROR, (char *)&result, &rSize));
- return result;
-}
-
-void Socket::setTcpNoDelay() const
-{
- SOCKET& socket = impl->fd;
- nodelay = true;
- if (socket != INVALID_SOCKET) {
- int flag = 1;
- int result = setsockopt(impl->fd,
- IPPROTO_TCP,
- TCP_NODELAY,
- (char *)&flag,
- sizeof(flag));
- QPID_WINSOCK_CHECK(result);
- }
-}
-
-inline IOHandlePrivate* IOHandlePrivate::getImpl(const qpid::sys::IOHandle &h)
-{
- return h.impl;
-}
-
-SOCKET toSocketHandle(const Socket& s)
-{
- return IOHandlePrivate::getImpl(s)->fd;
-}
-
-}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/windows/SslAsynchIO.cpp b/cpp/src/qpid/sys/windows/SslAsynchIO.cpp
index d263f00ab3..e48c799b29 100644
--- a/cpp/src/qpid/sys/windows/SslAsynchIO.cpp
+++ b/cpp/src/qpid/sys/windows/SslAsynchIO.cpp
@@ -209,18 +209,6 @@ bool SslAsynchIO::writeQueueEmpty() {
return aio->writeQueueEmpty();
}
-/*
- * Initiate a read operation. AsynchIO::readComplete() will be
- * called when the read is complete and data is available.
- */
-void SslAsynchIO::startReading() {
- aio->startReading();
-}
-
-void SslAsynchIO::stopReading() {
- aio->stopReading();
-}
-
// Queue the specified callback for invocation from an I/O thread.
void SslAsynchIO::requestCallback(RequestCallback callback) {
aio->requestCallback(callback);
@@ -241,11 +229,15 @@ AsynchIO::BufferBase* SslAsynchIO::getQueuedBuffer() {
return sslBuff;
}
-unsigned int SslAsynchIO::getSslKeySize() {
+SecuritySettings SslAsynchIO::getSecuritySettings() {
SecPkgContext_KeyInfo info;
memset(&info, 0, sizeof(info));
::QueryContextAttributes(&ctxtHandle, SECPKG_ATTR_KEY_INFO, &info);
- return info.KeySize;
+
+ SecuritySettings settings;
+ settings.ssf = info.KeySize;
+ settings.authid = std::string();
+ return settings;
}
void SslAsynchIO::negotiationDone() {
diff --git a/cpp/src/qpid/sys/windows/SslAsynchIO.h b/cpp/src/qpid/sys/windows/SslAsynchIO.h
index e9d9e8d629..2f6842b135 100644
--- a/cpp/src/qpid/sys/windows/SslAsynchIO.h
+++ b/cpp/src/qpid/sys/windows/SslAsynchIO.h
@@ -77,12 +77,9 @@ public:
virtual void notifyPendingWrite();
virtual void queueWriteClose();
virtual bool writeQueueEmpty();
- virtual void startReading();
- virtual void stopReading();
virtual void requestCallback(RequestCallback);
virtual BufferBase* getQueuedBuffer();
-
- QPID_COMMON_EXTERN unsigned int getSslKeySize();
+ virtual SecuritySettings getSecuritySettings(void);
protected:
CredHandle credHandle;
diff --git a/cpp/src/qpid/sys/windows/SystemInfo.cpp b/cpp/src/qpid/sys/windows/SystemInfo.cpp
index cef78dcc60..fb58d53b81 100755
--- a/cpp/src/qpid/sys/windows/SystemInfo.cpp
+++ b/cpp/src/qpid/sys/windows/SystemInfo.cpp
@@ -25,7 +25,8 @@
#include "qpid/sys/SystemInfo.h"
#include "qpid/sys/IntegerTypes.h"
-#include "qpid/Exception.h"
+#include "qpid/Exception.h"
+#include "qpid/log/Statement.h"
#include <assert.h>
#include <winsock2.h>
@@ -66,39 +67,10 @@ bool SystemInfo::getLocalHostname (Address &address) {
static const std::string LOCALHOST("127.0.0.1");
static const std::string TCP("tcp");
-void SystemInfo::getLocalIpAddresses (uint16_t port,
- std::vector<Address> &addrList) {
- enum { MAX_URL_INTERFACES = 100 };
-
- SOCKET s = socket (PF_INET, SOCK_STREAM, 0);
- if (s != INVALID_SOCKET) {
- INTERFACE_INFO interfaces[MAX_URL_INTERFACES];
- DWORD filledBytes = 0;
- WSAIoctl (s,
- SIO_GET_INTERFACE_LIST,
- 0,
- 0,
- interfaces,
- sizeof (interfaces),
- &filledBytes,
- 0,
- 0);
- unsigned int interfaceCount = filledBytes / sizeof (INTERFACE_INFO);
- for (unsigned int i = 0; i < interfaceCount; ++i) {
- if (interfaces[i].iiFlags & IFF_UP) {
- std::string addr(inet_ntoa(interfaces[i].iiAddress.AddressIn.sin_addr));
- if (addr != LOCALHOST)
- addrList.push_back(Address(TCP, addr, port));
- }
- }
- closesocket (s);
- }
-}
-
-bool SystemInfo::isLocalHost(const std::string& candidateHost) {
- // FIXME aconway 2012-05-03: not implemented.
- assert(0);
- throw Exception("Not implemented: isLocalHost");
+// Null function which always fails to find an network interface name
+bool SystemInfo::getInterfaceAddresses(const std::string&, std::vector<std::string>&)
+{
+ return false;
}
void SystemInfo::getSystemId (std::string &osName,
@@ -208,4 +180,29 @@ std::string SystemInfo::getProcessName()
return name;
}
+
+#ifdef _DLL
+namespace windows {
+// set from one or more Qpid DLLs: i.e. in DllMain with DLL_PROCESS_DETACH
+QPID_EXPORT bool processExiting = false;
+QPID_EXPORT bool libraryUnloading = false;
+}
+#endif
+
+bool SystemInfo::threadSafeShutdown()
+{
+#ifdef _DLL
+ if (!windows::processExiting && !windows::libraryUnloading) {
+ // called before exit() or FreeLibrary(), or by a DLL without
+ // a participating DllMain.
+ QPID_LOG(warning, "invalid query for shutdown state");
+ throw qpid::Exception(QPID_MSG("Unable to determine shutdown state."));
+ }
+ return !windows::processExiting;
+#else
+ // Not a DLL: shutdown can only be by exit() or return from main().
+ return false;
+#endif
+}
+
}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/windows/Thread.cpp b/cpp/src/qpid/sys/windows/Thread.cpp
index 23b0033be4..b342c9da1d 100755
--- a/cpp/src/qpid/sys/windows/Thread.cpp
+++ b/cpp/src/qpid/sys/windows/Thread.cpp
@@ -27,6 +27,7 @@
#include "qpid/sys/Thread.h"
#include "qpid/sys/Runnable.h"
#include "qpid/sys/windows/check.h"
+#include "qpid/sys/SystemInfo.h"
#include <process.h>
#include <windows.h>
@@ -274,8 +275,17 @@ Thread Thread::current() {
#ifdef _DLL
+namespace qpid {
+namespace sys {
+namespace windows {
+
+extern bool processExiting;
+extern bool libraryUnloading;
+
+}}} // namespace qpid::sys::SystemInfo
+
// DllMain: called possibly many times in a process lifetime if dll
-// loaded and freed repeatedly . Be mindful of Windows loader lock
+// loaded and freed repeatedly. Be mindful of Windows loader lock
// and other DllMain restrictions.
BOOL APIENTRY DllMain(HMODULE hm, DWORD reason, LPVOID reserved) {
@@ -290,10 +300,12 @@ BOOL APIENTRY DllMain(HMODULE hm, DWORD reason, LPVOID reserved) {
if (reserved != NULL) {
// process exit(): threads are stopped arbitrarily and
// possibly in an inconsistent state. Not even threadLock
- // can be trusted. All static destructors have been
- // called at this point and any resources this unit knows
- // about will be released as part of process tear down by
- // the OS. Accordingly, do nothing.
+ // can be trusted. All static destructors for this unit
+ // are pending and face the same unsafe environment.
+ // Any resources this unit knows about will be released as
+ // part of process tear down by the OS. Accordingly, skip
+ // any clean up tasks.
+ qpid::sys::windows::processExiting = true;
return TRUE;
}
else {
@@ -301,6 +313,7 @@ BOOL APIENTRY DllMain(HMODULE hm, DWORD reason, LPVOID reserved) {
// encouraged to clean up to avoid leaks. Mostly we just
// want any straggler threads to finish and notify
// threadsDone as the last thing they do.
+ qpid::sys::windows::libraryUnloading = true;
while (1) {
{
ScopedCriticalSection l(threadLock);
diff --git a/cpp/src/qpid/sys/windows/WinSocket.cpp b/cpp/src/qpid/sys/windows/WinSocket.cpp
new file mode 100644
index 0000000000..b2d2d79c63
--- /dev/null
+++ b/cpp/src/qpid/sys/windows/WinSocket.cpp
@@ -0,0 +1,276 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/sys/windows/WinSocket.h"
+
+#include "qpid/sys/SocketAddress.h"
+#include "qpid/sys/windows/check.h"
+#include "qpid/sys/windows/IoHandlePrivate.h"
+#include "qpid/sys/SystemInfo.h"
+
+namespace qpid {
+namespace sys {
+
+// Need to initialize WinSock. Ideally, this would be a singleton or embedded
+// in some one-time initialization function. I tried boost singleton and could
+// not get it to compile (and others located in google had the same problem).
+// So, this simple static with an interlocked increment will do for known
+// use cases at this time. Since this will only shut down winsock at process
+// termination, there may be some problems with client programs that also
+// expect to load and unload winsock, but we'll see...
+// If someone does get an easy-to-use singleton sometime, converting to it
+// may be preferable.
+
+namespace {
+
+static LONG volatile initialized = 0;
+
+class WinSockSetup {
+ // : public boost::details::pool::singleton_default<WinSockSetup> {
+
+public:
+ WinSockSetup() {
+ LONG timesEntered = InterlockedIncrement(&initialized);
+ if (timesEntered > 1)
+ return;
+ err = 0;
+ WORD wVersionRequested;
+ WSADATA wsaData;
+
+ /* Request WinSock 2.2 */
+ wVersionRequested = MAKEWORD(2, 2);
+ err = WSAStartup(wVersionRequested, &wsaData);
+ }
+
+ ~WinSockSetup() {
+ if (SystemInfo::threadSafeShutdown())
+ WSACleanup();
+ }
+
+public:
+ int error(void) const { return err; }
+
+protected:
+ DWORD err;
+};
+
+static WinSockSetup setup;
+
+std::string getName(SOCKET fd, bool local)
+{
+ ::sockaddr_storage name_s; // big enough for any socket address
+ ::sockaddr* name = (::sockaddr*)&name_s;
+ ::socklen_t namelen = sizeof(name_s);
+
+ if (local) {
+ QPID_WINSOCK_CHECK(::getsockname(fd, name, &namelen));
+ } else {
+ QPID_WINSOCK_CHECK(::getpeername(fd, name, &namelen));
+ }
+
+ return SocketAddress::asString(name, namelen);
+}
+
+uint16_t getLocalPort(int fd)
+{
+ ::sockaddr_storage name_s; // big enough for any socket address
+ ::sockaddr* name = (::sockaddr*)&name_s;
+ ::socklen_t namelen = sizeof(name_s);
+
+ QPID_WINSOCK_CHECK(::getsockname(fd, name, &namelen));
+
+ return SocketAddress::getPort(name);
+}
+} // namespace
+
+WinSocket::WinSocket() :
+ handle(new IOHandle),
+ nonblocking(false),
+ nodelay(false)
+{}
+
+Socket* createSocket()
+{
+ return new WinSocket;
+}
+
+WinSocket::WinSocket(SOCKET fd) :
+ handle(new IOHandle(fd)),
+ nonblocking(false),
+ nodelay(false)
+{}
+
+WinSocket::operator const IOHandle&() const
+{
+ return *handle;
+}
+
+void WinSocket::createSocket(const SocketAddress& sa) const
+{
+ SOCKET& socket = handle->fd;
+ if (socket != INVALID_SOCKET) WinSocket::close();
+
+ SOCKET s = ::socket (getAddrInfo(sa).ai_family,
+ getAddrInfo(sa).ai_socktype,
+ 0);
+ if (s == INVALID_SOCKET) throw QPID_WINDOWS_ERROR(WSAGetLastError());
+ socket = s;
+
+ try {
+ if (nonblocking) setNonblocking();
+ if (nodelay) setTcpNoDelay();
+ } catch (std::exception&) {
+ ::closesocket(s);
+ socket = INVALID_SOCKET;
+ throw;
+ }
+}
+
+void WinSocket::setNonblocking() const {
+ u_long nonblock = 1;
+ QPID_WINSOCK_CHECK(ioctlsocket(handle->fd, FIONBIO, &nonblock));
+}
+
+void
+WinSocket::connect(const SocketAddress& addr) const
+{
+ peername = addr.asString(false);
+
+ createSocket(addr);
+
+ const SOCKET& socket = handle->fd;
+ int err;
+ WSASetLastError(0);
+ if ((::connect(socket, getAddrInfo(addr).ai_addr, getAddrInfo(addr).ai_addrlen) != 0) &&
+ ((err = ::WSAGetLastError()) != WSAEWOULDBLOCK))
+ throw qpid::Exception(QPID_MSG(strError(err) << ": " << peername));
+}
+
+void
+WinSocket::finishConnect(const SocketAddress&) const
+{
+}
+
+void
+WinSocket::close() const
+{
+ SOCKET& socket = handle->fd;
+ if (socket == INVALID_SOCKET) return;
+ QPID_WINSOCK_CHECK(closesocket(socket));
+ socket = INVALID_SOCKET;
+}
+
+
+int WinSocket::write(const void *buf, size_t count) const
+{
+ const SOCKET& socket = handle->fd;
+ int sent = ::send(socket, (const char *)buf, count, 0);
+ if (sent == SOCKET_ERROR)
+ return -1;
+ return sent;
+}
+
+int WinSocket::read(void *buf, size_t count) const
+{
+ const SOCKET& socket = handle->fd;
+ int received = ::recv(socket, (char *)buf, count, 0);
+ if (received == SOCKET_ERROR)
+ return -1;
+ return received;
+}
+
+int WinSocket::listen(const SocketAddress& addr, int backlog) const
+{
+ createSocket(addr);
+
+ const SOCKET& socket = handle->fd;
+ BOOL yes=1;
+ QPID_WINSOCK_CHECK(setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)));
+
+ if (::bind(socket, getAddrInfo(addr).ai_addr, getAddrInfo(addr).ai_addrlen) == SOCKET_ERROR)
+ throw Exception(QPID_MSG("Can't bind to " << addr.asString() << ": " << strError(WSAGetLastError())));
+ if (::listen(socket, backlog) == SOCKET_ERROR)
+ throw Exception(QPID_MSG("Can't listen on " <<addr.asString() << ": " << strError(WSAGetLastError())));
+
+ return getLocalPort(socket);
+}
+
+Socket* WinSocket::accept() const
+{
+ SOCKET afd = ::accept(handle->fd, 0, 0);
+ if (afd != INVALID_SOCKET)
+ return new WinSocket(afd);
+ else if (WSAGetLastError() == EAGAIN)
+ return 0;
+ else throw QPID_WINDOWS_ERROR(WSAGetLastError());
+}
+
+std::string WinSocket::getPeerAddress() const
+{
+ if (peername.empty()) {
+ peername = getName(handle->fd, false);
+ }
+ return peername;
+}
+
+std::string WinSocket::getLocalAddress() const
+{
+ if (localname.empty()) {
+ localname = getName(handle->fd, true);
+ }
+ return localname;
+}
+
+int WinSocket::getError() const
+{
+ int result;
+ socklen_t rSize = sizeof (result);
+
+ QPID_WINSOCK_CHECK(::getsockopt(handle->fd, SOL_SOCKET, SO_ERROR, (char *)&result, &rSize));
+ return result;
+}
+
+void WinSocket::setTcpNoDelay() const
+{
+ SOCKET& socket = handle->fd;
+ nodelay = true;
+ if (socket != INVALID_SOCKET) {
+ int flag = 1;
+ int result = setsockopt(handle->fd,
+ IPPROTO_TCP,
+ TCP_NODELAY,
+ (char *)&flag,
+ sizeof(flag));
+ QPID_WINSOCK_CHECK(result);
+ }
+}
+
+int WinSocket::getKeyLen() const
+{
+ return 0;
+}
+
+std::string WinSocket::getClientAuthId() const
+{
+ return std::string();
+}
+
+}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/windows/WinSocket.h b/cpp/src/qpid/sys/windows/WinSocket.h
new file mode 100644
index 0000000000..bee6a58e7a
--- /dev/null
+++ b/cpp/src/qpid/sys/windows/WinSocket.h
@@ -0,0 +1,118 @@
+#ifndef QPID_SYS_WINDOWS_BSDSOCKET_H
+#define QPID_SYS_WINDOWS_BSDSOCKET_H
+
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/sys/Socket.h"
+#include "qpid/sys/IntegerTypes.h"
+#include "qpid/CommonImportExport.h"
+#include <string>
+
+#include <boost/scoped_ptr.hpp>
+
+// Ensure we get all of winsock2.h
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
+
+#include <winsock2.h>
+
+namespace qpid {
+namespace sys {
+
+namespace windows {
+Socket* createSameTypeSocket(const Socket&);
+}
+
+class Duration;
+class IOHandle;
+class SocketAddress;
+
+class QPID_COMMON_CLASS_EXTERN WinSocket : public Socket
+{
+public:
+ /** Create a socket wrapper for descriptor. */
+ QPID_COMMON_EXTERN WinSocket();
+
+ QPID_COMMON_EXTERN operator const IOHandle&() const;
+
+ /** Set socket non blocking */
+ QPID_COMMON_EXTERN virtual void setNonblocking() const;
+
+ QPID_COMMON_EXTERN virtual void setTcpNoDelay() const;
+
+ QPID_COMMON_EXTERN virtual void connect(const SocketAddress&) const;
+ QPID_COMMON_EXTERN virtual void finishConnect(const SocketAddress&) const;
+
+ QPID_COMMON_EXTERN virtual void close() const;
+
+ /** Bind to a port and start listening.
+ *@return The bound port number
+ */
+ QPID_COMMON_EXTERN virtual int listen(const SocketAddress&, int backlog = 10) const;
+
+ /**
+ * Returns an address (host and port) for the remote end of the
+ * socket
+ */
+ QPID_COMMON_EXTERN std::string getPeerAddress() const;
+ /**
+ * Returns an address (host and port) for the local end of the
+ * socket
+ */
+ QPID_COMMON_EXTERN std::string getLocalAddress() const;
+
+ /**
+ * Returns the error code stored in the socket. This may be used
+ * to determine the result of a non-blocking connect.
+ */
+ QPID_COMMON_EXTERN int getError() const;
+
+ /** Accept a connection from a socket that is already listening
+ * and has an incoming connection
+ */
+ QPID_COMMON_EXTERN virtual Socket* accept() const;
+
+ // TODO The following are raw operations, maybe they need better wrapping?
+ QPID_COMMON_EXTERN virtual int read(void *buf, size_t count) const;
+ QPID_COMMON_EXTERN virtual int write(const void *buf, size_t count) const;
+
+ QPID_COMMON_EXTERN int getKeyLen() const;
+ QPID_COMMON_EXTERN std::string getClientAuthId() const;
+
+protected:
+ /** Create socket */
+ void createSocket(const SocketAddress&) const;
+
+ mutable boost::scoped_ptr<IOHandle> handle;
+ mutable std::string localname;
+ mutable std::string peername;
+ mutable bool nonblocking;
+ mutable bool nodelay;
+
+ /** Construct socket with existing handle */
+ friend Socket* qpid::sys::windows::createSameTypeSocket(const Socket&);
+ WinSocket(SOCKET fd);
+};
+
+}}
+#endif /*!QPID_SYS_WINDOWS_BSDSOCKET_H*/
diff --git a/cpp/src/qpid/types/Variant.cpp b/cpp/src/qpid/types/Variant.cpp
index d332fffa5e..8c9837e765 100644
--- a/cpp/src/qpid/types/Variant.cpp
+++ b/cpp/src/qpid/types/Variant.cpp
@@ -110,21 +110,28 @@ class VariantImpl
} value;
std::string encoding;//optional encoding for variable length data
- template<class T> T convertFromString() const
+ template<class T> T convertFromString() const
{
const std::string& s = *value.string;
+
try {
- T r = boost::lexical_cast<T>(s);
- //lexical_cast won't fail if string is a negative number and T is unsigned
- //So check that and allow special case of negative zero
- //else its a non-zero negative number so throw exception at end of function
- if (std::numeric_limits<T>::is_signed || s.find('-') != 0 || r == 0) {
- return r;
+ // Extra shenanigans to work around negative zero
+ // conversion error in older GCC libs.
+ if ( s[0] != '-' ) {
+ return boost::lexical_cast<T>(s);
+ } else {
+ T r = boost::lexical_cast<T>(s.substr(1));
+ if (std::numeric_limits<T>::is_signed) {
+ return -r;
+ } else {
+ if (r==0) return 0;
+ }
}
} catch(const boost::bad_lexical_cast&) {
}
throw InvalidConversion(QPID_MSG("Cannot convert " << s));
}
+
};
@@ -650,7 +657,7 @@ VariantImpl* VariantImpl::create(const Variant& v)
}
}
-Variant::Variant() : impl(0) {}
+Variant::Variant() : impl(new VariantImpl()) {}
Variant::Variant(bool b) : impl(new VariantImpl(b)) {}
Variant::Variant(uint8_t i) : impl(new VariantImpl(i)) {}
Variant::Variant(uint16_t i) : impl(new VariantImpl(i)) {}
@@ -893,6 +900,8 @@ bool operator==(const Variant& a, const Variant& b)
return a.isEqualTo(b);
}
+bool operator!=(const Variant& a, const Variant& b) { return !(a == b); }
+
bool Variant::isEqualTo(const Variant& other) const
{
return impl && impl->isEqualTo(*other.impl);
diff --git a/cpp/src/qpidd.cpp b/cpp/src/qpidd.cpp
index b5686c6ab8..e17dea3164 100644
--- a/cpp/src/qpidd.cpp
+++ b/cpp/src/qpidd.cpp
@@ -41,6 +41,18 @@ int run_broker(int argc, char *argv[], bool hidden)
{
BootstrapOptions bootOptions(argv[0]);
string defaultPath (bootOptions.module.loadDir);
+
+ // --version causes print and exit
+ if (bootOptions.findArg(argc, argv, "version")) {
+ cout << "qpidd (" << qpid::product << ") version "
+ << qpid::version << endl;
+ return 0;
+ }
+
+ // --help sets a flag so that its presence is known despite
+ // subsequent parse problems.
+ bool helpArgSeen = bootOptions.findArg(argc, argv, "help");
+
// Parse only the common, load, and log options to see which
// modules need to be loaded. Once the modules are loaded,
// the command line will be re-parsed with all of the
@@ -51,32 +63,42 @@ int run_broker(int argc, char *argv[], bool hidden)
bootOptions.log.sinkOptions->detached();
qpid::log::Logger::instance().configure(bootOptions.log);
} catch (const std::exception& e) {
+ if (helpArgSeen) {
+ // provide help even when parsing fails
+ bootOptions.usage();
+ }
// Couldn't configure logging so write the message direct to stderr.
- cerr << "Unexpected error: " << e.what() << endl;
+ cerr << endl << "Unexpected error: " << e.what() << endl;
return 1;
}
for (vector<string>::iterator iter = bootOptions.module.load.begin();
iter != bootOptions.module.load.end();
iter++)
- qpid::tryShlib (iter->data(), false);
+ qpid::tryShlib (*iter);
if (!bootOptions.module.noLoad) {
bool isDefault = defaultPath == bootOptions.module.loadDir;
qpid::loadModuleDir (bootOptions.module.loadDir, isDefault);
}
- // Parse options
- options.reset(new QpiddOptions(argv[0]));
- options->parse(argc, argv, options->common.config);
+ // Parse options. In the second pass, do not allow unknown options.
+ // All the modules have been added now, so any unknown options
+ // should be flagged as errors.
+ try {
+ options.reset(new QpiddOptions(argv[0]));
+ options->parse(argc, argv, options->common.config, false);
+ } catch (const std::exception& /*e*/) {
+ if (helpArgSeen) {
+ // provide help even when parsing fails
+ options->usage();
+ }
+ throw;
+ }
// Options that just print information.
- if (options->common.help || options->common.version) {
- if (options->common.version)
- cout << "qpidd (" << qpid::product << ") version "
- << qpid::version << endl;
- else if (options->common.help)
- options->usage();
+ if (helpArgSeen) {
+ options->usage();
return 0;
}
diff --git a/cpp/src/qpidd.h b/cpp/src/qpidd.h
index f7f84d11da..08356ab29e 100644
--- a/cpp/src/qpidd.h
+++ b/cpp/src/qpidd.h
@@ -37,9 +37,10 @@ namespace broker {
struct BootstrapOptions : public qpid::Options {
qpid::CommonOptions common;
qpid::ModuleOptions module;
- qpid::log::Options log;
+ qpid::log::Options log;
BootstrapOptions(const char *argv0);
+ void usage() const;
};
// Each platform derives an options struct from QpiddOptionsPrivate, adding
diff --git a/cpp/src/rdma.cmake b/cpp/src/rdma.cmake
index b0d92facab..1d355e7ae6 100644
--- a/cpp/src/rdma.cmake
+++ b/cpp/src/rdma.cmake
@@ -64,11 +64,12 @@ if (BUILD_RDMA)
add_library (rdmawrap SHARED ${rdma_SOURCES})
target_link_libraries (rdmawrap qpidcommon rdmacm ibverbs)
- set_target_properties (rdmawrap PROPERTIES VERSION ${rdmawrap_version})
+ set_target_properties (rdmawrap PROPERTIES
+ LINK_FLAGS "${CATCH_UNDEFINED}"
+ VERSION ${rdmawrap_version})
if (CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(rdmawrap PROPERTIES
- COMPILE_FLAGS -Wno-missing-field-initializers
- LINK_FLAGS ${GCC_CATCH_UNDEFINED})
+ COMPILE_FLAGS -Wno-missing-field-initializers)
endif (CMAKE_COMPILER_IS_GNUCXX)
install (TARGETS rdmawrap
@@ -78,12 +79,13 @@ if (BUILD_RDMA)
add_library (rdma MODULE qpid/sys/RdmaIOPlugin.cpp)
target_link_libraries (rdma qpidbroker rdmawrap)
set_target_properties (rdma PROPERTIES
+ COMPILE_DEFINITIONS _IN_QPID_BROKER
+ LINK_FLAGS "${CATCH_UNDEFINED}"
PREFIX "")
if (CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(rdma PROPERTIES
- COMPILE_FLAGS -Wno-missing-field-initializers
- LINK_FLAGS ${GCC_CATCH_UNDEFINED})
+ COMPILE_FLAGS -Wno-missing-field-initializers)
endif (CMAKE_COMPILER_IS_GNUCXX)
install (TARGETS rdma
@@ -93,12 +95,12 @@ if (BUILD_RDMA)
add_library (rdmaconnector MODULE qpid/client/RdmaConnector.cpp)
target_link_libraries (rdmaconnector qpidclient rdmawrap)
set_target_properties (rdmaconnector PROPERTIES
+ LINK_FLAGS "${CATCH_UNDEFINED}"
PREFIX "")
if (CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(rdmaconnector PROPERTIES
- COMPILE_FLAGS -Wno-missing-field-initializers
- LINK_FLAGS ${GCC_CATCH_UNDEFINED})
+ COMPILE_FLAGS -Wno-missing-field-initializers)
endif (CMAKE_COMPILER_IS_GNUCXX)
install (TARGETS rdmaconnector
diff --git a/cpp/src/ssl.cmake b/cpp/src/ssl.cmake
index d66f59cfff..b7ad58b9f0 100644
--- a/cpp/src/ssl.cmake
+++ b/cpp/src/ssl.cmake
@@ -69,8 +69,6 @@ if (BUILD_SSL)
qpid/sys/ssl/util.cpp
qpid/sys/ssl/SslSocket.h
qpid/sys/ssl/SslSocket.cpp
- qpid/sys/ssl/SslIo.h
- qpid/sys/ssl/SslIo.cpp
)
add_library (sslcommon SHARED ${sslcommon_SOURCES})
@@ -87,14 +85,13 @@ if (BUILD_SSL)
set (ssl_SOURCES
qpid/sys/SslPlugin.cpp
- qpid/sys/ssl/SslHandler.h
- qpid/sys/ssl/SslHandler.cpp
)
add_library (ssl MODULE ${ssl_SOURCES})
target_link_libraries (ssl qpidbroker sslcommon ${Boost_PROGRAM_OPTIONS_LIBRARY})
set_target_properties (ssl PROPERTIES
PREFIX ""
- COMPILE_FLAGS ${NSS_COMPILE_FLAGS})
+ COMPILE_FLAGS "${NSS_COMPILE_FLAGS}"
+ COMPILE_DEFINITIONS _IN_QPID_BROKER)
if (CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(ssl PROPERTIES
LINK_FLAGS "${GCC_CATCH_UNDEFINED}")
@@ -104,7 +101,7 @@ if (BUILD_SSL)
DESTINATION ${QPIDD_MODULE_DIR}
COMPONENT ${QPID_COMPONENT_BROKER})
- add_library (sslconnector MODULE qpid/client/SslConnector.cpp)
+ add_library (sslconnector MODULE qpid/client/SslConnector.cpp qpid/messaging/amqp/SslTransport.cpp)
target_link_libraries (sslconnector qpidclient sslcommon)
set_target_properties (sslconnector PROPERTIES
PREFIX ""
diff --git a/cpp/src/ssl.mk b/cpp/src/ssl.mk
index 4dba9bb61c..aaaf14ed54 100644
--- a/cpp/src/ssl.mk
+++ b/cpp/src/ssl.mk
@@ -25,9 +25,7 @@ libsslcommon_la_SOURCES = \
qpid/sys/ssl/util.h \
qpid/sys/ssl/util.cpp \
qpid/sys/ssl/SslSocket.h \
- qpid/sys/ssl/SslSocket.cpp \
- qpid/sys/ssl/SslIo.h \
- qpid/sys/ssl/SslIo.cpp
+ qpid/sys/ssl/SslSocket.cpp
SSLCOMMON_VERSION_INFO = 2:0:0
libsslcommon_la_LDFLAGS = -version-info $(SSLCOMMON_VERSION_INFO)
@@ -37,13 +35,11 @@ libsslcommon_la_CXXFLAGS=$(AM_CXXFLAGS) $(SSL_CFLAGS)
lib_LTLIBRARIES += libsslcommon.la
ssl_la_SOURCES = \
- qpid/sys/SslPlugin.cpp \
- qpid/sys/ssl/SslHandler.h \
- qpid/sys/ssl/SslHandler.cpp
+ qpid/sys/SslPlugin.cpp
ssl_la_LIBADD= libqpidbroker.la libsslcommon.la
-ssl_la_CXXFLAGS=$(AM_CXXFLAGS) $(SSL_CFLAGS)
+ssl_la_CXXFLAGS=$(AM_CXXFLAGS) $(SSL_CFLAGS) -D_IN_QPID_BROKER
ssl_la_LDFLAGS = $(PLUGINLDFLAGS)
@@ -52,6 +48,13 @@ dmoduleexec_LTLIBRARIES += ssl.la
sslconnector_la_SOURCES = \
qpid/client/SslConnector.cpp
+if HAVE_PROTON
+sslconnector_la_SOURCES += \
+ qpid/messaging/amqp/SslTransport.cpp \
+ qpid/messaging/amqp/SslTransport.h
+endif #HAVE_PROTON
+
+
sslconnector_la_LIBADD = \
libqpidclient.la \
libsslcommon.la
diff --git a/cpp/src/tests/.valgrind.supp b/cpp/src/tests/.valgrind.supp
index 2c6a1509ff..1a24a9178e 100644
--- a/cpp/src/tests/.valgrind.supp
+++ b/cpp/src/tests/.valgrind.supp
@@ -39,21 +39,6 @@
fun:_sasl_load_plugins
fun:sasl_client_init
}
-{
- Benign leak in CPG - patched version.
- Memcheck:Leak
- fun:*
- fun:openais_service_connect
- fun:cpg_initialize
-}
-
-{
- Benign error in libcpg.
- Memcheck:Param
- socketcall.sendmsg(msg.msg_iov[i])
- obj:*/libpthread-2.5.so
- obj:*/libcpg.so.2.0.0
-}
{
Uninitialised value problem in _dl_relocate (F7, F8)
@@ -161,14 +146,6 @@
}
{
- CPG error - seems benign.
- Memcheck:Param
- socketcall.sendmsg(msg.msg_iov[i])
- obj:*
- obj:*/libcpg.so.2.0.0
-}
-
-{
Known leak in boost.thread 1.33.1. Wildcards for 64/32 bit diffs.
Memcheck:Leak
fun:*
diff --git a/cpp/src/tests/BrokerMgmtAgent.cpp b/cpp/src/tests/BrokerMgmtAgent.cpp
index 02aa87f876..29c3faf809 100644
--- a/cpp/src/tests/BrokerMgmtAgent.cpp
+++ b/cpp/src/tests/BrokerMgmtAgent.cpp
@@ -22,6 +22,7 @@
#include "unit_test.h"
#include "MessagingFixture.h"
#include "qpid/management/Buffer.h"
+#include "qpid/management/ManagementAgent.h"
#include "qpid/messaging/Message.h"
#include "qpid/amqp_0_10/Codecs.h"
#include "qpid/log/Logger.h"
@@ -41,751 +42,345 @@ using namespace qpid::types;
namespace qpid {
- namespace tests {
-
- namespace _qmf = qmf::org::apache::qpid::broker::mgmt::test;
- namespace {
-
- typedef boost::shared_ptr<_qmf::TestObject> TestObjectPtr;
- typedef std::vector<TestObjectPtr> TestObjectVector;
-
- // Instantiates a broker and its internal management agent. Provides
- // factories for constructing Receivers for object indication messages.
- //
- class AgentFixture
- {
- MessagingFixture *mFix;
-
- public:
- AgentFixture( unsigned int pubInterval=10,
- bool qmfV2=false,
- qpid::broker::Broker::Options opts = qpid::broker::Broker::Options())
- {
- opts.enableMgmt=true;
- opts.qmf2Support=qmfV2;
- opts.mgmtPubInterval=pubInterval;
- mFix = new MessagingFixture(opts, true);
-
- _qmf::TestObject::registerSelf(getBrokerAgent());
- };
- ~AgentFixture()
- {
- delete mFix;
- };
- ::qpid::management::ManagementAgent *getBrokerAgent() { return mFix->broker->getManagementAgent(); }
- Receiver createV1DataIndRcvr( const std::string package, const std::string klass )
- {
- return mFix->session.createReceiver(std::string("kqueue; {create: always, delete: always, "
- "node: {type: queue, "
- "x-bindings: [{exchange: qpid.management, "
- "key: 'console.obj.1.0.")
- + package + std::string(".") + klass
- + std::string("'}]}}"));
- };
- Receiver createV2DataIndRcvr( const std::string package, const std::string klass )
- {
- std::string p(package);
- std::replace(p.begin(), p.end(), '.', '_');
- std::string k(klass);
- std::replace(k.begin(), k.end(), '.', '_');
-
- return mFix->session.createReceiver(std::string("kqueue; {create: always, delete: always, "
- "node: {type: queue, "
- "x-bindings: [{exchange: qmf.default.topic, "
- "key: 'agent.ind.data.")
- + p + std::string(".") + k
- + std::string("'}]}}"));
- };
- };
-
-
- // A "management object" that supports the TestObject
- //
- class TestManageable : public qpid::management::Manageable
- {
- management::ManagementObject* mgmtObj;
- const std::string key;
- public:
- TestManageable(management::ManagementAgent *agent, std::string _key)
- : key(_key)
- {
- _qmf::TestObject *tmp = new _qmf::TestObject(agent, this);
-
- // seed it with some default values...
- tmp->set_string1(key);
- tmp->set_bool1(true);
- qpid::types::Variant::Map vMap;
- vMap["one"] = qpid::types::Variant(1);
- vMap["two"] = qpid::types::Variant("two");
- vMap["three"] = qpid::types::Variant("whatever");
- tmp->set_map1(vMap);
-
- mgmtObj = tmp;
- };
- ~TestManageable() { mgmtObj = 0; /* deleted by agent on shutdown */ };
- management::ManagementObject* GetManagementObject() const { return mgmtObj; };
- static void validateTestObjectProperties(_qmf::TestObject& to)
- {
- // verify the default values are as expected. We don't check 'string1',
- // as it is the object key, and is unique for each object (no default value).
- BOOST_CHECK(to.get_bool1() == true);
- BOOST_CHECK(to.get_map1().size() == 3);
- qpid::types::Variant::Map mappy = to.get_map1();
- BOOST_CHECK(1 == (unsigned int)mappy["one"]);
- BOOST_CHECK(mappy["two"].asString() == std::string("two"));
- BOOST_CHECK(mappy["three"].asString() == std::string("whatever"));
- };
- };
-
-
- // decode a V1 Content Indication message
- //
- void decodeV1ObjectUpdates(const Message& inMsg, TestObjectVector& objs, const size_t objLen)
- {
- const size_t MAX_BUFFER_SIZE=65536;
- char tmp[MAX_BUFFER_SIZE];
-
- objs.clear();
-
- BOOST_CHECK(inMsg.getContent().size() <= MAX_BUFFER_SIZE);
-
- ::memcpy(tmp, inMsg.getContent().data(), inMsg.getContent().size());
- Buffer buf(tmp, inMsg.getContent().size());
-
- while (buf.available() > 8) { // 8 == qmf v1 header size
- BOOST_CHECK_EQUAL(buf.getOctet(), 'A');
- BOOST_CHECK_EQUAL(buf.getOctet(), 'M');
- BOOST_CHECK_EQUAL(buf.getOctet(), '2');
- BOOST_CHECK_EQUAL(buf.getOctet(), 'c'); // opcode == content indication
- // @@todo: kag: how do we skip 'i' entries???
- buf.getLong(); // ignore sequence
-
- std::string str1; // decode content body as string
- buf.getRawData(str1, objLen);
-
- TestObjectPtr fake(new _qmf::TestObject(0,0));
- fake->readProperties( str1 );
- objs.push_back(fake);
- }
- }
-
-
- // decode a V2 Content Indication message
- //
- void decodeV2ObjectUpdates(const qpid::messaging::Message& inMsg, TestObjectVector& objs)
- {
- objs.clear();
-
- BOOST_CHECK_EQUAL(inMsg.getContentType(), std::string("amqp/list"));
-
- const ::qpid::types::Variant::Map& m = inMsg.getProperties();
- Variant::Map::const_iterator iter = m.find(std::string("qmf.opcode"));
- BOOST_CHECK(iter != m.end());
- BOOST_CHECK_EQUAL(iter->second.asString(), std::string("_data_indication"));
-
- Variant::List vList;
- ::qpid::amqp_0_10::ListCodec::decode(inMsg.getContent(), vList);
-
- for (Variant::List::iterator lIter = vList.begin(); lIter != vList.end(); lIter++) {
- TestObjectPtr fake(new _qmf::TestObject(0,0));
- fake->readTimestamps(lIter->asMap());
- fake->mapDecodeValues((lIter->asMap())["_values"].asMap());
- objs.push_back(fake);
- }
- }
- }
-
- QPID_AUTO_TEST_SUITE(BrokerMgmtAgent)
-
- // verify that an object that is added to the broker's management database is
- // published correctly. Furthermore, verify that it is published once after
- // it has been deleted.
- //
- QPID_AUTO_TEST_CASE(v1ObjPublish)
- {
- AgentFixture* fix = new AgentFixture(3);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
-
- // create a manageable test object
- TestManageable *tm = new TestManageable(agent, std::string("obj1"));
- uint32_t objLen = tm->GetManagementObject()->writePropertiesSize();
-
- Receiver r1 = fix->createV1DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
-
- agent->addObject(tm->GetManagementObject(), 1);
-
- // wait for the object to be published
- Message m1;
- BOOST_CHECK(r1.fetch(m1, Duration::SECOND * 6));
-
- TestObjectVector objs;
- decodeV1ObjectUpdates(m1, objs, objLen);
- BOOST_CHECK(objs.size() > 0);
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
-
- TestManageable::validateTestObjectProperties(**oIter);
-
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- BOOST_CHECK(0 == mappy["_delete_ts"].asUint64()); // not deleted
- }
-
- // destroy the object
-
- tm->GetManagementObject()->resourceDestroy();
-
- // wait for the deleted object to be published
-
- bool isDeleted = false;
- while (!isDeleted && r1.fetch(m1, Duration::SECOND * 6)) {
-
- decodeV1ObjectUpdates(m1, objs, objLen);
- BOOST_CHECK(objs.size() > 0);
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
-
- TestManageable::validateTestObjectProperties(**oIter);
-
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- if (mappy["_delete_ts"].asUint64() != 0)
- isDeleted = true;
- }
- }
-
- BOOST_CHECK(isDeleted);
-
- r1.close();
- delete fix;
- delete tm;
- }
-
- // Repeat the previous test, but with V2-based object support
- //
- QPID_AUTO_TEST_CASE(v2ObjPublish)
- {
- AgentFixture* fix = new AgentFixture(3, true);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
-
- TestManageable *tm = new TestManageable(agent, std::string("obj2"));
-
- Receiver r1 = fix->createV2DataIndRcvr(tm->GetManagementObject()->getPackageName(), "#");
-
- agent->addObject(tm->GetManagementObject(), "testobj-1");
-
- // wait for the object to be published
- Message m1;
- BOOST_CHECK(r1.fetch(m1, Duration::SECOND * 6));
-
- TestObjectVector objs;
- decodeV2ObjectUpdates(m1, objs);
- BOOST_CHECK(objs.size() > 0);
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
-
- TestManageable::validateTestObjectProperties(**oIter);
-
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- BOOST_CHECK(0 == mappy["_delete_ts"].asUint64());
- }
-
- // destroy the object
-
- tm->GetManagementObject()->resourceDestroy();
-
- // wait for the deleted object to be published
-
- bool isDeleted = false;
- while (!isDeleted && r1.fetch(m1, Duration::SECOND * 6)) {
-
- decodeV2ObjectUpdates(m1, objs);
- BOOST_CHECK(objs.size() > 0);
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
-
- TestManageable::validateTestObjectProperties(**oIter);
-
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- if (mappy["_delete_ts"].asUint64() != 0)
- isDeleted = true;
- }
- }
-
- BOOST_CHECK(isDeleted);
-
- r1.close();
- delete fix;
- delete tm;
- }
-
-
- // verify that a deleted object is exported correctly using the
- // exportDeletedObjects() method. V1 testcase.
- //
- QPID_AUTO_TEST_CASE(v1ExportDelObj)
- {
- AgentFixture* fix = new AgentFixture(3);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
-
- // create a manageable test object
- TestManageable *tm = new TestManageable(agent, std::string("myObj"));
- uint32_t objLen = tm->GetManagementObject()->writePropertiesSize();
-
- Receiver r1 = fix->createV1DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
-
- agent->addObject(tm->GetManagementObject(), 1);
-
- // wait for the object to be published
- Message m1;
- BOOST_CHECK(r1.fetch(m1, Duration::SECOND * 6));
-
- TestObjectVector objs;
- decodeV1ObjectUpdates(m1, objs, objLen);
- BOOST_CHECK(objs.size() > 0);
-
- // destroy the object, then immediately export (before the next poll cycle)
-
- ::qpid::management::ManagementAgent::DeletedObjectList delObjs;
- tm->GetManagementObject()->resourceDestroy();
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK(delObjs.size() == 1);
-
- // wait for the deleted object to be published
-
- bool isDeleted = false;
- while (!isDeleted && r1.fetch(m1, Duration::SECOND * 6)) {
-
- decodeV1ObjectUpdates(m1, objs, objLen);
- BOOST_CHECK(objs.size() > 0);
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
-
- TestManageable::validateTestObjectProperties(**oIter);
-
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- if (mappy["_delete_ts"].asUint64() != 0)
- isDeleted = true;
- }
- }
-
- BOOST_CHECK(isDeleted);
-
- // verify there are no deleted objects to export now.
-
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK(delObjs.size() == 0);
-
- r1.close();
- delete fix;
- delete tm;
- }
-
-
- // verify that a deleted object is imported correctly using the
- // importDeletedObjects() method. V1 testcase.
- //
- QPID_AUTO_TEST_CASE(v1ImportDelObj)
- {
- AgentFixture* fix = new AgentFixture(3);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
-
- // create a manageable test object
- TestManageable *tm = new TestManageable(agent, std::string("anObj"));
- uint32_t objLen = tm->GetManagementObject()->writePropertiesSize();
-
- Receiver r1 = fix->createV1DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
+namespace tests {
+
+namespace _qmf = qmf::org::apache::qpid::broker::mgmt::test;
+namespace {
+
+typedef boost::shared_ptr<_qmf::TestObject> TestObjectPtr;
+typedef std::vector<TestObjectPtr> TestObjectVector;
+
+// Instantiates a broker and its internal management agent. Provides
+// factories for constructing Receivers for object indication messages.
+//
+class AgentFixture
+{
+ MessagingFixture *mFix;
+
+ public:
+ AgentFixture( unsigned int pubInterval=10,
+ bool qmfV2=false,
+ qpid::broker::Broker::Options opts = qpid::broker::Broker::Options())
+ {
+ opts.enableMgmt=true;
+ opts.qmf2Support=qmfV2;
+ opts.mgmtPubInterval=pubInterval;
+ mFix = new MessagingFixture(opts, true);
+
+ _qmf::TestObject::registerSelf(getBrokerAgent());
+ };
+ ~AgentFixture()
+ {
+ delete mFix;
+ };
+ ::qpid::management::ManagementAgent *getBrokerAgent() { return mFix->broker->getManagementAgent(); }
+ Receiver createV1DataIndRcvr( const std::string package, const std::string klass )
+ {
+ return mFix->session.createReceiver(std::string("kqueue; {create: always, delete: always, "
+ "node: {type: queue, "
+ "x-bindings: [{exchange: qpid.management, "
+ "key: 'console.obj.1.0.")
+ + package + std::string(".") + klass
+ + std::string("'}]}}"));
+ };
+ Receiver createV2DataIndRcvr( const std::string package, const std::string klass )
+ {
+ std::string p(package);
+ std::replace(p.begin(), p.end(), '.', '_');
+ std::string k(klass);
+ std::replace(k.begin(), k.end(), '.', '_');
+
+ return mFix->session.createReceiver(std::string("kqueue; {create: always, delete: always, "
+ "node: {type: queue, "
+ "x-bindings: [{exchange: qmf.default.topic, "
+ "key: 'agent.ind.data.")
+ + p + std::string(".") + k
+ + std::string("'}]}}"));
+ };
+};
+
+
+// A "management object" that supports the TestObject
+//
+class TestManageable : public qpid::management::Manageable
+{
+ management::ManagementObject::shared_ptr mgmtObj;
+ const std::string key;
+ public:
+ TestManageable(management::ManagementAgent *agent, std::string _key)
+ : key(_key)
+ {
+ _qmf::TestObject::shared_ptr tmp(new _qmf::TestObject(agent, this));
+
+ // seed it with some default values...
+ tmp->set_string1(key);
+ tmp->set_bool1(true);
+ qpid::types::Variant::Map vMap;
+ vMap["one"] = qpid::types::Variant(1);
+ vMap["two"] = qpid::types::Variant("two");
+ vMap["three"] = qpid::types::Variant("whatever");
+ tmp->set_map1(vMap);
+
+ mgmtObj = tmp;
+ };
+ ~TestManageable() { mgmtObj.reset(); }
+ management::ManagementObject::shared_ptr GetManagementObject() const { return mgmtObj; };
+ static void validateTestObjectProperties(_qmf::TestObject& to)
+ {
+ // verify the default values are as expected. We don't check 'string1',
+ // as it is the object key, and is unique for each object (no default value).
+ BOOST_CHECK(to.get_bool1() == true);
+ BOOST_CHECK(to.get_map1().size() == 3);
+ qpid::types::Variant::Map mappy = to.get_map1();
+ BOOST_CHECK(1 == (unsigned int)mappy["one"]);
+ BOOST_CHECK(mappy["two"].asString() == std::string("two"));
+ BOOST_CHECK(mappy["three"].asString() == std::string("whatever"));
+ };
+};
+
+
+// decode a V1 Content Indication message
+//
+void decodeV1ObjectUpdates(const Message& inMsg, TestObjectVector& objs, const size_t objLen)
+{
+ const size_t MAX_BUFFER_SIZE=65536;
+ char tmp[MAX_BUFFER_SIZE];
+
+ objs.clear();
+
+ BOOST_CHECK(inMsg.getContent().size() <= MAX_BUFFER_SIZE);
+
+ ::memcpy(tmp, inMsg.getContent().data(), inMsg.getContent().size());
+ Buffer buf(tmp, inMsg.getContent().size());
+
+ while (buf.available() > 8) { // 8 == qmf v1 header size
+ BOOST_CHECK_EQUAL(buf.getOctet(), 'A');
+ BOOST_CHECK_EQUAL(buf.getOctet(), 'M');
+ BOOST_CHECK_EQUAL(buf.getOctet(), '2');
+ BOOST_CHECK_EQUAL(buf.getOctet(), 'c'); // opcode == content indication
+ // @@todo: kag: how do we skip 'i' entries???
+ buf.getLong(); // ignore sequence
+
+ std::string str1; // decode content body as string
+ buf.getRawData(str1, objLen);
+
+ TestObjectPtr fake(new _qmf::TestObject(0,0));
+ fake->readProperties( str1 );
+ objs.push_back(fake);
+ }
+}
- agent->addObject(tm->GetManagementObject(), 1);
- // wait for the object to be published
- Message m1;
- BOOST_CHECK(r1.fetch(m1, Duration::SECOND * 6));
+// decode a V2 Content Indication message
+//
+void decodeV2ObjectUpdates(const qpid::messaging::Message& inMsg, TestObjectVector& objs)
+{
+ objs.clear();
- TestObjectVector objs;
- decodeV1ObjectUpdates(m1, objs, objLen);
- BOOST_CHECK(objs.size() > 0);
+ BOOST_CHECK_EQUAL(inMsg.getContentType(), std::string("amqp/list"));
- // destroy the object, then immediately export (before the next poll cycle)
+ const ::qpid::types::Variant::Map& m = inMsg.getProperties();
+ Variant::Map::const_iterator iter = m.find(std::string("qmf.opcode"));
+ BOOST_CHECK(iter != m.end());
+ BOOST_CHECK_EQUAL(iter->second.asString(), std::string("_data_indication"));
- ::qpid::management::ManagementAgent::DeletedObjectList delObjs;
- tm->GetManagementObject()->resourceDestroy();
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK(delObjs.size() == 1);
+ Variant::List vList;
+ ::qpid::amqp_0_10::ListCodec::decode(inMsg.getContent(), vList);
- // destroy the broker, and reinistantiate a new one without populating it
- // with a TestObject.
+ for (Variant::List::iterator lIter = vList.begin(); lIter != vList.end(); lIter++) {
+ TestObjectPtr fake(new _qmf::TestObject(0,0));
+ fake->readTimestamps(lIter->asMap());
+ fake->mapDecodeValues((lIter->asMap())["_values"].asMap());
+ objs.push_back(fake);
+ }
+}
+}
- r1.close();
- delete fix;
- delete tm; // should no longer be necessary
+QPID_AUTO_TEST_SUITE(BrokerMgmtAgent)
- fix = new AgentFixture(3);
- r1 = fix->createV1DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
- agent = fix->getBrokerAgent();
- agent->importDeletedObjects( delObjs );
+// verify that an object that is added to the broker's management database is
+// published correctly. Furthermore, verify that it is published once after
+// it has been deleted.
+//
+QPID_AUTO_TEST_CASE(v1ObjPublish)
+{
+ AgentFixture* fix = new AgentFixture(3);
+ management::ManagementAgent* agent;
+ agent = fix->getBrokerAgent();
- // wait for the deleted object to be published
+ // create a manageable test object
+ TestManageable *tm = new TestManageable(agent, std::string("obj1"));
+ uint32_t objLen = tm->GetManagementObject()->writePropertiesSize();
- bool isDeleted = false;
- while (!isDeleted && r1.fetch(m1, Duration::SECOND * 6)) {
+ Receiver r1 = fix->createV1DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
- decodeV1ObjectUpdates(m1, objs, objLen);
- BOOST_CHECK(objs.size() > 0);
+ agent->addObject(tm->GetManagementObject(), 1);
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
+ // wait for the object to be published
+ Message m1;
+ BOOST_CHECK(r1.fetch(m1, Duration::SECOND * 6));
- TestManageable::validateTestObjectProperties(**oIter);
+ TestObjectVector objs;
+ decodeV1ObjectUpdates(m1, objs, objLen);
+ BOOST_CHECK(objs.size() > 0);
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- if (mappy["_delete_ts"].asUint64() != 0)
- isDeleted = true;
- }
- }
+ for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
- BOOST_CHECK(isDeleted);
+ TestManageable::validateTestObjectProperties(**oIter);
- // verify there are no deleted objects to export now.
+ qpid::types::Variant::Map mappy;
+ (*oIter)->writeTimestamps(mappy);
+ BOOST_CHECK(0 == mappy["_delete_ts"].asUint64()); // not deleted
+ }
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK(delObjs.size() == 0);
+ // destroy the object
- r1.close();
- delete fix;
- }
+ tm->GetManagementObject()->resourceDestroy();
+ // wait for the deleted object to be published
- // verify that an object that is added and deleted prior to the
- // first poll cycle is accounted for by the export
- //
- QPID_AUTO_TEST_CASE(v1ExportFastDelObj)
- {
- AgentFixture* fix = new AgentFixture(3);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
+ bool isDeleted = false;
+ while (!isDeleted && r1.fetch(m1, Duration::SECOND * 6)) {
- // create a manageable test object
- TestManageable *tm = new TestManageable(agent, std::string("objectifyMe"));
+ decodeV1ObjectUpdates(m1, objs, objLen);
+ BOOST_CHECK(objs.size() > 0);
- // add, then immediately delete and export the object...
+ for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
- ::qpid::management::ManagementAgent::DeletedObjectList delObjs;
- agent->addObject(tm->GetManagementObject(), 999);
- tm->GetManagementObject()->resourceDestroy();
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK(delObjs.size() == 1);
+ TestManageable::validateTestObjectProperties(**oIter);
- delete fix;
- delete tm;
+ qpid::types::Variant::Map mappy;
+ (*oIter)->writeTimestamps(mappy);
+ if (mappy["_delete_ts"].asUint64() != 0)
+ isDeleted = true;
}
+ }
+ BOOST_CHECK(isDeleted);
- // Verify that we can export and import multiple deleted objects correctly.
- //
- QPID_AUTO_TEST_CASE(v1ImportMultiDelObj)
- {
- AgentFixture* fix = new AgentFixture(3);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
-
- Receiver r1 = fix->createV1DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
-
- // populate the agent with multiple test objects
- const size_t objCount = 50;
- std::vector<TestManageable *> tmv;
- uint32_t objLen;
-
- for (size_t i = 0; i < objCount; i++) {
- std::stringstream key;
- key << "testobj-" << std::setfill('x') << std::setw(4) << i;
- // (no, seriously, I didn't just do that.)
- // Note well: we have to keep the key string length EXACTLY THE SAME
- // FOR ALL OBJECTS, so objLen will be the same. Otherwise the
- // decodeV1ObjectUpdates() will fail (v1 lacks explict encoded length).
- TestManageable *tm = new TestManageable(agent, key.str());
- objLen = tm->GetManagementObject()->writePropertiesSize();
- agent->addObject(tm->GetManagementObject(), i + 1);
- tmv.push_back(tm);
- }
+ r1.close();
+ delete fix;
+ delete tm;
+}
- // wait for the objects to be published
- Message m1;
- uint32_t msgCount = 0;
- while(r1.fetch(m1, Duration::SECOND * 6)) {
- TestObjectVector objs;
- decodeV1ObjectUpdates(m1, objs, objLen);
- msgCount += objs.size();
- }
+// Repeat the previous test, but with V2-based object support
+//
+QPID_AUTO_TEST_CASE(v2ObjPublish)
+{
+ AgentFixture* fix = new AgentFixture(3, true);
+ management::ManagementAgent* agent;
+ agent = fix->getBrokerAgent();
- BOOST_CHECK_EQUAL(msgCount, objCount);
+ TestManageable *tm = new TestManageable(agent, std::string("obj2"));
- // destroy some of the objects, then immediately export (before the next poll cycle)
+ Receiver r1 = fix->createV2DataIndRcvr(tm->GetManagementObject()->getPackageName(), "#");
- uint32_t delCount = 0;
- for (size_t i = 0; i < objCount; i += 2) {
- tmv[i]->GetManagementObject()->resourceDestroy();
- delCount++;
- }
+ agent->addObject(tm->GetManagementObject(), "testobj-1");
- ::qpid::management::ManagementAgent::DeletedObjectList delObjs;
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK_EQUAL(delObjs.size(), delCount);
+ // wait for the object to be published
+ Message m1;
+ BOOST_CHECK(r1.fetch(m1, Duration::SECOND * 6));
- // destroy the broker, and reinistantiate a new one without populating it
- // with TestObjects.
+ TestObjectVector objs;
+ decodeV2ObjectUpdates(m1, objs);
+ BOOST_CHECK(objs.size() > 0);
- r1.close();
- delete fix;
- while (tmv.size()) {
- delete tmv.back();
- tmv.pop_back();
- }
+ for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
- fix = new AgentFixture(3);
- r1 = fix->createV1DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
- agent = fix->getBrokerAgent();
- agent->importDeletedObjects( delObjs );
+ TestManageable::validateTestObjectProperties(**oIter);
- // wait for the deleted object to be published, verify the count
+ qpid::types::Variant::Map mappy;
+ (*oIter)->writeTimestamps(mappy);
+ BOOST_CHECK(0 == mappy["_delete_ts"].asUint64());
+ }
- uint32_t countDels = 0;
- while (r1.fetch(m1, Duration::SECOND * 6)) {
- TestObjectVector objs;
- decodeV1ObjectUpdates(m1, objs, objLen);
- BOOST_CHECK(objs.size() > 0);
+ // destroy the object
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
+ tm->GetManagementObject()->resourceDestroy();
- TestManageable::validateTestObjectProperties(**oIter);
+ // wait for the deleted object to be published
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- if (mappy["_delete_ts"].asUint64() != 0)
- countDels++;
- }
- }
+ bool isDeleted = false;
+ while (!isDeleted && r1.fetch(m1, Duration::SECOND * 6)) {
- // make sure we get the correct # of deleted objects
- BOOST_CHECK_EQUAL(countDels, delCount);
+ decodeV2ObjectUpdates(m1, objs);
+ BOOST_CHECK(objs.size() > 0);
- // verify there are no deleted objects to export now.
+ for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK(delObjs.size() == 0);
+ TestManageable::validateTestObjectProperties(**oIter);
- r1.close();
- delete fix;
+ qpid::types::Variant::Map mappy;
+ (*oIter)->writeTimestamps(mappy);
+ if (mappy["_delete_ts"].asUint64() != 0)
+ isDeleted = true;
}
+ }
- // Verify that we can export and import multiple deleted objects correctly.
- // QMF V2 variant
- QPID_AUTO_TEST_CASE(v2ImportMultiDelObj)
- {
- AgentFixture* fix = new AgentFixture(3, true);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
-
- Receiver r1 = fix->createV2DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
-
- // populate the agent with multiple test objects
- const size_t objCount = 50;
- std::vector<TestManageable *> tmv;
-
- for (size_t i = 0; i < objCount; i++) {
- std::stringstream key;
- key << "testobj-" << i;
- TestManageable *tm = new TestManageable(agent, key.str());
- if (tm->GetManagementObject()->writePropertiesSize()) {}
- agent->addObject(tm->GetManagementObject(), key.str());
- tmv.push_back(tm);
- }
-
- // wait for the objects to be published
- Message m1;
- uint32_t msgCount = 0;
- while(r1.fetch(m1, Duration::SECOND * 6)) {
- TestObjectVector objs;
- decodeV2ObjectUpdates(m1, objs);
- msgCount += objs.size();
- }
-
- BOOST_CHECK_EQUAL(msgCount, objCount);
-
- // destroy some of the objects, then immediately export (before the next poll cycle)
-
- uint32_t delCount = 0;
- for (size_t i = 0; i < objCount; i += 2) {
- tmv[i]->GetManagementObject()->resourceDestroy();
- delCount++;
- }
-
- ::qpid::management::ManagementAgent::DeletedObjectList delObjs;
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK_EQUAL(delObjs.size(), delCount);
-
- // destroy the broker, and reinistantiate a new one without populating it
- // with TestObjects.
-
- r1.close();
- delete fix;
- while (tmv.size()) {
- delete tmv.back();
- tmv.pop_back();
- }
-
- fix = new AgentFixture(3, true);
- r1 = fix->createV2DataIndRcvr("org.apache.qpid.broker.mgmt.test", "#");
- agent = fix->getBrokerAgent();
- agent->importDeletedObjects( delObjs );
-
- // wait for the deleted object to be published, verify the count
-
- uint32_t countDels = 0;
- while (r1.fetch(m1, Duration::SECOND * 6)) {
- TestObjectVector objs;
- decodeV2ObjectUpdates(m1, objs);
- BOOST_CHECK(objs.size() > 0);
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
-
- TestManageable::validateTestObjectProperties(**oIter);
-
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- if (mappy["_delete_ts"].asUint64() != 0)
- countDels++;
- }
- }
-
- // make sure we get the correct # of deleted objects
- BOOST_CHECK_EQUAL(countDels, delCount);
-
- // verify there are no deleted objects to export now.
-
- agent->exportDeletedObjects( delObjs );
- BOOST_CHECK(delObjs.size() == 0);
+ BOOST_CHECK(isDeleted);
- r1.close();
- delete fix;
- }
+ r1.close();
+ delete fix;
+ delete tm;
+}
- // See QPID-2997
- QPID_AUTO_TEST_CASE(v2RapidRestoreObj)
- {
- AgentFixture* fix = new AgentFixture(3, true);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
-
- // two objects, same ObjID
- TestManageable *tm1 = new TestManageable(agent, std::string("obj2"));
- TestManageable *tm2 = new TestManageable(agent, std::string("obj2"));
-
- Receiver r1 = fix->createV2DataIndRcvr(tm1->GetManagementObject()->getPackageName(), "#");
-
- // add, then immediately delete and re-add a copy of the object
- agent->addObject(tm1->GetManagementObject(), "testobj-1");
- tm1->GetManagementObject()->resourceDestroy();
- agent->addObject(tm2->GetManagementObject(), "testobj-1");
-
- // expect: a delete notification, then an update notification
- TestObjectVector objs;
- bool isDeleted = false;
- bool isAdvertised = false;
- size_t count = 0;
- Message m1;
- while (r1.fetch(m1, Duration::SECOND * 6)) {
-
- decodeV2ObjectUpdates(m1, objs);
- BOOST_CHECK(objs.size() > 0);
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
- count++;
- TestManageable::validateTestObjectProperties(**oIter);
-
- qpid::types::Variant::Map mappy;
- (*oIter)->writeTimestamps(mappy);
- if (mappy["_delete_ts"].asUint64() != 0) {
- isDeleted = true;
- BOOST_CHECK(isAdvertised == false); // delete must be first
- } else {
- isAdvertised = true;
- BOOST_CHECK(isDeleted == true); // delete must be first
- }
- }
+// See QPID-2997
+QPID_AUTO_TEST_CASE(v2RapidRestoreObj)
+{
+ AgentFixture* fix = new AgentFixture(3, true);
+ management::ManagementAgent* agent;
+ agent = fix->getBrokerAgent();
+
+ // two objects, same ObjID
+ TestManageable *tm1 = new TestManageable(agent, std::string("obj2"));
+ TestManageable *tm2 = new TestManageable(agent, std::string("obj2"));
+
+ Receiver r1 = fix->createV2DataIndRcvr(tm1->GetManagementObject()->getPackageName(), "#");
+
+ // add, then immediately delete and re-add a copy of the object
+ agent->addObject(tm1->GetManagementObject(), "testobj-1");
+ tm1->GetManagementObject()->resourceDestroy();
+ agent->addObject(tm2->GetManagementObject(), "testobj-1");
+
+ // expect: a delete notification, then an update notification
+ TestObjectVector objs;
+ bool isDeleted = false;
+ bool isAdvertised = false;
+ size_t count = 0;
+ Message m1;
+ while (r1.fetch(m1, Duration::SECOND * 6)) {
+
+ decodeV2ObjectUpdates(m1, objs);
+ BOOST_CHECK(objs.size() > 0);
+
+ for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
+ count++;
+ TestManageable::validateTestObjectProperties(**oIter);
+
+ qpid::types::Variant::Map mappy;
+ (*oIter)->writeTimestamps(mappy);
+ if (mappy["_delete_ts"].asUint64() != 0) {
+ isDeleted = true;
+ BOOST_CHECK(isAdvertised == false); // delete must be first
+ } else {
+ isAdvertised = true;
+ BOOST_CHECK(isDeleted == true); // delete must be first
}
-
- BOOST_CHECK(isDeleted);
- BOOST_CHECK(isAdvertised);
- BOOST_CHECK(count == 2);
-
- r1.close();
- delete fix;
- delete tm1;
- delete tm2;
}
+ }
- // See QPID-2997
- QPID_AUTO_TEST_CASE(v2DuplicateErrorObj)
- {
- AgentFixture* fix = new AgentFixture(3, true);
- management::ManagementAgent* agent;
- agent = fix->getBrokerAgent();
-
- // turn off the expected error log message
- qpid::log::Options logOpts;
- logOpts.selectors.clear();
- logOpts.selectors.push_back("critical+");
- qpid::log::Logger::instance().configure(logOpts);
-
- // two objects, same ObjID
- TestManageable *tm1 = new TestManageable(agent, std::string("obj2"));
- TestManageable *tm2 = new TestManageable(agent, std::string("obj2"));
- // Keep a pointer to the ManagementObject. This test simulates a user-caused error
- // case (duplicate objects) where the broker has no choice but to leak a management
- // object (safest assumption). To prevent valgrind from flagging this leak, we
- // manually clean up the object at the end of the test.
- management::ManagementObject *save = tm2->GetManagementObject();
-
- Receiver r1 = fix->createV2DataIndRcvr(tm1->GetManagementObject()->getPackageName(), "#");
-
- // add, then immediately delete and re-add a copy of the object
- agent->addObject(tm1->GetManagementObject(), "testobj-1");
- agent->addObject(tm2->GetManagementObject(), "testobj-1");
-
- TestObjectVector objs;
- size_t count = 0;
- Message m1;
- while (r1.fetch(m1, Duration::SECOND * 6)) {
-
- decodeV2ObjectUpdates(m1, objs);
- BOOST_CHECK(objs.size() > 0);
-
- for (TestObjectVector::iterator oIter = objs.begin(); oIter != objs.end(); oIter++) {
- count++;
- TestManageable::validateTestObjectProperties(**oIter);
- }
- }
-
- BOOST_CHECK(count == 1); // only one should be accepted.
+ BOOST_CHECK(isDeleted);
+ BOOST_CHECK(isAdvertised);
+ BOOST_CHECK(count == 2);
- r1.close();
- delete fix;
- delete tm1;
- delete tm2;
- delete save;
- }
+ r1.close();
+ delete fix;
+ delete tm1;
+ delete tm2;
+}
- QPID_AUTO_TEST_SUITE_END()
- }
+QPID_AUTO_TEST_SUITE_END()
+}
}
diff --git a/cpp/src/tests/CMakeLists.txt b/cpp/src/tests/CMakeLists.txt
index be7864fcb4..12e9cbed95 100644
--- a/cpp/src/tests/CMakeLists.txt
+++ b/cpp/src/tests/CMakeLists.txt
@@ -98,66 +98,78 @@ endif (CMAKE_SYSTEM_NAME STREQUAL Windows)
# when running the tests. If you want to build a subset of the tests run
# ccmake and set unit_tests_to_build to the set you want to build.
-set(unit_tests_to_build
- exception_test
- RefCounted
- SessionState
- logging
- AsyncCompletion
- Url
- Uuid
- Shlib
- FieldValue
- FieldTable
+set(all_unit_tests
+ AccumulatedAckTest
Array
- QueueOptionsTest
- InlineAllocator
- InlineVector
- ClientSessionTest
- MessagingSessionTests
- SequenceSet
- StringUtils
- RangeSet
+ AsyncCompletion
AtomicValue
- QueueTest
- AccumulatedAckTest
- DtxWorkRecordTest
+ ClientMessage
+ ClientMessageTest
+ ClientSessionTest
+ ConsoleTest
DeliveryRecordTest
+ DtxWorkRecordTest
+ exception_test
ExchangeTest
+ FieldTable
+ FieldValue
+ FrameDecoder
+ FramingTest
HeadersExchangeTest
+ HeaderTest
+ InlineAllocator
+ InlineVector
+ logging
+ ManagementTest
+ MessageReplayTracker
MessageTest
+ MessagingSessionTests
+ PollableCondition
+ ProxyTest
QueueDepth
- QueueRegistryTest
- QueuePolicyTest
QueueFlowLimitTest
- FramingTest
- HeaderTest
+ QueueOptionsTest
+ QueuePolicyTest
+ QueueRegistryTest
+ QueueTest
+ RangeSet
+ RefCounted
+ RetryList
SequenceNumberTest
+ SequenceSet
+ SessionState
+ Shlib
+ StringUtils
+ SystemInfo
TimerTest
TopicExchangeTest
TxBufferTest
- ManagementTest
- MessageReplayTracker
- ConsoleTest
- ProxyTest
- RetryList
- FrameDecoder
- ClientMessageTest
- PollableCondition
+ Url
+ Uuid
Variant
- ClientMessage
- SystemInfo
${xml_tests}
+ )
+
+set(unit_tests_to_build
+ ""
CACHE STRING "Which unit tests to build"
)
mark_as_advanced(unit_tests_to_build)
+# If no unit_test specifically set then use all unit tests
+if (unit_tests_to_build)
+set(actual_unit_tests ${unit_tests_to_build})
+else()
+set(actual_unit_tests ${all_unit_tests})
+endif()
+
add_executable (unit_test unit_test
- ${unit_tests_to_build} ${platform_test_additions})
+ ${actual_unit_tests} ${platform_test_additions})
target_link_libraries (unit_test
${qpid_test_boost_libs}
qpidmessaging qpidbroker qmfconsole)
+set_target_properties (unit_test PROPERTIES COMPILE_DEFINITIONS _IN_QPID_BROKER)
remember_location(unit_test)
add_library (shlibtest MODULE shlibtest.cpp)
@@ -274,8 +286,12 @@ remember_location(msg_group_test)
# qpid-perftest and qpid-latency-test are generally useful so install them
-install (TARGETS qpid-perftest qpid-latency-test RUNTIME
- DESTINATION ${QPID_INSTALL_BINDIR})
+install (TARGETS
+ qpid-perftest qpid-latency-test qpid-client-test
+ qpid-ping
+ qpid-receive qpid-send qpid-topic-listener qpid-topic-publisher receiver sender
+ qpid-txtest
+ RUNTIME DESTINATION ${QPID_INSTALL_TESTDIR})
# This should ideally be done as part of the test run, but I don't know a way
# to get these arguments and the working directory set like Makefile.am does,
@@ -309,10 +325,12 @@ if (PYTHON_EXECUTABLE)
add_test (ha_tests ${test_wrap} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/ha_tests.py)
add_test (ipv6_test ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/ipv6_test${test_script_suffix})
add_test (federation_tests ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/run_federation_tests${test_script_suffix})
+ add_test (federation_sys_tests ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/run_federation_sys_tests${test_script_suffix})
if (BUILD_ACL)
add_test (acl_tests ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/run_acl_tests${test_script_suffix})
endif (BUILD_ACL)
add_test (dynamic_log_level_test ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_log_level_test${test_script_suffix})
+add_test (dynamic_log_hires_timestamp ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/dynamic_log_hires_timestamp${test_script_suffix})
if (BUILD_MSSQL)
add_test (store_tests ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/run_store_tests${test_script_suffix} MSSQL)
endif (BUILD_MSSQL)
@@ -323,7 +341,9 @@ endif (PYTHON_EXECUTABLE)
add_library(test_store MODULE test_store.cpp)
target_link_libraries (test_store qpidbroker qpidcommon)
-set_target_properties (test_store PROPERTIES PREFIX "")
+set_target_properties (test_store PROPERTIES
+ COMPILE_DEFINITIONS _IN_QPID_BROKER
+ PREFIX "")
add_library (dlclose_noop MODULE dlclose_noop.c)
@@ -333,10 +353,16 @@ add_library (dlclose_noop MODULE dlclose_noop.c)
#
## Longer running stability tests, not run by default check: target.
## Not run under valgrind, too slow
-#LONG_TESTS=fanout_perftest shared_perftest multiq_perftest topic_perftest run_failover_soak
+#LONG_TESTS=fanout_perftest shared_perftest multiq_perftest topic_perftest
#EXTRA_DIST+=$(LONG_TESTS) run_perftest
#check-long:
# $(MAKE) check TESTS="start_broker $(LONG_TESTS) stop_broker" VALGRIND=
# Include async store tests
include(asyncstore.cmake)
+
+#
+# legacystore
+#
+#add_subdirectory(legacystore)
+
diff --git a/cpp/src/tests/ClusterFailover.cpp b/cpp/src/tests/ClusterFailover.cpp
deleted file mode 100644
index bf5c147f19..0000000000
--- a/cpp/src/tests/ClusterFailover.cpp
+++ /dev/null
@@ -1,115 +0,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.
- *
- */
-
-/**@file Tests for partial failure in a cluster.
- * Partial failure means some nodes experience a failure while others do not.
- * In this case the failed nodes must shut down.
- */
-
-#include "test_tools.h"
-#include "unit_test.h"
-#include "ClusterFixture.h"
-#include "qpid/client/FailoverManager.h"
-#include <boost/assign.hpp>
-#include <boost/algorithm/string.hpp>
-#include <boost/bind.hpp>
-
-namespace qpid {
-namespace tests {
-
-QPID_AUTO_TEST_SUITE(ClusterFailoverTestSuite)
-
-using namespace std;
-using namespace qpid;
-using namespace qpid::cluster;
-using namespace qpid::framing;
-using namespace qpid::client;
-using namespace qpid::client::arg;
-using namespace boost::assign;
-using broker::Broker;
-using boost::shared_ptr;
-
-// Timeout for tests that wait for messages
-const sys::Duration TIMEOUT=sys::TIME_SEC/4;
-
-ClusterFixture::Args getArgs(bool durable=std::getenv("STORE_LIB"))
-{
- ClusterFixture::Args args;
- args += "--auth", "no", "--no-module-dir",
- "--load-module", getLibPath("CLUSTER_LIB");
- if (durable)
- args += "--load-module", getLibPath("STORE_LIB"), "TMP_DATA_DIR";
- else
- args += "--no-data-dir";
- return args;
-}
-
-// Test re-connecting with same session name after a failure.
-QPID_AUTO_TEST_CASE(testReconnectSameSessionName) {
- ClusterFixture cluster(2, getArgs(), -1);
- // Specify a timeout to make sure it is ignored, session resume is
- // not implemented so sessions belonging to dead brokers should
- // not be kept.
- Client c0(cluster[0], "foo", 5);
- BOOST_CHECK_EQUAL(2u, knownBrokerPorts(c0.connection, 2).size()); // wait for both.
- c0.session.queueDeclare("q");
- c0.session.messageTransfer(arg::content=Message("sendme", "q"));
- BOOST_CHECK_EQUAL(c0.subs.get("q").getData(), "sendme");
- cluster.killWithSilencer(0, c0.connection, 9);
- Client c1(cluster[1], "foo", 5);
- c1.session.queueQuery(); // Try to use the session.
-}
-
-QPID_AUTO_TEST_CASE(testReconnectExclusiveQueue) {
- // Regresion test. Session timeouts should be ignored
- // by the broker as session resume is not implemented.
- ClusterFixture cluster(2, getArgs(), -1);
- Client c0(cluster[0], "foo", 5);
- c0.session.queueDeclare("exq", arg::exclusive=true);
- SubscriptionSettings settings;
- settings.exclusive = true;
- settings.autoAck = 0;
- Subscription s0 = c0.subs.subscribe(c0.lq, "exq", settings, "exsub");
- c0.session.messageTransfer(arg::content=Message("sendme", "exq"));
- BOOST_CHECK_EQUAL(c0.lq.get().getData(), "sendme");
-
- // Regression: core dump on exit if unacked messages were left in
- // a session with a timeout.
- cluster.killWithSilencer(0, c0.connection);
-
- // Regression: session timeouts prevented re-connecting to
- // exclusive queue.
- Client c1(cluster[1]);
- c1.session.queueDeclare("exq", arg::exclusive=true);
- Subscription s1 = c1.subs.subscribe(c1.lq, "exq", settings, "exsub");
- s1.cancel();
-
- // Regression: session timeouts prevented new member joining
- // cluster with exclusive queues.
- cluster.add();
- Client c2(cluster[2]);
- c2.session.queueQuery();
-}
-
-
-QPID_AUTO_TEST_SUITE_END()
-
-}} // namespace qpid::tests
diff --git a/cpp/src/tests/ClusterFixture.cpp b/cpp/src/tests/ClusterFixture.cpp
deleted file mode 100644
index 6b62cb6fc7..0000000000
--- a/cpp/src/tests/ClusterFixture.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * 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.
- *
- */
-
-#include "test_tools.h"
-#include "unit_test.h"
-#include "ForkedBroker.h"
-#include "BrokerFixture.h"
-
-#include "qpid/client/Connection.h"
-#include "qpid/client/ConnectionAccess.h"
-#include "qpid/client/Session.h"
-#include "qpid/client/FailoverListener.h"
-#include "qpid/cluster/Cluster.h"
-#include "qpid/cluster/Cpg.h"
-#include "qpid/cluster/UpdateClient.h"
-#include "qpid/framing/AMQBody.h"
-#include "qpid/framing/Uuid.h"
-#include "qpid/framing/reply_exceptions.h"
-#include "qpid/framing/enum.h"
-#include "qpid/log/Logger.h"
-
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/assign.hpp>
-
-#include <string>
-#include <iostream>
-#include <iterator>
-#include <vector>
-#include <set>
-#include <algorithm>
-#include <iterator>
-
-
-using namespace std;
-using namespace qpid;
-using namespace qpid::cluster;
-using namespace qpid::framing;
-using namespace qpid::client;
-using qpid::sys::TIME_SEC;
-using qpid::broker::Broker;
-using boost::shared_ptr;
-using qpid::cluster::Cluster;
-using boost::assign::list_of;
-
-
-#include "ClusterFixture.h"
-
-namespace qpid {
-namespace tests {
-
-ClusterFixture::ClusterFixture(size_t n, const Args& args_, int localIndex_)
- : name(Uuid(true).str()), localIndex(localIndex_), userArgs(args_)
-{
- add(n);
-}
-
-ClusterFixture::ClusterFixture(size_t n, boost::function<void (Args&, size_t)> updateArgs_, int localIndex_)
- : name(Uuid(true).str()), localIndex(localIndex_), updateArgs(updateArgs_)
-{
- add(n);
-}
-
-ClusterFixture::Args ClusterFixture::makeArgs(const std::string& prefix, size_t index) {
- Args args = list_of<string>("qpidd ")
- ("--cluster-name")(name)
- ("--log-prefix")(prefix);
- args.insert(args.end(), userArgs.begin(), userArgs.end());
- if (updateArgs) updateArgs(args, index);
- return args;
-}
-
-void ClusterFixture::add() {
- if (size() != size_t(localIndex)) { // fork a broker process.
- std::ostringstream os; os << "fork" << size();
- std::string prefix = os.str();
- forkedBrokers.push_back(shared_ptr<ForkedBroker>(new ForkedBroker(makeArgs(prefix, size()))));
- push_back(forkedBrokers.back()->getPort());
- }
- else { // Run in this process
- addLocal();
- }
-}
-
-namespace {
-/** Parse broker & cluster options */
-Broker::Options parseOpts(size_t argc, const char* argv[]) {
- Broker::Options opts;
- Plugin::addOptions(opts); // Pick up cluster options.
- opts.parse(argc, argv, "", true); // Allow-unknown for --load-module
- return opts;
-}
-}
-
-void ClusterFixture::addLocal() {
- assert(int(size()) == localIndex);
- ostringstream os; os << "local" << localIndex;
- string prefix = os.str();
- Args args(makeArgs(prefix, localIndex));
- vector<const char*> argv(args.size());
- transform(args.begin(), args.end(), argv.begin(), boost::bind(&string::c_str, _1));
- qpid::log::Logger::instance().setPrefix(prefix);
- localBroker.reset(new BrokerFixture(parseOpts(argv.size(), &argv[0])));
- push_back(localBroker->getPort());
- forkedBrokers.push_back(shared_ptr<ForkedBroker>());
-}
-
-bool ClusterFixture::hasLocal() const { return localIndex >= 0 && size_t(localIndex) < size(); }
-
-/** Kill a forked broker with sig, or shutdown localBroker if n==0. */
-void ClusterFixture::kill(size_t n, int sig) {
- if (n == size_t(localIndex))
- localBroker->broker->shutdown();
- else
- forkedBrokers[n]->kill(sig);
-}
-
-/** Kill a broker and suppress errors from closing connection c. */
-void ClusterFixture::killWithSilencer(size_t n, client::Connection& c, int sig) {
- ScopedSuppressLogging sl;
- try { c.close(); } catch(...) {}
- kill(n,sig);
-}
-
-/**
- * Get the known broker ports from a Connection.
- *@param n if specified wait for the cluster size to be n, up to a timeout.
- */
-std::set<int> knownBrokerPorts(qpid::client::Connection& c, int n) {
- FailoverListener fl(c, false);
- std::vector<qpid::Url> urls = fl.getKnownBrokers();
- if (n >= 0 && unsigned(n) != urls.size()) {
- // Retry up to 10 secs in .1 second intervals.
- for (size_t retry=100; urls.size() != unsigned(n) && retry != 0; --retry) {
- qpid::sys::usleep(1000*100); // 0.1 secs
- urls = fl.getKnownBrokers();
- }
- }
- std::set<int> s;
- for (std::vector<qpid::Url>::const_iterator i = urls.begin(); i != urls.end(); ++i)
- s.insert((*i)[0].port);
- return s;
-}
-
-}} // namespace qpid::tests
diff --git a/cpp/src/tests/ClusterFixture.h b/cpp/src/tests/ClusterFixture.h
deleted file mode 100644
index f548ff9376..0000000000
--- a/cpp/src/tests/ClusterFixture.h
+++ /dev/null
@@ -1,115 +0,0 @@
-#ifndef CLUSTER_FIXTURE_H
-#define CLUSTER_FIXTURE_H
-
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * 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.
- *
- */
-
-#include "test_tools.h"
-#include "unit_test.h"
-#include "ForkedBroker.h"
-#include "BrokerFixture.h"
-
-#include "qpid/client/Connection.h"
-#include "qpid/client/ConnectionAccess.h"
-#include "qpid/client/Session.h"
-#include "qpid/client/FailoverListener.h"
-#include "qpid/cluster/Cluster.h"
-#include "qpid/cluster/Cpg.h"
-#include "qpid/cluster/UpdateClient.h"
-#include "qpid/framing/AMQBody.h"
-#include "qpid/framing/Uuid.h"
-#include "qpid/framing/reply_exceptions.h"
-#include "qpid/framing/enum.h"
-#include "qpid/log/Logger.h"
-
-#include <boost/bind.hpp>
-#include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <string>
-#include <iostream>
-#include <iterator>
-#include <vector>
-#include <set>
-#include <algorithm>
-#include <iterator>
-
-
-using namespace std;
-using namespace qpid;
-using namespace qpid::cluster;
-using namespace qpid::framing;
-using namespace qpid::client;
-using qpid::sys::TIME_SEC;
-using qpid::broker::Broker;
-using boost::shared_ptr;
-using qpid::cluster::Cluster;
-
-namespace qpid {
-namespace tests {
-
-/** Cluster fixture is a vector of ports for the replicas.
- *
- * At most one replica (by default replica 0) is in the current
- * process, all others are forked as children.
- */
-class ClusterFixture : public vector<uint16_t> {
- public:
- typedef std::vector<std::string> Args;
-
- /** @param localIndex can be -1 meaning don't automatically start a local broker.
- * A local broker can be started with addLocal().
- */
- ClusterFixture(size_t n, const Args& args, int localIndex=-1);
-
- /**@param updateArgs function is passed the index of the cluster member and can update the arguments. */
- ClusterFixture(size_t n, boost::function<void (Args&, size_t)> updateArgs, int localIndex=-1);
-
- void add(size_t n) { for (size_t i=0; i < n; ++i) add(); }
- void add(); // Add a broker.
- void setup();
-
- bool hasLocal() const;
-
- /** Kill a forked broker with sig, or shutdown localBroker. */
- void kill(size_t n, int sig=SIGINT);
-
- /** Kill a broker and suppress errors from closing connection c. */
- void killWithSilencer(size_t n, client::Connection& c, int sig=SIGINT);
-
- private:
-
- void addLocal(); // Add a local broker.
- Args makeArgs(const std::string& prefix, size_t index);
- string name;
- std::auto_ptr<BrokerFixture> localBroker;
- int localIndex;
- std::vector<shared_ptr<ForkedBroker> > forkedBrokers;
- Args userArgs;
- boost::function<void (Args&, size_t)> updateArgs;
-};
-
-/**
- * Get the known broker ports from a Connection.
- *@param n if specified wait for the cluster size to be n, up to a timeout.
- */
-std::set<int> knownBrokerPorts(qpid::client::Connection& source, int n=-1);
-
-}} // namespace qpid::tests
-
-#endif /*!CLUSTER_FIXTURE_H*/
diff --git a/cpp/src/tests/DispatcherTest.cpp b/cpp/src/tests/DispatcherTest.cpp
index e1691db584..7312fe8d2e 100644
--- a/cpp/src/tests/DispatcherTest.cpp
+++ b/cpp/src/tests/DispatcherTest.cpp
@@ -20,7 +20,6 @@
*/
#include "qpid/sys/Poller.h"
-#include "qpid/sys/IOHandle.h"
#include "qpid/sys/Dispatcher.h"
#include "qpid/sys/DispatchHandle.h"
#include "qpid/sys/posix/PrivatePosix.h"
@@ -147,8 +146,8 @@ int main(int /*argc*/, char** /*argv*/)
for (int i = 0; i < 8; i++)
testString += testString;
- PosixIOHandle f0(sv[0]);
- PosixIOHandle f1(sv[1]);
+ IOHandle f0(sv[0]);
+ IOHandle f1(sv[1]);
rh = new DispatchHandleRef(f0, boost::bind(reader, _1, sv[0]), 0, 0);
wh = new DispatchHandleRef(f1, 0, boost::bind(writer, _1, sv[1], testString), 0);
diff --git a/cpp/src/tests/FieldTable.cpp b/cpp/src/tests/FieldTable.cpp
index 8aeeb031b3..81372d87c5 100644
--- a/cpp/src/tests/FieldTable.cpp
+++ b/cpp/src/tests/FieldTable.cpp
@@ -20,7 +20,6 @@
*/
#include <iostream>
#include <algorithm>
-#include "qpid/sys/alloca.h"
#include "qpid/framing/Array.h"
#include "qpid/framing/FieldTable.h"
#include "qpid/framing/FieldValue.h"
diff --git a/cpp/src/tests/ForkedBroker.cpp b/cpp/src/tests/ForkedBroker.cpp
deleted file mode 100644
index de1b42d40f..0000000000
--- a/cpp/src/tests/ForkedBroker.cpp
+++ /dev/null
@@ -1,157 +0,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.
- *
- */
-
-#include "ForkedBroker.h"
-#include "qpid/log/Statement.h"
-#include <boost/bind.hpp>
-#include <algorithm>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <signal.h>
-
-using namespace std;
-using qpid::ErrnoException;
-
-namespace std {
-static ostream& operator<<(ostream& o, const qpid::tests::ForkedBroker::Args& a) {
-copy(a.begin(), a.end(), ostream_iterator<string>(o, " "));
-return o;
-}
-}
-
-namespace qpid {
-namespace tests {
-
-ForkedBroker::ForkedBroker(const Args& constArgs) : running(false), exitStatus(0) {
- Args args(constArgs);
- // Substitute the special value "TMP_DATA_DIR" with a temporary data dir.
- Args::iterator i = find(args.begin(), args.end(), string("TMP_DATA_DIR"));
- if (i != args.end()) {
- args.erase(i);
- char dd[] = "/tmp/ForkedBroker.XXXXXX";
- if (!mkdtemp(dd))
- throw qpid::ErrnoException("Can't create data dir");
- dataDir = dd;
- args.push_back("--data-dir");
- args.push_back(dataDir);
- }
- // Never use the default data directory, set --no-data-dir if no other data-dir arg.
- Args::iterator j = find(args.begin(), args.end(), string("--data-dir"));
- Args::iterator k = find(args.begin(), args.end(), string("--no-data-dir"));
- if (j == args.end() && k == args.end())
- args.push_back("--no-data-dir");
- init(args);
-}
-
-ForkedBroker::~ForkedBroker() {
- try { kill(); }
- catch (const std::exception& e) {
- QPID_LOG(error, QPID_MSG("Killing forked broker: " << e.what()));
- }
- if (!dataDir.empty())
- {
- if(::system(("rm -rf "+dataDir).c_str())) {}
- }
-}
-
-void ForkedBroker::kill(int sig) {
- if (pid == 0) return;
- int savePid = pid;
- pid = 0; // Reset pid here in case of an exception.
- using qpid::ErrnoException;
- if (::kill(savePid, sig) < 0)
- throw ErrnoException("kill failed");
- int status;
- if (::waitpid(savePid, &status, 0) < 0 && sig != 9)
- throw ErrnoException("wait for forked process failed");
- if (WEXITSTATUS(status) != 0 && sig != 9)
- throw qpid::Exception(QPID_MSG("Forked broker exited with: " << WEXITSTATUS(status)));
- running = false;
- exitStatus = status;
-}
-
-bool isLogOption(const std::string& s) {
- const char * log_enable = "--log-enable",
- * trace = "--trace";
- return( (! strncmp(s.c_str(), log_enable, strlen(log_enable))) ||
- (! strncmp(s.c_str(), trace, strlen(trace)))
- );
-}
-
-namespace {
- void ignore_signal(int)
- {
- }
-}
-
-void ForkedBroker::init(const Args& userArgs) {
- using qpid::ErrnoException;
- port = 0;
- int pipeFds[2];
- if(::pipe(pipeFds) < 0) throw ErrnoException("Can't create pipe");
-
- // Ignore the SIGCHLD signal generated by an exitting child
- // We will clean up any exitting children in the waitpid above
- // This should really be neater (like only once not per fork)
- struct ::sigaction sa;
- sa.sa_handler = ignore_signal;
- ::sigemptyset(&sa.sa_mask);
- ::sigaddset(&sa.sa_mask, SIGCHLD);
- sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
- ::sigaction(SIGCHLD, &sa, 0);
-
- pid = ::fork();
- if (pid < 0) throw ErrnoException("Fork failed");
- if (pid) { // parent
- ::close(pipeFds[1]);
- FILE* f = ::fdopen(pipeFds[0], "r");
- if (!f) throw ErrnoException("fopen failed");
- if (::fscanf(f, "%d", &port) != 1) {
- if (ferror(f)) throw ErrnoException("Error reading port number from child.");
- else throw qpid::Exception("EOF reading port number from child.");
- }
- ::fclose(f);
- running = true;
- }
- else { // child
- ::close(pipeFds[0]);
- int fd = ::dup2(pipeFds[1], 1); // pipe stdout to the parent.
- if (fd < 0) throw ErrnoException("dup2 failed");
- const char* prog = ::getenv("QPIDD_EXEC");
- if (!prog) prog = "../qpidd"; // This only works from within svn checkout
- Args args(userArgs);
- args.push_back("--port=0");
- // Keep quiet except for errors.
- if (!::getenv("QPID_TRACE") && !::getenv("QPID_LOG_ENABLE")
- && find_if(userArgs.begin(), userArgs.end(), isLogOption) == userArgs.end())
- args.push_back("--log-enable=error+");
- std::vector<const char*> argv(args.size());
- std::transform(args.begin(), args.end(), argv.begin(), boost::bind(&std::string::c_str, _1));
- argv.push_back(0);
- QPID_LOG(debug, "ForkedBroker exec " << prog << ": " << args);
-
- execv(prog, const_cast<char* const*>(&argv[0]));
- QPID_LOG(critical, "execv failed to start broker: prog=\"" << prog << "\"; args=\"" << args << "\"; errno=" << errno << " (" << std::strerror(errno) << ")");
- ::exit(1);
- }
-}
-
-}} // namespace qpid::tests
diff --git a/cpp/src/tests/ForkedBroker.h b/cpp/src/tests/ForkedBroker.h
deleted file mode 100644
index 87e141a425..0000000000
--- a/cpp/src/tests/ForkedBroker.h
+++ /dev/null
@@ -1,82 +0,0 @@
-#ifndef TESTS_FORKEDBROKER_H
-#define TESTS_FORKEDBROKER_H
-
-
-/*
- *
- * 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.
- *
- */
-
-#include "qpid/Exception.h"
-#include "qpid/log/Statement.h"
-#include "qpid/broker/Broker.h"
-#include <boost/lexical_cast.hpp>
-#include <string>
-#include <stdio.h>
-#include <sys/wait.h>
-
-namespace qpid {
-namespace tests {
-
-/**
- * Class to fork a broker child process.
- *
- * For most tests a BrokerFixture may be more convenient as it starts
- * a broker in the same process which allows you to easily debug into
- * the broker.
- *
- * This useful for tests that need to start multiple brokers where
- * those brokers can't coexist in the same process (e.g. for cluster
- * tests where CPG doesn't allow multiple group members in a single
- * process.)
- *
- */
-class ForkedBroker {
- public:
- typedef std::vector<std::string> Args;
-
- // argv args are passed to broker.
- //
- // Special value "TMP_DATA_DIR" is substituted with a temporary
- // data directory for the broker.
- //
- ForkedBroker(const Args& argv);
- ~ForkedBroker();
-
- void kill(int sig=SIGINT);
- int wait(); // Wait for exit, return exit status.
- uint16_t getPort() { return port; }
- pid_t getPID() { return pid; }
- bool isRunning() { return running; }
-
- private:
-
- void init(const Args& args);
-
- bool running;
- int exitStatus;
-
- pid_t pid;
- int port;
- std::string dataDir;
-};
-
-}} // namespace qpid::tests
-
-#endif /*!TESTS_FORKEDBROKER_H*/
diff --git a/cpp/src/tests/InitialStatusMap.cpp b/cpp/src/tests/InitialStatusMap.cpp
deleted file mode 100644
index 95806737e3..0000000000
--- a/cpp/src/tests/InitialStatusMap.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * 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.
- *
- */
-
-
-#include "unit_test.h"
-#include "test_tools.h"
-#include "qpid/cluster/InitialStatusMap.h"
-#include "qpid/framing/Uuid.h"
-#include <boost/assign.hpp>
-
-using namespace std;
-using namespace qpid::cluster;
-using namespace qpid::framing;
-using namespace qpid::framing::cluster;
-using namespace boost::assign;
-
-namespace qpid {
-namespace tests {
-
-QPID_AUTO_TEST_SUITE(InitialStatusMapTestSuite)
-
-typedef InitialStatusMap::Status Status;
-
-Status activeStatus(const Uuid& id=Uuid(), const MemberSet& ms=MemberSet(),
- const framing::Array& urls=framing::Array())
-{
- return Status(ProtocolVersion(), 0, true, id, STORE_STATE_NO_STORE, Uuid(),
- encodeMemberSet(ms), urls);
-}
-
-Status newcomerStatus(const Uuid& id=Uuid(), const MemberSet& ms=MemberSet(),
- const framing::Array& urls=framing::Array())
-{
- return Status(ProtocolVersion(), 0, false, id, STORE_STATE_NO_STORE, Uuid(),
- encodeMemberSet(ms), urls);
-}
-
-Status storeStatus(bool active, StoreState state, Uuid start=Uuid(), Uuid stop=Uuid(),
- const MemberSet& ms=MemberSet(), const framing::Array& urls=framing::Array())
-{
- return Status(ProtocolVersion(), 0, active, start, state, stop,
- encodeMemberSet(ms), urls);
-}
-
-QPID_AUTO_TEST_CASE(testFirstInCluster) {
- // Single member is first in cluster.
- InitialStatusMap map(MemberId(0), 1);
- Uuid id(true);
- BOOST_CHECK(!map.isComplete());
- MemberSet members = list_of(MemberId(0));
- map.configChange(members);
- BOOST_CHECK(!map.isComplete());
- map.received(MemberId(0), newcomerStatus(id, list_of<MemberId>(0)));
- BOOST_CHECK(map.isComplete());
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK(map.getElders().empty());
- BOOST_CHECK(!map.isUpdateNeeded());
- BOOST_CHECK_EQUAL(id, map.getClusterId());
-}
-
-QPID_AUTO_TEST_CASE(testJoinExistingCluster) {
- // Single member 0 joins existing cluster 1,2
- InitialStatusMap map(MemberId(0), 1);
- Uuid id(true);
- MemberSet members = list_of(MemberId(0))(MemberId(1))(MemberId(2));
- map.configChange(members);
- BOOST_CHECK(map.isResendNeeded());
- BOOST_CHECK(!map.isComplete());
- map.received(MemberId(0), newcomerStatus());
- map.received(MemberId(1), activeStatus(id));
- BOOST_CHECK(!map.isComplete());
- map.received(MemberId(2), activeStatus(id));
- BOOST_CHECK(map.isComplete());
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK_EQUAL(map.getElders(), list_of<MemberId>(1)(2));
- BOOST_CHECK(map.isUpdateNeeded());
- BOOST_CHECK_EQUAL(map.getClusterId(), id);
-
- // Check that transitionToComplete is reset.
- map.configChange(list_of<MemberId>(0)(1));
- BOOST_CHECK(!map.transitionToComplete());
-}
-
-QPID_AUTO_TEST_CASE(testMultipleFirstInCluster) {
- // Multiple members 0,1,2 join at same time.
- InitialStatusMap map(MemberId(1), 1); // self is 1
- Uuid id(true);
- MemberSet members = list_of(MemberId(0))(MemberId(1))(MemberId(2));
- map.configChange(members);
- BOOST_CHECK(map.isResendNeeded());
-
- // All new members
- map.received(MemberId(0), newcomerStatus(id, list_of<MemberId>(0)(1)(2)));
- map.received(MemberId(1), newcomerStatus(id, list_of<MemberId>(0)(1)(2)));
- map.received(MemberId(2), newcomerStatus(id, list_of<MemberId>(0)(1)(2)));
- BOOST_CHECK(!map.isResendNeeded());
- BOOST_CHECK(map.isComplete());
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK_EQUAL(map.getElders(), list_of(MemberId(2)));
- BOOST_CHECK(!map.isUpdateNeeded());
- BOOST_CHECK_EQUAL(map.getClusterId(), id);
-}
-
-QPID_AUTO_TEST_CASE(testMultipleJoinExisting) {
- // Multiple members 2,3 join simultaneously a cluster containing 0,1.
- InitialStatusMap map(MemberId(2), 1); // self is 2
- Uuid id(true);
- MemberSet members = list_of(MemberId(0))(MemberId(1))(MemberId(2))(MemberId(3));
- map.configChange(members);
- BOOST_CHECK(map.isResendNeeded());
- map.received(MemberId(0), activeStatus(id, list_of<MemberId>(0)));
- map.received(MemberId(1), newcomerStatus(id, list_of<MemberId>(0)(1)));
- map.received(MemberId(2), newcomerStatus(id, list_of<MemberId>(0)(1)(2)(3)));
- map.received(MemberId(3), newcomerStatus(id, list_of<MemberId>(0)(1)(2)(3)));
- BOOST_CHECK(!map.isResendNeeded());
- BOOST_CHECK(map.isComplete());
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK_EQUAL(map.getElders(), list_of<MemberId>(0)(1)(3));
- BOOST_CHECK(map.isUpdateNeeded());
- BOOST_CHECK_EQUAL(map.getClusterId(), id);
-}
-
-QPID_AUTO_TEST_CASE(testMembersLeave) {
- // Test that map completes if members leave rather than send status.
- InitialStatusMap map(MemberId(0), 1);
- Uuid id(true);
- map.configChange(list_of(MemberId(0))(MemberId(1))(MemberId(2)));
- map.received(MemberId(0), newcomerStatus());
- map.received(MemberId(1), activeStatus(id));
- BOOST_CHECK(!map.isComplete());
- map.configChange(list_of(MemberId(0))(MemberId(1))); // 2 left
- BOOST_CHECK(map.isComplete());
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK_EQUAL(map.getElders(), list_of(MemberId(1)));
- BOOST_CHECK_EQUAL(map.getClusterId(), id);
-}
-
-QPID_AUTO_TEST_CASE(testInteveningConfig) {
- // Multiple config changes arrives before we complete the map.
- InitialStatusMap map(MemberId(0), 1);
- Uuid id(true);
-
- map.configChange(list_of<MemberId>(0)(1));
- BOOST_CHECK(map.isResendNeeded());
- map.received(MemberId(0), newcomerStatus());
- BOOST_CHECK(!map.isComplete());
- BOOST_CHECK(!map.isResendNeeded());
- // New member 2 joins before we receive 1
- map.configChange(list_of<MemberId>(0)(1)(2));
- BOOST_CHECK(!map.isComplete());
- BOOST_CHECK(map.isResendNeeded());
- map.received(1, activeStatus(id));
- map.received(2, newcomerStatus());
- // We should not be complete as we haven't received 0 since new member joined
- BOOST_CHECK(!map.isComplete());
- BOOST_CHECK(!map.isResendNeeded());
-
- map.received(0, newcomerStatus());
- BOOST_CHECK(map.isComplete());
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK_EQUAL(map.getElders(), list_of<MemberId>(1));
- BOOST_CHECK_EQUAL(map.getClusterId(), id);
-}
-
-QPID_AUTO_TEST_CASE(testAllCleanNoUpdate) {
- InitialStatusMap map(MemberId(0), 3);
- map.configChange(list_of<MemberId>(0)(1)(2));
- map.received(MemberId(0), storeStatus(false, STORE_STATE_CLEAN_STORE));
- map.received(MemberId(1), storeStatus(false, STORE_STATE_CLEAN_STORE));
- map.received(MemberId(2), storeStatus(false, STORE_STATE_CLEAN_STORE));
- BOOST_CHECK(!map.isUpdateNeeded());
-}
-
-QPID_AUTO_TEST_CASE(testAllEmptyNoUpdate) {
- InitialStatusMap map(MemberId(0), 3);
- map.configChange(list_of<MemberId>(0)(1)(2));
- map.received(MemberId(0), storeStatus(false, STORE_STATE_EMPTY_STORE));
- map.received(MemberId(1), storeStatus(false, STORE_STATE_EMPTY_STORE));
- map.received(MemberId(2), storeStatus(false, STORE_STATE_EMPTY_STORE));
- BOOST_CHECK(map.isComplete());
- BOOST_CHECK(!map.isUpdateNeeded());
-}
-
-QPID_AUTO_TEST_CASE(testAllNoStoreNoUpdate) {
- InitialStatusMap map(MemberId(0), 3);
- map.configChange(list_of<MemberId>(0)(1)(2));
- map.received(MemberId(0), storeStatus(false, STORE_STATE_NO_STORE));
- map.received(MemberId(1), storeStatus(false, STORE_STATE_NO_STORE));
- map.received(MemberId(2), storeStatus(false, STORE_STATE_NO_STORE));
- BOOST_CHECK(map.isComplete());
- BOOST_CHECK(!map.isUpdateNeeded());
-}
-
-QPID_AUTO_TEST_CASE(testDirtyNeedUpdate) {
- InitialStatusMap map(MemberId(0), 3);
- map.configChange(list_of<MemberId>(0)(1)(2));
- map.received(MemberId(0), storeStatus(false, STORE_STATE_DIRTY_STORE));
- map.received(MemberId(1), storeStatus(false, STORE_STATE_CLEAN_STORE));
- map.received(MemberId(2), storeStatus(false, STORE_STATE_CLEAN_STORE));
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK(map.isUpdateNeeded());
-}
-
-QPID_AUTO_TEST_CASE(testEmptyNeedUpdate) {
- InitialStatusMap map(MemberId(0), 3);
- map.configChange(list_of<MemberId>(0)(1)(2));
- map.received(MemberId(0), storeStatus(false, STORE_STATE_EMPTY_STORE));
- map.received(MemberId(1), storeStatus(false, STORE_STATE_CLEAN_STORE));
- map.received(MemberId(2), storeStatus(false, STORE_STATE_CLEAN_STORE));
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK(map.isUpdateNeeded());
-}
-
-QPID_AUTO_TEST_CASE(testEmptyAlone) {
- InitialStatusMap map(MemberId(0), 1);
- map.configChange(list_of<MemberId>(0));
- map.received(MemberId(0), storeStatus(false, STORE_STATE_EMPTY_STORE));
- BOOST_CHECK(map.transitionToComplete());
- BOOST_CHECK(!map.isUpdateNeeded());
-}
-
-QPID_AUTO_TEST_SUITE_END()
-
-}} // namespace qpid::tests
diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am
index f9eed9270b..3513e0a6d6 100644
--- a/cpp/src/tests/Makefile.am
+++ b/cpp/src/tests/Makefile.am
@@ -17,7 +17,7 @@
# under the License.
#
-AM_CXXFLAGS = $(WARNING_CFLAGS) -DBOOST_TEST_DYN_LINK
+AM_CXXFLAGS = $(WARNING_CFLAGS) -DBOOST_TEST_DYN_LINK -D_IN_QPID_BROKER
INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src -I$(top_builddir)/src
PUBLIC_INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include # Use public API only
QMF_GEN=$(top_srcdir)/managementgen/qmf-gen
@@ -28,6 +28,7 @@ abs_srcdir=@abs_srcdir@
extra_libs =
lib_client = $(abs_builddir)/../libqpidclient.la
lib_messaging = $(abs_builddir)/../libqpidmessaging.la
+lib_types = $(abs_builddir)/../libqpidtypes.la
lib_common = $(abs_builddir)/../libqpidcommon.la
lib_broker = $(abs_builddir)/../libqpidbroker.la
lib_console = $(abs_builddir)/../libqmfconsole.la
@@ -107,8 +108,6 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \
TopicExchangeTest.cpp \
TxBufferTest.cpp \
ConnectionOptions.h \
- ForkedBroker.h \
- ForkedBroker.cpp \
ManagementTest.cpp \
MessageReplayTracker.cpp \
ConsoleTest.cpp \
@@ -154,7 +153,7 @@ receiver_SOURCES = \
receiver.cpp \
TestOptions.h \
ConnectionOptions.h
-receiver_LDADD = $(lib_client)
+receiver_LDADD = $(lib_client) -lboost_program_options $(lib_common)
qpidexectest_PROGRAMS += sender
sender_SOURCES = \
@@ -162,7 +161,7 @@ sender_SOURCES = \
TestOptions.h \
ConnectionOptions.h \
Statistics.cpp
-sender_LDADD = $(lib_messaging)
+sender_LDADD = $(lib_messaging) -lboost_program_options $(lib_common) $(lib_types) $(lib_client)
qpidexectest_PROGRAMS += qpid-receive
qpid_receive_SOURCES = \
@@ -171,7 +170,7 @@ qpid_receive_SOURCES = \
ConnectionOptions.h \
Statistics.h \
Statistics.cpp
-qpid_receive_LDADD = $(lib_messaging)
+qpid_receive_LDADD = $(lib_messaging) -lboost_program_options $(lib_common) $(lib_types)
qpidexectest_PROGRAMS += qpid-send
qpid_send_SOURCES = \
@@ -180,42 +179,42 @@ qpid_send_SOURCES = \
ConnectionOptions.h \
Statistics.h \
Statistics.cpp
-qpid_send_LDADD = $(lib_messaging)
+qpid_send_LDADD = $(lib_messaging) -lboost_program_options $(lib_common) $(lib_types)
qpidexectest_PROGRAMS+=qpid-perftest
qpid_perftest_SOURCES=qpid-perftest.cpp test_tools.h TestOptions.h ConnectionOptions.h
qpid_perftest_INCLUDES=$(PUBLIC_INCLUDES)
-qpid_perftest_LDADD=$(lib_client)
+qpid_perftest_LDADD=$(lib_client) -lboost_program_options $(lib_common)
qpidexectest_PROGRAMS+=qpid-txtest
qpid_txtest_INCLUDES=$(PUBLIC_INCLUDES)
qpid_txtest_SOURCES=qpid-txtest.cpp TestOptions.h ConnectionOptions.h
-qpid_txtest_LDADD=$(lib_client)
+qpid_txtest_LDADD=$(lib_client) -lboost_program_options $(lib_common)
qpidexectest_PROGRAMS+=qpid-latency-test
qpid_latency_test_INCLUDES=$(PUBLIC_INCLUDES)
qpid_latency_test_SOURCES=qpid-latency-test.cpp TestOptions.h ConnectionOptions.h
-qpid_latency_test_LDADD=$(lib_client)
+qpid_latency_test_LDADD=$(lib_client) -lboost_program_options $(lib_common)
qpidexectest_PROGRAMS+=qpid-client-test
qpid_client_test_INCLUDES=$(PUBLIC_INCLUDES)
qpid_client_test_SOURCES=qpid-client-test.cpp TestOptions.h ConnectionOptions.h
-qpid_client_test_LDADD=$(lib_client)
+qpid_client_test_LDADD=$(lib_client) -lboost_program_options $(lib_common)
qpidexectest_PROGRAMS+=qpid-topic-listener
qpid_topic_listener_INCLUDES=$(PUBLIC_INCLUDES)
qpid_topic_listener_SOURCES=qpid-topic-listener.cpp TestOptions.h ConnectionOptions.h
-qpid_topic_listener_LDADD=$(lib_client)
+qpid_topic_listener_LDADD=$(lib_client) -lboost_program_options $(lib_common)
qpidexectest_PROGRAMS+=qpid-topic-publisher
qpid_topic_publisher_INCLUDES=$(PUBLIC_INCLUDES)
qpid_topic_publisher_SOURCES=qpid-topic-publisher.cpp TestOptions.h ConnectionOptions.h
-qpid_topic_publisher_LDADD=$(lib_client)
+qpid_topic_publisher_LDADD=$(lib_client) -lboost_program_options $(lib_common)
qpidexectest_PROGRAMS+=qpid-ping
qpid_ping_INCLUDES=$(PUBLIC_INCLUDES)
qpid_ping_SOURCES=qpid-ping.cpp test_tools.h TestOptions.h ConnectionOptions.h
-qpid_ping_LDADD=$(lib_client)
+qpid_ping_LDADD=$(lib_client) -lboost_program_options $(lib_common)
#
# Other test programs
@@ -241,11 +240,6 @@ header_test_INCLUDES=$(PUBLIC_INCLUDES)
header_test_SOURCES=header_test.cpp TestOptions.h ConnectionOptions.h
header_test_LDADD=$(lib_client)
-check_PROGRAMS+=failover_soak
-failover_soak_INCLUDES=$(PUBLIC_INCLUDES)
-failover_soak_SOURCES=failover_soak.cpp ForkedBroker.h ForkedBroker.cpp
-failover_soak_LDADD=$(lib_client) $(lib_broker)
-
check_PROGRAMS+=declare_queues
declare_queues_INCLUDES=$(PUBLIC_INCLUDES)
declare_queues_SOURCES=declare_queues.cpp
@@ -303,8 +297,8 @@ system_tests = qpid-client-test quick_perftest quick_topictest run_header_test q
run_msg_group_tests
TESTS += start_broker $(system_tests) python_tests stop_broker \
run_ha_tests run_federation_tests run_federation_sys_tests \
- run_acl_tests run_cli_tests replication_test dynamic_log_level_test \
- run_queue_flow_limit_tests ipv6_test
+ run_acl_tests run_cli_tests dynamic_log_level_test \
+ dynamic_log_hires_timestamp run_queue_flow_limit_tests ipv6_test
EXTRA_DIST += \
run_test vg_check \
@@ -316,8 +310,8 @@ EXTRA_DIST += \
run_header_test \
header_test.py \
ssl_test \
+ ping_broker \
config.null \
- cpg_check.sh.in \
run_federation_tests \
run_federation_sys_tests \
run_long_federation_sys_tests \
@@ -327,11 +321,11 @@ EXTRA_DIST += \
MessageUtils.h \
TestMessageStore.h \
TxMocks.h \
- replication_test \
run_perftest \
ring_queue_test \
run_ring_queue_test \
dynamic_log_level_test \
+ dynamic_log_hires_timestamp \
qpid-ctrl \
CMakeLists.txt \
windows/DisableWin32ErrorWindows.cpp \
@@ -349,7 +343,10 @@ EXTRA_DIST += \
run_msg_group_tests \
ipv6_test \
run_ha_tests \
+ ha_test.py \
ha_tests.py \
+ brokertest.py \
+ ha_store_tests.py \
test_env.ps1.in
check_LTLIBRARIES += libdlclose_noop.la
@@ -372,9 +369,6 @@ EXTRA_DIST+= \
shared_perftest \
multiq_perftest \
topic_perftest \
- run_failover_soak \
- reliable_replication_test \
- federated_cluster_test_with_node_failure \
sasl_test_setup.sh \
run_msg_group_tests_soak \
qpidd-empty.conf
diff --git a/cpp/src/tests/MessageUtils.h b/cpp/src/tests/MessageUtils.h
index c2eabd804d..5024f5b77c 100644
--- a/cpp/src/tests/MessageUtils.h
+++ b/cpp/src/tests/MessageUtils.h
@@ -1,3 +1,6 @@
+#ifndef TESTS_MESSAGEUTILS_H
+#define TESTS_MESSAGEUTILS_H
+
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -98,3 +101,5 @@ struct MessageUtils
};
}} // namespace qpid::tests
+
+#endif /*!TESTS_MESSAGEUTILS_H*/
diff --git a/cpp/src/tests/MessagingSessionTests.cpp b/cpp/src/tests/MessagingSessionTests.cpp
index c8ee3aa401..55cff046e2 100644
--- a/cpp/src/tests/MessagingSessionTests.cpp
+++ b/cpp/src/tests/MessagingSessionTests.cpp
@@ -1164,6 +1164,59 @@ QPID_AUTO_TEST_CASE(testAlternateExchangeInLinkDeclare)
}
}
+QPID_AUTO_TEST_CASE(testBrowseOnly)
+{
+ /* Set up a queue browse-only, and try to receive
+ the same messages twice with two different receivers.
+ This works because the browse-only queue does not
+ allow message acquisition. */
+
+ QueueFixture fix;
+ std::string addr = "q; {create:always, node:{type:queue, durable:false, x-declare:{arguments:{qpid.browse-only:1}}}}";
+ Sender sender = fix.session.createSender(addr);
+ Message out("test-message");
+
+ int count = 10;
+ for ( int i = 0; i < count; ++ i ) {
+ sender.send(out);
+ }
+
+ Message m;
+
+ Receiver receiver_1 = fix.session.createReceiver(addr);
+ for ( int i = 0; i < count; ++ i ) {
+ BOOST_CHECK(receiver_1.fetch(m, Duration::SECOND));
+ }
+
+ Receiver receiver_2 = fix.session.createReceiver(addr);
+ for ( int i = 0; i < count; ++ i ) {
+ BOOST_CHECK(receiver_2.fetch(m, Duration::SECOND));
+ }
+
+ fix.session.acknowledge();
+}
+
+QPID_AUTO_TEST_CASE(testLinkBindingCleanup)
+{
+ MessagingFixture fix;
+
+ Sender sender = fix.session.createSender("test.ex;{create:always,node:{type:topic}}");
+
+ Connection connection = fix.newConnection();
+ connection.open();
+
+ Session session(connection.createSession());
+ Receiver receiver1 = session.createReceiver("test.q;{create:always, node:{type:queue, x-bindings:[{exchange:test.ex,queue:test.q,key:#,arguments:{x-scope:session}}]}}");
+ Receiver receiver2 = fix.session.createReceiver("test.q;{create:never, delete:always}");
+ connection.close();
+
+ sender.send(Message("test-message"), true);
+
+ // The session-scoped binding should be removed when receiver1's network connection is lost
+ Message in;
+ BOOST_CHECK(!receiver2.fetch(in, Duration::IMMEDIATE));
+}
+
QPID_AUTO_TEST_SUITE_END()
}} // namespace qpid::tests
diff --git a/cpp/src/tests/PartialFailure.cpp b/cpp/src/tests/PartialFailure.cpp
deleted file mode 100644
index 63ee28017a..0000000000
--- a/cpp/src/tests/PartialFailure.cpp
+++ /dev/null
@@ -1,291 +0,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.
- *
- */
-
-/**@file Tests for partial failure in a cluster.
- * Partial failure means some nodes experience a failure while others do not.
- * In this case the failed nodes must shut down.
- */
-
-#include "test_tools.h"
-#include "unit_test.h"
-#include "ClusterFixture.h"
-#include <boost/assign.hpp>
-#include <boost/algorithm/string.hpp>
-#include <boost/bind.hpp>
-
-namespace qpid {
-namespace tests {
-
-QPID_AUTO_TEST_SUITE(PartialFailureTestSuite)
-
-using namespace std;
-using namespace qpid;
-using namespace qpid::cluster;
-using namespace qpid::framing;
-using namespace qpid::client;
-using namespace qpid::client::arg;
-using namespace boost::assign;
-using broker::Broker;
-using boost::shared_ptr;
-
-// Timeout for tests that wait for messages
-const sys::Duration TIMEOUT=sys::TIME_SEC/4;
-
-static bool isLogOption(const std::string& s) { return boost::starts_with(s, "--log-enable"); }
-
-void updateArgs(ClusterFixture::Args& args, size_t index) {
- ostringstream clusterLib, testStoreLib, storeName;
- clusterLib << getLibPath("CLUSTER_LIB");
- testStoreLib << getLibPath("TEST_STORE_LIB");
- storeName << "s" << index;
- args.push_back("--auth");
- args.push_back("no");
- args.push_back("--no-module-dir");
- args.push_back("--load-module");
- args.push_back(clusterLib.str());
- args.push_back("--load-module");
- args.push_back(testStoreLib.str());
- args.push_back("--test-store-name");
- args.push_back(storeName.str());
- args.push_back("TMP_DATA_DIR");
-
- // These tests generate errors deliberately, disable error logging unless a log env var is set.
- if (!::getenv("QPID_TRACE") && !::getenv("QPID_LOG_ENABLE")) {
- remove_if(args.begin(), args.end(), isLogOption);
- args.push_back("--log-enable=critical+:DISABLED"); // hacky way to disable logs.
- }
-}
-
-Message pMessage(string data, string q) {
- Message msg(data, q);
- msg.getDeliveryProperties().setDeliveryMode(PERSISTENT);
- return msg;
-}
-
-void queueAndSub(Client& c) {
- c.session.queueDeclare(c.name, durable=true);
- c.subs.subscribe(c.lq, c.name);
-}
-
-// Handle near-simultaneous errors
-QPID_AUTO_TEST_CASE(testCoincidentErrors) {
- ClusterFixture cluster(2, updateArgs, -1);
- Client c0(cluster[0], "c0");
- Client c1(cluster[1], "c1");
-
- c0.session.queueDeclare("q", durable=true);
- {
- ScopedSuppressLogging allQuiet;
- async(c0.session).messageTransfer(content=pMessage("TEST_STORE_DO: s0[exception]", "q"));
- async(c1.session).messageTransfer(content=pMessage("TEST_STORE_DO: s1[exception]", "q"));
-
- int alive=0;
- try { Client c00(cluster[0], "c00"); ++alive; c00.close(); } catch (...) {}
- try { Client c11(cluster[1], "c11"); ++alive; c11.close(); } catch (...) {}
-
- BOOST_CHECK_EQUAL(alive, 1);
-
- // Close inside ScopedSuppressLogging to avoid warnings
- c0.close();
- c1.close();
- }
-}
-
-// Verify normal cluster-wide errors.
-QPID_AUTO_TEST_CASE(testNormalErrors) {
- // FIXME aconway 2009-04-10: Would like to put a scope just around
- // the statements expected to fail (in BOOST_CHECK_yTHROW) but that
- // sproadically lets out messages, possibly because they're in
- // Connection thread.
-
- ClusterFixture cluster(3, updateArgs, -1);
- Client c0(cluster[0], "c0");
- Client c1(cluster[1], "c1");
- Client c2(cluster[2], "c2");
-
- {
- ScopedSuppressLogging allQuiet;
- queueAndSub(c0);
- c0.session.messageTransfer(content=Message("x", "c0"));
- BOOST_CHECK_EQUAL(c0.lq.get(TIMEOUT).getData(), "x");
-
- // Session error.
- BOOST_CHECK_THROW(c0.session.exchangeBind(), SessionException);
- c1.session.messageTransfer(content=Message("stay", "c0")); // Will stay on queue, session c0 is dead.
-
- // Connection error, kill c1 on all members.
- queueAndSub(c1);
- BOOST_CHECK_THROW(
- c1.session.messageTransfer(
- content=pMessage("TEST_STORE_DO: s0[exception] s1[exception] s2[exception] testNormalErrors", "c1")),
- ConnectionException);
- c2.session.messageTransfer(content=Message("stay", "c1")); // Will stay on queue, session/connection c1 is dead.
-
- BOOST_CHECK_EQUAL(3u, knownBrokerPorts(c2.connection, 3).size());
- BOOST_CHECK_EQUAL(c2.subs.get("c0", TIMEOUT).getData(), "stay");
- BOOST_CHECK_EQUAL(c2.subs.get("c1", TIMEOUT).getData(), "stay");
-
- // Close inside ScopedSuppressLogging to avoid warnings
- c0.close();
- c1.close();
- c2.close();
- }
-}
-
-
-// Test errors after a new member joins to verify frame-sequence-numbers are ok in update.
-QPID_AUTO_TEST_CASE(testErrorAfterJoin) {
- ClusterFixture cluster(1, updateArgs, -1);
- Client c0(cluster[0]);
- {
- ScopedSuppressLogging allQuiet;
-
- c0.session.queueDeclare("q", durable=true);
- c0.session.messageTransfer(content=pMessage("a", "q"));
-
- // Kill the new guy
- cluster.add();
- Client c1(cluster[1]);
- c0.session.messageTransfer(content=pMessage("TEST_STORE_DO: s1[exception] testErrorAfterJoin", "q"));
- BOOST_CHECK_THROW(c1.session.messageTransfer(content=pMessage("xxx", "q")), TransportFailure);
- BOOST_CHECK_EQUAL(1u, knownBrokerPorts(c0.connection, 1).size());
-
- // Kill the old guy
- cluster.add();
- Client c2(cluster[2]);
- c2.session.messageTransfer(content=pMessage("TEST_STORE_DO: s0[exception] testErrorAfterJoin2", "q"));
- BOOST_CHECK_THROW(c0.session.messageTransfer(content=pMessage("xxx", "q")), TransportFailure);
-
- BOOST_CHECK_EQUAL(1u, knownBrokerPorts(c2.connection, 1).size());
-
- // Close inside ScopedSuppressLogging to avoid warnings
- c0.close();
- c1.close();
- c2.close();
- }
-}
-
-// Test that if one member fails and others do not, the failure leaves the cluster.
-QPID_AUTO_TEST_CASE(testSinglePartialFailure) {
- ClusterFixture cluster(3, updateArgs, -1);
- Client c0(cluster[0], "c0");
- Client c1(cluster[1], "c1");
- Client c2(cluster[2], "c2");
-
- {
- ScopedSuppressLogging allQuiet;
-
- c0.session.queueDeclare("q", durable=true);
- c0.session.messageTransfer(content=pMessage("a", "q"));
- // Cause partial failure on c1
- c0.session.messageTransfer(content=pMessage("TEST_STORE_DO: s1[exception] testSinglePartialFailure", "q"));
- BOOST_CHECK_THROW(c1.session.queueQuery("q"), TransportFailure);
-
- c0.session.messageTransfer(content=pMessage("b", "q"));
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q").getMessageCount(), 3u);
- BOOST_CHECK_EQUAL(2u, knownBrokerPorts(c0.connection, 2).size());
-
- // Cause partial failure on c2
- c0.session.messageTransfer(content=pMessage("TEST_STORE_DO: s2[exception] testSinglePartialFailure2", "q"));
- BOOST_CHECK_THROW(c2.session.queueQuery("q"), TransportFailure);
-
- c0.session.messageTransfer(content=pMessage("c", "q"));
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q").getMessageCount(), 5u);
- BOOST_CHECK_EQUAL(1u, knownBrokerPorts(c0.connection, 1).size());
-
- // Close inside ScopedSuppressLogging to avoid warnings
- c0.close();
- c1.close();
- c2.close();
- }
-}
-
-// Test multiple partial falures: 2 fail 2 pass
-QPID_AUTO_TEST_CASE(testMultiPartialFailure) {
- ClusterFixture cluster(4, updateArgs, -1);
- Client c0(cluster[0], "c0");
- Client c1(cluster[1], "c1");
- Client c2(cluster[2], "c2");
- Client c3(cluster[3], "c3");
-
- {
- ScopedSuppressLogging allQuiet;
-
- c0.session.queueDeclare("q", durable=true);
- c0.session.messageTransfer(content=pMessage("a", "q"));
-
- // Cause partial failure on c1, c2
- c0.session.messageTransfer(content=pMessage("TEST_STORE_DO: s1[exception] s2[exception] testMultiPartialFailure", "q"));
- BOOST_CHECK_THROW(c1.session.queueQuery("q"), TransportFailure);
- BOOST_CHECK_THROW(c2.session.queueQuery("q"), TransportFailure);
-
- c0.session.messageTransfer(content=pMessage("b", "q"));
- c3.session.messageTransfer(content=pMessage("c", "q"));
- BOOST_CHECK_EQUAL(c3.session.queueQuery("q").getMessageCount(), 4u);
- // FIXME aconway 2009-06-30: This check fails sporadically with 2 != 3.
- // It should pass reliably.
- // BOOST_CHECK_EQUAL(2u, knownBrokerPorts(c0.connection, 2).size());
-
- // Close inside ScopedSuppressLogging to avoid warnings
- c0.close();
- c1.close();
- c2.close();
- c3.close();
- }
-}
-
-/** FIXME aconway 2009-04-10:
- * The current approach to shutting down a process in test_store
- * sometimes leads to assertion failures and errors in the shut-down
- * process. Need a cleaner solution
- */
-#if 0
-QPID_AUTO_TEST_CASE(testPartialFailureMemberLeaves) {
- ClusterFixture cluster(2, updateArgs, -1);
- Client c0(cluster[0], "c0");
- Client c1(cluster[1], "c1");
-
- {
- ScopedSuppressLogging allQuiet;
-
- c0.session.queueDeclare("q", durable=true);
- c0.session.messageTransfer(content=pMessage("a", "q"));
-
- // Cause failure on member 0 and simultaneous crash on member 1.
- BOOST_CHECK_THROW(
- c0.session.messageTransfer(
- content=pMessage("TEST_STORE_DO: s0[exception] s1[exit_process] testPartialFailureMemberLeaves", "q")),
- ConnectionException);
- cluster.wait(1);
-
- Client c00(cluster[0], "c00"); // Old connection is dead.
- BOOST_CHECK_EQUAL(c00.session.queueQuery("q").getMessageCount(), 1u);
- BOOST_CHECK_EQUAL(1u, knownBrokerPorts(c00.connection, 1).size());
-
- // Close inside ScopedSuppressLogging to avoid warnings
- c0.close();
- }
-}
-#endif
-
-QPID_AUTO_TEST_SUITE_END()
-
-}} // namespace qpid::tests
diff --git a/cpp/src/tests/PollerTest.cpp b/cpp/src/tests/PollerTest.cpp
index 9fa5689c5f..5a1d02964c 100644
--- a/cpp/src/tests/PollerTest.cpp
+++ b/cpp/src/tests/PollerTest.cpp
@@ -23,7 +23,6 @@
* Use socketpair to test the poller
*/
-#include "qpid/sys/IOHandle.h"
#include "qpid/sys/Poller.h"
#include "qpid/sys/posix/PrivatePosix.h"
@@ -106,8 +105,8 @@ int main(int /*argc*/, char** /*argv*/)
auto_ptr<Poller> poller(new Poller);
- PosixIOHandle f0(sv[0]);
- PosixIOHandle f1(sv[1]);
+ IOHandle f0(sv[0]);
+ IOHandle f1(sv[1]);
PollerHandle h0(f0);
PollerHandle h1(f1);
@@ -225,8 +224,8 @@ int main(int /*argc*/, char** /*argv*/)
auto_ptr<Poller> poller1(new Poller);
- PosixIOHandle f2(sv[0]);
- PosixIOHandle f3(sv[1]);
+ IOHandle f2(sv[0]);
+ IOHandle f3(sv[1]);
PollerHandle h2(f2);
PollerHandle h3(f3);
diff --git a/cpp/src/tests/QueueTest.cpp b/cpp/src/tests/QueueTest.cpp
index d86c18c38d..60ba036a7e 100644
--- a/cpp/src/tests/QueueTest.cpp
+++ b/cpp/src/tests/QueueTest.cpp
@@ -40,6 +40,7 @@
#include "qpid/framing/reply_exceptions.h"
#include "qpid/broker/QueueFlowLimit.h"
#include "qpid/broker/QueueSettings.h"
+#include "qpid/sys/Timer.h"
#include <iostream>
#include <vector>
diff --git a/cpp/src/tests/StoreStatus.cpp b/cpp/src/tests/StoreStatus.cpp
deleted file mode 100644
index 43d4cfd920..0000000000
--- a/cpp/src/tests/StoreStatus.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * 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.
- *
- */
-
-
-#include "unit_test.h"
-#include "test_tools.h"
-#include "qpid/cluster/StoreStatus.h"
-#include "qpid/framing/Uuid.h"
-#include <boost/assign.hpp>
-#include <boost/filesystem/operations.hpp>
-
-using namespace std;
-using namespace qpid::cluster;
-using namespace qpid::framing;
-using namespace qpid::framing::cluster;
-using namespace boost::assign;
-using namespace boost::filesystem;
-
-
-namespace qpid {
-namespace tests {
-
-QPID_AUTO_TEST_SUITE(StoreStatusTestSuite)
-
-const char* TEST_DIR = "StoreStatus.tmp";
-
-struct TestDir {
- TestDir() {
- remove_all(TEST_DIR);
- create_directory(TEST_DIR);
- }
- ~TestDir() {
- remove_all(TEST_DIR);
- }
-};
-
-QPID_AUTO_TEST_CASE(testLoadEmpty) {
- TestDir td;
- StoreStatus ss(TEST_DIR);
- BOOST_CHECK_EQUAL(ss.getState(), STORE_STATE_NO_STORE);
- BOOST_CHECK(!ss.getClusterId());
- BOOST_CHECK(!ss.getShutdownId());
- ss.load();
- BOOST_CHECK_EQUAL(ss.getState(), STORE_STATE_EMPTY_STORE);
- BOOST_CHECK(!ss.getShutdownId());
-}
-
-QPID_AUTO_TEST_CASE(testSaveLoadDirty) {
- TestDir td;
- Uuid clusterId = Uuid(true);
- StoreStatus ss(TEST_DIR);
- ss.load();
- ss.setClusterId(clusterId);
- ss.dirty();
- BOOST_CHECK_EQUAL(ss.getState(), STORE_STATE_DIRTY_STORE);
-
- StoreStatus ss2(TEST_DIR);
- ss2.load();
- BOOST_CHECK_EQUAL(ss2.getState(), STORE_STATE_DIRTY_STORE);
- BOOST_CHECK_EQUAL(ss2.getClusterId(), clusterId);
- BOOST_CHECK(!ss2.getShutdownId());
-}
-
-QPID_AUTO_TEST_CASE(testSaveLoadClean) {
- TestDir td;
- Uuid clusterId = Uuid(true);
- Uuid shutdownId = Uuid(true);
- StoreStatus ss(TEST_DIR);
- ss.load();
- ss.setClusterId(clusterId);
- ss.clean(shutdownId);
- BOOST_CHECK_EQUAL(ss.getState(), STORE_STATE_CLEAN_STORE);
-
- StoreStatus ss2(TEST_DIR);
- ss2.load();
- BOOST_CHECK_EQUAL(ss2.getState(), STORE_STATE_CLEAN_STORE);
- BOOST_CHECK_EQUAL(ss2.getClusterId(), clusterId);
- BOOST_CHECK_EQUAL(ss2.getShutdownId(), shutdownId);
-}
-
-QPID_AUTO_TEST_CASE(testMarkDirty) {
- // Save clean then mark to dirty.
- TestDir td;
- Uuid clusterId = Uuid(true);
- Uuid shutdownId = Uuid(true);
- StoreStatus ss(TEST_DIR);
- ss.load();
- ss.setClusterId(clusterId);
- ss.dirty();
- ss.clean(shutdownId);
- ss.dirty();
-
- StoreStatus ss2(TEST_DIR);
- ss2.load();
- BOOST_CHECK_EQUAL(ss2.getState(), STORE_STATE_DIRTY_STORE);
- BOOST_CHECK_EQUAL(ss2.getClusterId(), clusterId);
- BOOST_CHECK(!ss2.getShutdownId());
-}
-
-QPID_AUTO_TEST_SUITE_END()
-
- }} // namespace qpid::tests
diff --git a/cpp/src/tests/SystemInfo.cpp b/cpp/src/tests/SystemInfo.cpp
index 12d8d3dba8..34f1ac408e 100644
--- a/cpp/src/tests/SystemInfo.cpp
+++ b/cpp/src/tests/SystemInfo.cpp
@@ -31,22 +31,6 @@ namespace tests {
QPID_AUTO_TEST_SUITE(SystemInfoTestSuite)
-QPID_AUTO_TEST_CASE(TestIsLocalHost) {
- // Test that local hostname and addresses are considered local
- Address a;
- BOOST_ASSERT(SystemInfo::getLocalHostname(a));
- BOOST_ASSERT(SystemInfo::isLocalHost(a.host));
- std::vector<Address> addrs;
- SystemInfo::getLocalIpAddresses(0, addrs);
- for (std::vector<Address>::iterator i = addrs.begin(); i != addrs.end(); ++i)
- BOOST_ASSERT(SystemInfo::isLocalHost(i->host));
- // Check some non-local addresses
- BOOST_ASSERT(!SystemInfo::isLocalHost("123.4.5.6"));
- BOOST_ASSERT(!SystemInfo::isLocalHost("nosuchhost"));
- BOOST_ASSERT(SystemInfo::isLocalHost("127.0.0.1"));
- BOOST_ASSERT(SystemInfo::isLocalHost("::1"));
-}
-
QPID_AUTO_TEST_SUITE_END()
}} // namespace qpid::tests
diff --git a/cpp/src/tests/Variant.cpp b/cpp/src/tests/Variant.cpp
index 40f1c0cf75..6d629bbb4a 100644
--- a/cpp/src/tests/Variant.cpp
+++ b/cpp/src/tests/Variant.cpp
@@ -135,6 +135,16 @@ QPID_AUTO_TEST_CASE(testConversionsFromString)
BOOST_CHECK_EQUAL(0, value.asInt16());
BOOST_CHECK_EQUAL(0u, value.asUint16());
+ value = "-Blah";
+ BOOST_CHECK_THROW(value.asUint16(), InvalidConversion);
+ BOOST_CHECK_THROW(value.asInt16(), InvalidConversion);
+ BOOST_CHECK_THROW(value.asUint32(), InvalidConversion);
+ BOOST_CHECK_THROW(value.asInt32(), InvalidConversion);
+ BOOST_CHECK_THROW(value.asUint64(), InvalidConversion);
+ BOOST_CHECK_THROW(value.asInt64(), InvalidConversion);
+ BOOST_CHECK_THROW(value.asFloat(), InvalidConversion);
+ BOOST_CHECK_THROW(value.asDouble(), InvalidConversion);
+
value = "-000";
BOOST_CHECK_EQUAL(0, value.asInt16());
BOOST_CHECK_EQUAL(0u, value.asUint16());
diff --git a/cpp/src/tests/acl.py b/cpp/src/tests/acl.py
index 102796cba6..48723bfde9 100755
--- a/cpp/src/tests/acl.py
+++ b/cpp/src/tests/acl.py
@@ -53,6 +53,9 @@ class ACLTests(TestBase010):
def port_u(self):
return int(self.defines["port-u"])
+ def port_q(self):
+ return int(self.defines["port-q"])
+
def get_session_by_port(self, user, passwd, byPort):
socket = connect(self.broker.host, byPort)
connection = Connection (sock=socket, username=user, password=passwd,
@@ -542,6 +545,123 @@ class ACLTests(TestBase010):
self.fail(result)
+ def test_illegal_filemaxsize_upper_limit_spec(self):
+ """
+ Test illegal file policy
+ """
+ #
+ # Use filemaxsizeupperlimit
+ #
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID create queue name=q2 filemaxsizeupperlimit=-1\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ expected = "-1 is not a valid value for 'filemaxsizeupperlimit', " \
+ "values should be between 0 and 9223372036854775807";
+ if (result.find(expected) == -1):
+ self.fail(result)
+
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID create queue name=q2 filemaxsizeupperlimit=9223372036854775808\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ expected = "9223372036854775808 is not a valid value for 'filemaxsizeupperlimit', " \
+ "values should be between 0 and 9223372036854775807";
+ if (result.find(expected) == -1):
+ self.fail(result)
+
+
+
+ def test_illegal_filemaxcount_upper_limit_spec(self):
+ """
+ Test illegal file policy
+ """
+ #
+ # use maxfilecountupperlimit
+ #
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID create queue name=q2 filemaxcountupperlimit=-1\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ expected = "-1 is not a valid value for 'filemaxcountupperlimit', " \
+ "values should be between 0 and 9223372036854775807";
+ if (result.find(expected) == -1):
+ self.fail(result)
+
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID create queue name=q2 filemaxcountupperlimit=9223372036854775808\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ expected = "9223372036854775808 is not a valid value for 'filemaxcountupperlimit', " \
+ "values should be between 0 and 9223372036854775807";
+ if (result.find(expected) == -1):
+ self.fail(result)
+
+
+ def test_illegal_filemaxsize_lower_limit_spec(self):
+ """
+ Test illegal file policy
+ """
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID create queue name=q2 filemaxsizelowerlimit=-1\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ expected = "-1 is not a valid value for 'filemaxsizelowerlimit', " \
+ "values should be between 0 and 9223372036854775807";
+ if (result.find(expected) == -1):
+ self.fail(result)
+
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID create queue name=q2 filemaxsizelowerlimit=9223372036854775808\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ expected = "9223372036854775808 is not a valid value for 'filemaxsizelowerlimit', " \
+ "values should be between 0 and 9223372036854775807";
+ if (result.find(expected) == -1):
+ self.fail(result)
+
+
+
+ def test_illegal_filemaxcount_lower_limit_spec(self):
+ """
+ Test illegal file policy
+ """
+
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID create queue name=q2 filemaxcountlowerlimit=-1\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ expected = "-1 is not a valid value for 'filemaxcountlowerlimit', " \
+ "values should be between 0 and 9223372036854775807";
+ if (result.find(expected) == -1):
+ self.fail(result)
+
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID create queue name=q2 filemaxcountlowerlimit=9223372036854775808\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ expected = "9223372036854775808 is not a valid value for 'filemaxcountlowerlimit', " \
+ "values should be between 0 and 9223372036854775807";
+ if (result.find(expected) == -1):
+ self.fail(result)
+
+
#=====================================
# ACL queue tests
#=====================================
@@ -831,6 +951,171 @@ class ACLTests(TestBase010):
self.fail("ACL should allow queue delete request for q4");
#=====================================
+ # ACL file tests
+ #=====================================
+
+ def test_file_allow_mode(self):
+ """
+ Test cases for file acl in allow mode
+ """
+ aclf = self.get_acl_file()
+ aclf.write('acl deny bob@QPID access queue name=qf1\n')
+ aclf.write('acl deny bob@QPID create queue name=qf1 durable=true\n')
+ aclf.write('acl deny bob@QPID create queue name=qf2 exclusive=true policytype=ring\n')
+ aclf.write('acl deny bob@QPID access queue name=qf3\n')
+ aclf.write('acl deny bob@QPID purge queue name=qf3\n')
+ aclf.write('acl deny bob@QPID delete queue name=qf4\n')
+ aclf.write('acl deny bob@QPID create queue name=qf5 filemaxsizeupperlimit=1000 filemaxcountupperlimit=100\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ if (result):
+ self.fail(result)
+
+ session = self.get_session('bob','bob')
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 200
+ queue_options["qpid.file_size"] = 500
+ session.queue_declare(queue="qf5", exclusive=True, arguments=queue_options)
+ self.fail("ACL should deny queue create request with name=qf5, qpid.file_size=500 and qpid.file_count=200");
+ except qpid.session.SessionException, e:
+ self.assertEqual(403,e.args[0].error_code)
+ session = self.get_session('bob','bob')
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 200
+ queue_options["qpid.file_size"] = 100
+ session.queue_declare(queue="qf2", exclusive=True, arguments=queue_options)
+ except qpid.session.SessionException, e:
+ if (403 == e.args[0].error_code):
+ self.fail("ACL should allow queue create request with name=qf2, qpid.file_size=100 and qpid.file_count=200 ");
+
+
+ def test_file_deny_mode(self):
+ """
+ Test cases for queue acl in deny mode
+ """
+ aclf = self.get_acl_file()
+ aclf.write('acl allow bob@QPID access queue name=qfd1\n')
+ aclf.write('acl allow bob@QPID create queue name=qfd1 durable=true\n')
+ aclf.write('acl allow bob@QPID create queue name=qfd2 exclusive=true policytype=ring\n')
+ aclf.write('acl allow bob@QPID access queue name=qfd3\n')
+ aclf.write('acl allow bob@QPID purge queue name=qfd3\n')
+ aclf.write('acl allow bob@QPID create queue name=qfd3\n')
+ aclf.write('acl allow bob@QPID create queue name=qfd4\n')
+ aclf.write('acl allow bob@QPID delete queue name=qfd4\n')
+ aclf.write('acl allow bob@QPID create queue name=qfd5 filemaxsizeupperlimit=1000 filemaxcountupperlimit=100\n')
+ aclf.write('acl allow bob@QPID create queue name=qfd6 filemaxsizelowerlimit=50 filemaxsizeupperlimit=100 filemaxcountlowerlimit=50 filemaxcountupperlimit=100\n')
+ aclf.write('acl allow anonymous all all\n')
+ aclf.write('acl deny all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ if (result):
+ self.fail(result)
+
+ session = self.get_session('bob','bob')
+
+ try:
+ session.queue_declare(queue="qfd1", durable=True)
+ except qpid.session.SessionException, e:
+ if (403 == e.args[0].error_code):
+ self.fail("ACL should allow queue create request with name=qfd1 durable=true");
+
+ try:
+ session.queue_declare(queue="qfd1", durable=True, passive=True)
+ except qpid.session.SessionException, e:
+ if (403 == e.args[0].error_code):
+ self.fail("ACL should allow queue passive declare request with name=qfd1 durable=true passive=true");
+
+ try:
+ session.queue_declare(queue="qfd1", durable=False, passive=False)
+ self.fail("ACL should deny queue create request with name=qfd1 durable=true passive=false");
+ except qpid.session.SessionException, e:
+ self.assertEqual(403,e.args[0].error_code)
+ session = self.get_session('bob','bob')
+
+ try:
+ session.queue_declare(queue="qfd2", exclusive=False)
+ self.fail("ACL should deny queue create request with name=qfd2 exclusive=false");
+ except qpid.session.SessionException, e:
+ self.assertEqual(403,e.args[0].error_code)
+ session = self.get_session('bob','bob')
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 200
+ queue_options["qpid.file_size"] = 500
+ session.queue_declare(queue="qfd5", arguments=queue_options)
+ self.fail("ACL should deny queue create request with name=qfd5 filemaxsizeupperlimit=500 filemaxcountupperlimit=200");
+ except qpid.session.SessionException, e:
+ self.assertEqual(403,e.args[0].error_code)
+ session = self.get_session('bob','bob')
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 100
+ queue_options["qpid.file_size"] = 500
+ session.queue_declare(queue="qfd5", arguments=queue_options)
+ except qpid.session.SessionException, e:
+ if (403 == e.args[0].error_code):
+ self.fail("ACL should allow queue create request with name=qfd5 filemaxsizeupperlimit=500 filemaxcountupperlimit=200");
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 49
+ queue_options["qpid.file_size"] = 100
+ session.queue_declare(queue="qfd6", arguments=queue_options)
+ self.fail("ACL should deny queue create request with name=qfd6 filemaxsizeupperlimit=100 filemaxcountupperlimit=49");
+ except qpid.session.SessionException, e:
+ self.assertEqual(403,e.args[0].error_code)
+ session = self.get_session('bob','bob')
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 101
+ queue_options["qpid.file_size"] = 100
+ session.queue_declare(queue="qfd6", arguments=queue_options)
+ self.fail("ACL should allow queue create request with name=qfd6 filemaxsizeupperlimit=100 filemaxcountupperlimit=101");
+ except qpid.session.SessionException, e:
+ self.assertEqual(403,e.args[0].error_code)
+ session = self.get_session('bob','bob')
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 100
+ queue_options["qpid.file_size"] = 49
+ session.queue_declare(queue="qfd6", arguments=queue_options)
+ self.fail("ACL should deny queue create request with name=qfd6 filemaxsizeupperlimit=49 filemaxcountupperlimit=100");
+ except qpid.session.SessionException, e:
+ self.assertEqual(403,e.args[0].error_code)
+ session = self.get_session('bob','bob')
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 100
+ queue_options["qpid.file_size"] =101
+ session.queue_declare(queue="qfd6", arguments=queue_options)
+ self.fail("ACL should deny queue create request with name=qfd6 filemaxsizeupperlimit=101 filemaxcountupperlimit=100");
+ except qpid.session.SessionException, e:
+ self.assertEqual(403,e.args[0].error_code)
+ session = self.get_session('bob','bob')
+
+ try:
+ queue_options = {}
+ queue_options["qpid.file_count"] = 50
+ queue_options["qpid.file_size"] = 50
+ session.queue_declare(queue="qfd6", arguments=queue_options)
+ except qpid.session.SessionException, e:
+ if (403 == e.args[0].error_code):
+ self.fail("ACL should allow queue create request with name=qfd6 filemaxsizeupperlimit=50 filemaxcountupperlimit=50");
+
+
+ #=====================================
# ACL exchange tests
#=====================================
@@ -1538,10 +1823,10 @@ class ACLTests(TestBase010):
#=====================================
- # QMF Topic Exchange tests
+ # Routingkey lookup using Topic Exchange tests
#=====================================
- def test_qmf_topic_exchange_tests(self):
+ def test_topic_exchange_publish_tests(self):
"""
Test using QMF method hooks into ACL logic
"""
@@ -1655,40 +1940,367 @@ class ACLTests(TestBase010):
self.LookupPublish("dev@QPID", "X", "a.M.N", "allow-log")
self.LookupPublish("dev@QPID", "X", "a.M.p.qq.N", "allow-log")
+ def test_topic_exchange_other_tests(self):
+ """
+ Test using QMF method hooks into ACL logic
+ """
+ action_list = ['access','bind','unbind']
+
+ aclf = self.get_acl_file()
+ aclf.write('# begin hack alert: allow anonymous to access the lookup debug functions\n')
+ aclf.write('acl allow-log anonymous create queue\n')
+ aclf.write('acl allow-log anonymous all exchange name=qmf.*\n')
+ aclf.write('acl allow-log anonymous all exchange name=amq.direct\n')
+ aclf.write('acl allow-log anonymous all exchange name=qpid.management\n')
+ aclf.write('acl allow-log anonymous access method name=*\n')
+ aclf.write('# end hack alert\n')
+ for action in action_list:
+ aclf.write('acl allow-log uPlain1@COMPANY ' + action + ' exchange name=X routingkey=ab.cd.e\n')
+ aclf.write('acl allow-log uPlain2@COMPANY ' + action + ' exchange name=X routingkey=.\n')
+ aclf.write('acl allow-log uStar1@COMPANY ' + action + ' exchange name=X routingkey=a.*.b\n')
+ aclf.write('acl allow-log uStar2@COMPANY ' + action + ' exchange name=X routingkey=*.x\n')
+ aclf.write('acl allow-log uStar3@COMPANY ' + action + ' exchange name=X routingkey=x.x.*\n')
+ aclf.write('acl allow-log uHash1@COMPANY ' + action + ' exchange name=X routingkey=a.#.b\n')
+ aclf.write('acl allow-log uHash2@COMPANY ' + action + ' exchange name=X routingkey=a.#\n')
+ aclf.write('acl allow-log uHash3@COMPANY ' + action + ' exchange name=X routingkey=#.a\n')
+ aclf.write('acl allow-log uHash4@COMPANY ' + action + ' exchange name=X routingkey=a.#.b.#.c\n')
+ aclf.write('acl allow-log uMixed1@COMPANY ' + action + ' exchange name=X routingkey=*.x.#.y\n')
+ aclf.write('acl allow-log uMixed2@COMPANY ' + action + ' exchange name=X routingkey=a.#.b.*\n')
+ aclf.write('acl allow-log uMixed3@COMPANY ' + action + ' exchange name=X routingkey=*.*.*.#\n')
+
+ aclf.write('acl allow-log all ' + action + ' exchange name=X routingkey=MN.OP.Q\n')
+ aclf.write('acl allow-log all ' + action + ' exchange name=X routingkey=M.*.N\n')
+ aclf.write('acl allow-log all ' + action + ' exchange name=X routingkey=M.#.N\n')
+ aclf.write('acl allow-log all ' + action + ' exchange name=X routingkey=*.M.#.N\n')
+
+ aclf.write('acl deny-log all all\n')
+ aclf.close()
+
+ result = self.reload_acl()
+ if (result):
+ self.fail(result)
+
+ for action in action_list:
+ # aclKey: "ab.cd.e"
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":"ab.cd.e"}, "allow-log")
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":"ab.cd.e"}, "allow-log")
+
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":"ab.cd.e"}, "allow-log")
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":"abx.cd.e"}, "deny-log")
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":"ab.cd"}, "deny-log")
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":"ab.cd..e."}, "deny-log")
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":"ab.cd.e."}, "deny-log")
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":".ab.cd.e"}, "deny-log")
+ # aclKey: "."
+ self.Lookup("uPlain2@COMPANY", action, "exchange", "X", {"routingkey":"."}, "allow-log")
+
+ # aclKey: "a.*.b"
+ self.Lookup("uStar1@COMPANY", action, "exchange", "X", {"routingkey":"a.xx.b"}, "allow-log")
+ self.Lookup("uStar1@COMPANY", action, "exchange", "X", {"routingkey":"a.b"}, "deny-log")
+ # aclKey: "*.x"
+ self.Lookup("uStar2@COMPANY", action, "exchange", "X", {"routingkey":"y.x"}, "allow-log")
+ self.Lookup("uStar2@COMPANY", action, "exchange", "X", {"routingkey":".x"}, "allow-log")
+ self.Lookup("uStar2@COMPANY", action, "exchange", "X", {"routingkey":"x"}, "deny-log")
+ # aclKey: "x.x.*"
+ self.Lookup("uStar3@COMPANY", action, "exchange", "X", {"routingkey":"x.x.y"}, "allow-log")
+ self.Lookup("uStar3@COMPANY", action, "exchange", "X", {"routingkey":"x.x."}, "allow-log")
+ self.Lookup("uStar3@COMPANY", action, "exchange", "X", {"routingkey":"x.x"}, "deny-log")
+ self.Lookup("uStar3@COMPANY", action, "exchange", "X", {"routingkey":"q.x.y"}, "deny-log")
+
+ # aclKey: "a.#.b"
+ self.Lookup("uHash1@COMPANY", action, "exchange", "X", {"routingkey":"a.b"}, "allow-log")
+ self.Lookup("uHash1@COMPANY", action, "exchange", "X", {"routingkey":"a.x.b"}, "allow-log")
+ self.Lookup("uHash1@COMPANY", action, "exchange", "X", {"routingkey":"a..x.y.zz.b"}, "allow-log")
+ self.Lookup("uHash1@COMPANY", action, "exchange", "X", {"routingkey":"a.b."}, "deny-log")
+ self.Lookup("uHash1@COMPANY", action, "exchange", "X", {"routingkey":"q.x.b"}, "deny-log")
+
+ # aclKey: "a.#"
+ self.Lookup("uHash2@COMPANY", action, "exchange", "X", {"routingkey":"a"}, "allow-log")
+ self.Lookup("uHash2@COMPANY", action, "exchange", "X", {"routingkey":"a.b"}, "allow-log")
+ self.Lookup("uHash2@COMPANY", action, "exchange", "X", {"routingkey":"a.b.c"}, "allow-log")
+
+ # aclKey: "#.a"
+ self.Lookup("uHash3@COMPANY", action, "exchange", "X", {"routingkey":"a"}, "allow-log")
+ self.Lookup("uHash3@COMPANY", action, "exchange", "X", {"routingkey":"x.y.a"}, "allow-log")
+
+ # aclKey: "a.#.b.#.c"
+ self.Lookup("uHash4@COMPANY", action, "exchange", "X", {"routingkey":"a.b.c"}, "allow-log")
+ self.Lookup("uHash4@COMPANY", action, "exchange", "X", {"routingkey":"a.x.b.y.c"}, "allow-log")
+ self.Lookup("uHash4@COMPANY", action, "exchange", "X", {"routingkey":"a.x.x.b.y.y.c"}, "allow-log")
+
+ # aclKey: "*.x.#.y"
+ self.Lookup("uMixed1@COMPANY", action, "exchange", "X", {"routingkey":"a.x.y"}, "allow-log")
+ self.Lookup("uMixed1@COMPANY", action, "exchange", "X", {"routingkey":"a.x.p.qq.y"}, "allow-log")
+ self.Lookup("uMixed1@COMPANY", action, "exchange", "X", {"routingkey":"a.a.x.y"}, "deny-log")
+ self.Lookup("uMixed1@COMPANY", action, "exchange", "X", {"routingkey":"aa.x.b.c"}, "deny-log")
+
+ # aclKey: "a.#.b.*"
+ self.Lookup("uMixed2@COMPANY", action, "exchange", "X", {"routingkey":"a.b.x"}, "allow-log")
+ self.Lookup("uMixed2@COMPANY", action, "exchange", "X", {"routingkey":"a.x.x.x.b.x"}, "allow-log")
+
+ # aclKey: "*.*.*.#"
+ self.Lookup("uMixed3@COMPANY", action, "exchange", "X", {"routingkey":"x.y.z"}, "allow-log")
+ self.Lookup("uMixed3@COMPANY", action, "exchange", "X", {"routingkey":"x.y.z.a.b.c"}, "allow-log")
+ self.Lookup("uMixed3@COMPANY", action, "exchange", "X", {"routingkey":"x.y"}, "deny-log")
+ self.Lookup("uMixed3@COMPANY", action, "exchange", "X", {"routingkey":"x"}, "deny-log")
+
+ # Repeat the keys with wildcard user spec
+ self.Lookup("uPlain1@COMPANY", action, "exchange", "X", {"routingkey":"MN.OP.Q"}, "allow-log")
+ self.Lookup("uStar1@COMPANY" , action, "exchange", "X", {"routingkey":"M.xx.N"}, "allow-log")
+ self.Lookup("uHash1@COMPANY" , action, "exchange", "X", {"routingkey":"M.N"}, "allow-log")
+ self.Lookup("uHash1@COMPANY" , action, "exchange", "X", {"routingkey":"M.x.N"}, "allow-log")
+ self.Lookup("uHash1@COMPANY" , action, "exchange", "X", {"routingkey":"M..x.y.zz.N"}, "allow-log")
+ self.Lookup("uMixed1@COMPANY", action, "exchange", "X", {"routingkey":"a.M.N"}, "allow-log")
+ self.Lookup("uMixed1@COMPANY", action, "exchange", "X", {"routingkey":"a.M.p.qq.N"}, "allow-log")
+
+ self.Lookup("dev@QPID", action, "exchange", "X", {"routingkey": "MN.OP.Q"}, "allow-log")
+ self.Lookup("dev@QPID", action, "exchange", "X", {"routingkey": "M.xx.N"}, "allow-log")
+ self.Lookup("dev@QPID", action, "exchange", "X", {"routingkey": "M.N"}, "allow-log")
+ self.Lookup("dev@QPID", action, "exchange", "X", {"routingkey": "M.x.N"}, "allow-log")
+ self.Lookup("dev@QPID", action, "exchange", "X", {"routingkey": "M..x.y.zz.N"}, "allow-log")
+ self.Lookup("dev@QPID", action, "exchange", "X", {"routingkey": "a.M.N"}, "allow-log")
+ self.Lookup("dev@QPID", action, "exchange", "X", {"routingkey": "a.M.p.qq.N"}, "allow-log")
+
#=====================================
# Connection limits
#=====================================
- def test_connection_limits(self):
+ def test_connection_limits_cli_sets_all(self):
+
+ try:
+ sessiona1 = self.get_session_by_port('alice','alice', self.port_u())
+ sessiona2 = self.get_session_by_port('alice','alice', self.port_u())
+ except Exception, e:
+ self.fail("Could not create two connections for user alice: " + str(e))
+
+ # Third session should fail
+ try:
+ sessiona3 = self.get_session_by_port('alice','alice', self.port_u())
+ self.fail("Should not be able to create third connection for user alice")
+ except Exception, e:
+ result = None
+
+
+
+ def test_connection_limits_by_named_user(self):
"""
Test ACL control connection limits
"""
+ aclf = self.get_acl_file()
+ aclf.write('quota connections 2 alice bob\n')
+ aclf.write('quota connections 0 evildude\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ if (result):
+ self.fail(result)
+
# By username should be able to connect twice per user
try:
- sessiona1 = self.get_session_by_port('alice','alice', self.port_u())
- sessiona2 = self.get_session_by_port('alice','alice', self.port_u())
+ sessiona1 = self.get_session('alice','alice')
+ sessiona2 = self.get_session('alice','alice')
except Exception, e:
self.fail("Could not create two connections for user alice: " + str(e))
# Third session should fail
try:
- sessiona3 = self.get_session_by_port('alice','alice', self.port_u())
+ sessiona3 = self.get_session('alice','alice')
+ self.fail("Should not be able to create third connection for user alice")
+ except Exception, e:
+ result = None
+
+ # Disconnecting should allow another session.
+ sessiona1.close()
+ try:
+ sessiona3 = self.get_session('alice','alice')
+ except Exception, e:
+ self.fail("Could not recreate second connection for user alice: " + str(e))
+
+ # By username should be able to connect twice per user
+ try:
+ sessionb1 = self.get_session('bob','bob')
+ sessionb2 = self.get_session('bob','bob')
+ except Exception, e:
+ self.fail("Could not create two connections for user bob: " + str(e))
+
+ # Third session should fail
+ try:
+ sessionb3 = self.get_session('bob','bob')
+ self.fail("Should not be able to create third connection for user bob")
+ except Exception, e:
+ result = None
+
+
+ # User with quota of 0 is denied
+ try:
+ sessione1 = self.get_session('evildude','evildude')
+ self.fail("Should not be able to create a connection for user evildude")
+ except Exception, e:
+ result = None
+
+
+ # User not named in quotas is denied
+ try:
+ sessionc1 = self.get_session('charlie','charlie')
+ self.fail("Should not be able to create a connection for user charlie")
+ except Exception, e:
+ result = None
+
+ # Clean up the sessions
+ sessiona2.close()
+ sessiona3.close()
+ sessionb1.close()
+ sessionb2.close()
+
+
+
+ def test_connection_limits_by_unnamed_all(self):
+ """
+ Test ACL control connection limits
+ """
+ aclf = self.get_acl_file()
+ aclf.write('quota connections 2 alice bob\n')
+ aclf.write('quota connections 1 all\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ if (result):
+ self.fail(result)
+
+ # By username should be able to connect twice per user
+ try:
+ sessiona1 = self.get_session('alice','alice')
+ sessiona2 = self.get_session('alice','alice')
+ except Exception, e:
+ self.fail("Could not create two connections for user alice: " + str(e))
+
+ # Third session should fail
+ try:
+ sessiona3 = self.get_session('alice','alice')
self.fail("Should not be able to create third connection for user alice")
except Exception, e:
result = None
+ # By username should be able to connect twice per user
try:
- sessionb1 = self.get_session_by_port('bob','bob', self.port_u())
- sessionb2 = self.get_session_by_port('bob','bob', self.port_u())
+ sessionb1 = self.get_session('bob','bob')
+ sessionb2 = self.get_session('bob','bob')
except Exception, e:
self.fail("Could not create two connections for user bob: " + str(e))
+ # Third session should fail
try:
- sessionb3 = self.get_session_by_port('bob','bob', self.port_u())
+ sessionb3 = self.get_session('bob','bob')
self.fail("Should not be able to create third connection for user bob")
except Exception, e:
result = None
+ # User not named in quotas gets 'all' quota
+ try:
+ sessionc1 = self.get_session('charlie','charlie')
+ except Exception, e:
+ self.fail("Could not create one connection for user charlie: " + str(e))
+
+ # Next session should fail
+ try:
+ sessionc2 = self.get_session('charlie','charlie')
+ self.fail("Should not be able to create second connection for user charlie")
+ except Exception, e:
+ result = None
+
+ # Clean up the sessions
+ sessiona1.close()
+ sessiona2.close()
+ sessionb1.close()
+ sessionb2.close()
+ sessionc1.close()
+
+
+ def test_connection_limits_by_group(self):
+ """
+ Test ACL control connection limits
+ """
+ aclf = self.get_acl_file()
+ aclf.write('group stooges moe@QPID larry@QPID curly@QPID\n')
+ aclf.write('quota connections 2 alice bob\n')
+ aclf.write('quota connections 2 stooges charlie\n')
+ aclf.write('# user and groups may be overwritten. Should use last value\n')
+ aclf.write('quota connections 3 bob stooges\n')
+ aclf.write('acl allow all all')
+ aclf.close()
+
+ result = self.reload_acl()
+ if (result):
+ self.fail(result)
+
+ # Alice gets 2
+ try:
+ sessiona1 = self.get_session('alice','alice')
+ sessiona2 = self.get_session('alice','alice')
+ except Exception, e:
+ self.fail("Could not create two connections for user alice: " + str(e))
+
+ # Third session should fail
+ try:
+ sessiona3 = self.get_session('alice','alice')
+ self.fail("Should not be able to create third connection for user alice")
+ except Exception, e:
+ result = None
+
+ # Bob gets 3
+ try:
+ sessionb1 = self.get_session('bob','bob')
+ sessionb2 = self.get_session('bob','bob')
+ sessionb3 = self.get_session('bob','bob')
+ except Exception, e:
+ self.fail("Could not create three connections for user bob: " + str(e))
+
+ # Fourth session should fail
+ try:
+ sessionb4 = self.get_session('bob','bob')
+ self.fail("Should not be able to create fourth connection for user bob")
+ except Exception, e:
+ result = None
+
+ # Moe gets 3
+ try:
+ sessionm1 = self.get_session('moe','moe')
+ sessionm2 = self.get_session('moe','moe')
+ sessionm3 = self.get_session('moe','moe')
+ except Exception, e:
+ self.fail("Could not create three connections for user moe: " + str(e))
+
+ # Fourth session should fail
+ try:
+ sessionb4 = self.get_session('moe','moe')
+ self.fail("Should not be able to create fourth connection for user ,pe")
+ except Exception, e:
+ result = None
+
+ # User not named in quotas is denied
+ try:
+ sessions1 = self.get_session('shemp','shemp')
+ self.fail("Should not be able to create a connection for user shemp")
+ except Exception, e:
+ result = None
+
+ # Clean up the sessions
+ sessiona1.close()
+ sessiona2.close()
+ sessionb1.close()
+ sessionb2.close()
+ sessionb3.close()
+ sessionm1.close()
+ sessionm2.close()
+ sessionm3.close()
+
+
+ def test_connection_limits_by_ip_address(self):
+ """
+ Test ACL control connection limits by ip address
+ """
# By IP address should be able to connect twice per client address
try:
sessionb1 = self.get_session_by_port('alice','alice', self.port_i())
@@ -1703,6 +2315,8 @@ class ACLTests(TestBase010):
except Exception, e:
result = None
+ sessionb1.close()
+ sessionb2.close()
#=====================================
# User name substitution
@@ -2243,6 +2857,62 @@ class ACLTests(TestBase010):
self.LookupPublish("joe@QPID", "QPID-work", "QPID", "allow")
self.LookupPublish("joe@QPID", "QPID-work2", "QPID", "allow")
+ #=====================================
+ # Queue per-user quota
+ #=====================================
+
+ def test_queue_per_user_quota(self):
+ """
+ Test ACL queue counting limits.
+ port_q has a limit of 2
+ """
+ # bob should be able to create two queues
+ session = self.get_session_by_port('bob','bob', self.port_q())
+
+ try:
+ session.queue_declare(queue="queue1")
+ session.queue_declare(queue="queue2")
+ except qpid.session.SessionException, e:
+ self.fail("Error during queue create request");
+
+ # third queue should fail
+ try:
+ session.queue_declare(queue="queue3")
+ self.fail("Should not be able to create third queue")
+ except Exception, e:
+ result = None
+ session = self.get_session_by_port('bob','bob', self.port_q())
+
+ # alice should be able to create two queues
+ session2 = self.get_session_by_port('alice','alice', self.port_q())
+
+ try:
+ session2.queue_declare(queue="queuea1")
+ session2.queue_declare(queue="queuea2")
+ except qpid.session.SessionException, e:
+ self.fail("Error during queue create request");
+
+ # third queue should fail
+ try:
+ session2.queue_declare(queue="queuea3")
+ self.fail("Should not be able to create third queue")
+ except Exception, e:
+ result = None
+ session2 = self.get_session_by_port('alice','alice', self.port_q())
+
+ # bob should be able to delete a queue and create another
+ try:
+ session.queue_delete(queue="queue1")
+ session.queue_declare(queue="queue3")
+ except qpid.session.SessionException, e:
+ self.fail("Error during queue create request");
+
+ # alice should be able to delete a queue and create another
+ try:
+ session2.queue_delete(queue="queuea1")
+ session2.queue_declare(queue="queuea3")
+ except qpid.session.SessionException, e:
+ self.fail("Error during queue create request");
class BrokerAdmin:
def __init__(self, broker, username=None, password=None):
diff --git a/cpp/src/tests/benchmark b/cpp/src/tests/benchmark
deleted file mode 100755
index c075837847..0000000000
--- a/cpp/src/tests/benchmark
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/bin/sh
-#
-# 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.
-#
-# A basic "benchmark" to generate performacne samples of throughput
-# and latency against a single cluster member while they are replicating.
-#
-# Must be run in the qpid src/tests build directory.
-#
-
-usage() {
-cat <<EOF
-Usage: $0 [options] -- client hosts --- broker hosts
-Read the script for options.
-EOF
-}
-# Defaults
-TESTDIR=${TESTDIR:-$PWD} # Absolute path to test exes on all hosts.
-SCRIPTDIR=${SCRIPTDIR:-`dirname $0`} # Path to local test scripts directory.
-SAMPLES=10 # Runs of each test.
-COUNT=${COUNT:-10000} # Count for pub/sub tests.
-SIZE=${SIZE:-600} # Size of messages
-ECHO=${ECHO:-1000} # Count for echo test.
-NSUBS=${NSUBS:-4}
-NPUBS=${NPUBS:-4}
-
-collect() { eval $COLLECT=\""\$$COLLECT $*"\"; }
-COLLECT=ARGS
-while test $# -gt 0; do
- case $1 in
- --testdir) TESTDIR=$2 ; shift 2 ;;
- --samples) SAMPLES=$2 ; shift 2 ;;
- --count) COUNT=$2 ; shift 2 ;;
- --echos) ECHO=$2 ; shift 2 ;;
- --size) SIZE=$2 ; shift 2 ;;
- --nsubs) NSUBS=$2 ; shift 2 ;;
- --npubs) NPUBS=$2 ; shift 2 ;;
- --) COLLECT=CLIENTARG; shift ;;
- ---) COLLECT=BROKERARG; shift;;
- *) collect $1; shift ;;
- esac
-done
-
-CLIENTS=${CLIENTARG:-$CLIENTS}
-BROKERS=${BROKERARG:-$BROKERS}
-test -z "$CLIENTS" && { echo "Must specify at least one client host."; exit 1; }
-test -z "$BROKERS" && { echo "Must specify at least one broker host."; exit 1; }
-
-export TESTDIR # For perfdist
-CLIENTS=($CLIENTS) # Convert to array
-BROKERS=($BROKERS)
-trap "rm -f $FILES" EXIT
-
-dosamples() {
- FILE=`mktemp`
- FILES="$FILES $FILE"
- TABS=`echo "$HEADING" | sed s'/[^ ]//g'`
- {
- echo "\"$*\"$TABS"
- echo "$HEADING"
- for (( i=0; i<$SAMPLES; ++i)) ; do echo "`$*`" ; done
- echo
- } | tee $FILE
-}
-
-HEADING="pub sub total Mb"
-dosamples $SCRIPTDIR/perfdist --size $SIZE --count $COUNT --nsubs $NSUBS --npubs $NPUBS -s -- ${CLIENTS[*]} --- ${BROKERS[*]}
-HEADING="pub"
-dosamples ssh -A ${CLIENTS[0]} $TESTDIR/publish --routing-key perftest0 --size $SIZE --count $COUNT -s -b ${BROKERS[0]}
-HEADING="sub"
-dosamples ssh -A ${CLIENTS[0]} $TESTDIR/consume --queue perftest0 -s --count $COUNT -b ${BROKERS[0]}
-HEADING="min max avg"
-dosamples ssh -A ${CLIENTS[0]} $TESTDIR/echotest --count $ECHO -s -b ${BROKERS[0]}
-
-echo
-echo "Tab separated spreadsheet (also saved as benchmark.tab):"
-echo
-
-echo "benchmark -- ${CLIENTS[*]} --- ${BROKERS[*]} " | tee benchmark.tab
-paste $FILES | tee -a benchmark.tab
diff --git a/cpp/src/tests/brokertest.py b/cpp/src/tests/brokertest.py
index aea4460e5a..70c145a51b 100644
--- a/cpp/src/tests/brokertest.py
+++ b/cpp/src/tests/brokertest.py
@@ -17,8 +17,7 @@
# under the License.
#
-# Support library for tests that start multiple brokers, e.g. cluster
-# or federation
+# Support library for tests that start multiple brokers, e.g. HA or federation
import os, signal, string, tempfile, subprocess, socket, threading, time, imp, re
import qpid, traceback, signal
@@ -203,8 +202,10 @@ class Popen(subprocess.Popen):
self.wait()
def kill(self):
- try:
- subprocess.Popen.kill(self)
+ # Set to EXPECT_UNKNOWN, EXPECT_EXIT_FAIL creates a race condition
+ # if the process exits normally concurrent with the call to kill.
+ self.expect = EXPECT_UNKNOWN
+ try: subprocess.Popen.kill(self)
except AttributeError: # No terminate method
try:
os.kill( self.pid , signal.SIGKILL)
@@ -380,8 +381,7 @@ class Broker(Popen):
if not retry(self.log_ready, timeout=timeout):
raise Exception(
"Timed out waiting for broker %s%s"%(self.name, error_line(self.log,5)))
- # Create a connection and a session. For a cluster broker this will
- # return after cluster init has finished.
+ # Create a connection and a session.
try:
c = self.connect(**kwargs)
try: c.session()
@@ -389,54 +389,6 @@ class Broker(Popen):
except Exception,e: raise RethrownException(
"Broker %s not responding: (%s)%s"%(self.name,e,error_line(self.log, 5)))
- def store_state(self):
- f = open(os.path.join(self.datadir, "cluster", "store.status"))
- try: uuids = f.readlines()
- finally: f.close()
- null_uuid="00000000-0000-0000-0000-000000000000\n"
- if len(uuids) < 2: return "unknown" # we looked while the file was being updated.
- if uuids[0] == null_uuid: return "empty"
- if uuids[1] == null_uuid: return "dirty"
- return "clean"
-
-class Cluster:
- """A cluster of brokers in a test."""
- # Client connection options for use in failover tests.
- CONNECTION_OPTIONS = "reconnect:true,reconnect-timeout:10,reconnect-urls-replace:true"
-
- _cluster_count = 0
-
- def __init__(self, test, count=0, args=[], expect=EXPECT_RUNNING, wait=True, show_cmd=False):
- self.test = test
- self._brokers=[]
- self.name = "cluster%d" % Cluster._cluster_count
- Cluster._cluster_count += 1
- # Use unique cluster name
- self.args = copy(args)
- self.args += [ "--cluster-name", "%s-%s:%d" % (self.name, socket.gethostname(), os.getpid()) ]
- self.args += [ "--log-enable=info+", "--log-enable=debug+:cluster"]
- assert BrokerTest.cluster_lib, "Cannot locate cluster plug-in"
- self.args += [ "--load-module", BrokerTest.cluster_lib ]
- self.start_n(count, expect=expect, wait=wait, show_cmd=show_cmd)
-
- def start(self, name=None, expect=EXPECT_RUNNING, wait=True, args=[], port=0, show_cmd=False):
- """Add a broker to the cluster. Returns the index of the new broker."""
- if not name: name="%s-%d" % (self.name, len(self._brokers))
- self._brokers.append(self.test.broker(self.args+args, name, expect, wait, port=port, show_cmd=show_cmd))
- return self._brokers[-1]
-
- def ready(self):
- for b in self: b.ready()
-
- def start_n(self, count, expect=EXPECT_RUNNING, wait=True, args=[], show_cmd=False):
- for i in range(count): self.start(expect=expect, wait=wait, args=args, show_cmd=show_cmd)
-
- # Behave like a list of brokers.
- def __len__(self): return len(self._brokers)
- def __getitem__(self,index): return self._brokers[index]
- def __iter__(self): return self._brokers.__iter__()
-
-
def browse(session, queue, timeout=0, transform=lambda m: m.content):
"""Return a list with the contents of each message on queue."""
r = session.receiver("%s;{mode:browse}"%(queue))
@@ -473,7 +425,6 @@ class BrokerTest(TestCase):
# Environment settings.
qpidd_exec = os.path.abspath(checkenv("QPIDD_EXEC"))
- cluster_lib = os.getenv("CLUSTER_LIB")
ha_lib = os.getenv("HA_LIB")
xml_lib = os.getenv("XML_LIB")
qpid_config_exec = os.getenv("QPID_CONFIG_EXEC")
@@ -525,11 +476,6 @@ class BrokerTest(TestCase):
raise RethrownException("Failed to start broker %s(%s): %s" % (b.name, b.log, e))
return b
- def cluster(self, count=0, args=[], expect=EXPECT_RUNNING, wait=True, show_cmd=False):
- """Create and return a cluster ready for use"""
- cluster = Cluster(self, count, args, expect=expect, wait=wait, show_cmd=show_cmd)
- return cluster
-
def browse(self, *args, **kwargs): browse(*args, **kwargs)
def assert_browse(self, *args, **kwargs): assert_browse(*args, **kwargs)
def assert_browse_retry(self, *args, **kwargs): assert_browse_retry(*args, **kwargs)
@@ -558,14 +504,17 @@ class StoppableThread(Thread):
join(self)
if self.error: raise self.error
+# Options for a client that wants to reconnect automatically.
+RECONNECT_OPTIONS="reconnect:true,reconnect-timeout:10,reconnect-urls-replace:true"
+
class NumberedSender(Thread):
"""
Thread to run a sender client and send numbered messages until stopped.
"""
def __init__(self, broker, max_depth=None, queue="test-queue",
- connection_options=Cluster.CONNECTION_OPTIONS,
- failover_updates=True, url=None):
+ connection_options=RECONNECT_OPTIONS,
+ failover_updates=True, url=None, args=[]):
"""
max_depth: enable flow control, ensure sent - received <= max_depth.
Requires self.notify_received(n) to be called each time messages are received.
@@ -576,7 +525,7 @@ class NumberedSender(Thread):
"--address", "%s;{create:always}"%queue,
"--connection-options", "{%s}"%(connection_options),
"--content-stdin"
- ]
+ ] + args
if failover_updates: cmd += ["--failover-updates"]
self.sender = broker.test.popen(
cmd, expect=EXPECT_RUNNING, stdin=PIPE)
@@ -627,7 +576,7 @@ class NumberedReceiver(Thread):
sequentially numbered messages.
"""
def __init__(self, broker, sender=None, queue="test-queue",
- connection_options=Cluster.CONNECTION_OPTIONS,
+ connection_options=RECONNECT_OPTIONS,
failover_updates=True, url=None):
"""
sender: enable flow control. Call sender.received(n) for each message received.
@@ -676,31 +625,6 @@ class NumberedReceiver(Thread):
join(self)
self.check()
-class ErrorGenerator(StoppableThread):
- """
- Thread that continuously generates errors by trying to consume from
- a non-existent queue. For cluster regression tests, error handling
- caused issues in the past.
- """
-
- def __init__(self, broker):
- StoppableThread.__init__(self)
- self.broker=broker
- broker.test.cleanup_stop(self)
- self.start()
-
- def run(self):
- c = self.broker.connect_old()
- try:
- while not self.stopped:
- try:
- c.session(str(qpid.datatypes.uuid4())).message_subscribe(
- queue="non-existent-queue")
- assert(False)
- except qpid.session.SessionException: pass
- time.sleep(0.01)
- except: pass # Normal if broker is killed.
-
def import_script(path):
"""
Import executable script at path as a module.
diff --git a/cpp/src/tests/cluster_authentication_soak.cpp b/cpp/src/tests/cluster_authentication_soak.cpp
deleted file mode 100644
index a3271701c3..0000000000
--- a/cpp/src/tests/cluster_authentication_soak.cpp
+++ /dev/null
@@ -1,310 +0,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.
- *
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-
-#include <sys/wait.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include <string>
-#include <iostream>
-#include <sstream>
-#include <vector>
-
-#include <boost/assign.hpp>
-
-#include "qpid/framing/Uuid.h"
-
-#include <ForkedBroker.h>
-#include <qpid/client/Connection.h>
-
-#include <sasl/sasl.h>
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-
-
-
-using namespace std;
-using boost::assign::list_of;
-using namespace qpid::framing;
-using namespace qpid::client;
-
-
-namespace qpid {
-namespace tests {
-
-vector<pid_t> brokerPids;
-
-typedef vector<ForkedBroker *> brokerVector;
-
-
-
-
-
-int runSilent = 1;
-int newbiePort = 0;
-
-
-void
-makeClusterName ( string & s ) {
- stringstream ss;
- ss << "authenticationSoakCluster_" << Uuid(true).str();
- s = ss.str();
-}
-
-
-
-void
-startBroker ( brokerVector & brokers , int brokerNumber, string const & clusterName ) {
- stringstream prefix, clusterArg;
- prefix << "soak-" << brokerNumber;
- clusterArg << "--cluster-name=" << clusterName;
-
- std::vector<std::string> argv;
-
- argv.push_back ("../qpidd");
- argv.push_back ("--no-module-dir");
- argv.push_back ("--load-module=../.libs/cluster.so");
- argv.push_back (clusterArg.str());
- argv.push_back ("--cluster-username=zig");
- argv.push_back ("--cluster-password=zig");
- argv.push_back ("--cluster-mechanism=PLAIN");
- argv.push_back ("--sasl-config=./sasl_config");
- argv.push_back ("--auth=yes");
- argv.push_back ("--mgmt-enable=yes");
- argv.push_back ("--log-prefix");
- argv.push_back (prefix.str());
- argv.push_back ("--log-to-file");
- argv.push_back (prefix.str()+".log");
- argv.push_back ("TMP_DATA_DIR");
-
- ForkedBroker * newbie = new ForkedBroker (argv);
- newbiePort = newbie->getPort();
- brokers.push_back ( newbie );
-}
-
-
-
-
-bool
-runPerftest ( bool hangTest ) {
- stringstream portSs;
- portSs << newbiePort;
- string portStr = portSs.str();
- char const * path = "./qpid-perftest";
-
- vector<char const *> argv;
- argv.push_back ( "./qpid-perftest" );
- argv.push_back ( "-p" );
- argv.push_back ( portStr.c_str() );
- argv.push_back ( "--username" );
- argv.push_back ( "zig" );
- argv.push_back ( "--password" );
- argv.push_back ( "zig" );
- argv.push_back ( "--mechanism" );
- argv.push_back ( "DIGEST-MD5" );
- argv.push_back ( "--count" );
- argv.push_back ( "20000" );
- argv.push_back ( 0 );
-
- pid_t pid = fork();
-
- if ( ! pid ) {
- int i=open("/dev/null",O_RDWR);
- dup2 ( i, fileno(stdout) );
- dup2 ( i, fileno(stderr) );
-
- execv ( path, const_cast<char * const *>(&argv[0]) );
- // The exec failed: we are still in parent process.
- perror ( "error running qpid-perftest: " );
- return false;
- }
- else {
- if ( hangTest ) {
- if ( ! runSilent )
- cerr << "Pausing perftest " << pid << endl;
- kill ( pid, 19 );
- }
-
- struct timeval startTime,
- currentTime,
- duration;
-
- gettimeofday ( & startTime, 0 );
-
- while ( 1 ) {
- sleep ( 2 );
- int status;
- int returned_pid = waitpid ( pid, &status, WNOHANG );
- if ( returned_pid == pid ) {
- int exit_status = WEXITSTATUS(status);
- if ( exit_status ) {
- cerr << "qpid-perftest failed. exit_status was: " << exit_status << endl;
- return false;
- }
- else {
- return true; // qpid-perftest succeeded.
- }
- }
- else { // qpid-perftest has not yet completed.
- gettimeofday ( & currentTime, 0 );
- timersub ( & currentTime, & startTime, & duration );
- if ( duration.tv_sec > 60 ) {
- kill ( pid, 9 );
- cerr << "qpid-perftest pid " << pid << " hanging: killed.\n";
- return false;
- }
- }
- }
-
- }
-}
-
-
-
-bool
-allBrokersAreAlive ( brokerVector & brokers ) {
- for ( unsigned int i = 0; i < brokers.size(); ++ i )
- if ( ! brokers[i]->isRunning() )
- return false;
-
- return true;
-}
-
-
-
-
-
-void
-killAllBrokers ( brokerVector & brokers ) {
- for ( unsigned int i = 0; i < brokers.size(); ++ i ) {
- brokers[i]->kill ( 9 );
- }
-}
-
-
-
-
-void
-killOneBroker ( brokerVector & brokers ) {
- int doomedBroker = getpid() % brokers.size();
- cout << "Killing broker " << brokers[doomedBroker]->getPID() << endl;
- brokers[doomedBroker]->kill ( 9 );
- sleep ( 2 );
-}
-
-
-
-
-}} // namespace qpid::tests
-
-using namespace qpid::tests;
-
-
-
-/*
- * Please note that this test has self-test capability.
- * It is intended to detect
- * 1. perftest hangs.
- * 2. broker deaths
- * Both of these condtions can be forced when running manually
- * to ensure that the test really does detect them.
- * See command-line arguments 3 and 4.
- */
-int
-main ( int argc, char ** argv )
-{
- // I need the SASL_PATH_TYPE_CONFIG feature, which did not appear until SASL 2.1.22
-#if (SASL_VERSION_FULL < ((2<<16)|(1<<8)|22))
- cout << "Skipping SASL test, SASL version too low." << endl;
- return 0;
-#endif
-
- int n_iterations = argc > 1 ? atoi(argv[1]) : 1;
- runSilent = argc > 2 ? atoi(argv[2]) : 1; // default to silent
- int killBroker = argc > 3 ? atoi(argv[3]) : 0; // Force the kill of one broker.
- int hangTest = argc > 4 ? atoi(argv[4]) : 0; // Force the first perftest to hang.
- int n_brokers = 3;
- brokerVector brokers;
-
- srand ( getpid() );
- string clusterName;
- makeClusterName ( clusterName );
- for ( int i = 0; i < n_brokers; ++ i ) {
- startBroker ( brokers, i, clusterName );
- }
-
- sleep ( 3 );
-
- /* Run all qpid-perftest iterations, and only then check for brokers
- * still being up. If you just want a quick check for the failure
- * mode in which a single iteration would kill all brokers except
- * the client-connected one, just run it with the iterations arg
- * set to 1.
- */
- for ( int iteration = 0; iteration < n_iterations; ++ iteration ) {
- if ( ! runPerftest ( hangTest ) ) {
- if ( ! runSilent )
- cerr << "qpid-perftest " << iteration << " failed.\n";
- return 1;
- }
- if ( ! ( iteration % 10 ) ) {
- if ( ! runSilent )
- cerr << "qpid-perftest " << iteration << " complete. -------------- \n";
- }
- }
- if ( ! runSilent )
- cerr << "\nqpid-perftest " << n_iterations << " iterations complete. -------------- \n\n";
-
- /* If the command-line tells us to kill a broker, do
- * it now. Use this option to prove that this test
- * really can detect broker-deaths.
- */
- if ( killBroker ) {
- killOneBroker ( brokers );
- }
-
- if ( ! allBrokersAreAlive ( brokers ) ) {
- if ( ! runSilent )
- cerr << "not all brokers are alive.\n";
- killAllBrokers ( brokers );
- return 2;
- }
-
- killAllBrokers ( brokers );
- if ( ! runSilent )
- cout << "success.\n";
-
- return 0;
-}
-
-
-
diff --git a/cpp/src/tests/cluster_failover b/cpp/src/tests/cluster_failover
deleted file mode 100755
index 43170c731a..0000000000
--- a/cpp/src/tests/cluster_failover
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/sh
-# A simple manual failover test, sends a stream of numbered messages.
-# You can kill the connected broker and verify that the clients reconnect
-# and no messages are lost.
-
-URL=$1
-test -n "$URL" || { echo Usage: $0 URL ; exit 1; }
-SEND=$(mktemp /tmp/send.XXXXXXXXXX)
-RECV=$(mktemp /tmp/recv.XXXXXXXXXX)
-echo $SEND $RECV
-
-seq 1000000 > $SEND
-
-qpid-send -a 'cluster_failover;{create:always}' -b $URL --connection-options "{reconnect:true}" --send-rate 10 --content-stdin < $SEND &
-
-while msg=$(qpid-receive -m1 -f -a 'cluster_failover;{create:always}' -b $URL --connection-options "{reconnect:true,heartbeat:1}"); do
- echo -n $msg; date
-done
-wait
diff --git a/cpp/src/tests/cluster_python_tests b/cpp/src/tests/cluster_python_tests
deleted file mode 100755
index 25c7889246..0000000000
--- a/cpp/src/tests/cluster_python_tests
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/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.
-#
-
-# Skip if cluster services not running.
-. cpg_check.sh
-cpg_enabled || exit 0
-
-FAILING=`dirname $0`/cluster_python_tests_failing.txt
-source `dirname $0`/python_tests
-
diff --git a/cpp/src/tests/cluster_python_tests_failing.txt b/cpp/src/tests/cluster_python_tests_failing.txt
deleted file mode 100644
index f8639d7b59..0000000000
--- a/cpp/src/tests/cluster_python_tests_failing.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-qpid_tests.broker_0_10.management.ManagementTest.test_purge_queue
-qpid_tests.broker_0_10.management.ManagementTest.test_connection_close
-qpid_tests.broker_0_10.message.MessageTests.test_ttl
-qpid_tests.broker_0_10.management.ManagementTest.test_broker_connectivity_oldAPI
diff --git a/cpp/src/tests/cluster_read_credit b/cpp/src/tests/cluster_read_credit
deleted file mode 100755
index 552ffee53b..0000000000
--- a/cpp/src/tests/cluster_read_credit
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/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.
-#
-
-# Regression test for http://issues.apache.org/jira/browse/QPID-2086
-
-srcdir=`dirname $0`
-source cpg_check.sh
-cpg_enabled || exit 0
-
-$srcdir/start_cluster 1 --cluster-read-max=2 || exit 1
-trap $srcdir/stop_cluster EXIT
-seq 1 10000 | ./sender --port `cat cluster.ports` --routing-key no-such-queue
diff --git a/cpp/src/tests/cluster_test.cpp b/cpp/src/tests/cluster_test.cpp
deleted file mode 100644
index f2ccd0ba84..0000000000
--- a/cpp/src/tests/cluster_test.cpp
+++ /dev/null
@@ -1,1231 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * 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.
- *
- */
-
-#include "test_tools.h"
-#include "unit_test.h"
-#include "ForkedBroker.h"
-#include "BrokerFixture.h"
-#include "ClusterFixture.h"
-
-#include "qpid/client/Connection.h"
-#include "qpid/client/ConnectionSettings.h"
-#include "qpid/client/ConnectionAccess.h"
-#include "qpid/client/Session.h"
-#include "qpid/client/FailoverListener.h"
-#include "qpid/client/FailoverManager.h"
-#include "qpid/client/QueueOptions.h"
-#include "qpid/cluster/Cluster.h"
-#include "qpid/cluster/Cpg.h"
-#include "qpid/cluster/UpdateClient.h"
-#include "qpid/framing/AMQBody.h"
-#include "qpid/framing/Uuid.h"
-#include "qpid/framing/reply_exceptions.h"
-#include "qpid/framing/enum.h"
-#include "qpid/framing/MessageTransferBody.h"
-#include "qpid/log/Logger.h"
-#include "qpid/sys/Monitor.h"
-#include "qpid/sys/Thread.h"
-
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/assign.hpp>
-
-#include <string>
-#include <iostream>
-#include <fstream>
-#include <iterator>
-#include <vector>
-#include <set>
-#include <algorithm>
-#include <iterator>
-
-
-using namespace std;
-using namespace qpid;
-using namespace qpid::cluster;
-using namespace qpid::framing;
-using namespace qpid::client;
-using namespace boost::assign;
-using broker::Broker;
-using boost::shared_ptr;
-
-namespace qpid {
-namespace tests {
-
-QPID_AUTO_TEST_SUITE(cluster_test)
-
-bool durableFlag = std::getenv("STORE_LIB") != 0;
-
-void prepareArgs(ClusterFixture::Args& args, const bool durableFlag = false) {
- ostringstream clusterLib;
- clusterLib << getLibPath("CLUSTER_LIB");
- args += "--auth", "no", "--no-module-dir", "--load-module", clusterLib.str();
- if (durableFlag)
- args += "--load-module", getLibPath("STORE_LIB"), "TMP_DATA_DIR";
- else
- args += "--no-data-dir";
-}
-
-ClusterFixture::Args prepareArgs(const bool durableFlag = false) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- return args;
-}
-
-// Timeout for tests that wait for messages
-const sys::Duration TIMEOUT=2*sys::TIME_SEC;
-
-
-ostream& operator<<(ostream& o, const cpg_name* n) {
- return o << Cpg::str(*n);
-}
-
-ostream& operator<<(ostream& o, const cpg_address& a) {
- return o << "(" << a.nodeid <<","<<a.pid<<","<<a.reason<<")";
-}
-
-template <class T>
-ostream& operator<<(ostream& o, const pair<T*, int>& array) {
- o << "{ ";
- ostream_iterator<cpg_address> i(o, " ");
- copy(array.first, array.first+array.second, i);
- o << "}";
- return o;
-}
-
-template <class C> set<int> makeSet(const C& c) {
- set<int> s;
- copy(c.begin(), c.end(), inserter(s, s.begin()));
- return s;
-}
-
-class Sender {
- public:
- Sender(boost::shared_ptr<ConnectionImpl> ci, uint16_t ch) : connection(ci), channel(ch) {}
- void send(const AMQBody& body, bool firstSeg, bool lastSeg, bool firstFrame, bool lastFrame) {
- AMQFrame f(body);
- f.setChannel(channel);
- f.setFirstSegment(firstSeg);
- f.setLastSegment(lastSeg);
- f.setFirstFrame(firstFrame);
- f.setLastFrame(lastFrame);
- connection->expand(f.encodedSize(), false);
- connection->handle(f);
- }
-
- private:
- boost::shared_ptr<ConnectionImpl> connection;
- uint16_t channel;
-};
-
-int64_t getMsgSequence(const Message& m) {
- return m.getMessageProperties().getApplicationHeaders().getAsInt64("qpid.msg_sequence");
-}
-
-Message ttlMessage(const string& data, const string& key, uint64_t ttl, bool durable = false) {
- Message m(data, key);
- m.getDeliveryProperties().setTtl(ttl);
- if (durable) m.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT);
- return m;
-}
-
-Message makeMessage(const string& data, const string& key, bool durable = false) {
- Message m(data, key);
- if (durable) m.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT);
- return m;
-}
-
-vector<string> browse(Client& c, const string& q, int n) {
- SubscriptionSettings browseSettings(
- FlowControl::messageCredit(n),
- ACCEPT_MODE_NONE,
- ACQUIRE_MODE_NOT_ACQUIRED,
- 0 // No auto-ack.
- );
- LocalQueue lq;
- c.subs.subscribe(lq, q, browseSettings);
- c.session.messageFlush(q);
- vector<string> result;
- for (int i = 0; i < n; ++i) {
- Message m;
- if (!lq.get(m, TIMEOUT))
- break;
- result.push_back(m.getData());
- }
- c.subs.getSubscription(q).cancel();
- return result;
-}
-
-ConnectionSettings aclSettings(int port, const std::string& id) {
- ConnectionSettings settings;
- settings.port = port;
- settings.mechanism = "PLAIN";
- settings.username = id;
- settings.password = id;
- return settings;
-}
-
-// An illegal frame body
-struct PoisonPill : public AMQBody {
- virtual uint8_t type() const { return 0xFF; }
- virtual void encode(Buffer& ) const {}
- virtual void decode(Buffer& , uint32_t=0) {}
- virtual uint32_t encodedSize() const { return 0; }
-
- virtual void print(std::ostream&) const {};
- virtual void accept(AMQBodyConstVisitor&) const {};
-
- virtual AMQMethodBody* getMethod() { return 0; }
- virtual const AMQMethodBody* getMethod() const { return 0; }
-
- /** Match if same type and same class/method ID for methods */
- static bool match(const AMQBody& , const AMQBody& ) { return false; }
- virtual boost::intrusive_ptr<AMQBody> clone() const { return new PoisonPill; }
-};
-
-QPID_AUTO_TEST_CASE(testBadClientData) {
- // Ensure that bad data on a client connection closes the
- // connection but does not stop the broker.
- ClusterFixture::Args args;
- prepareArgs(args, false);
- args += "--log-enable=critical"; // Supress expected errors
- ClusterFixture cluster(2, args, -1);
- Client c0(cluster[0]);
- Client c1(cluster[1]);
- boost::shared_ptr<client::ConnectionImpl> ci =
- client::ConnectionAccess::getImpl(c0.connection);
- AMQFrame poison(boost::intrusive_ptr<AMQBody>(new PoisonPill));
- ci->expand(poison.encodedSize(), false);
- ci->handle(poison);
- {
- ScopedSuppressLogging sl;
- BOOST_CHECK_THROW(c0.session.queueQuery("q0"), Exception);
- }
- Client c00(cluster[0]);
- BOOST_CHECK_EQUAL(c00.session.queueQuery("q00").getQueue(), "");
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q1").getQueue(), "");
-}
-
-QPID_AUTO_TEST_CASE(testAcl) {
- ofstream policyFile("cluster_test.acl");
- policyFile << "acl allow foo@QPID create queue name=foo" << endl
- << "acl allow foo@QPID create queue name=foo2" << endl
- << "acl deny foo@QPID create queue name=bar" << endl
- << "acl allow all all" << endl;
- policyFile.close();
- char cwd[1024];
- BOOST_CHECK(::getcwd(cwd, sizeof(cwd)));
- ostringstream aclLib;
- aclLib << getLibPath("ACL_LIB");
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- args += "--log-enable=critical"; // Supress expected errors
- args += "--acl-file", string(cwd) + "/cluster_test.acl",
- "--cluster-mechanism", "PLAIN",
- "--cluster-username", "cluster",
- "--cluster-password", "cluster",
- "--load-module", aclLib.str();
- ClusterFixture cluster(2, args, -1);
-
- Client c0(aclSettings(cluster[0], "c0"), "c0");
- Client c1(aclSettings(cluster[1], "c1"), "c1");
- Client foo(aclSettings(cluster[1], "foo"), "foo");
-
- foo.session.queueDeclare("foo", arg::durable=durableFlag);
- BOOST_CHECK_EQUAL(c0.session.queueQuery("foo").getQueue(), "foo");
-
- {
- ScopedSuppressLogging sl;
- BOOST_CHECK_THROW(foo.session.queueDeclare("bar", arg::durable=durableFlag), framing::UnauthorizedAccessException);
- }
- BOOST_CHECK(c0.session.queueQuery("bar").getQueue().empty());
- BOOST_CHECK(c1.session.queueQuery("bar").getQueue().empty());
-
- cluster.add();
- Client c2(aclSettings(cluster[2], "c2"), "c2");
- {
- ScopedSuppressLogging sl;
- BOOST_CHECK_THROW(foo.session.queueDeclare("bar", arg::durable=durableFlag), framing::UnauthorizedAccessException);
- }
- BOOST_CHECK(c2.session.queueQuery("bar").getQueue().empty());
-}
-
-QPID_AUTO_TEST_CASE(testMessageTimeToLive) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(2, args, -1);
- Client c0(cluster[0], "c0");
- Client c1(cluster[1], "c1");
- c0.session.queueDeclare("p", arg::durable=durableFlag);
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=ttlMessage("a", "q", 200, durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("b", "q", durableFlag));
- c0.session.messageTransfer(arg::content=ttlMessage("x", "p", 100000, durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("y", "p", durableFlag));
- cluster.add();
- Client c2(cluster[1], "c2");
-
- BOOST_CHECK_EQUAL(browse(c0, "p", 1), list_of<string>("x"));
- BOOST_CHECK_EQUAL(browse(c1, "p", 1), list_of<string>("x"));
- BOOST_CHECK_EQUAL(browse(c2, "p", 1), list_of<string>("x"));
-
- sys::usleep(200*1000);
- BOOST_CHECK_EQUAL(browse(c0, "q", 1), list_of<string>("b"));
- BOOST_CHECK_EQUAL(browse(c1, "q", 1), list_of<string>("b"));
- BOOST_CHECK_EQUAL(browse(c2, "q", 1), list_of<string>("b"));
-}
-
-QPID_AUTO_TEST_CASE(testSequenceOptions) {
- // Make sure the exchange qpid.msg_sequence property is properly replicated.
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
- FieldTable ftargs;
- ftargs.setInt("qpid.msg_sequence", 1);
- c0.session.queueDeclare(arg::queue="q", arg::durable=durableFlag);
- c0.session.exchangeDeclare(arg::exchange="ex", arg::type="direct", arg::arguments=ftargs);
- c0.session.exchangeBind(arg::exchange="ex", arg::queue="q", arg::bindingKey="k");
- c0.session.messageTransfer(arg::content=makeMessage("1", "k", durableFlag), arg::destination="ex");
- c0.session.messageTransfer(arg::content=makeMessage("2", "k", durableFlag), arg::destination="ex");
- BOOST_CHECK_EQUAL(1, getMsgSequence(c0.subs.get("q", TIMEOUT)));
- BOOST_CHECK_EQUAL(2, getMsgSequence(c0.subs.get("q", TIMEOUT)));
-
- cluster.add();
- Client c1(cluster[1]);
- c1.session.messageTransfer(arg::content=makeMessage("3", "k", durableFlag), arg::destination="ex");
- BOOST_CHECK_EQUAL(3, getMsgSequence(c1.subs.get("q", TIMEOUT)));
-}
-
-QPID_AUTO_TEST_CASE(testTxTransaction) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
- c0.session.queueDeclare(arg::queue="q", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=makeMessage("A", "q", durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("B", "q", durableFlag));
-
- // Start a transaction that will commit.
- Session commitSession = c0.connection.newSession("commit");
- SubscriptionManager commitSubs(commitSession);
- commitSession.txSelect();
- commitSession.messageTransfer(arg::content=makeMessage("a", "q", durableFlag));
- commitSession.messageTransfer(arg::content=makeMessage("b", "q", durableFlag));
- BOOST_CHECK_EQUAL(commitSubs.get("q", TIMEOUT).getData(), "A");
-
- // Start a transaction that will roll back.
- Session rollbackSession = c0.connection.newSession("rollback");
- SubscriptionManager rollbackSubs(rollbackSession);
- rollbackSession.txSelect();
- rollbackSession.messageTransfer(arg::content=makeMessage("1", "q", durableFlag));
- Message rollbackMessage = rollbackSubs.get("q", TIMEOUT);
- BOOST_CHECK_EQUAL(rollbackMessage.getData(), "B");
-
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q").getMessageCount(), 0u);
- // Add new member mid transaction.
- cluster.add();
- Client c1(cluster[1], "c1");
-
- // More transactional work
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q").getMessageCount(), 0u);
- rollbackSession.messageTransfer(arg::content=makeMessage("2", "q", durableFlag));
- commitSession.messageTransfer(arg::content=makeMessage("c", "q", durableFlag));
- rollbackSession.messageTransfer(arg::content=makeMessage("3", "q", durableFlag));
-
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q").getMessageCount(), 0u);
-
- // Commit/roll back.
- commitSession.txCommit();
- rollbackSession.txRollback();
- rollbackSession.messageRelease(rollbackMessage.getId());
-
- // Verify queue status: just the comitted messages and dequeues should remain.
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q").getMessageCount(), 4u);
- BOOST_CHECK_EQUAL(c1.subs.get("q", TIMEOUT).getData(), "B");
- BOOST_CHECK_EQUAL(c1.subs.get("q", TIMEOUT).getData(), "a");
- BOOST_CHECK_EQUAL(c1.subs.get("q", TIMEOUT).getData(), "b");
- BOOST_CHECK_EQUAL(c1.subs.get("q", TIMEOUT).getData(), "c");
-
- commitSession.close();
- rollbackSession.close();
-}
-
-QPID_AUTO_TEST_CASE(testUnacked) {
- // Verify replication of unacknowledged messages.
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
-
- Message m;
-
- // Create unacked message: acquired but not accepted.
- SubscriptionSettings manualAccept(FlowControl::unlimited(), ACCEPT_MODE_EXPLICIT, ACQUIRE_MODE_PRE_ACQUIRED, 0);
- c0.session.queueDeclare("q1", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=makeMessage("11","q1", durableFlag));
- LocalQueue q1;
- c0.subs.subscribe(q1, "q1", manualAccept);
- BOOST_CHECK_EQUAL(q1.get(TIMEOUT).getData(), "11"); // Acquired but not accepted
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q1").getMessageCount(), 0u); // Gone from queue
-
- // Create unacked message: not acquired, accepted or completeed.
- SubscriptionSettings manualAcquire(FlowControl::unlimited(), ACCEPT_MODE_EXPLICIT, ACQUIRE_MODE_NOT_ACQUIRED, 0);
- c0.session.queueDeclare("q2", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=makeMessage("21","q2", durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("22","q2", durableFlag));
- LocalQueue q2;
- c0.subs.subscribe(q2, "q2", manualAcquire);
- m = q2.get(TIMEOUT); // Not acquired or accepted, still on queue
- BOOST_CHECK_EQUAL(m.getData(), "21");
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q2").getMessageCount(), 2u); // Not removed
- c0.subs.getSubscription("q2").acquire(m); // Acquire manually
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q2").getMessageCount(), 1u); // Removed
- BOOST_CHECK_EQUAL(q2.get(TIMEOUT).getData(), "22"); // Not acquired or accepted, still on queue
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q2").getMessageCount(), 1u); // 1 not acquired.
-
- // Create empty credit record: acquire and accept but don't complete.
- SubscriptionSettings manualComplete(FlowControl::messageWindow(1), ACCEPT_MODE_EXPLICIT, ACQUIRE_MODE_PRE_ACQUIRED, 1, MANUAL_COMPLETION);
- c0.session.queueDeclare("q3", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=makeMessage("31", "q3", durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("32", "q3", durableFlag));
- LocalQueue q3;
- c0.subs.subscribe(q3, "q3", manualComplete);
- Message m31=q3.get(TIMEOUT);
- BOOST_CHECK_EQUAL(m31.getData(), "31"); // Automatically acquired & accepted but not completed.
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q3").getMessageCount(), 1u);
-
- // Add new member while there are unacked messages.
- cluster.add();
- Client c1(cluster[1], "c1");
-
- // Check queue counts
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q1").getMessageCount(), 0u);
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q2").getMessageCount(), 1u);
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q3").getMessageCount(), 1u);
-
- // Complete the empty credit message, should unblock the message behind it.
- BOOST_CHECK_THROW(q3.get(0), Exception);
- c0.session.markCompleted(SequenceSet(m31.getId()), true);
- BOOST_CHECK_EQUAL(q3.get(TIMEOUT).getData(), "32");
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q3").getMessageCount(), 0u);
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q3").getMessageCount(), 0u);
-
- // Close the original session - unacked messages should be requeued.
- c0.session.close();
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q1").getMessageCount(), 1u);
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q2").getMessageCount(), 2u);
-
- BOOST_CHECK_EQUAL(c1.subs.get("q1", TIMEOUT).getData(), "11");
- BOOST_CHECK_EQUAL(c1.subs.get("q2", TIMEOUT).getData(), "21");
- BOOST_CHECK_EQUAL(c1.subs.get("q2", TIMEOUT).getData(), "22");
-}
-
-// FIXME aconway 2009-06-17: test for unimplemented feature, enable when implemented.
-void testUpdateTxState() {
- // Verify that we update transaction state correctly to new members.
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
-
- // Do work in a transaction.
- c0.session.txSelect();
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=makeMessage("1","q", durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("2","q", durableFlag));
- Message m;
- BOOST_CHECK(c0.subs.get(m, "q", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "1");
-
- // New member, TX not comitted, c1 should see nothing.
- cluster.add();
- Client c1(cluster[1], "c1");
- BOOST_CHECK_EQUAL(c1.session.queueQuery(arg::queue="q").getMessageCount(), 0u);
-
- // After commit c1 shoudl see results of tx.
- c0.session.txCommit();
- BOOST_CHECK_EQUAL(c1.session.queueQuery(arg::queue="q").getMessageCount(), 1u);
- BOOST_CHECK(c1.subs.get(m, "q", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "2");
-
- // Another transaction with both members active.
- c0.session.messageTransfer(arg::content=makeMessage("3","q", durableFlag));
- BOOST_CHECK_EQUAL(c1.session.queueQuery(arg::queue="q").getMessageCount(), 0u);
- c0.session.txCommit();
- BOOST_CHECK_EQUAL(c1.session.queueQuery(arg::queue="q").getMessageCount(), 1u);
- BOOST_CHECK(c1.subs.get(m, "q", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "3");
-}
-
-QPID_AUTO_TEST_CASE(testUpdateMessageBuilder) {
- // Verify that we update a partially recieved message to a new member.
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- Sender sender(ConnectionAccess::getImpl(c0.connection), c0.session.getChannel());
-
- // Send first 2 frames of message.
- MessageTransferBody transfer(
- ProtocolVersion(), string(), // default exchange.
- framing::message::ACCEPT_MODE_NONE,
- framing::message::ACQUIRE_MODE_PRE_ACQUIRED);
- sender.send(transfer, true, false, true, true);
- AMQHeaderBody header;
- header.get<DeliveryProperties>(true)->setRoutingKey("q");
- if (durableFlag)
- header.get<DeliveryProperties>(true)->setDeliveryMode(DELIVERY_MODE_PERSISTENT);
- else
- header.get<DeliveryProperties>(true)->setDeliveryMode(DELIVERY_MODE_NON_PERSISTENT);
- sender.send(header, false, false, true, true);
-
- // No reliable way to ensure the partial message has arrived
- // before we start the new broker, so we sleep.
- sys::usleep(2500);
- cluster.add();
-
- // Send final 2 frames of message.
- sender.send(AMQContentBody("ab"), false, true, true, false);
- sender.send(AMQContentBody("cd"), false, true, false, true);
-
- // Verify message is enqued correctly on second member.
- Message m;
- Client c1(cluster[1], "c1");
- BOOST_CHECK(c1.subs.get(m, "q", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "abcd");
- BOOST_CHECK_EQUAL(2u, knownBrokerPorts(c1.connection, 2).size());
-}
-
-QPID_AUTO_TEST_CASE(testConnectionKnownHosts) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
- set<int> kb0 = knownBrokerPorts(c0.connection, 1);
- BOOST_CHECK_EQUAL(kb0.size(), 1u);
- BOOST_CHECK_EQUAL(kb0, makeSet(cluster));
-
- cluster.add();
- Client c1(cluster[1], "c1");
- set<int> kb1 = knownBrokerPorts(c1.connection, 2);
- kb0 = knownBrokerPorts(c0.connection, 2);
- BOOST_CHECK_EQUAL(kb1.size(), 2u);
- BOOST_CHECK_EQUAL(kb1, makeSet(cluster));
- BOOST_CHECK_EQUAL(kb1,kb0);
-
- cluster.add();
- Client c2(cluster[2], "c2");
- set<int> kb2 = knownBrokerPorts(c2.connection, 3);
- kb1 = knownBrokerPorts(c1.connection, 3);
- kb0 = knownBrokerPorts(c0.connection, 3);
- BOOST_CHECK_EQUAL(kb2.size(), 3u);
- BOOST_CHECK_EQUAL(kb2, makeSet(cluster));
- BOOST_CHECK_EQUAL(kb2,kb0);
- BOOST_CHECK_EQUAL(kb2,kb1);
-
- cluster.killWithSilencer(1,c1.connection,9);
- kb0 = knownBrokerPorts(c0.connection, 2);
- kb2 = knownBrokerPorts(c2.connection, 2);
- BOOST_CHECK_EQUAL(kb0.size(), 2u);
- BOOST_CHECK_EQUAL(kb0, kb2);
-}
-
-QPID_AUTO_TEST_CASE(testUpdateConsumers) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
-
- Client c0(cluster[0], "c0");
- c0.session.queueDeclare("p", arg::durable=durableFlag);
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- c0.subs.subscribe(c0.lq, "q", FlowControl::zero());
- LocalQueue lp;
- c0.subs.subscribe(lp, "p", FlowControl::messageCredit(1));
- c0.session.sync();
-
- // Start new members
- cluster.add(); // Local
- Client c1(cluster[1], "c1");
- cluster.add();
- Client c2(cluster[2], "c2");
-
- // Transfer messages
- c0.session.messageTransfer(arg::content=makeMessage("aaa", "q", durableFlag));
-
- c0.session.messageTransfer(arg::content=makeMessage("bbb", "p", durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("ccc", "p", durableFlag));
-
- // Activate the subscription, ensure message removed on all queues.
- c0.subs.setFlowControl("q", FlowControl::unlimited());
- Message m;
- BOOST_CHECK(c0.lq.get(m, TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "aaa");
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q").getMessageCount(), 0u);
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q").getMessageCount(), 0u);
- BOOST_CHECK_EQUAL(c2.session.queueQuery("q").getMessageCount(), 0u);
-
- // Check second subscription's flow control: gets first message, not second.
- BOOST_CHECK(lp.get(m, TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "bbb");
- BOOST_CHECK_EQUAL(c0.session.queueQuery("p").getMessageCount(), 1u);
- BOOST_CHECK_EQUAL(c1.session.queueQuery("p").getMessageCount(), 1u);
- BOOST_CHECK_EQUAL(c2.session.queueQuery("p").getMessageCount(), 1u);
-
- BOOST_CHECK(c0.subs.get(m, "p", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "ccc");
-
- // Kill the subscribing member, ensure further messages are not removed.
- cluster.killWithSilencer(0,c0.connection,9);
- BOOST_REQUIRE_EQUAL(knownBrokerPorts(c1.connection, 2).size(), 2u);
- for (int i = 0; i < 10; ++i) {
- c1.session.messageTransfer(arg::content=makeMessage("xxx", "q", durableFlag));
- BOOST_REQUIRE(c1.subs.get(m, "q", TIMEOUT));
- BOOST_REQUIRE_EQUAL(m.getData(), "xxx");
- }
-}
-
-// Test that message data and delivery properties are updated properly.
-QPID_AUTO_TEST_CASE(testUpdateMessages) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
-
- // Create messages with different delivery properties
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- c0.session.exchangeBind(arg::exchange="amq.fanout", arg::queue="q");
- c0.session.messageTransfer(arg::content=makeMessage("foo","q", durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("bar","q", durableFlag),
- arg::destination="amq.fanout");
-
- while (c0.session.queueQuery("q").getMessageCount() != 2)
- sys::usleep(1000); // Wait for message to show up on broker 0.
-
- // Add a new broker, it will catch up.
- cluster.add();
-
- // Do some work post-add
- c0.session.queueDeclare("p", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=makeMessage("pfoo","p", durableFlag));
-
- // Do some work post-join
- BOOST_REQUIRE_EQUAL(knownBrokerPorts(c0.connection, 2).size(), 2u);
- c0.session.messageTransfer(arg::content=makeMessage("pbar","p", durableFlag));
-
- // Verify new brokers have state.
- Message m;
-
- Client c1(cluster[1], "c1");
-
- BOOST_CHECK(c1.subs.get(m, "q", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "foo");
- BOOST_CHECK(m.getDeliveryProperties().hasExchange());
- BOOST_CHECK_EQUAL(m.getDeliveryProperties().getExchange(), "");
- BOOST_CHECK(c1.subs.get(m, "q", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "bar");
- BOOST_CHECK(m.getDeliveryProperties().hasExchange());
- BOOST_CHECK_EQUAL(m.getDeliveryProperties().getExchange(), "amq.fanout");
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q").getMessageCount(), 0u);
-
- // Add another broker, don't wait for join - should be stalled till ready.
- cluster.add();
- Client c2(cluster[2], "c2");
- BOOST_CHECK(c2.subs.get(m, "p", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "pfoo");
- BOOST_CHECK(c2.subs.get(m, "p", TIMEOUT));
- BOOST_CHECK_EQUAL(m.getData(), "pbar");
- BOOST_CHECK_EQUAL(c2.session.queueQuery("p").getMessageCount(), 0u);
-}
-
-QPID_AUTO_TEST_CASE(testWiringReplication) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(3, args, -1);
- Client c0(cluster[0]);
- BOOST_CHECK(c0.session.queueQuery("q").getQueue().empty());
- BOOST_CHECK(c0.session.exchangeQuery("ex").getType().empty());
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- c0.session.exchangeDeclare("ex", arg::type="direct");
- c0.session.close();
- c0.connection.close();
- // Verify all brokers get wiring update.
- for (size_t i = 0; i < cluster.size(); ++i) {
- BOOST_MESSAGE("i == "<< i);
- Client c(cluster[i]);
- BOOST_CHECK_EQUAL("q", c.session.queueQuery("q").getQueue());
- BOOST_CHECK_EQUAL("direct", c.session.exchangeQuery("ex").getType());
- }
-}
-
-QPID_AUTO_TEST_CASE(testMessageEnqueue) {
- // Enqueue on one broker, dequeue on another.
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(2, args, -1);
- Client c0(cluster[0]);
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=makeMessage("foo", "q", durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("bar", "q", durableFlag));
- c0.session.close();
- Client c1(cluster[1]);
- Message msg;
- BOOST_CHECK(c1.subs.get(msg, "q", TIMEOUT));
- BOOST_CHECK_EQUAL(string("foo"), msg.getData());
- BOOST_CHECK(c1.subs.get(msg, "q", TIMEOUT));
- BOOST_CHECK_EQUAL(string("bar"), msg.getData());
-}
-
-QPID_AUTO_TEST_CASE(testMessageDequeue) {
- // Enqueue on one broker, dequeue on two others.
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(3, args, -1);
- Client c0(cluster[0], "c0");
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- c0.session.messageTransfer(arg::content=makeMessage("foo", "q", durableFlag));
- c0.session.messageTransfer(arg::content=makeMessage("bar", "q", durableFlag));
-
- Message msg;
-
- // Dequeue on 2 others, ensure correct order.
- Client c1(cluster[1], "c1");
- BOOST_CHECK(c1.subs.get(msg, "q"));
- BOOST_CHECK_EQUAL("foo", msg.getData());
-
- Client c2(cluster[2], "c2");
- BOOST_CHECK(c1.subs.get(msg, "q"));
- BOOST_CHECK_EQUAL("bar", msg.getData());
-
- // Queue should be empty on all cluster members.
- BOOST_CHECK_EQUAL(0u, c0.session.queueQuery("q").getMessageCount());
- BOOST_CHECK_EQUAL(0u, c1.session.queueQuery("q").getMessageCount());
- BOOST_CHECK_EQUAL(0u, c2.session.queueQuery("q").getMessageCount());
-}
-
-QPID_AUTO_TEST_CASE(testDequeueWaitingSubscription) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(3, args, -1);
- Client c0(cluster[0]);
- BOOST_REQUIRE_EQUAL(knownBrokerPorts(c0.connection, 3).size(), 3u); // Wait for brokers.
-
- // First start a subscription.
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- c0.subs.subscribe(c0.lq, "q", FlowControl::messageCredit(2));
-
- // Now send messages
- Client c1(cluster[1]);
- c1.session.messageTransfer(arg::content=makeMessage("foo", "q", durableFlag));
- c1.session.messageTransfer(arg::content=makeMessage("bar", "q", durableFlag));
-
- // Check they arrived
- Message m;
- BOOST_CHECK(c0.lq.get(m, TIMEOUT));
- BOOST_CHECK_EQUAL("foo", m.getData());
- BOOST_CHECK(c0.lq.get(m, TIMEOUT));
- BOOST_CHECK_EQUAL("bar", m.getData());
-
- // Queue should be empty on all cluster members.
- Client c2(cluster[2]);
- BOOST_CHECK_EQUAL(0u, c0.session.queueQuery("q").getMessageCount());
- BOOST_CHECK_EQUAL(0u, c1.session.queueQuery("q").getMessageCount());
- BOOST_CHECK_EQUAL(0u, c2.session.queueQuery("q").getMessageCount());
-}
-
-QPID_AUTO_TEST_CASE(queueDurabilityPropagationToNewbie)
-{
- /*
- Start with a single broker.
- Set up two queues: one durable, and one not.
- Add a new broker to the cluster.
- Make sure it has one durable and one non-durable queue.
- */
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0]);
- c0.session.queueDeclare("durable_queue", arg::durable=true);
- c0.session.queueDeclare("non_durable_queue", arg::durable=false);
- cluster.add();
- Client c1(cluster[1]);
- QueueQueryResult durable_query = c1.session.queueQuery ( "durable_queue" );
- QueueQueryResult non_durable_query = c1.session.queueQuery ( "non_durable_queue" );
- BOOST_CHECK_EQUAL(durable_query.getQueue(), std::string("durable_queue"));
- BOOST_CHECK_EQUAL(non_durable_query.getQueue(), std::string("non_durable_queue"));
-
- BOOST_CHECK_EQUAL ( durable_query.getDurable(), true );
- BOOST_CHECK_EQUAL ( non_durable_query.getDurable(), false );
-}
-
-
-QPID_AUTO_TEST_CASE(testHeartbeatCancelledOnFailover)
-{
-
- struct Sender : FailoverManager::Command
- {
- std::string queue;
- std::string content;
-
- Sender(const std::string& q, const std::string& c) : queue(q), content(c) {}
-
- void execute(AsyncSession& session, bool)
- {
- session.messageTransfer(arg::content=makeMessage(content, queue, durableFlag));
- }
- };
-
- struct Receiver : FailoverManager::Command, MessageListener, qpid::sys::Runnable
- {
- FailoverManager& mgr;
- std::string queue;
- std::string expectedContent;
- qpid::client::Subscription subscription;
- qpid::sys::Monitor lock;
- bool ready, failed;
-
- Receiver(FailoverManager& m, const std::string& q, const std::string& c) : mgr(m), queue(q), expectedContent(c), ready(false), failed(false) {}
-
- void received(Message& message)
- {
- BOOST_CHECK_EQUAL(expectedContent, message.getData());
- subscription.cancel();
- }
-
- void execute(AsyncSession& session, bool)
- {
- session.queueDeclare(arg::queue=queue, arg::durable=durableFlag);
- SubscriptionManager subs(session);
- subscription = subs.subscribe(*this, queue);
- session.sync();
- setReady();
- subs.run();
- //cleanup:
- session.queueDelete(arg::queue=queue);
- }
-
- void run()
- {
- try {
- mgr.execute(*this);
- }
- catch (const std::exception& e) {
- BOOST_MESSAGE("Exception in mgr.execute: " << e.what());
- failed = true;
- }
- }
-
- void waitForReady()
- {
- qpid::sys::Monitor::ScopedLock l(lock);
- while (!ready) {
- lock.wait();
- }
- }
-
- void setReady()
- {
- qpid::sys::Monitor::ScopedLock l(lock);
- ready = true;
- lock.notify();
- }
- };
-
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(2, args, -1);
- ConnectionSettings settings;
- settings.port = cluster[1];
- settings.heartbeat = 1;
- FailoverManager fmgr(settings);
- Sender sender("my-queue", "my-data");
- Receiver receiver(fmgr, "my-queue", "my-data");
- qpid::sys::Thread runner(receiver);
- receiver.waitForReady();
- {
- ScopedSuppressLogging allQuiet; // suppress connection closed messages
- cluster.kill(1);
- //sleep for 2 secs to allow the heartbeat task to fire on the now dead connection:
- ::usleep(2*1000*1000);
- }
- fmgr.execute(sender);
- runner.join();
- BOOST_CHECK(!receiver.failed);
- fmgr.close();
-}
-
-QPID_AUTO_TEST_CASE(testPolicyUpdate) {
- //tests that the policys internal state is accurate on newly
- //joined nodes
- ClusterFixture::Args args;
- args += "--log-enable", "critical";
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c1(cluster[0], "c1");
- {
- ScopedSuppressLogging allQuiet;
- QueueOptions options;
- options.setSizePolicy(REJECT, 0, 2);
- c1.session.queueDeclare("q", arg::arguments=options, arg::durable=durableFlag);
- c1.session.messageTransfer(arg::content=makeMessage("one", "q", durableFlag));
- cluster.add();
- Client c2(cluster[1], "c2");
- c2.session.messageTransfer(arg::content=makeMessage("two", "q", durableFlag));
-
- BOOST_CHECK_THROW(c2.session.messageTransfer(arg::content=makeMessage("three", "q", durableFlag)), framing::ResourceLimitExceededException);
-
- Message received;
- BOOST_CHECK(c1.subs.get(received, "q"));
- BOOST_CHECK_EQUAL(received.getData(), std::string("one"));
- BOOST_CHECK(c1.subs.get(received, "q"));
- BOOST_CHECK_EQUAL(received.getData(), std::string("two"));
- BOOST_CHECK(!c1.subs.get(received, "q"));
- }
-}
-
-QPID_AUTO_TEST_CASE(testExclusiveQueueUpdate) {
- //tests that exclusive queues are accurately replicated on newly
- //joined nodes
- ClusterFixture::Args args;
- args += "--log-enable", "critical";
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c1(cluster[0], "c1");
- {
- ScopedSuppressLogging allQuiet;
- c1.session.queueDeclare("q", arg::exclusive=true, arg::autoDelete=true, arg::alternateExchange="amq.fanout");
- cluster.add();
- Client c2(cluster[1], "c2");
- QueueQueryResult result = c2.session.queueQuery("q");
- BOOST_CHECK_EQUAL(result.getQueue(), std::string("q"));
- BOOST_CHECK(result.getExclusive());
- BOOST_CHECK(result.getAutoDelete());
- BOOST_CHECK(!result.getDurable());
- BOOST_CHECK_EQUAL(result.getAlternateExchange(), std::string("amq.fanout"));
- BOOST_CHECK_THROW(c2.session.queueDeclare(arg::queue="q", arg::exclusive=true, arg::passive=true), framing::ResourceLockedException);
- c1.session.close();
- c1.connection.close();
- c2.session = c2.connection.newSession();
- BOOST_CHECK_THROW(c2.session.queueDeclare(arg::queue="q", arg::passive=true), framing::NotFoundException);
- }
-}
-
-/**
- * Subscribes to specified queue and acquires up to the specified
- * number of message but does not accept or release them. These
- * message are therefore 'locked' by the clients session.
- */
-Subscription lockMessages(Client& client, const std::string& queue, int count)
-{
- LocalQueue q;
- SubscriptionSettings settings(FlowControl::messageCredit(count));
- settings.autoAck = 0;
- Subscription sub = client.subs.subscribe(q, queue, settings);
- client.session.messageFlush(sub.getName());
- return sub;
-}
-
-/**
- * check that the specified queue contains the expected set of
- * messages (matched on content) for all nodes in the cluster
- */
-void checkQueue(ClusterFixture& cluster, const std::string& queue, const std::vector<std::string>& messages)
-{
- for (size_t i = 0; i < cluster.size(); i++) {
- Client client(cluster[i], (boost::format("%1%_%2%") % "c" % (i+1)).str());
- BOOST_CHECK_EQUAL(browse(client, queue, messages.size()), messages);
- client.close();
- }
-}
-
-void send(Client& client, const std::string& queue, int count, int start=1, const std::string& base="m",
- const std::string& lvqKey="")
-{
- for (int i = 0; i < count; i++) {
- Message message = makeMessage((boost::format("%1%_%2%") % base % (i+start)).str(), queue, durableFlag);
- if (!lvqKey.empty()) message.getHeaders().setString(QueueOptions::strLVQMatchProperty, lvqKey);
- client.session.messageTransfer(arg::content=message);
- }
-}
-
-QPID_AUTO_TEST_CASE(testRingQueueUpdate) {
- //tests that ring queues are accurately replicated on newly
- //joined nodes
- ClusterFixture::Args args;
- args += "--log-enable", "critical";
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c1(cluster[0], "c1");
- {
- ScopedSuppressLogging allQuiet;
- QueueOptions options;
- options.setSizePolicy(RING, 0, 5);
- c1.session.queueDeclare("q", arg::arguments=options, arg::durable=durableFlag);
- send(c1, "q", 5);
- lockMessages(c1, "q", 1);
- //add new node
- cluster.add();
- BOOST_CHECK_EQUAL(2u, knownBrokerPorts(c1.connection, 2).size());//wait till joined
- //send one more message
- send(c1, "q", 1, 6);
- //release locked message
- c1.close();
- //check state of queue on both nodes
- checkQueue(cluster, "q", list_of<string>("m_2")("m_3")("m_4")("m_5")("m_6"));
- }
-}
-
-QPID_AUTO_TEST_CASE(testRingQueueUpdate2) {
- //tests that ring queues are accurately replicated on newly joined
- //nodes; just like testRingQueueUpdate, but new node joins after
- //the sixth message has been sent.
- ClusterFixture::Args args;
- args += "--log-enable", "critical";
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c1(cluster[0], "c1");
- {
- ScopedSuppressLogging allQuiet;
- QueueOptions options;
- options.setSizePolicy(RING, 0, 5);
- c1.session.queueDeclare("q", arg::arguments=options, arg::durable=durableFlag);
- send(c1, "q", 5);
- lockMessages(c1, "q", 1);
- //send sixth message
- send(c1, "q", 1, 6);
- //add new node
- cluster.add();
- BOOST_CHECK_EQUAL(2u, knownBrokerPorts(c1.connection, 2).size());//wait till joined
- //release locked message
- c1.close();
- //check state of queue on both nodes
- checkQueue(cluster, "q", list_of<string>("m_2")("m_3")("m_4")("m_5")("m_6"));
- }
-}
-
-QPID_AUTO_TEST_CASE(testLvqUpdate) {
- //tests that lvqs are accurately replicated on newly joined nodes
- ClusterFixture::Args args;
- args += "--log-enable", "critical";
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c1(cluster[0], "c1");
- {
- ScopedSuppressLogging allQuiet;
- QueueOptions options;
- options.setOrdering(LVQ);
- c1.session.queueDeclare("q", arg::arguments=options, arg::durable=durableFlag);
-
- send(c1, "q", 5, 1, "a", "a");
- send(c1, "q", 2, 1, "b", "b");
- send(c1, "q", 1, 1, "c", "c");
- send(c1, "q", 1, 3, "b", "b");
-
- //add new node
- cluster.add();
- BOOST_CHECK_EQUAL(2u, knownBrokerPorts(c1.connection, 2).size());//wait till joined
-
- //check state of queue on both nodes
- checkQueue(cluster, "q", list_of<string>("a_5")("b_3")("c_1"));
- }
-}
-
-
-QPID_AUTO_TEST_CASE(testBrowsedLvqUpdate) {
- //tests that lvqs are accurately replicated on newly joined nodes
- //if the lvq state has been affected by browsers
- ClusterFixture::Args args;
- args += "--log-enable", "critical";
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c1(cluster[0], "c1");
- {
- ScopedSuppressLogging allQuiet;
- QueueOptions options;
- options.setOrdering(LVQ);
- c1.session.queueDeclare("q", arg::arguments=options, arg::durable=durableFlag);
-
- send(c1, "q", 1, 1, "a", "a");
- send(c1, "q", 2, 1, "b", "b");
- send(c1, "q", 1, 1, "c", "c");
- checkQueue(cluster, "q", list_of<string>("a_1")("b_2")("c_1"));
- send(c1, "q", 4, 2, "a", "a");
- send(c1, "q", 1, 3, "b", "b");
-
- //add new node
- cluster.add();
- BOOST_CHECK_EQUAL(2u, knownBrokerPorts(c1.connection, 2).size());//wait till joined
-
- //check state of queue on both nodes
- checkQueue(cluster, "q", list_of<string>("a_1")("b_2")("c_1")("a_5")("b_3"));
- }
-}
-
-QPID_AUTO_TEST_CASE(testRelease) {
- //tests that releasing a messages that was unacked when one node
- //joined works correctly
- ClusterFixture::Args args;
- args += "--log-enable", "critical";
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c1(cluster[0], "c1");
- {
- ScopedSuppressLogging allQuiet;
- c1.session.queueDeclare("q", arg::durable=durableFlag);
- for (int i = 0; i < 5; i++) {
- c1.session.messageTransfer(arg::content=makeMessage((boost::format("%1%_%2%") % "m" % (i+1)).str(), "q", durableFlag));
- }
- //receive but don't ack a message
- LocalQueue lq;
- SubscriptionSettings lqSettings(FlowControl::messageCredit(1));
- lqSettings.autoAck = 0;
- Subscription lqSub = c1.subs.subscribe(lq, "q", lqSettings);
- c1.session.messageFlush("q");
- Message received;
- BOOST_CHECK(lq.get(received));
- BOOST_CHECK_EQUAL(received.getData(), std::string("m_1"));
-
- //add new node
- cluster.add();
-
- lqSub.release(lqSub.getUnaccepted());
-
- //check state of queue on both nodes
- vector<string> expected = list_of<string>("m_1")("m_2")("m_3")("m_4")("m_5");
- Client c3(cluster[0], "c3");
- BOOST_CHECK_EQUAL(browse(c3, "q", 5), expected);
- Client c2(cluster[1], "c2");
- BOOST_CHECK_EQUAL(browse(c2, "q", 5), expected);
- }
-}
-
-
-// Browse for 1 message with byte credit, return true if a message was
-// received false if not.
-bool browseByteCredit(Client& c, const string& q, int n, Message& m) {
- SubscriptionSettings browseSettings(
- FlowControl(1, n, false), // 1 message, n bytes credit, no window
- ACCEPT_MODE_NONE,
- ACQUIRE_MODE_NOT_ACQUIRED,
- 0 // No auto-ack.
- );
- LocalQueue lq;
- Subscription s = c.subs.subscribe(lq, q, browseSettings);
- c.session.messageFlush(arg::destination=q, arg::sync=true);
- c.session.sync();
- c.subs.getSubscription(q).cancel();
- return lq.get(m, 0); // No timeout, flush should push message thru.
-}
-
-// Ensure cluster update preserves exact message size, use byte credt as test.
-QPID_AUTO_TEST_CASE(testExactByteCredit) {
- ClusterFixture cluster(1, prepareArgs(), -1);
- Client c0(cluster[0], "c0");
- c0.session.queueDeclare("q");
- c0.session.messageTransfer(arg::content=Message("MyMessage", "q"));
- cluster.add();
-
- int size=36; // Size of message on broker: headers+body
- Client c1(cluster[1], "c1");
- Message m;
-
- // Ensure we get the message with exact credit.
- BOOST_CHECK(browseByteCredit(c0, "q", size, m));
- BOOST_CHECK(browseByteCredit(c1, "q", size, m));
- // and not with one byte less.
- BOOST_CHECK(!browseByteCredit(c0, "q", size-1, m));
- BOOST_CHECK(!browseByteCredit(c1, "q", size-1, m));
-}
-
-// Test that consumer positions are updated correctly.
-// Regression test for https://bugzilla.redhat.com/show_bug.cgi?id=541927
-//
-QPID_AUTO_TEST_CASE(testUpdateConsumerPosition) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
-
- c0.session.queueDeclare("q", arg::durable=durableFlag);
- SubscriptionSettings settings;
- settings.autoAck = 0;
- // Set the acquire mode to 'not-acquired' the consumer moves along the queue
- // but does not acquire (remove) messages.
- settings.acquireMode = ACQUIRE_MODE_NOT_ACQUIRED;
- Subscription s = c0.subs.subscribe(c0.lq, "q", settings);
- c0.session.messageTransfer(arg::content=makeMessage("1", "q", durableFlag));
- BOOST_CHECK_EQUAL("1", c0.lq.get(TIMEOUT).getData());
-
- // Add another member, send/receive another message and acquire
- // the messages. With the bug, this creates an inconsistency
- // because the browse position was not updated to the new member.
- cluster.add();
- c0.session.messageTransfer(arg::content=makeMessage("2", "q", durableFlag));
- BOOST_CHECK_EQUAL("2", c0.lq.get(TIMEOUT).getData());
- s.acquire(s.getUnacquired());
- s.accept(s.getUnaccepted());
-
- // In the bug we now have 0 messages on cluster[0] and 1 message on cluster[1]
- // Subscribing on cluster[1] provokes an error that shuts down cluster[0]
- Client c1(cluster[1], "c1");
- Subscription s1 = c1.subs.subscribe(c1.lq, "q"); // Default auto-ack=1
- Message m;
- BOOST_CHECK(!c1.lq.get(m, TIMEOUT/10));
- BOOST_CHECK_EQUAL(c1.session.queueQuery("q").getMessageCount(), 0u);
- BOOST_CHECK_EQUAL(c0.session.queueQuery("q").getMessageCount(), 0u);
-}
-
-QPID_AUTO_TEST_CASE(testFairsharePriorityDelivery) {
- ClusterFixture::Args args;
- prepareArgs(args, durableFlag);
- ClusterFixture cluster(1, args, -1);
- Client c0(cluster[0], "c0");
-
- FieldTable arguments;
- arguments.setInt("x-qpid-priorities", 10);
- arguments.setInt("x-qpid-fairshare", 5);
- c0.session.queueDeclare("q", arg::durable=durableFlag, arg::arguments=arguments);
-
- //send messages of different priorities
- for (int i = 0; i < 20; i++) {
- Message msg = makeMessage((boost::format("msg-%1%") % i).str(), "q", durableFlag);
- msg.getDeliveryProperties().setPriority(i % 2 ? 9 : 5);
- c0.session.messageTransfer(arg::content=msg);
- }
-
- //pull off a couple of the messages (first four should be the top priority messages
- for (int i = 0; i < 4; i++) {
- BOOST_CHECK_EQUAL((boost::format("msg-%1%") % ((i*2)+1)).str(), c0.subs.get("q", TIMEOUT).getData());
- }
-
- // Add another member
- cluster.add();
- Client c1(cluster[1], "c1");
-
- //pull off some more messages
- BOOST_CHECK_EQUAL((boost::format("msg-%1%") % 9).str(), c0.subs.get("q", TIMEOUT).getData());
- BOOST_CHECK_EQUAL((boost::format("msg-%1%") % 0).str(), c1.subs.get("q", TIMEOUT).getData());
- BOOST_CHECK_EQUAL((boost::format("msg-%1%") % 2).str(), c0.subs.get("q", TIMEOUT).getData());
-
- //check queue has same content on both nodes
- BOOST_CHECK_EQUAL(browse(c0, "q", 12), browse(c1, "q", 12));
-}
-
-QPID_AUTO_TEST_SUITE_END()
-}} // namespace qpid::tests
diff --git a/cpp/src/tests/cluster_test_logs.py b/cpp/src/tests/cluster_test_logs.py
deleted file mode 100755
index 22f2470590..0000000000
--- a/cpp/src/tests/cluster_test_logs.py
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/usr/bin/env python
-
-# 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.
-#
-
-# Functions for comparing broker log files, used by cluster_tests.py.
-
-import os, os.path, re, glob
-from itertools import izip
-
-def split_log(log):
- """Split a broker log at checkpoints where a member joins.
- Return the set of checkpoints discovered."""
- checkpoint_re = re.compile("Member joined, frameSeq=([0-9]+), queue snapshot:")
- outfile = None
- checkpoints = []
- for l in open(log):
- match = checkpoint_re.search(l)
- if match:
- checkpoint = match.groups()[0]
- checkpoints.append(checkpoint)
- if outfile: outfile.close()
- outfile = open("%s.%s"%(log, checkpoint), 'w')
-
- if outfile: outfile.write(l)
- if outfile: outfile.close()
- return checkpoints
-
-def filter_log(log):
- """Filter the contents of a log file to remove data that is expected
- to differ between brokers in a cluster. Filtered log contents between
- the same checkpoints should match across the cluster."""
- out = open("%s.filter"%(log), 'w')
- # Lines to skip entirely, expected differences
- skip = "|".join([
- 'local connection', # Only on local broker
- 'UPDATER|UPDATEE', # Ignore update process
- 'stall for update|unstall, ignore update|cancelled offer .* unstall',
- 'caught up',
- 'active for links|Passivating links|Activating links',
- 'info Connecting: .*', # UpdateClient connection
- 'info Connection.* connected to', # UpdateClient connection
- 'warning Connection \\[[-0-9.: ]+\\] closed', # UpdateClient connection
- 'warning Broker closed connection: 200, OK',
- 'task late',
- 'task overran',
- 'warning CLOSING .* unsent data',
- 'Inter-broker link ', # ignore link state changes
- 'Updated link key from ', # ignore link state changes
- 'Running in a cluster, marking store',
- 'debug Sending keepalive signal to watchdog', # Watchdog timer thread
- 'last broker standing joined by 1 replicas, updating queue policies.',
- 'Connection .* timed out: closing', # heartbeat connection close
- "org.apache.qpid.broker:bridge:", # ignore bridge index
- "closed connection"
- ])
- # Regex to match a UUID
- uuid='\w\w\w\w\w\w\w\w-\w\w\w\w-\w\w\w\w-\w\w\w\w-\w\w\w\w\w\w\w\w\w\w\w\w'
- # Substitutions to remove expected differences
- subs = [
- (r'\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d ', ''), # Remove timestamp
- (r'cluster\([0-9.: ]*', 'cluster('), # Remove cluster node id
- (r' local\)| shadow\)', ')'), # Remove local/shadow indication
- (r'CATCHUP', 'READY'), # Treat catchup as equivalent to ready.
- (r'OFFER', 'READY'), # Treat offer as equivalent to ready.
- # System UUID expected to be different
- (r'(org.apache.qpid.broker:system[:(])%s(\)?)'%(uuid), r'\1UUID\2'),
-
- # TODO aconway 2010-12-20: review if these should be expected:
- (r' len=\d+', ' len=NN'), # buffer lengths
- (r' map={.*_object_name:([^,}]*)[,}].*', r' \1'), # V2 map - just keep name
- (r'\d+-\d+-\d+--\d+', 'X-X-X--X'), # V1 Object IDs
- ]
- # Substitutions to mask known issue: durable test shows inconsistent "changed stats for com.redhat.rhm.store:journal" messages.
- skip += '|Changed V[12] statistics com.redhat.rhm.store:journal'
- subs += [(r'to=console.obj.1.0.com.redhat.rhm.store.journal props=\d+ stats=\d+',
- 'to=console.obj.1.0.com.redhat.rhm.store.journal props=NN stats=NN')]
-
- skip_re = re.compile(skip)
- subs = [(re.compile(pattern), subst) for pattern, subst in subs]
- for l in open(log):
- if skip_re.search(l): continue
- for pattern,subst in subs: l = re.sub(pattern,subst,l)
- out.write(l)
- out.close()
-
-def verify_logs():
- """Compare log files from cluster brokers, verify that they correspond correctly."""
- for l in glob.glob("*.log"): filter_log(l)
- checkpoints = set()
- for l in glob.glob("*.filter"): checkpoints = checkpoints.union(set(split_log(l)))
- errors=[]
- for c in checkpoints:
- fragments = glob.glob("*.filter.%s"%(c))
- fragments.sort(reverse=True, key=os.path.getsize)
- while len(fragments) >= 2:
- a = fragments.pop(0)
- b = fragments[0]
- for ab in izip(open(a), open(b)):
- if ab[0] != ab[1]:
- errors.append("\n %s %s"%(a, b))
- break
- if errors:
- raise Exception("Files differ in %s"%(os.getcwd())+"".join(errors))
-
-# Can be run as a script.
-if __name__ == "__main__":
- verify_logs()
diff --git a/cpp/src/tests/cluster_test_scripts/README.txt b/cpp/src/tests/cluster_test_scripts/README.txt
deleted file mode 100644
index e861a2f397..0000000000
--- a/cpp/src/tests/cluster_test_scripts/README.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-Cluster test scripts.
-
-A set of scripts to start and stop cluster and test clients on
-multiple hosts using ssh.
-
-Pre-requisites: You must be
- - set up for password-free ssh access to the test hosts.
- - a member of the ais group on all the test hosts.
-
-Configuration:
-
-Copy defaults.sh to config.sh and edit the values as necessary.
-
-Test scripts:
-
-Test scripts use the functions in functions.sh to start & monitor
-cluster and clients.
-A test script can collect other scripts.
-
-
diff --git a/cpp/src/tests/cluster_test_scripts/cluster_check b/cpp/src/tests/cluster_test_scripts/cluster_check
deleted file mode 100755
index 05fcc1bcd2..0000000000
--- a/cpp/src/tests/cluster_test_scripts/cluster_check
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-#
-# 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.
-#
-
-# Check that all members of a cluster are running
-
-source config.sh
-
-HOSTS=(`cat $CLUSTER_HOME/hosts`)
-PORTS=(`cat $CLUSTER_HOME/ports`)
-
-for ((i=0; i<${#HOSTS[*]}; ++i)); do
- host=${HOSTS[$i]}
- port=${PORTS[$i]}
- ssh $host "$QPIDD -cp $port" > /dev/null || {
- ret=1
- echo "ERROR: broker not running $host:$port"
- }
-done
-exit $ret
diff --git a/cpp/src/tests/cluster_test_scripts/cluster_start b/cpp/src/tests/cluster_test_scripts/cluster_start
deleted file mode 100755
index 8911358f7e..0000000000
--- a/cpp/src/tests/cluster_test_scripts/cluster_start
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/sh
-
-#
-# 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.
-#
-
-# Start a cluster
-#
-# Arguments: NAME HOST [host...]
-# Start a cluster called NAME with N nodes running on the given HOSTs
-# repeat the host name to run multiple brokers on one host. Use dynamic
-# ports.
-#
-# Log files, data directories and hosts/ports files are all stored under
-# $HOME/cluster_test/$NAME
-#
-
-source config.sh
-
-CLUSTER_NAME=`date +"${USER}_%F_%T"`
-HOSTS=($BROKER_HOSTS)
-for ((i = 0; i < ${#HOSTS[*]}; ++i)) ; do
- host=${HOSTS[$i]}
- datadir=$CLUSTER_HOME/broker$i
- log=$datadir/qpidd.log
- ssh $host "rm -rf $datadir; mkdir -p $datadir" || {
- echo "ERROR: can't make data dir $datadir"; exit 1
- }
- port=`ssh $host "echo $QPIDD -dp0 --cluster-name=$CLUSTER_NAME \
- --data-dir=$datadir \
- --log-to-file=$log --log-prefix=broker$i \
- $QPIDD_OPTS | newgrp ais"` || {
- error "ERROR: can't start broker $i on $host"; exit 1;
- }
- PORTS="$PORTS $port"
-done
-
-echo "$BROKER_HOSTS" > $CLUSTER_HOME/hosts
-echo "$PORTS" > $CLUSTER_HOME/ports
-
-`dirname $0`/cluster_check $NAME
diff --git a/cpp/src/tests/cluster_test_scripts/cluster_stop b/cpp/src/tests/cluster_test_scripts/cluster_stop
deleted file mode 100755
index 09aa8f3b21..0000000000
--- a/cpp/src/tests/cluster_test_scripts/cluster_stop
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/sh
-
-#
-# 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.
-#
-
-# Stop the cluster.
-
-source config.sh
-
-HOSTS=(`cat $CLUSTER_HOME/hosts`)
-PORTS=(`cat $CLUSTER_HOME/ports`)
-
-for ((i=0; i<${#HOSTS[*]}; ++i)); do
- host=${HOSTS[$i]}
- port=${PORTS[$i]}
- ssh $host "$QPIDD -qp $port" > /dev/null || {
- ret=1
- echo "ERROR: stopping broker at $host:$port"
- }
-done
-
-exit $ret
diff --git a/cpp/src/tests/cluster_test_scripts/config_example.sh b/cpp/src/tests/cluster_test_scripts/config_example.sh
deleted file mode 100755
index d47c9a9c77..0000000000
--- a/cpp/src/tests/cluster_test_scripts/config_example.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-# Cluster configuration.
-
-#
-# 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.
-#
-
-# All output stored under $HOME/$CLUSTER_HOME.
-CLUSTER_HOME=$HOME/cluster_test
-
-# Hosts where brokers will be run. Repeat hostname to run multiple brokers on 1 host.
-BROKER_HOSTS="mrg22 mrg23 mrg24 mrg25 mrg26"
-
-# Hosts where clients will be run.
-CLIENT_HOSTS="$BROKER_HOSTS"
-
-# Paths to executables
-QPIDD=qpidd
-PERFTEST=perftest
-
-# Directory containing tests
-TESTDIR=/usr/bin
-
-# Options for qpidd, must be sufficient to load the cluster plugin.
-# Scripts will add --cluster-name, --daemon, --port and --log-to-file options here.
-QPIDD_OPTS=" \
---auth=no \
---log-enable=notice+ \
---log-enable=debug+:cluster \
-"
diff --git a/cpp/src/tests/cluster_test_scripts/perftest b/cpp/src/tests/cluster_test_scripts/perftest
deleted file mode 100755
index 984761eb5f..0000000000
--- a/cpp/src/tests/cluster_test_scripts/perftest
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/sh
-
-#
-# 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.
-#
-
-# Run a distributed perftest against a cluster.
-# Args: npubs nsubs [perftest-options]
-
-source config.sh
-
-NPUBS=${1:-4} ; shift
-NSUBS=${1:-4} ; shift
-OPTS="--npubs $NPUBS --nsubs $NSUBS $*"
-
-CLIENTS=($CLIENT_HOSTS)
-BROKERS=(`cat $CLUSTER_HOME/hosts`)
-PORTS=(`cat $CLUSTER_HOME/ports`)
-
-start() {
- client=${CLIENTS[i % ${#CLIENTS[*]}]}
- broker=${BROKERS[i % ${#BROKERS[*]}]}
- port=${PORTS[i % ${#PORTS[*]}]}
- ssh -n $client $PERFTEST $OPTS $* -b $broker -p $port &
- PIDS="$PIDS $!"
-}
-
-ssh ${CLIENTS[0]} $PERFTEST $OPTS --setup -b ${BROKERS[0]} -p${PORTS[0]}
-for (( i=0 ; i < $NPUBS ; ++i)); do start --publish; done
-for (( ; i < $NPUBS+$NSUBS ; ++i)); do start --subscribe; done
-ssh ${CLIENTS[0]} $PERFTEST $OPTS --control -b ${BROKERS[0]} -p${PORTS[0]}
-
-for pid in $PIDS; do
- wait $pid || echo "ERROR: client process $pid failed"
-done
-
-`dirname $0`/cluster_check
-
-
diff --git a/cpp/src/tests/cluster_tests.fail b/cpp/src/tests/cluster_tests.fail
deleted file mode 100644
index b28b04f643..0000000000
--- a/cpp/src/tests/cluster_tests.fail
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/cpp/src/tests/cluster_tests.py b/cpp/src/tests/cluster_tests.py
deleted file mode 100755
index 3c96b252df..0000000000
--- a/cpp/src/tests/cluster_tests.py
+++ /dev/null
@@ -1,1834 +0,0 @@
-#!/usr/bin/env python
-
-# 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.
-#
-
-import os, signal, sys, time, imp, re, subprocess, glob, random, logging
-import cluster_test_logs
-from qpid import datatypes, messaging
-from brokertest import *
-from qpid.harness import Skipped
-from qpid.messaging import Message, Empty, Disposition, REJECTED, util
-from threading import Thread, Lock, Condition
-from logging import getLogger
-from itertools import chain
-from tempfile import NamedTemporaryFile
-
-log = getLogger("qpid.cluster_tests")
-
-# Note: brokers that shut themselves down due to critical error during
-# normal operation will still have an exit code of 0. Brokers that
-# shut down because of an error found during initialize will exit with
-# a non-0 code. Hence the apparently inconsistent use of EXPECT_EXIT_OK
-# and EXPECT_EXIT_FAIL in some of the tests below.
-
-# TODO aconway 2010-03-11: resolve this - ideally any exit due to an error
-# should give non-0 exit status.
-
-# Import scripts as modules
-qpid_cluster=import_script(checkenv("QPID_CLUSTER_EXEC"))
-
-def readfile(filename):
- """Returns te content of file named filename as a string"""
- f = file(filename)
- try: return f.read()
- finally: f.close()
-
-class ShortTests(BrokerTest):
- """Short cluster functionality tests."""
-
- def test_message_replication(self):
- """Test basic cluster message replication."""
- # Start a cluster, send some messages to member 0.
- cluster = self.cluster(2)
- s0 = cluster[0].connect().session()
- s0.sender("q; {create:always}").send(Message("x"))
- s0.sender("q; {create:always}").send(Message("y"))
- s0.connection.close()
-
- # Verify messages available on member 1.
- s1 = cluster[1].connect().session()
- m = s1.receiver("q", capacity=1).fetch(timeout=1)
- s1.acknowledge()
- self.assertEqual("x", m.content)
- s1.connection.close()
-
- # Start member 2 and verify messages available.
- s2 = cluster.start().connect().session()
- m = s2.receiver("q", capacity=1).fetch(timeout=1)
- s2.acknowledge()
- self.assertEqual("y", m.content)
- s2.connection.close()
-
- def test_store_direct_update_match(self):
- """Verify that brokers stores an identical message whether they receive it
- direct from clients or during an update, no header or other differences"""
- cluster = self.cluster(0, args=["--load-module", self.test_store_lib])
- cluster.start(args=["--test-store-dump", "direct.dump"])
- # Try messages with various headers
- cluster[0].send_message("q", Message(durable=True, content="foobar",
- subject="subject",
- reply_to="reply_to",
- properties={"n":10}))
- # Try messages of different sizes
- for size in range(0,10000,100):
- cluster[0].send_message("q", Message(content="x"*size, durable=True))
- # Try sending via named exchange
- c = cluster[0].connect_old()
- s = c.session(str(qpid.datatypes.uuid4()))
- s.exchange_bind(exchange="amq.direct", binding_key="foo", queue="q")
- props = s.delivery_properties(routing_key="foo", delivery_mode=2)
- s.message_transfer(
- destination="amq.direct",
- message=qpid.datatypes.Message(props, "content"))
-
- # Try message with TTL and differnet headers/properties
- cluster[0].send_message("q", Message(durable=True, ttl=100000))
- cluster[0].send_message("q", Message(durable=True, properties={}, ttl=100000))
- cluster[0].send_message("q", Message(durable=True, properties={"x":10}, ttl=100000))
-
- # Now update a new member and compare their dumps.
- cluster.start(args=["--test-store-dump", "updatee.dump"])
- assert readfile("direct.dump") == readfile("updatee.dump")
-
- os.remove("direct.dump")
- os.remove("updatee.dump")
-
- def test_sasl(self):
- """Test SASL authentication and encryption in a cluster"""
- sasl_config=os.path.join(self.rootdir, "sasl_config")
- acl=os.path.join(os.getcwd(), "policy.acl")
- aclf=file(acl,"w")
- # Must allow cluster-user (zag) access to credentials exchange.
- aclf.write("""
-acl allow zag@QPID publish exchange name=qpid.cluster-credentials
-acl allow zig@QPID all all
-acl deny all all
-""")
- aclf.close()
- cluster = self.cluster(1, args=["--auth", "yes",
- "--sasl-config", sasl_config,
- "--load-module", os.getenv("ACL_LIB"),
- "--acl-file", acl,
- "--cluster-username=zag",
- "--cluster-password=zag",
- "--cluster-mechanism=PLAIN"
- ])
-
- # Valid user/password, ensure queue is created.
- c = cluster[0].connect(username="zig", password="zig")
- c.session().sender("ziggy;{create:always,node:{x-declare:{exclusive:true}}}")
- c.close()
- cluster.start() # Start second node.
-
- # Check queue is created on second node.
- c = cluster[1].connect(username="zig", password="zig")
- c.session().receiver("ziggy;{assert:always}")
- c.close()
- for b in cluster: b.ready() # Make sure all brokers still running.
-
- # Valid user, bad password
- try:
- cluster[0].connect(username="zig", password="foo").close()
- self.fail("Expected exception")
- except messaging.exceptions.ConnectionError: pass
- for b in cluster: b.ready() # Make sure all brokers still running.
-
- # Bad user ID
- try:
- cluster[0].connect(username="foo", password="bar").close()
- self.fail("Expected exception")
- except messaging.exceptions.ConnectionError: pass
- for b in cluster: b.ready() # Make sure all brokers still running.
-
- # Action disallowed by ACL
- c = cluster[0].connect(username="zag", password="zag")
- try:
- s = c.session()
- s.sender("zaggy;{create:always}")
- s.close()
- self.fail("Expected exception")
- except messaging.exceptions.UnauthorizedAccess: pass
- # make sure the queue was not created at the other node.
- c = cluster[1].connect(username="zig", password="zig")
- try:
- s = c.session()
- s.sender("zaggy;{assert:always}")
- s.close()
- self.fail("Expected exception")
- except messaging.exceptions.NotFound: pass
-
- def test_sasl_join_good(self):
- """Verify SASL authentication between brokers when joining a cluster."""
- sasl_config=os.path.join(self.rootdir, "sasl_config")
- # Test with a valid username/password
- cluster = self.cluster(1, args=["--auth", "yes",
- "--sasl-config", sasl_config,
- "--cluster-username=zig",
- "--cluster-password=zig",
- "--cluster-mechanism=PLAIN"
- ])
- cluster.start()
- c = cluster[1].connect(username="zag", password="zag", mechanism="PLAIN")
-
- def test_sasl_join_bad_password(self):
- # Test with an invalid password
- cluster = self.cluster(1, args=["--auth", "yes",
- "--sasl-config", os.path.join(self.rootdir, "sasl_config"),
- "--cluster-username=zig",
- "--cluster-password=bad",
- "--cluster-mechanism=PLAIN"
- ])
- cluster.start(wait=False, expect=EXPECT_EXIT_FAIL)
- assert cluster[1].log_contains("critical Unexpected error: connection-forced: Authentication failed")
-
- def test_sasl_join_wrong_user(self):
- # Test with a valid user that is not the cluster user.
- cluster = self.cluster(0, args=["--auth", "yes",
- "--sasl-config", os.path.join(self.rootdir, "sasl_config")])
- cluster.start(args=["--cluster-username=zig",
- "--cluster-password=zig",
- "--cluster-mechanism=PLAIN"
- ])
-
- cluster.start(wait=False, expect=EXPECT_EXIT_FAIL,
- args=["--cluster-username=zag",
- "--cluster-password=zag",
- "--cluster-mechanism=PLAIN"
- ])
- assert cluster[1].log_contains("critical Unexpected error: unauthorized-access: unauthorized-access: Unauthorized user zag@QPID for qpid.cluster-credentials, should be zig")
-
- def test_user_id_update(self):
- """Ensure that user-id of an open session is updated to new cluster members"""
- sasl_config=os.path.join(self.rootdir, "sasl_config")
- cluster = self.cluster(1, args=["--auth", "yes", "--sasl-config", sasl_config,
- "--cluster-mechanism=ANONYMOUS"])
- c = cluster[0].connect(username="zig", password="zig")
- s = c.session().sender("q;{create:always}")
- s.send(Message("x", user_id="zig")) # Message sent before start new broker
- cluster.start()
- s.send(Message("y", user_id="zig")) # Messsage sent after start of new broker
- # Verify brokers are healthy and messages are on the queue.
- self.assertEqual("x", cluster[0].get_message("q").content)
- self.assertEqual("y", cluster[1].get_message("q").content)
-
- def test_other_mech(self):
- """Test using a mechanism other than PLAIN/ANONYMOUS for cluster update authentication.
- Regression test for https://issues.apache.org/jira/browse/QPID-3849"""
- sasl_config=os.path.join(self.rootdir, "sasl_config")
- cluster = self.cluster(2, args=["--auth", "yes", "--sasl-config", sasl_config,
- "--cluster-username=zig",
- "--cluster-password=zig",
- "--cluster-mechanism=DIGEST-MD5"])
- cluster[0].connect()
- cluster.start() # Before the fix this broker falied to join the cluster.
- cluster[2].connect()
-
- def test_link_events(self):
- """Regression test for https://bugzilla.redhat.com/show_bug.cgi?id=611543"""
- args = ["--mgmt-pub-interval", 1] # Publish management information every second.
- broker1 = self.cluster(1, args)[0]
- broker2 = self.cluster(1, args)[0]
- qp = self.popen(["qpid-printevents", broker1.host_port()], EXPECT_RUNNING)
- qr = self.popen(["qpid-route", "route", "add",
- broker1.host_port(), broker2.host_port(),
- "amq.fanout", "key"
- ], EXPECT_EXIT_OK)
- # Look for link event in printevents output.
- retry(lambda: find_in_file("brokerLinkUp", qp.outfile("out")))
- broker1.ready()
- broker2.ready()
- qr.wait()
-
- def test_queue_cleaner(self):
- """ Regression test to ensure that cleanup of expired messages works correctly """
- cluster = self.cluster(2, args=["--queue-purge-interval", 3])
-
- s0 = cluster[0].connect().session()
- sender = s0.sender("my-lvq; {create: always, node:{x-declare:{arguments:{'qpid.last_value_queue':1}}}}")
- #send 10 messages that will all expire and be cleaned up
- for i in range(1, 10):
- msg = Message("message-%s" % i)
- msg.properties["qpid.LVQ_key"] = "a"
- msg.ttl = 0.1
- sender.send(msg)
- #wait for queue cleaner to run
- time.sleep(3)
-
- #test all is ok by sending and receiving a message
- msg = Message("non-expiring")
- msg.properties["qpid.LVQ_key"] = "b"
- sender.send(msg)
- s0.connection.close()
- s1 = cluster[1].connect().session()
- m = s1.receiver("my-lvq", capacity=1).fetch(timeout=1)
- s1.acknowledge()
- self.assertEqual("non-expiring", m.content)
- s1.connection.close()
-
- for b in cluster: b.ready() # Make sure all brokers still running.
-
-
- def test_amqfailover_visible(self):
- """Verify that the amq.failover exchange can be seen by
- QMF-based tools - regression test for BZ615300."""
- broker1 = self.cluster(1)[0]
- broker2 = self.cluster(1)[0]
- qs = subprocess.Popen(["qpid-stat", "-e", "-b", broker1.host_port()], stdout=subprocess.PIPE)
- out = qs.communicate()[0]
- assert out.find("amq.failover") > 0
-
- def evaluate_address(self, session, address):
- """Create a receiver just to evaluate an address for its side effects"""
- r = session.receiver(address)
- r.close()
-
- def test_expire_fanout(self):
- """Regression test for QPID-2874: Clustered broker crashes in assertion in
- cluster/ExpiryPolicy.cpp.
- Caused by a fan-out message being updated as separate messages"""
- cluster = self.cluster(1)
- session0 = cluster[0].connect().session()
- # Create 2 queues bound to fanout exchange.
- self.evaluate_address(session0, "q1;{create:always,node:{x-bindings:[{exchange:'amq.fanout',queue:q1}]}}")
- self.evaluate_address(session0, "q2;{create:always,node:{x-bindings:[{exchange:'amq.fanout',queue:q2}]}}")
- queues = ["q1", "q2"]
- # Send a fanout message with a long timeout
- s = session0.sender("amq.fanout")
- s.send(Message("foo", ttl=100), sync=False)
- # Start a new member, check the messages
- cluster.start()
- session1 = cluster[1].connect().session()
- for q in queues: self.assert_browse(session1, "q1", ["foo"])
-
- def test_route_update(self):
- """Regression test for https://issues.apache.org/jira/browse/QPID-2982
- Links and bridges associated with routes were not replicated on update.
- This meant extra management objects and caused an exit if a management
- client was attached.
- """
- args=["--mgmt-pub-interval=1","--log-enable=trace+:management"]
-
- # First broker will be killed.
- cluster0 = self.cluster(1, args=args)
- cluster1 = self.cluster(1, args=args)
- assert 0 == subprocess.call(
- ["qpid-route", "route", "add", cluster0[0].host_port(),
- cluster1[0].host_port(), "dummy-exchange", "dummy-key", "-d"])
- cluster0.start()
-
- # Wait for qpid-tool:list on cluster0[0] to generate expected output.
- pattern = re.compile("org.apache.qpid.broker.*link")
- qpid_tool = subprocess.Popen(["qpid-tool", cluster0[0].host_port()],
- stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- class Scanner(Thread):
- def __init__(self): self.found = False; Thread.__init__(self)
- def run(self):
- for l in qpid_tool.stdout:
- if pattern.search(l): self.found = True; return
- scanner = Scanner()
- scanner.start()
- start = time.time()
- try:
- # Wait up to 5 second timeout for scanner to find expected output
- while not scanner.found and time.time() < start + 5:
- qpid_tool.stdin.write("list\n") # Ask qpid-tool to list
- for b in cluster0: b.ready() # Raise if any brokers are down
- finally:
- qpid_tool.stdin.write("quit\n")
- qpid_tool.wait()
- scanner.join()
- assert scanner.found
- # Regression test for https://issues.apache.org/jira/browse/QPID-3235
- # Inconsistent stats when changing elder.
-
- # Force a change of elder
- cluster0.start()
- for b in cluster0: b.ready()
- cluster0[0].expect=EXPECT_EXIT_FAIL # About to die.
- cluster0[0].kill()
- time.sleep(2) # Allow a management interval to pass.
- for b in cluster0[1:]: b.ready()
- # Verify logs are consistent
- cluster_test_logs.verify_logs()
-
- def test_redelivered(self):
- """Verify that redelivered flag is set correctly on replayed messages"""
- cluster = self.cluster(2, expect=EXPECT_EXIT_FAIL)
- url = "amqp:tcp:%s,tcp:%s" % (cluster[0].host_port(), cluster[1].host_port())
- queue = "my-queue"
- cluster[0].declare_queue(queue)
- self.sender = self.popen(
- ["qpid-send",
- "--broker", url,
- "--address", queue,
- "--sequence=true",
- "--send-eos=1",
- "--messages=100000",
- "--connection-options={%s}"%(Cluster.CONNECTION_OPTIONS)
- ])
- self.receiver = self.popen(
- ["qpid-receive",
- "--broker", url,
- "--address", queue,
- "--ignore-duplicates",
- "--check-redelivered",
- "--connection-options={%s}"%(Cluster.CONNECTION_OPTIONS),
- "--forever"
- ])
- time.sleep(1)#give sender enough time to have some messages to replay
- cluster[0].kill()
- self.sender.wait()
- self.receiver.wait()
- cluster[1].kill()
-
- class BlockedSend(Thread):
- """Send a message, send is expected to block.
- Verify that it does block (for a given timeout), then allow
- waiting till it unblocks when it is expected to do so."""
- def __init__(self, sender, msg):
- self.sender, self.msg = sender, msg
- self.blocked = True
- self.condition = Condition()
- self.timeout = 0.1 # Time to wait for expected results.
- Thread.__init__(self)
- def run(self):
- try:
- self.sender.send(self.msg, sync=True)
- self.condition.acquire()
- try:
- self.blocked = False
- self.condition.notify()
- finally: self.condition.release()
- except Exception,e: print "BlockedSend exception: %s"%e
- def start(self):
- Thread.start(self)
- time.sleep(self.timeout)
- assert self.blocked # Expected to block
- def assert_blocked(self): assert self.blocked
- def wait(self): # Now expecting to unblock
- self.condition.acquire()
- try:
- while self.blocked:
- self.condition.wait(self.timeout)
- if self.blocked: raise Exception("Timed out waiting for send to unblock")
- finally: self.condition.release()
- self.join()
-
- def queue_flowlimit_test(self, brokers):
- """Verify that the queue's flowlimit configuration and state are
- correctly replicated.
- The brokers argument allows this test to run on single broker,
- cluster of 2 pre-startd brokers or cluster where second broker
- starts after queue is in flow control.
- """
- # configure a queue with a specific flow limit on first broker
- ssn0 = brokers.first().connect().session()
- s0 = ssn0.sender("flq; {create:always, node:{type:queue, x-declare:{arguments:{'qpid.flow_stop_count':5, 'qpid.flow_resume_count':3}}}}")
- brokers.first().startQmf()
- q1 = [q for q in brokers.first().qmf_session.getObjects(_class="queue") if q.name == "flq"][0]
- oid = q1.getObjectId()
- self.assertEqual(q1.name, "flq")
- self.assertEqual(q1.arguments, {u'qpid.flow_stop_count': 5L, u'qpid.flow_resume_count': 3L})
- assert not q1.flowStopped
- self.assertEqual(q1.flowStoppedCount, 0)
-
- # fill the queue on one broker until flow control is active
- for x in range(5): s0.send(Message(str(x)))
- sender = ShortTests.BlockedSend(s0, Message(str(6)))
- sender.start() # Tests that sender does block
- # Verify the broker queue goes into a flowStopped state
- deadline = time.time() + 1
- while not q1.flowStopped and time.time() < deadline: q1.update()
- assert q1.flowStopped
- self.assertEqual(q1.flowStoppedCount, 1)
- sender.assert_blocked() # Still blocked
-
- # Now verify the both brokers in cluster have same configuration
- brokers.second().startQmf()
- qs = brokers.second().qmf_session.getObjects(_objectId=oid)
- self.assertEqual(len(qs), 1)
- q2 = qs[0]
- self.assertEqual(q2.name, "flq")
- self.assertEqual(q2.arguments, {u'qpid.flow_stop_count': 5L, u'qpid.flow_resume_count': 3L})
- assert q2.flowStopped
- self.assertEqual(q2.flowStoppedCount, 1)
-
- # now drain the queue using a session to the other broker
- ssn1 = brokers.second().connect().session()
- r1 = ssn1.receiver("flq", capacity=6)
- for x in range(4):
- r1.fetch(timeout=0)
- ssn1.acknowledge()
- sender.wait() # Verify no longer blocked.
-
- # and re-verify state of queue on both brokers
- q1.update()
- assert not q1.flowStopped
- q2.update()
- assert not q2.flowStopped
-
- ssn0.connection.close()
- ssn1.connection.close()
- cluster_test_logs.verify_logs()
-
- def test_queue_flowlimit(self):
- """Test flow limits on a standalone broker"""
- broker = self.broker()
- class Brokers:
- def first(self): return broker
- def second(self): return broker
- self.queue_flowlimit_test(Brokers())
-
- def test_queue_flowlimit_cluster(self):
- cluster = self.cluster(2)
- class Brokers:
- def first(self): return cluster[0]
- def second(self): return cluster[1]
- self.queue_flowlimit_test(Brokers())
-
- def test_queue_flowlimit_cluster_join(self):
- cluster = self.cluster(1)
- class Brokers:
- def first(self): return cluster[0]
- def second(self):
- if len(cluster) == 1: cluster.start()
- return cluster[1]
- self.queue_flowlimit_test(Brokers())
-
- def test_queue_flowlimit_replicate(self):
- """ Verify that a queue which is in flow control BUT has drained BELOW
- the flow control 'stop' threshold, is correctly replicated when a new
- broker is added to the cluster.
- """
-
- class AsyncSender(Thread):
- """Send a fixed number of msgs from a sender in a separate thread
- so it may block without blocking the test.
- """
- def __init__(self, broker, address, count=1, size=4):
- Thread.__init__(self)
- self.daemon = True
- self.broker = broker
- self.queue = address
- self.count = count
- self.size = size
- self.done = False
-
- def run(self):
- self.sender = subprocess.Popen(["qpid-send",
- "--capacity=1",
- "--content-size=%s" % self.size,
- "--messages=%s" % self.count,
- "--failover-updates",
- "--connection-options={%s}"%(Cluster.CONNECTION_OPTIONS),
- "--address=%s" % self.queue,
- "--broker=%s" % self.broker.host_port()])
- self.sender.wait()
- self.done = True
-
- cluster = self.cluster(2)
- # create a queue with rather draconian flow control settings
- ssn0 = cluster[0].connect().session()
- s0 = ssn0.sender("flq; {create:always, node:{type:queue, x-declare:{arguments:{'qpid.flow_stop_count':100, 'qpid.flow_resume_count':20}}}}")
-
- # fire off the sending thread to broker[0], and wait until the queue
- # hits flow control on broker[1]
- sender = AsyncSender(cluster[0], "flq", count=110);
- sender.start();
-
- cluster[1].startQmf()
- q_obj = [q for q in cluster[1].qmf_session.getObjects(_class="queue") if q.name == "flq"][0]
- deadline = time.time() + 10
- while not q_obj.flowStopped and time.time() < deadline:
- q_obj.update()
- assert q_obj.flowStopped
- assert not sender.done
- assert q_obj.msgDepth < 110
-
- # Now drain enough messages on broker[1] to drop below the flow stop
- # threshold, but not relieve flow control...
- receiver = subprocess.Popen(["qpid-receive",
- "--messages=15",
- "--timeout=1",
- "--print-content=no",
- "--failover-updates",
- "--connection-options={%s}"%(Cluster.CONNECTION_OPTIONS),
- "--ack-frequency=1",
- "--address=flq",
- "--broker=%s" % cluster[1].host_port()])
- receiver.wait()
- q_obj.update()
- assert q_obj.flowStopped
- assert not sender.done
- current_depth = q_obj.msgDepth
-
- # add a new broker to the cluster, and verify that the queue is in flow
- # control on that broker
- cluster.start()
- cluster[2].startQmf()
- q_obj = [q for q in cluster[2].qmf_session.getObjects(_class="queue") if q.name == "flq"][0]
- assert q_obj.flowStopped
- assert q_obj.msgDepth == current_depth
-
- # now drain the queue on broker[2], and verify that the sender becomes
- # unblocked
- receiver = subprocess.Popen(["qpid-receive",
- "--messages=95",
- "--timeout=1",
- "--print-content=no",
- "--failover-updates",
- "--connection-options={%s}"%(Cluster.CONNECTION_OPTIONS),
- "--ack-frequency=1",
- "--address=flq",
- "--broker=%s" % cluster[2].host_port()])
- receiver.wait()
- q_obj.update()
- assert not q_obj.flowStopped
- self.assertEqual(q_obj.msgDepth, 0)
-
- # verify that the sender has become unblocked
- sender.join(timeout=5)
- assert not sender.isAlive()
- assert sender.done
-
- def test_blocked_queue_delete(self):
- """Verify that producers which are blocked on a queue due to flow
- control are unblocked when that queue is deleted.
- """
-
- cluster = self.cluster(2)
- cluster[0].startQmf()
- cluster[1].startQmf()
-
- # configure a queue with a specific flow limit on first broker
- ssn0 = cluster[0].connect().session()
- s0 = ssn0.sender("flq; {create:always, node:{type:queue, x-declare:{arguments:{'qpid.flow_stop_count':5, 'qpid.flow_resume_count':3}}}}")
- q1 = [q for q in cluster[0].qmf_session.getObjects(_class="queue") if q.name == "flq"][0]
- oid = q1.getObjectId()
- self.assertEqual(q1.name, "flq")
- self.assertEqual(q1.arguments, {u'qpid.flow_stop_count': 5L, u'qpid.flow_resume_count': 3L})
- assert not q1.flowStopped
- self.assertEqual(q1.flowStoppedCount, 0)
-
- # fill the queue on one broker until flow control is active
- for x in range(5): s0.send(Message(str(x)))
- sender = ShortTests.BlockedSend(s0, Message(str(6)))
- sender.start() # Tests that sender does block
- # Verify the broker queue goes into a flowStopped state
- deadline = time.time() + 1
- while not q1.flowStopped and time.time() < deadline: q1.update()
- assert q1.flowStopped
- self.assertEqual(q1.flowStoppedCount, 1)
- sender.assert_blocked() # Still blocked
-
- # Now verify the both brokers in cluster have same configuration
- qs = cluster[1].qmf_session.getObjects(_objectId=oid)
- self.assertEqual(len(qs), 1)
- q2 = qs[0]
- self.assertEqual(q2.name, "flq")
- self.assertEqual(q2.arguments, {u'qpid.flow_stop_count': 5L, u'qpid.flow_resume_count': 3L})
- assert q2.flowStopped
- self.assertEqual(q2.flowStoppedCount, 1)
-
- # now delete the blocked queue from other broker
- ssn1 = cluster[1].connect().session()
- self.evaluate_address(ssn1, "flq;{delete:always}")
- sender.wait() # Verify no longer blocked.
-
- ssn0.connection.close()
- ssn1.connection.close()
- cluster_test_logs.verify_logs()
-
-
- def test_alternate_exchange_update(self):
- """Verify that alternate-exchange on exchanges and queues is propagated to new members of a cluster. """
- cluster = self.cluster(1)
- s0 = cluster[0].connect().session()
- # create alt queue bound to amq.fanout exchange, will be destination for alternate exchanges
- self.evaluate_address(s0, "alt;{create:always,node:{x-bindings:[{exchange:'amq.fanout',queue:alt}]}}")
- # create direct exchange ex with alternate-exchange amq.fanout and no queues bound
- self.evaluate_address(s0, "ex;{create:always,node:{type:topic, x-declare:{type:'direct', alternate-exchange:'amq.fanout'}}}")
- # create queue q with alternate-exchange amq.fanout
- self.evaluate_address(s0, "q;{create:always,node:{type:queue, x-declare:{alternate-exchange:'amq.fanout'}}}")
-
- def verify(broker):
- s = broker.connect().session()
- # Verify unmatched message goes to ex's alternate.
- s.sender("ex").send("foo")
- self.assertEqual("foo", s.receiver("alt").fetch(timeout=0).content)
- # Verify rejected message goes to q's alternate.
- s.sender("q").send("bar")
- msg = s.receiver("q").fetch(timeout=0)
- self.assertEqual("bar", msg.content)
- s.acknowledge(msg, Disposition(REJECTED)) # Reject the message
- self.assertEqual("bar", s.receiver("alt").fetch(timeout=0).content)
-
- verify(cluster[0])
- cluster.start()
- verify(cluster[1])
-
- def test_binding_order(self):
- """Regression test for binding order inconsistency in cluster"""
- cluster = self.cluster(1)
- c0 = cluster[0].connect()
- s0 = c0.session()
- # Declare multiple queues bound to same key on amq.topic
- def declare(q,max=0):
- if max: declare = 'x-declare:{arguments:{"qpid.max_count":%d, "qpid.flow_stop_count":0}}'%max
- else: declare = 'x-declare:{}'
- bind='x-bindings:[{queue:%s,key:key,exchange:"amq.topic"}]'%(q)
- s0.sender("%s;{create:always,node:{%s,%s}}" % (q,declare,bind))
- declare('d',max=4) # Only one with a limit
- for q in ['c', 'b','a']: declare(q)
- # Add a cluster member, send enough messages to exceed the max count
- cluster.start()
- try:
- s = s0.sender('amq.topic/key')
- for m in xrange(1,6): s.send(Message(str(m)))
- self.fail("Expected capacity exceeded exception")
- except messaging.exceptions.TargetCapacityExceeded: pass
- c1 = cluster[1].connect()
- s1 = c1.session()
- s0 = c0.session() # Old session s0 is broken by exception.
- # Verify queue contents are consistent.
- for q in ['a','b','c','d']:
- self.assertEqual(self.browse(s0, q), self.browse(s1, q))
- # Verify queue contents are "best effort"
- for q in ['a','b','c']: self.assert_browse(s1,q,[str(n) for n in xrange(1,6)])
- self.assert_browse(s1,'d',[str(n) for n in xrange(1,5)])
-
- def test_deleted_exchange(self):
- """QPID-3215: cached exchange reference can cause cluster inconsistencies
- if exchange is deleted/recreated
- Verify stand-alone case
- """
- cluster = self.cluster()
- # Verify we do not route message via an exchange that has been destroyed.
- cluster.start()
- s0 = cluster[0].connect().session()
- self.evaluate_address(s0, "ex;{create:always,node:{type:topic}}")
- self.evaluate_address(s0, "q;{create:always,node:{x-bindings:[{exchange:'ex',queue:q,key:foo}]}}")
- send0 = s0.sender("ex/foo")
- send0.send("foo")
- self.assert_browse(s0, "q", ["foo"])
- self.evaluate_address(s0, "ex;{delete:always}")
- try:
- send0.send("bar") # Should fail, exchange is deleted.
- self.fail("Expected not-found exception")
- except qpid.messaging.NotFound: pass
- self.assert_browse(cluster[0].connect().session(), "q", ["foo"])
-
- def test_deleted_exchange_inconsistent(self):
- """QPID-3215: cached exchange reference can cause cluster inconsistencies
- if exchange is deleted/recreated
-
- Verify cluster inconsistency.
- """
- cluster = self.cluster()
- cluster.start()
- s0 = cluster[0].connect().session()
- self.evaluate_address(s0, "ex;{create:always,node:{type:topic}}")
- self.evaluate_address(s0, "q;{create:always,node:{x-bindings:[{exchange:'ex',queue:q,key:foo}]}}")
- send0 = s0.sender("ex/foo")
- send0.send("foo")
- self.assert_browse(s0, "q", ["foo"])
-
- cluster.start()
- s1 = cluster[1].connect().session()
- self.evaluate_address(s0, "ex;{delete:always}")
- try:
- send0.send("bar")
- self.fail("Expected not-found exception")
- except qpid.messaging.NotFound: pass
-
- self.assert_browse(s1, "q", ["foo"])
-
-
- def test_ttl_consistent(self):
- """Ensure we don't get inconsistent errors with message that have TTL very close together"""
- messages = [ Message(str(i), ttl=i/1000.0) for i in xrange(0,1000)]
- messages.append(Message("x"))
- cluster = self.cluster(2)
- sender = cluster[0].connect().session().sender("q;{create:always}")
-
- def fetch(b):
- receiver = b.connect().session().receiver("q;{create:always}")
- while receiver.fetch().content != "x": pass
-
- for m in messages: sender.send(m, sync=False)
- for m in messages: sender.send(m, sync=False)
- fetch(cluster[0])
- fetch(cluster[1])
- for m in messages: sender.send(m, sync=False)
- cluster.start()
- fetch(cluster[2])
-
-
- def _verify_federation(self, src_broker, src, dst_broker, dst, timeout=30):
- """ Prove that traffic can pass between two federated brokers.
- """
- tot_time = 0
- active = False
- send_session = src_broker.connect().session()
- sender = send_session.sender(src)
- receive_session = dst_broker.connect().session()
- receiver = receive_session.receiver(dst)
- while not active and tot_time < timeout:
- sender.send(Message("Hello from Source!"))
- try:
- receiver.fetch(timeout = 1)
- receive_session.acknowledge()
- # Get this far without Empty exception, and the link is good!
- active = True
- while True:
- # Keep receiving msgs, as several may have accumulated
- receiver.fetch(timeout = 1)
- receive_session.acknowledge()
- except Empty:
- if not active:
- tot_time += 1
- receiver.close()
- receive_session.close()
- sender.close()
- send_session.close()
- return active
-
- def test_federation_failover(self):
- """
- Verify that federation operates across failures occuring in a cluster.
- Specifically:
- 1) Destination cluster learns of membership changes in the source
- cluster
- 2) Destination cluster replicates the current state of the source
- cluster to newly-added members
- """
-
- # 2 node cluster source, 2 node cluster destination
- src_cluster = self.cluster(2, expect=EXPECT_EXIT_FAIL)
- src_cluster.ready();
- dst_cluster = self.cluster(2, expect=EXPECT_EXIT_FAIL)
- dst_cluster.ready();
-
- cmd = self.popen(["qpid-config",
- "--broker", src_cluster[0].host_port(),
- "add", "queue", "srcQ"], EXPECT_EXIT_OK)
- cmd.wait()
-
- cmd = self.popen(["qpid-config",
- "--broker", dst_cluster[0].host_port(),
- "add", "exchange", "fanout", "destX"], EXPECT_EXIT_OK)
- cmd.wait()
-
- cmd = self.popen(["qpid-config",
- "--broker", dst_cluster[0].host_port(),
- "add", "queue", "destQ"], EXPECT_EXIT_OK)
- cmd.wait()
-
- cmd = self.popen(["qpid-config",
- "--broker", dst_cluster[0].host_port(),
- "bind", "destX", "destQ"], EXPECT_EXIT_OK)
- cmd.wait()
-
- # federate the srcQ to the destination exchange
- dst_cluster[0].startQmf()
- dst_broker = dst_cluster[0].qmf_session.getObjects(_class="broker")[0]
- result = dst_broker.connect(src_cluster[0].host(), src_cluster[0].port(), False, "PLAIN",
- "guest", "guest", "tcp")
- self.assertEqual(result.status, 0, result);
-
- link = dst_cluster[0].qmf_session.getObjects(_class="link")[0]
- result = link.bridge(False, "srcQ", "destX", "", "", "", True, False, False, 10)
- self.assertEqual(result.status, 0, result)
-
- # check that traffic passes
- assert self._verify_federation(src_cluster[0], "srcQ", dst_cluster[0], "destQ")
-
- # add src[2] broker to source cluster
- src_cluster.start(expect=EXPECT_EXIT_FAIL);
- src_cluster.ready();
- assert self._verify_federation(src_cluster[2], "srcQ", dst_cluster[0], "destQ")
-
- # Kill src[0]. dst[0] should fail over to src[1]
- src_cluster[0].kill()
- for b in src_cluster[1:]: b.ready()
- assert self._verify_federation(src_cluster[1], "srcQ", dst_cluster[0], "destQ")
-
- # Kill src[1], dst[0] should fail over to src[2]
- src_cluster[1].kill()
- for b in src_cluster[2:]: b.ready()
- assert self._verify_federation(src_cluster[2], "srcQ", dst_cluster[0], "destQ")
-
- # Kill dest[0], force failover to dest[1]
- dst_cluster[0].kill()
- for b in dst_cluster[1:]: b.ready()
- assert self._verify_federation(src_cluster[2], "srcQ", dst_cluster[1], "destQ")
-
- # Add dest[2]
- # dest[1] syncs dest[2] to current remote state
- dst_cluster.start(expect=EXPECT_EXIT_FAIL);
- for b in dst_cluster[1:]: b.ready()
- assert self._verify_federation(src_cluster[2], "srcQ", dst_cluster[1], "destQ")
-
- # Kill dest[1], force failover to dest[2]
- dst_cluster[1].kill()
- for b in dst_cluster[2:]: b.ready()
- assert self._verify_federation(src_cluster[2], "srcQ", dst_cluster[2], "destQ")
-
- for i in range(2, len(src_cluster)): src_cluster[i].kill()
- for i in range(2, len(dst_cluster)): dst_cluster[i].kill()
-
-
- def test_federation_multilink_failover(self):
- """
- Verify that multi-link federation operates across failures occuring in
- a cluster.
- """
-
- # 1 node cluster source, 1 node cluster destination
- src_cluster = self.cluster(1, expect=EXPECT_EXIT_FAIL)
- src_cluster.ready();
- dst_cluster = self.cluster(1, expect=EXPECT_EXIT_FAIL)
- dst_cluster.ready();
-
- # federate a direct binding across two separate links
-
- # first, create a direct exchange bound to two queues using different
- # bindings
- cmd = self.popen(["qpid-config",
- "--broker", src_cluster[0].host_port(),
- "add", "exchange", "direct", "FedX"],
- EXPECT_EXIT_OK)
- cmd.wait()
-
- cmd = self.popen(["qpid-config",
- "--broker", dst_cluster[0].host_port(),
- "add", "exchange", "direct", "FedX"],
- EXPECT_EXIT_OK)
- cmd.wait()
-
- cmd = self.popen(["qpid-config",
- "--broker", dst_cluster[0].host_port(),
- "add", "queue", "destQ1"],
- EXPECT_EXIT_OK)
- cmd.wait()
-
- cmd = self.popen(["qpid-config",
- "--broker", dst_cluster[0].host_port(),
- "bind", "FedX", "destQ1", "one"],
- EXPECT_EXIT_OK)
- cmd.wait()
-
- cmd = self.popen(["qpid-config",
- "--broker", dst_cluster[0].host_port(),
- "add", "queue", "destQ2"],
- EXPECT_EXIT_OK)
- cmd.wait()
-
- cmd = self.popen(["qpid-config",
- "--broker", dst_cluster[0].host_port(),
- "bind", "FedX", "destQ2", "two"],
- EXPECT_EXIT_OK)
- cmd.wait()
-
- # Create two separate links between the dst and source brokers, bind
- # each to different keys
- dst_cluster[0].startQmf()
- dst_broker = dst_cluster[0].qmf_session.getObjects(_class="broker")[0]
-
- for _l in [("link1", "bridge1", "one"),
- ("link2", "bridge2", "two")]:
- result = dst_broker.create("link", _l[0],
- {"host":src_cluster[0].host(),
- "port":src_cluster[0].port()},
- False)
- self.assertEqual(result.status, 0, result);
- result = dst_broker.create("bridge", _l[1],
- {"link":_l[0],
- "src":"FedX",
- "dest":"FedX",
- "key":_l[2]}, False)
- self.assertEqual(result.status, 0);
-
- # check that traffic passes
- assert self._verify_federation(src_cluster[0], "FedX/one", dst_cluster[0], "destQ1")
- assert self._verify_federation(src_cluster[0], "FedX/two", dst_cluster[0], "destQ2")
-
- # add new member, verify traffic
- src_cluster.start(expect=EXPECT_EXIT_FAIL);
- src_cluster.ready();
-
- dst_cluster.start(expect=EXPECT_EXIT_FAIL);
- dst_cluster.ready();
-
- assert self._verify_federation(src_cluster[0], "FedX/one", dst_cluster[0], "destQ1")
- assert self._verify_federation(src_cluster[0], "FedX/two", dst_cluster[0], "destQ2")
-
- src_cluster[0].kill()
- for b in src_cluster[1:]: b.ready()
-
- assert self._verify_federation(src_cluster[1], "FedX/one", dst_cluster[0], "destQ1")
- assert self._verify_federation(src_cluster[1], "FedX/two", dst_cluster[0], "destQ2")
-
- dst_cluster[0].kill()
- for b in dst_cluster[1:]: b.ready()
-
- assert self._verify_federation(src_cluster[1], "FedX/one", dst_cluster[1], "destQ1")
- assert self._verify_federation(src_cluster[1], "FedX/two", dst_cluster[1], "destQ2")
-
- for i in range(1, len(src_cluster)): src_cluster[i].kill()
- for i in range(1, len(dst_cluster)): dst_cluster[i].kill()
-
-
-
-# Some utility code for transaction tests
-XA_RBROLLBACK = 1
-XA_RBTIMEOUT = 2
-XA_OK = 0
-dtx_branch_counter = 0
-
-class DtxStatusException(Exception):
- def __init__(self, expect, actual):
- self.expect = expect
- self.actual = actual
-
- def str(self):
- return "DtxStatusException(expect=%s, actual=%s)"%(self.expect, self.actual)
-
-class DtxTestFixture:
- """Bundle together some common requirements for dtx tests."""
- def __init__(self, test, broker, name, exclusive=False):
- self.test = test
- self.broker = broker
- self.name = name
- # Use old API. DTX is not supported in messaging API.
- self.connection = broker.connect_old()
- self.session = self.connection.session(name, 1) # 1 second timeout
- self.queue = self.session.queue_declare(name, exclusive=exclusive)
- self.session.dtx_select()
- self.consumer = None
-
- def xid(self, id=None):
- if id is None: id = self.name
- return self.session.xid(format=0, global_id=id)
-
- def check_status(self, expect, actual):
- if expect != actual: raise DtxStatusException(expect, actual)
-
- def start(self, id=None, resume=False):
- self.check_status(XA_OK, self.session.dtx_start(xid=self.xid(id), resume=resume).status)
-
- def end(self, id=None, suspend=False):
- self.check_status(XA_OK, self.session.dtx_end(xid=self.xid(id), suspend=suspend).status)
-
- def prepare(self, id=None):
- self.check_status(XA_OK, self.session.dtx_prepare(xid=self.xid(id)).status)
-
- def commit(self, id=None, one_phase=True):
- self.check_status(
- XA_OK, self.session.dtx_commit(xid=self.xid(id), one_phase=one_phase).status)
-
- def rollback(self, id=None):
- self.check_status(XA_OK, self.session.dtx_rollback(xid=self.xid(id)).status)
-
- def set_timeout(self, timeout, id=None):
- self.session.dtx_set_timeout(xid=self.xid(id),timeout=timeout)
-
- def send(self, messages):
- for m in messages:
- dp=self.session.delivery_properties(routing_key=self.name)
- mp=self.session.message_properties()
- self.session.message_transfer(message=qpid.datatypes.Message(dp, mp, m))
-
- def accept(self):
- """Accept 1 message from queue"""
- consumer_tag="%s-consumer"%(self.name)
- self.session.message_subscribe(queue=self.name, destination=consumer_tag)
- self.session.message_flow(unit = self.session.credit_unit.message, value = 1, destination = consumer_tag)
- self.session.message_flow(unit = self.session.credit_unit.byte, value = 0xFFFFFFFFL, destination = consumer_tag)
- msg = self.session.incoming(consumer_tag).get(timeout=1)
- self.session.message_cancel(destination=consumer_tag)
- self.session.message_accept(qpid.datatypes.RangedSet(msg.id))
- return msg
-
-
- def verify(self, sessions, messages):
- for s in sessions:
- self.test.assert_browse(s, self.name, messages)
-
-class DtxTests(BrokerTest):
-
- def test_dtx_update(self):
- """Verify that DTX transaction state is updated to a new broker.
- Start a collection of transactions, then add a new cluster member,
- then verify they commit/rollback correctly on the new broker."""
-
- # Note: multiple test have been bundled into one to avoid the need to start/stop
- # multiple brokers per test.
-
- cluster=self.cluster(1)
- sessions = [cluster[0].connect().session()] # For verify
-
- # Transaction that will be open when new member joins, then committed.
- t1 = DtxTestFixture(self, cluster[0], "t1")
- t1.start()
- t1.send(["1", "2"])
- t1.verify(sessions, []) # Not visible outside of transaction
-
- # Transaction that will be open when new member joins, then rolled back.
- t2 = DtxTestFixture(self, cluster[0], "t2")
- t2.start()
- t2.send(["1", "2"])
-
- # Transaction that will be prepared when new member joins, then committed.
- t3 = DtxTestFixture(self, cluster[0], "t3")
- t3.start()
- t3.send(["1", "2"])
- t3.end()
- t3.prepare()
- t1.verify(sessions, []) # Not visible outside of transaction
-
- # Transaction that will be prepared when new member joins, then rolled back.
- t4 = DtxTestFixture(self, cluster[0], "t4")
- t4.start()
- t4.send(["1", "2"])
- t4.end()
- t4.prepare()
-
- # Transaction using an exclusive queue
- t5 = DtxTestFixture(self, cluster[0], "t5", exclusive=True)
- t5.start()
- t5.send(["1", "2"])
-
- # Accept messages in a transaction before/after join then commit
- # Note: Message sent outside transaction, we're testing transactional acceptance.
- t6 = DtxTestFixture(self, cluster[0], "t6")
- t6.send(["a","b","c"])
- t6.start()
- self.assertEqual(t6.accept().body, "a");
- t6.verify(sessions, ["b", "c"])
-
- # Accept messages in a transaction before/after join then roll back
- # Note: Message sent outside transaction, we're testing transactional acceptance.
- t7 = DtxTestFixture(self, cluster[0], "t7")
- t7.send(["a","b","c"])
- t7.start()
- self.assertEqual(t7.accept().body, "a");
- t7.verify(sessions, ["b", "c"])
-
- # Ended, suspended transactions across join.
- t8 = DtxTestFixture(self, cluster[0], "t8")
- t8.start(id="1")
- t8.send(["x"])
- t8.end(id="1", suspend=True)
- t8.start(id="2")
- t8.send(["y"])
- t8.end(id="2")
- t8.start()
- t8.send("z")
-
-
- # Start new cluster member
- cluster.start()
- sessions.append(cluster[1].connect().session())
-
- # Commit t1
- t1.send(["3","4"])
- t1.verify(sessions, [])
- t1.end()
- t1.commit(one_phase=True)
- t1.verify(sessions, ["1","2","3","4"])
-
- # Rollback t2
- t2.send(["3","4"])
- t2.end()
- t2.rollback()
- t2.verify(sessions, [])
-
- # Commit t3
- t3.commit(one_phase=False)
- t3.verify(sessions, ["1","2"])
-
- # Rollback t4
- t4.rollback()
- t4.verify(sessions, [])
-
- # Commit t5
- t5.send(["3","4"])
- t5.verify(sessions, [])
- t5.end()
- t5.commit(one_phase=True)
- t5.verify(sessions, ["1","2","3","4"])
-
- # Commit t6
- self.assertEqual(t6.accept().body, "b");
- t6.verify(sessions, ["c"])
- t6.end()
- t6.commit(one_phase=True)
- t6.session.close() # Make sure they're not requeued by the session.
- t6.verify(sessions, ["c"])
-
- # Rollback t7
- self.assertEqual(t7.accept().body, "b");
- t7.verify(sessions, ["c"])
- t7.end()
- t7.rollback()
- t7.verify(sessions, ["a", "b", "c"])
-
- # Resume t8
- t8.end()
- t8.commit(one_phase=True)
- t8.start("1", resume=True)
- t8.end("1")
- t8.commit("1", one_phase=True)
- t8.commit("2", one_phase=True)
- t8.verify(sessions, ["z", "x","y"])
-
-
- def test_dtx_failover_rollback(self):
- """Kill a broker during a transaction, verify we roll back correctly"""
- cluster=self.cluster(1, expect=EXPECT_EXIT_FAIL)
- cluster.start(expect=EXPECT_RUNNING)
-
- # Test unprepared at crash
- t1 = DtxTestFixture(self, cluster[0], "t1")
- t1.send(["a"]) # Not in transaction
- t1.start()
- t1.send(["b"]) # In transaction
-
- # Test prepared at crash
- t2 = DtxTestFixture(self, cluster[0], "t2")
- t2.send(["a"]) # Not in transaction
- t2.start()
- t2.send(["b"]) # In transaction
- t2.end()
- t2.prepare()
-
- # Crash the broker
- cluster[0].kill()
-
- # Transactional changes should not appear
- s = cluster[1].connect().session();
- self.assert_browse(s, "t1", ["a"])
- self.assert_browse(s, "t2", ["a"])
-
- def test_dtx_timeout(self):
- """Verify that dtx timeout works"""
- cluster = self.cluster(1)
- t1 = DtxTestFixture(self, cluster[0], "t1")
- t1.start()
- t1.set_timeout(1)
- time.sleep(1.1)
- try:
- t1.end()
- self.fail("Expected rollback timeout.")
- except DtxStatusException, e:
- self.assertEqual(e.actual, XA_RBTIMEOUT)
-
-class TxTests(BrokerTest):
-
- def test_tx_update(self):
- """Verify that transaction state is updated to a new broker"""
-
- def make_message(session, body=None, key=None, id=None):
- dp=session.delivery_properties(routing_key=key)
- mp=session.message_properties(correlation_id=id)
- return qpid.datatypes.Message(dp, mp, body)
-
- cluster=self.cluster(1)
- # Use old API. TX is not supported in messaging API.
- c = cluster[0].connect_old()
- s = c.session("tx-session", 1)
- s.queue_declare(queue="q")
- # Start transaction
- s.tx_select()
- s.message_transfer(message=make_message(s, "1", "q"))
- # Start new member mid-transaction
- cluster.start()
- # Do more work
- s.message_transfer(message=make_message(s, "2", "q"))
- # Commit the transaction and verify the results.
- s.tx_commit()
- for b in cluster: self.assert_browse(b.connect().session(), "q", ["1","2"])
-
-
-class LongTests(BrokerTest):
- """Tests that can run for a long time if -DDURATION=<minutes> is set"""
- def duration(self):
- d = self.config.defines.get("DURATION")
- if d: return float(d)*60
- else: return 3 # Default is to be quick
-
- def test_failover(self):
- """Test fail-over during continuous send-receive with errors"""
-
- # Original cluster will all be killed so expect exit with failure
- cluster = self.cluster(3, expect=EXPECT_EXIT_FAIL)
- for b in cluster: b.ready() # Wait for brokers to be ready
- for b in cluster: ErrorGenerator(b)
-
- # Start sender and receiver threads
- cluster[0].declare_queue("test-queue")
- sender = NumberedSender(cluster[0], max_depth=1000)
- receiver = NumberedReceiver(cluster[0], sender=sender)
- receiver.start()
- sender.start()
- # Wait for sender & receiver to get up and running
- retry(lambda: receiver.received > 0)
-
- # Kill original brokers, start new ones for the duration.
- endtime = time.time() + self.duration()
- i = 0
- while time.time() < endtime:
- sender.sender.assert_running()
- receiver.receiver.assert_running()
- cluster[i].kill()
- i += 1
- b = cluster.start(expect=EXPECT_EXIT_FAIL)
- for b in cluster[i:]: b.ready()
- ErrorGenerator(b)
- time.sleep(5)
- sender.stop()
- receiver.stop()
- for i in range(i, len(cluster)): cluster[i].kill()
-
- def test_management(self, args=[]):
- """
- Stress test: Run management clients and other clients concurrently
- while killing and restarting brokers.
- """
-
- class ClientLoop(StoppableThread):
- """Run a client executable in a loop."""
- def __init__(self, broker, cmd):
- StoppableThread.__init__(self)
- self.broker=broker
- self.cmd = cmd # Client command.
- self.lock = Lock()
- self.process = None # Client process.
- self.start()
-
- def run(self):
- try:
- while True:
- self.lock.acquire()
- try:
- if self.stopped: break
- self.process = self.broker.test.popen(
- self.cmd, expect=EXPECT_UNKNOWN)
- finally:
- self.lock.release()
- try:
- exit = self.process.wait()
- except OSError, e:
- # Process may already have been killed by self.stop()
- break
- except Exception, e:
- self.process.unexpected(
- "client of %s: %s"%(self.broker.name, e))
- self.lock.acquire()
- try:
- if self.stopped: break
- if exit != 0:
- self.process.unexpected(
- "client of %s exit code %s"%(self.broker.name, exit))
- finally:
- self.lock.release()
- except Exception, e:
- self.error = RethrownException("Error in ClientLoop.run")
-
- def stop(self):
- """Stop the running client and wait for it to exit"""
- self.lock.acquire()
- try:
- if self.stopped: return
- self.stopped = True
- if self.process:
- try: self.process.kill() # Kill the client.
- except OSError: pass # The client might not be running.
- finally: self.lock.release()
- StoppableThread.stop(self)
-
- # body of test_management()
-
- args += ["--mgmt-pub-interval", 1]
- args += ["--log-enable=trace+:management"]
- # Use store if present.
- if BrokerTest.store_lib: args +=["--load-module", BrokerTest.store_lib]
- cluster = self.cluster(3, args, expect=EXPECT_EXIT_FAIL) # brokers will be killed
-
- clients = [] # Per-broker list of clients that only connect to one broker.
- mclients = [] # Management clients that connect to every broker in the cluster.
-
- def start_clients(broker):
- """Start ordinary clients for a broker."""
- cmds=[
- ["qpid-tool", "localhost:%s"%(broker.port())],
- ["qpid-perftest", "--count=5000", "--durable=yes",
- "--base-name", str(qpid.datatypes.uuid4()), "--port", broker.port()],
- ["qpid-txtest", "--queue-base-name", "tx-%s"%str(qpid.datatypes.uuid4()),
- "--port", broker.port()],
- ["qpid-queue-stats", "-a", "localhost:%s" %(broker.port())]
- ]
- clients.append([ClientLoop(broker, cmd) for cmd in cmds])
-
- def start_mclients(broker):
- """Start management clients that make multiple connections."""
- cmd = ["qpid-cluster", "-C", "localhost:%s" %(broker.port())]
- mclients.append(ClientLoop(broker, cmd))
-
- endtime = time.time() + self.duration()
- # For long duration, first run is a quarter of the duration.
- runtime = min(5.0, self.duration() / 3.0)
- alive = 0 # First live cluster member
- for i in range(len(cluster)): start_clients(cluster[i])
- start_mclients(cluster[alive])
-
- while time.time() < endtime:
- time.sleep(runtime)
- runtime = 5 # Remaining runs 5 seconds, frequent broker kills
- for b in cluster[alive:]: b.ready() # Check if a broker crashed.
- # Kill the first broker, expect the clients to fail.
- b = cluster[alive]
- b.ready()
- b.kill()
- # Stop the brokers clients and all the mclients.
- for c in clients[alive] + mclients:
- try: c.stop()
- except: pass # Ignore expected errors due to broker shutdown.
- clients[alive] = []
- mclients = []
- # Start another broker and clients
- alive += 1
- cluster.start(expect=EXPECT_EXIT_FAIL)
- cluster[-1].ready() # Wait till its ready
- start_clients(cluster[-1])
- start_mclients(cluster[alive])
- for c in chain(mclients, *clients):
- c.stop()
- for b in cluster[alive:]:
- b.ready() # Verify still alive
- b.kill()
- # Verify that logs are consistent
- cluster_test_logs.verify_logs()
-
- def test_management_qmf2(self):
- self.test_management(args=["--mgmt-qmf2=yes"])
-
- def test_connect_consistent(self):
- args=["--mgmt-pub-interval=1","--log-enable=trace+:management"]
- cluster = self.cluster(2, args=args)
- end = time.time() + self.duration()
- while (time.time() < end): # Get a management interval
- for i in xrange(1000): cluster[0].connect().close()
- cluster_test_logs.verify_logs()
-
- def test_flowlimit_failover(self):
- """Test fail-over during continuous send-receive with flow control
- active.
- """
-
- # Original cluster will all be killed so expect exit with failure
- cluster = self.cluster(3, expect=EXPECT_EXIT_FAIL)
- for b in cluster: b.ready() # Wait for brokers to be ready
-
- # create a queue with rather draconian flow control settings
- ssn0 = cluster[0].connect().session()
- s0 = ssn0.sender("test-queue; {create:always, node:{type:queue, x-declare:{arguments:{'qpid.flow_stop_count':2000, 'qpid.flow_resume_count':100}}}}")
-
- receiver = NumberedReceiver(cluster[0])
- receiver.start()
- sender = NumberedSender(cluster[0])
- sender.start()
- # Wait for senders & receiver to get up and running
- retry(lambda: receiver.received > 10)
-
- # Kill original brokers, start new ones for the duration.
- endtime = time.time() + self.duration();
- i = 0
- while time.time() < endtime:
- sender.sender.assert_running()
- receiver.receiver.assert_running()
- for b in cluster[i:]: b.ready() # Check if any broker crashed.
- cluster[i].kill()
- i += 1
- b = cluster.start(expect=EXPECT_EXIT_FAIL)
- time.sleep(5)
- sender.stop()
- receiver.stop()
- for i in range(i, len(cluster)): cluster[i].kill()
-
- def test_ttl_failover(self):
- """Test that messages with TTL don't cause problems in a cluster with failover"""
-
- class Client(StoppableThread):
-
- def __init__(self, broker):
- StoppableThread.__init__(self)
- self.connection = broker.connect(reconnect=True)
- self.auto_fetch_reconnect_urls(self.connection)
- self.session = self.connection.session()
-
- def auto_fetch_reconnect_urls(self, conn):
- """Replacment for qpid.messaging.util version which is noisy"""
- ssn = conn.session("auto-fetch-reconnect-urls")
- rcv = ssn.receiver("amq.failover")
- rcv.capacity = 10
-
- def main():
- while True:
- try:
- msg = rcv.fetch()
- qpid.messaging.util.set_reconnect_urls(conn, msg)
- ssn.acknowledge(msg, sync=False)
- except messaging.exceptions.LinkClosed: return
- except messaging.exceptions.ConnectionError: return
-
- thread = Thread(name="auto-fetch-reconnect-urls", target=main)
- thread.setDaemon(True)
- thread.start()
-
- def stop(self):
- StoppableThread.stop(self)
- self.connection.detach()
-
- class Sender(Client):
- def __init__(self, broker, address):
- Client.__init__(self, broker)
- self.sent = 0 # Number of messages _reliably_ sent.
- self.sender = self.session.sender(address, capacity=1000)
-
- def send_counted(self, ttl):
- self.sender.send(Message(str(self.sent), ttl=ttl))
- self.sent += 1
-
- def run(self):
- while not self.stopped:
- choice = random.randint(0,4)
- if choice == 0: self.send_counted(None) # No ttl
- elif choice == 1: self.send_counted(100000) # Large ttl
- else: # Small ttl, might expire
- self.sender.send(Message("", ttl=random.random()/10))
- self.sender.send(Message("z"), sync=True) # Chaser.
-
- class Receiver(Client):
-
- def __init__(self, broker, address):
- Client.__init__(self, broker)
- self.received = 0 # Number of non-empty (reliable) messages received.
- self.receiver = self.session.receiver(address, capacity=1000)
- def run(self):
- try:
- while True:
- m = self.receiver.fetch(1)
- if m.content == "z": break
- if m.content: # Ignore unreliable messages
- # Ignore duplicates
- if int(m.content) == self.received: self.received += 1
- except Exception,e: self.error = e
-
- # def test_ttl_failover
-
- # Original cluster will all be killed so expect exit with failure
- # Set small purge interval.
- cluster = self.cluster(3, expect=EXPECT_EXIT_FAIL, args=["--queue-purge-interval=1"])
- for b in cluster: b.ready() # Wait for brokers to be ready
-
- # Python client failover produces noisy WARN logs, disable temporarily
- logger = logging.getLogger()
- log_level = logger.getEffectiveLevel()
- logger.setLevel(logging.ERROR)
- sender = None
- receiver = None
- try:
- # Start sender and receiver threads
- receiver = Receiver(cluster[0], "q;{create:always}")
- receiver.start()
- sender = Sender(cluster[0], "q;{create:always}")
- sender.start()
- # Wait for sender & receiver to get up and running
- retry(lambda: receiver.received > 0)
-
- # Kill brokers in a cycle.
- endtime = time.time() + self.duration()
- runtime = min(5.0, self.duration() / 4.0)
- i = 0
- while time.time() < endtime:
- for b in cluster[i:]: b.ready() # Check if any broker crashed.
- cluster[i].kill()
- i += 1
- b = cluster.start(expect=EXPECT_EXIT_FAIL)
- b.ready()
- time.sleep(runtime)
- sender.stop()
- receiver.stop()
- for b in cluster[i:]:
- b.ready() # Check it didn't crash
- b.kill()
- self.assertEqual(sender.sent, receiver.received)
- cluster_test_logs.verify_logs()
-
- finally:
- # Detach to avoid slow reconnect attempts during shut-down if test fails.
- if sender: sender.connection.detach()
- if receiver: receiver.connection.detach()
- logger.setLevel(log_level)
-
- def test_msg_group_failover(self):
- """Test fail-over during continuous send-receive of grouped messages.
- """
-
- class GroupedTrafficGenerator(Thread):
- def __init__(self, url, queue, group_key):
- Thread.__init__(self)
- self.url = url
- self.queue = queue
- self.group_key = group_key
- self.status = -1
-
- def run(self):
- # generate traffic for approx 10 seconds (2011msgs / 200 per-sec)
- cmd = ["msg_group_test",
- "--broker=%s" % self.url,
- "--address=%s" % self.queue,
- "--connection-options={%s}" % (Cluster.CONNECTION_OPTIONS),
- "--group-key=%s" % self.group_key,
- "--receivers=2",
- "--senders=3",
- "--messages=2011",
- "--send-rate=200",
- "--capacity=11",
- "--ack-frequency=23",
- "--allow-duplicates",
- "--group-size=37",
- "--randomize-group-size",
- "--interleave=13"]
- # "--trace"]
- self.generator = Popen( cmd );
- self.status = self.generator.wait()
- return self.status
-
- def results(self):
- self.join(timeout=30) # 3x assumed duration
- if self.isAlive(): return -1
- return self.status
-
- # Original cluster will all be killed so expect exit with failure
- cluster = self.cluster(3, expect=EXPECT_EXIT_FAIL, args=["-t"])
- for b in cluster: b.ready() # Wait for brokers to be ready
-
- # create a queue with rather draconian flow control settings
- ssn0 = cluster[0].connect().session()
- q_args = "{'qpid.group_header_key':'group-id', 'qpid.shared_msg_group':1}"
- s0 = ssn0.sender("test-group-q; {create:always, node:{type:queue, x-declare:{arguments:%s}}}" % q_args)
-
- # Kill original brokers, start new ones for the duration.
- endtime = time.time() + self.duration();
- i = 0
- while time.time() < endtime:
- traffic = GroupedTrafficGenerator( cluster[i].host_port(),
- "test-group-q", "group-id" )
- traffic.start()
- time.sleep(1)
-
- for x in range(2):
- for b in cluster[i:]: b.ready() # Check if any broker crashed.
- cluster[i].kill()
- i += 1
- b = cluster.start(expect=EXPECT_EXIT_FAIL)
- time.sleep(1)
-
- # wait for traffic to finish, verify success
- self.assertEqual(0, traffic.results())
-
- for i in range(i, len(cluster)): cluster[i].kill()
-
-
-class StoreTests(BrokerTest):
- """
- Cluster tests that can only be run if there is a store available.
- """
- def args(self):
- assert BrokerTest.store_lib
- return ["--load-module", BrokerTest.store_lib]
-
- def test_store_loaded(self):
- """Ensure we are indeed loading a working store"""
- broker = self.broker(self.args(), name="recoverme", expect=EXPECT_EXIT_FAIL)
- m = Message("x", durable=True)
- broker.send_message("q", m)
- broker.kill()
- broker = self.broker(self.args(), name="recoverme")
- self.assertEqual("x", broker.get_message("q").content)
-
- def test_kill_restart(self):
- """Verify we can kill/resetart a broker with store in a cluster"""
- cluster = self.cluster(1, self.args())
- cluster.start("restartme", expect=EXPECT_EXIT_FAIL).kill()
-
- # Send a message, retrieve from the restarted broker
- cluster[0].send_message("q", "x")
- m = cluster.start("restartme").get_message("q")
- self.assertEqual("x", m.content)
-
- def stop_cluster(self,broker):
- """Clean shut-down of a cluster"""
- self.assertEqual(0, qpid_cluster.main(
- ["-kf", broker.host_port()]))
-
- def test_persistent_restart(self):
- """Verify persistent cluster shutdown/restart scenarios"""
- cluster = self.cluster(0, args=self.args() + ["--cluster-size=3"])
- a = cluster.start("a", expect=EXPECT_EXIT_OK, wait=False)
- b = cluster.start("b", expect=EXPECT_EXIT_OK, wait=False)
- c = cluster.start("c", expect=EXPECT_EXIT_FAIL, wait=True)
- a.send_message("q", Message("1", durable=True))
- # Kill & restart one member.
- c.kill()
- self.assertEqual(a.get_message("q").content, "1")
- a.send_message("q", Message("2", durable=True))
- c = cluster.start("c", expect=EXPECT_EXIT_OK)
- self.assertEqual(c.get_message("q").content, "2")
- # Shut down the entire cluster cleanly and bring it back up
- a.send_message("q", Message("3", durable=True))
- self.stop_cluster(a)
- a = cluster.start("a", wait=False)
- b = cluster.start("b", wait=False)
- c = cluster.start("c", wait=True)
- self.assertEqual(a.get_message("q").content, "3")
-
- def test_persistent_partial_failure(self):
- # Kill 2 members, shut down the last cleanly then restart
- # Ensure we use the clean database
- cluster = self.cluster(0, args=self.args() + ["--cluster-size=3"])
- a = cluster.start("a", expect=EXPECT_EXIT_FAIL, wait=False)
- b = cluster.start("b", expect=EXPECT_EXIT_FAIL, wait=False)
- c = cluster.start("c", expect=EXPECT_EXIT_OK, wait=True)
- a.send_message("q", Message("4", durable=True))
- a.kill()
- b.kill()
- self.assertEqual(c.get_message("q").content, "4")
- c.send_message("q", Message("clean", durable=True))
- self.stop_cluster(c)
- a = cluster.start("a", wait=False)
- b = cluster.start("b", wait=False)
- c = cluster.start("c", wait=True)
- self.assertEqual(a.get_message("q").content, "clean")
-
- def test_wrong_cluster_id(self):
- # Start a cluster1 broker, then try to restart in cluster2
- cluster1 = self.cluster(0, args=self.args())
- a = cluster1.start("a", expect=EXPECT_EXIT_OK)
- a.terminate()
- cluster2 = self.cluster(1, args=self.args())
- try:
- a = cluster2.start("a", expect=EXPECT_EXIT_FAIL)
- a.ready()
- self.fail("Expected exception")
- except: pass
-
- def test_wrong_shutdown_id(self):
- # Start 2 members and shut down.
- cluster = self.cluster(0, args=self.args()+["--cluster-size=2"])
- a = cluster.start("a", expect=EXPECT_EXIT_OK, wait=False)
- b = cluster.start("b", expect=EXPECT_EXIT_OK, wait=False)
- self.stop_cluster(a)
- self.assertEqual(a.wait(), 0)
- self.assertEqual(b.wait(), 0)
-
- # Restart with a different member and shut down.
- a = cluster.start("a", expect=EXPECT_EXIT_OK, wait=False)
- c = cluster.start("c", expect=EXPECT_EXIT_OK, wait=False)
- self.stop_cluster(a)
- self.assertEqual(a.wait(), 0)
- self.assertEqual(c.wait(), 0)
- # Mix members from both shutdown events, they should fail
- # TODO aconway 2010-03-11: can't predict the exit status of these
- # as it depends on the order of delivery of initial-status messages.
- # See comment at top of this file.
- a = cluster.start("a", expect=EXPECT_UNKNOWN, wait=False)
- b = cluster.start("b", expect=EXPECT_UNKNOWN, wait=False)
- self.assertRaises(Exception, lambda: a.ready())
- self.assertRaises(Exception, lambda: b.ready())
-
- def test_solo_store_clean(self):
- # A single node cluster should always leave a clean store.
- cluster = self.cluster(0, self.args())
- a = cluster.start("a", expect=EXPECT_EXIT_FAIL)
- a.send_message("q", Message("x", durable=True))
- a.kill()
- a = cluster.start("a")
- self.assertEqual(a.get_message("q").content, "x")
-
- def test_last_store_clean(self):
- # Verify that only the last node in a cluster to shut down has
- # a clean store. Start with cluster of 3, reduce to 1 then
- # increase again to ensure that a node that was once alone but
- # finally did not finish as the last node does not get a clean
- # store.
- cluster = self.cluster(0, self.args())
- a = cluster.start("a", expect=EXPECT_EXIT_FAIL)
- self.assertEqual(a.store_state(), "clean")
- b = cluster.start("b", expect=EXPECT_EXIT_FAIL)
- c = cluster.start("c", expect=EXPECT_EXIT_FAIL)
- self.assertEqual(b.store_state(), "dirty")
- self.assertEqual(c.store_state(), "dirty")
- retry(lambda: a.store_state() == "dirty")
-
- a.send_message("q", Message("x", durable=True))
- a.kill()
- b.kill() # c is last man, will mark store clean
- retry(lambda: c.store_state() == "clean")
- a = cluster.start("a", expect=EXPECT_EXIT_FAIL) # c no longer last man
- retry(lambda: c.store_state() == "dirty")
- c.kill() # a is now last man
- retry(lambda: a.store_state() == "clean")
- a.kill()
- self.assertEqual(a.store_state(), "clean")
- self.assertEqual(b.store_state(), "dirty")
- self.assertEqual(c.store_state(), "dirty")
-
- def test_restart_clean(self):
- """Verify that we can re-start brokers one by one in a
- persistent cluster after a clean oshutdown"""
- cluster = self.cluster(0, self.args())
- a = cluster.start("a", expect=EXPECT_EXIT_OK)
- b = cluster.start("b", expect=EXPECT_EXIT_OK)
- c = cluster.start("c", expect=EXPECT_EXIT_OK)
- a.send_message("q", Message("x", durable=True))
- self.stop_cluster(a)
- a = cluster.start("a")
- b = cluster.start("b")
- c = cluster.start("c")
- self.assertEqual(c.get_message("q").content, "x")
-
- def test_join_sub_size(self):
- """Verify that after starting a cluster with cluster-size=N,
- we can join new members even if size < N-1"""
- cluster = self.cluster(0, self.args()+["--cluster-size=3"])
- a = cluster.start("a", wait=False, expect=EXPECT_EXIT_FAIL)
- b = cluster.start("b", wait=False, expect=EXPECT_EXIT_FAIL)
- c = cluster.start("c")
- a.send_message("q", Message("x", durable=True))
- a.send_message("q", Message("y", durable=True))
- a.kill()
- b.kill()
- a = cluster.start("a")
- self.assertEqual(c.get_message("q").content, "x")
- b = cluster.start("b")
- self.assertEqual(c.get_message("q").content, "y")
diff --git a/cpp/src/tests/clustered_replication_test b/cpp/src/tests/clustered_replication_test
deleted file mode 100755
index 5a9f143eb4..0000000000
--- a/cpp/src/tests/clustered_replication_test
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/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.
-#
-
-# Test reliability of the replication feature in the face of link
-# failures:
-source ./test_env.sh
-
-trap stop_brokers INT EXIT
-
-fail() {
- echo $1
- exit 1
-}
-
-stop_brokers() {
- if [[ $PRIMARY1 ]] ; then
- $QPIDD_EXEC --no-module-dir -q --port $PRIMARY1
- unset PRIMARY1
- fi
- if [[ $PRIMARY2 ]] ; then
- $QPIDD_EXEC --no-module-dir -q --port $PRIMARY2
- unset PRIMARY2
- fi
- if [[ $DR1 ]] ; then
- $QPIDD_EXEC --no-module-dir -q --port $DR1
- unset DR1
- fi
- if [[ $DR2 ]] ; then
- $QPIDD_EXEC --no-module-dir -q --port $DR2
- unset DR2
- fi
-}
-
-if test -d $PYTHON_DIR; then
- . cpg_check.sh
- cpg_enabled || exit 0
-
- #todo: these cluster names need to be unique to prevent clashes
- PRIMARY_CLUSTER=PRIMARY_$(hostname)_$$
- DR_CLUSTER=DR_$(hostname)_$$
-
- GENERAL_OPTS="--auth no --no-module-dir --no-data-dir --daemon --port 0 --log-to-stderr false"
- PRIMARY_OPTS="--load-module $REPLICATING_LISTENER_LIB --create-replication-queue true --replication-queue REPLICATION_QUEUE --load-module $CLUSTER_LIB --cluster-name $PRIMARY_CLUSTER"
- DR_OPTS="--load-module $REPLICATION_EXCHANGE_LIB --load-module $CLUSTER_LIB --cluster-name $DR_CLUSTER"
-
- rm -f repl*.tmp #cleanup any files left from previous run
-
- #start first node of primary cluster and set up test queue
- echo Starting primary cluster
- PRIMARY1=$(with_ais_group $QPIDD_EXEC $GENERAL_OPTS $PRIMARY_OPTS --log-to-file repl.primary.1.tmp) || fail "Could not start PRIMARY1"
- $PYTHON_COMMANDS/qpid-config -b "localhost:$PRIMARY1" add queue test-queue --generate-queue-events 2
- $PYTHON_COMMANDS/qpid-config -b "localhost:$PRIMARY1" add queue control-queue --generate-queue-events 1
-
- #send 10 messages, consume 5 of them
- for i in `seq 1 10`; do echo Message$i; done | ./sender --port $PRIMARY1
- ./receiver --port $PRIMARY1 --messages 5 > /dev/null
-
- #add new node to primary cluster, testing correct transfer of state:
- echo Adding node to primary cluster
- PRIMARY2=$(with_ais_group $QPIDD_EXEC $GENERAL_OPTS $PRIMARY_OPTS --log-to-file repl.primary.2.tmp) || fail "Could not start PRIMARY2 "
-
- #start DR cluster, set up test queue there and establish replication bridge
- echo Starting DR cluster
- DR1=$(with_ais_group $QPIDD_EXEC $GENERAL_OPTS $DR_OPTS --log-to-file repl.dr.1.tmp) || fail "Could not start DR1"
- DR2=$(with_ais_group $QPIDD_EXEC $GENERAL_OPTS $DR_OPTS --log-to-file repl.dr.2.tmp) || fail "Could not start DR2"
-
- $PYTHON_COMMANDS/qpid-config -b "localhost:$DR1" add queue test-queue
- $PYTHON_COMMANDS/qpid-config -b "localhost:$DR1" add queue control-queue
- $PYTHON_COMMANDS/qpid-config -b "localhost:$DR1" add exchange replication REPLICATION_EXCHANGE
- $PYTHON_COMMANDS/qpid-route queue add localhost:$DR2 localhost:$PRIMARY2 REPLICATION_EXCHANGE REPLICATION_QUEUE || fail "Could not add route."
-
- #send more messages to primary
- for i in `seq 11 20`; do echo Message$i; done | ./sender --port $PRIMARY1 --send-eos 1
-
- #wait for replication events to all be processed:
- echo Waiting for replication to complete
- echo Done | ./sender --port $PRIMARY1 --routing-key control-queue --send-eos 1
- ./receiver --queue control-queue --port $DR1 > /dev/null
-
- #verify contents of test queue on dr cluster:
- echo Verifying...
- ./receiver --port $DR2 > repl.out.tmp
- for i in `seq 6 20`; do echo Message$i; done | diff repl.out.tmp - || FAIL=1
-
- if [[ $FAIL ]]; then
- echo Clustered replication test failed: expectations not met!
- exit 1
- else
- echo Clustered replication test passed
- rm -f repl*.tmp
- fi
-
-fi
diff --git a/cpp/src/tests/cpg_check.sh.in b/cpp/src/tests/cpg_check.sh.in
deleted file mode 100755
index ed97776218..0000000000
--- a/cpp/src/tests/cpg_check.sh.in
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/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.
-#
-
-QPID_USE_CPG=${QPID_USE_CPG:-@USE_CPG@}
-
-# Check if CPG is enabled
-cpg_enabled() {
- test x$QPID_USE_CPG = xyes || return 1 # disabled
- ps -u root | grep 'aisexec\|corosync' >/dev/null || {
- echo WARNING: Skip cluster tests, aisexec or corosync daemon is not running.
- return 1; # A warning, not a failure.
- }
- return 0
-}
-
-# Execute command with the ais group set if user is a member.
-with_ais_group() {
- if id -nG | grep '\<ais\>' >/dev/null; then sg ais -c "$*"
- else "$@"
- fi
-}
diff --git a/cpp/src/tests/dynamic_log_hires_timestamp b/cpp/src/tests/dynamic_log_hires_timestamp
new file mode 100755
index 0000000000..afe79cc9b3
--- /dev/null
+++ b/cpp/src/tests/dynamic_log_hires_timestamp
@@ -0,0 +1,75 @@
+#!/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.
+#
+
+# Run a simple test to verify dynamic log highres timestamp changes
+source ./test_env.sh
+test -d $PYTHON_DIR || { echo "Skipping python tests, no python dir."; exit 0; }
+
+LOG_FILE=hires_test.log
+trap cleanup EXIT
+
+cleanup() {
+ test -n "$PORT" && $QPIDD_EXEC --no-module-dir --quit --port $PORT
+}
+
+error() {
+ echo $*;
+ exit 1;
+}
+
+rm -rf $LOG_FILE
+PORT=$($QPIDD_EXEC --auth=no --no-module-dir --daemon --port=0 --log-to-file $LOG_FILE) || error "Could not start broker"
+
+echo Broker for log highres timestamp test started on $PORT, pid is $($QPIDD_EXEC --no-module-dir --check --port $PORT)
+
+$srcdir/qpid-ctrl -b localhost:$PORT setLogLevel level='debug+:Broker' > /dev/null
+$srcdir/qpid-ctrl -b localhost:$PORT echo sequence=1 body=LOWRES > /dev/null
+$srcdir/qpid-ctrl -b localhost:$PORT setLogHiresTimestamp logHires='true' > /dev/null
+$srcdir/qpid-ctrl -b localhost:$PORT echo sequence=2 body=HI_RES > /dev/null
+$srcdir/qpid-ctrl -b localhost:$PORT setLogHiresTimestamp logHires='false' > /dev/null
+$srcdir/qpid-ctrl -b localhost:$PORT echo sequence=3 body=LOWRES > /dev/null
+
+# Expect 3 log entries with 'echo' in them
+if [[ $(grep echo $LOG_FILE | wc -l) -ne 3 ]]; then
+ cat $LOG_FILE
+ error "Log content error - expected 3 echo log entries"
+fi
+
+# Lines 1 and 3 are length X
+# Line 2 is length X+10 because of timestamp addition
+LEN1=$(grep echo $LOG_FILE | grep \(1 | wc -m)
+LEN2=$(grep echo $LOG_FILE | grep \(2 | wc -m)
+LEN3=$(grep echo $LOG_FILE | grep \(3 | wc -m)
+EXPECTED_LEN2=$(( $LEN1 + 10 ))
+
+if [ $LEN1 -ne $LEN3 ]; then
+ cat $LOG_FILE
+ error "Log content error - expected echo 3 to be same line length as echo 1"
+fi
+
+if [ $LEN2 -ne $EXPECTED_LEN2 ]; then
+ cat $LOG_FILE
+ error "Log content error - expected echo 2 to be 10 characters longer than echo 1"
+fi
+
+rm -rf $LOG_FILE
+echo OK
+
diff --git a/cpp/src/tests/failover_soak.cpp b/cpp/src/tests/failover_soak.cpp
deleted file mode 100644
index c2ac36a757..0000000000
--- a/cpp/src/tests/failover_soak.cpp
+++ /dev/null
@@ -1,827 +0,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.
- *
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <string.h>
-#include <sys/types.h>
-#include <signal.h>
-
-#include <string>
-#include <iostream>
-#include <sstream>
-#include <vector>
-
-#include <boost/assign.hpp>
-
-#include "qpid/framing/Uuid.h"
-
-#include <ForkedBroker.h>
-#include <qpid/client/Connection.h>
-
-
-
-
-
-using namespace std;
-using boost::assign::list_of;
-using namespace qpid::framing;
-using namespace qpid::client;
-
-
-namespace qpid {
-namespace tests {
-
-vector<pid_t> pids;
-
-typedef vector<ForkedBroker *> brokerVector;
-
-typedef enum
-{
- NO_STATUS,
- RUNNING,
- COMPLETED
-}
-childStatus;
-
-
-typedef enum
-{
- NO_TYPE,
- DECLARING_CLIENT,
- SENDING_CLIENT,
- RECEIVING_CLIENT
-}
-childType;
-
-
-ostream& operator<< ( ostream& os, const childType& ct ) {
- switch ( ct ) {
- case DECLARING_CLIENT: os << "Declaring Client"; break;
- case SENDING_CLIENT: os << "Sending Client"; break;
- case RECEIVING_CLIENT: os << "Receiving Client"; break;
- default: os << "No Client"; break;
- }
-
- return os;
-}
-
-
-
-
-struct child
-{
- child ( string & name, pid_t pid, childType type )
- : name(name), pid(pid), retval(-999), status(RUNNING), type(type)
- {
- gettimeofday ( & startTime, 0 );
- }
-
-
- void
- done ( int _retval )
- {
- retval = _retval;
- status = COMPLETED;
- gettimeofday ( & stopTime, 0 );
- }
-
-
- void
- setType ( childType t )
- {
- type = t;
- }
-
-
- string name;
- pid_t pid;
- int retval;
- childStatus status;
- childType type;
- struct timeval startTime,
- stopTime;
-};
-
-
-
-
-struct children : public vector<child *>
-{
-
- void
- add ( string & name, pid_t pid, childType type )
- {
- push_back ( new child ( name, pid, type ) );
- }
-
-
- child *
- get ( pid_t pid )
- {
- vector<child *>::iterator i;
- for ( i = begin(); i != end(); ++ i )
- if ( pid == (*i)->pid )
- return *i;
-
- return 0;
- }
-
-
- void
- exited ( pid_t pid, int retval )
- {
- child * kid = get ( pid );
- if(! kid)
- {
- if ( verbosity > 1 )
- {
- cerr << "children::exited warning: Can't find child with pid "
- << pid
- << endl;
- }
- return;
- }
-
- kid->done ( retval );
- }
-
-
- int
- unfinished ( )
- {
- int count = 0;
-
- vector<child *>::iterator i;
- for ( i = begin(); i != end(); ++ i )
- if ( COMPLETED != (*i)->status )
- ++ count;
-
- return count;
- }
-
-
- int
- checkChildren ( )
- {
- for ( unsigned int i = 0; i < pids.size(); ++ i )
- {
- int pid = pids[i];
- int returned_pid;
- int status;
-
- child * kid = get ( pid );
-
- if ( kid->status != COMPLETED )
- {
- returned_pid = waitpid ( pid, &status, WNOHANG );
-
- if ( returned_pid == pid )
- {
- int exit_status = WEXITSTATUS(status);
- exited ( pid, exit_status );
- if ( exit_status ) // this is a child error.
- return exit_status;
- }
- }
- }
-
- return 0;
- }
-
-
- void
- killEverybody ( )
- {
- vector<child *>::iterator i;
- for ( i = begin(); i != end(); ++ i )
- kill ( (*i)->pid, 9 );
- }
-
-
-
- void
- print ( )
- {
- cout << "--- status of all children --------------\n";
- vector<child *>::iterator i;
- for ( i = begin(); i != end(); ++ i )
- cout << "child: " << (*i)->name
- << " status: " << (*i)->status
- << endl;
- cout << "\n\n\n\n";
- }
-
- int verbosity;
-};
-
-
-children allMyChildren;
-
-
-void
-childExit ( int )
-{
- int childReturnCode;
- pid_t pid = waitpid ( 0, & childReturnCode, WNOHANG);
-
- if ( pid > 0 )
- allMyChildren.exited ( pid, childReturnCode );
-}
-
-
-
-int
-mrand ( int maxDesiredVal ) {
- double zeroToOne = (double) rand() / (double) RAND_MAX;
- return (int) (zeroToOne * (double) maxDesiredVal);
-}
-
-
-
-int
-mrand ( int minDesiredVal, int maxDesiredVal ) {
- int interval = maxDesiredVal - minDesiredVal;
- return minDesiredVal + mrand ( interval );
-}
-
-
-
-void
-makeClusterName ( string & s ) {
- stringstream ss;
- ss << "soakTestCluster_" << Uuid(true).str();
- s = ss.str();
-}
-
-
-
-
-
-void
-printBrokers ( brokerVector & brokers )
-{
- cout << "Broker List ------------ size: " << brokers.size() << "\n";
- for ( brokerVector::iterator i = brokers.begin(); i != brokers.end(); ++ i) {
- cout << "pid: "
- << (*i)->getPID()
- << " port: "
- << (*i)->getPort()
- << endl;
- }
- cout << "end Broker List ------------\n";
-}
-
-
-
-
-ForkedBroker * newbie = 0;
-int newbie_port = 0;
-
-
-
-bool
-wait_for_newbie ( )
-{
- if ( ! newbie )
- return true;
-
- try
- {
- Connection connection;
- connection.open ( "127.0.0.1", newbie_port );
- connection.close();
- newbie = 0; // He's no newbie anymore!
- return true;
- }
- catch ( const std::exception& error )
- {
- std::cerr << "wait_for_newbie error: "
- << error.what()
- << endl;
- return false;
- }
-}
-
-bool endsWith(const char* str, const char* suffix) {
- return (strlen(suffix) < strlen(str) && 0 == strcmp(str+strlen(str)-strlen(suffix), suffix));
-}
-
-
-void
-startNewBroker ( brokerVector & brokers,
- char const * moduleOrDir,
- string const clusterName,
- int verbosity,
- int durable )
-{
- static int brokerId = 0;
- stringstream path, prefix;
- prefix << "soak-" << brokerId;
- std::vector<std::string> argv = list_of<string>
- ("qpidd")
- ("--cluster-name")(clusterName)
- ("--auth=no")
- ("--mgmt-enable=no")
- ("--log-prefix")(prefix.str())
- ("--log-to-file")(prefix.str()+".log")
- ("--log-enable=info+")
- ("--log-enable=debug+:cluster")
- ("TMP_DATA_DIR");
-
- if (endsWith(moduleOrDir, "cluster.so")) {
- // Module path specified, load only that module.
- argv.push_back(string("--load-module=")+moduleOrDir);
- argv.push_back("--no-module-dir");
- if ( durable ) {
- std::cerr << "failover_soak warning: durable arg hass no effect. Use \"dir\" option of \"moduleOrDir\".\n";
- }
- }
- else {
- // Module directory specified, load all modules in dir.
- argv.push_back(string("--module-dir=")+moduleOrDir);
- }
-
- newbie = new ForkedBroker (argv);
- newbie_port = newbie->getPort();
- ForkedBroker * broker = newbie;
-
- if ( verbosity > 0 )
- std::cerr << "new broker created: pid == "
- << broker->getPID()
- << " log-prefix == "
- << "soak-" << brokerId
- << endl;
- brokers.push_back ( broker );
-
- ++ brokerId;
-}
-
-
-
-
-
-bool
-killFrontBroker ( brokerVector & brokers, int verbosity )
-{
- cerr << "killFrontBroker: waiting for newbie sync...\n";
- if ( ! wait_for_newbie() )
- return false;
- cerr << "killFrontBroker: newbie synced.\n";
-
- if ( verbosity > 0 )
- cout << "killFrontBroker pid: " << brokers[0]->getPID() << " on port " << brokers[0]->getPort() << endl;
- try { brokers[0]->kill(9); }
- catch ( const exception& error ) {
- if ( verbosity > 0 )
- {
- cout << "error killing broker: "
- << error.what()
- << endl;
- }
-
- return false;
- }
- delete brokers[0];
- brokers.erase ( brokers.begin() );
- return true;
-}
-
-
-
-
-
-/*
- * The optional delay is to avoid killing newbie brokers that have just
- * been added and are still in the process of updating. This causes
- * spurious, test-generated errors that scare everybody.
- */
-void
-killAllBrokers ( brokerVector & brokers, int delay )
-{
- if ( delay > 0 )
- {
- std::cerr << "Killing all brokers after delay of " << delay << endl;
- sleep ( delay );
- }
-
- for ( uint i = 0; i < brokers.size(); ++ i )
- try { brokers[i]->kill(9); }
- catch ( const exception& error )
- {
- std::cerr << "killAllBrokers Warning: exception during kill on broker "
- << i
- << " "
- << error.what()
- << endl;
- }
-}
-
-
-
-
-
-pid_t
-runDeclareQueuesClient ( brokerVector brokers,
- char const * host,
- char const * path,
- int verbosity,
- int durable,
- char const * queue_prefix,
- int n_queues
- )
-{
- string name("declareQueues");
- int port = brokers[0]->getPort ( );
-
- if ( verbosity > 1 )
- cout << "startDeclareQueuesClient: host: "
- << host
- << " port: "
- << port
- << endl;
- stringstream portSs;
- portSs << port;
-
- vector<const char*> argv;
- argv.push_back ( "declareQueues" );
- argv.push_back ( host );
- string portStr = portSs.str();
- argv.push_back ( portStr.c_str() );
- if ( durable )
- argv.push_back ( "1" );
- else
- argv.push_back ( "0" );
-
- argv.push_back ( queue_prefix );
-
- char n_queues_str[20];
- sprintf ( n_queues_str, "%d", n_queues );
- argv.push_back ( n_queues_str );
-
- argv.push_back ( 0 );
- pid_t pid = fork();
-
- if ( ! pid ) {
- execv ( path, const_cast<char * const *>(&argv[0]) );
- perror ( "error executing declareQueues: " );
- return 0;
- }
-
- allMyChildren.add ( name, pid, DECLARING_CLIENT );
- return pid;
-}
-
-
-
-
-
-pid_t
-startReceivingClient ( brokerVector brokers,
- char const * host,
- char const * receiverPath,
- char const * reportFrequency,
- int verbosity,
- char const * queue_name
- )
-{
- string name("receiver");
- int port = brokers[0]->getPort ( );
-
- if ( verbosity > 1 )
- cout << "startReceivingClient: port " << port << endl;
-
- // verbosity has to be > 1 to let clients talk.
- int client_verbosity = (verbosity > 1 ) ? 1 : 0;
-
- char portStr[100];
- char verbosityStr[100];
- sprintf(portStr, "%d", port);
- sprintf(verbosityStr, "%d", client_verbosity);
-
-
- vector<const char*> argv;
- argv.push_back ( "resumingReceiver" );
- argv.push_back ( host );
- argv.push_back ( portStr );
- argv.push_back ( reportFrequency );
- argv.push_back ( verbosityStr );
- argv.push_back ( queue_name );
- argv.push_back ( 0 );
-
- pid_t pid = fork();
- pids.push_back ( pid );
-
- if ( ! pid ) {
- execv ( receiverPath, const_cast<char * const *>(&argv[0]) );
- perror ( "error executing receiver: " );
- return 0;
- }
-
- allMyChildren.add ( name, pid, RECEIVING_CLIENT );
- return pid;
-}
-
-
-
-
-
-pid_t
-startSendingClient ( brokerVector brokers,
- char const * host,
- char const * senderPath,
- char const * nMessages,
- char const * reportFrequency,
- int verbosity,
- int durability,
- char const * queue_name
- )
-{
- string name("sender");
- int port = brokers[0]->getPort ( );
-
- if ( verbosity > 1)
- cout << "startSenderClient: port " << port << endl;
- char portStr[100];
- char verbosityStr[100];
- //
- // verbosity has to be > 1 to let clients talk.
- int client_verbosity = (verbosity > 1 ) ? 1 : 0;
-
- sprintf ( portStr, "%d", port);
- sprintf ( verbosityStr, "%d", client_verbosity);
-
- vector<const char*> argv;
- argv.push_back ( "replayingSender" );
- argv.push_back ( host );
- argv.push_back ( portStr );
- argv.push_back ( nMessages );
- argv.push_back ( reportFrequency );
- argv.push_back ( verbosityStr );
- if ( durability )
- argv.push_back ( "1" );
- else
- argv.push_back ( "0" );
- argv.push_back ( queue_name );
- argv.push_back ( 0 );
-
- pid_t pid = fork();
- pids.push_back ( pid );
-
- if ( ! pid ) {
- execv ( senderPath, const_cast<char * const *>(&argv[0]) );
- perror ( "error executing sender: " );
- return 0;
- }
-
- allMyChildren.add ( name, pid, SENDING_CLIENT );
- return pid;
-}
-
-
-
-#define HUNKY_DORY 0
-#define BAD_ARGS 1
-#define CANT_FORK_DQ 2
-#define CANT_FORK_RECEIVER 3
-#define CANT_FORK_SENDER 4
-#define DQ_FAILED 5
-#define ERROR_ON_CHILD 6
-#define HANGING 7
-#define ERROR_KILLING_BROKER 8
-
-}} // namespace qpid::tests
-
-using namespace qpid::tests;
-
-// If you want durability, use the "dir" option of "moduleOrDir" .
-int
-main ( int argc, char const ** argv )
-{
- int brokerKills = 0;
- if ( argc != 11 ) {
- cerr << "Usage: "
- << argv[0]
- << "moduleOrDir declareQueuesPath senderPath receiverPath nMessages reportFrequency verbosity durable n_queues n_brokers"
- << endl;
- cerr << "\tverbosity is an integer, durable is 0 or 1\n";
- return BAD_ARGS;
- }
- signal ( SIGCHLD, childExit );
-
- int i = 1;
- char const * moduleOrDir = argv[i++];
- char const * declareQueuesPath = argv[i++];
- char const * senderPath = argv[i++];
- char const * receiverPath = argv[i++];
- char const * nMessages = argv[i++];
- char const * reportFrequency = argv[i++];
- int verbosity = atoi(argv[i++]);
- int durable = atoi(argv[i++]);
- int n_queues = atoi(argv[i++]);
- int n_brokers = atoi(argv[i++]);
-
- char const * host = "127.0.0.1";
-
- allMyChildren.verbosity = verbosity;
-
- string clusterName;
-
- srand ( getpid() );
-
- makeClusterName ( clusterName );
-
- brokerVector brokers;
-
- if ( verbosity > 1 )
- cout << "Starting initial cluster...\n";
-
- for ( int i = 0; i < n_brokers; ++ i ) {
- startNewBroker ( brokers,
- moduleOrDir,
- clusterName,
- verbosity,
- durable );
- }
-
-
- if ( verbosity > 0 )
- printBrokers ( brokers );
-
- // Get prefix for each queue name.
- stringstream queue_prefix;
- queue_prefix << "failover_soak_" << getpid();
- string queue_prefix_str(queue_prefix.str());
-
- // Run the declareQueues child.
- int childStatus;
- pid_t dqClientPid =
- runDeclareQueuesClient ( brokers,
- host,
- declareQueuesPath,
- verbosity,
- durable,
- queue_prefix_str.c_str(),
- n_queues
- );
- if ( -1 == dqClientPid ) {
- cerr << "END_OF_TEST ERROR_START_DECLARE_1\n";
- return CANT_FORK_DQ;
- }
-
- // Don't continue until declareQueues is finished.
- pid_t retval = waitpid ( dqClientPid, & childStatus, 0);
- if ( retval != dqClientPid) {
- cerr << "END_OF_TEST ERROR_START_DECLARE_2\n";
- return DQ_FAILED;
- }
- allMyChildren.exited ( dqClientPid, childStatus );
-
-
- /*
- Start one receiving and one sending client for each queue.
- */
- for ( int i = 0; i < n_queues; ++ i ) {
-
- stringstream queue_name;
- queue_name << queue_prefix.str() << '_' << i;
- string queue_name_str(queue_name.str());
-
- // Receiving client ---------------------------
- pid_t receivingClientPid =
- startReceivingClient ( brokers,
- host,
- receiverPath,
- reportFrequency,
- verbosity,
- queue_name_str.c_str() );
- if ( -1 == receivingClientPid ) {
- cerr << "END_OF_TEST ERROR_START_RECEIVER\n";
- return CANT_FORK_RECEIVER;
- }
-
-
- // Sending client ---------------------------
- pid_t sendingClientPid =
- startSendingClient ( brokers,
- host,
- senderPath,
- nMessages,
- reportFrequency,
- verbosity,
- durable,
- queue_name_str.c_str() );
- if ( -1 == sendingClientPid ) {
- cerr << "END_OF_TEST ERROR_START_SENDER\n";
- return CANT_FORK_SENDER;
- }
- }
-
-
- int minSleep = 2,
- maxSleep = 6;
-
- int totalBrokers = n_brokers;
-
- int loop = 0;
-
- while ( 1 )
- {
- ++ loop;
-
- /*
- if ( verbosity > 1 )
- std::cerr << "------- loop " << loop << " --------\n";
-
- if ( verbosity > 0 )
- cout << totalBrokers << " brokers have been added to the cluster.\n\n\n";
- */
-
- // Sleep for a while. -------------------------
- int sleepyTime = mrand ( minSleep, maxSleep );
- sleep ( sleepyTime );
-
- int bullet = mrand ( 100 );
- if ( bullet >= 95 )
- {
- fprintf ( stderr, "Killing oldest broker...\n" );
-
- // Kill the oldest broker. --------------------------
- if ( ! killFrontBroker ( brokers, verbosity ) )
- {
- allMyChildren.killEverybody();
- killAllBrokers ( brokers, 5 );
- std::cerr << "END_OF_TEST ERROR_BROKER\n";
- return ERROR_KILLING_BROKER;
- }
- ++ brokerKills;
-
- // Start a new broker. --------------------------
- if ( verbosity > 0 )
- cout << "Starting new broker.\n\n";
-
- startNewBroker ( brokers,
- moduleOrDir,
- clusterName,
- verbosity,
- durable );
- ++ totalBrokers;
- printBrokers ( brokers );
- cerr << brokerKills << " brokers have been killed.\n\n\n";
- }
-
- int retval = allMyChildren.checkChildren();
- if ( retval )
- {
- std::cerr << "END_OF_TEST ERROR_CLIENT\n";
- allMyChildren.killEverybody();
- killAllBrokers ( brokers, 5 );
- return ERROR_ON_CHILD;
- }
-
- // If all children have exited, quit.
- int unfinished = allMyChildren.unfinished();
- if ( unfinished == 0 ) {
- killAllBrokers ( brokers, 5 );
-
- if ( verbosity > 1 )
- cout << "failoverSoak: all children have exited.\n";
-
- std::cerr << "END_OF_TEST SUCCESSFUL\n";
- return HUNKY_DORY;
- }
-
- }
-
- allMyChildren.killEverybody();
- killAllBrokers ( brokers, 5 );
-
- std::cerr << "END_OF_TEST SUCCESSFUL\n";
-
- return HUNKY_DORY;
-}
-
-
-
diff --git a/cpp/src/tests/federated_cluster_test b/cpp/src/tests/federated_cluster_test
deleted file mode 100755
index f42b7501b8..0000000000
--- a/cpp/src/tests/federated_cluster_test
+++ /dev/null
@@ -1,153 +0,0 @@
-#!/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.
-#
-
-# Test reliability of the replication feature in the face of link
-# failures:
-srcdir=`dirname $0`
-source ./test_env.sh
-
-trap stop_brokers EXIT
-
-fail() {
- echo $1
- exit 1
-}
-
-stop_brokers() {
- if [[ $BROKER_A ]] ; then
- ../qpidd --no-module-dir -q --port $BROKER_A
- unset BROKER_A
- fi
- if [[ $NODE_1 ]] ; then
- ../qpidd --no-module-dir -q --port $NODE_1
- unset NODE_1
- fi
- if [[ $NODE_2 ]] ; then
- ../qpidd --no-module-dir -q --port $NODE_2
- unset NODE_2
- fi
- if [ -f cluster.ports ]; then
- rm cluster.ports
- fi
-}
-
-start_brokers() {
- #start single node...
- BROKER_A=`../qpidd --daemon --port 0 --no-data-dir --no-module-dir --auth no --log-enable info+` || fail "BROKER_A failed to start"
-
- #...and start cluster
- $srcdir/start_cluster 2 || fail "Could not start cluster"
- NODE_1=$(head -1 cluster.ports)
- NODE_2=$(tail -1 cluster.ports)
- test -n "$NODE_1" || fail "NODE_1 failed to start"
- test -n "$NODE_2" || fail "NODE_2 failed to start"
-}
-
-setup() {
- #create exchange on both cluster and single broker
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add exchange direct test-exchange
- $PYTHON_COMMANDS/qpid-config -b "localhost:$NODE_1" add exchange direct test-exchange
-
- #create dynamic routes for test exchange
- $PYTHON_COMMANDS/qpid-route dynamic add "localhost:$NODE_2" "localhost:$BROKER_A" test-exchange
- $PYTHON_COMMANDS/qpid-route dynamic add "localhost:$BROKER_A" "localhost:$NODE_2" test-exchange
-
- #create test queue on cluster and bind it to the test exchange
- $PYTHON_COMMANDS/qpid-config -b "localhost:$NODE_1" add queue test-queue
- $PYTHON_COMMANDS/qpid-config -b "localhost:$NODE_1" bind test-exchange test-queue to-cluster
-
- #create test queue on single broker and bind it to the test exchange
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue test-queue
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" bind test-exchange test-queue from-cluster
-}
-
-run_test_pull_to_cluster_two_consumers() {
- #start consumers on each of the two nodes of the cluster
- ./receiver --port $NODE_1 --queue test-queue --credit-window 1 > fed1.out.tmp &
- ./receiver --port $NODE_2 --queue test-queue --credit-window 1 > fed2.out.tmp &
-
- #send stream of messages to test exchange on single broker
- for i in `seq 1 1000`; do echo Message $i >> fed.in.tmp; done
- ./sender --port $BROKER_A --exchange test-exchange --routing-key to-cluster --send-eos 2 < fed.in.tmp
-
- #combine output of the two consumers, sort it and compare with the expected stream
- wait
- sort -g -k 2 fed1.out.tmp fed2.out.tmp > fed.out.tmp
- diff fed.in.tmp fed.out.tmp || fail "federated link to cluster failed: expectations not met!"
-
- rm -f fed*.tmp #cleanup
-}
-
-run_test_pull_to_cluster() {
- #send stream of messages to test exchange on single broker
- for i in `seq 1 1000`; do echo Message $i >> fed.in.tmp; done
- ./sender --port $BROKER_A --exchange test-exchange --routing-key to-cluster --send-eos 1 < fed.in.tmp
-
- #consume from remaining node of the cluster
- ./receiver --port $NODE_2 --queue test-queue > fed.out.tmp
-
- #verify all messages are received
- diff fed.in.tmp fed.out.tmp || fail "federated link to cluster failed: expectations not met!"
-
- rm -f fed*.tmp #cleanup
-}
-
-run_test_pull_from_cluster() {
- #start consumer on single broker
- ./receiver --port $BROKER_A --queue test-queue --credit-window 1 > fed.out.tmp &
-
- #send stream of messages to test exchange on cluster
- for i in `seq 1 1000`; do echo Message $i >> fed.in.tmp; done
- ./sender --port $NODE_2 --exchange test-exchange --routing-key from-cluster --send-eos 1 < fed.in.tmp
-
- #verify all messages are received
- wait
- diff fed.in.tmp fed.out.tmp || fail "federated link from cluster failed: expectations not met!"
-
- rm -f fed*.tmp #cleanup
-}
-
-
-if test -d ${PYTHON_DIR}; then
- . cpg_check.sh
- cpg_enabled || exit 0
-
- rm -f fed*.tmp #cleanup any files left from previous run
- start_brokers
- echo "brokers started"
- setup
- echo "setup completed"
- run_test_pull_to_cluster_two_consumers
- echo "federated link to cluster verified"
- run_test_pull_from_cluster
- echo "federated link from cluster verified"
- if [[ $TEST_NODE_FAILURE ]] ; then
- #kill first cluster node and retest
- kill -9 $(../qpidd --check --port $NODE_1) && unset NODE_1
- echo "killed first cluster node; waiting for links to re-establish themselves..."
- sleep 5
- echo "retesting..."
- run_test_pull_to_cluster
- echo "federated link to cluster verified"
- run_test_pull_from_cluster
- echo "federated link from cluster verified"
- fi
-fi
diff --git a/cpp/src/tests/federated_cluster_test_with_node_failure b/cpp/src/tests/federated_cluster_test_with_node_failure
deleted file mode 100755
index e9ae4b5914..0000000000
--- a/cpp/src/tests/federated_cluster_test_with_node_failure
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/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.
-#
-
-srcdir=`dirname $0`
-TEST_NODE_FAILURE=1 $srcdir/federated_cluster_test
diff --git a/cpp/src/tests/federation.py b/cpp/src/tests/federation.py
index dcd074eda9..6477c6effd 100755
--- a/cpp/src/tests/federation.py
+++ b/cpp/src/tests/federation.py
@@ -2604,3 +2604,109 @@ class FederationTests(TestBase010):
self.verify_cleanup()
+ def test_dynamic_bounce_unbinds_named_queue(self):
+ """ Verify that a propagated binding is removed when the connection is
+ bounced
+ """
+ session = self.session
+
+ # create the federation
+
+ self.startQmf()
+ qmf = self.qmf
+
+ self._setup_brokers()
+
+ # create exchange on each broker, and retrieve the corresponding
+ # management object for that exchange
+
+ exchanges=[]
+ for _b in self._brokers[0:2]:
+ _b.client_session.exchange_declare(exchange="fedX", type="direct")
+ self.assertEqual(_b.client_session.exchange_query(name="fedX").type,
+ "direct", "exchange_declare failed!")
+ # pull the exchange out of qmf...
+ retries = 0
+ my_exchange = None
+ timeout = time() + 10
+ while my_exchange is None and time() <= timeout:
+ objs = qmf.getObjects(_broker=_b.qmf_broker, _class="exchange")
+ for ooo in objs:
+ if ooo.name == "fedX":
+ my_exchange = ooo
+ break
+ if my_exchange is None:
+ self.fail("QMF failed to find new exchange!")
+ exchanges.append(my_exchange)
+
+ # on the destination broker, create a binding for propagation
+ self._brokers[0].client_session.queue_declare(queue="fedDstQ")
+ self._brokers[0].client_session.exchange_bind(queue="fedDstQ", exchange="fedX", binding_key="spud")
+
+ # on the source broker, create a bridge queue
+ self._brokers[1].client_session.queue_declare(queue="fedSrcQ")
+
+ # connect B1 --> B0
+ result = self._brokers[0].qmf_object.create( "link",
+ "Link-dynamic",
+ {"host":self._brokers[1].host,
+ "port":self._brokers[1].port}, False)
+ self.assertEqual(result.status, 0)
+
+ # bridge the "fedX" exchange:
+ result = self._brokers[0].qmf_object.create("bridge",
+ "Bridge-dynamic",
+ {"link":"Link-dynamic",
+ "src":"fedX",
+ "dest":"fedX",
+ "dynamic":True,
+ "queue":"fedSrcQ"}, False)
+ self.assertEqual(result.status, 0)
+
+ # wait for the inter-broker links to become operational
+ operational = False
+ timeout = time() + 10
+ while not operational and time() <= timeout:
+ operational = True
+ for _l in qmf.getObjects(_class="link"):
+ #print("Link=%s:%s %s" % (_l.host, _l.port, str(_l.state)))
+ if _l.state != "Operational":
+ operational = False
+ self.failUnless(operational, "inter-broker links failed to become operational.")
+
+ # wait until the binding key has propagated to the src broker
+ exchanges[1].update()
+ timeout = time() + 10
+ while exchanges[1].bindingCount < 1 and time() <= timeout:
+ exchanges[1].update()
+ self.failUnless(exchanges[1].bindingCount == 1)
+
+ #
+ # Tear down the bridges between the two exchanges, then wait
+ # for the bindings to be cleaned up
+ #
+ for _b in qmf.getObjects(_class="bridge"):
+ result = _b.close()
+ self.assertEqual(result.status, 0)
+ exchanges[1].update()
+ timeout = time() + 10
+ while exchanges[1].bindingCount != 0 and time() <= timeout:
+ exchanges[1].update()
+ self.failUnless(exchanges[1].bindingCount == 0)
+
+ self._brokers[1].client_session.queue_delete(queue="fedSrcQ")
+
+ for _b in qmf.getObjects(_class="bridge"):
+ result = _b.close()
+ self.assertEqual(result.status, 0)
+
+ for _l in qmf.getObjects(_class="link"):
+ result = _l.close()
+ self.assertEqual(result.status, 0)
+
+ for _b in self._brokers[0:2]:
+ _b.client_session.exchange_delete(exchange="fedX")
+
+ self._teardown_brokers()
+
+ self.verify_cleanup()
diff --git a/cpp/src/tests/federation_sys.py b/cpp/src/tests/federation_sys.py
index 11590f684e..e2553e4cf3 100755
--- a/cpp/src/tests/federation_sys.py
+++ b/cpp/src/tests/federation_sys.py
@@ -7,9 +7,9 @@
# 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
@@ -37,12 +37,12 @@ class Enum(object):
class QmfTestBase010(TestBase010):
-
+
_brokers = []
_links = []
_bridges = []
_alt_exch_ops = Enum(none=0, create=1, delete=2)
-
+
class _Broker(object):
"""
This broker proxy object holds the Qmf proxy to a broker of known address as well as the QMF broker
@@ -64,7 +64,7 @@ class QmfTestBase010(TestBase010):
for session in self.sessions:
try: # Session may have been closed by broker error
session.close()
- except Exception, e: print "WARNING: %s: Unable to close session %s (%s): %s %s" % (self, session, hex(id(session)), type(e), e)
+ except Exception, e: print "WARNING: %s: Unable to close session %s (%s): %s %s" % (self, session, hex(id(session)), type(e), e)
try: # Connection may have been closed by broker error
self.connection.close()
except Exception, e: print "WARNING: %s: Unable to close connection %s (%s): %s %s" % (self, self.connection, hex(id(self.connection)), type(e), e)
@@ -72,7 +72,7 @@ class QmfTestBase010(TestBase010):
session = self.connection.session(name, transactional_flag)
self.sessions.append(session)
return session
-
+
def setUp(self):
"""
Called one before each test starts
@@ -96,34 +96,22 @@ class QmfTestBase010(TestBase010):
b.destroy(self.qmf)
TestBase010.tearDown(self)
self.qmf.close()
-
+
#--- General test utility functions
-
+
def _get_name(self):
"""
Return the name of method which called this method stripped of "test_" prefix. Used for naming
queues and exchanges on a per-test basis.
"""
return stack()[1][3][5:]
-
+
def _get_broker_port(self, key):
"""
Get the port of a broker defined in the environment using -D<key>=portno
"""
return int(self.defines[key])
-
- def _get_cluster_ports(self, key):
- """
- Get the cluster ports from the parameters of the test which place it in the environment using
- -D<key>="port0 port1 ... portN" (space-separated)
- """
- ports = []
- ports_str = self.defines[key]
- if ports_str:
- for p in ports_str.split():
- ports.append(int(p))
- return ports
-
+
def _get_send_address(self, exch_name, queue_name):
"""
Get an address to which to send messages based on the exchange name and queue name, but taking into account
@@ -132,18 +120,15 @@ class QmfTestBase010(TestBase010):
if len(exch_name) == 0: # Default exchange
return queue_name
return "%s/%s" % (exch_name, queue_name)
-
- def _get_broker(self, cluster_flag, broker_port_key, cluster_ports_key):
+
+ def _get_broker(self, broker_port_key):
"""
Read the port numbers for pre-started brokers from the environment using keys, then find or create and return
the Qmf broker proxy for the appropriate broker
"""
- if cluster_flag:
- port = self._get_cluster_ports(cluster_ports_key)[0] # Always use the first node in the cluster
- else:
- port = self._get_broker_port(broker_port_key)
+ port = self._get_broker_port(broker_port_key)
return self._find_create_broker("localhost:%s" % port)
-
+ ################
def _get_msg_subject(self, topic_key):
"""
Return an appropriate subject for sending a message to a known topic. Return None if there is no topic.
@@ -152,7 +137,7 @@ class QmfTestBase010(TestBase010):
if "*" in topic_key: return topic_key.replace("*", "test")
if "#" in topic_key: return topic_key.replace("#", "multipart.test")
return topic_key
-
+
def _send_msgs(self, session_name, broker, addr, msg_count, msg_content = "Message_%03d", topic_key = "",
msg_durable_flag = False, enq_txn_size = 0):
"""
@@ -172,7 +157,7 @@ class QmfTestBase010(TestBase010):
send_session.commit()
sender.close()
send_session.close()
-
+
def _receive_msgs(self, session_name, broker, addr, msg_count, msg_content = "Message_%03d", deq_txn_size = 0,
timeout = 0):
"""
@@ -214,9 +199,9 @@ class QmfTestBase010(TestBase010):
receive_session.commit()
receiver.close()
receive_session.close()
-
+
#--- QMF-specific utility functions
-
+
def _get_qmf_property(self, props, key):
"""
Get the value of a named property key kj from a property list [(k0, v0), (k1, v1), ... (kn, vn)].
@@ -225,13 +210,13 @@ class QmfTestBase010(TestBase010):
if k.name == key:
return v
return None
-
+
def _check_qmf_return(self, method_result):
"""
Check the result of a Qmf-defined method call
"""
self.assertTrue(method_result.status == 0, method_result.text)
-
+
def _check_optional_qmf_property(self, qmf_broker, type, qmf_object, key, expected_val, obj_ref_flag):
"""
Optional Qmf properties don't show up in the properties list when they are not specified. Checks for
@@ -253,9 +238,9 @@ class QmfTestBase010(TestBase010):
(type, qmf_object.name, key, val, expected_val))
else:
self.fail("%s %s exists, but has an unexpected %s property \"%s\" set." % (type, qmf_object.name, key, val))
-
+
#--- Find/create Qmf broker objects
-
+
def _find_qmf_broker(self, url):
"""
Find the Qmf broker object for the given broker URL. The broker must have been previously added to Qmf through
@@ -265,7 +250,7 @@ class QmfTestBase010(TestBase010):
if b.getBroker().getUrl() == url:
return b
return None
-
+
def _find_create_broker(self, url):
"""
Find a running broker through Qmf. If it does not exist, add it (assuming the broker is already running).
@@ -280,9 +265,9 @@ class QmfTestBase010(TestBase010):
else:
broker.qmf_broker = qmf_broker
return broker
-
+
#--- Find/create/delete exchanges
-
+
def _find_qmf_exchange(self, qmf_broker, name, type, alternate, durable, auto_delete):
"""
Find Qmf exchange object
@@ -302,7 +287,7 @@ class QmfTestBase010(TestBase010):
(name, e.autoDelete, auto_delete))
return e
return None
-
+
def _find_create_qmf_exchange(self, qmf_broker, name, type, alternate, durable, auto_delete, args):
"""
Find Qmf exchange object if exchange exists, create exchange and return its Qmf object if not
@@ -315,7 +300,7 @@ class QmfTestBase010(TestBase010):
e = self._find_qmf_exchange(qmf_broker, name, type, alternate, durable, auto_delete)
self.assertNotEqual(e, None, "Creation of exchange %s on broker %s failed" % (name, qmf_broker.getBroker().getUrl()))
return e
-
+
def _find_delete_qmf_exchange(self, qmf_broker, name, type, alternate, durable, auto_delete):
"""
Find and delete Qmf exchange object if it exists
@@ -323,9 +308,9 @@ class QmfTestBase010(TestBase010):
e = self._find_qmf_exchange(qmf_broker, name, type, alternate, durable, auto_delete)
if e is not None and not auto_delete:
self._check_qmf_return(qmf_broker.delete(type="exchange", name=name, options={}))
-
+
#--- Find/create/delete queues
-
+
def _find_qmf_queue(self, qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete):
"""
Find a Qmf queue object
@@ -344,7 +329,7 @@ class QmfTestBase010(TestBase010):
(name, q.autoDelete, auto_delete))
return q
return None
-
+
def _find_create_qmf_queue(self, qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete, args):
"""
Find Qmf queue object if queue exists, create queue and return its Qmf object if not
@@ -357,7 +342,7 @@ class QmfTestBase010(TestBase010):
q = self._find_qmf_queue(qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete)
self.assertNotEqual(q, None, "Creation of queue %s on broker %s failed" % (name, qmf_broker.getBroker().getUrl()))
return q
-
+
def _find_delete_qmf_queue(self, qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete, args):
"""
Find and delete Qmf queue object if it exists
@@ -365,9 +350,9 @@ class QmfTestBase010(TestBase010):
q = self._find_qmf_queue(qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete)
if q is not None and not auto_delete:
self._check_qmf_return(qmf_broker.delete(type="queue", name=name, options={}))
-
+
#--- Find/create/delete bindings (between an exchange and a queue)
-
+
def _find_qmf_binding(self, qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args):
"""
Find a Qmf binding object
@@ -383,7 +368,7 @@ class QmfTestBase010(TestBase010):
(qmf_exchange.name, qmf_queue.name, b.arguments, binding_args))
return b
return None
-
+
def _find_create_qmf_binding(self, qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args):
"""
Find Qmf binding object if it exists, create binding and return its Qmf object if not
@@ -396,7 +381,7 @@ class QmfTestBase010(TestBase010):
self.assertNotEqual(b, None, "Creation of binding between exchange %s and queue %s with key %s failed" %
(qmf_exchange.name, qmf_queue.name, binding_key))
return b
-
+
def _find_delete_qmf_binding(self, qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args):
"""
Find and delete Qmf binding object if it exists
@@ -405,7 +390,7 @@ class QmfTestBase010(TestBase010):
if b is not None:
if len(qmf_exchange.name) > 0: # not default exchange
self._check_qmf_return(qmf_broker.delete(type="binding", name="%s/%s/%s" % (qmf_exchange.name, qmf_queue.name, binding_key), options={}))
-
+
#--- Find/create a link
def _find_qmf_link(self, qmf_from_broker_proxy, host, port):
@@ -416,7 +401,7 @@ class QmfTestBase010(TestBase010):
if l.host == host and l.port == port:
return l
return None
-
+
def _find_create_qmf_link(self, qmf_from_broker, qmf_to_broker_proxy, link_durable_flag, auth_mechanism, user_id,
password, transport, pause_interval, link_ready_timeout):
"""
@@ -433,24 +418,19 @@ class QmfTestBase010(TestBase010):
(qmf_from_broker.getBroker().getUrl(), qmf_to_broker_proxy.getUrl()))
self._wait_for_link(l, pause_interval, link_ready_timeout)
return l
-
+
def _wait_for_link(self, link, pause_interval, link_ready_timeout):
"""
Wait for link to become active (state=Operational)
"""
tot_time = 0
link.update()
- if link.state == "":
- # Link mgmt updates for the c++ link object are disabled when in a cluster because of inconsistent state:
- # one is "Operational", the other "Passive". In this case, wait a bit and hope for the best...
- sleep(2*pause_interval)
- else:
- while link.state != "Operational" and tot_time < link_ready_timeout:
- sleep(pause_interval)
- tot_time += pause_interval
- link.update()
- self.assertEqual(link.state, "Operational", "Timeout: Link not operational, state=%s" % link.state)
-
+ while link.state != "Operational" and tot_time < link_ready_timeout:
+ sleep(pause_interval)
+ tot_time += pause_interval
+ link.update()
+ self.assertEqual(link.state, "Operational", "Timeout: Link not operational, state=%s" % link.state)
+
#--- Find/create a bridge
def _find_qmf_bridge(self, qmf_broker_proxy, qmf_link, source, destination, key):
@@ -461,7 +441,7 @@ class QmfTestBase010(TestBase010):
if b.linkRef == qmf_link.getObjectId() and b.src == source and b.dest == destination and b.key == key:
return b
return None
-
+
def _find_create_qmf_bridge(self, qmf_broker_proxy, qmf_link, queue_name, exch_name, topic_key,
queue_route_type_flag, bridge_durable_flag):
"""
@@ -486,7 +466,7 @@ class QmfTestBase010(TestBase010):
b = self._find_qmf_bridge(qmf_broker_proxy, qmf_link, src, dest, key)
self.assertNotEqual(b, None, "Bridge creation failed: src=%s dest=%s key=%s" % (src, dest, key))
return b
-
+
def _wait_for_bridge(self, bridge, src_broker, dest_broker, exch_name, queue_name, topic_key, pause_interval,
bridge_ready_timeout):
"""
@@ -522,9 +502,9 @@ class QmfTestBase010(TestBase010):
sender.close()
send_session.close()
self.assertTrue(active, "Bridge failed to become active after %ds: %s" % (bridge_ready_timeout, bridge))
-
+
#--- Find/create/delete utility functions
-
+
def _create_and_bind(self, qmf_broker, exchange_args, queue_args, binding_args):
"""
Create a binding between a named exchange and queue on a broker
@@ -532,7 +512,7 @@ class QmfTestBase010(TestBase010):
e = self._find_create_qmf_exchange(qmf_broker, **exchange_args)
q = self._find_create_qmf_queue(qmf_broker, **queue_args)
return self._find_create_qmf_binding(qmf_broker, e, q, **binding_args)
-
+
def _check_alt_exchange(self, qmf_broker, alt_exch_name, alt_exch_type, alt_exch_op):
"""
Check for existence of alternate exchange. Return the Qmf exchange proxy object for the alternate exchange
@@ -546,7 +526,7 @@ class QmfTestBase010(TestBase010):
alternate="", durable=False, auto_delete=False)
return self._find_qmf_exchange(qmf_broker=qmf_broker, name=alt_exchange_name, type=alt_exchange_type,
alternate="", durable=False, auto_delete=False)
-
+
def _delete_queue_binding(self, qmf_broker, exchange_args, queue_args, binding_args):
"""
Delete a queue and the binding between it and the exchange
@@ -555,7 +535,7 @@ class QmfTestBase010(TestBase010):
q = self._find_qmf_queue(qmf_broker, queue_args["name"], queue_args["alternate_exchange"], queue_args["durable"], queue_args["exclusive"], queue_args["auto_delete"])
self._find_delete_qmf_binding(qmf_broker, e, q, **binding_args)
self._find_delete_qmf_queue(qmf_broker, **queue_args)
-
+
def _create_route(self, queue_route_type_flag, src_broker, dest_broker, exch_name, queue_name, topic_key,
link_durable_flag, bridge_durable_flag, auth_mechanism, user_id, password, transport,
pause_interval = 1, link_ready_timeout = 20, bridge_ready_timeout = 20):
@@ -571,7 +551,7 @@ class QmfTestBase010(TestBase010):
self._wait_for_bridge(b, src_broker, dest_broker, exch_name, queue_name, topic_key, pause_interval, bridge_ready_timeout)
# Parameterized test - entry point for tests
-
+
def _do_test(self,
test_name, # Name of test
exch_name = "amq.direct", # Remote exchange name
@@ -597,8 +577,6 @@ class QmfTestBase010(TestBase010):
queue_route_type_flag = False, # Route type: false = bridge route, true = queue route
enq_txn_size = 0, # Enqueue transaction size, 0 = no transactions
deq_txn_size = 0, # Dequeue transaction size, 0 = no transactions
- local_cluster_flag = False, # Use a node from the local cluster, otherwise use single local broker
- remote_cluster_flag = False, # Use a node from the remote cluster, otherwise use single remote broker
alt_exch_op = _alt_exch_ops.create,# Op on alt exch [create (ensure present), delete (ensure not present), none (neither create nor delete)]
auth_mechanism = "", # Authorization mechanism for linked broker
user_id = "", # User ID for authorization on linked broker
@@ -609,32 +587,32 @@ class QmfTestBase010(TestBase010):
Parameterized federation test. Sets up a federated link between a source broker and a destination broker and
checks that messages correctly pass over the link to the destination. Where appropriate (non-queue-routes), also
checks for the presence of messages on the source broker.
-
+
In these tests, the concept is to create a LOCAL broker, then create a link to a REMOTE broker using federation.
In other words, the messages sent to the LOCAL broker will be replicated on the REMOTE broker, and tests are
performed on the REMOTE broker to check that the required messages are present. In the case of regular routes,
the LOCAL broker will also retain the messages, and a similar test is performed on this broker.
-
+
TODO: There are several items to improve here:
1. _do_test() is rather general. Rather create a version for each exchange type and test the exchange/queue
interaction in more detail based on the exchange type
2. Add a headers and an xml exchange type
- 3. Restructure the tests to start and stop brokers and clusters directly rather than relying on previously
- started brokers. Then persistence can be checked by stopping and restarting the brokers/clusters. In particular,
+ 3. Restructure the tests to start and stop brokers directly rather than relying on previously
+ started brokers. Then persistence can be checked by stopping and restarting the brokers. In particular,
test the persistence of links and bridges, both of which take a persistence flag.
4. Test the behavior of the alternate exchanges when messages are sourced through a link. Also check behavior
when the alternate exchange is not present or is deleted after the reference is made.
5. Test special queue types (eg LVQ)
"""
- local_broker = self._get_broker(local_cluster_flag, "local-port", "local-cluster-ports")
- remote_broker = self._get_broker(remote_cluster_flag, "remote-port", "remote-cluster-ports")
-
+ local_broker = self._get_broker("local-port")
+ remote_broker = self._get_broker("remote-port")
+
# Check alternate exchanges exist (and create them if not) on both local and remote brokers
self._check_alt_exchange(local_broker.qmf_broker, exch_alt_exch, exch_alt_exch_type, alt_exch_op)
self._check_alt_exchange(local_broker.qmf_broker, queue_alt_exch, queue_alt_exch_type, alt_exch_op)
self._check_alt_exchange(remote_broker.qmf_broker, exch_alt_exch, exch_alt_exch_type, alt_exch_op)
self._check_alt_exchange(remote_broker.qmf_broker, queue_alt_exch, queue_alt_exch_type, alt_exch_op)
-
+
queue_name = "queue_%s" % test_name
exchange_args = {"name": exch_name, "type": exch_type, "alternate": exch_alt_exch,
"durable": exch_durable_flag, "auto_delete": exch_auto_delete_flag, "args": exch_x_args}
@@ -658,70 +636,70 @@ class QmfTestBase010(TestBase010):
if not queue_route_type_flag:
self._receive_msgs("local_receive_session", local_broker, addr = queue_name, msg_count = msg_count, deq_txn_size = deq_txn_size)
self._receive_msgs("remote_receive_session", remote_broker, addr = queue_name, msg_count = msg_count, deq_txn_size = deq_txn_size, timeout = 5)
-
+
# Clean up
self._delete_queue_binding(qmf_broker=local_broker.qmf_broker, exchange_args=exchange_args, queue_args=queue_args, binding_args=binding_args)
self._delete_queue_binding(qmf_broker=remote_broker.qmf_broker, exchange_args=exchange_args, queue_args=queue_args, binding_args=binding_args)
class A_ShortTests(QmfTestBase010):
-
+
def test_route_defaultExch(self):
self._do_test(self._get_name())
-
+
def test_queueRoute_defaultExch(self):
self._do_test(self._get_name(), queue_route_type_flag=True)
-
-
+
+
class A_LongTests(QmfTestBase010):
-
+
def test_route_amqDirectExch(self):
self._do_test(self._get_name(), exch_name="amq.direct")
-
+
def test_queueRoute_amqDirectExch(self):
self._do_test(self._get_name(), exch_name="amq.direct", queue_route_type_flag=True)
-
-
+
+
def test_route_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange")
-
+
def test_queueRoute_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True)
-
-
+
+
def test_route_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout")
-
+
def test_queueRoute_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True)
-
-
+
+
def test_route_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#")
-
+
def test_queueRoute_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True)
-
-
+
+
class B_ShortTransactionTests(QmfTestBase010):
-
+
def test_txEnq01_route_defaultExch(self):
self._do_test(self._get_name(), enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_defaultExch(self):
self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_txDeq01_route_defaultExch(self):
self._do_test(self._get_name(), enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_defaultExch(self):
self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
class B_LongTransactionTests(QmfTestBase010):
-
+
def test_txEnq10_route_defaultExch(self):
self._do_test(self._get_name(), enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_defaultExch(self):
self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
@@ -730,1171 +708,270 @@ class B_LongTransactionTests(QmfTestBase010):
def test_txEnq01_route_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1)
def test_txEnq10_route_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq01_txDeq01_route_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
def test_txEnq01_route_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1)
def test_txEnq10_route_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq01_txDeq01_route_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
def test_txEnq01_route_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1)
def test_txEnq10_route_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq01_txDeq01_route_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-class C_ShortClusterTests(QmfTestBase010):
-
- def test_locCluster_route_defaultExch(self):
- self._do_test(self._get_name(), local_cluster_flag=True)
-
- def test_locCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_remCluster_route_defaultExch(self):
- self._do_test(self._get_name(), remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_defaultExch(self):
- self._do_test(self._get_name(), local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
-
-class C_LongClusterTests(QmfTestBase010):
-
- def test_locCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", local_cluster_flag=True)
-
- def test_locCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_remCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_locCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", local_cluster_flag=True)
-
- def test_locCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_remCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_locCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", local_cluster_flag=True)
-
- def test_locCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_remCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
-
-class D_ShortClusterTransactionTests(QmfTestBase010):
-
- def test_txEnq01_locCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
-
-class D_LongClusterTransactionTests(QmfTestBase010):
-
- def test_txEnq10_locCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_defaultExch(self):
- self._do_test(self._get_name(), enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_defaultExch(self):
- self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_txEnq01_locCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_txEnq01_locCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_txEnq01_locCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
-
-class E_ShortPersistenceTests(QmfTestBase010):
-
+class E_ShortPersistenceTests(QmfTestBase010):
+
def test_route_durQueue_defaultExch(self):
self._do_test(self._get_name(), queue_durable_flag=True)
-
+
def test_route_durMsg_durQueue_defaultExch(self):
self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True)
-
+
def test_queueRoute_durQueue_defaultExch(self):
self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True)
-
+
def test_queueRoute_durMsg_durQueue_defaultExch(self):
self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True)
-class E_LongPersistenceTests(QmfTestBase010):
+class E_LongPersistenceTests(QmfTestBase010):
+
-
def test_route_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True)
-
+
def test_route_durMsg_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True)
-
+
def test_queueRoute_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True)
-
+
def test_queueRoute_durMsg_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True)
-
+
def test_route_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True)
-
+
def test_route_durMsg_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True)
-
+
def test_queueRoute_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True)
-
+
def test_queueRoute_durMsg_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True)
-
+
def test_route_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True)
-
+
def test_route_durMsg_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True)
-
+
def test_queueRoute_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True)
-
+
def test_queueRoute_durMsg_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True)
-
+
class F_ShortPersistenceTransactionTests(QmfTestBase010):
-
+
def test_txEnq01_route_durQueue_defaultExch(self):
self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_route_durMsg_durQueue_defaultExch(self):
self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_durQueue_defaultExch(self):
self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_durMsg_durQueue_defaultExch(self):
self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_txDeq01_route_durQueue_defaultExch(self):
self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_route_durMsg_durQueue_defaultExch(self):
self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_durQueue_defaultExch(self):
self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_durMsg_durQueue_defaultExch(self):
self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
class F_LongPersistenceTransactionTests(QmfTestBase010):
-
+
def test_txEnq10_route_durQueue_defaultExch(self):
self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_route_durMsg_durQueue_defaultExch(self):
self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_durQueue_defaultExch(self):
self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_durMsg_durQueue_defaultExch(self):
self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
-
+
+
def test_txEnq01_route_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_route_durMsg_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_durMsg_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)
-
+
def test_txEnq10_route_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_route_durMsg_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_durMsg_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq01_txDeq01_route_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_route_durMsg_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_durMsg_durQueue_directExch(self):
self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_route_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_route_durMsg_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_durMsg_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)
-
+
def test_txEnq10_route_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_route_durMsg_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_durMsg_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq01_txDeq01_route_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_route_durMsg_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_durMsg_durQueue_fanoutExch(self):
self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
def test_txEnq01_route_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_route_durMsg_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)
-
+
def test_txEnq01_queueRoute_durMsg_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)
def test_txEnq10_route_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_route_durMsg_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq10_queueRoute_durMsg_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)
-
+
def test_txEnq01_txDeq01_route_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_route_durMsg_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-
+
def test_txEnq01_txDeq01_queueRoute_durMsg_durQueue_topicExch(self):
self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)
-class G_ShortPersistenceClusterTests(QmfTestBase010):
-
- def test_locCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, local_cluster_flag=True)
-
- def test_locCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, local_cluster_flag=True)
-
- def test_locCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_locCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_remCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
-
-class G_LongPersistenceClusterTests(QmfTestBase010):
-
-
-
- def test_locCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, local_cluster_flag=True)
-
- def test_locCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, local_cluster_flag=True)
-
- def test_locCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_locCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_remCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_locCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, local_cluster_flag=True)
-
- def test_locCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, local_cluster_flag=True)
-
- def test_locCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_locCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_remCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_locCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, local_cluster_flag=True)
-
- def test_locCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, local_cluster_flag=True)
-
- def test_locCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_locCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True)
-
- def test_remCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_remCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_locCluster_remCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, local_cluster_flag=True, remote_cluster_flag=True)
-
-
-class H_ShortPersistenceClusterTransactionTests(QmfTestBase010):
-
- def test_txEnq01_locCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
-
-class H_LongPersistenceClusterTransactionTests(QmfTestBase010):
-
- def test_txEnq10_locCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_durQueue_defaultExch(self):
- self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_durMsg_durQueue_defaultExch(self):
- self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
-
-
-
- def test_txEnq01_locCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_durMsg_durQueue_directExch(self):
- self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_txEnq01_locCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_durMsg_durQueue_fanoutExch(self):
- self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
-
- def test_txEnq01_locCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_locCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq10_locCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_remCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq10_remCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_remCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_locCluster_remCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq10_locCluster_remCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_route_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
- def test_txEnq01_txDeq01_locCluster_remCluster_queueRoute_durMsg_durQueue_topicExch(self):
- self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1, local_cluster_flag=True, remote_cluster_flag=True)
-
diff --git a/cpp/src/tests/ha_store_tests.py b/cpp/src/tests/ha_store_tests.py
new file mode 100755
index 0000000000..d1eaca1b87
--- /dev/null
+++ b/cpp/src/tests/ha_store_tests.py
@@ -0,0 +1,130 @@
+#!/usr/bin/env python
+
+# 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.
+#
+
+"""
+This module contains tests for HA functionality that requires a store.
+It is not included as part of "make check" since it will not function
+without a store. Currently it can be run from a build of the message
+store.
+"""
+
+import os, signal, sys, time, imp, re, subprocess, glob, random, logging, shutil, math, unittest, random
+import traceback
+from qpid.messaging import Message, NotFound, ConnectionError, ReceiverError, Connection, Timeout, Disposition, REJECTED, Empty
+from qpid.datatypes import uuid4
+from brokertest import *
+from ha_test import *
+from threading import Thread, Lock, Condition
+from logging import getLogger, WARN, ERROR, DEBUG, INFO
+from qpidtoollibs import BrokerAgent
+from uuid import UUID
+
+
+class StoreTests(BrokerTest):
+ """Test for HA with persistence."""
+
+ def test_store_recovery(self):
+ """Verify basic store and recover functionality"""
+ cluster = HaCluster(self, 2)
+ sn = cluster[0].connect().session()
+ s = sn.sender("qq;{create:always,node:{durable:true}}")
+ sk = sn.sender("xx/k;{create:always,node:{type:topic, durable:true, x-declare:{type:'direct'}, x-bindings:[{exchange:xx,key:k,queue:qq}]}}")
+ s.send(Message("foo", durable=True))
+ s.send(Message("bar", durable=True))
+ sk.send(Message("baz", durable=True))
+ r = cluster[0].connect().session().receiver("qq")
+ self.assertEqual(r.fetch().content, "foo")
+ r.session.acknowledge()
+ # FIXME aconway 2012-09-21: sending this message is an ugly hack to flush
+ # the dequeue operation on qq.
+ s.send(Message("flush", durable=True))
+
+ def verify(broker, x_count):
+ sn = broker.connect().session()
+ assert_browse(sn, "qq", [ "bar", "baz", "flush" ]+ (x_count)*["x"])
+ sn.sender("xx/k").send(Message("x", durable=True))
+ assert_browse(sn, "qq", [ "bar", "baz", "flush" ]+ (x_count+1)*["x"])
+
+ verify(cluster[0], 0)
+ cluster.bounce(0, promote_next=False)
+ cluster[0].promote()
+ cluster[0].wait_status("active")
+ verify(cluster[0], 1)
+ cluster.kill(0, promote_next=False)
+ cluster[1].promote()
+ cluster[1].wait_status("active")
+ verify(cluster[1], 2)
+ cluster.bounce(1, promote_next=False)
+ cluster[1].promote()
+ cluster[1].wait_status("active")
+ verify(cluster[1], 3)
+
+ def test_catchup_store(self):
+ """Verify that a backup erases queue data from store recovery before
+ doing catch-up from the primary."""
+ cluster = HaCluster(self, 2)
+ sn = cluster[0].connect().session()
+ s1 = sn.sender("q1;{create:always,node:{durable:true}}")
+ for m in ["foo","bar"]: s1.send(Message(m, durable=True))
+ s2 = sn.sender("q2;{create:always,node:{durable:true}}")
+ sk2 = sn.sender("ex/k2;{create:always,node:{type:topic, durable:true, x-declare:{type:'direct'}, x-bindings:[{exchange:ex,key:k2,queue:q2}]}}")
+ sk2.send(Message("hello", durable=True))
+ # Wait for backup to catch up.
+ cluster[1].assert_browse_backup("q1", ["foo","bar"])
+ cluster[1].assert_browse_backup("q2", ["hello"])
+
+ # Make changes that the backup doesn't see
+ cluster.kill(1, promote_next=False)
+ time.sleep(1) # FIXME aconway 2012-09-25:
+ r1 = cluster[0].connect().session().receiver("q1")
+ for m in ["foo", "bar"]: self.assertEqual(r1.fetch().content, m)
+ r1.session.acknowledge()
+ for m in ["x","y","z"]: s1.send(Message(m, durable=True))
+ # Use old connection to unbind
+ us = cluster[0].connect_old().session(str(uuid4()))
+ us.exchange_unbind(exchange="ex", binding_key="k2", queue="q2")
+ us.exchange_bind(exchange="ex", binding_key="k1", queue="q1")
+ # Restart both brokers from store to get inconsistent sequence numbering.
+ cluster.bounce(0, promote_next=False)
+ cluster[0].promote()
+ cluster[0].wait_status("active")
+ cluster.restart(1)
+ cluster[1].wait_status("ready")
+
+ # Verify state
+ cluster[0].assert_browse("q1", ["x","y","z"])
+ cluster[1].assert_browse_backup("q1", ["x","y","z"])
+ sn = cluster[0].connect().session() # FIXME aconway 2012-09-25: should fail over!
+ sn.sender("ex/k1").send("boo")
+ cluster[0].assert_browse_backup("q1", ["x","y","z", "boo"])
+ cluster[1].assert_browse_backup("q1", ["x","y","z", "boo"])
+ sn.sender("ex/k2").send("hoo") # q2 was unbound so this should be dropped.
+ sn.sender("q2").send("end") # mark the end of the queue for assert_browse
+ cluster[0].assert_browse("q2", ["hello", "end"])
+ cluster[1].assert_browse_backup("q2", ["hello", "end"])
+
+if __name__ == "__main__":
+ shutil.rmtree("brokertest.tmp", True)
+ qpid_ha = os.getenv("QPID_HA_EXEC")
+ if qpid_ha and os.path.exists(qpid_ha):
+ os.execvp("qpid-python-test",
+ ["qpid-python-test", "-m", "ha_store_tests"] + sys.argv[1:])
+ else:
+ print "Skipping ha_store_tests, %s not available"%(qpid_ha)
diff --git a/cpp/src/tests/ha_test.py b/cpp/src/tests/ha_test.py
new file mode 100755
index 0000000000..cdf9d3dd17
--- /dev/null
+++ b/cpp/src/tests/ha_test.py
@@ -0,0 +1,304 @@
+#!/usr/bin/env python
+
+# 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.
+#
+
+import os, signal, sys, time, imp, re, subprocess, glob, random, logging, shutil, math, unittest, random
+import traceback
+from qpid.messaging import Message, NotFound, ConnectionError, ReceiverError, Connection, Timeout, Disposition, REJECTED, Empty
+from qpid.datatypes import uuid4
+from brokertest import *
+from threading import Thread, Lock, Condition
+from logging import getLogger, WARN, ERROR, DEBUG, INFO
+from qpidtoollibs import BrokerAgent
+from uuid import UUID
+
+log = getLogger(__name__)
+
+class LogLevel:
+ """
+ Temporarily change the log settings on the root logger.
+ Used to suppress expected WARN messages from the python client.
+ """
+ def __init__(self, level):
+ self.save_level = getLogger().getEffectiveLevel()
+ getLogger().setLevel(level)
+
+ def restore(self):
+ getLogger().setLevel(self.save_level)
+
+class QmfAgent(object):
+ """Access to a QMF broker agent."""
+ def __init__(self, address, **kwargs):
+ self._connection = Connection.establish(
+ address, client_properties={"qpid.ha-admin":1}, **kwargs)
+ self._agent = BrokerAgent(self._connection)
+
+ def __getattr__(self, name):
+ a = getattr(self._agent, name)
+ return a
+
+class Credentials(object):
+ """SASL credentials: username, password, and mechanism"""
+ def __init__(self, username, password, mechanism):
+ (self.username, self.password, self.mechanism) = (username, password, mechanism)
+
+ def __str__(self): return "Credentials%s"%(self.tuple(),)
+
+ def tuple(self): return (self.username, self.password, self.mechanism)
+
+ def add_user(self, url): return "%s/%s@%s"%(self.username, self.password, url)
+
+class HaBroker(Broker):
+ """Start a broker with HA enabled
+ @param client_cred: (user, password, mechanism) for admin clients started by the HaBroker.
+ """
+ def __init__(self, test, args=[], brokers_url=None, ha_cluster=True, ha_replicate="all",
+ client_credentials=None, **kwargs):
+ assert BrokerTest.ha_lib, "Cannot locate HA plug-in"
+ args = copy(args)
+ args += ["--load-module", BrokerTest.ha_lib,
+ "--log-enable=debug+:ha::",
+ # FIXME aconway 2012-02-13: workaround slow link failover.
+ "--link-maintenance-interval=0.1",
+ "--ha-cluster=%s"%ha_cluster]
+ if ha_replicate is not None:
+ args += [ "--ha-replicate=%s"%ha_replicate ]
+ if brokers_url: args += [ "--ha-brokers-url", brokers_url ]
+ Broker.__init__(self, test, args, **kwargs)
+ self.qpid_ha_path=os.path.join(os.getenv("PYTHON_COMMANDS"), "qpid-ha")
+ assert os.path.exists(self.qpid_ha_path)
+ self.qpid_config_path=os.path.join(os.getenv("PYTHON_COMMANDS"), "qpid-config")
+ assert os.path.exists(self.qpid_config_path)
+ self.qpid_ha_script=import_script(self.qpid_ha_path)
+ self._agent = None
+ self.client_credentials = client_credentials
+
+ def __str__(self): return Broker.__str__(self)
+
+ def qpid_ha(self, args):
+ cred = self.client_credentials
+ url = self.host_port()
+ if cred:
+ url =cred.add_user(url)
+ args = args + ["--sasl-mechanism", cred.mechanism]
+ self.qpid_ha_script.main_except(["", "-b", url]+args)
+
+ def promote(self):
+ self.ready(); self.qpid_ha(["promote"])
+ def set_public_url(self, url): self.qpid_ha(["set", "--public-url", url])
+ def set_brokers_url(self, url): self.qpid_ha(["set", "--brokers-url", url])
+ def replicate(self, from_broker, queue): self.qpid_ha(["replicate", from_broker, queue])
+
+ def agent(self):
+ if not self._agent:
+ cred = self.client_credentials
+ if cred:
+ self._agent = QmfAgent(cred.add_user(self.host_port()), sasl_mechanisms=cred.mechanism)
+ else:
+ self._agent = QmfAgent(self.host_port())
+ return self._agent
+
+ def qmf(self):
+ hb = self.agent().getHaBroker()
+ hb.update()
+ return hb
+
+ def ha_status(self): return self.qmf().status
+
+ def wait_status(self, status):
+ def try_get_status():
+ self._status = "<unknown>"
+ # Ignore ConnectionError, the broker may not be up yet.
+ try:
+ self._status = self.ha_status()
+ return self._status == status;
+ except ConnectionError: return False
+ assert retry(try_get_status, timeout=20), "%s expected=%r, actual=%r"%(
+ self, status, self._status)
+
+ def wait_queue(self, queue, timeout=1):
+ """ Wait for queue to be visible via QMF"""
+ agent = self.agent()
+ assert retry(lambda: agent.getQueue(queue) is not None, timeout=timeout)
+
+ def wait_no_queue(self, queue, timeout=1):
+ """ Wait for queue to be invisible via QMF"""
+ agent = self.agent()
+ assert retry(lambda: agent.getQueue(queue) is None, timeout=timeout)
+
+ # FIXME aconway 2012-05-01: do direct python call to qpid-config code.
+ def qpid_config(self, args):
+ assert subprocess.call(
+ [self.qpid_config_path, "--broker", self.host_port()]+args,
+ stdout=1, stderr=subprocess.STDOUT
+ ) == 0
+
+ def config_replicate(self, from_broker, queue):
+ self.qpid_config(["add", "queue", "--start-replica", from_broker, queue])
+
+ def config_declare(self, queue, replication):
+ self.qpid_config(["add", "queue", queue, "--replicate", replication])
+
+ def connect_admin(self, **kwargs):
+ cred = self.client_credentials
+ if cred:
+ return Broker.connect(
+ self, client_properties={"qpid.ha-admin":1},
+ username=cred.username, password=cred.password, sasl_mechanisms=cred.mechanism,
+ **kwargs)
+ else:
+ return Broker.connect(self, client_properties={"qpid.ha-admin":1}, **kwargs)
+
+ def wait_address(self, address):
+ """Wait for address to become valid on the broker."""
+ bs = self.connect_admin().session()
+ try: wait_address(bs, address)
+ finally: bs.connection.close()
+
+ def wait_backup(self, address): self.wait_address(address)
+
+ def assert_browse(self, queue, expected, **kwargs):
+ """Verify queue contents by browsing."""
+ bs = self.connect().session()
+ try:
+ wait_address(bs, queue)
+ assert_browse_retry(bs, queue, expected, **kwargs)
+ finally: bs.connection.close()
+
+ def assert_browse_backup(self, queue, expected, **kwargs):
+ """Combines wait_backup and assert_browse_retry."""
+ bs = self.connect_admin().session()
+ try:
+ wait_address(bs, queue)
+ assert_browse_retry(bs, queue, expected, **kwargs)
+ finally: bs.connection.close()
+
+ def assert_connect_fail(self):
+ try:
+ self.connect()
+ self.test.fail("Expected ConnectionError")
+ except ConnectionError: pass
+
+ def try_connect(self):
+ try: return self.connect()
+ except ConnectionError: return None
+
+ def ready(self):
+ return Broker.ready(self, client_properties={"qpid.ha-admin":1})
+
+ def kill(self):
+ self._agent = None
+ return Broker.kill(self)
+
+class HaCluster(object):
+ _cluster_count = 0
+
+ def __init__(self, test, n, promote=True, wait=True, **kwargs):
+ """Start a cluster of n brokers.
+
+ @test: The test being run
+ @n: start n brokers
+ @promote: promote self[0] to primary
+ @wait: wait for primary active and backups ready. Ignored if promote=False
+ """
+ self.test = test
+ self.kwargs = kwargs
+ self._brokers = []
+ self.id = HaCluster._cluster_count
+ self.broker_id = 0
+ HaCluster._cluster_count += 1
+ for i in xrange(n): self.start(False)
+ self.update_urls()
+ if promote:
+ self[0].promote()
+ if wait:
+ self[0].wait_status("active")
+ for b in self[1:]: b.wait_status("ready")
+
+
+ def next_name(self):
+ name="cluster%s-%s"%(self.id, self.broker_id)
+ self.broker_id += 1
+ return name
+
+ def start(self, update_urls=True, args=[]):
+ """Start a new broker in the cluster"""
+ b = HaBroker(self.test, name=self.next_name(), **self.kwargs)
+ b.ready()
+ self._brokers.append(b)
+ if update_urls: self.update_urls()
+ return b
+
+ def update_urls(self):
+ self.url = ",".join([b.host_port() for b in self])
+ if len(self) > 1: # No failover addresses on a 1 cluster.
+ for b in self:
+ b.set_brokers_url(self.url)
+ b.set_public_url(self.url)
+
+ def connect(self, i):
+ """Connect with reconnect_urls"""
+ return self[i].connect(reconnect=True, reconnect_urls=self.url.split(","))
+
+ def kill(self, i, promote_next=True):
+ """Kill broker i, promote broker i+1"""
+ self[i].kill()
+ if promote_next: self[(i+1) % len(self)].promote()
+
+ def restart(self, i):
+ """Start a broker with the same port, name and data directory. It will get
+ a separate log file: foo.n.log"""
+ b = self._brokers[i]
+ self._brokers[i] = HaBroker(
+ self.test, name=b.name, port=b.port(), brokers_url=self.url,
+ **self.kwargs)
+ self._brokers[i].ready()
+
+ def bounce(self, i, promote_next=True):
+ """Stop and restart a broker in a cluster."""
+ if (len(self) == 1):
+ self.kill(i, promote_next=False)
+ self.restart(i)
+ self[i].ready()
+ if promote_next: self[i].promote()
+ else:
+ self.kill(i, promote_next)
+ self.restart(i)
+
+ # Behave like a list of brokers.
+ def __len__(self): return len(self._brokers)
+ def __getitem__(self,index): return self._brokers[index]
+ def __iter__(self): return self._brokers.__iter__()
+
+
+def wait_address(session, address):
+ """Wait for an address to become valid."""
+ def check():
+ try: session.sender(address); return True
+ except NotFound: return False
+ assert retry(check), "Timed out waiting for address %s"%(address)
+
+def valid_address(session, address):
+ """Test if an address is valid"""
+ try:
+ session.receiver(address)
+ return True
+ except NotFound: return False
+
+
diff --git a/cpp/src/tests/ha_tests.py b/cpp/src/tests/ha_tests.py
index 310ef844bd..77399bf2e2 100755
--- a/cpp/src/tests/ha_tests.py
+++ b/cpp/src/tests/ha_tests.py
@@ -18,235 +18,32 @@
# under the License.
#
-import os, signal, sys, time, imp, re, subprocess, glob, random, logging, shutil, math, unittest
+import os, signal, sys, time, imp, re, subprocess, glob, random, logging, shutil, math, unittest, random
import traceback
-from qpid.messaging import Message, NotFound, ConnectionError, ReceiverError, Connection, Timeout, Disposition, REJECTED
+from qpid.messaging import Message, SessionError, NotFound, ConnectionError, ReceiverError, Connection, Timeout, Disposition, REJECTED, Empty
from qpid.datatypes import uuid4
from brokertest import *
+from ha_test import *
from threading import Thread, Lock, Condition
from logging import getLogger, WARN, ERROR, DEBUG, INFO
-from qpidtoollibs import BrokerAgent
+from qpidtoollibs import BrokerAgent, EventHelper
from uuid import UUID
log = getLogger(__name__)
-class QmfAgent(object):
- """Access to a QMF broker agent."""
- def __init__(self, address, **kwargs):
- self._connection = Connection.establish(
- address, client_properties={"qpid.ha-admin":1}, **kwargs)
- self._agent = BrokerAgent(self._connection)
- assert self._agent.getHaBroker(), "HA module not loaded in broker at: %s"%(address)
+def grep(filename, regexp):
+ for line in open(filename).readlines():
+ if (regexp.search(line)): return True
+ return False
- def __getattr__(self, name):
- a = getattr(self._agent, name)
- return a
+class HaBrokerTest(BrokerTest):
+ """Base class for HA broker tests"""
+ def assert_log_no_errors(self, broker):
+ log = broker.get_log()
+ if grep(log, re.compile("] error|] critical")):
+ self.fail("Errors in log file %s"%(log))
-class Credentials(object):
- """SASL credentials: username, password, and mechanism"""
- def __init__(self, username, password, mechanism):
- (self.username, self.password, self.mechanism) = (username, password, mechanism)
-
- def __str__(self): return "Credentials%s"%(self.tuple(),)
-
- def tuple(self): return (self.username, self.password, self.mechanism)
-
- def add_user(self, url): return "%s/%s@%s"%(self.username, self.password, url)
-
-class HaBroker(Broker):
- """Start a broker with HA enabled
- @param client_cred: (user, password, mechanism) for admin clients started by the HaBroker.
- """
- def __init__(self, test, args=[], brokers_url=None, ha_cluster=True, ha_replicate="all",
- client_credentials=None, **kwargs):
- assert BrokerTest.ha_lib, "Cannot locate HA plug-in"
- args = copy(args)
- args += ["--load-module", BrokerTest.ha_lib,
- "--log-enable=debug+:ha::",
- # FIXME aconway 2012-02-13: workaround slow link failover.
- "--link-maintenace-interval=0.1",
- "--ha-cluster=%s"%ha_cluster]
- if ha_replicate is not None:
- args += [ "--ha-replicate=%s"%ha_replicate ]
- if brokers_url: args += [ "--ha-brokers-url", brokers_url ]
- Broker.__init__(self, test, args, **kwargs)
- self.qpid_ha_path=os.path.join(os.getenv("PYTHON_COMMANDS"), "qpid-ha")
- assert os.path.exists(self.qpid_ha_path)
- self.qpid_config_path=os.path.join(os.getenv("PYTHON_COMMANDS"), "qpid-config")
- assert os.path.exists(self.qpid_config_path)
- getLogger().setLevel(ERROR) # Hide expected WARNING log messages from failover.
- self.qpid_ha_script=import_script(self.qpid_ha_path)
- self._agent = None
- self.client_credentials = client_credentials
-
- def __str__(self): return Broker.__str__(self)
-
- def qpid_ha(self, args):
- cred = self.client_credentials
- url = self.host_port()
- if cred:
- url =cred.add_user(url)
- args = args + ["--sasl-mechanism", cred.mechanism]
- self.qpid_ha_script.main_except(["", "-b", url]+args)
-
- def promote(self): self.qpid_ha(["promote"])
- def set_client_url(self, url): self.qpid_ha(["set", "--public-url", url])
- def set_brokers_url(self, url): self.qpid_ha(["set", "--brokers-url", url])
- def replicate(self, from_broker, queue): self.qpid_ha(["replicate", from_broker, queue])
-
- def agent(self):
- if not self._agent:
- cred = self.client_credentials
- if cred:
- self._agent = QmfAgent(cred.add_user(self.host_port()), sasl_mechanisms=cred.mechanism)
- else:
- self._agent = QmfAgent(self.host_port())
- return self._agent
-
- def ha_status(self):
- hb = self.agent().getHaBroker()
- hb.update()
- return hb.status
-
- def wait_status(self, status):
- def try_get_status():
- # Ignore ConnectionError, the broker may not be up yet.
- try:
- self._status = self.ha_status()
- return self._status == status;
- except ConnectionError: return False
- assert retry(try_get_status, timeout=20), "%s %r != %r"%(self, self._status, status)
-
- # FIXME aconway 2012-05-01: do direct python call to qpid-config code.
- def qpid_config(self, args):
- assert subprocess.call(
- [self.qpid_config_path, "--broker", self.host_port()]+args) == 0
-
- def config_replicate(self, from_broker, queue):
- self.qpid_config(["add", "queue", "--start-replica", from_broker, queue])
-
- def config_declare(self, queue, replication):
- self.qpid_config(["add", "queue", queue, "--replicate", replication])
-
- def connect_admin(self, **kwargs):
- cred = self.client_credentials
- if cred:
- return Broker.connect(
- self, client_properties={"qpid.ha-admin":1},
- username=cred.username, password=cred.password, sasl_mechanisms=cred.mechanism,
- **kwargs)
- else:
- return Broker.connect(self, client_properties={"qpid.ha-admin":1}, **kwargs)
-
- def wait_backup(self, address):
- """Wait for address to become valid on a backup broker."""
- bs = self.connect_admin().session()
- try: wait_address(bs, address)
- finally: bs.connection.close()
-
- def assert_browse(self, queue, expected, **kwargs):
- """Verify queue contents by browsing."""
- bs = self.connect().session()
- try:
- wait_address(bs, queue)
- assert_browse_retry(bs, queue, expected, **kwargs)
- finally: bs.connection.close()
-
- def assert_browse_backup(self, queue, expected, **kwargs):
- """Combines wait_backup and assert_browse_retry."""
- bs = self.connect_admin().session()
- try:
- wait_address(bs, queue)
- assert_browse_retry(bs, queue, expected, **kwargs)
- finally: bs.connection.close()
-
- def assert_connect_fail(self):
- try:
- self.connect()
- self.test.fail("Expected ConnectionError")
- except ConnectionError: pass
-
- def try_connect(self):
- try: return self.connect()
- except ConnectionError: return None
-
-class HaCluster(object):
- _cluster_count = 0
-
- def __init__(self, test, n, promote=True, **kwargs):
- """Start a cluster of n brokers"""
- self.test = test
- self.kwargs = kwargs
- self._brokers = []
- self.id = HaCluster._cluster_count
- self.broker_id = 0
- HaCluster._cluster_count += 1
- for i in xrange(n): self.start(False)
- self.update_urls()
- self[0].promote()
-
- def next_name(self):
- name="cluster%s-%s"%(self.id, self.broker_id)
- self.broker_id += 1
- return name
-
- def start(self, update_urls=True, args=[]):
- """Start a new broker in the cluster"""
- b = HaBroker(self.test, name=self.next_name(), **self.kwargs)
- self._brokers.append(b)
- if update_urls: self.update_urls()
- return b
-
- def update_urls(self):
- self.url = ",".join([b.host_port() for b in self])
- if len(self) > 1: # No failover addresses on a 1 cluster.
- for b in self: b.set_brokers_url(self.url)
-
- def connect(self, i):
- """Connect with reconnect_urls"""
- return self[i].connect(reconnect=True, reconnect_urls=self.url.split(","))
-
- def kill(self, i, promote_next=True):
- """Kill broker i, promote broker i+1"""
- self[i].expect = EXPECT_EXIT_FAIL
- self[i].kill()
- if promote_next: self[(i+1) % len(self)].promote()
-
- def restart(self, i):
- """Start a broker with the same port, name and data directory. It will get
- a separate log file: foo.n.log"""
- b = self._brokers[i]
- self._brokers[i] = HaBroker(
- self.test, name=b.name, port=b.port(), brokers_url=self.url,
- **self.kwargs)
-
- def bounce(self, i, promote_next=True):
- """Stop and restart a broker in a cluster."""
- self.kill(i, promote_next)
- self.restart(i)
-
- # Behave like a list of brokers.
- def __len__(self): return len(self._brokers)
- def __getitem__(self,index): return self._brokers[index]
- def __iter__(self): return self._brokers.__iter__()
-
-def wait_address(session, address):
- """Wait for an address to become valid."""
- def check():
- try:
- session.sender(address)
- return True
- except NotFound: return False
- assert retry(check), "Timed out waiting for address %s"%(address)
-
-def valid_address(session, address):
- """Test if an address is valid"""
- try:
- session.receiver(address)
- return True
- except NotFound: return False
-
-class ReplicationTests(BrokerTest):
+class ReplicationTests(HaBrokerTest):
"""Correctness tests for HA replication."""
def test_replication(self):
@@ -256,8 +53,9 @@ class ReplicationTests(BrokerTest):
def queue(name, replicate):
return "%s;{create:always,node:{x-declare:{arguments:{'qpid.replicate':%s}}}}"%(name, replicate)
- def exchange(name, replicate, bindq):
- return"%s;{create:always,node:{type:topic,x-declare:{arguments:{'qpid.replicate':%s}, type:'fanout'},x-bindings:[{exchange:'%s',queue:'%s'}]}}"%(name, replicate, name, bindq)
+ def exchange(name, replicate, bindq, key):
+ return "%s/%s;{create:always,node:{type:topic,x-declare:{arguments:{'qpid.replicate':%s}, type:'topic'},x-bindings:[{exchange:'%s',queue:'%s',key:'%s'}]}}"%(name, key, replicate, name, bindq, key)
+
def setup(p, prefix, primary):
"""Create config, send messages on the primary p"""
s = p.sender(queue(prefix+"q1", "all"))
@@ -267,16 +65,21 @@ class ReplicationTests(BrokerTest):
p.acknowledge()
p.sender(queue(prefix+"q2", "configuration")).send(Message("2"))
p.sender(queue(prefix+"q3", "none")).send(Message("3"))
- p.sender(exchange(prefix+"e1", "all", prefix+"q1")).send(Message("4"))
- p.sender(exchange(prefix+"e2", "all", prefix+"q2")).send(Message("5"))
+ p.sender(exchange(prefix+"e1", "all", prefix+"q1", "key1")).send(Message("4"))
+ p.sender(exchange(prefix+"e2", "configuration", prefix+"q2", "key2")).send(Message("5"))
# Test unbind
p.sender(queue(prefix+"q4", "all")).send(Message("6"))
- s3 = p.sender(exchange(prefix+"e4", "all", prefix+"q4"))
+ s3 = p.sender(exchange(prefix+"e4", "all", prefix+"q4", "key4"))
s3.send(Message("7"))
# Use old connection to unbind
us = primary.connect_old().session(str(uuid4()))
- us.exchange_unbind(exchange=prefix+"e4", binding_key="", queue=prefix+"q4")
+ us.exchange_unbind(exchange=prefix+"e4", binding_key="key4", queue=prefix+"q4")
p.sender(prefix+"e4").send(Message("drop1")) # Should be dropped
+ # Test replication of deletes
+ p.sender(queue(prefix+"dq", "all"))
+ p.sender(exchange(prefix+"de", "all", prefix+"dq", ""))
+ p.sender(prefix+"dq;{delete:always}").close()
+ p.sender(prefix+"de;{delete:always}").close()
# Need a marker so we can wait till sync is done.
p.sender(queue(prefix+"x", "configuration"))
@@ -292,50 +95,61 @@ class ReplicationTests(BrokerTest):
self.assert_browse_retry(b, prefix+"q2", []) # configuration only
assert not valid_address(b, prefix+"q3")
- b.sender(prefix+"e1").send(Message(prefix+"e1")) # Verify binds with replicate=all
+
+ # Verify exchange with replicate=all
+ b.sender(prefix+"e1/key1").send(Message(prefix+"e1"))
self.assert_browse_retry(b, prefix+"q1", ["1", "4", prefix+"e1"])
- b.sender(prefix+"e2").send(Message(prefix+"e2")) # Verify binds with replicate=configuration
+
+ # Verify exchange with replicate=configuration
+ b.sender(prefix+"e2/key2").send(Message(prefix+"e2"))
self.assert_browse_retry(b, prefix+"q2", [prefix+"e2"])
- b.sender(prefix+"e4").send(Message("drop2")) # Verify unbind.
+ b.sender(prefix+"e4/key4").send(Message("drop2")) # Verify unbind.
self.assert_browse_retry(b, prefix+"q4", ["6","7"])
- primary = HaBroker(self, name="primary")
- primary.promote()
- p = primary.connect().session()
+ # Verify deletes
+ assert not valid_address(b, prefix+"dq")
+ assert not valid_address(b, prefix+"de")
- # Create config, send messages before starting the backup, to test catch-up replication.
- setup(p, "1", primary)
- backup = HaBroker(self, name="backup", brokers_url=primary.host_port())
- # Create config, send messages after starting the backup, to test steady-state replication.
- setup(p, "2", primary)
-
- # Verify the data on the backup
- b = backup.connect_admin().session()
- verify(b, "1", p)
- verify(b, "2", p)
- # Test a series of messages, enqueue all then dequeue all.
- s = p.sender(queue("foo","all"))
- wait_address(b, "foo")
- msgs = [str(i) for i in range(10)]
- for m in msgs: s.send(Message(m))
- self.assert_browse_retry(p, "foo", msgs)
- self.assert_browse_retry(b, "foo", msgs)
- r = p.receiver("foo")
- for m in msgs: self.assertEqual(m, r.fetch(timeout=0).content)
- p.acknowledge()
- self.assert_browse_retry(p, "foo", [])
- self.assert_browse_retry(b, "foo", [])
-
- # Another series, this time verify each dequeue individually.
- for m in msgs: s.send(Message(m))
- self.assert_browse_retry(p, "foo", msgs)
- self.assert_browse_retry(b, "foo", msgs)
- for i in range(len(msgs)):
- self.assertEqual(msgs[i], r.fetch(timeout=0).content)
+ l = LogLevel(ERROR) # Hide expected WARNING log messages from failover.
+ try:
+ primary = HaBroker(self, name="primary")
+ primary.promote()
+ p = primary.connect().session()
+
+ # Create config, send messages before starting the backup, to test catch-up replication.
+ setup(p, "1", primary)
+ backup = HaBroker(self, name="backup", brokers_url=primary.host_port())
+ # Create config, send messages after starting the backup, to test steady-state replication.
+ setup(p, "2", primary)
+
+ # Verify the data on the backup
+ b = backup.connect_admin().session()
+ verify(b, "1", p)
+ verify(b, "2", p)
+ # Test a series of messages, enqueue all then dequeue all.
+ s = p.sender(queue("foo","all"))
+ wait_address(b, "foo")
+ msgs = [str(i) for i in range(10)]
+ for m in msgs: s.send(Message(m))
+ self.assert_browse_retry(p, "foo", msgs)
+ self.assert_browse_retry(b, "foo", msgs)
+ r = p.receiver("foo")
+ for m in msgs: self.assertEqual(m, r.fetch(timeout=0).content)
p.acknowledge()
- self.assert_browse_retry(p, "foo", msgs[i+1:])
- self.assert_browse_retry(b, "foo", msgs[i+1:])
+ self.assert_browse_retry(p, "foo", [])
+ self.assert_browse_retry(b, "foo", [])
+
+ # Another series, this time verify each dequeue individually.
+ for m in msgs: s.send(Message(m))
+ self.assert_browse_retry(p, "foo", msgs)
+ self.assert_browse_retry(b, "foo", msgs)
+ for i in range(len(msgs)):
+ self.assertEqual(msgs[i], r.fetch(timeout=0).content)
+ p.acknowledge()
+ self.assert_browse_retry(p, "foo", msgs[i+1:])
+ self.assert_browse_retry(b, "foo", msgs[i+1:])
+ finally: l.restore()
def test_sync(self):
primary = HaBroker(self, name="primary")
@@ -361,53 +175,59 @@ class ReplicationTests(BrokerTest):
def test_send_receive(self):
"""Verify sequence numbers of messages sent by qpid-send"""
- brokers = HaCluster(self, 3)
- sender = self.popen(
- ["qpid-send",
- "--broker", brokers[0].host_port(),
- "--address", "q;{create:always}",
- "--messages=1000",
- "--content-string=x"
- ])
- receiver = self.popen(
- ["qpid-receive",
- "--broker", brokers[0].host_port(),
- "--address", "q;{create:always}",
- "--messages=990",
- "--timeout=10"
- ])
- self.assertEqual(sender.wait(), 0)
- self.assertEqual(receiver.wait(), 0)
- expect = [long(i) for i in range(991, 1001)]
- sn = lambda m: m.properties["sn"]
- brokers[1].assert_browse_backup("q", expect, transform=sn)
- brokers[2].assert_browse_backup("q", expect, transform=sn)
+ l = LogLevel(ERROR) # Hide expected WARNING log messages from failover.
+ try:
+ brokers = HaCluster(self, 3)
+ sender = self.popen(
+ ["qpid-send",
+ "--broker", brokers[0].host_port(),
+ "--address", "q;{create:always}",
+ "--messages=1000",
+ "--content-string=x"
+ ])
+ receiver = self.popen(
+ ["qpid-receive",
+ "--broker", brokers[0].host_port(),
+ "--address", "q;{create:always}",
+ "--messages=990",
+ "--timeout=10"
+ ])
+ self.assertEqual(sender.wait(), 0)
+ self.assertEqual(receiver.wait(), 0)
+ expect = [long(i) for i in range(991, 1001)]
+ sn = lambda m: m.properties["sn"]
+ brokers[1].assert_browse_backup("q", expect, transform=sn)
+ brokers[2].assert_browse_backup("q", expect, transform=sn)
+ finally: l.restore()
def test_failover_python(self):
"""Verify that backups rejects connections and that fail-over works in python client"""
- primary = HaBroker(self, name="primary", expect=EXPECT_EXIT_FAIL)
- primary.promote()
- backup = HaBroker(self, name="backup", brokers_url=primary.host_port())
- # Check that backup rejects normal connections
+ l = LogLevel(ERROR) # Hide expected WARNING log messages from failover.
try:
- backup.connect().session()
- self.fail("Expected connection to backup to fail")
- except ConnectionError: pass
- # Check that admin connections are allowed to backup.
- backup.connect_admin().close()
-
- # Test discovery: should connect to primary after reject by backup
- c = backup.connect(reconnect_urls=[primary.host_port(), backup.host_port()], reconnect=True)
- s = c.session()
- sender = s.sender("q;{create:always}")
- backup.wait_backup("q")
- sender.send("foo")
- primary.kill()
- assert retry(lambda: not is_running(primary.pid))
- backup.promote()
- sender.send("bar")
- self.assert_browse_retry(s, "q", ["foo", "bar"])
- c.close()
+ primary = HaBroker(self, name="primary", expect=EXPECT_EXIT_FAIL)
+ primary.promote()
+ backup = HaBroker(self, name="backup", brokers_url=primary.host_port())
+ # Check that backup rejects normal connections
+ try:
+ backup.connect().session()
+ self.fail("Expected connection to backup to fail")
+ except ConnectionError: pass
+ # Check that admin connections are allowed to backup.
+ backup.connect_admin().close()
+
+ # Test discovery: should connect to primary after reject by backup
+ c = backup.connect(reconnect_urls=[primary.host_port(), backup.host_port()], reconnect=True)
+ s = c.session()
+ sender = s.sender("q;{create:always}")
+ backup.wait_backup("q")
+ sender.send("foo")
+ primary.kill()
+ assert retry(lambda: not is_running(primary.pid))
+ backup.promote()
+ sender.send("bar")
+ self.assert_browse_retry(s, "q", ["foo", "bar"])
+ c.close()
+ finally: l.restore()
def test_failover_cpp(self):
"""Verify that failover works in the C++ client."""
@@ -456,51 +276,61 @@ class ReplicationTests(BrokerTest):
def test_standalone_queue_replica(self):
"""Test replication of individual queues outside of cluster mode"""
- getLogger().setLevel(ERROR) # Hide expected WARNING log messages from failover.
- primary = HaBroker(self, name="primary", ha_cluster=False)
- pc = primary.connect()
- ps = pc.session().sender("q;{create:always}")
- pr = pc.session().receiver("q;{create:always}")
- backup = HaBroker(self, name="backup", ha_cluster=False)
- br = backup.connect().session().receiver("q;{create:always}")
-
- # Set up replication with qpid-ha
- backup.replicate(primary.host_port(), "q")
- ps.send("a")
- backup.assert_browse_backup("q", ["a"])
- ps.send("b")
- backup.assert_browse_backup("q", ["a", "b"])
- self.assertEqual("a", pr.fetch().content)
- pr.session.acknowledge()
- backup.assert_browse_backup("q", ["b"])
-
- # Set up replication with qpid-config
- ps2 = pc.session().sender("q2;{create:always}")
- backup.config_replicate(primary.host_port(), "q2");
- ps2.send("x")
- backup.assert_browse_backup("q2", ["x"])
-
+ l = LogLevel(ERROR) # Hide expected WARNING log messages from failover.
+ try:
+ primary = HaBroker(self, name="primary", ha_cluster=False,
+ args=["--ha-queue-replication=yes"]);
+ pc = primary.connect()
+ ps = pc.session().sender("q;{create:always}")
+ pr = pc.session().receiver("q;{create:always}")
+ backup = HaBroker(self, name="backup", ha_cluster=False,
+ args=["--ha-queue-replication=yes"])
+ br = backup.connect().session().receiver("q;{create:always}")
+
+ # Set up replication with qpid-ha
+ backup.replicate(primary.host_port(), "q")
+ ps.send("a")
+ backup.assert_browse_backup("q", ["a"])
+ ps.send("b")
+ backup.assert_browse_backup("q", ["a", "b"])
+ self.assertEqual("a", pr.fetch().content)
+ pr.session.acknowledge()
+ backup.assert_browse_backup("q", ["b"])
+
+ # Set up replication with qpid-config
+ ps2 = pc.session().sender("q2;{create:always}")
+ backup.config_replicate(primary.host_port(), "q2");
+ ps2.send("x")
+ backup.assert_browse_backup("q2", ["x"])
+ finally: l.restore()
def test_queue_replica_failover(self):
- """Test individual queue replication from a cluster to a standalone backup broker, verify it fails over."""
- cluster = HaCluster(self, 2)
- primary = cluster[0]
- pc = cluster.connect(0)
- ps = pc.session().sender("q;{create:always}")
- pr = pc.session().receiver("q;{create:always}")
- backup = HaBroker(self, name="backup", ha_cluster=False)
- br = backup.connect().session().receiver("q;{create:always}")
- backup.replicate(cluster.url, "q")
- ps.send("a")
- backup.assert_browse_backup("q", ["a"])
- cluster.bounce(0)
- backup.assert_browse_backup("q", ["a"])
- ps.send("b")
- backup.assert_browse_backup("q", ["a", "b"])
- cluster.bounce(1)
- self.assertEqual("a", pr.fetch().content)
- pr.session.acknowledge()
- backup.assert_browse_backup("q", ["b"])
+ """Test individual queue replication from a cluster to a standalone
+ backup broker, verify it fails over."""
+ l = LogLevel(ERROR) # Hide expected WARNING log messages from failover.
+ try:
+ cluster = HaCluster(self, 2)
+ primary = cluster[0]
+ pc = cluster.connect(0)
+ ps = pc.session().sender("q;{create:always}")
+ pr = pc.session().receiver("q;{create:always}")
+ backup = HaBroker(self, name="backup", ha_cluster=False,
+ args=["--ha-queue-replication=yes"])
+ br = backup.connect().session().receiver("q;{create:always}")
+ backup.replicate(cluster.url, "q")
+ ps.send("a")
+ backup.assert_browse_backup("q", ["a"])
+ cluster.bounce(0)
+ backup.assert_browse_backup("q", ["a"])
+ ps.send("b")
+ backup.assert_browse_backup("q", ["a", "b"])
+ cluster.bounce(1)
+ self.assertEqual("a", pr.fetch().content)
+ pr.session.acknowledge()
+ backup.assert_browse_backup("q", ["b"])
+ pc.close()
+ br.close()
+ finally: l.restore()
def test_lvq(self):
"""Verify that we replicate to an LVQ correctly"""
@@ -634,8 +464,10 @@ class ReplicationTests(BrokerTest):
def test_replicate_default(self):
"""Make sure we don't replicate if ha-replicate is unspecified or none"""
cluster1 = HaCluster(self, 2, ha_replicate=None)
+ cluster1[1].wait_status("ready")
c1 = cluster1[0].connect().session().sender("q;{create:always}")
cluster2 = HaCluster(self, 2, ha_replicate="none")
+ cluster2[1].wait_status("ready")
cluster2[0].connect().session().sender("q;{create:always}")
time.sleep(.1) # Give replication a chance.
try:
@@ -647,6 +479,23 @@ class ReplicationTests(BrokerTest):
self.fail("Excpected no-such-queue exception")
except NotFound: pass
+ def test_replicate_binding(self):
+ """Verify that binding replication can be disabled"""
+ primary = HaBroker(self, name="primary", expect=EXPECT_EXIT_FAIL)
+ primary.promote()
+ backup = HaBroker(self, name="backup", brokers_url=primary.host_port())
+ ps = primary.connect().session()
+ ps.sender("ex;{create:always,node:{type:topic,x-declare:{arguments:{'qpid.replicate':all}, type:'fanout'}}}")
+ ps.sender("q;{create:always,node:{type:queue,x-declare:{arguments:{'qpid.replicate':all}},x-bindings:[{exchange:'ex',queue:'q',key:'',arguments:{'qpid.replicate':none}}]}}")
+ backup.wait_backup("q")
+
+ primary.kill()
+ assert retry(lambda: not is_running(primary.pid)) # Wait for primary to die
+ backup.promote()
+ bs = backup.connect_admin().session()
+ bs.sender("ex").send(Message("msg"))
+ self.assert_browse_retry(bs, "q", [])
+
def test_invalid_replication(self):
"""Verify that we reject an attempt to declare a queue with invalid replication value."""
cluster = HaCluster(self, 1, ha_replicate="all")
@@ -672,20 +521,26 @@ class ReplicationTests(BrokerTest):
def test_auto_delete_exclusive(self):
"""Verify that we ignore auto-delete, exclusive, non-auto-delete-timeout queues"""
- cluster = HaCluster(self,2)
- s = cluster[0].connect().session()
- s.receiver("exad;{create:always,node:{x-declare:{exclusive:True,auto-delete:True}}}")
- s.receiver("ex;{create:always,node:{x-declare:{exclusive:True}}}")
- s.receiver("ad;{create:always,node:{x-declare:{auto-delete:True}}}")
- s.receiver("time;{create:always,node:{x-declare:{exclusive:True,auto-delete:True,arguments:{'qpid.auto_delete_timeout':1}}}}")
- s.receiver("q;{create:always}")
+ cluster = HaCluster(self, 2)
+ s0 = cluster[0].connect().session()
+ s0.receiver("exad;{create:always,node:{x-declare:{exclusive:True,auto-delete:True}}}")
+ s0.receiver("ex;{create:always,node:{x-declare:{exclusive:True}}}")
+ ad = s0.receiver("ad;{create:always,node:{x-declare:{auto-delete:True}}}")
+ s0.receiver("time;{create:always,node:{x-declare:{exclusive:True,auto-delete:True,arguments:{'qpid.auto_delete_timeout':1}}}}")
+ s0.receiver("q;{create:always}")
- s = cluster[1].connect_admin().session()
+ s1 = cluster[1].connect_admin().session()
cluster[1].wait_backup("q")
- assert not valid_address(s, "exad")
- assert valid_address(s, "ex")
- assert valid_address(s, "ad")
- assert valid_address(s, "time")
+ assert not valid_address(s1, "exad")
+ assert valid_address(s1, "ex")
+ assert valid_address(s1, "ad")
+ assert valid_address(s1, "time")
+
+ # Verify that auto-delete queues are not kept alive by
+ # replicating subscriptions
+ ad.close()
+ s0.sync()
+ assert not valid_address(s0, "ad")
def test_broker_info(self):
"""Check that broker information is correctly published via management"""
@@ -763,18 +618,18 @@ acl deny all all
s.sender("altex;{create:always,node:{type:topic,x-declare:{type:'fanout'}}}")
# altq queue bound to altex, collect re-routed messages.
s.sender("altq;{create:always,node:{x-bindings:[{exchange:'altex',queue:altq}]}}")
- # 0ex exchange with alternate-exchange altex and no queues bound
- s.sender("0ex;{create:always,node:{type:topic, x-declare:{type:'direct', alternate-exchange:'altex'}}}")
+ # ex exchange with alternate-exchange altex and no queues bound
+ s.sender("ex;{create:always,node:{type:topic, x-declare:{type:'direct', alternate-exchange:'altex'}}}")
# create queue q with alternate-exchange altex
s.sender("q;{create:always,node:{type:queue, x-declare:{alternate-exchange:'altex'}}}")
# create a bunch of exchanges to ensure we don't clean up prematurely if the
# response comes in multiple fragments.
- for i in xrange(200): s.sender("00ex%s;{create:always,node:{type:topic}}"%i)
+ for i in xrange(200): s.sender("ex.%s;{create:always,node:{type:topic}}"%i)
def verify(broker):
s = broker.connect().session()
# Verify unmatched message goes to ex's alternate.
- s.sender("0ex").send("foo")
+ s.sender("ex").send("foo")
altq = s.receiver("altq")
self.assertEqual("foo", altq.fetch(timeout=0).content)
s.acknowledge()
@@ -786,20 +641,265 @@ acl deny all all
self.assertEqual("bar", altq.fetch(timeout=0).content)
s.acknowledge()
+ def ss(n): return cluster[n].connect().session()
+
# Sanity check: alternate exchanges on original broker
verify(cluster[0])
+ # Altex is in use as an alternate exchange.
+ self.assertRaises(SessionError,
+ lambda:ss(0).sender("altex;{delete:always}").close())
# Check backup that was connected during setup.
- cluster[1].wait_backup("0ex")
+ cluster[1].wait_status("ready")
+ cluster[1].wait_backup("ex")
cluster[1].wait_backup("q")
cluster.bounce(0)
verify(cluster[1])
+
# Check a newly started backup.
cluster.start()
- cluster[2].wait_backup("0ex")
+ cluster[2].wait_status("ready")
+ cluster[2].wait_backup("ex")
cluster[2].wait_backup("q")
cluster.bounce(1)
verify(cluster[2])
+ # Check that alt-exchange in-use count is replicated
+ s = cluster[2].connect().session();
+
+ self.assertRaises(SessionError,
+ lambda:ss(2).sender("altex;{delete:always}").close())
+ s.sender("q;{delete:always}").close()
+ self.assertRaises(SessionError,
+ lambda:ss(2).sender("altex;{delete:always}").close())
+ s.sender("ex;{delete:always}").close()
+ s.sender("altex;{delete:always}").close()
+
+ def test_priority_reroute(self):
+ """Regression test for QPID-4262, rerouting messages from a priority queue
+ to itself causes a crash"""
+ cluster = HaCluster(self, 2)
+ primary = cluster[0]
+ session = primary.connect().session()
+ s = session.sender("pq; {create:always, node:{x-declare:{arguments:{'qpid.priorities':10}},x-bindings:[{exchange:'amq.fanout',queue:pq}]}}")
+ for m in xrange(100): s.send(Message(str(m), priority=m%10))
+ pq = QmfAgent(primary.host_port()).getQueue("pq")
+ pq.reroute(request=0, useAltExchange=False, exchange="amq.fanout")
+ # Verify that consuming is in priority order
+ expect = [str(10*i+p) for p in xrange(9,-1,-1) for i in xrange(0,10) ]
+ actual = [m.content for m in primary.get_messages("pq", 100)]
+ self.assertEqual(expect, actual)
+
+ def test_delete_missing_response(self):
+ """Check that a backup correctly deletes leftover queues and exchanges that are
+ missing from the initial reponse set."""
+ # This test is a bit contrived, we set up the situation on backup brokers
+ # and then promote one.
+ cluster = HaCluster(self, 2, promote=False)
+
+ # cluster[0] Will be the primary
+ s = cluster[0].connect_admin().session()
+ s.sender("q1;{create:always}")
+ s.sender("e1;{create:always, node:{type:topic}}")
+
+ # cluster[1] will be the backup, has extra queues/exchanges
+ xdecl = "x-declare:{arguments:{'qpid.replicate':'all'}}"
+ node = "node:{%s}"%(xdecl)
+ s = cluster[1].connect_admin().session()
+ s.sender("q1;{create:always, %s}"%(node))
+ s.sender("q2;{create:always, %s}"%(node))
+ s.sender("e1;{create:always, node:{type:topic, %s}}"%(xdecl))
+ s.sender("e2;{create:always, node:{type:topic, %s}}"%(xdecl))
+ for a in ["q1", "q2", "e1", "e2"]: cluster[1].wait_backup(a)
+
+ cluster[0].promote()
+ # Verify the backup deletes the surplus queue and exchange
+ cluster[1].wait_status("ready")
+ s = cluster[1].connect_admin().session()
+ self.assertRaises(NotFound, s.receiver, ("q2"));
+ self.assertRaises(NotFound, s.receiver, ("e2"));
+
+
+ def test_delete_qpid_4285(self):
+ """Regression test for QPID-4285: on deleting a queue it gets stuck in a
+ partially deleted state and causes replication errors."""
+ cluster = HaCluster(self,2)
+ s = cluster[0].connect().session()
+ s.receiver("q;{create:always}")
+ cluster[1].wait_backup("q")
+ cluster.kill(0) # Make the backup take over.
+ s = cluster[1].connect().session()
+ s.receiver("q;{delete:always}").close() # Delete q on new primary
+ try:
+ s.receiver("q")
+ self.fail("Expected NotFound exception") # Should not be avaliable
+ except NotFound: pass
+ assert not cluster[1].agent().getQueue("q") # Should not be in QMF
+
+ def alt_setup(self, session, suffix):
+ # Create exchange to use as alternate and a queue bound to it.
+ # altex exchange: acts as alternate exchange
+ session.sender("altex%s;{create:always,node:{type:topic,x-declare:{type:'fanout'}}}"%(suffix))
+ # altq queue bound to altex, collect re-routed messages.
+ session.sender("altq%s;{create:always,node:{x-bindings:[{exchange:'altex%s',queue:altq%s}]}}"%(suffix,suffix,suffix))
+
+ def test_auto_delete_close(self):
+ """Verify auto-delete queues are deleted on backup if auto-deleted
+ on primary"""
+ cluster=HaCluster(self, 2)
+ p = cluster[0].connect().session()
+ self.alt_setup(p, "1")
+ r = p.receiver("adq1;{create:always,node:{x-declare:{auto-delete:True,alternate-exchange:'altex1'}}}", capacity=1)
+ s = p.sender("adq1")
+ for m in ["aa","bb","cc"]: s.send(m)
+ p.sender("adq2;{create:always,node:{x-declare:{auto-delete:True}}}")
+ cluster[1].wait_queue("adq1")
+ cluster[1].wait_queue("adq2")
+ r.close() # trigger auto-delete of adq1
+ cluster[1].wait_no_queue("adq1")
+ cluster[1].assert_browse_backup("altq1", ["aa","bb","cc"])
+ cluster[1].wait_queue("adq2")
+
+ def test_auto_delete_crash(self):
+ """Verify auto-delete queues are deleted on backup if the primary crashes"""
+ cluster=HaCluster(self, 2)
+ p = cluster[0].connect().session()
+ self.alt_setup(p,"1")
+
+ # adq1 is subscribed so will be auto-deleted.
+ r = p.receiver("adq1;{create:always,node:{x-declare:{auto-delete:True,alternate-exchange:'altex1'}}}", capacity=1)
+ s = p.sender("adq1")
+ for m in ["aa","bb","cc"]: s.send(m)
+ # adq2 is subscribed after cluster[2] starts.
+ p.sender("adq2;{create:always,node:{x-declare:{auto-delete:True}}}")
+ # adq3 is never subscribed.
+ p.sender("adq3;{create:always,node:{x-declare:{auto-delete:True}}}")
+
+ cluster.start()
+ cluster[2].wait_status("ready")
+
+ p.receiver("adq2") # Subscribed after cluster[2] joined
+
+ for q in ["adq1","adq2","adq3","altq1"]: cluster[1].wait_queue(q)
+ for q in ["adq1","adq2","adq3","altq1"]: cluster[2].wait_queue(q)
+ cluster[0].kill()
+
+ cluster[1].wait_no_queue("adq1")
+ cluster[1].wait_no_queue("adq2")
+ cluster[1].wait_queue("adq3")
+
+ cluster[2].wait_no_queue("adq1")
+ cluster[2].wait_no_queue("adq2")
+ cluster[2].wait_queue("adq3")
+
+ cluster[1].assert_browse_backup("altq1", ["aa","bb","cc"])
+ cluster[2].assert_browse_backup("altq1", ["aa","bb","cc"])
+
+ def test_auto_delete_timeout(self):
+ cluster = HaCluster(self, 2)
+ # Test timeout
+ r1 = cluster[0].connect().session().receiver("q1;{create:always,node:{x-declare:{auto-delete:True,arguments:{'qpid.auto_delete_timeout':1}}}}")
+ # Test special case of timeout = 0
+ r0 = cluster[0].connect().session().receiver("q0;{create:always,node:{x-declare:{auto-delete:True,arguments:{'qpid.auto_delete_timeout':0}}}}")
+ cluster[1].wait_queue("q0")
+ cluster[1].wait_queue("q1")
+ cluster[0].kill()
+ cluster[1].wait_queue("q1") # Not timed out yet
+ cluster[1].wait_no_queue("q1", timeout=5) # Wait for timeout
+ cluster[1].wait_no_queue("q0", timeout=5) # Wait for timeout
+
+ def test_alt_exchange_dup(self):
+ """QPID-4349: if a queue has an alterante exchange and is deleted the
+ messages appear twice on the alternate, they are rerouted once by the
+ primary and again by the backup."""
+ cluster = HaCluster(self,2)
+
+ # Set up q with alternate exchange altex bound to altq.
+ s = cluster[0].connect().session()
+ s.sender("altex;{create:always,node:{type:topic,x-declare:{type:'fanout'}}}")
+ s.sender("altq;{create:always,node:{x-bindings:[{exchange:'altex',queue:altq}]}}")
+ snd = s.sender("q;{create:always,node:{x-declare:{alternate-exchange:'altex'}}}")
+ messages = [ str(n) for n in xrange(10) ]
+ for m in messages: snd.send(m)
+ cluster[1].assert_browse_backup("q", messages)
+ s.sender("q;{delete:always}").close()
+ cluster[1].assert_browse_backup("altq", messages)
+
+ def test_expired(self):
+ """Regression test for QPID-4379: HA does not properly handle expired messages"""
+ # Race between messages expiring and HA replicating consumer.
+ cluster = HaCluster(self, 2)
+ s = cluster[0].connect().session().sender("q;{create:always}", capacity=2)
+ def send_ttl_messages():
+ for i in xrange(100): s.send(Message(str(i), ttl=0.001), timeout=1)
+ send_ttl_messages()
+ cluster.start()
+ send_ttl_messages()
+
+ def test_stale_response(self):
+ """Check for race condition where a stale response is processed after an
+ event for the same queue/exchange """
+ cluster = HaCluster(self, 2)
+ s = cluster[0].connect().session()
+ s.sender("keep;{create:always}") # Leave this queue in place.
+ for i in xrange(1000):
+ s.sender("deleteme%s;{create:always,delete:always}"%(i)).close()
+ # It is possible for the backup to attempt to subscribe after the queue
+ # is deleted. This is not an error, but is logged as an error on the primary.
+ # The backup does not log this as an error so we only check the backup log for errors.
+ self.assert_log_no_errors(cluster[1])
+
+ def test_missed_recreate(self):
+ """If a queue or exchange is destroyed and one with the same name re-created
+ while a backup is disconnected, the backup should also delete/recreate
+ the object when it re-connects"""
+ cluster = HaCluster(self, 3)
+ sn = cluster[0].connect().session()
+ # Create a queue with messages
+ s = sn.sender("qq;{create:always}")
+ msgs = [str(i) for i in xrange(3)]
+ for m in msgs: s.send(m)
+ cluster[1].assert_browse_backup("qq", msgs)
+ cluster[2].assert_browse_backup("qq", msgs)
+ # Set up an exchange with a binding.
+ sn.sender("xx;{create:always,node:{type:topic}}")
+ sn.sender("xxq;{create:always,node:{x-bindings:[{exchange:'xx',queue:'xxq',key:xxq}]}}")
+ cluster[1].wait_address("xx")
+ self.assertEqual(cluster[1].agent().getExchange("xx").values["bindingCount"], 1)
+ cluster[2].wait_address("xx")
+ self.assertEqual(cluster[2].agent().getExchange("xx").values["bindingCount"], 1)
+
+ # Simulate the race by re-creating the objects before promoting the new primary
+ cluster.kill(0, False)
+ xdecl = "x-declare:{arguments:{'qpid.replicate':'all'}}"
+ node = "node:{%s}"%(xdecl)
+ sn = cluster[1].connect_admin().session()
+ sn.sender("qq;{delete:always}").close()
+ s = sn.sender("qq;{create:always, %s}"%(node))
+ s.send("foo")
+ sn.sender("xx;{delete:always}").close()
+ sn.sender("xx;{create:always,node:{type:topic,%s}}"%(xdecl))
+ cluster[1].promote()
+ cluster[1].wait_status("active")
+ # Verify we are not still using the old objects on cluster[2]
+ cluster[2].assert_browse_backup("qq", ["foo"])
+ cluster[2].wait_address("xx")
+ self.assertEqual(cluster[2].agent().getExchange("xx").values["bindingCount"], 0)
+
+ def test_redeclare_exchange(self):
+ """Ensure that re-declaring an exchange is an HA no-op"""
+ cluster = HaCluster(self, 2)
+ ps = cluster[0].connect().session()
+ ps.sender("ex1;{create:always,node:{type:topic,x-declare:{arguments:{'qpid.replicate':all}, type:'fanout'}}}")
+ ps.sender("ex2;{create:always,node:{type:topic,x-declare:{arguments:{'qpid.replicate':all}, type:'fanout', alternate-exchange:'ex1'}}}")
+ cluster[1].wait_backup("ex1")
+ cluster[1].wait_backup("ex2")
+
+ # Use old API to re-declare the exchange
+ old_conn = cluster[0].connect_old()
+ old_sess = old_conn.session(str(qpid.datatypes.uuid4()))
+ old_sess.exchange_declare(exchange='ex1', type='fanout')
+ cluster[1].wait_backup("ex1")
+
def fairshare(msgs, limit, levels):
"""
Generator to return prioritised messages in expected order for a given fairshare limit
@@ -812,7 +912,7 @@ def fairshare(msgs, limit, levels):
msgs = postponed
count = 0
last_priority = None
- postponed = []
+ postponed = [ ]
msg = msgs.pop(0)
if last_priority and priority_level(msg.priority, levels) == last_priority:
count += 1
@@ -834,7 +934,7 @@ def priority_level(value, levels):
offset = 5-math.ceil(levels/2.0)
return min(max(value - offset, 0), levels-1)
-class LongTests(BrokerTest):
+class LongTests(HaBrokerTest):
"""Tests that can run for a long time if -DDURATION=<minutes> is set"""
def duration(self):
@@ -860,7 +960,7 @@ class LongTests(BrokerTest):
"""Wait for receiver r to pass n"""
def check():
r.check() # Verify no exceptions
- return r.received > n
+ return r.received > n + 100
assert retry(check), "Stalled %s at %s"%(r.queue, n)
for r in receivers: wait_passed(r, 0)
@@ -868,87 +968,176 @@ class LongTests(BrokerTest):
# Kill and restart brokers in a cycle:
endtime = time.time() + self.duration()
i = 0
+ primary = 0
try:
while time.time() < endtime or i < 3: # At least 3 iterations
+ # Precondition: All 3 brokers running,
+ # primary = index of promoted primary
+ # one or two backups are running,
for s in senders: s.sender.assert_running()
for r in receivers: r.receiver.assert_running()
- checkpoint = [ r.received for r in receivers ]
- # Don't kill primary till it is active and the next
- # backup is ready, otherwise we can lose messages.
- brokers[i%3].wait_status("active")
- brokers[(i+1)%3].wait_status("ready")
- brokers.bounce(i%3)
+ checkpoint = [ r.received+100 for r in receivers ]
+ dead = None
+ victim = random.randint(0,2)
+ if victim == primary:
+ # Don't kill primary till it is active and the next
+ # backup is ready, otherwise we can lose messages.
+ brokers[victim].wait_status("active")
+ next = (victim+1)%3
+ brokers[next].wait_status("ready")
+ brokers.bounce(victim) # Next one is promoted
+ primary = next
+ else:
+ brokers.kill(victim, False)
+ dead = victim
+
+ # At this point the primary is running with 1 or 2 backups
+ # Make sure we are not stalled
+ map(wait_passed, receivers, checkpoint)
+ # Run another checkpoint to ensure things work in this configuration
+ checkpoint = [ r.received+100 for r in receivers ]
+ map(wait_passed, receivers, checkpoint)
+
+ if dead is not None:
+ brokers.restart(dead) # Restart backup
+ brokers[dead].ready()
+ dead = None
i += 1
- map(wait_passed, receivers, checkpoint) # Wait for all receivers
except:
traceback.print_exc()
raise
finally:
for s in senders: s.stop()
for r in receivers: r.stop()
- dead = []
+ unexpected_dead = []
for i in xrange(3):
- if not brokers[i].is_running(): dead.append(i)
- brokers.kill(i, False)
- if dead: raise Exception("Brokers not running: %s"%dead)
+ if not brokers[i].is_running() and i != dead:
+ unexpected_dead.append(i)
+ if brokers[i].is_running(): brokers.kill(i, False)
+ if unexpected_dead:
+ raise Exception("Brokers not running: %s"%unexpected_dead)
+
+ def test_qmf_order(self):
+ """QPID 4402: HA QMF events can be out of order.
+ This test mimics the test described in the JIRA. Two threads repeatedly
+ declare the same auto-delete queue and close their connection.
+ """
+ broker = Broker(self)
+ class Receiver(Thread):
+ def __init__(self, qname):
+ Thread.__init__(self)
+ self.qname = qname
+ self.stopped = False
+
+ def run(self):
+ while not self.stopped:
+ self.connection = broker.connect()
+ try:
+ self.connection.session().receiver(
+ self.qname+";{create:always,node:{x-declare:{auto-delete:True}}}")
+ except NotFound: pass # Can occur occasionally, not an error.
+ try: self.connection.close()
+ except: pass
+
+ class QmfObject(object):
+ """Track existance of an object and validate QMF events"""
+ def __init__(self, type_name, name_field, name):
+ self.type_name, self.name_field, self.name = type_name, name_field, name
+ self.exists = False
+
+ def qmf_event(self, event):
+ content = event.content[0]
+ event_type = content['_schema_id']['_class_name']
+ values = content['_values']
+ if event_type == self.type_name+"Declare" and values[self.name_field] == self.name:
+ disp = values['disp']
+ log.debug("Event %s: disp=%s exists=%s"%(
+ event_type, values['disp'], self.exists))
+ if self.exists: assert values['disp'] == 'existing'
+ else: assert values['disp'] == 'created'
+ self.exists = True
+ elif event_type == self.type_name+"Delete" and values[self.name_field] == self.name:
+ log.debug("Event %s: exists=%s"%(event_type, self.exists))
+ assert self.exists
+ self.exists = False
+
+ # Verify order of QMF events.
+ helper = EventHelper()
+ r = broker.connect().session().receiver(helper.eventAddress())
+ threads = [Receiver("qq"), Receiver("qq")]
+ for t in threads: t.start()
+ queue = QmfObject("queue", "qName", "qq")
+ finish = time.time() + self.duration()
+ try:
+ while time.time() < finish:
+ queue.qmf_event(r.fetch())
+ finally:
+ for t in threads: t.stopped = True; t.join()
-class RecoveryTests(BrokerTest):
+class RecoveryTests(HaBrokerTest):
"""Tests for recovery after a failure."""
def test_queue_hold(self):
"""Verify that the broker holds queues without sufficient backup,
i.e. does not complete messages sent to those queues."""
- # We don't want backups to time out for this test, set long timeout.
- cluster = HaCluster(self, 4, args=["--ha-backup-timeout=100000"]);
- # Wait for the primary to be ready
- cluster[0].wait_status("active")
- # Create a queue before the failure.
- s1 = cluster.connect(0).session().sender("q1;{create:always}")
- for b in cluster: b.wait_backup("q1")
- for i in xrange(100): s1.send(str(i))
- # Kill primary and 2 backups
- for i in [0,1,2]: cluster.kill(i, False)
- cluster[3].promote() # New primary, backups will be 1 and 2
- cluster[3].wait_status("recovering")
-
- def assertSyncTimeout(s):
- try:
- s.sync(timeout=.01)
- self.fail("Expected Timeout exception")
- except Timeout: pass
-
- # Create a queue after the failure
- s2 = cluster.connect(3).session().sender("q2;{create:always}")
-
- # Verify that messages sent are not completed
- for i in xrange(100,200): s1.send(str(i), sync=False); s2.send(str(i), sync=False)
- assertSyncTimeout(s1)
- self.assertEqual(s1.unsettled(), 100)
- assertSyncTimeout(s2)
- self.assertEqual(s2.unsettled(), 100)
-
- # Verify we can receive even if sending is on hold:
- cluster[3].assert_browse("q1", [str(i) for i in range(100)+range(100,200)])
-
- # Restart backups, verify queues are released only when both backups are up
- cluster.restart(1)
- assertSyncTimeout(s1)
- self.assertEqual(s1.unsettled(), 100)
- assertSyncTimeout(s2)
- self.assertEqual(s2.unsettled(), 100)
- self.assertEqual(cluster[3].ha_status(), "recovering")
- cluster.restart(2)
-
- # Verify everything is up to date and active
- def settled(sender): sender.sync(); return sender.unsettled() == 0;
- assert retry(lambda: settled(s1)), "Unsetttled=%s"%(s1.unsettled())
- assert retry(lambda: settled(s2)), "Unsetttled=%s"%(s2.unsettled())
- cluster[1].assert_browse_backup("q1", [str(i) for i in range(100)+range(100,200)])
- cluster[1].assert_browse_backup("q2", [str(i) for i in range(100,200)])
- cluster[3].wait_status("active"),
- s1.session.connection.close()
- s2.session.connection.close()
+ l = LogLevel(ERROR) # Hide expected WARNING log messages from failover.
+ try:
+ # We don't want backups to time out for this test, set long timeout.
+ cluster = HaCluster(self, 4, args=["--ha-backup-timeout=120"]);
+ # Wait for the primary to be ready
+ cluster[0].wait_status("active")
+ for b in cluster[1:4]: b.wait_status("ready")
+ # Create a queue before the failure.
+ s1 = cluster.connect(0).session().sender("q1;{create:always}")
+ for b in cluster: b.wait_backup("q1")
+ for i in xrange(100): s1.send(str(i))
+
+ # Kill primary and 2 backups
+ cluster[3].wait_status("ready")
+ for i in [0,1,2]: cluster.kill(i, False)
+ cluster[3].promote() # New primary, backups will be 1 and 2
+ cluster[3].wait_status("recovering")
+
+ def assertSyncTimeout(s):
+ try:
+ s.sync(timeout=.01)
+ self.fail("Expected Timeout exception")
+ except Timeout: pass
+
+ # Create a queue after the failure
+ s2 = cluster.connect(3).session().sender("q2;{create:always}")
+
+ # Verify that messages sent are not completed
+ for i in xrange(100,200):
+ s1.send(str(i), sync=False);
+ s2.send(str(i), sync=False)
+ assertSyncTimeout(s1)
+ self.assertEqual(s1.unsettled(), 100)
+ assertSyncTimeout(s2)
+ self.assertEqual(s2.unsettled(), 100)
+
+ # Verify we can receive even if sending is on hold:
+ cluster[3].assert_browse("q1", [str(i) for i in range(200)])
+
+ # Restart backups, verify queues are released only when both backups are up
+ cluster.restart(1)
+ assertSyncTimeout(s1)
+ self.assertEqual(s1.unsettled(), 100)
+ assertSyncTimeout(s2)
+ self.assertEqual(s2.unsettled(), 100)
+ cluster.restart(2)
+
+ # Verify everything is up to date and active
+ def settled(sender): sender.sync(timeout=1); return sender.unsettled() == 0;
+ assert retry(lambda: settled(s1)), "Unsetttled=%s"%(s1.unsettled())
+ assert retry(lambda: settled(s2)), "Unsetttled=%s"%(s2.unsettled())
+ cluster[1].assert_browse_backup("q1", [str(i) for i in range(100)+range(100,200)])
+ cluster[1].assert_browse_backup("q2", [str(i) for i in range(100,200)])
+ cluster[3].wait_status("active"),
+ s1.session.connection.close()
+ s2.session.connection.close()
+ finally: l.restore()
def test_expected_backup_timeout(self):
"""Verify that we time-out expected backups and release held queues
@@ -972,6 +1161,52 @@ class RecoveryTests(BrokerTest):
s.sync(timeout=1) # And released after the timeout.
self.assertEqual(cluster[2].ha_status(), "active")
+ def test_join_ready_cluster(self):
+ """If we join a cluster where the primary is dead, the new primary is
+ not yet promoted and there are ready backups then we should refuse
+ promotion so that one of the ready backups can be chosen."""
+ # FIXME aconway 2012-10-05: smaller timeout
+ cluster = HaCluster(self, 2, args=["--link-heartbeat-interval", 1])
+ cluster[0].wait_status("active")
+ cluster[1].wait_status("ready")
+ cluster.bounce(0, promote_next=False)
+ self.assertRaises(Exception, cluster[0].promote)
+ os.kill(cluster[1].pid, signal.SIGSTOP) # Test for timeout if unresponsive.
+ cluster.bounce(0, promote_next=False)
+ cluster[0].promote()
+
+
+class ConfigurationTests(HaBrokerTest):
+ """Tests for configuration settings."""
+
+ def test_client_broker_url(self):
+ """Check that setting of broker and public URLs obeys correct defaulting
+ and precedence"""
+
+ def check(broker, brokers, public):
+ qmf = broker.qmf()
+ self.assertEqual(brokers, qmf.brokersUrl)
+ self.assertEqual(public, qmf.publicUrl)
+
+ def start(brokers, public, known=None):
+ args=[]
+ if brokers: args.append("--ha-brokers-url="+brokers)
+ if public: args.append("--ha-public-url="+public)
+ if known: args.append("--known-hosts-url="+known)
+ return HaBroker(self, args=args)
+
+ # Both set explictily, no defaulting
+ b = start("foo:123", "bar:456")
+ check(b, "amqp:tcp:foo:123", "amqp:tcp:bar:456")
+ b.set_brokers_url("foo:999")
+ check(b, "amqp:tcp:foo:999", "amqp:tcp:bar:456")
+ b.set_public_url("bar:999")
+ check(b, "amqp:tcp:foo:999", "amqp:tcp:bar:999")
+
+ # Allow "none" to mean "not set"
+ b = start("none", "none")
+ check(b, "", "")
+
if __name__ == "__main__":
shutil.rmtree("brokertest.tmp", True)
qpid_ha = os.getenv("QPID_HA_EXEC")
@@ -979,5 +1214,5 @@ if __name__ == "__main__":
os.execvp("qpid-python-test",
["qpid-python-test", "-m", "ha_tests"] + sys.argv[1:])
else:
- print "Skipping ha_tests, qpid_ha not available"
+ print "Skipping ha_tests, %s not available"%(qpid_ha)
diff --git a/cpp/src/tests/ipv6_test b/cpp/src/tests/ipv6_test
index 9d1cb2acdd..f47e721513 100755
--- a/cpp/src/tests/ipv6_test
+++ b/cpp/src/tests/ipv6_test
@@ -122,43 +122,3 @@ else
rm rdata-in rdata-out
fi
-# Cluster smoke test follows
-test -z $CLUSTER_LIB && exit 0 # Exit if cluster not supported.
-
-## Test failover in a cluster using IPv6 only
-. cpg_check.sh
-cpg_enabled || exit 0
-
-pick_port() {
- # We need a fixed port to set --cluster-url. Use qpidd to pick a free port.
- # Note this method is racy
- PICK=$($QPIDD_EXEC -dp0)
- $QPIDD_EXEC -qp $PICK
- echo $PICK
-}
-
-ssl_cluster_broker() { # $1 = port
- $QPIDD_EXEC $COMMON_OPTS --load-module $CLUSTER_LIB --cluster-name ipv6_test.$HOSTNAME.$$ --cluster-url amqp:[$TEST_HOSTNAME]:$1 --port $1
- # Wait for broker to be ready
- ./qpid-ping -b $TEST_HOSTNAME -qp $1 || { echo "Cannot connect to broker on $1"; exit 1; }
- echo "Running IPv6 cluster broker on port $1"
-}
-
-PORT1=`pick_port`; ssl_cluster_broker $PORT1
-PORT2=`pick_port`; ssl_cluster_broker $PORT2
-
-# Pipe receive output to uniq to remove duplicates
-./qpid-receive --connection-options "{reconnect:true, reconnect-timeout:5}" --failover-updates -b amqp:[$TEST_HOSTNAME]:$PORT1 -a "foo;{create:always}" -f | uniq > ssl_test_receive.tmp &
-
-./qpid-send -b amqp:[$TEST_HOSTNAME]:$PORT2 --content-string=one -a "foo;{create:always}"
-
-$QPIDD_EXEC -qp $PORT1 # Kill broker 1 receiver should fail-over.
-./qpid-send -b amqp:[$TEST_HOSTNAME]:$PORT2 --content-string=two -a "foo;{create:always}" --send-eos 1
-wait # Wait for qpid-receive
-{ echo one; echo two; } > ssl_test_receive.cmp
-diff ssl_test_receive.tmp ssl_test_receive.cmp || { echo "Failover failed"; exit 1; }
-
-$QPIDD_EXEC -qp $PORT2
-
-rm -f ssl_test_receive.*
-
diff --git a/cpp/src/tests/legacystore/.valgrind.supp b/cpp/src/tests/legacystore/.valgrind.supp
new file mode 100644
index 0000000000..5c1c5377bf
--- /dev/null
+++ b/cpp/src/tests/legacystore/.valgrind.supp
@@ -0,0 +1,35 @@
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:_Znwm
+ fun:_ZNSs4_Rep9_S_createEmmRKSaIcE
+ fun:_ZNSs12_S_constructIPKcEEPcT_S3_RKSaIcESt20forward_iterator_tag
+ fun:_ZNSsC1EPKcRKSaIcE
+}
+
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:_Znwm
+ fun:_ZNSs4_Rep9_S_createEmmRKSaIcE
+ fun:_ZNSs4_Rep8_M_cloneERKSaIcEm
+ fun:_ZNSs7reserveEm
+}
+
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:_Znwm
+ fun:_ZNSs4_Rep9_S_createEmmRKSaIcE
+ fun:_ZNSs9_M_mutateEmmm
+ fun:_ZNSs15_M_replace_safeEmmPKcm
+}
+
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:_Znwm
+ fun:_ZNSs4_Rep9_S_createEmmRKSaIcE
+ fun:_ZNSsC1IPcEET_S1_RKSaIcE
+}
+
diff --git a/cpp/src/tests/legacystore/.valgrindrc b/cpp/src/tests/legacystore/.valgrindrc
new file mode 100644
index 0000000000..4aba7661de
--- /dev/null
+++ b/cpp/src/tests/legacystore/.valgrindrc
@@ -0,0 +1,7 @@
+--gen-suppressions=all
+--leak-check=full
+--demangle=yes
+--suppressions=.valgrind.supp
+--num-callers=25
+--trace-children=yes
+
diff --git a/cpp/src/tests/legacystore/CMakeLists.txt b/cpp/src/tests/legacystore/CMakeLists.txt
new file mode 100644
index 0000000000..6cfaa7ec17
--- /dev/null
+++ b/cpp/src/tests/legacystore/CMakeLists.txt
@@ -0,0 +1,117 @@
+#
+# 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.
+#
+
+if(BUILD_LEGACYSTORE)
+
+message(STATUS "Building legacystore tests")
+
+# Enable dashboard reporting.
+include (CTest)
+
+# Make sure that everything get built before the tests
+# Need to create a var with all the necessary top level targets
+
+# If we're linking Boost for DLLs, turn that on for the unit test too.
+if (QPID_LINK_BOOST_DYNAMIC)
+ add_definitions(-DBOOST_TEST_DYN_LINK)
+endif (QPID_LINK_BOOST_DYNAMIC)
+
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
+
+include (FindPythonInterp)
+
+# # Inherit environment from parent script
+# set (abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR})
+# set (abs_builddir ${CMAKE_CURRENT_BINARY_DIR})
+# set (abs_top_srcdir ${CMAKE_SOURCE_DIR})
+# set (abs_top_builddir ${CMAKE_BINARY_DIR})
+# set (builddir_lib_suffix "")
+
+# If valgrind is selected in the configuration step, set up the path to it
+# for CTest.
+if (ENABLE_VALGRIND)
+ set (MEMORYCHECK_COMMAND ${VALGRIND})
+ set (MEMORYCHECK_COMMAND_OPTIONS "--gen-suppressions=all
+--leak-check=full
+--demangle=yes
+--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/.valgrind.supp
+--num-callers=25
+--log-file=ctest_valgrind.vglog")
+endif (ENABLE_VALGRIND)
+
+# Like this to work with cmake 2.4 on Unix
+set (qpid_test_boost_libs
+ ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${Boost_SYSTEM_LIBRARY})
+
+#
+# Unit test program
+#
+# Unit tests are built as a single program to reduce valgrind overhead
+# when running the tests. If you want to build a subset of the tests run
+# ccmake and set unit_tests_to_build to the set you want to build.
+# HACK ALERT - Unit tests are built individually to resolve a conflict
+# with running multiple brokers that connect to 0.0.0.0:5672 and that
+# womp on each other's store directory.
+
+#
+# define_selftest
+# macro to accept the name of a single source file and to create a
+# unit test executable that runs the source.
+#
+MACRO (define_selftest theSourceFile)
+add_executable (legacystore_${theSourceFile}
+ unit_test
+ ${theSourceFile}
+ ${platform_test_additions})
+target_link_libraries (legacystore_${theSourceFile}
+ ${qpid_test_boost_libs}
+ qpidmessaging qpidbroker qmfconsole legacystore)
+get_property(ls_include TARGET legacystore_${theSourceFile} PROPERTY INCLUDE_DIRECTORIES)
+list(APPEND ls_include ${abs_top_srcdir}/src/qpid/legacystore)
+list(APPEND ls_include ${abs_top_srcdir}/src/tests)
+set_target_properties (legacystore_${theSourceFile} PROPERTIES
+ INCLUDE_DIRECTORIES "${ls_include}"
+ COMPILE_DEFINITIONS _IN_QPID_BROKER)
+remember_location(legacystore_${theSourceFile})
+set(test_wrap ${shell} ${CMAKE_CURRENT_SOURCE_DIR}/run_test${test_script_suffix})
+
+add_test (legacystore_${theSourceFile} ${test_wrap} ${legacystore_${theSourceFile}_LOCATION})
+ENDMACRO (define_selftest)
+
+# add_definitions(-H)
+
+define_selftest (SimpleTest)
+define_selftest (OrderingTest)
+define_selftest (TransactionalTest)
+define_selftest (TwoPhaseCommitTest)
+
+#
+# Other test programs
+#
+
+# This should ideally be done as part of the test run, but I don't know a way
+# to get these arguments and the working directory set like Makefile.am does,
+# and have that run during the test pass.
+if (PYTHON_EXECUTABLE)
+ set (python_bld ${CMAKE_CURRENT_BINARY_DIR}/python)
+ execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py install --prefix=${pythoon_bld} --install-lib=${python_bld} --install-scripts=${python_bld}/commands
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/../python)
+endif (PYTHON_EXECUTABLE)
+
+endif (BUILD_LEGACYSTORE)
diff --git a/cpp/src/tests/legacystore/MessageUtils.h b/cpp/src/tests/legacystore/MessageUtils.h
new file mode 100644
index 0000000000..6552357c72
--- /dev/null
+++ b/cpp/src/tests/legacystore/MessageUtils.h
@@ -0,0 +1,105 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include <qpid/broker/Message.h>
+#include <qpid/broker/Queue.h>
+#include <qpid/broker/amqp_0_10/MessageTransfer.h>
+#include <qpid/framing/AMQFrame.h>
+#include <qpid/framing/all_method_bodies.h>
+#include <qpid/framing/Uuid.h>
+
+using namespace qpid::broker;
+using namespace qpid::framing;
+
+struct MessageUtils
+{
+ static Message createMessage(const std::string& exchange, const std::string& routingKey,
+ const Uuid& messageId=Uuid(), const bool durable = false,
+ const uint64_t contentSize = 0, const std::string& correlationId = std::string())
+ {
+ boost::intrusive_ptr<qpid::broker::amqp_0_10::MessageTransfer> msg(new qpid::broker::amqp_0_10::MessageTransfer());
+
+ AMQFrame method(( MessageTransferBody(ProtocolVersion(), exchange, 0, 0)));
+ AMQFrame header((AMQHeaderBody()));
+
+ msg->getFrames().append(method);
+ msg->getFrames().append(header);
+ MessageProperties* props = msg->getFrames().getHeaders()->get<MessageProperties>(true);
+ props->setContentLength(contentSize);
+ props->setMessageId(messageId);
+ props->setCorrelationId(correlationId);
+ msg->getFrames().getHeaders()->get<DeliveryProperties>(true)->setRoutingKey(routingKey);
+ if (durable)
+ msg->getFrames().getHeaders()->get<DeliveryProperties>(true)->setDeliveryMode(PERSISTENT);
+ return Message(msg, msg);
+ }
+
+ static void addContent(Message msg, const std::string& data)
+ {
+ AMQFrame content((AMQContentBody(data)));
+ qpid::broker::amqp_0_10::MessageTransfer::get(msg).getFrames().append(content);
+ }
+
+ struct MessageRetriever : public Consumer
+ {
+ MessageRetriever(Queue& q) : Consumer("test", CONSUMER), queue(q) {};
+
+ bool deliver(const QueueCursor& c, const Message& m)
+ {
+ message = m;
+ cursor = c;
+ return true;
+ };
+ void notify() {}
+ void cancel() {}
+ void acknowledged(const DeliveryRecord&) {}
+ OwnershipToken* getSession() { return 0; }
+
+ const Queue& queue;
+ Message message;
+ QueueCursor cursor;
+ };
+
+ static Message get(Queue& queue, QueueCursor* cursor = 0)
+ {
+ boost::shared_ptr<MessageRetriever> consumer(new MessageRetriever(queue));
+ if (!queue.dispatch(consumer))throw qpid::Exception("No message found!");
+ if (cursor) *cursor = consumer->cursor;
+ return consumer->message;
+ }
+
+ static Uuid getMessageId(const Message& message)
+ {
+ return qpid::broker::amqp_0_10::MessageTransfer::get(message).getProperties<MessageProperties>()->getMessageId();
+ }
+
+ static std::string getCorrelationId(const Message& message)
+ {
+ return qpid::broker::amqp_0_10::MessageTransfer::get(message).getProperties<MessageProperties>()->getCorrelationId();
+ }
+
+ static void deliver(Message& msg, FrameHandler& h, uint16_t framesize)
+ {
+ qpid::broker::amqp_0_10::MessageTransfer::get(msg).sendHeader(h, framesize, false, 0, 0, qpid::types::Variant::Map());
+ qpid::broker::amqp_0_10::MessageTransfer::get(msg).sendContent(h, framesize);
+ }
+
+};
diff --git a/cpp/src/tests/legacystore/OrderingTest.cpp b/cpp/src/tests/legacystore/OrderingTest.cpp
new file mode 100644
index 0000000000..92a09f0c60
--- /dev/null
+++ b/cpp/src/tests/legacystore/OrderingTest.cpp
@@ -0,0 +1,168 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "unit_test.h"
+
+#include "qpid/legacystore/MessageStoreImpl.h"
+#include <iostream>
+#include "MessageUtils.h"
+#include <qpid/broker/Queue.h>
+#include <qpid/broker/RecoveryManagerImpl.h>
+#include <qpid/framing/AMQHeaderBody.h>
+#include "qpid/log/Logger.h"
+#include "qpid/sys/Timer.h"
+
+using namespace qpid;
+using namespace qpid::broker;
+using namespace qpid::framing;
+using namespace mrg::msgstore;
+
+qpid::broker::Broker::Options opts;
+qpid::broker::Broker br(opts);
+
+QPID_AUTO_TEST_SUITE(OrderingTest)
+
+#define SET_LOG_LEVEL(level) \
+ qpid::log::Options opts(""); \
+ opts.selectors.clear(); \
+ opts.selectors.push_back(level); \
+ qpid::log::Logger::instance().configure(opts);
+
+const std::string test_filename("OrderingTest");
+const char* tdp = getenv("TMP_DATA_DIR");
+const std::string test_dir(tdp && strlen(tdp) > 0 ? tdp : "/tmp/OrderingTest");
+
+// === Helper fns ===
+
+const std::string name("OrderingQueue");
+std::auto_ptr<MessageStoreImpl> store;
+QueueRegistry queues;
+Queue::shared_ptr queue;
+std::queue<Uuid> ids;
+
+class TestConsumer : public Consumer
+{
+ public:
+
+ TestConsumer(Queue::shared_ptr q, std::queue<Uuid>& i) : Consumer("test", CONSUMER), queue(q), ids(i) {};
+
+ bool deliver(const QueueCursor& cursor, const Message& message)
+ {
+ queue->dequeue(0, cursor);
+ BOOST_CHECK_EQUAL(ids.front(), MessageUtils::getMessageId(message));
+ ids.pop();
+ return true;
+ };
+ void notify() {}
+ void cancel() {}
+ void acknowledged(const DeliveryRecord&) {}
+ OwnershipToken* getSession() { return 0; }
+ private:
+ Queue::shared_ptr queue;
+ std::queue<Uuid>& ids;
+};
+boost::shared_ptr<TestConsumer> consumer;
+
+void setup()
+{
+ store = std::auto_ptr<MessageStoreImpl>(new MessageStoreImpl(&br));
+ store->init(test_dir, 4, 1, true); // truncate store
+
+ queue = Queue::shared_ptr(new Queue(name, 0, store.get(), 0));
+ queue->create();
+ consumer = boost::shared_ptr<TestConsumer>(new TestConsumer(queue, ids));
+}
+
+void push()
+{
+ Uuid messageId(true);
+ ids.push(messageId);
+
+ Message msg = MessageUtils::createMessage("exchange", "routing_key", messageId, true, 0);
+
+ queue->deliver(msg);
+}
+
+bool pop()
+{
+ return queue->dispatch(consumer);
+}
+
+void restart()
+{
+ queue.reset();
+ store.reset();
+
+ store = std::auto_ptr<MessageStoreImpl>(new MessageStoreImpl(&br));
+ store->init(test_dir, 4, 1);
+ ExchangeRegistry exchanges;
+ LinkRegistry links;
+ sys::Timer t;
+ DtxManager mgr(t);
+ mgr.setStore (store.get());
+ RecoveryManagerImpl recoveryMgr(queues, exchanges, links, mgr, br.getProtocolRegistry());
+ store->recover(recoveryMgr);
+
+ queue = queues.find(name);
+ consumer = boost::shared_ptr<TestConsumer>(new TestConsumer(queue, ids));
+}
+
+void check()
+{
+ BOOST_REQUIRE(queue);
+ BOOST_CHECK_EQUAL((u_int32_t) ids.size(), queue->getMessageCount());
+ while (pop()) ;//keeping popping 'till all messages are dequeued
+ BOOST_CHECK_EQUAL((u_int32_t) 0, queue->getMessageCount());
+ BOOST_CHECK_EQUAL((size_t) 0, ids.size());
+}
+
+
+// === Test suite ===
+
+QPID_AUTO_TEST_CASE(Basic)
+{
+ SET_LOG_LEVEL("error+"); // This only needs to be set once.
+
+ std::cout << test_filename << ".Basic: " << std::flush;
+ setup();
+ //push on 10 messages
+ for (int i = 0; i < 10; i++) push();
+ restart();
+ check();
+ std::cout << "ok" << std::endl;
+}
+
+QPID_AUTO_TEST_CASE(Cycle)
+{
+ std::cout << test_filename << ".Cycle: " << std::flush;
+ setup();
+ //push on 10 messages:
+ for (int i = 0; i < 10; i++) push();
+ //pop 5:
+ for (int i = 0; i < 5; i++) pop();
+ //push on another 5:
+ for (int i = 0; i < 5; i++) push();
+ restart();
+ check();
+ std::cout << "ok" << std::endl;
+}
+
+QPID_AUTO_TEST_SUITE_END()
diff --git a/cpp/src/tests/legacystore/SimpleTest.cpp b/cpp/src/tests/legacystore/SimpleTest.cpp
new file mode 100644
index 0000000000..a49333d876
--- /dev/null
+++ b/cpp/src/tests/legacystore/SimpleTest.cpp
@@ -0,0 +1,497 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "unit_test.h"
+
+#include "qpid/legacystore/MessageStoreImpl.h"
+#include <iostream>
+#include "tests/legacystore/MessageUtils.h"
+#include "qpid/legacystore/StoreException.h"
+#include "qpid/broker/DirectExchange.h"
+#include <qpid/broker/Queue.h>
+#include <qpid/broker/QueueSettings.h>
+#include <qpid/broker/RecoveryManagerImpl.h>
+#include <qpid/framing/AMQHeaderBody.h>
+#include <qpid/framing/FieldTable.h>
+#include <qpid/framing/FieldValue.h>
+#include "qpid/log/Logger.h"
+#include "qpid/sys/Timer.h"
+
+qpid::broker::Broker::Options opts;
+qpid::broker::Broker br(opts);
+
+#define SET_LOG_LEVEL(level) \
+ qpid::log::Options opts(""); \
+ opts.selectors.clear(); \
+ opts.selectors.push_back(level); \
+ qpid::log::Logger::instance().configure(opts);
+
+
+using boost::intrusive_ptr;
+using boost::static_pointer_cast;
+using namespace qpid;
+using namespace qpid::broker;
+using namespace qpid::framing;
+using namespace mrg::msgstore;
+using namespace std;
+
+QPID_AUTO_TEST_SUITE(SimpleTest)
+
+const string test_filename("SimpleTest");
+const char* tdp = getenv("TMP_DATA_DIR");
+const string test_dir(tdp && strlen(tdp) > 0 ? tdp : "/tmp/SimpleTest");
+
+// === Helper fns ===
+
+struct DummyHandler : OutputHandler
+{
+ std::vector<AMQFrame> frames;
+
+ virtual void send(AMQFrame& frame){
+ frames.push_back(frame);
+ }
+};
+
+void recover(MessageStoreImpl& store, QueueRegistry& queues, ExchangeRegistry& exchanges, LinkRegistry& links)
+{
+ sys::Timer t;
+ DtxManager mgr(t);
+ mgr.setStore (&store);
+ RecoveryManagerImpl recovery(queues, exchanges, links, mgr, br.getProtocolRegistry());
+ store.recover(recovery);
+}
+
+void recover(MessageStoreImpl& store, ExchangeRegistry& exchanges)
+{
+ QueueRegistry queues;
+ LinkRegistry links;
+ recover(store, queues, exchanges, links);
+}
+
+void recover(MessageStoreImpl& store, QueueRegistry& queues)
+{
+ ExchangeRegistry exchanges;
+ LinkRegistry links;
+ recover(store, queues, exchanges, links);
+}
+
+void bindAndUnbind(const string& exchangeName, const string& queueName,
+ const string& key, const FieldTable& args)
+{
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ Exchange::shared_ptr exchange(new DirectExchange(exchangeName, true, args));
+ Queue::shared_ptr queue(new Queue(queueName, 0, &store, 0));
+ store.create(*exchange, qpid::framing::FieldTable());
+ store.create(*queue, qpid::framing::FieldTable());
+ BOOST_REQUIRE(exchange->bind(queue, key, &args));
+ store.bind(*exchange, *queue, key, args);
+ }//db will be closed
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ ExchangeRegistry exchanges;
+ QueueRegistry queues;
+ LinkRegistry links;
+
+ recover(store, queues, exchanges, links);
+
+ Exchange::shared_ptr exchange = exchanges.get(exchangeName);
+ Queue::shared_ptr queue = queues.find(queueName);
+ // check exchange args are still set
+ for (FieldTable::ValueMap::const_iterator i = args.begin(); i!=args.end(); i++) {
+ BOOST_CHECK(exchange->getArgs().get((*i).first)->getData() == (*i).second->getData());
+ }
+ //check it is bound by unbinding
+ BOOST_REQUIRE(exchange->unbind(queue, key, &args));
+ store.unbind(*exchange, *queue, key, args);
+ }
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ ExchangeRegistry exchanges;
+ QueueRegistry queues;
+ LinkRegistry links;
+
+ recover(store, queues, exchanges, links);
+
+ Exchange::shared_ptr exchange = exchanges.get(exchangeName);
+ Queue::shared_ptr queue = queues.find(queueName);
+ // check exchange args are still set
+ for (FieldTable::ValueMap::const_iterator i = args.begin(); i!=args.end(); i++) {
+ BOOST_CHECK(exchange->getArgs().get((*i).first)->getData() == (*i).second->getData());
+ }
+ //make sure it is no longer bound
+ BOOST_REQUIRE(!exchange->unbind(queue, key, &args));
+ }
+}
+
+
+// === Test suite ===
+
+QPID_AUTO_TEST_CASE(CreateDelete)
+{
+ SET_LOG_LEVEL("error+"); // This only needs to be set once.
+
+ cout << test_filename << ".CreateDelete: " << flush;
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ string name("CreateDeleteQueue");
+ Queue queue(name, 0, &store, 0);
+ store.create(queue, qpid::framing::FieldTable());
+// TODO - check dir exists
+ BOOST_REQUIRE(queue.getPersistenceId());
+ store.destroy(queue);
+// TODO - check dir is deleted
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(EmptyRecover)
+{
+ cout << test_filename << ".EmptyRecover: " << flush;
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ QueueRegistry registry;
+ registry.setStore (&store);
+ recover(store, registry);
+ //nothing to assert, just testing it doesn't blow up
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(QueueCreate)
+{
+ cout << test_filename << ".QueueCreate: " << flush;
+
+ uint64_t id(0);
+ string name("MyDurableQueue");
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ Queue queue(name, 0, &store, 0);
+ store.create(queue, qpid::framing::FieldTable());
+ BOOST_REQUIRE(queue.getPersistenceId());
+ id = queue.getPersistenceId();
+ }//db will be closed
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ QueueRegistry registry;
+ registry.setStore (&store);
+ recover(store, registry);
+ Queue::shared_ptr queue = registry.find(name);
+ BOOST_REQUIRE(queue.get());
+ BOOST_CHECK_EQUAL(id, queue->getPersistenceId());
+ }
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(QueueCreateWithSettings)
+{
+ cout << test_filename << ".QueueCreateWithSettings: " << flush;
+
+ FieldTable arguments;
+ arguments.setInt("qpid.max_count", 202);
+ arguments.setInt("qpid.max_size", 1003);
+ QueueSettings settings;
+ settings.populate(arguments, settings.storeSettings);
+ string name("MyDurableQueue");
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ Queue queue(name, settings, &store, 0);
+ queue.create();
+ BOOST_REQUIRE(queue.getPersistenceId());
+ }//db will be closed
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ QueueRegistry registry;
+ registry.setStore (&store);
+ recover(store, registry);
+ Queue::shared_ptr queue = registry.find(name);
+ BOOST_REQUIRE(queue);
+ BOOST_CHECK_EQUAL(settings.maxDepth.getCount(), 202);
+ BOOST_CHECK_EQUAL(settings.maxDepth.getSize(), 1003);
+ BOOST_CHECK_EQUAL(settings.maxDepth.getCount(), queue->getSettings().maxDepth.getCount());
+ BOOST_CHECK_EQUAL(settings.maxDepth.getSize(), queue->getSettings().maxDepth.getSize());
+ }
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(QueueDestroy)
+{
+ cout << test_filename << ".QueueDestroy: " << flush;
+
+ string name("MyDurableQueue");
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ Queue queue(name, 0, &store, 0);
+ store.create(queue, qpid::framing::FieldTable());
+ store.destroy(queue);
+ }//db will be closed
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ QueueRegistry registry;
+ registry.setStore (&store);
+ recover(store, registry);
+ BOOST_REQUIRE(!registry.find(name));
+ }
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(Enqueue)
+{
+ cout << test_filename << ".Enqueue: " << flush;
+
+ //TODO: this is largely copy & paste'd from MessageTest in
+ //qpid tree. ideally need some helper routines for reducing
+ //this to a simpler less duplicated form
+
+ string name("MyDurableQueue");
+ string exchange("MyExchange");
+ string routingKey("MyRoutingKey");
+ Uuid messageId(true);
+ string data1("abcdefg");
+ string data2("hijklmn");
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ Queue::shared_ptr queue(new Queue(name, 0, &store, 0));
+ queue->create();
+
+ Message msg = MessageUtils::createMessage(exchange, routingKey, messageId, true, 14);
+ MessageUtils::addContent(msg, data1);
+ MessageUtils::addContent(msg, data2);
+
+ msg.addAnnotation("abc", "xyz");
+
+ queue->deliver(msg);
+ }//db will be closed
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ QueueRegistry registry;
+ registry.setStore (&store);
+ recover(store, registry);
+ Queue::shared_ptr queue = registry.find(name);
+ BOOST_REQUIRE(queue);
+ BOOST_CHECK_EQUAL((u_int32_t) 1, queue->getMessageCount());
+ Message msg = MessageUtils::get(*queue);
+
+ BOOST_CHECK_EQUAL(routingKey, msg.getRoutingKey());
+ BOOST_CHECK_EQUAL(messageId, MessageUtils::getMessageId(msg));
+ BOOST_CHECK_EQUAL(std::string("xyz"), msg.getAnnotation("abc"));
+ BOOST_CHECK_EQUAL((u_int64_t) 14, msg.getContentSize());
+
+ DummyHandler handler;
+ MessageUtils::deliver(msg, handler, 100);
+ BOOST_CHECK_EQUAL((size_t) 2, handler.frames.size());
+ AMQContentBody* contentBody(dynamic_cast<AMQContentBody*>(handler.frames[1].getBody()));
+ BOOST_REQUIRE(contentBody);
+ BOOST_CHECK_EQUAL(data1.size() + data2.size(), contentBody->getData().size());
+ BOOST_CHECK_EQUAL(data1 + data2, contentBody->getData());
+ }
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(Dequeue)
+{
+ cout << test_filename << ".Dequeue: " << flush;
+
+ //TODO: reduce the duplication in these tests
+ string name("MyDurableQueue");
+ {
+ string exchange("MyExchange");
+ string routingKey("MyRoutingKey");
+ Uuid messageId(true);
+ string data("abcdefg");
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ Queue::shared_ptr queue(new Queue(name, 0, &store, 0));
+ queue->create();
+
+ Message msg = MessageUtils::createMessage(exchange, routingKey, messageId, true, 7);
+ MessageUtils::addContent(msg, data);
+
+ queue->deliver(msg);
+
+ QueueCursor cursor;
+ MessageUtils::get(*queue, &cursor);
+ queue->dequeue(0, cursor);
+ }//db will be closed
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ QueueRegistry registry;
+ registry.setStore (&store);
+ recover(store, registry);
+ Queue::shared_ptr queue = registry.find(name);
+ BOOST_REQUIRE(queue);
+ BOOST_CHECK_EQUAL((u_int32_t) 0, queue->getMessageCount());
+ }
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(ExchangeCreateAndDestroy)
+{
+ cout << test_filename << ".ExchangeCreateAndDestroy: " << flush;
+
+ uint64_t id(0);
+ string name("MyDurableExchange");
+ string type("direct");
+ FieldTable args;
+ args.setString("a", "A");
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ ExchangeRegistry registry;
+ Exchange::shared_ptr exchange = registry.declare(name, type, true, args).first;
+ store.create(*exchange, qpid::framing::FieldTable());
+ id = exchange->getPersistenceId();
+ BOOST_REQUIRE(id);
+ }//db will be closed
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ ExchangeRegistry registry;
+
+ recover(store, registry);
+
+ Exchange::shared_ptr exchange = registry.get(name);
+ BOOST_CHECK_EQUAL(id, exchange->getPersistenceId());
+ BOOST_CHECK_EQUAL(type, exchange->getType());
+ BOOST_REQUIRE(exchange->isDurable());
+ BOOST_CHECK_EQUAL(*args.get("a"), *exchange->getArgs().get("a"));
+ store.destroy(*exchange);
+ }
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ ExchangeRegistry registry;
+
+ recover(store, registry);
+
+ try {
+ Exchange::shared_ptr exchange = registry.get(name);
+ BOOST_FAIL("Expected exchange not to be found");
+ } catch (const SessionException& e) {
+ BOOST_CHECK_EQUAL((framing::ReplyCode) 404, e.code);
+ }
+ }
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(ExchangeBindAndUnbind)
+{
+ cout << test_filename << ".ExchangeBindAndUnbind: " << flush;
+
+ bindAndUnbind("MyDurableExchange", "MyDurableQueue", "my-routing-key", FieldTable());
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(ExchangeBindAndUnbindWithArgs)
+{
+ cout << test_filename << ".ExchangeBindAndUnbindWithArgs: " << flush;
+
+ FieldTable args;
+ args.setString("a", "A");
+ args.setString("b", "B");
+ bindAndUnbind("MyDurableExchange", "MyDurableQueue", "my-routing-key", args);
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(ExchangeImplicitUnbind)
+{
+ cout << test_filename << ".ExchangeImplicitUnbind: " << flush;
+
+ string exchangeName("MyDurableExchange");
+ string queueName1("MyDurableQueue1");
+ string queueName2("MyDurableQueue2");
+ string key("my-routing-key");
+ FieldTable args;
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1, true); // truncate store
+ Exchange::shared_ptr exchange(new DirectExchange(exchangeName, true, args));
+ Queue::shared_ptr queue1(new Queue(queueName1, 0, &store, 0));
+ Queue::shared_ptr queue2(new Queue(queueName2, 0, &store, 0));
+ store.create(*exchange, qpid::framing::FieldTable());
+ store.create(*queue1, qpid::framing::FieldTable());
+ store.create(*queue2, qpid::framing::FieldTable());
+ store.bind(*exchange, *queue1, key, args);
+ store.bind(*exchange, *queue2, key, args);
+ //delete queue1:
+ store.destroy(*queue1);
+ }//db will be closed
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ ExchangeRegistry exchanges;
+ QueueRegistry queues;
+ LinkRegistry links;
+
+ //ensure recovery works ok:
+ recover(store, queues, exchanges, links);
+
+ Exchange::shared_ptr exchange = exchanges.get(exchangeName);
+ BOOST_REQUIRE(!queues.find(queueName1).get());
+ BOOST_REQUIRE(queues.find(queueName2).get());
+
+ //delete exchange:
+ store.destroy(*exchange);
+ }
+ {
+ MessageStoreImpl store(&br);
+ store.init(test_dir, 4, 1);
+ ExchangeRegistry exchanges;
+ QueueRegistry queues;
+ LinkRegistry links;
+
+ //ensure recovery works ok:
+ recover(store, queues, exchanges, links);
+
+ try {
+ Exchange::shared_ptr exchange = exchanges.get(exchangeName);
+ BOOST_FAIL("Expected exchange not to be found");
+ } catch (const SessionException& e) {
+ BOOST_CHECK_EQUAL((framing::ReplyCode) 404, e.code);
+ }
+ Queue::shared_ptr queue = queues.find(queueName2);
+ store.destroy(*queue);
+ }
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_SUITE_END()
diff --git a/cpp/src/tests/legacystore/TestFramework.cpp b/cpp/src/tests/legacystore/TestFramework.cpp
new file mode 100644
index 0000000000..2f7faf7682
--- /dev/null
+++ b/cpp/src/tests/legacystore/TestFramework.cpp
@@ -0,0 +1,30 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+// Defines broker to be used by tests
+
+#include "unit_test.h"
+#include "TestFramework.h"
+#include "qpid/broker/Broker.h"
+
+#include <iostream>
+
+//BOOST_GLOBAL_FIXTURE( testBroker )
diff --git a/cpp/src/tests/legacystore/TestFramework.h b/cpp/src/tests/legacystore/TestFramework.h
new file mode 100644
index 0000000000..f3066db602
--- /dev/null
+++ b/cpp/src/tests/legacystore/TestFramework.h
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+// Defines broker to be used by tests
+
+#include "unit_test.h"
+
+#include <qpid/broker/Broker.h>
+
+namespace {
+ // test broker
+ qpid::broker::Broker::Options opts;
+ qpid::broker::Broker br(opts);
+/*
+ struct testBroker {
+ testBroker() {}
+ ~testBroker() {}
+ };*/
+}
diff --git a/cpp/src/tests/legacystore/TransactionalTest.cpp b/cpp/src/tests/legacystore/TransactionalTest.cpp
new file mode 100644
index 0000000000..2d3f6f922c
--- /dev/null
+++ b/cpp/src/tests/legacystore/TransactionalTest.cpp
@@ -0,0 +1,351 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "unit_test.h"
+
+#include "qpid/legacystore/MessageStoreImpl.h"
+#include <iostream>
+#include "MessageUtils.h"
+#include "qpid/legacystore/StoreException.h"
+#include "qpid/broker/Queue.h"
+#include "qpid/broker/RecoveryManagerImpl.h"
+#include "qpid/framing/AMQHeaderBody.h"
+#include "qpid/log/Statement.h"
+#include "qpid/log/Logger.h"
+#include "qpid/sys/Timer.h"
+
+using namespace mrg::msgstore;
+using namespace qpid;
+using namespace qpid::broker;
+using namespace qpid::framing;
+using namespace std;
+
+namespace {
+qpid::broker::Broker::Options opts;
+qpid::broker::Broker br(opts);
+}
+
+QPID_AUTO_TEST_SUITE(TransactionalTest)
+
+#define SET_LOG_LEVEL(level) \
+ qpid::log::Options opts(""); \
+ opts.selectors.clear(); \
+ opts.selectors.push_back(level); \
+ qpid::log::Logger::instance().configure(opts);
+
+const string test_filename("TransactionalTest");
+const char* tdp = getenv("TMP_DATA_DIR");
+const string test_dir(tdp && strlen(tdp) > 0 ? tdp : "/tmp/TransactionalTest");
+
+// Test txn context which has special setCompleteFailure() method which prevents entire "txn complete" process from hapenning
+class TestTxnCtxt : public TxnCtxt
+{
+ public:
+ TestTxnCtxt(IdSequence* _loggedtx) : TxnCtxt(_loggedtx) {}
+ void setCompleteFailure(const unsigned num_queues_rem) {
+ // Remove queue members from back of impactedQueues until queues_rem reamin.
+ // to end to simulate multi-queue txn complete failure.
+ while (impactedQueues.size() > num_queues_rem) impactedQueues.erase(impactedQueues.begin());
+ }
+ void resetPreparedXidStorePtr() { preparedXidStorePtr = 0; }
+};
+
+// Test store which has special begin() which returns a TestTPCTxnCtxt, and a method to check for
+// remaining open transactions.
+// begin(), commit(), and abort() all hide functions in MessageStoreImpl. To avoid the compiler
+// warnings/errors these are renamed with a 'TMS' prefix.
+class TestMessageStore: public MessageStoreImpl
+{
+ public:
+ TestMessageStore(qpid::broker::Broker* br, const char* envpath = 0) : MessageStoreImpl(br, envpath) {}
+ std::auto_ptr<qpid::broker::TransactionContext> TMSbegin() {
+ checkInit();
+ // pass sequence number for c/a
+ return auto_ptr<TransactionContext>(new TestTxnCtxt(&messageIdSequence));
+ }
+ void TMScommit(TransactionContext& ctxt, const bool complete_prepared_list) {
+ checkInit();
+ TxnCtxt* txn(check(&ctxt));
+ if (!txn->isTPC()) {
+ localPrepare(dynamic_cast<TxnCtxt*>(txn));
+ if (!complete_prepared_list) dynamic_cast<TestTxnCtxt*>(txn)->resetPreparedXidStorePtr();
+ }
+ completed(*dynamic_cast<TxnCtxt*>(txn), true);
+ }
+ void TMSabort(TransactionContext& ctxt, const bool complete_prepared_list)
+ {
+ checkInit();
+ TxnCtxt* txn(check(&ctxt));
+ if (!txn->isTPC()) {
+ localPrepare(dynamic_cast<TxnCtxt*>(txn));
+ if (!complete_prepared_list) dynamic_cast<TestTxnCtxt*>(txn)->resetPreparedXidStorePtr();
+ }
+ completed(*dynamic_cast<TxnCtxt*>(txn), false);
+ }
+};
+
+// === Helper fns ===
+
+const string nameA("queueA");
+const string nameB("queueB");
+//const Uuid messageId(true);
+std::auto_ptr<MessageStoreImpl> store;
+std::auto_ptr<QueueRegistry> queues;
+Queue::shared_ptr queueA;
+Queue::shared_ptr queueB;
+
+template <class T>
+void setup()
+{
+ store = std::auto_ptr<T>(new T(&br));
+ store->init(test_dir, 4, 1, true); // truncate store
+
+ //create two queues:
+ queueA = Queue::shared_ptr(new Queue(nameA, 0, store.get(), 0));
+ queueA->create();
+ queueB = Queue::shared_ptr(new Queue(nameB, 0, store.get(), 0));
+ queueB->create();
+}
+
+template <class T>
+void restart()
+{
+ queueA.reset();
+ queueB.reset();
+ queues.reset();
+ store.reset();
+
+ store = std::auto_ptr<T>(new T(&br));
+ store->init(test_dir, 4, 1);
+ queues = std::auto_ptr<QueueRegistry>(new QueueRegistry);
+ ExchangeRegistry exchanges;
+ LinkRegistry links;
+ sys::Timer t;
+ DtxManager mgr(t);
+ mgr.setStore (store.get());
+ RecoveryManagerImpl recovery(*queues, exchanges, links, mgr, br.getProtocolRegistry());
+ store->recover(recovery);
+
+ queueA = queues->find(nameA);
+ queueB = queues->find(nameB);
+}
+
+Message createMessage(const string& id, const string& exchange="exchange", const string& key="routing_key")
+{
+ return MessageUtils::createMessage(exchange, key, Uuid(), true, 0, id);
+}
+
+void checkMsg(Queue::shared_ptr& queue, u_int32_t size, const string& msgid = "<none>")
+{
+ BOOST_REQUIRE(queue);
+ BOOST_CHECK_EQUAL(size, queue->getMessageCount());
+ if (size > 0) {
+ Message msg = MessageUtils::get(*queue);
+ BOOST_REQUIRE(msg);
+ BOOST_CHECK_EQUAL(msgid, MessageUtils::getCorrelationId(msg));
+ }
+}
+
+void swap(bool commit)
+{
+ setup<MessageStoreImpl>();
+
+ //create message and enqueue it onto first queue:
+ Message msgA = createMessage("Message", "exchange", "routing_key");
+ queueA->deliver(msgA);
+
+ QueueCursor cursorB;
+ Message msgB = MessageUtils::get(*queueA, &cursorB);
+ BOOST_REQUIRE(msgB);
+ //move the message from one queue to the other as a transaction
+ std::auto_ptr<TransactionContext> txn = store->begin();
+ TxBuffer tx;
+ queueB->deliver(msgB, &tx);//note: need to enqueue it first to avoid message being deleted
+
+ queueA->dequeue(txn.get(), cursorB);
+ tx.prepare(txn.get());
+ if (commit) {
+ store->commit(*txn);
+ } else {
+ store->abort(*txn);
+ }
+
+ restart<MessageStoreImpl>();
+
+ // Check outcome
+ BOOST_REQUIRE(queueA);
+ BOOST_REQUIRE(queueB);
+
+ Queue::shared_ptr x;//the queue from which the message was swapped
+ Queue::shared_ptr y;//the queue on which the message is expected to be
+
+ if (commit) {
+ x = queueA;
+ y = queueB;
+ } else {
+ x = queueB;
+ y = queueA;
+ }
+
+ checkMsg(x, 0);
+ checkMsg(y, 1, "Message");
+ checkMsg(y, 0);
+}
+
+void testMultiQueueTxn(const unsigned num_queues_rem, const bool complete_prepared_list, const bool commit)
+{
+ setup<TestMessageStore>();
+ TestMessageStore* tmsp = static_cast<TestMessageStore*>(store.get());
+ std::auto_ptr<TransactionContext> txn(tmsp->TMSbegin());
+ TxBuffer tx;
+
+ //create two messages and enqueue them onto both queues:
+ Message msgA = createMessage("MessageA", "exchange", "routing_key");
+ queueA->deliver(msgA, &tx);
+ queueB->deliver(msgA, &tx);
+ Message msgB = createMessage("MessageB", "exchange", "routing_key");
+ queueA->deliver(msgB, &tx);
+ queueB->deliver(msgB, &tx);
+
+ tx.prepare(txn.get());
+ static_cast<TestTxnCtxt*>(txn.get())->setCompleteFailure(num_queues_rem);
+ if (commit)
+ tmsp->TMScommit(*txn, complete_prepared_list);
+ else
+ tmsp->TMSabort(*txn, complete_prepared_list);
+ restart<TestMessageStore>();
+
+ // Check outcome
+ if (commit)
+ {
+ checkMsg(queueA, 2, "MessageA");
+ checkMsg(queueB, 2, "MessageA");
+ checkMsg(queueA, 1, "MessageB");
+ checkMsg(queueB, 1, "MessageB");
+ }
+ checkMsg(queueA, 0);
+ checkMsg(queueB, 0);
+}
+
+// === Test suite ===
+
+QPID_AUTO_TEST_CASE(Commit)
+{
+ SET_LOG_LEVEL("error+"); // This only needs to be set once.
+
+ cout << test_filename << ".Commit: " << flush;
+ swap(true);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(Abort)
+{
+ cout << test_filename << ".Abort: " << flush;
+ swap(false);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueCommit)
+{
+ cout << test_filename << ".MultiQueueCommit: " << flush;
+ testMultiQueueTxn(2, true, true);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueAbort)
+{
+ cout << test_filename << ".MultiQueueAbort: " << flush;
+ testMultiQueueTxn(2, true, false);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueNoQueueCommitRecover)
+{
+ cout << test_filename << ".MultiQueueNoQueueCommitRecover: " << flush;
+ testMultiQueueTxn(0, false, true);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueNoQueueAbortRecover)
+{
+ cout << test_filename << ".MultiQueueNoQueueAbortRecover: " << flush;
+ testMultiQueueTxn(0, false, false);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueSomeQueueCommitRecover)
+{
+ cout << test_filename << ".MultiQueueSomeQueueCommitRecover: " << flush;
+ testMultiQueueTxn(1, false, true);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueSomeQueueAbortRecover)
+{
+ cout << test_filename << ".MultiQueueSomeQueueAbortRecover: " << flush;
+ testMultiQueueTxn(1, false, false);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueAllQueueCommitRecover)
+{
+ cout << test_filename << ".MultiQueueAllQueueCommitRecover: " << flush;
+ testMultiQueueTxn(2, false, true);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueAllQueueAbortRecover)
+{
+ cout << test_filename << ".MultiQueueAllQueueAbortRecover: " << flush;
+ testMultiQueueTxn(2, false, false);
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(LockedRecordTest)
+{
+ cout << test_filename << ".LockedRecordTest: " << flush;
+
+ setup<MessageStoreImpl>();
+ queueA->deliver(createMessage("Message", "exchange", "routingKey"));
+ std::auto_ptr<TransactionContext> txn = store->begin();
+
+ QueueCursor cursor;
+ Message msg = MessageUtils::get(*queueA, &cursor);
+ queueA->dequeue(txn.get(), cursor);
+
+ try {
+ store->dequeue(0, msg.getPersistentContext(), *queueA);
+ BOOST_ERROR("Did not throw JERR_MAP_LOCKED exception as expected.");
+ }
+ catch (const mrg::msgstore::StoreException& e) {
+ if (std::strstr(e.what(), "JERR_MAP_LOCKED") == 0)
+ BOOST_ERROR("Unexpected StoreException: " << e.what());
+ }
+ catch (const std::exception& e) {
+ BOOST_ERROR("Unexpected exception: " << e.what());
+ }
+ store->commit(*txn);
+ checkMsg(queueA, 0);
+
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_SUITE_END()
diff --git a/cpp/src/tests/legacystore/TwoPhaseCommitTest.cpp b/cpp/src/tests/legacystore/TwoPhaseCommitTest.cpp
new file mode 100644
index 0000000000..92e49df9e3
--- /dev/null
+++ b/cpp/src/tests/legacystore/TwoPhaseCommitTest.cpp
@@ -0,0 +1,675 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "unit_test.h"
+
+#include "qpid/legacystore/MessageStoreImpl.h"
+#include <iostream>
+#include "MessageUtils.h"
+#include "qpid/broker/Queue.h"
+#include "qpid/broker/RecoveryManagerImpl.h"
+#include "qpid/framing/AMQHeaderBody.h"
+#include "qpid/log/Statement.h"
+#include "qpid/legacystore/TxnCtxt.h"
+#include "qpid/log/Logger.h"
+#include "qpid/sys/Timer.h"
+
+using namespace mrg::msgstore;
+using namespace qpid;
+using namespace qpid::broker;
+using namespace qpid::framing;
+using namespace std;
+
+
+qpid::broker::Broker::Options opts;
+qpid::broker::Broker br(opts);
+
+
+QPID_AUTO_TEST_SUITE(TwoPhaseCommitTest)
+
+#define SET_LOG_LEVEL(level) \
+ qpid::log::Options opts(""); \
+ opts.selectors.clear(); \
+ opts.selectors.push_back(level); \
+ qpid::log::Logger::instance().configure(opts);
+
+
+const string test_filename("TwoPhaseCommitTest");
+const char* tdp = getenv("TMP_DATA_DIR");
+string test_dir(tdp && strlen(tdp) > 0 ? tdp : "/tmp/TwoPhaseCommitTest");
+
+// === Helper fns ===
+
+class TwoPhaseCommitTest
+{
+
+ class Strategy
+ {
+ public:
+ virtual void init() = 0;
+ virtual void run(TPCTransactionContext* txn) = 0;
+ virtual void check(bool committed) = 0;
+ virtual ~Strategy(){}
+ };
+
+ class Swap : public Strategy
+ {
+ TwoPhaseCommitTest* const test;
+ const string messageId;
+ Message msg;
+ public:
+ Swap(TwoPhaseCommitTest* const test_, const string& messageId_): test(test_), messageId(messageId_) {}
+ void init(){ msg = test->deliver(messageId, test->queueA); }
+ void run(TPCTransactionContext* txn) { test->swap(txn, test->queueA, test->queueB); }
+ void check(bool committed) { test->swapCheck(committed, messageId, test->queueA, test->queueB); }
+ };
+
+ class Enqueue : public Strategy
+ {
+ TwoPhaseCommitTest* const test;
+ Message msg1;
+ Message msg2;
+ Message msg3;
+ public:
+ Enqueue(TwoPhaseCommitTest* const test_): test(test_) {}
+ void init() {}
+ void run(TPCTransactionContext* txn) {
+ msg1 = test->enqueue(txn, "Enqueue1", test->queueA);
+ msg2 = test->enqueue(txn, "Enqueue2", test->queueA);
+ msg3 = test->enqueue(txn, "Enqueue3", test->queueA);
+ }
+ void check(bool committed) {
+ if (committed) {
+ test->checkMsg(test->queueA, 3, "Enqueue1");
+ test->checkMsg(test->queueA, 2, "Enqueue2");
+ test->checkMsg(test->queueA, 1, "Enqueue3");
+ }
+ test->checkMsg(test->queueA, 0);
+ }
+ };
+
+ class Dequeue : public Strategy
+ {
+ TwoPhaseCommitTest* const test;
+ Message msg1;
+ Message msg2;
+ Message msg3;
+ public:
+ Dequeue(TwoPhaseCommitTest* const test_): test(test_) {}
+ void init() {
+ msg1 = test->deliver("Dequeue1", test->queueA);
+ msg2 = test->deliver("Dequeue2", test->queueA);
+ msg3 = test->deliver("Dequeue3", test->queueA);
+ }
+ void run(TPCTransactionContext* txn) {
+ test->dequeue(txn, test->queueA);
+ test->dequeue(txn, test->queueA);
+ test->dequeue(txn, test->queueA);
+ }
+ void check(bool committed) {
+ if (!committed) {
+ test->checkMsg(test->queueA, 3, "Dequeue1");
+ test->checkMsg(test->queueA, 2, "Dequeue2");
+ test->checkMsg(test->queueA, 1, "Dequeue3");
+ }
+ test->checkMsg(test->queueA, 0);
+ }
+ };
+
+ class MultiQueueTxn : public Strategy
+ {
+ TwoPhaseCommitTest* const test;
+ Message msg1;
+ Message msg2;
+ std::set<Queue::shared_ptr> queueset;
+ public:
+ MultiQueueTxn(TwoPhaseCommitTest* const test_): test(test_) {}
+ virtual void init() {}
+ virtual void run(TPCTransactionContext* txn) {
+ queueset.insert(test->queueA);
+ queueset.insert(test->queueB);
+ msg1 = test->enqueue(txn, "Message1", queueset);
+ msg2 = test->enqueue(txn, "Message2", queueset);
+ queueset.clear();
+ }
+ virtual void check(bool committed) {
+ TestMessageStore* sptr = static_cast<TestMessageStore*>(test->store.get());
+ if (committed)
+ {
+ test->checkMsg(test->queueA, 2, "Message1");
+ test->checkMsg(test->queueB, 2, "Message1");
+ test->checkMsg(test->queueA, 1, "Message2");
+ test->checkMsg(test->queueB, 1, "Message2");
+ }
+ test->checkMsg(test->queueA, 0);
+ test->checkMsg(test->queueB, 0);
+ // Check there are no remaining open txns in store
+ BOOST_CHECK_EQUAL(u_int32_t(0), sptr->getRemainingTxns(*(test->queueA)));
+ BOOST_CHECK_EQUAL(u_int32_t(0), sptr->getRemainingTxns(*(test->queueB)));
+ BOOST_CHECK_EQUAL(u_int32_t(0), sptr->getRemainingPreparedListTxns());
+ }
+ };
+
+ // Test txn context which has special setCompleteFailure() method which prevents entire "txn complete" process from hapenning
+ class TestTPCTxnCtxt : public TPCTxnCtxt
+ {
+ public:
+ TestTPCTxnCtxt(const std::string& _xid, IdSequence* _loggedtx) : TPCTxnCtxt(_xid, _loggedtx) {}
+ void setCompleteFailure(const unsigned num_queues_rem, const bool complete_prepared_list) {
+ // Remove queue members from back of impactedQueues until queues_rem reamin.
+ // to end to simulate multi-queue txn complete failure.
+ while (impactedQueues.size() > num_queues_rem) impactedQueues.erase(impactedQueues.begin());
+ // If prepared list is not to be committed, set pointer to 0
+ if (!complete_prepared_list) preparedXidStorePtr = 0;
+ }
+ };
+
+ // Test store which has sepcial begin() which returns a TestTPCTxnCtxt, and a method to check for
+ // reamining open transactions
+ class TestMessageStore: public MessageStoreImpl
+ {
+ public:
+ TestMessageStore(qpid::broker::Broker* br, const char* envpath = 0) : MessageStoreImpl(br, envpath) {}
+ std::auto_ptr<qpid::broker::TPCTransactionContext> TMSbegin(const std::string& xid) {
+ checkInit();
+ IdSequence* jtx = &messageIdSequence;
+ // pass sequence number for c/a
+ return auto_ptr<TPCTransactionContext>(new TestTPCTxnCtxt(xid, jtx));
+ }
+ u_int32_t getRemainingTxns(const PersistableQueue& queue) {
+ return static_cast<JournalImpl*>(queue.getExternalQueueStore())->get_open_txn_cnt();
+ }
+ u_int32_t getRemainingPreparedListTxns() {
+ return tplStorePtr->get_open_txn_cnt();
+ }
+ };
+
+ const string nameA;
+ const string nameB;
+ std::auto_ptr<MessageStoreImpl> store;
+ std::auto_ptr<DtxManager> dtxmgr;
+ std::auto_ptr<QueueRegistry> queues;
+ std::auto_ptr<LinkRegistry> links;
+ Queue::shared_ptr queueA;
+ Queue::shared_ptr queueB;
+ Message msg1;
+ Message msg2;
+ Message msg4;
+ std::auto_ptr<TxBuffer> tx;
+
+ void recoverPrepared(bool commit)
+ {
+ setup<MessageStoreImpl>();
+
+ Swap swap(this, "RecoverPrepared");
+ swap.init();
+ std::auto_ptr<TPCTransactionContext> txn(store->begin("my-xid"));
+ swap.run(txn.get());
+ if (tx.get()) {
+ tx->prepare(txn.get());
+ tx.reset();
+ }
+
+ store->prepare(*txn);
+ restart<MessageStoreImpl>();
+
+ //check that the message is not available from either queue
+ BOOST_CHECK_EQUAL((u_int32_t) 0, queueA->getMessageCount());
+ BOOST_CHECK_EQUAL((u_int32_t) 0, queueB->getMessageCount());
+
+ //commit/abort the txn - through the dtx manager, not directly on the store
+ if (commit) {
+ dtxmgr->commit("my-xid", false);
+ } else {
+ dtxmgr->rollback("my-xid");
+ }
+
+ swap.check(commit);
+ restart<MessageStoreImpl>();
+ swap.check(commit);
+ }
+
+ void testMultiQueueTxn(const unsigned num_queues_rem, const bool complete_prepared_list, const bool commit)
+ {
+ setup<TestMessageStore>();
+ MultiQueueTxn mqtTest(this);
+ mqtTest.init();
+ std::auto_ptr<TPCTransactionContext> txn(static_cast<TestMessageStore*>(store.get())->begin("my-xid"));
+ mqtTest.run(txn.get());
+ if (tx.get()) {
+ tx->prepare(txn.get());
+ tx.reset();
+ }
+ store->prepare(*txn);
+
+ // As the commits and aborts should happen through DtxManager, and it is too complex to
+ // pass all these test params through, we bypass DtxManager and use the store directly.
+ // This will prevent the queues from seeing committed txns, however. To test the success
+ // or failure of
+ static_cast<TestTPCTxnCtxt*>(txn.get())->setCompleteFailure(num_queues_rem, complete_prepared_list);
+ if (commit)
+ store->commit(*txn);
+ else
+ store->abort(*txn);
+ restart<TestMessageStore>();
+ mqtTest.check(commit);
+ }
+
+ void commit(Strategy& strategy)
+ {
+ setup<MessageStoreImpl>();
+ strategy.init();
+
+ std::auto_ptr<TPCTransactionContext> txn(store->begin("my-xid"));
+ strategy.run(txn.get());
+ if (tx.get()) {
+ tx->prepare(txn.get());
+ tx.reset();
+ }
+ store->prepare(*txn);
+ store->commit(*txn);
+ restart<MessageStoreImpl>();
+ strategy.check(true);
+ }
+
+ void abort(Strategy& strategy, bool prepare)
+ {
+ setup<MessageStoreImpl>();
+ strategy.init();
+
+ std::auto_ptr<TPCTransactionContext> txn(store->begin("my-xid"));
+ strategy.run(txn.get());
+ if (tx.get()) {
+ tx->prepare(txn.get());
+ tx.reset();
+ }
+ if (prepare) store->prepare(*txn);
+ store->abort(*txn);
+ restart<MessageStoreImpl>();
+ strategy.check(false);
+ }
+
+ void swap(TPCTransactionContext* txn, Queue::shared_ptr& from, Queue::shared_ptr& to)
+ {
+ QueueCursor c;
+ Message msg1 = MessageUtils::get(*from, &c);//just dequeues in memory
+ //move the message from one queue to the other as part of a
+ //distributed transaction
+ if (!tx.get()) tx = std::auto_ptr<TxBuffer>(new TxBuffer);
+ to->deliver(msg1, tx.get());//note: need to enqueue it first to avoid message being deleted
+ from->dequeue(txn, c);
+ }
+
+ void dequeue(TPCTransactionContext* txn, Queue::shared_ptr& queue)
+ {
+ QueueCursor c;
+ Message msg2 = MessageUtils::get(*queue, &c);//just dequeues in memory
+ queue->dequeue(txn, c);
+ }
+
+ Message enqueue(TPCTransactionContext* /*txn*/, const string& msgid, Queue::shared_ptr& queue)
+ {
+ Message msg = createMessage(msgid);
+ if (!tx.get()) tx = std::auto_ptr<TxBuffer>(new TxBuffer);
+ queue->deliver(msg, tx.get());
+ return msg;
+ }
+
+ Message enqueue(TPCTransactionContext* /*txn*/, const string& msgid, std::set<Queue::shared_ptr>& queueset)
+ {
+ if (!tx.get()) tx = std::auto_ptr<TxBuffer>(new TxBuffer);
+ Message msg = createMessage(msgid);
+ for (std::set<Queue::shared_ptr>::iterator i = queueset.begin(); i != queueset.end(); i++) {
+ (*i)->deliver(msg, tx.get());
+ }
+ return msg;
+ }
+
+ Message deliver(const string& msgid, Queue::shared_ptr& queue)
+ {
+ Message m = createMessage(msgid);
+ queue->deliver(m);
+ return m;
+ }
+
+ template <class T>
+ void setup()
+ {
+ store = std::auto_ptr<T>(new T(&br));
+ store->init(test_dir, 4, 1, true); // truncate store
+
+ //create two queues:
+ queueA = Queue::shared_ptr(new Queue(nameA, 0, store.get(), 0));
+ queueA->create();
+ queueB = Queue::shared_ptr(new Queue(nameB, 0, store.get(), 0));
+ queueB->create();
+ }
+
+ Message createMessage(const string& id, const string& exchange="exchange", const string& key="routing_key")
+ {
+ Message msg = MessageUtils::createMessage(exchange, key, Uuid(), true, 0, id);
+ return msg;
+ }
+
+ template <class T>
+ void restart()
+ {
+ queueA.reset();
+ queueB.reset();
+ store.reset();
+ queues.reset();
+ links.reset();
+
+ store = std::auto_ptr<T>(new T(&br));
+ store->init(test_dir, 4, 1);
+ sys::Timer t;
+ ExchangeRegistry exchanges;
+ queues = std::auto_ptr<QueueRegistry>(new QueueRegistry);
+ links = std::auto_ptr<LinkRegistry>(new LinkRegistry);
+ dtxmgr = std::auto_ptr<DtxManager>(new DtxManager(t));
+ dtxmgr->setStore (store.get());
+ RecoveryManagerImpl recovery(*queues, exchanges, *links, *dtxmgr, br.getProtocolRegistry());
+ store->recover(recovery);
+
+ queueA = queues->find(nameA);
+ queueB = queues->find(nameB);
+ }
+
+ void checkMsg(Queue::shared_ptr& queue, u_int32_t size, const string& msgid = "<none>")
+ {
+ BOOST_REQUIRE(queue);
+ BOOST_CHECK_EQUAL(size, queue->getMessageCount());
+ if (size > 0) {
+ Message msg = MessageUtils::get(*queue);
+ BOOST_REQUIRE(msg);
+ BOOST_CHECK_EQUAL(msgid, MessageUtils::getCorrelationId(msg));
+ }
+ }
+
+ void swapCheck(bool swapped, const string& msgid, Queue::shared_ptr& from, Queue::shared_ptr& to)
+ {
+ BOOST_REQUIRE(from);
+ BOOST_REQUIRE(to);
+
+ Queue::shared_ptr x; //the queue from which the message was swapped
+ Queue::shared_ptr y; //the queue on which the message is expected to be
+
+ if (swapped) {
+ x = from;
+ y = to;
+ } else {
+ x = to;
+ y = from;
+ }
+
+ checkMsg(x, 0);
+ checkMsg(y, 1, msgid);
+ checkMsg(y, 0);
+ }
+
+public:
+ TwoPhaseCommitTest() : nameA("queueA"), nameB("queueB") {}
+
+ void testCommitEnqueue()
+ {
+ Enqueue enqueue(this);
+ commit(enqueue);
+ }
+
+ void testCommitDequeue()
+ {
+ Dequeue dequeue(this);
+ commit(dequeue);
+ }
+
+ void testCommitSwap()
+ {
+ Swap swap(this, "SwapMessageId");
+ commit(swap);
+ }
+
+ void testPrepareAndAbortEnqueue()
+ {
+ Enqueue enqueue(this);
+ abort(enqueue, true);
+ }
+
+ void testPrepareAndAbortDequeue()
+ {
+ Dequeue dequeue(this);
+ abort(dequeue, true);
+ }
+
+ void testPrepareAndAbortSwap()
+ {
+ Swap swap(this, "SwapMessageId");
+ abort(swap, true);
+ }
+
+ void testAbortNoPrepareEnqueue()
+ {
+ Enqueue enqueue(this);
+ abort(enqueue, false);
+ }
+
+ void testAbortNoPrepareDequeue()
+ {
+ Dequeue dequeue(this);
+ abort(dequeue, false);
+ }
+
+ void testAbortNoPrepareSwap()
+ {
+ Swap swap(this, "SwapMessageId");
+ abort(swap, false);
+ }
+
+ void testRecoverPreparedThenCommitted()
+ {
+ recoverPrepared(true);
+ }
+
+ void testRecoverPreparedThenAborted()
+ {
+ recoverPrepared(false);
+ }
+
+ void testMultiQueueCommit()
+ {
+ testMultiQueueTxn(2, true, true);
+ }
+
+ void testMultiQueueAbort()
+ {
+ testMultiQueueTxn(2, true, false);
+ }
+
+ void testMultiQueueNoQueueCommitRecover()
+ {
+ testMultiQueueTxn(0, false, true);
+ }
+
+ void testMultiQueueNoQueueAbortRecover()
+ {
+ testMultiQueueTxn(0, false, false);
+ }
+
+ void testMultiQueueSomeQueueCommitRecover()
+ {
+ testMultiQueueTxn(1, false, true);
+ }
+
+ void testMultiQueueSomeQueueAbortRecover()
+ {
+ testMultiQueueTxn(1, false, false);
+ }
+
+ void testMultiQueueAllQueueCommitRecover()
+ {
+ testMultiQueueTxn(2, false, true);
+ }
+
+ void testMultiQueueAllQueueAbortRecover()
+ {
+ testMultiQueueTxn(2, false, false);
+ }
+};
+
+TwoPhaseCommitTest tpct;
+
+// === Test suite ===
+
+QPID_AUTO_TEST_CASE(CommitEnqueue)
+{
+ SET_LOG_LEVEL("error+"); // This only needs to be set once.
+
+ cout << test_filename << ".CommitEnqueue: " << flush;
+ tpct.testCommitEnqueue();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(CommitDequeue)
+{
+ cout << test_filename << ".CommitDequeue: " << flush;
+ tpct.testCommitDequeue();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(CommitSwap)
+{
+ cout << test_filename << ".CommitSwap: " << flush;
+ tpct.testCommitSwap();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(PrepareAndAbortEnqueue)
+{
+ cout << test_filename << ".PrepareAndAbortEnqueue: " << flush;
+ tpct.testPrepareAndAbortEnqueue();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(PrepareAndAbortDequeue)
+{
+ cout << test_filename << ".PrepareAndAbortDequeue: " << flush;
+ tpct.testPrepareAndAbortDequeue();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(PrepareAndAbortSwap)
+{
+ cout << test_filename << ".PrepareAndAbortSwap: " << flush;
+ tpct.testPrepareAndAbortSwap();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(AbortNoPrepareEnqueue)
+{
+ cout << test_filename << ".AbortNoPrepareEnqueue: " << flush;
+ tpct.testAbortNoPrepareEnqueue();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(AbortNoPrepareDequeue)
+{
+ cout << test_filename << ".AbortNoPrepareDequeue: " << flush;
+ tpct.testAbortNoPrepareDequeue();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(AbortNoPrepareSwap)
+{
+ cout << test_filename << ".AbortNoPrepareSwap: " << flush;
+ tpct.testAbortNoPrepareSwap();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(RecoverPreparedThenCommitted)
+{
+ cout << test_filename << ".RecoverPreparedThenCommitted: " << flush;
+ tpct.testRecoverPreparedThenCommitted();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(RecoverPreparedThenAborted)
+{
+ cout << test_filename << ".RecoverPreparedThenAborted: " << flush;
+ tpct.testRecoverPreparedThenAborted();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueCommit)
+{
+ cout << test_filename << ".MultiQueueCommit: " << flush;
+ tpct.testMultiQueueCommit();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueAbort)
+{
+ cout << test_filename << ".MultiQueueAbort: " << flush;
+ tpct.testMultiQueueAbort();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueNoQueueCommitRecover)
+{
+ cout << test_filename << ".MultiQueueNoQueueCommitRecover: " << flush;
+ tpct.testMultiQueueNoQueueCommitRecover();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueNoQueueAbortRecover)
+{
+ cout << test_filename << ".MultiQueueNoQueueAbortRecover: " << flush;
+ tpct.testMultiQueueNoQueueAbortRecover();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueSomeQueueCommitRecover)
+{
+ cout << test_filename << ".MultiQueueSomeQueueCommitRecover: " << flush;
+ tpct.testMultiQueueSomeQueueCommitRecover();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueSomeQueueAbortRecover)
+{
+ cout << test_filename << ".MultiQueueSomeQueueAbortRecover: " << flush;
+ tpct.testMultiQueueSomeQueueAbortRecover();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueAllQueueCommitRecover)
+{
+ cout << test_filename << ".MultiQueueAllQueueCommitRecover: " << flush;
+ tpct.testMultiQueueAllQueueCommitRecover();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(MultiQueueAllQueueAbortRecover)
+{
+ cout << test_filename << ".MultiQueueAllQueueAbortRecover: " << flush;
+ tpct.testMultiQueueAllQueueAbortRecover();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_SUITE_END()
diff --git a/cpp/src/tests/legacystore/clean.sh b/cpp/src/tests/legacystore/clean.sh
new file mode 100644
index 0000000000..efb19586fa
--- /dev/null
+++ b/cpp/src/tests/legacystore/clean.sh
@@ -0,0 +1,32 @@
+#!/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.
+#
+
+# This script cleans up any previous database and journal files, and should
+# be run prior to the store system tests, as these are prone to crashing or
+# hanging under some circumstances if the database is old or inconsistent.
+
+if [ -d ${TMP_DATA_DIR} ]; then
+ rm -rf ${TMP_DATA_DIR}
+fi
+if [ -d ${TMP_PYTHON_TEST_DIR} ]; then
+ rm -rf ${TMP_PYTHON_TEST_DIR}
+fi
+rm -f ${abs_srcdir}/*.vglog*
diff --git a/cpp/src/tests/legacystore/persistence.py b/cpp/src/tests/legacystore/persistence.py
new file mode 100644
index 0000000000..c4ab712f14
--- /dev/null
+++ b/cpp/src/tests/legacystore/persistence.py
@@ -0,0 +1,574 @@
+#
+# 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.
+#
+
+import sys, re, traceback, socket
+from getopt import getopt, GetoptError
+
+from qpid.connection import Connection
+from qpid.util import connect
+from qpid.datatypes import Message, RangedSet
+from qpid.queue import Empty
+from qpid.session import SessionException
+from qpid.testlib import TestBase010
+from time import sleep
+
+class PersistenceTest(TestBase010):
+
+ XA_RBROLLBACK = 1
+ XA_RBTIMEOUT = 2
+ XA_OK = 0
+
+ def createMessage(self, **kwargs):
+ session = self.session
+ dp = {}
+ dp['delivery_mode'] = 2
+ mp = {}
+ for k, v in kwargs.iteritems():
+ if k in ['routing_key', 'delivery_mode']: dp[k] = v
+ if k in ['message_id', 'correlation_id', 'application_headers']: mp[k] = v
+ args = []
+ args.append(session.delivery_properties(**dp))
+ if len(mp):
+ args.append(session.message_properties(**mp))
+ if kwargs.has_key('body'): args.append(kwargs['body'])
+ return Message(*args)
+
+ def phase1(self):
+ session = self.session
+
+ session.queue_declare(queue="queue-a", durable=True)
+ session.queue_declare(queue="queue-b", durable=True)
+ session.exchange_bind(queue="queue-a", exchange="amq.direct", binding_key="a")
+ session.exchange_bind(queue="queue-b", exchange="amq.direct", binding_key="b")
+
+ session.message_transfer(destination="amq.direct",
+ message=self.createMessage(routing_key="a", correlation_id="Msg0001", body="A_Message1"))
+ session.message_transfer(destination="amq.direct",
+ message=self.createMessage(routing_key="b", correlation_id="Msg0002", body="B_Message1"))
+
+# session.queue_declare(queue="lvq-test", durable=True, arguments={"qpid.last_value_queue":True})
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"B"}, body="B1"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"A"}, body="A1"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"A"}, body="A2"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"B"}, body="B2"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"B"}, body="B3"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"C"}, body="C1"))
+
+
+
+ def phase2(self):
+ session = self.session
+
+ #check queues exists
+ session.queue_declare(queue="queue-a", durable=True, passive=True)
+ session.queue_declare(queue="queue-b", durable=True, passive=True)
+
+ #check they are still bound to amq.direct correctly
+ responses = []
+ responses.append(session.exchange_bound(queue="queue-a", exchange="amq.direct", binding_key="a"))
+ responses.append(session.exchange_bound(queue="queue-b", exchange="amq.direct", binding_key="b"))
+ for r in responses:
+ self.assert_(not r.exchange_not_found)
+ self.assert_(not r.queue_not_found)
+ self.assert_(not r.key_not_matched)
+
+
+ #check expected messages are there
+ self.assertMessageOnQueue("queue-a", "Msg0001", "A_Message1")
+ self.assertMessageOnQueue("queue-b", "Msg0002", "B_Message1")
+
+ self.assertEmptyQueue("queue-a")
+ self.assertEmptyQueue("queue-b")
+
+ session.queue_declare(queue="queue-c", durable=True)
+
+ #send a message to a topic such that it reaches all queues
+ session.exchange_bind(queue="queue-a", exchange="amq.topic", binding_key="abc")
+ session.exchange_bind(queue="queue-b", exchange="amq.topic", binding_key="abc")
+ session.exchange_bind(queue="queue-c", exchange="amq.topic", binding_key="abc")
+
+ session.message_transfer(destination="amq.topic",
+ message=self.createMessage(routing_key="abc", correlation_id="Msg0003", body="AB_Message2"))
+
+# #check LVQ exists and has exepected messages:
+# session.queue_declare(queue="lvq-test", durable=True, passive=True)
+# session.message_subscribe(destination="lvq", queue="lvq-test")
+# lvq = session.incoming("lvq")
+# lvq.start()
+# accepted = RangedSet()
+# for m in ["A2", "B3", "C1"]:
+# msg = lvq.get(timeout=1)
+# self.assertEquals(m, msg.body)
+# accepted.add(msg.id)
+# try:
+# extra = lvq.get(timeout=1)
+# self.fail("lvq-test not empty, contains: " + extra.body)
+# except Empty: None
+# #publish some more messages while subscriber is active (no replacement):
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"C"}, body="C2"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"C"}, body="C3"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"A"}, body="A3"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"A"}, body="A4"))
+# session.message_transfer(message=self.createMessage(routing_key="lvq-test", application_headers={"qpid.LVQ_key":"C"}, body="C4"))
+# #check that accepting replaced messages is safe
+# session.message_accept(accepted)
+
+
+ def phase3(self):
+ session = self.session
+
+# #lvq recovery validation
+# session.queue_declare(queue="lvq-test", durable=True, passive=True)
+# session.message_subscribe(destination="lvq", queue="lvq-test")
+# lvq = session.incoming("lvq")
+# lvq.start()
+# accepted = RangedSet()
+# lvq.start()
+# for m in ["C4", "A4"]:
+# msg = lvq.get(timeout=1)
+# self.assertEquals(m, msg.body)
+# accepted.add(msg.id)
+# session.message_accept(accepted)
+# try:
+# extra = lvq.get(timeout=1)
+# self.fail("lvq-test not empty, contains: " + extra.body)
+# except Empty: None
+# session.message_cancel(destination="lvq")
+# session.queue_delete(queue="lvq-test")
+
+
+ #check queues exists
+ session.queue_declare(queue="queue-a", durable=True, passive=True)
+ session.queue_declare(queue="queue-b", durable=True, passive=True)
+ session.queue_declare(queue="queue-c", durable=True, passive=True)
+
+ session.tx_select()
+ #check expected messages are there
+ self.assertMessageOnQueue("queue-a", "Msg0003", "AB_Message2")
+ self.assertMessageOnQueue("queue-b", "Msg0003", "AB_Message2")
+ self.assertMessageOnQueue("queue-c", "Msg0003", "AB_Message2")
+
+ self.assertEmptyQueue("queue-a")
+ self.assertEmptyQueue("queue-b")
+ self.assertEmptyQueue("queue-c")
+
+ #note: default bindings must be restored for this to work
+ session.message_transfer(message=self.createMessage(
+ routing_key="queue-a", correlation_id="Msg0004", body="A_Message3"))
+ session.message_transfer(message=self.createMessage(
+ routing_key="queue-a", correlation_id="Msg0005", body="A_Message4"))
+ session.message_transfer(message=self.createMessage(
+ routing_key="queue-a", correlation_id="Msg0006", body="A_Message5"))
+
+ session.tx_commit()
+
+
+ #delete a queue
+ session.queue_delete(queue="queue-c")
+
+ session.message_subscribe(destination="ctag", queue="queue-a", accept_mode=0)
+ session.message_flow(destination="ctag", unit=0, value=0xFFFFFFFF)
+ session.message_flow(destination="ctag", unit=1, value=0xFFFFFFFF)
+ included = session.incoming("ctag")
+ msg1 = included.get(timeout=1)
+ self.assertExpectedContent(msg1, "Msg0004", "A_Message3")
+ msg2 = included.get(timeout=1)
+ self.assertExpectedContent(msg2, "Msg0005", "A_Message4")
+ msg3 = included.get(timeout=1)
+ self.assertExpectedContent(msg3, "Msg0006", "A_Message5")
+ self.ack(msg1, msg2, msg3)
+
+ session.message_transfer(destination="amq.direct", message=self.createMessage(
+ routing_key="queue-b", correlation_id="Msg0007", body="B_Message3"))
+
+ session.tx_rollback()
+
+
+ def phase4(self):
+ session = self.session
+
+ #check queues exists
+ session.queue_declare(queue="queue-a", durable=True, passive=True)
+ session.queue_declare(queue="queue-b", durable=True, passive=True)
+
+ self.assertMessageOnQueue("queue-a", "Msg0004", "A_Message3")
+ self.assertMessageOnQueue("queue-a", "Msg0005", "A_Message4")
+ self.assertMessageOnQueue("queue-a", "Msg0006", "A_Message5")
+
+ self.assertEmptyQueue("queue-a")
+ self.assertEmptyQueue("queue-b")
+
+ #check this queue doesn't exist
+ try:
+ session.queue_declare(queue="queue-c", durable=True, passive=True)
+ raise Exception("Expected queue-c to have been deleted")
+ except SessionException, e:
+ self.assertEquals(404, e.args[0].error_code)
+
+ def phase5(self):
+
+ session = self.session
+ queues = ["queue-a1", "queue-a2", "queue-b1", "queue-b2", "queue-c1", "queue-c2", "queue-d1", "queue-d2"]
+
+ for q in queues:
+ session.queue_declare(queue=q, durable=True)
+ session.queue_purge(queue=q)
+
+ session.message_transfer(message=self.createMessage(
+ routing_key="queue-a1", correlation_id="MsgA", body="MessageA"))
+ session.message_transfer(message=self.createMessage(
+ routing_key="queue-b1", correlation_id="MsgB", body="MessageB"))
+ session.message_transfer(message=self.createMessage(
+ routing_key="queue-c1", correlation_id="MsgC", body="MessageC"))
+ session.message_transfer(message=self.createMessage(
+ routing_key="queue-d1", correlation_id="MsgD", body="MessageD"))
+
+ session.dtx_select()
+ txa = self.xid('a')
+ txb = self.xid('b')
+ txc = self.xid('c')
+ txd = self.xid('d')
+
+ self.txswap("queue-a1", "queue-a2", txa)
+ self.txswap("queue-b1", "queue-b2", txb)
+ self.txswap("queue-c1", "queue-c2", txc)
+ self.txswap("queue-d1", "queue-d2", txd)
+
+ #no queue should have any messages accessible
+ for q in queues:
+ self.assertEqual(0, session.queue_query(queue=q).message_count, "Bad count for %s" % (q))
+
+ self.assertEqual(self.XA_OK, session.dtx_commit(xid=txa, one_phase=True).status)
+ self.assertEqual(self.XA_OK, session.dtx_rollback(xid=txb).status)
+ self.assertEqual(self.XA_OK, session.dtx_prepare(xid=txc).status)
+ self.assertEqual(self.XA_OK, session.dtx_prepare(xid=txd).status)
+
+ #further checks
+ not_empty = ["queue-a2", "queue-b1"]
+ for q in queues:
+ if q in not_empty:
+ self.assertEqual(1, session.queue_query(queue=q).message_count, "Bad count for %s" % (q))
+ else:
+ self.assertEqual(0, session.queue_query(queue=q).message_count, "Bad count for %s" % (q))
+
+
+ def phase6(self):
+ session = self.session
+
+ #check prepared transaction are reported correctly by recover
+ txc = self.xid('c')
+ txd = self.xid('d')
+
+ xids = session.dtx_recover().in_doubt
+ ids = [x.global_id for x in xids] #TODO: come up with nicer way to test these
+
+ if txc.global_id not in ids:
+ self.fail("Recovered xids not as expected. missing: %s" % (txc))
+ if txd.global_id not in ids:
+ self.fail("Recovered xids not as expected. missing: %s" % (txd))
+ self.assertEqual(2, len(xids))
+
+
+ queues = ["queue-a1", "queue-a2", "queue-b1", "queue-b2", "queue-c1", "queue-c2", "queue-d1", "queue-d2"]
+ not_empty = ["queue-a2", "queue-b1"]
+
+ #re-check
+ not_empty = ["queue-a2", "queue-b1"]
+ for q in queues:
+ if q in not_empty:
+ self.assertEqual(1, session.queue_query(queue=q).message_count, "Bad count for %s" % (q))
+ else:
+ self.assertEqual(0, session.queue_query(queue=q).message_count, "Bad count for %s" % (q))
+
+ #complete the prepared transactions
+ self.assertEqual(self.XA_OK, session.dtx_commit(xid=txc).status)
+ self.assertEqual(self.XA_OK, session.dtx_rollback(xid=txd).status)
+ not_empty.append("queue-c2")
+ not_empty.append("queue-d1")
+
+ for q in queues:
+ if q in not_empty:
+ self.assertEqual(1, session.queue_query(queue=q).message_count)
+ else:
+ self.assertEqual(0, session.queue_query(queue=q).message_count)
+
+ def phase7(self):
+ session = self.session
+ session.synchronous = False
+
+ # check xids from phase 6 are gone
+ txc = self.xid('c')
+ txd = self.xid('d')
+
+ xids = session.dtx_recover().in_doubt
+ ids = [x.global_id for x in xids] #TODO: come up with nicer way to test these
+
+ if txc.global_id in ids:
+ self.fail("Xid still present : %s" % (txc))
+ if txd.global_id in ids:
+ self.fail("Xid still present : %s" % (txc))
+ self.assertEqual(0, len(xids))
+
+ #test deletion of queue after publish
+ #create queue
+ session.queue_declare(queue = "q", auto_delete=True, durable=True)
+
+ #send message
+ for i in range(1, 10):
+ session.message_transfer(message=self.createMessage(routing_key = "q", body = "my-message"))
+
+ session.synchronous = True
+ #explicitly delete queue
+ session.queue_delete(queue = "q")
+
+ #test acking of message from auto-deleted queue
+ #create queue
+ session.queue_declare(queue = "q", auto_delete=True, durable=True)
+
+ #send message
+ session.message_transfer(message=self.createMessage(routing_key = "q", body = "my-message"))
+
+ #create consumer
+ session.message_subscribe(queue = "q", destination = "a", accept_mode=0, acquire_mode=0)
+ session.message_flow(unit = 1, value = 0xFFFFFFFF, destination = "a")
+ session.message_flow(unit = 0, value = 10, destination = "a")
+ queue = session.incoming("a")
+
+ #consume the message, cancel subscription (triggering auto-delete), then ack it
+ msg = queue.get(timeout = 5)
+ session.message_cancel(destination = "a")
+ self.ack(msg)
+
+ #test implicit deletion of bindings when queue is deleted
+ session.queue_declare(queue = "durable-subscriber-queue", exclusive=True, durable=True)
+ session.exchange_bind(exchange="amq.topic", queue="durable-subscriber-queue", binding_key="xyz")
+ session.message_transfer(destination= "amq.topic", message=self.createMessage(routing_key = "xyz", body = "my-message"))
+ session.queue_delete(queue = "durable-subscriber-queue")
+
+ #test unbind:
+ #create a series of bindings to a queue
+ session.queue_declare(queue = "binding-test-queue", durable=True)
+ session.exchange_bind(exchange="amq.direct", queue="binding-test-queue", binding_key="abc")
+ session.exchange_bind(exchange="amq.direct", queue="binding-test-queue", binding_key="pqr")
+ session.exchange_bind(exchange="amq.direct", queue="binding-test-queue", binding_key="xyz")
+ session.exchange_bind(exchange="amq.match", queue="binding-test-queue", binding_key="a", arguments={"x-match":"all", "p":"a"})
+ session.exchange_bind(exchange="amq.match", queue="binding-test-queue", binding_key="b", arguments={"x-match":"all", "p":"b"})
+ session.exchange_bind(exchange="amq.match", queue="binding-test-queue", binding_key="c", arguments={"x-match":"all", "p":"c"})
+ #then restart broker...
+
+
+ def phase8(self):
+ session = self.session
+
+ #continue testing unbind:
+ #send messages to the queue via each of the bindings
+ for k in ["abc", "pqr", "xyz"]:
+ data = "first %s" % (k)
+ session.message_transfer(destination= "amq.direct", message=self.createMessage(routing_key=k, body=data))
+ for a in [{"p":"a"}, {"p":"b"}, {"p":"c"}]:
+ data = "first %s" % (a["p"])
+ session.message_transfer(destination="amq.match", message=self.createMessage(application_headers=a, body=data))
+ #unbind some bindings (using final 0-10 semantics)
+ session.exchange_unbind(exchange="amq.direct", queue="binding-test-queue", binding_key="pqr")
+ session.exchange_unbind(exchange="amq.match", queue="binding-test-queue", binding_key="b")
+ #send messages again
+ for k in ["abc", "pqr", "xyz"]:
+ data = "second %s" % (k)
+ session.message_transfer(destination= "amq.direct", message=self.createMessage(routing_key=k, body=data))
+ for a in [{"p":"a"}, {"p":"b"}, {"p":"c"}]:
+ data = "second %s" % (a["p"])
+ session.message_transfer(destination="amq.match", message=self.createMessage(application_headers=a, body=data))
+
+ #check that only the correct messages are received
+ expected = []
+ for k in ["abc", "pqr", "xyz"]:
+ expected.append("first %s" % (k))
+ for a in [{"p":"a"}, {"p":"b"}, {"p":"c"}]:
+ expected.append("first %s" % (a["p"]))
+ for k in ["abc", "xyz"]:
+ expected.append("second %s" % (k))
+ for a in [{"p":"a"}, {"p":"c"}]:
+ expected.append("second %s" % (a["p"]))
+
+ session.message_subscribe(queue = "binding-test-queue", destination = "binding-test")
+ session.message_flow(unit = 1, value = 0xFFFFFFFF, destination = "binding-test")
+ session.message_flow(unit = 0, value = 10, destination = "binding-test")
+ queue = session.incoming("binding-test")
+
+ while len(expected):
+ msg = queue.get(timeout=1)
+ if msg.body not in expected:
+ self.fail("Missing message: %s" % msg.body)
+ expected.remove(msg.body)
+ try:
+ msg = queue.get(timeout=1)
+ self.fail("Got extra message: %s" % msg.body)
+ except Empty: pass
+
+
+
+ session.queue_declare(queue = "durable-subscriber-queue", exclusive=True, durable=True)
+ session.exchange_bind(exchange="amq.topic", queue="durable-subscriber-queue", binding_key="xyz")
+ session.message_transfer(destination= "amq.topic", message=self.createMessage(routing_key = "xyz", body = "my-message"))
+ session.queue_delete(queue = "durable-subscriber-queue")
+
+
+ def xid(self, txid, branchqual = ''):
+ return self.session.xid(format=0, global_id=txid, branch_id=branchqual)
+
+ def txswap(self, src, dest, tx):
+ self.assertEqual(self.XA_OK, self.session.dtx_start(xid=tx).status)
+ self.session.message_subscribe(destination="temp-swap", queue=src, accept_mode=0)
+ self.session.message_flow(destination="temp-swap", unit=0, value=1)
+ self.session.message_flow(destination="temp-swap", unit=1, value=0xFFFFFFFF)
+ msg = self.session.incoming("temp-swap").get(timeout=1)
+ self.session.message_cancel(destination="temp-swap")
+ self.session.message_transfer(message=self.createMessage(routing_key=dest, correlation_id=self.getProperty(msg, 'correlation_id'),
+ body=msg.body))
+ self.ack(msg)
+ self.assertEqual(self.XA_OK, self.session.dtx_end(xid=tx).status)
+
+ def assertEmptyQueue(self, name):
+ self.assertEqual(0, self.session.queue_query(queue=name).message_count)
+
+ def assertConnectionException(self, expectedCode, message):
+ self.assertEqual("connection", message.method.klass.name)
+ self.assertEqual("close", message.method.name)
+ self.assertEqual(expectedCode, message.reply_code)
+
+ def assertExpectedMethod(self, reply, klass, method):
+ self.assertEqual(klass, reply.method.klass.name)
+ self.assertEqual(method, reply.method.name)
+
+ def assertExpectedContent(self, msg, id, body):
+ self.assertEqual(id, self.getProperty(msg, 'correlation_id'))
+ self.assertEqual(body, msg.body)
+ return msg
+
+ def getProperty(self, msg, name):
+ for h in msg.headers:
+ if hasattr(h, name): return getattr(h, name)
+ return None
+
+ def ack(self, *msgs):
+ session = self.session
+ set = RangedSet()
+ for m in msgs:
+ set.add(m.id)
+ #TODO: tidy up completion
+ session.receiver._completed.add(m.id)
+ session.message_accept(set)
+ session.channel.session_completed(session.receiver._completed)
+
+ def assertExpectedGetResult(self, id, body):
+ return self.assertExpectedContent(session.incoming("incoming-gets").get(timeout=1), id, body)
+
+ def assertEqual(self, expected, actual, msg=''):
+ if expected != actual: raise Exception("%s expected: %s actual: %s" % (msg, expected, actual))
+
+ def assertMessageOnQueue(self, queue, id, body):
+ self.session.message_subscribe(destination="incoming-gets", queue=queue, accept_mode=0)
+ self.session.message_flow(destination="incoming-gets", unit=0, value=1)
+ self.session.message_flow(destination="incoming-gets", unit=1, value=0xFFFFFFFF)
+ msg = self.session.incoming("incoming-gets").get(timeout=1)
+ self.assertExpectedContent(msg, id, body)
+ self.ack(msg)
+ self.session.message_cancel(destination="incoming-gets")
+
+
+ def __init__(self):
+ TestBase010.__init__(self, "run")
+ self.setBroker("localhost")
+ self.errata = []
+
+ def connect(self):
+ """ Connects to the broker """
+ self.conn = Connection(connect(self.host, self.port))
+ self.conn.start(timeout=10)
+ self.session = self.conn.session("test-session", timeout=10)
+
+ def run(self, args=sys.argv[1:]):
+ try:
+ opts, extra = getopt(args, "r:s:e:b:p:h", ["retry=", "spec=", "errata=", "broker=", "phase=", "help"])
+ except GetoptError, e:
+ self._die(str(e))
+ phase = 0
+ retry = 0;
+ for opt, value in opts:
+ if opt in ("-h", "--help"): self._die()
+ if opt in ("-s", "--spec"): self.spec = value
+ if opt in ("-e", "--errata"): self.errata.append(value)
+ if opt in ("-b", "--broker"): self.setBroker(value)
+ if opt in ("-p", "--phase"): phase = int(value)
+ if opt in ("-r", "--retry"): retry = int(value)
+
+ if not phase: self._die("please specify the phase to run")
+ phase = "phase%d" % phase
+ self.connect()
+
+ try:
+ getattr(self, phase)()
+ print phase, "succeeded"
+ res = True;
+ except Exception, e:
+ print phase, "failed: ", e
+ traceback.print_exc()
+ res = False
+
+
+ if not self.session.error(): self.session.close(timeout=10)
+ self.conn.close(timeout=10)
+
+ # Crude fix to wait for thread in client to exit after return from session_close()
+ # Reduces occurrences of "Unhandled exception in thread" messages after each test
+ import time
+ time.sleep(1)
+
+ return res
+
+
+ def setBroker(self, broker):
+ rex = re.compile(r"""
+ # [ <user> [ / <password> ] @] <host> [ :<port> ]
+ ^ (?: ([^/]*) (?: / ([^@]*) )? @)? ([^:]+) (?: :([0-9]+))?$""", re.X)
+ match = rex.match(broker)
+ if not match: self._die("'%s' is not a valid broker" % (broker))
+ self.user, self.password, self.host, self.port = match.groups()
+ self.port = int(default(self.port, 5672))
+ self.user = default(self.user, "guest")
+ self.password = default(self.password, "guest")
+
+ def _die(self, message = None):
+ if message: print message
+ print """
+Options:
+ -h/--help : this message
+ -s/--spec <spec.xml> : file containing amqp XML spec
+ -p/--phase : test phase to run
+ -b/--broker [<user>[/<password>]@]<host>[:<port>] : broker to connect to
+ """
+ sys.exit(1)
+
+def default(value, default):
+ if (value == None): return default
+ else: return value
+
+if __name__ == "__main__":
+ test = PersistenceTest()
+ if not test.run(): sys.exit(1)
diff --git a/cpp/src/tests/legacystore/run_long_python_tests b/cpp/src/tests/legacystore/run_long_python_tests
new file mode 100644
index 0000000000..e43b2236ec
--- /dev/null
+++ b/cpp/src/tests/legacystore/run_long_python_tests
@@ -0,0 +1,21 @@
+#!/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.
+#
+
+./run_python_tests LONG_TEST
diff --git a/cpp/src/tests/legacystore/run_python_tests b/cpp/src/tests/legacystore/run_python_tests
new file mode 100644
index 0000000000..d9dec16963
--- /dev/null
+++ b/cpp/src/tests/legacystore/run_python_tests
@@ -0,0 +1,64 @@
+#!/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.
+#
+
+if test -z ${QPID_DIR} ; then
+ cat <<EOF
+
+ =========== WARNING: PYTHON TESTS DISABLED ==============
+
+ QPID_DIR not set.
+
+ ===========================================================
+
+EOF
+ exit
+fi
+
+. `dirname $0`/tests_env.sh
+
+MODULENAME=python_tests
+
+echo "Running Python tests in module ${MODULENAME}..."
+
+case x$1 in
+ xSHORT_TEST)
+ DEFAULT_PYTHON_TESTS="*.client_persistence.ExchangeQueueTests.* *.flow_to_disk.SimpleMaxSizeCountTest.test_browse_recover *.flow_to_disk.SimpleMaxSizeCountTest.test_durable_browse_recover *.flow_to_disk.MultiDurableQueueDurableMsgBrowseRecoverTxPTxCTest.test_mixed_limit_2" ;;
+ xLONG_TEST)
+ DEFAULT_PYTHON_TESTS= ;;
+ x)
+ DEFAULT_PYTHON_TESTS="*.client_persistence.* *.flow_to_disk.SimpleMaxSizeCountTest.* *.flow_to_disk.MultiDurableQueue*.test_mixed_limit_1 *.flow_to_disk.MultiQueue*.test_mixed_limit_1 *.resize.SimpleTest.* *.federation.*" ;;
+ *)
+ DEFAULT_PYTHON_TESTS=$1
+esac
+
+PYTHON_TESTS=${PYTHON_TESTS:-${DEFAULT_PYTHON_TESTS}}
+
+OUTDIR=${MODULENAME}.tmp
+rm -rf $OUTDIR
+
+# To debug a test, add the following options to the end of the following line:
+# -v DEBUG -c qpid.messaging.io.ops [*.testName]
+${PYTHON_DIR}/qpid-python-test -m ${MODULENAME} -I ${FAILING_PYTHON_TESTS} ${PYTHON_TESTS} -DOUTDIR=$OUTDIR #-v DEBUG
+RETCODE=$?
+
+if test x${RETCODE} != x0; then
+ exit 1;
+fi
+exit 0
diff --git a/cpp/src/tests/legacystore/run_short_python_tests b/cpp/src/tests/legacystore/run_short_python_tests
new file mode 100644
index 0000000000..523924fdba
--- /dev/null
+++ b/cpp/src/tests/legacystore/run_short_python_tests
@@ -0,0 +1,21 @@
+#!/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.
+#
+
+./run_python_tests SHORT_TEST
diff --git a/cpp/src/tests/legacystore/run_test b/cpp/src/tests/legacystore/run_test
new file mode 100644
index 0000000000..1d5c2ae407
--- /dev/null
+++ b/cpp/src/tests/legacystore/run_test
@@ -0,0 +1,69 @@
+#!/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.
+#
+
+# Set up environment and run a test executable or script.
+#
+# Output nothing if test passes, show the output if it fails and
+# leave output in <test>.log for examination.
+#
+# If qpidd.port exists run test with QPID_PORT=`cat qpidd.port`
+#
+# If $VALGRIND if is set run under valgrind. If there are valgrind
+# erros show valgrind output, also leave it in <test>.valgrind for
+# examination.
+#
+
+source `dirname $0`/vg_check
+
+# Export variables from makefile.
+export VALGRIND srcdir
+
+# Export QPID_PORT if qpidd.port exists.
+test -f qpidd.port && export QPID_PORT=`cat qpidd.port`
+
+# Avoid silly libtool error messages if these are not defined
+test -z "$LC_ALL" && export LC_ALL=
+test -z "$LC_CTYPE" && export LC_CTYPE=
+test -z "$LC_COLLATE" && export LC_COLLATE=
+test -z "$LC_MESSAGES" && export LC_MESSAGES=
+
+VG_LOG="$1.vglog"
+rm -f $VG_LOG*
+
+if grep -l "^# Generated by .*libtool" "$1" >/dev/null 2>&1; then
+ # This is a libtool "executable". Valgrind it if VALGRIND specified.
+ test -n "$VALGRIND" && VALGRIND="$VALGRIND --log-file=$VG_LOG --"
+ # Hide output unless there's an error.
+ libtool --mode=execute $VALGRIND "$@" 2>&1 || ERROR=$?
+ test -n "$VALGRIND" && vg_check $VG_LOG*
+else
+ # This is a non-libtool shell script, just execute it.
+ export VALGRIND srcdir
+ exec "$@"
+fi
+
+if test -z "$ERROR"; then
+ # Clean up logs if there was no error.
+ rm -f $VG_LOG*
+ exit 0
+else
+ exit $ERROR
+fi
diff --git a/cpp/src/tests/legacystore/start_broker b/cpp/src/tests/legacystore/start_broker
new file mode 100644
index 0000000000..30e4659030
--- /dev/null
+++ b/cpp/src/tests/legacystore/start_broker
@@ -0,0 +1,25 @@
+#!/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.
+#
+
+QPIDD=$QPID_BLD/src/qpidd
+rm -f qpidd.vglog* qpidd.log
+test -n "$VALGRIND" && VALGRIND="$VALGRIND --log-file=qpidd.vglog --suppressions=$QPID_DIR/cpp/src/tests/.valgrind.supp --"
+exec libtool --mode=execute $VALGRIND $QPIDD --daemon --port=0 --log-enable error+ --log-to-file qpidd.log "$@" > qpidd.port
diff --git a/cpp/src/tests/legacystore/stop_broker b/cpp/src/tests/legacystore/stop_broker
new file mode 100644
index 0000000000..dcefff376f
--- /dev/null
+++ b/cpp/src/tests/legacystore/stop_broker
@@ -0,0 +1,46 @@
+#!/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.
+#
+
+# Stop the broker, check for errors.
+#
+if test -f qpidd.port; then
+ export QPID_PORT=`cat qpidd.port`
+ QPIDD=$QPID_BLD/src/qpidd
+ rm -f qpidd.port
+
+ $QPIDD --quit || ERROR=$?
+
+ # Check qpidd.log.
+ grep -a 'warning\|error\|critical' qpidd.log && {
+ echo "WARNING: Suspicious broker log entries in qpidd.log, above."
+ }
+
+ # Check valgrind log.
+ if test -n "$VALGRIND"; then
+ source `dirname $0`/vg_check $VG_LOG*
+ vg_check qpidd.vglog*
+ fi
+
+ exit $ERROR
+else
+ echo "No qpidd.port file found - cannot stop broker."
+ exit 1;
+fi
diff --git a/cpp/src/tests/legacystore/system_test.sh b/cpp/src/tests/legacystore/system_test.sh
new file mode 100644
index 0000000000..4cccc5ac8d
--- /dev/null
+++ b/cpp/src/tests/legacystore/system_test.sh
@@ -0,0 +1,51 @@
+#!/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.
+#
+
+error() { echo $*; exit 1; }
+
+# Make sure $QPID_DIR contains what we need.
+if ! test -d "$QPID_DIR" ; then
+ echo "WARNING: QPID_DIR is not set skipping system tests."
+ exit
+fi
+STORE_LIB=../lib/.libs/msgstore.so
+
+xml_spec=$QPID_DIR/specs/amqp.0-10-qpid-errata.xml
+test -f $xml_spec || error "$xml_spec not found: invalid \$QPID_DIR ?"
+export PYTHONPATH=$QPID_DIR/python:$QPID_DIR/extras/qmf/src/py:$QPID_DIR/tools/src/py
+
+echo "Using directory $TMP_DATA_DIR"
+
+fail=0
+
+# Run the tests with a given set of flags
+BROKER_OPTS="--no-module-dir --load-module=$STORE_LIB --data-dir=$TMP_DATA_DIR --auth=no --wcache-page-size 16"
+run_tests() {
+ for p in `seq 1 8`; do
+ $abs_srcdir/start_broker "$@" ${BROKER_OPTS} || { echo "FAIL broker start"; return 1; }
+ python "$abs_srcdir/persistence.py" -s "$xml_spec" -b localhost:`cat qpidd.port` -p $p -r 3 || fail=1;
+ $abs_srcdir/stop_broker
+ done
+}
+
+run_tests || fail=1
+
+exit $fail
diff --git a/cpp/src/tests/legacystore/tests_env.sh b/cpp/src/tests/legacystore/tests_env.sh
new file mode 100644
index 0000000000..30d255b87c
--- /dev/null
+++ b/cpp/src/tests/legacystore/tests_env.sh
@@ -0,0 +1,260 @@
+#
+# 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.
+#
+
+# --- Function definitions ---
+
+
+func_check_required_env ()
+#-------------------------
+# Check that EITHER:
+# QPID_DIR is set (for running against svn QPID)
+# OR
+# QPID_PREFIX is set (for running against installed QPID
+# Will exit with error code 1 if neither of these is defined.
+# Params: None
+# Returns: 0 if env vars ok, 1 otherwise
+{
+ if test -z "${QPID_DIR}" -a -z "${QPID_PREFIX}"; then
+ # Try to find qpidd in the normal installed location
+ if test -x /usr/sbin/qpidd; then
+ QPID_PREFIX=/usr
+ else
+ echo "ERROR: Could not find installed Qpid"
+ echo "Either of the following must be set in the environment for this script to run:"
+ echo " QPID_DIR for running against a Qpid svn build"
+ echo " QPID_PREFIX for running against an installed Qpid"
+ return 1
+ fi
+ fi
+ return 0
+}
+
+
+func_check_qpid_python ()
+#------------------------
+# Check that Qpid python environment is ok
+# Params: None
+# Returns: 0 if Python environment is ok; 1 otherwise
+{
+ if ! python -c "import qpid" ; then
+ cat <<EOF
+
+ =========== WARNING: PYTHON TESTS DISABLED ==============
+
+ Unable to load python qpid module - skipping python tests.
+
+ PYTHONPATH=${PYTHONPATH}
+
+ ===========================================================
+
+EOF
+ return 1
+ fi
+ return 0
+}
+
+
+func_set_env ()
+#--------------
+# Set up the environment based on value of ${QPID_DIR}: if ${QPID_DIR} exists, assume a svn checkout,
+# otherwise set up for an installed or prefix test.
+# Params: None
+# Returns: Nothing
+{
+ if test "${QPID_DIR}" -a -d "${QPID_DIR}" ; then
+ # QPID_DIR is defined for source tree builds by the --with-qpid-checkout configure option.
+ # QPID_BLD is defined as the build directory, either $QPID_DIR/cpp or separately specified with
+ # the --with-qpid-build option for VPATH builds.
+
+ # Check QPID_BLD is also set
+ if test -z ${QPID_BLD}; then
+ QPID_BLD="${QPID_DIR}/cpp"
+ fi
+
+ # Paths and dirs
+ #if test -z ${abs_srcdir}; then
+ # abs_srcdir=`pwd`
+ #fi
+ source $QPID_BLD/src/tests/test_env.sh
+ # Override these two settings from test_env.sh:
+ export RECEIVER_EXEC=$QPID_TEST_EXEC_DIR/qpid-receive
+ export SENDER_EXEC=$QPID_TEST_EXEC_DIR/qpid-send
+
+ echo "abs_srcdir=$abs_srcdir"
+ export STORE_LIB="`pwd`/../lib/.libs/msgstore.so"
+ export STORE_ENABLE=1
+ export CLUSTER_LIB="${QPID_BLD}/src/.libs/cluster.so"
+
+ PYTHON_DIR="${QPID_DIR}/python"
+ export PYTHONPATH="${PYTHONPATH}":"${PYTHON_DIR}":"${QPID_DIR}/extras/qmf/src/py":"${QPID_DIR}/tools/src/py":"${QPID_DIR}/cpp/src/tests":"${abs_srcdir}"
+
+ # Libraries
+
+ # Executables
+ export QPIDD_EXEC="${QPID_BLD}/src/qpidd"
+
+ # Test data
+
+ else
+ # Set up the environment based on value of ${QPID_PREFIX} for testing against an installed qpid
+ # Alternatively, make sure ${QPID_BIN_DIR}, ${QPID_SBIN_DIR}, ${QPID_LIB_DIR} and ${QPID_LIBEXEC_DIR} are set for
+ # the installed location.
+ if test "${QPID_PREFIX}" -a -d "${QPID_PREFIX}" ; then
+ QPID_BIN_DIR=${QPID_PREFIX}/bin
+ QPID_SBIN_DIR=${QPID_PREFIX}/sbin
+ QPID_LIB_DIR=${QPID_PREFIX}/lib
+ QPID_LIBEXEC_DIR=${QPID_PREFIX}/libexec
+ fi
+
+ # These four env vars must be set prior to calling this script
+ func_checkpaths QPID_BIN_DIR QPID_SBIN_DIR QPID_LIB_DIR QPID_LIBEXEC_DIR
+
+ # Paths and dirs
+ export PYTHON_DIR="${QPID_BIN_DIR}"
+ export PYTHONPATH="${PYTHONPATH}":"${QPID_LIB_DIR}/python":"${QPID_LIBEXEC_DIR}/qpid/tests":"${QPID_LIB_DIR}/python2.4"
+
+
+ # Libraries
+
+ # Executables
+ export QPIDD_EXEC="${QPID_SBIN_DIR}/qpidd"
+
+ # Test Data
+
+ fi
+}
+
+
+func_mk_data_dir ()
+#------------------
+# Create a data dir at ${TMP_DATA_DIR} if not present, clear it otherwise.
+# Set TMP_DATA_DIR if it is not set.
+# Params: None
+# Returns: Nothing
+{
+ if test -z "${TMP_DATA_DIR}"; then
+ TMP_DATA_DIR=/tmp/python_tests
+ echo "TMP_DATA_DIR not set; using ${TMP_DATA_DIR}"
+ fi
+
+ # Delete old test dirs if they exist
+ if test -d "${TMP_DATA_DIR}" ; then
+ rm -rf "${TMP_DATA_DIR}/*"
+ fi
+ mkdir -p "${TMP_DATA_DIR}"
+ export TMP_DATA_DIR
+}
+
+
+func_checkvar ()
+#---------------
+# Check that an environment var is set (ie non-zero length)
+# Params: $1 - env var to be checked
+# Returns: 0 = env var is set (ie non-zero length)
+# 1 = env var is not set
+{
+ local loc_VAR=$1
+ if test -z ${!loc_VAR}; then
+ echo "WARNING: environment variable ${loc_VAR} not set."
+ return 1
+ fi
+ return 0
+}
+
+
+func_checkpaths ()
+#-----------------
+# Check a list of paths (each can contain ':'-separated sub-list) is set and valid (ie each path exists as a dir)
+# Params: $@ - List of path env vars to be checked
+# Returns: Nothing
+{
+ local loc_PATHS=$@
+ for path in ${loc_PATHS}; do
+ func_checkvar ${path}
+ if test $? == 0; then
+ local temp_IFS=${IFS}
+ IFS=":"
+ local pl=${!path}
+ for p in ${pl[@]}; do
+ if test ! -d ${p}; then
+ echo "WARNING: Directory ${p} in var ${path} not found."
+ fi
+ done
+ IFS=${temp_IFS}
+ fi
+ done
+}
+
+
+func_checklibs ()
+#----------------
+# Check that a list of libs is set and valid (ie each lib exists as an executable file)
+# Params: $@ - List of lib values to be checked
+# Returns: Nothing
+{
+ local loc_LIBS=$@
+ for lib in ${loc_LIBS[@]}; do
+ func_checkvar ${lib}
+ if test $? == 0; then
+ if test ! -x ${!lib}; then
+ echo "WARNING: Library ${lib}=${!lib} not found."
+ fi
+ fi
+ done
+}
+
+
+func_checkexecs ()
+#-----------------
+# Check that a list of executable is set and valid (ie each exec exists as an executable file)
+# Params: $@ - List of exec values to be checked
+# Returns: Nothing
+{
+ local loc_EXECS=$@
+ for exec in ${loc_EXECS[@]}; do
+ func_checkvar ${exec}
+ if test $? == 0; then
+ if test ! -x ${!exec}; then
+ echo "WARNING: Executable ${exec}=${!exec} not found or is not executable."
+ fi
+ fi
+ done
+}
+
+
+#--- Start of script ---
+
+func_check_required_env || exit 1 # Cannot run, exit with error
+
+srcdir=`dirname $0`
+if test -z ${abs_srcdir}; then
+ abs_srcdir=${srcdir}
+fi
+
+func_set_env
+func_check_qpid_python || exit 0 # A warning, not a failure.
+func_mk_data_dir
+
+# Check expected environment vars are set
+func_checkpaths PYTHON_DIR PYTHONPATH TMP_DATA_DIR
+func_checklibs STORE_LIB CLUSTER_LIB
+func_checkexecs QPIDD_EXEC QPID_CONFIG_EXEC QPID_ROUTE_EXEC SENDER_EXEC RECEIVER_EXEC
+
+FAILING_PYTHON_TESTS="${abs_srcdir}/failing_python_tests.txt"
+
diff --git a/cpp/src/tests/legacystore/unit_test.cpp b/cpp/src/tests/legacystore/unit_test.cpp
new file mode 100644
index 0000000000..add80a6f91
--- /dev/null
+++ b/cpp/src/tests/legacystore/unit_test.cpp
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+
+// Defines test_main function to link with actual unit test code.
+#define BOOST_AUTO_TEST_MAIN // Boost 1.33
+#define BOOST_TEST_MAIN
+
+#include "unit_test.h"
+
diff --git a/cpp/src/tests/legacystore/unit_test.h b/cpp/src/tests/legacystore/unit_test.h
new file mode 100644
index 0000000000..16b6ae2ffb
--- /dev/null
+++ b/cpp/src/tests/legacystore/unit_test.h
@@ -0,0 +1,69 @@
+#ifndef QPIPD_TEST_UNIT_TEST_H_
+#define QPIPD_TEST_UNIT_TEST_H_
+
+/*
+ *
+ * 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.
+ *
+ */
+
+
+// Workaround so we can build against boost 1.32, 1.33 and boost 1.34.
+// Remove when we no longer need to support 1.32 or 1.33.
+
+#include <boost/version.hpp>
+
+#if (BOOST_VERSION < 103400) // v.1.33 and earlier
+# include <boost/test/auto_unit_test.hpp>
+#else // v.1.34 and later
+# include <boost/test/unit_test.hpp>
+#endif
+
+// Keep the test function for compilation but do not not register it.
+// TODO aconway 2008-04-23: better workaround for expected failures.
+// The following causes the test testUpdateTxState not to run at all.
+# define QPID_AUTO_TEST_CASE_EXPECTED_FAILURES(test_name,n) \
+ namespace { struct test_name { void test_method(); }; } \
+ void test_name::test_method()
+// The following runs the test testUpdateTxState, but it fails.
+/*#define QPID_AUTO_TEST_CASE_EXPECTED_FAILURES(test_name,n) \
+ namespace { struct test_name { void test_method(); }; } \
+ BOOST_AUTO_TEST_CASE(name)*/
+
+#if (BOOST_VERSION < 103300) // v.1.32 and earlier
+
+# define QPID_AUTO_TEST_SUITE(name)
+# define QPID_AUTO_TEST_CASE(name) BOOST_AUTO_UNIT_TEST(name)
+# define QPID_AUTO_TEST_SUITE_END()
+
+#elif (BOOST_VERSION < 103400) // v.1.33
+
+// Note the trailing ';'
+# define QPID_AUTO_TEST_SUITE(name) BOOST_AUTO_TEST_SUITE(name);
+# define QPID_AUTO_TEST_CASE(name) BOOST_AUTO_TEST_CASE(name)
+# define QPID_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END();
+
+#else // v.1.34 and later
+
+# define QPID_AUTO_TEST_SUITE(name) BOOST_AUTO_TEST_SUITE(name)
+# define QPID_AUTO_TEST_CASE(name) BOOST_AUTO_TEST_CASE(name)
+# define QPID_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
+
+#endif
+
+#endif /*!QPIPD_TEST_UNIT_TEST_H_*/
diff --git a/cpp/src/tests/long_cluster_tests.py b/cpp/src/tests/long_cluster_tests.py
deleted file mode 100755
index f77837f0c4..0000000000
--- a/cpp/src/tests/long_cluster_tests.py
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env python
-
-# 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.
-#
-
-import os, signal, sys, unittest
-from testlib import TestBaseCluster
-
-class LongClusterTests(TestBaseCluster):
- """Long/Soak cluster tests with async store ability"""
-
-
- def test_LongCluster_01_DummyTest(self):
- """Dummy test - a placeholder for the first of the long/soak python cluster tests"""
- pass
-
-# Start the test here
-
-if __name__ == '__main__':
- if os.getenv("STORE_LIB") != None:
- print "NOTE: Store enabled for the following tests:"
- if not unittest.main(): sys.exit(1)
-
diff --git a/cpp/src/tests/qpid-cluster-benchmark b/cpp/src/tests/qpid-cluster-benchmark
index 610beacebd..3e6b805692 100755
--- a/cpp/src/tests/qpid-cluster-benchmark
+++ b/cpp/src/tests/qpid-cluster-benchmark
@@ -55,12 +55,10 @@ done
shift $(($OPTIND-1))
CONNECTION_OPTIONS="--connection-options {tcp-nodelay:$TCP_NODELAY,reconnect:$RECONNECT,heartbeat:$HEARTBEAT}"
-CREATE_OPTIONS="node:{x-declare:{arguments:{'qpid.replicate':all}}}"
BROKER=$(echo $BROKERS | sed s/,.*//)
run_test() { echo $*; shift; "$@"; echo; echo; echo; }
OPTS="$OPTS $REPEAT $BROKERS --summarize $QUEUES $SENDERS $RECEIVERS $MESSAGES $CLIENT_HOSTS $SAVE_RECEIVED $CONNECTION_OPTIONS $NO_DELETE"
-OPTS="$OPTS --create-option $CREATE_OPTIONS"
run_test "Benchmark:" qpid-cpp-benchmark $OPTS "$@"
diff --git a/cpp/src/tests/qpid-cpp-benchmark b/cpp/src/tests/qpid-cpp-benchmark
index d5ad5191ca..9ac6a10883 100755
--- a/cpp/src/tests/qpid-cpp-benchmark
+++ b/cpp/src/tests/qpid-cpp-benchmark
@@ -18,7 +18,7 @@
# under the License.
#
-import optparse, time, qpid.messaging, re
+import optparse, time, qpid.messaging, re, os
from threading import Thread
from subprocess import Popen, PIPE, STDOUT
@@ -77,6 +77,10 @@ op.add_option("--no-delete", default=False, action="store_true",
help="Don't delete the test queues.")
op.add_option("--fill-drain", default=False, action="store_true",
help="First fill the queues, then drain them")
+op.add_option("--qpid-send-path", default="", type="str", metavar="PATH",
+ help="path to qpid-send binary")
+op.add_option("--qpid-receive-path", default="", type="str", metavar="PATH",
+ help="path to qpid-receive binary")
single_quote_re = re.compile("'")
def posix_quote(string):
@@ -115,7 +119,7 @@ def start_receive(queue, index, opts, ready_queue, broker, host):
messages = msg_total/opts.receivers;
if (index < msg_total%opts.receivers): messages += 1
if (messages == 0): return None
- command = ["qpid-receive",
+ command = [os.path.join(opts.qpid_receive_path, "qpid-receive"),
"-b", broker,
"-a", address,
"-m", str(messages),
@@ -138,7 +142,7 @@ def start_receive(queue, index, opts, ready_queue, broker, host):
def start_send(queue, opts, broker, host):
address="%s;{%s}"%(queue,",".join(opts.send_option + ["create:always"]))
- command = ["qpid-send",
+ command = [os.path.join(opts.qpid_send_path, "qpid-send"),
"-b", broker,
"-a", address,
"--messages", str(opts.messages),
diff --git a/cpp/src/tests/qpid-receive.cpp b/cpp/src/tests/qpid-receive.cpp
index 7a02b871db..e623d052e8 100644
--- a/cpp/src/tests/qpid-receive.cpp
+++ b/cpp/src/tests/qpid-receive.cpp
@@ -222,7 +222,7 @@ int main(int argc, char ** argv)
if (msg.getCorrelationId().size()) std::cout << "CorrelationId: " << msg.getCorrelationId() << std::endl;
if (msg.getUserId().size()) std::cout << "UserId: " << msg.getUserId() << std::endl;
if (msg.getTtl().getMilliseconds()) std::cout << "TTL: " << msg.getTtl().getMilliseconds() << std::endl;
- if (msg.getPriority()) std::cout << "Priority: " << msg.getPriority() << std::endl;
+ if (msg.getPriority()) std::cout << "Priority: " << ((uint) msg.getPriority()) << std::endl;
if (msg.getDurable()) std::cout << "Durable: true" << std::endl;
if (msg.getRedelivered()) std::cout << "Redelivered: true" << std::endl;
std::cout << "Properties: " << msg.getProperties() << std::endl;
diff --git a/cpp/src/tests/qpid-send.cpp b/cpp/src/tests/qpid-send.cpp
index b1c4f2be38..c3bba31e3b 100644
--- a/cpp/src/tests/qpid-send.cpp
+++ b/cpp/src/tests/qpid-send.cpp
@@ -200,7 +200,7 @@ struct Options : public qpid::Options
std::string name;
std::string value;
if (nameval(property, name, value)) {
- message.getProperties()[name] = value;
+ message.getProperties()[name].parse(value);
} else {
message.getProperties()[name] = Variant();
}
diff --git a/cpp/src/tests/qpid-test-cluster b/cpp/src/tests/qpid-test-cluster
deleted file mode 100755
index 40ad452a0d..0000000000
--- a/cpp/src/tests/qpid-test-cluster
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/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.
-#
-
-usage() {
- echo "Usage: `basename $0` [options] start|stop|restart|check [hosts]
-Start/stop/restart a cluster on specified hosts or on \$HOSTS via ssh.
-
-Options:
- -l USER Run qpidd and copy files as USER.
- -e SCRIPT Source SCRIPT for environment settings. Copies SCRIPT to each host.
- Default is $DEFAULT_ENV.
- -c CONFIG Use CONFIG as qpidd config file. Copies CONFIG to each host.
- Default is $DEFAULT_CONF
- -d Delete data-dir and log file before starting broker.
-"
- exit 1
-}
-
-DEFAULT_CONF=~/qpid-test-qpidd.conf
-DEFAULT_ENV=~/qpid-test-env.sh
-
-test -f $DEFAULT_CONF && CONF_FILE=$DEFAULT_CONF
-test -f $DEFAULT_ENV && ENV_FILE=$DEFAULT_ENV
-
-while getopts "l:e:c:d" opt; do
- case $opt in
- l) SSHOPTS="-l$OPTARG $SSHOPTS" ; RSYNC_USER="$OPTARG@" ;;
- e) ENV_FILE=$OPTARG ;;
- c) CONF_FILE=$OPTARG ;;
- d) DO_DELETE=1 ;;
- *) usage;;
- esac
-done
-shift `expr $OPTIND - 1`
-test "$*" || usage
-CMD=$1; shift
-HOSTS=${*:-$HOSTS}
-
-conf_value() { test -f "$CONF_FILE" && awk -F= "/^$1=/ {print \$2}" $CONF_FILE; }
-
-if test -n "$CONF_FILE"; then
- test -f "$CONF_FILE" || { echo Config file not found: $CONF_FILE; exit 1; }
- RSYNCFILES="$RSYNCFILES $CONF_FILE"
- QPIDD_ARGS="$QPIDD_ARGS --config $CONF_FILE"
- CONF_PORT=`conf_value port`
- CONF_DATA_DIR=`conf_value data-dir`
- CONF_LOG_FILE=`conf_value log-to-file`
-fi
-
-if test -n "$ENV_FILE"; then
- test -f "$ENV_FILE" || { echo Environment file not found: $ENV_FILE; exit 1; }
- RSYNCFILES="$RSYNCFILES $ENV_FILE"
- SOURCE_ENV="source $ENV_FILE ; "
-fi
-
-test -n "$RSYNCFILES" && rsynchosts $RSYNCFILES # Copy conf/env files to all hosts
-
-do_start() {
- for h in $HOSTS; do
- COMMAND="qpidd -d $QPIDD_ARGS"
- id -nG | grep '\<ais\>' >/dev/null && COMMAND="sg ais -c '$COMMAND'"
- if test "$DO_DELETE"; then COMMAND="rm -rf $CONF_DATA_DIR $CONF_LOG_FILE; $COMMAND"; fi
- ssh $h "$SOURCE_ENV $COMMAND" || { echo "Failed to start on $h"; exit 1; }
- done
-}
-
-do_stop() {
- for h in $HOSTS; do
- ssh $h "$SOURCE_ENV qpidd -q --no-module-dir --no-data-dir $QPIDD_ARGS"
- done
-}
-
-do_status() {
- for h in $HOSTS; do
- if ssh $h "$SOURCE_ENV qpidd -c --no-module-dir --no-data-dir $QPIDD_ARGS > /dev/null"; then
- echo "$h ok"
- else
- echo "$h not running"
- STATUS=1
- fi
- done
-}
-
-case $CMD in
- start) do_start ;;
- stop) do_stop ;;
- restart) do_stop ; do_start ;;
- status) do_status ;;
- *) usage;;
-esac
-
-exit $STATUS
diff --git a/cpp/src/tests/reliable_replication_test b/cpp/src/tests/reliable_replication_test
deleted file mode 100755
index c660f751e5..0000000000
--- a/cpp/src/tests/reliable_replication_test
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/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.
-#
-
-# Test reliability of the replication feature in the face of link
-# failures:
-
-source ./test_env.sh
-
-trap stop_brokers EXIT
-
-stop_brokers() {
- if [[ $BROKER_A ]] ; then
- $QPIDD_EXEC --no-module-dir -q --port $BROKER_A
- unset BROKER_A
- fi
- if [[ $BROKER_B ]] ; then
- $QPIDD_EXEC --no-module-dir -q --port $BROKER_B
- unset BROKER_B
- fi
-}
-
-setup() {
- rm -f replication-source.log replication-dest.log
- $QPIDD_EXEC --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module $REPLICATING_LISTENER_LIB --replication-queue replication --create-replication-queue true --log-enable trace+ --log-to-file replication-source.log --log-to-stderr 0 > qpidd-repl.port
- BROKER_A=`cat qpidd-repl.port`
-
- $QPIDD_EXEC --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module $REPLICATION_EXCHANGE_LIB --log-enable info+ --log-to-file replication-dest.log --log-to-stderr 0 > qpidd-repl.port
- BROKER_B=`cat qpidd-repl.port`
-
- echo "Testing replication from port $BROKER_A to port $BROKER_B"
-
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add exchange replication replication
- $PYTHON_COMMANDS/qpid-route --ack 500 queue add "localhost:$BROKER_B" "localhost:$BROKER_A" replication replication
-
- #create test queue (only replicate enqueues for this test):
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue queue-a --generate-queue-events 1
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add queue queue-a
-}
-
-send() {
- ./sender --port $BROKER_A --routing-key queue-a --send-eos 1 < replicated.expected
-}
-
-receive() {
- rm -f replicated.actual
- ./receiver --port $BROKER_B --queue queue-a > replicated.actual
-}
-
-bounce_link() {
- $PYTHON_COMMANDS/qpid-route link del "localhost:$BROKER_B" "localhost:$BROKER_A"
- $PYTHON_COMMANDS/qpid-route --ack 500 queue add "localhost:$BROKER_B" "localhost:$BROKER_A" replication replication
-}
-
-if test -d ${PYTHON_DIR} && test -e $REPLICATING_LISTENER_LIB && test -e $REPLICATION_EXCHANGE_LIB ; then
- setup
- for i in `seq 1 100000`; do echo Message $i; done > replicated.expected
- send &
- receive &
- for i in `seq 1 3`; do sleep 1; bounce_link; done;
- wait
- #check that received list is identical to sent list
- diff replicated.actual replicated.expected || exit 1
- rm -f replication.actual replication.expected replication-source.log replication-dest.log qpidd-repl.port
- true
-fi
-
diff --git a/cpp/src/tests/replication_test b/cpp/src/tests/replication_test
deleted file mode 100755
index f8b2136396..0000000000
--- a/cpp/src/tests/replication_test
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/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.
-#
-
-# Run a test of the replication feature
-
-source ./test_env.sh
-
-trap stop_brokers INT TERM QUIT
-
-stop_brokers() {
- if [ x$BROKER_A != x ]; then
- $QPIDD_EXEC --no-module-dir -q --port $BROKER_A
- unset BROKER_A
- fi
- if [ x$BROKER_B != x ]; then
- $QPIDD_EXEC --no-module-dir -q --port $BROKER_B
- unset BROKER_B
- fi
-}
-
-if test -d ${PYTHON_DIR} && test -f "$REPLICATING_LISTENER_LIB" && test -f "$REPLICATION_EXCHANGE_LIB"; then
- rm -f queue-*.repl replication-*.log #cleanup from any earlier runs
-
- $QPIDD_EXEC --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module $REPLICATING_LISTENER_LIB --replication-queue replication --create-replication-queue true --log-enable info+ --log-to-file replication-source.log --log-to-stderr 0 > qpidd.port
- BROKER_A=`cat qpidd.port`
-
- $QPIDD_EXEC --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module $REPLICATION_EXCHANGE_LIB --log-enable info+ --log-to-file replication-dest.log --log-to-stderr 0 > qpidd.port
- BROKER_B=`cat qpidd.port`
- echo "Running replication test between localhost:$BROKER_A and localhost:$BROKER_B"
-
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add exchange replication replication
- $PYTHON_COMMANDS/qpid-route --ack 5 queue add "localhost:$BROKER_B" "localhost:$BROKER_A" replication replication
-
- #create test queues
-
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue queue-a --generate-queue-events 2
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue queue-b --generate-queue-events 2
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue queue-c --generate-queue-events 1
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue queue-d --generate-queue-events 2
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue queue-e --generate-queue-events 1
-
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add queue queue-a
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add queue queue-b
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add queue queue-c
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add queue queue-e
- #queue-d deliberately not declared on DR; this error case should be handled
-
- #publish and consume from test queues on broker A:
- i=1
- while [ $i -le 10 ]; do
- echo Message $i for A >> queue-a-input.repl
- i=`expr $i + 1`
- done
- i=1
- while [ $i -le 20 ]; do
- echo Message $i for B >> queue-b-input.repl
- i=`expr $i + 1`
- done
- i=1
- while [ $i -le 15 ]; do
- echo Message $i for C >> queue-c-input.repl
- i=`expr $i + 1`
- done
-
- ./sender --port $BROKER_A --routing-key queue-a --send-eos 1 < queue-a-input.repl
- ./sender --port $BROKER_A --routing-key queue-b --send-eos 1 < queue-b-input.repl
- ./sender --port $BROKER_A --routing-key queue-c --send-eos 1 < queue-c-input.repl
- echo dummy | ./sender --port $BROKER_A --routing-key queue-d --send-eos 1
-
- ./receiver --port $BROKER_A --queue queue-a --messages 5 > /dev/null
- ./receiver --port $BROKER_A --queue queue-b --messages 10 > /dev/null
- ./receiver --port $BROKER_A --queue queue-c --messages 10 > /dev/null
- ./receiver --port $BROKER_A --queue queue-d > /dev/null
-
-
- # What we are doing is putting a message on the end of repliaction queue & waiting for it on remote side
- # making sure all the messages have been flushed from the replication queue.
- echo dummy | ./sender --port $BROKER_A --routing-key queue-e --send-eos 1
- ./receiver --port $BROKER_B --queue queue-e --messages 1 > /dev/null
-
- #shutdown broker A then check that broker Bs versions of the queues are as expected
- $QPIDD_EXEC --no-module-dir -q --port $BROKER_A
- unset BROKER_A
-
- #validate replicated queues:
- ./receiver --port $BROKER_B --queue queue-a > queue-a-backup.repl
- ./receiver --port $BROKER_B --queue queue-b > queue-b-backup.repl
- ./receiver --port $BROKER_B --queue queue-c > queue-c-backup.repl
-
-
- tail -5 queue-a-input.repl > queue-a-expected.repl
- tail -10 queue-b-input.repl > queue-b-expected.repl
- diff queue-a-backup.repl queue-a-expected.repl || FAIL=1
- diff queue-b-backup.repl queue-b-expected.repl || FAIL=1
- diff queue-c-backup.repl queue-c-input.repl || FAIL=1
-
- grep 'queue-d does not exist' replication-dest.log > /dev/null || echo "WARNING: Expected error to be logged!"
-
- stop_brokers
-
- # now check offsets working (enqueue based on position being set, not queue abs position)
-
- $QPIDD_EXEC --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module $REPLICATING_LISTENER_LIB --replication-queue replication --create-replication-queue true --log-enable info+ --log-to-file replication-source.log --log-to-stderr 0 > qpidd.port
- BROKER_A=`cat qpidd.port`
-
- $QPIDD_EXEC --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module $REPLICATION_EXCHANGE_LIB --log-enable info+ --log-to-file replication-dest.log --log-to-stderr 0 > qpidd.port
- BROKER_B=`cat qpidd.port`
-
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add exchange replication replication
- $PYTHON_COMMANDS/qpid-route --ack 5 queue add "localhost:$BROKER_B" "localhost:$BROKER_A" replication replication
-
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue queue-e --generate-queue-events 2
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add queue queue-e
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_A" add queue queue-d --generate-queue-events 1
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add queue queue-d
-
- i=1
- while [ $i -le 10 ]; do
- echo Message $i for A >> queue-e-input.repl
- i=`expr $i + 1`
- done
-
- ./sender --port $BROKER_A --routing-key queue-e --send-eos 1 < queue-e-input.repl
- ./receiver --port $BROKER_A --queue queue-e --messages 10 > /dev/null
-
- # What we are doing is putting a message on the end of repliaction queue & waiting for it on remote side
- # making sure all the messages have been flushed from the replication queue.
- echo dummy | ./sender --port $BROKER_A --routing-key queue-d --send-eos 1
- ./receiver --port $BROKER_B --queue queue-d --messages 1 > /dev/null
-
- # now check offsets working
- $QPIDD_EXEC --no-module-dir -q --port $BROKER_B
- unset BROKER_B
- $QPIDD_EXEC --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module $REPLICATION_EXCHANGE_LIB --log-enable info+ --log-to-file replication-dest.log --log-to-stderr 0 > qpidd.port
- BROKER_B=`cat qpidd.port`
-
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add queue queue-e
- $PYTHON_COMMANDS/qpid-config -b "localhost:$BROKER_B" add exchange replication replication
- $PYTHON_COMMANDS/qpid-route --ack 5 queue add "localhost:$BROKER_B" "localhost:$BROKER_A" replication replication
- # now send another 15
- i=11
- while [ $i -le 15 ]; do
- echo Message $i for A >> queue-e1-input.repl
- i=`expr $i + 1`
- done
- ./sender --port $BROKER_A --routing-key queue-e --send-eos 1 < queue-e1-input.repl
-
- ./receiver --port $BROKER_B --queue queue-e > queue-e-backup.repl
- diff queue-e-backup.repl queue-e1-input.repl || FAIL=1
-
- stop_brokers
-
- if [ x$FAIL != x ]; then
- echo replication test failed: expectations not met!
- exit 1
- else
- echo queue state replicated as expected
- rm -f queue-*.repl replication-*.log
- fi
-
-else
- echo "Skipping replication test, plugins not built or python utils not located"
-fi
-
diff --git a/cpp/src/tests/restart_cluster b/cpp/src/tests/restart_cluster
deleted file mode 100755
index 5b48e619f6..0000000000
--- a/cpp/src/tests/restart_cluster
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/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.
-#
-
-# Re-start a cluster on the local host.
-
-srcdir=`dirname $0`
-$srcdir/stop_cluster
-exec $srcdir/start_cluster "$@"
-#!/bin/bash
-# Re-start a cluster on the local host.
-
-srcdir=`dirname $0`
-$srcdir/stop_cluster
-exec $srcdir/start_cluster "$@"
-#!/bin/bash
-# Re-start a cluster on the local host.
-
-srcdir=`dirname $0`
-$srcdir/stop_cluster
-exec $srcdir/start_cluster "$@"
diff --git a/cpp/src/tests/run_acl_tests b/cpp/src/tests/run_acl_tests
index 25241ad75e..ebe4cf8bdb 100755
--- a/cpp/src/tests/run_acl_tests
+++ b/cpp/src/tests/run_acl_tests
@@ -24,22 +24,26 @@ source ./test_env.sh
DATA_DIR=`pwd`/data_dir
DATA_DIRI=`pwd`/data_diri
DATA_DIRU=`pwd`/data_diru
+DATA_DIRQ=`pwd`/data_dirq
trap stop_brokers INT TERM QUIT
start_brokers() {
- ../qpidd --daemon --port 0 --no-module-dir --data-dir $DATA_DIR --load-module $ACL_LIB --acl-file policy.acl --auth no --log-to-file local.log > qpidd.port
+ ../qpidd --daemon --port 0 --no-module-dir --data-dir $DATA_DIR --load-module $ACL_LIB --acl-file policy.acl --auth no --log-to-file local.log > qpidd.port
LOCAL_PORT=`cat qpidd.port`
- ../qpidd --daemon --port 0 --no-module-dir --data-dir $DATA_DIRI --load-module $ACL_LIB --acl-file policy.acl --auth no --max-connections-per-ip 2 --log-to-file locali.log > qpiddi.port
+ ../qpidd --daemon --port 0 --no-module-dir --data-dir $DATA_DIRI --load-module $ACL_LIB --acl-file policy.acl --auth no --connection-limit-per-ip 2 --log-to-file locali.log > qpiddi.port
LOCAL_PORTI=`cat qpiddi.port`
- ../qpidd --daemon --port 0 --no-module-dir --data-dir $DATA_DIRU --load-module $ACL_LIB --acl-file policy.acl --auth no --max-connections-per-user 2 --log-to-file localu.log > qpiddu.port
+ ../qpidd --daemon --port 0 --no-module-dir --data-dir $DATA_DIRU --load-module $ACL_LIB --acl-file policy.acl --auth no --connection-limit-per-user 2 --log-to-file localu.log > qpiddu.port
LOCAL_PORTU=`cat qpiddu.port`
+ ../qpidd --daemon --port 0 --no-module-dir --data-dir $DATA_DIRQ --load-module $ACL_LIB --acl-file policy.acl --auth no --max-queues-per-user 2 --log-to-file localq.log > qpiddq.port
+ LOCAL_PORTQ=`cat qpiddq.port`
}
stop_brokers() {
$QPIDD_EXEC --no-module-dir -q --port $LOCAL_PORT
$QPIDD_EXEC --no-module-dir -q --port $LOCAL_PORTI
$QPIDD_EXEC --no-module-dir -q --port $LOCAL_PORTU
+ $QPIDD_EXEC --no-module-dir -q --port $LOCAL_PORTQ
}
test_loading_acl_from_absolute_path(){
@@ -59,20 +63,24 @@ if test -d ${PYTHON_DIR} ; then
rm -rf $DATA_DIR
rm -rf $DATA_DIRI
rm -rf $DATA_DIRU
+ rm -rf $DATA_DIRQ
mkdir -p $DATA_DIR
mkdir -p $DATA_DIRI
mkdir -p $DATA_DIRU
+ mkdir -p $DATA_DIRQ
cp $srcdir/policy.acl $DATA_DIR
cp $srcdir/policy.acl $DATA_DIRI
cp $srcdir/policy.acl $DATA_DIRU
+ cp $srcdir/policy.acl $DATA_DIRQ
start_brokers
- echo "Running acl tests using brokers on ports $LOCAL_PORT, $LOCAL_PORTI, and $LOCAL_PORTU"
- $QPID_PYTHON_TEST -b localhost:$LOCAL_PORT -m acl -Dport-i=$LOCAL_PORTI -Dport-u=$LOCAL_PORTU || EXITCODE=1
+ echo "Running acl tests using brokers on ports $LOCAL_PORT, $LOCAL_PORTI, $LOCAL_PORTU, and $LOCAL_PORTQ"
+ $QPID_PYTHON_TEST -b localhost:$LOCAL_PORT -m acl -Dport-i=$LOCAL_PORTI -Dport-u=$LOCAL_PORTU -Dport-q=$LOCAL_PORTQ || EXITCODE=1
stop_brokers || EXITCODE=1
test_loading_acl_from_absolute_path || EXITCODE=1
rm -rf $DATA_DIR
rm -rf $DATA_DIRI
rm -rf $DATA_DIRU
+ rm -rf $DATA_DIRQ
exit $EXITCODE
fi
diff --git a/cpp/src/tests/run_cluster_authentication_soak b/cpp/src/tests/run_cluster_authentication_soak
deleted file mode 100755
index 24befa28ba..0000000000
--- a/cpp/src/tests/run_cluster_authentication_soak
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /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.
-
-
-source ./test_env.sh
-source sasl_test_setup.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-with_ais_group ./cluster_authentication_soak 500
-
diff --git a/cpp/src/tests/run_cluster_authentication_test b/cpp/src/tests/run_cluster_authentication_test
deleted file mode 100755
index 844807a857..0000000000
--- a/cpp/src/tests/run_cluster_authentication_test
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /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.
-
-
-source ./test_env.sh
-source sasl_test_setup.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-with_ais_group ./cluster_authentication_soak
-
diff --git a/cpp/src/tests/run_cluster_test b/cpp/src/tests/run_cluster_test
deleted file mode 100755
index 11df3d63a3..0000000000
--- a/cpp/src/tests/run_cluster_test
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/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.
-#
-
-
-# Run the tests
-srcdir=`dirname $0`
-source cpg_check.sh
-cpg_enabled || exit 0
-with_ais_group $srcdir/run_test ./cluster_test
diff --git a/cpp/src/tests/run_cluster_tests b/cpp/src/tests/run_cluster_tests
deleted file mode 100755
index a5cea5ff6e..0000000000
--- a/cpp/src/tests/run_cluster_tests
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/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.
-#
-
-source ./test_env.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-
-test -x $QPID_PYTHON_TEST || { echo Skipping test, $QPID_PYTHON_TEST not found; exit 0; }
-
-# Delete old cluster test data
-OUTDIR=${OUTDIR:-brokertest.tmp}
-rm -rf $OUTDIR
-mkdir -p $OUTDIR
-
-# Ignore tests requiring a store by default.
-CLUSTER_TESTS_IGNORE=${CLUSTER_TESTS_IGNORE:--i cluster_tests.StoreTests.* -I $srcdir/cluster_tests.fail}
-CLUSTER_TESTS=${CLUSTER_TESTS:-$*}
-
-with_ais_group $QPID_PYTHON_TEST -DOUTDIR=$OUTDIR -m cluster_tests $CLUSTER_TESTS_IGNORE $CLUSTER_TESTS || exit 1
-rm -rf $OUTDIR
diff --git a/cpp/src/tests/run_failover_soak b/cpp/src/tests/run_failover_soak
deleted file mode 100755
index 2c56bf7d6b..0000000000
--- a/cpp/src/tests/run_failover_soak
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/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.
-#
-
-source ./test_env.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-host=127.0.0.1
-
-unset QPID_NO_MODULE_DIR # failover_soak uses --module-dir, dont want clash
-MODULES=${MODULES:-$moduledir}
-MESSAGES=${MESSAGES:-500000}
-REPORT_FREQUENCY=${REPORT_FREQUENCY:-20000}
-VERBOSITY=${VERBOSITY:-0}
-DURABILITY=${DURABILITY:-0}
-N_QUEUES=${N_QUEUES:-1}
-N_BROKERS=${N_BROKERS:-4}
-
-rm -f soak-*.log
-exec ./failover_soak $MODULES ./declare_queues ./replaying_sender ./resuming_receiver $MESSAGES $REPORT_FREQUENCY $VERBOSITY $DURABILITY $N_QUEUES $N_BROKERS
-
diff --git a/cpp/src/tests/run_federation_sys_tests b/cpp/src/tests/run_federation_sys_tests
index 76da176914..d9a9649c37 100755
--- a/cpp/src/tests/run_federation_sys_tests
+++ b/cpp/src/tests/run_federation_sys_tests
@@ -25,10 +25,6 @@ source ./test_env.sh
MODULENAME=federation_sys
-# Test for clustering
-source cpg_check.sh
-if cpg_enabled; then CLUSTERING_ENABLED=1; fi
-
# Test for long test
if [[ "$1" == "LONG_TEST" ]]; then
USE_LONG_TEST=1
@@ -42,11 +38,7 @@ if [ -z ${USE_LONG_TEST} ]; then
SKIPTESTS="-i federation_sys.A_Long* -i federation_sys.B_Long* ${SKIPTESTS}"
fi
echo "WARNING: Tests using persistence will be ignored."
-if [ -z ${CLUSTERING_ENABLED} ]; then
- SKIPTESTS="${SKIPTESTS} -i federation_sys.C_* -i federation_sys.D_*"
-elif [ -z ${USE_LONG_TEST} ]; then
- SKIPTESTS="${SKIPTESTS} -i federation_sys.C_Long* -i federation_sys.D_Long*"
-fi
+SKIPTESTS="${SKIPTESTS} -i federation_sys.C_* -i federation_sys.D_*"
start_brokers() {
start_broker() {
@@ -56,35 +48,21 @@ start_brokers() {
}
start_broker "" LOCAL_PORT
start_broker "" REMOTE_PORT
- if [ -n "${CLUSTERING_ENABLED}" ]; then
- start_broker "--load-module ${CLUSTER_LIB} --cluster-name test-cluster-1" CLUSTER_C1_1
- start_broker "--load-module ${CLUSTER_LIB} --cluster-name test-cluster-1" CLUSTER_C1_2
- start_broker "--load-module ${CLUSTER_LIB} --cluster-name test-cluster-2" CLUSTER_C2_1
- start_broker "--load-module ${CLUSTER_LIB} --cluster-name test-cluster-2" CLUSTER_C2_2
- fi
rm qpidd.port
}
stop_brokers() {
${QPIDD_EXEC} -q --port ${LOCAL_PORT}
${QPIDD_EXEC} -q --port ${REMOTE_PORT}
- if [ -n "${CLUSTERING_ENABLED}" ]; then
- ${QPID_CLUSTER_EXEC} --all-stop --force localhost:${CLUSTER_C1_1}
- ${QPID_CLUSTER_EXEC} --all-stop --force localhost:${CLUSTER_C2_1}
- fi
}
if test -d ${PYTHON_DIR} ; then
start_brokers
- if [ -z ${CLUSTERING_ENABLED} ]; then
- echo "Running federation tests using brokers on local port ${LOCAL_PORT}, remote port ${REMOTE_PORT} (NOTE: clustering is DISABLED)"
- else
- echo "Running federation tests using brokers on local port ${LOCAL_PORT}, remote port ${REMOTE_PORT}, local cluster nodes ${CLUSTER_C1_1} ${CLUSTER_C1_2}, remote cluster nodes ${CLUSTER_C2_1} ${CLUSTER_C2_2}"
- fi
+ echo "Running federation tests using brokers on local port ${LOCAL_PORT}, remote port ${REMOTE_PORT} (NOTE: clustering is DISABLED)"
if [ -z ${USE_LONG_TEST} ]; then
echo "NOTE: To run a full set of federation system tests, use \"make check-long\". To test with persistence, run the store version of this script."
fi
- ${QPID_PYTHON_TEST} -m ${MODULENAME} ${SKIPTESTS} -b localhost:${REMOTE_PORT} -Dlocal-port=${LOCAL_PORT} -Dremote-port=${REMOTE_PORT} -Dlocal-cluster-ports="${CLUSTER_C1_1} ${CLUSTER_C1_2}" -Dremote-cluster-ports="${CLUSTER_C2_1} ${CLUSTER_C2_2}" $@
+ ${QPID_PYTHON_TEST} -m ${MODULENAME} ${SKIPTESTS} -b localhost:${REMOTE_PORT} -Dlocal-port=${LOCAL_PORT} -Dremote-port=${REMOTE_PORT} $@
RETCODE=$?
stop_brokers
if test x${RETCODE} != x0; then
diff --git a/cpp/src/tests/run_long_cluster_tests b/cpp/src/tests/run_long_cluster_tests
deleted file mode 100755
index 5dce0be585..0000000000
--- a/cpp/src/tests/run_long_cluster_tests
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/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.
-#
-
-srcdir=`dirname $0`
-$srcdir/run_cluster_tests 'cluster_tests.LongTests.*' -DDURATION=4
-
diff --git a/cpp/src/tests/sasl_fed_ex b/cpp/src/tests/sasl_fed_ex
index cc5b310067..4ea61c5a2a 100755
--- a/cpp/src/tests/sasl_fed_ex
+++ b/cpp/src/tests/sasl_fed_ex
@@ -34,17 +34,11 @@ then
echo
# These are the four different ways of creating links ( or routes+links )
# that the qpid-route command provides.
- echo "Usage: ${script_name} dynamic|link|queue|route [cluster]"
+ echo "Usage: ${script_name} dynamic|link|queue|route"
echo
exit 1
fi
-# Has the user told us to do clustering ? -----------
-clustering_flag=
-if [ $# -eq "2" ] && [ "$2" == "cluster" ]; then
- clustering_flag=true
-fi
-
qpid_route_method=$1
# Debugging print. --------------------------
@@ -128,15 +122,7 @@ DST_TCP_PORT=5807
SRC_TCP_PORT_2=5802
DST_TCP_PORT_2=5803
-CLUSTER_NAME_SUFFIX=`hostname | tr '.' ' ' | awk '{print $1}'`
-CLUSTER_1_NAME=sasl_fed_ex_cluster_1_${CLUSTER_NAME_SUFFIX}
-CLUSTER_2_NAME=sasl_fed_ex_cluster_2_${CLUSTER_NAME_SUFFIX}
-
-print "CLUSTER_1_NAME == ${CLUSTER_1_NAME}"
-print "CLUSTER_2_NAME == ${CLUSTER_2_NAME}"
-
SSL_LIB=${moduledir}/ssl.so
-CLUSTER_LIB=${moduledir}/cluster.so
export QPID_SSL_CERT_NAME=${TEST_HOSTNAME}
@@ -183,80 +169,26 @@ COMMON_BROKER_OPTIONS=" \
function start_brokers {
- if [ $1 ]; then
- # clustered ----------------------------------------
- print "Starting SRC cluster"
-
- print " src broker 1"
- $QPIDD_EXEC \
- --port=${SRC_TCP_PORT} \
- --ssl-port ${SRC_SSL_PORT} \
- ${COMMON_BROKER_OPTIONS} \
- --load-module ${CLUSTER_LIB} \
- --cluster-name ${CLUSTER_1_NAME} \
- --log-to-file $tmp_root/qpidd_src.log 2> /dev/null
-
- broker_ports[0]=${SRC_TCP_PORT}
-
- print " src broker 2"
- $QPIDD_EXEC \
- --port=${SRC_TCP_PORT_2} \
- --ssl-port ${SRC_SSL_PORT_2} \
- ${COMMON_BROKER_OPTIONS} \
- --load-module ${CLUSTER_LIB} \
- --cluster-name ${CLUSTER_1_NAME} \
- --log-to-file $tmp_root/qpidd_src_2.log 2> /dev/null
-
- broker_ports[1]=${SRC_TCP_PORT_2}
-
-
- print "Starting DST cluster"
-
- print " dst broker 1"
- $QPIDD_EXEC \
- --port=${DST_TCP_PORT} \
- --ssl-port ${DST_SSL_PORT} \
- ${COMMON_BROKER_OPTIONS} \
- --load-module ${CLUSTER_LIB} \
- --cluster-name ${CLUSTER_2_NAME} \
- --log-to-file $tmp_root/qpidd_dst.log 2> /dev/null
-
- broker_ports[2]=${DST_TCP_PORT}
-
- print " dst broker 2"
- $QPIDD_EXEC \
- --port=${DST_TCP_PORT_2} \
- --ssl-port ${DST_SSL_PORT_2} \
- ${COMMON_BROKER_OPTIONS} \
- --load-module ${CLUSTER_LIB} \
- --cluster-name ${CLUSTER_2_NAME} \
- --log-to-file $tmp_root/qpidd_dst_2.log 2> /dev/null
-
- broker_ports[3]=${DST_TCP_PORT_2}
-
- else
# vanilla brokers --------------------------------
print "Starting SRC broker"
$QPIDD_EXEC \
- --port=${SRC_TCP_PORT} \
- --ssl-port ${SRC_SSL_PORT} \
- ${COMMON_BROKER_OPTIONS} \
- --log-to-file $tmp_root/qpidd_src.log 2> /dev/null
+ --port=${SRC_TCP_PORT} \
+ --ssl-port ${SRC_SSL_PORT} \
+ ${COMMON_BROKER_OPTIONS} \
+ --log-to-file $tmp_root/qpidd_src.log 2> /dev/null
broker_ports[0]=${SRC_TCP_PORT}
print "Starting DST broker"
$QPIDD_EXEC \
- --port=${DST_TCP_PORT} \
- --ssl-port ${DST_SSL_PORT} \
- ${COMMON_BROKER_OPTIONS} \
- --log-to-file $tmp_root/qpidd_dst.log 2> /dev/null
+ --port=${DST_TCP_PORT} \
+ --ssl-port ${DST_SSL_PORT} \
+ ${COMMON_BROKER_OPTIONS} \
+ --log-to-file $tmp_root/qpidd_dst.log 2> /dev/null
broker_ports[1]=${DST_TCP_PORT}
- fi
}
-
function halt_brokers {
n_brokers=${#broker_ports[@]}
print "Halting ${n_brokers} brokers."
@@ -270,7 +202,7 @@ function halt_brokers {
}
-start_brokers $clustering_flag
+start_brokers
# I am not randomizing these names, because this test creates its own brokers.
@@ -329,9 +261,7 @@ fi
# to avoid false negatives.
sleep 5
-# This should work the same whether or not we are running a clustered test.
-# In the case of clustered tests, the status is not printed by qpid_route.
-# So in either case, I will look only at the transport field, which should be "ssl".
+# Look only at the transport field, which should be "ssl".
print "check the link"
link_status=$($QPID_ROUTE_EXEC link list localhost:${DST_TCP_PORT} | tail -1 | awk '{print $3}')
diff --git a/cpp/src/tests/sasl_fed_ex_dynamic_cluster b/cpp/src/tests/sasl_fed_ex_dynamic_cluster
deleted file mode 100755
index fd6b72a4f2..0000000000
--- a/cpp/src/tests/sasl_fed_ex_dynamic_cluster
+++ /dev/null
@@ -1,30 +0,0 @@
-#! /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.
-#
-
-
-source ./test_env.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-
-with_ais_group ${srcdir}/sasl_fed_ex dynamic cluster
-
-
diff --git a/cpp/src/tests/sasl_fed_ex_link_cluster b/cpp/src/tests/sasl_fed_ex_link_cluster
deleted file mode 100755
index 34b2aa4a5f..0000000000
--- a/cpp/src/tests/sasl_fed_ex_link_cluster
+++ /dev/null
@@ -1,29 +0,0 @@
-#! /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.
-#
-
-
-source ./test_env.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-with_ais_group ${srcdir}/sasl_fed_ex link cluster
-
-
diff --git a/cpp/src/tests/sasl_fed_ex_queue_cluster b/cpp/src/tests/sasl_fed_ex_queue_cluster
deleted file mode 100755
index 14f36f6fc4..0000000000
--- a/cpp/src/tests/sasl_fed_ex_queue_cluster
+++ /dev/null
@@ -1,29 +0,0 @@
-#! /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.
-#
-
-
-source ./test_env.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-with_ais_group ${srcdir}/sasl_fed_ex queue cluster
-
-
diff --git a/cpp/src/tests/sasl_fed_ex_route_cluster b/cpp/src/tests/sasl_fed_ex_route_cluster
deleted file mode 100755
index 756476056e..0000000000
--- a/cpp/src/tests/sasl_fed_ex_route_cluster
+++ /dev/null
@@ -1,29 +0,0 @@
-#! /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.
-#
-
-
-source ./test_env.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-with_ais_group ${srcdir}/sasl_fed_ex route cluster
-
-
diff --git a/cpp/src/tests/ssl_test b/cpp/src/tests/ssl_test
index 19a316a483..89aaf44af0 100755
--- a/cpp/src/tests/ssl_test
+++ b/cpp/src/tests/ssl_test
@@ -193,29 +193,3 @@ echo "Running SSL/TCP mux test on random port $PORT"
./qpid-perftest --count ${COUNT} --port ${PORT} -P tcp -b $TEST_HOSTNAME --summary || error "TCP connection failed!"
stop_brokers
-
-test -z $CLUSTER_LIB && exit 0 # Exit if cluster not supported.
-
-## Test failover in a cluster using SSL only
-source cpg_check.sh
-cpg_enabled || exit 0
-
-PORT1=`pick_port`; ssl_cluster_broker $PORT1
-echo "Running SSL cluster broker on port $PORT1"
-
-PORT2=`pick_port`; ssl_cluster_broker $PORT2
-echo "Running SSL cluster broker on port $PORT2"
-
-# Pipe receive output to uniq to remove duplicates
-./qpid-receive --connection-options "{reconnect:true, reconnect-timeout:5}" --failover-updates -b amqp:ssl:$TEST_HOSTNAME:$PORT1 -a "foo;{create:always}" -f | uniq > ssl_test_receive.tmp &
-./qpid-send -b amqp:ssl:$TEST_HOSTNAME:$PORT2 --content-string=one -a "foo;{create:always}"
-
-stop_broker 0 # Kill broker 1 - receiver should fail-over.
-echo "Killed SSL cluster broker on port $PORT1"
-
-./qpid-send -b amqp:ssl:$TEST_HOSTNAME:$PORT2 --content-string=two -a "foo;{create:always}" --send-eos 1
-wait # Wait for qpid-receive
-{ echo one; echo two; } > ssl_test_receive.cmp
-diff ssl_test_receive.tmp ssl_test_receive.cmp || { echo "Failover failed"; exit 1; }
-rm -f ssl_test_receive.*
-
diff --git a/cpp/src/tests/start_cluster b/cpp/src/tests/start_cluster
deleted file mode 100755
index 78fd104d9c..0000000000
--- a/cpp/src/tests/start_cluster
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/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.
-#
-
-# Start a cluster of brokers on local host, put the list of ports for cluster members in cluster.ports
-#
-
-# Execute command with the ais group set.
-source ./test_env.sh
-source cpg_check.sh
-cpg_enabled || exit 0
-
-rm -f cluster*.log cluster.ports qpidd.port
-
-SIZE=${1:-3}; shift
-CLUSTER=$HOSTNAME.$$
-OPTS="-d --no-module-dir --load-module $CLUSTER_LIB --cluster-name=$CLUSTER --auth=no --log-enable notice+ --log-enable debug+:cluster $@"
-
-for (( i=0; i<SIZE; ++i )); do
- DDIR=`mktemp -d /tmp/start_cluster.XXXXXXXXXX`
- PORT=`with_ais_group ../qpidd -p0 --log-to-file=cluster$i.log $OPTS --data-dir=$DDIR` || exit 1
- echo $PORT >> cluster.ports
-done
-
-head -n 1 cluster.ports > qpidd.port # First member's port for tests.
-
diff --git a/cpp/src/tests/start_cluster_hosts b/cpp/src/tests/start_cluster_hosts
deleted file mode 100755
index 778b4248da..0000000000
--- a/cpp/src/tests/start_cluster_hosts
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/bin/sh
-
-#
-# 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.
-#
-
-#
-# Start a cluster of brokers on local host, put the list of host port addresses
-# in cluster.ports
-#
-# Arguments: [-k] [-p port] HOST [HOST...]
-# -p port to start broker on, can be 0. Actual ports recorded in cluster.addr.
-# -k kill any qpidd processes owned by this user before starting.
-#
-# Start a broker on each named host. Name a host twice to start multiple brokers.
-#
-# You must be able to ssh to each host and be in group ais.
-# $QPIDD must be executable on each host.
-# Logs go to syslog on each host, with a unique prefix per broker.
-#
-
-QPIDD=${QPIDD:-$PWD/../qpidd}
-LIBQPIDCLUSTER=${LIBQPIDCLUSTER:-$PWD/../.libs/cluster.so}
-NAME=$USER # User name is default cluster name.
-RESTART=NO
-
-while getopts "kp:n:q:r" ARG ; do
- case $ARG in
- k) KILL=yes ;;
- p) PORT="$OPTARG" ;;
- n) NAME=$OPTARG ;;
- q) QPIDD=$OPTARG ;;
- l) LIBQPIDCLUSTER=$OPTARG ;;
- r) RESTART=yes ;;
- *) echo "Error parsing options: $ARG"; exit 1 ;;
- esac
-done
-shift `expr $OPTIND - 1`
-test -n "$PORT" && PORTOPT="-p $PORT"
-test "$KILL" = yes && KILL="$QPIDD --no-module-dir -q $PORTOPT ;"
-CLUSTER=${*:-$CLUSTER} # Use args or env
-test -z "$CLUSTER" && { echo Must specify at least one host; exit 1; }
-
-
-OPTS="-d $PORTOPT --load-module $LIBQPIDCLUSTER --cluster-name=$NAME --no-data-dir --auth=no --log-to-syslog --log-enable=info+"
-
-num=0
-for h in $CLUSTER; do
- num=`expr $num + 1` # Give a unique log prefix to each node.
- cmd="$KILL $QPIDD $OPTS --log-prefix $num.$h"
- out=`echo "$cmd" | ssh $h newgrp ais` || { echo == $h error: $out ; exit 1; }
- if [ "$PORT" = 0 ] ; then p=$out; else p=$PORT; fi
- echo "$h $p"
-done
-
diff --git a/cpp/src/tests/stop_cluster b/cpp/src/tests/stop_cluster
deleted file mode 100755
index 02436c60b7..0000000000
--- a/cpp/src/tests/stop_cluster
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/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.
-#
-
-# Stop brokers on ports listed in cluster.ports
-
-PORTS=`cat cluster.ports`
-for PORT in $PORTS ; do
- $QPIDD_EXEC --no-module-dir -qp $PORT || ERROR="$ERROR $PORT"
-done
-rm -f cluster.ports qpidd.port
-
-if [ -n "$ERROR" ]; then
- echo "Errors stopping brokers on ports: $ERROR"
- exit 1
-fi
diff --git a/cpp/src/tests/storePerftools/asyncPerf/PerfTest.cpp b/cpp/src/tests/storePerftools/asyncPerf/PerfTest.cpp
index 85dd7fa715..7d97ded8b9 100644
--- a/cpp/src/tests/storePerftools/asyncPerf/PerfTest.cpp
+++ b/cpp/src/tests/storePerftools/asyncPerf/PerfTest.cpp
@@ -157,7 +157,7 @@ PerfTest::destroyQueues() {
int
runPerfTest(int argc, char** argv) {
// Load async store module
- qpid::tryShlib ("asyncStore.so", false);
+ qpid::tryShlib ("asyncStore.so");
qpid::CommonOptions co;
qpid::asyncStore::AsyncStoreOptions aso;
diff --git a/cpp/src/tests/test_env.ps1.in b/cpp/src/tests/test_env.ps1.in
index 60ba4305a5..5fa3a0ac31 100644
--- a/cpp/src/tests/test_env.ps1.in
+++ b/cpp/src/tests/test_env.ps1.in
@@ -62,8 +62,6 @@ $env:TEST_STORE_LIB="$testmoduledir\test_store.so"
#exportmodule() { test -f $moduledir/$2 && eval "export $1=$moduledir/$2"; }
#exportmodule ACL_LIB acl.so
#exportmodule CLUSTER_LIB cluster.so
-#exportmodule REPLICATING_LISTENER_LIB replicating_listener.so
-#exportmodule REPLICATION_EXCHANGE_LIB replication_exchange.so
#exportmodule SSLCONNECTOR_LIB sslconnector.so
#exportmodule SSL_LIB ssl.so
#exportmodule WATCHDOG_LIB watchdog.so
diff --git a/cpp/src/tests/test_env.sh.in b/cpp/src/tests/test_env.sh.in
index cee36843ae..76e88283ed 100644
--- a/cpp/src/tests/test_env.sh.in
+++ b/cpp/src/tests/test_env.sh.in
@@ -43,7 +43,6 @@ export PYTHON_COMMANDS=$QPID_TOOLS/src/py
export PYTHONPATH=$srcdir:$PYTHON_DIR:$PYTHON_COMMANDS:$QPID_TESTS_PY:$QMF_LIB:$PYTHONPATH
export QPID_CONFIG_EXEC=$PYTHON_COMMANDS/qpid-config
export QPID_ROUTE_EXEC=$PYTHON_COMMANDS/qpid-route
-export QPID_CLUSTER_EXEC=$PYTHON_COMMANDS/qpid-cluster
export QPID_HA_EXEC=$PYTHON_COMMANDS/qpid-ha
# Executables
@@ -63,10 +62,7 @@ export TEST_STORE_LIB=$testmoduledir/test_store.so
exportmodule() { test -f $moduledir/$2 && eval "export $1=$moduledir/$2"; }
exportmodule ACL_LIB acl.so
-exportmodule CLUSTER_LIB cluster.so
exportmodule HA_LIB ha.so
-exportmodule REPLICATING_LISTENER_LIB replicating_listener.so
-exportmodule REPLICATION_EXCHANGE_LIB replication_exchange.so
exportmodule SSLCONNECTOR_LIB sslconnector.so
exportmodule SSL_LIB ssl.so
exportmodule WATCHDOG_LIB watchdog.so
diff --git a/cpp/src/tests/test_store.cpp b/cpp/src/tests/test_store.cpp
index e6bc55c033..46b7ea1196 100644
--- a/cpp/src/tests/test_store.cpp
+++ b/cpp/src/tests/test_store.cpp
@@ -37,17 +37,13 @@
//#include "qpid/broker/amqp_0_10/MessageTransfer.h"
//#include "qpid/framing/AMQFrame.h"
//#include "qpid/log/Statement.h"
+//#include "qpid/sys/Thread.h"
//#include "qpid/Plugin.h"
//#include "qpid/Options.h"
//#include <boost/cast.hpp>
//#include <boost/lexical_cast.hpp>
//#include <memory>
//#include <fstream>
-//
-//using namespace qpid;
-//using namespace broker;
-//using namespace std;
-//using namespace qpid::sys;
namespace qpid {
namespace tests {
diff --git a/cpp/src/tests/testagent.mk b/cpp/src/tests/testagent.mk
index 25cf43d71e..0492f3e3bb 100644
--- a/cpp/src/tests/testagent.mk
+++ b/cpp/src/tests/testagent.mk
@@ -46,6 +46,6 @@ testagent-testagent.$(OBJEXT): $(TESTAGENT_GEN_SRC)
qpidexectest_PROGRAMS+=testagent
testagent_CXXFLAGS=$(CXXFLAGS) -Itestagent_gen
testagent_SOURCES=testagent.cpp $(TESTAGENT_GEN_SRC)
-testagent_LDADD=$(top_builddir)/src/libqmf.la
+testagent_LDADD=$(top_builddir)/src/libqmf.la $(top_builddir)/src/libqpidcommon.la $(top_builddir)/src/libqpidtypes.la $(top_builddir)/src/libqpidclient.la
EXTRA_DIST+=testagent.xml
diff --git a/cpp/src/tests/testlib.py b/cpp/src/tests/testlib.py
deleted file mode 100644
index 71ad59e5c1..0000000000
--- a/cpp/src/tests/testlib.py
+++ /dev/null
@@ -1,766 +0,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.
-#
-
-#
-# Support library for qpid python tests.
-#
-
-import os, re, signal, subprocess, time, unittest
-
-class TestBase(unittest.TestCase):
- """
- Base class for qpid tests. Provides broker start/stop/kill methods
- """
-
- """
- The following environment vars control if and how the test is run, and determine where many of the helper
- executables/libs are to be found.
- """
- _storeLib = os.getenv("STORE_LIB")
- _storeEnable = _storeLib != None # Must be True for durability to be enabled during the test
- _qpiddExec = os.getenv("QPIDD_EXEC", "/usr/sbin/qpidd")
- _tempStoreDir = os.path.abspath(os.getenv("TMP_DATA_DIR", "/tmp/qpid"))
-
- """Global message counter ensures unique messages"""
- _msgCnt = 0
-
- # --- Helper functions for parameter handling ---
-
- def _paramBool(self, key, val, keyOnly = False):
- if val == None:
- return ""
- if keyOnly:
- if val:
- return " --%s" % key
- else:
- return ""
- else:
- if val:
- return " --%s yes" % key
- else:
- return " --%s no" % key
-
- # --- Helper functions for message creation ---
-
- def _makeMessage(self, msgSize):
- msg = "Message-%04d" % self._msgCnt
- self._msgCnt = self._msgCnt + 1
- msgLen = len(msg)
- if msgSize > msgLen:
- for i in range(msgLen, msgSize):
- if i == msgLen:
- msg += "-"
- else:
- msg += chr(ord('a') + (i % 26))
- return msg
-
- def _makeMessageList(self, numMsgs, msgSize):
- if msgSize == None:
- msgSize = 12
- msgs = ""
- for m in range(0, numMsgs):
- msgs += "%s\n" % self._makeMessage(msgSize)
- return msgs
-
- # --- Starting and stopping a broker ---
-
- def startBroker(self, qpiddArgs, logFile = None):
- """Start a single broker daemon, returns tuple (pid, port)"""
- if self._qpiddExec == None:
- raise Exception("Environment variable QPIDD is not set")
- cmd = "%s --daemon --port=0 %s" % (self._qpiddExec, qpiddArgs)
- portStr = os.popen(cmd).read()
- if len(portStr) == 0:
- err = "Broker daemon startup failed."
- if logFile != None:
- err += " See log file %s" % logFile
- raise Exception(err)
- port = int(portStr)
- pidStr = os.popen("%s -p %d -c" % (self._qpiddExec, port)).read()
- try:
- pid = int(pidStr)
- except:
- raise Exception("Unable to get pid: \"%s -p %d -c\" returned %s" % (self._qpiddExec, port, pidStr))
- #print "started broker: pid=%d, port=%d args: %s" % (pid, port, qpiddArgs)
- return (pid, port)
-
- def killBroker(self, nodeTuple, ignoreFailures = False):
- """Kill a broker using kill -9"""
- try:
- os.kill(nodeTuple[self.PID], signal.SIGKILL)
- try:
- os.waitpid(nodeTuple[self.PID], 0)
- except:
- pass
- #print "killed broker: port=%d pid=%d" % (nodeTuple[self.PORT], nodeTuple[self.PID])
- except:
- if ignoreFailures:
- print "WARNING: killBroker (port=%d pid=%d) failed - ignoring." % (nodeTuple[self.PORT], nodeTuple[self.PID])
- else:
- raise
-
- def stopBroker(self, nodeTuple, ignoreFailures = False):
- """Stop a broker using qpidd -q"""
- try:
- ret = os.spawnl(os.P_WAIT, self._qpiddExec, self._qpiddExec, "--port=%d" % nodeTuple[self.PORT], "--quit", "--no-module-dir")
- if ret != 0:
- raise Exception("stopBroker(): port=%d: qpidd -q returned %d" % (nodeTuple[self.PORT], ret))
- try:
- os.waitpid(nodeTuple[self.PID], 0)
- except:
- pass
- #print "stopped broker: port=%d pid=%d" % (nodeTuple[self.PORT], nodeTuple[self.PID])
- except:
- if ignoreFailures:
- print "WARNING: stopBroker (port=%d pid=%d) failed - ignoring." % (nodeTuple[self.PORT], nodeTuple[self.PID])
- else:
- raise
-
-
-
-class TestBaseCluster(TestBase):
- """
- Base class for cluster tests. Provides methods for starting and stopping clusters and cluster nodes.
- """
-
- """
- The following environment vars control if and how the test is run, and determine where many of the helper
- executables/libs are to be found.
- """
- _clusterLib = os.getenv("CLUSTER_LIB")
- _clusterTestEnable = _clusterLib != None # Must be True for these cluster tests to run
- _xmlLib = os.getenv("XML_LIB")
- _xmlEnable = _xmlLib != None
- _qpidConfigExec = os.getenv("QPID_CONFIG_EXEC", "/usr/bin/qpid-config")
- _qpidRouteExec = os.getenv("QPID_ROUTE_EXEC", "/usr/bin/qpid-route")
- _receiverExec = os.getenv("RECEIVER_EXEC", "/usr/libexec/qpid/test/receiver")
- _senderExec = os.getenv("SENDER_EXEC", "/usr/libexec/qpid/test/sender")
-
-
- """
- _clusterDict is a dictionary of clusters:
- key = cluster name (string)
- val = dictionary of node numbers:
- key = integer node number
- val = tuple containing (pid, port)
- For example, two clusters "TestCluster0" and "TestCluster1" containing several nodes would look as follows:
- {"TestCluster0": {0: (pid0-0, port0-0), 1: (pid0-1, port0-1), ...}, "TestCluster1": {0: (pid1-0, port1-0), 1: (pid1-1, port1-1), ...}}
- where pidm-n and portm-n are the int pid and port for TestCluster m node n respectively.
- """
- _clusterDict = {}
-
- """Index for (pid, port) tuple"""
- PID = 0
- PORT = 1
-
- def run(self, res):
- """ Skip cluster testing if env var RUN_CLUSTER_TESTS is not defined."""
- if not self._clusterTestEnable:
- return
- unittest.TestCase.run(self, res)
-
- # --- Private helper / convenience functions ---
-
- def _checkPids(self, clusterName = None):
- for pid, port in self.getTupleList():
- try:
- os.kill(pid, 0)
- except:
- raise Exception("_checkPids(): Broker with pid %d expected but does not exist! (crashed?)" % pid)
-
-
- # --- Starting cluster node(s) ---
-
- def createClusterNode(self, nodeNumber, clusterName):
- """Create a node and add it to the named cluster"""
- if self._tempStoreDir == None:
- raise Exception("Environment variable TMP_DATA_DIR is not set")
- if self._clusterLib == None:
- raise Exception("Environment variable LIBCLUSTER is not set")
- name = "%s-%d" % (clusterName, nodeNumber)
- dataDir = os.path.join(self._tempStoreDir, "cluster", name)
- logFile = "%s.log" % dataDir
- args = "--no-module-dir --load-module=%s --data-dir=%s --cluster-name=%s --auth=no --log-enable=notice+ --log-to-file=%s" % \
- (self._clusterLib, dataDir, clusterName, logFile)
- if self._storeEnable:
- if self._storeLib == None:
- raise Exception("Environment variable LIBSTORE is not set")
- args += " --load-module %s" % self._storeLib
- self._clusterDict[clusterName][nodeNumber] = self.startBroker(args, logFile)
-
- def createCluster(self, clusterName, numberNodes = 0):
- """Create a cluster containing an initial number of nodes"""
- self._clusterDict[clusterName] = {}
- for n in range(0, numberNodes):
- self.createClusterNode(n, clusterName)
-
- def waitForNodes(self, clusterName):
- """Wait for all nodes to become active (ie finish cluster sync)"""
- # TODO - connect to each known node in cluster
- # Until this is done, wait a bit (hack)
- time.sleep(1)
-
- # --- Cluster and node status ---
-
- def getTupleList(self, clusterName = None):
- """Get list of (pid, port) tuples of all known cluster brokers"""
- tList = []
- for c, l in self._clusterDict.iteritems():
- if clusterName == None or c == clusterName:
- for t in l.itervalues():
- tList.append(t)
- return tList
-
- def getNumBrokers(self):
- """Get total number of brokers in all known clusters"""
- return len(self.getTupleList())
-
- def checkNumBrokers(self, expected = None, checkPids = True):
- """Check that the total number of brokers in all known clusters is the expected value"""
- if expected != None and self.getNumBrokers() != expected:
- raise Exception("Unexpected number of brokers: expected %d, found %d" % (expected, self.getNumBrokers()))
- if checkPids:
- self._checkPids()
-
- def getClusterTupleList(self, clusterName):
- """Get list of (pid, port) tuples of all nodes in named cluster"""
- if clusterName in self._clusterDict:
- return self._clusterDict[clusterName].values()
- return []
-
- def getNumClusterBrokers(self, clusterName):
- """Get total number of brokers in named cluster"""
- return len(self.getClusterTupleList(clusterName))
-
- def getNodeTuple(self, nodeNumber, clusterName):
- """Get the (pid, port) tuple for the given cluster node"""
- return self._clusterDict[clusterName][nodeNumber]
-
- def checkNumClusterBrokers(self, clusterName, expected = None, checkPids = True, waitForNodes = True):
- """Check that the total number of brokers in the named cluster is the expected value"""
- if expected != None and self.getNumClusterBrokers(clusterName) != expected:
- raise Exception("Unexpected number of brokers in cluster %s: expected %d, found %d" % \
- (clusterName, expected, self.getNumClusterBrokers(clusterName)))
- if checkPids:
- self._checkPids(clusterName)
- if waitForNodes:
- self.waitForNodes(clusterName)
-
- def clusterExists(self, clusterName):
- """ Return True if clusterName exists, False otherwise"""
- return clusterName in self._clusterDict.keys()
-
- def clusterNodeExists(self, clusterName, nodeNumber):
- """ Return True if nodeNumber in clusterName exists, False otherwise"""
- if clusterName in self._clusterDict.keys():
- return nodeNumber in self._clusterDict[nodeName]
- return False
-
- def createCheckCluster(self, clusterName, size):
- """Create a cluster using the given name and size, then check the number of brokers"""
- self.createCluster(clusterName, size)
- self.checkNumClusterBrokers(clusterName, size)
-
- # --- Kill cluster nodes using signal 9 ---
-
- def killNode(self, nodeNumber, clusterName, updateDict = True, ignoreFailures = False):
- """Kill the given node in the named cluster using kill -9"""
- self.killBroker(self.getNodeTuple(nodeNumber, clusterName), ignoreFailures)
- if updateDict:
- del(self._clusterDict[clusterName][nodeNumber])
-
- def killCluster(self, clusterName, updateDict = True, ignoreFailures = False):
- """Kill all nodes in the named cluster"""
- for n in self._clusterDict[clusterName].iterkeys():
- self.killNode(n, clusterName, False, ignoreFailures)
- if updateDict:
- del(self._clusterDict[clusterName])
-
- def killClusterCheck(self, clusterName):
- """Kill the named cluster and check that the name is removed from the cluster dictionary"""
- self.killCluster(clusterName)
- if self.clusterExists(clusterName):
- raise Exception("Unable to kill cluster %s; %d nodes still exist" % \
- (clusterName, self.getNumClusterBrokers(clusterName)))
-
- def killAllClusters(self, ignoreFailures = False):
- """Kill all known clusters"""
- for n in self._clusterDict.iterkeys():
- self.killCluster(n, False, ignoreFailures)
- self._clusterDict.clear()
-
- def killAllClustersCheck(self, ignoreFailures = False):
- """Kill all known clusters and check that the cluster dictionary is empty"""
- self.killAllClusters(ignoreFailures)
- self.checkNumBrokers(0)
-
- # --- Stop cluster nodes using qpidd -q ---
-
- def stopNode(self, nodeNumber, clusterName, updateDict = True, ignoreFailures = False):
- """Stop the given node in the named cluster using qpidd -q"""
- self.stopBroker(self.getNodeTuple(nodeNumber, clusterName), ignoreFailures)
- if updateDict:
- del(self._clusterDict[clusterName][nodeNumber])
-
- def stopAllClusters(self, ignoreFailures = False):
- """Stop all known clusters"""
- for n in self._clusterDict.iterkeys():
- self.stopCluster(n, False, ignoreFailures)
- self._clusterDict.clear()
-
-
- def stopCluster(self, clusterName, updateDict = True, ignoreFailures = False):
- """Stop all nodes in the named cluster"""
- for n in self._clusterDict[clusterName].iterkeys():
- self.stopNode(n, clusterName, False, ignoreFailures)
- if updateDict:
- del(self._clusterDict[clusterName])
-
- def stopCheckCluster(self, clusterName, ignoreFailures = False):
- """Stop the named cluster and check that the name is removed from the cluster dictionary"""
- self.stopCluster(clusterName, True, ignoreFailures)
- if self.clusterExists(clusterName):
- raise Exception("Unable to kill cluster %s; %d nodes still exist" % (clusterName, self.getNumClusterBrokers(clusterName)))
-
- def stopAllCheck(self, ignoreFailures = False):
- """Kill all known clusters and check that the cluster dictionary is empty"""
- self.stopAllClusters()
- self.checkNumBrokers(0)
-
- # --- qpid-config functions ---
-
- def _qpidConfig(self, nodeNumber, clusterName, action):
- """Configure some aspect of a qpid broker using the qpid_config executable"""
- port = self.getNodeTuple(nodeNumber, clusterName)[self.PORT]
- #print "%s -b localhost:%d %s" % (self._qpidConfigExec, port, action)
- ret = os.spawnl(os.P_WAIT, self._qpidConfigExec, self._qpidConfigExec, "-b", "localhost:%d" % port, *action.split())
- if ret != 0:
- raise Exception("_qpidConfig(): cluster=\"%s\" nodeNumber=%d port=%d action=\"%s\" returned %d" % \
- (clusterName, nodeNumber, port, action, ret))
-
- def addExchange(self, nodeNumber, clusterName, exchangeType, exchangeName, durable = False, sequence = False, \
- ive = False):
- """Add a named exchange."""
- action = "add exchange %s %s" % (exchangeType, exchangeName)
- action += self._paramBool("durable", durable, True)
- action += self._paramBool("sequence", sequence, True)
- action += self._paramBool("ive", ive, True)
- self._qpidConfig(nodeNumber, clusterName, action)
-
- def deleteExchange(self, nodeNumber, clusterName, exchangeName):
- """Delete a named exchange"""
- self._qpidConfig(nodeNumber, clusterName, "del exchange %s" % exchangeName)
-
- def addQueue(self, nodeNumber, clusterName, queueName, configArgs = None):
- """Add a queue using qpid-config."""
- action = "add queue %s" % queueName
- if self._storeEnable:
- action += " --durable"
- if configArgs != None:
- action += " %s" % configArgs
- self._qpidConfig(nodeNumber, clusterName, action)
-
- def delQueue(self, nodeNumber, clusterName, queueName):
- """Delete a named queue using qpid-config."""
- self._qpidConfig(nodeNumber, clusterName, "del queue %s" % queueName)
-
- def bind(self, nodeNumber, clusterName, exchangeName, queueName, key):
- """Create an exchange-queue binding using qpid-config."""
- self._qpidConfig(nodeNumber, clusterName, "bind %s %s %s" % (exchangeName, queueName, key))
-
- def unbind(self, nodeNumber, clusterName, exchangeName, queueName, key):
- """Remove an exchange-queue binding using qpid-config."""
- self._qpidConfig(nodeNumber, clusterName, "unbind %s %s %s" % (exchangeName, queueName, key))
-
- # --- qpid-route functions (federation) ---
-
- def brokerDict(self, nodeNumber, clusterName, host = "localhost", user = None, password = None):
- """Returns a dictionary containing the broker info to be passed to route functions"""
- port = self.getNodeTuple(nodeNumber, clusterName)[self.PORT]
- return {"cluster": clusterName, "node":nodeNumber, "port":port, "host":host, "user":user, "password":password}
-
- def _brokerStr(self, brokerDict):
- """Set up a broker string in the format [user/password@]host:port"""
- str = ""
- if brokerDict["user"] !=None and brokerDict["password"] != None:
- str = "%s@%s" % (brokerDict["user"], brokerDict["password"])
- str += "%s:%d" % (brokerDict["host"], brokerDict["port"])
- return str
-
- def _qpidRoute(self, action):
- """Set up a route using qpid-route"""
- #print "%s %s" % (self._qpidRouteExec, action)
- ret = os.spawnl(os.P_WAIT, self._qpidRouteExec, self._qpidRouteExec, *action.split())
- if ret != 0:
- raise Exception("_qpidRoute(): action=\"%s\" returned %d" % (action, ret))
-
- def routeDynamicAdd(self, destBrokerDict, srcBrokerDict, exchangeName):
- self._qpidRoute("dynamic add %s %s %s" % (self._brokerStr(destBrokerDict), self._brokerStr(srcBrokerDict), exchangeName))
-
- def routeDynamicDelete(self, destBrokerDict, srcBrokerDict, exchangeName):
- self._qpidRoute("dynamic del %s %s %s" % (self._brokerStr(destBrokerDict), self._brokerStr(srcBrokerDict), exchangeName))
-
- def routeAdd(self, destBrokerDict, srcBrokerDict, exchangeName, routingKey):
- self._qpidRoute("route add %s %s %s %s" % (self._brokerStr(destBrokerDict), self._brokerStr(srcBrokerDict), exchangeName, routingKey))
-
- def routeDelete(self, destBrokerDict, srcBrokerDict, exchangeName, routingKey):
- self._qpidRoute("route del %s %s %s %s" % (self._brokerStr(destBrokerDict), self._brokerStr(srcBrokerDict), exchangeName, routingKey))
-
- def routeQueueAdd(self, destBrokerDict, srcBrokerDict, exchangeName, queueName):
- self._qpidRoute("queue add %s %s %s %s" % (self._brokerStr(destBrokerDict), self._brokerStr(srcBrokerDict), exchangeName, queueName))
-
- def routeQueueDelete(self, destBrokerDict, srcBrokerDict, exchangeName, queueName):
- self._qpidRoute("queue del %s %s %s %s" % (self._brokerStr(destBrokerDict), self._brokerStr(srcBrokerDict), exchangeName, queueName))
-
- def routeLinkAdd(self, destBrokerDict, srcBrokerDict):
- self._qpidRoute("link add %s %s" % (self._brokerStr(destBrokerDict), self._brokerStr(srcBrokerDict)))
-
- def routeLinkDelete(self, destBrokerDict, srcBrokerDict):
- self._qpidRoute("link del %s %s" % (self._brokerStr(destBrokerDict), self._brokerStr(srcBrokerDict)))
-
- # --- Message send and receive functions ---
-
- def _receiver(self, action):
- if self._receiverExec == None:
- raise Exception("Environment variable RECEIVER is not set")
- cmd = "%s %s" % (self._receiverExec, action)
- #print cmd
- return subprocess.Popen(cmd.split(), stdout = subprocess.PIPE)
-
- def _sender(self, action):
- if self._senderExec == None:
- raise Exception("Environment variable SENDER is not set")
- cmd = "%s %s" % (self._senderExec, action)
- #print cmd
- return subprocess.Popen(cmd.split(), stdin = subprocess.PIPE)
-
- def createReciever(self, nodeNumber, clusterName, queueName, numMsgs = None, receiverArgs = None):
- port = self.getNodeTuple(nodeNumber, clusterName)[self.PORT]
- action = "--port %d --queue %s" % (port, queueName)
- if numMsgs != None:
- action += " --messages %d" % numMsgs
- if receiverArgs != None:
- action += " %s" % receiverArgs
- return self._receiver(action)
-
- def createSender(self, nodeNumber, clusterName, exchangeName, routingKey, senderArgs = None):
- port = self.getNodeTuple(nodeNumber, clusterName)[self.PORT]
- action = "--port %d --exchange %s" % (port, exchangeName)
- if routingKey != None and len(routingKey) > 0:
- action += " --routing-key %s" % routingKey
- if self._storeEnable:
- action += " --durable yes"
- if senderArgs != None:
- action += " %s" % senderArgs
- return self._sender(action)
-
- def createBindDirectExchangeQueue(self, nodeNumber, clusterName, exchangeName, queueName):
- self.addExchange(nodeNumber, clusterName, "direct", exchangeName)
- self.addQueue(nodeNumber, clusterName, queueName)
- self.bind(nodeNumber, clusterName, exchangeName, queueName, queueName)
-
- def createBindTopicExchangeQueues(self, nodeNumber, clusterName, exchangeName, queueNameKeyList):
- self.addExchange(nodeNumber, clusterName, "topic", exchangeName)
- for queueName, key in queueNameKeyList.iteritems():
- self.addQueue(nodeNumber, clusterName, queueName)
- self.bind(nodeNumber, clusterName, exchangeName, queueName, key)
-
- def createBindFanoutExchangeQueues(self, nodeNumber, clusterName, exchangeName, queueNameList):
- self.addExchange(nodeNumber, clusterName, "fanout", exchangeName)
- for queueName in queueNameList:
- self.addQueue(nodeNumber, clusterName, queueName)
- self.bind(nodeNumber, clusterName, exchangeName, queueName, "")
-
- def sendMsgs(self, nodeNumber, clusterName, exchangeName, routingKey, numMsgs, msgSize = None, wait = True):
- msgs = self._makeMessageList(numMsgs, msgSize)
- sender = self.createSender(nodeNumber, clusterName, exchangeName, routingKey)
- sender.stdin.write(msgs)
- sender.stdin.close()
- if wait:
- sender.wait()
- return msgs
-
- def receiveMsgs(self, nodeNumber, clusterName, queueName, numMsgs, wait = True):
- receiver = self.createReciever(nodeNumber, clusterName, queueName, numMsgs)
- cnt = 0
- msgs = ""
- while cnt < numMsgs:
- rx = receiver.stdout.readline()
- if rx == "" and receiver.poll() != None: break
- msgs += rx
- cnt = cnt + 1
- if wait:
- receiver.wait()
- return msgs
-
-
- # --- Exchange-specific helper inner classes ---
-
- class TestHelper:
- """
- This is a "virtual" superclass for test helpers, and is not useful on its own, but the
- per-exchange subclasses are designed to keep track of the messages sent to and received
- from queues which have bindings to that exchange type.
- """
-
- def __init__(self, testBaseCluster, clusterName, numNodes, exchangeName, queueNameList):
-
- """Dictionary of queues and lists of messages sent to them."""
- self._txMsgs = {}
- """Dictionary of queues and lists of messages received from them."""
- self._rxMsgs = {}
- """List of node numbers currently in the cluster"""
- self._nodes = []
- """List of node numbers which have been killed and can therefore be recovered"""
- self._deadNodes = []
- """Last node to be used"""
- self._lastNode = None
-
- self._testBaseCluster = testBaseCluster
- self._clusterName = clusterName
- self._exchangeName = exchangeName
- self._queueNameList = queueNameList
- self._addQueues(queueNameList)
- self._testBaseCluster.createCheckCluster(clusterName, numNodes)
- self._nodes.extend(range(0, numNodes))
-
- def _addQueues(self, queueNameList):
- for qn in queueNameList:
- if not qn in self._txMsgs:
- self._txMsgs[qn] = []
- if not qn in self._rxMsgs:
- self._rxMsgs[qn] = []
-
- def _bindQueue(self, queueName, bindingKey, nodeNumber = None):
- """Bind a queue to an exchange using a binding key."""
- if nodeNumber == None:
- nodeNumber = self._nodes[0] # first available node
- self._testBaseCluster.addQueue(nodeNumber, self._clusterName, queueName)
- self._testBaseCluster.bind(nodeNumber, self._clusterName, self._exchangeName, queueName, bindingKey)
-
- def _highestNodeNumber(self):
- """Find the highest node number used so far between the current nodes and those stopped/killed."""
- highestNode = self._nodes[-1]
- if len(self._deadNodes) == 0:
- return highestNode
- highestDeadNode = self._deadNodes[-1]
- if highestNode > highestDeadNode:
- return highestNode
- return highestDeadNode
-
- def killCluster(self):
- """Kill all nodes in the cluster"""
- self._testBaseCluster.killCluster(self._clusterName)
- self._testBaseCluster.checkNumClusterBrokers(self._clusterName, 0)
- self._deadNodes.extend(self._nodes)
- self._deadNodes.sort()
- del self._nodes[:]
-
- def restoreCluster(self, lastNode = None, restoreNodes = True):
- """Restore a previously killed cluster"""
- self._testBaseCluster.createCluster(self._clusterName)
- if restoreNodes:
- numNodes = len(self._deadNodes)
- self.restoreNodes(lastNode)
- self._testBaseCluster.checkNumClusterBrokers(self._clusterName, numNodes)
-
- def addNodes(self, numberOfNodes = 1):
- """Add a fixed number of nodes to the cluster."""
- nodeStart = self._highestNodeNumber() + 1
- for i in range(0, numberOfNodes):
- nodeNumber = nodeStart + i
- self._testBaseCluster.createClusterNode(nodeNumber, self._clusterName)
- self._nodes.append(nodeNumber)
- self._testBaseCluster.checkNumClusterBrokers(self._clusterName, len(self._nodes))
- self._testBaseCluster.waitForNodes(self._clusterName)
-
- def restoreNode(self, nodeNumber):
- """Restore a cluster node that has been previously killed"""
- if nodeNumber not in self._deadNodes:
- raise Exception("restoreNode(): Node number %d not in dead node list %s" % (nodeNumber, self._deadNodes))
- self._testBaseCluster.createClusterNode(nodeNumber, self._clusterName)
- self._deadNodes.remove(nodeNumber)
- self._nodes.append(nodeNumber)
- self._nodes.sort()
-
- def restoreNodes(self, lastNode = None):
- """Restore all known cluster nodes that have been previously killed starting with a known last-used node"""
- if len(self._nodes) == 0: # restore last-used node first
- if lastNode == None:
- lastNode = self._lastNode
- self.restoreNode(lastNode)
- while len(self._deadNodes) > 0:
- self.restoreNode(self._deadNodes[0])
- self._testBaseCluster.waitForNodes(self._clusterName)
-
- def killNode(self, nodeNumber):
- """Kill a cluster node (if it is in the _nodes list)."""
- if nodeNumber not in self._nodes:
- raise Exception("killNode(): Node number %d not in node list %s" % (nodeNumber, self._nodes))
- self._testBaseCluster.killNode(nodeNumber, self._clusterName)
- self._nodes.remove(nodeNumber)
- self._deadNodes.append(nodeNumber)
- self._deadNodes.sort()
-
- def sendMsgs(self, routingKey, numMsgs, nodeNumber = None, msgSize = None, wait = True):
- """Send a fixed number of messages using the given routing key."""
- if nodeNumber == None:
- nodeNumber = self._nodes[0] # Use first available node
- msgs = self._testBaseCluster._makeMessageList(numMsgs, msgSize)
- sender = self._testBaseCluster.createSender(nodeNumber, self._clusterName, self._exchangeName, routingKey)
- sender.stdin.write(msgs)
- sender.stdin.close()
- if wait:
- sender.wait()
- self._lastNode = nodeNumber
- return msgs.split()
-
- # TODO - this i/f is messy: one mumMsgs can be given, but a list of queues
- # so assuming numMsgs for each queue
- # A mechanism is needed to specify a different numMsgs per queue
- def receiveMsgs(self, numMsgs, nodeNumber = None, queueNameList = None, wait = True):
- """Receive a fixed number of messages from a named queue. If numMsgs == None, get all remaining messages."""
- if nodeNumber == None:
- nodeNumber = self._nodes[0] # Use first available node
- if queueNameList == None:
- queueNameList = self._txMsgs.iterkeys()
- for qn in queueNameList:
- nm = numMsgs
- if nm == None:
- nm = len(self._txMsgs[qn]) - len(self._rxMsgs[qn]) # get all remaining messages
- if nm > 0:
- while nm > 0:
- receiver = self._testBaseCluster.createReciever(nodeNumber, self._clusterName, qn, nm)
- cnt = 0
- while cnt < nm:
- rx = receiver.stdout.readline().strip()
- if rx == "":
- if receiver.poll() != None: break
- elif rx not in self._rxMsgs[qn]:
- self._rxMsgs[qn].append(rx)
- cnt = cnt + 1
- nm = nm - cnt
- if wait:
- receiver.wait()
- self._rxMsgs[qn].sort()
- self._lastNode = nodeNumber
-
- def receiveRemainingMsgs(self, nodeNumber = None, queueNameList = None, wait = True):
- """Receive all remaining messages on named queue."""
- self.receiveMsgs(None, nodeNumber, queueNameList, wait)
-
- def checkMsgs(self):
- """Return True if all expected messages have been received (ie the transmit and receive list are identical)."""
- txMsgTot = 0
- rxMsgTot = 0
- for qn, txMsgList in self._txMsgs.iteritems():
- rxMsgList = self._rxMsgs[qn]
- txMsgTot = txMsgTot + len(txMsgList)
- rxMsgTot = rxMsgTot + len(rxMsgList)
- if len(txMsgList) != len(rxMsgList):
- return False
- for i, m in enumerate(txMsgList):
- if m != rxMsgList[i]:
- return False
- if txMsgTot == 0 and rxMsgTot == 0:
- print "WARNING: No messages were either sent or received"
- return True
-
- def finalizeTest(self):
- """Recover all the remaining messages on all queues, then check that all expected messages were received."""
- self.receiveRemainingMsgs()
- self._testBaseCluster.stopAllCheck()
- if not self.checkMsgs():
- self.printMsgs()
- self._testBaseCluster.fail("Send - receive message mismatch")
-
- def printMsgs(self, txMsgs = True, rxMsgs = True):
- """Print all messages transmitted and received."""
- for qn, txMsgList in self._txMsgs.iteritems():
- print "Queue: %s" % qn
- if txMsgs:
- print " txMsgList = %s" % txMsgList
- if rxMsgs:
- rxMsgList = self._rxMsgs[qn]
- print " rxMsgList = %s" % rxMsgList
-
-
- class DirectExchangeTestHelper(TestHelper):
-
- def __init__(self, testBaseCluster, clusterName, numNodes, exchangeName, queueNameList):
- TestBaseCluster.TestHelper.__init__(self, testBaseCluster, clusterName, numNodes, exchangeName, queueNameList)
- self._testBaseCluster.addExchange(0, clusterName, "direct", exchangeName)
- for qn in queueNameList:
- self._bindQueue(qn, qn)
-
- def addQueues(self, queueNameList):
- self._addQueues(queueNameList)
- for qn in queueNameList:
- self._bindQueue(qn, qn)
-
- def sendMsgs(self, numMsgs, nodeNumber = None, queueNameList = None, msgSize = None, wait = True):
- if queueNameList == None:
- queueNameList = self._txMsgs.iterkeys()
- for qn in queueNameList:
- self._txMsgs[qn].extend(TestBaseCluster.TestHelper.sendMsgs(self, qn, numMsgs, nodeNumber, msgSize, wait))
-
-
- class TopicExchangeTestHelper(TestHelper):
-
- def __init__(self, testBaseCluster, clusterName, numNodes, exchangeName, queueNameKeyList):
- self._queueNameKeyList = queueNameKeyList
- TestBaseCluster.TestHelper.__init__(self, testBaseCluster, clusterName, numNodes, exchangeName, queueNameKeyList.iterkeys())
- self._testBaseCluster.addExchange(0, clusterName, "topic", exchangeName)
- for qn, bk in queueNameKeyList.iteritems():
- self._bindQueue(qn, bk)
-
- def addQueues(self, queueNameKeyList):
- self._addQueues(queueNameKeyList.iterkeys())
- for qn, bk in queueNameKeyList.iteritems():
- self._bindQueue(qn, bk)
-
- def _prepareRegex(self, bk):
- # This regex conversion is not very complete - there are other chars that should be escaped too
- return "^%s$" % bk.replace(".", r"\.").replace("*", r"[^.]*").replace("#", ".*")
-
- def sendMsgs(self, routingKey, numMsgs, nodeNumber = None, msgSize = None, wait = True):
- msgList = TestBaseCluster.TestHelper.sendMsgs(self, routingKey, numMsgs, nodeNumber, msgSize, wait)
- for qn, bk in self._queueNameKeyList.iteritems():
- if re.match(self._prepareRegex(bk), routingKey):
- self._txMsgs[qn].extend(msgList)
-
-
- class FanoutExchangeTestHelper(TestHelper):
-
- def __init__(self, testBaseCluster, clusterName, numNodes, exchangeName, queueNameList):
- TestBaseCluster.TestHelper.__init__(self, testBaseCluster, clusterName, numNodes, exchangeName, queueNameList)
- self._testBaseCluster.addExchange(0, clusterName, "fanout", exchangeName)
- for qn in queueNameList:
- self._bindQueue(qn, "")
-
- def addQueues(self, queueNameList):
- self._addQueues(queueNameList)
- for qn in queueNameList:
- self._bindQueue(qn, "")
-
- def sendMsgs(self, numMsgs, nodeNumber = None, msgSize = None, wait = True):
- msgList = TestBaseCluster.TestHelper.sendMsgs(self, "", numMsgs, nodeNumber, msgSize, wait)
- for ml in self._txMsgs.itervalues():
- ml.extend(msgList)
-
diff --git a/cpp/src/tests/verify_cluster_objects b/cpp/src/tests/verify_cluster_objects
deleted file mode 100755
index 94661cf6b9..0000000000
--- a/cpp/src/tests/verify_cluster_objects
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/usr/bin/env python
-
-# 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.
-#
-
-# Verify managment objects are consistent in a cluster.
-# Arguments: url of one broker in the cluster.
-
-import qmf.console, sys, re
-
-class Session(qmf.console.Session):
- """A qmf.console.Session that caches useful values"""
-
- def __init__(self):
- qmf.console.Session.__init__(self)
- self.classes = None
-
- def all_classes(self):
- if self.classes is None:
- self.classes = [c for p in self.getPackages() for c in self.getClasses(p)]
- return self.classes
-
-class Broker:
- def __init__(self, url, qmf):
- self.url = url
- self.qmf = qmf
- self.broker = self.qmf.addBroker(url)
- self.broker._waitForStable()
- self.objects = None
- self.ignore_list = [ re.compile("org.apache.qpid.broker:system:") ]
-
- def get_objects(self):
- def ignore(name):
- for m in self.ignore_list:
- if m.match(name): return True
- if self.objects is None:
- obj_list = []
- ignored=0
- for c in self.qmf.all_classes():
- for o in self.qmf.getObjects(_key=c, _broker=self.broker):
- name=o.getObjectId().getObject()
- if not ignore(name): obj_list.append(name)
- else: ignored += 1
- self.objects = set(obj_list)
- if (len(obj_list) != len(self.objects)):
- raise Exception("Duplicates in object list for %s"%(self.url))
- print "%d objects on %s, ignored %d."%(len(self.objects), self.url, ignored)
- return self.objects
-
- def compare(self,other):
- def compare1(x,y):
- diff = x.get_objects() - y.get_objects()
- if diff:
- print "ERROR: found on %s but not %s"%(x, y)
- for o in diff: print " %s"%(o)
- return False
- return True
-
- so = compare1(self, other)
- os = compare1(other, self)
- return so and os
-
- def __str__(self): return self.url
-
- def get_cluster(self):
- """Given one Broker, return list of all brokers in its cluster"""
- clusters = self.qmf.getObjects(_class="cluster")
- if not clusters: raise ("%s is not a cluster member"%(self.url))
- def first_address(url):
- """Python doesn't understand the brokers URL syntax. Extract a simple addres"""
- return re.compile("amqp:tcp:([^,]*)").match(url).group(1)
- return [Broker(first_address(url), self.qmf)
- for url in clusters[0].members.split(";")]
-
- def __del__(self): self.qmf.delBroker(self.broker)
-
-def main(argv=None):
- if argv is None: argv = sys.argv
- qmf = Session()
- brokers = Broker(argv[1], qmf).get_cluster()
- print "%d members in cluster."%(len(brokers))
- base = brokers.pop(0)
- try:
- for b in brokers:
- if not base.compare(b): return 1
- print "No differences."
- return 0
- finally:
- del base
- del brokers
-
-if __name__ == "__main__": sys.exit(main())
diff --git a/cpp/src/versions.cmake b/cpp/src/versions.cmake
index acc075e899..fda9500cc6 100644
--- a/cpp/src/versions.cmake
+++ b/cpp/src/versions.cmake
@@ -36,4 +36,5 @@ set (qpidtypes_version 1.0.0)
set (rdmawrap_version 2.0.0)
set (sslcommon_version 2.0.0)
set (asyncStore_version 1.0.0)
+#set (legacystore_version 1.0.0)
diff --git a/cpp/src/windows/QpiddBroker.cpp b/cpp/src/windows/QpiddBroker.cpp
index 89a8945d00..b383b7d6c7 100644
--- a/cpp/src/windows/QpiddBroker.cpp
+++ b/cpp/src/windows/QpiddBroker.cpp
@@ -27,11 +27,19 @@
#include "qpid/Plugin.h"
#include "qpid/sys/IntegerTypes.h"
#include "qpid/sys/windows/check.h"
+#include "qpid/sys/Thread.h"
#include "qpid/broker/Broker.h"
#include <iostream>
+#include <string>
+#include <vector>
#include <windows.h>
+namespace {
+ // This will accept args from the command line; augmented with service args.
+ std::vector<std::string> cmdline_args;
+}
+
namespace qpid {
namespace broker {
@@ -46,6 +54,10 @@ BootstrapOptions::BootstrapOptions(const char* argv0)
add(log);
}
+void BootstrapOptions::usage() const {
+ std::cout << "Usage: qpidd [OPTIONS]" << std::endl << std::endl << *this << std::endl;
+}
+
// Local functions to set and get the pid via a LockFile.
namespace {
@@ -218,10 +230,10 @@ VOID WINAPI SvcCtrlHandler(DWORD control)
::SetServiceStatus(svcStatusHandle, &svcStatus);
CtrlHandler(CTRL_C_EVENT);
break;
-
+
case SERVICE_CONTROL_INTERROGATE:
break;
-
+
default:
break;
}
@@ -229,6 +241,25 @@ VOID WINAPI SvcCtrlHandler(DWORD control)
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
+ // The arguments can come from 2 places. Args set with the executable
+ // name when the service is installed come through main() and are now
+ // in cmdline_args. Arguments set in StartService come into argc/argv
+ // above; if they are set, argv[0] is the service name. Make command
+ // line args first; StartService args come later and can override
+ // command line args.
+ int all_argc = argc + cmdline_args.size();
+ if (argc == 0 && !cmdline_args.empty())
+ ++all_argc; // No StartService args, so need to add prog name argv[0]
+ const char **all_argv = new const char *[all_argc];
+ if (all_argc > 0) {
+ int i = 0;
+ all_argv[i++] = argc > 0 ? argv[0] : svcName.c_str();
+ for (size_t j = 0; j < cmdline_args.size(); ++j)
+ all_argv[i++] = cmdline_args[j].c_str();
+ for (DWORD k = 1; k < argc; ++k)
+ all_argv[i++] = argv[k];
+ }
+
::memset(&svcStatus, 0, sizeof(svcStatus));
svcStatusHandle = ::RegisterServiceCtrlHandler(svcName.c_str(),
SvcCtrlHandler);
@@ -238,7 +269,9 @@ VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
svcStatus.dwCurrentState = SERVICE_START_PENDING;
::SetServiceStatus(svcStatusHandle, &svcStatus);
// QpiddBroker class resets state to running.
- svcStatus.dwWin32ExitCode = run_broker(argc, argv, true);
+ svcStatus.dwWin32ExitCode = run_broker(all_argc,
+ const_cast<char**>(all_argv),
+ true);
svcStatus.dwCurrentState = SERVICE_STOPPED;
svcStatus.dwCheckPoint = 0;
svcStatus.dwWaitHint = 0;
@@ -278,7 +311,7 @@ struct ServiceOptions : public qpid::Options {
std::string password;
std::string depends;
- ServiceOptions()
+ ServiceOptions()
: qpid::Options("Service options"),
install(false),
start(false),
@@ -395,7 +428,7 @@ int QpiddBroker::execute (QpiddOptions *options) {
// Relies on port number being set via --port or QPID_PORT env variable.
NamedSharedMemory<BrokerInfo> info(brokerInfoName(options->broker.port));
int pid = info.get().pid;
- if (pid < 0)
+ if (pid < 0)
return 1;
if (myOptions->control.check)
std::cout << pid << std::endl;
@@ -464,6 +497,11 @@ int main(int argc, char* argv[])
{ "", (LPSERVICE_MAIN_FUNCTION)qpid::broker::ServiceMain },
{ NULL, NULL }
};
+ // Copy any command line args to be available in case we're started
+ // as a service. Pick these back up in ServiceMain.
+ for (int i = 1; i < argc; ++i)
+ cmdline_args.push_back(argv[i]);
+
if (!StartServiceCtrlDispatcher(dispatchTable)) {
DWORD err = ::GetLastError();
if (err == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) // Run as console
diff --git a/cpp/src/xml.mk b/cpp/src/xml.mk
index baf3803647..9376cfd54a 100644
--- a/cpp/src/xml.mk
+++ b/cpp/src/xml.mk
@@ -24,6 +24,6 @@ xml_la_SOURCES = \
qpid/xml/XmlExchangePlugin.cpp
xml_la_LIBADD = -lxerces-c -lxqilla libqpidbroker.la
-
+xml_la_CXXFLAGS = $(AM_CXXFLAGS) -D_IN_QPID_BROKER
xml_la_LDFLAGS = $(PLUGINLDFLAGS)
diff --git a/cpp/xml/cluster.xml b/cpp/xml/cluster.xml
deleted file mode 100644
index 09434ea37b..0000000000
--- a/cpp/xml/cluster.xml
+++ /dev/null
@@ -1,339 +0,0 @@
-<?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.
--
--->
-
-<!--
-- NOTE: if you make changes to this XML you must update CLUSTER_VERSION
-- in src/qpid/cluster/Cluster.cpp
--->
-
-<amqp major="0" minor="10" port="5672">
-
- <!-- Controls sent between cluster nodes. -->
-
- <class name = "cluster" code = "0x80" label="Qpid clustering extensions.">
- <doc>Qpid extension class to allow clustered brokers to communicate.</doc>
-
- <!-- New joiner requests an update to url. -->
- <control name="update-request" code="0x1">
- <field name="url" type="str16"/>
- </control>
-
- <!-- Sender offers an update to a new joiner. -->
- <control name = "update-offer" code="0x2">
- <field name="updatee" type="uint64"/>
- </control>
-
- <!-- Sender retracts an offer to a new joiner. -->
- <control name = "retract-offer" code="0x3">
- <field name="updatee" type="uint64"/>
- </control>
-
- <!-- Possible states for persistent store -->
- <domain name="store-state" type="uint8">
- <enum>
- <choice name="no-store" value="0"/>
- <choice name="empty-store" value="1"/>
- <choice name="clean-store" value="2"/>
- <choice name="dirty-store" value="3"/>
- </enum>
- </domain>
-
- <!-- Status exchanged when new members join the cluster. -->
- <control name="initial-status" code="0x5">
- <field name="version" type="uint32"/>
- <field name="active" type="bit"/>
- <field name="cluster-id" type="uuid"/>>
- <field name="store-state" type="store-state"/>
- <field name="shutdown-id" type="uuid"/>
- <field name="first-config" type="str16"/>
- <field name="urls" type="array"/> <!-- Array of str16 -->
- </control>
-
- <!-- New member or updater is ready as an active member. -->
- <control name="ready" code="0x10">
- <field name="url" type="str16"/>
- </control>
-
- <control name="config-change" code="0x11" label="Raw cluster membership.">
- <field name="members" type="vbin16"/> <!-- packed member-id array -->
- <field name="joined" type="vbin16"/> <!-- packed member-id array -->
- <field name="left" type="vbin16"/> <!-- packed member-id array -->
- </control>
-
- <domain name="error-type" type="uint8" label="Types of error">
- <enum>
- <choice name="none" value="0"/>
- <choice name="session" value="1"/>
- <choice name="connection" value="2"/>
- </enum>
- </domain>
-
- <!-- Check for error consistency across the cluster -->
- <control name="error-check" code="0x14">
- <field name="type" type="error-type"/>
- <field name="frame-seq" type="sequence-no"/>
- </control>
-
- <!-- Synchronize timer tasks across the cluster -->
- <control name="timer-wakeup" code="0x15">
- <field name="name" type="str16"/>
- </control>
-
- <control name="timer-drop" code="0x16">
- <field name="name" type="str16"/>
- </control>
-
- <!-- Shut down the entire cluster -->
- <control name="shutdown" code="0x20">
- <field name="shutdown-id" type="uuid"/>
- </control>
-
- <!-- Deliver a message to a queue -->
- <control name="deliver-to-queue" code="0x21">
- <field name="queue" type="str16"/>
- <field name="message" type="vbin32"/>
- </control>
-
- <!-- Update the cluster time -->
- <control name="clock" code="0x22">
- <field name="time" type="uint64"/>
- </control>
-
- </class>
-
- <!-- Controls associated with a specific connection. -->
-
- <class name="cluster-connection" code="0x81" label="Qpid clustering extensions.">
-
- <!-- Announce a new connection -->
- <control name="announce" code="0x1">
- <field name="management-id" type="str16"/>
- <!-- Security Strength Factor (ssf): if the transport provides
- encryption (e.g. ssl), ssf is the bit length of the key. Zero if no
- encryption provided. -->
- <field name="ssf" type="uint32"/>
- <!-- external auth id (e.g. ssl client certificate id) -->
- <field name="authid" type="str16"/>
- <!-- exclude certain sasl mechs, used with ssl and sasl-external -->
- <field name="nodict" type="bit"/>
- <!-- User name as negotiated by SASL -->
- <field name="username" type="str32"/>
- <!-- Frames forming the initial connection negotiation. -->
- <field name="initial-frames" type="str32"/>
- </control>
-
- <!-- Marks the cluster-wide point when a connection is considered closed. -->
- <control name="deliver-close" code="0x2"/>
-
- <!-- Permission to generate output up to the limit. -->
- <control name="deliver-do-output" code="0x3">
- <field name="limit" type="uint32"/>
- </control>
-
- <!-- Abort a connection that is sending invalid data. -->
- <control name="abort" code="0x4"/>
-
- <!-- Update controls. Sent to a new broker in joining mode.
- A connection is updated as followed:
- - send the shadow's management ID in shadow-perpare on the update connection
- - open the shadow as a normal connection.
- - attach sessions, create consumers, set flow with normal AMQP cokmmands.
- - send /reset additional session state with controls below.
- - send shadow-ready to mark end of shadow update.
- - send membership when entire update is complete.
- -->
- <!-- Send the user-id for an update connection. -->
- <control name="shadow-set-user" code="0x0E">
- <field name="user-id" type="str16"/>
- </control>
-
- <!-- Prepare to send a shadow connection with the given ID. -->
- <control name="shadow-prepare" code="0x0F">
- <field name="management-id" type="str16"/>
- </control>
-
- <!-- Consumer state that cannot be set by standard AMQP controls. -->
- <control name="consumer-state" code="0x10">
- <field name="name" type="str8"/>
- <field name="blocked" type="bit"/>
- <field name="notifyEnabled" type="bit"/>
- <field name="position" type="sequence-no"/>
- <field name="used-msg-credit" type="uint32"/>
- <field name="used-byte-credit" type="uint32"/>
- <field name="deliveryCount" type="uint32"/>
- </control>
-
- <!-- Delivery-record for outgoing messages sent but not yet accepted. -->
- <control name="delivery-record" code ="0x11">
- <field name="queue" type="str8"/>
- <field name="position" type="sequence-no"/>
- <field name="tag" type="str8"/>
- <field name="id" type="sequence-no"/>
- <field name="acquired" type="bit"/> <!--If not set, message is on update queue. -->
- <field name="accepted" type="bit"/>
- <field name="cancelled" type="bit"/>
- <field name="completed" type="bit"/>
- <field name="ended" type="bit"/>
- <field name="windowing" type="bit"/>
- <field name="enqueued" type="bit"/>
- <field name="credit" type="uint32"/>
- </control>
-
- <!-- Tx transaction state. -->
- <control name="tx-start" code="0x12"/>
- <control name="tx-accept" code="0x13"> <field name="commands" type="sequence-set"/> </control>
- <control name="tx-dequeue" code="0x14"> <field name="queue" type="str8"/> </control>
- <control name="tx-enqueue" code="0x15"> <field name="queue" type="str8"/> </control>
- <control name="tx-publish" code="0x16">
- <field name="queues" type="array"/> <!--Array of str8 -->
- <field name="delivered" type="bit"/>
- </control>
- <control name="tx-end" code="0x17"/>
- <control name="accumulated-ack" code="0x18"> <field name="commands" type="sequence-set"/> </control>
-
- <!-- Consumers in the connection's output task -->
- <control name="output-task" code="0x19">
- <field name="channel" type="uint16"/>
- <field name="name" type="str8"/>
- </control>
-
- <!-- Dtx transaction state. -->
- <control name="dtx-start" code="0x1A">
- <field name="xid" type="str16"/>
- <field name="ended" type="bit"/>
- <field name="suspended" type="bit"/>
- <field name="failed" type="bit"/>
- <field name="expired" type="bit"/>
- </control>
- <control name="dtx-end" code="0x1B"/>
-
- <control name="dtx-ack" code="0x1C"/>
-
- <control name="dtx-buffer-ref" code="0x1D">
- <field name="xid" type="str16"/>
- <field name="index" type="uint32"/>
- <field name="suspended" type="bit"/>
- </control>
-
- <control name="dtx-work-record" code="0x1E">
- <field name="xid" type="str16"/>
- <field name="prepared" type="bit"/>
- <field name="timeout" type="uint32"/>
- </control>
-
- <!-- Complete a session state update. -->
- <control name="session-state" code="0x1F">
- <!-- Target session deduced from channel number. -->
- <field name="replay-start" type="sequence-no"/> <!-- Replay frames will start from this point.-->
- <field name="command-point" type="sequence-no"/> <!-- Id of next command sent -->
- <field name="sent-incomplete" type="sequence-set"/> <!-- Commands sent and incomplete. -->
-
- <field name="expected" type="sequence-no"/> <!-- Next command expected. -->
- <field name="received" type="sequence-no"/> <!-- Received up to here (>= expected) -->
- <field name="unknown-completed" type="sequence-set"/> <!-- Completed but not known to peer. -->
- <field name="received-incomplete" type="sequence-set"/> <!-- Received and incomplete -->
- <field name="dtx-selected" type="bit"/>
- </control>
-
- <!-- Complete a shadow connection update. -->
- <control name="shadow-ready" code="0x20" label="End of shadow connection update.">
- <field name="member-id" type="uint64"/>
- <field name="connection-id" type="uint64"/>
- <field name="management-id" type="str16"/>
- <field name="user-name" type="str8"/>
- <field name="fragment" type="str32"/>
- <field name="send-max" type="uint32"/>
- </control>
-
- <!-- Complete a cluster state update. -->
- <control name="membership" code="0x21" label="Cluster membership details.">
- <field name="joiners" type="map"/> <!-- member-id -> URL -->
- <field name="members" type="map"/> <!-- member-id -> state -->
- <field name="frame-seq" type="sequence-no"/> <!-- frame sequence number -->
- </control>
-
- <!-- Updater cannot fulfill an update offer. -->
- <control name = "retract-offer" code="0x22"/>
-
- <!-- Set the position of a replicated queue. -->
- <control name="queue-position" code="0x30">
- <field name="queue" type="str8"/>
- <field name="position" type="sequence-no"/>
- </control>
-
- <!-- Replicate encoded exchanges/queues. -->
- <control name="exchange" code="0x31"><field name="encoded" type="str32"/></control>
-
- <!-- Add a listener to a queue -->
- <control name="add-queue-listener" code="0x34">
- <field name="queue" type="str8"/>
- <field name="consumer" type="uint32"/>
- </control>
-
- <!-- added by jrd. propagate a management-setup-state widget -->
- <control name="management-setup-state" code="0x36">
- <field name="objectNum" type="uint64"/>
- <field name="bootSequence" type="uint16"/>
- <field name="broker-id" type="uuid"/>
- <field name="vendor" type="str32"/>
- <field name="product" type="str32"/>
- <field name="instance" type="str32"/>
- </control>
-
- <!-- Replicate encoded config objects - e.g. links and bridges. -->
- <control name="config" code="0x37"><field name="encoded" type="str32"/></control>
-
- <!-- Set the fairshare delivery related state of a replicated queue. -->
- <control name="queue-fairshare-state" code="0x38">
- <field name="queue" type="str8"/>
- <field name="position" type="uint8"/>
- <field name="count" type="uint8"/>
- </control>
-
- <!-- Replicate a QueueObserver for a given queue. -->
- <control name="queue-observer-state" code="0x39">
- <field name="queue" type="str8"/>
- <field name="observer-id" type="str8"/>
- <field name="state" type="map"/> <!-- "name"=value -->
- </control>
-
- <!-- Update the cluster time -->
- <control name="clock" code="0x40">
- <field name="time" type="uint64"/>
- </control>
-
- <!-- Update a queue's dequeue rate -->
- <control name="queue-dequeue-since-purge-state" code="0x41">
- <field name="queue" type="str8"/>
- <field name="dequeueSincePurge" type="uint32"/>
- </control>
-
- <!-- Replicate the internal state for an object - e.g. Links, bridges, etc -->
- <control name="internal-state" code="0x42">
- <field name="type" type="str8"/> <!-- The type of object the state is for (e.g. 'link') -->
- <field name="name" type="str8"/> <!-- Identifies the particular object to be updated -->
- <field name="state" type="map"/> <!-- The internal state for the object -->
- </control>
-
- </class>
-
-</amqp>
diff --git a/doc/book/src/Makefile.inc b/doc/book/src/Makefile.inc
index 12cab54f8a..99d999ed7a 100644
--- a/doc/book/src/Makefile.inc
+++ b/doc/book/src/Makefile.inc
@@ -17,7 +17,7 @@
# under the License.
#
-BOOK=$(wildcard *Book.xml)
+BOOK=$(wildcard *Book.xml Programming-In-Apache-Qpid.xml)
XML=$(wildcard *.xml) $(wildcard ../common/*.xml)
IMAGES=$(wildcard images/*.png)
CSS=$(wilcard ../common/css/*.css)
diff --git a/doc/book/src/cpp-broker/AMQP-Messaging-Broker-CPP-Book.xml b/doc/book/src/cpp-broker/AMQP-Messaging-Broker-CPP-Book.xml
index 228c6a5e15..6122b12e18 100644
--- a/doc/book/src/cpp-broker/AMQP-Messaging-Broker-CPP-Book.xml
+++ b/doc/book/src/cpp-broker/AMQP-Messaging-Broker-CPP-Book.xml
@@ -53,7 +53,6 @@
<xi:include href="Security.xml"/>
<xi:include href="LVQ.xml"/>
<xi:include href="queue-state-replication.xml"/>
- <xi:include href="Active-Active-Cluster.xml"/>
<xi:include href="producer-flow-control.xml"/>
<xi:include href="AMQP-Compatibility.xml"/>
<xi:include href="Qpid-Interoperability-Documentation.xml"/>
diff --git a/doc/book/src/cpp-broker/Active-Active-Cluster.xml b/doc/book/src/cpp-broker/Active-Active-Cluster.xml
deleted file mode 100644
index 28db3876e2..0000000000
--- a/doc/book/src/cpp-broker/Active-Active-Cluster.xml
+++ /dev/null
@@ -1,561 +0,0 @@
-<?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.
-
--->
-
-<section id="chap-Messaging_User_Guide-Active_Active_Cluster">
- <title>Active-active Messaging Clusters</title>
- <para>
- Active-active Messaging Clusters provide fault tolerance by ensuring that every broker in a <firstterm>cluster</firstterm> has the same queues, exchanges, messages, and bindings, and allowing a client to <firstterm>fail over</firstterm> to a new broker and continue without any loss of messages if the current broker fails or becomes unavailable. <firstterm>Active-active</firstterm> refers to the fact that all brokers in the cluster can actively serve clients. Because all brokers are automatically kept in a consistent state, clients can connect to and use any broker in a cluster. Any number of messaging brokers can be run as one <firstterm>cluster</firstterm>, and brokers can be added to or removed from a cluster while it is in use.
- </para>
- <para>
- High Availability Messaging Clusters are implemented using using the <ulink url="http://www.openais.org/">OpenAIS Cluster Framework</ulink>.
- </para>
- <para>
- An OpenAIS daemon runs on every machine in the cluster, and these daemons communicate using multicast on a particular address. Every qpidd process in a cluster joins a named group that is automatically synchronized using OpenAIS Closed Process Groups (CPG) — the qpidd processes multicast events to the named group, and CPG ensures that each qpidd process receives all the events in the same sequence. All members get an identical sequence of events, so they can all update their state consistently.
- </para>
- <para>
- Two messaging brokers are in the same cluster if
- <orderedlist>
- <listitem>
- <para>
- They run on hosts in the same OpenAIS cluster; that is, OpenAIS is configured with the same mcastaddr, mcastport and bindnetaddr, and
- </para>
-
- </listitem>
- <listitem>
- <para>
- They use the same cluster name.
- </para>
-
- </listitem>
-
- </orderedlist>
-
- </para>
- <para>
- High Availability Clustering has a cost: in order to allow each broker in a cluster to continue the work of any other broker, a cluster must replicate state for all brokers in the cluster. Because of this, the brokers in a cluster should normally be on a LAN; there should be fast and reliable connections between brokers. Even on a LAN, using multiple brokers in a cluster is somewhat slower than using a single broker without clustering. This may be counter-intuitive for people who are used to clustering in the context of High Performance Computing or High Throughput Computing, where clustering increases performance or throughput.
- </para>
-
- <para>
- High Availability Messaging Clusters should be used together with Red Hat Clustering Services (RHCS); without RHCS, clusters are vulnerable to the &#34;split-brain&#34; condition, in which a network failure splits the cluster into two sub-clusters that cannot communicate with each other. See the documentation on the <command>--cluster-cman</command> option for details on running using RHCS with High Availability Messaging Clusters. See the <ulink url="http://sources.redhat.com/cluster/wiki">CMAN Wiki</ulink> for more detail on CMAN and split-brain conditions. Use the <command>--cluster-cman</command> option to enable RHCS when starting the broker.
- </para>
- <section id="sect-Messaging_User_Guide-High_Availability_Messaging_Clusters-Starting_a_Broker_in_a_Cluster">
- <title>Starting a Broker in a Cluster</title>
- <para>
- Clustering is implemented using the <filename>cluster.so</filename> module, which is loaded by default when you start a broker. To run brokers in a cluster, make sure they all use the same OpenAIS mcastaddr, mcastport, and bindnetaddr. All brokers in a cluster must also have the same cluster name — specify the cluster name in <filename>qpidd.conf</filename>:
- </para>
-
- <screen>cluster-name=&#34;local_test_cluster&#34;
- </screen>
- <para>
- On RHEL6, you must create the file <filename>/etc/corosync/uidgid.d/qpidd</filename> to tell Corosync the name of the user running the broker.By default, the user is qpidd:
- </para>
-
- <programlisting>
- uidgid {
- uid: qpidd
- gid: qpidd
- }
- </programlisting>
- <para>
- On RHEL5, the primary group for the process running qpidd must be the ais group. If you are running qpidd as a service, it is run as the <command>qpidd</command> user, which is already in the ais group. If you are running the broker from the command line, you must ensure that the primary group for the user running qpidd is ais. You can set the primary group using <command>newgrp</command>:
- </para>
-
- <screen>$ newgrp ais
- </screen>
- <para>
- You can then run the broker from the command line, specifying the cluster name as an option.
- </para>
-
- <screen>[jonathan@localhost]$ qpidd --cluster-name=&#34;local_test_cluster&#34;
- </screen>
- <para>
- All brokers in a cluster must have identical configuration, with a few exceptions noted below. They must load the same set of plug-ins, and have matching configuration files and command line arguments. The should also have identical ACL files and SASL databases if these are used. If one broker uses persistence, all must use persistence — a mix of transient and persistent brokers is not allowed. Differences in configuration can cause brokers to exit the cluster. For instance, if different ACL settings allow a client to access a queue on broker A but not on broker B, then publishing to the queue will succeed on A and fail on B, so B will exit the cluster to prevent inconsistency.
- </para>
- <para>
- The following settings can differ for brokers on a given cluster:
- </para>
- <itemizedlist>
- <listitem>
- <para>
- logging options
- </para>
-
- </listitem>
- <listitem>
- <para>
- cluster-url — if set, it will be different for each broker.
- </para>
-
- </listitem>
- <listitem>
- <para>
- port — brokers can listen on different ports.
- </para>
-
- </listitem>
-
- </itemizedlist>
- <para>
- The qpid log contains entries that record significant clustering events, e.g. when a broker becomes a member of a cluster, the membership of a cluster is changed, or an old journal is moved out of the way. For instance, the following message states that a broker has been added to a cluster as the first node:
- </para>
-
- <screen>
- 2009-07-09 18:13:41 info 127.0.0.1:1410(READY) member update: 127.0.0.1:1410(member)
- 2009-07-09 18:13:41 notice 127.0.0.1:1410(READY) first in cluster
- </screen>
- <note>
- <para>
- If you are using SELinux, the qpidd process and OpenAIS must have the same SELinux context, or else SELinux must be set to permissive mode. If both qpidd and OpenAIS are run as services, they have the same SELinux context. If both OpenAIS and qpidd are run as user processes, they have the same SELinux context. If one is run as a service, and the other is run as a user process, they have different SELinux contexts.
- </para>
-
- </note>
- <para>
- The following options are available for clustering:
- </para>
- <table frame="all" id="tabl-Messaging_User_Guide-Starting_a_Broker_in_a_Cluster-Options_for_High_Availability_Messaging_Cluster">
- <title>Options for High Availability Messaging Cluster</title>
- <tgroup align="left" cols="2" colsep="1" rowsep="1">
- <colspec colname="c1" colwidth="1*"></colspec>
- <colspec colname="c2" colwidth="4*"></colspec>
- <thead>
- <row>
- <entry align="center" nameend="c2" namest="c1">
- Options for High Availability Messaging Cluster
- </entry>
-
- </row>
-
- </thead>
- <tbody>
- <row>
- <entry>
- <command>--cluster-name <replaceable>NAME</replaceable></command>
- </entry>
- <entry>
- Name of the Messaging Cluster to join. A Messaging Cluster consists of all brokers started with the same cluster-name and openais configuration.
- </entry>
-
- </row>
- <row>
- <entry>
- <command>--cluster-size <replaceable>N</replaceable></command>
- </entry>
- <entry>
- Wait for at least N initial members before completing cluster initialization and serving clients. Use this option in a persistent cluster so all brokers in a persistent cluster can exchange the status of their persistent store and do consistency checks before serving clients.
- </entry>
-
- </row>
- <row>
- <entry>
- <command>--cluster-url <replaceable>URL</replaceable></command>
- </entry>
- <entry>
- An AMQP URL containing the local address that the broker advertizes to clients for fail-over connections. This is different for each host. By default, all local addresses for the broker are advertized. You only need to set this if
- <orderedlist>
- <listitem>
- <para>
- Your host has more than one active network interface, and
- </para>
-
- </listitem>
- <listitem>
- <para>
- You want to restrict client fail-over to a specific interface or interfaces.
- </para>
-
- </listitem>
-
- </orderedlist>
- <para>Each broker in the cluster is specified using the following form:</para>
-
- <programlisting>url = [&#34;amqp:&#34;][ user [&#34;/&#34; password] &#34;@&#34; ] protocol_addr
- (&#34;,&#34; protocol_addr)*
- protocol_addr = tcp_addr / rmda_addr / ssl_addr / ...
- tcp_addr = [&#34;tcp:&#34;] host [&#34;:&#34; port]
- rdma_addr = &#34;rdma:&#34; host [&#34;:&#34; port]
- ssl_addr = &#34;ssl:&#34; host [&#34;:&#34; port]</programlisting>
-
- <para>In most cases, only one address is advertized, but more than one address can be specified in if the machine running the broker has more than one network interface card, and you want to allow clients to connect using multiple network interfaces. Use a comma delimiter (&#34;,&#34;) to separate brokers in the URL. Examples:</para>
- <itemizedlist>
- <listitem>
- <para>
- <command>amqp:tcp:192.168.1.103:5672</command> advertizes a single address to the broker for failover.
- </para>
-
- </listitem>
- <listitem>
- <para>
- <command>amqp:tcp:192.168.1.103:5672,tcp:192.168.1.105:5672</command> advertizes two different addresses to the broker for failover, on two different network interfaces.
- </para>
-
- </listitem>
-
- </itemizedlist>
-
- </entry>
-
- </row>
- <row>
- <entry>
- <command>--cluster-cman</command>
- </entry>
- <entry>
- <para>
- CMAN protects against the &#34;split-brain&#34; condition, in which a network failure splits the cluster into two sub-clusters that cannot communicate with each other. When &#34;split-brain&#34; occurs, each of the sub-clusters can access shared resources without knowledge of the other sub-cluster, resulting in corrupted cluster integrity.
- </para>
- <para>
- To avoid &#34;split-brain&#34;, CMAN uses the notion of a &#34;quorum&#34;. If more than half the cluster nodes are active, the cluster has quorum and can act. If half (or fewer) nodes are active, the cluster does not have quorum, and all cluster activity is stopped. There are other ways to define the quorum for particular use cases (e.g. a cluster of only 2 members), see the <ulink url="http://sources.redhat.com/cluster/wiki">CMAN Wiki</ulink>
- for more detail.
- </para>
- <para>
- When enabled, the broker will wait until it belongs to a quorate cluster before accepting client connections. It continually monitors the quorum status and shuts down immediately if the node it runs on loses touch with the quorum.
- </para>
-
- </entry>
-
- </row>
- <row>
- <entry>
- --cluster-username
- </entry>
- <entry>
- SASL username for connections between brokers.
- </entry>
-
- </row>
- <row>
- <entry>
- --cluster-password
- </entry>
- <entry>
- SASL password for connections between brokers.
- </entry>
-
- </row>
- <row>
- <entry>
- --cluster-mechanism
- </entry>
- <entry>
- SASL authentication mechanism for connections between brokers
- </entry>
-
- </row>
-
- </tbody>
-
- </tgroup>
-
- </table>
- <para>
- If a broker is unable to establish a connection to another broker in the cluster, the log will contain SASL errors, e.g:
- </para>
-
- <screen>2009-aug-04 10:17:37 info SASL: Authentication failed: SASL(-13): user not found: Password verification failed
- </screen>
- <para>
- You can set the SASL user name and password used to connect to other brokers using the <command>cluster-username</command> and <command>cluster-password</command> properties when you start the broker. In most environment, it is easiest to create an account with the same user name and password on each broker in the cluster, and use these as the <command>cluster-username</command> and <command>cluster-password</command>. You can also set the SASL mode using <command>cluster-mechanism</command>. Remember that any mechanism you enable for broker-to-broker communication can also be used by a client, so do not enable <command>cluster-mechanism=ANONYMOUS</command> in a secure environment.
- </para>
- <para>
- Once the cluster is running, run <command>qpid-cluster</command> to make sure that the brokers are running as one cluster. See the following section for details.
- </para>
- <para>
- If the cluster is correctly configured, queues and messages are replicated to all brokers in the cluster, so an easy way to test the cluster is to run a program that routes messages to a queue on one broker, then to a different broker in the same cluster and read the messages to make sure they have been replicated. The <command>drain</command> and <command>spout</command> programs can be used for this test.
- </para>
-
- </section>
-
- <section id="sect-Messaging_User_Guide-High_Availability_Messaging_Clusters-qpid_cluster">
- <title>qpid-cluster</title>
- <para>
- <command>qpid-cluster</command> is a command-line utility that allows you to view information on a cluster and its brokers, disconnect a client connection, shut down a broker in a cluster, or shut down the entire cluster. You can see the options using the <command>--help</command> option:
- </para>
-
- <screen>$ ./qpid-cluster --help
- </screen>
-
- <screen>Usage: qpid-cluster [OPTIONS] [broker-addr]
-
- broker-addr is in the form: [username/password@] hostname | ip-address [:&#60;port&#62;]
- ex: localhost, 10.1.1.7:10000, broker-host:10000, guest/guest@localhost
-
- Options:
- -C [--all-connections] View client connections to all cluster members
- -c [--connections] ID View client connections to specified member
- -d [--del-connection] HOST:PORT
- Disconnect a client connection
- -s [--stop] ID Stop one member of the cluster by its ID
- -k [--all-stop] Shut down the whole cluster
- -f [--force] Suppress the &#39;are-you-sure?&#39; prompt
- -n [--numeric] Don&#39;t resolve names
- </screen>
- <para>
- Let&#39;s connect to a cluster and display basic information about the cluser and its brokers. When you connect to the cluster using <command>qpid-tool</command>, you can use the host and port for any broker in the cluster. For instance, if a broker in the cluster is running on <filename>localhost</filename> on port 6664, you can start <command>qpid-tool</command> like this:
- </para>
-
- <screen>
- $ qpid-cluster localhost:6664
- </screen>
- <para>
- Here is the output:
- </para>
-
- <screen>
- Cluster Name: local_test_cluster
- Cluster Status: ACTIVE
- Cluster Size: 3
- Members: ID=127.0.0.1:13143 URL=amqp:tcp:192.168.1.101:6664,tcp:192.168.122.1:6664,tcp:10.16.10.62:6664
- : ID=127.0.0.1:13167 URL=amqp:tcp:192.168.1.101:6665,tcp:192.168.122.1:6665,tcp:10.16.10.62:6665
- : ID=127.0.0.1:13192 URL=amqp:tcp:192.168.1.101:6666,tcp:192.168.122.1:6666,tcp:10.16.10.62:6666
- </screen>
- <para>
- The ID for each broker in cluster is given on the left. For instance, the ID for the first broker in the cluster is <command>127.0.0.1:13143</command>. The URL in the output is the broker&#39;s advertized address. Let&#39;s use the ID to shut the broker down using the <command>--stop</command> command:
- </para>
-
- <screen>$ ./qpid-cluster localhost:6664 --stop 127.0.0.1:13143
- </screen>
-
- </section>
-
- <section id="sect-Messaging_User_Guide-High_Availability_Messaging_Clusters-Failover_in_Clients">
- <title>Failover in Clients</title>
- <para>
- If a client is connected to a broker, the connection fails if the broker crashes or is killed. If heartbeat is enabled for the connection, a connection also fails if the broker hangs, the machine the broker is running on fails, or the network connection to the broker is lost — the connection fails no later than twice the heartbeat interval.
- </para>
- <para>
- When a client&#39;s connection to a broker fails, any sent messages that have been acknowledged to the sender will have been replicated to all brokers in the cluster, any received messages that have not yet been acknowledged by the receiving client requeued to all brokers, and the client API notifies the application of the failure by throwing an exception.
- </para>
- <para>
- Clients can be configured to automatically reconnect to another broker when it receives such an exception. Any messages that have been sent by the client, but not yet acknowledged as delivered, are resent. Any messages that have been read by the client, but not acknowledged, are delivered to the client.
- </para>
- <para>
- TCP is slow to detect connection failures. A client can configure a connection to use a heartbeat to detect connection failure, and can specify a time interval for the heartbeat. If heartbeats are in use, failures will be detected no later than twice the heartbeat interval. The Java JMS client enables hearbeat by default. See the sections on Failover in Java JMS Clients and Failover in C++ Clients for the code to enable heartbeat.
- </para>
- <section id="sect-Messaging_User_Guide-Failover_in_Clients-Failover_in_Java_JMS_Clients">
- <title>Failover in Java JMS Clients</title>
- <para>
- In Java JMS clients, client failover is handled automatically if it is enabled in the connection. Any messages that have been sent by the client, but not yet acknowledged as delivered, are resent. Any messages that have been read by the client, but not acknowledged, are sent to the client.
- </para>
- <para>
- You can configure a connection to use failover using the <command>failover</command> property:
- </para>
-
- <screen>
- connectionfactory.qpidConnectionfactory = amqp://guest:guest@clientid/test?brokerlist=&#39;tcp://localhost:5672&#39;&amp;failover=&#39;failover_exchange&#39;
- </screen>
- <para>
- This property can take three values:
- </para>
- <variablelist id="vari-Messaging_User_Guide-Failover_in_Java_JMS_Clients-Failover_Modes">
- <title>Failover Modes</title>
- <varlistentry>
- <term>failover_exchange</term>
- <listitem>
- <para>
- If the connection fails, fail over to any other broker in the cluster.
- </para>
-
- </listitem>
-
- </varlistentry>
- <varlistentry>
- <term>roundrobin</term>
- <listitem>
- <para>
- If the connection fails, fail over to one of the brokers specified in the <command>brokerlist</command>.
- </para>
-
- </listitem>
-
- </varlistentry>
- <varlistentry>
- <term>singlebroker</term>
- <listitem>
- <para>
- Failover is not supported; the connection is to a single broker only.
- </para>
-
- </listitem>
-
- </varlistentry>
-
- </variablelist>
- <para>
- In a Connection URL, heartbeat is set using the <command>idle_timeout</command> property, which is an integer corresponding to the heartbeat period in seconds. For instance, the following line from a JNDI properties file sets the heartbeat time out to 3 seconds:
- </para>
-
- <screen>
- connectionfactory.qpidConnectionfactory = amqp://guest:guest@clientid/test?brokerlist=&#39;tcp://localhost:5672&#39;,idle_timeout=3
- </screen>
-
- </section>
-
- <section id="sect-Messaging_User_Guide-Failover_in_Clients-Failover_and_the_Qpid_Messaging_API">
- <title>Failover and the Qpid Messaging API</title>
- <para>
- The Qpid Messaging API also supports automatic reconnection in the event a connection fails. . Senders can also be configured to replay any in-doubt messages (i.e. messages whice were sent but not acknowleged by the broker. See &#34;Connection Options&#34; and &#34;Sender Capacity and Replay&#34; in <citetitle>Programming in Apache Qpid</citetitle> for details.
- </para>
- <para>
- In C++ and python clients, heartbeats are disabled by default. You can enable them by specifying a heartbeat interval (in seconds) for the connection via the &#39;heartbeat&#39; option.
- </para>
- <para>
- See &#34;Cluster Failover&#34; in <citetitle>Programming in Apache Qpid</citetitle> for details on how to keep the client aware of cluster membership.
- </para>
-
- </section>
-
-
- </section>
-
- <section id="sect-Messaging_User_Guide-High_Availability_Messaging_Clusters-Error_handling_in_Clusters">
- <title>Error handling in Clusters</title>
- <para>
- If a broker crashes or is killed, or a broker machine failure, broker connection failure, or a broker hang is detected, the other brokers in the cluster are notified that it is no longer a member of the cluster. If a new broker is joined to the cluster, it synchronizes with an active broker to obtain the current cluster state; if this synchronization fails, the new broker exit the cluster and aborts.
- </para>
- <para>
- If a broker becomes extremely busy and stops responding, it stops accepting incoming work. All other brokers continue processing, and the non-responsive node caches all AIS traffic. When it resumes, the broker completes processes all cached AIS events, then accepts further incoming work. <!-- If a broker is non-responsive for too long, it is assumed to be hanging, and treated as described in the previous paragraph. -->
- </para>
- <para>
- Broker hangs are only detected if the watchdog plugin is loaded and the <command>--watchdog-interval</command> option is set. The watchdog plug-in kills the qpidd broker process if it becomes stuck for longer than the watchdog interval. In some cases, e.g. certain phases of error resolution, it is possible for a stuck process to hang other cluster members that are waiting for it to send a message. Using the watchdog, the stuck process is terminated and removed from the cluster, allowing other members to continue and clients of the stuck process to fail over to other members.
- </para>
- <para>
- Redundancy can also be achieved directly in the AIS network by specifying more than one network interface in the AIS configuration file. This causes Totem to use a redundant ring protocol, which makes failure of a single network transparent.
- </para>
- <para>
- Redundancy can be achieved at the operating system level by using NIC bonding, which combines multiple network ports into a single group, effectively aggregating the bandwidth of multiple interfaces into a single connection. This provides both network load balancing and fault tolerance.
- </para>
- <para>
- If any broker encounters an error, the brokers compare notes to see if they all received the same error. If not, the broker removes itself from the cluster and shuts itself down to ensure that all brokers in the cluster have consistent state. For instance, a broker may run out of disk space; if this happens, the broker shuts itself down. Examining the broker&#39;s log can help determine the error and suggest ways to prevent it from occuring in the future.
- </para>
- <!-- "Bad case" for cluster matrix - things we will fix, or things users may encounter long term? -->
- </section>
-
- <section id="sect-Messaging_User_Guide-High_Availability_Messaging_Clusters-Persistence_in_High_Availability_Message_Clusters">
- <title>Persistence in High Availability Message Clusters</title>
- <para>
- Persistence and clustering are two different ways to provide reliability. Most systems that use a cluster do not enable persistence, but you can do so if you want to ensure that messages are not lost even if the last broker in a cluster fails. A cluster must have all transient or all persistent members, mixed clusters are not allowed. Each broker in a persistent cluster has it&#39;s own independent replica of the cluster&#39;s state it its store.
- </para>
- <section id="sect-Messaging_User_Guide-Persistence_in_High_Availability_Message_Clusters-Clean_and_Dirty_Stores">
- <title>Clean and Dirty Stores</title>
- <para>
- When a broker is an active member of a cluster, its store is marked &#34;dirty&#34; because it may be out of date compared to other brokers in the cluster. If a broker leaves a running cluster because it is stopped, it crashes or the host crashes, its store continues to be marked &#34;dirty&#34;.
- </para>
- <para>
- If the cluster is reduced to a single broker, its store is marked &#34;clean&#34; since it is the only broker making updates. If the cluster is shut down with the command <literal>qpid-cluster -k</literal> then all the stores are marked clean.
- </para>
- <para>
- When a cluster is initially formed, brokers with clean stores read from their stores. Brokers with dirty stores, or brokers that join after the cluster is running, discard their old stores and initialize a new store with an update from one of the running brokers. The <command>--truncate</command> option can be used to force a broker to discard all existing stores even if they are clean. (A dirty store is discarded regardless.)
- </para>
- <para>
- Discarded stores are copied to a back up directory. The active store is in &#60;data-dir&#62;/rhm. Back-up stores are in &#60;data-dir&#62;/_cluster.bak.&#60;nnnn&#62;/rhm, where &#60;nnnn&#62; is a 4 digit number. A higher number means a more recent backup.
- </para>
-
- </section>
-
- <section id="sect-Messaging_User_Guide-Persistence_in_High_Availability_Message_Clusters-Starting_a_persistent_cluster">
- <title>Starting a persistent cluster</title>
- <para>
- When starting a persistent cluster broker, set the cluster-size option to the number of brokers in the cluster. This allows the brokers to wait until the entire cluster is running so that they can synchronize their stored state.
- </para>
- <para>
- The cluster can start if:
- </para>
- <para>
- <itemizedlist>
- <listitem>
- <para>
- all members have empty stores, or
- </para>
-
- </listitem>
- <listitem>
- <para>
- at least one member has a clean store
- </para>
-
- </listitem>
-
- </itemizedlist>
-
- </para>
- <para>
- All members of the new cluster will be initialized with the state from a clean store.
- </para>
-
- </section>
-
- <section id="sect-Messaging_User_Guide-Persistence_in_High_Availability_Message_Clusters-Stopping_a_persistent_cluster">
- <title>Stopping a persistent cluster</title>
- <para>
- To cleanly shut down a persistent cluster use the command <command>qpid-cluster -k</command>. This causes all brokers to synchronize their state and mark their stores as &#34;clean&#34; so they can be used when the cluster restarts.
- </para>
-
- </section>
-
- <section id="sect-Messaging_User_Guide-Persistence_in_High_Availability_Message_Clusters-Starting_a_persistent_cluster_with_no_clean_store">
- <title>Starting a persistent cluster with no clean store</title>
- <para>
- If the cluster has previously had a total failure and there are no clean stores then the brokers will fail to start with the log message <literal>Cannot recover, no clean store.</literal> If this happens you can start the cluster by marking one of the stores &#34;clean&#34; as follows:
- </para>
- <procedure>
- <step>
- <para>
- Move the latest store backup into place in the brokers data-directory. The backups end in a 4 digit number, the latest backup is the highest number.
- </para>
-
- <screen>
- cd &#60;data-dir&#62;
- mv rhm rhm.bak
- cp -a _cluster.bak.&#60;nnnn&#62;/rhm .
- </screen>
-
- </step>
- <step>
- <para>
- Mark the store as clean:
- <screen>qpid-cluster-store -c &#60;data-dir&#62;</screen>
-
- </para>
-
- </step>
-
- </procedure>
-
- <para>
- Now you can start the cluster, all members will be initialized from the store you marked as clean.
- </para>
-
- </section>
-
- <section id="sect-Messaging_User_Guide-Persistence_in_High_Availability_Message_Clusters-Isolated_failures_in_a_persistent_cluster">
- <title>Isolated failures in a persistent cluster</title>
- <para>
- A broker in a persistent cluster may encounter errors that other brokers in the cluster do not; if this happens, the broker shuts itself down to avoid making the cluster state inconsistent. For example a disk failure on one node will result in that node shutting down. Running out of storage capacity can also cause a node to shut down because because the brokers may not run out of storage at exactly the same point, even if they have similar storage configuration. To avoid unnecessary broker shutdowns, make sure the queue policy size of each durable queue is less than the capacity of the journal for the queue.
- </para>
-
- </section>
-
-
- </section>
-
-
-</section>
diff --git a/doc/book/src/cpp-broker/Active-Passive-Cluster.xml b/doc/book/src/cpp-broker/Active-Passive-Cluster.xml
index 805ceb06e0..8a6403c2b5 100644
--- a/doc/book/src/cpp-broker/Active-Passive-Cluster.xml
+++ b/doc/book/src/cpp-broker/Active-Passive-Cluster.xml
@@ -55,30 +55,45 @@ under the License.
<title>Avoiding message loss</title>
<para>
In order to avoid message loss, the primary broker <emphasis>delays
- acknowledgment</emphasis> of messages received from clients until the
- message has been replicated to and acknowledged by all of the back-up
+ acknowledgment</emphasis> of messages received from clients until the message has
+ been replicated to and acknowledged by all of the back-up brokers. This means that
+ all <emphasis>acknowledged</emphasis> messages are safely stored on all the backup
brokers.
</para>
<para>
- Clients buffer unacknowledged messages and re-send them in the event of
- a fail-over.
+ Clients keep <emphasis>unacknowledged</emphasis> messages in a buffer
+ <footnote>
+ <para>
+ You can control the maximum number of messages in the buffer by setting the
+ client's <literal>capacity</literal>. For details of how to set the capacity
+ in client code see &#34;Using the Qpid Messaging API&#34; in
+ <citetitle>Programming in Apache Qpid</citetitle>.
+ </para>
+ </footnote>
+ until they are acknowledged by the primary. If the primary fails, clients will
+ fail-over to the new primary and <emphasis>re-send</emphasis> all their
+ unacknowledged messages.
<footnote>
<para>
Clients must use "at-least-once" reliability to enable re-send of unacknowledged
messages. This is the default behavior, no options need be set to enable it. For
details of client addressing options see &#34;Using the Qpid Messaging API&#34;
- in <citetitle>Programming in Apache Qpid</citetitle>
+ in <citetitle>Programming in Apache Qpid</citetitle>.
</para>
</footnote>
- If the primary crashes before a message is replicated to
- all the backups, the client will re-send the message when it fails over
- to the new primary.
+ </para>
+ <para>
+ So if the primary crashes, all the <emphasis>acknowledged</emphasis>
+ messages will be available on the backup that takes over as the new
+ primary. The <emphasis>unacknowledged</emphasis> messages will be
+ re-sent by the clients. Thus no messages are lost.
</para>
<para>
Note that this means it is possible for messages to be
- <emphasis>duplicated</emphasis>. In the event of a failure it is
- possible for a message to be both received by the backup that becomes
- the new primary <emphasis>and</emphasis> re-sent by the client.
+ <emphasis>duplicated</emphasis>. In the event of a failure it is possible for a
+ message to received by the backup that becomes the new primary
+ <emphasis>and</emphasis> re-sent by the client. The application must take steps
+ to identify and eliminate duplicates.
</para>
<para>
When a new primary is promoted after a fail-over it is initially in
@@ -87,6 +102,11 @@ under the License.
primary. This protects those messages against a failure of the new
primary until the backups have a chance to connect and catch up.
</para>
+ <para>
+ Not all messages need to be replicated to the back-up brokers. If a
+ message is consumed and acknowledged by a regular client before it has
+ been replicated to a backup, then it doesn't need to be replicated.
+ </para>
<variablelist>
<title>Status of a HA broker</title>
<varlistentry>
@@ -134,67 +154,35 @@ under the License.
</variablelist>
</section>
<section>
- <title>Replacing the old cluster module</title>
+ <title>Limitations</title>
<para>
- The High Availability (HA) module replaces the previous
- <firstterm>active-active</firstterm> cluster module. The new active-passive
- approach has several advantages compared to the existing active-active cluster
- module.
- <itemizedlist>
- <listitem>
- It does not depend directly on openais or corosync. It does not use multicast
- which simplifies deployment.
- </listitem>
- <listitem>
- It is more portable: in environments that don't support corosync, it can be
- integrated with a resource manager available in that environment.
- </listitem>
- <listitem>
- Replication to a <firstterm>disaster recovery</firstterm> site can be handled as
- simply another node in the cluster, it does not require a separate replication
- mechanism.
- </listitem>
- <listitem>
- It can take advantage of features provided by the resource manager, for example
- virtual IP addresses.
- </listitem>
- <listitem>
- Improved performance and scalability due to better use of multiple CPUs
- </listitem>
- </itemizedlist>
+ There are a some known limitations in the current implementation. These
+ will be fixed in furture versions.
</para>
- </section>
- <section>
- <title>Limitations</title>
<itemizedlist>
<listitem>
- Transactional changes to queue state are not replicated atomically. If the
- primary crashes during a transaction, it is possible that the backup could
- contain only part of the changes introduced by a transaction.
- </listitem>
- <listitem>
- Not yet integrated with the persistent store. A persistent broker must have its
- store erased before joining an existing cluster. If the entire cluster fails,
- there are no tools to help identify the most recent store. In the future a
- persistent broker will be able to use its stored messages to avoid downloading
- messages from the primary when joining a cluster.
- </listitem>
- <listitem>
- Configuration changes (creating or deleting queues, exchanges and bindings) are
- replicated asynchronously. Management tools used to make changes will consider
- the change complete when it is complete on the primary, it may not yet be
- replicated to all the backups.
+ <para>
+ Transactional changes to queue state are not replicated atomically. If
+ the primary crashes during a transaction, it is possible that the
+ backup could contain only part of the changes introduced by a
+ transaction.
+ </para>
</listitem>
<listitem>
- Deletions made immediately after a failure (before all the backups are ready)
- may be lost on a backup. Queues, exchange or bindings that were deleted on the
- primary could re-appear if that backup is promoted to primary on a subsequent
- failure.
+ <para>
+ Configuration changes (creating or deleting queues, exchanges and
+ bindings) are replicated asynchronously. Management tools used to
+ make changes will consider the change complete when it is complete
+ on the primary, it may not yet be replicated to all the backups.
+ </para>
</listitem>
<listitem>
- Federated links <emphasis>from</emphasis> the primary will be lost in fail over,
- they will not be re-connected to the new primary. Federation links
- <emphasis>to</emphasis> the primary can fail over.
+ <para>
+ Federated links <emphasis>from</emphasis> the primary will be lost
+ in fail over, they will not be re-connected to the new
+ primary. Federation links <emphasis>to</emphasis> the primary will
+ fail over.
+ </para>
</listitem>
</itemizedlist>
</section>
@@ -247,12 +235,20 @@ under the License.
</row>
<row>
<entry>
+ <literal>ha-queue-replication <replaceable>yes|no</replaceable></literal>
+ </entry>
+ <entry>
+ Enable replication of specific queues without joining a cluster, see <xref linkend="ha-queue-replication"/>.
+ </entry>
+ </row>
+ <row>
+ <entry>
<literal>ha-brokers-url <replaceable>URL</replaceable></literal>
</entry>
<entry>
<para>
The URL
- <footnote>
+ <footnote id="ha-url-grammar">
<para>
The full format of the URL is given by this grammar:
<programlisting>
@@ -264,10 +260,9 @@ ssl_addr = "ssl:" host [":" port]'
</programlisting>
</para>
</footnote>
- used by cluster brokers to connect to each other. The URL can
- contain a list of all the broker addresses or it can contain a single
- virtual IP address. If a list is used it is comma separated, for example
- <literal>amqp:node1.exaple.com,node2.exaple.com,node3.exaple.com</literal>
+ used by cluster brokers to connect to each other. The URL should
+ contain a comma separated list of the broker addresses, rather than a
+ virtual IP address.
</para>
</entry>
</row>
@@ -275,20 +270,23 @@ ssl_addr = "ssl:" host [":" port]'
<entry><literal>ha-public-url <replaceable>URL</replaceable></literal> </entry>
<entry>
<para>
- The URL that is advertised to clients. This defaults to the
- <literal>ha-brokers-url</literal> URL above, and has the same format. A
- virtual IP address is recommended for the public URL as it simplifies
- deployment and hides changes to the cluster membership from clients.
+ The URL <footnoteref linkend="ha-url-grammar"/> is advertised to
+ clients as the "known-hosts" for fail-over. It can be a list or
+ a single virtual IP address. A virtual IP address is recommended.
</para>
<para>
- This option allows you to put client traffic on a different network from
- broker traffic, which is recommended.
+ Using this option you can put client and broker traffic on
+ separate networks, which is recommended.
+ </para>
+ <para>
+ Note: When HA clustering is enabled the broker option
+ <literal>known-hosts-url</literal> is ignored and over-ridden by
+ the <literal>ha-public-url</literal> setting.
</para>
</entry>
</row>
<row>
<entry><literal>ha-replicate </literal><replaceable>VALUE</replaceable></entry>
- <foo/>
<entry>
<para>
Specifies whether queues and exchanges are replicated by default.
@@ -330,6 +328,15 @@ ssl_addr = "ssl:" host [":" port]'
</para>
</entry>
</row>
+ <row>
+ <entry><literal>link-heartbeat-interval <replaceable>SECONDS</replaceable></literal></entry>
+ <entry>
+ <para>
+ Heartbeat interval for replication links. The link will be assumed broken
+ if there is no heartbeat for twice the interval.
+ </para>
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
@@ -382,7 +389,7 @@ ssl_addr = "ssl:" host [":" port]'
clustered services using <command>cman</command> and
<command>rgmanager</command>. It will show you how to configure an active-passive,
hot-standby <command>qpidd</command> HA cluster with <command>rgmanager</command>.
- </para>
+ </para>
<para>
You must provide a <literal>cluster.conf</literal> file to configure
<command>cman</command> and <command>rgmanager</command>. Here is
@@ -532,22 +539,28 @@ NOTE: fencing is not shown, you must configure fencing appropriately for your cl
</section>
<section id="ha-creating-replicated">
- <title>Creating replicated queues and exchanges</title>
+ <title>Controlling replication of queues and exchanges</title>
<para>
By default, queues and exchanges are not replicated automatically. You can change
the default behavior by setting the <literal>ha-replicate</literal> configuration
option. It has one of the following values:
<itemizedlist>
<listitem>
- <firstterm>all</firstterm>: Replicate everything automatically: queues,
- exchanges, bindings and messages.
+ <para>
+ <firstterm>all</firstterm>: Replicate everything automatically: queues,
+ exchanges, bindings and messages.
+ </para>
</listitem>
<listitem>
- <firstterm>configuration</firstterm>: Replicate the existence of queues,
- exchange and bindings but don't replicate messages.
+ <para>
+ <firstterm>configuration</firstterm>: Replicate the existence of queues,
+ exchange and bindings but don't replicate messages.
+ </para>
</listitem>
<listitem>
- <firstterm>none</firstterm>: Don't replicate anything, this is the default.
+ <para>
+ <firstterm>none</firstterm>: Don't replicate anything, this is the default.
+ </para>
</listitem>
</itemizedlist>
</para>
@@ -575,6 +588,18 @@ NOTE: fencing is not shown, you must configure fencing appropriately for your cl
<programlisting>
"myqueue;{create:always,node:{x-declare:{arguments:{'qpid.replicate':all}}}}"
</programlisting>
+ <para>
+ There are some built-in exchanges created automatically by the broker, these
+ exchangs are never replicated. The built-in exchanges are the default (nameless)
+ exchange, the AMQP standard exchanges (<literal>amq.direct, amq.topic, amq.fanout</literal> and
+ <literal>amq.match</literal>) and the management exchanges (<literal>qpid.management, qmf.default.direct</literal> and
+ <literal>qmf.default.topic</literal>)
+ </para>
+ <para>
+ Note that if you bind a replicated queue to one of these exchanges, the
+ binding wil <emphasis>not</emphasis> be replicated, so the queue will not
+ have the binding after a fail-over.
+ </para>
</section>
<section>
@@ -588,12 +613,17 @@ NOTE: fencing is not shown, you must configure fencing appropriately for your cl
each type of client). There are two possibilities
<itemizedlist>
<listitem>
- The URL contains multiple addresses, one for each broker in the cluster.
+ <para>
+ The URL contains multiple addresses, one for each broker in the cluster.
+ </para>
</listitem>
<listitem>
- The URL contains a single <firstterm>virtual IP address</firstterm>
- that is assigned to the primary broker by the resource manager.
- <footnote><para>Only if the resource manager supports virtual IP addresses</para></footnote>
+ <para>
+ The URL contains a single <firstterm>virtual IP address</firstterm>
+ that is assigned to the primary broker by the resource manager.
+ <footnote><para>Only if the resource manager supports virtual IP
+ addresses</para></footnote>
+ </para>
</listitem>
</itemizedlist>
In the first case, clients will repeatedly re-try each address in the URL
@@ -790,10 +820,10 @@ NOTE: fencing is not shown, you must configure fencing appropriately for your cl
<para>
To integrate with a different resource manager you must configure it to:
<itemizedlist>
- <listitem>Start a qpidd process on each node of the cluster.</listitem>
- <listitem>Restart qpidd if it crashes.</listitem>
- <listitem>Promote exactly one of the brokers to primary.</listitem>
- <listitem>Detect a failure and promote a new primary.</listitem>
+ <listitem><para>Start a qpidd process on each node of the cluster.</para></listitem>
+ <listitem><para>Restart qpidd if it crashes.</para></listitem>
+ <listitem><para>Promote exactly one of the brokers to primary.</para></listitem>
+ <listitem><para>Detect a failure and promote a new primary.</para></listitem>
</itemizedlist>
</para>
<para>
@@ -821,6 +851,30 @@ NOTE: fencing is not shown, you must configure fencing appropriately for your cl
or to simulate a cluster on a single node. For deployment, a resource manager is required.
</para>
</section>
+ <section id="ha-queue-replication">
+ <title>Replicating specific queues</title>
+ <para>
+ In addition to the automatic replication performed in a cluster, you can
+ set up replication for specific queues between arbitrary brokers, even if
+ the brokers are not members of a cluster. The command:
+ </para>
+ <programlisting>
+ qpid-ha replicate <replaceable>QUEUE</replaceable> <replaceable>REMOTE-BROKER</replaceable>
+ </programlisting>
+ <para>
+ sets up replication of <replaceable>QUEUE</replaceable> on <replaceable>REMOTE-BROKER</replaceable> to <replaceable>QUEUE</replaceable> on the current broker.
+ </para>
+ <para>
+ Set the configuration option
+ <literal>ha-queue-replication=yes</literal> on both brokers to enable this
+ feature on non-cluster brokers. It is automatically enabled for brokers
+ that are part of a cluster.
+ </para>
+ <para>
+ Note that this feature does not provide automatic fail-over, for that you
+ need to run a cluster.
+ </para>
+ </section>
</section>
<!-- LocalWords: scalability rgmanager multicast RGManager mailto LVQ qpidd IP dequeued Transactional username
diff --git a/doc/book/src/cpp-broker/Security.xml b/doc/book/src/cpp-broker/Security.xml
index f28b72c71d..67c9d3dab7 100644
--- a/doc/book/src/cpp-broker/Security.xml
+++ b/doc/book/src/cpp-broker/Security.xml
@@ -315,67 +315,102 @@ com.sun.security.jgss.initiate {
<!-- ################################################### --> <section id="sect-Messaging_User_Guide-Security-Authorization">
<title>Authorization</title>
<para>
- In Qpid, Authorization specifies which actions can be performed by each authenticated user using an Access Control List (ACL). Use the <command>--acl-file</command> command to load the access control list. The filename should have a <filename>.acl</filename> extension:
+ In Qpid, Authorization specifies which actions can be performed by each authenticated user using an Access Control List (ACL).
+ </para>
+ <para>
+ Use the <command>--acl-file</command> command to load the access control list. The filename should have a <filename>.acl</filename> extension:
</para>
<screen>
-$ qpidd --acl-file <replaceable>./aclfilename.acl</replaceable></screen>
+ $ qpidd --acl-file <replaceable>./aclfilename.acl</replaceable></screen>
<para>
Each line in an ACL file grants or denies specific rights to a user. If the last line in an ACL file is <literal>acl deny all all</literal>, the ACL uses <firstterm>deny mode</firstterm>, and only those rights that are explicitly allowed are granted:
</para>
<programlisting>
-acl allow rajith@QPID all all
-acl deny all all
+ acl allow rajith@QPID all all
+ acl deny all all
</programlisting>
<para>
On this server, <literal>rajith@QPID</literal> can perform any action, but nobody else can. Deny mode is the default, so the previous example is equivalent to the following ACL file:
</para>
<programlisting>
-acl allow rajith@QPID all all
+ acl allow rajith@QPID all all
+</programlisting>
+ <para>
+ Alternatively the ACL file may use <firstterm>allow mode</firstterm> by placing:
+ </para>
+<programlisting>
+ acl allow all all
</programlisting>
<para>
+ as the final line in the ACL file. In <emphasis>allow mode</emphasis> all actions by all users are allowed unless otherwise denied by specific ACL rules.
+ The ACL rule which selects <emphasis>deny mode</emphasis> or <emphasis>allow mode</emphasis> must be the last line in the ACL rule file.
+ </para>
+ <para>
ACL syntax allows fine-grained access rights for specific actions:
</para>
<programlisting>
-acl allow carlt@QPID create exchange name=carl.*
-acl allow fred@QPID create all
-acl allow all consume queue
-acl allow all bind exchange
-acl deny all all
+ acl allow carlt@QPID create exchange name=carl.*
+ acl allow fred@QPID create all
+ acl allow all consume queue
+ acl allow all bind exchange
+ acl deny all all
</programlisting>
<para>
An ACL file can define user groups, and assign permissions to them:
</para>
<programlisting>
-group admin ted@QPID martin@QPID
-acl allow admin create all
-acl deny all all
+ group admin ted@QPID martin@QPID
+ acl allow admin create all
+ acl deny all all
</programlisting>
+
+ <para>
+ Performance Note: Most ACL queries are performed infrequently. The overhead associated with
+ ACL passing an allow or deny decision on the creation of a queue is negligible
+ compared to actually creating and using the queue. One notable exception is the <command>publish exchange</command>
+ query. ACL files with no <emphasis>publish exchange</emphasis> rules are noted and the broker short circuits the logic
+ associated with the per-messsage <emphasis>publish exchange</emphasis> ACL query.
+ However, if an ACL file has any <emphasis>publish exchange</emphasis> rules
+ then the broker is required to perform a <emphasis>publish exchange</emphasis> query for each message published.
+ Users with performance critical applications are encouraged to structure exchanges, queues, and bindings so that
+ the <emphasis>publish exchange</emphasis> ACL rules are unnecessary.
+ </para>
+
<!-- ######## --> <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntax">
<title>ACL Syntax</title>
<para>
ACL rules must be on a single line and follow this syntax:
<programlisting><![CDATA[
-user = username[/domain[@realm]]
-user-list = user1 user2 user3 ...
-group-name-list = group1 group2 group3 ...
-
-group <group-name> = [user-list] [group-name-list]
-
-permission = [allow|allow-log|deny|deny-log]
-action = [consume|publish|create|access|bind|unbind|delete|purge|update]
-object = [virtualhost|queue|exchange|broker|link|route|method]
-property = [name|durable|owner|routingkey|autodelete|exclusive|
- type|alternate|queuename|schemapackage|schemaclass|
- queuemaxsizelowerlimit|queuemaxsizeupperlimit|
- queuemaxcountlowerlimit|queuemaxcountupperlimit]
-
-acl permission {<group-name>|<user-name>|"all"} {action|"all"} [object|"all"
- [property=<property-value> ...]]
+ user = username[/domain[@realm]]
+ user-list = user1 user2 user3 ...
+ group-name-list = group1 group2 group3 ...
+
+ group <group-name> = [user-list] [group-name-list]
+
+ permission = [allow | allow-log | deny | deny-log]
+ action = [consume | publish | create | access |
+ bind | unbind | delete | purge | update]
+ object = [queue | exchange | broker | link | method]
+ property = [name | durable | owner | routingkey |
+ autodelete | exclusive |type |
+ alternate | queuename |
+ schemapackage | schemaclass |
+ queuemaxsizelowerlimit |
+ queuemaxsizeupperlimit |
+ queuemaxcountlowerlimit |
+ queuemaxcountupperlimit |
+ filemaxsizelowerlimit |
+ filemaxsizeupperlimit |
+ filemaxcountlowerlimit |
+ filemaxcountupperlimit ]
+
+ acl permission {<group-name>|<user-name>|"all"} {action|"all"} [object|"all"
+ [property=<property-value> ...]]
]]></programlisting>
ACL rules can also include a single object name (or the keyword <parameter>all</parameter>) and one or more property name value pairs in the form <command>property=value</command>
@@ -463,7 +498,9 @@ acl permission {<group-name>|<user-name>|"all"} {action|"all"} [object|"all"
</entry>
<entry>
<para>
- Applied on a per message basis on publish message transfers, this rule consumes the most resources
+ Applied on a per message basis
+ to verify that the user has rights to publish to the given
+ exchange with the given routingkey.
</para>
</entry>
@@ -647,49 +684,49 @@ acl permission {<group-name>|<user-name>|"all"} {action|"all"} [object|"all"
<entry> <command>name</command> </entry>
<entry>String</entry>
<entry>Object name, such as a queue name or exchange name.</entry>
- <entry>.</entry>
+ <entry></entry>
</row>
<row>
<entry> <command>durable</command> </entry>
<entry>Boolean</entry>
<entry>Indicates the object is durable</entry>
- <entry>CREATE QUEUE, CREATE EXCHANGE</entry>
+ <entry>CREATE QUEUE, CREATE EXCHANGE, ACCESS QUEUE, ACCESS EXCHANGE</entry>
</row>
<row>
<entry> <command>routingkey</command> </entry>
<entry>String</entry>
<entry>Specifies routing key</entry>
- <entry>BIND EXCHANGE, UNBIND EXCHANGE, ACCESS EXCHANGE</entry>
+ <entry>BIND EXCHANGE, UNBIND EXCHANGE, ACCESS EXCHANGE, PUBLISH EXCHANGE</entry>
</row>
<row>
<entry> <command>autodelete</command> </entry>
<entry>Boolean</entry>
<entry>Indicates whether or not the object gets deleted when the connection is closed</entry>
- <entry>CREATE QUEUE</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
</row>
<row>
<entry> <command>exclusive</command> </entry>
<entry>Boolean</entry>
<entry>Indicates the presence of an <parameter>exclusive</parameter> flag</entry>
- <entry>CREATE QUEUE</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
</row>
<row>
<entry> <command>type</command> </entry>
<entry>String</entry>
<entry>Type of exchange, such as topic, fanout, or xml</entry>
- <entry>CREATE EXCHANGE</entry>
+ <entry>CREATE EXCHANGE, ACCESS EXCHANGE</entry>
</row>
<row>
<entry> <command>alternate</command> </entry>
<entry>String</entry>
<entry>Name of the alternate exchange</entry>
- <entry>CREATE EXCHANGE, CREATE QUEUE</entry>
+ <entry>CREATE EXCHANGE, CREATE QUEUE, ACCESS EXCHANGE, ACCESS QUEUE</entry>
</row>
<row>
<entry> <command>queuename</command> </entry>
<entry>String</entry>
<entry>Name of the queue</entry>
- <entry>ACCESS EXCHANGE</entry>
+ <entry>ACCESS EXCHANGE, BIND EXCHANGE, UNBIND EXCHANGE</entry>
</row>
<row>
<entry> <command>schemapackage</command> </entry>
@@ -706,119 +743,571 @@ acl permission {<group-name>|<user-name>|"all"} {action|"all"} [object|"all"
<row>
<entry> <command>queuemaxsizelowerlimit</command> </entry>
<entry>Integer</entry>
- <entry>Minimum value for queue.max_size</entry>
- <entry>CREATE QUEUE</entry>
+ <entry>Minimum value for queue.max_size (memory bytes)</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
</row>
<row>
<entry> <command>queuemaxsizeupperlimit</command> </entry>
<entry>Integer</entry>
- <entry>Maximum value for queue.max_size</entry>
- <entry>CREATE QUEUE</entry>
+ <entry>Maximum value for queue.max_size (memory bytes)</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
</row>
<row>
<entry> <command>queuemaxcountlowerlimit</command> </entry>
<entry>Integer</entry>
- <entry>Minimum value for queue.max_count</entry>
- <entry>CREATE QUEUE</entry>
+ <entry>Minimum value for queue.max_count (messages)</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
</row>
<row>
<entry> <command>queuemaxcountupperlimit</command> </entry>
<entry>Integer</entry>
- <entry>Maximum value for queue.max_count</entry>
- <entry>CREATE QUEUE</entry>
+ <entry>Maximum value for queue.max_count (messages)</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
+ </row>
+ <row>
+ <entry> <command>filemaxsizelowerlimit</command> </entry>
+ <entry>Integer</entry>
+ <entry>Minimum value for file.max_size (64kb pages)</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
+ </row>
+ <row>
+ <entry> <command>filemaxsizeupperlimit</command> </entry>
+ <entry>Integer</entry>
+ <entry>Maximum value for file.max_size (64kb pages)</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
+ </row>
+ <row>
+ <entry> <command>filemaxcountlowerlimit</command> </entry>
+ <entry>Integer</entry>
+ <entry>Minimum value for file.max_count (files)</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
+ </row>
+ <row>
+ <entry> <command>filemaxcountupperlimit</command> </entry>
+ <entry>Integer</entry>
+ <entry>Maximum value for file.max_count (files)</entry>
+ <entry>CREATE QUEUE, ACCESS QUEUE</entry>
</row>
-
</tbody>
-
</tgroup>
-
</table>
-
+
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_ActionObjectPropertyTuples">
+ <title>ACL Action-Object-Property Tuples</title>
+ <para>
+ Not every ACL action is applicable to every ACL object. Furthermore, not every property may be
+ specified for every action-object pair.
+ The following table enumerates which action and object pairs are allowed.
+ The table also lists which optional ACL properties are allowed to qualify
+ action-object pairs.
+ </para>
+ <para>
+ The <emphasis>access</emphasis> action is called with different argument
+ lists for the <emphasis>exchange</emphasis> and <emphasis>queue</emphasis> objects.
+ A separate column shows the AMQP 0.10 method that the Access ACL rule is satisfying.
+ Write separate rules with the additional arguments for the <emphasis>declare</emphasis>
+ and <emphasis>bind</emphasis> methods and include these rules in the ACL file
+ before the rules for the <emphasis>query</emphasis> method.
+ <!-- The exact sequence of calling these methods is a product of the client
+ library. The user might not know anything about a 'declare' or a 'query' or
+ a passive declaration. -->
+ </para>
+ <table id="tabl-Messaging_User_Guide-ACL_Syntax-ACL_ActionObject_properties">
+ <title>ACL Properties Allowed for each Action and Object</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Action</entry>
+ <entry>Object</entry>
+ <entry>Properties</entry>
+ <entry>Method</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>access</entry>
+ <entry>broker</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>access</entry>
+ <entry>exchange</entry>
+ <entry>name type alternate durable</entry>
+ <entry>declare</entry>
+ </row>
+ <row>
+ <entry>access</entry>
+ <entry>exchange</entry>
+ <entry>name queuename routingkey</entry>
+ <entry>bound</entry>
+ </row>
+ <row>
+ <entry>access</entry>
+ <entry>exchange</entry>
+ <entry>name</entry>
+ <entry>query</entry>
+ </row>
+ <row>
+ <entry>access</entry>
+ <entry>method</entry>
+ <entry>name schemapackage schemaclass</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>access</entry>
+ <entry>queue</entry>
+ <entry>name alternate durable exclusive autodelete policy queuemaxsizelowerlimit queuemaxsizeupperlimit queuemaxcountlowerlimit queuemaxcountupperlimit filemaxsizelowerlimit filemaxsizeupperlimit filemaxcountlowerlimit filemaxcountupperlimit</entry>
+ <entry>declare</entry>
+ </row>
+ <row>
+ <entry>access</entry>
+ <entry>queue</entry>
+ <entry>name</entry>
+ <entry>query</entry>
+ </row>
+ <row>
+ <entry>bind</entry>
+ <entry>exchange</entry>
+ <entry>name queuename routingkey</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>consume</entry>
+ <entry>queue</entry>
+ <entry>name</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>create</entry>
+ <entry>exchange</entry>
+ <entry>name type alternate durable</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>create</entry>
+ <entry>link</entry>
+ <entry>name</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>create</entry>
+ <entry>queue</entry>
+ <entry>name alternate durable exclusive autodelete policy queuemaxsizelowerlimit queuemaxsizeupperlimit queuemaxcountlowerlimit queuemaxcountupperlimit filemaxsizelowerlimit filemaxsizeupperlimit filemaxcountlowerlimit filemaxcountupperlimit</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>delete</entry>
+ <entry>exchange</entry>
+ <entry>name</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>delete</entry>
+ <entry>queue</entry>
+ <entry>name</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>publish</entry>
+ <entry>exchange</entry>
+ <entry>name routingkey</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>purge</entry>
+ <entry>queue</entry>
+ <entry>name</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>unbind</entry>
+ <entry>exchange</entry>
+ <entry>name queuename routingkey</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry>update</entry>
+ <entry>broker</entry>
+ <entry></entry>
+ <entry></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <para>
+
+ </para>
+ </section>
</section>
<section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions">
<title>ACL Syntactic Conventions</title>
- <para>
- In ACL files, the following syntactic conventions apply:
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-comments">
+ <title>Comments</title>
+ <para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ A line starting with the <command>#</command> character is considered a comment and is ignored.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Embedded comments and trailing comments are not allowed. The <command>#</command> is commonly found in routing keys and other AMQP literals which occur naturally in ACL rule specifications.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </section>
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-whitespace">
+ <title>White Space</title>
+ <itemizedlist>
+ <listitem>
+ <para>
+ Empty lines and lines that contain only whitespace (' ', '\f', '\n', '\r', '\t', '\v') are ignored.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Additional whitespace between and after tokens is allowed.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Group and Acl definitions must start with <command>group</command> and <command>acl</command> respectively and with no preceding whitespace.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </section>
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-characterset">
+ <title>Character Set</title>
+ <itemizedlist>
+ <listitem>
+ <para>
+ ACL files use 7-bit ASCII characters only
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Group names may contain only
<itemizedlist>
- <listitem>
- <para>
- A line starting with the <command>#</command> character is considered a comment and is ignored.
- </para>
-
- </listitem>
- <listitem>
- <para>
- Empty lines and lines that contain only whitespace (' ', '\f', '\n', '\r', '\t', '\v') are ignored.
- </para>
-
- </listitem>
- <listitem>
- <para>
- All tokens are case sensitive. <parameter>name1</parameter> is not the same as <parameter>Name1</parameter> and <parameter>create</parameter> is not the same as <parameter>CREATE</parameter>.
- </para>
-
- </listitem>
- <listitem>
- <para>
- Group lists can be extended to the following line by terminating the line with the <command>\</command> character.
- </para>
-
- </listitem>
- <listitem>
- <para>
- Additional whitespace - that is, where there is more than one whitespace character - between and after tokens is ignored. Group and ACL definitions must start with either <command>group</command> or <command>acl</command> and with no preceding whitespace.
- </para>
-
- </listitem>
- <listitem>
- <para>
- All ACL rules are limited to a single line of at most 1024 characters.
- </para>
-
- </listitem>
- <listitem>
- <para>
- Rules are interpreted from the top of the file down until a matching rule is obtained. The matching rule then controls the allow or deny decision.
- </para>
-
- </listitem>
- <listitem>
- <para>
- The keyword <parameter>all</parameter> is reserved and may be used in ACL rules to match all individuals and groups, all actions, or all objects.
- </para>
-
- </listitem>
- <listitem>
- <para>
- By default ACL files are in 'Deny Mode' and deny all actions by all users. That is, there is an implicit <parameter>acl deny all all</parameter> rule appended to the ACL rule list.
- </para>
-
- </listitem>
- <listitem>
- <para>
- Group names may contain only <parameter>a-z</parameter>, <parameter>A-Z</parameter>, <parameter>0-9</parameter>, <parameter>- hyphen</parameter> and <parameter>_ underscore</parameter>.
- </para>
-
- </listitem>
- <listitem>
- <para>
- Individual user names may contain only <parameter>a-z</parameter>, <parameter>A-Z</parameter>, <parameter>0-9</parameter>, <parameter>- hyphen</parameter>, <parameter>_ underscore</parameter>, <parameter>. period</parameter>, <parameter>@ ampersand</parameter>, and <parameter>/ slash</parameter>.
- </para>
-
- </listitem>
- <listitem>
- <para>
- Rules must be preceded by any group definitions they can use. Any name not defined as a group will be assumed to be that of an individual.
- </para>
-
- </listitem>
-
+ <listitem><command>[a-z]</command></listitem>
+ <listitem><command>[A-Z]</command></listitem>
+ <listitem><command>[0-9]</command></listitem>
+ <listitem><command>'-'</command> hyphen</listitem>
+ <listitem><command>'_'</command> underscore</listitem>
+ </itemizedlist>
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Individual user names may contain only
+ <itemizedlist>
+ <listitem><command>[a-z]</command></listitem>
+ <listitem><command>[A-Z]</command></listitem>
+ <listitem><command>[0-9]</command></listitem>
+ <listitem><command>'-'</command> hyphen</listitem>
+ <listitem><command>'_'</command> underscore</listitem>
+ <listitem><command>'.'</command> period</listitem>
+ <listitem><command>'@'</command> ampersand</listitem>
+ <listitem><command>'/'</command> slash</listitem>
</itemizedlist>
+ </para>
+ </listitem>
+ </itemizedlist>
+ </section>
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-casesensitivity">
+ <title>Case Sensitivity</title>
+ <itemizedlist>
+ <listitem>
+ <para>
+ All tokens are case sensitive. <parameter>name1</parameter> is not the same as <parameter>Name1</parameter> and <parameter>create</parameter> is not the same as <parameter>CREATE</parameter>.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </section>
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-linecontinuation">
+ <title>Line Continuation</title>
+ <itemizedlist>
+ <listitem>
+ <para>
+ Group lists can be extended to the following line by terminating the line with the <command>'\'</command> character. No other ACL file lines may be continued.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Group specification lines may be continued only after the group name or any of the user names included in the group. See example below.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Lines consisting solely of a <command>'\'</command> character are not permitted.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The <command>'\'</command> continuation character is recognized only if it is the last character in the line. Any characters after the <command>'\'</command> are not permitted.
+ </para>
+ </listitem>
+ </itemizedlist>
+<programlisting><![CDATA[
+ #
+ # Examples of extending group lists using a trailing '\' character
+ #
+ group group1 name1 name2 \
+ name3 name4 \
+ name5
+
+ group group2 \
+ group1 \
+ name6
+ #
+ # The following are illegal:
+ #
+ # '\' must be after group name
+ #
+ group \
+ group3 name7 name8
+ #
+ # No empty extension line
+ #
+ group group4 name9 \
+ \
+ name10
+]]></programlisting>
- </para>
+ </section>
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-linelength">
+ <title>Line Length</title>
+ <itemizedlist>
+ <listitem>
+ <para>
+ ACL file lines are limited to 1024 characters.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </section>
+
+
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-keywords">
+ <title>ACL File Keywords</title>
+ ACL reserves several words for convenience and for context sensitive substitution.
+
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-keywords-all">
+ <title>The <command>all</command> Keyword</title>
+ The keyword <command>all</command> is reserved. It may be used in ACL rules to match all individuals and groups, all actions, or all objects.
+ <itemizedlist>
+ <listitem>acl allow all create queue</listitem>
+ <listitem>acl allow bob@QPID all queue</listitem>
+ <listitem>acl allow bob@QPID create all</listitem>
+ </itemizedlist>
+ </section>
+
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntactic_Conventions-keywords-userdomain">
+ <title>User Name and Domain Name Keywords</title>
+ <para>
+ In the C++ Broker 0.20 a simple set of user name and domain name substitution variable keyword tokens is defined. This provides administrators with an easy way to describe private or shared resources.
+ </para>
+ <para>
+ Symbol substitution is allowed in the ACL file anywhere that text is supplied for a property value.
+ </para>
+ <para>
+ In the following table an authenticated user named bob.user@QPID.COM has his substitution keywords expanded.
+
+ <table id="tabl-Messaging_User_Guide-ACL_Syntax-ACL_UsernameSubstitution">
+ <title>ACL User Name and Domain Name Substitution Keywords</title>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>Keyword</entry>
+ <entry>Expansion</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry> <command>${userdomain}</command> </entry>
+ <entry>bob_user_QPID_COM</entry>
+ </row>
+ <row>
+ <entry> <command>${user}</command> </entry>
+ <entry>bob_user</entry>
+ </row>
+ <row>
+ <entry> <command>${domain}</command> </entry>
+ <entry>QPID_COM</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </para>
+
+ <para>
+ <itemizedlist>
+ <listitem>
+ The original user name has the period “.” and ampersand “@” characters translated into underscore “_”. This allows substitution to work when the substitution keyword is used in a routingkey in the Acl file.
+ </listitem>
+ <listitem>
+ The Acl processing matches ${userdomain} before matching either ${user} or ${domain}. Rules that specify the combination ${user}_${domain} will never match.
+ </listitem>
+ </itemizedlist>
+ </para>
+
+<programlisting><![CDATA[
+ # Example:
+ #
+ # Administrators can set up Acl rule files that allow every user to create a
+ # private exchange, a private queue, and a private binding between them.
+ # In this example the users are also allowed to create private backup exchanges,
+ # queues and bindings. This effectively provides limits to user's exchange,
+ # queue, and binding creation and guarantees that each user gets exclusive
+ # access to these resources.
+ #
+ #
+ # Create primary queue and exchange:
+ #
+ acl allow all create queue name=$\{user}-work alternate=$\{user}-work2
+ acl deny all create queue name=$\{user}-work alternate=*
+ acl allow all create queue name=$\{user}-work
+ acl allow all create exchange name=$\{user}-work alternate=$\{user}-work2
+ acl deny all create exchange name=$\{user}-work alternate=*
+ acl allow all create exchange name=$\{user}-work
+ #
+ # Create backup queue and exchange
+ #
+ acl deny all create queue name=$\{user}-work2 alternate=*
+ acl allow all create queue name=$\{user}-work2
+ acl deny all create exchange name=$\{user}-work2 alternate=*
+ acl allow all create exchange name=$\{user}-work2
+ #
+ # Bind/unbind primary exchange
+ #
+ acl allow all bind exchange name=$\{user}-work routingkey=$\{user} queuename=$\{user}-work
+ acl allow all unbind exchange name=$\{user}-work routingkey=$\{user} queuename=$\{user}-work
+ #
+ # Bind/unbind backup exchange
+ #
+ acl allow all bind exchange name=$\{user}-work2 routingkey=$\{user} queuename=$\{user}-work2
+ acl allow all unbind exchange name=$\{user}-work2 routingkey=$\{user} queuename=$\{user}-work2
+ #
+ # Access primary exchange
+ #
+ acl allow all access exchange name=$\{user}-work routingkey=$\{user} queuename=$\{user}-work
+ #
+ # Access backup exchange
+ #
+ acl allow all access exchange name=$\{user}-work2 routingkey=$\{user} queuename=$\{user}-work2
+ #
+ # Publish primary exchange
+ #
+ acl allow all publish exchange name=$\{user}-work routingkey=$\{user}
+ #
+ # Publish backup exchange
+ #
+ acl allow all publish exchange name=$\{user}-work2 routingkey=$\{user}
+ #
+ # deny mode
+ #
+ acl deny all all
+]]></programlisting>
+ </section>
+
+ </section>
+
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntatic_Conventions-wildcards">
+ <title>Wildcards</title>
+ ACL privides two types of wildcard matching to provide flexibility in writing rules.
+
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntatic_Conventions-wildcards-asterisk">
+ <title>Property Value Wildcard</title>
+ <para>
+ Text specifying a property value may end with a single trailing <command>*</command> character.
+ This is a simple wildcard match indicating that strings which match up to that point are matches for the ACL property rule.
+ An ACL rule such as
+ </para>
+ <para>
+ <programlisting> acl allow bob@QPID create queue name=bob*</programlisting>
+ </para>
+ <para>
+ allow user bob@QPID to create queues named bob1, bob2, bobQueue3, and so on.
+ </para>
+ </section>
+
+ <section id="sect-Messaging_User_Guide-Authorization-ACL_Syntatic_Conventions-wildcards-topickey">
+ <title>Topic Routing Key Wildcard</title>
+ <para>
+ In the C++ Broker 0.20 the logic governing the ACL Match has changed for each ACL rule that contains a routingkey property.
+ The routingkey property is matched according to Topic Exchange match logic the broker uses when it distributes messages published to a topic exchange.
+ </para>
+ <para>
+ Routing keys are hierarchical where each level is separated by a period:
+ <itemizedlist>
+ <listitem>weather.usa</listitem>
+ <listitem>weather.europe.germany</listitem>
+ <listitem>weather.europe.germany.berlin</listitem>
+ <listitem>company.engineering.repository</listitem>
+ </itemizedlist>
+ </para>
+ <para>
+ Within the routing key hierarchy two wildcard characters are defined.
+ <itemizedlist>
+ <listitem><command>*</command> matches one field</listitem>
+ <listitem><command>#</command> matches zero or more fields</listitem>
+ </itemizedlist>
+ </para>
+ <para>
+ Suppose an ACL rule file is:
+ </para>
+ <para>
+ <programlisting>
+ acl allow-log uHash1@COMPANY publish exchange name=X routingkey=a.#.b
+ acl deny all all
+ </programlisting>
+ </para>
+ <para>
+ When user uHash1@COMPANY attempts to publish to exchange X the ACL will return these results:
+
+ <table id="tabl-Messaging_User_Guide-ACL_Syntax-ACL_TopicExchangeMatch">
+ <title>Topic Exchange Wildcard Match Examples</title>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>routingkey in publish to exchange X</entry>
+ <entry>result</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry> <command>a.b</command> </entry>
+ <entry>allow-log</entry>
+ </row>
+ <row>
+ <entry> <command>a.x.b</command> </entry>
+ <entry>allow-log</entry>
+ </row>
+ <row>
+ <entry> <command>a.x.y.zz.b</command> </entry>
+ <entry>allow-log</entry>
+ </row>
+ <row>
+ <entry> <command>a.b.</command> </entry>
+ <entry>deny</entry>
+ </row>
+ <row>
+ <entry> <command>q.x.b</command> </entry>
+ <entry>deny</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
- </section>
+ </para>
+ </section>
+
+ </section>
+
+
+
+ </section>
<section id="sect-Messaging_User_Guide-Authorization-ACL_Rule_Matching">
<title>ACL Rule Matching</title>
@@ -839,51 +1328,51 @@ acl permission {<group-name>|<user-name>|"all"} {action|"all"} [object|"all"
<para>
The following illustration shows how ACL rules are processed to find matching rules.
<programlisting><![CDATA[
-# Example of rule matching
-#
-# Using this ACL file content:
-
-(1) acl deny bob create exchange name=test durable=true passive=true
-(2) acl deny bob create exchange name=myEx type=direct
-(3) acl allow all all
-
-#
-# Lookup 1. id:bob action:create objectType:exchange name=test
-# {durable=false passive=false type=direct alternate=}
-#
-# ACL Match Processing:
-# 1. Rule 1 passes minimum criteria with user bob, action create,
-# and object exchange.
-# 2. Rule 1 matches name=test.
-# 3. Rule 1 does not match the rule's durable=true with the requested
-# lookup of durable=false.
-# 4. Rule 1 does not control the decision and processing continues
-# to Rule 2.
-# 5. Rule 2 passes minimum criteria with user bob, action create,
-# and object exchange.
-# 6. Rule 2 does not match the rule's name=myEx with the requested
-# lookup of name=test.
-# 7. Rule 2 does not control the decision and processing continues
-# to Rule 3.
-# 8. Rule 3 matches everything and the decision is 'allow'.
-#
-# Lookup 2. id:bob action:create objectType:exchange name=myEx
-# {durable=true passive=true type=direct alternate=}
-#
-# ACL Match Processing:
-# 1. Rule 1 passes minimum criteria with user bob, action create,
-# and object exchange.
-# 6. Rule 1 does not match the rule's name=test with the requested
-# lookup of name=myEx.
-# 4. Rule 1 does not control the decision and processing continues
-# to Rule 2.
-# 5. Rule 2 passes minimum criteria with user bob, action create,
-# and object exchange.
-# 2. Rule 2 matches name=myEx.
-# 3. Rule 2 matches the rule's type=direct with the requested
-# lookup of type=direct.
-# 8. Rule 2 is the matching rule and the decision is 'deny'.
-#
+ # Example of rule matching
+ #
+ # Using this ACL file content:
+
+ (1) acl deny bob create exchange name=test durable=true passive=true
+ (2) acl deny bob create exchange name=myEx type=direct
+ (3) acl allow all all
+
+ #
+ # Lookup 1. id:bob action:create objectType:exchange name=test
+ # {durable=false passive=false type=direct alternate=}
+ #
+ # ACL Match Processing:
+ # 1. Rule 1 passes minimum criteria with user bob, action create,
+ # and object exchange.
+ # 2. Rule 1 matches name=test.
+ # 3. Rule 1 does not match the rule's durable=true with the requested
+ # lookup of durable=false.
+ # 4. Rule 1 does not control the decision and processing continues
+ # to Rule 2.
+ # 5. Rule 2 passes minimum criteria with user bob, action create,
+ # and object exchange.
+ # 6. Rule 2 does not match the rule's name=myEx with the requested
+ # lookup of name=test.
+ # 7. Rule 2 does not control the decision and processing continues
+ # to Rule 3.
+ # 8. Rule 3 matches everything and the decision is 'allow'.
+ #
+ # Lookup 2. id:bob action:create objectType:exchange name=myEx
+ # {durable=true passive=true type=direct alternate=}
+ #
+ # ACL Match Processing:
+ # 1. Rule 1 passes minimum criteria with user bob, action create,
+ # and object exchange.
+ # 2. Rule 1 does not match the rule's name=test with the requested
+ # lookup of name=myEx.
+ # 3. Rule 1 does not control the decision and processing continues
+ # to Rule 2.
+ # 4. Rule 2 passes minimum criteria with user bob, action create,
+ # and object exchange.
+ # 5. Rule 2 matches name=myEx.
+ # 6. Rule 2 matches the rule's type=direct with the requested
+ # lookup of type=direct.
+ # 7. Rule 2 is the matching rule and the decision is 'deny'.
+ #
]]></programlisting>
</para>
@@ -892,38 +1381,38 @@ acl permission {<group-name>|<user-name>|"all"} {action|"all"} [object|"all"
<section id="sect-Messaging_User_Guide-Authorization-Specifying_ACL_Permissions">
<title>Specifying ACL Permissions</title>
<para>
- Now that we have seen the ACL syntax, we will provide representative examples and guidelines for ACL files.
+ Now that we have seen the ACL syntax, we will provide representative examples and guidelines for ACL files.
</para>
<para>
Most ACL files begin by defining groups:
</para>
<programlisting>
-group admin ted@QPID martin@QPID
-group user-consume martin@QPID ted@QPID
-group group2 kim@QPID user-consume rob@QPID
-group publisher group2 \
-tom@QPID andrew@QPID debbie@QPID
+ group admin ted@QPID martin@QPID
+ group user-consume martin@QPID ted@QPID
+ group group2 kim@QPID user-consume rob@QPID
+ group publisher group2 \
+ tom@QPID andrew@QPID debbie@QPID
</programlisting>
<para>
Rules in an ACL file grant or deny specific permissions to users or groups:
</para>
<programlisting>
-acl allow carlt@QPID create exchange name=carl.*
-acl allow rob@QPID create queue
-acl allow guest@QPID bind exchange name=amq.topic routingkey=stocks.rht.#
-acl allow user-consume create queue name=tmp.*
-
-acl allow publisher publish all durable=false
-acl allow publisher create queue name=RequestQueue
-acl allow consumer consume queue durable=true
-acl allow fred@QPID create all
-acl allow bob@QPID all queue
-acl allow admin all
-acl allow all consume queue
-acl allow all bind exchange
-acl deny all all
+ acl allow carlt@QPID create exchange name=carl.*
+ acl allow rob@QPID create queue
+ acl allow guest@QPID bind exchange name=amq.topic routingkey=stocks.rht.#
+ acl allow user-consume create queue name=tmp.*
+
+ acl allow publisher publish all durable=false
+ acl allow publisher create queue name=RequestQueue
+ acl allow consumer consume queue durable=true
+ acl allow fred@QPID create all
+ acl allow bob@QPID all queue
+ acl allow admin all
+ acl allow all consume queue
+ acl allow all bind exchange
+ acl deny all all
</programlisting>
<para>
In the previous example, the last line, <literal>acl deny all all</literal>, denies all authorizations that have not been specifically granted. This is the default, but it is useful to include it explicitly on the last line for the sake of clarity. If you want to grant all rights by default, you can specify <literal>acl allow all all</literal> in the last line.
@@ -933,10 +1422,10 @@ acl deny all all
</para>
<para>
<programlisting>
-group users alice@QPID bob@QPID charlie@QPID
-acl deny charlie@QPID create queue
-acl allow users create queue
-acl deny all all
+ group users alice@QPID bob@QPID charlie@QPID
+ acl deny charlie@QPID create queue
+ acl allow users create queue
+ acl deny all all
</programlisting>
</para>
<para>
@@ -947,42 +1436,74 @@ acl deny all all
</para>
<programlisting>
-group allUsers guest@QPID
-....
-acl deny-log allUsers create link
-acl deny-log allUsers access method name=connect
-acl deny-log allUsers access method name=echo
-acl allow all all
+ group allUsers guest@QPID
+ ...
+ acl deny-log allUsers create link
+ acl deny-log allUsers access method name=connect
+ acl deny-log allUsers access method name=echo
+ acl allow all all
</programlisting>
</section>
-
- <section id="sect-Messaging_User_Guide-Authorization-Specifying_ACL_Connection_Limits">
- <title>Specifying ACL Connection Limits</title>
- <para>
- The ACL module creates two broker command line switches that set limits on the number of connections allowed per user or per client host address. These settings are not specified in the ACL file.
- </para>
- <para>
-<programlisting>
---acl-max-connect-per-user N_USER
---acl-max-connect-per-ip N_IP
-</programlisting>
- </para>
- <para>
- If either of these switches is not specified or the value specified is zero then the corresponding connection limit is not enforced.
- </para>
- <para>
- If a limit is set for user connections then all users are limited to that number of connections regardless of the client IP address the users are coming from.
- </para>
- <para>
- If a limit is set for IP connections then connections for a given IP address are limited regardless of the user credentials presented with the connection.
- </para>
- <para>
- Note that addresses using different transports are counted separately even though the host is actually the same physical machine. In the setting illustrated above a host would allow N_IP connections from [::1] IPv6 transport localhost and another N_IP connections from [127.0.0.1] IPv4 transport localhost.
- </para>
- </section>
-
- </section>
+ </section>
+
+ <section id="sect-Messaging_User_Guide-Authorization-Specifying_ACL_Quotas">
+ <title>User Connection and Queue Quotas</title>
+ The ACL module enforces various quotas and thereby limits user activity.
+
+ <section id="sect-Messaging_User_Guide-Authorization-Specifying_ACL_Connection_Limits">
+ <title>Connection Limits</title>
+ <para>
+ The ACL module creates broker command line switches that set limits on the number of concurrent connections allowed per user or per client host address. These settings are not specified in the ACL file.
+ </para>
+ <para>
+ <programlisting>
+ --max-connections N
+ --max-connections-per-user N
+ --max-connections-per-ip N
+ </programlisting>
+ </para>
+ <para>
+ If a switch is not specified or the value specified is zero then the corresponding connection limit is not enforced.
+ </para>
+ <para>
+ <command>max-connections</command> specifies an upper limit for all user connections.
+ </para>
+ <para>
+ <command>max-connections-per-user</command> specifies an upper limit for each user based on the authenticated user name. This limit is enforced regardless of the client IP address from which the connection originates.
+ </para>
+ <para>
+ <command>max-connections-per-ip</command> specifies an upper limit for connections for all users based on the originating client IP address. This limit is enforced regardless of the user credentials presented with the connection.
+ <itemizedlist>
+ <listitem>
+ Note that addresses using different transports are counted separately even though the originating host is actually the same physical machine. In the setting illustrated above a host would allow N_IP connections from [::1] IPv6 transport localhost and another N_IP connections from [127.0.0.1] IPv4 transport localhost.
+ </listitem>
+ <listitem>
+ The max-connections-per-ip and max-connections-per-user counts are active simultaneously. From a given client system users may be denied access to the broker by either connection limit.
+ </listitem>
+ </itemizedlist>
+ </para>
+ </section>
+
+ <section id="sect-Messaging_User_Guide-Authorization-Specifying_ACL_Queue_Limits">
+ <title>Queue Limits</title>
+ <para>
+ The ACL module creates a broker command line switch that set limits on the number of queues each user is allowed to create. This settings is not specified in the ACL file.
+ </para>
+ <para>
+ <programlisting>
+ --max-queues-per-user N
+ </programlisting>
+ </para>
+ <para>
+ If this switch is not specified or the value specified is zero then the queue limit is not enforced.
+ </para>
+ <para>
+ The queue limit is set for all users on the broker based on the authenticated user name.
+ </para>
+ </section>
+
+ </section>
<!-- ########################### --> <section id="sect-Messaging_User_Guide-Security-Encryption_using_SSL">
<title>Encryption using SSL</title>
diff --git a/doc/book/src/java-broker/AMQP-Messaging-Broker-Java-Book.xml b/doc/book/src/java-broker/AMQP-Messaging-Broker-Java-Book.xml
index 54c2984d0a..b2dbd969bc 100644
--- a/doc/book/src/java-broker/AMQP-Messaging-Broker-Java-Book.xml
+++ b/doc/book/src/java-broker/AMQP-Messaging-Broker-Java-Book.xml
@@ -8,66 +8,33 @@
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.
-
--->
-
-<book>
- <title>AMQP Messaging Broker (Implemented in Java)</title>
- <preface>
- <title>Introduction</title>
- <para>Qpid provides two AMQP messaging brokers:</para>
-
- <itemizedlist>
- <listitem><para>Implemented in C++ - high performance, low latency, and RDMA support.</para></listitem>
- <listitem><para>Implemented in Java - Fully JMS compliant, runs on any Java platform.</para></listitem>
- </itemizedlist>
-
- <para>Both AMQP messaging brokers support clients in multiple languages, as long as the messaging client and the messaging broker use the same version of AMQP.</para>
-
- <para>This manual contains information specific to the broker that is implemented in Java.</para>
- </preface>
-
-<chapter id="Java-General-User-Guides">
- <title>General User Guides</title>
-
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Feature-Guide.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Qpid-Java-FAQ.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Environment-Variables.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Qpid-Troubleshooting-Guide.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Broker-Configuration-Guide.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="HA-Guide.xml"/>
-</chapter>
-
-<chapter id="Qpid-Java-Broker-HowTos">
-<title>How Tos</title>
-
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Add-New-Users.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Configure-ACLs.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Configure-Java-Qpid-to-use-a-SSL-connection.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Configure-Log4j-CompositeRolling-Appender.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Configure-the-Broker-via-config.xml.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Configure-the-Virtual-Hosts-via-virtualhosts.xml.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Debug-using-log4j.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="How-to-Tune-M3-Java-Broker-Performance.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Qpid-Java-Build-How-To.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="OtherQueueTypes.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="How-to-Use-SlowConsumerDisconnect.xml"/>
-</chapter>
+-->
-<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Qpid-JMX-Management-Console.xml"/>
+<book xmlns:xi="http://www.w3.org/2001/XInclude">
+<title>AMQP Messaging Broker (Java)</title>
+
+<xi:include href="Java-Broker-Introduction.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Installation.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Getting-Started.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Concepts.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Virtual-Hosts.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Exchanges.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Queues.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Stores.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Configuring-And-Managing.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Security.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Runtime.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-High-Availability.xml"/>
+<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Miscellaneous.xml"/>
-<chapter id="QpidJavaBroker-ManagementTools">
-<title>Management Tools</title>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Qpid-Java-Broker-Management-CLI.xml"/>
-</chapter>
</book>
diff --git a/doc/book/src/java-broker/Add-New-Users.xml b/doc/book/src/java-broker/Add-New-Users.xml
deleted file mode 100644
index dc34bcc5c9..0000000000
--- a/doc/book/src/java-broker/Add-New-Users.xml
+++ /dev/null
@@ -1,237 +0,0 @@
-<?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.
-
--->
-
-<section><title>
- Add New Users
- </title><para>
- The Qpid Java Broker has a single reference source (<xref linkend="qpid_PrincipalDatabase"/>) that
- defines all the users in the system.
- </para><para>
- To add a new user to the broker the password file must be
- updated. The details about adding entries and when these updates
- take effect are dependent on the file format each of which are
- described below.
- </para>
-
- <section role="h2" id="AddNewUsers-AvailablePasswordfileformats"><title>
- Available
- Password file formats
- </title>
- <para>
- There are currently two different file formats available for use
- depending on the PrincipalDatabase that is desired. In all cases
- the clients need not be aware of the type of PrincipalDatabase in
- use they only need support the SASL mechanisms they provide.
- </para><itemizedlist>
- <listitem><para>
- <xref linkend="AddNewUsers-Plain"/>
- </para></listitem>
- <listitem><para>
- <xref linkend="AddNewUsers-Base64MD5PasswordFileFormat"/>
- </para></listitem>
- </itemizedlist><para>
-
- </para>
-
- <section role="h3" id="AddNewUsers-Plain"><title>
- Plain
- </title>
- <para>
- The plain file has the following format:
- </para>
- <programlisting>
-# Plain password authentication file.
-# default name : passwd
-# Format &lt;username&gt;:&lt;password&gt;
-#e.g.
-martin:password
-</programlisting>
- <para>
- As the contents of the file are plain text and the password is
- taken to be everything to the right of the ':'(colon). The
- password, therefore, cannot contain a ':' colon, but this can be
- used to delimit the password.
- </para><para>
- Lines starting with a '#' are treated as comments.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="AddNewUsers-Whereisthepasswordfileformybroker-3F"><title>
- Where is
- the password file for my broker ?
- </title>
- <para>
- The location of the password file in use for your broker is as
- configured in your config.xml file.
- </para>
- <programlisting>
-&lt;principal-databases&gt;
- &lt;principal-database&gt;
- &lt;name&gt;passwordfile&lt;/name&gt;
- &lt;class&gt;org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase&lt;/class&gt;
- &lt;attributes&gt;
- &lt;attribute&gt;
- &lt;name&gt;passwordFile&lt;/name&gt;
- &lt;value&gt;${conf}/passwd&lt;/value&gt;
- &lt;/attribute&gt;
- &lt;/attributes&gt;
- &lt;/principal-database&gt;
- &lt;/principal-databases&gt;
-</programlisting>
- <para>
- So in the example config.xml file this password file lives in the
- directory specified as the conf directory (at the top of your
- config.xml file).
- </para><para>
- If you wish to use Base64 encoding for your password file, then
- in the &lt;class&gt; element above you should specify
- org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase
- </para><para>
- The default is:
- </para>
- <programlisting>
- &lt;conf&gt;${prefix}/etc&lt;/conf&gt;
-</programlisting>
-<!--h3--></section>
-
-
- <section role="h3" id="AddNewUsers-Base64MD5PasswordFileFormat"><title>
- Base64MD5
- Password File Format
- </title>
- <para>
- This format can be used to ensure that SAs cannot read the plain
- text password values from your password file on disk.
- </para><para>
- The Base64MD5 file uses the following format:
- </para>
- <programlisting>
-# Base64MD5 password authentication file
-# default name : qpid.passwd
-# Format &lt;username&gt;:&lt;Base64 Encoded MD5 hash of the users password&gt;
-#e.g.
-martin:X03MO1qnZdYdgyfeuILPmQ==
-</programlisting>
- <para>
- As with the Plain format the line is delimited by a ':'(colon).
- The password field contains the MD5 Hash of the users password
- encoded in Base64.
- </para><para>
- This file is read on broker start-up and is not re-read.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="AddNewUsers-HowcanIupdateaBase64MD5passwordfile-3F"><title>
- How can
- I update a Base64MD5 password file ?
- </title>
- <para>
- To update the file there are two options:
- </para><orderedlist>
- <listitem><para>Edit the file by hand using the <emphasis>qpid-passwd</emphasis> tool
- that will generate the required lines. The output from the tool
- is the text that needs to be copied in to your active password
- file. This tool is located in the broker bin directory.
- Eventually it is planned for this tool to emulate the
- functionality of <xref linkend="qpid_htpasswd"/>
- for qpid passwd files.
- <emphasis>NOTE:</emphasis> For the changes to be seen by the broker you must
- either restart the broker or reload the data with the
- management tools (see <xref linkend="Qpid-JMX-Management-Console-User-Guide"/>)
- </para></listitem>
- <listitem><para>Use the management tools to create a new user. The changes
- will be made by the broker to the password file and the new user
- will be immediately available to the system (see <xref linkend="Qpid-JMX-Management-Console-User-Guide"/>).
- </para></listitem>
- </orderedlist>
-<!--h3--></section>
-<!--h2--></section>
-
-
- <section role="h2" id="AddNewUsers-Dynamicchangestopasswordfiles."><title>
- Dynamic
- changes to password files.
- </title>
- <para>
- The Plain password file and the Base64MD5 format file are both
- only read once on start up.
- </para><para>
- To make changes dynamically there are two options, both require
- administrator access via the Management Console (see <xref linkend="Qpid-JMX-Management-Console-User-Guide"/>)
- </para><orderedlist>
- <listitem><para>You can replace the file and use the console to reload its
- contents.
- </para></listitem>
- <listitem><para>The management console provides an interface to create,
- delete and amend the users. These changes are written back to the
- active password file.
- </para></listitem>
- </orderedlist>
-<!--h2--></section>
-
- <section role="h2" id="AddNewUsers-HowpasswordfilesandPrincipalDatabasesrelatetoauthenticationmechanisms"><title>
- How password files and PrincipalDatabases relate to
- authentication mechanisms
- </title>
- <para>
- For each type of password file a PrincipalDatabase exists that
- parses the contents. These PrincipalDatabases load various SASL
- mechanism based on their supportability. e.g. the Base64MD5 file
- format can't support Plain authentication as the plain password
- is not available. Any client connecting need only be concerned
- about the SASL module they support and not the type of
- PrincipalDatabase. So I client that understands CRAM-MD5 will
- work correctly with a Plain and Base64MD5 PrincipalDatabase.
- </para><table>
- <title>File Format and Principal Database</title><tgroup cols="2">
- <tbody>
- <row>
- <entry>
- FileFormat/PrincipalDatabase
- </entry>
- <entry>
- SASL
- </entry>
- </row>
- <row>
- <entry>
- Plain
- </entry>
- <entry>
- AMQPLAIN PLAIN CRAM-MD5
- </entry>
- </row>
- <row>
- <entry>
- Base64MD5
- </entry>
- <entry>
- CRAM-MD5 CRAM-MD5-HASHED
- </entry>
- </row>
- </tbody>
- </tgroup></table><para>
- For details of SASL support see <xref linkend="qpid_Qpid-Interoperability-Documentation"/>
- </para>
-<!--h2--></section>
-
-</section>
diff --git a/doc/book/src/java-broker/Broker-Configuration-Guide.xml b/doc/book/src/java-broker/Broker-Configuration-Guide.xml
deleted file mode 100644
index 558d17c63c..0000000000
--- a/doc/book/src/java-broker/Broker-Configuration-Guide.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?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.
-
--->
-
-<section id="Java-Broker-Configuration-Guide">
- <title>Broker Configuration Guide </title>
-
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Producer-Flow-Control.xml"/>
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Topic-Configuration.xml"/>
-</section>
diff --git a/doc/book/src/java-broker/Configure-ACLs.xml b/doc/book/src/java-broker/Configure-ACLs.xml
deleted file mode 100644
index e82f2a86d0..0000000000
--- a/doc/book/src/java-broker/Configure-ACLs.xml
+++ /dev/null
@@ -1,441 +0,0 @@
-<?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.
-
--->
-
-<section id="Configuring-ACLS">
- <title>
- Configuring ACLs
- </title>
- <para>
- In Qpid, ACLs specify which actions can be performed by each authenticated user. To enable the ACL &lt;acl/&gt; element is used within the
- &lt;security/&gt; element of the configuration XML. In the Java Broker, the ACL may be imposed broker wide or applied to individual virtual
- hosts. The &lt;acl/&gt; references a text file containing the ACL rules. By convention, this file should have a .acl extension.
- </para>
-
-
- <section role="h3" id="ConfigureACLs-EnablingACL">
- <title>
- Enabling ACLs
- </title>
-
- <para>
- To apply an ACL broker-wide, add the following to the config.xml (Assuming that <replaceable>conf</replaceable> has been set to a suitable
- location such as ${QPID_HOME}/etc)
- </para>
-
- <programlisting>
- &lt;broker&gt;
- ...
- &lt;security&gt;
- ...
- &lt;acl&gt;<replaceable>${conf}/broker.acl</replaceable>&lt;/acl&gt;
- &lt;/security&gt;
- &lt;/broker&gt;
- </programlisting>
-
- <para>
- </para>
-
- <para>
- To apply an ACL on a single virtualhost named <replaceable>test</replaceable>, add the following to the config.xml:
- </para>
-
- <programlisting>
- &lt;virtualhost&gt;
- ...
- &lt;name&gt;test&lt;/name&gt;
- &lt;test&gt;
- ...
- &lt;security&gt;
- &lt;acl&gt;<replaceable>${conf}/vhost_test.acl</replaceable>&lt;/acl&gt;
- &lt;/security&gt;
- &lt;/test&gt;
- &lt;/virtualhost&gt;
- </programlisting>
- </section>
-
- <section role="h3" id="ConfigureACLs-WriteACL">
- <title>
- Writing .acl files
- </title>
-
- <para>
- The ACL file consists of a series of rules and group definitions. Each rule grants or denies specific rights to a user or group. Group
- definitions declare groups of users and serve to make the ACL file more concise.
- </para>
- <para>
- Each ACL rule grants (or denies) a particular action on a object to a user. The rule may be augmented with one or more properties, restricting
- the rule's applicability.
- </para>
- <programlisting>
- ACL ALLOW alice CREATE QUEUE # Grants alice permission to create all queues.
- ACL DENY bob CREATE QUEUE name="myqueue" # Denies bob permission to create a queue called "myqueue"
- </programlisting>
- <para>
- The ACL is considered in strict line order with the first matching rule taking precedence over all those that follow. In the following
- example, if the user bob tries to create an exchange "myexch", the operation will be allowed by the first rule. The second rule will
- never be considered.
- </para>
- <programlisting>
- ACL ALLOW bob ALL EXCHANGE
- ACL DENY bob CREATE EXCHANGE name="myexch" # Dead rule
- </programlisting>
- <para>
- If the desire is to allow bob to create all exchanges except "myexch", order of the rules must be reversed:
- </para>
- <programlisting>
- ACL DENY bob CREATE EXCHANGE name="myexch"
- ACL ALLOW bob ALL EXCHANGE
- </programlisting>
- <para>
- All ACL files end with a implict rule denying all operations to all users. It is as if each file ends with
- <programlisting>ACL DENY ALL ALL </programlisting>
- To allow all operations, other than those controlled by earlier use <programlisting>ACL ALLOW ALL ALL </programlisting> instead.
- </para>
- <para>
- When writing a new ACL, a good approach is to begin with an .acl file containing only <programlisting>ACL DENY-LOG ALL ALL</programlisting>
- which will cause the Broker to deny all operations with details of the denial logged to the Qpid log file. Build up the ACL rule by rule,
- gradually working through the use-cases of your system. Once the ACL is complete, switch the DEBY-LOG to DENY for optimum performamce.
- </para>
- <para>
- ACL rules are very powerful: it is possible to write very expressive rules permissioning every AMQP objects enumerating all object
- properties. Most projects probably won't need this degree of flexibility. A reasonable approach is to choose to apply permissions
- at a certain level of abstraction (i.e. QUEUE) and apply consistently across the whole system.
- </para>
- </section>
-
- <section role="h4" id="ConfigureACLs-Syntax">
- <title>
- Syntax
- </title>
-
- <para>
- ACL rules must follow this syntax:
- </para>
- <programlisting>
- ACL {permission} {&lt;group-name&gt;|&lt;user-name>&gt;|ALL} {action|ALL} [object|ALL] [property="&lt;property-value&gt;"]
- </programlisting>
-
- <para>
- GROUP definitions must follow this syntax:
- </para>
- <programlisting>
- GROUP {group name} {username 1}..{username n} # Where username is a username, or a groupname.
- </programlisting>
-
- <para>
- Comments may be introduced with the hash (#) character and are ignored. Long lines can be broken with the slash (\) character.
- </para>
- <programlisting>
- # A comment
- ACL ALLOW admin CREATE ALL # Also a comment
- ACL DENY guest \
- ALL ALL # A broken line
- GROUP securegroup bob \
- alice # Another broker line
- </programlisting>
- </section>
- <table id="tabl-ConfigureACLs-Syntax_permissions">
- <title>ACL Rules: permission</title>
- <tgroup cols="2">
- <tbody>
- <row>
- <entry><command>ALLOW</command></entry>
- <entry><para>Allow the action</para></entry>
- </row>
- <row>
- <entry><command>ALLOW-LOG</command></entry>
- <entry><para> Allow the action and log the action in the log </para></entry>
- </row>
- <row>
- <entry><command>DENY</command></entry>
- <entry><para> Deny the action</para></entry>
- </row>
- <row>
- <entry><command>DENY-LOG</command></entry>
- <entry><para> Deny the action and log the action in the log</para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <table id="tabl-ConfigureACLs-Syntax_actions">
- <title>ACL Rules:action</title>
- <tgroup cols="2">
- <tbody>
- <row>
- <entry> <command>CONSUME</command> </entry>
- <entry> <para> Applied when subscriptions are created </para> </entry>
- </row>
- <row>
- <entry> <command>PUBLISH</command> </entry>
- <entry> <para> Applied on a per message basis on publish message transfers</para> </entry>
- </row>
- <row>
- <entry> <command>CREATE</command> </entry>
- <entry> <para> Applied when an object is created, such as bindings, queues, exchanges</para> </entry>
- </row>
- <row>
- <entry> <command>ACCESS</command> </entry>
- <entry> <para> Applied when an object is read or accessed</para> </entry>
- </row>
- <row>
- <entry> <command>BIND</command> </entry>
- <entry> <para> Applied when queues are bound to exchanges</para> </entry>
- </row>
- <row>
- <entry> <command>UNBIND</command> </entry>
- <entry> <para> Applied when queues are unbound from exchanges</para> </entry>
- </row>
- <row>
- <entry> <command>DELETE</command> </entry>
- <entry> <para> Applied when objects are deleted </para> </entry>
- </row>
- <row>
- <entry> <command>PURGE</command> </entry> <entry>
- <para>Applied when purge the contents of a queue</para> </entry>
- </row>
- <row>
- <entry> <command>UPDATE</command> </entry>
- <entry> <para> Applied when an object is updated </para> </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <table id="tabl-ConfigureACLs-Syntax_objects">
- <title>ACL Rules:object</title>
- <tgroup cols="2">
- <tbody>
- <row>
- <entry> <command>QUEUE</command> </entry>
- <entry> <para> A queue </para> </entry>
- </row>
- <row>
- <entry> <command>EXCHANGE</command> </entry>
- <entry> <para> An exchange </para> </entry>
- </row>
- <row>
- <entry> <command>VIRTUALHOST</command> </entry>
- <entry> <para> A virtualhost (Java Broker only)</para> </entry>
- </row>
- <row>
- <entry> <command>METHOD</command> </entry>
- <entry> <para> Management or agent or broker method (Java Broker only)</para> </entry>
- </row>
- <row>
- <entry> <command>BROKER</command> </entry>
- <entry> <para> The broker (not currently used in Java Broker)</para> </entry>
- </row>
- <row>
- <entry> <command>LINK</command> </entry>
- <entry> <para> A federation or inter-broker link (not currently used in Java Broker)</para> </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <table id="tabl-ConfigureACLs-Syntax_properties">
- <title>ACL Rules:property</title>
- <tgroup cols="2">
- <tbody>
- <row>
- <entry><command>name</command> </entry>
- <entry> <para> String. Object name, such as a queue name, exchange name or JMX method name. </para> </entry>
- </row>
- <row>
- <entry> <command>durable</command> </entry>
- <entry> <para> Boolean. Indicates the object is durable </para> </entry>
- </row>
- <row>
- <entry> <command>routingkey</command> </entry>
- <entry> <para> String. Specifies routing key </para> </entry>
- </row>
- <row>
- <entry> <command>passive</command> </entry>
- <entry> <para> Boolean. Indicates the presence of a <parameter>passive</parameter> flag </para> </entry>
- </row>
- <row>
- <entry> <command>autodelete</command> </entry>
- <entry> <para> Boolean. Indicates whether or not the object gets deleted when the connection is closed </para> </entry>
- </row>
- <row>
- <entry> <command>exclusive</command> </entry>
- <entry> <para> Boolean. Indicates the presence of an <parameter>exclusive</parameter> flag </para> </entry>
- </row>
- <row>
- <entry> <command>temporary</command> </entry>
- <entry> <para> Boolean. Indicates the presence of an <parameter>temporary</parameter> flag </para> </entry>
- </row>
- <row>
- <entry> <command>type</command> </entry>
- <entry> <para> String. Type of object, such as topic, fanout, or xml </para> </entry>
- </row>
- <row>
- <entry> <command>alternate</command> </entry>
- <entry> <para> String. Name of the alternate exchange </para> </entry>
- </row>
- <row>
- <entry> <command>queuename</command> </entry>
- <entry> <para> String. Name of the queue (used only when the object is something other than <parameter>queue</parameter> </para> </entry>
- </row>
- <row>
- <entry> <command>component</command> </entry>
- <entry> <para> String. JMX component name (Java Broker only)</para> </entry>
- </row>
- <row>
- <entry> <command>schemapackage</command> </entry>
- <entry> <para> String. QMF schema package name (Not used in Java Broker)</para> </entry>
- </row>
- <row>
- <entry> <command>schemaclass</command> </entry>
- <entry> <para> String. QMF schema class name (Not used in Java Broker)</para> </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <table id="tabl-ConfigureACLs-Syntax_javacomponents">
- <title>ACL rules:components (Java Broker only)</title>
- <tgroup cols="3">
- <tbody>
- <row>
- <entry> <command>UserManagement</command> </entry>
- <entry> <para>User maintainance; create/delete/view users, change passwords etc</para> </entry>
- <entry> <para>permissionable at broker level only</para> </entry>
- </row>
- <row>
- <entry> <command>ConfigurationManagement</command> </entry>
- <entry> <para>Dynammically reload configuration from disk.</para> </entry>
- <entry> <para>permissionable at broker level only</para> </entry>
- </row>
- <row>
- <entry> <command>LoggingManagement</command> </entry>
- <entry> <para>Dynammically control Qpid logging level</para> </entry>
- <entry> <para>permissionable at broker level only</para> </entry>
- </row>
- <row>
- <entry> <command>ServerInformation</command> </entry>
- <entry> <para>Read-only information regarding the Qpid: version number etc</para> </entry>
- <entry> <para>permissionable at broker level only</para> </entry>
- </row>
- <row>
- <entry> <command>VirtualHost.Queue</command> </entry>
- <entry> <para>Queue maintainance; copy/move/purge/view etc</para> </entry>
- </row>
- <row>
- <entry> <command>VirtualHost.Exchange</command> </entry>
- <entry> <para>Exchange maintenance; bind/unbind queues to exchanges</para> </entry>
- </row>
- <row>
- <entry> <command>VirtualHost.VirtualHost</command> </entry>
- <entry> <para>Virtual host maintainace; create/delete exchanges, queues etc</para> </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <section role="h4" id="ConfigureACLs-WorkedExamples">
- <title>
- Worked Examples
- </title>
- <para>
- Here are three example ACLs illustrating some common use-cases.
- </para>
- <section role="h4" id="ConfigureACLs-WorkedExample1">
- <title>
- Worked example 1 - Management rights
- </title>
- <para>
- Suppose you wish to permission two users: a user 'operator' must be able to perform all Management operations, and
- a user 'readonly' must be enable to perform only read-only functions. Neither 'operator' nor 'readonly'
- should be allow to connect for messaging.
- </para>
- <programlisting>
- # Give operator permission to execute all JMX Methods
- ACL ALLOW operator ALL METHOD
- # Give operator permission to execute only read-only JMX Methods
- ACL ALLOW readonly ACCESS METHOD
- # Deny operator/readonly permission to perform messaging.
- ACL DENY operator ACCESS VIRTUALHOST
- ACL DENY readonly ACCESS VIRTUALHOST
- ...
- ... rules for other users
- ...
- # Explicitly deny all (log) to eveyone
- ACL DENY-LOG ALL ALL
- </programlisting>
- </section>
- <section role="h4" id="ConfigureACLs-WorkedExample2">
- <title>
- Worked example 2 - User maintainer group
- </title>
- <para>
- Suppose you wish to restrict User Management operations to users belonging to a group 'usermaint'. No other user
- is allowed to perform user maintainence This example illustrates the permissioning of a individual component
- and a group definition.
- </para>
- <programlisting>
- # Create a group usermaint with members bob and alice
- GROUP usermaint bob alice
- # Give operator permission to execute all JMX Methods
- ACL ALLOW usermaint ALL METHOD component="UserManagement"
- ACL DENY ALL ALL METHOD component="UserManagement"
- ...
- ... rules for other users
- ...
- ACL DENY-LOG ALL ALL
- </programlisting>
- </section>
- <section role="h4" id="ConfigureACLs-WorkedExample3">
- <title>
- Worked example 3 - Request/Response messaging
- </title>
- <para>
- Suppose you wish to permission a system using a request/response paradigm. Two users: 'client' publishes requests;
- 'server' consumes the requests and generates a response. This example illustrates the permissioning of AMQP exchanges
- and queues.
- </para>
- <programlisting>
- # Allow client and server to connect to the virtual host.
- ACL ALLOW client ACCESS VIRTUALHOST
- ACL ALLOW server ACCESS VIRTUALHOST
-
- # Client side
- # Allow the 'client' user to publish requests to the request queue. As is the norm for the request/response paradigm, the client
- # is required to create a temporary queue on which the server will response. Consequently, there are rules to allow the creation
- # of the temporary queues and consumption of messages from it.
- ACL ALLOW client CREATE QUEUE temporary="true"
- ACL ALLOW client CONSUME QUEUE temporary="true"
- ACL ALLOW client DELETE QUEUE temporary="true"
- ACL ALLOW client BIND EXCHANGE name="amq.direct" temporary="true"
- ACL ALLOW client UNBIND EXCHANGE name="amq.direct" temporary="true"
- ACL ALLOW client PUBLISH EXCHANGE name="amq.direct" routingKey="example.RequestQueue"
-
- # Server side
- # Allow the 'server' user to consume from the request queue and publish a response to the temporary response queue created by
- # client. We also allow the server to create the request queue.
- ACL ALLOW server CREATE QUEUE name="example.RequestQueue"
- ACL ALLOW server CONSUME QUEUE name="example.RequestQueue"
- ACL ALLOW server BIND EXCHANGE
- ACL ALLOW server PUBLISH EXCHANGE name="amq.direct" routingKey="TempQueue*"
-
- ACL DENY-LOG all all
- </programlisting>
- </section>
- </section>
-</section>
diff --git a/doc/book/src/java-broker/Configure-Java-Qpid-to-use-a-SSL-connection.xml b/doc/book/src/java-broker/Configure-Java-Qpid-to-use-a-SSL-connection.xml
deleted file mode 100644
index 838b899337..0000000000
--- a/doc/book/src/java-broker/Configure-Java-Qpid-to-use-a-SSL-connection.xml
+++ /dev/null
@@ -1,84 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Java-SSL"><title>
- Configure Java Qpid to use a SSL connection.
- </title>
-
- <section role="h2" id="ConfigureJavaQpidtouseaSSLconnection.-UsingSSLconnectionwithQpidJava."><title>
- Using SSL connection with Qpid Java.
- </title>
- <para>
- This section will show how to use SSL to enable secure
- connections between a Java client and broker.
- </para>
-<!--h2--></section>
- <section role="h2" id="ConfigureJavaQpidtouseaSSLconnection.-Setup"><title>
- Setup
- </title>
- <section role="h3" id="ConfigureJavaQpidtouseaSSLconnection.-BrokerSetup"><title>
- Broker
- Setup
- </title>
- <para>
- The broker configuration file (config.xml) needs to be updated to
- include the SSL keystore location details.
- </para>
-
-<programlisting>
-&lt;!-- Additions required to Connector Section --&gt;
-
-&lt;ssl&gt;
- &lt;enabled&gt;true&lt;/enabled&gt;
- &lt;sslOnly&gt;true&lt;/sslOnly&gt;
- &lt;keyStorePath&gt;/path/to/keystore.ks&lt;/keyStorePath&gt;
- &lt;keyStorePassword&gt;keystorepass&lt;/keyStorePassword&gt;
-&lt;/ssl&gt;
-</programlisting>
-
- <para>
- The sslOnly option is included here for completeness however this
- will disable the unencrypted port and leave only the SSL port
- listening for connections.
- </para>
-<!--h3--></section>
- <section role="h3" id="ConfigureJavaQpidtouseaSSLconnection.-ClientSetup"><title>
- Client
- Setup
- </title>
- <para>
- The best place to start looking is class
- <emphasis>SSLConfiguration</emphasis> this is provided to the connection
- during creation however there is currently no example that
- demonstrates its use.
- </para>
-<!--h3--></section>
-<!--h2--></section>
-
- <section role="h2" id="ConfigureJavaQpidtouseaSSLconnection.-Performingtheconnection."><title>
- Performing
- the connection.
- </title>
- <para/>
- <!--h2--></section>
-</section>
diff --git a/doc/book/src/java-broker/Configure-Log4j-CompositeRolling-Appender.xml b/doc/book/src/java-broker/Configure-Log4j-CompositeRolling-Appender.xml
deleted file mode 100644
index f52bc55399..0000000000
--- a/doc/book/src/java-broker/Configure-Log4j-CompositeRolling-Appender.xml
+++ /dev/null
@@ -1,150 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Java-Log4j"><title>
- Configure Log4j CompositeRolling Appender
- </title>
- <section role="h2" id="ConfigureLog4jCompositeRollingAppender-HowtoconfiguretheCompositeRollinglog4jAppender"><title>
- How to configure the CompositeRolling log4j Appender
- </title>
- <para>
- There are several sections of our default log4j file that will
- need your attention if you wish to fully use this Appender.
- </para>
-
- <orderedlist>
- <listitem>
- <para>Enable the Appender</para>
- <para>
- The default log4j.xml file uses the FileAppender, swap this for
- the ArchivingFileAppender as follows:
- </para>
- <programlisting>
- &lt;!-- Log all info events to file --&gt;
- &lt;root&gt;
- &lt;priority value="info"/&gt;
-
- &lt;appender-ref ref="ArchivingFileAppender"/&gt;
- &lt;/root&gt;
-</programlisting>
- </listitem>
- <listitem>
- <para>
- Configure the Appender
- </para>
-
- <para>
- The Appender has a number of parameters that can be adjusted
- depending on what you are trying to achieve. For clarity lets
- take a quick look at the complete default appender:
- </para>
- <programlisting>
- &lt;appender name="ArchivingFileAppender" class="org.apache.log4j.QpidCompositeRollingAppender"&gt;
- &lt;!-- Ensure that logs allways have the dateFormat set--&gt;
- &lt;param name="StaticLogFileName" value="false"/&gt;
- &lt;param name="File" value="${QPID_WORK}/log/${logprefix}qpid${logsuffix}.log"/&gt;
- &lt;param name="Append" value="false"/&gt;
- &lt;!-- Change the direction so newer files have bigger numbers --&gt;
- &lt;!-- So log.1 is written then log.2 etc This prevents a lot of file renames at log rollover --&gt;
- &lt;param name="CountDirection" value="1"/&gt;
- &lt;!-- Use default 10MB --&gt;
- &lt;!--param name="MaxFileSize" value="100000"/--&gt;
- &lt;param name="DatePattern" value="'.'yyyy-MM-dd-HH-mm"/&gt;
- &lt;!-- Unlimited number of backups --&gt;
- &lt;param name="MaxSizeRollBackups" value="-1"/&gt;
- &lt;!-- Compress(gzip) the backup files--&gt;
- &lt;param name="CompressBackupFiles" value="true"/&gt;
- &lt;!-- Compress the backup files using a second thread --&gt;
- &lt;param name="CompressAsync" value="true"/&gt;
- &lt;!-- Start at zero numbered files--&gt;
- &lt;param name="ZeroBased" value="true"/&gt;
- &lt;!-- Backup Location --&gt;
- &lt;param name="backupFilesToPath" value="${QPID_WORK}/backup/log"/&gt;
-
- &lt;layout class="org.apache.log4j.PatternLayout"&gt;
- &lt;param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/&gt;
- &lt;/layout&gt;
- &lt;/appender&gt;
-</programlisting>
- <para>
- The appender configuration has three groups of parameter
- configuration.
- </para><para>
- The first group is for configuration of the file name. The
- default is to write a log file to QPID_WORK/log/qpid.log
- (Remembering you can use the logprefix and logsuffix values to
- modify the file name, see Property Config).
- </para>
- <programlisting>
- &lt;!-- Ensure that logs always have the dateFormat set--&gt;
- &lt;param name="StaticLogFileName" value="false"/&gt;
- &lt;param name="File" value="${QPID_WORK}/log/${logprefix}qpid${logsuffix}.log"/&gt;
- &lt;param name="Append" value="false"/&gt;
-</programlisting>
- <para>
- The second section allows the specification of a Maximum File
- Size and a DatePattern that will be used to move on to the next
- file.
- </para><para>
- When MaxFileSize is reached a new log file will be created
- The DataPattern is used to decide when to create a new log file,
- so here a new file will be created for every minute and every
- 10Meg of data. So if 15MB of data is made every minute then there
- will be two log files created each minute. One at the start of
- the minute and a second when the file hit 10MB. When the next
- minute arrives a new file will be made even though it only has
- 5MB of content. For a production system it would be expected to
- be changed to something like 'yyyy-MM-dd' which would make a new
- log file each day and keep the files to a max of 10MB.
- </para><para>
- The final MaxSizeRollBackups allows you to limit the amount of
- disk you are using by only keeping the last n backups.
- </para>
- <programlisting>
- &lt;!-- Change the direction so newer files have bigger numbers --&gt;
- &lt;!-- So log.1 is written then log.2 etc This prevents a lot of file renames at log rollover --&gt;
- &lt;param name="CountDirection" value="1"/&gt;
- &lt;!-- Use default 10MB --&gt;
- &lt;!--param name="MaxFileSize" value="100000"/--&gt;
- &lt;param name="DatePattern" value="'.'yyyy-MM-dd-HH-mm"/&gt;
- &lt;!-- Unlimited number of backups --&gt;
- &lt;param name="MaxSizeRollBackups" value="-1"/&gt;
-</programlisting>
- <para>
- The final section allows the old log files to be compressed and
- copied to a new location.
- </para>
- <programlisting>
- &lt;!-- Compress(gzip) the backup files--&gt;
- &lt;param name="CompressBackupFiles" value="true"/&gt;
- &lt;!-- Compress the backup files using a second thread --&gt;
- &lt;param name="CompressAsync" value="true"/&gt;
- &lt;!-- Start at zero numbered files--&gt;
- &lt;param name="ZeroBased" value="true"/&gt;
- &lt;!-- Backup Location --&gt;
- &lt;param name="backupFilesToPath" value="${QPID_WORK}/backup/log"/&gt;
-</programlisting>
-</listitem>
-</orderedlist>
-<!--h2--></section>
-</section>
diff --git a/doc/book/src/java-broker/Configure-the-Broker-via-config.xml.xml b/doc/book/src/java-broker/Configure-the-Broker-via-config.xml.xml
deleted file mode 100644
index 6a7729acd8..0000000000
--- a/doc/book/src/java-broker/Configure-the-Broker-via-config.xml.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Java-Broker-Config-File">
- <title>
- Configure the Broker via config.xml
- </title>
- <section role="h2" id="ConfiguretheBrokerviaconfig.xml-Brokerconfig.xmlOverview">
- <title>
- Broker config.xml Overview
- </title>
- <para>
- The broker config.xml file which is shipped in the etc directory
- of any Qpid binary distribution details various options and
- configuration for the Java Qpid broker implementation.
- </para>
- <para>
- In tandem with the virtualhosts.xml file, the config.xml file
- allows you to control much of the deployment detail for your Qpid
- broker in a flexible fashion.
- </para>
- <para>
- Note that you can pass the config.xml you wish to use for your
- broker instance to the broker using the -c command line option.
- In turn, you can specify the paths for the broker password file
- and virtualhosts.xml files in your config.xml for simplicity.
- </para>
- <para>
- For more information about command line configuration options
- please see <xref linkend="QpidDesign-Configuration-ConfigurationMethods"/>.
- </para>
- <!--h2-->
- </section>
-
- <section role="h2" id="ConfiguretheBrokerviaconfig.xml-QpidVersion">
- <title>
- Qpid
- Version
- </title>
- <para>
- The config format has changed between versions here you can find
- the configuration details on a per version basis.
- </para>
- <para>
- <xref linkend="qpid_M2-20--20config.xml"/>
- <xref linkend="qpid_M2.1-20--20config.xml"/>
- </para>
- <!--h2-->
- </section>
-
-</section>
diff --git a/doc/book/src/java-broker/Configure-the-Virtual-Hosts-via-virtualhosts.xml.xml b/doc/book/src/java-broker/Configure-the-Virtual-Hosts-via-virtualhosts.xml.xml
deleted file mode 100644
index 804970b923..0000000000
--- a/doc/book/src/java-broker/Configure-the-Virtual-Hosts-via-virtualhosts.xml.xml
+++ /dev/null
@@ -1,131 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Java-Broker-Virtualhosts-Config"><title>
- Configure the Virtual Hosts via virtualhosts.xml
- </title><section role="h2" id="ConfiguretheVirtualHostsviavirtualhosts.xml-virtualhosts.xmlOverview"><title>
- virtualhosts.xml Overview
- </title>
- <para>
- This configuration file contains details of all queues and
- topics, and associated properties, to be created on broker
- startup. These details are configured on a per virtual host
- basis.
- </para><para>
- Note that if you do not add details of a queue or topic you
- intend to use to this file, you must first create a consumer on a
- queue/topic before you can publish to it using Qpid.
- </para><para>
- Thus most application deployments need a virtualhosts.xml file
- with at least some minimal detail.
- </para>
-
- <section role="h3" id="ConfiguretheVirtualHostsviavirtualhosts.xml-XMLFormatwithComments"><title>
- XML Format with Comments
- </title>
- <para>
- The virtualhosts.xml which currently ships as part of the Qpid
- distribution is really targeted at development use, and supports
- various artifacts commonly used by the Qpid development team.
- </para><para>
- As a result, it is reasonably complex. In the example XML below,
- I have tried to simplify one example virtual host setup which is
- possibly more useful for new users of Qpid or development teams
- looking to simply make use of the Qpid broker in their
- deployment.
- </para><para>
- I have also added some inline comments on each section, which
- should give some extra information on the purpose of the various
- elements.
- </para>
-
-
-
- <programlisting>
-&lt;virtualhosts&gt;
- &lt;!-- Sets the default virtual host for connections which do not specify a vh --&gt;
- &lt;default&gt;localhost&lt;/default&gt;
- &lt;!-- Define a virtual host and all it's config --&gt;
- &lt;virtualhost&gt;
- &lt;name&gt;localhost&lt;/name&gt;
- &lt;localhost&gt;
- &lt;!-- Define the types of additional AMQP exchange available for this vh --&gt;
- &lt;!-- Always get amq.direct (for queues) and amq.topic (for topics) by default --&gt;
- &lt;exchanges&gt;
- &lt;!-- Example of declaring an additional exchanges type for developer use only --&gt;
- &lt;exchange&gt;
- &lt;type&gt;direct&lt;/type&gt;
- &lt;name&gt;test.direct&lt;/name&gt;
- &lt;durable&gt;true&lt;/durable&gt;
- &lt;/exchange&gt;
- &lt;/exchanges&gt;
-
- &lt;!-- Define the set of queues to be created at broker startup --&gt;
- &lt;queues&gt;
- &lt;!-- The properties configured here will be applied as defaults to all --&gt;
- &lt;!-- queues subsequently defined unless explicitly overridden --&gt;
- &lt;exchange&gt;amq.direct&lt;/exchange&gt;
- &lt;!-- Set threshold values for queue monitor alerting to log --&gt;
- &lt;maximumQueueDepth&gt;4235264&lt;/maximumQueueDepth&gt; &lt;!-- 4Mb --&gt;
- &lt;maximumMessageSize&gt;2117632&lt;/maximumMessageSize&gt; &lt;!-- 2Mb --&gt;
- &lt;maximumMessageAge&gt;600000&lt;/maximumMessageAge&gt; &lt;!-- 10 mins --&gt;
-
- &lt;!-- Define a queue with all default settings --&gt;
- &lt;queue&gt;
- &lt;name&gt;ping&lt;/name&gt;
- &lt;/queue&gt;
- &lt;!-- Example definitions of queues with overriden settings --&gt;
- &lt;queue&gt;
- &lt;name&gt;test-queue&lt;/name&gt;
- &lt;test-queue&gt;
- &lt;exchange&gt;test.direct&lt;/exchange&gt;
- &lt;durable&gt;true&lt;/durable&gt;
- &lt;/test-queue&gt;
- &lt;/queue&gt;
- &lt;queue&gt;
- &lt;name&gt;test-ping&lt;/name&gt;
- &lt;test-ping&gt;
- &lt;exchange&gt;test.direct&lt;/exchange&gt;
- &lt;/test-ping&gt;
- &lt;/queue&gt;
- &lt;/queues&gt;
- &lt;/localhost&gt;
- &lt;/virtualhost&gt;
-&lt;/virtualhosts&gt;
-</programlisting>
-<!--h3--></section>
- <section role="h3" id="ConfiguretheVirtualHostsviavirtualhosts.xml-Usingyourownvirtualhosts.xml"><title>
- Using your own virtualhosts.xml
- </title>
-
- <para>
- Note that the config.xml file shipped as an example (or developer
- default) in the Qpid distribution contains an element which
- defines the path to the virtualhosts.xml.
- </para><para>
- When using your own virtualhosts.xml you must edit this path to
- point at the location of your file.
- </para>
-<!--h3--></section>
-<!--h2--></section>
-</section>
diff --git a/doc/book/src/java-broker/Configuring-Management-Users.xml b/doc/book/src/java-broker/Configuring-Management-Users.xml
deleted file mode 100644
index a2a8d46d88..0000000000
--- a/doc/book/src/java-broker/Configuring-Management-Users.xml
+++ /dev/null
@@ -1,117 +0,0 @@
-<?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.
-
--->
-
-<section><title>
- Configuring Management Users
- </title><para>
- The Qpid Java broker has a single source of users for the system.
- So a user can connect to the broker to send messages and via the
- JMX console to check the state of the broker.
- </para><para>
-
- </para>
-
- <section role="h2" id="ConfiguringManagementUsers-Addinganewmanagementuser"><title>
- Adding
- a new management user
- </title>
- <para>
- The broker does have some minimal configuration available to
- limit which users can connect to the JMX console and what they
- can do when they are there.
- </para><para>
- There are two steps required to add a new user with rights for
- the JMX console.
- </para><orderedlist>
- <listitem><para>Create a new user login, see HowTo:<xref linkend="qpid_Add-New-Users"/>
- </para></listitem>
- <listitem><para>Grant the new user permission to the JMX Console
- </para></listitem>
- </orderedlist>
-
- <section role="h3" id="ConfiguringManagementUsers-GrantingJMXConsolePermissions"><title>
- Granting
- JMX Console Permissions
- </title>
- <para>
- By default new users do not have access to the JMX console. The
- access to the console is controlled via the file
- <emphasis>jmxremote.access</emphasis>.
- </para><para>
- This file contains a mapping from user to privilege.
- </para><para>
- There are three privileges available:
- </para><orderedlist>
- <listitem><para>readonly - The user is able to log in and view queues but not
- make any changes.
- </para></listitem>
- <listitem><para>readwrite - Grants user ability to read and write queue
- attributes such as alerting values.
- </para></listitem>
- <listitem><para>admin - Grants the user full access including ability to edit
- Users and JMX Permissions in addition to readwrite access.
- </para></listitem>
- </orderedlist><para>
- This file is read at start up and can forcibly be reloaded by an
- admin user through the management console.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="ConfiguringManagementUsers-AccessFileFormat"><title>
- Access
- File Format
- </title>
- <para>
- The file is a standard Java properties file and has the following
- format
- </para>
- <programlisting>
-&lt;username&gt;=&lt;privilege&gt;
-</programlisting>
- <para>
- If the username value is not a valid user (list in the specified
- PrincipalDatabase) then the broker will print a warning when it
- reads the file as that entry will have no meaning.
- </para><para>
- Only when the the username exists in both the access file and the
- PrincipalDatabase password file will the user be able to login
- via the JMX Console.
- </para><section role="h4" id="ConfiguringManagementUsers-ExampleFile"><title>
- Example File
- </title>
- <para>
- The file will be timestamped by the management console if edited
- through the console.
- </para>
- <programlisting>
-#Generated by JMX Console : Last edited by user:admin
-#Tue Jun 12 16:46:39 BST 2007
-admin=admin
-guest=readonly
-user=readwrite
-</programlisting>
-
-<!--h4--></section>
-<!--h3--></section>
-<!--h2--></section>
-</section>
diff --git a/doc/book/src/java-broker/Configuring-Qpid-JMX-Management-Console.xml b/doc/book/src/java-broker/Configuring-Qpid-JMX-Management-Console.xml
deleted file mode 100644
index 72e4ba8969..0000000000
--- a/doc/book/src/java-broker/Configuring-Qpid-JMX-Management-Console.xml
+++ /dev/null
@@ -1,181 +0,0 @@
-<?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.
-
--->
-
-<section><title>
- Configuring Qpid JMX Management Console
- </title><section role="h2" id="ConfiguringQpidJMXManagementConsole-ConfiguringQpidJMXManagementConsole"><title>
- Configuring Qpid JMX Management Console
- </title>
-
- <para>
- Qpid has a JMX management interface that exposes a number of
- components of the running broker.
- You can find out more about the features exposed by the JMX
- interfaces <xref linkend="qpid_Qpid-Management-Features"/>.
- </para><para>
-
- </para>
-
- <section role="h3" id="ConfiguringQpidJMXManagementConsole-InstallingtheQpidJMXManagementConsole"><title>
- Installing the Qpid JMX Management Console
- </title>
-
- <orderedlist>
- <listitem><para>Unzip the archive to a suitable location.</para>
-
- <note><title>SSL encrypted connections</title>
- <para>
- Recent versions of the broker can make use of SSL to
- encrypt their RMI based JMX connections. If a broker
- being connected to is making use of this ability then
- additional console configuration may be required,
- particularly when using self-signed certificates. See
- <xref linkend="qpid_Management-Console-Security"/> for details.
- </para>
- </note>
- </listitem>
- </orderedlist>
-
- <note>
- <title>JMXMP based connections</title>
- <para>
- In previous releases of Qpid (M4 and below) the broker
- JMX connections could make use of the JMXMPConnector for
- additional security over its default RMI based JMX
- configuration. This is no longer the case, with SSL
- encrypted RMI being the favored approach going forward.
- However, if you wish to connect to an older broker using
- JMXMP the console will support this so long as the
- <emphasis>jmxremote_optional.jar</emphasis> file is provided to it.
- For details see <xref linkend="qpid_Management-Console-Security"/>.
- </para>
- </note>
-<!--h3--></section>
-
-
- <section role="h3" id="ConfiguringQpidJMXManagementConsole-RunningtheQpidJMXManagementConsole"><title>
- Running the Qpid JMX Management Console
- </title>
-
- <para>
- The console can be started in the following way, depending on
- platform:
- </para><itemizedlist>
- <listitem><para>Windows: by running the 'qpidmc.exe' executable file.
- </para></listitem>
- </itemizedlist><itemizedlist>
- <listitem><para>Linux: by running the 'qpidmc' executable.
- </para></listitem>
- </itemizedlist><itemizedlist>
- <listitem><para>Mac OS X: by launching the consoles application bundle (.app
- file).
- </para></listitem>
- </itemizedlist>
-<!--h3--></section>
-
-
- <section role="h3" id="ConfiguringQpidJMXManagementConsole-UsingtheQpidJMXManagementConsole"><title>
- Using the Qpid JMX Management Console
- </title>
-
- <para>
- Please see <xref linkend="Qpid-JMX-Management-Console-User-Guide"/> for details on using this Eclipse RCP
- application.
- </para>
-
-<!--h3--></section>
-<!--h2--></section>
-
- <section role="h2" id="ConfiguringQpidJMXManagementConsole-UsingJConsole"><title>
- Using
- JConsole
- </title>
-
- <para>
- See <xref linkend="qpid_JConsole"/>
- </para>
-<!--h2--></section>
-
-
- <section role="h2" id="ConfiguringQpidJMXManagementConsole-UsingHermesJMS"><title>
- Using
- HermesJMS
- </title>
-
- <para>
- HermesJMS also offers integration with the Qpid management
- interfaces. You can get instructions and more information from
- <ulink url="http://cwiki.apache.org/confluence/display/qpid/HermesJMS">HermesJMS</ulink>.
- </para>
-<!--h2--></section>
-
- <section role="h2" id="ConfiguringQpidJMXManagementConsole-UsingMC4J"><title>
- Using
- MC4J
- </title>
-
- <para>
- <ulink url="qpid_www.mc4j.org">MC4J</ulink> is an alternative
- management tool. It provide a richer "dashboard" that can
- customise the raw MBeans.
- </para>
- <section role="h4" id="ConfiguringQpidJMXManagementConsole-Installation"><title>
- Installation
- </title>
-
- <itemizedlist>
- <listitem><para>First download and install MC4J for your platform. Version
- 1.2 beta 9 is the latest version that has been tested.
- </para></listitem>
- <listitem><para>Copy the directory blaze/java/management/mc4j into
- the directory &lt;MC4J-Installation&gt;/dashboards
- </para></listitem>
- </itemizedlist>
-<!--h4--></section>
-
- <section role="h4" id="ConfiguringQpidJMXManagementConsole-Configuration"><title>
- Configuration
- </title>
-
- <para>
- You should create a connection the JVM to be managed. Using the
- Management-&gt;Create Server Connection menu option. The
- connection URL should be of the form:
- service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi
- making the appropriate host and post changes.
- </para>
-<!--h4--></section>
-
- <section role="h4" id="ConfiguringQpidJMXManagementConsole-Operation"><title>
- Operation
- </title>
-
- <para>
- You can view tabular summaries of the queues, exchanges and
- connections using the Global Dashboards-&gt;QPID tree view. To
- drill down on individual beans you can right click on the bean.
- This will show any available graphs too.
- </para>
-<!--h4--></section>
-<!--h2--></section>
-</section>
diff --git a/doc/book/src/java-broker/Debug-using-log4j.xml b/doc/book/src/java-broker/Debug-using-log4j.xml
deleted file mode 100644
index 615fd9e560..0000000000
--- a/doc/book/src/java-broker/Debug-using-log4j.xml
+++ /dev/null
@@ -1,298 +0,0 @@
-<?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.
-
--->
-
-<section id="Java-Broker-Debug-Logging"><title>
- Debug using log4j
- </title>
-
- <section role="h2" id="Debugusinglog4j-Debuggingwithlog4jconfigurations"><title>
- Debugging
- with log4j configurations
- </title>
- <para>
- Unfortunately setting of logging in the Java Broker is not simply
- a matter of setting one of WARN,INFO,DEBUG. At some point in the
- future we may have more BAU logging that falls in to that
- category but more likely is that we will have a varioius config
- files that can be swapped in (dynamically) to understand what is
- going on.
- </para><para>
- This page will be host to a variety of useful configuration
- setups that will allow a user or developer to extract only the
- information they are interested in logging. Each section will be
- targeted at logging in a particular area and will include a full
- log4j file that can be used. In addition the logging
- <emphasis>category</emphasis> elements will be presented and discussed so
- that the user can create their own file.
- </para><para>
- Currently the configuration that is available has not been fully
- documented and as such there are gaps in what is desired and what
- is available. Some times this is due to the desire to reduce the
- overhead in message processing, but sometimes it is simply an
- oversight. Hopefully in future releases the latter will be
- addressed but care needs to be taken when adding logging to the
- 'Message Flow' path as this will have performance implications.
- </para>
-
- <section role="h3" id="Debugusinglog4j-LoggingConnectionState-5CDeprecated-5C"><title>
- Logging
- Connection State *Deprecated*
- </title>
- <para>
- <emphasis>deprecation notice</emphasis> Version 0.6 of the Java broker includes
- <xref linkend="qpid_Configure-Operational-Status-Logging"/> functionality which improves upon these messages and
- as such enabling status logging would be more beneficial.
- The configuration file has been left here for assistence with
- broker versions prior to 0.6.
- </para><para>
- The goals of this configuration are to record:
- </para><itemizedlist>
- <listitem><para>New Connections
- </para></listitem>
- <listitem><para>New Consumers
- </para></listitem>
- <listitem><para>Identify slow consumers
- </para></listitem>
- <listitem><para>Closing of Consumers
- </para></listitem>
- <listitem><para>Closing of Connections
- </para></listitem>
- </itemizedlist><para>
- An additional goal of this configuration is to minimise any
- impact to the 'message flow' path. So it should not adversely
- affect production systems.
- </para>
-<programlisting>
-<![CDATA[
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
- <appender name="FileAppender" class="org.apache.log4j.FileAppender">
- <param name="File" value="${QPID_WORK}/log/${logprefix}qpid${logsuffix}.log"/>
- <param name="Append" value="false"/>
-
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
- </layout>
-
- </appender>
-
- <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
-
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
- </layout>
- </appender>
-
- <category name="Qpid.Broker">
-
- <priority value="debug"/>
- </category>
-
-
- <!-- Provide warnings to standard output -->
- <category name="org.apache.qpid">
- <priority value="warn"/>
- </category>
-
-
- <!-- Connection Logging -->
-
- <!-- Log details of client starting connection -->
- <category name="org.apache.qpid.server.handler.ConnectionStartOkMethodHandler">
- <priority value="info"/>
- </category>
- <!-- Log details of client closing connection -->
- <category name="org.apache.qpid.server.handler.ConnectionCloseMethodHandler">
- <priority value="info"/>
- </category>
- <!-- Log details of client responding to be asked to closing connection -->
-
- <category name="org.apache.qpid.server.handler.ConnectionCloseOkMethodHandler">
- <priority value="info"/>
- </category>
-
-
- <!-- Consumer Logging -->
- <!-- Provide details of Consumers connecting-->
- <category name="org.apache.qpid.server.handler.BasicConsumeMethodHandler">
- <priority value="debug"/>
- </category>
-
- <!-- Provide details of Consumers disconnecting, if the call it-->
- <category name="org.apache.qpid.server.handler.BasicCancelMethodHandler">
- <priority value="debug"/>
- </category>
- <!-- Provide details of when a channel closes to attempt to match to the Consume as a Cancel is not always issued-->
- <category name="org.apache.qpid.server.handler.ChannelCloseHandler">
- <priority value="info"/>
- </category>
-
- <!-- Provide details of Consumers starting to consume-->
- <category name="org.apache.qpid.server.handler.ChannelFlowHandler">
- <priority value="debug"/>
- </category>
- <!-- Provide details of what consumers are going to be consuming-->
- <category name="org.apache.qpid.server.handler.QueueBindHandler">
- <priority value="info"/>
- </category>
-
- <!-- No way of determining if publish message is returned, client log should show it.-->
-
- <root>
- <priority value="debug"/>
- <appender-ref ref="STDOUT"/>
- <appender-ref ref="FileAppender"/>
- </root>
-
-</log4j:configuration>
-]]>
-</programlisting>
- <!--h3--></section>
-
- <section role="h3" id="Debugusinglog4j-DebuggingMyApplication"><title>
- Debugging My
- Application
- </title>
- <para>
- This is the most often asked for set of configuration. The goals
- of this configuration are to record:
- </para><itemizedlist>
- <listitem><para>New Connections
- </para></listitem>
- <listitem><para>New Consumers
- </para></listitem>
- <listitem><para>Message Publications
- </para></listitem>
- <listitem><para>Message Consumption
- </para></listitem>
- <listitem><para>Identify slow consumers
- </para></listitem>
- <listitem><para>Closing of Consumers
- </para></listitem>
- <listitem><para>Closing of Connections
- </para></listitem>
- </itemizedlist><para>
- NOTE: This configuration enables message logging on the 'message
- flow' path so should only be used were message volume is
- low.
- <emphasis>Every message that is sent to the broker will generate at
- least four logging statements</emphasis>
- </para>
-<programlisting>
-<![CDATA[
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
- <appender name="FileAppender" class="org.apache.log4j.FileAppender">
- <param name="File" value="${QPID_WORK}/log/${logprefix}qpid${logsuffix}.log"/>
- <param name="Append" value="false"/>
-
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
- </layout>
-
- </appender>
-
- <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
-
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
- </layout>
- </appender>
-
- <category name="Qpid.Broker">
-
- <priority value="debug"/>
- </category>
-
-
- <!-- Provide warnings to standard output -->
- <category name="org.apache.qpid">
- <priority value="warn"/>
- </category>
-
-
- <!-- Connection Logging -->
-
- <!-- Log details of client starting connection -->
- <category name="org.apache.qpid.server.handler.ConnectionStartOkMethodHandler">
- <priority value="info"/>
- </category>
- <!-- Log details of client closing connection -->
- <category name="org.apache.qpid.server.handler.ConnectionCloseMethodHandler">
- <priority value="info"/>
- </category>
- <!-- Log details of client responding to be asked to closing connection -->
-
- <category name="org.apache.qpid.server.handler.ConnectionCloseOkMethodHandler">
- <priority value="info"/>
- </category>
-
- <!-- Consumer Logging -->
- <!-- Provide details of Consumers connecting-->
- <category name="org.apache.qpid.server.handler.BasicConsumeMethodHandler">
- <priority value="debug"/>
- </category>
-
- <!-- Provide details of Consumers disconnecting, if the call it-->
- <category name="org.apache.qpid.server.handler.BasicCancelMethodHandler">
- <priority value="debug"/>
- </category>
- <!-- Provide details of when a channel closes to attempt to match to the Consume as a Cancel is not always issued-->
- <category name="org.apache.qpid.server.handler.ChannelCloseHandler">
- <priority value="info"/>
- </category>
-
- <!-- Provide details of Consumers starting to consume-->
- <category name="org.apache.qpid.server.handler.ChannelFlowHandler">
- <priority value="debug"/>
- </category>
- <!-- Provide details of what consumers are going to be consuming-->
- <category name="org.apache.qpid.server.handler.QueueBindHandler">
- <priority value="info"/>
- </category>
-
- <!-- No way of determining if publish message is returned, client log should show it.-->
-
- <!-- WARNING DO NOT ENABLE THIS IN PRODUCTION -->
- <!-- Will generate minimum one log statements per published message -->
- <!-- Will generate will log receiving of all body frame, count will vary on size of message.-->
- <!-- Empty Message = no body, Body is up to 64kb of data -->
- <!-- Will generate three log statements per recevied message -->
-
- <!-- Log messages flow-->
- <category name="org.apache.qpid.server.AMQChannel">
-
- <priority value="debug"/>
- </category>
-
- <root>
- <priority value="debug"/>
- <appender-ref ref="STDOUT"/>
- <appender-ref ref="FileAppender"/>
- </root>
-
-</log4j:configuration>
-]]>
-</programlisting>
-
-<!--h3--></section>
-<!--h2--></section>
-</section>
diff --git a/doc/book/src/java-broker/HA-Guide.xml b/doc/book/src/java-broker/HA-Guide.xml
deleted file mode 100644
index 041309d711..0000000000
--- a/doc/book/src/java-broker/HA-Guide.xml
+++ /dev/null
@@ -1,1008 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE urls [
-<!ENTITY oracleBdbProductOverviewUrl "http://www.oracle.com/technetwork/products/berkeleydb/overview/index-093405.html">
-<!ENTITY oracleBdbProductVersion "5.0.58">
-<!ENTITY oracleBdbRepGuideUrl "http://oracle.com/cd/E17277_02/html/ReplicationGuide/">
-<!ENTITY oracleBdbJavaDocUrl "http://docs.oracle.com/cd/E17277_02/html/java/">
-<!ENTITY oracleJdkDocUrl "http://oracle.com/javase/6/docs/api/">
-]>
-<!--
-
- 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.
-
--->
-<section id="High-Availability">
- <title>High Availability</title>
-
- <section role="h3" id="HAGeneralIntroduction">
- <title>General Introduction</title>
- <para>The term High Availability (HA) usually refers to having a number of instances of a service such as a Message Broker
- available so that should a service unexpectedly fail, or requires to be shutdown for maintenance, users may quickly connect
- to another instance and continue their work with minimal interuption. HA is one way to make a overall system more resilient
- by eliminating a single point of failure from a system.</para>
- <para>HA offerings are usually categorised as <emphasis role="bold">Active/Active</emphasis> or <emphasis role="bold">Active/Passive</emphasis>.
- An Active/Active system is one where all nodes within the cluster are usuaully available for use by clients all of the time. In an
- Active/Passive system, one only node within the cluster is available for use by clients at any one time, whilst the others are in
- some kind of standby state, awaiting to quickly step-in in the event the active node becomes unavailable.
- </para>
- </section>
-
- <section role="h3" id="HAOfferingsOfJavaBroker">
- <title>HA offerings of the Java Broker</title>
- <para>The Java Broker's HA offering became available at release <emphasis role="bold">0.18</emphasis>. HA is provided by way of the HA
- features built into the <ulink url="&oracleBdbProductOverviewUrl;">Java Edition of the Berkley Database (BDB JE)</ulink> and as such
- is currently only available to Java Broker users who use the optional BDB JE based persistence store. This
- <emphasis role="bold">optional</emphasis> store requires the use of BDB JE which is licensed under the Sleepycat Licence, which is
- not compatible with the Apache Licence and thus BDB JE is not distributed with Qpid. Users who elect to use this optional store for
- the broker have to provide this dependency.</para>
- <para>HA in the Java Broker provides an <emphasis role="bold">Active/Passive</emphasis> mode of operation with Virtual hosts being
- the unit of replication. The Active node (referred to as the <emphasis role="bold">Master</emphasis>) accepts all work from all the clients.
- The Passive nodes (referred to as <emphasis role="bold">Replicas</emphasis>) are unavailable for work: the only task they must perform is
- to remain in synch with the Master node by consuming a replication stream containing all data and state.</para>
- <para>If the Master node fails, a Replica node is elected to become the new Master node. All clients automatically failover
- <footnote><para>The automatic failover feature is available only for AMQP connections from the Java client. Management connections (JMX)
- do not current offer this feature.</para></footnote> to the new Master and continue their work.</para>
- <para>The Java Broker HA solution is incompatible with the HA solution offered by the CPP Broker. It is not possible to co-locate Java and CPP
- Brokers within the same cluster.</para>
- <para>HA is not currently available for those using the the <emphasis role="bold">Derby Store</emphasis> or <emphasis role="bold">Memory
- Message Store</emphasis>.</para>
- </section>
-
- <section role="h3" id="HATwoNodeCluster">
- <title>Two Node Cluster</title>
- <section role="h4">
- <title>Overview</title>
- <para>In this HA solution, a cluster is formed with two nodes. one node serves as
- <emphasis role="bold">master</emphasis> and the other is a <emphasis role="bold">replica</emphasis>.
- </para>
- <para>All data and state required for the operation of the virtual host is automatically sent from the
- master to the replica. This is called the replication stream. The master virtual host confirms each
- message is on the replica before the client transaction completes. The exact way the client awaits
- for the master and replica is gorverned by the <link linkend="HADurabilityGuarantee">durability</link>
- configuration, which is discussed later. In this way, the replica remains ready to take over the
- role of the master if the master becomes unavailable.
- </para>
- <para>It is important to note that there is an inherent limitation of two node clusters is that
- the replica node cannot make itself master automatically in the event of master failure. This
- is because the replica has no way to distinguish between a network partition (with potentially
- the master still alive on the other side of the partition) and the case of genuine master failure.
- (If the replica were to elect itself as master, the cluster would run the risk of a
- <ulink url="http://en.wikipedia.org/wiki/Split-brain_(computing)">split-brain</ulink> scenario).
- In the event of a master failure, a third party must designate the replica as primary. This process
- is described in more detail later.
- </para>
- <para>Clients connect to the cluster using a <link linkend="HAClientFailover">failover url</link>.
- This allows the client to maintain a connection to the master in a way that is transparent
- to the client application.</para>
- </section>
- <section role="h4">
- <title>Depictions of cluster operation</title>
- <para>In this section, the operation of the cluster is depicted through a series of figures
- supported by explanatory text.</para>
- <figure>
- <title>Key for figures</title>
- <mediaobject>
- <imageobject>
- <imagedata fileref="images/HA-2N-Key.png" format="PNG" scalefit="1"/>
- </imageobject>
- <textobject>
- <phrase>Key to figures</phrase>
- </textobject>
- </mediaobject>
- </figure>
- <section role="h5" id="HATwoNodeNormalOperation">
- <title>Normal Operation</title>
- <para>The figure below illustrates normal operation. Clients connecting to the cluster by way
- of the failover URL achieve a connection to the master. As clients perform work (message
- production, consumption, queue creation etc), the master additionally sends this data to the
- replica over the network.</para>
- <figure>
- <title>Normal operation of a two-node cluster</title>
- <mediaobject>
- <imageobject>
- <imagedata fileref="images/HA-2N-Normal.png" format="PNG" scalefit="1"/>
- </imageobject>
- <textobject>
- <phrase>Normal operation</phrase>
- </textobject>
- </mediaobject>
- </figure>
- </section>
- <section role="h5" id="HATwoNodeMasterFailure">
- <title>Master Failure and Recovery</title>
- <para>The figure below illustrates a sequence of events whereby the master suffers a failure
- and the replica is made the master to allow the clients to continue to work. Later the
- old master is repaired and comes back on-line in replica role.</para>
- <para>The item numbers in this list apply to the numbered boxes in the figure below.</para>
- <orderedlist>
- <listitem>
- <para>System operating normally</para>
- </listitem>
- <listitem>
- <para>Master suffers a failure and disconnects all clients. Replica realises that it is no
- longer in contact with master. Clients begin to try to reconnect to the cluster, although these
- connection attempts will fail at this point.</para>
- </listitem>
- <listitem>
- <para>A third-party (an operator, a script or a combination of the two) verifies that the master has truely
- failed <emphasis role="bold">and is no longer running</emphasis>. If it has truely failed, the decision is made
- to designate the replica as primary, allowing it to assume the role of master despite the other node being down.
- This primary designation is performed using <link linkend="HAJMXAPI">JMX</link>.</para>
- </listitem>
- <listitem>
- <para>Client connections to the new master succeed and the <emphasis role="bold">service is restored
- </emphasis>, albeit without a replica.</para>
- </listitem>
- <listitem>
- <para>The old master is repaired and brought back on-line. It automatically rejoins the cluster
- in the <emphasis role="bold">replica</emphasis> role.</para>
- </listitem>
- </orderedlist>
- <figure>
- <title>Failure of master and recovery sequence</title>
- <mediaobject>
- <imageobject>
- <imagedata fileref="images/HA-2N-MasterFail.png" format="PNG" scalefit="1"/>
- </imageobject>
- <textobject>
- <phrase>Failure of master and subsequent recovery sequence</phrase>
- </textobject>
- </mediaobject>
- </figure>
- </section>
- <section role="h5" id="HATwoNodeReplicaFailure">
- <title>Replica Failure and Recovery</title>
- <para>The figure that follows illustrates a sequence of events whereby the replica suffers a failure
- leaving the master to continue processing alone. Later the replica is repaired and is restarted.
- It rejoins the cluster so that it is once again ready to take over in the event of master failure.</para>
- <para>The behavior of the replica failure case is governed by the <varname>designatedPrimary</varname>
- configuration item. If set true on the master, the master will continue to operate solo without outside
- intervention when the replica fails. If false, a third-party must designate the master as primary in order
- for it to continue solo.</para>
- <para>The item numbers in this list apply to the numbered boxes in the figure below. This example assumes
- that <varname>designatedPrimary</varname> is true on the original master node.</para>
- <orderedlist>
- <listitem>
- <para>System operating normally</para>
- </listitem>
- <listitem>
- <para>Replica suffers a failure. Master realises that replica longer in contact but as
- <varname>designatedPrimary</varname> is true, master continues processing solo and thus client
- connections are uninterrupted by the loss of the replica. System continues operating normally, albeit
- with a single node.</para>
- </listitem>
- <listitem>
- <para>Replica is repaired.</para>
- </listitem>
- <listitem>
- <para>After catching up with missed work, replica is once again ready to take over in the event of master failure.</para>
- </listitem>
- </orderedlist>
- <figure>
- <title>Failure of replica and subsequent recovery sequence</title>
- <mediaobject>
- <imageobject>
- <imagedata fileref="images/HA-2N-ReplicaFail.png" format="PNG" scalefit="1"/>
- </imageobject>
- <textobject>
- <phrase>Failure of replica and subsequent recovery sequence</phrase>
- </textobject>
- </mediaobject>
- </figure>
- </section>
- <section role="h5" id="HATwoNodeNetworkPartition">
- <title>Network Partition and Recovery</title>
- <para>The figure below illustrates the sequence of events that would occur if the network between
- master and replica were to suffer a partition, and the nodes were out of contact with one and other.</para>
- <para>As with <link linkend="HATwoNodeReplicaFailure">Replica Failure and Recovery</link>, the
- behaviour is governed by the <varname>designatedPrimary</varname>.
- Only if <varname>designatedPrimary</varname> is true on the master, will the master continue solo.</para>
- <para>The item numbers in this list apply to the numbered boxes in the figure below. This example assumes
- that <varname>designatedPrimary</varname> is true on the original master node.</para>
- <orderedlist>
- <listitem>
- <para>System operating normally</para>
- </listitem>
- <listitem>
- <para>Network suffers a failure. Master realises that replica longer in contact but as
- <varname>designatedPrimary</varname> is true, master continues processing solo and thus client
- connections are uninterrupted by the network partition between master and replica.</para>
- </listitem>
- <listitem>
- <para>Network is repaired.</para>
- </listitem>
- <listitem>
- <para>After catching up with missed work, replica is once again ready to take over in the event of master failure.
- System operating normally again.</para>
- </listitem>
- </orderedlist>
- <figure>
- <title>Partition of the network separating master and replica</title>
- <mediaobject>
- <imageobject>
- <imagedata fileref="images/HA-2N-NetworkPartition.png" format="PNG" scalefit="1"/>
- </imageobject>
- <textobject>
- <phrase>Network Partition and Recovery</phrase>
- </textobject>
- </mediaobject>
- </figure>
- </section>
- <section role="h5" id="HATwoNodeSplitBrain">
- <title>Split Brain</title>
- <para>A <ulink url="http://en.wikipedia.org/wiki/Split-brain_(computing)">split-brain</ulink>
- is a situation where the two node cluster has two masters. BDB normally strives to prevent
- this situation arising by preventing two nodes in a cluster being master at the same time.
- However, if the network suffers a partition, and the third-party intervenes incorrectly
- and makes the replica a second master a split-brain will be formed and both masters will
- proceed to perform work <emphasis role="bold">independently</emphasis> of one and other.</para>
- <para>There is no automatic recovery from a split-brain.</para>
- <para>Manual intervention will be required to choose which store will be retained as master
- and which will be discarded. Manual intervention will be required to identify and repeat the
- lost business transactions.</para>
- <para>The item numbers in this list apply to the numbered boxes in the figure below.</para>
- <orderedlist>
- <listitem>
- <para>System operating normally</para>
- </listitem>
- <listitem>
- <para>Network suffers a failure. Master realises that replica longer in contact but as
- <varname>designatedPrimary</varname> is true, master continues processing solo. Client
- connections are uninterrupted by the network partition.</para>
- <para>A third-party <emphasis role="bold">erroneously</emphasis> designates the replica as primary while the
- original master continues running (now solo).</para>
- </listitem>
- <listitem>
- <para>As the nodes cannot see one and other, both behave as masters. Clients may perform work against
- both master nodes.</para>
- </listitem>
- </orderedlist>
- <figure>
- <title>Split Brain</title>
- <mediaobject>
- <imageobject>
- <imagedata fileref="images/HA-2N-SplitBrain.png" format="PNG" scalefit="1"/>
- </imageobject>
- <textobject>
- <phrase>Split Brain</phrase>
- </textobject>
- </mediaobject>
- </figure>
- </section>
- </section>
- </section>
-
- <section role="h3" id="HAMultiNodeCluster">
- <title>Multi Node Cluster</title>
- <para>Multi node clusters, that is clusters where the number of nodes is three or more, are not yet
- ready for use.</para>
- </section>
-
- <section role="h3" id="HAConfiguration">
- <title>Configuring a Virtual Host to be a node</title>
- <para>To configure a virtualhost as a cluster node, configure the virtualhost.xml in the following manner:</para>
- <para>
- <programlisting language="xml"><![CDATA[
-<virtualhost>
- <name>myhost</name>
- <myvhost>
- <store>
- <class>org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore</class>
- <environment-path>${work}/bdbhastore</environment-path>
- <highAvailability>
- <groupName>myclustername</groupName>
- <nodeName>mynode1</nodeName>
- <nodeHostPort>node1host:port</nodeHostPort>
- <helperHostPort>node1host:port</helperHostPort>
- <durability>NO_SYNC\,NO_SYNC\,SIMPLE_MAJORITY</durability>
- <coalescingSync>true|false</coalescingSync>
- <designatedPrimary>true|false</designatedPrimary>
- </highAvailability>
- </store>
- ...
- </myvhost>
-</virtualhost>]]></programlisting>
- </para>
- <para>The <varname>groupName</varname> is the name of logical name of the cluster. All nodes within the
- cluster must use the same <varname>groupName</varname> in order to be considered part of the cluster.</para>
- <para>The <varname>nodeName</varname> is the logical name of the node. All nodes within the cluster must have a
- unique name. It is recommended that the node name should be chosen from a different nomenclature from that of
- the servers on which they are hosted, in case the need arises to move node to a new server in the future.</para>
- <para>The <varname>nodeHostPort</varname> is the hostname and port number used by this node to communicate with the
- the other nodes in the cluster. For the hostname, an IP address, hostname or fully qualified hostname may be used.
- For the port number, any free port can be used. It is important that this address is stable over time, as BDB
- records and uses this address internally.</para>
- <para>The <varname>helperHostPort</varname> is the hostname and port number that new nodes use to discover other
- nodes within the cluster when they are newly introduced to the cluster. When configuring the first node, set the
- <varname>helperHostPort</varname> to its own <varname>nodeHostPort</varname>. For the second and subsequent nodes,
- set their <varname>helperHostPort</varname> to that of the first node.</para>
- <para><varname>durability</varname> controls the <link linkend="HADurabilityGuarantee">durability</link>
- guarantees made by the cluster. It is important that all nodes use the same value for this property. The default value is
- NO_SYNC\,NO_SYNC\,SIMPLE_MAJORITY. Owing to the internal use of Apache Commons Config, it is currently necessary
- to escape the commas within the durability string.</para>
- <para><varname>coalescingSync</varname> controls the <link linkend="HADurabilityGuarantee_CoalescingSync">coalescing-sync</link>
- mode of Qpid. It is important that all nodes use the same value. If omitted, it defaults to true.</para>
- <para>The <varname>designatedPrimary</varname> is applicable only to the <link linkend="HATwoNodeCluster">two-node
- case.</link> It governs the behaviour of a node when the other node fails or becomes uncontactable. If true,
- the node will be designated as primary at startup and will be able to continue operating as a single node master.
- If false, the node will transition to an unavailable state until a third-party manually designates the node as
- primary or the other node is restored. It is suggested that the node that normally fulfils the role of master is
- set true in config file and the node that is normally replica is set false. Be aware that setting both nodes to
- true will lead to a failure to start up, as both cannot be designated at the point of contact. Designating both
- nodes as primary at runtime (using the JMX interface) will lead to a <link linkend="HATwoNodeSplitBrain">split-brain</link>
- in the case of network partition and must be avoided.</para>
- <note><para>Usage of domain names in <varname>helperHostPort</varname> and <varname>nodeHostPort</varname> is more preferebale
- over IP addresses due to the tendency of more frequent changes of the last over the former.
- If server IP address changes but domain name remains the same the HA cluster can continue working as normal
- in case when domain names are used in cluster configuration. In case when IP addresses are used and they are changed with the time
- than Qpid <link linkend="HAJMXAPI">JMX API for HA</link> can be used to change the addresses or remove the nodes from the cluster.</para></note>
-
- <section role="h4" id="HAConfiguration_BDBEnvVars">
- <title>Passing BDB environment and replication configuration options</title>
- <para>It is possible to pass BDB <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/EnvironmentConfig.html">
- environment</ulink> and <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/ReplicationConfig.html">
- replication</ulink> configuration options from the virtualhost.xml. Environment configuration options are passed using
- the <varname>envConfig</varname> element, and replication config using <varname>repConfig</varname>.</para>
- <para>For example, to override the BDB environment configuration options <varname>je.cleaner.threads</varname> and
- <varname>je.txn.timeout</varname></para>
- <programlisting language="xml"><![CDATA[
- ...
- </highAvailability>
- <envConfig>
- <name>je.cleaner.threads</name>
- <value>2</value>
- </envConfig>
- <envConfig>
- <name>je.txn.timeout</name>
- <value>15 min</value>
- </envConfig>
- ...
- </store>]]></programlisting>
- <para>And to override the BDB replication configuration options <varname>je.rep.insufficientReplicasTimeout</varname>.</para>
- <programlisting language="xml"><![CDATA[
- ...
- </highAvailability>
- ...
- <repConfig>
- <name>je.rep.insufficientReplicasTimeout</name>
- <value>2</value>
- </envConfig>
- <envConfig>
- <name>je.txn.timeout</name>
- <value>10 s</value>
- </envConfig>
- ...
- </store>]]></programlisting>
- </section>
- </section>
-
- <section role="h3" id="HADurabilityGuarantee">
- <title>Durability Guarantees</title>
- <para>The term <ulink url="http://en.wikipedia.org/wiki/ACID#Durability">durability</ulink> is used to mean that once a
- transaction is committed, it remains committed regardless of subsequent failures. A highly durable system is one where
- loss of a committed transaction is extermely unlikely, whereas with a less durable system loss of a transaction is likely
- in a greater number of scenarios. Typically, the more highly durable a system the slower and more costly it will be.</para>
- <para>Qpid exposes the all the
- <ulink url="&oracleBdbRepGuideUrl;txn-management.html#durabilitycontrols">durability controls</ulink>
- offered by by BDB JE JA and a Qpid specific optimisation called <emphasis role="bold">coalescing-sync</emphasis> which defaults
- to enabled.</para>
- <section role="h4" id="HADurabilityGuarantee_BDBControls">
- <title>BDB Durability Controls</title>
- <para>BDB expresses durability as a triplet with the following form:</para>
- <programlisting><![CDATA[<master sync policy>,<replica sync policy>,<replica acknowledgement policy>]]></programlisting>
- <para>The sync polices controls whether the thread performing the committing thread awaits the successful completion of the
- write, or the write and sync before continuing. The master sync policy and replica sync policy need not be the same.</para>
- <para>For master and replic sync policies, the available values are:
- <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.SyncPolicy.html#SYNC">SYNC</ulink>,
- <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.SyncPolicy.html#WRITE_NO_SYNC">WRITE_NO_SYNC</ulink>,
- <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.SyncPolicy.html#NO_SYNC">NO_SYNC</ulink>. SYNC
- is offers the highest durability whereas NO_SYNC the lowest.</para>
- <para>Note: the combination of a master sync policy of SYNC and <link linkend="HADurabilityGuarantee_CoalescingSync">coalescing-sync</link>
- true would result in poor performance with no corresponding increase in durability guarantee. It cannot not be used.</para>
- <para>The acknowledgement policy defines whether when a master commits a transaction, it also awaits for the replica(s) to
- commit the same transaction before continuing. For the two-node case, ALL and SIMPLE_MAJORITY are equal.</para>
- <para>For acknowledgement policy, the available value are:
- <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.ReplicaAckPolicy.html#ALL">ALL</ulink>,
- <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.ReplicaAckPolicy.html#SIMPLE_MAJORITY">SIMPLE_MAJORITY</ulink>
- <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.ReplicaAckPolicy.html#NONE">NONE</ulink>.</para>
- </section>
- <section role="h4" id="HADurabilityGuarantee_CoalescingSync">
- <title>Coalescing-sync</title>
- <para>If enabled (the default) Qpid works to reduce the number of separate
- <ulink url="&oracleJdkDocUrl;java/io/FileDescriptor.html#sync()">file-system sync</ulink> operations
- performed by the <emphasis role="bold">master</emphasis> on the underlying storage device thus improving performance. It does
- this coalescing separate sync operations arising from the different client commits operations occuring at approximately the same time.
- It does this in such a manner not to reduce the ACID guarantees of the system.</para>
- <para>Coalescing-sync has no effect on the behaviour of the replicas.</para>
- </section>
- <section role="h4" id="HADurabilityGuarantee_Default">
- <title>Default</title>
- <para>The default durability guarantee is <constant>NO_SYNC, NO_SYNC, SIMPLE_MAJORITY</constant> with coalescing-sync enabled. The effect
- of this combination is described in the table below. It offers a good compromise between durability guarantee and performance
- with writes being guaranteed on the master and the additional guarantee that a majority of replicas have received the
- transaction.</para>
- </section>
- <section role="h4" id="HADurabilityGuarantee_Examples">
- <title>Examples</title>
- <para>Here are some examples illustrating the effects of the durability and coalescing-sync settings.</para>
- <para>
- <table>
- <title>Effect of different durability guarantees</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry/>
- <entry>Durability</entry>
- <entry>Coalescing-sync</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>1</entry>
- <entry>NO_SYNC, NO_SYNC, SIMPLE_MAJORITY</entry>
- <entry>true</entry>
- <entry>Before the commit returns to the client, the transaction will be written/sync'd to the Master's disk (effect of
- coalescing-sync) and a majority of the replica(s) will have acknowledged the <emphasis role="bold">receipt</emphasis>
- of the transaction. The replicas will write and sync the transaction to their disk at a point in the future governed by
- <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/ReplicationMutableConfig.html#LOG_FLUSH_TASK_INTERVAL">ReplicationMutableConfig#LOG_FLUSH_INTERVAL</ulink>.
- </entry>
- </row>
- <row>
- <entry>2</entry>
- <entry>NO_SYNC, WRITE_NO_SYNC, SIMPLE_MAJORITY</entry>
- <entry>true</entry>
- <entry>Before the commit returns to the client, the transaction will be written/sync'd to the Master's disk (effect of
- coalescing-sync and a majority of the replica(s) will have acknowledged the <emphasis role="bold">write</emphasis> of
- the transaction to their disk. The replicas will sync the transaction to disk at a point in the future with an upper bound governed by
- ReplicationMutableConfig#LOG_FLUSH_INTERVAL.</entry>
- </row>
- <row>
- <entry>3</entry>
- <entry>NO_SYNC, NO_SYNC, NONE</entry>
- <entry>false</entry>
- <entry>After the commit returns to the client, the transaction is neither guaranteed to be written to the disk of the master
- nor received by any of the replicas. The master and replicas will write and sync the transaction to their disk at a point
- in the future with an upper bound governed by ReplicationMutableConfig#LOG_FLUSH_INTERVAL. This offers the weakest durability guarantee.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </section>
- </section>
-
- <section id="HAClientFailover">
- <title>Client failover configuration</title>
- <para>The details about format of Qpid connection URLs can be found at section
- <ulink url="../../Programming-In-Apache-Qpid/html/QpidJNDI.html">Connection URLs</ulink>
- of book <ulink url="../../Programming-In-Apache-Qpid/html/">Programming In Apache Qpid</ulink>.</para>
- <para>The failover policy option in the connection URL for the HA Cluster should be set to <emphasis>roundrobin</emphasis>.
- The Master broker should be put into a first place in <emphasis>brokerlist</emphasis> URL option.
- The recommended value for <emphasis>connectdelay</emphasis> option in broker URL should be set to
- the value greater than 1000 milliseconds. If it is desired that clients re-connect automatically after a
- master to replica failure, <varname>cyclecount</varname> should be tuned so that the retry period is longer than
- the expected length of time to perform the failover.</para>
- <example><title>Example of connection URL for the HA Cluster</title><![CDATA[
-amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672?connectdelay='2000'&retries='3';tcp://localhost:5671?connectdelay='2000'&retries='3';tcp://localhost:5673?connectdelay='2000'&retries='3''&failover='roundrobin?cyclecount='30''
- ]]></example>
- </section>
-
-
- <section role="h3" id="HAJMXAPI">
- <title>Qpid JMX API for HA</title>
- <para>Qpid exposes the BDB HA store information via its JMX interface and provides APIs to remove a Node from
- the group, update a Node IP address, and assign a Node as the designated primary.</para>
- <para>An instance of the <classname>BDBHAMessageStore</classname> MBean is instantiated by the broker for the each virtualhost using the HA store.</para>
- <para>The reference to this MBean can be obtained via JMX API using an ObjectName like <emphasis>org.apache.qpid:type=BDBHAMessageStore,name=&lt;virtualhost name&gt;</emphasis>
- where &lt;virtualhost name&gt; is the name of a specific virtualhost on the broker.</para>
- <table border="1">
- <title>Mbean <classname>BDBHAMessageStore</classname> attributes</title>
- <thead>
- <tr>
- <td>Name</td>
- <td>Type</td>
- <td>Accessibility</td>
- <td>Description</td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>GroupName</td>
- <td>String</td>
- <td>Read only</td>
- <td>Name identifying the group</td>
- </tr>
- <tr>
- <td>NodeName</td>
- <td>String</td>
- <td>Read only</td>
- <td>Unique name identifying the node within the group</td>
- </tr>
- <tr>
- <td>NodeHostPort</td>
- <td>String</td>
- <td>Read only</td>
- <td>Host/port used to replicate data between this node and others in the group</td>
- </tr>
- <tr>
- <td>HelperHostPort</td>
- <td>String</td>
- <td>Read only</td>
- <td>Host/port used to allow a new node to discover other group members</td>
- </tr>
- <tr>
- <td>NodeState</td>
- <td>String</td>
- <td>Read only</td>
- <td>Current state of the node</td>
- </tr>
- <tr>
- <td>ReplicationPolicy</td>
- <td>String</td>
- <td>Read only</td>
- <td>Node replication durability</td>
- </tr>
- <tr id="JMXDesignatedPrimary">
- <td>DesignatedPrimary</td>
- <td>boolean</td>
- <td>Read/Write</td>
- <td>Designated primary flag. Applicable to the two node case.</td>
- </tr>
- <tr>
- <td>CoalescingSync</td>
- <td>boolean</td>
- <td>Read only</td>
- <td>Coalescing sync flag. Applicable to the master sync policies NO_SYNC and WRITE_NO_SYNC only.</td>
- </tr>
- <tr>
- <td>getAllNodesInGroup</td>
- <td>TabularData</td>
- <td>Read only</td>
- <td>Get all nodes within the group, regardless of whether currently attached or not</td>
- </tr>
- </tbody>
- </table>
-
- <table border="1">
- <title>Mbean <classname>BDBHAMessageStore</classname> operations</title>
- <thead>
- <tr>
- <td>Operation</td>
- <td>Parameters</td>
- <td>Returns</td>
- <td>Description</td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>removeNodeFromGroup</td>
- <td>
- <para><emphasis>nodeName</emphasis>, name of node, string</para>
- </td>
- <td>void</td>
- <td>Remove an existing node from the group</td>
- </tr>
- <tr>
- <td>updateAddress</td>
- <td>
- <itemizedlist>
- <listitem>
- <para><emphasis>nodeName</emphasis>, name of node, string</para>
- </listitem>
- <listitem>
- <para><emphasis>newHostName</emphasis>, new host name, string</para>
- </listitem>
- <listitem>
- <para><emphasis>newPort</emphasis>, new port number, int</para>
- </listitem>
- </itemizedlist>
- </td>
- <td>void</td>
- <td>Update the address of another node. The node must be in a STOPPED state.</td>
- </tr>
- </tbody>
- </table>
- <figure>
- <title>BDBHAMessageStore view from jconsole.</title>
- <graphic fileref="images/HA-BDBHAMessageStore-MBean-jconsole.png"/>
- </figure>
- <example>
- <title>Example of java code to get the node state value</title>
- <programlisting language="java"><![CDATA[
-Map<String, Object> environment = new HashMap<String, Object>();
-
-// credentials: user name and password
-environment.put(JMXConnector.CREDENTIALS, new String[] {"admin","admin"});
-JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9001/jmxrmi");
-JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
-MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
-
-ObjectName queueObjectName = new ObjectName("org.apache.qpid:type=BDBHAMessageStore,name=test");
-String state = (String)mbsc.getAttribute(queueObjectName, "NodeState");
-
-System.out.println("Node state:" + state);
- ]]></programlisting>
- <para>Example system output:</para>
- <screen><![CDATA[Node state:MASTER]]></screen>
- </example>
- </section>
-
- <section id="BDB-HA-Monitoring-cluster">
- <title>Monitoring cluster</title>
- <para>In order to discover potential issues with HA Cluster early, all nodes in the Cluster should be monitored on regular basis
- using the following techniques:</para>
- <itemizedlist>
- <listitem>
- <para>Broker log files scrapping for WARN or ERROR entries and operational log entries like:</para>
- <itemizedlist>
- <listitem>
- <para><emphasis>MST-1007 :</emphasis> Store Passivated. It can indicate that Master virtual host has gone down.</para>
- </listitem>
- <listitem>
- <para><emphasis>MST-1006 :</emphasis> Recovery Complete. It can indicate that a former Replica virtual host is up and became the Master.</para>
- </listitem>
- </itemizedlist>
- </listitem>
- <listitem>
- <para>Disk space usage and system load using system tools.</para>
- </listitem>
- <listitem>
- <para>Berkeley HA node status using <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/util/DbPing.html"><classname>DbPing</classname></ulink> utility.</para>
- <example><title>Using <classname>DbPing</classname> utility for monitoring HA nodes.</title><command>
-java -jar je-&oracleBdbProductVersion;.jar DbPing -groupName TestClusterGroup -nodeName Node-5001 -nodeHost localhost:5001 -socketTimeout 10000
-</command><screen>
-Current state of node: Node-5001 from group: TestClusterGroup
- Current state: MASTER
- Current master: Node-5001
- Current JE version: &oracleBdbProductVersion;
- Current log version: 8
- Current transaction end (abort or commit) VLSN: 165
- Current master transaction end (abort or commit) VLSN: 0
- Current active feeders on node: 0
- Current system load average: 0.35
-</screen></example>
- <para>In the example above <classname>DbPing</classname> utility requested status of Cluster node with name
- <emphasis>Node-5001</emphasis> from replication group <emphasis>TestClusterGroup</emphasis> running on host <emphasis>localhost:5001</emphasis>.
- The state of the node was reported into a system output.
- </para>
- </listitem>
- <listitem>
- <para>Using Qpid broker JMX interfaces.</para>
- <para>Mbean <classname>BDBHAMessageStore</classname> can be used to request the following node information:</para>
- <itemizedlist>
- <listitem>
- <para><emphasis>NodeState</emphasis> indicates whether node is a Master or Replica.</para>
- </listitem>
- <listitem>
- <para><emphasis>Durability</emphasis> replication durability.</para>
- </listitem>
- <listitem>
- <para><emphasis>DesignatedPrimary</emphasis> indicates whether Master node is designated primary.</para>
- </listitem>
- <listitem>
- <para><emphasis>GroupName</emphasis> replication group name.</para>
- </listitem>
- <listitem>
- <para><emphasis>NodeName</emphasis> node name.</para>
- </listitem>
- <listitem>
- <para><emphasis>NodeHostPort</emphasis> node host and port.</para>
- </listitem>
- <listitem>
- <para><emphasis>HelperHostPort</emphasis> helper host and port.</para>
- </listitem>
- <listitem>
- <para><emphasis>AllNodesInGroup</emphasis> lists of all nodes in the replication group including their names, hosts and ports.</para>
- </listitem>
- </itemizedlist>
- <para>For more details about <classname>BDBHAMessageStore</classname> MBean please refer section <link linkend="HAJMXAPI">Qpid JMX API for HA</link></para>
- </listitem>
- </itemizedlist>
- </section>
-
- <section id="HADiskSpace">
- <title>Disk space requirements</title>
- <para>Disk space is a critical resource for the HA Qpid broker.</para>
- <para>In case when a Replica goes down (or falls behind the Master in 2 node cluster where the Master is designated primary)
- and the Master continues running, the non-replicated store files are kept on the Masters disk for the period of time
- as specified in <emphasis>je.rep.repStreamTimeout</emphasis> JE setting in order to replicate this data later
- when the Replica is back. This setting is set to 1 hour by default by the broker. The setting can be overridden as described in
- <xref linkend="HAConfiguration_BDBEnvVars"/>.</para>
- <para>Depending from the application publishing/consuming rates and message sizes,
- the disk space might become overfull during this period of time due to preserved logs.
- Please, make sure to allocate enough space on your disk to avoid this from happening.
- </para>
- </section>
-
- <section id="BDB-HA-Network-Requirements">
- <title>Network Requirements</title>
- <para>The HA Cluster performance depends on the network bandwidth, its use by existing traffic, and quality of service.</para>
- <para>In order to achieve the best performance it is recommended to use a separate network infrastructure for the Qpid HA Nodes
- which might include installation of dedicated network hardware on Broker hosts, assigning a higher priority to replication ports,
- installing a cluster in a separate network not impacted by any other traffic.</para>
- </section>
-
- <section id="BDB-HA-Security">
- <title>Security</title>
- <para>At the moment Berkeley replication API supports only TCP/IP protocol to transfer replication data between Master and Replicas.</para>
- <para>As result, the replicated data is unprotected and can be intercepted by anyone having access to the replication network.</para>
- <para>Also, anyone who can access to this network can introduce a new node and therefore receive a copy of the data.</para>
- <para>In order to reduce the security risks the entire HA cluster is recommended to run in a separate network protected from general access.</para>
- </section>
-
- <section id="BDB-HA-Backup">
- <title>Backups</title>
- <para>In order to protect the entire cluster from some cataclysms which might destroy all cluster nodes,
- backups of the Master store should be taken on a regular basis.</para>
- <para>Qpid Broker distribution includes the "hot" backup utility <emphasis>backup.sh</emphasis> which can be found at broker bin folder.
- This utility can perform the backup when broker is running.</para>
- <para><emphasis>backup.sh</emphasis> script invokes <classname>org.apache.qpid.server.store.berkeleydb.BDBBackup</classname> to do the job.</para>
- <para>You can also run this class from command line like in an example below:</para>
- <example><title>Performing store backup by using <classname>BDBBackup</classname> class directly</title><command>
- java -cp qpid-bdbstore-0.18.jar org.apache.qpid.server.store.berkeleydb.BDBBackup -fromdir path/to/store/folder -todir path/to/backup/foldeAr</command>
- </example>
- <para>In the example above BDBBackup utility is called from qpid-bdbstore-0.18.jar to backup the store at <emphasis>path/to/store/folder</emphasis> and copy store logs into <emphasis>path/to/backup/folder</emphasis>.</para>
- <para>Linux and Unix users can take advantage of <emphasis>backup.sh</emphasis> bash script by running this script in a similar way.</para>
- <example><title>Performing store backup by using <classname>backup.sh</classname> bash script</title>
- <command>backup.sh -fromdir path/to/store/folder -todir path/to/backup/folder</command>
- </example>
- <note>
- <para>Do not forget to ensure that the Master store is being backed up, in the event the Node elected Master changes during
- the lifecycle of the cluster.</para>
- </note>
- </section>
-
- <section id="HAMigrationFromNonHA">
- <title>Migration of a non-HA store to HA</title>
- <para>Non HA stores starting from schema version 4 (0.14 Qpid release) can be automatically converted into HA store on broker startup if replication is first enabled with the <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/util/DbEnableReplication.html"><classname>DbEnableReplication</classname></ulink> utility from the BDB JE jar.</para>
- <para>DbEnableReplication converts a non HA store into an HA store and can be used as follows:</para>
- <example><title>Enabling replication</title><command>
-java -jar je-&oracleBdbProductVersion;.jar DbEnableReplication -h /path/to/store -groupName MyReplicationGroup -nodeName MyNode1 -nodeHostPort localhost:5001
- </command></example>
- <para>In the examples above, je jar of version &oracleBdbProductVersion; is used to convert store at <emphasis>/path/to/store</emphasis> into HA store having replication group name <emphasis>MyReplicationGroup</emphasis>, node name <emphasis>MyNode1</emphasis> and running on host <emphasis>localhost</emphasis> and port <emphasis>5001</emphasis>.</para>
- <para>After running DbEnableReplication and updating the virtual host store to configuration to be an HA message store, like in example below,
- on broker start up the store schema will be upgraded to the most recent version and the broker can be used as normal.</para>
- <example>
- <title>Example of XML configuration for HA message store</title>
- <programlisting language="xml"><![CDATA[
-<store>
- <class>org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore</class>
- <environment-path>/path/to/store</environment-path>
- <highAvailability>
- <groupName>MyReplicationGroup</groupName>
- <nodeName>MyNode1</nodeName>
- <nodeHostPort>localhost:5001</nodeHostPort>
- <helperHostPort>localhost:5001</helperHostPort>
- </highAvailability>
-</store>]]></programlisting>
- </example>
- <para>The Replica nodes can be started with empty stores. The data will be automatically copied from Master to Replica on Replica start-up.
- This will take a period of time determined by the size of the Masters store and the network bandwidth between the nodes.</para>
- <note>
- <para>Due to existing caveats in Berkeley JE with copying of data from Master into Replica it is recommended to restart the Master node after store schema upgrade is finished before starting the Replica nodes.</para>
- </note>
- </section>
-
- <section id="HADisasterRecovery">
- <title>Disaster Recovery</title>
- <para>This section describes the steps required to restore HA broker cluster from backup.</para>
- <para>The detailed instructions how to perform backup on replicated environment can be found <link linkend="BDB-HA-Backup">here</link>.</para>
- <para>At this point we assume that backups are collected on regular basis from Master node.</para>
- <para>Replication configuration of a cluster is stored internally in HA message store.
- This information includes IP addresses of the nodes.
- In case when HA message store needs to be restored on a different host with a different IP address
- the cluster replication configuration should be reseted in this case</para>
- <para>Oracle provides a command line utility <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/util/DbResetRepGroup.html"><classname>DbResetRepGroup</classname></ulink>
- to reset the members of a replication group and replace the group with a new group consisting of a single new member
- as described by the arguments supplied to the utility</para>
- <para>Cluster can be restored with the following steps:</para>
- <itemizedlist>
- <listitem><para>Copy log files into the store folder from backup</para></listitem>
- <listitem>
- <para>Use <classname>DbResetRepGroup</classname> to reset an existing environment. See an example below</para>
- <example>
- <title>Reseting of replication group with <classname>DbResetRepGroup</classname></title><command>
-java -cp je-&oracleBdbProductVersion;.jar com.sleepycat.je.rep.util.DbResetRepGroup -h ha-work/Node-5001/bdbstore -groupName TestClusterGroup -nodeName Node-5001 -nodeHostPort localhost:5001</command>
- </example>
- <para>In the example above <classname>DbResetRepGroup</classname> utility from Berkeley JE of version &oracleBdbProductVersion; is used to reset the store
- at location <emphasis>ha-work/Node-5001/bdbstore</emphasis> and set a replication group to <emphasis>TestClusterGroup</emphasis>
- having a node <emphasis>Node-5001</emphasis> which runs at <emphasis>localhost:5001</emphasis>.</para>
- </listitem>
- <listitem><para>Start a broker with HA store configured as specified on running of <classname>DbResetRepGroup</classname> utility.</para></listitem>
- <listitem><para>Start replica nodes having the same replication group and a helper host port pointing to a new master. The store content will be copied into Replicas from Master on their start up.</para></listitem>
- </itemizedlist>
- </section>
-
- <section id="HAPerformance">
- <title>Performance</title>
- <para>The aim of this section is not to provide exact performance metrics relating to HA, as this depends heavily on the test
- environment, but rather showing an impact of HA on Qpid broker performance in comparison with the Non HA case.</para>
- <para>For testing of impact of HA on a broker performance a special test script was written using Qpid performance test framework.
- The script opened a number of connections to the Qpid broker, created producers and consumers on separate connections,
- and published test messages with concurrent producers into a test queue and consumed them with concurrent consumers.
- The table below shows the number of producers/consumers used in the tests.
- The overall throughput was collected for each configuration.
- </para>
- <table border="1">
- <title>Number of producers/consumers in performance tests</title>
- <thead>
- <tr>
- <th>Test</th>
- <th>Number of producers</th>
- <th>Number of consumers</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>1</td>
- <td>1</td>
- <td>1</td>
- </tr>
- <tr>
- <td>2</td>
- <td>2</td>
- <td>2</td>
- </tr>
- <tr>
- <td>3</td>
- <td>4</td>
- <td>4</td>
- </tr>
- <tr>
- <td>4</td>
- <td>8</td>
- <td>8</td>
- </tr>
- <tr>
- <td>5</td>
- <td>16</td>
- <td>16</td>
- </tr>
- <tr>
- <td>6</td>
- <td>32</td>
- <td>32</td>
- </tr>
- <tr>
- <td>7</td>
- <td>64</td>
- <td>64</td>
- </tr>
- </tbody>
- </table>
- <para>The test was run against the following Qpid Broker configurations</para>
- <itemizedlist>
- <listitem>
- <para>Non HA Broker</para>
- </listitem>
- <listitem>
- <para>HA 2 Nodes Cluster with durability <emphasis>SYNC,SYNC,ALL</emphasis></para>
- </listitem>
- <listitem>
- <para>HA 2 Nodes Cluster with durability <emphasis>WRITE_NO_SYNC,WRITE_NO_SYNC,ALL</emphasis></para>
- </listitem>
- <listitem>
- <para>HA 2 Nodes Cluster with durability <emphasis>WRITE_NO_SYNC,WRITE_NO_SYNC,ALL</emphasis> and <emphasis>coalescing-sync</emphasis> Qpid mode</para>
- </listitem>
- <listitem>
- <para>HA 2 Nodes Cluster with durability <emphasis>WRITE_NO_SYNC,NO_SYNC,ALL</emphasis> and <emphasis>coalescing-sync</emphasis> Qpid mode</para>
- </listitem>
- <listitem>
- <para>HA 2 Nodes Cluster with durability <emphasis>NO_SYNC,NO_SYNC,ALL</emphasis> and <emphasis>coalescing-sync</emphasis> Qpid option</para>
- </listitem>
- </itemizedlist>
- <para>The evironment used in testing consisted of 2 servers with 4 CPU cores (2x Intel(r) Xeon(R) CPU 5150@2.66GHz), 4GB of RAM
- and running under OS Red Hat Enterprise Linux AS release 4 (Nahant Update 4). Network bandwidth was 1Gbit.
- </para>
- <para>We ran Master node on the first server and Replica and clients(both consumers and producers) on the second server.</para>
- <para>In non-HA case Qpid Broker was run on a first server and clients were run on a second server.</para>
- <para>The table below contains the test results we measured on this environment for different Broker configurations.</para>
- <para>Each result is represented by throughput value in KB/second and difference in % between HA configuration and non HA case for the same number of clients.</para>
- <table border="1">
- <title>Performance Comparison</title>
- <thead>
- <tr>
- <td>Test/Broker</td>
- <td>No HA</td>
- <td>SYNC, SYNC, ALL</td>
- <td>WRITE_NO_SYNC, WRITE_NO_SYNC, ALL</td>
- <td>WRITE_NO_SYNC, WRITE_NO_SYNC, ALL - coalescing-sync</td>
- <td>WRITE_NO_SYNC, NO_SYNC,ALL - coalescing-sync</td>
- <td>NO_SYNC, NO_SYNC, ALL - coalescing-sync</td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>1 (1/1)</td>
- <td>0.0%</td>
- <td>-61.4%</td>
- <td>117.0%</td>
- <td>-16.02%</td>
- <td>-9.58%</td>
- <td>-25.47%</td>
- </tr>
- <tr>
- <td>2 (2/2)</td>
- <td>0.0%</td>
- <td>-75.43%</td>
- <td>67.87%</td>
- <td>-66.6%</td>
- <td>-69.02%</td>
- <td>-30.43%</td>
- </tr>
- <tr>
- <td>3 (4/4)</td>
- <td>0.0%</td>
- <td>-84.89%</td>
- <td>24.19%</td>
- <td>-71.02%</td>
- <td>-69.37%</td>
- <td>-43.67%</td>
- </tr>
- <tr>
- <td>4 (8/8)</td>
- <td>0.0%</td>
- <td>-91.17%</td>
- <td>-22.97%</td>
- <td>-82.32%</td>
- <td>-83.42%</td>
- <td>-55.5%</td>
- </tr>
- <tr>
- <td>5 (16/16)</td>
- <td>0.0%</td>
- <td>-91.16%</td>
- <td>-21.42%</td>
- <td>-86.6%</td>
- <td>-86.37%</td>
- <td>-46.99%</td>
- </tr>
- <tr>
- <td>6 (32/32)</td>
- <td>0.0%</td>
- <td>-94.83%</td>
- <td>-51.51%</td>
- <td>-92.15%</td>
- <td>-92.02%</td>
- <td>-57.59%</td>
- </tr>
- <tr>
- <td>7 (64/64)</td>
- <td>0.0%</td>
- <td>-94.2%</td>
- <td>-41.84%</td>
- <td>-89.55%</td>
- <td>-89.55%</td>
- <td>-50.54%</td>
- </tr>
- </tbody>
- </table>
- <para>The figure below depicts the graphs for the performance test results</para>
- <figure>
- <title>Test results</title>
- <graphic fileref="images/HA-perftests-results.png"/>
- </figure>
- <para>On using durability <emphasis>SYNC,SYNC,ALL</emphasis> (without coalescing-sync) the performance drops significantly (by 62-95%) in comparison with non HA broker.</para>
- <para>Whilst, on using durability <emphasis>WRITE_NO_SYNC,WRITE_NO_SYNC,ALL</emphasis> (without coalescing-sync) the performance drops by only half, but with loss of durability guarantee, so is not recommended.</para>
- <para>In order to have better performance with HA, Qpid Broker comes up with the special mode called <link linkend="HADurabilityGuarantee_CoalescingSync">coalescing-sync</link>,
- With this mode enabled, Qpid broker batches the concurrent transaction commits and syncs transaction data into Master disk in one go.
- As result, the HA performance only drops by 25-60% for durability <emphasis>NO_SYNC,NO_SYNC,ALL</emphasis> and by 10-90% for <emphasis>WRITE_NO_SYNC,WRITE_NO_SYNC,ALL</emphasis>.</para>
- </section>
-
-</section>
diff --git a/doc/book/src/java-broker/How-to-Tune-M3-Java-Broker-Performance.xml b/doc/book/src/java-broker/How-to-Tune-M3-Java-Broker-Performance.xml
deleted file mode 100644
index f7fffbaceb..0000000000
--- a/doc/book/src/java-broker/How-to-Tune-M3-Java-Broker-Performance.xml
+++ /dev/null
@@ -1,172 +0,0 @@
-<?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.
-
--->
-<section id="How-to-Tune-M3-Java-Broker-Performance">
- <title>
- How to Tune M3 Java Broker Performance
- </title>
- <section role="h3" id="HowtoTuneM3JavaBrokerPerformance-ProblemStatement">
- <title>
- Problem
- Statement
- </title>
- <para>
- During destructive testing of the Qpid M3 Java Broker, we tested
- some tuning techniques and deployment changes to improve the Qpid
- M3 Java Broker's capacity to maintain high levels of throughput,
- particularly in the case of a slower consumer than produceer
- (i.e. a growing backlog).
- </para>
- <para>
- The focus of this page is to detail the results of tuning &amp;
- deployment changes trialled.
- </para>
- <para>
- The successful tuning changes are applicable for any deployment
- expecting to see bursts of high volume throughput (1000s of
- persistent messages in large batches). Any user wishing to use
- these options <emphasis>must test them thoroughly in their own
- environment with representative volumes</emphasis>.
- </para>
- <!--h3-->
- </section>
-
- <section role="h3" id="HowtoTuneM3JavaBrokerPerformance-SuccessfulTuningOptions">
- <title>
- Successful
- Tuning Options
- </title>
- <para>
- The key scenario being taregetted by these changes is a broker
- under heavy load (processing a large batch of persistent
- messages)can be seen to perform slowly when filling up with an
- influx of high volume transient messages which are queued behind
- the persistent backlog. However, the changes suggested will be
- equally applicable to general heavy load scenarios.
- </para>
- <para>
- The easiest way to address this is to separate streams of
- messages. Thus allowing the separate streams of messages to be
- processed, and preventing a backlog behind a particular slow
- consumer.
- </para>
- <para>
- These strategies have been successfully tested to mitigate this
- problem:
- </para>
- <table>
- <title/>
- <tgroup cols="2">
- <tbody>
- <row>
- <entry>
- Strategy
- </entry>
- <entry>
- Result
- </entry>
- </row>
- <row>
- <entry>
- Seperate connections to one broker for separate streams of
- messages.
- </entry>
- <entry>
- Messages processed successfully, no problems experienced
- </entry>
- </row>
- <row>
- <entry>
- Seperate brokers for transient and persistent messages.
- </entry>
- <entry>
- Messages processed successfully, no problems experienced
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>
- <emphasis>Separate Connections</emphasis>
- Using separate connections effectively means that the two streams
- of data are not being processed via the same buffer, and thus the
- broker gets &amp; processes the transient messages while
- processing the persistent messages. Thus any build up of
- unprocessed data is minimal and transitory.
- </para>
- <para>
- <emphasis>Separate Brokers</emphasis>
- Using separate brokers may mean more work in terms of client
- connection details being changed, and from an operational
- perspective. However, it is certainly the most clear cut way of
- isolating the two streams of messages and the heaps impacted.
- </para>
- <section role="h4" id="HowtoTuneM3JavaBrokerPerformance-Additionaltuning">
- <title>
- Additional
- tuning
- </title>
- <para>
- It is worth testing if changing the size of the Qpid read/write
- thread pool improves performance (eg. by setting
- JAVA_OPTS="-Damqj.read_write_pool_size=32" before running
- qpid-server). By default this is equal to the number of CPU
- cores, but a higher number may show better performance with some
- work loads.
- </para>
- <para>
- It is also important to note that you should give the Qpid broker
- plenty of memory - for any serious application at least a -Xmx of
- 3Gb. If you are deploying on a 64 bit platform, a larger heap is
- definitely worth testing with. We will be testing tuning options
- around a larger heap shortly.
- </para>
- <!--h4-->
- </section>
- <!--h3-->
- </section>
-
- <section role="h3" id="HowtoTuneM3JavaBrokerPerformance-NextSteps">
- <title>
- Next
- Steps
- </title>
- <para>
- These two options have been testing using a Qpid test case, and
- demonstrated that for a test case with a profile of persistent
- heavy load following by constant transient high load traffic they
- provide significant improvment.
- </para>
- <para>
- However, the deploying project <emphasis>must</emphasis> complete their own
- testing, using the same destructive test cases, representative
- message paradigms &amp; volumes, in order to verify the proposed
- mitigation options.
- </para>
- <para>
- The using programme should then choose the option most applicable
- for their deployment and perform BAU testing before any
- implementation into a production or pilot environment.
- </para>
- <!--h3-->
- </section>
-</section>
diff --git a/doc/book/src/java-broker/How-to-Use-SlowConsumerDisconnect.xml b/doc/book/src/java-broker/How-to-Use-SlowConsumerDisconnect.xml
deleted file mode 100644
index 4e0ce0f7e0..0000000000
--- a/doc/book/src/java-broker/How-to-Use-SlowConsumerDisconnect.xml
+++ /dev/null
@@ -1,280 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<!--
-
- 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.
-
--->
-<section id="Java-Broker-Slow-Consumer-Disconnect">
- <title>Slow Consumer Disconnect - User Guide</title>
-
- <section>
-<title>Introduction</title>
- <para>Slow Consumer Disconnect (SCD) is a new feature in Qpid that provides a configurable
- mechanism to prevent a single slow consumer from causing a back up of unconsumed messages on
- the broker. </para>
-
- <para>This is most relevant where Topics are in use, since a published message is not removed
- from the broker's memory until all subscribers have acknowledged that message. </para>
-
- <para>Cases where a consumer is 'slow' can arise due to one of the following: poor network
- connectivity exists; a transient system issue affects a single client; a single subscriber
- written by a client team is behaving incorrectly and not acknowledging messages; a
- downstream resource such as a database is non-responsive. </para>
-
- <para>SCD will enable the application owner to configure limits for a given consumer's queue and
- the behaviour to execute when those limits are reached. </para>
-
- </section>
-
- <section>
-<title>What can it do?</title>
- <para>SCD is only applicable to topics or durable subscriptions and can be configured on either
- a topic or a subscription name. </para>
-
- <para>On triggering of a specified threshold the offending client will be disconnected from the
- broker with a 506 error code wrapped in a JMSException returned to the client via the
- ExceptionListener registered on the Connection object. </para>
-
- <para>Note that it is essential that an ExceptionListener be specified by the client on
- creation of the connection and that exceptions coming back on that listener are handled
- correctly. </para>
-
- </section>
-
- <section>
-<title>Frequency of SCD Checking</title>
- <section>
-<title><emphasis role='bold'>Configuring Frequency</emphasis></title>
- <para>You can configure the frequency with which the SCD process will check for slow consumers,
- along with the unit of time used to specify that frequency. </para>
-
- <para>The <emphasis role="italic">virtualhosts.virtualhost.hostname.slow-consumer-detection</emphasis>
- elements <emphasis role="italic">delay</emphasis> and <emphasis role="italic">timeunit</emphasis>
- are used to specify the frequency and timeunit respectively in the virtualhosts.xml
- file e.g. </para>
-
-<programlisting>
-&lt;virtualhosts&gt;
- &lt;default&gt;test&lt;/default&gt;
- &lt;virtualhost&gt;
- &lt;name&gt;test&lt;/name&gt;
- &lt;test&gt;
- &lt;slow-consumer-detection&gt;
- &lt;delay&gt;60&lt;delay/&gt;
- &lt;timeunit&gt;seconds&lt;timeunit/&gt;
- &lt;slow-consumer-detection/&gt;
- &lt;/test&gt;
- &lt;/virtualhost&gt;
-&lt;/virtualhosts&gt;
-</programlisting>
-
- </section>
-
- <section>
-<title><emphasis role='bold'>SCD Log output</emphasis></title>
- <para>When the SCD component finds a queue with a configured threshold to check, the operational
- logging component (if enabled) will output the following line:</para>
-
- <programlisting>
- SCD-1003 : Checking Status of Queue
- </programlisting>
-
- </section>
-
- </section>
-
- <section>
-<title>Client Exception<emphasis role='bold'>s</emphasis></title>
- <para>When a Slow Consumer is disconnected, the client receives a 506 error from the broker
- wrapped in a JMSException and the Session and Connection are closed:</para>
-
-<programlisting>
-Dispatcher-Channel-1 2010-09-01 16:23:34,206 INFO [qpid.client.AMQSession.Dispatcher]
- Dispatcher-Channel-1 thread terminating for channel 1:org.apache.qpid.client.AMQSession_0_8@1de8aa8
-pool-2-thread-3 2010-09-01 16:23:34,238 INFO [apache.qpid.client.AMQConnection] Closing AMQConnection due to
- :org.apache.qpid.AMQChannelClosedException: Error: Consuming to slow. [error code 506: resource error]
-javax.jms.JMSException: 506
-at org.apache.qpid.client.AMQConnection.exceptionReceived(AMQConnection.java:1396)
-at org.apache.qpid.client.protocol.AMQProtocolHandler.exception(AMQProtocolHandler.java:329)
-at org.apache.qpid.client.protocol.AMQProtocolHandler.methodBodyReceived(AMQProtocolHandler.java:536)
-at org.apache.qpid.client.protocol.AMQProtocolSession.methodFrameReceived(AMQProtocolSession.java:453)
-at org.apache.qpid.framing.AMQMethodBodyImpl.handle(AMQMethodBodyImpl.java:93)
-at org.apache.qpid.client.protocol.AMQProtocolHandler$1.run(AMQProtocolHandler.java:462)
-at org.apache.qpid.pool.Job.processAll(Job.java:110)
-at org.apache.qpid.pool.Job.run(Job.java:149)
-at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
-at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
-at java.lang.Thread.run(Thread.java:619)
-Caused by: org.apache.qpid.AMQChannelClosedException: Error: Consuming to slow. [error code 506: resource error]
-at org.apache.qpid.client.handler.ChannelCloseMethodHandler.methodReceived(ChannelCloseMethodHandler.java:96)
-at org.apache.qpid.client.handler.ClientMethodDispatcherImpl.dispatchChannelClose(ClientMethodDispatcherImpl.java:163)
-at org.apache.qpid.framing.amqp_8_0.ChannelCloseBodyImpl.execute(ChannelCloseBodyImpl.java:140)
-at org.apache.qpid.client.state.AMQStateManager.methodReceived(AMQStateManager.java:112)
-at org.apache.qpid.client.protocol.AMQProtocolHandler.methodBodyReceived(AMQProtocolHandler.java:511)
-... 8 more
-main 2010-09-01 16:23:34,316 INFO [apache.qpid.client.AMQSession] Closing session:
- org.apache.qpid.client.AMQSession_0_8@ffeef1
-</programlisting>
-
- </section>
-
- <section>
-<title>Disconnection Thresholds</title>
- <section>
-<title>Topic Subscriptions</title>
- <para>One key feature of SCD is the disconnection of a consuming client when a specified
- threshold is exceeded. For a pub-sub model using topics, this means that messages will no
- longer be delivered to the private queue which was associated with that consuming client,
- thus reducing any associated backlog in the broker. </para>
-
- </section>
-
- <section>
-<title>Durable Topic Subscriptions</title>
- <para>For durable subscriptions, simply disconnecting the consuming client will not suffice
- since the associated queue is by definition durable and messages would continue to flow to
- it after disconnection, potentially worsening any backing up of data on the broker. </para>
-
- <para>The solution is to configure durable subscriptions to delete the underlying queue on
- disconnection. This means that messages will no longer be delivered to the private queue
- associated with the subscription, thus preventing any backlog. </para>
-
- <para>Full details of how to configure the thresholds are provided below. </para>
-
- </section>
-
- <section>
-<title>Message Age Threshold</title>
- <para>You can configure SCD to be triggered on a topic or subscription when the oldest message
- in the associated private queue for the consumer ages beyond the specified value, in
- milliseconds. </para>
-
- </section>
-
- <section>
-<title>Queue Depth Threshold</title>
- <para>You can opt to use the depth of the queue in bytes as a threshold. SCD will be triggered
- by a queue depth greater than the threshold specified i.e. when a broker receives a
- message that takes the queue depth over the threshold. </para>
-
- </section>
-
- <section>
-<title>Message Count Threshold</title>
- <para>You can use the message count for the consumer's queue as the trigger, where a count
- higher than that specified will trigger disconnection. </para>
-
- </section>
-
- <section>
-<title><emphasis role='bold'>Delete Policy</emphasis></title>
- <para>You can configure the policy you wish to apply in your broker configuration. There are
- currently 2 policies available: </para>
-
- <para>
-<emphasis role='bold'>Delete Temporary Queues Only</emphasis>
- </para>
-
- <para>If you do not specify a &lt;topicDelete/&gt; element in your configuration, then only temporary
- queues associated with a topic subscription will be deleted on client disconnect. This is
- the default behaviour. </para>
- <para/>
-
- <para>
-<emphasis role='bold'>Delete Durable Subscription Queues</emphasis>
- </para>
-
- <para>If you add the &lt;topicDelete/&gt; element with the sub-element
- &lt;delete-persistent/&gt; to your config, then the persistent queue which is associated
- with durable subscriptions to a topic will also be deleted. This is an important
- consideration since without deleting the underlying queue the client's unconsumed data
- will grow indefinitely while they will be unable to reconnect to that queue due to the SCD
- threshold configured, potentially having an adverse effect on the application or broker in
- use.</para>
- <para/>
-
- <para><emphasis role="bold"> Example Topic Configuration </emphasis></para>
-
- <para/>
-
- <para>
-The following steps are required to configure SCD:
- </para>
-
-<itemizedlist>
- <listitem>
- <para>Enable SCD checking for your virtual host</para>
- </listitem>
- <listitem>
- <para>Specify frequency for SCD checking</para>
- </listitem>
- <listitem>
- <para>Define thresholds for the topic</para>
- </listitem>
- <listitem>
- <para>Define the policy to apply on trigger </para>
- </listitem>
-</itemizedlist>
-
- <para>The example below shows a simple definition, with all three thresholds specified and a
- simple disconnection, with deletion of any temporary queue, defined. </para>
-
- <para>For a durable subscription to this topic, no queue deletion would be applied on disconnect
- - which is likely to be undesirable (see section above). </para>
-
-<programlisting>
-&lt;topics&gt;
- &lt;topic&gt;
- &lt;name&gt;stocks.us.*&lt;/name&gt;
- &lt;slow-consumer-detection&gt;
- &lt;!-- The maximum depth before which --&gt;
- &lt;!-- the policy will be applied--&gt;
- &lt;depth&gt;4235264&lt;/depth&gt;
- &lt;!-- The maximum message age before which --&gt;
- &lt;!-- the policy will be applied--&gt;
- &lt;messageAge&gt;600000&lt;/messageAge&gt;
- &lt;!-- The maximum number of message before --&gt;
- &lt;!-- which the policy will be applied--&gt;
- &lt;messageCount&gt;50&lt;/messageCount&gt;
- &lt;!-- Policy Selection --&gt;
- &lt;policy name="TopicDelete"/&gt;
- &lt;/slow-consumer-detection&gt;
- &lt;/topic&gt;
-&lt;/topics&gt;
-</programlisting>
-
- </section>
-
- </section>
-
- <section>
-<title>Important Points To Note</title>
- <para> Client application developers should be educated about how to correctly handle being
- disconnected with a 506 error code, to avoid them getting into a thrashing state where they
- continually attempt to connect, fail to consume fast enough and are disconnected again. </para>
-
- <para>Clients affected by slow consumer disconnect configuration should always use transactions
- where duplicate processing of an incoming message would have adverse affects, since they may
- receive a message more than once if disconnected before acknowledging a message in flight. </para>
-
- </section>
-
- </section>
-
diff --git a/doc/book/src/java-broker/Java-Broker-Concepts-Authentication-Providers.xml b/doc/book/src/java-broker/Java-Broker-Concepts-Authentication-Providers.xml
new file mode 100644
index 0000000000..3a2825826b
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Concepts-Authentication-Providers.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Concepts-Authentication-Providers">
+<title>Authentication Providers</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Concepts-Exchanges.xml b/doc/book/src/java-broker/Java-Broker-Concepts-Exchanges.xml
new file mode 100644
index 0000000000..af14b46a69
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Concepts-Exchanges.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Concepts-Exchanges">
+<title>Exchanges</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Concepts-Other-Services.xml b/doc/book/src/java-broker/Java-Broker-Concepts-Other-Services.xml
new file mode 100644
index 0000000000..bb694d81da
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Concepts-Other-Services.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Concepts-Other-Services">
+<title>Other Services</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Concepts-Ports.xml b/doc/book/src/java-broker/Java-Broker-Concepts-Ports.xml
new file mode 100644
index 0000000000..afbb612bc4
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Concepts-Ports.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Concepts-Ports">
+<title>Ports</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Concepts-Protocols.xml b/doc/book/src/java-broker/Java-Broker-Concepts-Protocols.xml
new file mode 100644
index 0000000000..45a62ce5ab
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Concepts-Protocols.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Concepts-Protocols">
+<title>Protocols</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Concepts-Queues.xml b/doc/book/src/java-broker/Java-Broker-Concepts-Queues.xml
new file mode 100644
index 0000000000..a4b0995a7e
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Concepts-Queues.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Concepts-Queues">
+<title>Queues</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Concepts-Virtual-Hosts.xml b/doc/book/src/java-broker/Java-Broker-Concepts-Virtual-Hosts.xml
new file mode 100644
index 0000000000..c12a543140
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Concepts-Virtual-Hosts.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Concepts-Virtual-Hosts">
+<title>Virtual Hosts</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Concepts.xml b/doc/book/src/java-broker/Java-Broker-Concepts.xml
new file mode 100644
index 0000000000..013308fb8f
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Concepts.xml
@@ -0,0 +1,32 @@
+<?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.
+
+-->
+
+<chapter id="Java-Broker-Concepts">
+ <title>Concepts</title>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Concepts-Virtual-Hosts.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Concepts-Exchanges.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Concepts-Queues.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Concepts-Ports.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Concepts-Protocols.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Concepts-Authentication-Providers.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Concepts-Other-Services.xml"/>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Config-Files.xml b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Config-Files.xml
new file mode 100644
index 0000000000..66d471fb37
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Config-Files.xml
@@ -0,0 +1,178 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Configuring-And-Managing-Config-Files">
+<title>Config Files</title>
+
+ <para>
+ This section shows how to configure and manage broker.
+ </para>
+
+ <section role="h2" id="Java-Broker-Configuring-And-Managing-Config-Files-Configuration">
+ <title>Configuration file</title>
+ <para>Broker can be configured using XML configuration files. By default, broker is looking for configuration file at ${QPID_HOME}/etc/config.xml. The default configuration location can be overridden by specifying command line option <emphasis>-c &lt;path to configuration&gt;</emphasis> on broker start up.</para>
+ </section>
+
+ <section role="h2" id="Java-Broker-Configuring-And-Managing-Config-Files-Management">
+ <title>Management Configuration</title>
+ <para>
+ Management interfaces can be configured in <emphasis>management</emphasis> section of broker configuration file. The example of the management section is provided below.
+ </para>
+ <example>
+ <title>Management configuration</title>
+ <programlisting><![CDATA[
+ <broker>
+ ...
+ <management>
+ <enabled>true</enabled>
+ <jmxport>
+ <registryServer>8999</registryServer>
+ </jmxport>
+ <ssl>
+ <enabled>false</enabled>
+ <keyStorePath>${conf}/qpid.keystore</keyStorePath>
+ <keyStorePassword>password</keyStorePassword>
+ </ssl>
+ <http>
+ <enabled>true</enabled>
+ </http>
+ <https>
+ <enabled>false</enabled>
+ </https>
+ </management>
+ ...
+ </broker>]]></programlisting>
+ </example>
+ </section>
+ <section role="h2" id="Java-Broker-Configuring-And-Managing-Config-Files-JMX-Management">
+ <title>JMX Management Configuration</title>
+ <para>
+ JMX management can be configured in <emphasis>management</emphasis> section of broker configuration file.
+ </para>
+ <para>An <emphasis>enabled</emphasis> element in the <emphasis>management</emphasis> section is used to enable or disable the JMX interfaces. Setting it to <emphasis>true</emphasis> causes the broker to start the management plugin if such is available on the broker classpath.</para>
+ <para>JMX management requires two ports which can be configured in <emphasis>jmxport</emphasis> sub-section of <emphasis>management</emphasis>:
+ <itemizedlist>
+ <listitem><para>RMI port (8999 by default) can be configured in an element <emphasis>jmxport/registryServer</emphasis></para></listitem>
+ <listitem><para>Connector port can be configured in an element <emphasis>jmxport/connectorServer</emphasis>. If configuration element <emphasis>connectorServer</emphasis> is not provided than the connector port defaults to <emphasis>100 + registryServer port</emphasis>.</para></listitem>
+ </itemizedlist>
+ </para>
+ <example>
+ <title>Enabling JMX Management and configuring JMX ports</title>
+ <programlisting>
+&lt;broker&gt;
+...
+&lt;management&gt;
+ <emphasis>&lt;enabled>true&lt;/enabled&gt;</emphasis> <co id="java-broker-example-jmx-management-0"/>
+ &lt;jmxport&gt;
+ <emphasis>&lt;registryServer>7999&lt;/registryServer&gt;</emphasis> <co id="java-broker-example-jmx-management-1"/>
+ <emphasis>&lt;connectorServer>7998&lt;/connectorServer&gt;</emphasis> <co id="java-broker-example-jmx-management-2"/>
+ &lt;/jmxport&gt;
+&lt;/management&gt;
+...
+&lt;/broker&gt;</programlisting>
+ </example>
+ <para>In the snippet above the following is configured:</para>
+ <calloutlist>
+ <callout arearefs="java-broker-example-jmx-management-0"><para>Enable JMX management</para></callout>
+ <callout arearefs="java-broker-example-jmx-management-1"><para>Set RMI port to 7999</para></callout>
+ <callout arearefs="java-broker-example-jmx-management-2"><para>Set connector port to 7998</para></callout>
+ </calloutlist>
+ <para>SSL can be configured to use on the connector port in the sub-section <emphasis>ssl</emphasis> of the <emphasis>management</emphasis> section. See <xref linkend="Java-Broker-Configuring-And-Managing-Config-Files-SSL-keystore-configuration"/> for details.</para>
+ <para>In order to use SSL with JMX management an element <emphasis>ssl/enabled</emphasis> needs to be set to <emphasis>true</emphasis>.</para>
+ </section>
+ <section role="h2" id="Java-Broker-Configuring-And-Managing-Config-Files-SSL-keystore-configuration">
+ <title>Management SSL key store configuration</title>
+ <para>
+ This section describes how to configure the key store to use in SSL connections in both JMX and Web management interfaces.
+ </para>
+ <para>The following examples demonstrates how to configure keystore for management</para>
+ <example>
+ <title>Management key store configuration</title>
+ <programlisting>
+&lt;broker&gt;
+...
+&lt;management&gt;
+...
+ &lt;ssl&gt;
+ &lt;enabled&gt;true&lt;/enabled&gt; <co id="java-broker-example-management-keystore-0"/>
+ &lt;keyStorePath&gt;${conf}/qpid.keystore&lt;/keyStorePath&gt; <co id="java-broker-example-management-keystore-1"/>
+ &lt;keyStorePassword&gt;password&lt;/keyStorePassword&gt; <co id="java-broker-example-management-keystore-2"/>
+ &lt;/ssl&gt;
+...
+&lt;/management&gt;
+...
+&lt;/broker&gt;</programlisting>
+ </example>
+ <calloutlist>
+ <callout arearefs="java-broker-example-management-keystore-0"><para>Enable SSL on JMX connector port only. This setting does not effect the web management interfaces.</para></callout>
+ <callout arearefs="java-broker-example-management-keystore-1"><para>Set path to the key store file</para></callout>
+ <callout arearefs="java-broker-example-management-keystore-2"><para>Set keystore password</para></callout>
+ </calloutlist>
+ </section>
+ <section role="h2" id="Java-Broker-Configuring-And-Managing-Config-Files-Web-Management">
+ <title>Web Management Configuration</title>
+ <para>
+ Web management can be configured in <emphasis>management</emphasis> section of broker configuration file.
+ </para>
+ <para>Sub-section <emphasis>http</emphasis> is used to enable web management on http port.</para>
+ <para>Sub-section <emphasis>https</emphasis> is used to enable web management on https port.</para>
+ <para>The following example shows how to configure http and https ports</para>
+ <example>
+ <title>Enabling web management</title>
+ <programlisting>
+&lt;broker&gt;
+...
+&lt;management&gt;
+...
+ &lt;http&gt;
+ &lt;enabled&gt;true&lt;/enabled&gt; <co id="java-broker-example-management-web-0"/>
+ &lt;port&gt;9090&lt;/port&gt; <co id="java-broker-example-management-web-1"/>
+ &lt;basic-auth&gt;false&lt;/basic-auth&gt; <co id="java-broker-example-management-web-2"/>
+ &lt;sasl-auth&gt;true&lt;/sasl-auth&gt; <co id="java-broker-example-management-web-3"/>
+ &lt;session-timeout&gt;600&lt;/session-timeout&gt; <co id="java-broker-example-management-web-4"/>
+ &lt;/http&gt;
+
+ &lt;https&gt;
+ &lt;enabled&gt;true&lt;/enabled&gt; <co id="java-broker-example-management-web-5"/>
+ &lt;port&gt;9443&lt;/port&gt; <co id="java-broker-example-management-web-6"/>
+ &lt;sasl-auth&gt;true&lt;/sasl-auth&gt; <co id="java-broker-example-management-web-7"/>
+ &lt;basic-auth&gt;true&lt;/basic-auth&gt; <co id="java-broker-example-management-web-8"/>
+ &lt;/https&gt;
+...
+&lt;/management&gt;
+...
+&lt;/broker&gt;</programlisting>
+ </example>
+ <calloutlist>
+ <callout arearefs="java-broker-example-management-web-0"><para>Enable web management on http port. Default is true.</para></callout>
+ <callout arearefs="java-broker-example-management-web-1"><para>Set web management http port to 9090. Default is 8080.</para></callout>
+ <callout arearefs="java-broker-example-management-web-2"><para>Disable basic authentication on http port for REST services only. Default is false.</para></callout>
+ <callout arearefs="java-broker-example-management-web-3"><para>Enable SASL authentication on http port for REST services and web console. Default is true.</para></callout>
+ <callout arearefs="java-broker-example-management-web-4"><para>Set session timeout in seconds. Default is 15 minutes.</para></callout>
+ <callout arearefs="java-broker-example-management-web-5"><para>Enable web management on https port. Default is false.</para></callout>
+ <callout arearefs="java-broker-example-management-web-6"><para>Set web management https port to 9443. Default is 8443.</para></callout>
+ <callout arearefs="java-broker-example-management-web-7"><para>Enable SASL authentication on https port for REST services and web console. Default is true.</para></callout>
+ <callout arearefs="java-broker-example-management-web-8"><para>Enable basic authentication on https port for REST services only. Default is true.</para></callout>
+ </calloutlist>
+ <note><para>Please configure the keystore to use with the https web management port. See <xref linkend="Java-Broker-Configuring-And-Managing-Config-Files-SSL-keystore-configuration"/> for details.</para></note>
+ </section>
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-JMX.xml b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-JMX.xml
new file mode 100644
index 0000000000..122da6d267
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-JMX.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Configuring-And-Managing-JMX">
+<title>JMX</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Other-Tooling.xml b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Other-Tooling.xml
new file mode 100644
index 0000000000..cf9d9497dd
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Other-Tooling.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Configuring-And-Managing-Other-Tooling">
+<title>Other Tooling</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-REST-API.xml b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-REST-API.xml
new file mode 100644
index 0000000000..8bd63ade7a
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-REST-API.xml
@@ -0,0 +1,263 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Configuring-And-Managing-REST-API">
+<title>REST API</title>
+ <section id="Java-Broker-Configuring-And-Managing-REST-API-Overview">
+ <title>REST API Overview</title>
+ <para>This section provides an overview of REST management API.</para>
+ <para>If web management is enabled (see <xref linkend="Java-Broker-Configuring-And-Managing-Config-Files-Web-Management"/>)
+ the REST API can be used to monitor and manage the broker instance.</para>
+ <para>The Qpid broker REST services support traditional REST model which uses the GET method requests to retrieve
+ the information about broker configured objects, DELETE method requests to delete the configured object,
+ PUT to create the configured object and POST to update the configured objects.</para>
+ <para>The table below lists the available REST services with brief description how they can be used.</para>
+
+ <table>
+ <title>Rest services</title>
+ <tgroup cols="6">
+ <thead>
+ <row>
+ <entry>Rest service URL</entry>
+ <entry>Description</entry>
+ <entry>GET</entry>
+ <entry>PUT</entry>
+ <entry>POST</entry>
+ <entry>DELETE</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><para>/rest/broker</para></entry>
+ <entry><para>Rest service to manage broker instance</para></entry>
+ <entry><para>Retrieves the details of broker configuration</para></entry>
+ <entry><para>Not implemented yet</para></entry>
+ <entry><para>Not implemented yet</para></entry>
+ <entry><para>Not implemented yet</para></entry>
+ </row>
+ <row>
+ <entry><para>/rest/authenticationprovider</para>
+ <para>/rest/authenticationprovider/&lt;authentication provider name&gt;</para>
+ </entry>
+ <entry>Rest service to manage authentication providers on the broker</entry>
+ <entry>Retrieves the details about authentication providers</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry><para>/rest/user</para>
+ <para>/rest/user/&lt;authentication provider name&gt;/&lt;user name&gt;</para>
+ </entry>
+ <entry>Rest service to manage user account</entry>
+ <entry>Retrieves the details about user account</entry>
+ <entry>Creates user account</entry>
+ <entry>Updates user password</entry>
+ <entry>Deletes user account</entry>
+ </row>
+ <row>
+ <entry><para>/rest/groupprovider</para>
+ <para>/rest/groupprovider/&lt;group provider name&gt;</para>
+ </entry>
+ <entry>Rest service to manage group providers</entry>
+ <entry>Retrieves the details about group provider(s)</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry><para>/rest/group</para>
+ <para>/rest/group/&lt;group provider name&gt;/&lt;group name&gt;</para>
+ </entry>
+ <entry>Rest service to manage user group</entry>
+ <entry>Retrieves the details about user group</entry>
+ <entry>Creates group</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Deletes group</entry>
+ </row>
+ <row>
+ <entry><para>/rest/groupmember</para>
+ <para>/rest/groupmember/&lt;group provider name &gt;/&lt;group name&gt;/&lt;user name&gt;</para>
+ </entry>
+ <entry>Rest service to manage group member(s)</entry>
+ <entry>Retrieves the details about group member(s)</entry>
+ <entry>Add user to group</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Deletes user from group</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/port</para>
+ <para>/rest/port/&lt;port name&gt;</para>
+ </entry>
+ <entry>Rest service to manage broker ports(s)</entry>
+ <entry>Retrieves the details about the broker port(s)</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/port</para>
+ <para>/rest/port/&lt;port name&gt;</para>
+ </entry>
+ <entry>Rest service to manage broker ports(s)</entry>
+ <entry>Retrieves the details about the broker port(s)</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/queue</para>
+ <para>/rest/queue/&lt;virtual host name&gt;/&gt;queue name&gt;</para>
+ </entry>
+ <entry>Rest service to manage queue(s)</entry>
+ <entry>Retrieves the details about the queue(s)</entry>
+ <entry>Creates queue</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Deletes queue</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/exchange</para>
+ <para>/rest/exchange/&lt;virtual host name&gt;/&lt;exchange name&gt;</para>
+ </entry>
+ <entry>Rest service to manage exchange(s)</entry>
+ <entry>Retrieves the details about the exchange(s)</entry>
+ <entry>Creates exchange</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Deletes exchange</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/binding</para>
+ <para>/rest/binding/&lt;virtual host name&gt;/&lt;exchange name&gt;/&lt;queue name&gt;/&lt;binding name&gt;</para>
+ </entry>
+ <entry>Rest service to manage binding(s)</entry>
+ <entry>Retrieves the details about the binding(s)</entry>
+ <entry>Binds a queue to an exchange</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Deletes binding</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/connection</para>
+ <para>/rest/connection/&lt;virtual host name&gt;/&lt;connection name&gt;</para>
+ </entry>
+ <entry>Rest service to manage connection(s)</entry>
+ <entry>Retrieves the details about the connection(s)</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/session</para>
+ <para>/rest/session/&lt;virtual host name&gt;/&lt;connection name&gt;/&lt;session name&gt;</para>
+ </entry>
+ <entry>Rest service to manage session(s)</entry>
+ <entry>Retrieves the details about the session(s)</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/message/*</para>
+ </entry>
+ <entry>Rest service to manage messages(s)</entry>
+ <entry>Retrieves the details about the messages(s)</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Copies, moves messages</entry>
+ <entry>Deletes messages</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/message-content/*</para>
+ </entry>
+ <entry>Rest service to retrieve message content</entry>
+ <entry>Retrieves the message content</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/logrecords</para>
+ </entry>
+ <entry>Rest service to retrieve broker logs</entry>
+ <entry>Retrieves the broker logs</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/sasl</para>
+ </entry>
+ <entry>Sasl authentication</entry>
+ <entry>Retrieves user current authentication status and broker supported SASL mechanisms</entry>
+ <entry>Authenticates user using supported SASL mechanisms</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ <row>
+ <entry>
+ <para>/rest/logout</para>
+ </entry>
+ <entry>Log outs</entry>
+ <entry>Log outs user</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ <entry>Not implemented yet</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <para>Rest URL are hierarchical. It is permitted to replace rest URL elements with an "asterisks" in GET requests to denote
+ all object of a particular type. Additionally, trailing object type in the URL hierarchy can be omitted.
+ In this case GET request will return all of the object underneath of the current object.</para>
+ <para>For example, for binding URL http://localhost:8080/rest/binding/&lt;vhost&gt;/&lt;exchange&gt;/&lt;queue&gt;/&lt;binding&gt;
+ replacing of <emphasis>&lt;exchange&gt;</emphasis> with "asterisks" (http://localhost:8080/rest/binding/&lt;vhost&gt;/*/&lt;queue&gt;/&lt;binding&gt;)
+ will result in the GET response containing the list of bindings for all of the exchanges in the virtual host having the given name and given queue.
+ If <emphasis>&lt;binding&gt;</emphasis> and <emphasis>&lt;queue&gt;</emphasis> are omitted in binding REST URL
+ (http://localhost:8080/rest/binding/&lt;vhostname&gt;/&lt;exchangename&gt;) the GET request will result in returning
+ all bindings for all queues for the given exchange in the virtual host.
+ </para>
+ <example>
+ <title>Examples of queue creation using curl:</title>
+ <programlisting><![CDATA[
+#create a durable queue
+curl -X PUT -d '{"durable":true}' http://localhost:8080/rest/queue/<vhostname>/<queuename>
+#create a durable priority queue
+curl -X PUT -d '{"durable":true,"type":"priority"}' http://localhost:8080/rest/queue/<vhostname>/<queuename>
+ ]]></programlisting>
+ </example><example>
+ <title>Example of binding a queue to an exchange using curl</title>
+ <programlisting><![CDATA[
+curl -X PUT -d '{}' http://localhost:8080/rest/binding/<vhostname>/<exchangename>/<queue-name>/<binding-name>
+ ]]></programlisting>
+ </example>
+ <para>Qpid broker web management console calls rest interfaces internally to manage the broker.</para>
+ </section>
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Web-Console.xml b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Web-Console.xml
new file mode 100644
index 0000000000..406f2fbe08
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing-Web-Console.xml
@@ -0,0 +1,35 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Configuring-And-Managing-Web-Console">
+ <title>Web Console</title>
+ <para>If web management is enabled (see <xref linkend="Java-Broker-Configuring-And-Managing-Config-Files-Web-Management"/>) the web management console can be accessed from web browser using URL http(s)://&lt;hostname&gt;:&lt;port&gt;/management, where</para>
+ <itemizedlist>
+ <listitem><para><emphasis>hostname</emphasis> is the broker host</para></listitem>
+ <listitem><para><emphasis>port</emphasis> is the broker port(either http or https)</para></listitem>
+ </itemizedlist>
+ <para>The page like following is displayed on navigation to the management URL.</para>
+ <figure>
+ <title>Web management Console</title>
+ <graphic fileref="images/Management-Web-Console.png"/>
+ </figure>
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing.xml b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing.xml
new file mode 100644
index 0000000000..d0858a80c0
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Configuring-And-Managing.xml
@@ -0,0 +1,30 @@
+<?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.
+
+-->
+
+<chapter id="Java-Broker-Configuring-And-Managing">
+ <title>Configuring And Managing</title>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Configuring-And-Managing-Config-Files.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Configuring-And-Managing-Web-Console.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Configuring-And-Managing-REST-API.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Configuring-And-Managing-JMX.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Configuring-And-Managing-Other-Tooling.xml"/>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Exchanges-Binding-Arguments.xml b/doc/book/src/java-broker/Java-Broker-Exchanges-Binding-Arguments.xml
new file mode 100644
index 0000000000..06c5ee7336
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Exchanges-Binding-Arguments.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="">
+<title></title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Exchanges.xml b/doc/book/src/java-broker/Java-Broker-Exchanges.xml
new file mode 100644
index 0000000000..f6272fb0f3
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Exchanges.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<chapter id="Java-Broker-Exchanges">
+ <title>Exchanges</title>
+
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Feature-Guide.xml b/doc/book/src/java-broker/Java-Broker-Feature-Guide.xml
deleted file mode 100644
index bbc2a1aaf0..0000000000
--- a/doc/book/src/java-broker/Java-Broker-Feature-Guide.xml
+++ /dev/null
@@ -1,84 +0,0 @@
-<?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.
-
--->
-
-<section>
- <title>
- Java Broker Feature Guide
- </title>
- <section role="h3" id="JavaBrokerFeatureGuide-TheQpidpureJavabrokercurrentlysupportsthefollowingfeatures-3A">
- <title>
- The Qpid pure Java broker currently supports the following
- features:
- </title>
- <itemizedlist>
- <listitem><para>All features required by the Sun JMS 1.1 specification, fully
- tested
- </para></listitem>
- <listitem><para>Transaction support
- </para></listitem>
- <listitem><para>Persistence using a pluggable layer
- </para></listitem>
- <listitem><para>Pluggable security using SASL
- </para></listitem>
- <listitem><para>Management using JMX and an Eclipse Management Console
- application
- </para></listitem>
- <listitem><para>High performance header-based routing for messages
- </para></listitem>
- <listitem><para>Message Priorities
- </para></listitem>
- <listitem><para>Configurable logging and log archiving
- </para></listitem>
- <listitem><para>Threshold alerting
- </para></listitem>
- <listitem><para>ACLs
- </para></listitem>
- <listitem><para>Extensively tested on each release, including performance
- &amp; reliability testing
- </para></listitem>
- <listitem><para>Automatic client failover using configurable connection
- properties
- </para></listitem>
- <listitem><para>Durable Queues/Subscriptions
- </para></listitem>
- </itemizedlist>
- <section role="h3" id="JavaBrokerFeatureGuide-Upcomingfeatures-3A">
- <title>
- Upcoming
- features:
- </title>
- <itemizedlist>
- <listitem><para>Flow To Disk
- </para></listitem>
- <listitem><para>IP Whitelist
- </para></listitem>
- <listitem><para>AMQP 0-10 Support (for interoperability)
- </para></listitem>
- </itemizedlist>
-
- <!--h3-->
- </section>
-
- <!--h3-->
- </section>
-
-</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Getting-Started.xml b/doc/book/src/java-broker/Java-Broker-Getting-Started.xml
new file mode 100644
index 0000000000..630c27ce89
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Getting-Started.xml
@@ -0,0 +1,140 @@
+<?xml version="1.0"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<chapter id="Java-Broker-Getting-Started">
+ <title>Getting Started</title>
+ <para>This section describes how to start the Java Broker for the first time.</para>
+ <section role="h2" id="Java-Broker-Getting-Started-Starting">
+ <title>Starting/Stopping the Broker</title>
+ <para>To start the Broker, use the <command>qpid-server</command> script (UNIX) or <command>qpid-server.bat</command> (Windows)
+ provided within distribution.</para>
+ </section>
+ <section role="h2" id="Java-Broker-Getting-Started-Starting-Stopping-Windows">
+ <title>Starting/Stopping on Windows</title>
+ <para>Firstly change to the installation directory used during the <link linkend="Java-Broker-Installation-InstallationWindows">installation</link>
+ and ensure that the <link linkend="Java-Broker-Installation-InstallationWindows-SettingQPIDWORK">QPID_WORK environment variable is set</link>.</para>
+ <para>Now use the <command>qpid-server.bat</command> to start the server</para>
+ <programlisting><![CDATA[bin\qpid-server.bat]]></programlisting>
+ <para>Output similar to the following will be seen:</para>
+ <screen>[Broker] BRK-1006 : Using configuration : C:\qpid\qpid-broker-&qpidCurrentRelease;\etc\config.xml
+[Broker] BRK-1007 : Using logging configuration : C:\qpid\qpid-broker-&qpidCurrentRelease;\etc\log4j.xml
+[Broker] BRK-1001 : Startup : Version: &qpidCurrentRelease; Build: 1411386
+[Broker] BRK-1010 : Platform : JVM : Sun Microsystems Inc. version: 1.6.0_24-b07 OS : Windows 7 version: 6.1 arch: amd64
+[Broker] BRK-1011 : Maximum Memory : 1,069,416,448 bytes
+[Broker] MNG-1001 : Web Management Startup
+[Broker] MNG-1002 : Starting : HTTP : Listening on port 8080
+[Broker] MNG-1004 : Web Management Ready
+[Broker] MNG-1001 : JMX Management Startup
+[Broker] MNG-1002 : Starting : RMI Registry : Listening on port 8999
+[Broker] MNG-1002 : Starting : JMX RMIConnectorServer : Listening on port 9099
+[Broker] MNG-1004 : JMX Management Ready
+[Broker] BRK-1002 : Starting : Listening on TCP port 5672
+[Broker] BRK-1004 : Qpid Broker Ready</screen>
+ <para>The BRK-1004 message confirms that the Broker is ready for work. The MNG-1002 and BRK-1002 confirm the ports to
+ which the Broker is listening (for HTTP/JMX management and AMQP respectively).</para>
+ <para>To stop the Broker, use Control-C or use the Shutdown MBean made from the <xref
+ linkend="Java-Broker-Configuring-And-Managing-JMX"/></para>
+ </section>
+ <section role="h2" id="Java-Broker-Getting-Started-Starting-Stopping-Unix">
+ <title>Starting/Stopping on Unix</title>
+ <para>Firstly change to the installation directory used during the <link linkend="Java-Broker-Installation-InstallationUnix">installation</link>
+ and ensure that the <link linkend="Java-Broker-Installation-InstallationUnix-SettingQPIDWORK">QPID_WORK environment variable is set</link>.</para>
+ <para>Now use the <command>qpid-server</command> script to start the server:</para>
+ <programlisting><![CDATA[bin\qpid-server]]></programlisting>
+ <para>Output similar to the following will be seen:</para>
+ <screen>[Broker] BRK-1006 : Using configuration : /usr/local/qpid/qpid-broker-&qpidCurrentRelease;/etc/config.xml
+[Broker] BRK-1007 : Using logging configuration : /usr/local/qpid/qpid-broker-&qpidCurrentRelease;/etc/log4j.xml
+[Broker] BRK-1001 : Startup : Version: &qpidCurrentRelease; Build: 1411386
+[Broker] BRK-1010 : Platform : JVM : Apple Inc. version: 1.6.0_35-b10-428-11M3811 OS : Mac OS X version: 10.8.2 arch: x86_64
+[Broker] BRK-1011 : Maximum Memory : 1,070,399,488 bytes
+[Broker] MNG-1001 : Web Management Startup
+[Broker] MNG-1002 : Starting : HTTP : Listening on port 8080
+[Broker] MNG-1004 : Web Management Ready
+[Broker] MNG-1001 : JMX Management Startup
+[Broker] MNG-1002 : Starting : RMI Registry : Listening on port 8999
+[Broker] MNG-1002 : Starting : JMX RMIConnectorServer : Listening on port 9099
+[Broker] MNG-1004 : JMX Management Ready
+[Broker] BRK-1002 : Starting : Listening on TCP port 5672
+[Broker] BRK-1004 : Qpid Broker Ready</screen>
+ <para>The BRK-1004 message confirms that the Broker is ready for work. The MNG-1002 and BRK-1002 confirm the ports to
+ which the Broker is listening (for HTTP/JMX management and AMQP respectively).</para>
+ <para>To stop the Broker, use Control-C from the controlling shell, use the
+ <command>bin/qpid.stop</command> script, or use <command>kill -TERM &lt;pid&gt;</command> or
+ the Shutdown MBean from <xref linkend="Java-Broker-Configuring-And-Managing-JMX"/></para>
+ </section>
+ <section role="h2" id="Java-Broker-Getting-Started-LogFile">
+ <title>Log file</title>
+ <para>The Java Broker writes a log file to record both details of its normal operation and any exceptional
+ conditions. By default the log file is written within the log subdirectory beneath the work directory
+ - <computeroutput>$QPID_WORK/log/qpid.log</computeroutput> (UNIX) and
+ <computeroutput>%QPID_WORK%\log\qpid.log</computeroutput> (Windows).</para>
+ <para>For details of how to control the logging, see <xref linkend="Java-Broker-Runtime-Log-Files"/></para>
+ </section>
+ <section role="h2" id="Java-Broker-Getting-Started-CommandLine">
+ <title>Using the command line</title>
+ <para>The Java Broker understands a number of command line options which may be used to override the configuration.</para>
+ <para>To see usage information for all command line options, use the option <option>--help</option></para>
+ <programlisting><![CDATA[bin/qpid-server --help]]></programlisting>
+ <screen><![CDATA[usage: Qpid [-b address>] [-c <file>] [--exclude-0-10 <port>] [--exclude-0-8 <port>] [--exclude-0-9 <port>] [--exclude-0-9-1
+ <port>] [--exclude-1-0 <port>] [-h] [--include-0-10 <port>] [--include-0-8 <port>] [--include-0-9 <port>] [--include-0-9-1
+ <port>] [--include-1-0 <port>] [--jmxconnectorport <port>] [-l <file>] [-m <port>] [-p <port>] [-s <port>] [-v] [-w <period>]
+ -b,--bind <address> bind to the specified address. Overrides any value in the config file
+ -c,--config <file> use given configuration file
+ --exclude-0-10 <port> when listening on the specified port do not accept AMQP0-10 connections. The
+ specified port must be one specified on the command line
+ --exclude-0-8 <port> when listening on the specified port do not accept AMQP0-8 connections. The
+ specified port must be one specified on the command line
+ --exclude-0-9 <port> when listening on the specified port do not accept AMQP0-9 connections. The
+ specified port must be one specified on the command line
+ --exclude-0-9-1 <port> when listening on the specified port do not accept AMQP0-9-1 connections. The
+ specified port must be one specified on the command line
+ --exclude-1-0 <port> when listening on the specified port do not accept AMQP1-0 connections. The
+ specified port must be one specified on the command line
+ -h,--help print this message
+ --include-0-10 <port> accept AMQP0-10 connections on this port, overriding configuration to the contrary.
+ The specified port must be one specified on the command line
+ --include-0-8 <port> accept AMQP0-8 connections on this port, overriding configuration to the contrary.
+ The specified port must be one specified on the command line
+ --include-0-9 <port> accept AMQP0-9 connections on this port, overriding configuration to the contrary.
+ The specified port must be one specified on the command line
+ --include-0-9-1 <port> accept AMQP0-9-1 connections on this port, overriding configuration to the contrary.
+ The specified port must be one specified on the command line
+ --include-1-0 <port> accept AMQP1-0 connections on this port, overriding configuration to the contrary.
+ The specified port must be one specified on the command line
+ --jmxconnectorport <port> listen on the specified management (connector server) port. Overrides any
+ value in the config file
+ -l,--logconfig <file> use the specified log4j xml configuration file. By default looks for a file named
+ etc/log4j.xml in the same directory as the configuration file
+ -m,--jmxregistryport <port> listen on the specified management (registry server) port. Overrides any
+ value in the config file
+ -p,--port <port> listen on the specified port. Overrides any value in the config file
+ -s,--sslport <port> SSL port. Overrides any value in the config file
+ -v,--version print the version information and exit
+ -w,--logwatch <period> monitor the log file configuration file for changes. Units are seconds. Zero means
+ do not check for changes.]]></screen>
+ </section>
+
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-High-Availability.xml b/doc/book/src/java-broker/Java-Broker-High-Availability.xml
new file mode 100644
index 0000000000..7ea9dae38a
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-High-Availability.xml
@@ -0,0 +1,1005 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+<chapter id="Java-Broker-High-Availability">
+ <title>High Availability</title>
+
+ <section role="h3" id="Java-Broker-High-Availability-GeneralIntroduction">
+ <title>General Introduction</title>
+ <para>The term High Availability (HA) usually refers to having a number of instances of a service such as a Message Broker
+ available so that should a service unexpectedly fail, or requires to be shutdown for maintenance, users may quickly connect
+ to another instance and continue their work with minimal interuption. HA is one way to make a overall system more resilient
+ by eliminating a single point of failure from a system.</para>
+ <para>HA offerings are usually categorised as <emphasis role="bold">Active/Active</emphasis> or <emphasis role="bold">Active/Passive</emphasis>.
+ An Active/Active system is one where all nodes within the cluster are usuaully available for use by clients all of the time. In an
+ Active/Passive system, one only node within the cluster is available for use by clients at any one time, whilst the others are in
+ some kind of standby state, awaiting to quickly step-in in the event the active node becomes unavailable.
+ </para>
+ </section>
+
+ <section role="h3" id="Java-Broker-High-Availability-OfferingsOfJavaBroker">
+ <title>HA offerings of the Java Broker</title>
+ <para>The Java Broker's HA offering became available at release <emphasis role="bold">0.18</emphasis>. HA is provided by way of the HA
+ features built into the <ulink url="&oracleBdbProductOverviewUrl;">Java Edition of the Berkley Database (BDB JE)</ulink> and as such
+ is currently only available to Java Broker users who use the optional BDB JE based persistence store. This
+ <emphasis role="bold">optional</emphasis> store requires the use of BDB JE which is licensed under the Sleepycat Licence, which is
+ not compatible with the Apache Licence and thus BDB JE is not distributed with Qpid. Users who elect to use this optional store for
+ the broker have to provide this dependency.</para>
+ <para>HA in the Java Broker provides an <emphasis role="bold">Active/Passive</emphasis> mode of operation with Virtual hosts being
+ the unit of replication. The Active node (referred to as the <emphasis role="bold">Master</emphasis>) accepts all work from all the clients.
+ The Passive nodes (referred to as <emphasis role="bold">Replicas</emphasis>) are unavailable for work: the only task they must perform is
+ to remain in synch with the Master node by consuming a replication stream containing all data and state.</para>
+ <para>If the Master node fails, a Replica node is elected to become the new Master node. All clients automatically failover
+ <footnote><para>The automatic failover feature is available only for AMQP connections from the Java client. Management connections (JMX)
+ do not current offer this feature.</para></footnote> to the new Master and continue their work.</para>
+ <para>The Java Broker HA solution is incompatible with the HA solution offered by the CPP Broker. It is not possible to co-locate Java and CPP
+ Brokers within the same cluster.</para>
+ <para>HA is not currently available for those using the the <emphasis role="bold">Derby Store</emphasis> or <emphasis role="bold">Memory
+ Message Store</emphasis>.</para>
+ </section>
+
+ <section role="h3" id="Java-Broker-High-Availability-TwoNodeCluster">
+ <title>Two Node Cluster</title>
+ <section role="h4">
+ <title>Overview</title>
+ <para>In this HA solution, a cluster is formed with two nodes. one node serves as
+ <emphasis role="bold">master</emphasis> and the other is a <emphasis role="bold">replica</emphasis>.
+ </para>
+ <para>All data and state required for the operation of the virtual host is automatically sent from the
+ master to the replica. This is called the replication stream. The master virtual host confirms each
+ message is on the replica before the client transaction completes. The exact way the client awaits
+ for the master and replica is gorverned by the <link linkend="Java-Broker-High-Availability-DurabilityGuarantee">durability</link>
+ configuration, which is discussed later. In this way, the replica remains ready to take over the
+ role of the master if the master becomes unavailable.
+ </para>
+ <para>It is important to note that there is an inherent limitation of two node clusters is that
+ the replica node cannot make itself master automatically in the event of master failure. This
+ is because the replica has no way to distinguish between a network partition (with potentially
+ the master still alive on the other side of the partition) and the case of genuine master failure.
+ (If the replica were to elect itself as master, the cluster would run the risk of a
+ <ulink url="http://en.wikipedia.org/wiki/Split-brain_(computing)">split-brain</ulink> scenario).
+ In the event of a master failure, a third party must designate the replica as primary. This process
+ is described in more detail later.
+ </para>
+ <para>Clients connect to the cluster using a <link linkend="Java-Broker-High-Availability-ClientFailover">failover url</link>.
+ This allows the client to maintain a connection to the master in a way that is transparent
+ to the client application.</para>
+ </section>
+ <section role="h4">
+ <title>Depictions of cluster operation</title>
+ <para>In this section, the operation of the cluster is depicted through a series of figures
+ supported by explanatory text.</para>
+ <figure>
+ <title>Key for figures</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/HA-2N-Key.png" format="PNG" scalefit="1"/>
+ </imageobject>
+ <textobject>
+ <phrase>Key to figures</phrase>
+ </textobject>
+ </mediaobject>
+ </figure>
+ <section role="h5" id="Java-Broker-High-Availability-TwoNodeNormalOperation">
+ <title>Normal Operation</title>
+ <para>The figure below illustrates normal operation. Clients connecting to the cluster by way
+ of the failover URL achieve a connection to the master. As clients perform work (message
+ production, consumption, queue creation etc), the master additionally sends this data to the
+ replica over the network.</para>
+ <figure>
+ <title>Normal operation of a two-node cluster</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/HA-2N-Normal.png" format="PNG" scalefit="1"/>
+ </imageobject>
+ <textobject>
+ <phrase>Normal operation</phrase>
+ </textobject>
+ </mediaobject>
+ </figure>
+ </section>
+ <section role="h5" id="Java-Broker-High-Availability-TwoNodeMasterFailure">
+ <title>Master Failure and Recovery</title>
+ <para>The figure below illustrates a sequence of events whereby the master suffers a failure
+ and the replica is made the master to allow the clients to continue to work. Later the
+ old master is repaired and comes back on-line in replica role.</para>
+ <para>The item numbers in this list apply to the numbered boxes in the figure below.</para>
+ <orderedlist>
+ <listitem>
+ <para>System operating normally</para>
+ </listitem>
+ <listitem>
+ <para>Master suffers a failure and disconnects all clients. Replica realises that it is no
+ longer in contact with master. Clients begin to try to reconnect to the cluster, although these
+ connection attempts will fail at this point.</para>
+ </listitem>
+ <listitem>
+ <para>A third-party (an operator, a script or a combination of the two) verifies that the master has truely
+ failed <emphasis role="bold">and is no longer running</emphasis>. If it has truely failed, the decision is made
+ to designate the replica as primary, allowing it to assume the role of master despite the other node being down.
+ This primary designation is performed using <link linkend="Java-Broker-High-Availability-JMXAPI">JMX</link>.</para>
+ </listitem>
+ <listitem>
+ <para>Client connections to the new master succeed and the <emphasis role="bold">service is restored
+ </emphasis>, albeit without a replica.</para>
+ </listitem>
+ <listitem>
+ <para>The old master is repaired and brought back on-line. It automatically rejoins the cluster
+ in the <emphasis role="bold">replica</emphasis> role.</para>
+ </listitem>
+ </orderedlist>
+ <figure>
+ <title>Failure of master and recovery sequence</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/HA-2N-MasterFail.png" format="PNG" scalefit="1"/>
+ </imageobject>
+ <textobject>
+ <phrase>Failure of master and subsequent recovery sequence</phrase>
+ </textobject>
+ </mediaobject>
+ </figure>
+ </section>
+ <section role="h5" id="Java-Broker-High-Availability-TwoNodeReplicaFailure">
+ <title>Replica Failure and Recovery</title>
+ <para>The figure that follows illustrates a sequence of events whereby the replica suffers a failure
+ leaving the master to continue processing alone. Later the replica is repaired and is restarted.
+ It rejoins the cluster so that it is once again ready to take over in the event of master failure.</para>
+ <para>The behavior of the replica failure case is governed by the <varname>designatedPrimary</varname>
+ configuration item. If set true on the master, the master will continue to operate solo without outside
+ intervention when the replica fails. If false, a third-party must designate the master as primary in order
+ for it to continue solo.</para>
+ <para>The item numbers in this list apply to the numbered boxes in the figure below. This example assumes
+ that <varname>designatedPrimary</varname> is true on the original master node.</para>
+ <orderedlist>
+ <listitem>
+ <para>System operating normally</para>
+ </listitem>
+ <listitem>
+ <para>Replica suffers a failure. Master realises that replica longer in contact but as
+ <varname>designatedPrimary</varname> is true, master continues processing solo and thus client
+ connections are uninterrupted by the loss of the replica. System continues operating normally, albeit
+ with a single node.</para>
+ </listitem>
+ <listitem>
+ <para>Replica is repaired.</para>
+ </listitem>
+ <listitem>
+ <para>After catching up with missed work, replica is once again ready to take over in the event of master failure.</para>
+ </listitem>
+ </orderedlist>
+ <figure>
+ <title>Failure of replica and subsequent recovery sequence</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/HA-2N-ReplicaFail.png" format="PNG" scalefit="1"/>
+ </imageobject>
+ <textobject>
+ <phrase>Failure of replica and subsequent recovery sequence</phrase>
+ </textobject>
+ </mediaobject>
+ </figure>
+ </section>
+ <section role="h5" id="Java-Broker-High-Availability-TwoNodeNetworkPartition">
+ <title>Network Partition and Recovery</title>
+ <para>The figure below illustrates the sequence of events that would occur if the network between
+ master and replica were to suffer a partition, and the nodes were out of contact with one and other.</para>
+ <para>As with <link linkend="Java-Broker-High-Availability-TwoNodeReplicaFailure">Replica Failure and Recovery</link>, the
+ behaviour is governed by the <varname>designatedPrimary</varname>.
+ Only if <varname>designatedPrimary</varname> is true on the master, will the master continue solo.</para>
+ <para>The item numbers in this list apply to the numbered boxes in the figure below. This example assumes
+ that <varname>designatedPrimary</varname> is true on the original master node.</para>
+ <orderedlist>
+ <listitem>
+ <para>System operating normally</para>
+ </listitem>
+ <listitem>
+ <para>Network suffers a failure. Master realises that replica longer in contact but as
+ <varname>designatedPrimary</varname> is true, master continues processing solo and thus client
+ connections are uninterrupted by the network partition between master and replica.</para>
+ </listitem>
+ <listitem>
+ <para>Network is repaired.</para>
+ </listitem>
+ <listitem>
+ <para>After catching up with missed work, replica is once again ready to take over in the event of master failure.
+ System operating normally again.</para>
+ </listitem>
+ </orderedlist>
+ <figure>
+ <title>Partition of the network separating master and replica</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/HA-2N-NetworkPartition.png" format="PNG" scalefit="1"/>
+ </imageobject>
+ <textobject>
+ <phrase>Network Partition and Recovery</phrase>
+ </textobject>
+ </mediaobject>
+ </figure>
+ </section>
+ <section role="h5" id="Java-Broker-High-Availability-TwoNodeSplitBrain">
+ <title>Split Brain</title>
+ <para>A <ulink url="http://en.wikipedia.org/wiki/Split-brain_(computing)">split-brain</ulink>
+ is a situation where the two node cluster has two masters. BDB normally strives to prevent
+ this situation arising by preventing two nodes in a cluster being master at the same time.
+ However, if the network suffers a partition, and the third-party intervenes incorrectly
+ and makes the replica a second master a split-brain will be formed and both masters will
+ proceed to perform work <emphasis role="bold">independently</emphasis> of one and other.</para>
+ <para>There is no automatic recovery from a split-brain.</para>
+ <para>Manual intervention will be required to choose which store will be retained as master
+ and which will be discarded. Manual intervention will be required to identify and repeat the
+ lost business transactions.</para>
+ <para>The item numbers in this list apply to the numbered boxes in the figure below.</para>
+ <orderedlist>
+ <listitem>
+ <para>System operating normally</para>
+ </listitem>
+ <listitem>
+ <para>Network suffers a failure. Master realises that replica longer in contact but as
+ <varname>designatedPrimary</varname> is true, master continues processing solo. Client
+ connections are uninterrupted by the network partition.</para>
+ <para>A third-party <emphasis role="bold">erroneously</emphasis> designates the replica as primary while the
+ original master continues running (now solo).</para>
+ </listitem>
+ <listitem>
+ <para>As the nodes cannot see one and other, both behave as masters. Clients may perform work against
+ both master nodes.</para>
+ </listitem>
+ </orderedlist>
+ <figure>
+ <title>Split Brain</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/HA-2N-SplitBrain.png" format="PNG" scalefit="1"/>
+ </imageobject>
+ <textobject>
+ <phrase>Split Brain</phrase>
+ </textobject>
+ </mediaobject>
+ </figure>
+ </section>
+ </section>
+ </section>
+
+ <section role="h3" id="Java-Broker-High-Availability-MultiNodeCluster">
+ <title>Multi Node Cluster</title>
+ <para>Multi node clusters, that is clusters where the number of nodes is three or more, are not yet
+ ready for use.</para>
+ </section>
+
+ <section role="h3" id="Java-Broker-High-Availability-Configuration">
+ <title>Configuring a Virtual Host to be a node</title>
+ <para>To configure a virtualhost as a cluster node, configure the virtualhost.xml in the following manner:</para>
+ <para>
+
+ <example>
+ <title>Configuring a VirtualHost to use the BDBHAMessageStore</title>
+ <programlisting language="xml"><![CDATA[
+<virtualhost>
+ <name>myhost</name>
+ <myvhost>
+ <store>
+ <class>org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore</class>
+ <environment-path>${work}/bdbhastore</environment-path>
+ <highAvailability>
+ <groupName>myclustername</groupName>
+ <nodeName>mynode1</nodeName>
+ <nodeHostPort>node1host:port</nodeHostPort>
+ <helperHostPort>node1host:port</helperHostPort>
+ <durability>NO_SYNC\,NO_SYNC\,SIMPLE_MAJORITY</durability>
+ <coalescingSync>true|false</coalescingSync>
+ <designatedPrimary>true|false</designatedPrimary>
+ </highAvailability>
+ </store>
+ ...
+ </myvhost>
+</virtualhost>]]></programlisting>
+ </example>
+ </para>
+ <para>The <varname>groupName</varname> is the name of logical name of the cluster. All nodes within the
+ cluster must use the same <varname>groupName</varname> in order to be considered part of the cluster.</para>
+ <para>The <varname>nodeName</varname> is the logical name of the node. All nodes within the cluster must have a
+ unique name. It is recommended that the node name should be chosen from a different nomenclature from that of
+ the servers on which they are hosted, in case the need arises to move node to a new server in the future.</para>
+ <para>The <varname>nodeHostPort</varname> is the hostname and port number used by this node to communicate with the
+ the other nodes in the cluster. For the hostname, an IP address, hostname or fully qualified hostname may be used.
+ For the port number, any free port can be used. It is important that this address is stable over time, as BDB
+ records and uses this address internally.</para>
+ <para>The <varname>helperHostPort</varname> is the hostname and port number that new nodes use to discover other
+ nodes within the cluster when they are newly introduced to the cluster. When configuring the first node, set the
+ <varname>helperHostPort</varname> to its own <varname>nodeHostPort</varname>. For the second and subsequent nodes,
+ set their <varname>helperHostPort</varname> to that of the first node.</para>
+ <para><varname>durability</varname> controls the <link linkend="Java-Broker-High-Availability-DurabilityGuarantee">durability</link>
+ guarantees made by the cluster. It is important that all nodes use the same value for this property. The default value is
+ NO_SYNC\,NO_SYNC\,SIMPLE_MAJORITY. Owing to the internal use of Apache Commons Config, it is currently necessary
+ to escape the commas within the durability string.</para>
+ <para><varname>coalescingSync</varname> controls the <link linkend="Java-Broker-High-Availability-DurabilityGuarantee_CoalescingSync">coalescing-sync</link>
+ mode of Qpid. It is important that all nodes use the same value. If omitted, it defaults to true.</para>
+ <para>The <varname>designatedPrimary</varname> is applicable only to the <link linkend="Java-Broker-High-Availability-TwoNodeCluster">two-node
+ case.</link> It governs the behaviour of a node when the other node fails or becomes uncontactable. If true,
+ the node will be designated as primary at startup and will be able to continue operating as a single node master.
+ If false, the node will transition to an unavailable state until a third-party manually designates the node as
+ primary or the other node is restored. It is suggested that the node that normally fulfils the role of master is
+ set true in config file and the node that is normally replica is set false. Be aware that setting both nodes to
+ true will lead to a failure to start up, as both cannot be designated at the point of contact. Designating both
+ nodes as primary at runtime (using the JMX interface) will lead to a <link linkend="Java-Broker-High-Availability-TwoNodeSplitBrain">split-brain</link>
+ in the case of network partition and must be avoided.</para>
+ <note><para>Usage of domain names in <varname>helperHostPort</varname> and <varname>nodeHostPort</varname> is more preferebale
+ over IP addresses due to the tendency of more frequent changes of the last over the former.
+ If server IP address changes but domain name remains the same the HA cluster can continue working as normal
+ in case when domain names are used in cluster configuration. In case when IP addresses are used and they are changed with the time
+ than Qpid <link linkend="Java-Broker-High-Availability-JMXAPI">JMX API for HA</link> can be used to change the addresses or remove the nodes from the cluster.</para></note>
+
+ <section role="h4" id="Java-Broker-High-Availability-Configuration_BDBEnvVars">
+ <title>Passing BDB environment and replication configuration options</title>
+ <para>It is possible to pass BDB <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/EnvironmentConfig.html">
+ environment</ulink> and <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/ReplicationConfig.html">
+ replication</ulink> configuration options from the virtualhost.xml. Environment configuration options are passed using
+ the <varname>envConfig</varname> element, and replication config using <varname>repConfig</varname>.</para>
+ <para>For example, to override the BDB environment configuration options <varname>je.cleaner.threads</varname> and
+ <varname>je.txn.timeout</varname></para>
+ <programlisting language="xml"><![CDATA[
+ ...
+ </highAvailability>
+ <envConfig>
+ <name>je.cleaner.threads</name>
+ <value>2</value>
+ </envConfig>
+ <envConfig>
+ <name>je.txn.timeout</name>
+ <value>15 min</value>
+ </envConfig>
+ ...
+ </store>]]></programlisting>
+ <para>And to override the BDB replication configuration options <varname>je.rep.electionsPrimaryRetries</varname>.</para>
+ <programlisting language="xml"><![CDATA[
+ ...
+ </highAvailability>
+ ...
+ <repConfig>
+ <name>je.rep.electionsPrimaryRetries</name>
+ <value>3</value>
+ </repConfig>
+ ...
+ </store>]]></programlisting>
+ </section>
+ </section>
+
+ <section role="h3" id="Java-Broker-High-Availability-DurabilityGuarantee">
+ <title>Durability Guarantees</title>
+ <para>The term <ulink url="http://en.wikipedia.org/wiki/ACID#Durability">durability</ulink> is used to mean that once a
+ transaction is committed, it remains committed regardless of subsequent failures. A highly durable system is one where
+ loss of a committed transaction is extermely unlikely, whereas with a less durable system loss of a transaction is likely
+ in a greater number of scenarios. Typically, the more highly durable a system the slower and more costly it will be.</para>
+ <para>Qpid exposes the all the
+ <ulink url="&oracleBdbRepGuideUrl;txn-management.html#durabilitycontrols">durability controls</ulink>
+ offered by by BDB JE JA and a Qpid specific optimisation called <emphasis role="bold">coalescing-sync</emphasis> which defaults
+ to enabled.</para>
+ <section role="h4" id="Java-Broker-High-Availability-DurabilityGuarantee_BDBControls">
+ <title>BDB Durability Controls</title>
+ <para>BDB expresses durability as a triplet with the following form:</para>
+ <programlisting><![CDATA[<master sync policy>,<replica sync policy>,<replica acknowledgement policy>]]></programlisting>
+ <para>The sync polices controls whether the thread performing the committing thread awaits the successful completion of the
+ write, or the write and sync before continuing. The master sync policy and replica sync policy need not be the same.</para>
+ <para>For master and replic sync policies, the available values are:
+ <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.SyncPolicy.html#SYNC">SYNC</ulink>,
+ <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.SyncPolicy.html#WRITE_NO_SYNC">WRITE_NO_SYNC</ulink>,
+ <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.SyncPolicy.html#NO_SYNC">NO_SYNC</ulink>. SYNC
+ is offers the highest durability whereas NO_SYNC the lowest.</para>
+ <para>Note: the combination of a master sync policy of SYNC and <link linkend="Java-Broker-High-Availability-DurabilityGuarantee_CoalescingSync">coalescing-sync</link>
+ true would result in poor performance with no corresponding increase in durability guarantee. It cannot not be used.</para>
+ <para>The acknowledgement policy defines whether when a master commits a transaction, it also awaits for the replica(s) to
+ commit the same transaction before continuing. For the two-node case, ALL and SIMPLE_MAJORITY are equal.</para>
+ <para>For acknowledgement policy, the available value are:
+ <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.ReplicaAckPolicy.html#ALL">ALL</ulink>,
+ <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.ReplicaAckPolicy.html#SIMPLE_MAJORITY">SIMPLE_MAJORITY</ulink>
+ <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/Durability.ReplicaAckPolicy.html#NONE">NONE</ulink>.</para>
+ </section>
+ <section role="h4" id="Java-Broker-High-Availability-DurabilityGuarantee_CoalescingSync">
+ <title>Coalescing-sync</title>
+ <para>If enabled (the default) Qpid works to reduce the number of separate
+ <ulink url="&oracleJdkDocUrl;java/io/FileDescriptor.html#sync()">file-system sync</ulink> operations
+ performed by the <emphasis role="bold">master</emphasis> on the underlying storage device thus improving performance. It does
+ this coalescing separate sync operations arising from the different client commits operations occuring at approximately the same time.
+ It does this in such a manner not to reduce the ACID guarantees of the system.</para>
+ <para>Coalescing-sync has no effect on the behaviour of the replicas.</para>
+ </section>
+ <section role="h4" id="Java-Broker-High-Availability-DurabilityGuarantee_Default">
+ <title>Default</title>
+ <para>The default durability guarantee is <constant>NO_SYNC, NO_SYNC, SIMPLE_MAJORITY</constant> with coalescing-sync enabled. The effect
+ of this combination is described in the table below. It offers a good compromise between durability guarantee and performance
+ with writes being guaranteed on the master and the additional guarantee that a majority of replicas have received the
+ transaction.</para>
+ </section>
+ <section role="h4" id="Java-Broker-High-Availability-DurabilityGuarantee_Examples">
+ <title>Examples</title>
+ <para>Here are some examples illustrating the effects of the durability and coalescing-sync settings.</para>
+ <para>
+ <table>
+ <title>Effect of different durability guarantees</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry/>
+ <entry>Durability</entry>
+ <entry>Coalescing-sync</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>1</entry>
+ <entry>NO_SYNC, NO_SYNC, SIMPLE_MAJORITY</entry>
+ <entry>true</entry>
+ <entry>Before the commit returns to the client, the transaction will be written/sync'd to the Master's disk (effect of
+ coalescing-sync) and a majority of the replica(s) will have acknowledged the <emphasis role="bold">receipt</emphasis>
+ of the transaction. The replicas will write and sync the transaction to their disk at a point in the future governed by
+ <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/ReplicationMutableConfig.html#LOG_FLUSH_TASK_INTERVAL">ReplicationMutableConfig#LOG_FLUSH_INTERVAL</ulink>.
+ </entry>
+ </row>
+ <row>
+ <entry>2</entry>
+ <entry>NO_SYNC, WRITE_NO_SYNC, SIMPLE_MAJORITY</entry>
+ <entry>true</entry>
+ <entry>Before the commit returns to the client, the transaction will be written/sync'd to the Master's disk (effect of
+ coalescing-sync and a majority of the replica(s) will have acknowledged the <emphasis role="bold">write</emphasis> of
+ the transaction to their disk. The replicas will sync the transaction to disk at a point in the future with an upper bound governed by
+ ReplicationMutableConfig#LOG_FLUSH_INTERVAL.</entry>
+ </row>
+ <row>
+ <entry>3</entry>
+ <entry>NO_SYNC, NO_SYNC, NONE</entry>
+ <entry>false</entry>
+ <entry>After the commit returns to the client, the transaction is neither guaranteed to be written to the disk of the master
+ nor received by any of the replicas. The master and replicas will write and sync the transaction to their disk at a point
+ in the future with an upper bound governed by ReplicationMutableConfig#LOG_FLUSH_INTERVAL. This offers the weakest durability guarantee.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </para>
+ </section>
+ </section>
+
+ <section id="Java-Broker-High-Availability-ClientFailover">
+ <title>Client failover configuration</title>
+ <para>The details about format of Qpid connection URLs can be found at section
+ <ulink url="../../Programming-In-Apache-Qpid/html/QpidJNDI.html">Connection URLs</ulink>
+ of book <ulink url="../../Programming-In-Apache-Qpid/html/">Programming In Apache Qpid</ulink>.</para>
+ <para>The failover policy option in the connection URL for the HA Cluster should be set to <emphasis>roundrobin</emphasis>.
+ The Master broker should be put into a first place in <emphasis>brokerlist</emphasis> URL option.
+ The recommended value for <emphasis>connectdelay</emphasis> option in broker URL should be set to
+ the value greater than 1000 milliseconds. If it is desired that clients re-connect automatically after a
+ master to replica failure, <varname>cyclecount</varname> should be tuned so that the retry period is longer than
+ the expected length of time to perform the failover.</para>
+ <example><title>Example of connection URL for the HA Cluster</title><![CDATA[
+amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672?connectdelay='2000'&retries='3';tcp://localhost:5671?connectdelay='2000'&retries='3';tcp://localhost:5673?connectdelay='2000'&retries='3''&failover='roundrobin?cyclecount='30''
+ ]]></example>
+ </section>
+
+
+ <section role="h3" id="Java-Broker-High-Availability-JMXAPI">
+ <title>Qpid JMX API for HA</title>
+ <para>Qpid exposes the BDB HA store information via its JMX interface and provides APIs to remove a Node from
+ the group, update a Node IP address, and assign a Node as the designated primary.</para>
+ <para>An instance of the <classname>BDBHAMessageStore</classname> MBean is instantiated by the broker for the each virtualhost using the HA store.</para>
+ <para>The reference to this MBean can be obtained via JMX API using an ObjectName like <emphasis>org.apache.qpid:type=BDBHAMessageStore,name=&quot;&lt;virtualhost name&gt;&quot;</emphasis>
+ where &lt;virtualhost name&gt; is the name of a specific virtualhost on the broker.</para>
+ <table border="1">
+ <title>Mbean <classname>BDBHAMessageStore</classname> attributes</title>
+ <thead>
+ <tr>
+ <td>Name</td>
+ <td>Type</td>
+ <td>Accessibility</td>
+ <td>Description</td>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>GroupName</td>
+ <td>String</td>
+ <td>Read only</td>
+ <td>Name identifying the group</td>
+ </tr>
+ <tr>
+ <td>NodeName</td>
+ <td>String</td>
+ <td>Read only</td>
+ <td>Unique name identifying the node within the group</td>
+ </tr>
+ <tr>
+ <td>NodeHostPort</td>
+ <td>String</td>
+ <td>Read only</td>
+ <td>Host/port used to replicate data between this node and others in the group</td>
+ </tr>
+ <tr>
+ <td>HelperHostPort</td>
+ <td>String</td>
+ <td>Read only</td>
+ <td>Host/port used to allow a new node to discover other group members</td>
+ </tr>
+ <tr>
+ <td>NodeState</td>
+ <td>String</td>
+ <td>Read only</td>
+ <td>Current state of the node</td>
+ </tr>
+ <tr>
+ <td>ReplicationPolicy</td>
+ <td>String</td>
+ <td>Read only</td>
+ <td>Node replication durability</td>
+ </tr>
+ <tr id="JMXDesignatedPrimary">
+ <td>DesignatedPrimary</td>
+ <td>boolean</td>
+ <td>Read/Write</td>
+ <td>Designated primary flag. Applicable to the two node case.</td>
+ </tr>
+ <tr>
+ <td>CoalescingSync</td>
+ <td>boolean</td>
+ <td>Read only</td>
+ <td>Coalescing sync flag. Applicable to the master sync policies NO_SYNC and WRITE_NO_SYNC only.</td>
+ </tr>
+ <tr>
+ <td>getAllNodesInGroup</td>
+ <td>TabularData</td>
+ <td>Read only</td>
+ <td>Get all nodes within the group, regardless of whether currently attached or not</td>
+ </tr>
+ </tbody>
+ </table>
+
+ <table border="1">
+ <title>Mbean <classname>BDBHAMessageStore</classname> operations</title>
+ <thead>
+ <tr>
+ <td>Operation</td>
+ <td>Parameters</td>
+ <td>Returns</td>
+ <td>Description</td>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>removeNodeFromGroup</td>
+ <td>
+ <para><emphasis>nodeName</emphasis>, name of node, string</para>
+ </td>
+ <td>void</td>
+ <td>Remove an existing node from the group</td>
+ </tr>
+ <tr>
+ <td>updateAddress</td>
+ <td>
+ <itemizedlist>
+ <listitem>
+ <para><emphasis>nodeName</emphasis>, name of node, string</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>newHostName</emphasis>, new host name, string</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>newPort</emphasis>, new port number, int</para>
+ </listitem>
+ </itemizedlist>
+ </td>
+ <td>void</td>
+ <td>Update the address of another node. The node must be in a STOPPED state.</td>
+ </tr>
+ </tbody>
+ </table>
+ <figure>
+ <title>BDBHAMessageStore view from jconsole.</title>
+ <graphic fileref="images/HA-BDBHAMessageStore-MBean-jconsole.png"/>
+ </figure>
+ <example>
+ <title>Example of java code to get the node state value</title>
+ <programlisting language="java"><![CDATA[
+Map<String, Object> environment = new HashMap<String, Object>();
+
+// credentials: user name and password
+environment.put(JMXConnector.CREDENTIALS, new String[] {"admin","admin"});
+JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9001/jmxrmi");
+JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
+MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
+
+ObjectName queueObjectName = new ObjectName("org.apache.qpid:type=BDBHAMessageStore,name=\"test\"");
+String state = (String)mbsc.getAttribute(queueObjectName, "NodeState");
+
+System.out.println("Node state:" + state);
+ ]]></programlisting>
+ <para>Example system output:</para>
+ <screen><![CDATA[Node state:MASTER]]></screen>
+ </example>
+ </section>
+
+ <section id="Java-Broker-High-Availability-Monitoring-cluster">
+ <title>Monitoring cluster</title>
+ <para>In order to discover potential issues with HA Cluster early, all nodes in the Cluster should be monitored on regular basis
+ using the following techniques:</para>
+ <itemizedlist>
+ <listitem>
+ <para>Broker log files scrapping for WARN or ERROR entries and operational log entries like:</para>
+ <itemizedlist>
+ <listitem>
+ <para><emphasis>MST-1007 :</emphasis> Store Passivated. It can indicate that Master virtual host has gone down.</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>MST-1006 :</emphasis> Recovery Complete. It can indicate that a former Replica virtual host is up and became the Master.</para>
+ </listitem>
+ </itemizedlist>
+ </listitem>
+ <listitem>
+ <para>Disk space usage and system load using system tools.</para>
+ </listitem>
+ <listitem>
+ <para>Berkeley HA node status using <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/util/DbPing.html"><classname>DbPing</classname></ulink> utility.</para>
+ <example><title>Using <classname>DbPing</classname> utility for monitoring HA nodes.</title><command>
+java -jar je-&oracleBdbProductVersion;.jar DbPing -groupName TestClusterGroup -nodeName Node-5001 -nodeHost localhost:5001 -socketTimeout 10000
+</command><screen>
+Current state of node: Node-5001 from group: TestClusterGroup
+ Current state: MASTER
+ Current master: Node-5001
+ Current JE version: &oracleBdbProductVersion;
+ Current log version: 8
+ Current transaction end (abort or commit) VLSN: 165
+ Current master transaction end (abort or commit) VLSN: 0
+ Current active feeders on node: 0
+ Current system load average: 0.35
+</screen></example>
+ <para>In the example above <classname>DbPing</classname> utility requested status of Cluster node with name
+ <emphasis>Node-5001</emphasis> from replication group <emphasis>TestClusterGroup</emphasis> running on host <emphasis>localhost:5001</emphasis>.
+ The state of the node was reported into a system output.
+ </para>
+ </listitem>
+ <listitem>
+ <para>Using Qpid broker JMX interfaces.</para>
+ <para>Mbean <classname>BDBHAMessageStore</classname> can be used to request the following node information:</para>
+ <itemizedlist>
+ <listitem>
+ <para><emphasis>NodeState</emphasis> indicates whether node is a Master or Replica.</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>Durability</emphasis> replication durability.</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>DesignatedPrimary</emphasis> indicates whether Master node is designated primary.</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>GroupName</emphasis> replication group name.</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>NodeName</emphasis> node name.</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>NodeHostPort</emphasis> node host and port.</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>HelperHostPort</emphasis> helper host and port.</para>
+ </listitem>
+ <listitem>
+ <para><emphasis>AllNodesInGroup</emphasis> lists of all nodes in the replication group including their names, hosts and ports.</para>
+ </listitem>
+ </itemizedlist>
+ <para>For more details about <classname>BDBHAMessageStore</classname> MBean please refer section <link linkend="Java-Broker-High-Availability-JMXAPI">Qpid JMX API for HA</link></para>
+ </listitem>
+ </itemizedlist>
+ </section>
+
+ <section id="Java-Broker-High-Availability-DiskSpace">
+ <title>Disk space requirements</title>
+ <para>Disk space is a critical resource for the HA Qpid broker.</para>
+ <para>In case when a Replica goes down (or falls behind the Master in 2 node cluster where the Master is designated primary)
+ and the Master continues running, the non-replicated store files are kept on the Masters disk for the period of time
+ as specified in <emphasis>je.rep.repStreamTimeout</emphasis> JE setting in order to replicate this data later
+ when the Replica is back. This setting is set to 1 hour by default by the broker. The setting can be overridden as described in
+ <xref linkend="Java-Broker-High-Availability-Configuration_BDBEnvVars"/>.</para>
+ <para>Depending from the application publishing/consuming rates and message sizes,
+ the disk space might become overfull during this period of time due to preserved logs.
+ Please, make sure to allocate enough space on your disk to avoid this from happening.
+ </para>
+ </section>
+
+ <section id="Java-Broker-High-Availability-Network-Requirements">
+ <title>Network Requirements</title>
+ <para>The HA Cluster performance depends on the network bandwidth, its use by existing traffic, and quality of service.</para>
+ <para>In order to achieve the best performance it is recommended to use a separate network infrastructure for the Qpid HA Nodes
+ which might include installation of dedicated network hardware on Broker hosts, assigning a higher priority to replication ports,
+ installing a cluster in a separate network not impacted by any other traffic.</para>
+ </section>
+
+ <section id="Java-Broker-High-Availability-Security">
+ <title>Security</title>
+ <para>At the moment Berkeley replication API supports only TCP/IP protocol to transfer replication data between Master and Replicas.</para>
+ <para>As result, the replicated data is unprotected and can be intercepted by anyone having access to the replication network.</para>
+ <para>Also, anyone who can access to this network can introduce a new node and therefore receive a copy of the data.</para>
+ <para>In order to reduce the security risks the entire HA cluster is recommended to run in a separate network protected from general access.</para>
+ </section>
+
+ <section id="Java-Broker-High-Availability-Backup">
+ <title>Backups</title>
+ <para>In order to protect the entire cluster from some cataclysms which might destroy all cluster nodes,
+ backups of the Master store should be taken on a regular basis.</para>
+ <para>Qpid Broker distribution includes the "hot" backup utility <emphasis>backup.sh</emphasis> which can be found at broker bin folder.
+ This utility can perform the backup when broker is running.</para>
+ <para><emphasis>backup.sh</emphasis> script invokes <classname>org.apache.qpid.server.store.berkeleydb.BDBBackup</classname> to do the job.</para>
+ <para>You can also run this class from command line like in an example below:</para>
+ <example><title>Performing store backup by using <classname>BDBBackup</classname> class directly</title><command>
+ java -cp qpid-bdbstore-0.18.jar org.apache.qpid.server.store.berkeleydb.BDBBackup -fromdir path/to/store/folder -todir path/to/backup/foldeAr</command>
+ </example>
+ <para>In the example above BDBBackup utility is called from qpid-bdbstore-0.18.jar to backup the store at <emphasis>path/to/store/folder</emphasis> and copy store logs into <emphasis>path/to/backup/folder</emphasis>.</para>
+ <para>Linux and Unix users can take advantage of <emphasis>backup.sh</emphasis> bash script by running this script in a similar way.</para>
+ <example><title>Performing store backup by using <classname>backup.sh</classname> bash script</title>
+ <command>backup.sh -fromdir path/to/store/folder -todir path/to/backup/folder</command>
+ </example>
+ <note>
+ <para>Do not forget to ensure that the Master store is being backed up, in the event the Node elected Master changes during
+ the lifecycle of the cluster.</para>
+ </note>
+ </section>
+
+ <section id="Java-Broker-High-Availability-MigrationFromNonHA">
+ <title>Migration of a non-HA store to HA</title>
+ <para>Non HA stores starting from schema version 4 (0.14 Qpid release) can be automatically converted into HA store on broker startup if replication is first enabled with the <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/util/DbEnableReplication.html"><classname>DbEnableReplication</classname></ulink> utility from the BDB JE jar.</para>
+ <para>DbEnableReplication converts a non HA store into an HA store and can be used as follows:</para>
+ <example><title>Enabling replication</title><command>
+java -jar je-&oracleBdbProductVersion;.jar DbEnableReplication -h /path/to/store -groupName MyReplicationGroup -nodeName MyNode1 -nodeHostPort localhost:5001
+ </command></example>
+ <para>In the examples above, je jar of version &oracleBdbProductVersion; is used to convert store at <emphasis>/path/to/store</emphasis> into HA store having replication group name <emphasis>MyReplicationGroup</emphasis>, node name <emphasis>MyNode1</emphasis> and running on host <emphasis>localhost</emphasis> and port <emphasis>5001</emphasis>.</para>
+ <para>After running DbEnableReplication and updating the virtual host store to configuration to be an HA message store, like in example below,
+ on broker start up the store schema will be upgraded to the most recent version and the broker can be used as normal.</para>
+ <example>
+ <title>Example of XML configuration for HA message store</title>
+ <programlisting language="xml"><![CDATA[
+<store>
+ <class>org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore</class>
+ <environment-path>/path/to/store</environment-path>
+ <highAvailability>
+ <groupName>MyReplicationGroup</groupName>
+ <nodeName>MyNode1</nodeName>
+ <nodeHostPort>localhost:5001</nodeHostPort>
+ <helperHostPort>localhost:5001</helperHostPort>
+ </highAvailability>
+</store>]]></programlisting>
+ </example>
+ <para>The Replica nodes can be started with empty stores. The data will be automatically copied from Master to Replica on Replica start-up.
+ This will take a period of time determined by the size of the Masters store and the network bandwidth between the nodes.</para>
+ <note>
+ <para>Due to existing caveats in Berkeley JE with copying of data from Master into Replica it is recommended to restart the Master node after store schema upgrade is finished before starting the Replica nodes.</para>
+ </note>
+ </section>
+
+ <section id="Java-Broker-High-Availability-DisasterRecovery">
+ <title>Disaster Recovery</title>
+ <para>This section describes the steps required to restore HA broker cluster from backup.</para>
+ <para>The detailed instructions how to perform backup on replicated environment can be found <link linkend="Java-Broker-High-Availability-Backup">here</link>.</para>
+ <para>At this point we assume that backups are collected on regular basis from Master node.</para>
+ <para>Replication configuration of a cluster is stored internally in HA message store.
+ This information includes IP addresses of the nodes.
+ In case when HA message store needs to be restored on a different host with a different IP address
+ the cluster replication configuration should be reseted in this case</para>
+ <para>Oracle provides a command line utility <ulink url="&oracleBdbJavaDocUrl;com/sleepycat/je/rep/util/DbResetRepGroup.html"><classname>DbResetRepGroup</classname></ulink>
+ to reset the members of a replication group and replace the group with a new group consisting of a single new member
+ as described by the arguments supplied to the utility</para>
+ <para>Cluster can be restored with the following steps:</para>
+ <itemizedlist>
+ <listitem><para>Copy log files into the store folder from backup</para></listitem>
+ <listitem>
+ <para>Use <classname>DbResetRepGroup</classname> to reset an existing environment. See an example below</para>
+ <example>
+ <title>Reseting of replication group with <classname>DbResetRepGroup</classname></title><command>
+java -cp je-&oracleBdbProductVersion;.jar com.sleepycat.je.rep.util.DbResetRepGroup -h ha-work/Node-5001/bdbstore -groupName TestClusterGroup -nodeName Node-5001 -nodeHostPort localhost:5001</command>
+ </example>
+ <para>In the example above <classname>DbResetRepGroup</classname> utility from Berkeley JE of version &oracleBdbProductVersion; is used to reset the store
+ at location <emphasis>ha-work/Node-5001/bdbstore</emphasis> and set a replication group to <emphasis>TestClusterGroup</emphasis>
+ having a node <emphasis>Node-5001</emphasis> which runs at <emphasis>localhost:5001</emphasis>.</para>
+ </listitem>
+ <listitem><para>Start a broker with HA store configured as specified on running of <classname>DbResetRepGroup</classname> utility.</para></listitem>
+ <listitem><para>Start replica nodes having the same replication group and a helper host port pointing to a new master. The store content will be copied into Replicas from Master on their start up.</para></listitem>
+ </itemizedlist>
+ </section>
+
+ <section id="Java-Broker-High-Availability-Performance">
+ <title>Performance</title>
+ <para>The aim of this section is not to provide exact performance metrics relating to HA, as this depends heavily on the test
+ environment, but rather showing an impact of HA on Qpid broker performance in comparison with the Non HA case.</para>
+ <para>For testing of impact of HA on a broker performance a special test script was written using Qpid performance test framework.
+ The script opened a number of connections to the Qpid broker, created producers and consumers on separate connections,
+ and published test messages with concurrent producers into a test queue and consumed them with concurrent consumers.
+ The table below shows the number of producers/consumers used in the tests.
+ The overall throughput was collected for each configuration.
+ </para>
+ <table border="1">
+ <title>Number of producers/consumers in performance tests</title>
+ <thead>
+ <tr>
+ <th>Test</th>
+ <th>Number of producers</th>
+ <th>Number of consumers</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>1</td>
+ <td>1</td>
+ <td>1</td>
+ </tr>
+ <tr>
+ <td>2</td>
+ <td>2</td>
+ <td>2</td>
+ </tr>
+ <tr>
+ <td>3</td>
+ <td>4</td>
+ <td>4</td>
+ </tr>
+ <tr>
+ <td>4</td>
+ <td>8</td>
+ <td>8</td>
+ </tr>
+ <tr>
+ <td>5</td>
+ <td>16</td>
+ <td>16</td>
+ </tr>
+ <tr>
+ <td>6</td>
+ <td>32</td>
+ <td>32</td>
+ </tr>
+ <tr>
+ <td>7</td>
+ <td>64</td>
+ <td>64</td>
+ </tr>
+ </tbody>
+ </table>
+ <para>The test was run against the following Qpid Broker configurations</para>
+ <itemizedlist>
+ <listitem>
+ <para>Non HA Broker</para>
+ </listitem>
+ <listitem>
+ <para>HA 2 Nodes Cluster with durability <emphasis>SYNC,SYNC,ALL</emphasis></para>
+ </listitem>
+ <listitem>
+ <para>HA 2 Nodes Cluster with durability <emphasis>WRITE_NO_SYNC,WRITE_NO_SYNC,ALL</emphasis></para>
+ </listitem>
+ <listitem>
+ <para>HA 2 Nodes Cluster with durability <emphasis>WRITE_NO_SYNC,WRITE_NO_SYNC,ALL</emphasis> and <emphasis>coalescing-sync</emphasis> Qpid mode</para>
+ </listitem>
+ <listitem>
+ <para>HA 2 Nodes Cluster with durability <emphasis>WRITE_NO_SYNC,NO_SYNC,ALL</emphasis> and <emphasis>coalescing-sync</emphasis> Qpid mode</para>
+ </listitem>
+ <listitem>
+ <para>HA 2 Nodes Cluster with durability <emphasis>NO_SYNC,NO_SYNC,ALL</emphasis> and <emphasis>coalescing-sync</emphasis> Qpid option</para>
+ </listitem>
+ </itemizedlist>
+ <para>The evironment used in testing consisted of 2 servers with 4 CPU cores (2x Intel(r) Xeon(R) CPU 5150@2.66GHz), 4GB of RAM
+ and running under OS Red Hat Enterprise Linux AS release 4 (Nahant Update 4). Network bandwidth was 1Gbit.
+ </para>
+ <para>We ran Master node on the first server and Replica and clients(both consumers and producers) on the second server.</para>
+ <para>In non-HA case Qpid Broker was run on a first server and clients were run on a second server.</para>
+ <para>The table below contains the test results we measured on this environment for different Broker configurations.</para>
+ <para>Each result is represented by throughput value in KB/second and difference in % between HA configuration and non HA case for the same number of clients.</para>
+ <table border="1">
+ <title>Performance Comparison</title>
+ <thead>
+ <tr>
+ <td>Test/Broker</td>
+ <td>No HA</td>
+ <td>SYNC, SYNC, ALL</td>
+ <td>WRITE_NO_SYNC, WRITE_NO_SYNC, ALL</td>
+ <td>WRITE_NO_SYNC, WRITE_NO_SYNC, ALL - coalescing-sync</td>
+ <td>WRITE_NO_SYNC, NO_SYNC,ALL - coalescing-sync</td>
+ <td>NO_SYNC, NO_SYNC, ALL - coalescing-sync</td>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>1 (1/1)</td>
+ <td>0.0%</td>
+ <td>-61.4%</td>
+ <td>117.0%</td>
+ <td>-16.02%</td>
+ <td>-9.58%</td>
+ <td>-25.47%</td>
+ </tr>
+ <tr>
+ <td>2 (2/2)</td>
+ <td>0.0%</td>
+ <td>-75.43%</td>
+ <td>67.87%</td>
+ <td>-66.6%</td>
+ <td>-69.02%</td>
+ <td>-30.43%</td>
+ </tr>
+ <tr>
+ <td>3 (4/4)</td>
+ <td>0.0%</td>
+ <td>-84.89%</td>
+ <td>24.19%</td>
+ <td>-71.02%</td>
+ <td>-69.37%</td>
+ <td>-43.67%</td>
+ </tr>
+ <tr>
+ <td>4 (8/8)</td>
+ <td>0.0%</td>
+ <td>-91.17%</td>
+ <td>-22.97%</td>
+ <td>-82.32%</td>
+ <td>-83.42%</td>
+ <td>-55.5%</td>
+ </tr>
+ <tr>
+ <td>5 (16/16)</td>
+ <td>0.0%</td>
+ <td>-91.16%</td>
+ <td>-21.42%</td>
+ <td>-86.6%</td>
+ <td>-86.37%</td>
+ <td>-46.99%</td>
+ </tr>
+ <tr>
+ <td>6 (32/32)</td>
+ <td>0.0%</td>
+ <td>-94.83%</td>
+ <td>-51.51%</td>
+ <td>-92.15%</td>
+ <td>-92.02%</td>
+ <td>-57.59%</td>
+ </tr>
+ <tr>
+ <td>7 (64/64)</td>
+ <td>0.0%</td>
+ <td>-94.2%</td>
+ <td>-41.84%</td>
+ <td>-89.55%</td>
+ <td>-89.55%</td>
+ <td>-50.54%</td>
+ </tr>
+ </tbody>
+ </table>
+ <para>The figure below depicts the graphs for the performance test results</para>
+ <figure>
+ <title>Test results</title>
+ <graphic fileref="images/HA-perftests-results.png"/>
+ </figure>
+ <para>On using durability <emphasis>SYNC,SYNC,ALL</emphasis> (without coalescing-sync) the performance drops significantly (by 62-95%) in comparison with non HA broker.</para>
+ <para>Whilst, on using durability <emphasis>WRITE_NO_SYNC,WRITE_NO_SYNC,ALL</emphasis> (without coalescing-sync) the performance drops by only half, but with loss of durability guarantee, so is not recommended.</para>
+ <para>In order to have better performance with HA, Qpid Broker comes up with the special mode called <link linkend="Java-Broker-High-Availability-DurabilityGuarantee_CoalescingSync">coalescing-sync</link>,
+ With this mode enabled, Qpid broker batches the concurrent transaction commits and syncs transaction data into Master disk in one go.
+ As result, the HA performance only drops by 25-60% for durability <emphasis>NO_SYNC,NO_SYNC,ALL</emphasis> and by 10-90% for <emphasis>WRITE_NO_SYNC,WRITE_NO_SYNC,ALL</emphasis>.</para>
+ </section>
+
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Installation.xml b/doc/book/src/java-broker/Java-Broker-Installation.xml
new file mode 100644
index 0000000000..218e39f578
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Installation.xml
@@ -0,0 +1,185 @@
+<?xml version="1.0"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<chapter id="Java-Broker-Installation">
+ <title>Installation</title>
+ <section role="h2" id="Java-Broker-Installation-Introduction">
+ <title>Introduction</title>
+ <para>This document describes how to install the Java Broker on both Windows and UNIX
+ platforms.</para>
+ </section>
+ <section role="h2" id="Java-Broker-Installation-Prerequistes">
+ <title>Prerequisites</title>
+ <section role="h3" id="Java-Broker-Installation-Prerequistes-Java">
+ <title>Java Platform</title>
+ <para>
+ The Java Broker is an 100% Java implementation and as such it can be used on any operating
+ system supporting Java 1.6 or higher. This includes Linux, Solaris, Mac OS X, and Windows XP/Vista/7/8.</para>
+ <para>
+ The broker has been tested with Java implementations from both Oracle and IBM. Whatever
+ platform you chose, it is recommended that you ensure it is patched with any critical updates made
+ available from the vendor.
+ </para>
+ <para>
+ Verify that your JVM is installed properly by following <link linkend="Java-Broker-Miscellaneous-JVM-Verification">these instructions.</link>
+ </para>
+ </section>
+ <section role="h3" id="Java-Broker-Installation-Prerequistes-Disk">
+ <title>Disk</title>
+ <para>The Java Broker installation requires approximately 20MB of free disk space.</para>
+ <para>The Java Broker also requires a working directory. The working directory is used for
+ the message store, that is, the area of the file-system used to record persistent messages whilst they
+ are passing through the Broker. The working directory is also used for the default location of the log file.
+ The size of the working directory will depend on the how the Broker is used.</para>
+ <para>The performance of the file system hosting the work directory is key to the performance of Broker as
+ a whole. For best performance, choose a device that has low latency and one that is uncontended by other
+ applications.</para>
+ <para>Be aware that there are additional considerations if you are considering hosting the working directory on NFS. See
+ <xref linkend="Java-Broker-Stores"/> for further details.</para>
+ </section>
+ <section role="h3" id="Java-Broker-Installation-Prerequistes-Memory">
+ <title>Memory</title>
+ <para>Qpid caches messages on the heap for performance reasons, so in general, the Broker will
+ benefit from as much heap as possible. However, on a 32bit JVM, the maximum addressable memory range
+ for a process is 4GB, after leaving space for the JVM's own use this will give a maximum heap size
+ of approximately ~3.7GB.</para>
+ </section>
+ <section role="h3" id="Java-Broker-Installation-Prerequistes-OperatingSystemAccount">
+ <title>Operating System Account</title>
+ <para>Installation or operation of Qpid does <emphasis>not</emphasis> require a privileged account (i.e. root
+ on UNIX platforms or Administrator on Windows). However it is suggested that you use an dedicated account
+ (e.g. qpid) for the installation and operation of the Java Broker.</para>
+ </section>
+ </section>
+
+ <section role="h2" id="Java-Broker-Installation-Download">
+ <title>Download</title>
+ <section role="h3" id="Java-Broker-Installation-Download-Release">
+ <title>Broker Release</title>
+ <para>You can download the latest qpid-java-broker-&qpidCurrentRelease;.tar.gz package from the <ulink
+ url="&qpidDownloadUrl;">Download Page</ulink>.
+ </para>
+ <para> It is recommended that you confirm the integrity of the download by verifying the PGP signature
+ matches that available on the site. Instrutions are given on the download page.
+ </para>
+ </section>
+ <section role="h3" id="Java-Broker-Installation-Download-OptionalDependencies">
+ <title>Optional Dependencies</title>
+ <para>The broker has an optional message store implementations backed by Oracle BDB JE. If you wish to use these
+ stores you will need to provide the optional Oracle BDB JE dependency. For more details, see <xref linkend="Java-Broker-Stores-BDB-Store"></xref>
+ </para>
+ </section>
+ </section>
+
+ <section role="h2" id="Java-Broker-Installation-InstallationWindows">
+ <title>Installation on Windows</title>
+ <para>
+ Firstly, verify that your JVM is installed properly by following
+ <link linkend="Java-Broker-Miscellaneous-JVM-Verification-Windows">these instructions.</link>
+ </para>
+ <para>Now chose a directory for Qpid broker installation. This directory will be used for the Qpid JARs and configuration files.
+ It need not be the same location as the store used for the persistent messages or the log file (you will chose this
+ location later). For the remainder this example we will assumed that location c:\qpid has been chosen.</para>
+ <para>Now using WinZip<footnote><para>WinZip is a Registered Trademark of WinZip International LLC</para></footnote> (or similar)
+ extract the Qpid package qpid-java-broker-&qpidCurrentRelease;.tar.gz into the directory.</para>
+ <para>The extraction of the Qpid package will have created a directory qpid-broker-&qpidCurrentRelease; within c:\qpid</para>
+ <screen>Volume in drive C has no label
+
+ Directory of c:\qpid\qpid-broker-&qpidCurrentRelease;
+
+07/25/2012 11:22 PM .
+09/30/2012 10:51 AM ..
+09/30/2012 12:24 AM bin
+08/21/2012 11:17 PM etc
+07/25/2012 11:22 PM lib
+07/20/2012 08:10 PM 65,925 LICENSE
+07/20/2012 08:10 PM 3,858 NOTICE
+07/20/2012 08:10 PM 1,346 README.txt
+ 3 File(s) 71,129 bytes
+ 5 Dir(s) 743,228,796,928 bytes free</screen>
+ <section role="h3" id="Java-Broker-Installation-InstallationWindows-SettingQPIDWORK">
+ <title>Setting the working directory</title>
+ <para>Qpid requires a work directory. This directory is used for the default location of the Qpid log
+ file and is used for the storage of persistent messages. The work directory can be set on the
+ command-line (for the lifetime of the command interpreter), but you will normally want to set
+ the environment variable permanently via the Advanced System Settings in the Control Panel.</para>
+ <screen>set QPID_WORK=S:\qpidwork</screen>
+ <para>If the directory referred to by QPID_WORK does not exist, the Java Broker will attempt to create it
+ on start-up.</para>
+ </section>
+ <section role="h3" id="Java-Broker-Installation-InstallationWindows-OptionalDependencies">
+ <title>Optional Dependencies</title>
+ <para>The broker has an optional message store implementations backed by Oracle BDB JE. If you wish to use these
+ stores you will need to provide the optional Oracle BDB JE dependency. For more details, see <xref linkend="Java-Broker-Stores-BDB-Store"></xref>
+ </para>
+ </section>
+ </section>
+
+ <section role="h2" id="Java-Broker-Installation-InstallationUnix">
+ <title>Installation on UNIX platforms</title>
+ <para>
+ Firstly, verify that your JVM is installed properly by following
+ <link linkend="Java-Broker-Miscellaneous-JVM-Verification-Unix">these instructions.</link>
+ </para>
+ <para>Now chose a directory for Qpid broker installation. This directory will be used for the Qpid JARs and configuration files.
+ It need not be the same location as the store used for the persistent messages or the log file (you will chose this
+ location later). For the remainder this example we will assumed that location /usr/local/qpid has been chosen.</para>
+ <para>Extract the Qpid package qpid-java-broker-&qpidCurrentRelease;.tar.gz into the directory.</para>
+ <programlisting>mkdir /usr/local/qpid
+cd /usr/local/qpid
+tar xvzf qpid-java-broker-&qpidCurrentRelease;.tar.gz></programlisting>
+ <para>The extraction of the Qpid package will have created a directory qpid-broker-x.x</para>
+ <screen>ls -la qpid-broker-&qpidCurrentRelease;/
+total 152
+drwxr-xr-x 8 qpid qpid 272 25 Jul 23:22 .
+drwxr-xr-x 45 qpid qpid 1530 30 Sep 10:51 ..
+-rw-r--r--@ 1 qpid qpid 65925 20 Jul 20:10 LICENSE
+-rw-r--r--@ 1 qpid qpid 3858 20 Jul 20:10 NOTICE
+-rw-r--r--@ 1 qpid qpid 1346 20 Jul 20:10 README.txt
+drwxr-xr-x 10 qpid qpid 340 30 Sep 00:24 bin
+drwxr-xr-x 9 qpid qpid 306 21 Aug 23:17 etc
+drwxr-xr-x 34 qpid qpid 1156 25 Jul 23:22 lib
+ </screen>
+ <section role="h3" id="Java-Broker-Installation-InstallationUnix-SettingQPIDWORK">
+ <title>Setting the working directory</title>
+ <para>Qpid requires a work directory. This directory is used for the default location of the Qpid log
+ file and is used for the storage of persistent messages. The work directory can be set on the
+ command-line (for the lifetime of the current shell), but you will normally want to set
+ the environment variable permanently the user's shell profile file (~/.bash_profile for Bash etc).</para>
+ <screen><![CDATA[export QPID_WORK=/var/qpidwork]]>
+ </screen>
+ <para>If the directory referred to by QPID_WORK does not exist, the Java Broker will attempt to create it
+ on start-up.
+ </para>
+ </section>
+ <section role="h3" id="Java-Broker-Installation-InstallationUnix-OptionalDependencies">
+ <title>Optional Dependencies</title>
+ <para>The broker has an optional message store implementations backed by Oracle BDB JE. If you wish to use these
+ stores you will need to provide the optional Oracle BDB JE dependency. For more details, see <xref linkend="Java-Broker-Stores-BDB-Store"></xref>
+ </para>
+ </section>
+ </section>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Introduction.xml b/doc/book/src/java-broker/Java-Broker-Introduction.xml
new file mode 100644
index 0000000000..651389d0ac
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Introduction.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0"?>
+<!DOCTYPE chapter[
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<chapter id="Java-Broker-Introduction">
+ <title>Introduction</title>
+ <para>The Java Broker is a powerful open-source message broker that implements all versions of the
+ <ulink url="http://www.amqp.org"> Advanced Message Queuing Protocol (AMQP)</ulink>. The Java
+ Broker is actually one of two message brokers provided by the <ulink
+ url="http://qpid.apache.org">Apache Qpid project</ulink>: the Java Broker and the C++
+ Broker.</para>
+ <para>This document relates to the Java Broker. The <ulink url="&qpidCppBook;">C++ Broker is
+ described separately</ulink>.</para>
+ <para><emphasis>Headline features</emphasis></para>
+ <itemizedlist mark="circle">
+ <listitem>
+ <para>100% Java implementation - runs on any platform supporting Java 1.6 or higher</para>
+ </listitem>
+ <listitem>
+ <para>Messaging clients support in Java, C++, Python.</para>
+ </listitem>
+ <listitem>
+ <para>JMS 1.1 compliance (Java client).</para>
+ </listitem>
+ <listitem>
+ <para>Persistent and non-persistent (transient) message support</para>
+ </listitem>
+ <listitem>
+ <para>Supports for all common messaging patterns (point-to-point, publish/subscribe, fan-out
+ etc).</para>
+ </listitem>
+ <listitem>
+ <para>Transaction support including XA<footnote>
+ <para>XA provided when using AMQP 0-10</para>
+ </footnote></para>
+ </listitem>
+ <listitem>
+ <para>Supports for all versions of the AMQP protocol</para>
+ </listitem>
+ <listitem>
+ <para>Automatic message translation, allowing clients using different AMQP versions to communicate with each other.</para>
+ </listitem>
+ <listitem>
+ <para>Pluggable authentication architecture with out-of-the-box support for Kerberos, LDAP,
+ External, and file-based authentication mechanisms.</para>
+ </listitem>
+ <listitem>
+ <para>Pluggable message store architecture with implementations based on <ulink
+ url="http://db.apache.org/derby/">Apache Derby</ulink>, <ulink
+ url="&oracleBdbProductOverviewUrl;">Oracle BDB JE</ulink><footnote>
+ <para>Oracle BDB JE must be downloaded separately.</para>
+ </footnote>, and Memory Store</para>
+ </listitem>
+ <listitem>
+ <para>Web based management interface and programmatic management interfaces via REST and JMX
+ APIs.</para>
+ </listitem>
+ <listitem>
+ <para>SSL support</para>
+ </listitem>
+ <listitem>
+ <para>High availability (HA) support.<footnote>
+ <para>HA currently only available to users of the optional BDB JE HA based message store.</para>
+ </footnote></para>
+ </listitem>
+ </itemizedlist>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Miscellaneous.xml b/doc/book/src/java-broker/Java-Broker-Miscellaneous.xml
new file mode 100644
index 0000000000..007d6cde5b
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Miscellaneous.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<chapter id="Java-Broker-Miscellaneous">
+ <title>Miscellaneous</title>
+
+ <section role="h2" id="Java-Broker-Miscellaneous-JVM-Verification">
+ <title>JVM Installation verification</title>
+ <section role="h2" id="Java-Broker-Miscellaneous-JVM-Verification-Windows">
+ <title>Verify JVM on Windows</title>
+ <para>
+ Firstly confirm that the JAVA_HOME environment variable is set correctly by typing the
+ following at the command prompt:
+ </para>
+ <programlisting><![CDATA[echo %JAVA_HOME%]]></programlisting>
+ <para>
+ If JAVA_HOME is set you will see something similar to the following:
+ </para>
+ <screen><![CDATA[c:"\PROGRA~1"\Java\jdk1.6.0_24\]]>
+ </screen>
+ <para>
+ Then confirm that a Java installation (1.6 or higher) is available:
+ </para>
+ <programlisting><![CDATA[java -version]]></programlisting>
+ <para>
+ If java is available on the path, output similar to the following will be seen:
+ </para>
+ <screen><![CDATA[java version "1.6.0_24"
+Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
+Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)]]></screen>
+ </section>
+
+ <section role="h2" id="Java-Broker-Miscellaneous-JVM-Verification-Unix">
+ <title>Verify JVM on Windows</title>
+ <para>
+ Firstly confirm that the JAVA_HOME environment variable is set correctly by typing the
+ following at the command prompt:
+ </para>
+ <programlisting><![CDATA[echo $JAVA_HOME]]></programlisting>
+ <para>
+ If JAVA_HOME is set you will see something similar to the following:
+ </para>
+ <screen><![CDATA[/usr/java/jdk1.6.0_35]]>
+ </screen>
+ <para>
+ Then confirm that a Java installation (1.6 or higher) is available:
+ </para>
+ <programlisting><![CDATA[java -version]]></programlisting>
+ <para>
+ If java is available on the path, output similar to the following will be seen:
+ </para>
+ <screen><![CDATA[java version "1.6.0_35"
+Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
+Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)]]></screen>
+ </section>
+ </section>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Queues-Messaging-Groups.xml b/doc/book/src/java-broker/Java-Broker-Queues-Messaging-Groups.xml
new file mode 100644
index 0000000000..60413282a0
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Queues-Messaging-Groups.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Queues-Messaging-Groups">
+<title>Messaging Groups</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Queues-OtherTypes.xml b/doc/book/src/java-broker/Java-Broker-Queues-OtherTypes.xml
new file mode 100644
index 0000000000..471d73f283
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Queues-OtherTypes.xml
@@ -0,0 +1,276 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<section id="Java-Broker-Queues-OtherTypes">
+ <title>Other Queue Types</title>
+
+ <section role="h2" id="Java-Broker-Queues-OtherTypes-Introduction">
+ <title>Introduction</title>
+ <para> In addition to the standard queue type where messages are delivered in the same order
+ that they were sent, the Java Broker supports three additional queue types which allows for
+ alternative delivery behaviours. These are <link linkend="Java-Broker-Queues-OtherTypes-Priority"
+ >priority-queues</link>, <link linkend="Java-Broker-Queues-OtherTypes-Sorted">sorted-queues</link>-, and
+ <link linkend="Java-Broker-Queues-OtherTypes-LVQ">last-value-queues</link> (LVQs). </para>
+ <para> In the following sections, the semantics of each queue type is described, followed by a
+ description of how instances of these queue can be created via <link
+ linkend="Java-Broker-Queues-OtherTypes-CreateUsingConfig">configuration</link> or <link
+ linkend="Java-Broker-Queues-OtherTypes-CreateUsingJmsOrJmx">programmatically</link>. </para>
+ <para>The final section discusses the importance of using a <link
+ linkend="Java-Broker-Queues-OtherTypes-SetLowPrefetch">low client pre-fetch</link> with these queued.
+ </para>
+ </section>
+
+ <section role="h2" id="Java-Broker-Queues-OtherTypes-Priority">
+ <title>Priority Queues</title>
+ <para>In a priority queue, messages on the queue are delivered in an order determined by the
+ <ulink url="&oracleJeeDocUrl;javax/jms/Message.html#getJMSPriority()">JMS priority message
+ header</ulink> within the message. By default Qpid supports the 10 priority levels mandated
+ by JMS, with priority value 0 as the lowest priority and 9 as the highest. </para>
+ <para>It is possible to reduce the effective number of priorities if desired.</para>
+ <para>JMS defines the <ulink url="&oracleJeeDocUrl;javax/jms/Message.html#DEFAULT_PRIORITY">
+ default message priority</ulink> as 4. Messages sent without a specified priority use this
+ default. </para>
+ </section>
+ <section role="h2" id="Java-Broker-Queues-OtherTypes-Sorted">
+ <title>Sorted Queues</title>
+ <para>Sorted queues allow the message delivery order to be determined by value of an arbitrary
+ <ulink url="&oracleJeeDocUrl;javax/jms/Message.html#getStringProperty()">JMS message
+ property</ulink>. Sort order is alpha-numeric and the property value must have a type
+ java.lang.String.</para>
+ <para>Messages sent to a sorted queue without the specified JMS message property will be
+ inserted into the 'last' position in the queue.</para>
+ </section>
+ <section role="h2" id="Java-Broker-Queues-OtherTypes-LVQ">
+ <title>Last Value Queues (LVQ)</title>
+ <para>LVQs (or conflation queues) are special queues that automatically discard any message when
+ a newer message arrives with the same key value. The key is specified by arbitrary <ulink
+ url="&oracleJeeDocUrl;javax/jms/Message.html#getPropertyNames()">JMS message
+ property</ulink>.</para>
+ <para>An example of an LVQ might be where a queue represents prices on a stock exchange: when
+ you first consume from the queue you get the latest quote for each stock, and then as new
+ prices come in you are sent only these updates. </para>
+ <para>Like other queues, LVQs can either be browsed or consumed from. When browsing an
+ individual subscriber does not remove the message from the queue when receiving it. This
+ allows for many subscriptions to browse the same LVQ (i.e. you do not need to create and bind
+ a separate LVQ for each subscriber who wishes to receive the contents of the LVQ).</para>
+ <para>Messages sent to an LVQ without the specified property will be delivered as normal and
+ will never be "replaced".</para>
+ </section>
+ <section role="h2" id="Java-Broker-Queues-OtherTypes-Create">
+ <title>Creating a Priority, Sorted or LVQ Queue</title>
+ <para>To create a priority, sorted or LVQ queue, it can be defined in the virtualhost
+ configuration file, or the queue can be created programmtically from a client via AMQP (using
+ an extension to JMS), or using JMX. These methods are described below. </para>
+ <para>Once a queue is created you cannot change its type (without deleting it and re-creating).
+ Also note you cannot currently mix the natures of these queue types, for instance, you cannot
+ define a queue which it both an LVQ and a priority-queue.</para>
+ <section role="h2" id="Java-Broker-Queues-OtherTypes-CreateUsingConfig">
+ <title>Using configuration</title>
+ <para>To create a priority, sorted or LVQ queue within configuration, add the appropriate xml
+ to the virtualhost.xml configuration file within the <varname>queues</varname>
+ element.</para>
+ <section role="h3" id="Java-Broker-Queues-OtherTypes-CreateUsingConfig-Priority">
+ <title>Priority</title>
+ <para> To defining a priority queue, add a &lt;priority&gt;true&lt;/priority&gt; element. By
+ default the queue will have 10 distinct priorities. </para>
+ <example>
+ <title>Configuring a priority queue</title>
+ <programlisting><![CDATA[<queue>
+ <name>myqueue</name>
+ <myqueue>
+ <exchange>amq.direct</exchange>
+ <priority>true</priority>
+ </myqueue>
+</queue>]]></programlisting>
+ </example>
+ <para> If you require fewer priorities, it is possible to specify a
+ <varname>priorities</varname> element (whose value is a integer value between 2 and 10
+ inclusive) which will give the queue that number of distinct priorities. When messages are
+ sent to that queue, their effective priority will be calculated by partitioning the
+ priority space. If the number of effective priorities is 2, then messages with priority
+ 0-4 are treated the same as "lower priority" and messages with priority 5-9 are treated
+ equivalently as "higher priority". </para>
+ <example>
+ <title>Configuring a priority queue with fewer priorities</title>
+ <programlisting><![CDATA[<queue>
+ <name>myqueue</name>
+ <myqueue>
+ <exchange>amq.direct</exchange>
+ <priority>true</priority>
+ <priorities>4</priorities>
+ </myqueue>
+</queue>]]></programlisting>
+ </example>
+ </section>
+ <section role="h3" id="Java-Broker-Queues-OtherTypes-CreateUsingConfig-Sorted">
+ <title>Sorted</title>
+ <para> To define a sorted queue, add a <varname>sortKey</varname> element. The value of the
+ <varname>sortKey</varname> element defines the message property to use the value of when
+ sorting the messages put onto the queue. </para>
+ <example>
+ <title>Configuring a sorted queue</title>
+ <programlisting><![CDATA[<queue>
+ <name>myqueue</name>
+ <myqueue>
+ <exchange>amq.direct</exchange>
+ <sortKey>message-property-to-sort-by</sortKey>
+ </myqueue>
+</queue>]]></programlisting>
+ </example>
+ </section>
+ <section role="h3" id="Java-Broker-Queues-OtherTypes-CreateUsingConfig-LVQ">
+ <title>LVQ</title>
+ <para> To define a LVQ, add a <varname>lvq</varname> element with the value
+ <constant>true</constant>. Without any further configuration this will define an LVQ
+ which uses the JMS message property <constant>qpid.LVQ_key</constant> as the key for
+ replacement. </para>
+ <example>
+ <title>Configuring a LVQ queue</title>
+ <programlisting><![CDATA[<queue>
+ <name>myqueue</name>
+ <myqueue>
+ <exchange>amq.direct</exchange>
+ <lvq>true</lvq>
+ </myqueue>
+</queue>]]></programlisting>
+ </example>
+ <para> If you wish to define your own property then you can do so using the
+ <varname>lvqKey</varname> element.</para>
+ <example>
+ <title>Configuring a LVQ queue with custom message property name</title>
+ <programlisting><![CDATA[<queue>
+ <name>myqueue</name>
+ <myqueue>
+ <exchange>amq.direct</exchange>
+ <lvq>true</lvq>
+ <lvqKey>ISIN</lvqKey>
+ </myqueue>
+</queue>]]></programlisting>
+ </example>
+ </section>
+ </section>
+ <section role="h2" id="Java-Broker-Queues-OtherTypes-CreateUsingJmsOrJmx">
+ <title>Using JMX or AMQP</title>
+ <para>To create a priority, sorted or LVQ queue programmatically from JMX or using a Qpid
+ extension to JMS, pass the appropriate queue-declare arguments.</para>
+ <table>
+ <title>Queue-declare arguments understood for priority, sorted and LVQ queues</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Queue type</entry>
+ <entry>Argument name</entry>
+ <entry>Argument name</entry>
+ <entry>Argument Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>priority</entry>
+ <entry>priorities</entry>
+ <entry>java.lang.Integer</entry>
+ <entry>Specifies a priority queue with given number priorities</entry>
+ </row>
+ <row>
+ <entry>sorted</entry>
+ <entry>qpid.queue_sort_key</entry>
+ <entry>java.lang.String</entry>
+ <entry>Specifies sorted queue with given message property used to sort the
+ entries</entry>
+ </row>
+ <row>
+ <entry>lvq</entry>
+ <entry>qpid.last_value_queue_key</entry>
+ <entry>java.lang.String</entry>
+ <entry>Specifies lvq queue with given message property used to conflate the
+ entries</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <para>The following example illustrates the creation of the a LVQ queue from a
+ javax.jms.Session object. Note that this utilises a Qpid specific extension to JMS and
+ involves casting the session object back to its Qpid base-class.</para>
+ <example>
+ <title>Creation of an LVQ using the Qpid extension to JMS</title>
+ <programlisting><![CDATA[Map<String,Object> arguments = new HashMap<String, Object>();
+arguments.put("qpid.last_value_queue_key","ISIN");
+((AMQSession<?,?>) session).createQueue(queueName, autoDelete, durable, exclusive, arguments);]]></programlisting>
+
+ </example>
+ <para> The following example illustrates the creation of the sorted queue from a the JMX
+ interface using the ManagedBroker interface. </para>
+ <example>
+ <title>Creation of a sorted queue using JMX</title>
+ <programlisting><![CDATA[Map<String, Object> environment = new HashMap<String, Object>();
+environment.put(JMXConnector.CREDENTIALS, new String[] {"admin","password"});
+// Connect to service
+JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi");
+JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
+MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
+// Object name for ManagedBroker for virtualhost myvhost
+ObjectName objectName = new ObjectName("org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=myvhost");
+// Get the ManagedBroker object
+ManagedBroker managedBroker = JMX.newMBeanProxy(mbsc, objectName, ManagedBroker.class);;
+
+// Create the queue passing arguments
+Map<String,Object> arguments = new HashMap<String, Object>();
+arguments.put("qpid.queue_sort_key","myheader");
+managedBroker.createNewQueue("myqueue", null, true, arguments);]]></programlisting>
+ </example>
+ </section>
+ </section>
+
+ <section role="h2" id="Java-Broker-Queues-OtherTypes-SetLowPrefetch">
+ <title>Low pre-fetch</title>
+ <para>Qpid clients receive buffered messages in batches, sized according to the pre-fetch value.
+ The current default is 500. </para>
+ <para>However, if you use the default value you will probably <emphasis>not</emphasis> see
+ desirable behaviour when using priority, sorted or lvq queues. Once the broker has sent a
+ message to the client its delivery order is then fixed, regardless of the special behaviour of
+ the queue. </para>
+ <para>For example, if using a priority queue and a prefetch of 100, and 100 messages arrive with
+ priority 2, the broker will send these messages to the client. If then a new message arrives
+ will priority 1, the broker cannot leap frog messages of lower priority. The priority 1 will
+ be delivered at the front of the next batch of messages to be sent to the client.</para>
+ <para> So, you need to set the prefetch values for your client (consumer) to make this sensible.
+ To do this set the Java system property <varname>max_prefetch</varname> on the client
+ environment (using -D) before creating your consumer. </para>
+ <para>A default for all client connections can be set via a system property: </para>
+ <programlisting>
+-Dmax_prefetch=1
+</programlisting>
+ <para> The prefetch can be also be adjusted on a per connection basis by adding a
+ <varname>maxprefetch</varname> value to the <ulink url="../../Programming-In-Apache-Qpid/html/QpidJNDI.html#section-jms-connection-url">Connection URLs</ulink>
+ </para>
+ <programlisting>
+amqp://guest:guest@client1/development?maxprefetch='1'&amp;brokerlist='tcp://localhost:5672'
+</programlisting>
+ <para>Setting the Qpid pre-fetch to 1 will give exact queue-type semantics as perceived by the
+ client however, this brings a performance cost. You could test with a slightly higher
+ pre-fetch to trade-off between throughput and exact semantics.</para>
+ </section>
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Queues.xml b/doc/book/src/java-broker/Java-Broker-Queues.xml
new file mode 100644
index 0000000000..050d4cdbce
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Queues.xml
@@ -0,0 +1,27 @@
+<?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.
+
+-->
+
+<chapter id="Java-Broker-Queues">
+ <title>Queues</title>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Queues-Messaging-Groups.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Queues-OtherTypes.xml"/>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Runtime-Alerts.xml b/doc/book/src/java-broker/Java-Broker-Runtime-Alerts.xml
new file mode 100644
index 0000000000..29ac68b937
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Runtime-Alerts.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Runtime-Alerts">
+<title>Alerts</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Runtime-Disk-Space-Management-Producer-Flow-Control.xml b/doc/book/src/java-broker/Java-Broker-Runtime-Disk-Space-Management-Producer-Flow-Control.xml
new file mode 100644
index 0000000000..8db014a6b7
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Runtime-Disk-Space-Management-Producer-Flow-Control.xml
@@ -0,0 +1,228 @@
+<?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.
+
+-->
+
+<section id="Qpid-Producer-Flow-Control">
+ <title>Producer Flow Control</title>
+
+ <section role="h2" id="Java-Broker-Runtime-Disk-Space-Management-Producer-Flow-Control-GeneralInformation">
+ <title>General Information</title>
+ <para>
+ The Qpid 0.6 release introduced a simplistic producer-side flow control mechanism
+ into the Java Messaging Broker, causing producers to be flow-controlled when they
+ attempt to send messages to an overfull queue. Qpid 0.18 introduced a similar
+ mechanism triggered by an overfull persistent message store on a virtual host.
+ </para>
+ </section>
+ <section role="h2" id="Java-Broker-Runtime-Disk-Space-Management-Producer-Flow-Control-ServerConfiguration">
+ <title>Server Configuration</title>
+ <section role="h3">
+ <title>Configuring a Queue to use flow control</title>
+ <para>
+ Flow control is enabled on a producer when it sends a message to a Queue
+ which is "overfull". The producer flow control will be rescinded when all
+ Queues on which a producer is blocking become "underfull". A Queue is defined
+ as overfull when the size (in bytes) of the messages on the queue exceeds the
+ "capacity" of the Queue. A Queue becomes "underfull" when its size becomes
+ less than the "flowResumeCapacity".
+
+
+ <example>
+ <title>Configuring a queue depth limit</title>
+ <programlisting>
+ <![CDATA[
+<queue>
+ <name>test</name>
+ <test>
+ <exchange>amq.direct</exchange>
+ <capacity>10485760</capacity> <!-- set the queue capacity to 10Mb -->
+ <flowResumeCapacity>8388608</flowResumeCapacity> <!-- set the resume capacity to 8Mb -->
+ </test>
+</queue>
+ ]]>
+ </programlisting>
+ </example>
+
+ The default for all queues on a virtual host can also be set
+
+ <example>
+ <title>Configuring a default queue depth limit on a virtualhost</title>
+ <programlisting>
+ <![CDATA[
+<virtualhosts>
+ <virtualhost>
+ <name>localhost</name>
+ <localhost>
+ <capacity>10485760</capacity> <!-- set the queue capacity to 10Mb -->
+ <flowResumeCapacity>8388608</flowResumeCapacity> <!-- set the resume capacity to 8Mb -->
+ </localhost>
+ </virtualhost>
+</virtualhosts>
+ ]]>
+ </programlisting>
+ </example>
+
+ Where no flowResumeCapacity is set, the flowResumeCapacity is set to be equal
+ to the capacity. Where no capacity is set, capacity is defaulted to 0 meaning
+ there is no capacity limit.
+ </para>
+ <section role="h4">
+ <title>Broker Log Messages</title>
+ <para>
+ There are four new Broker log messages that may occur if flow control through queue capacity limits is enabled.
+ Firstly, when a capacity limited queue becomes overfull, a log message similar to the following is produced
+ </para>
+ <programlisting>
+MESSAGE [vh(/test)/qu(MyQueue)] [vh(/test)/qu(MyQueue)] QUE-1003 : Overfull : Size : 1,200 bytes, Capacity : 1,000
+ </programlisting>
+ <para>Then for each channel which becomes blocked upon the overful queue a log message similar to the following is produced:</para>
+ <programlisting>
+MESSAGE [con:2(guest@anonymous(713889609)/test)/ch:1] [con:2(guest@anonymous(713889609)/test)/ch:1] CHN-1005 : Flow Control Enforced (Queue MyQueue)
+ </programlisting>
+ <para>When enough messages have been consumed from the queue that it becomes underfull, then the following log is generated: </para>
+ <programlisting>
+MESSAGE [vh(/test)/qu(MyQueue)] [vh(/test)/qu(MyQueue)] QUE-1004 : Underfull : Size : 600 bytes, Resume Capacity : 800
+ </programlisting>
+ <para>And for every channel which becomes unblocked you will see a message similar to: </para>
+ <programlisting>
+MESSAGE [con:2(guest@anonymous(713889609)/test)/ch:1] [con:2(guest@anonymous(713889609)/test)/ch:1] CHN-1006 : Flow Control Removed
+ </programlisting>
+ <para>Obviously the details of connection, virtual host, queue, size, capacity, etc would depend on the configuration in use.</para>
+
+
+ </section><!-- Broker Log Messages -->
+ </section><!-- Configuring a Queue to use flow control -->
+
+ <section role="h3">
+ <title>Disk quota-based flow control</title>
+ <para>
+ Since version 0.18 of Qpid Broker, flow control can be triggered when a
+ configured disk quota is exceeded. This is supported by the BDB and Derby message stores.
+ </para>
+ <para>
+ This functionality blocks all producers on reaching the disk overflow limit. When consumers
+ consume the messages, causing disk space usage to falls below the underflow limit, the
+ producers are unblocked and continue working as normal.
+ </para>
+ <para>
+ Two limits can be configured:
+ </para>
+ <para>
+ overfull limit - the maximum space on disk (in bytes) which can be used by store.
+ </para>
+ <para>
+ underfull limit - when the space on disk drops below this limit, producers are allowed to resume publishing.
+ </para>
+ <para>
+ An example of quota configuration for the BDB message store is provided below.
+ </para>
+
+ <example>
+ <title>Configuring a limit on a store</title>
+ <programlisting>
+ <![CDATA[
+<store>
+ <class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>
+ <environment-path>${work}/bdbstore/test</environment-path>
+ <overfull-size>50000000</overfull-size>
+ <underfull-size>45000000</underfull-size>
+</store>
+ ]]>
+ </programlisting>
+ </example>
+ <para>
+ The disk quota functionality is based on "best effort" principle. This means the broker
+ cannot guarantee that the disk space limit will not be exceeded. If several concurrent
+ transactions are started before the limit is reached, which collectively cause the limit
+ to be exceeded, the broker may allow all of them to be committed.
+ </para>
+
+ <section role="h4">
+ <title>Broker Log Messages for quota flow control</title>
+ <para>
+ There are 2 new broker log messages that may occur if flow control through disk quota limits is enabled.
+ When the virtual host is blocked due to exceeding of the disk quota limit the following message
+ appears in the broker log
+ <programlisting>
+[vh(/test)/ms(BDBMessageStore)] MST-1008 : Store overfull, flow control will be enforced
+ </programlisting>
+ When virtual host is unblocked after cleaning the disk space the following message appears in the broker log
+ <programlisting>
+[vh(/test)/ms(BDBMessageStore)] MST-1009 : Store overfull condition cleared
+ </programlisting>
+ </para>
+ </section>
+ </section><!-- Disk quota-based flow control -->
+ </section><!-- Server configuration -->
+
+
+ <section role="h2" id="Java-Broker-Runtime-Disk-Space-Management-Producer-Flow-Control-ClientImpact">
+ <title>Client impact and configuration</title>
+ <para>
+ If a producer sends to a queue which is overfull, the broker will respond by
+ instructing the client not to send any more messages. The impact of this is
+ that any future attempts to send will block until the broker rescinds the flow control order.
+ </para>
+ <para>
+ While blocking the client will periodically log the fact that it is blocked waiting on flow control.
+ </para>
+ <programlisting>
+WARN Message send delayed by 5s due to broker enforced flow control
+WARN Message send delayed by 10s due to broker enforced flow control
+ </programlisting>
+ <para>
+ After a set period the send will timeout and throw a JMSException to the calling code.
+ </para>
+ <para>
+ If such a JMSException is thrown, the message will not be sent to the broker,
+ however the underlying Session may still be active - in particular if the
+ Session is transactional then the current transaction will not be automatically
+ rolled back. Users may choose to either attempt to resend the message, or to
+ roll back any transactional work and close the Session.
+ </para>
+ <para>
+ Both the timeout delay and the periodicity of the warning messages can be set
+ using Java system properties.
+ </para>
+ <para>
+ The amount of time (in milliseconds) to wait before timing out
+ is controlled by the property qpid.flow_control_wait_failure.
+ </para>
+ <para>
+ The frequency at which the log message informing that the producer is flow
+ controlled is sent is controlled by the system property qpid.flow_control_wait_notify_period.
+ </para>
+ <para>
+ Adding the following to the command line to start the client would result in a timeout of one minute,
+ with warning messages every ten seconds:
+ </para>
+ <programlisting>
+-Dqpid.flow_control_wait_failure=60000
+-Dqpid.flow_control_wait_notify_period=10000
+ </programlisting>
+ <section role="h3">
+ <title>Older Clients</title>
+ <para>
+ The flow control feature was first added to the Java broker/client in the 0.6 release. If an older client connects to the broker then the flow control commands will be ignored by it and it will not be blocked. So to fully benefit from this feature both Client and Broker need to be at least version 0.6.
+ </para>
+ </section>
+ </section> <!-- Client impact and configuration -->
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Runtime-Disk-Space-Management.xml b/doc/book/src/java-broker/Java-Broker-Runtime-Disk-Space-Management.xml
new file mode 100644
index 0000000000..814b366d9d
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Runtime-Disk-Space-Management.xml
@@ -0,0 +1,27 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Runtime-Disk-Space-Management">
+ <title>Disk Space Management</title>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Runtime-Disk-Space-Management-Producer-Flow-Control.xml"/>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Runtime-Handling-Undeliverable-Messages.xml b/doc/book/src/java-broker/Java-Broker-Runtime-Handling-Undeliverable-Messages.xml
new file mode 100644
index 0000000000..40c0e44629
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Runtime-Handling-Undeliverable-Messages.xml
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<section id="Java-Broker-Runtime-Handling-Undeliverable-Messages">
+ <title>Handing Undeliverable Messages</title>
+
+ <section role="h2" id="Java-Broker-Runtime-Handling-Undeliverable-Messages-Introduction">
+ <title>Introduction</title>
+ <para> Messages that cannot be delivered successfully to a consumer (for instance, because the
+ client is using a transacted session and rolls-back the transaction) can be made available on
+ the queue again and then subsequently be redelivered, depending on the precise session
+ acknowledgement mode and messaging model used by the application. This is normally desirable
+ behaviour that contributes to the ability of a system to withstand unexpected errors. However, it
+ leaves open the possibility for a message to be repeatedly redelivered (potentially indefinitely),
+ consuming system resources and preventing the delivery of other messages. Such undeliverable
+ messages are sometimes known as poison messages.</para>
+ <para>For an example, consider a stock ticker application that has been designed to consume prices
+ contained within JMS TextMessages. What if inadvertently a BytesMessage is placed onto the queue?
+ As the ticker application does not expect the BytesMessage, its processing might fail and cause it
+ to roll-back the transaction, however the default behavior of the Broker would mean that the
+ BytesMessage would be delivered over and over again, preventing the delivery of other legitimate
+ messages, until an operator intervenes and removes the erroneous message from the queue. </para>
+ <para>Qpid has maximum delivery count and dead-letter queue (DLQ) features which can be used in
+ concert to construct a system that automatically handles such a condition. These features are
+ described in the following sections.</para>
+ </section>
+
+ <section role="h2" id="Java-Broker-Runtime-Handling-Undeliverable-Messages-Maximum-Delivery-Count">
+ <title>Maximum Delivery Count</title>
+ <para> Maximum delivery count is a property of a queue. If a consumer application is unable to
+ process a message more than the specified number of times, then the broker will either route the
+ message to a dead-letter queue (if one has been defined), or will discard the message. </para>
+ <para> In order for a maximum delivery count to be enforced, the consuming client
+ <emphasis>must</emphasis> call <ulink url="&oracleJeeDocUrl;javax/jms/Session.html#rollback()"
+ >Session#rollback()</ulink> (or <ulink url="&oracleJeeDocUrl;javax/jms/Session.html#recover()"
+ >Session#recover()</ulink> if the session is not transacted). It is during the Broker's
+ processing of Session#rollback() (or Session#recover()) that if a message has been seen
+ at least the maximum number of times then it will move the message to the DLQ or discard the
+ message.</para>
+ <para>If the consuming client fails in another manner, for instance, closes the connection, the
+ message will not be re-routed and consumer application will see the same poison message again
+ once it reconnects.</para>
+ <para> If the consuming application is using AMQP 0-9-1, 0-9, or 0-8 protocols, it is necessary to
+ set the client system property <varname>qpid.reject.behaviour</varname> or connection or binding
+ URL option <varname>rejectbehaviour</varname> to the value <literal>system</literal>.</para>
+ <para>It is possible to determine the number of times a message has been sent to a consumer via
+ the Management interfaces, but is not possible to determine this information from a message client.
+ Specifically, the optional JMS message header <property>JMSXDeliveryCount</property> is not
+ supported.</para>
+ <para>Maximum Delivery Count can be enabled via management (see <xref
+ linkend="Java-Broker-Configuring-And-Managing"/>) using the the queue declare property
+ <property>x-qpid-maximum-delivery-count</property> or via <link
+ linkend="Java-Broker-Runtime-Handling-Undeliverable-Messages-Configuration">configuration</link>
+ as illustrated below.</para>
+ </section>
+
+ <section role="h2" id="Java-Broker-Runtime-Handling-Undeliverable-Messages-Dead-Letter-Queues">
+ <title>Dead Letter Queues (DLQ)</title>
+ <para>A Dead Letter Queue (DLQ) acts as an destination for messages that have somehow exceeded the
+ normal bounds of processing and is utilised to prevent disruption to flow of other messages. When
+ a DLQ is enabled for a given queue if a consuming client indicates it no longer wishes the
+ receive the message (typically by exceeding a Maximum Delivery Count) then the message is moved
+ onto the DLQ and removed from the original queue. </para>
+ <para>The DLQ feature causes generation of a Dead Letter Exchange and a Dead Letter Queue. These
+ are named convention QueueName<emphasis>_DLE</emphasis> and QueueName<emphasis>_DLQ</emphasis>.</para>
+ <para>DLQs can be enabled via management (see <xref linkend="Java-Broker-Configuring-And-Managing"
+ />) using the queue declare property <property>x-qpid-dlq-enabled</property> or via <link
+ linkend="Java-Broker-Runtime-Handling-Undeliverable-Messages-Configuration">configuration</link>
+ as illustrated below.</para>
+ <caution>
+ <title>Avoid excessive queue depth</title>
+ <para>Applications making use of DLQs <emphasis>should</emphasis> make provision for the frequent
+ examination of messages arriving on DLQs so that both corrective actions can be taken to resolve
+ the underlying cause and organise for their timely removal from the DLQ. Messages on DLQs
+ consume system resources in the same manner as messages on normal queues so excessive queue
+ depths should not be permitted to develop.</para>
+ </caution>
+ </section>
+
+ <section role="h2" id="Java-Broker-Runtime-Handling-Undeliverable-Messages-Configuration">
+ <title>Configuration</title>
+ <para>In the below configuration it can be seen that DLQs/Maximum Delivery Count are enabled at
+ the broker level with maximum delivery count set to 5, disabled at the virtualhost level for the
+ 'dev-only' virtualhost, and enabled specifically for the 'dev-only-main-queue' with maximum
+ delivery count overridden to 5. </para>
+ <para>As 'dev-only-main-queue' has its own configuration specified, this value overrides all
+ others and causes the features to be enabled for this queue. In contrast to this,
+ 'dev-only-other-queue' does not specify its own value and picks up the false value specified for
+ its parent virtualhost, causing the DLQ/Maximum Delivery Count features to be disabled for this
+ queue. Any such queue in the 'dev-only' virtualhost which does not specify its own configuration
+ value will have the DLQ/Maximum Delivery Count feature disabled.</para>
+ <para>The queue 'localhost-queue' has the DLQ/Maximum Delivery Count features enabled, as neither
+ the queue itself or the 'localhost' virtualhost specifies a configuration value and so the broker
+ level value of true is used. Any such queue in the 'localhost' virtualhost which does not specify
+ its own configuration value will have the features enabled.</para>
+ <example>
+ <title>Enabling DLQs and maximum delivery count at broker level within config.xml</title>
+ <programlisting><![CDATA[<broker>
+ ...
+ <deadLetterQueues>true</deadLetterQueues>
+ <maximumDeliveryCount>5</maximumDeliveryCount>
+ ...
+</broker>]]></programlisting>
+ </example>
+ <example>
+ <title>Enabling DLQs and maximum delivery count at virtualhost and queue level within
+ virtualhosts.xml</title>
+ <programlisting><![CDATA[<virtualhosts>
+ ...
+ <virtualhost>
+ <name>dev-only</name>
+ <dev-only>
+ <queues>
+ <deadLetterQueues>false</deadLetterQueues>
+ <maximumDeliveryCount>0</maximumDeliveryCount>
+ <queue>
+ <name>dev-only-main-queue</name>
+ <dev-only-main-queue>
+ <deadLetterQueues>true</deadLetterQueues>
+ <maximumDeliveryCount>3</maximumDeliveryCount>
+ </dev-only-main-queue>
+ </queue>
+ <queue>
+ <name>dev-only-other-queue</name>
+ </queue>
+ </queues>
+ </dev-only>
+ </virtualhost>
+ <virtualhost>
+ <name>localhost</name>
+ <localhost>
+ <queues>
+ <queue>
+ <name>localhost-queue</name>
+ </queue>
+ </queues>
+ </localhost>
+ </virtualhost>
+ ...
+</virtualhosts>]]>
+ </programlisting>
+ </example>
+ </section>
+
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Runtime-Log-Files.xml b/doc/book/src/java-broker/Java-Broker-Runtime-Log-Files.xml
new file mode 100644
index 0000000000..84ee4db6d3
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Runtime-Log-Files.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Runtime-Log-Files">
+<title>Log Files</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Runtime-Producer-Transaction-Timeout.xml b/doc/book/src/java-broker/Java-Broker-Runtime-Producer-Transaction-Timeout.xml
new file mode 100644
index 0000000000..04212d94ed
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Runtime-Producer-Transaction-Timeout.xml
@@ -0,0 +1,181 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<section id="Java-Broker-Runtime-Producer-Transaction-Timeout">
+ <title>Producer Transaction Timeout</title>
+ <section role="h2" id="Java-Broker-Runtime-Producer-Transaction-Timeout-GeneralInformation">
+ <title>General Information</title>
+ <para> The transaction timeout mechanism is used to control broker resources when clients
+ producing messages using transactional sessions hang or otherwise become unresponsive, or simply
+ begin a transaction and keep using it without ever calling <ulink
+ url="&oracleJeeDocUrl;javax/jms/Session.html#commit">Session#commit()</ulink>.</para>
+ <para>Users can choose to configure an idleWarn or openWarn threshold, after which the identified
+ transaction should be logged as a WARN level alert as well as (more importantly) an idleClose or
+ openClose threshold after which the transaction and the connection it applies to will be
+ closed.</para>
+ <para>This feature is particularly useful in environments where the owner of the broker does not
+ have full control over the implementation of clients, such as in a shared services
+ deployment.</para>
+ <para>The following section provide more details on this feature and its use.</para>
+ </section>
+ <section role="h2" id="Java-Broker-Runtime-Producer-Transaction-Timeout-Purpose">
+ <title>Purpose</title>
+ <para> This feature has been introduced to address the scenario where an open transaction on the
+ broker holds an open transaction on the persistent store. This can have undesirable consequences
+ if the store does not time out or close long-running transactions, such as with <link
+ linkend="Java-Broker-Stores-BDB-Store">BDB</link>. This can can result in a rapid increase in
+ disk usage size, bounded only by available space, due to growth of the transaction log. </para>
+ </section>
+ <section role="h2" id="Java-Broker-Runtime-Producer-Transaction-Timeout-Scope">
+ <title>Scope</title>
+ <para>Note that only <ulink url="&oracleJeeDocUrl;javax/jms/MessageProducer.html"
+ >MessageProducer</ulink> clients will be affected by a transaction timeout, since store
+ transaction lifespan on a consumer only spans the execution of the call to Session#commit() and
+ there is no scope for a long-lived transaction to arise.</para>
+ <para>It is also important to note that the transaction timeout mechanism is purely a JMS
+ transaction timeout, and unrelated to any other timeouts in the Qpid client library and will have
+ no impact on any RDBMS your application may utilise.</para>
+ </section>
+ <section role="h2" id="Java-Broker-Runtime-Producer-Transaction-Timeout-Effect">
+ <title>Effect</title>
+ <para>Full details of configuration options are provided in the sections that follow. This section
+ gives a brief overview of what the Transaction Timeout feature can do.</para>
+ <section role="h3" id="Java-Broker-Runtime-Producer-Transaction-Timeout-Effect-Broker-Side">
+ <title>Broker Logging and Connection Close</title>
+ <para>When the openWarn or idleWarn specified threshold is exceeded, the broker will log a WARN
+ level alert with details of the connection and channel on which the threshold has been exceeded,
+ along with the age of the transaction.</para>
+ <para>When the openClose or idleClose specified threshold value is exceeded, the broker will
+ throw an exception back to the client connection via the <ulink
+ url="&oracleJeeDocUrl;javax/jms/ExceptionListener.html">ExceptionListener</ulink>, log the
+ action and then close the connection.</para>
+ <para>The example broker log output shown below is where the idleWarn threshold specified is
+ lower than the idleClose threshold and the broker therefore logs the idle transaction 3 times
+ before the close threshold is triggered and the connection closed out.</para>
+ <screen><![CDATA[CHN-1008 : Idle Transaction : 13,116 ms
+CHN-1008 : Idle Transaction : 14,116 ms
+CHN-1008 : Idle Transaction : 15,118 ms
+CHN-1003 : Close]]>
+ </screen>
+ <para>The second example broker log output shown below illustrates the same mechanism operating
+ on an open transaction.</para>
+ <screen><![CDATA[
+CHN-1007 : Open Transaction : 12,406 ms
+CHN-1007 : Open Transaction : 13,406 ms
+CHN-1007 : Open Transaction : 14,406 ms
+CHN-1003 : Close]]>
+ </screen>
+ </section>
+ <section role="h3" id="Java-Broker-Runtime-Producer-Transaction-Timeout-Effect-Client-Side">
+ <title>Client Side Effect</title>
+ <para>After a Close threshold has been exceeded, the trigger client will receive this exception
+ on its <ulink url="&oracleJeeDocUrl;javax/jms/ExceptionListener.html">exception
+ listener</ulink>, prior to being disconnected:</para>
+ <computeroutput>org.apache.qpid.AMQConnectionClosedException: Error: Idle transaction timed out
+ [error code 506: resource error]</computeroutput>
+ <para>Any later attempt to use the connection will result in this exception being thrown:</para>
+ <screen><![CDATA[Producer: Caught an Exception: javax.jms.IllegalStateException: Object org.apache.qpid.client.AMQSession_0_8@129b0e1 has been closed
+ javax.jms.IllegalStateException: Object org.apache.qpid.client.AMQSession_0_8@129b0e1 has been closed
+ at org.apache.qpid.client.Closeable.checkNotClosed(Closeable.java:70)
+ at org.apache.qpid.client.AMQSession.checkNotClosed(AMQSession.java:555)
+ at org.apache.qpid.client.AMQSession.createBytesMessage(AMQSession.java:573)]]>
+ </screen>
+ <para>Thus clients must be able to handle this case successfully, reconnecting where required and
+ registering an exception listener on all connections. This is critical, and must be communicated
+ to client applications by any broker owner switching on transaction timeouts.</para>
+ </section>
+
+ </section>
+ <section role="h2" id="Java-Broker-Runtime-Producer-Transaction-Timeout-Configuration">
+ <title>Configuration</title>
+ <section role="h3" id="Java-Broker-Runtime-Producer-Transaction-Timeout-Configuration-Overview">
+ <title>Configuration</title>
+ <para>Transaction timeouts are configurable separately on each defined virtual host, using the
+ virtualhosts.xml file.</para>
+ <para>We would recommend that only warnings are configured at first, which should allow broker
+ administrators to obtain an idea of the distribution of transaction lengths on their systems,
+ and configure production settings appropriately for both warning and closure. Ideally
+ establishing thresholds should be achieved in a representative UAT environment, with clients and
+ broker running, prior to any production deployment.</para>
+ <para>It is impossible to give suggested values, due to the large variation in usage depending on
+ the applications using a broker. However, clearly transactions should not span the expected
+ lifetime of any client application as this would indicate a hung client.</para>
+ <para>When configuring warning and closure timeouts, it should be noted that these only apply to
+ message producers that are connected to the broker, but that a timeout will cause the connection
+ to be closed - this disconnecting all producers and consumers created on that connection.</para>
+ <para>This should not be an issue for environments using Mule or Spring, where connection
+ factories can be configured appropriately to manage a single MessageProducer object per JMS
+ Session and Connection. Clients that use the JMS API directly should be aware that sessions
+ managing both consumers and producers, or multiple producers, will be affected by a single
+ producer hanging or leaving a transaction idle or open, and closed, and must take appropriate
+ action to handle that scenario.</para>
+ </section>
+ <section role="h3"
+ id="Java-Broker-Runtime-Producer-Transaction-Timeout-Configuration-Virtualhosts">
+ <title>Virtualhosts.xml</title>
+ <para> The JMS transaction timeouts are configured on each virtual host defined in the XML
+ configuration files.</para>
+ <para> The default values for each of the parameters is 0, indicating that the particular check
+ is disabled.</para>
+ <para> Any or all of the parameters can be set, using the desired value in milliseconds, and will
+ be checked each time the housekeeping process runs, usually set to run every 30 seconds in
+ standard configuration. The meaning of each property is as follows:</para>
+ <para>
+ <itemizedlist>
+ <listitem>
+ <para>openWarn - the time a transaction can be open for (with activity occurring on it) after
+ which a warning alert will be issued.</para>
+ </listitem>
+ <listitem>
+ <para>openClose - the time a transaction can be open for before the connection it is on is
+ closed.</para>
+ </listitem>
+ <listitem>
+ <para>idleWarn - the time a transaction can be idle for (with no activity occurring on it)
+ after which a warning alert will be issued.</para>
+ </listitem>
+ <listitem>
+ <para>idleClose - the time a transaction can be idle for before the connection it is on is
+ closed.</para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ <para> The virtualhosts configuration is shown below, and must occur inside the
+ //virtualhosts/virtualhost/name/ elements: </para>
+ <example>
+<title>Configuring producer transaction timeout</title>
+ <programlisting><![CDATA[
+<transactionTimeout>
+ <openWarn>10000</openWarn>
+ <openClose>20000</openClose>
+ <idleWarn>5000</idleWarn>
+ <idleClose>15000</idleClose>
+</transactionTimeout>
+ ]]></programlisting>
+ </example>
+ </section>
+ </section>
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Runtime.xml b/doc/book/src/java-broker/Java-Broker-Runtime.xml
new file mode 100644
index 0000000000..2af775d2fc
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Runtime.xml
@@ -0,0 +1,30 @@
+<?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.
+
+-->
+
+<chapter id="Java-Broker-Runtime">
+ <title>Runtime</title>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Runtime-Log-Files.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Runtime-Alerts.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Runtime-Disk-Space-Management.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Runtime-Producer-Transaction-Timeout.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Runtime-Handling-Undeliverable-Messages.xml"/>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Security-ACLs.xml b/doc/book/src/java-broker/Java-Broker-Security-ACLs.xml
new file mode 100644
index 0000000000..21e1052183
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Security-ACLs.xml
@@ -0,0 +1,536 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Security-ACLs">
+ <title>Access Control Lists</title>
+ <para>
+ In Qpid, Access Control Lists (ACLs) specify which actions can be performed by each authenticated user.
+ To enable, the &lt;acl/&gt; element is used within the &lt;security/&gt; element of the configuration XML.
+ In the Java Broker, the ACL may be imposed broker wide or applied to individual virtual
+ hosts. The &lt;acl/&gt; configuration references a text file containing the ACL rules.
+ By convention, this file should have a .acl extension.
+ </para>
+
+
+ <section role="h3" id="Java-Broker-Security-ACLs-EnablingACL">
+ <title>
+ Enabling ACLs
+ </title>
+
+ <para>
+ To apply an ACL broker-wide, add the following to the config.xml (assuming that <replaceable>conf</replaceable> has been set to a suitable
+ location such as ${QPID_HOME}/etc):
+ </para>
+
+ <programlisting>
+ &lt;broker&gt;
+ ...
+ &lt;security&gt;
+ ...
+ &lt;acl&gt;<replaceable>${conf}/broker.acl</replaceable>&lt;/acl&gt;
+ &lt;/security&gt;
+ &lt;/broker&gt;
+ </programlisting>
+
+ <para>
+ </para>
+
+ <para>
+ To apply an ACL on a single virtualhost named <replaceable>test</replaceable>, add the following to the config.xml:
+ </para>
+
+ <programlisting>
+ &lt;virtualhost&gt;
+ ...
+ &lt;name&gt;test&lt;/name&gt;
+ &lt;test&gt;
+ ...
+ &lt;security&gt;
+ &lt;acl&gt;<replaceable>${conf}/vhost_test.acl</replaceable>&lt;/acl&gt;
+ &lt;/security&gt;
+ &lt;/test&gt;
+ &lt;/virtualhost&gt;
+ </programlisting>
+ </section>
+
+ <section role="h3" id="Java-Broker-Security-ACLs-WriteACL">
+ <title>
+ Writing .acl files
+ </title>
+
+ <para>
+ The ACL file consists of a series of rules associating behaviour for a user or group. Use of groups can serve to make the ACL file more concise. See <link linkend="Java-Broker-Security-Group-Providers">Configuring Group Providers</link> for more information on defining groups.
+ </para>
+ <para>
+ Each ACL rule grants or denies a particular action on an object to a user/group. The rule may be augmented with one or more properties, restricting
+ the rule's applicability.
+ </para>
+ <programlisting>
+ ACL ALLOW alice CREATE QUEUE # Grants alice permission to create all queues.
+ ACL DENY bob CREATE QUEUE name="myqueue" # Denies bob permission to create a queue called "myqueue"
+ </programlisting>
+ <para>
+ The ACL is considered in strict line order with the first matching rule taking precedence over all those that follow. In the following
+ example, if the user bob tries to create an exchange "myexch", the operation will be allowed by the first rule. The second rule will
+ never be considered.
+ </para>
+ <programlisting>
+ ACL ALLOW bob ALL EXCHANGE
+ ACL DENY bob CREATE EXCHANGE name="myexch" # Dead rule
+ </programlisting>
+ <para>
+ If the desire is to allow bob to create all exchanges except "myexch", order of the rules must be reversed:
+ </para>
+ <programlisting>
+ ACL DENY bob CREATE EXCHANGE name="myexch"
+ ACL ALLOW bob ALL EXCHANGE
+ </programlisting>
+ <para>
+ All ACL files end with an implict rule denying all operations to all users. It is as if each file ends with
+ <programlisting>ACL DENY ALL ALL </programlisting>
+ If instead you wish to <emphasis>allow</emphasis> all operations other than those controlled by earlier rules,
+ add <programlisting>ACL ALLOW ALL ALL</programlisting> to the bottom of the ACL file.
+ </para>
+ <para>
+ When writing a new ACL, a good approach is to begin with an .acl file containing only <programlisting>ACL DENY-LOG ALL ALL</programlisting>
+ which will cause the Broker to deny all operations with details of the denial logged to the Qpid log file. Build up the ACL rule by rule,
+ gradually working through the use-cases of your system. Once the ACL is complete, consider switching the DENY-LOG actions to DENY
+ to improve performamce and reduce log noise.
+ </para>
+ <para>
+ ACL rules are very powerful: it is possible to write very granular rules specifying many broker objects and their
+ properties. Most projects probably won't need this degree of flexibility. A reasonable approach is to choose to apply permissions
+ at a certain level of abstraction (e.g. QUEUE) and apply them consistently across the whole system.
+ </para>
+ </section>
+
+ <section role="h4" id="Java-Broker-Security-ACLs-Syntax">
+ <title>
+ Syntax
+ </title>
+
+ <para>
+ ACL rules follow this syntax:
+ </para>
+ <programlisting>
+ ACL {permission} {&lt;group-name&gt;|&lt;user-name>&gt;|ALL} {action|ALL} [object|ALL] [property="&lt;property-value&gt;"]
+ </programlisting>
+
+ <para>
+ Comments may be introduced with the hash (#) character and are ignored. Long lines can be broken with the slash (\) character.
+ </para>
+ <programlisting>
+ # A comment
+ ACL ALLOW admin CREATE ALL # Also a comment
+ ACL DENY guest \
+ ALL ALL # A broken line
+ </programlisting>
+ </section>
+ <table id="table-Java-Broker-Security-ACLs-Syntax_permissions">
+ <title>List of ACL permission</title>
+ <tgroup cols="2">
+ <tbody>
+ <row>
+ <entry><command>ALLOW</command></entry>
+ <entry><para>Allow the action</para></entry>
+ </row>
+ <row>
+ <entry><command>ALLOW-LOG</command></entry>
+ <entry><para> Allow the action and log the action in the log </para></entry>
+ </row>
+ <row>
+ <entry><command>DENY</command></entry>
+ <entry><para> Deny the action</para></entry>
+ </row>
+ <row>
+ <entry><command>DENY-LOG</command></entry>
+ <entry><para> Deny the action and log the action in the log</para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <table id="table-Java-Broker-Security-ACLs-Syntax_actions">
+ <title>List of ACL actions</title>
+ <tgroup cols="2">
+ <tbody>
+ <row>
+ <entry> <command>CONSUME</command> </entry>
+ <entry> <para> Applied when subscriptions are created </para> </entry>
+ </row>
+ <row>
+ <entry> <command>PUBLISH</command> </entry>
+ <entry> <para> Applied on a per message basis on publish message transfers</para> </entry>
+ </row>
+ <row>
+ <entry> <command>CREATE</command> </entry>
+ <entry> <para> Applied when an object is created, such as bindings, queues, exchanges</para> </entry>
+ </row>
+ <row>
+ <entry> <command>ACCESS</command> </entry>
+ <entry> <para> Applied when an object is read or accessed</para> </entry>
+ </row>
+ <row>
+ <entry> <command>BIND</command> </entry>
+ <entry> <para> Applied when queues are bound to exchanges</para> </entry>
+ </row>
+ <row>
+ <entry> <command>UNBIND</command> </entry>
+ <entry> <para> Applied when queues are unbound from exchanges</para> </entry>
+ </row>
+ <row>
+ <entry> <command>DELETE</command> </entry>
+ <entry> <para> Applied when objects are deleted </para> </entry>
+ </row>
+ <row>
+ <entry> <command>PURGE</command> </entry> <entry>
+ <para>Applied when purge the contents of a queue</para> </entry>
+ </row>
+ <row>
+ <entry> <command>UPDATE</command> </entry>
+ <entry> <para> Applied when an object is updated </para> </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <table id="table-Java-Broker-Security-ACLs-Syntax_objects">
+ <title>List of ACL objects</title>
+ <tgroup cols="2">
+ <tbody>
+ <row>
+ <entry> <command>VIRTUALHOST</command> </entry>
+ <entry> <para>A virtualhost (Java Broker only)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>MANAGEMENT </command> </entry>
+ <entry> <para>Management - for web and JMX (Java Broker only)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>QUEUE</command> </entry>
+ <entry> <para>A queue </para> </entry>
+ </row>
+ <row>
+ <entry> <command>EXCHANGE</command> </entry>
+ <entry> <para>An exchange </para> </entry>
+ </row>
+ <row>
+ <entry> <command>USER</command> </entry>
+ <entry> <para>A user (Java Broker only)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>GROUP</command> </entry>
+ <entry> <para>A group (Java Broker only)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>METHOD</command> </entry>
+ <entry> <para>Management or agent or broker method (Java Broker only)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>LINK</command> </entry>
+ <entry> <para>A federation or inter-broker link (not currently used in Java Broker)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>BROKER</command> </entry>
+ <entry> <para>The broker (not currently used in Java Broker)</para> </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <table id="table-Java-Broker-Security-ACLs-Syntax_properties">
+ <title>List of ACL properties</title>
+ <tgroup cols="2">
+ <tbody>
+ <row>
+ <entry><command>name</command> </entry>
+ <entry> <para> String. Object name, such as a queue name, exchange name or JMX method name. </para> </entry>
+ </row>
+ <row>
+ <entry> <command>durable</command> </entry>
+ <entry> <para> Boolean. Indicates the object is durable </para> </entry>
+ </row>
+ <row>
+ <entry> <command>routingkey</command> </entry>
+ <entry> <para> String. Specifies routing key </para> </entry>
+ </row>
+ <row>
+ <entry> <command>passive</command> </entry>
+ <entry> <para> Boolean. Indicates the presence of a <parameter>passive</parameter> flag </para> </entry>
+ </row>
+ <row>
+ <entry> <command>autodelete</command> </entry>
+ <entry> <para> Boolean. Indicates whether or not the object gets deleted when the connection is closed </para> </entry>
+ </row>
+ <row>
+ <entry> <command>exclusive</command> </entry>
+ <entry> <para> Boolean. Indicates the presence of an <parameter>exclusive</parameter> flag </para> </entry>
+ </row>
+ <row>
+ <entry> <command>temporary</command> </entry>
+ <entry> <para> Boolean. Indicates the presence of an <parameter>temporary</parameter> flag </para> </entry>
+ </row>
+ <row>
+ <entry> <command>type</command> </entry>
+ <entry> <para> String. Type of object, such as topic, fanout, or xml </para> </entry>
+ </row>
+ <row>
+ <entry> <command>alternate</command> </entry>
+ <entry> <para> String. Name of the alternate exchange </para> </entry>
+ </row>
+ <row>
+ <entry> <command>queuename</command> </entry>
+ <entry> <para> String. Name of the queue (used only when the object is something other than <parameter>queue</parameter> </para> </entry>
+ </row>
+ <row>
+ <entry> <command>component</command> </entry>
+ <entry> <para> String. JMX component name (Java Broker only)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>schemapackage</command> </entry>
+ <entry> <para> String. QMF schema package name (Not used in Java Broker)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>schemaclass</command> </entry>
+ <entry> <para> String. QMF schema class name (Not used in Java Broker)</para> </entry>
+ </row>
+ <row>
+ <entry> <command>from_network</command> </entry>
+ <entry>
+ <para>
+ Comma-separated strings representing IPv4 address ranges.
+ </para>
+ <para>
+ Intended for use in ACCESS VIRTUALHOST rules to apply firewall-like restrictions.
+ </para>
+ <para>
+ The rule matches if any of the address ranges match the IPv4 address of the messaging client.
+ The address ranges are specified using either Classless Inter-Domain Routing notation
+ (e.g. 192.168.1.0/24; see <ulink url="http://tools.ietf.org/html/rfc4632">RFC 4632</ulink>)
+ or wildcards (e.g. 192.169.1.*).
+ </para>
+ <para>
+ Java Broker only.
+ </para>
+ </entry>
+ </row>
+ <row>
+ <entry> <command>from_hostname</command> </entry>
+ <entry>
+ <para>
+ Comma-separated strings representing hostnames, specified using Perl-style regular
+ expressions, e.g. .*\.example\.company\.com
+ </para>
+ <para>
+ Intended for use in ACCESS VIRTUALHOST rules to apply firewall-like restrictions.
+ </para>
+ <para>
+ The rule matches if any of the patterns match the hostname of the messaging client.
+ </para>
+ <para>
+ To look up the client's hostname, Qpid uses Java's DNS support, which internally caches its results.
+ </para>
+ <para>
+ You can modify the time-to-live of cached results using the *.ttl properties described on the
+ Java <ulink url="http://docs.oracle.com/javase/6/docs/technotes/guides/net/properties.html">Networking
+ Properties</ulink> page.
+ </para>
+ <para>
+ For example, you can either set system property sun.net.inetaddr.ttl from the command line
+ (e.g. export QPID_OPTS="-Dsun.net.inetaddr.ttl=0") or networkaddress.cache.ttl in
+ $JAVA_HOME/lib/security/java.security. The latter is preferred because it is JVM
+ vendor-independent.
+ </para>
+ <para>
+ Java Broker only.
+ </para>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <table id="table-Java-Broker-Security-ACLs-Syntax_javacomponents">
+ <title>List of ACL rules</title>
+ <tgroup cols="3">
+ <tbody>
+ <row>
+ <entry> <command>UserManagement</command> </entry>
+ <entry> <para>User maintainance; create/delete/view users, change passwords etc</para> </entry>
+ <entry> <para>permissionable at broker level only</para> </entry>
+ </row>
+ <row>
+ <entry> <command>ConfigurationManagement</command> </entry>
+ <entry> <para>Dynammically reload configuration from disk.</para> </entry>
+ <entry> <para>permissionable at broker level only</para> </entry>
+ </row>
+ <row>
+ <entry> <command>LoggingManagement</command> </entry>
+ <entry> <para>Dynammically control Qpid logging level</para> </entry>
+ <entry> <para>permissionable at broker level only</para> </entry>
+ </row>
+ <row>
+ <entry> <command>ServerInformation</command> </entry>
+ <entry> <para>Read-only information regarding the Qpid: version number etc</para> </entry>
+ <entry> <para>permissionable at broker level only</para> </entry>
+ </row>
+ <row>
+ <entry> <command>VirtualHost.Queue</command> </entry>
+ <entry> <para>Queue maintainance; copy/move/purge/view etc</para> </entry>
+ </row>
+ <row>
+ <entry> <command>VirtualHost.Exchange</command> </entry>
+ <entry> <para>Exchange maintenance; bind/unbind queues to exchanges</para> </entry>
+ </row>
+ <row>
+ <entry> <command>VirtualHost.VirtualHost</command> </entry>
+ <entry> <para>Virtual host maintainace; create/delete exchanges, queues etc</para> </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <section role="h4" id="Java-Broker-Security-ACLs-WorkedExamples">
+ <title>
+ Worked Examples
+ </title>
+ <para>
+ Here are some example ACLs illustrating common use cases.
+ In addition, note that the Java broker provides a complete example ACL file, located at etc/broker_example.acl.
+ </para>
+ <section role="h4" id="Java-Broker-Security-ACLs-WorkedExample1">
+ <title>
+ Worked example 1 - Management rights
+ </title>
+ <para>
+ Suppose you wish to permission two users: a user 'operator' must be able to perform all Management operations, and
+ a user 'readonly' must be enable to perform only read-only functions. Neither 'operator' nor 'readonly'
+ should be allowed to connect clients for messaging.
+ </para>
+ <programlisting>
+# Deny (loggged) operator/readonly permission to connect messaging clients.
+ACL DENY-LOG operator ACCESS VIRTUALHOST
+ACL DENY-LOG readonly ACCESS VIRTUALHOST
+# Give operator permission to perfom all other actions
+ACL ALLOW operator ALL ALL
+# Give readonly permission to execute only read-only actions
+ACL ALLOW readonly ACCESS ALL
+...
+... rules for other users
+...
+# Explicitly deny all (log) to eveyone
+ACL DENY-LOG ALL ALL
+ </programlisting>
+ </section>
+ <section role="h4" id="Java-Broker-Security-ACLs-WorkedExample2">
+ <title>
+ Worked example 2 - User maintainer group
+ </title>
+ <para>
+ Suppose you wish to restrict User Management operations to users belonging to a
+ <link linkend="Java-Broker-Security-Group-Providers">group</link> 'usermaint'. No other user
+ is allowed to perform user maintainence This example illustrates the permissioning of an individual component.
+ </para>
+ <programlisting>
+# Give usermaint access to management and permission to execute all JMX Methods on the
+# UserManagement MBean and perform all actions for USER objects
+ACL ALLOW usermaint ACCESS MANAGEMENT
+ACL ALLOW usermaint ALL METHOD component="UserManagement"
+ACL ALLOW usermaint ALL USER
+ACL DENY ALL ALL METHOD component="UserManagement"
+ACL DENY ALL ALL USER
+...
+... rules for other users
+...
+ACL DENY-LOG ALL ALL
+ </programlisting>
+ </section>
+ <section role="h4" id="Java-Broker-Security-ACLs-WorkedExample3">
+ <title>
+ Worked example 3 - Request/Response messaging
+ </title>
+ <para>
+ Suppose you wish to permission a system using a request/response paradigm. Two users: 'client' publishes requests;
+ 'server' consumes the requests and generates a response. This example illustrates the permissioning of AMQP exchanges
+ and queues.
+ </para>
+ <programlisting>
+# Allow client and server to connect to the virtual host.
+ACL ALLOW client ACCESS VIRTUALHOST
+ACL ALLOW server ACCESS VIRTUALHOST
+
+# Client side
+# Allow the 'client' user to publish requests to the request queue. As is the norm for the request/response paradigm, the client
+# is required to create a temporary queue on which the server will respond. Consequently, there are rules to allow the creation
+# of the temporary queues and consumption of messages from it.
+ACL ALLOW client CREATE QUEUE temporary="true"
+ACL ALLOW client CONSUME QUEUE temporary="true"
+ACL ALLOW client DELETE QUEUE temporary="true"
+ACL ALLOW client BIND EXCHANGE name="amq.direct" temporary="true"
+ACL ALLOW client UNBIND EXCHANGE name="amq.direct" temporary="true"
+ACL ALLOW client PUBLISH EXCHANGE name="amq.direct" routingKey="example.RequestQueue"
+
+# Server side
+# Allow the 'server' user to consume from the request queue and publish a response to the temporary response queue created by
+# client. We also allow the server to create the request queue.
+ACL ALLOW server CREATE QUEUE name="example.RequestQueue"
+ACL ALLOW server CONSUME QUEUE name="example.RequestQueue"
+ACL ALLOW server BIND EXCHANGE
+ACL ALLOW server PUBLISH EXCHANGE name="amq.direct" routingKey="TempQueue*"
+
+ACL DENY-LOG all all
+ </programlisting>
+ </section>
+ <section role="h4" id="Java-Broker-Security-ACLs-WorkedExample4">
+ <title>
+ Worked example 4 - firewall-like access control
+ </title>
+ <para>
+ This example illustrates how to set up an ACL that restricts the IP addresses and hostnames
+ of messaging clients that can access a virtual host.
+ </para>
+ <programlisting>
+################
+# Hostname rules
+################
+
+# Allow messaging clients from company1.com and company1.co.uk to connect
+ACL ALLOW all ACCESS VIRTUALHOST from_hostname=".*\.company1\.com,.*\.company1\.co\.uk"
+
+# Deny messaging clients from hosts within the dev subdomain
+ACL DENY-LOG all ACCESS VIRTUALHOST from_hostname=".*\.dev\.company1\.com"
+
+##################
+# IP address rules
+##################
+
+# Deny access to all users in the IP ranges 192.168.1.0-192.168.1.255 and 192.168.2.0-192.168.2.255,
+# using the notation specified in RFC 4632, "Classless Inter-domain Routing (CIDR)"
+ACL DENY-LOG messaging-users ACCESS VIRTUALHOST \
+ from_network="192.168.1.0/24,192.168.2.0/24"
+
+# Deny access to all users in the IP ranges 192.169.1.0-192.169.1.255 and 192.169.2.0-192.169.2.255,
+# using wildcard notation.
+ACL DENY-LOG messaging-users ACCESS VIRTUALHOST \
+ from_network="192.169.1.*,192.169.2.*"
+
+ACL DENY-LOG all all
+ </programlisting>
+ </section>
+ </section>
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Security-Authentication-Providers.xml b/doc/book/src/java-broker/Java-Broker-Security-Authentication-Providers.xml
new file mode 100644
index 0000000000..0974441ae5
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Security-Authentication-Providers.xml
@@ -0,0 +1,320 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Security-Authentication-Providers">
+ <title>Authentication Providers</title>
+ <para>
+ In order to successfully establish a connection to the Java Broker, the connection must be
+ authenticated. The Java Broker supports a number of different authentication schemes, each
+ with its own "authentication manager". Each of these are outlined below, along with details
+ of <link linkend="MultipleAuthProviders"> using more than one at a time</link>.
+ </para>
+
+ <section>
+ <title>Password File</title>
+ <para>
+ TODO
+ </para>
+
+ </section>
+
+ <section id="LDAPAuthManager">
+ <title>LDAP</title>
+
+ <para>
+ LDAP authentication can be configured using the &lt;simple-ldap-auth-manager&gt; element
+ within the &lt;security&gt; section. An example of how to configure this is shown below.
+ Please note this example also configures an unused &lt;pd-auth-manager&gt; to use an empty
+ password file, this is a workaround for an issue relating to registration of security providers.
+ </para>
+
+ <para>
+ <emphasis>NOTE: When using LDAP authentication, you must also use SSL on the brokers AMQP messaging and
+ JMX/HTTP management ports in order to protect passwords during transmission to the broker.</emphasis>
+ </para>
+ <example>
+ <title>Configuring LDAP authentication</title>
+ <programlisting><![CDATA[
+<security>
+ <default-auth-manager>SimpleLDAPAuthenticationManager</default-auth-manager>
+ <simple-ldap-auth-manager>
+ <provider-url>ldaps://example.com:636/</provider-url>
+ <search-context>dc=example\,dc=com</search-context>
+ <search-filter>(uid={0})</search-filter>
+ </simple-ldap-auth-manager>
+
+ <!-- Unused pd-auth-manager, a workaround to register the necessary security providers -->
+ <pd-auth-manager>
+ <principal-database>
+ <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
+ <attributes>
+ <attribute>
+ <name>passwordFile</name>
+ <value>${conf}/emptyPasswdFile</value>
+ </attribute>
+ </attributes>
+ </principal-database>
+ <pd-auth-manager>
+ ...
+</security>]]></programlisting>
+ </example>
+
+ <para>
+ The authentication manager first connects to the ldap server anonymously and searches for the
+ ldap entity which is identified by the username provided over SASL. Essentially the
+ authentication manager calls
+ DirContext.search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons)
+ with the values of search-context and search-filter as the first two arguments, and the username
+ as the only element in the array which is the third argument.
+ </para>
+
+ <para>
+ If the search returns a name from the LDAP server, the AuthenticationManager then attempts to
+ login to the ldap server with the given name and the password.
+ </para>
+
+ <para>
+ If the URL to open for authentication is different to that for the search, then the
+ authentication url can be overridden using &lt;provider-auth-url&gt; in addition to providing a
+ &lt;provider-url&gt;. Note that the URL used for authentication should use ldaps:// since
+ passwords will be being sent over it.
+ </para>
+
+ <para>
+ By default com.sun.jndi.ldap.LdapCtxFactory is used to create the context, however this can be
+ overridden by specifying &lt;ldap-context-factory&gt; in the configuration.
+ </para>
+ </section>
+
+ <section>
+ <title>Kerberos</title>
+
+ <para>
+ Kereberos Authentication is configured using the &lt;kerberos-auth-manager&gt; element within
+ the &lt;security&gt; section. When referencing from the default-auth-manager or port-mapping
+ sections, its name is KerberosAuthenticationManager.
+ </para>
+
+ <para>
+ Since Kerberos support only works where SASL authentication is available (e.g. not for JMX
+ authentication) you may wish to also include an alternative Authentication Manager
+ configuration, and use this for other ports:
+ </para>
+
+ <example>
+ <title>Configuring Kerberos authentication</title>
+ <programlisting><![CDATA[
+<security>
+ <pd-auth-manager>
+ <principal-database>
+ <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
+ <attributes>
+ <attribute>
+ <name>passwordFile</name>
+ <value>${conf}/passwd</value>
+ </attribute>
+ </attributes>
+ </principal-database>
+ </pd-auth-manager>
+ <kerberos-auth-manager/>
+ <default-auth-manager>PrincipalDatabaseAuthenticationManager</default-auth-manager>
+ <port-mappings>
+ <port-mapping>
+ <port>5672</port>
+ <auth-manager>KerberosAuthenticationManager</auth-manager>
+ </port-mapping>
+ </port-mappings>
+ ...
+</security>]]></programlisting>
+ </example>
+
+ <para>
+ Configuration of kerberos is done through system properties (there doesn't seem to be a way
+ around this unfortunately).
+ </para>
+
+ <programlisting>
+ export QPID_OPTS=-Djavax.security.auth.useSubjectCredsOnly=false -Djava.security.auth.login.config=qpid.conf
+ ${QPID_HOME}/bin/qpid-server
+ </programlisting>
+
+ <para>Where qpid.conf would look something like this:</para>
+
+ <programlisting><![CDATA[
+com.sun.security.jgss.accept {
+ com.sun.security.auth.module.Krb5LoginModule required
+ useKeyTab=true
+ storeKey=true
+ doNotPrompt=true
+ realm="EXAMPLE.COM"
+ useSubjectCredsOnly=false
+ kdc="kerberos.example.com"
+ keyTab="/path/to/keytab-file"
+ principal="<name>/<host>";
+};]]></programlisting>
+
+ <para>
+ Where realm, kdc, keyTab and principal should obviously be set correctly for the environment
+ where you are running (see the existing documentation for the C++ broker about creating a keytab
+ file).
+ </para>
+
+ <para>
+ Note: You may need to install the "Java Cryptography Extension (JCE) Unlimited Strength
+ Jurisdiction Policy Files" appropriate for your JDK in order to get Kerberos support working.
+ </para>
+ </section>
+
+ <section id="ExternalAuthManager">
+ <title>External (SSL Client Certificates)</title>
+
+ <para>
+ When <link linkend="SSL-Truststore-ClientCertificate"> requiring SSL Client Certificates</link> be
+ presented the ExternalAuthenticationManager can be used, such that the user is authenticated based on
+ trust of their certificate alone, and the X500Principal from the SSL session is then used as the username
+ for the connection, instead of also requiring the user to present a valid username and password.
+ </para>
+
+ <para>
+ The ExternalAuthenticationManager may be enabled by adding an empty &lt;external-auth-manager&gt; element to
+ the &lt;security&gt; section, as shown below. When referencing it from the default-auth-manager or port-mapping
+ sections, its name is ExternalAuthenticationManager.
+ </para>
+
+ <para>
+ <emphasis role="bold">Note:</emphasis> The ExternalAuthenticationManager should typically only be used on the
+ AMQP ports, in conjunction with <link linkend="SSL-Truststore-ClientCertificate">SSL client certificate
+ authentication</link>. It is not intended for other uses such as the JMX management port and will treat any
+ non-sasl authentication processes on these ports as successfull with the given username. As such you should
+ <link linkend="MultipleAuthProviders">include another Authentication Manager for use on non-AMQP ports</link>,
+ as is done in the example below. Perhaps the only exception to this would be where the broker is embedded in a
+ container that is itself externally protecting the HTTP interface and then providing the remote users name.
+ </para>
+
+ <example>
+ <title>Configuring external authentication (SSL client auth)</title>
+ <programlisting><![CDATA[
+<security>
+ <pd-auth-manager>
+ <principal-database>
+ <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
+ <attributes>
+ <attribute>
+ <name>passwordFile</name>
+ <value>${conf}/passwd</value>
+ </attribute>
+ </attributes>
+ </principal-database>
+ </pd-auth-manager>
+ <external-auth-manager/>
+ <default-auth-manager>PrincipalDatabaseAuthenticationManager</default-auth-manager>
+ <port-mappings>
+ <port-mapping>
+ <port>5672</port>
+ <auth-manager>ExternalAuthenticationManager</auth-manager>
+ </port-mapping>
+ </port-mappings>
+ ...
+</security>]]></programlisting>
+ </example>
+
+ </section>
+
+ <section id="AnonymousAuthManager">
+ <title>Anonymous</title>
+
+ <para>
+ The AnonymousAuthenticationManager will allow users to connect with or without credentials and result
+ in their identification on the broker as the user ANONYMOUS. It may be enabled by adding an empty
+ anonymous-auth-manager element to the security configuration section, as shown below.
+ </para>
+
+ <example>
+ <title>Configuring anonymous authentication</title>
+
+ <programlisting><![CDATA[
+<security>
+ <anonymous-auth-manager/>
+ ...
+</security>]]></programlisting>
+ </example>
+
+ <para>
+ When referencing it from the default-auth-manager or port-mapping sections, its name is
+ AnonymousAuthenticationManager.
+ </para>
+ </section>
+
+ <section id="MultipleAuthProviders">
+ <title>Configuring multiple Authentication Providers</title>
+ <para>
+ Different managers may be used on different ports. Each manager has its own configuration element,
+ the presence of which within the &lt;security&gt; section denotes the use of that authentication
+ provider. Where only one such manager is configured, it will be used on all ports (including JMX
+ and HTTP). Where more than one authentication manager is configured the configuration must define
+ which is the "default", and (if required) the mapping of non-default authentication managers to
+ other ports.
+ </para>
+ <para>
+ The following configuration sets up three authentication managers, using a password file as the
+ default (e.g. for the JMX and HTTP ports), Kerberos on port 5672 (the regular AMQP port) and Anonymous
+ on port 5673 (e.g a second AMQP port the broker could have been configured with).
+ </para>
+
+ <example>
+ <title>Configuring multiple (per-port) authentication schemes</title>
+ <programlisting><![CDATA[
+<security>
+ <pd-auth-manager>
+ <principal-database>
+ <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
+ <attributes>
+ <attribute>
+ <name>passwordFile</name>
+ <value>${conf}/passwd</value>
+ </attribute>
+ </attributes>
+ </principal-database>
+ </pd-auth-manager>
+ <kerberos-auth-manager>
+ <auth-name>sib</auth-name>
+ </kerberos-auth-manager>
+ <anonymous-auth-manager/>
+ <default-auth-manager>PrincipalDatabaseAuthenticationManager</default-auth-manager>
+ <port-mappings>
+ <port-mapping>
+ <port>5672</port>
+ <auth-manager>KerberosAuthenticationManager</auth-manager>
+ </port-mapping>
+ <port-mapping>
+ <port>5673</port>
+ <auth-manager>AnonymousAuthenticationManager</auth-manager>
+ </port-mapping>
+ </port-mappings>
+ ...
+</security>]]></programlisting>
+ </example>
+ </section>
+
+</section>
+
diff --git a/doc/book/src/java-broker/Java-Broker-Security-Group-Providers.xml b/doc/book/src/java-broker/Java-Broker-Security-Group-Providers.xml
new file mode 100644
index 0000000000..eaecd85770
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Security-Group-Providers.xml
@@ -0,0 +1,73 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Security-Group-Providers">
+ <title>Configuring Group Providers</title>
+ <para>
+ The Java broker utilises GroupProviders to allow assigning users to groups for use in <link linkend="Java-Broker-Security-ACLs">ACLs</link>. Following authentication by a given <link linkend="Java-Broker-Security-Authentication-Providers">Authentication Provider</link>, the configured Group Providers are consulted to allowing assignment of GroupPrincipals for a given authenticated user.
+ </para>
+
+
+ <section role="h3" id="File-Group-Manager">
+ <title>FileGroupManager</title>
+ <para>
+ The FileGroupManager allows specifying group membership in a flat file on disk, and is also exposed for inspection and update through the brokers HTTP management interface.
+ </para>
+ <para>
+ To enable the FileGroupManager, add the following configuration to the config.xml, adjusting the groupFile attribute value to match your desired groups file location.
+ </para>
+
+ <programlisting><![CDATA[
+ ...
+ <security>
+ <file-group-manager>
+ <attributes>
+ <attribute>
+ <name>groupFile</name>
+ <value>${conf}/groups</value>
+ </attribute>
+ </attributes>
+ </file-group-manager>
+ </security>]]>
+ ...
+</programlisting>
+
+ <section role="h4" id="File-Group-Manager-FileFormat">
+ <title>File Format</title>
+ <para>
+ The groups file has the following format:
+ </para>
+ <programlisting>
+ # &lt;GroupName&gt;.users = &lt;comma deliminated user list&gt;
+ # For example:
+
+ administrators.users = admin,manager
+</programlisting>
+ <para>
+ Only users can be added to a group currently, not other groups. Usernames can't contain commas.
+ </para><para>
+ Lines starting with a '#' are treated as comments when opening the file, but these are not preserved when the broker updates the file due to changes made through the management interface.
+ </para>
+ </section>
+ </section>
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Security-SSL.xml b/doc/book/src/java-broker/Java-Broker-Security-SSL.xml
new file mode 100644
index 0000000000..e415065a84
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Security-SSL.xml
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<section id="Java-Broker-Security-SSL">
+ <title>SSL</title>
+
+ <para>
+ This section will show how to use SSL to enable secure
+ connections between an AMQP message client and the broker.
+ </para>
+ <section role="h2" id="SSL-Keystore">
+ <title>Keystore Configuration</title>
+ <para>
+ The broker configuration file (config.xml) needs to be updated to include the required SSL keystore
+ configuration, an example of which can be found below.
+ </para>
+
+ <example>
+ <title>Configuring an SSL Keystore</title>
+ <programlisting><![CDATA[
+<connector>
+ ...
+ <ssl>
+ <enabled>true</enabled>
+ <port>5671</port>
+ <sslOnly>false</sslOnly>
+ <keyStorePath>/path/to/keystore.ks</keyStorePath>
+ <keyStorePassword>keystorepass</keyStorePassword>
+ <certAlias>alias<certAlias>
+ </ssl>
+ ...
+<connector>]]></programlisting>
+ </example>
+
+ <para>
+ The certAlias element is an optional way of specifying which certificate the broker should use
+ if the keystore contains multiple entries.
+ </para>
+
+ <para>
+ The sslOnly element controls whether the broker will <emphasis role="bold">only</emphasis> bind
+ the configured SSL port(s) or will also bind the non-SSL port(s). Setting sslOnly to true will
+ disable the non-SSL ports.
+ </para>
+
+ <important>
+ <para>
+ The password of the certificate used by the Broker <emphasis role="bold">must</emphasis>
+ match the password of the keystore itself. This is a restriction of the Qpid Broker
+ implementation. If using the <ulink url="&oracleKeytool;">keytool</ulink> utility,
+ note that this means the argument to the <option>-keypass</option> option must match
+ the <option>-storepass</option> option.
+ </para>
+ </important>
+ </section>
+
+ <section role="h2" id="SSL-Truststore-ClientCertificate">
+ <title>Truststore / Client Certificate Authentication</title>
+ <para>
+ The SSL trustore and related Client Certificate Authentication behaviour can be configured with
+ additional configuration as shown in the example below, in which the broker requires client
+ certificate authentication.
+ </para>
+
+ <example>
+ <title>Configuring an SSL Truststore and client auth</title>
+ <programlisting><![CDATA[
+<connector>
+ ...
+ <ssl>
+ ...
+ <trustStorePath>/path/to/truststore.ks</trustStorePath>
+ <trustStorePassword>truststorepass</trustStorePassword>
+ <needClientAuth>true</needClientAuth>
+ <wantClientAuth>false</wantClientAuth>
+ ...
+ </ssl>
+ ...
+<connector>]]></programlisting>
+ </example>
+
+ <para>
+ The needClientAuth and wantClientAuth elements allow control of whether the client must present an
+ SSL certificate. Only one of these elements is needed but both may be used at the same time.
+ A socket's client authentication setting is one of three states: required (needClientAuth = true),
+ requested (wantClientAuth = true), or none desired (both false, the default). If both elements are
+ set to true, needClientAuth takes precedence.
+ </para>
+
+ <para>
+ When using Client Certificate Authentication it may be desirable to use the External Authentication
+ Manager, for details see <xref linkend="ExternalAuthManager"></xref>
+ </para>
+
+ </section>
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Security-Users-And-Groups.xml b/doc/book/src/java-broker/Java-Broker-Security-Users-And-Groups.xml
new file mode 100644
index 0000000000..2125f3a3df
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Security-Users-And-Groups.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Security-Users-And-Groups">
+<title>Users And Groups</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Security.xml b/doc/book/src/java-broker/Java-Broker-Security.xml
new file mode 100644
index 0000000000..3db672100e
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Security.xml
@@ -0,0 +1,30 @@
+<?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.
+
+-->
+
+<chapter id="Java-Broker-Security">
+ <title>Security</title>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Security-Users-And-Groups.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Security-Group-Providers.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Security-Authentication-Providers.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Security-ACLs.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Security-SSL.xml"/>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Stores-BDB-Store.xml b/doc/book/src/java-broker/Java-Broker-Stores-BDB-Store.xml
new file mode 100644
index 0000000000..c16d9aa227
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Stores-BDB-Store.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE entities [
+<!ENTITY % entities SYSTEM "commonEntities.xml">
+%entities;
+]>
+<!--
+
+ 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.
+
+-->
+
+<section id="Java-Broker-Stores-BDB-Store">
+ <title>BDB Store</title>
+ <para>
+ The Java broker has an <emphasis>optional</emphasis> message store implementation backed by Oracle BDB JE.
+ This section will detail where to download the optional dependency from, how to add it to the broker installation,
+ and provide an example configuration for using the BDBMessageStore.
+ </para>
+
+ <section role="h3" id="Java-Broker-Stores-BDB-Store-BDBJE-Download">
+ <title>Oracle BDB JE download</title>
+ <para>
+ The BDB based message store is optional due to its dependency on Oracle BDB JE, which is distributed under the Sleepycat
+ licence. As a result of this, the dependency cant be distributed by the Apache Qpid project as part of the broker release package.
+ </para>
+ <para>
+ If you wish to use the BDBMessageStore, then you must download the Oracle BDB JE &oracleBdbProductVersion; release
+ <ulink url="&oracleJeDownloadUrl;">from the Oracle website.</ulink>
+ </para>
+ <para>
+ The download has a name in the form je-&oracleBdbProductVersion;.tar.gz. It is recommended that you
+ confirm the integrity of the download by verifying the MD5.
+ </para>
+ </section>
+
+ <section role="h3" id="Java-Broker-Stores-BDB-Store-BDBJE-Installation">
+ <title>Oracle BDB JE jar installation</title>
+ <para>
+ If you wish to use the BDBMessageStore, copy the je-&oracleBdbProductVersion;.jar from within the release
+ downloaded <link linkend="Java-Broker-Stores-BDB-Store-BDBJE-Download">above</link> into the 'opt' sub-directory
+ of the brokers 'lib' directory.
+ </para>
+
+ <programlisting>Unix:
+cp je-&oracleBdbProductVersion;.jar qpid-broker-&qpidCurrentRelease;/lib/opt</programlisting>
+
+ <programlisting>Windows:
+copy je-&oracleBdbProductVersion;.jar qpid-broker-&qpidCurrentRelease;\lib\opt</programlisting>
+ </section>
+
+
+
+ <section role="h3" id="Java-Broker-Stores-BDB-Store-Configuration">
+ <title>Configuration</title>
+ <para>
+ In order to use the BDBMessageStore, you must configure it for each VirtualHost desired by updating the store element
+ to specify the associated store class and provide a directory location for the data to be written, as shown below.
+ </para>
+
+ <example>
+ <title>Configuring a VirtualHost to use the BDBMessageStore</title>
+ <programlisting><![CDATA[
+<virtualhosts>
+ <virtualhost>
+ <name>vhostname</name>
+ <vhostname>
+ <store>
+ <class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>
+ <environment-path>${QPID_WORK}/bdbstore/vhostname</environment-path>
+ </store>
+ ...
+ </vhostname>
+ </virtualhost>
+</virtualhosts>
+]]></programlisting>
+ </example>
+ </section>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Stores-Derby-Store.xml b/doc/book/src/java-broker/Java-Broker-Stores-Derby-Store.xml
new file mode 100644
index 0000000000..042b2324de
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Stores-Derby-Store.xml
@@ -0,0 +1,56 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Stores-Derby-Store">
+<title>Derby Store</title>
+ <para>
+ The Java broker has a message store implementation backed by Apache Derby.
+ This section will detail configuration for using the DerbyMessageStore.
+ </para>
+
+ <section role="h3" id="Java-Broker-Stores-Derby-Store-Configuration">
+ <title>Configuration</title>
+ <para>
+ In order to use the DerbyMessageStore, you must configure it for each VirtualHost desired by updating the store element
+ to specify the associated store class and provide a directory location for the data to be written, as shown below.
+ </para>
+
+ <example>
+ <title>Configuring a VirtualHost to use the DerbyMessageStore</title>
+ <programlisting><![CDATA[
+<virtualhosts>
+ <virtualhost>
+ <name>vhostname</name>
+ <vhostname>
+ <store>
+ <class>org.apache.qpid.server.store.DerbyMessageStore</class>
+ <environment-path>${QPID_WORK}/derbystore/vhostname</environment-path>
+ </store>
+ ...
+ </vhostname>
+ </virtualhost>
+</virtualhosts>
+]]></programlisting>
+ </example>
+ </section>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Stores-HA-BDB-Store.xml b/doc/book/src/java-broker/Java-Broker-Stores-HA-BDB-Store.xml
new file mode 100644
index 0000000000..e8a13c52dc
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Stores-HA-BDB-Store.xml
@@ -0,0 +1,62 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Stores-HA-BDB-Store">
+ <title>High Availability BDB Store</title>
+ <para>
+ The Java broker has an <emphasis>optional</emphasis> High Availability message store implementation backed by Oracle BDB JE HA.
+ This section references information on where to download the optional dependency from, how to add it to the broker
+ installation, and how to configure the BDBHAMessageStore.
+ </para>
+ <para>
+ For more detailed information about use of this store, see <xref linkend="Java-Broker-High-Availability"></xref>.
+ </para>
+
+ <section role="h3" id="Java-Broker-Stores-HA-BDB-Store-BDBJE-Download">
+ <title>Oracle BDB JE download</title>
+ <para>
+ For details, see <xref linkend="Java-Broker-Stores-BDB-Store-BDBJE-Download"></xref>.
+ </para>
+ </section>
+
+ <section role="h3" id="Java-Broker-Stores-HA-BDB-Store-BDBJE-Installation">
+ <title>Oracle BDB JE jar installation</title>
+ <para>
+ For details, see <xref linkend="Java-Broker-Stores-BDB-Store-BDBJE-Installation"></xref>.
+ </para>
+ </section>
+
+ <section role="h3" id="Java-Broker-Stores-HA-BDB-Store-Configuration">
+ <title>Configuration</title>
+ <para>
+ In order to use the BDBHAMessageStore, you must configure it for each VirtualHost desired by updating the store element
+ to specify the associated store class, provide a directory location for the data to be written, and configure the
+ replication group and policies used by BDB JA HA.
+ </para>
+ <para>
+ A general configuration example is shown <link linkend="Java-Broker-High-Availability-Configuration">here</link>, however it
+ is strongly recommended you examine the wider context of <xref linkend="Java-Broker-High-Availability"></xref> for a fuller
+ discussion of the various configuration options and how to use them.
+ </para>
+ </section>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Stores-Memory-Store.xml b/doc/book/src/java-broker/Java-Broker-Stores-Memory-Store.xml
new file mode 100644
index 0000000000..b8694f3315
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Stores-Memory-Store.xml
@@ -0,0 +1,61 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Stores-Memory-Store">
+ <title>Memory Store</title>
+ <para>
+ The Java broker has an in-memory message store implementation.
+ This section will detail configuration for using the MemoryMessageStore.
+ </para>
+ <para>
+ Note: when using this store, the broker will store both persistent and non-persistent messages
+ in memory, which is to say that neither will be available following a broker restart, and the
+ ability to store new messages will be entirely constrained by the JVM heap size.
+ </para>
+
+ <section role="h3" id="Java-Broker-Stores-Memory-Store-Configuration">
+ <title>Configuration</title>
+ <para>
+ In order to use the MemoryMessageStore, you must configure it for each VirtualHost desired by updating the store element
+ to specify the associated store class, as shown below.
+ </para>
+
+ <example>
+ <title>Configuring a VirtualHost to use the MemoryMessageStore</title>
+ <programlisting><![CDATA[
+<virtualhosts>
+ <virtualhost>
+ <name>vhostname</name>
+ <vhostname>
+ <store>
+ <class>org.apache.qpid.server.store.MemoryMessageStore</class
+ </store>
+ ...
+ </vhostname>
+ </virtualhost>
+</virtualhosts>
+]]></programlisting>
+ </example>
+ </section>
+
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Stores-SQL-Store.xml b/doc/book/src/java-broker/Java-Broker-Stores-SQL-Store.xml
new file mode 100644
index 0000000000..b6776c81e6
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Stores-SQL-Store.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+<section id="Java-Broker-Stores-SQL-Store">
+<title>SQL Store</title>
+
+</section>
diff --git a/doc/book/src/java-broker/Java-Broker-Stores.xml b/doc/book/src/java-broker/Java-Broker-Stores.xml
new file mode 100644
index 0000000000..aee3cdebdb
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Stores.xml
@@ -0,0 +1,30 @@
+<?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.
+
+-->
+
+<chapter id="Java-Broker-Stores">
+ <title>Stores</title>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Stores-Memory-Store.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Stores-Derby-Store.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Stores-SQL-Store.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Stores-BDB-Store.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Java-Broker-Stores-HA-BDB-Store.xml"/>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Broker-Virtual-Hosts.xml b/doc/book/src/java-broker/Java-Broker-Virtual-Hosts.xml
new file mode 100644
index 0000000000..fc1a8b1dc5
--- /dev/null
+++ b/doc/book/src/java-broker/Java-Broker-Virtual-Hosts.xml
@@ -0,0 +1,25 @@
+<?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.
+
+-->
+
+<chapter id="Java-Broker-Virtual-Hosts">
+ <title>Virtual Hosts</title>
+</chapter>
diff --git a/doc/book/src/java-broker/Java-Environment-Variables.xml b/doc/book/src/java-broker/Java-Environment-Variables.xml
deleted file mode 100644
index 12703190f2..0000000000
--- a/doc/book/src/java-broker/Java-Environment-Variables.xml
+++ /dev/null
@@ -1,84 +0,0 @@
-<?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.
-
--->
-
-<section id="Java-Environment-Variables">
- <title>
- Java Environment Variables
- </title>
- <section role="h2" id="JavaEnvironmentVariables-SettingQpidEnvironmentVariables">
- <title>
- Setting
- Qpid Environment Variables
- </title>
-
- <section role="h3" id="JavaEnvironmentVariables-QpidDeploymentPathVariables">
- <title>
- Qpid
- Deployment Path Variables
- </title>
- <para>
- There are two main Qpid environment variables which are required
- to be set for Qpid deployments, QPID_HOME and QPID_WORK.
- </para>
- <para>
- QPID_HOME - This variable is used to tell the Qpid broker where
- it's installed home is, which is in turn used to find dependency
- JARs which Qpid uses.
- </para>
- <para>
- QPID_WORK - This variable is used by Qpid when creating all
- 'writeable' directories that it uses. This includes the log
- directory and the storage location for any BDB instances in use
- by your deployment (if you're using persistence with BDB). If you
- do not set this variable, then the broker will default (in the
- qpid-server script) to use the current user's homedir as the root
- directory for creating the writeable locations that it uses.
- </para>
-
- <!--h3-->
- </section>
-
- <section role="h3" id="JavaEnvironmentVariables-SettingMaxMemoryforthebroker">
- <title>
- Setting
- Max Memory for the broker
- </title>
- <para>
- If you simply start the Qpid broker, it will default to use a
- -Xmx setting of 1024M for the broker JVM. However, we would
- recommend that you make the maximum -Xmx heap size available, if
- possible, of 3Gb (for 32-bit platforms).
- </para>
- <para>
- You can control the memory setting for your broker by setting the
- QPID_JAVA_MEM variable before starting the broker e.g. -Xmx3668m
- . Enclose your value within quotes if you also specify a -Xms
- value. The value in use is echo'd by the qpid-server script on
- startup.
- </para>
- <!--h3-->
- </section>
-
- <!--h2-->
- </section>
-
-</section>
diff --git a/doc/book/src/java-broker/Management-Console-Security.xml b/doc/book/src/java-broker/Management-Console-Security.xml
deleted file mode 100644
index 31f63c70da..0000000000
--- a/doc/book/src/java-broker/Management-Console-Security.xml
+++ /dev/null
@@ -1,251 +0,0 @@
-<?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.
-
--->
-
-<section><title>
- Management Console Security
- </title><section role="h1" id="ManagementConsoleSecurity-ManagementConsoleSecurity"><title>
- Management
- Console Security
- </title>
- <itemizedlist>
- <listitem><para>
- <xref linkend="ManagementConsoleSecurity-SSLencryptedRMI-280.5andabove-29"/>
- </para></listitem>
- <listitem><para>
- <xref linkend="ManagementConsoleSecurity-JMXMP-28M4andprevious-29"/>
- </para></listitem>
- <listitem><para>
- <xref linkend="ManagementConsoleSecurity-UserAccounts-26AccessRights"/>
- </para></listitem>
- </itemizedlist>
- <section role="h2" id="ManagementConsoleSecurity-SSLencryptedRMI-280.5andabove-29"><title>
- SSL
- encrypted RMI (0.5 and above)
- </title>
- <para>
- Current versions of the broker make use of SSL encryption to
- secure their RMI based JMX ConnectorServer for security purposes.
- This ships enabled by default, although the test SSL keystore
- used during development is not provided for security reasons
- (using this would provide no security as anyone could have access
- to it).
- </para><section role="h3" id="ManagementConsoleSecurity-BrokerConfiguration"><title>
- Broker
- Configuration
- </title>
-
- <para>
- The broker configuration must be updated before the broker will
- start. This can be done either by disabling the SSL support,
- utilizing a purchased SSL certificate to create a keystore of
- your own, or generating a self-signed keystore.
- </para><para>
- The broker must be configured with a keystore containing the
- private and public keys associated with its SSL certificate. This
- is accomplished by setting the Java environment properties
- <emphasis>javax.net.ssl.keyStore</emphasis> and
- <emphasis>javax.net.ssl.keyStorePassword</emphasis> respectively with the
- location and password of an appropriate SSL keystore. Entries for
- these properties exist in the brokers main configuration file
- alongside the other management settings (see below), although the
- command line options will still work and take precedence over the
- configuration file.
- </para>
- <programlisting>
-&lt;management&gt;
- &lt;ssl&gt;
- &lt;enabled&gt;true&lt;/enabled&gt;
- &lt;!-- Update below path to your keystore location, eg ${conf}/qpid.keystore --&gt;
- &lt;keyStorePath&gt;${conf}/qpid.keystore&lt;/keyStorePath&gt;
- &lt;keyStorePassword&gt;password&lt;/keyStorePassword&gt;
- &lt;/ssl&gt;
-&lt;/management&gt;
-</programlisting>
-<!--h3--></section>
-
- <section role="h3" id="ManagementConsoleSecurity-JMXManagementConsoleConfiguration"><title>
- JMX
- Management Console Configuration
- </title>
-
- <para>
- If the broker makes use of an SSL certificate signed by a known
- signing CA (Certification Authority), the management console
- needs no extra configuration, and will make use of Java's
- built-in CA
- truststore for certificate verification (you may however have to
- update the system-wide default truststore if your CA is not
- already present in it).
- </para><para>
- If however you wish to use a self-signed SSL certificate, then
- the management console must be provided with an SSL truststore
- containing a record for the SSL certificate so that it is able to
- validate it when presented by the broker. This is performed by
- setting the <emphasis>javax.net.ssl.trustStore</emphasis> and
- <emphasis>javax.net.ssl.trustStorePassword</emphasis> environment variables
- when starting the console. This can be done at the command line,
- or alternatively an example configuration has been made within
- the console's qpidmc.ini launcher configuration file that may
- pre-configured in advance for repeated usage. See the <xref linkend="Qpid-JMX-Management-Console-User-Guide"/> for more
- information on this configuration process.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="ManagementConsoleSecurity-JConsoleConfiguration"><title>
- JConsole
- Configuration
- </title>
-
- <para>
- As with the JMX Management Console above, if the broker is using
- a self-signed SSL certificate then in order to connect remotely
- using JConsole, an appropriate trust store must be provided at
- startup. See <xref linkend="qpid_JConsole"/> for further details on configuration.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="ManagementConsoleSecurity-AdditionalInformation"><title>
- Additional
- Information
- </title>
-
- <para>
- More information on Java's handling of SSL certificate
- verification and customizing the keystores can be found in the
- <ulink url="http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores">http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores</ulink>.
- </para>
-<!--h3--></section>
-<!--h2--></section>
-
-
-
- <section role="h2" id="ManagementConsoleSecurity-JMXMP-28M4andprevious-29"><title>
- JMXMP
- (M4 and previous)
- </title>
-
- <para>
- In previous releases of Qpid (M4 and below) the broker, can make
- use of Sun's Java Management Extensions Messaging Protocol
- (JMXMP) to provide encryption of the JMX connection, offering
- increased security over the default unencrypted RMI based JMX
- connection.
- </para><section role="h3" id="ManagementConsoleSecurity-DownloadandInstall"><title>
- Download and
- Install
- </title>
-
- <para>
- This is possible by adding the jmxremote_optional.jar as provided
- by Sun. This jar is covered by the Sun Binary Code License and is
- not compatible with the Apache License which is why this
- component is not bundled with Qpid.
- </para><para>
- Download the JMX Remote API 1.0.1_04 Reference Implementation
- from <xref linkend="qpid_download.jsp"/>. The included
- 'jmxremote-1_0_1-bin\lib\jmxremote_optional.jar' file must be
- added to the broker classpath:
- </para><para>
- First set your classpath to something like this:
- </para>
- <programlisting>
-CLASSPATH=jmxremote_optional.jar
-</programlisting>
- <para>
- Then, run qpid-server passing the following additional flag:
- </para>
- <programlisting>
-qpid-server -run:external-classpath=first
-</programlisting>
- <para>
- Following this the configuration option can be updated to enabled
- use of the JMXMP based JMXConnectorServer.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="ManagementConsoleSecurity-BrokerConfiguration2"><title>
- Broker
- Configuration
- </title>
-
- <para>
- To enabled this security option change the
- <emphasis>security-enabled</emphasis> value in your broker configuration
- file.
- </para>
- <programlisting>
- &lt;management&gt;
- &lt;security-enabled&gt;true&lt;/security-enabled&gt;
- &lt;/management&gt;
-</programlisting>
- <para>
- You may also (for M2 and earlier) need to set the following
- system properties using the environment variable QPID_OPTS:
- </para><para>
- QPID_OPTS="-Dcom.sun.management.jmxremote
- -Dcom.sun.management.jmxremote.port=8999
- -Dcom.sun.management.jmxremote.authenticate=false
- -Dcom.sun.management.jmxremote.ssl=false"
- </para>
-<!--h3--></section>
-
- <section role="h3" id="ManagementConsoleSecurity-JMXManagementConsoleConfiguration-2"><title>
- JMX
- Management Console Configuration
- </title>
-
- <para>
- If you wish to connect to a broker configured to use JMXMP then
- the console also requires provision of the Optional sections of
- the JMX Remote API that are not included within the JavaSE
- platform.
- </para><para>
- In order to make it available to the console, place the
- 'jmxremote_optional.jar' (rename the file if any additional
- information is present in the file name) jar file within the
- 'plugins/jmxremote.sasl_1.0.1/' folder of the console release (on
- Mac OS X you will need to select 'Show package contents' from the
- context menu whilst selecting the management console bundle in
- order to reveal the inner file tree).
- </para><para>
- Following the the console will automatically load the JMX Remote
- Optional classes and attempt the JMXMP connection when connecting
- to a JMXMP enabled broker.
- </para>
-<!--h3--></section>
-<!--h2--></section>
-
- <section role="h2" id="ManagementConsoleSecurity-UserAccounts-26AccessRights"><title>
- User
- Accounts &amp; Access Rights
- </title>
-
- <para>
- In order to access the management operations via JMX, users must
- have an account and have been assigned appropriate access rights.
- See <xref linkend="qpid_Configuring-Management-Users"/>
- </para>
-<!--h2--></section>
-<!--h1--></section>
-
-
-</section>
diff --git a/doc/book/src/java-broker/OtherQueueTypes.xml b/doc/book/src/java-broker/OtherQueueTypes.xml
deleted file mode 100644
index d42e4e62cb..0000000000
--- a/doc/book/src/java-broker/OtherQueueTypes.xml
+++ /dev/null
@@ -1,274 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE urls [
-<!ENTITY oracleJeeDocUrl "http://docs.oracle.com/javaee/6/api/">
-]>
-<!--
-
- 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.
-
--->
-
-<section id="OtherQueueTypes">
- <title>Other Queue Types</title>
-
- <section role="h2" id="OtherQueueTypes-Introduction">
- <title>Introduction</title>
- <para> In addition to the standard queue type where messages are delivered in the same order
- that they were sent, the Java Broker supports three additional queue types which allows for
- alternative delivery behaviours. These are <link linkend="OtherQueueTypes-Priority"
- >priority-queues</link>, <link linkend="OtherQueueTypes-Sorted">sorted-queues</link>-, and
- <link linkend="OtherQueueTypes-LVQ">last-value-queues</link> (LVQs). </para>
- <para> In the following sections, the semantics of each queue type is described, followed by a
- description of how instances of these queue can be created via <link
- linkend="OtherQueueTypes-CreateUsingConfig">configuration</link> or <link
- linkend="OtherQueueTypes-CreateUsingJmsOrJmx">programmatically</link>. </para>
- <para>The final section discusses the importance of using a <link
- linkend="OtherQueueTypes-SetLowPrefetch">low client pre-fetch</link> with these queued.
- </para>
- </section>
-
- <section role="h2" id="OtherQueueTypes-Priority">
- <title>Priority Queues</title>
- <para>In a priority queue, messages on the queue are delivered in an order determined by the
- <ulink url="&oracleJeeDocUrl;javax/jms/Message.html#getJMSPriority()">JMS priority message
- header</ulink> within the message. By default Qpid supports the 10 priority levels mandated
- by JMS, with priority value 0 as the lowest priority and 9 as the highest. </para>
- <para>It is possible to reduce the effective number of priorities if desired.</para>
- <para>JMS defines the <ulink url="&oracleJeeDocUrl;javax/jms/Message.html#DEFAULT_PRIORITY">
- default message priority</ulink> as 4. Messages sent without a specified priority use this
- default. </para>
- </section>
- <section role="h2" id="OtherQueueTypes-Sorted">
- <title>Sorted Queues</title>
- <para>Sorted queues allow the message delivery order to be determined by value of an arbitrary
- <ulink url="&oracleJeeDocUrl;javax/jms/Message.html#getStringProperty()">JMS message
- property</ulink>. Sort order is alpha-numeric and the property value must have a type
- java.lang.String.</para>
- <para>Messages sent to a sorted queue without the specified JMS message property will be
- inserted into the 'last' position in the queue.</para>
- </section>
- <section role="h2" id="OtherQueueTypes-LVQ">
- <title>Last Value Queues (LVQ)</title>
- <para>LVQs (or conflation queues) are special queues that automatically discard any message when
- a newer message arrives with the same key value. The key is specified by arbitrary <ulink
- url="&oracleJeeDocUrl;javax/jms/Message.html#getPropertyNames()">JMS message
- property</ulink>.</para>
- <para>An example of an LVQ might be where a queue represents prices on a stock exchange: when
- you first consume from the queue you get the latest quote for each stock, and then as new
- prices come in you are sent only these updates. </para>
- <para>Like other queues, LVQs can either be browsed or consumed from. When browsing an
- individual subscriber does not remove the message from the queue when receiving it. This
- allows for many subscriptions to browse the same LVQ (i.e. you do not need to create and bind
- a separate LVQ for each subscriber who wishes to receive the contents of the LVQ).</para>
- <para>Messages sent to an LVQ without the specified property will be delivered as normal and
- will never be "replaced".</para>
- </section>
- <section role="h2" id="OtherQueueTypes-Create">
- <title>Creating a Priority, Sorted or LVQ Queue</title>
- <para>To create a priority, sorted or LVQ queue, it can be defined in the virtualhost
- configuration file, or the queue can be created programmtically from a client via AMQP (using
- an extension to JMS), or using JMX. These methods are described below. </para>
- <para>Once a queue is created you cannot change its type (without deleting it and re-creating).
- Also note you cannot currently mix the natures of these queue types, for instance, you cannot
- define a queue which it both an LVQ and a priority-queue.</para>
- <section role="h2" id="OtherQueueTypes-CreateUsingConfig">
- <title>Using configuration</title>
- <para>To create a priority, sorted or LVQ queue within configuration, add the appropriate xml
- to the virtualhost.xml configuration file within the <varname>queues</varname>
- element.</para>
- <section role="h3" id="OtherQueueTypes-CreateUsingConfig-Priority">
- <title>Priority</title>
- <para> To defining a priority queue, add a &lt;priority&gt;true&lt;/priority&gt; element. By
- default the queue will have 10 distinct priorities. </para>
- <example>
- <title>Configuring a priority queue</title>
- <programlisting><![CDATA[<queue>
- <name>myqueue</name>
- <myqueue>
- <exchange>amq.direct</exchange>
- <priority>true</priority>
- </myqueue>
-</queue>]]></programlisting>
- </example>
- <para> If you require fewer priorities, it is possible to specify a
- <varname>priorities</varname> element (whose value is a integer value between 2 and 10
- inclusive) which will give the queue that number of distinct priorities. When messages are
- sent to that queue, their effective priority will be calculated by partitioning the
- priority space. If the number of effective priorities is 2, then messages with priority
- 0-4 are treated the same as "lower priority" and messages with priority 5-9 are treated
- equivalently as "higher priority". </para>
- <example>
- <title>Configuring a priority queue with fewer priorities</title>
- <programlisting><![CDATA[<queue>
- <name>myqueue</name>
- <myqueue>
- <exchange>amq.direct</exchange>
- <priority>true</priority>
- <priorities>4</priorities>
- </myqueue>
-</queue>]]></programlisting>
- </example>
- </section>
- <section role="h3" id="OtherQueueTypes-CreateUsingConfig-Sorted">
- <title>Sorted</title>
- <para> To define a sorted queue, add a <varname>sortKey</varname> element. The value of the
- <varname>sortKey</varname> element defines the message property to use the value of when
- sorting the messages put onto the queue. </para>
- <example>
- <title>Configuring a sorted queue</title>
- <programlisting><![CDATA[<queue>
- <name>myqueue</name>
- <myqueue>
- <exchange>amq.direct</exchange>
- <sortKey>message-property-to-sort-by</sortKey>
- </myqueue>
-</queue>]]></programlisting>
- </example>
- </section>
- <section role="h3" id="OtherQueueTypes-CreateUsingConfig-LVQ">
- <title>LVQ</title>
- <para> To define a LVQ, add a <varname>lvq</varname> element with the value
- <constant>true</constant>. Without any further configuration this will define an LVQ
- which uses the JMS message property <constant>qpid.LVQ_key</constant> as the key for
- replacement. </para>
- <example>
- <title>Configuring a LVQ queue</title>
- <programlisting><![CDATA[<queue>
- <name>myqueue</name>
- <myqueue>
- <exchange>amq.direct</exchange>
- <lvq>true</lvq>
- </myqueue>
-</queue>]]></programlisting>
- </example>
- <para> If you wish to define your own property then you can do so using the
- <varname>lvqKey</varname> element.</para>
- <example>
- <title>Configuring a LVQ queue with custom message property name</title>
- <programlisting><![CDATA[<queue>
- <name>myqueue</name>
- <myqueue>
- <exchange>amq.direct</exchange>
- <lvq>true</lvq>
- <lvqKey>ISIN</lvqKey>
- </myqueue>
-</queue>]]></programlisting>
- </example>
- </section>
- </section>
- <section role="h2" id="OtherQueueTypes-CreateUsingJmsOrJmx">
- <title>Using JMS or AMQP</title>
- <para>To create a priority, sorted or LVQ queue programmatically from JMX or using a Qpid
- extension to JMS, pass the appropriate queue-declare arguments.</para>
- <table>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Queue type</entry>
- <entry>Argument name</entry>
- <entry>Argument name</entry>
- <entry>Argument Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>priority</entry>
- <entry>priorities</entry>
- <entry>java.lang.Integer</entry>
- <entry>Specifies a priority queue with given number priorities</entry>
- </row>
- <row>
- <entry>sorted</entry>
- <entry>qpid.queue_sort_key</entry>
- <entry>java.lang.String</entry>
- <entry>Specifies sorted queue with given message property used to sort the
- entries</entry>
- </row>
- <row>
- <entry>lvq</entry>
- <entry>qpid.last_value_queue_key</entry>
- <entry>java.lang.String</entry>
- <entry>Specifies lvq queue with given message property used to conflate the
- entries</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>The following example illustrates the creation of the a LVQ queue from a
- javax.jms.Session object. Note that this utilises a Qpid specific extension to JMS and
- involves casting the session object back to its Qpid base-class.</para>
- <example>
- <title>Creation of an LVQ using the Qpid extension to JMS</title>
- <programlisting><![CDATA[Map<String,Object> arguments = new HashMap<String, Object>();
-arguments.put("qpid.last_value_queue_key","ISIN");
-((AMQSession<?,?>) session).createQueue(queueName, autoDelete, durable, exclusive, arguments);]]></programlisting>
-
- </example>
- <para> The following example illustrates the creation of the sorted queue from a the JMX
- interface using the ManagedBroker interface. </para>
- <example>
- <title>Creation of a sorted queue using JMX</title>
- <programlisting><![CDATA[Map<String, Object> environment = new HashMap<String, Object>();
-environment.put(JMXConnector.CREDENTIALS, new String[] {"admin","password"});
-// Connect to service
-JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi");
-JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
-MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
-// Object name for ManagedBroker for virtualhost myvhost
-ObjectName objectName = new ObjectName("org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=myvhost");
-// Get the ManagedBroker object
-ManagedBroker managedBroker = JMX.newMBeanProxy(mbsc, objectName, ManagedBroker.class);;
-
-// Create the queue passing arguments
-Map<String,Object> arguments = new HashMap<String, Object>();
-arguments.put("qpid.queue_sort_key","myheader");
-managedBroker.createNewQueue("myqueue", null, true, arguments);]]></programlisting>
- </example>
- </section>
- </section>
-
- <section role="h2" id="OtherQueueTypes-SetLowPrefetch">
- <title>Low pre-fetch</title>
- <para>Qpid clients receive buffered messages in batches, sized according to the pre-fetch value.
- The current default is 500. </para>
- <para>However, if you use the default value you will probably <emphasis>not</emphasis> see
- desirable behaviour when using priority, sorted or lvq queues. Once the broker has sent a
- message to the client its delivery order is then fixed, regardless of the special behaviour of
- the queue. </para>
- <para>For example, if using a priority queue and a prefetch of 100, and 100 messages arrive with
- priority 2, the broker will send these messages to the client. If then a new message arrives
- will priority 1, the broker cannot leap frog messages of lower priority. The priority 1 will
- be delivered at the front of the next batch of messages to be sent to the client.</para>
- <para> So, you need to set the prefetch values for your client (consumer) to make this sensible.
- To do this set the Java system property <varname>max_prefetch</varname> on the client
- environment (using -D) before creating your consumer. </para>
- <para>A default for all client connections can be set via a system property: </para>
- <programlisting>
--Dmax_prefetch=1
-</programlisting>
- <para> The prefetch can be also be adjusted on a per connection basis by adding a
- <varname>maxprefetch</varname> value to the <ulink url="../../Programming-In-Apache-Qpid/html/QpidJNDI.html#section-jms-connection-url">Connection URLs</ulink>
- </para>
- <programlisting>
-amqp://guest:guest@client1/development?maxprefetch='1'&amp;brokerlist='tcp://localhost:5672'
-</programlisting>
- <para>Setting the Qpid pre-fetch to 1 will give exact queue-type semantics as perceived by the
- client however, this brings a performance cost. You could test with a slightly higher
- pre-fetch to trade-off between throughput and exact semantics.</para>
- </section>
-</section>
diff --git a/doc/book/src/java-broker/Producer-Flow-Control.xml b/doc/book/src/java-broker/Producer-Flow-Control.xml
deleted file mode 100644
index 262279510e..0000000000
--- a/doc/book/src/java-broker/Producer-Flow-Control.xml
+++ /dev/null
@@ -1,217 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Producer-Flow-Control">
- <title>Producer Flow Control</title>
-
- <section role="h2" id="QpidProducerFlowControlGeneralInformation">
- <title>General Information</title>
- <para>
- The Qpid 0.6 release introduced a simplistic producer-side flow control mechanism
- into the Java Messaging Broker, causing producers to be flow-controlled when they
- attempt to send messages to an overfull queue. Qpid 0.18 introduced a similar
- mechanism triggered by an overfull persistent message store on a virtual host.
- </para>
- </section>
- <section role="h2" id="QpidProducerFlowControlServerConfiguration">
- <title>Server Configuration</title>
- <section role="h3">
- <title>Configuring a Queue to use flow control</title>
- <para>
- Flow control is enabled on a producer when it sends a message to a Queue
- which is "overfull". The producer flow control will be rescinded when all
- Queues on which a producer is blocking become "underfull". A Queue is defined
- as overfull when the size (in bytes) of the messages on the queue exceeds the
- "capacity" of the Queue. A Queue becomes "underfull" when its size becomes
- less than the "flowResumeCapacity".
-
- <programlisting>
- <![CDATA[
-<queue>
- <name>test</name>
- <test>
- <exchange>amq.direct</exchange>
- <capacity>10485760</capacity> <!-- set the queue capacity to 10Mb -->
- <flowResumeCapacity>8388608</flowResumeCapacity> <!-- set the resume capacity to 8Mb -->
- </test>
-</queue>
- ]]>
- </programlisting>
-
- The default for all queues on a virtual host can also be set
-
- <programlisting>
- <![CDATA[
-<virtualhosts>
- <virtualhost>
- <name>localhost</name>
- <localhost>
- <capacity>10485760</capacity> <!-- set the queue capacity to 10Mb -->
- <flowResumeCapacity>8388608</flowResumeCapacity> <!-- set the resume capacity to 8Mb -->
- </localhost>
- </virtualhost>
-</virtualhosts>
- ]]>
- </programlisting>
-
- Where no flowResumeCapacity is set, the flowResumeCapacity is set to be equal
- to the capacity. Where no capacity is set, capacity is defaulted to 0 meaning
- there is no capacity limit.
- </para>
- <section role="h4">
- <title>Broker Log Messages</title>
- <para>
- There are four new Broker log messages that may occur if flow control through queue capacity limits is enabled.
- Firstly, when a capacity limited queue becomes overfull, a log message similar to the following is produced
- </para>
- <programlisting>
-MESSAGE [vh(/test)/qu(MyQueue)] [vh(/test)/qu(MyQueue)] QUE-1003 : Overfull : Size : 1,200 bytes, Capacity : 1,000
- </programlisting>
- <para>Then for each channel which becomes blocked upon the overful queue a log message similar to the following is produced:</para>
- <programlisting>
-MESSAGE [con:2(guest@anonymous(713889609)/test)/ch:1] [con:2(guest@anonymous(713889609)/test)/ch:1] CHN-1005 : Flow Control Enforced (Queue MyQueue)
- </programlisting>
- <para>When enough messages have been consumed from the queue that it becomes underfull, then the following log is generated: </para>
- <programlisting>
-MESSAGE [vh(/test)/qu(MyQueue)] [vh(/test)/qu(MyQueue)] QUE-1004 : Underfull : Size : 600 bytes, Resume Capacity : 800
- </programlisting>
- <para>And for every channel which becomes unblocked you will see a message similar to: </para>
- <programlisting>
-MESSAGE [con:2(guest@anonymous(713889609)/test)/ch:1] [con:2(guest@anonymous(713889609)/test)/ch:1] CHN-1006 : Flow Control Removed
- </programlisting>
- <para>Obviously the details of connection, virtual host, queue, size, capacity, etc would depend on the configuration in use.</para>
-
-
- </section><!-- Broker Log Messages -->
- </section><!-- Configuring a Queue to use flow control -->
-
- <section role="h3">
- <title>Disk quota-based flow control</title>
- <para>
- Since version 0.18 of Qpid Broker, flow control can be triggered when a
- configured disk quota is exceeded. This is supported by the BDB and Derby message stores.
- </para>
- <para>
- This functionality blocks all producers on reaching the disk overflow limit. When consumers
- consume the messages, causing disk space usage to falls below the underflow limit, the
- producers are unblocked and continue working as normal.
- </para>
- <para>
- Two limits can be configured:
- </para>
- <para>
- overfull limit - the maximum space on disk (in bytes) which can be used by store.
- </para>
- <para>
- underfull limit - when the space on disk drops below this limit, producers are allowed to resume publishing.
- </para>
- <para>
- An example of quota configuration for the BDB message store is provided below.
- </para>
- <programlisting>
- <![CDATA[
-<store>
- <class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>
- <environment-path>${work}/bdbstore/test</environment-path>
- <overfull-size>50000000</overfull-size>
- <underfull-size>45000000</underfull-size>
-</store>
- ]]>
- </programlisting>
- <para>
- The disk quota functionality is based on "best effort" principle. This means the broker
- cannot guarantee that the disk space limit will not be exceeded. If several concurrent
- transactions are started before the limit is reached, which collectively cause the limit
- to be exceeded, the broker may allow all of them to be committed.
- </para>
-
- <section role="h4">
- <title>Broker Log Messages for quota flow control</title>
- <para>
- There are 2 new broker log messages that may occur if flow control through disk quota limits is enabled.
- When the virtual host is blocked due to exceeding of the disk quota limit the following message
- appears in the broker log
- <programlisting>
-[vh(/test)/ms(BDBMessageStore)] MST-1008 : Store overfull, flow control will be enforced
- </programlisting>
- When virtual host is unblocked after cleaning the disk space the following message appears in the broker log
- <programlisting>
-[vh(/test)/ms(BDBMessageStore)] MST-1009 : Store overfull condition cleared
- </programlisting>
- </para>
- </section>
- </section><!-- Disk quota-based flow control -->
- </section><!-- Server configuration -->
-
-
- <section role="h2" id="QpidProducerFlowControlClientImpact">
- <title>Client impact and configuration</title>
- <para>
- If a producer sends to a queue which is overfull, the broker will respond by
- instructing the client not to send any more messages. The impact of this is
- that any future attempts to send will block until the broker rescinds the flow control order.
- </para>
- <para>
- While blocking the client will periodically log the fact that it is blocked waiting on flow control.
- </para>
- <programlisting>
-WARN Message send delayed by 5s due to broker enforced flow control
-WARN Message send delayed by 10s due to broker enforced flow control
- </programlisting>
- <para>
- After a set period the send will timeout and throw a JMSException to the calling code.
- </para>
- <para>
- If such a JMSException is thrown, the message will not be sent to the broker,
- however the underlying Session may still be active - in particular if the
- Session is transactional then the current transaction will not be automatically
- rolled back. Users may choose to either attempt to resend the message, or to
- roll back any transactional work and close the Session.
- </para>
- <para>
- Both the timeout delay and the periodicity of the warning messages can be set
- using Java system properties.
- </para>
- <para>
- The amount of time (in milliseconds) to wait before timing out
- is controlled by the property qpid.flow_control_wait_failure.
- </para>
- <para>
- The frequency at which the log message informing that the producer is flow
- controlled is sent is controlled by the system property qpid.flow_control_wait_notify_period.
- </para>
- <para>
- Adding the following to the command line to start the client would result in a timeout of one minute,
- with warning messages every ten seconds:
- </para>
- <programlisting>
--Dqpid.flow_control_wait_failure=60000
--Dqpid.flow_control_wait_notify_period=10000
- </programlisting>
- <section role="h3">
- <title>Older Clients</title>
- <para>
- The flow control feature was first added to the Java broker/client in the 0.6 release. If an older client connects to the broker then the flow control commands will be ignored by it and it will not be blocked. So to fully benefit from this feature both Client and Broker need to be at least version 0.6.
- </para>
- </section>
- </section> <!-- Client impact and configuration -->
-</section>
diff --git a/doc/book/src/java-broker/Qpid-JMX-Management-Console-FAQ.xml b/doc/book/src/java-broker/Qpid-JMX-Management-Console-FAQ.xml
deleted file mode 100644
index 1806ab01b1..0000000000
--- a/doc/book/src/java-broker/Qpid-JMX-Management-Console-FAQ.xml
+++ /dev/null
@@ -1,96 +0,0 @@
-<?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.
-
--->
-
-<section><title>
- Qpid JMX Management Console FAQ
- </title>
-<!--
-h3. {toggle-cloak:id=qManagementConsoleSecurity} How do I connect the management console to my broker using security ?
-{cloak:id=qManagementConsoleSecurity}
-
-The [Management Console Security] page will give you the instructions that you should use to set this up.
-{cloak}
-
-
-h3. {toggle-cloak:id=rmiServerHostname} I am unable to connect Qpid JMX MC/JConsole to a remote broker running on Linux, but connecting to localhost on that machine works ?
-{cloak:id=rmiServerHostname}
-
-The RMI based JMX ConnectorServer used by the broker requries two ports to operate. The console connects to an RMI Registry running on the primary (default 8999) port and retrieves the information actually needed to connect to the JMX Server. This information embeds the hostname of the remote machine, and if this is incorrect or unreachable by the connecting client the connection will fail.
-
-This situation arises due to the hostname configuration on Linux and is generally encountered when the remote machine does not have a DNS hostname entry on the local network, causing the hostname command to return a loopback IP instead of a fully qualified domain name or IP address accessible by remote client machines. It is described in further detail at: http://java.sun.com/javase/6/docs/technotes/guides/management/faq.html#linux1
-
-To remedy this issue you can set the _java.rmi.server.hostname_ system property to control the hostname/ip reported to the RMI runtime when advertising the JMX ConnectorServer. This can also be used to dictate the address returned on a computer with multiple network interfaces to control reachability. To do so, add the value _-Djava.rmi.server.hostname=<desired hostname/ip>_ to the QPID_OPTS environment variable before starting the _qpid-server_ script.
--->
-
- <section role="h2" id="QpidJMXManagementConsoleFAQ-Errors"><title>
- Errors
- </title>
-
- <section role="h3" id="QpidJMXManagementConsoleFAQ-HowdoIconnectthemanagementconsoletomybrokerusingsecurity-3F"><title>
- How do I connect the management console to
- my broker using security ?
- </title>
-
- <para>
- The <xref linkend="qpid_Management-Console-Security"/> page will give you the instructions that you should
- use to set this up.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJMXManagementConsoleFAQ-IamunabletoconnectQpidJMXMC-2FJConsoletoaremotebrokerrunningonLinux-2Cbutconnectingtolocalhostonthatmachineworks-3F"><title>
- I am unable to connect Qpid JMX MC/JConsole
- to a remote broker running on Linux, but connecting to localhost
- on that machine works ?
- </title>
-
- <para>
- The RMI
- based JMX ConnectorServer used by the broker requries two ports
- to operate. The console connects to an RMI Registry running on
- the primary (default 8999) port and retrieves the information
- actually needed to connect to the JMX Server. This information
- embeds the hostname of the remote machine, and if this is
- incorrect or unreachable by the connecting client the connection
- will fail.
- </para><para>
- This
- situation arises due to the hostname configuration on Linux and
- is generally encountered when the remote machine does not have a
- DNS hostname entry on the local network, causing the hostname
- command to return a loopback IP instead of a fully qualified
- domain name or IP address accessible by remote client machines.
- It is described in further detail at: <xref linkend="qpid_faq"/>
- </para><para>
- To
- remedy this issue you can set the
- <emphasis>java.rmi.server.hostname</emphasis> system property to control the
- hostname/ip reported to the RMI runtime when advertising the JMX
- ConnectorServer. This can also be used to dictate the address
- returned on a computer with multiple network interfaces to
- control reachability. To do so, add the value
- <emphasis>-Djava.rmi.server.hostname=&lt;desired hostname/ip&gt;</emphasis>
- to the QPID_OPTS environment variable before starting the
- <emphasis>qpid-server</emphasis> script.
- </para>
-<!--h3--></section>
-<!--h2--></section>
-</section>
diff --git a/doc/book/src/java-broker/Qpid-JMX-Management-Console-User-Guide.xml b/doc/book/src/java-broker/Qpid-JMX-Management-Console-User-Guide.xml
deleted file mode 100644
index 35bb5dfbe8..0000000000
--- a/doc/book/src/java-broker/Qpid-JMX-Management-Console-User-Guide.xml
+++ /dev/null
@@ -1,793 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-JMX-Management-Console-User-Guide"><title>
- Qpid JMX Management Console User Guide
- </title><section role="h1" id="QpidJMXManagementConsoleUserGuide-QpidJMXManagementConsoleUserGuide"><title>
- Qpid JMX Management Console User Guide
- </title>
-
-
- <para>
-
- The Qpid JMX Management Console is a standalone Eclipse RCP
- application for managing and monitoring the Qpid Java server
- utilising its JMX management interfaces.
- </para><para>
- This guide will give an overview of configuring the console, the
- features supported by it, and how to make use of the console in
- managing the various JMX Management Beans (MBeans) offered by the
- Qpid Java server.
- </para>
-<!--h1--></section>
-
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-Startup-26Configuration"><title>
-
- Startup &amp; Configuration
- </title>
-
- <para>
-
- </para>
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-Startup"><title>
- Startup
- </title>
-
- <para>
-
- The console can be started in the following way, depending on
- platform:
- </para><itemizedlist>
- <listitem><para>
- <emphasis>Windows:</emphasis> by running the <emphasis>qpidmc.exe</emphasis> executable
- file.
- </para></listitem>
- <listitem><para>
- <emphasis>Linux:</emphasis> by running the <emphasis>qpidmc</emphasis> executable.
- </para></listitem>
- <listitem><para>
- <emphasis>Mac OS X:</emphasis> by launching the <emphasis>Qpid Management
- Console.app</emphasis> application bundle.
- </para></listitem>
- </itemizedlist><para>
-
- </para>
- </section>
-
-
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-SSLconfiguration"><title>
- SSL
- configuration
- </title>
-
- <para>
-
- Newer Qpid Java servers can protect their JMX connections with
- SSL, and this is enabled by default. When attempting to connect
- to a server with this enabled, the console must be able to verify
- the SSL certificate presented to it by the server or the
- connection will fail.
- </para><para>
- If the server makes use of an SSL certificate signed by a known
- Signing CA (Certification Authority) then the console needs no
- extra configuration, and will make use of Java's default
- system-wide CA TrustStore for certificate verification (you may
- however have to update the system-wide default CA TrustStore if
- your certified is signed by a less common CA that is not already
- present in it).
- </para><para>
- If however the server is equipped with a self-signed SSL
- certificate, then the management console must be provided with an
- appropriate SSL TrustStore containing the public key for the SSL
- certificate, so that it is able to validate it when presented by
- the server. The server ships with a script to create an example
- self-signed SSL certificate, and store the relevant entries in a
- KeyStore and matching TrustStore. This script can serve as a
- guide on how to use the Java Keytool security utility to
- manipulate your own stores, and more information can be found in
- the JSSE Reference Guide:
- <ulink url="http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores">http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores</ulink>.
- </para><para>
- Supplying the necessary details to the console is performed by
- setting the <emphasis>javax.net.ssl.trustStore</emphasis> and
- <emphasis>javax.net.ssl.trustStorePassword</emphasis> environment variables
- when starting it. This can be done at the command line, but the
- preferred option is to set the configuration within the
- <emphasis>qpidmc.ini</emphasis> launcher configuration file for repeated
- usage. This file is equipped with a template to ease
- configuration, this should be uncommented and edited to suit your
- needs. It can be found in the root of the console releases for
- Windows, and Linux. For Mac OS X the file is located within the
- consoles <emphasis>.app</emphasis> application bundle, and to locate and edit
- it you must select <emphasis>'Show Package Contents'</emphasis> when
- accessing the context menu of the application, then browse to the
- <emphasis>Contents/MacOS</emphasis> sub folder to locate the file.
- </para>
-<!--h2--></section>
-
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-JMXMPconfiguration"><title>
- JMXMP
- configuration
- </title>
-
- <para>
-
- Older releases of the Qpid Java server can make use of the Java
- Management Extensions Messaging Protocol (JMXMP) to provide
- protection for their JMX connections. This occurs when the server
- has its main configuration set with the management
- <emphasis>'security-enabled'</emphasis> property set to true.
- </para><para>
- In order to connect to this configuration of server, the console
- needs an additional library that is not included within the Java
- SE platform and cannot be distributed with the console due to
- licensing restrictions.
- </para><para>
- You can download the JMX Remote API 1.0.1_04 Reference
- Implementation from the Sun website <xref linkend="qpid_download.jsp"/>. The included
- <emphasis>jmxremote-1_0_1-bin/lib/jmxremote_optional.jar</emphasis> file must
- be added to the <emphasis>plugins/jmxremote.sasl_1.0.1</emphasis> folder of
- the console release (again, in Mac OS X you will need to select
- <emphasis>'Show package contents'</emphasis> from the context menu whilst
- selecting the management console bundle in order to reveal the
- inner file tree).
- </para><para>
- Following this the console will automatically load the JMX Remote
- Optional classes and negotiate the SASL authentication profile
- type when encountering a JMXMP enabled Qpid Java server.
- </para>
-<!--h2--></section>
-<!--h1--></section>
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-ManagingServerConnections"><title>
-
- Managing Server Connections
- </title>
-
- <para>
-
- </para>
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-MainToolbar"><title>
- Main Toolbar
- </title>
-
- <para>
-
- The main toolbar of the console can be seen in the image below.
- The left most buttons respectively allow for adding a new server
- connection, reconnecting to an existing server selected in the
- connection tree, disconnecting the selected server connection,
- and removing the server from the connection tree.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113098.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
-
-
- Beside these buttons is a combo for selecting the refresh
- interval; that is, how often the console requests updated
- information to display for the currently open area in the main
- view. Finally, the right-most button enables an immediate update.
- </para>
- </section>
-
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-Connectingtoanewserver"><title>
- Connecting
- to a new server
- </title>
-
- <para>
-
- To connect to a new server, press the <emphasis>Add New Server</emphasis>
- toolbar button, or select the <emphasis>Qpid Manager -&gt; Add New
- Connection</emphasis> menu item. At this point a dialog box will be
- displayed requesting the server details, namely the server
- hostname, management port, and a username and password. An
- example is shown below:
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113099.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
-
- Once all the required details are entered, pressing Connect will
- initiate a connection attempt to the server. It the attempt fails
- a reason will be shown and the server will not be added to the
- connection tree. If the attempt is successful the server will be
- added to the connections list and the entry expanded to show the
- initial administration MBeans the user has access to and any
- VirtualHosts present on the server, as can be seen in the figure
- below.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113100.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
-
- If the server supports a newer management API than the console in
- use, once connected this initial screen will contain a message on
- the right, indicating an upgraded console should be sought by the
- user to ensure all management functionality supported by the
- server is being utilised.
- </para>
-<!--h2--></section>
-
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-Reconnectingtoaserver"><title>
- Reconnecting
- to a server
- </title>
-
- <para>
-
- If a server has been connected to previously, it will be saved as
- an entry in the connection tree for further use. On subsequent
- connections the server can simply be selected from the tree and
- using the <emphasis>Reconnect</emphasis> toolbar button or <emphasis>Qpid Manager
- -&gt; Reconnect</emphasis> menu item. At this stage the console will
- prompt simply for the username and password with which the user
- wishes to connect, and following a successful connection the
- screen will appear as shown previously above.
- </para>
-<!--h2--></section>
-
-
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-Disconnectingfromaserver"><title>
- Disconnecting
- from a server
- </title>
-
- <para>
-
- To disconnect from a server, select the connection tree node for
- the server and press the <emphasis>Disconnect</emphasis> toolbar button, or
- use the <emphasis>Qpid Manager -&gt; Disconnect</emphasis> menu option.
- </para>
-<!--h2--></section>
-
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-Removingaserver"><title>
- Removing a
- server
- </title>
-
- <para>
-
- To remove a server from the connection list, select the
- connection tree node for the server and press the <emphasis>Remove</emphasis>
- toolbar button, or use the <emphasis>Qpid Manager -&gt; Remove
- Connection</emphasis> menu option.
- </para>
-<!--h2--></section>
-<!--h1--></section>
-
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-Navigatingaconnectedserver"><title>
- Navigating a connected server
- </title>
-
- <para>
-
- Once connected to a server, the various areas available for
- administration are accessed using the Qpid Connections tree at
- the left side of the application. To open a particular MBean from
- the tree for viewing, simply select it in the tree and it will be
- opened in the main view.
- <mediaobject><imageobject><imagedata fileref="images/3113101.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- As there may be vast numbers of Queues, Connections, and
- Exchanges on the server these MBeans are not automatically added
- to the tree along with the general administration MBeans.
- Instead, dedicated selection areas are provided to allow users to
- select which Queue/Connection/Exchange they wish to view or add
- to the tree. These areas can be found by clicking on the
- Connections, Exchanges, and Queues nodes in the tree under each
- VirtualHost, as shown in the figure above. One or more MBeans may
- be selected and added to the tree as Favourites using the button
- provided. These settings are saved for future use, and each time
- the console connects to the server it will check for the presence
- of the MBean previously in the tree and add them if they are
- still present. Queue/Connection/Exchange MBeans can be removed
- from the tree by right clicking on them to expose a context menu
- allowing deletion.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113102.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- As an alternative way to open a particular MBean for viewing,
- without first adding it to the tree, you can simply double click
- an entry in the table within the Queue/Connection/Exchange
- selection areas to open it immediately. It is also possible to
- open some MBeans like this whilst viewing certain other MBeans.
- When opening an MBean in either of these ways, a Back button is
- enabled in the top right corner of the main view. Using this
- button will return you to the selection area or MBean you were
- previously viewing. The history resets each time the tree is used
- to open a new area or MBean.
- </para>
-<!--h1--></section>
-
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-ConfigurationManagementMBean"><title>
-
- ConfigurationManagement MBean
- </title>
-
- <para>
-
- The ConfigurationManagement MBean is available on newer servers,
- to users with admin level management rights. It offers the
- ability to perform a live reload of the <emphasis>Security</emphasis>
- sections defined in the main server configuration file (e.g.
- defaults to: <emphasis>etc/config.xml</emphasis>). This is mainly to allow
- updating the server Firewall configuration to new settings
- without a restart, and can be performed by clicking the Execute
- button and confirming the prompt which follows.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113103.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para>
-<!--h1--></section>
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-LoggingManagementMBean"><title>
-
- LoggingManagement MBean
- </title>
-
- <para>
-
- The LoggingManagement MBean is available on newer servers, and
- accessible by admin level users. It allows live alteration of the
- logging behaviour, both at a Runtime-only level and at the
- configuration file level. The latter can optionally affect the
- Runtime configuration, either through use of the servers
- automated LogWatch ability which detects changes to the
- configuration file and reloads it, or by manually requesting a
- reload. This functionality is split across two management tabs,
- Runtime Options and ConfigurationFile Options.
- </para>
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-RuntimeOptions"><title>
- Runtime
- Options
- </title>
-
- <para>
-
- <mediaobject><imageobject><imagedata fileref="images/3113104.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- The Runtime Options tab allows manipulation of the logging
- settings without affecting the configuration files (this means
- the changes will be lost when the server restarts), and gives
- individual access to every Logger active within the server.
- </para><para>
- As shown in the figure above, the table in this tab presents the
- Effective Level of each Logger. This is because the Loggers form
- a hierarchy in which those without an explicitly defined (in the
- logging configuration file) Level will inherit the Level of their
- immediate parent; that is, the Logger whose full name is a prefix
- of their own, or if none satisfy that condition then the
- RootLogger is their parent. As example, take the
- <emphasis>org.apache.qpid</emphasis> Logger. It is parent to all those below
- it which begin with <emphasis>org.apache.qpid</emphasis> and unless they have
- a specific Level of their own, they will inherit its Level. This
- can be seen in the figure, whereby all the children Loggers
- visible have a level of WARN just like their parent, but the
- RootLogger Level is INFO; the children have inherited the WARN
- level from <emphasis>org.apache.qpid</emphasis> rather than INFO from the
- RootLogger.
- </para><para>
- To aid with this distinction, the Logger Levels that are
- currently defined in the configuration file are highlighted in
- the List. Changing these levels at runtime will also change the
- Level of all their children which haven't been set their own
- Level using the runtime options. In the latest versions of the
- LoggingManagement MBean, it is possible to restore a child logger
- that has had an explicit level se, to inheriting that of its
- parent by setting it to an INHERITED level that removes any
- previously set Level of its own.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113105.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- In order to set one of more Loggers to a new Level, they should
- be selected in the table (or double click an individual Logger to
- modify it) and the <emphasis>Edit Selected Logger(s)</emphasis> button
- pressed to load the dialog shown above. At this point, any of the
- available Levels supported by the server can be applied to the
- Loggers selected and they will immediately update, as will any
- child Loggers without their own specific Level.
- </para><para>
- The RootLogger can be similarly edited using the button at the
- bottom left of the window.
- </para>
-<!--h2--></section>
-
- <section role="h2" id="QpidJMXManagementConsoleUserGuide-ConfigurationFileOptions"><title>
- ConfigurationFile
- Options
- </title>
-
- <para>
-
- The ConfigurationFile Options tab allows alteration of the Level
- settings for the Loggers defined in the configuration file,
- allowing changes to persist following a restart of the server.
- Changes made to the configuration file are only applied
- automatically while the sever is running if it was configured to
- enable the LogWatch capability, meaning it will monitor the
- configuration file for changes and apply the new configuration
- when the change is detected. If this was not enabled, the changes
- will be picked up when the server is restarted. The status of the
- LogWatch feature is shown at the bottom of the tab.
- Alternatively, in the latest versions of the LoggingManagement
- MBean it is possible to reload the logging configuration file on
- demand.
- </para><para>
- Manipulating the Levels is as on the Runtime Options tab, either
- double-click an individual Logger entry or select multiple
- Loggers and use the button to load the dialog to set the new
- Level.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113106.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- One issue to note of when reloading the configuration file
- settings, either automatically using LogWatch or manually, is
- that any Logger set to a specific Level using the Runtime Options
- tab that is not defined in the configuration file will maintain
- that Level when the configuration file is reloaded. In other
- words, if a Logger is defined in the configuration file, then the
- configuration file will take precedence at reload, otherwise the
- Runtime options take precedence.
- </para><para>
- This situation will be immediately obvious by examining the
- Runtime Options tab to see the effective Level of each Logger
- – unless it has been altered with the RuntimeOptions or
- specifically set in the configuration file, a Logger Level should
- match that of its parent. In the latest versions of the
- LoggingManagement MBean, it is possible to use the RuntimeOptions
- to restore a child logger to inheriting from its parent by
- setting it with an INHERITED level that removes any previously
- set Level of its own.
-
- </para>
-<!--h2--></section>
-<!--h1--></section>
-
-
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-ServerInformationMBean"><title>
- ServerInformation MBean
- </title>
-
- <para>
-
- <mediaobject><imageobject><imagedata fileref="images/3113107.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- The ServerInformation MBean currently only conveys various pieces
- of version information to allow precise identification of the
- server version and its management capabilities. In future it is
- likely to convey additional server-wide details and/or
- functionality.
- </para>
-<!--h1--></section>
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-UserManagementMBean"><title>
-
- UserManagement MBean
- </title>
-
- <para>
-
- The UserManagement MBean is accessible by admin level users, and
- allows manipulation of existing user accounts and creation of new
- user accounts.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113108.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
-
- To add a new user, press the <emphasis>Add New User</emphasis> button, which
- will load the dialog shown below.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113109.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- Here you may enter the new users Username, Password, and select
- their JMX Management Rights. This controls whether or not they
- have access to the management interface, and if so what
- capabilities are accessible. <emphasis>Read Only</emphasis> access allows
- undertaking any operations that do not alter the server state,
- such as viewing messages. <emphasis>Read + Write</emphasis> access allows use
- of all operations which are not deemed admin-only (such as those
- in the UserManagement MBean itself). <emphasis>Admin</emphasis> access allows
- a user to utilize any operation, and view the admin-only MBeans
- (currently these are ConfigurationManagement, LoggingManagement,
- and UserManagement).
- </para><para>
- One or more users at a time may be deleted by selecting them in
- the table and clicking the <emphasis>Delete User(s)</emphasis> button. The
- console will then prompt for confirmation before undertaking the
- removals. Similarly, the access rights for one or more users may
- be updated by selecting them in the table and clicking the
- <emphasis>Set Rights</emphasis> button. The console will then display a
- dialog enabling selection of the new access level and
- confirmation to undertake the update.
- </para><para>
- An individual user password may be updated by selecting the user
- in the table in and clicking the <emphasis>Set Password</emphasis> button.
- The console will then display a dialog enabling input of the new
- password and confirmation to undertake the update.
- </para><para>
-
- The server caches the user details in memory to aid performance.
- If may sometimes be necessary to externally modify the password
- and access right files on disk. In order for these changes to be
- known to the server without a restart, it must be instructed to
- reload the file contents. This can be done using the provided
- <emphasis>Reload User Details</emphasis> button (on older servers, only the
- management rights file is reloaded, on newer servers both files
- are. The description on screen will indicate the behaviour).
- After pressing this button the console will seek confirmation
- before proceeding.
- </para>
-<!--h1--></section>
-
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-VirtualHostManagerMBean"><title>
-
- VirtualHostManager MBean
- </title>
-
- <para>
-
- Each VirtualHost in the server has an associated
- VirtualHostManager MBean. This allows viewing, creation, and
- deletion of Queues and Exchanges within the VirtualHost.
- </para><para>
- Clicking the <emphasis>Create</emphasis> button in the Queue section will
- open a dialog allowing specification of the Name, Owner
- (optional), and durability properties of the new Queue, and
- confirmation of the operation.
- </para><para>
- One or more Queues may be deleted by selecting them in the table
- and clicking the <emphasis>Delete</emphasis> button. This will unregister the
- Queue bindings, remove the subscriptions and delete the Queue(s).
- The console will prompt for confirmation before undertaking the
- operation.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113110.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- Clicking the <emphasis>Create</emphasis> button in the Exchange section will
- open a dialog allowing specification of the Name, Type, and
- Durable attributes of the new Exchange, and confirmation of the
- operation.
- </para><para>
- One or more Exchanges may be deleted by selecting them in the
- table and clicking the <emphasis>Delete</emphasis> button. This will
- unregister all the related channels and Queue bindings then
- delete the Exchange(s). The console will prompt for confirmation
- before undertaking the operation.
- </para><para>
-
- Double-clicking on a particular Queue or Exchange name in the
- tables will open the MBean representing it.
- </para>
-<!--h1--></section>
-
-
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-Notifications"><title>
-
- Notifications
- </title>
-
- <para>
-
- MBeans on the server can potentially send Notifications that
- users may subscribe to. When managing an individual MBean that
- offers Notifications types for subscription, the console supplies
- a Notifications tab to allow (un)subscription to the
- Notifications if desired and viewing any that are received
- following subscription.
- </para><para>
- In order to provide quicker access to/awareness of any received
- Notifications, each VirtualHost area in the connection tree has a
- Notifications area that aggregates all received Notifications for
- MBeans in that VirtualHost. An example of this can be seen in the
- figure below.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113111.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- All received Notifications will be displayed until such time as
- the user removes them, either in this aggregated view, or in the
- Notifications area of the individual MBean that generated the
- Notification.
- </para><para>
- They may be cleared selectively or all at once. To clear
- particular Notifications, they should be selected in the table
- before pressing the <emphasis>Clear</emphasis> button. To clear all
- Notifications, simply press the <emphasis>Clear</emphasis> button without
- anything selected in the table, at which point the console will
- request confirmation of this clear-all action.
- </para>
-<!--h1--></section>
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-ManagingQueues"><title>
- Managing
- Queues
- </title>
-
- <para>
-
- As mentioned in earlier discussion of Navigation, Queue MBeans
- can be opened either by double clicking an entry in the Queues
- selection area, or adding a queue to the tree as a favourite and
- clicking on its tree node. Unique to the Queue selection screen
- is the ability to view additional attributes beyond just that of
- the Queue Name. This is helpful for determining which Queues
- satisfy a particular condition, e.g. having &lt;X&gt; messages on
- the queue. The example below shows the selection view with
- additional attributes <emphasis>Consumer Count, Durable, MessageCount,
- and QueueDepth</emphasis> (selected using the <emphasis>Select
- Attributes</emphasis> button at the bottom right corner of the
- table)<emphasis>.</emphasis>
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113112.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- Upon opening a Queue MBean, the Attributes tab is displayed, as
- shown below. This allows viewing the value all attributes,
- editing those which are writable values (highlighted in blue) if
- the users management permissions allow, viewing descriptions of
- their purpose, and graphing certain numerical attribute values as
- they change over time.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113113.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- The next tab contains the operations that can be performed on the
- queue. The main table serves as a means of viewing the messages
- on the queue, and later for selecting specific messages to
- operate upon. It is possible to view any desired range of
- messages on the queue by specifying the visible range using the
- fields at the top and pressing the <emphasis>Set</emphasis> button. Next to
- this there are helper buttons to enable faster browsing through
- the messages on the queue; these allow moving forward and back by
- whatever number of messages is made visible by the viewing range
- set. The Queue Position column indicates the position of each
- message on the queue, but is only present when connected to newer
- servers as older versions cannot provide the necessary
- information to show this (unless only a single message position
- is requested).
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113114.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- Upon selecting a message in the table, its header properties and
- redelivery status are updated in the area below the table. Double
- clicking a message in the table (or using the <emphasis>View Message
- Content</emphasis> button to its right) will open a dialog window
- displaying the contents of the message.
- </para><para>
- One or more messages can be selected in the table and moved to
- another queue in the VirtualHost by using the <emphasis>Move
- Message(s)</emphasis> button, which opens a dialog to enable selection
- of the destination and confirmation of the operation. Newer
- servers support the ability to similarly copy the selected
- messages to another queue in a similar fashion, or delete the
- selected messages from the queue after prompting for
- confirmation.
- </para><para>
- Finally, all messages (that have not been acquired by consumers)
- on the queue can be deleted using the <emphasis>Clear Queue</emphasis>
- button, which will generate a prompt for confirmation. On newer
- servers, the status bar at the lower left of the application will
- report the number of messages actually removed.
- </para>
-<!--h1--></section>
-
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-ManagingExchanges"><title>
-
- Managing Exchanges
- </title>
-
- <para>
- Exchange MBeans are opened for management operations in similar
- fashion as described for Queues, again showing an Attributes tab
- initially, with the Operations tab next:
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113115.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- Of the four default Exchange Types <emphasis>(direct, fanout, headers,
- and topic)</emphasis> all but <emphasis>headers</emphasis> have their bindings
- presented in the format shown above. The left table provides the
- binding/routing keys present in the exchange. Selecting one of
- these entries in the table prompts the right table to display all
- the queues associated with this key. Pressing the <emphasis>Create</emphasis>
- button opens a dialog allowing association of an existing queue
- with the entered Binding.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113116.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- The <emphasis>headers</emphasis> Exchange type (default instantiation
- <emphasis>amq.match or amq.headers</emphasis>) is presented as below:
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113117.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- In the previous figure, the left table indicates the binding
- number, and the Queue associated with the binding. Selecting one
- of these entries in the table prompts the right table to display
- the header values that control when the binding matches an
- incoming message.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113118.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- </para><para>
- Pressing the <emphasis>Create</emphasis> button when managing a
- <emphasis>headers</emphasis> Exchange opens a dialog allowing creation of a
- new binding, associating an existing Queue with a particular set
- of header keys and values. The <emphasis>x-match</emphasis> key is required,
- and instructs the server whether to match the binding with
- incoming messages based on ANY or ALL of the further key-value
- pairs entered. If it is desired to enter more than 4 pairs, you
- may press the <emphasis>Add additional field</emphasis> button to create a
- new row as many times as is required.
-
- When managing a <emphasis>headers</emphasis> Exchange, double clicking an
- entry in the left-hand table will open the MBean for the Queue
- specified in the binding properties.
- </para><para>
- When managing another Exchange Type, double clicking the Queue
- Name in the right-hand table will open the MBean of the Queue
- specified.
- </para>
-<!--h1--></section>
-
- <section role="h1" id="QpidJMXManagementConsoleUserGuide-ManagingConnections"><title>
-
- Managing Connections
- </title>
-
- <para>
-
- Exchange MBeans are opened for management operations in similar
- fashion as described for Queues, again showing an Attributes tab
- initially, with the Operations tab next, and finally a
- Notifications tab allowing subscription and viewing of
- Notifications. The Operations tab can be seen in the figure
- below.
- </para><para>
- <mediaobject><imageobject><imagedata fileref="images/3113119.png" format="PNG" scalefit="1"/></imageobject><textobject><phrase/></textobject><caption><para/></caption></mediaobject>
- The main table shows the properties of all the Channels that are
- present on the Connection, including whether they are
- <emphasis>Transactional</emphasis>, the <emphasis>Number of Unacked Messages</emphasis>
- on them, and the <emphasis>Default Queue</emphasis> if there is one (or
- <emphasis>null</emphasis> if there is not).
- </para><para>
- The main operations supported on a connection are Commiting and
- Rolling Back of Transactions on a particular Channel, if the
- Channel is Transactional. This can be done by selecting a
- particular Channel in the table and pressing the <emphasis>Commit
- Transactions</emphasis> or <emphasis>Rollback Transactions</emphasis> buttons at
- the lower right corner of the table, at which point the console
- will prompt for confirmation of the action. These buttons are
- only active when the selected Channel in the table is
- Transactional.
- </para><para>
- The final operation supported is closing the Connection. After
- pressing the <emphasis>Close Connection</emphasis> button, the console will
- prompt for confirmation of the action. If this is carried out,
- the MBean for the Connection being managed will be removed from
- the server. The console will be notified of this by the server
- and display an information dialog to that effect, as it would if
- any other MBean were to be unregistered whilst being viewed.
- </para><para>
- Double clicking a row in the table will open the MBean of the
- associated <emphasis>Default Queue</emphasis> if there is one.
- </para>
-
-<!--h1--></section>
-</section>
diff --git a/doc/book/src/java-broker/Qpid-JMX-Management-Console.xml b/doc/book/src/java-broker/Qpid-JMX-Management-Console.xml
deleted file mode 100644
index fb46f4a01a..0000000000
--- a/doc/book/src/java-broker/Qpid-JMX-Management-Console.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?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.
-
--->
-
-<chapter id="Qpid-JMX-Management-Console">
-
- <title>
- Qpid JMX Management Console
- </title>
-
- <section role="h2" id="QpidJMXManagementConsole-QpidJMXManagementConsole">
-
- <title> Qpid JMX Management Console </title>
-
- <section role="h3" id="QpidJMXManagementConsole-Overview">
-
- <title>
- Overview
- </title>
-
- <para>
- The Qpid JMX Management Console is a standalone Eclipse
- RCP application that communicates with the broker using
- JMX.
- </para>
-
- <xi:include href="Configuring-Management-Users.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
- <xi:include href="Configuring-Qpid-JMX-Management-Console.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
- <xi:include href="Management-Console-Security.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
- <xi:include href="Qpid-JMX-Management-Console-FAQ.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
- <xi:include href="Qpid-JMX-Management-Console-User-Guide.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
- <xi:include href="Qpid-Management-Features.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
-<!--h3--></section>
-<!--h2--></section>
-</chapter>
diff --git a/doc/book/src/java-broker/Qpid-Java-Broker-Management-CLI.xml b/doc/book/src/java-broker/Qpid-Java-Broker-Management-CLI.xml
deleted file mode 100644
index 84c4b7b7a4..0000000000
--- a/doc/book/src/java-broker/Qpid-Java-Broker-Management-CLI.xml
+++ /dev/null
@@ -1,159 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Java-Broker-Management-CLI"><title>
- Qpid Java Broker Management CLI
- </title>
- <section role="h2" id="QpidJavaBrokerManagementCLI-HowtobuildApacheQpidCLI"><title>
- How to
- build Apache Qpid CLI
- </title>
-
-
- <section role="h3" id="QpidJavaBrokerManagementCLI-BuildInstructionsGeneral"><title>
- Build
- Instructions - General
- </title>
-
- <para>
- At the very beginning please build Apache Qpid by refering this
- installation guide from here <xref linkend="qpid_qpid-java-build-how-to"/>.
- </para><para>
- After successfully build Apache Qpid you'll be able to start
- Apache Qpid Java broker,then only you are in a position to use
- Qpid CLI.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaBrokerManagementCLI-CheckouttheSource"><title>
- Check
- out the Source
- </title>
-
- <para>
- First check out the source from subversion repository. Please
- visit the following link for more information about different
- versions of Qpid CLI.
- </para><para>
- <xref linkend="qpid_list"/>
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaBrokerManagementCLI-Prerequisites"><title>
- Prerequisites
- </title>
-
- <para>
- For the broker code you need JDK 1.5.0_15 or later. You should
- set JAVA_HOME and include the bin directory in your PATH.
- </para><para>
- Check it's ok by executing java -v !
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaBrokerManagementCLI-BuildingApacheQpidCLI"><title>
- Building
- Apache Qpid CLI
- </title>
-
- <para>
- This project is currently having only an ant build system.Please
- install ant build system before trying to install Qpid CLI.
- </para>
-<!--h3--></section>
-
-
-
- <section role="h3" id="QpidJavaBrokerManagementCLI-Compiling"><title>
- Compiling
- </title>
-
- <para>
- To compile the source please run following command
- </para>
- <programlisting>
-ant compile
-</programlisting>
- <para>
- To compile the test source run the following command
- </para>
- <programlisting>
-ant compile-tests
-</programlisting>
-<!--h3--></section>
-
-
- <section role="h3" id="QpidJavaBrokerManagementCLI-RunningCLI"><title>
- Running CLI
- </title>
-
- <para>
- After successful compilation set QPID_CLI environment variable to
- the main source directory.(set the environment variable to the
- directory where ant build script stored in the SVN
- checkout).Please check whether the Qpid Java broker is up an
- running in the appropriate location and run the following command
- to start the Qpid CLI by running the qpid-cli script in the bin
- directory.
- </para><para>
- $QPID_CLI/bin/qpid-cli -h &lt;hostname of the broker&gt; -p
- &lt;broker running port&gt;
- For more details please have a look in to README file which ships
- with source package of Qpid CLI.
- </para>
-<!--h3--></section>
-
-
- <section role="h3" id="QpidJavaBrokerManagementCLI-Otheranttargets"><title>
- Other
- ant targets
- </title>
-
- <para>For now we are supporting those ant targets.</para>
-
- <variablelist>
- <varlistentry>
- <term>ant clean</term>
- <listitem><para>Clean the complete build including CLI build and test build.</para></listitem>
- </varlistentry>
- <varlistentry>
- <term>ant jar</term>
- <listitem><para>Create the jar file for the project without test cases.</para></listitem>
- </varlistentry>
- <varlistentry>
- <term>ant init</term>
- <listitem><para>Create the directory structure for build.</para></listitem>
- </varlistentry>
- <varlistentry>
- <term>ant compile-tests </term>
- <listitem><para>This compiles all the test source.</para></listitem>
- </varlistentry>
- <varlistentry>
- <term>ant test </term>
- <listitem><para>Run all the test cases.</para></listitem>
- </varlistentry>
-
- </variablelist>
-
-<!--h3--></section>
-<!--h2--></section>
-</section>
diff --git a/doc/book/src/java-broker/Qpid-Java-Build-How-To.xml b/doc/book/src/java-broker/Qpid-Java-Build-How-To.xml
deleted file mode 100644
index 9f3625760a..0000000000
--- a/doc/book/src/java-broker/Qpid-Java-Build-How-To.xml
+++ /dev/null
@@ -1,365 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Java-Build-HowTo"><title>
- Qpid Java Build How To
- </title>
-
- <section role="h1" id="QpidJavaBuildHowTo-BuildInstructionsGeneral"><title>
- Build
- Instructions - General
- </title>
-
- <section role="h2" id="QpidJavaBuildHowTo-Checkoutthesource"><title>
- Check out the
- source
- </title>
- <para>
- Firstly, check the source for Qpid out of our subversion
- repository:
- </para><para>
- <xref linkend="qpid_trunk"/>
- </para>
-<!--h2--></section>
- <section role="h2" id="QpidJavaBuildHowTo-Prerequisites"><title>
- Prerequisites
- </title>
- <para>
- For the broker code you need JDK 1.5.0_15 or later. You should
- set JAVA_HOME and include the bin directory in your PATH.
- </para><para>
- Check it's ok by executing java -v !
- </para><para>
- If you are wanting to run the python tests against the broker you
- will of course need a version of python.
- </para>
-<!--h2--></section>
-<!--h1--></section>
-
- <section role="h1" id="QpidJavaBuildHowTo-BuildInstructionsTrunk"><title>
- Build
- Instructions - Trunk
- </title>
- <para>
- Our build system has reverted to ant as of May 2008.
- </para><para>
- The ant target 'help' will tell you what you need to know about
- the build system.
- </para>
- <section role="h2" id="QpidJavaBuildHowTo-AntBuildScripts"><title>
- Ant Build
- Scripts
- </title>
- <para>
- Currently the Qpid java project builds using ant.
- </para><para>
- The ant build system is set up in a modular way, with a top level
- build script and template for module builds and then a module
- level build script which inherits from the template.
- </para><para>
- So, at the top level there are:
- </para><table><title/><tgroup cols="2">
- <tbody>
- <row>
- <entry>
- File
- </entry>
- <entry>
- Description
- </entry>
- </row>
- <row>
- <entry>
- build.xml
- </entry>
- <entry>
- Top level build file for the project which defines all the
- build targets
- </entry>
- </row>
- <row>
- <entry>
- common.xml
- </entry>
- <entry>
- Common properties used throughout the build system
- </entry>
- </row>
- <row>
- <entry>
- module.xml
- </entry>
- <entry>
- Template used by all modules which sets up properties for
- module builds
- </entry>
- </row>
- </tbody>
- </tgroup></table><para>
- Then, in each module subdirectory there is:
- </para><table><title/><tgroup cols="2">
- <tbody>
- <row>
- <entry>
- File
- </entry>
- <entry>
- Description
- </entry>
- </row>
- <row>
- <entry>
- build.xml
- </entry>
- <entry>
- Defines all the module values for template properties
- </entry>
- </row>
- </tbody>
- </tgroup></table>
-<!--h2--></section>
- <section role="h2" id="QpidJavaBuildHowTo-Buildtargets"><title>
- Build targets
- </title>
- <para>
- The main build targets you are probably interested in are:
- </para><table><title/><tgroup cols="2">
- <tbody>
- <row>
- <entry>
- Target
- </entry>
- <entry>
- Description
- </entry>
- </row>
- <row>
- <entry>
- build
- </entry>
- <entry>
- Builds all source code for Qpid
- </entry>
- </row>
- <row>
- <entry>
- test
- </entry>
- <entry>
- Runs the testsuite for Qpid
- </entry>
- </row>
- </tbody>
- </tgroup></table><para>
- So, if you just want to compile everything you should run the
- build target in the top level build.xml file.
- </para><para>
- If you want to build an installable version of Qpid, run the
- archive task from the top level build.xml file.
- </para><para>
- If you want to compile an individual module, simply run the build
- target from the appropriate module e.g. to compile the broker
- source
- </para>
-<!--h2--></section>
- <section role="h2" id="QpidJavaBuildHowTo-ConfiguringEclipse"><title>
- Configuring
- Eclipse
- </title>
- <para>
- 1. Run the ant build from the root directory of Java trunk.
- 2. New project -&gt; create from existing file system for broker,
- common, client, junit-toolkit, perftests, systests and each
- directory under management
- 4. Add the contents of lib/ to the build path
- 5. Setup Generated Code
- 6. Setup Dependencies
- </para>
- <section role="h3" id="QpidJavaBuildHowTo-GeneratedCode"><title>
- Generated Code
- </title>
- <para>
- The Broker and Common packages both depend on generated code.
- After running 'ant' the build/scratch directory will contain this
- generated code.
- For the broker module add build/scratch/broker/src
- For the common module add build/scratch/common/src
- </para>
-<!--h3--></section>
- <section role="h3" id="QpidJavaBuildHowTo-Dependencies"><title>
- Dependencies
- </title>
- <para>
- These dependencies are correct at the time of writting however,
- if things are not working you can check the dependencies by
- looking in the modules build.xml file:
- </para>
- <programlisting>
-for i in `find . -name build.xml` ; do echo "$i:"; grep module.depends $i ; done
-</programlisting>
- <para>
- The <emphasis>module.depend</emphasis> value will detail which other modules
- are dependencies.
- </para><para>
- broker
- </para><itemizedlist>
- <listitem><para>common
- </para></listitem>
- <listitem><para>management/common
- </para></listitem>
- </itemizedlist><para>
- client
- </para><itemizedlist>
- <listitem><para>Common
- </para></listitem>
- </itemizedlist><para>
- systest
- </para><itemizedlist>
- <listitem><para>client
- </para></listitem>
- <listitem><para>management/common
- </para></listitem>
- <listitem><para>broker
- </para></listitem>
- <listitem><para>broker/test
- </para></listitem>
- <listitem><para>common
- </para></listitem>
- <listitem><para>junit-toolkit
- </para></listitem>
- <listitem><para>management/tools/qpid-cli
- </para></listitem>
- </itemizedlist><para>
- perftests
- </para><itemizedlist>
- <listitem><para>systests
- </para></listitem>
- <listitem><para>client
- </para></listitem>
- <listitem><para>broker
- </para></listitem>
- <listitem><para>common
- </para></listitem>
- <listitem><para>junit-toolkit
- </para></listitem>
- </itemizedlist><para>
- management/eclipse-plugin
- </para><itemizedlist>
- <listitem><para>broker
- </para></listitem>
- <listitem><para>common
- </para></listitem>
- <listitem><para>management/common
- </para></listitem>
- </itemizedlist><para>
- management/console
- </para><itemizedlist>
- <listitem><para>common
- </para></listitem>
- <listitem><para>client
- </para></listitem>
- </itemizedlist><para>
- management/agent
- </para><itemizedlist>
- <listitem><para>common
- </para></listitem>
- <listitem><para>client
- </para></listitem>
- </itemizedlist><para>
- management/tools/qpid-cli
- </para><itemizedlist>
- <listitem><para>common
- </para></listitem>
- <listitem><para>management/common
- </para></listitem>
- </itemizedlist><para>
- management/client
- </para><itemizedlist>
- <listitem><para>common
- </para></listitem>
- <listitem><para>client
- </para></listitem>
- </itemizedlist><para>
- integrationtests
- </para><itemizedlist>
- <listitem><para>systests
- </para></listitem>
- <listitem><para>client
- </para></listitem>
- <listitem><para>common
- </para></listitem>
- <listitem><para>junit-toolkit
- </para></listitem>
- </itemizedlist><para>
- testkit
- </para><itemizedlist>
- <listitem><para>client
- </para></listitem>
- <listitem><para>broker
- </para></listitem>
- <listitem><para>common
- </para></listitem>
- </itemizedlist><para>
- tools
- </para><itemizedlist>
- <listitem><para>client
- </para></listitem>
- <listitem><para>common
- </para></listitem>
- </itemizedlist><para>
- client/examples
- </para><itemizedlist>
- <listitem><para>common
- </para></listitem>
- <listitem><para>client
- </para></listitem>
- </itemizedlist><para>
- broker-plugins
- </para><itemizedlist>
- <listitem><para>client
- </para></listitem>
- <listitem><para>management/common
- </para></listitem>
- <listitem><para>broker
- </para></listitem>
- <listitem><para>common
- </para></listitem>
- <listitem><para>junit-toolkit
- </para></listitem>
- </itemizedlist>
-<!--h3--></section>
-<!--h2--></section>
-
- <section role="h2" id="QpidJavaBuildHowTo-Whatnext-3F"><title>
- What next ?
- </title>
- <para>
- If you want to run your built Qpid package, see our <xref linkend="qpid_Getting-Started-Guide"/> for details of
- how to do that.
- </para><para>
- If you want to run our tests, you can use the ant test or
- testreport (produces a useful report) targets.
- </para>
-
-<!--h2--></section>
-<!--h1--></section>
-</section>
diff --git a/doc/book/src/java-broker/Qpid-Java-FAQ.xml b/doc/book/src/java-broker/Qpid-Java-FAQ.xml
deleted file mode 100644
index 2940e58138..0000000000
--- a/doc/book/src/java-broker/Qpid-Java-FAQ.xml
+++ /dev/null
@@ -1,890 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Java-FAQ"><title>
- Qpid Java FAQ
- </title>
-
- <section role="h2" id="QpidJavaFAQ-Purpose">
- <title>Purpose</title>
- <para>
- Here are a list of commonly asked questions and answers. Click on
- the the bolded questions for the answer to unfold. If you have
- any questions which are not on this list, please email our
- qpid-user list.
- </para>
-
- <section role="h3" id="QpidJavaFAQ-WhatisQpid-3F"><title>
- What is Qpid ?
- </title>
-
- <para>
- The java implementation of Qpid is a pure Java message broker
- that implements the AMQP protocol. Essentially, Qpid is a robust,
- performant middleware component that can handle your messaging
- traffic.
- </para><para>
- It currently supports the following features:
- </para><itemizedlist>
- <listitem><para>High performance header-based routing for messages
- </para></listitem>
- <listitem><para>All features required by the JMS 1.1 specification. Qpid
- passes all tests in the Sun JMS compliance test suite
- </para></listitem>
- <listitem><para>Transaction support
- </para></listitem>
- <listitem><para>Persistence using the high performance Berkeley DB Java
- Edition. The persistence layer is also pluggable should an
- alternative implementation be required. The BDB store is
- available from the <xref linkend="qpid_3rd-Party-Libraries"/> page
- </para></listitem>
- <listitem><para>Pluggable security using SASL. Any Java SASL provider can be
- used
- </para></listitem>
- <listitem><para>Management using JMX and a custom management console built
- using Eclipse RCP
- </para></listitem>
- <listitem><para>Naturally, interoperability with other clients including the
- Qpid .NET, Python, Ruby and C++ implementations
- </para></listitem>
- </itemizedlist>
- <!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-WhyamIgettingaConfigurationExceptionatbrokerstartup-3F"><title>
- Why am I getting a ConfigurationException at broker startup ?
- </title>
-
- <section role="h4" id="QpidJavaFAQ-InvocationTargetException"><title>
- InvocationTargetException
- </title>
- <para>
- If you get a java.lang.reflect.InvocationTargetException on
- startup, wrapped as ConfigurationException like this:
- </para>
- <programlisting>
-Error configuring message broker: org.apache.commons.configuration.ConfigurationException: java.lang.reflect.InvocationTargetException
-2008-09-26 15:14:56,529 ERROR [main] server.Main (Main.java:206) - Error configuring message broker: org.apache.commons.configuration.ConfigurationException: java.lang.reflect.InvocationTargetException
-org.apache.commons.configuration.ConfigurationException: java.lang.reflect.InvocationTargetException
-at org.apache.qpid.server.security.auth.database.ConfigurationFilePrincipalDatabaseManager.initialisePrincipalDatabase(ConfigurationFilePrincipalDatabaseManager.java:158)
-at org.apache.qpid.server.security.auth.database.ConfigurationFilePrincipalDatabaseManager.initialisePrincipalDatabases(ConfigurationFilePrincipalDatabaseManager.java:87)
-at org.apache.qpid.server.security.auth.database.ConfigurationFilePrincipalDatabaseManager.&lt;init&gt;(ConfigurationFilePrincipalDatabaseManager.java:56)
-at org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry.initialise(ConfigurationFileApplicationRegistry.java:117)
-at org.apache.qpid.server.registry.ApplicationRegistry.initialise(ApplicationRegistry.java:79)
-at org.apache.qpid.server.registry.ApplicationRegistry.initialise(ApplicationRegistry.java:67)
-at org.apache.qpid.server.Main.startup(Main.java:260)
-at org.apache.qpid.server.Main.execute(Main.java:196)
-at org.apache.qpid.server.Main.&lt;init&gt;(Main.java:96)
-at org.apache.qpid.server.Main.main(Main.java:454)
-at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
-at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
-at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
-at java.lang.reflect.Method.invoke(Method.java:597)
-at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
-Caused by: java.lang.reflect.InvocationTargetException
-at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
-at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
-at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
-at java.lang.reflect.Method.invoke(Method.java:597)
-at org.apache.qpid.server.security.auth.database.ConfigurationFilePrincipalDatabaseManager.initialisePrincipalDatabase(ConfigurationFilePrincipalDatabaseManager.java:148)
-</programlisting>
- <para>
- .. then it means you have a missing password file.
- </para><para>
- You need to create a password file for your deployment and update
- your config.xml to reflect the location of the password file for
- your instance.
- </para><para>
- The config.xml can be a little confusing in terms of element
- names and file names for passwords.
- </para><para>
- To do this, you need to edit the passwordDir element for the
- broker, which may have a comment to that effect:
- </para>
- <programlisting>
-&lt;passwordDir&gt;&lt;!-- Change to the location --&gt;&lt;/passwordDir&gt;
-</programlisting>
- <para>
- The file should be named passwd by default but if you want to you
- can change this by editing this element:
- </para>
- <programlisting>
-&lt;value&gt;${passwordDir}/passwd&lt;/value&gt;
-</programlisting>
- <!--h4--></section>
-
-
- <section role="h4" id="QpidJavaFAQ-Cannotlocateconfigurationsourcenull-2Fvirtualhosts.xml"><title>
- Cannot locate configuration source null/virtualhosts.xml
- </title>
-
- <para>
- If you get this message, wrapped inside a ConfigurationException
- then you've come across a known issue, see JIRA <xref linkend="qpid_QPID-431"/>
- </para><para>
- The work around is to use a qualified path as the parameter value
- for your -c option, rather than (as you migth be) starting the
- broker from your installed etc directory. Even going up one level
- and using a path relative to your £QPID_HOME directory
- would sort this e.g qpid-server -c ./etc/myconfig.xml
- </para>
-<!--h4--></section>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIruntheQpidbroker-3F"><title>
- How do I run
- the Qpid broker ?
- </title>
-
- <para>
- The broker comes with a script for unix/linux/cygwin called
- qpid-server, which can be found in the bin directory of the
- installed package. This command can be executed without any
- paramters and will then use the default configuration file
- provided on install.
- </para><para>
- For the Windows OS, please use qpid-server.bat.
- </para><para>
- There's no need to set your classpath for QPID as the scripts
- take care of that by adding jar's with classpath defining
- manifest files to your classpath.
- </para><para>
- For more information on running the broker please see our
- <xref linkend="Getting-Started"/> page.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowcanIcreateaconnectionusingaURL-3F"><title>
- How can I
- create a connection using a URL ?
- </title>
-
- <para>
- Please see the <xref linkend="qpid_Connection-URL-Format"/> documentation.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIrepresentaJMSDestinationstringwithQPID-3F"><title>
- How
- do I represent a JMS Destination string with QPID ?
- </title>
-
- <section role="h4" id="QpidJavaFAQ-Queues"><title>
- Queues
- </title>
-
- <para>
- A queue can be created in QPID using the following URL format.
- </para><para>
- direct://amq.direct/&lt;Destination&gt;/&lt;Queue
- Name&gt;
- </para><para>
- For example:
- direct://amq.direct/&lt;Destination&gt;/simpleQueue
- </para><para>
- Queue names may consist of any mixture of digits, letters, and
- underscores.
- </para><para>
- The <xref linkend="BindingURLFormat"/> is described in more
- detail on it's own page.
- </para>
-<!--h4--></section>
-
- <section role="h4" id="QpidJavaFAQ-Topics"><title>
- Topics
- </title>
-
- <para>
- A topic can be created in QPID using the following URL format.
- </para><para>
- topic://amq.topic/&lt;Topic Subscription&gt;/
- </para><para>
- The topic subscription may only contain the letters A-Z and a-z
- and digits 0-9.
- </para><para>
- The topic subscription is formed from a series of words that may
- only contain the letters A-Z and a-z and digits 0-9.
- The words are delimited by dots. Each dot represents a new level.
- </para><para>
- For example: stocks.nyse.ibm
- </para><para>
- Wildcards can be used on subscription with the following meaning.
- </para><itemizedlist>
- <listitem><para>match a single level
- # match zero or more levels
- </para></listitem>
- </itemizedlist><para>
- For example:
- With two clients
- 1 - stocks.*.ibm
- 2 - stocks.#.ibm
- </para><para>
- Publishing stocks.nyse.ibm will be received by both
- clients but stocks.ibm and stocks.world.us.ibm
- will only be received by client 2.
- </para><para>
- The topic currently does not support wild cards.
- </para>
-<!--h4--></section>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIconnecttothebrokerusingJNDI-3F"><title>
- How do I
- connect to the broker using JNDI ?
- </title>
-
- <para>
- see <xref linkend="How-to-Use-JNDI"/>
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-I-27musingSpringandWeblogiccanyouhelpmewiththeconfigurationformovingovertoQpid-3F"><title>
- I'm using Spring and Weblogic - can you help me with the
- configuration for moving over to Qpid ?
- </title>
-
- <para>
- Here is a donated Spring configuration file <ulink
- url="http://qpid.apache.org/qpid-java-faq.data/appContext.zip">appContext.zip</ulink>
- which shows the config for Qpid side by side with
- Weblogic. HtH !
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIconfigurethelogginglevelforQpid-3F"><title>
- How do
- I configure the logging level for Qpid ?
- </title>
-
- <para>
- The system property
- </para>
- <programlisting>
-amqj.logging.level
-</programlisting>
- <para>
- can be used to configure the logging level.
- For the broker, you can use the environment variable
- AMQJ_LOGGING_LEVEL which is picked up by the qpid-run script
- (called by qpid-server to start the broker) at runtime.
- </para><para>
- For client code that you've written, simply pass in a system
- property to your command line to set it to the level you'd like
- i.e.
- </para>
- <programlisting>
--Damqj.logging.level=INFO
-</programlisting>
- <para>
- The log level for the broker defaults to INFO if the env variable
- is not set, but you may find that your log4j properties affect
- this. Setting the property noted above should address this.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowcanIconfiguremyapplicationtouseQpidclientlogging-3F"><title>
- How can I configure my application to use Qpid client
- logging?
- </title>
-
- <para>
- If you don't already have a logging implementation in your
- classpath you should add slf4-log4j12-1.4.0.jar and
- log4j-1.2.12.jar.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowcanIconfigurethebroker-3F"><title>
- How can I
- configure the broker ?
- </title>
-
- <para>
- The broker configuration is contained in the
- &lt;installed-dir&gt;/etc/config.xml file. You can copy and edit
- this file and then specify your own configuration file as a
- parameter to the startup script using the -c flag i.e.
- qpid-server -c &lt;your_config_file's_path&gt;
- </para><para>
- For more detailed information on configuration, please see
- <xref linkend="qpid_Qpid-Design---Configuration"/>
- </para><para>
-
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-Whatportsdoesthebrokeruse"><title>
- What ports
- does the broker use?
- </title>
-
- <para>
- The broker defaults to use port 5672 at startup for AMQP
- traffic.
- If the management interface is enabled it starts on port 8999 by
- default.
- </para><para>
- The JMX management interface actually requires 2 ports to
- operate, the second of which is indicated to the client
- application during connection initiation to the main (default:
- 8999) port. Previously this second port has been chosen at random
- during broker startup, however since Qpid 0.5 this has been fixed
- to a port 100 higher than the main port(ie Default:9099) in order
- to ease firewall navigation.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowcanIchangetheportthebrokerusesatruntime-3F"><title>
- How
- can I change the port the broker uses at runtime ?
- </title>
-
- <para>
- The broker defaults to use port 5672 at startup for AMQP
- traffic.
- The broker also uses port 8999 for the JMX Management interface.
- </para><para>
- To change the AMQP traffic port use the -p flag at startup. To
- change the management port use -m
- i.e. qpid-server -p &lt;port_number_to_use&gt; -m
- &lt;port_number_to_use&gt;
- </para><para>
- Use this to get round any issues on your host server with port
- 5672/8999 being in use/unavailable.
- </para><para>
- For additional details on what ports the broker uses see <xref linkend="QpidJavaFAQ-Whatportsdoesthebrokeruse"/> FAQ
- entry.
- For more detailed information on configuration, please see
- <xref linkend="qpid_Qpid-Design---Configuration"/>
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-WhatcommandlineoptionscanIpassintotheqpidserverscript-3F"><title>
- What command line options can I pass into the qpid-server
- script ?
- </title>
-
- <para>
- The following command line options are available:
- </para>
-
- <para>
- The following options are available:
- </para><table>
- <title>
- Command Line Options
- </title>
-
- <tgroup cols="3">
- <tbody>
- <row>
- <entry>
- Option
- </entry>
- <entry>
- Long Option
- </entry>
- <entry>
- Description
- </entry>
- </row>
- <row>
- <entry>
- b
- </entry>
- <entry>
- bind
- </entry>
- <entry>
- Bind to the specified address overriding any value in the
- config file
- </entry>
- </row>
- <row>
- <entry>
- c
- </entry>
- <entry>
- config
- </entry>
- <entry>
- Use the given configuration file
- </entry>
- </row>
- <row>
- <entry>
- h
- </entry>
- <entry>
- help
- </entry>
- <entry>
- Prints list of options
- </entry>
- </row>
- <row>
- <entry>
- l
- </entry>
- <entry>
- logconfig
- </entry>
- <entry>
- Use the specified log4j.xml file rather than that in the
- etc directory
- </entry>
- </row>
- <row>
- <entry>
- m
- </entry>
- <entry>
- mport
- </entry>
- <entry>
- Specify port to listen on for the JMX Management. Overrides
- value in config file
- </entry>
- </row>
- <row>
- <entry>
- p
- </entry>
- <entry>
- port
- </entry>
- <entry>
- Specify port to listen on. Overrides value in config file
- </entry>
- </row>
- <row>
- <entry>
- v
- </entry>
- <entry>
- version
- </entry>
- <entry>
- Print version information and exit
- </entry>
- </row>
- <row>
- <entry>
- w
- </entry>
- <entry>
- logwatch
- </entry>
- <entry>
- Specify interval for checking for logging config changes.
- Zero means no checking
- </entry>
- </row>
- </tbody>
- </tgroup></table>
- </section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIauthenticatewiththebroker-3FWhatuserid-26passwordshouldIuse-3F"><title>
- How do I authenticate with the broker ? What user id &amp;
- password should I use ?
- </title>
-
- <para>
- You should login as user guest with password guest
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIcreatequeuesthatwillalwaysbeinstantiatedatbrokerstartup-3F"><title>
- How do I create queues that will always be instantiated at
- broker startup ?
- </title>
-
- <para>
- You can configure queues which will be created at broker startup
- by tailoring a copy of the virtualhosts.xml file provided in the
- installed qpid-version/etc directory.
- </para><para>
- So, if you're using a queue called 'devqueue' you can ensure that
- it is created at startup by using an entry something like this:
- </para>
- <programlisting>
-&lt;virtualhosts&gt;
- &lt;default&gt;test&lt;/default&gt;
- &lt;virtualhost&gt;
- &lt;name&gt;test&lt;/name&gt;
- &lt;test&gt;
- &lt;queue&gt;
- &lt;name&gt;devqueue&lt;/name&gt;
- &lt;devqueue&gt;
- &lt;exchange&gt;amq.direct&lt;/exchange&gt;
- &lt;maximumQueueDepth&gt;4235264&lt;/maximumQueueDepth&gt; &lt;!-- 4Mb --&gt;
- &lt;maximumMessageSize&gt;2117632&lt;/maximumMessageSize&gt; &lt;!-- 2Mb --&gt;
- &lt;maximumMessageAge&gt;600000&lt;/maximumMessageAge&gt; &lt;!-- 10 mins --&gt;
- &lt;/devqueue&gt;
- &lt;/queue&gt;
- &lt;/test&gt;
- &lt;/virtualhost&gt;
-&lt;/virtualhosts&gt;
-</programlisting>
- <para>
- Note that the name (in thie example above the name is 'test')
- element should match the virtualhost that you're using to create
- connections to the broker. This is effectively a namespace used
- to prevent queue name clashes etc. You can also see that we've
- set the 'test' virtual host to be the default for any connections
- which do not specify a virtual host (in the &lt;default&gt; tag).
- </para><para>
- You can amend the config.xml to point at a different
- virtualhosts.xml file by editing the &lt;virtualhosts/&gt;
- element.
- </para><para>
- So, for example, you could tell the broker to use a file in your
- home directory by creating a new config.xml file with the
- following entry:
- </para><para>
- &lt;virtualhosts&gt;/home/myhomedir/virtualhosts.xml&lt;/virtualhosts&gt;
- </para><para>
- You can then pass this amended config.xml into the broker at
- startup using the -c flag i.e.
- qpid-server -c &lt;path&gt;/config.xml
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIcreatequeuesatruntime-3F"><title>
- How do I
- create queues at runtime?
- </title>
-
- <para>
- Queues can be dynamically created at runtime by creating a
- consumer for them. After they have been created and bound (which
- happens automatically when a JMS Consumer is created) a publisher
- can send messages to them.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoItunethebroker-3F"><title>
- How do I tune
- the broker?
- </title>
-
- <para>
- There are a number of tuning options available, please see the
- <xref linkend="How-to-Tune-M3-Java-Broker-Performance"/> page for more information.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-Wheredoundeliverablemessagesendup-3F"><title>
- Where do
- undeliverable messages end up ?
- </title>
-
- <para>
- At present, messages with an invalid routing key will be returned
- to the sender. If you register an exception listener for your
- publisher (easiest to do by making your publisher implement the
- ExceptionListener interface and coding the onException method)
- you'll see that you end up in onException in this case. You can
- expect to be catching a subclass of
- org.apache.qpid.AMQUndeliveredException.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-CanIconfigurethenameoftheQpidbrokerlogfileatruntime-3F"><title>
- Can I configure the name of the Qpid broker log file at
- runtime ?
- </title>
-
- <para>
- If you simply start the Qpid broker using the default
- configuration, then the log file is written to
- $QPID_WORK/log/qpid.log
- </para><para>
- This is not ideal if you want to run several instances from one
- install, or acrhive logs to a shared drive from several hosts.
- </para><para>
- To make life easier, there are two optional ways to configure the
- naming convention used for the broker log.
- </para>
-
- <section role="h4" id="QpidJavaFAQ-Settingaprefixorsuffix"><title>
- Setting a prefix
- or suffix
- </title>
-
- <para>
- Users should set the following environment variables before
- running qpid-server:
- </para><para>
- QPID_LOG_PREFIX - will prefix the log file name with the
- specified value e.g. if you set this value to be the name of your
- host (for example) it could look something like host123qpid.log
- </para><para>
- QPID_LOG_SUFFIX - will suffix the file name with the specified
- value e.g. if you set this value to be the name of your
- application (for example) if could look something like
- qpidMyApp.log
- </para>
-<!--h4--></section>
-
- <section role="h4" id="QpidJavaFAQ-IncludingthePID"><title>
- Including the PID
- </title>
-
- <para>
- Setting either of these variables to the special value PID will
- introduce the process id of the java process into the file name
- as a prefix or suffix as specified**
- </para>
-<!--h4--></section>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-Myclientapplicationappearstohavehung-3F"><title>
- My
- client application appears to have hung?
- </title>
-
- <para>
- The client code currently has various timeouts scattered
- throughout the code. These can cause your client to appear like
- it has hung when it is actually waiting for the timeout ot
- compelete. One example is when the broker becomes non-responsive,
- the client code has a hard coded 2 minute timeout that it will
- wait when closing a connection. These timeouts need to be
- consolidated and exposed. see <xref linkend="qpid_QPID-429"/>
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIcontacttheQpidteam-3F"><title>
- How do I
- contact the Qpid team ?
- </title>
-
- <para>
- For general questions, please subscribe to the
- <ulink url="mailto:users@qpid.apache.org">users@qpid.apache.org</ulink> mailing list.
- </para><para>
- For development questions, please subscribe to the
- <ulink url="mailto:dev@qpid.apache.org">dev@qpid.apache.org</ulink> mailing list.
- </para><para>
- More details on these lists are available on our <xref linkend="qpid_Mailing-Lists"/>
- page.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowcanIchangeauser-27spasswordwhilethebrokerisup-3F"><title>
- How can I change a user's password while the broker is up ?
- </title>
-
- <para>
- You can do this via the <xref linkend="qpid_Qpid-JMX-Management-Console"/>. To
- do this simply log in to the management console as an admin user
- (you need to have created an admin account in the
- jmxremote.access file first) and then select the 'UserManagement'
- mbean. Select the user in the table and click the Set Password
- button. Alternatively, update the password file and use the
- management console to reload the file with the button at the
- bottom of the 'UserManagement' view. In both cases, this will
- take effect when the user next logs in i.e. will not cause them
- to be disconnected if they are already connected.
- </para><para>
- For more information on the Management Console please see our
- <xref linkend="Qpid-JMX-Management-Console-User-Guide"/>
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowdoIknowifthereisaconsumerforamessageIamgoingtosend-3F"><title>
- How do I know if there is a consumer for a message I am going
- to send?
- </title>
-
- <para>
- Knowing that there is a consumer for a message is quite tricky.
- That said using the qpid.jms.Session#createProducer with
- immediate and mandatory set to true will get you part of the way
- there.
- </para><para>
- If you are publishing to a well known queue then immediate will
- let you know if there is any consumer able to pre-fetch that
- message at the time you send it. If not it will be returned to
- you on your connection listener.
- </para><para>
- If you are sending to a queue that the consumer creates then the
- mandatory flag will let you know if they have not yet created
- that queue.
- </para><para>
- These flags will not be able to tell you if the consuming
- application has received the message and is able to process it.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-HowcanIinspectthecontentsofmyMessageStore-3F"><title>
- How
- can I inspect the contents of my MessageStore?
- </title>
-
- <para>
- The management console can be used to interogate an active
- broker and browse the contents of a queue.See the <xref linkend="qpid_Qpid-JMX-Management-Console"/>
- page for further details.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-Whyaremytransientmessagesbeingsoslow-3F"><title>
- Why are
- my transient messages being so slow?
- </title>
-
- <para>
- You should check that you aren't sending persistent messages,
- this is the default. If you want to send transient messages you
- must explicitly set this option when instantiating your
- MessageProducer or on the send() method.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-Whydoesmyproducerfillupthebrokerwithmessages-3F"><title>
- Why
- does my producer fill up the broker with messages?
- </title>
-
- <para>
- Switch on producer flow control to prevent temporary spikes in
- message production over-filling the broker.
-
- Of course, if the long-term rate of message production exceeds
- the rate of message
- consumption then that is an architectural problem that can only
- be temporarily mitigated by producer flow control.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-ThebrokerkeepsthrowinganOutOfMemoryexception-3F"><title>
- The
- broker keeps throwing an OutOfMemory exception?
- </title>
-
- <para>
- The broker can no longer store any more messages in memory. This
- is particular evident if you are using the MemoryMessageStore. To
- alleviate this issue you should ensure that your clients are
- consuming all the messages from the broker.
- </para><para>
- You may also want to increase the memory allowance to the broker
- though this will only delay the exception if you are publishing
- messages faster than you are consuming. See <xref linkend="qpid_Java-Environment-Variables"/> for
- details of changing the memory settings.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-WhyamIgettingabrokersideexceptionwhenItrytopublishtoaqueueoratopic-3F"><title>
- Why am I getting a broker side exception when I try to
- publish to a queue or a topic ?
- </title>
-
- <para>
- If you get a stack trace like this when you try to publish, then
- you may have typo'd the exchange type in your queue or topic
- declaration. Open your virtualhosts.xml and check that the
- </para>
- <programlisting>
-&lt;exchange&gt;amq.direct&lt;/exchange&gt;
-</programlisting>
-
- <programlisting>
-2009-01-12 15:26:27,957 ERROR [pool-11-thread-2] protocol.AMQMinaProtocolSession (AMQMinaProtocolSession.java:365) - Unexpected exception while processing frame. Closing connection.
-java.lang.NullPointerException
- at org.apache.qpid.server.security.access.PrincipalPermissions.authorise(PrincipalPermissions.java:398)
- at org.apache.qpid.server.security.access.plugins.SimpleXML.authorise(SimpleXML.java:302)
- at org.apache.qpid.server.handler.QueueBindHandler.methodReceived(QueueBindHandler.java:111)
- at org.apache.qpid.server.handler.ServerMethodDispatcherImpl.dispatchQueueBind(ServerMethodDispatcherImpl.java:498)
- at org.apache.qpid.framing.amqp_8_0.QueueBindBodyImpl.execute(QueueBindBodyImpl.java:167)
- at org.apache.qpid.server.state.AMQStateManager.methodReceived(AMQStateManager.java:204)
- at org.apache.qpid.server.protocol.AMQMinaProtocolSession.methodFrameReceived(AMQMinaProtocolSession.java:295)
- at org.apache.qpid.framing.AMQMethodBodyImpl.handle(AMQMethodBodyImpl.java:93)
- at org.apache.qpid.server.protocol.AMQMinaProtocolSession.frameReceived(AMQMinaProtocolSession.java:235)
- at org.apache.qpid.server.protocol.AMQMinaProtocolSession.dataBlockReceived(AMQMinaProtocolSession.java:191)
- at org.apache.qpid.server.protocol.AMQPFastProtocolHandler.messageReceived(AMQPFastProtocolHandler.java:244)
- at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:703)
- at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
- at org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:54)
- at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
- at org.apache.qpid.pool.PoolingFilter.messageReceived(PoolingFilter.java:371)
- at org.apache.mina.filter.ReferenceCountingIoFilter.messageReceived(ReferenceCountingIoFilter.java:96)
- at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
- at org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:54)
- at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
- at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flush(SimpleProtocolDecoderOutput.java:60)
- at org.apache.mina.filter.codec.QpidProtocolCodecFilter.messageReceived(QpidProtocolCodecFilter.java:174)
- at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
- at org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:54)
- at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
- at org.apache.qpid.pool.Event$ReceivedEvent.process(Event.java:86)
- at org.apache.qpid.pool.Job.processAll(Job.java:110)
- at org.apache.qpid.pool.Job.run(Job.java:149)
- at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
- at java.lang.Thread.run(Thread.java:619)
-</programlisting>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-WhyistherealotofAnonymousIoServicethreads"><title>
- Why
- is there a lot of AnonymousIoService threads
- </title>
-
- <para>
- These threads are part of the thread pool used by Mina to process
- the socket. In the future we may provide tuning guidelines but at
- this point we have seen no performance implications from the
- current configuration. As the threads are part of a pool they
- should remain inactive until required.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ--22unabletocertifytheprovidedSSLcertificateusingthecurrentSSLtruststore-22whenconnectingtheManagementConsoletothebroker."><title>
- "unable to certify the provided SSL certificate using the
- current SSL trust store" when connecting the Management Console
- to the broker.
- </title>
-
- <para>
- You have not configured the console's SSL trust store properly,
- see <xref linkend="qpid_Management-Console-Security"/> for
- more details.
- </para>
-<!--h3--></section>
-
- <section role="h3" id="QpidJavaFAQ-CanauseTCPKEEPALIVEorAMQPheartbeatingtokeepmyconnectionopen-3F"><title>
- Can a use TCP_KEEPALIVE or AMQP heartbeating to keep my
- connection open?
- </title>
-
- <para>
- See <xref linkend="qpid_Configure-Broker-and-Client-Heartbeating"/>
- </para>
-
-<!--h3--></section>
-<!--h2--></section>
-
-
-
-</section>
diff --git a/doc/book/src/java-broker/Qpid-Management-Features.xml b/doc/book/src/java-broker/Qpid-Management-Features.xml
deleted file mode 100644
index c90d7e97c6..0000000000
--- a/doc/book/src/java-broker/Qpid-Management-Features.xml
+++ /dev/null
@@ -1,185 +0,0 @@
-<?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.
-
--->
-
-<section>
- <title>
- Qpid Management Features
- </title>
- <para>
- <emphasis>Management tool:</emphasis> See our <xref linkend="qpid_Qpid-JMX-Management-Console"/> for
- details of how to use various console options with the Qpid
- management features.
- </para>
- <para>
- The management of QPID is categorised into following types-
- </para>
- <orderedlist>
- <listitem><para>Exchange
- </para></listitem>
- <listitem><para>Queue
- </para></listitem>
- <listitem><para>Connection
- </para></listitem>
- <listitem><para>Broker
- </para></listitem>
- </orderedlist>
- <para>
-  <emphasis>1) Managing and Monitoring Exchanges</emphasis>: Following is
- the list of features, which we can have available for managing
- and monitoring an Exchange running on a Qpid Server Domain-
- </para>
- <orderedlist>
- <listitem><para>Displaying the following information for monitoring purpose-
- <orderedlist>
- <listitem><para>The list of queues bound to the exchange along with the
- routing keys.
- </para></listitem>
- <listitem><para>
- General Exchange properties(like name,
- durable etc).
- </para></listitem>
- </orderedlist>
- </para></listitem>
- <listitem><para>
- Binding an existing queue with the
- exchange.
- </para></listitem>
- </orderedlist>
- <para>
- <emphasis>2) Managing and Monitoring
- Queues</emphasis>:  Following are the
- features, which we can have for a Queue on a Qpid Server
- Domain-
- </para>
- <orderedlist>
- <listitem><para>
- Displaying the following information about
- the queue for monitoring purpose-
- <orderedlist>
- <listitem><para>
- General Queue properties(like name,
- durable, etc.)
- </para></listitem>
- <listitem><para>
- The maximum size of a message that can
- be accepted from the message producer.
- </para></listitem>
- <listitem><para>
- The number of the active consumers
- accessing the Queue.
- </para></listitem>
- <listitem><para>
- The total number of
- consumers (Active and Suspended).
- </para></listitem>
- <listitem><para>
- The number of undelivered messages
- in the Queue.
- </para></listitem>
- <listitem><para>
- The total number of messages received
- on the Queue since startup.
- </para></listitem>
- <listitem><para>
- The maximum number of bytes for
- the Queue that can be stored on the Server.
- </para></listitem>
- <listitem><para>The maximum number of messages for the Queue that can be
- stored on the Server.
- </para></listitem>
- </orderedlist>
- </para></listitem>
- <listitem><para>
- Viewing the messages on the Queue.
- </para></listitem>
- <listitem><para>
- Deleting message from top of the
- Queue.
- </para></listitem>
- <listitem><para>
- Clearing the Queue.
- </para></listitem>
- <listitem><para>
- Browsing the DeadMessageQueue - Messages
- which are expired or undelivered because of some reason are
- routed to the DeadMessageQueue.  This queue can not be
- deleted.  [Note: The is open because it depends on how
- these kind of messages will be handeled?]
- </para></listitem>
- </orderedlist>
- <para>
- <emphasis>3) Managing and Monitoring
- Connections</emphasis>: Following are the
- features, which we can have for a connection on a QPID
- Server Domain-
- </para>
- <orderedlist>
- <listitem><para>
- Displaying general connection
- properties(like remote address, etc.).
- </para></listitem>
- <listitem><para>Setting maximum number of channels allowed for a
- connection.
- </para></listitem>
- <listitem><para>View all related channels and channel properties.
- </para></listitem>
- <listitem><para>Closing a channel.
- </para></listitem>
- <listitem><para>Commit or Rollback transactions of a channel, if the channel
- is transactional.
- </para></listitem>
- <listitem><para>Notification for exceeding the maximum number of
- channels.
- </para></listitem>
- <listitem><para>Dropping a connection.
- </para></listitem>
- <listitem><para>The work for <xref linkend="qpid_Network-IO-Interface"/> implies that
- there are potentially some additional requirements
- <orderedlist>
- <listitem><para>Alert when tcp flow control kicks in
- </para></listitem>
- <listitem><para>Information available about current memory usage
- available through JMX interface
- </para></listitem>
- <listitem><para>Dynamic removal of buffer bounds? (fundamentally not
- possible with TransportIO)
- </para></listitem>
- <listitem><para>Management functionality added to JMX interface - UI
- changes?
- </para></listitem>
- </orderedlist>
- </para></listitem>
- </orderedlist>
- <para>
- <emphasis>4) Managing the Broker</emphasis>: Features for the Broker-
- </para>
- <orderedlist>
- <listitem><para>Creating an Exchange.
- </para></listitem>
- <listitem><para>Unregistering an Exchange.
- </para></listitem>
- <listitem><para>Creating a Queue.
- </para></listitem>
- <listitem><para>Deleting a Queue.
- </para></listitem>
- </orderedlist>
-</section>
diff --git a/doc/book/src/java-broker/Qpid-Troubleshooting-Guide.xml b/doc/book/src/java-broker/Qpid-Troubleshooting-Guide.xml
deleted file mode 100644
index 0920f18798..0000000000
--- a/doc/book/src/java-broker/Qpid-Troubleshooting-Guide.xml
+++ /dev/null
@@ -1,156 +0,0 @@
-<?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.
-
--->
-
-<section id="Qpid-Troubleshooting-Guide">
-
- <title>
- Qpid Troubleshooting Guide
- </title>
-
- <section role="h2" id="QpidTroubleshootingGuide-I-27mgettingajava.lang.UnsupportedClassVersionErrorwhenItrytostartthebroker.Whatdoesthismean-3F"><title>
- I'm getting a java.lang.UnsupportedClassVersionError when I
- try to start the broker. What does this mean ?
- </title>
-
- <para>
- The QPID broker requires JDK 1.5 or later. If you're seeing this
- exception you don't have that version in your path. Set JAVA_HOME
- to the correct version and ensure the bin directory is on your
- path.
- </para><para>
- java.lang.UnsupportedClassVersionError:
- org/apache/qpid/server/Main (Unsupported major.minor version
- 49.0)
- at
- java.lang.ClassLoader.defineClass(Ljava.lang.String;[BIILjava.security.ProtectionDomain;)Ljava.lang.Class;(Unknown
- Source)
- at
- java.security.SecureClassLoader.defineClass(Ljava.lang.String;[BIILjava.security.CodeSource;)Ljava.lang.Class;(SecureClassLoader.java:123)
-
- at
- java.net.URLClassLoader.defineClass(Ljava.lang.String;Lsun.misc.Resource;)Ljava.lang.Class;(URLClassLoader.java:251)
-
- at
- java.net.URLClassLoader.access$100(Ljava.net.URLClassLoader;Ljava.lang.String;Lsun.misc.Resource;)Ljava.lang.Class;(URLClassLoader.java:55)
-
- at java.net.URLClassLoader$1.run()Ljava.lang.Object;
- (URLClassLoader.java:194)
- at
- jrockit.vm.AccessController.do_privileged_exc(Ljava.security.PrivilegedExceptionAction;Ljava.security.AccessControlContext;I)Ljava.lang.Object;(Unknown
- Source)
- at
- jrockit.vm.AccessController.doPrivileged(Ljava.security.PrivilegedExceptionAction;Ljava.security.AccessControlContext;)Ljava.lang.Object;(Unknown
- Source)
- at
- java.net.URLClassLoader.findClass(Ljava.lang.String;)Ljava.lang.Class;(URLClassLoader.java:187)
-
- at
- java.lang.ClassLoader.loadClass(Ljava.lang.String;Z)Ljava.lang.Class;
- (Unknown Source)
- at
- sun.misc.Launcher$AppClassLoader.loadClass(Ljava.lang.String;Z)Ljava.lang.Class;(Launcher.java:274)
-
- at
- java.lang.ClassLoader.loadClass(Ljava.lang.String;)Ljava.lang.Class;
-
- (Unknown Source)
- at
- java.lang.ClassLoader.loadClassFromNative(II)Ljava.lang.Class;
-
- (Unknown Source)
- </para>
-
-<!--h2--></section>
-
- <section role="h2" id="QpidTroubleshootingGuide-I-27mhavingaproblembindingtotherequiredhost-3Aportatbrokerstartup-3F"><title>
- I'm having a problem binding to the required host:port at
- broker startup ?
- </title>
- <para>
- This error probably indicates that another process is using the
- port you the broker is trying to listen on. If you haven't
- amended the default configuration this will be 5672. To check
- what process is using the port you can use 'netstat -an |grep
- 5672'.
- </para><para>
- To change the port your broker uses, either edit the config.xml
- you are using. You can specify an alternative config.xml from the
- one provided in /etc by using the -c flag i.e. qpid-server -c
- &lt;my config file path&gt;.
- </para><para>
- You can also amend the port more simply using the -p option to
- qpid-server i.e. qpid-server -p &lt;my port number'
- </para>
-<!--h2--></section>
-
- <section role="h2" id="QpidTroubleshootingGuide-I-27mhavingproblemswithmyclasspath.HowcanIensurethatmyclasspathisok-3F"><title>
- I'm having problems with my classpath. How can I ensure that
- my classpath is ok ?
- </title>
- <para>
- When you are running the broker the classpath is taken care of
- for you, via the manifest entries in the launch jars that the
- qpid-server configuration file adds to the classpath.
- </para><para>
- However, if you are running your own client code and experiencing
- classspath errors you need to ensure that the client-launch.jar
- from the installed Qpid lib directory is on your classpath. The
- manifest for this jar includes the common-launch.jar, and thus
- all the code you need to run a client application.
- </para>
- </section>
-
- <section role="h2" id="QpidTroubleshootingGuide-Ican-27tgetthebrokertostart.HowcanIdiagnosetheproblem-3F"><title>
- I can't get the broker to start. How can I diagnose the
- problem ?
- </title>
- <para>
- Firstly have a look at the broker log file - either on stdout or
- in $QPID_WORK/log/qpid.log or in $HOME/log/qpid.log if you
- haven't set QPID_WORK.
- </para><para>
- You should see the problem logged in here via log4j and a stack
- trace. Have a look at the other entries on this page for common
- problems. If the log file includes a line like:
- </para><para>
- "2006-10-13 09:58:14,672 INFO [main] server.Main (Main.java:343)
- - Qpid.AMQP listening on non-SSL address 0.0.0.0/0.0.0.0:5672"
- </para><para>
- ... then you know the broker started up. If not, then it didn't.
- </para>
-<!--h2--></section>
-
- <section role="h2" id="QpidTroubleshootingGuide-WhenItrytosendmessagestoaqueueI-27mgettingaerrorasthequeuedoesnotexist.WhatcanIdo-3F"><title>
- When I try to send messages to a queue I'm getting a error as
- the queue does not exist. What can I do ?
- </title>
- <para>
- In Qpid queues need a consumer before they really exist, unless
- you have used the virtualhosts.xml file to specify queues which
- should always be created at broker startup. If you don't want to
- use this config, then simply ensure that you consume first from
- queue before staring to publish to it. See the entry on our
- <xref linkend="qpid_Qpid-Java-FAQ"/> for more details of using the virtualhosts.xml route.
- </para>
-<!--h2--></section>
-
-</section>
diff --git a/doc/book/src/java-broker/Topic-Configuration.xml b/doc/book/src/java-broker/Topic-Configuration.xml
deleted file mode 100644
index 1f73bbd7a4..0000000000
--- a/doc/book/src/java-broker/Topic-Configuration.xml
+++ /dev/null
@@ -1,107 +0,0 @@
-<?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.
-
--->
-
-<section>
- <title>Topic Configuration on Java Broker</title>
-
- <para>New in 0.8 is the ability to define configuration for topics. Currently this is limited to
- configuration for slow consumer detection. This configuration is based on the work
- designed on the <ulink
- url="http://cwiki.apache.org/confluence/display/qpid/Topic+Configuration+Design">design
- wiki</ulink>.</para>
-
- <section id="Topic Identification">
- <title>Topic Identification</title>
- <para>A configuration section has two entries that can be used to identify how the
- configuration will be applied: 'name' and 'subscriptionName'.
-
- <programlisting>
- &lt;topic&gt;
- &lt;name&gt;stocks.us&lt;/name&gt;
- </programlisting>
- <programlisting>
- &lt;topic&gt;
- &lt;subscriptionName&gt;clientid:mysubscription&lt;/subscriptionName&gt;
- </programlisting>
-
- It is also possible to combine these two identifiers to specify a unique subscription to
- a given topic.
-
- <programlisting>
- &lt;topic&gt;
- &lt;name&gt;stocks.us&lt;/name&gt;
- &lt;subscriptionName&gt;clientid:mysubscription&lt;/subscriptionName&gt;
- </programlisting>
- </para>
- </section>
-
- <section>
- <title>Configuration Items</title>
- <para> Currently only one element of the designed configuration is processed, that of the
- slow consumer detection. This is setup as below using the 'slow-consumer-detection'
- element. There are two required types of tag, first the trigger, which is one of
- 'depth', 'messageAge' or 'messageCount' and secondly the 'policy'. </para>
- <programlisting>
- &lt;slow-consumer-detection&gt;
- &lt;!-- The maximum depth before which the policy will be applied--&gt;
- &lt;depth&gt;4235264&lt;/depth&gt;
-
- &lt;!-- The maximum message age before which the policy will be applied--&gt;
- &lt;messageAge&gt;600000&lt;/messageAge&gt;
-
- &lt;!-- The maximum number of message before which the policy will be applied--&gt;
- &lt;messageCount&gt;50&lt;/messageCount&gt;
-
- &lt;!-- Policy Selection --&gt;
- &lt;policy name="TopicDelete"/&gt;
- &lt;/slow-consumer-detection&gt;
- </programlisting>
-
- <para> The trigger is used to determine when the policy should be applied. Currently we have
- a simple policy 'topicdelete', this will disconnect consumers of topics where their
- consumption rate falls sufficiently to hit one of the trigger values. </para>
- </section>
-
-
- <section id="Limitiations">
- <title>Limitiations</title>
- <para> As of 0.8 the topic configuration is limited to straight string matching. This means
- that given the following two topic configuring sections for 'stocks.us' and 'stocks.*' a
- subscription for 'stocks.uk' will not match the expected 'stocks.*'. Nor will any
- additional configuration listed in 'stocks.*' affect any 'stocks.us' subscriptions. </para>
- <programlisting>
- &lt;topics&gt;
- &lt;topic&gt;
- &lt;name&gt;stocks.us&lt;/name&gt;
- ...
- &lt;/topic&gt;
- &lt;topic&gt;
- &lt;name&gt;stocks.*&lt;/name&gt;
- ...
- &lt;/topic&gt;
- &lt;/topics&gt;
- </programlisting>
- <para> A subscription for 'stocks.us' will only receive configuration settings that are
- defined in the 'stocks.us' section. </para>
- </section>
-
-</section>
diff --git a/doc/book/src/java-broker/commonEntities.xml b/doc/book/src/java-broker/commonEntities.xml
new file mode 100644
index 0000000000..a53440a467
--- /dev/null
+++ b/doc/book/src/java-broker/commonEntities.xml
@@ -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.
+
+-->
+
+<!ENTITY qpidDownloadUrl "http://qpid.apache.org/download.html">
+<!ENTITY qpidProgrammingBook "../../Programming-In-Apache-Qpid/html/">
+<!ENTITY qpidCppBook "../../AMQP-Messaging-Broker-CPP-Book/html/">
+
+<!ENTITY qpidCurrentRelease "0.21">
+
+<!-- Oracle javadoc -->
+<!ENTITY oracleJdkDocUrl "http://oracle.com/javase/6/docs/api/">
+<!ENTITY oracleJeeDocUrl "http://docs.oracle.com/javaee/6/api/">
+<!ENTITY oracleKeytool "http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/keytool.html">
+
+<!-- Oracle BDB JE-->
+<!ENTITY oracleJeDownloadUrl "http://www.oracle.com/technetwork/products/berkeleydb/downloads/index.html?ssSourceSiteId=ocomen">
+<!ENTITY oracleBdbProductOverviewUrl "http://www.oracle.com/technetwork/products/berkeleydb/overview/index-093405.html">
+<!ENTITY oracleBdbRepGuideUrl "http://oracle.com/cd/E17277_02/html/ReplicationGuide/">
+<!ENTITY oracleBdbJavaDocUrl "http://docs.oracle.com/cd/E17277_02/html/java/">
+<!ENTITY oracleBdbProductVersion "5.0.58">
+
diff --git a/doc/book/src/java-broker/images/3113098.png b/doc/book/src/java-broker/images/3113098.png
deleted file mode 100644
index 7de85030c6..0000000000
--- a/doc/book/src/java-broker/images/3113098.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113099.png b/doc/book/src/java-broker/images/3113099.png
deleted file mode 100644
index fb6fc65d73..0000000000
--- a/doc/book/src/java-broker/images/3113099.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113100.png b/doc/book/src/java-broker/images/3113100.png
deleted file mode 100644
index a7d727b854..0000000000
--- a/doc/book/src/java-broker/images/3113100.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113101.png b/doc/book/src/java-broker/images/3113101.png
deleted file mode 100644
index 30731277c2..0000000000
--- a/doc/book/src/java-broker/images/3113101.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113102.png b/doc/book/src/java-broker/images/3113102.png
deleted file mode 100644
index f150a21b10..0000000000
--- a/doc/book/src/java-broker/images/3113102.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113103.png b/doc/book/src/java-broker/images/3113103.png
deleted file mode 100644
index a91efb4306..0000000000
--- a/doc/book/src/java-broker/images/3113103.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113104.png b/doc/book/src/java-broker/images/3113104.png
deleted file mode 100644
index c5ef12d8b1..0000000000
--- a/doc/book/src/java-broker/images/3113104.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113105.png b/doc/book/src/java-broker/images/3113105.png
deleted file mode 100644
index b155f9d9a1..0000000000
--- a/doc/book/src/java-broker/images/3113105.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113106.png b/doc/book/src/java-broker/images/3113106.png
deleted file mode 100644
index 22bcdd084e..0000000000
--- a/doc/book/src/java-broker/images/3113106.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113107.png b/doc/book/src/java-broker/images/3113107.png
deleted file mode 100644
index cf5dd97e89..0000000000
--- a/doc/book/src/java-broker/images/3113107.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113108.png b/doc/book/src/java-broker/images/3113108.png
deleted file mode 100644
index c0e5eafde2..0000000000
--- a/doc/book/src/java-broker/images/3113108.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113109.png b/doc/book/src/java-broker/images/3113109.png
deleted file mode 100644
index 139d81d849..0000000000
--- a/doc/book/src/java-broker/images/3113109.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113110.png b/doc/book/src/java-broker/images/3113110.png
deleted file mode 100644
index 2207f15cd7..0000000000
--- a/doc/book/src/java-broker/images/3113110.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113111.png b/doc/book/src/java-broker/images/3113111.png
deleted file mode 100644
index 5737f41caf..0000000000
--- a/doc/book/src/java-broker/images/3113111.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113112.png b/doc/book/src/java-broker/images/3113112.png
deleted file mode 100644
index d9ee094ab4..0000000000
--- a/doc/book/src/java-broker/images/3113112.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113113.png b/doc/book/src/java-broker/images/3113113.png
deleted file mode 100644
index e80812f83c..0000000000
--- a/doc/book/src/java-broker/images/3113113.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113114.png b/doc/book/src/java-broker/images/3113114.png
deleted file mode 100644
index b237181150..0000000000
--- a/doc/book/src/java-broker/images/3113114.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113115.png b/doc/book/src/java-broker/images/3113115.png
deleted file mode 100644
index 84ad42b567..0000000000
--- a/doc/book/src/java-broker/images/3113115.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113116.png b/doc/book/src/java-broker/images/3113116.png
deleted file mode 100644
index 18b979792f..0000000000
--- a/doc/book/src/java-broker/images/3113116.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113117.png b/doc/book/src/java-broker/images/3113117.png
deleted file mode 100644
index 3b33ef67ac..0000000000
--- a/doc/book/src/java-broker/images/3113117.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113118.png b/doc/book/src/java-broker/images/3113118.png
deleted file mode 100644
index 60451f88cf..0000000000
--- a/doc/book/src/java-broker/images/3113118.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/3113119.png b/doc/book/src/java-broker/images/3113119.png
deleted file mode 100644
index 16ded074bd..0000000000
--- a/doc/book/src/java-broker/images/3113119.png
+++ /dev/null
Binary files differ
diff --git a/doc/book/src/java-broker/images/HA-BDBHAMessageStore-MBean-jconsole.png b/doc/book/src/java-broker/images/HA-BDBHAMessageStore-MBean-jconsole.png
index 6caaacb1e1..29d5494746 100644
--- a/doc/book/src/java-broker/images/HA-BDBHAMessageStore-MBean-jconsole.png
+++ b/doc/book/src/java-broker/images/HA-BDBHAMessageStore-MBean-jconsole.png
Binary files differ
diff --git a/doc/book/src/java-broker/images/Management-Web-Console.png b/doc/book/src/java-broker/images/Management-Web-Console.png
new file mode 100644
index 0000000000..c752adec3b
--- /dev/null
+++ b/doc/book/src/java-broker/images/Management-Web-Console.png
Binary files differ
diff --git a/doc/book/src/programming/Programming-In-Apache-Qpid-Book.xml b/doc/book/src/programming/Programming-In-Apache-Qpid-Book.xml
deleted file mode 100644
index fd32f42f2e..0000000000
--- a/doc/book/src/programming/Programming-In-Apache-Qpid-Book.xml
+++ /dev/null
@@ -1,6510 +0,0 @@
-<?xml version='1.0' encoding='utf-8' ?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
-
-<!--
-
-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.
-
--->
-
-<book id="client-api-tutorial">
- <title>Programming in Apache Qpid</title>
- <subtitle>Cross-Platform AMQP Messaging in Java JMS, .NET, C++, and Python</subtitle>
-
- <chapter>
- <title>Introduction</title>
-
- <para>Apache Qpid is a reliable, asynchronous messaging system that
- supports the AMQP messaging protocol in several common programming
- languages. Qpid is supported on most common platforms.
- </para>
-
- <itemizedlist>
- <listitem>
- <para>
- On the Java platform, Qpid uses the
- established <ulink url="http://java.sun.com/products/jms/">Java JMS
- API</ulink>.
- </para>
- </listitem>
- <listitem>
- <para>
- For Python, C++, and .NET, Qpid defines its own messaging API, the
- <firstterm>Qpid Messaging API</firstterm>, which is
- conceptually similar in each.
- </para>
- <para>
- On the .NET platform, Qpid also provides a WCF binding.
- </para>
- </listitem>
- <listitem>
- <para>
- Ruby will also use the Qpid Messaging API, which will soon
- be implemented. (Ruby currently uses an API that is closely
- tied to the AMQP version).
- </para>
- </listitem>
- </itemizedlist>
-
- </chapter>
-
- <chapter>
- <title>Using the Qpid Messaging API</title>
-
- <para>The Qpid Messaging API is quite simple, consisting of only a
- handful of core classes.
- </para>
-
- <itemizedlist>
-
- <listitem>
- <para>
- A <firstterm>message</firstterm> consists of a standard set
- of fields (e.g. <literal>subject</literal>,
- <literal>reply-to</literal>), an application-defined set of
- properties, and message content (the main body of the
- message).
- </para>
- </listitem>
-
- <listitem>
- <para>
- A <firstterm>connection</firstterm> represents a network
- connection to a remote endpoint.
- </para>
- </listitem>
-
- <listitem>
- <para>
- A <firstterm>session</firstterm> provides a sequentially
- ordered context for sending and receiving
- <emphasis>messages</emphasis>. A session is obtained from a
- connection.
- </para>
- </listitem>
-
- <listitem>
- <para>
- A <firstterm>sender</firstterm> sends messages to a target
- using the <literal>sender.send</literal> method. A sender is
- obtained from a session for a given target address.
- </para>
- </listitem>
-
- <listitem>
- <para>
- A <firstterm>receiver</firstterm> receives messages from a
- source using the <literal>receiver.fetch</literal> method.
- A receiver is obtained from a session for a given source
- address.
- </para>
- </listitem>
-
- </itemizedlist>
-
- <para>
- The following sections show how to use these classes in a
- simple messaging program.
- </para>
-
- <section>
- <title>A Simple Messaging Program in C++</title>
-
- <para>The following C++ program shows how to create a connection,
- create a session, send messages using a sender, and receive
- messages using a receiver.</para>
-
- <example>
- <title>"Hello world!" in C++</title>
- <programlisting lang="c++"><![CDATA[
- #include <qpid/messaging/Connection.h>
- #include <qpid/messaging/Message.h>
- #include <qpid/messaging/Receiver.h>
- #include <qpid/messaging/Sender.h>
- #include <qpid/messaging/Session.h>
-
- #include <iostream>]]>
-
- using namespace qpid::messaging;
-
- int main(int argc, char** argv) {
- std::string broker = argc > 1 ? argv[1] : "localhost:5672";
- std::string address = argc > 2 ? argv[2] : "amq.topic";
- std::string connectionOptions = argc > 3 ? argv[3] : "";
-
- Connection connection(broker, connectionOptions);
- try {
- connection.open(); <co id="hello-cpp-open" linkends="callout-cpp-open"/>
- Session session = connection.createSession(); <co id="hello-cpp-session" linkends="callout-cpp-session"/>
-
- Receiver receiver = session.createReceiver(address); <co id="hello-cpp-receiver" linkends="callout-cpp-receiver"/>
- Sender sender = session.createSender(address); <co id="hello-cpp-sender" linkends="callout-cpp-sender"/>
-
- sender.send(Message("Hello world!"));
-
- Message message = receiver.fetch(Duration::SECOND * 1); <co id="hello-cpp-fetch" linkends="callout-cpp-fetch"/>
- <![CDATA[std::cout << message.getContent() << std::endl;]]>
- session.acknowledge(); <co id="hello-cpp-acknowledge" linkends="callout-cpp-acknowledge"/>
-
- connection.close(); <co id="hello-cpp-close" linkends="callout-cpp-close"/>
- return 0;
- } catch(const std::exception&amp; error) {
- <![CDATA[std::cerr << error.what() << std::endl;]]>
- connection.close();
- return 1;
- }
- }</programlisting>
-
- <calloutlist>
- <callout id="callout-cpp-open" arearefs="hello-cpp-open">
- <para>Establishes the connection with the messaging broker.</para>
- </callout>
- <callout id="callout-cpp-session" arearefs="hello-cpp-session">
- <para>Creates a session object on which messages will be sent and received.</para>
- </callout>
- <callout id="callout-cpp-receiver" arearefs="hello-cpp-receiver">
- <para>Creates a receiver that receives messages from the given address.</para>
- </callout>
- <callout id="callout-cpp-sender" arearefs="hello-cpp-sender">
- <para>Creates a sender that sends to the given address.</para>
- </callout>
- <callout id="callout-cpp-fetch" arearefs="hello-cpp-fetch">
- <para>Receives the next message. The duration is optional, if omitted, will wait indefinitely for the next message.</para>
- </callout>
- <callout id="callout-cpp-acknowledge" arearefs="hello-cpp-acknowledge">
- <para>Acknowledges receipt of all fetched messages on the
- session. This informs the broker that the messages were
- transferred and processed by the client successfully.</para>
- </callout>
- <callout id="callout-cpp-close" arearefs="hello-cpp-close">
- <para>Closes the connection, all sessions managed by the connection, and all senders and receivers managed by each session.</para>
- </callout>
- </calloutlist>
- </example>
-
-
- </section>
-
- <section>
- <title>A Simple Messaging Program in Python</title>
-
- <para>The following Python program shows how to create a
- connection, create a session, send messages using a sender, and
- receive messages using a receiver.</para>
-
- <example>
- <title>"Hello world!" in Python</title>
- <programlisting lang="python"><![CDATA[
- import sys
- from qpid.messaging import *
-
- broker = "localhost:5672" if len(sys.argv)<2 else sys.argv[1]
- address = "amq.topic" if len(sys.argv)<3 else sys.argv[2]]]>
-
- connection = Connection(broker)
-
- try:
- connection.open() <co id="hello-python-open" linkends="callout-python-open"/>
- session = connection.session() <co id="hello-python-session" linkends="callout-python-session"/>
-
- sender = session.sender(address) <co id="hello-python-sender" linkends="callout-python-sender"/>
- receiver = session.receiver(address) <co id="hello-python-receiver" linkends="callout-python-receiver"/>
-
- sender.send(Message("Hello world!"));
-
- message = receiver.fetch(timeout=1) <co id="hello-python-fetch" linkends="callout-python-fetch"/>
- print message.content
- session.acknowledge() <co id="hello-python-acknowledge" linkends="callout-python-acknowledge"/>
-
- except MessagingError,m:
- print m
- finally:
- connection.close() <co id="hello-python-close" linkends="callout-python-close"/>
- </programlisting>
-
- <calloutlist>
- <callout id="callout-python-open" arearefs="hello-python-open">
- <para>Establishes the connection with the messaging broker.</para>
- </callout>
- <callout id="callout-python-session" arearefs="hello-python-session">
- <para>Creates a session object on which messages will be sent and received.</para>
- </callout>
- <callout id="callout-python-receiver" arearefs="hello-python-receiver">
- <para>Creates a receiver that receives messages from the given address.</para>
- </callout>
- <callout id="callout-python-sender" arearefs="hello-python-sender">
- <para>Creates a sender that sends to the given address.</para>
- </callout>
- <callout id="callout-python-fetch" arearefs="hello-python-fetch">
- <para>Receives the next message. The duration is optional, if omitted, will wait indefinitely for the next message.</para>
- </callout>
- <callout id="callout-python-acknowledge" arearefs="hello-python-acknowledge">
- <para>Acknowledges receipt of all fetched messages on
- the session. This informs the broker that the messages were
- transfered and processed by the client successfully.</para>
- </callout>
- <callout id="callout-python-close" arearefs="hello-python-close">
- <para>Closes the connection, all sessions managed by the connection, and all senders and receivers managed by each session.</para>
- </callout>
- </calloutlist>
-
- </example>
-
- </section>
-
-
-
-
- <section>
- <title>A Simple Messaging Program in .NET C#</title>
-
- <para>The following .NET C#
- <footnote>
- <para>
- The .NET binding for the Qpid C++ Messaging API
- applies to all .NET Framework managed code languages. C# was chosen
- for illustration purposes only.
- </para>
- </footnote>
- program shows how to create a connection,
- create a session, send messages using a sender, and receive
- messages using a receiver.
- </para>
-
- <example>
- <title>"Hello world!" in .NET C#</title>
- <programlisting lang="c++">
- using System;
- using Org.Apache.Qpid.Messaging; <co id="hello-csharp-using" linkends="callout-csharp-using"/>
-
- namespace Org.Apache.Qpid.Messaging {
- class Program {
- static void Main(string[] args) {
- String broker = args.Length > 0 ? args[0] : "localhost:5672";
- String address = args.Length > 1 ? args[1] : "amq.topic";
-
- Connection connection = null;
- try {
- connection = new Connection(broker);
- connection.Open(); <co id="hello-csharp-open" linkends="callout-csharp-open"/>
- Session session = connection.CreateSession(); <co id="hello-csharp-session" linkends="callout-csharp-session"/>
-
- Receiver receiver = session.CreateReceiver(address); <co id="hello-csharp-receiver" linkends="callout-csharp-receiver"/>
- Sender sender = session.CreateSender(address); <co id="hello-csharp-sender" linkends="callout-csharp-sender"/>
-
- sender.Send(new Message("Hello world!"));
-
- Message message = new Message();
- message = receiver.Fetch(DurationConstants.SECOND * 1); <co id="hello-csharp-fetch" linkends="callout-csharp-fetch"/>
- Console.WriteLine("{0}", message.GetContent());
- session.Acknowledge(); <co id="hello-csharp-acknowledge" linkends="callout-csharp-acknowledge"/>
-
- connection.Close(); <co id="hello-csharp-close" linkends="callout-csharp-close"/>
- } catch (Exception e) {
- Console.WriteLine("Exception {0}.", e);
- if (null != connection)
- connection.Close();
- }
- }
- }
- }
-
- </programlisting>
-
- <calloutlist>
- <callout id="callout-csharp-using" arearefs="hello-csharp-using">
- <para> Permits use of Org.Apache.Qpid.Messaging types and methods without explicit namespace qualification. Any .NET project must have a project reference to the assembly file <literal>Org.Apache.Qpid.Messaging.dll</literal> in order to obtain the definitions of the .NET Binding for Qpid Messaging namespace.</para>
- </callout>
- <callout id="callout-csharp-open" arearefs="hello-csharp-open">
- <para>Establishes the connection with the messaging broker.</para>
- </callout>
- <callout id="callout-csharp-session" arearefs="hello-csharp-session">
- <para>Creates a session object on which messages will be sent and received.</para>
- </callout>
- <callout id="callout-csharp-receiver" arearefs="hello-csharp-receiver">
- <para>Creates a receiver that receives messages from the given address.</para>
- </callout>
- <callout id="callout-csharp-sender" arearefs="hello-csharp-sender">
- <para>Creates a sender that sends to the given address.</para>
- </callout>
- <callout id="callout-csharp-fetch" arearefs="hello-csharp-fetch">
- <para>Receives the next message. The duration is optional, if omitted, will wait indefinitely for the next message.</para>
- </callout>
- <callout id="callout-csharp-acknowledge" arearefs="hello-csharp-acknowledge">
- <para>Acknowledges receipt of all fetched messages on the
- session. This informs the broker that the messages were
- transfered and processed by the client successfully.</para>
- </callout>
- <callout id="callout-csharp-close" arearefs="hello-csharp-close">
- <para>Closes the connection, all sessions managed by the connection, and all senders and receivers managed by each session.</para>
- </callout>
- </calloutlist>
- </example>
-
-
- </section>
-
-
-
-
-
-
- <section id="section-addresses">
- <title>Addresses</title>
-
- <para>An <firstterm>address</firstterm> is the name of a message
- target or message source.
-
- <footnote><para>In the programs we have just seen, we used
- <literal>amq.topic</literal> as the default address if none is
- passed in. This is the name of a standard exchange that always
- exists on an AMQP 0-10 messaging broker.</para></footnote>
-
- The methods that create senders and receivers require an
- address. The details of sending to a particular target or
- receiving from a particular source are then handled by the
- sender or receiver. A different target or source can be used
- simply by using a different address.
- </para>
-
- <para>An address resolves to a <firstterm>node</firstterm>. The
- Qpid Messaging API recognises two kinds of nodes,
- <firstterm>queues</firstterm> and <firstterm>topics</firstterm>
-
- <footnote><para>The terms <emphasis>queue</emphasis> and
- <emphasis>topic</emphasis> here were chosen to align with
- their meaning in JMS. These two addressing 'patterns',
- queue and topic, are sometimes refered as point-to-point
- and publish-subscribe. AMQP 0-10 has an exchange type
- called a <emphasis>topic exchange</emphasis>. When the term
- <emphasis>topic</emphasis> occurs alone, it refers to a
- Messaging API topic, not the topic
- exchange.</para></footnote>.
-
- A queue stores each message until it has been received and
- acknowledged, and only one receiver can receive a given message
-
- <footnote><para>There are exceptions to this rule; for instance,
- a receiver can use <literal>browse</literal> mode, which leaves
- messages on the queue for other receivers to
- read.</para></footnote>.
-
- A topic immediately delivers a message to all eligible
- receivers; if there are no eligible receivers, it discards the
- message. In the AMQP 0-10 implementation of the API,
-
- <footnote><para>The AMQP 0-10 implementation is the only one
- that currently exists.</para></footnote>
-
- queues map to AMQP queues, and topics map to AMQP exchanges.
-
- <footnote><para>In AMQP 0-10, messages are sent to
- exchanges, and read from queues. The Messaging API also
- allows a sender to send messages to a queue; internally,
- Qpid implements this by sending the message to the default
- exchange, with the name of the queue as the routing key. The
- Messaging API also allows a receiver to receive messages
- from a topic; internally, Qpid implements this by setting up
- a private subscription queue for the receiver and binding
- the subscription queue to the exchange that corresponds to
- the topic.</para></footnote>
- </para>
-
- <para>In the rest of this tutorial, we present many examples
- using two programs that take an address as a command line
- parameter. <command>spout</command> sends messages to the
- target address, <command>drain</command> receives messages from
- the source address. The source code is available in C++, Python, and
- .NET C# and can be found in the examples directory for each
- language. These programs can use any address string as a source
- or a destination, and have many command line options to
- configure behavior&mdash;use the <command>-h</command> option
- for documentation on these options.
-
- <footnote><para>Currently, the C++, Python, and .NET C#
- implementations of <command>drain</command> and
- <command>spout</command> have slightly different
- options. This tutorial uses the C++ implementation. The
- options will be reconciled in the near
- future.</para></footnote>
-
-
- The examples in this tutorial also use the
- <command>qpid-config</command> utility to configure AMQP 0-10
- queues and exchanges on a Qpid broker.
- </para>
-
-
- <example>
- <title>Queues</title>
-
- <para>Create a queue with <command>qpid-config</command>, send a message using
- <command>spout</command>, and read it using <command>drain</command>:</para>
-
- <screen>
- $ qpid-config add queue hello-world
- $ ./spout hello-world
- $ ./drain hello-world
-
- Message(properties={spout-id:c877e622-d57b-4df2-bf3e-6014c68da0ea:0}, content='')
- </screen>
-
- <para>The queue stored the message sent by <command>spout</command> and delivered
- it to <command>drain</command> when requested.</para>
-
- <para>Once the message has been delivered and and acknowledged
- by <command>drain</command>, it is no longer available on the queue. If we run
- <command>drain</command> one more time, no messages will be retrieved.</para>
-
- <screen>
- $ ./drain hello-world
- $
- </screen>
-
- </example>
-
- <example>
- <title>Topics</title>
-
- <para>This example is similar to the previous example, but it
- uses a topic instead of a queue.</para>
-
- <para>First, use <command>qpid-config</command> to remove the queue
- and create an exchange with the same name:</para>
-
- <screen>
- $ qpid-config del queue hello-world
- $ qpid-config add exchange topic hello-world
- </screen>
-
- <para>Now run <command>drain</command> and <command>spout</command> the same way we did in the previous example:</para>
-
- <screen>
- $ ./spout hello-world
- $ ./drain hello-world
- $
- </screen>
-
- <para>Topics deliver messages immediately to any interested
- receiver, and do not store messages. Because there were no
- receivers at the time <command>spout</command> sent the
- message, it was simply discarded. When we ran
- <command>drain</command>, there were no messages to
- receive.</para>
-
- <para>Now let's run <command>drain</command> first, using the
- <literal>-t</literal> option to specify a timeout in seconds.
- While <command>drain</command> is waiting for messages,
- run <command>spout</command> in another window.</para>
-
- <para><emphasis>First Window:</emphasis></para>
-
- <screen>
- $ ./drain -t 30 hello-word
- </screen>
-
-
- <para><emphasis>Second Window:</emphasis></para>
-
- <screen>
- $ ./spout hello-word
- </screen>
-
- <para>Once <command>spout</command> has sent a message, return
- to the first window to see the output from
- <command>drain</command>:</para>
-
- <screen>
- Message(properties={spout-id:7da2d27d-93e6-4803-8a61-536d87b8d93f:0}, content='')
- </screen>
-
- <para>You can run <command>drain</command> in several separate
- windows; each creates a subscription for the exchange, and
- each receives all messages sent to the exchange.</para>
-
- </example>
-
- <section>
- <title>Address Strings</title>
-
- <para>So far, our examples have used address strings that
- contain only the name of a node. An <firstterm>address
- string</firstterm> can also contain a
- <firstterm>subject</firstterm> and
- <firstterm>options</firstterm>.</para>
-
- <para>The syntax for an address string is:</para>
-
- <programlisting><![CDATA[
- address_string ::= <address> [ / <subject> ] [ ; <options> ]
- options ::= { <key> : <value>, ... }
- ]]></programlisting>
-
- <para>Addresses, subjects, and keys are strings. Values can
- be numbers, strings (with optional single or double quotes),
- maps, or lists. A complete BNF for address strings appears in
- <xref linkend="section-address-string-bnf"/>.</para>
-
-
- <para>So far, the address strings in this tutorial have only
- used simple names. The following sections show how to use
- subjects and options.</para>
-
- </section>
-
- <section>
- <title>Subjects</title>
-
-
- <para>Every message has a property called
- <firstterm>subject</firstterm>, which is analogous to the
- subject on an email message. If no subject is specified, the
- message's subject is null. For convenience, address strings
- also allow a subject. If a sender's address contains a
- subject, it is used as the default subject for the messages
- it sends.
-
- If a receiver's address contains a subject, it is used to
- select only messages that match the subject&mdash;the matching
- algorithm depends on the message source.
- </para>
-
- <para>
- In AMQP 0-10, each exchange type has its own matching
- algorithm. This is discussed in
- <xref linkend="section-amqp0-10-mapping"/>.
- </para>
-
- <note>
- <para>
- Currently, a receiver bound to a queue ignores subjects,
- receiving messages from the queue without filtering. Support
- for subject filtering on queues will be implemented soon.
- </para>
- </note>
-
-
- <example>
- <title>Using subjects</title>
-
- <para>In this example we show how subjects affect message
- flow.</para>
-
- <para>First, let's use <command>qpid-config</command> to create a topic exchange.</para>
-
- <screen>
- $ qpid-config add exchange topic news-service
- </screen>
-
- <para>Now we use drain to receive messages from <literal>news-service</literal> that match the subject <literal>sports</literal>.</para>
- <para><emphasis>First Window:</emphasis></para>
- <screen>
- $ ./drain -t 30 news-service/sports
- </screen>
-
- <para>In a second window, let's send messages to <literal>news-service</literal> using two different subjects:</para>
-
- <para><emphasis>Second Window:</emphasis></para>
- <screen>
- $ ./spout news-service/sports
- $ ./spout news-service/news
- </screen>
-
- <para>Now look at the first window, the message with the
- subject <literal>sports</literal> has been received, but not
- the message with the subject <literal>news</literal>:</para>
-
- <screen>
- Message(properties={qpid.subject:sports, spout-id:9441674e-a157-4780-a78e-f7ccea998291:0}, content='')
- </screen>
-
- <para>If you run <command>drain</command> in multiple
- windows using the same subject, all instances of
- <command>drain</command> receive the messages for that
- subject.</para>
- </example>
-
-
- <para>The AMQP exchange type we are using here,
- <literal>amq.topic</literal>, can also do more sophisticated
- matching.
-
- A sender's subject can contain multiple words separated by a
- <quote>.</quote> delimiter. For instance, in a news
- application, the sender might use subjects like
- <literal>usa.news</literal>, <literal>usa.weather</literal>,
- <literal>europe.news</literal>, or
- <literal>europe.weather</literal>.
-
- The receiver's subject can include wildcard characters&mdash;
- <quote>#</quote> matches one or more words in the message's
- subject, <quote>*</quote> matches a single word.
-
- For instance, if the subject in the source address is
- <literal>*.news</literal>, it matches messages with the
- subject <literal>europe.news</literal> or
- <literal>usa.news</literal>; if it is
- <literal>europe.#</literal>, it matches messages with subjects
- like <literal>europe.news</literal> or
- <literal>europe.pseudo.news</literal>.</para>
-
- <example>
- <title>Subjects with multi-word keys</title>
-
- <para>This example uses drain and spout to demonstrate the
- use of subjects with two-word keys.</para>
-
- <para>Let's use <command>drain</command> with the subject
- <literal>*.news</literal> to listen for messages in which
- the second word of the key is
- <literal>news</literal>.</para>
-
- <para><emphasis>First Window:</emphasis></para>
-
- <screen>
- $ ./drain -t 30 news-service/*.news
- </screen>
-
- <para>Now let's send messages using several different
- two-word keys:</para>
-
- <para><emphasis>Second Window:</emphasis></para>
-
- <screen>
- $ ./spout news-service/usa.news
- $ ./spout news-service/usa.sports
- $ ./spout news-service/europe.sports
- $ ./spout news-service/europe.news
- </screen>
-
- <para>In the first window, the messages with
- <literal>news</literal> in the second word of the key have
- been received:</para>
-
- <screen>
- Message(properties={qpid.subject:usa.news, spout-id:73fc8058-5af6-407c-9166-b49a9076097a:0}, content='')
- Message(properties={qpid.subject:europe.news, spout-id:f72815aa-7be4-4944-99fd-c64c9747a876:0}, content='')
- </screen>
-
-
- <para>Next, let's use <command>drain</command> with the
- subject <literal>#.news</literal> to match any sequence of
- words that ends with <literal>news</literal>.</para>
-
- <para><emphasis>First Window:</emphasis></para>
-
- <screen>
- $ ./drain -t 30 news-service/#.news
- </screen>
-
- <para>In the second window, let's send messages using a
- variety of different multi-word keys:</para>
-
- <para><emphasis>Second Window:</emphasis></para>
-
- <screen>
- $ ./spout news-service/news
- $ ./spout news-service/sports
- $ ./spout news-service/usa.news
- $ ./spout news-service/usa.sports
- $ ./spout news-service/usa.faux.news
- $ ./spout news-service/usa.faux.sports
- </screen>
-
- <para>In the first window, messages with
- <literal>news</literal> in the last word of the key have been
- received:</para>
-
- <screen>
- Message(properties={qpid.subject:news, spout-id:cbd42b0f-c87b-4088-8206-26d7627c9640:0}, content='')
- Message(properties={qpid.subject:usa.news, spout-id:234a78d7-daeb-4826-90e1-1c6540781eac:0}, content='')
- Message(properties={qpid.subject:usa.faux.news, spout-id:6029430a-cfcb-4700-8e9b-cbe4a81fca5f:0}, content='')
- </screen>
- </example>
-
- </section>
-
- <section>
- <title>Address String Options</title>
-
- <para>
- The options in an address string can contain additional
- information for the senders or receivers created for it,
- including:
- </para>
- <itemizedlist>
- <listitem>
- <para>
- Policies for assertions about the node to which an address
- refers.
- </para>
- <para>
- For instance, in the address string <literal>my-queue;
- {assert: always, node:{ type: queue }}</literal>, the node
- named <literal>my-queue</literal> must be a queue; if not,
- the address does not resolve to a node, and an exception
- is raised.
- </para>
- </listitem>
- <listitem>
- <para>
- Policies for automatically creating or deleting the node to which an address refers.
- </para>
- <para>
- For instance, in the address string <literal>xoxox ; {create: always}</literal>,
- the queue <literal>xoxox</literal> is created, if it does
- not exist, before the address is resolved.
- </para>
- </listitem>
- <listitem>
- <para>
- Extension points that can be used for sender/receiver configuration.
- </para>
- <para>
- For instance, if the address for a receiver is
- <literal>my-queue; {mode: browse}</literal>, the receiver
- works in <literal>browse</literal> mode, leaving messages
- on the queue so other receivers can receive them.
- </para>
- </listitem>
- <listitem>
- <para>
- Extension points providing more direct control over the underlying protocol.
- </para>
- <para>
- For instance, the <literal>x-bindings</literal> property
- allows greater control over the AMQP 0-10 binding process
- when an address is resolved.
- </para>
- </listitem>
- </itemizedlist>
-
-
- <para>
- Let's use some examples to show how these different kinds of
- address string options affect the behavior of senders and
- receives.
- </para>
-
- <section>
- <title>assert</title>
- <para>
- In this section, we use the <literal>assert</literal> option
- to ensure that the address resolves to a node of the required
- type.
- </para>
-
-
- <example>
- <title>Assertions on Nodes</title>
-
- <para>Let's use <command>qpid-config</command> to create a
- queue and a topic.</para>
-
- <screen>
- $ qpid-config add queue my-queue
- $ qpid-config add exchange topic my-topic
- </screen>
-
- <para>
- We can now use the address specified to drain to assert that it is
- of a particular type:
- </para>
-
- <screen>
- $ ./drain 'my-queue; {assert: always, node:{ type: queue }}'
- $ ./drain 'my-queue; {assert: always, node:{ type: topic }}'
- 2010-04-20 17:30:46 warning Exception received from broker: not-found: not-found: Exchange not found: my-queue (../../src/qpid/broker/ExchangeRegistry.cpp:92) [caused by 2 \x07:\x01]
- Exchange my-queue does not exist
- </screen>
-
- <para>
- The first attempt passed without error as my-queue is indeed a
- queue. The second attempt however failed; my-queue is not a
- topic.
- </para>
-
- <para>
- We can do the same thing for my-topic:
- </para>
-
- <screen>
- $ ./drain 'my-topic; {assert: always, node:{ type: topic }}'
- $ ./drain 'my-topic; {assert: always, node:{ type: queue }}'
- 2010-04-20 17:31:01 warning Exception received from broker: not-found: not-found: Queue not found: my-topic (../../src/qpid/broker/SessionAdapter.cpp:754) [caused by 1 \x08:\x01]
- Queue my-topic does not exist
- </screen>
- </example>
-
- <para>Now let's use the <literal>create</literal> option to
- create the queue <literal>xoxox</literal> if it does not already
- exist:</para>
-
- </section>
-
- <section>
- <title>create</title>
-
- <para>In previous examples, we created the queue before
- listening for messages on it. Using <literal>create:
- always</literal>, the queue is automatically created if it
- does not exist.</para>
-
- <example>
- <title>Creating a Queue Automatically</title>
-
- <para><emphasis>First Window:</emphasis></para>
- <screen>$ ./drain -t 30 "xoxox ; {create: always}"</screen>
-
-
- <para>Now we can send messages to this queue:</para>
-
- <para><emphasis>Second Window:</emphasis></para>
- <screen>$ ./spout "xoxox ; {create: always}"</screen>
-
- <para>Returning to the first window, we see that <command>drain</command> has received this message:</para>
-
- <screen>Message(properties={spout-id:1a1a3842-1a8b-4f88-8940-b4096e615a7d:0}, content='')</screen>
- </example>
- <para>The details of the node thus created can be controlled by further options within the node. See <xref linkend="table-node-properties"/> for details.</para>
- </section>
-
- <section>
- <title>browse</title>
- <para>Some options specify message transfer semantics; for
- instance, they may state whether messages should be consumed or
- read in browsing mode, or specify reliability
- characteristics. The following example uses the
- <literal>browse</literal> option to receive messages without
- removing them from a queue.</para>
-
- <example>
- <title>Browsing a Queue</title>
- <para>
- Let's use the browse mode to receive messages without
- removing them from the queue. First we send three messages to the
- queue:
- </para>
- <screen>
- $ ./spout my-queue --content one
- $ ./spout my-queue --content two
- $ ./spout my-queue --content three
- </screen>
-
- <para>Now we use drain to get those messages, using the browse option:</para>
- <screen>
- $ ./drain 'my-queue; {mode: browse}'
- Message(properties={spout-id:fbb93f30-0e82-4b6d-8c1d-be60eb132530:0}, content='one')
- Message(properties={spout-id:ab9e7c31-19b0-4455-8976-34abe83edc5f:0}, content='two')
- Message(properties={spout-id:ea75d64d-ea37-47f9-96a9-d38e01c97925:0}, content='three')
- </screen>
-
- <para>We can confirm the messages are still on the queue by repeating the drain:</para>
- <screen>
- $ ./drain 'my-queue; {mode: browse}'
- Message(properties={spout-id:fbb93f30-0e82-4b6d-8c1d-be60eb132530:0}, content='one')
- Message(properties={spout-id:ab9e7c31-19b0-4455-8976-34abe83edc5f:0}, content='two')
- Message(properties={spout-id:ea75d64d-ea37-47f9-96a9-d38e01c97925:0}, content='three')
- </screen>
- </example>
- </section>
-
- <section>
- <title>x-bindings</title>
-
- <para>Greater control over the AMQP 0-10 binding process can
- be achieved by including an <literal>x-bindings</literal>
- option in an address string.
-
- For instance, the XML Exchange is an AMQP 0-10 custom exchange
- provided by the Apache Qpid C++ broker. It allows messages to
- be filtered using XQuery; queries can address either message
- properties or XML content in the body of the message. The
- xquery is specified in the arguments field of the AMQP 0-10
- command. When using the messaging API an xquery can be
- specified in and address that resolves to an XML exchange by
- using the x-bindings property.</para>
-
-
- <para>An instance of the XML Exchange must be added before it
- can be used:</para>
-
- <programlisting>
- $ qpid-config add exchange xml xml
- </programlisting>
-
- <para>When using the XML Exchange, a receiver provides an
- XQuery as an x-binding argument. If the query contains a
- context item (a path starting with <quote>.</quote>), then it
- is applied to the content of the message, which must be
- well-formed XML. For instance, <literal>./weather</literal> is
- a valid XQuery, which matches any message in which the root
- element is named <literal>weather</literal>. Here is an
- address string that contains this query:</para>
-
- <programlisting><![CDATA[
- xml; {
- link: {
- x-bindings: [{exchange:xml, key:weather, arguments:{xquery:"./weather"} }]
- }
- }
- ]]></programlisting>
-
- <para>When using longer queries with <command>drain</command>,
- it is often useful to place the query in a file, and use
- <command>cat</command> in the command line. We do this in the
- following example.</para>
-
- <example>
- <title>Using the XML Exchange</title>
-
- <para>This example uses an x-binding that contains queries, which filter based on the content of XML messages. Here is an XQuery that we will use in this example:</para>
-
- <programlisting>
- <![CDATA[
- let $w := ./weather
- return $w/station = 'Raleigh-Durham International Airport (KRDU)'
- and $w/temperature_f > 50
- and $w/temperature_f - $w/dewpoint > 5
- and $w/wind_speed_mph > 7
- and $w/wind_speed_mph < 20 ]]>
- </programlisting>
-
- <para>We can specify this query in an x-binding to listen to messages that meet the criteria specified by the query:</para>
-
- <para><emphasis>First Window:</emphasis></para>
-
- <screen>
- $ ./drain -f "xml; {link:{x-bindings:[{key:'weather',
- arguments:{xquery:\"$(cat rdu.xquery )\"}}]}}"
- </screen>
-
- <para>In another window, let's create an XML message that meets the criteria in the query, and place it in the file <filename>rdu.xml</filename>:</para>
-
- <programlisting>
- <![CDATA[
- <weather>
- <station>Raleigh-Durham International Airport (KRDU)</station>
- <wind_speed_mph>16</wind_speed_mph>
- <temperature_f>70</temperature_f>
- <dewpoint>35</dewpoint>
- </weather>
- ]]></programlisting>
-
- <para>Now let's use <command>spout</command> to send this message to the XML exchange:</para>
-
- <para><emphasis>Second Window:</emphasis></para>
- <screen>
- spout --content "$(cat rdu.xml)" xml/weather
- </screen>
-
- <para>Returning to the first window, we see that the message has been received:</para>
-
- <screen><![CDATA[$ ./drain -f "xml; {link:{x-bindings:[{exchange:'xml', key:'weather', arguments:{xquery:\"$(cat rdu.xquery )\"}}]}}"
- Message(properties={qpid.subject:weather, spout-id:31c431de-593f-4bec-a3dd-29717bd945d3:0},
- content='<weather>
- <station>Raleigh-Durham International Airport (KRDU)</station>
- <wind_speed_mph>16</wind_speed_mph>
- <temperature_f>40</temperature_f>
- <dewpoint>35</dewpoint>
- </weather>') ]]>
- </screen>
- </example>
- </section>
-
- <!--
- <para>When sending data using <command>cat</command> to provide arguments to <command>spout</command>, you can use <command>sed</command> to change the values that are sent:</para>
-
-<screen>
-spout - -content "$(cat rdu.xml | sed -e 's/70/45/')" xml/weather
-</screen>
- -->
-
- <!--
- TODO: Add some reliability option examples
- -->
-
- <section>
- <title>Address String Options - Reference</title>
-
- <table pgwide="1">
- <title>Address String Options</title>
- <tgroup cols="3">
- <thead>
- <colspec colnum="1" colwidth="1*"/>
- <colspec colnum="2" colwidth="3*"/>
- <colspec colnum="3" colwidth="3*"/>
- <row>
- <entry>option</entry>
- <entry>value</entry>
- <entry>semantics</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- assert
- </entry>
- <entry>
- one of: always, never, sender or receiver
- </entry>
- <entry>
- Asserts that the properties specified in the node option
- match whatever the address resolves to. If they do not,
- resolution fails and an exception is raised. <!-- ###
- Which exception -->
- </entry>
- </row>
-
- <row>
- <entry>
- create
- </entry>
- <entry>
- one of: always, never, sender or receiver
- </entry>
- <entry>
- Creates the node to which an address refers if it does
- not exist. No error is raised if the node does
- exist. The details of the node may be specified in the
- node option.
- </entry>
- </row>
- <row>
- <entry>
- delete
- </entry>
- <entry>
- one of: always, never, sender or receiver
- </entry>
- <entry>
- Delete the node when the sender or receiver is closed.
- </entry>
- </row>
- <row>
- <entry>
- node
- </entry>
- <entry>
- A nested map containing the entries shown in <xref linkend="table-node-properties"/>.
- </entry>
- <entry>
- Specifies properties of the node to which the address
- refers. These are used in conjunction with the assert or
- create options.
- </entry>
- </row>
- <row>
- <entry>
- link
- </entry>
- <entry>
- A nested map containing the entries shown in <xref linkend="table-link-properties"/>.
- </entry>
- <entry>
- Used to control the establishment of a conceptual link
- from the client application to or from the target/source
- address.
- </entry>
- </row>
- <row>
- <entry>
- mode
- </entry>
- <entry>
- one of: browse, consume
- </entry>
- <entry>
- This option is only of relevance for source addresses
- that resolve to a queue. If browse is specified the
- messages delivered to the receiver are left on the queue
- rather than being removed. If consume is specified the
- normal behaviour applies; messages are removed from the
- queue once the client acknowledges their receipt.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
-
- <table id="table-node-properties" pgwide="1">
- <title>Node Properties</title>
- <tgroup cols="3">
- <thead>
- <colspec colnum="1" colwidth="1*"/>
- <colspec colnum="2" colwidth="3*"/>
- <colspec colnum="3" colwidth="3*"/>
- <row>
- <entry>property</entry>
- <entry>value</entry>
- <entry>semantics</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- type
- </entry>
- <entry>
- topic, queue
- </entry>
- <entry>
- Indicates the type of the node.
- </entry>
- </row>
- <row>
- <entry>
- durable
- </entry>
- <entry>
- True, False
- </entry>
- <entry>
- Indicates whether the node survives a loss of
- volatile storage e.g. if the broker is restarted.
- </entry>
- </row>
- <row>
- <entry>
- x-declare
- </entry>
- <entry>
- A nested map whose values correspond to the valid fields
- on an AMQP 0-10 queue-declare or exchange-declare
- command.
- </entry>
- <entry>
- These values are used to fine tune the creation or
- assertion process. Note however that they are protocol
- specific.
- </entry>
- </row>
- <row>
- <entry>
- x-bindings
- </entry>
- <entry>
- A nested list in which each binding is represented by
- a map. The entries of the map for a binding contain
- the fields that describe an AMQP 0-10 binding. Here is
- the format for x-bindings:
-
- <programlisting><![CDATA[
- [
- {
- exchange: <exchange>,
- queue: <queue>,
- key: <key>,
- arguments: {
- <key_1>: <value_1>,
- ...,
- <key_n>: <value_n> }
- },
- ...
- ]
- ]]></programlisting>
- </entry>
- <entry>
- In conjunction with the create option, each of these
- bindings is established as the address is resolved. In
- conjunction with the assert option, the existence of
- each of these bindings is verified during
- resolution. Again, these are protocol specific.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table id="table-link-properties" pgwide="1">
- <title>Link Properties</title>
- <tgroup cols="3">
- <thead>
- <colspec colnum="1" colwidth="1*"/>
- <colspec colnum="2" colwidth="3*"/>
- <colspec colnum="3" colwidth="3*"/>
- <row>
- <entry>option</entry>
- <entry>value</entry>
- <entry>semantics</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- reliability
- </entry>
- <entry>
- one of: unreliable, at-least-once, at-most-once, exactly-once
- </entry>
- <entry>
- Reliability indicates the level of reliability that
- the sender or receiver. <literal>unreliable</literal>
- and <literal>at-most-once</literal> are currently
- treated as synonyms, and allow messages to be lost if
- a broker crashes or the connection to a broker is
- lost. <literal>at-least-once</literal> guarantees that
- a message is not lost, but duplicates may be
- received. <literal>exactly-once</literal> guarantees
- that a message is not lost, and is delivered precisely
- once. Currently only <literal>unreliable</literal>
- and <literal>at-least-once</literal> are supported.
- <footnote><para>If at-most-once is requested,
- unreliable will be used and for durable messages on
- durable queues there is the possibility that messages
- will be redelivered; if exactly-once is requested,
- at-least-once will be used and the application needs to
- be able to deal with duplicates.</para></footnote>
- </entry>
- </row>
- <row>
- <entry>
- durable
- </entry>
- <entry>
- True, False
- </entry>
- <entry>
- Indicates whether the link survives a loss of
- volatile storage e.g. if the broker is restarted.
- </entry>
- </row>
- <row>
- <entry>
- x-declare
- </entry>
- <entry>
- A nested map whose values correspond to the valid fields
- of an AMQP 0-10 queue-declare command.
- </entry>
- <entry>
- These values can be used to customise the subscription
- queue in the case of receiving from an exchange. Note
- however that they are protocol specific.
- </entry>
- </row>
- <row>
- <entry>
- x-subscribe
- </entry>
- <entry>
- A nested map whose values correspond to the valid fields
- of an AMQP 0-10 message-subscribe command.
- </entry>
- <entry>
- These values can be used to customise the subscription.
- </entry>
- </row>
- <row>
- <entry>
- x-bindings
- </entry>
- <entry>
- A nested list each of whose entries is a map that may
- contain fields (queue, exchange, key and arguments)
- describing an AMQP 0-10 binding.
- </entry>
- <entry>
- These bindings are established during resolution
- independent of the create option. They are considered
- logically part of the linking process rather than of
- node creation.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- </section>
- </section>
-
- <section id="section-address-string-bnf">
- <title>Address String Grammar</title>
-
- <para>This section provides a formal grammar for address strings.</para>
-
- <formalpara>
- <title>Tokens</title>
- <para>The following regular expressions define the tokens used
- to parse address strings:</para></formalpara>
- <programlisting><![CDATA[
- LBRACE: \\{
- RBRACE: \\}
- LBRACK: \\[
- RBRACK: \\]
- COLON: :
- SEMI: ;
- SLASH: /
- COMMA: ,
- NUMBER: [+-]?[0-9]*\\.?[0-9]+
- ID: [a-zA-Z_](?:[a-zA-Z0-9_-]*[a-zA-Z0-9_])?
- STRING: "(?:[^\\\\"]|\\\\.)*"|\'(?:[^\\\\\']|\\\\.)*\'
- 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]
- SYM: [.#*%@$^!+-]
- WSPACE: [ \\n\\r\\t]+
- ]]></programlisting>
-
- <formalpara>
- <title>Grammar</title>
- <para>The formal grammar for addresses is given below:</para>
- </formalpara>
-
- <programlisting><![CDATA[
- address := name [ SLASH subject ] [ ";" options ]
- name := ( part | quoted )+
- subject := ( part | quoted | SLASH )*
- quoted := STRING / ESC
- part := LBRACE / RBRACE / COLON / COMMA / NUMBER / ID / SYM
- options := map
- map := "{" ( keyval ( "," keyval )* )? "}"
- keyval "= ID ":" value
- value := NUMBER / STRING / ID / map / list
- list := "[" ( value ( "," value )* )? "]"
- ]]></programlisting>
-
-
- <formalpara>
- <title>Address String Options</title>
- <para>The address string options map supports the following parameters:</para>
- </formalpara>
-
- <programlisting><![CDATA[
- <name> [ / <subject> ] ; {
- create: always | sender | receiver | never,
- delete: always | sender | receiver | never,
- assert: always | sender | receiver | never,
- mode: browse | consume,
- node: {
- type: queue | topic,
- durable: True | False,
- x-declare: { ... <declare-overrides> ... },
- x-bindings: [<binding_1>, ... <binding_n>]
- },
- link: {
- name: <link-name>,
- durable: True | False,
- reliability: unreliable | at-most-once | at-least-once | exactly-once,
- x-declare: { ... <declare-overrides> ... },
- x-bindings: [<binding_1>, ... <binding_n>],
- x-subscribe: { ... <subscribe-overrides> ... }
- }
- }
- ]]></programlisting>
-
-
- <itemizedlist>
- <title>Create, Delete, and Assert Policies</title>
- <para>The create, delete, and assert policies specify who should
- perfom the associated action:</para>
- <listitem><para><emphasis>always</emphasis>: the action is performed by any messaging client</para></listitem>
- <listitem><para><emphasis>sender</emphasis>: the action is only performed by a sender</para></listitem>
- <listitem><para><emphasis>receiver</emphasis>: the action is only performed by a receiver</para></listitem>
- <listitem><para><emphasis>never</emphasis>: the action is never performed (this is the default)</para></listitem>
- </itemizedlist>
-
- <itemizedlist>
- <title>Node-Type</title>
- <para>The node-type is one of:</para>
- <listitem><para><emphasis>topic</emphasis>: in the AMQP 0-10
- mapping, a topic node defaults to the topic exchange, x-declare
- may be used to specify other exchange types</para></listitem>
- <listitem><para><emphasis>queue</emphasis>: this is the default node-type</para></listitem>
- </itemizedlist>
- </section>
-
-
- </section>
-
- <section id="replay">
- <title>Sender Capacity and Replay</title>
-
- <para>The send method of a sender has an optional second parameter
- that controls whether the send call is synchronous or not. A
- synchronous send call will block until the broker has confirmed
- receipt of the message. An asynchronous send call will return
- before the broker confirms receipt of the message, allowing for
- example further send calls to be made without waiting for a
- roundtrip to the broker for each message. This is desirable where
- increased throughput is important.</para>
-
- <para>The sender maintains a list of sent messages whose receipt
- has yet to be confirmed by the broker. The maximum number of such
- messages that it will hold is defined by the capacity of the
- sender, which can be set by the application. If an application
- tries to send with a sender whose capacity is already fully used
- up, the send call will block waiting for capacity regardless of
- the value of the sync flag.</para>
-
- <para>The sender can be queried for the available space (i.e. the
- unused capacity), and for the current count of unsettled messages
- (i.e. those held in the replay list pending confirmation by the
- server). When the unsettled count is zero, all messages on that
- sender have been successfully sent.</para>
-
- <para>If the connection fails and is transparently reconnected
- (see <xref linkend="connection-options"/> for details on how to control
- this feature), the unsettled messages for each sender over that
- connection will be re-transmitted. This provides a transparent
- level of reliability. This feature can be controlled through the
- link's reliability as defined in the address (see
- <xref linkend="table-link-properties"/>). At present only
- at-least-once guarantees are offered. </para>
- </section>
-
- <section id="prefetch">
- <title>Receiver Capacity (Prefetch)</title>
-
- <para>By default, a receiver requests the next message from the
- server in response to each fetch call, resulting in messages being
- sent to the receiver one at a time. As in the case of sending, it
- is often desirable to avoid this roundtrip for each message. This
- can be achieved by allowing the receiver
- to <firstterm>prefetch</firstterm> messages in anticipation of
- fetch calls being made. The receiver needs to be able to store
- these prefetched messages, the number it can hold is controlled by
- the receivers capacity.</para>
-
- </section>
-
- <section id="acknowledgements">
- <title>Acknowledging Received Messages</title>
-
- <para>Applications that receive messages should acknowledge their
- receipt by calling the session's acknowledge method. As in the
- case of sending messages, acknowledged transfer of messages to
- receivers provides at-least-once reliability, which means that the
- loss of the connection or a client crash does not result in lost
- messages; durable messages are not lost even if the broker is
- restarted.
-
- Some cases may not require this however and the reliability can be
- controlled through a link property in the address options (see
- <xref linkend="table-link-properties"/>).</para>
-
- <para>The acknowledge call acknowledges all messages received on
- the session (i.e. all message that have been returned from a fetch
- call on a receiver created on that session).</para>
-
- <para>The acknowledge call also support an optional parameter
- controlling whether the call is synchronous or not. A synchronous
- acknowledge will block until the server has confirmed that it has
- received the acknowledgement. In the asynchronous case, when the
- call returns there is not yet any guarantee that the server has
- received and processed the acknowledgement. The session may be
- queried for the number of unsettled acknowledgements; when that
- count is zero all acknowledgements made for received messages have
- been successful.</para>
-
- </section>
-
-
- <section>
- <title>Receiving Messages from Multiple Sources</title>
-
- <para>A receiver can only read from one source, but many
- programs need to be able to read messages from many sources. In
- the Qpid Messaging API, a program can ask a session for
- the <quote>next receiver</quote>; that is, the receiver that is
- responsible for the next available message. The following
- examples show how this is done in C++, Python, and .NET C#.
- </para>
-
- <para>Note that to use this pattern you must enable prefetching
- for each receiver of interest so that the broker will send
- messages before a fetch call is made. See
- <xref linkend="prefetch"/> for more on this.</para>
-
- <example>
- <title>Receiving Messages from Multiple Sources</title>
-
- <para>C++:</para>
-
- <programlisting><![CDATA[
- Receiver receiver1 = session.createReceiver(address1);
- receiver1.setCapacity(10);
- Receiver receiver2 = session.createReceiver(address2);
- receiver2.setCapacity(10);
-
- Message message = session.nextReceiver().fetch();
- std::cout << message.getContent() << std::endl;
- session.acknowledge(); // acknowledge message receipt
- ]]> </programlisting>
-
- <para>Python:</para>
- <programlisting><![CDATA[
- receiver1 = session.receiver(address1)
- receiver1.capacity = 10
- receiver2 = session.receiver(address)
- receiver2.capacity = 10
- message = session.next_receiver().fetch()
- print message.content
- session.acknowledge()
- ]]> </programlisting>
-
- <para>.NET C#:</para>
- <programlisting><![CDATA[
- Receiver receiver1 = session.CreateReceiver(address1);
- receiver1.Capacity = 10;
- Receiver receiver2 = session.CreateReceiver(address2);
- receiver2.Capacity = 10;
-
- Message message = new Message();
- message = session.NextReceiver().Fetch();
- Console.WriteLine("{0}", message.GetContent());
- session.Acknowledge();
- ]]> </programlisting>
-
- </example>
- </section>
-
- <section>
- <title>Transactions</title>
-
- <para>Sometimes it is useful to be able to group messages
- transfers - sent and/or received - on a session into atomic
- grouping. This can be done be creating the session as
- transactional. On a transactional session sent messages only
- become available at the target address on commit. Likewise any
- received and acknowledged messages are only discarded at their
- source on commit
-
- <footnote><para>Note that this currently is only true for
- messages received using a reliable mode
- e.g. at-least-once. Messages sent by a broker to a receiver in
- unreliable receiver will be discarded immediately regardless of
- transctionality.</para></footnote>
-
- .</para>
-
- <example>
- <title>Transactions</title>
- <para>C++:</para>
- <programlisting><![CDATA[
- Connection connection(broker);
- Session session = connection.createTransactionalSession();
- ...
- if (smellsOk())
- session.commit();
- else
- session.rollback();
- ]]></programlisting>
- <para>
- .NET C#:
- </para>
-
- <programlisting>
- Connection connection = new Connection(broker);
- Session session = connection.CreateTransactionalSession();
- ...
- if (smellsOk())
- session.Commit();
- else
- session.Rollback();
- </programlisting>
- <!--
- <para>Python</para>
- <programlisting><![CDATA[
- ### TODO
- ]]></programlisting>
- -->
- </example>
-
- </section>
-
- <section id="connection-options">
- <title>Connection Options</title>
-
- <para>
- Aspects of the connections behaviour can be controlled through
- specifying connection options. For example, connections can be
- configured to automatically reconnect if the connection to a
- broker is lost.
- </para>
-
- <example>
- <title>Specifying Connection Options in C++, Python, and .NET</title>
-
- <para>In C++, these options can be set using <function>Connection::setOption()</function> or by passing in a set of options to the constructor. The options can be passed in as a map or in string form:</para>
-
- <programlisting><![CDATA[
- Connection connection("localhost:5672", "{reconnect: true}");
- try {
- connection.open();
- !!! SNIP !!!
- ]]></programlisting>
-
- <para>or</para>
-
- <programlisting><![CDATA[
- Connection connection("localhost:5672");
- connection.setOption("reconnect", true);
- try {
- connection.open();
- !!! SNIP !!!
- ]]></programlisting>
-
- <para>In Python, these options can be set as attributes of the connection or using named arguments in
- the <function>Connection</function> constructor:</para>
-
- <programlisting><![CDATA[
- connection = Connection("localhost:5672", reconnect=True)
- try:
- connection.open()
- !!! SNIP !!!
- ]]></programlisting>
-
- <para>or</para>
-
- <programlisting><![CDATA[
- connection = Connection("localhost:5672")
- connection.reconnect = True
- try:
- connection.open()
- !!! SNIP !!!
- ]]></programlisting>
- <para>
- In .NET, these options can be set using <function>Connection.SetOption()</function> or by passing in a set of options to the constructor. The options can be passed in as a map or in string form:
- </para>
-
- <programlisting>
- Connection connection= new Connection(&#34;localhost:5672&#34;, &#34;{reconnect: true}&#34;);
- try {
- connection.Open();
- !!! SNIP !!!
- </programlisting>
- <para>
- or
- </para>
-
- <programlisting>
- Connection connection = new Connection(&#34;localhost:5672&#34;);
- connection.SetOption(&#34;reconnect&#34;, true);
- try {
- connection.Open();
- !!! SNIP !!!
- </programlisting>
-
- <para>See the reference documentation for details in each language.</para>
- </example>
-
- <para>The following table lists the supported connection options.</para>
-
- <table pgwide="1">
- <title>Connection Options</title>
- <tgroup cols="3">
- <thead>
- <colspec colnum="1" colwidth="1*"/>
- <colspec colnum="2" colwidth="1*"/>
- <colspec colnum="3" colwidth="3*"/>
- <row>
- <entry>option name</entry>
- <entry>value type</entry>
- <entry>semantics</entry>
- </row>
- </thead>
- <tbody>
-
- <row>
- <entry>
- <literal>username</literal>
- </entry>
- <entry>
- string
- </entry>
- <entry>
- The username to use when authenticating to the broker.
- </entry>
- </row>
- <row>
- <entry>
- <literal>password</literal>
- </entry>
- <entry>
- string
- </entry>
- <entry>
- The password to use when authenticating to the broker.
- </entry>
- </row>
- <row>
- <entry>
- <literal>sasl_mechanisms</literal>
- </entry>
- <entry>
- string
- </entry>
- <entry>
- The specific SASL mechanisms to use with the python
- client when authenticating to the broker. The value
- is a space separated list.
- </entry>
- </row>
-
-
- <row>
- <entry>
- <literal>reconnect</literal>
- </entry>
- <entry>
- boolean
- </entry>
- <entry>
- Transparently reconnect if the connection is lost.
- </entry>
- </row>
- <row>
- <entry>
- <literal>reconnect_timeout</literal>
- </entry>
- <entry>
- integer
- </entry>
- <entry>
- Total number of seconds to continue reconnection attempts before giving up and raising an exception.
- </entry>
- </row>
- <row>
- <entry>
- <literal>reconnect_limit</literal>
- </entry>
- <entry>
- integer
- </entry>
- <entry>
- Maximum number of reconnection attempts before giving up and raising an exception.
- </entry>
- </row>
- <row>
- <entry>
- <literal>reconnect_interval_min</literal>
- </entry>
- <entry>
- integer representing time in seconds
- </entry>
- <entry>
- 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 <literal>reconnect_interval_min</literal>; if that attempt fails, the reconnect interval increases exponentially until a reconnection attempt succeeds or <literal>reconnect_interval_max</literal> is reached.
- </entry>
- </row>
- <row>
- <entry>
- <literal>reconnect_interval_max</literal>
- </entry>
- <entry>
- integer representing time in seconds
- </entry>
- <entry>
- Maximum reconnect interval.
- </entry>
- </row>
- <row>
- <entry>
- <literal>reconnect_interval</literal>
- </entry>
- <entry>
- integer representing time in seconds
- </entry>
- <entry>
- Sets both <literal>reconnection_interval_min</literal> and <literal>reconnection_interval_max</literal> to the same value.
- </entry>
- </row>
-
- <row>
- <entry>
- <literal>heartbeat</literal>
- </entry>
- <entry>
- integer representing time in seconds
- </entry>
- <entry>
- Requests that heartbeats be sent every N seconds. If two
- successive heartbeats are missed the connection is
- considered to be lost.
- </entry>
- </row>
- <row>
- <entry>
- <literal>protocol</literal>
- </entry>
- <entry>
- string
- </entry>
- <entry>
- Sets the underlying protocol used. The default option is 'tcp'. To enable ssl, set to 'ssl'. The C++ client additionally supports 'rdma'.
- </entry>
- </row>
- <row>
- <entry>
- <literal>tcp-nodelay</literal>
- </entry>
- <entry>
- boolean
- </entry>
- <entry>
- Set tcp no-delay, i.e. disable Nagle algorithm. [C++ only]
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- </section>
-
- <section id="section-Maps">
- <title>Maps and Lists in Message Content</title>
-
- <para>Many messaging applications need to exchange data across
- languages and platforms, using the native datatypes of each
- programming language.</para>
-
- <para>The Qpid Messaging API supports <classname>map</classname> and <classname>list</classname> in message content.
-
- <footnote><para>Unlike JMS, there is not a specific message type for
- map messages.</para></footnote>
-
- <footnote>
- <para>
- Note that the Qpid JMS client supports MapMessages whose values can be nested maps or lists. This is not standard JMS behaviour.
- </para>
- </footnote>
- Specific language support for <classname>map</classname> and <classname>list</classname> objects are shown in the following table.
- </para>
- <table id="tabl-Programming_in_Apache_Qpid-Qpid_Maps_in_Message_Content">
- <title>Map and List Representation in Supported Languages</title>
- <tgroup cols="3">
- <thead>
- <row>
- <entry>Language</entry>
- <entry>map</entry>
- <entry>list</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Python</entry>
- <entry><classname>dict</classname></entry>
- <entry><classname>list</classname></entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry><classname>Variant::Map</classname></entry>
- <entry><classname>Variant::List</classname></entry>
- </row>
- <row>
- <entry>Java</entry>
- <entry><classname>MapMessage</classname></entry>
- <entry><classname>&nbsp;</classname></entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry><classname>Dictionary&#60;string, object&#62;</classname></entry>
- <entry><classname>Collection&#60;object&#62;</classname></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>
- In all languages, messages are encoded using AMQP&#39;s portable datatypes.
- </para>
-
- <tip>
- <para>Because of the differences in type systems among
- languages, the simplest way to provide portable messages is to
- rely on maps, lists, strings, 64 bit signed integers, and
- doubles for messages that need to be exchanged across languages
- and platforms.</para>
- </tip>
-
- <section id="section-Python-Maps">
- <title>Qpid Maps and Lists in Python</title>
-
- <para>In Python, Qpid supports the <classname>dict</classname> and <classname>list</classname> types directly in message content. The following code shows how to send these structures in a message:</para>
-
- <example>
- <title>Sending Qpid Maps and Lists in Python</title>
- <programlisting><![CDATA[
- from qpid.messaging import *
- # !!! SNIP !!!
-
- content = {'Id' : 987654321, 'name' : 'Widget', 'percent' : 0.99}
- content['colours'] = ['red', 'green', 'white']
- content['dimensions'] = {'length' : 10.2, 'width' : 5.1,'depth' : 2.0};
- content['parts'] = [ [1,2,5], [8,2,5] ]
- content['specs'] = {'colors' : content['colours'],
- 'dimensions' : content['dimensions'],
- 'parts' : content['parts'] }
- message = Message(content=content)
- sender.send(message)
- ]]> </programlisting>
- </example>
-
-
- <para>The following table shows the datatypes that can be sent in a Python map message,
- and the corresponding datatypes that will be received by clients in Java or C++.</para>
-
-
- <table id="table-Python-Maps" >
- <title>Python Datatypes in Maps</title>
- <tgroup cols="3">
- <thead>
- <row>
- <entry>Python Datatype</entry>
- <entry>&rarr; C++</entry>
- <entry>&rarr; Java</entry>
- </row>
- </thead>
- <tbody>
- <row><entry>bool</entry><entry>bool</entry><entry>boolean</entry></row>
- <row><entry>int</entry><entry>int64</entry><entry>long</entry></row>
- <row><entry>long</entry><entry>int64</entry><entry>long</entry></row>
- <row><entry>float</entry><entry>double</entry><entry>double</entry></row>
- <row><entry>unicode</entry><entry>string</entry><entry>java.lang.String</entry></row>
- <row><entry>uuid</entry><entry>qpid::types::Uuid</entry><entry>java.util.UUID</entry></row>
- <row><entry>dict</entry><entry>Variant::Map</entry><entry>java.util.Map</entry></row>
- <row><entry>list</entry><entry>Variant::List</entry><entry>java.util.List</entry></row>
- </tbody>
- </tgroup>
- </table>
-
- </section>
-
-
-
-
- <section id="section-cpp-Maps">
- <title>Qpid Maps and Lists in C++</title>
-
-
- <para>In C++, Qpid defines the the
- <classname>Variant::Map</classname> and
- <classname>Variant::List</classname> types, which can be
- encoded into message content. The following code shows how to
- send these structures in a message:</para>
-
- <example>
- <title>Sending Qpid Maps and Lists in C++</title>
- <programlisting><![CDATA[
- using namespace qpid::types;
-
- // !!! SNIP !!!
-
- Message message;
- Variant::Map content;
- content["id"] = 987654321;
- content["name"] = "Widget";
- content["percent"] = 0.99;
- Variant::List colours;
- colours.push_back(Variant("red"));
- colours.push_back(Variant("green"));
- colours.push_back(Variant("white"));
- content["colours"] = colours;
-
- Variant::Map dimensions;
- dimensions["length"] = 10.2;
- dimensions["width"] = 5.1;
- dimensions["depth"] = 2.0;
- content["dimensions"]= dimensions;
-
- Variant::List part1;
- part1.push_back(Variant(1));
- part1.push_back(Variant(2));
- part1.push_back(Variant(5));
-
- Variant::List part2;
- part2.push_back(Variant(8));
- part2.push_back(Variant(2));
- part2.push_back(Variant(5));
-
- Variant::List parts;
- parts.push_back(part1);
- parts.push_back(part2);
- content["parts"]= parts;
-
- Variant::Map specs;
- specs["colours"] = colours;
- specs["dimensions"] = dimensions;
- specs["parts"] = parts;
- content["specs"] = specs;
-
- encode(content, message);
- sender.send(message, true);
- ]]> </programlisting>
- </example>
-
- <para>The following table shows the datatypes that can be sent
- in a C++ map message, and the corresponding datatypes that
- will be received by clients in Java and Python.</para>
-
- <table id="table-cpp-Maps">
- <title>C++ Datatypes in Maps</title>
- <tgroup cols="3">
- <thead>
- <row>
- <entry>C++ Datatype</entry>
- <entry>&rarr; Python</entry>
- <entry>&rarr; Java</entry>
- </row>
- </thead>
- <tbody>
- <row><entry>bool</entry><entry>bool</entry><entry>boolean</entry></row>
- <row><entry>uint16</entry><entry>int | long</entry><entry>short</entry></row>
- <row><entry>uint32</entry><entry>int | long</entry><entry>int</entry></row>
- <row><entry>uint64</entry><entry>int | long</entry><entry>long</entry></row>
- <row><entry>int16</entry><entry>int | long</entry><entry>short</entry></row>
- <row><entry>int32</entry><entry>int | long</entry><entry>int</entry></row>
- <row><entry>int64</entry><entry>int | long</entry><entry>long</entry></row>
- <row><entry>float</entry><entry>float</entry><entry>float</entry></row>
- <row><entry>double</entry><entry>float</entry><entry>double</entry></row>
- <row><entry>string</entry><entry>unicode</entry><entry>java.lang.String</entry></row>
- <row><entry>qpid::types::Uuid</entry><entry>uuid</entry><entry>java.util.UUID</entry></row>
- <row><entry>Variant::Map</entry><entry>dict</entry><entry>java.util.Map</entry></row>
- <row><entry>Variant::List</entry><entry>list</entry><entry>java.util.List</entry></row>
- </tbody>
- </tgroup>
- </table>
- </section>
-
- <section id="section-dotnet-Maps">
- <title>Qpid Maps and Lists in .NET</title>
-
-
- <para>
- The .NET binding for the Qpid Messaging API binds .NET managed data types
- to C++ <classname>Variant</classname> data types. The following code shows how to
- send Map and List structures in a message:
- </para>
-
- <example>
- <?dbfo keep-together="auto" ?>
- <title>Sending Qpid Maps and Lists in .NET C#</title>
- <programlisting><![CDATA[
- using System;
- using Org.Apache.Qpid.Messaging;
-
- // !!! SNIP !!!
-
- Dictionary<string, object> content = new Dictionary<string, object>();
- Dictionary<string, object> subMap = new Dictionary<string, object>();
- Collection<object> colors = new Collection<object>();
-
- // add simple types
- content["id"] = 987654321;
- content["name"] = "Widget";
- content["percent"] = 0.99;
-
- // add nested amqp/map
- subMap["name"] = "Smith";
- subMap["number"] = 354;
- content["nestedMap"] = subMap;
-
- // add an amqp/list
- colors.Add("red");
- colors.Add("green");
- colors.Add("white");
- content["colorsList"] = colors;
-
- // add one of each supported amqp data type
- bool mybool = true;
- content["mybool"] = mybool;
-
- byte mybyte = 4;
- content["mybyte"] = mybyte;
-
- UInt16 myUInt16 = 5;
- content["myUInt16"] = myUInt16;
-
- UInt32 myUInt32 = 6;
- content["myUInt32"] = myUInt32;
-
- UInt64 myUInt64 = 7;
- content["myUInt64"] = myUInt64;
-
- char mychar = 'h';
- content["mychar"] = mychar;
-
- Int16 myInt16 = 9;
- content["myInt16"] = myInt16;
-
- Int32 myInt32 = 10;
- content["myInt32"] = myInt32;
-
- Int64 myInt64 = 11;
- content["myInt64"] = myInt64;
-
- Single mySingle = (Single)12.12;
- content["mySingle"] = mySingle;
-
- Double myDouble = 13.13;
- content["myDouble"] = myDouble;
-
- Guid myGuid = new Guid("000102030405060708090a0b0c0d0e0f");
- content["myGuid"] = myGuid;
-
- Message message = new Message(content);
- Send(message, true);
- ]]> </programlisting>
- </example>
-
- <para>
- The following table shows the mapping between datatypes in .NET and C++.
- </para>
-
- <table id="table-dotnet-Maps">
- <title>Datatype Mapping between C++ and .NET binding</title>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>C++ Datatype</entry>
- <entry>&rarr; .NET binding</entry>
- </row>
- </thead>
- <tbody>
- <row><entry>void</entry><entry>nullptr</entry></row>
- <row><entry>bool</entry><entry>bool</entry></row>
- <row><entry>uint8</entry><entry>byte</entry></row>
- <row><entry>uint16</entry><entry>UInt16</entry></row>
- <row><entry>uint32</entry><entry>UInt32</entry></row>
- <row><entry>uint64</entry><entry>UInt64</entry></row>
- <row><entry>uint8</entry><entry>char</entry></row>
- <row><entry>int16</entry><entry>Int16</entry></row>
- <row><entry>int32</entry><entry>Int32</entry></row>
- <row><entry>int64</entry><entry>Int64</entry></row>
- <row><entry>float</entry><entry>Single</entry></row>
- <row><entry>double</entry><entry>Double</entry></row>
- <row><entry>string</entry><entry>string
- <footnote id="callout-dotnet-string">
- <para>Strings are currently interpreted only with UTF-8 encoding.</para>
- </footnote></entry></row>
- <row><entry>qpid::types::Uuid</entry><entry>Guid</entry></row>
- <row><entry>Variant::Map</entry><entry><![CDATA[Dictionary<string, object>]]>
- <footnoteref linkend="callout-dotnet-string"/></entry></row>
- <row><entry>Variant::List</entry><entry><![CDATA[Collection<object>]]>
- <footnoteref linkend="callout-dotnet-string"/></entry></row>
- </tbody>
- </tgroup>
- </table>
-
-
- </section>
-
-
- </section>
-
- <section>
- <title>The Request / Response Pattern</title>
- <para>Request / Response applications use the reply-to property,
- described in <xref
- linkend="table-amqp0-10-message-properties"/>, to allow a server
- to respond to the client that sent a message. A server sets up a
- service queue, with a name known to clients. A client creates a
- private queue for the server's response, creates a message for a
- request, sets the request's reply-to property to the address of
- the client's response queue, and sends the request to the
- service queue. The server sends the response to the address
- specified in the request's reply-to property.
- </para>
- <example>
- <title>Request / Response Applications in C++</title>
-
- <para>This example shows the C++ code for a client and server
- that use the request / response pattern.</para>
-
- <para>The server creates a service queue and waits for a
- message to arrive. If it receives a message, it sends a
- message back to the sender.</para>
-
- <programlisting><![CDATA[Receiver receiver = session.createReceiver("service_queue; {create: always}");
-
- Message request = receiver.fetch();
- const Address&amp; address = request.getReplyTo(); // Get "reply-to" from request ...
- if (address) {
- Sender sender = session.createSender(address); // ... send response to "reply-to"
- Message response("pong!");
- sender.send(response);
- session.acknowledge();
- }
- ]]></programlisting>
-
- <para>The client creates a sender for the service queue, and
- also creates a response queue that is deleted when the
- client closes the receiver for the response queue. In the C++
- client, if the address starts with the character
- <literal>#</literal>, it is given a unique name.</para>
-
- <programlisting><![CDATA[
- Sender sender = session.createSender("service_queue");
-
- Address responseQueue("#response-queue; {create:always, delete:always}");
- Receiver receiver = session.createReceiver(responseQueue);
-
- Message request;
- request.setReplyTo(responseQueue);
- request.setContent("ping");
- sender.send(request);
- Message response = receiver.fetch();
- std::cout << request.getContent() << " -> " << response.getContent() << std::endl;
- ]]> </programlisting>
-
- <para>The client sends the string <literal>ping</literal> to
- the server. The server sends the response
- <literal>pong</literal> back to the same client, using the
- <varname>replyTo</varname> property.</para>
-
- </example>
- <!--
- <example>
- <title>Request / Response Applications in Python</title>
- <programlisting>### TODO</programlisting>
- </example>
- -->
- </section>
-
-
- <section>
- <title>Performance Tips</title>
-
- <itemizedlist>
- <listitem>
- <para>Consider prefetching messages for receivers (see
- <xref linkend="prefetch"/>). This helps eliminate roundtrips
- and increases throughput. Prefetch is disabled by default,
- and enabling it is the most effective means of improving
- throughput of received messages.</para>
- </listitem>
- <listitem>
- <para>Send messages asynchronously. Again, this helps
- eliminate roundtrips and increases throughput. The C++ and
- .NET clients send asynchronously by default, however the
- python client defaults to synchronous sends. </para>
- </listitem>
- <listitem>
- <para>Acknowledge messages in batches (see
- <xref linkend="acknowledgements"/>). Rather than
- acknowledging each message individually, consider issuing
- acknowledgements after n messages and/or after a particular
- duration has elapsed.</para>
- </listitem>
- <listitem>
- <para>Tune the sender capacity (see
- <xref linkend="replay"/>). If the capacity is too low the
- sender may block waiting for the broker to confirm receipt
- of messages, before it can free up more capacity.</para>
- </listitem>
- <listitem>
- <para>If you are setting a reply-to address on messages
- being sent by the c++ client, make sure the address type is
- set to either queue or topic as appropriate. This avoids the
- client having to determine which type of node is being
- refered to, which is required when hanling reply-to in AMQP
- 0-10. </para>
- </listitem>
- <listitem>
- <para>For latency sensitive applications, setting tcp-nodelay
- on qpidd and on client connections can help reduce the
- latency.</para>
- </listitem>
- </itemizedlist>
- </section>
-
- <section>
- <title>Cluster Failover</title>
-
- <para>The messaging broker can be run in clustering mode, which provides high reliability through replicating state between brokers in the cluster. If one broker in a cluster fails, clients can choose another broker in the cluster and continue their work. Each broker in the cluster also advertises the addresses of all known brokers
-
- <footnote><para>This is done via the amq.failover exchange in AMQP 0-10</para></footnote>
-
- . A client can use this information to dynamically keep the list of reconnection urls up to date.</para>
-
- <para>In C++, the <classname>FailoverUpdates</classname> class provides this functionality:</para>
-
- <example>
- <title>Tracking cluster membership</title>
-
- <para>In C++:</para>
-
- <programlisting><![CDATA[
- #include <qpid/messaging/FailoverUpdates.h>
- ...
- Connection connection("localhost:5672");
- connection.setOption("reconnect", true);
- try {
- connection.open();
- std::auto_ptr<FailoverUpdates> updates(new FailoverUpdates(connection));
- ]]>
- </programlisting>
-
- <para>In python:</para>
-
- <programlisting><![CDATA[
- import qpid.messaging.util
- ...
- connection = Connection("localhost:5672")
- connection.reconnect = True
- try:
- connection.open()
- auto_fetch_reconnect_urls(connection)
- ]]>
- </programlisting>
- <para>
- In .NET C#:
- </para>
-
- <programlisting>
- using Org.Apache.Qpid.Messaging;
- ...
- connection = new Connection(&#34;localhost:5672&#34;);
- connection.SetOption("reconnect", true);
- try {
- connection.Open();
- FailoverUpdates failover = new FailoverUpdates(connection);
-
- </programlisting>
-
-
- </example>
- </section>
-
-
-
- <section>
- <title>Logging</title>
-
- <para>To simplify debugging, Qpid provides a logging facility
- that prints out messaging events.</para>
-
- <section>
- <title>Logging in C++</title>
- <para>
- The Qpidd broker and C++ clients can both use environment variables to enable logging. Linux and Windows systems use the same named environment variables and values.
- </para>
- <para>Use QPID_LOG_ENABLE to set the level of logging you are interested in (trace, debug, info, notice, warning, error, or critical):
- </para>
-
- <screen>
- export QPID_LOG_ENABLE=&#34;warning+&#34;
- </screen>
- <para>
- The Qpidd broker and C++ clients use QPID_LOG_OUTPUT to determine where logging output should be sent. This is either a file name or the special values stderr, stdout, or syslog:
- </para>
-
- <screen>
- export QPID_LOG_TO_FILE=&#34;/tmp/myclient.out&#34;
- </screen>
-
- <para>
- From a Windows command prompt, use the following command format to set the environment variables:
- </para>
-
- <screen>
- set QPID_LOG_ENABLE=warning+
- set QPID_LOG_TO_FILE=D:\tmp\myclient.out
- </screen>
- </section>
-
- <section>
- <title>Logging in Python</title>
- <para>
- The Python client library supports logging using the standard Python logging module. The easiest way to do logging is to use the <command>basicConfig()</command>, which reports all warnings and errors:
- </para>
-
- <programlisting>from logging import basicConfig
- basicConfig()
- </programlisting>
- <para>
- Qpidd also provides a convenience method that makes it easy to specify the level of logging desired. For instance, the following code enables logging at the <command>DEBUG</command> level:
- </para>
-
- <programlisting>from qpid.log import enable, DEBUG
- enable("qpid.messaging.io", DEBUG)
- </programlisting>
- <para>
- For more information on Python logging, see <ulink url="http://docs.python.org/lib/node425.html">http://docs.python.org/lib/node425.html</ulink>. For more information on Qpid logging, use <command>$ pydoc qpid.log</command>.
- </para>
- </section>
- </section>
-
-
-
- <section id="section-amqp0-10-mapping">
- <title>The AMQP 0-10 mapping</title>
-
- <para>
- This section describes the AMQP 0-10 mapping for the Qpid
- Messaging API.
- </para>
- <para>
- The interaction with the broker triggered by creating a sender
- or receiver depends on what the specified address resolves
- to. Where the node type is not specified in the address, the
- client queries the broker to determine whether it refers to a
- queue or an exchange.
- </para>
- <para>
- When sending to a queue, the queue's name is set as the
- routing key and the message is transfered to the default (or
- nameless) exchange. When sending to an exchange, the message
- is transfered to that exchange and the routing key is set to
- the message subject if one is specified. A default subject may
- be specified in the target address. The subject may also be
- set on each message individually to override the default if
- required. In each case any specified subject is also added as
- a qpid.subject entry in the application-headers field of the
- message-properties.
- </para>
- <para>
- When receiving from a queue, any subject in the source address
- is currently ignored. The client sends a message-subscribe
- request for the queue in question. The accept-mode is
- determined by the reliability option in the link properties;
- for unreliable links the accept-mode is none, for reliable
- links it is explicit. The default for a queue is reliable. The
- acquire-mode is determined by the value of the mode option. If
- the mode is set to browse the acquire mode is not-acquired,
- otherwise it is set to pre-acquired. The exclusive and
- arguments fields in the message-subscribe command can be
- controlled using the x-subscribe map.
- </para>
- <para>
- When receiving from an exchange, the client creates a
- subscription queue and binds that to the exchange. The
- subscription queue's arguments can be specified using the
- x-declare map within the link properties. The reliability
- option determines most of the other parameters. If the
- reliability is set to unreliable then an auto-deleted,
- exclusive queue is used meaning that if the client or
- connection fails messages may be lost. For exactly-once the
- queue is not set to be auto-deleted. The durability of the
- subscription queue is determined by the durable option in the
- link properties. The binding process depends on the type of
- the exchange the source address resolves to.
- </para>
-
- <itemizedlist>
- <listitem>
- <para>
- For a topic exchange, if no subject is specified and no
- x-bindings are defined for the link, the subscription
- queue is bound using a wildcard matching any routing key
- (thus satisfying the expectation that any message sent to
- that address will be received from it). If a subject is
- specified in the source address however, it is used for
- the binding key (this means that the subject in the source
- address may be a binding pattern including wildcards).
- </para>
- </listitem>
- <listitem>
- <para>
- For a fanout exchange the binding key is irrelevant to
- matching. A receiver created from a source address that
- resolves to a fanout exchange receives all messages
- sent to that exchange regardless of any subject the source
- address may contain. An x-bindings element in the link
- properties should be used if there is any need to set the
- arguments to the bind.
- </para>
- </listitem>
- <listitem>
- <para>
- For a direct exchange, the subject is used as the binding
- key. If no subject is specified an empty string is used as
- the binding key.
- </para>
- </listitem>
- <listitem>
- <para>
- For a headers exchange, if no subject is specified the
- binding arguments simply contain an x-match entry and no
- other entries, causing all messages to match. If a subject
- is specified then the binding arguments contain an x-match
- entry set to all and an entry for qpid.subject whose value
- is the subject in the source address (this means the
- subject in the source address must match the message
- subject exactly). For more control the x-bindings element
- in the link properties must be used.
- </para>
- </listitem>
- <listitem>
- <para>
- For the XML exchange,<footnote><para>Note that the XML
- exchange is not a standard AMQP exchange type. It is a
- Qpid extension and is currently only supported by the C++
- broker.</para></footnote> if a subject is specified it is
- used as the binding key and an XQuery is defined that
- matches any message with that value for
- qpid.subject. Again this means that only messages whose
- subject exactly match that specified in the source address
- are received. If no subject is specified then the empty
- string is used as the binding key with an xquery that will
- match any message (this means that only messages with an
- empty string as the routing key will be received). For more
- control the x-bindings element in the link properties must
- be used. A source address that resolves to the XML
- exchange must contain either a subject or an x-bindings
- element in the link properties as there is no way at
- present to receive any message regardless of routing key.
- </para>
- </listitem>
- </itemizedlist>
-
- <para>
- If an x-bindings list is present in the link options a binding
- is created for each element within that list. Each element is
- a nested map that may contain values named queue, exchange,
- key or arguments. If the queue value is absent the queue name
- the address resolves to is implied. If the exchange value is
- absent the exchange name the address resolves to is implied.
- </para>
-
- <para>The following table shows how Qpid Messaging API message
- properties are mapped to AMQP 0-10 message properties and
- delivery properties. In this table <varname>msg</varname>
- refers to the Message class defined in the Qpid Messaging API,
- <varname>mp</varname> refers to an AMQP 0-10
- <varname>message-properties</varname> struct, and
- <varname>dp</varname> refers to an AMQP 0-10
- <varname>delivery-properties</varname> struct.</para>
-
- <table id="table-amqp0-10-message-properties" pgwide="1">
- <title>Mapping to AMQP 0-10 Message Properties</title>
- <tgroup cols="3">
- <thead>
- <colspec colnum="1" colname="Python API" colwidth="3*"/>
- <colspec colnum="2" colname="C++ API" colwidth="3*"/>
- <colspec colnum="3" colname="AMPQ 0-10 Property" colwidth="6*"/>
- <row>
- <entry>Python API</entry>
- <entry>C++ API
- <footnote>
- <para>
- The .NET Binding for C++ Messaging provides all the
- message and delivery properties described in the C++ API.
- See <xref linkend="table-Dotnet-Binding-Message" /> .
- </para>
- </footnote>
- </entry>
- <entry>AMQP 0-10 Property<footnote><para>In these entries, <literal>mp</literal> refers to an AMQP message property, and <literal>dp</literal> refers to an AMQP delivery property.</para></footnote></entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>msg.id</entry><entry>msg.{get,set}MessageId()</entry><entry>mp.message_id</entry>
- </row>
- <row>
- <entry>msg.subject</entry><entry>msg.{get,set}Subject()</entry><entry>mp.application_headers["qpid.subject"]</entry>
- </row>
- <row>
- <entry>msg.user_id</entry><entry>msg.{get,set}UserId()</entry><entry>mp.user_id</entry>
- </row>
- <row>
- <entry>msg.reply_to</entry><entry>msg.{get,set}ReplyTo()</entry><entry>mp.reply_to<footnote><para>The reply_to is converted from the protocol representation into an address.</para></footnote></entry>
- </row>
- <row>
- <entry>msg.correlation_id</entry><entry>msg.{get,set}CorrelationId()</entry><entry>mp.correlation_id</entry>
- </row>
- <row>
- <entry>msg.durable</entry><entry>msg.{get,set}Durable()</entry><entry>dp.delivery_mode == delivery_mode.persistent<footnote><para>Note that msg.durable is a boolean, not an enum.</para></footnote></entry>
- </row>
- <row>
- <entry>msg.priority</entry><entry>msg.{get,set}Priority()</entry><entry>dp.priority</entry>
- </row>
- <row>
- <entry>msg.ttl</entry><entry>msg.{get,set}Ttl()</entry><entry>dp.ttl</entry>
- </row>
- <row>
- <entry>msg.redelivered</entry><entry>msg.{get,set}Redelivered()</entry><entry>dp.redelivered</entry>
- </row>
- <row><entry>msg.properties</entry><entry>msg.getProperties()/msg.setProperty()</entry><entry>mp.application_headers</entry>
- </row>
- <row>
- <entry>msg.content_type</entry><entry>msg.{get,set}ContentType()</entry><entry>mp.content_type</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <section role="h3" id="section-amqp0-10-message-props">
- <title>0-10 Message Property Keys</title>
- <para>
- The QPID Messaging API also recognises special message property keys and
- automatically provides a mapping to their corresponding AMQP 0-10 definitions.
- </para>
- <itemizedlist>
- <listitem>
- <para>
- When sending a message, if the properties contain an entry for
- <literal>x-amqp-0-10.app-id</literal>, its value will be used to set the
- <literal>message-properties.app-id</literal> property in the outgoing
- message. Likewise, if an incoming message has
- <literal>message-properties.app-id</literal> set, its value can be accessed
- via the <literal>x-amqp-0-10.app-id</literal> message property key.
- </para>
- </listitem>
- <listitem>
- <para>
- When sending a message, if the properties contain an entry for
- <literal>x-amqp-0-10.content-encoding</literal>, its value will be used to
- set the <literal>message-properties.content-encoding</literal> property in
- the outgoing message. Likewise, if an incoming message has
- <literal>message-properties.content-encoding</literal> set, its value can be
- accessed via the <literal>x-amqp-0-10.content-encoding</literal> message
- property key.
- </para>
- </listitem>
- <listitem>
- <para>
- The routing key (<literal>delivery-properties.routing-key</literal>) in an
- incoming messages can be accessed via the
- <literal>x-amqp-0-10.routing-key</literal> message property.
- </para>
- </listitem>
- <listitem>
- <para>
- If the timestamp delivery property is set in an incoming message
- (<literal>delivery-properties.timestamp</literal>), the timestamp value will
- be made available via the <literal>x-amqp-0-10.timestamp</literal> message
- property.
- <footnote>
- <para>
- This special property is currently not supported by the Qpid JMS client.
- </para>
- </footnote>
- </para>
- </listitem>
- </itemizedlist>
- <example>
- <title>Accessing the AMQP 0-10 Message Timestamp in Python</title>
- <para>
- The following code fragment checks for and extracts the message timestamp from
- a received message.
- </para>
- <programlisting lang="python">
- try:
- msg = receiver.fetch(timeout=1)
- if "x-amqp-0-10.timestamp" in msg.properties:
- print("Timestamp=%s" % str(msg.properties["x-amqp-0-10.timestamp"]))
- except Empty:
- pass
- </programlisting>
- </example>
- <example>
- <title>Accessing the AMQP 0-10 Message Timestamp in C++</title>
- <para>
- The same example, except in C++.
- </para>
- <programlisting lang="c++">
- messaging::Message msg;
- if (receiver.fetch(msg, messaging::Duration::SECOND*1)) {
- if (msg.getProperties().find("x-amqp-0-10.timestamp") != msg.getProperties().end()) {
- <![CDATA[std::cout << "Timestamp=" << msg.getProperties()["x-amqp-0-10.timestamp"].asString() << std::endl;]]>
- }
- }
- </programlisting>
- </example>
- </section>
- </section>
-
- <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Message-Groups-Guide.xml"/>
-
- </chapter>
-
-
- <chapter id="QpidJMS">
- <title>Using the Qpid JMS client</title>
- <section>
- <title>A Simple Messaging Program in Java JMS</title>
-
- <para>The following program shows how to send and receive a
- message using the Qpid JMS client. JMS programs typically use
- JNDI to obtain connection factory and destination objects which
- the application needs. In this way the configuration is kept
- separate from the application code itself.</para>
-
- <para>In this example, we create a JNDI context using a
- properties file, use the context to lookup a connection factory,
- create and start a connection, create a session, and lookup a
- destination from the JNDI context. Then we create a producer and
- a consumer, send a message with the producer and receive it with
- the consumer. This code should be straightforward for anyone
- familiar with Java JMS.</para>
-
- <example>
- <title>"Hello world!" in Java</title>
- <programlisting lang="java">
- package org.apache.qpid.example.jmsexample.hello;
-
- import javax.jms.*;
- import javax.naming.Context;
- import javax.naming.InitialContext;
- import java.util.Properties;
-
- public class Hello {
-
- public Hello() {
- }
-
- public static void main(String[] args) {
- Hello producer = new Hello();
- producer.runTest();
- }
-
- private void runTest() {
- try {
- Properties properties = new Properties();
- properties.load(this.getClass().getResourceAsStream("hello.properties")); <co id="hello-java-properties" linkends="callout-java-properties"/>
- Context context = new InitialContext(properties); <co id="hello-java-context" linkends="callout-java-context"/>
-
- ConnectionFactory connectionFactory
- = (ConnectionFactory) context.lookup("qpidConnectionfactory"); <co id="hello-java-connection-factory" linkends="callout-java-connection-factory"/>
- Connection connection = connectionFactory.createConnection(); <co id="hello-java-connection" linkends="callout-java-connection"/>
- connection.start(); <co id="hello-java-start" linkends="callout-java-start"/>
-
- Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);<co id="hello-java-session" linkends="callout-java-session"/>
- Destination destination = (Destination) context.lookup("topicExchange"); <co id="hello-java-destination" linkends="callout-java-destination"/>
-
- MessageProducer messageProducer = session.createProducer(destination); <co id="hello-java-producer" linkends="callout-java-producer"/>
- MessageConsumer messageConsumer = session.createConsumer(destination); <co id="hello-java-consumer" linkends="callout-java-consumer"/>
-
- TextMessage message = session.createTextMessage("Hello world!");
- messageProducer.send(message);
-
- message = (TextMessage)messageConsumer.receive(); <co id="hello-java-receive" linkends="callout-java-receive"/>
- System.out.println(message.getText());
-
- connection.close(); <co id="hello-java-close" linkends="callout-java-close"/>
- context.close(); <co id="hello-java-jndi-close" linkends="callout-java-jndi-close"/>
- }
- catch (Exception exp) {
- exp.printStackTrace();
- }
- }
- }
- </programlisting>
- </example>
-
- <calloutlist>
- <callout id="callout-java-properties" arearefs="hello-java-properties">
- <para>Loads the JNDI properties file, which specifies connection properties, queues, topics, and addressing options. See <xref linkend="QpidJNDI"/> for details.</para>
- </callout>
- <callout id="callout-java-context" arearefs="hello-java-context">
- <para>Creates the JNDI initial context.</para>
- </callout>
- <callout id="callout-java-connection-factory" arearefs="hello-java-connection-factory">
- <para>Creates a JMS connection factory for Qpid.</para>
- </callout>
- <callout id="callout-java-connection" arearefs="hello-java-connection">
- <para>Creates a JMS connection.</para>
- </callout>
- <callout id="callout-java-start" arearefs="hello-java-start">
- <para>Activates the connection.</para>
- </callout>
- <callout id="callout-java-session" arearefs="hello-java-session">
- <para>Creates a session. This session is not transactional (transactions='false'), and messages are automatically acknowledged.</para>
- </callout>
- <callout id="callout-java-destination" arearefs="hello-java-destination">
- <para>Creates a destination for the topic exchange, so senders and receivers can use it.</para>
- </callout>
- <callout id="callout-java-producer" arearefs="hello-java-producer">
- <para>Creates a producer that sends messages to the topic exchange.</para>
- </callout>
- <callout id="callout-java-consumer" arearefs="hello-java-consumer">
- <para>Creates a consumer that reads messages from the topic exchange.</para>
- </callout>
- <callout id="callout-java-receive" arearefs="hello-java-receive">
- <para>Reads the next available message.</para>
- </callout>
- <callout id="callout-java-close" arearefs="hello-java-close">
- <para>Closes the connection, all sessions managed by the connection, and all senders and receivers managed by each session.</para>
- </callout>
- <callout id="callout-java-jndi-close" arearefs="hello-java-jndi-close">
- <para>Closes the JNDI context.</para>
- </callout>
- </calloutlist>
-
- <para>The contents of the hello.properties file are shown below.</para>
-
- <example>
- <title>JNDI Properties File for "Hello world!" example</title>
- <programlisting>
- java.naming.factory.initial
- = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
-
- # connectionfactory.[jndiname] = [ConnectionURL]
- connectionfactory.qpidConnectionfactory
- = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672' <co id="hello-properties-connectionfactory" linkends="callout-hello-properties-connectionfactory"/>
- # destination.[jndiname] = [address_string]
- destination.topicExchange = amq.topic <co id="hello-properties-destination" linkends="callout-hello-properties-destination"/>
- </programlisting>
- </example>
-
- <calloutlist>
- <callout id="callout-hello-properties-connectionfactory" arearefs="hello-properties-connectionfactory">
- <para>Defines a connection factory from which connections
- can be created. The syntax of a ConnectionURL is given in
- <xref linkend="QpidJNDI"/>.</para>
- </callout>
- <callout id="callout-hello-properties-destination" arearefs="hello-properties-destination">
- <para>Defines a destination for which MessageProducers
- and/or MessageConsumers can be created to send and receive
- messages. The value for the destination in the properties
- file is an address string as described in
- <xref linkend="section-addresses"/>. In the JMS
- implementation MessageProducers are analogous to senders in
- the Qpid Message API, and MessageConsumers are analogous to
- receivers.</para>
- </callout>
- </calloutlist>
-
- </section>
-
- <section id="QpidJNDI">
- <title>Apache Qpid JNDI Properties for AMQP Messaging</title>
-
-
- <para>
- Apache Qpid defines JNDI properties that can be used to specify JMS Connections and Destinations. Here is a typical JNDI properties file:
- </para>
-
- <example>
- <title>JNDI Properties File</title>
- <programlisting><![CDATA[
- java.naming.factory.initial
- = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
-
- # connectionfactory.[jndiname] = [ConnectionURL]
- connectionfactory.qpidConnectionfactory
- = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
- # destination.[jndiname] = [address_string]
- destination.topicExchange = amq.topic
- ]]></programlisting>
- </example>
-
- <para>The following sections describe the JNDI properties that Qpid uses.</para>
-
-
- <section>
- <title>JNDI Properties for Apache Qpid</title>
- <para>
- Apache Qpid supports the properties shown in the following table:
- </para>
- <table>
- <title>JNDI Properties supported by Apache Qpid</title>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>
- Property
- </entry>
- <entry>
- Purpose
- </entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- connectionfactory.&lt;jndiname&gt;
- </entry>
- <entry>
- <para>
- The Connection URL that the connection factory uses to perform connections.
- </para>
- </entry>
- </row>
- <row>
- <entry>
- queue.&lt;jndiname&gt;
- </entry>
- <entry>
- <para>
- A JMS queue, which is implemented as an amq.direct exchange in Apache Qpid.
- </para>
- </entry>
- </row>
- <row>
- <entry>
- topic.&lt;jndiname&gt;
- </entry>
- <entry>
- <para>
- A JMS topic, which is implemented as an amq.topic exchange in Apache Qpid.
- </para>
- </entry>
- </row>
- <row>
- <entry>
- destination.&lt;jndiname&gt;
- </entry>
- <entry>
- <para>
- Can be used for defining all amq destinations,
- queues, topics and header matching, using an
- address string.
-
- <footnote><para>Binding URLs, which were used in
- earlier versions of the Qpid Java JMS client, can
- still be used instead of address
- strings.</para></footnote>
- </para>
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
-
- <section id="section-jms-connection-url">
- <title>Connection URLs</title>
- <para>
- In JNDI properties, a Connection URL specifies properties for a connection. The format for a Connection URL is:
- </para>
-
- <programlisting>amqp://[&lt;user&gt;:&lt;pass&gt;@][&lt;clientid&gt;]&lt;virtualhost&gt;[?&lt;option&gt;=&#39;&lt;value&gt;&#39;[&amp;&lt;option&gt;=&#39;&lt;value&gt;&#39;]]
- </programlisting>
- <para>
- For instance, the following Connection URL specifies a user name, a password, a client ID, a virtual host ("test"), a broker list with a single broker, and a TCP host with the host name <quote>localhost</quote> using port 5672:
- </para>
-
- <programlisting>amqp://username:password@clientid/test?brokerlist=&#39;tcp://localhost:5672&#39;
- </programlisting>
- <para>
- Apache Qpid supports the following properties in Connection URLs:
- </para>
- <table pgwide="1">
- <title>Connection URL Properties</title>
- <tgroup cols="3">
- <thead>
- <row>
- <entry>
- Option
- </entry>
- <entry>
- Type
- </entry>
- <entry>
- Description
- </entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- brokerlist
- </entry>
- <entry>
- see below
- </entry>
- <entry>
- List of one or more broker addresses.
- </entry>
- </row>
- <row>
- <entry>
- maxprefetch
- </entry>
- <entry>
- integer
- </entry>
- <entry>
- <para>
- The maximum number of pre-fetched messages per consumer. If not specified, default value of 500 is used.
- </para>
- <para>
- Note: You can also set the default per-consumer prefetch value on a client-wide basis by configuring the client using <link linkend="client-jvm-properties">Java system properties.</link>
- </para>
- </entry>
- </row>
- <row>
- <entry>
- sync_publish
- </entry>
- <entry>
- {'persistent' | 'all'}
- </entry>
- <entry>
- 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.
- </entry>
- </row>
- <row>
- <entry>
- sync_ack
- </entry>
- <entry>
- Boolean
- </entry>
- <entry>
- A sync command is sent after every acknowledgement to guarantee that it has been received.
- </entry>
- </row>
- <row>
- <entry>
- use_legacy_map_msg_format
- </entry>
- <entry>
- Boolean
- </entry>
- <entry>
- 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.
- </entry>
- </row>
- <row>
- <entry>
- failover
- </entry>
- <entry>
- {'singlebroker' | 'roundrobin' | 'failover_exchange' | 'nofailover' | '&lt;class&gt;'}
- </entry>
- <entry>
- <para>
- This option controls failover behaviour. The method <literal>singlebroker</literal> uses only the first broker in the list,
- <literal>roundrobin</literal> will try each broker given in the broker list until a connection is established,
- <literal>failover_exchange</literal> connects to the initial broker given in the broker URL and will receive membership updates
- via the failover exchange. <literal>nofailover</literal> disables all retry and failover logic. Any other value is interpreted as a
- classname which must implement the <literal>org.apache.qpid.jms.failover.FailoverMethod</literal> interface.
- </para>
- <para>
- The broker list options <literal>retries</literal> and <literal>connectdelay</literal> (described below) determine the number of times a
- connection to a broker will be retried and the the length of time to wait between successive connection attempts before moving on to
- the next broker in the list. The failover option <literal>cyclecount</literal> controls the number of times to loop through the list of
- available brokers before finally giving up.
- </para>
- <para>
- Defaults to <literal>roundrobin</literal> if the brokerlist contains multiple brokers, or <literal>singlebroker</literal> otherwise.
- </para>
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>
- Broker lists are specified using a URL in this format:
- </para>
-
- <programlisting>brokerlist=&lt;transport&gt;://&lt;host&gt;[:&lt;port&gt;](?&lt;param>='&lt;value>')(&amp;&lt;param>='&lt;value>')*</programlisting>
- <para>
- For instance, this is a typical broker list:
- </para>
-
- <programlisting>brokerlist=&#39;tcp://localhost:5672&#39;
- </programlisting>
-
- <para>
- A broker list can contain more than one broker address; if so, the connection is made to the first broker in the list that is available. In general, it is better to use the failover exchange when using multiple brokers, since it allows applications to fail over if a broker goes down.
- </para>
-
- <example>
- <title>Broker Lists</title>
- <para>A broker list can specify properties to be used when connecting to the broker, such as security options. This broker list specifies options for a Kerberos connection using GSSAPI:</para>
- <programlisting><![CDATA[
- amqp://guest:guest@test/test?sync_ack='true'
- &brokerlist='tcp://ip1:5672?sasl_mechs='GSSAPI''
- ]]></programlisting>
-
- <para>This broker list specifies SSL options:</para>
-
- <programlisting><![CDATA[
- amqp://guest:guest@test/test?sync_ack='true'
- &brokerlist='tcp://ip1:5672?ssl='true'&ssl_cert_alias='cert1''
- ]]></programlisting>
-
- <para>
- This broker list specifies two brokers using the connectdelay and retries broker options. It also illustrates the failover connection URL
- property.
- </para>
-
- <programlisting><![CDATA[
-
- amqp://guest:guest@/test?failover='roundrobin?cyclecount='2''
- &brokerlist='tcp://ip1:5672?retries='5'&connectdelay='2000';tcp://ip2:5672?retries='5'&connectdelay='2000''
- ]]></programlisting>
- </example>
-
- <para>The following broker list options are supported.</para>
-
- <table pgwide="1">
- <title>Broker List Options</title>
- <tgroup cols="3">
- <thead>
- <row>
- <entry>
- Option
- </entry>
- <entry>
- Type
- </entry>
- <entry>
- Description
- </entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- heartbeat
- </entry>
- <entry>
- integer
- </entry>
- <entry>
- frequency of heartbeat messages (in seconds)
- </entry>
- </row>
- <row>
- <entry>
- sasl_mechs
- </entry>
- <entry>
- --
- </entry>
- <entry>
- For secure applications, we suggest CRAM-MD5,
- DIGEST-MD5, or GSSAPI. The ANONYMOUS method is not
- secure. The PLAIN method is secure only when used
- together with SSL. For Kerberos, sasl_mechs must be
- set to GSSAPI, sasl_protocol must be set to the
- principal for the qpidd broker, e.g. qpidd/, and
- sasl_server must be set to the host for the SASL
- server, e.g. sasl.com. SASL External is supported
- using SSL certification, e.g.
- <literal>ssl='true'&amp;sasl_mechs='EXTERNAL'</literal>
- </entry>
- </row>
- <row>
- <entry>
- sasl_encryption
- </entry>
- <entry>
- Boolean
- </entry>
- <entry>
- If <literal>sasl_encryption='true'</literal>, 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.
- </entry>
- </row>
- <row>
- <entry>
- sasl_protocol
- </entry>
- <entry>
- --
- </entry>
- <entry>
- Used only for
- Kerberos. <literal>sasl_protocol</literal> must be
- set to the principal for the qpidd broker,
- e.g. <literal>qpidd/</literal>
- </entry>
- </row>
- <row>
- <entry>
- sasl_server
- </entry>
- <entry>
- --
- </entry>
- <entry>
- For Kerberos, sasl_mechs must be set to GSSAPI,
- sasl_server must be set to the host for the SASL
- server, e.g. <literal>sasl.com</literal>.
- </entry>
- </row>
- <row>
- <entry>
- trust_store
- </entry>
- <entry>
- --
- </entry>
- <entry>
- path to trust store
- </entry>
- </row>
- <row>
- <entry>
- trust_store_password
- </entry>
- <entry>
- </entry>
- <entry>
- Trust store password
- </entry>
- </row>
- <row>
- <entry>
- key_store
- </entry>
- <entry>
- </entry>
- <entry>
- path to key store
- </entry>
- </row>
- <row>
- <entry>
- key_store_password
- </entry>
- <entry>
- --
- </entry>
- <entry>
- key store password
- </entry>
- </row>
- <row>
- <entry>
- ssl
- </entry>
- <entry>
- Boolean
- </entry>
- <entry>
- If <literal>ssl='true'</literal>, the JMS client will encrypt the connection using SSL.
- </entry>
- </row>
- <row>
- <entry>
- ssl_verify_hostname
- </entry>
- <entry>
- Boolean
- </entry>
- <entry>
- When using SSL you can enable hostname verification
- by using <literal>ssl_verify_hostname='true'</literal> in the broker
- URL.
- </entry>
- </row>
- <row>
- <entry>
- ssl_cert_alias
- </entry>
- <entry>
-
- </entry>
- <entry>
- If multiple certificates are present in the keystore, the alias will be used to extract the correct certificate.
- </entry>
- </row>
- <row>
- <entry>
- retries
- </entry>
- <entry>
- integer
- </entry>
- <entry>
- The number of times to retry connection to each broker in the broker list. Defaults to 1.
- </entry>
- </row>
- <row>
- <entry>
- connectdelay
- </entry>
- <entry>
- integer
- </entry>
- <entry>
- Length of time (in milliseconds) to wait before attempting to reconnect. Defaults to 0.
- </entry>
- </row>
- <row>
- <entry>
- connecttimeout
- </entry>
- <entry>
- integer
- </entry>
- <entry>
- Length of time (in milliseconds) to wait for the socket connection to succeed. A value of 0 represents an infinite timeout, i.e. the connection attempt will block until established or an error occurs. Defaults to 30000.
- </entry>
- </row>
- <row>
- <entry>
- tcp_nodelay
- </entry>
- <entry>
- Boolean
- </entry>
- <entry>
- If <literal>tcp_nodelay='true'</literal>, TCP packet
- batching is disabled. Defaults to true since Qpid 0.14.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- </section>
-
- <section>
- <title>Java JMS Message Properties</title>
-
- <para>The following table shows how Qpid Messaging API message
- properties are mapped to AMQP 0-10 message properties and
- delivery properties. In this table <varname>msg</varname>
- refers to the Message class defined in the Qpid Messaging API,
- <varname>mp</varname> refers to an AMQP 0-10
- <varname>message-properties</varname> struct, and
- <varname>dp</varname> refers to an AMQP 0-10
- <varname>delivery-properties</varname> struct.</para>
-
- <table >
- <title>Java JMS Mapping to AMQP 0-10 Message Properties</title>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>Java JMS Message Property</entry>
- <entry>AMQP 0-10 Property<footnote><para>In these entries, <literal>mp</literal> refers to an AMQP message property, and <literal>dp</literal> refers to an AMQP delivery property.</para></footnote></entry>
-
- </row>
- </thead>
- <tbody>
- <row>
- <entry>JMSMessageID</entry><entry>mp.message_id</entry>
- </row>
- <row>
- <entry>qpid.subject<footnote><para>This is a custom JMS property, set automatically by the Java JMS client implementation.</para></footnote></entry><entry>mp.application_headers["qpid.subject"]</entry>
- </row>
- <row>
- <entry>JMSXUserID</entry><entry>mp.user_id</entry>
- </row>
- <row>
- <entry>JMSReplyTo</entry><entry>mp.reply_to<footnote><para>The reply_to is converted from the protocol representation into an address.</para></footnote></entry>
- </row>
- <row>
- <entry>JMSCorrelationID</entry><entry>mp.correlation_id</entry>
- </row>
- <row>
- <entry>JMSDeliveryMode</entry><entry>dp.delivery_mode</entry>
- </row>
- <row>
- <entry>JMSPriority</entry><entry>dp.priority</entry>
- </row>
- <row>
- <entry>JMSExpiration</entry><entry>dp.ttl<footnote><para>JMSExpiration = dp.ttl + currentTime</para></footnote></entry>
- </row>
- <row>
- <entry>JMSRedelivered</entry><entry>dp.redelivered</entry>
- </row>
- <row>
- <entry>JMS Properties</entry><entry>mp.application_headers</entry>
- </row>
- <row>
- <entry>JMSType</entry><entry>mp.content_type</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- </section>
-
- <section id="section-JMS-MapMessage">
- <title>JMS MapMessage Types</title>
-
- <para>Qpid supports the Java JMS <classname>MapMessage</classname> interface, which provides support for maps in messages. The following code shows how to send a <classname>MapMessage</classname> in Java JMS.</para>
-
- <example>
- <title>Sending a Java JMS MapMessage</title>
- <programlisting><![CDATA[
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import javax.jms.Connection;
- import javax.jms.Destination;
- import javax.jms.MapMessage;
- import javax.jms.MessageProducer;
- import javax.jms.Session;
-
- import java.util.Arrays;
-
- // !!! SNIP !!!
-
- MessageProducer producer = session.createProducer(queue);
-
- MapMessage m = session.createMapMessage();
- m.setIntProperty("Id", 987654321);
- m.setStringProperty("name", "Widget");
- m.setDoubleProperty("price", 0.99);
-
- List<String> colors = new ArrayList<String>();
- colors.add("red");
- colors.add("green");
- colors.add("white");
- m.setObject("colours", colors);
-
- Map<String,Double> dimensions = new HashMap<String,Double>();
- dimensions.put("length",10.2);
- dimensions.put("width",5.1);
- dimensions.put("depth",2.0);
- m.setObject("dimensions",dimensions);
-
- List<List<Integer>> parts = new ArrayList<List<Integer>>();
- parts.add(Arrays.asList(new Integer[] {1,2,5}));
- parts.add(Arrays.asList(new Integer[] {8,2,5}));
- m.setObject("parts", parts);
-
- Map<String,Object> specs = new HashMap<String,Object>();
- specs.put("colours", colors);
- specs.put("dimensions", dimensions);
- specs.put("parts", parts);
- m.setObject("specs",specs);
-
- producer.send(m);
- ]]></programlisting>
- </example>
-
- <para>The following table shows the datatypes that can be sent in a <classname>MapMessage</classname>, and the corresponding datatypes that will be received by clients in Python or C++.</para>
-
- <table id="table-Java-Maps">
- <title>Java Datatypes in Maps</title>
- <tgroup cols="3">
- <thead>
- <row>
- <entry>Java Datatype</entry>
- <entry>&rarr; Python</entry>
- <entry>&rarr; C++</entry>
- </row>
- </thead>
- <tbody>
- <row><entry>boolean</entry><entry>bool</entry><entry>bool</entry></row>
- <row><entry>short</entry><entry>int | long</entry><entry>int16</entry></row>
- <row><entry>int</entry><entry>int | long</entry><entry>int32</entry></row>
- <row><entry>long</entry><entry>int | long</entry><entry>int64</entry></row>
- <row><entry>float</entry><entry>float</entry><entry>float</entry></row>
- <row><entry>double</entry><entry>float</entry><entry>double</entry></row>
- <row><entry>java.lang.String</entry><entry>unicode</entry><entry>std::string</entry></row>
- <row><entry>java.util.UUID</entry><entry>uuid</entry><entry>qpid::types::Uuid</entry></row>
- <row><entry>java.util.Map<footnote><para>In Qpid, maps can nest. This goes beyond the functionality required by the JMS specification.</para></footnote></entry><entry>dict</entry><entry>Variant::Map</entry></row>
- <row><entry>java.util.List</entry><entry>list</entry><entry>Variant::List</entry></row>
- </tbody>
- </tgroup>
- </table>
-
- </section>
-
- <section id="section-JMS-Logging">
- <title>JMS Client Logging</title>
- <para>The JMS Client logging is handled using the Simple Logging Facade for Java (<ulink url="http://www.slf4j.org/">SLF4J</ulink>). As the name implies, slf4j is a facade that delegates to other logging systems like log4j or JDK 1.4 logging. For more information on how to configure slf4j for specific logging systems, please consult the slf4j documentation.</para>
-
- <para>When using the log4j binding, please set the log level for org.apache.qpid explicitly. Otherwise log4j will default to DEBUG which will degrade performance considerably due to excessive logging. The recommended logging level for production is <literal>WARN</literal>.</para>
-
- <para>The following example shows the logging properties used to configure client logging for slf4j using the log4j binding. These properties can be placed in a log4j.properties file and placed in the <varname>CLASSPATH</varname>, or they can be set explicitly using the <literal>-Dlog4j.configuration</literal> property.</para>
-
- <example>
- <title>log4j Logging Properties</title>
-
- <programlisting><![CDATA[
- log4j.logger.org.apache.qpid=WARN, console
- log4j.additivity.org.apache.qpid=false
-
- log4j.appender.console=org.apache.log4j.ConsoleAppender
- log4j.appender.console.Threshold=all
- log4j.appender.console.layout=org.apache.log4j.PatternLayout
- log4j.appender.console.layout.ConversionPattern=%t %d %p [%c{4}] %m%n
- ]]></programlisting>
- </example>
-
- </section>
-
- <section>
- <title>Configuring the JMS Client</title>
-
- <para>The Qpid JMS Client allows several configuration options to customize it's behaviour at different levels of granualarity.</para>
-
- <itemizedlist>
- <listitem>
- <para>
- JVM level using JVM arguments : Configuration that affects all connections, sessions, consumers and producers created within that JVM.
- </para>
- <para>Ex. <varname>-Dmax_prefetch=1000</varname> property specifies the message credits to use.</para>
- </listitem>
-
- <listitem>
- <para>
- Connection level using Connection/Broker properties : Affects the respective connection and sessions, consumers and produces created by that connection.
- </para>
- <para>Ex. <varname>amqp://guest:guest@test/test?max_prefetch='1000'
- &amp;brokerlist='tcp://localhost:5672'
- </varname> property specifies the message credits to use. This overrides any value specified via the JVM argument <varname>max_prefetch</varname>.</para>
- <para>Please refer to the <xref linkend="section-jms-connection-url"/> section for a complete list of all properties and how to use them.</para>
- </listitem>
-
- <listitem>
- <para>
- Destination level using Addressing options : Affects the producer(s) and consumer(s) created using the respective destination.
- </para>
- <para>Ex. <varname>my-queue; {create: always, link:{capacity: 10}}</varname>, where <varname>capacity</varname> option specifies the message credits to use. This overrides any connection level configuration.</para>
- <para>Please refer to the <xref linkend="section-addresses"/> section for a complete understanding of addressing and it's various options.</para>
- </listitem>
- </itemizedlist>
-
- <para>Some of these config options are available at all three levels (Ex. <varname>max_prefetch</varname>), while others are available only at JVM or connection level.</para>
-
- <section id="client-jvm-properties">
- <title>Qpid JVM Arguments</title>
-
- <table >
- <title>Config Options For Connection Behaviour</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>qpid.amqp.version</entry>
- <entry>string</entry>
- <entry>0-10</entry>
- <entry><para>Sets the AMQP version to be used - currently supports one of {0-8,0-9,0-91,0-10}.</para><para>The client will begin negotiation at the specified version and only negotiate downwards if the Broker does not support the specified version.</para></entry>
- </row>
- <row>
- <entry>qpid.heartbeat</entry>
- <entry>int</entry>
- <entry>120 (secs)</entry>
- <entry>The heartbeat interval in seconds. Two consective misssed heartbeats will result in the connection timing out.<para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
-
- <row>
- <entry>ignore_setclientID</entry>
- <entry>boolean</entry>
- <entry>false</entry>
- <entry>If a client ID is specified in the connection URL it's used or else an ID is generated. If an ID is specified after it's been set Qpid will throw an exception. <para>Setting this property to 'true' will disable that check and allow you to set a client ID of your choice later on.</para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
-
- <table >
- <title>Config Options For Session Behaviour</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>qpid.session.command_limit</entry>
- <entry>int</entry>
- <entry>65536</entry>
- <entry>Limits the # of unacked commands</entry>
- </row>
-
- <row>
- <entry>qpid.session.byte_limit</entry>
- <entry>int</entry>
- <entry>1048576</entry>
- <entry>Limits the # of unacked commands in terms of bytes</entry>
- </row>
-
- <row>
- <entry>qpid.use_legacy_map_message</entry>
- <entry>boolean</entry>
- <entry>false</entry>
- <entry><para>If set will use the old map message encoding. By default the Map messages are encoded using the 0-10 map encoding.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
-
- <row>
- <entry>qpid.jms.daemon.dispatcher</entry>
- <entry>boolean</entry>
- <entry>false</entry>
- <entry><para>Controls whether the Session dispatcher thread is a daemon thread or not. If this system property is set to true then the Session dispatcher threads will be created as daemon threads. This setting is introduced in version 0.16.</para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table >
- <title>Config Options For Consumer Behaviour</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>max_prefetch</entry>
- <entry>int</entry>
- <entry>500</entry>
- <entry>Maximum number of pre-fetched messages per consumer. <para>This can also be defaulted for consumers created on a particular connection using the <link linkend="section-jms-connection-url">Connection URL</link> options, or per destination (see the <varname>capacity</varname> option under link properties in addressing)</para></entry>
- </row>
-
- <row>
- <entry>qpid.session.max_ack_delay</entry>
- <entry>long</entry>
- <entry>1000 (ms)</entry>
- <entry><para>Timer interval to flush message acks in buffer when using AUTO_ACK and DUPS_OK.</para> <para>When using the above ack modes, message acks are batched and sent if one of the following conditions are met (which ever happens first).
- <itemizedlist>
- <listitem><para>When the ack timer fires.</para></listitem>
- <listitem><para>if un_acked_msg_count > max_prefetch/2.</para></listitem>
- </itemizedlist>
- </para>
- <para>The ack timer can be disabled by setting it to 0.</para>
- </entry>
- </row>
-
- <row>
- <entry>sync_ack</entry>
- <entry>boolean</entry>
- <entry>false</entry>
- <entry><para>If set, each message will be acknowledged synchronously. When using AUTO_ACK mode, you need to set this to "true", in order to get the correct behaviour as described by the JMS spec.</para><para>This is set to false by default for performance reasons, therefore by default AUTO_ACK behaves similar to DUPS_OK.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table >
- <title>Config Options For Producer Behaviour</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>sync_publish</entry>
- <entry>string</entry>
- <entry>"" (disabled)</entry>
- <entry><para>If one of {persistent|all} is set then persistent messages or all messages will be sent synchronously.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table >
- <title>Config Options For Threading</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>qpid.thread_factory</entry>
- <entry>string</entry>
- <entry>org.apache.qpid.thread.DefaultThreadFactory</entry>
- <entry><para>Specifies the thread factory to use.</para><para>If using a real time JVM, you need to set the above property to <varname>org.apache.qpid.thread.RealtimeThreadFactory</varname>.</para></entry>
- </row>
-
- <row>
- <entry>qpid.rt_thread_priority</entry>
- <entry>int</entry>
- <entry>20</entry>
- <entry><para>Specifies the priority (1-99) for Real time threads created by the real time thread factory.</para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table >
- <title>Config Options For I/O</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>qpid.transport</entry>
- <entry>string</entry>
- <entry>org.apache.qpid.transport.network.io.IoNetworkTransport</entry>
- <entry><para>The transport implementation to be used.</para><para>A user could specify an alternative transport mechanism that implements the interface <varname>org.apache.qpid.transport.network.OutgoingNetworkTransport</varname>.</para></entry>
- </row>
- <row>
- <entry>qpid.sync_op_timeout</entry>
- <entry>long</entry>
- <entry>60000</entry>
- <entry><para>The length of time (in milliseconds) to wait for a synchronous operation to complete.</para><para>For compatibility with older clients, the synonym <varname>amqj.default_syncwrite_timeout</varname> is supported.</para></entry>
- </row>
- <row>
- <entry>qpid.tcp_nodelay</entry>
- <entry>boolean</entry>
- <entry>true</entry>
- <entry>
- <para>Sets the TCP_NODELAY property of the underlying socket. The default was changed to true as of Qpid 0.14.</para>
- <para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para>
- <para>For compatibility with older clients, the synonym <varname>amqj.tcp_nodelay</varname> is supported.</para>
- </entry>
- </row>
- <row>
- <entry>qpid.send_buffer_size</entry>
- <entry>integer</entry>
- <entry>65535</entry>
- <entry>
- <para>Sets the SO_SNDBUF property of the underlying socket. Added in Qpid 0.16.</para>
- <para>For compatibility with older clients, the synonym <varname>amqj.sendBufferSize</varname> is supported.</para>
- </entry>
- </row>
- <row>
- <entry>qpid.receive_buffer_size</entry>
- <entry>integer</entry>
- <entry>65535</entry>
- <entry>
- <para>Sets the SO_RCVBUF property of the underlying socket. Added in Qpid 0.16.</para>
- <para>For compatibility with older clients, the synonym <varname>amqj.receiveBufferSize</varname> is supported.</para>
- </entry>
- </row>
- <row>
- <entry>qpid.failover_method_timeout</entry>
- <entry>long</entry>
- <entry>60000</entry>
- <entry>
- <para>During failover, this is the timeout for each attempt to try to re-establish the connection.
- If a reconnection attempt exceeds the timeout, the entire failover process is aborted.</para>
- <para>It is only applicable for AMQP 0-8/0-9/0-9-1 clients.</para>
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table >
- <title>Config Options For Security</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>qpid.sasl_mechs</entry>
- <entry>string</entry>
- <entry>PLAIN</entry>
- <entry><para>The SASL mechanism to be used. More than one could be specified as a comma separated list.</para><para>We currently support the following mechanisms {PLAIN | GSSAPI | EXTERNAL}.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
-
- <row>
- <entry>qpid.sasl_protocol</entry>
- <entry>string</entry>
- <entry>AMQP</entry>
- <entry><para>When using GSSAPI as the SASL mechanism, <varname>sasl_protocol</varname> must be set to the principal for the qpidd broker, e.g. <varname>qpidd</varname>.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
-
- <row>
- <entry>qpid.sasl_server_name</entry>
- <entry>string</entry>
- <entry>localhost</entry>
- <entry><para>When using GSSAPI as the SASL mechanism, <varname>sasl_server</varname> must be set to the host for the SASL server, e.g. <varname>example.com</varname>.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table>
- <title>Config Options For Security - Standard JVM properties needed when using GSSAPI as the SASL mechanism.<footnote><para>Please refer to the Java security documentation for a complete understanding of the above properties.</para></footnote></title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>javax.security.auth.useSubjectCredsOnly</entry>
- <entry>boolean</entry>
- <entry>true</entry>
- <entry><para>If set to 'false', forces the SASL GASSPI client to obtain the kerberos credentials explicitly instead of obtaining from the "subject" that owns the current thread.</para></entry>
- </row>
-
- <row>
- <entry>java.security.auth.login.config</entry>
- <entry>string</entry>
- <entry></entry>
- <entry><para>Specifies the jass configuration file.</para><para><varname>Ex-Djava.security.auth.login.config=myjas.conf</varname>
- </para><para>Here is the sample myjas.conf JASS configuration file: <programlisting><![CDATA[
-
- com.sun.security.jgss.initiate {
- com.sun.security.auth.module.Krb5LoginModule required useTicketCache=true;
- };
-
- ]]></programlisting></para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table>
- <title>Config Options For Security - Using SSL for securing connections or using EXTERNAL as the SASL mechanism.</title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>qpid.ssl_timeout</entry>
- <entry>long</entry>
- <entry>60000</entry>
- <entry><para>Timeout value used by the Java SSL engine when waiting on operations.</para></entry>
- </row>
-
- <row>
- <entry>qpid.ssl.KeyManagerFactory.algorithm</entry>
- <entry>string</entry>
- <entry>-</entry>
- <entry>
- <para>The key manager factory algorithm name. If not set, defaults to the value returned from the Java runtime call <literal>KeyManagerFactory.getDefaultAlgorithm()</literal></para>
- <para>For compatibility with older clients, the synonym <varname>qpid.ssl.keyStoreCertType</varname> is supported.</para>
- </entry>
- </row>
-
- <row>
- <entry>qpid.ssl.TrustManagerFactory.algorithm</entry>
- <entry>string</entry>
- <entry>-</entry>
- <entry>
- <para>The trust manager factory algorithm name. If not set, defaults to the value returned from the Java runtime call <literal>TrustManagerFactory.getDefaultAlgorithm()</literal></para>
- <para>For compatibility with older clients, the synonym <varname>qpid.ssl.trustStoreCertType</varname> is supported.</para>
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table>
- <title>Config Options For Security - Standard JVM properties needed when Using SSL for securing connections or using EXTERNAL as the SASL mechanism.<footnote><para>Qpid allows you to have per connection key and trust stores if required. If specified per connection, the JVM arguments are ignored.</para></footnote></title>
- <tgroup cols="4">
- <thead>
- <row>
- <entry>Property Name</entry>
- <entry>Type</entry>
- <entry>Default Value</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>javax.net.ssl.keyStore</entry>
- <entry>string</entry>
- <entry>jvm default</entry>
- <entry><para>Specifies the key store path.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
-
- <row>
- <entry>javax.net.ssl.keyStorePassword</entry>
- <entry>string</entry>
- <entry>jvm default</entry>
- <entry><para>Specifies the key store password.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
-
- <row>
- <entry>javax.net.ssl.trustStore</entry>
- <entry>string</entry>
- <entry>jvm default</entry>
- <entry><para>Specifies the trust store path.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
-
- <row>
- <entry>javax.net.ssl.trustStorePassword</entry>
- <entry>string</entry>
- <entry>jvm default</entry>
- <entry><para>Specifies the trust store password.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- </section>
-
- </chapter>
-
- <chapter id="QpidWCF">
- <title>Using the Qpid WCF client</title>
- <section>
- <title>XML and Binary Bindings</title>
-
- <para>The Qpid WCF client provides two bindings, each with support for
- Windows .NET transactions.</para>
-
- <para>The AmqpBinding is suitable for communication between two WCF
- applications. By default it uses the WCF binary .NET XML encoder
- (BinaryMessageEncodingBindingElement) for efficient message
- transmission, but it can also use the text and Message Transmission
- Optimization Mechanism (MTOM) encoders. Here is a traditional service
- model sample program using the AmqpBinding. It assumes that the queue
- "hello_service_node" has been created and configured on the AMQP
- broker.</para>
-
- <example><?dbfo keep-together="auto" ?>
- <title>Traditional service model "Hello world!" example</title>
- <programlisting><![CDATA[
- namespace Apache.Qpid.Documentation.HelloService
- {
- using System;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using System.Threading;
- using Apache.Qpid.Channel;
-
- [ServiceContract]
- public interface IHelloService
- {
- [OperationContract(IsOneWay = true, Action = "*")]
- void SayHello(string greeting);
- }
-
- public class HelloService : IHelloService
- {
- private static int greetingCount;
-
- public static int GreetingCount
- {
- get { return greetingCount; }
- }
-
- public void SayHello(string greeting)
- {
- Console.WriteLine("Service received: " + greeting);
- greetingCount++;
- }]]></programlisting>
-
- <programlisting><![CDATA[
- static void Main(string[] args)
- {
- try
- {
- AmqpBinding amqpBinding = new AmqpBinding();
- amqpBinding.BrokerHost = "localhost";
- amqpBinding.BrokerPort = 5672;
-
- ServiceHost serviceHost = new ServiceHost(typeof(HelloService));
- serviceHost.AddServiceEndpoint(typeof(IHelloService),
- amqpBinding, "amqp:hello_service_node");
- serviceHost.Open();
-
- // Send the service a test greeting
- Uri amqpClientUri=new Uri("amqp:amq.direct?routingkey=hello_service_node");
- EndpointAddress clientEndpoint = new EndpointAddress(amqpClientUri);
- ChannelFactory<IHelloService> channelFactory =
- new ChannelFactory<IHelloService>(amqpBinding, clientEndpoint);
- IHelloService clientProxy = channelFactory.CreateChannel();
-
- clientProxy.SayHello("Greetings from WCF client");
-
- // wait for service to process the greeting
- while (HelloService.GreetingCount == 0)
- {
- Thread.Sleep(100);
- }
- channelFactory.Close();
- serviceHost.Close();
- }
- catch (Exception e)
- {
- Console.WriteLine("Exception: {0}", e);
- }
- }
- }
- }
- ]]></programlisting>
- </example>
-
- <para>The second binding, AmqpBinaryBinding, is suitable for WCF
- applications that need to inter-operate with non-WCF clients or that
- wish to have direct access to the raw wire representation of the
- message body. It relies on a custom encoder to read and write raw
- (binary) content which operates similarly to the ByteStream encoder
- (introduced in .NET 4.0). The encoder presents an abstract XML
- infoset view of the raw message content on input. On output, the
- encoder does the reverse and peels away the XML infoset layer exposing
- the raw content to the wire representation of the message body. The
- application must do the inverse of what the encoder does to allow the
- XML infoset wrapper to cancel properly. This is demonstrated in the
- following sample code (using the channel programming model) which
- directly manipulates or provides callbacks to the WCF message readers
- and writers when the content is consumed. In contrast to the
- AmqpBinding sample where the simple greeting is encapsulated in a
- compressed SOAP envelope, the wire representation of the message
- contains the raw content and is identical and fully interoperable with
- the Qpid C++ "Hello world!" example.</para>
-
- <example><?dbfo keep-together="auto" ?>
- <title>Binary "Hello world!" example using the channel model</title>
- <programlisting><![CDATA[
- namespace Apache.Qpid.Samples.Channel.HelloWorld
- {
- using System;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using System.ServiceModel.Description;
- using System.Text;
- using System.Xml;
- using Apache.Qpid.Channel;
-
- public class HelloWorld
- {
- static void Main(string[] args)
- {
- String broker = "localhost";
- int port = 5672;
- String target = "amq.topic";
- String source = "my_topic_node";
-
- if (args.Length > 0)
- {
- broker = args[0];
- }
-
- if (args.Length > 1)
- {
- port = int.Parse(args[1]);
- }
-
- if (args.Length > 2)
- {
- target = args[2];
- }
-
- if (args.Length > 3)
- {
- source = args[3];
- }
-
- AmqpBinaryBinding binding = new AmqpBinaryBinding();
- binding.BrokerHost = broker;
- binding.BrokerPort = port;
-
- IChannelFactory<IInputChannel> receiverFactory = binding.BuildChannelFactory<IInputChannel>();
- receiverFactory.Open();
- IInputChannel receiver = receiverFactory.CreateChannel(new EndpointAddress("amqp:" + source));
- receiver.Open();
-
- IChannelFactory<IOutputChannel> senderFactory = binding.BuildChannelFactory<IOutputChannel>();
- senderFactory.Open();
- IOutputChannel sender = senderFactory.CreateChannel(new EndpointAddress("amqp:" + target));
- sender.Open();
-
- sender.Send(Message.CreateMessage(MessageVersion.None, "", new HelloWorldBinaryBodyWriter()));
-
- Message message = receiver.Receive();
- XmlDictionaryReader reader = message.GetReaderAtBodyContents();
- while (!reader.HasValue)
- {
- reader.Read();
- }
-
- byte[] binaryContent = reader.ReadContentAsBase64();
- string text = Encoding.UTF8.GetString(binaryContent);
-
- Console.WriteLine(text);
-
- senderFactory.Close();
- receiverFactory.Close();
- }
- }
-
- public class HelloWorldBinaryBodyWriter : BodyWriter
- {
- public HelloWorldBinaryBodyWriter() : base (true) {}
-
- protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
- {
- byte[] binaryContent = Encoding.UTF8.GetBytes("Hello world!");
-
- // wrap the content:
- writer.WriteStartElement("Binary");
- writer.WriteBase64(binaryContent, 0, binaryContent.Length);
- }
- }
- }
- ]]></programlisting>
- </example>
-
- <para>Bindings define ChannelFactories and ChannelListeners associated with
- an AMQP Broker. WCF will frequently automatically create and manage
- the life cycle of a these and the resulting IChannel objects used in
- message transfer. The binding parameters that can be set are:</para>
-
- <table pgwide="1">
- <title>WCF Binding Parameters</title>
- <tgroup cols="3">
- <thead>
- <colspec colnum="1" colwidth="1*"/>
- <colspec colnum="2" colwidth="3*"/>
- <colspec colnum="3" colwidth="3*"/>
- <row>
- <entry>Parameter</entry>
- <entry>Default</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- BrokerHost
- </entry>
- <entry>
- localhost
- </entry>
- <entry>
- The broker's server name. Currently the WCF channel
- only supports connections with a single broker.
- Failover to multiple brokers will be provided in the
- future.
- </entry>
- </row>
-
- <row>
- <entry>
- BrokerPort
- </entry>
- <entry>
- 5672
- </entry>
- <entry>
- The port the broker is listening on.
- </entry>
- </row>
-
- <row>
- <entry>
- PrefetchLimit
- </entry>
- <entry>
- 0
- </entry>
- <entry>
- The number of messages to prefetch from the amqp
- broker before the application actually consumes them.
- Increasing this number can dramatically increase the
- read performance in some circumstances.
- </entry>
- </row>
-
- <row>
- <entry>
- Shared
- </entry>
- <entry>
- false
- </entry>
- <entry>
- Indicates if separate channels to the same broker can
- share an underlying AMQP tcp connection (provided they
- also share the same authentication credentials).
- </entry>
- </row>
-
- <row>
- <entry>
- TransferMode
- </entry>
- <entry>
- buffered
- </entry>
- <entry>
- Indicates whether the channel's encoder uses the WCF
- BufferManager cache to temporarily store message
- content during the encoding/decoding phase. For small
- to medium sized SOAP based messages, buffered is
- usually the preferred choice. For binary messages,
- streamed TransferMode is the more efficient mode.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
-
- <section>
- <title>Endpoints</title>
-
- <para>In Qpid 0.6 the WCF Endpoints map to simple AMQP 0-10
- exchanges (IOutputChannel) or AMQP 0-10 queues (IInputChannel).
- The format for an IOutputChannel is</para>
-
- <programlisting><![CDATA[
- "amqp:amq.direct" or "amqp:my_exchange?routingkey=my_routing_key"
-]]></programlisting>
-
- <para>and for an IInputChannel is</para>
-
- <programlisting><![CDATA[
- "amqp:my_queue"
-]]></programlisting>
-
- <para>The routing key is in fact a default value associated with
- the particular channel. Outgoing messages can always have their
- routing key uniquely set.</para>
-
- <para>If the respective queue or exchange doesn't exist, an exception
- is thrown when opening the channel. Queues and exchanges can be
- created and configured using qpid-config.</para>
-
- </section>
-
- <section>
- <title>Message Headers</title>
-
- <para>AMQP specific message headers can be set on or retrieved
- from the ServiceModel.Channels.Message using the AmqpProperties
- type.</para>
-
- <para>For example, on output:</para>
-
- <programlisting><![CDATA[
-AmqpProperties props = new AmqpProperties();
-props.Durable = true;
-props.PropertyMap.Add("my_custom_header", new AmqpString("a custom value"));
-Message msg = Message.CreateMessage(args);
-msg.Properties.Add("AmqpProperties", amqpProperties);
-outputChannel.Send(msg);
-]]></programlisting>
-
- <para>On input the headers can be accessed from the Message or extracted
- from the operation context</para>
-
- <programlisting><![CDATA[
-public void SayHello(string greeting)
-{
- AmqpProperties props = (AmqpProperties) OperationContext.
- Current.IncomingMessageProperties["AmqpProperties"];
- AmqpString extra = (AmqpString) props.PropertyMap["my_custom_header"];
- Console.WriteLine("Service received: {0} and {1}", greeting, extra);
-}
-]]></programlisting>
-
- </section>
-
- <section>
- <title>Security</title>
-
- <para>To engage TLS/SSL:</para>
-
- <programlisting><![CDATA[
-binding.Security.Mode = AmqpSecurityMode.Transport;
-binding.Security.Transport.UseSSL = true;
-binding.BrokerPort = 5671;
-]]></programlisting>
-
- <para>Currently the WCF client only provides SASL PLAIN (i.e. username and
- password) authentication. To provide a username and password, you can
- set the DefaultAmqpCredential value in the binding. This value can be
- overridden or set for a binding's channel factories and listeners,
- either by setting the ClientCredentials as a binding parameter, or by
- using an AmqpCredential as a binding parameter. The search order for
- credentials is the AmqpCredential binding parameter, followed by the
- ClientCredentials (unless IgnoreEndpointClientCredentials has been
- set), and finally defaulting to the DefaultAmqpCredential of the
- binding itself. Here is a sample using ClientCredentials:</para>
-
- <programlisting><![CDATA[
-ClientCredentials credentials = new ClientCredentials();
-credentials.UserName.UserName = "guest";
-credentials.UserName.Password = "guest";
-bindingParameters = new BindingParameterCollection();
-bindingParameters.Add(credentials);
-readerFactory = binding.BuildChannelFactory<IInputChannel>(bindingParameters);
-]]></programlisting>
-
- </section>
-
- <section>
- <title>Transactions</title>
-
- <para>The WCF channel provides a transaction resource manager
- module and a recovery module that together provide distributed
- transaction support with one-phase optimization. Some
- configuration is required on Windows machines to enable
- transaction support (see your installation notes or top level
- ReadMe.txt file for instructions). Once properly configured,
- the Qpid WCF channel acts as any other System.Transactions aware
- resource, capable of participating in explicit or implicit
- transactions.</para>
-
- <para>Server code:</para>
-
- <programlisting><![CDATA[
-[OperationBehavior(TransactionScopeRequired = true,
- TransactionAutoComplete = true)]
-
-public void SayHello(string greeting)
-{
- // increment ExactlyOnceReceived counter on DB
-
- // Success: transaction auto completes:
-}
-]]></programlisting>
-
- <para>Because this operation involves two transaction resources, the
- database and the AMQP message broker, this operates as a full two
- phase commit transaction managed by the Distributed Transaction
- Coordinator service. If the transaction proceeds without error,
- both ExactlyOnceReceived is incremented in the database and the AMQP
- message is consumed from the broker. Otherwise, ExactlyOnceReceived is
- unchanged and AMQP message is returned to its queue on the broker.</para>
-
- <para>For the client code a few changes are made to the non-transacted
- example. For "exactly once" semantics, we set the AMQP "Durable"
- message property and enclose the transacted activities in a
- TransactionScope:</para>
-
- <programlisting><![CDATA[
-AmqpProperties myDefaults = new AmqpProperties();
-myDefaults.Durable = true;
-amqpBinding.DefaultMessageProperties = myDefaults;
-ChannelFactory<IHelloService> channelFactory =
-new ChannelFactory<IHelloService>(amqpBinding, clientEndpoint);
-IHelloService clientProxy = channelFactory.CreateChannel();
-
-using (TransactionScope ts = new TransactionScope())
-{
- AmqpProperties amqpProperties = new AmqpProperties();
- clientProxy.SayHello("Greetings from WCF client");
- // increment ExactlyOnceSent counter on DB
- ts.Complete();
-}
-]]></programlisting>
-
- </section>
- </chapter>
-
- <chapter>
- <title>The .NET Binding for the C++ Messaging Client</title>
- <para>
- The .NET Binding for the C++ Qpid Messaging Client is a library that gives
- any .NET program access to Qpid C++ Messaging objects and methods.
- </para>
- <section>
- <title>.NET Binding for the C++ Messaging Client Component Architecture</title>
-
- <programlisting><![CDATA[
- +----------------------------+
- | Dotnet examples |
- | Managed C# |
- +------+---------------+-----+
- | |
- V |
- +---------------------------+ |
- | .NET Managed Callback | |
- | org.apache.qpid.messaging.| |
- | sessionreceiver.dll | |
- +----------------------+----+ |
- | |
-managed V V
-(.NET) +--------------------------------+
-:::::::::::::::::::::::| .NET Binding Library |::::::::::::
-unmanaged | org.apache.qpid.messaging.dll |
-(Native Win32/64) +---------------+----------------+
- |
- |
- +----------------+ |
- | Native examples| |
- | Unmanaged C++ | |
- +--------+-------+ |
- | |
- V V
- +----------------------------------+
- | QPID Messaging C++ Libraries |
- | qpid*.dll qmf*.dll |
- +--------+--------------+----------+
-]]></programlisting>
-
-
-<para>This diagram illustrates the code and library components of the binding
-and the hierarchical relationships between them.</para>
-
- <table id="table-Dotnet-Binding-Component-Architecture" >
- <title>.NET Binding for the C++ Messaging Client Component Architecture</title>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>Component Name</entry>
- <entry>Component Function</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>QPID Messaging C++ Libraries</entry>
- <entry>The QPID Messaging C++ core run time system</entry>
- </row>
- <row>
- <entry>Unmanaged C++ Example Source Programs</entry>
- <entry>Ordinary C++ programs that illustrate using qpid/cpp Messaging directly
- in a native Windows environment.</entry>
- </row>
- <row>
- <entry>.NET Messaging Binding Library</entry>
- <entry>The .NET Messaging Binding library provides interoprability between
- managed .NET programs and the unmanaged, native Qpid Messaging C++ core
- run time system. .NET programs create a Reference to this library thereby
- exposing all of the native C++ Messaging functionality to programs
- written in any .NET language.</entry>
- </row>
- <row>
- <entry>.NET Messaging Managed Callback Library</entry>
- <entry>An extension of the .NET Messaging Binding Library that provides message
- callbacks in a managed .NET environment.</entry>
- </row>
- <row>
- <entry>Managed C# .NET Example Source Programs</entry>
- <entry>Various C# example programs that illustrate using .NET Binding for C++ Messaging in the .NET environment.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
-
- <section>
- <title>.NET Binding for the C++ Messaging Client Examples</title>
-
- <para>This chapter describes the various sample programs that
- are available to illustrate common Qpid Messaging usage.</para>
-
- <table id="table-Dotnet-Binding-Example-Client-Server">
- <title>Example : Client - Server</title>
- <tgroup cols="2">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Example Name</entry>
- <entry>Example Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>csharp.example.server</entry>
- <entry>Creates a Receiver and listens for messages.
- Upon message reception the message content is converted to upper case
- and forwarded to the received message's ReplyTo address.</entry>
- </row>
- <row>
- <entry>csharp.example.client</entry>
- <entry>Sends a series of messages to the Server and prints the original message
- content and the received message content.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table id="table-Dotnet-Binding-Example-MapSender-MapReceiver">
- <title>Example : Map Sender – Map Receiver</title>
- <tgroup cols="2">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Example Name</entry>
- <entry>Example Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>csharp.map.receiver</entry>
- <entry>Creates a Receiver and listens for a map message.
- Upon message reception the message is decoded and displayed on the console.</entry>
- </row>
- <row>
- <entry>csharp.map.sender</entry>
- <entry>Creates a map message and sends it to map.receiver.
- The map message contains values for every supported .NET Messaging
- Binding data type.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table id="table-Dotnet-Binding-Example-Spout-Drain">
- <title>Example : Spout - Drain</title>
- <tgroup cols="2">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Example Name</entry>
- <entry>Example Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>csharp.example.spout</entry>
- <entry>Spout is a more complex example of code that generates a series of messages
- and sends them to peer program Drain. Flexible command line arguments allow
- the user to specify a variety of message and program options.</entry>
- </row>
- <row>
- <entry>csharp.example.drain</entry>
- <entry>Drain is a more complex example of code that receives a series of messages
- and displays their contents on the console.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table id="table-Dotnet-Binding-Example-CallbackSender-CallbackReceiver">
- <title>Example : Map Callback Sender – Map Callback Receiver</title>
- <tgroup cols="2">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Example Name</entry>
- <entry>Example Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>csharp.map.callback.receiver</entry>
- <entry>Creates a Receiver and listens for a map message.
- Upon message reception the message is decoded and displayed on the console.
- This example illustrates the use of the C# managed code callback mechanism
- provided by .NET Messaging Binding Managed Callback Library.</entry>
- </row>
- <row>
- <entry>csharp.map.callback.sender</entry>
- <entry>Creates a map message and sends it to map_receiver.
- The map message contains values for every supported .NET Messaging
- Binding data type.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table id="table-Dotnet-Binding-Example-DeclareQueues">
- <title>Example - Declare Queues</title>
- <tgroup cols="2">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Example Name</entry>
- <entry>Example Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>csharp.example.declare_queues</entry>
- <entry>A program to illustrate creating objects on a broker.
- This program creates a queue used by spout and drain.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table id="table-Dotnet-Binding-Example-DirectSender-DirectReceiver">
- <title>Example: Direct Sender - Direct Receiver</title>
- <tgroup cols="2">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Example Name</entry>
- <entry>Example Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>csharp.direct.receiver</entry>
- <entry>Creates a Receiver and listens for a messages.
- Upon message reception the message is decoded and displayed on the console.</entry>
- </row>
- <row>
- <entry>csharp.direct.sender</entry>
- <entry> Creates a series of messages and sends them to csharp.direct.receiver.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table id="table-Dotnet-Binding-Example-Helloworld">
- <title>Example: Hello World</title>
- <tgroup cols="2">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Example Name</entry>
- <entry>Example Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>csharp.example.helloworld</entry>
- <entry>A program to send a message and to receive the same message.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- </section>
-
- <section>
- <title>.NET Binding Class Mapping to Underlying C++ Messaging API</title>
-
- <para>This chapter describes the specific mappings between
- classes in the .NET Binding and the underlying C++ Messaging
- API.</para>
-
- <section>
- <title>.NET Binding for the C++ Messaging API Class: Address</title>
- <table id="table-Dotnet-Binding-Address">
- <title>.NET Binding for the C++ Messaging API Class: Address</title>
- <tgroup cols="2">
- <colspec colname="c1" colwidth="1*"/>
- <colspec colname="c2" colwidth="7*"/>
- <thead>
- <row>
- <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Address</entry>
- </row>
- <row>
- <entry>Language</entry>
- <entry>Syntax</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>C++</entry>
- <entry>class Address</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ref class Address</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Address();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Address();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Address(const std::string&amp; address);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Address(string address);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Address(const std::string&amp; name, const std::string&amp; subject, const qpid::types::Variant::Map&amp; options, const std::string&amp; type = "");</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Address(string name, string subject, Dictionary&lt;string, object&gt; options);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Address(string name, string subject, Dictionary&lt;string, object&gt; options, string type);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Address(const Address&amp; address);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Address(Address address);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Destructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>~Address();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>~Address();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>!Address();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Address&amp; operator=(const Address&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Address op_Assign(Address rhs);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Name</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getName() const;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setName(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string Name { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Subject</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getSubject() const;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setSubject(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string Subject { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Options</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const qpid::types::Variant::Map&amp; getOptions() const;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>qpid::types::Variant::Map&amp; getOptions();</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setOptions(const qpid::types::Variant::Map&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Dictionary&lt;string, object&gt; Options { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Type</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>std::string getType() const;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setType(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string Type { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Miscellaneous</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>std::string str() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string ToStr();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Miscellaneous</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>operator bool() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Miscellaneous</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool operator !() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>n/a</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- <section>
- <title>.NET Binding for the C++ Messaging API Class: Connection</title>
- <table id="table-Dotnet-Binding-Connection">
- <title>.NET Binding for the C++ Messaging API Class: Connection</title>
- <tgroup cols="2">
- <colspec colname="c1" colwidth="1*"/>
- <colspec colname="c2" colwidth="7*"/>
- <thead>
- <row>
- <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Connection</entry>
- </row>
- <row>
- <entry>Language</entry>
- <entry>Syntax</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>C++</entry>
- <entry>class Connection : public qpid::messaging::Handle&lt;ConnectionImpl&gt;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ref class Connection</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Connection(ConnectionImpl* impl);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Connection();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Connection(const std::string&amp; url, const qpid::types::Variant::Map&amp; options = qpid::types::Variant::Map());</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Connection(string url);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Connection(string url, Dictionary&lt;string, object&gt; options);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Connection(const std::string&amp; url, const std::string&amp; options);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Connection(string url, string options); </entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Connection(const Connection&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Connection(Connection connection);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Destructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>~Connection();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>~Connection();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>!Connection();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Connection&amp; operator=(const Connection&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Connection op_Assign(Connection rhs);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: SetOption</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setOption(const std::string&amp; name, const qpid::types::Variant&amp; value);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void SetOption(string name, object value);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: open</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void open();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Open();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: isOpen</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool isOpen();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool IsOpen { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: close</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void close();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Close();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: createTransactionalSession</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Session createTransactionalSession(const std::string&amp; name = std::string());</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session CreateTransactionalSession();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session CreateTransactionalSession(string name);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: createSession</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Session createSession(const std::string&amp; name = std::string());</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session CreateSession();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session CreateSession(string name);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: getSession</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Session getSession(const std::string&amp; name) const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session GetSession(string name);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: AuthenticatedUsername</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>std::string getAuthenticatedUsername();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string GetAuthenticatedUsername();</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- <section>
- <title>.NET Binding for the C++ Messaging API Class: Duration</title>
- <table id="table-Dotnet-Binding-Duration">
- <title>.NET Binding for the C++ Messaging API Class: Duration</title>
- <tgroup cols="2">
- <colspec colname="c1" colwidth="1*"/>
- <colspec colname="c2" colwidth="7*"/>
- <thead>
- <row>
- <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Duration</entry>
- </row>
- <row>
- <entry>Language</entry>
- <entry>Syntax</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>C++</entry>
- <entry>class Duration</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ref class Duration</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>explicit Duration(uint64_t milliseconds);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Duration(ulong mS);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Duration(Duration rhs);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Destructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>default</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>default</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>default</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Milliseconds</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint64_t getMilliseconds() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ulong Milliseconds { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Operator: *</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Duration operator*(const Duration&amp; duration, uint64_t multiplier);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public static Duration operator *(Duration dur, ulong multiplier);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public static Duration Multiply(Duration dur, ulong multiplier);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Duration operator*(uint64_t multiplier, const Duration&amp; duration);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public static Duration operator *(ulong multiplier, Duration dur);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public static Duration Multiply(ulong multiplier, Duration dur);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constants</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>static const Duration FOREVER;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>static const Duration IMMEDIATE;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>static const Duration SECOND;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>static const Duration MINUTE;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public sealed class DurationConstants</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public static Duration FORVER;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public static Duration IMMEDIATE;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public static Duration MINUTE;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public static Duration SECOND;</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- <section>
- <title>.NET Binding for the C++ Messaging API Class: FailoverUpdates</title>
- <table id="table-Dotnet-Binding-FailoverUpdates">
- <title>.NET Binding for the C++ Messaging API Class: FailoverUpdates</title>
- <tgroup cols="2">
- <colspec colname="c1" colwidth="1*"/>
- <colspec colname="c2" colwidth="7*"/>
- <thead>
- <row>
- <entry namest="c1" nameend="c2" align="center">.NET Binding Class: FailoverUpdates</entry>
- </row>
- <row>
- <entry>Language</entry>
- <entry>Syntax</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>C++</entry>
- <entry>class FailoverUpdates</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ref class FailoverUpdates</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>FailoverUpdates(Connection&amp; connection);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public FailoverUpdates(Connection connection);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Destructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>~FailoverUpdates();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>~FailoverUpdates();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>!FailoverUpdates();</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- <section>
- <title>.NET Binding for the C++ Messaging API Class: Message</title>
- <table id="table-Dotnet-Binding-Message">
- <title>.NET Binding for the C++ Messaging API Class: Message</title>
- <tgroup cols="2">
- <colspec colname="c1" colwidth="1*"/>
- <colspec colname="c2" colwidth="7*"/>
- <thead>
- <row>
- <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Message</entry>
- </row>
- <row>
- <entry>Language</entry>
- <entry>Syntax</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>C++</entry>
- <entry>class Message</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ref class Message</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Message(const std::string&amp; bytes = std::string());</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>Message();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>Message(System::String ^ theStr);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>Message(System::Object ^ theValue);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>Message(array&lt;System::Byte&gt; ^ bytes);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Message(const char*, size_t);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Message(byte[] bytes, int offset, int size);</entry>
- </row>
- <row>
- <entry> </entry>
- <entry>Copy constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Message(const Message&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Message(Message message);</entry>
- </row>
- <row>
- <entry> </entry>
- <entry>Copy assignment operator</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Message&amp; operator=(const Message&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Message op_Assign(Message rhs);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Destructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>~Message();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>~Message();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>!Message()</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: ReplyTo</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setReplyTo(const Address&amp;);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const Address&amp; getReplyTo() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Address ReplyTo { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Subject</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setSubject(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getSubject() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string Subject { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: ContentType</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setContentType(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getContentType() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string ContentType { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: MessageId</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setMessageId(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getMessageId() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string MessageId { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: UserId</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setUserId(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getUserId() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string UserId { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: CorrelationId</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setCorrelationId(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getCorrelationId() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string CorrelationId { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Priority</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setPriority(uint8_t);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint8_t getPriority() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public byte Priority { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Ttl</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setTtl(Duration ttl);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Duration getTtl() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Duration Ttl { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Durable</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setDurable(bool durable);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool getDurable() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool Durable { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Redelivered</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool getRedelivered() const;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setRedelivered(bool);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool Redelivered { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: SetProperty</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setProperty(const std::string&amp;, const qpid::types::Variant&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void SetProperty(string name, object value);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Properties</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const qpid::types::Variant::Map&amp; getProperties() const;</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>qpid::types::Variant::Map&amp; getProperties();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Dictionary&lt;string, object&gt; Properties { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: SetContent</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setContent(const std::string&amp;);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setContent(const char* chars, size_t count);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void SetContent(byte[] bytes);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void SetContent(string content);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void SetContent(byte[] bytes, int offset, int size);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: GetContent</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>std::string getContent() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string GetContent();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void GetContent(byte[] arr);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void GetContent(Collection&lt;object&gt; __p1);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void GetContent(Dictionary&lt;string, object&gt; dict);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: GetContentPtr</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const char* getContentPtr() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: ContentSize</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>size_t getContentSize() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ulong ContentSize { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Struct: EncodingException</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>struct EncodingException : qpid::types::Exception</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: decode</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void decode(const Message&amp; message, qpid::types::Variant::Map&amp; map, const std::string&amp; encoding = std::string());</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void decode(const Message&amp; message, qpid::types::Variant::List&amp; list, const std::string&amp; encoding = std::string());</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: encode</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void encode(const qpid::types::Variant::Map&amp; map, Message&amp; message, const std::string&amp; encoding = std::string());</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void encode(const qpid::types::Variant::List&amp; list, Message&amp; message, const std::string&amp; encoding = std::string());</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: AsString</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string AsString(object obj);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string ListAsString(Collection&lt;object&gt; list);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string MapAsString(Dictionary&lt;string, object&gt; dict);</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- <section>
- <title>.NET Binding for the C++ Messaging API Class: Receiver</title>
- <table id="table-Dotnet-Binding-Receiver">
- <title>.NET Binding for the C++ Messaging API Class: Receiver</title>
- <tgroup cols="2">
- <colspec colname="c1" colwidth="1*"/>
- <colspec colname="c2" colwidth="7*"/>
- <thead>
- <row>
- <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Receiver</entry>
- </row>
- <row>
- <entry>Language</entry>
- <entry>Syntax</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>C++</entry>
- <entry>class Receiver</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ref class Receiver</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>Constructed object is returned by Session.CreateReceiver</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Receiver(const Receiver&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Receiver(Receiver receiver);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Destructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>~Receiver();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>~Receiver();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>!Receiver()</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Receiver&amp; operator=(const Receiver&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Receiver op_Assign(Receiver rhs);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Get</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool get(Message&amp; message, Duration timeout=Duration::FOREVER);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool Get(Message mmsgp);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool Get(Message mmsgp, Duration durationp);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Get</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Message get(Duration timeout=Duration::FOREVER);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Message Get();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Message Get(Duration durationp);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Fetch</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool fetch(Message&amp; message, Duration timeout=Duration::FOREVER);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool Fetch(Message mmsgp);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool Fetch(Message mmsgp, Duration duration);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Fetch</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Message fetch(Duration timeout=Duration::FOREVER);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Message Fetch();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Message Fetch(Duration durationp);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Capacity</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setCapacity(uint32_t);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint32_t getCapacity();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public uint Capacity { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Available</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint32_t getAvailable();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public uint Available { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Unsettled</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint32_t getUnsettled();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public uint Unsettled { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Close</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void close();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Close();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: IsClosed</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool isClosed() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool IsClosed { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Name</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getName() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string Name { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Session</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Session getSession() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session Session { get; }</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- <section>
- <title>.NET Binding for the C++ Messaging API Class: Sender</title>
- <table id="table-Dotnet-Binding-Sender">
- <title>.NET Binding for the C++ Messaging API Class: Sender</title>
- <tgroup cols="2">
- <colspec colname="c1" colwidth="1*"/>
- <colspec colname="c2" colwidth="7*"/>
- <thead>
- <row>
- <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Sender</entry>
- </row>
- <row>
- <entry>Language</entry>
- <entry>Syntax</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>C++</entry>
- <entry>class Sender</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ref class Sender</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>Constructed object is returned by Session.CreateSender</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Sender(const Sender&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Sender(Sender sender);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Destructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>~Sender();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>~Sender();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>!Sender()</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Sender&amp; operator=(const Sender&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Sender op_Assign(Sender rhs);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Send</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void send(const Message&amp; message, bool sync=false);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Send(Message mmsgp);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Send(Message mmsgp, bool sync);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Close</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void close();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Close();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Capacity</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void setCapacity(uint32_t);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint32_t getCapacity();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public uint Capacity { get; set; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Available</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint32_t getAvailable();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public uint Available { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Unsettled</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint32_t getUnsettled();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public uint Unsettled { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Name</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>const std::string&amp; getName() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public string Name { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Session</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Session getSession() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session Session { get; }</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- <section>
- <title>.NET Binding for the C++ Messaging API Class: Session</title>
- <table id="table-Dotnet-Binding-Session">
- <title>.NET Binding for the C++ Messaging API Class: Session</title>
- <tgroup cols="2">
- <colspec colname="c1" colwidth="1*"/>
- <colspec colname="c2" colwidth="7*"/>
- <thead>
- <row>
- <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Session</entry>
- </row>
- <row>
- <entry>Language</entry>
- <entry>Syntax</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>C++</entry>
- <entry>class Session</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public ref class Session</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Constructor</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>Constructed object is returned by Connection.CreateSession</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Session(const Session&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session(Session session);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Destructor</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>~Session();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>~Session();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>n/a</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>!Session()</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Session&amp; operator=(const Session&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Session op_Assign(Session rhs);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Close</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void close();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Close();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Commit</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void commit();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Commit();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Rollback</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void rollback();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Rollback();</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Acknowledge</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void acknowledge(bool sync=false);</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void acknowledge(Message&amp;, bool sync=false);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Acknowledge();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Acknowledge(bool sync);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Acknowledge(Message __p1);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Acknowledge(Message __p1, bool __p2);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Reject</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void reject(Message&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Reject(Message __p1);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Release</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void release(Message&amp;);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Release(Message __p1);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: Sync</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void sync(bool block=true);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Sync();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void Sync(bool block);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Receivable</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint32_t getReceivable();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public uint Receivable { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: UnsettledAcks</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>uint32_t getUnsettledAcks();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public uint UnsetledAcks { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: NextReceiver</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool nextReceiver(Receiver&amp;, Duration timeout=Duration::FOREVER);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool NextReceiver(Receiver rcvr);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool NextReceiver(Receiver rcvr, Duration timeout);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: NextReceiver</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Receiver nextReceiver(Duration timeout=Duration::FOREVER);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Receiver NextReceiver();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Receiver NextReceiver(Duration timeout);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: CreateSender</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Sender createSender(const Address&amp; address);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Sender CreateSender(Address address);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: CreateSender</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Sender createSender(const std::string&amp; address);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Sender CreateSender(string address);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: CreateReceiver</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Receiver createReceiver(const Address&amp; address);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Receiver CreateReceiver(Address address);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: CreateReceiver</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Receiver createReceiver(const std::string&amp; address);</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Receiver CreateReceiver(string address);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: GetSender</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Sender getSender(const std::string&amp; name) const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Sender GetSender(string name);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: GetReceiver</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Receiver getReceiver(const std::string&amp; name) const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Receiver GetReceiver(string name);</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: Connection</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>Connection getConnection() const;</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public Connection Connection { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Property: HasError</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>bool hasError();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public bool HasError { get; }</entry>
- </row>
- <row>
- <entry namest="c1" nameend="c2" align="center">Method: CheckError</entry>
- </row>
- <row>
- <entry>C++</entry>
- <entry>void checkError();</entry>
- </row>
- <row>
- <entry>.NET</entry>
- <entry>public void CheckError();</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </section>
- <section>
- <title>.NET Binding Class: SessionReceiver</title>
- <para>
- The SessionReceiver class provides a convenient callback
- mechanism for Messages received by all Receivers on a given
- Session.
- </para>
- <para>
- <programlisting><![CDATA[
-using Org.Apache.Qpid.Messaging;
-using System;
-
-namespace Org.Apache.Qpid.Messaging.SessionReceiver
-{
- public interface ISessionReceiver
- {
- void SessionReceiver(Receiver receiver, Message message);
- }
-
- public class CallbackServer
- {
- public CallbackServer(Session session, ISessionReceiver callback);
-
- public void Close();
- }
-}
-]]>
- </programlisting>
- </para>
- <para>
- To use this class a client program includes references to both
- Org.Apache.Qpid.Messaging and Org.Apache.Qpid.Messaging.SessionReceiver.
- The calling program creates a function that implements the
- ISessionReceiver interface. This function will be called whenever
- message is received by the session. The callback process is started
- by creating a CallbackServer and will continue to run until the
- client program calls the CallbackServer.Close function.
- </para>
- <para>
- A complete operating example of using the SessionReceiver callback
- is contained in cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver.
- </para>
- </section>
- </section>
- </chapter>
-</book>
-
-<!--
- - client code remains exactly the same, but routing behavior
- changes
- - exchanges drop messages if nobody is listening, so we need to
- start drain first
- - drain will exit immediately if the source is empty (note that
- this is actually a semantic guarantee provided by the API, we
- know for a fact that the source is empty when drain/fetch
- reports it, no fudge factor timeout is required [this assumes
- nobody is concurrently publishing of course])
- - drain -f invokes blocking fetch (you could use a timeout here also)
- -->
diff --git a/doc/book/src/programming/Programming-In-Apache-Qpid.xml b/doc/book/src/programming/Programming-In-Apache-Qpid.xml
new file mode 100644
index 0000000000..e2f6d8756c
--- /dev/null
+++ b/doc/book/src/programming/Programming-In-Apache-Qpid.xml
@@ -0,0 +1,6530 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+
+<!--
+
+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.
+
+-->
+
+<book id="client-api-tutorial">
+ <title>Programming in Apache Qpid</title>
+ <subtitle>Cross-Platform AMQP Messaging in Java JMS, .NET, C++, and Python</subtitle>
+
+ <chapter>
+ <title>Introduction</title>
+
+ <para>Apache Qpid is a reliable, asynchronous messaging system that
+ supports the AMQP messaging protocol in several common programming
+ languages. Qpid is supported on most common platforms.
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ On the Java platform, Qpid uses the
+ established <ulink url="http://java.sun.com/products/jms/">Java JMS
+ API</ulink>.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ For Python, C++, and .NET, Qpid defines its own messaging API, the
+ <firstterm>Qpid Messaging API</firstterm>, which is
+ conceptually similar in each.
+ </para>
+ <para>
+ On the .NET platform, Qpid also provides a WCF binding.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Ruby will also use the Qpid Messaging API, which will soon
+ be implemented. (Ruby currently uses an API that is closely
+ tied to the AMQP version).
+ </para>
+ </listitem>
+ </itemizedlist>
+
+ </chapter>
+
+ <chapter>
+ <title>Using the Qpid Messaging API</title>
+
+ <para>The Qpid Messaging API is quite simple, consisting of only a
+ handful of core classes.
+ </para>
+
+ <itemizedlist>
+
+ <listitem>
+ <para>
+ A <firstterm>message</firstterm> consists of a standard set
+ of fields (e.g. <literal>subject</literal>,
+ <literal>reply-to</literal>), an application-defined set of
+ properties, and message content (the main body of the
+ message).
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ A <firstterm>connection</firstterm> represents a network
+ connection to a remote endpoint.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ A <firstterm>session</firstterm> provides a sequentially
+ ordered context for sending and receiving
+ <emphasis>messages</emphasis>. A session is obtained from a
+ connection.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ A <firstterm>sender</firstterm> sends messages to a target
+ using the <literal>sender.send</literal> method. A sender is
+ obtained from a session for a given target address.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ A <firstterm>receiver</firstterm> receives messages from a
+ source using the <literal>receiver.fetch</literal> method.
+ A receiver is obtained from a session for a given source
+ address.
+ </para>
+ </listitem>
+
+ </itemizedlist>
+
+ <para>
+ The following sections show how to use these classes in a
+ simple messaging program.
+ </para>
+
+ <section>
+ <title>A Simple Messaging Program in C++</title>
+
+ <para>The following C++ program shows how to create a connection,
+ create a session, send messages using a sender, and receive
+ messages using a receiver.</para>
+
+ <example>
+ <title>"Hello world!" in C++</title>
+ <programlisting lang="c++"><![CDATA[
+ #include <qpid/messaging/Connection.h>
+ #include <qpid/messaging/Message.h>
+ #include <qpid/messaging/Receiver.h>
+ #include <qpid/messaging/Sender.h>
+ #include <qpid/messaging/Session.h>
+
+ #include <iostream>]]>
+
+ using namespace qpid::messaging;
+
+ int main(int argc, char** argv) {
+ std::string broker = argc > 1 ? argv[1] : "localhost:5672";
+ std::string address = argc > 2 ? argv[2] : "amq.topic";
+ std::string connectionOptions = argc > 3 ? argv[3] : "";
+
+ Connection connection(broker, connectionOptions);
+ try {
+ connection.open(); <co id="hello-cpp-open" linkends="callout-cpp-open"/>
+ Session session = connection.createSession(); <co id="hello-cpp-session" linkends="callout-cpp-session"/>
+
+ Receiver receiver = session.createReceiver(address); <co id="hello-cpp-receiver" linkends="callout-cpp-receiver"/>
+ Sender sender = session.createSender(address); <co id="hello-cpp-sender" linkends="callout-cpp-sender"/>
+
+ sender.send(Message("Hello world!"));
+
+ Message message = receiver.fetch(Duration::SECOND * 1); <co id="hello-cpp-fetch" linkends="callout-cpp-fetch"/>
+ <![CDATA[std::cout << message.getContent() << std::endl;]]>
+ session.acknowledge(); <co id="hello-cpp-acknowledge" linkends="callout-cpp-acknowledge"/>
+
+ connection.close(); <co id="hello-cpp-close" linkends="callout-cpp-close"/>
+ return 0;
+ } catch(const std::exception&amp; error) {
+ <![CDATA[std::cerr << error.what() << std::endl;]]>
+ connection.close();
+ return 1;
+ }
+ }</programlisting>
+
+ <calloutlist>
+ <callout id="callout-cpp-open" arearefs="hello-cpp-open">
+ <para>Establishes the connection with the messaging broker.</para>
+ </callout>
+ <callout id="callout-cpp-session" arearefs="hello-cpp-session">
+ <para>Creates a session object on which messages will be sent and received.</para>
+ </callout>
+ <callout id="callout-cpp-receiver" arearefs="hello-cpp-receiver">
+ <para>Creates a receiver that receives messages from the given address.</para>
+ </callout>
+ <callout id="callout-cpp-sender" arearefs="hello-cpp-sender">
+ <para>Creates a sender that sends to the given address.</para>
+ </callout>
+ <callout id="callout-cpp-fetch" arearefs="hello-cpp-fetch">
+ <para>Receives the next message. The duration is optional, if omitted, will wait indefinitely for the next message.</para>
+ </callout>
+ <callout id="callout-cpp-acknowledge" arearefs="hello-cpp-acknowledge">
+ <para>Acknowledges receipt of all fetched messages on the
+ session. This informs the broker that the messages were
+ transferred and processed by the client successfully.</para>
+ </callout>
+ <callout id="callout-cpp-close" arearefs="hello-cpp-close">
+ <para>Closes the connection, all sessions managed by the connection, and all senders and receivers managed by each session.</para>
+ </callout>
+ </calloutlist>
+ </example>
+
+
+ </section>
+
+ <section>
+ <title>A Simple Messaging Program in Python</title>
+
+ <para>The following Python program shows how to create a
+ connection, create a session, send messages using a sender, and
+ receive messages using a receiver.</para>
+
+ <example>
+ <title>"Hello world!" in Python</title>
+ <programlisting lang="python"><![CDATA[
+ import sys
+ from qpid.messaging import *
+
+ broker = "localhost:5672" if len(sys.argv)<2 else sys.argv[1]
+ address = "amq.topic" if len(sys.argv)<3 else sys.argv[2]]]>
+
+ connection = Connection(broker)
+
+ try:
+ connection.open() <co id="hello-python-open" linkends="callout-python-open"/>
+ session = connection.session() <co id="hello-python-session" linkends="callout-python-session"/>
+
+ sender = session.sender(address) <co id="hello-python-sender" linkends="callout-python-sender"/>
+ receiver = session.receiver(address) <co id="hello-python-receiver" linkends="callout-python-receiver"/>
+
+ sender.send(Message("Hello world!"));
+
+ message = receiver.fetch(timeout=1) <co id="hello-python-fetch" linkends="callout-python-fetch"/>
+ print message.content
+ session.acknowledge() <co id="hello-python-acknowledge" linkends="callout-python-acknowledge"/>
+
+ except MessagingError,m:
+ print m
+ finally:
+ connection.close() <co id="hello-python-close" linkends="callout-python-close"/>
+ </programlisting>
+
+ <calloutlist>
+ <callout id="callout-python-open" arearefs="hello-python-open">
+ <para>Establishes the connection with the messaging broker.</para>
+ </callout>
+ <callout id="callout-python-session" arearefs="hello-python-session">
+ <para>Creates a session object on which messages will be sent and received.</para>
+ </callout>
+ <callout id="callout-python-receiver" arearefs="hello-python-receiver">
+ <para>Creates a receiver that receives messages from the given address.</para>
+ </callout>
+ <callout id="callout-python-sender" arearefs="hello-python-sender">
+ <para>Creates a sender that sends to the given address.</para>
+ </callout>
+ <callout id="callout-python-fetch" arearefs="hello-python-fetch">
+ <para>Receives the next message. The duration is optional, if omitted, will wait indefinitely for the next message.</para>
+ </callout>
+ <callout id="callout-python-acknowledge" arearefs="hello-python-acknowledge">
+ <para>Acknowledges receipt of all fetched messages on
+ the session. This informs the broker that the messages were
+ transfered and processed by the client successfully.</para>
+ </callout>
+ <callout id="callout-python-close" arearefs="hello-python-close">
+ <para>Closes the connection, all sessions managed by the connection, and all senders and receivers managed by each session.</para>
+ </callout>
+ </calloutlist>
+
+ </example>
+
+ </section>
+
+
+
+
+ <section>
+ <title>A Simple Messaging Program in .NET C#</title>
+
+ <para>The following .NET C#
+ <footnote>
+ <para>
+ The .NET binding for the Qpid C++ Messaging API
+ applies to all .NET Framework managed code languages. C# was chosen
+ for illustration purposes only.
+ </para>
+ </footnote>
+ program shows how to create a connection,
+ create a session, send messages using a sender, and receive
+ messages using a receiver.
+ </para>
+
+ <example>
+ <title>"Hello world!" in .NET C#</title>
+ <programlisting lang="c++">
+ using System;
+ using Org.Apache.Qpid.Messaging; <co id="hello-csharp-using" linkends="callout-csharp-using"/>
+
+ namespace Org.Apache.Qpid.Messaging {
+ class Program {
+ static void Main(string[] args) {
+ String broker = args.Length > 0 ? args[0] : "localhost:5672";
+ String address = args.Length > 1 ? args[1] : "amq.topic";
+
+ Connection connection = null;
+ try {
+ connection = new Connection(broker);
+ connection.Open(); <co id="hello-csharp-open" linkends="callout-csharp-open"/>
+ Session session = connection.CreateSession(); <co id="hello-csharp-session" linkends="callout-csharp-session"/>
+
+ Receiver receiver = session.CreateReceiver(address); <co id="hello-csharp-receiver" linkends="callout-csharp-receiver"/>
+ Sender sender = session.CreateSender(address); <co id="hello-csharp-sender" linkends="callout-csharp-sender"/>
+
+ sender.Send(new Message("Hello world!"));
+
+ Message message = new Message();
+ message = receiver.Fetch(DurationConstants.SECOND * 1); <co id="hello-csharp-fetch" linkends="callout-csharp-fetch"/>
+ Console.WriteLine("{0}", message.GetContent());
+ session.Acknowledge(); <co id="hello-csharp-acknowledge" linkends="callout-csharp-acknowledge"/>
+
+ connection.Close(); <co id="hello-csharp-close" linkends="callout-csharp-close"/>
+ } catch (Exception e) {
+ Console.WriteLine("Exception {0}.", e);
+ if (null != connection)
+ connection.Close();
+ }
+ }
+ }
+ }
+
+ </programlisting>
+
+ <calloutlist>
+ <callout id="callout-csharp-using" arearefs="hello-csharp-using">
+ <para> Permits use of Org.Apache.Qpid.Messaging types and methods without explicit namespace qualification. Any .NET project must have a project reference to the assembly file <literal>Org.Apache.Qpid.Messaging.dll</literal> in order to obtain the definitions of the .NET Binding for Qpid Messaging namespace.</para>
+ </callout>
+ <callout id="callout-csharp-open" arearefs="hello-csharp-open">
+ <para>Establishes the connection with the messaging broker.</para>
+ </callout>
+ <callout id="callout-csharp-session" arearefs="hello-csharp-session">
+ <para>Creates a session object on which messages will be sent and received.</para>
+ </callout>
+ <callout id="callout-csharp-receiver" arearefs="hello-csharp-receiver">
+ <para>Creates a receiver that receives messages from the given address.</para>
+ </callout>
+ <callout id="callout-csharp-sender" arearefs="hello-csharp-sender">
+ <para>Creates a sender that sends to the given address.</para>
+ </callout>
+ <callout id="callout-csharp-fetch" arearefs="hello-csharp-fetch">
+ <para>Receives the next message. The duration is optional, if omitted, will wait indefinitely for the next message.</para>
+ </callout>
+ <callout id="callout-csharp-acknowledge" arearefs="hello-csharp-acknowledge">
+ <para>Acknowledges receipt of all fetched messages on the
+ session. This informs the broker that the messages were
+ transfered and processed by the client successfully.</para>
+ </callout>
+ <callout id="callout-csharp-close" arearefs="hello-csharp-close">
+ <para>Closes the connection, all sessions managed by the connection, and all senders and receivers managed by each session.</para>
+ </callout>
+ </calloutlist>
+ </example>
+
+
+ </section>
+
+
+
+
+
+
+ <section id="section-addresses">
+ <title>Addresses</title>
+
+ <para>An <firstterm>address</firstterm> is the name of a message
+ target or message source.
+
+ <footnote><para>In the programs we have just seen, we used
+ <literal>amq.topic</literal> as the default address if none is
+ passed in. This is the name of a standard exchange that always
+ exists on an AMQP 0-10 messaging broker.</para></footnote>
+
+ The methods that create senders and receivers require an
+ address. The details of sending to a particular target or
+ receiving from a particular source are then handled by the
+ sender or receiver. A different target or source can be used
+ simply by using a different address.
+ </para>
+
+ <para>An address resolves to a <firstterm>node</firstterm>. The
+ Qpid Messaging API recognises two kinds of nodes,
+ <firstterm>queues</firstterm> and <firstterm>topics</firstterm>
+
+ <footnote><para>The terms <emphasis>queue</emphasis> and
+ <emphasis>topic</emphasis> here were chosen to align with
+ their meaning in JMS. These two addressing 'patterns',
+ queue and topic, are sometimes refered as point-to-point
+ and publish-subscribe. AMQP 0-10 has an exchange type
+ called a <emphasis>topic exchange</emphasis>. When the term
+ <emphasis>topic</emphasis> occurs alone, it refers to a
+ Messaging API topic, not the topic
+ exchange.</para></footnote>.
+
+ A queue stores each message until it has been received and
+ acknowledged, and only one receiver can receive a given message
+
+ <footnote><para>There are exceptions to this rule; for instance,
+ a receiver can use <literal>browse</literal> mode, which leaves
+ messages on the queue for other receivers to
+ read.</para></footnote>.
+
+ A topic immediately delivers a message to all eligible
+ receivers; if there are no eligible receivers, it discards the
+ message. In the AMQP 0-10 implementation of the API,
+
+ <footnote><para>The AMQP 0-10 implementation is the only one
+ that currently exists.</para></footnote>
+
+ queues map to AMQP queues, and topics map to AMQP exchanges.
+
+ <footnote><para>In AMQP 0-10, messages are sent to
+ exchanges, and read from queues. The Messaging API also
+ allows a sender to send messages to a queue; internally,
+ Qpid implements this by sending the message to the default
+ exchange, with the name of the queue as the routing key. The
+ Messaging API also allows a receiver to receive messages
+ from a topic; internally, Qpid implements this by setting up
+ a private subscription queue for the receiver and binding
+ the subscription queue to the exchange that corresponds to
+ the topic.</para></footnote>
+ </para>
+
+ <para>In the rest of this tutorial, we present many examples
+ using two programs that take an address as a command line
+ parameter. <command>spout</command> sends messages to the
+ target address, <command>drain</command> receives messages from
+ the source address. The source code is available in C++, Python, and
+ .NET C# and can be found in the examples directory for each
+ language. These programs can use any address string as a source
+ or a destination, and have many command line options to
+ configure behavior&mdash;use the <command>-h</command> option
+ for documentation on these options.
+
+ <footnote><para>Currently, the C++, Python, and .NET C#
+ implementations of <command>drain</command> and
+ <command>spout</command> have slightly different
+ options. This tutorial uses the C++ implementation. The
+ options will be reconciled in the near
+ future.</para></footnote>
+
+
+ The examples in this tutorial also use the
+ <command>qpid-config</command> utility to configure AMQP 0-10
+ queues and exchanges on a Qpid broker.
+ </para>
+
+
+ <example>
+ <title>Queues</title>
+
+ <para>Create a queue with <command>qpid-config</command>, send a message using
+ <command>spout</command>, and read it using <command>drain</command>:</para>
+
+ <screen>
+ $ qpid-config add queue hello-world
+ $ ./spout hello-world
+ $ ./drain hello-world
+
+ Message(properties={spout-id:c877e622-d57b-4df2-bf3e-6014c68da0ea:0}, content='')
+ </screen>
+
+ <para>The queue stored the message sent by <command>spout</command> and delivered
+ it to <command>drain</command> when requested.</para>
+
+ <para>Once the message has been delivered and and acknowledged
+ by <command>drain</command>, it is no longer available on the queue. If we run
+ <command>drain</command> one more time, no messages will be retrieved.</para>
+
+ <screen>
+ $ ./drain hello-world
+ $
+ </screen>
+
+ </example>
+
+ <example>
+ <title>Topics</title>
+
+ <para>This example is similar to the previous example, but it
+ uses a topic instead of a queue.</para>
+
+ <para>First, use <command>qpid-config</command> to remove the queue
+ and create an exchange with the same name:</para>
+
+ <screen>
+ $ qpid-config del queue hello-world
+ $ qpid-config add exchange topic hello-world
+ </screen>
+
+ <para>Now run <command>drain</command> and <command>spout</command> the same way we did in the previous example:</para>
+
+ <screen>
+ $ ./spout hello-world
+ $ ./drain hello-world
+ $
+ </screen>
+
+ <para>Topics deliver messages immediately to any interested
+ receiver, and do not store messages. Because there were no
+ receivers at the time <command>spout</command> sent the
+ message, it was simply discarded. When we ran
+ <command>drain</command>, there were no messages to
+ receive.</para>
+
+ <para>Now let's run <command>drain</command> first, using the
+ <literal>-t</literal> option to specify a timeout in seconds.
+ While <command>drain</command> is waiting for messages,
+ run <command>spout</command> in another window.</para>
+
+ <para><emphasis>First Window:</emphasis></para>
+
+ <screen>
+ $ ./drain -t 30 hello-word
+ </screen>
+
+
+ <para><emphasis>Second Window:</emphasis></para>
+
+ <screen>
+ $ ./spout hello-word
+ </screen>
+
+ <para>Once <command>spout</command> has sent a message, return
+ to the first window to see the output from
+ <command>drain</command>:</para>
+
+ <screen>
+ Message(properties={spout-id:7da2d27d-93e6-4803-8a61-536d87b8d93f:0}, content='')
+ </screen>
+
+ <para>You can run <command>drain</command> in several separate
+ windows; each creates a subscription for the exchange, and
+ each receives all messages sent to the exchange.</para>
+
+ </example>
+
+ <section>
+ <title>Address Strings</title>
+
+ <para>So far, our examples have used address strings that
+ contain only the name of a node. An <firstterm>address
+ string</firstterm> can also contain a
+ <firstterm>subject</firstterm> and
+ <firstterm>options</firstterm>.</para>
+
+ <para>The syntax for an address string is:</para>
+
+ <programlisting><![CDATA[
+ address_string ::= <address> [ / <subject> ] [ ; <options> ]
+ options ::= { <key> : <value>, ... }
+ ]]></programlisting>
+
+ <para>Addresses, subjects, and keys are strings. Values can
+ be numbers, strings (with optional single or double quotes),
+ maps, or lists. A complete BNF for address strings appears in
+ <xref linkend="section-address-string-bnf"/>.</para>
+
+
+ <para>So far, the address strings in this tutorial have only
+ used simple names. The following sections show how to use
+ subjects and options.</para>
+
+ </section>
+
+ <section>
+ <title>Subjects</title>
+
+
+ <para>Every message has a property called
+ <firstterm>subject</firstterm>, which is analogous to the
+ subject on an email message. If no subject is specified, the
+ message's subject is null. For convenience, address strings
+ also allow a subject. If a sender's address contains a
+ subject, it is used as the default subject for the messages
+ it sends.
+
+ If a receiver's address contains a subject, it is used to
+ select only messages that match the subject&mdash;the matching
+ algorithm depends on the message source.
+ </para>
+
+ <para>
+ In AMQP 0-10, each exchange type has its own matching
+ algorithm. This is discussed in
+ <xref linkend="section-amqp0-10-mapping"/>.
+ </para>
+
+ <note>
+ <para>
+ Currently, a receiver bound to a queue ignores subjects,
+ receiving messages from the queue without filtering. Support
+ for subject filtering on queues will be implemented soon.
+ </para>
+ </note>
+
+
+ <example>
+ <title>Using subjects</title>
+
+ <para>In this example we show how subjects affect message
+ flow.</para>
+
+ <para>First, let's use <command>qpid-config</command> to create a topic exchange.</para>
+
+ <screen>
+ $ qpid-config add exchange topic news-service
+ </screen>
+
+ <para>Now we use drain to receive messages from <literal>news-service</literal> that match the subject <literal>sports</literal>.</para>
+ <para><emphasis>First Window:</emphasis></para>
+ <screen>
+ $ ./drain -t 30 news-service/sports
+ </screen>
+
+ <para>In a second window, let's send messages to <literal>news-service</literal> using two different subjects:</para>
+
+ <para><emphasis>Second Window:</emphasis></para>
+ <screen>
+ $ ./spout news-service/sports
+ $ ./spout news-service/news
+ </screen>
+
+ <para>Now look at the first window, the message with the
+ subject <literal>sports</literal> has been received, but not
+ the message with the subject <literal>news</literal>:</para>
+
+ <screen>
+ Message(properties={qpid.subject:sports, spout-id:9441674e-a157-4780-a78e-f7ccea998291:0}, content='')
+ </screen>
+
+ <para>If you run <command>drain</command> in multiple
+ windows using the same subject, all instances of
+ <command>drain</command> receive the messages for that
+ subject.</para>
+ </example>
+
+
+ <para>The AMQP exchange type we are using here,
+ <literal>amq.topic</literal>, can also do more sophisticated
+ matching.
+
+ A sender's subject can contain multiple words separated by a
+ <quote>.</quote> delimiter. For instance, in a news
+ application, the sender might use subjects like
+ <literal>usa.news</literal>, <literal>usa.weather</literal>,
+ <literal>europe.news</literal>, or
+ <literal>europe.weather</literal>.
+
+ The receiver's subject can include wildcard characters&mdash;
+ <quote>#</quote> matches one or more words in the message's
+ subject, <quote>*</quote> matches a single word.
+
+ For instance, if the subject in the source address is
+ <literal>*.news</literal>, it matches messages with the
+ subject <literal>europe.news</literal> or
+ <literal>usa.news</literal>; if it is
+ <literal>europe.#</literal>, it matches messages with subjects
+ like <literal>europe.news</literal> or
+ <literal>europe.pseudo.news</literal>.</para>
+
+ <example>
+ <title>Subjects with multi-word keys</title>
+
+ <para>This example uses drain and spout to demonstrate the
+ use of subjects with two-word keys.</para>
+
+ <para>Let's use <command>drain</command> with the subject
+ <literal>*.news</literal> to listen for messages in which
+ the second word of the key is
+ <literal>news</literal>.</para>
+
+ <para><emphasis>First Window:</emphasis></para>
+
+ <screen>
+ $ ./drain -t 30 news-service/*.news
+ </screen>
+
+ <para>Now let's send messages using several different
+ two-word keys:</para>
+
+ <para><emphasis>Second Window:</emphasis></para>
+
+ <screen>
+ $ ./spout news-service/usa.news
+ $ ./spout news-service/usa.sports
+ $ ./spout news-service/europe.sports
+ $ ./spout news-service/europe.news
+ </screen>
+
+ <para>In the first window, the messages with
+ <literal>news</literal> in the second word of the key have
+ been received:</para>
+
+ <screen>
+ Message(properties={qpid.subject:usa.news, spout-id:73fc8058-5af6-407c-9166-b49a9076097a:0}, content='')
+ Message(properties={qpid.subject:europe.news, spout-id:f72815aa-7be4-4944-99fd-c64c9747a876:0}, content='')
+ </screen>
+
+
+ <para>Next, let's use <command>drain</command> with the
+ subject <literal>#.news</literal> to match any sequence of
+ words that ends with <literal>news</literal>.</para>
+
+ <para><emphasis>First Window:</emphasis></para>
+
+ <screen>
+ $ ./drain -t 30 news-service/#.news
+ </screen>
+
+ <para>In the second window, let's send messages using a
+ variety of different multi-word keys:</para>
+
+ <para><emphasis>Second Window:</emphasis></para>
+
+ <screen>
+ $ ./spout news-service/news
+ $ ./spout news-service/sports
+ $ ./spout news-service/usa.news
+ $ ./spout news-service/usa.sports
+ $ ./spout news-service/usa.faux.news
+ $ ./spout news-service/usa.faux.sports
+ </screen>
+
+ <para>In the first window, messages with
+ <literal>news</literal> in the last word of the key have been
+ received:</para>
+
+ <screen>
+ Message(properties={qpid.subject:news, spout-id:cbd42b0f-c87b-4088-8206-26d7627c9640:0}, content='')
+ Message(properties={qpid.subject:usa.news, spout-id:234a78d7-daeb-4826-90e1-1c6540781eac:0}, content='')
+ Message(properties={qpid.subject:usa.faux.news, spout-id:6029430a-cfcb-4700-8e9b-cbe4a81fca5f:0}, content='')
+ </screen>
+ </example>
+
+ </section>
+
+ <section>
+ <title>Address String Options</title>
+
+ <para>
+ The options in an address string can contain additional
+ information for the senders or receivers created for it,
+ including:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ Policies for assertions about the node to which an address
+ refers.
+ </para>
+ <para>
+ For instance, in the address string <literal>my-queue;
+ {assert: always, node:{ type: queue }}</literal>, the node
+ named <literal>my-queue</literal> must be a queue; if not,
+ the address does not resolve to a node, and an exception
+ is raised.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Policies for automatically creating or deleting the node to which an address refers.
+ </para>
+ <para>
+ For instance, in the address string <literal>xoxox ; {create: always}</literal>,
+ the queue <literal>xoxox</literal> is created, if it does
+ not exist, before the address is resolved.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Extension points that can be used for sender/receiver configuration.
+ </para>
+ <para>
+ For instance, if the address for a receiver is
+ <literal>my-queue; {mode: browse}</literal>, the receiver
+ works in <literal>browse</literal> mode, leaving messages
+ on the queue so other receivers can receive them.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Extension points providing more direct control over the underlying protocol.
+ </para>
+ <para>
+ For instance, the <literal>x-bindings</literal> property
+ allows greater control over the AMQP 0-10 binding process
+ when an address is resolved.
+ </para>
+ </listitem>
+ </itemizedlist>
+
+
+ <para>
+ Let's use some examples to show how these different kinds of
+ address string options affect the behavior of senders and
+ receives.
+ </para>
+
+ <section>
+ <title>assert</title>
+ <para>
+ In this section, we use the <literal>assert</literal> option
+ to ensure that the address resolves to a node of the required
+ type.
+ </para>
+
+
+ <example>
+ <title>Assertions on Nodes</title>
+
+ <para>Let's use <command>qpid-config</command> to create a
+ queue and a topic.</para>
+
+ <screen>
+ $ qpid-config add queue my-queue
+ $ qpid-config add exchange topic my-topic
+ </screen>
+
+ <para>
+ We can now use the address specified to drain to assert that it is
+ of a particular type:
+ </para>
+
+ <screen>
+ $ ./drain 'my-queue; {assert: always, node:{ type: queue }}'
+ $ ./drain 'my-queue; {assert: always, node:{ type: topic }}'
+ 2010-04-20 17:30:46 warning Exception received from broker: not-found: not-found: Exchange not found: my-queue (../../src/qpid/broker/ExchangeRegistry.cpp:92) [caused by 2 \x07:\x01]
+ Exchange my-queue does not exist
+ </screen>
+
+ <para>
+ The first attempt passed without error as my-queue is indeed a
+ queue. The second attempt however failed; my-queue is not a
+ topic.
+ </para>
+
+ <para>
+ We can do the same thing for my-topic:
+ </para>
+
+ <screen>
+ $ ./drain 'my-topic; {assert: always, node:{ type: topic }}'
+ $ ./drain 'my-topic; {assert: always, node:{ type: queue }}'
+ 2010-04-20 17:31:01 warning Exception received from broker: not-found: not-found: Queue not found: my-topic (../../src/qpid/broker/SessionAdapter.cpp:754) [caused by 1 \x08:\x01]
+ Queue my-topic does not exist
+ </screen>
+ </example>
+
+ <para>Now let's use the <literal>create</literal> option to
+ create the queue <literal>xoxox</literal> if it does not already
+ exist:</para>
+
+ </section>
+
+ <section>
+ <title>create</title>
+
+ <para>In previous examples, we created the queue before
+ listening for messages on it. Using <literal>create:
+ always</literal>, the queue is automatically created if it
+ does not exist.</para>
+
+ <example>
+ <title>Creating a Queue Automatically</title>
+
+ <para><emphasis>First Window:</emphasis></para>
+ <screen>$ ./drain -t 30 "xoxox ; {create: always}"</screen>
+
+
+ <para>Now we can send messages to this queue:</para>
+
+ <para><emphasis>Second Window:</emphasis></para>
+ <screen>$ ./spout "xoxox ; {create: always}"</screen>
+
+ <para>Returning to the first window, we see that <command>drain</command> has received this message:</para>
+
+ <screen>Message(properties={spout-id:1a1a3842-1a8b-4f88-8940-b4096e615a7d:0}, content='')</screen>
+ </example>
+ <para>The details of the node thus created can be controlled by further options within the node. See <xref linkend="table-node-properties"/> for details.</para>
+ </section>
+
+ <section>
+ <title>browse</title>
+ <para>Some options specify message transfer semantics; for
+ instance, they may state whether messages should be consumed or
+ read in browsing mode, or specify reliability
+ characteristics. The following example uses the
+ <literal>browse</literal> option to receive messages without
+ removing them from a queue.</para>
+
+ <example>
+ <title>Browsing a Queue</title>
+ <para>
+ Let's use the browse mode to receive messages without
+ removing them from the queue. First we send three messages to the
+ queue:
+ </para>
+ <screen>
+ $ ./spout my-queue --content one
+ $ ./spout my-queue --content two
+ $ ./spout my-queue --content three
+ </screen>
+
+ <para>Now we use drain to get those messages, using the browse option:</para>
+ <screen>
+ $ ./drain 'my-queue; {mode: browse}'
+ Message(properties={spout-id:fbb93f30-0e82-4b6d-8c1d-be60eb132530:0}, content='one')
+ Message(properties={spout-id:ab9e7c31-19b0-4455-8976-34abe83edc5f:0}, content='two')
+ Message(properties={spout-id:ea75d64d-ea37-47f9-96a9-d38e01c97925:0}, content='three')
+ </screen>
+
+ <para>We can confirm the messages are still on the queue by repeating the drain:</para>
+ <screen>
+ $ ./drain 'my-queue; {mode: browse}'
+ Message(properties={spout-id:fbb93f30-0e82-4b6d-8c1d-be60eb132530:0}, content='one')
+ Message(properties={spout-id:ab9e7c31-19b0-4455-8976-34abe83edc5f:0}, content='two')
+ Message(properties={spout-id:ea75d64d-ea37-47f9-96a9-d38e01c97925:0}, content='three')
+ </screen>
+ </example>
+ </section>
+
+ <section>
+ <title>x-bindings</title>
+
+ <para>Greater control over the AMQP 0-10 binding process can
+ be achieved by including an <literal>x-bindings</literal>
+ option in an address string.
+
+ For instance, the XML Exchange is an AMQP 0-10 custom exchange
+ provided by the Apache Qpid C++ broker. It allows messages to
+ be filtered using XQuery; queries can address either message
+ properties or XML content in the body of the message. The
+ xquery is specified in the arguments field of the AMQP 0-10
+ command. When using the messaging API an xquery can be
+ specified in and address that resolves to an XML exchange by
+ using the x-bindings property.</para>
+
+
+ <para>An instance of the XML Exchange must be added before it
+ can be used:</para>
+
+ <programlisting>
+ $ qpid-config add exchange xml xml
+ </programlisting>
+
+ <para>When using the XML Exchange, a receiver provides an
+ XQuery as an x-binding argument. If the query contains a
+ context item (a path starting with <quote>.</quote>), then it
+ is applied to the content of the message, which must be
+ well-formed XML. For instance, <literal>./weather</literal> is
+ a valid XQuery, which matches any message in which the root
+ element is named <literal>weather</literal>. Here is an
+ address string that contains this query:</para>
+
+ <programlisting><![CDATA[
+ xml; {
+ link: {
+ x-bindings: [{exchange:xml, key:weather, arguments:{xquery:"./weather"} }]
+ }
+ }
+ ]]></programlisting>
+
+ <para>When using longer queries with <command>drain</command>,
+ it is often useful to place the query in a file, and use
+ <command>cat</command> in the command line. We do this in the
+ following example.</para>
+
+ <example>
+ <title>Using the XML Exchange</title>
+
+ <para>This example uses an x-binding that contains queries, which filter based on the content of XML messages. Here is an XQuery that we will use in this example:</para>
+
+ <programlisting>
+ <![CDATA[
+ let $w := ./weather
+ return $w/station = 'Raleigh-Durham International Airport (KRDU)'
+ and $w/temperature_f > 50
+ and $w/temperature_f - $w/dewpoint > 5
+ and $w/wind_speed_mph > 7
+ and $w/wind_speed_mph < 20 ]]>
+ </programlisting>
+
+ <para>We can specify this query in an x-binding to listen to messages that meet the criteria specified by the query:</para>
+
+ <para><emphasis>First Window:</emphasis></para>
+
+ <screen>
+ $ ./drain -f "xml; {link:{x-bindings:[{key:'weather',
+ arguments:{xquery:\"$(cat rdu.xquery )\"}}]}}"
+ </screen>
+
+ <para>In another window, let's create an XML message that meets the criteria in the query, and place it in the file <filename>rdu.xml</filename>:</para>
+
+ <programlisting>
+ <![CDATA[
+ <weather>
+ <station>Raleigh-Durham International Airport (KRDU)</station>
+ <wind_speed_mph>16</wind_speed_mph>
+ <temperature_f>70</temperature_f>
+ <dewpoint>35</dewpoint>
+ </weather>
+ ]]></programlisting>
+
+ <para>Now let's use <command>spout</command> to send this message to the XML exchange:</para>
+
+ <para><emphasis>Second Window:</emphasis></para>
+ <screen>
+ spout --content "$(cat rdu.xml)" xml/weather
+ </screen>
+
+ <para>Returning to the first window, we see that the message has been received:</para>
+
+ <screen><![CDATA[$ ./drain -f "xml; {link:{x-bindings:[{exchange:'xml', key:'weather', arguments:{xquery:\"$(cat rdu.xquery )\"}}]}}"
+ Message(properties={qpid.subject:weather, spout-id:31c431de-593f-4bec-a3dd-29717bd945d3:0},
+ content='<weather>
+ <station>Raleigh-Durham International Airport (KRDU)</station>
+ <wind_speed_mph>16</wind_speed_mph>
+ <temperature_f>40</temperature_f>
+ <dewpoint>35</dewpoint>
+ </weather>') ]]>
+ </screen>
+ </example>
+ </section>
+
+ <!--
+ <para>When sending data using <command>cat</command> to provide arguments to <command>spout</command>, you can use <command>sed</command> to change the values that are sent:</para>
+
+<screen>
+spout - -content "$(cat rdu.xml | sed -e 's/70/45/')" xml/weather
+</screen>
+ -->
+
+ <!--
+ TODO: Add some reliability option examples
+ -->
+
+ <section>
+ <title>Address String Options - Reference</title>
+
+ <table pgwide="1">
+ <title>Address String Options</title>
+ <tgroup cols="3">
+ <thead>
+ <colspec colnum="1" colwidth="1*"/>
+ <colspec colnum="2" colwidth="3*"/>
+ <colspec colnum="3" colwidth="3*"/>
+ <row>
+ <entry>option</entry>
+ <entry>value</entry>
+ <entry>semantics</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ assert
+ </entry>
+ <entry>
+ one of: always, never, sender or receiver
+ </entry>
+ <entry>
+ Asserts that the properties specified in the node option
+ match whatever the address resolves to. If they do not,
+ resolution fails and an exception is raised. <!-- ###
+ Which exception -->
+ </entry>
+ </row>
+
+ <row>
+ <entry>
+ create
+ </entry>
+ <entry>
+ one of: always, never, sender or receiver
+ </entry>
+ <entry>
+ Creates the node to which an address refers if it does
+ not exist. No error is raised if the node does
+ exist. The details of the node may be specified in the
+ node option.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ delete
+ </entry>
+ <entry>
+ one of: always, never, sender or receiver
+ </entry>
+ <entry>
+ Delete the node when the sender or receiver is closed.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ node
+ </entry>
+ <entry>
+ A nested map containing the entries shown in <xref linkend="table-node-properties"/>.
+ </entry>
+ <entry>
+ Specifies properties of the node to which the address
+ refers. These are used in conjunction with the assert or
+ create options.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ link
+ </entry>
+ <entry>
+ A nested map containing the entries shown in <xref linkend="table-link-properties"/>.
+ </entry>
+ <entry>
+ Used to control the establishment of a conceptual link
+ from the client application to or from the target/source
+ address.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ mode
+ </entry>
+ <entry>
+ one of: browse, consume
+ </entry>
+ <entry>
+ This option is only of relevance for source addresses
+ that resolve to a queue. If browse is specified the
+ messages delivered to the receiver are left on the queue
+ rather than being removed. If consume is specified the
+ normal behaviour applies; messages are removed from the
+ queue once the client acknowledges their receipt.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+
+ <table id="table-node-properties" pgwide="1">
+ <title>Node Properties</title>
+ <tgroup cols="3">
+ <thead>
+ <colspec colnum="1" colwidth="1*"/>
+ <colspec colnum="2" colwidth="3*"/>
+ <colspec colnum="3" colwidth="3*"/>
+ <row>
+ <entry>property</entry>
+ <entry>value</entry>
+ <entry>semantics</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ type
+ </entry>
+ <entry>
+ topic, queue
+ </entry>
+ <entry>
+ Indicates the type of the node.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ durable
+ </entry>
+ <entry>
+ True, False
+ </entry>
+ <entry>
+ Indicates whether the node survives a loss of
+ volatile storage e.g. if the broker is restarted.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ x-declare
+ </entry>
+ <entry>
+ A nested map whose values correspond to the valid fields
+ on an AMQP 0-10 queue-declare or exchange-declare
+ command.
+ </entry>
+ <entry>
+ These values are used to fine tune the creation or
+ assertion process. Note however that they are protocol
+ specific.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ x-bindings
+ </entry>
+ <entry>
+ A nested list in which each binding is represented by
+ a map. The entries of the map for a binding contain
+ the fields that describe an AMQP 0-10 binding. Here is
+ the format for x-bindings:
+
+ <programlisting><![CDATA[
+ [
+ {
+ exchange: <exchange>,
+ queue: <queue>,
+ key: <key>,
+ arguments: {
+ <key_1>: <value_1>,
+ ...,
+ <key_n>: <value_n> }
+ },
+ ...
+ ]
+ ]]></programlisting>
+ </entry>
+ <entry>
+ In conjunction with the create option, each of these
+ bindings is established as the address is resolved. In
+ conjunction with the assert option, the existence of
+ each of these bindings is verified during
+ resolution. Again, these are protocol specific.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table id="table-link-properties" pgwide="1">
+ <title>Link Properties</title>
+ <tgroup cols="3">
+ <thead>
+ <colspec colnum="1" colwidth="1*"/>
+ <colspec colnum="2" colwidth="3*"/>
+ <colspec colnum="3" colwidth="3*"/>
+ <row>
+ <entry>option</entry>
+ <entry>value</entry>
+ <entry>semantics</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ reliability
+ </entry>
+ <entry>
+ one of: unreliable, at-least-once, at-most-once, exactly-once
+ </entry>
+ <entry>
+ Reliability indicates the level of reliability that
+ the sender or receiver. <literal>unreliable</literal>
+ and <literal>at-most-once</literal> are currently
+ treated as synonyms, and allow messages to be lost if
+ a broker crashes or the connection to a broker is
+ lost. <literal>at-least-once</literal> guarantees that
+ a message is not lost, but duplicates may be
+ received. <literal>exactly-once</literal> guarantees
+ that a message is not lost, and is delivered precisely
+ once. Currently only <literal>unreliable</literal>
+ and <literal>at-least-once</literal> are supported.
+ <footnote><para>If at-most-once is requested,
+ unreliable will be used and for durable messages on
+ durable queues there is the possibility that messages
+ will be redelivered; if exactly-once is requested,
+ at-least-once will be used and the application needs to
+ be able to deal with duplicates.</para></footnote>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ durable
+ </entry>
+ <entry>
+ True, False
+ </entry>
+ <entry>
+ Indicates whether the link survives a loss of
+ volatile storage e.g. if the broker is restarted.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ x-declare
+ </entry>
+ <entry>
+ A nested map whose values correspond to the valid fields
+ of an AMQP 0-10 queue-declare command.
+ </entry>
+ <entry>
+ These values can be used to customise the subscription
+ queue in the case of receiving from an exchange. Note
+ however that they are protocol specific.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ x-subscribe
+ </entry>
+ <entry>
+ A nested map whose values correspond to the valid fields
+ of an AMQP 0-10 message-subscribe command.
+ </entry>
+ <entry>
+ These values can be used to customise the subscription.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ x-bindings
+ </entry>
+ <entry>
+ A nested list each of whose entries is a map that may
+ contain fields (queue, exchange, key and arguments)
+ describing an AMQP 0-10 binding.
+ </entry>
+ <entry>
+ These bindings are established during resolution
+ independent of the create option. They are considered
+ logically part of the linking process rather than of
+ node creation.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ </section>
+ </section>
+
+ <section id="section-address-string-bnf">
+ <title>Address String Grammar</title>
+
+ <para>This section provides a formal grammar for address strings.</para>
+
+ <formalpara>
+ <title>Tokens</title>
+ <para>The following regular expressions define the tokens used
+ to parse address strings:</para></formalpara>
+ <programlisting><![CDATA[
+ LBRACE: \\{
+ RBRACE: \\}
+ LBRACK: \\[
+ RBRACK: \\]
+ COLON: :
+ SEMI: ;
+ SLASH: /
+ COMMA: ,
+ NUMBER: [+-]?[0-9]*\\.?[0-9]+
+ ID: [a-zA-Z_](?:[a-zA-Z0-9_-]*[a-zA-Z0-9_])?
+ STRING: "(?:[^\\\\"]|\\\\.)*"|\'(?:[^\\\\\']|\\\\.)*\'
+ 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]
+ SYM: [.#*%@$^!+-]
+ WSPACE: [ \\n\\r\\t]+
+ ]]></programlisting>
+
+ <formalpara>
+ <title>Grammar</title>
+ <para>The formal grammar for addresses is given below:</para>
+ </formalpara>
+
+ <programlisting><![CDATA[
+ address := name [ SLASH subject ] [ ";" options ]
+ name := ( part | quoted )+
+ subject := ( part | quoted | SLASH )*
+ quoted := STRING / ESC
+ part := LBRACE / RBRACE / COLON / COMMA / NUMBER / ID / SYM
+ options := map
+ map := "{" ( keyval ( "," keyval )* )? "}"
+ keyval "= ID ":" value
+ value := NUMBER / STRING / ID / map / list
+ list := "[" ( value ( "," value )* )? "]"
+ ]]></programlisting>
+
+
+ <formalpara>
+ <title>Address String Options</title>
+ <para>The address string options map supports the following parameters:</para>
+ </formalpara>
+
+ <programlisting><![CDATA[
+ <name> [ / <subject> ] ; {
+ create: always | sender | receiver | never,
+ delete: always | sender | receiver | never,
+ assert: always | sender | receiver | never,
+ mode: browse | consume,
+ node: {
+ type: queue | topic,
+ durable: True | False,
+ x-declare: { ... <declare-overrides> ... },
+ x-bindings: [<binding_1>, ... <binding_n>]
+ },
+ link: {
+ name: <link-name>,
+ durable: True | False,
+ reliability: unreliable | at-most-once | at-least-once | exactly-once,
+ x-declare: { ... <declare-overrides> ... },
+ x-bindings: [<binding_1>, ... <binding_n>],
+ x-subscribe: { ... <subscribe-overrides> ... }
+ }
+ }
+ ]]></programlisting>
+
+
+ <itemizedlist>
+ <title>Create, Delete, and Assert Policies</title>
+ <para>The create, delete, and assert policies specify who should
+ perfom the associated action:</para>
+ <listitem><para><emphasis>always</emphasis>: the action is performed by any messaging client</para></listitem>
+ <listitem><para><emphasis>sender</emphasis>: the action is only performed by a sender</para></listitem>
+ <listitem><para><emphasis>receiver</emphasis>: the action is only performed by a receiver</para></listitem>
+ <listitem><para><emphasis>never</emphasis>: the action is never performed (this is the default)</para></listitem>
+ </itemizedlist>
+
+ <itemizedlist>
+ <title>Node-Type</title>
+ <para>The node-type is one of:</para>
+ <listitem><para><emphasis>topic</emphasis>: in the AMQP 0-10
+ mapping, a topic node defaults to the topic exchange, x-declare
+ may be used to specify other exchange types</para></listitem>
+ <listitem><para><emphasis>queue</emphasis>: this is the default node-type</para></listitem>
+ </itemizedlist>
+ </section>
+
+
+ </section>
+
+ <section id="replay">
+ <title>Sender Capacity and Replay</title>
+
+ <para>The send method of a sender has an optional second parameter
+ that controls whether the send call is synchronous or not. A
+ synchronous send call will block until the broker has confirmed
+ receipt of the message. An asynchronous send call will return
+ before the broker confirms receipt of the message, allowing for
+ example further send calls to be made without waiting for a
+ roundtrip to the broker for each message. This is desirable where
+ increased throughput is important.</para>
+
+ <para>The sender maintains a list of sent messages whose receipt
+ has yet to be confirmed by the broker. The maximum number of such
+ messages that it will hold is defined by the capacity of the
+ sender, which can be set by the application. If an application
+ tries to send with a sender whose capacity is already fully used
+ up, the send call will block waiting for capacity regardless of
+ the value of the sync flag.</para>
+
+ <para>The sender can be queried for the available space (i.e. the
+ unused capacity), and for the current count of unsettled messages
+ (i.e. those held in the replay list pending confirmation by the
+ server). When the unsettled count is zero, all messages on that
+ sender have been successfully sent.</para>
+
+ <para>If the connection fails and is transparently reconnected
+ (see <xref linkend="connection-options"/> for details on how to control
+ this feature), the unsettled messages for each sender over that
+ connection will be re-transmitted. This provides a transparent
+ level of reliability. This feature can be controlled through the
+ link's reliability as defined in the address (see
+ <xref linkend="table-link-properties"/>). At present only
+ at-least-once guarantees are offered. </para>
+ </section>
+
+ <section id="prefetch">
+ <title>Receiver Capacity (Prefetch)</title>
+
+ <para>By default, a receiver requests the next message from the
+ server in response to each fetch call, resulting in messages being
+ sent to the receiver one at a time. As in the case of sending, it
+ is often desirable to avoid this roundtrip for each message. This
+ can be achieved by allowing the receiver
+ to <firstterm>prefetch</firstterm> messages in anticipation of
+ fetch calls being made. The receiver needs to be able to store
+ these prefetched messages, the number it can hold is controlled by
+ the receivers capacity.</para>
+
+ </section>
+
+ <section id="acknowledgements">
+ <title>Acknowledging Received Messages</title>
+
+ <para>Applications that receive messages should acknowledge their
+ receipt by calling the session's acknowledge method. As in the
+ case of sending messages, acknowledged transfer of messages to
+ receivers provides at-least-once reliability, which means that the
+ loss of the connection or a client crash does not result in lost
+ messages; durable messages are not lost even if the broker is
+ restarted.
+
+ Some cases may not require this however and the reliability can be
+ controlled through a link property in the address options (see
+ <xref linkend="table-link-properties"/>).</para>
+
+ <para>The acknowledge call acknowledges all messages received on
+ the session (i.e. all message that have been returned from a fetch
+ call on a receiver created on that session).</para>
+
+ <para>The acknowledge call also support an optional parameter
+ controlling whether the call is synchronous or not. A synchronous
+ acknowledge will block until the server has confirmed that it has
+ received the acknowledgement. In the asynchronous case, when the
+ call returns there is not yet any guarantee that the server has
+ received and processed the acknowledgement. The session may be
+ queried for the number of unsettled acknowledgements; when that
+ count is zero all acknowledgements made for received messages have
+ been successful.</para>
+
+ </section>
+
+
+ <section>
+ <title>Receiving Messages from Multiple Sources</title>
+
+ <para>A receiver can only read from one source, but many
+ programs need to be able to read messages from many sources. In
+ the Qpid Messaging API, a program can ask a session for
+ the <quote>next receiver</quote>; that is, the receiver that is
+ responsible for the next available message. The following
+ examples show how this is done in C++, Python, and .NET C#.
+ </para>
+
+ <para>Note that to use this pattern you must enable prefetching
+ for each receiver of interest so that the broker will send
+ messages before a fetch call is made. See
+ <xref linkend="prefetch"/> for more on this.</para>
+
+ <example>
+ <title>Receiving Messages from Multiple Sources</title>
+
+ <para>C++:</para>
+
+ <programlisting><![CDATA[
+ Receiver receiver1 = session.createReceiver(address1);
+ receiver1.setCapacity(10);
+ Receiver receiver2 = session.createReceiver(address2);
+ receiver2.setCapacity(10);
+
+ Message message = session.nextReceiver().fetch();
+ std::cout << message.getContent() << std::endl;
+ session.acknowledge(); // acknowledge message receipt
+ ]]> </programlisting>
+
+ <para>Python:</para>
+ <programlisting><![CDATA[
+ receiver1 = session.receiver(address1)
+ receiver1.capacity = 10
+ receiver2 = session.receiver(address)
+ receiver2.capacity = 10
+ message = session.next_receiver().fetch()
+ print message.content
+ session.acknowledge()
+ ]]> </programlisting>
+
+ <para>.NET C#:</para>
+ <programlisting><![CDATA[
+ Receiver receiver1 = session.CreateReceiver(address1);
+ receiver1.Capacity = 10;
+ Receiver receiver2 = session.CreateReceiver(address2);
+ receiver2.Capacity = 10;
+
+ Message message = new Message();
+ message = session.NextReceiver().Fetch();
+ Console.WriteLine("{0}", message.GetContent());
+ session.Acknowledge();
+ ]]> </programlisting>
+
+ </example>
+ </section>
+
+ <section>
+ <title>Transactions</title>
+
+ <para>Sometimes it is useful to be able to group messages
+ transfers - sent and/or received - on a session into atomic
+ grouping. This can be done be creating the session as
+ transactional. On a transactional session sent messages only
+ become available at the target address on commit. Likewise any
+ received and acknowledged messages are only discarded at their
+ source on commit
+
+ <footnote><para>Note that this currently is only true for
+ messages received using a reliable mode
+ e.g. at-least-once. Messages sent by a broker to a receiver in
+ unreliable receiver will be discarded immediately regardless of
+ transctionality.</para></footnote>
+
+ .</para>
+
+ <example>
+ <title>Transactions</title>
+ <para>C++:</para>
+ <programlisting><![CDATA[
+ Connection connection(broker);
+ Session session = connection.createTransactionalSession();
+ ...
+ if (smellsOk())
+ session.commit();
+ else
+ session.rollback();
+ ]]></programlisting>
+ <para>
+ .NET C#:
+ </para>
+
+ <programlisting>
+ Connection connection = new Connection(broker);
+ Session session = connection.CreateTransactionalSession();
+ ...
+ if (smellsOk())
+ session.Commit();
+ else
+ session.Rollback();
+ </programlisting>
+ <!--
+ <para>Python</para>
+ <programlisting><![CDATA[
+ ### TODO
+ ]]></programlisting>
+ -->
+ </example>
+
+ </section>
+
+ <section id="connection-options">
+ <title>Connection Options</title>
+
+ <para>
+ Aspects of the connections behaviour can be controlled through
+ specifying connection options. For example, connections can be
+ configured to automatically reconnect if the connection to a
+ broker is lost.
+ </para>
+
+ <example>
+ <title>Specifying Connection Options in C++, Python, and .NET</title>
+
+ <para>In C++, these options can be set using <function>Connection::setOption()</function> or by passing in a set of options to the constructor. The options can be passed in as a map or in string form:</para>
+
+ <programlisting><![CDATA[
+ Connection connection("localhost:5672", "{reconnect: true}");
+ try {
+ connection.open();
+ !!! SNIP !!!
+ ]]></programlisting>
+
+ <para>or</para>
+
+ <programlisting><![CDATA[
+ Connection connection("localhost:5672");
+ connection.setOption("reconnect", true);
+ try {
+ connection.open();
+ !!! SNIP !!!
+ ]]></programlisting>
+
+ <para>In Python, these options can be set as attributes of the connection or using named arguments in
+ the <function>Connection</function> constructor:</para>
+
+ <programlisting><![CDATA[
+ connection = Connection("localhost:5672", reconnect=True)
+ try:
+ connection.open()
+ !!! SNIP !!!
+ ]]></programlisting>
+
+ <para>or</para>
+
+ <programlisting><![CDATA[
+ connection = Connection("localhost:5672")
+ connection.reconnect = True
+ try:
+ connection.open()
+ !!! SNIP !!!
+ ]]></programlisting>
+ <para>
+ In .NET, these options can be set using <function>Connection.SetOption()</function> or by passing in a set of options to the constructor. The options can be passed in as a map or in string form:
+ </para>
+
+ <programlisting>
+ Connection connection= new Connection(&#34;localhost:5672&#34;, &#34;{reconnect: true}&#34;);
+ try {
+ connection.Open();
+ !!! SNIP !!!
+ </programlisting>
+ <para>
+ or
+ </para>
+
+ <programlisting>
+ Connection connection = new Connection(&#34;localhost:5672&#34;);
+ connection.SetOption(&#34;reconnect&#34;, true);
+ try {
+ connection.Open();
+ !!! SNIP !!!
+ </programlisting>
+
+ <para>See the reference documentation for details in each language.</para>
+ </example>
+
+ <para>The following table lists the supported connection options.</para>
+
+ <table pgwide="1">
+ <title>Connection Options</title>
+ <tgroup cols="3">
+ <thead>
+ <colspec colnum="1" colwidth="1*"/>
+ <colspec colnum="2" colwidth="1*"/>
+ <colspec colnum="3" colwidth="3*"/>
+ <row>
+ <entry>option name</entry>
+ <entry>value type</entry>
+ <entry>semantics</entry>
+ </row>
+ </thead>
+ <tbody>
+
+ <row>
+ <entry>
+ <literal>username</literal>
+ </entry>
+ <entry>
+ string
+ </entry>
+ <entry>
+ The username to use when authenticating to the broker.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>password</literal>
+ </entry>
+ <entry>
+ string
+ </entry>
+ <entry>
+ The password to use when authenticating to the broker.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>sasl_mechanisms</literal>
+ </entry>
+ <entry>
+ string
+ </entry>
+ <entry>
+ The specific SASL mechanisms to use with the python
+ client when authenticating to the broker. The value
+ is a space separated list.
+ </entry>
+ </row>
+
+
+ <row>
+ <entry>
+ <literal>reconnect</literal>
+ </entry>
+ <entry>
+ boolean
+ </entry>
+ <entry>
+ Transparently reconnect if the connection is lost.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>reconnect_timeout</literal>
+ </entry>
+ <entry>
+ integer
+ </entry>
+ <entry>
+ Total number of seconds to continue reconnection attempts before giving up and raising an exception.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>reconnect_limit</literal>
+ </entry>
+ <entry>
+ integer
+ </entry>
+ <entry>
+ Maximum number of reconnection attempts before giving up and raising an exception.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>reconnect_interval_min</literal>
+ </entry>
+ <entry>
+ integer representing time in seconds
+ </entry>
+ <entry>
+ 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 <literal>reconnect_interval_min</literal>; if that attempt fails, the reconnect interval increases exponentially until a reconnection attempt succeeds or <literal>reconnect_interval_max</literal> is reached.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>reconnect_interval_max</literal>
+ </entry>
+ <entry>
+ integer representing time in seconds
+ </entry>
+ <entry>
+ Maximum reconnect interval.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>reconnect_interval</literal>
+ </entry>
+ <entry>
+ integer representing time in seconds
+ </entry>
+ <entry>
+ Sets both <literal>reconnection_interval_min</literal> and <literal>reconnection_interval_max</literal> to the same value.
+ </entry>
+ </row>
+
+ <row>
+ <entry>
+ <literal>heartbeat</literal>
+ </entry>
+ <entry>
+ integer representing time in seconds
+ </entry>
+ <entry>
+ Requests that heartbeats be sent every N seconds. If two
+ successive heartbeats are missed the connection is
+ considered to be lost.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>protocol</literal>
+ </entry>
+ <entry>
+ string
+ </entry>
+ <entry>
+ Sets the underlying protocol used. The default option is 'tcp'. To enable ssl, set to 'ssl'. The C++ client additionally supports 'rdma'.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <literal>tcp-nodelay</literal>
+ </entry>
+ <entry>
+ boolean
+ </entry>
+ <entry>
+ Set tcp no-delay, i.e. disable Nagle algorithm. [C++ only]
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ </section>
+
+ <section id="section-Maps">
+ <title>Maps and Lists in Message Content</title>
+
+ <para>Many messaging applications need to exchange data across
+ languages and platforms, using the native datatypes of each
+ programming language.</para>
+
+ <para>The Qpid Messaging API supports <classname>map</classname> and <classname>list</classname> in message content.
+
+ <footnote><para>Unlike JMS, there is not a specific message type for
+ map messages.</para></footnote>
+
+ <footnote>
+ <para>
+ Note that the Qpid JMS client supports MapMessages whose values can be nested maps or lists. This is not standard JMS behaviour.
+ </para>
+ </footnote>
+ Specific language support for <classname>map</classname> and <classname>list</classname> objects are shown in the following table.
+ </para>
+ <table id="tabl-Programming_in_Apache_Qpid-Qpid_Maps_in_Message_Content">
+ <title>Map and List Representation in Supported Languages</title>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Language</entry>
+ <entry>map</entry>
+ <entry>list</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>Python</entry>
+ <entry><classname>dict</classname></entry>
+ <entry><classname>list</classname></entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry><classname>Variant::Map</classname></entry>
+ <entry><classname>Variant::List</classname></entry>
+ </row>
+ <row>
+ <entry>Java</entry>
+ <entry><classname>MapMessage</classname></entry>
+ <entry><classname>&nbsp;</classname></entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry><classname>Dictionary&#60;string, object&#62;</classname></entry>
+ <entry><classname>Collection&#60;object&#62;</classname></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <para>
+ In all languages, messages are encoded using AMQP&#39;s portable datatypes.
+ </para>
+
+ <tip>
+ <para>Because of the differences in type systems among
+ languages, the simplest way to provide portable messages is to
+ rely on maps, lists, strings, 64 bit signed integers, and
+ doubles for messages that need to be exchanged across languages
+ and platforms.</para>
+ </tip>
+
+ <section id="section-Python-Maps">
+ <title>Qpid Maps and Lists in Python</title>
+
+ <para>In Python, Qpid supports the <classname>dict</classname> and <classname>list</classname> types directly in message content. The following code shows how to send these structures in a message:</para>
+
+ <example>
+ <title>Sending Qpid Maps and Lists in Python</title>
+ <programlisting><![CDATA[
+ from qpid.messaging import *
+ # !!! SNIP !!!
+
+ content = {'Id' : 987654321, 'name' : 'Widget', 'percent' : 0.99}
+ content['colours'] = ['red', 'green', 'white']
+ content['dimensions'] = {'length' : 10.2, 'width' : 5.1,'depth' : 2.0};
+ content['parts'] = [ [1,2,5], [8,2,5] ]
+ content['specs'] = {'colors' : content['colours'],
+ 'dimensions' : content['dimensions'],
+ 'parts' : content['parts'] }
+ message = Message(content=content)
+ sender.send(message)
+ ]]> </programlisting>
+ </example>
+
+
+ <para>The following table shows the datatypes that can be sent in a Python map message,
+ and the corresponding datatypes that will be received by clients in Java or C++.</para>
+
+
+ <table id="table-Python-Maps" >
+ <title>Python Datatypes in Maps</title>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Python Datatype</entry>
+ <entry>&rarr; C++</entry>
+ <entry>&rarr; Java</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row><entry>bool</entry><entry>bool</entry><entry>boolean</entry></row>
+ <row><entry>int</entry><entry>int64</entry><entry>long</entry></row>
+ <row><entry>long</entry><entry>int64</entry><entry>long</entry></row>
+ <row><entry>float</entry><entry>double</entry><entry>double</entry></row>
+ <row><entry>unicode</entry><entry>string</entry><entry>java.lang.String</entry></row>
+ <row><entry>uuid</entry><entry>qpid::types::Uuid</entry><entry>java.util.UUID</entry></row>
+ <row><entry>dict</entry><entry>Variant::Map</entry><entry>java.util.Map</entry></row>
+ <row><entry>list</entry><entry>Variant::List</entry><entry>java.util.List</entry></row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ </section>
+
+
+
+
+ <section id="section-cpp-Maps">
+ <title>Qpid Maps and Lists in C++</title>
+
+
+ <para>In C++, Qpid defines the the
+ <classname>Variant::Map</classname> and
+ <classname>Variant::List</classname> types, which can be
+ encoded into message content. The following code shows how to
+ send these structures in a message:</para>
+
+ <example>
+ <title>Sending Qpid Maps and Lists in C++</title>
+ <programlisting><![CDATA[
+ using namespace qpid::types;
+
+ // !!! SNIP !!!
+
+ Message message;
+ Variant::Map content;
+ content["id"] = 987654321;
+ content["name"] = "Widget";
+ content["percent"] = 0.99;
+ Variant::List colours;
+ colours.push_back(Variant("red"));
+ colours.push_back(Variant("green"));
+ colours.push_back(Variant("white"));
+ content["colours"] = colours;
+
+ Variant::Map dimensions;
+ dimensions["length"] = 10.2;
+ dimensions["width"] = 5.1;
+ dimensions["depth"] = 2.0;
+ content["dimensions"]= dimensions;
+
+ Variant::List part1;
+ part1.push_back(Variant(1));
+ part1.push_back(Variant(2));
+ part1.push_back(Variant(5));
+
+ Variant::List part2;
+ part2.push_back(Variant(8));
+ part2.push_back(Variant(2));
+ part2.push_back(Variant(5));
+
+ Variant::List parts;
+ parts.push_back(part1);
+ parts.push_back(part2);
+ content["parts"]= parts;
+
+ Variant::Map specs;
+ specs["colours"] = colours;
+ specs["dimensions"] = dimensions;
+ specs["parts"] = parts;
+ content["specs"] = specs;
+
+ encode(content, message);
+ sender.send(message, true);
+ ]]> </programlisting>
+ </example>
+
+ <para>The following table shows the datatypes that can be sent
+ in a C++ map message, and the corresponding datatypes that
+ will be received by clients in Java and Python.</para>
+
+ <table id="table-cpp-Maps">
+ <title>C++ Datatypes in Maps</title>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>C++ Datatype</entry>
+ <entry>&rarr; Python</entry>
+ <entry>&rarr; Java</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row><entry>bool</entry><entry>bool</entry><entry>boolean</entry></row>
+ <row><entry>uint16</entry><entry>int | long</entry><entry>short</entry></row>
+ <row><entry>uint32</entry><entry>int | long</entry><entry>int</entry></row>
+ <row><entry>uint64</entry><entry>int | long</entry><entry>long</entry></row>
+ <row><entry>int16</entry><entry>int | long</entry><entry>short</entry></row>
+ <row><entry>int32</entry><entry>int | long</entry><entry>int</entry></row>
+ <row><entry>int64</entry><entry>int | long</entry><entry>long</entry></row>
+ <row><entry>float</entry><entry>float</entry><entry>float</entry></row>
+ <row><entry>double</entry><entry>float</entry><entry>double</entry></row>
+ <row><entry>string</entry><entry>unicode</entry><entry>java.lang.String</entry></row>
+ <row><entry>qpid::types::Uuid</entry><entry>uuid</entry><entry>java.util.UUID</entry></row>
+ <row><entry>Variant::Map</entry><entry>dict</entry><entry>java.util.Map</entry></row>
+ <row><entry>Variant::List</entry><entry>list</entry><entry>java.util.List</entry></row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+
+ <section id="section-dotnet-Maps">
+ <title>Qpid Maps and Lists in .NET</title>
+
+
+ <para>
+ The .NET binding for the Qpid Messaging API binds .NET managed data types
+ to C++ <classname>Variant</classname> data types. The following code shows how to
+ send Map and List structures in a message:
+ </para>
+
+ <example>
+ <?dbfo keep-together="auto" ?>
+ <title>Sending Qpid Maps and Lists in .NET C#</title>
+ <programlisting><![CDATA[
+ using System;
+ using Org.Apache.Qpid.Messaging;
+
+ // !!! SNIP !!!
+
+ Dictionary<string, object> content = new Dictionary<string, object>();
+ Dictionary<string, object> subMap = new Dictionary<string, object>();
+ Collection<object> colors = new Collection<object>();
+
+ // add simple types
+ content["id"] = 987654321;
+ content["name"] = "Widget";
+ content["percent"] = 0.99;
+
+ // add nested amqp/map
+ subMap["name"] = "Smith";
+ subMap["number"] = 354;
+ content["nestedMap"] = subMap;
+
+ // add an amqp/list
+ colors.Add("red");
+ colors.Add("green");
+ colors.Add("white");
+ content["colorsList"] = colors;
+
+ // add one of each supported amqp data type
+ bool mybool = true;
+ content["mybool"] = mybool;
+
+ byte mybyte = 4;
+ content["mybyte"] = mybyte;
+
+ UInt16 myUInt16 = 5;
+ content["myUInt16"] = myUInt16;
+
+ UInt32 myUInt32 = 6;
+ content["myUInt32"] = myUInt32;
+
+ UInt64 myUInt64 = 7;
+ content["myUInt64"] = myUInt64;
+
+ char mychar = 'h';
+ content["mychar"] = mychar;
+
+ Int16 myInt16 = 9;
+ content["myInt16"] = myInt16;
+
+ Int32 myInt32 = 10;
+ content["myInt32"] = myInt32;
+
+ Int64 myInt64 = 11;
+ content["myInt64"] = myInt64;
+
+ Single mySingle = (Single)12.12;
+ content["mySingle"] = mySingle;
+
+ Double myDouble = 13.13;
+ content["myDouble"] = myDouble;
+
+ Guid myGuid = new Guid("000102030405060708090a0b0c0d0e0f");
+ content["myGuid"] = myGuid;
+
+ Message message = new Message(content);
+ Send(message, true);
+ ]]> </programlisting>
+ </example>
+
+ <para>
+ The following table shows the mapping between datatypes in .NET and C++.
+ </para>
+
+ <table id="table-dotnet-Maps">
+ <title>Datatype Mapping between C++ and .NET binding</title>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>C++ Datatype</entry>
+ <entry>&rarr; .NET binding</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row><entry>void</entry><entry>nullptr</entry></row>
+ <row><entry>bool</entry><entry>bool</entry></row>
+ <row><entry>uint8</entry><entry>byte</entry></row>
+ <row><entry>uint16</entry><entry>UInt16</entry></row>
+ <row><entry>uint32</entry><entry>UInt32</entry></row>
+ <row><entry>uint64</entry><entry>UInt64</entry></row>
+ <row><entry>uint8</entry><entry>char</entry></row>
+ <row><entry>int16</entry><entry>Int16</entry></row>
+ <row><entry>int32</entry><entry>Int32</entry></row>
+ <row><entry>int64</entry><entry>Int64</entry></row>
+ <row><entry>float</entry><entry>Single</entry></row>
+ <row><entry>double</entry><entry>Double</entry></row>
+ <row><entry>string</entry><entry>string
+ <footnote id="callout-dotnet-string">
+ <para>Strings are currently interpreted only with UTF-8 encoding.</para>
+ </footnote></entry></row>
+ <row><entry>qpid::types::Uuid</entry><entry>Guid</entry></row>
+ <row><entry>Variant::Map</entry><entry><![CDATA[Dictionary<string, object>]]>
+ <footnoteref linkend="callout-dotnet-string"/></entry></row>
+ <row><entry>Variant::List</entry><entry><![CDATA[Collection<object>]]>
+ <footnoteref linkend="callout-dotnet-string"/></entry></row>
+ </tbody>
+ </tgroup>
+ </table>
+
+
+ </section>
+
+
+ </section>
+
+ <section>
+ <title>The Request / Response Pattern</title>
+ <para>Request / Response applications use the reply-to property,
+ described in <xref
+ linkend="table-amqp0-10-message-properties"/>, to allow a server
+ to respond to the client that sent a message. A server sets up a
+ service queue, with a name known to clients. A client creates a
+ private queue for the server's response, creates a message for a
+ request, sets the request's reply-to property to the address of
+ the client's response queue, and sends the request to the
+ service queue. The server sends the response to the address
+ specified in the request's reply-to property.
+ </para>
+ <example>
+ <title>Request / Response Applications in C++</title>
+
+ <para>This example shows the C++ code for a client and server
+ that use the request / response pattern.</para>
+
+ <para>The server creates a service queue and waits for a
+ message to arrive. If it receives a message, it sends a
+ message back to the sender.</para>
+
+ <programlisting><![CDATA[Receiver receiver = session.createReceiver("service_queue; {create: always}");
+
+ Message request = receiver.fetch();
+ const Address&amp; address = request.getReplyTo(); // Get "reply-to" from request ...
+ if (address) {
+ Sender sender = session.createSender(address); // ... send response to "reply-to"
+ Message response("pong!");
+ sender.send(response);
+ session.acknowledge();
+ }
+ ]]></programlisting>
+
+ <para>The client creates a sender for the service queue, and
+ also creates a response queue that is deleted when the
+ client closes the receiver for the response queue. In the C++
+ client, if the address starts with the character
+ <literal>#</literal>, it is given a unique name.</para>
+
+ <programlisting><![CDATA[
+ Sender sender = session.createSender("service_queue");
+
+ Address responseQueue("#response-queue; {create:always, delete:always}");
+ Receiver receiver = session.createReceiver(responseQueue);
+
+ Message request;
+ request.setReplyTo(responseQueue);
+ request.setContent("ping");
+ sender.send(request);
+ Message response = receiver.fetch();
+ std::cout << request.getContent() << " -> " << response.getContent() << std::endl;
+ ]]> </programlisting>
+
+ <para>The client sends the string <literal>ping</literal> to
+ the server. The server sends the response
+ <literal>pong</literal> back to the same client, using the
+ <varname>replyTo</varname> property.</para>
+
+ </example>
+ <!--
+ <example>
+ <title>Request / Response Applications in Python</title>
+ <programlisting>### TODO</programlisting>
+ </example>
+ -->
+ </section>
+
+
+ <section>
+ <title>Performance Tips</title>
+
+ <itemizedlist>
+ <listitem>
+ <para>Consider prefetching messages for receivers (see
+ <xref linkend="prefetch"/>). This helps eliminate roundtrips
+ and increases throughput. Prefetch is disabled by default,
+ and enabling it is the most effective means of improving
+ throughput of received messages.</para>
+ </listitem>
+ <listitem>
+ <para>Send messages asynchronously. Again, this helps
+ eliminate roundtrips and increases throughput. The C++ and
+ .NET clients send asynchronously by default, however the
+ python client defaults to synchronous sends. </para>
+ </listitem>
+ <listitem>
+ <para>Acknowledge messages in batches (see
+ <xref linkend="acknowledgements"/>). Rather than
+ acknowledging each message individually, consider issuing
+ acknowledgements after n messages and/or after a particular
+ duration has elapsed.</para>
+ </listitem>
+ <listitem>
+ <para>Tune the sender capacity (see
+ <xref linkend="replay"/>). If the capacity is too low the
+ sender may block waiting for the broker to confirm receipt
+ of messages, before it can free up more capacity.</para>
+ </listitem>
+ <listitem>
+ <para>If you are setting a reply-to address on messages
+ being sent by the c++ client, make sure the address type is
+ set to either queue or topic as appropriate. This avoids the
+ client having to determine which type of node is being
+ refered to, which is required when hanling reply-to in AMQP
+ 0-10. </para>
+ </listitem>
+ <listitem>
+ <para>For latency sensitive applications, setting tcp-nodelay
+ on qpidd and on client connections can help reduce the
+ latency.</para>
+ </listitem>
+ </itemizedlist>
+ </section>
+
+ <section>
+ <title>Cluster Failover</title>
+
+ <para>The messaging broker can be run in clustering mode, which provides high reliability through replicating state between brokers in the cluster. If one broker in a cluster fails, clients can choose another broker in the cluster and continue their work. Each broker in the cluster also advertises the addresses of all known brokers
+
+ <footnote><para>This is done via the amq.failover exchange in AMQP 0-10</para></footnote>
+
+ . A client can use this information to dynamically keep the list of reconnection urls up to date.</para>
+
+ <para>In C++, the <classname>FailoverUpdates</classname> class provides this functionality:</para>
+
+ <example>
+ <title>Tracking cluster membership</title>
+
+ <para>In C++:</para>
+
+ <programlisting><![CDATA[
+ #include <qpid/messaging/FailoverUpdates.h>
+ ...
+ Connection connection("localhost:5672");
+ connection.setOption("reconnect", true);
+ try {
+ connection.open();
+ std::auto_ptr<FailoverUpdates> updates(new FailoverUpdates(connection));
+ ]]>
+ </programlisting>
+
+ <para>In python:</para>
+
+ <programlisting><![CDATA[
+ import qpid.messaging.util
+ ...
+ connection = Connection("localhost:5672")
+ connection.reconnect = True
+ try:
+ connection.open()
+ auto_fetch_reconnect_urls(connection)
+ ]]>
+ </programlisting>
+ <para>
+ In .NET C#:
+ </para>
+
+ <programlisting>
+ using Org.Apache.Qpid.Messaging;
+ ...
+ connection = new Connection(&#34;localhost:5672&#34;);
+ connection.SetOption("reconnect", true);
+ try {
+ connection.Open();
+ FailoverUpdates failover = new FailoverUpdates(connection);
+
+ </programlisting>
+
+
+ </example>
+ </section>
+
+
+
+ <section>
+ <title>Logging</title>
+
+ <para>To simplify debugging, Qpid provides a logging facility
+ that prints out messaging events.</para>
+
+ <section>
+ <title>Logging in C++</title>
+ <para>
+ The Qpidd broker and C++ clients can both use environment variables to enable logging. Linux and Windows systems use the same named environment variables and values.
+ </para>
+ <para>Use QPID_LOG_ENABLE to set the level of logging you are interested in (trace, debug, info, notice, warning, error, or critical):
+ </para>
+
+ <screen>
+ export QPID_LOG_ENABLE=&#34;warning+&#34;
+ </screen>
+ <para>
+ The Qpidd broker and C++ clients use QPID_LOG_OUTPUT to determine where logging output should be sent. This is either a file name or the special values stderr, stdout, or syslog:
+ </para>
+
+ <screen>
+ export QPID_LOG_TO_FILE=&#34;/tmp/myclient.out&#34;
+ </screen>
+
+ <para>
+ From a Windows command prompt, use the following command format to set the environment variables:
+ </para>
+
+ <screen>
+ set QPID_LOG_ENABLE=warning+
+ set QPID_LOG_TO_FILE=D:\tmp\myclient.out
+ </screen>
+ </section>
+
+ <section>
+ <title>Logging in Python</title>
+ <para>
+ The Python client library supports logging using the standard Python logging module. The easiest way to do logging is to use the <command>basicConfig()</command>, which reports all warnings and errors:
+ </para>
+
+ <programlisting>from logging import basicConfig
+ basicConfig()
+ </programlisting>
+ <para>
+ Qpidd also provides a convenience method that makes it easy to specify the level of logging desired. For instance, the following code enables logging at the <command>DEBUG</command> level:
+ </para>
+
+ <programlisting>from qpid.log import enable, DEBUG
+ enable("qpid.messaging.io", DEBUG)
+ </programlisting>
+ <para>
+ For more information on Python logging, see <ulink url="http://docs.python.org/lib/node425.html">http://docs.python.org/lib/node425.html</ulink>. For more information on Qpid logging, use <command>$ pydoc qpid.log</command>.
+ </para>
+ </section>
+ </section>
+
+
+
+ <section id="section-amqp0-10-mapping">
+ <title>The AMQP 0-10 mapping</title>
+
+ <para>
+ This section describes the AMQP 0-10 mapping for the Qpid
+ Messaging API.
+ </para>
+ <para>
+ The interaction with the broker triggered by creating a sender
+ or receiver depends on what the specified address resolves
+ to. Where the node type is not specified in the address, the
+ client queries the broker to determine whether it refers to a
+ queue or an exchange.
+ </para>
+ <para>
+ When sending to a queue, the queue's name is set as the
+ routing key and the message is transfered to the default (or
+ nameless) exchange. When sending to an exchange, the message
+ is transfered to that exchange and the routing key is set to
+ the message subject if one is specified. A default subject may
+ be specified in the target address. The subject may also be
+ set on each message individually to override the default if
+ required. In each case any specified subject is also added as
+ a qpid.subject entry in the application-headers field of the
+ message-properties.
+ </para>
+ <para>
+ When receiving from a queue, any subject in the source address
+ is currently ignored. The client sends a message-subscribe
+ request for the queue in question. The accept-mode is
+ determined by the reliability option in the link properties;
+ for unreliable links the accept-mode is none, for reliable
+ links it is explicit. The default for a queue is reliable. The
+ acquire-mode is determined by the value of the mode option. If
+ the mode is set to browse the acquire mode is not-acquired,
+ otherwise it is set to pre-acquired. The exclusive and
+ arguments fields in the message-subscribe command can be
+ controlled using the x-subscribe map.
+ </para>
+ <para>
+ When receiving from an exchange, the client creates a
+ subscription queue and binds that to the exchange. The
+ subscription queue's arguments can be specified using the
+ x-declare map within the link properties. The reliability
+ option determines most of the other parameters. If the
+ reliability is set to unreliable then an auto-deleted,
+ exclusive queue is used meaning that if the client or
+ connection fails messages may be lost. For exactly-once the
+ queue is not set to be auto-deleted. The durability of the
+ subscription queue is determined by the durable option in the
+ link properties. The binding process depends on the type of
+ the exchange the source address resolves to.
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ For a topic exchange, if no subject is specified and no
+ x-bindings are defined for the link, the subscription
+ queue is bound using a wildcard matching any routing key
+ (thus satisfying the expectation that any message sent to
+ that address will be received from it). If a subject is
+ specified in the source address however, it is used for
+ the binding key (this means that the subject in the source
+ address may be a binding pattern including wildcards).
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ For a fanout exchange the binding key is irrelevant to
+ matching. A receiver created from a source address that
+ resolves to a fanout exchange receives all messages
+ sent to that exchange regardless of any subject the source
+ address may contain. An x-bindings element in the link
+ properties should be used if there is any need to set the
+ arguments to the bind.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ For a direct exchange, the subject is used as the binding
+ key. If no subject is specified an empty string is used as
+ the binding key.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ For a headers exchange, if no subject is specified the
+ binding arguments simply contain an x-match entry and no
+ other entries, causing all messages to match. If a subject
+ is specified then the binding arguments contain an x-match
+ entry set to all and an entry for qpid.subject whose value
+ is the subject in the source address (this means the
+ subject in the source address must match the message
+ subject exactly). For more control the x-bindings element
+ in the link properties must be used.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ For the XML exchange,<footnote><para>Note that the XML
+ exchange is not a standard AMQP exchange type. It is a
+ Qpid extension and is currently only supported by the C++
+ broker.</para></footnote> if a subject is specified it is
+ used as the binding key and an XQuery is defined that
+ matches any message with that value for
+ qpid.subject. Again this means that only messages whose
+ subject exactly match that specified in the source address
+ are received. If no subject is specified then the empty
+ string is used as the binding key with an xquery that will
+ match any message (this means that only messages with an
+ empty string as the routing key will be received). For more
+ control the x-bindings element in the link properties must
+ be used. A source address that resolves to the XML
+ exchange must contain either a subject or an x-bindings
+ element in the link properties as there is no way at
+ present to receive any message regardless of routing key.
+ </para>
+ </listitem>
+ </itemizedlist>
+
+ <para>
+ If an x-bindings list is present in the link options a binding
+ is created for each element within that list. Each element is
+ a nested map that may contain values named queue, exchange,
+ key or arguments. If the queue value is absent the queue name
+ the address resolves to is implied. If the exchange value is
+ absent the exchange name the address resolves to is implied.
+ </para>
+
+ <para>The following table shows how Qpid Messaging API message
+ properties are mapped to AMQP 0-10 message properties and
+ delivery properties. In this table <varname>msg</varname>
+ refers to the Message class defined in the Qpid Messaging API,
+ <varname>mp</varname> refers to an AMQP 0-10
+ <varname>message-properties</varname> struct, and
+ <varname>dp</varname> refers to an AMQP 0-10
+ <varname>delivery-properties</varname> struct.</para>
+
+ <table id="table-amqp0-10-message-properties" pgwide="1">
+ <title>Mapping to AMQP 0-10 Message Properties</title>
+ <tgroup cols="3">
+ <thead>
+ <colspec colnum="1" colname="Python API" colwidth="3*"/>
+ <colspec colnum="2" colname="C++ API" colwidth="3*"/>
+ <colspec colnum="3" colname="AMPQ 0-10 Property" colwidth="6*"/>
+ <row>
+ <entry>Python API</entry>
+ <entry>C++ API
+ <footnote>
+ <para>
+ The .NET Binding for C++ Messaging provides all the
+ message and delivery properties described in the C++ API.
+ See <xref linkend="table-Dotnet-Binding-Message" /> .
+ </para>
+ </footnote>
+ </entry>
+ <entry>AMQP 0-10 Property<footnote><para>In these entries, <literal>mp</literal> refers to an AMQP message property, and <literal>dp</literal> refers to an AMQP delivery property.</para></footnote></entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>msg.id</entry><entry>msg.{get,set}MessageId()</entry><entry>mp.message_id</entry>
+ </row>
+ <row>
+ <entry>msg.subject</entry><entry>msg.{get,set}Subject()</entry><entry>mp.application_headers["qpid.subject"]</entry>
+ </row>
+ <row>
+ <entry>msg.user_id</entry><entry>msg.{get,set}UserId()</entry><entry>mp.user_id</entry>
+ </row>
+ <row>
+ <entry>msg.reply_to</entry><entry>msg.{get,set}ReplyTo()</entry><entry>mp.reply_to<footnote><para>The reply_to is converted from the protocol representation into an address.</para></footnote></entry>
+ </row>
+ <row>
+ <entry>msg.correlation_id</entry><entry>msg.{get,set}CorrelationId()</entry><entry>mp.correlation_id</entry>
+ </row>
+ <row>
+ <entry>msg.durable</entry><entry>msg.{get,set}Durable()</entry><entry>dp.delivery_mode == delivery_mode.persistent<footnote><para>Note that msg.durable is a boolean, not an enum.</para></footnote></entry>
+ </row>
+ <row>
+ <entry>msg.priority</entry><entry>msg.{get,set}Priority()</entry><entry>dp.priority</entry>
+ </row>
+ <row>
+ <entry>msg.ttl</entry><entry>msg.{get,set}Ttl()</entry><entry>dp.ttl</entry>
+ </row>
+ <row>
+ <entry>msg.redelivered</entry><entry>msg.{get,set}Redelivered()</entry><entry>dp.redelivered</entry>
+ </row>
+ <row><entry>msg.properties</entry><entry>msg.getProperties()/msg.setProperty()</entry><entry>mp.application_headers</entry>
+ </row>
+ <row>
+ <entry>msg.content_type</entry><entry>msg.{get,set}ContentType()</entry><entry>mp.content_type</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <section role="h3" id="section-amqp0-10-message-props">
+ <title>0-10 Message Property Keys</title>
+ <para>
+ The QPID Messaging API also recognises special message property keys and
+ automatically provides a mapping to their corresponding AMQP 0-10 definitions.
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ When sending a message, if the properties contain an entry for
+ <literal>x-amqp-0-10.app-id</literal>, its value will be used to set the
+ <literal>message-properties.app-id</literal> property in the outgoing
+ message. Likewise, if an incoming message has
+ <literal>message-properties.app-id</literal> set, its value can be accessed
+ via the <literal>x-amqp-0-10.app-id</literal> message property key.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ When sending a message, if the properties contain an entry for
+ <literal>x-amqp-0-10.content-encoding</literal>, its value will be used to
+ set the <literal>message-properties.content-encoding</literal> property in
+ the outgoing message. Likewise, if an incoming message has
+ <literal>message-properties.content-encoding</literal> set, its value can be
+ accessed via the <literal>x-amqp-0-10.content-encoding</literal> message
+ property key.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The routing key (<literal>delivery-properties.routing-key</literal>) in an
+ incoming messages can be accessed via the
+ <literal>x-amqp-0-10.routing-key</literal> message property.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ If the timestamp delivery property is set in an incoming message
+ (<literal>delivery-properties.timestamp</literal>), the timestamp value will
+ be made available via the <literal>x-amqp-0-10.timestamp</literal> message
+ property.
+ <footnote>
+ <para>
+ This special property is currently not supported by the Qpid JMS client.
+ </para>
+ </footnote>
+ </para>
+ </listitem>
+ </itemizedlist>
+ <example>
+ <title>Accessing the AMQP 0-10 Message Timestamp in Python</title>
+ <para>
+ The following code fragment checks for and extracts the message timestamp from
+ a received message.
+ </para>
+ <programlisting lang="python">
+ try:
+ msg = receiver.fetch(timeout=1)
+ if "x-amqp-0-10.timestamp" in msg.properties:
+ print("Timestamp=%s" % str(msg.properties["x-amqp-0-10.timestamp"]))
+ except Empty:
+ pass
+ </programlisting>
+ </example>
+ <example>
+ <title>Accessing the AMQP 0-10 Message Timestamp in C++</title>
+ <para>
+ The same example, except in C++.
+ </para>
+ <programlisting lang="c++">
+ messaging::Message msg;
+ if (receiver.fetch(msg, messaging::Duration::SECOND*1)) {
+ if (msg.getProperties().find("x-amqp-0-10.timestamp") != msg.getProperties().end()) {
+ <![CDATA[std::cout << "Timestamp=" << msg.getProperties()["x-amqp-0-10.timestamp"].asString() << std::endl;]]>
+ }
+ }
+ </programlisting>
+ </example>
+ </section>
+ </section>
+
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Message-Groups-Guide.xml"/>
+
+ </chapter>
+
+
+ <chapter id="QpidJMS">
+ <title>Using the Qpid JMS client</title>
+ <section>
+ <title>A Simple Messaging Program in Java JMS</title>
+
+ <para>The following program shows how to send and receive a
+ message using the Qpid JMS client. JMS programs typically use
+ JNDI to obtain connection factory and destination objects which
+ the application needs. In this way the configuration is kept
+ separate from the application code itself.</para>
+
+ <para>In this example, we create a JNDI context using a
+ properties file, use the context to lookup a connection factory,
+ create and start a connection, create a session, and lookup a
+ destination from the JNDI context. Then we create a producer and
+ a consumer, send a message with the producer and receive it with
+ the consumer. This code should be straightforward for anyone
+ familiar with Java JMS.</para>
+
+ <example>
+ <title>"Hello world!" in Java</title>
+ <programlisting lang="java">
+ package org.apache.qpid.example.jmsexample.hello;
+
+ import javax.jms.*;
+ import javax.naming.Context;
+ import javax.naming.InitialContext;
+ import java.util.Properties;
+
+ public class Hello {
+
+ public Hello() {
+ }
+
+ public static void main(String[] args) {
+ Hello producer = new Hello();
+ producer.runTest();
+ }
+
+ private void runTest() {
+ try {
+ Properties properties = new Properties();
+ properties.load(this.getClass().getResourceAsStream("hello.properties")); <co id="hello-java-properties" linkends="callout-java-properties"/>
+ Context context = new InitialContext(properties); <co id="hello-java-context" linkends="callout-java-context"/>
+
+ ConnectionFactory connectionFactory
+ = (ConnectionFactory) context.lookup("qpidConnectionfactory"); <co id="hello-java-connection-factory" linkends="callout-java-connection-factory"/>
+ Connection connection = connectionFactory.createConnection(); <co id="hello-java-connection" linkends="callout-java-connection"/>
+ connection.start(); <co id="hello-java-start" linkends="callout-java-start"/>
+
+ Session session=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);<co id="hello-java-session" linkends="callout-java-session"/>
+ Destination destination = (Destination) context.lookup("topicExchange"); <co id="hello-java-destination" linkends="callout-java-destination"/>
+
+ MessageProducer messageProducer = session.createProducer(destination); <co id="hello-java-producer" linkends="callout-java-producer"/>
+ MessageConsumer messageConsumer = session.createConsumer(destination); <co id="hello-java-consumer" linkends="callout-java-consumer"/>
+
+ TextMessage message = session.createTextMessage("Hello world!");
+ messageProducer.send(message);
+
+ message = (TextMessage)messageConsumer.receive(); <co id="hello-java-receive" linkends="callout-java-receive"/>
+ System.out.println(message.getText());
+
+ connection.close(); <co id="hello-java-close" linkends="callout-java-close"/>
+ context.close(); <co id="hello-java-jndi-close" linkends="callout-java-jndi-close"/>
+ }
+ catch (Exception exp) {
+ exp.printStackTrace();
+ }
+ }
+ }
+ </programlisting>
+ </example>
+
+ <calloutlist>
+ <callout id="callout-java-properties" arearefs="hello-java-properties">
+ <para>Loads the JNDI properties file, which specifies connection properties, queues, topics, and addressing options. See <xref linkend="QpidJNDI"/> for details.</para>
+ </callout>
+ <callout id="callout-java-context" arearefs="hello-java-context">
+ <para>Creates the JNDI initial context.</para>
+ </callout>
+ <callout id="callout-java-connection-factory" arearefs="hello-java-connection-factory">
+ <para>Creates a JMS connection factory for Qpid.</para>
+ </callout>
+ <callout id="callout-java-connection" arearefs="hello-java-connection">
+ <para>Creates a JMS connection.</para>
+ </callout>
+ <callout id="callout-java-start" arearefs="hello-java-start">
+ <para>Activates the connection.</para>
+ </callout>
+ <callout id="callout-java-session" arearefs="hello-java-session">
+ <para>Creates a session. This session is not transactional (transactions='false'), and messages are automatically acknowledged.</para>
+ </callout>
+ <callout id="callout-java-destination" arearefs="hello-java-destination">
+ <para>Creates a destination for the topic exchange, so senders and receivers can use it.</para>
+ </callout>
+ <callout id="callout-java-producer" arearefs="hello-java-producer">
+ <para>Creates a producer that sends messages to the topic exchange.</para>
+ </callout>
+ <callout id="callout-java-consumer" arearefs="hello-java-consumer">
+ <para>Creates a consumer that reads messages from the topic exchange.</para>
+ </callout>
+ <callout id="callout-java-receive" arearefs="hello-java-receive">
+ <para>Reads the next available message.</para>
+ </callout>
+ <callout id="callout-java-close" arearefs="hello-java-close">
+ <para>Closes the connection, all sessions managed by the connection, and all senders and receivers managed by each session.</para>
+ </callout>
+ <callout id="callout-java-jndi-close" arearefs="hello-java-jndi-close">
+ <para>Closes the JNDI context.</para>
+ </callout>
+ </calloutlist>
+
+ <para>The contents of the hello.properties file are shown below.</para>
+
+ <example>
+ <title>JNDI Properties File for "Hello world!" example</title>
+ <programlisting>
+ java.naming.factory.initial
+ = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
+
+ # connectionfactory.[jndiname] = [ConnectionURL]
+ connectionfactory.qpidConnectionfactory
+ = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672' <co id="hello-properties-connectionfactory" linkends="callout-hello-properties-connectionfactory"/>
+ # destination.[jndiname] = [address_string]
+ destination.topicExchange = amq.topic <co id="hello-properties-destination" linkends="callout-hello-properties-destination"/>
+ </programlisting>
+ </example>
+
+ <calloutlist>
+ <callout id="callout-hello-properties-connectionfactory" arearefs="hello-properties-connectionfactory">
+ <para>Defines a connection factory from which connections
+ can be created. The syntax of a ConnectionURL is given in
+ <xref linkend="QpidJNDI"/>.</para>
+ </callout>
+ <callout id="callout-hello-properties-destination" arearefs="hello-properties-destination">
+ <para>Defines a destination for which MessageProducers
+ and/or MessageConsumers can be created to send and receive
+ messages. The value for the destination in the properties
+ file is an address string as described in
+ <xref linkend="section-addresses"/>. In the JMS
+ implementation MessageProducers are analogous to senders in
+ the Qpid Message API, and MessageConsumers are analogous to
+ receivers.</para>
+ </callout>
+ </calloutlist>
+
+ </section>
+
+ <section id="QpidJNDI">
+ <title>Apache Qpid JNDI Properties for AMQP Messaging</title>
+
+
+ <para>
+ Apache Qpid defines JNDI properties that can be used to specify JMS Connections and Destinations. Here is a typical JNDI properties file:
+ </para>
+
+ <example>
+ <title>JNDI Properties File</title>
+ <programlisting><![CDATA[
+ java.naming.factory.initial
+ = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
+
+ # connectionfactory.[jndiname] = [ConnectionURL]
+ connectionfactory.qpidConnectionfactory
+ = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
+ # destination.[jndiname] = [address_string]
+ destination.topicExchange = amq.topic
+ ]]></programlisting>
+ </example>
+
+ <para>The following sections describe the JNDI properties that Qpid uses.</para>
+
+
+ <section>
+ <title>JNDI Properties for Apache Qpid</title>
+ <para>
+ Apache Qpid supports the properties shown in the following table:
+ </para>
+ <table>
+ <title>JNDI Properties supported by Apache Qpid</title>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>
+ Property
+ </entry>
+ <entry>
+ Purpose
+ </entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ connectionfactory.&lt;jndiname&gt;
+ </entry>
+ <entry>
+ <para>
+ The Connection URL that the connection factory uses to perform connections.
+ </para>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ queue.&lt;jndiname&gt;
+ </entry>
+ <entry>
+ <para>
+ A JMS queue, which is implemented as an amq.direct exchange in Apache Qpid.
+ </para>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ topic.&lt;jndiname&gt;
+ </entry>
+ <entry>
+ <para>
+ A JMS topic, which is implemented as an amq.topic exchange in Apache Qpid.
+ </para>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ destination.&lt;jndiname&gt;
+ </entry>
+ <entry>
+ <para>
+ Can be used for defining all amq destinations,
+ queues, topics and header matching, using an
+ address string.
+
+ <footnote><para>Binding URLs, which were used in
+ earlier versions of the Qpid Java JMS client, can
+ still be used instead of address
+ strings.</para></footnote>
+ </para>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+
+ <section id="section-jms-connection-url">
+ <title>Connection URLs</title>
+ <para>
+ In JNDI properties, a Connection URL specifies properties for a connection. The format for a Connection URL is:
+ </para>
+
+ <programlisting>amqp://[&lt;user&gt;:&lt;pass&gt;@][&lt;clientid&gt;]&lt;virtualhost&gt;[?&lt;option&gt;=&#39;&lt;value&gt;&#39;[&amp;&lt;option&gt;=&#39;&lt;value&gt;&#39;]]
+ </programlisting>
+ <para>
+ For instance, the following Connection URL specifies a user name, a password, a client ID, a virtual host ("test"), a broker list with a single broker, and a TCP host with the host name <quote>localhost</quote> using port 5672:
+ </para>
+
+ <programlisting>amqp://username:password@clientid/test?brokerlist=&#39;tcp://localhost:5672&#39;
+ </programlisting>
+ <para>
+ Apache Qpid supports the following properties in Connection URLs:
+ </para>
+ <table pgwide="1">
+ <title>Connection URL Properties</title>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>
+ Option
+ </entry>
+ <entry>
+ Type
+ </entry>
+ <entry>
+ Description
+ </entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ brokerlist
+ </entry>
+ <entry>
+ see below
+ </entry>
+ <entry>
+ List of one or more broker addresses.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ maxprefetch
+ </entry>
+ <entry>
+ integer
+ </entry>
+ <entry>
+ <para>
+ The maximum number of pre-fetched messages per consumer. If not specified, default value of 500 is used.
+ </para>
+ <para>
+ Note: You can also set the default per-consumer prefetch value on a client-wide basis by configuring the client using <link linkend="client-jvm-properties">Java system properties.</link>
+ </para>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ sync_publish
+ </entry>
+ <entry>
+ {'persistent' | 'all'}
+ </entry>
+ <entry>
+ 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.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ sync_ack
+ </entry>
+ <entry>
+ Boolean
+ </entry>
+ <entry>
+ A sync command is sent after every acknowledgement to guarantee that it has been received.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ use_legacy_map_msg_format
+ </entry>
+ <entry>
+ Boolean
+ </entry>
+ <entry>
+ 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.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ failover
+ </entry>
+ <entry>
+ {'singlebroker' | 'roundrobin' | 'failover_exchange' | 'nofailover' | '&lt;class&gt;'}
+ </entry>
+ <entry>
+ <para>
+ This option controls failover behaviour. The method <literal>singlebroker</literal> uses only the first broker in the list,
+ <literal>roundrobin</literal> will try each broker given in the broker list until a connection is established,
+ <literal>failover_exchange</literal> connects to the initial broker given in the broker URL and will receive membership updates
+ via the failover exchange. <literal>nofailover</literal> disables all retry and failover logic. Any other value is interpreted as a
+ classname which must implement the <literal>org.apache.qpid.jms.failover.FailoverMethod</literal> interface.
+ </para>
+ <para>
+ The broker list options <literal>retries</literal> and <literal>connectdelay</literal> (described below) determine the number of times a
+ connection to a broker will be retried and the the length of time to wait between successive connection attempts before moving on to
+ the next broker in the list. The failover option <literal>cyclecount</literal> controls the number of times to loop through the list of
+ available brokers before finally giving up.
+ </para>
+ <para>
+ Defaults to <literal>roundrobin</literal> if the brokerlist contains multiple brokers, or <literal>singlebroker</literal> otherwise.
+ </para>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ ssl
+ </entry>
+ <entry>
+ boolean
+ </entry>
+ <entry>
+ <para>
+ If <literal>ssl='true'</literal>, use SSL for all broker connections. Overrides any per-broker settings in the brokerlist (see below) entries. If not specified, the brokerlist entry for each given broker is used to determine whether SSL is used.
+ </para>
+ <para>
+ Introduced in version 0.22.
+ </para>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <para>
+ Broker lists are specified using a URL in this format:
+ </para>
+
+ <programlisting>brokerlist=&lt;transport&gt;://&lt;host&gt;[:&lt;port&gt;](?&lt;param>='&lt;value>')(&amp;&lt;param>='&lt;value>')*</programlisting>
+ <para>
+ For instance, this is a typical broker list:
+ </para>
+
+ <programlisting>brokerlist=&#39;tcp://localhost:5672&#39;
+ </programlisting>
+
+ <para>
+ A broker list can contain more than one broker address; if so, the connection is made to the first broker in the list that is available. In general, it is better to use the failover exchange when using multiple brokers, since it allows applications to fail over if a broker goes down.
+ </para>
+
+ <example>
+ <title>Broker Lists</title>
+ <para>A broker list can specify properties to be used when connecting to the broker, such as security options. This broker list specifies options for a Kerberos connection using GSSAPI:</para>
+ <programlisting><![CDATA[
+ amqp://guest:guest@test/test?sync_ack='true'
+ &brokerlist='tcp://ip1:5672?sasl_mechs='GSSAPI''
+ ]]></programlisting>
+
+ <para>This broker list specifies SSL options:</para>
+
+ <programlisting><![CDATA[
+ amqp://guest:guest@test/test?sync_ack='true'
+ &brokerlist='tcp://ip1:5672?ssl='true'&ssl_cert_alias='cert1''
+ ]]></programlisting>
+
+ <para>
+ This broker list specifies two brokers using the connectdelay and retries broker options. It also illustrates the failover connection URL
+ property.
+ </para>
+
+ <programlisting><![CDATA[
+
+ amqp://guest:guest@/test?failover='roundrobin?cyclecount='2''
+ &brokerlist='tcp://ip1:5672?retries='5'&connectdelay='2000';tcp://ip2:5672?retries='5'&connectdelay='2000''
+ ]]></programlisting>
+ </example>
+
+ <para>The following broker list options are supported.</para>
+
+ <table pgwide="1">
+ <title>Broker List Options</title>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>
+ Option
+ </entry>
+ <entry>
+ Type
+ </entry>
+ <entry>
+ Description
+ </entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ heartbeat
+ </entry>
+ <entry>
+ integer
+ </entry>
+ <entry>
+ frequency of heartbeat messages (in seconds)
+ </entry>
+ </row>
+ <row>
+ <entry>
+ sasl_mechs
+ </entry>
+ <entry>
+ --
+ </entry>
+ <entry>
+ For secure applications, we suggest CRAM-MD5,
+ DIGEST-MD5, or GSSAPI. The ANONYMOUS method is not
+ secure. The PLAIN method is secure only when used
+ together with SSL. For Kerberos, sasl_mechs must be
+ set to GSSAPI, sasl_protocol must be set to the
+ principal for the qpidd broker, e.g. qpidd/, and
+ sasl_server must be set to the host for the SASL
+ server, e.g. sasl.com. SASL External is supported
+ using SSL certification, e.g.
+ <literal>ssl='true'&amp;sasl_mechs='EXTERNAL'</literal>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ sasl_encryption
+ </entry>
+ <entry>
+ Boolean
+ </entry>
+ <entry>
+ If <literal>sasl_encryption='true'</literal>, 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.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ sasl_protocol
+ </entry>
+ <entry>
+ --
+ </entry>
+ <entry>
+ Used only for
+ Kerberos. <literal>sasl_protocol</literal> must be
+ set to the principal for the qpidd broker,
+ e.g. <literal>qpidd/</literal>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ sasl_server
+ </entry>
+ <entry>
+ --
+ </entry>
+ <entry>
+ For Kerberos, sasl_mechs must be set to GSSAPI,
+ sasl_server must be set to the host for the SASL
+ server, e.g. <literal>sasl.com</literal>.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ trust_store
+ </entry>
+ <entry>
+ --
+ </entry>
+ <entry>
+ path to trust store
+ </entry>
+ </row>
+ <row>
+ <entry>
+ trust_store_password
+ </entry>
+ <entry>
+ --
+ </entry>
+ <entry>
+ Trust store password
+ </entry>
+ </row>
+ <row>
+ <entry>
+ key_store
+ </entry>
+ <entry>
+ --
+ </entry>
+ <entry>
+ path to key store
+ </entry>
+ </row>
+ <row>
+ <entry>
+ key_store_password
+ </entry>
+ <entry>
+ --
+ </entry>
+ <entry>
+ key store password
+ </entry>
+ </row>
+ <row>
+ <entry>
+ ssl
+ </entry>
+ <entry>
+ Boolean
+ </entry>
+ <entry>
+ <para>If <literal>ssl='true'</literal>, the JMS client will encrypt the connection to this broker using SSL.</para>
+
+ <para>This can also be set/overridden for all brokers using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ ssl_verify_hostname
+ </entry>
+ <entry>
+ Boolean
+ </entry>
+ <entry>
+ When using SSL you can enable hostname verification
+ by using <literal>ssl_verify_hostname='true'</literal> in the broker
+ URL.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ ssl_cert_alias
+ </entry>
+ <entry>
+ --
+ </entry>
+ <entry>
+ If multiple certificates are present in the keystore, the alias will be used to extract the correct certificate.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ retries
+ </entry>
+ <entry>
+ integer
+ </entry>
+ <entry>
+ The number of times to retry connection to each broker in the broker list. Defaults to 1.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ connectdelay
+ </entry>
+ <entry>
+ integer
+ </entry>
+ <entry>
+ Length of time (in milliseconds) to wait before attempting to reconnect. Defaults to 0.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ connecttimeout
+ </entry>
+ <entry>
+ integer
+ </entry>
+ <entry>
+ Length of time (in milliseconds) to wait for the socket connection to succeed. A value of 0 represents an infinite timeout, i.e. the connection attempt will block until established or an error occurs. Defaults to 30000.
+ </entry>
+ </row>
+ <row>
+ <entry>
+ tcp_nodelay
+ </entry>
+ <entry>
+ Boolean
+ </entry>
+ <entry>
+ If <literal>tcp_nodelay='true'</literal>, TCP packet
+ batching is disabled. Defaults to true since Qpid 0.14.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ </section>
+
+ <section>
+ <title>Java JMS Message Properties</title>
+
+ <para>The following table shows how Qpid Messaging API message
+ properties are mapped to AMQP 0-10 message properties and
+ delivery properties. In this table <varname>msg</varname>
+ refers to the Message class defined in the Qpid Messaging API,
+ <varname>mp</varname> refers to an AMQP 0-10
+ <varname>message-properties</varname> struct, and
+ <varname>dp</varname> refers to an AMQP 0-10
+ <varname>delivery-properties</varname> struct.</para>
+
+ <table >
+ <title>Java JMS Mapping to AMQP 0-10 Message Properties</title>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>Java JMS Message Property</entry>
+ <entry>AMQP 0-10 Property<footnote><para>In these entries, <literal>mp</literal> refers to an AMQP message property, and <literal>dp</literal> refers to an AMQP delivery property.</para></footnote></entry>
+
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>JMSMessageID</entry><entry>mp.message_id</entry>
+ </row>
+ <row>
+ <entry>qpid.subject<footnote><para>This is a custom JMS property, set automatically by the Java JMS client implementation.</para></footnote></entry><entry>mp.application_headers["qpid.subject"]</entry>
+ </row>
+ <row>
+ <entry>JMSXUserID</entry><entry>mp.user_id</entry>
+ </row>
+ <row>
+ <entry>JMSReplyTo</entry><entry>mp.reply_to<footnote><para>The reply_to is converted from the protocol representation into an address.</para></footnote></entry>
+ </row>
+ <row>
+ <entry>JMSCorrelationID</entry><entry>mp.correlation_id</entry>
+ </row>
+ <row>
+ <entry>JMSDeliveryMode</entry><entry>dp.delivery_mode</entry>
+ </row>
+ <row>
+ <entry>JMSPriority</entry><entry>dp.priority</entry>
+ </row>
+ <row>
+ <entry>JMSExpiration</entry><entry>dp.ttl<footnote><para>JMSExpiration = dp.ttl + currentTime</para></footnote></entry>
+ </row>
+ <row>
+ <entry>JMSRedelivered</entry><entry>dp.redelivered</entry>
+ </row>
+ <row>
+ <entry>JMS Properties</entry><entry>mp.application_headers</entry>
+ </row>
+ <row>
+ <entry>JMSType</entry><entry>mp.content_type</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ </section>
+
+ <section id="section-JMS-MapMessage">
+ <title>JMS MapMessage Types</title>
+
+ <para>Qpid supports the Java JMS <classname>MapMessage</classname> interface, which provides support for maps in messages. The following code shows how to send a <classname>MapMessage</classname> in Java JMS.</para>
+
+ <example>
+ <title>Sending a Java JMS MapMessage</title>
+ <programlisting><![CDATA[
+ import java.util.ArrayList;
+ import java.util.HashMap;
+ import java.util.List;
+ import java.util.Map;
+
+ import javax.jms.Connection;
+ import javax.jms.Destination;
+ import javax.jms.MapMessage;
+ import javax.jms.MessageProducer;
+ import javax.jms.Session;
+
+ import java.util.Arrays;
+
+ // !!! SNIP !!!
+
+ MessageProducer producer = session.createProducer(queue);
+
+ MapMessage m = session.createMapMessage();
+ m.setIntProperty("Id", 987654321);
+ m.setStringProperty("name", "Widget");
+ m.setDoubleProperty("price", 0.99);
+
+ List<String> colors = new ArrayList<String>();
+ colors.add("red");
+ colors.add("green");
+ colors.add("white");
+ m.setObject("colours", colors);
+
+ Map<String,Double> dimensions = new HashMap<String,Double>();
+ dimensions.put("length",10.2);
+ dimensions.put("width",5.1);
+ dimensions.put("depth",2.0);
+ m.setObject("dimensions",dimensions);
+
+ List<List<Integer>> parts = new ArrayList<List<Integer>>();
+ parts.add(Arrays.asList(new Integer[] {1,2,5}));
+ parts.add(Arrays.asList(new Integer[] {8,2,5}));
+ m.setObject("parts", parts);
+
+ Map<String,Object> specs = new HashMap<String,Object>();
+ specs.put("colours", colors);
+ specs.put("dimensions", dimensions);
+ specs.put("parts", parts);
+ m.setObject("specs",specs);
+
+ producer.send(m);
+ ]]></programlisting>
+ </example>
+
+ <para>The following table shows the datatypes that can be sent in a <classname>MapMessage</classname>, and the corresponding datatypes that will be received by clients in Python or C++.</para>
+
+ <table id="table-Java-Maps">
+ <title>Java Datatypes in Maps</title>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Java Datatype</entry>
+ <entry>&rarr; Python</entry>
+ <entry>&rarr; C++</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row><entry>boolean</entry><entry>bool</entry><entry>bool</entry></row>
+ <row><entry>short</entry><entry>int | long</entry><entry>int16</entry></row>
+ <row><entry>int</entry><entry>int | long</entry><entry>int32</entry></row>
+ <row><entry>long</entry><entry>int | long</entry><entry>int64</entry></row>
+ <row><entry>float</entry><entry>float</entry><entry>float</entry></row>
+ <row><entry>double</entry><entry>float</entry><entry>double</entry></row>
+ <row><entry>java.lang.String</entry><entry>unicode</entry><entry>std::string</entry></row>
+ <row><entry>java.util.UUID</entry><entry>uuid</entry><entry>qpid::types::Uuid</entry></row>
+ <row><entry>java.util.Map<footnote><para>In Qpid, maps can nest. This goes beyond the functionality required by the JMS specification.</para></footnote></entry><entry>dict</entry><entry>Variant::Map</entry></row>
+ <row><entry>java.util.List</entry><entry>list</entry><entry>Variant::List</entry></row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ </section>
+
+ <section id="section-JMS-Logging">
+ <title>JMS Client Logging</title>
+ <para>The JMS Client logging is handled using the Simple Logging Facade for Java (<ulink url="http://www.slf4j.org/">SLF4J</ulink>). As the name implies, slf4j is a facade that delegates to other logging systems like log4j or JDK 1.4 logging. For more information on how to configure slf4j for specific logging systems, please consult the slf4j documentation.</para>
+
+ <para>When using the log4j binding, please set the log level for org.apache.qpid explicitly. Otherwise log4j will default to DEBUG which will degrade performance considerably due to excessive logging. The recommended logging level for production is <literal>WARN</literal>.</para>
+
+ <para>The following example shows the logging properties used to configure client logging for slf4j using the log4j binding. These properties can be placed in a log4j.properties file and placed in the <varname>CLASSPATH</varname>, or they can be set explicitly using the <literal>-Dlog4j.configuration</literal> property.</para>
+
+ <example>
+ <title>log4j Logging Properties</title>
+
+ <programlisting><![CDATA[
+ log4j.logger.org.apache.qpid=WARN, console
+ log4j.additivity.org.apache.qpid=false
+
+ log4j.appender.console=org.apache.log4j.ConsoleAppender
+ log4j.appender.console.Threshold=all
+ log4j.appender.console.layout=org.apache.log4j.PatternLayout
+ log4j.appender.console.layout.ConversionPattern=%t %d %p [%c{4}] %m%n
+ ]]></programlisting>
+ </example>
+
+ </section>
+
+ <section>
+ <title>Configuring the JMS Client</title>
+
+ <para>The Qpid JMS Client allows several configuration options to customize it's behaviour at different levels of granualarity.</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ JVM level using JVM arguments : Configuration that affects all connections, sessions, consumers and producers created within that JVM.
+ </para>
+ <para>Ex. <varname>-Dmax_prefetch=1000</varname> property specifies the message credits to use.</para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Connection level using Connection/Broker properties : Affects the respective connection and sessions, consumers and produces created by that connection.
+ </para>
+ <para>Ex. <varname>amqp://guest:guest@test/test?max_prefetch='1000'
+ &amp;brokerlist='tcp://localhost:5672'
+ </varname> property specifies the message credits to use. This overrides any value specified via the JVM argument <varname>max_prefetch</varname>.</para>
+ <para>Please refer to the <xref linkend="section-jms-connection-url"/> section for a complete list of all properties and how to use them.</para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Destination level using Addressing options : Affects the producer(s) and consumer(s) created using the respective destination.
+ </para>
+ <para>Ex. <varname>my-queue; {create: always, link:{capacity: 10}}</varname>, where <varname>capacity</varname> option specifies the message credits to use. This overrides any connection level configuration.</para>
+ <para>Please refer to the <xref linkend="section-addresses"/> section for a complete understanding of addressing and it's various options.</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Some of these config options are available at all three levels (Ex. <varname>max_prefetch</varname>), while others are available only at JVM or connection level.</para>
+
+ <section id="client-jvm-properties">
+ <title>Qpid JVM Arguments</title>
+
+ <table >
+ <title>Config Options For Connection Behaviour</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>qpid.amqp.version</entry>
+ <entry>string</entry>
+ <entry>0-10</entry>
+ <entry><para>Sets the AMQP version to be used - currently supports one of {0-8,0-9,0-91,0-10}.</para><para>The client will begin negotiation at the specified version and only negotiate downwards if the Broker does not support the specified version.</para></entry>
+ </row>
+ <row>
+ <entry>qpid.heartbeat</entry>
+ <entry>int</entry>
+ <entry>120 (secs)</entry>
+ <entry>The heartbeat interval in seconds. Two consective misssed heartbeats will result in the connection timing out.<para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+
+ <row>
+ <entry>ignore_setclientID</entry>
+ <entry>boolean</entry>
+ <entry>false</entry>
+ <entry>If a client ID is specified in the connection URL it's used or else an ID is generated. If an ID is specified after it's been set Qpid will throw an exception. <para>Setting this property to 'true' will disable that check and allow you to set a client ID of your choice later on.</para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+
+ <table >
+ <title>Config Options For Session Behaviour</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>qpid.session.command_limit</entry>
+ <entry>int</entry>
+ <entry>65536</entry>
+ <entry>Limits the # of unacked commands</entry>
+ </row>
+
+ <row>
+ <entry>qpid.session.byte_limit</entry>
+ <entry>int</entry>
+ <entry>1048576</entry>
+ <entry>Limits the # of unacked commands in terms of bytes</entry>
+ </row>
+
+ <row>
+ <entry>qpid.use_legacy_map_message</entry>
+ <entry>boolean</entry>
+ <entry>false</entry>
+ <entry><para>If set will use the old map message encoding. By default the Map messages are encoded using the 0-10 map encoding.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+
+ <row>
+ <entry>qpid.jms.daemon.dispatcher</entry>
+ <entry>boolean</entry>
+ <entry>false</entry>
+ <entry><para>Controls whether the Session dispatcher thread is a daemon thread or not. If this system property is set to true then the Session dispatcher threads will be created as daemon threads. This setting is introduced in version 0.16.</para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table >
+ <title>Config Options For Consumer Behaviour</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>max_prefetch</entry>
+ <entry>int</entry>
+ <entry>500</entry>
+ <entry>Maximum number of pre-fetched messages per consumer. <para>This can also be defaulted for consumers created on a particular connection using the <link linkend="section-jms-connection-url">Connection URL</link> options, or per destination (see the <varname>capacity</varname> option under link properties in addressing)</para></entry>
+ </row>
+
+ <row>
+ <entry>qpid.session.max_ack_delay</entry>
+ <entry>long</entry>
+ <entry>1000 (ms)</entry>
+ <entry><para>Timer interval to flush message acks in buffer when using AUTO_ACK and DUPS_OK.</para> <para>When using the above ack modes, message acks are batched and sent if one of the following conditions are met (which ever happens first).
+ <itemizedlist>
+ <listitem><para>When the ack timer fires.</para></listitem>
+ <listitem><para>if un_acked_msg_count > max_prefetch/2.</para></listitem>
+ </itemizedlist>
+ </para>
+ <para>The ack timer can be disabled by setting it to 0.</para>
+ </entry>
+ </row>
+
+ <row>
+ <entry>sync_ack</entry>
+ <entry>boolean</entry>
+ <entry>false</entry>
+ <entry><para>If set, each message will be acknowledged synchronously. When using AUTO_ACK mode, you need to set this to "true", in order to get the correct behaviour as described by the JMS spec.</para><para>This is set to false by default for performance reasons, therefore by default AUTO_ACK behaves similar to DUPS_OK.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table >
+ <title>Config Options For Producer Behaviour</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>sync_publish</entry>
+ <entry>string</entry>
+ <entry>"" (disabled)</entry>
+ <entry><para>If one of {persistent|all} is set then persistent messages or all messages will be sent synchronously.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table >
+ <title>Config Options For Threading</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>qpid.thread_factory</entry>
+ <entry>string</entry>
+ <entry>org.apache.qpid.thread.DefaultThreadFactory</entry>
+ <entry><para>Specifies the thread factory to use.</para><para>If using a real time JVM, you need to set the above property to <varname>org.apache.qpid.thread.RealtimeThreadFactory</varname>.</para></entry>
+ </row>
+
+ <row>
+ <entry>qpid.rt_thread_priority</entry>
+ <entry>int</entry>
+ <entry>20</entry>
+ <entry><para>Specifies the priority (1-99) for Real time threads created by the real time thread factory.</para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table >
+ <title>Config Options For I/O</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>qpid.transport</entry>
+ <entry>string</entry>
+ <entry>org.apache.qpid.transport.network.io.IoNetworkTransport</entry>
+ <entry><para>The transport implementation to be used.</para><para>A user could specify an alternative transport mechanism that implements the interface <varname>org.apache.qpid.transport.network.OutgoingNetworkTransport</varname>.</para></entry>
+ </row>
+ <row>
+ <entry>qpid.sync_op_timeout</entry>
+ <entry>long</entry>
+ <entry>60000</entry>
+ <entry><para>The length of time (in milliseconds) to wait for a synchronous operation to complete.</para><para>For compatibility with older clients, the synonym <varname>amqj.default_syncwrite_timeout</varname> is supported.</para></entry>
+ </row>
+ <row>
+ <entry>qpid.tcp_nodelay</entry>
+ <entry>boolean</entry>
+ <entry>true</entry>
+ <entry>
+ <para>Sets the TCP_NODELAY property of the underlying socket. The default was changed to true as of Qpid 0.14.</para>
+ <para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para>
+ <para>For compatibility with older clients, the synonym <varname>amqj.tcp_nodelay</varname> is supported.</para>
+ </entry>
+ </row>
+ <row>
+ <entry>qpid.send_buffer_size</entry>
+ <entry>integer</entry>
+ <entry>65535</entry>
+ <entry>
+ <para>Sets the SO_SNDBUF property of the underlying socket. Added in Qpid 0.16.</para>
+ <para>For compatibility with older clients, the synonym <varname>amqj.sendBufferSize</varname> is supported.</para>
+ </entry>
+ </row>
+ <row>
+ <entry>qpid.receive_buffer_size</entry>
+ <entry>integer</entry>
+ <entry>65535</entry>
+ <entry>
+ <para>Sets the SO_RCVBUF property of the underlying socket. Added in Qpid 0.16.</para>
+ <para>For compatibility with older clients, the synonym <varname>amqj.receiveBufferSize</varname> is supported.</para>
+ </entry>
+ </row>
+ <row>
+ <entry>qpid.failover_method_timeout</entry>
+ <entry>long</entry>
+ <entry>60000</entry>
+ <entry>
+ <para>During failover, this is the timeout for each attempt to try to re-establish the connection.
+ If a reconnection attempt exceeds the timeout, the entire failover process is aborted.</para>
+ <para>It is only applicable for AMQP 0-8/0-9/0-9-1 clients.</para>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table >
+ <title>Config Options For Security</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>qpid.sasl_mechs</entry>
+ <entry>string</entry>
+ <entry>PLAIN</entry>
+ <entry><para>The SASL mechanism to be used. More than one could be specified as a comma separated list.</para><para>We currently support the following mechanisms {PLAIN | GSSAPI | EXTERNAL}.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+
+ <row>
+ <entry>qpid.sasl_protocol</entry>
+ <entry>string</entry>
+ <entry>AMQP</entry>
+ <entry><para>When using GSSAPI as the SASL mechanism, <varname>sasl_protocol</varname> must be set to the principal for the qpidd broker, e.g. <varname>qpidd</varname>.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+
+ <row>
+ <entry>qpid.sasl_server_name</entry>
+ <entry>string</entry>
+ <entry>localhost</entry>
+ <entry><para>When using GSSAPI as the SASL mechanism, <varname>sasl_server</varname> must be set to the host for the SASL server, e.g. <varname>example.com</varname>.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table>
+ <title>Config Options For Security - Standard JVM properties needed when using GSSAPI as the SASL mechanism.<footnote><para>Please refer to the Java security documentation for a complete understanding of the above properties.</para></footnote></title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>javax.security.auth.useSubjectCredsOnly</entry>
+ <entry>boolean</entry>
+ <entry>true</entry>
+ <entry><para>If set to 'false', forces the SASL GASSPI client to obtain the kerberos credentials explicitly instead of obtaining from the "subject" that owns the current thread.</para></entry>
+ </row>
+
+ <row>
+ <entry>java.security.auth.login.config</entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry><para>Specifies the jass configuration file.</para><para><varname>Ex-Djava.security.auth.login.config=myjas.conf</varname>
+ </para><para>Here is the sample myjas.conf JASS configuration file: <programlisting><![CDATA[
+
+ com.sun.security.jgss.initiate {
+ com.sun.security.auth.module.Krb5LoginModule required useTicketCache=true;
+ };
+
+ ]]></programlisting></para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table>
+ <title>Config Options For Security - Using SSL for securing connections or using EXTERNAL as the SASL mechanism.</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>qpid.ssl_timeout</entry>
+ <entry>long</entry>
+ <entry>60000</entry>
+ <entry><para>Timeout value used by the Java SSL engine when waiting on operations.</para></entry>
+ </row>
+
+ <row>
+ <entry>qpid.ssl.KeyManagerFactory.algorithm</entry>
+ <entry>string</entry>
+ <entry>-</entry>
+ <entry>
+ <para>The key manager factory algorithm name. If not set, defaults to the value returned from the Java runtime call <literal>KeyManagerFactory.getDefaultAlgorithm()</literal></para>
+ <para>For compatibility with older clients, the synonym <varname>qpid.ssl.keyStoreCertType</varname> is supported.</para>
+ </entry>
+ </row>
+
+ <row>
+ <entry>qpid.ssl.TrustManagerFactory.algorithm</entry>
+ <entry>string</entry>
+ <entry>-</entry>
+ <entry>
+ <para>The trust manager factory algorithm name. If not set, defaults to the value returned from the Java runtime call <literal>TrustManagerFactory.getDefaultAlgorithm()</literal></para>
+ <para>For compatibility with older clients, the synonym <varname>qpid.ssl.trustStoreCertType</varname> is supported.</para>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table>
+ <title>Config Options For Security - Standard JVM properties needed when Using SSL for securing connections or using EXTERNAL as the SASL mechanism.<footnote><para>Qpid allows you to have per connection key and trust stores if required. If specified per connection, the JVM arguments are ignored.</para></footnote></title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Property Name</entry>
+ <entry>Type</entry>
+ <entry>Default Value</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>javax.net.ssl.keyStore</entry>
+ <entry>string</entry>
+ <entry>jvm default</entry>
+ <entry><para>Specifies the key store path.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+
+ <row>
+ <entry>javax.net.ssl.keyStorePassword</entry>
+ <entry>string</entry>
+ <entry>jvm default</entry>
+ <entry><para>Specifies the key store password.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+
+ <row>
+ <entry>javax.net.ssl.trustStore</entry>
+ <entry>string</entry>
+ <entry>jvm default</entry>
+ <entry><para>Specifies the trust store path.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+
+ <row>
+ <entry>javax.net.ssl.trustStorePassword</entry>
+ <entry>string</entry>
+ <entry>jvm default</entry>
+ <entry><para>Specifies the trust store password.</para><para>This can also be set per connection using the <link linkend="section-jms-connection-url">Connection URL</link> options.</para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ </section>
+
+ </chapter>
+
+ <chapter id="QpidWCF">
+ <title>Using the Qpid WCF client</title>
+ <section>
+ <title>XML and Binary Bindings</title>
+
+ <para>The Qpid WCF client provides two bindings, each with support for
+ Windows .NET transactions.</para>
+
+ <para>The AmqpBinding is suitable for communication between two WCF
+ applications. By default it uses the WCF binary .NET XML encoder
+ (BinaryMessageEncodingBindingElement) for efficient message
+ transmission, but it can also use the text and Message Transmission
+ Optimization Mechanism (MTOM) encoders. Here is a traditional service
+ model sample program using the AmqpBinding. It assumes that the queue
+ "hello_service_node" has been created and configured on the AMQP
+ broker.</para>
+
+ <example><?dbfo keep-together="auto" ?>
+ <title>Traditional service model "Hello world!" example</title>
+ <programlisting><![CDATA[
+ namespace Apache.Qpid.Documentation.HelloService
+ {
+ using System;
+ using System.ServiceModel;
+ using System.ServiceModel.Channels;
+ using System.Threading;
+ using Apache.Qpid.Channel;
+
+ [ServiceContract]
+ public interface IHelloService
+ {
+ [OperationContract(IsOneWay = true, Action = "*")]
+ void SayHello(string greeting);
+ }
+
+ public class HelloService : IHelloService
+ {
+ private static int greetingCount;
+
+ public static int GreetingCount
+ {
+ get { return greetingCount; }
+ }
+
+ public void SayHello(string greeting)
+ {
+ Console.WriteLine("Service received: " + greeting);
+ greetingCount++;
+ }]]></programlisting>
+
+ <programlisting><![CDATA[
+ static void Main(string[] args)
+ {
+ try
+ {
+ AmqpBinding amqpBinding = new AmqpBinding();
+ amqpBinding.BrokerHost = "localhost";
+ amqpBinding.BrokerPort = 5672;
+
+ ServiceHost serviceHost = new ServiceHost(typeof(HelloService));
+ serviceHost.AddServiceEndpoint(typeof(IHelloService),
+ amqpBinding, "amqp:hello_service_node");
+ serviceHost.Open();
+
+ // Send the service a test greeting
+ Uri amqpClientUri=new Uri("amqp:amq.direct?routingkey=hello_service_node");
+ EndpointAddress clientEndpoint = new EndpointAddress(amqpClientUri);
+ ChannelFactory<IHelloService> channelFactory =
+ new ChannelFactory<IHelloService>(amqpBinding, clientEndpoint);
+ IHelloService clientProxy = channelFactory.CreateChannel();
+
+ clientProxy.SayHello("Greetings from WCF client");
+
+ // wait for service to process the greeting
+ while (HelloService.GreetingCount == 0)
+ {
+ Thread.Sleep(100);
+ }
+ channelFactory.Close();
+ serviceHost.Close();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Exception: {0}", e);
+ }
+ }
+ }
+ }
+ ]]></programlisting>
+ </example>
+
+ <para>The second binding, AmqpBinaryBinding, is suitable for WCF
+ applications that need to inter-operate with non-WCF clients or that
+ wish to have direct access to the raw wire representation of the
+ message body. It relies on a custom encoder to read and write raw
+ (binary) content which operates similarly to the ByteStream encoder
+ (introduced in .NET 4.0). The encoder presents an abstract XML
+ infoset view of the raw message content on input. On output, the
+ encoder does the reverse and peels away the XML infoset layer exposing
+ the raw content to the wire representation of the message body. The
+ application must do the inverse of what the encoder does to allow the
+ XML infoset wrapper to cancel properly. This is demonstrated in the
+ following sample code (using the channel programming model) which
+ directly manipulates or provides callbacks to the WCF message readers
+ and writers when the content is consumed. In contrast to the
+ AmqpBinding sample where the simple greeting is encapsulated in a
+ compressed SOAP envelope, the wire representation of the message
+ contains the raw content and is identical and fully interoperable with
+ the Qpid C++ "Hello world!" example.</para>
+
+ <example><?dbfo keep-together="auto" ?>
+ <title>Binary "Hello world!" example using the channel model</title>
+ <programlisting><![CDATA[
+ namespace Apache.Qpid.Samples.Channel.HelloWorld
+ {
+ using System;
+ using System.ServiceModel;
+ using System.ServiceModel.Channels;
+ using System.ServiceModel.Description;
+ using System.Text;
+ using System.Xml;
+ using Apache.Qpid.Channel;
+
+ public class HelloWorld
+ {
+ static void Main(string[] args)
+ {
+ String broker = "localhost";
+ int port = 5672;
+ String target = "amq.topic";
+ String source = "my_topic_node";
+
+ if (args.Length > 0)
+ {
+ broker = args[0];
+ }
+
+ if (args.Length > 1)
+ {
+ port = int.Parse(args[1]);
+ }
+
+ if (args.Length > 2)
+ {
+ target = args[2];
+ }
+
+ if (args.Length > 3)
+ {
+ source = args[3];
+ }
+
+ AmqpBinaryBinding binding = new AmqpBinaryBinding();
+ binding.BrokerHost = broker;
+ binding.BrokerPort = port;
+
+ IChannelFactory<IInputChannel> receiverFactory = binding.BuildChannelFactory<IInputChannel>();
+ receiverFactory.Open();
+ IInputChannel receiver = receiverFactory.CreateChannel(new EndpointAddress("amqp:" + source));
+ receiver.Open();
+
+ IChannelFactory<IOutputChannel> senderFactory = binding.BuildChannelFactory<IOutputChannel>();
+ senderFactory.Open();
+ IOutputChannel sender = senderFactory.CreateChannel(new EndpointAddress("amqp:" + target));
+ sender.Open();
+
+ sender.Send(Message.CreateMessage(MessageVersion.None, "", new HelloWorldBinaryBodyWriter()));
+
+ Message message = receiver.Receive();
+ XmlDictionaryReader reader = message.GetReaderAtBodyContents();
+ while (!reader.HasValue)
+ {
+ reader.Read();
+ }
+
+ byte[] binaryContent = reader.ReadContentAsBase64();
+ string text = Encoding.UTF8.GetString(binaryContent);
+
+ Console.WriteLine(text);
+
+ senderFactory.Close();
+ receiverFactory.Close();
+ }
+ }
+
+ public class HelloWorldBinaryBodyWriter : BodyWriter
+ {
+ public HelloWorldBinaryBodyWriter() : base (true) {}
+
+ protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
+ {
+ byte[] binaryContent = Encoding.UTF8.GetBytes("Hello world!");
+
+ // wrap the content:
+ writer.WriteStartElement("Binary");
+ writer.WriteBase64(binaryContent, 0, binaryContent.Length);
+ }
+ }
+ }
+ ]]></programlisting>
+ </example>
+
+ <para>Bindings define ChannelFactories and ChannelListeners associated with
+ an AMQP Broker. WCF will frequently automatically create and manage
+ the life cycle of a these and the resulting IChannel objects used in
+ message transfer. The binding parameters that can be set are:</para>
+
+ <table pgwide="1">
+ <title>WCF Binding Parameters</title>
+ <tgroup cols="3">
+ <thead>
+ <colspec colnum="1" colwidth="1*"/>
+ <colspec colnum="2" colwidth="3*"/>
+ <colspec colnum="3" colwidth="3*"/>
+ <row>
+ <entry>Parameter</entry>
+ <entry>Default</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ BrokerHost
+ </entry>
+ <entry>
+ localhost
+ </entry>
+ <entry>
+ The broker's server name. Currently the WCF channel
+ only supports connections with a single broker.
+ Failover to multiple brokers will be provided in the
+ future.
+ </entry>
+ </row>
+
+ <row>
+ <entry>
+ BrokerPort
+ </entry>
+ <entry>
+ 5672
+ </entry>
+ <entry>
+ The port the broker is listening on.
+ </entry>
+ </row>
+
+ <row>
+ <entry>
+ PrefetchLimit
+ </entry>
+ <entry>
+ 0
+ </entry>
+ <entry>
+ The number of messages to prefetch from the amqp
+ broker before the application actually consumes them.
+ Increasing this number can dramatically increase the
+ read performance in some circumstances.
+ </entry>
+ </row>
+
+ <row>
+ <entry>
+ Shared
+ </entry>
+ <entry>
+ false
+ </entry>
+ <entry>
+ Indicates if separate channels to the same broker can
+ share an underlying AMQP tcp connection (provided they
+ also share the same authentication credentials).
+ </entry>
+ </row>
+
+ <row>
+ <entry>
+ TransferMode
+ </entry>
+ <entry>
+ buffered
+ </entry>
+ <entry>
+ Indicates whether the channel's encoder uses the WCF
+ BufferManager cache to temporarily store message
+ content during the encoding/decoding phase. For small
+ to medium sized SOAP based messages, buffered is
+ usually the preferred choice. For binary messages,
+ streamed TransferMode is the more efficient mode.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+
+ <section>
+ <title>Endpoints</title>
+
+ <para>In Qpid 0.6 the WCF Endpoints map to simple AMQP 0-10
+ exchanges (IOutputChannel) or AMQP 0-10 queues (IInputChannel).
+ The format for an IOutputChannel is</para>
+
+ <programlisting><![CDATA[
+ "amqp:amq.direct" or "amqp:my_exchange?routingkey=my_routing_key"
+]]></programlisting>
+
+ <para>and for an IInputChannel is</para>
+
+ <programlisting><![CDATA[
+ "amqp:my_queue"
+]]></programlisting>
+
+ <para>The routing key is in fact a default value associated with
+ the particular channel. Outgoing messages can always have their
+ routing key uniquely set.</para>
+
+ <para>If the respective queue or exchange doesn't exist, an exception
+ is thrown when opening the channel. Queues and exchanges can be
+ created and configured using qpid-config.</para>
+
+ </section>
+
+ <section>
+ <title>Message Headers</title>
+
+ <para>AMQP specific message headers can be set on or retrieved
+ from the ServiceModel.Channels.Message using the AmqpProperties
+ type.</para>
+
+ <para>For example, on output:</para>
+
+ <programlisting><![CDATA[
+AmqpProperties props = new AmqpProperties();
+props.Durable = true;
+props.PropertyMap.Add("my_custom_header", new AmqpString("a custom value"));
+Message msg = Message.CreateMessage(args);
+msg.Properties.Add("AmqpProperties", amqpProperties);
+outputChannel.Send(msg);
+]]></programlisting>
+
+ <para>On input the headers can be accessed from the Message or extracted
+ from the operation context</para>
+
+ <programlisting><![CDATA[
+public void SayHello(string greeting)
+{
+ AmqpProperties props = (AmqpProperties) OperationContext.
+ Current.IncomingMessageProperties["AmqpProperties"];
+ AmqpString extra = (AmqpString) props.PropertyMap["my_custom_header"];
+ Console.WriteLine("Service received: {0} and {1}", greeting, extra);
+}
+]]></programlisting>
+
+ </section>
+
+ <section>
+ <title>Security</title>
+
+ <para>To engage TLS/SSL:</para>
+
+ <programlisting><![CDATA[
+binding.Security.Mode = AmqpSecurityMode.Transport;
+binding.Security.Transport.UseSSL = true;
+binding.BrokerPort = 5671;
+]]></programlisting>
+
+ <para>Currently the WCF client only provides SASL PLAIN (i.e. username and
+ password) authentication. To provide a username and password, you can
+ set the DefaultAmqpCredential value in the binding. This value can be
+ overridden or set for a binding's channel factories and listeners,
+ either by setting the ClientCredentials as a binding parameter, or by
+ using an AmqpCredential as a binding parameter. The search order for
+ credentials is the AmqpCredential binding parameter, followed by the
+ ClientCredentials (unless IgnoreEndpointClientCredentials has been
+ set), and finally defaulting to the DefaultAmqpCredential of the
+ binding itself. Here is a sample using ClientCredentials:</para>
+
+ <programlisting><![CDATA[
+ClientCredentials credentials = new ClientCredentials();
+credentials.UserName.UserName = "guest";
+credentials.UserName.Password = "guest";
+bindingParameters = new BindingParameterCollection();
+bindingParameters.Add(credentials);
+readerFactory = binding.BuildChannelFactory<IInputChannel>(bindingParameters);
+]]></programlisting>
+
+ </section>
+
+ <section>
+ <title>Transactions</title>
+
+ <para>The WCF channel provides a transaction resource manager
+ module and a recovery module that together provide distributed
+ transaction support with one-phase optimization. Some
+ configuration is required on Windows machines to enable
+ transaction support (see your installation notes or top level
+ ReadMe.txt file for instructions). Once properly configured,
+ the Qpid WCF channel acts as any other System.Transactions aware
+ resource, capable of participating in explicit or implicit
+ transactions.</para>
+
+ <para>Server code:</para>
+
+ <programlisting><![CDATA[
+[OperationBehavior(TransactionScopeRequired = true,
+ TransactionAutoComplete = true)]
+
+public void SayHello(string greeting)
+{
+ // increment ExactlyOnceReceived counter on DB
+
+ // Success: transaction auto completes:
+}
+]]></programlisting>
+
+ <para>Because this operation involves two transaction resources, the
+ database and the AMQP message broker, this operates as a full two
+ phase commit transaction managed by the Distributed Transaction
+ Coordinator service. If the transaction proceeds without error,
+ both ExactlyOnceReceived is incremented in the database and the AMQP
+ message is consumed from the broker. Otherwise, ExactlyOnceReceived is
+ unchanged and AMQP message is returned to its queue on the broker.</para>
+
+ <para>For the client code a few changes are made to the non-transacted
+ example. For "exactly once" semantics, we set the AMQP "Durable"
+ message property and enclose the transacted activities in a
+ TransactionScope:</para>
+
+ <programlisting><![CDATA[
+AmqpProperties myDefaults = new AmqpProperties();
+myDefaults.Durable = true;
+amqpBinding.DefaultMessageProperties = myDefaults;
+ChannelFactory<IHelloService> channelFactory =
+new ChannelFactory<IHelloService>(amqpBinding, clientEndpoint);
+IHelloService clientProxy = channelFactory.CreateChannel();
+
+using (TransactionScope ts = new TransactionScope())
+{
+ AmqpProperties amqpProperties = new AmqpProperties();
+ clientProxy.SayHello("Greetings from WCF client");
+ // increment ExactlyOnceSent counter on DB
+ ts.Complete();
+}
+]]></programlisting>
+
+ </section>
+ </chapter>
+
+ <chapter>
+ <title>The .NET Binding for the C++ Messaging Client</title>
+ <para>
+ The .NET Binding for the C++ Qpid Messaging Client is a library that gives
+ any .NET program access to Qpid C++ Messaging objects and methods.
+ </para>
+ <section>
+ <title>.NET Binding for the C++ Messaging Client Component Architecture</title>
+
+ <programlisting><![CDATA[
+ +----------------------------+
+ | Dotnet examples |
+ | Managed C# |
+ +------+---------------+-----+
+ | |
+ V |
+ +---------------------------+ |
+ | .NET Managed Callback | |
+ | org.apache.qpid.messaging.| |
+ | sessionreceiver.dll | |
+ +----------------------+----+ |
+ | |
+managed V V
+(.NET) +--------------------------------+
+:::::::::::::::::::::::| .NET Binding Library |::::::::::::
+unmanaged | org.apache.qpid.messaging.dll |
+(Native Win32/64) +---------------+----------------+
+ |
+ |
+ +----------------+ |
+ | Native examples| |
+ | Unmanaged C++ | |
+ +--------+-------+ |
+ | |
+ V V
+ +----------------------------------+
+ | QPID Messaging C++ Libraries |
+ | qpid*.dll qmf*.dll |
+ +--------+--------------+----------+
+]]></programlisting>
+
+
+<para>This diagram illustrates the code and library components of the binding
+and the hierarchical relationships between them.</para>
+
+ <table id="table-Dotnet-Binding-Component-Architecture" >
+ <title>.NET Binding for the C++ Messaging Client Component Architecture</title>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>Component Name</entry>
+ <entry>Component Function</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>QPID Messaging C++ Libraries</entry>
+ <entry>The QPID Messaging C++ core run time system</entry>
+ </row>
+ <row>
+ <entry>Unmanaged C++ Example Source Programs</entry>
+ <entry>Ordinary C++ programs that illustrate using qpid/cpp Messaging directly
+ in a native Windows environment.</entry>
+ </row>
+ <row>
+ <entry>.NET Messaging Binding Library</entry>
+ <entry>The .NET Messaging Binding library provides interoprability between
+ managed .NET programs and the unmanaged, native Qpid Messaging C++ core
+ run time system. .NET programs create a Reference to this library thereby
+ exposing all of the native C++ Messaging functionality to programs
+ written in any .NET language.</entry>
+ </row>
+ <row>
+ <entry>.NET Messaging Managed Callback Library</entry>
+ <entry>An extension of the .NET Messaging Binding Library that provides message
+ callbacks in a managed .NET environment.</entry>
+ </row>
+ <row>
+ <entry>Managed C# .NET Example Source Programs</entry>
+ <entry>Various C# example programs that illustrate using .NET Binding for C++ Messaging in the .NET environment.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+
+ <section>
+ <title>.NET Binding for the C++ Messaging Client Examples</title>
+
+ <para>This chapter describes the various sample programs that
+ are available to illustrate common Qpid Messaging usage.</para>
+
+ <table id="table-Dotnet-Binding-Example-Client-Server">
+ <title>Example : Client - Server</title>
+ <tgroup cols="2">
+ <colspec colname="c1"/>
+ <colspec colname="c2"/>
+ <thead>
+ <row>
+ <entry>Example Name</entry>
+ <entry>Example Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>csharp.example.server</entry>
+ <entry>Creates a Receiver and listens for messages.
+ Upon message reception the message content is converted to upper case
+ and forwarded to the received message's ReplyTo address.</entry>
+ </row>
+ <row>
+ <entry>csharp.example.client</entry>
+ <entry>Sends a series of messages to the Server and prints the original message
+ content and the received message content.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table id="table-Dotnet-Binding-Example-MapSender-MapReceiver">
+ <title>Example : Map Sender – Map Receiver</title>
+ <tgroup cols="2">
+ <colspec colname="c1"/>
+ <colspec colname="c2"/>
+ <thead>
+ <row>
+ <entry>Example Name</entry>
+ <entry>Example Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>csharp.map.receiver</entry>
+ <entry>Creates a Receiver and listens for a map message.
+ Upon message reception the message is decoded and displayed on the console.</entry>
+ </row>
+ <row>
+ <entry>csharp.map.sender</entry>
+ <entry>Creates a map message and sends it to map.receiver.
+ The map message contains values for every supported .NET Messaging
+ Binding data type.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table id="table-Dotnet-Binding-Example-Spout-Drain">
+ <title>Example : Spout - Drain</title>
+ <tgroup cols="2">
+ <colspec colname="c1"/>
+ <colspec colname="c2"/>
+ <thead>
+ <row>
+ <entry>Example Name</entry>
+ <entry>Example Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>csharp.example.spout</entry>
+ <entry>Spout is a more complex example of code that generates a series of messages
+ and sends them to peer program Drain. Flexible command line arguments allow
+ the user to specify a variety of message and program options.</entry>
+ </row>
+ <row>
+ <entry>csharp.example.drain</entry>
+ <entry>Drain is a more complex example of code that receives a series of messages
+ and displays their contents on the console.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table id="table-Dotnet-Binding-Example-CallbackSender-CallbackReceiver">
+ <title>Example : Map Callback Sender – Map Callback Receiver</title>
+ <tgroup cols="2">
+ <colspec colname="c1"/>
+ <colspec colname="c2"/>
+ <thead>
+ <row>
+ <entry>Example Name</entry>
+ <entry>Example Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>csharp.map.callback.receiver</entry>
+ <entry>Creates a Receiver and listens for a map message.
+ Upon message reception the message is decoded and displayed on the console.
+ This example illustrates the use of the C# managed code callback mechanism
+ provided by .NET Messaging Binding Managed Callback Library.</entry>
+ </row>
+ <row>
+ <entry>csharp.map.callback.sender</entry>
+ <entry>Creates a map message and sends it to map_receiver.
+ The map message contains values for every supported .NET Messaging
+ Binding data type.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table id="table-Dotnet-Binding-Example-DeclareQueues">
+ <title>Example - Declare Queues</title>
+ <tgroup cols="2">
+ <colspec colname="c1"/>
+ <colspec colname="c2"/>
+ <thead>
+ <row>
+ <entry>Example Name</entry>
+ <entry>Example Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>csharp.example.declare_queues</entry>
+ <entry>A program to illustrate creating objects on a broker.
+ This program creates a queue used by spout and drain.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table id="table-Dotnet-Binding-Example-DirectSender-DirectReceiver">
+ <title>Example: Direct Sender - Direct Receiver</title>
+ <tgroup cols="2">
+ <colspec colname="c1"/>
+ <colspec colname="c2"/>
+ <thead>
+ <row>
+ <entry>Example Name</entry>
+ <entry>Example Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>csharp.direct.receiver</entry>
+ <entry>Creates a Receiver and listens for a messages.
+ Upon message reception the message is decoded and displayed on the console.</entry>
+ </row>
+ <row>
+ <entry>csharp.direct.sender</entry>
+ <entry> Creates a series of messages and sends them to csharp.direct.receiver.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table id="table-Dotnet-Binding-Example-Helloworld">
+ <title>Example: Hello World</title>
+ <tgroup cols="2">
+ <colspec colname="c1"/>
+ <colspec colname="c2"/>
+ <thead>
+ <row>
+ <entry>Example Name</entry>
+ <entry>Example Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>csharp.example.helloworld</entry>
+ <entry>A program to send a message and to receive the same message.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ </section>
+
+ <section>
+ <title>.NET Binding Class Mapping to Underlying C++ Messaging API</title>
+
+ <para>This chapter describes the specific mappings between
+ classes in the .NET Binding and the underlying C++ Messaging
+ API.</para>
+
+ <section>
+ <title>.NET Binding for the C++ Messaging API Class: Address</title>
+ <table id="table-Dotnet-Binding-Address">
+ <title>.NET Binding for the C++ Messaging API Class: Address</title>
+ <tgroup cols="2">
+ <colspec colname="c1" colwidth="1*"/>
+ <colspec colname="c2" colwidth="7*"/>
+ <thead>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Address</entry>
+ </row>
+ <row>
+ <entry>Language</entry>
+ <entry>Syntax</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>C++</entry>
+ <entry>class Address</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ref class Address</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Address();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Address();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Address(const std::string&amp; address);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Address(string address);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Address(const std::string&amp; name, const std::string&amp; subject, const qpid::types::Variant::Map&amp; options, const std::string&amp; type = "");</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Address(string name, string subject, Dictionary&lt;string, object&gt; options);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Address(string name, string subject, Dictionary&lt;string, object&gt; options, string type);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Address(const Address&amp; address);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Address(Address address);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Destructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>~Address();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>~Address();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>!Address();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Address&amp; operator=(const Address&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Address op_Assign(Address rhs);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Name</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getName() const;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setName(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string Name { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Subject</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getSubject() const;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setSubject(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string Subject { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Options</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const qpid::types::Variant::Map&amp; getOptions() const;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>qpid::types::Variant::Map&amp; getOptions();</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setOptions(const qpid::types::Variant::Map&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Dictionary&lt;string, object&gt; Options { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Type</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>std::string getType() const;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setType(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string Type { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Miscellaneous</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>std::string str() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string ToStr();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Miscellaneous</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>operator bool() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Miscellaneous</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool operator !() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>n/a</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ <section>
+ <title>.NET Binding for the C++ Messaging API Class: Connection</title>
+ <table id="table-Dotnet-Binding-Connection">
+ <title>.NET Binding for the C++ Messaging API Class: Connection</title>
+ <tgroup cols="2">
+ <colspec colname="c1" colwidth="1*"/>
+ <colspec colname="c2" colwidth="7*"/>
+ <thead>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Connection</entry>
+ </row>
+ <row>
+ <entry>Language</entry>
+ <entry>Syntax</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>C++</entry>
+ <entry>class Connection : public qpid::messaging::Handle&lt;ConnectionImpl&gt;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ref class Connection</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Connection(ConnectionImpl* impl);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Connection();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Connection(const std::string&amp; url, const qpid::types::Variant::Map&amp; options = qpid::types::Variant::Map());</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Connection(string url);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Connection(string url, Dictionary&lt;string, object&gt; options);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Connection(const std::string&amp; url, const std::string&amp; options);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Connection(string url, string options); </entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Connection(const Connection&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Connection(Connection connection);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Destructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>~Connection();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>~Connection();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>!Connection();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Connection&amp; operator=(const Connection&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Connection op_Assign(Connection rhs);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: SetOption</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setOption(const std::string&amp; name, const qpid::types::Variant&amp; value);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void SetOption(string name, object value);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: open</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void open();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Open();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: isOpen</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool isOpen();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool IsOpen { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: close</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void close();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Close();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: createTransactionalSession</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Session createTransactionalSession(const std::string&amp; name = std::string());</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session CreateTransactionalSession();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session CreateTransactionalSession(string name);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: createSession</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Session createSession(const std::string&amp; name = std::string());</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session CreateSession();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session CreateSession(string name);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: getSession</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Session getSession(const std::string&amp; name) const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session GetSession(string name);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: AuthenticatedUsername</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>std::string getAuthenticatedUsername();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string GetAuthenticatedUsername();</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ <section>
+ <title>.NET Binding for the C++ Messaging API Class: Duration</title>
+ <table id="table-Dotnet-Binding-Duration">
+ <title>.NET Binding for the C++ Messaging API Class: Duration</title>
+ <tgroup cols="2">
+ <colspec colname="c1" colwidth="1*"/>
+ <colspec colname="c2" colwidth="7*"/>
+ <thead>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Duration</entry>
+ </row>
+ <row>
+ <entry>Language</entry>
+ <entry>Syntax</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>C++</entry>
+ <entry>class Duration</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ref class Duration</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>explicit Duration(uint64_t milliseconds);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Duration(ulong mS);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Duration(Duration rhs);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Destructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>default</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>default</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>default</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Milliseconds</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint64_t getMilliseconds() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ulong Milliseconds { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Operator: *</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Duration operator*(const Duration&amp; duration, uint64_t multiplier);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public static Duration operator *(Duration dur, ulong multiplier);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public static Duration Multiply(Duration dur, ulong multiplier);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Duration operator*(uint64_t multiplier, const Duration&amp; duration);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public static Duration operator *(ulong multiplier, Duration dur);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public static Duration Multiply(ulong multiplier, Duration dur);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constants</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>static const Duration FOREVER;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>static const Duration IMMEDIATE;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>static const Duration SECOND;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>static const Duration MINUTE;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public sealed class DurationConstants</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public static Duration FORVER;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public static Duration IMMEDIATE;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public static Duration MINUTE;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public static Duration SECOND;</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ <section>
+ <title>.NET Binding for the C++ Messaging API Class: FailoverUpdates</title>
+ <table id="table-Dotnet-Binding-FailoverUpdates">
+ <title>.NET Binding for the C++ Messaging API Class: FailoverUpdates</title>
+ <tgroup cols="2">
+ <colspec colname="c1" colwidth="1*"/>
+ <colspec colname="c2" colwidth="7*"/>
+ <thead>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">.NET Binding Class: FailoverUpdates</entry>
+ </row>
+ <row>
+ <entry>Language</entry>
+ <entry>Syntax</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>C++</entry>
+ <entry>class FailoverUpdates</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ref class FailoverUpdates</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>FailoverUpdates(Connection&amp; connection);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public FailoverUpdates(Connection connection);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Destructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>~FailoverUpdates();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>~FailoverUpdates();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>!FailoverUpdates();</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ <section>
+ <title>.NET Binding for the C++ Messaging API Class: Message</title>
+ <table id="table-Dotnet-Binding-Message">
+ <title>.NET Binding for the C++ Messaging API Class: Message</title>
+ <tgroup cols="2">
+ <colspec colname="c1" colwidth="1*"/>
+ <colspec colname="c2" colwidth="7*"/>
+ <thead>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Message</entry>
+ </row>
+ <row>
+ <entry>Language</entry>
+ <entry>Syntax</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>C++</entry>
+ <entry>class Message</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ref class Message</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Message(const std::string&amp; bytes = std::string());</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>Message();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>Message(System::String ^ theStr);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>Message(System::Object ^ theValue);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>Message(array&lt;System::Byte&gt; ^ bytes);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Message(const char*, size_t);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Message(byte[] bytes, int offset, int size);</entry>
+ </row>
+ <row>
+ <entry> </entry>
+ <entry>Copy constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Message(const Message&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Message(Message message);</entry>
+ </row>
+ <row>
+ <entry> </entry>
+ <entry>Copy assignment operator</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Message&amp; operator=(const Message&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Message op_Assign(Message rhs);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Destructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>~Message();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>~Message();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>!Message()</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: ReplyTo</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setReplyTo(const Address&amp;);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const Address&amp; getReplyTo() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Address ReplyTo { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Subject</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setSubject(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getSubject() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string Subject { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: ContentType</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setContentType(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getContentType() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string ContentType { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: MessageId</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setMessageId(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getMessageId() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string MessageId { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: UserId</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setUserId(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getUserId() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string UserId { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: CorrelationId</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setCorrelationId(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getCorrelationId() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string CorrelationId { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Priority</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setPriority(uint8_t);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint8_t getPriority() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public byte Priority { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Ttl</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setTtl(Duration ttl);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Duration getTtl() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Duration Ttl { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Durable</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setDurable(bool durable);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool getDurable() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool Durable { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Redelivered</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool getRedelivered() const;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setRedelivered(bool);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool Redelivered { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: SetProperty</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setProperty(const std::string&amp;, const qpid::types::Variant&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void SetProperty(string name, object value);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Properties</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const qpid::types::Variant::Map&amp; getProperties() const;</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>qpid::types::Variant::Map&amp; getProperties();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Dictionary&lt;string, object&gt; Properties { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: SetContent</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setContent(const std::string&amp;);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setContent(const char* chars, size_t count);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void SetContent(byte[] bytes);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void SetContent(string content);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void SetContent(byte[] bytes, int offset, int size);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: GetContent</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>std::string getContent() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string GetContent();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void GetContent(byte[] arr);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void GetContent(Collection&lt;object&gt; __p1);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void GetContent(Dictionary&lt;string, object&gt; dict);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: GetContentPtr</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const char* getContentPtr() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: ContentSize</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>size_t getContentSize() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ulong ContentSize { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Struct: EncodingException</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>struct EncodingException : qpid::types::Exception</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: decode</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void decode(const Message&amp; message, qpid::types::Variant::Map&amp; map, const std::string&amp; encoding = std::string());</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void decode(const Message&amp; message, qpid::types::Variant::List&amp; list, const std::string&amp; encoding = std::string());</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: encode</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void encode(const qpid::types::Variant::Map&amp; map, Message&amp; message, const std::string&amp; encoding = std::string());</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void encode(const qpid::types::Variant::List&amp; list, Message&amp; message, const std::string&amp; encoding = std::string());</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: AsString</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string AsString(object obj);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string ListAsString(Collection&lt;object&gt; list);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string MapAsString(Dictionary&lt;string, object&gt; dict);</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ <section>
+ <title>.NET Binding for the C++ Messaging API Class: Receiver</title>
+ <table id="table-Dotnet-Binding-Receiver">
+ <title>.NET Binding for the C++ Messaging API Class: Receiver</title>
+ <tgroup cols="2">
+ <colspec colname="c1" colwidth="1*"/>
+ <colspec colname="c2" colwidth="7*"/>
+ <thead>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Receiver</entry>
+ </row>
+ <row>
+ <entry>Language</entry>
+ <entry>Syntax</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>C++</entry>
+ <entry>class Receiver</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ref class Receiver</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>Constructed object is returned by Session.CreateReceiver</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Receiver(const Receiver&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Receiver(Receiver receiver);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Destructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>~Receiver();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>~Receiver();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>!Receiver()</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Receiver&amp; operator=(const Receiver&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Receiver op_Assign(Receiver rhs);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Get</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool get(Message&amp; message, Duration timeout=Duration::FOREVER);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool Get(Message mmsgp);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool Get(Message mmsgp, Duration durationp);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Get</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Message get(Duration timeout=Duration::FOREVER);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Message Get();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Message Get(Duration durationp);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Fetch</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool fetch(Message&amp; message, Duration timeout=Duration::FOREVER);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool Fetch(Message mmsgp);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool Fetch(Message mmsgp, Duration duration);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Fetch</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Message fetch(Duration timeout=Duration::FOREVER);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Message Fetch();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Message Fetch(Duration durationp);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Capacity</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setCapacity(uint32_t);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint32_t getCapacity();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public uint Capacity { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Available</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint32_t getAvailable();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public uint Available { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Unsettled</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint32_t getUnsettled();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public uint Unsettled { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Close</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void close();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Close();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: IsClosed</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool isClosed() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool IsClosed { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Name</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getName() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string Name { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Session</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Session getSession() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session Session { get; }</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ <section>
+ <title>.NET Binding for the C++ Messaging API Class: Sender</title>
+ <table id="table-Dotnet-Binding-Sender">
+ <title>.NET Binding for the C++ Messaging API Class: Sender</title>
+ <tgroup cols="2">
+ <colspec colname="c1" colwidth="1*"/>
+ <colspec colname="c2" colwidth="7*"/>
+ <thead>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Sender</entry>
+ </row>
+ <row>
+ <entry>Language</entry>
+ <entry>Syntax</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>C++</entry>
+ <entry>class Sender</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ref class Sender</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>Constructed object is returned by Session.CreateSender</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Sender(const Sender&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Sender(Sender sender);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Destructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>~Sender();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>~Sender();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>!Sender()</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Sender&amp; operator=(const Sender&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Sender op_Assign(Sender rhs);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Send</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void send(const Message&amp; message, bool sync=false);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Send(Message mmsgp);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Send(Message mmsgp, bool sync);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Close</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void close();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Close();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Capacity</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void setCapacity(uint32_t);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint32_t getCapacity();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public uint Capacity { get; set; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Available</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint32_t getAvailable();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public uint Available { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Unsettled</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint32_t getUnsettled();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public uint Unsettled { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Name</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>const std::string&amp; getName() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public string Name { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Session</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Session getSession() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session Session { get; }</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ <section>
+ <title>.NET Binding for the C++ Messaging API Class: Session</title>
+ <table id="table-Dotnet-Binding-Session">
+ <title>.NET Binding for the C++ Messaging API Class: Session</title>
+ <tgroup cols="2">
+ <colspec colname="c1" colwidth="1*"/>
+ <colspec colname="c2" colwidth="7*"/>
+ <thead>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">.NET Binding Class: Session</entry>
+ </row>
+ <row>
+ <entry>Language</entry>
+ <entry>Syntax</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>C++</entry>
+ <entry>class Session</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public ref class Session</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Constructor</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>Constructed object is returned by Connection.CreateSession</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy constructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Session(const Session&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session(Session session);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Destructor</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>~Session();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>~Session();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Finalizer</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>n/a</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>!Session()</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Copy assignment operator</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Session&amp; operator=(const Session&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Session op_Assign(Session rhs);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Close</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void close();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Close();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Commit</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void commit();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Commit();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Rollback</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void rollback();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Rollback();</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Acknowledge</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void acknowledge(bool sync=false);</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void acknowledge(Message&amp;, bool sync=false);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Acknowledge();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Acknowledge(bool sync);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Acknowledge(Message __p1);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Acknowledge(Message __p1, bool __p2);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Reject</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void reject(Message&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Reject(Message __p1);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Release</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void release(Message&amp;);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Release(Message __p1);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: Sync</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void sync(bool block=true);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Sync();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void Sync(bool block);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Receivable</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint32_t getReceivable();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public uint Receivable { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: UnsettledAcks</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>uint32_t getUnsettledAcks();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public uint UnsetledAcks { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: NextReceiver</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool nextReceiver(Receiver&amp;, Duration timeout=Duration::FOREVER);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool NextReceiver(Receiver rcvr);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool NextReceiver(Receiver rcvr, Duration timeout);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: NextReceiver</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Receiver nextReceiver(Duration timeout=Duration::FOREVER);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Receiver NextReceiver();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Receiver NextReceiver(Duration timeout);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: CreateSender</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Sender createSender(const Address&amp; address);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Sender CreateSender(Address address);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: CreateSender</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Sender createSender(const std::string&amp; address);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Sender CreateSender(string address);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: CreateReceiver</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Receiver createReceiver(const Address&amp; address);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Receiver CreateReceiver(Address address);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: CreateReceiver</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Receiver createReceiver(const std::string&amp; address);</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Receiver CreateReceiver(string address);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: GetSender</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Sender getSender(const std::string&amp; name) const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Sender GetSender(string name);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: GetReceiver</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Receiver getReceiver(const std::string&amp; name) const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Receiver GetReceiver(string name);</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: Connection</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>Connection getConnection() const;</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public Connection Connection { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Property: HasError</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>bool hasError();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public bool HasError { get; }</entry>
+ </row>
+ <row>
+ <entry namest="c1" nameend="c2" align="center">Method: CheckError</entry>
+ </row>
+ <row>
+ <entry>C++</entry>
+ <entry>void checkError();</entry>
+ </row>
+ <row>
+ <entry>.NET</entry>
+ <entry>public void CheckError();</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+ <section>
+ <title>.NET Binding Class: SessionReceiver</title>
+ <para>
+ The SessionReceiver class provides a convenient callback
+ mechanism for Messages received by all Receivers on a given
+ Session.
+ </para>
+ <para>
+ <programlisting><![CDATA[
+using Org.Apache.Qpid.Messaging;
+using System;
+
+namespace Org.Apache.Qpid.Messaging.SessionReceiver
+{
+ public interface ISessionReceiver
+ {
+ void SessionReceiver(Receiver receiver, Message message);
+ }
+
+ public class CallbackServer
+ {
+ public CallbackServer(Session session, ISessionReceiver callback);
+
+ public void Close();
+ }
+}
+]]>
+ </programlisting>
+ </para>
+ <para>
+ To use this class a client program includes references to both
+ Org.Apache.Qpid.Messaging and Org.Apache.Qpid.Messaging.SessionReceiver.
+ The calling program creates a function that implements the
+ ISessionReceiver interface. This function will be called whenever
+ message is received by the session. The callback process is started
+ by creating a CallbackServer and will continue to run until the
+ client program calls the CallbackServer.Close function.
+ </para>
+ <para>
+ A complete operating example of using the SessionReceiver callback
+ is contained in cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver.
+ </para>
+ </section>
+ </section>
+ </chapter>
+</book>
+
+<!--
+ - client code remains exactly the same, but routing behavior
+ changes
+ - exchanges drop messages if nobody is listening, so we need to
+ start drain first
+ - drain will exit immediately if the source is empty (note that
+ this is actually a semantic guarantee provided by the API, we
+ know for a fact that the source is empty when drain/fetch
+ reports it, no fudge factor timeout is required [this assumes
+ nobody is concurrently publishing of course])
+ - drain -f invokes blocking fetch (you could use a timeout here also)
+ -->
diff --git a/doc/book/xsl/html-custom.xsl b/doc/book/xsl/html-custom.xsl
index 94ba3b67f9..dbfbcc44c7 100644
--- a/doc/book/xsl/html-custom.xsl
+++ b/doc/book/xsl/html-custom.xsl
@@ -125,7 +125,7 @@
<DIV class="menu_box_body">
<H3>Documentation</H3>
<UL>
- <LI><A href="http://qpid.apache.org/documentation.html#doc-release">0.14 Release</A></LI>
+ <LI><A href="http://qpid.apache.org/documentation.html#doc-release">Latest Release</A></LI>
<LI><A href="http://qpid.apache.org/documentation.html#doc-trunk">Trunk</A></LI>
<LI><A href="http://qpid.apache.org/documentation.html#doc-archives">Archive</A></LI>
</UL>
diff --git a/extras/dispatch/CMakeLists.txt b/extras/dispatch/CMakeLists.txt
new file mode 100644
index 0000000000..bc1812fb6b
--- /dev/null
+++ b/extras/dispatch/CMakeLists.txt
@@ -0,0 +1,99 @@
+##
+## 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.
+##
+
+cmake_minimum_required(VERSION 2.6)
+include(CheckLibraryExists)
+include(CheckSymbolExists)
+
+project(qpid-dispatch C)
+
+set (SO_VERSION_MAJOR 0)
+set (SO_VERSION_MINOR 1)
+set (SO_VERSION "${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}")
+
+if (NOT DEFINED LIB_SUFFIX)
+ get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
+ if ("${LIB64}" STREQUAL "TRUE" AND ${CMAKE_SIZEOF_VOID_P} STREQUAL "8")
+ set(LIB_SUFFIX 64)
+ else()
+ set(LIB_SUFFIX "")
+ endif()
+endif()
+
+set(INCLUDE_INSTALL_DIR include CACHE PATH "Include file directory")
+set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Library object file directory")
+set(SYSCONF_INSTALL_DIR etc CACHE PATH "System read only configuration directory")
+set(SHARE_INSTALL_DIR share CACHE PATH "Shared read only data directory")
+set(MAN_INSTALL_DIR share/man CACHE PATH "Manpage directory")
+
+include_directories(
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ ${proton_include}
+ )
+
+##
+## Find dependencies
+##
+find_library(proton_lib qpid-proton)
+find_library(pthread_lib pthread)
+find_library(rt_lib rt)
+find_path(proton_include proton/driver.h)
+
+set(CMAKE_C_FLAGS "-pthread -Wall -Werror")
+set(CATCH_UNDEFINED "-Wl,--no-undefined")
+
+##
+## Build the Multi-Threaded Server Library
+##
+set(server_SOURCES
+ src/agent.c
+ src/alloc.c
+ src/auth.c
+ src/buffer.c
+ src/container.c
+ src/hash.c
+ src/iovec.c
+ src/iterator.c
+ src/log.c
+ src/message.c
+ src/posix/threading.c
+ src/router_node.c
+ src/server.c
+ src/timer.c
+ src/work_queue.c
+ )
+
+add_library(qpid-dispatch SHARED ${server_SOURCES})
+target_link_libraries(qpid-dispatch ${proton_lib} ${pthread_lib} ${rt_lib})
+set_target_properties(qpid-dispatch PROPERTIES
+ VERSION "${SO_VERSION}"
+ SOVERSION "${SO_VERSION_MAJOR}"
+ LINK_FLAGS "${CATCH_UNDEFINED}"
+ )
+install(TARGETS qpid-dispatch
+ LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+file(GLOB headers "include/qpid/dispatch/*.h")
+install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR}/qpid/dispatch)
+
+##
+## Build Tests
+##
+add_subdirectory(router)
+add_subdirectory(tests)
diff --git a/extras/dispatch/include/qpid/dispatch/agent.h b/extras/dispatch/include/qpid/dispatch/agent.h
new file mode 100644
index 0000000000..d53d24d4d4
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/agent.h
@@ -0,0 +1,108 @@
+#ifndef __dispatch_agent_h__
+#define __dispatch_agent_h__ 1
+/*
+ * 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.
+ */
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+/**
+ * \defgroup Container Management Agent
+ * @{
+ */
+
+typedef struct dx_agent_class_t dx_agent_class_t;
+
+
+/**
+ * \brief Get Schema Data Handler
+ *
+ * @param context The handler context supplied in dx_agent_register.
+ */
+typedef void (*dx_agent_schema_cb_t)(void* context);
+
+
+/**
+ * \brief Query Handler
+ *
+ * @param context The handler context supplied in dx_agent_register.
+ * @param id The identifier of the instance being queried or NULL for all instances.
+ * @param correlator The correlation handle to be used in calls to dx_agent_value_*
+ */
+typedef void (*dx_agent_query_cb_t)(void* context, const char *id, const void *correlator);
+
+
+/**
+ * \brief Initialize the agent module and prepare it for operation.
+ *
+ */
+void dx_agent_initialize();
+
+
+/**
+ * \brief Finalize the agent after it has stopped running.
+ */
+void dx_agent_finalize(void);
+
+
+/**
+ * \brief Register a class/object-type with the agent.
+ */
+dx_agent_class_t *dx_agent_register_class(const char *fqname,
+ void *context,
+ dx_agent_schema_cb_t schema_handler,
+ dx_agent_query_cb_t query_handler);
+
+/**
+ * \brief Register an event-type with the agent.
+ */
+dx_agent_class_t *dx_agent_register_event(const char *fqname,
+ void *context,
+ dx_agent_schema_cb_t schema_handler);
+
+/**
+ *
+ */
+void dx_agent_value_string(const void *correlator, const char *key, const char *value);
+void dx_agent_value_uint(const void *correlator, const char *key, uint64_t value);
+void dx_agent_value_null(const void *correlator, const char *key);
+void dx_agent_value_boolean(const void *correlator, const char *key, bool value);
+void dx_agent_value_binary(const void *correlator, const char *key, const uint8_t *value, size_t len);
+void dx_agent_value_uuid(const void *correlator, const char *key, const uint8_t *value);
+void dx_agent_value_timestamp(const void *correlator, const char *key, uint64_t value);
+
+
+/**
+ *
+ */
+void dx_agent_value_complete(const void *correlator, bool more);
+
+
+/**
+ *
+ */
+void *dx_agent_raise_event(dx_agent_class_t *event);
+
+
+/**
+ * @}
+ */
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/alloc.h b/extras/dispatch/include/qpid/dispatch/alloc.h
new file mode 100644
index 0000000000..ae4190ad89
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/alloc.h
@@ -0,0 +1,72 @@
+#ifndef __dispatch_alloc_h__
+#define __dispatch_alloc_h__ 1
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <qpid/dispatch/threading.h>
+
+typedef struct dx_alloc_pool_t dx_alloc_pool_t;
+
+typedef struct {
+ int transfer_batch_size;
+ int local_free_list_max;
+ int global_free_list_max;
+} dx_alloc_config_t;
+
+typedef struct {
+ uint64_t total_alloc_from_heap;
+ uint64_t total_free_to_heap;
+ uint64_t held_by_threads;
+ uint64_t batches_rebalanced_to_threads;
+ uint64_t batches_rebalanced_to_global;
+} dx_alloc_stats_t;
+
+typedef struct {
+ char *type_name;
+ size_t type_size;
+ size_t *additional_size;
+ size_t total_size;
+ dx_alloc_config_t *config;
+ dx_alloc_stats_t *stats;
+ dx_alloc_pool_t *global_pool;
+ sys_mutex_t *lock;
+} dx_alloc_type_desc_t;
+
+
+void *dx_alloc(dx_alloc_type_desc_t *desc, dx_alloc_pool_t **tpool);
+void dx_dealloc(dx_alloc_type_desc_t *desc, dx_alloc_pool_t **tpool, void *p);
+
+
+#define ALLOC_DECLARE(T) \
+ T *new_##T(); \
+ void free_##T(T *p)
+
+#define ALLOC_DEFINE_CONFIG(T,S,A,C) \
+ dx_alloc_type_desc_t __desc_##T = {#T, S, A, 0, C, 0, 0, 0}; \
+ __thread dx_alloc_pool_t *__local_pool_##T = 0; \
+ T *new_##T() { return (T*) dx_alloc(&__desc_##T, &__local_pool_##T); } \
+ void free_##T(T *p) { dx_dealloc(&__desc_##T, &__local_pool_##T, (void*) p); } \
+ dx_alloc_stats_t *alloc_stats_##T() { return __desc_##T.stats; }
+
+#define ALLOC_DEFINE(T) ALLOC_DEFINE_CONFIG(T, sizeof(T), 0, 0)
+
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/buffer.h b/extras/dispatch/include/qpid/dispatch/buffer.h
new file mode 100644
index 0000000000..1c372b265d
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/buffer.h
@@ -0,0 +1,79 @@
+#ifndef __dispatch_buffer_h__
+#define __dispatch_buffer_h__ 1
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/ctools.h>
+
+typedef struct dx_buffer_t dx_buffer_t;
+
+DEQ_DECLARE(dx_buffer_t, dx_buffer_list_t);
+
+struct dx_buffer_t {
+ DEQ_LINKS(dx_buffer_t);
+ unsigned int size;
+};
+
+/**
+ */
+void dx_buffer_set_size(size_t size);
+
+/**
+ */
+dx_buffer_t *dx_allocate_buffer(void);
+
+/**
+ * @param buf A pointer to an allocated buffer
+ */
+void dx_free_buffer(dx_buffer_t *buf);
+
+/**
+ * @param buf A pointer to an allocated buffer
+ * @return A pointer to the first octet in the buffer
+ */
+unsigned char *dx_buffer_base(dx_buffer_t *buf);
+
+/**
+ * @param buf A pointer to an allocated buffer
+ * @return A pointer to the first free octet in the buffer, the insert point for new data.
+ */
+unsigned char *dx_buffer_cursor(dx_buffer_t *buf);
+
+/**
+ * @param buf A pointer to an allocated buffer
+ * @return The number of octets in the buffer's free space, how many octets may be inserted.
+ */
+size_t dx_buffer_capacity(dx_buffer_t *buf);
+
+/**
+ * @param buf A pointer to an allocated buffer
+ * @return The number of octets of data in the buffer
+ */
+size_t dx_buffer_size(dx_buffer_t *buf);
+
+/**
+ * Notify the buffer that octets have been inserted at the buffer's cursor. This will advance the
+ * cursor by len octets.
+ *
+ * @param buf A pointer to an allocated buffer
+ * @param len The number of octets that have been appended to the buffer
+ */
+void dx_buffer_insert(dx_buffer_t *buf, size_t len);
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/container.h b/extras/dispatch/include/qpid/dispatch/container.h
new file mode 100644
index 0000000000..01a24fbbef
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/container.h
@@ -0,0 +1,129 @@
+#ifndef __dispatch_container_h__
+#define __dispatch_container_h__ 1
+/*
+ * 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.
+ */
+
+#include <proton/engine.h>
+#include <qpid/dispatch/server.h>
+#include <qpid/dispatch/alloc.h>
+#include <qpid/dispatch/ctools.h>
+
+typedef uint8_t dx_dist_mode_t;
+#define DX_DIST_COPY 0x01
+#define DX_DIST_MOVE 0x02
+#define DX_DIST_BOTH 0x03
+
+/**
+ * Node Lifetime Policy (see AMQP 3.5.9)
+ */
+typedef enum {
+ DX_LIFE_PERMANENT,
+ DX_LIFE_DELETE_CLOSE,
+ DX_LIFE_DELETE_NO_LINKS,
+ DX_LIFE_DELETE_NO_MESSAGES,
+ DX_LIFE_DELETE_NO_LINKS_MESSAGES
+} dx_lifetime_policy_t;
+
+
+/**
+ * Link Direction
+ */
+typedef enum {
+ DX_INCOMING,
+ DX_OUTGOING
+} dx_direction_t;
+
+
+typedef struct dx_node_t dx_node_t;
+typedef struct dx_link_t dx_link_t;
+
+typedef void (*dx_container_delivery_handler_t) (void *node_context, dx_link_t *link, pn_delivery_t *delivery);
+typedef int (*dx_container_link_handler_t) (void *node_context, dx_link_t *link);
+typedef int (*dx_container_link_detach_handler_t) (void *node_context, dx_link_t *link, int closed);
+typedef void (*dx_container_node_handler_t) (void *type_context, dx_node_t *node);
+typedef void (*dx_container_conn_handler_t) (void *type_context, dx_connection_t *conn);
+
+typedef struct {
+ char *type_name;
+ void *type_context;
+ int allow_dynamic_creation;
+
+ //
+ // Node-Instance Handlers
+ //
+ dx_container_delivery_handler_t rx_handler;
+ dx_container_delivery_handler_t tx_handler;
+ dx_container_delivery_handler_t disp_handler;
+ dx_container_link_handler_t incoming_handler;
+ dx_container_link_handler_t outgoing_handler;
+ dx_container_link_handler_t writable_handler;
+ dx_container_link_detach_handler_t link_detach_handler;
+
+ //
+ // Node-Type Handlers
+ //
+ dx_container_node_handler_t node_created_handler;
+ dx_container_node_handler_t node_destroyed_handler;
+ dx_container_conn_handler_t inbound_conn_open_handler;
+ dx_container_conn_handler_t outbound_conn_open_handler;
+} dx_node_type_t;
+
+void dx_container_initialize(void);
+void dx_container_finalize(void);
+
+int dx_container_register_node_type(const dx_node_type_t *nt);
+
+void dx_container_set_default_node_type(const dx_node_type_t *nt,
+ void *node_context,
+ dx_dist_mode_t supported_dist);
+
+dx_node_t *dx_container_create_node(const dx_node_type_t *nt,
+ const char *name,
+ void *node_context,
+ dx_dist_mode_t supported_dist,
+ dx_lifetime_policy_t life_policy);
+void dx_container_destroy_node(dx_node_t *node);
+
+void dx_container_node_set_context(dx_node_t *node, void *node_context);
+dx_dist_mode_t dx_container_node_get_dist_modes(const dx_node_t *node);
+dx_lifetime_policy_t dx_container_node_get_life_policy(const dx_node_t *node);
+
+dx_link_t *dx_link(dx_node_t *node, dx_connection_t *conn, dx_direction_t dir, const char *name);
+void dx_link_set_context(dx_link_t *link, void *link_context);
+void *dx_link_get_context(dx_link_t *link);
+pn_link_t *dx_link_pn(dx_link_t *link);
+pn_terminus_t *dx_link_source(dx_link_t *link);
+pn_terminus_t *dx_link_target(dx_link_t *link);
+pn_terminus_t *dx_link_remote_source(dx_link_t *link);
+pn_terminus_t *dx_link_remote_target(dx_link_t *link);
+void dx_link_activate(dx_link_t *link);
+void dx_link_close(dx_link_t *link);
+
+
+typedef struct dx_link_item_t dx_link_item_t;
+
+struct dx_link_item_t {
+ DEQ_LINKS(dx_link_item_t);
+ dx_link_t *link;
+};
+
+ALLOC_DECLARE(dx_link_item_t);
+DEQ_DECLARE(dx_link_item_t, dx_link_list_t);
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/ctools.h b/extras/dispatch/include/qpid/dispatch/ctools.h
new file mode 100644
index 0000000000..33178a23ee
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/ctools.h
@@ -0,0 +1,146 @@
+#ifndef __dispatch_ctools_h__
+#define __dispatch_ctools_h__ 1
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <assert.h>
+
+#define CT_ASSERT(exp) { assert(exp); }
+
+#define NEW(t) (t*) malloc(sizeof(t))
+#define NEW_ARRAY(t,n) (t*) malloc(sizeof(t)*(n))
+#define NEW_PTR_ARRAY(t,n) (t**) malloc(sizeof(t*)*(n))
+
+#define DEQ_DECLARE(i,d) typedef struct { \
+ i *head; \
+ i *tail; \
+ i *scratch; \
+ size_t size; \
+ } d
+
+#define DEQ_LINKS(t) t *prev; t *next
+
+#define DEQ_INIT(d) do { (d).head = 0; (d).tail = 0; (d).scratch = 0; (d).size = 0; } while (0)
+#define DEQ_ITEM_INIT(i) do { (i)->next = 0; (i)->prev = 0; } while(0)
+#define DEQ_HEAD(d) ((d).head)
+#define DEQ_TAIL(d) ((d).tail)
+#define DEQ_SIZE(d) ((d).size)
+#define DEQ_NEXT(i) (i)->next
+#define DEQ_PREV(i) (i)->prev
+
+#define DEQ_INSERT_HEAD(d,i) \
+do { \
+ CT_ASSERT((i)->next == 0); \
+ CT_ASSERT((i)->prev == 0); \
+ if ((d).head) { \
+ (i)->next = (d).head; \
+ (d).head->prev = i; \
+ } else { \
+ (d).tail = i; \
+ (i)->next = 0; \
+ CT_ASSERT((d).size == 0); \
+ } \
+ (i)->prev = 0; \
+ (d).head = i; \
+ (d).size++; \
+} while (0)
+
+#define DEQ_INSERT_TAIL(d,i) \
+do { \
+ CT_ASSERT((i)->next == 0); \
+ CT_ASSERT((i)->prev == 0); \
+ if ((d).tail) { \
+ (i)->prev = (d).tail; \
+ (d).tail->next = i; \
+ } else { \
+ (d).head = i; \
+ (i)->prev = 0; \
+ CT_ASSERT((d).size == 0); \
+ } \
+ (i)->next = 0; \
+ (d).tail = i; \
+ (d).size++; \
+} while (0)
+
+#define DEQ_REMOVE_HEAD(d) \
+do { \
+ CT_ASSERT((d).head); \
+ if ((d).head) { \
+ (d).scratch = (d).head; \
+ (d).head = (d).head->next; \
+ if ((d).head == 0) { \
+ (d).tail = 0; \
+ CT_ASSERT((d).size == 1); \
+ } else \
+ (d).head->prev = 0; \
+ (d).size--; \
+ (d).scratch->next = 0; \
+ (d).scratch->prev = 0; \
+ } \
+} while (0)
+
+#define DEQ_REMOVE_TAIL(d) \
+do { \
+ CT_ASSERT((d).tail); \
+ if ((d).tail) { \
+ (d).scratch = (d).tail; \
+ (d).tail = (d).tail->prev; \
+ if ((d).tail == 0) { \
+ (d).head = 0; \
+ CT_ASSERT((d).size == 1); \
+ } else \
+ (d).tail->next = 0; \
+ (d).size--; \
+ (d).scratch->next = 0; \
+ (d).scratch->prev = 0; \
+ } \
+} while (0)
+
+#define DEQ_INSERT_AFTER(d,i,a) \
+do { \
+ CT_ASSERT((i)->next == 0); \
+ CT_ASSERT((i)->prev == 0); \
+ if ((a)->next) \
+ (a)->next->prev = (i); \
+ else \
+ (d).tail = (i); \
+ (i)->next = (a)->next; \
+ (i)->prev = (a); \
+ (a)->next = (i); \
+ (d).size++; \
+} while (0)
+
+#define DEQ_REMOVE(d,i) \
+do { \
+ if ((i)->next) \
+ (i)->next->prev = (i)->prev; \
+ else \
+ (d).tail = (i)->prev; \
+ if ((i)->prev) \
+ (i)->prev->next = (i)->next; \
+ else \
+ (d).head = (i)->next; \
+ (d).size--; \
+ (i)->next = 0; \
+ (i)->prev = 0; \
+ CT_ASSERT((d).size || (!(d).head && !(d).tail)); \
+} while (0)
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/hash.h b/extras/dispatch/include/qpid/dispatch/hash.h
new file mode 100644
index 0000000000..7f4a4bb950
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/hash.h
@@ -0,0 +1,37 @@
+#ifndef __dispatch_hash_h__
+#define __dispatch_hash_h__ 1
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <qpid/dispatch/iterator.h>
+
+typedef struct hash_t hash_t;
+
+hash_t *hash(int bucket_exponent, int batch_size, int value_is_const);
+void hash_free(hash_t *h);
+
+size_t hash_size(hash_t *h);
+int hash_insert(hash_t *h, dx_field_iterator_t *key, void *val);
+int hash_insert_const(hash_t *h, dx_field_iterator_t *key, const void *val);
+int hash_retrieve(hash_t *h, dx_field_iterator_t *key, void **val);
+int hash_retrieve_const(hash_t *h, dx_field_iterator_t *key, const void **val);
+int hash_remove(hash_t *h, dx_field_iterator_t *key);
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/iovec.h b/extras/dispatch/include/qpid/dispatch/iovec.h
new file mode 100644
index 0000000000..5b56c638ff
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/iovec.h
@@ -0,0 +1,32 @@
+#ifndef __dispatch_iovec_h__
+#define __dispatch_iovec_h__ 1
+/*
+ * 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.
+ */
+
+#include <sys/uio.h>
+
+typedef struct dx_iovec_t dx_iovec_t;
+
+dx_iovec_t *dx_iovec(int vector_count);
+void dx_iovec_free(dx_iovec_t *iov);
+struct iovec *dx_iovec_array(dx_iovec_t *iov);
+int dx_iovec_count(dx_iovec_t *iov);
+
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/iterator.h b/extras/dispatch/include/qpid/dispatch/iterator.h
new file mode 100644
index 0000000000..9844286483
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/iterator.h
@@ -0,0 +1,113 @@
+#ifndef __dispatch_iterator_h__
+#define __dispatch_iterator_h__ 1
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/buffer.h>
+
+/**
+ * The field iterator is used to access fields within a buffer chain.
+ * It shields the user from the fact that the field may be split across
+ * one or more physical buffers.
+ */
+typedef struct dx_field_iterator_t dx_field_iterator_t;
+
+/**
+ * Iterator views allow the code traversing the field to see a transformed
+ * view of the raw field.
+ *
+ * ITER_VIEW_ALL - No transformation of the raw field data
+ *
+ * ITER_VIEW_NO_HOST - Remove the scheme and host fields from the view
+ *
+ * amqp://host.domain.com:port/node-id/node/specific
+ * ^^^^^^^^^^^^^^^^^^^^^
+ * node-id/node/specific
+ * ^^^^^^^^^^^^^^^^^^^^^
+ *
+ * ITER_VIEW_NODE_ID - Isolate the node identifier from an address
+ *
+ * amqp://host.domain.com:port/node-id/node/specific
+ * ^^^^^^^
+ * node-id/node/specific
+ * ^^^^^^^
+ *
+ * ITER_VIEW_NODE_SPECIFIC - Isolate node-specific text from an address
+ *
+ * amqp://host.domain.com:port/node-id/node/specific
+ * ^^^^^^^^^^^^^
+ * node-id/node/specific
+ * ^^^^^^^^^^^^^
+ */
+typedef enum {
+ ITER_VIEW_ALL,
+ ITER_VIEW_NO_HOST,
+ ITER_VIEW_NODE_ID,
+ ITER_VIEW_NODE_SPECIFIC
+} dx_iterator_view_t;
+
+/**
+ * Create an iterator from a null-terminated string.
+ *
+ * The "text" string must stay intact for the whole life of the iterator. The iterator
+ * does not copy the string, it references it.
+ */
+dx_field_iterator_t* dx_field_iterator_string(const char *text,
+ dx_iterator_view_t view);
+
+/**
+ * Create an iterator from a field in a buffer chain
+ */
+dx_field_iterator_t *dx_field_iterator_buffer(dx_buffer_t *buffer,
+ int offset,
+ int length,
+ dx_iterator_view_t view);
+
+/**
+ * Free an iterator
+ */
+void dx_field_iterator_free(dx_field_iterator_t *iter);
+
+/**
+ * Reset the iterator to the first octet and set a new view
+ */
+void dx_field_iterator_reset(dx_field_iterator_t *iter,
+ dx_iterator_view_t view);
+
+/**
+ * Return the current octet in the iterator's view and step to the next.
+ */
+unsigned char dx_field_iterator_octet(dx_field_iterator_t *iter);
+
+/**
+ * Return true iff the iterator has no more octets in the view.
+ */
+int dx_field_iterator_end(dx_field_iterator_t *iter);
+
+/**
+ * Compare an input string to the iterator's view. Return true iff they are equal.
+ */
+int dx_field_iterator_equal(dx_field_iterator_t *iter, unsigned char *string);
+
+/**
+ * Return a copy of the iterator's view.
+ */
+unsigned char *dx_field_iterator_copy(dx_field_iterator_t *iter);
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/log.h b/extras/dispatch/include/qpid/dispatch/log.h
new file mode 100644
index 0000000000..cbea50f266
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/log.h
@@ -0,0 +1,31 @@
+#ifndef __dispatch_log_h__
+#define __dispatch_log_h__ 1
+/*
+ * 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.
+ */
+
+#define LOG_NONE 0x00000000
+#define LOG_TRACE 0x00000001
+#define LOG_ERROR 0x00000002
+#define LOG_INFO 0x00000004
+
+void dx_log(const char *module, int cls, const char *fmt, ...);
+
+void dx_log_set_mask(int mask);
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/message.h b/extras/dispatch/include/qpid/dispatch/message.h
new file mode 100644
index 0000000000..41983c44a1
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/message.h
@@ -0,0 +1,165 @@
+#ifndef __dispatch_message_h__
+#define __dispatch_message_h__ 1
+/*
+ * 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.
+ */
+
+#include <proton/engine.h>
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/alloc.h>
+#include <qpid/dispatch/iterator.h>
+#include <qpid/dispatch/buffer.h>
+#include <qpid/dispatch/iovec.h>
+
+// Callback for status change (confirmed persistent, loaded-in-memory, etc.)
+
+typedef struct dx_message_t dx_message_t;
+
+DEQ_DECLARE(dx_message_t, dx_message_list_t);
+
+struct dx_message_t {
+ DEQ_LINKS(dx_message_t);
+ // Private members not listed here.
+};
+
+typedef enum {
+ DX_DEPTH_NONE,
+ DX_DEPTH_HEADER,
+ DX_DEPTH_DELIVERY_ANNOTATIONS,
+ DX_DEPTH_MESSAGE_ANNOTATIONS,
+ DX_DEPTH_PROPERTIES,
+ DX_DEPTH_APPLICATION_PROPERTIES,
+ DX_DEPTH_BODY,
+ DX_DEPTH_ALL
+} dx_message_depth_t;
+
+
+typedef enum {
+ //
+ // Message Sections
+ //
+ DX_FIELD_HEADER,
+ DX_FIELD_DELIVERY_ANNOTATION,
+ DX_FIELD_MESSAGE_ANNOTATION,
+ DX_FIELD_PROPERTIES,
+ DX_FIELD_APPLICATION_PROPERTIES,
+ DX_FIELD_BODY,
+ DX_FIELD_FOOTER,
+
+ //
+ // Fields of the Header Section
+ //
+ DX_FIELD_DURABLE,
+ DX_FIELD_PRIORITY,
+ DX_FIELD_TTL,
+ DX_FIELD_FIRST_ACQUIRER,
+ DX_FIELD_DELIVERY_COUNT,
+
+ //
+ // Fields of the Properties Section
+ //
+ DX_FIELD_MESSAGE_ID,
+ DX_FIELD_USER_ID,
+ DX_FIELD_TO,
+ DX_FIELD_SUBJECT,
+ DX_FIELD_REPLY_TO,
+ DX_FIELD_CORRELATION_ID,
+ DX_FIELD_CONTENT_TYPE,
+ DX_FIELD_CONTENT_ENCODING,
+ DX_FIELD_ABSOLUTE_EXPIRY_TIME,
+ DX_FIELD_CREATION_TIME,
+ DX_FIELD_GROUP_ID,
+ DX_FIELD_GROUP_SEQUENCE,
+ DX_FIELD_REPLY_TO_GROUP_ID
+} dx_message_field_t;
+
+//
+// Functions for allocation
+//
+dx_message_t *dx_allocate_message(void);
+void dx_free_message(dx_message_t *qm);
+dx_message_t *dx_message_copy(dx_message_t *qm);
+int dx_message_persistent(dx_message_t *qm);
+int dx_message_in_memory(dx_message_t *qm);
+
+void dx_message_set_out_delivery(dx_message_t *msg, pn_delivery_t *delivery);
+pn_delivery_t *dx_message_out_delivery(dx_message_t *msg);
+void dx_message_set_in_delivery(dx_message_t *msg, pn_delivery_t *delivery);
+pn_delivery_t *dx_message_in_delivery(dx_message_t *msg);
+
+//
+// Functions for received messages
+//
+dx_message_t *dx_message_receive(pn_delivery_t *delivery);
+void dx_message_send(dx_message_t *msg, pn_link_t *link);
+
+int dx_message_check(dx_message_t *msg, dx_message_depth_t depth);
+dx_field_iterator_t *dx_message_field_iterator(dx_message_t *msg, dx_message_field_t field);
+dx_iovec_t *dx_message_field_iovec(dx_message_t *msg, dx_message_field_t field);
+
+pn_delivery_t *dx_message_inbound_delivery(dx_message_t *qm);
+
+//
+// Functions for composed messages
+//
+
+// Convenience Functions
+void dx_message_compose_1(dx_message_t *msg, const char *to, dx_buffer_list_t *buffers);
+void dx_message_copy_header(dx_message_t *msg); // Copy received header into send-header (prior to adding annotations)
+void dx_message_copy_message_annotations(dx_message_t *msg);
+
+// Raw Functions
+void dx_message_begin_header(dx_message_t *msg);
+void dx_message_end_header(dx_message_t *msg);
+
+void dx_message_begin_delivery_annotations(dx_message_t *msg);
+void dx_message_end_delivery_annotations(dx_message_t *msg);
+
+void dx_message_begin_message_annotations(dx_message_t *msg);
+void dx_message_end_message_annotations(dx_message_t *msg);
+
+void dx_message_begin_message_properties(dx_message_t *msg);
+void dx_message_end_message_properties(dx_message_t *msg);
+
+void dx_message_begin_application_properties(dx_message_t *msg);
+void dx_message_end_application_properties(dx_message_t *msg);
+
+void dx_message_append_body_data(dx_message_t *msg, dx_buffer_list_t *buffers);
+
+void dx_message_begin_body_sequence(dx_message_t *msg);
+void dx_message_end_body_sequence(dx_message_t *msg);
+
+void dx_message_begin_footer(dx_message_t *msg);
+void dx_message_end_footer(dx_message_t *msg);
+
+void dx_message_insert_null(dx_message_t *msg);
+void dx_message_insert_boolean(dx_message_t *msg, int value);
+void dx_message_insert_ubyte(dx_message_t *msg, uint8_t value);
+void dx_message_insert_uint(dx_message_t *msg, uint32_t value);
+void dx_message_insert_ulong(dx_message_t *msg, uint64_t value);
+void dx_message_insert_binary(dx_message_t *msg, const uint8_t *start, size_t len);
+void dx_message_insert_string(dx_message_t *msg, const char *start);
+void dx_message_insert_uuid(dx_message_t *msg, const uint8_t *value);
+void dx_message_insert_symbol(dx_message_t *msg, const char *start, size_t len);
+void dx_message_insert_timestamp(dx_message_t *msg, uint64_t value);
+void dx_message_begin_list(dx_message_t* msg);
+void dx_message_end_list(dx_message_t* msg);
+void dx_message_begin_map(dx_message_t* msg);
+void dx_message_end_map(dx_message_t* msg);
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/router.h b/extras/dispatch/include/qpid/dispatch/router.h
new file mode 100644
index 0000000000..03f4aa15be
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/router.h
@@ -0,0 +1,35 @@
+#ifndef __dispatch_router_h__
+#define __dispatch_router_h__ 1
+/*
+ * 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.
+ */
+
+#include <proton/engine.h>
+#include <qpid/dispatch/container.h>
+
+typedef struct dx_router_t dx_router_t;
+
+typedef struct {
+ size_t message_limit;
+ size_t memory_limit;
+} dx_router_configuration_t;
+
+dx_router_t *dx_router(dx_router_configuration_t *config);
+void dx_router_free(dx_router_t *router);
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/server.h b/extras/dispatch/include/qpid/dispatch/server.h
new file mode 100644
index 0000000000..635e1323dd
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/server.h
@@ -0,0 +1,403 @@
+#ifndef __dispatch_server_h__
+#define __dispatch_server_h__ 1
+/*
+ * 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.
+ */
+
+#include <proton/engine.h>
+
+/**
+ * \defgroup Control Server Control Functions
+ * @{
+ */
+
+/**
+ * \brief Thread Start Handler
+ *
+ * Callback invoked when a new server thread is started. The callback is
+ * invoked on the newly created thread.
+ *
+ * This handler can be used to set processor affinity or other thread-specific
+ * tuning values.
+ *
+ * @param context The handler context supplied in dx_server_initialize.
+ * @param thread_id The integer thread identifier that uniquely identifies this thread.
+ */
+typedef void (*dx_thread_start_cb_t)(void* context, int thread_id);
+
+
+/**
+ * \brief Initialize the server module and prepare it for operation.
+ *
+ * @param thread_count The number of worker threads (1 or more) that the server shall create
+ */
+void dx_server_initialize(int thread_count);
+
+
+/**
+ * \brief Finalize the server after it has stopped running.
+ */
+void dx_server_finalize(void);
+
+
+/**
+ * \brief Set the optional thread-start handler.
+ *
+ * This handler is called once on each worker thread at the time
+ * the thread is started. This may be used to set tuning settings like processor affinity, etc.
+ *
+ * @param start_handler The thread-start handler invoked per thread on thread startup.
+ * @param context Opaque context to be passed back in the callback function.
+ */
+void dx_server_set_start_handler(dx_thread_start_cb_t start_handler, void *context);
+
+
+/**
+ * \brief Run the server threads until completion.
+ *
+ * Start the operation of the server, including launching all of the worker threads.
+ * This function does not return until after the server has been stopped. The thread
+ * that calls dx_server_run is used as one of the worker threads.
+ */
+void dx_server_run(void);
+
+
+/**
+ * \brief Stop the server
+ *
+ * Stop the server and join all of its worker threads. This function may be called from any
+ * thread. When this function returns, all of the other server threads have been closed and
+ * joined. The calling thread will be the only running thread in the process.
+ */
+void dx_server_stop(void);
+
+
+/**
+ * \brief Pause (quiesce) the server.
+ *
+ * This call blocks until all of the worker threads (except
+ * the one calling the this function) are finished processing and have been blocked. When
+ * this call returns, the calling thread is the only thread running in the process.
+ */
+void dx_server_pause(void);
+
+
+/**
+ * \brief Resume normal operation of a paused server.
+ *
+ * This call unblocks all of the worker threads
+ * so they can resume normal connection processing.
+ */
+void dx_server_resume(void);
+
+
+/**
+ * @}
+ * \defgroup Signal Server Signal Handling Functions
+ * @{
+ */
+
+
+/**
+ * \brief Signal Handler
+ *
+ * Callback for caught signals. This handler will only be invoked for signal numbers
+ * that were registered via dx_server_signal. The handler is not invoked in the context
+ * of the OS signal handler. Rather, it is invoked on one of the worker threads in an
+ * orderly sequence.
+ *
+ * @param context The handler context supplied in dx_server_initialize.
+ * @param signum The signal number that was raised.
+ */
+typedef void (*dx_signal_handler_cb_t)(void* context, int signum);
+
+
+/**
+ * Set the signal handler for the server. The signal handler is invoked cleanly on a worker thread
+ * after the server process catches an operating-system signal. The signal handler is optional and
+ * need not be set.
+ *
+ * @param signal_handler The signal handler called when a registered signal is caught.
+ * @param context Opaque context to be passed back in the callback function.
+ */
+void dx_server_set_signal_handler(dx_signal_handler_cb_t signal_handler, void *context);
+
+
+/**
+ * \brief Register a signal to be caught and handled by the signal handler.
+ *
+ * @param signum The signal number of a signal to be handled by the application.
+ */
+void dx_server_signal(int signum);
+
+
+/**
+ * @}
+ * \defgroup Connection Server AMQP Connection Handling Functions
+ * @{
+ */
+
+/**
+ * \brief Listener objects represent the desire to accept incoming transport connections.
+ */
+typedef struct dx_listener_t dx_listener_t;
+
+/**
+ * \brief Connector objects represent the desire to create and maintain an outgoing transport connection.
+ */
+typedef struct dx_connector_t dx_connector_t;
+
+/**
+ * \brief Connection objects wrap Proton connection objects.
+ */
+typedef struct dx_connection_t dx_connection_t;
+
+/**
+ * Event type for the connection callback.
+ */
+typedef enum {
+ /// The connection just opened via a listener (inbound).
+ DX_CONN_EVENT_LISTENER_OPEN,
+
+ /// The connection just opened via a connector (outbound).
+ DX_CONN_EVENT_CONNECTOR_OPEN,
+
+ /// The connection was closed at the transport level (not cleanly).
+ DX_CONN_EVENT_CLOSE,
+
+ /// The connection requires processing.
+ DX_CONN_EVENT_PROCESS
+} dx_conn_event_t;
+
+
+/**
+ * \brief Connection Event Handler
+ *
+ * Callback invoked when processing is needed on a proton connection. This callback
+ * shall be invoked on one of the server's worker threads. The server guarantees that
+ * no two threads shall be allowed to process a single connection concurrently.
+ * The implementation of this handler may assume that it has exclusive access to the
+ * connection and its subservient components (sessions, links, deliveries, etc.).
+ *
+ * @param context The handler context supplied in dx_server_{connect,listen}.
+ * @param event The event/reason for the invocation of the handler.
+ * @param conn The connection that requires processing by the handler.
+ * @return A value greater than zero if the handler did any proton processing for
+ * the connection. If no work was done, zero is returned.
+ */
+typedef int (*dx_conn_handler_cb_t)(void* context, dx_conn_event_t event, dx_connection_t *conn);
+
+
+/**
+ * \brief Set the connection event handler callback.
+ *
+ * Set the connection handler callback for the server. This callback is mandatory and must be set
+ * prior to the invocation of dx_server_run.
+ *
+ * @param conn_hander The handler for processing connection-related events.
+ */
+void dx_server_set_conn_handler(dx_conn_handler_cb_t conn_handler);
+
+
+/**
+ * \brief Set the user context for a connection.
+ *
+ * @param conn Connection object supplied in DX_CONN_EVENT_{LISTENER,CONNETOR}_OPEN
+ * @param context User context to be stored with the connection.
+ */
+void dx_connection_set_context(dx_connection_t *conn, void *context);
+
+
+/**
+ * \brief Get the user context from a connection.
+ *
+ * @param conn Connection object supplied in DX_CONN_EVENT_{LISTENER,CONNETOR}_OPEN
+ * @return The user context stored with the connection.
+ */
+void *dx_connection_get_context(dx_connection_t *conn);
+
+
+/**
+ * \brief Activate a connection for output.
+ *
+ * This function is used to request that the server activate the indicated connection.
+ * It is assumed that the connection is one that the caller does not have permission to
+ * access (i.e. it may be owned by another thread currently). An activated connection
+ * will, when writable, appear in the internal work list and be invoked for processing
+ * by a worker thread.
+ *
+ * @param conn The connection over which the application wishes to send data
+ */
+void dx_server_activate(dx_connection_t *conn);
+
+
+/**
+ * \brief Get the wrapped proton-engine connection object.
+ *
+ * @param conn Connection object supplied in DX_CONN_EVENT_{LISTENER,CONNETOR}_OPEN
+ * @return The proton connection object.
+ */
+pn_connection_t *dx_connection_pn(dx_connection_t *conn);
+
+
+/**
+ * \brief Configuration block for a connector or a listener.
+ */
+typedef struct dx_server_config_t {
+ /**
+ * Host name or network address to bind to a listener or use in the connector.
+ */
+ char *host;
+
+ /**
+ * Port name or number to bind to a listener or use in the connector.
+ */
+ char *port;
+
+ /**
+ * Space-separated list of SASL mechanisms to be accepted for the connection.
+ */
+ char *sasl_mechanisms;
+
+ /**
+ * If appropriate for the mechanism, the username for authentication
+ * (connector only)
+ */
+ char *sasl_username;
+
+ /**
+ * If appropriate for the mechanism, the password for authentication
+ * (connector only)
+ */
+ char *sasl_password;
+
+ /**
+ * If appropriate for the mechanism, the minimum acceptable security strength factor
+ */
+ int sasl_minssf;
+
+ /**
+ * If appropriate for the mechanism, the maximum acceptable security strength factor
+ */
+ int sasl_maxssf;
+
+ /**
+ * SSL is enabled for this connection iff non-zero.
+ */
+ int ssl_enabled;
+
+ /**
+ * Connection will take on the role of SSL server iff non-zero.
+ */
+ int ssl_server;
+
+ /**
+ * Iff non-zero AND ssl_enabled is non-zero, this listener will detect the client's use
+ * of SSL or non-SSL and conform to the client's protocol.
+ * (listener only)
+ */
+ int ssl_allow_unsecured_client;
+
+ /**
+ * Path to the file containing the PEM-formatted public certificate for the local end
+ * of the connection.
+ */
+ char *ssl_certificate_file;
+
+ /**
+ * Path to the file containing the PEM-formatted private key for the local end of the
+ * connection.
+ */
+ char *ssl_private_key_file;
+
+ /**
+ * The password used to sign the private key, or NULL if the key is not protected.
+ */
+ char *ssl_password;
+
+ /**
+ * Path to the file containing the PEM-formatted set of certificates of trusted CAs.
+ */
+ char *ssl_trusted_certificate_db;
+
+ /**
+ * Iff non-zero, require that the peer's certificate be supplied and that it be authentic
+ * according to the set of trusted CAs.
+ */
+ int ssl_require_peer_authentication;
+
+ /**
+ * Allow the connection to be redirected by the peer (via CLOSE->Redirect). This is
+ * meaningful for outgoing (connector) connections only.
+ */
+ int allow_redirect;
+} dx_server_config_t;
+
+
+/**
+ * \brief Create a listener for incoming connections.
+ *
+ * @param config Pointer to a configuration block for this listener. This block will be
+ * referenced by the server, not copied. The referenced record must remain
+ * in-scope for the life of the listener.
+ * @param context User context passed back in the connection handler.
+ * @return A pointer to the new listener, or NULL in case of failure.
+ */
+dx_listener_t *dx_server_listen(const dx_server_config_t *config, void *context);
+
+
+/**
+ * \brief Free the resources associated with a listener.
+ *
+ * @param li A listener pointer returned by dx_listen.
+ */
+void dx_listener_free(dx_listener_t* li);
+
+
+/**
+ * \brief Close a listener so it will accept no more connections.
+ *
+ * @param li A listener pointer returned by dx_listen.
+ */
+void dx_listener_close(dx_listener_t* li);
+
+
+/**
+ * \brief Create a connector for an outgoing connection.
+ *
+ * @param config Pointer to a configuration block for this connector. This block will be
+ * referenced by the server, not copied. The referenced record must remain
+ * in-scope for the life of the connector..
+ * @param context User context passed back in the connection handler.
+ * @return A pointer to the new connector, or NULL in case of failure.
+ */
+dx_connector_t *dx_server_connect(const dx_server_config_t *config, void *context);
+
+
+/**
+ * \brief Free the resources associated with a connector.
+ *
+ * @param ct A connector pointer returned by dx_connect.
+ */
+void dx_connector_free(dx_connector_t* ct);
+
+/**
+ * @}
+ */
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/threading.h b/extras/dispatch/include/qpid/dispatch/threading.h
new file mode 100644
index 0000000000..f275fc0086
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/threading.h
@@ -0,0 +1,45 @@
+#ifndef __sys_threading_h__
+#define __sys_threading_h__ 1
+/*
+ * 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.
+ */
+
+typedef struct sys_mutex_t sys_mutex_t;
+
+sys_mutex_t *sys_mutex(void);
+void sys_mutex_free(sys_mutex_t *mutex);
+void sys_mutex_lock(sys_mutex_t *mutex);
+void sys_mutex_unlock(sys_mutex_t *mutex);
+
+
+typedef struct sys_cond_t sys_cond_t;
+
+sys_cond_t *sys_cond(void);
+void sys_cond_free(sys_cond_t *cond);
+void sys_cond_wait(sys_cond_t *cond, sys_mutex_t *held_mutex);
+void sys_cond_signal(sys_cond_t *cond);
+void sys_cond_signal_all(sys_cond_t *cond);
+
+
+typedef struct sys_thread_t sys_thread_t;
+
+sys_thread_t *sys_thread(void *(*run_function) (void *), void *arg);
+void sys_thread_free(sys_thread_t *thread);
+void sys_thread_join(sys_thread_t *thread);
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/timer.h b/extras/dispatch/include/qpid/dispatch/timer.h
new file mode 100644
index 0000000000..af3a22e262
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/timer.h
@@ -0,0 +1,86 @@
+#ifndef __dispatch_timer_h__
+#define __dispatch_timer_h__ 1
+/*
+ * 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.
+ */
+
+/**
+ * \defgroup Timer Server Timer Functions
+ * @{
+ */
+
+typedef struct dx_timer_t dx_timer_t;
+
+/**
+ * Timer Callback
+ *
+ * Callback invoked after a timer's interval expires and the timer fires.
+ *
+ * @param context The context supplied in dx_timer
+ */
+typedef void (*dx_timer_cb_t)(void* context);
+
+
+/**
+ * Create a new timer object.
+ *
+ * @param cb The callback function to be invoked when the timer expires.
+ * @param context An opaque, user-supplied context to be passed into the callback.
+ * @return A pointer to the new timer object or NULL if memory is exhausted.
+ */
+dx_timer_t *dx_timer(dx_timer_cb_t cb, void* context);
+
+
+/**
+ * Free the resources for a timer object. If the timer was scheduled, it will be canceled
+ * prior to freeing. After this function returns, the callback will not be invoked for this
+ * timer.
+ *
+ * @param timer Pointer to the timer object returned by dx_timer.
+ */
+void dx_timer_free(dx_timer_t *timer);
+
+
+/**
+ * Schedule a timer to fire in the future.
+ *
+ * Note that the timer callback will never be invoked synchronously during the execution
+ * of dx_timer_schedule. Even if the interval is immediate (0), the callback invocation will
+ * be asynchronous and after the return of this function.
+ *
+ * @param timer Pointer to the timer object returned by dx_timer.
+ * @param msec The minimum number of milliseconds of delay until the timer fires.
+ * If 0 is supplied, the timer will fire immediately.
+ */
+void dx_timer_schedule(dx_timer_t *timer, long msec);
+
+
+/**
+ * Attempt to cancel a scheduled timer. Since the timer callback can be invoked on any
+ * server thread, it is always possible that a last-second cancel attempt may arrive too late
+ * to stop the timer from firing (i.e. the cancel is concurrent with the fire callback).
+ *
+ * @param timer Pointer to the timer object returned by dx_timer.
+ */
+void dx_timer_cancel(dx_timer_t *timer);
+
+/**
+ * @}
+ */
+
+#endif
diff --git a/extras/dispatch/include/qpid/dispatch/user_fd.h b/extras/dispatch/include/qpid/dispatch/user_fd.h
new file mode 100644
index 0000000000..3e5584ce2e
--- /dev/null
+++ b/extras/dispatch/include/qpid/dispatch/user_fd.h
@@ -0,0 +1,121 @@
+#ifndef __dispatch_user_fd_h__
+#define __dispatch_user_fd_h__ 1
+/*
+ * 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.
+ */
+
+
+/**
+ * \defgroup UserFd Server User-File-Descriptor Functions
+ * @{
+ */
+
+typedef struct dx_user_fd_t dx_user_fd_t;
+
+
+/**
+ * User_fd Handler
+ *
+ * Callback invoked when a user-managed file descriptor is available for reading or writing or there
+ * was an error on the file descriptor.
+ *
+ * @param context The handler context supplied in the dx_user_fd call.
+ * @param ufd The user_fd handle for the processable fd.
+ */
+typedef void (*dx_user_fd_handler_cb_t)(void* context, dx_user_fd_t *ufd);
+
+
+/**
+ * Set the user-fd handler callback for the server. This handler is optional, but must be supplied
+ * if the dx_server is used to manage the activation of user file descriptors.
+ */
+void dx_server_set_user_fd_handler(dx_user_fd_handler_cb_t ufd_handler);
+
+
+/**
+ * Create a tracker for a user-managed file descriptor.
+ *
+ * A user-fd is appropriate for use when the application opens and manages file descriptors
+ * for purposes other than AMQP communication. Registering a user fd with the dispatch server
+ * controls processing of the FD alongside the FDs used for messaging.
+ *
+ * @param fd The open file descriptor being managed by the application.
+ * @param context User context passed back in the connection handler.
+ * @return A pointer to the new user_fd.
+ */
+dx_user_fd_t *dx_user_fd(int fd, void *context);
+
+
+/**
+ * Free the resources for a user-managed FD tracker.
+ *
+ * @param ufd Structure pointer returned by dx_user_fd.
+ */
+void dx_user_fd_free(dx_user_fd_t *ufd);
+
+
+/**
+ * Activate a user-fd for read.
+ *
+ * Use this activation when the application has capacity to receive data from the user-fd. This will
+ * cause the callback set in dx_server_set_user_fd_handler to later be invoked when the
+ * file descriptor has data to read.
+ *
+ * @param ufd Structure pointer returned by dx_user_fd.
+ */
+void dx_user_fd_activate_read(dx_user_fd_t *ufd);
+
+
+/**
+ * Activate a user-fd for write.
+ *
+ * Use this activation when the application has data to write via the user-fd. This will
+ * cause the callback set in dx_server_set_user_fd_handler to later be invoked when the
+ * file descriptor is writable.
+ *
+ * @param ufd Structure pointer returned by dx_user_fd.
+ */
+void dx_user_fd_activate_write(dx_user_fd_t *ufd);
+
+
+/**
+ * Check readable status of a user-fd
+ *
+ * Note: It is possible that readable status is spurious (i.e. this function returns true
+ * but the file-descriptor is not readable and will block if not set to O_NONBLOCK).
+ * Code accordingly.
+ *
+ * @param ufd Structure pointer returned by dx_user_fd.
+ * @return true iff the user file descriptor is readable.
+ */
+bool dx_user_fd_is_readable(dx_user_fd_t *ufd);
+
+
+/**
+ * Check writable status of a user-fd
+ *
+ * @param ufd Structure pointer returned by dx_user_fd.
+ * @return true iff the user file descriptor is writable.
+ */
+bool dx_user_fd_is_writeable(dx_user_fd_t *ufd);
+
+/**
+ * @}
+ */
+
+#endif
diff --git a/extras/dispatch/router/CMakeLists.txt b/extras/dispatch/router/CMakeLists.txt
new file mode 100644
index 0000000000..efb424ee13
--- /dev/null
+++ b/extras/dispatch/router/CMakeLists.txt
@@ -0,0 +1,31 @@
+##
+## 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.
+##
+
+##
+## Build the router application
+##
+set(router_SOURCES
+ src/main.c
+ )
+
+add_executable(dispatch-router ${router_SOURCES})
+target_link_libraries(dispatch-router qpid-dispatch ${proton_lib})
+
+install(TARGETS dispatch-router RUNTIME DESTINATION bin)
+
diff --git a/extras/dispatch/router/src/main.c b/extras/dispatch/router/src/main.c
new file mode 100644
index 0000000000..0cafa6a2ca
--- /dev/null
+++ b/extras/dispatch/router/src/main.c
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <proton/driver.h>
+#include <qpid/dispatch/server.h>
+#include <qpid/dispatch/container.h>
+#include <qpid/dispatch/timer.h>
+#include <qpid/dispatch/log.h>
+#include <qpid/dispatch/router.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+static int exit_with_sigint = 0;
+
+static void thread_start_handler(void* context, int thread_id)
+{
+}
+
+
+static void signal_handler(void* context, int signum)
+{
+ dx_server_pause();
+
+ switch (signum) {
+ case SIGINT:
+ exit_with_sigint = 1;
+
+ case SIGQUIT:
+ case SIGTERM:
+ fflush(stdout);
+ dx_server_stop();
+ break;
+
+ case SIGHUP:
+ break;
+
+ default:
+ break;
+ }
+
+ dx_server_resume();
+}
+
+
+static void startup(void *context)
+{
+ // TODO - Move this into a configuration framework
+
+ dx_server_pause();
+
+ static dx_server_config_t server_config;
+ server_config.host = "0.0.0.0";
+ server_config.port = "5672";
+ server_config.sasl_mechanisms = "ANONYMOUS";
+ server_config.ssl_enabled = 0;
+
+ dx_server_listen(&server_config, 0);
+
+ /*
+ static dx_server_config_t client_config;
+ client_config.host = "0.0.0.0";
+ client_config.port = "10000";
+ client_config.sasl_mechanisms = "ANONYMOUS";
+ client_config.ssl_enabled = 0;
+
+ dx_server_connect(&client_config, 0);
+ */
+
+ dx_server_resume();
+}
+
+
+int main(int argc, char **argv)
+{
+ dx_log_set_mask(LOG_INFO | LOG_TRACE | LOG_ERROR);
+
+ dx_server_initialize(4);
+ dx_container_initialize();
+
+ dx_server_set_signal_handler(signal_handler, 0);
+ dx_server_set_start_handler(thread_start_handler, 0);
+
+ dx_router_t *router = dx_router(0);
+
+ dx_timer_t *startup_timer = dx_timer(startup, 0);
+ dx_timer_schedule(startup_timer, 0);
+
+ dx_server_signal(SIGHUP);
+ dx_server_signal(SIGQUIT);
+ dx_server_signal(SIGTERM);
+ dx_server_signal(SIGINT);
+
+ dx_server_run();
+ dx_router_free(router);
+ dx_server_finalize();
+
+ if (exit_with_sigint) {
+ signal(SIGINT, SIG_DFL);
+ kill(getpid(), SIGINT);
+ }
+
+ return 0;
+}
+
diff --git a/extras/dispatch/site/css/style.css b/extras/dispatch/site/css/style.css
new file mode 100644
index 0000000000..b73c136d4a
--- /dev/null
+++ b/extras/dispatch/site/css/style.css
@@ -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.
+ *
+ */
+ul {
+ list-style-type:square;
+}
+
+th {
+ text-align: left;
+ font-weight: bold;
+}
+
+body {
+ margin:0;
+ background:#FFFFFF;
+ font-family:"Verdana", sans-serif;
+}
+
+.container {
+ width:950px;
+ margin:0 auto;
+}
+
+.header {
+ height:100px;
+ width:950px;
+ background:url(images/header.png)
+}
+
+.logo {
+ text-align:center;
+ font-weight:600;
+ padding:0 0 0 0;
+ font-size:14px;
+ font-family:"Verdana", cursive;
+}
+
+.logo a {
+ color:#000000;
+ text-decoration:none;
+}
+
+.main_text_area {
+ margin-left:200px;
+}
+
+.main_text_area_top {
+ height:14px;
+ font-size:1px;
+}
+
+.main_text_area_bottom {
+ display:none;
+/* height:14px;
+ margin-bottom:4px;*/
+}
+
+.main_text_area_body {
+ padding:5px 24px;
+}
+
+.main_text_area_body p {
+ text-align:justify;
+}
+
+.main_text_area br {
+ line-height:10px;
+}
+
+.main_text_area h1 {
+ font-size:28px;
+ font-weight:600;
+ margin:0 0 24px 0;
+ color:#0c3b82;
+ font-family:"Verdana", Times, serif;
+}
+
+.main_text_area h2 {
+ font-size:24px;
+ font-weight:600;
+ margin:24px 0 8px 0;
+ color:#0c3b82;
+ font-family:"Verdana",Times, serif;
+}
+
+.main_text_area ol, .main_text_area ul {
+ padding:0;
+ margin:10px 0;
+ margin-left:20px;
+}
+
+.main_text_area li {
+/* margin-left:40px; */
+}
+
+.main_text_area, .menu_box {
+ font-size:13px;
+ line-height:17px;
+ color:#000000;
+}
+
+.main_text_area {
+ font-size:15px;
+}
+
+.main_text_area a {
+ color:#000000;
+}
+
+.main_text_area a:hover {
+ color:#000000;
+}
+
+.menu_box {
+ width:196px;
+ float:left;
+ margin-left:4px;
+}
+
+.menu_box_top {
+ background:url(images/menu_top.png) no-repeat;
+ height:14px;
+ font-size:1px;
+}
+
+.menu_box_body {
+ background:url(images/menu_body.png) repeat-y;
+ padding:5px 24px 5px 24px;
+}
+
+.menu_box_bottom {
+ background:url(images/menu_bottom.png) no-repeat;
+ height:14px;
+ font-size:1px;
+ margin-bottom:1px;
+}
+
+.menu_box h3 {
+ font-size:20px;
+ font-weight:500;
+ margin:0 0 8px 0;
+ color:#0c3b82;
+ font-family:"Verdana",Times, serif;
+}
+
+.menu_box ul {
+ margin:12px;
+ padding:0px;
+}
+
+.menu_box li {
+ list-style:square;
+}
+
+.menu_box a {
+ color:#000000;
+ text-decoration:none;
+}
+
+.menu_box a:hover {
+ color:#000000;
+ text-decoration:underline;
+}
+
+.feature_box {
+ width:698px;
+ overflow:hidden;
+}
+
+.feature_box h3 {
+ font-size:18px;
+ font-weight:600;
+ margin:0 0 8px 0;
+ color:#0c3b82;
+ font-family:"Verdana", Times, serif;
+}
+
+.feature_box_column1 {
+ width:196px;
+ float:left;
+ padding:10px 15px 10px 15px;
+ margin-left:0px;
+}
+
+.feature_box_column2 {
+ width:196px;
+ float:left;
+ padding:10px 15px 10px 15px;
+ margin-left:0px;
+}
+
+.feature_box_column3 {
+ width:196px;
+ float:left;
+ padding:10px 15px 10px 15px;
+ margin-left:0px;
+}
+
+
+.feature_box ul {
+ margin:.8em .4em;
+ padding-left:1.2em;
+ padding:0;
+ list-style-type: square;
+}
+
+.feature_box ul li {
+ font-family:"Verdana",sans-serif;
+ font-size:14px;
+ color:#000;
+ margin:.4em 0;
+}
+
+.feature_box ul li ul {
+ padding-left:1.2em;
+ margin-left:2em;
+}
+
+.feature_box a {
+ color:#000000;
+ text-decoration:none;
+}
+
+.feature_box a:hover {
+ color:#000000;
+ text-decoration:underline;
+}
+
+.footer {
+ color:#000000;
+ clear:both;
+ text-align:center;
+ font-size:11px;
+ line-height:17px;
+ height:45px;
+ padding-top:18px;
+}
+
+.footer a {
+ color:#000000;
+}
+
+.footer a:hover {
+ color:#000000;
+}
+
+.download_table {
+ width:100%;
+}
+
+.download_table_col_1 {
+ width:240px;
+}
+
+.proton_download_table_col_1 {
+ width:420px;
+}
+
+.download_table_amqp_col {
+ text-align:center;
+ width:80px;
+}
+
diff --git a/extras/dispatch/site/images/arch.dia b/extras/dispatch/site/images/arch.dia
new file mode 100644
index 0000000000..99b3185447
--- /dev/null
+++ b/extras/dispatch/site/images/arch.dia
Binary files differ
diff --git a/extras/dispatch/site/images/arch.png b/extras/dispatch/site/images/arch.png
new file mode 100644
index 0000000000..a2b7f776b9
--- /dev/null
+++ b/extras/dispatch/site/images/arch.png
Binary files differ
diff --git a/extras/dispatch/site/includes/footer.include b/extras/dispatch/site/includes/footer.include
new file mode 100644
index 0000000000..35ff04b9f2
--- /dev/null
+++ b/extras/dispatch/site/includes/footer.include
@@ -0,0 +1,7 @@
+ <div class="footer">
+ <p>
+ &#xA9; 2004-2012 The Apache Software Foundation.<br />
+ Apache Qpid, Qpid, Apache, the Apache feather logo, and the Apache Qpid project logo are trademarks of The Apache Software Foundation.<br />
+ All other marks mentioned may be trademarks or registered trademarks of their respective owners.
+ </p>
+ </div>
diff --git a/extras/dispatch/site/includes/header.include b/extras/dispatch/site/includes/header.include
new file mode 100644
index 0000000000..244dfc4517
--- /dev/null
+++ b/extras/dispatch/site/includes/header.include
@@ -0,0 +1,6 @@
+ <div class="header">
+ <div class="logo">
+ <h1>Apache Qpid&#8482;</h1>
+ <h2>Open Source AMQP Messaging</h2>
+ </div>
+ </div>
diff --git a/extras/dispatch/site/includes/menu.include b/extras/dispatch/site/includes/menu.include
new file mode 100644
index 0000000000..7cbdbd139d
--- /dev/null
+++ b/extras/dispatch/site/includes/menu.include
@@ -0,0 +1,68 @@
+ <div class="menu_box">
+ <div class="menu_box_top"></div>
+ <div class="menu_box_body">
+ <h3>Apache Qpid Dispatch</h3>
+ <ul>
+ <li><a href="index.html">Back to Qpid</a></li>
+ <li><a href="index.html">Home</a></li>
+ <li><a href="download.html">Download</a></li>
+ <li><a href="getting_started.html">Getting Started</a></li>
+ <li><a href="http://www.apache.org/licenses/">License</a></li>
+ <li><a href="https://cwiki.apache.org/qpid/faq.html">FAQ</a></li>
+ </ul>
+ </div>
+ <div class="menu_box_bottom"></div>
+
+ <div class="menu_box_top"></div>
+ <div class="menu_box_body">
+ <h3>Documentation</h3>
+ <ul>
+ <li><a href="documentation.html#doc-release">Latest Release</a></li>
+ <li><a href="documentation.html#doc-trunk">Trunk</a></li>
+ <li><a href="documentation.html#doc-archives">Archive</a></li>
+ </ul>
+ </div>
+ <div class="menu_box_bottom"></div>
+
+ <div class="menu_box_top"></div>
+ <div class="menu_box_body">
+ <h3>Community</h3>
+ <ul>
+ <li><a href="getting_involved.html">Getting Involved</a></li>
+ <li><a href="source_repository.html">Source Repository</a></li>
+ <li><a href="https://issues.apache.org/jira/browse/qpid">Issue Reporting</a></li>
+ </ul>
+ </div>
+ <div class="menu_box_bottom"></div>
+
+ <div class="menu_box_top"></div>
+ <div class="menu_box_body">
+ <h3>Developers</h3>
+ <ul>
+ <li><a href="https://cwiki.apache.org/qpid/building.html">Building Qpid</a></li>
+ <li><a href="https://cwiki.apache.org/qpid/developer-pages.html">Developer Pages</a></li>
+ </ul>
+ </div>
+ <div class="menu_box_bottom"></div>
+
+ <div class="menu_box_top"></div>
+ <div class="menu_box_body">
+ <h3>About AMQP</h3>
+ <ul>
+ <li><a href="amqp.html">What is AMQP?</a></li>
+ </ul>
+ </div>
+ <div class="menu_box_bottom"></div>
+
+ <div class="menu_box_top"></div>
+ <div class="menu_box_body">
+ <h3>About Apache</h3>
+ <ul>
+ <li><a href="http://www.apache.org">Home</a></li>
+ <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
+ <li><a href="http://www.apache.org/foundation/thanks.html">Thanks</a></li>
+ <li><a href="http://www.apache.org/security/">Security</a></li>
+ </ul>
+ </div>
+ <div class="menu_box_bottom"></div>
+ </div>
diff --git a/extras/dispatch/site/index.html b/extras/dispatch/site/index.html
new file mode 100755
index 0000000000..d8f1759492
--- /dev/null
+++ b/extras/dispatch/site/index.html
@@ -0,0 +1,101 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ -
+ - 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.
+ -
+-->
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Apache Qpid Dispatch&#8482;: A Platform for Building AMQP Infrastructure</title>
+ <link href="css/style.css" rel="stylesheet" type="text/css"/>
+ </head>
+
+ <body>
+ <div class="container">
+ <!-- begin header -->
+
+ <div class="header">
+ <div class="logo">
+ <h1>Apache Qpid Dispatch&#8482;</h1>
+ <h2>A Platform for Building AMQP Infrastructure</h2>
+ </div>
+ </div>
+
+ <!-- end header -->
+
+ <!-- begin menu -->
+ <!--#include virtual="includes/menu.include" -->
+ <!-- end menu -->
+
+ <!-- begin content -->
+ <div class="main_text_area">
+ <div class="main_text_area_top"></div>
+
+ <div class="main_text_area_body">
+
+<p>Qpid Dispatch is a library to help developers build infrastructure
+components for AMQP. Dispatch is not a general-purpose Messaging API.
+Rather, it is a foundation on which to build applications, services, and
+appliances that need direct access to the detailed constructs of AMQP.</p>
+<hr width="80%" />
+<h2>Overview</h2>
+<p>Dispatch is an extension of the Engine and Driver interfaces of
+<a href="http://qpid.apache.org/proton">Qpid Proton</a>. It neither
+uses nor exposes the Messenger interface of Proton. Rather, it
+provides a way for developers to use Proton's more detailed Engine
+facility. The following features are provided:</p>
+
+<ul>
+ <li>An asynchronous, event-oriented application environment</li>
+ <li>Safe multi-threaded use of Proton</li>
+ <li>Operating System Signal handling</li>
+ <li>Quiesce and Resume for the application's threads</li>
+ <li>Timers</li>
+ <li>Resilient outbound connections (retry/reconnect)</li>
+ <li>Polling support for the application's non-AMQP file descriptors</li>
+ <li>An AMQP Node Container that allows the developer to create
+ custom node types</li>
+</ul>
+<p />
+<hr width="80%" />
+<h2>Architecture</h2>
+<center><img src="images/arch.png" /></center>
+<ul>
+ <li><b>Proton Engine and Driver</b> provide the underlying AMQP capability</li>
+ <li><a href="doxygen/server/modules.html">Dispatch Server</a>
+ wraps Proton connections in a multi-threaded server environment</li>
+ <li><b>Dispatch Container</b> provides management of AMQP nodes (links, termini, and deliveries)</li>
+ <li><b>Dispatch Message</b> provides efficient message encode/decode, optimized for messaging intermediaries</li>
+ <li>The <b>Application</b> uses all of the above services to implement scalable and performant AMQP infrastructure</li>
+</ul>
+<hr width="80%" />
+
+ </div>
+
+ <div class="main_text_area_bottom"></div>
+ </div>
+ <!-- end content -->
+
+ <!-- begin footer -->
+ <!--#include virtual="includes/footer.include" -->
+ <!-- end footer -->
+
+ </div>
+ </body>
+</html>
diff --git a/extras/dispatch/src/agent.c b/extras/dispatch/src/agent.c
new file mode 100644
index 0000000000..a885042b45
--- /dev/null
+++ b/extras/dispatch/src/agent.c
@@ -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.
+ */
+
+#include <qpid/dispatch/agent.h>
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/hash.h>
+#include <qpid/dispatch/container.h>
+#include <qpid/dispatch/message.h>
+#include <qpid/dispatch/threading.h>
+#include <qpid/dispatch/timer.h>
+#include <string.h>
+
+
+typedef struct dx_agent_t {
+ hash_t *class_hash;
+ dx_message_list_t in_fifo;
+ dx_message_list_t out_fifo;
+ sys_mutex_t *lock;
+ dx_timer_t *timer;
+} dx_agent_t;
+
+static dx_agent_t *agent = 0;
+
+
+struct dx_agent_class_t {
+ char *fqname;
+ void *context;
+ dx_agent_schema_cb_t schema_handler;
+ dx_agent_query_cb_t query_handler; // 0 iff class is an event.
+};
+
+
+static void dx_agent_timer_handler(void *context)
+{
+ // TODO - Process the in_fifo here
+}
+
+
+void dx_agent_initialize()
+{
+ assert(!agent);
+ agent = NEW(dx_agent_t);
+ agent->class_hash = hash(6, 10, 1);
+ DEQ_INIT(agent->in_fifo);
+ DEQ_INIT(agent->out_fifo);
+ agent->lock = sys_mutex();
+ agent->timer = dx_timer(dx_agent_timer_handler, agent);
+}
+
+
+void dx_agent_finalize(void)
+{
+ sys_mutex_free(agent->lock);
+ dx_timer_free(agent->timer);
+ hash_free(agent->class_hash);
+ free(agent);
+ agent = 0;
+}
+
+
+dx_agent_class_t *dx_agent_register_class(const char *fqname,
+ void *context,
+ dx_agent_schema_cb_t schema_handler,
+ dx_agent_query_cb_t query_handler)
+{
+ dx_agent_class_t *cls = NEW(dx_agent_class_t);
+ assert(cls);
+ cls->fqname = (char*) malloc(strlen(fqname) + 1);
+ strcpy(cls->fqname, fqname);
+ cls->context = context;
+ cls->schema_handler = schema_handler;
+ cls->query_handler = query_handler;
+
+ dx_field_iterator_t *iter = dx_field_iterator_string(fqname, ITER_VIEW_ALL);
+ int result = hash_insert_const(agent->class_hash, iter, cls);
+ dx_field_iterator_free(iter);
+ assert(result >= 0);
+
+ return cls;
+}
+
+
+dx_agent_class_t *dx_agent_register_event(const char *fqname,
+ void *context,
+ dx_agent_schema_cb_t schema_handler)
+{
+ return dx_agent_register_class(fqname, context, schema_handler, 0);
+}
+
+
+void dx_agent_value_string(const void *correlator, const char *key, const char *value)
+{
+}
+
+
+void dx_agent_value_uint(const void *correlator, const char *key, uint64_t value)
+{
+}
+
+
+void dx_agent_value_null(const void *correlator, const char *key)
+{
+}
+
+
+void dx_agent_value_boolean(const void *correlator, const char *key, bool value)
+{
+}
+
+
+void dx_agent_value_binary(const void *correlator, const char *key, const uint8_t *value, size_t len)
+{
+}
+
+
+void dx_agent_value_uuid(const void *correlator, const char *key, const uint8_t *value)
+{
+}
+
+
+void dx_agent_value_timestamp(const void *correlator, const char *key, uint64_t value)
+{
+}
+
+
+void dx_agent_value_complete(const void *correlator, bool more)
+{
+}
+
+
+void *dx_agent_raise_event(dx_agent_class_t *event)
+{
+ return 0;
+}
+
diff --git a/extras/dispatch/src/alloc.c b/extras/dispatch/src/alloc.c
new file mode 100644
index 0000000000..2b3b953aad
--- /dev/null
+++ b/extras/dispatch/src/alloc.c
@@ -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.
+ */
+
+#include <qpid/dispatch/alloc.h>
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/log.h>
+#include <memory.h>
+#include <stdio.h>
+
+typedef struct item_t item_t;
+
+struct item_t {
+ DEQ_LINKS(item_t);
+ dx_alloc_type_desc_t *desc;
+};
+
+DEQ_DECLARE(item_t, item_list_t);
+
+struct dx_alloc_pool_t {
+ item_list_t free_list;
+};
+
+dx_alloc_config_t dx_alloc_default_config_big = {16, 32, 0};
+dx_alloc_config_t dx_alloc_default_config_small = {64, 128, 0};
+
+sys_mutex_t *init_lock;
+item_list_t type_list;
+
+static void dx_alloc_init(dx_alloc_type_desc_t *desc)
+{
+ sys_mutex_lock(init_lock);
+
+ desc->total_size = desc->type_size;
+ if (desc->additional_size)
+ desc->total_size += *desc->additional_size;
+
+ dx_log("ALLOC", LOG_TRACE, "Initialized Allocator - type=%s type-size=%d total-size=%d",
+ desc->type_name, desc->type_size, desc->total_size);
+
+ if (!desc->global_pool) {
+ if (desc->config == 0)
+ desc->config = desc->total_size > 256 ?
+ &dx_alloc_default_config_big : &dx_alloc_default_config_small;
+
+ assert (desc->config->local_free_list_max >= desc->config->transfer_batch_size);
+
+ desc->global_pool = NEW(dx_alloc_pool_t);
+ DEQ_INIT(desc->global_pool->free_list);
+ desc->lock = sys_mutex();
+ desc->stats = NEW(dx_alloc_stats_t);
+ memset(desc->stats, 0, sizeof(dx_alloc_stats_t));
+ }
+
+ item_t *type_item = NEW(item_t);
+ DEQ_ITEM_INIT(type_item);
+ type_item->desc = desc;
+ DEQ_INSERT_TAIL(type_list, type_item);
+
+ sys_mutex_unlock(init_lock);
+}
+
+
+void *dx_alloc(dx_alloc_type_desc_t *desc, dx_alloc_pool_t **tpool)
+{
+ int idx;
+
+ //
+ // If the descriptor is not initialized, set it up now.
+ //
+ if (!desc->global_pool)
+ dx_alloc_init(desc);
+
+ //
+ // If this is the thread's first pass through here, allocate the
+ // thread-local pool for this type.
+ //
+ if (*tpool == 0) {
+ *tpool = NEW(dx_alloc_pool_t);
+ DEQ_INIT((*tpool)->free_list);
+ }
+
+ dx_alloc_pool_t *pool = *tpool;
+
+ //
+ // Fast case: If there's an item on the local free list, take it off the
+ // list and return it. Since everything we've touched is thread-local,
+ // there is no need to acquire a lock.
+ //
+ item_t *item = DEQ_HEAD(pool->free_list);
+ if (item) {
+ DEQ_REMOVE_HEAD(pool->free_list);
+ return &item[1];
+ }
+
+ //
+ // The local free list is empty, we need to either rebalance a batch
+ // of items from the global list or go to the heap to get new memory.
+ //
+ sys_mutex_lock(desc->lock);
+ if (DEQ_SIZE(desc->global_pool->free_list) >= desc->config->transfer_batch_size) {
+ //
+ // Rebalance a full batch from the global free list to the thread list.
+ //
+ desc->stats->batches_rebalanced_to_threads++;
+ desc->stats->held_by_threads += desc->config->transfer_batch_size;
+ for (idx = 0; idx < desc->config->transfer_batch_size; idx++) {
+ item = DEQ_HEAD(desc->global_pool->free_list);
+ DEQ_REMOVE_HEAD(desc->global_pool->free_list);
+ DEQ_INSERT_TAIL(pool->free_list, item);
+ }
+ } else {
+ //
+ // Allocate a full batch from the heap and put it on the thread list.
+ //
+ for (idx = 0; idx < desc->config->transfer_batch_size; idx++) {
+ item = (item_t*) malloc(sizeof(item_t) + desc->total_size);
+ if (item == 0)
+ break;
+ DEQ_ITEM_INIT(item);
+ item->desc = desc;
+ DEQ_INSERT_TAIL(pool->free_list, item);
+ desc->stats->held_by_threads++;
+ desc->stats->total_alloc_from_heap++;
+ }
+ }
+ sys_mutex_unlock(desc->lock);
+
+ item = DEQ_HEAD(pool->free_list);
+ if (item) {
+ DEQ_REMOVE_HEAD(pool->free_list);
+ return &item[1];
+ }
+
+ return 0;
+}
+
+
+void dx_dealloc(dx_alloc_type_desc_t *desc, dx_alloc_pool_t **tpool, void *p)
+{
+ item_t *item = ((item_t*) p) - 1;
+ int idx;
+
+ //
+ // If this is the thread's first pass through here, allocate the
+ // thread-local pool for this type.
+ //
+ if (*tpool == 0) {
+ *tpool = NEW(dx_alloc_pool_t);
+ DEQ_INIT((*tpool)->free_list);
+ }
+
+ dx_alloc_pool_t *pool = *tpool;
+
+ DEQ_INSERT_TAIL(pool->free_list, item);
+
+ if (DEQ_SIZE(pool->free_list) <= desc->config->local_free_list_max)
+ return;
+
+ //
+ // We've exceeded the maximum size of the local free list. A batch must be
+ // rebalanced back to the global list.
+ //
+ sys_mutex_lock(desc->lock);
+ desc->stats->batches_rebalanced_to_global++;
+ desc->stats->held_by_threads -= desc->config->transfer_batch_size;
+ for (idx = 0; idx < desc->config->transfer_batch_size; idx++) {
+ item = DEQ_HEAD(pool->free_list);
+ DEQ_REMOVE_HEAD(pool->free_list);
+ DEQ_INSERT_TAIL(desc->global_pool->free_list, item);
+ }
+
+ //
+ // If there's a global_free_list size limit, remove items until the limit is
+ // not exceeded.
+ //
+ if (desc->config->global_free_list_max != 0) {
+ while (DEQ_SIZE(desc->global_pool->free_list) > desc->config->global_free_list_max) {
+ item = DEQ_HEAD(desc->global_pool->free_list);
+ DEQ_REMOVE_HEAD(desc->global_pool->free_list);
+ free(item);
+ desc->stats->total_free_to_heap++;
+ }
+ }
+
+ sys_mutex_unlock(desc->lock);
+}
+
+
+void dx_alloc_initialize(void)
+{
+ init_lock = sys_mutex();
+ DEQ_INIT(type_list);
+}
+
diff --git a/extras/dispatch/src/alloc_private.h b/extras/dispatch/src/alloc_private.h
new file mode 100644
index 0000000000..fbb18ccd48
--- /dev/null
+++ b/extras/dispatch/src/alloc_private.h
@@ -0,0 +1,26 @@
+#ifndef __dispatch_alloc_private_h__
+#define __dispatch_alloc_private_h__ 1
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/alloc.h>
+
+void dx_alloc_initialize(void);
+
+#endif
diff --git a/extras/dispatch/src/auth.c b/extras/dispatch/src/auth.c
new file mode 100644
index 0000000000..f0df58f6c2
--- /dev/null
+++ b/extras/dispatch/src/auth.c
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "auth.h"
+#include "server_private.h"
+#include <proton/sasl.h>
+
+
+void auth_client_handler(pn_connector_t *cxtr)
+{
+ pn_sasl_t *sasl = pn_connector_sasl(cxtr);
+ pn_sasl_state_t state = pn_sasl_state(sasl);
+ dx_connection_t *ctx = (dx_connection_t*) pn_connector_context(cxtr);
+
+ if (state == PN_SASL_CONF) {
+ pn_sasl_mechanisms(sasl, "ANONYMOUS");
+ pn_sasl_client(sasl);
+ }
+
+ state = pn_sasl_state(sasl);
+
+ if (state == PN_SASL_PASS) {
+ ctx->state = CONN_STATE_OPENING;
+ } else if (state == PN_SASL_FAIL) {
+ ctx->state = CONN_STATE_FAILED;
+ }
+}
+
+
+void auth_server_handler(pn_connector_t *cxtr)
+{
+ pn_sasl_t *sasl = pn_connector_sasl(cxtr);
+ pn_sasl_state_t state = pn_sasl_state(sasl);
+ dx_connection_t *ctx = (dx_connection_t*) pn_connector_context(cxtr);
+
+ while (state == PN_SASL_CONF || state == PN_SASL_STEP) {
+ if (state == PN_SASL_CONF) {
+ pn_sasl_mechanisms(sasl, "ANONYMOUS");
+ pn_sasl_server(sasl);
+ } else if (state == PN_SASL_STEP) {
+ const char* mechanisms = pn_sasl_remote_mechanisms(sasl);
+ if (strcmp(mechanisms, "ANONYMOUS") == 0)
+ pn_sasl_done(sasl, PN_SASL_OK);
+ else
+ pn_sasl_done(sasl, PN_SASL_AUTH);
+ }
+ state = pn_sasl_state(sasl);
+ }
+
+ if (state == PN_SASL_PASS) {
+ ctx->state = CONN_STATE_OPENING;
+ } else if (state == PN_SASL_FAIL) {
+ ctx->state = CONN_STATE_FAILED;
+ }
+}
+
+
diff --git a/extras/dispatch/src/auth.h b/extras/dispatch/src/auth.h
new file mode 100644
index 0000000000..c551c8ff76
--- /dev/null
+++ b/extras/dispatch/src/auth.h
@@ -0,0 +1,27 @@
+#ifndef __auth_h__
+#define __auth_h__ 1
+/*
+ * 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.
+ */
+
+#include <proton/driver.h>
+
+void auth_client_handler(pn_connector_t *conn);
+void auth_server_handler(pn_connector_t *conn);
+
+#endif
diff --git a/extras/dispatch/src/buffer.c b/extras/dispatch/src/buffer.c
new file mode 100644
index 0000000000..015711afd9
--- /dev/null
+++ b/extras/dispatch/src/buffer.c
@@ -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.
+ */
+
+#include <qpid/dispatch/buffer.h>
+#include <qpid/dispatch/alloc.h>
+
+static size_t buffer_size = 512;
+static int size_locked = 0;
+
+ALLOC_DECLARE(dx_buffer_t);
+ALLOC_DEFINE_CONFIG(dx_buffer_t, sizeof(dx_buffer_t), &buffer_size, 0);
+
+
+void dx_buffer_set_size(size_t size)
+{
+ assert(!size_locked);
+ buffer_size = size;
+}
+
+
+dx_buffer_t *dx_allocate_buffer(void)
+{
+ size_locked = 1;
+ dx_buffer_t *buf = new_dx_buffer_t();
+
+ DEQ_ITEM_INIT(buf);
+ buf->size = 0;
+ return buf;
+}
+
+
+void dx_free_buffer(dx_buffer_t *buf)
+{
+ free_dx_buffer_t(buf);
+}
+
+
+unsigned char *dx_buffer_base(dx_buffer_t *buf)
+{
+ return (unsigned char*) &buf[1];
+}
+
+
+unsigned char *dx_buffer_cursor(dx_buffer_t *buf)
+{
+ return ((unsigned char*) &buf[1]) + buf->size;
+}
+
+
+size_t dx_buffer_capacity(dx_buffer_t *buf)
+{
+ return buffer_size - buf->size;
+}
+
+
+size_t dx_buffer_size(dx_buffer_t *buf)
+{
+ return buf->size;
+}
+
+
+void dx_buffer_insert(dx_buffer_t *buf, size_t len)
+{
+ buf->size += len;
+ assert(buf->size <= buffer_size);
+}
+
diff --git a/extras/dispatch/src/container.c b/extras/dispatch/src/container.c
new file mode 100644
index 0000000000..68e2afa3eb
--- /dev/null
+++ b/extras/dispatch/src/container.c
@@ -0,0 +1,616 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <qpid/dispatch/container.h>
+#include <qpid/dispatch/message.h>
+#include <proton/engine.h>
+#include <proton/message.h>
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/hash.h>
+#include <qpid/dispatch/threading.h>
+#include <qpid/dispatch/iterator.h>
+#include <qpid/dispatch/log.h>
+
+static char *module="CONTAINER";
+
+struct dx_node_t {
+ const dx_node_type_t *ntype;
+ char *name;
+ void *context;
+ dx_dist_mode_t supported_dist;
+ dx_lifetime_policy_t life_policy;
+};
+
+ALLOC_DECLARE(dx_node_t);
+ALLOC_DEFINE(dx_node_t);
+ALLOC_DEFINE(dx_link_item_t);
+
+struct dx_link_t {
+ pn_link_t *pn_link;
+ void *context;
+ dx_node_t *node;
+};
+
+ALLOC_DECLARE(dx_link_t);
+ALLOC_DEFINE(dx_link_t);
+
+typedef struct nxc_node_type_t {
+ DEQ_LINKS(struct nxc_node_type_t);
+ const dx_node_type_t *ntype;
+} nxc_node_type_t;
+DEQ_DECLARE(nxc_node_type_t, nxc_node_type_list_t);
+
+
+static hash_t *node_type_map;
+static hash_t *node_map;
+static sys_mutex_t *lock;
+static dx_node_t *default_node;
+static nxc_node_type_list_t node_type_list;
+
+static void setup_outgoing_link(pn_link_t *pn_link)
+{
+ sys_mutex_lock(lock);
+ dx_node_t *node;
+ int result;
+ const char *source = pn_terminus_get_address(pn_link_remote_source(pn_link));
+ dx_field_iterator_t *iter;
+ // TODO - Extract the name from the structured source
+
+ if (source) {
+ iter = dx_field_iterator_string(source, ITER_VIEW_NODE_ID);
+ result = hash_retrieve(node_map, iter, (void*) &node);
+ dx_field_iterator_free(iter);
+ } else
+ result = -1;
+ sys_mutex_unlock(lock);
+
+ if (result < 0) {
+ if (default_node)
+ node = default_node;
+ else {
+ // Reject the link
+ // TODO - When the API allows, add an error message for "no available node"
+ pn_link_close(pn_link);
+ return;
+ }
+ }
+
+ dx_link_t *link = new_dx_link_t();
+ if (!link) {
+ pn_link_close(pn_link);
+ return;
+ }
+
+ link->pn_link = pn_link;
+ link->context = 0;
+ link->node = node;
+
+ pn_link_set_context(pn_link, link);
+ node->ntype->outgoing_handler(node->context, link);
+}
+
+
+static void setup_incoming_link(pn_link_t *pn_link)
+{
+ sys_mutex_lock(lock);
+ dx_node_t *node;
+ int result;
+ const char *target = pn_terminus_get_address(pn_link_remote_target(pn_link));
+ dx_field_iterator_t *iter;
+ // TODO - Extract the name from the structured target
+
+ if (target) {
+ iter = dx_field_iterator_string(target, ITER_VIEW_NODE_ID);
+ result = hash_retrieve(node_map, iter, (void*) &node);
+ dx_field_iterator_free(iter);
+ } else
+ result = -1;
+ sys_mutex_unlock(lock);
+
+ if (result < 0) {
+ if (default_node)
+ node = default_node;
+ else {
+ // Reject the link
+ // TODO - When the API allows, add an error message for "no available node"
+ pn_link_close(pn_link);
+ return;
+ }
+ }
+
+ dx_link_t *link = new_dx_link_t();
+ if (!link) {
+ pn_link_close(pn_link);
+ return;
+ }
+
+ link->pn_link = pn_link;
+ link->context = 0;
+ link->node = node;
+
+ pn_link_set_context(pn_link, link);
+ node->ntype->incoming_handler(node->context, link);
+}
+
+
+static int do_writable(pn_link_t *pn_link)
+{
+ dx_link_t *link = (dx_link_t*) pn_link_get_context(pn_link);
+ if (!link)
+ return 0;
+
+ dx_node_t *node = link->node;
+ if (!node)
+ return 0;
+
+ return node->ntype->writable_handler(node->context, link);
+}
+
+
+static void process_receive(pn_delivery_t *delivery)
+{
+ pn_link_t *pn_link = pn_delivery_link(delivery);
+ dx_link_t *link = (dx_link_t*) pn_link_get_context(pn_link);
+
+ if (link) {
+ dx_node_t *node = link->node;
+ if (node) {
+ node->ntype->rx_handler(node->context, link, delivery);
+ return;
+ }
+ }
+
+ //
+ // Reject the delivery if we couldn't find a node to handle it
+ //
+ pn_link_advance(pn_link);
+ pn_link_flow(pn_link, 1);
+ pn_delivery_update(delivery, PN_REJECTED);
+ pn_delivery_settle(delivery);
+}
+
+
+static void do_send(pn_delivery_t *delivery)
+{
+ pn_link_t *pn_link = pn_delivery_link(delivery);
+ dx_link_t *link = (dx_link_t*) pn_link_get_context(pn_link);
+
+ if (link) {
+ dx_node_t *node = link->node;
+ if (node) {
+ node->ntype->tx_handler(node->context, link, delivery);
+ return;
+ }
+ }
+
+ // TODO - Cancel the delivery
+}
+
+
+static void do_updated(pn_delivery_t *delivery)
+{
+ pn_link_t *pn_link = pn_delivery_link(delivery);
+ dx_link_t *link = (dx_link_t*) pn_link_get_context(pn_link);
+
+ if (link) {
+ dx_node_t *node = link->node;
+ if (node)
+ node->ntype->disp_handler(node->context, link, delivery);
+ }
+}
+
+
+static int close_handler(void* unused, pn_connection_t *conn)
+{
+ //
+ // Close all links, passing False as the 'closed' argument. These links are not
+ // being properly 'detached'. They are being orphaned.
+ //
+ pn_link_t *pn_link = pn_link_head(conn, 0);
+ while (pn_link) {
+ dx_link_t *link = (dx_link_t*) pn_link_get_context(pn_link);
+ dx_node_t *node = link->node;
+ if (node)
+ node->ntype->link_detach_handler(node->context, link, 0);
+ pn_link_close(pn_link);
+ free_dx_link_t(link);
+ pn_link = pn_link_next(pn_link, 0);
+ }
+
+ // teardown all sessions
+ pn_session_t *ssn = pn_session_head(conn, 0);
+ while (ssn) {
+ pn_session_close(ssn);
+ ssn = pn_session_next(ssn, 0);
+ }
+
+ // teardown the connection
+ pn_connection_close(conn);
+ return 0;
+}
+
+
+static int process_handler(void* unused, pn_connection_t *conn)
+{
+ pn_session_t *ssn;
+ pn_link_t *pn_link;
+ pn_delivery_t *delivery;
+ int event_count = 0;
+
+ // Step 1: setup the engine's connection, and any sessions and links
+ // that may be pending.
+
+ // initialize the connection if it's new
+ if (pn_connection_state(conn) & PN_LOCAL_UNINIT) {
+ pn_connection_open(conn);
+ event_count++;
+ }
+
+ // open all pending sessions
+ ssn = pn_session_head(conn, PN_LOCAL_UNINIT);
+ while (ssn) {
+ pn_session_open(ssn);
+ ssn = pn_session_next(ssn, PN_LOCAL_UNINIT);
+ event_count++;
+ }
+
+ // configure and open any pending links
+ pn_link = pn_link_head(conn, PN_LOCAL_UNINIT);
+ while (pn_link) {
+ if (pn_link_is_sender(pn_link))
+ setup_outgoing_link(pn_link);
+ else
+ setup_incoming_link(pn_link);
+ pn_link = pn_link_next(pn_link, PN_LOCAL_UNINIT);
+ event_count++;
+ }
+
+
+ // Step 2: Now drain all the pending deliveries from the connection's
+ // work queue and process them
+
+ delivery = pn_work_head(conn);
+ while (delivery) {
+ if (pn_delivery_readable(delivery))
+ process_receive(delivery);
+ else if (pn_delivery_writable(delivery))
+ do_send(delivery);
+
+ if (pn_delivery_updated(delivery))
+ do_updated(delivery);
+
+ delivery = pn_work_next(delivery);
+ event_count++;
+ }
+
+ //
+ // Step 2.5: Traverse all of the links on the connection looking for
+ // outgoing links with non-zero credit. Call the attached node's
+ // writable handler for such links.
+ //
+ pn_link = pn_link_head(conn, PN_LOCAL_ACTIVE | PN_REMOTE_ACTIVE);
+ while (pn_link) {
+ assert(pn_session_connection(pn_link_session(pn_link)) == conn);
+ if (pn_link_is_sender(pn_link) && pn_link_credit(pn_link) > 0)
+ event_count += do_writable(pn_link);
+ pn_link = pn_link_next(pn_link, PN_LOCAL_ACTIVE | PN_REMOTE_ACTIVE);
+ }
+
+ // Step 3: Clean up any links or sessions that have been closed by the
+ // remote. If the connection has been closed remotely, clean that up
+ // also.
+
+ // teardown any terminating links
+ pn_link = pn_link_head(conn, PN_LOCAL_ACTIVE | PN_REMOTE_CLOSED);
+ while (pn_link) {
+ dx_link_t *link = (dx_link_t*) pn_link_get_context(pn_link);
+ dx_node_t *node = link->node;
+ if (node)
+ node->ntype->link_detach_handler(node->context, link, 1); // TODO - get 'closed' from detach message
+ pn_link_close(pn_link);
+ pn_link = pn_link_next(pn_link, PN_LOCAL_ACTIVE | PN_REMOTE_CLOSED);
+ event_count++;
+ }
+
+ // teardown any terminating sessions
+ ssn = pn_session_head(conn, PN_LOCAL_ACTIVE | PN_REMOTE_CLOSED);
+ while (ssn) {
+ pn_session_close(ssn);
+ ssn = pn_session_next(ssn, PN_LOCAL_ACTIVE | PN_REMOTE_CLOSED);
+ event_count++;
+ }
+
+ // teardown the connection if it's terminating
+ if (pn_connection_state(conn) == (PN_LOCAL_ACTIVE | PN_REMOTE_CLOSED)) {
+ pn_connection_close(conn);
+ event_count++;
+ }
+
+ return event_count;
+}
+
+
+static void open_handler(dx_connection_t *conn, dx_direction_t dir)
+{
+ const dx_node_type_t *nt;
+
+ //
+ // Note the locking structure in this function. Generally this would be unsafe, but since
+ // this particular list is only ever appended to and never has items inserted or deleted,
+ // this usage is safe in this case.
+ //
+ sys_mutex_lock(lock);
+ nxc_node_type_t *nt_item = DEQ_HEAD(node_type_list);
+ sys_mutex_unlock(lock);
+
+ pn_connection_open(dx_connection_pn(conn));
+
+ while (nt_item) {
+ nt = nt_item->ntype;
+ if (dir == DX_INCOMING) {
+ if (nt->inbound_conn_open_handler)
+ nt->inbound_conn_open_handler(nt->type_context, conn);
+ } else {
+ if (nt->outbound_conn_open_handler)
+ nt->outbound_conn_open_handler(nt->type_context, conn);
+ }
+
+ sys_mutex_lock(lock);
+ nt_item = DEQ_NEXT(nt_item);
+ sys_mutex_unlock(lock);
+ }
+}
+
+
+static int handler(void* context, dx_conn_event_t event, dx_connection_t *dx_conn)
+{
+ pn_connection_t *conn = dx_connection_pn(dx_conn);
+
+ switch (event) {
+ case DX_CONN_EVENT_LISTENER_OPEN: open_handler(dx_conn, DX_INCOMING); break;
+ case DX_CONN_EVENT_CONNECTOR_OPEN: open_handler(dx_conn, DX_OUTGOING); break;
+ case DX_CONN_EVENT_CLOSE: return close_handler(context, conn);
+ case DX_CONN_EVENT_PROCESS: return process_handler(context, conn);
+ }
+
+ return 0;
+}
+
+
+void dx_container_initialize(void)
+{
+ dx_log(module, LOG_TRACE, "Container Initializing");
+
+ node_type_map = hash(6, 4, 1); // 64 buckets, item batches of 4
+ node_map = hash(10, 32, 0); // 1K buckets, item batches of 32
+ lock = sys_mutex();
+ default_node = 0;
+ DEQ_INIT(node_type_list);
+
+ dx_server_set_conn_handler(handler);
+}
+
+
+void dx_container_finalize(void)
+{
+}
+
+
+int dx_container_register_node_type(const dx_node_type_t *nt)
+{
+ int result;
+ dx_field_iterator_t *iter = dx_field_iterator_string(nt->type_name, ITER_VIEW_ALL);
+ nxc_node_type_t *nt_item = NEW(nxc_node_type_t);
+ DEQ_ITEM_INIT(nt_item);
+ nt_item->ntype = nt;
+
+ sys_mutex_lock(lock);
+ result = hash_insert_const(node_type_map, iter, nt);
+ DEQ_INSERT_TAIL(node_type_list, nt_item);
+ sys_mutex_unlock(lock);
+
+ dx_field_iterator_free(iter);
+ if (result < 0)
+ return result;
+ dx_log(module, LOG_TRACE, "Node Type Registered - %s", nt->type_name);
+
+ return 0;
+}
+
+
+void dx_container_set_default_node_type(const dx_node_type_t *nt,
+ void *context,
+ dx_dist_mode_t supported_dist)
+{
+ if (default_node)
+ dx_container_destroy_node(default_node);
+
+ if (nt) {
+ default_node = dx_container_create_node(nt, 0, context, supported_dist, DX_LIFE_PERMANENT);
+ dx_log(module, LOG_TRACE, "Node of type '%s' installed as default node", nt->type_name);
+ } else {
+ default_node = 0;
+ dx_log(module, LOG_TRACE, "Default node removed");
+ }
+}
+
+
+dx_node_t *dx_container_create_node(const dx_node_type_t *nt,
+ const char *name,
+ void *context,
+ dx_dist_mode_t supported_dist,
+ dx_lifetime_policy_t life_policy)
+{
+ int result;
+ dx_node_t *node = new_dx_node_t();
+ if (!node)
+ return 0;
+
+ node->ntype = nt;
+ node->name = 0;
+ node->context = context;
+ node->supported_dist = supported_dist;
+ node->life_policy = life_policy;
+
+ if (name) {
+ dx_field_iterator_t *iter = dx_field_iterator_string(name, ITER_VIEW_ALL);
+ sys_mutex_lock(lock);
+ result = hash_insert(node_map, iter, node);
+ sys_mutex_unlock(lock);
+ dx_field_iterator_free(iter);
+ if (result < 0) {
+ free_dx_node_t(node);
+ return 0;
+ }
+
+ node->name = (char*) malloc(strlen(name) + 1);
+ strcpy(node->name, name);
+ }
+
+ if (name)
+ dx_log(module, LOG_TRACE, "Node of type '%s' created with name '%s'", nt->type_name, name);
+
+ return node;
+}
+
+
+void dx_container_destroy_node(dx_node_t *node)
+{
+ if (node->name) {
+ dx_field_iterator_t *iter = dx_field_iterator_string(node->name, ITER_VIEW_ALL);
+ sys_mutex_lock(lock);
+ hash_remove(node_map, iter);
+ sys_mutex_unlock(lock);
+ dx_field_iterator_free(iter);
+ free(node->name);
+ }
+
+ free_dx_node_t(node);
+}
+
+
+void dx_container_node_set_context(dx_node_t *node, void *node_context)
+{
+ node->context = node_context;
+}
+
+
+dx_dist_mode_t dx_container_node_get_dist_modes(const dx_node_t *node)
+{
+ return node->supported_dist;
+}
+
+
+dx_lifetime_policy_t dx_container_node_get_life_policy(const dx_node_t *node)
+{
+ return node->life_policy;
+}
+
+
+dx_link_t *dx_link(dx_node_t *node, dx_connection_t *conn, dx_direction_t dir, const char* name)
+{
+ pn_session_t *sess = pn_session(dx_connection_pn(conn));
+ dx_link_t *link = new_dx_link_t();
+
+ if (dir == DX_OUTGOING)
+ link->pn_link = pn_sender(sess, name);
+ else
+ link->pn_link = pn_receiver(sess, name);
+ link->context = node->context;
+ link->node = node;
+
+ pn_link_set_context(link->pn_link, link);
+
+ pn_session_open(sess);
+
+ return link;
+}
+
+
+void dx_link_set_context(dx_link_t *link, void *context)
+{
+ link->context = context;
+}
+
+
+void *dx_link_get_context(dx_link_t *link)
+{
+ return link->context;
+}
+
+
+pn_link_t *dx_link_pn(dx_link_t *link)
+{
+ return link->pn_link;
+}
+
+
+pn_terminus_t *dx_link_source(dx_link_t *link)
+{
+ return pn_link_source(link->pn_link);
+}
+
+
+pn_terminus_t *dx_link_target(dx_link_t *link)
+{
+ return pn_link_target(link->pn_link);
+}
+
+
+pn_terminus_t *dx_link_remote_source(dx_link_t *link)
+{
+ return pn_link_remote_source(link->pn_link);
+}
+
+
+pn_terminus_t *dx_link_remote_target(dx_link_t *link)
+{
+ return pn_link_remote_target(link->pn_link);
+}
+
+
+void dx_link_activate(dx_link_t *link)
+{
+ if (!link || !link->pn_link)
+ return;
+
+ pn_session_t *sess = pn_link_session(link->pn_link);
+ if (!sess)
+ return;
+
+ pn_connection_t *conn = pn_session_connection(sess);
+ if (!conn)
+ return;
+
+ dx_connection_t *ctx = pn_connection_get_context(conn);
+ if (!ctx)
+ return;
+
+ dx_server_activate(ctx);
+}
+
+
+void dx_link_close(dx_link_t *link)
+{
+ pn_link_close(link->pn_link);
+}
+
+
diff --git a/extras/dispatch/src/hash.c b/extras/dispatch/src/hash.c
new file mode 100644
index 0000000000..c54d5d6fcf
--- /dev/null
+++ b/extras/dispatch/src/hash.c
@@ -0,0 +1,223 @@
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/hash.h>
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/alloc.h>
+#include <stdio.h>
+#include <string.h>
+
+typedef struct hash_item_t {
+ DEQ_LINKS(struct hash_item_t);
+ unsigned char *key;
+ union {
+ void *val;
+ const void *val_const;
+ } v;
+} hash_item_t;
+
+ALLOC_DECLARE(hash_item_t);
+ALLOC_DEFINE(hash_item_t);
+DEQ_DECLARE(hash_item_t, items_t);
+
+
+typedef struct bucket_t {
+ items_t items;
+} bucket_t;
+
+
+struct hash_t {
+ bucket_t *buckets;
+ unsigned int bucket_count;
+ unsigned int bucket_mask;
+ int batch_size;
+ size_t size;
+ int is_const;
+};
+
+
+// djb2 hash algorithm
+static unsigned long hash_function(dx_field_iterator_t *iter)
+{
+ unsigned long hash = 5381;
+ int c;
+
+ while (!dx_field_iterator_end(iter)) {
+ c = (int) dx_field_iterator_octet(iter);
+ hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
+ }
+
+ return hash;
+}
+
+
+hash_t *hash(int bucket_exponent, int batch_size, int value_is_const)
+{
+ int i;
+ hash_t *h = NEW(hash_t);
+
+ if (!h)
+ return 0;
+
+ h->bucket_count = 1 << bucket_exponent;
+ h->bucket_mask = h->bucket_count - 1;
+ h->batch_size = batch_size;
+ h->size = 0;
+ h->is_const = value_is_const;
+ h->buckets = NEW_ARRAY(bucket_t, h->bucket_count);
+ for (i = 0; i < h->bucket_count; i++) {
+ DEQ_INIT(h->buckets[i].items);
+ }
+
+ return h;
+}
+
+
+void hash_free(hash_t *h)
+{
+ // TODO - Implement this
+}
+
+
+size_t hash_size(hash_t *h)
+{
+ return h ? h->size : 0;
+}
+
+
+static hash_item_t *hash_internal_insert(hash_t *h, dx_field_iterator_t *key, int *error)
+{
+ unsigned long idx = hash_function(key) & h->bucket_mask;
+ hash_item_t *item = DEQ_HEAD(h->buckets[idx].items);
+
+ *error = 0;
+
+ while (item) {
+ if (dx_field_iterator_equal(key, item->key))
+ break;
+ item = item->next;
+ }
+
+ if (item) {
+ *error = -1;
+ return 0;
+ }
+
+ item = new_hash_item_t();
+ if (!item) {
+ *error = -2;
+ return 0;
+ }
+
+ DEQ_ITEM_INIT(item);
+ item->key = dx_field_iterator_copy(key);
+
+ DEQ_INSERT_TAIL(h->buckets[idx].items, item);
+ h->size++;
+ return item;
+}
+
+
+int hash_insert(hash_t *h, dx_field_iterator_t *key, void *val)
+{
+ int error = 0;
+ hash_item_t *item = hash_internal_insert(h, key, &error);
+
+ if (item)
+ item->v.val = val;
+ return error;
+}
+
+
+int hash_insert_const(hash_t *h, dx_field_iterator_t *key, const void *val)
+{
+ if (!h->is_const)
+ return -3;
+
+ int error = 0;
+ hash_item_t *item = hash_internal_insert(h, key, &error);
+
+ if (item)
+ item->v.val_const = val;
+ return error;
+}
+
+
+static hash_item_t *hash_internal_retrieve(hash_t *h, dx_field_iterator_t *key)
+{
+ unsigned long idx = hash_function(key) & h->bucket_mask;
+ hash_item_t *item = DEQ_HEAD(h->buckets[idx].items);
+
+ while (item) {
+ if (dx_field_iterator_equal(key, item->key))
+ break;
+ item = item->next;
+ }
+
+ return item;
+}
+
+
+int hash_retrieve(hash_t *h, dx_field_iterator_t *key, void **val)
+{
+ hash_item_t *item = hash_internal_retrieve(h, key);
+ if (item) {
+ *val = item->v.val;
+ return 0;
+ }
+ return -1;
+}
+
+
+int hash_retrieve_const(hash_t *h, dx_field_iterator_t *key, const void **val)
+{
+ if (!h->is_const)
+ return -3;
+
+ hash_item_t *item = hash_internal_retrieve(h, key);
+ if (item) {
+ *val = item->v.val_const;
+ return 0;
+ }
+ return -1;
+}
+
+
+int hash_remove(hash_t *h, dx_field_iterator_t *key)
+{
+ unsigned long idx = hash_function(key) & h->bucket_mask;
+ hash_item_t *item = DEQ_HEAD(h->buckets[idx].items);
+
+ while (item) {
+ if (dx_field_iterator_equal(key, item->key))
+ break;
+ item = item->next;
+ }
+
+ if (item) {
+ free(item->key);
+ DEQ_REMOVE(h->buckets[idx].items, item);
+ free_hash_item_t(item);
+ h->size--;
+ return 0;
+ }
+
+ return -1;
+}
+
diff --git a/extras/dispatch/src/iovec.c b/extras/dispatch/src/iovec.c
new file mode 100644
index 0000000000..6ff6874440
--- /dev/null
+++ b/extras/dispatch/src/iovec.c
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/iovec.h>
+#include <qpid/dispatch/alloc.h>
+#include <string.h>
+
+#define DX_IOVEC_MAX 64
+
+struct dx_iovec_t {
+ struct iovec iov_array[DX_IOVEC_MAX];
+ struct iovec *iov;
+ int iov_count;
+};
+
+
+ALLOC_DECLARE(dx_iovec_t);
+ALLOC_DEFINE(dx_iovec_t);
+
+
+dx_iovec_t *dx_iovec(int vector_count)
+{
+ dx_iovec_t *iov = new_dx_iovec_t();
+ if (!iov)
+ return 0;
+
+ memset(iov, 0, sizeof(dx_iovec_t));
+
+ iov->iov_count = vector_count;
+ if (vector_count > DX_IOVEC_MAX)
+ iov->iov = (struct iovec*) malloc(sizeof(struct iovec) * vector_count);
+ else
+ iov->iov = &iov->iov_array[0];
+
+ return iov;
+}
+
+
+void dx_iovec_free(dx_iovec_t *iov)
+{
+ if (!iov)
+ return;
+
+ if (iov->iov && iov->iov != &iov->iov_array[0])
+ free(iov->iov);
+
+ free_dx_iovec_t(iov);
+}
+
+
+struct iovec *dx_iovec_array(dx_iovec_t *iov)
+{
+ if (!iov)
+ return 0;
+ return iov->iov;
+}
+
+
+int dx_iovec_count(dx_iovec_t *iov)
+{
+ if (!iov)
+ return 0;
+ return iov->iov_count;
+}
+
diff --git a/extras/dispatch/src/iterator.c b/extras/dispatch/src/iterator.c
new file mode 100644
index 0000000000..6ab67f948d
--- /dev/null
+++ b/extras/dispatch/src/iterator.c
@@ -0,0 +1,268 @@
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/iterator.h>
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/alloc.h>
+#include "message_private.h"
+#include <stdio.h>
+#include <string.h>
+
+typedef enum {
+MODE_TO_END,
+MODE_TO_SLASH
+} parse_mode_t;
+
+struct dx_field_iterator_t {
+ dx_buffer_t *start_buffer;
+ unsigned char *start_cursor;
+ int start_length;
+ dx_buffer_t *buffer;
+ unsigned char *cursor;
+ int length;
+ dx_iterator_view_t view;
+ parse_mode_t mode;
+};
+
+
+ALLOC_DECLARE(dx_field_iterator_t);
+ALLOC_DEFINE(dx_field_iterator_t);
+
+
+typedef enum {
+STATE_START,
+STATE_SLASH_LEFT,
+STATE_SKIPPING_TO_NEXT_SLASH,
+STATE_SCANNING,
+STATE_COLON,
+STATE_COLON_SLASH,
+STATE_AT_NODE_ID
+} state_t;
+
+
+static void view_initialize(dx_field_iterator_t *iter)
+{
+ if (iter->view == ITER_VIEW_ALL) {
+ iter->mode = MODE_TO_END;
+ return;
+ }
+
+ //
+ // Advance to the node-id.
+ //
+ state_t state = STATE_START;
+ unsigned int octet;
+ while (!dx_field_iterator_end(iter) && state != STATE_AT_NODE_ID) {
+ octet = dx_field_iterator_octet(iter);
+ switch (state) {
+ case STATE_START :
+ if (octet == '/')
+ state = STATE_SLASH_LEFT;
+ else
+ state = STATE_SCANNING;
+ break;
+
+ case STATE_SLASH_LEFT :
+ if (octet == '/')
+ state = STATE_SKIPPING_TO_NEXT_SLASH;
+ else
+ state = STATE_AT_NODE_ID;
+ break;
+
+ case STATE_SKIPPING_TO_NEXT_SLASH :
+ if (octet == '/')
+ state = STATE_AT_NODE_ID;
+ break;
+
+ case STATE_SCANNING :
+ if (octet == ':')
+ state = STATE_COLON;
+ break;
+
+ case STATE_COLON :
+ if (octet == '/')
+ state = STATE_COLON_SLASH;
+ else
+ state = STATE_SCANNING;
+ break;
+
+ case STATE_COLON_SLASH :
+ if (octet == '/')
+ state = STATE_SKIPPING_TO_NEXT_SLASH;
+ else
+ state = STATE_SCANNING;
+ break;
+
+ case STATE_AT_NODE_ID :
+ break;
+ }
+ }
+
+ if (state != STATE_AT_NODE_ID) {
+ //
+ // The address string was relative, not absolute. The node-id
+ // is at the beginning of the string.
+ //
+ iter->buffer = iter->start_buffer;
+ iter->cursor = iter->start_cursor;
+ iter->length = iter->start_length;
+ }
+
+ //
+ // Cursor is now on the first octet of the node-id
+ //
+ if (iter->view == ITER_VIEW_NODE_ID) {
+ iter->mode = MODE_TO_SLASH;
+ return;
+ }
+
+ if (iter->view == ITER_VIEW_NO_HOST) {
+ iter->mode = MODE_TO_END;
+ return;
+ }
+
+ if (iter->view == ITER_VIEW_NODE_SPECIFIC) {
+ iter->mode = MODE_TO_END;
+ while (!dx_field_iterator_end(iter)) {
+ octet = dx_field_iterator_octet(iter);
+ if (octet == '/')
+ break;
+ }
+ return;
+ }
+}
+
+
+dx_field_iterator_t* dx_field_iterator_string(const char *text, dx_iterator_view_t view)
+{
+ dx_field_iterator_t *iter = new_dx_field_iterator_t();
+ if (!iter)
+ return 0;
+
+ iter->start_buffer = 0;
+ iter->start_cursor = (unsigned char*) text;
+ iter->start_length = strlen(text);
+
+ dx_field_iterator_reset(iter, view);
+
+ return iter;
+}
+
+
+dx_field_iterator_t *dx_field_iterator_buffer(dx_buffer_t *buffer, int offset, int length, dx_iterator_view_t view)
+{
+ dx_field_iterator_t *iter = new_dx_field_iterator_t();
+ if (!iter)
+ return 0;
+
+ iter->start_buffer = buffer;
+ iter->start_cursor = dx_buffer_base(buffer) + offset;
+ iter->start_length = length;
+
+ dx_field_iterator_reset(iter, view);
+
+ return iter;
+}
+
+
+void dx_field_iterator_free(dx_field_iterator_t *iter)
+{
+ free_dx_field_iterator_t(iter);
+}
+
+
+void dx_field_iterator_reset(dx_field_iterator_t *iter, dx_iterator_view_t view)
+{
+ iter->buffer = iter->start_buffer;
+ iter->cursor = iter->start_cursor;
+ iter->length = iter->start_length;
+ iter->view = view;
+
+ view_initialize(iter);
+}
+
+
+unsigned char dx_field_iterator_octet(dx_field_iterator_t *iter)
+{
+ if (iter->length == 0)
+ return (unsigned char) 0;
+
+ unsigned char result = *(iter->cursor);
+
+ iter->cursor++;
+ iter->length--;
+
+ if (iter->length > 0) {
+ if (iter->buffer) {
+ if (iter->cursor - dx_buffer_base(iter->buffer) == dx_buffer_size(iter->buffer)) {
+ iter->buffer = iter->buffer->next;
+ if (iter->buffer == 0)
+ iter->length = 0;
+ iter->cursor = dx_buffer_base(iter->buffer);
+ }
+ }
+ }
+
+ if (iter->length && iter->mode == MODE_TO_SLASH && *(iter->cursor) == '/')
+ iter->length = 0;
+
+ return result;
+}
+
+
+int dx_field_iterator_end(dx_field_iterator_t *iter)
+{
+ return iter->length == 0;
+}
+
+
+int dx_field_iterator_equal(dx_field_iterator_t *iter, unsigned char *string)
+{
+ dx_field_iterator_reset(iter, iter->view);
+ while (!dx_field_iterator_end(iter) && *string) {
+ if (*string != dx_field_iterator_octet(iter))
+ return 0;
+ string++;
+ }
+
+ return (dx_field_iterator_end(iter) && (*string == 0));
+}
+
+
+unsigned char *dx_field_iterator_copy(dx_field_iterator_t *iter)
+{
+ int length = 0;
+ int idx = 0;
+ unsigned char *copy;
+
+ dx_field_iterator_reset(iter, iter->view);
+ while (!dx_field_iterator_end(iter)) {
+ dx_field_iterator_octet(iter);
+ length++;
+ }
+
+ dx_field_iterator_reset(iter, iter->view);
+ copy = (unsigned char*) malloc(length + 1);
+ while (!dx_field_iterator_end(iter))
+ copy[idx++] = dx_field_iterator_octet(iter);
+ copy[idx] = '\0';
+
+ return copy;
+}
+
diff --git a/extras/dispatch/src/log.c b/extras/dispatch/src/log.c
new file mode 100644
index 0000000000..d4ec534915
--- /dev/null
+++ b/extras/dispatch/src/log.c
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/log.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+static int mask=LOG_INFO;
+
+static char *cls_prefix(int cls)
+{
+ switch (cls) {
+ case LOG_TRACE : return "TRACE";
+ case LOG_ERROR : return "ERROR";
+ case LOG_INFO : return "INFO";
+ }
+
+ return "";
+}
+
+void dx_log(const char *module, int cls, const char *fmt, ...)
+{
+ if (!(cls & mask))
+ return;
+
+ va_list ap;
+ char line[128];
+
+ va_start(ap, fmt);
+ vsnprintf(line, 127, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "%s (%s): %s\n", module, cls_prefix(cls), line);
+}
+
+void dx_log_set_mask(int _mask)
+{
+ mask = _mask;
+}
+
diff --git a/extras/dispatch/src/message.c b/extras/dispatch/src/message.c
new file mode 100644
index 0000000000..f66e79010c
--- /dev/null
+++ b/extras/dispatch/src/message.c
@@ -0,0 +1,1120 @@
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/threading.h>
+#include "message_private.h"
+#include <string.h>
+#include <stdio.h>
+
+ALLOC_DEFINE_CONFIG(dx_message_t, sizeof(dx_message_pvt_t), 0, 0);
+ALLOC_DEFINE(dx_message_content_t);
+
+
+static void advance(unsigned char **cursor, dx_buffer_t **buffer, int consume)
+{
+ unsigned char *local_cursor = *cursor;
+ dx_buffer_t *local_buffer = *buffer;
+
+ int remaining = dx_buffer_size(local_buffer) - (local_cursor - dx_buffer_base(local_buffer));
+ while (consume > 0) {
+ if (consume < remaining) {
+ local_cursor += consume;
+ consume = 0;
+ } else {
+ consume -= remaining;
+ local_buffer = local_buffer->next;
+ if (local_buffer == 0){
+ local_cursor = 0;
+ break;
+ }
+ local_cursor = dx_buffer_base(local_buffer);
+ remaining = dx_buffer_size(local_buffer) - (local_cursor - dx_buffer_base(local_buffer));
+ }
+ }
+
+ *cursor = local_cursor;
+ *buffer = local_buffer;
+}
+
+
+static unsigned char next_octet(unsigned char **cursor, dx_buffer_t **buffer)
+{
+ unsigned char result = **cursor;
+ advance(cursor, buffer, 1);
+ return result;
+}
+
+
+static int traverse_field(unsigned char **cursor, dx_buffer_t **buffer, dx_field_location_t *field)
+{
+ unsigned char tag = next_octet(cursor, buffer);
+ if (!(*cursor)) return 0;
+ int consume = 0;
+ switch (tag & 0xF0) {
+ case 0x40 : consume = 0; break;
+ case 0x50 : consume = 1; break;
+ case 0x60 : consume = 2; break;
+ case 0x70 : consume = 4; break;
+ case 0x80 : consume = 8; break;
+ case 0x90 : consume = 16; break;
+
+ case 0xB0 :
+ case 0xD0 :
+ case 0xF0 :
+ consume |= ((int) next_octet(cursor, buffer)) << 24;
+ if (!(*cursor)) return 0;
+ consume |= ((int) next_octet(cursor, buffer)) << 16;
+ if (!(*cursor)) return 0;
+ consume |= ((int) next_octet(cursor, buffer)) << 8;
+ if (!(*cursor)) return 0;
+ // Fall through to the next case...
+
+ case 0xA0 :
+ case 0xC0 :
+ case 0xE0 :
+ consume |= (int) next_octet(cursor, buffer);
+ if (!(*cursor)) return 0;
+ break;
+ }
+
+ if (field) {
+ field->buffer = *buffer;
+ field->offset = *cursor - dx_buffer_base(*buffer);
+ field->length = consume;
+ field->parsed = 1;
+ }
+
+ advance(cursor, buffer, consume);
+ return 1;
+}
+
+
+static int start_list(unsigned char **cursor, dx_buffer_t **buffer)
+{
+ unsigned char tag = next_octet(cursor, buffer);
+ if (!(*cursor)) return 0;
+ int length = 0;
+ int count = 0;
+
+ switch (tag) {
+ case 0x45 : // list0
+ break;
+ case 0xd0 : // list32
+ length |= ((int) next_octet(cursor, buffer)) << 24;
+ if (!(*cursor)) return 0;
+ length |= ((int) next_octet(cursor, buffer)) << 16;
+ if (!(*cursor)) return 0;
+ length |= ((int) next_octet(cursor, buffer)) << 8;
+ if (!(*cursor)) return 0;
+ length |= (int) next_octet(cursor, buffer);
+ if (!(*cursor)) return 0;
+
+ count |= ((int) next_octet(cursor, buffer)) << 24;
+ if (!(*cursor)) return 0;
+ count |= ((int) next_octet(cursor, buffer)) << 16;
+ if (!(*cursor)) return 0;
+ count |= ((int) next_octet(cursor, buffer)) << 8;
+ if (!(*cursor)) return 0;
+ count |= (int) next_octet(cursor, buffer);
+ if (!(*cursor)) return 0;
+
+ break;
+
+ case 0xc0 : // list8
+ length |= (int) next_octet(cursor, buffer);
+ if (!(*cursor)) return 0;
+
+ count |= (int) next_octet(cursor, buffer);
+ if (!(*cursor)) return 0;
+ break;
+ }
+
+ return count;
+}
+
+
+//
+// Check the buffer chain, starting at cursor to see if it matches the pattern.
+// If the pattern matches, check the next tag to see if it's in the set of expected
+// tags. If not, return zero. If so, set the location descriptor to the good
+// tag and advance the cursor (and buffer, if needed) to the end of the matched section.
+//
+// If there is no match, don't advance the cursor.
+//
+// Return 0 if the pattern matches but the following tag is unexpected
+// Return 0 if the pattern matches and the location already has a pointer (duplicate section)
+// Return 1 if the pattern matches and we've advanced the cursor/buffer
+// Return 1 if the pattern does not match
+//
+static int dx_check_and_advance(dx_buffer_t **buffer,
+ unsigned char **cursor,
+ unsigned char *pattern,
+ int pattern_length,
+ unsigned char *expected_tags,
+ dx_field_location_t *location)
+{
+ dx_buffer_t *test_buffer = *buffer;
+ unsigned char *test_cursor = *cursor;
+
+ if (!test_cursor)
+ return 1; // no match
+
+ unsigned char *end_of_buffer = dx_buffer_base(test_buffer) + dx_buffer_size(test_buffer);
+ int idx = 0;
+
+ while (idx < pattern_length && *test_cursor == pattern[idx]) {
+ idx++;
+ test_cursor++;
+ if (test_cursor == end_of_buffer) {
+ test_buffer = test_buffer->next;
+ if (test_buffer == 0)
+ return 1; // Pattern didn't match
+ test_cursor = dx_buffer_base(test_buffer);
+ end_of_buffer = test_cursor + dx_buffer_size(test_buffer);
+ }
+ }
+
+ if (idx < pattern_length)
+ return 1; // Pattern didn't match
+
+ //
+ // Pattern matched, check the tag
+ //
+ while (*expected_tags && *test_cursor != *expected_tags)
+ expected_tags++;
+ if (*expected_tags == 0)
+ return 0; // Unexpected tag
+
+ if (location->parsed)
+ return 0; // Duplicate section
+
+ //
+ // Pattern matched and tag is expected. Mark the beginning of the section.
+ //
+ location->parsed = 1;
+ location->buffer = test_buffer;
+ location->offset = test_cursor - dx_buffer_base(test_buffer);
+ location->length = 0;
+
+ //
+ // Advance the pointers to consume the whole section.
+ //
+ int consume = 0;
+ unsigned char tag = next_octet(&test_cursor, &test_buffer);
+ if (!test_cursor) return 0;
+ switch (tag) {
+ case 0x45 : // list0
+ break;
+
+ case 0xd0 : // list32
+ case 0xd1 : // map32
+ case 0xb0 : // vbin32
+ consume |= ((int) next_octet(&test_cursor, &test_buffer)) << 24;
+ if (!test_cursor) return 0;
+ consume |= ((int) next_octet(&test_cursor, &test_buffer)) << 16;
+ if (!test_cursor) return 0;
+ consume |= ((int) next_octet(&test_cursor, &test_buffer)) << 8;
+ if (!test_cursor) return 0;
+ // Fall through to the next case...
+
+ case 0xc0 : // list8
+ case 0xc1 : // map8
+ case 0xa0 : // vbin8
+ consume |= (int) next_octet(&test_cursor, &test_buffer);
+ if (!test_cursor) return 0;
+ break;
+ }
+
+ if (consume)
+ advance(&test_cursor, &test_buffer, consume);
+
+ *cursor = test_cursor;
+ *buffer = test_buffer;
+ return 1;
+}
+
+
+static void dx_insert(dx_message_content_t *msg, const uint8_t *seq, size_t len)
+{
+ dx_buffer_t *buf = DEQ_TAIL(msg->buffers);
+
+ while (len > 0) {
+ if (buf == 0 || dx_buffer_capacity(buf) == 0) {
+ buf = dx_allocate_buffer();
+ if (buf == 0)
+ return;
+ DEQ_INSERT_TAIL(msg->buffers, buf);
+ }
+
+ size_t to_copy = dx_buffer_capacity(buf);
+ if (to_copy > len)
+ to_copy = len;
+ memcpy(dx_buffer_cursor(buf), seq, to_copy);
+ dx_buffer_insert(buf, to_copy);
+ len -= to_copy;
+ seq += to_copy;
+ msg->length += to_copy;
+ }
+}
+
+
+static void dx_insert_8(dx_message_content_t *msg, uint8_t value)
+{
+ dx_insert(msg, &value, 1);
+}
+
+
+static void dx_insert_32(dx_message_content_t *msg, uint32_t value)
+{
+ uint8_t buf[4];
+ buf[0] = (uint8_t) ((value & 0xFF000000) >> 24);
+ buf[1] = (uint8_t) ((value & 0x00FF0000) >> 16);
+ buf[2] = (uint8_t) ((value & 0x0000FF00) >> 8);
+ buf[3] = (uint8_t) (value & 0x000000FF);
+ dx_insert(msg, buf, 4);
+}
+
+
+static void dx_insert_64(dx_message_content_t *msg, uint64_t value)
+{
+ uint8_t buf[8];
+ buf[0] = (uint8_t) ((value & 0xFF00000000000000L) >> 56);
+ buf[1] = (uint8_t) ((value & 0x00FF000000000000L) >> 48);
+ buf[2] = (uint8_t) ((value & 0x0000FF0000000000L) >> 40);
+ buf[3] = (uint8_t) ((value & 0x000000FF00000000L) >> 32);
+ buf[4] = (uint8_t) ((value & 0x00000000FF000000L) >> 24);
+ buf[5] = (uint8_t) ((value & 0x0000000000FF0000L) >> 16);
+ buf[6] = (uint8_t) ((value & 0x000000000000FF00L) >> 8);
+ buf[7] = (uint8_t) (value & 0x00000000000000FFL);
+ dx_insert(msg, buf, 8);
+}
+
+
+static void dx_overwrite(dx_buffer_t **buf, size_t *cursor, uint8_t value)
+{
+ while (*buf) {
+ if (*cursor >= dx_buffer_size(*buf)) {
+ *buf = (*buf)->next;
+ *cursor = 0;
+ } else {
+ dx_buffer_base(*buf)[*cursor] = value;
+ (*cursor)++;
+ return;
+ }
+ }
+}
+
+
+static void dx_overwrite_32(dx_field_location_t *field, uint32_t value)
+{
+ dx_buffer_t *buf = field->buffer;
+ size_t cursor = field->offset;
+
+ dx_overwrite(&buf, &cursor, (uint8_t) ((value & 0xFF000000) >> 24));
+ dx_overwrite(&buf, &cursor, (uint8_t) ((value & 0x00FF0000) >> 24));
+ dx_overwrite(&buf, &cursor, (uint8_t) ((value & 0x0000FF00) >> 24));
+ dx_overwrite(&buf, &cursor, (uint8_t) (value & 0x000000FF));
+}
+
+
+static void dx_start_list_performative(dx_message_content_t *msg, uint8_t code)
+{
+ //
+ // Insert the short-form performative tag
+ //
+ dx_insert(msg, (const uint8_t*) "\x00\x53", 2);
+ dx_insert_8(msg, code);
+
+ //
+ // Open the list with a list32 tag
+ //
+ dx_insert_8(msg, 0xd0);
+
+ //
+ // Mark the current location to later overwrite the length
+ //
+ msg->compose_length.buffer = DEQ_TAIL(msg->buffers);
+ msg->compose_length.offset = dx_buffer_size(msg->compose_length.buffer);
+ msg->compose_length.length = 4;
+ msg->compose_length.parsed = 1;
+
+ dx_insert(msg, (const uint8_t*) "\x00\x00\x00\x00", 4);
+
+ //
+ // Mark the current location to later overwrite the count
+ //
+ msg->compose_count.buffer = DEQ_TAIL(msg->buffers);
+ msg->compose_count.offset = dx_buffer_size(msg->compose_count.buffer);
+ msg->compose_count.length = 4;
+ msg->compose_count.parsed = 1;
+
+ dx_insert(msg, (const uint8_t*) "\x00\x00\x00\x00", 4);
+
+ msg->length = 4; // Include the length of the count field
+ msg->count = 0;
+}
+
+
+static void dx_end_list(dx_message_content_t *msg)
+{
+ dx_overwrite_32(&msg->compose_length, msg->length);
+ dx_overwrite_32(&msg->compose_count, msg->count);
+}
+
+
+static dx_field_location_t *dx_message_field_location(dx_message_t *msg, dx_message_field_t field)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+
+ switch (field) {
+ case DX_FIELD_TO:
+ while (1) {
+ if (content->field_to.parsed)
+ return &content->field_to;
+
+ if (content->section_message_properties.parsed == 0)
+ break;
+
+ dx_buffer_t *buffer = content->section_message_properties.buffer;
+ unsigned char *cursor = dx_buffer_base(buffer) + content->section_message_properties.offset;
+
+ int count = start_list(&cursor, &buffer);
+ int result;
+
+ if (count < 3)
+ break;
+
+ result = traverse_field(&cursor, &buffer, 0); // message_id
+ if (!result) return 0;
+ result = traverse_field(&cursor, &buffer, 0); // user_id
+ if (!result) return 0;
+ result = traverse_field(&cursor, &buffer, &content->field_to); // to
+ if (!result) return 0;
+ }
+ break;
+
+ case DX_FIELD_BODY:
+ while (1) {
+ if (content->body.parsed)
+ return &content->body;
+
+ if (content->section_body.parsed == 0)
+ break;
+
+ dx_buffer_t *buffer = content->section_body.buffer;
+ unsigned char *cursor = dx_buffer_base(buffer) + content->section_body.offset;
+ int result;
+
+ result = traverse_field(&cursor, &buffer, &content->body);
+ if (!result) return 0;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+
+dx_message_t *dx_allocate_message()
+{
+ dx_message_pvt_t *msg = (dx_message_pvt_t*) new_dx_message_t();
+ if (!msg)
+ return 0;
+
+ DEQ_ITEM_INIT(msg);
+ msg->content = new_dx_message_content_t();
+ msg->out_delivery = 0;
+
+ if (msg->content == 0) {
+ free_dx_message_t((dx_message_t*) msg);
+ return 0;
+ }
+
+ memset(msg->content, 0, sizeof(dx_message_content_t));
+ msg->content->lock = sys_mutex();
+ msg->content->ref_count = 1;
+
+ return (dx_message_t*) msg;
+}
+
+
+void dx_free_message(dx_message_t *in_msg)
+{
+ uint32_t rc;
+ dx_message_pvt_t *msg = (dx_message_pvt_t*) in_msg;
+ dx_message_content_t *content = msg->content;
+
+ sys_mutex_lock(content->lock);
+ rc = --content->ref_count;
+ sys_mutex_unlock(content->lock);
+
+ if (rc == 0) {
+ dx_buffer_t *buf = DEQ_HEAD(content->buffers);
+
+ while (buf) {
+ DEQ_REMOVE_HEAD(content->buffers);
+ dx_free_buffer(buf);
+ buf = DEQ_HEAD(content->buffers);
+ }
+
+ sys_mutex_free(content->lock);
+ free_dx_message_content_t(content);
+ }
+
+ free_dx_message_t((dx_message_t*) msg);
+}
+
+
+dx_message_t *dx_message_copy(dx_message_t *in_msg)
+{
+ dx_message_pvt_t *msg = (dx_message_pvt_t*) in_msg;
+ dx_message_content_t *content = msg->content;
+ dx_message_pvt_t *copy = (dx_message_pvt_t*) new_dx_message_t();
+
+ if (!copy)
+ return 0;
+
+ DEQ_ITEM_INIT(copy);
+ copy->content = content;
+ copy->out_delivery = 0;
+
+ sys_mutex_lock(content->lock);
+ content->ref_count++;
+ sys_mutex_unlock(content->lock);
+
+ return (dx_message_t*) copy;
+}
+
+
+void dx_message_set_out_delivery(dx_message_t *msg, pn_delivery_t *delivery)
+{
+ ((dx_message_pvt_t*) msg)->out_delivery = delivery;
+}
+
+
+pn_delivery_t *dx_message_out_delivery(dx_message_t *msg)
+{
+ return ((dx_message_pvt_t*) msg)->out_delivery;
+}
+
+
+void dx_message_set_in_delivery(dx_message_t *msg, pn_delivery_t *delivery)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ content->in_delivery = delivery;
+}
+
+
+pn_delivery_t *dx_message_in_delivery(dx_message_t *msg)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ return content->in_delivery;
+}
+
+
+dx_message_t *dx_message_receive(pn_delivery_t *delivery)
+{
+ pn_link_t *link = pn_delivery_link(delivery);
+ dx_message_pvt_t *msg = (dx_message_pvt_t*) pn_delivery_get_context(delivery);
+ ssize_t rc;
+ dx_buffer_t *buf;
+
+ //
+ // If there is no message associated with the delivery, this is the first time
+ // we've received anything on this delivery. Allocate a message descriptor and
+ // link it and the delivery together.
+ //
+ if (!msg) {
+ msg = (dx_message_pvt_t*) dx_allocate_message();
+ pn_delivery_set_context(delivery, (void*) msg);
+
+ //
+ // Record the incoming delivery only if it is not settled. If it is
+ // settled, it should not be recorded as no future operations on it are
+ // permitted.
+ //
+ if (!pn_delivery_settled(delivery))
+ msg->content->in_delivery = delivery;
+ }
+
+ //
+ // Get a reference to the tail buffer on the message. This is the buffer into which
+ // we will store incoming message data. If there is no buffer in the message, allocate
+ // an empty one and add it to the message.
+ //
+ buf = DEQ_TAIL(msg->content->buffers);
+ if (!buf) {
+ buf = dx_allocate_buffer();
+ DEQ_INSERT_TAIL(msg->content->buffers, buf);
+ }
+
+ while (1) {
+ //
+ // Try to receive enough data to fill the remaining space in the tail buffer.
+ //
+ rc = pn_link_recv(link, (char*) dx_buffer_cursor(buf), dx_buffer_capacity(buf));
+
+ //
+ // If we receive PN_EOS, we have come to the end of the message.
+ //
+ if (rc == PN_EOS) {
+ //
+ // If the last buffer in the list is empty, remove it and free it. This
+ // will only happen if the size of the message content is an exact multiple
+ // of the buffer size.
+ //
+ if (dx_buffer_size(buf) == 0) {
+ DEQ_REMOVE_TAIL(msg->content->buffers);
+ dx_free_buffer(buf);
+ }
+ return (dx_message_t*) msg;
+ }
+
+ if (rc > 0) {
+ //
+ // We have received a positive number of bytes for the message. Advance
+ // the cursor in the buffer.
+ //
+ dx_buffer_insert(buf, rc);
+
+ //
+ // If the buffer is full, allocate a new empty buffer and append it to the
+ // tail of the message's list.
+ //
+ if (dx_buffer_capacity(buf) == 0) {
+ buf = dx_allocate_buffer();
+ DEQ_INSERT_TAIL(msg->content->buffers, buf);
+ }
+ } else
+ //
+ // We received zero bytes, and no PN_EOS. This means that we've received
+ // all of the data available up to this point, but it does not constitute
+ // the entire message. We'll be back later to finish it up.
+ //
+ break;
+ }
+
+ return 0;
+}
+
+
+void dx_message_send(dx_message_t *in_msg, pn_link_t *link)
+{
+ dx_message_pvt_t *msg = (dx_message_pvt_t*) in_msg;
+ dx_buffer_t *buf = DEQ_HEAD(msg->content->buffers);
+
+ // TODO - Handle cases where annotations have been added or modified
+ while (buf) {
+ pn_link_send(link, (char*) dx_buffer_base(buf), dx_buffer_size(buf));
+ buf = DEQ_NEXT(buf);
+ }
+}
+
+
+int dx_message_check(dx_message_t *in_msg, dx_message_depth_t depth)
+{
+
+#define LONG 10
+#define SHORT 3
+#define MSG_HDR_LONG (unsigned char*) "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x70"
+#define MSG_HDR_SHORT (unsigned char*) "\x00\x53\x70"
+#define DELIVERY_ANNOTATION_LONG (unsigned char*) "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x71"
+#define DELIVERY_ANNOTATION_SHORT (unsigned char*) "\x00\x53\x71"
+#define MESSAGE_ANNOTATION_LONG (unsigned char*) "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x72"
+#define MESSAGE_ANNOTATION_SHORT (unsigned char*) "\x00\x53\x72"
+#define PROPERTIES_LONG (unsigned char*) "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x73"
+#define PROPERTIES_SHORT (unsigned char*) "\x00\x53\x73"
+#define APPLICATION_PROPERTIES_LONG (unsigned char*) "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x74"
+#define APPLICATION_PROPERTIES_SHORT (unsigned char*) "\x00\x53\x74"
+#define BODY_DATA_LONG (unsigned char*) "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x75"
+#define BODY_DATA_SHORT (unsigned char*) "\x00\x53\x75"
+#define BODY_SEQUENCE_LONG (unsigned char*) "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x76"
+#define BODY_SEQUENCE_SHORT (unsigned char*) "\x00\x53\x76"
+#define FOOTER_LONG (unsigned char*) "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x78"
+#define FOOTER_SHORT (unsigned char*) "\x00\x53\x78"
+#define TAGS_LIST (unsigned char*) "\x45\xc0\xd0"
+#define TAGS_MAP (unsigned char*) "\xc1\xd1"
+#define TAGS_BINARY (unsigned char*) "\xa0\xb0"
+
+ dx_message_pvt_t *msg = (dx_message_pvt_t*) in_msg;
+ dx_message_content_t *content = msg->content;
+ dx_buffer_t *buffer = DEQ_HEAD(content->buffers);
+ unsigned char *cursor;
+
+ if (!buffer)
+ return 0; // Invalid - No data in the message
+
+ if (depth == DX_DEPTH_NONE)
+ return 1;
+
+ cursor = dx_buffer_base(buffer);
+
+ //
+ // MESSAGE HEADER
+ //
+ if (0 == dx_check_and_advance(&buffer, &cursor, MSG_HDR_LONG, LONG, TAGS_LIST, &content->section_message_header))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, MSG_HDR_SHORT, SHORT, TAGS_LIST, &content->section_message_header))
+ return 0;
+
+ if (depth == DX_DEPTH_HEADER)
+ return 1;
+
+ //
+ // DELIVERY ANNOTATION
+ //
+ if (0 == dx_check_and_advance(&buffer, &cursor, DELIVERY_ANNOTATION_LONG, LONG, TAGS_MAP, &content->section_delivery_annotation))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, DELIVERY_ANNOTATION_SHORT, SHORT, TAGS_MAP, &content->section_delivery_annotation))
+ return 0;
+
+ if (depth == DX_DEPTH_DELIVERY_ANNOTATIONS)
+ return 1;
+
+ //
+ // MESSAGE ANNOTATION
+ //
+ if (0 == dx_check_and_advance(&buffer, &cursor, MESSAGE_ANNOTATION_LONG, LONG, TAGS_MAP, &content->section_message_annotation))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, MESSAGE_ANNOTATION_SHORT, SHORT, TAGS_MAP, &content->section_message_annotation))
+ return 0;
+
+ if (depth == DX_DEPTH_MESSAGE_ANNOTATIONS)
+ return 1;
+
+ //
+ // PROPERTIES
+ //
+ if (0 == dx_check_and_advance(&buffer, &cursor, PROPERTIES_LONG, LONG, TAGS_LIST, &content->section_message_properties))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, PROPERTIES_SHORT, SHORT, TAGS_LIST, &content->section_message_properties))
+ return 0;
+
+ if (depth == DX_DEPTH_PROPERTIES)
+ return 1;
+
+ //
+ // APPLICATION PROPERTIES
+ //
+ if (0 == dx_check_and_advance(&buffer, &cursor, APPLICATION_PROPERTIES_LONG, LONG, TAGS_MAP, &content->section_application_properties))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, APPLICATION_PROPERTIES_SHORT, SHORT, TAGS_MAP, &content->section_application_properties))
+ return 0;
+
+ if (depth == DX_DEPTH_APPLICATION_PROPERTIES)
+ return 1;
+
+ //
+ // BODY (Note that this function expects a single data section or a single AMQP sequence)
+ //
+ if (0 == dx_check_and_advance(&buffer, &cursor, BODY_DATA_LONG, LONG, TAGS_BINARY, &content->section_body))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, BODY_DATA_SHORT, SHORT, TAGS_BINARY, &content->section_body))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, BODY_SEQUENCE_LONG, LONG, TAGS_LIST, &content->section_body))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, BODY_SEQUENCE_SHORT, SHORT, TAGS_LIST, &content->section_body))
+ return 0;
+
+ if (depth == DX_DEPTH_BODY)
+ return 1;
+
+ //
+ // FOOTER
+ //
+ if (0 == dx_check_and_advance(&buffer, &cursor, FOOTER_LONG, LONG, TAGS_MAP, &content->section_footer))
+ return 0;
+ if (0 == dx_check_and_advance(&buffer, &cursor, FOOTER_SHORT, SHORT, TAGS_MAP, &content->section_footer))
+ return 0;
+
+ return 1;
+}
+
+
+dx_field_iterator_t *dx_message_field_iterator(dx_message_t *msg, dx_message_field_t field)
+{
+ dx_field_location_t *loc = dx_message_field_location(msg, field);
+ if (!loc)
+ return 0;
+
+ return dx_field_iterator_buffer(loc->buffer, loc->offset, loc->length, ITER_VIEW_ALL);
+}
+
+
+dx_iovec_t *dx_message_field_iovec(dx_message_t *msg, dx_message_field_t field)
+{
+ dx_field_location_t *loc = dx_message_field_location(msg, field);
+ if (!loc)
+ return 0;
+
+ //
+ // Count the number of buffers this field straddles
+ //
+ int bufcnt = 1;
+ dx_buffer_t *buf = loc->buffer;
+ size_t bufsize = dx_buffer_size(buf) - loc->offset;
+ ssize_t remaining = loc->length - bufsize;
+
+ while (remaining > 0) {
+ bufcnt++;
+ buf = buf->next;
+ if (!buf)
+ return 0;
+ remaining -= dx_buffer_size(buf);
+ }
+
+ //
+ // Allocate an iovec object big enough to hold the number of buffers
+ //
+ dx_iovec_t *iov = dx_iovec(bufcnt);
+ if (!iov)
+ return 0;
+
+ //
+ // Build out the io vectors with pointers to the segments of the field in buffers
+ //
+ bufcnt = 0;
+ buf = loc->buffer;
+ bufsize = dx_buffer_size(buf) - loc->offset;
+ void *base = dx_buffer_base(buf) + loc->offset;
+ remaining = loc->length;
+
+ while (remaining > 0) {
+ dx_iovec_array(iov)[bufcnt].iov_base = base;
+ dx_iovec_array(iov)[bufcnt].iov_len = bufsize;
+ bufcnt++;
+ remaining -= bufsize;
+ if (remaining > 0) {
+ buf = buf->next;
+ base = dx_buffer_base(buf);
+ bufsize = dx_buffer_size(buf);
+ if (bufsize > remaining)
+ bufsize = remaining;
+ }
+ }
+
+ return iov;
+}
+
+
+void dx_message_compose_1(dx_message_t *msg, const char *to, dx_buffer_list_t *buffers)
+{
+ dx_message_begin_header(msg);
+ dx_message_insert_boolean(msg, 0); // durable
+ //dx_message_insert_null(msg); // priority
+ //dx_message_insert_null(msg); // ttl
+ //dx_message_insert_boolean(msg, 0); // first-acquirer
+ //dx_message_insert_uint(msg, 0); // delivery-count
+ dx_message_end_header(msg);
+
+ dx_message_begin_message_properties(msg);
+ dx_message_insert_null(msg); // message-id
+ dx_message_insert_null(msg); // user-id
+ dx_message_insert_string(msg, to); // to
+ //dx_message_insert_null(msg); // subject
+ //dx_message_insert_null(msg); // reply-to
+ //dx_message_insert_null(msg); // correlation-id
+ //dx_message_insert_null(msg); // content-type
+ //dx_message_insert_null(msg); // content-encoding
+ //dx_message_insert_timestamp(msg, 0); // absolute-expiry-time
+ //dx_message_insert_timestamp(msg, 0); // creation-time
+ //dx_message_insert_null(msg); // group-id
+ //dx_message_insert_uint(msg, 0); // group-sequence
+ //dx_message_insert_null(msg); // reply-to-group-id
+ dx_message_end_message_properties(msg);
+
+ if (buffers)
+ dx_message_append_body_data(msg, buffers);
+}
+
+
+void dx_message_begin_header(dx_message_t *msg)
+{
+ dx_start_list_performative(MSG_CONTENT(msg), 0x70);
+}
+
+
+void dx_message_end_header(dx_message_t *msg)
+{
+ dx_end_list(MSG_CONTENT(msg));
+}
+
+
+void dx_message_begin_delivery_annotations(dx_message_t *msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_end_delivery_annotations(dx_message_t *msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_begin_message_annotations(dx_message_t *msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_end_message_annotations(dx_message_t *msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_begin_message_properties(dx_message_t *msg)
+{
+ dx_start_list_performative(MSG_CONTENT(msg), 0x73);
+}
+
+
+void dx_message_end_message_properties(dx_message_t *msg)
+{
+ dx_end_list(MSG_CONTENT(msg));
+}
+
+
+void dx_message_begin_application_properties(dx_message_t *msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_end_application_properties(dx_message_t *msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_append_body_data(dx_message_t *msg, dx_buffer_list_t *buffers)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ dx_buffer_t *buf = DEQ_HEAD(*buffers);
+ uint32_t len = 0;
+
+ //
+ // Calculate the size of the body to be appended.
+ //
+ while (buf) {
+ len += dx_buffer_size(buf);
+ buf = DEQ_NEXT(buf);
+ }
+
+ //
+ // Insert a DATA section performative header.
+ //
+ dx_insert(content, (const uint8_t*) "\x00\x53\x75", 3);
+ if (len < 256) {
+ dx_insert_8(content, 0xa0); // vbin8
+ dx_insert_8(content, (uint8_t) len);
+ } else {
+ dx_insert_8(content, 0xb0); // vbin32
+ dx_insert_32(content, len);
+ }
+
+ //
+ // Move the supplied buffers to the tail of the message's buffer list.
+ //
+ buf = DEQ_HEAD(*buffers);
+ while (buf) {
+ DEQ_REMOVE_HEAD(*buffers);
+ DEQ_INSERT_TAIL(content->buffers, buf);
+ buf = DEQ_HEAD(*buffers);
+ }
+}
+
+
+void dx_message_begin_body_sequence(dx_message_t *msg)
+{
+}
+
+
+void dx_message_end_body_sequence(dx_message_t *msg)
+{
+}
+
+
+void dx_message_begin_footer(dx_message_t *msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_end_footer(dx_message_t *msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_insert_null(dx_message_t *msg)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ dx_insert_8(content, 0x40);
+ content->count++;
+}
+
+
+void dx_message_insert_boolean(dx_message_t *msg, int value)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ if (value)
+ dx_insert(content, (const uint8_t*) "\x56\x01", 2);
+ else
+ dx_insert(content, (const uint8_t*) "\x56\x00", 2);
+ content->count++;
+}
+
+
+void dx_message_insert_ubyte(dx_message_t *msg, uint8_t value)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ dx_insert_8(content, 0x50);
+ dx_insert_8(content, value);
+ content->count++;
+}
+
+
+void dx_message_insert_uint(dx_message_t *msg, uint32_t value)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ if (value == 0) {
+ dx_insert_8(content, 0x43); // uint0
+ } else if (value < 256) {
+ dx_insert_8(content, 0x52); // smalluint
+ dx_insert_8(content, (uint8_t) value);
+ } else {
+ dx_insert_8(content, 0x70); // uint
+ dx_insert_32(content, value);
+ }
+ content->count++;
+}
+
+
+void dx_message_insert_ulong(dx_message_t *msg, uint64_t value)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ if (value == 0) {
+ dx_insert_8(content, 0x44); // ulong0
+ } else if (value < 256) {
+ dx_insert_8(content, 0x53); // smallulong
+ dx_insert_8(content, (uint8_t) value);
+ } else {
+ dx_insert_8(content, 0x80); // ulong
+ dx_insert_64(content, value);
+ }
+ content->count++;
+}
+
+
+void dx_message_insert_binary(dx_message_t *msg, const uint8_t *start, size_t len)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ if (len < 256) {
+ dx_insert_8(content, 0xa0); // vbin8
+ dx_insert_8(content, (uint8_t) len);
+ } else {
+ dx_insert_8(content, 0xb0); // vbin32
+ dx_insert_32(content, len);
+ }
+ dx_insert(content, start, len);
+ content->count++;
+}
+
+
+void dx_message_insert_string(dx_message_t *msg, const char *start)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ uint32_t len = strlen(start);
+
+ if (len < 256) {
+ dx_insert_8(content, 0xa1); // str8-utf8
+ dx_insert_8(content, (uint8_t) len);
+ dx_insert(content, (const uint8_t*) start, len);
+ } else {
+ dx_insert_8(content, 0xb1); // str32-utf8
+ dx_insert_32(content, len);
+ dx_insert(content, (const uint8_t*) start, len);
+ }
+ content->count++;
+}
+
+
+void dx_message_insert_uuid(dx_message_t *msg, const uint8_t *value)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ dx_insert_8(content, 0x98); // uuid
+ dx_insert(content, value, 16);
+ content->count++;
+}
+
+
+void dx_message_insert_symbol(dx_message_t *msg, const char *start, size_t len)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ if (len < 256) {
+ dx_insert_8(content, 0xa3); // sym8
+ dx_insert_8(content, (uint8_t) len);
+ dx_insert(content, (const uint8_t*) start, len);
+ } else {
+ dx_insert_8(content, 0xb3); // sym32
+ dx_insert_32(content, len);
+ dx_insert(content, (const uint8_t*) start, len);
+ }
+ content->count++;
+}
+
+
+void dx_message_insert_timestamp(dx_message_t *msg, uint64_t value)
+{
+ dx_message_content_t *content = MSG_CONTENT(msg);
+ dx_insert_8(content, 0x83); // timestamp
+ dx_insert_64(content, value);
+ content->count++;
+}
+
+
+void dx_message_begin_list(dx_message_t* msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_end_list(dx_message_t* msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_begin_map(dx_message_t* msg)
+{
+ assert(0); // Not Implemented
+}
+
+
+void dx_message_end_map(dx_message_t* msg)
+{
+ assert(0); // Not Implemented
+}
+
diff --git a/extras/dispatch/src/message_private.h b/extras/dispatch/src/message_private.h
new file mode 100644
index 0000000000..5fb18078f5
--- /dev/null
+++ b/extras/dispatch/src/message_private.h
@@ -0,0 +1,94 @@
+#ifndef __message_private_h__
+#define __message_private_h__ 1
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/message.h>
+#include <qpid/dispatch/alloc.h>
+#include <qpid/dispatch/threading.h>
+
+/**
+ * Architecture of the message module:
+ *
+ * +--------------+ +----------------------+
+ * | | | |
+ * | dx_message_t |----------->| dx_message_content_t |
+ * | | +----->| |
+ * +--------------+ | +----------------------+
+ * | |
+ * +--------------+ | | +-------------+ +-------------+ +-------------+
+ * | | | +--->| dx_buffer_t |-->| dx_buffer_t |-->| dx_buffer_t |--/
+ * | dx_message_t |-----+ +-------------+ +-------------+ +-------------+
+ * | |
+ * +--------------+
+ *
+ * The message module provides chained-fixed-sized-buffer storage of message content with multiple
+ * references. If a message is received and is to be queued for multiple destinations, there is only
+ * one copy of the message content in memory but multiple lightweight references to the content.
+ *
+ */
+
+typedef struct {
+ dx_buffer_t *buffer; // Buffer that contains the first octet of the field, null if the field is not present
+ size_t offset; // Offset in the buffer to the first octet
+ size_t length; // Length of the field or zero if unneeded
+ int parsed; // non-zero iff the buffer chain has been parsed to find this field
+} dx_field_location_t;
+
+
+// TODO - consider using pointers to dx_field_location_t below to save memory
+// TODO - we need a second buffer list for modified annotations and header
+// There are three message scenarios:
+// 1) Received message is held and forwarded unmodified - single buffer list
+// 2) Received message is held and modified before forwarding - two buffer lists
+// 3) Message is composed internally - single buffer list
+
+typedef struct {
+ sys_mutex_t *lock;
+ uint32_t ref_count; // The number of qmessages referencing this
+ dx_buffer_list_t buffers; // The buffer chain containing the message
+ pn_delivery_t *in_delivery; // The delivery on which the message arrived
+ dx_field_location_t section_message_header; // The message header list
+ dx_field_location_t section_delivery_annotation; // The delivery annotation map
+ dx_field_location_t section_message_annotation; // The message annotation map
+ dx_field_location_t section_message_properties; // The message properties list
+ dx_field_location_t section_application_properties; // The application properties list
+ dx_field_location_t section_body; // The message body: Data
+ dx_field_location_t section_footer; // The footer
+ dx_field_location_t field_user_id; // The string value of the user-id
+ dx_field_location_t field_to; // The string value of the to field
+ dx_field_location_t body; // The body of the message
+ dx_field_location_t compose_length;
+ dx_field_location_t compose_count;
+ uint32_t length;
+ uint32_t count;
+} dx_message_content_t;
+
+typedef struct {
+ DEQ_LINKS(dx_message_t); // Deq linkage that overlays the dx_message_t
+ dx_message_content_t *content;
+ pn_delivery_t *out_delivery;
+} dx_message_pvt_t;
+
+ALLOC_DECLARE(dx_message_t);
+ALLOC_DECLARE(dx_message_content_t);
+
+#define MSG_CONTENT(m) (((dx_message_pvt_t*) m)->content)
+
+#endif
diff --git a/extras/dispatch/src/posix/threading.c b/extras/dispatch/src/posix/threading.c
new file mode 100644
index 0000000000..8edce86cdc
--- /dev/null
+++ b/extras/dispatch/src/posix/threading.c
@@ -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.
+ */
+
+#include <qpid/dispatch/threading.h>
+#include <qpid/dispatch/ctools.h>
+#include <stdio.h>
+#include <pthread.h>
+
+struct sys_mutex_t {
+ pthread_mutex_t mutex;
+ int acquired;
+};
+
+sys_mutex_t *sys_mutex(void)
+{
+ sys_mutex_t *mutex = NEW(sys_mutex_t);
+ pthread_mutex_init(&(mutex->mutex), 0);
+ mutex->acquired = 0;
+ return mutex;
+}
+
+
+void sys_mutex_free(sys_mutex_t *mutex)
+{
+ assert(!mutex->acquired);
+ pthread_mutex_destroy(&(mutex->mutex));
+ free(mutex);
+}
+
+
+void sys_mutex_lock(sys_mutex_t *mutex)
+{
+ pthread_mutex_lock(&(mutex->mutex));
+ assert(!mutex->acquired);
+ mutex->acquired++;
+}
+
+
+void sys_mutex_unlock(sys_mutex_t *mutex)
+{
+ mutex->acquired--;
+ assert(!mutex->acquired);
+ pthread_mutex_unlock(&(mutex->mutex));
+}
+
+
+struct sys_cond_t {
+ pthread_cond_t cond;
+};
+
+
+sys_cond_t *sys_cond(void)
+{
+ sys_cond_t *cond = NEW(sys_cond_t);
+ pthread_cond_init(&(cond->cond), 0);
+ return cond;
+}
+
+
+void sys_cond_free(sys_cond_t *cond)
+{
+ pthread_cond_destroy(&(cond->cond));
+ free(cond);
+}
+
+
+void sys_cond_wait(sys_cond_t *cond, sys_mutex_t *held_mutex)
+{
+ assert(held_mutex->acquired);
+ held_mutex->acquired--;
+ pthread_cond_wait(&(cond->cond), &(held_mutex->mutex));
+ held_mutex->acquired++;
+}
+
+
+void sys_cond_signal(sys_cond_t *cond)
+{
+ pthread_cond_signal(&(cond->cond));
+}
+
+
+void sys_cond_signal_all(sys_cond_t *cond)
+{
+ pthread_cond_broadcast(&(cond->cond));
+}
+
+
+struct sys_thread_t {
+ pthread_t thread;
+};
+
+sys_thread_t *sys_thread(void *(*run_function) (void *), void *arg)
+{
+ sys_thread_t *thread = NEW(sys_thread_t);
+ pthread_create(&(thread->thread), 0, run_function, arg);
+ return thread;
+}
+
+
+void sys_thread_free(sys_thread_t *thread)
+{
+ free(thread);
+}
+
+
+void sys_thread_join(sys_thread_t *thread)
+{
+ pthread_join(thread->thread, 0);
+}
+
diff --git a/extras/dispatch/src/router_node.c b/extras/dispatch/src/router_node.c
new file mode 100644
index 0000000000..6ddc8f45dd
--- /dev/null
+++ b/extras/dispatch/src/router_node.c
@@ -0,0 +1,424 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <qpid/dispatch/server.h>
+#include <qpid/dispatch/message.h>
+#include <qpid/dispatch/threading.h>
+#include <qpid/dispatch/timer.h>
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/hash.h>
+#include <qpid/dispatch/iterator.h>
+#include <qpid/dispatch/log.h>
+#include <qpid/dispatch/router.h>
+
+static char *module="ROUTER_NODE";
+
+struct dx_router_t {
+ dx_node_t *node;
+ dx_link_list_t in_links;
+ dx_link_list_t out_links;
+ dx_message_list_t in_fifo;
+ sys_mutex_t *lock;
+ dx_timer_t *timer;
+ hash_t *out_hash;
+ uint64_t dtag;
+};
+
+
+typedef struct {
+ dx_link_t *link;
+ dx_message_list_t out_fifo;
+} dx_router_link_t;
+
+
+ALLOC_DECLARE(dx_router_link_t);
+ALLOC_DEFINE(dx_router_link_t);
+
+
+/**
+ * Outbound Delivery Handler
+ */
+static void router_tx_handler(void* context, dx_link_t *link, pn_delivery_t *delivery)
+{
+ dx_router_t *router = (dx_router_t*) context;
+ pn_link_t *pn_link = pn_delivery_link(delivery);
+ dx_router_link_t *rlink = (dx_router_link_t*) dx_link_get_context(link);
+ dx_message_t *msg;
+ size_t size;
+
+ sys_mutex_lock(router->lock);
+ msg = DEQ_HEAD(rlink->out_fifo);
+ if (!msg) {
+ // TODO - Recind the delivery
+ sys_mutex_unlock(router->lock);
+ return;
+ }
+
+ DEQ_REMOVE_HEAD(rlink->out_fifo);
+ size = (DEQ_SIZE(rlink->out_fifo));
+ sys_mutex_unlock(router->lock);
+
+ dx_message_send(msg, pn_link);
+
+ //
+ // If there is no incoming delivery, it was pre-settled. In this case,
+ // we must pre-settle the outgoing delivery as well.
+ //
+ if (dx_message_in_delivery(msg)) {
+ pn_delivery_set_context(delivery, (void*) msg);
+ dx_message_set_out_delivery(msg, delivery);
+ } else {
+ pn_delivery_settle(delivery);
+ dx_free_message(msg);
+ }
+
+ pn_link_advance(pn_link);
+ pn_link_offered(pn_link, size);
+}
+
+
+/**
+ * Inbound Delivery Handler
+ */
+static void router_rx_handler(void* context, dx_link_t *link, pn_delivery_t *delivery)
+{
+ dx_router_t *router = (dx_router_t*) context;
+ pn_link_t *pn_link = pn_delivery_link(delivery);
+ dx_message_t *msg;
+ int valid_message = 0;
+
+ //
+ // Receive the message into a local representation. If the returned message
+ // pointer is NULL, we have not yet received a complete message.
+ //
+ sys_mutex_lock(router->lock);
+ msg = dx_message_receive(delivery);
+ sys_mutex_unlock(router->lock);
+
+ if (!msg)
+ return;
+
+ //
+ // Validate the message through the Properties section
+ //
+ valid_message = dx_message_check(msg, DX_DEPTH_PROPERTIES);
+
+ pn_link_advance(pn_link);
+ pn_link_flow(pn_link, 1);
+
+ if (valid_message) {
+ dx_field_iterator_t *iter = dx_message_field_iterator(msg, DX_FIELD_TO);
+ dx_router_link_t *rlink;
+ if (iter) {
+ dx_field_iterator_reset(iter, ITER_VIEW_NO_HOST);
+ sys_mutex_lock(router->lock);
+ int result = hash_retrieve(router->out_hash, iter, (void*) &rlink);
+ dx_field_iterator_free(iter);
+
+ if (result == 0) {
+ //
+ // To field is valid and contains a known destination. Enqueue on
+ // the output fifo for the next-hop-to-destination.
+ //
+ pn_link_t* pn_outlink = dx_link_pn(rlink->link);
+ DEQ_INSERT_TAIL(rlink->out_fifo, msg);
+ pn_link_offered(pn_outlink, DEQ_SIZE(rlink->out_fifo));
+ dx_link_activate(rlink->link);
+ } else {
+ //
+ // To field contains an unknown address. Release the message.
+ //
+ pn_delivery_update(delivery, PN_RELEASED);
+ pn_delivery_settle(delivery);
+ }
+
+ sys_mutex_unlock(router->lock);
+ }
+ } else {
+ //
+ // Message is invalid. Reject the message.
+ //
+ pn_delivery_update(delivery, PN_REJECTED);
+ pn_delivery_settle(delivery);
+ pn_delivery_set_context(delivery, 0);
+ dx_free_message(msg);
+ }
+}
+
+
+/**
+ * Delivery Disposition Handler
+ */
+static void router_disp_handler(void* context, dx_link_t *link, pn_delivery_t *delivery)
+{
+ pn_link_t *pn_link = pn_delivery_link(delivery);
+
+ if (pn_link_is_sender(pn_link)) {
+ pn_disposition_t disp = pn_delivery_remote_state(delivery);
+ dx_message_t *msg = pn_delivery_get_context(delivery);
+ pn_delivery_t *activate = 0;
+
+ if (msg) {
+ assert(delivery == dx_message_out_delivery(msg));
+ if (disp != 0) {
+ activate = dx_message_in_delivery(msg);
+ pn_delivery_update(activate, disp);
+ // TODO - handling of the data accompanying RECEIVED/MODIFIED
+ }
+
+ if (pn_delivery_settled(delivery)) {
+ //
+ // Downstream delivery has been settled. Propagate the settlement
+ // upstream.
+ //
+ activate = dx_message_in_delivery(msg);
+ pn_delivery_settle(activate);
+ pn_delivery_settle(delivery);
+ dx_free_message(msg);
+ }
+
+ if (activate) {
+ //
+ // Activate the upstream/incoming link so that the settlement will
+ // get pushed out.
+ //
+ dx_link_t *act_link = (dx_link_t*) pn_link_get_context(pn_delivery_link(activate));
+ dx_link_activate(act_link);
+ }
+
+ return;
+ }
+ }
+
+ pn_delivery_settle(delivery);
+}
+
+
+/**
+ * New Incoming Link Handler
+ */
+static int router_incoming_link_handler(void* context, dx_link_t *link)
+{
+ dx_router_t *router = (dx_router_t*) context;
+ dx_link_item_t *item = new_dx_link_item_t();
+ pn_link_t *pn_link = dx_link_pn(link);
+
+ if (item) {
+ DEQ_ITEM_INIT(item);
+ item->link = link;
+
+ sys_mutex_lock(router->lock);
+ DEQ_INSERT_TAIL(router->in_links, item);
+ sys_mutex_unlock(router->lock);
+
+ pn_terminus_copy(pn_link_source(pn_link), pn_link_remote_source(pn_link));
+ pn_terminus_copy(pn_link_target(pn_link), pn_link_remote_target(pn_link));
+ pn_link_flow(pn_link, 8);
+ pn_link_open(pn_link);
+ } else {
+ pn_link_close(pn_link);
+ }
+ return 0;
+}
+
+
+/**
+ * New Outgoing Link Handler
+ */
+static int router_outgoing_link_handler(void* context, dx_link_t *link)
+{
+ dx_router_t *router = (dx_router_t*) context;
+ pn_link_t *pn_link = dx_link_pn(link);
+ const char *r_tgt = pn_terminus_get_address(pn_link_remote_target(pn_link));
+
+ sys_mutex_lock(router->lock);
+ dx_router_link_t *rlink = new_dx_router_link_t();
+ rlink->link = link;
+ DEQ_INIT(rlink->out_fifo);
+ dx_link_set_context(link, rlink);
+
+ dx_field_iterator_t *iter = dx_field_iterator_string(r_tgt, ITER_VIEW_NO_HOST);
+ int result = hash_insert(router->out_hash, iter, rlink);
+ dx_field_iterator_free(iter);
+
+ if (result == 0) {
+ pn_terminus_copy(pn_link_source(pn_link), pn_link_remote_source(pn_link));
+ pn_terminus_copy(pn_link_target(pn_link), pn_link_remote_target(pn_link));
+ pn_link_open(pn_link);
+ sys_mutex_unlock(router->lock);
+ dx_log(module, LOG_TRACE, "Registered new local address: %s", r_tgt);
+ return 0;
+ }
+
+ dx_log(module, LOG_TRACE, "Address '%s' not registered as it already exists", r_tgt);
+ pn_link_close(pn_link);
+ sys_mutex_unlock(router->lock);
+ return 0;
+}
+
+
+/**
+ * Outgoing Link Writable Handler
+ */
+static int router_writable_link_handler(void* context, dx_link_t *link)
+{
+ dx_router_t *router = (dx_router_t*) context;
+ int grant_delivery = 0;
+ pn_delivery_t *delivery;
+ dx_router_link_t *rlink = (dx_router_link_t*) dx_link_get_context(link);
+ pn_link_t *pn_link = dx_link_pn(link);
+ uint64_t tag;
+
+ sys_mutex_lock(router->lock);
+ if (DEQ_SIZE(rlink->out_fifo) > 0) {
+ grant_delivery = 1;
+ tag = router->dtag++;
+ }
+ sys_mutex_unlock(router->lock);
+
+ if (grant_delivery) {
+ pn_delivery(pn_link, pn_dtag((char*) &tag, 8));
+ delivery = pn_link_current(pn_link);
+ if (delivery) {
+ router_tx_handler(context, link, delivery);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+
+/**
+ * Link Detached Handler
+ */
+static int router_link_detach_handler(void* context, dx_link_t *link, int closed)
+{
+ dx_router_t *router = (dx_router_t*) context;
+ pn_link_t *pn_link = dx_link_pn(link);
+ const char *r_tgt = pn_terminus_get_address(pn_link_remote_target(pn_link));
+ dx_link_item_t *item;
+
+ sys_mutex_lock(router->lock);
+ if (pn_link_is_sender(pn_link)) {
+ item = DEQ_HEAD(router->out_links);
+
+ dx_field_iterator_t *iter = dx_field_iterator_string(r_tgt, ITER_VIEW_NO_HOST);
+ dx_router_link_t *rlink;
+ if (iter) {
+ int result = hash_retrieve(router->out_hash, iter, (void*) &rlink);
+ if (result == 0) {
+ dx_field_iterator_reset(iter, ITER_VIEW_NO_HOST);
+ hash_remove(router->out_hash, iter);
+ free_dx_router_link_t(rlink);
+ dx_log(module, LOG_TRACE, "Removed local address: %s", r_tgt);
+ }
+ dx_field_iterator_free(iter);
+ }
+ }
+ else
+ item = DEQ_HEAD(router->in_links);
+
+ while (item) {
+ if (item->link == link) {
+ if (pn_link_is_sender(pn_link))
+ DEQ_REMOVE(router->out_links, item);
+ else
+ DEQ_REMOVE(router->in_links, item);
+ free_dx_link_item_t(item);
+ break;
+ }
+ item = item->next;
+ }
+
+ sys_mutex_unlock(router->lock);
+ return 0;
+}
+
+
+static void router_inbound_open_handler(void *type_context, dx_connection_t *conn)
+{
+}
+
+
+static void router_outbound_open_handler(void *type_context, dx_connection_t *conn)
+{
+}
+
+
+static void dx_router_timer_handler(void *context)
+{
+ dx_router_t *router = (dx_router_t*) context;
+
+ //
+ // Periodic processing.
+ //
+ dx_timer_schedule(router->timer, 1000);
+}
+
+
+static dx_node_type_t router_node = {"router", 0, 0,
+ router_rx_handler,
+ router_tx_handler,
+ router_disp_handler,
+ router_incoming_link_handler,
+ router_outgoing_link_handler,
+ router_writable_link_handler,
+ router_link_detach_handler,
+ 0, // node_created_handler
+ 0, // node_destroyed_handler
+ router_inbound_open_handler,
+ router_outbound_open_handler };
+static int type_registered = 0;
+
+
+dx_router_t *dx_router(dx_router_configuration_t *config)
+{
+ if (!type_registered) {
+ type_registered = 1;
+ dx_container_register_node_type(&router_node);
+ }
+
+ dx_router_t *router = NEW(dx_router_t);
+ dx_container_set_default_node_type(&router_node, (void*) router, DX_DIST_BOTH);
+
+ DEQ_INIT(router->in_links);
+ DEQ_INIT(router->out_links);
+ DEQ_INIT(router->in_fifo);
+
+ router->lock = sys_mutex();
+
+ router->timer = dx_timer(dx_router_timer_handler, (void*) router);
+ dx_timer_schedule(router->timer, 0); // Immediate
+
+ router->out_hash = hash(10, 32, 0);
+ router->dtag = 1;
+
+ return router;
+}
+
+
+void dx_router_free(dx_router_t *router)
+{
+ dx_container_set_default_node_type(0, 0, DX_DIST_BOTH);
+ sys_mutex_free(router->lock);
+ free(router);
+}
+
diff --git a/extras/dispatch/src/server.c b/extras/dispatch/src/server.c
new file mode 100644
index 0000000000..0099393f60
--- /dev/null
+++ b/extras/dispatch/src/server.c
@@ -0,0 +1,903 @@
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/threading.h>
+#include <qpid/dispatch/log.h>
+#include "server_private.h"
+#include "timer_private.h"
+#include "alloc_private.h"
+#include "auth.h"
+#include "work_queue.h"
+#include <stdio.h>
+#include <time.h>
+#include <signal.h>
+
+static char *module="SERVER";
+
+typedef struct dx_thread_t {
+ int thread_id;
+ volatile int running;
+ volatile int canceled;
+ int using_thread;
+ sys_thread_t *thread;
+} dx_thread_t;
+
+
+typedef struct dx_server_t {
+ int thread_count;
+ pn_driver_t *driver;
+ dx_thread_start_cb_t start_handler;
+ dx_conn_handler_cb_t conn_handler;
+ dx_signal_handler_cb_t signal_handler;
+ dx_user_fd_handler_cb_t ufd_handler;
+ void *start_context;
+ void *conn_context;
+ void *signal_context;
+ sys_cond_t *cond;
+ sys_mutex_t *lock;
+ dx_thread_t **threads;
+ work_queue_t *work_queue;
+ dx_timer_list_t pending_timers;
+ bool a_thread_is_waiting;
+ int threads_active;
+ int pause_requests;
+ int threads_paused;
+ int pause_next_sequence;
+ int pause_now_serving;
+ int pending_signal;
+} dx_server_t;
+
+
+ALLOC_DEFINE(dx_listener_t);
+ALLOC_DEFINE(dx_connector_t);
+ALLOC_DEFINE(dx_connection_t);
+ALLOC_DEFINE(dx_user_fd_t);
+
+
+/**
+ * Singleton Concurrent Proton Driver object
+ */
+static dx_server_t *dx_server = 0;
+
+
+static void signal_handler(int signum)
+{
+ dx_server->pending_signal = signum;
+ sys_cond_signal_all(dx_server->cond);
+}
+
+
+static dx_thread_t *thread(int id)
+{
+ dx_thread_t *thread = NEW(dx_thread_t);
+ if (!thread)
+ return 0;
+
+ thread->thread_id = id;
+ thread->running = 0;
+ thread->canceled = 0;
+ thread->using_thread = 0;
+
+ return thread;
+}
+
+
+static void thread_process_listeners(pn_driver_t *driver)
+{
+ pn_listener_t *listener = pn_driver_listener(driver);
+ pn_connector_t *cxtr;
+ dx_connection_t *ctx;
+
+ while (listener) {
+ dx_log(module, LOG_TRACE, "Accepting Connection");
+ cxtr = pn_listener_accept(listener);
+ ctx = new_dx_connection_t();
+ ctx->state = CONN_STATE_SASL_SERVER;
+ ctx->owner_thread = CONTEXT_NO_OWNER;
+ ctx->enqueued = 0;
+ ctx->pn_cxtr = cxtr;
+ ctx->pn_conn = 0;
+ ctx->listener = (dx_listener_t*) pn_listener_context(listener);
+ ctx->connector = 0;
+ ctx->context = ctx->listener->context;
+ ctx->ufd = 0;
+
+ pn_connector_set_context(cxtr, ctx);
+ listener = pn_driver_listener(driver);
+ }
+}
+
+
+static void handle_signals_LH(void)
+{
+ int signum = dx_server->pending_signal;
+
+ if (signum) {
+ dx_server->pending_signal = 0;
+ if (dx_server->signal_handler) {
+ sys_mutex_unlock(dx_server->lock);
+ dx_server->signal_handler(dx_server->signal_context, signum);
+ sys_mutex_lock(dx_server->lock);
+ }
+ }
+}
+
+
+static void block_if_paused_LH(void)
+{
+ if (dx_server->pause_requests > 0) {
+ dx_server->threads_paused++;
+ sys_cond_signal_all(dx_server->cond);
+ while (dx_server->pause_requests > 0)
+ sys_cond_wait(dx_server->cond, dx_server->lock);
+ dx_server->threads_paused--;
+ }
+}
+
+
+static void process_connector(pn_connector_t *cxtr)
+{
+ dx_connection_t *ctx = pn_connector_context(cxtr);
+ int events = 0;
+ int auth_passes = 0;
+
+ if (ctx->state == CONN_STATE_USER) {
+ dx_server->ufd_handler(ctx->ufd->context, ctx->ufd);
+ return;
+ }
+
+ do {
+ //
+ // Step the engine for pre-handler processing
+ //
+ pn_connector_process(cxtr);
+
+ //
+ // Call the handler that is appropriate for the connector's state.
+ //
+ switch (ctx->state) {
+ case CONN_STATE_CONNECTING:
+ if (!pn_connector_closed(cxtr)) {
+ ctx->state = CONN_STATE_SASL_CLIENT;
+ assert(ctx->connector);
+ ctx->connector->state = CXTR_STATE_OPEN;
+ events = 1;
+ } else {
+ ctx->state = CONN_STATE_FAILED;
+ events = 0;
+ }
+ break;
+
+ case CONN_STATE_SASL_CLIENT:
+ if (auth_passes == 0) {
+ auth_client_handler(cxtr);
+ events = 1;
+ } else {
+ auth_passes++;
+ events = 0;
+ }
+ break;
+
+ case CONN_STATE_SASL_SERVER:
+ if (auth_passes == 0) {
+ auth_server_handler(cxtr);
+ events = 1;
+ } else {
+ auth_passes++;
+ events = 0;
+ }
+ break;
+
+ case CONN_STATE_OPENING:
+ ctx->state = CONN_STATE_OPERATIONAL;
+
+ pn_connection_t *conn = pn_connection();
+ pn_connection_set_container(conn, "dispatch"); // TODO - make unique
+ pn_connector_set_connection(cxtr, conn);
+ pn_connection_set_context(conn, ctx);
+ ctx->pn_conn = conn;
+
+ dx_conn_event_t ce = DX_CONN_EVENT_PROCESS; // Initialize to keep the compiler happy
+
+ if (ctx->listener) {
+ ce = DX_CONN_EVENT_LISTENER_OPEN;
+ } else if (ctx->connector) {
+ ce = DX_CONN_EVENT_CONNECTOR_OPEN;
+ ctx->connector->delay = 0;
+ } else
+ assert(0);
+
+ dx_server->conn_handler(ctx->context, ce, (dx_connection_t*) pn_connector_context(cxtr));
+ events = 1;
+ break;
+
+ case CONN_STATE_OPERATIONAL:
+ if (pn_connector_closed(cxtr)) {
+ dx_server->conn_handler(ctx->context,
+ DX_CONN_EVENT_CLOSE,
+ (dx_connection_t*) pn_connector_context(cxtr));
+ events = 0;
+ }
+ else
+ events = dx_server->conn_handler(ctx->context,
+ DX_CONN_EVENT_PROCESS,
+ (dx_connection_t*) pn_connector_context(cxtr));
+ break;
+
+ default:
+ break;
+ }
+ } while (events > 0);
+}
+
+
+//
+// TEMPORARY FUNCTION PROTOTYPES
+//
+void pn_driver_wait_1(pn_driver_t *d);
+int pn_driver_wait_2(pn_driver_t *d, int timeout);
+void pn_driver_wait_3(pn_driver_t *d);
+//
+// END TEMPORARY
+//
+
+static void *thread_run(void *arg)
+{
+ dx_thread_t *thread = (dx_thread_t*) arg;
+ pn_connector_t *work;
+ pn_connection_t *conn;
+ dx_connection_t *ctx;
+ int error;
+ int poll_result;
+ int timer_holdoff = 0;
+
+ if (!thread)
+ return 0;
+
+ thread->running = 1;
+
+ if (thread->canceled)
+ return 0;
+
+ //
+ // Invoke the start handler if the application supplied one.
+ // This handler can be used to set NUMA or processor affinnity for the thread.
+ //
+ if (dx_server->start_handler)
+ dx_server->start_handler(dx_server->start_context, thread->thread_id);
+
+ //
+ // Main Loop
+ //
+ while (thread->running) {
+ sys_mutex_lock(dx_server->lock);
+
+ //
+ // Check for pending signals to process
+ //
+ handle_signals_LH();
+ if (!thread->running) {
+ sys_mutex_unlock(dx_server->lock);
+ break;
+ }
+
+ //
+ // Check to see if the server is pausing. If so, block here.
+ //
+ block_if_paused_LH();
+ if (!thread->running) {
+ sys_mutex_unlock(dx_server->lock);
+ break;
+ }
+
+ //
+ // Service pending timers.
+ //
+ dx_timer_t *timer = DEQ_HEAD(dx_server->pending_timers);
+ if (timer) {
+ DEQ_REMOVE_HEAD(dx_server->pending_timers);
+
+ //
+ // Mark the timer as idle in case it reschedules itself.
+ //
+ dx_timer_idle_LH(timer);
+
+ //
+ // Release the lock and invoke the connection handler.
+ //
+ sys_mutex_unlock(dx_server->lock);
+ timer->handler(timer->context);
+ pn_driver_wakeup(dx_server->driver);
+ continue;
+ }
+
+ //
+ // Check the work queue for connectors scheduled for processing.
+ //
+ work = work_queue_get(dx_server->work_queue);
+ if (!work) {
+ //
+ // There is no pending work to do
+ //
+ if (dx_server->a_thread_is_waiting) {
+ //
+ // Another thread is waiting on the proton driver, this thread must
+ // wait on the condition variable until signaled.
+ //
+ sys_cond_wait(dx_server->cond, dx_server->lock);
+ } else {
+ //
+ // This thread elects itself to wait on the proton driver. Set the
+ // thread-is-waiting flag so other idle threads will not interfere.
+ //
+ dx_server->a_thread_is_waiting = true;
+
+ //
+ // Ask the timer module when its next timer is scheduled to fire. We'll
+ // use this value in driver_wait as the timeout. If there are no scheduled
+ // timers, the returned value will be -1.
+ //
+ long duration = dx_timer_next_duration_LH();
+
+ //
+ // Invoke the proton driver's wait sequence. This is a bit of a hack for now
+ // and will be improved in the future. The wait process is divided into three parts,
+ // the first and third of which need to be non-reentrant, and the second of which
+ // must be reentrant (and blocks).
+ //
+ pn_driver_wait_1(dx_server->driver);
+ sys_mutex_unlock(dx_server->lock);
+
+ do {
+ error = 0;
+ poll_result = pn_driver_wait_2(dx_server->driver, duration);
+ if (poll_result == -1)
+ error = pn_driver_errno(dx_server->driver);
+ } while (error == PN_INTR);
+ if (error) {
+ dx_log(module, LOG_ERROR, "Driver Error: %s", pn_error_text(pn_error(dx_server->driver)));
+ exit(-1);
+ }
+
+ sys_mutex_lock(dx_server->lock);
+ pn_driver_wait_3(dx_server->driver);
+
+ if (!thread->running) {
+ sys_mutex_unlock(dx_server->lock);
+ break;
+ }
+
+ //
+ // Visit the timer module.
+ //
+ if (poll_result == 0 || ++timer_holdoff == 100) {
+ struct timespec tv;
+ clock_gettime(CLOCK_REALTIME, &tv);
+ long milliseconds = tv.tv_sec * 1000 + tv.tv_nsec / 1000000;
+ dx_timer_visit_LH(milliseconds);
+ timer_holdoff = 0;
+ }
+
+ //
+ // Process listeners (incoming connections).
+ //
+ thread_process_listeners(dx_server->driver);
+
+ //
+ // Traverse the list of connectors-needing-service from the proton driver.
+ // If the connector is not already in the work queue and it is not currently
+ // being processed by another thread, put it in the work queue and signal the
+ // condition variable.
+ //
+ work = pn_driver_connector(dx_server->driver);
+ while (work) {
+ ctx = pn_connector_context(work);
+ if (!ctx->enqueued && ctx->owner_thread == CONTEXT_NO_OWNER) {
+ ctx->enqueued = 1;
+ work_queue_put(dx_server->work_queue, work);
+ sys_cond_signal(dx_server->cond);
+ }
+ work = pn_driver_connector(dx_server->driver);
+ }
+
+ //
+ // Release our exclusive claim on pn_driver_wait.
+ //
+ dx_server->a_thread_is_waiting = false;
+ }
+ }
+
+ //
+ // If we were given a connector to work on from the work queue, mark it as
+ // owned by this thread and as no longer enqueued.
+ //
+ if (work) {
+ ctx = pn_connector_context(work);
+ if (ctx->owner_thread == CONTEXT_NO_OWNER) {
+ ctx->owner_thread = thread->thread_id;
+ ctx->enqueued = 0;
+ dx_server->threads_active++;
+ } else {
+ //
+ // This connector is being processed by another thread, re-queue it.
+ //
+ work_queue_put(dx_server->work_queue, work);
+ work = 0;
+ }
+ }
+ sys_mutex_unlock(dx_server->lock);
+
+ //
+ // Process the connector that we now have exclusive access to.
+ //
+ if (work) {
+ process_connector(work);
+
+ //
+ // Check to see if the connector was closed during processing
+ //
+ if (pn_connector_closed(work)) {
+ //
+ // Connector is closed. Free the context and the connector.
+ //
+ conn = pn_connector_connection(work);
+ if (ctx->connector) {
+ ctx->connector->ctx = 0;
+ ctx->connector->state = CXTR_STATE_CONNECTING;
+ dx_timer_schedule(ctx->connector->timer, ctx->connector->delay);
+ }
+ sys_mutex_lock(dx_server->lock);
+ free_dx_connection_t(ctx);
+ pn_connector_free(work);
+ if (conn)
+ pn_connection_free(conn);
+ dx_server->threads_active--;
+ sys_mutex_unlock(dx_server->lock);
+ } else {
+ //
+ // The connector lives on. Mark it as no longer owned by this thread.
+ //
+ sys_mutex_lock(dx_server->lock);
+ ctx->owner_thread = CONTEXT_NO_OWNER;
+ dx_server->threads_active--;
+ sys_mutex_unlock(dx_server->lock);
+ }
+
+ //
+ // Wake up the proton driver to force it to reconsider its set of FDs
+ // in light of the processing that just occurred.
+ //
+ pn_driver_wakeup(dx_server->driver);
+ }
+ }
+
+ return 0;
+}
+
+
+static void thread_start(dx_thread_t *thread)
+{
+ if (!thread)
+ return;
+
+ thread->using_thread = 1;
+ thread->thread = sys_thread(thread_run, (void*) thread);
+}
+
+
+static void thread_cancel(dx_thread_t *thread)
+{
+ if (!thread)
+ return;
+
+ thread->running = 0;
+ thread->canceled = 1;
+}
+
+
+static void thread_join(dx_thread_t *thread)
+{
+ if (!thread)
+ return;
+
+ if (thread->using_thread)
+ sys_thread_join(thread->thread);
+}
+
+
+static void thread_free(dx_thread_t *thread)
+{
+ if (!thread)
+ return;
+
+ free(thread);
+}
+
+
+static void cxtr_try_open(void *context)
+{
+ dx_connector_t *ct = (dx_connector_t*) context;
+ if (ct->state != CXTR_STATE_CONNECTING)
+ return;
+
+ dx_connection_t *ctx = new_dx_connection_t();
+ ctx->state = CONN_STATE_CONNECTING;
+ ctx->owner_thread = CONTEXT_NO_OWNER;
+ ctx->enqueued = 0;
+ ctx->pn_conn = 0;
+ ctx->listener = 0;
+ ctx->connector = ct;
+ ctx->context = ct->context;
+ ctx->user_context = 0;
+ ctx->ufd = 0;
+
+ //
+ // pn_connector is not thread safe
+ //
+ sys_mutex_lock(dx_server->lock);
+ ctx->pn_cxtr = pn_connector(dx_server->driver, ct->config->host, ct->config->port, (void*) ctx);
+ sys_mutex_unlock(dx_server->lock);
+
+ ct->ctx = ctx;
+ ct->delay = 5000;
+ dx_log(module, LOG_TRACE, "Connecting to %s:%s", ct->config->host, ct->config->port);
+}
+
+
+void dx_server_initialize(int thread_count)
+{
+ int i;
+
+ if (dx_server)
+ return; // TODO - Fail in a more dramatic way
+
+ dx_alloc_initialize();
+ dx_server = NEW(dx_server_t);
+
+ if (!dx_server)
+ return; // TODO - Fail in a more dramatic way
+
+ dx_server->thread_count = thread_count;
+ dx_server->driver = pn_driver();
+ dx_server->start_handler = 0;
+ dx_server->conn_handler = 0;
+ dx_server->signal_handler = 0;
+ dx_server->ufd_handler = 0;
+ dx_server->start_context = 0;
+ dx_server->signal_context = 0;
+ dx_server->lock = sys_mutex();
+ dx_server->cond = sys_cond();
+
+ dx_timer_initialize(dx_server->lock);
+
+ dx_server->threads = NEW_PTR_ARRAY(dx_thread_t, thread_count);
+ for (i = 0; i < thread_count; i++)
+ dx_server->threads[i] = thread(i);
+
+ dx_server->work_queue = work_queue();
+ DEQ_INIT(dx_server->pending_timers);
+ dx_server->a_thread_is_waiting = false;
+ dx_server->threads_active = 0;
+ dx_server->pause_requests = 0;
+ dx_server->threads_paused = 0;
+ dx_server->pause_next_sequence = 0;
+ dx_server->pause_now_serving = 0;
+ dx_server->pending_signal = 0;
+}
+
+
+void dx_server_finalize(void)
+{
+ int i;
+ if (!dx_server)
+ return;
+
+ for (i = 0; i < dx_server->thread_count; i++)
+ thread_free(dx_server->threads[i]);
+
+ work_queue_free(dx_server->work_queue);
+
+ pn_driver_free(dx_server->driver);
+ sys_mutex_free(dx_server->lock);
+ sys_cond_free(dx_server->cond);
+ free(dx_server);
+ dx_server = 0;
+}
+
+
+void dx_server_set_conn_handler(dx_conn_handler_cb_t handler)
+{
+ dx_server->conn_handler = handler;
+}
+
+
+void dx_server_set_signal_handler(dx_signal_handler_cb_t handler, void *context)
+{
+ dx_server->signal_handler = handler;
+ dx_server->signal_context = context;
+}
+
+
+void dx_server_set_start_handler(dx_thread_start_cb_t handler, void *context)
+{
+ dx_server->start_handler = handler;
+ dx_server->start_context = context;
+}
+
+
+void dx_server_set_user_fd_handler(dx_user_fd_handler_cb_t ufd_handler)
+{
+ dx_server->ufd_handler = ufd_handler;
+}
+
+
+void dx_server_run(void)
+{
+ int i;
+ if (!dx_server)
+ return;
+
+ assert(dx_server->conn_handler); // Server can't run without a connection handler.
+
+ for (i = 1; i < dx_server->thread_count; i++)
+ thread_start(dx_server->threads[i]);
+
+ dx_log(module, LOG_INFO, "Operational, %d Threads Running", dx_server->thread_count);
+
+ thread_run((void*) dx_server->threads[0]);
+
+ for (i = 1; i < dx_server->thread_count; i++)
+ thread_join(dx_server->threads[i]);
+
+ dx_log(module, LOG_INFO, "Shut Down");
+}
+
+
+void dx_server_stop(void)
+{
+ int idx;
+
+ sys_mutex_lock(dx_server->lock);
+ for (idx = 0; idx < dx_server->thread_count; idx++)
+ thread_cancel(dx_server->threads[idx]);
+ sys_cond_signal_all(dx_server->cond);
+ pn_driver_wakeup(dx_server->driver);
+ sys_mutex_unlock(dx_server->lock);
+}
+
+
+void dx_server_signal(int signum)
+{
+ signal(signum, signal_handler);
+}
+
+
+void dx_server_pause(void)
+{
+ sys_mutex_lock(dx_server->lock);
+
+ //
+ // Bump the request count to stop all the threads.
+ //
+ dx_server->pause_requests++;
+ int my_sequence = dx_server->pause_next_sequence++;
+
+ //
+ // Awaken all threads that are currently blocking.
+ //
+ sys_cond_signal_all(dx_server->cond);
+ pn_driver_wakeup(dx_server->driver);
+
+ //
+ // Wait for the paused thread count plus the number of threads requesting a pause to equal
+ // the total thread count. Also, don't exit the blocking loop until now_serving equals our
+ // sequence number. This ensures that concurrent pausers don't run at the same time.
+ //
+ while ((dx_server->threads_paused + dx_server->pause_requests < dx_server->thread_count) ||
+ (my_sequence != dx_server->pause_now_serving))
+ sys_cond_wait(dx_server->cond, dx_server->lock);
+
+ sys_mutex_unlock(dx_server->lock);
+}
+
+
+void dx_server_resume(void)
+{
+ sys_mutex_lock(dx_server->lock);
+ dx_server->pause_requests--;
+ dx_server->pause_now_serving++;
+ sys_cond_signal_all(dx_server->cond);
+ sys_mutex_unlock(dx_server->lock);
+}
+
+
+void dx_server_activate(dx_connection_t *ctx)
+{
+ if (!ctx)
+ return;
+
+ pn_connector_t *ctor = ctx->pn_cxtr;
+ if (!ctor)
+ return;
+
+ if (!pn_connector_closed(ctor))
+ pn_connector_activate(ctor, PN_CONNECTOR_WRITABLE);
+}
+
+
+void dx_connection_set_context(dx_connection_t *conn, void *context)
+{
+ conn->user_context = context;
+}
+
+
+void *dx_connection_get_context(dx_connection_t *conn)
+{
+ return conn->user_context;
+}
+
+
+pn_connection_t *dx_connection_pn(dx_connection_t *conn)
+{
+ return conn->pn_conn;
+}
+
+
+dx_listener_t *dx_server_listen(const dx_server_config_t *config, void *context)
+{
+ dx_listener_t *li = new_dx_listener_t();
+
+ if (!li)
+ return 0;
+
+ li->config = config;
+ li->context = context;
+ li->pn_listener = pn_listener(dx_server->driver, config->host, config->port, (void*) li);
+
+ if (!li->pn_listener) {
+ dx_log(module, LOG_ERROR, "Driver Error %d (%s)",
+ pn_driver_errno(dx_server->driver), pn_driver_error(dx_server->driver));
+ free_dx_listener_t(li);
+ return 0;
+ }
+ dx_log(module, LOG_TRACE, "Listening on %s:%s", config->host, config->port);
+
+ return li;
+}
+
+
+void dx_server_listener_free(dx_listener_t* li)
+{
+ pn_listener_free(li->pn_listener);
+ free_dx_listener_t(li);
+}
+
+
+void dx_server_listener_close(dx_listener_t* li)
+{
+ pn_listener_close(li->pn_listener);
+}
+
+
+dx_connector_t *dx_server_connect(const dx_server_config_t *config, void *context)
+{
+ dx_connector_t *ct = new_dx_connector_t();
+
+ if (!ct)
+ return 0;
+
+ ct->state = CXTR_STATE_CONNECTING;
+ ct->config = config;
+ ct->context = context;
+ ct->ctx = 0;
+ ct->timer = dx_timer(cxtr_try_open, (void*) ct);
+ ct->delay = 0;
+
+ dx_timer_schedule(ct->timer, ct->delay);
+ return ct;
+}
+
+
+void dx_server_connector_free(dx_connector_t* ct)
+{
+ // Don't free the proton connector. This will be done by the connector
+ // processing/cleanup.
+
+ if (ct->ctx) {
+ pn_connector_close(ct->ctx->pn_cxtr);
+ ct->ctx->connector = 0;
+ }
+
+ dx_timer_free(ct->timer);
+ free_dx_connector_t(ct);
+}
+
+
+dx_user_fd_t *dx_user_fd(int fd, void *context)
+{
+ dx_user_fd_t *ufd = new_dx_user_fd_t();
+
+ if (!ufd)
+ return 0;
+
+ dx_connection_t *ctx = new_dx_connection_t();
+ ctx->state = CONN_STATE_USER;
+ ctx->owner_thread = CONTEXT_NO_OWNER;
+ ctx->enqueued = 0;
+ ctx->pn_conn = 0;
+ ctx->listener = 0;
+ ctx->connector = 0;
+ ctx->context = 0;
+ ctx->user_context = 0;
+ ctx->ufd = ufd;
+
+ ufd->context = context;
+ ufd->fd = fd;
+ ufd->pn_conn = pn_connector_fd(dx_server->driver, fd, (void*) ctx);
+ pn_driver_wakeup(dx_server->driver);
+
+ return ufd;
+}
+
+
+void dx_user_fd_free(dx_user_fd_t *ufd)
+{
+ pn_connector_close(ufd->pn_conn);
+ free_dx_user_fd_t(ufd);
+}
+
+
+void dx_user_fd_activate_read(dx_user_fd_t *ufd)
+{
+ pn_connector_activate(ufd->pn_conn, PN_CONNECTOR_READABLE);
+ pn_driver_wakeup(dx_server->driver);
+}
+
+
+void dx_user_fd_activate_write(dx_user_fd_t *ufd)
+{
+ pn_connector_activate(ufd->pn_conn, PN_CONNECTOR_WRITABLE);
+ pn_driver_wakeup(dx_server->driver);
+}
+
+
+bool dx_user_fd_is_readable(dx_user_fd_t *ufd)
+{
+ return pn_connector_activated(ufd->pn_conn, PN_CONNECTOR_READABLE);
+}
+
+
+bool dx_user_fd_is_writeable(dx_user_fd_t *ufd)
+{
+ return pn_connector_activated(ufd->pn_conn, PN_CONNECTOR_WRITABLE);
+}
+
+
+void dx_server_timer_pending_LH(dx_timer_t *timer)
+{
+ DEQ_INSERT_TAIL(dx_server->pending_timers, timer);
+}
+
+
+void dx_server_timer_cancel_LH(dx_timer_t *timer)
+{
+ DEQ_REMOVE(dx_server->pending_timers, timer);
+}
+
diff --git a/extras/dispatch/src/server_private.h b/extras/dispatch/src/server_private.h
new file mode 100644
index 0000000000..1722175e35
--- /dev/null
+++ b/extras/dispatch/src/server_private.h
@@ -0,0 +1,96 @@
+#ifndef __server_private_h__
+#define __server_private_h__ 1
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/server.h>
+#include <qpid/dispatch/user_fd.h>
+#include <qpid/dispatch/timer.h>
+#include <qpid/dispatch/alloc.h>
+#include <proton/driver.h>
+#include <proton/driver_extras.h>
+
+void dx_server_timer_pending_LH(dx_timer_t *timer);
+void dx_server_timer_cancel_LH(dx_timer_t *timer);
+
+
+typedef enum {
+ CONN_STATE_CONNECTING = 0,
+ CONN_STATE_SASL_CLIENT,
+ CONN_STATE_SASL_SERVER,
+ CONN_STATE_OPENING,
+ CONN_STATE_OPERATIONAL,
+ CONN_STATE_FAILED,
+ CONN_STATE_USER
+} conn_state_t;
+
+#define CONTEXT_NO_OWNER -1
+
+typedef enum {
+ CXTR_STATE_CONNECTING = 0,
+ CXTR_STATE_OPEN,
+ CXTR_STATE_FAILED
+} cxtr_state_t;
+
+
+struct dx_listener_t {
+ const dx_server_config_t *config;
+ void *context;
+ pn_listener_t *pn_listener;
+};
+
+
+struct dx_connector_t {
+ cxtr_state_t state;
+ const dx_server_config_t *config;
+ void *context;
+ dx_connection_t *ctx;
+ dx_timer_t *timer;
+ long delay;
+};
+
+
+struct dx_connection_t {
+ conn_state_t state;
+ int owner_thread;
+ int enqueued;
+ pn_connector_t *pn_cxtr;
+ pn_connection_t *pn_conn;
+ dx_listener_t *listener;
+ dx_connector_t *connector;
+ void *context; // Copy of context from listener or connector
+ void *user_context;
+ dx_user_fd_t *ufd;
+};
+
+
+struct dx_user_fd_t {
+ void *context;
+ int fd;
+ pn_connector_t *pn_conn;
+};
+
+
+ALLOC_DECLARE(dx_listener_t);
+ALLOC_DECLARE(dx_connector_t);
+ALLOC_DECLARE(dx_connection_t);
+ALLOC_DECLARE(dx_user_fd_t);
+
+
+#endif
diff --git a/extras/dispatch/src/timer.c b/extras/dispatch/src/timer.c
new file mode 100644
index 0000000000..b6b4864e26
--- /dev/null
+++ b/extras/dispatch/src/timer.c
@@ -0,0 +1,236 @@
+/*
+ * 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.
+ */
+
+#include "timer_private.h"
+#include "server_private.h"
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/threading.h>
+#include <qpid/dispatch/alloc.h>
+#include <assert.h>
+#include <stdio.h>
+
+static sys_mutex_t *lock;
+static dx_timer_list_t idle_timers;
+static dx_timer_list_t scheduled_timers;
+static long time_base;
+
+ALLOC_DECLARE(dx_timer_t);
+ALLOC_DEFINE(dx_timer_t);
+
+//=========================================================================
+// Private static functions
+//=========================================================================
+
+static void dx_timer_cancel_LH(dx_timer_t *timer)
+{
+ switch (timer->state) {
+ case TIMER_FREE:
+ assert(0);
+ break;
+
+ case TIMER_IDLE:
+ break;
+
+ case TIMER_SCHEDULED:
+ if (timer->next)
+ timer->next->delta_time += timer->delta_time;
+ DEQ_REMOVE(scheduled_timers, timer);
+ DEQ_INSERT_TAIL(idle_timers, timer);
+ break;
+
+ case TIMER_PENDING:
+ dx_server_timer_cancel_LH(timer);
+ break;
+ }
+
+ timer->state = TIMER_IDLE;
+}
+
+
+//=========================================================================
+// Public Functions from timer.h
+//=========================================================================
+
+dx_timer_t *dx_timer(dx_timer_cb_t cb, void* context)
+{
+ dx_timer_t *timer = new_dx_timer_t();
+ if (!timer)
+ return 0;
+
+ DEQ_ITEM_INIT(timer);
+
+ timer->handler = cb;
+ timer->context = context;
+ timer->delta_time = 0;
+ timer->state = TIMER_IDLE;
+
+ sys_mutex_lock(lock);
+ DEQ_INSERT_TAIL(idle_timers, timer);
+ sys_mutex_unlock(lock);
+
+ return timer;
+}
+
+
+void dx_timer_free(dx_timer_t *timer)
+{
+ sys_mutex_lock(lock);
+ dx_timer_cancel_LH(timer);
+ DEQ_REMOVE(idle_timers, timer);
+ sys_mutex_unlock(lock);
+
+ timer->state = TIMER_FREE;
+ free_dx_timer_t(timer);
+}
+
+
+void dx_timer_schedule(dx_timer_t *timer, long duration)
+{
+ dx_timer_t *ptr;
+ dx_timer_t *last;
+ long total_time;
+
+ sys_mutex_lock(lock);
+ dx_timer_cancel_LH(timer); // Timer is now on the idle list
+ assert(timer->state == TIMER_IDLE);
+ DEQ_REMOVE(idle_timers, timer);
+
+ //
+ // Handle the special case of a zero-time scheduling. In this case,
+ // the timer doesn't go on the scheduled list. It goes straight to the
+ // pending list in the server.
+ //
+ if (duration == 0) {
+ timer->state = TIMER_PENDING;
+ dx_server_timer_pending_LH(timer);
+ sys_mutex_unlock(lock);
+ return;
+ }
+
+ //
+ // Find the insert point in the schedule.
+ //
+ total_time = 0;
+ ptr = DEQ_HEAD(scheduled_timers);
+ assert(!ptr || ptr->prev == 0);
+ while (ptr) {
+ total_time += ptr->delta_time;
+ if (total_time > duration)
+ break;
+ ptr = ptr->next;
+ }
+
+ //
+ // Insert the timer into the schedule and adjust the delta time
+ // of the following timer if present.
+ //
+ if (total_time <= duration) {
+ assert(ptr == 0);
+ timer->delta_time = duration - total_time;
+ DEQ_INSERT_TAIL(scheduled_timers, timer);
+ } else {
+ total_time -= ptr->delta_time;
+ timer->delta_time = duration - total_time;
+ assert(ptr->delta_time > timer->delta_time);
+ ptr->delta_time -= timer->delta_time;
+ last = ptr->prev;
+ if (last)
+ DEQ_INSERT_AFTER(scheduled_timers, timer, last);
+ else
+ DEQ_INSERT_HEAD(scheduled_timers, timer);
+ }
+
+ timer->state = TIMER_SCHEDULED;
+
+ sys_mutex_unlock(lock);
+}
+
+
+void dx_timer_cancel(dx_timer_t *timer)
+{
+ sys_mutex_lock(lock);
+ dx_timer_cancel_LH(timer);
+ sys_mutex_unlock(lock);
+}
+
+
+//=========================================================================
+// Private Functions from timer_private.h
+//=========================================================================
+
+void dx_timer_initialize(sys_mutex_t *server_lock)
+{
+ lock = server_lock;
+ DEQ_INIT(idle_timers);
+ DEQ_INIT(scheduled_timers);
+ time_base = 0;
+}
+
+
+void dx_timer_finalize(void)
+{
+ lock = 0;
+}
+
+
+long dx_timer_next_duration_LH(void)
+{
+ dx_timer_t *timer = DEQ_HEAD(scheduled_timers);
+ if (timer)
+ return timer->delta_time;
+ return -1;
+}
+
+
+void dx_timer_visit_LH(long current_time)
+{
+ long delta;
+ dx_timer_t *timer = DEQ_HEAD(scheduled_timers);
+
+ if (time_base == 0) {
+ time_base = current_time;
+ return;
+ }
+
+ delta = current_time - time_base;
+ time_base = current_time;
+
+ while (timer) {
+ assert(delta >= 0);
+ if (timer->delta_time > delta) {
+ timer->delta_time -= delta;
+ break;
+ } else {
+ DEQ_REMOVE_HEAD(scheduled_timers);
+ delta -= timer->delta_time;
+ timer->state = TIMER_PENDING;
+ dx_server_timer_pending_LH(timer);
+
+ }
+ timer = DEQ_HEAD(scheduled_timers);
+ }
+}
+
+
+void dx_timer_idle_LH(dx_timer_t *timer)
+{
+ timer->state = TIMER_IDLE;
+ DEQ_INSERT_TAIL(idle_timers, timer);
+}
+
diff --git a/extras/dispatch/src/timer_private.h b/extras/dispatch/src/timer_private.h
new file mode 100644
index 0000000000..618297b18e
--- /dev/null
+++ b/extras/dispatch/src/timer_private.h
@@ -0,0 +1,51 @@
+#ifndef __timer_private_h__
+#define __timer_private_h__ 1
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/timer.h>
+#include <qpid/dispatch/threading.h>
+
+typedef enum {
+ TIMER_FREE,
+ TIMER_IDLE,
+ TIMER_SCHEDULED,
+ TIMER_PENDING
+} dx_timer_state_t;
+
+
+struct dx_timer_t {
+ DEQ_LINKS(dx_timer_t);
+ dx_timer_cb_t handler;
+ void *context;
+ long delta_time;
+ dx_timer_state_t state;
+};
+
+DEQ_DECLARE(dx_timer_t, dx_timer_list_t);
+
+void dx_timer_initialize(sys_mutex_t *server_lock);
+void dx_timer_finalize(void);
+long dx_timer_next_duration_LH(void);
+void dx_timer_visit_LH(long current_time);
+void dx_timer_idle_LH(dx_timer_t *timer);
+
+
+#endif
diff --git a/extras/dispatch/src/work_queue.c b/extras/dispatch/src/work_queue.c
new file mode 100644
index 0000000000..4b3c5d7fa5
--- /dev/null
+++ b/extras/dispatch/src/work_queue.c
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+
+#include <qpid/dispatch/ctools.h>
+#include "work_queue.h"
+#include <string.h>
+#include <stdio.h>
+
+#define BATCH_SIZE 100
+typedef struct work_item_t work_item_t;
+
+struct work_item_t {
+ DEQ_LINKS(work_item_t);
+ pn_connector_t *conn;
+};
+
+DEQ_DECLARE(work_item_t, work_list_t);
+
+struct work_queue_t {
+ work_list_t items;
+ work_list_t free_list;
+};
+
+static void allocate_batch(work_queue_t *w)
+{
+ int i;
+ work_item_t *batch = NEW_ARRAY(work_item_t, BATCH_SIZE);
+ if (!batch)
+ return;
+
+ memset(batch, 0, sizeof(work_item_t) * BATCH_SIZE);
+
+ for (i = 0; i < BATCH_SIZE; i++)
+ DEQ_INSERT_TAIL(w->free_list, &batch[i]);
+}
+
+
+work_queue_t *work_queue(void)
+{
+ work_queue_t *w = NEW(work_queue_t);
+ if (!w)
+ return 0;
+
+ DEQ_INIT(w->items);
+ DEQ_INIT(w->free_list);
+
+ allocate_batch(w);
+
+ return w;
+}
+
+
+void work_queue_free(work_queue_t *w)
+{
+ if (!w)
+ return;
+
+ // KEEP TRACK OF BATCHES AND FREE
+ free(w);
+}
+
+
+void work_queue_put(work_queue_t *w, pn_connector_t *conn)
+{
+ work_item_t *item;
+
+ if (!w)
+ return;
+ if (DEQ_SIZE(w->free_list) == 0)
+ allocate_batch(w);
+ if (DEQ_SIZE(w->free_list) == 0)
+ return;
+
+ item = DEQ_HEAD(w->free_list);
+ DEQ_REMOVE_HEAD(w->free_list);
+
+ item->conn = conn;
+
+ DEQ_INSERT_TAIL(w->items, item);
+}
+
+
+pn_connector_t *work_queue_get(work_queue_t *w)
+{
+ work_item_t *item;
+ pn_connector_t *conn;
+
+ if (!w)
+ return 0;
+ item = DEQ_HEAD(w->items);
+ if (!item)
+ return 0;
+
+ DEQ_REMOVE_HEAD(w->items);
+ conn = item->conn;
+ item->conn = 0;
+
+ DEQ_INSERT_TAIL(w->free_list, item);
+
+ return conn;
+}
+
+
+int work_queue_empty(work_queue_t *w)
+{
+ return !w || DEQ_SIZE(w->items) == 0;
+}
+
+
+int work_queue_depth(work_queue_t *w)
+{
+ if (!w)
+ return 0;
+ return DEQ_SIZE(w->items);
+}
+
diff --git a/extras/dispatch/src/work_queue.h b/extras/dispatch/src/work_queue.h
new file mode 100644
index 0000000000..597a484a9c
--- /dev/null
+++ b/extras/dispatch/src/work_queue.h
@@ -0,0 +1,33 @@
+#ifndef __work_queue_h__
+#define __work_queue_h__ 1
+/*
+ * 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.
+ */
+
+#include <proton/driver.h>
+
+typedef struct work_queue_t work_queue_t;
+
+work_queue_t *work_queue(void);
+void work_queue_free(work_queue_t *w);
+void work_queue_put(work_queue_t *w, pn_connector_t *conn);
+pn_connector_t *work_queue_get(work_queue_t *w);
+int work_queue_empty(work_queue_t *w);
+int work_queue_depth(work_queue_t *w);
+
+#endif
diff --git a/extras/dispatch/tests/CMakeLists.txt b/extras/dispatch/tests/CMakeLists.txt
new file mode 100644
index 0000000000..10bf1eb43a
--- /dev/null
+++ b/extras/dispatch/tests/CMakeLists.txt
@@ -0,0 +1,34 @@
+##
+## 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.
+##
+
+##
+## Build test applications
+##
+set(test_SOURCES
+ alloc_test.c
+ message_test.c
+ run_tests.c
+ server_test.c
+ timer_test.c
+ tool_test.c
+ )
+
+add_executable(run_tests ${test_SOURCES})
+target_link_libraries(run_tests qpid-dispatch)
+
diff --git a/extras/dispatch/tests/alloc_test.c b/extras/dispatch/tests/alloc_test.c
new file mode 100644
index 0000000000..2406048209
--- /dev/null
+++ b/extras/dispatch/tests/alloc_test.c
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+#include "test_case.h"
+#include <stdio.h>
+#include <string.h>
+#include "alloc_private.h"
+
+typedef struct {
+ int A;
+ int B;
+} object_t;
+
+dx_alloc_config_t config = {3, 7, 10};
+
+ALLOC_DECLARE(object_t);
+ALLOC_DEFINE_CONFIG(object_t, sizeof(object_t), 0, &config);
+
+
+static char* check_stats(dx_alloc_stats_t *stats, uint64_t ah, uint64_t fh, uint64_t ht, uint64_t rt, uint64_t rg)
+{
+ if (stats->total_alloc_from_heap != ah) return "Incorrect alloc-from-heap";
+ if (stats->total_free_to_heap != fh) return "Incorrect free-to-heap";
+ if (stats->held_by_threads != ht) return "Incorrect held-by-threads";
+ if (stats->batches_rebalanced_to_threads != rt) return "Incorrect rebalance-to-threads";
+ if (stats->batches_rebalanced_to_global != rg) return "Incorrect rebalance-to-global";
+ return 0;
+}
+
+
+static char* test_alloc_basic(void *context)
+{
+ object_t *obj[50];
+ int idx;
+ dx_alloc_stats_t *stats;
+ char *error;
+
+ for (idx = 0; idx < 20; idx++)
+ obj[idx] = new_object_t();
+
+ stats = alloc_stats_object_t();
+ error = check_stats(stats, 21, 0, 21, 0, 0);
+ if (error) return error;
+
+ for (idx = 0; idx < 20; idx++)
+ free_object_t(obj[idx]);
+
+ error = check_stats(stats, 21, 5, 6, 0, 5);
+ if (error) return error;
+
+ for (idx = 0; idx < 20; idx++)
+ obj[idx] = new_object_t();
+
+ error = check_stats(stats, 27, 5, 21, 3, 5);
+ if (error) return error;
+
+ return 0;
+}
+
+
+int alloc_tests(void)
+{
+ int result = 0;
+ dx_alloc_initialize();
+
+ TEST_CASE(test_alloc_basic, 0);
+
+ return result;
+}
+
diff --git a/extras/dispatch/tests/message_test.c b/extras/dispatch/tests/message_test.c
new file mode 100644
index 0000000000..590b7f6ed7
--- /dev/null
+++ b/extras/dispatch/tests/message_test.c
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ */
+
+#include "test_case.h"
+#include <stdio.h>
+#include <string.h>
+#include "message_private.h"
+#include <qpid/dispatch/iterator.h>
+#include <proton/message.h>
+
+
+static char* test_send_to_messenger(void *context)
+{
+ dx_message_t *msg = dx_allocate_message();
+ dx_message_content_t *content = MSG_CONTENT(msg);
+
+ dx_message_compose_1(msg, "test_addr_0", 0);
+ dx_buffer_t *buf = DEQ_HEAD(content->buffers);
+ if (buf == 0) return "Expected a buffer in the test message";
+
+ pn_message_t *pn_msg = pn_message();
+ int result = pn_message_decode(pn_msg, (const char*) dx_buffer_base(buf), dx_buffer_size(buf));
+ if (result != 0) return "Error in pn_message_decode";
+
+ if (strcmp(pn_message_get_address(pn_msg), "test_addr_0") != 0)
+ return "Address mismatch in received message";
+
+ pn_message_free(pn_msg);
+ dx_free_message(msg);
+
+ return 0;
+}
+
+
+static char* test_receive_from_messenger(void *context)
+{
+ pn_message_t *pn_msg = pn_message();
+ pn_message_set_address(pn_msg, "test_addr_1");
+
+ dx_buffer_t *buf = dx_allocate_buffer();
+ size_t size = dx_buffer_capacity(buf);
+ int result = pn_message_encode(pn_msg, (char*) dx_buffer_cursor(buf), &size);
+ if (result != 0) return "Error in pn_message_encode";
+ dx_buffer_insert(buf, size);
+
+ dx_message_t *msg = dx_allocate_message();
+ dx_message_content_t *content = MSG_CONTENT(msg);
+
+ DEQ_INSERT_TAIL(content->buffers, buf);
+ int valid = dx_message_check(msg, DX_DEPTH_ALL);
+ if (!valid) return "dx_message_check returns 'invalid'";
+
+ dx_field_iterator_t *iter = dx_message_field_iterator(msg, DX_FIELD_TO);
+ if (iter == 0) return "Expected an iterator for the 'to' field";
+
+ if (!dx_field_iterator_equal(iter, (unsigned char*) "test_addr_1"))
+ return "Mismatched 'to' field contents";
+
+ pn_message_free(pn_msg);
+ dx_free_message(msg);
+
+ return 0;
+}
+
+
+static char* test_insufficient_check_depth(void *context)
+{
+ pn_message_t *pn_msg = pn_message();
+ pn_message_set_address(pn_msg, "test_addr_2");
+
+ dx_buffer_t *buf = dx_allocate_buffer();
+ size_t size = dx_buffer_capacity(buf);
+ int result = pn_message_encode(pn_msg, (char*) dx_buffer_cursor(buf), &size);
+ if (result != 0) return "Error in pn_message_encode";
+ dx_buffer_insert(buf, size);
+
+ dx_message_t *msg = dx_allocate_message();
+ dx_message_content_t *content = MSG_CONTENT(msg);
+
+ DEQ_INSERT_TAIL(content->buffers, buf);
+ int valid = dx_message_check(msg, DX_DEPTH_DELIVERY_ANNOTATIONS);
+ if (!valid) return "dx_message_check returns 'invalid'";
+
+ dx_field_iterator_t *iter = dx_message_field_iterator(msg, DX_FIELD_TO);
+ if (iter) return "Expected no iterator for the 'to' field";
+
+ dx_free_message(msg);
+
+ return 0;
+}
+
+
+int message_tests(void)
+{
+ int result = 0;
+
+ TEST_CASE(test_send_to_messenger, 0);
+ TEST_CASE(test_receive_from_messenger, 0);
+ TEST_CASE(test_insufficient_check_depth, 0);
+
+ return result;
+}
+
diff --git a/extras/dispatch/tests/run_tests.c b/extras/dispatch/tests/run_tests.c
new file mode 100644
index 0000000000..a677c04577
--- /dev/null
+++ b/extras/dispatch/tests/run_tests.c
@@ -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.
+ */
+
+int tool_tests();
+int timer_tests();
+int alloc_tests();
+int server_tests();
+int message_tests();
+
+int main(int argc, char** argv)
+{
+ int result = 0;
+ result += tool_tests();
+ result += timer_tests();
+ result += alloc_tests();
+ result += server_tests();
+ result += message_tests();
+ return result;
+}
+
diff --git a/extras/dispatch/tests/server_test.c b/extras/dispatch/tests/server_test.c
new file mode 100644
index 0000000000..adeab62af9
--- /dev/null
+++ b/extras/dispatch/tests/server_test.c
@@ -0,0 +1,195 @@
+/*
+ * 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.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <assert.h>
+#include <qpid/dispatch/timer.h>
+#include "test_case.h"
+#include <qpid/dispatch/server.h>
+#include <qpid/dispatch/user_fd.h>
+#include <qpid/dispatch/threading.h>
+#include <qpid/dispatch/log.h>
+
+#define THREAD_COUNT 4
+#define OCTET_COUNT 100
+
+static sys_mutex_t *test_lock;
+
+static void *expected_context;
+static int call_count;
+static int threads_seen[THREAD_COUNT];
+static char stored_error[512];
+
+static int write_count;
+static int read_count;
+static int fd[2];
+static dx_user_fd_t *ufd_write;
+static dx_user_fd_t *ufd_read;
+
+
+static void thread_start(void *context, int thread_id)
+{
+ sys_mutex_lock(test_lock);
+ if (context != expected_context && !stored_error[0])
+ sprintf(stored_error, "Unexpected Context Value: %lx", (long) context);
+ if (thread_id >= THREAD_COUNT && !stored_error[0])
+ sprintf(stored_error, "Thread_ID too large: %d", thread_id);
+ if (thread_id < 0 && !stored_error[0])
+ sprintf(stored_error, "Thread_ID negative: %d", thread_id);
+
+ call_count++;
+ if (thread_id >= 0 && thread_id < THREAD_COUNT)
+ threads_seen[thread_id]++;
+
+ if (call_count == THREAD_COUNT)
+ dx_server_stop();
+ sys_mutex_unlock(test_lock);
+}
+
+
+static int conn_handler(void *context, dx_conn_event_t event, dx_connection_t *conn)
+{
+ return 0;
+}
+
+
+static void ufd_handler(void *context, dx_user_fd_t *ufd)
+{
+ long dir = (long) context;
+ char buffer;
+ ssize_t len;
+ static int in_read = 0;
+ static int in_write = 0;
+
+ if (dir == 0) { // READ
+ in_read++;
+ assert(in_read == 1);
+ if (!dx_user_fd_is_readable(ufd_read)) {
+ sprintf(stored_error, "Expected Readable");
+ dx_server_stop();
+ } else {
+ len = read(fd[0], &buffer, 1);
+ if (len == 1) {
+ read_count++;
+ if (read_count == OCTET_COUNT)
+ dx_server_stop();
+ }
+ dx_user_fd_activate_read(ufd_read);
+ }
+ in_read--;
+ } else { // WRITE
+ in_write++;
+ assert(in_write == 1);
+ if (!dx_user_fd_is_writeable(ufd_write)) {
+ sprintf(stored_error, "Expected Writable");
+ dx_server_stop();
+ } else {
+ write(fd[1], "X", 1);
+
+ write_count++;
+ if (write_count < OCTET_COUNT)
+ dx_user_fd_activate_write(ufd_write);
+ }
+ in_write--;
+ }
+}
+
+
+static void fd_test_start(void *context)
+{
+ dx_user_fd_activate_read(ufd_read);
+}
+
+
+static char* test_start_handler(void *context)
+{
+ int i;
+
+ dx_server_initialize(THREAD_COUNT);
+
+ expected_context = (void*) 0x00112233;
+ stored_error[0] = 0x0;
+ call_count = 0;
+ for (i = 0; i < THREAD_COUNT; i++)
+ threads_seen[i] = 0;
+
+ dx_server_set_conn_handler(conn_handler);
+ dx_server_set_start_handler(thread_start, expected_context);
+ dx_server_run();
+ dx_server_finalize();
+
+ if (stored_error[0]) return stored_error;
+ if (call_count != THREAD_COUNT) return "Incorrect number of thread-start callbacks";
+ for (i = 0; i < THREAD_COUNT; i++)
+ if (threads_seen[i] != 1) return "Incorrect count on one thread ID";
+
+ return 0;
+}
+
+
+static char* test_user_fd(void *context)
+{
+ int res;
+ dx_timer_t *timer;
+
+ dx_server_initialize(THREAD_COUNT);
+ dx_server_set_conn_handler(conn_handler);
+ dx_server_set_user_fd_handler(ufd_handler);
+ timer = dx_timer(fd_test_start, 0);
+ dx_timer_schedule(timer, 0);
+
+ stored_error[0] = 0x0;
+ res = pipe2(fd, O_NONBLOCK);
+ if (res != 0) return "Error creating pipe2";
+
+ ufd_write = dx_user_fd(fd[1], (void*) 1);
+ ufd_read = dx_user_fd(fd[0], (void*) 0);
+
+ dx_server_run();
+ dx_timer_free(timer);
+ dx_server_finalize();
+ close(fd[0]);
+ close(fd[1]);
+
+ if (stored_error[0]) return stored_error;
+ if (write_count - OCTET_COUNT > 2) sprintf(stored_error, "Excessively high Write Count: %d", write_count);
+ if (read_count != OCTET_COUNT) sprintf(stored_error, "Incorrect Read Count: %d", read_count);;
+
+ if (stored_error[0]) return stored_error;
+ return 0;
+}
+
+
+int server_tests(void)
+{
+ int result = 0;
+ test_lock = sys_mutex();
+ dx_log_set_mask(LOG_NONE);
+
+ TEST_CASE(test_start_handler, 0);
+ TEST_CASE(test_user_fd, 0);
+
+ sys_mutex_free(test_lock);
+ return result;
+}
+
diff --git a/extras/dispatch/tests/test_case.h b/extras/dispatch/tests/test_case.h
new file mode 100644
index 0000000000..6e36b440a5
--- /dev/null
+++ b/extras/dispatch/tests/test_case.h
@@ -0,0 +1,36 @@
+#ifndef _nexus_test_case_h_
+#define _nexus_test_case_h_ 1
+/*
+ * 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.
+ */
+
+typedef char* (*testcase_t)(void *context);
+
+#define TEST_CASE(T,C) do { \
+ char *r = T(C); \
+ printf("Test Case %s.%s: ", __FUNCTION__, #T); \
+ if (r) { \
+ printf("FAIL: %s\n", r); \
+ result++; \
+ } else \
+ printf("PASS\n"); \
+} while(0);
+
+
+#endif
+
diff --git a/extras/dispatch/tests/timer_test.c b/extras/dispatch/tests/timer_test.c
new file mode 100644
index 0000000000..3d199f2aa2
--- /dev/null
+++ b/extras/dispatch/tests/timer_test.c
@@ -0,0 +1,388 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+#include <qpid/dispatch/timer.h>
+#include "alloc_private.h"
+#include "timer_private.h"
+#include "test_case.h"
+#include <qpid/dispatch/threading.h>
+
+
+static unsigned long fire_mask;
+static dx_timer_list_t pending_timers;
+static sys_mutex_t *lock;
+static long time;
+static dx_timer_t *timers[16];
+
+
+void dx_server_timer_pending_LH(dx_timer_t *timer)
+{
+ DEQ_INSERT_TAIL(pending_timers, timer);
+}
+
+
+void dx_server_timer_cancel_LH(dx_timer_t *timer)
+{
+ if (timer->state == TIMER_PENDING)
+ DEQ_REMOVE(pending_timers, timer);
+}
+
+
+static int fire_head()
+{
+ sys_mutex_lock(lock);
+ int result = DEQ_SIZE(pending_timers);
+ dx_timer_t *timer = DEQ_HEAD(pending_timers);
+ if (timer) {
+ DEQ_REMOVE_HEAD(pending_timers);
+ dx_timer_idle_LH(timer);
+ fire_mask |= (unsigned long) timer->context;
+ }
+ sys_mutex_unlock(lock);
+ return result;
+}
+
+
+static char* test_quiet(void *context)
+{
+ fire_mask = 0;
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+
+ while(fire_head());
+
+ if (fire_mask != 0)
+ return "Expected zero timers fired";
+ return 0;
+}
+
+static char* test_immediate(void *context)
+{
+ while(fire_head());
+ fire_mask = 0;
+
+ dx_timer_schedule(timers[0], 0);
+
+ if (fire_mask != 0) return "Premature firing";
+ if (fire_head() > 1) return "Too many firings";
+ if (fire_mask != 1) return "Incorrect fire mask";
+
+ return 0;
+}
+
+
+static char* test_immediate_plus_delayed(void *context)
+{
+ while(fire_head());
+ fire_mask = 0;
+
+ dx_timer_schedule(timers[0], 0);
+ dx_timer_schedule(timers[1], 5);
+
+ if (fire_mask != 0) return "Premature firing";
+ if (fire_head() > 1) return "Too many firings";
+ if (fire_mask != 1) return "Incorrect fire mask 1";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ time += 8;
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+
+ if (fire_head() < 1) return "Delayed Failed to fire";
+ if (fire_mask != 3) return "Incorrect fire mask 3";
+
+ return 0;
+}
+
+
+static char* test_single(void *context)
+{
+ while(fire_head());
+ fire_mask = 0;
+
+ dx_timer_schedule(timers[0], 2);
+ if (fire_head() > 0) return "Premature firing 1";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ if (fire_head() > 0) return "Premature firing 2";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ if (fire_head() < 1) return "Failed to fire";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ if (fire_head() != 0) return "Spurious fires";
+
+ if (fire_mask != 1) return "Incorrect fire mask";
+ if (timers[0]->state != TIMER_IDLE) return "Expected idle timer state";
+
+ return 0;
+}
+
+
+static char* test_two_inorder(void *context)
+{
+ while(fire_head());
+ fire_mask = 0;
+
+ dx_timer_schedule(timers[0], 2);
+ dx_timer_schedule(timers[1], 4);
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ int count = fire_head();
+ if (count < 1) return "First failed to fire";
+ if (count > 1) return "Second fired prematurely";
+ if (fire_mask != 1) return "Incorrect fire mask 1";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ if (fire_head() < 1) return "Second failed to fire";
+ if (fire_mask != 3) return "Incorrect fire mask 3";
+
+ return 0;
+}
+
+
+static char* test_two_reverse(void *context)
+{
+ while(fire_head());
+ fire_mask = 0;
+
+ dx_timer_schedule(timers[0], 4);
+ dx_timer_schedule(timers[1], 2);
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ int count = fire_head();
+ if (count < 1) return "First failed to fire";
+ if (count > 1) return "Second fired prematurely";
+ if (fire_mask != 2) return "Incorrect fire mask 2";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ if (fire_head() < 1) return "Second failed to fire";
+ if (fire_mask != 3) return "Incorrect fire mask 3";
+
+ return 0;
+}
+
+
+static char* test_two_duplicate(void *context)
+{
+ while(fire_head());
+ fire_mask = 0;
+
+ dx_timer_schedule(timers[0], 2);
+ dx_timer_schedule(timers[1], 2);
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ int count = fire_head();
+ if (count != 2) return "Expected two firings";
+ fire_head();
+ if (fire_mask != 3) return "Incorrect fire mask 3";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ if (fire_head() > 0) return "Spurious timer fires";
+
+ return 0;
+}
+
+
+static char* test_separated(void *context)
+{
+ int count;
+
+ while(fire_head());
+ fire_mask = 0;
+
+ dx_timer_schedule(timers[0], 2);
+ dx_timer_schedule(timers[1], 4);
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ count = fire_head();
+ if (count < 1) return "First failed to fire";
+ if (count > 1) return "Second fired prematurely";
+ if (fire_mask != 1) return "Incorrect fire mask 1";
+
+ dx_timer_schedule(timers[2], 2);
+ dx_timer_schedule(timers[3], 4);
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ count = fire_head();
+ fire_head();
+ if (count < 1) return "Second failed to fire";
+ if (count < 2) return "Third failed to fire";
+ if (fire_mask != 7) return "Incorrect fire mask 7";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ count = fire_head();
+ if (count < 1) return "Fourth failed to fire";
+ if (fire_mask != 15) return "Incorrect fire mask 15";
+
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ count = fire_head();
+ if (count > 0) return "Spurious fire";
+
+ return 0;
+}
+
+
+static char* test_big(void *context)
+{
+ while(fire_head());
+ fire_mask = 0;
+
+ long durations[16] =
+ { 5, 8, 7, 6,
+ 14, 10, 16, 15,
+ 11, 12, 9, 12,
+ 1, 2, 3, 4};
+ unsigned long masks[18] = {
+ 0x1000,
+ 0x3000,
+ 0x7000,
+ 0xf000,
+ 0xf001,
+ 0xf009,
+ 0xf00d,
+ 0xf00f,
+ 0xf40f,
+ 0xf42f,
+ 0xf52f,
+ 0xff2f,
+ 0xff2f,
+ 0xff3f,
+ 0xffbf,
+ 0xffff,
+ 0xffff,
+ 0xffff
+ };
+
+ int i;
+ for (i = 0; i < 16; i++)
+ dx_timer_schedule(timers[i], durations[i]);
+ for (i = 0; i < 18; i++) {
+ sys_mutex_lock(lock);
+ dx_timer_visit_LH(time++);
+ sys_mutex_unlock(lock);
+ while(fire_head());
+ if (fire_mask != masks[i]) {
+ static char error[100];
+ sprintf(error, "Iteration %d: expected mask %04lx, got %04lx", i, masks[i], fire_mask);
+ return error;
+ }
+ }
+
+ return 0;
+}
+
+
+int timer_tests(void)
+{
+ int result = 0;
+ dx_alloc_initialize();
+
+ fire_mask = 0;
+ DEQ_INIT(pending_timers);
+ lock = sys_mutex();
+ dx_timer_initialize(lock);
+ time = 1;
+
+ timers[0] = dx_timer(0, (void*) 0x00000001);
+ timers[1] = dx_timer(0, (void*) 0x00000002);
+ timers[2] = dx_timer(0, (void*) 0x00000004);
+ timers[3] = dx_timer(0, (void*) 0x00000008);
+ timers[4] = dx_timer(0, (void*) 0x00000010);
+ timers[5] = dx_timer(0, (void*) 0x00000020);
+ timers[6] = dx_timer(0, (void*) 0x00000040);
+ timers[7] = dx_timer(0, (void*) 0x00000080);
+ timers[8] = dx_timer(0, (void*) 0x00000100);
+ timers[9] = dx_timer(0, (void*) 0x00000200);
+ timers[10] = dx_timer(0, (void*) 0x00000400);
+ timers[11] = dx_timer(0, (void*) 0x00000800);
+ timers[12] = dx_timer(0, (void*) 0x00001000);
+ timers[13] = dx_timer(0, (void*) 0x00002000);
+ timers[14] = dx_timer(0, (void*) 0x00004000);
+ timers[15] = dx_timer(0, (void*) 0x00008000);
+
+ TEST_CASE(test_quiet, 0);
+ TEST_CASE(test_immediate, 0);
+ TEST_CASE(test_immediate_plus_delayed, 0);
+ TEST_CASE(test_single, 0);
+ TEST_CASE(test_two_inorder, 0);
+ TEST_CASE(test_two_reverse, 0);
+ TEST_CASE(test_two_duplicate, 0);
+ TEST_CASE(test_separated, 0);
+ TEST_CASE(test_big, 0);
+
+ int i;
+ for (i = 0; i < 16; i++)
+ dx_timer_free(timers[i]);
+
+ dx_timer_finalize();
+
+ return result;
+}
+
diff --git a/extras/dispatch/tests/tool_test.c b/extras/dispatch/tests/tool_test.c
new file mode 100644
index 0000000000..7923ee3381
--- /dev/null
+++ b/extras/dispatch/tests/tool_test.c
@@ -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.
+ */
+
+#include "test_case.h"
+#include <stdio.h>
+#include <string.h>
+#include <qpid/dispatch/ctools.h>
+
+typedef struct item_t {
+ DEQ_LINKS(struct item_t);
+ char letter;
+} item_t;
+
+DEQ_DECLARE(item_t, item_list_t);
+
+
+static char* list_well_formed(item_list_t list, char *key)
+{
+ item_t *ptr;
+ item_t *last = 0;
+ int size = DEQ_SIZE(list);
+ int count = 0;
+ char str[32];
+
+ ptr = DEQ_HEAD(list);
+ while (ptr) {
+ str[count] = ptr->letter;
+ count++;
+ if (DEQ_PREV(ptr) != last) return "Corrupt previous link";
+ last = ptr;
+ ptr = DEQ_NEXT(ptr);
+ }
+ str[count] = '\0';
+ if (strcmp(str, key) != 0) return "Invalid key";
+
+ if (count != size) return "Size different from number of items (forward)";
+
+ count = 0;
+ last = 0;
+ ptr = DEQ_TAIL(list);
+ while (ptr) {
+ count++;
+ if (DEQ_NEXT(ptr) != last) return "Corrupt next link";
+ last = ptr;
+ ptr = DEQ_PREV(ptr);
+ }
+
+ if (count != size) return "Size different from number of items (backward)";
+
+ return 0;
+}
+
+
+static char* test_deq_basic(void *context)
+{
+ item_list_t list;
+ item_t item[10];
+ item_t *ptr;
+ int idx;
+ char *subtest;
+
+ DEQ_INIT(list);
+ if (DEQ_SIZE(list) != 0) return "Expected zero initial size";
+
+ for (idx = 0; idx < 10; idx++) {
+ DEQ_ITEM_INIT(&item[idx]);
+ item[idx].letter = 'A' + idx;
+ DEQ_INSERT_TAIL(list, &item[idx]);
+ }
+ if (DEQ_SIZE(list) != 10) return "Expected 10 items in list";
+
+ ptr = DEQ_HEAD(list);
+ if (!ptr) return "Expected valid head item";
+ if (DEQ_PREV(ptr)) return "Head item has non-null previous link";
+ if (ptr->letter != 'A') return "Expected item A at the head";
+ if (DEQ_NEXT(ptr) == 0) return "Head item has null next link";
+ subtest = list_well_formed(list, "ABCDEFGHIJ");
+ if (subtest) return subtest;
+
+ DEQ_REMOVE_HEAD(list);
+ if (DEQ_SIZE(list) != 9) return "Expected 9 items in list";
+ ptr = DEQ_HEAD(list);
+ if (ptr->letter != 'B') return "Expected item B at the head";
+ subtest = list_well_formed(list, "BCDEFGHIJ");
+ if (subtest) return subtest;
+
+ DEQ_REMOVE_TAIL(list);
+ if (DEQ_SIZE(list) != 8) return "Expected 8 items in list";
+ ptr = DEQ_TAIL(list);
+ if (ptr->letter != 'I') return "Expected item I at the tail";
+ subtest = list_well_formed(list, "BCDEFGHI");
+ if (subtest) return subtest;
+
+ DEQ_REMOVE(list, &item[4]);
+ if (DEQ_SIZE(list) != 7) return "Expected 7 items in list";
+ subtest = list_well_formed(list, "BCDFGHI");
+ if (subtest) return subtest;
+
+ DEQ_REMOVE(list, &item[1]);
+ if (DEQ_SIZE(list) != 6) return "Expected 6 items in list";
+ subtest = list_well_formed(list, "CDFGHI");
+ if (subtest) return subtest;
+
+ DEQ_REMOVE(list, &item[8]);
+ if (DEQ_SIZE(list) != 5) return "Expected 5 items in list";
+ subtest = list_well_formed(list, "CDFGH");
+ if (subtest) return subtest;
+
+ DEQ_INSERT_HEAD(list, &item[8]);
+ if (DEQ_SIZE(list) != 6) return "Expected 6 items in list";
+ ptr = DEQ_HEAD(list);
+ if (ptr->letter != 'I') return "Expected item I at the head";
+ subtest = list_well_formed(list, "ICDFGH");
+ if (subtest) return subtest;
+
+ DEQ_INSERT_AFTER(list, &item[4], &item[7]);
+ if (DEQ_SIZE(list) != 7) return "Expected 7 items in list";
+ ptr = DEQ_TAIL(list);
+ if (ptr->letter != 'E') return "Expected item E at the head";
+ subtest = list_well_formed(list, "ICDFGHE");
+ if (subtest) return subtest;
+
+ DEQ_INSERT_AFTER(list, &item[1], &item[5]);
+ if (DEQ_SIZE(list) != 8) return "Expected 8 items in list";
+ subtest = list_well_formed(list, "ICDFBGHE");
+ if (subtest) return subtest;
+
+ if (item[0].prev || item[0].next) return "Unlisted item A has non-null pointers";
+ if (item[9].prev || item[9].next) return "Unlisted item J has non-null pointers";
+
+ return 0;
+}
+
+
+int tool_tests(void)
+{
+ int result = 0;
+
+ TEST_CASE(test_deq_basic, 0);
+
+ return result;
+}
+
diff --git a/extras/qmf/setup.py b/extras/qmf/setup.py
index fcfd2f8a30..db62ddba99 100755
--- a/extras/qmf/setup.py
+++ b/extras/qmf/setup.py
@@ -20,7 +20,7 @@
from distutils.core import setup
setup(name="qpid-qmf",
- version="0.19",
+ version="0.21",
author="Apache Qpid",
author_email="dev@qpid.apache.org",
packages=["qmf"],
diff --git a/extras/qmf/src/py/qmf/console.py b/extras/qmf/src/py/qmf/console.py
index af5d1da5ca..0a30176ed5 100644
--- a/extras/qmf/src/py/qmf/console.py
+++ b/extras/qmf/src/py/qmf/console.py
@@ -25,6 +25,7 @@ import qpid
import struct
import socket
import re
+import sys
from qpid.datatypes import UUID
from qpid.datatypes import timestamp
from qpid.datatypes import datetime
@@ -2423,11 +2424,21 @@ class Broker(Thread):
oldTimeout = sock.gettimeout()
sock.settimeout(self.connTimeout)
connSock = None
+ force_blocking = False
if self.ssl:
+ # Bug (QPID-4337): the "old" implementation of python SSL
+ # fails if the socket is set to non-blocking (which settimeout()
+ # may change).
+ if sys.version_info[:2] < (2, 6): # 2.6+ uses openssl - it's ok
+ force_blocking = True
+ sock.setblocking(1)
+ certfile = None
if 'ssl_certfile' in self.connectArgs:
- connSock = ssl(sock, certfile=self.connectArgs['ssl_certfile'])
- else:
- connSock = ssl(sock)
+ certfile = self.connectArgs['ssl_certfile']
+ keyfile = None
+ if 'ssl_keyfile' in self.connectArgs:
+ keyfile = self.connectArgs['ssl_keyfile']
+ connSock = ssl(sock, certfile=certfile, keyfile=keyfile)
else:
connSock = sock
self.conn = Connection(connSock, username=self.authUser, password=self.authPass,
@@ -2438,7 +2449,10 @@ class Broker(Thread):
oldAborted = self.conn.aborted
self.conn.aborted = aborted
self.conn.start()
- sock.settimeout(oldTimeout)
+
+ # Bug (QPID-4337): don't enable non-blocking (timeouts) for old SSL
+ if not force_blocking:
+ sock.settimeout(oldTimeout)
self.conn.aborted = oldAborted
uid = self.conn.user_id
if uid.__class__ == tuple and len(uid) == 2:
diff --git a/gentools/LICENSE b/gentools/LICENSE
deleted file mode 100644
index 43fa6abd19..0000000000
--- a/gentools/LICENSE
+++ /dev/null
@@ -1,202 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- 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.
-
diff --git a/gentools/NOTICE b/gentools/NOTICE
deleted file mode 100644
index 09e9ae4902..0000000000
--- a/gentools/NOTICE
+++ /dev/null
@@ -1,2 +0,0 @@
-This product includes software developed by The Apache Software Foundation (http://www.apache.org/).
-
diff --git a/gentools/README.txt b/gentools/README.txt
deleted file mode 100644
index 94f705b064..0000000000
--- a/gentools/README.txt
+++ /dev/null
@@ -1,61 +0,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.
-================================================================================
-
-AMQP MULTI_VERSION CODE GENERATOR
-
-This directory contains the first part of the new multi-AMQP-version code
-generator. The Java generation is almost complete, C++ will follow.
-
-NOTE: The generator has NOT been integrated into the current build, and is
-included here to run stand-alone for the purposes of review and comment. As
-currently configured, this generator will not interact with any file or
-directory outside of this directory.
-
-To build (from this directory):
-rm org/apache/qpid/gentools/*.class
-javac org/apache/qpid/gentools/Main.java
-
-Make sure you are using Sun's JDK1.5.0; Eclipse and gcj do not work.
-
-To run (from this directory):
-java org/apache/qpid/gentools/Main -j [xml_spec_file, ...]
-
-XML test files are located in the xml-src directory. Pay attention to the
-Basic class and Basic.Consume method - these were the primary test vehicles
-for this generator. *** NOTE *** These files do not represent any current or
-future version of the AMQP specification - do not use in production!
-
-Folders:
---------
-org/apache/qpid/gentools/: Source.
-xml-src/: Test AMQP specification files.
-templ.java/: Templates for java code generation.
-out.java/: Output folder for generated Java files (will be created with use
- of -j flag on command-line).
-templ.cpp/: (Future:) Templates for C++ code generation.
-out.cpp/: Output folder for generated C++ files (will be created with use
- of -c flag on command-line).
-
-For a more detaild description of the generator, see the Qpid Wiki
-(http://cwiki.apache.org/qpid/multiple-amqp-version-support.html).
-
-Please send comments and bugs to me (kim.vdriet [at] redhat.com) or via the
-Apache Qpid list (dev [at] qpid.apache.org).
-
-Kim van der Riet
diff --git a/gentools/build b/gentools/build
deleted file mode 100755
index a18a984dff..0000000000
--- a/gentools/build
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/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.
-#
-#
-
-
-cd src
-echo "--------- Building gentools ----------"
-echo "Clearing out old build files..."
-for f in org/apache/qpid/gentools/*.class; do
- if [ -e $f ]; then
- rm $f
- fi
-done
-echo "Compiling..."
-javac -source=1.5 -target=1.5 org/apache/qpid/gentools/*.java
-echo "Done. Try it out..."
-java org.apache.qpid.gentools.Main
-echo "--------- Building gentools completed ----------"
-cd ..
diff --git a/gentools/build.xml b/gentools/build.xml
deleted file mode 100644
index f6760a215e..0000000000
--- a/gentools/build.xml
+++ /dev/null
@@ -1,43 +0,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="gentools" default="compile">
- <property name="src" location="src" />
-
- <property name="java.source" value="1.5"/>
- <property name="java.target" value="1.5"/>
-
- <target name="compile">
- <javac srcdir="${src}" source="${java.source}" target="${java.target}" fork="true" debug="on" includeantruntime="false">
- <classpath>
- <fileset dir="${src}/../lib">
- <include name="**/*.jar"/>
- </fileset>
- </classpath>
- </javac>
- </target>
-
- <target name="clean">
- <delete>
- <fileset dir="${src}/org/apache/qpid/gentools" includes="*.class" />
- </delete>
- </target>
-
-</project>
diff --git a/gentools/lib/LICENSE b/gentools/lib/LICENSE
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gentools/lib/LICENSE
+++ /dev/null
diff --git a/gentools/lib/NOTICE b/gentools/lib/NOTICE
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gentools/lib/NOTICE
+++ /dev/null
diff --git a/gentools/lib/README.txt b/gentools/lib/README.txt
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gentools/lib/README.txt
+++ /dev/null
diff --git a/gentools/lib/velocity-1.4.jar b/gentools/lib/velocity-1.4.jar
deleted file mode 100644
index 04ec9d2f85..0000000000
--- a/gentools/lib/velocity-1.4.jar
+++ /dev/null
Binary files differ
diff --git a/gentools/lib/velocity-dep-1.4.jar b/gentools/lib/velocity-dep-1.4.jar
deleted file mode 100644
index 375712b0e8..0000000000
--- a/gentools/lib/velocity-dep-1.4.jar
+++ /dev/null
Binary files differ
diff --git a/gentools/templ.cpp/method/MethodBodyClass.h.tmpl b/gentools/templ.cpp/method/MethodBodyClass.h.tmpl
deleted file mode 100644
index 5819a9cf9c..0000000000
--- a/gentools/templ.cpp/method/MethodBodyClass.h.tmpl
+++ /dev/null
@@ -1,112 +0,0 @@
-&{${CLASS}${METHOD}Body.h}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#ifndef qpid_framing_${CLASS}${METHOD}Body__
-#define qpid_framing_${CLASS}${METHOD}Body__
-
-#include <string>
-#include <sstream>
-
-#include <amqp_types.h>
-#include <AMQMethodBody.h>
-#include <Buffer.h>
-#include <FieldTable.h>
-
-namespace qpid
-{
-namespace framing
-{
-${version_namespace_start}
-
-class ${CLASS}${METHOD}Body : public AMQMethodBody
-{
- // Method field declarations
-
-%{FLIST} ${mb_field_declaration}
-
-
-public:
- typedef boost::shared_ptr<${CLASS}${METHOD}Body> shared_ptr;
-
- // Constructors and destructors
-
-${mb_constructor_with_initializers}
-
- inline ${CLASS}${METHOD}Body(u_int8_t major, u_int8_t minor): AMQMethodBody(major, minor) {}
- inline ${CLASS}${METHOD}Body(ProtocolVersion& version): AMQMethodBody(version) {}
- virtual ~${CLASS}${METHOD}Body() {}
-
- // Attribute get methods
-
-%{FLIST} ${mb_field_get_method}
-
- // Helper methods
-
- inline void print(std::ostream& out) const
- {
- out << "${CLASS}${METHOD}: ";
-%{FLIST} ${mb_field_print}
- }
-
- inline u_int16_t amqpClassId() const
- {
- return ${CLASS_ID_INIT};
- }
-
- inline u_int16_t amqpMethodId() const
- {
- return ${METHOD_ID_INIT};
- }
-
- inline u_int32_t bodySize() const
- {
- u_int32_t size = 0;
-%{FLIST} ${mb_body_size}
- return size;
- }
-
- inline void encodeContent(Buffer&${mb_buffer_param}) const
- {
-%{FLIST} ${mb_encode}
- }
-
- inline void decodeContent(Buffer&${mb_buffer_param})
- {
-%{FLIST} ${mb_decode}
- }
-
-${mb_server_operation_invoke}
-
-}; // class ${CLASS}${METHOD}Body
-
-${version_namespace_end}
-} // namespace framing
-} // namespace qpid
-
-#endif
-
diff --git a/gentools/templ.cpp/model/AMQP_ClientOperations.h.tmpl b/gentools/templ.cpp/model/AMQP_ClientOperations.h.tmpl
deleted file mode 100644
index a9fb0e0f69..0000000000
--- a/gentools/templ.cpp/model/AMQP_ClientOperations.h.tmpl
+++ /dev/null
@@ -1,82 +0,0 @@
-&{AMQP_ClientOperations.h}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#ifndef qpid_framing_AMQP_ClientOperations__
-#define qpid_framing_AMQP_ClientOperations__
-
-#include <sstream>
-
-#include <FieldTable.h>
-#include <ProtocolVersion.h>
-#include <ProtocolVersionException.h>
-
-namespace qpid {
-namespace framing {
-
-class AMQP_ClientProxy;
-
-class AMQP_ClientOperations
-{
-protected:
- ProtocolVersion version;
- AMQP_ClientOperations() {}
-
-public:
- AMQP_ClientOperations(u_int8_t major, u_int8_t minor) : version(major, minor) {}
- AMQP_ClientOperations(ProtocolVersion& version) : version(version) {}
- virtual ~AMQP_ClientOperations() {}
-
- inline u_int8_t getMajor() const { return version.getMajor(); }
- inline u_int8_t getMinor() const { return version.getMinor(); }
- inline const ProtocolVersion& getVersion() const { return version; }
- inline bool isVersion(u_int8_t _major, u_int8_t _minor) const
- {
- return version.equals(_major, _minor);
- }
- inline bool isVersion(ProtocolVersion& _version) const
- {
- return version.equals(_version);
- }
-
- // Include framing constant declarations
- #include <AMQP_Constants.h>
-
- // Inner classes
-
-%{CLIST} ${coh_inner_class}
-
- // Method handler get methods
-
-%{CLIST} ${coh_method_handler_get_method}
-
-}; /* class AMQP_ClientOperations */
-
-} /* namespace framing */
-} /* namespace qpid */
-
-#endif
diff --git a/gentools/templ.cpp/model/AMQP_ClientProxy.cpp.tmpl b/gentools/templ.cpp/model/AMQP_ClientProxy.cpp.tmpl
deleted file mode 100644
index 8cca6e5cec..0000000000
--- a/gentools/templ.cpp/model/AMQP_ClientProxy.cpp.tmpl
+++ /dev/null
@@ -1,52 +0,0 @@
-&{AMQP_ClientProxy.cpp}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#include <sstream>
-
-#include <AMQP_ClientProxy.h>
-#include <AMQFrame.h>
-%{MLIST} ${cpc_method_body_include}
-
-namespace qpid {
-namespace framing {
-
-AMQP_ClientProxy::AMQP_ClientProxy(OutputHandler* out, u_int8_t major, u_int8_t minor) :
-%{CLIST} ${cpc_constructor_initializer}
-
-{}
-
- // Inner class instance get methods
-
-%{CLIST} ${cpc_inner_class_get_method}
-
- // Inner class implementation
-
-%{CLIST} ${cpc_inner_class_impl}
-
-} /* namespace framing */
-} /* namespace qpid */
diff --git a/gentools/templ.cpp/model/AMQP_ClientProxy.h.tmpl b/gentools/templ.cpp/model/AMQP_ClientProxy.h.tmpl
deleted file mode 100644
index 0653ed7186..0000000000
--- a/gentools/templ.cpp/model/AMQP_ClientProxy.h.tmpl
+++ /dev/null
@@ -1,75 +0,0 @@
-&{AMQP_ClientProxy.h}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#ifndef qpid_framing_AMQP_ClientProxy__
-#define qpid_framing_AMQP_ClientProxy__
-
-#include <AMQP_ClientOperations.h>
-#include <FieldTable.h>
-#include <OutputHandler.h>
-
-namespace qpid {
-namespace framing {
-
-class AMQP_ClientProxy : public AMQP_ClientOperations
-{
-private:
-
- ProtocolVersion version;
- OutputHandler* out;
-%{CLIST} ${cph_handler_pointer_defn}
-
-public:
- AMQP_ClientProxy(OutputHandler* out, u_int8_t major, u_int8_t minor);
- ProtocolVersion& getProtocolVersion() {return version;}
- virtual ~AMQP_ClientProxy() {}
-
- // Get methods for handlers
-
-%{CLIST} ${cph_handler_pointer_get_method}
-
- // Inner class definitions
-
-%{CLIST} ${cph_inner_class_defn}
-
-private:
- // Inner class instances
-
-%{CLIST} ${cph_inner_class_instance}
-
-public:
- // Inner class instance get methods
-
-%{CLIST} ${cph_inner_class_get_method}
-
-}; /* class AMQP_ClientProxy */
-
-} /* namespace framing */
-} /* namespace qpid */
-
-#endif
diff --git a/gentools/templ.cpp/model/AMQP_Constants.h.tmpl b/gentools/templ.cpp/model/AMQP_Constants.h.tmpl
deleted file mode 100644
index 4631bc8de6..0000000000
--- a/gentools/templ.cpp/model/AMQP_Constants.h.tmpl
+++ /dev/null
@@ -1,34 +0,0 @@
-&{AMQP_Constants.h}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
- // NOTE: This file is intended to be included within the class structure of both
- // the client and server operations classes. These need to have <sstream> included.
-
- // Constant getValue methods
-
-%{TLIST} ${ch_get_value_method}
- \ No newline at end of file
diff --git a/gentools/templ.cpp/model/AMQP_HighestVersion.h.tmpl b/gentools/templ.cpp/model/AMQP_HighestVersion.h.tmpl
deleted file mode 100644
index 9753b454ba..0000000000
--- a/gentools/templ.cpp/model/AMQP_HighestVersion.h.tmpl
+++ /dev/null
@@ -1,42 +0,0 @@
-&{AMQP_HighestVersion.h}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-#ifndef qpid_framing_highestProtocolVersion__
-#define qpid_framing_highestProtocolVersion__
-
-#include <ProtocolVersion.h>
-
-
-namespace qpid {
-namespace framing {
-
-static ProtocolVersion highestProtocolVersion(${hv_latest_major}, ${hv_latest_minor});
-
-} /* namespace framing */
-} /* namespace qpid */
-
-#endif
diff --git a/gentools/templ.cpp/model/AMQP_MethodVersionMap.cpp.tmpl b/gentools/templ.cpp/model/AMQP_MethodVersionMap.cpp.tmpl
deleted file mode 100644
index dc2a890c88..0000000000
--- a/gentools/templ.cpp/model/AMQP_MethodVersionMap.cpp.tmpl
+++ /dev/null
@@ -1,62 +0,0 @@
-&{AMQP_MethodVersionMap.cpp}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#include <sstream>
-
-#include <AMQP_MethodVersionMap.h>
-
-namespace qpid
-{
-namespace framing
-{
-
-AMQP_MethodVersionMap::AMQP_MethodVersionMap()
-{
-%{CLIST} ${mc_create_method_body_map_entry}
-}
-
-AMQMethodBody* AMQP_MethodVersionMap::createMethodBody(u_int16_t classId, u_int16_t methodId, u_int8_t major, u_int8_t minor)
-{
- iterator itr = find(createMapKey(classId, methodId, major, minor));
- if (itr == end())
- {
- std::stringstream ss;
- ss << "Unable to find MethodBody class for classId = " << classId << ", methodId = " <<
- methodId << ", AMQ protocol version = " << major << "-" << minor << ".";
- throw ProtocolVersionException(ss.str());
- }
- return (itr->second)(major, minor);
-}
-
-u_int64_t AMQP_MethodVersionMap::createMapKey(u_int16_t classId, u_int16_t methodId, u_int8_t major, u_int8_t minor)
-{
- return ((u_int64_t)classId<<48) + ((u_int64_t)methodId<<32) + ((u_int64_t)major<<16) + minor;
-}
-
-} /* namespace framing */
-} /* namespace qpid */
diff --git a/gentools/templ.cpp/model/AMQP_MethodVersionMap.h.tmpl b/gentools/templ.cpp/model/AMQP_MethodVersionMap.h.tmpl
deleted file mode 100644
index c197871d4b..0000000000
--- a/gentools/templ.cpp/model/AMQP_MethodVersionMap.h.tmpl
+++ /dev/null
@@ -1,57 +0,0 @@
-&{AMQP_MethodVersionMap.h}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#ifndef qpid_framing_AMQP_MethodVersionMap__
-#define qpid_framing_AMQP_MethodVersionMap__
-
-#include <map>
-#include <AMQMethodBody.h>
-
-%{MLIST} ${mc_method_body_include}
-
-namespace qpid
-{
-namespace framing
-{
-
-template <class T> AMQMethodBody* createMethodBodyFn(u_int8_t major, u_int8_t minor) { return new T(major, minor); }
-typedef AMQMethodBody* (*fnPtr)(u_int8_t, u_int8_t);
-
-class AMQP_MethodVersionMap: public std::map<u_int64_t, fnPtr>
-{
-protected:
- u_int64_t createMapKey(u_int16_t classId, u_int16_t methodId, u_int8_t major, u_int8_t minor);
-public:
- AMQP_MethodVersionMap();
- AMQMethodBody* createMethodBody(u_int16_t classId, u_int16_t methodId, u_int8_t major, u_int8_t minor);
-};
-
-} /* namespace framing */
-} /* namespace qpid */
-
-#endif
diff --git a/gentools/templ.cpp/model/AMQP_ServerOperations.h.tmpl b/gentools/templ.cpp/model/AMQP_ServerOperations.h.tmpl
deleted file mode 100644
index e87723667b..0000000000
--- a/gentools/templ.cpp/model/AMQP_ServerOperations.h.tmpl
+++ /dev/null
@@ -1,83 +0,0 @@
-&{AMQP_ServerOperations.h}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#ifndef qpid_framing_AMQP_ServerOperations__
-#define qpid_framing_AMQP_ServerOperations__
-
-#include <sstream>
-
-#include <FieldTable.h>
-#include <ProtocolVersion.h>
-#include <ProtocolVersionException.h>
-
-namespace qpid {
-namespace framing {
-
-class AMQP_ServerProxy;
-class AMQP_ClientProxy;
-
-class AMQP_ServerOperations
-{
-protected:
- ProtocolVersion version;
- AMQP_ServerOperations() {}
-
-public:
- AMQP_ServerOperations(u_int8_t major, u_int8_t minor) : version(major, minor) {}
- AMQP_ServerOperations(ProtocolVersion& version) : version(version) {}
- virtual ~AMQP_ServerOperations() {}
-
- inline u_int8_t getMajor() const { return version.getMajor(); }
- inline u_int8_t getMinor() const { return version.getMinor(); }
- inline const ProtocolVersion& getVersion() const { return version; }
- inline bool isVersion(u_int8_t _major, u_int8_t _minor) const
- {
- return version.equals(_major, _minor);
- }
- inline bool isVersion(ProtocolVersion& _version) const
- {
- return version.equals(_version);
- }
-
- // Include framing constant declarations
- #include <AMQP_Constants.h>
-
- // Inner classes
-
-%{CLIST} ${soh_inner_class}
-
- // Method handler get methods
-
-%{CLIST} ${soh_method_handler_get_method}
-
-}; /* class AMQP_ServerOperations */
-
-} /* namespace framing */
-} /* namespace qpid */
-
-#endif
diff --git a/gentools/templ.cpp/model/AMQP_ServerProxy.cpp.tmpl b/gentools/templ.cpp/model/AMQP_ServerProxy.cpp.tmpl
deleted file mode 100644
index cce369f98b..0000000000
--- a/gentools/templ.cpp/model/AMQP_ServerProxy.cpp.tmpl
+++ /dev/null
@@ -1,51 +0,0 @@
-&{AMQP_ServerProxy.cpp}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#include <sstream>
-
-#include <AMQP_ServerProxy.h>
-#include <AMQFrame.h>
-%{MLIST} ${spc_method_body_include}
-
-namespace qpid {
-namespace framing {
-
-AMQP_ServerProxy::AMQP_ServerProxy(OutputHandler* out, u_int8_t major, u_int8_t minor) :
-%{CLIST} ${spc_constructor_initializer}
-{}
-
- // Inner class instance get methods
-
-%{CLIST} ${spc_inner_class_get_method}
-
- // Inner class implementation
-
-%{CLIST} ${spc_inner_class_impl}
-
-} /* namespace framing */
-} /* namespace qpid */
diff --git a/gentools/templ.cpp/model/AMQP_ServerProxy.h.tmpl b/gentools/templ.cpp/model/AMQP_ServerProxy.h.tmpl
deleted file mode 100644
index fab29f2c60..0000000000
--- a/gentools/templ.cpp/model/AMQP_ServerProxy.h.tmpl
+++ /dev/null
@@ -1,74 +0,0 @@
-&{AMQP_ServerProxy.h}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-#ifndef qpid_framing_AMQP_ServerProxy__
-#define qpid_framing_AMQP_ServerProxy__
-
-#include <AMQP_ServerOperations.h>
-#include <FieldTable.h>
-#include <OutputHandler.h>
-
-namespace qpid {
-namespace framing {
-
-class AMQP_ServerProxy : public AMQP_ServerOperations
-{
-private:
- ProtocolVersion version;
- OutputHandler* out;
-%{CLIST} ${sph_handler_pointer_defn}
-
-public:
- AMQP_ServerProxy(OutputHandler* out, u_int8_t major, u_int8_t minor);
- ProtocolVersion& getProtocolVersion() {return version;}
- virtual ~AMQP_ServerProxy() {}
-
- // Get methods for handlers
-
-%{CLIST} ${sph_handler_pointer_get_method}
-
- // Inner class definitions
-
-%{CLIST} ${sph_inner_class_defn}
-
-private:
- // Inner class instances
-
-%{CLIST} ${sph_inner_class_instance}
-
-public:
- // Inner class instance get methods
-
-%{CLIST} ${sph_inner_class_get_method}
-
-}; /* class AMQP_ServerProxy */
-
-} /* namespace framing */
-} /* namespace qpid */
-
-#endif
diff --git a/gentools/templ.java/PropertyContentHeaderClass.tmpl b/gentools/templ.java/PropertyContentHeaderClass.tmpl
deleted file mode 100644
index ab6406b1fe..0000000000
--- a/gentools/templ.java/PropertyContentHeaderClass.tmpl
+++ /dev/null
@@ -1,208 +0,0 @@
-&{${CLASS}ContentHeaderProperties.java}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-package org.apache.qpid.framing;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.mina.common.ByteBuffer;
-
-public class ${CLASS}ContentHeaderProperties implements ContentHeaderProperties
-{
- private static final Logger logger = LoggerFactory.getLogger(BasicContentHeaderProperties.class);
-
- /**
- * We store the encoded form when we decode the content header so that if we need to
- * write it out without modifying it we can do so without incurring the expense of
- * reencoding it.
- */
- private byte[] encodedBuffer;
-
- /**
- * Flag indicating whether the entire content header has been decoded yet.
- */
- private boolean decodedFlag = true;
-
- /**
- * We have some optimisations for partial decoding for maximum performance. The
- * headers are used in the broker for routing in some cases so we can decode that
- * separately.
- */
- private boolean decodedHeadersFlag = true;
-
- /**
- * We have some optimisations for partial decoding for maximum performance. The
- * content type is used by all clients to determine the message type.
- */
- private boolean decodedContentTypeFlag = true;
-
- /**
- * AMQP major and minor version of this instance.
- */
- private byte major;
- private byte minor;
-
- /**
- * Property flags.
- */
- ${pch_property_flags_declare}
-
- // Header fields from specification
-%{FLIST} ${field_declaration}
-
- /**
- * Constructor
- */
- public ${CLASS}ContentHeaderProperties(byte major, byte minor)
- {
- this.major = major;
- this.minor = minor;
-
- // Although one flag is initialized per property, the flags are used
- // in ordinal order of the AMQP version represented by this instance,
- // thus the number of flags actually used may be less than the total
- // number defined.
- ${pch_property_flags_initializer}
- }
-
- public int getPropertyListSize()
- {
- if (encodedBuffer != null)
- {
- return encodedBuffer.length;
- }
- else
- {
- int size = 0;
-%{FLIST} ${pch_field_list_size}
- return size;
- }
- }
-
- private void clearEncodedForm()
- {
- if (!decodedFlag && encodedBuffer != null)
- {
- //decode();
- }
- encodedBuffer = null;
- }
-
- public void setPropertyFlags(int[] compactPropertyFlags)
- throws AMQProtocolVersionException
- {
- clearEncodedForm();
-${pch_compact_property_flags_check}
-%{FLIST} ${pch_set_compact_property_flags}
- }
-
- public int[] getPropertyFlags()
- {
- int[] compactPropertyFlags = new int[] { 0 };
-${pch_compact_property_flags_initializer}
-%{FLIST} ${pch_get_compact_property_flags}
- return compactPropertyFlags;
- }
-
- public void writePropertyListPayload(ByteBuffer buffer)
- {
- if (encodedBuffer != null)
- {
- buffer.put(encodedBuffer);
- }
- else
- {
-%{FLIST} ${pch_field_list_payload}
- }
- }
-
- public void populatePropertiesFromBuffer(ByteBuffer buffer, int[] propertyFlags, int size)
- throws AMQFrameDecodingException, AMQProtocolVersionException
- {
- setPropertyFlags(propertyFlags);
-
- if (logger.isDebugEnabled())
- {
- logger.debug("Property flags: " + propertyFlags);
- }
- decode(buffer);
- /*encodedBuffer = new byte[size];
- buffer.get(encodedBuffer, 0, size);
- decodedFlag = false;
- decodedHeadersFlag = false;
- decodedContentTypeFlag = false;*/
- }
-
- private void decode(ByteBuffer buffer)
- {
- //ByteBuffer buffer = ByteBuffer.wrap(encodedBuffer);
- int pos = buffer.position();
- try
- {
-%{FLIST} ${pch_field_list_decode}
- // This line does nothing, but prevents a compiler error (Exception not thrown)
- // if this block is empty.
- if (false) throw new AMQFrameDecodingException("");
- }
- catch (AMQFrameDecodingException e)
- {
- throw new RuntimeException("Error in content header data: " + e);
- }
-
- final int endPos = buffer.position();
- buffer.position(pos);
- final int len = endPos - pos;
- encodedBuffer = new byte[len];
- final int limit = buffer.limit();
- buffer.limit(endPos);
- buffer.get(encodedBuffer, 0, len);
- buffer.limit(limit);
- buffer.position(endPos);
- decodedFlag = true;
- }
-
- private void decodeIfNecessary()
- {
- if (!decodedFlag)
- {
- //decode();
- }
- }
-
- // Field clear methods
-
-%{FLIST} ${pch_field_clear_methods}
-
- // Field get methods
-
-%{FLIST} ${pch_field_get_methods}
-
- // Field set methods
-
-%{FLIST} ${pch_field_set_methods}
-}
diff --git a/gentools/templ.java/method/version/MethodBodyClass.vm b/gentools/templ.java/method/version/MethodBodyClass.vm
deleted file mode 100644
index bb62438a65..0000000000
--- a/gentools/templ.java/method/version/MethodBodyClass.vm
+++ /dev/null
@@ -1,190 +0,0 @@
-#macro( UpperCamel $name )
-#set( $name = "${name.substring(0,1).toUpperCase()}${name.substring(1)}" )
-#end
-#macro( toUpperCamel $name )${name.substring(0,1).toUpperCase()}${name.substring(1)}#end
-
-
-
-#set( $amqp_ClassName = $amqpClass.Name)
-#UpperCamel( $amqp_ClassName )
-#set( $amqp_MethodName = $amqpMethod.Name )
-#UpperCamel( $amqp_MethodName )
-#set( $javaClassName = "${amqp_ClassName}${amqp_MethodName}BodyImpl" )
-#set( $interfaceName = "${amqp_ClassName}${amqp_MethodName}Body" )
-#set( $amqpPackageName = "amqp_$version.getMajor()_$version.getMinor()" )
-
-#set( $filename = "${amqpPackageName}/${javaClassName}.java")
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${generator} - do not modify.
- * Supported AMQP version:
- * $version.getMajor()-$version.getMinor()
- */
-
-#set( $clazz = $amqpClass.asSingleVersionClass( $version ) )
-#set( $method = $amqpMethod.asSingleVersionMethod( $version ) )
-
-package org.apache.qpid.framing.amqp_$version.getMajor()_$version.getMinor();
-
-import java.util.HashMap;
-
-import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.framing.*;
-
-public class ${javaClassName} extends AMQMethodBody_$version.getMajor()_$version.getMinor() implements $interfaceName
-{
- private static final AMQMethodBodyInstanceFactory FACTORY_INSTANCE = new AMQMethodBodyInstanceFactory()
- {
- public AMQMethodBody newInstance(ByteBuffer in, long size) throws AMQFrameDecodingException
- {
- return new ${javaClassName}(in);
- }
-
-
- };
-
-
- public static AMQMethodBodyInstanceFactory getFactory()
- {
- return FACTORY_INSTANCE;
- }
-
- public static int CLASS_ID = $clazz.ClassId;
-
- public static int METHOD_ID = $method.MethodId;
-
-
-
- // Fields declared in specification
-#foreach( $field in $method.ConsolidatedFields )
- private final $field.NativeType _$field.getName(); // $field.UnderlyingFields
-#end
-
-
- // Constructor
-
- public ${javaClassName}(ByteBuffer buffer) throws AMQFrameDecodingException
- {
-#foreach( $field in $method.ConsolidatedFields )
- _$field.Name = read$field.getEncodingType()( buffer );
-#end
- }
-
- public ${javaClassName}(
-#foreach( $field in $method.FieldList )
-#if( $velocityCount == $method.getFieldList().size() )
- $field.NativeType $field.Name
-#else
- $field.NativeType $field.Name,
-#end
-#end)
- {
-#set( $consolidatedFieldName = "" )
-#foreach( $field in $method.FieldList )
-#if( $method.isConsolidated( $field.Name ) )
-#if( !$method.getConsolidatedFieldName( $field.Name ).equals( $consolidatedFieldName ) )
-#if( !$consolidatedFieldName.equals("") )
- _$consolidatedFieldName = $consolidatedFieldName; // 1
-#end
-#set( $consolidatedFieldName = $method.getConsolidatedFieldName( $field.Name ) )
- byte $consolidatedFieldName = (byte)0;
-#end
- if( $field.Name )
- {
- $consolidatedFieldName = (byte) (((int) $consolidatedFieldName) | (1 << $method.getPositionInBitField( $field.Name )));
- }
-#if( $velocityCount == $method.getFieldList().size())
- _$consolidatedFieldName = $consolidatedFieldName;
-#else
-
-#end
-#else
-#if( !$consolidatedFieldName.equals("") )
- _$consolidatedFieldName = $consolidatedFieldName;
-#end
-#set( $consolidatedFieldName = "" )
- _$field.Name = $field.Name;
-#end
-#end
- }
-
- public int getClazz()
- {
- return CLASS_ID;
- }
-
- public int getMethod()
- {
- return METHOD_ID;
- }
-
-
-#foreach( $field in $method.FieldList )
- public final $field.NativeType get#toUpperCamel( ${field.Name} )()
- {
-#if( $method.isConsolidated( $field.Name ) )
- return (((int)(_$method.getConsolidatedFieldName( $field.Name ))) & ( 1 << $method.getPositionInBitField( $field.Name ))) != 0;
-#else
- return _$field.Name;
-#end
- }
-#end
-
- protected int getBodySize()
- {
- int size = 0;
-#foreach( $field in $method.ConsolidatedFields )
-#if( $field.isFixedSize() )
- size += $field.Size;
-#else
- size += getSizeOf( _$field.Name );
-#end
-#end
- return size;
- }
-
- public void writeMethodPayload(ByteBuffer buffer)
- {
-#foreach( $field in $method.ConsolidatedFields )
-
- write$field.getEncodingType()( buffer, _$field.Name );
-#end
- }
-
-
- public String toString()
- {
- StringBuffer buf = new StringBuffer("[$javaClassName: ");
-#foreach( $field in $method.FieldList )
- buf.append( "$field.Name=" );
- buf.append( get#toUpperCamel( $field.Name )() );
-#if( $velocityCount != $method.FieldList.size() )
- buf.append( ", " );
-#end
-#end
- buf.append("]");
- return buf.toString();
- }
-
-
-}
diff --git a/gentools/templ.java/model/ProtocolVersionListClass.vm b/gentools/templ.java/model/ProtocolVersionListClass.vm
deleted file mode 100644
index bcf7db345b..0000000000
--- a/gentools/templ.java/model/ProtocolVersionListClass.vm
+++ /dev/null
@@ -1,154 +0,0 @@
-#set( $filename = "ProtocolVersion.java" )
-/*
-*
-* 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.
-*
-*/
-
-/*
-* This file is auto-generated by $generator - do not modify.
-* Supported AMQP versions:
-#foreach( $version in $model.getVersionSet() )
-* $version.getMajor()-$version.getMinor()
-#end
-*/
-
-package org.apache.qpid.framing;
-
-import java.util.SortedSet;
-import java.util.Collections;
-import java.util.TreeSet;
-
-
-public class ProtocolVersion implements Comparable
-{
- private final byte _majorVersion;
- private final byte _minorVersion;
- private final String _stringFormat;
-
-
- public ProtocolVersion(byte majorVersion, byte minorVersion)
- {
- _majorVersion = majorVersion;
- _minorVersion = minorVersion;
- _stringFormat = _majorVersion+"-"+_minorVersion;
- }
-
- public byte getMajorVersion()
- {
- return _majorVersion;
- }
-
- public byte getMinorVersion()
- {
- return _minorVersion;
- }
-
- public String toString()
- {
- return _stringFormat;
- }
-
- public int compareTo(Object o)
- {
- ProtocolVersion pv = (ProtocolVersion) o;
-
- /*
- * 0-8 has it's major and minor numbers the wrong way round (it's actually 8-0)...
- * so we need to deal with that case specially
- */
-
- if((_majorVersion == (byte) 8) && (_minorVersion == (byte) 0))
- {
- ProtocolVersion fixedThis = new ProtocolVersion(_minorVersion, _majorVersion);
- return fixedThis.compareTo(pv);
- }
-
- if((pv.getMajorVersion() == (byte) 8) && (pv.getMinorVersion() == (byte) 0))
- {
- ProtocolVersion fixedOther = new ProtocolVersion(pv.getMinorVersion(), pv.getMajorVersion());
- return this.compareTo(fixedOther);
- }
-
- if(_majorVersion > pv.getMajorVersion())
- {
- return 1;
- }
- else if(_majorVersion < pv.getMajorVersion())
- {
- return -1;
- }
- else if(_minorVersion > pv.getMinorVersion())
- {
- return 1;
- }
- else if(getMinorVersion() < pv.getMinorVersion())
- {
- return -1;
- }
- else
- {
- return 0;
- }
-
- }
-
- public boolean equals(Object o)
- {
- return o != null && (o == this || (compareTo(o) == 0));
- }
-
- public int hashCode()
- {
- return (0xFF & (int)_minorVersion) | ((0xFF & (int)_majorVersion) << 8);
- }
-
-
- public boolean isSupported()
- {
- return _supportedVersions.contains(this);
- }
-
- public static ProtocolVersion getLatestSupportedVersion()
- {
- return _supportedVersions.last();
- }
-
- private static final SortedSet<ProtocolVersion> _supportedVersions;
-
- static
- {
- SortedSet<ProtocolVersion> versions = new TreeSet<ProtocolVersion>();
-
-#foreach( $version in $model.getVersionSet() )
- versions.add(new ProtocolVersion((byte)$version.getMajor(),(byte)$version.getMinor()));
-#end
- _supportedVersions = Collections.unmodifiableSortedSet(versions);
- }
-
-
- public static SortedSet<ProtocolVersion> getSupportedProtocolVersions()
- {
- return _supportedVersions;
- }
-
-
-
-
-
-}
diff --git a/gentools/templ.java/model/version/AmqpConstantsClass.vm b/gentools/templ.java/model/version/AmqpConstantsClass.vm
deleted file mode 100644
index 8d459f2977..0000000000
--- a/gentools/templ.java/model/version/AmqpConstantsClass.vm
+++ /dev/null
@@ -1,37 +0,0 @@
-&{AmqpConstants.java}
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by ${GENERATOR} - do not modify.
- * Supported AMQP versions:
-%{VLIST} * ${major}-${minor}
- */
-
-package org.apache.qpid.framing;
-
-class AmqpConstants
-{
- // Constant getValue methods
-
-%{TLIST} ${const_get_method}
-
-}
diff --git a/gentools/templ.java/model/version/MethodRegistryClass.vm b/gentools/templ.java/model/version/MethodRegistryClass.vm
deleted file mode 100644
index 82287e7f8f..0000000000
--- a/gentools/templ.java/model/version/MethodRegistryClass.vm
+++ /dev/null
@@ -1,145 +0,0 @@
-#set( $filename = "amqp_$version.getMajor()_$version.getMinor()/MethodRegistry_${version.getMajor()}_${version.getMinor()}.java")
-/*
- *
- * 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.
- *
- */
-
-/*
- * This file is auto-generated by $generator - do not modify.
- * Supported AMQP version:
- * $version.getMajor()-$version.getMinor()
- */
-
-package org.apache.qpid.framing.amqp_${version.getMajor()}_${version.getMinor()};
-
-import org.apache.qpid.framing.AMQMethodBodyInstanceFactory;
-import org.apache.qpid.framing.AMQFrameDecodingException;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.framing.MethodRegistry;
-import org.apache.qpid.framing.ProtocolVersion;
-
-
-import org.apache.log4j.Logger;
-import org.apache.mina.common.ByteBuffer;
-
-public class MethodRegistry_$version.getMajor()_$version.getMinor() extends MethodRegistry
-{
-
- private static final Logger _log = Logger.getLogger(MethodRegistry.class);
-
-#set( $specificModel = $model.asSingleVersionModel() )
-
-
-
- private final AMQMethodBodyInstanceFactory[][] _factories = new AMQMethodBodyInstanceFactory[$specificModel.getMaximumClassId()+1][];
-
- public MethodRegistry_$version.getMajor()_$version.getMinor()()
- {
- this(new ProtocolVersion((byte)$version.getMajor(),(byte)$version.getMinor()));
- }
-
- public MethodRegistry_$version.getMajor()_$version.getMinor()(ProtocolVersion pv)
- {
- super(pv);
-#foreach( $amqpClass in $specificModel.getClassList() )
-#set( $amqpClassNameFirstChar = $amqpClass.getName().substring(0,1) )
-#set( $amqpClassNameFirstCharU = $amqpClassNameFirstChar.toUpperCase() )
-#set( $amqpClassNameUpperCamel = "$amqpClassNameFirstCharU$amqpClass.getName().substring(1)" )
-
-
-
- // Register method body instance factories for the $amqpClassNameUpperCamel class.
-
- _factories[$amqpClass.getClassId()] = new AMQMethodBodyInstanceFactory[$amqpClass.getMaximumMethodId()+1];
-
-#foreach( $amqpMethod in $amqpClass.getMethodList() )
-#set( $amqpMethodNameFirstChar = $amqpMethod.getName().substring(0,1) )
-#set( $amqpMethodNameFirstCharU = $amqpMethodNameFirstChar.toUpperCase() )
-#set( $amqpMethodNameUpperCamel = "$amqpMethodNameFirstCharU$amqpMethod.getName().substring(1)" )
- _factories[$amqpClass.getClassId()][$amqpMethod.getMethodId()] = ${amqpClassNameUpperCamel}${amqpMethodNameUpperCamel}BodyImpl.getFactory();
-#end
-
-#end
-
-
- }
-
-
- public AMQMethodBody convertToBody(ByteBuffer in, long size)
- throws AMQFrameDecodingException
- {
- int classId = in.getUnsignedShort();
- int methodId = in.getUnsignedShort();
-
- AMQMethodBodyInstanceFactory bodyFactory;
- try
- {
- bodyFactory = _factories[classId][methodId];
- }
- catch(NullPointerException e)
- {
- throw new AMQFrameDecodingException(_log,
- "Class " + classId + " unknown in AMQP version $version.getMajor()-$version.getMinor()"
- + " (while trying to decode class " + classId + " method " + methodId + ".");
- }
- catch(IndexOutOfBoundsException e)
- {
- if(classId >= _factories.length)
- {
- throw new AMQFrameDecodingException(_log,
- "Class " + classId + " unknown in AMQP version $version.getMajor()-$version.getMinor()"
- + " (while trying to decode class " + classId + " method " + methodId + ".");
-
- }
- else
- {
- throw new AMQFrameDecodingException(_log,
- "Method " + methodId + " unknown in AMQP version $version.getMajor()-$version.getMinor()"
- + " (while trying to decode class " + classId + " method " + methodId + ".");
-
- }
- }
-
-
- if (bodyFactory == null)
- {
- throw new AMQFrameDecodingException(_log,
- "Method " + methodId + " unknown in AMQP version $version.getMajor()-$version.getMinor()"
- + " (while trying to decode class " + classId + " method " + methodId + ".");
- }
-
-
- return bodyFactory.newInstance(in, size);
-
-
- }
-
-
- public int getMaxClassId()
- {
- return $specificModel.getMaximumClassId();
- }
-
- public int getMaxMethodId(int classId)
- {
- return _factories[classId].length - 1;
- }
-
-
-}
diff --git a/gentools/xml-src/amqp-0.10.test.xml b/gentools/xml-src/amqp-0.10.test.xml
deleted file mode 100644
index 5d3d80648b..0000000000
--- a/gentools/xml-src/amqp-0.10.test.xml
+++ /dev/null
@@ -1,4241 +0,0 @@
-<?xml version = "1.0"?>
-
-<!--
- EDITORS: (PH) Pieter Hintjens <ph@imatix.com>
- (KvdR) Kim van der Riet <kim.vdriet@redhat.com>
-
- These editors have been assigned by the AMQP working group.
- Please do not edit/commit this file without consulting with
- one of the above editors.
- ========================================================
-
- TODOs
- - see TODO comments in the text
--->
-
-<!--
- Copyright Notice
- ================
- (c) Copyright JPMorgan Chase Bank & Co., Cisco Systems, Inc., Envoy Technologies Inc.,
- iMatix Corporation, IONA\ufffd Technologies, Red Hat, Inc.,
- TWIST Process Innovations, and 29West Inc. 2006. All rights reserved.
-
- License
- =======
- JPMorgan Chase Bank & Co., Cisco Systems, Inc., Envoy Technologies Inc., iMatix
- Corporation, IONA\ufffd Technologies, Red Hat, Inc., TWIST Process Innovations, and
- 29West Inc. (collectively, the "Authors") each hereby grants to you a worldwide,
- perpetual, royalty-free, nontransferable, nonexclusive license to
- (i) copy, display, and implement the Advanced Messaging Queue Protocol
- ("AMQP") Specification and (ii) the Licensed Claims that are held by
- the Authors, all for the purpose of implementing the Advanced Messaging
- Queue Protocol Specification. Your license and any rights under this
- Agreement will terminate immediately without notice from
- any Author if you bring any claim, suit, demand, or action related to
- the Advanced Messaging Queue Protocol Specification against any Author.
- Upon termination, you shall destroy all copies of the Advanced Messaging
- Queue Protocol Specification in your possession or control.
-
- As used hereunder, "Licensed Claims" means those claims of a patent or
- patent application, throughout the world, excluding design patents and
- design registrations, owned or controlled, or that can be sublicensed
- without fee and in compliance with the requirements of this
- Agreement, by an Author or its affiliates now or at any
- future time and which would necessarily be infringed by implementation
- of the Advanced Messaging Queue Protocol Specification. A claim is
- necessarily infringed hereunder only when it is not possible to avoid
- infringing it because there is no plausible non-infringing alternative
- for implementing the required portions of the Advanced Messaging Queue
- Protocol Specification. Notwithstanding the foregoing, Licensed Claims
- shall not include any claims other than as set forth above even if
- contained in the same patent as Licensed Claims; or that read solely
- on any implementations of any portion of the Advanced Messaging Queue
- Protocol Specification that are not required by the Advanced Messaging
- Queue Protocol Specification, or that, if licensed, would require a
- payment of royalties by the licensor to unaffiliated third parties.
- Moreover, Licensed Claims shall not include (i) any enabling technologies
- that may be necessary to make or use any Licensed Product but are not
- themselves expressly set forth in the Advanced Messaging Queue Protocol
- Specification (e.g., semiconductor manufacturing technology, compiler
- technology, object oriented technology, networking technology, operating
- system technology, and the like); or (ii) the implementation of other
- published standards developed elsewhere and merely referred to in the
- body of the Advanced Messaging Queue Protocol Specification, or
- (iii) any Licensed Product and any combinations thereof the purpose or
- function of which is not required for compliance with the Advanced
- Messaging Queue Protocol Specification. For purposes of this definition,
- the Advanced Messaging Queue Protocol Specification shall be deemed to
- include both architectural and interconnection requirements essential
- for interoperability and may also include supporting source code artifacts
- where such architectural, interconnection requirements and source code
- artifacts are expressly identified as being required or documentation to
- achieve compliance with the Advanced Messaging Queue Protocol Specification.
-
- As used hereunder, "Licensed Products" means only those specific portions
- of products (hardware, software or combinations thereof) that implement
- and are compliant with all relevant portions of the Advanced Messaging
- Queue Protocol Specification.
-
- The following disclaimers, which you hereby also acknowledge as to any
- use you may make of the Advanced Messaging Queue Protocol Specification:
-
- THE ADVANCED MESSAGING QUEUE PROTOCOL SPECIFICATION IS PROVIDED "AS IS,"
- AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
- IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE
- CONTENTS OF THE ADVANCED MESSAGING QUEUE PROTOCOL SPECIFICATION ARE
- SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF THE ADVANCED
- MESSAGING QUEUE PROTOCOL SPECIFICATION WILL NOT INFRINGE ANY THIRD PARTY
- PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
-
- THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
- INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY
- USE, IMPLEMENTATION OR DISTRIBUTION OF THE ADVANCED MESSAGING QUEUE
- PROTOCOL SPECIFICATION.
-
- The name and trademarks of the Authors may NOT be used in any manner,
- including advertising or publicity pertaining to the Advanced Messaging
- Queue Protocol Specification or its contents without specific, written
- prior permission. Title to copyright in the Advanced Messaging Queue
- Protocol Specification will at all times remain with the Authors.
-
- No other rights are granted by implication, estoppel or otherwise.
-
- Upon termination of your license or rights under this Agreement, you
- shall destroy all copies of the Advanced Messaging Queue Protocol
- Specification in your possession or control.
-
- Trademarks
- ==========
- "JPMorgan", "JPMorgan Chase", "Chase", the JPMorgan Chase logo and the
- Octagon Symbol are trademarks of JPMorgan Chase & Co.
-
- IMATIX and the iMatix logo are trademarks of iMatix Corporation sprl.
-
- IONA, IONA Technologies, and the IONA logos are trademarks of IONA
- Technologies PLC and/or its subsidiaries.
-
- LINUX is a trademark of Linus Torvalds. RED HAT and JBOSS are registered
- trademarks of Red Hat, Inc. in the US and other countries.
-
- Java, all Java-based trademarks and OpenOffice.org are trademarks of
- Sun Microsystems, Inc. in the United States, other countries, or both.
-
- Other company, product, or service names may be trademarks or service
- marks of others.
-
- Links to full AMQP specification:
- =================================
- http://www.envoytech.org/spec/amq/
- http://www.iona.com/opensource/amqp/
- http://www.redhat.com/solutions/specifications/amqp/
- http://www.twiststandards.org/tiki-index.php?page=AMQ
- http://www.imatix.com/amqp
--->
-
-<!--
- <!DOCTYPE amqp SYSTEM "amqp.dtd">
--->
-
-<!-- XML Notes
-
- We use entities to indicate repetition; attributes to indicate properties.
-
- We use the 'name' attribute as an identifier, usually within the context
- of the surrounding entities.
-
- We use spaces to seperate words in names, so that we can print names in
- their natural form depending on the context - underlines for source code,
- hyphens for written text, etc.
-
- We do not enforce any particular validation mechanism but we support all
- mechanisms. The protocol definition conforms to a formal grammar that is
- published seperately in several technologies.
-
- -->
-
-<amqp major = "0" minor = "10" port = "5672" comment = "AMQ Protocol">
- <!--
- ======================================================
- == CONSTANTS
- ======================================================
- -->
- <!-- Frame types -->
- <constant name = "frame-method" value = "1" />
- <constant name = "frame-header" value = "2" />
- <constant name = "frame-body" value = "3" />
- <constant name = "frame-oob-method" value = "4" />
- <constant name = "frame-oob-header" value = "5" />
- <constant name = "frame-oob-body" value = "6" />
- <constant name = "frame-trace" value = "7" />
- <constant name = "frame-heartbeat" value = "8" />
-
- <!-- Protocol constants -->
- <constant name = "frame-min-size" value = "4096" />
- <constant name = "frame-end" value = "206" />
-
- <!-- Reply codes -->
- <constant name = "reply-success" value = "200">
- <doc>
- Indicates that the method completed successfully. This reply code is
- reserved for future use - the current protocol design does not use positive
- confirmation and reply codes are sent only in case of an error.
- </doc>
- </constant>
-
- <constant name = "not-delivered" value = "310" class = "soft-error">
- <doc>
- The client asked for a specific message that is no longer available.
- The message was delivered to another client, or was purged from the queue
- for some other reason.
- </doc>
- </constant>
-
- <constant name = "content-too-large" value = "311" class = "soft-error">
- <doc>
- The client attempted to transfer content larger than the server could accept
- at the present time. The client may retry at a later time.
- </doc>
- </constant>
-
- <constant name = "connection-forced" value = "320" class = "hard-error">
- <doc>
- An operator intervened to close the connection for some reason. The client
- may retry at some later date.
- </doc>
- </constant>
-
- <constant name = "invalid-path" value = "402" class = "hard-error">
- <doc>
- The client tried to work with an unknown virtual host.
- </doc>
- </constant>
-
- <constant name = "access-refused" value = "403" class = "soft-error">
- <doc>
- The client attempted to work with a server entity to which it has no
- access due to security settings.
- </doc>
- </constant>
-
- <constant name = "not-found" value = "404" class = "soft-error">
- <doc>The client attempted to work with a server entity that does not exist.</doc>
- </constant>
-
- <constant name = "resource-locked" value = "405" class = "soft-error">
- <doc>
- The client attempted to work with a server entity to which it has no
- access because another client is working with it.
- </doc>
- </constant>
-
- <constant name = "precondition-failed" value = "406" class = "soft-error">
- <doc>
- The client requested a method that was not allowed because some precondition
- failed.
- </doc>
- </constant>
-
- <constant name = "frame-error" value = "501" class = "hard-error">
- <doc>
- The client sent a malformed frame that the server could not decode. This
- strongly implies a programming error in the client.
- </doc>
- </constant>
-
- <constant name = "syntax-error" value = "502" class = "hard-error">
- <doc>
- The client sent a frame that contained illegal values for one or more
- fields. This strongly implies a programming error in the client.
- </doc>
- </constant>
-
- <constant name = "command-invalid" value = "503" class = "hard-error">
- <doc>
- The client sent an invalid sequence of frames, attempting to perform an
- operation that was considered invalid by the server. This usually implies
- a programming error in the client.
- </doc>
- </constant>
-
- <constant name = "channel-error" value = "504" class = "hard-error">
- <doc>
- The client attempted to work with a channel that had not been correctly
- opened. This most likely indicates a fault in the client layer.
- </doc>
- </constant>
-
- <constant name = "resource-error" value = "506" class = "hard-error">
- <doc>
- The server could not complete the method because it lacked sufficient
- resources. This may be due to the client creating too many of some type
- of entity.
- </doc>
- </constant>
-
- <constant name = "not-allowed" value = "530" class = "hard-error">
- <doc>
- The client tried to work with some entity in a manner that is prohibited
- by the server, due to security settings or by some other criteria.
- </doc>
- </constant>
-
- <constant name = "not-implemented" value = "540" class = "hard-error">
- <doc>
- The client tried to use functionality that is not implemented in the
- server.
- </doc>
- </constant>
-
- <constant name = "internal-error" value = "545" class = "hard-error">
- <doc>
- The server could not complete the method because of an internal error.
- The server may require intervention by an operator in order to resume
- normal operations.
- </doc>
- </constant>
-
- <constant name = "test-double" value = "3.141592654"/>
- <constant name = "test-str1" value = "hello, world!"/>
- <constant name = "test-str2" value = "1.2.3.4"/>
-
- <!--
- ======================================================
- == DOMAIN TYPES
- ======================================================
- -->
-
- <domain name = "access-ticket" type = "short" label = "access ticket granted by server">
- <doc>
- An access ticket granted by the server for a certain set of access rights
- within a specific realm. Access tickets are valid within the channel where
- they were created, and expire when the channel closes.
- </doc>
- <assert check = "ne" value = "0" />
- </domain>
-
- <domain name = "class-id" type = "short" />
-
- <domain name = "consumer-tag" type = "shortstr" label = "consumer tag">
- <doc>
- Identifier for the consumer, valid within the current connection.
- </doc>
- </domain>
-
- <domain name = "delivery-tag" type = "longlong" label = "server-assigned delivery tag">
- <doc>
- The server-assigned and channel-specific delivery tag
- </doc>
- <rule name = "channel-local">
- <doc>
- The delivery tag is valid only within the channel from which the message was
- received. I.e. a client MUST NOT receive a message on one channel and then
- acknowledge it on another.
- </doc>
- </rule>
- <rule name = "non-zero">
- <doc>
- The server MUST NOT use a zero value for delivery tags. Zero is reserved
- for client use, meaning "all messages so far received".
- </doc>
- </rule>
- </domain>
-
- <domain name = "exchange-name" type = "shortstr" label = "exchange name">
- <doc>
- The exchange name is a client-selected string that identifies the exchange for publish
- methods. Exchange names may consist of any mixture of digits, letters, and underscores.
- Exchange names are scoped by the virtual host.
- </doc>
- <assert check = "length" value = "127" />
- </domain>
-
- <domain name = "known-hosts" type = "shortstr" label = "list of known hosts">
- <doc>
- Specifies the list of equivalent or alternative hosts that the server knows about,
- which will normally include the current server itself. Clients can cache this
- information and use it when reconnecting to a server after a failure. This field
- may be empty.
- </doc>
- </domain>
-
- <domain name = "method-id" type = "long" />
-
- <domain name = "no-ack" type = "bit" label = "no acknowledgement needed">
- <doc>
- If this field is set the server does not expect acknowledgments for
- messages. That is, when a message is delivered to the client the server
- automatically and silently acknowledges it on behalf of the client. This
- functionality increases performance but at the cost of reliability.
- Messages can get lost if a client dies before it can deliver them to the
- application.
- </doc>
- </domain>
-
- <domain name = "no-local" type = "bit" label = "do not deliver own messages">
- <doc>
- If the no-local field is set the server will not send messages to the client that
- published them.
- </doc>
- </domain>
-
- <domain name = "path" type = "shortstr">
- <doc>
- Must start with a slash "/" and continue with path names separated by slashes. A path
- name consists of any combination of at least one of [A-Za-z0-9] plus zero or more of
- [.-_+!=:].
- </doc>
-
- <assert check = "notnull" />
- <assert check = "syntax" rule = "path" />
- <assert check = "length" value = "127" />
- </domain>
-
- <domain name = "peer-properties" type = "table">
- <doc>
- This string provides a set of peer properties, used for identification, debugging, and
- general information.
- </doc>
- </domain>
-
- <domain name = "queue-name" type = "shortstr" label = "queue name">
- <doc>
- The queue name identifies the queue within the vhost. Queue names may consist of any
- mixture of digits, letters, and underscores.
- </doc>
- <assert check = "length" value = "127" />
- </domain>
-
- <domain name = "redelivered" type = "bit" label = "message is being redelivered">
- <doc>
- This indicates that the message has been previously delivered to this or
- another client.
- </doc>
- <rule name = "implementation">
- <doc>
- The server SHOULD try to signal redelivered messages when it can. When
- redelivering a message that was not successfully acknowledged, the server
- SHOULD deliver it to the original client if possible.
- </doc>
- <doc type = "scenario">
- Create a shared queue and publish a message to the queue. Consume the
- message using explicit acknowledgements, but do not acknowledge the
- message. Close the connection, reconnect, and consume from the queue
- again. The message should arrive with the redelivered flag set.
- </doc>
- </rule>
- <rule name = "hinting">
- <doc>
- The client MUST NOT rely on the redelivered field but should take it as a
- hint that the message may already have been processed. A fully robust
- client must be able to track duplicate received messages on non-transacted,
- and locally-transacted channels.
- </doc>
- </rule>
- </domain>
-
- <domain name = "reply-code" type = "short" label = "reply code from server">
- <doc>
- The reply code. The AMQ reply codes are defined as constants at the start
- of this formal specification.
- </doc>
- <assert check = "notnull" />
- </domain>
-
- <domain name = "reply-text" type = "shortstr" label = "localised reply text">
- <doc>
- The localised reply text. This text can be logged as an aid to resolving
- issues.
- </doc>
- <assert check = "notnull" />
- </domain>
-
- <!-- Elementary domains -->
- <domain name = "bit" type = "bit" label = "single bit" />
- <domain name = "octet" type = "octet" label = "single octet" />
- <domain name = "short" type = "short" label = "16-bit integer" />
- <domain name = "long" type = "long" label = "32-bit integer" />
- <domain name = "longlong" type = "longlong" label = "64-bit integer" />
- <domain name = "shortstr" type = "shortstr" label = "short string" />
- <domain name = "longstr" type = "longstr" label = "long string" />
- <domain name = "timestamp" type = "timestamp" label = "64-bit timestamp" />
- <domain name = "table" type = "table" label = "field table" />
-
- <!-- == CONNECTION ======================================================= -->
-
- <!-- TODO 0.81 - the 'handler' attribute of methods needs to be reviewed, and if
- no current implementations use it, removed. /PH 2006/07/20
- -->
-
- <class name = "connection" handler = "connection" index = "10" label = "work with socket connections">
- <doc>
- The connection class provides methods for a client to establish a network connection to
- a server, and for both peers to operate the connection thereafter.
- </doc>
-
- <doc type = "grammar">
- connection = open-connection *use-connection close-connection
- open-connection = C:protocol-header
- S:START C:START-OK
- *challenge
- S:TUNE C:TUNE-OK
- C:OPEN S:OPEN-OK | S:REDIRECT
- challenge = S:SECURE C:SECURE-OK
- use-connection = *channel
- close-connection = C:CLOSE S:CLOSE-OK
- / S:CLOSE C:CLOSE-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "start" synchronous = "1" index = "10" label = "start connection negotiation">
- <doc>
- This method starts the connection negotiation process by telling the client the
- protocol version that the server proposes, along with a list of security mechanisms
- which the client can use for authentication.
- </doc>
-
- <rule name = "protocol-name">
- <doc>
- If the server cannot support the protocol specified in the protocol header,
- it MUST close the socket connection without sending any response method.
- </doc>
- <doc type = "scenario">
- The client sends a protocol header containing an invalid protocol name.
- The server must respond by closing the connection.
- </doc>
- </rule>
- <rule name = "server-support">
- <doc>
- The server MUST provide a protocol version that is lower than or equal to
- that requested by the client in the protocol header.
- </doc>
- <doc type = "scenario">
- The client requests a protocol version that is higher than any valid
- implementation, e.g. 9.0. The server must respond with a current
- protocol version, e.g. 1.0.
- </doc>
- </rule>
- <rule name = "client-support">
- <doc>
- If the client cannot handle the protocol version suggested by the server
- it MUST close the socket connection.
- </doc>
- <doc type = "scenario">
- The server sends a protocol version that is lower than any valid
- implementation, e.g. 0.1. The client must respond by closing the
- connection.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
- <response name = "start-ok" />
-
- <field name = "version-major" domain = "octet" label = "protocol major version">
- <doc>
- The version of the protocol, expressed in protocol units of 0.1 public
- versions and properly printed as two digits with a leading zero. I.e. a
- protocol version of "09" represents a public version "0.9". The decimal
- shift allows the correct expression of pre-1.0 protocol releases.
- </doc>
- <doc type = "todo">
- This field should be renamed to "protocol version".
- </doc>
- </field>
-
- <field name = "version-minor" domain = "octet" label = "protocol major version">
- <doc>
- The protocol revision, expressed as an integer from 0 to 9. The use of more
- than ten revisions is discouraged. The public version string is constructed
- from the protocol version and revision as follows: we print the protocol
- version with one decimal position, and we append the protocol revision. A
- version=10 and revision=2 are printed as "1.02".
- </doc>
- <doc type = "todo">
- This field should be renamed to "protocol revision".
- </doc>
- </field>
-
- <field name = "server-properties" domain = "peer-properties" label = "server properties">
- <rule name = "required-fields">
- <doc>
- The properties SHOULD contain at least these fields: "host", specifying the
- server host name or address, "product", giving the name of the server product,
- "version", giving the name of the server version, "platform", giving the name
- of the operating system, "copyright", if appropriate, and "information", giving
- other general information.
- </doc>
- <doc type = "scenario">
- Client connects to server and inspects the server properties. It checks for
- the presence of the required fields.
- </doc>
- </rule>
- </field>
-
- <field name = "mechanisms" domain = "longstr" label = "available security mechanisms">
- <doc>
- A list of the security mechanisms that the server supports, delimited by spaces.
- Currently ASL supports these mechanisms: PLAIN.
- </doc>
- <assert check = "notnull" />
- </field>
-
- <field name = "locales" domain = "longstr" label = "available message locales">
- <doc>
- A list of the message locales that the server supports, delimited by spaces. The
- locale defines the language in which the server will send reply texts.
- </doc>
- <rule name = "required-support">
- <doc>
- The server MUST support at least the en_US locale.
- </doc>
- <doc type = "scenario">
- Client connects to server and inspects the locales field. It checks for
- the presence of the required locale(s).
- </doc>
- </rule>
- <assert check = "notnull" />
- </field>
- </method>
-
- <method name = "start-ok" synchronous = "1" index = "11"
- label = "select security mechanism and locale">
- <doc>
- This method selects a SASL security mechanism. ASL uses SASL (RFC2222) to
- negotiate authentication and encryption.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "client-properties" domain = "peer-properties" label = "client properties">
- <rule name = "required-fields">
- <!-- This rule is not testable from the client side -->
- <doc>
- The properties SHOULD contain at least these fields: "product", giving the name
- of the client product, "version", giving the name of the client version, "platform",
- giving the name of the operating system, "copyright", if appropriate, and
- "information", giving other general information.
- </doc>
- </rule>
- </field>
-
- <field name = "mechanism" domain = "shortstr" label = "selected security mechanism">
- <doc>
- A single security mechanisms selected by the client, which must be one of those
- specified by the server.
- </doc>
- <rule name = "security">
- <doc>
- The client SHOULD authenticate using the highest-level security profile it
- can handle from the list provided by the server.
- </doc>
- </rule>
- <rule name = "validity">
- <doc>
- If the mechanism field does not contain one of the security mechanisms
- proposed by the server in the Start method, the server MUST close the
- connection without sending any further data.
- </doc>
- <doc type = "scenario">
- Client connects to server and sends an invalid security mechanism. The
- server must respond by closing the connection (a socket close, with no
- connection close negotiation).
- </doc>
- </rule>
- <assert check = "notnull" />
- </field>
-
- <field name = "response" domain = "longstr" label = "security response data">
- <doc>
- A block of opaque data passed to the security mechanism. The contents of this
- data are defined by the SASL security mechanism.
- </doc>
- <assert check = "notnull" />
- </field>
-
- <field name = "locale" domain = "shortstr" label = "selected message locale">
- <doc>
- A single message local selected by the client, which must be one of those
- specified by the server.
- </doc>
- <assert check = "notnull" />
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "secure" synchronous = "1" index = "20" label = "security mechanism challenge">
- <doc>
- The SASL protocol works by exchanging challenges and responses until both peers have
- received sufficient information to authenticate each other. This method challenges
- the client to provide more information.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
- <response name = "secure-ok" />
-
- <field name = "challenge" domain = "longstr" label = "security challenge data">
- <doc>
- Challenge information, a block of opaque binary data passed to the security
- mechanism.
- </doc>
- </field>
- </method>
-
- <method name = "secure-ok" synchronous = "1" index = "21" label = "security mechanism response">
- <doc>
- This method attempts to authenticate, passing a block of SASL data for the security
- mechanism at the server side.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "response" domain = "longstr" label = "security response data">
- <doc>
- A block of opaque data passed to the security mechanism. The contents of this
- data are defined by the SASL security mechanism.
- </doc>
- <assert check = "notnull" />
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "tune" synchronous = "1" index = "30"
- label = "propose connection tuning parameters">
- <doc>
- This method proposes a set of connection configuration values to the client. The
- client can accept and/or adjust these.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <response name = "tune-ok" />
-
- <field name = "channel-max" domain = "short" label = "proposed maximum channels">
- <doc>
- The maximum total number of channels that the server allows per connection. Zero
- means that the server does not impose a fixed limit, but the number of allowed
- channels may be limited by available server resources.
- </doc>
- </field>
-
- <field name = "frame-max" domain = "long" label = "proposed maximum frame size">
- <doc>
- The largest frame size that the server proposes for the connection. The client
- can negotiate a lower value. Zero means that the server does not impose any
- specific limit but may reject very large frames if it cannot allocate resources
- for them.
- </doc>
- <rule name = "minimum">
- <doc>
- Until the frame-max has been negotiated, both peers MUST accept frames of up
- to frame-min-size octets large, and the minimum negotiated value for frame-max
- is also frame-min-size.
- </doc>
- <doc type = "scenario">
- Client connects to server and sends a large properties field, creating a frame
- of frame-min-size octets. The server must accept this frame.
- </doc>
- </rule>
- </field>
-
- <field name = "heartbeat" domain = "short" label = "desired heartbeat delay">
- <!-- TODO 0.82 - the heartbeat negotiation mechanism was changed during
- implementation because the model documented here does not actually
- work properly. The best model we found is that the server proposes
- a heartbeat value to the client; the client can reply with zero, meaning
- 'do not use heartbeats (as documented here), or can propose its own
- heartbeat value, which the server should then accept. This is different
- from the model here which is disconnected - e.g. each side requests a
- heartbeat independently. Basically a connection is heartbeated in
- both ways, or not at all, depending on whether both peers support
- heartbeating or not, and the heartbeat value should itself be chosen
- by the client so that remote links can get a higher value. Also, the
- actual heartbeat mechanism needs documentation, and is as follows: so
- long as there is activity on a connection - in or out - both peers
- assume the connection is active. When there is no activity, each peer
- must send heartbeat frames. When no heartbeat frame is received after
- N cycles (where N is at least 2), the connection can be considered to
- have died. /PH 2006/07/19
- -->
- <doc>
- The delay, in seconds, of the connection heartbeat that the server wants.
- Zero means the server does not want a heartbeat.
- </doc>
- </field>
- </method>
-
- <method name = "tune-ok" synchronous = "1" index = "31"
- label = "negotiate connection tuning parameters">
- <doc>
- This method sends the client's connection tuning parameters to the server.
- Certain fields are negotiated, others provide capability information.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "channel-max" domain = "short" label = "negotiated maximum channels">
- <doc>
- The maximum total number of channels that the client will use per connection.
- </doc>
- <rule name = "upper-limit">
- <doc>
- If the client specifies a channel max that is higher than the value provided
- by the server, the server MUST close the connection without attempting a
- negotiated close. The server may report the error in some fashion to assist
- implementors.
- </doc>
- </rule>
- <assert check = "notnull" />
- <assert check = "le" method = "tune" field = "channel-max" />
- </field>
-
- <field name = "frame-max" domain = "long" label = "negotiated maximum frame size">
- <doc>
- The largest frame size that the client and server will use for the connection.
- Zero means that the client does not impose any specific limit but may reject
- very large frames if it cannot allocate resources for them. Note that the
- frame-max limit applies principally to content frames, where large contents can
- be broken into frames of arbitrary size.
- </doc>
- <rule name = "minimum">
- <doc>
- Until the frame-max has been negotiated, both peers MUST accept frames of up
- to frame-min-size octets large, and the minimum negotiated value for frame-max
- is also frame-min-size.
- </doc>
- </rule>
- <rule name = "upper-limit">
- <doc>
- If the client specifies a frame max that is higher than the value provided
- by the server, the server MUST close the connection without attempting a
- negotiated close. The server may report the error in some fashion to assist
- implementors.
- </doc>
- </rule>
- </field>
-
- <field name = "heartbeat" domain = "short" label = "desired heartbeat delay">
- <doc>
- The delay, in seconds, of the connection heartbeat that the client wants. Zero
- means the client does not want a heartbeat.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "open" synchronous = "1" index = "40" label = "open connection to virtual host">
- <doc>
- This method opens a connection to a virtual host, which is a collection of
- resources, and acts to separate multiple application domains within a server.
- The server may apply arbitrary limits per virtual host, such as the number
- of each type of entity that may be used, per connection and/or in total.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "open-ok" />
- <response name = "redirect" />
-
- <field name = "virtual-host" domain = "path" label = "virtual host name">
- <!-- TODO 0.82 - the entire vhost model needs review. This concept was
- prompted by the HTTP vhost concept but does not fit very well into
- AMQP. Currently we use the vhost as a "cluster identifier" which is
- inaccurate usage. /PH 2006/07/19
- -->
- <assert check = "regexp" value = "^[a-zA-Z0-9/-_]+$" />
- <doc>
- The name of the virtual host to work with.
- </doc>
- <rule name = "separation">
- <doc>
- If the server supports multiple virtual hosts, it MUST enforce a full
- separation of exchanges, queues, and all associated entities per virtual
- host. An application, connected to a specific virtual host, MUST NOT be able
- to access resources of another virtual host.
- </doc>
- </rule>
- <rule name = "security">
- <doc>
- The server SHOULD verify that the client has permission to access the
- specified virtual host.
- </doc>
- </rule>
- </field>
-
- <field name = "capabilities" domain = "shortstr" label = "required capabilities">
- <doc>
- The client can specify zero or more capability names, delimited by spaces.
- The server can use this string to how to process the client's connection
- request.
- </doc>
- </field>
-
- <field name = "insist" domain = "bit" label = "insist on connecting to server">
- <doc>
- In a configuration with multiple collaborating servers, the server may respond
- to a Connection.Open method with a Connection.Redirect. The insist option tells
- the server that the client is insisting on a connection to the specified server.
- </doc>
- <rule name = "behaviour">
- <doc>
- When the client uses the insist option, the server MUST NOT respond with a
- Connection.Redirect method. If it cannot accept the client's connection
- request it should respond by closing the connection with a suitable reply
- code.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "open-ok" synchronous = "1" index = "41" label = "signal that connection is ready">
- <doc>
- This method signals to the client that the connection is ready for use.
- </doc>
- <chassis name = "client" implement = "MUST" />
- <field name = "known-hosts" domain = "known-hosts" />
- </method>
-
- <method name = "redirect" synchronous = "1" index = "42" label = "redirects client to other server">
- <doc>
- This method redirects the client to another server, based on the requested virtual
- host and/or capabilities.
- </doc>
- <rule name = "usage">
- <doc>
- When getting the Connection.Redirect method, the client SHOULD reconnect to
- the host specified, and if that host is not present, to any of the hosts
- specified in the known-hosts list.
- </doc>
- </rule>
- <chassis name = "client" implement = "MUST" />
- <field name = "host" domain = "shortstr" label = "server to connect to">
- <doc>
- Specifies the server to connect to. This is an IP address or a DNS name,
- optionally followed by a colon and a port number. If no port number is
- specified, the client should use the default port number for the protocol.
- </doc>
- <assert check = "notnull" />
- </field>
- <field name = "known-hosts" domain = "known-hosts" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "close" synchronous = "1" index = "50" label = "request a connection close">
- <doc>
- This method indicates that the sender wants to close the connection. This may be
- due to internal conditions (e.g. a forced shut-down) or due to an error handling
- a specific method, i.e. an exception. When a close is due to an exception, the
- sender provides the class and method id of the method which caused the exception.
- </doc>
- <!-- TODO: the connection close mechanism needs to be reviewed from the ODF
- documentation and better expressed as rules here. /PH 2006/07/20
- -->
- <rule name = "stability">
- <doc>
- After sending this method any received method except the Close-OK method MUST
- be discarded.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
- <chassis name = "server" implement = "MUST" />
- <response name = "close-ok" />
-
- <field name = "reply-code" domain = "reply-code" />
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "class-id" domain = "class-id" label = "failing method class">
- <doc>
- When the close is provoked by a method exception, this is the class of the
- method.
- </doc>
- </field>
-
- <field name = "method-id" domain = "method-id" label = "failing method ID">
- <doc>
- When the close is provoked by a method exception, this is the ID of the method.
- </doc>
- </field>
- </method>
-
- <method name = "close-ok" synchronous = "1" index = "51" label = "confirm a connection close">
- <doc>
- This method confirms a Connection.Close method and tells the recipient that it is
- safe to release resources for the connection and close the socket.
- </doc>
- <rule name = "reporting">
- <doc>
- A peer that detects a socket closure without having received a Close-Ok
- handshake method SHOULD log the error.
- </doc>
- </rule>
- <chassis name = "client" implement = "MUST" />
- <chassis name = "server" implement = "MUST" />
- </method>
- </class>
-
- <!-- == CHANNEL ========================================================== -->
-
- <class name = "channel" handler = "channel" index = "20" label = "work with channels">
- <doc>
- The channel class provides methods for a client to establish a channel to a
- server and for both peers to operate the channel thereafter.
- </doc>
-
- <doc type = "grammar">
- channel = open-channel *use-channel close-channel
- open-channel = C:OPEN S:OPEN-OK
- use-channel = C:FLOW S:FLOW-OK
- / S:FLOW C:FLOW-OK
- / S:ALERT
- / functional-class
- close-channel = C:CLOSE S:CLOSE-OK
- / S:CLOSE C:CLOSE-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "open" synchronous = "1" index = "10" label = "open a channel for use">
- <doc>
- This method opens a channel to the server.
- </doc>
- <rule name = "state" on-failure = "channel-error">
- <doc>
- The client MUST NOT use this method on an alread-opened channel.
- </doc>
- <doc type = "scenario">
- Client opens a channel and then reopens the same channel.
- </doc>
- </rule>
- <chassis name = "server" implement = "MUST" />
- <response name = "open-ok" />
- <field name = "out of band" domain = "shortstr" label = "out-of-band settings">
- <doc>
- Configures out-of-band transfers on this channel. The syntax and meaning of this
- field will be formally defined at a later date.
- </doc>
- <assert check = "null" />
- </field>
- </method>
-
- <method name = "open-ok" synchronous = "1" index = "11" label = "signal that the channel is ready">
- <doc>
- This method signals to the client that the channel is ready for use.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "flow" synchronous = "1" index = "20" label = "enable/disable flow from peer">
- <doc>
- This method asks the peer to pause or restart the flow of content data. This is a
- simple flow-control mechanism that a peer can use to avoid oveflowing its queues or
- otherwise finding itself receiving more messages than it can process. Note that this
- method is not intended for window control. The peer that receives a disable flow
- method should finish sending the current content frame, if any, then pause.
- </doc>
-
- <rule name = "initial-state">
- <doc>
- When a new channel is opened, it is active (flow is active). Some applications
- assume that channels are inactive until started. To emulate this behaviour a
- client MAY open the channel, then pause it.
- </doc>
- </rule>
-
- <rule name = "bidirectional">
- <doc>
- When sending content frames, a peer SHOULD monitor the channel for incoming
- methods and respond to a Channel.Flow as rapidly as possible.
- </doc>
- </rule>
-
- <rule name = "throttling">
- <doc>
- A peer MAY use the Channel.Flow method to throttle incoming content data for
- internal reasons, for example, when exchanging data over a slower connection.
- </doc>
- </rule>
-
- <rule name = "expected-behaviour">
- <doc>
- The peer that requests a Channel.Flow method MAY disconnect and/or ban a peer
- that does not respect the request. This is to prevent badly-behaved clients
- from overwhelming a broker.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <response name = "flow-ok" />
-
- <field name = "active" domain = "bit" label = "start/stop content frames">
- <doc>
- If 1, the peer starts sending content frames. If 0, the peer stops sending
- content frames.
- </doc>
- </field>
- </method>
-
- <method name = "flow-ok" index = "21" label = "confirm a flow method">
- <doc>
- Confirms to the peer that a flow command was received and processed.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
- <field name = "active" domain = "bit" label = "current flow setting">
- <doc>
- Confirms the setting of the processed flow method: 1 means the peer will start
- sending or continue to send content frames; 0 means it will not.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <!-- TODO 0.82 - remove this method entirely
- /PH 2006/07/20
- -->
- <method name = "alert" index = "30" label = "send a non-fatal warning message">
- <doc>
- This method allows the server to send a non-fatal warning to the client. This is
- used for methods that are normally asynchronous and thus do not have confirmations,
- and for which the server may detect errors that need to be reported. Fatal errors
- are handled as channel or connection exceptions; non-fatal errors are sent through
- this method.
- </doc>
- <chassis name = "client" implement = "MUST" />
- <field name = "reply-code" domain = "reply-code" />
- <field name = "reply-text" domain = "reply-text" />
- <field name = "details" domain = "table" label = "detailed information for warning">
- <doc>
- A set of fields that provide more information about the problem. The meaning of
- these fields are defined on a per-reply-code basis (TO BE DEFINED).
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "close" synchronous = "1" index = "40" label = "request a channel close">
- <doc>
- This method indicates that the sender wants to close the channel. This may be due to
- internal conditions (e.g. a forced shut-down) or due to an error handling a specific
- method, i.e. an exception. When a close is due to an exception, the sender provides
- the class and method id of the method which caused the exception.
- </doc>
-
- <!-- TODO: the channel close behaviour needs to be reviewed from the ODF
- documentation and better expressed as rules here. /PH 2006/07/20
- -->
- <rule name = "stability">
- <doc>
- After sending this method any received method except the Close-OK method MUST
- be discarded.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
- <chassis name = "server" implement = "MUST" />
- <response name = "close-ok" />
-
- <field name = "reply-code" domain = "reply-code" />
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "class-id" domain = "class-id" label = "failing method class">
- <doc>
- When the close is provoked by a method exception, this is the class of the
- method.
- </doc>
- </field>
-
- <field name = "method-id" domain = "method-id" label = "failing method ID">
- <doc>
- When the close is provoked by a method exception, this is the ID of the method.
- </doc>
- </field>
- </method>
-
- <method name = "close-ok" synchronous = "1" index = "41" label = "confirm a channel close">
- <doc>
- This method confirms a Channel.Close method and tells the recipient that it is safe
- to release resources for the channel and close the socket.
- </doc>
- <rule name = "reporting">
- <doc>
- A peer that detects a socket closure without having received a Channel.Close-Ok
- handshake method SHOULD log the error.
- </doc>
- </rule>
- <chassis name = "client" implement = "MUST" />
- <chassis name = "server" implement = "MUST" />
- </method>
- </class>
-
- <!-- == ACCESS =========================================================== -->
-
- <!-- TODO 0.82 - this class must be implemented by two teams before we can
- consider it matured.
- -->
-
- <class name = "access" handler = "connection" index = "30" label = "work with access tickets">
- <doc>
- The protocol control access to server resources using access tickets. A
- client must explicitly request access tickets before doing work. An access
- ticket grants a client the right to use a specific set of resources -
- called a "realm" - in specific ways.
- </doc>
-
- <doc type = "grammar">
- access = C:REQUEST S:REQUEST-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "request" synchronous = "1" index = "10" label = "request an access ticket">
- <doc>
- This method requests an access ticket for an access realm. The server
- responds by granting the access ticket. If the client does not have
- access rights to the requested realm this causes a connection exception.
- Access tickets are a per-channel resource.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "request-ok" />
-
- <field name = "realm" domain = "shortstr" label = "name of requested realm">
- <doc>
- Specifies the name of the realm to which the client is requesting access.
- The realm is a configured server-side object that collects a set of
- resources (exchanges, queues, etc.). If the channel has already requested
- an access ticket onto this realm, the previous ticket is destroyed and a
- new ticket is created with the requested access rights, if allowed.
- </doc>
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MUST specify a realm that is known to the server. The server
- makes an identical response for undefined realms as it does for realms
- that are defined but inaccessible to this client.
- </doc>
- <doc type = "scenario">
- Client specifies an undefined realm.
- </doc>
- </rule>
- </field>
-
- <field name = "exclusive" domain = "bit" label = "request exclusive access">
- <doc>
- Request exclusive access to the realm, meaning that this will be the only
- channel that uses the realm's resources.
- </doc>
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MAY NOT request exclusive access to a realm that has active
- access tickets, unless the same channel already had the only access
- ticket onto that realm.
- </doc>
- <doc type = "scenario">
- Client opens two channels and requests exclusive access to the same realm.
- </doc>
- </rule>
- </field>
- <field name = "passive" domain = "bit" label = "request passive access">
- <doc>
- Request message passive access to the specified access realm. Passive
- access lets a client get information about resources in the realm but
- not to make any changes to them.
- </doc>
- </field>
- <field name = "active" domain = "bit" label = "request active access">
- <doc>
- Request message active access to the specified access realm. Active access lets
- a client get create and delete resources in the realm.
- </doc>
- </field>
- <field name = "write" domain = "bit" label = "request write access">
- <doc>
- Request write access to the specified access realm. Write access lets a client
- publish messages to all exchanges in the realm.
- </doc>
- </field>
- <field name = "read" domain = "bit" label = "request read access">
- <doc>
- Request read access to the specified access realm. Read access lets a client
- consume messages from queues in the realm.
- </doc>
- </field>
- </method>
-
- <method name = "request-ok" synchronous = "1" index = "11" label = "grant access to server resources">
- <doc>
- This method provides the client with an access ticket. The access ticket is valid
- within the current channel and for the lifespan of the channel.
- </doc>
- <rule name = "per-channel" on-failure = "not-allowed">
- <doc>
- The client MUST NOT use access tickets except within the same channel as
- originally granted.
- </doc>
- <doc type = "scenario">
- Client opens two channels, requests a ticket on one channel, and then
- tries to use that ticket in a seconc channel.
- </doc>
- </rule>
- <chassis name = "client" implement = "MUST" />
- <field name = "ticket" domain = "access-ticket" />
- </method>
- </class>
-
- <!-- == EXCHANGE ========================================================= -->
-
- <class name = "exchange" handler = "channel" index = "40" label = "work with exchanges">
- <doc>
- Exchanges match and distribute messages across queues. Exchanges can be configured in
- the server or created at runtime.
- </doc>
-
- <doc type = "grammar">
- exchange = C:DECLARE S:DECLARE-OK
- / C:DELETE S:DELETE-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <rule name = "required-types">
- <doc>
- The server MUST implement these standard exchange types: fanout, direct.
- </doc>
- <doc type = "scenario">
- Client attempts to declare an exchange with each of these standard types.
- </doc>
- </rule>
- <rule name = "recommended-types">
- <doc>
- The server SHOULD implement these standard exchange types: topic, headers.
- </doc>
- <doc type = "scenario">
- Client attempts to declare an exchange with each of these standard types.
- </doc>
- </rule>
- <rule name = "required-instances">
- <doc>
- The server MUST, in each virtual host, pre-declare an exchange instance
- for each standard exchange type that it implements, where the name of the
- exchange instance is "amq." followed by the exchange type name.
- </doc>
- <doc type = "scenario">
- Client creates a temporary queue and attempts to bind to each required
- exchange instance (amq.fanout, amq.direct, and amq.topic, amq.headers if
- those types are defined).
- </doc>
- </rule>
- <rule name = "default-exchange">
- <doc>
- The server MUST predeclare a direct exchange to act as the default exchange
- for content Publish methods and for default queue bindings.
- </doc>
- <doc type = "scenario">
- Client checks that the default exchange is active by specifying a queue
- binding with no exchange name, and publishing a message with a suitable
- routing key but without specifying the exchange name, then ensuring that
- the message arrives in the queue correctly.
- </doc>
- </rule>
- <rule name = "default-access">
- <doc>
- The server MUST NOT allow clients to access the default exchange except
- by specifying an empty exchange name in the Queue.Bind and content Publish
- methods.
- </doc>
- </rule>
- <rule name = "extensions">
- <doc>
- The server MAY implement other exchange types as wanted.
- </doc>
- </rule>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "declare" synchronous = "1" index = "10" label = "declare exchange, create if needed">
- <doc>
- This method creates an exchange if it does not already exist, and if the exchange
- exists, verifies that it is of the correct and expected class.
- </doc>
- <rule name = "minimum">
- <doc>
- The server SHOULD support a minimum of 16 exchanges per virtual host and
- ideally, impose no limit except as defined by available resources.
- </doc>
- <doc type = "scenario">
- The client creates as many exchanges as it can until the server reports
- an error; the number of exchanges successfuly created must be at least
- sixteen.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "declare-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>
- When a client defines a new exchange, this belongs to the access realm of the
- ticket used. All further work done with that exchange must be done with an
- access ticket for the same realm.
- </doc>
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MUST provide a valid access ticket giving "active" access to
- the realm in which the exchange exists or will be created, or "passive"
- access if the if-exists flag is set.
- </doc>
- <doc type = "scenario">
- Client creates access ticket with wrong access rights and attempts to use
- in this method.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <rule name = "reserved" on-failure = "access-refused">
- <doc>
- Exchange names starting with "amq." are reserved for predeclared and
- standardised exchanges. The client MUST NOT attempt to create an exchange
- starting with "amq.".
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- <assert check = "regexp" value = "^[a-zA-Z0-9-_.:]+$" />
- </field>
-
- <field name = "type" domain = "shortstr" label = "exchange type">
- <doc>
- Each exchange belongs to one of a set of exchange types implemented by the
- server. The exchange types define the functionality of the exchange - i.e. how
- messages are routed through it. It is not valid or meaningful to attempt to
- change the type of an existing exchange.
- </doc>
- <rule name = "typed" on-failure = "not-allowed">
- <doc>
- Exchanges cannot be redeclared with different types. The client MUST not
- attempt to redeclare an existing exchange with a different type than used
- in the original Exchange.Declare method.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- <rule name = "support" on-failure = "command-invalid">
- <doc>
- The client MUST NOT attempt to create an exchange with a type that the
- server does not support.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- <assert check = "regexp" value = "^[a-zA-Z0-9-_.:]+$" />
- </field>
-
- <field name = "passive" domain = "bit" label = "do not create exchange">
- <doc>
- If set, the server will not create the exchange. The client can use this to
- check whether an exchange exists without modifying the server state.
- </doc>
- <rule name = "not-found">
- <doc>
- If set, and the exchange does not already exist, the server MUST raise a
- channel exception with reply code 404 (not found).
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "durable" domain = "bit" label = "request a durable exchange">
- <doc>
- If set when creating a new exchange, the exchange will be marked as durable.
- Durable exchanges remain active when a server restarts. Non-durable exchanges
- (transient exchanges) are purged if/when a server restarts.
- </doc>
- <rule name = "support">
- <doc>
- The server MUST support both durable and transient exchanges.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- <rule name = "sticky">
- <doc>
- The server MUST ignore the durable field if the exchange already exists.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <!-- TODO 0.82 - clarify how this works; there is no way to cancel a binding
- except by deleting a queue.
- -->
- <field name = "auto-delete" domain = "bit" label = "auto-delete when unused">
- <doc>
- If set, the exchange is deleted when all queues have finished using it.
- </doc>
- <rule name = "sticky">
- <doc>
- The server MUST ignore the auto-delete field if the exchange already
- exists.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "internal" domain = "bit" label = "create internal exchange">
- <doc>
- If set, the exchange may not be used directly by publishers, but only when bound
- to other exchanges. Internal exchanges are used to construct wiring that is not
- visible to applications.
- </doc>
- </field>
-
- <field name = "arguments" domain = "table" label = "arguments for declaration">
- <doc>
- A set of arguments for the declaration. The syntax and semantics of these
- arguments depends on the server implementation. This field is ignored if passive
- is 1.
- </doc>
- </field>
- </method>
-
- <method name = "declare-ok" synchronous = "1" index = "11" label = "confirm exchange declaration">
- <doc>
- This method confirms a Declare method and confirms the name of the exchange,
- essential for automatically-named exchanges.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "delete" synchronous = "1" index = "20" label = "delete an exchange">
- <doc>
- This method deletes an exchange. When an exchange is deleted all queue bindings on
- the exchange are cancelled.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "delete-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MUST provide a valid access ticket giving "active" access
- rights to the exchange's access realm.
- </doc>
- <doc type = "scenario">
- Client creates access ticket with wrong access rights and attempts to use
- in this method.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <rule name = "exists" on-failure = "not-found">
- <doc>
- The client MUST NOT attempt to delete an exchange that does not exist.
- </doc>
- </rule>
- <assert check = "notnull" />
- </field>
-
- <!-- TODO 0.82 - discuss whether this option is useful or not. I don't have
- any real use case for it. /PH 2006-07-23.
- -->
- <field name = "if-unused" domain = "bit" label = "delete only if unused">
- <doc>
- If set, the server will only delete the exchange if it has no queue bindings. If
- the exchange has queue bindings the server does not delete it but raises a
- channel exception instead.
- </doc>
- </field>
- </method>
-
- <method name = "delete-ok" synchronous = "1" index = "21"
- label = "confirm deletion of an exchange">
- <doc>This method confirms the deletion of an exchange.</doc>
- <chassis name = "client" implement = "MUST" />
- </method>
- </class>
-
- <!-- == QUEUE ============================================================ -->
-
- <class name = "queue" handler = "channel" index = "50" label = "work with queues">
- <doc>
- Queues store and forward messages. Queues can be configured in the server or created at
- runtime. Queues must be attached to at least one exchange in order to receive messages
- from publishers.
- </doc>
-
- <doc type = "grammar">
- queue = C:DECLARE S:DECLARE-OK
- / C:BIND S:BIND-OK
- / C:PURGE S:PURGE-OK
- / C:DELETE S:DELETE-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <rule name = "any-content">
- <doc>
- A server MUST allow any content class to be sent to any queue, in any mix, and
- queue and deliver these content classes independently. Note that all methods
- that fetch content off queues are specific to a given content class.
- </doc>
- <doc type = "scenario">
- Client creates an exchange of each standard type and several queues that
- it binds to each exchange. It must then sucessfully send each of the standard
- content types to each of the available queues.
- </doc>
- </rule>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "declare" synchronous = "1" index = "10" label = "declare queue, create if needed">
- <doc>
- This method creates or checks a queue. When creating a new queue the client can
- specify various properties that control the durability of the queue and its
- contents, and the level of sharing for the queue.
- </doc>
-
- <rule name = "default-binding">
- <doc>
- The server MUST create a default binding for a newly-created queue to the
- default exchange, which is an exchange of type 'direct'.
- </doc>
- <doc type = "scenario">
- Client creates a new queue, and then without explicitly binding it to an
- exchange, attempts to send a message through the default exchange binding,
- i.e. publish a message to the empty exchange, with the queue name as routing
- key.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_35" -->
- <rule name = "minimum-queues">
- <doc>
- The server SHOULD support a minimum of 256 queues per virtual host and ideally,
- impose no limit except as defined by available resources.
- </doc>
- <doc type = "scenario">
- Client attempts to create as many queues as it can until the server reports
- an error. The resulting count must at least be 256.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "declare-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>
- When a client defines a new queue, this belongs to the access realm of the
- ticket used. All further work done with that queue must be done with an access
- ticket for the same realm.
- </doc>
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MUST provide a valid access ticket giving "active" access to
- the realm in which the queue exists or will be created.
- </doc>
- <doc type = "scenario">
- Client creates access ticket with wrong access rights and attempts to use
- in this method.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <rule name = "default-name">
- <doc>
- The queue name MAY be empty, in which case the server MUST create a new
- queue with a unique generated name and return this to the client in the
- Declare-Ok method.
- </doc>
- <doc type = "scenario">
- Client attempts to create several queues with an empty name. The client then
- verifies that the server-assigned names are unique and different.
- </doc>
- </rule>
- <rule name = "reserved-prefix" on-failure = "not-allowed">
- <doc>
- Queue names starting with "amq." are reserved for predeclared and
- standardised server queues. A client MAY NOT attempt to declare a queue with a
- name that starts with "amq." and the passive option set to zero.
- </doc>
- <doc type = "scenario">
- A client attempts to create a queue with a name starting with "amq." and with
- the passive option set to zero.
- </doc>
- </rule>
- <assert check = "regexp" value = "^[a-zA-Z0-9-_.:]*$" />
- </field>
-
- <field name = "passive" domain = "bit" label = "do not create queue">
- <doc>
- If set, the server will not create the queue. This field allows the client
- to assert the presence of a queue without modifying the server state.
- </doc>
- <rule name = "passive" on-failure = "not-found">
- <doc>
- The client MAY ask the server to assert that a queue exists without
- creating the queue if not. If the queue does not exist, the server
- treats this as a failure.
- </doc>
- <doc type = "scenario">
- Client declares an existing queue with the passive option and expects
- the server to respond with a declare-ok. Client then attempts to declare
- a non-existent queue with the passive option, and the server must close
- the channel with the correct reply-code.
- </doc>
- </rule>
- </field>
-
- <field name = "durable" domain = "bit" label = "request a durable queue">
- <doc>
- If set when creating a new queue, the queue will be marked as durable. Durable
- queues remain active when a server restarts. Non-durable queues (transient
- queues) are purged if/when a server restarts. Note that durable queues do not
- necessarily hold persistent messages, although it does not make sense to send
- persistent messages to a transient queue.
- </doc>
- <!-- Rule test name: was "amq_queue_03" -->
- <rule name = "persistence">
- <doc>The server MUST recreate the durable queue after a restart.</doc>
-
- <!-- TODO: use 'client does something' rather than 'a client does something'. -->
- <doc type = "scenario">
- A client creates a durable queue. The server is then restarted. The client
- then attempts to send a message to the queue. The message should be successfully
- delivered.
- </doc>
- </rule>
- <!-- Rule test name: was "amq_queue_36" -->
- <rule name = "types">
- <doc>The server MUST support both durable and transient queues.</doc>
- <doc type = "scenario">
- A client creates two named queues, one durable and one transient.
- </doc>
- </rule>
- <!-- Rule test name: was "amq_queue_37" -->
- <rule name = "pre-existence">
- <doc>The server MUST ignore the durable field if the queue already exists.</doc>
- <doc type = "scenario">
- A client creates two named queues, one durable and one transient. The client
- then attempts to declare the two queues using the same names again, but reversing
- the value of the durable flag in each case. Verify that the queues still exist
- with the original durable flag values.
- <!-- TODO: but how? -->
- </doc>
- </rule>
- </field>
-
- <field name = "exclusive" domain = "bit" label = "request an exclusive queue">
- <doc>
- Exclusive queues may only be consumed from by the current connection. Setting
- the 'exclusive' flag always implies 'auto-delete'.
- </doc>
-
- <!-- Rule test name: was "amq_queue_38" -->
- <rule name = "types">
- <doc>
- The server MUST support both exclusive (private) and non-exclusive (shared)
- queues.
- </doc>
- <doc type = "scenario">
- A client creates two named queues, one exclusive and one non-exclusive.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_04" -->
- <rule name = "02" on-failure = "channel-error">
- <doc>
- The client MAY NOT attempt to declare any existing and exclusive queue
- on multiple connections.
- </doc>
- <doc type = "scenario">
- A client declares an exclusive named queue. A second client on a different
- connection attempts to declare a queue of the same name.
- </doc>
- </rule>
- </field>
-
- <field name = "auto-delete" domain = "bit" label = "auto-delete queue when unused">
- <doc>
- If set, the queue is deleted when all consumers have finished using it. Last
- consumer can be cancelled either explicitly or because its channel is closed. If
- there was no consumer ever on the queue, it won't be deleted.
- </doc>
-
- <!-- Rule test name: was "amq_queue_31" -->
- <rule name = "pre-existence">
- <doc>
- The server MUST ignore the auto-delete field if the queue already exists.
- </doc>
- <doc type = "scenario">
- A client creates two named queues, one as auto-delete and one explicit-delete.
- The client then attempts to declare the two queues using the same names again,
- but reversing the value of the auto-delete field in each case. Verify that the
- queues still exist with the original auto-delete flag values.
- <!-- TODO: but how? -->
- </doc>
- </rule>
- </field>
-
- <field name = "arguments" domain = "table" label = "arguments for declaration">
- <doc>
- A set of arguments for the declaration. The syntax and semantics of these
- arguments depends on the server implementation. This field is ignored if passive
- is 1.
- </doc>
- </field>
- </method>
-
- <method name = "declare-ok" synchronous = "1" index = "11" label = "confirms a queue definition">
- <doc>
- This method confirms a Declare method and confirms the name of the queue, essential
- for automatically-named queues.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Reports the name of the queue. If the server generated a queue name, this field
- contains that name.
- </doc>
- <assert check = "notnull" />
- </field>
-
- <field name = "message-count" domain = "long" label = "number of messages in queue">
- <doc>
- Reports the number of messages in the queue, which will be zero for
- newly-created queues.
- </doc>
- </field>
-
- <field name = "consumer-count" domain = "long" label = "number of consumers">
- <doc>
- Reports the number of active consumers for the queue. Note that consumers can
- suspend activity (Channel.Flow) in which case they do not appear in this count.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "bind" synchronous = "1" index = "20" label = "bind queue to an exchange">
- <doc>
- This method binds a queue to an exchange. Until a queue is bound it will not receive
- any messages. In a classic messaging model, store-and-forward queues are bound to a
- dest exchange and subscription queues are bound to a dest_wild exchange.
- </doc>
-
- <!-- Rule test name: was "amq_queue_25" -->
- <rule name = "duplicates">
- <doc>
- A server MUST allow ignore duplicate bindings - that is, two or more bind
- methods for a specific queue, with identical arguments - without treating these
- as an error.
- </doc>
- <doc type = "scenario">
- A client binds a named queue to an exchange. The client then repeats the bind
- (with identical arguments).
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_39" -->
- <rule name = "failure" on-failure = "??????">
- <!--
- TODO: Find correct code. The on-failure code returned should depend on why the bind
- failed. Assuming that failures owing to bad parameters are covered in the rules relating
- to those parameters, the only remaining reason for a failure would be the lack of
- server resorces or some internal error - such as too many queues open. Would these
- cases qualify as "resource error" 506 or "internal error" 541?
- -->
- <doc>If a bind fails, the server MUST raise a connection exception.</doc>
- <doc type = "scenario">
- TODO
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_12" -->
- <rule name = "transient-exchange" on-failure = "not-allowed">
- <doc>
- The server MUST NOT allow a durable queue to bind to a transient exchange.
- </doc>
- <doc type = "scenario">
- A client creates a transient exchange. The client then declares a named durable
- queue and then attempts to bind the transient exchange to the durable queue.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_13" -->
- <rule name = "durable-exchange">
- <doc>
- Bindings for durable queues are automatically durable and the server SHOULD
- restore such bindings after a server restart.
- </doc>
- <doc type = "scenario">
- A server creates a named durable queue and binds it to a durable exchange. The
- server is restarted. The client then attempts to use the queue/exchange combination.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_17" -->
- <rule name = "internal-exchange">
- <doc>
- If the client attempts to bind to an exchange that was declared as internal, the server
- MUST raise a connection exception with reply code 530 (not allowed).
- </doc>
- <doc type = "scenario">
- A client attempts to bind a named queue to an internal exchange.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_40" -->
- <rule name = "binding-count">
- <doc>
- The server SHOULD support at least 4 bindings per queue, and ideally, impose no
- limit except as defined by available resources.
- </doc>
- <doc type = "scenario">
- A client creates a named queue and attempts to bind it to 4 different non-internal
- exchanges.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "bind-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>
- The client provides a valid access ticket giving "active" access rights to the
- queue's access realm.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to bind. If the queue name is empty, refers to
- the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "empty-queue" on-failure = "not-allowed">
- <doc>
- A client MUST NOT be allowed to bind a non-existent and unnamed queue (i.e.
- empty queue name) to an exchange.
- </doc>
- <doc type = "scenario">
- A client attempts to bind with an unnamed (empty) queue name to an exchange.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_26" -->
- <rule name = "queue-existence" on-failure = "not-found">
- <doc>
- A client MUST NOT be allowed to bind a non-existent queue (i.e. not previously
- declared) to an exchange.
- </doc>
- <doc type = "scenario">
- A client attempts to bind an undeclared queue name to an exchange.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name" label = "name of the exchange to bind to">
- <!-- Rule test name: was "amq_queue_14" -->
- <rule name = "exchange-existence" on-failure = "not-found">
- <doc>
- A client MUST NOT be allowed to bind a queue to a non-existent exchange.
- </doc>
- <doc type = "scenario">
- A client attempts to bind an named queue to a undeclared exchange.
- </doc>
- </rule>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "message routing key">
- <doc>
- Specifies the routing key for the binding. The routing key is used for routing
- messages depending on the exchange configuration. Not all exchanges use a
- routing key - refer to the specific exchange documentation. If the queue name
- is empty, the server uses the last queue declared on the channel. If the
- routing key is also empty, the server uses this queue name for the routing
- key as well. If the queue name is provided but the routing key is empty, the
- server does the binding with that empty routing key. The meaning of empty
- routing keys depends on the exchange implementation.
- </doc>
- </field>
-
- <field name = "arguments" domain = "table" label = "arguments for binding">
- <doc>
- A set of arguments for the binding. The syntax and semantics of these arguments
- depends on the exchange class.
- </doc>
- </field>
- </method>
-
- <method name = "bind-ok" synchronous = "1" index = "21" label = "confirm bind successful">
- <doc>This method confirms that the bind was successful.</doc>
-
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "purge" synchronous = "1" index = "30" label = "purge a queue">
- <doc>
- This method removes all messages from a queue. It does not cancel consumers. Purged
- messages are deleted without any formal "undo" mechanism.
- </doc>
-
- <!-- Rule test name: was "amq_queue_15" -->
- <rule name = "01">
- <doc>A call to purge MUST result in an empty queue.</doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_41" -->
- <rule name = "02">
- <doc>
- On transacted channels the server MUST not purge messages that have already been
- sent to a client but not yet acknowledged.
- </doc>
- </rule>
-
- <!-- TODO: Rule split? -->
-
- <!-- Rule test name: was "amq_queue_42" -->
- <rule name = "03">
- <doc>
- The server MAY implement a purge queue or log that allows system administrators
- to recover accidentally-purged messages. The server SHOULD NOT keep purged
- messages in the same storage spaces as the live messages since the volumes of
- purged messages may get very large.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "purge-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>The access ticket must be for the access realm that holds the queue.</doc>
-
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the queue's access realm. Note that purging a queue is equivalent to reading
- all messages and discarding them.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to purge. If the queue name is empty, refers to
- the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- </rule>
-
- <!-- TODO Rule split? -->
-
- <!-- Rule test name: was "amq_queue_16" -->
- <rule name = "02">
- <doc>
- The queue MUST exist. Attempting to purge a non-existing queue MUST cause a
- channel exception.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "purge-ok" synchronous = "1" index = "31" label = "confirms a queue purge">
- <doc>This method confirms the purge of a queue.</doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "message-count" domain = "long" label = "number of messages purged">
- <doc>Reports the number of messages purged.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "delete" synchronous = "1" index = "40" label = "delete a queue">
- <doc>
- This method deletes a queue. When a queue is deleted any pending messages are sent
- to a dead-letter queue if this is defined in the server configuration, and all
- consumers on the queue are cancelled.
- </doc>
-
- <!-- TODO: Rule split? -->
-
- <!-- Rule test name: was "amq_queue_43" -->
- <rule name = "01">
- <doc>
- The server SHOULD use a dead-letter queue to hold messages that were pending on
- a deleted queue, and MAY provide facilities for a system administrator to move
- these messages back to an active queue.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "delete-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>
- The client provides a valid access ticket giving "active" access rights to the
- queue's access realm.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to delete. If the queue name is empty, refers to
- the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_21" -->
- <rule name = "02">
- <doc>
- The queue must exist. If the client attempts to delete a non-existing queue
- the server MUST raise a channel exception with reply code 404 (not found).
- </doc>
- </rule>
- </field>
-
- <field name = "if-unused" domain = "bit" label = "delete only if unused">
- <doc>
- If set, the server will only delete the queue if it has no consumers. If the
- queue has consumers the server does does not delete it but raises a channel
- exception instead.
- </doc>
-
- <!-- Rule test name: was "amq_queue_29" and "amq_queue_30" -->
- <rule name = "01">
- <doc>The server MUST respect the if-unused flag when deleting a queue.</doc>
- </rule>
- </field>
-
- <field name = "if-empty" domain = "bit" label = "delete only if empty">
- <doc>
- If set, the server will only delete the queue if it has no messages.
- </doc>
- <rule name = "01">
- <doc>
- If the queue is not empty the server MUST raise a channel exception with
- reply code 406 (precondition failed).
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "delete-ok" synchronous = "1" index = "41" label = "confirm deletion of a queue">
- <doc>This method confirms the deletion of a queue.</doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "message-count" domain = "long" label = "number of messages purged">
- <doc>Reports the number of messages purged.</doc>
- </field>
- </method>
- </class>
-
- <!-- == BASIC ============================================================ -->
-
- <class name = "basic" handler = "channel" index = "60" label = "work with basic content">
- <doc>
- The Basic class provides methods that support an industry-standard messaging model.
- </doc>
-
- <doc type = "grammar">
- basic = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:PUBLISH content
- / S:RETURN content
- / S:DELIVER content
- / C:GET ( S:GET-OK content / S:GET-EMPTY )
- / C:ACK
- / C:REJECT
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MAY" />
-
- <!-- Rule test name: was "amq_basic_08" -->
- <rule name = "01">
- <doc>
- The server SHOULD respect the persistent property of basic messages and
- SHOULD make a best-effort to hold persistent basic messages on a reliable
- storage mechanism.
- </doc>
- <doc type = "scenario">
- Send a persistent message to queue, stop server, restart server and then
- verify whether message is still present. Assumes that queues are durable.
- Persistence without durable queues makes no sense.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_09" -->
- <rule name = "02">
- <doc>
- The server MUST NOT discard a persistent basic message in case of a queue
- overflow.
- </doc>
- <doc type = "scenario">
- Create a queue overflow situation with persistent messages and verify that
- messages do not get lost (presumably the server will write them to disk).
- </doc>
- </rule>
-
- <rule name = "03">
- <doc>
- The server MAY use the Channel.Flow method to slow or stop a basic message
- publisher when necessary.
- </doc>
- <doc type = "scenario">
- Create a queue overflow situation with non-persistent messages and verify
- whether the server responds with Channel.Flow or not. Repeat with persistent
- messages.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_10" -->
- <rule name = "04">
- <doc>
- The server MAY overflow non-persistent basic messages to persistent
- storage.
- </doc>
- <!-- Test scenario: untestable -->
- </rule>
-
- <rule name = "05">
- <doc>
- The server MAY discard or dead-letter non-persistent basic messages on a
- priority basis if the queue size exceeds some configured limit.
- </doc>
- <!-- Test scenario: untestable -->
- </rule>
-
- <!-- Rule test name: was "amq_basic_11" -->
- <rule name = "06">
- <doc>
- The server MUST implement at least 2 priority levels for basic messages,
- where priorities 0-4 and 5-9 are treated as two distinct levels.
- </doc>
- <doc type = "scenario">
- Send a number of priority 0 messages to a queue. Send one priority 9
- message. Consume messages from the queue and verify that the first message
- received was priority 9.
- </doc>
- </rule>
-
- <rule name = "07">
- <doc>
- The server MAY implement up to 10 priority levels.
- </doc>
- <doc type = "scenario">
- Send a number of messages with mixed priorities to a queue, so that all
- priority values from 0 to 9 are exercised. A good scenario would be ten
- messages in low-to-high priority. Consume from queue and verify how many
- priority levels emerge.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_12" -->
- <rule name = "08">
- <doc>
- The server MUST deliver messages of the same priority in order irrespective of
- their individual persistence.
- </doc>
- <doc type = "scenario">
- Send a set of messages with the same priority but different persistence
- settings to a queue. Consume and verify that messages arrive in same order
- as originally published.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_13" -->
- <rule name = "09">
- <doc>
- The server MUST support automatic acknowledgements on Basic content, i.e.
- consumers with the no-ack field set to FALSE.
- </doc>
- <doc type = "scenario">
- Create a queue and a consumer using automatic acknowledgements. Publish
- a set of messages to the queue. Consume the messages and verify that all
- messages are received.
- </doc>
- </rule>
-
- <rule name = "10">
- <doc>
- The server MUST support explicit acknowledgements on Basic content, i.e.
- consumers with the no-ack field set to TRUE.
- </doc>
- <doc type = "scenario">
- Create a queue and a consumer using explicit acknowledgements. Publish a
- set of messages to the queue. Consume the messages but acknowledge only
- half of them. Disconnect and reconnect, and consume from the queue.
- Verify that the remaining messages are received.
- </doc>
- </rule>
-
- <!-- These are the properties for a Basic content -->
-
- <field name = "content-type" domain = "shortstr" label = "MIME content type" />
- <field name = "content-encoding" domain = "shortstr" label = "MIME content encoding" />
- <field name = "headers" domain = "table" label = "message header field table" />
- <field name = "delivery-mode" domain = "octet" label = "non-persistent (1) or persistent (2)" />
- <field name = "priority" domain = "short" label = "message priority, 0 to 9" />
- <field name = "correlation-id" domain = "shortstr" label = "application correlation identifier" />
- <field name = "reply-to" domain = "shortstr" label = "destination to reply to" />
- <field name = "expiration" domain = "shortstr" label = "message expiration specification" />
- <field name = "timestamp" domain = "timestamp" label = "message timestamp" />
- <field name = "message-id" domain = "shortstr" label = "application message identifier" />
- <field name = "type" domain = "shortstr" label = "message type name" />
- <field name = "user-id" domain = "shortstr" label = "creating user id" />
- <field name = "app-id" domain = "shortstr" label = "creating application id" />
- <!-- This field is deprecated pending review -->
- <field name = "cluster-id" domain = "shortstr" label = "intra-cluster routing identifier" />
-
- <!-- Type diversity test -->
- <field name = "property-bit" domain = "bit" label = "Extra property for testing only" />
- <field name = "property-octet" domain = "octet" label = "Extra property for testing only" />
- <field name = "property-short" domain = "short" label = "Extra property for testing only" />
- <field name = "property-long" domain = "long" label = "Extra property for testing only" />
- <field name = "property-longlong" domain = "longlong" label = "Extra property for testing only" />
- <field name = "property-shortstr" domain = "shortstr" label = "Extra property for testing only" />
- <field name = "property-longstr" domain = "longstr" label = "Extra property for testing only" />
- <field name = "property-timestamp" domain = "timestamp" label = "Extra property for testing only" />
- <field name = "property-table" domain = "table" label = "Extra property for testing only" />
- <field name = "property-access-ticket" domain = "access-ticket" label = "Extra property for testing only" />
- <field name = "property-class-id" domain = "class-id" label = "Extra property for testing only" />
- <field name = "property-consumer-tag" domain = "consumer-tag" label = "Extra property for testing only" />
- <field name = "property-delivery-tag" domain = "delivery-tag" label = "Extra property for testing only" />
- <field name = "property-exchange-name" domain = "exchange-name" label = "Extra property for testing only" />
- <field name = "property-known-hosts" domain = "known-hosts" label = "Extra property for testing only" />
- <field name = "property-method-id" domain = "method-id" label = "Extra property for testing only" />
- <field name = "property-no-ack" domain = "no-ack" label = "Extra property for testing only" />
- <field name = "property-no-local" domain = "no-local" label = "Extra property for testing only" />
- <field name = "property-path" domain = "path" label = "Extra property for testing only" />
- <field name = "property-peer-properties" domain = "peer-properties" label = "Extra property for testing only" />
- <field name = "property-queue-name" domain = "queue-name" label = "Extra property for testing only" />
- <field name = "property-redelivered" domain = "redelivered" label = "Extra property for testing only" />
- <field name = "property-reply-code" domain = "reply-code" label = "Extra property for testing only" />
- <field name = "property-reply-text" domain = "reply-text" label = "Extra property for testing only" />
-
- <!-- Bit field test -->
- <field name = "property-long-A" domain = "long" label = "Extra property for testing only" />
- <field name = "property-bit-B" domain = "bit" label = "Extra property for testing only" />
- <field name = "property-bit-C" domain = "bit" label = "Extra property for testing only" />
- <field name = "property-bit-D" domain = "bit" label = "Extra property for testing only" />
- <field name = "property-bit-E" domain = "bit" label = "Extra property for testing only" />
- <field name = "property-bit-F" domain = "bit" label = "Extra property for testing only" />
- <field name = "property-shortstr-G" domain = "shortstr" label = "Extra property for testing only" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "qos" synchronous = "1" index = "10" label = "specify quality of service">
- <doc>
- This method requests a specific quality of service. The QoS can be specified for the
- current channel or for all channels on the connection. The particular properties and
- semantics of a qos method always depend on the content class semantics. Though the
- qos method could in principle apply to both peers, it is currently meaningful only
- for the server.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "qos-ok" />
-
- <field name = "prefetch-size" domain = "long" label = "prefetch window in octets">
- <doc>
- The client can request that messages be sent in advance so that when the client
- finishes processing a message, the following message is already held locally,
- rather than needing to be sent down the channel. Prefetching gives a performance
- improvement. This field specifies the prefetch window size in octets. The server
- will send a message in advance if it is equal to or smaller in size than the
- available prefetch size (and also falls into other prefetch limits). May be set
- to zero, meaning "no specific limit", although other prefetch limits may still
- apply. The prefetch-size is ignored if the no-ack option is set.
- </doc>
- <!-- Rule test name: was "amq_basic_17" -->
- <rule name = "01">
- <doc>
- The server MUST ignore this setting when the client is not processing any
- messages - i.e. the prefetch size does not limit the transfer of single
- messages to a client, only the sending in advance of more messages while
- the client still has one or more unacknowledged messages.
- </doc>
- <doc type = "scenario">
- Define a QoS prefetch-size limit and send a single message that exceeds
- that limit. Verify that the message arrives correctly.
- </doc>
- </rule>
- </field>
-
- <field name = "prefetch-count" domain = "short" label = "prefetch window in messages">
- <doc>
- Specifies a prefetch window in terms of whole messages. This field may be used
- in combination with the prefetch-size field; a message will only be sent in
- advance if both prefetch windows (and those at the channel and connection level)
- allow it. The prefetch-count is ignored if the no-ack option is set.
- </doc>
- <!-- Rule test name: was "amq_basic_18" -->
- <rule name = "01">
- <doc>
- The server may send less data in advance than allowed by the client's
- specified prefetch windows but it MUST NOT send more.
- </doc>
- <doc type = "scenario">
- Define a QoS prefetch-size limit and a prefetch-count limit greater than
- one. Send multiple messages that exceed the prefetch size. Verify that
- no more than one message arrives at once.
- </doc>
- </rule>
- </field>
-
- <field name = "global" domain = "bit" label = "apply to entire connection">
- <doc>
- By default the QoS settings apply to the current channel only. If this field is
- set, they are applied to the entire connection.
- </doc>
- </field>
- </method>
-
- <method name = "qos-ok" synchronous = "1" index = "11" label = "confirm the requested qos">
- <doc>
- This method tells the client that the requested QoS levels could be handled by the
- server. The requested QoS applies to all active consumers until a new QoS is
- defined.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "consume" synchronous = "1" index = "20" label = "start a queue consumer">
- <doc>
- This method asks the server to start a "consumer", which is a transient request for
- messages from a specific queue. Consumers last as long as the channel they were
- created on, or until the client cancels them.
- </doc>
-
- <!-- Rule test name: was "amq_basic_01" -->
- <rule name = "01">
- <doc>
- The server SHOULD support at least 16 consumers per queue, and ideally, impose
- no limit except as defined by available resources.
- </doc>
- <doc type = "scenario">
- Create a queue and create consumers on that queue until the server closes the
- connection. Verify that the number of consumers created was at least sixteen
- and report the total number.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01" on-failure = "access-refused">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the realm for the queue.
- </doc>
- <doc type = "scenario">
- Attempt to create a consumer with an invalid (non-zero) access ticket.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name is null,
- refers to the current queue for the channel, which is the last declared queue.
- </doc>
- <rule name = "01" on-failure = "not-allowed">
- <doc>
- If the queue name is empty the client MUST have previously declared a
- queue using this channel.
- </doc>
- <doc type = "scenario">
- Attempt to create a consumer with an empty queue name and no previously
- declared queue on the channel.
- </doc>
- </rule>
- </field>
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is local to a
- connection, so two clients can use the same consumer tags. If this field is
- empty the server will generate a unique tag.
- </doc>
- <rule name = "01" on-failure = "not-allowed">
- <doc>
- The client MUST NOT specify a tag that refers to an existing consumer.
- </doc>
- <doc type = "scenario">
- Attempt to create two consumers with the same non-empty tag.
- </doc>
- </rule>
- <rule name = "02" on-failure = "not-allowed">
- <doc>
- The consumer tag is valid only within the channel from which the
- consumer was created. I.e. a client MUST NOT create a consumer in one
- channel and then use it in another.
- </doc>
- <doc type = "scenario">
- Attempt to create a consumer in one channel, then use in another channel,
- in which consumers have also been created (to test that the server uses
- unique consumer tags).
- </doc>
- </rule>
- </field>
-
- <field name = "no-local" domain = "no-local" />
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise
- a channel or connection exception.
- </doc>
- </field>
-
- <field name = "bit-test-1" domain = "bit" />
- <field name = "bit-test-2" domain = "bit" />
- <field name = "bit-test-3" domain = "bit" />
- <field name = "bit-test-4" domain = "bit" />
- <field name = "bit-test-5" domain = "bit" />
- <field name = "bit-test-6" domain = "bit" />
- <field name = "bit-test-7" domain = "bit" />
- <field name = "bit-test-8" domain = "bit" />
- <field name = "bit-test-9" domain = "bit" />
-
- <field name = "no-ack" domain = "short" />
-
- <field name = "exclusive" domain = "bit" label = "request exclusive access">
- <doc>
- Request exclusive consumer access, meaning only this consumer can access the
- queue.
- </doc>
- <!-- Rule test name: was "amq_basic_02" -->
- <rule name = "01" on-failure = "access-refused">
- <doc>
- The client MAY NOT gain exclusive access to a queue that already has
- active consumers.
- </doc>
- <doc type = "scenario">
- Open two connections to a server, and in one connection create a shared
- (non-exclusive) queue and then consume from the queue. In the second
- connection attempt to consume from the same queue using the exclusive
- option.
- </doc>
- </rule>
- </field>
-
- <field name = "priority" domain = "short" label = "consume priority"/>
- </method>
-
- <method name = "consume-ok" synchronous = "1" index = "21" label = "confirm a new consumer">
- <doc>
- The server provides the client with a consumer tag, which is used by the client
- for methods called on the consumer at a later stage.
- </doc>
- <chassis name = "client" implement = "MUST" />
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>
- Holds the consumer tag specified by the client or provided by the server.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "cancel" synchronous = "1" index = "30" label = "end a queue consumer">
- <doc>
- This method cancels a consumer. This does not affect already delivered
- messages, but it does mean the server will not send any more messages for
- that consumer. The client may receive an abitrary number of messages in
- between sending the cancel method and receiving the cancel-ok reply.
- </doc>
-
- <rule name = "01">
- <doc>
- If the queue does not exist the server MUST ignore the cancel method, so
- long as the consumer tag is valid for that channel.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "cancel-ok" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <method name = "cancel-ok" synchronous = "1" index = "31" label = "confirm a cancelled consumer">
- <doc>
- This method confirms that the cancellation was completed.
- </doc>
- <chassis name = "client" implement = "MUST" />
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "publish" content = "1" index = "40" label = "publish a message">
- <doc>
- This method publishes a message to a specific exchange. The message will be routed
- to queues as defined by the exchange configuration and distributed to any active
- consumers when the transaction, if any, is committed.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "write" access rights
- to the access realm for the exchange.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange name can be
- empty, meaning the default exchange. If the exchange name is specified, and that
- exchange does not exist, the server will raise a channel exception.
- </doc>
-
- <!-- Rule test name: was "amq_basic_06" -->
- <rule name = "01">
- <doc>
- The server MUST accept a blank exchange name to mean the default exchange.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_14" -->
- <rule name = "02">
- <doc>
- If the exchange was declared as an internal exchange, the server MUST raise
- a channel exception with a reply code 403 (access refused).
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_15" -->
- <rule name = "03">
- <doc>
- The exchange MAY refuse basic content in which case it MUST raise a channel
- exception with reply code 540 (not implemented).
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>
- Specifies the routing key for the message. The routing key is used for routing
- messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" domain = "bit" label = "indicate mandatory routing">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue. If this flag is set, the server will return an unroutable message with a
- Return method. If this flag is zero, the server silently drops the message.
- </doc>
- <!-- Rule test name: was "amq_basic_07" -->
- <rule name = "01">
- <doc>
- The server SHOULD implement the mandatory flag.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "immediate" domain = "bit" label = "request immediate delivery">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue consumer immediately. If this flag is set, the server will return an
- undeliverable message with a Return method. If this flag is zero, the server
- will queue the message, but with no guarantee that it will ever be consumed.
- </doc>
- <!-- Rule test name: was "amq_basic_16" -->
- <rule name = "01">
- <doc>
- The server SHOULD implement the immediate flag.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "return" content = "1" index = "50" label = "return a failed message">
- <doc>
- This method returns an undeliverable message that was published with the "immediate"
- flag set, or an unroutable message published with the "mandatory" flag set. The
- reply code and text provide information about the reason that the message was
- undeliverable.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply-code" domain = "reply-code" />
-
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>
- Specifies the routing key name specified when the message was published.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "deliver" content = "1" index = "60"
- label = "notify the client of a consumer message">
- <doc>
- This method delivers a message to the client, via a consumer. In the asynchronous
- message delivery model, the client starts a consumer using the Consume method, then
- the server responds with Deliver methods as and when messages arrive for that
- consumer.
- </doc>
-
- <!-- Rule test name: was "amq_basic_19" -->
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server SHOULD track the number of times a message has been delivered to
- clients and when a message is redelivered a certain number of times - e.g. 5
- times - without being acknowledged, the server SHOULD consider the message to be
- unprocessable (possibly causing client applications to abort), and move the
- message to a dead letter queue.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "get" synchronous = "1" index = "70" label = "direct access to a queue">
- <doc>
- This method provides a direct access to the messages in a queue using a synchronous
- dialogue that is designed for specific types of application where synchronous
- functionality is more important than performance.
- </doc>
-
- <response name = "get-ok" />
- <response name = "get-empty" />
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the realm for the queue.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name is null,
- refers to the current queue for the channel, which is the last declared queue.
- </doc>
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "no-ack" domain = "no-ack" />
- </method>
-
- <method name = "get-ok" synchronous = "1" content = "1" index = "71"
- label = "provide client with a message">
- <doc>
- This method delivers a message to the client following a get method. A message
- delivered by 'get-ok' must be acknowledged unless the no-ack option was set in the
- get method.
- </doc>
-
- <chassis name = "client" implement = "MAY" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- If empty, the message was published to the default exchange.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
-
- <field name = "message-count" domain = "long" label = "number of messages pending">
- <doc>
- This field reports the number of messages pending on the queue, excluding the
- message being delivered. Note that this figure is indicative, not reliable, and
- can change arbitrarily as messages are added to the queue and removed by other
- clients.
- </doc>
- </field>
- </method>
-
- <method name = "get-empty" synchronous = "1" index = "72"
- label = "indicate no messages available">
- <doc>
- This method tells the client that the queue has no messages available for the
- client.
- </doc>
-
- <chassis name = "client" implement = "MAY" />
-
- <!-- This field is deprecated pending review -->
- <field name = "cluster-id" domain = "shortstr" label = "Cluster id">
- <doc>
- For use by cluster applications, should not be used by client applications.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "ack" index = "80" label = "acknowledge one or more messages">
- <doc>
- This method acknowledges one or more messages delivered via the Deliver or Get-Ok
- methods. The client can ask to confirm a single message or a set of messages up to
- and including a specific message.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "multiple" domain = "bit" label = "acknowledge multiple messages">
- <doc>
- If set to 1, the delivery tag is treated as "up to and including", so that the
- client can acknowledge multiple messages with a single method. If set to zero,
- the delivery tag refers to a single message. If the multiple field is 1, and the
- delivery tag is zero, tells the server to acknowledge all outstanding mesages.
- </doc>
-
- <!-- Rule test name: was "amq_basic_20" -->
- <rule name = "01">
- <doc>
- The server MUST validate that a non-zero delivery-tag refers to an delivered
- message, and raise a channel exception if this is not the case.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "reject" index = "90" label = "reject an incoming message">
- <doc>
- This method allows a client to reject a message. It can be used to interrupt and
- cancel large incoming messages, or return untreatable messages to their original
- queue.
- </doc>
-
- <!-- Rule test name: was "amq_basic_21" -->
- <rule name = "01">
- <doc>
- The server SHOULD be capable of accepting and process the Reject method while
- sending message content with a Deliver or Get-Ok method. I.e. the server should
- read and process incoming methods while sending output frames. To cancel a
- partially-send content, the server sends a content body frame of size 1 (i.e.
- with no data except the frame-end octet).
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_22" -->
- <rule name = "02">
- <doc>
- The server SHOULD interpret this method as meaning that the client is unable to
- process the message at this time.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <rule name = "03">
- <!-- TODO: Rule split? -->
- <doc>
- A client MUST NOT use this method as a means of selecting messages to process. A
- rejected message MAY be discarded or dead-lettered, not necessarily passed to
- another client.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "requeue" domain = "bit" label = "requeue the message">
- <doc>
- If this field is zero, the message will be discarded. If this bit is 1, the
- server will attempt to requeue the message.
- </doc>
-
- <!-- Rule test name: was "amq_basic_23" -->
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server MUST NOT deliver the message to the same client within the
- context of the current channel. The recommended strategy is to attempt to
- deliver the message to an alternative consumer, and if that is not possible,
- to move the message to a dead-letter queue. The server MAY use more
- sophisticated tracking to hold the message on the queue and redeliver it to
- the same client at a later stage.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "recover" index = "100" label = "redeliver unacknowledged messages">
- <doc>
- This method asks the broker to redeliver all unacknowledged messages on a specified
- channel. Zero or more messages may be redelivered. This method is only allowed on
- non-transacted channels.
- </doc>
-
- <rule name = "01">
- <doc>
- The server MUST set the redelivered flag on all messages that are resent.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <rule name = "02">
- <doc>
- The server MUST raise a channel exception if this is called on a transacted
- channel.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "requeue" domain = "bit" label = "requeue the message">
- <doc>
- If this field is zero, the message will be redelivered to the original
- recipient. If this bit is 1, the server will attempt to requeue the message,
- potentially then delivering it to an alternative subscriber.
- </doc>
- </field>
- </method>
- </class>
-
- <!-- == FILE ============================================================= -->
-
- <class name = "file" handler = "channel" index = "70" label = "work with file content">
- <doc>
- The file class provides methods that support reliable file transfer. File
- messages have a specific set of properties that are required for interoperability
- with file transfer applications. File messages and acknowledgements are subject to
- channel transactions. Note that the file class does not provide message browsing
- methods; these are not compatible with the staging model. Applications that need
- browsable file transfer should use Basic content and the Basic class.
- </doc>
-
- <doc type = "grammar">
- file = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:OPEN S:OPEN-OK C:STAGE content
- / S:OPEN C:OPEN-OK S:STAGE content
- / C:PUBLISH
- / S:DELIVER
- / S:RETURN
- / C:ACK
- / C:REJECT
- </doc>
-
- <chassis name = "server" implement = "MAY" />
- <chassis name = "client" implement = "MAY" />
-
- <rule name = "01">
- <doc>
- The server MUST make a best-effort to hold file messages on a reliable storage
- mechanism.
- </doc>
- </rule>
-
- <!-- TODO Rule implement attr inverse? -->
-
- <!-- TODO: Rule split? -->
-
- <rule name = "02">
- <doc>
- The server MUST NOT discard a file message in case of a queue overflow. The server
- MUST use the Channel.Flow method to slow or stop a file message publisher when
- necessary.
- </doc>
- </rule>
-
- <!-- TODO: Rule split? -->
-
- <rule name = "03">
- <doc>
- The server MUST implement at least 2 priority levels for file messages, where
- priorities 0-4 and 5-9 are treated as two distinct levels. The server MAY implement
- up to 10 priority levels.
- </doc>
- </rule>
-
- <rule name = "04">
- <doc>
- The server MUST support both automatic and explicit acknowledgements on file
- content.
- </doc>
- </rule>
-
- <!-- These are the properties for a File content -->
-
- <field name = "content-type" domain = "shortstr" label = "MIME content type" />
- <field name = "content-encoding" domain = "shortstr" label = "MIME content encoding" />
- <field name = "headers" domain = "table" label = "message header field table" />
- <field name = "priority" domain = "octet" label = "message priority, 0 to 9" />
- <field name = "reply-to" domain = "shortstr" label = "destination to reply to" />
- <field name = "message-id" domain = "shortstr" label = "application message identifier" />
- <field name = "filename" domain = "shortstr" label = "message filename" />
- <field name = "timestamp" domain = "timestamp" label = "message timestamp" />
- <!-- This field is deprecated pending review -->
- <field name = "cluster-id" domain = "shortstr" label = "intra-cluster routing identifier" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "qos" synchronous = "1" index = "10" label = "specify quality of service">
- <doc>
- This method requests a specific quality of service. The QoS can be specified for the
- current channel or for all channels on the connection. The particular properties and
- semantics of a qos method always depend on the content class semantics. Though the
- qos method could in principle apply to both peers, it is currently meaningful only
- for the server.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "qos-ok" />
-
- <field name = "prefetch-size" domain = "long" label = "prefetch window in octets">
- <doc>
- The client can request that messages be sent in advance so that when the client
- finishes processing a message, the following message is already held locally,
- rather than needing to be sent down the channel. Prefetching gives a performance
- improvement. This field specifies the prefetch window size in octets. May be set
- to zero, meaning "no specific limit". Note that other prefetch limits may still
- apply. The prefetch-size is ignored if the no-ack option is set.
- </doc>
- </field>
-
- <field name = "prefetch-count" domain = "short" label = "prefetch window in messages">
- <doc>
- Specifies a prefetch window in terms of whole messages. This is compatible with
- some file API implementations. This field may be used in combination with the
- prefetch-size field; a message will only be sent in advance if both prefetch
- windows (and those at the channel and connection level) allow it. The
- prefetch-count is ignored if the no-ack option is set.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server MAY send less data in advance than allowed by the client's
- specified prefetch windows but it MUST NOT send more.
- </doc>
- </rule>
- </field>
-
- <field name = "global" domain = "bit" label = "apply to entire connection">
- <doc>
- By default the QoS settings apply to the current channel only. If this field is
- set, they are applied to the entire connection.
- </doc>
- </field>
- </method>
-
- <method name = "qos-ok" synchronous = "1" index = "11" label = "confirm the requested qos">
- <doc>
- This method tells the client that the requested QoS levels could be handled by the
- server. The requested QoS applies to all active consumers until a new QoS is
- defined.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "consume" synchronous = "1" index = "20" label = "start a queue consumer">
- <doc>
- This method asks the server to start a "consumer", which is a transient request for
- messages from a specific queue. Consumers last as long as the channel they were
- created on, or until the client cancels them.
- </doc>
-
- <rule name = "01">
- <doc>
- The server SHOULD support at least 16 consumers per queue, unless the queue was
- declared as private, and ideally, impose no limit except as defined by available
- resources.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the realm for the queue.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name is null,
- refers to the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- </rule>
- </field>
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is local to a
- connection, so two clients can use the same consumer tags. If this field is
- empty the server will generate a unique tag.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The tag MUST NOT refer to an existing consumer. If the client attempts to
- create two consumers with the same non-empty tag the server MUST raise a
- connection exception with reply code 530 (not allowed).
- </doc>
- </rule>
- </field>
-
- <field name = "no-local" domain = "no-local" />
-
- <field name = "no-ack" domain = "no-ack" />
-
- <field name = "exclusive" domain = "bit" label = "request exclusive access">
- <doc>
- Request exclusive consumer access, meaning only this consumer can access the
- queue.
- </doc>
-
- <!-- Rule test name: was "amq_file_00" -->
- <rule name = "01">
- <doc>
- If the server cannot grant exclusive access to the queue when asked, -
- because there are other consumers active - it MUST raise a channel exception
- with return code 405 (resource locked).
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "consume-ok" synchronous = "1" index = "21" label = "confirm a new consumer">
- <doc>
- This method provides the client with a consumer tag which it MUST use in methods
- that work with the consumer.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>Holds the consumer tag specified by the client or provided by the server.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "cancel" synchronous = "1" index = "30" label = "end a queue consumer">
- <doc>
- This method cancels a consumer. This does not affect already delivered messages, but
- it does mean the server will not send any more messages for that consumer.
- </doc>
-
- <response name = "cancel-ok" />
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <method name = "cancel-ok" synchronous = "1" index = "31" label = "confirm a cancelled consumer">
- <doc>This method confirms that the cancellation was completed.</doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "open" synchronous = "1" index = "40" label = "request to start staging">
- <doc>
- This method requests permission to start staging a message. Staging means sending
- the message into a temporary area at the recipient end and then delivering the
- message by referring to this temporary area. Staging is how the protocol handles
- partial file transfers - if a message is partially staged and the connection breaks,
- the next time the sender starts to stage it, it can restart from where it left off.
- </doc>
-
- <response name = "open-ok" />
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <field name = "identifier" domain = "shortstr" label = "staging identifier">
- <doc>
- This is the staging identifier. This is an arbitrary string chosen by the
- sender. For staging to work correctly the sender must use the same staging
- identifier when staging the same message a second time after recovery from a
- failure. A good choice for the staging identifier would be the SHA1 hash of the
- message properties data (including the original filename, revised time, etc.).
- </doc>
- </field>
-
- <field name = "content-size" domain = "longlong" label = "message content size">
- <doc>
- The size of the content in octets. The recipient may use this information to
- allocate or check available space in advance, to avoid "disk full" errors during
- staging of very large messages.
- </doc>
-
- <rule name = "01">
- <doc>
- The sender MUST accurately fill the content-size field. Zero-length content
- is permitted.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "open-ok" synchronous = "1" index = "41" label = "confirm staging ready">
- <doc>
- This method confirms that the recipient is ready to accept staged data. If the
- message was already partially-staged at a previous time the recipient will report
- the number of octets already staged.
- </doc>
-
- <response name = "stage" />
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <field name = "staged-size" domain = "longlong" label = "already staged amount">
- <doc>
- The amount of previously-staged content in octets. For a new message this will
- be zero.
- </doc>
-
- <rule name = "01">
- <doc>
- The sender MUST start sending data from this octet offset in the message,
- counting from zero.
- </doc>
- </rule>
-
- <rule name = "02">
- <!-- TODO: Rule split? -->
- <doc>
- The recipient MAY decide how long to hold partially-staged content and MAY
- implement staging by always discarding partially-staged content. However if
- it uses the file content type it MUST support the staging methods.
- </doc>
- </rule>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "stage" content = "1" index = "50" label = "stage message content">
- <doc>
- This method stages the message, sending the message content to the recipient from
- the octet offset specified in the Open-Ok method.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "publish" index = "60" label = "publish a message">
- <doc>
- This method publishes a staged file message to a specific exchange. The file message
- will be routed to queues as defined by the exchange configuration and distributed to
- any active consumers when the transaction, if any, is committed.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "write" access rights
- to the access realm for the exchange.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange name can be
- empty, meaning the default exchange. If the exchange name is specified, and that
- exchange does not exist, the server will raise a channel exception.
- </doc>
-
- <rule name = "01">
- <doc>
- The server MUST accept a blank exchange name to mean the default exchange.
- </doc>
- </rule>
-
- <rule name = "02">
- <doc>
- If the exchange was declared as an internal exchange, the server MUST
- respond with a reply code 403 (access refused) and raise a channel
- exception.
- </doc>
- </rule>
-
- <!-- TODO: Rule split? -->
-
- <rule name = "03">
- <doc>
- The exchange MAY refuse file content in which case it MUST respond with a
- reply code 540 (not implemented) and raise a channel exception.
- </doc>
- </rule>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>
- Specifies the routing key for the message. The routing key is used for routing
- messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" domain = "bit" label = "indicate mandatory routing">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue. If this flag is set, the server will return an unroutable message with a
- Return method. If this flag is zero, the server silently drops the message.
- </doc>
-
- <!-- Rule test name: was "amq_file_00" -->
- <rule name = "01">
- <doc>The server SHOULD implement the mandatory flag.</doc>
- </rule>
- </field>
-
- <field name = "immediate" domain = "bit" label = "request immediate delivery">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue consumer immediately. If this flag is set, the server will return an
- undeliverable message with a Return method. If this flag is zero, the server
- will queue the message, but with no guarantee that it will ever be consumed.
- </doc>
-
- <!-- Rule test name: was "amq_file_00" -->
- <rule name = "01">
- <doc>The server SHOULD implement the immediate flag.</doc>
- </rule>
- </field>
-
- <field name = "identifier" domain = "shortstr" label = "staging identifier">
- <doc>
- This is the staging identifier of the message to publish. The message must have
- been staged. Note that a client can send the Publish method asynchronously
- without waiting for staging to finish.
- </doc>
- </field>
- </method>
-
- <method name = "return" content = "1" index = "70" label = "return a failed message">
- <doc>
- This method returns an undeliverable message that was published with the "immediate"
- flag set, or an unroutable message published with the "mandatory" flag set. The
- reply code and text provide information about the reason that the message was
- undeliverable.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply-code" domain = "reply-code" />
-
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "deliver" index = "80" label = "notify the client of a consumer message">
- <doc>
- This method delivers a staged file message to the client, via a consumer. In the
- asynchronous message delivery model, the client starts a consumer using the Consume
- method, then the server responds with Deliver methods as and when messages arrive
- for that consumer.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server SHOULD track the number of times a message has been delivered to
- clients and when a message is redelivered a certain number of times - e.g. 5
- times - without being acknowledged, the server SHOULD consider the message to be
- unprocessable (possibly causing client applications to abort), and move the
- message to a dead letter queue.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
-
- <field name = "identifier" domain = "shortstr" label = "staging identifier">
- <doc>
- This is the staging identifier of the message to deliver. The message must have
- been staged. Note that a server can send the Deliver method asynchronously
- without waiting for staging to finish.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "ack" index = "90" label = "acknowledge one or more messages">
- <doc>
- This method acknowledges one or more messages delivered via the Deliver method. The
- client can ask to confirm a single message or a set of messages up to and including
- a specific message.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "multiple" domain = "bit" label = "acknowledge multiple messages">
- <doc>
- If set to 1, the delivery tag is treated as "up to and including", so that the
- client can acknowledge multiple messages with a single method. If set to zero,
- the delivery tag refers to a single message. If the multiple field is 1, and the
- delivery tag is zero, tells the server to acknowledge all outstanding mesages.
- </doc>
-
- <rule name = "01">
- <doc>
- The server MUST validate that a non-zero delivery-tag refers to an delivered
- message, and raise a channel exception if this is not the case.
- </doc>
- </rule>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "reject" index = "100" label = "reject an incoming message">
- <doc>
- This method allows a client to reject a message. It can be used to return
- untreatable messages to their original queue. Note that file content is staged
- before delivery, so the client will not use this method to interrupt delivery of a
- large message.
- </doc>
-
- <rule name = "01">
- <doc>
- The server SHOULD interpret this method as meaning that the client is unable to
- process the message at this time.
- </doc>
- </rule>
-
- <!-- TODO: Rule split? -->
-
- <rule name = "02">
- <doc>
- A client MUST NOT use this method as a means of selecting messages to process. A
- rejected message MAY be discarded or dead-lettered, not necessarily passed to
- another client.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "requeue" domain = "bit" label = "requeue the message">
- <doc>
- If this field is zero, the message will be discarded. If this bit is 1, the
- server will attempt to requeue the message.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server MUST NOT deliver the message to the same client within the
- context of the current channel. The recommended strategy is to attempt to
- deliver the message to an alternative consumer, and if that is not possible,
- to move the message to a dead-letter queue. The server MAY use more
- sophisticated tracking to hold the message on the queue and redeliver it to
- the same client at a later stage.
- </doc>
- </rule>
- </field>
- </method>
- </class>
-
- <!-- == STREAM =========================================================== -->
-
- <class name = "stream" handler = "channel" index = "80" label = "work with streaming content">
- <doc>
- The stream class provides methods that support multimedia streaming. The stream class
- uses the following semantics: one message is one packet of data; delivery is
- unacknowleged and unreliable; the consumer can specify quality of service parameters
- that the server can try to adhere to; lower-priority messages may be discarded in favour
- of high priority messages.
- </doc>
-
- <doc type = "grammar">
- stream = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:PUBLISH content
- / S:RETURN
- / S:DELIVER content
- </doc>
-
- <chassis name = "server" implement = "MAY" />
- <chassis name = "client" implement = "MAY" />
-
- <rule name = "01">
- <doc>
- The server SHOULD discard stream messages on a priority basis if the queue size
- exceeds some configured limit.
- </doc>
- </rule>
-
- <rule name = "02">
- <!-- TODO: Rule split? -->
- <doc>
- The server MUST implement at least 2 priority levels for stream messages, where
- priorities 0-4 and 5-9 are treated as two distinct levels. The server MAY implement
- up to 10 priority levels.
- </doc>
- </rule>
-
- <rule name = "03">
- <doc>
- The server MUST implement automatic acknowledgements on stream content. That is, as
- soon as a message is delivered to a client via a Deliver method, the server must
- remove it from the queue.
- </doc>
- </rule>
-
- <!-- These are the properties for a Stream content -->
-
- <field name = "content-type" domain = "shortstr" label = "MIME content type" />
- <field name = "content-encoding" domain = "shortstr" label = "MIME content encoding" />
- <field name = "headers" domain = "table" label = "message header field table" />
- <field name = "priority" domain = "octet" label = "message priority, 0 to 9" />
- <field name = "timestamp" domain = "timestamp" label = "message timestamp" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "qos" synchronous = "1" index = "10" label = "specify quality of service">
- <doc>
- This method requests a specific quality of service. The QoS can be specified for the
- current channel or for all channels on the connection. The particular properties and
- semantics of a qos method always depend on the content class semantics. Though the
- qos method could in principle apply to both peers, it is currently meaningful only
- for the server.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "qos-ok" />
-
- <field name = "prefetch-size" domain = "long" label = "prefetch window in octets">
- <doc>
- The client can request that messages be sent in advance so that when the client
- finishes processing a message, the following message is already held locally,
- rather than needing to be sent down the channel. Prefetching gives a performance
- improvement. This field specifies the prefetch window size in octets. May be set
- to zero, meaning "no specific limit". Note that other prefetch limits may still
- apply.
- </doc>
- </field>
-
- <field name = "prefetch-count" domain = "short" label = "prefetch window in messages">
- <doc>
- Specifies a prefetch window in terms of whole messages. This field may be used
- in combination with the prefetch-size field; a message will only be sent in
- advance if both prefetch windows (and those at the channel and connection level)
- allow it.
- </doc>
- </field>
-
- <field name = "consume-rate" domain = "long" label = "transfer rate in octets/second">
- <doc>
- Specifies a desired transfer rate in octets per second. This is usually
- determined by the application that uses the streaming data. A value of zero
- means "no limit", i.e. as rapidly as possible.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server MAY ignore the prefetch values and consume rates, depending on
- the type of stream and the ability of the server to queue and/or reply it.
- The server MAY drop low-priority messages in favour of high-priority
- messages.
- </doc>
- </rule>
- </field>
-
- <field name = "global" domain = "bit" label = "apply to entire connection">
- <doc>
- By default the QoS settings apply to the current channel only. If this field is
- set, they are applied to the entire connection.
- </doc>
- </field>
- </method>
-
- <method name = "qos-ok" synchronous = "1" index = "11" label = "confirm the requested qos">
- <doc>
- This method tells the client that the requested QoS levels could be handled by the
- server. The requested QoS applies to all active consumers until a new QoS is
- defined.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "consume" synchronous = "1" index = "20" label = "start a queue consumer">
- <doc>
- This method asks the server to start a "consumer", which is a transient request for
- messages from a specific queue. Consumers last as long as the channel they were
- created on, or until the client cancels them.
- </doc>
-
- <rule name = "01">
- <doc>
- The server SHOULD support at least 16 consumers per queue, unless the queue was
- declared as private, and ideally, impose no limit except as defined by available
- resources.
- </doc>
- </rule>
-
- <rule name = "02">
- <doc>
- Streaming applications SHOULD use different channels to select different
- streaming resolutions. AMQP makes no provision for filtering and/or transforming
- streams except on the basis of priority-based selective delivery of individual
- messages.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the realm for the queue.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name is null,
- refers to the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- </rule>
- </field>
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is local to a
- connection, so two clients can use the same consumer tags. If this field is
- empty the server will generate a unique tag.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The tag MUST NOT refer to an existing consumer. If the client attempts to
- create two consumers with the same non-empty tag the server MUST raise a
- connection exception with reply code 530 (not allowed).
- </doc>
- </rule>
- </field>
-
- <field name = "no-local" domain = "no-local" />
-
- <field name = "exclusive" domain = "bit" label = "request exclusive access">
- <doc>
- Request exclusive consumer access, meaning only this consumer can access the
- queue.
- </doc>
-
-
- <!-- Rule test name: was "amq_file_00" -->
- <rule name = "01">
- <doc>
- If the server cannot grant exclusive access to the queue when asked, -
- because there are other consumers active - it MUST raise a channel exception
- with return code 405 (resource locked).
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "consume-ok" synchronous = "1" index = "21" label = "confirm a new consumer">
- <doc>
- This method provides the client with a consumer tag which it may use in methods that
- work with the consumer.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>Holds the consumer tag specified by the client or provided by the server.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "cancel" synchronous = "1" index = "30" label = "end a queue consumer">
- <doc>
- This method cancels a consumer. Since message delivery is asynchronous the client
- may continue to receive messages for a short while after canceling a consumer. It
- may process or discard these as appropriate.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "cancel-ok" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <method name = "cancel-ok" synchronous = "1" index = "31" label = "confirm a cancelled consumer">
- <doc>This method confirms that the cancellation was completed.</doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "publish" content = "1" index = "40" label = "publish a message">
- <doc>
- This method publishes a message to a specific exchange. The message will be routed
- to queues as defined by the exchange configuration and distributed to any active
- consumers as appropriate.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "write" access rights
- to the access realm for the exchange.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange name can be
- empty, meaning the default exchange. If the exchange name is specified, and that
- exchange does not exist, the server will raise a channel exception.
- </doc>
-
- <rule name = "01">
- <doc>
- The server MUST accept a blank exchange name to mean the default exchange.
- </doc>
- </rule>
-
- <rule name = "02">
- <doc>
- If the exchange was declared as an internal exchange, the server MUST
- respond with a reply code 403 (access refused) and raise a channel
- exception.
- </doc>
- </rule>
-
- <rule name = "03">
- <doc>
- The exchange MAY refuse stream content in which case it MUST respond with a
- reply code 540 (not implemented) and raise a channel exception.
- </doc>
- </rule>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>
- Specifies the routing key for the message. The routing key is used for routing
- messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" domain = "bit" label = "indicate mandatory routing">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue. If this flag is set, the server will return an unroutable message with a
- Return method. If this flag is zero, the server silently drops the message.
- </doc>
-
- <!-- Rule test name: was "amq_stream_00" -->
- <rule name = "01">
- <doc>The server SHOULD implement the mandatory flag.</doc>
- </rule>
- </field>
-
- <field name = "immediate" domain = "bit" label = "request immediate delivery">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue consumer immediately. If this flag is set, the server will return an
- undeliverable message with a Return method. If this flag is zero, the server
- will queue the message, but with no guarantee that it will ever be consumed.
- </doc>
-
- <!-- Rule test name: was "amq_stream_00" -->
- <rule name = "01">
- <doc>The server SHOULD implement the immediate flag.</doc>
- </rule>
- </field>
- </method>
-
- <method name = "return" content = "1" index = "50" label = "return a failed message">
- <doc>
- This method returns an undeliverable message that was published with the "immediate"
- flag set, or an unroutable message published with the "mandatory" flag set. The
- reply code and text provide information about the reason that the message was
- undeliverable.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply-code" domain = "reply-code" />
-
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "deliver" content = "1" index = "60"
- label = "notify the client of a consumer message">
- <doc>
- This method delivers a message to the client, via a consumer. In the asynchronous
- message delivery model, the client starts a consumer using the Consume method, then
- the server responds with Deliver methods as and when messages arrive for that
- consumer.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue that the message came from. Note that a single
- channel can start many consumers on different queues.
- </doc>
- <assert check = "notnull" />
- </field>
- </method>
- </class>
-
- <!-- == TX =============================================================== -->
-
- <class name = "tx" handler = "channel" index = "90" label = "work with standard transactions">
- <doc>
- Standard transactions provide so-called "1.5 phase commit". We can ensure that work is
- never lost, but there is a chance of confirmations being lost, so that messages may be
- resent. Applications that use standard transactions must be able to detect and ignore
- duplicate messages.
- </doc>
-
- <!-- TODO: Rule split? -->
-
- <rule name = "01">
- <doc>
- An client using standard transactions SHOULD be able to track all messages received
- within a reasonable period, and thus detect and reject duplicates of the same
- message. It SHOULD NOT pass these to the application layer.
- </doc>
- </rule>
-
- <doc type = "grammar">
- tx = C:SELECT S:SELECT-OK
- / C:COMMIT S:COMMIT-OK
- / C:ROLLBACK S:ROLLBACK-OK
- </doc>
-
- <chassis name = "server" implement = "SHOULD" />
- <chassis name = "client" implement = "MAY" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "select" synchronous = "1" index = "10" label = "select standard transaction mode">
- <doc>
- This method sets the channel to use standard transactions. The client must use this
- method at least once on a channel before using the Commit or Rollback methods.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "select-ok" />
- </method>
-
- <method name = "select-ok" synchronous = "1" index = "11" label = "confirm transaction mode">
- <doc>
- This method confirms to the client that the channel was successfully set to use
- standard transactions.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "commit" synchronous = "1" index = "20" label = "commit the current transaction">
- <doc>
- This method commits all messages published and acknowledged in the current
- transaction. A new transaction starts immediately after a commit.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "commit-ok" />
- </method>
-
- <method name = "commit-ok" synchronous = "1" index = "21" label = "confirm a successful commit">
- <doc>
- This method confirms to the client that the commit succeeded. Note that if a commit
- fails, the server raises a channel exception.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "rollback" synchronous = "1" index = "30"
- label = "abandon the current transaction">
- <doc>
- This method abandons all messages published and acknowledged in the current
- transaction. A new transaction starts immediately after a rollback.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "rollback-ok" />
- </method>
-
- <method name = "rollback-ok" synchronous = "1" index = "31" label = "confirm successful rollback">
- <doc>
- This method confirms to the client that the rollback succeeded. Note that if an
- rollback fails, the server raises a channel exception.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
- </class>
-
- <!-- == DTX ============================================================== -->
-
- <class name = "dtx" handler = "channel" index = "100" label = "work with distributed transactions">
- <doc>
- Distributed transactions provide so-called "2-phase commit". The AMQP distributed
- transaction model supports the X-Open XA architecture and other distributed transaction
- implementations. The Dtx class assumes that the server has a private communications
- channel (not AMQP) to a distributed transaction coordinator.
- </doc>
-
- <doc type = "grammar">
- dtx = C:SELECT S:SELECT-OK
- C:START S:START-OK
- </doc>
-
- <chassis name = "server" implement = "MAY" />
- <chassis name = "client" implement = "MAY" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "select" synchronous = "1" index = "10" label = "select standard transaction mode">
- <doc>
- This method sets the channel to use distributed transactions. The client must use
- this method at least once on a channel before using the Start method.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "select-ok" />
- </method>
-
- <method name = "select-ok" synchronous = "1" index = "11" label = "confirm transaction mode">
- <doc>
- This method confirms to the client that the channel was successfully set to use
- distributed transactions.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "start" synchronous = "1" index = "20"
- label = "start a new distributed transaction">
- <doc>
- This method starts a new distributed transaction. This must be the first method on a
- new channel that uses the distributed transaction mode, before any methods that
- publish or consume messages.
- </doc>
- <chassis name = "server" implement = "MAY" />
- <response name = "start-ok" />
- <field name = "dtx-identifier" domain = "shortstr" label = "transaction identifier">
- <doc>
- The distributed transaction key. This identifies the transaction so that the
- AMQP server can coordinate with the distributed transaction coordinator.
- </doc>
- <assert check = "notnull" />
- </field>
- </method>
-
- <method name = "start-ok" synchronous = "1" index = "21"
- label = "confirm the start of a new distributed transaction">
- <doc>
- This method confirms to the client that the transaction started. Note that if a
- start fails, the server raises a channel exception.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
- </class>
-
- <!-- == TUNNEL =========================================================== -->
-
- <class name = "tunnel" handler = "tunnel" index = "110" label = "methods for protocol tunneling">
- <doc>
- The tunnel methods are used to send blocks of binary data - which can be serialised AMQP
- methods or other protocol frames - between AMQP peers.
- </doc>
-
- <doc type = "grammar">
- tunnel = C:REQUEST
- / S:REQUEST
- </doc>
-
- <chassis name = "server" implement = "MAY" />
- <chassis name = "client" implement = "MAY" />
-
- <field name = "headers" domain = "table" label = "message header field table" />
- <field name = "proxy-name" domain = "shortstr" label = "identity of tunnelling proxy" />
- <field name = "data-name" domain = "shortstr" label = "name or type of message being tunnelled" />
- <field name = "durable" domain = "octet" label = "message durability indicator" />
- <field name = "broadcast" domain = "octet" label = "message broadcast mode" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "request" content = "1" index = "10" label = "sends a tunnelled method">
- <doc>
- This method tunnels a block of binary data, which can be an encoded
- AMQP method or other data. The binary data is sent as the content for
- the Tunnel.Request method.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <field name = "meta-data" domain = "table" label = "meta data for the tunnelled block">
- <doc>
- This field table holds arbitrary meta-data that the sender needs to
- pass to the recipient.
- </doc>
- </field>
- </method>
- </class>
-</amqp>
diff --git a/gentools/xml-src/amqp-0.8.test.xml b/gentools/xml-src/amqp-0.8.test.xml
deleted file mode 100644
index b0adf31828..0000000000
--- a/gentools/xml-src/amqp-0.8.test.xml
+++ /dev/null
@@ -1,3959 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
- Copyright Notice
- ================
- (c) Copyright JPMorgan Chase Bank & Co., Cisco Systems, Inc., Envoy Technologies Inc.,
- iMatix Corporation, IONA\ufffd Technologies, Red Hat, Inc.,
- TWIST Process Innovations, and 29West Inc. 2006. All rights reserved.
-
- License
- =======
- JPMorgan Chase Bank & Co., Cisco Systems, Inc., Envoy Technologies Inc., iMatix
- Corporation, IONA\ufffd Technologies, Red Hat, Inc., TWIST Process Innovations, and
- 29West Inc. (collectively, the "Authors") each hereby grants to you a worldwide,
- perpetual, royalty-free, nontransferable, nonexclusive license to
- (i) copy, display, and implement the Advanced Messaging Queue Protocol
- ("AMQP") Specification and (ii) the Licensed Claims that are held by
- the Authors, all for the purpose of implementing the Advanced Messaging
- Queue Protocol Specification. Your license and any rights under this
- Agreement will terminate immediately without notice from
- any Author if you bring any claim, suit, demand, or action related to
- the Advanced Messaging Queue Protocol Specification against any Author.
- Upon termination, you shall destroy all copies of the Advanced Messaging
- Queue Protocol Specification in your possession or control.
-
- As used hereunder, "Licensed Claims" means those claims of a patent or
- patent application, throughout the world, excluding design patents and
- design registrations, owned or controlled, or that can be sublicensed
- without fee and in compliance with the requirements of this
- Agreement, by an Author or its affiliates now or at any
- future time and which would necessarily be infringed by implementation
- of the Advanced Messaging Queue Protocol Specification. A claim is
- necessarily infringed hereunder only when it is not possible to avoid
- infringing it because there is no plausible non-infringing alternative
- for implementing the required portions of the Advanced Messaging Queue
- Protocol Specification. Notwithstanding the foregoing, Licensed Claims
- shall not include any claims other than as set forth above even if
- contained in the same patent as Licensed Claims; or that read solely
- on any implementations of any portion of the Advanced Messaging Queue
- Protocol Specification that are not required by the Advanced Messaging
- Queue Protocol Specification, or that, if licensed, would require a
- payment of royalties by the licensor to unaffiliated third parties.
- Moreover, Licensed Claims shall not include (i) any enabling technologies
- that may be necessary to make or use any Licensed Product but are not
- themselves expressly set forth in the Advanced Messaging Queue Protocol
- Specification (e.g., semiconductor manufacturing technology, compiler
- technology, object oriented technology, networking technology, operating
- system technology, and the like); or (ii) the implementation of other
- published standards developed elsewhere and merely referred to in the
- body of the Advanced Messaging Queue Protocol Specification, or
- (iii) any Licensed Product and any combinations thereof the purpose or
- function of which is not required for compliance with the Advanced
- Messaging Queue Protocol Specification. For purposes of this definition,
- the Advanced Messaging Queue Protocol Specification shall be deemed to
- include both architectural and interconnection requirements essential
- for interoperability and may also include supporting source code artifacts
- where such architectural, interconnection requirements and source code
- artifacts are expressly identified as being required or documentation to
- achieve compliance with the Advanced Messaging Queue Protocol Specification.
-
- As used hereunder, "Licensed Products" means only those specific portions
- of products (hardware, software or combinations thereof) that implement
- and are compliant with all relevant portions of the Advanced Messaging
- Queue Protocol Specification.
-
- The following disclaimers, which you hereby also acknowledge as to any
- use you may make of the Advanced Messaging Queue Protocol Specification:
-
- THE ADVANCED MESSAGING QUEUE PROTOCOL SPECIFICATION IS PROVIDED "AS IS,"
- AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
- IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE
- CONTENTS OF THE ADVANCED MESSAGING QUEUE PROTOCOL SPECIFICATION ARE
- SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF THE ADVANCED
- MESSAGING QUEUE PROTOCOL SPECIFICATION WILL NOT INFRINGE ANY THIRD PARTY
- PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
-
- THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
- INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY
- USE, IMPLEMENTATION OR DISTRIBUTION OF THE ADVANCED MESSAGING QUEUE
- PROTOCOL SPECIFICATION.
-
- The name and trademarks of the Authors may NOT be used in any manner,
- including advertising or publicity pertaining to the Advanced Messaging
- Queue Protocol Specification or its contents without specific, written
- prior permission. Title to copyright in the Advanced Messaging Queue
- Protocol Specification will at all times remain with the Authors.
-
- No other rights are granted by implication, estoppel or otherwise.
-
- Upon termination of your license or rights under this Agreement, you
- shall destroy all copies of the Advanced Messaging Queue Protocol
- Specification in your possession or control.
-
- Trademarks
- ==========
- "JPMorgan", "JPMorgan Chase", "Chase", the JPMorgan Chase logo and the
- Octagon Symbol are trademarks of JPMorgan Chase & Co.
-
- IMATIX and the iMatix logo are trademarks of iMatix Corporation sprl.
-
- IONA, IONA Technologies, and the IONA logos are trademarks of IONA
- Technologies PLC and/or its subsidiaries.
-
- LINUX is a trademark of Linus Torvalds. RED HAT and JBOSS are registered
- trademarks of Red Hat, Inc. in the US and other countries.
-
- Java, all Java-based trademarks and OpenOffice.org are trademarks of
- Sun Microsystems, Inc. in the United States, other countries, or both.
-
- Other company, product, or service names may be trademarks or service
- marks of others.
-
- Links to full AMQP specification:
- =================================
- http://www.envoytech.org/spec/amq/
- http://www.iona.com/opensource/amqp/
- http://www.redhat.com/solutions/specifications/amqp/
- http://www.twiststandards.org/tiki-index.php?page=AMQ
- http://www.imatix.com/amqp
-
--->
-
-<!--
-========================================================
-EDITORS: (PH) Pieter Hintjens <ph@imatix.com>
- (KvdR) Kim van der Riet <kim.vdriet@redhat.com>
-
-NOTE: These editors have been assigned by the AMQP working group. Please do not
-edit/commit this file without consulting with one of the above editors.
-========================================================
-
-Revision history:
- 2006-06-07 (PH) - version number changed to 0.8 to conform to public
- release documentation.
-
- 2006-05-15 (PH) - fixed comments on queue name in basic.get to clarify
- use of current queue in this method.
-
- 2006-05-15 (PH) - fixed comments on routing key in queue.bind to clarify
- how routing key is filled when empty (to allow asynch queue.declare).
-
- 2006-05-11 (PH) - reset version to 0.70 so that putatitive standards
- group can release 2-3 major new versions before hitting 1.0 (again).
-
- 2006-05-11 (PH) - TODO in documentation: cycle field in frame header
- has been removed.
-
- 2006-05-11 (PH) - added nowait option to exchange.declare, delete,
- queue.declare, delete, bind, purge, basic.consume, cancel,
- file.consume, cancel, stream.consume and cancel methods.
-
- 2006-05-11 (PH) - removed notnull rule and added explanations on queue
- name in queue.bind, purge, delete, basic.consume, cancel, file.consume,
- cancel, stream.consume and cancel methods.
-
- 2006-05-11 (PH) - added basic.qos, file.qos, and stream.qos methods that
- regroup all prefetch options from the consume methods. Also removed the
- prefetch option from channel.open.
-
- 2006-05-11 (PH) - renumbered method indexes to show request-response
- nature of methods; requests are 10, 20, 30 while responses are 11, 21,
- etc.
-
- 2006-05-11 (PH) - removed OpenAMQ extension methods from this definition
- since these are maintained seperately.
-
- 2006-05-26 (RG) - added Basic.Recover method to allow replay of
- unacknowledged messages on a channel.
-
- 2006-07-03 (PH) - cosmetic clean-up of Basic.Recover comments.
--->
-
-<amqp major="8" minor="0" port="5672" comment="AMQ protocol 0.80">
- AMQ Protocol 0.80
-
-<!--
-======================================================
-== CONSTANTS
-======================================================
--->
- <constant name="frame method" value="1"/>
- <constant name="frame header" value="2"/>
- <constant name="frame body" value="3"/>
- <constant name="frame oob method" value="4"/>
- <constant name="frame oob header" value="5"/>
- <constant name="frame oob body" value="6"/>
- <constant name="frame trace" value="7"/>
- <constant name="frame heartbeat" value="8"/>
- <constant name="frame min size" value="4096"/>
- <constant name="frame end" value="206"/>
- <constant name="reply success" value="200">
- Indicates that the method completed successfully. This reply code is
- reserved for future use - the current protocol design does not use
- positive confirmation and reply codes are sent only in case of an
- error.
-</constant>
- <constant name="not delivered" value="310" class="soft error">
- The client asked for a specific message that is no longer available.
- The message was delivered to another client, or was purged from the
- queue for some other reason.
-</constant>
- <constant name="content too large" value="311" class="soft error">
- The client attempted to transfer content larger than the server
- could accept at the present time. The client may retry at a later
- time.
-</constant>
- <constant name="connection forced" value="320" class="hard error">
- An operator intervened to close the connection for some reason.
- The client may retry at some later date.
-</constant>
- <constant name="invalid path" value="402" class="hard error">
- The client tried to work with an unknown virtual host or cluster.
-</constant>
- <constant name="access refused" value="403" class="soft error">
- The client attempted to work with a server entity to which it has
- no due to security settings.
-</constant>
- <constant name="not found" value="404" class="soft error">
- The client attempted to work with a server entity that does not exist.
-</constant>
- <constant name="resource locked" value="405" class="soft error">
- The client attempted to work with a server entity to which it has
- no access because another client is working with it.
-</constant>
- <constant name="frame error" value="501" class="hard error">
- The client sent a malformed frame that the server could not decode.
- This strongly implies a programming error in the client.
-</constant>
- <constant name="syntax error" value="502" class="hard error">
- The client sent a frame that contained illegal values for one or more
- fields. This strongly implies a programming error in the client.
-</constant>
- <constant name="command invalid" value="503" class="hard error">
- The client sent an invalid sequence of frames, attempting to perform
- an operation that was considered invalid by the server. This usually
- implies a programming error in the client.
-</constant>
- <constant name="channel error" value="504" class="hard error">
- The client attempted to work with a channel that had not been
- correctly opened. This most likely indicates a fault in the client
- layer.
-</constant>
- <constant name="resource error" value="506" class="hard error">
- The server could not complete the method because it lacked sufficient
- resources. This may be due to the client creating too many of some
- type of entity.
-</constant>
- <constant name="not allowed" value="530" class="hard error">
- The client tried to work with some entity in a manner that is
- prohibited by the server, due to security settings or by some other
- criteria.
-</constant>
- <constant name="not implemented" value="540" class="hard error">
- The client tried to use functionality that is not implemented in the
- server.
-</constant>
- <constant name="internal error" value="541" class="hard error">
- The server could not complete the method because of an internal error.
- The server may require intervention by an operator in order to resume
- normal operations.
-</constant>
- <!--
-======================================================
-== DOMAIN TYPES
-======================================================
--->
- <domain name="access ticket" type="short">
- access ticket granted by server
- <doc>
- An access ticket granted by the server for a certain set of access
- rights within a specific realm. Access tickets are valid within the
- channel where they were created, and expire when the channel closes.
- </doc>
- <assert check="ne" value="0"/>
- </domain>
- <domain name="class id" type="short"/>
- <domain name="consumer tag" type="shortstr">
- consumer tag
- <doc>
- Identifier for the consumer, valid within the current connection.
- </doc>
- <rule implement="MUST">
- The consumer tag is valid only within the channel from which the
- consumer was created. I.e. a client MUST NOT create a consumer in
- one channel and then use it in another.
- </rule>
- </domain>
- <domain name="delivery tag" type="longlong">
- server-assigned delivery tag
- <doc>
- The server-assigned and channel-specific delivery tag
- </doc>
- <rule implement="MUST">
- The delivery tag is valid only within the channel from which the
- message was received. I.e. a client MUST NOT receive a message on
- one channel and then acknowledge it on another.
- </rule>
- <rule implement="MUST">
- The server MUST NOT use a zero value for delivery tags. Zero is
- reserved for client use, meaning "all messages so far received".
- </rule>
- </domain>
- <domain name="exchange name" type="shortstr">
- exchange name
- <doc>
- The exchange name is a client-selected string that identifies
- the exchange for publish methods. Exchange names may consist
- of any mixture of digits, letters, and underscores. Exchange
- names are scoped by the virtual host.
- </doc>
- <assert check="length" value="127"/>
- </domain>
- <domain name="known hosts" type="shortstr">
-list of known hosts
-<doc>
-Specifies the list of equivalent or alternative hosts that the server
-knows about, which will normally include the current server itself.
-Clients can cache this information and use it when reconnecting to a
-server after a failure.
-</doc>
- <rule implement="MAY">
-The server MAY leave this field empty if it knows of no other
-hosts than itself.
-</rule>
- </domain>
- <domain name="method id" type="short"/>
- <domain name="no ack" type="bit">
- no acknowledgement needed
- <doc>
- If this field is set the server does not expect acknowledgments
- for messages. That is, when a message is delivered to the client
- the server automatically and silently acknowledges it on behalf
- of the client. This functionality increases performance but at
- the cost of reliability. Messages can get lost if a client dies
- before it can deliver them to the application.
- </doc>
- </domain>
- <domain name="no local" type="bit">
- do not deliver own messages
- <doc>
- If the no-local field is set the server will not send messages to
- the client that published them.
- </doc>
- </domain>
- <domain name="path" type="shortstr">
- <doc>
- Must start with a slash "/" and continue with path names
- separated by slashes. A path name consists of any combination
- of at least one of [A-Za-z0-9] plus zero or more of [.-_+!=:].
-</doc>
- <assert check="notnull"/>
- <assert check="syntax" rule="path"/>
- <assert check="length" value="127"/>
- </domain>
- <domain name="peer properties" type="table">
- <doc>
-This string provides a set of peer properties, used for
-identification, debugging, and general information.
-</doc>
- <rule implement="SHOULD">
-The properties SHOULD contain these fields:
-"product", giving the name of the peer product, "version", giving
-the name of the peer version, "platform", giving the name of the
-operating system, "copyright", if appropriate, and "information",
-giving other general information.
-</rule>
- </domain>
- <domain name="queue name" type="shortstr">
- queue name
- <doc>
- The queue name identifies the queue within the vhost. Queue
- names may consist of any mixture of digits, letters, and
- underscores.
- </doc>
- <assert check="length" value="127"/>
- </domain>
- <domain name="redelivered" type="bit">
- message is being redelivered
- <doc>
- This indicates that the message has been previously delivered to
- this or another client.
- </doc>
- <rule implement="SHOULD">
- The server SHOULD try to signal redelivered messages when it can.
- When redelivering a message that was not successfully acknowledged,
- the server SHOULD deliver it to the original client if possible.
- </rule>
- <rule implement="MUST">
- The client MUST NOT rely on the redelivered field but MUST take it
- as a hint that the message may already have been processed. A
- fully robust client must be able to track duplicate received messages
- on non-transacted, and locally-transacted channels.
- </rule>
- </domain>
- <domain name="reply code" type="short">
-reply code from server
-<doc>
- The reply code. The AMQ reply codes are defined in AMQ RFC 011.
-</doc>
- <assert check="notnull"/>
- </domain>
- <domain name="reply text" type="shortstr">
-localised reply text
-<doc>
- The localised reply text. This text can be logged as an aid to
- resolving issues.
-</doc>
- <assert check="notnull"/>
- </domain>
- <class name="connection" handler="connection" index="10">
- <!--
-======================================================
-== CONNECTION
-======================================================
--->
- work with socket connections
-<doc>
- The connection class provides methods for a client to establish a
- network connection to a server, and for both peers to operate the
- connection thereafter.
-</doc>
- <doc name="grammar">
- connection = open-connection *use-connection close-connection
- open-connection = C:protocol-header
- S:START C:START-OK
- *challenge
- S:TUNE C:TUNE-OK
- C:OPEN S:OPEN-OK | S:REDIRECT
- challenge = S:SECURE C:SECURE-OK
- use-connection = *channel
- close-connection = C:CLOSE S:CLOSE-OK
- / S:CLOSE C:CLOSE-OK
-</doc>
- <chassis name="server" implement="MUST"/>
- <chassis name="client" implement="MUST"/>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="start" synchronous="1" index="10">
- start connection negotiation
- <doc>
- This method starts the connection negotiation process by telling
- the client the protocol version that the server proposes, along
- with a list of security mechanisms which the client can use for
- authentication.
- </doc>
- <rule implement="MUST">
- If the client cannot handle the protocol version suggested by the
- server it MUST close the socket connection.
- </rule>
- <rule implement="MUST">
- The server MUST provide a protocol version that is lower than or
- equal to that requested by the client in the protocol header. If
- the server cannot support the specified protocol it MUST NOT send
- this method, but MUST close the socket connection.
- </rule>
- <chassis name="client" implement="MUST"/>
- <response name="start-ok"/>
- <field name="version major" type="octet">
- protocol major version
- <doc>
- The protocol major version that the server agrees to use, which
- cannot be higher than the client's major version.
- </doc>
- </field>
- <field name="version minor" type="octet">
- protocol major version
- <doc>
- The protocol minor version that the server agrees to use, which
- cannot be higher than the client's minor version.
- </doc>
- </field>
- <field name="server properties" domain="peer properties">
- server properties
- </field>
- <field name="mechanisms" type="longstr">
- available security mechanisms
- <doc>
- A list of the security mechanisms that the server supports, delimited
- by spaces. Currently ASL supports these mechanisms: PLAIN.
- </doc>
- <see name="security mechanisms"/>
- <assert check="notnull"/>
- </field>
- <field name="locales" type="longstr">
- available message locales
- <doc>
- A list of the message locales that the server supports, delimited
- by spaces. The locale defines the language in which the server
- will send reply texts.
- </doc>
- <rule implement="MUST">
- All servers MUST support at least the en_US locale.
- </rule>
- <assert check="notnull"/>
- </field>
- </method>
- <method name="start-ok" synchronous="1" index="11">
- select security mechanism and locale
- <doc>
- This method selects a SASL security mechanism. ASL uses SASL
- (RFC2222) to negotiate authentication and encryption.
- </doc>
- <chassis name="server" implement="MUST"/>
- <field name="client properties" domain="peer properties">
- client properties
- </field>
- <field name="mechanism" type="shortstr">
- selected security mechanism
- <doc>
- A single security mechanisms selected by the client, which must be
- one of those specified by the server.
- </doc>
- <rule implement="SHOULD">
- The client SHOULD authenticate using the highest-level security
- profile it can handle from the list provided by the server.
- </rule>
- <rule implement="MUST">
- The mechanism field MUST contain one of the security mechanisms
- proposed by the server in the Start method. If it doesn't, the
- server MUST close the socket.
- </rule>
- <assert check="notnull"/>
- </field>
- <field name="response" type="longstr">
- security response data
- <doc>
- A block of opaque data passed to the security mechanism. The contents
- of this data are defined by the SASL security mechanism. For the
- PLAIN security mechanism this is defined as a field table holding
- two fields, LOGIN and PASSWORD.
- </doc>
- <assert check="notnull"/>
- </field>
- <field name="locale" type="shortstr">
- selected message locale
- <doc>
- A single message local selected by the client, which must be one
- of those specified by the server.
- </doc>
- <assert check="notnull"/>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="secure" synchronous="1" index="20">
- security mechanism challenge
- <doc>
- The SASL protocol works by exchanging challenges and responses until
- both peers have received sufficient information to authenticate each
- other. This method challenges the client to provide more information.
- </doc>
- <chassis name="client" implement="MUST"/>
- <response name="secure-ok"/>
- <field name="challenge" type="longstr">
- security challenge data
- <doc>
- Challenge information, a block of opaque binary data passed to
- the security mechanism.
- </doc>
- <see name="security mechanisms"/>
- </field>
- </method>
- <method name="secure-ok" synchronous="1" index="21">
- security mechanism response
- <doc>
- This method attempts to authenticate, passing a block of SASL data
- for the security mechanism at the server side.
- </doc>
- <chassis name="server" implement="MUST"/>
- <field name="response" type="longstr">
- security response data
- <doc>
- A block of opaque data passed to the security mechanism. The contents
- of this data are defined by the SASL security mechanism.
- </doc>
- <assert check="notnull"/>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="tune" synchronous="1" index="30">
- propose connection tuning parameters
- <doc>
- This method proposes a set of connection configuration values
- to the client. The client can accept and/or adjust these.
- </doc>
- <chassis name="client" implement="MUST"/>
- <response name="tune-ok"/>
- <field name="channel max" type="short">
- proposed maximum channels
- <doc>
- The maximum total number of channels that the server allows
- per connection. Zero means that the server does not impose a
- fixed limit, but the number of allowed channels may be limited
- by available server resources.
- </doc>
- </field>
- <field name="frame max" type="long">
- proposed maximum frame size
- <doc>
- The largest frame size that the server proposes for the
- connection. The client can negotiate a lower value. Zero means
- that the server does not impose any specific limit but may reject
- very large frames if it cannot allocate resources for them.
- </doc>
- <rule implement="MUST">
- Until the frame-max has been negotiated, both peers MUST accept
- frames of up to 4096 octets large. The minimum non-zero value for
- the frame-max field is 4096.
- </rule>
- </field>
- <field name="heartbeat" type="short">
- desired heartbeat delay
- <doc>
- The delay, in seconds, of the connection heartbeat that the server
- wants. Zero means the server does not want a heartbeat.
- </doc>
- </field>
- </method>
- <method name="tune-ok" synchronous="1" index="31">
- negotiate connection tuning parameters
- <doc>
- This method sends the client's connection tuning parameters to the
- server. Certain fields are negotiated, others provide capability
- information.
- </doc>
- <chassis name="server" implement="MUST"/>
- <field name="channel max" type="short">
- negotiated maximum channels
- <doc>
- The maximum total number of channels that the client will use
- per connection. May not be higher than the value specified by
- the server.
- </doc>
- <rule implement="MAY">
- The server MAY ignore the channel-max value or MAY use it for
- tuning its resource allocation.
- </rule>
- <assert check="notnull"/>
- <assert check="le" method="tune" field="channel max"/>
- </field>
- <field name="frame max" type="long">
- negotiated maximum frame size
- <doc>
- The largest frame size that the client and server will use for
- the connection. Zero means that the client does not impose any
- specific limit but may reject very large frames if it cannot
- allocate resources for them. Note that the frame-max limit
- applies principally to content frames, where large contents
- can be broken into frames of arbitrary size.
- </doc>
- <rule implement="MUST">
- Until the frame-max has been negotiated, both peers must accept
- frames of up to 4096 octets large. The minimum non-zero value for
- the frame-max field is 4096.
- </rule>
- </field>
- <field name="heartbeat" type="short">
- desired heartbeat delay
- <doc>
- The delay, in seconds, of the connection heartbeat that the client
- wants. Zero means the client does not want a heartbeat.
- </doc>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="open" synchronous="1" index="40">
- open connection to virtual host
- <doc>
- This method opens a connection to a virtual host, which is a
- collection of resources, and acts to separate multiple application
- domains within a server.
- </doc>
- <rule implement="MUST">
- The client MUST open the context before doing any work on the
- connection.
- </rule>
- <chassis name="server" implement="MUST"/>
- <response name="open-ok"/>
- <response name="redirect"/>
- <field name="virtual host" domain="path">
- virtual host name
- <assert check="regexp" value="^[a-zA-Z0-9/-_]+$"/>
- <doc>
- The name of the virtual host to work with.
- </doc>
- <rule implement="MUST">
- If the server supports multiple virtual hosts, it MUST enforce a
- full separation of exchanges, queues, and all associated entities
- per virtual host. An application, connected to a specific virtual
- host, MUST NOT be able to access resources of another virtual host.
- </rule>
- <rule implement="SHOULD">
- The server SHOULD verify that the client has permission to access
- the specified virtual host.
- </rule>
- <rule implement="MAY">
- The server MAY configure arbitrary limits per virtual host, such
- as the number of each type of entity that may be used, per
- connection and/or in total.
- </rule>
- </field>
- <field name="capabilities" type="shortstr">
- required capabilities
- <doc>
- The client may specify a number of capability names, delimited by
- spaces. The server can use this string to how to process the
- client's connection request.
- </doc>
- </field>
- <field name="insist" type="bit">
- insist on connecting to server
- <doc>
- In a configuration with multiple load-sharing servers, the server
- may respond to a Connection.Open method with a Connection.Redirect.
- The insist option tells the server that the client is insisting on
- a connection to the specified server.
- </doc>
- <rule implement="SHOULD">
- When the client uses the insist option, the server SHOULD accept
- the client connection unless it is technically unable to do so.
- </rule>
- </field>
- </method>
- <method name="open-ok" synchronous="1" index="41">
- signal that the connection is ready
- <doc>
- This method signals to the client that the connection is ready for
- use.
- </doc>
- <chassis name="client" implement="MUST"/>
- <field name="known hosts" domain="known hosts"/>
- </method>
- <method name="redirect" synchronous="1" index="50">
- asks the client to use a different server
- <doc>
- This method redirects the client to another server, based on the
- requested virtual host and/or capabilities.
- </doc>
- <rule implement="SHOULD">
- When getting the Connection.Redirect method, the client SHOULD
- reconnect to the host specified, and if that host is not present,
- to any of the hosts specified in the known-hosts list.
- </rule>
- <chassis name="client" implement="MAY"/>
- <field name="host" type="shortstr">
- server to connect to
- <doc>
- Specifies the server to connect to. This is an IP address or a
- DNS name, optionally followed by a colon and a port number. If
- no port number is specified, the client should use the default
- port number for the protocol.
- </doc>
- <assert check="notnull"/>
- </field>
- <field name="known hosts" domain="known hosts"/>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="close" synchronous="1" index="60">
- request a connection close
- <doc>
- This method indicates that the sender wants to close the connection.
- This may be due to internal conditions (e.g. a forced shut-down) or
- due to an error handling a specific method, i.e. an exception. When
- a close is due to an exception, the sender provides the class and
- method id of the method which caused the exception.
- </doc>
- <rule implement="MUST">
- After sending this method any received method except the Close-OK
- method MUST be discarded.
- </rule>
- <rule implement="MAY">
- The peer sending this method MAY use a counter or timeout to
- detect failure of the other peer to respond correctly with
- the Close-OK method.
- </rule>
- <rule implement="MUST">
- When a server receives the Close method from a client it MUST
- delete all server-side resources associated with the client's
- context. A client CANNOT reconnect to a context after sending
- or receiving a Close method.
- </rule>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <response name="close-ok"/>
- <field name="reply code" domain="reply code"/>
- <field name="reply text" domain="reply text"/>
- <field name="class id" domain="class id">
- failing method class
- <doc>
- When the close is provoked by a method exception, this is the
- class of the method.
- </doc>
- </field>
- <field name="method id" domain="class id">
- failing method ID
- <doc>
- When the close is provoked by a method exception, this is the
- ID of the method.
- </doc>
- </field>
- </method>
- <method name="close-ok" synchronous="1" index="61">
- confirm a connection close
- <doc>
- This method confirms a Connection.Close method and tells the
- recipient that it is safe to release resources for the connection
- and close the socket.
- </doc>
- <rule implement="SHOULD">
- A peer that detects a socket closure without having received a
- Close-Ok handshake method SHOULD log the error.
- </rule>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- </method>
- </class>
- <class name="channel" handler="channel" index="20">
- <!--
-======================================================
-== CHANNEL
-======================================================
--->
- work with channels
-<doc>
- The channel class provides methods for a client to establish a virtual
- connection - a channel - to a server and for both peers to operate the
- virtual connection thereafter.
-</doc>
- <doc name="grammar">
- channel = open-channel *use-channel close-channel
- open-channel = C:OPEN S:OPEN-OK
- use-channel = C:FLOW S:FLOW-OK
- / S:FLOW C:FLOW-OK
- / S:ALERT
- / functional-class
- close-channel = C:CLOSE S:CLOSE-OK
- / S:CLOSE C:CLOSE-OK
-</doc>
- <chassis name="server" implement="MUST"/>
- <chassis name="client" implement="MUST"/>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="open" synchronous="1" index="10">
- open a channel for use
- <doc>
- This method opens a virtual connection (a channel).
- </doc>
- <rule implement="MUST">
- This method MUST NOT be called when the channel is already open.
- </rule>
- <chassis name="server" implement="MUST"/>
- <response name="open-ok"/>
- <field name="out of band" type="shortstr">
- out-of-band settings
- <doc>
- Configures out-of-band transfers on this channel. The syntax and
- meaning of this field will be formally defined at a later date.
- </doc>
- <assert check="null"/>
- </field>
- </method>
- <method name="open-ok" synchronous="1" index="11">
- signal that the channel is ready
- <doc>
- This method signals to the client that the channel is ready for use.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="flow" synchronous="1" index="20">
- enable/disable flow from peer
- <doc>
- This method asks the peer to pause or restart the flow of content
- data. This is a simple flow-control mechanism that a peer can use
- to avoid oveflowing its queues or otherwise finding itself receiving
- more messages than it can process. Note that this method is not
- intended for window control. The peer that receives a request to
- stop sending content should finish sending the current content, if
- any, and then wait until it receives a Flow restart method.
- </doc>
- <rule implement="MAY">
- When a new channel is opened, it is active. Some applications
- assume that channels are inactive until started. To emulate this
- behaviour a client MAY open the channel, then pause it.
- </rule>
- <rule implement="SHOULD">
- When sending content data in multiple frames, a peer SHOULD monitor
- the channel for incoming methods and respond to a Channel.Flow as
- rapidly as possible.
- </rule>
- <rule implement="MAY">
- A peer MAY use the Channel.Flow method to throttle incoming content
- data for internal reasons, for example, when exchangeing data over a
- slower connection.
- </rule>
- <rule implement="MAY">
- The peer that requests a Channel.Flow method MAY disconnect and/or
- ban a peer that does not respect the request.
- </rule>
- <chassis name="server" implement="MUST"/>
- <chassis name="client" implement="MUST"/>
- <response name="flow-ok"/>
- <field name="active" type="bit">
- start/stop content frames
- <doc>
- If 1, the peer starts sending content frames. If 0, the peer
- stops sending content frames.
- </doc>
- </field>
- </method>
- <method name="flow-ok" index="21">
- confirm a flow method
- <doc>
- Confirms to the peer that a flow command was received and processed.
- </doc>
- <chassis name="server" implement="MUST"/>
- <chassis name="client" implement="MUST"/>
- <field name="active" type="bit">
- current flow setting
- <doc>
- Confirms the setting of the processed flow method: 1 means the
- peer will start sending or continue to send content frames; 0
- means it will not.
- </doc>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="alert" index="30">
- send a non-fatal warning message
- <doc>
- This method allows the server to send a non-fatal warning to the
- client. This is used for methods that are normally asynchronous
- and thus do not have confirmations, and for which the server may
- detect errors that need to be reported. Fatal errors are handled
- as channel or connection exceptions; non-fatal errors are sent
- through this method.
- </doc>
- <chassis name="client" implement="MUST"/>
- <field name="reply code" domain="reply code"/>
- <field name="reply text" domain="reply text"/>
- <field name="details" type="table">
- detailed information for warning
- <doc>
- A set of fields that provide more information about the
- problem. The meaning of these fields are defined on a
- per-reply-code basis (TO BE DEFINED).
- </doc>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="close" synchronous="1" index="40">
- request a channel close
- <doc>
- This method indicates that the sender wants to close the channel.
- This may be due to internal conditions (e.g. a forced shut-down) or
- due to an error handling a specific method, i.e. an exception. When
- a close is due to an exception, the sender provides the class and
- method id of the method which caused the exception.
- </doc>
- <rule implement="MUST">
- After sending this method any received method except
- Channel.Close-OK MUST be discarded.
- </rule>
- <rule implement="MAY">
- The peer sending this method MAY use a counter or timeout to detect
- failure of the other peer to respond correctly with Channel.Close-OK..
- </rule>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <response name="close-ok"/>
- <field name="reply code" domain="reply code"/>
- <field name="reply text" domain="reply text"/>
- <field name="class id" domain="class id">
- failing method class
- <doc>
- When the close is provoked by a method exception, this is the
- class of the method.
- </doc>
- </field>
- <field name="method id" domain="method id">
- failing method ID
- <doc>
- When the close is provoked by a method exception, this is the
- ID of the method.
- </doc>
- </field>
- </method>
- <method name="close-ok" synchronous="1" index="41">
- confirm a channel close
- <doc>
- This method confirms a Channel.Close method and tells the recipient
- that it is safe to release resources for the channel and close the
- socket.
- </doc>
- <rule implement="SHOULD">
- A peer that detects a socket closure without having received a
- Channel.Close-Ok handshake method SHOULD log the error.
- </rule>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- </method>
- </class>
- <class name="access" handler="connection" index="30">
- <!--
-======================================================
-== ACCESS CONTROL
-======================================================
--->
- work with access tickets
-<doc>
- The protocol control access to server resources using access tickets.
- A client must explicitly request access tickets before doing work.
- An access ticket grants a client the right to use a specific set of
- resources - called a "realm" - in specific ways.
-</doc>
- <doc name="grammar">
- access = C:REQUEST S:REQUEST-OK
-</doc>
- <chassis name="server" implement="MUST"/>
- <chassis name="client" implement="MUST"/>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="request" synchronous="1" index="10">
- request an access ticket
- <doc>
- This method requests an access ticket for an access realm.
- The server responds by granting the access ticket. If the
- client does not have access rights to the requested realm
- this causes a connection exception. Access tickets are a
- per-channel resource.
- </doc>
- <rule implement="MUST">
- The realm name MUST start with either "/data" (for application
- resources) or "/admin" (for server administration resources).
- If the realm starts with any other path, the server MUST raise
- a connection exception with reply code 403 (access refused).
- </rule>
- <rule implement="MUST">
- The server MUST implement the /data realm and MAY implement the
- /admin realm. The mapping of resources to realms is not
- defined in the protocol - this is a server-side configuration
- issue.
- </rule>
- <chassis name="server" implement="MUST"/>
- <response name="request-ok"/>
- <field name="realm" domain="path">
- name of requested realm
- <rule implement="MUST">
- If the specified realm is not known to the server, the server
- must raise a channel exception with reply code 402 (invalid
- path).
- </rule>
- </field>
- <field name="exclusive" type="bit">
- request exclusive access
- <doc>
- Request exclusive access to the realm. If the server cannot grant
- this - because there are other active tickets for the realm - it
- raises a channel exception.
- </doc>
- </field>
- <field name="passive" type="bit">
- request passive access
- <doc>
- Request message passive access to the specified access realm.
- Passive access lets a client get information about resources in
- the realm but not to make any changes to them.
- </doc>
- </field>
- <field name="active" type="bit">
- request active access
- <doc>
- Request message active access to the specified access realm.
- Acvtive access lets a client get create and delete resources in
- the realm.
- </doc>
- </field>
- <field name="write" type="bit">
- request write access
- <doc>
- Request write access to the specified access realm. Write access
- lets a client publish messages to all exchanges in the realm.
- </doc>
- </field>
- <field name="read" type="bit">
- request read access
- <doc>
- Request read access to the specified access realm. Read access
- lets a client consume messages from queues in the realm.
- </doc>
- </field>
- </method>
- <method name="request-ok" synchronous="1" index="11">
- grant access to server resources
- <doc>
- This method provides the client with an access ticket. The access
- ticket is valid within the current channel and for the lifespan of
- the channel.
- </doc>
- <rule implement="MUST">
- The client MUST NOT use access tickets except within the same
- channel as originally granted.
- </rule>
- <rule implement="MUST">
- The server MUST isolate access tickets per channel and treat an
- attempt by a client to mix these as a connection exception.
- </rule>
- <chassis name="client" implement="MUST"/>
- <field name="ticket" domain="access ticket"/>
- </method>
- </class>
- <class name="exchange" handler="channel" index="40">
- <!--
-======================================================
-== EXCHANGES (or "routers", if you prefer)
-== (Or matchers, plugins, extensions, agents,... Routing is just one of
-== the many fun things an exchange can do.)
-======================================================
--->
- work with exchanges
-<doc>
- Exchanges match and distribute messages across queues. Exchanges can be
- configured in the server or created at runtime.
-</doc>
- <doc name="grammar">
- exchange = C:DECLARE S:DECLARE-OK
- / C:DELETE S:DELETE-OK
-</doc>
- <chassis name="server" implement="MUST"/>
- <chassis name="client" implement="MUST"/>
- <rule implement="MUST">
- <test>amq_exchange_19</test>
- The server MUST implement the direct and fanout exchange types, and
- predeclare the corresponding exchanges named amq.direct and amq.fanout
- in each virtual host. The server MUST also predeclare a direct
- exchange to act as the default exchange for content Publish methods
- and for default queue bindings.
-</rule>
- <rule implement="SHOULD">
- <test>amq_exchange_20</test>
- The server SHOULD implement the topic exchange type, and predeclare
- the corresponding exchange named amq.topic in each virtual host.
-</rule>
- <rule implement="MAY">
- <test>amq_exchange_21</test>
- The server MAY implement the system exchange type, and predeclare the
- corresponding exchanges named amq.system in each virtual host. If the
- client attempts to bind a queue to the system exchange, the server
- MUST raise a connection exception with reply code 507 (not allowed).
-</rule>
- <rule implement="MUST">
- <test>amq_exchange_22</test>
- The default exchange MUST be defined as internal, and be inaccessible
- to the client except by specifying an empty exchange name in a content
- Publish method. That is, the server MUST NOT let clients make explicit
- bindings to this exchange.
-</rule>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="declare" synchronous="1" index="10">
- declare exchange, create if needed
- <doc>
- This method creates an exchange if it does not already exist, and if the
- exchange exists, verifies that it is of the correct and expected class.
- </doc>
- <rule implement="SHOULD">
- <test>amq_exchange_23</test>
- The server SHOULD support a minimum of 16 exchanges per virtual host
- and ideally, impose no limit except as defined by available resources.
- </rule>
- <chassis name="server" implement="MUST"/>
- <response name="declare-ok"/>
- <field name="ticket" domain="access ticket">
- <doc>
- When a client defines a new exchange, this belongs to the access realm
- of the ticket used. All further work done with that exchange must be
- done with an access ticket for the same realm.
- </doc>
- <rule implement="MUST">
- The client MUST provide a valid access ticket giving "active" access
- to the realm in which the exchange exists or will be created, or
- "passive" access if the if-exists flag is set.
- </rule>
- </field>
- <field name="exchange" domain="exchange name">
- <rule implement="MUST">
- <test>amq_exchange_15</test>
- Exchange names starting with "amq." are reserved for predeclared
- and standardised exchanges. If the client attempts to create an
- exchange starting with "amq.", the server MUST raise a channel
- exception with reply code 403 (access refused).
- </rule>
- <assert check="regexp" value="^[a-zA-Z0-9-_.:]+$"/>
- </field>
- <field name="type" type="shortstr">
- exchange type
- <doc>
- Each exchange belongs to one of a set of exchange types implemented
- by the server. The exchange types define the functionality of the
- exchange - i.e. how messages are routed through it. It is not valid
- or meaningful to attempt to change the type of an existing exchange.
- </doc>
- <rule implement="MUST">
- <test>amq_exchange_16</test>
- If the exchange already exists with a different type, the server
- MUST raise a connection exception with a reply code 507 (not allowed).
- </rule>
- <rule implement="MUST">
- <test>amq_exchange_18</test>
- If the server does not support the requested exchange type it MUST
- raise a connection exception with a reply code 503 (command invalid).
- </rule>
- <assert check="regexp" value="^[a-zA-Z0-9-_.:]+$"/>
- </field>
- <field name="passive" type="bit">
- do not create exchange
- <doc>
- If set, the server will not create the exchange. The client can use
- this to check whether an exchange exists without modifying the server
- state.
- </doc>
- <rule implement="MUST">
- <test>amq_exchange_05</test>
- If set, and the exchange does not already exist, the server MUST
- raise a channel exception with reply code 404 (not found).
- </rule>
- </field>
- <field name="durable" type="bit">
- request a durable exchange
- <doc>
- If set when creating a new exchange, the exchange will be marked as
- durable. Durable exchanges remain active when a server restarts.
- Non-durable exchanges (transient exchanges) are purged if/when a
- server restarts.
- </doc>
- <rule implement="MUST">
- <test>amq_exchange_24</test>
- The server MUST support both durable and transient exchanges.
- </rule>
- <rule implement="MUST">
- The server MUST ignore the durable field if the exchange already
- exists.
- </rule>
- </field>
- <field name="auto delete" type="bit">
- auto-delete when unused
- <doc>
- If set, the exchange is deleted when all queues have finished
- using it.
- </doc>
- <rule implement="SHOULD">
- <test>amq_exchange_02</test>
- The server SHOULD allow for a reasonable delay between the point
- when it determines that an exchange is not being used (or no longer
- used), and the point when it deletes the exchange. At the least it
- must allow a client to create an exchange and then bind a queue to
- it, with a small but non-zero delay between these two actions.
- </rule>
- <rule implement="MUST">
- <test>amq_exchange_25</test>
- The server MUST ignore the auto-delete field if the exchange already
- exists.
- </rule>
- </field>
- <field name="internal" type="bit">
- create internal exchange
- <doc>
- If set, the exchange may not be used directly by publishers, but
- only when bound to other exchanges. Internal exchanges are used to
- construct wiring that is not visible to applications.
- </doc>
- </field>
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-
- <field name="arguments" type="table">
- arguments for declaration
- <doc>
- A set of arguments for the declaration. The syntax and semantics
- of these arguments depends on the server implementation. This
- field is ignored if passive is 1.
- </doc>
- </field>
- </method>
- <method name="declare-ok" synchronous="1" index="11">
- confirms an exchange declaration
- <doc>
- This method confirms a Declare method and confirms the name of the
- exchange, essential for automatically-named exchanges.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="delete" synchronous="1" index="20">
- delete an exchange
- <doc>
- This method deletes an exchange. When an exchange is deleted all queue
- bindings on the exchange are cancelled.
- </doc>
- <chassis name="server" implement="MUST"/>
- <response name="delete-ok"/>
- <field name="ticket" domain="access ticket">
- <rule implement="MUST">
- The client MUST provide a valid access ticket giving "active"
- access rights to the exchange's access realm.
- </rule>
- </field>
- <field name="exchange" domain="exchange name">
- <rule implement="MUST">
- <test>amq_exchange_11</test>
- The exchange MUST exist. Attempting to delete a non-existing exchange
- causes a channel exception.
- </rule>
- <assert check="notnull"/>
- </field>
- <field name="if unused" type="bit">
- delete only if unused
- <doc>
- If set, the server will only delete the exchange if it has no queue
- bindings. If the exchange has queue bindings the server does not
- delete it but raises a channel exception instead.
- </doc>
- <rule implement="SHOULD">
- <test>amq_exchange_12</test>
- If set, the server SHOULD delete the exchange but only if it has
- no queue bindings.
- </rule>
- <rule implement="SHOULD">
- <test>amq_exchange_13</test>
- If set, the server SHOULD raise a channel exception if the exchange is in
- use.
- </rule>
- </field>
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-
- </method>
- <method name="delete-ok" synchronous="1" index="21">
- confirm deletion of an exchange
- <doc>
- This method confirms the deletion of an exchange.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- </class>
- <class name="queue" handler="channel" index="50">
- <!--
-======================================================
-== QUEUES
-======================================================
--->
- work with queues
-
-<doc>
- Queues store and forward messages. Queues can be configured in the server
- or created at runtime. Queues must be attached to at least one exchange
- in order to receive messages from publishers.
-</doc>
- <doc name="grammar">
- queue = C:DECLARE S:DECLARE-OK
- / C:BIND S:BIND-OK
- / C:PURGE S:PURGE-OK
- / C:DELETE S:DELETE-OK
-</doc>
- <chassis name="server" implement="MUST"/>
- <chassis name="client" implement="MUST"/>
- <rule implement="MUST">
- <test>amq_queue_33</test>
- A server MUST allow any content class to be sent to any queue, in any
- mix, and queue and delivery these content classes independently. Note
- that all methods that fetch content off queues are specific to a given
- content class.
-</rule>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="declare" synchronous="1" index="10">
- declare queue, create if needed
- <doc>
- This method creates or checks a queue. When creating a new queue
- the client can specify various properties that control the durability
- of the queue and its contents, and the level of sharing for the queue.
- </doc>
- <rule implement="MUST">
- <test>amq_queue_34</test>
- The server MUST create a default binding for a newly-created queue
- to the default exchange, which is an exchange of type 'direct'.
- </rule>
- <rule implement="SHOULD">
- <test>amq_queue_35</test>
- The server SHOULD support a minimum of 256 queues per virtual host
- and ideally, impose no limit except as defined by available resources.
- </rule>
- <chassis name="server" implement="MUST"/>
- <response name="declare-ok"/>
- <field name="ticket" domain="access ticket">
- <doc>
- When a client defines a new queue, this belongs to the access realm
- of the ticket used. All further work done with that queue must be
- done with an access ticket for the same realm.
- </doc>
- <doc>
- The client provides a valid access ticket giving "active" access
- to the realm in which the queue exists or will be created, or
- "passive" access if the if-exists flag is set.
- </doc>
- </field>
- <field name="queue" domain="queue name">
- <rule implement="MAY">
- <test>amq_queue_10</test>
- The queue name MAY be empty, in which case the server MUST create
- a new queue with a unique generated name and return this to the
- client in the Declare-Ok method.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_32</test>
- Queue names starting with "amq." are reserved for predeclared and
- standardised server queues. If the queue name starts with "amq."
- and the passive option is zero, the server MUST raise a connection
- exception with reply code 403 (access refused).
- </rule>
- <assert check="regexp" value="^[a-zA-Z0-9-_.:]*$"/>
- </field>
- <field name="passive" type="bit">
- do not create queue
- <doc>
- If set, the server will not create the queue. The client can use
- this to check whether a queue exists without modifying the server
- state.
- </doc>
- <rule implement="MUST">
- <test>amq_queue_05</test>
- If set, and the queue does not already exist, the server MUST
- respond with a reply code 404 (not found) and raise a channel
- exception.
- </rule>
- </field>
- <field name="durable" type="bit">
- request a durable queue
- <doc>
- If set when creating a new queue, the queue will be marked as
- durable. Durable queues remain active when a server restarts.
- Non-durable queues (transient queues) are purged if/when a
- server restarts. Note that durable queues do not necessarily
- hold persistent messages, although it does not make sense to
- send persistent messages to a transient queue.
- </doc>
- <rule implement="MUST">
- <test>amq_queue_03</test>
- The server MUST recreate the durable queue after a restart.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_36</test>
- The server MUST support both durable and transient queues.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_37</test>
- The server MUST ignore the durable field if the queue already
- exists.
- </rule>
- </field>
- <field name="exclusive" type="bit">
- request an exclusive queue
- <doc>
- Exclusive queues may only be consumed from by the current connection.
- Setting the 'exclusive' flag always implies 'auto-delete'.
- </doc>
- <rule implement="MUST">
- <test>amq_queue_38</test>
- The server MUST support both exclusive (private) and non-exclusive
- (shared) queues.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_04</test>
- The server MUST raise a channel exception if 'exclusive' is specified
- and the queue already exists and is owned by a different connection.
- </rule>
- </field>
- <field name="auto delete" type="bit">
- auto-delete queue when unused
- <doc>
- If set, the queue is deleted when all consumers have finished
- using it. Last consumer can be cancelled either explicitly or because
- its channel is closed. If there was no consumer ever on the queue, it
- won't be deleted.
- </doc>
- <rule implement="SHOULD">
- <test>amq_queue_02</test>
- The server SHOULD allow for a reasonable delay between the point
- when it determines that a queue is not being used (or no longer
- used), and the point when it deletes the queue. At the least it
- must allow a client to create a queue and then create a consumer
- to read from it, with a small but non-zero delay between these
- two actions. The server should equally allow for clients that may
- be disconnected prematurely, and wish to re-consume from the same
- queue without losing messages. We would recommend a configurable
- timeout, with a suitable default value being one minute.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_31</test>
- The server MUST ignore the auto-delete field if the queue already
- exists.
- </rule>
- </field>
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-
- <field name="arguments" type="table">
- arguments for declaration
- <doc>
- A set of arguments for the declaration. The syntax and semantics
- of these arguments depends on the server implementation. This
- field is ignored if passive is 1.
- </doc>
- </field>
- </method>
- <method name="declare-ok" synchronous="1" index="11">
- confirms a queue definition
- <doc>
- This method confirms a Declare method and confirms the name of the
- queue, essential for automatically-named queues.
- </doc>
- <chassis name="client" implement="MUST"/>
- <field name="queue" domain="queue name">
- <doc>
- Reports the name of the queue. If the server generated a queue
- name, this field contains that name.
- </doc>
- <assert check="notnull"/>
- </field>
- <field name="message count" type="long">
- number of messages in queue
- <doc>
- Reports the number of messages in the queue, which will be zero
- for newly-created queues.
- </doc>
- </field>
- <field name="consumer count" type="long">
- number of consumers
- <doc>
- Reports the number of active consumers for the queue. Note that
- consumers can suspend activity (Channel.Flow) in which case they
- do not appear in this count.
- </doc>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="bind" synchronous="1" index="20">
- bind queue to an exchange
- <doc>
- This method binds a queue to an exchange. Until a queue is
- bound it will not receive any messages. In a classic messaging
- model, store-and-forward queues are bound to a dest exchange
- and subscription queues are bound to a dest_wild exchange.
- </doc>
- <rule implement="MUST">
- <test>amq_queue_25</test>
- A server MUST allow ignore duplicate bindings - that is, two or
- more bind methods for a specific queue, with identical arguments
- - without treating these as an error.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_39</test>
- If a bind fails, the server MUST raise a connection exception.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_12</test>
- The server MUST NOT allow a durable queue to bind to a transient
- exchange. If the client attempts this the server MUST raise a
- channel exception.
- </rule>
- <rule implement="SHOULD">
- <test>amq_queue_13</test>
- Bindings for durable queues are automatically durable and the
- server SHOULD restore such bindings after a server restart.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_17</test>
- If the client attempts to an exchange that was declared as internal,
- the server MUST raise a connection exception with reply code 530
- (not allowed).
- </rule>
- <rule implement="SHOULD">
- <test>amq_queue_40</test>
- The server SHOULD support at least 4 bindings per queue, and
- ideally, impose no limit except as defined by available resources.
- </rule>
- <chassis name="server" implement="MUST"/>
- <response name="bind-ok"/>
- <field name="ticket" domain="access ticket">
- <doc>
- The client provides a valid access ticket giving "active"
- access rights to the queue's access realm.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue name">
- <doc>
- Specifies the name of the queue to bind. If the queue name is
- empty, refers to the current queue for the channel, which is
- the last declared queue.
- </doc>
- <doc name = "rule">
- If the client did not previously declare a queue, and the queue
- name in this method is empty, the server MUST raise a connection
- exception with reply code 530 (not allowed).
- </doc>
- <doc name = "rule" test = "amq_queue_26">
- If the queue does not exist the server MUST raise a channel exception
- with reply code 404 (not found).
- </doc>
- </field>
-
- <field name="exchange" domain="exchange name">
- The name of the exchange to bind to.
- <rule implement="MUST">
- <test>amq_queue_14</test>
- If the exchange does not exist the server MUST raise a channel
- exception with reply code 404 (not found).
- </rule>
- </field>
- <field name="routing key" type="shortstr">
- message routing key
- <doc>
- Specifies the routing key for the binding. The routing key is
- used for routing messages depending on the exchange configuration.
- Not all exchanges use a routing key - refer to the specific
- exchange documentation. If the routing key is empty and the queue
- name is empty, the routing key will be the current queue for the
- channel, which is the last declared queue.
- </doc>
- </field>
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-
- <field name="arguments" type="table">
- arguments for binding
- <doc>
- A set of arguments for the binding. The syntax and semantics of
- these arguments depends on the exchange class.
- </doc>
- </field>
- </method>
- <method name="bind-ok" synchronous="1" index="21">
- confirm bind successful
- <doc>
- This method confirms that the bind was successful.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="purge" synchronous="1" index="30">
- purge a queue
- <doc>
- This method removes all messages from a queue. It does not cancel
- consumers. Purged messages are deleted without any formal "undo"
- mechanism.
- </doc>
- <rule implement="MUST">
- <test>amq_queue_15</test>
- A call to purge MUST result in an empty queue.
- </rule>
- <rule implement="MUST">
- <test>amq_queue_41</test>
- On transacted channels the server MUST not purge messages that have
- already been sent to a client but not yet acknowledged.
- </rule>
- <rule implement="MAY">
- <test>amq_queue_42</test>
- The server MAY implement a purge queue or log that allows system
- administrators to recover accidentally-purged messages. The server
- SHOULD NOT keep purged messages in the same storage spaces as the
- live messages since the volumes of purged messages may get very
- large.
- </rule>
- <chassis name="server" implement="MUST"/>
- <response name="purge-ok"/>
- <field name="ticket" domain="access ticket">
- <doc>
- The access ticket must be for the access realm that holds the
- queue.
- </doc>
- <rule implement="MUST">
- The client MUST provide a valid access ticket giving "read" access
- rights to the queue's access realm. Note that purging a queue is
- equivalent to reading all messages and discarding them.
- </rule>
- </field>
- <field name = "queue" domain = "queue name">
- <doc>
- Specifies the name of the queue to purge. If the queue name is
- empty, refers to the current queue for the channel, which is
- the last declared queue.
- </doc>
- <doc name = "rule">
- If the client did not previously declare a queue, and the queue
- name in this method is empty, the server MUST raise a connection
- exception with reply code 530 (not allowed).
- </doc>
- <doc name = "rule" test = "amq_queue_16">
- The queue must exist. Attempting to purge a non-existing queue
- causes a channel exception.
- </doc>
- </field>
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
- </method>
- <method name="purge-ok" synchronous="1" index="31">
- confirms a queue purge
- <doc>
- This method confirms the purge of a queue.
- </doc>
- <chassis name="client" implement="MUST"/>
- <field name="message count" type="long">
- number of messages purged
- <doc>
- Reports the number of messages purged.
- </doc>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="delete" synchronous="1" index="40">
- delete a queue
- <doc>
- This method deletes a queue. When a queue is deleted any pending
- messages are sent to a dead-letter queue if this is defined in the
- server configuration, and all consumers on the queue are cancelled.
- </doc>
- <rule implement="SHOULD">
- <test>amq_queue_43</test>
- The server SHOULD use a dead-letter queue to hold messages that
- were pending on a deleted queue, and MAY provide facilities for
- a system administrator to move these messages back to an active
- queue.
- </rule>
- <chassis name="server" implement="MUST"/>
- <response name="delete-ok"/>
- <field name="ticket" domain="access ticket">
- <doc>
- The client provides a valid access ticket giving "active"
- access rights to the queue's access realm.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue name">
- <doc>
- Specifies the name of the queue to delete. If the queue name is
- empty, refers to the current queue for the channel, which is the
- last declared queue.
- </doc>
- <doc name = "rule">
- If the client did not previously declare a queue, and the queue
- name in this method is empty, the server MUST raise a connection
- exception with reply code 530 (not allowed).
- </doc>
- <doc name = "rule" test = "amq_queue_21">
- The queue must exist. Attempting to delete a non-existing queue
- causes a channel exception.
- </doc>
- </field>
-
- <field name="if unused" type="bit">
- delete only if unused
- <doc>
- If set, the server will only delete the queue if it has no
- consumers. If the queue has consumers the server does does not
- delete it but raises a channel exception instead.
- </doc>
- <rule implement="MUST">
- <test>amq_queue_29</test>
- <test>amq_queue_30</test>
- The server MUST respect the if-unused flag when deleting a queue.
- </rule>
- </field>
- <field name="if empty" type="bit">
- delete only if empty
- <test>amq_queue_27</test>
- <doc>
- If set, the server will only delete the queue if it has no
- messages. If the queue is not empty the server raises a channel
- exception.
- </doc>
- </field>
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name="delete-ok" synchronous="1" index="41">
- confirm deletion of a queue
- <doc>
- This method confirms the deletion of a queue.
- </doc>
- <chassis name="client" implement="MUST"/>
- <field name="message count" type="long">
- number of messages purged
- <doc>
- Reports the number of messages purged.
- </doc>
- </field>
- </method>
- </class>
- <class name="basic" handler="channel" index="60">
- <!--
-======================================================
-== BASIC MIDDLEWARE
-======================================================
--->
- work with basic content
-<doc>
- The Basic class provides methods that support an industry-standard
- messaging model.
-</doc>
-
-<doc name = "grammar">
- basic = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:PUBLISH content
- / S:RETURN content
- / S:DELIVER content
- / C:GET ( S:GET-OK content / S:GET-EMPTY )
- / C:ACK
- / C:REJECT
-</doc>
-
-<chassis name = "server" implement = "MUST" />
-<chassis name = "client" implement = "MAY" />
-
-<doc name = "rule" test = "amq_basic_08">
- The server SHOULD respect the persistent property of basic messages
- and SHOULD make a best-effort to hold persistent basic messages on a
- reliable storage mechanism.
-</doc>
-<doc name = "rule" test = "amq_basic_09">
- The server MUST NOT discard a persistent basic message in case of a
- queue overflow. The server MAY use the Channel.Flow method to slow
- or stop a basic message publisher when necessary.
-</doc>
-<doc name = "rule" test = "amq_basic_10">
- The server MAY overflow non-persistent basic messages to persistent
- storage and MAY discard or dead-letter non-persistent basic messages
- on a priority basis if the queue size exceeds some configured limit.
-</doc>
-<doc name = "rule" test = "amq_basic_11">
- The server MUST implement at least 2 priority levels for basic
- messages, where priorities 0-4 and 5-9 are treated as two distinct
- levels. The server MAY implement up to 10 priority levels.
-</doc>
-<doc name = "rule" test = "amq_basic_12">
- The server MUST deliver messages of the same priority in order
- irrespective of their individual persistence.
-</doc>
-<doc name = "rule" test = "amq_basic_13">
- The server MUST support both automatic and explicit acknowledgements
- on Basic content.
-</doc>
-
-<!-- These are the properties for a Basic content -->
-
-<field name = "content type" type = "shortstr">
- MIME content type
-</field>
-<field name = "content encoding" type = "shortstr">
- MIME content encoding
-</field>
-<field name = "headers" type = "table">
- Message header field table
-</field>
-<field name = "delivery mode" type = "octet">
- Non-persistent (1) or persistent (2)
-</field>
-<field name = "priority" type = "octet">
- The message priority, 0 to 9
-</field>
-<field name = "correlation id" type = "shortstr">
- The application correlation identifier
-</field>
-<field name = "reply to" type = "shortstr">
- The destination to reply to
-</field>
-<field name = "expiration" type = "shortstr">
- Message expiration specification
-</field>
-<field name = "message id" type = "shortstr">
- The application message identifier
-</field>
-<field name = "timestamp" type = "timestamp">
- The message timestamp
-</field>
-<field name = "type" type = "shortstr">
- The message type name
-</field>
-<field name = "user id" type = "shortstr">
- The creating user id
-</field>
-<field name = "app id" type = "shortstr">
- The creating application id
-</field>
-<field name = "cluster id" type = "shortstr">
- Intra-cluster routing identifier
-</field>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "qos" synchronous = "1" index = "10">
- specify quality of service
- <doc>
- This method requests a specific quality of service. The QoS can
- be specified for the current channel or for all channels on the
- connection. The particular properties and semantics of a qos method
- always depend on the content class semantics. Though the qos method
- could in principle apply to both peers, it is currently meaningful
- only for the server.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "qos-ok" />
-
- <field name = "prefetch size" type = "long">
- prefetch window in octets
- <doc>
- The client can request that messages be sent in advance so that
- when the client finishes processing a message, the following
- message is already held locally, rather than needing to be sent
- down the channel. Prefetching gives a performance improvement.
- This field specifies the prefetch window size in octets. The
- server will send a message in advance if it is equal to or
- smaller in size than the available prefetch size (and also falls
- into other prefetch limits). May be set to zero, meaning "no
- specific limit", although other prefetch limits may still apply.
- The prefetch-size is ignored if the no-ack option is set.
- </doc>
- <doc name = "rule" test = "amq_basic_17">
- The server MUST ignore this setting when the client is not
- processing any messages - i.e. the prefetch size does not limit
- the transfer of single messages to a client, only the sending in
- advance of more messages while the client still has one or more
- unacknowledged messages.
- </doc>
- </field>
-
- <field name = "prefetch count" type = "short">
- prefetch window in messages
- <doc>
- Specifies a prefetch window in terms of whole messages. This
- field may be used in combination with the prefetch-size field;
- a message will only be sent in advance if both prefetch windows
- (and those at the channel and connection level) allow it.
- The prefetch-count is ignored if the no-ack option is set.
- </doc>
- <doc name = "rule" test = "amq_basic_18">
- The server MAY send less data in advance than allowed by the
- client's specified prefetch windows but it MUST NOT send more.
- </doc>
- </field>
-
- <field name = "global" type = "bit">
- apply to entire connection
- <doc>
- By default the QoS settings apply to the current channel only. If
- this field is set, they are applied to the entire connection.
- </doc>
- </field>
-</method>
-
-<method name = "qos-ok" synchronous = "1" index = "11">
- confirm the requested qos
- <doc>
- This method tells the client that the requested QoS levels could
- be handled by the server. The requested QoS applies to all active
- consumers until a new QoS is defined.
- </doc>
- <chassis name = "client" implement = "MUST" />
-</method>
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "consume" synchronous = "1" index = "20">
- start a queue consumer
- <doc>
- This method asks the server to start a "consumer", which is a
- transient request for messages from a specific queue. Consumers
- last as long as the channel they were created on, or until the
- client cancels them.
- </doc>
- <doc name = "rule" test = "amq_basic_01">
- The server SHOULD support at least 16 consumers per queue, unless
- the queue was declared as private, and ideally, impose no limit
- except as defined by available resources.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access ticket">
- <doc name = "rule">
- The client MUST provide a valid access ticket giving "read" access
- rights to the realm for the queue.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name
- is null, refers to the current queue for the channel, which is the
- last declared queue.
- </doc>
- <doc name = "rule">
- If the client did not previously declare a queue, and the queue name
- in this method is empty, the server MUST raise a connection exception
- with reply code 530 (not allowed).
- </doc>
- </field>
-
- <field name = "consumer tag" domain = "consumer tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is
- local to a connection, so two clients can use the same consumer
- tags. If this field is empty the server will generate a unique
- tag.
- </doc>
- <doc name = "rule" test = "todo">
- The tag MUST NOT refer to an existing consumer. If the client
- attempts to create two consumers with the same non-empty tag
- the server MUST raise a connection exception with reply code
- 530 (not allowed).
- </doc>
- </field>
-
- <field name = "no local" domain = "no local" />
-
- <field name = "no ack" domain = "no ack" />
-
- <field name = "exclusive" type = "bit">
- request exclusive access
- <doc>
- Request exclusive consumer access, meaning only this consumer can
- access the queue.
- </doc>
- <doc name = "rule" test = "amq_basic_02">
- If the server cannot grant exclusive access to the queue when asked,
- - because there are other consumers active - it MUST raise a channel
- exception with return code 403 (access refused).
- </doc>
- </field>
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-</method>
-
-<method name = "consume-ok" synchronous = "1" index = "21">
- confirm a new consumer
- <doc>
- The server provides the client with a consumer tag, which is used
- by the client for methods called on the consumer at a later stage.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag">
- <doc>
- Holds the consumer tag specified by the client or provided by
- the server.
- </doc>
- </field>
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "cancel" synchronous = "1" index = "30">
- end a queue consumer
- <doc test = "amq_basic_04">
- This method cancels a consumer. This does not affect already
- delivered messages, but it does mean the server will not send any
- more messages for that consumer. The client may receive an
- abitrary number of messages in between sending the cancel method
- and receiving the cancel-ok reply.
- </doc>
- <doc name = "rule" test = "todo">
- If the queue no longer exists when the client sends a cancel command,
- or the consumer has been cancelled for other reasons, this command
- has no effect.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "cancel-ok" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-</method>
-
-<method name = "cancel-ok" synchronous = "1" index = "31">
- confirm a cancelled consumer
- <doc>
- This method confirms that the cancellation was completed.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "publish" content = "1" index = "40">
- publish a message
- <doc>
- This method publishes a message to a specific exchange. The message
- will be routed to queues as defined by the exchange configuration
- and distributed to any active consumers when the transaction, if any,
- is committed.
- </doc>
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access ticket">
- <doc name = "rule">
- The client MUST provide a valid access ticket giving "write"
- access rights to the access realm for the exchange.
- </doc>
- </field>
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange
- name can be empty, meaning the default exchange. If the exchange
- name is specified, and that exchange does not exist, the server
- will raise a channel exception.
- </doc>
- <doc name = "rule" test = "amq_basic_06">
- The server MUST accept a blank exchange name to mean the default
- exchange.
- </doc>
- <doc name = "rule" test = "amq_basic_14">
- If the exchange was declared as an internal exchange, the server
- MUST raise a channel exception with a reply code 403 (access
- refused).
- </doc>
- <doc name = "rule" test = "amq_basic_15">
- The exchange MAY refuse basic content in which case it MUST raise
- a channel exception with reply code 540 (not implemented).
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key for the message. The routing key is
- used for routing messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" type = "bit">
- indicate mandatory routing
- <doc>
- This flag tells the server how to react if the message cannot be
- routed to a queue. If this flag is set, the server will return an
- unroutable message with a Return method. If this flag is zero, the
- server silently drops the message.
- </doc>
- <doc name = "rule" test = "amq_basic_07">
- The server SHOULD implement the mandatory flag.
- </doc>
- </field>
-
- <field name = "immediate" type = "bit">
- request immediate delivery
- <doc>
- This flag tells the server how to react if the message cannot be
- routed to a queue consumer immediately. If this flag is set, the
- server will return an undeliverable message with a Return method.
- If this flag is zero, the server will queue the message, but with
- no guarantee that it will ever be consumed.
- </doc>
- <doc name = "rule" test = "amq_basic_16">
- The server SHOULD implement the immediate flag.
- </doc>
- </field>
-</method>
-
-<method name = "return" content = "1" index = "50">
- return a failed message
- <doc>
- This method returns an undeliverable message that was published
- with the "immediate" flag set, or an unroutable message published
- with the "mandatory" flag set. The reply code and text provide
- information about the reason that the message was undeliverable.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply code" domain = "reply code" />
- <field name = "reply text" domain = "reply text" />
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange that the message was
- originally published to.
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key name specified when the message was
- published.
- </doc>
- </field>
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "deliver" content = "1" index = "60">
- notify the client of a consumer message
- <doc>
- This method delivers a message to the client, via a consumer. In
- the asynchronous message delivery model, the client starts a
- consumer using the Consume method, then the server responds with
- Deliver methods as and when messages arrive for that consumer.
- </doc>
- <doc name = "rule" test = "amq_basic_19">
- The server SHOULD track the number of times a message has been
- delivered to clients and when a message is redelivered a certain
- number of times - e.g. 5 times - without being acknowledged, the
- server SHOULD consider the message to be unprocessable (possibly
- causing client applications to abort), and move the message to a
- dead letter queue.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-
- <field name = "delivery tag" domain = "delivery tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange that the message was
- originally published to.
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key name specified when the message was
- published.
- </doc>
- </field>
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "get" synchronous = "1" index = "70">
- direct access to a queue
- <doc>
- This method provides a direct access to the messages in a queue
- using a synchronous dialogue that is designed for specific types of
- application where synchronous functionality is more important than
- performance.
- </doc>
- <response name = "get-ok" />
- <response name = "get-empty" />
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access ticket">
- <doc name = "rule">
- The client MUST provide a valid access ticket giving "read"
- access rights to the realm for the queue.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name
- is null, refers to the current queue for the channel, which is the
- last declared queue.
- </doc>
- <doc name = "rule">
- If the client did not previously declare a queue, and the queue name
- in this method is empty, the server MUST raise a connection exception
- with reply code 530 (not allowed).
- </doc>
- </field>
-
- <field name = "no ack" domain = "no ack" />
-</method>
-
-<method name = "get-ok" synchronous = "1" content = "1" index = "71">
- provide client with a message
- <doc>
- This method delivers a message to the client following a get
- method. A message delivered by 'get-ok' must be acknowledged
- unless the no-ack option was set in the get method.
- </doc>
- <chassis name = "client" implement = "MAY" />
-
- <field name = "delivery tag" domain = "delivery tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange that the message was originally
- published to. If empty, the message was published to the default
- exchange.
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key name specified when the message was
- published.
- </doc>
- </field>
-
- <field name = "message count" type = "long" >
- number of messages pending
- <doc>
- This field reports the number of messages pending on the queue,
- excluding the message being delivered. Note that this figure is
- indicative, not reliable, and can change arbitrarily as messages
- are added to the queue and removed by other clients.
- </doc>
- </field>
-</method>
-
-
-<method name = "get-empty" synchronous = "1" index = "72">
- indicate no messages available
- <doc>
- This method tells the client that the queue has no messages
- available for the client.
- </doc>
- <chassis name = "client" implement = "MAY" />
-
- <field name = "cluster id" type = "shortstr">
- Cluster id
- <doc>
- For use by cluster applications, should not be used by
- client applications.
- </doc>
- </field>
-</method>
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "ack" index = "80">
- acknowledge one or more messages
- <doc>
- This method acknowledges one or more messages delivered via the
- Deliver or Get-Ok methods. The client can ask to confirm a
- single message or a set of messages up to and including a specific
- message.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <field name = "delivery tag" domain = "delivery tag" />
-
- <field name = "multiple" type = "bit">
- acknowledge multiple messages
- <doc>
- If set to 1, the delivery tag is treated as "up to and including",
- so that the client can acknowledge multiple messages with a single
- method. If set to zero, the delivery tag refers to a single
- message. If the multiple field is 1, and the delivery tag is zero,
- tells the server to acknowledge all outstanding mesages.
- </doc>
- <doc name = "rule" test = "amq_basic_20">
- The server MUST validate that a non-zero delivery-tag refers to an
- delivered message, and raise a channel exception if this is not the
- case.
- </doc>
- </field>
-</method>
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "reject" index = "90">
- reject an incoming message
- <doc>
- This method allows a client to reject a message. It can be used to
- interrupt and cancel large incoming messages, or return untreatable
- messages to their original queue.
- </doc>
- <doc name = "rule" test = "amq_basic_21">
- The server SHOULD be capable of accepting and process the Reject
- method while sending message content with a Deliver or Get-Ok
- method. I.e. the server should read and process incoming methods
- while sending output frames. To cancel a partially-send content,
- the server sends a content body frame of size 1 (i.e. with no data
- except the frame-end octet).
- </doc>
- <doc name = "rule" test = "amq_basic_22">
- The server SHOULD interpret this method as meaning that the client
- is unable to process the message at this time.
- </doc>
- <doc name = "rule">
- A client MUST NOT use this method as a means of selecting messages
- to process. A rejected message MAY be discarded or dead-lettered,
- not necessarily passed to another client.
- </doc>
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery tag" domain = "delivery tag" />
-
- <field name = "requeue" type = "bit">
- requeue the message
- <doc>
- If this field is zero, the message will be discarded. If this bit
- is 1, the server will attempt to requeue the message.
- </doc>
- <doc name = "rule" test = "amq_basic_23">
- The server MUST NOT deliver the message to the same client within
- the context of the current channel. The recommended strategy is
- to attempt to deliver the message to an alternative consumer, and
- if that is not possible, to move the message to a dead-letter
- queue. The server MAY use more sophisticated tracking to hold
- the message on the queue and redeliver it to the same client at
- a later stage.
- </doc>
- </field>
-</method>
-
-<method name = "recover" index = "100">
- redeliver unacknowledged messages
- <doc>
- This method asks the broker to redeliver all unacknowledged messages on a
- specified channel. Zero or more messages may be redelivered. This method
- is only allowed on non-transacted channels.
- </doc>
- <chassis name = "server" implement = "MUST" />
-
- <field name = "requeue" type = "bit">
- requeue the message
- <doc>
- If this field is zero, the message will be redelivered to the original
- recipient. If this bit is 1, the server will attempt to requeue the
- message, potentially then delivering it to an alternative subscriber.
- </doc>
- </field>
- <doc name="rule">
- The server MUST set the redelivered flag on all messages that are resent.
- </doc>
- <doc name="rule">
- The server MUST raise a channel exception if this is called on a
- transacted channel.
- </doc>
-</method>
-
-</class>
-
-
- <class name="file" handler="channel" index="70">
- <!--
-======================================================
-== FILE TRANSFER
-======================================================
--->
- work with file content
-<doc>
- The file class provides methods that support reliable file transfer.
- File messages have a specific set of properties that are required for
- interoperability with file transfer applications. File messages and
- acknowledgements are subject to channel transactions. Note that the
- file class does not provide message browsing methods; these are not
- compatible with the staging model. Applications that need browsable
- file transfer should use Basic content and the Basic class.
-</doc>
-
-<doc name = "grammar">
- file = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:OPEN S:OPEN-OK C:STAGE content
- / S:OPEN C:OPEN-OK S:STAGE content
- / C:PUBLISH
- / S:DELIVER
- / S:RETURN
- / C:ACK
- / C:REJECT
-</doc>
-
-<chassis name = "server" implement = "MAY" />
-<chassis name = "client" implement = "MAY" />
-
-<doc name = "rule">
- The server MUST make a best-effort to hold file messages on a
- reliable storage mechanism.
-</doc>
-<doc name = "rule">
- The server MUST NOT discard a file message in case of a queue
- overflow. The server MUST use the Channel.Flow method to slow or stop
- a file message publisher when necessary.
-</doc>
-<doc name = "rule">
- The server MUST implement at least 2 priority levels for file
- messages, where priorities 0-4 and 5-9 are treated as two distinct
- levels. The server MAY implement up to 10 priority levels.
-</doc>
-<doc name = "rule">
- The server MUST support both automatic and explicit acknowledgements
- on file content.
-</doc>
-
-<!-- These are the properties for a File content -->
-
-<field name = "content type" type = "shortstr">
- MIME content type
-</field>
-<field name = "content encoding" type = "shortstr">
- MIME content encoding
-</field>
-<field name = "headers" type = "table">
- Message header field table
-</field>
-<field name = "priority" type = "octet">
- The message priority, 0 to 9
-</field>
-<field name = "reply to" type = "shortstr">
- The destination to reply to
-</field>
-<field name = "message id" type = "shortstr">
- The application message identifier
-</field>
-<field name = "filename" type = "shortstr">
- The message filename
-</field>
-<field name = "timestamp" type = "timestamp">
- The message timestamp
-</field>
-<field name = "cluster id" type = "shortstr">
- Intra-cluster routing identifier
-</field>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "qos" synchronous = "1" index = "10">
- specify quality of service
- <doc>
- This method requests a specific quality of service. The QoS can
- be specified for the current channel or for all channels on the
- connection. The particular properties and semantics of a qos method
- always depend on the content class semantics. Though the qos method
- could in principle apply to both peers, it is currently meaningful
- only for the server.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "qos-ok" />
-
- <field name = "prefetch size" type = "long">
- prefetch window in octets
- <doc>
- The client can request that messages be sent in advance so that
- when the client finishes processing a message, the following
- message is already held locally, rather than needing to be sent
- down the channel. Prefetching gives a performance improvement.
- This field specifies the prefetch window size in octets. May be
- set to zero, meaning "no specific limit". Note that other
- prefetch limits may still apply. The prefetch-size is ignored
- if the no-ack option is set.
- </doc>
- </field>
-
- <field name = "prefetch count" type = "short">
- prefetch window in messages
- <doc>
- Specifies a prefetch window in terms of whole messages. This
- is compatible with some file API implementations. This field
- may be used in combination with the prefetch-size field; a
- message will only be sent in advance if both prefetch windows
- (and those at the channel and connection level) allow it.
- The prefetch-count is ignored if the no-ack option is set.
- </doc>
- <doc name = "rule">
- The server MAY send less data in advance than allowed by the
- client's specified prefetch windows but it MUST NOT send more.
- </doc>
- </field>
-
- <field name = "global" type = "bit">
- apply to entire connection
- <doc>
- By default the QoS settings apply to the current channel only. If
- this field is set, they are applied to the entire connection.
- </doc>
- </field>
-</method>
-
-<method name = "qos-ok" synchronous = "1" index = "11">
- confirm the requested qos
- <doc>
- This method tells the client that the requested QoS levels could
- be handled by the server. The requested QoS applies to all active
- consumers until a new QoS is defined.
- </doc>
- <chassis name = "client" implement = "MUST" />
-</method>
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "consume" synchronous = "1" index = "20">
- start a queue consumer
- <doc>
- This method asks the server to start a "consumer", which is a
- transient request for messages from a specific queue. Consumers
- last as long as the channel they were created on, or until the
- client cancels them.
- </doc>
- <doc name = "rule">
- The server SHOULD support at least 16 consumers per queue, unless
- the queue was declared as private, and ideally, impose no limit
- except as defined by available resources.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access ticket">
- <doc name = "rule">
- The client MUST provide a valid access ticket giving "read" access
- rights to the realm for the queue.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name
- is null, refers to the current queue for the channel, which is the
- last declared queue.
- </doc>
- <doc name = "rule">
- If the client did not previously declare a queue, and the queue name
- in this method is empty, the server MUST raise a connection exception
- with reply code 530 (not allowed).
- </doc>
- </field>
-
- <field name = "consumer tag" domain = "consumer tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is
- local to a connection, so two clients can use the same consumer
- tags. If this field is empty the server will generate a unique
- tag.
- </doc>
- <doc name = "rule" test = "todo">
- The tag MUST NOT refer to an existing consumer. If the client
- attempts to create two consumers with the same non-empty tag
- the server MUST raise a connection exception with reply code
- 530 (not allowed).
- </doc>
- </field>
-
- <field name = "no local" domain = "no local" />
-
- <field name = "no ack" domain = "no ack" />
-
- <field name = "exclusive" type = "bit">
- request exclusive access
- <doc>
- Request exclusive consumer access, meaning only this consumer can
- access the queue.
- </doc>
- <doc name = "rule" test = "amq_file_00">
- If the server cannot grant exclusive access to the queue when asked,
- - because there are other consumers active - it MUST raise a channel
- exception with return code 405 (resource locked).
- </doc>
- </field>
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-</method>
-
-<method name = "consume-ok" synchronous = "1" index = "21">
- confirm a new consumer
- <doc>
- This method provides the client with a consumer tag which it MUST
- use in methods that work with the consumer.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag">
- <doc>
- Holds the consumer tag specified by the client or provided by
- the server.
- </doc>
- </field>
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "cancel" synchronous = "1" index = "30">
- end a queue consumer
- <doc>
- This method cancels a consumer. This does not affect already
- delivered messages, but it does mean the server will not send any
- more messages for that consumer.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "cancel-ok" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-</method>
-
-<method name = "cancel-ok" synchronous = "1" index = "31">
- confirm a cancelled consumer
- <doc>
- This method confirms that the cancellation was completed.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "open" synchronous = "1" index = "40">
- request to start staging
- <doc>
- This method requests permission to start staging a message. Staging
- means sending the message into a temporary area at the recipient end
- and then delivering the message by referring to this temporary area.
- Staging is how the protocol handles partial file transfers - if a
- message is partially staged and the connection breaks, the next time
- the sender starts to stage it, it can restart from where it left off.
- </doc>
- <response name = "open-ok" />
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <field name = "identifier" type = "shortstr">
- staging identifier
- <doc>
- This is the staging identifier. This is an arbitrary string chosen
- by the sender. For staging to work correctly the sender must use
- the same staging identifier when staging the same message a second
- time after recovery from a failure. A good choice for the staging
- identifier would be the SHA1 hash of the message properties data
- (including the original filename, revised time, etc.).
- </doc>
- </field>
-
- <field name = "content size" type = "longlong">
- message content size
- <doc>
- The size of the content in octets. The recipient may use this
- information to allocate or check available space in advance, to
- avoid "disk full" errors during staging of very large messages.
- </doc>
- <doc name = "rule">
- The sender MUST accurately fill the content-size field.
- Zero-length content is permitted.
- </doc>
- </field>
-</method>
-
-<method name = "open-ok" synchronous = "1" index = "41">
- confirm staging ready
- <doc>
- This method confirms that the recipient is ready to accept staged
- data. If the message was already partially-staged at a previous
- time the recipient will report the number of octets already staged.
- </doc>
- <response name = "stage" />
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <field name = "staged size" type = "longlong">
- already staged amount
- <doc>
- The amount of previously-staged content in octets. For a new
- message this will be zero.
- </doc>
- <doc name = "rule">
- The sender MUST start sending data from this octet offset in the
- message, counting from zero.
- </doc>
- <doc name = "rule">
- The recipient MAY decide how long to hold partially-staged content
- and MAY implement staging by always discarding partially-staged
- content. However if it uses the file content type it MUST support
- the staging methods.
- </doc>
- </field>
-</method>
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "stage" content = "1" index = "50">
- stage message content
- <doc>
- This method stages the message, sending the message content to the
- recipient from the octet offset specified in the Open-Ok method.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "publish" index = "60">
- publish a message
- <doc>
- This method publishes a staged file message to a specific exchange.
- The file message will be routed to queues as defined by the exchange
- configuration and distributed to any active consumers when the
- transaction, if any, is committed.
- </doc>
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access ticket">
- <doc name = "rule">
- The client MUST provide a valid access ticket giving "write"
- access rights to the access realm for the exchange.
- </doc>
- </field>
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange
- name can be empty, meaning the default exchange. If the exchange
- name is specified, and that exchange does not exist, the server
- will raise a channel exception.
- </doc>
- <doc name = "rule">
- The server MUST accept a blank exchange name to mean the default
- exchange.
- </doc>
- <doc name = "rule">
- If the exchange was declared as an internal exchange, the server
- MUST respond with a reply code 403 (access refused) and raise a
- channel exception.
- </doc>
- <doc name = "rule">
- The exchange MAY refuse file content in which case it MUST respond
- with a reply code 540 (not implemented) and raise a channel
- exception.
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key for the message. The routing key is
- used for routing messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" type = "bit">
- indicate mandatory routing
- <doc>
- This flag tells the server how to react if the message cannot be
- routed to a queue. If this flag is set, the server will return an
- unroutable message with a Return method. If this flag is zero, the
- server silently drops the message.
- </doc>
- <doc name = "rule" test = "amq_file_00">
- The server SHOULD implement the mandatory flag.
- </doc>
- </field>
-
- <field name = "immediate" type = "bit">
- request immediate delivery
- <doc>
- This flag tells the server how to react if the message cannot be
- routed to a queue consumer immediately. If this flag is set, the
- server will return an undeliverable message with a Return method.
- If this flag is zero, the server will queue the message, but with
- no guarantee that it will ever be consumed.
- </doc>
- <doc name = "rule" test = "amq_file_00">
- The server SHOULD implement the immediate flag.
- </doc>
- </field>
-
- <field name = "identifier" type = "shortstr">
- staging identifier
- <doc>
- This is the staging identifier of the message to publish. The
- message must have been staged. Note that a client can send the
- Publish method asynchronously without waiting for staging to
- finish.
- </doc>
- </field>
-</method>
-
-<method name = "return" content = "1" index = "70">
- return a failed message
- <doc>
- This method returns an undeliverable message that was published
- with the "immediate" flag set, or an unroutable message published
- with the "mandatory" flag set. The reply code and text provide
- information about the reason that the message was undeliverable.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply code" domain = "reply code" />
- <field name = "reply text" domain = "reply text" />
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange that the message was
- originally published to.
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key name specified when the message was
- published.
- </doc>
- </field>
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "deliver" index = "80">
- notify the client of a consumer message
- <doc>
- This method delivers a staged file message to the client, via a
- consumer. In the asynchronous message delivery model, the client
- starts a consumer using the Consume method, then the server
- responds with Deliver methods as and when messages arrive for
- that consumer.
- </doc>
- <doc name = "rule">
- The server SHOULD track the number of times a message has been
- delivered to clients and when a message is redelivered a certain
- number of times - e.g. 5 times - without being acknowledged, the
- server SHOULD consider the message to be unprocessable (possibly
- causing client applications to abort), and move the message to a
- dead letter queue.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-
- <field name = "delivery tag" domain = "delivery tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange that the message was originally
- published to.
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key name specified when the message was
- published.
- </doc>
- </field>
-
- <field name = "identifier" type = "shortstr">
- staging identifier
- <doc>
- This is the staging identifier of the message to deliver. The
- message must have been staged. Note that a server can send the
- Deliver method asynchronously without waiting for staging to
- finish.
- </doc>
- </field>
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "ack" index = "90">
- acknowledge one or more messages
- <doc>
- This method acknowledges one or more messages delivered via the
- Deliver method. The client can ask to confirm a single message or
- a set of messages up to and including a specific message.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <field name = "delivery tag" domain = "delivery tag" />
-
- <field name = "multiple" type = "bit">
- acknowledge multiple messages
- <doc>
- If set to 1, the delivery tag is treated as "up to and including",
- so that the client can acknowledge multiple messages with a single
- method. If set to zero, the delivery tag refers to a single
- message. If the multiple field is 1, and the delivery tag is zero,
- tells the server to acknowledge all outstanding mesages.
- </doc>
- <doc name = "rule">
- The server MUST validate that a non-zero delivery-tag refers to an
- delivered message, and raise a channel exception if this is not the
- case.
- </doc>
- </field>
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "reject" index = "100">
- reject an incoming message
- <doc>
- This method allows a client to reject a message. It can be used to
- return untreatable messages to their original queue. Note that file
- content is staged before delivery, so the client will not use this
- method to interrupt delivery of a large message.
- </doc>
- <doc name = "rule">
- The server SHOULD interpret this method as meaning that the client
- is unable to process the message at this time.
- </doc>
- <doc name = "rule">
- A client MUST NOT use this method as a means of selecting messages
- to process. A rejected message MAY be discarded or dead-lettered,
- not necessarily passed to another client.
- </doc>
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery tag" domain = "delivery tag" />
-
- <field name = "requeue" type = "bit">
- requeue the message
- <doc>
- If this field is zero, the message will be discarded. If this bit
- is 1, the server will attempt to requeue the message.
- </doc>
- <doc name = "rule">
- The server MUST NOT deliver the message to the same client within
- the context of the current channel. The recommended strategy is
- to attempt to deliver the message to an alternative consumer, and
- if that is not possible, to move the message to a dead-letter
- queue. The server MAY use more sophisticated tracking to hold
- the message on the queue and redeliver it to the same client at
- a later stage.
- </doc>
- </field>
-</method>
-
-</class>
-
- <class name="stream" handler="channel" index="80">
- <!--
-======================================================
-== STREAMING
-======================================================
--->
- work with streaming content
-
-<doc>
- The stream class provides methods that support multimedia streaming.
- The stream class uses the following semantics: one message is one
- packet of data; delivery is unacknowleged and unreliable; the consumer
- can specify quality of service parameters that the server can try to
- adhere to; lower-priority messages may be discarded in favour of high
- priority messages.
-</doc>
-
-<doc name = "grammar">
- stream = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:PUBLISH content
- / S:RETURN
- / S:DELIVER content
-</doc>
-
-<chassis name = "server" implement = "MAY" />
-<chassis name = "client" implement = "MAY" />
-
-<doc name = "rule">
- The server SHOULD discard stream messages on a priority basis if
- the queue size exceeds some configured limit.
-</doc>
-<doc name = "rule">
- The server MUST implement at least 2 priority levels for stream
- messages, where priorities 0-4 and 5-9 are treated as two distinct
- levels. The server MAY implement up to 10 priority levels.
-</doc>
-<doc name = "rule">
- The server MUST implement automatic acknowledgements on stream
- content. That is, as soon as a message is delivered to a client
- via a Deliver method, the server must remove it from the queue.
-</doc>
-
-
-<!-- These are the properties for a Stream content -->
-
-<field name = "content type" type = "shortstr">
- MIME content type
-</field>
-<field name = "content encoding" type = "shortstr">
- MIME content encoding
-</field>
-<field name = "headers" type = "table">
- Message header field table
-</field>
-<field name = "priority" type = "octet">
- The message priority, 0 to 9
-</field>
-<field name = "timestamp" type = "timestamp">
- The message timestamp
-</field>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "qos" synchronous = "1" index = "10">
- specify quality of service
- <doc>
- This method requests a specific quality of service. The QoS can
- be specified for the current channel or for all channels on the
- connection. The particular properties and semantics of a qos method
- always depend on the content class semantics. Though the qos method
- could in principle apply to both peers, it is currently meaningful
- only for the server.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "qos-ok" />
-
- <field name = "prefetch size" type = "long">
- prefetch window in octets
- <doc>
- The client can request that messages be sent in advance so that
- when the client finishes processing a message, the following
- message is already held locally, rather than needing to be sent
- down the channel. Prefetching gives a performance improvement.
- This field specifies the prefetch window size in octets. May be
- set to zero, meaning "no specific limit". Note that other
- prefetch limits may still apply.
- </doc>
- </field>
-
- <field name = "prefetch count" type = "short">
- prefetch window in messages
- <doc>
- Specifies a prefetch window in terms of whole messages. This
- field may be used in combination with the prefetch-size field;
- a message will only be sent in advance if both prefetch windows
- (and those at the channel and connection level) allow it.
- </doc>
- </field>
-
- <field name = "consume rate" type = "long">
- transfer rate in octets/second
- <doc>
- Specifies a desired transfer rate in octets per second. This is
- usually determined by the application that uses the streaming
- data. A value of zero means "no limit", i.e. as rapidly as
- possible.
- </doc>
- <doc name = "rule">
- The server MAY ignore the prefetch values and consume rates,
- depending on the type of stream and the ability of the server
- to queue and/or reply it. The server MAY drop low-priority
- messages in favour of high-priority messages.
- </doc>
- </field>
-
- <field name = "global" type = "bit">
- apply to entire connection
- <doc>
- By default the QoS settings apply to the current channel only. If
- this field is set, they are applied to the entire connection.
- </doc>
- </field>
-</method>
-
-<method name = "qos-ok" synchronous = "1" index = "11">
- confirm the requested qos
- <doc>
- This method tells the client that the requested QoS levels could
- be handled by the server. The requested QoS applies to all active
- consumers until a new QoS is defined.
- </doc>
- <chassis name = "client" implement = "MUST" />
-</method>
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "consume" synchronous = "1" index = "20">
- start a queue consumer
- <doc>
- This method asks the server to start a "consumer", which is a
- transient request for messages from a specific queue. Consumers
- last as long as the channel they were created on, or until the
- client cancels them.
- </doc>
- <doc name = "rule">
- The server SHOULD support at least 16 consumers per queue, unless
- the queue was declared as private, and ideally, impose no limit
- except as defined by available resources.
- </doc>
- <doc name = "rule">
- Streaming applications SHOULD use different channels to select
- different streaming resolutions. AMQP makes no provision for
- filtering and/or transforming streams except on the basis of
- priority-based selective delivery of individual messages.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access ticket">
- <doc name = "rule">
- The client MUST provide a valid access ticket giving "read" access
- rights to the realm for the queue.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name
- is null, refers to the current queue for the channel, which is the
- last declared queue.
- </doc>
- <doc name = "rule">
- If the client did not previously declare a queue, and the queue name
- in this method is empty, the server MUST raise a connection exception
- with reply code 530 (not allowed).
- </doc>
- </field>
-
- <field name = "consumer tag" domain = "consumer tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is
- local to a connection, so two clients can use the same consumer
- tags. If this field is empty the server will generate a unique
- tag.
- </doc>
- <doc name = "rule" test = "todo">
- The tag MUST NOT refer to an existing consumer. If the client
- attempts to create two consumers with the same non-empty tag
- the server MUST raise a connection exception with reply code
- 530 (not allowed).
- </doc>
- </field>
-
- <field name = "no local" domain = "no local" />
-
- <field name = "exclusive" type = "bit">
- request exclusive access
- <doc>
- Request exclusive consumer access, meaning only this consumer can
- access the queue.
- </doc>
- <doc name = "rule" test = "amq_file_00">
- If the server cannot grant exclusive access to the queue when asked,
- - because there are other consumers active - it MUST raise a channel
- exception with return code 405 (resource locked).
- </doc>
- </field>
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-</method>
-
-
-<method name = "consume-ok" synchronous = "1" index = "21">
- confirm a new consumer
- <doc>
- This method provides the client with a consumer tag which it may
- use in methods that work with the consumer.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag">
- <doc>
- Holds the consumer tag specified by the client or provided by
- the server.
- </doc>
- </field>
-</method>
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "cancel" synchronous = "1" index = "30">
- end a queue consumer
- <doc>
- This method cancels a consumer. Since message delivery is
- asynchronous the client may continue to receive messages for
- a short while after canceling a consumer. It may process or
- discard these as appropriate.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "cancel-ok" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-
- <field name = "nowait" type = "bit">
- do not send a reply method
- <doc>
- If set, the server will not respond to the method. The client should
- not wait for a reply method. If the server could not complete the
- method it will raise a channel or connection exception.
- </doc>
- </field>
-</method>
-
-<method name = "cancel-ok" synchronous = "1" index = "31">
- confirm a cancelled consumer
- <doc>
- This method confirms that the cancellation was completed.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "publish" content = "1" index = "40">
- publish a message
- <doc>
- This method publishes a message to a specific exchange. The message
- will be routed to queues as defined by the exchange configuration
- and distributed to any active consumers as appropriate.
- </doc>
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access ticket">
- <doc name = "rule">
- The client MUST provide a valid access ticket giving "write"
- access rights to the access realm for the exchange.
- </doc>
- </field>
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange
- name can be empty, meaning the default exchange. If the exchange
- name is specified, and that exchange does not exist, the server
- will raise a channel exception.
- </doc>
- <doc name = "rule">
- The server MUST accept a blank exchange name to mean the default
- exchange.
- </doc>
- <doc name = "rule">
- If the exchange was declared as an internal exchange, the server
- MUST respond with a reply code 403 (access refused) and raise a
- channel exception.
- </doc>
- <doc name = "rule">
- The exchange MAY refuse stream content in which case it MUST
- respond with a reply code 540 (not implemented) and raise a
- channel exception.
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key for the message. The routing key is
- used for routing messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" type = "bit">
- indicate mandatory routing
- <doc>
- This flag tells the server how to react if the message cannot be
- routed to a queue. If this flag is set, the server will return an
- unroutable message with a Return method. If this flag is zero, the
- server silently drops the message.
- </doc>
- <doc name = "rule" test = "amq_stream_00">
- The server SHOULD implement the mandatory flag.
- </doc>
- </field>
-
- <field name = "immediate" type = "bit">
- request immediate delivery
- <doc>
- This flag tells the server how to react if the message cannot be
- routed to a queue consumer immediately. If this flag is set, the
- server will return an undeliverable message with a Return method.
- If this flag is zero, the server will queue the message, but with
- no guarantee that it will ever be consumed.
- </doc>
- <doc name = "rule" test = "amq_stream_00">
- The server SHOULD implement the immediate flag.
- </doc>
- </field>
-</method>
-
-<method name = "return" content = "1" index = "50">
- return a failed message
- <doc>
- This method returns an undeliverable message that was published
- with the "immediate" flag set, or an unroutable message published
- with the "mandatory" flag set. The reply code and text provide
- information about the reason that the message was undeliverable.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply code" domain = "reply code" />
- <field name = "reply text" domain = "reply text" />
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange that the message was
- originally published to.
- </doc>
- </field>
-
- <field name = "routing key" type = "shortstr">
- Message routing key
- <doc>
- Specifies the routing key name specified when the message was
- published.
- </doc>
- </field>
-</method>
-
-
-<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
-<method name = "deliver" content = "1" index = "60">
- notify the client of a consumer message
- <doc>
- This method delivers a message to the client, via a consumer. In
- the asynchronous message delivery model, the client starts a
- consumer using the Consume method, then the server responds with
- Deliver methods as and when messages arrive for that consumer.
- </doc>
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer tag" domain = "consumer tag" />
-
- <field name = "delivery tag" domain = "delivery tag" />
-
- <field name = "exchange" domain = "exchange name">
- <doc>
- Specifies the name of the exchange that the message was originally
- published to.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue name">
- <doc>
- Specifies the name of the queue that the message came from. Note
- that a single channel can start many consumers on different
- queues.
- </doc>
- <assert check = "notnull" />
- </field>
-</method>
- </class>
-
- <class name="tx" handler="channel" index="90">
- <!--
-======================================================
-== TRANSACTIONS
-======================================================
--->
- work with standard transactions
-
-<doc>
- Standard transactions provide so-called "1.5 phase commit". We can
- ensure that work is never lost, but there is a chance of confirmations
- being lost, so that messages may be resent. Applications that use
- standard transactions must be able to detect and ignore duplicate
- messages.
-</doc>
- <rule implement="SHOULD">
- An client using standard transactions SHOULD be able to track all
- messages received within a reasonable period, and thus detect and
- reject duplicates of the same message. It SHOULD NOT pass these to
- the application layer.
-</rule>
- <doc name="grammar">
- tx = C:SELECT S:SELECT-OK
- / C:COMMIT S:COMMIT-OK
- / C:ROLLBACK S:ROLLBACK-OK
-</doc>
- <chassis name="server" implement="SHOULD"/>
- <chassis name="client" implement="MAY"/>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="select" synchronous="1" index="10">
-select standard transaction mode
- <doc>
- This method sets the channel to use standard transactions. The
- client must use this method at least once on a channel before
- using the Commit or Rollback methods.
- </doc>
- <chassis name="server" implement="MUST"/>
- <response name="select-ok"/>
- </method>
- <method name="select-ok" synchronous="1" index="11">
-confirm transaction mode
- <doc>
- This method confirms to the client that the channel was successfully
- set to use standard transactions.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="commit" synchronous="1" index="20">
-commit the current transaction
- <doc>
- This method commits all messages published and acknowledged in
- the current transaction. A new transaction starts immediately
- after a commit.
- </doc>
- <chassis name="server" implement="MUST"/>
- <response name="commit-ok"/>
- </method>
- <method name="commit-ok" synchronous="1" index="21">
-confirm a successful commit
- <doc>
- This method confirms to the client that the commit succeeded.
- Note that if a commit fails, the server raises a channel exception.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="rollback" synchronous="1" index="30">
-abandon the current transaction
- <doc>
- This method abandons all messages published and acknowledged in
- the current transaction. A new transaction starts immediately
- after a rollback.
- </doc>
- <chassis name="server" implement="MUST"/>
- <response name="rollback-ok"/>
- </method>
- <method name="rollback-ok" synchronous="1" index="31">
-confirm a successful rollback
- <doc>
- This method confirms to the client that the rollback succeeded.
- Note that if an rollback fails, the server raises a channel exception.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- </class>
- <class name="dtx" handler="channel" index="100">
- <!--
-======================================================
-== DISTRIBUTED TRANSACTIONS
-======================================================
--->
- work with distributed transactions
-
-<doc>
- Distributed transactions provide so-called "2-phase commit". The
- AMQP distributed transaction model supports the X-Open XA
- architecture and other distributed transaction implementations.
- The Dtx class assumes that the server has a private communications
- channel (not AMQP) to a distributed transaction coordinator.
-</doc>
- <doc name="grammar">
- dtx = C:SELECT S:SELECT-OK
- C:START S:START-OK
-</doc>
- <chassis name="server" implement="MAY"/>
- <chassis name="client" implement="MAY"/>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="select" synchronous="1" index="10">
-select standard transaction mode
- <doc>
- This method sets the channel to use distributed transactions. The
- client must use this method at least once on a channel before
- using the Start method.
- </doc>
- <chassis name="server" implement="MUST"/>
- <response name="select-ok"/>
- </method>
- <method name="select-ok" synchronous="1" index="11">
-confirm transaction mode
- <doc>
- This method confirms to the client that the channel was successfully
- set to use distributed transactions.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="start" synchronous="1" index="20">
- start a new distributed transaction
- <doc>
- This method starts a new distributed transaction. This must be
- the first method on a new channel that uses the distributed
- transaction mode, before any methods that publish or consume
- messages.
- </doc>
- <chassis name="server" implement="MAY"/>
- <response name="start-ok"/>
- <field name="dtx identifier" type="shortstr">
- transaction identifier
- <doc>
- The distributed transaction key. This identifies the transaction
- so that the AMQP server can coordinate with the distributed
- transaction coordinator.
- </doc>
- <assert check="notnull"/>
- </field>
- </method>
- <method name="start-ok" synchronous="1" index="21">
- confirm the start of a new distributed transaction
- <doc>
- This method confirms to the client that the transaction started.
- Note that if a start fails, the server raises a channel exception.
- </doc>
- <chassis name="client" implement="MUST"/>
- </method>
- </class>
- <class name="tunnel" handler="tunnel" index="110">
- <!--
-======================================================
-== TUNNEL
-======================================================
--->
- methods for protocol tunneling.
-
-<doc>
- The tunnel methods are used to send blocks of binary data - which
- can be serialised AMQP methods or other protocol frames - between
- AMQP peers.
-</doc>
- <doc name="grammar">
- tunnel = C:REQUEST
- / S:REQUEST
-</doc>
- <chassis name="server" implement="MAY"/>
- <chassis name="client" implement="MAY"/>
- <field name="headers" type="table">
- Message header field table
-</field>
- <field name="proxy name" type="shortstr">
- The identity of the tunnelling proxy
-</field>
- <field name="data name" type="shortstr">
- The name or type of the message being tunnelled
-</field>
- <field name="durable" type="octet">
- The message durability indicator
-</field>
- <field name="broadcast" type="octet">
- The message broadcast mode
-</field>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="request" content="1" index="10">
- sends a tunnelled method
- <doc>
- This method tunnels a block of binary data, which can be an
- encoded AMQP method or other data. The binary data is sent
- as the content for the Tunnel.Request method.
- </doc>
- <chassis name="server" implement="MUST"/>
- <field name="meta data" type="table">
- meta data for the tunnelled block
- <doc>
- This field table holds arbitrary meta-data that the sender needs
- to pass to the recipient.
- </doc>
- </field>
- </method>
- </class>
- <class name="test" handler="channel" index="120">
- <!--
-======================================================
-== TEST - CHECK FUNCTIONAL CAPABILITIES OF AN IMPLEMENTATION
-======================================================
--->
- test functional primitives of the implementation
-
-<doc>
- The test class provides methods for a peer to test the basic
- operational correctness of another peer. The test methods are
- intended to ensure that all peers respect at least the basic
- elements of the protocol, such as frame and content organisation
- and field types. We assume that a specially-designed peer, a
- "monitor client" would perform such tests.
-</doc>
- <doc name="grammar">
- test = C:INTEGER S:INTEGER-OK
- / S:INTEGER C:INTEGER-OK
- / C:STRING S:STRING-OK
- / S:STRING C:STRING-OK
- / C:TABLE S:TABLE-OK
- / S:TABLE C:TABLE-OK
- / C:CONTENT S:CONTENT-OK
- / S:CONTENT C:CONTENT-OK
-</doc>
- <chassis name="server" implement="MUST"/>
- <chassis name="client" implement="SHOULD"/>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="integer" synchronous="1" index="10">
- test integer handling
- <doc>
- This method tests the peer's capability to correctly marshal integer
- data.
- </doc>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <response name="integer-ok"/>
- <field name="integer 1" type="octet">
- octet test value
- <doc>
- An octet integer test value.
- </doc>
- </field>
- <field name="integer 2" type="short">
- short test value
- <doc>
- A short integer test value.
- </doc>
- </field>
- <field name="integer 3" type="long">
- long test value
- <doc>
- A long integer test value.
- </doc>
- </field>
- <field name="integer 4" type="longlong">
- long-long test value
- <doc>
- A long long integer test value.
- </doc>
- </field>
- <field name="operation" type="octet">
- operation to test
- <doc>
- The client must execute this operation on the provided integer
- test fields and return the result.
- </doc>
- <assert check="enum">
- <value name="add">return sum of test values</value>
- <value name="min">return lowest of test values</value>
- <value name="max">return highest of test values</value>
- </assert>
- </field>
- </method>
- <method name="integer-ok" synchronous="1" index="11">
- report integer test result
- <doc>
- This method reports the result of an Integer method.
- </doc>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <field name="result" type="longlong">
- result value
- <doc>
- The result of the tested operation.
- </doc>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="string" synchronous="1" index="20">
- test string handling
- <doc>
- This method tests the peer's capability to correctly marshal string
- data.
- </doc>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <response name="string-ok"/>
- <field name="string 1" type="shortstr">
- short string test value
- <doc>
- An short string test value.
- </doc>
- </field>
- <field name="string 2" type="longstr">
- long string test value
- <doc>
- A long string test value.
- </doc>
- </field>
- <field name="operation" type="octet">
- operation to test
- <doc>
- The client must execute this operation on the provided string
- test fields and return the result.
- </doc>
- <assert check="enum">
- <value name="add">return concatentation of test strings</value>
- <value name="min">return shortest of test strings</value>
- <value name="max">return longest of test strings</value>
- </assert>
- </field>
- </method>
- <method name="string-ok" synchronous="1" index="21">
- report string test result
- <doc>
- This method reports the result of a String method.
- </doc>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <field name="result" type="longstr">
- result value
- <doc>
- The result of the tested operation.
- </doc>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="table" synchronous="1" index="30">
- test field table handling
- <doc>
- This method tests the peer's capability to correctly marshal field
- table data.
- </doc>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <response name="table-ok"/>
- <field name="table" type="table">
- field table of test values
- <doc>
- A field table of test values.
- </doc>
- </field>
- <field name="integer op" type="octet">
- operation to test on integers
- <doc>
- The client must execute this operation on the provided field
- table integer values and return the result.
- </doc>
- <assert check="enum">
- <value name="add">return sum of numeric field values</value>
- <value name="min">return min of numeric field values</value>
- <value name="max">return max of numeric field values</value>
- </assert>
- </field>
- <field name="string op" type="octet">
- operation to test on strings
- <doc>
- The client must execute this operation on the provided field
- table string values and return the result.
- </doc>
- <assert check="enum">
- <value name="add">return concatenation of string field values</value>
- <value name="min">return shortest of string field values</value>
- <value name="max">return longest of string field values</value>
- </assert>
- </field>
- </method>
- <method name="table-ok" synchronous="1" index="31">
- report table test result
- <doc>
- This method reports the result of a Table method.
- </doc>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <field name="integer result" type="longlong">
- integer result value
- <doc>
- The result of the tested integer operation.
- </doc>
- </field>
- <field name="string result" type="longstr">
- string result value
- <doc>
- The result of the tested string operation.
- </doc>
- </field>
- </method>
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <method name="content" synchronous="1" content="1" index="40">
- test content handling
- <doc>
- This method tests the peer's capability to correctly marshal content.
- </doc>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <response name="content-ok"/>
- </method>
- <method name="content-ok" synchronous="1" content="1" index="41">
- report content test result
- <doc>
- This method reports the result of a Content method. It contains the
- content checksum and echoes the original content as provided.
- </doc>
- <chassis name="client" implement="MUST"/>
- <chassis name="server" implement="MUST"/>
- <field name="content checksum" type="long">
- content hash
- <doc>
- The 32-bit checksum of the content, calculated by adding the
- content into a 32-bit accumulator.
- </doc>
- </field>
- </method>
- </class>
-</amqp>
diff --git a/gentools/xml-src/amqp-0.9.test.xml b/gentools/xml-src/amqp-0.9.test.xml
deleted file mode 100644
index e12e9c787a..0000000000
--- a/gentools/xml-src/amqp-0.9.test.xml
+++ /dev/null
@@ -1,4282 +0,0 @@
-<?xml version = "1.0"?>
-
-<!--
- EDITORS: (PH) Pieter Hintjens <ph@imatix.com>
- (KvdR) Kim van der Riet <kim.vdriet@redhat.com>
-
- These editors have been assigned by the AMQP working group.
- Please do not edit/commit this file without consulting with
- one of the above editors.
- ========================================================
-
- TODOs
- - see TODO comments in the text
--->
-
-<!--
- Copyright Notice
- ================
- (c) Copyright JPMorgan Chase Bank & Co., Cisco Systems, Inc., Envoy Technologies Inc.,
- iMatix Corporation, IONA\ufffd Technologies, Red Hat, Inc.,
- TWIST Process Innovations, and 29West Inc. 2006. All rights reserved.
-
- License
- =======
- JPMorgan Chase Bank & Co., Cisco Systems, Inc., Envoy Technologies Inc., iMatix
- Corporation, IONA\ufffd Technologies, Red Hat, Inc., TWIST Process Innovations, and
- 29West Inc. (collectively, the "Authors") each hereby grants to you a worldwide,
- perpetual, royalty-free, nontransferable, nonexclusive license to
- (i) copy, display, and implement the Advanced Messaging Queue Protocol
- ("AMQP") Specification and (ii) the Licensed Claims that are held by
- the Authors, all for the purpose of implementing the Advanced Messaging
- Queue Protocol Specification. Your license and any rights under this
- Agreement will terminate immediately without notice from
- any Author if you bring any claim, suit, demand, or action related to
- the Advanced Messaging Queue Protocol Specification against any Author.
- Upon termination, you shall destroy all copies of the Advanced Messaging
- Queue Protocol Specification in your possession or control.
-
- As used hereunder, "Licensed Claims" means those claims of a patent or
- patent application, throughout the world, excluding design patents and
- design registrations, owned or controlled, or that can be sublicensed
- without fee and in compliance with the requirements of this
- Agreement, by an Author or its affiliates now or at any
- future time and which would necessarily be infringed by implementation
- of the Advanced Messaging Queue Protocol Specification. A claim is
- necessarily infringed hereunder only when it is not possible to avoid
- infringing it because there is no plausible non-infringing alternative
- for implementing the required portions of the Advanced Messaging Queue
- Protocol Specification. Notwithstanding the foregoing, Licensed Claims
- shall not include any claims other than as set forth above even if
- contained in the same patent as Licensed Claims; or that read solely
- on any implementations of any portion of the Advanced Messaging Queue
- Protocol Specification that are not required by the Advanced Messaging
- Queue Protocol Specification, or that, if licensed, would require a
- payment of royalties by the licensor to unaffiliated third parties.
- Moreover, Licensed Claims shall not include (i) any enabling technologies
- that may be necessary to make or use any Licensed Product but are not
- themselves expressly set forth in the Advanced Messaging Queue Protocol
- Specification (e.g., semiconductor manufacturing technology, compiler
- technology, object oriented technology, networking technology, operating
- system technology, and the like); or (ii) the implementation of other
- published standards developed elsewhere and merely referred to in the
- body of the Advanced Messaging Queue Protocol Specification, or
- (iii) any Licensed Product and any combinations thereof the purpose or
- function of which is not required for compliance with the Advanced
- Messaging Queue Protocol Specification. For purposes of this definition,
- the Advanced Messaging Queue Protocol Specification shall be deemed to
- include both architectural and interconnection requirements essential
- for interoperability and may also include supporting source code artifacts
- where such architectural, interconnection requirements and source code
- artifacts are expressly identified as being required or documentation to
- achieve compliance with the Advanced Messaging Queue Protocol Specification.
-
- As used hereunder, "Licensed Products" means only those specific portions
- of products (hardware, software or combinations thereof) that implement
- and are compliant with all relevant portions of the Advanced Messaging
- Queue Protocol Specification.
-
- The following disclaimers, which you hereby also acknowledge as to any
- use you may make of the Advanced Messaging Queue Protocol Specification:
-
- THE ADVANCED MESSAGING QUEUE PROTOCOL SPECIFICATION IS PROVIDED "AS IS,"
- AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
- IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE
- CONTENTS OF THE ADVANCED MESSAGING QUEUE PROTOCOL SPECIFICATION ARE
- SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF THE ADVANCED
- MESSAGING QUEUE PROTOCOL SPECIFICATION WILL NOT INFRINGE ANY THIRD PARTY
- PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
-
- THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
- INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY
- USE, IMPLEMENTATION OR DISTRIBUTION OF THE ADVANCED MESSAGING QUEUE
- PROTOCOL SPECIFICATION.
-
- The name and trademarks of the Authors may NOT be used in any manner,
- including advertising or publicity pertaining to the Advanced Messaging
- Queue Protocol Specification or its contents without specific, written
- prior permission. Title to copyright in the Advanced Messaging Queue
- Protocol Specification will at all times remain with the Authors.
-
- No other rights are granted by implication, estoppel or otherwise.
-
- Upon termination of your license or rights under this Agreement, you
- shall destroy all copies of the Advanced Messaging Queue Protocol
- Specification in your possession or control.
-
- Trademarks
- ==========
- "JPMorgan", "JPMorgan Chase", "Chase", the JPMorgan Chase logo and the
- Octagon Symbol are trademarks of JPMorgan Chase & Co.
-
- IMATIX and the iMatix logo are trademarks of iMatix Corporation sprl.
-
- IONA, IONA Technologies, and the IONA logos are trademarks of IONA
- Technologies PLC and/or its subsidiaries.
-
- LINUX is a trademark of Linus Torvalds. RED HAT and JBOSS are registered
- trademarks of Red Hat, Inc. in the US and other countries.
-
- Java, all Java-based trademarks and OpenOffice.org are trademarks of
- Sun Microsystems, Inc. in the United States, other countries, or both.
-
- Other company, product, or service names may be trademarks or service
- marks of others.
-
- Links to full AMQP specification:
- =================================
- http://www.envoytech.org/spec/amq/
- http://www.iona.com/opensource/amqp/
- http://www.redhat.com/solutions/specifications/amqp/
- http://www.twiststandards.org/tiki-index.php?page=AMQ
- http://www.imatix.com/amqp
--->
-
-<!--
- <!DOCTYPE amqp SYSTEM "amqp.dtd">
--->
-
-<!-- XML Notes
-
- We use entities to indicate repetition; attributes to indicate properties.
-
- We use the 'name' attribute as an identifier, usually within the context
- of the surrounding entities.
-
- We use spaces to seperate words in names, so that we can print names in
- their natural form depending on the context - underlines for source code,
- hyphens for written text, etc.
-
- We do not enforce any particular validation mechanism but we support all
- mechanisms. The protocol definition conforms to a formal grammar that is
- published seperately in several technologies.
-
- -->
-
-<amqp major = "0" minor = "9" port = "5672" comment = "AMQ Protocol">
- <!--
- ======================================================
- == CONSTANTS
- ======================================================
- -->
- <!-- Frame types -->
- <constant name = "frame-method" value = "1" />
- <constant name = "frame-header" value = "2" />
- <constant name = "frame-body" value = "3" />
- <constant name = "frame-oob-method" value = "4" />
- <constant name = "frame-oob-header" value = "5" />
- <constant name = "frame-oob-body" value = "6" />
- <constant name = "frame-trace" value = "7" />
- <constant name = "frame-heartbeat" value = "8" />
-
- <!-- Protocol constants -->
- <constant name = "frame-min-size" value = "4096" />
- <constant name = "frame-end" value = "206" />
-
- <!-- Reply codes -->
- <constant name = "reply-success" value = "200">
- <doc>
- Indicates that the method completed successfully. This reply code is
- reserved for future use - the current protocol design does not use positive
- confirmation and reply codes are sent only in case of an error.
- </doc>
- </constant>
-
- <constant name = "not-delivered" value = "310" class = "soft-error">
- <doc>
- The client asked for a specific message that is no longer available.
- The message was delivered to another client, or was purged from the queue
- for some other reason.
- </doc>
- </constant>
-
- <constant name = "content-too-large" value = "311" class = "soft-error">
- <doc>
- The client attempted to transfer content larger than the server could accept
- at the present time. The client may retry at a later time.
- </doc>
- </constant>
-
- <constant name = "connection-forced" value = "320" class = "hard-error">
- <doc>
- An operator intervened to close the connection for some reason. The client
- may retry at some later date.
- </doc>
- </constant>
-
- <constant name = "invalid-path" value = "402" class = "hard-error">
- <doc>
- The client tried to work with an unknown virtual host.
- </doc>
- </constant>
-
- <constant name = "access-refused" value = "403" class = "soft-error">
- <doc>
- The client attempted to work with a server entity to which it has no
- access due to security settings.
- </doc>
- </constant>
-
- <constant name = "not-found" value = "404" class = "soft-error">
- <doc>The client attempted to work with a server entity that does not exist.</doc>
- </constant>
-
- <constant name = "resource-locked" value = "405" class = "soft-error">
- <doc>
- The client attempted to work with a server entity to which it has no
- access because another client is working with it.
- </doc>
- </constant>
-
- <constant name = "precondition-failed" value = "406" class = "soft-error">
- <doc>
- The client requested a method that was not allowed because some precondition
- failed.
- </doc>
- </constant>
-
- <constant name = "frame-error" value = "501" class = "hard-error">
- <doc>
- The client sent a malformed frame that the server could not decode. This
- strongly implies a programming error in the client.
- </doc>
- </constant>
-
- <constant name = "syntax-error" value = "502" class = "hard-error">
- <doc>
- The client sent a frame that contained illegal values for one or more
- fields. This strongly implies a programming error in the client.
- </doc>
- </constant>
-
- <constant name = "command-invalid" value = "503" class = "hard-error">
- <doc>
- The client sent an invalid sequence of frames, attempting to perform an
- operation that was considered invalid by the server. This usually implies
- a programming error in the client.
- </doc>
- </constant>
-
- <constant name = "channel-error" value = "504" class = "hard-error">
- <doc>
- The client attempted to work with a channel that had not been correctly
- opened. This most likely indicates a fault in the client layer.
- </doc>
- </constant>
-
- <constant name = "resource-error" value = "506" class = "hard-error">
- <doc>
- The server could not complete the method because it lacked sufficient
- resources. This may be due to the client creating too many of some type
- of entity.
- </doc>
- </constant>
-
- <constant name = "not-allowed" value = "530" class = "hard-error">
- <doc>
- The client tried to work with some entity in a manner that is prohibited
- by the server, due to security settings or by some other criteria.
- </doc>
- </constant>
-
- <constant name = "not-implemented" value = "540" class = "hard-error">
- <doc>
- The client tried to use functionality that is not implemented in the
- server.
- </doc>
- </constant>
-
- <constant name = "internal-error" value = "541" class = "hard-error">
- <doc>
- The server could not complete the method because of an internal error.
- The server may require intervention by an operator in order to resume
- normal operations.
- </doc>
- </constant>
-
- <constant name = "test-str2" value = "1.2.3.3"/>
-
- <!--
- ======================================================
- == DOMAIN TYPES
- ======================================================
- -->
-
- <domain name = "access-ticket" type = "short" label = "access ticket granted by server">
- <doc>
- An access ticket granted by the server for a certain set of access rights
- within a specific realm. Access tickets are valid within the channel where
- they were created, and expire when the channel closes.
- </doc>
- <assert check = "ne" value = "0" />
- </domain>
-
- <domain name = "class-id" type = "short" />
-
- <domain name = "consumer-tag" type = "shortstr" label = "consumer tag">
- <doc>
- Identifier for the consumer, valid within the current connection.
- </doc>
- </domain>
-
- <domain name = "delivery-tag" type = "longlong" label = "server-assigned delivery tag">
- <doc>
- The server-assigned and channel-specific delivery tag
- </doc>
- <rule name = "channel-local">
- <doc>
- The delivery tag is valid only within the channel from which the message was
- received. I.e. a client MUST NOT receive a message on one channel and then
- acknowledge it on another.
- </doc>
- </rule>
- <rule name = "non-zero">
- <doc>
- The server MUST NOT use a zero value for delivery tags. Zero is reserved
- for client use, meaning "all messages so far received".
- </doc>
- </rule>
- </domain>
-
- <domain name = "exchange-name" type = "shortstr" label = "exchange name">
- <doc>
- The exchange name is a client-selected string that identifies the exchange for publish
- methods. Exchange names may consist of any mixture of digits, letters, and underscores.
- Exchange names are scoped by the virtual host.
- </doc>
- <assert check = "length" value = "127" />
- </domain>
-
- <domain name = "known-hosts" type = "shortstr" label = "list of known hosts">
- <doc>
- Specifies the list of equivalent or alternative hosts that the server knows about,
- which will normally include the current server itself. Clients can cache this
- information and use it when reconnecting to a server after a failure. This field
- may be empty.
- </doc>
- </domain>
-
- <domain name = "method-id" type = "short" />
-
- <domain name = "no-ack" type = "bit" label = "no acknowledgement needed">
- <doc>
- If this field is set the server does not expect acknowledgments for
- messages. That is, when a message is delivered to the client the server
- automatically and silently acknowledges it on behalf of the client. This
- functionality increases performance but at the cost of reliability.
- Messages can get lost if a client dies before it can deliver them to the
- application.
- </doc>
- </domain>
-
- <domain name = "no-local" type = "bit" label = "do not deliver own messages">
- <doc>
- If the no-local field is set the server will not send messages to the client that
- published them.
- </doc>
- </domain>
-
- <domain name = "path" type = "shortstr">
- <doc>
- Must start with a slash "/" and continue with path names separated by slashes. A path
- name consists of any combination of at least one of [A-Za-z0-9] plus zero or more of
- [.-_+!=:].
- </doc>
-
- <assert check = "notnull" />
- <assert check = "syntax" rule = "path" />
- <assert check = "length" value = "127" />
- </domain>
-
- <domain name = "peer-properties" type = "table">
- <doc>
- This string provides a set of peer properties, used for identification, debugging, and
- general information.
- </doc>
- </domain>
-
- <domain name = "queue-name" type = "shortstr" label = "queue name">
- <doc>
- The queue name identifies the queue within the vhost. Queue names may consist of any
- mixture of digits, letters, and underscores.
- </doc>
- <assert check = "length" value = "127" />
- </domain>
-
- <domain name = "redelivered" type = "bit" label = "message is being redelivered">
- <doc>
- This indicates that the message has been previously delivered to this or
- another client.
- </doc>
- <rule name = "implementation">
- <doc>
- The server SHOULD try to signal redelivered messages when it can. When
- redelivering a message that was not successfully acknowledged, the server
- SHOULD deliver it to the original client if possible.
- </doc>
- <doc type = "scenario">
- Create a shared queue and publish a message to the queue. Consume the
- message using explicit acknowledgements, but do not acknowledge the
- message. Close the connection, reconnect, and consume from the queue
- again. The message should arrive with the redelivered flag set.
- </doc>
- </rule>
- <rule name = "hinting">
- <doc>
- The client MUST NOT rely on the redelivered field but should take it as a
- hint that the message may already have been processed. A fully robust
- client must be able to track duplicate received messages on non-transacted,
- and locally-transacted channels.
- </doc>
- </rule>
- </domain>
-
- <domain name = "reply-code" type = "short" label = "reply code from server">
- <doc>
- The reply code. The AMQ reply codes are defined as constants at the start
- of this formal specification.
- </doc>
- <assert check = "notnull" />
- </domain>
-
- <domain name = "reply-text" type = "shortstr" label = "localised reply text">
- <doc>
- The localised reply text. This text can be logged as an aid to resolving
- issues.
- </doc>
- <assert check = "notnull" />
- </domain>
-
- <!-- Elementary domains -->
- <domain name = "bit" type = "bit" label = "single bit" />
- <domain name = "octet" type = "octet" label = "single octet" />
- <domain name = "short" type = "short" label = "16-bit integer" />
- <domain name = "long" type = "long" label = "32-bit integer" />
- <domain name = "longlong" type = "longlong" label = "64-bit integer" />
- <domain name = "shortstr" type = "shortstr" label = "short string" />
- <domain name = "longstr" type = "longstr" label = "long string" />
- <domain name = "timestamp" type = "timestamp" label = "64-bit timestamp" />
- <domain name = "table" type = "table" label = "field table" />
-
- <!-- == CONNECTION ======================================================= -->
-
- <!-- TODO 0.81 - the 'handler' attribute of methods needs to be reviewed, and if
- no current implementations use it, removed. /PH 2006/07/20
- -->
-
- <class name = "connection" handler = "connection" index = "10" label = "work with socket connections">
- <doc>
- The connection class provides methods for a client to establish a network connection to
- a server, and for both peers to operate the connection thereafter.
- </doc>
-
- <doc type = "grammar">
- connection = open-connection *use-connection close-connection
- open-connection = C:protocol-header
- S:START C:START-OK
- *challenge
- S:TUNE C:TUNE-OK
- C:OPEN S:OPEN-OK | S:REDIRECT
- challenge = S:SECURE C:SECURE-OK
- use-connection = *channel
- close-connection = C:CLOSE S:CLOSE-OK
- / S:CLOSE C:CLOSE-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "start" synchronous = "1" index = "10" label = "start connection negotiation">
- <doc>
- This method starts the connection negotiation process by telling the client the
- protocol version that the server proposes, along with a list of security mechanisms
- which the client can use for authentication.
- </doc>
-
- <rule name = "protocol-name">
- <doc>
- If the server cannot support the protocol specified in the protocol header,
- it MUST close the socket connection without sending any response method.
- </doc>
- <doc type = "scenario">
- The client sends a protocol header containing an invalid protocol name.
- The server must respond by closing the connection.
- </doc>
- </rule>
- <rule name = "server-support">
- <doc>
- The server MUST provide a protocol version that is lower than or equal to
- that requested by the client in the protocol header.
- </doc>
- <doc type = "scenario">
- The client requests a protocol version that is higher than any valid
- implementation, e.g. 9.0. The server must respond with a current
- protocol version, e.g. 1.0.
- </doc>
- </rule>
- <rule name = "client-support">
- <doc>
- If the client cannot handle the protocol version suggested by the server
- it MUST close the socket connection.
- </doc>
- <doc type = "scenario">
- The server sends a protocol version that is lower than any valid
- implementation, e.g. 0.1. The client must respond by closing the
- connection.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
- <response name = "start-ok" />
-
- <field name = "version-major" domain = "octet" label = "protocol major version">
- <doc>
- The version of the protocol, expressed in protocol units of 0.1 public
- versions and properly printed as two digits with a leading zero. I.e. a
- protocol version of "09" represents a public version "0.9". The decimal
- shift allows the correct expression of pre-1.0 protocol releases.
- </doc>
- <doc type = "todo">
- This field should be renamed to "protocol version".
- </doc>
- </field>
-
- <field name = "version-minor" domain = "octet" label = "protocol major version">
- <doc>
- The protocol revision, expressed as an integer from 0 to 9. The use of more
- than ten revisions is discouraged. The public version string is constructed
- from the protocol version and revision as follows: we print the protocol
- version with one decimal position, and we append the protocol revision. A
- version=10 and revision=2 are printed as "1.02".
- </doc>
- <doc type = "todo">
- This field should be renamed to "protocol revision".
- </doc>
- </field>
-
- <field name = "server-properties" domain = "peer-properties" label = "server properties">
- <rule name = "required-fields">
- <doc>
- The properties SHOULD contain at least these fields: "host", specifying the
- server host name or address, "product", giving the name of the server product,
- "version", giving the name of the server version, "platform", giving the name
- of the operating system, "copyright", if appropriate, and "information", giving
- other general information.
- </doc>
- <doc type = "scenario">
- Client connects to server and inspects the server properties. It checks for
- the presence of the required fields.
- </doc>
- </rule>
- </field>
-
- <field name = "mechanisms" domain = "longstr" label = "available security mechanisms">
- <doc>
- A list of the security mechanisms that the server supports, delimited by spaces.
- Currently ASL supports these mechanisms: PLAIN.
- </doc>
- <assert check = "notnull" />
- </field>
-
- <field name = "locales" domain = "longstr" label = "available message locales">
- <doc>
- A list of the message locales that the server supports, delimited by spaces. The
- locale defines the language in which the server will send reply texts.
- </doc>
- <rule name = "required-support">
- <doc>
- The server MUST support at least the en_US locale.
- </doc>
- <doc type = "scenario">
- Client connects to server and inspects the locales field. It checks for
- the presence of the required locale(s).
- </doc>
- </rule>
- <assert check = "notnull" />
- </field>
- </method>
-
- <method name = "start-ok" synchronous = "1" index = "11"
- label = "select security mechanism and locale">
- <doc>
- This method selects a SASL security mechanism. ASL uses SASL (RFC2222) to
- negotiate authentication and encryption.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "client-properties" domain = "peer-properties" label = "client properties">
- <rule name = "required-fields">
- <!-- This rule is not testable from the client side -->
- <doc>
- The properties SHOULD contain at least these fields: "product", giving the name
- of the client product, "version", giving the name of the client version, "platform",
- giving the name of the operating system, "copyright", if appropriate, and
- "information", giving other general information.
- </doc>
- </rule>
- </field>
-
- <field name = "mechanism" domain = "shortstr" label = "selected security mechanism">
- <doc>
- A single security mechanisms selected by the client, which must be one of those
- specified by the server.
- </doc>
- <rule name = "security">
- <doc>
- The client SHOULD authenticate using the highest-level security profile it
- can handle from the list provided by the server.
- </doc>
- </rule>
- <rule name = "validity">
- <doc>
- If the mechanism field does not contain one of the security mechanisms
- proposed by the server in the Start method, the server MUST close the
- connection without sending any further data.
- </doc>
- <doc type = "scenario">
- Client connects to server and sends an invalid security mechanism. The
- server must respond by closing the connection (a socket close, with no
- connection close negotiation).
- </doc>
- </rule>
- <assert check = "notnull" />
- </field>
-
- <field name = "response" domain = "longstr" label = "security response data">
- <doc>
- A block of opaque data passed to the security mechanism. The contents of this
- data are defined by the SASL security mechanism.
- </doc>
- <assert check = "notnull" />
- </field>
-
- <field name = "locale" domain = "shortstr" label = "selected message locale">
- <doc>
- A single message local selected by the client, which must be one of those
- specified by the server.
- </doc>
- <assert check = "notnull" />
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "secure" synchronous = "1" index = "20" label = "security mechanism challenge">
- <doc>
- The SASL protocol works by exchanging challenges and responses until both peers have
- received sufficient information to authenticate each other. This method challenges
- the client to provide more information.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
- <response name = "secure-ok" />
-
- <field name = "challenge" domain = "longstr" label = "security challenge data">
- <doc>
- Challenge information, a block of opaque binary data passed to the security
- mechanism.
- </doc>
- </field>
- </method>
-
- <method name = "secure-ok" synchronous = "1" index = "21" label = "security mechanism response">
- <doc>
- This method attempts to authenticate, passing a block of SASL data for the security
- mechanism at the server side.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "response" domain = "longstr" label = "security response data">
- <doc>
- A block of opaque data passed to the security mechanism. The contents of this
- data are defined by the SASL security mechanism.
- </doc>
- <assert check = "notnull" />
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "tune" synchronous = "1" index = "30"
- label = "propose connection tuning parameters">
- <doc>
- This method proposes a set of connection configuration values to the client. The
- client can accept and/or adjust these.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <response name = "tune-ok" />
-
- <field name = "channel-max" domain = "short" label = "proposed maximum channels">
- <doc>
- The maximum total number of channels that the server allows per connection. Zero
- means that the server does not impose a fixed limit, but the number of allowed
- channels may be limited by available server resources.
- </doc>
- </field>
-
- <field name = "frame-max" domain = "long" label = "proposed maximum frame size">
- <doc>
- The largest frame size that the server proposes for the connection. The client
- can negotiate a lower value. Zero means that the server does not impose any
- specific limit but may reject very large frames if it cannot allocate resources
- for them.
- </doc>
- <rule name = "minimum">
- <doc>
- Until the frame-max has been negotiated, both peers MUST accept frames of up
- to frame-min-size octets large, and the minimum negotiated value for frame-max
- is also frame-min-size.
- </doc>
- <doc type = "scenario">
- Client connects to server and sends a large properties field, creating a frame
- of frame-min-size octets. The server must accept this frame.
- </doc>
- </rule>
- </field>
-
- <field name = "heartbeat" domain = "short" label = "desired heartbeat delay">
- <!-- TODO 0.82 - the heartbeat negotiation mechanism was changed during
- implementation because the model documented here does not actually
- work properly. The best model we found is that the server proposes
- a heartbeat value to the client; the client can reply with zero, meaning
- 'do not use heartbeats (as documented here), or can propose its own
- heartbeat value, which the server should then accept. This is different
- from the model here which is disconnected - e.g. each side requests a
- heartbeat independently. Basically a connection is heartbeated in
- both ways, or not at all, depending on whether both peers support
- heartbeating or not, and the heartbeat value should itself be chosen
- by the client so that remote links can get a higher value. Also, the
- actual heartbeat mechanism needs documentation, and is as follows: so
- long as there is activity on a connection - in or out - both peers
- assume the connection is active. When there is no activity, each peer
- must send heartbeat frames. When no heartbeat frame is received after
- N cycles (where N is at least 2), the connection can be considered to
- have died. /PH 2006/07/19
- -->
- <doc>
- The delay, in seconds, of the connection heartbeat that the server wants.
- Zero means the server does not want a heartbeat.
- </doc>
- </field>
- </method>
-
- <method name = "tune-ok" synchronous = "1" index = "31"
- label = "negotiate connection tuning parameters">
- <doc>
- This method sends the client's connection tuning parameters to the server.
- Certain fields are negotiated, others provide capability information.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "channel-max" domain = "short" label = "negotiated maximum channels">
- <doc>
- The maximum total number of channels that the client will use per connection.
- </doc>
- <rule name = "upper-limit">
- <doc>
- If the client specifies a channel max that is higher than the value provided
- by the server, the server MUST close the connection without attempting a
- negotiated close. The server may report the error in some fashion to assist
- implementors.
- </doc>
- </rule>
- <assert check = "notnull" />
- <assert check = "le" method = "tune" field = "channel-max" />
- </field>
-
- <field name = "frame-max" domain = "long" label = "negotiated maximum frame size">
- <doc>
- The largest frame size that the client and server will use for the connection.
- Zero means that the client does not impose any specific limit but may reject
- very large frames if it cannot allocate resources for them. Note that the
- frame-max limit applies principally to content frames, where large contents can
- be broken into frames of arbitrary size.
- </doc>
- <rule name = "minimum">
- <doc>
- Until the frame-max has been negotiated, both peers MUST accept frames of up
- to frame-min-size octets large, and the minimum negotiated value for frame-max
- is also frame-min-size.
- </doc>
- </rule>
- <rule name = "upper-limit">
- <doc>
- If the client specifies a frame max that is higher than the value provided
- by the server, the server MUST close the connection without attempting a
- negotiated close. The server may report the error in some fashion to assist
- implementors.
- </doc>
- </rule>
- </field>
-
- <field name = "heartbeat" domain = "short" label = "desired heartbeat delay">
- <doc>
- The delay, in seconds, of the connection heartbeat that the client wants. Zero
- means the client does not want a heartbeat.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "open" synchronous = "1" index = "40" label = "open connection to virtual host">
- <doc>
- This method opens a connection to a virtual host, which is a collection of
- resources, and acts to separate multiple application domains within a server.
- The server may apply arbitrary limits per virtual host, such as the number
- of each type of entity that may be used, per connection and/or in total.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "open-ok" />
- <response name = "redirect" />
-
- <field name = "virtual-host" domain = "path" label = "virtual host name">
- <!-- TODO 0.82 - the entire vhost model needs review. This concept was
- prompted by the HTTP vhost concept but does not fit very well into
- AMQP. Currently we use the vhost as a "cluster identifier" which is
- inaccurate usage. /PH 2006/07/19
- -->
- <assert check = "regexp" value = "^[a-zA-Z0-9/-_]+$" />
- <doc>
- The name of the virtual host to work with.
- </doc>
- <rule name = "separation">
- <doc>
- If the server supports multiple virtual hosts, it MUST enforce a full
- separation of exchanges, queues, and all associated entities per virtual
- host. An application, connected to a specific virtual host, MUST NOT be able
- to access resources of another virtual host.
- </doc>
- </rule>
- <rule name = "security">
- <doc>
- The server SHOULD verify that the client has permission to access the
- specified virtual host.
- </doc>
- </rule>
- </field>
-
- <field name = "capabilities" domain = "shortstr" label = "required capabilities">
- <doc>
- The client can specify zero or more capability names, delimited by spaces.
- The server can use this string to how to process the client's connection
- request.
- </doc>
- </field>
-
- <field name = "insist" domain = "bit" label = "insist on connecting to server">
- <doc>
- In a configuration with multiple collaborating servers, the server may respond
- to a Connection.Open method with a Connection.Redirect. The insist option tells
- the server that the client is insisting on a connection to the specified server.
- </doc>
- <rule name = "behaviour">
- <doc>
- When the client uses the insist option, the server MUST NOT respond with a
- Connection.Redirect method. If it cannot accept the client's connection
- request it should respond by closing the connection with a suitable reply
- code.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "open-ok" synchronous = "1" index = "41" label = "signal that connection is ready">
- <doc>
- This method signals to the client that the connection is ready for use.
- </doc>
- <chassis name = "client" implement = "MUST" />
- <field name = "known-hosts" domain = "known-hosts" />
- </method>
-
- <method name = "redirect" synchronous = "1" index = "42" label = "redirects client to other server">
- <doc>
- This method redirects the client to another server, based on the requested virtual
- host and/or capabilities.
- </doc>
- <rule name = "usage">
- <doc>
- When getting the Connection.Redirect method, the client SHOULD reconnect to
- the host specified, and if that host is not present, to any of the hosts
- specified in the known-hosts list.
- </doc>
- </rule>
- <chassis name = "client" implement = "MUST" />
- <field name = "host" domain = "shortstr" label = "server to connect to">
- <doc>
- Specifies the server to connect to. This is an IP address or a DNS name,
- optionally followed by a colon and a port number. If no port number is
- specified, the client should use the default port number for the protocol.
- </doc>
- <assert check = "notnull" />
- </field>
- <field name = "known-hosts" domain = "known-hosts" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "close" synchronous = "1" index = "50" label = "request a connection close">
- <doc>
- This method indicates that the sender wants to close the connection. This may be
- due to internal conditions (e.g. a forced shut-down) or due to an error handling
- a specific method, i.e. an exception. When a close is due to an exception, the
- sender provides the class and method id of the method which caused the exception.
- </doc>
- <!-- TODO: the connection close mechanism needs to be reviewed from the ODF
- documentation and better expressed as rules here. /PH 2006/07/20
- -->
- <rule name = "stability">
- <doc>
- After sending this method any received method except the Close-OK method MUST
- be discarded.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
- <chassis name = "server" implement = "MUST" />
- <response name = "close-ok" />
-
- <field name = "reply-code" domain = "reply-code" />
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "class-id" domain = "class-id" label = "failing method class">
- <doc>
- When the close is provoked by a method exception, this is the class of the
- method.
- </doc>
- </field>
-
- <field name = "method-id" domain = "method-id" label = "failing method ID">
- <doc>
- When the close is provoked by a method exception, this is the ID of the method.
- </doc>
- </field>
- </method>
-
- <method name = "close-ok" synchronous = "1" index = "51" label = "confirm a connection close">
- <doc>
- This method confirms a Connection.Close method and tells the recipient that it is
- safe to release resources for the connection and close the socket.
- </doc>
- <rule name = "reporting">
- <doc>
- A peer that detects a socket closure without having received a Close-Ok
- handshake method SHOULD log the error.
- </doc>
- </rule>
- <chassis name = "client" implement = "MUST" />
- <chassis name = "server" implement = "MUST" />
- </method>
- </class>
-
- <!-- == CHANNEL ========================================================== -->
-
- <class name = "channel" handler = "channel" index = "20" label = "work with channels">
- <doc>
- The channel class provides methods for a client to establish a channel to a
- server and for both peers to operate the channel thereafter.
- </doc>
-
- <doc type = "grammar">
- channel = open-channel *use-channel close-channel
- open-channel = C:OPEN S:OPEN-OK
- use-channel = C:FLOW S:FLOW-OK
- / S:FLOW C:FLOW-OK
- / S:ALERT
- / functional-class
- close-channel = C:CLOSE S:CLOSE-OK
- / S:CLOSE C:CLOSE-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "open" synchronous = "1" index = "10" label = "open a channel for use">
- <doc>
- This method opens a channel to the server.
- </doc>
- <rule name = "state" on-failure = "channel-error">
- <doc>
- The client MUST NOT use this method on an alread-opened channel.
- </doc>
- <doc type = "scenario">
- Client opens a channel and then reopens the same channel.
- </doc>
- </rule>
- <chassis name = "server" implement = "MUST" />
- <response name = "open-ok" />
- <field name = "out of band" domain = "shortstr" label = "out-of-band settings">
- <doc>
- Configures out-of-band transfers on this channel. The syntax and meaning of this
- field will be formally defined at a later date.
- </doc>
- <assert check = "null" />
- </field>
- </method>
-
- <method name = "open-ok" synchronous = "1" index = "11" label = "signal that the channel is ready">
- <doc>
- This method signals to the client that the channel is ready for use.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "flow" synchronous = "1" index = "20" label = "enable/disable flow from peer">
- <doc>
- This method asks the peer to pause or restart the flow of content data. This is a
- simple flow-control mechanism that a peer can use to avoid oveflowing its queues or
- otherwise finding itself receiving more messages than it can process. Note that this
- method is not intended for window control. The peer that receives a disable flow
- method should finish sending the current content frame, if any, then pause.
- </doc>
-
- <rule name = "initial-state">
- <doc>
- When a new channel is opened, it is active (flow is active). Some applications
- assume that channels are inactive until started. To emulate this behaviour a
- client MAY open the channel, then pause it.
- </doc>
- </rule>
-
- <rule name = "bidirectional">
- <doc>
- When sending content frames, a peer SHOULD monitor the channel for incoming
- methods and respond to a Channel.Flow as rapidly as possible.
- </doc>
- </rule>
-
- <rule name = "throttling">
- <doc>
- A peer MAY use the Channel.Flow method to throttle incoming content data for
- internal reasons, for example, when exchanging data over a slower connection.
- </doc>
- </rule>
-
- <rule name = "expected-behaviour">
- <doc>
- The peer that requests a Channel.Flow method MAY disconnect and/or ban a peer
- that does not respect the request. This is to prevent badly-behaved clients
- from overwhelming a broker.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <response name = "flow-ok" />
-
- <field name = "active" domain = "bit" label = "start/stop content frames">
- <doc>
- If 1, the peer starts sending content frames. If 0, the peer stops sending
- content frames.
- </doc>
- </field>
- </method>
-
- <method name = "flow-ok" index = "21" label = "confirm a flow method">
- <doc>
- Confirms to the peer that a flow command was received and processed.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
- <field name = "active" domain = "bit" label = "current flow setting">
- <doc>
- Confirms the setting of the processed flow method: 1 means the peer will start
- sending or continue to send content frames; 0 means it will not.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
- <!-- TODO 0.82 - remove this method entirely
- /PH 2006/07/20
- -->
- <method name = "alert" index = "30" label = "send a non-fatal warning message">
- <doc>
- This method allows the server to send a non-fatal warning to the client. This is
- used for methods that are normally asynchronous and thus do not have confirmations,
- and for which the server may detect errors that need to be reported. Fatal errors
- are handled as channel or connection exceptions; non-fatal errors are sent through
- this method.
- </doc>
- <chassis name = "client" implement = "MUST" />
- <field name = "reply-code" domain = "reply-code" />
- <field name = "reply-text" domain = "reply-text" />
- <field name = "details" domain = "table" label = "detailed information for warning">
- <doc>
- A set of fields that provide more information about the problem. The meaning of
- these fields are defined on a per-reply-code basis (TO BE DEFINED).
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "close" synchronous = "1" index = "40" label = "request a channel close">
- <doc>
- This method indicates that the sender wants to close the channel. This may be due to
- internal conditions (e.g. a forced shut-down) or due to an error handling a specific
- method, i.e. an exception. When a close is due to an exception, the sender provides
- the class and method id of the method which caused the exception.
- </doc>
-
- <!-- TODO: the channel close behaviour needs to be reviewed from the ODF
- documentation and better expressed as rules here. /PH 2006/07/20
- -->
- <rule name = "stability">
- <doc>
- After sending this method any received method except the Close-OK method MUST
- be discarded.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
- <chassis name = "server" implement = "MUST" />
- <response name = "close-ok" />
-
- <field name = "reply-code" domain = "reply-code" />
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "class-id" domain = "class-id" label = "failing method class">
- <doc>
- When the close is provoked by a method exception, this is the class of the
- method.
- </doc>
- </field>
-
- <field name = "method-id" domain = "method-id" label = "failing method ID">
- <doc>
- When the close is provoked by a method exception, this is the ID of the method.
- </doc>
- </field>
- </method>
-
- <method name = "close-ok" synchronous = "1" index = "41" label = "confirm a channel close">
- <doc>
- This method confirms a Channel.Close method and tells the recipient that it is safe
- to release resources for the channel and close the socket.
- </doc>
- <rule name = "reporting">
- <doc>
- A peer that detects a socket closure without having received a Channel.Close-Ok
- handshake method SHOULD log the error.
- </doc>
- </rule>
- <chassis name = "client" implement = "MUST" />
- <chassis name = "server" implement = "MUST" />
- </method>
- </class>
-
- <!-- == ACCESS =========================================================== -->
-
- <!-- TODO 0.82 - this class must be implemented by two teams before we can
- consider it matured.
- -->
-
- <class name = "access" handler = "connection" index = "30" label = "work with access tickets">
- <doc>
- The protocol control access to server resources using access tickets. A
- client must explicitly request access tickets before doing work. An access
- ticket grants a client the right to use a specific set of resources -
- called a "realm" - in specific ways.
- </doc>
-
- <doc type = "grammar">
- access = C:REQUEST S:REQUEST-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "request" synchronous = "1" index = "10" label = "request an access ticket">
- <doc>
- This method requests an access ticket for an access realm. The server
- responds by granting the access ticket. If the client does not have
- access rights to the requested realm this causes a connection exception.
- Access tickets are a per-channel resource.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "request-ok" />
-
- <field name = "realm" domain = "shortstr" label = "name of requested realm">
- <doc>
- Specifies the name of the realm to which the client is requesting access.
- The realm is a configured server-side object that collects a set of
- resources (exchanges, queues, etc.). If the channel has already requested
- an access ticket onto this realm, the previous ticket is destroyed and a
- new ticket is created with the requested access rights, if allowed.
- </doc>
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MUST specify a realm that is known to the server. The server
- makes an identical response for undefined realms as it does for realms
- that are defined but inaccessible to this client.
- </doc>
- <doc type = "scenario">
- Client specifies an undefined realm.
- </doc>
- </rule>
- </field>
-
- <field name = "exclusive" domain = "bit" label = "request exclusive access">
- <doc>
- Request exclusive access to the realm, meaning that this will be the only
- channel that uses the realm's resources.
- </doc>
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MAY NOT request exclusive access to a realm that has active
- access tickets, unless the same channel already had the only access
- ticket onto that realm.
- </doc>
- <doc type = "scenario">
- Client opens two channels and requests exclusive access to the same realm.
- </doc>
- </rule>
- </field>
- <field name = "passive" domain = "bit" label = "request passive access">
- <doc>
- Request message passive access to the specified access realm. Passive
- access lets a client get information about resources in the realm but
- not to make any changes to them.
- </doc>
- </field>
- <field name = "active" domain = "bit" label = "request active access">
- <doc>
- Request message active access to the specified access realm. Active access lets
- a client get create and delete resources in the realm.
- </doc>
- </field>
- <field name = "write" domain = "bit" label = "request write access">
- <doc>
- Request write access to the specified access realm. Write access lets a client
- publish messages to all exchanges in the realm.
- </doc>
- </field>
- <field name = "read" domain = "bit" label = "request read access">
- <doc>
- Request read access to the specified access realm. Read access lets a client
- consume messages from queues in the realm.
- </doc>
- </field>
- </method>
-
- <method name = "request-ok" synchronous = "1" index = "11" label = "grant access to server resources">
- <doc>
- This method provides the client with an access ticket. The access ticket is valid
- within the current channel and for the lifespan of the channel.
- </doc>
- <rule name = "per-channel" on-failure = "not-allowed">
- <doc>
- The client MUST NOT use access tickets except within the same channel as
- originally granted.
- </doc>
- <doc type = "scenario">
- Client opens two channels, requests a ticket on one channel, and then
- tries to use that ticket in a seconc channel.
- </doc>
- </rule>
- <chassis name = "client" implement = "MUST" />
- <field name = "ticket" domain = "access-ticket" />
- </method>
- </class>
-
- <!-- == EXCHANGE ========================================================= -->
-
- <class name = "exchange" handler = "channel" index = "40" label = "work with exchanges">
- <doc>
- Exchanges match and distribute messages across queues. Exchanges can be configured in
- the server or created at runtime.
- </doc>
-
- <doc type = "grammar">
- exchange = C:DECLARE S:DECLARE-OK
- / C:DELETE S:DELETE-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <rule name = "required-types">
- <doc>
- The server MUST implement these standard exchange types: fanout, direct.
- </doc>
- <doc type = "scenario">
- Client attempts to declare an exchange with each of these standard types.
- </doc>
- </rule>
- <rule name = "recommended-types">
- <doc>
- The server SHOULD implement these standard exchange types: topic, headers.
- </doc>
- <doc type = "scenario">
- Client attempts to declare an exchange with each of these standard types.
- </doc>
- </rule>
- <rule name = "required-instances">
- <doc>
- The server MUST, in each virtual host, pre-declare an exchange instance
- for each standard exchange type that it implements, where the name of the
- exchange instance is "amq." followed by the exchange type name.
- </doc>
- <doc type = "scenario">
- Client creates a temporary queue and attempts to bind to each required
- exchange instance (amq.fanout, amq.direct, and amq.topic, amq.headers if
- those types are defined).
- </doc>
- </rule>
- <rule name = "default-exchange">
- <doc>
- The server MUST predeclare a direct exchange to act as the default exchange
- for content Publish methods and for default queue bindings.
- </doc>
- <doc type = "scenario">
- Client checks that the default exchange is active by specifying a queue
- binding with no exchange name, and publishing a message with a suitable
- routing key but without specifying the exchange name, then ensuring that
- the message arrives in the queue correctly.
- </doc>
- </rule>
- <rule name = "default-access">
- <doc>
- The server MUST NOT allow clients to access the default exchange except
- by specifying an empty exchange name in the Queue.Bind and content Publish
- methods.
- </doc>
- </rule>
- <rule name = "extensions">
- <doc>
- The server MAY implement other exchange types as wanted.
- </doc>
- </rule>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "declare" synchronous = "1" index = "10" label = "declare exchange, create if needed">
- <doc>
- This method creates an exchange if it does not already exist, and if the exchange
- exists, verifies that it is of the correct and expected class.
- </doc>
- <rule name = "minimum">
- <doc>
- The server SHOULD support a minimum of 16 exchanges per virtual host and
- ideally, impose no limit except as defined by available resources.
- </doc>
- <doc type = "scenario">
- The client creates as many exchanges as it can until the server reports
- an error; the number of exchanges successfuly created must be at least
- sixteen.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "declare-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>
- When a client defines a new exchange, this belongs to the access realm of the
- ticket used. All further work done with that exchange must be done with an
- access ticket for the same realm.
- </doc>
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MUST provide a valid access ticket giving "active" access to
- the realm in which the exchange exists or will be created, or "passive"
- access if the if-exists flag is set.
- </doc>
- <doc type = "scenario">
- Client creates access ticket with wrong access rights and attempts to use
- in this method.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <rule name = "reserved" on-failure = "access-refused">
- <doc>
- Exchange names starting with "amq." are reserved for predeclared and
- standardised exchanges. The client MUST NOT attempt to create an exchange
- starting with "amq.".
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- <assert check = "regexp" value = "^[a-zA-Z0-9-_.:]+$" />
- </field>
-
- <field name = "type" domain = "shortstr" label = "exchange type">
- <doc>
- Each exchange belongs to one of a set of exchange types implemented by the
- server. The exchange types define the functionality of the exchange - i.e. how
- messages are routed through it. It is not valid or meaningful to attempt to
- change the type of an existing exchange.
- </doc>
- <rule name = "typed" on-failure = "not-allowed">
- <doc>
- Exchanges cannot be redeclared with different types. The client MUST not
- attempt to redeclare an existing exchange with a different type than used
- in the original Exchange.Declare method.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- <rule name = "support" on-failure = "command-invalid">
- <doc>
- The client MUST NOT attempt to create an exchange with a type that the
- server does not support.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- <assert check = "regexp" value = "^[a-zA-Z0-9-_.:]+$" />
- </field>
-
- <field name = "passive" domain = "bit" label = "do not create exchange">
- <doc>
- If set, the server will not create the exchange. The client can use this to
- check whether an exchange exists without modifying the server state.
- </doc>
- <rule name = "not-found">
- <doc>
- If set, and the exchange does not already exist, the server MUST raise a
- channel exception with reply code 404 (not found).
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "durable" domain = "bit" label = "request a durable exchange">
- <doc>
- If set when creating a new exchange, the exchange will be marked as durable.
- Durable exchanges remain active when a server restarts. Non-durable exchanges
- (transient exchanges) are purged if/when a server restarts.
- </doc>
- <rule name = "support">
- <doc>
- The server MUST support both durable and transient exchanges.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- <rule name = "sticky">
- <doc>
- The server MUST ignore the durable field if the exchange already exists.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <!-- TODO 0.82 - clarify how this works; there is no way to cancel a binding
- except by deleting a queue.
- -->
- <field name = "auto-delete" domain = "bit" label = "auto-delete when unused">
- <doc>
- If set, the exchange is deleted when all queues have finished using it.
- </doc>
- <rule name = "sticky">
- <doc>
- The server MUST ignore the auto-delete field if the exchange already
- exists.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "internal" domain = "bit" label = "create internal exchange">
- <doc>
- If set, the exchange may not be used directly by publishers, but only when bound
- to other exchanges. Internal exchanges are used to construct wiring that is not
- visible to applications.
- </doc>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
-
- <field name = "arguments" domain = "table" label = "arguments for declaration">
- <doc>
- A set of arguments for the declaration. The syntax and semantics of these
- arguments depends on the server implementation. This field is ignored if passive
- is 1.
- </doc>
- </field>
- </method>
-
- <method name = "declare-ok" synchronous = "1" index = "11" label = "confirm exchange declaration">
- <doc>
- This method confirms a Declare method and confirms the name of the exchange,
- essential for automatically-named exchanges.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "delete" synchronous = "1" index = "20" label = "delete an exchange">
- <doc>
- This method deletes an exchange. When an exchange is deleted all queue bindings on
- the exchange are cancelled.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "delete-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MUST provide a valid access ticket giving "active" access
- rights to the exchange's access realm.
- </doc>
- <doc type = "scenario">
- Client creates access ticket with wrong access rights and attempts to use
- in this method.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <rule name = "exists" on-failure = "not-found">
- <doc>
- The client MUST NOT attempt to delete an exchange that does not exist.
- </doc>
- </rule>
- <assert check = "notnull" />
- </field>
-
- <!-- TODO 0.82 - discuss whether this option is useful or not. I don't have
- any real use case for it. /PH 2006-07-23.
- -->
- <field name = "if-unused" domain = "bit" label = "delete only if unused">
- <doc>
- If set, the server will only delete the exchange if it has no queue bindings. If
- the exchange has queue bindings the server does not delete it but raises a
- channel exception instead.
- </doc>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "delete-ok" synchronous = "1" index = "21"
- label = "confirm deletion of an exchange">
- <doc>This method confirms the deletion of an exchange.</doc>
- <chassis name = "client" implement = "MUST" />
- </method>
- </class>
-
- <!-- == QUEUE ============================================================ -->
-
- <class name = "queue" handler = "channel" index = "50" label = "work with queues">
- <doc>
- Queues store and forward messages. Queues can be configured in the server or created at
- runtime. Queues must be attached to at least one exchange in order to receive messages
- from publishers.
- </doc>
-
- <doc type = "grammar">
- queue = C:DECLARE S:DECLARE-OK
- / C:BIND S:BIND-OK
- / C:PURGE S:PURGE-OK
- / C:DELETE S:DELETE-OK
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <rule name = "any-content">
- <doc>
- A server MUST allow any content class to be sent to any queue, in any mix, and
- queue and deliver these content classes independently. Note that all methods
- that fetch content off queues are specific to a given content class.
- </doc>
- <doc type = "scenario">
- Client creates an exchange of each standard type and several queues that
- it binds to each exchange. It must then sucessfully send each of the standard
- content types to each of the available queues.
- </doc>
- </rule>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "declare" synchronous = "1" index = "10" label = "declare queue, create if needed">
- <doc>
- This method creates or checks a queue. When creating a new queue the client can
- specify various properties that control the durability of the queue and its
- contents, and the level of sharing for the queue.
- </doc>
-
- <rule name = "default-binding">
- <doc>
- The server MUST create a default binding for a newly-created queue to the
- default exchange, which is an exchange of type 'direct'.
- </doc>
- <doc type = "scenario">
- Client creates a new queue, and then without explicitly binding it to an
- exchange, attempts to send a message through the default exchange binding,
- i.e. publish a message to the empty exchange, with the queue name as routing
- key.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_35" -->
- <rule name = "minimum-queues">
- <doc>
- The server SHOULD support a minimum of 256 queues per virtual host and ideally,
- impose no limit except as defined by available resources.
- </doc>
- <doc type = "scenario">
- Client attempts to create as many queues as it can until the server reports
- an error. The resulting count must at least be 256.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "declare-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>
- When a client defines a new queue, this belongs to the access realm of the
- ticket used. All further work done with that queue must be done with an access
- ticket for the same realm.
- </doc>
- <rule name = "validity" on-failure = "access-refused">
- <doc>
- The client MUST provide a valid access ticket giving "active" access to
- the realm in which the queue exists or will be created.
- </doc>
- <doc type = "scenario">
- Client creates access ticket with wrong access rights and attempts to use
- in this method.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <rule name = "default-name">
- <doc>
- The queue name MAY be empty, in which case the server MUST create a new
- queue with a unique generated name and return this to the client in the
- Declare-Ok method.
- </doc>
- <doc type = "scenario">
- Client attempts to create several queues with an empty name. The client then
- verifies that the server-assigned names are unique and different.
- </doc>
- </rule>
- <rule name = "reserved-prefix" on-failure = "not-allowed">
- <doc>
- Queue names starting with "amq." are reserved for predeclared and
- standardised server queues. A client MAY NOT attempt to declare a queue with a
- name that starts with "amq." and the passive option set to zero.
- </doc>
- <doc type = "scenario">
- A client attempts to create a queue with a name starting with "amq." and with
- the passive option set to zero.
- </doc>
- </rule>
- <assert check = "regexp" value = "^[a-zA-Z0-9-_.:]*$" />
- </field>
-
- <field name = "passive" domain = "bit" label = "do not create queue">
- <doc>
- If set, the server will not create the queue. This field allows the client
- to assert the presence of a queue without modifying the server state.
- </doc>
- <rule name = "passive" on-failure = "not-found">
- <doc>
- The client MAY ask the server to assert that a queue exists without
- creating the queue if not. If the queue does not exist, the server
- treats this as a failure.
- </doc>
- <doc type = "scenario">
- Client declares an existing queue with the passive option and expects
- the server to respond with a declare-ok. Client then attempts to declare
- a non-existent queue with the passive option, and the server must close
- the channel with the correct reply-code.
- </doc>
- </rule>
- </field>
-
- <field name = "durable" domain = "bit" label = "request a durable queue">
- <doc>
- If set when creating a new queue, the queue will be marked as durable. Durable
- queues remain active when a server restarts. Non-durable queues (transient
- queues) are purged if/when a server restarts. Note that durable queues do not
- necessarily hold persistent messages, although it does not make sense to send
- persistent messages to a transient queue.
- </doc>
- <!-- Rule test name: was "amq_queue_03" -->
- <rule name = "persistence">
- <doc>The server MUST recreate the durable queue after a restart.</doc>
-
- <!-- TODO: use 'client does something' rather than 'a client does something'. -->
- <doc type = "scenario">
- A client creates a durable queue. The server is then restarted. The client
- then attempts to send a message to the queue. The message should be successfully
- delivered.
- </doc>
- </rule>
- <!-- Rule test name: was "amq_queue_36" -->
- <rule name = "types">
- <doc>The server MUST support both durable and transient queues.</doc>
- <doc type = "scenario">
- A client creates two named queues, one durable and one transient.
- </doc>
- </rule>
- <!-- Rule test name: was "amq_queue_37" -->
- <rule name = "pre-existence">
- <doc>The server MUST ignore the durable field if the queue already exists.</doc>
- <doc type = "scenario">
- A client creates two named queues, one durable and one transient. The client
- then attempts to declare the two queues using the same names again, but reversing
- the value of the durable flag in each case. Verify that the queues still exist
- with the original durable flag values.
- <!-- TODO: but how? -->
- </doc>
- </rule>
- </field>
-
- <field name = "exclusive" domain = "bit" label = "request an exclusive queue">
- <doc>
- Exclusive queues may only be consumed from by the current connection. Setting
- the 'exclusive' flag always implies 'auto-delete'.
- </doc>
-
- <!-- Rule test name: was "amq_queue_38" -->
- <rule name = "types">
- <doc>
- The server MUST support both exclusive (private) and non-exclusive (shared)
- queues.
- </doc>
- <doc type = "scenario">
- A client creates two named queues, one exclusive and one non-exclusive.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_04" -->
- <rule name = "02" on-failure = "channel-error">
- <doc>
- The client MAY NOT attempt to declare any existing and exclusive queue
- on multiple connections.
- </doc>
- <doc type = "scenario">
- A client declares an exclusive named queue. A second client on a different
- connection attempts to declare a queue of the same name.
- </doc>
- </rule>
- </field>
-
- <field name = "auto-delete" domain = "bit" label = "auto-delete queue when unused">
- <doc>
- If set, the queue is deleted when all consumers have finished using it. Last
- consumer can be cancelled either explicitly or because its channel is closed. If
- there was no consumer ever on the queue, it won't be deleted.
- </doc>
-
- <!-- Rule test name: was "amq_queue_31" -->
- <rule name = "pre-existence">
- <doc>
- The server MUST ignore the auto-delete field if the queue already exists.
- </doc>
- <doc type = "scenario">
- A client creates two named queues, one as auto-delete and one explicit-delete.
- The client then attempts to declare the two queues using the same names again,
- but reversing the value of the auto-delete field in each case. Verify that the
- queues still exist with the original auto-delete flag values.
- <!-- TODO: but how? -->
- </doc>
- </rule>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
-
- <field name = "arguments" domain = "table" label = "arguments for declaration">
- <doc>
- A set of arguments for the declaration. The syntax and semantics of these
- arguments depends on the server implementation. This field is ignored if passive
- is 1.
- </doc>
- </field>
- </method>
-
- <method name = "declare-ok" synchronous = "1" index = "11" label = "confirms a queue definition">
- <doc>
- This method confirms a Declare method and confirms the name of the queue, essential
- for automatically-named queues.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Reports the name of the queue. If the server generated a queue name, this field
- contains that name.
- </doc>
- <assert check = "notnull" />
- </field>
-
- <field name = "message-count" domain = "long" label = "number of messages in queue">
- <doc>
- Reports the number of messages in the queue, which will be zero for
- newly-created queues.
- </doc>
- </field>
-
- <field name = "consumer-count" domain = "long" label = "number of consumers">
- <doc>
- Reports the number of active consumers for the queue. Note that consumers can
- suspend activity (Channel.Flow) in which case they do not appear in this count.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "bind" synchronous = "1" index = "20" label = "bind queue to an exchange">
- <doc>
- This method binds a queue to an exchange. Until a queue is bound it will not receive
- any messages. In a classic messaging model, store-and-forward queues are bound to a
- dest exchange and subscription queues are bound to a dest_wild exchange.
- </doc>
-
- <!-- Rule test name: was "amq_queue_25" -->
- <rule name = "duplicates">
- <doc>
- A server MUST allow ignore duplicate bindings - that is, two or more bind
- methods for a specific queue, with identical arguments - without treating these
- as an error.
- </doc>
- <doc type = "scenario">
- A client binds a named queue to an exchange. The client then repeats the bind
- (with identical arguments).
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_39" -->
- <rule name = "failure" on-failure = "??????">
- <!--
- TODO: Find correct code. The on-failure code returned should depend on why the bind
- failed. Assuming that failures owing to bad parameters are covered in the rules relating
- to those parameters, the only remaining reason for a failure would be the lack of
- server resorces or some internal error - such as too many queues open. Would these
- cases qualify as "resource error" 506 or "internal error" 541?
- -->
- <doc>If a bind fails, the server MUST raise a connection exception.</doc>
- <doc type = "scenario">
- TODO
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_12" -->
- <rule name = "transient-exchange" on-failure = "not-allowed">
- <doc>
- The server MUST NOT allow a durable queue to bind to a transient exchange.
- </doc>
- <doc type = "scenario">
- A client creates a transient exchange. The client then declares a named durable
- queue and then attempts to bind the transient exchange to the durable queue.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_13" -->
- <rule name = "durable-exchange">
- <doc>
- Bindings for durable queues are automatically durable and the server SHOULD
- restore such bindings after a server restart.
- </doc>
- <doc type = "scenario">
- A server creates a named durable queue and binds it to a durable exchange. The
- server is restarted. The client then attempts to use the queue/exchange combination.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_17" -->
- <rule name = "internal-exchange">
- <doc>
- If the client attempts to bind to an exchange that was declared as internal, the server
- MUST raise a connection exception with reply code 530 (not allowed).
- </doc>
- <doc type = "scenario">
- A client attempts to bind a named queue to an internal exchange.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_40" -->
- <rule name = "binding-count">
- <doc>
- The server SHOULD support at least 4 bindings per queue, and ideally, impose no
- limit except as defined by available resources.
- </doc>
- <doc type = "scenario">
- A client creates a named queue and attempts to bind it to 4 different non-internal
- exchanges.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "bind-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>
- The client provides a valid access ticket giving "active" access rights to the
- queue's access realm.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to bind. If the queue name is empty, refers to
- the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "empty-queue" on-failure = "not-allowed">
- <doc>
- A client MUST NOT be allowed to bind a non-existent and unnamed queue (i.e.
- empty queue name) to an exchange.
- </doc>
- <doc type = "scenario">
- A client attempts to bind with an unnamed (empty) queue name to an exchange.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_26" -->
- <rule name = "queue-existence" on-failure = "not-found">
- <doc>
- A client MUST NOT be allowed to bind a non-existent queue (i.e. not previously
- declared) to an exchange.
- </doc>
- <doc type = "scenario">
- A client attempts to bind an undeclared queue name to an exchange.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name" label = "name of the exchange to bind to">
- <!-- Rule test name: was "amq_queue_14" -->
- <rule name = "exchange-existence" on-failure = "not-found">
- <doc>
- A client MUST NOT be allowed to bind a queue to a non-existent exchange.
- </doc>
- <doc type = "scenario">
- A client attempts to bind an named queue to a undeclared exchange.
- </doc>
- </rule>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "message routing key">
- <doc>
- Specifies the routing key for the binding. The routing key is used for routing
- messages depending on the exchange configuration. Not all exchanges use a
- routing key - refer to the specific exchange documentation. If the queue name
- is empty, the server uses the last queue declared on the channel. If the
- routing key is also empty, the server uses this queue name for the routing
- key as well. If the queue name is provided but the routing key is empty, the
- server does the binding with that empty routing key. The meaning of empty
- routing keys depends on the exchange implementation.
- </doc>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
-
- <field name = "arguments" domain = "table" label = "arguments for binding">
- <doc>
- A set of arguments for the binding. The syntax and semantics of these arguments
- depends on the exchange class.
- </doc>
- </field>
- </method>
-
- <method name = "bind-ok" synchronous = "1" index = "21" label = "confirm bind successful">
- <doc>This method confirms that the bind was successful.</doc>
-
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "purge" synchronous = "1" index = "30" label = "purge a queue">
- <doc>
- This method removes all messages from a queue. It does not cancel consumers. Purged
- messages are deleted without any formal "undo" mechanism.
- </doc>
-
- <!-- Rule test name: was "amq_queue_15" -->
- <rule name = "01">
- <doc>A call to purge MUST result in an empty queue.</doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_41" -->
- <rule name = "02">
- <doc>
- On transacted channels the server MUST not purge messages that have already been
- sent to a client but not yet acknowledged.
- </doc>
- </rule>
-
- <!-- TODO: Rule split? -->
-
- <!-- Rule test name: was "amq_queue_42" -->
- <rule name = "03">
- <doc>
- The server MAY implement a purge queue or log that allows system administrators
- to recover accidentally-purged messages. The server SHOULD NOT keep purged
- messages in the same storage spaces as the live messages since the volumes of
- purged messages may get very large.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "purge-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>The access ticket must be for the access realm that holds the queue.</doc>
-
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the queue's access realm. Note that purging a queue is equivalent to reading
- all messages and discarding them.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to purge. If the queue name is empty, refers to
- the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- </rule>
-
- <!-- TODO Rule split? -->
-
- <!-- Rule test name: was "amq_queue_16" -->
- <rule name = "02">
- <doc>
- The queue MUST exist. Attempting to purge a non-existing queue MUST cause a
- channel exception.
- </doc>
- </rule>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "purge-ok" synchronous = "1" index = "31" label = "confirms a queue purge">
- <doc>This method confirms the purge of a queue.</doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "message-count" domain = "long" label = "number of messages purged">
- <doc>Reports the number of messages purged.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "delete" synchronous = "1" index = "40" label = "delete a queue">
- <doc>
- This method deletes a queue. When a queue is deleted any pending messages are sent
- to a dead-letter queue if this is defined in the server configuration, and all
- consumers on the queue are cancelled.
- </doc>
-
- <!-- TODO: Rule split? -->
-
- <!-- Rule test name: was "amq_queue_43" -->
- <rule name = "01">
- <doc>
- The server SHOULD use a dead-letter queue to hold messages that were pending on
- a deleted queue, and MAY provide facilities for a system administrator to move
- these messages back to an active queue.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "delete-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <doc>
- The client provides a valid access ticket giving "active" access rights to the
- queue's access realm.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to delete. If the queue name is empty, refers to
- the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_queue_21" -->
- <rule name = "02">
- <doc>
- The queue must exist. If the client attempts to delete a non-existing queue
- the server MUST raise a channel exception with reply code 404 (not found).
- </doc>
- </rule>
- </field>
-
- <field name = "if-unused" domain = "bit" label = "delete only if unused">
- <doc>
- If set, the server will only delete the queue if it has no consumers. If the
- queue has consumers the server does does not delete it but raises a channel
- exception instead.
- </doc>
-
- <!-- Rule test name: was "amq_queue_29" and "amq_queue_30" -->
- <rule name = "01">
- <doc>The server MUST respect the if-unused flag when deleting a queue.</doc>
- </rule>
- </field>
-
- <field name = "if-empty" domain = "bit" label = "delete only if empty">
- <doc>
- If set, the server will only delete the queue if it has no messages.
- </doc>
- <rule name = "01">
- <doc>
- If the queue is not empty the server MUST raise a channel exception with
- reply code 406 (precondition failed).
- </doc>
- </rule>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "delete-ok" synchronous = "1" index = "41" label = "confirm deletion of a queue">
- <doc>This method confirms the deletion of a queue.</doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "message-count" domain = "long" label = "number of messages purged">
- <doc>Reports the number of messages purged.</doc>
- </field>
- </method>
- </class>
-
- <!-- == BASIC ============================================================ -->
-
- <class name = "basic" handler = "channel" index = "60" label = "work with basic content">
- <doc>
- The Basic class provides methods that support an industry-standard messaging model.
- </doc>
-
- <doc type = "grammar">
- basic = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:PUBLISH content
- / S:RETURN content
- / S:DELIVER content
- / C:GET ( S:GET-OK content / S:GET-EMPTY )
- / C:ACK
- / C:REJECT
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MAY" />
-
- <!-- Rule test name: was "amq_basic_08" -->
- <rule name = "01">
- <doc>
- The server SHOULD respect the persistent property of basic messages and
- SHOULD make a best-effort to hold persistent basic messages on a reliable
- storage mechanism.
- </doc>
- <doc type = "scenario">
- Send a persistent message to queue, stop server, restart server and then
- verify whether message is still present. Assumes that queues are durable.
- Persistence without durable queues makes no sense.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_09" -->
- <rule name = "02">
- <doc>
- The server MUST NOT discard a persistent basic message in case of a queue
- overflow.
- </doc>
- <doc type = "scenario">
- Create a queue overflow situation with persistent messages and verify that
- messages do not get lost (presumably the server will write them to disk).
- </doc>
- </rule>
-
- <rule name = "03">
- <doc>
- The server MAY use the Channel.Flow method to slow or stop a basic message
- publisher when necessary.
- </doc>
- <doc type = "scenario">
- Create a queue overflow situation with non-persistent messages and verify
- whether the server responds with Channel.Flow or not. Repeat with persistent
- messages.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_10" -->
- <rule name = "04">
- <doc>
- The server MAY overflow non-persistent basic messages to persistent
- storage.
- </doc>
- <!-- Test scenario: untestable -->
- </rule>
-
- <rule name = "05">
- <doc>
- The server MAY discard or dead-letter non-persistent basic messages on a
- priority basis if the queue size exceeds some configured limit.
- </doc>
- <!-- Test scenario: untestable -->
- </rule>
-
- <!-- Rule test name: was "amq_basic_11" -->
- <rule name = "06">
- <doc>
- The server MUST implement at least 2 priority levels for basic messages,
- where priorities 0-4 and 5-9 are treated as two distinct levels.
- </doc>
- <doc type = "scenario">
- Send a number of priority 0 messages to a queue. Send one priority 9
- message. Consume messages from the queue and verify that the first message
- received was priority 9.
- </doc>
- </rule>
-
- <rule name = "07">
- <doc>
- The server MAY implement up to 10 priority levels.
- </doc>
- <doc type = "scenario">
- Send a number of messages with mixed priorities to a queue, so that all
- priority values from 0 to 9 are exercised. A good scenario would be ten
- messages in low-to-high priority. Consume from queue and verify how many
- priority levels emerge.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_12" -->
- <rule name = "08">
- <doc>
- The server MUST deliver messages of the same priority in order irrespective of
- their individual persistence.
- </doc>
- <doc type = "scenario">
- Send a set of messages with the same priority but different persistence
- settings to a queue. Consume and verify that messages arrive in same order
- as originally published.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_13" -->
- <rule name = "09">
- <doc>
- The server MUST support automatic acknowledgements on Basic content, i.e.
- consumers with the no-ack field set to FALSE.
- </doc>
- <doc type = "scenario">
- Create a queue and a consumer using automatic acknowledgements. Publish
- a set of messages to the queue. Consume the messages and verify that all
- messages are received.
- </doc>
- </rule>
-
- <rule name = "10">
- <doc>
- The server MUST support explicit acknowledgements on Basic content, i.e.
- consumers with the no-ack field set to TRUE.
- </doc>
- <doc type = "scenario">
- Create a queue and a consumer using explicit acknowledgements. Publish a
- set of messages to the queue. Consume the messages but acknowledge only
- half of them. Disconnect and reconnect, and consume from the queue.
- Verify that the remaining messages are received.
- </doc>
- </rule>
-
- <!-- These are the properties for a Basic content -->
-
- <field name = "content-type" domain = "shortstr" label = "MIME content type" />
- <field name = "content-encoding" domain = "shortstr" label = "MIME content encoding" />
- <field name = "headers" domain = "table" label = "message header field table" />
- <field name = "delivery-mode" domain = "octet" label = "non-persistent (1) or persistent (2)" />
- <field name = "priority" domain = "octet" label = "message priority, 0 to 9" />
- <field name = "correlation-id" domain = "shortstr" label = "application correlation identifier" />
- <field name = "reply-to" domain = "shortstr" label = "destination to reply to" />
- <field name = "expiration" domain = "shortstr" label = "message expiration specification" />
- <field name = "message-id" domain = "shortstr" label = "application message identifier" />
- <field name = "timestamp" domain = "timestamp" label = "message timestamp" />
- <field name = "type" domain = "shortstr" label = "message type name" />
- <field name = "user-id" domain = "shortstr" label = "creating user id" />
- <field name = "app-id" domain = "shortstr" label = "creating application id" />
- <!-- This field is deprecated pending review -->
- <field name = "cluster-id" domain = "shortstr" label = "intra-cluster routing identifier" />
-
- <field name = "property-one" domain = "shortstr" label = "Extra property for testing only" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "qos" synchronous = "1" index = "10" label = "specify quality of service">
- <doc>
- This method requests a specific quality of service. The QoS can be specified for the
- current channel or for all channels on the connection. The particular properties and
- semantics of a qos method always depend on the content class semantics. Though the
- qos method could in principle apply to both peers, it is currently meaningful only
- for the server.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "qos-ok" />
-
- <field name = "prefetch-size" domain = "long" label = "prefetch window in octets">
- <doc>
- The client can request that messages be sent in advance so that when the client
- finishes processing a message, the following message is already held locally,
- rather than needing to be sent down the channel. Prefetching gives a performance
- improvement. This field specifies the prefetch window size in octets. The server
- will send a message in advance if it is equal to or smaller in size than the
- available prefetch size (and also falls into other prefetch limits). May be set
- to zero, meaning "no specific limit", although other prefetch limits may still
- apply. The prefetch-size is ignored if the no-ack option is set.
- </doc>
- <!-- Rule test name: was "amq_basic_17" -->
- <rule name = "01">
- <doc>
- The server MUST ignore this setting when the client is not processing any
- messages - i.e. the prefetch size does not limit the transfer of single
- messages to a client, only the sending in advance of more messages while
- the client still has one or more unacknowledged messages.
- </doc>
- <doc type = "scenario">
- Define a QoS prefetch-size limit and send a single message that exceeds
- that limit. Verify that the message arrives correctly.
- </doc>
- </rule>
- </field>
-
- <field name = "prefetch-count" domain = "short" label = "prefetch window in messages">
- <doc>
- Specifies a prefetch window in terms of whole messages. This field may be used
- in combination with the prefetch-size field; a message will only be sent in
- advance if both prefetch windows (and those at the channel and connection level)
- allow it. The prefetch-count is ignored if the no-ack option is set.
- </doc>
- <!-- Rule test name: was "amq_basic_18" -->
- <rule name = "01">
- <doc>
- The server may send less data in advance than allowed by the client's
- specified prefetch windows but it MUST NOT send more.
- </doc>
- <doc type = "scenario">
- Define a QoS prefetch-size limit and a prefetch-count limit greater than
- one. Send multiple messages that exceed the prefetch size. Verify that
- no more than one message arrives at once.
- </doc>
- </rule>
- </field>
-
- <field name = "global" domain = "bit" label = "apply to entire connection">
- <doc>
- By default the QoS settings apply to the current channel only. If this field is
- set, they are applied to the entire connection.
- </doc>
- </field>
- </method>
-
- <method name = "qos-ok" synchronous = "1" index = "11" label = "confirm the requested qos">
- <doc>
- This method tells the client that the requested QoS levels could be handled by the
- server. The requested QoS applies to all active consumers until a new QoS is
- defined.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "consume" synchronous = "1" index = "30" label = "start a queue consumer">
- <doc>
- This method asks the server to start a "consumer", which is a transient request for
- messages from a specific queue. Consumers last as long as the channel they were
- created on, or until the client cancels them.
- </doc>
-
- <!-- Rule test name: was "amq_basic_01" -->
- <rule name = "01">
- <doc>
- The server SHOULD support at least 16 consumers per queue, and ideally, impose
- no limit except as defined by available resources.
- </doc>
- <doc type = "scenario">
- Create a queue and create consumers on that queue until the server closes the
- connection. Verify that the number of consumers created was at least sixteen
- and report the total number.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01" on-failure = "access-refused">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the realm for the queue.
- </doc>
- <doc type = "scenario">
- Attempt to create a consumer with an invalid (non-zero) access ticket.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name is null,
- refers to the current queue for the channel, which is the last declared queue.
- </doc>
- <rule name = "01" on-failure = "not-allowed">
- <doc>
- If the queue name is empty the client MUST have previously declared a
- queue using this channel.
- </doc>
- <doc type = "scenario">
- Attempt to create a consumer with an empty queue name and no previously
- declared queue on the channel.
- </doc>
- </rule>
- </field>
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is local to a
- connection, so two clients can use the same consumer tags. If this field is
- empty the server will generate a unique tag.
- </doc>
- <rule name = "01" on-failure = "not-allowed">
- <doc>
- The client MUST NOT specify a tag that refers to an existing consumer.
- </doc>
- <doc type = "scenario">
- Attempt to create two consumers with the same non-empty tag.
- </doc>
- </rule>
- <rule name = "02" on-failure = "not-allowed">
- <doc>
- The consumer tag is valid only within the channel from which the
- consumer was created. I.e. a client MUST NOT create a consumer in one
- channel and then use it in another.
- </doc>
- <doc type = "scenario">
- Attempt to create a consumer in one channel, then use in another channel,
- in which consumers have also been created (to test that the server uses
- unique consumer tags).
- </doc>
- </rule>
- </field>
-
- <field name = "no-local" domain = "no-local" />
-
- <field name = "no-ack" domain = "no-ack" />
-
- <field name = "exclusive" domain = "bit" label = "request exclusive access">
- <doc>
- Request exclusive consumer access, meaning only this consumer can access the
- queue.
- </doc>
- <!-- Rule test name: was "amq_basic_02" -->
- <rule name = "01" on-failure = "access-refused">
- <doc>
- The client MAY NOT gain exclusive access to a queue that already has
- active consumers.
- </doc>
- <doc type = "scenario">
- Open two connections to a server, and in one connection create a shared
- (non-exclusive) queue and then consume from the queue. In the second
- connection attempt to consume from the same queue using the exclusive
- option.
- </doc>
- </rule>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise
- a channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "consume-ok" synchronous = "1" index = "31" label = "confirm a new consumer">
- <doc>
- The server provides the client with a consumer tag, which is used by the client
- for methods called on the consumer at a later stage.
- </doc>
- <chassis name = "client" implement = "MUST" />
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>
- Holds the consumer tag specified by the client or provided by the server.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "cancel" synchronous = "1" index = "20" label = "end a queue consumer">
- <doc>
- This method cancels a consumer. This does not affect already delivered
- messages, but it does mean the server will not send any more messages for
- that consumer. The client may receive an abitrary number of messages in
- between sending the cancel method and receiving the cancel-ok reply.
- </doc>
-
- <rule name = "01">
- <doc>
- If the queue does not exist the server MUST ignore the cancel method, so
- long as the consumer tag is valid for that channel.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "cancel-ok" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "cancel-ok" synchronous = "1" index = "21" label = "confirm a cancelled consumer">
- <doc>
- This method confirms that the cancellation was completed.
- </doc>
- <chassis name = "client" implement = "MUST" />
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "publish" content = "1" index = "40" label = "publish a message">
- <doc>
- This method publishes a message to a specific exchange. The message will be routed
- to queues as defined by the exchange configuration and distributed to any active
- consumers when the transaction, if any, is committed.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "write" access rights
- to the access realm for the exchange.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange name can be
- empty, meaning the default exchange. If the exchange name is specified, and that
- exchange does not exist, the server will raise a channel exception.
- </doc>
-
- <!-- Rule test name: was "amq_basic_06" -->
- <rule name = "01">
- <doc>
- The server MUST accept a blank exchange name to mean the default exchange.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_14" -->
- <rule name = "02">
- <doc>
- If the exchange was declared as an internal exchange, the server MUST raise
- a channel exception with a reply code 403 (access refused).
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_15" -->
- <rule name = "03">
- <doc>
- The exchange MAY refuse basic content in which case it MUST raise a channel
- exception with reply code 540 (not implemented).
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>
- Specifies the routing key for the message. The routing key is used for routing
- messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" domain = "bit" label = "indicate mandatory routing">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue. If this flag is set, the server will return an unroutable message with a
- Return method. If this flag is zero, the server silently drops the message.
- </doc>
- <!-- Rule test name: was "amq_basic_07" -->
- <rule name = "01">
- <doc>
- The server SHOULD implement the mandatory flag.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "immediate" domain = "bit" label = "request immediate delivery">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue consumer immediately. If this flag is set, the server will return an
- undeliverable message with a Return method. If this flag is zero, the server
- will queue the message, but with no guarantee that it will ever be consumed.
- </doc>
- <!-- Rule test name: was "amq_basic_16" -->
- <rule name = "01">
- <doc>
- The server SHOULD implement the immediate flag.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "return" content = "1" index = "50" label = "return a failed message">
- <doc>
- This method returns an undeliverable message that was published with the "immediate"
- flag set, or an unroutable message published with the "mandatory" flag set. The
- reply code and text provide information about the reason that the message was
- undeliverable.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply-code" domain = "reply-code" />
-
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>
- Specifies the routing key name specified when the message was published.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "deliver" content = "1" index = "60"
- label = "notify the client of a consumer message">
- <doc>
- This method delivers a message to the client, via a consumer. In the asynchronous
- message delivery model, the client starts a consumer using the Consume method, then
- the server responds with Deliver methods as and when messages arrive for that
- consumer.
- </doc>
-
- <!-- Rule test name: was "amq_basic_19" -->
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server SHOULD track the number of times a message has been delivered to
- clients and when a message is redelivered a certain number of times - e.g. 5
- times - without being acknowledged, the server SHOULD consider the message to be
- unprocessable (possibly causing client applications to abort), and move the
- message to a dead letter queue.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "get" synchronous = "1" index = "70" label = "direct access to a queue">
- <doc>
- This method provides a direct access to the messages in a queue using a synchronous
- dialogue that is designed for specific types of application where synchronous
- functionality is more important than performance.
- </doc>
-
- <response name = "get-ok" />
- <response name = "get-empty" />
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the realm for the queue.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name is null,
- refers to the current queue for the channel, which is the last declared queue.
- </doc>
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
-
- <field name = "no-ack" domain = "no-ack" />
- </method>
-
- <method name = "get-ok" synchronous = "1" content = "1" index = "71"
- label = "provide client with a message">
- <doc>
- This method delivers a message to the client following a get method. A message
- delivered by 'get-ok' must be acknowledged unless the no-ack option was set in the
- get method.
- </doc>
-
- <chassis name = "client" implement = "MAY" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- If empty, the message was published to the default exchange.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
-
- <field name = "message-count" domain = "long" label = "number of messages pending">
- <doc>
- This field reports the number of messages pending on the queue, excluding the
- message being delivered. Note that this figure is indicative, not reliable, and
- can change arbitrarily as messages are added to the queue and removed by other
- clients.
- </doc>
- </field>
- </method>
-
- <method name = "get-empty" synchronous = "1" index = "72"
- label = "indicate no messages available">
- <doc>
- This method tells the client that the queue has no messages available for the
- client.
- </doc>
-
- <chassis name = "client" implement = "MAY" />
-
- <!-- This field is deprecated pending review -->
- <field name = "cluster-id" domain = "shortstr" label = "Cluster id">
- <doc>
- For use by cluster applications, should not be used by client applications.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "ack" index = "80" label = "acknowledge one or more messages">
- <doc>
- This method acknowledges one or more messages delivered via the Deliver or Get-Ok
- methods. The client can ask to confirm a single message or a set of messages up to
- and including a specific message.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "multiple" domain = "bit" label = "acknowledge multiple messages">
- <doc>
- If set to 1, the delivery tag is treated as "up to and including", so that the
- client can acknowledge multiple messages with a single method. If set to zero,
- the delivery tag refers to a single message. If the multiple field is 1, and the
- delivery tag is zero, tells the server to acknowledge all outstanding mesages.
- </doc>
-
- <!-- Rule test name: was "amq_basic_20" -->
- <rule name = "01">
- <doc>
- The server MUST validate that a non-zero delivery-tag refers to an delivered
- message, and raise a channel exception if this is not the case.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "reject" index = "90" label = "reject an incoming message">
- <doc>
- This method allows a client to reject a message. It can be used to interrupt and
- cancel large incoming messages, or return untreatable messages to their original
- queue.
- </doc>
-
- <!-- Rule test name: was "amq_basic_21" -->
- <rule name = "01">
- <doc>
- The server SHOULD be capable of accepting and process the Reject method while
- sending message content with a Deliver or Get-Ok method. I.e. the server should
- read and process incoming methods while sending output frames. To cancel a
- partially-send content, the server sends a content body frame of size 1 (i.e.
- with no data except the frame-end octet).
- </doc>
- </rule>
-
- <!-- Rule test name: was "amq_basic_22" -->
- <rule name = "02">
- <doc>
- The server SHOULD interpret this method as meaning that the client is unable to
- process the message at this time.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <rule name = "03">
- <!-- TODO: Rule split? -->
- <doc>
- A client MUST NOT use this method as a means of selecting messages to process. A
- rejected message MAY be discarded or dead-lettered, not necessarily passed to
- another client.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "requeue" domain = "bit" label = "requeue the message">
- <doc>
- If this field is zero, the message will be discarded. If this bit is 1, the
- server will attempt to requeue the message.
- </doc>
-
- <!-- Rule test name: was "amq_basic_23" -->
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server MUST NOT deliver the message to the same client within the
- context of the current channel. The recommended strategy is to attempt to
- deliver the message to an alternative consumer, and if that is not possible,
- to move the message to a dead-letter queue. The server MAY use more
- sophisticated tracking to hold the message on the queue and redeliver it to
- the same client at a later stage.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "recover" index = "100" label = "redeliver unacknowledged messages">
- <doc>
- This method asks the broker to redeliver all unacknowledged messages on a specified
- channel. Zero or more messages may be redelivered. This method is only allowed on
- non-transacted channels.
- </doc>
-
- <rule name = "01">
- <doc>
- The server MUST set the redelivered flag on all messages that are resent.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <rule name = "02">
- <doc>
- The server MUST raise a channel exception if this is called on a transacted
- channel.
- </doc>
- <doc type = "scenario">
- TODO.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "requeue" domain = "bit" label = "requeue the message">
- <doc>
- If this field is zero, the message will be redelivered to the original
- recipient. If this bit is 1, the server will attempt to requeue the message,
- potentially then delivering it to an alternative subscriber.
- </doc>
- </field>
- </method>
- </class>
-
- <!-- == FILE ============================================================= -->
-
- <class name = "file" handler = "channel" index = "70" label = "work with file content">
- <doc>
- The file class provides methods that support reliable file transfer. File
- messages have a specific set of properties that are required for interoperability
- with file transfer applications. File messages and acknowledgements are subject to
- channel transactions. Note that the file class does not provide message browsing
- methods; these are not compatible with the staging model. Applications that need
- browsable file transfer should use Basic content and the Basic class.
- </doc>
-
- <doc type = "grammar">
- file = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:OPEN S:OPEN-OK C:STAGE content
- / S:OPEN C:OPEN-OK S:STAGE content
- / C:PUBLISH
- / S:DELIVER
- / S:RETURN
- / C:ACK
- / C:REJECT
- </doc>
-
- <chassis name = "server" implement = "MAY" />
- <chassis name = "client" implement = "MAY" />
-
- <rule name = "01">
- <doc>
- The server MUST make a best-effort to hold file messages on a reliable storage
- mechanism.
- </doc>
- </rule>
-
- <!-- TODO Rule implement attr inverse? -->
-
- <!-- TODO: Rule split? -->
-
- <rule name = "02">
- <doc>
- The server MUST NOT discard a file message in case of a queue overflow. The server
- MUST use the Channel.Flow method to slow or stop a file message publisher when
- necessary.
- </doc>
- </rule>
-
- <!-- TODO: Rule split? -->
-
- <rule name = "03">
- <doc>
- The server MUST implement at least 2 priority levels for file messages, where
- priorities 0-4 and 5-9 are treated as two distinct levels. The server MAY implement
- up to 10 priority levels.
- </doc>
- </rule>
-
- <rule name = "04">
- <doc>
- The server MUST support both automatic and explicit acknowledgements on file
- content.
- </doc>
- </rule>
-
- <!-- These are the properties for a File content -->
-
- <field name = "content-type" domain = "shortstr" label = "MIME content type" />
- <field name = "content-encoding" domain = "shortstr" label = "MIME content encoding" />
- <field name = "headers" domain = "table" label = "message header field table" />
- <field name = "priority" domain = "octet" label = "message priority, 0 to 9" />
- <field name = "reply-to" domain = "shortstr" label = "destination to reply to" />
- <field name = "message-id" domain = "shortstr" label = "application message identifier" />
- <field name = "filename" domain = "shortstr" label = "message filename" />
- <field name = "timestamp" domain = "timestamp" label = "message timestamp" />
- <!-- This field is deprecated pending review -->
- <field name = "cluster-id" domain = "shortstr" label = "intra-cluster routing identifier" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "qos" synchronous = "1" index = "10" label = "specify quality of service">
- <doc>
- This method requests a specific quality of service. The QoS can be specified for the
- current channel or for all channels on the connection. The particular properties and
- semantics of a qos method always depend on the content class semantics. Though the
- qos method could in principle apply to both peers, it is currently meaningful only
- for the server.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "qos-ok" />
-
- <field name = "prefetch-size" domain = "long" label = "prefetch window in octets">
- <doc>
- The client can request that messages be sent in advance so that when the client
- finishes processing a message, the following message is already held locally,
- rather than needing to be sent down the channel. Prefetching gives a performance
- improvement. This field specifies the prefetch window size in octets. May be set
- to zero, meaning "no specific limit". Note that other prefetch limits may still
- apply. The prefetch-size is ignored if the no-ack option is set.
- </doc>
- </field>
-
- <field name = "prefetch-count" domain = "short" label = "prefetch window in messages">
- <doc>
- Specifies a prefetch window in terms of whole messages. This is compatible with
- some file API implementations. This field may be used in combination with the
- prefetch-size field; a message will only be sent in advance if both prefetch
- windows (and those at the channel and connection level) allow it. The
- prefetch-count is ignored if the no-ack option is set.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server MAY send less data in advance than allowed by the client's
- specified prefetch windows but it MUST NOT send more.
- </doc>
- </rule>
- </field>
-
- <field name = "global" domain = "bit" label = "apply to entire connection">
- <doc>
- By default the QoS settings apply to the current channel only. If this field is
- set, they are applied to the entire connection.
- </doc>
- </field>
- </method>
-
- <method name = "qos-ok" synchronous = "1" index = "11" label = "confirm the requested qos">
- <doc>
- This method tells the client that the requested QoS levels could be handled by the
- server. The requested QoS applies to all active consumers until a new QoS is
- defined.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "consume" synchronous = "1" index = "20" label = "start a queue consumer">
- <doc>
- This method asks the server to start a "consumer", which is a transient request for
- messages from a specific queue. Consumers last as long as the channel they were
- created on, or until the client cancels them.
- </doc>
-
- <rule name = "01">
- <doc>
- The server SHOULD support at least 16 consumers per queue, unless the queue was
- declared as private, and ideally, impose no limit except as defined by available
- resources.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the realm for the queue.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name is null,
- refers to the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- </rule>
- </field>
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is local to a
- connection, so two clients can use the same consumer tags. If this field is
- empty the server will generate a unique tag.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The tag MUST NOT refer to an existing consumer. If the client attempts to
- create two consumers with the same non-empty tag the server MUST raise a
- connection exception with reply code 530 (not allowed).
- </doc>
- </rule>
- </field>
-
- <field name = "no-local" domain = "no-local" />
-
- <field name = "no-ack" domain = "no-ack" />
-
- <field name = "exclusive" domain = "bit" label = "request exclusive access">
- <doc>
- Request exclusive consumer access, meaning only this consumer can access the
- queue.
- </doc>
-
- <!-- Rule test name: was "amq_file_00" -->
- <rule name = "01">
- <doc>
- If the server cannot grant exclusive access to the queue when asked, -
- because there are other consumers active - it MUST raise a channel exception
- with return code 405 (resource locked).
- </doc>
- </rule>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "consume-ok" synchronous = "1" index = "21" label = "confirm a new consumer">
- <doc>
- This method provides the client with a consumer tag which it MUST use in methods
- that work with the consumer.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>Holds the consumer tag specified by the client or provided by the server.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "cancel" synchronous = "1" index = "30" label = "end a queue consumer">
- <doc>
- This method cancels a consumer. This does not affect already delivered messages, but
- it does mean the server will not send any more messages for that consumer.
- </doc>
-
- <response name = "cancel-ok" />
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "cancel-ok" synchronous = "1" index = "31" label = "confirm a cancelled consumer">
- <doc>This method confirms that the cancellation was completed.</doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "open" synchronous = "1" index = "40" label = "request to start staging">
- <doc>
- This method requests permission to start staging a message. Staging means sending
- the message into a temporary area at the recipient end and then delivering the
- message by referring to this temporary area. Staging is how the protocol handles
- partial file transfers - if a message is partially staged and the connection breaks,
- the next time the sender starts to stage it, it can restart from where it left off.
- </doc>
-
- <response name = "open-ok" />
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <field name = "identifier" domain = "shortstr" label = "staging identifier">
- <doc>
- This is the staging identifier. This is an arbitrary string chosen by the
- sender. For staging to work correctly the sender must use the same staging
- identifier when staging the same message a second time after recovery from a
- failure. A good choice for the staging identifier would be the SHA1 hash of the
- message properties data (including the original filename, revised time, etc.).
- </doc>
- </field>
-
- <field name = "content-size" domain = "longlong" label = "message content size">
- <doc>
- The size of the content in octets. The recipient may use this information to
- allocate or check available space in advance, to avoid "disk full" errors during
- staging of very large messages.
- </doc>
-
- <rule name = "01">
- <doc>
- The sender MUST accurately fill the content-size field. Zero-length content
- is permitted.
- </doc>
- </rule>
- </field>
- </method>
-
- <method name = "open-ok" synchronous = "1" index = "41" label = "confirm staging ready">
- <doc>
- This method confirms that the recipient is ready to accept staged data. If the
- message was already partially-staged at a previous time the recipient will report
- the number of octets already staged.
- </doc>
-
- <response name = "stage" />
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
-
- <field name = "staged-size" domain = "longlong" label = "already staged amount">
- <doc>
- The amount of previously-staged content in octets. For a new message this will
- be zero.
- </doc>
-
- <rule name = "01">
- <doc>
- The sender MUST start sending data from this octet offset in the message,
- counting from zero.
- </doc>
- </rule>
-
- <rule name = "02">
- <!-- TODO: Rule split? -->
- <doc>
- The recipient MAY decide how long to hold partially-staged content and MAY
- implement staging by always discarding partially-staged content. However if
- it uses the file content type it MUST support the staging methods.
- </doc>
- </rule>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "stage" content = "1" index = "50" label = "stage message content">
- <doc>
- This method stages the message, sending the message content to the recipient from
- the octet offset specified in the Open-Ok method.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "publish" index = "60" label = "publish a message">
- <doc>
- This method publishes a staged file message to a specific exchange. The file message
- will be routed to queues as defined by the exchange configuration and distributed to
- any active consumers when the transaction, if any, is committed.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "write" access rights
- to the access realm for the exchange.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange name can be
- empty, meaning the default exchange. If the exchange name is specified, and that
- exchange does not exist, the server will raise a channel exception.
- </doc>
-
- <rule name = "01">
- <doc>
- The server MUST accept a blank exchange name to mean the default exchange.
- </doc>
- </rule>
-
- <rule name = "02">
- <doc>
- If the exchange was declared as an internal exchange, the server MUST
- respond with a reply code 403 (access refused) and raise a channel
- exception.
- </doc>
- </rule>
-
- <!-- TODO: Rule split? -->
-
- <rule name = "03">
- <doc>
- The exchange MAY refuse file content in which case it MUST respond with a
- reply code 540 (not implemented) and raise a channel exception.
- </doc>
- </rule>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>
- Specifies the routing key for the message. The routing key is used for routing
- messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" domain = "bit" label = "indicate mandatory routing">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue. If this flag is set, the server will return an unroutable message with a
- Return method. If this flag is zero, the server silently drops the message.
- </doc>
-
- <!-- Rule test name: was "amq_file_00" -->
- <rule name = "01">
- <doc>The server SHOULD implement the mandatory flag.</doc>
- </rule>
- </field>
-
- <field name = "immediate" domain = "bit" label = "request immediate delivery">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue consumer immediately. If this flag is set, the server will return an
- undeliverable message with a Return method. If this flag is zero, the server
- will queue the message, but with no guarantee that it will ever be consumed.
- </doc>
-
- <!-- Rule test name: was "amq_file_00" -->
- <rule name = "01">
- <doc>The server SHOULD implement the immediate flag.</doc>
- </rule>
- </field>
-
- <field name = "identifier" domain = "shortstr" label = "staging identifier">
- <doc>
- This is the staging identifier of the message to publish. The message must have
- been staged. Note that a client can send the Publish method asynchronously
- without waiting for staging to finish.
- </doc>
- </field>
- </method>
-
- <method name = "return" content = "1" index = "70" label = "return a failed message">
- <doc>
- This method returns an undeliverable message that was published with the "immediate"
- flag set, or an unroutable message published with the "mandatory" flag set. The
- reply code and text provide information about the reason that the message was
- undeliverable.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply-code" domain = "reply-code" />
-
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "deliver" index = "80" label = "notify the client of a consumer message">
- <doc>
- This method delivers a staged file message to the client, via a consumer. In the
- asynchronous message delivery model, the client starts a consumer using the Consume
- method, then the server responds with Deliver methods as and when messages arrive
- for that consumer.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server SHOULD track the number of times a message has been delivered to
- clients and when a message is redelivered a certain number of times - e.g. 5
- times - without being acknowledged, the server SHOULD consider the message to be
- unprocessable (possibly causing client applications to abort), and move the
- message to a dead letter queue.
- </doc>
- </rule>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "redelivered" domain = "redelivered" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
-
- <field name = "identifier" domain = "shortstr" label = "staging identifier">
- <doc>
- This is the staging identifier of the message to deliver. The message must have
- been staged. Note that a server can send the Deliver method asynchronously
- without waiting for staging to finish.
- </doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "ack" index = "90" label = "acknowledge one or more messages">
- <doc>
- This method acknowledges one or more messages delivered via the Deliver method. The
- client can ask to confirm a single message or a set of messages up to and including
- a specific message.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "multiple" domain = "bit" label = "acknowledge multiple messages">
- <doc>
- If set to 1, the delivery tag is treated as "up to and including", so that the
- client can acknowledge multiple messages with a single method. If set to zero,
- the delivery tag refers to a single message. If the multiple field is 1, and the
- delivery tag is zero, tells the server to acknowledge all outstanding mesages.
- </doc>
-
- <rule name = "01">
- <doc>
- The server MUST validate that a non-zero delivery-tag refers to an delivered
- message, and raise a channel exception if this is not the case.
- </doc>
- </rule>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "reject" index = "100" label = "reject an incoming message">
- <doc>
- This method allows a client to reject a message. It can be used to return
- untreatable messages to their original queue. Note that file content is staged
- before delivery, so the client will not use this method to interrupt delivery of a
- large message.
- </doc>
-
- <rule name = "01">
- <doc>
- The server SHOULD interpret this method as meaning that the client is unable to
- process the message at this time.
- </doc>
- </rule>
-
- <!-- TODO: Rule split? -->
-
- <rule name = "02">
- <doc>
- A client MUST NOT use this method as a means of selecting messages to process. A
- rejected message MAY be discarded or dead-lettered, not necessarily passed to
- another client.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "requeue" domain = "bit" label = "requeue the message">
- <doc>
- If this field is zero, the message will be discarded. If this bit is 1, the
- server will attempt to requeue the message.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server MUST NOT deliver the message to the same client within the
- context of the current channel. The recommended strategy is to attempt to
- deliver the message to an alternative consumer, and if that is not possible,
- to move the message to a dead-letter queue. The server MAY use more
- sophisticated tracking to hold the message on the queue and redeliver it to
- the same client at a later stage.
- </doc>
- </rule>
- </field>
- </method>
- </class>
-
- <!-- == STREAM =========================================================== -->
-
- <class name = "stream" handler = "channel" index = "80" label = "work with streaming content">
- <doc>
- The stream class provides methods that support multimedia streaming. The stream class
- uses the following semantics: one message is one packet of data; delivery is
- unacknowleged and unreliable; the consumer can specify quality of service parameters
- that the server can try to adhere to; lower-priority messages may be discarded in favour
- of high priority messages.
- </doc>
-
- <doc type = "grammar">
- stream = C:QOS S:QOS-OK
- / C:CONSUME S:CONSUME-OK
- / C:CANCEL S:CANCEL-OK
- / C:PUBLISH content
- / S:RETURN
- / S:DELIVER content
- </doc>
-
- <chassis name = "server" implement = "MAY" />
- <chassis name = "client" implement = "MAY" />
-
- <rule name = "01">
- <doc>
- The server SHOULD discard stream messages on a priority basis if the queue size
- exceeds some configured limit.
- </doc>
- </rule>
-
- <rule name = "02">
- <!-- TODO: Rule split? -->
- <doc>
- The server MUST implement at least 2 priority levels for stream messages, where
- priorities 0-4 and 5-9 are treated as two distinct levels. The server MAY implement
- up to 10 priority levels.
- </doc>
- </rule>
-
- <rule name = "03">
- <doc>
- The server MUST implement automatic acknowledgements on stream content. That is, as
- soon as a message is delivered to a client via a Deliver method, the server must
- remove it from the queue.
- </doc>
- </rule>
-
- <!-- These are the properties for a Stream content -->
-
- <field name = "content-type" domain = "shortstr" label = "MIME content type" />
- <field name = "content-encoding" domain = "shortstr" label = "MIME content encoding" />
- <field name = "headers" domain = "table" label = "message header field table" />
- <field name = "priority" domain = "octet" label = "message priority, 0 to 9" />
- <field name = "timestamp" domain = "timestamp" label = "message timestamp" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "qos" synchronous = "1" index = "10" label = "specify quality of service">
- <doc>
- This method requests a specific quality of service. The QoS can be specified for the
- current channel or for all channels on the connection. The particular properties and
- semantics of a qos method always depend on the content class semantics. Though the
- qos method could in principle apply to both peers, it is currently meaningful only
- for the server.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "qos-ok" />
-
- <field name = "prefetch-size" domain = "long" label = "prefetch window in octets">
- <doc>
- The client can request that messages be sent in advance so that when the client
- finishes processing a message, the following message is already held locally,
- rather than needing to be sent down the channel. Prefetching gives a performance
- improvement. This field specifies the prefetch window size in octets. May be set
- to zero, meaning "no specific limit". Note that other prefetch limits may still
- apply.
- </doc>
- </field>
-
- <field name = "prefetch-count" domain = "short" label = "prefetch window in messages">
- <doc>
- Specifies a prefetch window in terms of whole messages. This field may be used
- in combination with the prefetch-size field; a message will only be sent in
- advance if both prefetch windows (and those at the channel and connection level)
- allow it.
- </doc>
- </field>
-
- <field name = "consume-rate" domain = "long" label = "transfer rate in octets/second">
- <doc>
- Specifies a desired transfer rate in octets per second. This is usually
- determined by the application that uses the streaming data. A value of zero
- means "no limit", i.e. as rapidly as possible.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The server MAY ignore the prefetch values and consume rates, depending on
- the type of stream and the ability of the server to queue and/or reply it.
- The server MAY drop low-priority messages in favour of high-priority
- messages.
- </doc>
- </rule>
- </field>
-
- <field name = "global" domain = "bit" label = "apply to entire connection">
- <doc>
- By default the QoS settings apply to the current channel only. If this field is
- set, they are applied to the entire connection.
- </doc>
- </field>
- </method>
-
- <method name = "qos-ok" synchronous = "1" index = "11" label = "confirm the requested qos">
- <doc>
- This method tells the client that the requested QoS levels could be handled by the
- server. The requested QoS applies to all active consumers until a new QoS is
- defined.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "consume" synchronous = "1" index = "20" label = "start a queue consumer">
- <doc>
- This method asks the server to start a "consumer", which is a transient request for
- messages from a specific queue. Consumers last as long as the channel they were
- created on, or until the client cancels them.
- </doc>
-
- <rule name = "01">
- <doc>
- The server SHOULD support at least 16 consumers per queue, unless the queue was
- declared as private, and ideally, impose no limit except as defined by available
- resources.
- </doc>
- </rule>
-
- <rule name = "02">
- <doc>
- Streaming applications SHOULD use different channels to select different
- streaming resolutions. AMQP makes no provision for filtering and/or transforming
- streams except on the basis of priority-based selective delivery of individual
- messages.
- </doc>
- </rule>
-
- <chassis name = "server" implement = "MUST" />
- <response name = "consume-ok" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "read" access rights to
- the realm for the queue.
- </doc>
- </rule>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue to consume from. If the queue name is null,
- refers to the current queue for the channel, which is the last declared queue.
- </doc>
-
- <rule name = "01">
- <doc>
- If the client did not previously declare a queue, and the queue name in this
- method is empty, the server MUST raise a connection exception with reply
- code 530 (not allowed).
- </doc>
- </rule>
- </field>
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>
- Specifies the identifier for the consumer. The consumer tag is local to a
- connection, so two clients can use the same consumer tags. If this field is
- empty the server will generate a unique tag.
- </doc>
-
- <rule name = "01">
- <!-- TODO: Rule split? -->
- <doc>
- The tag MUST NOT refer to an existing consumer. If the client attempts to
- create two consumers with the same non-empty tag the server MUST raise a
- connection exception with reply code 530 (not allowed).
- </doc>
- </rule>
- </field>
-
- <field name = "no-local" domain = "no-local" />
-
- <field name = "exclusive" domain = "bit" label = "request exclusive access">
- <doc>
- Request exclusive consumer access, meaning only this consumer can access the
- queue.
- </doc>
-
-
- <!-- Rule test name: was "amq_file_00" -->
- <rule name = "01">
- <doc>
- If the server cannot grant exclusive access to the queue when asked, -
- because there are other consumers active - it MUST raise a channel exception
- with return code 405 (resource locked).
- </doc>
- </rule>
- </field>
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "consume-ok" synchronous = "1" index = "21" label = "confirm a new consumer">
- <doc>
- This method provides the client with a consumer tag which it may use in methods that
- work with the consumer.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag">
- <doc>Holds the consumer tag specified by the client or provided by the server.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "cancel" synchronous = "1" index = "30" label = "end a queue consumer">
- <doc>
- This method cancels a consumer. Since message delivery is asynchronous the client
- may continue to receive messages for a short while after canceling a consumer. It
- may process or discard these as appropriate.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <response name = "cancel-ok" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "nowait" domain = "bit" label = "do not send a reply method">
- <doc>
- If set, the server will not respond to the method. The client should not wait
- for a reply method. If the server could not complete the method it will raise a
- channel or connection exception.
- </doc>
- </field>
- </method>
-
- <method name = "cancel-ok" synchronous = "1" index = "31" label = "confirm a cancelled consumer">
- <doc>This method confirms that the cancellation was completed.</doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "publish" content = "1" index = "40" label = "publish a message">
- <doc>
- This method publishes a message to a specific exchange. The message will be routed
- to queues as defined by the exchange configuration and distributed to any active
- consumers as appropriate.
- </doc>
-
- <chassis name = "server" implement = "MUST" />
-
- <field name = "ticket" domain = "access-ticket">
- <rule name = "01">
- <doc>
- The client MUST provide a valid access ticket giving "write" access rights
- to the access realm for the exchange.
- </doc>
- </rule>
- </field>
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange to publish to. The exchange name can be
- empty, meaning the default exchange. If the exchange name is specified, and that
- exchange does not exist, the server will raise a channel exception.
- </doc>
-
- <rule name = "01">
- <doc>
- The server MUST accept a blank exchange name to mean the default exchange.
- </doc>
- </rule>
-
- <rule name = "02">
- <doc>
- If the exchange was declared as an internal exchange, the server MUST
- respond with a reply code 403 (access refused) and raise a channel
- exception.
- </doc>
- </rule>
-
- <rule name = "03">
- <doc>
- The exchange MAY refuse stream content in which case it MUST respond with a
- reply code 540 (not implemented) and raise a channel exception.
- </doc>
- </rule>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>
- Specifies the routing key for the message. The routing key is used for routing
- messages depending on the exchange configuration.
- </doc>
- </field>
-
- <field name = "mandatory" domain = "bit" label = "indicate mandatory routing">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue. If this flag is set, the server will return an unroutable message with a
- Return method. If this flag is zero, the server silently drops the message.
- </doc>
-
- <!-- Rule test name: was "amq_stream_00" -->
- <rule name = "01">
- <doc>The server SHOULD implement the mandatory flag.</doc>
- </rule>
- </field>
-
- <field name = "immediate" domain = "bit" label = "request immediate delivery">
- <doc>
- This flag tells the server how to react if the message cannot be routed to a
- queue consumer immediately. If this flag is set, the server will return an
- undeliverable message with a Return method. If this flag is zero, the server
- will queue the message, but with no guarantee that it will ever be consumed.
- </doc>
-
- <!-- Rule test name: was "amq_stream_00" -->
- <rule name = "01">
- <doc>The server SHOULD implement the immediate flag.</doc>
- </rule>
- </field>
- </method>
-
- <method name = "return" content = "1" index = "50" label = "return a failed message">
- <doc>
- This method returns an undeliverable message that was published with the "immediate"
- flag set, or an unroutable message published with the "mandatory" flag set. The
- reply code and text provide information about the reason that the message was
- undeliverable.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "reply-code" domain = "reply-code" />
-
- <field name = "reply-text" domain = "reply-text" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "routing-key" domain = "shortstr" label = "Message routing key">
- <doc>Specifies the routing key name specified when the message was published.</doc>
- </field>
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "deliver" content = "1" index = "60"
- label = "notify the client of a consumer message">
- <doc>
- This method delivers a message to the client, via a consumer. In the asynchronous
- message delivery model, the client starts a consumer using the Consume method, then
- the server responds with Deliver methods as and when messages arrive for that
- consumer.
- </doc>
-
- <chassis name = "client" implement = "MUST" />
-
- <field name = "consumer-tag" domain = "consumer-tag" />
-
- <field name = "delivery-tag" domain = "delivery-tag" />
-
- <field name = "exchange" domain = "exchange-name">
- <doc>
- Specifies the name of the exchange that the message was originally published to.
- </doc>
- </field>
-
- <field name = "queue" domain = "queue-name">
- <doc>
- Specifies the name of the queue that the message came from. Note that a single
- channel can start many consumers on different queues.
- </doc>
- <assert check = "notnull" />
- </field>
- </method>
- </class>
-
- <!-- == TX =============================================================== -->
-
- <class name = "tx" handler = "channel" index = "90" label = "work with standard transactions">
- <doc>
- Standard transactions provide so-called "1.5 phase commit". We can ensure that work is
- never lost, but there is a chance of confirmations being lost, so that messages may be
- resent. Applications that use standard transactions must be able to detect and ignore
- duplicate messages.
- </doc>
-
- <!-- TODO: Rule split? -->
-
- <rule name = "01">
- <doc>
- An client using standard transactions SHOULD be able to track all messages received
- within a reasonable period, and thus detect and reject duplicates of the same
- message. It SHOULD NOT pass these to the application layer.
- </doc>
- </rule>
-
- <doc type = "grammar">
- tx = C:SELECT S:SELECT-OK
- / C:COMMIT S:COMMIT-OK
- / C:ROLLBACK S:ROLLBACK-OK
- </doc>
-
- <chassis name = "server" implement = "SHOULD" />
- <chassis name = "client" implement = "MAY" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "select" synchronous = "1" index = "10" label = "select standard transaction mode">
- <doc>
- This method sets the channel to use standard transactions. The client must use this
- method at least once on a channel before using the Commit or Rollback methods.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "select-ok" />
- </method>
-
- <method name = "select-ok" synchronous = "1" index = "11" label = "confirm transaction mode">
- <doc>
- This method confirms to the client that the channel was successfully set to use
- standard transactions.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "commit" synchronous = "1" index = "20" label = "commit the current transaction">
- <doc>
- This method commits all messages published and acknowledged in the current
- transaction. A new transaction starts immediately after a commit.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "commit-ok" />
- </method>
-
- <method name = "commit-ok" synchronous = "1" index = "21" label = "confirm a successful commit">
- <doc>
- This method confirms to the client that the commit succeeded. Note that if a commit
- fails, the server raises a channel exception.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "rollback" synchronous = "1" index = "30"
- label = "abandon the current transaction">
- <doc>
- This method abandons all messages published and acknowledged in the current
- transaction. A new transaction starts immediately after a rollback.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "rollback-ok" />
- </method>
-
- <method name = "rollback-ok" synchronous = "1" index = "31" label = "confirm successful rollback">
- <doc>
- This method confirms to the client that the rollback succeeded. Note that if an
- rollback fails, the server raises a channel exception.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
- </class>
-
- <!-- == DTX ============================================================== -->
-
- <class name = "dtx" handler = "channel" index = "100" label = "work with distributed transactions">
- <doc>
- Distributed transactions provide so-called "2-phase commit". The AMQP distributed
- transaction model supports the X-Open XA architecture and other distributed transaction
- implementations. The Dtx class assumes that the server has a private communications
- channel (not AMQP) to a distributed transaction coordinator.
- </doc>
-
- <doc type = "grammar">
- dtx = C:SELECT S:SELECT-OK
- C:START S:START-OK
- </doc>
-
- <chassis name = "server" implement = "MAY" />
- <chassis name = "client" implement = "MAY" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "select" synchronous = "1" index = "10" label = "select standard transaction mode">
- <doc>
- This method sets the channel to use distributed transactions. The client must use
- this method at least once on a channel before using the Start method.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <response name = "select-ok" />
- </method>
-
- <method name = "select-ok" synchronous = "1" index = "11" label = "confirm transaction mode">
- <doc>
- This method confirms to the client that the channel was successfully set to use
- distributed transactions.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "start" synchronous = "1" index = "20"
- label = "start a new distributed transaction">
- <doc>
- This method starts a new distributed transaction. This must be the first method on a
- new channel that uses the distributed transaction mode, before any methods that
- publish or consume messages.
- </doc>
- <chassis name = "server" implement = "MAY" />
- <response name = "start-ok" />
- <field name = "dtx-identifier" domain = "shortstr" label = "transaction identifier">
- <doc>
- The distributed transaction key. This identifies the transaction so that the
- AMQP server can coordinate with the distributed transaction coordinator.
- </doc>
- <assert check = "notnull" />
- </field>
- </method>
-
- <method name = "start-ok" synchronous = "1" index = "21"
- label = "confirm the start of a new distributed transaction">
- <doc>
- This method confirms to the client that the transaction started. Note that if a
- start fails, the server raises a channel exception.
- </doc>
- <chassis name = "client" implement = "MUST" />
- </method>
- </class>
-
- <!-- == TUNNEL =========================================================== -->
-
- <class name = "tunnel" handler = "tunnel" index = "110" label = "methods for protocol tunneling">
- <doc>
- The tunnel methods are used to send blocks of binary data - which can be serialised AMQP
- methods or other protocol frames - between AMQP peers.
- </doc>
-
- <doc type = "grammar">
- tunnel = C:REQUEST
- / S:REQUEST
- </doc>
-
- <chassis name = "server" implement = "MAY" />
- <chassis name = "client" implement = "MAY" />
-
- <field name = "headers" domain = "table" label = "message header field table" />
- <field name = "proxy-name" domain = "shortstr" label = "identity of tunnelling proxy" />
- <field name = "data-name" domain = "shortstr" label = "name or type of message being tunnelled" />
- <field name = "durable" domain = "octet" label = "message durability indicator" />
- <field name = "broadcast" domain = "octet" label = "message broadcast mode" />
-
- <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
-
- <method name = "request" content = "1" index = "10" label = "sends a tunnelled method">
- <doc>
- This method tunnels a block of binary data, which can be an encoded
- AMQP method or other data. The binary data is sent as the content for
- the Tunnel.Request method.
- </doc>
- <chassis name = "server" implement = "MUST" />
- <field name = "meta-data" domain = "table" label = "meta data for the tunnelled block">
- <doc>
- This field table holds arbitrary meta-data that the sender needs to
- pass to the recipient.
- </doc>
- </field>
- </method>
- </class>
-</amqp>
diff --git a/gentools/xml-src/cluster-0.9.test.xml b/gentools/xml-src/cluster-0.9.test.xml
deleted file mode 100644
index 142e6c9380..0000000000
--- a/gentools/xml-src/cluster-0.9.test.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?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.
- -
- -->
-
-<amqp major="0" minor="9" port="5672" comment="AMQ protocol 0.80">
-
-<class name = "cluster" index = "101">
-
-<doc>
- An extension that allows brokers to communicate in order to
- provide a clustered service to clients.
-</doc>
-
-<method name = "join" index="10">
- <field name = "broker" type = "shortstr" />
-</method>
-
-<method name = "membership" index="20">
- <field name = "members" type = "longstr" />
-</method>
-
-<method name = "synch" index="30">
-</method>
-
-<method name = "leave" index="40">
- <field name = "broker" type = "shortstr" />
-</method>
-
-<method name = "suspect" index="50">
- <field name = "broker" type = "shortstr" />
-</method>
-
-<method name = "ping" index="60">
- <field name = "broker" type = "shortstr" />
- <field name = "load" type = "long" />
- <field name = "response required" type = "bit" />
-</method>
-
-</class>
-
-</amqp>
diff --git a/java/.gitignore b/java/.gitignore
index 417b51f12d..d995501f21 100644
--- a/java/.gitignore
+++ b/java/.gitignore
@@ -18,3 +18,4 @@
#
*.swp
eclipse-projects/*
+derby.log
diff --git a/java/amqp-1-0-client-jms/build.xml b/java/amqp-1-0-client-jms/build.xml
index cfc6e0babe..d501be1d8d 100644
--- a/java/amqp-1-0-client-jms/build.xml
+++ b/java/amqp-1-0-client-jms/build.xml
@@ -24,6 +24,9 @@
<property name="module.depends" value="amqp-1-0-common amqp-1-0-client"/>
<property name="module.genpom.args" value="-Sgeronimo-jms_1.1_spec=provided"/>
+ <property name="example.src.dir" value="${project.root}/amqp-1-0-client-jms/example/src/main/java" />
+ <property name="example.jar.file" value="${build.lib}/qpid-amqp-1-0-client-jms-example-${project.version}.jar" />
+
<target name="release-bin-copy-readme">
<copy todir="${module.release}" overwrite="true" failonerror="true">
diff --git a/java/amqp-1-0-client-jms/example/build.xml b/java/amqp-1-0-client-jms/example/build.xml
new file mode 100644
index 0000000000..cb9ab0994c
--- /dev/null
+++ b/java/amqp-1-0-client-jms/example/build.xml
@@ -0,0 +1,28 @@
+<!--
+ -
+ - 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="AMQ 1.0 JMS Client Example" default="build">
+
+ <property name="module.depends" value="amqp-1-0-client-jms amqp-1-0-client amqp-1-0-common"/>
+ <property name="module.test.depends" value=""/>
+
+ <import file="../../module.xml"/>
+
+</project>
diff --git a/java/amqp-1-0-client-jms/resources/LICENSE b/java/amqp-1-0-client-jms/resources/LICENSE
new file mode 100644
index 0000000000..de4b130f35
--- /dev/null
+++ b/java/amqp-1-0-client-jms/resources/LICENSE
@@ -0,0 +1,204 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
diff --git a/java/amqp-1-0-client-jms/resources/NOTICE b/java/amqp-1-0-client-jms/resources/NOTICE
new file mode 100644
index 0000000000..8d1c3f3122
--- /dev/null
+++ b/java/amqp-1-0-client-jms/resources/NOTICE
@@ -0,0 +1,5 @@
+Apache Qpid
+Copyright 2006-2012 Apache Software Foundation
+This product includes software developed at
+Apache Software Foundation (http://www.apache.org/)
+
diff --git a/java/amqp-1-0-client-jms/resources/README.txt b/java/amqp-1-0-client-jms/resources/README.txt
new file mode 100644
index 0000000000..35d25050fe
--- /dev/null
+++ b/java/amqp-1-0-client-jms/resources/README.txt
@@ -0,0 +1,7 @@
+
+Documentation
+--------------
+All of our user documentation can be accessed at:
+
+http://qpid.apache.org/documentation.html
+
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionFactoryImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionFactoryImpl.java
index d9e6dfe36d..4856a7c491 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionFactoryImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionFactoryImpl.java
@@ -20,8 +20,12 @@
*/
package org.apache.qpid.amqp_1_0.jms.impl;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.net.URLStreamHandler;
import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
@@ -39,6 +43,8 @@ public class ConnectionFactoryImpl implements ConnectionFactory, TopicConnection
private String _remoteHost;
private boolean _ssl;
+ private String _queuePrefix;
+ private String _topicPrefix;
public ConnectionFactoryImpl(final String host,
final int port,
@@ -86,36 +92,70 @@ public class ConnectionFactoryImpl implements ConnectionFactory, TopicConnection
public ConnectionImpl createConnection() throws JMSException
{
- return new ConnectionImpl(_host, _port, _username, _password, _clientId, _remoteHost, _ssl);
+ return createConnection(_username, _password);
}
public ConnectionImpl createConnection(final String username, final String password) throws JMSException
{
- return new ConnectionImpl(_host, _port, username, password, _clientId, _remoteHost, _ssl);
+ ConnectionImpl connection = new ConnectionImpl(_host, _port, username, password, _clientId, _remoteHost, _ssl);
+ connection.setQueuePrefix(_queuePrefix);
+ connection.setTopicPrefix(_topicPrefix);
+ return connection;
}
public static ConnectionFactoryImpl createFromURL(final String urlString) throws MalformedURLException
{
- URL url = new URL(urlString);
+ URL url = new URL(null, urlString, new URLStreamHandler()
+ {
+ @Override
+ protected URLConnection openConnection(URL u) throws IOException
+ {
+ throw new UnsupportedOperationException();
+ }
+ });
+ String protocol = url.getProtocol();
+ if(protocol == null || "".equals(protocol))
+ {
+ protocol = "amqp";
+ }
+ else if(!protocol.equals("amqp") && !protocol.equals("amqps"))
+ {
+ throw new MalformedURLException("Protocol '"+protocol+"' unknown. Must be one of 'amqp' or 'amqps'.");
+ }
String host = url.getHost();
int port = url.getPort();
+
+ boolean ssl = false;
+
if(port == -1)
{
- port = 5672;
+ if("amqps".equals(protocol))
+ {
+ port = 5671;
+ ssl = true;
+ }
+ else
+ {
+ port = 5672;
+ }
}
+ else if("amqps".equals(protocol))
+ {
+ ssl = true;
+ }
+
String userInfo = url.getUserInfo();
String username = null;
String password = null;
String clientId = null;
String remoteHost = null;
- boolean ssl = false;
if(userInfo != null)
{
String[] components = userInfo.split(":",2);
- username = components[0];
+ username = URLDecoder.decode(components[0]);
if(components.length == 2)
{
- password = components[1];
+ password = URLDecoder.decode(components[1]);
}
}
String query = url.getQuery();
@@ -139,6 +179,11 @@ public class ConnectionFactoryImpl implements ConnectionFactory, TopicConnection
}
}
+ if(remoteHost == null)
+ {
+ remoteHost = host;
+ }
+
return new ConnectionFactoryImpl(host, port, username, password, clientId, remoteHost, ssl);
}
@@ -170,4 +215,24 @@ public class ConnectionFactoryImpl implements ConnectionFactory, TopicConnection
connection.setTopicConnection(true);
return connection;
}
+
+ public String getTopicPrefix()
+ {
+ return _topicPrefix;
+ }
+
+ public void setTopicPrefix(String topicPrefix)
+ {
+ _topicPrefix = topicPrefix;
+ }
+
+ public String getQueuePrefix()
+ {
+ return _queuePrefix;
+ }
+
+ public void setQueuePrefix(String queuePrefix)
+ {
+ _queuePrefix = queuePrefix;
+ }
}
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionImpl.java
index 587b12b51a..be1c2d6514 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ConnectionImpl.java
@@ -25,9 +25,8 @@ import org.apache.qpid.amqp_1_0.transport.Container;
import javax.jms.*;
import javax.jms.IllegalStateException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import javax.jms.Queue;
+import java.util.*;
public class ConnectionImpl implements Connection, QueueConnection, TopicConnection
{
@@ -43,16 +42,26 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
private boolean _isQueueConnection;
private boolean _isTopicConnection;
private final Collection<CloseTask> _closeTasks = new ArrayList<CloseTask>();
+ private final String _host;
+ private final int _port;
+ private final String _username;
+ private final String _password;
+ private final String _remoteHost;
+ private final boolean _ssl;
+ private String _clientId;
+ private String _queuePrefix;
+ private String _topicPrefix;
private static enum State
{
+ UNCONNECTED,
STOPPED,
STARTED,
CLOSED
}
- private volatile State _state = State.STOPPED;
+ private volatile State _state = State.UNCONNECTED;
public ConnectionImpl(String host, int port, String username, String password, String clientId) throws JMSException
{
@@ -66,20 +75,52 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
public ConnectionImpl(String host, int port, String username, String password, String clientId, String remoteHost, boolean ssl) throws JMSException
{
- Container container = clientId == null ? new Container() : new Container(clientId);
- // TODO - authentication, containerId, clientId, ssl?, etc
- try
+ _host = host;
+ _port = port;
+ _username = username;
+ _password = password;
+ _clientId = clientId;
+ _remoteHost = remoteHost;
+ _ssl = ssl;
+ }
+
+ private void connect() throws JMSException
+ {
+ synchronized(_lock)
{
- _conn = new org.apache.qpid.amqp_1_0.client.Connection(host, port, username, password, container, remoteHost, ssl);
- // TODO - retrieve negotiated AMQP version
- _connectionMetaData = new ConnectionMetaDataImpl(1,0,0);
+ // already connected?
+ if( _state == State.UNCONNECTED )
+ {
+ _state = State.STOPPED;
+
+ Container container = _clientId == null ? new Container() : new Container(_clientId);
+ // TODO - authentication, containerId, clientId, ssl?, etc
+ try
+ {
+ _conn = new org.apache.qpid.amqp_1_0.client.Connection(_host,
+ _port, _username, _password, container, _remoteHost, _ssl);
+ // TODO - retrieve negotiated AMQP version
+ _connectionMetaData = new ConnectionMetaDataImpl(1,0,0);
+ }
+ catch (org.apache.qpid.amqp_1_0.client.Connection.ConnectionException e)
+ {
+ JMSException jmsEx = new JMSException(e.getMessage());
+ jmsEx.setLinkedException(e);
+ jmsEx.initCause(e);
+ throw jmsEx;
+ }
+ }
}
- catch (org.apache.qpid.amqp_1_0.client.Connection.ConnectionException e)
+ }
+
+ private void checkNotConnected(String msg) throws IllegalStateException
+ {
+ synchronized(_lock)
{
- JMSException jmsEx = new JMSException(e.getMessage());
- jmsEx.setLinkedException(e);
- jmsEx.initCause(e);
- throw jmsEx;
+ if( _state != State.UNCONNECTED )
+ {
+ throw new IllegalStateException(msg);
+ }
}
}
@@ -111,7 +152,7 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
{
throw new IllegalStateException("Cannot create a session on a closed connection");
}
-
+ connect();
SessionImpl session = new SessionImpl(this, acknowledgeMode);
session.setQueueSession(_isQueueConnection);
session.setTopicSession(_isTopicConnection);
@@ -125,14 +166,19 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
public String getClientID() throws JMSException
{
checkClosed();
- return _conn.getEndpoint().getContainer().getId();
+ return _clientId;
}
- public void setClientID(final String s) throws JMSException
+ public void setClientID(final String value) throws JMSException
{
- throw new IllegalStateException("Cannot set client-id to \""
- + s
- + "\"; client-id must be set on connection creation");
+ checkNotConnected("Cannot set client-id to \""
+ + value
+ + "\"; client-id must be set before the connection is used");
+ if( _clientId !=null )
+ {
+ throw new IllegalStateException("client-id has already been set");
+ }
+ _clientId = value;
}
public ConnectionMetaData getMetaData() throws JMSException
@@ -158,6 +204,7 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
synchronized(_lock)
{
checkClosed();
+ connect();
if(_state == State.STOPPED)
{
// TODO
@@ -187,6 +234,7 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
{
session.stop();
}
+ case UNCONNECTED:
_state = State.STOPPED;
break;
case CLOSED:
@@ -235,7 +283,9 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
{
task.onClose();
}
- _conn.close();
+ if(_conn != null && _state != State.UNCONNECTED ) {
+ _conn.close();
+ }
_state = State.CLOSED;
}
@@ -282,6 +332,10 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
final int i) throws JMSException
{
checkClosed();
+ if (_isQueueConnection)
+ {
+ throw new IllegalStateException("QueueConnection cannot be used to create Pub/Sub based resources.");
+ }
return null; //TODO
}
@@ -326,4 +380,78 @@ public class ConnectionImpl implements Connection, QueueConnection, TopicConnect
{
_isTopicConnection = topicConnection;
}
+
+ public String getTopicPrefix()
+ {
+ return _topicPrefix;
+ }
+
+ public void setTopicPrefix(String topicPrefix)
+ {
+ _topicPrefix = topicPrefix;
+ }
+
+ public String getQueuePrefix()
+ {
+ return _queuePrefix;
+ }
+
+ public void setQueuePrefix(String queueprefix)
+ {
+ _queuePrefix = queueprefix;
+ }
+
+ DecodedDestination toDecodedDestination(DestinationImpl dest)
+ {
+ String address = dest.getAddress();
+ Set<String> kind = null;
+ Class clazz = dest.getClass();
+ if( clazz==QueueImpl.class )
+ {
+ kind = MessageImpl.JMS_QUEUE_ATTRIBUTES;
+ if( _queuePrefix!=null )
+ {
+ // Avoid double prefixing..
+ if( !address.startsWith(_queuePrefix) )
+ {
+ address = _queuePrefix+address;
+ }
+ }
+ }
+ else if( clazz==TopicImpl.class )
+ {
+ kind = MessageImpl.JMS_TOPIC_ATTRIBUTES;
+ if( _topicPrefix!=null )
+ {
+ // Avoid double prefixing..
+ if( !address.startsWith(_topicPrefix) )
+ {
+ address = _topicPrefix+address;
+ }
+ }
+ }
+ else if( clazz==TemporaryQueueImpl.class )
+ {
+ kind = MessageImpl.JMS_TEMP_QUEUE_ATTRIBUTES;
+ }
+ else if( clazz==TemporaryTopicImpl.class )
+ {
+ kind = MessageImpl.JMS_TEMP_TOPIC_ATTRIBUTES;
+ }
+ return new DecodedDestination(address, kind);
+ }
+
+ DecodedDestination toDecodedDestination(String address, Set<String> kind)
+ {
+ if( (kind == null || kind.equals(MessageImpl.JMS_QUEUE_ATTRIBUTES)) && _queuePrefix!=null && address.startsWith(_queuePrefix))
+ {
+ return new DecodedDestination(address.substring(_queuePrefix.length()), MessageImpl.JMS_QUEUE_ATTRIBUTES);
+ }
+ if( (kind == null || kind.equals(MessageImpl.JMS_TOPIC_ATTRIBUTES)) && _topicPrefix!=null && address.startsWith(_topicPrefix))
+ {
+ return new DecodedDestination(address.substring(_topicPrefix.length()), MessageImpl.JMS_TOPIC_ATTRIBUTES);
+ }
+ return new DecodedDestination(address, kind);
+ }
+
}
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/DecodedDestination.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/DecodedDestination.java
new file mode 100644
index 0000000000..74e98c2163
--- /dev/null
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/DecodedDestination.java
@@ -0,0 +1,47 @@
+/*
+ * 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.amqp_1_0.jms.impl;
+
+import java.util.Set;
+
+/**
+* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+*/
+class DecodedDestination
+{
+ private final String _address;
+ private final Set<String> _attributes;
+
+ DecodedDestination(String address, Set<String> kind)
+ {
+ _address = address;
+ _attributes = kind;
+ }
+
+ public String getAddress()
+ {
+ return _address;
+ }
+
+ public Set<String> getAttributes()
+ {
+ return _attributes;
+ }
+}
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageConsumerImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageConsumerImpl.java
index e0402cd0a7..3c15c74d6f 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageConsumerImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageConsumerImpl.java
@@ -127,7 +127,7 @@ public class MessageConsumerImpl implements MessageConsumer, QueueReceiver, Topi
{
try
{
- return _session.getClientSession(). createReceiver(_destination.getAddress(), AcknowledgeMode.ALO,
+ return _session.getClientSession(). createReceiver(_session.toAddress(_destination), AcknowledgeMode.ALO,
_linkName, _durable, getFilters(), null);
}
catch (AmqpErrorException e)
@@ -316,9 +316,9 @@ public class MessageConsumerImpl implements MessageConsumer, QueueReceiver, Topi
_lastUnackedMessage = deliveryTag;
}
- void preReceiveAction(final org.apache.qpid.amqp_1_0.client.Message msg) throws IllegalStateException
+ void preReceiveAction(final org.apache.qpid.amqp_1_0.client.Message msg)
{
- final int acknowledgeMode = _session.getAcknowledgeMode();
+ int acknowledgeMode = _session.getAckModeEnum().ordinal();
if(acknowledgeMode == Session.AUTO_ACKNOWLEDGE
|| acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageImpl.java
index f1056b94fd..fba50c5477 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageImpl.java
@@ -50,14 +50,24 @@ public abstract class MessageImpl implements Message
static final Set<Class> _supportedClasses =
new HashSet<Class>(Arrays.asList(Boolean.class, Byte.class, Short.class, Integer.class, Long.class,
Float.class, Double.class, Character.class, String.class, byte[].class));
- private static final Symbol JMS_TYPE = Symbol.valueOf("x-opt-jms-type");
+ static final Symbol JMS_TYPE = Symbol.valueOf("x-opt-jms-type");
+ static final Symbol TO_TYPE = Symbol.valueOf("x-opt-to-type");
+ static final Symbol REPLY_TO_TYPE = Symbol.valueOf("x-opt-reply-type");
+
+ static final String QUEUE_ATTRIBUTE = "queue";
+ static final String TOPIC_ATTRIBUTE = "topic";
+ static final String TEMPORARY_ATTRIBUTE = "temporary";
+
+ static final Set<String> JMS_QUEUE_ATTRIBUTES = set(QUEUE_ATTRIBUTE);
+ static final Set<String> JMS_TOPIC_ATTRIBUTES = set(TOPIC_ATTRIBUTE);
+ static final Set<String> JMS_TEMP_QUEUE_ATTRIBUTES = set(QUEUE_ATTRIBUTE, TEMPORARY_ATTRIBUTE);
+ static final Set<String> JMS_TEMP_TOPIC_ATTRIBUTES = set(TOPIC_ATTRIBUTE, TEMPORARY_ATTRIBUTE);
private Header _header;
private Properties _properties;
private ApplicationProperties _applicationProperties;
private Footer _footer;
- public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
- private SessionImpl _sessionImpl;
+ private final SessionImpl _sessionImpl;
private boolean _readOnly;
private MessageAnnotations _messageAnnotations;
@@ -171,45 +181,53 @@ public abstract class MessageImpl implements Message
public DestinationImpl getJMSReplyTo() throws JMSException
{
- return DestinationImpl.valueOf(getReplyTo());
+ return toDestination(getReplyTo(), splitCommaSeparateSet((String) getMessageAnnotation(REPLY_TO_TYPE)));
}
public void setJMSReplyTo(Destination destination) throws NonAMQPDestinationException
{
- if(destination == null)
+ if( destination==null )
{
setReplyTo(null);
- }
- else if (destination instanceof org.apache.qpid.amqp_1_0.jms.Destination)
- {
- setReplyTo(((org.apache.qpid.amqp_1_0.jms.Destination)destination).getAddress());
+ messageAnnotationMap().remove(REPLY_TO_TYPE);
}
else
{
- throw new NonAMQPDestinationException(destination);
+ DecodedDestination dd = toDecodedDestination(destination);
+ setReplyTo(dd.getAddress());
+ messageAnnotationMap().put(REPLY_TO_TYPE, join(",", dd.getAttributes()));
}
}
public DestinationImpl getJMSDestination() throws JMSException
{
- return _isFromQueue ? QueueImpl.valueOf(getTo())
- : _isFromTopic ? TopicImpl.valueOf(getTo())
- : DestinationImpl.valueOf(getTo());
+ Set<String> type = splitCommaSeparateSet((String) getMessageAnnotation(TO_TYPE));
+ if( type==null )
+ {
+ if( _isFromQueue )
+ {
+ type = JMS_QUEUE_ATTRIBUTES;
+ }
+ else if( _isFromTopic )
+ {
+ type = JMS_TOPIC_ATTRIBUTES;
+ }
+ }
+ return toDestination(getTo(), type);
}
public void setJMSDestination(Destination destination) throws NonAMQPDestinationException
{
- if(destination == null)
+ if( destination==null )
{
setTo(null);
- }
- else if (destination instanceof org.apache.qpid.amqp_1_0.jms.Destination)
- {
- setTo(((org.apache.qpid.amqp_1_0.jms.Destination)destination).getAddress());
+ messageAnnotationMap().remove(TO_TYPE);
}
else
{
- throw new NonAMQPDestinationException(destination);
+ DecodedDestination dd = toDecodedDestination(destination);
+ setTo(dd.getAddress());
+ messageAnnotationMap().put(TO_TYPE, join(",", dd.getAttributes()));
}
}
@@ -264,22 +282,13 @@ public abstract class MessageImpl implements Message
public String getJMSType() throws JMSException
{
- Map messageAttrs = _messageAnnotations == null ? null : _messageAnnotations.getValue();
- final Object attrValue = messageAttrs == null ? null : messageAttrs.get(JMS_TYPE);
-
+ final Object attrValue = getMessageAnnotation(JMS_TYPE);
return attrValue instanceof String ? attrValue.toString() : null;
}
public void setJMSType(String s) throws JMSException
{
- Map messageAttrs = _messageAnnotations == null ? null : _messageAnnotations.getValue();
- if(messageAttrs == null)
- {
- messageAttrs = new HashMap();
- _messageAnnotations = new MessageAnnotations(messageAttrs);
- }
-
- messageAttrs.put(JMS_TYPE, s);
+ messageAnnotationMap().put(JMS_TYPE, s);
}
public long getJMSExpiration() throws JMSException
@@ -1206,4 +1215,118 @@ public abstract class MessageImpl implements Message
}
abstract Collection<Section> getSections();
+
+ DecodedDestination toDecodedDestination(Destination destination) throws NonAMQPDestinationException
+ {
+ if(destination == null)
+ {
+ return null;
+ }
+ if (destination instanceof DestinationImpl)
+ {
+ return _sessionImpl.getConnection().toDecodedDestination((DestinationImpl) destination);
+ }
+ throw new NonAMQPDestinationException(destination);
+ }
+
+ DestinationImpl toDestination(String address, Set<String> kind)
+ {
+ if( address == null )
+ {
+ return null;
+ }
+
+ // If destination prefixes are in play, we have to strip the the prefix, and we might
+ // be able to infer the kind, if we don't know it yet.
+ DecodedDestination decoded = _sessionImpl.getConnection().toDecodedDestination(address, kind);
+ address = decoded.getAddress();
+ kind = decoded.getAttributes();
+
+ if( kind == null )
+ {
+ return DestinationImpl.valueOf(address);
+ }
+ if( kind.contains(QUEUE_ATTRIBUTE) )
+ {
+ if( kind.contains(TEMPORARY_ATTRIBUTE) )
+ {
+ return new TemporaryQueueImpl(address, null, _sessionImpl);
+ }
+ else
+ {
+ return QueueImpl.valueOf(address);
+ }
+ }
+ else if ( kind.contains(TOPIC_ATTRIBUTE) )
+ {
+ if( kind.contains(TEMPORARY_ATTRIBUTE) )
+ {
+ return new TemporaryTopicImpl(address, null, _sessionImpl);
+ }
+ else
+ {
+ return TopicImpl.valueOf(address);
+ }
+ }
+
+ return DestinationImpl.valueOf(address);
+ }
+
+ private Object getMessageAnnotation(Symbol key)
+ {
+ Map messageAttrs = _messageAnnotations == null ? null : _messageAnnotations.getValue();
+ return messageAttrs == null ? null : messageAttrs.get(key);
+ }
+
+ private Map messageAnnotationMap()
+ {
+ Map messageAttrs = _messageAnnotations == null ? null : _messageAnnotations.getValue();
+ if(messageAttrs == null)
+ {
+ messageAttrs = new HashMap();
+ _messageAnnotations = new MessageAnnotations(messageAttrs);
+ }
+ return messageAttrs;
+ }
+
+ Set<String> splitCommaSeparateSet(String value)
+ {
+ if( value == null )
+ {
+ return null;
+ }
+ HashSet<String> rc = new HashSet<String>();
+ for( String x: value.split("\\s*,\\s*") )
+ {
+ rc.add(x);
+ }
+ return rc;
+ }
+
+ private static Set<String> set(String ...args)
+ {
+ HashSet<String> s = new HashSet<String>();
+ for (String arg : args)
+ {
+ s.add(arg);
+ }
+ return Collections.unmodifiableSet(s);
+ }
+
+ static final String join(String sep, Iterable items)
+ {
+ StringBuilder result = new StringBuilder();
+
+ for (Object o : items)
+ {
+ if (result.length() > 0)
+ {
+ result.append(sep);
+ }
+ result.append(o.toString());
+ }
+
+ return result.toString();
+ }
+
}
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageProducerImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageProducerImpl.java
index 5bb8845eb7..badc20472b 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageProducerImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/MessageProducerImpl.java
@@ -20,7 +20,6 @@ package org.apache.qpid.amqp_1_0.jms.impl;
import org.apache.qpid.amqp_1_0.client.Sender;
import org.apache.qpid.amqp_1_0.jms.MessageProducer;
-import org.apache.qpid.amqp_1_0.jms.Queue;
import org.apache.qpid.amqp_1_0.jms.QueueSender;
import org.apache.qpid.amqp_1_0.jms.TemporaryDestination;
import org.apache.qpid.amqp_1_0.jms.TopicPublisher;
@@ -61,7 +60,7 @@ public class MessageProducerImpl implements MessageProducer, QueueSender, TopicP
{
try
{
- _sender = _session.getClientSession().createSender(_destination.getAddress());
+ _sender = _session.getClientSession().createSender(_session.toAddress(_destination));
}
catch (Sender.SenderCreationException e)
{
@@ -297,7 +296,7 @@ public class MessageProducerImpl implements MessageProducer, QueueSender, TopicP
try
{
_destination = (DestinationImpl) destination;
- _sender = _session.getClientSession().createSender(_destination.getAddress());
+ _sender = _session.getClientSession().createSender(_session.toAddress(_destination));
send(message, deliveryMode, priority, ttl);
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ObjectMessageImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ObjectMessageImpl.java
index 2a52b0557a..95c1497d07 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ObjectMessageImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/ObjectMessageImpl.java
@@ -40,7 +40,25 @@ public class ObjectMessageImpl extends MessageImpl implements ObjectMessage
{
static final Symbol CONTENT_TYPE = Symbol.valueOf("application/x-java-serialized-object");
- private Data _objectData;
+ static final Data NULL_OBJECT_DATA;
+ static
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try
+ {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(null);
+ oos.flush();
+ oos.close();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ NULL_OBJECT_DATA = new Data(new Binary(baos.toByteArray()));
+ }
+
+ private Data _objectData = NULL_OBJECT_DATA;
protected ObjectMessageImpl(Header header,
MessageAnnotations messageAnnotations,
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueBrowserImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueBrowserImpl.java
index 527e82eaed..8fab315b10 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueBrowserImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueBrowserImpl.java
@@ -18,9 +18,7 @@
*/
package org.apache.qpid.amqp_1_0.jms.impl;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Map;
+import java.util.*;
import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
import org.apache.qpid.amqp_1_0.client.AcknowledgeMode;
@@ -29,6 +27,7 @@ import org.apache.qpid.amqp_1_0.client.Receiver;
import org.apache.qpid.amqp_1_0.jms.QueueBrowser;
import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
import org.apache.qpid.amqp_1_0.type.Symbol;
+import org.apache.qpid.amqp_1_0.type.UnsignedInteger;
import org.apache.qpid.amqp_1_0.type.messaging.Filter;
import org.apache.qpid.amqp_1_0.type.messaging.JMSSelectorFilter;
import org.apache.qpid.amqp_1_0.type.messaging.StdDistMode;
@@ -39,49 +38,27 @@ public class QueueBrowserImpl implements QueueBrowser
private static final String JMS_SELECTOR = "jms-selector";
private QueueImpl _queue;
private String _selector;
- private Receiver _receiver;
- private Message _nextElement;
- private MessageEnumeration _enumeration;
+ private final SessionImpl _session;
+ private Map<Symbol, Filter> _filters;
+ private HashSet<MessageEnumeration> _enumerations = new HashSet<MessageEnumeration>();
+ private boolean _closed;
QueueBrowserImpl(final QueueImpl queue, final String selector, SessionImpl session) throws JMSException
{
_queue = queue;
_selector = selector;
+ _session = session;
- Map<Symbol, Filter> filters;
if(selector == null || selector.trim().equals(""))
{
- filters = null;
+ _filters = null;
}
else
{
- filters = Collections.singletonMap(Symbol.valueOf(JMS_SELECTOR),(Filter) new JMSSelectorFilter(_selector));
- }
-
-
- try
- {
- _receiver = session.getClientSession().createReceiver(queue.getAddress(),
- StdDistMode.COPY,
- AcknowledgeMode.AMO,null,
- false,
- filters, null);
- _nextElement = _receiver.receive(0L);
- _enumeration = new MessageEnumeration();
- }
- catch(AmqpErrorException e)
- {
- org.apache.qpid.amqp_1_0.type.transport.Error error = e.getError();
- if(AmqpError.INVALID_FIELD.equals(error.getCondition()))
- {
- throw new InvalidSelectorException(e.getMessage());
- }
- else
- {
- throw new JMSException(e.getMessage(), error.getCondition().getValue().toString());
- }
-
+ _filters = Collections.singletonMap(Symbol.valueOf(JMS_SELECTOR),(Filter) new JMSSelectorFilter(_selector));
+ // We do this just to have the server validate the filter..
+ new MessageEnumeration().close();
}
}
@@ -97,42 +74,124 @@ public class QueueBrowserImpl implements QueueBrowser
public Enumeration getEnumeration() throws JMSException
{
- if(_enumeration == null)
+ if(_closed)
{
throw new IllegalStateException("Browser has been closed");
}
- return _enumeration;
+ return new MessageEnumeration();
}
public void close() throws JMSException
{
- _receiver.close();
- _enumeration = null;
+ _closed = true;
+ for(MessageEnumeration me : new ArrayList<MessageEnumeration>(_enumerations))
+ {
+ me.close();
+ }
}
- private final class MessageEnumeration implements Enumeration<Message>
+ private final class MessageEnumeration implements Enumeration<MessageImpl>
{
+ private Receiver _receiver;
+ private MessageImpl _nextElement;
+ private boolean _needNext = true;
+
+ MessageEnumeration() throws JMSException
+ {
+ try
+ {
+ _receiver = _session.getClientSession().createReceiver(_session.toAddress(_queue),
+ StdDistMode.COPY,
+ AcknowledgeMode.AMO, null,
+ false,
+ _filters, null);
+ _receiver.setCredit(UnsignedInteger.valueOf(100), true);
+ }
+ catch(AmqpErrorException e)
+ {
+ org.apache.qpid.amqp_1_0.type.transport.Error error = e.getError();
+ if(AmqpError.INVALID_FIELD.equals(error.getCondition()))
+ {
+ throw new InvalidSelectorException(e.getMessage());
+ }
+ else
+ {
+ throw new JMSException(e.getMessage(), error.getCondition().getValue().toString());
+ }
+
+ }
+ _enumerations.add(this);
+
+ }
+
+ public void close()
+ {
+ _enumerations.remove(this);
+ _receiver.close();
+ _receiver = null;
+ }
@Override
public boolean hasMoreElements()
{
+ if( _receiver == null )
+ {
+ return false;
+ }
+ if( _needNext )
+ {
+ _needNext = false;
+ _nextElement = createJMSMessage(_receiver.receive(0L));
+ if( _nextElement == null )
+ {
+ // Drain to verify there really are no more messages.
+ _receiver.drain();
+ _receiver.drainWait();
+ _nextElement = createJMSMessage(_receiver.receive(0L));
+ if( _nextElement == null )
+ {
+ close();
+ }
+ else
+ {
+ // there are still more messages, open up the credit window again..
+ _receiver.clearDrain();
+ }
+ }
+ }
return _nextElement != null;
}
@Override
- public Message nextElement()
+ public MessageImpl nextElement()
{
-
- Message message = _nextElement;
- if(message == null)
+ if( hasMoreElements() )
{
- message = _receiver.receive(0l);
+ MessageImpl message = _nextElement;
+ _nextElement = null;
+ _needNext = true;
+ return message;
}
- if(message != null)
+ else
{
- _nextElement = _receiver.receive(0l);
+ throw new NoSuchElementException();
}
+ }
+ }
+
+ MessageImpl createJMSMessage(final Message msg)
+ {
+ if(msg != null)
+ {
+ final MessageImpl message = _session.getMessageFactory().createMessage(_queue, msg);
+ message.setFromQueue(true);
+ message.setFromTopic(false);
return message;
}
+ else
+ {
+ return null;
+ }
}
+
}
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueReceiverImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueReceiverImpl.java
index d46ed7183f..67b597f5cf 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueReceiverImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/QueueReceiverImpl.java
@@ -41,7 +41,7 @@ public class QueueReceiverImpl extends MessageConsumerImpl implements QueueRecei
{
try
{
- return getSession().getClientSession().createMovingReceiver(getDestination().getAddress());
+ return getSession().getClientSession().createMovingReceiver(getSession().toAddress(getDestination()));
}
catch (AmqpErrorException e)
{
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/SessionImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/SessionImpl.java
index e321245a0e..58b7d4f625 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/SessionImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/SessionImpl.java
@@ -766,7 +766,7 @@ public class SessionImpl implements Session, QueueSession, TopicSession
{
while(!_closed)
{
- while(!_started || (_recoveredMessage == null && _messageConsumerList.isEmpty()))
+ while(!_closed && (!_started || (_recoveredMessage == null && _messageConsumerList.isEmpty())))
{
try
{
@@ -777,7 +777,7 @@ public class SessionImpl implements Session, QueueSession, TopicSession
return;
}
}
- while(_started && (_recoveredMessage != null || !_messageConsumerList.isEmpty()))
+ while(!_closed && (_started && (_recoveredMessage != null || !_messageConsumerList.isEmpty())))
{
Message msg;
@@ -804,6 +804,10 @@ public class SessionImpl implements Session, QueueSession, TopicSession
if(message != null)
{
+ if(_acknowledgeMode == AcknowledgeMode.CLIENT_ACKNOWLEDGE)
+ {
+ consumer.setLastUnackedMessage(msg.getDeliveryTag());
+ }
_currentConsumer = consumer;
_currentMessage = msg;
try
@@ -816,11 +820,11 @@ public class SessionImpl implements Session, QueueSession, TopicSession
_currentMessage = null;
}
- if((_recoveredMessage == null) && (_acknowledgeMode == AcknowledgeMode.AUTO_ACKNOWLEDGE
- || _acknowledgeMode == AcknowledgeMode.DUPS_OK_ACKNOWLEDGE))
+ if(_recoveredMessage == null)
{
- consumer.acknowledge(msg);
+ consumer.preReceiveAction(msg);
}
+
}
}
@@ -895,4 +899,10 @@ public class SessionImpl implements Session, QueueSession, TopicSession
{
_isTopicSession = topicSession;
}
+
+ String toAddress(DestinationImpl dest)
+ {
+ return _connection.toDecodedDestination(dest).getAddress();
+ }
+
}
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java
index 52d8c412ec..f267794796 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java
@@ -66,7 +66,7 @@ public class TopicSubscriberImpl extends MessageConsumerImpl implements TopicSub
{
try
{
- String address = getDestination().getAddress();
+ String address = getSession().toAddress(getDestination());
Receiver receiver = getSession().getClientSession().createReceiver(address,
StdDistMode.COPY, AcknowledgeMode.ALO,
getLinkName(), isDurable(), getFilters(),
diff --git a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/jndi/PropertiesFileInitialContextFactory.java b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/jndi/PropertiesFileInitialContextFactory.java
index 31030a7d30..091ab41304 100644
--- a/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/jndi/PropertiesFileInitialContextFactory.java
+++ b/java/amqp-1-0-client-jms/src/main/java/org/apache/qpid/amqp_1_0/jms/jndi/PropertiesFileInitialContextFactory.java
@@ -57,6 +57,9 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor
Map data = new ConcurrentHashMap();
String file = null;
+ String fileName = (environment.containsKey(Context.PROVIDER_URL))
+ ? (String)environment.get(Context.PROVIDER_URL) : System.getProperty(Context.PROVIDER_URL);
+
try
{
diff --git a/java/amqp-1-0-client/build.xml b/java/amqp-1-0-client/build.xml
index 031809a380..cd7654ed15 100644
--- a/java/amqp-1-0-client/build.xml
+++ b/java/amqp-1-0-client/build.xml
@@ -23,6 +23,9 @@
<property name="module.genpom" value="true"/>
<property name="module.depends" value="amqp-1-0-common"/>
+ <property name="example.src.dir" value="${project.root}/amqp-1-0-client/example/src/main/java" />
+ <property name="example.jar.file" value="${build.lib}/qpid-amqp-1-0-client-example-${project.version}.jar" />
+
<import file="../module.xml"/>
diff --git a/java/amqp-1-0-client/example/build.xml b/java/amqp-1-0-client/example/build.xml
new file mode 100644
index 0000000000..89bba729dd
--- /dev/null
+++ b/java/amqp-1-0-client/example/build.xml
@@ -0,0 +1,28 @@
+<!--
+ -
+ - 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="AMQ 1.0 Client Example" default="build">
+
+ <property name="module.depends" value="amqp-1-0-client amqp-1-0-common"/>
+ <property name="module.test.depends" value=""/>
+
+ <import file="../../module.xml"/>
+
+</project>
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Command.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Command.java
index 3bb26744c4..3bb26744c4 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Command.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Command.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Demo.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Demo.java
index b58ce6bfe5..b58ce6bfe5 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Demo.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Demo.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Dump.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Dump.java
index 65d27b21f8..65d27b21f8 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Dump.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Dump.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Filereceiver.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Filereceiver.java
index 4d98655ad2..4d98655ad2 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Filereceiver.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Filereceiver.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Filesender.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Filesender.java
index 46e6ba537f..46e6ba537f 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Filesender.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Filesender.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Receive.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Receive.java
index 0da9dc3fb7..0da9dc3fb7 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Receive.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Receive.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Request.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Request.java
index 6e1d15376c..6e1d15376c 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Request.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Request.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Respond.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Respond.java
index 8d9de4893f..8d9de4893f 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Respond.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Respond.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Send.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Send.java
index 6f6575e083..6f6575e083 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Send.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Send.java
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Util.java b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Util.java
index 6fe2a6d510..6fe2a6d510 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Util.java
+++ b/java/amqp-1-0-client/example/src/main/java/org/apache/qpid/amqp_1_0/client/Util.java
diff --git a/java/amqp-1-0-client/resources/LICENSE b/java/amqp-1-0-client/resources/LICENSE
new file mode 100644
index 0000000000..de4b130f35
--- /dev/null
+++ b/java/amqp-1-0-client/resources/LICENSE
@@ -0,0 +1,204 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
diff --git a/java/amqp-1-0-client/resources/NOTICE b/java/amqp-1-0-client/resources/NOTICE
new file mode 100644
index 0000000000..8d1c3f3122
--- /dev/null
+++ b/java/amqp-1-0-client/resources/NOTICE
@@ -0,0 +1,5 @@
+Apache Qpid
+Copyright 2006-2012 Apache Software Foundation
+This product includes software developed at
+Apache Software Foundation (http://www.apache.org/)
+
diff --git a/java/amqp-1-0-client/resources/README.txt b/java/amqp-1-0-client/resources/README.txt
new file mode 100644
index 0000000000..35d25050fe
--- /dev/null
+++ b/java/amqp-1-0-client/resources/README.txt
@@ -0,0 +1,7 @@
+
+Documentation
+--------------
+All of our user documentation can be accessed at:
+
+http://qpid.apache.org/documentation.html
+
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Connection.java b/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Connection.java
index e3d56fae09..e501662dbb 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Connection.java
+++ b/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Connection.java
@@ -20,6 +20,15 @@
*/
package org.apache.qpid.amqp_1_0.client;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.security.Principal;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.net.ssl.SSLSocketFactory;
import org.apache.qpid.amqp_1_0.framing.ConnectionHandler;
import org.apache.qpid.amqp_1_0.transport.AMQPTransport;
import org.apache.qpid.amqp_1_0.transport.ConnectionEndpoint;
@@ -30,17 +39,6 @@ import org.apache.qpid.amqp_1_0.type.FrameBody;
import org.apache.qpid.amqp_1_0.type.SaslFrameBody;
import org.apache.qpid.amqp_1_0.type.UnsignedInteger;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.nio.ByteBuffer;
-import java.security.Principal;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
public class Connection
{
private static final Logger RAW_LOGGER = Logger.getLogger("RAW");
@@ -224,7 +222,6 @@ public class Connection
}
- //ConnectionHandler.OutputHandler outputHandler = new ConnectionHandler.OutputHandler(outputStream, out, _conn.getDescribedTypeRegistry());
ConnectionHandler.BytesOutputHandler outputHandler = new ConnectionHandler.BytesOutputHandler(outputStream, src, _conn);
Thread outputThread = new Thread(outputHandler);
outputThread.setDaemon(true);
@@ -236,8 +233,6 @@ public class Connection
final ConnectionHandler handler = new ConnectionHandler(_conn);
final InputStream inputStream = s.getInputStream();
- //final AMQPTransport transport = new AMQPTransport(new AMQPFrameTransport(_conn));
-
Thread inputThread = new Thread(new Runnable()
{
@@ -246,7 +241,6 @@ public class Connection
try
{
doRead(handler, inputStream);
-// doRead(transport, inputStream);
}
finally
{
@@ -268,85 +262,6 @@ public class Connection
inputThread.setDaemon(true);
inputThread.start();
-/*
- Thread outputThread = new Thread(new Runnable()
- {
-
- private int _lastWrite;
-
- public void run()
- {
- try
- {
-// doRead(handler, inputStream);
- final Object lock = new Object();
- transport.setOutputStateChangeListener(new StateChangeListener()
- {
-
- public void onStateChange(final boolean active)
- {
- synchronized (lock)
- {
- lock.notifyAll();
- }
- }
- });
-
- synchronized(lock)
- {
- while(transport.isOpenForOutput())
- {
- _lastWrite = 0;
- transport.getNextBytes(new BytesProcessor()
- {
-
- public void processBytes(final ByteBuffer buf)
- {
- _lastWrite = buf.remaining();
- try
- {
- outputStream.write(buf.array(),
- buf.arrayOffset() + buf.position(),
- buf.limit() - buf.position());
- }
- catch (IOException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- });
- if(_lastWrite == 0 && transport.isOpenForOutput())
- {
- try
- {
- lock.wait(1000);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- }
- }
- }
- finally
- {
- if(_conn.closedForInput() && _conn.closedForOutput())
- {
- try
- {
- s.close();
- }
- catch (IOException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- }
- }
- });
-*/
-
_conn.open();
}
@@ -394,7 +309,7 @@ public class Connection
}
catch (IOException e)
{
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ e.printStackTrace();
}
}
@@ -419,7 +334,7 @@ public class Connection
{
int read;
boolean done = false;
- while(!done && (read = inputStream.read(buf)) != -1)
+ while(!handler.isDone() && (read = inputStream.read(buf)) != -1)
{
ByteBuffer bbuf = ByteBuffer.wrap(buf, 0, read);
Binary b = new Binary(buf,0,read);
@@ -428,12 +343,6 @@ public class Connection
{
RAW_LOGGER.fine("RECV [" + _conn.getRemoteAddress() + "] : " + b.toString());
}
- /*System.err.println(b);
- System.err.println("XXX: " + bbuf.hasRemaining() + "; " + handler.isDone());
- if(handler.isDone())
- {
- System.err.println(handler.getClass().getName() + "IS DONE!");
- } */
while(bbuf.hasRemaining() && !handler.isDone())
{
handler.parse(bbuf);
@@ -444,7 +353,7 @@ public class Connection
}
catch (IOException e)
{
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ e.printStackTrace();
}
}
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/ReadBytes.java b/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/ReadBytes.java
deleted file mode 100644
index 07ae54b54f..0000000000
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/ReadBytes.java
+++ /dev/null
@@ -1,77 +0,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.
- */
-
-package org.apache.qpid.amqp_1_0.client;
-
-import org.apache.qpid.amqp_1_0.codec.ValueHandler;
-import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
-import org.apache.qpid.amqp_1_0.type.codec.AMQPDescribedTypeRegistry;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-
-public class ReadBytes
-{
-
- public static void main(String[] args) throws IOException, AmqpErrorException
- {
-
- if(args.length == 0)
- {
- readBytes(System.in);
- }
- else
- {
- for(String fileName : args)
- {
- System.out.println("=========================== " + fileName + " ===========================");
- final FileInputStream fis = new FileInputStream(fileName);
- readBytes(fis);
- fis.close();
- }
- }
-
- }
-
- private static void readBytes(final InputStream inputStream) throws IOException, AmqpErrorException
- {
- byte[] bytes = new byte[4096];
-
- ValueHandler valueHandler = new ValueHandler(AMQPDescribedTypeRegistry.newInstance());
-
- int count;
-
- while((count = inputStream.read(bytes))!=-1)
- {
- ByteBuffer buf = ByteBuffer.wrap(bytes);
- buf.limit(count);
- while(buf.hasRemaining())
- {
-
- final Object value = valueHandler.parse(buf);
- System.out.print((value == null ? "" : value.getClass().getName() + ":") +value +"\n");
-
- }
- }
-
- }
-
-
-}
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Receiver.java b/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Receiver.java
index ad390fd498..8b792db1f1 100644
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Receiver.java
+++ b/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Receiver.java
@@ -241,7 +241,7 @@ public class Receiver implements DeliveryStateHandler
}
if(hasMore)
{
- xfr = receiveFromPrefetch(0L);
+ xfr = receiveFromPrefetch(-1l);
if(xfr== null)
{
// TODO - this is wrong!!!!
@@ -503,6 +503,37 @@ public class Receiver implements DeliveryStateHandler
_endpoint.drain();
}
+ /**
+ * Waits for the receiver to drain or a message to be available to be received.
+ * @return true if the receiver has been drained.
+ */
+ public boolean drainWait()
+ {
+ final Object lock = _endpoint.getLock();
+ synchronized(lock)
+ {
+ try
+ {
+ while( _prefetchQueue.peek()==null && !_endpoint.isDrained() && !_endpoint.isDetached() )
+ {
+ lock.wait();
+ }
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ return _prefetchQueue.peek()==null && _endpoint.isDrained();
+ }
+
+ /**
+ * Clears the receiver drain so that message delivery can resume.
+ */
+ public void clearDrain()
+ {
+ _endpoint.clearDrain();
+ }
+
public void setCreditWithTransaction(final UnsignedInteger credit, final Transaction txn)
{
_endpoint.setLinkCredit(credit);
@@ -558,4 +589,4 @@ public class Receiver implements DeliveryStateHandler
void messageArrived(Receiver receiver);
}
-} \ No newline at end of file
+}
diff --git a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/SendBytes.java b/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/SendBytes.java
deleted file mode 100644
index 6f97ecd810..0000000000
--- a/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/SendBytes.java
+++ /dev/null
@@ -1,331 +0,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.
- */
-
-package org.apache.qpid.amqp_1_0.client;
-
-import org.apache.qpid.amqp_1_0.codec.FrameWriter;
-import org.apache.qpid.amqp_1_0.codec.ValueWriter;
-import org.apache.qpid.amqp_1_0.framing.AMQFrame;
-import org.apache.qpid.amqp_1_0.type.Binary;
-import org.apache.qpid.amqp_1_0.type.FrameBody;
-import org.apache.qpid.amqp_1_0.type.Section;
-import org.apache.qpid.amqp_1_0.type.Symbol;
-import org.apache.qpid.amqp_1_0.type.UnsignedByte;
-import org.apache.qpid.amqp_1_0.type.UnsignedInteger;
-import org.apache.qpid.amqp_1_0.type.UnsignedLong;
-import org.apache.qpid.amqp_1_0.type.UnsignedShort;
-import org.apache.qpid.amqp_1_0.type.codec.AMQPDescribedTypeRegistry;
-import org.apache.qpid.amqp_1_0.type.messaging.Footer;
-import org.apache.qpid.amqp_1_0.type.messaging.Header;
-import org.apache.qpid.amqp_1_0.type.messaging.Properties;
-import org.apache.qpid.amqp_1_0.type.transport.Flow;
-
-import org.apache.qpid.amqp_1_0.type.transport.Transfer;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-public class SendBytes
-{
-
- public static void main(String[] args) throws
- Sender.SenderCreationException,
- Sender.SenderClosingException,
- Connection.ConnectionException,
- IOException, ParseException
- {
- Transfer xfr = new Transfer();
- Flow fs = new Flow();
- fs.setIncomingWindow(UnsignedInteger.valueOf(1024));
- fs.setDeliveryCount(UnsignedInteger.valueOf(2));
- fs.setLinkCredit(UnsignedInteger.valueOf(18));
- fs.setAvailable(UnsignedInteger.valueOf(0));
- fs.setDrain(false);
-
- xfr.setHandle(UnsignedInteger.valueOf(0));
- xfr.setDeliveryTag(new Binary("\"queue\"<-6ec024a7-d98e-4196-9348-15f6026c32ca:0".getBytes()));
- //xfr.setDeliveryTag(new Binary(new byte[] {0}));
- xfr.setDeliveryId(UnsignedInteger.valueOf(0));
- xfr.setSettled(true);
-
-
- Header h = new Header();
- Properties p = new Properties();
- p.setTo("queue");
- //p.setMessageId(new Binary(UUID.randomUUID().toString().getBytes()));
-
- Footer f = new Footer(Collections.EMPTY_MAP);
-
- Section[] sections = new Section[] { h,p,f};
- //Section[] sections = new Section[] { b };
- //Section[] sections = { h,p, b};
-/*
- Fragment[] fragments = new Fragment[5];
-
- final AMQPDescribedTypeRegistry typeRegistry = AMQPDescribedTypeRegistry.newInstance().registerTransportLayer().registerMessagingLayer();
-
- SectionEncoderImpl encoder = new SectionEncoderImpl(typeRegistry);
-
- int num = 0;
- int i = 0;
- for(Section s : sections)
- {
- Fragment frag = new Fragment();
-
- frag.setPayload(s.encode(encoder));
- frag.setFirst(true);
- frag.setLast(true);
- frag.setSectionCode(s.getSectionCode());
- frag.setSectionNumber(UnsignedInteger.valueOf(num++));
- frag.setSectionOffset(UnsignedLong.valueOf(0L));
- fragments[i++] =frag;
- }
-
- xfr.setFragments(fragments);
-*/
-
- encodeTypes("xfr",xfr);
-
- final byte[] result;
- final Object input = xfr;
-/*
- result = encode(1024, input);
-
- boolean ok = true;
-
- for(int j = 10; ok && j < 400; j++)
- {
-
- byte[] result2 = encode(j,input);
-
- for(int i = 0; i <400; i++)
- {
- if(result[i] != result2[i])
- {
- System.out.println("result differs at " + i + " Splitting at " + j+ " [" + result[i] + " - " + result2[i] + "]");
- //break;
- //ok = false;
-
- }
- }
- }*/
- //System.out.println(Arrays.equals(result, result2));
-
- //doEncodes();
- /*OutputStream out = System.out;
- if(args.length > 0)
- {
- out = new FileOutputStream(args[0]);
- }
-
- Transfer xfr = new Transfer();
- fs.setSessionCredit(UnsignedInteger.valueOf(1024));
- fs.setTransferCount(UnsignedInteger.valueOf(2));
- fs.setLinkCredit(UnsignedInteger.valueOf(18));
- fs.setAvailable(UnsignedInteger.valueOf(0));
- fs.setDrain(false);
-
- xfr.setHandle(UnsignedInteger.valueOf(0));
- //xfr.setDeliveryTag(new Binary("\"queue\"<-6ec024a7-d98e-4196-9348-15f6026c32ca:0".getBytes()));
- xfr.setDeliveryTag(new Binary(new byte[] {0}));
- xfr.setTransferId(UnsignedInteger.valueOf(0));
- xfr.setSettled(true);
- xfr.setFlowState(fs);
-
- Header h = new Header();
- h.setTransmitTime(new Date(System.currentTimeMillis()));
- Properties p = new Properties();
- p.setTo(new Address("queue"));
- //p.setMessageId(new Binary(UUID.randomUUID().toString().getBytes()));
- AmqpMapSection m = new AmqpMapSection();
- DataSection b = new DataSection("Hello World!".getBytes());
-
- Footer f = new Footer();
-
- Section[] sections = new Section[] { h,p,m,b,f};
- //Section[] sections = new Section[] { b };
- //Section[] sections = { h,p, b};
- List<Fragment> fragments = new ArrayList<Fragment>(5);
-
- final AMQPDescribedTypeRegistry typeRegistry = AMQPDescribedTypeRegistry.newInstance();
-
- SectionEncoderImpl encoder = new SectionEncoderImpl(typeRegistry);
-
- for(Section s : sections)
- {
- Fragment frag = new Fragment();
-
- frag.setPayload(s.encode(encoder));
- frag.setFirst(true);
- frag.setLast(true);
- frag.setFormatCode(s.getSectionCode());
- frag.setFragmentOffset(null);
- fragments.add(frag);
- }
-
- xfr.setFragments(fragments);
-
-
- Object[] objectsToWrite = new Object[] { xfr };
- ByteBuffer buf = ByteBuffer.allocate(4096);
-
-
- for(Object obj : objectsToWrite)
- {
- ValueWriter writer = typeRegistry.getValueWriter(obj);
-
- int count;
-
-
- do
- {
- count = writer.writeToBuffer(buf);
- out.write(buf.array(), buf.arrayOffset(), count);
- buf.clear();
- } while (!writer.isComplete());
-
- }
-
- out.flush();
- out.close();*/
-
- }
-
- public static void doEncodes() throws IOException, ParseException
- {
- encodeTypes("boolean", Boolean.TRUE, Boolean.FALSE);
- encodeTypes("ubyte", UnsignedByte.valueOf((byte)0), UnsignedByte.valueOf((byte)1 ),UnsignedByte.valueOf((byte)3), UnsignedByte.valueOf((byte)42), UnsignedByte.valueOf("255"));
- encodeTypes("byte", Byte.valueOf((byte)0), Byte.valueOf( (byte)1), Byte.valueOf((byte) 3), Byte.valueOf((byte) 42), Byte.valueOf((byte) 127), Byte.valueOf((byte) -1), Byte.valueOf((byte) -3), Byte.valueOf((byte) -42), Byte.valueOf( (byte)-128));
- encodeTypes("ushort", UnsignedShort.valueOf((short)0), UnsignedShort.valueOf((short)1), UnsignedShort.valueOf((short)3), UnsignedShort.valueOf((short)42), UnsignedShort.valueOf("65535"));
- encodeTypes("short", Short.valueOf((short)0), Short.valueOf((short)1), Short.valueOf((short)3), Short.valueOf((short)42), Short.valueOf((short)32767), Short.valueOf((short)-1), Short.valueOf((short)-3), Short.valueOf((short)-42), Short.valueOf((short)-32768));
- encodeTypes("uint",UnsignedInteger.valueOf(0), UnsignedInteger.valueOf(1), UnsignedInteger.valueOf(3), UnsignedInteger.valueOf(42), UnsignedInteger.valueOf("4294967295"));
- encodeTypes("int", 0, 1, 3, 42, 2147483647, -1, -3, -42, -2147483648);
- encodeTypes("ulong", UnsignedLong.valueOf(0), UnsignedLong.valueOf(1), UnsignedLong.valueOf(3), UnsignedLong.valueOf(42), UnsignedLong.valueOf("18446744073709551615"));
- encodeTypes("long", 0l, 1l, 3l, 42l, 9223372036854775807l, -1l, -3l, -42l, -9223372036854775808l);
- encodeTypes("float", 3.14159);
- encodeTypes("double", Double.valueOf(3.14159265359));
- encodeTypes("char", '?');
-
- SimpleDateFormat df = new SimpleDateFormat("HHa z MMM d yyyy");
-
- encodeTypes("timestamp", df.parse("9AM PST Dec 6 2010"), df.parse("9AM PST Dec 6 1910"));
- encodeTypes("uuid", UUID.fromString("f275ea5e-0c57-4ad7-b11a-b20c563d3b71"));
- encodeTypes("binary", new Binary( new byte[] {(byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF}), new Binary(new byte[] { (byte)0xCA,(byte)0xFE, (byte)0xBA, (byte)0xBE}));
- encodeTypes("string", "The quick brown fox jumped over the lazy cow.");
- encodeTypes("symbol", Symbol.valueOf("connectathon"));
- encodeTypes("list", Arrays.asList(new Object[] {Long.valueOf(1), "two", Double.valueOf(3.14159265359), null, Boolean.FALSE}));
- Map map = new HashMap();
- map.put("one", Long.valueOf(1));
- map.put("two", Long.valueOf(2));
- map.put("pi", Double.valueOf(3.14159265359));
- map.put("list:", Arrays.asList(new Object[] {Long.valueOf(1), "two", Double.valueOf(3.14159265359), null, Boolean.FALSE}));
- map.put(null, Boolean.TRUE);
- encodeTypes("map", map);
- encodeTypes("null", null);
-
- }
-
- static void encodeTypes(String name, Object... vals ) throws IOException
- {
- FileOutputStream out = new FileOutputStream("/home/rob/"+name+".out");
- ByteBuffer buf = ByteBuffer.allocate(4096);
- final AMQPDescribedTypeRegistry typeRegistry = AMQPDescribedTypeRegistry.newInstance();
-
- if(vals != null)
- {
- for(Object obj : vals)
- {
- ValueWriter writer = typeRegistry.getValueWriter(obj);
-
- int count;
-
-
- do
- {
- count = writer.writeToBuffer(buf);
- out.write(buf.array(), buf.arrayOffset(), count);
- buf.clear();
- } while (!writer.isComplete());
-
- }
- }
- else
- {
- ValueWriter writer = typeRegistry.getValueWriter(null);
-
- int count;
-
-
- do
- {
- count = writer.writeToBuffer(buf);
- out.write(buf.array(), buf.arrayOffset(), count);
- buf.clear();
- } while (!writer.isComplete());
-
- }
- out.flush();
- out.close();
-
- }
-
- static byte[] encode(int size, Object... vals)
- {
- byte[] result = new byte[10000];
- int pos = 0;
-
- final AMQPDescribedTypeRegistry typeRegistry = AMQPDescribedTypeRegistry.newInstance();
- AMQFrame frame = AMQFrame.createAMQFrame((short) 0, (FrameBody) vals[0]);
- FrameWriter writer = new FrameWriter(typeRegistry);
- /*for(Object obj : vals)
- {
- final AMQPDescribedTypeRegistry typeRegistry = AMQPDescribedTypeRegistry.newInstance();
- ValueWriter writer = typeRegistry.getValueWriter(obj);
-*/
- int count;
-
- ByteBuffer buf = ByteBuffer.wrap(result, pos, size);
-
- do
- {
-
- writer.writeToBuffer(buf);
- pos = buf.position();
- buf = ByteBuffer.wrap(result, pos, size);
- if(!writer.isComplete())
- {
- count = 3;
- }
-
- } while (!writer.isComplete());
-/*
-
- }
-*/
-
- return result;
-
- }
-
-
-}
diff --git a/java/amqp-1-0-common/resources/LICENSE b/java/amqp-1-0-common/resources/LICENSE
new file mode 100644
index 0000000000..de4b130f35
--- /dev/null
+++ b/java/amqp-1-0-common/resources/LICENSE
@@ -0,0 +1,204 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
+
diff --git a/java/amqp-1-0-common/resources/NOTICE b/java/amqp-1-0-common/resources/NOTICE
new file mode 100644
index 0000000000..8d1c3f3122
--- /dev/null
+++ b/java/amqp-1-0-common/resources/NOTICE
@@ -0,0 +1,5 @@
+Apache Qpid
+Copyright 2006-2012 Apache Software Foundation
+This product includes software developed at
+Apache Software Foundation (http://www.apache.org/)
+
diff --git a/java/amqp-1-0-common/resources/README.txt b/java/amqp-1-0-common/resources/README.txt
new file mode 100644
index 0000000000..35d25050fe
--- /dev/null
+++ b/java/amqp-1-0-common/resources/README.txt
@@ -0,0 +1,7 @@
+
+Documentation
+--------------
+All of our user documentation can be accessed at:
+
+http://qpid.apache.org/documentation.html
+
diff --git a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java
index dbf9306366..95e327852b 100644
--- a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java
+++ b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java
@@ -77,13 +77,21 @@ public class FrameWriter implements ValueWriter<AMQFrame>
{
case SIZE_0:
- _typeWriter.setValue(_frame.getFrameBody());
-
int payloadLength = _payload == null ? 0 : _payload.remaining();
- _size = _typeWriter.writeToBuffer(remaining > 8
- ? (ByteBuffer)buffer.duplicate().position(buffer.position()+8)
- : ByteBuffer.wrap(EMPTY_BYTE_ARRAY)) + 8 + payloadLength;
+ if(_typeWriter!=null)
+ {
+ _typeWriter.setValue(_frame.getFrameBody());
+
+
+ _size = _typeWriter.writeToBuffer(remaining > 8
+ ? (ByteBuffer)buffer.duplicate().position(buffer.position()+8)
+ : ByteBuffer.wrap(EMPTY_BYTE_ARRAY)) + 8 + payloadLength;
+ }
+ else
+ {
+ _size = 8 + payloadLength;
+ }
if(remaining >= 4)
{
buffer.putInt(_size);
@@ -239,7 +247,14 @@ public class FrameWriter implements ValueWriter<AMQFrame>
_size = -1;
_payload = null;
final Object frameBody = frame.getFrameBody();
- _typeWriter = _registry.getValueWriter(frameBody);
+ if(frameBody!=null)
+ {
+ _typeWriter = _registry.getValueWriter(frameBody);
+ }
+ else
+ {
+ _typeWriter = null;
+ }
_payload = frame.getPayload() == null ? null : frame.getPayload().duplicate();
}
}
diff --git a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/AMQFrame.java b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/AMQFrame.java
index 769fe13d29..9684e290f4 100644
--- a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/AMQFrame.java
+++ b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/AMQFrame.java
@@ -21,6 +21,7 @@
package org.apache.qpid.amqp_1_0.framing;
+import org.apache.qpid.amqp_1_0.type.Binary;
import org.apache.qpid.amqp_1_0.type.FrameBody;
import java.nio.ByteBuffer;
@@ -65,4 +66,11 @@ public abstract class AMQFrame<T>
return _frameBody;
}
+ @Override
+ public String toString()
+ {
+ return "AMQFrame{" +
+ "frameBody=" + _frameBody +
+ '}';
+ }
}
diff --git a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/ConnectionHandler.java b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/ConnectionHandler.java
index 78bed8a71e..f4cd06f3ef 100644
--- a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/ConnectionHandler.java
+++ b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/framing/ConnectionHandler.java
@@ -103,6 +103,7 @@ public class ConnectionHandler
private boolean _setForClose;
private boolean _closed;
+ private long _nextHeartbeat;
public FrameOutput(final ConnectionEndpoint conn)
{
@@ -165,14 +166,34 @@ public class ConnectionHandler
{
synchronized(_conn.getLock())
{
+ long time = System.currentTimeMillis();
try
{
AMQFrame frame = null;
while(!closed() && (frame = _queue.poll()) == null && wait)
{
- _conn.getLock().wait();
+ _conn.getLock().wait(_conn.getIdleTimeout()/2);
+
+ if(_conn.getIdleTimeout()>0)
+ {
+ time = System.currentTimeMillis();
+
+ if(frame == null && time > _nextHeartbeat)
+ {
+ frame = new TransportFrame((short) 0,null);
+ break;
+ }
+ }
}
+
+
+
+ if(frame != null)
+ {
+ _nextHeartbeat = time + _conn.getIdleTimeout()/2;
+
+ }
if(frame == _endOfFrameMarker)
{
_closed = true;
diff --git a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java
index 70e990d92e..17bc2caf5f 100644
--- a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java
+++ b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java
@@ -81,6 +81,8 @@ public class ConnectionEndpoint implements DescribedTypeConstructorRegistry.Sour
private boolean _closedForInput;
private boolean _closedForOutput;
+ private long _idleTimeout;
+
private AMQPDescribedTypeRegistry _describedTypeRegistry = AMQPDescribedTypeRegistry.newInstance()
.registerTransportLayer()
.registerMessagingLayer()
@@ -282,6 +284,11 @@ public class ConnectionEndpoint implements DescribedTypeConstructorRegistry.Sour
_remoteContainerId = open.getContainerId();
+ if(open.getIdleTimeOut() != null)
+ {
+ _idleTimeout = open.getIdleTimeOut().longValue();
+ }
+
switch(_state)
{
case UNOPENED:
@@ -316,6 +323,7 @@ public class ConnectionEndpoint implements DescribedTypeConstructorRegistry.Sour
sendClose(new Close());
break;
case CLOSE_SENT:
+
default:
}
}
@@ -650,6 +658,11 @@ public class ConnectionEndpoint implements DescribedTypeConstructorRegistry.Sour
return this;
}
+ public synchronized long getIdleTimeout()
+ {
+ return _idleTimeout;
+ }
+
public synchronized void close()
{
switch(_state)
diff --git a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/Delivery.java b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/Delivery.java
index 4135199045..aca781afb9 100644
--- a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/Delivery.java
+++ b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/Delivery.java
@@ -71,6 +71,10 @@ public class Delivery
{
setComplete(true);
}
+ if(Boolean.TRUE.equals(transfer.getSettled()))
+ {
+ setSettled(true);
+ }
}
public List<Transfer> getTransfers()
diff --git a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ReceivingLinkEndpoint.java b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ReceivingLinkEndpoint.java
index cf86fc2471..5fbca0b695 100644
--- a/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ReceivingLinkEndpoint.java
+++ b/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ReceivingLinkEndpoint.java
@@ -113,33 +113,37 @@ public class ReceivingLinkEndpoint extends LinkEndpoint<ReceivingLinkListener>
synchronized (getLock())
{
TransientState transientState;
- boolean existingState = _unsettledMap.containsKey(transfer.getDeliveryTag());
- _unsettledMap.put(transfer.getDeliveryTag(), transfer.getState());
+ final Binary deliveryTag = delivery.getDeliveryTag();
+ boolean existingState = _unsettledMap.containsKey(deliveryTag);
+ if(!existingState || transfer.getState() != null)
+ {
+ _unsettledMap.put(deliveryTag, transfer.getState());
+ }
if(!existingState)
{
transientState = new TransientState(transfer.getDeliveryId());
- if(Boolean.TRUE.equals(transfer.getSettled()))
+ if(delivery.isSettled())
{
transientState.setSettled(true);
}
- _unsettledIds.put(transfer.getDeliveryTag(), transientState);
+ _unsettledIds.put(deliveryTag, transientState);
setLinkCredit(getLinkCredit().subtract(UnsignedInteger.ONE));
setDeliveryCount(getDeliveryCount().add(UnsignedInteger.ONE));
}
else
{
- transientState = _unsettledIds.get(transfer.getDeliveryTag());
+ transientState = _unsettledIds.get(deliveryTag);
transientState.incrementCredit();
- if(Boolean.TRUE.equals(transfer.getSettled()))
+ if(delivery.isSettled())
{
transientState.setSettled(true);
}
}
- if(transientState.isSettled())
+ if(transientState.isSettled() && delivery.isComplete())
{
- _unsettledMap.remove(transfer.getDeliveryTag());
+ _unsettledMap.remove(deliveryTag);
}
getLinkEventListener().messageTransfer(transfer);
@@ -155,7 +159,7 @@ public class ReceivingLinkEndpoint extends LinkEndpoint<ReceivingLinkListener>
super.receiveFlow(flow);
_remoteDrain = Boolean.TRUE.equals((Boolean)flow.getDrain());
setAvailable(flow.getAvailable());
- _remoteTransferCount = flow.getDeliveryCount();
+ setDeliveryCount(flow.getDeliveryCount());
getLock().notifyAll();
}
}
@@ -371,7 +375,7 @@ public class ReceivingLinkEndpoint extends LinkEndpoint<ReceivingLinkListener>
tag = iter.next();
tagsToUpdate.add(tag);
- deliveryId = _unsettledIds.get(firstTag).getDeliveryId();
+ deliveryId = _unsettledIds.get(tag).getDeliveryId();
if(deliveryId.equals(last.add(UnsignedInteger.ONE)))
{
diff --git a/java/bdbstore/bin/backup.sh b/java/bdbstore/bin/backup.sh
index 61311cd2ef..ba51758d3c 100755
--- a/java/bdbstore/bin/backup.sh
+++ b/java/bdbstore/bin/backup.sh
@@ -34,11 +34,8 @@ if [ -z "${QPID_HOME}" ]; then
export QPID_HOME=`cd ${WHEREAMI}/../ && pwd`
fi
-VERSION=0.19
-
# BDB's je JAR expected to be found in lib/opt
-LIBS="${QPID_HOME}/lib/opt/*:${QPID_HOME}/lib/qpid-bdbstore-${VERSION}.jar:${QPID_HOME}/lib/qpid-all.jar"
-
+LIBS="${QPID_HOME}/lib/opt/*:${QPID_HOME}/lib/qpid-all.jar"
echo "Starting Hot Backup Script"
java -Dlog4j.configuration=backup-log4j.xml ${JAVA_OPTS} -cp "${LIBS}" org.apache.qpid.server.store.berkeleydb.BDBBackup "${ARGS[@]}"
diff --git a/java/bdbstore/build.xml b/java/bdbstore/build.xml
index 7c305c7c2f..46809f6a90 100644
--- a/java/bdbstore/build.xml
+++ b/java/bdbstore/build.xml
@@ -18,7 +18,7 @@
-->
<project name="bdbstore" xmlns:ivy="antlib:org.apache.ivy.ant" default="build">
<property name="module.depends" value="common broker" />
- <property name="module.test.depends" value="test client common/test broker/test management/common systests" />
+ <property name="module.test.depends" value="client common/tests broker/tests management/common systests broker-plugins/management-jmx" />
<property name="module.genpom" value="true"/>
<import file="../module.xml" />
@@ -78,19 +78,4 @@ http://www.oracle.com/technetwork/database/berkeleydb/downloads/jeoslicense-0868
<target name="build" depends="check-request-props, bdb-jar-required, module.build" />
- <target name="postbuild" depends="copy-store-to-upgrade" />
-
- <target name="copy-store-to-upgrade" description="copy the upgrade tool resource folder contents into the build tree">
- <copy todir="${qpid.home}" failonerror="true">
- <fileset dir="src/test/resources/upgrade"/>
- </copy>
- </target>
-
- <target name="precompile-tests">
- <mkdir dir="${module.test.resources}"/>
- <copy todir="${module.test.resources}">
- <fileset dir="src/test/resources"/>
- </copy>
- </target>
-
</project>
diff --git a/java/bdbstore/jmx/MANIFEST.MF b/java/bdbstore/jmx/MANIFEST.MF
deleted file mode 100644
index ee59bc3ad8..0000000000
--- a/java/bdbstore/jmx/MANIFEST.MF
+++ /dev/null
@@ -1,20 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Qpid Bdbstore-Plugins JMX
-Bundle-SymbolicName: bdbstore-plugins-jmx
-Bundle-Description: Bdbstore Management plugin for Qpid.
-Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
-Bundle-DocURL: http://www.apache.org/
-Bundle-Version: 1.0.0
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ClassPath: .
-Fragment-Host: broker-plugins-management-jmx
-Import-Package: org.apache.qpid,
- org.apache.qpid.management.common.mbeans.annotations,
- org.apache.qpid.server.model,
- org.apache.qpid.server.virtualhost,
- org.apache.qpid.server.store.berkeleydb,
- org.apache.log4j;version=1.2.16,
- javax.management,
- javax.management.openmbean
-Export-Package: org.apache.qpid.server.store.berkeleydb.jmx
diff --git a/java/bdbstore/jmx/build.xml b/java/bdbstore/jmx/build.xml
index 229631555d..d3e9f63b46 100644
--- a/java/bdbstore/jmx/build.xml
+++ b/java/bdbstore/jmx/build.xml
@@ -18,13 +18,13 @@
-->
<project name="bdbstore-jmx" default="build">
<property name="module.depends" value="common broker broker-plugins/management-jmx management/common bdbstore" />
- <property name="module.test.depends" value="test broker/test common/test management/common client systests bdbstore/test" />
+ <property name="module.test.depends" value="broker/tests common/tests management/common client systests bdbstore/tests" />
- <property name="module.manifest" value="MANIFEST.MF" />
- <property name="module.plugin" value="true" />
<property name="module.genpom" value="true"/>
<property name="module.genpom.args" value="-Sqpid-common=provided -Sqpid-broker=provided -Sqpid-broker-plugins-management-jmx=provided -Sqpid-management-common=provided -Sqpid-bdbstore=provided -Sje=provided"/>
+ <property name="broker.plugin" value="true"/>
+
<import file="../../module.xml" />
<target name="bundle" depends="bundle-tasks" />
diff --git a/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBean.java b/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBean.java
index cfcea602b4..28528ec83c 100644
--- a/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBean.java
+++ b/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBean.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import javax.management.JMException;
+import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
@@ -91,7 +92,7 @@ public class BDBHAMessageStoreManagerMBean extends AMQManagedObject implements M
@Override
public String getObjectInstanceName()
{
- return _store.getName();
+ return ObjectName.quote(_store.getName());
}
@Override
diff --git a/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java b/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java
index 837da1eef3..14cdec1669 100644
--- a/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java
+++ b/java/bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanProvider.java
@@ -28,13 +28,11 @@ import org.apache.qpid.server.jmx.MBeanProvider;
import org.apache.qpid.server.jmx.ManagedObject;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
/**
* This provide will create a {@link BDBHAMessageStoreManagerMBean} if the child is a virtual
- * host and of type {@link BDBHAMessageStore#BDB_HA_STORE_TYPE}.
+ * host and of type {@link BDBHAMessageStore#TYPE}.
*
*/
public class BDBHAMessageStoreManagerMBeanProvider implements MBeanProvider
@@ -50,7 +48,7 @@ public class BDBHAMessageStoreManagerMBeanProvider implements MBeanProvider
public boolean isChildManageableByMBean(ConfiguredObject child)
{
return (child instanceof VirtualHost
- && BDBHAMessageStore.BDB_HA_STORE_TYPE.equals(child.getAttribute(VirtualHost.STORE_TYPE)));
+ && BDBHAMessageStore.TYPE.equals(child.getAttribute(VirtualHost.STORE_TYPE)));
}
@Override
@@ -58,10 +56,7 @@ public class BDBHAMessageStoreManagerMBeanProvider implements MBeanProvider
{
VirtualHost virtualHostChild = (VirtualHost) child;
- VirtualHostRegistry virtualHostRegistry = ApplicationRegistry.getInstance().getVirtualHostRegistry();
- org.apache.qpid.server.virtualhost.VirtualHost vhost = virtualHostRegistry.getVirtualHost(virtualHostChild.getName());
-
- BDBHAMessageStore messageStore = (BDBHAMessageStore) vhost.getMessageStore();
+ BDBHAMessageStore messageStore = (BDBHAMessageStore) virtualHostChild.getMessageStore();
if (LOGGER.isDebugEnabled())
{
diff --git a/java/bdbstore/jmx/src/main/resources/META-INF/services/org.apache.qpid.server.jmx.MBeanProvider b/java/bdbstore/jmx/src/main/resources/META-INF/services/org.apache.qpid.server.jmx.MBeanProvider
index b5bc947612..8ece9627b0 100644
--- a/java/bdbstore/jmx/src/main/resources/META-INF/services/org.apache.qpid.server.jmx.MBeanProvider
+++ b/java/bdbstore/jmx/src/main/resources/META-INF/services/org.apache.qpid.server.jmx.MBeanProvider
@@ -1 +1,19 @@
+#
+# 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.
+#
org.apache.qpid.server.store.berkeleydb.jmx.BDBHAMessageStoreManagerMBeanProvider
diff --git a/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java b/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
index 606983cdae..ff47ed958d 100644
--- a/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
+++ b/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterManagementTest.java
@@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.Set;
import javax.jms.Connection;
+import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
@@ -37,7 +38,6 @@ import org.apache.log4j.Logger;
import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.management.common.mbeans.ManagedBroker;
import org.apache.qpid.server.store.berkeleydb.jmx.ManagedBDBHAMessageStore;
-import org.apache.qpid.server.virtualhost.ManagedVirtualHost;
import org.apache.qpid.test.utils.JMXTestUtils;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
@@ -55,7 +55,7 @@ public class HAClusterManagementTest extends QpidBrokerTestCase
private static final Set<String> NON_MASTER_STATES = new HashSet<String>(Arrays.asList(REPLICA.toString(), DETACHED.toString(), UNKNOWN.toString()));;
private static final String VIRTUAL_HOST = "test";
- private static final String MANAGED_OBJECT_QUERY = "org.apache.qpid:type=BDBHAMessageStore,name=" + VIRTUAL_HOST;
+ private static final String MANAGED_OBJECT_QUERY = "org.apache.qpid:type=BDBHAMessageStore,name=" + ObjectName.quote(VIRTUAL_HOST);
private static final int NUMBER_OF_NODES = 4;
private final HATestClusterCreator _clusterCreator = new HATestClusterCreator(this, VIRTUAL_HOST, NUMBER_OF_NODES);
@@ -67,7 +67,6 @@ public class HAClusterManagementTest extends QpidBrokerTestCase
protected void setUp() throws Exception
{
_brokerType = BrokerType.SPAWNED;
- _jmxUtils.setUp();
_clusterCreator.configureClusterNodes();
_brokerFailoverUrl = _clusterCreator.getConnectionUrlForAllClusterNodes();
@@ -132,12 +131,11 @@ public class HAClusterManagementTest extends QpidBrokerTestCase
final int brokerPortNumber = getBrokerPortNumbers().iterator().next();
ManagedBDBHAMessageStore storeBean = getStoreBeanForNodeAtBrokerPort(brokerPortNumber);
+ awaitAllNodesJoiningGroup(storeBean, NUMBER_OF_NODES);
+
final TabularData groupMembers = storeBean.getAllNodesInGroup();
assertNotNull(groupMembers);
- final int numberOfDataRows = groupMembers.size();
- assertEquals("Unexpected number of data rows", NUMBER_OF_NODES ,numberOfDataRows);
-
for(int bdbPortNumber : _clusterCreator.getBdbPortNumbers())
{
final String nodeName = _clusterCreator.getNodeNameForNodeAt(bdbPortNumber);
@@ -155,8 +153,7 @@ public class HAClusterManagementTest extends QpidBrokerTestCase
final int brokerPortNumberToMakeObservation = brokerPortNumberIterator.next();
final int brokerPortNumberToBeRemoved = brokerPortNumberIterator.next();
final ManagedBDBHAMessageStore storeBean = getStoreBeanForNodeAtBrokerPort(brokerPortNumberToMakeObservation);
- final int numberOfDataRows = storeBean.getAllNodesInGroup().size();
- assertEquals("Unexpected number of data rows before test", NUMBER_OF_NODES ,numberOfDataRows);
+ awaitAllNodesJoiningGroup(storeBean, NUMBER_OF_NODES);
final String removedNodeName = _clusterCreator.getNodeNameForNodeAt(_clusterCreator.getBdbPortForBrokerPort(brokerPortNumberToBeRemoved));
_clusterCreator.stopNode(brokerPortNumberToBeRemoved);
@@ -266,4 +263,27 @@ public class HAClusterManagementTest extends QpidBrokerTestCase
return _jmxUtils.getManagedBroker(VIRTUAL_HOST);
}
+
+ private void awaitAllNodesJoiningGroup(ManagedBDBHAMessageStore storeBean, int expectedNumberOfNodes) throws Exception
+ {
+ long totalTimeWaited = 0l;
+ long waitInterval = 100l;
+ long maxWaitTime = 10000;
+
+ int currentNumberOfNodes = storeBean.getAllNodesInGroup().size();
+ while (expectedNumberOfNodes > currentNumberOfNodes || totalTimeWaited > maxWaitTime)
+ {
+ LOGGER.debug("Still awaiting nodes to join group; expecting "
+ + expectedNumberOfNodes + " node(s) but only have " + currentNumberOfNodes
+ + " after " + totalTimeWaited + " ms.");
+
+ totalTimeWaited += waitInterval;
+ Thread.sleep(waitInterval);
+
+ currentNumberOfNodes = storeBean.getAllNodesInGroup().size();
+ }
+
+ assertEquals("Unexpected number of nodes in group after " + totalTimeWaited + " ms",
+ expectedNumberOfNodes ,currentNumberOfNodes);
+ }
}
diff --git a/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java b/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java
index 22877ec36c..95626f7fa5 100644
--- a/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java
+++ b/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterTwoNodeTest.java
@@ -27,6 +27,7 @@ import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
+import javax.management.ObjectName;
import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.server.store.berkeleydb.jmx.ManagedBDBHAMessageStore;
@@ -41,7 +42,7 @@ public class HAClusterTwoNodeTest extends QpidBrokerTestCase
private static final String VIRTUAL_HOST = "test";
- private static final String MANAGED_OBJECT_QUERY = "org.apache.qpid:type=BDBHAMessageStore,name=" + VIRTUAL_HOST;
+ private static final String MANAGED_OBJECT_QUERY = "org.apache.qpid:type=BDBHAMessageStore,name=" + ObjectName.quote(VIRTUAL_HOST);
private static final int NUMBER_OF_NODES = 2;
private final HATestClusterCreator _clusterCreator = new HATestClusterCreator(this, VIRTUAL_HOST, NUMBER_OF_NODES);
@@ -56,7 +57,6 @@ public class HAClusterTwoNodeTest extends QpidBrokerTestCase
assertTrue(isJavaBroker());
assertTrue(isBrokerStorePersistent());
- _jmxUtils.setUp();
super.setUp();
}
@@ -86,11 +86,11 @@ public class HAClusterTwoNodeTest extends QpidBrokerTestCase
String storeConfigKeyPrefix = _clusterCreator.getStoreConfigKeyPrefix();
- setConfigurationProperty(storeConfigKeyPrefix + ".repConfig(0).name", ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT);
- setConfigurationProperty(storeConfigKeyPrefix + ".repConfig(0).value", "2 s");
+ setVirtualHostConfigurationProperty(storeConfigKeyPrefix + ".repConfig(0).name", ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT);
+ setVirtualHostConfigurationProperty(storeConfigKeyPrefix + ".repConfig(0).value", "2 s");
- setConfigurationProperty(storeConfigKeyPrefix + ".repConfig(1).name", ReplicationConfig.ELECTIONS_PRIMARY_RETRIES);
- setConfigurationProperty(storeConfigKeyPrefix + ".repConfig(1).value", "0");
+ setVirtualHostConfigurationProperty(storeConfigKeyPrefix + ".repConfig(1).name", ReplicationConfig.ELECTIONS_PRIMARY_RETRIES);
+ setVirtualHostConfigurationProperty(storeConfigKeyPrefix + ".repConfig(1).value", "0");
_clusterCreator.configureClusterNodes();
_clusterCreator.setDesignatedPrimaryOnFirstBroker(designedPrimary);
diff --git a/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanTest.java b/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanTest.java
index 49b3ddd3dc..298d5bc045 100644
--- a/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanTest.java
+++ b/java/bdbstore/jmx/src/test/java/org/apache/qpid/server/store/berkeleydb/jmx/BDBHAMessageStoreManagerMBeanTest.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import javax.management.JMException;
+import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.TabularData;
@@ -84,7 +85,7 @@ public class BDBHAMessageStoreManagerMBeanTest extends TestCase
{
when(_store.getName()).thenReturn(TEST_STORE_NAME);
- String expectedObjectName = "org.apache.qpid:type=BDBHAMessageStore,name=" + TEST_STORE_NAME;
+ String expectedObjectName = "org.apache.qpid:type=BDBHAMessageStore,name=" + ObjectName.quote(TEST_STORE_NAME);
assertEquals(expectedObjectName, _mBean.getObjectName().toString());
}
diff --git a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
index 9323111fdd..6e64ea5597 100644
--- a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
+++ b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
@@ -54,13 +54,10 @@ import org.apache.qpid.AMQStoreException;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.federation.Bridge;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.message.EnqueableMessage;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.store.*;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.BindingRecoveryHandler;
-import org.apache.qpid.server.store.ConfigurationRecoveryHandler.BrokerLinkRecoveryHandler;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.ExchangeRecoveryHandler;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.QueueRecoveryHandler;
import org.apache.qpid.server.store.MessageStoreRecoveryHandler.StoredMessageRecoveryHandler;
@@ -73,7 +70,6 @@ import org.apache.qpid.server.store.berkeleydb.tuple.ContentBinding;
import org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding;
import org.apache.qpid.server.store.berkeleydb.tuple.PreparedTransactionBinding;
import org.apache.qpid.server.store.berkeleydb.tuple.QueueEntryBinding;
-import org.apache.qpid.server.store.berkeleydb.tuple.StringMapBinding;
import org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding;
import org.apache.qpid.server.store.berkeleydb.tuple.XidBinding;
import org.apache.qpid.server.store.berkeleydb.upgrade.Upgrader;
@@ -423,8 +419,7 @@ public abstract class AbstractBDBMessageStore implements MessageStore
BindingRecoveryHandler brh = qrh.completeQueueRecovery();
_configuredObjectHelper.recoverBindings(brh, configuredObjects);
- BrokerLinkRecoveryHandler lrh = brh.completeBindingRecovery();
- recoverBrokerLinks(lrh);
+ brh.completeBindingRecovery();
}
catch (DatabaseException e)
{
@@ -466,66 +461,6 @@ public abstract class AbstractBDBMessageStore implements MessageStore
}
}
- private void recoverBrokerLinks(final ConfigurationRecoveryHandler.BrokerLinkRecoveryHandler lrh)
- {
- Cursor cursor = null;
-
- try
- {
- cursor = _linkDb.openCursor(null, null);
- DatabaseEntry key = new DatabaseEntry();
- DatabaseEntry value = new DatabaseEntry();
-
- while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
- {
- UUID id = UUIDTupleBinding.getInstance().entryToObject(key);
- long createTime = LongBinding.entryToLong(value);
- Map<String,String> arguments = StringMapBinding.getInstance().entryToObject(value);
-
- ConfigurationRecoveryHandler.BridgeRecoveryHandler brh = lrh.brokerLink(id, createTime, arguments);
-
- recoverBridges(brh, id);
- }
- }
- finally
- {
- closeCursorSafely(cursor);
- }
-
- }
-
- private void recoverBridges(final ConfigurationRecoveryHandler.BridgeRecoveryHandler brh, final UUID linkId)
- {
- Cursor cursor = null;
-
- try
- {
- cursor = _bridgeDb.openCursor(null, null);
- DatabaseEntry key = new DatabaseEntry();
- DatabaseEntry value = new DatabaseEntry();
-
- while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
- {
- UUID id = UUIDTupleBinding.getInstance().entryToObject(key);
-
- UUID parentId = UUIDTupleBinding.getInstance().entryToObject(value);
- if(parentId.equals(linkId))
- {
-
- long createTime = LongBinding.entryToLong(value);
- Map<String,String> arguments = StringMapBinding.getInstance().entryToObject(value);
- brh.bridge(id,createTime,arguments);
- }
- }
- brh.completeBridgeRecoveryForLink();
- }
- finally
- {
- closeCursorSafely(cursor);
- }
-
- }
-
private void recoverMessages(MessageStoreRecoveryHandler msrh) throws DatabaseException
{
@@ -940,89 +875,6 @@ public abstract class AbstractBDBMessageStore implements MessageStore
}
}
- public void createBrokerLink(final BrokerLink link) throws AMQStoreException
- {
- if (_stateManager.isInState(State.ACTIVE))
- {
- DatabaseEntry key = new DatabaseEntry();
- UUIDTupleBinding.getInstance().objectToEntry(link.getQMFId(), key);
-
- DatabaseEntry value = new DatabaseEntry();
- LongBinding.longToEntry(link.getCreateTime(), value);
- StringMapBinding.getInstance().objectToEntry(link.getArguments(), value);
-
- try
- {
- _linkDb.put(null, key, value);
- }
- catch (DatabaseException e)
- {
- throw new AMQStoreException("Error writing Link " + link
- + " to database: " + e.getMessage(), e);
- }
- }
- }
-
- public void deleteBrokerLink(final BrokerLink link) throws AMQStoreException
- {
- DatabaseEntry key = new DatabaseEntry();
- UUIDTupleBinding.getInstance().objectToEntry(link.getQMFId(), key);
- try
- {
- OperationStatus status = _linkDb.delete(null, key);
- if (status == OperationStatus.NOTFOUND)
- {
- throw new AMQStoreException("Link " + link + " not found");
- }
- }
- catch (DatabaseException e)
- {
- throw new AMQStoreException("Error deleting the Link " + link + " from database: " + e.getMessage(), e);
- }
- }
-
- public void createBridge(final Bridge bridge) throws AMQStoreException
- {
- if (_stateManager.isInState(State.ACTIVE))
- {
- DatabaseEntry key = new DatabaseEntry();
- UUIDTupleBinding.getInstance().objectToEntry(bridge.getQMFId(), key);
-
- DatabaseEntry value = new DatabaseEntry();
- UUIDTupleBinding.getInstance().objectToEntry(bridge.getLink().getQMFId(),value);
- LongBinding.longToEntry(bridge.getCreateTime(),value);
- StringMapBinding.getInstance().objectToEntry(bridge.getArguments(), value);
-
- try
- {
- _bridgeDb.put(null, key, value);
- }
- catch (DatabaseException e)
- {
- throw new AMQStoreException("Error writing Bridge " + bridge
- + " to database: " + e.getMessage(), e);
- }
-
- }
- }
-
- public void deleteBridge(final Bridge bridge) throws AMQStoreException
- {
- DatabaseEntry key = new DatabaseEntry();
- UUIDTupleBinding.getInstance().objectToEntry(bridge.getQMFId(), key);
- try
- {
- OperationStatus status = _bridgeDb.delete(null, key);
- if (status == OperationStatus.NOTFOUND)
- {
- throw new AMQStoreException("Bridge " + bridge + " not found");
- }
- }
- catch (DatabaseException e)
- {
- throw new AMQStoreException("Error deleting the Bridge " + bridge + " from database: " + e.getMessage(), e);
- }
- }
/**
* Places a message onto a specified queue, in a given transaction.
@@ -1050,7 +902,7 @@ public abstract class AbstractBDBMessageStore implements MessageStore
{
LOGGER.debug("Enqueuing message " + messageId + " on queue "
+ (queue instanceof AMQQueue ? ((AMQQueue) queue).getName() + " with id " : "") + queue.getId()
- + " [Transaction" + tx + "]");
+ + " in transaction " + tx);
}
_deliveryDb.put(tx, key, value);
}
@@ -1204,7 +1056,8 @@ public abstract class AbstractBDBMessageStore implements MessageStore
if (LOGGER.isDebugEnabled())
{
- LOGGER.debug("commitTranImpl completed for [Transaction:" + tx + "]");
+ String transactionType = syncCommit ? "synchronous" : "asynchronous";
+ LOGGER.debug("commitTranImpl completed " + transactionType + " transaction " + tx);
}
}
catch (DatabaseException e)
@@ -1226,7 +1079,7 @@ public abstract class AbstractBDBMessageStore implements MessageStore
{
if (LOGGER.isDebugEnabled())
{
- LOGGER.debug("abortTran called for [Transaction:" + tx + "]");
+ LOGGER.debug("abortTran called for transaction " + tx);
}
try
@@ -1338,7 +1191,7 @@ public abstract class AbstractBDBMessageStore implements MessageStore
if (LOGGER.isDebugEnabled())
{
- LOGGER.debug("Storing content for message " + messageId + "[Transaction" + tx + "]");
+ LOGGER.debug("Storing content for message " + messageId + " in transaction " + tx);
}
}
@@ -1363,8 +1216,9 @@ public abstract class AbstractBDBMessageStore implements MessageStore
{
if (LOGGER.isDebugEnabled())
{
- LOGGER.debug("public void storeMetaData(Txn tx = " + tx + ", Long messageId = "
- + messageId + ", MessageMetaData messageMetaData = " + messageMetaData + "): called");
+ LOGGER.debug("storeMetaData called for transaction " + tx
+ + ", messageId " + messageId
+ + ", messageMetaData " + messageMetaData);
}
DatabaseEntry key = new DatabaseEntry();
@@ -1378,7 +1232,7 @@ public abstract class AbstractBDBMessageStore implements MessageStore
_messageMetaDataDb.put(tx, key, value);
if (LOGGER.isDebugEnabled())
{
- LOGGER.debug("Storing message metadata for message id " + messageId + "[Transaction" + tx + "]");
+ LOGGER.debug("Storing message metadata for message id " + messageId + " in transaction " + tx);
}
}
catch (DatabaseException e)
@@ -1680,7 +1534,8 @@ public abstract class AbstractBDBMessageStore implements MessageStore
else
{
ByteBuffer buf = ByteBuffer.allocate(size);
- getContent(offsetInMessage, buf);
+ int length = getContent(offsetInMessage, buf);
+ buf.limit(length);
buf.position(0);
return buf;
}
diff --git a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java
index c40f24dbc3..ba111e8091 100644
--- a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java
+++ b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStore.java
@@ -105,7 +105,7 @@ public class BDBHAMessageStore extends AbstractBDBMessageStore implements HAMess
put(ReplicationConfig.LOG_FLUSH_TASK_INTERVAL, "1 min");
}});
- public static final String BDB_HA_STORE_TYPE = "BDB-HA";
+ public static final String TYPE = "BDB-HA";
private String _groupName;
private String _nodeName;
@@ -602,6 +602,6 @@ public class BDBHAMessageStore extends AbstractBDBMessageStore implements HAMess
@Override
public String getStoreType()
{
- return BDB_HA_STORE_TYPE;
+ return TYPE;
}
}
diff --git a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreFactory.java b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreFactory.java
new file mode 100644
index 0000000000..20dce2628d
--- /dev/null
+++ b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreFactory.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.store.berkeleydb;
+
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreFactory;
+
+public class BDBHAMessageStoreFactory implements MessageStoreFactory
+{
+
+ @Override
+ public String getType()
+ {
+ return BDBHAMessageStore.TYPE;
+ }
+
+ @Override
+ public MessageStore createMessageStore()
+ {
+ return new BDBHAMessageStore();
+ }
+
+}
diff --git a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
index 82bc3d8564..4028de4b80 100644
--- a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
+++ b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
@@ -42,7 +42,7 @@ import com.sleepycat.je.EnvironmentConfig;
public class BDBMessageStore extends AbstractBDBMessageStore
{
private static final Logger LOGGER = Logger.getLogger(BDBMessageStore.class);
- private static final String BDB_STORE_TYPE = "BDB";
+ public static final String TYPE = "BDB";
private CommitThreadWrapper _commitThreadWrapper;
@Override
@@ -108,7 +108,7 @@ public class BDBMessageStore extends AbstractBDBMessageStore
@Override
public String getStoreType()
{
- return BDB_STORE_TYPE;
+ return TYPE;
}
}
diff --git a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java
new file mode 100644
index 0000000000..126bf1928a
--- /dev/null
+++ b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.store.berkeleydb;
+
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreFactory;
+
+public class BDBMessageStoreFactory implements MessageStoreFactory
+{
+
+ @Override
+ public String getType()
+ {
+ return BDBMessageStore.TYPE;
+ }
+
+ @Override
+ public MessageStore createMessageStore()
+ {
+ return new BDBMessageStore();
+ }
+
+}
diff --git a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/CommitThreadWrapper.java b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/CommitThreadWrapper.java
index fe1556b5a6..598d20146c 100644
--- a/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/CommitThreadWrapper.java
+++ b/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/CommitThreadWrapper.java
@@ -80,7 +80,7 @@ public class CommitThreadWrapper
{
if (LOGGER.isDebugEnabled())
{
- LOGGER.debug("public synchronized void complete(): called (Transaction = " + _tx + ")");
+ LOGGER.debug("complete() called for transaction " + _tx);
}
_complete = true;
@@ -101,7 +101,10 @@ public class CommitThreadWrapper
if(!_syncCommit)
{
- LOGGER.debug("CommitAsync was requested, returning immediately.");
+ if(LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("CommitAsync was requested, returning immediately.");
+ }
return;
}
@@ -121,6 +124,12 @@ public class CommitThreadWrapper
public synchronized void waitForCompletion()
{
+ long startTime = 0;
+ if(LOGGER.isDebugEnabled())
+ {
+ startTime = System.currentTimeMillis();
+ }
+
while (!isComplete())
{
_commitThread.explicitNotify();
@@ -133,6 +142,12 @@ public class CommitThreadWrapper
throw new RuntimeException(e);
}
}
+
+ if(LOGGER.isDebugEnabled())
+ {
+ long duration = System.currentTimeMillis() - startTime;
+ LOGGER.debug("waitForCompletion returning after " + duration + " ms for transaction " + _tx);
+ }
}
}
@@ -198,8 +213,20 @@ public class CommitThreadWrapper
try
{
+ long startTime = 0;
+ if(LOGGER.isDebugEnabled())
+ {
+ startTime = System.currentTimeMillis();
+ }
+
_environment.flushLog(true);
+ if(LOGGER.isDebugEnabled())
+ {
+ long duration = System.currentTimeMillis() - startTime;
+ LOGGER.debug("flushLog completed in " + duration + " ms");
+ }
+
for(int i = 0; i < size; i++)
{
BDBCommitFuture commit = _jobQueue.poll();
diff --git a/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory b/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory
new file mode 100644
index 0000000000..0be7035e2e
--- /dev/null
+++ b/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+org.apache.qpid.server.store.berkeleydb.BDBMessageStoreFactory
+org.apache.qpid.server.store.berkeleydb.BDBHAMessageStoreFactory \ No newline at end of file
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java
index 342c185b99..7c04d83e79 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java
@@ -63,7 +63,7 @@ public class BDBBackupTest extends QpidBrokerTestCase
// It would be preferable to lookup the store path using #getConfigurationStringProperty("virtualhosts...")
// but the config as known to QBTC does not pull-in the virtualhost section from its separate source file
- _backupFromDir = new File(qpidWork + "/bdbstore/" + TEST_VHOST + "-store");
+ _backupFromDir = new File(qpidWork + File.separator + TEST_VHOST + "-store");
boolean fromDirExistsAndIsDir = _backupFromDir.isDirectory();
assertTrue("backupFromDir " + _backupFromDir + " should already exist", fromDirExistsAndIsDir);
}
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java
index a04fb20680..8e32a1d113 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAMessageStoreTest.java
@@ -24,12 +24,8 @@ import java.io.File;
import java.net.InetAddress;
import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.logging.SystemOutMessageLogger;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.TestLogActor;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
@@ -51,6 +47,7 @@ public class BDBHAMessageStoreTest extends QpidTestCase
private int _masterPort;
private String _host;
private XMLConfiguration _configXml;
+ private VirtualHost _virtualHost;
public void setUp() throws Exception
{
@@ -63,41 +60,48 @@ public class BDBHAMessageStoreTest extends QpidTestCase
FileUtils.delete(new File(_workDir), true);
_configXml = new XMLConfiguration();
- }
- public void tearDown() throws Exception
- {
- FileUtils.delete(new File(_workDir), true);
- super.tearDown();
- }
+ BrokerTestHelper.setUp();
+ }
- public void testSetSystemConfiguration() throws Exception
+ public void tearDown() throws Exception
{
- // create virtual host configuration, registry and host instance
- addVirtualHostConfiguration();
- TestApplicationRegistry registry = initialize();
try
{
- VirtualHost virtualhost = registry.getVirtualHostRegistry().getVirtualHost("test" + _masterPort);
- BDBHAMessageStore store = (BDBHAMessageStore) virtualhost.getMessageStore();
-
- // test whether JVM system settings were applied
- Environment env = store.getEnvironment();
- assertEquals("Unexpected number of cleaner threads", TEST_NUMBER_OF_THREADS, env.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
- assertEquals("Unexpected log file max", TEST_LOG_FILE_MAX, env.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
-
- ReplicatedEnvironment repEnv = store.getReplicatedEnvironment();
- assertEquals("Unexpected number of elections primary retries", TEST_ELECTION_RETRIES,
- repEnv.getConfig().getConfigParam(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES));
- assertEquals("Unexpected number of elections primary retries", TEST_ENV_CONSISTENCY_TIMEOUT,
- repEnv.getConfig().getConfigParam(ReplicationConfig.ENV_CONSISTENCY_TIMEOUT));
+ FileUtils.delete(new File(_workDir), true);
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
}
finally
{
- ApplicationRegistry.remove();
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
}
+ public void testSetSystemConfiguration() throws Exception
+ {
+ // create virtual host configuration, registry and host instance
+ addVirtualHostConfiguration();
+ String vhostName = "test" + _masterPort;
+ VirtualHostConfiguration configuration = new VirtualHostConfiguration(vhostName, _configXml.subset("virtualhosts.virtualhost." + vhostName), BrokerTestHelper.createBrokerMock());
+ _virtualHost = BrokerTestHelper.createVirtualHost(configuration);
+ BDBHAMessageStore store = (BDBHAMessageStore) _virtualHost.getMessageStore();
+
+ // test whether JVM system settings were applied
+ Environment env = store.getEnvironment();
+ assertEquals("Unexpected number of cleaner threads", TEST_NUMBER_OF_THREADS, env.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
+ assertEquals("Unexpected log file max", TEST_LOG_FILE_MAX, env.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
+
+ ReplicatedEnvironment repEnv = store.getReplicatedEnvironment();
+ assertEquals("Unexpected number of elections primary retries", TEST_ELECTION_RETRIES,
+ repEnv.getConfig().getConfigParam(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES));
+ assertEquals("Unexpected number of elections primary retries", TEST_ENV_CONSISTENCY_TIMEOUT,
+ repEnv.getConfig().getConfigParam(ReplicationConfig.ENV_CONSISTENCY_TIMEOUT));
+ }
+
private void addVirtualHostConfiguration() throws Exception
{
int port = findFreePort();
@@ -152,14 +156,4 @@ public class BDBHAMessageStoreTest extends QpidTestCase
}
return _host + ":" + _masterPort;
}
-
- private TestApplicationRegistry initialize() throws Exception
- {
- CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
- ServerConfiguration configuration = new ServerConfiguration(_configXml);
- TestApplicationRegistry registry = new TestApplicationRegistry(configuration);
- ApplicationRegistry.initialise(registry);
- registry.getVirtualHostRegistry().setDefaultVirtualHostName("test" + _masterPort);
- return registry;
- }
}
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
index eef9f7eab4..d18c850ecf 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
@@ -225,7 +225,7 @@ public class BDBMessageStoreTest extends org.apache.qpid.server.store.MessageSto
messageStore.close();
AbstractBDBMessageStore newStore = new BDBMessageStore();
- newStore.configure("", _config.subset("store"));
+ newStore.configure("", getConfig().subset("store"));
newStore.startWithNoRecover();
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgradeTestPreparer.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgradeTestPreparer.java
index 122f846a2d..390d667db0 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgradeTestPreparer.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreUpgradeTestPreparer.java
@@ -20,6 +20,9 @@
*/
package org.apache.qpid.server.store.berkeleydb;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
@@ -35,6 +38,11 @@ import javax.jms.TopicConnection;
import javax.jms.TopicPublisher;
import javax.jms.TopicSession;
import javax.jms.TopicSubscriber;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
import org.apache.qpid.client.AMQConnectionFactory;
import org.apache.qpid.client.AMQDestination;
@@ -62,6 +70,11 @@ public class BDBStoreUpgradeTestPreparer
public static final String QUEUE_NAME="myUpgradeQueue";
public static final String NON_DURABLE_QUEUE_NAME="queue-non-durable";
+ public static final String PRIORITY_QUEUE_NAME="myPriorityQueue";
+ public static final String QUEUE_WITH_DLQ_NAME="myQueueWithDLQ";
+ public static final String NONEXCLUSIVE_WITH_ERRONEOUS_OWNER = "nonexclusive-with-erroneous-owner";
+ public static final String MISUSED_OWNER = "misused-owner-as-description";
+
private static AMQConnectionFactory _connFac;
private static final String CONN_URL =
"amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'";
@@ -86,10 +99,10 @@ public class BDBStoreUpgradeTestPreparer
{
Connection connection = _connFac.createConnection();
AMQSession<?, ?> session = (AMQSession<?,?>)connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- AMQShortString queueName = AMQShortString.valueOf(NON_DURABLE_QUEUE_NAME);
+ AMQShortString queueName = new AMQShortString(NON_DURABLE_QUEUE_NAME);
AMQDestination destination = (AMQDestination) session.createQueue(NON_DURABLE_QUEUE_NAME);
session.sendCreateQueue(queueName, false, false, false, null);
- session.bindQueue(queueName, queueName, null, AMQShortString.valueOf("amq.direct"), destination);
+ session.bindQueue(queueName, queueName, null, new AMQShortString("amq.direct"), destination);
MessageProducer messageProducer = session.createProducer(destination);
sendMessages(session, messageProducer, destination, DeliveryMode.PERSISTENT, 1024, 3);
connection.close();
@@ -140,11 +153,56 @@ public class BDBStoreUpgradeTestPreparer
// Publish 5 persistent messages which will NOT be committed and so should be 'lost'
sendMessages(session, messageProducer, queue, DeliveryMode.PERSISTENT, 1*1024, 5);
+ messageProducer.close();
+ session.close();
+
+ session = connection.createSession(true, Session.SESSION_TRANSACTED);
+ // Create a priority queue on broker
+ final Map<String,Object> priorityQueueArguments = new HashMap<String, Object>();
+ priorityQueueArguments.put("x-qpid-priorities",10);
+ createAndBindQueueOnBroker(session, PRIORITY_QUEUE_NAME, priorityQueueArguments);
+
+ // Create a queue that has a DLQ
+ final Map<String,Object> queueWithDLQArguments = new HashMap<String, Object>();
+ queueWithDLQArguments.put("x-qpid-dlq-enabled", true);
+ queueWithDLQArguments.put("x-qpid-maximum-delivery-count", 2);
+ createAndBindQueueOnBroker(session, QUEUE_WITH_DLQ_NAME, queueWithDLQArguments);
+
+ // Send message to the DLQ
+ Queue dlq = session.createQueue("fanout://" + QUEUE_WITH_DLQ_NAME + "_DLE//does-not-matter");
+ MessageProducer dlqMessageProducer = session.createProducer(dlq);
+ sendMessages(session, dlqMessageProducer, dlq, DeliveryMode.PERSISTENT, 1*1024, 1);
+ session.commit();
+ // Create a queue with JMX specifying an owner, so it can later be moved into description
+ createAndBindQueueOnBrokerWithJMX(NONEXCLUSIVE_WITH_ERRONEOUS_OWNER, MISUSED_OWNER, priorityQueueArguments);
session.close();
connection.close();
}
+ private void createAndBindQueueOnBroker(Session session, String queueName, final Map<String, Object> arguments) throws Exception
+ {
+ ((AMQSession<?,?>) session).createQueue(new AMQShortString(queueName), false, true, false, arguments);
+ Queue queue = (Queue) session.createQueue("direct://amq.direct/"+queueName+"/"+queueName+"?durable='true'");
+ ((AMQSession<?,?>) session).declareAndBind((AMQDestination)queue);
+ }
+
+ private void createAndBindQueueOnBrokerWithJMX(String queueName, String owner, final Map<String, Object> arguments) throws Exception
+ {
+ Map<String, Object> environment = new HashMap<String, Object>();
+ environment.put(JMXConnector.CREDENTIALS, new String[] {"admin","admin"});
+ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi");
+ JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
+ MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
+ ObjectName virtualHost = new ObjectName("org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=\"test\"");
+
+ Object[] params = new Object[] {queueName, owner, true, arguments};
+ String[] signature = new String[] {String.class.getName(), String.class.getName(), boolean.class.getName(), Map.class.getName()};
+ mbsc.invoke(virtualHost, "createNewQueue", params, signature);
+
+ ObjectName directExchange = new ObjectName("org.apache.qpid:type=VirtualHost.Exchange,VirtualHost=\"test\",name=\"amq.direct\",ExchangeType=direct");
+ mbsc.invoke(directExchange, "createNewBinding", new Object[] {queueName, queueName}, new String[] {String.class.getName(), String.class.getName()});
+ }
/**
* Prepare a DurableSubscription backing queue for use in testing selector
* recovery and queue exclusivity marking during the upgrade process.
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java
index 4e201d5473..e4837b212e 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java
@@ -22,16 +22,20 @@ package org.apache.qpid.server.store.berkeleydb;
import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.NON_DURABLE_QUEUE_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.PRIORITY_QUEUE_NAME;
import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.QUEUE_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.QUEUE_WITH_DLQ_NAME;
import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.SELECTOR_SUB_NAME;
import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.SELECTOR_TOPIC_NAME;
import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.SUB_NAME;
import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.TOPIC_NAME;
import java.io.File;
+import java.io.InputStream;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
@@ -43,7 +47,10 @@ import javax.jms.TopicConnection;
import javax.jms.TopicPublisher;
import javax.jms.TopicSession;
import javax.jms.TopicSubscriber;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularDataSupport;
+import org.apache.qpid.management.common.mbeans.ManagedExchange;
import org.apache.qpid.management.common.mbeans.ManagedQueue;
import org.apache.qpid.test.utils.JMXTestUtils;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
@@ -70,7 +77,7 @@ public class BDBUpgradeTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
assertNotNull("QPID_WORK must be set", QPID_WORK_ORIG);
- _storeLocation = getWorkDirBaseDir() + "/bdbstore/test-store";
+ _storeLocation = getWorkDirBaseDir() + File.separator + "test-store";
//Clear the two target directories if they exist.
File directory = new File(_storeLocation);
@@ -78,15 +85,13 @@ public class BDBUpgradeTest extends QpidBrokerTestCase
{
FileUtils.delete(directory, true);
}
+ directory.mkdirs();
// copy store files
- String src = getClass().getClassLoader().getResource("upgrade/bdbstore-v4/test-store").toURI().getPath();
- FileUtils.copyRecursive(new File(src), new File(_storeLocation));
-
- //override the broker config used and then start the broker with the updated store
- _configFile = new File("build/etc/config-systests-bdb.xml");
- setConfigurationProperty("management.enabled", "true");
+ InputStream src = getClass().getClassLoader().getResourceAsStream("upgrade/bdbstore-v4/test-store/00000000.jdb");
+ FileUtils.copy(src, new File(_storeLocation, "00000000.jdb"));
+ getBrokerConfiguration().addJmxManagementConfiguration();
super.setUp();
}
@@ -302,11 +307,110 @@ public class BDBUpgradeTest extends QpidBrokerTestCase
Queue queue = session.createQueue(NON_DURABLE_QUEUE_NAME);
MessageConsumer messageConsumer = session.createConsumer(queue);
- for (int i = 0; i < 3; i++)
+ for (int i = 1; i <= 3; i++)
{
Message message = messageConsumer.receive(1000);
assertNotNull("Message was not migrated!", message);
assertTrue("Unexpected message received!", message instanceof TextMessage);
+ assertEquals("ID property did not match", i, message.getIntProperty("ID"));
+ }
+ }
+
+ /**
+ * Tests store upgrade has maintained the priority queue configuration,
+ * such that sending messages with priorities out-of-order and then consuming
+ * them gets the messages back in priority order.
+ */
+ public void testPriorityQueue() throws Exception
+ {
+ // Create a connection and start it
+ Connection connection = getConnection();
+ connection.start();
+
+ // send some messages to the priority queue
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue queue = session.createQueue(PRIORITY_QUEUE_NAME);
+ MessageProducer producer = session.createProducer(queue);
+
+ producer.setPriority(4);
+ producer.send(createMessage(1, false, session, producer));
+ producer.setPriority(1);
+ producer.send(createMessage(2, false, session, producer));
+ producer.setPriority(9);
+ producer.send(createMessage(3, false, session, producer));
+ session.close();
+
+ //consume the messages, expected order: msg 3, msg 1, msg 2.
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+
+ Message msg = consumer.receive(1500);
+ assertNotNull("expected message was not received", msg);
+ assertEquals(3, msg.getIntProperty("msg"));
+ msg = consumer.receive(1500);
+ assertNotNull("expected message was not received", msg);
+ assertEquals(1, msg.getIntProperty("msg"));
+ msg = consumer.receive(1500);
+ assertNotNull("expected message was not received", msg);
+ assertEquals(2, msg.getIntProperty("msg"));
+ }
+
+ /**
+ * Test that the queue configured to have a DLQ was recovered and has the alternate exchange
+ * and max delivery count, the DLE exists, the DLQ exists with no max delivery count, the
+ * DLQ is bound to the DLE, and that the DLQ does not itself have a DLQ.
+ *
+ * DLQs are NOT enabled at the virtualhost level, we are testing recovery of the arguments
+ * that turned it on for this specific queue.
+ */
+ public void testRecoveryOfQueueWithDLQ() throws Exception
+ {
+ JMXTestUtils jmxUtils = null;
+ try
+ {
+ jmxUtils = new JMXTestUtils(this, "guest", "guest");
+ jmxUtils.open();
+ }
+ catch (Exception e)
+ {
+ fail("Unable to establish JMX connection, test cannot proceed");
+ }
+
+ try
+ {
+ //verify the DLE exchange exists, has the expected type, and a single binding for the DLQ
+ ManagedExchange exchange = jmxUtils.getManagedExchange(QUEUE_WITH_DLQ_NAME + "_DLE");
+ assertEquals("Wrong exchange type", "fanout", exchange.getExchangeType());
+ TabularDataSupport bindings = (TabularDataSupport) exchange.bindings();
+ assertEquals(1, bindings.size());
+ for(Object o : bindings.values())
+ {
+ CompositeData binding = (CompositeData) o;
+
+ String bindingKey = (String) binding.get(ManagedExchange.BINDING_KEY);
+ String[] queueNames = (String[]) binding.get(ManagedExchange.QUEUE_NAMES);
+
+ //Because its a fanout exchange, we just return a single '*' key with all bound queues
+ assertEquals("unexpected binding key", "*", bindingKey);
+ assertEquals("unexpected number of queues bound", 1, queueNames.length);
+ assertEquals("unexpected queue name", QUEUE_WITH_DLQ_NAME + "_DLQ", queueNames[0]);
+ }
+
+ //verify the queue exists, has the expected alternate exchange and max delivery count
+ ManagedQueue queue = jmxUtils.getManagedQueue(QUEUE_WITH_DLQ_NAME);
+ assertEquals("Queue does not have the expected AlternateExchange", QUEUE_WITH_DLQ_NAME + "_DLE", queue.getAlternateExchange());
+ assertEquals("Unexpected maximum delivery count", Integer.valueOf(2), queue.getMaximumDeliveryCount());
+
+ ManagedQueue dlQqueue = jmxUtils.getManagedQueue(QUEUE_WITH_DLQ_NAME + "_DLQ");
+ assertNull("Queue should not have an AlternateExchange", dlQqueue.getAlternateExchange());
+ assertEquals("Unexpected maximum delivery count", Integer.valueOf(0), dlQqueue.getMaximumDeliveryCount());
+
+ String dlqDlqObjectNameString = jmxUtils.getQueueObjectNameString("test", QUEUE_WITH_DLQ_NAME + "_DLQ" + "_DLQ");
+ assertFalse("a DLQ should not exist for the DLQ itself", jmxUtils.doesManagedObjectExist(dlqDlqObjectNameString));
+ }
+ finally
+ {
+ jmxUtils.close();
}
}
@@ -387,4 +491,11 @@ public class BDBUpgradeTest extends QpidBrokerTestCase
session.close();
}
+ private Message createMessage(int msgId, boolean first, Session producerSession, MessageProducer producer) throws JMSException
+ {
+ Message send = producerSession.createTextMessage("Message: " + msgId);
+ send.setIntProperty("msg", msgId);
+
+ return send;
+ }
}
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterBlackboxTest.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterBlackboxTest.java
index c6a9ba8f8b..0e1ef7b25d 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterBlackboxTest.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HAClusterBlackboxTest.java
@@ -31,6 +31,7 @@ import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.jms.ConnectionListener;
import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestUtils;
import com.sleepycat.je.rep.ReplicationConfig;
@@ -134,7 +135,10 @@ public class HAClusterBlackboxTest extends QpidBrokerTestCase
public void assertFailoverOccurs(long delay) throws InterruptedException
{
- _failoverLatch.await(delay, TimeUnit.MILLISECONDS);
+ if (!_failoverLatch.await(delay, TimeUnit.MILLISECONDS))
+ {
+ LOGGER.warn("Test thread dump:\n\n" + TestUtils.dumpThreads() + "\n");
+ }
assertEquals("Failover did not occur", 0, _failoverLatch.getCount());
}
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java
index abe13edc32..4c2fa910f5 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java
@@ -43,6 +43,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQConnectionURL;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.url.URLSyntaxException;
@@ -67,7 +68,7 @@ public class HATestClusterCreator
private final Map<Integer, Integer> _brokerPortToBdbPortMap = new HashMap<Integer, Integer>();
private final Map<Integer, BrokerConfigHolder> _brokerConfigurations = new TreeMap<Integer, BrokerConfigHolder>();
private final String _virtualHostName;
- private final String _storeConfigKeyPrefix;
+ private final String _vhostStoreConfigKeyPrefix;
private final String _ipAddressOfBroker;
private final String _groupName ;
@@ -82,7 +83,7 @@ public class HATestClusterCreator
_groupName = "group" + _testcase.getName();
_ipAddressOfBroker = getIpAddressOfBrokerHost();
_numberOfNodes = numberOfNodes;
- _storeConfigKeyPrefix = "virtualhosts.virtualhost." + _virtualHostName + ".store.";
+ _vhostStoreConfigKeyPrefix = "virtualhosts.virtualhost." + _virtualHostName + ".store.";
_bdbHelperPort = 0;
}
@@ -102,7 +103,9 @@ public class HATestClusterCreator
}
configureClusterNode(brokerPort, bdbPort);
- collectConfig(brokerPort, _testcase.getTestConfiguration(), _testcase.getTestVirtualhosts());
+ TestBrokerConfiguration brokerConfiguration = _testcase.getBrokerConfiguration(brokerPort);
+ brokerConfiguration.addJmxManagementConfiguration();
+ collectConfig(brokerPort, brokerConfiguration, _testcase.getTestVirtualhosts());
brokerPort = _testcase.getNextAvailable(bdbPort + 1);
}
@@ -127,7 +130,7 @@ public class HATestClusterCreator
*/
private String getConfigKey(String configKeySuffix)
{
- final String configKey = StringUtils.substringAfter(_storeConfigKeyPrefix + configKeySuffix, "virtualhosts.");
+ final String configKey = StringUtils.substringAfter(_vhostStoreConfigKeyPrefix + configKeySuffix, "virtualhosts.");
return configKey;
}
@@ -135,7 +138,6 @@ public class HATestClusterCreator
{
final BrokerConfigHolder brokerConfigHolder = _brokerConfigurations.get(brokerPortNumber);
- _testcase.setTestConfiguration(brokerConfigHolder.getTestConfiguration());
_testcase.setTestVirtualhosts(brokerConfigHolder.getTestVirtualhosts());
_testcase.startBroker(brokerPortNumber);
@@ -204,7 +206,7 @@ public class HATestClusterCreator
public void stopNode(final int brokerPortNumber)
{
- _testcase.stopBroker(brokerPortNumber);
+ _testcase.killBroker(brokerPortNumber);
}
public void stopCluster() throws Exception
@@ -348,12 +350,12 @@ public class HATestClusterCreator
{
final String nodeName = getNodeNameForNodeAt(bdbPort);
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "class", "org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore");
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "class", "org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore");
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "highAvailability.groupName", _groupName);
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "highAvailability.nodeName", nodeName);
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "highAvailability.nodeHostPort", getNodeHostPortForNodeAt(bdbPort));
- _testcase.setConfigurationProperty(_storeConfigKeyPrefix + "highAvailability.helperHostPort", getHelperHostPort());
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "highAvailability.groupName", _groupName);
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "highAvailability.nodeName", nodeName);
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "highAvailability.nodeHostPort", getNodeHostPortForNodeAt(bdbPort));
+ _testcase.setVirtualHostConfigurationProperty(_vhostStoreConfigKeyPrefix + "highAvailability.helperHostPort", getHelperHostPort());
}
public String getIpAddressOfBrokerHost()
@@ -369,24 +371,24 @@ public class HATestClusterCreator
}
}
- private void collectConfig(final int brokerPortNumber, XMLConfiguration testConfiguration, XMLConfiguration testVirtualhosts)
+ private void collectConfig(final int brokerPortNumber, TestBrokerConfiguration testConfiguration, XMLConfiguration testVirtualhosts)
{
- _brokerConfigurations.put(brokerPortNumber, new BrokerConfigHolder((XMLConfiguration) testConfiguration.clone(),
+ _brokerConfigurations.put(brokerPortNumber, new BrokerConfigHolder(testConfiguration,
(XMLConfiguration) testVirtualhosts.clone()));
}
public class BrokerConfigHolder
{
- private final XMLConfiguration _testConfiguration;
+ private final TestBrokerConfiguration _testConfiguration;
private final XMLConfiguration _testVirtualhosts;
- public BrokerConfigHolder(XMLConfiguration testConfiguration, XMLConfiguration testVirtualhosts)
+ public BrokerConfigHolder(TestBrokerConfiguration testConfiguration, XMLConfiguration testVirtualhosts)
{
_testConfiguration = testConfiguration;
_testVirtualhosts = testVirtualhosts;
}
- public XMLConfiguration getTestConfiguration()
+ public TestBrokerConfiguration getTestConfiguration()
{
return _testConfiguration;
}
@@ -416,7 +418,7 @@ public class HATestClusterCreator
public String getStoreConfigKeyPrefix()
{
- return _storeConfigKeyPrefix;
+ return _vhostStoreConfigKeyPrefix;
}
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/MessageStoreCreatorTest.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/MessageStoreCreatorTest.java
new file mode 100644
index 0000000000..d33eb868c2
--- /dev/null
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/MessageStoreCreatorTest.java
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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.store.berkeleydb;
+
+import org.apache.qpid.server.store.MemoryMessageStore;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreCreator;
+import org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore;
+import org.apache.qpid.server.store.berkeleydb.BDBMessageStore;
+import org.apache.qpid.server.store.derby.DerbyMessageStore;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class MessageStoreCreatorTest extends QpidTestCase
+{
+ private static final String[] STORE_TYPES = {MemoryMessageStore.TYPE, DerbyMessageStore.TYPE, BDBMessageStore.TYPE, BDBHAMessageStore.TYPE};
+
+ public void testMessageStoreCreator()
+ {
+ MessageStoreCreator messageStoreCreator = new MessageStoreCreator();
+ for (String type : STORE_TYPES)
+ {
+ MessageStore store = messageStoreCreator.createMessageStore(type);
+ assertNotNull("Store of type " + type + " is not created", store);
+ }
+ }
+}
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java
index cd2654f79f..b2b28b3c2d 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/AbstractUpgradeTestCase.java
@@ -20,7 +20,14 @@
*/
package org.apache.qpid.server.store.berkeleydb.upgrade;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.NONEXCLUSIVE_WITH_ERRONEOUS_OWNER;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.NON_DURABLE_QUEUE_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.PRIORITY_QUEUE_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.QUEUE_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.QUEUE_WITH_DLQ_NAME;
+
import java.io.File;
+import java.io.InputStream;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.subjects.TestBlankSubject;
@@ -51,15 +58,15 @@ public abstract class AbstractUpgradeTestCase extends QpidTestCase
}
}
- public static final String[] QUEUE_NAMES = { "clientid:myDurSubName", "clientid:mySelectorDurSubName", "myUpgradeQueue",
- "queue-non-durable", "nonexclusive-with-erroneous-owner" };
- public static int[] QUEUE_SIZES = { 1, 1, 10, 3, 0};
- public static int TOTAL_MESSAGE_NUMBER = 15;
+ public static final String[] QUEUE_NAMES = { "clientid:myDurSubName", "clientid:mySelectorDurSubName", QUEUE_NAME, NON_DURABLE_QUEUE_NAME,
+ NONEXCLUSIVE_WITH_ERRONEOUS_OWNER, PRIORITY_QUEUE_NAME, QUEUE_WITH_DLQ_NAME, QUEUE_WITH_DLQ_NAME + "_DLQ" };
+ public static int[] QUEUE_SIZES = { 1, 1, 10, 3, 0, 0, 0, 1};
+ public static int TOTAL_MESSAGE_NUMBER = 16;
protected static final LogSubject LOG_SUBJECT = new TestBlankSubject();
- // one binding per exchange
- protected static final int TOTAL_BINDINGS = QUEUE_NAMES.length * 2;
- protected static final int TOTAL_EXCHANGES = 5;
+ // myQueueWithDLQ_DLQ is not bound to the default exchange
+ protected static final int TOTAL_BINDINGS = QUEUE_NAMES.length * 2 - 1;
+ protected static final int TOTAL_EXCHANGES = 6;
private File _storeLocation;
protected Environment _environment;
@@ -105,10 +112,24 @@ public abstract class AbstractUpgradeTestCase extends QpidTestCase
private File copyStore(String storeDirectoryName) throws Exception
{
- String src = getClass().getClassLoader().getResource("upgrade/" + storeDirectoryName).toURI().getPath();
File storeLocation = new File(new File(TMP_FOLDER), "test-store");
deleteDirectoryIfExists(storeLocation);
- FileUtils.copyRecursive(new File(src), new File(TMP_FOLDER));
+ storeLocation.mkdirs();
+ int index = 0;
+ String prefix = "0000000";
+ String extension = ".jdb";
+ InputStream is = null;
+ do
+ {
+ String fileName = prefix + index + extension;
+ is = getClass().getClassLoader().getResourceAsStream("upgrade/" + storeDirectoryName + "/test-store/" + fileName);
+ if (is != null)
+ {
+ FileUtils.copy(is, new File(storeLocation, fileName));
+ }
+ index++;
+ }
+ while (is != null);
return storeLocation;
}
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4to5Test.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4to5Test.java
index 65a8bb03fb..500fb0a919 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4to5Test.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4to5Test.java
@@ -20,6 +20,13 @@
*/
package org.apache.qpid.server.store.berkeleydb.upgrade;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.NONEXCLUSIVE_WITH_ERRONEOUS_OWNER;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.NON_DURABLE_QUEUE_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.QUEUE_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.QUEUE_WITH_DLQ_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.SELECTOR_TOPIC_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.TOPIC_NAME;
+
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
@@ -34,7 +41,6 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.BindingRecord;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.BindingTuple;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.MessageContentKey;
@@ -50,9 +56,6 @@ import com.sleepycat.je.Transaction;
public class UpgradeFrom4to5Test extends AbstractUpgradeTestCase
{
- private static final String NON_DURABLE_QUEUE = BDBStoreUpgradeTestPreparer.NON_DURABLE_QUEUE_NAME;
- private static final String DURABLE_QUEUE = BDBStoreUpgradeTestPreparer.QUEUE_NAME;
- private static final String NON_EXCLUSIVE_WITH_ERRONEOUS_OWNER = "nonexclusive-with-erroneous-owner";
private static final String DURABLE_SUBSCRIPTION_QUEUE_WITH_SELECTOR = "clientid:mySelectorDurSubName";
private static final String DURABLE_SUBSCRIPTION_QUEUE = "clientid:myDurSubName";
private static final String EXCHANGE_DB_NAME = "exchangeDb_v5";
@@ -85,15 +88,14 @@ public class UpgradeFrom4to5Test extends AbstractUpgradeTestCase
final List<BindingRecord> queueBindings = loadBindings();
- assertEquals("Unxpected list size", TOTAL_BINDINGS, queueBindings.size());
- assertBindingRecord(queueBindings, DURABLE_SUBSCRIPTION_QUEUE, "amq.topic", BDBStoreUpgradeTestPreparer.TOPIC_NAME, "");
- assertBindingRecord(queueBindings, DURABLE_SUBSCRIPTION_QUEUE_WITH_SELECTOR, "amq.topic",
- BDBStoreUpgradeTestPreparer.SELECTOR_TOPIC_NAME, "testprop='true'");
- assertBindingRecord(queueBindings, DURABLE_QUEUE, "amq.direct", DURABLE_QUEUE, null);
- assertBindingRecord(queueBindings, NON_DURABLE_QUEUE, "amq.direct", NON_DURABLE_QUEUE, null);
- assertBindingRecord(queueBindings, NON_EXCLUSIVE_WITH_ERRONEOUS_OWNER, "amq.direct", NON_EXCLUSIVE_WITH_ERRONEOUS_OWNER, null);
+ assertEquals("Unxpected bindings size", TOTAL_BINDINGS, queueBindings.size());
+ assertBindingRecord(queueBindings, DURABLE_SUBSCRIPTION_QUEUE, "amq.topic", TOPIC_NAME, "");
+ assertBindingRecord(queueBindings, DURABLE_SUBSCRIPTION_QUEUE_WITH_SELECTOR, "amq.topic", SELECTOR_TOPIC_NAME, "testprop='true'");
+ assertBindingRecord(queueBindings, QUEUE_NAME, "amq.direct", QUEUE_NAME, null);
+ assertBindingRecord(queueBindings, NON_DURABLE_QUEUE_NAME, "amq.direct", NON_DURABLE_QUEUE_NAME, null);
+ assertBindingRecord(queueBindings, NONEXCLUSIVE_WITH_ERRONEOUS_OWNER, "amq.direct", NONEXCLUSIVE_WITH_ERRONEOUS_OWNER, null);
- assertQueueHasOwner(NON_EXCLUSIVE_WITH_ERRONEOUS_OWNER, "misused-owner-as-description");
+ assertQueueHasOwner(NONEXCLUSIVE_WITH_ERRONEOUS_OWNER, "misused-owner-as-description");
assertContent();
}
@@ -102,26 +104,29 @@ public class UpgradeFrom4to5Test extends AbstractUpgradeTestCase
{
UpgradeFrom4To5 upgrade = new UpgradeFrom4To5();
upgrade.performUpgrade(_environment, new StaticAnswerHandler(UpgradeInteractionResponse.NO), getVirtualHostName());
- assertQueues(new HashSet<String>(Arrays.asList(DURABLE_SUBSCRIPTION_QUEUE, DURABLE_SUBSCRIPTION_QUEUE_WITH_SELECTOR, DURABLE_QUEUE, NON_EXCLUSIVE_WITH_ERRONEOUS_OWNER)));
+ HashSet<String> queues = new HashSet<String>(Arrays.asList(QUEUE_NAMES));
+ assertTrue(NON_DURABLE_QUEUE_NAME + " should be in the list of queues" , queues.remove(NON_DURABLE_QUEUE_NAME));
+
+ assertQueues(queues);
- assertDatabaseRecordCount(DELIVERY_DB_NAME, 12);
- assertDatabaseRecordCount(MESSAGE_META_DATA_DB_NAME, 12);
+ assertDatabaseRecordCount(DELIVERY_DB_NAME, 13);
+ assertDatabaseRecordCount(MESSAGE_META_DATA_DB_NAME, 13);
assertDatabaseRecordCount(EXCHANGE_DB_NAME, TOTAL_EXCHANGES);
assertQueueMessages(DURABLE_SUBSCRIPTION_QUEUE, 1);
assertQueueMessages(DURABLE_SUBSCRIPTION_QUEUE_WITH_SELECTOR, 1);
- assertQueueMessages(DURABLE_QUEUE, 10);
+ assertQueueMessages(QUEUE_NAME, 10);
+ assertQueueMessages(QUEUE_WITH_DLQ_NAME + "_DLQ", 1);
final List<BindingRecord> queueBindings = loadBindings();
assertEquals("Unxpected list size", TOTAL_BINDINGS - 2, queueBindings.size());
- assertBindingRecord(queueBindings, DURABLE_SUBSCRIPTION_QUEUE, "amq.topic", BDBStoreUpgradeTestPreparer.TOPIC_NAME,
- "");
+ assertBindingRecord(queueBindings, DURABLE_SUBSCRIPTION_QUEUE, "amq.topic", TOPIC_NAME, "");
assertBindingRecord(queueBindings, DURABLE_SUBSCRIPTION_QUEUE_WITH_SELECTOR, "amq.topic",
- BDBStoreUpgradeTestPreparer.SELECTOR_TOPIC_NAME, "testprop='true'");
- assertBindingRecord(queueBindings, DURABLE_QUEUE, "amq.direct", DURABLE_QUEUE, null);
+ SELECTOR_TOPIC_NAME, "testprop='true'");
+ assertBindingRecord(queueBindings, QUEUE_NAME, "amq.direct", QUEUE_NAME, null);
- assertQueueHasOwner(NON_EXCLUSIVE_WITH_ERRONEOUS_OWNER, "misused-owner-as-description");
+ assertQueueHasOwner(NONEXCLUSIVE_WITH_ERRONEOUS_OWNER, "misused-owner-as-description");
assertContent();
}
diff --git a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6Test.java b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6Test.java
index 2d2a6b20a2..c33d427868 100644
--- a/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6Test.java
+++ b/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6Test.java
@@ -20,6 +20,8 @@
*/
package org.apache.qpid.server.store.berkeleydb.upgrade;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.PRIORITY_QUEUE_NAME;
+import static org.apache.qpid.server.store.berkeleydb.BDBStoreUpgradeTestPreparer.QUEUE_WITH_DLQ_NAME;
import static org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CONFIGURED_OBJECTS_DB_NAME;
import static org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NEW_CONTENT_DB_NAME;
import static org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NEW_DELIVERY_DB_NAME;
@@ -42,6 +44,7 @@ import java.util.UUID;
import org.apache.log4j.Logger;
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.Queue;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.queue.AMQQueueFactory;
@@ -50,7 +53,6 @@ import org.apache.qpid.server.store.berkeleydb.tuple.XidBinding;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKey;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.CompoundKeyBinding;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.ConfiguredObjectBinding;
-import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.UpgradeConfiguredObjectRecord;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewDataBinding;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransactionBinding;
@@ -60,6 +62,7 @@ import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewRecord
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransactionBinding;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldRecordImpl;
+import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.UpgradeConfiguredObjectRecord;
import org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.UpgradeUUIDBinding;
import org.apache.qpid.server.util.MapJsonSerializer;
@@ -115,8 +118,8 @@ public class UpgradeFrom5To6Test extends AbstractUpgradeTestCase
upgrade.performUpgrade(_environment, discardMessageInteractionHandler, getVirtualHostName());
- assertDatabaseRecordCount(NEW_METADATA_DB_NAME, 11);
- assertDatabaseRecordCount(NEW_CONTENT_DB_NAME, 11);
+ assertDatabaseRecordCount(NEW_METADATA_DB_NAME, 12);
+ assertDatabaseRecordCount(NEW_CONTENT_DB_NAME, 12);
assertConfiguredObjects();
assertQueueEntries();
@@ -264,17 +267,17 @@ public class UpgradeFrom5To6Test extends AbstractUpgradeTestCase
private void assertDatabaseRecordCounts()
{
- assertDatabaseRecordCount(CONFIGURED_OBJECTS_DB_NAME, 12);
- assertDatabaseRecordCount(NEW_DELIVERY_DB_NAME, 12);
+ assertDatabaseRecordCount(CONFIGURED_OBJECTS_DB_NAME, 21);
+ assertDatabaseRecordCount(NEW_DELIVERY_DB_NAME, 13);
- assertDatabaseRecordCount(NEW_METADATA_DB_NAME, 12);
- assertDatabaseRecordCount(NEW_CONTENT_DB_NAME, 12);
+ assertDatabaseRecordCount(NEW_METADATA_DB_NAME, 13);
+ assertDatabaseRecordCount(NEW_CONTENT_DB_NAME, 13);
}
private void assertConfiguredObjects()
{
Map<UUID, UpgradeConfiguredObjectRecord> configuredObjects = loadConfiguredObjects();
- assertEquals("Unexpected number of configured objects", 12, configuredObjects.size());
+ assertEquals("Unexpected number of configured objects", 21, configuredObjects.size());
Set<Map<String, Object>> expected = new HashSet<Map<String, Object>>(12);
List<UUID> expectedBindingIDs = new ArrayList<UUID>();
@@ -282,8 +285,26 @@ public class UpgradeFrom5To6Test extends AbstractUpgradeTestCase
expected.add(createExpectedQueueMap("myUpgradeQueue", Boolean.FALSE, null, null));
expected.add(createExpectedQueueMap("clientid:mySelectorDurSubName", Boolean.TRUE, "clientid", null));
expected.add(createExpectedQueueMap("clientid:myDurSubName", Boolean.TRUE, "clientid", null));
- expected.add(createExpectedQueueMap("nonexclusive-with-erroneous-owner", Boolean.FALSE, null,
- Collections.singletonMap(AMQQueueFactory.X_QPID_DESCRIPTION, "misused-owner-as-description")));
+
+ final Map<String, Object> queueWithOwnerArguments = new HashMap<String, Object>();
+ queueWithOwnerArguments.put("x-qpid-priorities", 10);
+ queueWithOwnerArguments.put(AMQQueueFactory.X_QPID_DESCRIPTION, "misused-owner-as-description");
+ expected.add(createExpectedQueueMap("nonexclusive-with-erroneous-owner", Boolean.FALSE, null,queueWithOwnerArguments));
+
+ final Map<String, Object> priorityQueueArguments = new HashMap<String, Object>();
+ priorityQueueArguments.put("x-qpid-priorities", 10);
+ expected.add(createExpectedQueueMap(PRIORITY_QUEUE_NAME, Boolean.FALSE, null, priorityQueueArguments));
+
+ final Map<String, Object> queueWithDLQArguments = new HashMap<String, Object>();
+ queueWithDLQArguments.put("x-qpid-dlq-enabled", true);
+ queueWithDLQArguments.put("x-qpid-maximum-delivery-count", 2);
+ expected.add(createExpectedQueueMap(QUEUE_WITH_DLQ_NAME, Boolean.FALSE, null, queueWithDLQArguments));
+
+ final Map<String, Object> dlqArguments = new HashMap<String, Object>();
+ dlqArguments.put("x-qpid-dlq-enabled", false);
+ dlqArguments.put("x-qpid-maximum-delivery-count", 0);
+ expected.add(createExpectedQueueMap(QUEUE_WITH_DLQ_NAME + "_DLQ", Boolean.FALSE, null, dlqArguments));
+ expected.add(createExpectedExchangeMap(QUEUE_WITH_DLQ_NAME + "_DLE", "fanout"));
expected.add(createExpectedQueueBindingMapAndID("myUpgradeQueue","myUpgradeQueue", "<<default>>", null, expectedBindingIDs));
expected.add(createExpectedQueueBindingMapAndID("myUpgradeQueue", "myUpgradeQueue", "amq.direct", null, expectedBindingIDs));
@@ -296,6 +317,13 @@ public class UpgradeFrom5To6Test extends AbstractUpgradeTestCase
expected.add(createExpectedQueueBindingMapAndID("nonexclusive-with-erroneous-owner", "nonexclusive-with-erroneous-owner", "amq.direct", null, expectedBindingIDs));
expected.add(createExpectedQueueBindingMapAndID("nonexclusive-with-erroneous-owner","nonexclusive-with-erroneous-owner", "<<default>>", null, expectedBindingIDs));
+ expected.add(createExpectedQueueBindingMapAndID(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_NAME, "<<default>>", null, expectedBindingIDs));
+ expected.add(createExpectedQueueBindingMapAndID(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_NAME, "amq.direct", null, expectedBindingIDs));
+
+ expected.add(createExpectedQueueBindingMapAndID(QUEUE_WITH_DLQ_NAME, QUEUE_WITH_DLQ_NAME, "<<default>>", null, expectedBindingIDs));
+ expected.add(createExpectedQueueBindingMapAndID(QUEUE_WITH_DLQ_NAME, QUEUE_WITH_DLQ_NAME, "amq.direct", null, expectedBindingIDs));
+ expected.add(createExpectedQueueBindingMapAndID(QUEUE_WITH_DLQ_NAME + "_DLQ", "dlq", QUEUE_WITH_DLQ_NAME + "_DLE", null, expectedBindingIDs));
+
Set<String> expectedTypes = new HashSet<String>();
expectedTypes.add(Queue.class.getName());
expectedTypes.add(Exchange.class.getName());
@@ -305,7 +333,9 @@ public class UpgradeFrom5To6Test extends AbstractUpgradeTestCase
{
UpgradeConfiguredObjectRecord object = entry.getValue();
Map<String, Object> deserialized = jsonSerializer.deserialize(object.getAttributes());
- assertTrue("Unexpected entry:" + object.getAttributes(), expected.remove(deserialized));
+
+ assertTrue("Unexpected entry in a store - json [" + object.getAttributes() + "], map [" + deserialized + "]",
+ expected.remove(deserialized));
String type = object.getType();
assertTrue("Unexpected type:" + type, expectedTypes.contains(type));
UUID key = entry.getKey();
@@ -350,7 +380,7 @@ public class UpgradeFrom5To6Test extends AbstractUpgradeTestCase
return expectedQueueBinding;
}
- private Map<String, Object> createExpectedQueueMap(String name, boolean exclusiveFlag, String owner, Map<String, String> argumentMap)
+ private Map<String, Object> createExpectedQueueMap(String name, boolean exclusiveFlag, String owner, Map<String, Object> argumentMap)
{
Map<String, Object> expectedQueueEntry = new HashMap<String, Object>();
expectedQueueEntry.put(Queue.NAME, name);
@@ -363,6 +393,15 @@ public class UpgradeFrom5To6Test extends AbstractUpgradeTestCase
return expectedQueueEntry;
}
+ private Map<String, Object> createExpectedExchangeMap(String name, String type)
+ {
+ Map<String, Object> expectedExchnageEntry = new HashMap<String, Object>();
+ expectedExchnageEntry.put(Exchange.NAME, name);
+ expectedExchnageEntry.put(Exchange.TYPE, type);
+ expectedExchnageEntry.put(Exchange.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name());
+ return expectedExchnageEntry;
+ }
+
private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects()
{
final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
diff --git a/java/bdbstore/src/test/resources/upgrade/bdbstore-v4/test-store/00000000.jdb b/java/bdbstore/src/test/resources/upgrade/bdbstore-v4/test-store/00000000.jdb
index f5ed9aa5a2..cfc1f05d28 100644
--- a/java/bdbstore/src/test/resources/upgrade/bdbstore-v4/test-store/00000000.jdb
+++ b/java/bdbstore/src/test/resources/upgrade/bdbstore-v4/test-store/00000000.jdb
Binary files differ
diff --git a/java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000000.jdb b/java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000000.jdb
index f5ed9aa5a2..cfc1f05d28 100644
--- a/java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000000.jdb
+++ b/java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000000.jdb
Binary files differ
diff --git a/java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000001.jdb b/java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000001.jdb
index d5ae8c1096..4b45ff61e6 100644
--- a/java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000001.jdb
+++ b/java/bdbstore/src/test/resources/upgrade/bdbstore-v5/test-store/00000001.jdb
Binary files differ
diff --git a/java/broker-plugins/access-control/MANIFEST.MF b/java/broker-plugins/access-control/MANIFEST.MF
deleted file mode 100644
index a8fb99995e..0000000000
--- a/java/broker-plugins/access-control/MANIFEST.MF
+++ /dev/null
@@ -1,41 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Qpid Broker-Plugins Access Control
-Bundle-SymbolicName: broker-plugins-access-control
-Bundle-Description: Access control plugin for Qpid.
-Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
-Bundle-DocURL: http://qpid.apache.org/acl.html
-Bundle-Version: 1.0.0
-Bundle-Activator: org.apache.qpid.server.security.access.plugins.AccessControlActivator
-Bundle-RequiredExecutionEnvironment: JavaSE-1.5
-Bundle-ClassPath: .
-Bundle-ActivationPolicy: lazy
-Import-Package: org.apache.qpid,
- org.apache.qpid.exchange,
- org.apache.qpid.framing,
- org.apache.qpid.protocol,
- org.apache.qpid.server.configuration,
- org.apache.qpid.server.configuration.plugins,
- org.apache.qpid.server.exchange,
- org.apache.qpid.server.logging,
- org.apache.qpid.server.logging.actors,
- org.apache.qpid.server.logging.subjects,
- org.apache.qpid.server.plugins,
- org.apache.qpid.server.queue,
- org.apache.qpid.server.registry,
- org.apache.qpid.server.security,
- org.apache.qpid.server.security.access,
- org.apache.qpid.server.virtualhost,
- org.apache.qpid.util,
- org.apache.commons.configuration;version=1.0.0,
- org.apache.commons.lang;version=1.0.0,
- org.apache.commons.lang.builder;version=1.0.0,
- org.apache.log4j;version=1.0.0,
- javax.management;version=1.0.0,
- javax.management.openmbean;version=1.0.0,
- javax.security.auth;version=1.0.0,
- org.osgi.util.tracker;version=1.0.0,
- org.osgi.framework;version=1.3
-Private-Package: org.apache.qpid.server.security.access.config,
- org.apache.qpid.server.security.access.logging
-Export-Package: org.apache.qpid.server.security.access.plugins
diff --git a/java/broker-plugins/access-control/build.xml b/java/broker-plugins/access-control/build.xml
index df3346788c..4debdcb95a 100644
--- a/java/broker-plugins/access-control/build.xml
+++ b/java/broker-plugins/access-control/build.xml
@@ -18,13 +18,13 @@
-->
<project name="Qpid Broker-Plugins Access Control" default="build">
<property name="module.depends" value="common broker" />
- <property name="module.test.depends" value="test common/test broker/test management/common systests" />
+ <property name="module.test.depends" value="common/tests broker/tests management/common" />
- <property name="module.manifest" value="MANIFEST.MF" />
- <property name="module.plugin" value="true" />
<property name="module.genpom" value="true"/>
<property name="module.genpom.args" value="-Sqpid-common=provided -Sqpid-broker=provided"/>
+ <property name="broker.plugin" value="true"/>
+
<property name="broker-plugins-access-control.libs" value=""/>
<import file="../../module.xml" />
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java
index f04dd38aca..f87374ac80 100644
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AbstractConfiguration.java
@@ -22,13 +22,8 @@ package org.apache.qpid.server.security.access.config;
import java.io.File;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-
public abstract class AbstractConfiguration implements ConfigurationFile
{
- private static final Logger _logger = Logger.getLogger(ConfigurationFile.class);
-
private File _file;
private RuleSet _config;
@@ -42,7 +37,7 @@ public abstract class AbstractConfiguration implements ConfigurationFile
return _file;
}
- public RuleSet load() throws ConfigurationException
+ public RuleSet load()
{
_config = new RuleSet();
return _config;
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AclAction.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AclAction.java
new file mode 100644
index 0000000000..e4bf21a082
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AclAction.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.server.security.access.config;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectType;
+import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.access.firewall.FirewallRule;
+
+public class AclAction
+{
+ private Action _action;
+ private FirewallRule _firewallRule;
+
+ public AclAction(Operation operation, ObjectType object, AclRulePredicates predicates)
+ {
+ _action = new Action(operation, object, predicates.getObjectProperties());
+ _firewallRule = predicates.getFirewallRule();
+ }
+
+ public AclAction(Operation operation)
+ {
+ _action = new Action(operation);
+ }
+
+ public AclAction(Operation operation, ObjectType object, ObjectProperties properties)
+ {
+ _action = new Action(operation, object, properties);
+ }
+
+ public FirewallRule getFirewallRule()
+ {
+ return _firewallRule;
+ }
+
+ public Action getAction()
+ {
+ return _action;
+ }
+
+ public boolean isAllowed()
+ {
+ return _action.isAllowed();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder()
+ .append(_action)
+ .append(_firewallRule).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj.getClass() != getClass())
+ {
+ return false;
+ }
+ AclAction rhs = (AclAction) obj;
+ return new EqualsBuilder()
+ .append(_action, rhs._action)
+ .append(_firewallRule, rhs._firewallRule).isEquals();
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append(_action)
+ .append(_firewallRule).toString();
+ }
+}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AclRulePredicates.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AclRulePredicates.java
new file mode 100644
index 0000000000..45af85be6c
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/AclRulePredicates.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.server.security.access.config;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectProperties.Property;
+import org.apache.qpid.server.security.access.firewall.FirewallRule;
+import org.apache.qpid.server.security.access.firewall.FirewallRuleFactory;
+
+/**
+ * Represents the predicates on an ACL rule by combining predicates relating to the object being operated on
+ * (e.g. name=foo) with firewall rules.
+ */
+public class AclRulePredicates
+{
+ private static final Logger _logger = Logger.getLogger(AclRulePredicates.class);
+
+ private static final String SEPARATOR = ",";
+
+ private ObjectProperties _properties = new ObjectProperties();
+
+ private FirewallRule _firewallRule;
+
+ private FirewallRuleFactory _firewallRuleFactory = new FirewallRuleFactory();
+
+ public void parse(String key, String value)
+ {
+ ObjectProperties.Property property = ObjectProperties.Property.parse(key);
+
+ if(property == Property.FROM_HOSTNAME)
+ {
+ checkFirewallRuleNotAlreadyDefined(key, value);
+ _firewallRule = _firewallRuleFactory.createForHostname(value.split(SEPARATOR));
+ }
+ else if(property == Property.FROM_NETWORK)
+ {
+ checkFirewallRuleNotAlreadyDefined(key, value);
+ _firewallRule = _firewallRuleFactory.createForNetwork(value.split(SEPARATOR));
+ }
+ else
+ {
+ _properties.put(property, value);
+ }
+
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Parsed " + property + " with value " + value);
+ }
+ }
+
+ private void checkFirewallRuleNotAlreadyDefined(String key, String value)
+ {
+ if(_firewallRule != null)
+ {
+ throw new IllegalStateException(
+ "Cannot parse " + key + "=" + value
+ + " because firewall rule " + _firewallRule + " has already been defined");
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append(_properties)
+ .append(_firewallRule).toString();
+ }
+
+ public FirewallRule getFirewallRule()
+ {
+ return _firewallRule;
+ }
+
+ public ObjectProperties getObjectProperties()
+ {
+ return _properties;
+ }
+
+ void setFirewallRuleFactory(FirewallRuleFactory firewallRuleFactory)
+ {
+ _firewallRuleFactory = firewallRuleFactory;
+ }
+}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Action.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Action.java
index b887d1e079..4fff0bebf5 100644
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Action.java
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Action.java
@@ -20,8 +20,6 @@
*/
package org.apache.qpid.server.security.access.config;
-import java.util.Comparator;
-
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
@@ -32,7 +30,7 @@ import org.apache.qpid.server.security.access.Operation;
/**
* An access control v2 rule action.
- *
+ *
* An action consists of an {@link Operation} on an {@link ObjectType} with certain properties, stored in a {@link java.util.Map}.
* The operation and object should be an allowable combination, based on the {@link ObjectType#isAllowed(Operation)}
* method of the object, which is exposed as the {@link #isAllowed()} method here. The internal {@link #propertiesMatch(Map)}
@@ -45,104 +43,96 @@ import org.apache.qpid.server.security.access.Operation;
*/
public class Action
{
- private Operation _operation;
- private ObjectType _object;
- private ObjectProperties _properties;
-
+ private final Operation _operation;
+ private final ObjectType _object;
+ private final ObjectProperties _properties;
+
public Action(Operation operation)
{
this(operation, ObjectType.ALL);
}
-
+
public Action(Operation operation, ObjectType object, String name)
{
this(operation, object, new ObjectProperties(name));
}
-
+
public Action(Operation operation, ObjectType object)
{
this(operation, object, ObjectProperties.EMPTY);
}
-
+
public Action(Operation operation, ObjectType object, ObjectProperties properties)
{
- setOperation(operation);
- setObjectType(object);
- setProperties(properties);
+ _operation = operation;
+ _object = object;
+ _properties = properties;
}
-
+
public Operation getOperation()
{
return _operation;
}
- public void setOperation(Operation operation)
- {
- _operation = operation;
- }
-
public ObjectType getObjectType()
{
return _object;
}
- public void setObjectType(ObjectType object)
- {
- _object = object;
- }
-
public ObjectProperties getProperties()
{
return _properties;
}
-
- public void setProperties(ObjectProperties properties)
- {
- _properties = properties;
- }
-
+
public boolean isAllowed()
{
return _object.isAllowed(_operation);
}
- /** @see Comparable#compareTo(Object) */
public boolean matches(Action a)
{
- return ((Operation.ALL == a.getOperation() || getOperation() == a.getOperation())
- && (ObjectType.ALL == a.getObjectType() || getObjectType() == a.getObjectType())
- && _properties.matches(a.getProperties()));
+ if (!operationsMatch(a))
+ {
+ return false;
+ }
+
+ if (!objectTypesMatch(a))
+ {
+ return false;
+ }
+
+ if (!propertiesMatch(a))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean operationsMatch(Action a)
+ {
+ return Operation.ALL == a.getOperation() || getOperation() == a.getOperation();
}
- /**
- * An ordering based on specificity
- *
- * @see Comparator#compare(Object, Object)
- */
- public class Specificity implements Comparator<Action>
+ private boolean objectTypesMatch(Action a)
{
- public int compare(Action a, Action b)
+ return ObjectType.ALL == a.getObjectType() || getObjectType() == a.getObjectType();
+ }
+
+ private boolean propertiesMatch(Action a)
+ {
+ boolean propertiesMatch = false;
+ if (_properties != null)
+ {
+ propertiesMatch = _properties.matches(a.getProperties());
+ }
+ else if (a.getProperties() == null)
{
- if (a.getOperation() == Operation.ALL && b.getOperation() != Operation.ALL)
- {
- return 1; // B is more specific
- }
- else if (b.getOperation() == Operation.ALL && a.getOperation() != Operation.ALL)
- {
- return 1; // A is more specific
- }
- else if (a.getOperation() == b.getOperation())
- {
- return 1; // b is more specific
- }
- else // Different operations
- {
- return a.getOperation().compareTo(b.getOperation()); // Arbitrary
- }
+ propertiesMatch = true;
}
+ return propertiesMatch;
}
- /** @see Object#equals(Object) */
@Override
public boolean equals(Object o)
{
@@ -151,26 +141,24 @@ public class Action
return false;
}
Action a = (Action) o;
-
+
return new EqualsBuilder()
.append(_operation, a.getOperation())
.append(_object, a.getObjectType())
- .appendSuper(_properties.equals(a.getProperties()))
+ .append(_properties, a.getProperties())
.isEquals();
}
- /** @see Object#hashCode() */
@Override
public int hashCode()
{
return new HashCodeBuilder()
.append(_operation)
- .append(_operation)
+ .append(_object)
.append(_properties)
.toHashCode();
}
- /** @see Object#toString() */
@Override
public String toString()
{
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ClientAction.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ClientAction.java
new file mode 100644
index 0000000000..fed20a56c8
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ClientAction.java
@@ -0,0 +1,88 @@
+/*
+ * 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.security.access.config;
+
+import java.net.InetAddress;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectType;
+import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.access.firewall.FirewallRule;
+
+/**
+ * I represent an {@link Action} taken by a client from a known address. The address is used to
+ * determine if I match an {@link AclAction}, which may contain firewall rules.
+ */
+public class ClientAction
+{
+ private Action _clientAction;
+
+ public ClientAction(Action clientAction)
+ {
+ _clientAction = clientAction;
+ }
+
+ public ClientAction(Operation operation, ObjectType objectType, ObjectProperties properties)
+ {
+ _clientAction = new Action(operation, objectType, properties);
+ }
+
+ public boolean matches(AclAction ruleAction, InetAddress addressOfClient)
+ {
+ return _clientAction.matches(ruleAction.getAction())
+ && addressOfClientMatches(ruleAction, addressOfClient);
+ }
+
+ private boolean addressOfClientMatches(AclAction ruleAction, InetAddress addressOfClient)
+ {
+ FirewallRule firewallRule = ruleAction.getFirewallRule();
+ if(firewallRule == null || addressOfClient == null)
+ {
+ return true;
+ }
+ else
+ {
+ return firewallRule.matches(addressOfClient);
+ }
+ }
+
+ public Operation getOperation()
+ {
+ return _clientAction.getOperation();
+ }
+
+ public ObjectType getObjectType()
+ {
+ return _clientAction.getObjectType();
+ }
+
+ public ObjectProperties getProperties()
+ {
+ return _clientAction.getProperties();
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append(_clientAction).toString();
+ }
+}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java
index 8b1a00259b..966c32e24e 100644
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ConfigurationFile.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.security.access.config;
import java.io.File;
-import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
public interface ConfigurationFile
{
@@ -33,19 +33,17 @@ public interface ConfigurationFile
/**
* Load this configuration file's contents into a {@link RuleSet}.
- *
- * @throws ConfigurationException if the configuration file has errors.
+ * @throws IllegalConfigurationException if the configuration file has errors.
* @throws IllegalArgumentException if individual tokens cannot be parsed.
*/
- RuleSet load() throws ConfigurationException;
+ RuleSet load() throws IllegalConfigurationException;
/**
* Reload this configuration file's contents.
- *
- * @throws ConfigurationException if the configuration file has errors.
+ * @throws IllegalConfigurationException if the configuration file has errors.
* @throws IllegalArgumentException if individual tokens cannot be parsed.
*/
- RuleSet reload() throws ConfigurationException;
+ RuleSet reload() throws IllegalConfigurationException;
RuleSet getConfiguration();
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java
index 9a08eb6499..ab309c54ce 100644
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/PlainConfiguration.java
@@ -1,5 +1,5 @@
/*
- *
+ *
* 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
@@ -7,16 +7,16 @@
* 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.security.access.config;
@@ -32,55 +32,65 @@ import java.util.List;
import java.util.Map;
import java.util.Stack;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.lang.StringUtils;
-import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.security.access.ObjectType;
import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.security.access.Permission;
public class PlainConfiguration extends AbstractConfiguration
{
+ private static final Logger _logger = Logger.getLogger(PlainConfiguration.class);
+
public static final Character COMMENT = '#';
public static final Character CONTINUATION = '\\';
- public static final String GROUP = "group";
public static final String ACL = "acl";
public static final String CONFIG = "config";
- public static final String UNRECOGNISED_INITIAL_MSG = "Unrecognised initial token '%s' at line %d";
- public static final String NOT_ENOUGH_TOKENS_MSG = "Not enough tokens at line %d";
- public static final String NUMBER_NOT_ALLOWED_MSG = "Number not allowed before '%s' at line %d";
- public static final String CANNOT_LOAD_MSG = "Cannot load config file %s";
- public static final String PREMATURE_CONTINUATION_MSG = "Premature continuation character at line %d";
- public static final String PREMATURE_EOF_MSG = "Premature end of file reached at line %d";
- public static final String PARSE_TOKEN_FAILED_MSG = "Failed to parse token at line %d";
- public static final String CONFIG_NOT_FOUND_MSG = "Cannot find config file %s";
- public static final String NOT_ENOUGH_GROUP_MSG = "Not enough data for a group at line %d";
- public static final String NOT_ENOUGH_ACL_MSG = "Not enough data for an acl at line %d";
- public static final String NOT_ENOUGH_CONFIG_MSG = "Not enough data for config at line %d";
- public static final String BAD_ACL_RULE_NUMBER_MSG = "Invalid rule number at line %d";
- public static final String PROPERTY_KEY_ONLY_MSG = "Incomplete property (key only) at line %d";
- public static final String PROPERTY_NO_EQUALS_MSG = "Incomplete property (no equals) at line %d";
- public static final String PROPERTY_NO_VALUE_MSG = "Incomplete property (no value) at line %d";
-
+ static final String UNRECOGNISED_INITIAL_MSG = "Unrecognised initial token '%s' at line %d";
+ static final String NOT_ENOUGH_TOKENS_MSG = "Not enough tokens at line %d";
+ static final String NUMBER_NOT_ALLOWED_MSG = "Number not allowed before '%s' at line %d";
+ static final String CANNOT_LOAD_MSG = "Cannot load config file %s";
+ static final String CANNOT_CLOSE_MSG = "Cannot close config file %s";
+ static final String PREMATURE_CONTINUATION_MSG = "Premature continuation character at line %d";
+ static final String PREMATURE_EOF_MSG = "Premature end of file reached at line %d";
+ static final String PARSE_TOKEN_FAILED_MSG = "Failed to parse token at line %d";
+ static final String CONFIG_NOT_FOUND_MSG = "Cannot find config file %s";
+ static final String NOT_ENOUGH_ACL_MSG = "Not enough data for an acl at line %d";
+ static final String NOT_ENOUGH_CONFIG_MSG = "Not enough data for config at line %d";
+ static final String BAD_ACL_RULE_NUMBER_MSG = "Invalid rule number at line %d";
+ static final String PROPERTY_KEY_ONLY_MSG = "Incomplete property (key only) at line %d";
+ static final String PROPERTY_NO_EQUALS_MSG = "Incomplete property (no equals) at line %d";
+ static final String PROPERTY_NO_VALUE_MSG = "Incomplete property (no value) at line %d";
+
private StreamTokenizer _st;
public PlainConfiguration(File file)
{
super(file);
}
-
+
@Override
- public RuleSet load() throws ConfigurationException
+ public RuleSet load()
{
RuleSet ruleSet = super.load();
-
+
+ File file = getFile();
+ FileReader fileReader = null;
+
try
{
- _st = new StreamTokenizer(new BufferedReader(new FileReader(getFile())));
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("About to load ACL file " + file);
+ }
+
+ fileReader = new FileReader(file);
+ _st = new StreamTokenizer(new BufferedReader(fileReader));
_st.resetSyntax(); // setup the tokenizer
-
+
_st.commentChar(COMMENT); // single line comments
_st.eolIsSignificant(true); // return EOL as a token
_st.ordinaryChar('='); // equals is a token
@@ -97,7 +107,7 @@ public class PlainConfiguration extends AbstractConfiguration
_st.wordChars('*', '*'); // star
_st.wordChars('@', '@'); // at
_st.wordChars(':', ':'); // colon
-
+
// parse the acl file lines
Stack<String> stack = new Stack<String>();
int current;
@@ -111,21 +121,21 @@ public class PlainConfiguration extends AbstractConfiguration
{
break; // blank line
}
-
+
// pull out the first token from the bottom of the stack and check arguments exist
String first = stack.firstElement();
stack.removeElementAt(0);
if (stack.isEmpty())
{
- throw new ConfigurationException(String.format(NOT_ENOUGH_TOKENS_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(NOT_ENOUGH_TOKENS_MSG, getLine()));
}
-
+
// check for and parse optional initial number for ACL lines
Integer number = null;
if (StringUtils.isNumeric(first))
{
// set the acl number and get the next element
- number = Integer.valueOf(first);
+ number = Integer.valueOf(first);
first = stack.firstElement();
stack.removeElementAt(0);
}
@@ -136,9 +146,9 @@ public class PlainConfiguration extends AbstractConfiguration
}
else if (number == null)
{
- if (StringUtils.equalsIgnoreCase(GROUP, first))
+ if(StringUtils.equalsIgnoreCase("GROUP", first))
{
- parseGroup(stack);
+ throw new IllegalConfigurationException(String.format("GROUP keyword not supported. Groups should defined via a Group Provider, not in the ACL file.", getLine()));
}
else if (StringUtils.equalsIgnoreCase(CONFIG, first))
{
@@ -146,14 +156,14 @@ public class PlainConfiguration extends AbstractConfiguration
}
else
{
- throw new ConfigurationException(String.format(UNRECOGNISED_INITIAL_MSG, first, getLine()));
+ throw new IllegalConfigurationException(String.format(UNRECOGNISED_INITIAL_MSG, first, getLine()));
}
}
else
{
- throw new ConfigurationException(String.format(NUMBER_NOT_ALLOWED_MSG, first, getLine()));
+ throw new IllegalConfigurationException(String.format(NUMBER_NOT_ALLOWED_MSG, first, getLine()));
}
-
+
// reset stack, start next line
stack.clear();
break;
@@ -171,9 +181,9 @@ public class PlainConfiguration extends AbstractConfiguration
{
break; // continue reading next line
}
-
+
// invalid location for continuation character (add one to line beacuse we ate the EOL)
- throw new ConfigurationException(String.format(PREMATURE_CONTINUATION_MSG, getLine() + 1));
+ throw new IllegalConfigurationException(String.format(PREMATURE_CONTINUATION_MSG, getLine() + 1));
}
else if (_st.ttype == '\'' || _st.ttype == '"')
{
@@ -185,54 +195,59 @@ public class PlainConfiguration extends AbstractConfiguration
}
}
} while (current != StreamTokenizer.TT_EOF);
-
+
if (!stack.isEmpty())
{
- throw new ConfigurationException(String.format(PREMATURE_EOF_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PREMATURE_EOF_MSG, getLine()));
}
}
catch (IllegalArgumentException iae)
{
- throw new ConfigurationException(String.format(PARSE_TOKEN_FAILED_MSG, getLine()), iae);
+ throw new IllegalConfigurationException(String.format(PARSE_TOKEN_FAILED_MSG, getLine()), iae);
}
catch (FileNotFoundException fnfe)
{
- throw new ConfigurationException(String.format(CONFIG_NOT_FOUND_MSG, getFile().getName()), fnfe);
+ throw new IllegalConfigurationException(String.format(CONFIG_NOT_FOUND_MSG, file.getName()), fnfe);
}
catch (IOException ioe)
{
- throw new ConfigurationException(String.format(CANNOT_LOAD_MSG, getFile().getName()), ioe);
+ throw new IllegalConfigurationException(String.format(CANNOT_LOAD_MSG, file.getName()), ioe);
}
-
- return ruleSet;
- }
-
- private void parseGroup(List<String> args) throws ConfigurationException
- {
- if (args.size() < 2)
+ finally
{
- throw new ConfigurationException(String.format(NOT_ENOUGH_GROUP_MSG, getLine()));
+ if(fileReader != null)
+ {
+ try
+ {
+ fileReader.close();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException(String.format(CANNOT_CLOSE_MSG, file.getName()), e);
+ }
+ }
}
-
- getConfiguration().addGroup(args.get(0), args.subList(1, args.size()));
+
+
+ return ruleSet;
}
-
- private void parseAcl(Integer number, List<String> args) throws ConfigurationException
+
+ private void parseAcl(Integer number, List<String> args)
{
if (args.size() < 3)
{
- throw new ConfigurationException(String.format(NOT_ENOUGH_ACL_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(NOT_ENOUGH_ACL_MSG, getLine()));
}
Permission permission = Permission.parse(args.get(0));
String identity = args.get(1);
Operation operation = Operation.parse(args.get(2));
-
+
if (number != null && !getConfiguration().isValidNumber(number))
{
- throw new ConfigurationException(String.format(BAD_ACL_RULE_NUMBER_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(BAD_ACL_RULE_NUMBER_MSG, getLine()));
}
-
+
if (args.size() == 3)
{
getConfiguration().grant(number, identity, permission, operation);
@@ -240,55 +255,52 @@ public class PlainConfiguration extends AbstractConfiguration
else
{
ObjectType object = ObjectType.parse(args.get(3));
- ObjectProperties properties = toObjectProperties(args.subList(4, args.size()));
+ AclRulePredicates predicates = toRulePredicates(args.subList(4, args.size()));
- getConfiguration().grant(number, identity, permission, operation, object, properties);
+ getConfiguration().grant(number, identity, permission, operation, object, predicates);
}
}
-
- private void parseConfig(List<String> args) throws ConfigurationException
+
+ private void parseConfig(List<String> args)
{
if (args.size() < 3)
{
- throw new ConfigurationException(String.format(NOT_ENOUGH_CONFIG_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(NOT_ENOUGH_CONFIG_MSG, getLine()));
}
Map<String, Boolean> properties = toPluginProperties(args);
-
+
getConfiguration().configure(properties);
}
-
- /** Converts a {@link List} of "name", "=", "value" tokens into a {@link Map}. */
- protected ObjectProperties toObjectProperties(List<String> args) throws ConfigurationException
+
+ private AclRulePredicates toRulePredicates(List<String> args)
{
- ObjectProperties properties = new ObjectProperties();
+ AclRulePredicates predicates = new AclRulePredicates();
Iterator<String> i = args.iterator();
while (i.hasNext())
{
String key = i.next();
if (!i.hasNext())
{
- throw new ConfigurationException(String.format(PROPERTY_KEY_ONLY_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_KEY_ONLY_MSG, getLine()));
}
if (!"=".equals(i.next()))
{
- throw new ConfigurationException(String.format(PROPERTY_NO_EQUALS_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_NO_EQUALS_MSG, getLine()));
}
if (!i.hasNext())
{
- throw new ConfigurationException(String.format(PROPERTY_NO_VALUE_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_NO_VALUE_MSG, getLine()));
}
String value = i.next();
-
- // parse property key
- ObjectProperties.Property property = ObjectProperties.Property.parse(key);
- properties.put(property, value);
+
+ predicates.parse(key, value);
}
- return properties;
+ return predicates;
}
-
+
/** Converts a {@link List} of "name", "=", "value" tokens into a {@link Map}. */
- protected Map<String, Boolean> toPluginProperties(List<String> args) throws ConfigurationException
+ protected Map<String, Boolean> toPluginProperties(List<String> args)
{
Map<String, Boolean> properties = new HashMap<String, Boolean>();
Iterator<String> i = args.iterator();
@@ -297,24 +309,24 @@ public class PlainConfiguration extends AbstractConfiguration
String key = i.next().toLowerCase();
if (!i.hasNext())
{
- throw new ConfigurationException(String.format(PROPERTY_KEY_ONLY_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_KEY_ONLY_MSG, getLine()));
}
if (!"=".equals(i.next()))
{
- throw new ConfigurationException(String.format(PROPERTY_NO_EQUALS_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_NO_EQUALS_MSG, getLine()));
}
if (!i.hasNext())
{
- throw new ConfigurationException(String.format(PROPERTY_NO_VALUE_MSG, getLine()));
+ throw new IllegalConfigurationException(String.format(PROPERTY_NO_VALUE_MSG, getLine()));
}
-
+
// parse property value and save
Boolean value = Boolean.valueOf(i.next());
properties.put(key, value);
}
return properties;
}
-
+
protected int getLine()
{
return _st.lineno() - 1;
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Rule.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Rule.java
index 15d6b67192..cef9a8696b 100644
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Rule.java
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/Rule.java
@@ -29,7 +29,7 @@ import org.apache.qpid.server.security.access.Permission;
/**
* An access control v2 rule.
- *
+ *
* A rule consists of {@link Permission} for a particular identity to perform an {@link Action}. The identity
* may be either a user or a group.
*/
@@ -37,41 +37,41 @@ public class Rule implements Comparable<Rule>
{
/** String indicating all identitied. */
public static final String ALL = "all";
-
+
private Integer _number;
private Boolean _enabled = Boolean.TRUE;
private String _identity;
- private Action _action;
+ private AclAction _action;
private Permission _permission;
-
- public Rule(Integer number, String identity, Action action, Permission permission)
+
+ public Rule(Integer number, String identity, AclAction action, Permission permission)
{
setNumber(number);
setIdentity(identity);
setAction(action);
setPermission(permission);
}
-
- public Rule(String identity, Action action, Permission permission)
+
+ public Rule(String identity, AclAction action, Permission permission)
{
this(null, identity, action, permission);
}
-
+
public boolean isEnabled()
{
return _enabled;
}
-
+
public void setEnabled(boolean enabled)
{
_enabled = enabled;
}
-
+
public void enable()
{
_enabled = Boolean.TRUE;
}
-
+
public void disable()
{
_enabled = Boolean.FALSE;
@@ -96,13 +96,18 @@ public class Rule implements Comparable<Rule>
{
_identity = identity;
}
-
+
public Action getAction()
{
+ return _action.getAction();
+ }
+
+ public AclAction getAclAction()
+ {
return _action;
}
- public void setAction(Action action)
+ public void setAction(AclAction action)
{
_action = action;
}
@@ -117,7 +122,7 @@ public class Rule implements Comparable<Rule>
_permission = permission;
}
- /** @see Comparable#compareTo(Object) */
+ @Override
public int compareTo(Rule r)
{
return new CompareToBuilder()
@@ -127,7 +132,6 @@ public class Rule implements Comparable<Rule>
.toComparison();
}
- /** @see Object#equals(Object) */
@Override
public boolean equals(Object o)
{
@@ -136,33 +140,31 @@ public class Rule implements Comparable<Rule>
return false;
}
Rule r = (Rule) o;
-
+
return new EqualsBuilder()
.append(getIdentity(), r.getIdentity())
- .append(getAction(), r.getAction())
+ .append(getAclAction(), r.getAclAction())
.append(getPermission(), r.getPermission())
.isEquals();
}
- /** @see Object#hashCode() */
@Override
public int hashCode()
{
return new HashCodeBuilder()
.append(getIdentity())
- .append(getAction())
+ .append(getAclAction())
.append(getPermission())
.toHashCode();
}
- /** @see Object#toString() */
@Override
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("#", getNumber())
.append("identity", getIdentity())
- .append("action", getAction())
+ .append("action", getAclAction())
.append("permission", getPermission())
.append("enabled", isEnabled())
.toString();
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/RuleSet.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/RuleSet.java
index 815df99f80..e61370fced 100644
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/RuleSet.java
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/RuleSet.java
@@ -18,8 +18,8 @@
*/
package org.apache.qpid.server.security.access.config;
+import java.net.InetAddress;
import java.security.Principal;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
@@ -54,7 +54,7 @@ import org.apache.qpid.server.security.access.logging.AccessControlMessages;
*/
public class RuleSet
{
- public static final Logger _logger = Logger.getLogger(RuleSet.class);
+ private static final Logger _logger = Logger.getLogger(RuleSet.class);
private static final String AT = "@";
private static final String SLASH = "/";
@@ -66,7 +66,6 @@ public class RuleSet
private static final Integer _increment = 10;
- private final Map<String, List<String>> _aclGroups = new HashMap<String, List<String>>();
private final SortedMap<Integer, Rule> _rules = new TreeMap<Integer, Rule>();
private final Map<Subject, Map<Operation, Map<ObjectType, List<Rule>>>> _cache =
new WeakHashMap<Subject, Map<Operation, Map<ObjectType, List<Rule>>>>();
@@ -79,14 +78,13 @@ public class RuleSet
}
/**
- * Clear the contents, including acl groups, rules and configuration.
+ * Clear the contents, including acl rules and configuration.
*/
public void clear()
{
_rules.clear();
_cache.clear();
_config.clear();
- _aclGroups.clear();
}
public int getRuleCount()
@@ -157,21 +155,27 @@ public class RuleSet
public void grant(Integer number, String identity, Permission permission, Operation operation)
{
- Action action = new Action(operation);
+ AclAction action = new AclAction(operation);
addRule(number, identity, permission, action);
}
public void grant(Integer number, String identity, Permission permission, Operation operation, ObjectType object, ObjectProperties properties)
{
- Action action = new Action(operation, object, properties);
+ AclAction action = new AclAction(operation, object, properties);
addRule(number, identity, permission, action);
}
- public boolean ruleExists(String identity, Action action)
+ public void grant(Integer number, String identity, Permission permission, Operation operation, ObjectType object, AclRulePredicates predicates)
+ {
+ AclAction aclAction = new AclAction(operation, object, predicates);
+ addRule(number, identity, permission, aclAction);
+ }
+
+ public boolean ruleExists(String identity, AclAction action)
{
for (Rule rule : _rules.values())
{
- if (rule.getIdentity().equals(identity) && rule.getAction().equals(action))
+ if (rule.getIdentity().equals(identity) && rule.getAclAction().equals(action))
{
return true;
}
@@ -179,8 +183,7 @@ public class RuleSet
return false;
}
- // TODO make this work when group membership is not known at file parse time
- public void addRule(Integer number, String identity, Permission permission, Action action)
+ public void addRule(Integer number, String identity, Permission permission, AclAction action)
{
_cache.clear();
@@ -222,53 +225,6 @@ public class RuleSet
_rules.get(Integer.valueOf(ruleNumber)).disable();
}
- public boolean addGroup(String group, List<String> constituents)
- {
- _cache.clear();
-
- if (_aclGroups.containsKey(group))
- {
- // cannot redefine
- return false;
- }
- else
- {
- _aclGroups.put(group, new ArrayList<String>());
- }
-
- for (String name : constituents)
- {
- if (name.equalsIgnoreCase(group))
- {
- // recursive definition
- return false;
- }
-
- if (!checkName(name))
- {
- // invalid name
- return false;
- }
-
- if (_aclGroups.containsKey(name))
- {
- // is a group
- _aclGroups.get(group).addAll(_aclGroups.get(name));
- }
- else
- {
- // is a user
- if (!isvalidUserName(name))
- {
- // invalid username
- return false;
- }
- _aclGroups.get(group).add(name);
- }
- }
- return true;
- }
-
/** Return true if the name is well-formed (contains legal characters). */
protected boolean checkName(String name)
{
@@ -312,11 +268,15 @@ public class RuleSet
return true;
}
- // CPP broker authorise function prototype
- // virtual bool authorise(const std::string& id, const Action& action, const ObjectType& objType,
- // const std::string& name, std::map<Property, std::string>* params=0)
-
- // Possibly add a String name paramater?
+ /**
+ * Checks for the case when the client's address is not known.
+ *
+ * @see #check(Subject, Operation, ObjectType, ObjectProperties, InetAddress)
+ */
+ public Result check(Subject subject, Operation operation, ObjectType objectType, ObjectProperties properties)
+ {
+ return check(subject, operation, objectType, properties, null);
+ }
/**
* Check the authorisation granted to a particular identity for an operation on an object type with
@@ -327,10 +287,9 @@ public class RuleSet
* the first match found, or denies access if there are no matching rules. Normally, it would be expected
* to have a default deny or allow rule at the end of an access configuration however.
*/
- public Result check(Subject subject, Operation operation, ObjectType objectType, ObjectProperties properties)
+ public Result check(Subject subject, Operation operation, ObjectType objectType, ObjectProperties properties, InetAddress addressOfClient)
{
- // Create the action to check
- Action action = new Action(operation, objectType, properties);
+ ClientAction action = new ClientAction(operation, objectType, properties);
if(_logger.isDebugEnabled())
{
@@ -349,27 +308,31 @@ public class RuleSet
}
// Iterate through a filtered set of rules dealing with this identity and operation
- for (Rule current : rules)
+ for (Rule rule : rules)
{
if(_logger.isDebugEnabled())
{
- _logger.debug("Checking against rule: " + current);
+ _logger.debug("Checking against rule: " + rule);
}
- // Check if action matches
- if (action.matches(current.getAction()))
+
+ if (action.matches(rule.getAclAction(), addressOfClient))
{
- Permission permission = current.getPermission();
+ Permission permission = rule.getPermission();
switch (permission)
{
case ALLOW_LOG:
CurrentActor.get().message(AccessControlMessages.ALLOWED(
- action.getOperation().toString(), action.getObjectType().toString(), action.getProperties().toString()));
+ action.getOperation().toString(),
+ action.getObjectType().toString(),
+ action.getProperties().toString()));
case ALLOW:
return Result.ALLOWED;
case DENY_LOG:
CurrentActor.get().message(AccessControlMessages.DENIED(
- action.getOperation().toString(), action.getObjectType().toString(), action.getProperties().toString()));
+ action.getOperation().toString(),
+ action.getObjectType().toString(),
+ action.getProperties().toString()));
case DENY:
return Result.DENIED;
}
@@ -446,8 +409,7 @@ public class RuleSet
{
final Principal principal = iterator.next();
- if (rule.getIdentity().equalsIgnoreCase(principal.getName())
- || (_aclGroups.containsKey(rule.getIdentity()) && _aclGroups.get(rule.getIdentity()).contains(principal.getName())))
+ if (rule.getIdentity().equalsIgnoreCase(principal.getName()))
{
return true;
}
@@ -476,5 +438,4 @@ public class RuleSet
}
return objects;
}
-
}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/AccessControlFirewallException.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/AccessControlFirewallException.java
new file mode 100644
index 0000000000..d08a052efd
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/AccessControlFirewallException.java
@@ -0,0 +1,47 @@
+/*
+ *
+ * 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.security.access.firewall;
+
+public class AccessControlFirewallException extends RuntimeException
+{
+ /** serialVersionUID */
+ private static final long serialVersionUID = 4526157149690917805L;
+
+ public AccessControlFirewallException()
+ {
+ super();
+ }
+
+ public AccessControlFirewallException(String message)
+ {
+ super(message);
+ }
+
+ public AccessControlFirewallException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public AccessControlFirewallException(Throwable cause)
+ {
+ super(cause);
+ }
+} \ No newline at end of file
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/FirewallRule.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/FirewallRule.java
new file mode 100644
index 0000000000..482a795693
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/FirewallRule.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.server.security.access.firewall;
+
+import java.net.InetAddress;
+
+public interface FirewallRule
+{
+ boolean matches(InetAddress addressOfClient);
+}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/FirewallRuleFactory.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/FirewallRuleFactory.java
new file mode 100644
index 0000000000..64be26c209
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/FirewallRuleFactory.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.server.security.access.firewall;
+
+public class FirewallRuleFactory
+{
+ public FirewallRule createForHostname(String[] hostnames)
+ {
+ return new HostnameFirewallRule(hostnames);
+ }
+
+ public FirewallRule createForNetwork(String[] networks)
+ {
+ return new NetworkFirewallRule(networks);
+ }
+
+}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/HostnameFirewallRule.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/HostnameFirewallRule.java
new file mode 100644
index 0000000000..fb13426fbb
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/HostnameFirewallRule.java
@@ -0,0 +1,156 @@
+/*
+ * 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.security.access.firewall;
+
+import java.net.InetAddress;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.log4j.Logger;
+
+public class HostnameFirewallRule implements FirewallRule
+{
+ private static final Logger _logger = Logger.getLogger(HostnameFirewallRule.class);
+
+ private static final long DNS_TIMEOUT = 30000;
+ private static final ExecutorService DNS_LOOKUP = Executors.newCachedThreadPool();
+
+ private Pattern[] _hostnamePatterns;
+ private String[] _hostnames;
+
+ public HostnameFirewallRule(String... hostnames)
+ {
+ _hostnames = hostnames;
+
+ int i = 0;
+ _hostnamePatterns = new Pattern[hostnames.length];
+ for (String hostname : hostnames)
+ {
+ _hostnamePatterns[i++] = Pattern.compile(hostname);
+ }
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Created " + this);
+ }
+ }
+
+ @Override
+ public boolean matches(InetAddress remote)
+ {
+ String hostname = getHostname(remote);
+ if (hostname == null)
+ {
+ throw new AccessControlFirewallException("DNS lookup failed for address " + remote);
+ }
+ for (Pattern pattern : _hostnamePatterns)
+ {
+ boolean hostnameMatches = pattern.matcher(hostname).matches();
+
+ if (hostnameMatches)
+ {
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Hostname " + hostname + " matches rule " + pattern.toString());
+ }
+ return true;
+ }
+ }
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Hostname " + hostname + " matches no configured hostname patterns");
+ }
+
+ return false;
+ }
+
+
+ /**
+ * @param remote
+ * the InetAddress to look up
+ * @return the hostname, null if not found, takes longer than
+ * {@value #DNS_LOOKUP} to find or otherwise fails
+ */
+ private String getHostname(final InetAddress remote) throws AccessControlFirewallException
+ {
+ FutureTask<String> lookup = new FutureTask<String>(new Callable<String>()
+ {
+ public String call()
+ {
+ return remote.getCanonicalHostName();
+ }
+ });
+ DNS_LOOKUP.execute(lookup);
+
+ try
+ {
+ return lookup.get(DNS_TIMEOUT, TimeUnit.MILLISECONDS);
+ }
+ catch (Exception e)
+ {
+ _logger.warn("Unable to look up hostname from address " + remote, e);
+ return null;
+ }
+ finally
+ {
+ lookup.cancel(true);
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder().append(_hostnames).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj.getClass() != getClass())
+ {
+ return false;
+ }
+ HostnameFirewallRule rhs = (HostnameFirewallRule) obj;
+ return new EqualsBuilder().append(_hostnames, rhs._hostnames).isEquals();
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append(_hostnames).toString();
+ }
+}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/InetNetwork.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/InetNetwork.java
new file mode 100644
index 0000000000..2e979b38f1
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/InetNetwork.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.server.security.access.firewall;
+
+import java.net.InetAddress;
+
+class InetNetwork
+{
+ /*
+ * Implements network masking, and is compatible with RFC 1518 and
+ * RFC 1519, which describe CIDR: Classless Inter-Domain Routing.
+ */
+
+ private InetAddress network;
+ private InetAddress netmask;
+
+ public InetNetwork(InetAddress ip, InetAddress netmask)
+ {
+ this.network = maskIP(ip, netmask);
+ this.netmask = netmask;
+ }
+
+ public boolean contains(final String name) throws java.net.UnknownHostException
+ {
+ return network.equals(maskIP(InetAddress.getByName(name), netmask));
+ }
+
+ public boolean contains(final InetAddress ip)
+ {
+ return network.equals(maskIP(ip, netmask));
+ }
+
+ @Override
+ public String toString()
+ {
+ return network.getHostAddress() + "/" + netmask.getHostAddress();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return maskIP(network, netmask).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj != null) &&
+ (obj instanceof InetNetwork) &&
+ ((InetNetwork)obj).network.equals(network) &&
+ ((InetNetwork)obj).netmask.equals(netmask);
+ }
+
+ public static InetNetwork getFromString(String netspec) throws java.net.UnknownHostException
+ {
+ if (netspec.endsWith("*"))
+ {
+ netspec = normalizeFromAsterisk(netspec);
+ }
+ else
+ {
+ int iSlash = netspec.indexOf('/');
+ if (iSlash == -1)
+ {
+ netspec += "/255.255.255.255";
+ }
+ else if (netspec.indexOf('.', iSlash) == -1)
+ {
+ netspec = normalizeFromCIDR(netspec);
+ }
+ }
+
+ return new InetNetwork(
+ InetAddress.getByName(netspec.substring(0, netspec.indexOf('/'))),
+ InetAddress.getByName(netspec.substring(netspec.indexOf('/') + 1)));
+ }
+
+ public static InetAddress maskIP(final byte[] ip, final byte[] mask)
+ {
+ try
+ {
+ return getByAddress(
+ new byte[]
+ {
+ (byte) (mask[0] & ip[0]),
+ (byte) (mask[1] & ip[1]),
+ (byte) (mask[2] & ip[2]),
+ (byte) (mask[3] & ip[3])
+ }
+ );
+ }
+ catch (Exception _)
+ {
+ return null;
+ }
+ }
+
+ public static InetAddress maskIP(final InetAddress ip, final InetAddress mask)
+ {
+ return maskIP(ip.getAddress(), mask.getAddress());
+ }
+
+ /*
+ * This converts from an uncommon "wildcard" CIDR format
+ * to "address + mask" format:
+ *
+ * * => 000.000.000.0/000.000.000.0
+ * xxx.* => xxx.000.000.0/255.000.000.0
+ * xxx.xxx.* => xxx.xxx.000.0/255.255.000.0
+ * xxx.xxx.xxx.* => xxx.xxx.xxx.0/255.255.255.0
+ */
+ static private String normalizeFromAsterisk(final String netspec)
+ {
+ String[] masks = { "0.0.0.0/0.0.0.0", "0.0.0/255.0.0.0", "0.0/255.255.0.0", "0/255.255.255.0" };
+ char[] srcb = netspec.toCharArray();
+ int octets = 0;
+ for (int i = 1; i < netspec.length(); i++)
+ {
+ if (srcb[i] == '.')
+ {
+ octets++;
+ }
+ }
+ return (octets == 0) ? masks[0] : netspec.substring(0, netspec.length() -1 ).concat(masks[octets]);
+ }
+
+ /*
+ * RFC 1518, 1519 - Classless Inter-Domain Routing (CIDR)
+ * This converts from "prefix + prefix-length" format to
+ * "address + mask" format, e.g. from xxx.xxx.xxx.xxx/yy
+ * to xxx.xxx.xxx.xxx/yyy.yyy.yyy.yyy.
+ */
+ static private String normalizeFromCIDR(final String netspec)
+ {
+ final int bits = 32 - Integer.parseInt(netspec.substring(netspec.indexOf('/')+1));
+ final int mask = (bits == 32) ? 0 : 0xFFFFFFFF - ((1 << bits)-1);
+
+ return netspec.substring(0, netspec.indexOf('/') + 1) +
+ Integer.toString(mask >> 24 & 0xFF, 10) + "." +
+ Integer.toString(mask >> 16 & 0xFF, 10) + "." +
+ Integer.toString(mask >> 8 & 0xFF, 10) + "." +
+ Integer.toString(mask >> 0 & 0xFF, 10);
+ }
+
+ private static InetAddress getByAddress(byte[] ip) throws java.net.UnknownHostException
+ {
+ InetAddress addr = InetAddress.getByAddress(ip);
+
+ if (addr == null) {
+ addr = InetAddress.getByName
+ (
+ Integer.toString(ip[0] & 0xFF, 10) + "." +
+ Integer.toString(ip[1] & 0xFF, 10) + "." +
+ Integer.toString(ip[2] & 0xFF, 10) + "." +
+ Integer.toString(ip[3] & 0xFF, 10)
+ );
+ }
+
+ return addr;
+ }
+} \ No newline at end of file
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/NetworkFirewallRule.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/NetworkFirewallRule.java
new file mode 100644
index 0000000000..ad619a0e0b
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/firewall/NetworkFirewallRule.java
@@ -0,0 +1,117 @@
+/*
+ * 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.security.access.firewall;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.log4j.Logger;
+
+public class NetworkFirewallRule implements FirewallRule
+{
+ private static final Logger _logger = Logger.getLogger(NetworkFirewallRule.class);
+
+ private List<InetNetwork> _networks;
+
+ public NetworkFirewallRule(String... networks)
+ {
+ _networks = new ArrayList<InetNetwork>();
+ for (int i = 0; i < networks.length; i++)
+ {
+ String network = networks[i];
+ try
+ {
+ InetNetwork inetNetwork = InetNetwork.getFromString(network);
+ if (!_networks.contains(inetNetwork))
+ {
+ _networks.add(inetNetwork);
+ }
+ }
+ catch (java.net.UnknownHostException uhe)
+ {
+ _logger.error("Cannot resolve address: " + network, uhe);
+ }
+ }
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Created " + this);
+ }
+ }
+
+ @Override
+ public boolean matches(InetAddress ip)
+ {
+ for (InetNetwork network : _networks)
+ {
+ if (network.contains(ip))
+ {
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Client address " + ip + " matches configured network " + network);
+ }
+ return true;
+ }
+ }
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Client address " + ip + " does not match any configured networks");
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder().append(_networks).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj.getClass() != getClass())
+ {
+ return false;
+ }
+ NetworkFirewallRule rhs = (NetworkFirewallRule) obj;
+ return new EqualsBuilder().append(_networks, rhs._networks).isEquals();
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append(_networks).toString();
+ }
+}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/logging/AccessControl_logmessages.properties b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/logging/AccessControl_logmessages.properties
index bf80df3722..2a5eb7b3be 100644
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/logging/AccessControl_logmessages.properties
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/logging/AccessControl_logmessages.properties
@@ -25,4 +25,4 @@
ALLOWED = ACL-1001 : Allowed : {0} {1} {2}
# 'deny-log' rule message
-DENIED = ACL-1002 : Denied : {0} {1} {2} \ No newline at end of file
+DENIED = ACL-1002 : Denied : {0} {1} {2}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControl.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControl.java
deleted file mode 100644
index d8a5bd4085..0000000000
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControl.java
+++ /dev/null
@@ -1,116 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import javax.security.auth.Subject;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.security.AbstractPlugin;
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.SecurityPluginFactory;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-import org.apache.qpid.server.security.access.config.RuleSet;
-
-/**
- * This access control plugin implements version two plain text access control.
- */
-public class AccessControl extends AbstractPlugin
-{
- public static final Logger _logger = Logger.getLogger(AccessControl.class);
-
- private RuleSet _ruleSet;
-
- public static final SecurityPluginFactory<AccessControl> FACTORY = new SecurityPluginFactory<AccessControl>()
- {
- public Class<AccessControl> getPluginClass()
- {
- return AccessControl.class;
- }
-
- public String getPluginName()
- {
- return AccessControl.class.getName();
- }
-
- public AccessControl newInstance(ConfigurationPlugin config) throws ConfigurationException
- {
- AccessControlConfiguration configuration = config.getConfiguration(AccessControlConfiguration.class.getName());
-
- // If there is no configuration for this plugin then don't load it.
- if (configuration == null)
- {
- return null;
- }
-
- AccessControl plugin = new AccessControl();
- plugin.configure(configuration);
- return plugin;
- }
- };
-
- public Result getDefault()
- {
- return _ruleSet.getDefault();
- }
-
- /**
- * Object instance access authorisation.
- *
- * Delegate to the {@link #authorise(Operation, ObjectType, ObjectProperties)} method, with
- * the operation set to ACCESS and no object properties.
- */
- public Result access(ObjectType objectType, Object instance)
- {
- return authorise(Operation.ACCESS, objectType, ObjectProperties.EMPTY);
- }
-
- /**
- * Check if an operation is authorised by asking the configuration object about the access
- * control rules granted to the current thread's {@link Subject}. If there is no current
- * user the plugin will abstain.
- */
- public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties)
- {
- final Subject subject = SecurityManager.getThreadSubject();
- // Abstain if there is no subject/principal associated with this thread
- if (subject == null || subject.getPrincipals().size() == 0)
- {
- return Result.ABSTAIN;
- }
-
- _logger.debug("Checking " + operation + " " + objectType);
- return _ruleSet.check(subject, operation, objectType, properties);
- }
-
- public void configure(ConfigurationPlugin config)
- {
- super.configure(config);
-
- AccessControlConfiguration accessConfig = (AccessControlConfiguration) getConfig();
-
- _ruleSet = accessConfig.getRuleSet();
- }
-}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControlActivator.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControlActivator.java
deleted file mode 100644
index 7c83446cf1..0000000000
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControlActivator.java
+++ /dev/null
@@ -1,41 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.security.SecurityPluginActivator;
-import org.apache.qpid.server.security.SecurityPluginFactory;
-
-/**
- * The OSGi {@link org.osgi.framework.BundleActivator} for {@link AccessControl}.
- */
-public class AccessControlActivator extends SecurityPluginActivator
-{
- public SecurityPluginFactory getFactory()
- {
- return AccessControl.FACTORY;
- }
-
- public ConfigurationPluginFactory getConfigurationFactory()
- {
- return AccessControlConfiguration.FACTORY;
- }
-}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControlConfiguration.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControlConfiguration.java
deleted file mode 100644
index c4db6db820..0000000000
--- a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/AccessControlConfiguration.java
+++ /dev/null
@@ -1,83 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.security.access.config.ConfigurationFile;
-import org.apache.qpid.server.security.access.config.PlainConfiguration;
-import org.apache.qpid.server.security.access.config.RuleSet;
-
-public class AccessControlConfiguration extends ConfigurationPlugin
-{
- public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory()
- {
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- ConfigurationPlugin instance = new AccessControlConfiguration();
- instance.setConfiguration(path, config);
- return instance;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList("security.acl", "virtualhosts.virtualhost.security.acl");
- }
- };
-
- private RuleSet _ruleSet;
-
- public String[] getElementsProcessed()
- {
- return new String[] { "" };
- }
-
- public String getFileName()
- {
- return getConfig().getString("");
- }
-
- public void validateConfiguration() throws ConfigurationException
- {
- String filename = getFileName();
- if (filename == null)
- {
- throw new ConfigurationException("No ACL file name specified");
- }
-
- File aclFile = new File(filename);
-
- ConfigurationFile configFile = new PlainConfiguration(aclFile);
- _ruleSet = configFile.load();
- }
-
- public RuleSet getRuleSet()
- {
- return _ruleSet;
- }
-
-}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java
new file mode 100644
index 0000000000..6f7885da94
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControl.java
@@ -0,0 +1,122 @@
+/*
+ *
+ * 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.security.access.plugins;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.io.File;
+
+import javax.security.auth.Subject;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.security.Result;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.AccessControl;
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectType;
+import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.access.config.ConfigurationFile;
+import org.apache.qpid.server.security.access.config.PlainConfiguration;
+import org.apache.qpid.server.security.access.config.RuleSet;
+
+public class DefaultAccessControl implements AccessControl
+{
+ private static final Logger _logger = Logger.getLogger(DefaultAccessControl.class);
+
+ private RuleSet _ruleSet;
+
+ public DefaultAccessControl(String fileName)
+ {
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Creating AccessControl instance using file: " + fileName);
+ }
+ File aclFile = new File(fileName);
+
+ ConfigurationFile configFile = new PlainConfiguration(aclFile);
+ _ruleSet = configFile.load();
+ }
+
+ DefaultAccessControl(RuleSet rs) throws ConfigurationException
+ {
+ _ruleSet = rs;
+ }
+
+ public Result getDefault()
+ {
+ return _ruleSet.getDefault();
+ }
+
+ /**
+ * Object instance access authorisation.
+ *
+ * Delegate to the {@link #authorise(Operation, ObjectType, ObjectProperties)} method, with
+ * the operation set to ACCESS and no object properties.
+ */
+ public Result access(ObjectType objectType, Object inetSocketAddress)
+ {
+ InetAddress addressOfClient = null;
+
+ if(inetSocketAddress != null)
+ {
+ addressOfClient = ((InetSocketAddress) inetSocketAddress).getAddress();
+ }
+
+ return authoriseFromAddress(Operation.ACCESS, objectType, ObjectProperties.EMPTY, addressOfClient);
+ }
+
+ /**
+ * Check if an operation is authorised by asking the configuration object about the access
+ * control rules granted to the current thread's {@link Subject}. If there is no current
+ * user the plugin will abstain.
+ */
+ public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties)
+ {
+ return authoriseFromAddress(operation, objectType, properties, null);
+ }
+
+ public Result authoriseFromAddress(Operation operation, ObjectType objectType, ObjectProperties properties, InetAddress addressOfClient)
+ {
+ final Subject subject = SecurityManager.getThreadSubject();
+ // Abstain if there is no subject/principal associated with this thread
+ if (subject == null || subject.getPrincipals().size() == 0)
+ {
+ return Result.ABSTAIN;
+ }
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Checking " + operation + " " + objectType + " " + ObjectUtils.defaultIfNull(addressOfClient, ""));
+ }
+
+ try
+ {
+ return _ruleSet.check(subject, operation, objectType, properties, addressOfClient);
+ }
+ catch(Exception e)
+ {
+ _logger.error("Unable to check " + operation + " " + objectType + " " + ObjectUtils.defaultIfNull(addressOfClient, ""), e);
+ return Result.DENIED;
+ }
+ }
+}
diff --git a/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
new file mode 100644
index 0000000000..a3d7823caf
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.security.access.plugins;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.plugin.AccessControlFactory;
+import org.apache.qpid.server.security.AccessControl;
+
+public class DefaultAccessControlFactory implements AccessControlFactory
+{
+ public static final String ATTRIBUTE_ACL_FILE = "aclFile";
+
+ public AccessControl createInstance(Map<String, Object> aclConfiguration)
+ {
+ if (aclConfiguration != null)
+ {
+ Object aclFile = aclConfiguration.get(ATTRIBUTE_ACL_FILE);
+ if (aclFile != null)
+ {
+ if (aclFile instanceof String)
+ {
+ String aclPath = (String) aclFile;
+ if (!new File(aclPath).exists())
+ {
+ throw new IllegalConfigurationException("ACL file '" + aclPath + "' is not found");
+ }
+ return new DefaultAccessControl(aclPath);
+ }
+ else
+ {
+ throw new IllegalConfigurationException("Expected '" + ATTRIBUTE_ACL_FILE + "' attribute value of type String but was " + aclFile.getClass()
+ + ": " + aclFile);
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlFactory b/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlFactory
new file mode 100644
index 0000000000..b6c429baab
--- /dev/null
+++ b/java/broker-plugins/access-control/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AccessControlFactory
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.qpid.server.security.access.plugins.DefaultAccessControlFactory
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/AclActionTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/AclActionTest.java
new file mode 100644
index 0000000000..14620cff70
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/AclActionTest.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.server.security.access.config;
+
+import static org.mockito.Mockito.*;
+
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectType;
+import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.access.firewall.FirewallRule;
+
+import junit.framework.TestCase;
+
+public class AclActionTest extends TestCase
+{
+ public void testEqualsAndHashCode()
+ {
+ AclRulePredicates predicates = createAclRulePredicates();
+ ObjectType objectType = ObjectType.EXCHANGE;
+ Operation operation = Operation.ACCESS;
+
+ AclAction aclAction = new AclAction(operation, objectType, predicates);
+ AclAction equalAclAction = new AclAction(operation, objectType, predicates);
+
+ assertTrue(aclAction.equals(aclAction));
+ assertTrue(aclAction.equals(equalAclAction));
+ assertTrue(equalAclAction.equals(aclAction));
+
+ assertTrue(aclAction.hashCode() == equalAclAction.hashCode());
+
+ assertFalse("Different operation should cause aclActions to be unequal",
+ aclAction.equals(new AclAction(Operation.BIND, objectType, predicates)));
+
+ assertFalse("Different operation type should cause aclActions to be unequal",
+ aclAction.equals(new AclAction(operation, ObjectType.GROUP, predicates)));
+
+ assertFalse("Different predicates should cause aclActions to be unequal",
+ aclAction.equals(new AclAction(operation, objectType, createAclRulePredicates())));
+
+ }
+
+ private AclRulePredicates createAclRulePredicates()
+ {
+ AclRulePredicates predicates = mock(AclRulePredicates.class);
+ when(predicates.getFirewallRule()).thenReturn(mock(FirewallRule.class));
+ when(predicates.getObjectProperties()).thenReturn(mock(ObjectProperties.class));
+ return predicates;
+ }
+
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/AclRulePredicatesTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/AclRulePredicatesTest.java
new file mode 100644
index 0000000000..93b765d0fb
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/AclRulePredicatesTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.security.access.config;
+
+import static org.apache.qpid.server.security.access.ObjectProperties.Property.*;
+
+import org.apache.qpid.server.security.access.firewall.FirewallRule;
+import org.apache.qpid.server.security.access.firewall.FirewallRuleFactory;
+
+import static org.mockito.Mockito.*;
+
+import junit.framework.TestCase;
+
+public class AclRulePredicatesTest extends TestCase
+{
+ private AclRulePredicates _aclRulePredicates = new AclRulePredicates();
+ private FirewallRuleFactory _firewallRuleFactory = mock(FirewallRuleFactory.class);
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ _aclRulePredicates.setFirewallRuleFactory(_firewallRuleFactory);
+
+ when(_firewallRuleFactory.createForHostname((String[]) any())).thenReturn(mock(FirewallRule.class));
+ when(_firewallRuleFactory.createForNetwork((String[]) any())).thenReturn(mock(FirewallRule.class));
+ }
+
+ public void testParse()
+ {
+ String name = "name";
+ String className = "class";
+
+ _aclRulePredicates.parse(NAME.name(), name);
+ _aclRulePredicates.parse(CLASS.name(), className);
+
+ assertEquals(name, _aclRulePredicates.getObjectProperties().get(NAME));
+ assertEquals(className, _aclRulePredicates.getObjectProperties().get(CLASS));
+ }
+
+ public void testParseHostnameFirewallRule()
+ {
+ String hostname = "hostname1,hostname2";
+ _aclRulePredicates.parse(FROM_HOSTNAME.name(), hostname);
+
+ verify(_firewallRuleFactory).createForHostname(new String[] {"hostname1", "hostname2"});
+ }
+
+ public void testParseNetworkFirewallRule()
+ {
+ _aclRulePredicates.setFirewallRuleFactory(_firewallRuleFactory);
+
+ String networks = "network1,network2";
+ _aclRulePredicates.parse(FROM_NETWORK.name(), networks);
+
+ verify(_firewallRuleFactory).createForNetwork(new String[] {"network1", "network2"});
+ }
+
+ public void testParseThrowsExceptionIfBothHostnameAndNetworkSpecified()
+ {
+ _aclRulePredicates.parse(FROM_NETWORK.name(), "network1,network2");
+ try
+ {
+ _aclRulePredicates.parse(FROM_HOSTNAME.name(), "hostname1,hostname2");
+ fail("Exception not thrown");
+ }
+ catch(IllegalStateException e)
+ {
+ // pass
+ }
+ }
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/ActionTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/ActionTest.java
new file mode 100644
index 0000000000..00e06106bf
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/ActionTest.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.server.security.access.config;
+
+import static org.mockito.Mockito.*;
+
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectType;
+import org.apache.qpid.server.security.access.Operation;
+
+import junit.framework.TestCase;
+
+public class ActionTest extends TestCase
+{
+ private ObjectProperties _properties1 = mock(ObjectProperties.class);
+ private ObjectProperties _properties2 = mock(ObjectProperties.class);
+
+ public void testMatchesReturnsTrueForMatchingActions()
+ {
+ when(_properties1.matches(_properties2)).thenReturn(true);
+
+ assertMatches(
+ new Action(Operation.CONSUME, ObjectType.QUEUE, _properties1),
+ new Action(Operation.CONSUME, ObjectType.QUEUE, _properties2));
+ }
+
+ public void testMatchesReturnsFalseWhenOperationsDiffer()
+ {
+ assertDoesntMatch(
+ new Action(Operation.CONSUME, ObjectType.QUEUE, _properties1),
+ new Action(Operation.CREATE, ObjectType.QUEUE, _properties1));
+ }
+
+ public void testMatchesReturnsFalseWhenOperationTypesDiffer()
+ {
+ assertDoesntMatch(
+ new Action(Operation.CREATE, ObjectType.QUEUE, _properties1),
+ new Action(Operation.CREATE, ObjectType.EXCHANGE, _properties1));
+ }
+
+ public void testMatchesReturnsFalseWhenOperationPropertiesDiffer()
+ {
+ assertDoesntMatch(
+ new Action(Operation.CREATE, ObjectType.QUEUE, _properties1),
+ new Action(Operation.CREATE, ObjectType.QUEUE, _properties2));
+ }
+
+ public void testMatchesReturnsFalseWhenMyOperationPropertiesIsNull()
+ {
+ assertDoesntMatch(
+ new Action(Operation.CREATE, ObjectType.QUEUE, (ObjectProperties)null),
+ new Action(Operation.CREATE, ObjectType.QUEUE, _properties1));
+ }
+
+ public void testMatchesReturnsFalseWhenOtherOperationPropertiesIsNull()
+ {
+ assertDoesntMatch(
+ new Action(Operation.CREATE, ObjectType.QUEUE, _properties1),
+ new Action(Operation.CREATE, ObjectType.QUEUE, (ObjectProperties)null));
+ }
+
+ public void testMatchesReturnsTrueWhenBothOperationPropertiesAreNull()
+ {
+ assertMatches(
+ new Action(Operation.CREATE, ObjectType.QUEUE, (ObjectProperties)null),
+ new Action(Operation.CREATE, ObjectType.QUEUE, (ObjectProperties)null));
+ }
+
+ private void assertMatches(Action action1, Action action2)
+ {
+ assertTrue(action1 + " should match " + action2, action1.matches(action2));
+ }
+
+ private void assertDoesntMatch(Action action1, Action action2)
+ {
+ assertFalse(action1 + " should not match " + action2, action1.matches(action2));
+ }
+
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/ClientActionTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/ClientActionTest.java
new file mode 100644
index 0000000000..ae5d3fda74
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/ClientActionTest.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.security.access.config;
+
+import static org.mockito.Mockito.*;
+
+import java.net.InetAddress;
+
+import org.apache.qpid.server.security.access.firewall.FirewallRule;
+
+import junit.framework.TestCase;
+
+public class ClientActionTest extends TestCase
+{
+ private Action _action = mock(Action.class);
+ private AclAction _ruleAction = mock(AclAction.class);
+ private InetAddress _addressOfClient = mock(InetAddress.class);
+
+ private ClientAction _clientAction = new ClientAction(_action);
+
+ public void testMatches_returnsTrueWhenActionsMatchAndNoFirewallRule()
+ {
+ when(_action.matches(any(Action.class))).thenReturn(true);
+ when(_ruleAction.getFirewallRule()).thenReturn(null);
+
+ assertTrue(_clientAction.matches(_ruleAction, _addressOfClient));
+ }
+
+ public void testMatches_returnsFalseWhenActionsDontMatch()
+ {
+ FirewallRule firewallRule = mock(FirewallRule.class);
+ when(firewallRule.matches(_addressOfClient)).thenReturn(true);
+
+ when(_action.matches(any(Action.class))).thenReturn(false);
+ when(_ruleAction.getFirewallRule()).thenReturn(firewallRule);
+
+ assertFalse(_clientAction.matches(_ruleAction, _addressOfClient));
+ }
+
+ public void testMatches_returnsTrueWhenActionsAndFirewallRuleMatch()
+ {
+ FirewallRule firewallRule = mock(FirewallRule.class);
+ when(firewallRule.matches(_addressOfClient)).thenReturn(true);
+
+ when(_action.matches(any(Action.class))).thenReturn(true);
+ when(_ruleAction.getFirewallRule()).thenReturn(firewallRule);
+
+ assertTrue(_clientAction.matches(_ruleAction, _addressOfClient));
+ }
+
+ public void testMatches_ignoresFirewallRuleIfClientAddressIsNull()
+ {
+ FirewallRule firewallRule = mock(FirewallRule.class);
+
+ when(_action.matches(any(Action.class))).thenReturn(true);
+ when(_ruleAction.getFirewallRule()).thenReturn(firewallRule);
+
+ assertTrue(_clientAction.matches(_ruleAction, null));
+
+ verifyZeroInteractions(firewallRule);
+ }
+
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java
new file mode 100644
index 0000000000..cbfc9003c8
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/PlainConfigurationTest.java
@@ -0,0 +1,463 @@
+/*
+ * 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.security.access.config;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectProperties.Property;
+import org.apache.qpid.server.security.access.ObjectType;
+import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.access.config.ConfigurationFile;
+import org.apache.qpid.server.security.access.config.PlainConfiguration;
+import org.apache.qpid.server.security.access.config.Rule;
+import org.apache.qpid.server.security.access.config.RuleSet;
+
+/**
+ * These tests check that the ACL file parsing works correctly.
+ *
+ * For each message that can be returned in a {@link ConfigurationException}, an ACL file is created that should trigger this
+ * particular message.
+ */
+public class PlainConfigurationTest extends TestCase
+{
+ private PlainConfiguration writeACLConfig(String...aclData) throws Exception
+ {
+ File acl = File.createTempFile(getClass().getName() + getName(), "acl");
+ acl.deleteOnExit();
+
+ // Write ACL file
+ PrintWriter aclWriter = new PrintWriter(new FileWriter(acl));
+ for (String line : aclData)
+ {
+ aclWriter.println(line);
+ }
+ aclWriter.close();
+
+ // Load ruleset
+ PlainConfiguration configFile = new PlainConfiguration(acl);
+ configFile.load();
+ return configFile;
+ }
+
+ public void testMissingACLConfig() throws Exception
+ {
+ try
+ {
+ // Load ruleset
+ ConfigurationFile configFile = new PlainConfiguration(new File("doesnotexist"));
+ configFile.load();
+
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.CONFIG_NOT_FOUND_MSG, "doesnotexist"), ce.getMessage());
+ assertTrue(ce.getCause() instanceof FileNotFoundException);
+ }
+ }
+
+ public void testACLFileSyntaxContinuation() throws Exception
+ {
+ try
+ {
+ writeACLConfig("ACL ALLOW ALL \\ ALL");
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.PREMATURE_CONTINUATION_MSG, 1), ce.getMessage());
+ }
+ }
+
+ public void testACLFileSyntaxTokens() throws Exception
+ {
+ try
+ {
+ writeACLConfig("ACL unparsed ALL ALL");
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.PARSE_TOKEN_FAILED_MSG, 1), ce.getMessage());
+ assertTrue(ce.getCause() instanceof IllegalArgumentException);
+ assertEquals("Not a valid permission: unparsed", ce.getCause().getMessage());
+ }
+ }
+
+ public void testACLFileSyntaxNotEnoughACL() throws Exception
+ {
+ try
+ {
+ writeACLConfig("ACL ALLOW");
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_ACL_MSG, 1), ce.getMessage());
+ }
+ }
+
+ public void testACLFileSyntaxNotEnoughConfig() throws Exception
+ {
+ try
+ {
+ writeACLConfig("CONFIG");
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_TOKENS_MSG, 1), ce.getMessage());
+ }
+ }
+
+ public void testACLFileSyntaxNotEnough() throws Exception
+ {
+ try
+ {
+ writeACLConfig("INVALID");
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_TOKENS_MSG, 1), ce.getMessage());
+ }
+ }
+
+ public void testACLFileSyntaxPropertyKeyOnly() throws Exception
+ {
+ try
+ {
+ writeACLConfig("ACL ALLOW adk CREATE QUEUE name");
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.PROPERTY_KEY_ONLY_MSG, 1), ce.getMessage());
+ }
+ }
+
+ public void testACLFileSyntaxPropertyNoEquals() throws Exception
+ {
+ try
+ {
+ writeACLConfig("ACL ALLOW adk CREATE QUEUE name test");
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.PROPERTY_NO_EQUALS_MSG, 1), ce.getMessage());
+ }
+ }
+
+ public void testACLFileSyntaxPropertyNoValue() throws Exception
+ {
+ try
+ {
+ writeACLConfig("ACL ALLOW adk CREATE QUEUE name =");
+ fail("fail");
+ }
+ catch (IllegalConfigurationException ce)
+ {
+ assertEquals(String.format(PlainConfiguration.PROPERTY_NO_VALUE_MSG, 1), ce.getMessage());
+ }
+ }
+
+ /**
+ * Tests interpretation of an acl rule with no object properties.
+ *
+ */
+ public void testValidRule() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("ACL DENY-LOG user1 ACCESS VIRTUALHOST");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", "user1", rule.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.ACCESS, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.VIRTUALHOST, rule.getAction().getObjectType());
+ assertEquals("Rule has unexpected object properties", ObjectProperties.EMPTY, rule.getAction().getProperties());
+ }
+
+ /**
+ * Tests interpretation of an acl rule with object properties quoted in single quotes.
+ */
+ public void testValidRuleWithSingleQuotedProperty() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("ACL ALLOW all CREATE EXCHANGE name = \'value\'");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", "all", rule.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.CREATE, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.EXCHANGE, rule.getAction().getObjectType());
+ final ObjectProperties expectedProperties = new ObjectProperties();
+ expectedProperties.setName("value");
+ assertEquals("Rule has unexpected object properties", expectedProperties, rule.getAction().getProperties());
+ }
+
+ /**
+ * Tests interpretation of an acl rule with object properties quoted in double quotes.
+ */
+ public void testValidRuleWithDoubleQuotedProperty() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("ACL ALLOW all CREATE EXCHANGE name = \"value\"");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", "all", rule.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.CREATE, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.EXCHANGE, rule.getAction().getObjectType());
+ final ObjectProperties expectedProperties = new ObjectProperties();
+ expectedProperties.setName("value");
+ assertEquals("Rule has unexpected object properties", expectedProperties, rule.getAction().getProperties());
+ }
+
+ /**
+ * Tests interpretation of an acl rule with many object properties.
+ */
+ public void testValidRuleWithManyProperties() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("ACL ALLOW admin DELETE QUEUE name=name1 owner = owner1");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", "admin", rule.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.DELETE, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.QUEUE, rule.getAction().getObjectType());
+ final ObjectProperties expectedProperties = new ObjectProperties();
+ expectedProperties.setName("name1");
+ expectedProperties.put(Property.OWNER, "owner1");
+ assertEquals("Rule has unexpected operation", expectedProperties, rule.getAction().getProperties());
+ }
+
+ /**
+ * Tests interpretation of an acl rule with object properties containing wildcards. Values containing
+ * hashes must be quoted otherwise they are interpreted as comments.
+ */
+ public void testValidRuleWithWildcardProperties() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("ACL ALLOW all CREATE EXCHANGE routingKey = \'news.#\'",
+ "ACL ALLOW all CREATE EXCHANGE routingKey = \'news.co.#\'",
+ "ACL ALLOW all CREATE EXCHANGE routingKey = *.co.medellin");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(3, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(3, rules.size());
+ final Rule rule1 = rules.get(0);
+ assertEquals("Rule has unexpected identity", "all", rule1.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.CREATE, rule1.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.EXCHANGE, rule1.getAction().getObjectType());
+ final ObjectProperties expectedProperties1 = new ObjectProperties();
+ expectedProperties1.put(Property.ROUTING_KEY,"news.#");
+ assertEquals("Rule has unexpected object properties", expectedProperties1, rule1.getAction().getProperties());
+
+ final Rule rule2 = rules.get(10);
+ final ObjectProperties expectedProperties2 = new ObjectProperties();
+ expectedProperties2.put(Property.ROUTING_KEY,"news.co.#");
+ assertEquals("Rule has unexpected object properties", expectedProperties2, rule2.getAction().getProperties());
+
+ final Rule rule3 = rules.get(20);
+ final ObjectProperties expectedProperties3 = new ObjectProperties();
+ expectedProperties3.put(Property.ROUTING_KEY,"*.co.medellin");
+ assertEquals("Rule has unexpected object properties", expectedProperties3, rule3.getAction().getProperties());
+ }
+
+ /**
+ * Tests that rules are case insignificant.
+ */
+ public void testMixedCaseRuleInterpretation() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("AcL deny-LOG User1 BiND Exchange Name=AmQ.dIrect");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", "User1", rule.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.BIND, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.EXCHANGE, rule.getAction().getObjectType());
+ final ObjectProperties expectedProperties = new ObjectProperties("AmQ.dIrect");
+ assertEquals("Rule has unexpected object properties", expectedProperties, rule.getAction().getProperties());
+ }
+
+ /**
+ * Tests whitespace is supported. Note that currently the Java implementation permits comments to
+ * be introduced anywhere in the ACL, whereas the C++ supports only whitespace at the beginning of
+ * of line.
+ */
+ public void testCommentsSuppported() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("#Comment",
+ "ACL DENY-LOG user1 ACCESS VIRTUALHOST # another comment",
+ " # final comment with leading whitespace");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", "user1", rule.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.ACCESS, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.VIRTUALHOST, rule.getAction().getObjectType());
+ assertEquals("Rule has unexpected object properties", ObjectProperties.EMPTY, rule.getAction().getProperties());
+ }
+
+ /**
+ * Tests interpretation of an acl rule using mixtures of tabs/spaces as token separators.
+ *
+ */
+ public void testWhitespace() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("ACL\tDENY-LOG\t\t user1\t \tACCESS VIRTUALHOST");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", "user1", rule.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.ACCESS, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.VIRTUALHOST, rule.getAction().getObjectType());
+ assertEquals("Rule has unexpected object properties", ObjectProperties.EMPTY, rule.getAction().getProperties());
+ }
+
+ /**
+ * Tests interpretation of an acl utilising line continuation.
+ */
+ public void testLineContination() throws Exception
+ {
+ final PlainConfiguration config = writeACLConfig("ACL DENY-LOG user1 \\",
+ "ACCESS VIRTUALHOST");
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", "user1", rule.getIdentity());
+ assertEquals("Rule has unexpected operation", Operation.ACCESS, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", ObjectType.VIRTUALHOST, rule.getAction().getObjectType());
+ assertEquals("Rule has unexpected object properties", ObjectProperties.EMPTY, rule.getAction().getProperties());
+ }
+
+ public void testUserRuleParsing() throws Exception
+ {
+ validateRule(writeACLConfig("ACL ALLOW user1 CREATE USER"),
+ "user1", Operation.CREATE, ObjectType.USER, ObjectProperties.EMPTY);
+ validateRule(writeACLConfig("ACL ALLOW user1 CREATE USER name=\"otherUser\""),
+ "user1", Operation.CREATE, ObjectType.USER, new ObjectProperties("otherUser"));
+
+ validateRule(writeACLConfig("ACL ALLOW user1 DELETE USER"),
+ "user1", Operation.DELETE, ObjectType.USER, ObjectProperties.EMPTY);
+ validateRule(writeACLConfig("ACL ALLOW user1 DELETE USER name=\"otherUser\""),
+ "user1", Operation.DELETE, ObjectType.USER, new ObjectProperties("otherUser"));
+
+ validateRule(writeACLConfig("ACL ALLOW user1 UPDATE USER"),
+ "user1", Operation.UPDATE, ObjectType.USER, ObjectProperties.EMPTY);
+ validateRule(writeACLConfig("ACL ALLOW user1 UPDATE USER name=\"otherUser\""),
+ "user1", Operation.UPDATE, ObjectType.USER, new ObjectProperties("otherUser"));
+
+ validateRule(writeACLConfig("ACL ALLOW user1 ALL USER"),
+ "user1", Operation.ALL, ObjectType.USER, ObjectProperties.EMPTY);
+ validateRule(writeACLConfig("ACL ALLOW user1 ALL USER name=\"otherUser\""),
+ "user1", Operation.ALL, ObjectType.USER, new ObjectProperties("otherUser"));
+ }
+
+ public void testGroupRuleParsing() throws Exception
+ {
+ validateRule(writeACLConfig("ACL ALLOW user1 CREATE GROUP"),
+ "user1", Operation.CREATE, ObjectType.GROUP, ObjectProperties.EMPTY);
+ validateRule(writeACLConfig("ACL ALLOW user1 CREATE GROUP name=\"groupName\""),
+ "user1", Operation.CREATE, ObjectType.GROUP, new ObjectProperties("groupName"));
+
+ validateRule(writeACLConfig("ACL ALLOW user1 DELETE GROUP"),
+ "user1", Operation.DELETE, ObjectType.GROUP, ObjectProperties.EMPTY);
+ validateRule(writeACLConfig("ACL ALLOW user1 DELETE GROUP name=\"groupName\""),
+ "user1", Operation.DELETE, ObjectType.GROUP, new ObjectProperties("groupName"));
+
+ validateRule(writeACLConfig("ACL ALLOW user1 UPDATE GROUP"),
+ "user1", Operation.UPDATE, ObjectType.GROUP, ObjectProperties.EMPTY);
+ validateRule(writeACLConfig("ACL ALLOW user1 UPDATE GROUP name=\"groupName\""),
+ "user1", Operation.UPDATE, ObjectType.GROUP, new ObjectProperties("groupName"));
+
+ validateRule(writeACLConfig("ACL ALLOW user1 ALL GROUP"),
+ "user1", Operation.ALL, ObjectType.GROUP, ObjectProperties.EMPTY);
+ validateRule(writeACLConfig("ACL ALLOW user1 ALL GROUP name=\"groupName\""),
+ "user1", Operation.ALL, ObjectType.GROUP, new ObjectProperties("groupName"));
+ }
+
+ /** explicitly test for exception indicating that this functionality has been moved to Group Providers */
+ public void testGroupDefinitionThrowsException() throws Exception
+ {
+ try
+ {
+ writeACLConfig("GROUP group1 bob alice");
+ fail("Expected exception not thrown");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ assertTrue(e.getMessage().contains("GROUP keyword not supported"));
+ }
+ }
+
+ public void testManagementRuleParsing() throws Exception
+ {
+ validateRule(writeACLConfig("ACL ALLOW user1 ALL MANAGEMENT"),
+ "user1", Operation.ALL, ObjectType.MANAGEMENT, ObjectProperties.EMPTY);
+
+ validateRule(writeACLConfig("ACL ALLOW user1 ACCESS MANAGEMENT"),
+ "user1", Operation.ACCESS, ObjectType.MANAGEMENT, ObjectProperties.EMPTY);
+ }
+
+ private void validateRule(final PlainConfiguration config, String username, Operation operation, ObjectType objectType, ObjectProperties objectProperties)
+ {
+ final RuleSet rs = config.getConfiguration();
+ assertEquals(1, rs.getRuleCount());
+
+ final Map<Integer, Rule> rules = rs.getAllRules();
+ assertEquals(1, rules.size());
+ final Rule rule = rules.get(0);
+ assertEquals("Rule has unexpected identity", username, rule.getIdentity());
+ assertEquals("Rule has unexpected operation", operation, rule.getAction().getOperation());
+ assertEquals("Rule has unexpected operation", objectType, rule.getAction().getObjectType());
+ assertEquals("Rule has unexpected object properties", objectProperties, rule.getAction().getProperties());
+ }
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/RuleTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/RuleTest.java
new file mode 100644
index 0000000000..2ae7759679
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/config/RuleTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.security.access.config;
+
+import static org.mockito.Mockito.*;
+
+import org.apache.qpid.server.security.access.Permission;
+
+import junit.framework.TestCase;
+
+public class RuleTest extends TestCase
+{
+ public void testEqualsAndHashCode()
+ {
+ AclAction aclAction = mock(AclAction.class);
+ String identity = "identity";
+ Permission allow = Permission.ALLOW;
+
+ Rule rule = new Rule(identity, aclAction, allow);
+ Rule equalRule = new Rule(identity, aclAction, allow);
+
+ assertTrue(rule.equals(rule));
+ assertTrue(rule.equals(equalRule));
+ assertTrue(equalRule.equals(rule));
+
+ assertTrue(rule.hashCode() == equalRule.hashCode());
+
+ assertFalse("Different identity should cause rules to be unequal",
+ rule.equals(new Rule("identity2", aclAction, allow)));
+
+ assertFalse("Different action should cause rules to be unequal",
+ rule.equals(new Rule(identity, mock(AclAction.class), allow)));
+
+ assertFalse("Different permission should cause rules to be unequal",
+ rule.equals(new Rule(identity, aclAction, Permission.DENY)));
+ }
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/firewall/HostnameFirewallRuleTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/firewall/HostnameFirewallRuleTest.java
new file mode 100644
index 0000000000..be82cb294a
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/firewall/HostnameFirewallRuleTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.security.access.firewall;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.net.InetAddress;
+
+import org.apache.qpid.server.security.access.firewall.HostnameFirewallRule;
+
+import junit.framework.TestCase;
+
+public class HostnameFirewallRuleTest extends TestCase
+{
+ private InetAddress _addressNotInRule;
+
+ private HostnameFirewallRule _HostnameFirewallRule;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ _addressNotInRule = InetAddress.getByName("127.0.0.1");
+ }
+
+ public void testSingleHostname() throws Exception
+ {
+ String hostnameInRule = "hostnameInRule";
+ InetAddress addressWithMatchingHostname = mock(InetAddress.class);
+ when(addressWithMatchingHostname.getCanonicalHostName()).thenReturn(hostnameInRule);
+
+ _HostnameFirewallRule = new HostnameFirewallRule(hostnameInRule);
+
+ assertFalse(_HostnameFirewallRule.matches(_addressNotInRule));
+ assertTrue(_HostnameFirewallRule.matches(addressWithMatchingHostname));
+ }
+
+ public void testSingleHostnameWilcard() throws Exception
+ {
+ String hostnameInRule = ".*FOO.*";
+ InetAddress addressWithMatchingHostname = mock(InetAddress.class);
+ when(addressWithMatchingHostname.getCanonicalHostName()).thenReturn("xxFOOxx");
+
+ _HostnameFirewallRule = new HostnameFirewallRule(hostnameInRule);
+
+ assertFalse(_HostnameFirewallRule.matches(_addressNotInRule));
+ assertTrue(_HostnameFirewallRule.matches(addressWithMatchingHostname));
+ }
+
+ public void testMultipleHostnames() throws Exception
+ {
+ String[] hostnamesInRule = new String[] {"hostnameInRule1", "hostnameInRule2"};
+
+ _HostnameFirewallRule = new HostnameFirewallRule(hostnamesInRule);
+
+ assertFalse(_HostnameFirewallRule.matches(_addressNotInRule));
+ for (String hostnameInRule : hostnamesInRule)
+ {
+ InetAddress addressWithMatchingHostname = mock(InetAddress.class);
+ when(addressWithMatchingHostname.getCanonicalHostName()).thenReturn(hostnameInRule);
+
+ assertTrue(_HostnameFirewallRule.matches(addressWithMatchingHostname));
+ }
+ }
+
+ public void testEqualsAndHashCode()
+ {
+ String hostname1 = "hostname1";
+ String hostname2 = "hostname2";
+
+ HostnameFirewallRule rule = new HostnameFirewallRule(hostname1, hostname2);
+ HostnameFirewallRule equalRule = new HostnameFirewallRule(hostname1, hostname2);
+
+ assertTrue(rule.equals(rule));
+ assertTrue(rule.equals(equalRule));
+ assertTrue(equalRule.equals(rule));
+
+ assertTrue(rule.hashCode() == equalRule.hashCode());
+
+ assertFalse("Different hostnames should cause rules to be unequal",
+ rule.equals(new HostnameFirewallRule(hostname1, "different-hostname")));
+ }
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/firewall/NetworkFirewallRuleTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/firewall/NetworkFirewallRuleTest.java
new file mode 100644
index 0000000000..e521039db2
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/firewall/NetworkFirewallRuleTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.security.access.firewall;
+
+import java.net.InetAddress;
+
+import org.apache.qpid.server.security.access.firewall.NetworkFirewallRule;
+
+import junit.framework.TestCase;
+
+public class NetworkFirewallRuleTest extends TestCase
+{
+ private static final String LOCALHOST_IP = "127.0.0.1";
+ private static final String OTHER_IP_1 = "192.168.23.1";
+ private static final String OTHER_IP_2 = "192.168.23.2";
+
+ private InetAddress _addressNotInRule;
+
+ private NetworkFirewallRule _networkFirewallRule;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ _addressNotInRule = InetAddress.getByName(LOCALHOST_IP);
+ }
+
+ public void testIpRule() throws Exception
+ {
+ String ipAddressInRule = OTHER_IP_1;
+
+ _networkFirewallRule = new NetworkFirewallRule(ipAddressInRule);
+
+ assertFalse(_networkFirewallRule.matches(_addressNotInRule));
+ assertTrue(_networkFirewallRule.matches(InetAddress.getByName(ipAddressInRule)));
+ }
+
+ public void testNetMask() throws Exception
+ {
+ String ipAddressInRule = "192.168.23.0/24";
+ _networkFirewallRule = new NetworkFirewallRule(ipAddressInRule);
+
+ assertFalse(_networkFirewallRule.matches(InetAddress.getByName("192.168.24.1")));
+ assertTrue(_networkFirewallRule.matches(InetAddress.getByName("192.168.23.0")));
+ assertTrue(_networkFirewallRule.matches(InetAddress.getByName("192.168.23.255")));
+ }
+
+ public void testWildcard() throws Exception
+ {
+ // Test xxx.xxx.*
+
+ assertFalse(new NetworkFirewallRule("192.168.*")
+ .matches(InetAddress.getByName("192.169.1.0")));
+
+ assertTrue(new NetworkFirewallRule("192.168.*")
+ .matches(InetAddress.getByName("192.168.1.0")));
+
+ assertTrue(new NetworkFirewallRule("192.168.*")
+ .matches(InetAddress.getByName("192.168.255.255")));
+
+ // Test xxx.xxx.xxx.*
+
+ assertFalse(new NetworkFirewallRule("192.168.1.*")
+ .matches(InetAddress.getByName("192.169.2.0")));
+
+ assertTrue(new NetworkFirewallRule("192.168.1.*")
+ .matches(InetAddress.getByName("192.168.1.0")));
+
+ assertTrue(new NetworkFirewallRule("192.168.1.*")
+ .matches(InetAddress.getByName("192.168.1.255")));
+ }
+
+ public void testMultipleNetworks() throws Exception
+ {
+ String[] ipAddressesInRule = new String[] {OTHER_IP_1, OTHER_IP_2};
+
+ _networkFirewallRule = new NetworkFirewallRule(ipAddressesInRule);
+
+ assertFalse(_networkFirewallRule.matches(_addressNotInRule));
+ for (String ipAddressInRule : ipAddressesInRule)
+ {
+ assertTrue(_networkFirewallRule.matches(InetAddress.getByName(ipAddressInRule)));
+ }
+ }
+
+ public void testEqualsAndHashCode()
+ {
+ NetworkFirewallRule rule = new NetworkFirewallRule(LOCALHOST_IP, OTHER_IP_1);
+ NetworkFirewallRule equalRule = new NetworkFirewallRule(LOCALHOST_IP, OTHER_IP_1);
+
+ assertTrue(rule.equals(rule));
+ assertTrue(rule.equals(equalRule));
+ assertTrue(equalRule.equals(rule));
+
+ assertTrue(rule.hashCode() == equalRule.hashCode());
+
+ assertFalse("Different networks should cause rules to be unequal",
+ rule.equals(new NetworkFirewallRule(LOCALHOST_IP, OTHER_IP_2)));
+ }
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/AccessControlTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/AccessControlTest.java
deleted file mode 100644
index 5db02d10ce..0000000000
--- a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/AccessControlTest.java
+++ /dev/null
@@ -1,355 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.logging.UnitTestMessageLogger;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.TestLogActor;
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-import org.apache.qpid.server.security.access.Permission;
-import org.apache.qpid.server.security.access.config.Rule;
-import org.apache.qpid.server.security.access.config.RuleSet;
-import org.apache.qpid.server.security.auth.sasl.TestPrincipalUtils;
-
-/**
- * Unit test for ACL V2 plugin.
- *
- * This unit test tests the AccessControl class and it collaboration with {@link RuleSet},
- * {@link SecurityManager} and {@link CurrentActor}. The ruleset is configured programmatically,
- * rather than from an external file.
- *
- * @see RuleSetTest
- */
-public class AccessControlTest extends TestCase
-{
- private AccessControl _plugin = null; // Class under test
- private final UnitTestMessageLogger messageLogger = new UnitTestMessageLogger();
-
- private void setUpGroupAccessControl() throws ConfigurationException
- {
- configureAccessControl(createGroupRuleSet());
- }
-
- private void configureAccessControl(final RuleSet rs) throws ConfigurationException
- {
- _plugin = (AccessControl) AccessControl.FACTORY.newInstance(createConfiguration(rs));
- SecurityManager.setThreadSubject(null);
- CurrentActor.set(new TestLogActor(messageLogger));
- }
-
- private RuleSet createGroupRuleSet()
- {
- final RuleSet rs = new RuleSet();
- rs.addGroup("aclGroup1", Arrays.asList(new String[] {"member1", "Member2"}));
-
- // Rule expressed with username
- rs.grant(0, "user1", Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- // Rule expressed with a acl group
- rs.grant(1, "aclGroup1", Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- // Rule expressed with an external group
- rs.grant(2, "extGroup1", Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- // Catch all rule
- rs.grant(3, Rule.ALL, Permission.DENY_LOG, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
-
- return rs;
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
- SecurityManager.setThreadSubject(null);
- }
-
- /**
- * ACL plugin must always abstain if there is no subject attached to the thread.
- */
- public void testNoSubjectAlwaysAbstains() throws ConfigurationException
- {
- setUpGroupAccessControl();
- SecurityManager.setThreadSubject(null);
-
- final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- assertEquals(Result.ABSTAIN, result);
- }
-
- /**
- * Tests that an allow rule expressed with a username allows an operation performed by a thread running
- * with the same username.
- */
- public void testUsernameAllowsOperation() throws ConfigurationException
- {
- setUpGroupAccessControl();
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user1"));
-
- final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- assertEquals(Result.ALLOWED, result);
- }
-
- /**
- * Tests that an allow rule expressed with an <b>ACL groupname</b> allows an operation performed by a thread running
- * by a user who belongs to the same group..
- */
- public void testAclGroupMembershipAllowsOperation() throws ConfigurationException
- {
- setUpGroupAccessControl();
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("member1"));
-
- Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- assertEquals(Result.ALLOWED, result);
-
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("Member2"));
-
- result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- assertEquals(Result.ALLOWED, result);
- }
-
- /**
- * Tests that a deny rule expressed with an <b>External groupname</b> denies an operation performed by a thread running
- * by a user who belongs to the same group.
- */
- public void testExternalGroupMembershipDeniesOperation() throws ConfigurationException
- {
- setUpGroupAccessControl();
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user3", "extGroup1"));
-
- final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- assertEquals(Result.DENIED, result);
- }
-
- /**
- * Tests that the catch all deny denies the operation and logs with the logging actor.
- */
- public void testCatchAllRuleDeniesUnrecognisedUsername() throws ConfigurationException
- {
- setUpGroupAccessControl();
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("unknown", "unkgroup1", "unkgroup2"));
-
- assertEquals("Expecting zero messages before test", 0, messageLogger.getLogMessages().size());
- final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- assertEquals(Result.DENIED, result);
-
- assertEquals("Expecting one message before test", 1, messageLogger.getLogMessages().size());
- assertTrue("Logged message does not contain expected string", messageLogger.messageContains(0, "ACL-1002"));
- }
-
- /**
- * Tests that a grant access method rule allows any access operation to be performed on any component
- */
- public void testAuthoriseAccessMethodWhenAllAccessOperationsAllowedOnAllComponents() throws ConfigurationException
- {
- final RuleSet rs = new RuleSet();
-
- // grant user4 access right on any method in any component
- rs.grant(1, "user4", Permission.ALLOW, Operation.ACCESS, ObjectType.METHOD, new ObjectProperties(ObjectProperties.STAR));
- configureAccessControl(rs);
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user4"));
-
- ObjectProperties actionProperties = new ObjectProperties("getName");
- actionProperties.put(ObjectProperties.Property.COMPONENT, "Test");
-
- final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, actionProperties);
- assertEquals(Result.ALLOWED, result);
- }
-
- /**
- * Tests that a grant access method rule allows any access operation to be performed on a specified component
- */
- public void testAuthoriseAccessMethodWhenAllAccessOperationsAllowedOnSpecifiedComponent() throws ConfigurationException
- {
- final RuleSet rs = new RuleSet();
-
- // grant user5 access right on any methods in "Test" component
- ObjectProperties ruleProperties = new ObjectProperties(ObjectProperties.STAR);
- ruleProperties.put(ObjectProperties.Property.COMPONENT, "Test");
- rs.grant(1, "user5", Permission.ALLOW, Operation.ACCESS, ObjectType.METHOD, ruleProperties);
- configureAccessControl(rs);
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user5"));
-
- ObjectProperties actionProperties = new ObjectProperties("getName");
- actionProperties.put(ObjectProperties.Property.COMPONENT, "Test");
- Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, actionProperties);
- assertEquals(Result.ALLOWED, result);
-
- actionProperties.put(ObjectProperties.Property.COMPONENT, "Test2");
- result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, actionProperties);
- assertEquals(Result.DEFER, result);
- }
-
- /**
- * Tests that a grant access method rule allows any access operation to be performed on a specified component
- */
- public void testAuthoriseAccessMethodWhenSpecifiedAccessOperationsAllowedOnSpecifiedComponent() throws ConfigurationException
- {
- final RuleSet rs = new RuleSet();
-
- // grant user6 access right on "getAttribute" method in "Test" component
- ObjectProperties ruleProperties = new ObjectProperties("getAttribute");
- ruleProperties.put(ObjectProperties.Property.COMPONENT, "Test");
- rs.grant(1, "user6", Permission.ALLOW, Operation.ACCESS, ObjectType.METHOD, ruleProperties);
- configureAccessControl(rs);
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user6"));
-
- ObjectProperties properties = new ObjectProperties("getAttribute");
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
- Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
-
- properties.put(ObjectProperties.Property.COMPONENT, "Test2");
- result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.DEFER, result);
-
- properties = new ObjectProperties("getAttribute2");
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
- result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.DEFER, result);
- }
-
- /**
- * Tests that granting of all method rights on a method allows a specified operation to be performed on any component
- */
- public void testAuthoriseAccessUpdateMethodWhenAllRightsGrantedOnSpecifiedMethodForAllComponents() throws ConfigurationException
- {
- final RuleSet rs = new RuleSet();
-
- // grant user8 all rights on method queryNames in all component
- rs.grant(1, "user8", Permission.ALLOW, Operation.ALL, ObjectType.METHOD, new ObjectProperties("queryNames"));
- configureAccessControl(rs);
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user8"));
-
- ObjectProperties properties = new ObjectProperties();
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
- properties.put(ObjectProperties.Property.NAME, "queryNames");
-
- Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
-
- result = _plugin.authorise(Operation.UPDATE, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
-
- properties = new ObjectProperties("getAttribute");
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
- result = _plugin.authorise(Operation.UPDATE, ObjectType.METHOD, properties);
- assertEquals(Result.DEFER, result);
-
- result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.DEFER, result);
- }
-
- /**
- * Tests that granting of all method rights allows any operation to be performed on any component
- */
- public void testAuthoriseAccessUpdateMethodWhenAllRightsGrantedOnAllMethodsInAllComponents() throws ConfigurationException
- {
- final RuleSet rs = new RuleSet();
-
- // grant user9 all rights on any method in all component
- rs.grant(1, "user9", Permission.ALLOW, Operation.ALL, ObjectType.METHOD, new ObjectProperties());
- configureAccessControl(rs);
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user9"));
-
- ObjectProperties properties = new ObjectProperties("queryNames");
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
-
- Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
-
- result = _plugin.authorise(Operation.UPDATE, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
-
- properties = new ObjectProperties("getAttribute");
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
- result = _plugin.authorise(Operation.UPDATE, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
-
- result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
- }
-
- /**
- * Tests that granting of access method rights with mask allows matching operations to be performed on the specified component
- */
- public void testAuthoriseAccessMethodWhenMatchingAcessOperationsAllowedOnSpecifiedComponent() throws ConfigurationException
- {
- final RuleSet rs = new RuleSet();
-
- // grant user9 all rights on "getAttribute*" methods in Test component
- ObjectProperties ruleProperties = new ObjectProperties();
- ruleProperties.put(ObjectProperties.Property.COMPONENT, "Test");
- ruleProperties.put(ObjectProperties.Property.NAME, "getAttribute*");
-
- rs.grant(1, "user9", Permission.ALLOW, Operation.ACCESS, ObjectType.METHOD, ruleProperties);
- configureAccessControl(rs);
- SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user9"));
-
- ObjectProperties properties = new ObjectProperties("getAttributes");
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
- Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
-
- properties = new ObjectProperties("getAttribute");
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
- result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.ALLOWED, result);
-
- properties = new ObjectProperties("getAttribut");
- properties.put(ObjectProperties.Property.COMPONENT, "Test");
- result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
- assertEquals(Result.DEFER, result);
- }
-
- /**
- * Creates a configuration plugin for the {@link AccessControl} plugin.
- */
- private ConfigurationPlugin createConfiguration(final RuleSet rs)
- {
- final ConfigurationPlugin cp = new ConfigurationPlugin()
- {
- @SuppressWarnings("unchecked")
- public AccessControlConfiguration getConfiguration(final String plugin)
- {
- return new AccessControlConfiguration()
- {
- public RuleSet getRuleSet()
- {
- return rs;
- }
- };
- }
-
- public String[] getElementsProcessed()
- {
- throw new UnsupportedOperationException();
- }
- };
-
- return cp;
- }
-}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java
new file mode 100644
index 0000000000..ca1f19098f
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java
@@ -0,0 +1,69 @@
+package org.apache.qpid.server.security.access.plugins;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.security.AccessControl;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+public class DefaultAccessControlFactoryTest extends QpidTestCase
+{
+ public void testCreateInstanceWhenAclFileIsNotPresent()
+ {
+ DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ AccessControl acl = factory.createInstance(attributes);
+ assertNull("ACL was created without a configuration file", acl);
+ }
+
+ public void testCreateInstanceWhenAclFileIsSpecified()
+ {
+ File aclFile = TestFileUtils.createTempFile(this, ".acl", "ACL ALLOW all all");
+ DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile.getAbsolutePath());
+ AccessControl acl = factory.createInstance(attributes);
+
+ assertNotNull("ACL was not created from acl file: " + aclFile.getAbsolutePath(), acl);
+ }
+
+ public void testCreateInstanceWhenAclFileIsSpecifiedButDoesNotExist()
+ {
+ File aclFile = new File(TMP_FOLDER, "my-non-existing-acl-" + System.currentTimeMillis());
+ assertFalse("ACL file " + aclFile.getAbsolutePath() + " actually exists but should not", aclFile.exists());
+ DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile.getAbsolutePath());
+ try
+ {
+ factory.createInstance(attributes);
+ fail("It should not be possible to create ACL from non existing file");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ assertTrue("Unexpected exception message", Pattern.matches("ACL file '.*' is not found", e.getMessage()));
+ }
+ }
+
+ public void testCreateInstanceWhenAclFileIsSpecifiedAsNonString()
+ {
+ DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ Integer aclFile = new Integer(0);
+ attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile);
+ try
+ {
+ factory.createInstance(attributes);
+ fail("It should not be possible to create ACL from Integer");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ assertEquals("Unexpected exception message", "Expected '" + DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE
+ + "' attribute value of type String but was " + Integer.class + ": " + aclFile, e.getMessage());
+ }
+ }
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlTest.java
new file mode 100644
index 0000000000..a8406308c0
--- /dev/null
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlTest.java
@@ -0,0 +1,368 @@
+/*
+ *
+ * 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.security.access.plugins;
+
+import static org.mockito.Mockito.*;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import javax.security.auth.Subject;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.logging.UnitTestMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.security.Result;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectType;
+import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.access.Permission;
+import org.apache.qpid.server.security.access.config.Rule;
+import org.apache.qpid.server.security.access.config.RuleSet;
+import org.apache.qpid.server.security.auth.TestPrincipalUtils;
+
+/**
+ * In these tests, the ruleset is configured programmatically rather than from an external file.
+ *
+ * @see RuleSetTest
+ */
+public class DefaultAccessControlTest extends TestCase
+{
+ private static final String ALLOWED_GROUP = "allowed_group";
+ private static final String DENIED_GROUP = "denied_group";
+
+ private DefaultAccessControl _plugin = null; // Class under test
+ private final UnitTestMessageLogger messageLogger = new UnitTestMessageLogger();
+
+ private void setUpGroupAccessControl() throws ConfigurationException
+ {
+ configureAccessControl(createGroupRuleSet());
+ }
+
+ private void configureAccessControl(final RuleSet rs) throws ConfigurationException
+ {
+ _plugin = new DefaultAccessControl(rs);
+ SecurityManager.setThreadSubject(null);
+ CurrentActor.set(new TestLogActor(messageLogger));
+ }
+
+ private RuleSet createGroupRuleSet()
+ {
+ final RuleSet rs = new RuleSet();
+
+ // Rule expressed with username
+ rs.grant(0, "user1", Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ // Rules expressed with groups
+ rs.grant(1, ALLOWED_GROUP, Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ rs.grant(2, DENIED_GROUP, Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ // Catch all rule
+ rs.grant(3, Rule.ALL, Permission.DENY_LOG, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+
+ return rs;
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ SecurityManager.setThreadSubject(null);
+ }
+
+ /**
+ * ACL plugin must always abstain if there is no subject attached to the thread.
+ */
+ public void testNoSubjectAlwaysAbstains() throws ConfigurationException
+ {
+ setUpGroupAccessControl();
+ SecurityManager.setThreadSubject(null);
+
+ final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ assertEquals(Result.ABSTAIN, result);
+ }
+
+ /**
+ * Tests that an allow rule expressed with a username allows an operation performed by a thread running
+ * with the same username.
+ */
+ public void testUsernameAllowsOperation() throws ConfigurationException
+ {
+ setUpGroupAccessControl();
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user1"));
+
+ final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ assertEquals(Result.ALLOWED, result);
+ }
+
+ /**
+ * Tests that an allow rule expressed with an <b>ACL groupname</b> allows an operation performed by a thread running
+ * by a user who belongs to the same group..
+ */
+ public void testGroupMembershipAllowsOperation() throws ConfigurationException
+ {
+ setUpGroupAccessControl();
+
+ authoriseAndAssertResult(Result.ALLOWED, "member of allowed group", ALLOWED_GROUP);
+ authoriseAndAssertResult(Result.DENIED, "member of denied group", DENIED_GROUP);
+ authoriseAndAssertResult(Result.ALLOWED, "another member of allowed group", ALLOWED_GROUP);
+ }
+
+ /**
+ * Tests that a deny rule expressed with a <b>groupname</b> denies an operation performed by a thread running
+ * by a user who belongs to the same group.
+ */
+ public void testGroupMembershipDeniesOperation() throws ConfigurationException
+ {
+ setUpGroupAccessControl();
+ authoriseAndAssertResult(Result.DENIED, "user3", DENIED_GROUP);
+ }
+
+ /**
+ * Tests that the catch all deny denies the operation and logs with the logging actor.
+ */
+ public void testCatchAllRuleDeniesUnrecognisedUsername() throws ConfigurationException
+ {
+ setUpGroupAccessControl();
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("unknown", "unkgroup1", "unkgroup2"));
+
+ assertEquals("Expecting zero messages before test", 0, messageLogger.getLogMessages().size());
+ final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ assertEquals(Result.DENIED, result);
+
+ assertEquals("Expecting one message before test", 1, messageLogger.getLogMessages().size());
+ assertTrue("Logged message does not contain expected string", messageLogger.messageContains(0, "ACL-1002"));
+ }
+
+ /**
+ * Tests that a grant access method rule allows any access operation to be performed on any component
+ */
+ public void testAuthoriseAccessMethodWhenAllAccessOperationsAllowedOnAllComponents() throws ConfigurationException
+ {
+ final RuleSet rs = new RuleSet();
+
+ // grant user4 access right on any method in any component
+ rs.grant(1, "user4", Permission.ALLOW, Operation.ACCESS, ObjectType.METHOD, new ObjectProperties(ObjectProperties.STAR));
+ configureAccessControl(rs);
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user4"));
+
+ ObjectProperties actionProperties = new ObjectProperties("getName");
+ actionProperties.put(ObjectProperties.Property.COMPONENT, "Test");
+
+ final Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, actionProperties);
+ assertEquals(Result.ALLOWED, result);
+ }
+
+ /**
+ * Tests that a grant access method rule allows any access operation to be performed on a specified component
+ */
+ public void testAuthoriseAccessMethodWhenAllAccessOperationsAllowedOnSpecifiedComponent() throws ConfigurationException
+ {
+ final RuleSet rs = new RuleSet();
+
+ // grant user5 access right on any methods in "Test" component
+ ObjectProperties ruleProperties = new ObjectProperties(ObjectProperties.STAR);
+ ruleProperties.put(ObjectProperties.Property.COMPONENT, "Test");
+ rs.grant(1, "user5", Permission.ALLOW, Operation.ACCESS, ObjectType.METHOD, ruleProperties);
+ configureAccessControl(rs);
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user5"));
+
+ ObjectProperties actionProperties = new ObjectProperties("getName");
+ actionProperties.put(ObjectProperties.Property.COMPONENT, "Test");
+ Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, actionProperties);
+ assertEquals(Result.ALLOWED, result);
+
+ actionProperties.put(ObjectProperties.Property.COMPONENT, "Test2");
+ result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, actionProperties);
+ assertEquals(Result.DEFER, result);
+ }
+
+ public void testAccess() throws Exception
+ {
+ Subject subject = TestPrincipalUtils.createTestSubject("user1");
+ SecurityManager.setThreadSubject(subject);
+
+ RuleSet mockRuleSet = mock(RuleSet.class);
+
+ InetAddress inetAddress = InetAddress.getLocalHost();
+ InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 1);
+
+ DefaultAccessControl accessControl = new DefaultAccessControl(mockRuleSet);
+
+ accessControl.access(ObjectType.VIRTUALHOST, inetSocketAddress);
+
+ verify(mockRuleSet).check(subject, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY, inetAddress);
+ }
+
+ public void testAccessIsDeniedIfRuleThrowsException() throws Exception
+ {
+ Subject subject = TestPrincipalUtils.createTestSubject("user1");
+ SecurityManager.setThreadSubject(subject);
+
+ InetAddress inetAddress = InetAddress.getLocalHost();
+ InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 1);
+
+ RuleSet mockRuleSet = mock(RuleSet.class);
+ when(mockRuleSet.check(
+ subject,
+ Operation.ACCESS,
+ ObjectType.VIRTUALHOST,
+ ObjectProperties.EMPTY,
+ inetAddress)).thenThrow(new RuntimeException());
+
+ DefaultAccessControl accessControl = new DefaultAccessControl(mockRuleSet);
+ Result result = accessControl.access(ObjectType.VIRTUALHOST, inetSocketAddress);
+
+ assertEquals(Result.DENIED, result);
+ }
+
+
+ /**
+ * Tests that a grant access method rule allows any access operation to be performed on a specified component
+ */
+ public void testAuthoriseAccessMethodWhenSpecifiedAccessOperationsAllowedOnSpecifiedComponent() throws ConfigurationException
+ {
+ final RuleSet rs = new RuleSet();
+
+ // grant user6 access right on "getAttribute" method in "Test" component
+ ObjectProperties ruleProperties = new ObjectProperties("getAttribute");
+ ruleProperties.put(ObjectProperties.Property.COMPONENT, "Test");
+ rs.grant(1, "user6", Permission.ALLOW, Operation.ACCESS, ObjectType.METHOD, ruleProperties);
+ configureAccessControl(rs);
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user6"));
+
+ ObjectProperties properties = new ObjectProperties("getAttribute");
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+ Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+
+ properties.put(ObjectProperties.Property.COMPONENT, "Test2");
+ result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.DEFER, result);
+
+ properties = new ObjectProperties("getAttribute2");
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+ result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.DEFER, result);
+ }
+
+ /**
+ * Tests that granting of all method rights on a method allows a specified operation to be performed on any component
+ */
+ public void testAuthoriseAccessUpdateMethodWhenAllRightsGrantedOnSpecifiedMethodForAllComponents() throws ConfigurationException
+ {
+ final RuleSet rs = new RuleSet();
+
+ // grant user8 all rights on method queryNames in all component
+ rs.grant(1, "user8", Permission.ALLOW, Operation.ALL, ObjectType.METHOD, new ObjectProperties("queryNames"));
+ configureAccessControl(rs);
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user8"));
+
+ ObjectProperties properties = new ObjectProperties();
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+ properties.put(ObjectProperties.Property.NAME, "queryNames");
+
+ Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+
+ result = _plugin.authorise(Operation.UPDATE, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+
+ properties = new ObjectProperties("getAttribute");
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+ result = _plugin.authorise(Operation.UPDATE, ObjectType.METHOD, properties);
+ assertEquals(Result.DEFER, result);
+
+ result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.DEFER, result);
+ }
+
+ /**
+ * Tests that granting of all method rights allows any operation to be performed on any component
+ */
+ public void testAuthoriseAccessUpdateMethodWhenAllRightsGrantedOnAllMethodsInAllComponents() throws ConfigurationException
+ {
+ final RuleSet rs = new RuleSet();
+
+ // grant user9 all rights on any method in all component
+ rs.grant(1, "user9", Permission.ALLOW, Operation.ALL, ObjectType.METHOD, new ObjectProperties());
+ configureAccessControl(rs);
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user9"));
+
+ ObjectProperties properties = new ObjectProperties("queryNames");
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+
+ Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+
+ result = _plugin.authorise(Operation.UPDATE, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+
+ properties = new ObjectProperties("getAttribute");
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+ result = _plugin.authorise(Operation.UPDATE, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+
+ result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+ }
+
+ /**
+ * Tests that granting of access method rights with mask allows matching operations to be performed on the specified component
+ */
+ public void testAuthoriseAccessMethodWhenMatchingAcessOperationsAllowedOnSpecifiedComponent() throws ConfigurationException
+ {
+ final RuleSet rs = new RuleSet();
+
+ // grant user9 all rights on "getAttribute*" methods in Test component
+ ObjectProperties ruleProperties = new ObjectProperties();
+ ruleProperties.put(ObjectProperties.Property.COMPONENT, "Test");
+ ruleProperties.put(ObjectProperties.Property.NAME, "getAttribute*");
+
+ rs.grant(1, "user9", Permission.ALLOW, Operation.ACCESS, ObjectType.METHOD, ruleProperties);
+ configureAccessControl(rs);
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject("user9"));
+
+ ObjectProperties properties = new ObjectProperties("getAttributes");
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+ Result result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+
+ properties = new ObjectProperties("getAttribute");
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+ result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.ALLOWED, result);
+
+ properties = new ObjectProperties("getAttribut");
+ properties.put(ObjectProperties.Property.COMPONENT, "Test");
+ result = _plugin.authorise(Operation.ACCESS, ObjectType.METHOD, properties);
+ assertEquals(Result.DEFER, result);
+ }
+
+ private void authoriseAndAssertResult(Result expectedResult, String userName, String... groups)
+ {
+ SecurityManager.setThreadSubject(TestPrincipalUtils.createTestSubject(userName, groups));
+
+ Result result = _plugin.authorise(Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ assertEquals(expectedResult, result);
+ }
+}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/PlainConfigurationTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/PlainConfigurationTest.java
deleted file mode 100644
index c2282694fb..0000000000
--- a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/PlainConfigurationTest.java
+++ /dev/null
@@ -1,394 +0,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.
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectProperties.Property;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-import org.apache.qpid.server.security.access.config.ConfigurationFile;
-import org.apache.qpid.server.security.access.config.PlainConfiguration;
-import org.apache.qpid.server.security.access.config.Rule;
-import org.apache.qpid.server.security.access.config.RuleSet;
-
-/**
- * These tests check that the ACL file parsing works correctly.
- *
- * For each message that can be returned in a {@link ConfigurationException}, an ACL file is created that should trigger this
- * particular message.
- */
-public class PlainConfigurationTest extends TestCase
-{
- private PlainConfiguration writeACLConfig(String...aclData) throws Exception
- {
- File acl = File.createTempFile(getClass().getName() + getName(), "acl");
- acl.deleteOnExit();
-
- // Write ACL file
- PrintWriter aclWriter = new PrintWriter(new FileWriter(acl));
- for (String line : aclData)
- {
- aclWriter.println(line);
- }
- aclWriter.close();
-
- // Load ruleset
- PlainConfiguration configFile = new PlainConfiguration(acl);
- configFile.load();
- return configFile;
- }
-
- public void testMissingACLConfig() throws Exception
- {
- try
- {
- // Load ruleset
- ConfigurationFile configFile = new PlainConfiguration(new File("doesnotexist"));
- configFile.load();
-
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.CONFIG_NOT_FOUND_MSG, "doesnotexist"), ce.getMessage());
- assertTrue(ce.getCause() instanceof FileNotFoundException);
- }
- }
-
- public void testACLFileSyntaxContinuation() throws Exception
- {
- try
- {
- writeACLConfig("ACL ALLOW ALL \\ ALL");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.PREMATURE_CONTINUATION_MSG, 1), ce.getMessage());
- }
- }
-
- public void testACLFileSyntaxTokens() throws Exception
- {
- try
- {
- writeACLConfig("ACL unparsed ALL ALL");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.PARSE_TOKEN_FAILED_MSG, 1), ce.getMessage());
- assertTrue(ce.getCause() instanceof IllegalArgumentException);
- assertEquals("Not a valid permission: unparsed", ce.getCause().getMessage());
- }
- }
-
- public void testACLFileSyntaxNotEnoughGroup() throws Exception
- {
- try
- {
- writeACLConfig("GROUP blah");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_GROUP_MSG, 1), ce.getMessage());
- }
- }
-
- public void testACLFileSyntaxNotEnoughACL() throws Exception
- {
- try
- {
- writeACLConfig("ACL ALLOW");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_ACL_MSG, 1), ce.getMessage());
- }
- }
-
- public void testACLFileSyntaxNotEnoughConfig() throws Exception
- {
- try
- {
- writeACLConfig("CONFIG");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_TOKENS_MSG, 1), ce.getMessage());
- }
- }
-
- public void testACLFileSyntaxNotEnough() throws Exception
- {
- try
- {
- writeACLConfig("INVALID");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.NOT_ENOUGH_TOKENS_MSG, 1), ce.getMessage());
- }
- }
-
- public void testACLFileSyntaxPropertyKeyOnly() throws Exception
- {
- try
- {
- writeACLConfig("ACL ALLOW adk CREATE QUEUE name");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.PROPERTY_KEY_ONLY_MSG, 1), ce.getMessage());
- }
- }
-
- public void testACLFileSyntaxPropertyNoEquals() throws Exception
- {
- try
- {
- writeACLConfig("ACL ALLOW adk CREATE QUEUE name test");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.PROPERTY_NO_EQUALS_MSG, 1), ce.getMessage());
- }
- }
-
- public void testACLFileSyntaxPropertyNoValue() throws Exception
- {
- try
- {
- writeACLConfig("ACL ALLOW adk CREATE QUEUE name =");
- fail("fail");
- }
- catch (ConfigurationException ce)
- {
- assertEquals(String.format(PlainConfiguration.PROPERTY_NO_VALUE_MSG, 1), ce.getMessage());
- }
- }
-
- /**
- * Tests interpretation of an acl rule with no object properties.
- *
- */
- public void testValidRule() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("ACL DENY-LOG user1 ACCESS VIRTUALHOST");
- final RuleSet rs = config.getConfiguration();
- assertEquals(1, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(1, rules.size());
- final Rule rule = rules.get(0);
- assertEquals("Rule has unexpected identity", "user1", rule.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.ACCESS, rule.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.VIRTUALHOST, rule.getAction().getObjectType());
- assertEquals("Rule has unexpected object properties", ObjectProperties.EMPTY, rule.getAction().getProperties());
- }
-
- /**
- * Tests interpretation of an acl rule with object properties quoted in single quotes.
- */
- public void testValidRuleWithSingleQuotedProperty() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("ACL ALLOW all CREATE EXCHANGE name = \'value\'");
- final RuleSet rs = config.getConfiguration();
- assertEquals(1, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(1, rules.size());
- final Rule rule = rules.get(0);
- assertEquals("Rule has unexpected identity", "all", rule.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.CREATE, rule.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.EXCHANGE, rule.getAction().getObjectType());
- final ObjectProperties expectedProperties = new ObjectProperties();
- expectedProperties.setName("value");
- assertEquals("Rule has unexpected object properties", expectedProperties, rule.getAction().getProperties());
- }
-
- /**
- * Tests interpretation of an acl rule with object properties quoted in double quotes.
- */
- public void testValidRuleWithDoubleQuotedProperty() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("ACL ALLOW all CREATE EXCHANGE name = \"value\"");
- final RuleSet rs = config.getConfiguration();
- assertEquals(1, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(1, rules.size());
- final Rule rule = rules.get(0);
- assertEquals("Rule has unexpected identity", "all", rule.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.CREATE, rule.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.EXCHANGE, rule.getAction().getObjectType());
- final ObjectProperties expectedProperties = new ObjectProperties();
- expectedProperties.setName("value");
- assertEquals("Rule has unexpected object properties", expectedProperties, rule.getAction().getProperties());
- }
-
- /**
- * Tests interpretation of an acl rule with many object properties.
- */
- public void testValidRuleWithManyProperties() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("ACL ALLOW admin DELETE QUEUE name=name1 owner = owner1");
- final RuleSet rs = config.getConfiguration();
- assertEquals(1, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(1, rules.size());
- final Rule rule = rules.get(0);
- assertEquals("Rule has unexpected identity", "admin", rule.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.DELETE, rule.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.QUEUE, rule.getAction().getObjectType());
- final ObjectProperties expectedProperties = new ObjectProperties();
- expectedProperties.setName("name1");
- expectedProperties.put(Property.OWNER, "owner1");
- assertEquals("Rule has unexpected operation", expectedProperties, rule.getAction().getProperties());
- }
-
- /**
- * Tests interpretation of an acl rule with object properties containing wildcards. Values containing
- * hashes must be quoted otherwise they are interpreted as comments.
- */
- public void testValidRuleWithWildcardProperties() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("ACL ALLOW all CREATE EXCHANGE routingKey = \'news.#\'",
- "ACL ALLOW all CREATE EXCHANGE routingKey = \'news.co.#\'",
- "ACL ALLOW all CREATE EXCHANGE routingKey = *.co.medellin");
- final RuleSet rs = config.getConfiguration();
- assertEquals(3, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(3, rules.size());
- final Rule rule1 = rules.get(0);
- assertEquals("Rule has unexpected identity", "all", rule1.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.CREATE, rule1.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.EXCHANGE, rule1.getAction().getObjectType());
- final ObjectProperties expectedProperties1 = new ObjectProperties();
- expectedProperties1.put(Property.ROUTING_KEY,"news.#");
- assertEquals("Rule has unexpected object properties", expectedProperties1, rule1.getAction().getProperties());
-
- final Rule rule2 = rules.get(10);
- final ObjectProperties expectedProperties2 = new ObjectProperties();
- expectedProperties2.put(Property.ROUTING_KEY,"news.co.#");
- assertEquals("Rule has unexpected object properties", expectedProperties2, rule2.getAction().getProperties());
-
- final Rule rule3 = rules.get(20);
- final ObjectProperties expectedProperties3 = new ObjectProperties();
- expectedProperties3.put(Property.ROUTING_KEY,"*.co.medellin");
- assertEquals("Rule has unexpected object properties", expectedProperties3, rule3.getAction().getProperties());
- }
-
- /**
- * Tests that rules are case insignificant.
- */
- public void testMixedCaseRuleInterpretation() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("AcL deny-LOG User1 BiND Exchange Name=AmQ.dIrect");
- final RuleSet rs = config.getConfiguration();
- assertEquals(1, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(1, rules.size());
- final Rule rule = rules.get(0);
- assertEquals("Rule has unexpected identity", "User1", rule.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.BIND, rule.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.EXCHANGE, rule.getAction().getObjectType());
- final ObjectProperties expectedProperties = new ObjectProperties("AmQ.dIrect");
- assertEquals("Rule has unexpected object properties", expectedProperties, rule.getAction().getProperties());
- }
-
- /**
- * Tests whitespace is supported. Note that currently the Java implementation permits comments to
- * be introduced anywhere in the ACL, whereas the C++ supports only whitespace at the beginning of
- * of line.
- */
- public void testCommentsSuppported() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("#Comment",
- "ACL DENY-LOG user1 ACCESS VIRTUALHOST # another comment",
- " # final comment with leading whitespace");
- final RuleSet rs = config.getConfiguration();
- assertEquals(1, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(1, rules.size());
- final Rule rule = rules.get(0);
- assertEquals("Rule has unexpected identity", "user1", rule.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.ACCESS, rule.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.VIRTUALHOST, rule.getAction().getObjectType());
- assertEquals("Rule has unexpected object properties", ObjectProperties.EMPTY, rule.getAction().getProperties());
- }
-
- /**
- * Tests interpretation of an acl rule using mixtures of tabs/spaces as token separators.
- *
- */
- public void testWhitespace() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("ACL\tDENY-LOG\t\t user1\t \tACCESS VIRTUALHOST");
- final RuleSet rs = config.getConfiguration();
- assertEquals(1, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(1, rules.size());
- final Rule rule = rules.get(0);
- assertEquals("Rule has unexpected identity", "user1", rule.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.ACCESS, rule.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.VIRTUALHOST, rule.getAction().getObjectType());
- assertEquals("Rule has unexpected object properties", ObjectProperties.EMPTY, rule.getAction().getProperties());
- }
-
- /**
- * Tests interpretation of an acl utilising line continuation.
- */
- public void testLineContination() throws Exception
- {
- final PlainConfiguration config = writeACLConfig("ACL DENY-LOG user1 \\",
- "ACCESS VIRTUALHOST");
- final RuleSet rs = config.getConfiguration();
- assertEquals(1, rs.getRuleCount());
-
- final Map<Integer, Rule> rules = rs.getAllRules();
- assertEquals(1, rules.size());
- final Rule rule = rules.get(0);
- assertEquals("Rule has unexpected identity", "user1", rule.getIdentity());
- assertEquals("Rule has unexpected operation", Operation.ACCESS, rule.getAction().getOperation());
- assertEquals("Rule has unexpected operation", ObjectType.VIRTUALHOST, rule.getAction().getObjectType());
- assertEquals("Rule has unexpected object properties", ObjectProperties.EMPTY, rule.getAction().getProperties());
- }
-
-}
diff --git a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java
index f7cc60543d..181d693614 100644
--- a/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java
+++ b/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/RuleSetTest.java
@@ -22,7 +22,6 @@
package org.apache.qpid.server.security.access.plugins;
import java.security.Principal;
-import java.util.Arrays;
import javax.security.auth.Subject;
@@ -34,8 +33,7 @@ import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.security.access.Permission;
import org.apache.qpid.server.security.access.config.Rule;
import org.apache.qpid.server.security.access.config.RuleSet;
-import org.apache.qpid.server.security.auth.sasl.TestPrincipalUtils;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.TestPrincipalUtils;
import org.apache.qpid.test.utils.QpidTestCase;
/**
@@ -46,10 +44,7 @@ import org.apache.qpid.test.utils.QpidTestCase;
* access control mechanism is validated by checking whether operations would be authorised by calling the
* {@link RuleSet#check(Principal, Operation, ObjectType, ObjectProperties)} method.
*
- * It ensure that permissions can be granted correctly on users directly, ACL groups (that is those
- * groups declared directly in the ACL itself), and External groups (that is a group from an External
- * Authentication Provider, such as an LDAP).
-
+ * It ensure that permissions can be granted correctly on users directly and on groups.
*/
public class RuleSetTest extends QpidTestCase
{
@@ -316,63 +311,36 @@ public class RuleSetTest extends QpidTestCase
assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject("userb"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
}
- /**
- * Tests support for ACL groups (i.e. inline groups declared in the ACL file itself).
- */
- public void testAclGroupsSupported()
+ public void testGroupsSupported()
{
- assertTrue(_ruleSet.addGroup("aclgroup", Arrays.asList(new String[] {"usera", "userb"})));
-
- _ruleSet.grant(1, "aclgroup", Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- assertEquals(1, _ruleSet.getRuleCount());
-
- assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject("usera"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
- assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject("userb"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
- assertEquals(Result.DEFER, _ruleSet.check(TestPrincipalUtils.createTestSubject("userc"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
- }
-
- /**
- * Tests support for nested ACL groups.
- */
- public void testNestedAclGroupsSupported()
- {
- assertTrue(_ruleSet.addGroup("aclgroup1", Arrays.asList(new String[] {"userb"})));
- assertTrue(_ruleSet.addGroup("aclgroup2", Arrays.asList(new String[] {"usera", "aclgroup1"})));
-
- _ruleSet.grant(1, "aclgroup2", Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- assertEquals(1, _ruleSet.getRuleCount());
+ String allowGroup = "allowGroup";
+ String deniedGroup = "deniedGroup";
- assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject("usera"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
- assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject("userb"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
- }
+ _ruleSet.grant(1, allowGroup, Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ _ruleSet.grant(2, deniedGroup, Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- /**
- * Tests support for nested External groups (i.e. those groups coming from an external source such as an LDAP).
- */
- public void testExternalGroupsSupported()
- {
- _ruleSet.grant(1, "extgroup1", Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- _ruleSet.grant(2, "extgroup2", Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
assertEquals(2, _ruleSet.getRuleCount());
- assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject("usera", "extgroup1"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
- assertEquals(Result.DENIED, _ruleSet.check(TestPrincipalUtils.createTestSubject("userb", "extgroup2"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
+ assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject("usera", allowGroup),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
+ assertEquals(Result.DENIED, _ruleSet.check(TestPrincipalUtils.createTestSubject("userb", deniedGroup),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
+ assertEquals(Result.DEFER, _ruleSet.check(TestPrincipalUtils.createTestSubject("user", "group not mentioned in acl"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
}
/**
* Rule order in the ACL determines the outcome of the check. This test ensures that a user who is
- * granted explicit permission on an object, is granted that access even although late a group
+ * granted explicit permission on an object, is granted that access even though a group
* to which the user belongs is later denied the permission.
*/
public void testAllowDeterminedByRuleOrder()
{
- assertTrue(_ruleSet.addGroup("aclgroup", Arrays.asList(new String[] {"usera"})));
+ String group = "group";
+ String user = "user";
- _ruleSet.grant(1, "usera", Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- _ruleSet.grant(2, "aclgroup", Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ _ruleSet.grant(1, user, Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ _ruleSet.grant(2, group, Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
assertEquals(2, _ruleSet.getRuleCount());
- assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject("usera"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
+ assertEquals(Result.ALLOWED, _ruleSet.check(TestPrincipalUtils.createTestSubject(user, group),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
}
/**
@@ -381,13 +349,33 @@ public class RuleSetTest extends QpidTestCase
*/
public void testDenyDeterminedByRuleOrder()
{
- assertTrue(_ruleSet.addGroup("aclgroup", Arrays.asList(new String[] {"usera"})));
+ String group = "aclgroup";
+ String user = "usera";
- _ruleSet.grant(1, "aclgroup", Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
- _ruleSet.grant(2, "usera", Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ _ruleSet.grant(1, group, Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ _ruleSet.grant(2, user, Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
assertEquals(2, _ruleSet.getRuleCount());
- assertEquals(Result.DENIED, _ruleSet.check(TestPrincipalUtils.createTestSubject("usera"),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
+ assertEquals(Result.DENIED, _ruleSet.check(TestPrincipalUtils.createTestSubject(user, group),Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
+ }
+
+ public void testUserInMultipleGroups()
+ {
+ String allowedGroup = "group1";
+ String deniedGroup = "group2";
+
+ _ruleSet.grant(1, allowedGroup, Permission.ALLOW, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+ _ruleSet.grant(2, deniedGroup, Permission.DENY, Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY);
+
+ Subject subjectInBothGroups = TestPrincipalUtils.createTestSubject("user", allowedGroup, deniedGroup);
+ Subject subjectInDeniedGroupAndOneOther = TestPrincipalUtils.createTestSubject("user", deniedGroup, "some other group");
+ Subject subjectInAllowedGroupAndOneOther = TestPrincipalUtils.createTestSubject("user", allowedGroup, "some other group");
+
+ assertEquals(Result.ALLOWED, _ruleSet.check(subjectInBothGroups,Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
+
+ assertEquals(Result.DENIED, _ruleSet.check(subjectInDeniedGroupAndOneOther,Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
+
+ assertEquals(Result.ALLOWED, _ruleSet.check(subjectInAllowedGroupAndOneOther,Operation.ACCESS, ObjectType.VIRTUALHOST, ObjectProperties.EMPTY));
}
}
diff --git a/java/broker-plugins/firewall/MANIFEST.MF b/java/broker-plugins/firewall/MANIFEST.MF
deleted file mode 100644
index a302921d03..0000000000
--- a/java/broker-plugins/firewall/MANIFEST.MF
+++ /dev/null
@@ -1,34 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Qpid Broker-Plugins Firewall
-Bundle-SymbolicName: broker-plugins-firewall
-Bundle-Description: Firewall plugin for Qpid.
-Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
-Bundle-DocURL: http://www.apache.org/
-Bundle-Version: 1.0.0
-Bundle-Activator: org.apache.qpid.server.security.access.plugins.FirewallActivator
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ClassPath: .
-Bundle-ActivationPolicy: lazy
-Import-Package: org.apache.qpid,
- org.apache.qpid.framing,
- org.apache.qpid.protocol,
- org.apache.qpid.server.configuration,
- org.apache.qpid.server.configuration.plugins,
- org.apache.qpid.server.exchange,
- org.apache.qpid.server.plugins,
- org.apache.qpid.server.queue,
- org.apache.qpid.server.security,
- org.apache.qpid.server.security.access,
- org.apache.qpid.server.virtualhost,
- org.apache.qpid.util,
- org.apache.commons.configuration;version=1.0.0,
- org.apache.commons.lang;version=1.0.0,
- org.apache.commons.lang.builder;version=1.0.0,
- org.apache.log4j;version=1.0.0,
- javax.management;version=1.0.0,
- javax.management.openmbean;version=1.0.0,
- org.osgi.util.tracker;version=1.0.0,
- org.osgi.framework;version=1.3
-Private-Package: org.apache.qpid.server.security.access.config
-Export-Package: org.apache.qpid.server.security.access.plugins;uses:="org.osgi.framework"
diff --git a/java/broker-plugins/firewall/build.xml b/java/broker-plugins/firewall/build.xml
deleted file mode 100644
index 6ae6a35b89..0000000000
--- a/java/broker-plugins/firewall/build.xml
+++ /dev/null
@@ -1,34 +0,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="Qpid Broker-Plugins Firewall" default="build">
- <property name="module.depends" value="common broker" />
- <property name="module.test.depends" value="test broker/test common/test management/common" />
-
- <property name="module.manifest" value="MANIFEST.MF" />
- <property name="module.plugin" value="true" />
- <property name="module.genpom" value="true"/>
- <property name="module.genpom.args" value="-Sqpid-common=provided -Sqpid-broker=provided"/>
-
- <property name="broker-plugins-firewall.libs" value=""/>
-
- <import file="../../module.xml" />
-
- <target name="bundle" depends="bundle-tasks" />
-
-</project>
diff --git a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/config/FirewallException.java b/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/config/FirewallException.java
deleted file mode 100644
index a9e3fdc242..0000000000
--- a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/config/FirewallException.java
+++ /dev/null
@@ -1,46 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.config;
-
-/**
- * Firewall plugin exception.
- */
-public class FirewallException extends Exception
-{
- /** serialVersionUID */
- private static final long serialVersionUID = 4526157149690917805L;
-
- public FirewallException() {
- super();
- }
-
- public FirewallException(String message) {
- super(message);
- }
-
- public FirewallException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public FirewallException(Throwable cause) {
- super(cause);
- }
-} \ No newline at end of file
diff --git a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/config/FirewallRule.java b/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/config/FirewallRule.java
deleted file mode 100644
index ecec4b0cec..0000000000
--- a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/config/FirewallRule.java
+++ /dev/null
@@ -1,136 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.config;
-
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.util.NetMatcher;
-
-import java.net.InetAddress;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.TimeUnit;
-import java.util.regex.Pattern;
-
-public class FirewallRule
-{
- public static final String ALLOW = "ALLOW";
- public static final String DENY = "DENY";
-
- private static final long DNS_TIMEOUT = 30000;
- private static final ExecutorService DNS_LOOKUP = Executors.newCachedThreadPool();
-
- private Result _access;
- private NetMatcher _network;
- private Pattern[] _hostnamePatterns;
-
- public FirewallRule(String access, List networks, List hostnames)
- {
- _access = (access.equalsIgnoreCase(ALLOW)) ? Result.ALLOWED : Result.DENIED;
-
- if (networks != null && networks.size() > 0)
- {
- String[] networkStrings = objListToStringArray(networks);
- _network = new NetMatcher(networkStrings);
- }
-
- if (hostnames != null && hostnames.size() > 0)
- {
- int i = 0;
- _hostnamePatterns = new Pattern[hostnames.size()];
- for (String hostname : objListToStringArray(hostnames))
- {
- _hostnamePatterns[i++] = Pattern.compile(hostname);
- }
- }
- }
-
- private String[] objListToStringArray(List objList)
- {
- String[] networkStrings = new String[objList.size()];
- int i = 0;
- for (Object network : objList)
- {
- networkStrings[i++] = (String) network;
- }
- return networkStrings;
- }
-
- public boolean match(InetAddress remote) throws FirewallException
- {
- if (_hostnamePatterns != null)
- {
- String hostname = getHostname(remote);
- if (hostname == null)
- {
- throw new FirewallException("DNS lookup failed");
- }
- for (Pattern pattern : _hostnamePatterns)
- {
- if (pattern.matcher(hostname).matches())
- {
- return true;
- }
- }
- return false;
- }
- else
- {
- return _network.matchInetNetwork(remote);
- }
- }
-
- /**
- * @param remote the InetAddress to look up
- * @return the hostname, null if not found, takes longer than 30s to find or otherwise fails
- */
- private String getHostname(final InetAddress remote) throws FirewallException
- {
- FutureTask<String> lookup = new FutureTask<String>(new Callable<String>()
- {
- public String call()
- {
- return remote.getCanonicalHostName();
- }
- });
- DNS_LOOKUP.execute(lookup);
-
- try
- {
- return lookup.get(DNS_TIMEOUT, TimeUnit.MILLISECONDS);
- }
- catch (Exception e)
- {
- return null;
- }
- finally
- {
- lookup.cancel(true);
- }
- }
-
- public Result getAccess()
- {
- return _access;
- }
-} \ No newline at end of file
diff --git a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/Firewall.java b/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/Firewall.java
deleted file mode 100644
index 40a65fddba..0000000000
--- a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/Firewall.java
+++ /dev/null
@@ -1,137 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.security.AbstractPlugin;
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.server.security.SecurityPluginFactory;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-import org.apache.qpid.server.security.access.config.FirewallException;
-import org.apache.qpid.server.security.access.config.FirewallRule;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-
-public class Firewall extends AbstractPlugin
-{
- public static final SecurityPluginFactory<Firewall> FACTORY = new SecurityPluginFactory<Firewall>()
- {
- public Firewall newInstance(ConfigurationPlugin config) throws ConfigurationException
- {
- FirewallConfiguration configuration = config.getConfiguration(FirewallConfiguration.class.getName());
-
- // If there is no configuration for this plugin then don't load it.
- if (configuration == null)
- {
- return null;
- }
-
- Firewall plugin = new Firewall();
- plugin.configure(configuration);
- return plugin;
- }
-
- public Class<Firewall> getPluginClass()
- {
- return Firewall.class;
- }
-
- public String getPluginName()
- {
- return Firewall.class.getName();
- }
- };
-
- private Result _default = Result.ABSTAIN;
- private FirewallRule[] _rules;
-
- public Result getDefault()
- {
- return _default;
- }
-
- public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties)
- {
- return Result.ABSTAIN; // We only deal with access requests
- }
-
- public Result access(ObjectType objectType, Object instance)
- {
- if (objectType != ObjectType.VIRTUALHOST)
- {
- return Result.ABSTAIN; // We are only interested in access to virtualhosts
- }
-
- if (!(instance instanceof InetSocketAddress))
- {
- return Result.ABSTAIN; // We need an internet address
- }
-
- InetAddress address = ((InetSocketAddress) instance).getAddress();
-
- try
- {
- for (FirewallRule rule : _rules)
- {
- boolean match = rule.match(address);
- if (match)
- {
- return rule.getAccess();
- }
- }
- return getDefault();
- }
- catch (FirewallException fe)
- {
- return Result.DENIED;
- }
- }
-
-
- public void configure(ConfigurationPlugin config)
- {
- super.configure(config);
- FirewallConfiguration firewallConfiguration = (FirewallConfiguration) getConfig();
-
- // Get default action
- _default = firewallConfiguration.getDefaultAction();
-
- Configuration finalConfig = firewallConfiguration.getConfiguration();
-
- // all rules must have an access attribute
- int numRules = finalConfig.getList("rule[@access]").size();
- _rules = new FirewallRule[numRules];
- for (int i = 0; i < numRules; i++)
- {
- FirewallRule rule = new FirewallRule(finalConfig.getString("rule(" + i + ")[@access]"),
- finalConfig.getList("rule(" + i + ")[@network]"),
- finalConfig.getList("rule(" + i + ")[@hostname]"));
- _rules[i] = rule;
- }
-
- }
-}
diff --git a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/FirewallActivator.java b/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/FirewallActivator.java
deleted file mode 100644
index 1669352085..0000000000
--- a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/FirewallActivator.java
+++ /dev/null
@@ -1,41 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.security.SecurityPluginActivator;
-import org.apache.qpid.server.security.SecurityPluginFactory;
-
-/**
- * The OSGi {@link org.osgi.framework.BundleActivator} for {@link Firewall}.
- */
-public class FirewallActivator extends SecurityPluginActivator
-{
- public SecurityPluginFactory getFactory()
- {
- return Firewall.FACTORY;
- }
-
- public ConfigurationPluginFactory getConfigurationFactory()
- {
- return FirewallConfiguration.FACTORY;
- }
-}
diff --git a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/FirewallConfiguration.java b/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/FirewallConfiguration.java
deleted file mode 100644
index 010d1652f0..0000000000
--- a/java/broker-plugins/firewall/src/main/java/org/apache/qpid/server/security/access/plugins/FirewallConfiguration.java
+++ /dev/null
@@ -1,103 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.server.security.access.config.FirewallRule;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class FirewallConfiguration extends ConfigurationPlugin
-{
- private CompositeConfiguration _finalConfig;
-
- public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory()
- {
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- ConfigurationPlugin instance = new FirewallConfiguration();
- instance.setConfiguration(path, config);
- return instance;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList("security.firewall", "virtualhosts.virtualhost.security.firewall");
- }
- };
-
- public String[] getElementsProcessed()
- {
- return new String[] { "" };
- }
-
- public Configuration getConfiguration()
- {
- return _finalConfig;
- }
-
- public Result getDefaultAction()
- {
- String defaultAction = getConfig().getString("[@default-action]");
- if (defaultAction == null)
- {
- return Result.ABSTAIN;
- }
- else if (defaultAction.equalsIgnoreCase(FirewallRule.ALLOW))
- {
- return Result.ALLOWED;
- }
- else
- {
- return Result.DENIED;
- }
- }
-
-
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- // Valid Configuration either has xml links to new files
- _finalConfig = new CompositeConfiguration(getConfig());
- List subFiles = getConfig().getList("xml[@fileName]");
- for (Object subFile : subFiles)
- {
- _finalConfig.addConfiguration(new XMLConfiguration((String) subFile));
- }
-
- // all rules must have an access attribute or a default value
- if (_finalConfig.getList("rule[@access]").size() == 0 &&
- getConfig().getString("[@default-action]") == null)
- {
- throw new ConfigurationException("No rules or default-action found in firewall configuration.");
- }
- }
-
-}
diff --git a/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java b/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java
deleted file mode 100644
index 8969363979..0000000000
--- a/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallConfigurationTest.java
+++ /dev/null
@@ -1,322 +0,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.
- *
- */
-package org.apache.qpid.server.security.access;
-
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.net.InetSocketAddress;
-
-public class FirewallConfigurationTest extends QpidTestCase
-{
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- ApplicationRegistry.remove();
- }
-
- public void testFirewallConfiguration() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), null);
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, false);
-
- // Load config
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
-
- // Test config
- assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535)));
- assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.1.2.3", 65535)));
- }
-
- public void testCombinedConfigurationFirewall() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), null);
- File fileA = File.createTempFile(getClass().getName(), null);
- File fileB = File.createTempFile(getClass().getName(), null);
-
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
-
- FileWriter out = new FileWriter(mainFile);
- out.write("<configuration><system/>");
- out.write("<xml fileName=\"" + fileA.getAbsolutePath() + "\"/>");
- out.write("</configuration>");
- out.close();
-
- out = new FileWriter(fileA);
- out.write("<broker>\n");
- out.write("\t<plugin-directory>${QPID_HOME}/lib/plugins</plugin-directory>\n");
- out.write("\t<cache-directory>${QPID_WORK}/cache</cache-directory>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<xml fileName=\"" + fileB.getAbsolutePath() + "\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- out.write("\t<virtualhosts>\n");
- out.write("\t\t<virtualhost>\n");
- out.write("\t\t\t<name>test</name>\n");
- out.write("\t\t</virtualhost>\n");
- out.write("\t</virtualhosts>\n");
- out.write("</broker>\n");
- out.close();
-
- out = new FileWriter(fileB);
- out.write("<firewall>\n");
- out.write("\t<rule access=\"deny\" network=\"127.0.0.1\"/>");
- out.write("</firewall>\n");
- out.close();
-
- // Load config
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
-
- // Test config
- assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535)));
- }
-
- public void testConfigurationFirewallReload() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), null);
-
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, false);
-
- // Load config
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
-
- // Test config
- assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535)));
-
- // Switch to deny the connection
- writeConfigFile(mainFile, true);
-
- reg.getConfiguration().reparseConfigFileSecuritySections();
-
- assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535)));
- }
-
- public void testCombinedConfigurationFirewallReload() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), null);
- File fileA = File.createTempFile(getClass().getName(), null);
- File fileB = File.createTempFile(getClass().getName(), null);
-
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
-
- FileWriter out = new FileWriter(mainFile);
- out.write("<configuration><system/>");
- out.write("<xml fileName=\"" + fileA.getAbsolutePath() + "\"/>");
- out.write("</configuration>");
- out.close();
-
- out = new FileWriter(fileA);
- out.write("<broker>\n");
- out.write("\t<plugin-directory>${QPID_HOME}/lib/plugins</plugin-directory>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<xml fileName=\"" + fileB.getAbsolutePath() + "\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- out.write("\t<virtualhosts>\n");
- out.write("\t\t<virtualhost>\n");
- out.write("\t\t\t<name>test</name>\n");
- out.write("\t\t</virtualhost>\n");
- out.write("\t</virtualhosts>\n");
- out.write("</broker>\n");
- out.close();
-
- out = new FileWriter(fileB);
- out.write("<firewall>\n");
- out.write("\t<rule access=\"deny\" network=\"127.0.0.1\"/>");
- out.write("</firewall>\n");
- out.close();
-
- // Load config
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
-
- // Test config
- assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535)));
-
- RandomAccessFile fileBRandom = new RandomAccessFile(fileB, "rw");
- fileBRandom.setLength(0);
- fileBRandom.seek(0);
- fileBRandom.close();
-
- out = new FileWriter(fileB);
- out.write("<firewall>\n");
- out.write("\t<rule access=\"allow\" network=\"127.0.0.1\"/>");
- out.write("</firewall>\n");
- out.close();
-
- reg.getConfiguration().reparseConfigFileSecuritySections();
-
- assertTrue(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535)));
-
- fileBRandom = new RandomAccessFile(fileB, "rw");
- fileBRandom.setLength(0);
- fileBRandom.seek(0);
- fileBRandom.close();
-
- out = new FileWriter(fileB);
- out.write("<firewall>\n");
- out.write("\t<rule access=\"deny\" network=\"127.0.0.1\"/>");
- out.write("</firewall>\n");
- out.close();
-
- reg.getConfiguration().reparseConfigFileSecuritySections();
-
- assertFalse(reg.getSecurityManager().accessVirtualhost("test", new InetSocketAddress("127.0.0.1", 65535)));
- }
-
- private void writeFirewallVhostsFile(File vhostsFile, boolean allow) throws IOException
- {
- FileWriter out = new FileWriter(vhostsFile);
- String ipAddr = "127.0.0.1"; // FIXME: get this from InetAddress.getLocalHost().getAddress() ?
- out.write("<virtualhosts><virtualhost>");
- out.write("<name>test</name>");
- out.write("<test>");
- out.write("<security><firewall>");
- out.write("<rule access=\""+((allow) ? "allow" : "deny")+"\" network=\""+ipAddr +"\"/>");
- out.write("</firewall></security>");
- out.write("</test>");
- out.write("</virtualhost></virtualhosts>");
- out.close();
- }
-
- private void writeConfigFile(File mainFile, boolean allow) throws IOException {
- writeConfigFile(mainFile, allow, true, null, "test");
- }
-
- /*
- XMLConfiguration config = new XMLConfiguration(mainFile);
- PluginManager pluginManager = new MockPluginManager("");
- SecurityManager manager = new SecurityManager(config, pluginManager, Firewall.FACTORY);
-
- */
- private void writeConfigFile(File mainFile, boolean allow, boolean includeVhosts, File vhostsFile, String name) throws IOException {
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<plugin-directory>${QPID_HOME}/lib/plugins</plugin-directory>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<rule access=\""+ ((allow) ? "allow" : "deny") +"\" network=\"127.0.0.1\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- if (includeVhosts)
- {
- out.write("\t<virtualhosts>\n");
- out.write("\t\t<default>test</default>\n");
- out.write("\t\t<virtualhost>\n");
- out.write(String.format("\t\t\t<name>%s</name>\n", name));
- out.write("\t\t</virtualhost>\n");
- out.write("\t</virtualhosts>\n");
- }
- if (vhostsFile != null)
- {
- out.write("\t<virtualhosts>"+vhostsFile.getAbsolutePath()+"</virtualhosts>\n");
- }
- out.write("</broker>\n");
- out.close();
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in an external
- * configuration file only.
- * <p>
- * Test for QPID-2360
- */
- public void testExternalFirewallVirtualhostXMLFile() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- vhostsFile.deleteOnExit();
- writeConfigFile(mainFile, false, false, vhostsFile, null);
- writeFirewallVhostsFile(vhostsFile, false);
-
- // Load config
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
-
- // Test config
- VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry();
- VirtualHost virtualHost = virtualHostRegistry.getVirtualHost("test");
-
- assertEquals("Incorrect virtualhost count", 1, virtualHostRegistry.getVirtualHosts().size());
- assertEquals("Incorrect virtualhost name", "test", virtualHost.getName());
- }
-}
diff --git a/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java b/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java
deleted file mode 100644
index 2004852c48..0000000000
--- a/java/broker-plugins/firewall/src/test/java/org/apache/qpid/server/security/access/FirewallPluginTest.java
+++ /dev/null
@@ -1,294 +0,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.
- */
-package org.apache.qpid.server.security.access;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.server.security.access.plugins.Firewall;
-import org.apache.qpid.server.security.access.plugins.FirewallConfiguration;
-import org.apache.qpid.server.util.TestApplicationRegistry;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-
-public class FirewallPluginTest extends QpidTestCase
-{
- public class RuleInfo
- {
- private String _access;
- private String _network;
- private String _hostname;
-
- public void setAccess(String _access)
- {
- this._access = _access;
- }
-
- public String getAccess()
- {
- return _access;
- }
-
- public void setNetwork(String _network)
- {
- this._network = _network;
- }
-
- public String getNetwork()
- {
- return _network;
- }
-
- public void setHostname(String _hostname)
- {
- this._hostname = _hostname;
- }
-
- public String getHostname()
- {
- return _hostname;
- }
- }
-
- // IP address
- private SocketAddress _address;
- private ServerConfiguration _serverConfig;
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- _serverConfig = new ServerConfiguration(new XMLConfiguration());
- ApplicationRegistry.initialise(new TestApplicationRegistry(_serverConfig));
- _address = new InetSocketAddress("127.0.0.1", 65535);
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- ApplicationRegistry.remove();
- }
- private Firewall initialisePlugin(String defaultAction, RuleInfo[] rules) throws IOException, ConfigurationException
- {
- // Create sample config file
- File confFile = File.createTempFile(getClass().getSimpleName()+"conffile", null);
- confFile.deleteOnExit();
- BufferedWriter buf = new BufferedWriter(new FileWriter(confFile));
- buf.write("<firewall default-action=\""+defaultAction+"\">\n");
- if (rules != null)
- {
- for (RuleInfo rule : rules)
- {
- buf.write("<rule");
- buf.write(" access=\""+rule.getAccess()+"\"");
- if (rule.getHostname() != null)
- {
- buf.write(" hostname=\""+rule.getHostname()+"\"");
- }
- if (rule.getNetwork() != null)
- {
- buf.write(" network=\""+rule.getNetwork()+"\"");
- }
- buf.write("/>\n");
- }
- }
- buf.write("</firewall>");
- buf.close();
-
- // Configure plugin
- FirewallConfiguration config = new FirewallConfiguration();
- config.setConfiguration("", new XMLConfiguration(confFile));
- Firewall plugin = new Firewall();
- plugin.configure(config);
- return plugin;
- }
-
- private Firewall initialisePlugin(String string) throws ConfigurationException, IOException
- {
- return initialisePlugin(string, null);
- }
-
- public void testDefaultAction() throws Exception
- {
- // Test simple deny
- Firewall plugin = initialisePlugin("deny");
- assertEquals(Result.DENIED, plugin.access(ObjectType.VIRTUALHOST, _address));
-
- // Test simple allow
- plugin = initialisePlugin("allow");
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
-
- public void testSingleIPRule() throws Exception
- {
- RuleInfo rule = new RuleInfo();
- rule.setAccess("allow");
- rule.setNetwork("192.168.23.23");
-
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{rule});
-
- assertEquals(Result.DENIED, plugin.access(ObjectType.VIRTUALHOST, _address));
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("192.168.23.23", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
- public void testSingleNetworkRule() throws Exception
- {
- RuleInfo rule = new RuleInfo();
- rule.setAccess("allow");
- rule.setNetwork("192.168.23.0/24");
-
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{rule});
-
- assertEquals(Result.DENIED, plugin.access(ObjectType.VIRTUALHOST, _address));
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("192.168.23.23", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
- public void testSingleHostRule() throws Exception
- {
- RuleInfo rule = new RuleInfo();
- rule.setAccess("allow");
- rule.setHostname(new InetSocketAddress("127.0.0.1", 5672).getHostName());
-
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{rule});
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("127.0.0.1", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
- public void testSingleHostWilcardRule() throws Exception
- {
- RuleInfo rule = new RuleInfo();
- rule.setAccess("allow");
- String hostname = new InetSocketAddress("127.0.0.1", 0).getHostName();
- rule.setHostname(".*"+hostname.subSequence(hostname.length() - 1, hostname.length())+"*");
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{rule});
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("127.0.0.1", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
- public void testSeveralFirstAllowsAccess() throws Exception
- {
- RuleInfo firstRule = new RuleInfo();
- firstRule.setAccess("allow");
- firstRule.setNetwork("192.168.23.23");
-
- RuleInfo secondRule = new RuleInfo();
- secondRule.setAccess("deny");
- secondRule.setNetwork("192.168.42.42");
-
- RuleInfo thirdRule = new RuleInfo();
- thirdRule.setAccess("deny");
- thirdRule.setHostname("localhost");
-
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{firstRule, secondRule, thirdRule});
-
- assertEquals(Result.DENIED, plugin.access(ObjectType.VIRTUALHOST, _address));
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("192.168.23.23", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
- public void testSeveralLastAllowsAccess() throws Exception
- {
- RuleInfo firstRule = new RuleInfo();
- firstRule.setAccess("deny");
- firstRule.setHostname("localhost");
-
- RuleInfo secondRule = new RuleInfo();
- secondRule.setAccess("deny");
- secondRule.setNetwork("192.168.42.42");
-
- RuleInfo thirdRule = new RuleInfo();
- thirdRule.setAccess("allow");
- thirdRule.setNetwork("192.168.23.23");
-
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{firstRule, secondRule, thirdRule});
-
- assertEquals(Result.DENIED, plugin.access(ObjectType.VIRTUALHOST, _address));
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("192.168.23.23", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
- public void testNetmask() throws Exception
- {
- RuleInfo firstRule = new RuleInfo();
- firstRule.setAccess("allow");
- firstRule.setNetwork("192.168.23.0/24");
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{firstRule});
-
- assertEquals(Result.DENIED, plugin.access(ObjectType.VIRTUALHOST, _address));
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("192.168.23.23", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
- public void testCommaSeperatedNetmask() throws Exception
- {
- RuleInfo firstRule = new RuleInfo();
- firstRule.setAccess("allow");
- firstRule.setNetwork("10.1.1.1/8, 192.168.23.0/24");
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{firstRule});
-
- assertEquals(Result.DENIED, plugin.access(ObjectType.VIRTUALHOST, _address));
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("192.168.23.23", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-
- public void testCommaSeperatedHostnames() throws Exception
- {
- RuleInfo firstRule = new RuleInfo();
- firstRule.setAccess("allow");
- firstRule.setHostname("foo, bar, "+new InetSocketAddress("127.0.0.1", 5672).getHostName());
- Firewall plugin = initialisePlugin("deny", new RuleInfo[]{firstRule});
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("10.0.0.1", 65535);
- assertEquals(Result.DENIED, plugin.access(ObjectType.VIRTUALHOST, _address));
-
- // Set IP so that we're connected from the right address
- _address = new InetSocketAddress("127.0.0.1", 65535);
- assertEquals(Result.ALLOWED, plugin.access(ObjectType.VIRTUALHOST, _address));
- }
-}
diff --git a/java/broker-plugins/management-http/MANIFEST.MF b/java/broker-plugins/management-http/MANIFEST.MF
deleted file mode 100644
index cca10d3f89..0000000000
--- a/java/broker-plugins/management-http/MANIFEST.MF
+++ /dev/null
@@ -1,70 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Qpid Broker-Plugins Management HTTP
-Bundle-SymbolicName: broker-plugins-management-http
-Bundle-Description: HTTP management plugin for Qpid.
-Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
-Bundle-DocURL: http://www.apache.org/
-Bundle-Version: 1.0.0
-Bundle-Activator: org.apache.qpid.server.management.plugin.ManagementActivator
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ClassPath: .
-Bundle-ActivationPolicy: lazy
-Import-Package: org.apache.qpid,
- org.apache.qpid.framing,
- org.apache.qpid.protocol,
- org.apache.qpid.common,
- org.apache.qpid.server.security.auth,
- org.apache.qpid.server.security.auth.manager,
- org.apache.qpid.server.security.auth.sasl,
- org.apache.qpid.server.binding,
- org.apache.qpid.server.exchange,
- org.apache.qpid.server.logging,
- org.apache.qpid.server.message,
- org.apache.qpid.server.model,
- org.apache.qpid.server.model.adapter,
- org.apache.qpid.server.model.impl,
- org.apache.qpid.server.configuration,
- org.apache.qpid.server.configuration.plugins,
- org.apache.qpid.server.connection,
- org.apache.qpid.server.plugins,
- org.apache.qpid.server.protocol,
- org.apache.qpid.server.queue,
- org.apache.qpid.server.subscription,
- org.apache.qpid.server.registry,
- org.apache.qpid.server.security,
- org.apache.qpid.server.security.access,
- org.apache.qpid.server.stats,
- org.apache.qpid.server.virtualhost,
- org.apache.qpid.util,
- org.eclipse.jetty.server;version=7.6.3,
- org.eclipse.jetty.server.session;version=7.6.3,
- org.eclipse.jetty.server.ssl;version=7.6.3,
- org.eclipse.jetty.server.nio;version=7.6.3,
- org.eclipse.jetty.security;version=7.6.3,
- org.eclipse.jetty.http;version=7.6.3,
- org.eclipse.jetty.io;version=7.6.3,
- org.eclipse.jetty.io.nio;version=7.6.3,
- org.eclipse.jetty.servlet;version=7.6.3,
- org.eclipse.jetty.util.ssl;version=7.6.3,
- org.apache.commons.codec;version=1.3.0,
- org.apache.commons.codec.binary;version=1.3.0,
- org.apache.commons.configuration;version=1.0.0,
- org.apache.commons.lang;version=1.0.0,
- org.apache.commons.lang.builder;version=1.0.0,
- org.apache.log4j;version=1.0.0,
- org.codehaus.jackson;version=1.9.0,
- org.codehaus.jackson.map;version=1.9.0,
- javax.crypto,
- javax.crypto.spec,
- javax.security.auth,
- javax.security.auth.callback,
- javax.security.sasl,
- javax.servlet,
- javax.servlet.http,
- javax.management;version=1.0.0,
- javax.management.openmbean;version=1.0.0,
- org.osgi.util.tracker;version=1.0.0,
- org.osgi.framework;version=1.3
-Private-Package: org.apache.qpid.server.management.plugin.impl
-Export-Package: org.apache.qpid.server.management.plugin;uses:="org.osgi.framework"
diff --git a/java/broker-plugins/management-http/build.xml b/java/broker-plugins/management-http/build.xml
index b792cb292e..abf35d9c88 100644
--- a/java/broker-plugins/management-http/build.xml
+++ b/java/broker-plugins/management-http/build.xml
@@ -18,39 +18,36 @@
-->
<project name="Qpid Broker-Plugins Management HTTP" default="build">
- <condition property="systests.optional.depends" value="bdbstore" else="">
- <or>
- <and>
- <contains string="${modules.opt}" substring="bdbstore"/>
- <contains string="${profile}" substring="bdb"/>
- </and>
- <and>
- <istrue value="${optional}"/>
- <contains string="${profile}" substring="bdb"/>
- </and>
- </or>
- </condition>
-
<property name="module.depends" value="common broker" />
- <property name="module.test.depends" value="systests test broker/test common/test management/common client ${systests.optional.depends}" />
+ <property name="module.test.depends" value="broker/tests common/tests management/common client" />
+
+ <property name="module.genpom" value="true" />
+ <property name="module.genpom.args" value="-Sqpid-common=provided -Sqpid-broker=provided" />
- <property name="module.manifest" value="MANIFEST.MF" />
- <property name="module.plugin" value="true" />
- <property name="module.genpom" value="true"/>
- <property name="module.genpom.args" value="-Sqpid-common=provided -Sqpid-broker=provided"/>
+ <property name="broker.plugin" value="true"/>
- <property name="broker-plugins-management-http.libs" value=""/>
+ <property name="broker-plugins-management-http.libs" value="" />
<import file="../../module.xml" />
- <target name="precompile">
- <unwar src="${project.root}/${dojo}" dest="${module.classes}/resources/dojo">
- <patternset>
- <exclude name="META-INF/**"/>
- <exclude name="WEB-INF/**"/>
- <exclude name="**/*.uncompressed.js"/>
- </patternset>
- </unwar>
+ <!-- Flagfile used to determine if uwar needs to be done. ._ is part of Ant's defaultexcludes so wont appear bundles -->
+ <property name="dojo.uptodate.flagfile" value="${module.classes}/resources/dojo/._dojouptodate.timestamp" />
+
+ <target name="precompile" depends="unwardojo" />
+
+ <target name="unwardojo" depends="check-unwardojo.done" unless="unwardojo.done">
+ <unwar src="${project.root}/${dojo}" dest="${module.classes}/resources/dojo">
+ <patternset>
+ <exclude name="META-INF/**" />
+ <exclude name="WEB-INF/**" />
+ <exclude name="**/*.uncompressed.js" />
+ </patternset>
+ </unwar>
+ <touch file="${dojo.uptodate.flagfile}" />
+ </target>
+
+ <target name="check-unwardojo.done">
+ <uptodate property="unwardojo.done" targetfile="${dojo.uptodate.flagfile}" srcfile="${project.root}/${dojo}" />
</target>
<target name="bundle" depends="bundle-tasks" />
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
new file mode 100644
index 0000000000..c2ac675e20
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagement.java
@@ -0,0 +1,416 @@
+/*
+ *
+ * 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.management.plugin;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
+import org.apache.qpid.server.management.plugin.servlet.DefinedFileServlet;
+import org.apache.qpid.server.management.plugin.servlet.FileServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.AbstractServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.LogRecordsServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.LogoutServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.MessageContentServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.MessageServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.RestServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet;
+import org.apache.qpid.server.management.plugin.servlet.rest.StructureServlet;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Connection;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.Group;
+import org.apache.qpid.server.model.GroupMember;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Plugin;
+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.Session;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.User;
+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;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.SessionManager;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.server.ssl.SslSocketConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
+public class HttpManagement extends AbstractPluginAdapter
+{
+ private final Logger _logger = Logger.getLogger(HttpManagement.class);
+
+ // 10 minutes by default
+ public static final int DEFAULT_TIMEOUT_IN_SECONDS = 60 * 10;
+ public static final boolean DEFAULT_HTTP_BASIC_AUTHENTICATION_ENABLED = false;
+ public static final boolean DEFAULT_HTTPS_BASIC_AUTHENTICATION_ENABLED = true;
+ public static final boolean DEFAULT_HTTP_SASL_AUTHENTICATION_ENABLED = true;
+ public static final boolean DEFAULT_HTTPS_SASL_AUTHENTICATION_ENABLED = true;
+ public static final String DEFAULT_NAME = "httpManagement";
+
+ public static final String TIME_OUT = "sessionTimeout";
+ public static final String HTTP_BASIC_AUTHENTICATION_ENABLED = "httpBasicAuthenticationEnabled";
+ public static final String HTTPS_BASIC_AUTHENTICATION_ENABLED = "httpsBasicAuthenticationEnabled";
+ public static final String HTTP_SASL_AUTHENTICATION_ENABLED = "httpSaslAuthenticationEnabled";
+ public static final String HTTPS_SASL_AUTHENTICATION_ENABLED = "httpsSaslAuthenticationEnabled";
+
+ public static final String PLUGIN_TYPE = "MANAGEMENT-HTTP";
+
+ @SuppressWarnings("serial")
+ private static final Collection<String> AVAILABLE_ATTRIBUTES = Collections.unmodifiableSet(new HashSet<String>(Plugin.AVAILABLE_ATTRIBUTES)
+ {{
+ add(HTTP_BASIC_AUTHENTICATION_ENABLED);
+ add(HTTPS_BASIC_AUTHENTICATION_ENABLED);
+ add(HTTP_SASL_AUTHENTICATION_ENABLED);
+ add(HTTPS_SASL_AUTHENTICATION_ENABLED);
+ add(TIME_OUT);
+ add(PluginFactory.PLUGIN_TYPE);
+ }});
+
+ public static final String ENTRY_POINT_PATH = "/management";
+
+ private static final String OPERATIONAL_LOGGING_NAME = "Web";
+
+
+ @SuppressWarnings("serial")
+ public static final Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>()
+ {{
+ put(HTTP_BASIC_AUTHENTICATION_ENABLED, DEFAULT_HTTP_BASIC_AUTHENTICATION_ENABLED);
+ put(HTTPS_BASIC_AUTHENTICATION_ENABLED, DEFAULT_HTTPS_BASIC_AUTHENTICATION_ENABLED);
+ put(HTTP_SASL_AUTHENTICATION_ENABLED, DEFAULT_HTTP_SASL_AUTHENTICATION_ENABLED);
+ put(HTTPS_SASL_AUTHENTICATION_ENABLED, DEFAULT_HTTPS_SASL_AUTHENTICATION_ENABLED);
+ put(TIME_OUT, DEFAULT_TIMEOUT_IN_SECONDS);
+ put(NAME, DEFAULT_NAME);
+ }});
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Class<?>> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Class<?>>(){{
+ put(HTTP_BASIC_AUTHENTICATION_ENABLED, Boolean.class);
+ put(HTTPS_BASIC_AUTHENTICATION_ENABLED, Boolean.class);
+ put(HTTP_SASL_AUTHENTICATION_ENABLED, Boolean.class);
+ put(HTTPS_SASL_AUTHENTICATION_ENABLED, Boolean.class);
+ put(NAME, String.class);
+ put(TIME_OUT, Integer.class);
+ put(PluginFactory.PLUGIN_TYPE, String.class);
+ }});
+
+ private final Broker _broker;
+
+ private Server _server;
+
+ public HttpManagement(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), broker.getTaskExecutor());
+ _broker = broker;
+ addParent(Broker.class, broker);
+ }
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if(desiredState == State.ACTIVE)
+ {
+ start();
+ return true;
+ }
+ else if(desiredState == State.STOPPED)
+ {
+ stop();
+ return true;
+ }
+ return false;
+ }
+
+ private void start()
+ {
+ CurrentActor.get().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
+
+ Collection<Port> httpPorts = getHttpPorts(_broker.getPorts());
+ _server = createServer(httpPorts);
+ try
+ {
+ _server.start();
+ logOperationalListenMessages(_server);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to start http management on ports " + httpPorts);
+ }
+
+ CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
+ }
+
+ private void stop()
+ {
+ if (_server != null)
+ {
+ try
+ {
+ _server.stop();
+ logOperationalShutdownMessage(_server);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to stop http management on port " + getHttpPorts(_broker.getPorts()));
+ }
+ }
+
+ CurrentActor.get().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME));
+ }
+
+ /** Added for testing purposes */
+ Broker getBroker()
+ {
+ return _broker;
+ }
+
+ /** Added for testing purposes */
+ int getSessionTimeout()
+ {
+ return (Integer)getAttribute(TIME_OUT);
+ }
+
+ private boolean isManagementHttp(Port port)
+ {
+ return port.getProtocols().contains(Protocol.HTTP) || port.getProtocols().contains(Protocol.HTTPS);
+ }
+
+ @SuppressWarnings("unchecked")
+ private Server createServer(Collection<Port> ports)
+ {
+ if (_logger.isInfoEnabled())
+ {
+ _logger.info("Starting up web server on " + ports);
+ }
+
+ Server server = new Server();
+ for (Port port : ports)
+ {
+ if (State.QUIESCED.equals(port.getActualState()))
+ {
+ continue;
+ }
+ final Collection<Protocol> protocols = port.getProtocols();
+ Connector connector = null;
+
+ //TODO: what to do if protocol HTTP and transport SSL?
+ if (protocols.contains(Protocol.HTTP))
+ {
+ connector = new SelectChannelConnector();
+ }
+ else if (protocols.contains(Protocol.HTTPS))
+ {
+ KeyStore keyStore = _broker.getDefaultKeyStore();
+ if (keyStore == null)
+ {
+ throw new IllegalConfigurationException("Key store is not configured. Cannot start management on HTTPS port without keystore");
+ }
+ String keyStorePath = (String)keyStore.getAttribute(KeyStore.PATH);
+ String keyStorePassword = keyStore.getPassword();
+ validateKeystoreParameters(keyStorePath, keyStorePassword);
+
+ SslContextFactory factory = new SslContextFactory();
+ factory.setKeyStorePath(keyStorePath);
+ factory.setKeyStorePassword(keyStorePassword);
+
+ connector = new SslSocketConnector(factory);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unexpected protocol " + protocols);
+ }
+ connector.setPort(port.getPort());
+ server.addConnector(connector);
+ }
+
+ ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ root.setContextPath("/");
+ server.setHandler(root);
+
+ // set servlet context attributes for broker and configuration
+ root.getServletContext().setAttribute(AbstractServlet.ATTR_BROKER, _broker);
+ root.getServletContext().setAttribute(AbstractServlet.ATTR_MANAGEMENT, this);
+
+ addRestServlet(root, "broker");
+ addRestServlet(root, "virtualhost", VirtualHost.class);
+ addRestServlet(root, "authenticationprovider", AuthenticationProvider.class);
+ addRestServlet(root, "user", AuthenticationProvider.class, User.class);
+ addRestServlet(root, "groupprovider", GroupProvider.class);
+ addRestServlet(root, "group", GroupProvider.class, Group.class);
+ addRestServlet(root, "groupmember", GroupProvider.class, Group.class, GroupMember.class);
+ addRestServlet(root, "exchange", VirtualHost.class, Exchange.class);
+ addRestServlet(root, "queue", VirtualHost.class, Queue.class);
+ addRestServlet(root, "connection", VirtualHost.class, Connection.class);
+ addRestServlet(root, "binding", VirtualHost.class, Exchange.class, Queue.class, Binding.class);
+ addRestServlet(root, "port", Port.class);
+ addRestServlet(root, "session", VirtualHost.class, Connection.class, Session.class);
+
+ root.addServlet(new ServletHolder(new StructureServlet()), "/rest/structure");
+ root.addServlet(new ServletHolder(new MessageServlet()), "/rest/message/*");
+ root.addServlet(new ServletHolder(new MessageContentServlet()), "/rest/message-content/*");
+
+ root.addServlet(new ServletHolder(new LogRecordsServlet()), "/rest/logrecords");
+
+ root.addServlet(new ServletHolder(new SaslServlet()), "/rest/sasl");
+
+ root.addServlet(new ServletHolder(new DefinedFileServlet("index.html")), ENTRY_POINT_PATH);
+ root.addServlet(new ServletHolder(new LogoutServlet()), "/logout");
+
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.js");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.css");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.html");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.png");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.gif");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.jpg");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.jpeg");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.json");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.txt");
+ root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.xsl");
+
+ final SessionManager sessionManager = root.getSessionHandler().getSessionManager();
+
+ sessionManager.setMaxInactiveInterval((Integer)getAttribute(TIME_OUT));
+
+ return server;
+ }
+
+ private void addRestServlet(ServletContextHandler root, String name, Class<? extends ConfiguredObject>... hierarchy)
+ {
+ root.addServlet(new ServletHolder(new RestServlet(hierarchy)), "/rest/" + name + "/*");
+ }
+
+ private void validateKeystoreParameters(String keyStorePath, String password)
+ {
+ if (keyStorePath == null)
+ {
+ throw new RuntimeException("Management SSL keystore path not defined, unable to start SSL protected HTTP connector");
+ }
+ if (password == null)
+ {
+ throw new RuntimeException("Management SSL keystore password, unable to start SSL protected HTTP connector");
+ }
+ File ksf = new File(keyStorePath);
+ if (!ksf.exists())
+ {
+ throw new RuntimeException("Cannot find management SSL keystore file: " + ksf);
+ }
+ if (!ksf.canRead())
+ {
+ throw new RuntimeException("Cannot read management SSL keystore file: " + ksf + ". Check permissions.");
+ }
+ }
+
+ private void logOperationalListenMessages(Server server)
+ {
+ Connector[] connectors = server.getConnectors();
+ for (Connector connector : connectors)
+ {
+ CurrentActor.get().message(ManagementConsoleMessages.LISTENING(stringifyConnectorScheme(connector), connector.getPort()));
+ if (connector instanceof SslSocketConnector)
+ {
+ SslContextFactory sslContextFactory = ((SslSocketConnector)connector).getSslContextFactory();
+ if (sslContextFactory != null && sslContextFactory.getKeyStorePath() != null)
+ {
+ CurrentActor.get().message(ManagementConsoleMessages.SSL_KEYSTORE(sslContextFactory.getKeyStorePath()));
+ }
+ }
+ }
+ }
+
+ private void logOperationalShutdownMessage(Server server)
+ {
+ Connector[] connectors = server.getConnectors();
+ for (Connector connector : connectors)
+ {
+ CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN(stringifyConnectorScheme(connector), connector.getPort()));
+ }
+ }
+
+ private String stringifyConnectorScheme(Connector connector)
+ {
+ return connector instanceof SslSocketConnector ? "HTTPS" : "HTTP";
+ }
+
+ private Collection<Port> getHttpPorts(Collection<Port> ports)
+ {
+ Collection<Port> httpPorts = new HashSet<Port>();
+ for (Port port : ports)
+ {
+ if (isManagementHttp(port))
+ {
+ httpPorts.add(port);
+ }
+ }
+ return httpPorts;
+ }
+
+
+ @Override
+ public String getName()
+ {
+ return (String)getAttribute(NAME);
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return Collections.unmodifiableCollection(AVAILABLE_ATTRIBUTES);
+ }
+
+ public boolean isHttpsSaslAuthenticationEnabled()
+ {
+ return (Boolean)getAttribute(HTTPS_SASL_AUTHENTICATION_ENABLED);
+ }
+
+ public boolean isHttpSaslAuthenticationEnabled()
+ {
+ return (Boolean)getAttribute(HTTP_SASL_AUTHENTICATION_ENABLED);
+ }
+
+ public boolean isHttpsBasicAuthenticationEnabled()
+ {
+ return (Boolean)getAttribute(HTTPS_BASIC_AUTHENTICATION_ENABLED);
+ }
+
+ public boolean isHttpBasicAuthenticationEnabled()
+ {
+ return (Boolean)getAttribute(HTTP_BASIC_AUTHENTICATION_ENABLED);
+ }
+
+}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java
new file mode 100644
index 0000000000..ccf5373234
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementFactory.java
@@ -0,0 +1,41 @@
+/*
+ * 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.management.plugin;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
+
+public class HttpManagementFactory implements PluginFactory
+{
+
+ @Override
+ public Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker)
+ {
+ if (!HttpManagement.PLUGIN_TYPE.equals(attributes.get(PLUGIN_TYPE)))
+ {
+ return null;
+ }
+
+ return new HttpManagement(id, broker, attributes);
+ }
+}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/Management.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/Management.java
deleted file mode 100644
index c2f9b73b54..0000000000
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/Management.java
+++ /dev/null
@@ -1,248 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.management.plugin.servlet.DefinedFileServlet;
-import org.apache.qpid.server.management.plugin.servlet.FileServlet;
-import org.apache.qpid.server.management.plugin.servlet.api.ExchangesServlet;
-import org.apache.qpid.server.management.plugin.servlet.api.VhostsServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.LogRecordsServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.MessageContentServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.MessageServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.RestServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet;
-import org.apache.qpid.server.management.plugin.servlet.rest.StructureServlet;
-import org.apache.qpid.server.model.AuthenticationProvider;
-import org.apache.qpid.server.model.Binding;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.Connection;
-import org.apache.qpid.server.model.Exchange;
-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.Session;
-import org.apache.qpid.server.model.Transport;
-import org.apache.qpid.server.model.User;
-import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.SessionManager;
-import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.eclipse.jetty.server.ssl.SslSocketConnector;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-
-public class Management
-{
-
- private final Logger _logger = Logger.getLogger(Management.class);
-
- private Broker _broker;
-
- private Collection<Server> _servers = new ArrayList<Server>();
-
- public Management() throws ConfigurationException, IOException
- {
- _broker = ApplicationRegistry.getInstance().getBroker();
-
- Collection<Port> ports = _broker.getPorts();
- int httpPort = -1, httpsPort = -1;
- for (Port port : ports)
- {
- if (port.getProtocols().contains(Protocol.HTTP))
- {
- if (port.getTransports().contains(Transport.TCP))
- {
- httpPort = port.getPort();
- }
- }
- if (port.getProtocols().contains(Protocol.HTTPS))
- {
- if (port.getTransports().contains(Transport.SSL))
- {
- httpsPort = port.getPort();
- }
- }
- }
-
- if (httpPort != -1 || httpsPort != -1)
- {
- _servers.add(createServer(httpPort, httpsPort));
- if (_logger.isDebugEnabled())
- {
- _logger.debug(_servers.size() + " server(s) defined");
- }
- }
- else
- {
- if (_logger.isInfoEnabled())
- {
- _logger.info("Cannot create web server as neither HTTP nor HTTPS port specified");
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private Server createServer(int port, int sslPort) throws IOException, ConfigurationException
- {
- if (_logger.isInfoEnabled())
- {
- _logger.info("Starting up web server on" + (port == -1 ? "" : " HTTP port " + port)
- + (sslPort == -1 ? "" : " HTTPS port " + sslPort));
- }
-
- Server server = new Server();
-
- if (port != -1)
- {
- SelectChannelConnector connector = new SelectChannelConnector();
- connector.setPort(port);
- if (sslPort != -1)
- {
- connector.setConfidentialPort(sslPort);
- }
- server.addConnector(connector);
- }
-
- if (sslPort != -1)
- {
- IApplicationRegistry appRegistry = ApplicationRegistry.getInstance();
- String keyStorePath = getKeyStorePath(appRegistry);
-
- SslContextFactory factory = new SslContextFactory();
- factory.setKeyStorePath(keyStorePath);
- factory.setKeyStorePassword(appRegistry.getConfiguration().getManagementKeyStorePassword());
-
- SslSocketConnector connector = new SslSocketConnector(factory);
- connector.setPort(sslPort);
- server.addConnector(connector);
- }
-
- ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
- root.setContextPath("/");
- server.setHandler(root);
-
- root.addServlet(new ServletHolder(new VhostsServlet(_broker)), "/api/vhosts/*");
- root.addServlet(new ServletHolder(new ExchangesServlet(_broker)), "/api/exchanges/*");
-
- addRestServlet(root, "broker");
- addRestServlet(root, "virtualhost", VirtualHost.class);
- addRestServlet(root, "authenticationprovider", AuthenticationProvider.class);
- addRestServlet(root, "user", AuthenticationProvider.class, User.class);
- addRestServlet(root, "exchange", VirtualHost.class, Exchange.class);
- addRestServlet(root, "queue", VirtualHost.class, Queue.class);
- addRestServlet(root, "connection", VirtualHost.class, Connection.class);
- addRestServlet(root, "binding", VirtualHost.class, Exchange.class, Queue.class, Binding.class);
- addRestServlet(root, "port", Port.class);
- addRestServlet(root, "session", VirtualHost.class, Connection.class, Session.class);
-
- root.addServlet(new ServletHolder(new StructureServlet(_broker)), "/rest/structure");
- root.addServlet(new ServletHolder(new MessageServlet(_broker)), "/rest/message/*");
- root.addServlet(new ServletHolder(new MessageContentServlet(_broker)), "/rest/message-content/*");
-
- root.addServlet(new ServletHolder(new LogRecordsServlet(_broker)), "/rest/logrecords");
-
- root.addServlet(new ServletHolder(new SaslServlet(_broker)), "/rest/sasl");
-
- root.addServlet(new ServletHolder(new DefinedFileServlet("management.html")), "/management");
-
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.js");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.css");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.html");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.png");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.gif");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.jpg");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.jpeg");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.json");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.txt");
- root.addServlet(new ServletHolder(FileServlet.INSTANCE), "*.xsl");
-
- final SessionManager sessionManager = root.getSessionHandler().getSessionManager();
-
- sessionManager.setMaxInactiveInterval(60 * 15);
-
- return server;
- }
-
- private void addRestServlet(ServletContextHandler root, String name, Class<? extends ConfiguredObject>... hierarchy)
- {
- root.addServlet(new ServletHolder(new RestServlet(_broker, hierarchy)), "/rest/" + name + "/*");
- }
-
- public void start() throws Exception
- {
- for (Server server : _servers)
- {
- server.start();
- }
- }
-
- public void stop() throws Exception
- {
- for (Server server : _servers)
- {
- server.stop();
- }
- }
-
- private String getKeyStorePath(IApplicationRegistry appRegistry) throws ConfigurationException, FileNotFoundException
- {
- String keyStorePath = null;
- if (System.getProperty("javax.net.ssl.keyStore") != null)
- {
- keyStorePath = System.getProperty("javax.net.ssl.keyStore");
- }
- else
- {
- keyStorePath = appRegistry.getConfiguration().getManagementKeyStorePath();
- }
-
- if (keyStorePath == null)
- {
- throw new ConfigurationException("Management SSL keystore path not defined, unable to start SSL protected HTTP connector");
- }
- else
- {
- File ksf = new File(keyStorePath);
- if (!ksf.exists())
- {
- throw new FileNotFoundException("Cannot find management SSL keystore file: " + ksf);
- }
- if (!ksf.canRead())
- {
- throw new FileNotFoundException("Cannot read management SSL keystore file: " + ksf + ". Check permissions.");
- }
- }
- return keyStorePath;
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ManagementActivator.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ManagementActivator.java
deleted file mode 100644
index 09b7e08bfb..0000000000
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ManagementActivator.java
+++ /dev/null
@@ -1,73 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-public class ManagementActivator implements BundleActivator
-{
- private static final Logger _logger = Logger.getLogger(ManagementActivator.class);
-
-
- private BundleContext _ctx;
- private String _bundleName;
- private Management _managementService;
-
-
- public void start(final BundleContext ctx) throws Exception
- {
- _ctx = ctx;
- if (!ApplicationRegistry.getInstance().getConfiguration().getHTTPManagementEnabled()
- && !ApplicationRegistry.getInstance().getConfiguration().getHTTPSManagementEnabled())
- {
- _logger.info("Management plugin is disabled!");
- ctx.getBundle().uninstall();
- return;
- }
- _managementService = new Management();
- _managementService.start();
- _bundleName = ctx.getBundle().getSymbolicName();
-
- // register the service
- _logger.info("Registering management plugin: " + _bundleName);
- _ctx.registerService(Management.class.getName(), _managementService, null);
- _ctx.registerService(ConfigurationPluginFactory.class.getName(), ManagementConfiguration.FACTORY, null);
- }
-
- public void stop(final BundleContext bundleContext) throws Exception
- {
- if (_managementService != null)
- {
- _logger.info("Stopping management plugin: " + _bundleName);
-
- _managementService.stop();
-
- // null object references
- _managementService = null;
- }
- _ctx = null;
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ManagementConfiguration.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ManagementConfiguration.java
deleted file mode 100644
index 3866da8f89..0000000000
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ManagementConfiguration.java
+++ /dev/null
@@ -1,77 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class ManagementConfiguration extends ConfigurationPlugin
-{
- CompositeConfiguration _finalConfig;
-
- public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory()
- {
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- ConfigurationPlugin instance = new ManagementConfiguration();
- instance.setConfiguration(path, config);
- return instance;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList("management");
- }
- };
-
- public String[] getElementsProcessed()
- {
- return new String[] { "" };
- }
-
- public Configuration getConfiguration()
- {
- return _finalConfig;
- }
-
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- // Valid Configuration either has xml links to new files
- _finalConfig = new CompositeConfiguration(getConfig());
- List subFiles = getConfig().getList("xml[@fileName]");
- for (Object subFile : subFiles)
- {
- _finalConfig.addConfiguration(new XMLConfiguration((String) subFile));
- }
-
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/DefinedFileServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/DefinedFileServlet.java
index d8a8395550..e6ae47dcff 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/DefinedFileServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/DefinedFileServlet.java
@@ -73,7 +73,7 @@ public class DefinedFileServlet extends HttpServlet
}
else
{
- response.sendError(404, "unknown file: "+ _filename);
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, "unknown file: "+ _filename);
}
}
}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/FileServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/FileServlet.java
index f8ca082d79..24e5e7c049 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/FileServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/FileServlet.java
@@ -20,11 +20,8 @@
*/
package org.apache.qpid.server.management.plugin.servlet;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
@@ -101,7 +98,7 @@ public class FileServlet extends HttpServlet
}
else
{
- response.sendError(404, "unknown file: "+ filename);
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, "unknown file: "+ filename);
}
}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/ExchangesServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/ExchangesServlet.java
deleted file mode 100644
index a3c5ec68a2..0000000000
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/ExchangesServlet.java
+++ /dev/null
@@ -1,208 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.api;
-
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.ObjectReader;
-
-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.State;
-import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ExchangesServlet extends HttpServlet
-{
-
-
- private Broker _broker;
-
- public ExchangesServlet()
- {
- super();
- _broker = ApplicationRegistry.getInstance().getBroker();
- }
-
- public ExchangesServlet(Broker broker)
- {
- _broker = broker;
- }
-
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- response.setContentType("application/json");
- response.setStatus(HttpServletResponse.SC_OK);
-
- Collection<VirtualHost> vhosts = _broker.getVirtualHosts();
- Collection<Exchange> exchanges = new ArrayList<Exchange>();
- Collection<Map<String,Object>> outputObject = new ArrayList<Map<String,Object>>();
-
- final PrintWriter writer = response.getWriter();
-
- ObjectMapper mapper = new ObjectMapper();
- String vhostName = null;
- String exchangeName = null;
-
- if(request.getPathInfo() != null && request.getPathInfo().length()>0)
- {
- String path = request.getPathInfo().substring(1);
- String[] parts = path.split("/");
- vhostName = parts.length == 0 ? "" : parts[0];
- if(parts.length > 1)
- {
- exchangeName = parts[1];
- }
- }
-
- for(VirtualHost vhost : vhosts)
- {
- if(vhostName == null || vhostName.equals(vhost.getName()))
- {
- for(Exchange exchange : vhost.getExchanges())
- {
- if(exchangeName == null || exchangeName.equals(exchange.getName()))
- {
- outputObject.add(convertToObject(exchange));
- if(exchangeName != null)
- {
- break;
- }
- }
- }
- if(vhostName != null)
- {
- break;
- }
- }
- }
-
- mapper.writeValue(writer, outputObject);
-
- }
-
- private Map<String,Object> convertToObject(final Exchange exchange)
- {
- Map<String, Object> object = new LinkedHashMap<String, Object>();
- object.put("name",exchange.getName());
- object.put("type", exchange.getExchangeType());
- object.put("durable", exchange.isDurable());
- object.put("auto-delete", exchange.getLifetimePolicy() == LifetimePolicy.AUTO_DELETE);
-
- Map<String,Object> arguments = new HashMap<String, Object>();
- for(String key : exchange.getAttributeNames())
- {
- if(!key.equals(Exchange.TYPE))
- {
- arguments.put(key, exchange.getAttribute(key));
- }
- }
- object.put("arguments", arguments);
- return object;
- }
-
- protected void doPut(final HttpServletRequest request, final HttpServletResponse response)
- throws ServletException, IOException
- {
-
- response.setContentType("application/json");
-
-
- String vhostName = null;
- String exchangeName = null;
- if(request.getPathInfo() != null && request.getPathInfo().length()>0)
- {
- String path = request.getPathInfo().substring(1);
- String[] parts = path.split("/");
- vhostName = parts.length == 0 ? "" : parts[0];
- if(parts.length > 1)
- {
- exchangeName = parts[1];
- }
- }
- if(vhostName == null)
- {
- response.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
- }
- else if (exchangeName == null)
- {
- response.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
- }
- else
- {
- VirtualHost vhost = null;
- for(VirtualHost host : _broker.getVirtualHosts())
- {
- if(host.getName().equals(vhostName))
- {
- vhost = host;
- }
- }
- if(vhost == null)
- {
- response.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
- }
- else
- {
- response.setStatus(HttpServletResponse.SC_NO_CONTENT);
- ObjectMapper mapper = new ObjectMapper();
- Map<String,Object> exchangeObject = mapper.readValue(request.getInputStream(), LinkedHashMap.class);
-
- final boolean isDurable = exchangeObject.get("durable") instanceof Boolean
- && ((Boolean)exchangeObject.get("durable"));
- final boolean isAutoDelete = exchangeObject.get("auto_delete") instanceof Boolean
- && ((Boolean)exchangeObject.get("auto_delete"));
-
- final String type = (String) exchangeObject.get("type");
- final Map<String, Object> attributes = new HashMap<String, Object>(exchangeObject);
- attributes.remove("durable");
- attributes.remove("auto_delete");
- attributes.remove("type");
-
- vhost.createExchange(exchangeName, State.ACTIVE, isDurable,
- isAutoDelete ? LifetimePolicy.AUTO_DELETE : LifetimePolicy.PERMANENT,
- 0l,
- type,
- attributes);
- }
-
-
-
- }
-
-
-
- }
-}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/VhostsServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/VhostsServlet.java
deleted file mode 100644
index b2c0fcfe52..0000000000
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/VhostsServlet.java
+++ /dev/null
@@ -1,118 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.api;
-
-import org.codehaus.jackson.map.ObjectMapper;
-
-import org.apache.qpid.common.QpidProperties;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.LifetimePolicy;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.protocol.AMQConnectionModel;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.*;
-
-public class VhostsServlet extends HttpServlet
-{
-
-
- private Broker _broker;
-
- public VhostsServlet()
- {
- super();
- _broker = ApplicationRegistry.getInstance().getBroker();
- }
-
- public VhostsServlet(Broker broker)
- {
- _broker = broker;
- }
-
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
-System.out.println("Get /api/vhosts");
- response.setContentType("application/json");
- response.setStatus(HttpServletResponse.SC_OK);
-
- Collection<VirtualHost> vhosts = _broker.getVirtualHosts();
-
-
-
- final PrintWriter writer = response.getWriter();
-
- ObjectMapper mapper = new ObjectMapper();
-
- if(request.getPathInfo() == null || request.getPathInfo().length()==0)
- {
-
- LinkedHashMap<String, Object> vhostObject = new LinkedHashMap<String, Object>();
- List<Map> vhostList = new ArrayList<Map>();
-
- for(VirtualHost vhost : vhosts)
- {
- vhostList.add(Collections.singletonMap("name", vhost.getName()));
- }
- mapper.writeValue(writer, vhostList);
- }
- else
- {
- LinkedHashMap<String, Object> vhostObject = new LinkedHashMap<String, Object>();
- String vhostName = request.getPathInfo().substring(1);
-
- for(VirtualHost vhost : vhosts)
- {
- if(vhostName.equals(vhost.getName()))
- {
- vhostObject.put("name", vhost.getName());
- break;
- }
- }
- mapper.writeValue(writer, vhostObject);
- }
- }
-
-
- protected void doPut(final HttpServletRequest request, final HttpServletResponse response)
- throws ServletException, IOException
- {
-
- response.setContentType("application/json");
- response.setStatus(HttpServletResponse.SC_NO_CONTENT);
-
- if(request.getPathInfo() != null && request.getPathInfo().length()>0)
- {
- String vhostName = request.getPathInfo().substring(1);
- _broker.createVirtualHost(vhostName, State.ACTIVE, true, LifetimePolicy.PERMANENT, 0L, Collections.EMPTY_MAP);
- }
-
-
- }
-}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
index a76bd98179..689bdb50d8 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
@@ -18,191 +18,456 @@
* under the License.
*
*/
-
package org.apache.qpid.server.management.plugin.servlet.rest;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
-import java.security.Principal;
-import java.util.Collections;
+import java.security.AccessControlException;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
import javax.security.auth.Subject;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.HttpManagementActor;
+import org.apache.qpid.server.management.plugin.HttpManagement;
+import org.apache.qpid.server.management.plugin.session.LoginLogoutReporter;
import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
public abstract class AbstractServlet extends HttpServlet
{
- private final Broker _broker;
+ private static final Logger LOGGER = Logger.getLogger(AbstractServlet.class);
+
+ /**
+ * Servlet context attribute holding a reference to a broker instance
+ */
+ public static final String ATTR_BROKER = "Qpid.broker";
+
+ /**
+ * Servlet context attribute holding a reference to plugin configuration
+ */
+ public static final String ATTR_MANAGEMENT = "Qpid.management";
+
+ private static final String ATTR_LOGIN_LOGOUT_REPORTER = "AbstractServlet.loginLogoutReporter";
+ private static final String ATTR_SUBJECT = "AbstractServlet.subject";
+ private static final String ATTR_LOG_ACTOR = "AbstractServlet.logActor";
+
+ private Broker _broker;
+ private RootMessageLogger _rootLogger;
+ private HttpManagement _httpManagement;
protected AbstractServlet()
{
super();
- _broker = ApplicationRegistry.getInstance().getBroker();
}
- protected AbstractServlet(Broker broker)
+ @Override
+ public void init() throws ServletException
{
- _broker = broker;
+ ServletConfig servletConfig = getServletConfig();
+ ServletContext servletContext = servletConfig.getServletContext();
+ _broker = (Broker)servletContext.getAttribute(ATTR_BROKER);
+ _rootLogger = _broker.getRootMessageLogger();
+ _httpManagement = (HttpManagement)servletContext.getAttribute(ATTR_MANAGEMENT);
+ super.init();
}
@Override
- protected final void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException
+ protected final void doGet(final HttpServletRequest request, final HttpServletResponse resp)
{
- setAuthorizedSubject(request);
- try
- {
- onGet(request, resp);
- }
- finally
- {
- clearAuthorizedSubject();
- }
+ doWithSubjectAndActor(
+ new PrivilegedExceptionAction<Void>()
+ {
+ @Override
+ public Void run() throws Exception
+ {
+ doGetWithSubjectAndActor(request, resp);
+ return null;
+ }
+ },
+ request,
+ resp
+ );
+ }
+
+ /**
+ * Performs the GET action as the logged-in {@link Subject}.
+ * The {@link LogActor} is set before this method is called.
+ * Subclasses commonly override this method
+ */
+ protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException
+ {
+ throw new UnsupportedOperationException("GET not supported by this servlet");
+ }
+
+
+ @Override
+ protected final void doPost(final HttpServletRequest request, final HttpServletResponse resp)
+ {
+ doWithSubjectAndActor(
+ new PrivilegedExceptionAction<Void>()
+ {
+ @Override
+ public Void run() throws Exception
+ {
+ doPostWithSubjectAndActor(request, resp);
+ return null;
+ }
+ },
+ request,
+ resp
+ );
+ }
+
+ /**
+ * Performs the POST action as the logged-in {@link Subject}.
+ * The {@link LogActor} is set before this method is called.
+ * Subclasses commonly override this method
+ */
+ protected void doPostWithSubjectAndActor(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ throw new UnsupportedOperationException("POST not supported by this servlet");
+ }
+
+ @Override
+ protected final void doPut(final HttpServletRequest request, final HttpServletResponse resp)
+ {
+ doWithSubjectAndActor(
+ new PrivilegedExceptionAction<Void>()
+ {
+ @Override
+ public Void run() throws Exception
+ {
+ doPutWithSubjectAndActor(request, resp);
+ return null;
+ }
+ },
+ request,
+ resp
+ );
}
- protected void onGet(HttpServletRequest request, HttpServletResponse resp) throws IOException, ServletException
+ /**
+ * Performs the PUT action as the logged-in {@link Subject}.
+ * The {@link LogActor} is set before this method is called.
+ * Subclasses commonly override this method
+ */
+ protected void doPutWithSubjectAndActor(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
- super.doGet(request, resp);
+ throw new UnsupportedOperationException("PUT not supported by this servlet");
}
- private void clearAuthorizedSubject()
+ @Override
+ protected final void doDelete(final HttpServletRequest request, final HttpServletResponse resp)
+ throws ServletException, IOException
{
- org.apache.qpid.server.security.SecurityManager.setThreadSubject(null);
+ doWithSubjectAndActor(
+ new PrivilegedExceptionAction<Void>()
+ {
+ @Override
+ public Void run() throws Exception
+ {
+ doDeleteWithSubjectAndActor(request, resp);
+ return null;
+ }
+ },
+ request,
+ resp
+ );
}
+ /**
+ * Performs the PUT action as the logged-in {@link Subject}.
+ * The {@link LogActor} is set before this method is called.
+ * Subclasses commonly override this method
+ */
+ protected void doDeleteWithSubjectAndActor(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ throw new UnsupportedOperationException("DELETE not supported by this servlet");
+ }
- private void setAuthorizedSubject(HttpServletRequest request)
+ private void doWithSubjectAndActor(
+ PrivilegedExceptionAction<Void> privilegedExceptionAction,
+ final HttpServletRequest request,
+ final HttpServletResponse resp)
{
- HttpSession session = request.getSession(true);
- Subject subject = (Subject) session.getAttribute("subject");
+ Subject subject;
+ try
+ {
+ subject = getAndCacheAuthorizedSubject(request);
+ }
+ catch (AccessControlException e)
+ {
+ sendError(resp, HttpServletResponse.SC_FORBIDDEN);
+ return;
+ }
- if(subject == null)
+ SecurityManager.setThreadSubject(subject);
+ try
{
- Principal principal = request.getUserPrincipal();
- if(principal != null)
+ HttpManagementActor logActor = getLogActorAndCacheInSession(request);
+ CurrentActor.set(logActor);
+ try
+ {
+ Subject.doAs(subject, privilegedExceptionAction);
+ }
+ catch(RuntimeException e)
{
- subject = new Subject(false, Collections.singleton(principal),Collections.emptySet(),
- Collections.emptySet());
+ LOGGER.error("Unable to perform action", e);
+ throw e;
}
- else
+ catch (PrivilegedActionException e)
{
- String header = request.getHeader("Authorization");
+ LOGGER.error("Unable to perform action", e);
+ throw new RuntimeException(e.getCause());
+ }
+ finally
+ {
+ CurrentActor.remove();
+ }
+ }
+ finally
+ {
+ try
+ {
+ SecurityManager.setThreadSubject(null);
+ }
+ finally
+ {
+ AMQShortString.clearLocalCache();
+ }
+ }
+ }
+
+ /**
+ * Gets the logged-in {@link Subject} by trying the following:
+ *
+ * <ul>
+ * <li>Get it from the session</li>
+ * <li>Get it from the request</li>
+ * <li>Log in using the username and password in the Authorization HTTP header</li>
+ * <li>Create a Subject representing the anonymous user.</li>
+ * </ul>
+ *
+ * If an authenticated subject is found it is cached in the http session.
+ */
+ private Subject getAndCacheAuthorizedSubject(HttpServletRequest request)
+ {
+ HttpSession session = request.getSession();
+ Subject subject = getAuthorisedSubjectFromSession(session);
- /*
- * TODO - Should configure whether basic authentication is allowed... and in particular whether it
- * should be allowed over non-ssl connections
- * */
+ if(subject != null)
+ {
+ return subject;
+ }
- if (header != null)
+ SubjectCreator subjectCreator = getSubjectCreator(request);
+ subject = authenticate(request, subjectCreator);
+ if (subject != null)
+ {
+ authoriseManagement(request, subject);
+ setAuthorisedSubjectInSession(subject, request, session);
+ }
+ else
+ {
+ subject = subjectCreator.createSubjectWithGroups(AnonymousAuthenticationManager.ANONYMOUS_USERNAME);
+ }
+
+ return subject;
+ }
+
+ protected void authoriseManagement(HttpServletRequest request, Subject subject)
+ {
+ // TODO: We should eliminate SecurityManager.setThreadSubject in favour of Subject.doAs
+ SecurityManager.setThreadSubject(subject); // Required for accessManagement check
+ LogActor actor = createHttpManagementActor(request);
+ CurrentActor.set(actor);
+ try
+ {
+ try
+ {
+ Subject.doAs(subject, new PrivilegedExceptionAction<Void>() // Required for proper logging of Subject
{
- String[] tokens = header.split("\\s");
- if(tokens.length >= 2
- && "BASIC".equalsIgnoreCase(tokens[0]))
+ @Override
+ public Void run() throws Exception
{
- String[] credentials = (new String(Base64.decodeBase64(tokens[1].getBytes()))).split(":",2);
- if(credentials.length == 2)
+ boolean allowed = getSecurityManager().accessManagement();
+ if (!allowed)
{
- SocketAddress address = getSocketAddress(request);
- AuthenticationManager authenticationManager =
- ApplicationRegistry.getInstance().getAuthenticationManager(address);
- AuthenticationResult authResult =
- authenticationManager.authenticate(credentials[0], credentials[1]);
- subject = authResult.getSubject();
-
+ throw new AccessControlException("User is not authorised for management");
}
+ return null;
}
- }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException("Unable to perform access check", e);
}
}
- if (subject == null)
+ finally
{
- subject = AnonymousAuthenticationManager.ANONYMOUS_SUBJECT;
+ try
+ {
+ CurrentActor.remove();
+ }
+ finally
+ {
+ SecurityManager.setThreadSubject(null);
+ }
}
- org.apache.qpid.server.security.SecurityManager.setThreadSubject(subject);
-
}
- protected Subject getSubject(HttpSession session)
+ private Subject authenticate(HttpServletRequest request, SubjectCreator subjectCreator)
{
- return (Subject)session.getAttribute("subject");
+ Subject subject = null;
+
+ String remoteUser = request.getRemoteUser();
+ if(remoteUser != null)
+ {
+ subject = authenticateUserAndGetSubject(subjectCreator, remoteUser, null);
+ }
+ else
+ {
+ String header = request.getHeader("Authorization");
+
+ if (header != null)
+ {
+ String[] tokens = header.split("\\s");
+ if(tokens.length >= 2 && "BASIC".equalsIgnoreCase(tokens[0]))
+ {
+ if(!isBasicAuthSupported(request))
+ {
+ //TODO: write a return response indicating failure?
+ throw new IllegalArgumentException("BASIC Authorization is not enabled.");
+ }
+
+ subject = performBasicAuth(subject, subjectCreator, tokens[1]);
+ }
+ }
+ }
+
+ return subject;
}
- @Override
- protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ private Subject performBasicAuth(Subject subject,SubjectCreator subjectCreator, String base64UsernameAndPassword)
{
- setAuthorizedSubject(req);
- try
+ String[] credentials = (new String(Base64.decodeBase64(base64UsernameAndPassword.getBytes()))).split(":",2);
+ if(credentials.length == 2)
{
- onPost(req, resp);
+ subject = authenticateUserAndGetSubject(subjectCreator, credentials[0], credentials[1]);
}
- finally
+ else
{
- clearAuthorizedSubject();
+ //TODO: write a return response indicating failure?
+ throw new AccessControlException("Invalid number of credentials supplied: "
+ + credentials.length);
}
+ return subject;
+ }
+ private Subject authenticateUserAndGetSubject(SubjectCreator subjectCreator, String username, String password)
+ {
+ SubjectAuthenticationResult authResult = subjectCreator.authenticate(username, password);
+ if( authResult.getStatus() != AuthenticationStatus.SUCCESS)
+ {
+ //TODO: write a return response indicating failure?
+ throw new AccessControlException("Incorrect username or password");
+ }
+ Subject subject = authResult.getSubject();
+ return subject;
}
- protected void onPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ private boolean isBasicAuthSupported(HttpServletRequest req)
{
- super.doPost(req, resp);
+ return req.isSecure() ? _httpManagement.isHttpsBasicAuthenticationEnabled()
+ : _httpManagement.isHttpBasicAuthenticationEnabled();
}
- @Override
- protected final void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ private HttpManagementActor getLogActorAndCacheInSession(HttpServletRequest req)
{
- setAuthorizedSubject(req);
- try
- {
- onPut(req, resp);
+ HttpSession session = req.getSession();
- }
- finally
+ HttpManagementActor actor = (HttpManagementActor) session.getAttribute(ATTR_LOG_ACTOR);
+ if(actor == null)
{
- clearAuthorizedSubject();
+ actor = createHttpManagementActor(req);
+ session.setAttribute(ATTR_LOG_ACTOR, actor);
}
+
+ return actor;
}
- protected void onPut(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
+ protected Subject getAuthorisedSubjectFromSession(HttpSession session)
{
- super.doPut(req,resp);
+ return (Subject)session.getAttribute(ATTR_SUBJECT);
}
- @Override
- protected final void doDelete(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
+ protected void setAuthorisedSubjectInSession(Subject subject, HttpServletRequest request, final HttpSession session)
+ {
+ session.setAttribute(ATTR_SUBJECT, subject);
+
+ LogActor logActor = createHttpManagementActor(request);
+ // Cause the user logon to be logged.
+ session.setAttribute(ATTR_LOGIN_LOGOUT_REPORTER, new LoginLogoutReporter(logActor, subject));
+ }
+
+ protected Broker getBroker()
+ {
+ return _broker;
+ }
+
+ protected SocketAddress getSocketAddress(HttpServletRequest request)
+ {
+ return InetSocketAddress.createUnresolved(request.getServerName(), request.getServerPort());
+ }
+
+ protected void sendError(final HttpServletResponse resp, int errorCode)
{
- setAuthorizedSubject(req);
try
{
- onDelete(req, resp);
+ resp.sendError(errorCode);
}
- finally
+ catch (IOException e)
{
- clearAuthorizedSubject();
+ throw new RuntimeException("Failed to send error response code " + errorCode, e);
}
}
- protected void onDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ private HttpManagementActor createHttpManagementActor(HttpServletRequest request)
{
- super.doDelete(req, resp);
+ return new HttpManagementActor(_rootLogger, request.getRemoteAddr(), request.getRemotePort());
}
+ protected HttpManagement getManagement()
+ {
+ return _httpManagement;
+ }
- protected Broker getBroker()
+ protected SecurityManager getSecurityManager()
{
- return _broker;
+ return _broker.getSecurityManager();
}
- protected SocketAddress getSocketAddress(HttpServletRequest request)
+ protected SubjectCreator getSubjectCreator(HttpServletRequest request)
{
- return InetSocketAddress.createUnresolved(request.getServerName(), request.getServerPort());
+ return _broker.getSubjectCreator(getSocketAddress(request));
}
}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
index 404793b592..f2cf5d7734 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
@@ -26,8 +26,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.qpid.server.logging.LogRecorder;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
@@ -35,16 +33,11 @@ public class LogRecordsServlet extends AbstractServlet
{
public LogRecordsServlet()
{
- super(ApplicationRegistry.getInstance().getBroker());
- }
-
- public LogRecordsServlet(Broker broker)
- {
- super(broker);
+ super();
}
@Override
- protected void onGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
@@ -53,10 +46,10 @@ public class LogRecordsServlet extends AbstractServlet
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
- ApplicationRegistry applicationRegistry = (ApplicationRegistry) ApplicationRegistry.getInstance();
List<Map<String,Object>> logRecords = new ArrayList<Map<String, Object>>();
- for(LogRecorder.Record record : applicationRegistry.getLogRecorder())
+ LogRecorder logRecorder = getBroker().getLogRecorder();
+ for(LogRecorder.Record record : logRecorder)
{
logRecords.add(logRecordToObject(record));
}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogoutServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogoutServlet.java
new file mode 100644
index 0000000000..4188e7d60d
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogoutServlet.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.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.qpid.server.management.plugin.HttpManagement;
+
+@SuppressWarnings("serial")
+public class LogoutServlet extends HttpServlet
+{
+ public static final String RETURN_URL_INIT_PARAM = "qpid.webui_logout_redirect";
+ private String _returnUrl = HttpManagement.ENTRY_POINT_PATH;
+
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+
+ String initValue = config.getServletContext().getInitParameter(RETURN_URL_INIT_PARAM);
+ if(initValue != null)
+ {
+ _returnUrl = initValue;
+ }
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException
+ {
+ HttpSession session = request.getSession(false);
+ if(session != null)
+ {
+ // Invalidating the session will cause LoginLogoutReporter to log the user logoff.
+ session.invalidate();
+ }
+
+ resp.sendRedirect(_returnUrl);
+ }
+
+}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java
index bc87f0bcc5..d61c48bb2c 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java
@@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.queue.QueueEntry;
@@ -42,13 +41,8 @@ public class MessageContentServlet extends AbstractServlet
super();
}
- public MessageContentServlet(Broker broker)
- {
- super(broker);
- }
-
@Override
- protected void onGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if(request.getPathInfo() != null && request.getPathInfo().length()>0 && request.getPathInfo().substring(1).split("/").length > 2)
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
index 6e7bc1d935..49e0c2b1bf 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
@@ -34,13 +34,10 @@ import org.apache.log4j.Logger;
import org.apache.qpid.server.message.AMQMessageHeader;
import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.queue.QueueEntry;
import org.apache.qpid.server.queue.QueueEntryVisitor;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.access.Operation;
import org.apache.qpid.server.subscription.Subscription;
@@ -56,13 +53,8 @@ public class MessageServlet extends AbstractServlet
super();
}
- public MessageServlet(Broker broker)
- {
- super(broker);
- }
-
@Override
- protected void onGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if(request.getPathInfo() != null && request.getPathInfo().length()>0 && request.getPathInfo().substring(1).split("/").length > 2)
@@ -400,7 +392,7 @@ public class MessageServlet extends AbstractServlet
* POST moves or copies messages to the given queue from a queue specified in the posted JSON data
*/
@Override
- protected void onPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ protected void doPostWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
@@ -422,7 +414,7 @@ public class MessageServlet extends AbstractServlet
// FIXME: added temporary authorization check until we introduce management layer
// and review current ACL rules to have common rules for all management interfaces
String methodName = isMoveTransaction? "moveMessages":"copyMessages";
- if (isQueueUpdateMethodAuthorized(methodName, vhost.getName()))
+ if (isQueueUpdateMethodAuthorized(methodName, vhost))
{
final Queue destinationQueue = getQueueFromVirtualHost(destQueueName, vhost);
final List messageIds = new ArrayList((List) providedObject.get("messages"));
@@ -435,7 +427,7 @@ public class MessageServlet extends AbstractServlet
}
else
{
- response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
}
catch(RuntimeException e)
@@ -450,7 +442,7 @@ public class MessageServlet extends AbstractServlet
* DELETE removes messages from the queue
*/
@Override
- protected void onDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ protected void doDeleteWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response)
{
final Queue sourceQueue = getQueueFromRequest(request);
@@ -466,37 +458,22 @@ public class MessageServlet extends AbstractServlet
// FIXME: added temporary authorization check until we introduce management layer
// and review current ACL rules to have common rules for all management interfaces
- if (isQueueUpdateMethodAuthorized("deleteMessages", vhost.getName()))
+ if (isQueueUpdateMethodAuthorized("deleteMessages", vhost))
{
vhost.executeTransaction(new DeleteTransaction(sourceQueue, messageIds));
response.setStatus(HttpServletResponse.SC_OK);
}
else
{
- response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
}
- private boolean isQueueUpdateMethodAuthorized(String methodName, String virtualHost)
+ private boolean isQueueUpdateMethodAuthorized(String methodName, VirtualHost host)
{
- SecurityManager securityManager = getSecurityManager(virtualHost);
+ SecurityManager securityManager = host.getSecurityManager();
return securityManager.authoriseMethod(Operation.UPDATE, "VirtualHost.Queue", methodName);
}
- private SecurityManager getSecurityManager(String virtualHost)
- {
- IApplicationRegistry appRegistry = ApplicationRegistry.getInstance();
- SecurityManager security;
- if (virtualHost == null)
- {
- security = appRegistry.getSecurityManager();
- }
- else
- {
- security = appRegistry.getVirtualHostRegistry().getVirtualHost(virtualHost).getSecurityManager();
- }
- return security;
- }
-
}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
index 6a79916d07..3fab26cde5 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
@@ -19,6 +19,7 @@ package org.apache.qpid.server.management.plugin.servlet.rest;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
+import java.security.AccessControlException;
import java.util.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -31,7 +32,6 @@ import org.apache.qpid.server.model.*;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
-
public class RestServlet extends AbstractServlet
{
private static final Logger LOGGER = Logger.getLogger(RestServlet.class);
@@ -47,29 +47,29 @@ public class RestServlet extends AbstractServlet
private Class<? extends ConfiguredObject>[] _hierarchy;
- private volatile boolean initializationRequired = false;
-
private final ConfiguredObjectToMapConverter _objectConverter = new ConfiguredObjectToMapConverter();
+ private final boolean _hierarchyInitializationRequired;
public RestServlet()
{
super();
- initializationRequired = true;
+ _hierarchyInitializationRequired = true;
}
- public RestServlet(Broker broker, Class<? extends ConfiguredObject>... hierarchy)
+ public RestServlet(Class<? extends ConfiguredObject>... hierarchy)
{
- super(broker);
+ super();
_hierarchy = hierarchy;
+ _hierarchyInitializationRequired = false;
}
@Override
public void init() throws ServletException
{
- if (initializationRequired)
+ super.init();
+ if (_hierarchyInitializationRequired)
{
doInitialization();
- initializationRequired = false;
}
}
@@ -285,7 +285,7 @@ public class RestServlet extends AbstractServlet
}
@Override
- protected void onGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
@@ -319,7 +319,7 @@ public class RestServlet extends AbstractServlet
}
@Override
- protected void onPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ protected void doPutWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("application/json");
@@ -336,7 +336,8 @@ public class RestServlet extends AbstractServlet
if(names.size() != _hierarchy.length)
{
- throw new IllegalArgumentException("Path to object to create must be fully specified");
+ throw new IllegalArgumentException("Path to object to create must be fully specified. "
+ + "Found " + names.size() + " expecting " + _hierarchy.length);
}
}
@@ -428,8 +429,11 @@ public class RestServlet extends AbstractServlet
|| (obj.getName().equals(providedObject.get("name")) && equalParents(obj, otherParents)))
{
doUpdate(obj, providedObject);
+ response.setStatus(HttpServletResponse.SC_OK);
+ return;
}
}
+
theParent.createChild(objClass, providedObject, otherParents);
}
catch (RuntimeException e)
@@ -462,13 +466,17 @@ public class RestServlet extends AbstractServlet
private void setResponseStatus(HttpServletResponse response, RuntimeException e) throws IOException
{
- if (e.getCause() instanceof AMQSecurityException)
+ if (e instanceof AccessControlException || e.getCause() instanceof AMQSecurityException)
{
- response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Caught security exception, sending " + HttpServletResponse.SC_FORBIDDEN, e);
+ }
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
else
{
- LOGGER.warn("Unexpected exception is caught", e);
+ LOGGER.warn("Caught exception", e);
// TODO
response.setStatus(HttpServletResponse.SC_CONFLICT);
@@ -476,7 +484,7 @@ public class RestServlet extends AbstractServlet
}
@Override
- protected void onDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ protected void doDeleteWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
index 1b78611a50..069132af1e 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
@@ -25,10 +25,9 @@ import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.management.plugin.HttpManagement;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
import javax.security.auth.Subject;
import javax.security.sasl.SaslException;
@@ -39,6 +38,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
+import java.security.AccessControlException;
import java.security.Principal;
import java.security.SecureRandom;
import java.util.LinkedHashMap;
@@ -47,6 +47,7 @@ import java.util.Random;
public class SaslServlet extends AbstractServlet
{
+
private static final Logger LOGGER = Logger.getLogger(SaslServlet.class);
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
@@ -56,18 +57,12 @@ public class SaslServlet extends AbstractServlet
private static final String ATTR_EXPIRY = "SaslServlet.Expiry";
private static final long SASL_EXCHANGE_EXPIRY = 1000L;
-
public SaslServlet()
{
super();
}
- public SaslServlet(Broker broker)
- {
- super(broker);
- }
-
- protected void onGet(HttpServletRequest request, HttpServletResponse response) throws
+ protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException
{
@@ -79,15 +74,16 @@ public class SaslServlet extends AbstractServlet
response.setDateHeader ("Expires", 0);
HttpSession session = request.getSession();
- Random rand = getRandom(session);
+ getRandom(session);
- AuthenticationManager authManager = ApplicationRegistry.getInstance().getAuthenticationManager(getSocketAddress(request));
- String[] mechanisms = authManager.getMechanisms().split(" ");
+ SubjectCreator subjectCreator = getSubjectCreator(request);
+ String[] mechanisms = subjectCreator.getMechanisms().split(" ");
Map<String, Object> outputObject = new LinkedHashMap<String, Object>();
- final Subject subject = (Subject) session.getAttribute("subject");
+
+ final Subject subject = getAuthorisedSubjectFromSession(session);
if(subject != null)
{
- final Principal principal = subject.getPrincipals().iterator().next();
+ Principal principal = AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(subject);
outputObject.put("user", principal.getName());
}
else if (request.getRemoteUser() != null)
@@ -121,9 +117,10 @@ public class SaslServlet extends AbstractServlet
@Override
- protected void onPost(final HttpServletRequest request, final HttpServletResponse response)
- throws ServletException, IOException
+ protected void doPostWithSubjectAndActor(final HttpServletRequest request, final HttpServletResponse response) throws IOException
{
+ checkSaslAuthEnabled(request);
+
try
{
response.setContentType("application/json");
@@ -137,14 +134,18 @@ public class SaslServlet extends AbstractServlet
String id = request.getParameter("id");
String saslResponse = request.getParameter("response");
- AuthenticationManager authManager = ApplicationRegistry.getInstance().getAuthenticationManager(getSocketAddress(request));
+ SubjectCreator subjectCreator = getSubjectCreator(request);
if(mechanism != null)
{
if(id == null)
{
- SaslServer saslServer = authManager.createSaslServer(mechanism, request.getServerName(), null/*TODO*/);
- evaluateSaslResponse(response, session, saslResponse, saslServer);
+ if(LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Creating SaslServer for mechanism: " + mechanism);
+ }
+ SaslServer saslServer = subjectCreator.createSaslServer(mechanism, request.getServerName(), null/*TODO*/);
+ evaluateSaslResponse(request, response, session, saslResponse, saslServer, subjectCreator);
}
else
{
@@ -152,9 +153,7 @@ public class SaslServlet extends AbstractServlet
session.removeAttribute(ATTR_ID);
session.removeAttribute(ATTR_SASL_SERVER);
session.removeAttribute(ATTR_EXPIRY);
-
}
-
}
else
{
@@ -163,8 +162,7 @@ public class SaslServlet extends AbstractServlet
if(id.equals(session.getAttribute(ATTR_ID)) && System.currentTimeMillis() < (Long) session.getAttribute(ATTR_EXPIRY))
{
SaslServer saslServer = (SaslServer) session.getAttribute(ATTR_SASL_SERVER);
- evaluateSaslResponse(response, session, saslResponse, saslServer);
-
+ evaluateSaslResponse(request, response, session, saslResponse, saslServer, subjectCreator);
}
else
{
@@ -180,7 +178,6 @@ public class SaslServlet extends AbstractServlet
session.removeAttribute(ATTR_ID);
session.removeAttribute(ATTR_SASL_SERVER);
session.removeAttribute(ATTR_EXPIRY);
-
}
}
}
@@ -194,12 +191,30 @@ public class SaslServlet extends AbstractServlet
LOGGER.error("Error processing SASL request", e);
throw e;
}
+ }
+ private void checkSaslAuthEnabled(HttpServletRequest request)
+ {
+ boolean saslAuthEnabled;
+ HttpManagement management = getManagement();
+ if (request.isSecure())
+ {
+ saslAuthEnabled = management.isHttpsSaslAuthenticationEnabled();
+ }
+ else
+ {
+ saslAuthEnabled = management.isHttpSaslAuthenticationEnabled();
+ }
+
+ if (!saslAuthEnabled)
+ {
+ throw new RuntimeException("Sasl authentication disabled.");
+ }
}
- private void evaluateSaslResponse(final HttpServletResponse response,
- final HttpSession session,
- final String saslResponse, final SaslServer saslServer) throws IOException
+ private void evaluateSaslResponse(final HttpServletRequest request,
+ final HttpServletResponse response,
+ final HttpSession session, final String saslResponse, final SaslServer saslServer, SubjectCreator subjectCreator) throws IOException
{
final String id;
byte[] challenge;
@@ -209,27 +224,34 @@ public class SaslServlet extends AbstractServlet
}
catch(SaslException e)
{
-
session.removeAttribute(ATTR_ID);
session.removeAttribute(ATTR_SASL_SERVER);
session.removeAttribute(ATTR_EXPIRY);
- response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
if(saslServer.isComplete())
{
- final Subject subject = new Subject();
- subject.getPrincipals().add(new UsernamePrincipal(saslServer.getAuthorizationID()));
- session.setAttribute("subject", subject);
+ Subject subject = subjectCreator.createSubjectWithGroups(saslServer.getAuthorizationID());
+
+ try
+ {
+ authoriseManagement(request, subject);
+ }
+ catch (AccessControlException ace)
+ {
+ sendError(response, HttpServletResponse.SC_FORBIDDEN);
+ return;
+ }
+
+ setAuthorisedSubjectInSession(subject, request, session);
session.removeAttribute(ATTR_ID);
session.removeAttribute(ATTR_SASL_SERVER);
session.removeAttribute(ATTR_EXPIRY);
response.setStatus(HttpServletResponse.SC_OK);
-
-
}
else
{
@@ -250,7 +272,6 @@ public class SaslServlet extends AbstractServlet
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
mapper.writeValue(writer, outputObject);
-
}
}
}
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
index 60f977ca66..40d3c02768 100644
--- a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
@@ -41,13 +41,8 @@ public class StructureServlet extends AbstractServlet
super();
}
- public StructureServlet(Broker broker)
- {
- super(broker);
- }
-
@Override
- protected void onGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
@@ -56,6 +51,8 @@ public class StructureServlet extends AbstractServlet
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
+ // TODO filtering??? request.getParameter("filter"); // filter=1,2,3 /groups/*/*
+
Map<String,Object> structure = generateStructure(getBroker(), Broker.class);
final PrintWriter writer = response.getWriter();
diff --git a/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/session/LoginLogoutReporter.java b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/session/LoginLogoutReporter.java
new file mode 100644
index 0000000000..238f1b4719
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/session/LoginLogoutReporter.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.management.plugin.session;
+
+import java.security.Principal;
+import java.security.PrivilegedAction;
+
+import javax.security.auth.Subject;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+
+/**
+ * Logs {@link ManagementConsoleMessages#OPEN(String)} and {@link ManagementConsoleMessages#CLOSE(String)}
+ * messages. A single instance of this class must be placed in the {@link HttpSession} immediately after
+ * the user has successfully logged-in, and removed (or the whole session invalidated) as the user logs out.
+ */
+public class LoginLogoutReporter implements HttpSessionBindingListener
+{
+ private static final Logger LOGGER = Logger.getLogger(LoginLogoutReporter.class);
+ private final LogActor _logActor;
+ private final Subject _subject;
+ private final Principal _principal;
+
+ public LoginLogoutReporter(LogActor logActor, Subject subject)
+ {
+ super();
+ _logActor = logActor;
+ _subject = subject;
+ _principal = AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(_subject);
+ }
+
+ @Override
+ public void valueBound(HttpSessionBindingEvent arg0)
+ {
+ reportLogin();
+ }
+
+ @Override
+ public void valueUnbound(HttpSessionBindingEvent arg0)
+ {
+ reportLogout();
+ }
+
+ private void reportLogin()
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("User logging in : " + _principal);
+ }
+
+ Subject.doAs(_subject, new PrivilegedAction<Void>()
+ {
+ @Override
+ public Void run()
+ {
+ _logActor.message(ManagementConsoleMessages.OPEN(_principal.getName()));
+ return null;
+ }
+ });
+ }
+
+ private void reportLogout()
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("User logging out : " + _principal);
+ }
+
+ Subject.doAs(_subject, new PrivilegedAction<Void>()
+ {
+ @Override
+ public Void run()
+ {
+ _logActor.message(ManagementConsoleMessages.CLOSE(_principal.getName()));
+ return null;
+ }
+ });
+ }
+
+}
diff --git a/java/broker-plugins/management-http/src/main/java/resources/authenticationprovider/showPrincipalDatabaseAuthenticationManager.html b/java/broker-plugins/management-http/src/main/java/resources/authenticationprovider/showPrincipalDatabaseAuthenticationManager.html
index baadc8c35f..e6c067fddf 100644
--- a/java/broker-plugins/management-http/src/main/java/resources/authenticationprovider/showPrincipalDatabaseAuthenticationManager.html
+++ b/java/broker-plugins/management-http/src/main/java/resources/authenticationprovider/showPrincipalDatabaseAuthenticationManager.html
@@ -23,7 +23,5 @@
<div class="users"></div>
<button data-dojo-type="dijit.form.Button" class="addUserButton">Add User</button>
<button data-dojo-type="dijit.form.Button" class="deleteUserButton">Delete Users</button>
-
</div>
-
</div>
diff --git a/java/broker-plugins/management-http/src/main/java/resources/group/addGroupMember.html b/java/broker-plugins/management-http/src/main/java/resources/group/addGroupMember.html
new file mode 100644
index 0000000000..0372468f91
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/group/addGroupMember.html
@@ -0,0 +1,37 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<div class="dijitHidden">
+ <div data-dojo-type="dijit.Dialog" style="width:600px;" data-dojo-props="title:'Add Group Member'" id="addGroupMember">
+ <form id="formAddGroupMember" method="post" dojoType="dijit.form.Form">
+ <table cellpadding="0" cellspacing="2">
+ <tr>
+ <td valign="top"><strong>Name*: </strong></td>
+ <td><input type="text" required="true" name="name" id="formAddGroupMember.name" placeholder="Name"
+ dojoType="dijit.form.ValidationTextBox" missingMessage="A name must be supplied" /></td>
+ </tr>
+ </table>
+ <br/>
+
+ <!-- submit buttons -->
+ <input type="submit" value="Add Group Member" label="Add Group Member" dojoType="dijit.form.Button" />
+ </form>
+ </div>
+</div>
diff --git a/java/broker-plugins/management-http/src/main/java/resources/group/showGroup.html b/java/broker-plugins/management-http/src/main/java/resources/group/showGroup.html
new file mode 100644
index 0000000000..4fddf727d0
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/group/showGroup.html
@@ -0,0 +1,30 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<div class="group">
+ <span style="">Name:</span><span class="name" style="position:absolute; left:6em"></span>
+ <br/>
+ <div data-dojo-type="dijit.TitlePane" data-dojo-props="title: 'Group Members'">
+ <div class="groupMembers"></div>
+ <button data-dojo-type="dijit.form.Button" class="addGroupMemberButton" type="button">Add Group Member</button>
+ <button data-dojo-type="dijit.form.Button" class="removeGroupMemberButton" type="button">Remove Group Members</button>
+ </div>
+</div>
+
diff --git a/java/broker-plugins/management-http/src/main/java/resources/groupprovider/addGroup.html b/java/broker-plugins/management-http/src/main/java/resources/groupprovider/addGroup.html
new file mode 100644
index 0000000000..8d3431808a
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/groupprovider/addGroup.html
@@ -0,0 +1,38 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<div class="dijitHidden">
+ <div data-dojo-type="dijit.Dialog" style="width:600px;" data-dojo-props="title:'Add Group'" id="addGroup">
+ <form id="formAddGroup" method="post" dojoType="dijit.form.Form">
+ <table cellpadding="0" cellspacing="2">
+ <tr>
+ <td valign="top"><strong>Group Name*: </strong></td>
+ <td><input type="text" required="true" name="name" id="formAddGroup.name" placeholder="Group Name"
+ dojoType="dijit.form.ValidationTextBox" missingMessage="A name must be supplied" /></td>
+ </tr>
+ </table>
+ <br/>
+
+ <!-- submit buttons -->
+ <input type="submit" value="Create Group" label="Create Group" dojoType="dijit.form.Button" />
+
+ </form>
+ </div>
+</div>
diff --git a/java/broker-plugins/management-http/src/main/java/resources/groupprovider/showFileGroupManager.html b/java/broker-plugins/management-http/src/main/java/resources/groupprovider/showFileGroupManager.html
new file mode 100644
index 0000000000..734e8b5419
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/groupprovider/showFileGroupManager.html
@@ -0,0 +1,28 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<div class="FileGroupManager">
+ <div data-dojo-type="dijit.TitlePane" data-dojo-props="title: 'Groups'">
+ <div class="groups"></div>
+ <button data-dojo-type="dijit.form.Button" class="addGroupButton">Add Group</button>
+ <button data-dojo-type="dijit.form.Button" class="deleteGroupButton">Delete Groups</button>
+ </div>
+
+</div>
diff --git a/java/broker-plugins/management-http/src/main/java/resources/index.html b/java/broker-plugins/management-http/src/main/java/resources/index.html
new file mode 100644
index 0000000000..2fb9137ff8
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/index.html
@@ -0,0 +1,90 @@
+<!DOCTYPE HTML>
+<!--
+ ~ 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.
+ -->
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>Qpid Management</title>
+ <link rel="stylesheet" href="dojo/dojo/resources/dojo.css">
+ <link rel="stylesheet" href="dojo/dijit/themes/claro/claro.css">
+ <link rel="stylesheet" href="dojo/dojox/grid/resources/claroGrid.css">
+ <link rel="stylesheet" href="dojo/dojox/grid/enhanced/resources/claro/EnhancedGrid.css">
+ <link rel="stylesheet" href="dojo/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css">
+ <link rel="stylesheet" href="css/common.css" media="screen">
+ <script>
+ function getContextPath()
+ {
+ var contextPath = "/";
+ var documentURL = document.URL;
+ var managementPageStart = documentURL.lastIndexOf("/");
+ var firstSlashPos = documentURL.indexOf("/", documentURL.indexOf("//") + 2);
+ if (managementPageStart > firstSlashPos)
+ {
+ contextPath = documentURL.substring(firstSlashPos, managementPageStart);
+ }
+ return contextPath;
+ }
+
+ var dojoConfig = {
+ tlmSiblingOfDojo:false,
+ parseOnLoad:true,
+ async:true,
+ baseUrl: getContextPath(),
+ packages:[
+ { name:"dojo", location:"dojo/dojo" },
+ { name:"dijit", location:"dojo/dijit" },
+ { name:"dojox", location:"dojo/dojox" },
+ { name:"qpid", location:"js/qpid" }
+ ]
+ };
+
+ </script>
+ <script src="dojo/dojo/dojo.js">
+ </script>
+
+ <script>
+ require(["dijit/layout/BorderContainer",
+ "dijit/layout/TabContainer",
+ "dijit/layout/ContentPane",
+ "dijit/TitlePane",
+ "dojo/parser",
+ "qpid/management/treeView",
+ "qpid/management/controller",
+ "qpid/common/footer",
+ "qpid/authorization/sasl"]);
+ </script>
+
+</head>
+<body class="claro">
+
+<div id="pageLayout" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design: 'headline', gutters: false">
+ <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
+ <div id="header" class="header" style="float: left; width: 300px"></div>
+ <div id="login" style="float: right"></div>
+ </div>
+ <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'leading', splitter: true">
+ <div qpid-type="treeView" qpid-props="query: 'rest/structure'" ></div>
+ </div>
+ <div id="managedViews" data-dojo-type="dijit.layout.TabContainer" data-dojo-props="region:'center', tabPosition: 'top'">
+ </div>
+ <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'">
+ <div qpid-type="footer"></div>
+ </div>
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/authorization/sasl.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/authorization/sasl.js
index 152504da86..b4f0728685 100644
--- a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/authorization/sasl.js
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/authorization/sasl.js
@@ -71,7 +71,7 @@ var saslPlain = function saslPlain(user, password)
},
function(error)
{
- if(error.status == 401)
+ if(error.status == 403)
{
alert("Authentication Failed");
}
@@ -127,7 +127,7 @@ var saslCramMD5 = function saslCramMD5(user, password)
},
function(error)
{
- if(error.status == 401)
+ if(error.status == 403)
{
alert("Authentication Failed");
}
@@ -141,7 +141,7 @@ var saslCramMD5 = function saslCramMD5(user, password)
},
function(error)
{
- if(error.status == 401)
+ if(error.status == 403)
{
alert("Authentication Failed");
}
@@ -152,10 +152,45 @@ var saslCramMD5 = function saslCramMD5(user, password)
});
};
+var containsMechanism = function containsMechanism(mechanisms, mech)
+{
+ for (var i = 0; i < mechanisms.length; i++) {
+ if (mechanisms[i] == mech) {
+ return true;
+ }
+ }
+
+ return false;
+};
+
var doAuthenticate = function doAuthenticate()
{
- saslCramMD5(dojo.byId("username").value, dojo.byId("pass").value);
- updateAuthentication();
+ dojo.xhrGet({
+ // The URL of the request
+ url: "rest/sasl",
+ handleAs: "json"
+ }).then(function(data)
+ {
+ var mechMap = data.mechanisms;
+
+ if (containsMechanism(mechMap, "CRAM-MD5"))
+ {
+ saslCramMD5(dojo.byId("username").value, dojo.byId("pass").value);
+ updateAuthentication();
+ }
+ else if (containsMechanism(mechMap, "PLAIN"))
+ {
+ saslPlain(dojo.byId("username").value, dojo.byId("pass").value);
+ updateAuthentication();
+ }
+ else
+ {
+ alert("No supported SASL mechanism offered: " + mechMap);
+ }
+ }
+ );
+
+
};
@@ -170,13 +205,13 @@ var updateAuthentication = function updateAuthentication()
if(data.user)
{
dojo.byId("authenticatedUser").innerHTML = data.user;
- dojo.style(button.domNode, {visibility: 'hidden'});
- dojo.style(usernameSpan, {visibility: 'visible'});
+ dojo.style(button.domNode, {display: 'none'});
+ dojo.style(usernameSpan, {display: 'block'});
}
else
{
- dojo.style(button.domNode, {visibility: 'visible'});
- dojo.style(usernameSpan, {visibility: 'hidden'});
+ dojo.style(button.domNode, {display: 'block'});
+ dojo.style(usernameSpan, {display: 'none'});
}
}
);
@@ -198,13 +233,13 @@ require(["dijit/form/DropDownButton", "dijit/TooltipDialog", "dijit/form/TextBox
dropDown: dialog
});
- usernameSpan = domConstruct.create("span", { innerHTML: '<strong>User: </strong><span id="authenticatedUser"></span>',
- style: { visibility: "hidden" }});
+ usernameSpan = domConstruct.create("span", { innerHTML: '<strong>User: </strong> <span id="authenticatedUser"></span><a href="logout">[logout]</a>',
+ style: { display: "none" }});
var loginDiv = dom.byId("login");
- loginDiv.appendChild(button.domNode);
loginDiv.appendChild(usernameSpan);
+ loginDiv.appendChild(button.domNode);
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js
index 08fdf5c99b..5557c37a2c 100644
--- a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js
@@ -58,10 +58,10 @@ define(["dojo/_base/xhr"],
return exchangeName == null || exchangeName == "" || "<<default>>" == exchangeName || exchangeName.indexOf("amq.") == 0 || exchangeName.indexOf("qpid.") == 0;
};
- util.deleteGridSelections = function(updater, gridName, url, confirmationMessageStart)
+ util.deleteGridSelections = function(updater, grid, url, confirmationMessageStart)
{
- var grid = updater[gridName].grid;
var data = grid.selection.getSelected();
+
if(data.length)
{
var confirmationMessage = null;
@@ -103,7 +103,8 @@ define(["dojo/_base/xhr"],
xhr.del({url: query, sync: true, handleAs: "json"}).then(
function(data)
{
- grid.setQuery({id: "*"});
+ // TODO why query *??
+ //grid.setQuery({id: "*"});
grid.selection.deselectAll();
updater.update();
},
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Exchange.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Exchange.js
index 37bae1ef8e..5a5a6515ef 100644
--- a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Exchange.js
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Exchange.js
@@ -115,7 +115,7 @@ define(["dojo/_base/xhr",
{
util.deleteGridSelections(
this.exchangeUpdater,
- "bindingsGrid",
+ that.exchangeUpdater.bindingsGrid.grid,
"rest/binding/"+ encodeURIComponent(this.getVirtualHostName()) + "/" + encodeURIComponent(this.name),
"Are you sure you want to delete binding for queue");
}
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/GroupProvider.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/GroupProvider.js
new file mode 100644
index 0000000000..4e05f4b0ea
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/GroupProvider.js
@@ -0,0 +1,109 @@
+/*
+ *
+ * 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.
+ *
+ */
+define(["dojo/_base/xhr",
+ "dojo/parser",
+ "dojo/query",
+ "dojo/_base/connect",
+ "qpid/common/properties",
+ "qpid/common/updater",
+ "qpid/common/util",
+ "qpid/common/UpdatableStore",
+ "dojox/grid/EnhancedGrid",
+ "dojox/grid/enhanced/plugins/Pagination",
+ "dojox/grid/enhanced/plugins/IndirectSelection",
+ "dojo/domReady!"],
+ function (xhr, parser, query, connect, properties, updater, util, UpdatableStore, EnhancedGrid) {
+
+ function GroupProvider(name, parent, controller) {
+ this.name = name;
+ this.controller = controller;
+ this.modelObj = { type: "groupprovider", name: name };
+ if(parent) {
+ this.modelObj.parent = {};
+ this.modelObj.parent[ parent.type] = parent;
+ }
+ }
+
+ GroupProvider.prototype.getTitle = function() {
+ return "GroupProvider";
+ };
+
+ GroupProvider.prototype.open = function(contentPane) {
+ var that = this;
+ this.contentPane = contentPane;
+ xhr.get({url: "showGroupProvider.html",
+ sync: true,
+ load: function(data) {
+ contentPane.containerNode.innerHTML = data;
+ parser.parse(contentPane.containerNode);
+
+ that.groupProviderAdapter = new GroupProviderUpdater(contentPane.containerNode, that.modelObj, that.controller);
+
+ updater.add( that.groupProviderAdapter );
+
+ that.groupProviderAdapter.update();
+
+ }});
+ };
+
+ GroupProvider.prototype.close = function() {
+ updater.remove( this.groupProviderAdapter );
+ };
+
+ function GroupProviderUpdater(node, groupProviderObj, controller)
+ {
+ this.controller = controller;
+ this.name = query(".name", node)[0];
+ this.query = "rest/groupprovider/"+encodeURIComponent(groupProviderObj.name);
+
+ var that = this;
+
+ xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"})
+ .then(function(data)
+ {
+ that.groupProviderData = data[0];
+
+ util.flattenStatistics( that.groupProviderData );
+
+ that.updateHeader();
+
+ require(["qpid/management/groupprovider/"+that.groupProviderData.type],
+ function(SpecificProvider) {
+ that.details = new SpecificProvider(node, groupProviderObj, controller);
+ that.details.update();
+ });
+
+ });
+
+ }
+
+ GroupProviderUpdater.prototype.updateHeader = function()
+ {
+ this.name.innerHTML = this.groupProviderData[ "name" ];
+ };
+
+ GroupProviderUpdater.prototype.update = function()
+ {
+ var that = this;
+ };
+
+ return GroupProvider;
+ });
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js
index 957f2381cf..2efc46476d 100644
--- a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/VirtualHost.js
@@ -72,7 +72,7 @@ define(["dojo/_base/xhr",
function(evt){
util.deleteGridSelections(
that.vhostUpdater,
- "queuesGrid",
+ that.vhostUpdater.queuesGrid.grid,
"rest/queue/"+ encodeURIComponent(that.name),
"Are you sure you want to delete queue");
}
@@ -87,7 +87,7 @@ define(["dojo/_base/xhr",
{
util.deleteGridSelections(
that.vhostUpdater,
- "exchangesGrid",
+ that.vhostUpdater.exchangesGrid.grid,
"rest/exchange/"+ encodeURIComponent(that.name),
"Are you sure you want to delete exchange");
}
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js
index 1aa05a5a3c..5d3a666760 100644
--- a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/controller.js
@@ -27,13 +27,17 @@ define(["dojo/dom",
"qpid/management/Queue",
"qpid/management/Connection",
"qpid/management/AuthenticationProvider",
+ "qpid/management/GroupProvider",
+ "qpid/management/group/Group",
"dojo/ready",
"dojo/domReady!"],
- function (dom, registry, ContentPane, Broker, VirtualHost, Exchange, Queue, Connection, AuthProvider, ready) {
+ function (dom, registry, ContentPane, Broker, VirtualHost, Exchange, Queue, Connection, AuthProvider, GroupProvider, Group, ready) {
var controller = {};
var constructors = { broker: Broker, virtualhost: VirtualHost, exchange: Exchange,
- queue: Queue, connection: Connection, authenticationprovider: AuthProvider };
+ queue: Queue, connection: Connection,
+ authenticationprovider: AuthProvider, groupprovider: GroupProvider,
+ group: Group };
var tabDiv = dom.byId("managedViews");
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/group/Group.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/group/Group.js
new file mode 100644
index 0000000000..ea918644e9
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/group/Group.js
@@ -0,0 +1,204 @@
+/*
+ *
+ * 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.
+ *
+ */
+define(["dojo/_base/xhr",
+ "dojo/parser",
+ "dojo/query",
+ "dijit/registry",
+ "dojo/_base/connect",
+ "dojo/_base/event",
+ "dojo/json",
+ "qpid/common/properties",
+ "qpid/common/updater",
+ "qpid/common/util",
+ "qpid/common/formatter",
+ "qpid/common/UpdatableStore",
+ "dojo/store/JsonRest",
+ "dojox/grid/EnhancedGrid",
+ "dojo/data/ObjectStore",
+ "qpid/management/group/addGroupMember",
+ "dojox/grid/enhanced/plugins/Pagination",
+ "dojox/grid/enhanced/plugins/IndirectSelection",
+ "dojo/domReady!"],
+ function (xhr, parser, query, registry, connect, event, json, properties, updater, util, formatter,
+ UpdatableStore, JsonRest, EnhancedGrid, ObjectStore, addGroupMember) {
+
+ function Group(name, parent, controller) {
+ this.name = name;
+ this.controller = controller;
+ this.modelObj = { type: "group", name: name };
+
+ if(parent) {
+ this.modelObj.parent = {};
+ this.modelObj.parent[ parent.type] = parent;
+ }
+ }
+
+ Group.prototype.getGroupName = function()
+ {
+ return this.name;
+ };
+
+
+ Group.prototype.getGroupProviderName = function()
+ {
+ return this.modelObj.parent.groupprovider.name;
+ };
+
+ Group.prototype.getTitle = function()
+ {
+ return "Group: " + this.name;
+ };
+
+ Group.prototype.open = function(contentPane) {
+ var that = this;
+ this.contentPane = contentPane;
+
+ xhr.get({url: "group/showGroup.html",
+ sync: true,
+ load: function(data) {
+ contentPane.containerNode.innerHTML = data;
+ parser.parse(contentPane.containerNode);
+
+ that.groupUpdater = new GroupUpdater(contentPane.containerNode, that, that.controller);
+
+ updater.add( that.groupUpdater );
+
+ that.groupUpdater.update();
+
+ var addGroupMemberButton = query(".addGroupMemberButton", contentPane.containerNode)[0];
+ connect.connect(registry.byNode(addGroupMemberButton), "onClick",
+ function(evt){
+ addGroupMember.show(that.getGroupProviderName(), that.getGroupName())
+ }
+ );
+
+ var removeGroupMemberButton = query(".removeGroupMemberButton", contentPane.containerNode)[0];
+ connect.connect(registry.byNode(removeGroupMemberButton), "onClick",
+ function(evt){
+ util.deleteGridSelections(
+ that.groupUpdater,
+ that.groupUpdater.groupMembersUpdatableStore.grid,
+ "rest/groupmember/"+ encodeURIComponent(that.getGroupProviderName()) +
+ "/" + encodeURIComponent(that.getGroupName()),
+ "Are you sure you want to remove group member");
+ }
+ );
+ }});
+ };
+
+ Group.prototype.close = function() {
+ updater.remove( this.groupUpdater );
+ };
+
+ function GroupUpdater(containerNode, groupObj, controller)
+ {
+ var that = this;
+
+ function findNode(name) {
+ return query("." + name, containerNode)[0];
+ }
+
+ function storeNodes(names)
+ {
+ for(var i = 0; i < names.length; i++) {
+ that[names[i]] = findNode(names[i]);
+ }
+ }
+
+ storeNodes(["name",
+ "state",
+ "durable",
+ "lifetimePolicy",
+ "type"]);
+
+ this.query = "rest/groupmember/"+ encodeURIComponent(groupObj.getGroupProviderName()) + "/" + encodeURIComponent(groupObj.getGroupName());
+
+ xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"}).then(function(data)
+ {
+ that.groupMemberData = data;
+
+ util.flattenStatistics( that.groupMemberData );
+
+ var gridProperties = {
+ keepSelection: true,
+ plugins: {
+ pagination: {
+ pageSizes: ["10", "25", "50", "100"],
+ description: true,
+ sizeSwitch: true,
+ pageStepper: true,
+ gotoButton: true,
+ maxPageStep: 4,
+ position: "bottom"
+ },
+ indirectSelection: true
+
+ }};
+
+ that.groupMembersUpdatableStore = new UpdatableStore(that.groupMemberData, findNode("groupMembers"),
+ [ { name: "Group Member Name", field: "name", width: "100%" }],
+ function(obj)
+ {
+ connect.connect(obj.grid, "onRowDblClick", obj.grid,
+ function(evt){
+
+ });
+ } , gridProperties, EnhancedGrid);
+
+ });
+
+ }
+
+ GroupUpdater.prototype.update = function()
+ {
+
+ var that = this;
+
+ xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"})
+ .then(function(data) {
+ that.groupMemberData = data;
+
+ util.flattenStatistics( that.groupMemberData );
+
+ that.groupMembersUpdatableStore.update(that.groupMemberData);
+ });
+ };
+
+ Group.prototype.deleteGroupMember = function() {
+ if(confirm("Are you sure you want to delete group member'" +this.name+"'?")) {
+ var query = "rest/groupmember/"+ encodeURIComponent(this.getGroupProviderName()) + "/" + encodeURIComponent(this.name);
+ this.success = true
+ var that = this;
+ xhr.del({url: query, sync: true, handleAs: "json"}).then(
+ function(data) {
+ that.contentPane.onClose()
+ that.controller.tabContainer.removeChild(that.contentPane);
+ that.contentPane.destroyRecursive();
+ },
+ function(error) {that.success = false; that.failureReason = error;});
+ if(!this.success ) {
+ alert("Error:" + this.failureReason);
+ }
+ }
+ }
+
+ return Group;
+ });
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/group/addGroupMember.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/group/addGroupMember.js
new file mode 100644
index 0000000000..1861cc6ffe
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/group/addGroupMember.js
@@ -0,0 +1,108 @@
+/*
+ *
+ * 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.
+ *
+ */
+define(["dojo/_base/xhr",
+ "dojo/dom",
+ "dojo/dom-construct",
+ "dojo/_base/window",
+ "dijit/registry",
+ "dojo/parser",
+ "dojo/_base/array",
+ "dojo/_base/event",
+ 'dojo/_base/json',
+ "dijit/form/NumberSpinner", // required by the form
+ /* dojox/ validate resources */
+ "dojox/validate/us", "dojox/validate/web",
+ /* basic dijit classes */
+ "dijit/Dialog",
+ "dijit/form/CheckBox", "dijit/form/Textarea",
+ "dijit/form/FilteringSelect", "dijit/form/TextBox",
+ "dijit/form/ValidationTextBox", "dijit/form/DateTextBox",
+ "dijit/form/TimeTextBox", "dijit/form/Button",
+ "dijit/form/RadioButton", "dijit/form/Form",
+ "dijit/form/DateTextBox",
+ /* basic dojox classes */
+ "dojox/form/BusyButton", "dojox/form/CheckedMultiSelect",
+ "dojo/domReady!"],
+ function (xhr, dom, construct, win, registry, parser, array, event, json) {
+
+ var addGroupMember = {};
+
+ var node = construct.create("div", null, win.body(), "last");
+
+ var convertToGroupMember = function convertToGroupMember(formValues)
+ {
+ var newGroupMember = {};
+ newGroupMember.name = formValues.name;
+ return newGroupMember;
+ };
+
+ xhr.get({url: "group/addGroupMember.html",
+ sync: true,
+ load: function(data) {
+ var theForm;
+ node.innerHTML = data;
+ addGroupMember.dialogNode = dom.byId("addGroupMember");
+ parser.instantiate([addGroupMember.dialogNode]);
+
+ theForm = registry.byId("formAddGroupMember");
+ theForm.on("submit", function(e) {
+
+ event.stop(e);
+ if(theForm.validate()){
+
+ var newGroupMember = convertToGroupMember(theForm.getValues());
+ var that = this;
+ xhr.put({url: "rest/groupmember/"+encodeURIComponent(addGroupMember.groupProvider) +
+ "/" + encodeURIComponent(addGroupMember.group) + "/" + encodeURIComponent(newGroupMember.name), sync: true, handleAs: "json",
+ headers: { "Content-Type": "application/json"},
+ putData: json.toJson(newGroupMember),
+ load: function(x) {that.success = true; },
+ error: function(error) {that.success = false; that.failureReason = error;}});
+
+ if(this.success === true)
+ {
+ registry.byId("addGroupMember").hide();
+ }
+ else
+ {
+ alert("Error:" + this.failureReason);
+ }
+
+ return false;
+
+
+ }else{
+ alert('Form contains invalid data. Please correct first');
+ return false;
+ }
+
+ });
+ }});
+
+ addGroupMember.show = function(groupProvider, group) {
+ addGroupMember.groupProvider = groupProvider;
+ addGroupMember.group = group;
+ registry.byId("formAddGroupMember").reset();
+ registry.byId("addGroupMember").show();
+ };
+
+ return addGroupMember;
+ }); \ No newline at end of file
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/groupprovider/FileGroupManager.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/groupprovider/FileGroupManager.js
new file mode 100644
index 0000000000..44fc9702e2
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/groupprovider/FileGroupManager.js
@@ -0,0 +1,251 @@
+/*
+ *
+ * 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.
+ *
+ */
+define(["dojo/_base/xhr",
+ "dojo/dom",
+ "dojo/parser",
+ "dojo/query",
+ "dojo/dom-construct",
+ "dojo/_base/connect",
+ "dojo/_base/window",
+ "dojo/_base/event",
+ "dojo/_base/json",
+ "dijit/registry",
+ "qpid/common/util",
+ "qpid/common/properties",
+ "qpid/common/updater",
+ "qpid/common/UpdatableStore",
+ "dojox/grid/EnhancedGrid",
+ "dojox/grid/enhanced/plugins/Pagination",
+ "dojox/grid/enhanced/plugins/IndirectSelection",
+ "dojox/validate/us", "dojox/validate/web",
+ "dijit/Dialog",
+ "dijit/form/TextBox",
+ "dijit/form/ValidationTextBox",
+ "dijit/form/TimeTextBox", "dijit/form/Button",
+ "dijit/form/Form",
+ "dijit/form/DateTextBox",
+ "dojo/domReady!"],
+ function (xhr, dom, parser, query, construct, connect, win, event, json, registry, util, properties, updater, UpdatableStore, EnhancedGrid) {
+ function DatabaseGroupManager(containerNode, groupProviderObj, controller) {
+ var node = construct.create("div", null, containerNode, "last");
+ var that = this;
+ this.name = groupProviderObj.name;
+ xhr.get({url: "groupprovider/showFileGroupManager.html",
+ sync: true,
+ load: function(data) {
+ node.innerHTML = data;
+ parser.parse(node);
+
+
+ that.groupDatabaseUpdater= new GroupProviderUpdater(node, groupProviderObj, controller);
+
+ updater.add( that.groupDatabaseUpdater);
+
+ that.groupDatabaseUpdater.update();
+
+
+ }});
+ }
+
+ DatabaseGroupManager.prototype.update = function() {
+ this.groupDatabaseUpdater.update();
+ };
+
+ DatabaseGroupManager.prototype.close = function() {
+ updater.remove( this.groupDatabaseUpdater );
+ };
+
+ function GroupProviderUpdater(node, groupProviderObj, controller)
+ {
+ this.controller = controller;
+ this.query = "rest/groupprovider/"+encodeURIComponent(groupProviderObj.name);
+ this.name = groupProviderObj.name;
+ var that = this;
+
+ xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"})
+ .then(function(data) {
+ that.groupProviderData = data[0];
+
+ util.flattenStatistics( that.groupProviderData );
+
+ var groupDiv = query(".groups")[0];
+
+ var gridProperties = {
+ height: 400,
+ keepSelection: true,
+ plugins: {
+ pagination: {
+ pageSizes: ["10", "25", "50", "100"],
+ description: true,
+ sizeSwitch: true,
+ pageStepper: true,
+ gotoButton: true,
+ maxPageStep: 4,
+ position: "bottom"
+ },
+ indirectSelection: true
+
+ }};
+
+
+ that.groupsGrid =
+ new UpdatableStore(that.groupProviderData.groups, groupDiv,
+ [ { name: "Group Name", field: "name", width: "100%" }
+ ], null, gridProperties, EnhancedGrid);
+
+
+ var addGroupButton = query(".addGroupButton", node)[0];
+ connect.connect(registry.byNode(addGroupButton), "onClick", function(evt){ addGroup.show(groupProviderObj.name) });
+
+ var deleteMessagesButton = query(".deleteGroupButton", node)[0];
+ var deleteWidget = registry.byNode(deleteMessagesButton);
+ connect.connect(deleteWidget, "onClick",
+ function(evt){
+ event.stop(evt);
+ that.deleteGroups();
+ });
+ });
+ }
+
+ GroupProviderUpdater.prototype.deleteGroups = function()
+ {
+ var grid = this.groupsGrid.grid;
+ var data = grid.selection.getSelected();
+ if(data.length) {
+ var that = this;
+ if(confirm("Delete " + data.length + " groups?")) {
+ var i, queryParam;
+ for(i = 0; i<data.length; i++) {
+ if(queryParam) {
+ queryParam += "&";
+ } else {
+ queryParam = "?";
+ }
+
+ queryParam += "id=" + data[i].id;
+ }
+ var query = "rest/group/"+ encodeURIComponent(that.name)
+ + queryParam;
+ that.success = true
+ xhr.del({url: query, sync: true, handleAs: "json"}).then(
+ function(data) {
+ grid.setQuery({id: "*"});
+ grid.selection.deselectAll();
+ that.update();
+ },
+ function(error) {that.success = false; that.failureReason = error;});
+ if(!that.success ) {
+ alert("Error:" + this.failureReason);
+ }
+ }
+}
+ };
+
+ GroupProviderUpdater.prototype.update = function()
+ {
+
+ var that = this;
+
+ xhr.get({url: this.query, sync: properties.useSyncGet, handleAs: "json"})
+ .then(function(data) {
+ that.groupProviderData = data[0];
+ util.flattenStatistics( that.groupProviderData );
+
+ that.groupsGrid.update(that.groupProviderData.groups);
+
+ });
+
+
+ };
+
+ var addGroup = {};
+
+ var node = construct.create("div", null, win.body(), "last");
+
+ var convertToGroup = function convertToGroup(formValues) {
+ var newGroup = {};
+ newGroup.name = formValues.name;
+ for(var propName in formValues)
+ {
+ if(formValues.hasOwnProperty(propName)) {
+ if(formValues[ propName ] !== "") {
+ newGroup[ propName ] = formValues[propName];
+ }
+ }
+ }
+
+ return newGroup;
+ };
+
+
+ xhr.get({url: "groupprovider/addGroup.html",
+ sync: true,
+ load: function(data) {
+ var theForm;
+ node.innerHTML = data;
+ addGroup.dialogNode = dom.byId("addGroup");
+ parser.instantiate([addGroup.dialogNode]);
+
+ var that = this;
+
+ theForm = registry.byId("formAddGroup");
+ theForm.on("submit", function(e) {
+
+ event.stop(e);
+ if(theForm.validate()){
+
+ var newGroup = convertToGroup(theForm.getValues());
+
+
+ var url = "rest/group/"+encodeURIComponent(addGroup.groupProvider) +
+ "/"+encodeURIComponent(newGroup.name);
+
+ xhr.put({url: url, sync: true, handleAs: "json",
+ headers: { "Content-Type": "application/json"},
+ putData: json.toJson(newGroup),
+ load: function(x) {that.success = true; },
+ error: function(error) {that.success = false; that.failureReason = error;}});
+
+ if(that.success === true) {
+ registry.byId("addGroup").hide();
+ } else {
+ alert("Error:" + that.failureReason);
+ }
+
+ return false;
+
+
+ }else{
+ alert('Form contains invalid data. Please correct first');
+ return false;
+ }
+
+ });
+ }});
+
+ addGroup.show = function(groupProvider) {
+ addGroup.groupProvider = groupProvider;
+ registry.byId("formAddGroup").reset();
+ registry.byId("addGroup").show();
+ };
+
+ return DatabaseGroupManager;
+ });
diff --git a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/treeView.js b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/treeView.js
index b1d4abf8c1..59356cfce1 100644
--- a/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/treeView.js
+++ b/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/treeView.js
@@ -273,10 +273,12 @@ define(["dojo/_base/xhr",
controller.show("port", details.port, { type: "virtualhost", name: details.virtualhost, parent: {broker: {type:"broker", name:""}}});
} else if (details.type == 'authenticationprovider') {
controller.show("authenticationprovider", details.authenticationprovider, {broker: {type:"broker", name:""}});
+ } else if (details.type == 'groupprovider') {
+ controller.show("groupprovider", details.groupprovider, {broker: {type:"broker", name:""}});
+ } else if (details.type == 'group') {
+ controller.show("group", details.group, { type: "groupprovider", name: details.groupprovider, parent: {broker: {type:"broker", name:""}}});
}
-
-
};
TreeViewModel.prototype.update = function () {
diff --git a/java/broker-plugins/management-http/src/main/java/resources/management.html b/java/broker-plugins/management-http/src/main/java/resources/management.html
deleted file mode 100644
index a8345a8503..0000000000
--- a/java/broker-plugins/management-http/src/main/java/resources/management.html
+++ /dev/null
@@ -1,92 +0,0 @@
-<!DOCTYPE HTML>
-<!--
- ~ 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.
- -->
-<html lang="en">
-<head>
- <meta charset="utf-8">
- <title>Qpid Management</title>
- <link rel="stylesheet" href="dojo/dojo/resources/dojo.css">
- <link rel="stylesheet" href="dojo/dijit/themes/claro/claro.css">
- <link rel="stylesheet" href="dojo/dojox/grid/resources/claroGrid.css">
- <link rel="stylesheet" href="dojo/dojox/grid/enhanced/resources/claro/EnhancedGrid.css">
- <link rel="stylesheet" href="dojo/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css">
- <link rel="stylesheet" href="css/common.css" media="screen">
- <script>
- function getContextPath()
- {
- var contextPath = "/";
- var documentURL = document.URL;
- var managementPageStart = documentURL.lastIndexOf("/");
- var firstSlashPos = documentURL.indexOf("/", documentURL.indexOf("//") + 2);
- if (managementPageStart > firstSlashPos)
- {
- contextPath = documentURL.substring(firstSlashPos, managementPageStart);
- }
- return contextPath;
- }
-
- var dojoConfig = {
- tlmSiblingOfDojo:false,
- parseOnLoad:true,
- async:true,
- baseUrl: getContextPath(),
- packages:[
- { name:"dojo", location:"dojo/dojo" },
- { name:"dijit", location:"dojo/dijit" },
- { name:"dojox", location:"dojo/dojox" },
- { name:"qpid", location:"js/qpid" }
- ]
- };
-
- </script>
- <script src="dojo/dojo/dojo.js">
- </script>
-
- <script>
- require(["dijit/layout/BorderContainer",
- "dijit/layout/TabContainer",
- "dijit/layout/ContentPane",
- "dijit/TitlePane",
- "dojo/parser",
- "qpid/management/treeView",
- "qpid/management/controller",
- "qpid/common/footer",
- "qpid/authorization/sasl"]);
- </script>
-
-</head>
-<body class="claro">
-
-<div id="pageLayout" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design: 'headline', gutters: false">
- <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
- <div id="header" class="header"></div>
- </div>
- <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'">
- <div id="login"></div>
- </div>
- <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'leading', splitter: true">
- <div qpid-type="treeView" qpid-props="query: 'rest/structure'" ></div>
- </div>
- <div id="managedViews" data-dojo-type="dijit.layout.TabContainer" data-dojo-props="region:'center', tabPosition: 'top'">
- </div>
- <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'">
- <div qpid-type="footer"></div>
- </div>
-</div>
-
-</body>
-</html> \ No newline at end of file
diff --git a/java/broker-plugins/management-http/src/main/java/resources/showGroupProvider.html b/java/broker-plugins/management-http/src/main/java/resources/showGroupProvider.html
new file mode 100644
index 0000000000..914857db5c
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/java/resources/showGroupProvider.html
@@ -0,0 +1,25 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<div class="groupProvider">
+ <span style="">Name:</span><span class="name" style="position:absolute; left:6em"></span>
+ <br/>
+ <span style="">Type:</span><span class="type" style="position:absolute; left:6em"></span>
+</div> \ No newline at end of file
diff --git a/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory b/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory
new file mode 100644
index 0000000000..7ffb9a9013
--- /dev/null
+++ b/java/broker-plugins/management-http/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.qpid.server.management.plugin.HttpManagementFactory
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java
new file mode 100644
index 0000000000..bb4c46826c
--- /dev/null
+++ b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.management.plugin;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class HttpManagementFactoryTest extends QpidTestCase
+{
+ private static final int SESSION_TIMEOUT = 3600;
+
+ private PluginFactory _pluginFactory = new HttpManagementFactory();
+ private Map<String, Object> _attributes = new HashMap<String, Object>();
+ private Broker _broker = mock(Broker.class);
+ private UUID _id = UUID.randomUUID();
+
+ public void testCreateInstanceReturnsNullWhenPluginTypeMissing() throws Exception
+ {
+ assertNull(_pluginFactory.createInstance(_id, _attributes, _broker));
+ }
+ public void testCreateInstanceReturnsNullWhenPluginTypeNotHttp()
+ {
+ _attributes.put(PluginFactory.PLUGIN_TYPE, "notHttp");
+ assertNull(_pluginFactory.createInstance(_id, _attributes, _broker));
+ }
+
+ public void testCreateInstance() throws Exception
+ {
+ _attributes.put(PluginFactory.PLUGIN_TYPE, HttpManagement.PLUGIN_TYPE);
+ _attributes.put(HttpManagement.TIME_OUT, SESSION_TIMEOUT);
+
+ HttpManagement management = (HttpManagement) _pluginFactory.createInstance(_id, _attributes, _broker);
+
+ assertEquals(_broker, management.getBroker());
+ assertEquals(SESSION_TIMEOUT, management.getSessionTimeout());
+ }
+
+}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/Asserts.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/Asserts.java
deleted file mode 100644
index 2595007574..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/Asserts.java
+++ /dev/null
@@ -1,249 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-
-import javax.jms.JMSException;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.server.model.Binding;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.Connection;
-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.Queue;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.VirtualHost;
-
-public class Asserts
-{
- public static final String STATISTICS_ATTRIBUTE = "statistics";
-
- public static void assertVirtualHost(String virtualHostName, Map<String, Object> virtualHost)
- {
- assertNotNull("Virtualhost " + virtualHostName + " data are not found", virtualHost);
- assertAttributesPresent(virtualHost, VirtualHost.AVAILABLE_ATTRIBUTES, VirtualHost.TIME_TO_LIVE,
- VirtualHost.CREATED, VirtualHost.UPDATED, VirtualHost.SUPPORTED_QUEUE_TYPES, VirtualHost.STORE_CONFIGURATION);
-
- assertEquals("Unexpected value of attribute " + VirtualHost.NAME, virtualHostName, virtualHost.get(VirtualHost.NAME));
- assertNotNull("Unexpected value of attribute " + VirtualHost.ID, virtualHost.get(VirtualHost.ID));
- assertEquals("Unexpected value of attribute " + VirtualHost.STATE, State.ACTIVE.name(),
- virtualHost.get(VirtualHost.STATE));
- assertEquals("Unexpected value of attribute " + VirtualHost.DURABLE, Boolean.TRUE,
- virtualHost.get(VirtualHost.DURABLE));
- assertEquals("Unexpected value of attribute " + VirtualHost.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
- virtualHost.get(VirtualHost.LIFETIME_POLICY));
- assertEquals("Unexpected value of attribute " + VirtualHost.DEAD_LETTER_QUEUE_ENABLED, Boolean.FALSE,
- virtualHost.get(VirtualHost.DEAD_LETTER_QUEUE_ENABLED));
-
- @SuppressWarnings("unchecked")
- Collection<String> exchangeTypes = (Collection<String>) virtualHost.get(VirtualHost.SUPPORTED_EXCHANGE_TYPES);
- assertEquals("Unexpected value of attribute " + VirtualHost.SUPPORTED_EXCHANGE_TYPES,
- new HashSet<String>(Arrays.asList("headers", "topic", "direct", "fanout", "management")),
- new HashSet<String>(exchangeTypes));
-
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) virtualHost.get(STATISTICS_ATTRIBUTE);
- Asserts.assertAttributesPresent(statistics, VirtualHost.AVAILABLE_STATISTICS, VirtualHost.BYTES_RETAINED,
- VirtualHost.LOCAL_TRANSACTION_BEGINS, VirtualHost.LOCAL_TRANSACTION_ROLLBACKS,
- VirtualHost.MESSAGES_RETAINED, VirtualHost.STATE_CHANGED, VirtualHost.XA_TRANSACTION_BRANCH_ENDS,
- VirtualHost.XA_TRANSACTION_BRANCH_STARTS, VirtualHost.XA_TRANSACTION_BRANCH_SUSPENDS);
-
- }
-
- public static void assertQueue(String queueName, String queueType, Map<String, Object> queueData)
- {
- assertQueue(queueName, queueType, queueData, null);
- }
-
- public static void assertQueue(String queueName, String queueType, Map<String, Object> queueData, Map<String, Object> expectedAttributes)
- {
- assertNotNull("Queue " + queueName + " is not found!", queueData);
- Asserts.assertAttributesPresent(queueData, Queue.AVAILABLE_ATTRIBUTES, Queue.CREATED, Queue.UPDATED,
- Queue.DESCRIPTION, Queue.TIME_TO_LIVE, Queue.ALTERNATE_EXCHANGE, Queue.OWNER, Queue.NO_LOCAL, Queue.LVQ_KEY,
- Queue.SORT_KEY, Queue.MESSAGE_GROUP_KEY, Queue.MESSAGE_GROUP_DEFAULT_GROUP,
- Queue.MESSAGE_GROUP_SHARED_GROUPS, Queue.PRIORITIES);
-
- assertEquals("Unexpected value of queue attribute " + Queue.NAME, queueName, queueData.get(Queue.NAME));
- assertNotNull("Unexpected value of queue attribute " + Queue.ID, queueData.get(Queue.ID));
- assertEquals("Unexpected value of queue attribute " + Queue.STATE, State.ACTIVE.name(), queueData.get(Queue.STATE));
- assertEquals("Unexpected value of queue attribute " + Queue.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
- queueData.get(Queue.LIFETIME_POLICY));
- assertEquals("Unexpected value of queue attribute " + Queue.TYPE, queueType, queueData.get(Queue.TYPE));
- if (expectedAttributes == null)
- {
- assertEquals("Unexpected value of queue attribute " + Queue.EXCLUSIVE, Boolean.FALSE, queueData.get(Queue.EXCLUSIVE));
- assertEquals("Unexpected value of queue attribute " + Queue.MAXIMUM_DELIVERY_ATTEMPTS, 0,
- queueData.get(Queue.MAXIMUM_DELIVERY_ATTEMPTS));
- assertEquals("Unexpected value of queue attribute " + Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES, 0,
- queueData.get(Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES));
- assertEquals("Unexpected value of queue attribute " + Queue.QUEUE_FLOW_RESUME_SIZE_BYTES, 0,
- queueData.get(Queue.QUEUE_FLOW_RESUME_SIZE_BYTES));
- assertEquals("Unexpected value of queue attribute " + Queue.QUEUE_FLOW_STOPPED, Boolean.FALSE,
- queueData.get(Queue.QUEUE_FLOW_STOPPED));
- }
- else
- {
- for (Map.Entry<String, Object> attribute : expectedAttributes.entrySet())
- {
- assertEquals("Unexpected value of " + queueName + " queue attribute " + attribute.getKey(),
- attribute.getValue(), queueData.get(attribute.getKey()));
- }
- }
-
- assertNotNull("Unexpected value of queue attribute statistics", queueData.get(Asserts.STATISTICS_ATTRIBUTE));
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) queueData.get(Asserts.STATISTICS_ATTRIBUTE);
- Asserts.assertAttributesPresent(statistics, Queue.AVAILABLE_STATISTICS, Queue.DISCARDS_TTL_BYTES,
- Queue.DISCARDS_TTL_MESSAGES, Queue.STATE_CHANGED);
- }
-
- public static void assertAttributesPresent(Map<String, Object> data, String[] attributes)
- {
- for (String name : attributes)
- {
- assertNotNull("Attribute " + name + " is not present", data.get(name));
- }
- }
-
- public static void assertAttributesPresent(Map<String, Object> data, Collection<String> attributes,
- String... unsupportedAttributes)
- {
- for (String name : attributes)
- {
- boolean unsupported = false;
- for (String unsupportedAttribute : unsupportedAttributes)
- {
- if (unsupportedAttribute.equals(name))
- {
- unsupported = true;
- break;
- }
- }
- if (unsupported)
- {
- continue;
- }
- assertNotNull("Attribute " + name + " is not present", data.get(name));
- }
- }
-
- public static void assertConnection(Map<String, Object> connectionData, AMQConnection connection) throws JMSException
- {
- assertNotNull("Unexpected connection data", connectionData);
- assertAttributesPresent(connectionData, Connection.AVAILABLE_ATTRIBUTES, Connection.STATE, Connection.DURABLE,
- Connection.LIFETIME_POLICY, Connection.TIME_TO_LIVE, Connection.CREATED, Connection.UPDATED,
- Connection.INCOMING, Connection.REMOTE_PROCESS_NAME, Connection.REMOTE_PROCESS_PID,
- Connection.LOCAL_ADDRESS, Connection.PROPERTIES);
-
- assertEquals("Unexpected value of connection attribute " + Connection.SESSION_COUNT_LIMIT,
- (int) connection.getMaximumChannelCount(), connectionData.get(Connection.SESSION_COUNT_LIMIT));
- assertEquals("Unexpected value of connection attribute " + Connection.CLIENT_ID, "clientid",
- connectionData.get(Connection.CLIENT_ID));
- assertEquals("Unexpected value of connection attribute " + Connection.PRINCIPAL, "guest",
- connectionData.get(Connection.PRINCIPAL));
-
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) connectionData.get(STATISTICS_ATTRIBUTE);
- assertAttributesPresent(statistics, Connection.AVAILABLE_STATISTICS, Connection.LOCAL_TRANSACTION_BEGINS,
- Connection.LOCAL_TRANSACTION_ROLLBACKS, Connection.STATE_CHANGED, Connection.XA_TRANSACTION_BRANCH_ENDS,
- Connection.XA_TRANSACTION_BRANCH_STARTS, Connection.XA_TRANSACTION_BRANCH_SUSPENDS);
- assertEquals("Unexpected value of connection statistics attribute " + Connection.SESSION_COUNT, 1,
- statistics.get(Connection.SESSION_COUNT));
- }
-
- public static void assertPortAttributes(Map<String, Object> port)
- {
- assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED);
-
- assertNotNull("Unexpected value of attribute " + Port.ID, port.get(Port.ID));
- assertEquals("Unexpected value of attribute " + Port.DURABLE, Boolean.FALSE, port.get(Port.DURABLE));
- assertEquals("Unexpected value of attribute " + Port.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
- port.get(Broker.LIFETIME_POLICY));
- assertEquals("Unexpected value of attribute " + Port.STATE, State.ACTIVE.name(), port.get(Port.STATE));
- assertEquals("Unexpected value of attribute " + Port.TIME_TO_LIVE, 0, port.get(Port.TIME_TO_LIVE));
- assertNotNull("Unexpected value of attribute " + Port.BINDING_ADDRESS, port.get(Port.BINDING_ADDRESS));
- assertNotNull("Unexpected value of attribute " + Port.PROTOCOLS, port.get(Port.PROTOCOLS));
- assertNotNull("Unexpected value of attribute " + Port.NAME, port.get(Port.NAME));
-
- @SuppressWarnings("unchecked")
- Collection<String> transports = (Collection<String>) port.get(Port.TRANSPORTS);
- assertEquals("Unexpected value of attribute " + Port.TRANSPORTS, new HashSet<String>(Arrays.asList("TCP")),
- new HashSet<String>(transports));
- }
-
- public static void assertDurableExchange(String exchangeName, String type, Map<String, Object> exchangeData)
- {
- assertExchange(exchangeName, type, exchangeData);
-
- assertEquals("Unexpected value of exchange attribute " + Exchange.DURABLE, Boolean.TRUE,
- exchangeData.get(Exchange.DURABLE));
- }
-
- public static void assertExchange(String exchangeName, String type, Map<String, Object> exchangeData)
- {
- assertNotNull("Exchange " + exchangeName + " is not found!", exchangeData);
- assertAttributesPresent(exchangeData, Exchange.AVAILABLE_ATTRIBUTES, Exchange.CREATED, Exchange.UPDATED,
- Exchange.ALTERNATE_EXCHANGE, Exchange.TIME_TO_LIVE);
-
- assertEquals("Unexpected value of exchange attribute " + Exchange.NAME, exchangeName,
- exchangeData.get(Exchange.NAME));
- assertNotNull("Unexpected value of exchange attribute " + Exchange.ID, exchangeData.get(VirtualHost.ID));
- assertEquals("Unexpected value of exchange attribute " + Exchange.STATE, State.ACTIVE.name(),
- exchangeData.get(Exchange.STATE));
-
- assertEquals("Unexpected value of exchange attribute " + Exchange.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
- exchangeData.get(Exchange.LIFETIME_POLICY));
- assertEquals("Unexpected value of exchange attribute " + Exchange.TYPE, type, exchangeData.get(Exchange.TYPE));
- assertNotNull("Unexpected value of exchange attribute statistics", exchangeData.get(STATISTICS_ATTRIBUTE));
-
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) exchangeData.get(STATISTICS_ATTRIBUTE);
- assertAttributesPresent(statistics, Exchange.AVAILABLE_STATISTICS, Exchange.STATE_CHANGED, Exchange.PRODUCER_COUNT);
- }
-
- public static void assertBinding(String bindingName, String queueName, String exchange, Map<String, Object> binding)
- {
- assertNotNull("Binding map should not be null", binding);
- assertAttributesPresent(binding, Binding.AVAILABLE_ATTRIBUTES, Binding.STATE, Binding.TIME_TO_LIVE,
- Binding.CREATED, Binding.UPDATED);
-
- assertEquals("Unexpected binding attribute " + Binding.NAME, bindingName, binding.get(Binding.NAME));
- assertEquals("Unexpected binding attribute " + Binding.QUEUE, queueName, binding.get(Binding.QUEUE));
- assertEquals("Unexpected binding attribute " + Binding.EXCHANGE, exchange, binding.get(Binding.EXCHANGE));
- assertEquals("Unexpected binding attribute " + Binding.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
- binding.get(Binding.LIFETIME_POLICY));
- }
-
- public static void assertBinding(String queueName, String exchange, Map<String, Object> binding)
- {
- assertBinding(queueName, queueName, exchange, binding);
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/AuthenticationProviderRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/AuthenticationProviderRestTest.java
deleted file mode 100644
index 5e6d9a998a..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/AuthenticationProviderRestTest.java
+++ /dev/null
@@ -1,73 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.qpid.server.model.AuthenticationProvider;
-import org.apache.qpid.server.model.LifetimePolicy;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.User;
-
-public class AuthenticationProviderRestTest extends QpidRestTestCase
-{
-
- public void testGet() throws Exception
- {
- List<Map<String, Object>> providerDetails = getJsonAsList("/rest/authenticationprovider");
- assertNotNull("Providers details cannot be null", providerDetails);
- assertEquals("Unexpected number of providers", 1, providerDetails.size());
- for (Map<String, Object> provider : providerDetails)
- {
- assertProvider("PrincipalDatabaseAuthenticationManager", provider);
- Map<String, Object> data = getJsonAsSingletonList("/rest/authenticationprovider/"
- + provider.get(AuthenticationProvider.NAME));
- assertNotNull("Cannot load data for " + provider.get(AuthenticationProvider.NAME), data);
- assertProvider("PrincipalDatabaseAuthenticationManager", data);
- }
- }
-
- private void assertProvider(String type, Map<String, Object> provider)
- {
- Asserts.assertAttributesPresent(provider, AuthenticationProvider.AVAILABLE_ATTRIBUTES,
- AuthenticationProvider.CREATED, AuthenticationProvider.UPDATED, AuthenticationProvider.DESCRIPTION,
- AuthenticationProvider.TIME_TO_LIVE);
- assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.STATE, State.ACTIVE.name(),
- provider.get(AuthenticationProvider.STATE));
- assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.LIFETIME_POLICY,
- LifetimePolicy.PERMANENT.name(), provider.get(AuthenticationProvider.LIFETIME_POLICY));
- assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.DURABLE, Boolean.TRUE,
- provider.get(AuthenticationProvider.DURABLE));
- assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.TYPE, type,
- provider.get(AuthenticationProvider.TYPE));
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> users = (List<Map<String, Object>>) provider.get("users");
- assertNotNull("Users are not found", users);
- assertTrue("Unexpected number of users", users.size() > 1);
- for (Map<String, Object> user : users)
- {
- assertNotNull("Attribute " + User.ID, user.get(User.ID));
- assertNotNull("Attribute " + User.NAME, user.get(User.NAME));
- }
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BindingRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BindingRestTest.java
deleted file mode 100644
index 1ed0d97185..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BindingRestTest.java
+++ /dev/null
@@ -1,129 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.net.HttpURLConnection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.qpid.server.model.Binding;
-
-public class BindingRestTest extends QpidRestTestCase
-{
-
- public void testGetAllBindings() throws Exception
- {
- List<Map<String, Object>> bindings = getJsonAsList("/rest/binding");
- assertNotNull("Bindings cannot be null", bindings);
- assertTrue("Unexpected number of bindings", bindings.size() >= EXPECTED_HOSTS.length * EXPECTED_QUEUES.length);
- for (Map<String, Object> binding : bindings)
- {
- Asserts.assertBinding((String) binding.get(Binding.NAME), (String) binding.get(Binding.EXCHANGE), binding);
- }
- }
-
- public void testGetVirtualHostBindings() throws Exception
- {
- List<Map<String, Object>> bindings = getJsonAsList("/rest/binding/test");
- assertNotNull("Bindings cannot be null", bindings);
- assertEquals("Unexpected number of bindings", EXPECTED_QUEUES.length * 2, bindings.size());
- for (String queueName : EXPECTED_QUEUES)
- {
- Map<String, Object> searchAttributes = new HashMap<String, Object>();
- searchAttributes.put(Binding.NAME, queueName);
- searchAttributes.put(Binding.EXCHANGE, "amq.direct");
-
- Map<String, Object> binding = find(searchAttributes, bindings);
- Asserts.assertBinding(queueName, "amq.direct", binding);
-
- searchAttributes.put(Binding.EXCHANGE, "<<default>>");
-
- binding = find(searchAttributes, bindings);
- Asserts.assertBinding(queueName, "<<default>>", binding);
- }
- }
-
- public void testGetVirtualHostExchangeBindings() throws Exception
- {
- List<Map<String, Object>> bindings = getJsonAsList("/rest/binding/test/amq.direct");
- assertNotNull("Bindings cannot be null", bindings);
- assertEquals("Unexpected number of bindings", EXPECTED_QUEUES.length, bindings.size());
- for (String queueName : EXPECTED_QUEUES)
- {
- Map<String, Object> binding = find(Binding.NAME, queueName, bindings);
- Asserts.assertBinding(queueName, "amq.direct", binding);
- }
- }
-
- public void testGetVirtualHostExchangeQueueBindings() throws Exception
- {
- List<Map<String, Object>> bindings = getJsonAsList("/rest/binding/test/amq.direct/queue");
- assertNotNull("Bindings cannot be null", bindings);
- assertEquals("Unexpected number of bindings", 1, bindings.size());
- Asserts.assertBinding("queue", "amq.direct", bindings.get(0));
- }
-
-
- public void testDeleteBinding() throws Exception
- {
- List<Map<String, Object>> bindings = getJsonAsList("/rest/binding/test/amq.direct/queue/queue");
- assertEquals("Unexpected number of bindings", 1, bindings.size());
- Asserts.assertBinding("queue", "amq.direct", bindings.get(0));
-
- HttpURLConnection connection = openManagementConection("/rest/binding/test/amq.direct/queue/queue", "DELETE");
- connection.connect();
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
-
- bindings = getJsonAsList("/rest/binding/test/amq.direct/queue/queue");
- assertEquals("Binding should be deleted", 0, bindings.size());
- }
-
- public void testDeleteBindingById() throws Exception
- {
- Map<String, Object> binding = getJsonAsSingletonList("/rest/binding/test/amq.direct/queue");
- HttpURLConnection connection = openManagementConection("/rest/binding/test/amq.direct?id=" + binding.get(Binding.ID), "DELETE");
- connection.connect();
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
- List<Map<String, Object>> bindings = getJsonAsList("/rest/binding/test/amq.direct/queue");
- assertEquals("Binding should be deleted", 0, bindings.size());
- }
-
- public void testCreateBinding() throws Exception
- {
- String bindingName = getTestName();
- Map<String, Object> bindingData = new HashMap<String, Object>();
- bindingData.put(Binding.NAME, bindingName);
- bindingData.put(Binding.QUEUE, "queue");
- bindingData.put(Binding.EXCHANGE, "amq.direct");
-
- HttpURLConnection connection = openManagementConection("/rest/binding/test/amq.direct/queue/" + bindingName, "PUT");
- connection.connect();
- writeJsonRequest(connection, bindingData);
- int responseCode = connection.getResponseCode();
- connection.disconnect();
- assertEquals("Unexpected response code", 201, responseCode);
- Map<String, Object> binding = getJsonAsSingletonList("/rest/binding/test/amq.direct/queue/" + bindingName);
-
- Asserts.assertBinding(bindingName, "queue", "amq.direct", binding);
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BrokerRestHttpsTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BrokerRestHttpsTest.java
deleted file mode 100644
index 4bbe9155cd..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BrokerRestHttpsTest.java
+++ /dev/null
@@ -1,86 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Map;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSocketFactory;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.server.model.Broker;
-
-public class BrokerRestHttpsTest extends QpidRestTestCase
-{
- private static final String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks";
- private static final String TRUSTSTORE_PASSWORD = "password";
-
- @Override
- public void setUp() throws Exception
- {
- setSystemProperty("javax.net.debug", "ssl");
- super.setUp();
- setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
- setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
- }
-
- @Override
- protected void customizeConfiguration() throws ConfigurationException, IOException
- {
- setConfigurationProperty("management.enabled", "true");
- setConfigurationProperty("management.http.enabled", "false");
- setConfigurationProperty("management.https.enabled", "true");
- setConfigurationProperty("management.https.port", Integer.toString(getHttpPort()));
- }
-
- @Override
- protected String getHostName()
- {
- return "localhost";
- }
-
- @Override
- protected String getProtocol()
- {
- return "https";
- }
-
- @Override
- protected HttpURLConnection openManagementConection(String path) throws IOException
- {
- URL url = getManagementURL(path);
- HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
- ((HttpsURLConnection) httpCon).setSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());
- httpCon.setDoOutput(true);
- return httpCon;
- }
-
- public void testGetWithHttps() throws Exception
- {
- Map<String, Object> brokerDetails = getJsonAsSingletonList("/rest/broker");
-
- Asserts.assertAttributesPresent(brokerDetails, Broker.AVAILABLE_ATTRIBUTES, Broker.BYTES_RETAINED,
- Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES, Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED);
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BrokerRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BrokerRestTest.java
deleted file mode 100644
index f2970e2ba9..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/BrokerRestTest.java
+++ /dev/null
@@ -1,118 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.qpid.common.QpidProperties;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.LifetimePolicy;
-import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.VirtualHost;
-
-public class BrokerRestTest extends QpidRestTestCase
-{
-
- private static final String BROKER_AUTHENTICATIONPROVIDERS_ATTRIBUTE = "authenticationproviders";
- private static final String BROKER_PORTS_ATTRIBUTE = "ports";
- private static final String BROKER_VIRTUALHOSTS_ATTRIBUTE = "virtualhosts";
- private static final String BROKER_STATISTICS_ATTRIBUTE = "statistics";
-
- public void testGet() throws Exception
- {
- Map<String, Object> brokerDetails = getJsonAsSingletonList("/rest/broker");
-
- assertBrokerAttributes(brokerDetails);
-
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) brokerDetails.get(BROKER_STATISTICS_ATTRIBUTE);
- Asserts.assertAttributesPresent(statistics, new String[]{ "bytesIn", "messagesOut", "bytesOut", "messagesIn" });
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) brokerDetails.get(BROKER_VIRTUALHOSTS_ATTRIBUTE);
- assertEquals("Unexpected number of virtual hosts", 3, virtualhosts.size());
-
- Asserts.assertVirtualHost("development", find(VirtualHost.NAME, "development", virtualhosts));
- Asserts.assertVirtualHost("localhost", find(VirtualHost.NAME, "localhost", virtualhosts));
- Asserts.assertVirtualHost("test", find(VirtualHost.NAME, "test", virtualhosts));
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> ports = (List<Map<String, Object>>) brokerDetails.get(BROKER_PORTS_ATTRIBUTE);
- assertEquals("Unexpected number of ports", 2, ports.size());
-
- for (Map<String, Object> port : ports)
- {
- Asserts.assertPortAttributes(port);
- }
-
- String bindingAddress = (String)ports.get(0).get(Port.BINDING_ADDRESS);
-
- Map<String, Object> amqpPort = find(Port.NAME, bindingAddress + ":" + getPort(), ports);
- Map<String, Object> httpPort = find(Port.NAME, bindingAddress + ":" + getHttpPort(), ports);
-
- assertNotNull("Cannot find AMQP port", amqpPort);
- assertNotNull("Cannot find HTTP port", httpPort);
-
- @SuppressWarnings("unchecked")
- Collection<String> port1Protocols = (Collection<String>) amqpPort.get(Port.PROTOCOLS);
- assertFalse("AMQP protocol list cannot contain HTTP", port1Protocols.contains("HTTP"));
-
- @SuppressWarnings("unchecked")
- Collection<String> port2Protocols = (Collection<String>) httpPort.get(Port.PROTOCOLS);
- assertEquals("Unexpected value of attribute " + Port.PROTOCOLS, new HashSet<String>(Arrays.asList("HTTP")),
- new HashSet<String>(port2Protocols));
- }
-
- protected void assertBrokerAttributes(Map<String, Object> brokerDetails)
- {
- Asserts.assertAttributesPresent(brokerDetails, Broker.AVAILABLE_ATTRIBUTES,
- Broker.BYTES_RETAINED, Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES,
- Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED);
-
- assertEquals("Unexpected value of attribute " + Broker.BUILD_VERSION, QpidProperties.getBuildVersion(),
- brokerDetails.get(Broker.BUILD_VERSION));
- assertEquals("Unexpected value of attribute " + Broker.OPERATING_SYSTEM, System.getProperty("os.name") + " "
- + System.getProperty("os.version") + " " + System.getProperty("os.arch"),
- brokerDetails.get(Broker.OPERATING_SYSTEM));
- assertEquals(
- "Unexpected value of attribute " + Broker.PLATFORM,
- System.getProperty("java.vendor") + " "
- + System.getProperty("java.runtime.version", System.getProperty("java.version")),
- brokerDetails.get(Broker.PLATFORM));
- assertEquals("Unexpected value of attribute " + Broker.DURABLE, Boolean.TRUE, brokerDetails.get(Broker.DURABLE));
- assertEquals("Unexpected value of attribute " + Broker.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
- brokerDetails.get(Broker.LIFETIME_POLICY));
- assertEquals("Unexpected value of attribute " + Broker.NAME, "Broker", brokerDetails.get(Broker.NAME));
- assertEquals("Unexpected value of attribute " + Broker.STATE, State.ACTIVE.name(), brokerDetails.get(Broker.STATE));
-
- assertNotNull("Unexpected value of attribute " + Broker.ID, brokerDetails.get(Broker.ID));
- assertNotNull("Unexpected value of attribute statistics", brokerDetails.get(BROKER_STATISTICS_ATTRIBUTE));
- assertNotNull("Unexpected value of attribute virtualhosts", brokerDetails.get(BROKER_VIRTUALHOSTS_ATTRIBUTE));
- assertNotNull("Unexpected value of attribute ports", brokerDetails.get(BROKER_PORTS_ATTRIBUTE));
- assertNotNull("Unexpected value of attribute authenticationproviders", brokerDetails.get(BROKER_AUTHENTICATIONPROVIDERS_ATTRIBUTE));
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConnectionRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConnectionRestTest.java
deleted file mode 100644
index 3661b94a7c..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConnectionRestTest.java
+++ /dev/null
@@ -1,213 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.io.IOException;
-import java.net.URLDecoder;
-import java.util.List;
-import java.util.Map;
-
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.server.model.Connection;
-import org.apache.qpid.server.model.Session;
-
-public class ConnectionRestTest extends QpidRestTestCase
-{
- /**
- * Message number to publish into queue
- */
- private static final int MESSAGE_NUMBER = 5;
- private static final int MESSAGE_SIZE = 6;
-
- private static final String SESSIONS_ATTRIBUTE = "sessions";
-
- private javax.jms.Connection _connection;
- private javax.jms.Session _session;
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- _connection = getConnection();
- _session = _connection.createSession(true, javax.jms.Session.SESSION_TRANSACTED);
- String queueName = getTestQueueName();
- Destination queue = _session.createQueue(queueName);
- MessageConsumer consumer = _session.createConsumer(queue);
- MessageProducer producer = _session.createProducer(queue);
- _connection.start();
-
- // send messages
- for (int i = 0; i < MESSAGE_NUMBER; i++)
- {
- producer.send(_session.createTextMessage("Test-" + i));
- }
- _session.commit();
-
- Message m = consumer.receive(1000l);
- assertNotNull("Message was not received", m);
- _session.commit();
-
- // receive the rest of messages for rollback
- for (int i = 0; i < MESSAGE_NUMBER - 1; i++)
- {
- m = consumer.receive(1000l);
- assertNotNull("Message was not received", m);
- }
- _session.rollback();
-
- // receive them again
- for (int i = 0; i < MESSAGE_NUMBER - 1; i++)
- {
- m = consumer.receive(1000l);
- assertNotNull("Message was not received", m);
- }
- }
-
- public void testGetAllConnections() throws Exception
- {
- List<Map<String, Object>> connections = getJsonAsList("/rest/connection");
- assertEquals("Unexpected number of connections", 1, connections.size());
- Asserts.assertConnection(connections.get(0), (AMQConnection) _connection);
- }
-
- public void testGetVirtualHostConnections() throws Exception
- {
- List<Map<String, Object>> connections = getJsonAsList("/rest/connection/test");
- assertEquals("Unexpected number of connections", 1, connections.size());
- Asserts.assertConnection(connections.get(0), (AMQConnection) _connection);
- }
-
- public void testGetConnectionByName() throws Exception
- {
- // get connection name
- String connectionName = getConnectionName();
-
- Map<String, Object> connectionDetails = getJsonAsSingletonList("/rest/connection/test/"
- + URLDecoder.decode(connectionName, "UTF-8"));
- assertConnection(connectionDetails);
- }
-
- public void testGetAllSessions() throws Exception
- {
- List<Map<String, Object>> sessions = getJsonAsList("/rest/session");
- assertEquals("Unexpected number of sessions", 1, sessions.size());
- assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
- }
-
- public void testGetVirtualHostSessions() throws Exception
- {
- List<Map<String, Object>> sessions = getJsonAsList("/rest/session/test");
- assertEquals("Unexpected number of sessions", 1, sessions.size());
- assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
- }
-
- public void testGetConnectionSessions() throws Exception
- {
- // get connection name
- String connectionName = getConnectionName();
-
- List<Map<String, Object>> sessions = getJsonAsList("/rest/session/test/"
- + URLDecoder.decode(connectionName, "UTF-8"));
- assertEquals("Unexpected number of sessions", 1, sessions.size());
- assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
- }
-
- public void testGetSessionByName() throws Exception
- {
- // get connection name
- String connectionName = getConnectionName();
-
- List<Map<String, Object>> sessions = getJsonAsList("/rest/session/test/"
- + URLDecoder.decode(connectionName, "UTF-8") + "/" + ((AMQSession<?, ?>) _session).getChannelId());
- assertEquals("Unexpected number of sessions", 1, sessions.size());
- assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
- }
-
- private void assertConnection(Map<String, Object> connectionDetails) throws JMSException
- {
- Asserts.assertConnection(connectionDetails, (AMQConnection) _connection);
-
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) connectionDetails.get(Asserts.STATISTICS_ATTRIBUTE);
- assertEquals("Unexpected value of connection statistics attribute " + Connection.BYTES_IN, MESSAGE_NUMBER
- * MESSAGE_SIZE, statistics.get(Connection.BYTES_IN));
- assertEquals("Unexpected value of connection statistics attribute " + Connection.BYTES_OUT, MESSAGE_SIZE
- + ((MESSAGE_NUMBER - 1) * MESSAGE_SIZE) * 2, statistics.get(Connection.BYTES_OUT));
- assertEquals("Unexpected value of connection statistics attribute " + Connection.MESSAGES_IN, MESSAGE_NUMBER,
- statistics.get(Connection.MESSAGES_IN));
- assertEquals("Unexpected value of connection statistics attribute " + Connection.MESSAGES_OUT,
- MESSAGE_NUMBER * 2 - 1, statistics.get(Connection.MESSAGES_OUT));
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> sessions = (List<Map<String, Object>>) connectionDetails.get(SESSIONS_ATTRIBUTE);
- assertNotNull("Sessions cannot be found", sessions);
- assertEquals("Unexpected number of sessions", 1, sessions.size());
- assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
- }
-
- private void assertSession(Map<String, Object> sessionData, AMQSession<?, ?> session)
- {
- assertNotNull("Session map cannot be null", sessionData);
- Asserts.assertAttributesPresent(sessionData, Session.AVAILABLE_ATTRIBUTES, Session.STATE, Session.DURABLE,
- Session.LIFETIME_POLICY, Session.TIME_TO_LIVE, Session.CREATED, Session.UPDATED);
- assertEquals("Unexpecte value of attribute " + Session.NAME, session.getChannelId() + "",
- sessionData.get(Session.NAME));
- assertEquals("Unexpecte value of attribute " + Session.PRODUCER_FLOW_BLOCKED, Boolean.FALSE,
- sessionData.get(Session.PRODUCER_FLOW_BLOCKED));
- assertEquals("Unexpecte value of attribute " + Session.CHANNEL_ID, session.getChannelId(),
- sessionData.get(Session.CHANNEL_ID));
-
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) sessionData.get(Asserts.STATISTICS_ATTRIBUTE);
- Asserts.assertAttributesPresent(statistics, Session.AVAILABLE_STATISTICS, Session.BYTES_IN, Session.BYTES_OUT,
- Session.STATE_CHANGED, Session.UNACKNOWLEDGED_BYTES, Session.LOCAL_TRANSACTION_OPEN,
- Session.XA_TRANSACTION_BRANCH_ENDS, Session.XA_TRANSACTION_BRANCH_STARTS,
- Session.XA_TRANSACTION_BRANCH_SUSPENDS);
-
- assertEquals("Unexpecte value of statistic attribute " + Session.UNACKNOWLEDGED_MESSAGES, MESSAGE_NUMBER - 1,
- statistics.get(Session.UNACKNOWLEDGED_MESSAGES));
- assertEquals("Unexpecte value of statistic attribute " + Session.LOCAL_TRANSACTION_BEGINS, 4,
- statistics.get(Session.LOCAL_TRANSACTION_BEGINS));
- assertEquals("Unexpecte value of statistic attribute " + Session.LOCAL_TRANSACTION_ROLLBACKS, 1,
- statistics.get(Session.LOCAL_TRANSACTION_ROLLBACKS));
- assertEquals("Unexpecte value of statistic attribute " + Session.CONSUMER_COUNT, 1,
- statistics.get(Session.CONSUMER_COUNT));
- }
-
- private String getConnectionName() throws IOException
- {
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> connections = (List<Map<String, Object>>) hostDetails
- .get(VirtualHostRestTest.VIRTUALHOST_CONNECTIONS_ATTRIBUTE);
- assertEquals("Unexpected number of connections", 1, connections.size());
- Map<String, Object> connection = connections.get(0);
- String connectionName = (String) connection.get(Connection.NAME);
- return connectionName;
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ExchangeRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ExchangeRestTest.java
deleted file mode 100644
index 4904d2adf3..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ExchangeRestTest.java
+++ /dev/null
@@ -1,87 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.net.URLDecoder;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.qpid.server.model.Binding;
-import org.apache.qpid.server.model.Exchange;
-
-public class ExchangeRestTest extends QpidRestTestCase
-{
- public void testGet() throws Exception
- {
- List<Map<String, Object>> exchanges = getJsonAsList("/rest/exchange");
- assertNotNull("Exchanges cannot be null", exchanges);
- assertTrue("Unexpected number of exchanges", exchanges.size() >= EXPECTED_HOSTS.length * EXPECTED_EXCHANGES.length);
- for (Map<String, Object> exchange : exchanges)
- {
- Asserts.assertExchange((String) exchange.get(Exchange.NAME), (String) exchange.get(Exchange.TYPE), exchange);
- }
- }
-
- public void testGetHostExchanges() throws Exception
- {
- List<Map<String, Object>> exchanges = getJsonAsList("/rest/exchange/test");
- assertNotNull("Users cannot be null", exchanges);
- assertEquals("Unexpected number of exchanges", 6, EXPECTED_EXCHANGES.length);
- for (String exchangeName : EXPECTED_EXCHANGES)
- {
- Map<String, Object> exchange = find(Exchange.NAME, exchangeName, exchanges);
- assertExchange(exchangeName, exchange);
- }
- }
-
- public void testGetHostExchangeByName() throws Exception
- {
- for (String exchangeName : EXPECTED_EXCHANGES)
- {
- Map<String, Object> exchange = getJsonAsSingletonList("/rest/exchange/test/"
- + URLDecoder.decode(exchangeName, "UTF-8"));
- assertExchange(exchangeName, exchange);
- }
- }
-
- private void assertExchange(String exchangeName, Map<String, Object> exchange)
- {
- assertNotNull("Exchange with name " + exchangeName + " is not found", exchange);
- String type = (String) exchange.get(Exchange.TYPE);
- Asserts.assertExchange(exchangeName, type, exchange);
- if ("direct".equals(type))
- {
- assertBindings(exchange);
- }
- }
-
- private void assertBindings(Map<String, Object> exchange)
- {
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> bindings = (List<Map<String, Object>>) exchange.get("bindings");
- for (String queueName : EXPECTED_QUEUES)
- {
- Map<String, Object> binding = find(Binding.NAME, queueName, bindings);
- Asserts.assertBinding(queueName, (String) exchange.get(Exchange.NAME), binding);
- }
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsRestTest.java
deleted file mode 100644
index c64fd6e1da..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsRestTest.java
+++ /dev/null
@@ -1,42 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.util.List;
-import java.util.Map;
-
-public class LogRecordsRestTest extends QpidRestTestCase
-{
- public void testGet() throws Exception
- {
- List<Map<String, Object>> logs = getJsonAsList("/rest/logrecords");
- assertNotNull("Logs data cannot be null", logs);
- assertTrue("Logs are not found", logs.size() > 0);
- Map<String, Object> record = find("message", "[Broker] BRK-1004 : Qpid Broker Ready", logs);
-
- assertNotNull("BRK-1004 message is not found", record);
- assertNotNull("Message id cannot be null", record.get("id"));
- assertNotNull("Message timestamp cannot be null", record.get("timestamp"));
- assertEquals("Unexpected log level", "INFO", record.get("level"));
- assertEquals("Unexpected thread", "main", record.get("thread"));
- assertEquals("Unexpected logger", "qpid.message.broker.ready", record.get("logger"));
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/MessagesRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/MessagesRestTest.java
deleted file mode 100644
index 492df43957..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/MessagesRestTest.java
+++ /dev/null
@@ -1,354 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import javax.jms.BytesMessage;
-import javax.jms.Connection;
-import javax.jms.DeliveryMode;
-import javax.jms.Destination;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
-
-public class MessagesRestTest extends QpidRestTestCase
-{
-
- /**
- * Message number to publish into queue
- */
- private static final int MESSAGE_NUMBER = 12;
-
- private Connection _connection;
- private Session _session;
- private MessageProducer _producer;
- private long _startTime;
- private long _ttl;
-
- public void setUp() throws Exception
- {
- super.setUp();
- _startTime = System.currentTimeMillis();
- _connection = getConnection();
- _session = _connection.createSession(true, Session.SESSION_TRANSACTED);
- String queueName = getTestQueueName();
- Destination queue = _session.createQueue(queueName);
- _session.createConsumer(queue);
- _producer = _session.createProducer(queue);
-
- _ttl = TimeUnit.DAYS.toMillis(1);
- for (int i = 0; i < MESSAGE_NUMBER; i++)
- {
- Message m = _session.createTextMessage("Test-" + i);
- m.setIntProperty("index", i);
- if (i % 2 == 0)
- {
- _producer.send(m);
- }
- else
- {
- _producer.send(m, DeliveryMode.NON_PERSISTENT, 5, _ttl);
- }
- }
- _session.commit();
- }
-
- public void testGet() throws Exception
- {
- String queueName = getTestQueueName();
- List<Map<String, Object>> messages = getJsonAsList("/rest/message/test/" + queueName);
- assertNotNull("Messages are not found", messages);
- assertEquals("Unexpected number of messages", MESSAGE_NUMBER, messages.size());
- int position = 0;
- for (Map<String, Object> message : messages)
- {
- assertMessage(position, message);
- position++;
- }
- }
-
- public void testGetMessageContent() throws Exception
- {
- String queueName = getTestQueueName();
-
- // add bytes message
- BytesMessage byteMessage = _session.createBytesMessage();
- byte[] messageBytes = "Test".getBytes();
- byteMessage.writeBytes(messageBytes);
- byteMessage.setStringProperty("test", "value");
- _producer.send(byteMessage);
- _session.commit();
-
- // get message IDs
- List<Long> ids = getMesssageIds(queueName);
-
- Map<String, Object> message = getJsonAsMap("/rest/message/test/" + queueName + "/" + ids.get(0));
- assertMessageAttributes(message);
- assertMessageAttributeValues(message, true);
-
- @SuppressWarnings("unchecked")
- Map<String, Object> headers = (Map<String, Object>) message.get("headers");
- assertNotNull("Message headers are not found", headers);
- assertEquals("Unexpected message header", 0, headers.get("index"));
-
- Long lastMessageId = ids.get(ids.size() - 1);
- message = getJsonAsMap("/rest/message/test/" + queueName + "/" + lastMessageId);
- assertMessageAttributes(message);
- assertEquals("Unexpected message attribute mimeType", "application/octet-stream", message.get("mimeType"));
- assertEquals("Unexpected message attribute size", 4, message.get("size"));
-
- @SuppressWarnings("unchecked")
- Map<String, Object> bytesMessageHeader = (Map<String, Object>) message.get("headers");
- assertNotNull("Message headers are not found", bytesMessageHeader);
- assertEquals("Unexpected message header", "value", bytesMessageHeader.get("test"));
-
- // get content
- HttpURLConnection connection = openManagementConection("/rest/message-content/test/" + queueName + "/"
- + lastMessageId, "GET");
- connection.connect();
- byte[] data = readConnectionInputStream(connection);
- assertTrue("Unexpected message", Arrays.equals(messageBytes, data));
-
- }
-
- public void testPostMoveMessages() throws Exception
- {
- String queueName = getTestQueueName();
- String queueName2 = queueName + "_2";
- Destination queue2 = _session.createQueue(queueName2);
- _session.createConsumer(queue2);
-
- // get message IDs
- List<Long> ids = getMesssageIds(queueName);
-
- // move half of the messages
- int movedNumber = ids.size() / 2;
- List<Long> movedMessageIds = new ArrayList<Long>();
- for (int i = 0; i < movedNumber; i++)
- {
- movedMessageIds.add(ids.remove(i));
- }
-
- // move messages
- HttpURLConnection connection = openManagementConection("/rest/message/test/" + queueName, "POST");
-
- Map<String, Object> messagesData = new HashMap<String, Object>();
- messagesData.put("messages", movedMessageIds);
- messagesData.put("destinationQueue", queueName2);
- messagesData.put("move", Boolean.TRUE);
-
- writeJsonRequest(connection, messagesData);
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
-
- // check messages on target queue
- List<Map<String, Object>> messages = getJsonAsList("/rest/message/test/" + queueName2);
- assertNotNull("Messages are not found", messages);
- assertEquals("Unexpected number of messages", movedMessageIds.size(), messages.size());
- for (Long id : movedMessageIds)
- {
- Map<String, Object> message = find("id", id.intValue(), messages);
- assertMessageAttributes(message);
- }
-
- // check messages on original queue
- messages = getJsonAsList("/rest/message/test/" + queueName);
- assertNotNull("Messages are not found", messages);
- assertEquals("Unexpected number of messages", ids.size(), messages.size());
- for (Long id : ids)
- {
- Map<String, Object> message = find("id", id.intValue(), messages);
- assertMessageAttributes(message);
- }
- for (Long id : movedMessageIds)
- {
- Map<String, Object> message = find("id", id.intValue(), messages);
- assertNull("Moved message " + id + " is found on original queue", message);
- }
- }
-
- public void testPostCopyMessages() throws Exception
- {
- String queueName = getTestQueueName();
- String queueName2 = queueName + "_2";
- Destination queue2 = _session.createQueue(queueName2);
- _session.createConsumer(queue2);
-
- // get message IDs
- List<Long> ids = getMesssageIds(queueName);
-
- // copy half of the messages
- int copyNumber = ids.size() / 2;
- List<Long> copyMessageIds = new ArrayList<Long>();
- for (int i = 0; i < copyNumber; i++)
- {
- copyMessageIds.add(ids.remove(i));
- }
-
- // copy messages
- HttpURLConnection connection = openManagementConection("/rest/message/test/" + queueName, "POST");
-
- Map<String, Object> messagesData = new HashMap<String, Object>();
- messagesData.put("messages", copyMessageIds);
- messagesData.put("destinationQueue", queueName2);
-
- writeJsonRequest(connection, messagesData);
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
-
- // check messages on target queue
- List<Map<String, Object>> messages = getJsonAsList("/rest/message/test/" + queueName2);
- assertNotNull("Messages are not found", messages);
- assertEquals("Unexpected number of messages", copyMessageIds.size(), messages.size());
- for (Long id : copyMessageIds)
- {
- Map<String, Object> message = find("id", id.intValue(), messages);
- assertMessageAttributes(message);
- }
-
- // check messages on original queue
- messages = getJsonAsList("/rest/message/test/" + queueName);
- assertNotNull("Messages are not found", messages);
- assertEquals("Unexpected number of messages", MESSAGE_NUMBER, messages.size());
- for (Long id : ids)
- {
- Map<String, Object> message = find("id", id.intValue(), messages);
- assertMessageAttributes(message);
- }
- for (Long id : copyMessageIds)
- {
- Map<String, Object> message = find("id", id.intValue(), messages);
- assertMessageAttributes(message);
- }
- }
-
- public void testDeleteMessages() throws Exception
- {
- String queueName = getTestQueueName();
-
- // get message IDs
- List<Long> ids = getMesssageIds(queueName);
-
- // delete half of the messages
- int deleteNumber = ids.size() / 2;
- StringBuilder queryString = new StringBuilder();
- List<Long> deleteMessageIds = new ArrayList<Long>();
- for (int i = 0; i < deleteNumber; i++)
- {
- Long id = ids.remove(i);
- deleteMessageIds.add(id);
- if (queryString.length() > 0)
- {
- queryString.append("&");
- }
- queryString.append("id=").append(id);
- }
-
- // delete messages
- HttpURLConnection connection = openManagementConection(
- "/rest/message/test/" + queueName + "?" + queryString.toString(), "DELETE");
- connection.connect();
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
-
- // check messages on queue
- List<Map<String, Object>> messages = getJsonAsList("/rest/message/test/" + queueName);
- assertNotNull("Messages are not found", messages);
- assertEquals("Unexpected number of messages", ids.size(), messages.size());
- for (Long id : ids)
- {
- Map<String, Object> message = find("id", id.intValue(), messages);
- assertMessageAttributes(message);
- }
- for (Long id : deleteMessageIds)
- {
- Map<String, Object> message = find("id", id.intValue(), messages);
- assertNull("Message with id " + id + " was not deleted", message);
- }
- }
-
- private List<Long> getMesssageIds(String queueName) throws IOException, JsonParseException, JsonMappingException
- {
- List<Map<String, Object>> messages = getJsonAsList("/rest/message/test/" + queueName);
- List<Long> ids = new ArrayList<Long>();
- for (Map<String, Object> message : messages)
- {
- ids.add(((Number) message.get("id")).longValue());
- }
- return ids;
- }
-
- private void assertMessage(int position, Map<String, Object> message)
- {
- assertMessageAttributes(message);
-
- assertEquals("Unexpected message attribute position", position, message.get("position"));
- assertEquals("Unexpected message attribute size", position < 10 ? 6 : 7, message.get("size"));
- boolean even = position % 2 == 0;
- assertMessageAttributeValues(message, even);
- }
-
- private void assertMessageAttributeValues(Map<String, Object> message, boolean even)
- {
- if (even)
- {
- assertEquals("Unexpected message attribute expirationTime", 0, message.get("expirationTime"));
- assertEquals("Unexpected message attribute priority", 4, message.get("priority"));
- assertEquals("Unexpected message attribute persistent", Boolean.TRUE, message.get("persistent"));
- }
- else
- {
- assertEquals("Unexpected message attribute expirationTime", ((Number) message.get("timestamp")).longValue()
- + _ttl, message.get("expirationTime"));
- assertEquals("Unexpected message attribute priority", 5, message.get("priority"));
- assertEquals("Unexpected message attribute persistent", Boolean.FALSE, message.get("persistent"));
- }
- assertEquals("Unexpected message attribute mimeType", "text/plain", message.get("mimeType"));
- assertEquals("Unexpected message attribute userId", "guest", message.get("userId"));
- assertEquals("Unexpected message attribute deliveryCount", 0, message.get("deliveryCount"));
- assertEquals("Unexpected message attribute state", "Available", message.get("state"));
- }
-
- private void assertMessageAttributes(Map<String, Object> message)
- {
- assertNotNull("Message map cannot be null", message);
- assertNotNull("Unexpected message attribute deliveryCount", message.get("deliveryCount"));
- assertNotNull("Unexpected message attribute state", message.get("state"));
- assertNotNull("Unexpected message attribute id", message.get("id"));
- assertNotNull("Message arrivalTime cannot be null", message.get("arrivalTime"));
- assertNotNull("Message timestamp cannot be null", message.get("timestamp"));
- assertTrue("Message arrivalTime cannot be null", ((Number) message.get("arrivalTime")).longValue() > _startTime);
- assertNotNull("Message messageId cannot be null", message.get("messageId"));
- assertNotNull("Unexpected message attribute mimeType", message.get("mimeType"));
- assertNotNull("Unexpected message attribute userId", message.get("userId"));
- assertNotNull("Message priority cannot be null", message.get("priority"));
- assertNotNull("Message expirationTime cannot be null", message.get("expirationTime"));
- assertNotNull("Message persistent cannot be null", message.get("persistent"));
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/PortRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/PortRestTest.java
deleted file mode 100644
index 739ef5c737..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/PortRestTest.java
+++ /dev/null
@@ -1,61 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.net.URLDecoder;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.qpid.server.model.Port;
-
-public class PortRestTest extends QpidRestTestCase
-{
- public void testGet() throws Exception
- {
- List<Map<String, Object>> ports = getJsonAsList("/rest/port/");
- assertNotNull("Port data cannot be null", ports);
- assertEquals("Unexpected number of ports", 2, ports.size());
- int[] expectedPorts = { getPort(), getHttpPort() };
- for (int port : expectedPorts)
- {
- String portName = "0.0.0.0:" + port;
- Map<String, Object> portData = find(Port.NAME, portName, ports);
- assertNotNull("Port " + portName + " is not found", portData);
- Asserts.assertPortAttributes(portData);
- }
- }
-
- public void testGetPort() throws Exception
- {
- List<Map<String, Object>> ports = getJsonAsList("/rest/port/");
- assertNotNull("Ports data cannot be null", ports);
- assertEquals("Unexpected number of ports", 2, ports.size());
- for (Map<String, Object> portMap : ports)
- {
- String portName = (String) portMap.get(Port.NAME);
- assertNotNull("Port name attribute is not found", portName);
- Map<String, Object> portData = getJsonAsSingletonList("/rest/port/" + URLDecoder.decode(portName, "UTF-8"));
- assertNotNull("Port " + portName + " is not found", portData);
- Asserts.assertPortAttributes(portData);
- }
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QpidRestTestCase.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QpidRestTestCase.java
deleted file mode 100644
index e83341de80..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QpidRestTestCase.java
+++ /dev/null
@@ -1,245 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.InetAddress;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
-
-public class QpidRestTestCase extends QpidBrokerTestCase
-{
- private static final Logger LOGGER = Logger.getLogger(QpidRestTestCase.class);
-
- public static final String[] EXPECTED_HOSTS = { "development", "test", "localhost" };
- public static final String[] EXPECTED_QUEUES = { "queue", "ping" };
- public static final String[] EXPECTED_EXCHANGES = { "amq.fanout", "amq.match", "amq.direct", "amq.topic",
- "qpid.management", "<<default>>" };
-
- private int _httpPort;
- private String _hostName;
- private List<HttpURLConnection> _httpConnections;
-
- @Override
- public void setUp() throws Exception
- {
- _httpConnections = new ArrayList<HttpURLConnection>();
- _hostName = InetAddress.getLocalHost().getHostName();
- _httpPort = findFreePort();
- customizeConfiguration();
- super.setUp();
-
- }
-
- protected void customizeConfiguration() throws ConfigurationException, IOException
- {
- setConfigurationProperty("management.enabled", "false");
- setConfigurationProperty("management.http.enabled", "true");
- setConfigurationProperty("management.https.enabled", "false");
- setConfigurationProperty("management.http.port", Integer.toString(_httpPort));
- }
-
- public void teearDown() throws Exception
- {
- for (HttpURLConnection connection : _httpConnections)
- {
- try
- {
- connection.disconnect();
- }
- catch (Exception e)
- {
- // ignore
- }
- }
- super.tearDown();
- }
-
- protected int getHttpPort()
- {
- return _httpPort;
- }
-
- protected String getHostName()
- {
- return _hostName;
- }
-
- protected String getProtocol()
- {
- return "http";
- }
-
- protected String getManagementURL()
- {
- return getProtocol() + "://" + getHostName() + ":" + getHttpPort();
- }
-
- protected URL getManagementURL(String path) throws MalformedURLException
- {
- return new URL(getManagementURL() + path);
- }
-
- protected HttpURLConnection openManagementConection(String path) throws IOException
- {
- URL url = getManagementURL(path);
- HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
- httpCon.setDoOutput(true);
- return httpCon;
- }
-
- protected HttpURLConnection openManagementConection(String path, String method) throws IOException
- {
- HttpURLConnection httpCon = openManagementConection(path);
- httpCon.setRequestMethod(method);
- return httpCon;
- }
-
- protected List<Map<String, Object>> readJsonResponseAsList(HttpURLConnection connection) throws IOException,
- JsonParseException, JsonMappingException
- {
- byte[] data = readConnectionInputStream(connection);
-
- ObjectMapper mapper = new ObjectMapper();
-
- TypeReference<List<LinkedHashMap<String, Object>>> typeReference = new TypeReference<List<LinkedHashMap<String, Object>>>()
- {
- };
- List<Map<String, Object>> providedObject = mapper.readValue(new ByteArrayInputStream(data), typeReference);
- return providedObject;
- }
-
- protected Map<String, Object> readJsonResponseAsMap(HttpURLConnection connection) throws IOException,
- JsonParseException, JsonMappingException
- {
- byte[] data = readConnectionInputStream(connection);
-
- ObjectMapper mapper = new ObjectMapper();
-
- TypeReference<LinkedHashMap<String, Object>> typeReference = new TypeReference<LinkedHashMap<String, Object>>()
- {
- };
- Map<String, Object> providedObject = mapper.readValue(new ByteArrayInputStream(data), typeReference);
- return providedObject;
- }
-
- protected byte[] readConnectionInputStream(HttpURLConnection connection) throws IOException
- {
- InputStream is = connection.getInputStream();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int len = -1;
- while ((len = is.read(buffer)) != -1)
- {
- baos.write(buffer, 0, len);
- }
- if (LOGGER.isTraceEnabled())
- {
- LOGGER.trace("RESPONSE:" + new String(baos.toByteArray()));
- }
- return baos.toByteArray();
- }
-
- protected void writeJsonRequest(HttpURLConnection connection, Map<String, Object> data) throws JsonGenerationException,
- JsonMappingException, IOException
- {
- ObjectMapper mapper = new ObjectMapper();
- mapper.writeValue(connection.getOutputStream(), data);
- }
-
- protected Map<String, Object> find(String name, Object value, List<Map<String, Object>> data)
- {
- for (Map<String, Object> map : data)
- {
- Object mapValue = map.get(name);
- if (value.equals(mapValue))
- {
- return map;
- }
- }
- return null;
- }
-
- protected Map<String, Object> find(Map<String, Object> searchAttributes, List<Map<String, Object>> data)
- {
- for (Map<String, Object> map : data)
- {
- boolean equals = true;
- for (Map.Entry<String, Object> entry : searchAttributes.entrySet())
- {
- Object mapValue = map.get(entry.getKey());
- if (!entry.getValue().equals(mapValue))
- {
- equals = false;
- break;
- }
- }
- if (equals)
- {
- return map;
- }
- }
- return null;
- }
-
- protected Map<String, Object> getJsonAsSingletonList(String path) throws IOException
- {
- List<Map<String, Object>> response = getJsonAsList(path);
-
- assertNotNull("Response cannot be null", response);
- assertEquals("Unexpected response", 1, response.size());
- return response.get(0);
- }
-
- protected List<Map<String, Object>> getJsonAsList(String path) throws IOException, JsonParseException,
- JsonMappingException
- {
- HttpURLConnection connection = openManagementConection(path, "GET");
- connection.connect();
- List<Map<String, Object>> response = readJsonResponseAsList(connection);
- return response;
- }
-
- protected Map<String, Object> getJsonAsMap(String path) throws IOException
- {
- HttpURLConnection connection = openManagementConection(path, "GET");
- connection.connect();
- Map<String, Object> response = readJsonResponseAsMap(connection);
- return response;
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QueueRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QueueRestTest.java
deleted file mode 100644
index 5f11b3fb1d..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QueueRestTest.java
+++ /dev/null
@@ -1,225 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URLDecoder;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-
-import org.apache.qpid.server.model.Binding;
-import org.apache.qpid.server.model.Consumer;
-import org.apache.qpid.server.model.LifetimePolicy;
-import org.apache.qpid.server.model.Queue;
-
-public class QueueRestTest extends QpidRestTestCase
-{
- private static final String QUEUE_ATTRIBUTE_CONSUMERS = "consumers";
- private static final String QUEUE_ATTRIBUTE_BINDINGS = "bindings";
-
- /**
- * Message number to publish into queue
- */
- private static final int MESSAGE_NUMBER = 2;
- private static final int MESSAGE_PAYLOAD_SIZE = 6;
- private static final int ENQUEUED_MESSAGES = 1;
- private static final int DEQUEUED_MESSAGES = 1;
- private static final int ENQUEUED_BYTES = MESSAGE_PAYLOAD_SIZE;
- private static final int DEQUEUED_BYTES = MESSAGE_PAYLOAD_SIZE;
-
- private Connection _connection;
-
- public void setUp() throws Exception
- {
- super.setUp();
- _connection = getConnection();
- Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
- String queueName = getTestQueueName();
- Destination queue = session.createQueue(queueName);
- MessageConsumer consumer = session.createConsumer(queue);
- MessageProducer producer = session.createProducer(queue);
-
- for (int i = 0; i < MESSAGE_NUMBER; i++)
- {
- producer.send(session.createTextMessage("Test-" + i));
- }
- session.commit();
- _connection.start();
- Message m = consumer.receive(1000l);
- assertNotNull("Message is not received", m);
- session.commit();
- }
-
- public void testGetVirtualHostQueues() throws Exception
- {
- String queueName = getTestQueueName();
- List<Map<String, Object>> queues = getJsonAsList("/rest/queue/test");
- assertEquals("Unexpected number of queues", EXPECTED_QUEUES.length + 1, queues.size());
- String[] expectedQueues = new String[EXPECTED_QUEUES.length + 1];
- System.arraycopy(EXPECTED_QUEUES, 0, expectedQueues, 0, EXPECTED_QUEUES.length);
- expectedQueues[EXPECTED_QUEUES.length] = queueName;
-
- for (String name : expectedQueues)
- {
- Map<String, Object> queueDetails = find(Queue.NAME, name, queues);
- Asserts.assertQueue(name, "standard", queueDetails);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
- assertNotNull("Queue bindings are not found", bindings);
- assertEquals("Unexpected number of bindings", 2, bindings.size());
-
- Map<String, Object> defaultExchangeBinding = find(Binding.EXCHANGE, "<<default>>", bindings);
- Map<String, Object> directExchangeBinding = find(Binding.EXCHANGE, "amq.direct", bindings);
- Asserts.assertBinding(name, "<<default>>", defaultExchangeBinding);
- Asserts.assertBinding(name, "amq.direct", directExchangeBinding);
- }
- }
-
- public void testGetByName() throws Exception
- {
- String queueName = getTestQueueName();
- Map<String, Object> queueDetails = getJsonAsSingletonList("/rest/queue/test/" + queueName);
- Asserts.assertQueue(queueName, "standard", queueDetails);
- assertStatistics(queueDetails);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
- assertNotNull("Queue bindings are not found", bindings);
- assertEquals("Unexpected number of bindings", 2, bindings.size());
-
- Map<String, Object> defaultExchangeBinding = find(Binding.EXCHANGE, "<<default>>", bindings);
- Map<String, Object> directExchangeBinding = find(Binding.EXCHANGE, "amq.direct", bindings);
- Asserts.assertBinding(queueName, "<<default>>", defaultExchangeBinding);
- Asserts.assertBinding(queueName, "amq.direct", directExchangeBinding);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> consumers = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_CONSUMERS);
- assertNotNull("Queue consumers are not found", consumers);
- assertEquals("Unexpected number of consumers", 1, consumers.size());
- assertConsumer(consumers.get(0));
- }
-
- public void testPutCreateBinding() throws Exception
- {
- String queueName = getTestQueueName();
- String bindingName = queueName + 2;
- String[] exchanges = { "amq.direct", "amq.fanout", "amq.topic", "amq.match", "qpid.management", "<<default>>" };
-
- for (int i = 0; i < exchanges.length; i++)
- {
- createBinding(bindingName, exchanges[i], queueName);
- }
-
- Map<String, Object> queueDetails = getJsonAsSingletonList("/rest/queue/test/" + queueName);
- Asserts.assertQueue(queueName, "standard", queueDetails);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
- assertNotNull("Queue bindings are not found", bindings);
- assertEquals("Unexpected number of bindings", exchanges.length + 2, bindings.size());
-
- Map<String, Object> searchAttributes = new HashMap<String, Object>();
- searchAttributes.put(Binding.NAME, bindingName);
-
- for (int i = 0; i < exchanges.length; i++)
- {
- searchAttributes.put(Binding.EXCHANGE, exchanges[i]);
- Map<String, Object> binding = find(searchAttributes, bindings);
- Asserts.assertBinding(bindingName, queueName, exchanges[i], binding);
- }
- }
-
- private void createBinding(String bindingName, String exchangeName, String queueName) throws IOException
- {
- HttpURLConnection connection = openManagementConection(
- "/rest/binding/test/" + URLDecoder.decode(exchangeName, "UTF-8") + "/" + queueName + "/" + bindingName,
- "PUT");
-
- Map<String, Object> bindingData = new HashMap<String, Object>();
- bindingData.put(Binding.NAME, bindingName);
- bindingData.put(Binding.EXCHANGE, exchangeName);
- bindingData.put(Binding.QUEUE, queueName);
-
- writeJsonRequest(connection, bindingData);
- assertEquals("Unexpected response code", 201, connection.getResponseCode());
-
- connection.disconnect();
- }
-
- private void assertConsumer(Map<String, Object> consumer)
- {
- assertNotNull("Consumer map should not be null", consumer);
- Asserts.assertAttributesPresent(consumer, Consumer.AVAILABLE_ATTRIBUTES, Consumer.STATE, Consumer.TIME_TO_LIVE,
- Consumer.CREATED, Consumer.UPDATED, Consumer.SETTLEMENT_MODE, Consumer.EXCLUSIVE, Consumer.SELECTOR,
- Consumer.NO_LOCAL);
-
- assertEquals("Unexpected binding attribute " + Consumer.NAME, "1", consumer.get(Consumer.NAME));
- assertEquals("Unexpected binding attribute " + Consumer.DURABLE, Boolean.FALSE, consumer.get(Consumer.DURABLE));
- assertEquals("Unexpected binding attribute " + Consumer.LIFETIME_POLICY, LifetimePolicy.AUTO_DELETE.name(),
- consumer.get(Consumer.LIFETIME_POLICY));
- assertEquals("Unexpected binding attribute " + Consumer.DISTRIBUTION_MODE, "MOVE",
- consumer.get(Consumer.DISTRIBUTION_MODE));
-
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) consumer.get(Asserts.STATISTICS_ATTRIBUTE);
- assertNotNull("Consumer statistics is not present", statistics);
- Asserts.assertAttributesPresent(statistics, Consumer.AVAILABLE_STATISTICS, Consumer.STATE_CHANGED);
- }
-
- private void assertStatistics(Map<String, Object> queueDetails)
- {
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) queueDetails.get(Asserts.STATISTICS_ATTRIBUTE);
- assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
- statistics.get(Queue.PERSISTENT_DEQUEUED_MESSAGES));
- assertEquals("Unexpected queue statistics attribute " + Queue.QUEUE_DEPTH_MESSAGES, ENQUEUED_MESSAGES,
- statistics.get(Queue.QUEUE_DEPTH_MESSAGES));
- assertEquals("Unexpected queue statistics attribute " + Queue.CONSUMER_COUNT, 1,
- statistics.get(Queue.CONSUMER_COUNT));
- assertEquals("Unexpected queue statistics attribute " + Queue.CONSUMER_COUNT_WITH_CREDIT, 1,
- statistics.get(Queue.CONSUMER_COUNT_WITH_CREDIT));
- assertEquals("Unexpected queue statistics attribute " + Queue.BINDING_COUNT, 2, statistics.get(Queue.BINDING_COUNT));
- assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
- statistics.get(Queue.PERSISTENT_DEQUEUED_MESSAGES));
- assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
- statistics.get(Queue.TOTAL_DEQUEUED_MESSAGES));
- assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_DEQUEUED_BYTES, DEQUEUED_BYTES,
- statistics.get(Queue.TOTAL_DEQUEUED_BYTES));
- assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_BYTES, DEQUEUED_BYTES,
- statistics.get(Queue.TOTAL_DEQUEUED_BYTES));
- assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_ENQUEUED_BYTES, ENQUEUED_BYTES
- + DEQUEUED_BYTES, statistics.get(Queue.PERSISTENT_ENQUEUED_BYTES));
- assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_ENQUEUED_BYTES, ENQUEUED_BYTES + DEQUEUED_BYTES,
- statistics.get(Queue.TOTAL_ENQUEUED_BYTES));
- assertEquals("Unexpected queue statistics attribute " + Queue.QUEUE_DEPTH_BYTES, ENQUEUED_BYTES,
- statistics.get(Queue.QUEUE_DEPTH_BYTES));
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslRestTest.java
deleted file mode 100644
index b504c9fa60..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslRestTest.java
+++ /dev/null
@@ -1,42 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.util.List;
-import java.util.Map;
-
-public class SaslRestTest extends QpidRestTestCase
-{
- public void testGet() throws Exception
- {
- Map<String, Object> saslData = getJsonAsMap("/rest/sasl");
- assertNotNull("mechanisms attribute is not found", saslData.get("mechanisms"));
-
- @SuppressWarnings("unchecked")
- List<String> mechanisms = (List<String>) saslData.get("mechanisms");
- String[] expectedMechanisms = { "AMQPLAIN", "PLAIN", "CRAM-MD5" };
- for (String mechanism : expectedMechanisms)
- {
- assertTrue("Mechanism " + mechanism + " is not found", mechanisms.contains(mechanism));
- }
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureRestTest.java
deleted file mode 100644
index b01e1d44b8..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureRestTest.java
+++ /dev/null
@@ -1,115 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.util.List;
-import java.util.Map;
-
-public class StructureRestTest extends QpidRestTestCase
-{
-
- public void testGet() throws Exception
- {
- Map<String, Object> structure = getJsonAsMap("/rest/structure");
- assertNotNull("Structure data cannot be null", structure);
- assertNode(structure, "Broker");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) structure.get("virtualhosts");
- assertEquals("Unexpected number of virtual hosts", 3, virtualhosts.size());
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> ports = (List<Map<String, Object>>) structure.get("ports");
- assertEquals("Unexpected number of ports", 2, ports.size());
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> providers = (List<Map<String, Object>>) structure.get("authenticationproviders");
- assertEquals("Unexpected number of authentication providers", 1, providers.size());
-
- for (String hostName : EXPECTED_HOSTS)
- {
- Map<String, Object> host = find("name", hostName, virtualhosts);
- assertNotNull("Host " + hostName + " is not found ", host);
- assertNode(host, hostName);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) host.get("queues");
- assertNotNull("Host " + hostName + " queues are not found ", queues);
- for (String queueName : EXPECTED_QUEUES)
- {
- Map<String, Object> queue = find("name", queueName, queues);
- assertNotNull(hostName + " queue " + queueName + " is not found ", queue);
- assertNode(queue, queueName);
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> bindings = (List<Map<String, Object>>) queue.get("bindings");
- assertNotNull(hostName + " queue " + queueName + " bindings are not found ", queues);
- for (Map<String, Object> binding : bindings)
- {
- assertNode(binding, queueName);
- }
- }
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> exchanges = (List<Map<String, Object>>) host.get("exchanges");
- assertNotNull("Host " + hostName + " exchanges are not found ", exchanges);
- for (String exchangeName : EXPECTED_EXCHANGES)
- {
- Map<String, Object> exchange = find("name", exchangeName, exchanges);
- assertNotNull("Exchange " + exchangeName + " is not found ", exchange);
- assertNode(exchange, exchangeName);
- if ("amq.direct".equalsIgnoreCase(exchangeName) || "<<default>>".equalsIgnoreCase(exchangeName))
- {
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> bindings = (List<Map<String, Object>>) exchange.get("bindings");
- assertNotNull(hostName + " exchange " + exchangeName + " bindings are not found ", bindings);
- for (String queueName : EXPECTED_QUEUES)
- {
- Map<String, Object> binding = find("name", queueName, bindings);
- assertNotNull(hostName + " exchange " + exchangeName + " binding " + queueName + " is not found", binding);
- assertNode(binding, queueName);
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> aliases = (List<Map<String, Object>>) host.get("virtualhostaliases");
- assertNotNull("Host " + hostName + " aliaces are not found ", aliases);
- assertEquals("Unexpected aliaces size", 1, aliases.size());
- assertNode(aliases.get(0), hostName);
- }
-
- int[] expectedPorts = { getPort(), getHttpPort() };
- for (int port : expectedPorts)
- {
- String portName = "0.0.0.0:" + port;
- Map<String, Object> portData = find("name", portName, ports);
- assertNotNull("Port " + portName + " is not found ", portData);
- assertNode(portData, portName);
- }
- }
-
- private void assertNode(Map<String, Object> node, String name)
- {
- assertEquals("Unexpected name", name, node.get("name"));
- assertNotNull("Unexpected id", node.get("id"));
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/UserRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/UserRestTest.java
deleted file mode 100644
index e56fa27e21..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/UserRestTest.java
+++ /dev/null
@@ -1,112 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.net.HttpURLConnection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.qpid.server.model.User;
-
-public class UserRestTest extends QpidRestTestCase
-{
- public void testGet() throws Exception
- {
- List<Map<String, Object>> users = getJsonAsList("/rest/user");
- assertNotNull("Users cannot be null", users);
- assertTrue("Unexpected number of users", users.size() > 1);
- for (Map<String, Object> user : users)
- {
- assertUser(user);
- }
- }
-
- public void testGetUserByName() throws Exception
- {
- List<Map<String, Object>> users = getJsonAsList("/rest/user");
- assertNotNull("Users cannot be null", users);
- assertTrue("Unexpected number of users", users.size() > 1);
- for (Map<String, Object> user : users)
- {
- assertNotNull("Attribute " + User.ID, user.get(User.ID));
- String userName = (String) user.get(User.NAME);
- assertNotNull("Attribute " + User.NAME, userName);
- Map<String, Object> userDetails = getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
- + userName);
- assertUser(userDetails);
- assertEquals("Unexpected user name", userName, userDetails.get(User.NAME));
- }
- }
-
- public void testPut() throws Exception
- {
- String userName = getTestName();
- HttpURLConnection connection = openManagementConection("/rest/user/PrincipalDatabaseAuthenticationManager/"
- + userName, "PUT");
-
- Map<String, Object> userData = new HashMap<String, Object>();
- userData.put(User.NAME, userName);
- userData.put(User.PASSWORD, userName);
-
- writeJsonRequest(connection, userData);
- assertEquals("Unexpected response code", 201, connection.getResponseCode());
-
- connection.disconnect();
-
- Map<String, Object> userDetails = getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
- + userName);
- assertUser(userDetails);
- assertEquals("Unexpected user name", userName, userDetails.get(User.NAME));
- }
-
- public void testDelete() throws Exception
- {
- // add user
- String userName = getTestName();
- HttpURLConnection connection = openManagementConection("/rest/user/PrincipalDatabaseAuthenticationManager/"
- + userName, "PUT");
-
- Map<String, Object> userData = new HashMap<String, Object>();
- userData.put(User.NAME, userName);
- userData.put(User.PASSWORD, userName);
-
- writeJsonRequest(connection, userData);
- assertEquals("Unexpected response code", 201, connection.getResponseCode());
- connection.disconnect();
-
- Map<String, Object> userDetails = getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
- + userName);
- String id = (String) userDetails.get(User.ID);
-
- connection = openManagementConection("/rest/user/PrincipalDatabaseAuthenticationManager?id=" + id, "DELETE");
- connection.connect();
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
- List<Map<String, Object>> users = getJsonAsList("/rest/user/PrincipalDatabaseAuthenticationManager/" + userName);
- assertEquals("User should be deleted", 0, users.size());
- }
-
- private void assertUser(Map<String, Object> user)
- {
- assertNotNull("Attribute " + User.ID, user.get(User.ID));
- assertNotNull("Attribute " + User.NAME, user.get(User.NAME));
- }
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostRestTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostRestTest.java
deleted file mode 100644
index 17f1aaaf7b..0000000000
--- a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostRestTest.java
+++ /dev/null
@@ -1,434 +0,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.
- *
- */
-package org.apache.qpid.server.management.plugin.servlet.rest;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.jms.Session;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.server.model.Exchange;
-import org.apache.qpid.server.model.Queue;
-import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.map.JsonMappingException;
-
-public class VirtualHostRestTest extends QpidRestTestCase
-{
- private static final String VIRTUALHOST_EXCHANGES_ATTRIBUTE = "exchanges";
- public static final String VIRTUALHOST_QUEUES_ATTRIBUTE = "queues";
- public static final String VIRTUALHOST_CONNECTIONS_ATTRIBUTE = "connections";
-
- private AMQConnection _connection;
-
- public void testGet() throws Exception
- {
- List<Map<String, Object>> hosts = getJsonAsList("/rest/virtualhost/");
- assertNotNull("Hosts data cannot be null", hosts);
- assertEquals("Unexpected number of hosts", 3, hosts.size());
- for (String hostName : EXPECTED_HOSTS)
- {
- Map<String, Object> host = find("name", hostName, hosts);
- Asserts.assertVirtualHost(hostName, host);
- }
- }
-
- public void testGetHost() throws Exception
- {
- // create AMQP connection to get connection JSON details
- _connection = (AMQConnection) getConnection();
- _connection.createSession(true, Session.SESSION_TRANSACTED);
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
- Asserts.assertVirtualHost("test", hostDetails);
-
- @SuppressWarnings("unchecked")
- Map<String, Object> statistics = (Map<String, Object>) hostDetails.get(Asserts.STATISTICS_ATTRIBUTE);
- assertEquals("Unexpected number of exchanges in statistics", 6, statistics.get(VirtualHost.EXCHANGE_COUNT));
- assertEquals("Unexpected number of queues in statistics", 2, statistics.get(VirtualHost.QUEUE_COUNT));
- assertEquals("Unexpected number of connections in statistics", 1, statistics.get(VirtualHost.CONNECTION_COUNT));
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_EXCHANGES_ATTRIBUTE);
- assertEquals("Unexpected number of exchanges", 6, exchanges.size());
- Asserts.assertDurableExchange("amq.fanout", "fanout", find(Exchange.NAME, "amq.fanout", exchanges));
- Asserts.assertDurableExchange("qpid.management", "management", find(Exchange.NAME, "qpid.management", exchanges));
- Asserts.assertDurableExchange("amq.topic", "topic", find(Exchange.NAME, "amq.topic", exchanges));
- Asserts.assertDurableExchange("amq.direct", "direct", find(Exchange.NAME, "amq.direct", exchanges));
- Asserts.assertDurableExchange("amq.match", "headers", find(Exchange.NAME, "amq.match", exchanges));
- Asserts.assertDurableExchange("<<default>>", "direct", find(Exchange.NAME, "<<default>>", exchanges));
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_QUEUES_ATTRIBUTE);
- assertEquals("Unexpected number of queues", 2, queues.size());
- Map<String, Object> queue = find(Queue.NAME, "queue", queues);
- Map<String, Object> ping = find(Queue.NAME, "ping", queues);
- Asserts.assertQueue("queue", "standard", queue);
- Asserts.assertQueue("ping", "standard", ping);
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.FALSE, queue.get(Queue.DURABLE));
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.FALSE, ping.get(Queue.DURABLE));
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> connections = (List<Map<String, Object>>) hostDetails
- .get(VIRTUALHOST_CONNECTIONS_ATTRIBUTE);
- assertEquals("Unexpected number of connections", 1, connections.size());
- Asserts.assertConnection(connections.get(0), _connection);
- }
-
- public void testPutCreateQueue() throws Exception
- {
- String queueName = getTestQueueName();
-
- createQueue(queueName + "-standard", "standard", null);
-
- Map<String, Object> sortedQueueAttributes = new HashMap<String, Object>();
- sortedQueueAttributes.put(Queue.SORT_KEY, "sortme");
- createQueue(queueName + "-sorted", "sorted", sortedQueueAttributes);
-
- Map<String, Object> priorityQueueAttributes = new HashMap<String, Object>();
- priorityQueueAttributes.put(Queue.PRIORITIES, 10);
- createQueue(queueName + "-priority", "priority", priorityQueueAttributes);
-
- Map<String, Object> lvqQueueAttributes = new HashMap<String, Object>();
- lvqQueueAttributes.put(Queue.LVQ_KEY, "LVQ");
- createQueue(queueName + "-lvq", "lvq", lvqQueueAttributes);
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- Map<String, Object> standardQueue = find(Queue.NAME, queueName + "-standard" , queues);
- Map<String, Object> sortedQueue = find(Queue.NAME, queueName + "-sorted" , queues);
- Map<String, Object> priorityQueue = find(Queue.NAME, queueName + "-priority" , queues);
- Map<String, Object> lvqQueue = find(Queue.NAME, queueName + "-lvq" , queues);
-
- Asserts.assertQueue(queueName + "-standard", "standard", standardQueue);
- Asserts.assertQueue(queueName + "-sorted", "sorted", sortedQueue);
- Asserts.assertQueue(queueName + "-priority", "priority", priorityQueue);
- Asserts.assertQueue(queueName + "-lvq", "lvq", lvqQueue);
-
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, standardQueue.get(Queue.DURABLE));
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, sortedQueue.get(Queue.DURABLE));
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, priorityQueue.get(Queue.DURABLE));
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, lvqQueue.get(Queue.DURABLE));
-
- assertEquals("Unexpected sorted key attribute", "sortme", sortedQueue.get(Queue.SORT_KEY));
- assertEquals("Unexpected lvq key attribute", "LVQ", lvqQueue.get(Queue.LVQ_KEY));
- assertEquals("Unexpected priorities key attribute", 10, priorityQueue.get(Queue.PRIORITIES));
- }
-
- public void testPutCreateExchange() throws Exception
- {
- String exchangeName = getTestName();
-
- createExchange(exchangeName + "-direct", "direct");
- createExchange(exchangeName + "-topic", "topic");
- createExchange(exchangeName + "-headers", "headers");
- createExchange(exchangeName + "-fanout", "fanout");
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_EXCHANGES_ATTRIBUTE);
- Map<String, Object> directExchange = find(Queue.NAME, exchangeName + "-direct" , exchanges);
- Map<String, Object> topicExchange = find(Queue.NAME, exchangeName + "-topic" , exchanges);
- Map<String, Object> headersExchange = find(Queue.NAME, exchangeName + "-headers" , exchanges);
- Map<String, Object> fanoutExchange = find(Queue.NAME, exchangeName + "-fanout" , exchanges);
-
- Asserts.assertDurableExchange(exchangeName + "-direct", "direct", directExchange);
- Asserts.assertDurableExchange(exchangeName + "-topic", "topic", topicExchange);
- Asserts.assertDurableExchange(exchangeName + "-headers", "headers", headersExchange);
- Asserts.assertDurableExchange(exchangeName + "-fanout", "fanout", fanoutExchange);
-
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, directExchange.get(Queue.DURABLE));
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, topicExchange.get(Queue.DURABLE));
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, headersExchange.get(Queue.DURABLE));
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, fanoutExchange.get(Queue.DURABLE));
-
- }
-
- public void testPutCreateLVQWithoutKey() throws Exception
- {
- String queueName = getTestQueueName()+ "-lvq";
- createQueue(queueName, "lvq", null);
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- Map<String, Object> lvqQueue = find(Queue.NAME, queueName , queues);
-
- Asserts.assertQueue(queueName , "lvq", lvqQueue);
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, lvqQueue.get(Queue.DURABLE));
- assertEquals("Unexpected lvq key attribute", AMQQueueFactory.QPID_LVQ_KEY, lvqQueue.get(Queue.LVQ_KEY));
- }
-
- public void testPutCreateSortedQueueWithoutKey() throws Exception
- {
- String queueName = getTestQueueName() + "-sorted";
- int responseCode = tryCreateQueue(queueName, "sorted", null);
- assertEquals("Unexpected response code", 409, responseCode);
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- Map<String, Object> testQueue = find(Queue.NAME, queueName , queues);
-
- assertNull("Sorted queue without a key was created ", testQueue);
- }
-
- public void testPutCreatePriorityQueueWithoutKey() throws Exception
- {
- String queueName = getTestQueueName()+ "-priority";
- createQueue(queueName, "priority", null);
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- Map<String, Object> priorityQueue = find(Queue.NAME, queueName , queues);
-
- Asserts.assertQueue(queueName , "priority", priorityQueue);
- assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, priorityQueue.get(Queue.DURABLE));
- assertEquals("Unexpected number of priorities", 10, priorityQueue.get(Queue.PRIORITIES));
- }
-
- public void testPutCreateStandardQueueWithoutType() throws Exception
- {
- String queueName = getTestQueueName();
- createQueue(queueName, null, null);
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- Map<String, Object> queue = find(Queue.NAME, queueName , queues);
-
- Asserts.assertQueue(queueName , "standard", queue);
- }
-
- public void testPutCreateQueueOfUnsupportedType() throws Exception
- {
- String queueName = getTestQueueName();
- int responseCode = tryCreateQueue(queueName, "unsupported", null);
- assertEquals("Unexpected response code", 409, responseCode);
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- Map<String, Object> queue = find(Queue.NAME, queueName , queues);
-
- assertNull("Queue of unsupported type was created", queue);
- }
-
- public void testDeleteQueue() throws Exception
- {
- String queueName = getTestQueueName();
- createQueue(queueName, null, null);
-
- HttpURLConnection connection = openManagementConection("/rest/queue/test/" + queueName, "DELETE");
- connection.connect();
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
- List<Map<String, Object>> queues = getJsonAsList("/rest/queue/test/" + queueName);
- assertEquals("Queue should be deleted", 0, queues.size());
- }
-
- public void testDeleteQueueById() throws Exception
- {
- String queueName = getTestQueueName();
- createQueue(queueName, null, null);
- Map<String, Object> queueDetails = getJsonAsSingletonList("/rest/queue/test/" + queueName);
-
- HttpURLConnection connection = openManagementConection("/rest/queue/test?id=" + queueDetails.get(Queue.ID), "DELETE");
- connection.connect();
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
- List<Map<String, Object>> queues = getJsonAsList("/rest/queue/test/" + queueName);
- assertEquals("Queue should be deleted", 0, queues.size());
- }
-
- public void testDeleteExchange() throws Exception
- {
- String exchangeName = getTestName();
- createExchange(exchangeName, "direct");
-
- HttpURLConnection connection = openManagementConection("/rest/exchange/test/" + exchangeName, "DELETE");
- connection.connect();
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
- List<Map<String, Object>> queues = getJsonAsList("/rest/exchange/test/" + exchangeName);
- assertEquals("Exchange should be deleted", 0, queues.size());
- }
-
- public void testDeleteExchangeById() throws Exception
- {
- String exchangeName = getTestName();
- createExchange(exchangeName, "direct");
- Map<String, Object> echangeDetails = getJsonAsSingletonList("/rest/exchange/test/" + exchangeName);
-
- HttpURLConnection connection = openManagementConection("/rest/exchange/test?id=" + echangeDetails.get(Exchange.ID), "DELETE");
- connection.connect();
- assertEquals("Unexpected response code", 200, connection.getResponseCode());
- List<Map<String, Object>> queues = getJsonAsList("/rest/exchange/test/" + exchangeName);
- assertEquals("Exchange should be deleted", 0, queues.size());
- }
-
- public void testPutCreateQueueWithAttributes() throws Exception
- {
- String queueName = getTestQueueName();
-
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(Queue.ALERT_REPEAT_GAP, 1000);
- attributes.put(Queue.ALERT_THRESHOLD_MESSAGE_AGE, 3600000);
- attributes.put(Queue.ALERT_THRESHOLD_MESSAGE_SIZE, 1000000000);
- attributes.put(Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, 800);
- attributes.put(Queue.MAXIMUM_DELIVERY_ATTEMPTS, 15);
- attributes.put(Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES, 2000000000);
- attributes.put(Queue.QUEUE_FLOW_RESUME_SIZE_BYTES, 1500000000);
-
- createQueue(queueName + "-standard", "standard", attributes);
-
- Map<String, Object> sortedQueueAttributes = new HashMap<String, Object>();
- sortedQueueAttributes.putAll(attributes);
- sortedQueueAttributes.put(Queue.SORT_KEY, "sortme");
- createQueue(queueName + "-sorted", "sorted", sortedQueueAttributes);
-
- Map<String, Object> priorityQueueAttributes = new HashMap<String, Object>();
- priorityQueueAttributes.putAll(attributes);
- priorityQueueAttributes.put(Queue.PRIORITIES, 10);
- createQueue(queueName + "-priority", "priority", priorityQueueAttributes);
-
- Map<String, Object> lvqQueueAttributes = new HashMap<String, Object>();
- lvqQueueAttributes.putAll(attributes);
- lvqQueueAttributes.put(Queue.LVQ_KEY, "LVQ");
- createQueue(queueName + "-lvq", "lvq", lvqQueueAttributes);
-
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
-
- @SuppressWarnings("unchecked")
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- Map<String, Object> standardQueue = find(Queue.NAME, queueName + "-standard" , queues);
- Map<String, Object> sortedQueue = find(Queue.NAME, queueName + "-sorted" , queues);
- Map<String, Object> priorityQueue = find(Queue.NAME, queueName + "-priority" , queues);
- Map<String, Object> lvqQueue = find(Queue.NAME, queueName + "-lvq" , queues);
-
- attributes.put(Queue.DURABLE, Boolean.TRUE);
- Asserts.assertQueue(queueName + "-standard", "standard", standardQueue, attributes);
- Asserts.assertQueue(queueName + "-sorted", "sorted", sortedQueue, attributes);
- Asserts.assertQueue(queueName + "-priority", "priority", priorityQueue, attributes);
- Asserts.assertQueue(queueName + "-lvq", "lvq", lvqQueue, attributes);
-
- assertEquals("Unexpected sorted key attribute", "sortme", sortedQueue.get(Queue.SORT_KEY));
- assertEquals("Unexpected lvq key attribute", "LVQ", lvqQueue.get(Queue.LVQ_KEY));
- assertEquals("Unexpected priorities key attribute", 10, priorityQueue.get(Queue.PRIORITIES));
- }
-
- @SuppressWarnings("unchecked")
- public void testCreateQueueWithDLQEnabled() throws Exception
- {
- String queueName = getTestQueueName();
-
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(AMQQueueFactory.X_QPID_DLQ_ENABLED, true);
-
- //verify the starting state
- Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
- List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_EXCHANGES_ATTRIBUTE);
-
- assertNull("queue should not have already been present", find(Queue.NAME, queueName , queues));
- assertNull("queue should not have already been present", find(Queue.NAME, queueName + "_DLQ" , queues));
- assertNull("exchange should not have already been present", find(Exchange.NAME, queueName + "_DLE" , exchanges));
-
- //create the queue
- createQueue(queueName, "standard", attributes);
-
- //verify the new queue, as well as the DLQueue and DLExchange have been created
- hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
- queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
- exchanges = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_EXCHANGES_ATTRIBUTE);
-
- Map<String, Object> queue = find(Queue.NAME, queueName , queues);
- Map<String, Object> dlqQueue = find(Queue.NAME, queueName + "_DLQ" , queues);
- Map<String, Object> dlExchange = find(Exchange.NAME, queueName + "_DLE" , exchanges);
- assertNotNull("queue should not have been present", queue);
- assertNotNull("queue should not have been present", dlqQueue);
- assertNotNull("exchange should not have been present", dlExchange);
-
- //verify that the alternate exchange is set as expected on the new queue
- Map<String, Object> queueAttributes = new HashMap<String, Object>();
- queueAttributes.put(Queue.ALTERNATE_EXCHANGE, queueName + "_DLE");
-
- Asserts.assertQueue(queueName, "standard", queue, queueAttributes);
- Asserts.assertQueue(queueName, "standard", queue, null);
- }
-
- private void createExchange(String exchangeName, String exchangeType) throws IOException
- {
- HttpURLConnection connection = openManagementConection("/rest/exchange/test/" + exchangeName, "PUT");
-
- Map<String, Object> queueData = new HashMap<String, Object>();
- queueData.put(Exchange.NAME, exchangeName);
- queueData.put(Exchange.DURABLE, Boolean.TRUE);
- queueData.put(Exchange.TYPE, exchangeType);
-
- writeJsonRequest(connection, queueData);
- assertEquals("Unexpected response code", 201, connection.getResponseCode());
-
- connection.disconnect();
- }
-
- private void createQueue(String queueName, String queueType, Map<String, Object> attributes) throws IOException,
- JsonGenerationException, JsonMappingException
- {
- int responseCode = tryCreateQueue(queueName, queueType, attributes);
- assertEquals("Unexpected response code", 201, responseCode);
- }
-
- private int tryCreateQueue(String queueName, String queueType, Map<String, Object> attributes) throws IOException,
- JsonGenerationException, JsonMappingException
- {
- HttpURLConnection connection = openManagementConection("/rest/queue/test/" + queueName, "PUT");
-
- Map<String, Object> queueData = new HashMap<String, Object>();
- queueData.put(Queue.NAME, queueName);
- queueData.put(Queue.DURABLE, Boolean.TRUE);
- if (queueType != null)
- {
- queueData.put(Queue.TYPE, queueType);
- }
- if (attributes != null)
- {
- queueData.putAll(attributes);
- }
-
- writeJsonRequest(connection, queueData);
- int responseCode = connection.getResponseCode();
- connection.disconnect();
- return responseCode;
- }
-
-}
diff --git a/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/session/LoginLogoutReporterTest.java b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/session/LoginLogoutReporterTest.java
new file mode 100644
index 0000000000..1d43c44587
--- /dev/null
+++ b/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/session/LoginLogoutReporterTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.management.plugin.session;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Matchers.argThat;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.LogMessage;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+import org.mockito.ArgumentMatcher;
+import org.mockito.Mockito;
+
+import junit.framework.TestCase;
+
+public class LoginLogoutReporterTest extends TestCase
+{
+ private LoginLogoutReporter _loginLogoutReport;
+ private Subject _subject = new Subject();
+ private LogActor _logActor = Mockito.mock(LogActor.class);
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ _subject.getPrincipals().add(new AuthenticatedPrincipal("mockusername"));
+ _loginLogoutReport = new LoginLogoutReporter(_logActor, _subject);
+ }
+
+ public void testLoginLogged()
+ {
+ _loginLogoutReport.valueBound(null);
+ verify(_logActor).message(isLogMessageWithMessage("MNG-1007 : Open : User mockusername"));
+ }
+
+ public void testLogoutLogged()
+ {
+ _loginLogoutReport.valueUnbound(null);
+ verify(_logActor).message(isLogMessageWithMessage("MNG-1008 : Close : User mockusername"));
+ }
+
+ private LogMessage isLogMessageWithMessage(final String expectedMessage)
+ {
+ return argThat( new ArgumentMatcher<LogMessage>()
+ {
+ @Override
+ public boolean matches(Object argument)
+ {
+ LogMessage actual = (LogMessage) argument;
+ return actual.toString().equals(expectedMessage);
+ }
+ });
+ }
+}
diff --git a/java/broker-plugins/management-jmx/MANIFEST.MF b/java/broker-plugins/management-jmx/MANIFEST.MF
deleted file mode 100644
index b18ec1ace7..0000000000
--- a/java/broker-plugins/management-jmx/MANIFEST.MF
+++ /dev/null
@@ -1,66 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Qpid Broker-Plugins Management JMX
-Bundle-SymbolicName: broker-plugins-management-jmx
-Bundle-Description: JMX management plugin for Qpid.
-Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
-Bundle-DocURL: http://www.apache.org/
-Bundle-Version: 1.0.0
-Bundle-Activator: org.apache.qpid.server.jmx.JMXActivator
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ClassPath: .
-Bundle-ActivationPolicy: lazy
-Import-Package: org.apache.qpid,
- org.apache.qpid.framing,
- org.apache.qpid.protocol,
- org.apache.qpid.common,
- org.apache.qpid.management.common.mbeans,
- org.apache.qpid.management.common.mbeans.annotations,
- org.apache.qpid.server.security.auth,
- org.apache.qpid.server.security.auth.manager,
- org.apache.qpid.server.security.auth.rmi,
- org.apache.qpid.server.security.auth.sasl,
- org.apache.qpid.server.binding,
- org.apache.qpid.server.exchange,
- org.apache.qpid.server.logging,
- org.apache.qpid.server.logging.log4j,
- org.apache.qpid.server.logging.actors,
- org.apache.qpid.server.logging.messages,
- org.apache.qpid.server.message,
- org.apache.qpid.server.model,
- org.apache.qpid.server.model.adapter,
- org.apache.qpid.server.model.impl,
- org.apache.qpid.server.configuration,
- org.apache.qpid.server.configuration.plugins,
- org.apache.qpid.server.connection,
- org.apache.qpid.server.plugins,
- org.apache.qpid.server.protocol,
- org.apache.qpid.server.queue,
- org.apache.qpid.server.registry,
- org.apache.qpid.server.security,
- org.apache.qpid.server.security.access,
- org.apache.qpid.server.stats,
- org.apache.qpid.server.virtualhost,
- org.apache.qpid.util,
- org.apache.commons.codec;version=1.3.0,
- org.apache.commons.codec.binary;version=1.3.0,
- org.apache.commons.configuration;version=1.0.0,
- org.apache.commons.lang;version=1.0.0,
- org.apache.commons.lang.builder;version=1.0.0,
- org.apache.commons.lang.time;version=1.0.0,
- org.apache.log4j;version=1.2.16,
- org.codehaus.jackson;version=1.9.0,
- org.codehaus.jackson.map;version=1.9.0,
- javax.management.remote.rmi,
- javax.management.remote,
- javax.servlet,
- javax.servlet.http,
- javax.management;version=1.0.0,
- javax.management.monitor;version=1.0.0,
- javax.management.openmbean;version=1.0.0,
- javax.security.auth.login;version=1.0.0,
- javax.security.auth;version=1.0.0,
- javax.rmi.ssl;version=1.0.0,
- org.osgi.util.tracker;version=1.0.0,
- org.osgi.framework;version=1.3
-Export-Package: org.apache.qpid.server.jmx;uses:="org.osgi.framework"
diff --git a/java/broker-plugins/management-jmx/build.xml b/java/broker-plugins/management-jmx/build.xml
index fa50b8467d..9d212cf39a 100644
--- a/java/broker-plugins/management-jmx/build.xml
+++ b/java/broker-plugins/management-jmx/build.xml
@@ -17,28 +17,14 @@
- under the License.
-->
<project name="Qpid Broker-Plugins Management JMX" default="build">
-
- <condition property="systests.optional.depends" value="bdbstore" else="">
- <or>
- <and>
- <contains string="${modules.opt}" substring="bdbstore"/>
- <contains string="${profile}" substring="bdb"/>
- </and>
- <and>
- <istrue value="${optional}"/>
- <contains string="${profile}" substring="bdb"/>
- </and>
- </or>
- </condition>
-
<property name="module.depends" value="common broker management/common" />
- <property name="module.test.depends" value="systests test broker/test common/test management/common client ${systests.optional.depends}" />
+ <property name="module.test.depends" value="broker/tests common/tests management/common client" />
- <property name="module.manifest" value="MANIFEST.MF" />
- <property name="module.plugin" value="true" />
<property name="module.genpom" value="true"/>
<property name="module.genpom.args" value="-Sqpid-common=provided -Sqpid-broker=provided -Sqpid-management-common=provided"/>
+ <property name="broker.plugin" value="true"/>
+
<property name="broker-plugins-management-jmx.libs" value=""/>
<import file="../../module.xml" />
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/CustomRMIServerSocketFactory.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/CustomRMIServerSocketFactory.java
new file mode 100644
index 0000000000..b7aab78e45
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/CustomRMIServerSocketFactory.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.jmx;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.rmi.server.RMIServerSocketFactory;
+
+/**
+ * Custom RMIServerSocketFactory class, used to prevent updates to the RMI registry.
+ * Supplied to the registry at creation, this will prevent RMI-based operations on the
+ * registry such as attempting to bind a new object, thereby securing it from tampering.
+ * This is accomplished by always returning null when attempting to determine the address
+ * of the caller, thus ensuring the registry will refuse the attempt. Calls to bind etc
+ * made using the object reference will not be affected and continue to operate normally.
+ */
+class CustomRMIServerSocketFactory implements RMIServerSocketFactory
+{
+
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ return new NoLocalAddressServerSocket(port);
+ }
+
+ private static class NoLocalAddressServerSocket extends ServerSocket
+ {
+ NoLocalAddressServerSocket(int port) throws IOException
+ {
+ super(port);
+ }
+
+ @Override
+ public Socket accept() throws IOException
+ {
+ Socket s = new NoLocalAddressSocket();
+ super.implAccept(s);
+ return s;
+ }
+ }
+
+ private static class NoLocalAddressSocket extends Socket
+ {
+ @Override
+ public InetAddress getInetAddress()
+ {
+ return null;
+ }
+ }
+} \ No newline at end of file
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXActivator.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXActivator.java
deleted file mode 100644
index c588b40de7..0000000000
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXActivator.java
+++ /dev/null
@@ -1,136 +0,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.
- *
- */
-package org.apache.qpid.server.jmx;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
-public class JMXActivator implements BundleActivator
-{
- private static final Logger LOGGER = Logger.getLogger(JMXActivator.class);
-
- private String _bundleName;
- private JMXService _jmxService;
-
- private List<ServiceRegistration> _registeredServices;
-
-
- public void start(final BundleContext ctx) throws Exception
- {
- boolean jmxManagementEnabled = ApplicationRegistry.getInstance().getConfiguration().getJMXManagementEnabled();
-
- if (jmxManagementEnabled)
- {
- _jmxService = new JMXService();
- startJmsService(_jmxService);
-
- _bundleName = ctx.getBundle().getSymbolicName();
-
- _registeredServices = registerServices(ctx);
- }
- else
- {
- LOGGER.debug("Skipping registration of JMX plugin as JMX Management disabled in config. ");
- }
- }
-
- public void stop(final BundleContext bundleContext) throws Exception
- {
- try
- {
- if (_jmxService != null)
- {
- if (LOGGER.isInfoEnabled())
- {
- LOGGER.info("Stopping jmx plugin: " + _bundleName);
- }
- _jmxService.close();
- }
-
- if (_registeredServices != null)
- {
- unregisterServices();
- }
- }
- finally
- {
- _jmxService = null;
- _registeredServices = null;
- }
- }
-
-
- private List<ServiceRegistration> registerServices(BundleContext ctx)
- {
- if (LOGGER.isInfoEnabled())
- {
- LOGGER.info("Registering jmx plugin: " + _bundleName);
- }
-
- List<ServiceRegistration> serviceRegistrations = new ArrayList<ServiceRegistration>();
-
- ServiceRegistration jmxServiceRegistration = ctx.registerService(JMXService.class.getName(), _jmxService, null);
- ServiceRegistration jmxConfigFactoryRegistration = ctx.registerService(ConfigurationPluginFactory.class.getName(), JMXConfiguration.FACTORY, null);
-
- serviceRegistrations.add(jmxServiceRegistration);
- serviceRegistrations.add(jmxConfigFactoryRegistration);
- return serviceRegistrations;
- }
-
- private void startJmsService(JMXService jmxService) throws Exception
- {
- if (LOGGER.isInfoEnabled())
- {
- LOGGER.info("Starting JMX service");
- }
- boolean startedSuccessfully = false;
- try
- {
- jmxService.start();
- startedSuccessfully = true;
- }
- finally
- {
- if (!startedSuccessfully)
- {
- LOGGER.error("JMX failed to start normally, closing service");
- jmxService.close();
- }
- }
- }
-
- private void unregisterServices()
- {
- for (Iterator<ServiceRegistration> iterator = _registeredServices.iterator(); iterator.hasNext();)
- {
- ServiceRegistration service = iterator.next();
- service.unregister();
- }
- }
-}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXConfiguration.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXConfiguration.java
deleted file mode 100644
index dc9a712f90..0000000000
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXConfiguration.java
+++ /dev/null
@@ -1,76 +0,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.
- *
- */
-package org.apache.qpid.server.jmx;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class JMXConfiguration extends ConfigurationPlugin
-{
- CompositeConfiguration _finalConfig;
-
- public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory()
- {
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- ConfigurationPlugin instance = new JMXConfiguration();
- instance.setConfiguration(path, config);
- return instance;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList("jmx");
- }
- };
-
- public String[] getElementsProcessed()
- {
- return new String[] { "" };
- }
-
- public Configuration getConfiguration()
- {
- return _finalConfig;
- }
-
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- // Valid Configuration either has xml links to new files
- _finalConfig = new CompositeConfiguration(getConfig());
- List subFiles = getConfig().getList("xml[@fileName]");
- for (Object subFile : subFiles)
- {
- _finalConfig.addConfiguration(new XMLConfiguration((String) subFile));
- }
-
- }
-
-}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java
index 0648235077..a045683de1 100644
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagedObjectRegistry.java
@@ -20,171 +20,114 @@
*/
package org.apache.qpid.server.jmx;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
-import org.apache.qpid.AMQException;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
-
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
import org.apache.qpid.server.security.auth.rmi.RMIPasswordAuthenticator;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
-import javax.management.Notification;
-import javax.management.NotificationFilterSupport;
-import javax.management.NotificationListener;
import javax.management.ObjectName;
-import javax.management.remote.JMXConnectionNotification;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXServiceURL;
import javax.management.remote.MBeanServerForwarder;
-import javax.management.remote.rmi.RMIConnection;
import javax.management.remote.rmi.RMIConnectorServer;
-import javax.management.remote.rmi.RMIJRMPServerImpl;
-import javax.management.remote.rmi.RMIServerImpl;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
-import javax.security.auth.Subject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.management.ManagementFactory;
-import java.lang.reflect.Proxy;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
import java.net.UnknownHostException;
import java.rmi.AlreadyBoundException;
import java.rmi.NoSuchObjectException;
import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RMIClientSocketFactory;
import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
/**
- * This class starts up an MBeanserver. If out of the box agent has been enabled then there are no
+ * This class starts up an MBeanserver. If out of the box agent has been enabled then there are no
* security features implemented like user authentication and authorisation.
*/
public class JMXManagedObjectRegistry implements ManagedObjectRegistry
{
private static final Logger _log = Logger.getLogger(JMXManagedObjectRegistry.class);
+ private static final String OPERATIONAL_LOGGING_NAME = "JMX";
+
private final MBeanServer _mbeanServer;
+
private JMXConnectorServer _cs;
private Registry _rmiRegistry;
- private boolean _useCustomSocketFactory;
- private final int _jmxPortRegistryServer;
- private final int _jmxPortConnectorServer;
+ private final Broker _broker;
+ private final Port _registryPort;
+ private final Port _connectorPort;
- public JMXManagedObjectRegistry() throws AMQException
+ public JMXManagedObjectRegistry(
+ Broker broker,
+ Port connectorPort, Port registryPort,
+ JMXManagement jmxManagement)
{
- _log.info("Initialising managed object registry using platform MBean server");
- IApplicationRegistry appRegistry = ApplicationRegistry.getInstance();
+ _broker = broker;
+ _registryPort = registryPort;
+ _connectorPort = connectorPort;
- // Retrieve the config parameters
- _useCustomSocketFactory = appRegistry.getConfiguration().getUseCustomRMISocketFactory();
- boolean platformServer = appRegistry.getConfiguration().getPlatformMbeanserver();
+ boolean usePlatformServer = (Boolean)jmxManagement.getAttribute(JMXManagement.USE_PLATFORM_MBEAN_SERVER);
_mbeanServer =
- platformServer ? ManagementFactory.getPlatformMBeanServer()
+ usePlatformServer ? ManagementFactory.getPlatformMBeanServer()
: MBeanServerFactory.createMBeanServer(ManagedObject.DOMAIN);
+ }
- _jmxPortRegistryServer = appRegistry.getConfiguration().getJMXPortRegistryServer();
- _jmxPortConnectorServer = appRegistry.getConfiguration().getJMXConnectorServerPort();
-
- }
-
- public void start() throws IOException, ConfigurationException
+ @Override
+ public void start() throws IOException
{
-
- CurrentActor.get().message(ManagementConsoleMessages.STARTUP());
+ CurrentActor.get().message(ManagementConsoleMessages.STARTUP(OPERATIONAL_LOGGING_NAME));
//check if system properties are set to use the JVM's out-of-the-box JMXAgent
if (areOutOfTheBoxJMXOptionsSet())
{
- CurrentActor.get().message(ManagementConsoleMessages.READY(true));
- return;
+ CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
}
+ else
+ {
+ startRegistryAndConnector();
+ }
+ }
- IApplicationRegistry appRegistry = ApplicationRegistry.getInstance();
-
-
- //Socket factories for the RMIConnectorServer, either default or SLL depending on configuration
+ private void startRegistryAndConnector() throws IOException
+ {
+ //Socket factories for the RMIConnectorServer, either default or SSL depending on configuration
RMIClientSocketFactory csf;
RMIServerSocketFactory ssf;
- //check ssl enabled option in config, default to true if option is not set
- boolean sslEnabled = appRegistry.getConfiguration().getManagementSSLEnabled();
+ //check ssl enabled option on connector port (note we don't provide ssl for registry server at
+ //moment).
+ boolean connectorSslEnabled = _connectorPort.getTransports().contains(Transport.SSL);
- if (sslEnabled)
+ if (connectorSslEnabled)
{
- //set the SSL related system properties used by the SSL RMI socket factories to the values
- //given in the configuration file, unless command line settings have already been specified
- String keyStorePath;
+ String keyStorePath = System.getProperty("javax.net.ssl.keyStore");
+ String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
- if(System.getProperty("javax.net.ssl.keyStore") != null)
- {
- keyStorePath = System.getProperty("javax.net.ssl.keyStore");
- }
- else
- {
- keyStorePath = appRegistry.getConfiguration().getManagementKeyStorePath();
- }
+ validateKeyStoreProperties(keyStorePath, keyStorePassword);
- //check the keystore path value is valid
- if (keyStorePath == null)
- {
- throw new ConfigurationException("JMX management SSL keystore path not defined, " +
- "unable to start SSL protected JMX ConnectorServer");
- }
- else
- {
- //ensure the system property is set
- System.setProperty("javax.net.ssl.keyStore", keyStorePath);
-
- //check the file is usable
- File ksf = new File(keyStorePath);
-
- if (!ksf.exists())
- {
- throw new FileNotFoundException("Cannot find JMX management SSL keystore file: " + ksf);
- }
- if (!ksf.canRead())
- {
- throw new FileNotFoundException("Cannot read JMX management SSL keystore file: "
- + ksf + ". Check permissions.");
- }
-
- CurrentActor.get().message(ManagementConsoleMessages.SSL_KEYSTORE(ksf.getAbsolutePath()));
- }
-
- //check the key store password is set
- if (System.getProperty("javax.net.ssl.keyStorePassword") == null)
- {
-
- if (appRegistry.getConfiguration().getManagementKeyStorePassword() == null)
- {
- throw new ConfigurationException("JMX management SSL keystore password not defined, " +
- "unable to start requested SSL protected JMX server");
- }
- else
- {
- System.setProperty("javax.net.ssl.keyStorePassword",
- appRegistry.getConfiguration().getManagementKeyStorePassword());
- }
- }
+ CurrentActor.get().message(ManagementConsoleMessages.SSL_KEYSTORE(keyStorePath));
//create the SSL RMI socket factories
csf = new SslRMIClientSocketFactory();
@@ -197,27 +140,23 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
ssf = null;
}
+ int jmxPortRegistryServer = _registryPort.getPort();
+ int jmxPortConnectorServer = _connectorPort.getPort();
+
//add a JMXAuthenticator implementation the env map to authenticate the RMI based JMX connector server
- RMIPasswordAuthenticator rmipa = new RMIPasswordAuthenticator(new InetSocketAddress(_jmxPortRegistryServer));
- HashMap<String,Object> env = new HashMap<String,Object>();
- env.put(JMXConnectorServer.AUTHENTICATOR, rmipa);
+ RMIPasswordAuthenticator rmipa = new RMIPasswordAuthenticator(_broker, new InetSocketAddress(jmxPortConnectorServer));
+ HashMap<String,Object> connectorEnv = new HashMap<String,Object>();
+ connectorEnv.put(JMXConnectorServer.AUTHENTICATOR, rmipa);
+
+ System.setProperty("java.rmi.server.randomIDs", "true");
+ boolean useCustomSocketFactory = Boolean.parseBoolean(System.getProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, Boolean.TRUE.toString()));
/*
* Start a RMI registry on the management port, to hold the JMX RMI ConnectorServer stub.
* Using custom socket factory to prevent anyone (including us unfortunately) binding to the registry using RMI.
* As a result, only binds made using the object reference will succeed, thus securing it from external change.
*/
- System.setProperty("java.rmi.server.randomIDs", "true");
- if(_useCustomSocketFactory)
- {
- _rmiRegistry = LocateRegistry.createRegistry(_jmxPortRegistryServer, null, new CustomRMIServerSocketFactory());
- }
- else
- {
- _rmiRegistry = LocateRegistry.createRegistry(_jmxPortRegistryServer, null, null);
- }
-
- CurrentActor.get().message(ManagementConsoleMessages.LISTENING("RMI Registry", _jmxPortRegistryServer));
+ _rmiRegistry = createRmiRegistry(jmxPortRegistryServer, useCustomSocketFactory);
/*
* We must now create the RMI ConnectorServer manually, as the JMX Factory methods use RMI calls
@@ -225,57 +164,16 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
* locked it from any RMI based modifications, including our own. Instead, we will manually bind
* the RMIConnectorServer stub to the registry using its object reference, which will still succeed.
*
- * The registry is exported on the defined management port 'port'. We will export the RMIConnectorServer
- * on 'port +1'. Use of these two well-defined ports will ease any navigation through firewall's.
+ * The registry is exported on the defined management port 'port'.
*/
- final Map<String, String> connectionIdUsernameMap = new ConcurrentHashMap<String, String>();
- final RMIServerImpl rmiConnectorServerStub = new RMIJRMPServerImpl(_jmxPortConnectorServer, csf, ssf, env)
- {
-
- /**
- * Override makeClient so we can cache the username of the client in a Map keyed by connectionId.
- * ConnectionId is guaranteed to be unique per client connection, according to the JMS spec.
- * An instance of NotificationListener (mapCleanupListener) will be responsible for removing these Map
- * entries.
- *
- * @see javax.management.remote.rmi.RMIJRMPServerImpl#makeClient(String, javax.security.auth.Subject)
- */
- @Override
- protected RMIConnection makeClient(String connectionId, Subject subject) throws IOException
- {
- final RMIConnection makeClient = super.makeClient(connectionId, subject);
- final UsernamePrincipal usernamePrincipalFromSubject = UsernamePrincipal.getUsernamePrincipalFromSubject(subject);
- connectionIdUsernameMap.put(connectionId, usernamePrincipalFromSubject.getName());
- return makeClient;
- }
- };
-
- // Create a Listener responsible for removing the map entries add by the #makeClient entry above.
- final NotificationListener mapCleanupListener = new NotificationListener()
- {
-
- public void handleNotification(Notification notification, Object handback)
- {
- final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
- connectionIdUsernameMap.remove(connectionId);
- }
- };
+ final UsernameCachingRMIJRMPServer usernameCachingRmiServer = new UsernameCachingRMIJRMPServer(jmxPortConnectorServer, csf, ssf, connectorEnv);
- String localHost;
- try
- {
- localHost = InetAddress.getLocalHost().getHostName();
- }
- catch(UnknownHostException ex)
- {
- localHost="127.0.0.1";
- }
- final String hostname = localHost;
+ final String localHostName = getLocalhost();
final JMXServiceURL externalUrl = new JMXServiceURL(
- "service:jmx:rmi://"+hostname+":"+(_jmxPortConnectorServer)+"/jndi/rmi://"+hostname+":"+_jmxPortRegistryServer+"/jmxrmi");
+ "service:jmx:rmi://"+localHostName+":"+(jmxPortConnectorServer)+"/jndi/rmi://"+localHostName+":"+jmxPortRegistryServer+"/jmxrmi");
- final JMXServiceURL internalUrl = new JMXServiceURL("rmi", hostname, _jmxPortConnectorServer);
- _cs = new RMIConnectorServer(internalUrl, env, rmiConnectorServerStub, _mbeanServer)
+ final JMXServiceURL internalUrl = new JMXServiceURL("rmi", localHostName, jmxPortConnectorServer);
+ _cs = new RMIConnectorServer(internalUrl, connectorEnv, usernameCachingRmiServer, _mbeanServer)
{
@Override
public synchronized void start() throws IOException
@@ -283,7 +181,7 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
try
{
//manually bind the connector server to the registry at key 'jmxrmi', like the out-of-the-box agent
- _rmiRegistry.bind("jmxrmi", rmiConnectorServerStub);
+ _rmiRegistry.bind("jmxrmi", usernameCachingRmiServer);
}
catch (AlreadyBoundException abe)
{
@@ -311,7 +209,6 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
}
catch (NotBoundException nbe)
{
- // TODO consider if we want to keep new logging
_log.error("Failed to unbind jmxrmi", nbe);
//ignore
}
@@ -326,97 +223,100 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
//must return our pre-crafted url that includes the full details, inc JNDI details
return externalUrl;
}
-
};
-
//Add the custom invoker as an MBeanServerForwarder, and start the RMIConnectorServer.
- MBeanServerForwarder mbsf = MBeanInvocationHandlerImpl.newProxyInstance();
+ MBeanServerForwarder mbsf = MBeanInvocationHandlerImpl.newProxyInstance(_broker);
_cs.setMBeanServerForwarder(mbsf);
+ // Install a ManagementLogonLogoffReporter so we can report as users logon/logoff
+ ManagementLogonLogoffReporter jmxManagementUserLogonLogoffReporter = new ManagementLogonLogoffReporter(_broker.getRootMessageLogger(), usernameCachingRmiServer);
+ _cs.addNotificationListener(jmxManagementUserLogonLogoffReporter, jmxManagementUserLogonLogoffReporter, null);
- // Get the handler that is used by the above MBInvocationHandler Proxy.
- // which is the MBeanInvocationHandlerImpl and so also a NotificationListener.
- final NotificationListener invocationHandler = (NotificationListener) Proxy.getInvocationHandler(mbsf);
-
- // Install a notification listener on OPENED, CLOSED, and FAILED,
- // passing the map of connection-ids to usernames as hand-back data.
- final NotificationFilterSupport invocationHandlerFilter = new NotificationFilterSupport();
- invocationHandlerFilter.enableType(JMXConnectionNotification.OPENED);
- invocationHandlerFilter.enableType(JMXConnectionNotification.CLOSED);
- invocationHandlerFilter.enableType(JMXConnectionNotification.FAILED);
- _cs.addNotificationListener(invocationHandler, invocationHandlerFilter, connectionIdUsernameMap);
-
- // Install a second notification listener on CLOSED AND FAILED only to remove the entry from the
- // Map. Here we rely on the fact that JMX will call the listeners in the order in which they are
- // installed.
- final NotificationFilterSupport mapCleanupHandlerFilter = new NotificationFilterSupport();
- mapCleanupHandlerFilter.enableType(JMXConnectionNotification.CLOSED);
- mapCleanupHandlerFilter.enableType(JMXConnectionNotification.FAILED);
- _cs.addNotificationListener(mapCleanupListener, mapCleanupHandlerFilter, null);
+ // Install the usernameCachingRmiServer as a listener so it may cleanup as clients disconnect
+ _cs.addNotificationListener(usernameCachingRmiServer, usernameCachingRmiServer, null);
_cs.start();
- String connectorServer = (sslEnabled ? "SSL " : "") + "JMX RMIConnectorServer";
- CurrentActor.get().message(ManagementConsoleMessages.LISTENING(connectorServer, _jmxPortConnectorServer));
-
- CurrentActor.get().message(ManagementConsoleMessages.READY(false));
+ String connectorServer = (connectorSslEnabled ? "SSL " : "") + "JMX RMIConnectorServer";
+ CurrentActor.get().message(ManagementConsoleMessages.LISTENING(connectorServer, jmxPortConnectorServer));
+ CurrentActor.get().message(ManagementConsoleMessages.READY(OPERATIONAL_LOGGING_NAME));
}
- /*
- * Custom RMIServerSocketFactory class, used to prevent updates to the RMI registry.
- * Supplied to the registry at creation, this will prevent RMI-based operations on the
- * registry such as attempting to bind a new object, thereby securing it from tampering.
- * This is accomplished by always returning null when attempting to determine the address
- * of the caller, thus ensuring the registry will refuse the attempt. Calls to bind etc
- * made using the object reference will not be affected and continue to operate normally.
- */
-
- private static class CustomRMIServerSocketFactory implements RMIServerSocketFactory
+ private Registry createRmiRegistry(int jmxPortRegistryServer, boolean useCustomRmiRegistry)
+ throws RemoteException
{
-
- public ServerSocket createServerSocket(int port) throws IOException
+ Registry rmiRegistry;
+ if(useCustomRmiRegistry)
{
- return new NoLocalAddressServerSocket(port);
+ _log.debug("Using custom RMIServerSocketFactory");
+ rmiRegistry = LocateRegistry.createRegistry(jmxPortRegistryServer, null, new CustomRMIServerSocketFactory());
}
-
- private static class NoLocalAddressServerSocket extends ServerSocket
+ else
{
- NoLocalAddressServerSocket(int port) throws IOException
- {
- super(port);
- }
+ _log.debug("Using default RMIServerSocketFactory");
+ rmiRegistry = LocateRegistry.createRegistry(jmxPortRegistryServer, null, null);
+ }
- @Override
- public Socket accept() throws IOException
- {
- Socket s = new NoLocalAddressSocket();
- super.implAccept(s);
- return s;
- }
+ CurrentActor.get().message(ManagementConsoleMessages.LISTENING("RMI Registry", jmxPortRegistryServer));
+ return rmiRegistry;
+ }
+
+ private void validateKeyStoreProperties(String keyStorePath, String keyStorePassword) throws FileNotFoundException
+ {
+ if (keyStorePath == null)
+ {
+ throw new IllegalConfigurationException("JVM system property 'javax.net.ssl.keyStore' is not set, "
+ + "unable to start requested SSL protected JMX connector");
+ }
+ if (keyStorePassword == null)
+ {
+ throw new IllegalConfigurationException( "JVM system property 'javax.net.ssl.keyStorePassword' is not set, "
+ + "unable to start requested SSL protected JMX connector");
}
- private static class NoLocalAddressSocket extends Socket
+ File ksf = new File(keyStorePath);
+ if (!ksf.exists())
{
- @Override
- public InetAddress getInetAddress()
- {
- return null;
- }
+ throw new FileNotFoundException("Cannot find JMX management SSL keystore file: " + ksf);
+ }
+ if (!ksf.canRead())
+ {
+ throw new FileNotFoundException("Cannot read JMX management SSL keystore file: "
+ + ksf + ". Check permissions.");
}
}
-
+ @Override
public void registerObject(ManagedObject managedObject) throws JMException
{
_mbeanServer.registerMBean(managedObject, managedObject.getObjectName());
}
+ @Override
public void unregisterObject(ManagedObject managedObject) throws JMException
{
_mbeanServer.unregisterMBean(managedObject.getObjectName());
}
+ @Override
+ public void close()
+ {
+ _log.debug("close() called");
+
+ closeConnectorAndRegistryServers();
+
+ unregisterAllMbeans();
+
+ CurrentActor.get().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME));
+ }
+
+ private void closeConnectorAndRegistryServers()
+ {
+ closeConnectorServer();
+ closeRegistryServer();
+ }
+
// checks if the system properties are set which enable the JVM's out-of-the-box JMXAgent.
private boolean areOutOfTheBoxJMXOptionsSet()
{
@@ -433,29 +333,26 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
return false;
}
- //Stops the JMXConnectorServer and RMIRegistry, then unregisters any remaining MBeans from the MBeanServer
- public void close()
+ private String getLocalhost()
{
- _log.debug("close() called");
-
- if (_cs != null)
+ String localHost;
+ try
{
- // Stopping the JMX ConnectorServer
- try
- {
- CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("JMX RMIConnectorServer", _cs.getAddress().getPort()));
- _cs.stop();
- }
- catch (IOException e)
- {
- _log.error("Exception while closing the JMX ConnectorServer: ", e);
- }
+ localHost = InetAddress.getLocalHost().getHostName();
}
-
+ catch(UnknownHostException ex)
+ {
+ localHost="127.0.0.1";
+ }
+ return localHost;
+ }
+
+ private void closeRegistryServer()
+ {
if (_rmiRegistry != null)
{
// Stopping the RMI registry
- CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("RMI Registry", _jmxPortRegistryServer));
+ CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("RMI Registry", _registryPort.getPort()));
try
{
boolean success = UnicastRemoteObject.unexportObject(_rmiRegistry, false);
@@ -468,8 +365,36 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
{
_log.error("Exception while closing the RMI Registry: ", e);
}
+ finally
+ {
+ _rmiRegistry = null;
+ }
+ }
+ }
+
+ private void closeConnectorServer()
+ {
+ if (_cs != null)
+ {
+ // Stopping the JMX ConnectorServer
+ try
+ {
+ CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("JMX RMIConnectorServer", _cs.getAddress().getPort()));
+ _cs.stop();
+ }
+ catch (IOException e)
+ {
+ _log.error("Exception while closing the JMX ConnectorServer: ", e);
+ }
+ finally
+ {
+ _cs = null;
+ }
}
-
+ }
+
+ private void unregisterAllMbeans()
+ {
//ObjectName query to gather all Qpid related MBeans
ObjectName mbeanNameQuery = null;
try
@@ -492,8 +417,6 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry
_log.error("Exception unregistering MBean '"+ name +"': " + e.getMessage());
}
}
-
- CurrentActor.get().message(ManagementConsoleMessages.STOPPED());
}
}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.java
new file mode 100644
index 0000000000..8f087ba50c
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagement.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.server.jmx;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.management.JMException;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.jmx.mbeans.LoggingManagementMBean;
+import org.apache.qpid.server.jmx.mbeans.UserManagementMBean;
+import org.apache.qpid.server.jmx.mbeans.ServerInformationMBean;
+import org.apache.qpid.server.jmx.mbeans.Shutdown;
+import org.apache.qpid.server.jmx.mbeans.VirtualHostMBean;
+import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
+import org.apache.qpid.server.model.AuthenticationProvider;
+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.PasswordCredentialManagingAuthenticationProvider;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+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.plugin.QpidServiceLoader;
+import org.apache.qpid.server.util.MapValueConverter;
+
+public class JMXManagement extends AbstractPluginAdapter implements ConfigurationChangeListener
+{
+ private static final Logger LOGGER = Logger.getLogger(JMXManagement.class);
+
+ public static final String PLUGIN_TYPE = "MANAGEMENT-JMX";
+
+ // attributes
+ public static final String USE_PLATFORM_MBEAN_SERVER = "usePlatformMBeanServer";
+ public static final String NAME = "name";
+
+ // default values
+ public static final String DEFAULT_NAME = "JMXManagement";
+ public static final boolean DEFAULT_USE_PLATFORM_MBEAN_SERVER = true;
+
+ @SuppressWarnings("serial")
+ private static final Collection<String> AVAILABLE_ATTRIBUTES = Collections.unmodifiableCollection(new HashSet<String>(Plugin.AVAILABLE_ATTRIBUTES){{
+ add(NAME);
+ add(USE_PLATFORM_MBEAN_SERVER);
+ add(PluginFactory.PLUGIN_TYPE);
+ }});
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Object> DEFAULTS = new HashMap<String, Object>(){{
+ put(USE_PLATFORM_MBEAN_SERVER, DEFAULT_USE_PLATFORM_MBEAN_SERVER);
+ put(NAME, DEFAULT_NAME);
+ put(PluginFactory.PLUGIN_TYPE, PLUGIN_TYPE);
+ }};
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Class<?>> ATTRIBUTE_TYPES = new HashMap<String, Class<?>>(){{
+ put(USE_PLATFORM_MBEAN_SERVER, Boolean.class);
+ put(NAME, String.class);
+ put(PluginFactory.PLUGIN_TYPE, String.class);
+ }};
+
+ private final Broker _broker;
+ private JMXManagedObjectRegistry _objectRegistry;
+
+ private final Map<ConfiguredObject, AMQManagedObject> _children = new HashMap<ConfiguredObject, AMQManagedObject>();
+
+ public JMXManagement(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), broker.getTaskExecutor());
+ _broker = broker;
+ addParent(Broker.class, broker);
+ }
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if(desiredState == State.ACTIVE)
+ {
+ try
+ {
+ start();
+ }
+ catch (JMException e)
+ {
+ throw new RuntimeException("Couldn't start JMX management", e);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Couldn't start JMX management", e);
+ }
+ return true;
+ }
+ else if(desiredState == State.STOPPED)
+ {
+ stop();
+ return true;
+ }
+ return false;
+ }
+
+ private void start() throws JMException, IOException
+ {
+ Port connectorPort = null;
+ Port registryPort = null;
+ Collection<Port> ports = _broker.getPorts();
+ for (Port port : ports)
+ {
+ if (State.QUIESCED.equals(port.getActualState()))
+ {
+ continue;
+ }
+
+ if(isRegistryPort(port))
+ {
+ registryPort = port;
+ }
+ else if(isConnectorPort(port))
+ {
+ connectorPort = port;
+ }
+ }
+ if(connectorPort == null)
+ {
+ throw new IllegalStateException("No JMX connector port found supporting protocol " + Protocol.JMX_RMI);
+ }
+ if(registryPort == null)
+ {
+ throw new IllegalStateException("No JMX RMI port found supporting protocol " + Protocol.RMI);
+ }
+
+ _objectRegistry = new JMXManagedObjectRegistry(_broker, connectorPort, registryPort, this);
+
+ _broker.addChangeListener(this);
+
+ synchronized (_children)
+ {
+ for(VirtualHost virtualHost : _broker.getVirtualHosts())
+ {
+ if(!_children.containsKey(virtualHost))
+ {
+ LOGGER.debug("Create MBean for virtual host:" + virtualHost.getName());
+ VirtualHostMBean mbean = new VirtualHostMBean(virtualHost, _objectRegistry);
+ LOGGER.debug("Check for additional MBeans for virtual host:" + virtualHost.getName());
+ createAdditionalMBeansFromProviders(virtualHost, mbean);
+ }
+ }
+ Collection<AuthenticationProvider> authenticationProviders = _broker.getAuthenticationProviders();
+ for (AuthenticationProvider authenticationProvider : authenticationProviders)
+ {
+ if(authenticationProvider instanceof PasswordCredentialManagingAuthenticationProvider)
+ {
+ UserManagementMBean mbean = new UserManagementMBean(
+ (PasswordCredentialManagingAuthenticationProvider) authenticationProvider,
+ _objectRegistry);
+ _children.put(authenticationProvider, mbean);
+ }
+ }
+ }
+ new Shutdown(_objectRegistry);
+ new ServerInformationMBean(_objectRegistry, _broker);
+ if (LoggingManagementFacade.getCurrentInstance() != null)
+ {
+ new LoggingManagementMBean(LoggingManagementFacade.getCurrentInstance(), _objectRegistry);
+ }
+ _objectRegistry.start();
+ }
+
+ private boolean isConnectorPort(Port port)
+ {
+ return port.getProtocols().contains(Protocol.JMX_RMI);
+ }
+
+ private boolean isRegistryPort(Port port)
+ {
+ return port.getProtocols().contains(Protocol.RMI);
+ }
+
+ private void stop()
+ {
+ synchronized (_children)
+ {
+ for(ConfiguredObject object : _children.keySet())
+ {
+ AMQManagedObject mbean = _children.get(object);
+ if (mbean instanceof ConfigurationChangeListener)
+ {
+ object.removeChangeListener((ConfigurationChangeListener)mbean);
+ }
+ try
+ {
+ mbean.unregister();
+ }
+ catch (JMException e)
+ {
+ LOGGER.error("Error unregistering mbean", e);
+ }
+ }
+ _children.clear();
+ }
+ _broker.removeChangeListener(this);
+ _objectRegistry.close();
+ }
+
+ @Override
+ public void stateChanged(ConfiguredObject object, State oldState, State newState)
+ {
+ // no-op
+ }
+
+ @Override
+ public void childAdded(ConfiguredObject object, ConfiguredObject child)
+ {
+ synchronized (_children)
+ {
+ try
+ {
+ AMQManagedObject mbean;
+ if(child instanceof VirtualHost)
+ {
+ VirtualHost vhostChild = (VirtualHost)child;
+ mbean = new VirtualHostMBean(vhostChild, _objectRegistry);
+ }
+ else if(child instanceof PasswordCredentialManagingAuthenticationProvider)
+ {
+ mbean = new UserManagementMBean((PasswordCredentialManagingAuthenticationProvider) child, _objectRegistry);
+ }
+ else
+ {
+ mbean = null;
+ }
+
+ if (mbean != null)
+ {
+ createAdditionalMBeansFromProviders(child, mbean);
+ }
+ }
+ catch(JMException e)
+ {
+ LOGGER.error("Error creating mbean", e);
+ // TODO - Implement error reporting on mbean creation
+ }
+ }
+ }
+
+ @Override
+ public void childRemoved(ConfiguredObject object, ConfiguredObject child)
+ {
+ // TODO - implement vhost removal (possibly just removing the instanceof check below)
+
+ synchronized (_children)
+ {
+ if(child instanceof PasswordCredentialManagingAuthenticationProvider)
+ {
+ AMQManagedObject mbean = _children.remove(child);
+ if(mbean != null)
+ {
+ try
+ {
+ mbean.unregister();
+ }
+ catch(JMException e)
+ {
+ LOGGER.error("Error creating mbean", e);
+ //TODO - report error on removing child MBean
+ }
+ }
+ }
+
+ }
+ }
+
+ @Override
+ public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue)
+ {
+ // no-op
+ }
+
+ private void createAdditionalMBeansFromProviders(ConfiguredObject child, AMQManagedObject mbean) throws JMException
+ {
+ _children.put(child, mbean);
+
+ QpidServiceLoader<MBeanProvider> qpidServiceLoader = new QpidServiceLoader<MBeanProvider>();
+ for (MBeanProvider provider : qpidServiceLoader.instancesOf(MBeanProvider.class))
+ {
+ LOGGER.debug("Consulting mbean provider : " + provider + " for child : " + child);
+ if (provider.isChildManageableByMBean(child))
+ {
+ LOGGER.debug("Provider will create mbean ");
+ provider.createMBean(child, mbean);
+ // TODO track the mbeans that have been created on behalf of a child in a map, then
+ // if the child is ever removed, destroy these beans too.
+ }
+ }
+ }
+
+ /** Added for testing purposes */
+ Broker getBroker()
+ {
+ return _broker;
+ }
+
+ @Override
+ public String getName()
+ {
+ return (String)getAttribute(NAME);
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.java
new file mode 100644
index 0000000000..c2186c372b
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXManagementFactory.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.server.jmx;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
+
+public class JMXManagementFactory implements PluginFactory
+{
+ private static final Logger LOGGER = Logger.getLogger(JMXManagementFactory.class);
+
+ @Override
+ public Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker)
+ {
+ if (JMXManagement.PLUGIN_TYPE.equals(attributes.get(PLUGIN_TYPE)))
+ {
+ return new JMXManagement(id, broker, attributes);
+ }
+ else
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Skipping registration of JMX plugin as JMX Management disabled in config.");
+ }
+ return null;
+ }
+ }
+}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXService.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXService.java
deleted file mode 100644
index 7a232d2584..0000000000
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/JMXService.java
+++ /dev/null
@@ -1,193 +0,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.
- *
- */
-
-package org.apache.qpid.server.jmx;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.ServiceLoader;
-
-import javax.management.JMException;
-import javax.management.StandardMBean;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.jmx.mbeans.LoggingManagementMBean;
-import org.apache.qpid.server.jmx.mbeans.UserManagementMBean;
-import org.apache.qpid.server.jmx.mbeans.ConfigurationManagementMBean;
-import org.apache.qpid.server.jmx.mbeans.ServerInformationMBean;
-import org.apache.qpid.server.jmx.mbeans.Shutdown;
-import org.apache.qpid.server.jmx.mbeans.VirtualHostMBean;
-import org.apache.qpid.server.logging.log4j.LoggingFacade;
-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.PasswordCredentialManagingAuthenticationProvider;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-
-public class JMXService implements ConfigurationChangeListener
-{
- private static final ClassLoader BUNDLE_CLASSLOADER = JMXService.class.getClassLoader();
-
- private static final Logger LOGGER = Logger.getLogger(JMXService.class);
-
- private final Broker _broker;
- private final JMXManagedObjectRegistry _objectRegistry;
- private final Shutdown _shutdown;
- private final ServerInformationMBean _serverInfo;
- private final ConfigurationManagementMBean _configManagement;
- private final LoggingManagementMBean _loggingManagement;
-
- private final Map<ConfiguredObject, AMQManagedObject> _children = new HashMap<ConfiguredObject, AMQManagedObject>();
-
- public JMXService() throws AMQException, JMException
- {
- _broker = ApplicationRegistry.getInstance().getBroker();
- _objectRegistry = new JMXManagedObjectRegistry();
-
- _broker.addChangeListener(this);
- synchronized (_children)
- {
- for(VirtualHost virtualHost : _broker.getVirtualHosts())
- {
- if(!_children.containsKey(virtualHost))
- {
- _children.put(virtualHost, new VirtualHostMBean(virtualHost, _objectRegistry));
- }
- }
- }
- _shutdown = new Shutdown(_objectRegistry);
- _serverInfo = new ServerInformationMBean(_objectRegistry, _broker);
- _configManagement = new ConfigurationManagementMBean(_objectRegistry);
- _loggingManagement = new LoggingManagementMBean(LoggingFacade.getCurrentInstance(), _objectRegistry);
- }
-
- public void start() throws IOException, ConfigurationException
- {
- _objectRegistry.start();
- }
-
- public void close()
- {
- _broker.removeChangeListener(this);
-
- _objectRegistry.close();
- }
-
- public void stateChanged(ConfiguredObject object, State oldState, State newState)
- {
-
- }
-
- public void childAdded(ConfiguredObject object, ConfiguredObject child)
- {
- synchronized (_children)
- {
- try
- {
- AMQManagedObject mbean;
- if(child instanceof VirtualHost)
- {
- VirtualHost vhostChild = (VirtualHost)child;
- mbean = new VirtualHostMBean(vhostChild, _objectRegistry);
- }
- else if(child instanceof PasswordCredentialManagingAuthenticationProvider)
- {
- mbean = new UserManagementMBean((PasswordCredentialManagingAuthenticationProvider) child, _objectRegistry);
- }
- else
- {
- mbean = null;
- }
-
- if (mbean != null)
- {
- createAdditionalMBeansFromProviders(child, mbean);
- }
- }
- catch(JMException e)
- {
- LOGGER.error("Error creating mbean", e);
- // TODO - Implement error reporting on mbean creation
- }
- }
- }
-
-
- public void childRemoved(ConfiguredObject object, ConfiguredObject child)
- {
- // TODO - implement vhost removal (possibly just removing the instanceof check below)
-
- synchronized (_children)
- {
- if(child instanceof PasswordCredentialManagingAuthenticationProvider)
- {
- AMQManagedObject mbean = _children.remove(child);
- if(mbean != null)
- {
- try
- {
- mbean.unregister();
- }
- catch(JMException e)
- {
- LOGGER.error("Error creating mbean", e);
- //TODO - report error on removing child MBean
- }
- }
- }
-
- }
- }
-
- private void createAdditionalMBeansFromProviders(ConfiguredObject child, AMQManagedObject mbean) throws JMException
- {
- _children.put(child, mbean);
-
- for (Iterator<MBeanProvider> iterator = getMBeanProviderIterator(); iterator.hasNext();)
- {
- MBeanProvider provider = iterator.next();
- LOGGER.debug("Consulting mbean provider : " + provider + " for child : " + child);
- if (provider.isChildManageableByMBean(child))
- {
- LOGGER.debug("Provider will create mbean ");
- StandardMBean bean = provider.createMBean(child, mbean);
- // TODO track the mbeans that have been created on behalf of a child in a map, then
- // if the child is ever removed, destroy these beans too.
- }
- }
- }
-
- /**
- * Finds all classes implementing the {@link MBeanProvider} interface. This will find
- * <b>only</b> those classes which are visible to the classloader of this OSGI bundle.
- */
- private Iterator<MBeanProvider> getMBeanProviderIterator()
- {
- return ServiceLoader.load(MBeanProvider.class, BUNDLE_CLASSLOADER).iterator();
- }
-}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java
index a2a0d2d093..8bc2afb176 100644
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanInvocationHandlerImpl.java
@@ -22,26 +22,22 @@ package org.apache.qpid.server.jmx;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.ManagementActor;
-import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
import javax.management.Attribute;
import javax.management.JMException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
-import javax.management.Notification;
-import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.RuntimeErrorException;
-import javax.management.remote.JMXConnectionNotification;
-import javax.management.remote.JMXPrincipal;
import javax.management.remote.MBeanServerForwarder;
import javax.security.auth.Subject;
import java.lang.reflect.InvocationHandler;
@@ -51,27 +47,32 @@ import java.lang.reflect.Proxy;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.Arrays;
-import java.util.Map;
-import java.util.Set;
/**
* This class can be used by the JMXConnectorServer as an InvocationHandler for the mbean operations. It delegates
* JMX access decisions to the SecurityPlugin.
*/
-public class MBeanInvocationHandlerImpl implements InvocationHandler, NotificationListener
+public class MBeanInvocationHandlerImpl implements InvocationHandler
{
private static final Logger _logger = Logger.getLogger(MBeanInvocationHandlerImpl.class);
- private final IApplicationRegistry _appRegistry = ApplicationRegistry.getInstance();
private final static String DELEGATE = "JMImplementation:type=MBeanServerDelegate";
private MBeanServer _mbs;
- private final ManagementActor _logActor = new ManagementActor(_appRegistry.getRootMessageLogger());
- private final boolean _managementRightsInferAllAccess =
- _appRegistry.getConfiguration().getManagementRightsInferAllAccess();
+ private final ManagementActor _logActor;
- public static MBeanServerForwarder newProxyInstance()
+ private final boolean _managementRightsInferAllAccess;
+ private final Broker _broker;
+
+ MBeanInvocationHandlerImpl(Broker broker)
+ {
+ _managementRightsInferAllAccess = Boolean.valueOf(System.getProperty(BrokerProperties.PROPERTY_MANAGEMENT_RIGHTS_INFER_ALL_ACCESS, "true"));
+ _broker = broker;
+ _logActor = new ManagementActor(broker.getRootMessageLogger());
+ }
+
+ public static MBeanServerForwarder newProxyInstance(Broker broker)
{
- final InvocationHandler handler = new MBeanInvocationHandlerImpl();
+ final InvocationHandler handler = new MBeanInvocationHandlerImpl(broker);
final Class<?>[] interfaces = new Class[] { MBeanServerForwarder.class };
Object proxy = Proxy.newProxyInstance(MBeanServerForwarder.class.getClassLoader(), interfaces, handler);
@@ -101,7 +102,7 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler, Notificati
{
ObjectName mbean = (ObjectName) args[0];
- if(!DefaultManagedObject.DOMAIN.equalsIgnoreCase(mbean.getDomain()))
+ if(!ManagedObject.DOMAIN.equalsIgnoreCase(mbean.getDomain()))
{
return true;
}
@@ -151,11 +152,13 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler, Notificati
return method.invoke(_mbs, args);
}
- // Retrieve JMXPrincipal from Subject
- Set<JMXPrincipal> principals = subject.getPrincipals(JMXPrincipal.class);
- if (principals == null || principals.isEmpty())
+ try
+ {
+ AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(subject);
+ }
+ catch(Exception e)
{
- throw new SecurityException("Access denied: no JMX principal");
+ throw new SecurityException("Access denied: no authenticated principal", e);
}
// Save the subject
@@ -211,11 +214,16 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler, Notificati
SecurityManager security;
if (vhost == null)
{
- security = _appRegistry.getSecurityManager();
+ security = _broker.getSecurityManager();
}
else
{
- security = _appRegistry.getVirtualHostRegistry().getVirtualHost(vhost).getSecurityManager();
+ VirtualHost virtualHost = _broker.findVirtualHostByName(vhost);
+ if (virtualHost == null)
+ {
+ throw new IllegalArgumentException("Virtual host with name '" + vhost + "' is not found.");
+ }
+ security = virtualHost.getSecurityManager();
}
methodName = getMethodName(method, args);
@@ -360,50 +368,5 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler, Notificati
return (methodName.startsWith("query") || methodName.startsWith("get") || methodName.startsWith("is"));
}
- /**
- * Receives notifications from the MBeanServer.
- */
- public void handleNotification(final Notification notification, final Object handback)
- {
- assert notification instanceof JMXConnectionNotification;
-
- final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
- final String type = notification.getType();
-
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Notification connectionId : " + connectionId + " type : " + type
- + " Notification handback : " + handback);
- }
-
- // Normally JMXManagedObjectRegistry provides a Map as handback data containing a map
- // between connection id and username.
- String user = null;
- if (handback instanceof Map)
- {
- final Map<String, String> connectionIdUsernameMap = (Map<String, String>) handback;
- user = connectionIdUsernameMap.get(connectionId);
- }
-
- // If user is still null, fallback to an unordered list of Principals from the connection id.
- if (user == null)
- {
- final String[] splitConnectionId = connectionId.split(" ");
- user = splitConnectionId[1];
- }
-
- // use a separate instance of actor as subject is not set on connect/disconnect
- // we need to pass principal name explicitly into log actor
- LogActor logActor = new ManagementActor(_appRegistry.getRootMessageLogger(), user);
- if (JMXConnectionNotification.OPENED.equals(type))
- {
- logActor.message(ManagementConsoleMessages.OPEN(user));
- }
- else if (JMXConnectionNotification.CLOSED.equals(type) ||
- JMXConnectionNotification.FAILED.equals(type))
- {
- logActor.message(ManagementConsoleMessages.CLOSE(user));
- }
- }
}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanProvider.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanProvider.java
index 83909dbe72..b80ddc7fac 100644
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanProvider.java
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/MBeanProvider.java
@@ -21,17 +21,16 @@
package org.apache.qpid.server.jmx;
-import java.util.ServiceLoader;
-
import javax.management.JMException;
import javax.management.StandardMBean;
import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
/**
* A provider of an mbean implementation.
*
- * Provider implementations are advertised as services and loaded via {@link ServiceLoader}.
+ * Provider implementations are advertised as services and loaded by a {@link QpidServiceLoader}.
*/
public interface MBeanProvider
{
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporter.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporter.java
new file mode 100644
index 0000000000..ae0574dc21
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporter.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.server.jmx;
+
+import static javax.management.remote.JMXConnectionNotification.CLOSED;
+import static javax.management.remote.JMXConnectionNotification.FAILED;
+import static javax.management.remote.JMXConnectionNotification.OPENED;
+
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.remote.JMXConnectionNotification;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.actors.ManagementActor;
+import org.apache.qpid.server.logging.messages.ManagementConsoleMessages;
+
+public class ManagementLogonLogoffReporter implements NotificationListener, NotificationFilter
+{
+ private static final Logger LOGGER = Logger.getLogger(ManagementLogonLogoffReporter.class);
+ private final RootMessageLogger _rootMessageLogger;
+ private final UsernameAccessor _usernameAccessor;
+
+ public ManagementLogonLogoffReporter(RootMessageLogger rootMessageLogger, UsernameAccessor usernameAccessor)
+ {
+ _rootMessageLogger = rootMessageLogger;
+ _usernameAccessor = usernameAccessor;
+ }
+
+ @Override
+ public void handleNotification(final Notification notification, final Object handback)
+ {
+ final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
+ final String type = notification.getType();
+
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Notification connectionId : " + connectionId + " type : " + type);
+ }
+
+ String user = _usernameAccessor.getUsernameForConnectionId(connectionId);
+
+ // If user is still null, fallback to an unordered list of Principals from the connection id.
+ if (user == null)
+ {
+ final String[] splitConnectionId = connectionId.split(" ");
+ user = splitConnectionId[1];
+ }
+
+ // use a separate instance of actor as subject is not set on connect/disconnect
+ // we need to pass principal name explicitly into log actor
+ LogActor logActor = new ManagementActor(_rootMessageLogger, user);
+ if (JMXConnectionNotification.OPENED.equals(type))
+ {
+ logActor.message(ManagementConsoleMessages.OPEN(user));
+ }
+ else if (JMXConnectionNotification.CLOSED.equals(type) ||
+ JMXConnectionNotification.FAILED.equals(type))
+ {
+ logActor.message(ManagementConsoleMessages.CLOSE(user));
+ }
+ }
+
+ @Override
+ public boolean isNotificationEnabled(Notification notification)
+ {
+ return notification instanceof JMXConnectionNotification && isLogonTypeEvent(notification);
+ }
+
+ private boolean isLogonTypeEvent(Notification notification)
+ {
+ final String type = notification.getType();
+ return CLOSED.equals(type) || FAILED.equals(type) || OPENED.equals(type);
+ }
+
+}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameAccessor.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameAccessor.java
new file mode 100644
index 0000000000..0cbb0d2687
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameAccessor.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.jmx;
+
+public interface UsernameAccessor
+{
+ public String getUsernameForConnectionId(String connectionId);
+
+}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameCachingRMIJRMPServer.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameCachingRMIJRMPServer.java
new file mode 100644
index 0000000000..838e9e5664
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/UsernameCachingRMIJRMPServer.java
@@ -0,0 +1,100 @@
+/*
+ * 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.jmx;
+
+import static javax.management.remote.JMXConnectionNotification.CLOSED;
+import static javax.management.remote.JMXConnectionNotification.FAILED;
+
+import java.io.IOException;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.remote.JMXConnectionNotification;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.rmi.RMIConnection;
+import javax.management.remote.rmi.RMIJRMPServerImpl;
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+
+/**
+ * An implementation of RMIJRMPServerImpl that caches the usernames of users as they log-on
+ * and makes the same available via {@link UsernameAccessor#getUsernameForConnectionId(String)}.
+ *
+ * Caller is responsible for installing this object as a {@link NotificationListener} of the
+ * {@link JMXConnectorServer} so the cache entries are removed as the clients disconnect.
+ *
+ */
+public class UsernameCachingRMIJRMPServer extends RMIJRMPServerImpl implements NotificationListener, NotificationFilter, UsernameAccessor
+{
+ // ConnectionId is guaranteed to be unique per client connection, according to the JMX spec.
+ private final Map<String, String> _connectionIdUsernameMap = new ConcurrentHashMap<String, String>();
+
+ UsernameCachingRMIJRMPServer(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf,
+ Map<String, ?> env) throws IOException
+ {
+ super(port, csf, ssf, env);
+ }
+
+ @Override
+ protected RMIConnection makeClient(String connectionId, Subject subject) throws IOException
+ {
+ final RMIConnection makeClient = super.makeClient(connectionId, subject);
+ final AuthenticatedPrincipal authenticatedPrincipalFromSubject = AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(subject);
+ _connectionIdUsernameMap.put(connectionId, authenticatedPrincipalFromSubject.getName());
+ return makeClient;
+ }
+
+ @Override
+ public String getUsernameForConnectionId(String connectionId)
+ {
+ return _connectionIdUsernameMap.get(connectionId);
+ }
+
+ @Override
+ public void handleNotification(Notification notification, Object handback)
+ {
+ final String connectionId = ((JMXConnectionNotification) notification).getConnectionId();
+ removeConnectionIdFromCache(connectionId);
+ }
+
+ @Override
+ public boolean isNotificationEnabled(Notification notification)
+ {
+ return isClientDisconnectEvent(notification);
+ }
+
+ private void removeConnectionIdFromCache(String connectionId)
+ {
+ _connectionIdUsernameMap.remove(connectionId);
+ }
+
+ private boolean isClientDisconnectEvent(Notification notification)
+ {
+ final String type = notification.getType();
+ return CLOSED.equals(type) || FAILED.equals(type);
+ }
+
+} \ No newline at end of file
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConfigurationManagementMBean.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConfigurationManagementMBean.java
deleted file mode 100644
index beffb4eaa9..0000000000
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/ConfigurationManagementMBean.java
+++ /dev/null
@@ -1,56 +0,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.
- *
- */
-package org.apache.qpid.server.jmx.mbeans;
-
-import org.apache.qpid.management.common.mbeans.ConfigurationManagement;
-import org.apache.qpid.server.jmx.AMQManagedObject;
-import org.apache.qpid.server.jmx.ManagedObject;
-import org.apache.qpid.server.jmx.ManagedObjectRegistry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-import javax.management.JMException;
-import javax.management.NotCompliantMBeanException;
-
-public class ConfigurationManagementMBean extends AMQManagedObject implements ConfigurationManagement
-{
-
- public ConfigurationManagementMBean(ManagedObjectRegistry registry) throws JMException
- {
- super(ConfigurationManagement.class, ConfigurationManagement.TYPE, registry);
- register();
- }
-
- public String getObjectInstanceName()
- {
- return ConfigurationManagement.TYPE;
- }
-
- public void reloadSecurityConfiguration() throws Exception
- {
- ApplicationRegistry.getInstance().getConfiguration().reparseConfigFileSecuritySections();
- }
-
- @Override
- public ManagedObject getParentObject()
- {
- return null;
- }
-}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBean.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBean.java
index 0dac8ebe37..d6f4b5d8c9 100644
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBean.java
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBean.java
@@ -26,7 +26,7 @@ import org.apache.qpid.management.common.mbeans.annotations.MBeanDescription;
import org.apache.qpid.server.jmx.AMQManagedObject;
import org.apache.qpid.server.jmx.ManagedObject;
import org.apache.qpid.server.jmx.ManagedObjectRegistry;
-import org.apache.qpid.server.logging.log4j.LoggingFacade;
+import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
import org.apache.qpid.server.logging.log4j.LoggingFacadeException;
import javax.management.JMException;
@@ -55,7 +55,8 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
private static final TabularType LOGGER_LEVEL_TABULAR_TYE;
private static final CompositeType LOGGER_LEVEL_COMPOSITE_TYPE;
- private final LoggingFacade _configurator;
+ private final LoggingManagementFacade _loggingManagementFacade;
+ private final String[] _allAvailableLogLevels;
static
{
@@ -77,12 +78,13 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
throw new ExceptionInInitializerError(e);
}
}
-
- public LoggingManagementMBean(LoggingFacade configurator, ManagedObjectRegistry registry) throws JMException
+
+ public LoggingManagementMBean(LoggingManagementFacade loggingManagementFacade, ManagedObjectRegistry registry) throws JMException
{
super(LoggingManagement.class, LoggingManagement.TYPE, registry);
register();
- _configurator = configurator;
+ _loggingManagementFacade = loggingManagementFacade;
+ _allAvailableLogLevels = buildAllAvailableLoggerLevelsWithInheritedPsuedoLogLevel(_loggingManagementFacade);
}
@Override
@@ -100,30 +102,26 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
@Override
public Integer getLog4jLogWatchInterval()
{
- return _configurator.getLog4jLogWatchInterval();
+ return _loggingManagementFacade.getLog4jLogWatchInterval();
}
@Override
public String[] getAvailableLoggerLevels()
{
- List<String> levels = _configurator.getAvailableLoggerLevels();
- List<String> mbeanLevels = new ArrayList<String>(levels);
- mbeanLevels.add(INHERITED_PSUEDO_LOG_LEVEL);
-
- return mbeanLevels.toArray(new String[mbeanLevels.size()]);
+ return _allAvailableLogLevels;
}
@Override
public TabularData viewEffectiveRuntimeLoggerLevels()
{
- Map<String, String> levels = _configurator.retrieveRuntimeLoggersLevels();
+ Map<String, String> levels = _loggingManagementFacade.retrieveRuntimeLoggersLevels();
return createTabularDataFromLevelsMap(levels);
}
@Override
public String getRuntimeRootLoggerLevel()
{
- return _configurator.retrieveRuntimeRootLoggerLevel();
+ return _loggingManagementFacade.retrieveRuntimeRootLoggerLevel();
}
@Override
@@ -139,7 +137,7 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
return false;
}
- _configurator.setRuntimeRootLoggerLevel(level);
+ _loggingManagementFacade.setRuntimeRootLoggerLevel(level);
return true;
}
@@ -159,7 +157,7 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
try
{
- _configurator.setRuntimeLoggerLevel(logger, validatedLevel);
+ _loggingManagementFacade.setRuntimeLoggerLevel(logger, validatedLevel);
}
catch (LoggingFacadeException e)
{
@@ -175,7 +173,7 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
Map<String,String> levels;
try
{
- levels = _configurator.retrieveConfigFileLoggersLevels();
+ levels = _loggingManagementFacade.retrieveConfigFileLoggersLevels();
}
catch (LoggingFacadeException e)
{
@@ -191,7 +189,7 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
{
try
{
- return _configurator.retrieveConfigFileRootLoggerLevel().toUpperCase();
+ return _loggingManagementFacade.retrieveConfigFileRootLoggerLevel().toUpperCase();
}
catch (LoggingFacadeException e)
{
@@ -216,7 +214,7 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
try
{
- _configurator.setConfigFileLoggerLevel(logger, validatedLevel);
+ _loggingManagementFacade.setConfigFileLoggerLevel(logger, validatedLevel);
}
catch (LoggingFacadeException e)
{
@@ -241,7 +239,7 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
try
{
- _configurator.setConfigFileRootLoggerLevel(level);
+ _loggingManagementFacade.setConfigFileRootLoggerLevel(level);
return true;
}
catch (LoggingFacadeException e)
@@ -257,7 +255,7 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
try
{
- _configurator.reload();
+ _loggingManagementFacade.reload();
}
catch (LoggingFacadeException e)
{
@@ -283,9 +281,8 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
private void validateLevelNotAllowingInherited(String level)
{
- final List<String> availableLoggerLevels = _configurator.getAvailableLoggerLevels();
- if (!availableLoggerLevels.contains(level)
- && !availableLoggerLevels.contains(String.valueOf(level).toUpperCase()))
+ final List<String> availableLoggerLevels = _loggingManagementFacade.getAvailableLoggerLevels();
+ if (level == null || !availableLoggerLevels.contains(level.toUpperCase()))
{
throw new IllegalArgumentException(level + " not known");
}
@@ -305,7 +302,6 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
return loggerLevelList;
}
-
private CompositeData createRow(String loggerName, String level)
{
Object[] itemData = {loggerName, level.toUpperCase()};
@@ -321,4 +317,13 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM
throw new RuntimeException(ode);
}
}
+
+ private String[] buildAllAvailableLoggerLevelsWithInheritedPsuedoLogLevel(LoggingManagementFacade loggingManagementFacade)
+ {
+ List<String> levels = loggingManagementFacade.getAvailableLoggerLevels();
+ List<String> mbeanLevels = new ArrayList<String>(levels);
+ mbeanLevels.add(INHERITED_PSUEDO_LOG_LEVEL);
+
+ return mbeanLevels.toArray(new String[mbeanLevels.size()]);
+ }
}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
index 5c8b0f7194..94fac218ff 100644
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/QueueMBean.java
@@ -513,7 +513,6 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN
{
_queue.visit(new QueueEntryVisitor()
{
-
public boolean visit(final QueueEntry entry)
{
final ServerMessage message = entry.getMessage();
@@ -525,11 +524,9 @@ public class QueueMBean extends AMQManagedObject implements ManagedQueue, QueueN
&& (messageId <= toMessageId))
{
txn.dequeue(entry);
- return true;
}
- return false;
}
- return true;
+ return false;
}
});
}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java
index 6990a40dee..51dea92775 100644
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostMBean.java
@@ -65,7 +65,7 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
_managerMBean = new VirtualHostManagerMBean(this);
}
- private void initQueues() throws JMException
+ private void initQueues()
{
synchronized (_children)
{
@@ -73,13 +73,20 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
{
if(!_children.containsKey(queue))
{
- _children.put(queue, new QueueMBean(queue, this));
+ try
+ {
+ _children.put(queue, new QueueMBean(queue, this));
+ }
+ catch(Exception e)
+ {
+ LOGGER.error("Cannot create queue mbean for queue " + queue.getName(), e);
+ }
}
}
}
}
- private void initExchanges() throws JMException
+ private void initExchanges()
{
synchronized (_children)
{
@@ -87,13 +94,20 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
{
if(!_children.containsKey(exchange))
{
- _children.put(exchange, new ExchangeMBean(exchange, this));
+ try
+ {
+ _children.put(exchange, new ExchangeMBean(exchange, this));
+ }
+ catch(Exception e)
+ {
+ LOGGER.error("Cannot create exchange mbean for exchange " + exchange.getName(), e);
+ }
}
}
}
}
- private void initConnections() throws JMException
+ private void initConnections()
{
synchronized (_children)
{
@@ -101,7 +115,14 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
{
if(!_children.containsKey(conn))
{
- _children.put(conn, new ConnectionMBean(conn, this));
+ try
+ {
+ _children.put(conn, new ConnectionMBean(conn, this));
+ }
+ catch(Exception e)
+ {
+ LOGGER.error("Cannot create connection mbean for connection " + conn.getName(), e);
+ }
}
}
}
@@ -119,7 +140,7 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
public void stateChanged(ConfiguredObject object, State oldState, State newState)
{
- // ignore
+ // no-op
}
public void childAdded(ConfiguredObject object, ConfiguredObject child)
@@ -208,4 +229,35 @@ public class VirtualHostMBean extends AMQManagedObject implements ManagedVirtual
return queues;
}
+
+ @Override
+ public void unregister() throws JMException
+ {
+ synchronized (_children)
+ {
+ for (AMQManagedObject mbean : _children.values())
+ {
+ if(mbean != null)
+ {
+ try
+ {
+ mbean.unregister();
+ }
+ catch(JMException e)
+ {
+ LOGGER.error("Failed to remove mbean for child : " + mbean, e);
+ }
+ }
+ }
+ _children.clear();
+ }
+ _managerMBean.unregister();
+ }
+
+ @Override
+ public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue)
+ {
+ // no-op
+ }
+
}
diff --git a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
index b3dbbc424a..67ac1bdc7c 100644
--- a/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
+++ b/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java
@@ -229,10 +229,9 @@ public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<Vi
return getObjectNameForSingleInstanceMBean();
}
- public synchronized boolean isStatisticsEnabled()
+ public boolean isStatisticsEnabled()
{
- updateStats();
- return false; //TODO - implement isStatisticsEnabled
+ return true;
}
}
diff --git a/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory b/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory
new file mode 100644
index 0000000000..8fa778269e
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.PluginFactory
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.qpid.server.jmx.JMXManagementFactory
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.java
new file mode 100644
index 0000000000..5af1369239
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/JMXManagementFactoryTest.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.server.jmx;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class JMXManagementFactoryTest extends QpidTestCase
+{
+ private final JMXManagementFactory _jmxManagementFactory = new JMXManagementFactory();
+ private final Map<String, Object> _attributes = new HashMap<String, Object>();
+ private final Broker _broker = mock(Broker.class);
+ private UUID _id = UUID.randomUUID();
+
+ public void testJMXConfigured() throws Exception
+ {
+ _attributes.put(PluginFactory.PLUGIN_TYPE, JMXManagement.PLUGIN_TYPE);
+
+ JMXManagement jmxManagement = (JMXManagement) _jmxManagementFactory.createInstance(_id, _attributes, _broker);
+
+ assertNotNull(jmxManagement);
+ assertEquals("Unexpected plugin type", JMXManagement.PLUGIN_TYPE, jmxManagement.getAttribute(JMXManagementFactory.PLUGIN_TYPE));
+ assertEquals("Unexpected default mbean platform", JMXManagement.DEFAULT_USE_PLATFORM_MBEAN_SERVER, jmxManagement.getAttribute(JMXManagement.USE_PLATFORM_MBEAN_SERVER));
+ assertEquals("Unexpected default name", JMXManagement.DEFAULT_NAME, jmxManagement.getAttribute(JMXManagement.NAME));
+ }
+
+ public void testCreateInstanceReturnsNullWhenPluginTypeMissing()
+ {
+ assertNull(_jmxManagementFactory.createInstance(_id, _attributes, _broker));
+ }
+
+ public void testCreateInstanceReturnsNullWhenPluginTypeNotJmx()
+ {
+ _attributes.put(PluginFactory.PLUGIN_TYPE, "notJmx");
+ assertNull(_jmxManagementFactory.createInstance(_id, _attributes, _broker));
+ }
+}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogActorTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogActorTest.java
deleted file mode 100644
index c1df9afc5d..0000000000
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogActorTest.java
+++ /dev/null
@@ -1,170 +0,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.
- *
- */
-package org.apache.qpid.server.jmx;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.JMException;
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.server.security.SecurityPlugin;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-import org.apache.qpid.server.util.TestApplicationRegistry;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-public class ManagementLogActorTest extends QpidTestCase
-{
- private ApplicationRegistry _registry;
- private JMXManagedObjectRegistry _objectRegistry;
- private int _registryPort;
- private int _connectorPort;
- private TestPlugin _plugin;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
-
- _registryPort = findFreePort();
- _connectorPort = getNextAvailable(_registryPort + 1);
- XMLConfiguration config = new XMLConfiguration();
- config.addProperty(ServerConfiguration.MGMT_JMXPORT_REGISTRYSERVER, _registryPort + "");
- config.addProperty(ServerConfiguration.MGMT_JMXPORT_CONNECTORSERVER, _connectorPort + "");
- _registry = new TestApplicationRegistry(new ServerConfiguration(config));
- ApplicationRegistry.initialise(_registry);
-
- _plugin = new TestPlugin();
- _registry.getSecurityManager().addHostPlugin(_plugin);
-
- _objectRegistry = new JMXManagedObjectRegistry();
- new TestMBean(_objectRegistry);
- _objectRegistry.start();
- }
-
- public void tearDown() throws Exception
- {
- _objectRegistry.close();
- ApplicationRegistry.remove();
- super.tearDown();
- }
-
- public void testPrincipalInLogMessage() throws Throwable
- {
- Map<String, Object> environment = new HashMap<String, Object>();
- environment.put(JMXConnector.CREDENTIALS, new String[] { "admin", "admin" });
- String urlString = "service:jmx:rmi:///jndi/rmi://localhost:" + _registryPort + "/jmxrmi";
- JMXServiceURL url = new JMXServiceURL(urlString);
- JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
- MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
- ObjectName mbeanObject = new ObjectName("org.apache.qpid:type=TestMBean,name=test");
-
- String actorLogMessage = (String) mbsc.getAttribute(mbeanObject, "ActorLogMessage");
-
- assertTrue("Unexpected log principal in security plugin", _plugin.getLogMessage().startsWith("[mng:admin"));
- assertTrue("Unexpected log principal in MBean", actorLogMessage.startsWith("[mng:admin"));
- }
-
- public static class TestMBean extends DefaultManagedObject implements CurrentActorRetriever
- {
-
- public TestMBean(ManagedObjectRegistry registry) throws JMException
- {
- super(CurrentActorRetriever.class, "TestMBean", registry);
- register();
- }
-
- @Override
- public String getObjectInstanceName()
- {
- return "test";
- }
-
- @Override
- public ManagedObject getParentObject()
- {
- return null;
- }
-
- @Override
- public String getActorLogMessage()
- {
- return CurrentActor.get().getLogMessage();
- }
-
- }
-
- public static interface CurrentActorRetriever
- {
- String getActorLogMessage();
- }
-
- public static class TestPlugin implements SecurityPlugin
- {
- private String _logMessage;
-
- @Override
- public void configure(ConfigurationPlugin config) throws ConfigurationException
- {
- }
-
- @Override
- public Result getDefault()
- {
- return Result.ALLOWED;
- }
-
- @Override
- public Result access(ObjectType objectType, Object instance)
- {
- return Result.ALLOWED;
- }
-
- @Override
- public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties)
- {
- // set thread name to work around logic in MangementActor
- Thread.currentThread().setName("RMI TCP Connection(1)-" + System.currentTimeMillis());
- _logMessage = CurrentActor.get().getLogMessage();
- return Result.ALLOWED;
- }
-
- public String getLogMessage()
- {
- return _logMessage;
- }
-
- }
-
-}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporterTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporterTest.java
new file mode 100644
index 0000000000..ba9c2cdaa5
--- /dev/null
+++ b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/ManagementLogonLogoffReporterTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.jmx;
+
+import static javax.management.remote.JMXConnectionNotification.OPENED;
+import static javax.management.remote.JMXConnectionNotification.CLOSED;
+import static javax.management.remote.JMXConnectionNotification.FAILED;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+
+import javax.management.remote.JMXConnectionNotification;
+
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.RootMessageLogger;
+
+import junit.framework.TestCase;
+
+public class ManagementLogonLogoffReporterTest extends TestCase
+{
+ private static final String TEST_JMX_UNIQUE_CONNECTION_ID = "jmxconnectionid1 jmxuser,group";
+ private static final String TEST_USER = "jmxuser";
+
+ private ManagementLogonLogoffReporter _reporter;
+ private UsernameAccessor _usernameAccessor;
+ private RootMessageLogger _rootMessageLogger;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _usernameAccessor = mock(UsernameAccessor.class);
+ _rootMessageLogger = mock(RootMessageLogger.class);
+ // Enable messaging so we can valid the generated strings
+ when(_rootMessageLogger.isMessageEnabled(any(LogActor.class), anyString())).thenReturn(true);
+
+ _reporter = new ManagementLogonLogoffReporter(_rootMessageLogger, _usernameAccessor);
+ }
+
+ public void testOpenedNotification()
+ {
+ when(_usernameAccessor.getUsernameForConnectionId(TEST_JMX_UNIQUE_CONNECTION_ID)).thenReturn(TEST_USER);
+ JMXConnectionNotification openNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, OPENED);
+
+ _reporter.handleNotification(openNotification, null);
+
+ verify(_rootMessageLogger).rawMessage("[main] MNG-1007 : Open : User jmxuser", "qpid.message.managementconsole.open");
+ }
+
+ public void testClosedNotification()
+ {
+ when(_usernameAccessor.getUsernameForConnectionId(TEST_JMX_UNIQUE_CONNECTION_ID)).thenReturn(TEST_USER);
+ JMXConnectionNotification closeNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, CLOSED);
+
+ _reporter.handleNotification(closeNotification, null);
+
+ verify(_rootMessageLogger).rawMessage("[main] MNG-1008 : Close : User jmxuser", "qpid.message.managementconsole.close");
+ }
+
+ public void tesNotifiedForLogOnTypeEvents()
+ {
+ JMXConnectionNotification openNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, OPENED);
+ JMXConnectionNotification closeNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, CLOSED);
+ JMXConnectionNotification failedNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, FAILED);
+
+ assertTrue(_reporter.isNotificationEnabled(openNotification));
+ assertTrue(_reporter.isNotificationEnabled(closeNotification));
+ assertTrue(_reporter.isNotificationEnabled(failedNotification));
+
+ JMXConnectionNotification otherNotification = createMockNotification(TEST_JMX_UNIQUE_CONNECTION_ID, "other");
+ assertFalse(_reporter.isNotificationEnabled(otherNotification));
+ }
+
+ private JMXConnectionNotification createMockNotification(String connectionId, String notificationType)
+ {
+ JMXConnectionNotification notification = mock(JMXConnectionNotification.class);
+ when(notification.getConnectionId()).thenReturn(connectionId);
+ when(notification.getType()).thenReturn(notificationType);
+ return notification;
+ }
+}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java
index ae1be5db00..0f33e78d03 100644
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java
+++ b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/LoggingManagementMBeanTest.java
@@ -39,7 +39,7 @@ import junit.framework.TestCase;
import org.apache.qpid.management.common.mbeans.LoggingManagement;
import org.apache.qpid.server.jmx.ManagedObjectRegistry;
-import org.apache.qpid.server.logging.log4j.LoggingFacade;
+import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
public class LoggingManagementMBeanTest extends TestCase
{
@@ -47,13 +47,13 @@ public class LoggingManagementMBeanTest extends TestCase
private static final String TEST_LEVEL2 = "LEVEL2";
private LoggingManagementMBean _loggingMBean;
- private LoggingFacade _mockLoggingFacade;
+ private LoggingManagementFacade _mockLoggingFacade;
private ManagedObjectRegistry _mockManagedObjectRegistry;
@Override
protected void setUp() throws Exception
{
- _mockLoggingFacade = mock(LoggingFacade.class);
+ _mockLoggingFacade = mock(LoggingManagementFacade.class);
final List<String> listOfLevels = new ArrayList<String>()
{{
add(TEST_LEVEL1);
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
deleted file mode 100644
index 7473a4d3e7..0000000000
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
+++ /dev/null
@@ -1,124 +0,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.
- */
-package org.apache.qpid.systest.management.jmx;
-
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.management.common.mbeans.ManagedBroker;
-import org.apache.qpid.management.common.mbeans.ManagedExchange;
-import org.apache.qpid.test.utils.JMXTestUtils;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-/**
- * Tests the JMX API for the Managed Broker.
- *
- */
-public class BrokerManagementTest extends QpidBrokerTestCase
-{
- private static final String VIRTUAL_HOST = "test";
-
- /**
- * JMX helper.
- */
- private JMXTestUtils _jmxUtils;
- private ManagedBroker _managedBroker;
-
- public void setUp() throws Exception
- {
- _jmxUtils = new JMXTestUtils(this);
- _jmxUtils.setUp();
- super.setUp();
- _jmxUtils.open();
- _managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST);
- }
-
- public void tearDown() throws Exception
- {
- if (_jmxUtils != null)
- {
- _jmxUtils.close();
- }
- super.tearDown();
- }
-
- /**
- * Tests queue creation/deletion also verifying the automatic binding to the default exchange.
- */
- public void testCreateQueueAndDeletion() throws Exception
- {
- final String queueName = getTestQueueName();
- final ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString());
-
- // Check that bind does not exist before queue creation
- assertFalse("Binding to " + queueName + " should not exist in default exchange before queue creation",
- defaultExchange.bindings().containsKey(new String[] {queueName}));
-
- _managedBroker.createNewQueue(queueName, "testowner", true);
-
- // Ensure the queue exists
- assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName));
- assertNotNull("Manager queue expected to be available", _jmxUtils.getManagedQueue(queueName));
-
- // Now verify that the default exchange has been bound.
- assertTrue("Binding to " + queueName + " should exist in default exchange after queue creation",
- defaultExchange.bindings().containsKey(new String[] {queueName}));
-
- // Now delete the queue
- _managedBroker.deleteQueue(queueName);
-
- // Finally ensure that the binding has been removed.
- assertFalse("Binding to " + queueName + " should not exist in default exchange after queue deletion",
- defaultExchange.bindings().containsKey(new String[] {queueName}));
- }
-
- /**
- * Tests exchange creation/deletion via JMX API.
- */
- public void testCreateExchangeAndUnregister() throws Exception
- {
- String exchangeName = getTestName();
- _managedBroker.createNewExchange(exchangeName, "topic", true);
-
- ManagedExchange exchange = _jmxUtils.getManagedExchange(exchangeName);
- assertNotNull("Exchange should exist", exchange);
-
- _managedBroker.unregisterExchange(exchangeName);
- }
-
- /**
- * Tests that it is disallowed to unregister the default exchange.
- */
- public void testUnregisterOfDefaultExchangeDisallowed() throws Exception
- {
- String defaultExchangeName = ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString();
-
- try
- {
- _managedBroker.unregisterExchange(defaultExchangeName);
- fail("Exception not thrown");
- }
- catch (UnsupportedOperationException e)
- {
- // PASS
- assertEquals("'<<default>>' is a reserved exchange and can't be deleted", e.getMessage());
- }
- final ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName);
- assertNotNull("Exchange should exist", defaultExchange);
- }
-
-}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java
deleted file mode 100644
index ac6730638e..0000000000
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java
+++ /dev/null
@@ -1,149 +0,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.
- */
-package org.apache.qpid.systest.management.jmx;
-
-import java.io.File;
-import java.util.List;
-
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.TabularData;
-
-import org.apache.qpid.management.common.mbeans.LoggingManagement;
-import org.apache.qpid.server.jmx.mbeans.LoggingManagementMBeanTest;
-import org.apache.qpid.server.logging.log4j.LoggingFacadeTest;
-import org.apache.qpid.test.utils.JMXTestUtils;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-import org.apache.qpid.util.FileUtils;
-import org.apache.qpid.util.LogMonitor;
-
-/**
- * System test for Logging Management. <b>These tests rely on value set within
- * test-profiles/log4j-test.xml</b>.
- *
- * @see LoggingManagementMBeanTest
- * @see LoggingFacadeTest
- *
- */
-public class LoggingManagementTest extends QpidBrokerTestCase
-{
- private JMXTestUtils _jmxUtils;
- private LoggingManagement _loggingManagement;
- private LogMonitor _monitor;
-
- public void setUp() throws Exception
- {
- _jmxUtils = new JMXTestUtils(this);
- _jmxUtils.setUp();
-
- // System test normally run with log for4j test config from beneath test-profiles. We need to
- // copy it as some of our tests write to this file.
-
- File tmpLogFile = File.createTempFile("log4j" + "." + getName(), ".xml");
- tmpLogFile.deleteOnExit();
- FileUtils.copy(_logConfigFile, tmpLogFile);
-
- _logConfigFile = tmpLogFile;
-
- super.setUp();
- _jmxUtils.open();
-
- _loggingManagement = _jmxUtils.getLoggingManagement();
- _monitor = new LogMonitor(_outputFile);
- }
-
- public void tearDown() throws Exception
- {
- try
- {
- if (_jmxUtils != null)
- {
- _jmxUtils.close();
- }
- }
- finally
- {
- super.tearDown();
- }
- }
-
- public void testViewEffectiveRuntimeLoggerLevels() throws Exception
- {
- final String qpidMainLogger = "org.apache.qpid";
-
- TabularData table = _loggingManagement.viewEffectiveRuntimeLoggerLevels();
- final CompositeData row = table.get(new String[] {qpidMainLogger} );
- assertChannelRow(row, qpidMainLogger, "DEBUG");
- }
-
- public void testViewConfigFileLoggerLevels() throws Exception
- {
- final String operationalLoggingLogger = "qpid.message";
-
- TabularData table = _loggingManagement.viewConfigFileLoggerLevels();
- final CompositeData row = table.get(new String[] {operationalLoggingLogger} );
- assertChannelRow(row, operationalLoggingLogger, "INFO");
- }
-
- public void testTurnOffOrgApacheQpidAtRuntime() throws Exception
- {
- final String logger = "org.apache.qpid";
- _monitor.markDiscardPoint();
- _loggingManagement.setRuntimeLoggerLevel(logger, "OFF");
-
- List<String> matches = _monitor.findMatches("Setting level to OFF for logger 'org.apache.qpid'");
- assertEquals(1, matches.size());
-
- TabularData table = _loggingManagement.viewEffectiveRuntimeLoggerLevels();
- final CompositeData row1 = table.get(new String[] {logger} );
- assertChannelRow(row1, logger, "OFF");
- }
-
- public void testChangesToConfigFileBecomeEffectiveAfterReload() throws Exception
- {
- final String operationalLoggingLogger = "qpid.message";
- assertEffectiveLoggingLevel(operationalLoggingLogger, "INFO");
-
- _monitor.markDiscardPoint();
- _loggingManagement.setConfigFileLoggerLevel(operationalLoggingLogger, "OFF");
-
- List<String> matches = _monitor.findMatches("Setting level to OFF for logger 'qpid.message'");
- assertEquals(1, matches.size());
-
- assertEffectiveLoggingLevel(operationalLoggingLogger, "INFO");
-
- _loggingManagement.reloadConfigFile();
-
- assertEffectiveLoggingLevel(operationalLoggingLogger, "OFF");
- }
-
- private void assertEffectiveLoggingLevel(String operationalLoggingLogger, String expectedLevel)
- {
- TabularData table = _loggingManagement.viewEffectiveRuntimeLoggerLevels();
- final CompositeData row1 = table.get(new String[] {operationalLoggingLogger} );
- assertChannelRow(row1, operationalLoggingLogger, expectedLevel);
- }
-
- private void assertChannelRow(final CompositeData row, String logger, String level)
- {
- assertNotNull("No row for " + logger, row);
- assertEquals("Unexpected logger name", logger, row.get(LoggingManagement.LOGGER_NAME));
- assertEquals("Unexpected level", level, row.get(LoggingManagement.LOGGER_LEVEL));
- }
-
-}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
deleted file mode 100644
index 6100d5a23e..0000000000
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
+++ /dev/null
@@ -1,317 +0,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.
- *
- */
-package org.apache.qpid.systest.management.jmx;
-
-
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.logging.AbstractTestLogging;
-import org.apache.qpid.test.utils.JMXTestUtils;
-import org.apache.qpid.util.LogMonitor;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * Management Console Test Suite
- *
- * The Management Console test suite validates that the follow log messages as specified in the Functional Specification.
- *
- * This suite of tests validate that the management console messages occur correctly and according to the following format:
- *
- * MNG-1001 : Startup
- * MNG-1002 : Starting : <service> : Listening on port <Port>
- * MNG-1003 : Shutting down : <service> : port <Port>
- * MNG-1004 : Ready
- * MNG-1005 : Stopped
- * MNG-1006 : Using SSL Keystore : <path>
- * MNG-1007 : Open : User <username>
- * MNG-1008 : Close : User <username>
- */
-public class ManagementLoggingTest extends AbstractTestLogging
-{
- private static final String MNG_PREFIX = "MNG-";
-
- public void setUp() throws Exception
- {
- setLogMessagePrefix();
-
- // We either do this here or have a null check in tearDown.
- // As when this test is run against profiles other than java it will NPE
- _monitor = new LogMonitor(_outputFile);
- //We explicitly do not call super.setUp as starting up the broker is
- //part of the test case.
-
- }
-
- /**
- * Description:
- * Using the startup configuration validate that the management startup
- * message is logged correctly.
- * Input:
- * Standard configuration with management enabled
- * Output:
- *
- * <date> MNG-1001 : Startup
- *
- * Constraints:
- * This is the FIRST message logged by MNG
- * Validation Steps:
- *
- * 1. The BRK ID is correct
- * 2. This is the FIRST message logged by MNG
- */
- public void testManagementStartupEnabled() throws Exception
- {
- // This test only works on java brokers
- if (isJavaBroker())
- {
- startBrokerAndCreateMonitor(true, false);
-
- // Ensure we have received the MNG log msg.
- waitForMessage("MNG-1001");
-
- List<String> results = findMatches(MNG_PREFIX);
- // Validation
-
- assertTrue("MNGer message not logged", results.size() > 0);
-
- String log = getLogMessage(results, 0);
-
- //1
- validateMessageID("MNG-1001", log);
-
- //2
- //There will be 2 copies of the startup message (one via SystemOut, and one via Log4J)
- results = findMatches("MNG-1001");
- assertEquals("Unexpected startup message count.",
- 2, results.size());
-
- //3
- assertEquals("Startup log message is not 'Startup'.", "Startup",
- getMessageString(log));
- }
- }
-
- /**
- * Description:
- * Verify that when management is disabled in the configuration file the
- * startup message is not logged.
- * Input:
- * Standard configuration with management disabled
- * Output:
- * NO MNG messages
- * Validation Steps:
- *
- * 1. Validate that no MNG messages are produced.
- */
- public void testManagementStartupDisabled() throws Exception
- {
- if (isJavaBroker())
- {
- startBrokerAndCreateMonitor(false, false);
-
- List<String> results = findMatches(MNG_PREFIX);
- // Validation
-
- assertEquals("MNGer messages logged", 0, results.size());
- }
- }
-
- /**
- * The two MNG-1002 messages are logged at the same time so lets test them
- * at the same time.
- *
- * Description:
- * Using the default configuration validate that the RMI Registry socket is
- * correctly reported as being opened
- *
- * Input:
- * The default configuration file
- * Output:
- *
- * <date> MESSAGE MNG-1002 : Starting : RMI Registry : Listening on port 8999
- *
- * Constraints:
- * The RMI ConnectorServer and Registry log messages do not have a prescribed order
- * Validation Steps:
- *
- * 1. The MNG ID is correct
- * 2. The specified port is the correct '8999'
- *
- * Description:
- * Using the default configuration validate that the RMI ConnectorServer
- * socket is correctly reported as being opened
- *
- * Input:
- * The default configuration file
- * Output:
- *
- * <date> MESSAGE MNG-1002 : Starting : RMI ConnectorServer : Listening on port 9099
- *
- * Constraints:
- * The RMI ConnectorServer and Registry log messages do not have a prescribed order
- * Validation Steps:
- *
- * 1. The MNG ID is correct
- * 2. The specified port is the correct '9099'
- */
- public void testManagementStartupRMIEntries() throws Exception
- {
- if (isJavaBroker())
- {
- startBrokerAndCreateMonitor(true, false);
-
- List<String> results = waitAndFindMatches("MNG-1002");
- // Validation
-
- //There will be 4 startup messages (two via SystemOut, and two via Log4J)
- assertEquals("Unexpected MNG-1002 message count", 4, results.size());
-
- String log = getLogMessage(results, 0);
-
- //1
- validateMessageID("MNG-1002", log);
-
- //Check the RMI Registry port is as expected
- int mPort = getManagementPort(getPort());
- assertTrue("RMI Registry port not as expected(" + mPort + ").:" + getMessageString(log),
- getMessageString(log).endsWith(String.valueOf(mPort)));
-
- log = getLogMessage(results, 2);
-
- //1
- validateMessageID("MNG-1002", log);
-
- // We expect the RMI Registry port (the defined 'management port') to be
- // 100 lower than the JMX RMIConnector Server Port (the actual JMX server)
- int jmxPort = mPort + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET;
- assertTrue("JMX RMIConnectorServer port not as expected(" + jmxPort + ").:" + getMessageString(log),
- getMessageString(log).endsWith(String.valueOf(jmxPort)));
- }
- }
-
- /**
- * Description:
- * Using the default configuration with SSL enabled for the management port the SSL Keystore path should be reported via MNG-1006
- * Input:
- * Management SSL enabled default configuration.
- * Output:
- *
- * <date> MESSAGE MNG-1006 : Using SSL Keystore : test_resources/ssl/keystore.jks
- *
- * Validation Steps:
- *
- * 1. The MNG ID is correct
- * 2. The keystore path is as specified in the configuration
- */
- public void testManagementStartupSSLKeystore() throws Exception
- {
- if (isJavaBroker())
- {
- startBrokerAndCreateMonitor(true, true);
-
- List<String> results = waitAndFindMatches("MNG-1006");
-
- assertTrue("MNGer message not logged", results.size() > 0);
-
- String log = getLogMessage(results, 0);
-
- //1
- validateMessageID("MNG-1006", log);
-
- // Validate we only have two MNG-1002 (one via stdout, one via log4j)
- results = findMatches("MNG-1006");
- assertEquals("Upexpected SSL Keystore message count",
- 2, results.size());
-
- // Validate the keystore path is as expected
- assertTrue("SSL Keystore entry expected.:" + getMessageString(log),
- getMessageString(log).endsWith(new File(getConfigurationStringProperty("management.ssl.keyStorePath")).getName()));
- }
- }
-
- /**
- * Description: Tests the management connection open/close are logged correctly.
- *
- * Output:
- *
- * <date> MESSAGE MNG-1007 : Open : User <username>
- * <date> MESSAGE MNG-1008 : Close : User <username>
- *
- * Validation Steps:
- *
- * 1. The MNG ID is correct
- * 2. The message and username are correct
- */
- public void testManagementUserOpenClose() throws Exception
- {
- if (isJavaBroker())
- {
- startBrokerAndCreateMonitor(true, false);
-
- final JMXTestUtils jmxUtils = new JMXTestUtils(this);
- List<String> openResults = null;
- List<String> closeResults = null;
- try
- {
- jmxUtils.setUp();
- jmxUtils.open();
- openResults = waitAndFindMatches("MNG-1007");
- }
- finally
- {
- if (jmxUtils != null)
- {
- jmxUtils.close();
- closeResults = waitAndFindMatches("MNG-1008");
- }
- }
-
- assertNotNull("Management Open results null", openResults.size());
- assertEquals("Management Open logged unexpected number of times", 1, openResults.size());
-
- assertNotNull("Management Close results null", closeResults.size());
- assertEquals("Management Close logged unexpected number of times", 1, closeResults.size());
-
- final String openMessage = getMessageString(getLogMessage(openResults, 0));
- assertTrue("Unexpected open message " + openMessage, openMessage.endsWith("Open : User admin"));
- final String closeMessage = getMessageString(getLogMessage(closeResults, 0));
- assertTrue("Unexpected close message " + closeMessage, closeMessage.endsWith("Close : User admin"));
- }
- }
-
- private void startBrokerAndCreateMonitor(boolean managementEnabled, boolean useManagementSSL) throws Exception
- {
- //Ensure management is on
- setConfigurationProperty("management.enabled", String.valueOf(managementEnabled));
-
- if(useManagementSSL)
- {
- // This test requires we have an ssl connection
- setConfigurationProperty("management.ssl.enabled", "true");
- }
-
- startBroker();
-
- // Now we can create the monitor as _outputFile will now be defined
- _monitor = new LogMonitor(_outputFile);
- }
-}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/QueueManagementTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/QueueManagementTest.java
deleted file mode 100644
index 79d04b239e..0000000000
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/QueueManagementTest.java
+++ /dev/null
@@ -1,696 +0,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.
- */
-package org.apache.qpid.systest.management.jmx;
-
-import org.apache.commons.lang.time.FastDateFormat;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.configuration.ClientProperties;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.management.common.mbeans.ManagedBroker;
-import org.apache.qpid.management.common.mbeans.ManagedQueue;
-import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.queue.NotificationCheckTest;
-import org.apache.qpid.server.queue.SimpleAMQQueueTest;
-import org.apache.qpid.test.client.destination.AddressBasedDestinationTest;
-import org.apache.qpid.test.utils.JMXTestUtils;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.TabularData;
-import javax.naming.NamingException;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Tests the JMX API for the Managed Queue.
- *
- */
-public class QueueManagementTest extends QpidBrokerTestCase
-{
-
- private static final Logger LOGGER = Logger.getLogger(QueueManagementTest.class);
-
- private static final String VIRTUAL_HOST = "test";
- private static final String TEST_QUEUE_DESCRIPTION = "my description";
-
- private JMXTestUtils _jmxUtils;
- private Connection _connection;
- private Session _session;
-
- private String _sourceQueueName;
- private String _destinationQueueName;
- private Destination _sourceQueue;
- private Destination _destinationQueue;
- private ManagedQueue _managedSourceQueue;
- private ManagedQueue _managedDestinationQueue;
-
- public void setUp() throws Exception
- {
- _jmxUtils = new JMXTestUtils(this);
- _jmxUtils.setUp();
-
- super.setUp();
- _sourceQueueName = getTestQueueName() + "_src";
- _destinationQueueName = getTestQueueName() + "_dest";
-
- createConnectionAndSession();
-
- _sourceQueue = _session.createQueue(_sourceQueueName);
- _destinationQueue = _session.createQueue(_destinationQueueName);
- createQueueOnBroker(_sourceQueue);
- createQueueOnBroker(_destinationQueue);
-
- _jmxUtils.open();
-
- createManagementInterfacesForQueues();
- }
-
- public void tearDown() throws Exception
- {
- if (_jmxUtils != null)
- {
- _jmxUtils.close();
- }
- super.tearDown();
- }
-
- public void testQueueAttributes() throws Exception
- {
- Queue queue = _session.createQueue(getTestQueueName());
- createQueueOnBroker(queue);
-
- final String queueName = queue.getQueueName();
-
- final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertEquals("Unexpected name", queueName, managedQueue.getName());
- assertEquals("Unexpected queue type", "standard", managedQueue.getQueueType());
- }
-
- public void testExclusiveQueueHasJmsClientIdAsOwner() throws Exception
- {
- Queue tmpQueue = _session.createTemporaryQueue();
-
- final String queueName = tmpQueue.getQueueName();
-
- final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertNotNull(_connection.getClientID());
- assertEquals("Unexpected owner", _connection.getClientID(), managedQueue.getOwner());
- }
-
- public void testNonExclusiveQueueHasNoOwner() throws Exception
- {
- Queue nonExclusiveQueue = _session.createQueue(getTestQueueName());
- createQueueOnBroker(nonExclusiveQueue);
-
- final String queueName = nonExclusiveQueue.getQueueName();
-
- final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertNull("Unexpected owner", managedQueue.getOwner());
- }
-
- public void testSetNewQueueDescriptionOnExistingQueue() throws Exception
- {
- Queue queue = _session.createQueue(getTestQueueName());
- createQueueOnBroker(queue);
-
- final String queueName = queue.getQueueName();
-
- final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertNull("Unexpected description", managedQueue.getDescription());
-
- managedQueue.setDescription(TEST_QUEUE_DESCRIPTION);
- assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription());
- }
-
- public void testNewQueueWithDescription() throws Exception
- {
- String queueName = getTestQueueName();
- Map<String, Object> arguments = Collections.singletonMap(AMQQueueFactory.X_QPID_DESCRIPTION, (Object)TEST_QUEUE_DESCRIPTION);
- ((AMQSession<?, ?>)_session).createQueue(AMQShortString.valueOf(queueName), false, true, false, arguments);
-
- final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription());
- }
-
- /**
- * Requires persistent store.
- */
- public void testQueueDescriptionSurvivesRestart() throws Exception
- {
- String queueName = getTestQueueName();
- Map<String, Object> arguments = Collections.singletonMap(AMQQueueFactory.X_QPID_DESCRIPTION, (Object)TEST_QUEUE_DESCRIPTION);
-
- ((AMQSession<?, ?>)_session).createQueue(AMQShortString.valueOf(queueName), false, true, false, arguments);
-
- ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription());
-
- restartBroker();
-
- managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription());
- }
-
- /**
- * Tests queue creation with {@link AMQQueueFactory#X_QPID_MAXIMUM_DELIVERY_COUNT} argument. Also tests
- * that the attribute is exposed correctly through {@link ManagedQueue#getMaximumDeliveryCount()}.
- */
- public void testCreateQueueWithMaximumDeliveryCountSet() throws Exception
- {
- final String queueName = getName();
- final ManagedBroker managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST);
-
- final Integer deliveryCount = 1;
- final Map<String, Object> arguments = Collections.singletonMap(AMQQueueFactory.X_QPID_MAXIMUM_DELIVERY_COUNT, (Object)deliveryCount);
- managedBroker.createNewQueue(queueName, null, true, arguments);
-
- // Ensure the queue exists
- assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName("test", queueName));
- assertNotNull("Manager queue expected to be available", _jmxUtils.getManagedQueue(queueName));
-
- final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertEquals("Unexpected maximum delivery count", deliveryCount, managedQueue.getMaximumDeliveryCount());
- }
-
- /**
- * Requires 0-10 as relies on ADDR addresses.
- * @see AddressBasedDestinationTest for the testing of message routing to the alternate exchange
- */
- public void testGetSetAlternateExchange() throws Exception
- {
- String queueName = getTestQueueName();
- String altExchange = "amq.fanout";
- String addrWithAltExch = String.format("ADDR:%s;{create:always,node:{type:queue,x-declare:{alternate-exchange:'%s'}}}", queueName, altExchange);
- Queue queue = _session.createQueue(addrWithAltExch);
-
- createQueueOnBroker(queue);
-
- final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertEquals("Newly created queue does not have expected alternate exchange", altExchange, managedQueue.getAlternateExchange());
-
- String newAltExch = "amq.topic";
- managedQueue.setAlternateExchange(newAltExch);
- assertEquals("Unexpected alternate exchange after set", newAltExch, managedQueue.getAlternateExchange());
- }
-
- /**
- * Requires 0-10 as relies on ADDR addresses.
- */
- public void testRemoveAlternateExchange() throws Exception
- {
- String queueName = getTestQueueName();
- String altExchange = "amq.fanout";
- String addrWithAltExch = String.format("ADDR:%s;{create:always,node:{type:queue,x-declare:{alternate-exchange:'%s'}}}", queueName, altExchange);
- Queue queue = _session.createQueue(addrWithAltExch);
-
- createQueueOnBroker(queue);
-
- final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- assertEquals("Newly created queue does not have expected alternate exchange", altExchange, managedQueue.getAlternateExchange());
-
- managedQueue.setAlternateExchange("");
- assertNull("Unexpected alternate exchange after set", managedQueue.getAlternateExchange());
- }
-
- /**
- * Requires persistent store
- * Requires 0-10 as relies on ADDR addresses.
- */
- public void testAlternateExchangeSurvivesRestart() throws Exception
- {
- String nonMandatoryExchangeName = "exch" + getName();
-
- final ManagedBroker managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST);
- managedBroker.createNewExchange(nonMandatoryExchangeName, "fanout", true);
-
- String queueName1 = getTestQueueName() + "1";
- String altExchange1 = "amq.fanout";
- String addr1WithAltExch = String.format("ADDR:%s;{create:always,node:{durable: true,type:queue,x-declare:{alternate-exchange:'%s'}}}", queueName1, altExchange1);
- Queue queue1 = _session.createQueue(addr1WithAltExch);
-
- String queueName2 = getTestQueueName() + "2";
- String addr2WithoutAltExch = String.format("ADDR:%s;{create:always,node:{durable: true,type:queue}}", queueName2);
- Queue queue2 = _session.createQueue(addr2WithoutAltExch);
-
- createQueueOnBroker(queue1);
- createQueueOnBroker(queue2);
-
- ManagedQueue managedQueue1 = _jmxUtils.getManagedQueue(queueName1);
- assertEquals("Newly created queue1 does not have expected alternate exchange", altExchange1, managedQueue1.getAlternateExchange());
-
- ManagedQueue managedQueue2 = _jmxUtils.getManagedQueue(queueName2);
- assertNull("Newly created queue2 does not have expected alternate exchange", managedQueue2.getAlternateExchange());
-
- String altExchange2 = nonMandatoryExchangeName;
- managedQueue2.setAlternateExchange(altExchange2);
-
- restartBroker();
-
- managedQueue1 = _jmxUtils.getManagedQueue(queueName1);
- assertEquals("Queue1 does not have expected alternate exchange after restart", altExchange1, managedQueue1.getAlternateExchange());
-
- managedQueue2 = _jmxUtils.getManagedQueue(queueName2);
- assertEquals("Queue2 does not have expected updated alternate exchange after restart", altExchange2, managedQueue2.getAlternateExchange());
- }
-
- /**
- * Tests the ability to receive queue alerts as JMX notifications.
- *
- * @see NotificationCheckTest
- * @see SimpleAMQQueueTest#testNotificationFiredAsync()
- * @see SimpleAMQQueueTest#testNotificationFiredOnEnqueue()
- */
- public void testQueueNotification() throws Exception
- {
- final String queueName = getName();
- final long maximumMessageCount = 3;
-
- Queue queue = _session.createQueue(queueName);
- createQueueOnBroker(queue);
-
- ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
- managedQueue.setMaximumMessageCount(maximumMessageCount);
-
- RecordingNotificationListener listener = new RecordingNotificationListener(1);
-
- _jmxUtils.addNotificationListener(_jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName), listener, null, null);
-
- // Send two messages - this should *not* trigger the notification
- sendMessage(_session, queue, 2);
-
- assertEquals("Premature notification received", 0, listener.getNumberOfNotificationsReceived());
-
- // A further message should trigger the message count alert
- sendMessage(_session, queue, 1);
-
- listener.awaitExpectedNotifications(5, TimeUnit.SECONDS);
-
- assertEquals("Unexpected number of JMX notifications received", 1, listener.getNumberOfNotificationsReceived());
-
- Notification notification = listener.getLastNotification();
- assertEquals("Unexpected notification message", "MESSAGE_COUNT_ALERT 3: Maximum count on queue threshold (3) breached.", notification.getMessage());
- }
-
- /**
- * Tests {@link ManagedQueue#viewMessages(long, long)} interface.
- */
- public void testViewSingleMessage() throws Exception
- {
- final List<Message> sentMessages = sendMessage(_session, _sourceQueue, 1);
- syncSession(_session);
- final Message sentMessage = sentMessages.get(0);
-
- assertEquals("Unexpected queue depth", 1, _managedSourceQueue.getMessageCount().intValue());
-
- // Check the contents of the message
- final TabularData tab = _managedSourceQueue.viewMessages(1l, 1l);
- assertEquals("Unexpected number of rows in table", 1, tab.size());
- final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator();
-
- final CompositeData row1 = rowItr.next();
- assertNotNull("Message should have AMQ message id", row1.get(ManagedQueue.MSG_AMQ_ID));
- assertEquals("Unexpected queue position", 1l, row1.get(ManagedQueue.MSG_QUEUE_POS));
- assertEquals("Unexpected redelivered flag", Boolean.FALSE, row1.get(ManagedQueue.MSG_REDELIVERED));
-
- // Check the contents of header (encoded in a string array)
- final String[] headerArray = (String[]) row1.get(ManagedQueue.MSG_HEADER);
- assertNotNull("Expected message header array", headerArray);
- final Map<String, String> headers = headerArrayToMap(headerArray);
-
- final String expectedJMSMessageID = isBroker010() ? sentMessage.getJMSMessageID().replace("ID:", "") : sentMessage.getJMSMessageID();
- final String expectedFormattedJMSTimestamp = FastDateFormat.getInstance(ManagedQueue.JMSTIMESTAMP_DATETIME_FORMAT).format(sentMessage.getJMSTimestamp());
- assertEquals("Unexpected JMSMessageID within header", expectedJMSMessageID, headers.get("JMSMessageID"));
- assertEquals("Unexpected JMSPriority within header", String.valueOf(sentMessage.getJMSPriority()), headers.get("JMSPriority"));
- assertEquals("Unexpected JMSTimestamp within header", expectedFormattedJMSTimestamp, headers.get("JMSTimestamp"));
- }
-
- /**
- * Tests {@link ManagedQueue#moveMessages(long, long, String)} interface.
- */
- public void testMoveMessagesBetweenQueues() throws Exception
- {
- final int numberOfMessagesToSend = 10;
-
- sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
- syncSession(_session);
- assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
-
- List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
-
- // Move first three messages to destination
- long fromMessageId = amqMessagesIds.get(0);
- long toMessageId = amqMessagesIds.get(2);
- _managedSourceQueue.moveMessages(fromMessageId, toMessageId, _destinationQueueName);
-
- assertEquals("Unexpected queue depth on destination queue after first move", 3, _managedDestinationQueue.getMessageCount().intValue());
- assertEquals("Unexpected queue depth on source queue after first move", 7, _managedSourceQueue.getMessageCount().intValue());
-
- // Now move a further two messages to destination
- fromMessageId = amqMessagesIds.get(7);
- toMessageId = amqMessagesIds.get(8);
- _managedSourceQueue.moveMessages(fromMessageId, toMessageId, _destinationQueueName);
- assertEquals("Unexpected queue depth on destination queue after second move", 5, _managedDestinationQueue.getMessageCount().intValue());
- assertEquals("Unexpected queue depth on source queue after second move", 5, _managedSourceQueue.getMessageCount().intValue());
-
- assertMessageIndicesOn(_destinationQueue, 0, 1, 2, 7, 8);
- }
-
- /**
- * Tests {@link ManagedQueue#copyMessages(long, long, String)} interface.
- */
- public void testCopyMessagesBetweenQueues() throws Exception
- {
- final int numberOfMessagesToSend = 10;
- sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
- syncSession(_session);
- assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
-
- List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
-
- // Copy first three messages to destination
- long fromMessageId = amqMessagesIds.get(0);
- long toMessageId = amqMessagesIds.get(2);
- _managedSourceQueue.copyMessages(fromMessageId, toMessageId, _destinationQueueName);
-
- assertEquals("Unexpected queue depth on destination queue after first copy", 3, _managedDestinationQueue.getMessageCount().intValue());
- assertEquals("Unexpected queue depth on source queue after first copy", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
-
- // Now copy a further two messages to destination
- fromMessageId = amqMessagesIds.get(7);
- toMessageId = amqMessagesIds.get(8);
- _managedSourceQueue.copyMessages(fromMessageId, toMessageId, _destinationQueueName);
- assertEquals("Unexpected queue depth on destination queue after second copy", 5, _managedDestinationQueue.getMessageCount().intValue());
- assertEquals("Unexpected queue depth on source queue after second copy", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
-
- assertMessageIndicesOn(_destinationQueue, 0, 1, 2, 7, 8);
- }
-
- public void testMoveMessagesBetweenQueuesWithActiveConsumerOnSourceQueue() throws Exception
- {
- setTestClientSystemProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, new Integer(1).toString());
- Connection asyncConnection = getConnection();
- asyncConnection.start();
-
- final int numberOfMessagesToSend = 50;
- sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
- syncSession(_session);
- assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
-
- List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
-
- long fromMessageId = amqMessagesIds.get(0);
- long toMessageId = amqMessagesIds.get(numberOfMessagesToSend - 1);
-
- CountDownLatch consumerReadToHalfwayLatch = new CountDownLatch(numberOfMessagesToSend / 2);
- AtomicInteger totalConsumed = new AtomicInteger(0);
- startAsyncConsumerOn(_sourceQueue, asyncConnection, consumerReadToHalfwayLatch, totalConsumed);
-
- boolean halfwayPointReached = consumerReadToHalfwayLatch.await(5000, TimeUnit.MILLISECONDS);
- assertTrue("Did not read half of messages within time allowed", halfwayPointReached);
-
- _managedSourceQueue.moveMessages(fromMessageId, toMessageId, _destinationQueueName);
-
- asyncConnection.stop();
-
- // The exact number of messages moved will be non deterministic, as the number of messages processed
- // by the consumer cannot be predicted. There is also the possibility that a message can remain
- // on the source queue. This situation will arise if a message has been acquired by the consumer, but not
- // yet delivered to the client application (i.e. MessageListener#onMessage()) when the Connection#stop() occurs.
- //
- // The number of messages moved + the number consumed + any messages remaining on source should
- // *always* be equal to the number we originally sent.
-
- int numberOfMessagesReadByConsumer = totalConsumed.intValue();
- int numberOfMessagesOnDestinationQueue = _managedDestinationQueue.getMessageCount().intValue();
- int numberOfMessagesRemainingOnSourceQueue = _managedSourceQueue.getMessageCount().intValue();
-
- LOGGER.debug("Async consumer read : " + numberOfMessagesReadByConsumer
- + " Number of messages moved to destination : " + numberOfMessagesOnDestinationQueue
- + " Number of messages remaining on source : " + numberOfMessagesRemainingOnSourceQueue);
- assertEquals("Unexpected number of messages after move", numberOfMessagesToSend, numberOfMessagesReadByConsumer + numberOfMessagesOnDestinationQueue + numberOfMessagesRemainingOnSourceQueue);
- }
-
- public void testMoveMessagesBetweenQueuesWithActiveConsumerOnDestinationQueue() throws Exception
- {
- setTestClientSystemProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, new Integer(1).toString());
- Connection asyncConnection = getConnection();
- asyncConnection.start();
-
- final int numberOfMessagesToSend = 50;
- sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
- syncSession(_session);
- assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
-
- List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
- long fromMessageId = amqMessagesIds.get(0);
- long toMessageId = amqMessagesIds.get(numberOfMessagesToSend - 1);
-
- AtomicInteger totalConsumed = new AtomicInteger(0);
- CountDownLatch allMessagesConsumedLatch = new CountDownLatch(numberOfMessagesToSend);
- startAsyncConsumerOn(_destinationQueue, asyncConnection, allMessagesConsumedLatch, totalConsumed);
-
- _managedSourceQueue.moveMessages(fromMessageId, toMessageId, _destinationQueueName);
-
- allMessagesConsumedLatch.await(5000, TimeUnit.MILLISECONDS);
- assertEquals("Did not consume all messages from destination queue", numberOfMessagesToSend, totalConsumed.intValue());
- }
-
- /**
- * Tests {@link ManagedQueue#moveMessages(long, long, String)} interface.
- */
- public void testMoveMessageBetweenQueuesWithBrokerRestart() throws Exception
- {
- final int numberOfMessagesToSend = 1;
-
- sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
- syncSession(_session);
- assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
-
- restartBroker();
-
- createManagementInterfacesForQueues();
- createConnectionAndSession();
-
- List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
-
- // Move messages to destination
- long messageId = amqMessagesIds.get(0);
- _managedSourceQueue.moveMessages(messageId, messageId, _destinationQueueName);
-
- assertEquals("Unexpected queue depth on destination queue after move", 1, _managedDestinationQueue.getMessageCount().intValue());
- assertEquals("Unexpected queue depth on source queue after move", 0, _managedSourceQueue.getMessageCount().intValue());
-
- assertMessageIndicesOn(_destinationQueue, 0);
- }
-
- /**
- * Tests {@link ManagedQueue#copyMessages(long, long, String)} interface.
- */
- public void testCopyMessageBetweenQueuesWithBrokerRestart() throws Exception
- {
- final int numberOfMessagesToSend = 1;
-
- sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
- syncSession(_session);
- assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
-
- restartBroker();
-
- createManagementInterfacesForQueues();
- createConnectionAndSession();
-
- List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
-
- // Move messages to destination
- long messageId = amqMessagesIds.get(0);
- _managedSourceQueue.copyMessages(messageId, messageId, _destinationQueueName);
-
- assertEquals("Unexpected queue depth on destination queue after copy", 1, _managedDestinationQueue.getMessageCount().intValue());
- assertEquals("Unexpected queue depth on source queue after copy", 1, _managedSourceQueue.getMessageCount().intValue());
-
- assertMessageIndicesOn(_destinationQueue, 0);
- }
-
- @Override
- public Message createNextMessage(Session session, int messageNumber) throws JMSException
- {
- Message message = session.createTextMessage(getContentForMessageNumber(messageNumber));
- message.setIntProperty(INDEX, messageNumber);
- return message;
- }
-
- private void startAsyncConsumerOn(Destination queue, Connection asyncConnection,
- final CountDownLatch requiredNumberOfMessagesRead, final AtomicInteger totalConsumed) throws Exception
- {
- Session session = asyncConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer consumer = session.createConsumer(queue);
- consumer.setMessageListener(new MessageListener()
- {
-
- @Override
- public void onMessage(Message arg0)
- {
- totalConsumed.incrementAndGet();
- requiredNumberOfMessagesRead.countDown();
- }
- });
- }
-
- private void assertMessageIndicesOn(Destination queue, int... expectedIndices) throws Exception
- {
- MessageConsumer consumer = _session.createConsumer(queue);
-
- for (int i : expectedIndices)
- {
- TextMessage message = (TextMessage)consumer.receive(1000);
- assertNotNull("Expected message with index " + i, message);
- assertEquals("Expected message with index " + i, i, message.getIntProperty(INDEX));
- assertEquals("Expected message content", getContentForMessageNumber(i), message.getText());
- }
-
- assertNull("Unexpected message encountered", consumer.receive(1000));
- }
-
- private List<Long> getAMQMessageIdsOn(ManagedQueue managedQueue, long startIndex, long endIndex) throws Exception
- {
- final SortedSet<Long> messageIds = new TreeSet<Long>();
-
- final TabularData tab = managedQueue.viewMessages(startIndex, endIndex);
- final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator();
- while(rowItr.hasNext())
- {
- final CompositeData row = rowItr.next();
- long amqMessageId = (Long)row.get(ManagedQueue.MSG_AMQ_ID);
- messageIds.add(amqMessageId);
- }
-
- return new ArrayList<Long>(messageIds);
- }
-
- /**
- *
- * Utility method to convert array of Strings in the form x = y into a
- * map with key/value x =&gt; y.
- *
- */
- private Map<String,String> headerArrayToMap(final String[] headerArray)
- {
- final Map<String, String> headerMap = new HashMap<String, String>();
- final List<String> headerList = Arrays.asList(headerArray);
- for (Iterator<String> iterator = headerList.iterator(); iterator.hasNext();)
- {
- final String nameValuePair = iterator.next();
- final String[] nameValue = nameValuePair.split(" *= *", 2);
- headerMap.put(nameValue[0], nameValue[1]);
- }
- return headerMap;
- }
-
- private void createQueueOnBroker(Destination destination) throws JMSException
- {
- _session.createConsumer(destination).close(); // Create a consumer only to cause queue creation
- }
-
- private void syncSession(Session session) throws Exception
- {
- ((AMQSession<?,?>)session).sync();
- }
-
- private void createConnectionAndSession() throws JMSException,
- NamingException
- {
- _connection = getConnection();
- _connection.start();
- _session = _connection.createSession(true, Session.SESSION_TRANSACTED);
- }
-
- private void createManagementInterfacesForQueues()
- {
- _managedSourceQueue = _jmxUtils.getManagedQueue(_sourceQueueName);
- _managedDestinationQueue = _jmxUtils.getManagedQueue(_destinationQueueName);
- }
-
- private String getContentForMessageNumber(int msgCount)
- {
- return "Message count " + msgCount;
- }
-
- private final class RecordingNotificationListener implements NotificationListener
- {
- private final CountDownLatch _notificationReceivedLatch;
- private final AtomicInteger _numberOfNotifications;
- private final AtomicReference<Notification> _lastNotification;
-
- private RecordingNotificationListener(int expectedNumberOfNotifications)
- {
- _notificationReceivedLatch = new CountDownLatch(expectedNumberOfNotifications);
- _numberOfNotifications = new AtomicInteger(0);
- _lastNotification = new AtomicReference<Notification>();
- }
-
- @Override
- public void handleNotification(Notification notification, Object handback)
- {
- _lastNotification.set(notification);
- _numberOfNotifications.incrementAndGet();
- _notificationReceivedLatch.countDown();
- }
-
- public int getNumberOfNotificationsReceived()
- {
- return _numberOfNotifications.get();
- }
-
- public Notification getLastNotification()
- {
- return _lastNotification.get();
- }
-
- public void awaitExpectedNotifications(long timeout, TimeUnit timeunit) throws InterruptedException
- {
- _notificationReceivedLatch.await(timeout, timeunit);
- }
- }
-
-}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java
deleted file mode 100644
index c3fff94923..0000000000
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java
+++ /dev/null
@@ -1,204 +0,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.
- *
- */
-package org.apache.qpid.systest.management.jmx;
-
-import java.util.List;
-
-import javax.jms.Connection;
-import javax.jms.MessageConsumer;
-import javax.jms.Queue;
-import javax.jms.Session;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.management.common.mbeans.ManagedBroker;
-import org.apache.qpid.management.common.mbeans.ManagedConnection;
-import org.apache.qpid.management.common.mbeans.ServerInformation;
-import org.apache.qpid.test.utils.JMXTestUtils;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-public class StatisticsTest extends QpidBrokerTestCase
-{
- private static final String TEST_USER = "admin";
- private static final String TEST_PASSWORD = "admin";
- private static final int MESSAGE_COUNT_TEST = 5;
- private static final int MESSAGE_COUNT_DEV = 9;
-
- private JMXTestUtils _jmxUtils;
- private Connection _test1, _dev;
- private Session _testSession, _developmentSession;
- private Queue _developmentQueue, _testQueue;
- protected String _brokerUrl;
-
- @Override
- public void setUp() throws Exception
- {
- _jmxUtils = new JMXTestUtils(this, TEST_USER, TEST_PASSWORD);
- _jmxUtils.setUp();
-
- super.setUp();
-
- _brokerUrl = getBroker().toString();
- _test1 = new AMQConnection(_brokerUrl, TEST_USER, TEST_PASSWORD, "clientid", "test");
- _dev = new AMQConnection(_brokerUrl, TEST_USER, TEST_PASSWORD, "clientid", "development");
- _test1.start();
- _dev.start();
-
- _testSession = _test1.createSession(true, Session.SESSION_TRANSACTED);
- _developmentSession = _dev.createSession(true, Session.SESSION_TRANSACTED);
-
- _developmentQueue = _developmentSession.createQueue(getTestQueueName());
- _testQueue = _testSession.createQueue(getTestQueueName());
-
- //Create queues by opening and closing consumers
- final MessageConsumer testConsumer = _testSession.createConsumer(_testQueue);
- testConsumer.close();
- final MessageConsumer developmentConsumer = _developmentSession.createConsumer(_developmentQueue);
- developmentConsumer.close();
-
- _jmxUtils.open();
- }
-
- @Override
- public void tearDown() throws Exception
- {
- _jmxUtils.close();
-
- super.tearDown();
- }
-
- public void testInitialStatisticValues() throws Exception
- {
- //Check initial values
- checkSingleConnectionOnVHostStatistics("test", 0, 0, 0, 0);
- checkVHostStatistics("test", 0, 0, 0, 0);
- checkSingleConnectionOnVHostStatistics("development", 0, 0, 0, 0);
- checkVHostStatistics("development", 0, 0, 0, 0);
- checkBrokerStatistics(0, 0, 0, 0);
- }
-
- public void testSendOnSingleVHost() throws Exception
- {
- sendMessagesAndSync(_testSession, _testQueue, MESSAGE_COUNT_TEST);
-
- //Check values
- checkSingleConnectionOnVHostStatistics("test", MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
- checkVHostStatistics("test", MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
- checkSingleConnectionOnVHostStatistics("development", 0, 0, 0, 0);
- checkVHostStatistics("development", 0, 0, 0, 0);
- checkBrokerStatistics(MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
- }
-
- public void testSendOnTwoVHosts() throws Exception
- {
- sendMessagesAndSync(_testSession, _testQueue, MESSAGE_COUNT_TEST);
- sendMessagesAndSync(_developmentSession, _developmentQueue, MESSAGE_COUNT_DEV);
-
- //Check values
- checkSingleConnectionOnVHostStatistics("test", MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
- checkVHostStatistics("test", MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
- checkSingleConnectionOnVHostStatistics("development", MESSAGE_COUNT_DEV, 0, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE, 0);
- checkVHostStatistics("development", MESSAGE_COUNT_DEV, 0, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE, 0);
- checkBrokerStatistics(MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV, 0, (MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV) * DEFAULT_MESSAGE_SIZE, 0);
- }
-
- public void testSendAndConsumeOnSingleVHost() throws Exception
- {
- sendMessagesAndSync(_testSession, _testQueue, MESSAGE_COUNT_TEST);
- consumeMessages(_testSession, _testQueue, MESSAGE_COUNT_TEST);
-
- //Check values
- checkSingleConnectionOnVHostStatistics("test", MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
- checkVHostStatistics("test", MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
- checkSingleConnectionOnVHostStatistics("development", 0, 0, 0, 0);
- checkVHostStatistics("development", 0, 0, 0, 0);
- checkBrokerStatistics(MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
- }
-
- public void testSendAndConsumeOnTwoVHosts() throws Exception
- {
- sendMessagesAndSync(_testSession, _testQueue, MESSAGE_COUNT_TEST);
- sendMessagesAndSync(_developmentSession, _developmentQueue, MESSAGE_COUNT_DEV);
- consumeMessages(_testSession, _testQueue, MESSAGE_COUNT_TEST);
- consumeMessages(_developmentSession, _developmentQueue, MESSAGE_COUNT_DEV);
-
- //Check values
- checkSingleConnectionOnVHostStatistics("test", MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
- checkVHostStatistics("test", MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
- checkSingleConnectionOnVHostStatistics("development", MESSAGE_COUNT_DEV, MESSAGE_COUNT_DEV, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE);
- checkVHostStatistics("development", MESSAGE_COUNT_DEV, MESSAGE_COUNT_DEV, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE);
- checkBrokerStatistics(MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV, MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV, (MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV) * DEFAULT_MESSAGE_SIZE, (MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV) * DEFAULT_MESSAGE_SIZE);
- }
-
- private void sendMessagesAndSync(Session session, Queue queue, int numberOfMessages) throws Exception
- {
- //Send messages via connection on and sync
- sendMessage(session, queue, numberOfMessages);
- ((AMQSession<?,?>)session).sync();
- }
-
- private void consumeMessages(Session session, Queue queue, int numberOfMessages) throws Exception
- {
- //consume the messages on the virtual host
- final MessageConsumer consumer = session.createConsumer(queue);
- for (int i = 0 ; i < numberOfMessages ; i++)
- {
- assertNotNull("an expected message was not received", consumer.receive(1500));
- }
- session.commit();
- consumer.close();
- }
-
- private void checkSingleConnectionOnVHostStatistics(String vHostName, long messagesSent, long messagesReceived, long dataSent, long dataReceived)
- {
- List<ManagedConnection> managedConnections = _jmxUtils.getManagedConnections(vHostName);
- assertEquals(1, managedConnections.size());
-
- ManagedConnection managedConnection = managedConnections.get(0);
-
- assertEquals(messagesSent, managedConnection.getTotalMessagesReceived());
- assertEquals(messagesReceived, managedConnection.getTotalMessagesDelivered());
-
- assertEquals(dataSent, managedConnection.getTotalDataReceived());
- assertEquals(dataReceived, managedConnection.getTotalDataDelivered());
- }
-
- private void checkVHostStatistics(String vHostName, long messagesSent, long messagesReceived, long dataSent, long dataReceived)
- {
- ManagedBroker vhost = _jmxUtils.getManagedBroker(vHostName);
-
- assertEquals(messagesSent, vhost.getTotalMessagesReceived());
- assertEquals(messagesReceived, vhost.getTotalMessagesDelivered());
-
- assertEquals(dataSent, vhost.getTotalDataReceived());
- assertEquals(dataReceived, vhost.getTotalDataDelivered());
- }
-
- private void checkBrokerStatistics(long messagesSent, long messagesReceived, long dataSent, long dataReceived)
- {
- ServerInformation broker = _jmxUtils.getServerInformation();
-
- assertEquals(messagesSent, broker.getTotalMessagesReceived());
- assertEquals(messagesReceived, broker.getTotalMessagesDelivered());
-
- assertEquals(dataSent, broker.getTotalDataReceived());
- assertEquals(dataReceived, broker.getTotalDataDelivered());
- }
-}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java
deleted file mode 100644
index 62b1b554a9..0000000000
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java
+++ /dev/null
@@ -1,251 +0,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.
- */
-package org.apache.qpid.systest.management.jmx;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-
-import org.apache.qpid.management.common.mbeans.UserManagement;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
-import org.apache.qpid.test.utils.JMXTestUtils;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-import org.apache.qpid.tools.security.Passwd;
-
-/**
- * System test for User Management.
- *
- */
-public class UserManagementTest extends QpidBrokerTestCase
-{
- private static final String TEST_NEWPASSWORD = "newpassword";
- private static final String TEST_PASSWORD = "password";
- private JMXTestUtils _jmxUtils;
- private String _testUserName;
- private File _passwordFile;
- private UserManagement _userManagement;
- private Passwd _passwd;
-
- public void setUp() throws Exception
- {
- _passwd = createPasswordEncodingUtility();
- _passwordFile = createTemporaryPasswordFileWithJmxAdminUser();
-
- setConfigurationProperty("security.pd-auth-manager.principal-database.class", getPrincipalDatabaseImplClass().getName());
- setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile");
- setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.value", _passwordFile.getAbsolutePath());
-
- _jmxUtils = new JMXTestUtils(this);
- _jmxUtils.setUp();
-
- super.setUp();
- _jmxUtils.open();
-
- _testUserName = getTestName() + System.currentTimeMillis();
-
- _userManagement = _jmxUtils.getUserManagement();
- }
-
-
- public void tearDown() throws Exception
- {
- try
- {
- if (_jmxUtils != null)
- {
- _jmxUtils.close();
- }
- }
- finally
- {
- super.tearDown();
- }
- }
-
- public void testCreateUser() throws Exception
- {
- final int initialNumberOfUsers = _userManagement.viewUsers().size();
- assertFileDoesNotContainsPasswordForUser(_testUserName);
-
- boolean success = _userManagement.createUser(_testUserName, TEST_PASSWORD);
- assertTrue("Should have been able to create new user " + _testUserName, success);
- assertEquals("Unexpected number of users after add", initialNumberOfUsers + 1, _userManagement.viewUsers().size());
-
- assertFileContainsPasswordForUser(_testUserName);
- }
-
- public void testJmsLoginForNewUser() throws Exception
- {
- assertJmsConnectionFails(_testUserName, TEST_PASSWORD);
- testCreateUser();
-
- assertJmsConnectionSucceeds(_testUserName, TEST_PASSWORD);
- }
-
- public void testDeleteUser() throws Exception
- {
- final int initialNumberOfUsers = _userManagement.viewUsers().size();
-
- testCreateUser();
-
- boolean success = _userManagement.deleteUser(_testUserName);
- assertTrue("Should have been able to delete new user " + _testUserName, success);
- assertEquals("Unexpected number of users after delete", initialNumberOfUsers, _userManagement.viewUsers().size());
- assertFileDoesNotContainsPasswordForUser(_testUserName);
- }
-
- public void testJmsLoginNotPossibleForDeletedUser() throws Exception
- {
- testDeleteUser();
-
- assertJmsConnectionFails(_testUserName, TEST_PASSWORD);
- }
-
- public void testSetPassword() throws Exception
- {
- testCreateUser();
-
- _userManagement.setPassword(_testUserName, TEST_NEWPASSWORD);
-
- assertFileContainsPasswordForUser(_testUserName);
- }
-
- public void testJmsLoginForPasswordChangedUser() throws Exception
- {
- testSetPassword();
-
- assertJmsConnectionSucceeds(_testUserName, TEST_NEWPASSWORD);
- assertJmsConnectionFails(_testUserName, TEST_PASSWORD);
- }
-
- public void testReload() throws Exception
- {
- writePasswordFile(_passwordFile, JMXTestUtils.DEFAULT_USERID, JMXTestUtils.DEFAULT_PASSWORD, _testUserName, TEST_PASSWORD);
-
- assertJmsConnectionFails(_testUserName, TEST_PASSWORD);
-
- _userManagement.reloadData();
-
- assertJmsConnectionSucceeds(_testUserName, TEST_PASSWORD);
- }
-
- protected Passwd createPasswordEncodingUtility()
- {
- return new Passwd()
- {
- @Override
- public String getOutput(String username, String password)
- {
- return username + ":" + password;
- }
- };
- }
-
- protected Class<? extends PrincipalDatabase> getPrincipalDatabaseImplClass()
- {
- return PlainPasswordFilePrincipalDatabase.class;
- }
-
- private File createTemporaryPasswordFileWithJmxAdminUser() throws Exception
- {
- File passwordFile = File.createTempFile("passwd", "pwd");
- passwordFile.deleteOnExit();
- writePasswordFile(passwordFile, JMXTestUtils.DEFAULT_USERID, JMXTestUtils.DEFAULT_PASSWORD);
- return passwordFile;
- }
-
- private void writePasswordFile(File passwordFile, String... userNamePasswordPairs) throws Exception
- {
- FileWriter writer = null;
- try
- {
- writer = new FileWriter(passwordFile);
- for (int i = 0; i < userNamePasswordPairs.length; i=i+2)
- {
- String username = userNamePasswordPairs[i];
- String password = userNamePasswordPairs[i+1];
- writer.append(_passwd.getOutput(username, password) + "\n");
- }
- }
- finally
- {
- writer.close();
- }
- }
-
-
- private void assertFileContainsPasswordForUser(String username) throws IOException
- {
- assertTrue("Could not find password for user " + username + " within " + _passwordFile, passwordFileContainsUser(username));
- }
-
- private void assertFileDoesNotContainsPasswordForUser(String username) throws IOException
- {
- assertFalse("Could not find password for user " + username + " within " + _passwordFile, passwordFileContainsUser(username));
- }
-
- private boolean passwordFileContainsUser(String username) throws IOException
- {
- BufferedReader reader = null;
- try
- {
- reader = new BufferedReader(new FileReader(_passwordFile));
- String line = reader.readLine();
- while(line != null)
- {
- if (line.startsWith(username))
- {
- return true;
- }
- line = reader.readLine();
- }
-
- return false;
- }
- finally
- {
- reader.close();
- }
- }
-
- private void assertJmsConnectionSucceeds(String username, String password) throws Exception
- {
- Connection connection = getConnection(username, password);
- assertNotNull(connection);
- }
-
- private void assertJmsConnectionFails(String username, String password) throws Exception
- {
- try
- {
- getConnection(username, password);
- fail("Exception not thrown");
- }
- catch (JMSException e)
- {
- // PASS
- }
- }
-}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java b/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java
deleted file mode 100644
index 84a66232ce..0000000000
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java
+++ /dev/null
@@ -1,39 +0,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.
- */
-package org.apache.qpid.systest.management.jmx;
-
-import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
-import org.apache.qpid.tools.security.Passwd;
-
-public class UserManagementWithBase64MD5PasswordsTest extends UserManagementTest
-{
- @Override
- protected Passwd createPasswordEncodingUtility()
- {
- return new Passwd();
- }
-
- @Override
- protected Class<? extends PrincipalDatabase> getPrincipalDatabaseImplClass()
- {
- return Base64MD5PasswordFilePrincipalDatabase.class;
- }
-
-}
diff --git a/java/broker/bin/qpid-server b/java/broker/bin/qpid-server
index 382004c9f5..206ae6a225 100755
--- a/java/broker/bin/qpid-server
+++ b/java/broker/bin/qpid-server
@@ -33,8 +33,8 @@ if [ -z "$QPID_PNAME" ]; then
export QPID_PNAME=" -DPNAME=QPBRKR"
fi
-# Set classpath to include the qpid-all manifest jar, and any jars supplied in lib/opt
-QPID_LIBS="$QPID_HOME/lib/qpid-all.jar:$QPID_HOME/lib/opt/*"
+# Set classpath to include the qpid-all manifest jar, plus jars in lib/plugins and lib/opt
+QPID_LIBS="$QPID_HOME/lib/qpid-all.jar:$QPID_HOME/lib/plugins/*:$QPID_HOME/lib/opt/*"
# Set other variables used by the qpid-run script before calling
export JAVA=java \
diff --git a/java/broker/bin/qpid-server.bat b/java/broker/bin/qpid-server.bat
index 6b7bbcb96e..0d0355c44a 100644
--- a/java/broker/bin/qpid-server.bat
+++ b/java/broker/bin/qpid-server.bat
@@ -76,8 +76,8 @@ echo Using CLASSPATH: %CLASSPATH%
goto afterQpidClasspath
:noQpidClasspath
-echo Warning: Qpid classpath not set. CLASSPATH set to %QPID_HOME%\lib\qpid-all.jar
-set CLASSPATH=%QPID_HOME%\lib\qpid-all.jar;%QPID_HOME%\lib\opt\*
+echo Warning: Qpid classpath not set. CLASSPATH set to %QPID_HOME%\lib\qpid-all.jar;%QPID_HOME%\lib\plugins\*;%QPID_HOME%\lib\opt\*
+set CLASSPATH=%QPID_HOME%\lib\qpid-all.jar;%QPID_HOME%\lib\plugins\*;%QPID_HOME%\lib\opt\*
:afterQpidClasspath
REM start parsing -run arguments
diff --git a/java/broker/build.xml b/java/broker/build.xml
index 938066728e..8581b7c639 100644
--- a/java/broker/build.xml
+++ b/java/broker/build.xml
@@ -20,7 +20,7 @@
-->
<project name="AMQ Broker" default="build">
<property name="module.depends" value="management/common common amqp-1-0-common"/>
- <property name="module.test.depends" value="common/test" />
+ <property name="module.test.depends" value="common/tests" />
<property name="module.main" value="org.apache.qpid.server.Main"/>
<property name="module.genpom" value="true"/>
@@ -28,23 +28,7 @@
<property name="output.dir" value="${module.precompiled}/org/apache/qpid/server/filter/jms/selector"/>
- <property name="qmf.input.file" value="${project.root}/../specs/management-schema.xml"/>
- <property name="qmf.xsl.file" value="${project.root}/broker/src/xsl/qmf.xsl"/>
- <property name="qmf.output.dir" value="${module.precompiled}/org/apache/qpid/qmf/schema"/>
- <property name="qmf.output.file" value="BrokerSchema.java"/>
-
- <target name="precompile" depends="gen_logging,gen_qmf"/>
-
- <target name="check_qmf_deps">
- <uptodate property="gen_qmf.notRequired" targetfile="${qmf.output.dir}/${qmf.output.file}">
- <srcfiles file="${qmf.input.file}"/>
- <srcfiles file="${qmf.xsl.file}"/>
- </uptodate>
- </target>
-
- <target name="gen_qmf" depends="check_qmf_deps" unless="gen_qmf.notRequired">
- <xslt in="${qmf.input.file}" out="${qmf.output.dir}/${qmf.output.file}" style="${qmf.xsl.file}"/>
- </target>
+ <target name="precompile" depends="gen_logging"/>
<target name="copy-etc-release" if="module.etc.exists" description="copy etc directory if it exists to build tree">
<copy todir="${module.release}/etc" failonerror="false" flatten="true">
@@ -64,9 +48,15 @@
<fixcrlf srcdir="${module.release}/bin" fixlast="true" eol="dos" includes="*.bat"/>
</target>
- <target name="release-bin-other" depends="release-bin-other-bdbstore" description="copy broker-plugins into module release">
+ <target name="release-bin-other" depends="release-bin-other-lib-opt,release-bin-other-bdbstore,release-bin-copy-broker-plugins"/>
+
+ <target name="release-bin-other-lib-opt" depends="release-bin-other-bdbstore" description="make lib/opt dir in the module release">
+ <mkdir dir="${module.release}/lib/opt"/>
+ </target>
+
+ <target name="release-bin-copy-broker-plugins" description="copy broker-plugins into module release">
<copy todir="${module.release}/lib/plugins" failonerror="true">
- <fileset dir="${build.lib}/plugins"/>
+ <fileset dir="${build.scratch.broker.plugins.lib}"/>
</copy>
</target>
diff --git a/java/broker/etc/broker_example.acl b/java/broker/etc/broker_example.acl
index 45a48bda09..fc650801c8 100644
--- a/java/broker/etc/broker_example.acl
+++ b/java/broker/etc/broker_example.acl
@@ -19,24 +19,20 @@
### EXAMPLE ACL V2 FILE
### NOTE: Rules are considered from top to bottom, and the first matching rule governs the decision.
-
-### DEFINE GROUPS ###
-
-#Define a 'messaging-users' group with users 'client' and 'server' in it
-GROUP messaging-users client server
-
-#Define a group for management web console users
-GROUP webadmins webadmin
+### Rules may refer to users or groups. Groups are currently defined in the etc/groups file.
### JMX MANAGEMENT ####
-# Allow everyone to perform read operations on the ServerInformation mbean
-# This is used for items such as querying the management API and broker release versions.
-ACL ALLOW ALL ACCESS METHOD component="ServerInformation"
+# To use JMX management, first give the user/group ACCESS MANAGEMENT permission
+ACL ALLOW administrators ACCESS MANAGEMENT
+ACL ALLOW guest ACCESS MANAGEMENT
-# Allow 'admin' all management operations. To reduce log file noise, only non-read-only operations are logged.
-ACL ALLOW admin ACCESS METHOD
-ACL ALLOW-LOG admin ALL METHOD
+# Allow guest to perform read operations on the ServerInformation mbean
+ACL ALLOW guest ACCESS METHOD component="ServerInformation"
+
+# Allow 'administrators' all management operations. To reduce log file noise, only non-read-only operations are logged.
+ACL ALLOW administrators ACCESS METHOD
+ACL ALLOW-LOG administrators ALL METHOD
# Allow 'guest' to view logger levels, and use getter methods on LoggingManagement
ACL ALLOW guest ACCESS METHOD component="LoggingManagement" name="viewEffectiveRuntimeLoggerLevels"
@@ -49,17 +45,61 @@ ACL DENY-LOG ALL ACCESS METHOD component="UserManagement"
ACL DENY-LOG ALL ACCESS METHOD component="ConfigurationManagement"
ACL DENY-LOG ALL ACCESS METHOD component="LoggingManagement"
-# Allow everyone to perform all read operations (using ALLOW rather than ALLOW-LOG to reduce log file noise)
-# on the mbeans not listed in the DENY rules above
+# Allow everyone to perform all read operations on the mbeans not listed in the DENY rules above
ACL ALLOW ALL ACCESS METHOD
+### WEB MANAGEMENT ####
+
+# To use web management, first give the user/group ACCESS MANAGEMENT permission
+ACL ALLOW webadmins ACCESS MANAGEMENT
+
+# ACL for web management console admins
+# All rules below are required for console admin users
+# to perform create/update/delete operations
+ACL ALLOW-LOG webadmins CREATE QUEUE
+ACL ALLOW-LOG webadmins DELETE QUEUE
+ACL ALLOW-LOG webadmins PURGE QUEUE
+ACL ALLOW-LOG webadmins CREATE EXCHANGE
+ACL ALLOW-LOG webadmins DELETE EXCHANGE
+ACL ALLOW-LOG webadmins BIND EXCHANGE
+ACL ALLOW-LOG webadmins UNBIND EXCHANGE
+ACL ALLOW-LOG webadmins CREATE GROUP
+ACL ALLOW-LOG webadmins DELETE GROUP
+ACL ALLOW-LOG webadmins UPDATE GROUP
+ACL ALLOW-LOG webadmins CREATE USER
+ACL ALLOW-LOG webadmins DELETE USER
+ACL ALLOW-LOG webadmins UPDATE USER
+
+ACL ALLOW-LOG webadmins UPDATE METHOD
+
+# at the moment only the following UPDATE METHOD rules are supported by web management console
+#ACL ALLOW-LOG webadmins UPDATE METHOD component="VirtualHost.Queue" name="moveMessages"
+#ACL ALLOW-LOG webadmins UPDATE METHOD component="VirtualHost.Queue" name="copyMessages"
+#ACL ALLOW-LOG webadmins UPDATE METHOD component="VirtualHost.Queue" name="deleteMessages"
+
### MESSAGING ###
+# The 'ACCESS VIRTUALHOST' rules below apply to messaging operations (as opposed to management operations)
+
+# Firewall examples
+
+# Deny access to all users from *.example.company1.com and *.example.company2.com
+ACL DENY-LOG all ACCESS VIRTUALHOST from_hostname=".*\.example\.company1.com,.*\.example\.company2.com"
-#Example permissions for request-response based messaging.
+# Deny access to all users in the IP ranges 192.168.1.0-192.168.1.255 and 192.168.2.0-192.168.2.255,
+# using the notation specified in RFC 4632, "Classless Inter-domain Routing (CIDR)"
+ACL DENY-LOG messaging-users ACCESS VIRTUALHOST from_network="192.168.1.0/24,192.168.2.0/24"
-#Allow 'messaging-users' group to connect to the virtualhost
+# Deny access to all users in the IP ranges 192.169.1.0-192.169.1.255 and 192.169.2.0-192.169.2.255,
+# using wildcard notation.
+ACL DENY-LOG messaging-users ACCESS VIRTUALHOST from_network="192.169.1.*,192.169.2.*"
+
+# Allow 'messaging-users' group to connect to all virtualhosts
ACL ALLOW-LOG messaging-users ACCESS VIRTUALHOST
+# Deny messaging-users management
+ACL DENY-LOG messaging-users ACCESS MANAGEMENT
+
+
# Client side
# Allow the 'client' user to publish requests to the request queue and create, consume from, and delete temporary reply queues.
ACL ALLOW-LOG client CREATE QUEUE temporary="true"
@@ -77,24 +117,8 @@ ACL ALLOW-LOG server CONSUME QUEUE name="example.RequestQueue"
ACL ALLOW-LOG server BIND EXCHANGE
ACL ALLOW-LOG server PUBLISH EXCHANGE name="amq.direct" routingKey="TempQueue*"
-# ACL for web management console admins
-# All rules below are required for console admin users
-# to perform create/update/delete operations
-ACL ALLOW-LOG webadmins CREATE QUEUE
-ACL ALLOW-LOG webadmins DELETE QUEUE
-ACL ALLOW-LOG webadmins PURGE QUEUE
-ACL ALLOW-LOG webadmins CREATE EXCHANGE
-ACL ALLOW-LOG webadmins DELETE EXCHANGE
-ACL ALLOW-LOG webadmins BIND EXCHANGE
-ACL ALLOW-LOG webadmins UNBIND EXCHANGE
-ACL ALLOW-LOG webadmins UPDATE METHOD
-
-# at the moment only the following UPDATE METHOD rules are supported by web management console
-#ACL ALLOW-LOG webadmins UPDATE METHOD component="VirtualHost.Queue" name="moveMessages"
-#ACL ALLOW-LOG webadmins UPDATE METHOD component="VirtualHost.Queue" name="copyMessages"
-#ACL ALLOW-LOG webadmins UPDATE METHOD component="VirtualHost.Queue" name="deleteMessages"
### DEFAULT ###
-#Deny all users from performing all operations
+# Deny all users from performing all operations
ACL DENY-LOG all all
diff --git a/java/broker/etc/config.xml b/java/broker/etc/config.xml
deleted file mode 100644
index 08c7c23d13..0000000000
--- a/java/broker/etc/config.xml
+++ /dev/null
@@ -1,106 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <prefix>${QPID_HOME}</prefix>
- <work>${QPID_WORK}</work>
- <conf>${prefix}/etc</conf>
-
- <plugin-directory>${QPID_HOME}/lib/plugins</plugin-directory>
- <cache-directory>${QPID_WORK}/cache</cache-directory>
-
- <connector>
- <!-- To enable SSL edit the keystorePath and keystorePassword
- and set enabled to true.
- To disable Non-SSL port set sslOnly to true -->
- <ssl>
- <enabled>false</enabled>
- <port>5671</port>
- <sslOnly>false</sslOnly>
- <keyStorePath>/path/to/keystore.ks</keyStorePath>
- <keyStorePassword>keystorepass</keyStorePassword>
- </ssl>
- <port>5672</port>
- <socketReceiveBuffer>262144</socketReceiveBuffer>
- <socketSendBuffer>262144</socketSendBuffer>
- </connector>
- <management>
- <enabled>true</enabled>
- <jmxport>
- <registryServer>8999</registryServer>
- <!--
- If unspecified, connectorServer defaults to 100 + registryServer port.
- <connectorServer>9099</connectionServer>
- -->
- </jmxport>
- <ssl>
- <enabled>false</enabled>
- <!-- Update below path to your keystore location. -->
- <keyStorePath>${conf}/qpid.keystore</keyStorePath>
- <keyStorePassword>password</keyStorePassword>
- </ssl>
- <https>
- <enabled>false</enabled>
- </https>
- </management>
- <advanced>
- <framesize>65535</framesize>
- <locale>en_US</locale>
- </advanced>
-
- <security>
- <pd-auth-manager>
- <principal-database>
- <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
- <attributes>
- <attribute>
- <name>passwordFile</name>
- <value>${conf}/passwd</value>
- </attribute>
- </attributes>
- </principal-database>
- </pd-auth-manager>
-
- <!-- By default, all authenticated users have permissions to perform all actions -->
-
- <!-- ACL Example
- This example illustrates securing the both Management (JMX) and Messaging.
- <acl>${conf}/broker_example.acl</acl>
- -->
-
- <msg-auth>false</msg-auth>
- </security>
-
- <virtualhosts>${conf}/virtualhosts.xml</virtualhosts>
-
- <heartbeat>
- <delay>0</delay>
- <timeoutFactor>2.0</timeoutFactor>
- </heartbeat>
- <queue>
- <auto_register>true</auto_register>
- </queue>
-
- <status-updates>ON</status-updates>
-
-</broker>
-
-
diff --git a/java/broker/etc/groups b/java/broker/etc/groups
new file mode 100644
index 0000000000..e3912ece99
--- /dev/null
+++ b/java/broker/etc/groups
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+#
+# To define a group, use the format:
+#
+# <groupname>.users=<user1>,<user2>,...,<usern>
+#
+
+messaging-users.users=guest,client,server
+administrators.users=admin
+webadmins.users=webadmin
+
diff --git a/java/broker/etc/log4j.xml b/java/broker/etc/log4j.xml
index b1b31248c1..71a13875a1 100644
--- a/java/broker/etc/log4j.xml
+++ b/java/broker/etc/log4j.xml
@@ -68,7 +68,7 @@
<param name="backupFilesToPath" value="${QPID_WORK}/backup/log"/>
<layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%t] (%F:%L) - %m%n"/>
+ <param name="ConversionPattern" value="%d %-5p [%t] (%c{2}) - %m%n"/>
</layout>
</appender>
@@ -77,20 +77,20 @@
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%t] (%F:%L) - %m%n"/>
+ <param name="ConversionPattern" value="%d %-5p [%t] (%c{2}) - %m%n"/>
</layout>
</appender>
<appender class="org.apache.log4j.ConsoleAppender" name="STDOUT">
<layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%t] (%F:%L) - %m%n"/>
+ <param name="ConversionPattern" value="%d %-5p [%t] (%c{2}) - %m%n"/>
</layout>
</appender>
<!-- Provide warnings to standard output -->
- <category additivity="true" name="org.apache.qpid">
- <priority value="warn"/>
- </category>
+ <logger additivity="true" name="org.apache.qpid">
+ <level value="warn"/>
+ </logger>
<!-- Enable info messages for the status-logging hierarchy -->
<logger additivity="true" name="qpid.message">
@@ -108,21 +108,14 @@
<level value="info"/>
</logger>
- <!-- Examples of additional logging settings -->
- <!-- Used to generate extra debug. See debug.log4j.xml -->
-
- <!--<category additivity="true" name="org.apache.qpid.server.store">
- <priority value="debug"/>
- </category-->
-
<!-- Set the commons logging that the XML parser uses to WARN, it is very chatty at debug -->
<logger name="org.apache.commons">
- <level value="WARN"/>
+ <level value="warn"/>
</logger>
<!-- Log all info events to file -->
<root>
- <priority value="info"/>
+ <level value="info"/>
<appender-ref ref="FileAppender"/>
<!--appender-ref ref="ArchivingFileAppender"/-->
</root>
diff --git a/java/broker/src/main/java/broker.bnd b/java/broker/src/main/java/broker.bnd
index 4e799a1609..bf338543f7 100755
--- a/java/broker/src/main/java/broker.bnd
+++ b/java/broker/src/main/java/broker.bnd
@@ -17,7 +17,7 @@
# under the License.
#
-ver: 0.19.0
+ver: 0.21.0
Bundle-SymbolicName: qpid-broker
Bundle-Version: ${ver}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/CompletionCode.java b/java/broker/src/main/java/org/apache/qpid/qmf/CompletionCode.java
deleted file mode 100644
index 706ab3974a..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/CompletionCode.java
+++ /dev/null
@@ -1,36 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-public enum CompletionCode
-{
- OK,
- UNKNOWN_OBJECT,
- UNKNOWN_METHOD,
- NOT_IMPLEMENTED,
- INVALID_PARAMETER,
- FEATURE_NOT_IMPLEMENTED,
- FORBIDDEN,
- EXCEPTION,
- UNKNOWN_PACKAGE,
- UNKNOWN_CLASS;
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/ManagementExchange.java b/java/broker/src/main/java/org/apache/qpid/qmf/ManagementExchange.java
deleted file mode 100644
index 27ab580642..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/ManagementExchange.java
+++ /dev/null
@@ -1,586 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.ExchangeConfigType;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.exchange.ExchangeReferrer;
-import org.apache.qpid.server.exchange.ExchangeType;
-import org.apache.qpid.server.exchange.topic.TopicExchangeResult;
-import org.apache.qpid.server.exchange.topic.TopicMatcherResult;
-import org.apache.qpid.server.exchange.topic.TopicNormalizer;
-import org.apache.qpid.server.exchange.topic.TopicParser;
-import org.apache.qpid.server.message.InboundMessage;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.virtualhost.HouseKeepingTask;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.atomic.AtomicLong;
-
-public class ManagementExchange implements Exchange, QMFService.Listener
-{
- private static final AMQShortString QPID_MANAGEMENT = new AMQShortString("qpid.management");
- private static final AMQShortString QPID_MANAGEMENT_TYPE = new AMQShortString("management");
-
- private VirtualHost _virtualHost;
-
- private final TopicParser _parser = new TopicParser();
-
- private final Map<AMQShortString, TopicExchangeResult> _topicExchangeResults =
- new ConcurrentHashMap<AMQShortString, TopicExchangeResult>();
-
- private final Set<Binding> _bindingSet = new CopyOnWriteArraySet<Binding>();
- private UUID _id;
- private UUID _qmfId;
- private static final String AGENT_BANK = "0";
-
- private int _bindingCountHigh;
- private final AtomicLong _msgReceived = new AtomicLong();
- private final AtomicLong _bytesReceived = new AtomicLong();
-
- private final CopyOnWriteArrayList<BindingListener> _listeners = new CopyOnWriteArrayList<Exchange.BindingListener>();
-
- //TODO : persist creation time
- private long _createTime = System.currentTimeMillis();
-
-
- private class ManagementQueue implements BaseQueue
- {
- private final UUID QUEUE_ID = UUIDGenerator.generateRandomUUID();
- private final String NAME_AS_STRING = "##__mgmt_pseudo_queue__##" + QUEUE_ID.toString();
- private final AMQShortString NAME_AS_SHORT_STRING = new AMQShortString(NAME_AS_STRING);
-
- public void enqueue(ServerMessage message) throws AMQException
- {
- long size = message.getSize();
-
- ByteBuffer buf = ByteBuffer.allocate((int) size);
-
- int offset = 0;
-
- while(offset < size)
- {
- offset += message.getContent(buf,offset);
- }
-
- buf.flip();
- QMFCommandDecoder commandDecoder = new QMFCommandDecoder(getQMFService(),buf);
- QMFCommand cmd;
- while((cmd = commandDecoder.decode()) != null)
- {
- cmd.process(_virtualHost, message);
- }
-
- }
-
- public void enqueue(ServerMessage message, boolean sync, PostEnqueueAction action) throws AMQException
- {
- enqueue(message);
- }
-
- public void enqueue(ServerMessage message, PostEnqueueAction action) throws AMQException
- {
- enqueue(message);
- }
-
- public boolean isDurable()
- {
- return false;
- }
-
- public AMQShortString getNameShortString()
- {
- return NAME_AS_SHORT_STRING;
- }
-
- @Override
- public UUID getId()
- {
- return QUEUE_ID;
- }
- }
-
-
- private final ManagementQueue _mgmtQueue = new ManagementQueue();
-
- public ManagementExchange()
- {
- }
-
- public static final ExchangeType<ManagementExchange> TYPE = new ExchangeType<ManagementExchange>()
- {
-
- public AMQShortString getName()
- {
- return QPID_MANAGEMENT_TYPE;
- }
-
- public Class<ManagementExchange> getExchangeClass()
- {
- return ManagementExchange.class;
- }
-
- public ManagementExchange newInstance(UUID id, VirtualHost host,
- AMQShortString name,
- boolean durable,
- int ticket,
- boolean autoDelete) throws AMQException
- {
- ManagementExchange exch = new ManagementExchange();
- exch.initialise(id, host, name, durable, ticket, autoDelete);
- return exch;
- }
-
- public AMQShortString getDefaultExchangeName()
- {
- return QPID_MANAGEMENT;
- }
- };
-
-
- public AMQShortString getNameShortString()
- {
- return QPID_MANAGEMENT;
- }
-
- public AMQShortString getTypeShortString()
- {
- return QPID_MANAGEMENT_TYPE;
- }
-
- public void initialise(UUID id, VirtualHost host, AMQShortString name, boolean durable, int ticket, boolean autoDelete)
- throws AMQException
- {
- if(!QPID_MANAGEMENT.equals(name))
- {
- throw new AMQException("Can't create more than one Management exchange");
- }
- _virtualHost = host;
- _id = id;
- _virtualHost.scheduleHouseKeepingTask(_virtualHost.getBroker().getManagementPublishInterval(), new UpdateTask(_virtualHost));
- _qmfId = getConfigStore().createId();
- getConfigStore().addConfiguredObject(this);
- getQMFService().addListener(this);
- }
-
- public UUID getId()
- {
- return _id;
- }
-
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public ExchangeConfigType getConfigType()
- {
- return ExchangeConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return _virtualHost;
- }
-
- public boolean isDurable()
- {
- return true;
- }
-
- public VirtualHost getVirtualHost()
- {
- return _virtualHost;
- }
-
- public String getName()
- {
- return QPID_MANAGEMENT.toString();
- }
-
- public ExchangeType getType()
- {
- return TYPE;
- }
-
- public boolean isAutoDelete()
- {
- return false;
- }
-
- public int getTicket()
- {
- return 0;
- }
-
- public void close() throws AMQException
- {
- getConfigStore().removeConfiguredObject(this);
- }
-
- public ConfigStore getConfigStore()
- {
- return getVirtualHost().getConfigStore();
- }
-
- public synchronized void addBinding(final Binding b)
- {
-
- if(_bindingSet.add(b))
- {
- AMQShortString routingKey = TopicNormalizer.normalize(new AMQShortString(b.getBindingKey()));
-
- TopicExchangeResult result = _topicExchangeResults.get(routingKey);
- if(result == null)
- {
- result = new TopicExchangeResult();
- result.addUnfilteredQueue(b.getQueue());
- _parser.addBinding(routingKey, result);
- _topicExchangeResults.put(routingKey,result);
- }
- else
- {
- result.addUnfilteredQueue(b.getQueue());
- }
-
- result.addBinding(b);
- }
-
- for(BindingListener listener : _listeners)
- {
- listener.bindingAdded(this, b);
- }
-
- if(_bindingSet.size() > _bindingCountHigh)
- {
- _bindingCountHigh = _bindingSet.size();
- }
-
- String bindingKey = b.getBindingKey();
-
- if(bindingKey.startsWith("schema.") || bindingKey.startsWith("*.") || bindingKey.startsWith("#."))
- {
- publishAllSchema();
- }
- if(bindingKey.startsWith("console.") || bindingKey.startsWith("*.") || bindingKey.startsWith("#."))
- {
- publishAllConsole();
- }
-
- }
-
- void publishAllConsole()
- {
- QMFService qmfService = getQMFService();
-
- long sampleTime = System.currentTimeMillis();
-
- for(QMFPackage pkg : qmfService.getSupportedSchemas())
- {
- for(QMFClass qmfClass : pkg.getClasses())
- {
- Collection<QMFObject> qmfObjects = qmfService.getObjects(qmfClass);
-
- publishObjectsToConsole(sampleTime, qmfObjects);
- }
-
- }
-
- }
-
- private QMFService getQMFService()
- {
- return _virtualHost.getApplicationRegistry().getQMFService();
- }
-
- void publishObjectsToConsole(final long sampleTime,
- final Collection<QMFObject> qmfObjects)
- {
- if(!qmfObjects.isEmpty() && hasBindings())
- {
- QMFClass qmfClass = qmfObjects.iterator().next().getQMFClass();
- ArrayList<QMFCommand> commands = new ArrayList<QMFCommand>();
-
-
- for(QMFObject obj : qmfObjects)
- {
- commands.add(obj.asConfigInfoCmd(sampleTime));
- commands.add(obj.asInstrumentInfoCmd(sampleTime));
- }
-
- publishToConsole(qmfClass, commands);
- }
- }
-
- private void publishToConsole(final QMFClass qmfClass, final ArrayList<QMFCommand> commands)
- {
- if(!commands.isEmpty() && hasBindings())
- {
- String routingKey = "console.obj.1." + AGENT_BANK + "." + qmfClass.getPackage().getName() + "." + qmfClass.getName();
- QMFMessage message = new QMFMessage(routingKey,commands.toArray(new QMFCommand[commands.size()]));
-
- Collection<TopicMatcherResult> results = _parser.parse(new AMQShortString(routingKey));
- HashSet<AMQQueue> queues = new HashSet<AMQQueue>();
- for(TopicMatcherResult result : results)
- {
- TopicExchangeResult res = (TopicExchangeResult)result;
-
- for(Binding b : res.getBindings())
- {
- b.incrementMatches();
- }
-
- queues.addAll(((TopicExchangeResult)result).getUnfilteredQueues());
- }
- for(AMQQueue queue : queues)
- {
- try
- {
- queue.enqueue(message);
- }
- catch (AMQException e)
- {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- void publishAllSchema()
- {
-
- }
-
- public synchronized void removeBinding(final Binding binding)
- {
- if(_bindingSet.remove(binding))
- {
- AMQShortString bindingKey = TopicNormalizer.normalize(new AMQShortString(binding.getBindingKey()));
- TopicExchangeResult result = _topicExchangeResults.get(bindingKey);
- result.removeBinding(binding);
- result.removeUnfilteredQueue(binding.getQueue());
- }
-
- for(BindingListener listener : _listeners)
- {
- listener.bindingRemoved(this, binding);
- }
- }
-
- public synchronized Collection<Binding> getBindings()
- {
- return new ArrayList<Binding>(_bindingSet);
- }
-
- public ArrayList<BaseQueue> route(InboundMessage message)
- {
- ArrayList<BaseQueue> queues = new ArrayList<BaseQueue>(1);
- _msgReceived.incrementAndGet();
- _bytesReceived.addAndGet(message.getSize());
- queues.add(_mgmtQueue);
- return queues;
- }
-
- public boolean isBound(String bindingKey, Map<String, Object> arguments, AMQQueue queue)
- {
- return false; //TODO
- }
-
- public boolean isBound(AMQShortString routingKey, FieldTable arguments, AMQQueue queue)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isBound(AMQShortString routingKey, AMQQueue queue)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isBound(AMQShortString routingKey)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isBound(AMQQueue queue)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean hasBindings()
- {
- return !_bindingSet.isEmpty();
- }
-
- public boolean isBound(String bindingKey, AMQQueue queue)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isBound(String bindingKey)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void addCloseTask(final Task task)
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void removeCloseTask(final Task task)
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
-
-
- public Exchange getAlternateExchange()
- {
- return null;
- }
-
- public Map<String, Object> getArguments()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setAlternateExchange(Exchange exchange)
- {
-
- }
-
- public void removeReference(ExchangeReferrer exchange)
- {
- }
-
- public void addReference(ExchangeReferrer exchange)
- {
- }
-
- public boolean hasReferrers()
- {
- return true;
- }
-
-
-
- private class UpdateTask extends HouseKeepingTask
- {
- public UpdateTask(VirtualHost vhost)
- {
- super(vhost);
- }
-
- public void execute()
- {
- publishAllConsole();
- publishAllSchema();
- }
-
- }
-
- public void objectCreated(final QMFObject obj)
- {
- publishObjectsToConsole(System.currentTimeMillis(), Collections.singleton(obj));
- }
-
- public void objectDeleted(final QMFObject obj)
- {
- publishObjectsToConsole(System.currentTimeMillis(), Collections.singleton(obj));
- }
-
- public long getBindingCount()
- {
- return getBindings().size();
- }
-
- public long getBindingCountHigh()
- {
- return _bindingCountHigh;
- }
-
- public long getMsgReceives()
- {
- return _msgReceived.get();
- }
-
- public long getMsgRoutes()
- {
- return getMsgReceives();
- }
-
- public long getMsgDrops()
- {
- return 0l;
- }
-
- public long getByteReceives()
- {
- return _bytesReceived.get();
- }
-
- public long getByteRoutes()
- {
- return getByteReceives();
- }
-
- public long getByteDrops()
- {
- return 0l;
- }
-
- public long getCreateTime()
- {
- return _createTime;
- }
-
- public void addBindingListener(final BindingListener listener)
- {
- _listeners.add(listener);
- }
-
- public void removeBindingListener(final BindingListener listener)
- {
- _listeners.remove(listener);
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFBrokerRequestCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFBrokerRequestCommand.java
deleted file mode 100644
index 69284abc48..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFBrokerRequestCommand.java
+++ /dev/null
@@ -1,82 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.codec.BBDecoder;
-
-import java.util.List;
-
-public class QMFBrokerRequestCommand extends QMFCommand
-{
-
- private static final Logger _qmfLogger = Logger.getLogger("qpid.qmf");
-
-
- public QMFBrokerRequestCommand(QMFCommandHeader header, BBDecoder buf)
- {
- super(header);
- }
-
- public void process(VirtualHost virtualHost, ServerMessage message)
- {
- String exchangeName = message.getMessageHeader().getReplyToExchange();
- String queueName = message.getMessageHeader().getReplyToRoutingKey();
-
- _qmfLogger.debug("Execute: " + this);
-
- QMFCommand[] commands = new QMFCommand[2];
- commands[0] = new QMFBrokerResponseCommand(this, virtualHost);
- commands[1] = new QMFCommandCompletionCommand(this);
-
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(exchangeName);
-
- for(QMFCommand cmd : commands)
- {
- QMFMessage responseMessage = new QMFMessage(queueName, cmd);
-
-
- List<? extends BaseQueue> queues = exchange.route(responseMessage);
-
-
- for(BaseQueue q : queues)
- {
- try
- {
- q.enqueue(responseMessage);
- }
- catch (AMQException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- }
- }
-
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFBrokerResponseCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFBrokerResponseCommand.java
deleted file mode 100644
index 34b2a851dc..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFBrokerResponseCommand.java
+++ /dev/null
@@ -1,45 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.codec.BBEncoder;
-
-public class QMFBrokerResponseCommand extends QMFCommand
-{
- private QMFCommandHeader _header;
- private VirtualHost _virtualHost;
-
- public QMFBrokerResponseCommand(QMFBrokerRequestCommand qmfBrokerRequestCommand, VirtualHost virtualHost)
- {
- super( new QMFCommandHeader(qmfBrokerRequestCommand.getHeader().getVersion(),
- qmfBrokerRequestCommand.getHeader().getSeq(),
- QMFOperation.BROKER_RESPONSE));
- _virtualHost = virtualHost;
- }
-
- public void encode(BBEncoder encoder)
- {
- super.encode(encoder);
- encoder.writeUuid(_virtualHost.getBrokerId());
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFClass.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFClass.java
deleted file mode 100644
index 7d566567a1..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFClass.java
+++ /dev/null
@@ -1,156 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-abstract public class QMFClass
-{
-
-
- public enum Type
- {
- OBJECT((byte)1),
- EVENT((byte)2);
-
- private final byte _value;
-
- Type(byte value)
- {
- _value = value;
- }
-
- public byte getValue()
- {
- return _value;
- }
- }
-
- private final Type _type;
- private QMFPackage _package;
- private final String _name;
- private byte[] _schemaHash;
-
- private Map<String, QMFProperty> _properties = new LinkedHashMap<String, QMFProperty>();
- private Map<String, QMFStatistic> _statistics = new LinkedHashMap<String, QMFStatistic>();
- private Map<String, QMFMethod> _methods = new LinkedHashMap<String, QMFMethod>();
-
-
-
- public QMFClass(Type type, String name, byte[] schemaHash, List<QMFProperty> properties,
- List<QMFStatistic> statistics, List<QMFMethod> methods)
- {
- this(type, name, schemaHash);
- setProperties(properties);
- setStatistics(statistics);
- setMethods(methods);
- }
-
-
- public QMFClass(Type type, String name, byte[] schemaHash)
-
- {
- _type = type;
- _name = name;
- _schemaHash = schemaHash;
-
- }
-
- protected void setProperties(List<QMFProperty> properties)
- {
- for(QMFProperty prop : properties)
- {
- _properties.put(prop.getName(), prop);
- }
- }
-
- protected void setStatistics(List<QMFStatistic> statistics)
- {
- for(QMFStatistic stat : statistics)
- {
- _statistics.put(stat.getName(), stat);
- }
- }
-
-
- protected void setMethods(List<QMFMethod> methods)
- {
- for(QMFMethod method : methods)
- {
- _methods.put(method.getName(), method);
- }
- }
-
- public void setPackage(QMFPackage aPackage)
- {
- _package = aPackage;
- for(QMFProperty prop : _properties.values())
- {
- prop.setQMFClass(this);
- }
- // TODO Statisics, Methods
- }
-
- public Type getType()
- {
- return _type;
- }
-
- public QMFPackage getPackage()
- {
- return _package;
- }
-
- public String getName()
- {
- return _name;
- }
-
- public byte[] getSchemaHash()
- {
- return _schemaHash;
- }
-
- public Collection<QMFProperty> getProperties()
- {
- return _properties.values();
- }
-
- public Collection<QMFStatistic> getStatistics()
- {
- return _statistics.values();
- }
-
- public Collection<QMFMethod> getMethods()
- {
- return _methods.values();
- }
-
- public QMFMethod getMethod(String methodName)
- {
- return _methods.get(methodName);
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFClassIndicationCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFClassIndicationCommand.java
deleted file mode 100644
index 613e1e5978..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFClassIndicationCommand.java
+++ /dev/null
@@ -1,48 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBEncoder;
-
-public class QMFClassIndicationCommand extends QMFCommand
-{
- private QMFClass _qmfClass;
-
- public QMFClassIndicationCommand(QMFClassQueryCommand qmfClassQueryCommand, QMFClass qmfClass)
- {
- super(new QMFCommandHeader(qmfClassQueryCommand.getHeader().getVersion(),
- qmfClassQueryCommand.getHeader().getSeq(),
- QMFOperation.CLASS_INDICATION));
- _qmfClass = qmfClass;
- }
-
-
- @Override
- public void encode(BBEncoder encoder)
- {
- super.encode(encoder);
- encoder.writeUint8(_qmfClass.getType().getValue());
- encoder.writeStr8(_qmfClass.getPackage().getName());
- encoder.writeStr8(_qmfClass.getName());
- encoder.writeBin128(_qmfClass.getSchemaHash());
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFClassQueryCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFClassQueryCommand.java
deleted file mode 100644
index 5676bb7306..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFClassQueryCommand.java
+++ /dev/null
@@ -1,105 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.codec.BBDecoder;
-
-import java.util.Collection;
-import java.util.List;
-
-public class QMFClassQueryCommand extends QMFCommand
-{
- private static final Logger _qmfLogger = Logger.getLogger("qpid.qmf");
-
-
- private final String _package;
-
- public QMFClassQueryCommand(QMFCommandHeader header, BBDecoder decoder)
- {
- super(header);
- _package = decoder.readStr8();
- }
-
- public void process(VirtualHost virtualHost, ServerMessage message)
- {
- String exchangeName = message.getMessageHeader().getReplyToExchange();
- String routingKey = message.getMessageHeader().getReplyToRoutingKey();
-
- _qmfLogger.debug("Execute: " + this);
-
- IApplicationRegistry appRegistry = virtualHost.getApplicationRegistry();
- QMFService service = appRegistry.getQMFService();
-
- QMFPackage qmfPackage = service.getPackage(_package);
- Collection<QMFClass> qmfClasses = qmfPackage.getClasses();
-
- QMFCommand[] commands = new QMFCommand[ qmfClasses.size() + 1 ];
-
- int i = 0;
- for(QMFClass qmfClass : qmfClasses)
- {
- commands[i++] = new QMFClassIndicationCommand(this, qmfClass);
- }
- commands[ commands.length - 1 ] = new QMFCommandCompletionCommand(this);
-
-
- for(QMFCommand cmd : commands)
- {
-
-
- QMFMessage responseMessage = new QMFMessage(routingKey, cmd);
-
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(exchangeName);
-
- List<? extends BaseQueue> queues = exchange.route(responseMessage);
-
- for(BaseQueue q : queues)
- {
- try
- {
- q.enqueue(responseMessage);
- }
- catch (AMQException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- }
- }
-
-
- @Override
- public String toString()
- {
- return "QMFClassQueryCommand{" +
- "package='" + _package + '\'' +
- '}';
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommand.java
deleted file mode 100644
index 4f143701af..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommand.java
+++ /dev/null
@@ -1,54 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.codec.BBEncoder;
-
-public abstract class QMFCommand
-{
-
- private final QMFCommandHeader _header;
-
- protected QMFCommand(QMFCommandHeader header)
- {
- _header = header;
- }
-
-
- public void process(final VirtualHost virtualHost, final ServerMessage message)
- {
- throw new UnsupportedOperationException();
- }
-
- public void encode(BBEncoder encoder)
- {
- _header.encode(encoder);
-
- }
-
- public QMFCommandHeader getHeader()
- {
- return _header;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandCompletionCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandCompletionCommand.java
deleted file mode 100644
index 397ad4090e..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandCompletionCommand.java
+++ /dev/null
@@ -1,63 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBEncoder;
-
-public class QMFCommandCompletionCommand extends QMFCommand
-{
-
- private final CompletionCode _status;
- private final String _text;
-
- public QMFCommandCompletionCommand(QMFCommand command)
- {
- this(command, CompletionCode.OK, "");
- }
- public QMFCommandCompletionCommand(QMFCommand command, CompletionCode status, String text)
- {
- super( new QMFCommandHeader(command.getHeader().getVersion(),
- command.getHeader().getSeq(),
- QMFOperation.COMMAND_COMPLETION));
-
- _status = status;
- _text = text;
- }
-
-
- @Override
- public void encode(BBEncoder encoder)
- {
- super.encode(encoder);
- encoder.writeInt32(_status.ordinal());
- encoder.writeStr8(_text);
- }
-
- @Override
- public String toString()
- {
- return "QMFCommandCompletionCommand{" +
- "status=" + _status +
- ",text='" + _text + '\'' +
- '}';
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandDecoder.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandDecoder.java
deleted file mode 100644
index ac036dfa19..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandDecoder.java
+++ /dev/null
@@ -1,98 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBDecoder;
-
-import java.nio.ByteBuffer;
-
-public class QMFCommandDecoder
-{
- private BBDecoder _decoder;
-
-
- private static final QMFOperation[] OP_CODES = new QMFOperation[256];
- private final QMFService _qmfService;
-
- static
- {
- for(QMFOperation op : QMFOperation.values())
- {
- OP_CODES[op.getOpcode()] = op;
- }
- }
-
- public QMFCommandDecoder(final QMFService qmfService, ByteBuffer buf)
- {
- _qmfService = qmfService;
- _decoder = new BBDecoder();
- _decoder.init(buf);
- }
-
- public QMFCommand decode()
- {
- if(_decoder.hasRemaining())
- {
- QMFCommandHeader header = readQMFHeader();
-
- switch(header.getOperation())
- {
- case BROKER_REQUEST:
- return new QMFBrokerRequestCommand(header, _decoder);
- case PACKAGE_QUERY:
- return new QMFPackageQueryCommand(header, _decoder);
- case CLASS_QUERY:
- return new QMFClassQueryCommand(header, _decoder);
- case SCHEMA_REQUEST:
- return new QMFSchemaRequestCommand(header, _decoder);
- case METHOD_REQUEST:
- return new QMFMethodRequestCommand(header, _decoder, _qmfService);
- case GET_QUERY:
- return new QMFGetQueryCommand(header, _decoder);
- default:
- System.out.println("Unknown command");
-
- }
-
- return null;
- }
- else
- {
- return null;
- }
- }
-
- private QMFCommandHeader readQMFHeader()
- {
- if(_decoder.readInt8() == (byte) 'A'
- && _decoder.readInt8() == (byte) 'M')
- {
- byte version = _decoder.readInt8();
- short opCode = _decoder.readUint8();
- int seq = _decoder.readInt32();
-
- return new QMFCommandHeader(version, seq, OP_CODES[opCode]);
-
- }
- return null;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandHeader.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandHeader.java
deleted file mode 100644
index c4d771317f..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFCommandHeader.java
+++ /dev/null
@@ -1,63 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBEncoder;
-
-public class QMFCommandHeader
-{
- private final byte _version;
- private final int _seq;
-
- private final QMFOperation _operation;
-
- public QMFCommandHeader(byte version, int seq, QMFOperation operation)
- {
- _version = version;
- _seq = seq;
- _operation = operation;
- }
-
- public byte getVersion()
- {
- return _version;
- }
-
- public int getSeq()
- {
- return _seq;
- }
-
- public QMFOperation getOperation()
- {
- return _operation;
- }
-
- public void encode(BBEncoder encoder)
- {
- encoder.writeUint8((short)'A');
- encoder.writeUint8((short)'M');
- encoder.writeInt8(_version);
- encoder.writeUint8((short)_operation.getOpcode());
- encoder.writeInt32(_seq);
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventClass.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventClass.java
deleted file mode 100644
index ec471f18e8..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventClass.java
+++ /dev/null
@@ -1,42 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-import java.util.List;
-
-public abstract class QMFEventClass extends QMFClass
-{
- public QMFEventClass(String name,
- byte[] schemaHash,
- List<QMFProperty> properties,
- List<QMFStatistic> statistics, List<QMFMethod> methods)
- {
- super(Type.EVENT, name, schemaHash, properties, statistics, methods);
- }
-
- public QMFEventClass(String name, byte[] schemaHash)
- {
- super(Type.EVENT, name, schemaHash);
- }
-
- abstract public QMFEventSeverity getSeverity();
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventCommand.java
deleted file mode 100644
index 833ccfbca4..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventCommand.java
+++ /dev/null
@@ -1,47 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBEncoder;
-
-public abstract class QMFEventCommand<T extends QMFEventClass> extends QMFCommand
-{
- private final long _timestamp;
-
- protected QMFEventCommand()
- {
- super(new QMFCommandHeader((byte)'2',0, QMFOperation.EVENT));
- _timestamp = System.currentTimeMillis();
- }
-
- abstract public T getEventClass();
-
- @Override
- public void encode(final BBEncoder encoder)
- {
- super.encode(encoder);
- encoder.writeStr8(getEventClass().getPackage().getName());
- encoder.writeStr8(getEventClass().getName());
- encoder.writeBin128(new byte[16]);
- encoder.writeUint64(_timestamp * 1000000L);
- encoder.writeUint8((short) getEventClass().getSeverity().ordinal());
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventSeverity.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventSeverity.java
deleted file mode 100644
index 9f9c832732..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFEventSeverity.java
+++ /dev/null
@@ -1,33 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-public enum QMFEventSeverity
-{
- EMERGENCY,
- ALERT,
- CRITICAL,
- ERROR,
- WARN,
- NOTICE,
- INFORM,
- DEBUG
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFGetQueryCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFGetQueryCommand.java
deleted file mode 100644
index b1f958d4ba..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFGetQueryCommand.java
+++ /dev/null
@@ -1,205 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.codec.BBDecoder;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-public class QMFGetQueryCommand extends QMFCommand
-{
-
- private static final Logger _qmfLogger = Logger.getLogger("qpid.qmf");
-
- private String _className;
- private String _packageName;
- private UUID _objectId;
-
- public QMFGetQueryCommand(QMFCommandHeader header, BBDecoder decoder)
- {
- super(header);
-
- Map<String, Object> _map = decoder.readMap();
- _className = (String) _map.get("_class");
- _packageName = (String) _map.get("_package");
- byte[] objectIdBytes = (byte[]) _map.get("_objectId");
-
- if(objectIdBytes != null)
- {
- long msb = 0;
- long lsb = 0;
-
- for (int i = 0; i != 8; i++)
- {
- msb = (msb << 8) | (objectIdBytes[i] & 0xff);
- }
- for (int i = 8; i != 16; i++)
- {
- lsb = (lsb << 8) | (objectIdBytes[i] & 0xff);
- }
- _objectId = new UUID(msb, lsb);
- }
- else
- {
- _objectId = null;
- }
-
-
- }
-
- public void process(VirtualHost virtualHost, ServerMessage message)
- {
- String exchangeName = message.getMessageHeader().getReplyToExchange();
- String routingKey = message.getMessageHeader().getReplyToRoutingKey();
-
- IApplicationRegistry appRegistry = virtualHost.getApplicationRegistry();
- QMFService service = appRegistry.getQMFService();
-
- _qmfLogger.debug("Execute: " + this);
-
- List<QMFCommand> commands = new ArrayList<QMFCommand>();
- final long sampleTime = System.currentTimeMillis() * 1000000l;
-
- Collection<QMFPackage> packages;
-
- if(_packageName != null && _packageName.length() != 0)
- {
- QMFPackage qmfPackage = service.getPackage(_packageName);
- if(qmfPackage == null)
- {
- packages = Collections.EMPTY_LIST;
- }
- else
- {
- packages = Collections.singleton(qmfPackage);
- }
- }
- else
- {
- packages = service.getSupportedSchemas();
- }
-
- for(QMFPackage qmfPackage : packages)
- {
-
- Collection<QMFClass> qmfClasses;
-
- if(_className != null && _className.length() != 0)
- {
- QMFClass qmfClass = qmfPackage.getQMFClass(_className);
- if(qmfClass == null)
- {
- qmfClasses = Collections.EMPTY_LIST;
- }
- else
- {
- qmfClasses = Collections.singleton(qmfClass);
- }
- }
- else
- {
- qmfClasses = qmfPackage.getClasses();
- }
-
-
- for(QMFClass qmfClass : qmfClasses)
- {
- Collection<QMFObject> objects;
-
- if(_objectId != null)
- {
- QMFObject obj = service.getObjectById(qmfClass, _objectId);
- if(obj == null)
- {
- objects = Collections.EMPTY_LIST;
- }
- else
- {
- objects = Collections.singleton(obj);
- }
- }
- else
- {
- objects = service.getObjects(qmfClass);
- }
-
- for(QMFObject object : objects)
- {
-
- commands.add(object.asGetQueryResponseCmd(this, sampleTime));
- }
- }
-
-
- }
-
-
- commands.add( new QMFCommandCompletionCommand(this));
-
-
- for(QMFCommand cmd : commands)
- {
-
- _qmfLogger.debug("Respond: " + cmd);
- QMFMessage responseMessage = new QMFMessage(routingKey, cmd);
-
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(exchangeName);
-
- List<? extends BaseQueue> queues = exchange.route(responseMessage);
-
- for(BaseQueue q : queues)
- {
- try
- {
- q.enqueue(responseMessage);
- }
- catch (AMQException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- }
- }
-
- @Override
- public String toString()
- {
- return "QMFGetQueryCommand{" +
- "packageName='" + _packageName + '\'' +
- ", className='" + _className + '\'' +
- ", objectId=" + _objectId +
- '}';
- }
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMessage.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFMessage.java
deleted file mode 100644
index 1b173c7e11..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMessage.java
+++ /dev/null
@@ -1,256 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import java.util.Collection;
-import java.util.Collections;
-import org.apache.commons.lang.NotImplementedException;
-
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.SessionConfig;
-import org.apache.qpid.server.message.AMQMessageHeader;
-import org.apache.qpid.server.message.InboundMessage;
-import org.apache.qpid.server.message.MessageReference;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.store.StoredMessage;
-import org.apache.qpid.transport.codec.BBEncoder;
-
-import java.nio.ByteBuffer;
-import java.util.Set;
-
-public class QMFMessage implements ServerMessage, InboundMessage, AMQMessageHeader
-{
-
- private ByteBuffer _content;
- private String _routingKey;
-
- public QMFMessage(String routingKey, QMFCommand command)
- {
- this(routingKey, new QMFCommand[] { command });
- }
-
-
- public QMFMessage(String routingKey, QMFCommand[] commands)
- {
- _routingKey = routingKey;
- BBEncoder encoder = new BBEncoder(256);
-
- for(QMFCommand cmd : commands)
- {
- cmd.encode(encoder);
- }
-
-
- _content = encoder.buffer();
- }
-
- public String getRoutingKey()
- {
- return _routingKey;
- }
-
- public AMQShortString getRoutingKeyShortString()
- {
- return AMQShortString.valueOf(_routingKey);
- }
-
- public AMQMessageHeader getMessageHeader()
- {
- return this;
- }
-
- public StoredMessage getStoredMessage()
- {
- throw new NotImplementedException();
- }
-
- public boolean isPersistent()
- {
- return false;
- }
-
- public boolean isRedelivered()
- {
- return false;
- }
-
- public long getSize()
- {
- return _content.limit();
- }
-
- public boolean isImmediate()
- {
- return false;
- }
-
- public String getCorrelationId()
- {
- return null;
- }
-
- public long getExpiration()
- {
- return 0;
- }
-
- public String getUserId()
- {
- return null;
- }
-
- public String getAppId()
- {
- return null;
- }
-
- public String getMessageId()
- {
- return null;
- }
-
- public String getMimeType()
- {
- return null;
- }
-
- public String getEncoding()
- {
- return null;
- }
-
- public byte getPriority()
- {
- return 4;
- }
-
- public long getTimestamp()
- {
- return 0;
- }
-
- public String getType()
- {
- return null;
- }
-
- public String getReplyTo()
- {
- return null;
- }
-
- public String getReplyToExchange()
- {
- return null;
- }
-
- public String getReplyToRoutingKey()
- {
- return null;
- }
-
- public Object getHeader(String name)
- {
- return null;
- }
-
- public boolean containsHeaders(Set<String> names)
- {
- return false;
- }
-
- @Override
- public Collection<String> getHeaderNames()
- {
- return Collections.EMPTY_SET;
- }
-
- public boolean containsHeader(String name)
- {
- return false;
- }
-
- public MessageReference newReference()
- {
- return new QMFMessageReference(this);
- }
-
- public long getMessageNumber()
- {
- return 0l;
- }
-
- public long getArrivalTime()
- {
- return 0;
- }
-
- public int getContent(ByteBuffer buf, int offset)
- {
- ByteBuffer src = _content.duplicate();
- src.position(offset);
- src = src.slice();
- int len = src.remaining();
- if(len > buf.remaining())
- {
- len = buf.remaining();
- }
-
- buf.put(src);
-
- return len;
- }
-
-
- public ByteBuffer getContent(int offset, int size)
- {
- ByteBuffer src = _content.duplicate();
- src.position(offset);
- src = src.slice();
- src.limit(size);
- return src;
- }
-
- private static class QMFMessageReference extends MessageReference<QMFMessage>
- {
- public QMFMessageReference(QMFMessage message)
- {
- super(message);
- }
-
- protected void onReference(QMFMessage message)
- {
-
- }
-
- protected void onRelease(QMFMessage message)
- {
-
- }
- }
-
- public SessionConfig getSessionConfig()
- {
- return null;
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethod.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethod.java
deleted file mode 100644
index 1d1cd24724..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethod.java
+++ /dev/null
@@ -1,157 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBDecoder;
-import org.apache.qpid.transport.codec.Encoder;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-
-public abstract class QMFMethod<T extends QMFObject>
-{
- private final LinkedHashMap<String,Object> _map = new LinkedHashMap<String,Object>();
- private final List<Argument> _arguments = new ArrayList<Argument>();
-
- private static final String NAME = "name";
- private static final String TYPE = "type";
- private static final String REF_PACKAGE = "refPackage";
- private static final String REF_CLASS = "refClass";
- private static final String UNIT = "unit";
- private static final String MIN = "min";
- private static final String MAX = "max";
- private static final String MAX_LENGTH = "maxlen";
- private static final String DESCRIPTION = "desc";
- private static final String DEFAULT = "default";
- private static final String DIRECTION = "dir";
- private static final String ARG_COUNT = "argCount";
-
-
-
- public enum Direction
- {
- I,
- O,
- IO;
- }
-
- public class Argument
- {
- private final LinkedHashMap<String,Object> _map = new LinkedHashMap<String,Object>();
-
- public Argument(String name, QMFType type)
- {
- _map.put(NAME, name);
- _map.put(TYPE, type.codeValue());
- }
-
- public void setRefPackage(String refPackage)
- {
- _map.put(REF_PACKAGE, refPackage);
- }
-
- public void setRefClass(String refClass)
- {
- _map.put(REF_CLASS, refClass);
- }
-
- public void setUnit(String unit)
- {
- _map.put(UNIT, unit);
- }
-
- public void setMax(Number max)
- {
- _map.put(MAX, max);
- }
-
- public void setMin(Number min)
- {
- _map.put(MIN, min);
- }
-
- public void setMaxLength(int len)
- {
- _map.put(MAX_LENGTH, len);
- }
-
- public void setDefault(Object dflt)
- {
- _map.put(DEFAULT, dflt);
- }
-
- public void setDescription(String desc)
- {
- _map.put(DESCRIPTION, desc);
- }
-
- public void setDirection(Direction direction)
- {
- _map.put(DIRECTION, direction.toString());
- }
-
- public void encode(Encoder encoder)
- {
- encoder.writeMap(_map);
- }
-
- public String getName()
- {
- return (String) _map.get(NAME);
- }
- }
-
- public QMFMethod(String name, String description)
- {
- _map.put(NAME, name);
- _map.put(ARG_COUNT, 0);
- if(description != null)
- {
- _map.put(DESCRIPTION, description);
- }
-
- }
-
- abstract public QMFMethodInvocation<T> parse(final BBDecoder decoder);
-
- protected void addArgument(Argument arg)
- {
- _arguments.add(arg);
- _map.put(ARG_COUNT, _arguments.size());
- }
-
-
- public void encode(Encoder encoder)
- {
- encoder.writeMap(_map);
- for(Argument arg : _arguments)
- {
- arg.encode(encoder);
- }
- }
-
- public String getName()
- {
- return (String) _map.get(NAME);
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodInvocation.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodInvocation.java
deleted file mode 100644
index 5348c2783f..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodInvocation.java
+++ /dev/null
@@ -1,26 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-public interface QMFMethodInvocation<T extends QMFObject>
-{
- QMFMethodResponseCommand execute(T obj, QMFMethodRequestCommand cmd);
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodRequestCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodRequestCommand.java
deleted file mode 100644
index 1a4ce228b5..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodRequestCommand.java
+++ /dev/null
@@ -1,95 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.codec.BBDecoder;
-
-import java.util.List;
-import java.util.UUID;
-
-public class QMFMethodRequestCommand extends QMFCommand
-{
- private static final Logger _qmfLogger = Logger.getLogger("qpid.qmf");
-
- private QMFMethodInvocation _methodInstance;
- private QMFObject _object;
-
- public QMFMethodRequestCommand(final QMFCommandHeader header, final BBDecoder decoder, final QMFService qmfService)
- {
- super(header);
- UUID objectId = decoder.readUuid();
- String packageName = decoder.readStr8();
- String className = decoder.readStr8();
- byte[] hash = decoder.readBin128();
- String methodName = decoder.readStr8();
-
- QMFPackage qmfPackage = qmfService.getPackage(packageName);
- QMFClass qmfClass = qmfPackage.getQMFClass(className);
- _object = qmfService.getObjectById(qmfClass, objectId);
- QMFMethod method = qmfClass.getMethod(methodName);
- _methodInstance = method.parse(decoder);
-
- }
-
- public void process(final VirtualHost virtualHost, final ServerMessage message)
- {
- String exchangeName = message.getMessageHeader().getReplyToExchange();
- String queueName = message.getMessageHeader().getReplyToRoutingKey();
-
- QMFCommand[] commands = new QMFCommand[2];
-
- _qmfLogger.debug("Execute: " + _methodInstance + " on " + _object);
-
- commands[0] = _methodInstance.execute(_object, this);
- commands[1] = new QMFCommandCompletionCommand(this);
-
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(exchangeName);
-
- for(QMFCommand cmd : commands)
- {
- QMFMessage responseMessage = new QMFMessage(queueName, cmd);
-
-
- List<? extends BaseQueue> queues = exchange.route(responseMessage);
-
-
- for(BaseQueue q : queues)
- {
- try
- {
- q.enqueue(responseMessage);
- }
- catch (AMQException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- }
-
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodResponseCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodResponseCommand.java
deleted file mode 100644
index 5fea014ad8..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFMethodResponseCommand.java
+++ /dev/null
@@ -1,76 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBEncoder;
-
-public class QMFMethodResponseCommand extends QMFCommand
-{
- private CompletionCode _status = null;
- private String _msg = null;
-
- public QMFMethodResponseCommand(final QMFMethodRequestCommand cmd,
- CompletionCode status,
- String msg)
- {
- super( new QMFCommandHeader(cmd.getHeader().getVersion(),
- cmd.getHeader().getSeq(),
- QMFOperation.METHOD_RESPONSE));
-
- if(status == null)
- {
- _status = CompletionCode.OK;
- }
- else
- {
- _status = status;
- }
-
- _msg = msg;
- }
-
- public CompletionCode getStatus()
- {
- return _status;
- }
-
- public String getStatusText()
- {
- return _msg;
- }
-
- @Override
- public void encode(final BBEncoder encoder)
- {
- super.encode(encoder);
-
- encoder.writeUint32(_status.ordinal());
-
- if(_msg == null)
- {
- encoder.writeStr16(_status.toString());
- }
- else
- {
- encoder.writeStr16(_msg);
- }
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFObject.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFObject.java
deleted file mode 100644
index c3604dca44..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFObject.java
+++ /dev/null
@@ -1,81 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-import java.util.UUID;
-
-public abstract class QMFObject<C extends QMFClass, D extends QMFObject.Delegate>
-{
- private long _deleteTime;
-
- public interface Delegate
- {
- UUID getQMFId();
- long getCreateTime();
- }
-
-
- private D _delegate;
-
- protected QMFObject(D delegate)
- {
- _delegate = delegate;
- }
-
- public D getDelegate()
- {
- return _delegate;
- }
-
- abstract public C getQMFClass();
-
- public final UUID getId()
- {
- return _delegate.getQMFId();
- }
-
- public final long getCreateTime()
- {
- return _delegate.getCreateTime();
- }
-
- public final void setDeleteTime()
- {
- _deleteTime = System.currentTimeMillis();
- }
-
- public final long getDeleteTime()
- {
- return _deleteTime;
- }
-
-
-
- abstract public QMFCommand asConfigInfoCmd(long sampleTime);
- abstract public QMFCommand asInstrumentInfoCmd(long sampleTime);
- abstract public QMFCommand asGetQueryResponseCmd(final QMFGetQueryCommand queryCommand, long sampleTime);
-
- @Override
- public String toString()
- {
- return _delegate.toString();
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFObjectClass.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFObjectClass.java
deleted file mode 100644
index fefdecb8d7..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFObjectClass.java
+++ /dev/null
@@ -1,44 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-import java.util.List;
-
-public abstract class QMFObjectClass<T extends QMFObject, S extends QMFObject.Delegate> extends QMFClass
-{
- public QMFObjectClass(String name,
- byte[] schemaHash,
- List<QMFProperty> properties,
- List<QMFStatistic> statistics, List<QMFMethod> methods)
- {
- super(QMFClass.Type.OBJECT, name, schemaHash, properties, statistics, methods);
- }
-
- public QMFObjectClass(String name, byte[] schemaHash)
- {
- super(QMFClass.Type.OBJECT, name, schemaHash);
- }
-
-
- public abstract T newInstance(S delegate);
-
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFOperation.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFOperation.java
deleted file mode 100644
index 6736b5d460..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFOperation.java
+++ /dev/null
@@ -1,67 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-public enum QMFOperation
-{
-
-
- BROKER_REQUEST('B'),
- BROKER_RESPONSE('b'), // This message contains a broker response, sent from the broker in response to a broker request message.
- COMMAND_COMPLETION('z'), // This message is sent to indicate the completion of a request.
- CLASS_QUERY('Q'), // Class query messages are used by a management console to request a list of schema classes that are known by the management broker.
- CLASS_INDICATION('q'), // Sent by the management broker, a class indication notifies the peer of the existence of a schema class.
- SCHEMA_REQUEST('S'), // Schema request messages are used to request the full schema details for a class.
- SCHEMA_RESPONSE('s'), // Schema response message contain a full description of the schema for a class.
- HEARTBEAT_INDEICATION('h'), // This message is published once per publish-interval. It can be used by a client to positively determine which objects did not change during the interval (since updates are not published for objects with no changes).
- CONFIG_INDICATION('c'),
- INSTRUMENTATION_INDICATION('i'),
- GET_QUERY_RESPONSE('g'), // This message contains a content record. Content records contain the values of all properties or statistics in an object. Such records are broadcast on a periodic interval if 1) a change has been made in the value of one of the elements, or 2) if a new management client has bound a queue to the management exchange.
- GET_QUERY('G'), // Sent by a management console, a get query requests that the management broker provide content indications for all objects that match the query criteria.
- METHOD_REQUEST('M'), // This message contains a method request.
- METHOD_RESPONSE('m'), // This message contains a method result.
- PACKAGE_QUERY('P'), // This message contains a schema package query request, requesting that the broker dump the list of known packages
- PACKAGE_INDICATION('p'), // This message contains a schema package indication, identifying a package known by the broker
- AGENT_ATTACH_REUQEST('A'), // This message is sent by a remote agent when it wishes to attach to a management broker
- AGENT_ATTACH_RESPONSE('a'), // The management broker sends this response if an attaching remote agent is permitted to join
- CONSOLE_ADDED_INDICATION('x'), // This message is sent to all remote agents by the management broker when a new console binds to the management exchange
- EVENT('e')
- ;
-
-
- private final char _opcode;
-
- private static final QMFOperation[] OP_CODES = new QMFOperation[256];
-
-
- QMFOperation(char opcode)
- {
- _opcode = opcode;
- }
-
-
- public char getOpcode()
- {
- return _opcode;
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackage.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackage.java
deleted file mode 100644
index 63b43475aa..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackage.java
+++ /dev/null
@@ -1,67 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-public class QMFPackage
-{
- private final String _name;
- private final Map<String, QMFClass> _classes = new HashMap<String, QMFClass>();
-
- public QMFPackage(String name)
- {
- _name = name;
- }
-
- public QMFPackage(String name, Collection<QMFClass> classes)
- {
- this(name);
- setClasses(classes);
- }
-
- protected void setClasses(Collection<QMFClass> classes)
- {
- for(QMFClass qmfClass : classes)
- {
- qmfClass.setPackage(this);
- _classes.put(qmfClass.getName(), qmfClass);
- }
- }
-
- public String getName()
- {
- return _name;
- }
-
- public Collection<QMFClass> getClasses()
- {
- return _classes.values();
- }
-
- public QMFClass getQMFClass(String className)
- {
- return _classes.get(className);
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackageIndicationCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackageIndicationCommand.java
deleted file mode 100644
index 9c8fa1e2c6..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackageIndicationCommand.java
+++ /dev/null
@@ -1,44 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBEncoder;
-
-public class QMFPackageIndicationCommand extends QMFCommand
-{
- private String _supportedSchema;
-
- public QMFPackageIndicationCommand(QMFPackageQueryCommand qmfPackageQueryCommand, String supportedSchema)
- {
- super( new QMFCommandHeader(qmfPackageQueryCommand.getHeader().getVersion(),
- qmfPackageQueryCommand.getHeader().getSeq(),
- QMFOperation.PACKAGE_INDICATION));
- _supportedSchema = supportedSchema;
-
- }
-
- public void encode(BBEncoder encoder)
- {
- super.encode(encoder);
- encoder.writeStr8(_supportedSchema);
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackageQueryCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackageQueryCommand.java
deleted file mode 100644
index c74c7da252..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFPackageQueryCommand.java
+++ /dev/null
@@ -1,98 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.codec.BBDecoder;
-
-import java.util.Collection;
-import java.util.List;
-
-public class QMFPackageQueryCommand extends QMFCommand
-{
-
- private static final Logger _qmfLogger = Logger.getLogger("qpid.qmf");
-
- public QMFPackageQueryCommand(QMFCommandHeader header, BBDecoder decoder)
- {
- super(header);
- }
-
- public void process(VirtualHost virtualHost, ServerMessage message)
- {
- String exchangeName = message.getMessageHeader().getReplyToExchange();
- String routingKey = message.getMessageHeader().getReplyToRoutingKey();
-
-
- IApplicationRegistry appRegistry = virtualHost.getApplicationRegistry();
- QMFService service = appRegistry.getQMFService();
-
- Collection<QMFPackage> supportedSchemas = service.getSupportedSchemas();
-
- QMFCommand[] commands = new QMFCommand[ supportedSchemas.size() + 1 ];
-
- _qmfLogger.debug("Exectuting " + this);
-
- int i = 0;
- for(QMFPackage p : supportedSchemas)
- {
- commands[i++] = new QMFPackageIndicationCommand(this, p.getName());
- }
- commands[ commands.length - 1 ] = new QMFCommandCompletionCommand(this);
-
-
- for(QMFCommand cmd : commands)
- {
-
- QMFMessage responseMessage = new QMFMessage(routingKey, cmd);
-
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(exchangeName);
-
- List<? extends BaseQueue> queues = exchange.route(responseMessage);
-
-
- for(BaseQueue q : queues)
- {
- try
- {
- q.enqueue(responseMessage);
- }
- catch (AMQException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- }
- }
-
- public String toString()
- {
- return "QMFPackageQueryCommand";
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFProperty.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFProperty.java
deleted file mode 100644
index 5314466e2a..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFProperty.java
+++ /dev/null
@@ -1,120 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.Encoder;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class QMFProperty
-{
- private final Map<String, Object> _map = new LinkedHashMap<String, Object>();
- private static final String NAME = "name";
- private static final String TYPE = "type";
- private static final String ACCESS = "access";
- private static final String INDEX = "index";
- private static final String OPTIONAL = "optional";
- private static final String REF_PACKAGE = "refPackage";
- private static final String REF_CLASS = "refClass";
- private static final String UNIT = "unit";
- private static final String MIN = "min";
- private static final String MAX = "max";
- private static final String MAX_LENGTH = "maxlen";
- private static final String DESCRIPTION = "desc";
-
-
- public static enum AccessCode
- {
- RC,
- RW,
- RO;
-
- public int codeValue()
- {
- return ordinal()+1;
- }
- }
-
- public QMFProperty(String name, QMFType type, AccessCode accessCode, boolean index, boolean optional)
- {
- _map.put(NAME, name);
- _map.put(TYPE, type.codeValue());
- _map.put(ACCESS, accessCode.codeValue());
- _map.put(INDEX, index ? 1 : 0);
- _map.put(OPTIONAL, optional ? 1 :0);
- }
-
-
- public void setQMFClass(QMFClass qmfClass)
- {
- }
-
- public void setReferencedClass(String refClass)
- {
- _map.put(REF_CLASS, refClass);
- }
-
- public void setReferencedPackage(String refPackage)
- {
- _map.put(REF_CLASS, refPackage);
- }
-
-
- public String getName()
- {
- return (String) _map.get(NAME);
- }
-
-
- public void setUnit(String unit)
- {
- _map.put(UNIT, unit);
- }
-
- public void setMin(Number min)
- {
- _map.put(MIN, min);
- }
-
- public void setMax(Number max)
- {
- _map.put(MAX, max);
- }
-
- public void setMaxLength(int maxlen)
- {
- _map.put(MAX_LENGTH, maxlen);
- }
-
-
- public void setDescription(String description)
- {
- _map.put(DESCRIPTION, description);
- }
-
- public void encode(Encoder encoder)
- {
- encoder.writeMap(_map);
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFSchemaRequestCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFSchemaRequestCommand.java
deleted file mode 100644
index 57c67fa7f6..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFSchemaRequestCommand.java
+++ /dev/null
@@ -1,102 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.codec.BBDecoder;
-
-import java.util.List;
-
-public class QMFSchemaRequestCommand extends QMFCommand
-{
- private static final Logger _qmfLogger = Logger.getLogger("qpid.qmf");
-
- private final String _packageName;
- private final String _className;
- private final byte[] _hash;
-
- public QMFSchemaRequestCommand(QMFCommandHeader header, BBDecoder decoder)
- {
- super(header);
- _packageName = decoder.readStr8();
- _className = decoder.readStr8();
- _hash = decoder.readBin128();
- }
-
- public void process(VirtualHost virtualHost, ServerMessage message)
- {
- _qmfLogger.debug("Execute: " + this);
-
- String exchangeName = message.getMessageHeader().getReplyToExchange();
- String routingKey = message.getMessageHeader().getReplyToRoutingKey();
-
- IApplicationRegistry appRegistry = virtualHost.getApplicationRegistry();
- QMFService service = appRegistry.getQMFService();
-
- QMFPackage qmfPackage = service.getPackage(_packageName);
- QMFClass qmfClass = qmfPackage.getQMFClass( _className );
-
- QMFCommand[] commands = new QMFCommand[2];
- commands[0] = new QMFSchemaResponseCommand(this, qmfClass);
- commands[ 1 ] = new QMFCommandCompletionCommand(this);
-
-
-
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(exchangeName);
-
- for(QMFCommand cmd : commands)
- {
- QMFMessage responseMessage = new QMFMessage(routingKey, cmd);
-
-
- List<? extends BaseQueue> queues = exchange.route(responseMessage);
-
- for(BaseQueue q : queues)
- {
- try
- {
- q.enqueue(responseMessage);
- }
- catch (AMQException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- }
- }
-
- @Override
- public String toString()
- {
- return "QMFSchemaRequestCommand{" +
- " packageName='" + _packageName + '\'' +
- ", className='" + _className + '\'' +
- '}';
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFSchemaResponseCommand.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFSchemaResponseCommand.java
deleted file mode 100644
index 4bd0e41989..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFSchemaResponseCommand.java
+++ /dev/null
@@ -1,81 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.BBEncoder;
-
-import java.util.Collection;
-
-public class QMFSchemaResponseCommand extends QMFCommand
-{
- private final QMFClass _qmfClass;
-
-
- public QMFSchemaResponseCommand(QMFSchemaRequestCommand qmfSchemaRequestCommand, QMFClass qmfClass)
- {
- super(new QMFCommandHeader(qmfSchemaRequestCommand.getHeader().getVersion(),
- qmfSchemaRequestCommand.getHeader().getSeq(),
- QMFOperation.SCHEMA_RESPONSE));
- _qmfClass = qmfClass;
- }
-
- @Override
- public void encode(BBEncoder encoder)
- {
- super.encode(encoder);
- encoder.writeUint8(_qmfClass.getType().getValue());
- encoder.writeStr8(_qmfClass.getPackage().getName());
- encoder.writeStr8(_qmfClass.getName());
- encoder.writeBin128(_qmfClass.getSchemaHash());
-
- Collection<QMFProperty> props = _qmfClass.getProperties();
- Collection<QMFStatistic> stats = _qmfClass.getStatistics();
- Collection<QMFMethod> methods = _qmfClass.getMethods();
-
- encoder.writeUint16(props.size());
- if(_qmfClass.getType() == QMFClass.Type.OBJECT)
- {
- encoder.writeUint16(stats.size());
- encoder.writeUint16(methods.size());
- }
-
- for(QMFProperty prop : props)
- {
- prop.encode(encoder);
- }
-
- if(_qmfClass.getType() == QMFClass.Type.OBJECT)
- {
-
- for(QMFStatistic stat : stats)
- {
- stat.encode(encoder);
- }
-
- for(QMFMethod method : methods)
- {
- method.encode(encoder);
- }
- }
-
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFService.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFService.java
deleted file mode 100644
index d713976919..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFService.java
+++ /dev/null
@@ -1,2086 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.common.Closeable;
-import org.apache.qpid.qmf.schema.BrokerSchema;
-import org.apache.qpid.server.configuration.*;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-public class QMFService implements ConfigStore.ConfigEventListener, Closeable
-{
-
-
- private IApplicationRegistry _applicationRegistry;
- private ConfigStore _configStore;
-
-
- private final Map<String, QMFPackage> _supportedSchemas = new HashMap<String, QMFPackage>();
- private static final Map<String, ConfigObjectType> _qmfClassMapping = new HashMap<String, ConfigObjectType>();
-
- static
- {
- _qmfClassMapping.put("system", SystemConfigType.getInstance());
- _qmfClassMapping.put("broker", BrokerConfigType.getInstance());
- _qmfClassMapping.put("vhost", VirtualHostConfigType.getInstance());
- _qmfClassMapping.put("exchange", ExchangeConfigType.getInstance());
- _qmfClassMapping.put("queue", QueueConfigType.getInstance());
- _qmfClassMapping.put("binding", BindingConfigType.getInstance());
- _qmfClassMapping.put("connection", ConnectionConfigType.getInstance());
- _qmfClassMapping.put("session", SessionConfigType.getInstance());
- _qmfClassMapping.put("subscription", SubscriptionConfigType.getInstance());
- _qmfClassMapping.put("link", LinkConfigType.getInstance());
- _qmfClassMapping.put("bridge", BridgeConfigType.getInstance());
- }
-
- private final Map<ConfigObjectType, ConfigObjectAdapter> _adapterMap =
- new HashMap<ConfigObjectType, ConfigObjectAdapter>();
- private final Map<ConfigObjectType,QMFClass> _classMap =
- new HashMap<ConfigObjectType,QMFClass>();
-
-
- private final ConcurrentHashMap<QMFClass,ConcurrentHashMap<ConfiguredObject, QMFObject>> _managedObjects =
- new ConcurrentHashMap<QMFClass,ConcurrentHashMap<ConfiguredObject, QMFObject>>();
-
- private final ConcurrentHashMap<QMFClass,ConcurrentHashMap<UUID, QMFObject>> _managedObjectsById =
- new ConcurrentHashMap<QMFClass,ConcurrentHashMap<UUID, QMFObject>>();
-
- private static final BrokerSchema PACKAGE = BrokerSchema.getPackage();
-
- public static interface Listener
- {
- public void objectCreated(QMFObject obj);
- public void objectDeleted(QMFObject obj);
- }
-
- private final CopyOnWriteArrayList<Listener> _listeners = new CopyOnWriteArrayList<Listener>();
-
- abstract class ConfigObjectAdapter<Q extends QMFObject<S,D>, S extends QMFObjectClass<Q,D>, D extends QMFObject.Delegate, T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>>
- {
- private final T _type;
- private final S _qmfClass;
-
-
- protected ConfigObjectAdapter(final T type, final S qmfClass)
- {
- _type = type;
- _qmfClass = qmfClass;
- _adapterMap.put(type,this);
- _classMap.put(type,qmfClass);
- }
-
- public T getType()
- {
- return _type;
- }
-
- public S getQMFClass()
- {
- return _qmfClass;
- }
-
- protected final Q newInstance(D delegate)
- {
- return _qmfClass.newInstance(delegate);
- }
-
- public abstract Q createQMFObject(C configObject);
- }
-
- private ConfigObjectAdapter<BrokerSchema.SystemObject,
- BrokerSchema.SystemClass,
- BrokerSchema.SystemDelegate,
- SystemConfigType,
- SystemConfig> _systemObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.SystemObject,
- BrokerSchema.SystemClass,
- BrokerSchema.SystemDelegate,
- SystemConfigType,
- SystemConfig>(SystemConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.SystemClass.class))
- {
-
-
- public BrokerSchema.SystemObject createQMFObject(
- final SystemConfig configObject)
- {
- return newInstance(new SystemDelegate(configObject));
- }
- };
-
- private ConfigObjectAdapter<BrokerSchema.BrokerObject,
- BrokerSchema.BrokerClass,
- BrokerSchema.BrokerDelegate,
- BrokerConfigType,
- BrokerConfig> _brokerObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.BrokerObject,
- BrokerSchema.BrokerClass,
- BrokerSchema.BrokerDelegate,
- BrokerConfigType,
- BrokerConfig>(BrokerConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.BrokerClass.class))
- {
-
- public BrokerSchema.BrokerObject createQMFObject(
- final BrokerConfig configObject)
- {
- return newInstance(new BrokerDelegate(configObject));
- }
- };
-
- private ConfigObjectAdapter<BrokerSchema.VhostObject,
- BrokerSchema.VhostClass,
- BrokerSchema.VhostDelegate,
- VirtualHostConfigType,
- VirtualHostConfig> _vhostObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.VhostObject,
- BrokerSchema.VhostClass,
- BrokerSchema.VhostDelegate,
- VirtualHostConfigType,
- VirtualHostConfig>(VirtualHostConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.VhostClass.class))
- {
-
- public BrokerSchema.VhostObject createQMFObject(
- final VirtualHostConfig configObject)
- {
- return newInstance(new VhostDelegate(configObject));
- }
- };
-
-
- private ConfigObjectAdapter<BrokerSchema.ExchangeObject,
- BrokerSchema.ExchangeClass,
- BrokerSchema.ExchangeDelegate,
- ExchangeConfigType,
- ExchangeConfig> _exchangeObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.ExchangeObject,
- BrokerSchema.ExchangeClass,
- BrokerSchema.ExchangeDelegate,
- ExchangeConfigType,
- ExchangeConfig>(ExchangeConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.ExchangeClass.class))
- {
-
- public BrokerSchema.ExchangeObject createQMFObject(
- final ExchangeConfig configObject)
- {
- return newInstance(new ExchangeDelegate(configObject));
- }
- };
-
-
- private ConfigObjectAdapter<BrokerSchema.QueueObject,
- BrokerSchema.QueueClass,
- BrokerSchema.QueueDelegate,
- QueueConfigType,
- QueueConfig> _queueObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.QueueObject,
- BrokerSchema.QueueClass,
- BrokerSchema.QueueDelegate,
- QueueConfigType,
- QueueConfig>(QueueConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.QueueClass.class))
- {
-
- public BrokerSchema.QueueObject createQMFObject(
- final QueueConfig configObject)
- {
- return newInstance(new QueueDelegate(configObject));
- }
- };
-
-
- private ConfigObjectAdapter<BrokerSchema.BindingObject,
- BrokerSchema.BindingClass,
- BrokerSchema.BindingDelegate,
- BindingConfigType,
- BindingConfig> _bindingObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.BindingObject,
- BrokerSchema.BindingClass,
- BrokerSchema.BindingDelegate,
- BindingConfigType,
- BindingConfig>(BindingConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.BindingClass.class))
- {
-
- public BrokerSchema.BindingObject createQMFObject(
- final BindingConfig configObject)
- {
- return newInstance(new BindingDelegate(configObject));
- }
- };
-
-
- private ConfigObjectAdapter<BrokerSchema.ConnectionObject,
- BrokerSchema.ConnectionClass,
- BrokerSchema.ConnectionDelegate,
- ConnectionConfigType,
- ConnectionConfig> _connectionObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.ConnectionObject,
- BrokerSchema.ConnectionClass,
- BrokerSchema.ConnectionDelegate,
- ConnectionConfigType,
- ConnectionConfig>(ConnectionConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.ConnectionClass.class))
- {
-
- public BrokerSchema.ConnectionObject createQMFObject(
- final ConnectionConfig configObject)
- {
- return newInstance(new ConnectionDelegate(configObject));
- }
- };
-
-
- private ConfigObjectAdapter<BrokerSchema.SessionObject,
- BrokerSchema.SessionClass,
- BrokerSchema.SessionDelegate,
- SessionConfigType,
- SessionConfig> _sessionObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.SessionObject,
- BrokerSchema.SessionClass,
- BrokerSchema.SessionDelegate,
- SessionConfigType,
- SessionConfig>(SessionConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.SessionClass.class))
- {
-
- public BrokerSchema.SessionObject createQMFObject(
- final SessionConfig configObject)
- {
- return newInstance(new SessionDelegate(configObject));
- }
- };
-
- private ConfigObjectAdapter<BrokerSchema.SubscriptionObject,
- BrokerSchema.SubscriptionClass,
- BrokerSchema.SubscriptionDelegate,
- SubscriptionConfigType,
- SubscriptionConfig> _subscriptionObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.SubscriptionObject,
- BrokerSchema.SubscriptionClass,
- BrokerSchema.SubscriptionDelegate,
- SubscriptionConfigType,
- SubscriptionConfig>(SubscriptionConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.SubscriptionClass.class))
- {
-
- public BrokerSchema.SubscriptionObject createQMFObject(
- final SubscriptionConfig configObject)
- {
- return newInstance(new SubscriptionDelegate(configObject));
- }
- };
-
-
- private ConfigObjectAdapter<BrokerSchema.LinkObject,
- BrokerSchema.LinkClass,
- BrokerSchema.LinkDelegate,
- LinkConfigType,
- LinkConfig> _linkObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.LinkObject,
- BrokerSchema.LinkClass,
- BrokerSchema.LinkDelegate,
- LinkConfigType,
- LinkConfig>(LinkConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.LinkClass.class))
- {
-
- public BrokerSchema.LinkObject createQMFObject(
- final LinkConfig configObject)
- {
- return newInstance(new LinkDelegate(configObject));
- }
- };
-
-
- private ConfigObjectAdapter<BrokerSchema.BridgeObject,
- BrokerSchema.BridgeClass,
- BrokerSchema.BridgeDelegate,
- BridgeConfigType,
- BridgeConfig> _bridgeObjectAdapter =
- new ConfigObjectAdapter<BrokerSchema.BridgeObject,
- BrokerSchema.BridgeClass,
- BrokerSchema.BridgeDelegate,
- BridgeConfigType,
- BridgeConfig>(BridgeConfigType.getInstance(),
- PACKAGE.getQMFClassInstance(BrokerSchema.BridgeClass.class))
- {
-
- public BrokerSchema.BridgeObject createQMFObject(
- final BridgeConfig configObject)
- {
- return newInstance(new BridgeDelegate(configObject));
- }
- };
-
-
-
- public QMFService(ConfigStore configStore, IApplicationRegistry applicationRegistry)
- {
- _configStore = configStore;
- _applicationRegistry = applicationRegistry;
- registerSchema(PACKAGE);
-
- for(ConfigObjectType v : _qmfClassMapping.values())
- {
- configStore.addConfigEventListener(v, this);
- }
- init();
- }
-
- public void close()
- {
- for(ConfigObjectType v : _qmfClassMapping.values())
- {
- _configStore.removeConfigEventListener(v, this);
- }
- _listeners.clear();
-
- _managedObjects.clear();
- _managedObjectsById.clear();
- _classMap.clear();
- _adapterMap.clear();
- _supportedSchemas.clear();
- }
-
-
- public void registerSchema(QMFPackage qmfPackage)
- {
- _supportedSchemas.put(qmfPackage.getName(), qmfPackage);
- }
-
-
- public Collection<QMFPackage> getSupportedSchemas()
- {
- return _supportedSchemas.values();
- }
-
- public QMFPackage getPackage(String aPackage)
- {
- return _supportedSchemas.get(aPackage);
- }
-
- public void onEvent(final ConfiguredObject object, final ConfigStore.Event evt)
- {
-
- switch (evt)
- {
- case CREATED:
- manageObject(object);
- break;
-
- case DELETED:
- unmanageObject(object);
- break;
- }
- }
-
- public QMFObject getObjectById(QMFClass qmfclass, UUID id)
- {
- ConcurrentHashMap<UUID, QMFObject> map = _managedObjectsById.get(qmfclass);
- if(map != null)
- {
-
- UUID key = new UUID(id.getMostSignificantBits() & (0xFFFl << 48), id.getLeastSignificantBits());
- return map.get(key);
-
- }
- else
- {
- return null;
- }
- }
-
- private void unmanageObject(final ConfiguredObject object)
- {
- final QMFClass qmfClass = _classMap.get(object.getConfigType());
-
- if(qmfClass == null)
- {
- return;
- }
-
- ConcurrentHashMap<ConfiguredObject, QMFObject> classObjects = _managedObjects.get(qmfClass);
- if(classObjects != null)
- {
- QMFObject qmfObject = classObjects.remove(object);
- if(qmfObject != null)
- {
- _managedObjectsById.get(qmfClass).remove(object.getQMFId());
- objectRemoved(qmfObject);
- }
- }
- }
-
- private void manageObject(final ConfiguredObject object)
- {
- ConfigObjectAdapter adapter = _adapterMap.get(object.getConfigType());
- QMFObject qmfObject = adapter.createQMFObject(object);
- final QMFClass qmfClass = qmfObject.getQMFClass();
- ConcurrentHashMap<ConfiguredObject, QMFObject> classObjects = _managedObjects.get(qmfClass);
-
- if(classObjects == null)
- {
- classObjects = new ConcurrentHashMap<ConfiguredObject, QMFObject>();
- if(_managedObjects.putIfAbsent(qmfClass, classObjects) != null)
- {
- classObjects = _managedObjects.get(qmfClass);
- }
- }
-
- ConcurrentHashMap<UUID, QMFObject> classObjectsById = _managedObjectsById.get(qmfClass);
- if(classObjectsById == null)
- {
- classObjectsById = new ConcurrentHashMap<UUID, QMFObject>();
- if(_managedObjectsById.putIfAbsent(qmfClass, classObjectsById) != null)
- {
- classObjectsById = _managedObjectsById.get(qmfClass);
- }
- }
-
- classObjectsById.put(object.getQMFId(),qmfObject);
-
- if(classObjects.putIfAbsent(object, qmfObject) == null)
- {
- objectAdded(qmfObject);
- }
- }
-
- private void objectRemoved(final QMFObject qmfObject)
- {
- qmfObject.setDeleteTime();
- for(Listener l : _listeners)
- {
- l.objectDeleted(qmfObject);
- }
- }
-
- private void objectAdded(final QMFObject qmfObject)
- {
- for(Listener l : _listeners)
- {
- l.objectCreated(qmfObject);
- }
- }
-
- public void addListener(Listener l)
- {
- _listeners.add(l);
- }
-
- public void removeListener(Listener l)
- {
- _listeners.remove(l);
- }
-
-
- private void init()
- {
- for(QMFClass qmfClass : PACKAGE.getClasses())
- {
- ConfigObjectType configType = getConfigType(qmfClass);
- if(configType != null)
- {
- Collection<ConfiguredObject> objects = _configStore.getConfiguredObjects(configType);
- for(ConfiguredObject object : objects)
- {
- manageObject(object);
- }
- }
- }
- }
-
- public Collection<QMFObject> getObjects(QMFClass qmfClass)
- {
- ConcurrentHashMap<ConfiguredObject, QMFObject> classObjects = _managedObjects.get(qmfClass);
- if(classObjects != null)
- {
- return classObjects.values();
- }
- else
- {
- return Collections.EMPTY_SET;
- }
- }
-
- private QMFObject adapt(final ConfiguredObject object)
- {
- if(object == null)
- {
- return null;
- }
-
- QMFClass qmfClass = _classMap.get(object.getConfigType());
- ConcurrentHashMap<ConfiguredObject, QMFObject> classObjects = _managedObjects.get(qmfClass);
- if(classObjects != null)
- {
- QMFObject qmfObject = classObjects.get(object);
- if(qmfObject != null)
- {
- return qmfObject;
- }
- }
-
- return _adapterMap.get(object.getConfigType()).createQMFObject(object);
- }
-
- private ConfigObjectType getConfigType(final QMFClass qmfClass)
- {
- return _qmfClassMapping.get(qmfClass.getName());
- }
-
- private static class SystemDelegate implements BrokerSchema.SystemDelegate
- {
- private final SystemConfig _obj;
-
- public SystemDelegate(final SystemConfig obj)
- {
- _obj = obj;
- }
-
- public UUID getSystemId()
- {
- return _obj.getQMFId();
- }
-
- public String getOsName()
- {
- return _obj.getOperatingSystemName();
- }
-
- public String getNodeName()
- {
- return _obj.getNodeName();
- }
-
- public String getRelease()
- {
- return _obj.getOSRelease();
- }
-
- public String getVersion()
- {
- return _obj.getOSVersion();
- }
-
- public String getMachine()
- {
- return _obj.getOSArchitecture();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class BrokerDelegate implements BrokerSchema.BrokerDelegate
- {
- private final BrokerConfig _obj;
-
- public BrokerDelegate(final BrokerConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.SystemObject getSystemRef()
- {
- return (BrokerSchema.SystemObject) adapt(_obj.getSystem());
- }
-
- public String getName()
- {
- return "amqp-broker";
- }
-
- public Integer getPort()
- {
- return _obj.getPort();
- }
-
- public Integer getWorkerThreads()
- {
- return _obj.getWorkerThreads();
- }
-
- public Integer getMaxConns()
- {
- return _obj.getMaxConnections();
- }
-
- public Integer getConnBacklog()
- {
- return _obj.getConnectionBacklogLimit();
- }
-
- public Long getStagingThreshold()
- {
- return _obj.getStagingThreshold();
- }
-
- public Boolean getMgmtPublish()
- {
- return true;
- }
-
- public Integer getMgmtPubInterval()
- {
- return _obj.getManagementPublishInterval();
- }
-
- public String getVersion()
- {
- return _obj.getVersion();
- }
-
- public String getDataDir()
- {
- return _obj.getDataDirectory();
- }
-
- public Long getUptime()
- {
- return (System.currentTimeMillis() - _obj.getCreateTime()) * 1000000L;
- }
-
- public Long getQueueCount()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgTotalEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgTotalDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteTotalEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteTotalDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgDepth()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteDepth()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgPersistEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgPersistDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getBytePersistEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getBytePersistDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgTxnEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgTxnDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteTxnEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteTxnDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgFtdEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgFtdDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteFtdEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteFtdDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgFtdDepth()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteFtdDepth()
- {
- // TODO
- return 0L;
- }
-
- public Long getReleases()
- {
- // TODO
- return 0L;
- }
-
- public Long getAcquires()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsNoRoute()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsTtl()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsRing()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsLvq()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsOverflow()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsSubscriber()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsPurge()
- {
- // TODO
- return 0L;
- }
-
- public Long getReroutes()
- {
- // TODO
- return 0L;
- }
-
- public Long getAbandoned()
- {
- // TODO
- return 0L;
- }
-
- public Long getAbandonedViaAlt()
- {
- // TODO
- return 0L;
- }
-
- public BrokerSchema.BrokerClass.EchoMethodResponseCommand echo(final BrokerSchema.BrokerClass.EchoMethodResponseCommandFactory factory,
- final Long sequence,
- final String body)
- {
- return factory.createResponseCommand(sequence, body);
- }
-
- public BrokerSchema.BrokerClass.ConnectMethodResponseCommand connect(final BrokerSchema.BrokerClass.ConnectMethodResponseCommandFactory factory,
- final String host,
- final Long port,
- final Boolean durable,
- final String authMechanism,
- final String username,
- final String password,
- final String transport)
- {
- _obj.createBrokerConnection(transport, host, port.intValue(), durable, authMechanism, username, password);
-
- return factory.createResponseCommand();
- }
-
- public BrokerSchema.BrokerClass.QueueMoveMessagesMethodResponseCommand queueMoveMessages(final BrokerSchema.BrokerClass.QueueMoveMessagesMethodResponseCommandFactory factory,
- final String srcQueue,
- final String destQueue,
- final Long qty,
- final Map filter) // TODO: move based on group identifier
- {
- // TODO
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.BrokerClass.GetLogLevelMethodResponseCommand getLogLevel(final BrokerSchema.BrokerClass.GetLogLevelMethodResponseCommandFactory factory)
- {
- // TODO: The Java broker has numerous loggers, so we can't really implement this method properly.
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.BrokerClass.SetLogLevelMethodResponseCommand setLogLevel(final BrokerSchema.BrokerClass.SetLogLevelMethodResponseCommandFactory factory, String level)
- {
- // TODO: The Java broker has numerous loggers, so we can't really implement this method properly.
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.BrokerClass.GetTimestampConfigMethodResponseCommand getTimestampConfig(final BrokerSchema.BrokerClass.GetTimestampConfigMethodResponseCommandFactory factory)
- {
- // TODO: timestamp support
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.BrokerClass.SetTimestampConfigMethodResponseCommand setTimestampConfig(final BrokerSchema.BrokerClass.SetTimestampConfigMethodResponseCommandFactory factory,
- final java.lang.Boolean receive)
- {
- // TODO: timestamp support
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.BrokerClass.CreateMethodResponseCommand create(final BrokerSchema.BrokerClass.CreateMethodResponseCommandFactory factory,
- final String type,
- final String name,
- final Map properties,
- final java.lang.Boolean lenient)
- {
- //TODO:
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.BrokerClass.DeleteMethodResponseCommand delete(final BrokerSchema.BrokerClass.DeleteMethodResponseCommandFactory factory,
- final String type,
- final String name,
- final Map options)
- {
- //TODO:
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.BrokerClass.QueryMethodResponseCommand query(final BrokerSchema.BrokerClass.QueryMethodResponseCommandFactory factory,
- final String type,
- final String name)
- {
- //TODO:
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class VhostDelegate implements BrokerSchema.VhostDelegate
- {
- private final VirtualHostConfig _obj;
-
- public VhostDelegate(final VirtualHostConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.BrokerObject getBrokerRef()
- {
- return (BrokerSchema.BrokerObject) adapt(_obj.getBroker());
- }
-
- public String getName()
- {
- return _obj.getName();
- }
-
- public String getFederationTag()
- {
- return _obj.getFederationTag();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class ExchangeDelegate implements BrokerSchema.ExchangeDelegate
- {
- private final ExchangeConfig _obj;
-
- public ExchangeDelegate(final ExchangeConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.VhostObject getVhostRef()
- {
- return (BrokerSchema.VhostObject) adapt(_obj.getVirtualHost());
- }
-
- public String getName()
- {
- return _obj.getName();
- }
-
- public String getType()
- {
- return _obj.getType().getName().toString();
- }
-
- public Boolean getDurable()
- {
- return _obj.isDurable();
- }
-
- public Boolean getAutoDelete()
- {
- return _obj.isAutoDelete();
- }
-
- public BrokerSchema.ExchangeObject getAltExchange()
- {
- if(_obj.getAlternateExchange() != null)
- {
- return (BrokerSchema.ExchangeObject) adapt(_obj.getAlternateExchange());
- }
- else
- {
- return null;
- }
- }
-
- public Map getArguments()
- {
- return _obj.getArguments();
- }
-
- public Long getProducerCount()
- {
- // TODO
- return 0l;
- }
-
- public Long getProducerCountHigh()
- {
- // TODO
- return 0l;
- }
-
- public Long getProducerCountLow()
- {
- // TODO
- return 0l;
- }
-
- public Long getBindingCount()
- {
- return _obj.getBindingCount();
- }
-
- public Long getBindingCountHigh()
- {
- return _obj.getBindingCountHigh();
- }
-
- public Long getBindingCountLow()
- {
- // TODO
- return 0l;
- }
-
- public Long getMsgReceives()
- {
- return _obj.getMsgReceives();
- }
-
- public Long getMsgDrops()
- {
- return getMsgReceives() - getMsgRoutes();
- }
-
- public Long getMsgRoutes()
- {
- return _obj.getMsgRoutes();
- }
-
- public Long getByteReceives()
- {
- return _obj.getByteReceives();
- }
-
- public Long getByteDrops()
- {
- return getByteReceives() - getByteRoutes();
- }
-
- public Long getByteRoutes()
- {
- return _obj.getByteRoutes();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class QueueDelegate implements BrokerSchema.QueueDelegate
- {
- private final QueueConfig _obj;
-
- public QueueDelegate(final QueueConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.VhostObject getVhostRef()
- {
- return (BrokerSchema.VhostObject) adapt(_obj.getVirtualHost());
- }
-
- public String getName()
- {
- return _obj.getName();
- }
-
- public Boolean getDurable()
- {
- return _obj.isDurable();
- }
-
- public Boolean getAutoDelete()
- {
- return _obj.isAutoDelete();
- }
-
- public Boolean getExclusive()
- {
- return _obj.isExclusive();
- }
-
- public BrokerSchema.ExchangeObject getAltExchange()
- {
- if(_obj.getAlternateExchange() != null)
- {
- return (BrokerSchema.ExchangeObject) adapt(_obj.getAlternateExchange());
- }
- else
- {
- return null;
- }
- }
-
- public Long getMsgTotalEnqueues()
- {
- return _obj.getReceivedMessageCount();
- }
-
- public Long getMsgTotalDequeues()
- {
- return _obj.getMessageDequeueCount();
- }
-
- public Long getMsgTxnEnqueues()
- {
- return _obj.getMsgTxnEnqueues();
- }
-
- public Long getMsgTxnDequeues()
- {
- return _obj.getMsgTxnDequeues();
- }
-
- public Long getMsgPersistEnqueues()
- {
- return _obj.getPersistentMsgEnqueues();
- }
-
- public Long getMsgPersistDequeues()
- {
- return _obj.getPersistentMsgDequeues();
- }
-
- public Long getMsgDepth()
- {
- return (long) _obj.getMessageCount();
- }
-
- public Long getByteDepth()
- {
- return _obj.getQueueDepth();
- }
-
- public Long getByteTotalEnqueues()
- {
- return _obj.getTotalEnqueueSize();
- }
-
- public Long getByteTotalDequeues()
- {
- return _obj.getTotalDequeueSize();
- }
-
- public Long getByteTxnEnqueues()
- {
- return _obj.getByteTxnEnqueues();
- }
-
- public Long getByteTxnDequeues()
- {
- return _obj.getByteTxnDequeues();
- }
-
- public Long getBytePersistEnqueues()
- {
- return _obj.getPersistentByteEnqueues();
- }
-
- public Long getBytePersistDequeues()
- {
- return _obj.getPersistentByteDequeues();
- }
-
- public Long getMsgFtdEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgFtdDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteFtdEnqueues()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteFtdDequeues()
- {
- // TODO
- return 0L;
- }
-
- public Long getMsgFtdDepth()
- {
- // TODO
- return 0L;
- }
-
- public Long getByteFtdDepth()
- {
- // TODO
- return 0L;
- }
-
- public Long getReleases()
- {
- // TODO
- return 0L;
- }
-
- public Long getAcquires()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsTtl()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsRing()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsLvq()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsOverflow()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsSubscriber()
- {
- // TODO
- return 0L;
- }
-
- public Long getDiscardsPurge()
- {
- // TODO
- return 0L;
- }
-
- public Long getReroutes()
- {
- // TODO
- return 0L;
- }
-
- public Long getConsumerCount()
- {
- return (long) _obj.getConsumerCount();
- }
-
- public Long getConsumerCountHigh()
- {
- return (long) _obj.getConsumerCountHigh();
- }
-
- public Long getConsumerCountLow()
- {
- // TODO
- return 0l;
- }
-
- public Long getBindingCount()
- {
- return (long) _obj.getBindingCount();
- }
-
- public Long getBindingCountHigh()
- {
- return (long) _obj.getBindingCountHigh();
- }
-
- public Long getBindingCountLow()
- {
- // TODO
- return 0l;
- }
-
- public Long getUnackedMessages()
- {
- return _obj.getUnackedMessageCount();
- }
-
- public Long getUnackedMessagesHigh()
- {
- return _obj.getUnackedMessageCountHigh();
- }
-
- public Long getUnackedMessagesLow()
- {
- // TODO
- return 0l;
- }
-
- public Long getMessageLatencySamples()
- {
- // TODO
- return 0l;
- }
-
- public Long getMessageLatencyMin()
- {
- // TODO
- return 0l;
- }
-
- public Long getMessageLatencyMax()
- {
- // TODO
- return 0l;
- }
-
- public Long getMessageLatencyAverage()
- {
- // TODO
- return 0l;
- }
-
- public Boolean getFlowStopped()
- {
- return Boolean.FALSE;
- }
-
- public Long getFlowStoppedCount()
- {
- return 0L;
- }
-
- public BrokerSchema.QueueClass.PurgeMethodResponseCommand purge(final BrokerSchema.QueueClass.PurgeMethodResponseCommandFactory factory,
- final Long request,
- final Map filter) // TODO: support for purge-by-group-identifier
- {
- try
- {
- _obj.purge(request);
- } catch (AMQException e)
- {
- // TODO
- throw new RuntimeException();
- }
- return factory.createResponseCommand();
- }
-
- public BrokerSchema.QueueClass.RerouteMethodResponseCommand reroute(final BrokerSchema.QueueClass.RerouteMethodResponseCommandFactory factory,
- final Long request,
- final Boolean useAltExchange,
- final String exchange,
- final Map filter) // TODO: support for re-route-by-group-identifier
- {
- //TODO
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
-
- public Map getArguments()
- {
- return _obj.getArguments();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class BindingDelegate implements BrokerSchema.BindingDelegate
- {
- private final BindingConfig _obj;
-
- public BindingDelegate(final BindingConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.ExchangeObject getExchangeRef()
- {
- return (BrokerSchema.ExchangeObject) adapt(_obj.getExchange());
- }
-
- public BrokerSchema.QueueObject getQueueRef()
- {
- return (BrokerSchema.QueueObject) adapt(_obj.getQueue());
- }
-
- public String getBindingKey()
- {
- return _obj.getBindingKey();
- }
-
- public Map getArguments()
- {
- return _obj.getArguments();
- }
-
- public String getOrigin()
- {
- return _obj.getOrigin();
- }
-
- public Long getMsgMatched()
- {
- // TODO
- return _obj.getMatches();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class ConnectionDelegate implements BrokerSchema.ConnectionDelegate
- {
- private final ConnectionConfig _obj;
-
- public ConnectionDelegate(final ConnectionConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.VhostObject getVhostRef()
- {
- return (BrokerSchema.VhostObject) adapt(_obj.getVirtualHost());
- }
-
- public String getAddress()
- {
- return _obj.getAddress();
- }
-
- public Boolean getIncoming()
- {
- return _obj.isIncoming();
- }
-
- public Boolean getSystemConnection()
- {
- return _obj.isSystemConnection();
- }
-
- public Boolean getFederationLink()
- {
- return _obj.isFederationLink();
- }
-
- public String getAuthIdentity()
- {
- return _obj.getAuthId();
- }
-
- public String getRemoteProcessName()
- {
- return _obj.getRemoteProcessName();
- }
-
- public Long getRemotePid()
- {
- Integer remotePID = _obj.getRemotePID();
- return remotePID == null ? null : (long) remotePID;
- }
-
- public Long getRemoteParentPid()
- {
- Integer remotePPID = _obj.getRemoteParentPID();
- return remotePPID == null ? null : (long) remotePPID;
-
- }
-
- public Boolean getClosing()
- {
- return false;
- }
-
- public Long getFramesFromClient()
- {
- // TODO
- return 0l;
- }
-
- public Long getFramesToClient()
- {
- // TODO
- return 0l;
- }
-
- public Long getBytesFromClient()
- {
- // TODO
- return 0l;
- }
-
- public Long getBytesToClient()
- {
- // TODO
- return 0l;
- }
-
- public Long getMsgsFromClient()
- {
- // TODO
- return 0l;
- }
-
- public Long getMsgsToClient()
- {
- // TODO
- return 0l;
- }
-
- public BrokerSchema.ConnectionClass.CloseMethodResponseCommand close(final BrokerSchema.ConnectionClass.CloseMethodResponseCommandFactory factory)
- {
- _obj.mgmtClose();
-
- return factory.createResponseCommand();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public Boolean getShadow()
- {
- return _obj.isShadow();
- }
-
- public Boolean getUserProxyAuth()
- {
- // TODO
- return false;
- }
-
- public String getSaslMechanism()
- {
- // TODO
- return null;
- }
- public Integer getSaslSsf()
- {
- // TODO
- return 0;
- }
-
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class SessionDelegate implements BrokerSchema.SessionDelegate
- {
- private final SessionConfig _obj;
-
- public SessionDelegate(final SessionConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.VhostObject getVhostRef()
- {
- return (BrokerSchema.VhostObject) adapt(_obj.getVirtualHost());
- }
-
- public String getName()
- {
- return _obj.getSessionName();
- }
-
- public Integer getChannelId()
- {
- return _obj.getChannel();
- }
-
- public BrokerSchema.ConnectionObject getConnectionRef()
- {
- return (BrokerSchema.ConnectionObject) adapt(_obj.getConnectionConfig());
- }
-
- public Long getDetachedLifespan()
- {
- return _obj.getDetachedLifespan();
- }
-
- public Boolean getAttached()
- {
- return _obj.isAttached();
- }
-
- public Long getExpireTime()
- {
- return _obj.getExpiryTime();
- }
-
- public Long getMaxClientRate()
- {
- return _obj.getMaxClientRate();
- }
-
- public Long getFramesOutstanding()
- {
- // TODO
- return 0l;
- }
-
- public Long getUnackedMessages()
- {
- // TODO
- return 0l;
- }
-
- public Long getTxnStarts()
- {
- return _obj.getTxnStarts();
- }
-
- public Long getTxnCommits()
- {
- return _obj.getTxnCommits();
- }
-
- public Long getTxnRejects()
- {
- return _obj.getTxnRejects();
- }
-
- public Long getTxnCount()
- {
- return _obj.getTxnCount();
- }
-
- public Long getClientCredit()
- {
- // TODO
- return 0l;
- }
-
- public BrokerSchema.SessionClass.SolicitAckMethodResponseCommand solicitAck(final BrokerSchema.SessionClass.SolicitAckMethodResponseCommandFactory factory)
- {
- //TODO
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.SessionClass.DetachMethodResponseCommand detach(final BrokerSchema.SessionClass.DetachMethodResponseCommandFactory factory)
- {
- //TODO
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.SessionClass.ResetLifespanMethodResponseCommand resetLifespan(final BrokerSchema.SessionClass.ResetLifespanMethodResponseCommandFactory factory)
- {
- //TODO
- return factory.createResponseCommand(CompletionCode.NOT_IMPLEMENTED);
- }
-
- public BrokerSchema.SessionClass.CloseMethodResponseCommand close(final BrokerSchema.SessionClass.CloseMethodResponseCommandFactory factory)
- {
- try
- {
- _obj.mgmtClose();
- }
- catch (AMQException e)
- {
- return factory.createResponseCommand(CompletionCode.EXCEPTION, e.getMessage());
- }
-
- return factory.createResponseCommand();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class SubscriptionDelegate implements BrokerSchema.SubscriptionDelegate
- {
- private final SubscriptionConfig _obj;
-
- private SubscriptionDelegate(final SubscriptionConfig obj)
- {
- _obj = obj;
- }
-
-
- public BrokerSchema.SessionObject getSessionRef()
- {
- return (BrokerSchema.SessionObject) adapt(_obj.getSessionConfig());
- }
-
- public BrokerSchema.QueueObject getQueueRef()
- {
- return (BrokerSchema.QueueObject) adapt(_obj.getQueue());
- }
-
- public String getName()
- {
- return _obj.getName();
- }
-
- public Boolean getBrowsing()
- {
- return _obj.isBrowsing();
- }
-
- public Boolean getAcknowledged()
- {
- return _obj.isExplicitAcknowledge();
- }
-
- public Boolean getExclusive()
- {
- return _obj.isExclusive();
- }
-
- public String getCreditMode()
- {
- return _obj.getCreditMode();
- }
-
- public Map getArguments()
- {
- return _obj.getArguments();
- }
-
- public Long getDelivered()
- {
- return _obj.getDelivered();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class BridgeDelegate implements BrokerSchema.BridgeDelegate
- {
- private final BridgeConfig _obj;
-
- private BridgeDelegate(final BridgeConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.LinkObject getLinkRef()
- {
- return (BrokerSchema.LinkObject) adapt(_obj.getLink());
- }
-
- public Integer getChannelId()
- {
- return _obj.getChannelId();
- }
-
- public Boolean getDurable()
- {
- return _obj.isDurable();
- }
-
- public String getSrc()
- {
- return _obj.getSource();
- }
-
- public String getDest()
- {
- return _obj.getDestination();
- }
-
- public String getKey()
- {
- return _obj.getKey();
- }
-
- public Boolean getSrcIsQueue()
- {
- return _obj.isQueueBridge();
- }
-
- public Boolean getSrcIsLocal()
- {
- return _obj.isLocalSource();
- }
-
- public String getTag()
- {
- return _obj.getTag();
- }
-
- public String getExcludes()
- {
- return _obj.getExcludes();
- }
-
- public Boolean getDynamic()
- {
- return _obj.isDynamic();
- }
-
- public Integer getSync()
- {
- return _obj.getAckBatching();
- }
-
- /* support TBD */
- public String getName()
- {
- return null;
- }
-
- public BrokerSchema.BridgeClass.CloseMethodResponseCommand close(final BrokerSchema.BridgeClass.CloseMethodResponseCommandFactory factory)
- {
- return null;
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- public String toString()
- {
- return _obj.toString();
- }
- }
-
- private class LinkDelegate implements BrokerSchema.LinkDelegate
- {
- private final LinkConfig _obj;
-
- private LinkDelegate(final LinkConfig obj)
- {
- _obj = obj;
- }
-
- public BrokerSchema.VhostObject getVhostRef()
- {
- return (BrokerSchema.VhostObject) adapt(_obj.getVirtualHost());
- }
-
- public String getHost()
- {
- return _obj.getHost();
- }
-
- public Integer getPort()
- {
- return _obj.getPort();
- }
-
- public String getTransport()
- {
- return _obj.getTransport();
- }
-
- public Boolean getDurable()
- {
- return _obj.isDurable();
- }
-
- public String getState()
- {
- return _obj.getState();
- }
-
- public String getLastError()
- {
- return _obj.getLastError();
- }
-
- /* support TBD */
- public String getName()
- {
- return null;
- }
-
- /* support TBD */
- public BrokerSchema.ConnectionObject getConnectionRef()
- {
- return (BrokerSchema.ConnectionObject) null;
- }
-
- public BrokerSchema.LinkClass.CloseMethodResponseCommand close(final BrokerSchema.LinkClass.CloseMethodResponseCommandFactory factory)
- {
- _obj.close();
- return factory.createResponseCommand();
- }
-
- public BrokerSchema.LinkClass.BridgeMethodResponseCommand bridge(final BrokerSchema.LinkClass.BridgeMethodResponseCommandFactory factory,
- final Boolean durable,
- final String src,
- final String dest,
- final String key,
- final String tag,
- final String excludes,
- final Boolean srcIsQueue,
- final Boolean srcIsLocal,
- final Boolean dynamic,
- final Integer sync)
- {
- _obj.createBridge(durable, dynamic, srcIsQueue, srcIsLocal, src, dest, key, tag, excludes);
- return factory.createResponseCommand();
- }
-
- public UUID getQMFId()
- {
- return _obj.getQMFId();
- }
-
- public long getCreateTime()
- {
- return _obj.getCreateTime();
- }
-
- @Override
- public String toString()
- {
- return _obj.toString();
- }
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFStatistic.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFStatistic.java
deleted file mode 100644
index 89d650e03b..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFStatistic.java
+++ /dev/null
@@ -1,61 +0,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.
- *
- */
-
-package org.apache.qpid.qmf;
-
-import org.apache.qpid.transport.codec.Encoder;
-
-import java.util.LinkedHashMap;
-
-public class QMFStatistic
-{
- private final LinkedHashMap<String,Object> _map = new LinkedHashMap<String,Object>();
- private static final String NAME = "name";
- private static final String TYPE = "type";
- private static final String UNIT = "unit";
- private static final String DESCRIPTION = "desc";
-
-
- public QMFStatistic(String name, QMFType type, String unit, String description)
- {
- _map.put(NAME, name);
- _map.put(TYPE, type.codeValue());
- if(unit != null)
- {
- _map.put(UNIT, unit);
- }
- if(description != null)
- {
- _map.put(DESCRIPTION, description);
- }
-
- }
-
- public void encode(Encoder encoder)
- {
- encoder.writeMap(_map);
- }
-
- public String getName()
- {
- return (String) _map.get(NAME);
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/qmf/QMFType.java b/java/broker/src/main/java/org/apache/qpid/qmf/QMFType.java
deleted file mode 100644
index 0e01c27db5..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/qmf/QMFType.java
+++ /dev/null
@@ -1,53 +0,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.
- *
- */
-package org.apache.qpid.qmf;
-
-public enum QMFType
-{
-
- UINT8,
- UINT16,
- UINT32,
- UINT64,
- UNKNOWN,
- STR8,
- STR16,
- ABSTIME,
- DELTATIME,
- OBJECTREFERENCE,
- BOOLEAN,
- FLOAT,
- DOUBLE,
- UUID,
- MAP,
- INT8,
- INT16,
- INT32,
- INT64,
- OBJECT,
- LIST,
- ARRAY;
-
- public int codeValue()
- {
- return ordinal()+1;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java b/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
index e197dddfde..ab4ca81d05 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
@@ -51,13 +51,10 @@ import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.framing.abstraction.ContentChunk;
import org.apache.qpid.framing.abstraction.MessagePublishInfo;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.server.TransactionTimeoutHelper.CloseAction;
import org.apache.qpid.server.ack.UnacknowledgedMessageMap;
import org.apache.qpid.server.ack.UnacknowledgedMessageMapImpl;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.ConnectionConfig;
-import org.apache.qpid.server.configuration.SessionConfig;
-import org.apache.qpid.server.configuration.SessionConfigType;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.flow.FlowCreditManager;
import org.apache.qpid.server.flow.Pre0_10CreditManager;
@@ -75,7 +72,6 @@ import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.server.message.ServerMessage;
import org.apache.qpid.server.output.ProtocolOutputConverter;
import org.apache.qpid.server.protocol.AMQConnectionModel;
-import org.apache.qpid.server.protocol.AMQProtocolEngine;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.queue.AMQQueue;
@@ -83,7 +79,6 @@ import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.InboundMessageAdapter;
import org.apache.qpid.server.queue.IncomingMessage;
import org.apache.qpid.server.queue.QueueEntry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.store.StoreFuture;
import org.apache.qpid.server.store.StoredMessage;
@@ -93,19 +88,19 @@ import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.subscription.SubscriptionFactoryImpl;
import org.apache.qpid.server.txn.AsyncAutoCommitTransaction;
import org.apache.qpid.server.txn.LocalTransaction;
+import org.apache.qpid.server.txn.LocalTransaction.ActivityTimeAccessor;
import org.apache.qpid.server.txn.ServerTransaction;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.TransportException;
-public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoCommitTransaction.FutureRecorder
+public class AMQChannel implements AMQSessionModel, AsyncAutoCommitTransaction.FutureRecorder
{
public static final int DEFAULT_PREFETCH = 4096;
private static final Logger _logger = Logger.getLogger(AMQChannel.class);
- private static final boolean MSG_AUTH =
- ApplicationRegistry.getInstance().getConfiguration().getMsgAuth();
-
+ //TODO use Broker property to configure message authorization requirements
+ private boolean _messageAuthorizationRequired = Boolean.getBoolean(BrokerProperties.PROPERTY_MSG_AUTH);
private final int _channelId;
@@ -118,7 +113,7 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
*/
private long _deliveryTag = 0;
- /** A channel has a default queue (the last declared) that is used when no queue name is explictily set */
+ /** A channel has a default queue (the last declared) that is used when no queue name is explicitly set */
private AMQQueue _defaultQueue;
/** This tag is unique per subscription to a queue. The server returns this in response to a basic.consume request. */
@@ -151,7 +146,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
private final AtomicLong _txnCommits = new AtomicLong(0);
private final AtomicLong _txnRejects = new AtomicLong(0);
private final AtomicLong _txnCount = new AtomicLong(0);
- private final AtomicLong _txnUpdateTime = new AtomicLong(0);
private final AMQProtocolSession _session;
private AtomicBoolean _closing = new AtomicBoolean(false);
@@ -169,12 +163,12 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
private List<QueueEntry> _resendList = new ArrayList<QueueEntry>();
private static final
AMQShortString IMMEDIATE_DELIVERY_REPLY_TEXT = new AMQShortString("Immediate delivery is not possible.");
- private final UUID _qmfId;
private long _createTime = System.currentTimeMillis();
private final ClientDeliveryMethod _clientDeliveryMethod;
private final TransactionTimeoutHelper _transactionTimeoutHelper;
+ private final UUID _id = UUID.randomUUID();
public AMQChannel(AMQProtocolSession session, int channelId, MessageStore messageStore)
throws AMQException
@@ -184,30 +178,36 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
_actor = new AMQPChannelActor(this, session.getLogActor().getRootMessageLogger());
_logSubject = new ChannelLogSubject(this);
- _qmfId = getConfigStore().createId();
_actor.message(ChannelMessages.CREATE());
- getConfigStore().addConfiguredObject(this);
-
_messageStore = messageStore;
// by default the session is non-transactional
_transaction = new AsyncAutoCommitTransaction(_messageStore, this);
- _clientDeliveryMethod = session.createDeliveryMethod(_channelId);
-
- _transactionTimeoutHelper = new TransactionTimeoutHelper(_logSubject);
- }
+ _clientDeliveryMethod = session.createDeliveryMethod(_channelId);
- public ConfigStore getConfigStore()
- {
- return getVirtualHost().getConfigStore();
+ _transactionTimeoutHelper = new TransactionTimeoutHelper(_logSubject, new CloseAction()
+ {
+ @Override
+ public void doTimeoutAction(String reason) throws AMQException
+ {
+ closeConnection(reason);
+ }
+ });
}
/** Sets this channel to be part of a local transaction */
public void setLocalTransactional()
{
- _transaction = new LocalTransaction(_messageStore);
+ _transaction = new LocalTransaction(_messageStore, new ActivityTimeAccessor()
+ {
+ @Override
+ public long getActivityTime()
+ {
+ return _session.getLastReceivedTime();
+ }
+ });
_txnStarts.incrementAndGet();
}
@@ -221,12 +221,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
sync();
}
-
- public boolean inTransaction()
- {
- return isTransactional() && _txnUpdateTime.get() > 0 && _transaction.getTransactionStartTime() > 0;
- }
-
private void incrementOutstandingTxnsIfNecessary()
{
if(isTransactional())
@@ -247,11 +241,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
}
}
- public Long getTxnStarts()
- {
- return _txnStarts.get();
- }
-
public Long getTxnCommits()
{
return _txnCommits.get();
@@ -369,9 +358,8 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
}
});
- _transaction.enqueue(destinationQueues, _currentMessage, new MessageDeliveryAction(_currentMessage, destinationQueues), getProtocolSession().getLastReceivedTime());
+ _transaction.enqueue(destinationQueues, _currentMessage, new MessageDeliveryAction(_currentMessage, destinationQueues));
incrementOutstandingTxnsIfNecessary();
- updateTransactionalActivity();
_currentMessage.getStoredMessage().flushToStore();
}
}
@@ -396,7 +384,7 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
if (_logger.isDebugEnabled())
{
- _logger.debug(debugIdentity() + "Content body received on channel " + _channelId);
+ _logger.debug(debugIdentity() + " content body received on channel " + _channelId);
}
try
@@ -556,9 +544,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
{
_logger.error("Caught TransportException whilst attempting to requeue:" + e);
}
-
- getConfigStore().removeConfiguredObject(this);
-
}
private void unsubscribeAllConsumers() throws AMQException
@@ -860,7 +845,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
{
Collection<QueueEntry> ackedMessages = getAckedMessages(deliveryTag, multiple);
_transaction.dequeue(ackedMessages, new MessageAcknowledgeAction(ackedMessages));
- updateTransactionalActivity();
}
private Collection<QueueEntry> getAckedMessages(long deliveryTag, boolean multiple)
@@ -1054,19 +1038,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
}
}
-
-
- }
-
- /**
- * Update last transaction activity timestamp
- */
- private void updateTransactionalActivity()
- {
- if (isTransactional())
- {
- _txnUpdateTime.set(getProtocolSession().getLastReceivedTime());
- }
}
public String toString()
@@ -1149,10 +1120,16 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
? ((BasicContentHeaderProperties) header.getProperties()).getUserId()
: null;
- return (!MSG_AUTH || _session.getAuthorizedPrincipal().getName().equals(userID == null? "" : userID.toString()));
+ return (!_messageAuthorizationRequired || _session.getAuthorizedPrincipal().getName().equals(userID == null? "" : userID.toString()));
}
+ @Override
+ public UUID getId()
+ {
+ return _id;
+ }
+
public AMQConnectionModel getConnectionModel()
{
return _session;
@@ -1168,6 +1145,12 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
return _logSubject;
}
+ @Override
+ public int compareTo(AMQSessionModel o)
+ {
+ return getId().compareTo(o.getId());
+ }
+
private class MessageDeliveryAction implements ServerTransaction.Action
{
private IncomingMessage _incommingMessage;
@@ -1221,11 +1204,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
// TODO
throw new RuntimeException(e);
}
-
-
-
-
-
}
public void onRollback()
@@ -1375,7 +1353,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
public void onRollback()
{
- //To change body of implemented methods use File | Settings | File Templates.
}
}
@@ -1469,97 +1446,24 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
return getProtocolSession().getVirtualHost();
}
-
- public ConfiguredObject getParent()
- {
- return getVirtualHost();
- }
-
- public SessionConfigType getConfigType()
- {
- return SessionConfigType.getInstance();
- }
-
public int getChannel()
{
return getChannelId();
}
- public boolean isAttached()
- {
- return true;
- }
-
- public long getDetachedLifespan()
- {
- return 0;
- }
-
- public ConnectionConfig getConnectionConfig()
- {
- return (AMQProtocolEngine)getProtocolSession();
- }
-
- public Long getExpiryTime()
- {
- return null;
- }
-
- public Long getMaxClientRate()
- {
- return null;
- }
-
public boolean isDurable()
{
return false;
}
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public String getSessionName()
- {
- return getConnectionConfig().getAddress() + "/" + getChannelId();
- }
-
public long getCreateTime()
{
return _createTime;
}
- public void mgmtClose() throws AMQException
- {
- _session.mgmtCloseChannel(_channelId);
- }
-
public void checkTransactionStatus(long openWarn, long openClose, long idleWarn, long idleClose) throws AMQException
{
- if (inTransaction())
- {
- long currentTime = System.currentTimeMillis();
- long openTime = currentTime - _transaction.getTransactionStartTime();
- long idleTime = currentTime - _txnUpdateTime.get();
-
- _transactionTimeoutHelper.logIfNecessary(idleTime, idleWarn, ChannelMessages.IDLE_TXN(idleTime),
- TransactionTimeoutHelper.IDLE_TRANSACTION_ALERT);
- if (_transactionTimeoutHelper.isTimedOut(idleTime, idleClose))
- {
- closeConnection("Idle transaction timed out");
- return;
- }
-
- _transactionTimeoutHelper.logIfNecessary(openTime, openWarn, ChannelMessages.OPEN_TXN(openTime),
- TransactionTimeoutHelper.OPEN_TRANSACTION_ALERT);
- if (_transactionTimeoutHelper.isTimedOut(openTime, openClose))
- {
- closeConnection("Open transaction timed out");
- return;
- }
- }
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, openWarn, openClose, idleWarn, idleClose);
}
/**
@@ -1637,6 +1541,11 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
public void sync()
{
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("sync() called on channel " + debugIdentity());
+ }
+
AsyncCommand cmd;
while((cmd = _unfinishedCommandsQueue.poll()) != null)
{
@@ -1674,16 +1583,6 @@ public class AMQChannel implements SessionConfig, AMQSessionModel, AsyncAutoComm
_action.postCommit();
_action = null;
}
-
- boolean isReadyForCompletion()
- {
- return _future.isComplete();
- }
- }
-
- public int compareTo(AMQSessionModel session)
- {
- return getQMFId().compareTo(session.getQMFId());
}
@Override
diff --git a/java/broker/src/main/java/org/apache/qpid/server/Broker.java b/java/broker/src/main/java/org/apache/qpid/server/Broker.java
index d58a0d5bb4..54dcf0543d 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/Broker.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/Broker.java
@@ -23,37 +23,31 @@ package org.apache.qpid.server;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.util.*;
-import javax.net.ssl.SSLContext;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.ServerNetworkTransportConfiguration;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator;
+import org.apache.qpid.server.configuration.store.ManagementModeStoreHandler;
import org.apache.qpid.server.logging.SystemOutMessageLogger;
import org.apache.qpid.server.logging.actors.BrokerActor;
import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.GenericActor;
-import org.apache.qpid.server.logging.log4j.LoggingFacade;
+import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
import org.apache.qpid.server.logging.messages.BrokerMessages;
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory;
import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry;
-import org.apache.qpid.server.transport.QpidAcceptor;
-import org.apache.qpid.ssl.SSLContextFactory;
-import org.apache.qpid.transport.NetworkTransportConfiguration;
-import org.apache.qpid.transport.network.IncomingNetworkTransport;
-import org.apache.qpid.transport.network.Transport;
-
-import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
+import org.apache.qpid.server.registry.IApplicationRegistry;
public class Broker
{
private static final Logger LOGGER = Logger.getLogger(Broker.class);
private volatile Thread _shutdownHookThread;
+ private volatile IApplicationRegistry _applicationRegistry;
protected static class InitException extends RuntimeException
{
@@ -73,7 +67,17 @@ public class Broker
}
finally
{
- ApplicationRegistry.remove();
+ try
+ {
+ if (_applicationRegistry != null)
+ {
+ _applicationRegistry.close();
+ }
+ }
+ finally
+ {
+ clearAMQShortStringCache();
+ }
}
}
@@ -84,274 +88,76 @@ public class Broker
public void startup(final BrokerOptions options) throws Exception
{
+ CurrentActor.set(new BrokerActor(new SystemOutMessageLogger()));
try
{
- CurrentActor.set(new BrokerActor(new SystemOutMessageLogger()));
startupImpl(options);
addShutdownHook();
}
finally
{
- CurrentActor.remove();
+ try
+ {
+ CurrentActor.remove();
+ }
+ finally
+ {
+ clearAMQShortStringCache();
+ }
}
}
private void startupImpl(final BrokerOptions options) throws Exception
{
- final String qpidHome = options.getQpidHome();
- final File configFile = getConfigFile(options.getConfigFile(),
- BrokerOptions.DEFAULT_CONFIG_FILE, qpidHome, true);
-
- CurrentActor.get().message(BrokerMessages.CONFIG(configFile.getAbsolutePath()));
-
- File logConfigFile = getConfigFile(options.getLogConfigFile(),
- BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false);
-
- configureLogging(logConfigFile, options.getLogWatchFrequency());
+ final String qpidHome = System.getProperty(BrokerProperties.PROPERTY_QPID_HOME);
+ String storeLocation = options.getConfigurationStoreLocation();
+ String storeType = options.getConfigurationStoreType();
- ConfigurationFileApplicationRegistry config = new ConfigurationFileApplicationRegistry(configFile, options.getBundleContext());
- ServerConfiguration serverConfig = config.getConfiguration();
- if (options.getQpidWork() != null)
+ if (storeLocation == null)
{
- serverConfig.setQpidWork(options.getQpidWork());
- }
- if (options.getQpidHome() != null)
- {
- serverConfig.setQpidHome(options.getQpidHome());
- }
- updateManagementPorts(serverConfig, options.getJmxPortRegistryServer(), options.getJmxPortConnectorServer());
-
- ApplicationRegistry.initialise(config);
-
- // We have already loaded the BrokerMessages class by this point so we
- // need to refresh the locale setting incase we had a different value in
- // the configuration.
- BrokerMessages.reload();
-
- // AR.initialise() sets and removes its own actor so we now need to set the actor
- // for the remainder of the startup, and the default actor if the stack is empty
- CurrentActor.set(new BrokerActor(config.getCompositeStartupMessageLogger()));
- CurrentActor.setDefault(new BrokerActor(config.getRootMessageLogger()));
- GenericActor.setDefaultMessageLogger(config.getRootMessageLogger());
-
- try
- {
- Set<Integer> ports = new HashSet<Integer>(options.getPorts());
- if(ports.isEmpty())
- {
- parsePortList(ports, serverConfig.getPorts());
- }
-
- Set<Integer> sslPorts = new HashSet<Integer>(options.getSSLPorts());
- if(sslPorts.isEmpty())
- {
- parsePortList(sslPorts, serverConfig.getSSLPorts());
- }
-
- //1-0 excludes and includes
- Set<Integer> exclude_1_0 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v1_0));
- if(exclude_1_0.isEmpty())
- {
- parsePortList(exclude_1_0, serverConfig.getPortExclude10());
- }
-
- Set<Integer> include_1_0 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v1_0));
- if(include_1_0.isEmpty())
- {
- parsePortList(include_1_0, serverConfig.getPortInclude10());
- }
-
- //0-10 excludes and includes
- Set<Integer> exclude_0_10 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_10));
- if(exclude_0_10.isEmpty())
- {
- parsePortList(exclude_0_10, serverConfig.getPortExclude010());
- }
-
- Set<Integer> include_0_10 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_10));
- if(include_0_10.isEmpty())
- {
- parsePortList(include_0_10, serverConfig.getPortInclude010());
- }
-
- //0-9-1 excludes and includes
- Set<Integer> exclude_0_9_1 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_9_1));
- if(exclude_0_9_1.isEmpty())
- {
- parsePortList(exclude_0_9_1, serverConfig.getPortExclude091());
- }
-
- Set<Integer> include_0_9_1 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_9_1));
- if(include_0_9_1.isEmpty())
- {
- parsePortList(include_0_9_1, serverConfig.getPortInclude091());
- }
-
- //0-9 excludes and includes
- Set<Integer> exclude_0_9 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_9));
- if(exclude_0_9.isEmpty())
- {
- parsePortList(exclude_0_9, serverConfig.getPortExclude09());
- }
-
- Set<Integer> include_0_9 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_9));
- if(include_0_9.isEmpty())
- {
- parsePortList(include_0_9, serverConfig.getPortInclude09());
- }
-
- //0-8 excludes and includes
- Set<Integer> exclude_0_8 = new HashSet<Integer>(options.getExcludedPorts(ProtocolExclusion.v0_8));
- if(exclude_0_8.isEmpty())
- {
- parsePortList(exclude_0_8, serverConfig.getPortExclude08());
- }
-
- Set<Integer> include_0_8 = new HashSet<Integer>(options.getIncludedPorts(ProtocolInclusion.v0_8));
- if(include_0_8.isEmpty())
- {
- parsePortList(include_0_8, serverConfig.getPortInclude08());
- }
-
- String bindAddr = options.getBind();
- if (bindAddr == null)
- {
- bindAddr = serverConfig.getBind();
- }
-
- InetAddress bindAddress;
- if (bindAddr.equals(WILDCARD_ADDRESS))
- {
- bindAddress = null;
- }
- else
- {
- bindAddress = InetAddress.getByName(bindAddr);
- }
-
- final AmqpProtocolVersion defaultSupportedProtocolReply = serverConfig.getDefaultSupportedProtocolReply();
-
- if (!serverConfig.getSSLOnly())
- {
- for(int port : ports)
- {
- final InetSocketAddress inetSocketAddress = new InetSocketAddress(bindAddress, port);
-
- final Set<AmqpProtocolVersion> supported =
- getSupportedVersions(port, exclude_1_0, exclude_0_10, exclude_0_9_1, exclude_0_9, exclude_0_8,
- include_1_0, include_0_10, include_0_9_1, include_0_9, include_0_8,serverConfig);
-
- final NetworkTransportConfiguration settings =
- new ServerNetworkTransportConfiguration(serverConfig, inetSocketAddress, Transport.TCP);
-
- final IncomingNetworkTransport transport = Transport.getIncomingTransportInstance();
- final MultiVersionProtocolEngineFactory protocolEngineFactory =
- new MultiVersionProtocolEngineFactory(supported, defaultSupportedProtocolReply);
-
- transport.accept(settings, protocolEngineFactory, null);
-
- ApplicationRegistry.getInstance().addAcceptor(inetSocketAddress,
- new QpidAcceptor(transport,QpidAcceptor.Transport.TCP, supported));
- CurrentActor.get().message(BrokerMessages.LISTENING("TCP", port));
- }
- }
-
- if (serverConfig.getEnableSSL())
+ String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK);
+ if (qpidWork == null)
{
- final String keystorePath = serverConfig.getConnectorKeyStorePath();
- final String keystorePassword = serverConfig.getConnectorKeyStorePassword();
- final String keystoreType = serverConfig.getConnectorKeyStoreType();
- final String keyManagerFactoryAlgorithm = serverConfig.getConnectorKeyManagerFactoryAlgorithm();
- final SSLContext sslContext;
- if(serverConfig.getConnectorTrustStorePath()!=null)
- {
- sslContext = SSLContextFactory.buildClientContext(serverConfig.getConnectorTrustStorePath(),
- serverConfig.getConnectorTrustStorePassword(),
- serverConfig.getConnectorTrustStoreType(),
- serverConfig.getConnectorTrustManagerFactoryAlgorithm(),
- keystorePath,
- keystorePassword, keystoreType, keyManagerFactoryAlgorithm,
- serverConfig.getCertAlias());
- }
- else
- {
- sslContext = SSLContextFactory.buildServerContext(keystorePath, keystorePassword, keystoreType, keyManagerFactoryAlgorithm);
- }
-
- for(int sslPort : sslPorts)
- {
- final InetSocketAddress inetSocketAddress = new InetSocketAddress(bindAddress, sslPort);
-
- final Set<AmqpProtocolVersion> supported =
- getSupportedVersions(sslPort, exclude_1_0, exclude_0_10, exclude_0_9_1, exclude_0_9, exclude_0_8,
- include_1_0, include_0_10, include_0_9_1, include_0_9, include_0_8, serverConfig);
- final NetworkTransportConfiguration settings =
- new ServerNetworkTransportConfiguration(serverConfig, inetSocketAddress, Transport.TCP);
-
- final IncomingNetworkTransport transport = Transport.getIncomingTransportInstance();
- final MultiVersionProtocolEngineFactory protocolEngineFactory =
- new MultiVersionProtocolEngineFactory(supported, defaultSupportedProtocolReply);
-
- transport.accept(settings, protocolEngineFactory, sslContext);
-
- ApplicationRegistry.getInstance().addAcceptor(inetSocketAddress,
- new QpidAcceptor(transport,QpidAcceptor.Transport.SSL, supported));
- CurrentActor.get().message(BrokerMessages.LISTENING("TCP/SSL", sslPort));
- }
+ qpidWork = new File(System.getProperty("user.dir"), "work").getAbsolutePath();
}
-
- CurrentActor.get().message(BrokerMessages.READY());
- }
- finally
- {
- // Startup is complete so remove the AR initialised Startup actor
- CurrentActor.remove();
+ storeLocation = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_FILE + "." + storeType).getAbsolutePath();
}
- }
- private static Set<AmqpProtocolVersion> getSupportedVersions(final int port,
- final Set<Integer> exclude_1_0,
- final Set<Integer> exclude_0_10,
- final Set<Integer> exclude_0_9_1,
- final Set<Integer> exclude_0_9,
- final Set<Integer> exclude_0_8,
- final Set<Integer> include_1_0,
- final Set<Integer> include_0_10,
- final Set<Integer> include_0_9_1,
- final Set<Integer> include_0_9,
- final Set<Integer> include_0_8,
- final ServerConfiguration serverConfig)
- {
- final EnumSet<AmqpProtocolVersion> supported = EnumSet.allOf(AmqpProtocolVersion.class);
+ CurrentActor.get().message(BrokerMessages.CONFIG(storeLocation));
- if((exclude_1_0.contains(port) || !serverConfig.isAmqp10enabled()) && !include_1_0.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v1_0_0);
- }
+ File logConfigFile = getConfigFile(options.getLogConfigFile(), BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false);
+ configureLogging(logConfigFile, options.getLogWatchFrequency());
- if((exclude_0_10.contains(port) || !serverConfig.isAmqp010enabled()) && !include_0_10.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_10);
- }
+ BrokerConfigurationStoreCreator storeCreator = new BrokerConfigurationStoreCreator();
+ ConfigurationEntryStore store = storeCreator.createStore(storeLocation, storeType,
+ options.getInitialConfigurationStoreLocation(), options.getInitialConfigurationStoreLocation());
- if((exclude_0_9_1.contains(port) || !serverConfig.isAmqp091enabled()) && !include_0_9_1.contains(port))
+ if (options.isManagementMode())
{
- supported.remove(AmqpProtocolVersion.v0_9_1);
+ store = new ManagementModeStoreHandler(store, options);
}
- if((exclude_0_9.contains(port) || !serverConfig.isAmqp09enabled()) && !include_0_9.contains(port))
+ _applicationRegistry = new ApplicationRegistry(store);
+ try
{
- supported.remove(AmqpProtocolVersion.v0_9);
+ _applicationRegistry.initialise();
}
-
- if((exclude_0_8.contains(port) || !serverConfig.isAmqp08enabled()) && !include_0_8.contains(port))
+ catch(Exception e)
{
- supported.remove(AmqpProtocolVersion.v0_8);
+ try
+ {
+ _applicationRegistry.close();
+ }
+ catch(Exception ce)
+ {
+ LOGGER.debug("An error occured when closing the registry following initialization failure", ce);
+ }
+ throw e;
}
- return supported;
}
+
private File getConfigFile(final String fileName,
final String defaultFileName,
final String qpidHome, boolean throwOnFileNotFound) throws InitException
@@ -368,11 +174,11 @@ public class Broker
if (!configFile.exists() && throwOnFileNotFound)
{
- String error = "File " + fileName + " could not be found. Check the file exists and is readable.";
+ String error = "File " + configFile + " could not be found. Check the file exists and is readable.";
if (qpidHome == null)
{
- error = error + "\nNote: " + BrokerOptions.QPID_HOME + " is not set.";
+ error = error + "\nNote: " + BrokerProperties.PROPERTY_QPID_HOME + " is not set.";
}
throw new InitException(error, null);
@@ -399,37 +205,6 @@ public class Broker
}
}
- /**
- * Update the configuration data with the management port.
- * @param configuration
- * @param registryServerPort The string from the command line
- */
- private void updateManagementPorts(ServerConfiguration configuration, Integer registryServerPort, Integer connectorServerPort)
- {
- if (registryServerPort != null)
- {
- try
- {
- configuration.setJMXPortRegistryServer(registryServerPort);
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid management (registry server) port: " + registryServerPort, null);
- }
- }
- if (connectorServerPort != null)
- {
- try
- {
- configuration.setJMXPortConnectorServer(connectorServerPort);
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid management (connector server) port: " + connectorServerPort, null);
- }
- }
- }
-
private void configureLogging(File logConfigFile, int logWatchTime) throws InitException, IOException
{
if (logConfigFile.exists() && logConfigFile.canRead())
@@ -443,7 +218,7 @@ public class Broker
// log4j expects the watch interval in milliseconds
try
{
- LoggingFacade.configureAndWatch(logConfigFile.getPath(), logWatchTime * 1000);
+ LoggingManagementFacade.configureAndWatch(logConfigFile.getPath(), logWatchTime * 1000);
}
catch (Exception e)
{
@@ -454,7 +229,7 @@ public class Broker
{
try
{
- LoggingFacade.configure(logConfigFile.getPath());
+ LoggingManagementFacade.configure(logConfigFile.getPath());
}
catch (Exception e)
{
@@ -531,6 +306,24 @@ public class Broker
LOGGER.debug("Skipping shutdown hook removal as there either isnt one, or we are it.");
}
}
+ /**
+ * Workaround that prevents AMQShortStrings cache from being left in the thread local. This is important
+ * when embedding the Broker in containers where the starting thread may not belong to Qpid.
+ * The long term solution here is to stop our use of AMQShortString outside the AMQP transport layer.
+ */
+ private void clearAMQShortStringCache()
+ {
+ AMQShortString.clearLocalCache();
+ }
+
+ public org.apache.qpid.server.model.Broker getBroker()
+ {
+ if (_applicationRegistry == null)
+ {
+ return null;
+ }
+ return _applicationRegistry.getBroker();
+ }
private class ShutdownService implements Runnable
{
@@ -540,4 +333,5 @@ public class Broker
Broker.this.shutdown();
}
}
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java b/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
index 434d40d557..57e401e608 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
@@ -20,66 +20,25 @@
*/
package org.apache.qpid.server;
-import org.osgi.framework.BundleContext;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
public class BrokerOptions
{
- public static final String DEFAULT_CONFIG_FILE = "etc/config.xml";
+ public static final String DEFAULT_STORE_TYPE = "json";
+ public static final String DEFAULT_CONFIG_FILE = "config";
public static final String DEFAULT_LOG_CONFIG_FILE = "etc/log4j.xml";
- public static final String QPID_HOME = "QPID_HOME";
- public static final String QPID_WORK = "QPID_WORK";
-
- private final Set<Integer> _ports = new HashSet<Integer>();
- private final Set<Integer> _sslPorts = new HashSet<Integer>();
- private final Map<ProtocolExclusion,Set<Integer>> _exclusionMap = new HashMap<ProtocolExclusion, Set<Integer>>();
- private final Map<ProtocolInclusion,Set<Integer>> _inclusionMap = new HashMap<ProtocolInclusion, Set<Integer>>();
- private String _configFile;
private String _logConfigFile;
- private String _bind;
- private Integer _jmxPortRegistryServer;
- private Integer _jmxPortConnectorServer;
- private BundleContext _bundleContext;
-
private Integer _logWatchFrequency = 0;
- private String _qpidWorkFolder;
- private String _qpidHomeFolder;
- public void addPort(final int port)
- {
- _ports.add(port);
- }
+ private String _configurationStoreLocation;
+ private String _configurationStoreType = DEFAULT_STORE_TYPE;
- public void addSSLPort(final int sslPort)
- {
- _sslPorts.add(sslPort);
- }
+ private String _initialConfigurationStoreLocation;
+ private String _initialConfigurationStoreType = DEFAULT_STORE_TYPE;
- public Set<Integer> getPorts()
- {
- return Collections.unmodifiableSet(_ports);
- }
-
- public Set<Integer> getSSLPorts()
- {
- return Collections.unmodifiableSet(_sslPorts);
- }
-
- public String getConfigFile()
- {
- return _configFile;
- }
-
- public void setConfigFile(final String configFile)
- {
- _configFile = configFile;
- }
+ private boolean _managementMode;
+ private int _managementModeRmiPort;
+ private int _managementModeConnectorPort;
+ private int _managementModeHttpPort;
public String getLogConfigFile()
{
@@ -91,110 +50,97 @@ public class BrokerOptions
_logConfigFile = logConfigFile;
}
- public Integer getJmxPortRegistryServer()
+ public int getLogWatchFrequency()
{
- return _jmxPortRegistryServer;
+ return _logWatchFrequency;
}
- public void setJmxPortRegistryServer(final int jmxPortRegistryServer)
+ /**
+ * Set the frequency with which the log config file will be checked for updates.
+ * @param logWatchFrequency frequency in seconds
+ */
+ public void setLogWatchFrequency(final int logWatchFrequency)
{
- _jmxPortRegistryServer = jmxPortRegistryServer;
+ _logWatchFrequency = logWatchFrequency;
}
- public Integer getJmxPortConnectorServer()
+ public String getConfigurationStoreLocation()
{
- return _jmxPortConnectorServer;
+ return _configurationStoreLocation;
}
- public void setJmxPortConnectorServer(final int jmxPortConnectorServer)
+ public void setConfigurationStoreLocation(String cofigurationStore)
{
- _jmxPortConnectorServer = jmxPortConnectorServer;
+ _configurationStoreLocation = cofigurationStore;
}
- public String getQpidHome()
+
+ public String getConfigurationStoreType()
{
- return _qpidHomeFolder == null? System.getProperty(QPID_HOME): _qpidHomeFolder;
+ return _configurationStoreType;
}
- public Set<Integer> getExcludedPorts(final ProtocolExclusion excludeProtocol)
+ public void setConfigurationStoreType(String cofigurationStoreType)
{
- final Set<Integer> excludedPorts = _exclusionMap.get(excludeProtocol);
- return excludedPorts == null ? Collections.<Integer>emptySet() : excludedPorts;
+ _configurationStoreType = cofigurationStoreType;
}
- public void addExcludedPort(final ProtocolExclusion excludeProtocol, final int port)
+ public void setInitialConfigurationStoreLocation(String initialConfigurationStore)
{
- if (!_exclusionMap.containsKey(excludeProtocol))
- {
- _exclusionMap.put(excludeProtocol, new HashSet<Integer>());
- }
-
- Set<Integer> ports = _exclusionMap.get(excludeProtocol);
- ports.add(port);
+ _initialConfigurationStoreLocation = initialConfigurationStore;
}
- public String getBind()
+ public void setInitialConfigurationStoreType(String initialConfigurationStoreType)
{
- return _bind;
+ _initialConfigurationStoreType = initialConfigurationStoreType;
}
- public void setBind(final String bind)
+ public String getInitialConfigurationStoreLocation()
{
- _bind = bind;
+ return _initialConfigurationStoreLocation;
}
- public int getLogWatchFrequency()
+ public String getInitialConfigurationStoreType()
{
- return _logWatchFrequency;
+ return _initialConfigurationStoreType;
}
- /**
- * Set the frequency with which the log config file will be checked for updates.
- * @param logWatchFrequency frequency in seconds
- */
- public void setLogWatchFrequency(final int logWatchFrequency)
+ public boolean isManagementMode()
{
- _logWatchFrequency = logWatchFrequency;
+ return _managementMode;
}
- public BundleContext getBundleContext()
+ public void setManagementMode(boolean managementMode)
{
- return _bundleContext ;
+ _managementMode = managementMode;
}
- public void setBundleContext(final BundleContext bundleContext)
+ public int getManagementModeRmiPort()
{
- _bundleContext = bundleContext;
+ return _managementModeRmiPort;
}
- public Set<Integer> getIncludedPorts(final ProtocolInclusion includeProtocol)
+ public void setManagementModeRmiPort(int managementModeRmiPort)
{
- final Set<Integer> includedPorts = _inclusionMap.get(includeProtocol);
- return includedPorts == null ? Collections.<Integer>emptySet() : includedPorts;
+ _managementModeRmiPort = managementModeRmiPort;
}
- public void addIncludedPort(final ProtocolInclusion includeProtocol, final int port)
+ public int getManagementModeConnectorPort()
{
- if (!_inclusionMap.containsKey(includeProtocol))
- {
- _inclusionMap.put(includeProtocol, new HashSet<Integer>());
- }
-
- Set<Integer> ports = _inclusionMap.get(includeProtocol);
- ports.add(port);
+ return _managementModeConnectorPort;
}
- public String getQpidWork()
+ public void setManagementModeConnectorPort(int managementModeConnectorPort)
{
- return _qpidWorkFolder;
+ _managementModeConnectorPort = managementModeConnectorPort;
}
- public void setQpidWork(String qpidWorkFolder)
+ public int getManagementModeHttpPort()
{
- _qpidWorkFolder = qpidWorkFolder;
+ return _managementModeHttpPort;
}
- public void setQpidHome(String qpidHomeFolder)
+ public void setManagementModeHttpPort(int managementModeHttpPort)
{
- _qpidHomeFolder = qpidHomeFolder;
+ _managementModeHttpPort = managementModeHttpPort;
}
} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/Main.java b/java/broker/src/main/java/org/apache/qpid/server/Main.java
index 9fe7a6619f..4927956c6c 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/Main.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/Main.java
@@ -30,9 +30,6 @@ import org.apache.commons.cli.PosixParser;
import org.apache.log4j.Logger;
import org.apache.qpid.common.QpidProperties;
import org.apache.qpid.framing.ProtocolVersion;
-import org.apache.qpid.server.Broker.InitException;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
/**
* Main entry point for AMQPD.
@@ -45,86 +42,17 @@ public class Main
private static final Option OPTION_VERSION = new Option("v", "version", false, "print the version information and exit");
- private static final Option OPTION_CONFIG_FILE =
- OptionBuilder.withArgName("file").hasArg().withDescription("use given configuration file").withLongOpt("config")
- .create("c");
-
- private static final Option OPTION_PORT =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("listen on the specified port. Overrides any value in the config file")
- .withLongOpt("port").create("p");
-
- private static final Option OPTION_SSLPORT =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("SSL port. Overrides any value in the config file")
- .withLongOpt("sslport").create("s");
-
-
- private static final Option OPTION_EXCLUDE_1_0 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP1-0 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-1-0").create();
-
- private static final Option OPTION_EXCLUDE_0_10 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP0-10 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-0-10").create();
-
- private static final Option OPTION_EXCLUDE_0_9_1 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP0-9-1 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-0-9-1").create();
-
- private static final Option OPTION_EXCLUDE_0_9 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP0-9 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-0-9").create();
-
- private static final Option OPTION_EXCLUDE_0_8 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("when listening on the specified port do not accept AMQP0-8 connections. The specified port must be one specified on the command line")
- .withLongOpt("exclude-0-8").create();
-
- private static final Option OPTION_INCLUDE_1_0 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP1-0 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-1-0").create();
-
-private static final Option OPTION_INCLUDE_0_10 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP0-10 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-0-10").create();
-
-private static final Option OPTION_INCLUDE_0_9_1 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP0-9-1 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-0-9-1").create();
-
-private static final Option OPTION_INCLUDE_0_9 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP0-9 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-0-9").create();
-
-private static final Option OPTION_INCLUDE_0_8 =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("accept AMQP0-8 connections on this port, overriding configuration to the contrary. The specified port must be one specified on the command line")
- .withLongOpt("include-0-8").create();
-
-
- private static final Option OPTION_JMX_PORT_REGISTRY_SERVER =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("listen on the specified management (registry server) port. Overrides any value in the config file")
- .withLongOpt("jmxregistryport").create("m");
-
- private static final Option OPTION_JMX_PORT_CONNECTOR_SERVER =
- OptionBuilder.withArgName("port").hasArg()
- .withDescription("listen on the specified management (connector server) port. Overrides any value in the config file")
- .withLongOpt("jmxconnectorport").create();
-
- private static final Option OPTION_BIND =
- OptionBuilder.withArgName("address").hasArg()
- .withDescription("bind to the specified address. Overrides any value in the config file")
- .withLongOpt("bind").create("b");
+ private static final Option OPTION_CONFIGURATION_STORE_PATH = OptionBuilder.withArgName("path").hasArg()
+ .withDescription("use given configuration store location").withLongOpt("store-path").create("sp");
+
+ private static final Option OPTION_CONFIGURATION_STORE_TYPE = OptionBuilder.withArgName("type").hasArg()
+ .withDescription("use given store type").withLongOpt("store-type").create("st");
+
+ private static final Option OPTION_INITIAL_CONFIGURATION_STORE_PATH = OptionBuilder.withArgName("path").hasArg()
+ .withDescription("pass the location of initial store to use to create a user store").withLongOpt("initial-store-path").create("isp");
+
+ private static final Option OPTION_INITIAL_CONFIGURATION_STORE_TYPE = OptionBuilder.withArgName("type").hasArg()
+ .withDescription("the type of initial store").withLongOpt("initial-store-type").create("ist");
private static final Option OPTION_LOG_CONFIG_FILE =
OptionBuilder.withArgName("file").hasArg()
@@ -137,31 +65,31 @@ private static final Option OPTION_INCLUDE_0_8 =
.withDescription("monitor the log file configuration file for changes. Units are seconds. "
+ "Zero means do not check for changes.").withLongOpt("logwatch").create("w");
+ private static final Option OPTION_MANAGEMENT_MODE = OptionBuilder.withDescription("start broker in a management mode")
+ .withLongOpt("management-mode").create("mm");
+ private static final Option OPTION_RMI_PORT = OptionBuilder.withArgName("port").hasArg()
+ .withDescription("override jmx rmi port in management mode").withLongOpt("jmxregistryport").create("rmi");
+ private static final Option OPTION_CONNECTOR_PORT = OptionBuilder.withArgName("port").hasArg()
+ .withDescription("override jmx connector port in management mode").withLongOpt("jmxconnectorport").create("jmxrmi");
+ private static final Option OPTION_HTTP_PORT = OptionBuilder.withArgName("port").hasArg()
+ .withDescription("override web management port in management mode").withLongOpt("httpport").create("http");
+
private static final Options OPTIONS = new Options();
static
{
OPTIONS.addOption(OPTION_HELP);
OPTIONS.addOption(OPTION_VERSION);
- OPTIONS.addOption(OPTION_CONFIG_FILE);
+ OPTIONS.addOption(OPTION_CONFIGURATION_STORE_PATH);
+ OPTIONS.addOption(OPTION_CONFIGURATION_STORE_TYPE);
OPTIONS.addOption(OPTION_LOG_CONFIG_FILE);
OPTIONS.addOption(OPTION_LOG_WATCH);
- OPTIONS.addOption(OPTION_PORT);
- OPTIONS.addOption(OPTION_SSLPORT);
- OPTIONS.addOption(OPTION_EXCLUDE_1_0);
- OPTIONS.addOption(OPTION_EXCLUDE_0_10);
- OPTIONS.addOption(OPTION_EXCLUDE_0_9_1);
- OPTIONS.addOption(OPTION_EXCLUDE_0_9);
- OPTIONS.addOption(OPTION_EXCLUDE_0_8);
- OPTIONS.addOption(OPTION_INCLUDE_1_0);
- OPTIONS.addOption(OPTION_INCLUDE_0_10);
- OPTIONS.addOption(OPTION_INCLUDE_0_9_1);
- OPTIONS.addOption(OPTION_INCLUDE_0_9);
- OPTIONS.addOption(OPTION_INCLUDE_0_8);
- OPTIONS.addOption(OPTION_BIND);
-
- OPTIONS.addOption(OPTION_JMX_PORT_REGISTRY_SERVER);
- OPTIONS.addOption(OPTION_JMX_PORT_CONNECTOR_SERVER);
+ OPTIONS.addOption(OPTION_INITIAL_CONFIGURATION_STORE_PATH);
+ OPTIONS.addOption(OPTION_INITIAL_CONFIGURATION_STORE_TYPE);
+ OPTIONS.addOption(OPTION_MANAGEMENT_MODE);
+ OPTIONS.addOption(OPTION_RMI_PORT);
+ OPTIONS.addOption(OPTION_CONNECTOR_PORT);
+ OPTIONS.addOption(OPTION_HTTP_PORT);
}
protected CommandLine _commandLine;
@@ -243,10 +171,15 @@ private static final Option OPTION_INCLUDE_0_8 =
else
{
BrokerOptions options = new BrokerOptions();
- String configFile = _commandLine.getOptionValue(OPTION_CONFIG_FILE.getOpt());
- if(configFile != null)
+ String configurationStore = _commandLine.getOptionValue(OPTION_CONFIGURATION_STORE_PATH.getOpt());
+ if (configurationStore != null)
+ {
+ options.setConfigurationStoreLocation(configurationStore);
+ }
+ String configurationStoreType = _commandLine.getOptionValue(OPTION_CONFIGURATION_STORE_TYPE.getOpt());
+ if (configurationStoreType != null)
{
- options.setConfigFile(configFile);
+ options.setConfigurationStoreType(configurationStoreType);
}
String logWatchConfig = _commandLine.getOptionValue(OPTION_LOG_WATCH.getOpt());
@@ -261,52 +194,37 @@ private static final Option OPTION_INCLUDE_0_8 =
options.setLogConfigFile(logConfig);
}
- String jmxPortRegistryServer = _commandLine.getOptionValue(OPTION_JMX_PORT_REGISTRY_SERVER.getOpt());
- if(jmxPortRegistryServer != null)
+ String initialConfigurationStore = _commandLine.getOptionValue(OPTION_INITIAL_CONFIGURATION_STORE_PATH.getOpt());
+ if (initialConfigurationStore != null)
{
- options.setJmxPortRegistryServer(Integer.parseInt(jmxPortRegistryServer));
+ options.setInitialConfigurationStoreLocation(initialConfigurationStore);
}
-
- String jmxPortConnectorServer = _commandLine.getOptionValue(OPTION_JMX_PORT_CONNECTOR_SERVER.getLongOpt());
- if(jmxPortConnectorServer != null)
- {
- options.setJmxPortConnectorServer(Integer.parseInt(jmxPortConnectorServer));
- }
-
- String bindAddr = _commandLine.getOptionValue(OPTION_BIND.getOpt());
- if (bindAddr != null)
+ String initailConfigurationStoreType = _commandLine.getOptionValue(OPTION_INITIAL_CONFIGURATION_STORE_TYPE.getOpt());
+ if (initailConfigurationStoreType != null)
{
- options.setBind(bindAddr);
+ options.setInitialConfigurationStoreType(initailConfigurationStoreType);
}
- String[] portStr = _commandLine.getOptionValues(OPTION_PORT.getOpt());
- if(portStr != null)
+ boolean managmentMode = _commandLine.hasOption(OPTION_MANAGEMENT_MODE.getOpt());
+ if (managmentMode)
{
- parsePortArray(options, portStr, false);
- for(ProtocolExclusion pe : ProtocolExclusion.values())
+ options.setManagementMode(true);
+ String rmiPort = _commandLine.getOptionValue(OPTION_RMI_PORT.getOpt());
+ if (rmiPort != null)
{
- parsePortArray(options, _commandLine.getOptionValues(pe.getExcludeName()), pe);
+ options.setManagementModeRmiPort(Integer.parseInt(rmiPort));
}
- for(ProtocolInclusion pe : ProtocolInclusion.values())
+ String connectorPort = _commandLine.getOptionValue(OPTION_CONNECTOR_PORT.getOpt());
+ if (connectorPort != null)
{
- parseProtocolInclusions(options, _commandLine.getOptionValues(pe.getIncludeName()), pe);
+ options.setManagementModeConnectorPort(Integer.parseInt(connectorPort));
}
- }
-
- String[] sslPortStr = _commandLine.getOptionValues(OPTION_SSLPORT.getOpt());
- if(sslPortStr != null)
- {
- parsePortArray(options, sslPortStr, true);
- for(ProtocolExclusion pe : ProtocolExclusion.values())
+ String httpPort = _commandLine.getOptionValue(OPTION_HTTP_PORT.getOpt());
+ if (httpPort != null)
{
- parsePortArray(options, _commandLine.getOptionValues(pe.getExcludeName()), pe);
- }
- for(ProtocolInclusion pe : ProtocolInclusion.values())
- {
- parseProtocolInclusions(options, _commandLine.getOptionValues(pe.getIncludeName()), pe);
+ options.setManagementModeHttpPort(Integer.parseInt(httpPort));
}
}
-
setExceptionHandler();
startBroker(options);
@@ -389,72 +307,7 @@ private static final Option OPTION_INCLUDE_0_8 =
protected void shutdown(final int status)
{
- ApplicationRegistry.remove();
System.exit(status);
}
- private static void parsePortArray(final BrokerOptions options,final Object[] ports,
- final boolean ssl) throws InitException
- {
- if(ports != null)
- {
- for(int i = 0; i < ports.length; i++)
- {
- try
- {
- if(ssl)
- {
- options.addSSLPort(Integer.parseInt(String.valueOf(ports[i])));
- }
- else
- {
- options.addPort(Integer.parseInt(String.valueOf(ports[i])));
- }
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid port: " + ports[i], e);
- }
- }
- }
- }
-
- private static void parsePortArray(final BrokerOptions options, final Object[] ports,
- final ProtocolExclusion excludedProtocol) throws InitException
- {
- if(ports != null)
- {
- for(int i = 0; i < ports.length; i++)
- {
- try
- {
- options.addExcludedPort(excludedProtocol,
- Integer.parseInt(String.valueOf(ports[i])));
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid port for exclusion: " + ports[i], e);
- }
- }
- }
- }
-
- private static void parseProtocolInclusions(final BrokerOptions options, final Object[] ports,
- final ProtocolInclusion includedProtocol) throws InitException
- {
- if(ports != null)
- {
- for(int i = 0; i < ports.length; i++)
- {
- try
- {
- options.addIncludedPort(includedProtocol, Integer.parseInt(String.valueOf(ports[i])));
- }
- catch (NumberFormatException e)
- {
- throw new InitException("Invalid port for inclusion: " + ports[i], e);
- }
- }
- }
- }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java b/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java
deleted file mode 100644
index fe6e32173f..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/ProtocolExclusion.java
+++ /dev/null
@@ -1,74 +0,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.
- *
- */
-package org.apache.qpid.server;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public enum ProtocolExclusion
-{
- v0_8("exclude-0-8","--exclude-0-8"),
- v0_9("exclude-0-9", "--exclude-0-9"),
- v0_9_1("exclude-0-9-1", "--exclude-0-9-1"),
- v0_10("exclude-0-10", "--exclude-0-10"),
- v1_0("exclude-1-0", "--exclude-1-0");
-
- private static final Map<String, ProtocolExclusion> MAP = new HashMap<String,ProtocolExclusion>();
-
- static
- {
- for(ProtocolExclusion pe : ProtocolExclusion.values())
- {
- MAP.put(pe.getArg(), pe);
- }
- }
-
- private String _arg;
- private String _excludeName;
-
- private ProtocolExclusion(final String excludeName, final String arg)
- {
- _excludeName = excludeName;
- _arg = arg;
- }
-
- public String getArg()
- {
- return _arg;
- }
-
- public String getExcludeName()
- {
- return _excludeName;
- }
-
- public static ProtocolExclusion lookup(final String arg)
- {
- ProtocolExclusion ex = MAP.get(arg);
-
- if(ex == null)
- {
- throw new IllegalArgumentException(arg + " is not a valid protocol exclusion");
- }
-
- return ex;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/ProtocolInclusion.java b/java/broker/src/main/java/org/apache/qpid/server/ProtocolInclusion.java
deleted file mode 100644
index 85fbe2e02e..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/ProtocolInclusion.java
+++ /dev/null
@@ -1,74 +0,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.
- *
- */
-package org.apache.qpid.server;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public enum ProtocolInclusion
-{
- v0_8("include-0-8","--include-0-8"),
- v0_9("include-0-9", "--include-0-9"),
- v0_9_1("include-0-9-1", "--include-0-9-1"),
- v0_10("include-0-10", "--include-0-10"),
- v1_0("include-1-0", "--include-1-0");
-
- private static final Map<String, ProtocolInclusion> MAP = new HashMap<String,ProtocolInclusion>();
-
- static
- {
- for(ProtocolInclusion pe : ProtocolInclusion.values())
- {
- MAP.put(pe.getArg(), pe);
- }
- }
-
- private String _arg;
- private String _includeName;
-
- private ProtocolInclusion(final String includeName, final String arg)
- {
- _includeName = includeName;
- _arg = arg;
- }
-
- public String getArg()
- {
- return _arg;
- }
-
- public String getIncludeName()
- {
- return _includeName;
- }
-
- public static ProtocolInclusion lookup(final String arg)
- {
- ProtocolInclusion ex = MAP.get(arg);
-
- if(ex == null)
- {
- throw new IllegalArgumentException(arg + " is not a valid protocol inclusion");
- }
-
- return ex;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/TransactionTimeoutHelper.java b/java/broker/src/main/java/org/apache/qpid/server/TransactionTimeoutHelper.java
index 0c474cca13..b7007bf768 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/TransactionTimeoutHelper.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/TransactionTimeoutHelper.java
@@ -18,46 +18,85 @@
*/
package org.apache.qpid.server;
-import org.apache.log4j.Logger;
+import org.apache.qpid.AMQException;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogMessage;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.messages.ChannelMessages;
+import org.apache.qpid.server.txn.ServerTransaction;
public class TransactionTimeoutHelper
{
- private static final Logger LOGGER = Logger.getLogger(TransactionTimeoutHelper.class);
-
- public static final String IDLE_TRANSACTION_ALERT = "IDLE TRANSACTION ALERT";
- public static final String OPEN_TRANSACTION_ALERT = "OPEN TRANSACTION ALERT";
+ private static final String OPEN_TRANSACTION_TIMEOUT_ERROR = "Open transaction timed out";
+ private static final String IDLE_TRANSACTION_TIMEOUT_ERROR = "Idle transaction timed out";
private final LogSubject _logSubject;
- public TransactionTimeoutHelper(final LogSubject logSubject)
+ private final CloseAction _closeAction;
+
+ public TransactionTimeoutHelper(final LogSubject logSubject, final CloseAction closeAction)
{
_logSubject = logSubject;
+ _closeAction = closeAction;
}
- public void logIfNecessary(final long timeSoFar, final long warnTimeout,
- final LogMessage message, final String alternateLogPrefix)
+ public void checkIdleOrOpenTimes(ServerTransaction transaction, long openWarn, long openClose, long idleWarn, long idleClose) throws AMQException
{
- if (isTimedOut(timeSoFar, warnTimeout))
+ if (transaction.isTransactional())
{
- LogActor logActor = CurrentActor.get();
- if(logActor.getRootMessageLogger().isMessageEnabled(logActor, _logSubject, message.getLogHierarchy()))
+ final long transactionUpdateTime = transaction.getTransactionUpdateTime();
+ if(transactionUpdateTime > 0)
{
- logActor.message(_logSubject, message);
+ long idleTime = System.currentTimeMillis() - transactionUpdateTime;
+ boolean closed = logAndCloseIfNecessary(idleTime, idleWarn, idleClose, ChannelMessages.IDLE_TXN(idleTime), IDLE_TRANSACTION_TIMEOUT_ERROR);
+ if (closed)
+ {
+ return; // no point proceeding to check the open time
+ }
}
- else
+
+ final long transactionStartTime = transaction.getTransactionStartTime();
+ if(transactionStartTime > 0)
{
- LOGGER.warn(alternateLogPrefix + " " + _logSubject.toLogString() + " " + timeSoFar + " ms");
+ long openTime = System.currentTimeMillis() - transactionStartTime;
+ logAndCloseIfNecessary(openTime, openWarn, openClose, ChannelMessages.OPEN_TXN(openTime), OPEN_TRANSACTION_TIMEOUT_ERROR);
}
}
}
- public boolean isTimedOut(long timeSoFar, long timeout)
+ /**
+ * @return true iff closeTimeout was exceeded
+ */
+ private boolean logAndCloseIfNecessary(final long timeSoFar,
+ final long warnTimeout, final long closeTimeout,
+ final LogMessage warnMessage, final String closeMessage) throws AMQException
+ {
+ if (isTimedOut(timeSoFar, warnTimeout))
+ {
+ LogActor logActor = CurrentActor.get();
+ logActor.message(_logSubject, warnMessage);
+ }
+
+ if(isTimedOut(timeSoFar, closeTimeout))
+ {
+ _closeAction.doTimeoutAction(closeMessage);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ private boolean isTimedOut(long timeSoFar, long timeout)
{
return timeout > 0L && timeSoFar > timeout;
}
+
+ public interface CloseAction
+ {
+ void doTimeoutAction(String reason) throws AMQException;
+ }
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/binding/Binding.java b/java/broker/src/main/java/org/apache/qpid/server/binding/Binding.java
index 9b3be624e0..469a4bb9d0 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/binding/Binding.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/binding/Binding.java
@@ -35,13 +35,15 @@ public class Binding
private final Exchange _exchange;
private final Map<String, Object> _arguments;
private final UUID _id;
- private final UUID _qmfId;
private final AtomicLong _matches = new AtomicLong();
- public Binding(UUID id, UUID qmfId, final String bindingKey, final AMQQueue queue, final Exchange exchange, final Map<String, Object> arguments)
+ public Binding(UUID id,
+ final String bindingKey,
+ final AMQQueue queue,
+ final Exchange exchange,
+ final Map<String, Object> arguments)
{
_id = id;
- _qmfId = qmfId;
_bindingKey = bindingKey;
_queue = queue;
_exchange = exchange;
@@ -53,11 +55,6 @@ public class Binding
return _id;
}
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
public String getBindingKey()
{
return _bindingKey;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/binding/BindingFactory.java b/java/broker/src/main/java/org/apache/qpid/server/binding/BindingFactory.java
index b805056311..69ff081528 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/binding/BindingFactory.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/binding/BindingFactory.java
@@ -24,10 +24,6 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.AMQInternalException;
import org.apache.qpid.AMQSecurityException;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.BindingConfig;
-import org.apache.qpid.server.configuration.BindingConfigType;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.messages.BindingMessages;
@@ -52,7 +48,7 @@ public class BindingFactory
_virtualHost = vhost;
}
- private final class BindingImpl extends Binding implements AMQQueue.Task, Exchange.Task, BindingConfig
+ private final class BindingImpl extends Binding implements AMQQueue.Task, Exchange.Task
{
private final BindingLogSubject _logSubject;
//TODO : persist creation time
@@ -60,7 +56,7 @@ public class BindingFactory
private BindingImpl(UUID id, String bindingKey, final AMQQueue queue, final Exchange exchange, final Map<String, Object> arguments)
{
- super(id, queue.getVirtualHost().getConfigStore().createId(), bindingKey, queue, exchange, arguments);
+ super(id, bindingKey, queue, exchange, arguments);
_logSubject = new BindingLogSubject(bindingKey,exchange,queue);
}
@@ -96,16 +92,6 @@ public class BindingFactory
return _createTime;
}
- public BindingConfigType getConfigType()
- {
- return BindingConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return _virtualHost;
- }
-
public boolean isDurable()
{
return getQueue().isDurable() && getExchange().isDurable();
@@ -186,7 +172,6 @@ public class BindingFactory
exchange.addCloseTask(b);
queue.addBinding(b);
exchange.addBinding(b);
- getConfigStore().addConfiguredObject(b);
b.logCreation();
return true;
@@ -197,11 +182,6 @@ public class BindingFactory
}
}
- private ConfigStore getConfigStore()
- {
- return _virtualHost.getConfigStore();
- }
-
public void restoreBinding(final UUID id, final String bindingKey, final AMQQueue queue, final Exchange exchange, final Map<String, Object> argumentMap) throws AMQSecurityException, AMQInternalException
{
makeBinding(id, bindingKey,queue,exchange,argumentMap,true, false);
@@ -257,7 +237,6 @@ public class BindingFactory
_virtualHost.getMessageStore().unbindQueue(b);
}
b.logDestruction();
- getConfigStore().removeConfiguredObject(b);
}
return b;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfig.java
deleted file mode 100644
index 233134abc5..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfig.java
+++ /dev/null
@@ -1,41 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.Map;
-
-
-public interface BindingConfig extends ConfiguredObject<BindingConfigType, BindingConfig>
-{
-
- ExchangeConfig getExchange();
-
- QueueConfig getQueue();
-
- String getBindingKey();
-
- Map<String, Object> getArguments();
-
- String getOrigin();
-
- long getMatches();
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfigType.java
deleted file mode 100644
index 1ed6b38758..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BindingConfigType.java
+++ /dev/null
@@ -1,114 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-public final class BindingConfigType extends ConfigObjectType<BindingConfigType, BindingConfig>
-{
- private static final List<BindingProperty<?>> BINDING_PROPERTIES = new ArrayList<BindingProperty<?>>();
-
- public static interface BindingProperty<S> extends ConfigProperty<BindingConfigType, BindingConfig, S>
- {
- }
-
- private abstract static class BindingReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<BindingConfigType, BindingConfig, S> implements BindingProperty<S>
- {
- public BindingReadWriteProperty(String name)
- {
- super(name);
- BINDING_PROPERTIES.add(this);
- }
- }
-
- private abstract static class BindingReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<BindingConfigType, BindingConfig, S> implements BindingProperty<S>
- {
- public BindingReadOnlyProperty(String name)
- {
- super(name);
- BINDING_PROPERTIES.add(this);
- }
- }
-
- public static final BindingReadOnlyProperty<ExchangeConfig> EXCHANGE_PROPERTY = new BindingReadOnlyProperty<ExchangeConfig>("exchange")
- {
- public ExchangeConfig getValue(BindingConfig object)
- {
- return object.getExchange();
- }
- };
-
- public static final BindingReadOnlyProperty<QueueConfig> QUEUE_PROPERTY = new BindingReadOnlyProperty<QueueConfig>("queue")
- {
- public QueueConfig getValue(BindingConfig object)
- {
- return object.getQueue();
- }
- };
-
- public static final BindingReadOnlyProperty<String> BINDING_KEY_PROPERTY = new BindingReadOnlyProperty<String>("bindingKey")
- {
- public String getValue(BindingConfig object)
- {
- return object.getBindingKey();
- }
- };
-
- public static final BindingReadOnlyProperty<Map<String,Object>> ARGUMENTS = new BindingReadOnlyProperty<Map<String,Object>>("arguments")
- {
- public Map<String,Object> getValue(BindingConfig object)
- {
- return object.getArguments();
- }
- };
-
- public static final BindingReadOnlyProperty<String> ORIGIN_PROPERTY = new BindingReadOnlyProperty<String>("origin")
- {
- public String getValue(BindingConfig object)
- {
- return object.getOrigin();
- }
- };
-
- private static final BindingConfigType INSTANCE = new BindingConfigType();
-
- private BindingConfigType()
- {
- }
-
- public Collection<BindingProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(BINDING_PROPERTIES);
- }
-
- public static BindingConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfig.java
deleted file mode 100644
index 00ed5fd0dd..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfig.java
+++ /dev/null
@@ -1,48 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-public interface BridgeConfig extends ConfiguredObject<BridgeConfigType, BridgeConfig>
-{
-
- boolean isDynamic();
-
- boolean isQueueBridge();
-
- boolean isLocalSource();
-
- String getSource();
-
- String getDestination();
-
- String getKey();
-
- String getTag();
-
- String getExcludes();
-
- LinkConfig getLink();
-
- Integer getChannelId();
-
- int getAckBatching();
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfigType.java
deleted file mode 100644
index 888feeff0c..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BridgeConfigType.java
+++ /dev/null
@@ -1,170 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public final class BridgeConfigType extends ConfigObjectType<BridgeConfigType, BridgeConfig>
-{
- private static final List<BridgeProperty<?>> BRIDGE_PROPERTIES = new ArrayList<BridgeProperty<?>>();
-
- public static interface BridgeProperty<S> extends ConfigProperty<BridgeConfigType, BridgeConfig, S>
- {
- }
-
- private abstract static class BridgeReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<BridgeConfigType, BridgeConfig, S> implements BridgeProperty<S>
- {
- public BridgeReadWriteProperty(String name)
- {
- super(name);
- BRIDGE_PROPERTIES.add(this);
- }
- }
-
- private abstract static class BridgeReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<BridgeConfigType, BridgeConfig, S> implements BridgeProperty<S>
- {
- public BridgeReadOnlyProperty(String name)
- {
- super(name);
- BRIDGE_PROPERTIES.add(this);
- }
- }
-
- public static final BridgeReadOnlyProperty<LinkConfig> LINK_PROPERTY = new BridgeReadOnlyProperty<LinkConfig>("link")
- {
- public LinkConfig getValue(BridgeConfig object)
- {
- return object.getLink();
- }
- };
-
- public static final BridgeReadOnlyProperty<Integer> CHANNEL_ID_PROPERTY = new BridgeReadOnlyProperty<Integer>("channelId")
- {
- public Integer getValue(BridgeConfig object)
- {
- return object.getChannelId();
- }
- };
-
- public static final BridgeReadOnlyProperty<Boolean> DURABLE_PROPERTY = new BridgeReadOnlyProperty<Boolean>("durable")
- {
- public Boolean getValue(BridgeConfig object)
- {
- return object.isDurable();
- }
- };
-
- public static final BridgeReadOnlyProperty<String> SOURCE_PROPERTY = new BridgeReadOnlyProperty<String>("source")
- {
- public String getValue(BridgeConfig object)
- {
- return object.getSource();
- }
- };
-
- public static final BridgeReadOnlyProperty<String> DESTINATION_PROPERTY = new BridgeReadOnlyProperty<String>("destination")
- {
- public String getValue(BridgeConfig object)
- {
- return object.getDestination();
- }
- };
-
- public static final BridgeReadOnlyProperty<String> KEY_PROPERTY = new BridgeReadOnlyProperty<String>("key")
- {
- public String getValue(BridgeConfig object)
- {
- return object.getKey();
- }
- };
-
- public static final BridgeReadOnlyProperty<Boolean> QUEUE_BRIDGE_PROPERTY = new BridgeReadOnlyProperty<Boolean>("queueBridge")
- {
- public Boolean getValue(BridgeConfig object)
- {
- return object.isQueueBridge();
- }
- };
-
- public static final BridgeReadOnlyProperty<Boolean> LOCAL_SOURCE_PROPERTY = new BridgeReadOnlyProperty<Boolean>("localSource")
- {
- public Boolean getValue(BridgeConfig object)
- {
- return object.isLocalSource();
- }
- };
-
- public static final BridgeReadOnlyProperty<String> TAG_PROPERTY = new BridgeReadOnlyProperty<String>("tag")
- {
- public String getValue(BridgeConfig object)
- {
- return object.getTag();
- }
- };
-
- public static final BridgeReadOnlyProperty<String> EXCLUDES_PROPERTY = new BridgeReadOnlyProperty<String>("excludes")
- {
- public String getValue(BridgeConfig object)
- {
- return object.getExcludes();
- }
- };
-
- public static final BridgeReadOnlyProperty<Boolean> DYNAMIC_PROPERTY = new BridgeReadOnlyProperty<Boolean>("dynamic")
- {
- public Boolean getValue(BridgeConfig object)
- {
- return object.isDynamic();
- }
- };
-
- public static final BridgeReadOnlyProperty<Integer> ACK_BATCHING_PROPERTY = new BridgeReadOnlyProperty<Integer>("ackBatching")
- {
- public Integer getValue(BridgeConfig object)
- {
- return object.getAckBatching();
- }
- };
-
-
- private static final BridgeConfigType INSTANCE = new BridgeConfigType();
-
- private BridgeConfigType()
- {
- }
-
- public Collection<BridgeProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(BRIDGE_PROPERTIES);
- }
-
- public static BridgeConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfig.java
deleted file mode 100644
index 7dffc2d3c0..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfig.java
+++ /dev/null
@@ -1,71 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.List;
-
-
-public interface BrokerConfig extends ConfiguredObject<BrokerConfigType,BrokerConfig>
-{
- void setSystem(SystemConfig system);
-
- SystemConfig getSystem();
-
- Integer getPort();
-
- Integer getWorkerThreads();
-
- Integer getMaxConnections();
-
- Integer getConnectionBacklogLimit();
-
- Long getStagingThreshold();
-
- Integer getManagementPublishInterval();
-
- String getVersion();
-
- String getDataDirectory();
-
- String getFederationTag();
-
- /**
- * List of feature(s) to be advertised to clients on connection.
- * Feature names are strings, beginning with qpid. followed by more or more
- * words separated by minus signs e.g. qpid.jms-selector.
- *
- * If there are no features, this method must return an empty array.
- *
- * @return list of feature names
- */
- List<String> getFeatures();
-
- void addVirtualHost(VirtualHostConfig virtualHost);
-
- void createBrokerConnection(String transport,
- String host,
- int port,
- boolean durable,
- String authMechanism,
- String username, String password);
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigType.java
deleted file mode 100644
index 64a59c3f61..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigType.java
+++ /dev/null
@@ -1,145 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public final class BrokerConfigType extends ConfigObjectType<BrokerConfigType, BrokerConfig>
-{
- private static final List<BrokerProperty<?>> BROKER_PROPERTIES = new ArrayList<BrokerProperty<?>>();
-
- public static interface BrokerProperty<S> extends ConfigProperty<BrokerConfigType, BrokerConfig, S>
- {
- }
-
- private abstract static class BrokerReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<BrokerConfigType, BrokerConfig, S> implements BrokerProperty<S>
- {
- public BrokerReadWriteProperty(String name)
- {
- super(name);
- BROKER_PROPERTIES.add(this);
- }
- }
-
- private abstract static class BrokerReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<BrokerConfigType, BrokerConfig, S> implements BrokerProperty<S>
- {
- public BrokerReadOnlyProperty(String name)
- {
- super(name);
- BROKER_PROPERTIES.add(this);
- }
- }
-
- public static final BrokerReadOnlyProperty<SystemConfig> SYSTEM_PROPERTY = new BrokerReadOnlyProperty<SystemConfig>("system")
- {
- public SystemConfig getValue(BrokerConfig object)
- {
- return object.getSystem();
- }
- };
-
- public static final BrokerReadOnlyProperty<Integer> PORT_PROPERTY = new BrokerReadOnlyProperty<Integer>("port")
- {
- public Integer getValue(BrokerConfig object)
- {
- return object.getPort();
- }
- };
-
- public static final BrokerReadOnlyProperty<Integer> WORKER_THREADS_PROPERTY = new BrokerReadOnlyProperty<Integer>("workerThreads")
- {
- public Integer getValue(BrokerConfig object)
- {
- return object.getWorkerThreads();
- }
- };
-
- public static final BrokerReadOnlyProperty<Integer> MAX_CONNECTIONS_PROPERTY = new BrokerReadOnlyProperty<Integer>("maxConnections")
- {
- public Integer getValue(BrokerConfig object)
- {
- return object.getMaxConnections();
- }
- };
-
- public static final BrokerReadOnlyProperty<Integer> CONNECTION_BACKLOG_LIMIT_PROPERTY = new BrokerReadOnlyProperty<Integer>("connectionBacklog")
- {
- public Integer getValue(BrokerConfig object)
- {
- return object.getConnectionBacklogLimit();
- }
- };
-
- public static final BrokerReadOnlyProperty<Long> STAGING_THRESHOLD_PROPERTY = new BrokerReadOnlyProperty<Long>("stagingThreshold")
- {
- public Long getValue(BrokerConfig object)
- {
- return object.getStagingThreshold();
- }
- };
-
- public static final BrokerReadOnlyProperty<Integer> MANAGEMENT_PUBLISH_INTERVAL_PROPERTY = new BrokerReadOnlyProperty<Integer>("mgmtPublishInterval")
- {
- public Integer getValue(BrokerConfig object)
- {
- return object.getManagementPublishInterval();
- }
- };
-
- public static final BrokerReadOnlyProperty<String> VERSION_PROPERTY = new BrokerReadOnlyProperty<String>("version")
- {
- public String getValue(BrokerConfig object)
- {
- return object.getVersion();
- }
- };
-
- public static final BrokerReadOnlyProperty<String> DATA_DIR_PROPERTY = new BrokerReadOnlyProperty<String>("dataDirectory")
- {
- public String getValue(BrokerConfig object)
- {
- return object.getDataDirectory();
- }
- };
-
- private static final BrokerConfigType INSTANCE = new BrokerConfigType();
-
- private BrokerConfigType()
- {
- }
-
- public Collection<BrokerProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(BROKER_PROPERTIES);
- }
-
- public static BrokerConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java
new file mode 100644
index 0000000000..31e08ab88a
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.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.server.configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+/**
+ * A helper class responsible for creation and opening of broker store.
+ */
+public class BrokerConfigurationStoreCreator
+{
+ /**
+ * URL to resource containing broker default configuration
+ */
+ public static final String DEFAULT_INITIAL_STORE_LOCATION = BrokerConfigurationStoreCreator.class.getClassLoader()
+ .getResource("initial-store.json").toExternalForm();
+
+ private Map<String, ConfigurationStoreFactory> _factories = new HashMap<String, ConfigurationStoreFactory>();
+
+ public BrokerConfigurationStoreCreator()
+ {
+ QpidServiceLoader<ConfigurationStoreFactory> serviceLoader = new QpidServiceLoader<ConfigurationStoreFactory>();
+ Iterable<ConfigurationStoreFactory> configurationStoreFactories = serviceLoader
+ .instancesOf(ConfigurationStoreFactory.class);
+ for (ConfigurationStoreFactory storeFactory : configurationStoreFactories)
+ {
+ String type = storeFactory.getStoreType();
+ ConfigurationStoreFactory factory = _factories.put(type.toLowerCase(), storeFactory);
+ if (factory != null)
+ {
+ throw new IllegalStateException("ConfigurationStoreFactory with type name '" + type
+ + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '"
+ + storeFactory.getClass().getName() + "'");
+ }
+ }
+ }
+
+ /**
+ * Create broker configuration store for a given store location, store type, initial store location and initial store type
+ *
+ * @param storeLocation store location
+ * @param storeType store type
+ * @param initialStoreLocation initial store location
+ * @param initialStoreType initial store type
+ * @return store instance opened at given store location
+ * @throws IllegalConfigurationException if store type is unknown
+ */
+ public ConfigurationEntryStore createStore(String storeLocation, String storeType, String initialStoreLocation,
+ String initialStoreType)
+ {
+ ConfigurationEntryStore store = createStore(storeType);
+ if (initialStoreLocation == null)
+ {
+ initialStoreLocation = DEFAULT_INITIAL_STORE_LOCATION;
+ initialStoreType = JsonConfigurationEntryStore.STORE_TYPE;
+ }
+ if (storeType.equals(initialStoreType))
+ {
+ store.open(storeLocation, initialStoreLocation);
+ }
+ else
+ {
+ ConfigurationEntryStore initialStore = createStore(initialStoreType);
+ initialStore.open(initialStoreLocation);
+ store.open(storeLocation, initialStore);
+ }
+ return store;
+ }
+
+ private ConfigurationEntryStore createStore(String storeType)
+ {
+ ConfigurationStoreFactory factory = _factories.get(storeType.toLowerCase());
+ if (factory == null)
+ {
+ throw new IllegalConfigurationException("Unknown store type: " + storeType);
+ }
+ return factory.createStore();
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java
new file mode 100644
index 0000000000..179d4a5640
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/BrokerProperties.java
@@ -0,0 +1,54 @@
+package org.apache.qpid.server.configuration;
+
+import java.util.Locale;
+
+/**
+ * Declares broker system property names
+ */
+public class BrokerProperties
+{
+ public static final int DEFAULT_HEART_BEAT_TIMEOUT_FACTOR = 2;
+
+ public static final String PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX = "qpid.dead_letter_exchange_suffix";
+ public static final String PROPERTY_DEAD_LETTER_QUEUE_SUFFIX = "qpid.dead_letter_queue_suffix";
+
+ public static final String PROPERTY_FRAME_SIZE = "qpid.frame_size";
+ public static final String PROPERTY_MSG_AUTH = "qpid.msg_auth";
+ public static final String PROPERTY_STATUS_UPDATES = "qpid.status_updates";
+ public static final String PROPERTY_LOCALE = "qpid.locale";
+ public static final String PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY = "qpid.default_supported_protocol_version_reply";
+ public static final String PROPERTY_DISABLED_FEATURES = "qpid.broker_disabled_features";
+
+ public static final int DEFAULT_FRAME_SIZE = Integer.getInteger(PROPERTY_FRAME_SIZE, 65535);
+ public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES = "qpid.broker_default_amqp_protocol_excludes";
+ public static final String PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES = "qpid.broker_default_amqp_protocol_includes";
+
+ public static final String PROPERTY_MANAGEMENT_RIGHTS_INFER_ALL_ACCESS = "qpid.broker_jmx_method_rights_infer_all_access";
+ public static final String PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY = "qpid.broker_jmx_use_custom_rmi_socket_factory";
+
+ public static final String PROPERTY_QPID_HOME = "QPID_HOME";
+ public static final String PROPERTY_QPID_WORK = "QPID_WORK";
+
+ private BrokerProperties()
+ {
+ }
+
+ public static Locale getLocale()
+ {
+ Locale locale = Locale.US;
+ String localeSetting = System.getProperty(BrokerProperties.PROPERTY_LOCALE);
+ if (localeSetting != null)
+ {
+ String[] localeParts = localeSetting.split("_");
+ String language = (localeParts.length > 0 ? localeParts[0] : "");
+ String country = (localeParts.length > 1 ? localeParts[1] : "");
+ String variant = "";
+ if (localeParts.length > 2)
+ {
+ variant = localeSetting.substring(language.length() + 1 + country.length() + 1);
+ }
+ locale = new Locale(language, country, variant);
+ }
+ return locale;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigObjectType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigObjectType.java
deleted file mode 100644
index c45aaaf1ee..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigObjectType.java
+++ /dev/null
@@ -1,30 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.Collection;
-
-public abstract class ConfigObjectType<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>>
-{
- public abstract Collection<? extends ConfigProperty<T, C, ?>> getProperties();
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigProperty.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigProperty.java
deleted file mode 100644
index 2d88ba00a0..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigProperty.java
+++ /dev/null
@@ -1,66 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-public interface ConfigProperty<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>, S>
-{
- public String getName();
-
- public S getValue(C object);
-
- public void setValue(C object, S value);
-
- public void clearValue(C object);
-
- public abstract static class ReadWriteConfigProperty<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>,S> implements ConfigProperty<T, C, S>
- {
- private final String _name;
-
- protected ReadWriteConfigProperty(String name)
- {
- _name = name;
- }
-
- public final String getName()
- {
- return _name;
- }
- }
-
- public abstract static class ReadOnlyConfigProperty<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T,C>, S> extends ReadWriteConfigProperty<T, C, S>
- {
- protected ReadOnlyConfigProperty(String name)
- {
- super(name);
- }
-
- public final void setValue(C object, S value)
- {
- throw new UnsupportedOperationException("Cannot set value '"+getName()+"' as this property is read-only");
- }
-
- public final void clearValue(C object)
- {
- throw new UnsupportedOperationException("Cannot set value '"+getName()+"' as this property is read-only");
- }
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java
deleted file mode 100644
index c519a0c0fa..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java
+++ /dev/null
@@ -1,201 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-
-public class ConfigStore
-{
- private ConcurrentHashMap<ConfigObjectType, ConcurrentHashMap<UUID, ConfiguredObject>> _typeMap =
- new ConcurrentHashMap<ConfigObjectType, ConcurrentHashMap<UUID, ConfiguredObject>>();
-
- private ConcurrentHashMap<ConfigObjectType, CopyOnWriteArrayList<ConfigEventListener>> _listenerMap =
- new ConcurrentHashMap<ConfigObjectType, CopyOnWriteArrayList<ConfigEventListener>>();
-
- private AtomicReference<SystemConfig> _root = new AtomicReference<SystemConfig>(null);
-
- private final AtomicLong _objectIdSource = new AtomicLong(0l);
- private final AtomicLong _persistentObjectIdSource = new AtomicLong(0l);
-
- // TODO - should load/increment this on broker startup
- private long _sequenceNumber = 1L;
-
- public enum Event
- {
- CREATED, DELETED
- }
-
- public interface ConfigEventListener<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T, C>>
- {
- void onEvent(C object, Event evt);
- }
-
- private ConfigStore()
- {
- }
-
- public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> ConfiguredObject<T, C> getConfiguredObject(ConfigObjectType<T,C> type, UUID id)
- {
- ConcurrentHashMap<UUID, ConfiguredObject> typeMap = _typeMap.get(type);
- if(typeMap != null)
- {
- return typeMap.get(id);
- }
- else
- {
- return null;
- }
-
- }
-
- public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> Collection<? extends C> getConfiguredObjects(ConfigObjectType<T,C> type)
- {
- ConcurrentHashMap typeMap = _typeMap.get(type);
- if(typeMap != null)
- {
- return typeMap.values();
- }
- else
- {
- return Collections.EMPTY_LIST;
- }
-
- }
-
- public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> void addConfiguredObject(ConfiguredObject<T, C> object)
- {
- ConcurrentHashMap typeMap = _typeMap.get(object.getConfigType());
- if(typeMap == null)
- {
- typeMap = new ConcurrentHashMap();
- ConcurrentHashMap oldMap = _typeMap.putIfAbsent(object.getConfigType(), typeMap);
- if(oldMap != null)
- {
- typeMap = oldMap;
- }
-
- }
-
- typeMap.put(object.getQMFId(), object);
- sendEvent(Event.CREATED, object);
- }
-
-
- public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> void removeConfiguredObject(ConfiguredObject<T, C> object)
- {
- ConcurrentHashMap typeMap = _typeMap.get(object.getConfigType());
- if(typeMap != null)
- {
- typeMap.remove(object.getQMFId());
- sendEvent(Event.DELETED, object);
- }
- }
-
- public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> void addConfigEventListener(T type, ConfigEventListener<T,C> listener)
- {
- CopyOnWriteArrayList listeners = _listenerMap.get(type);
- if(listeners == null)
- {
- listeners = new CopyOnWriteArrayList();
- CopyOnWriteArrayList oldListeners = _listenerMap.putIfAbsent(type, listeners);
- if(oldListeners != null)
- {
- listeners = oldListeners;
- }
-
- }
-
- listeners.add(listener);
-
- }
-
- public <T extends ConfigObjectType<T, C>, C extends ConfiguredObject<T, C>> void removeConfigEventListener(T type, ConfigEventListener<T,C> listener)
- {
- CopyOnWriteArrayList listeners = _listenerMap.get(type);
- if(listeners != null)
- {
- listeners.remove(listener);
- }
- }
-
- private void sendEvent(Event e, ConfiguredObject o)
- {
- CopyOnWriteArrayList<ConfigEventListener> listeners = _listenerMap.get(o.getConfigType());
- if(listeners != null)
- {
- for(ConfigEventListener listener : listeners)
- {
- listener.onEvent(o, e);
- }
- }
- }
-
- public boolean setRoot(SystemConfig object)
- {
- if(_root.compareAndSet(null,object))
- {
- addConfiguredObject(object);
- return true;
- }
- else
- {
- return false;
- }
- }
-
- public UUID createId()
- {
- return new UUID(((_sequenceNumber & 0xFFFl)<<48), _objectIdSource.incrementAndGet());
- }
-
- public UUID createPersistentId()
- {
- return new UUID(0L, _persistentObjectIdSource.incrementAndGet());
- }
-
- public void persistentIdInUse(UUID id)
- {
- long lsb = id.getLeastSignificantBits();
- long currentId;
- while((currentId = _persistentObjectIdSource.get()) < lsb)
- {
- _persistentObjectIdSource.compareAndSet(currentId, lsb);
- }
- }
-
- public SystemConfig getRoot()
- {
- return _root.get();
- }
-
- public static ConfigStore newInstance()
- {
- return new ConfigStore();
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java
new file mode 100644
index 0000000000..8afb1af24d
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.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.configuration;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+public class ConfigurationEntry
+{
+ public static final String ATTRIBUTE_NAME = "name";
+
+ private final UUID _id;
+ private final String _type;
+ private final Map<String, Object> _attributes;
+ private final Set<UUID> _childrenIds;
+ private final ConfigurationEntryStore _store;
+
+ public ConfigurationEntry(UUID id, String type, Map<String, Object> attributes, Set<UUID> childrenIds,
+ ConfigurationEntryStore store)
+ {
+ super();
+ _id = id;
+ _type = type;
+ _attributes = attributes;
+ _childrenIds = childrenIds;
+ _store = store;
+ }
+
+ public UUID getId()
+ {
+ return _id;
+ }
+
+ public String getType()
+ {
+ return _type;
+ }
+
+ public Map<String, Object> getAttributes()
+ {
+ return _attributes;
+ }
+
+ public Set<UUID> getChildrenIds()
+ {
+ return _childrenIds;
+ }
+
+ public ConfigurationEntryStore getStore()
+ {
+ return _store;
+ }
+
+ /**
+ * Returns this entry's children. The collection should not be modified.
+ */
+ public Map<String, Collection<ConfigurationEntry>> getChildren()
+ {
+ Map<String, Collection<ConfigurationEntry>> children = null;
+ if (_childrenIds == null)
+ {
+ children = Collections.emptyMap();
+ }
+ else
+ {
+ children = new HashMap<String, Collection<ConfigurationEntry>>();
+ for (UUID childId : _childrenIds)
+ {
+ ConfigurationEntry entry = _store.getEntry(childId);
+ String type = entry.getType();
+ Collection<ConfigurationEntry> childrenOfType = children.get(type);
+ if (childrenOfType == null)
+ {
+ childrenOfType = new ArrayList<ConfigurationEntry>();
+ children.put(type, childrenOfType);
+ }
+ childrenOfType.add(entry);
+ }
+ }
+ return Collections.unmodifiableMap(children);
+ }
+
+ public boolean hasChild(UUID id)
+ {
+ return _childrenIds.contains(id);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _id.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+
+ ConfigurationEntry other = (ConfigurationEntry) obj;
+ if (_id == null)
+ {
+ if (other._id != null)
+ {
+ return false;
+ }
+ }
+ else if (!_id.equals(other._id))
+ {
+ return false;
+ }
+
+ if (_type == null)
+ {
+ if (other._type != null)
+ {
+ return false;
+ }
+ }
+ else if (!_type.equals(other._type))
+ {
+ return false;
+ }
+
+ if (_store == null)
+ {
+ if (other._store != null)
+ {
+ return false;
+ }
+ }
+ else if (!_store.equals(other._store))
+ {
+ return false;
+ }
+
+ if (_childrenIds == null)
+ {
+ if (other._childrenIds != null)
+ {
+ return false;
+ }
+ }
+ else if (!_childrenIds.equals(other._childrenIds))
+ {
+ return false;
+ }
+
+ if (_attributes == null)
+ {
+ if (other._attributes != null)
+ {
+ return false;
+ }
+ }
+ else if (!_attributes.equals(other._attributes))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ConfigurationEntry [id=" + _id + ", type=" + _type + ", attributes=" + _attributes + ", childrenIds="
+ + _childrenIds + "]";
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java
new file mode 100644
index 0000000000..8238d147bd
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java
@@ -0,0 +1,98 @@
+/*
+ *
+ * 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.configuration;
+
+import java.util.UUID;
+
+public interface ConfigurationEntryStore
+{
+ /**
+ * Opens the store from a given location.
+ * <p>
+ * If location does not exists than a new empty store is created with a single root entry
+ *
+ * @param storeLocation store location
+ * @throws IllegalConfigurationException if store cannot be opened in the given location
+ */
+ void open(String storeLocation);
+
+ /**
+ * Opens the store from a given location.
+ * <p>
+ * If location does not exists than a new store is created either empty or from the initial store location if it is provided
+ *
+ * @param storeLocation store location
+ * @param initialStoreLocation initial store location
+ * @throws IllegalConfigurationException if store cannot be opened in the given location or initial store location does not
+ * exists or corrupted.
+ */
+ void open(String storeLocation, String initialStoreLocation);
+
+ /**
+ * Opens the store from a given location.
+ * <p>
+ * If location does not exists than a new store is created either empty or from the initial store if it is provided
+ *
+ * @param storeLocation store location
+ * @param initialStore initial store
+ * @throws IllegalConfigurationException if store cannot be opened in the given location
+ */
+ void open(String storeLocation, ConfigurationEntryStore initialStore);
+
+ /**
+ * Returns stored root configuration entry
+ *
+ * @return root entry
+ */
+ ConfigurationEntry getRootEntry();
+
+ /**
+ * Returns the configuration entry with a given id.
+ *
+ * @return entry with a given id or null if entry does not exists
+ */
+ ConfigurationEntry getEntry(UUID id);
+
+ /**
+ * Saves given entries in the store.
+ *
+ * @param entries entries to store
+ * @throws IllegalConfigurationException if save operation fails
+ */
+ void save(ConfigurationEntry... entries);
+
+ /**
+ * Removes the entries with given IDs and all their children
+ *
+ * @param entryIds IDs of entries to remove
+ * @return IDs of removed entries
+ * @throws IllegalConfigurationException if remove operation fails
+ */
+ UUID[] remove(UUID... entryIds);
+
+ /**
+ * Copies the store into the given location
+ *
+ * @param target location to copy store into
+ * @throws IllegalConfigurationException if store cannot be copied into given location
+ */
+ public void copyTo(String copyLocation);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java
deleted file mode 100644
index 06402fa646..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationManager.java
+++ /dev/null
@@ -1,54 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-public class ConfigurationManager
-{
- public List<ConfigurationPlugin> getConfigurationPlugins(String configurationElement, Configuration configuration) throws ConfigurationException
- {
- List<ConfigurationPlugin> plugins = new ArrayList<ConfigurationPlugin>();
- Map<List<String>, ConfigurationPluginFactory> factories =
- ApplicationRegistry.getInstance().getPluginManager().getConfigurationPlugins();
-
- for (Entry<List<String>, ConfigurationPluginFactory> entry : factories.entrySet())
- {
- if (entry.getKey().contains(configurationElement))
- {
- ConfigurationPluginFactory factory = entry.getValue();
- plugins.add(factory.newInstance(configurationElement, configuration));
- }
- }
-
- return plugins;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java
new file mode 100644
index 0000000000..dced38d260
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationStoreFactory.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.configuration;
+
+
+public interface ConfigurationStoreFactory
+{
+ /**
+ * Returns the type of the store this factory can create
+ */
+ public String getStoreType();
+
+ /**
+ * Creates the store instance.
+ */
+ public ConfigurationEntryStore createStore();
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObject.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObject.java
deleted file mode 100644
index ff4e38d9f7..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObject.java
+++ /dev/null
@@ -1,37 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.UUID;
-
-public interface ConfiguredObject<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T, C>>
-{
- public UUID getQMFId();
-
- public T getConfigType();
-
- public ConfiguredObject<T,C> getParent();
-
- public boolean isDurable();
-
- long getCreateTime();
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java
new file mode 100644
index 0000000000..65d97e6db1
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfiguredObjectRecoverer.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.configuration;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public interface ConfiguredObjectRecoverer<T extends ConfiguredObject>
+{
+ T create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfig.java
deleted file mode 100644
index 0dd36fe1fe..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfig.java
+++ /dev/null
@@ -1,49 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-public interface ConnectionConfig extends ConfiguredObject<ConnectionConfigType, ConnectionConfig>
-{
- VirtualHostConfig getVirtualHost();
-
- String getAddress();
-
- Boolean isIncoming();
-
- Boolean isSystemConnection();
-
- Boolean isFederationLink();
-
- String getAuthId();
-
- String getRemoteProcessName();
-
- Integer getRemotePID();
-
- Integer getRemoteParentPID();
-
- ConfigStore getConfigStore();
-
- Boolean isShadow();
-
- void mgmtClose();
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfigType.java
deleted file mode 100644
index 5631fda37c..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ConnectionConfigType.java
+++ /dev/null
@@ -1,146 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public final class ConnectionConfigType extends ConfigObjectType<ConnectionConfigType, ConnectionConfig>
-{
- private static final List<ConnectionProperty<?>> CONNECTION_PROPERTIES = new ArrayList<ConnectionProperty<?>>();
-
- public static interface ConnectionProperty<S> extends ConfigProperty<ConnectionConfigType, ConnectionConfig, S>
- {
- }
-
- private abstract static class ConnectionReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<ConnectionConfigType, ConnectionConfig, S> implements ConnectionProperty<S>
- {
- public ConnectionReadWriteProperty(String name)
- {
- super(name);
- CONNECTION_PROPERTIES.add(this);
- }
- }
-
- private abstract static class ConnectionReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<ConnectionConfigType, ConnectionConfig, S> implements ConnectionProperty<S>
- {
- public ConnectionReadOnlyProperty(String name)
- {
- super(name);
- CONNECTION_PROPERTIES.add(this);
- }
- }
-
- public static final ConnectionReadOnlyProperty<VirtualHostConfig> VIRTUAL_HOST_PROPERTY = new ConnectionReadOnlyProperty<VirtualHostConfig>("virtualHost")
- {
- public VirtualHostConfig getValue(ConnectionConfig object)
- {
- return object.getVirtualHost();
- }
- };
-
- public static final ConnectionReadOnlyProperty<String> ADDRESS_PROPERTY = new ConnectionReadOnlyProperty<String>("address")
- {
- public String getValue(ConnectionConfig object)
- {
- return object.getAddress();
- }
- };
-
- public static final ConnectionReadOnlyProperty<Boolean> INCOMING_PROPERTY = new ConnectionReadOnlyProperty<Boolean>("incoming")
- {
- public Boolean getValue(ConnectionConfig object)
- {
- return object.isIncoming();
- }
- };
-
- public static final ConnectionReadOnlyProperty<Boolean> SYSTEM_CONNECTION_PROPERTY = new ConnectionReadOnlyProperty<Boolean>("systemConnection")
- {
- public Boolean getValue(ConnectionConfig object)
- {
- return object.isSystemConnection();
- }
- };
-
- public static final ConnectionReadOnlyProperty<Boolean> FEDERATION_LINK_PROPERTY = new ConnectionReadOnlyProperty<Boolean>("federationLink")
- {
- public Boolean getValue(ConnectionConfig object)
- {
- return object.isFederationLink();
- }
- };
-
- public static final ConnectionReadOnlyProperty<String> AUTH_ID_PROPERTY = new ConnectionReadOnlyProperty<String>("authId")
- {
- public String getValue(ConnectionConfig object)
- {
- return object.getAuthId();
- }
- };
-
- public static final ConnectionReadOnlyProperty<String> REMOTE_PROCESS_NAME_PROPERTY = new ConnectionReadOnlyProperty<String>("remoteProcessName")
- {
- public String getValue(ConnectionConfig object)
- {
- return object.getRemoteProcessName();
- }
- };
-
-
- public static final ConnectionReadOnlyProperty<Integer> REMOTE_PID_PROPERTY = new ConnectionReadOnlyProperty<Integer>("remotePid")
- {
- public Integer getValue(ConnectionConfig object)
- {
- return object.getRemotePID();
- }
- };
-
- public static final ConnectionReadOnlyProperty<Integer> REMOTE_PARENT_PID_PROPERTY = new ConnectionReadOnlyProperty<Integer>("remoteParentPid")
- {
- public Integer getValue(ConnectionConfig object)
- {
- return object.getRemoteParentPID();
- }
- };
-
- private static final ConnectionConfigType INSTANCE = new ConnectionConfigType();
-
- private ConnectionConfigType()
- {
- }
-
- public Collection<ConnectionProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(CONNECTION_PROPERTIES);
- }
-
- public static ConnectionConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfig.java
deleted file mode 100644
index 6633d93adf..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfig.java
+++ /dev/null
@@ -1,60 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import org.apache.qpid.server.exchange.ExchangeType;
-
-import java.util.Map;
-
-
-public interface ExchangeConfig extends ConfiguredObject<ExchangeConfigType, ExchangeConfig>
-{
- VirtualHostConfig getVirtualHost();
-
- String getName();
-
- ExchangeType getType();
-
- boolean isAutoDelete();
-
- ExchangeConfig getAlternateExchange();
-
- Map<String, Object> getArguments();
-
-
- long getBindingCount();
-
- long getBindingCountHigh();
-
- long getMsgReceives();
-
- long getMsgRoutes();
-
- long getMsgDrops();
-
- long getByteReceives();
-
- long getByteRoutes();
-
- long getByteDrops();
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigType.java
deleted file mode 100644
index c7744117c4..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigType.java
+++ /dev/null
@@ -1,115 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-public final class ExchangeConfigType extends ConfigObjectType<ExchangeConfigType, ExchangeConfig>
-{
- private static final List<ExchangeProperty<?>> EXCHANGE_PROPERTIES = new ArrayList<ExchangeProperty<?>>();
-
- public static interface ExchangeProperty<S> extends ConfigProperty<ExchangeConfigType, ExchangeConfig, S>
- {
- }
-
- private abstract static class ExchangeReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<ExchangeConfigType, ExchangeConfig, S> implements ExchangeProperty<S>
- {
- public ExchangeReadWriteProperty(String name)
- {
- super(name);
- EXCHANGE_PROPERTIES.add(this);
- }
- }
-
- private abstract static class ExchangeReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<ExchangeConfigType, ExchangeConfig, S> implements ExchangeProperty<S>
- {
- public ExchangeReadOnlyProperty(String name)
- {
- super(name);
- EXCHANGE_PROPERTIES.add(this);
- }
- }
-
- public static final ExchangeReadOnlyProperty<VirtualHostConfig> VIRTUAL_HOST_PROPERTY = new ExchangeReadOnlyProperty<VirtualHostConfig>("virtualHost")
- {
- public VirtualHostConfig getValue(ExchangeConfig object)
- {
- return object.getVirtualHost();
- }
- };
-
- public static final ExchangeReadOnlyProperty<String> NAME_PROPERTY = new ExchangeReadOnlyProperty<String>("name")
- {
- public String getValue(ExchangeConfig object)
- {
- return object.getName();
- }
- };
-
- public static final ExchangeReadOnlyProperty<Boolean> AUTODELETE_PROPERTY = new ExchangeReadOnlyProperty<Boolean>("autodelete")
- {
- public Boolean getValue(ExchangeConfig object)
- {
- return object.isAutoDelete();
- }
- };
-
-
- public static final ExchangeReadOnlyProperty<ExchangeConfig> ALTERNATE_EXCHANGE_PROPERTY = new ExchangeReadOnlyProperty<ExchangeConfig>("alternateExchange")
- {
- public ExchangeConfig getValue(ExchangeConfig object)
- {
- return object.getAlternateExchange();
- }
- };
-
- public static final ExchangeReadOnlyProperty<Map<String,Object>> ARGUMENTS = new ExchangeReadOnlyProperty<Map<String,Object>>("arguments")
- {
- public Map<String,Object> getValue(ExchangeConfig object)
- {
- return object.getArguments();
- }
- };
-
- private static final ExchangeConfigType INSTANCE = new ExchangeConfigType();
-
- private ExchangeConfigType()
- {
- }
-
- public Collection<ExchangeProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(EXCHANGE_PROPERTIES);
- }
-
- public static ExchangeConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigurationPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigurationPlugin.java
deleted file mode 100644
index bfb2de4235..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ExchangeConfigurationPlugin.java
+++ /dev/null
@@ -1,29 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.queue.AMQQueue;
-
-public interface ExchangeConfigurationPlugin
-{
- ConfigurationPlugin getConfiguration(AMQQueue queue);
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java
new file mode 100644
index 0000000000..bedd470ddf
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/IllegalConfigurationException.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.configuration;
+
+public class IllegalConfigurationException extends RuntimeException
+{
+ private static final long serialVersionUID = 1130064756291179812L;
+
+ public IllegalConfigurationException(String message)
+ {
+ super(message);
+ }
+
+ public IllegalConfigurationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfig.java
deleted file mode 100644
index 2c37a94db0..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfig.java
+++ /dev/null
@@ -1,56 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-public interface LinkConfig extends ConfiguredObject<LinkConfigType, LinkConfig>
-{
- VirtualHostConfig getVirtualHost();
-
-
- String getTransport();
-
- String getHost();
-
- int getPort();
-
- String getRemoteVhost();
-
- String getAuthMechanism();
-
- String getUsername();
-
- String getPassword();
-
- void close();
-
- void createBridge(boolean durable,
- boolean dynamic,
- boolean srcIsQueue,
- boolean srcIsLocal,
- String src,
- String dest,
- String key, String tag, String excludes);
-
- String getState();
-
- String getLastError();
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfigType.java
deleted file mode 100644
index 847cae87f5..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/LinkConfigType.java
+++ /dev/null
@@ -1,137 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public final class LinkConfigType extends ConfigObjectType<LinkConfigType, LinkConfig>
-{
- private static final List<LinkProperty<?>> LINK_PROPERTIES = new ArrayList<LinkProperty<?>>();
-
- public static interface LinkProperty<S> extends ConfigProperty<LinkConfigType, LinkConfig, S>
- {
- }
-
- private abstract static class LinkReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<LinkConfigType, LinkConfig, S> implements LinkProperty<S>
- {
- public LinkReadWriteProperty(String name)
- {
- super(name);
- LINK_PROPERTIES.add(this);
- }
- }
-
- private abstract static class LinkReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<LinkConfigType, LinkConfig, S> implements LinkProperty<S>
- {
- public LinkReadOnlyProperty(String name)
- {
- super(name);
- LINK_PROPERTIES.add(this);
- }
- }
-
- public static final LinkReadOnlyProperty<VirtualHostConfig> VIRTUAL_HOST_PROPERTY = new LinkReadOnlyProperty<VirtualHostConfig>("virtualHost")
- {
- public VirtualHostConfig getValue(LinkConfig object)
- {
- return object.getVirtualHost();
- }
- };
-
- public static final LinkReadOnlyProperty<String> TRANSPORT_PROPERTY = new LinkReadOnlyProperty<String>("transport")
- {
- public String getValue(LinkConfig object)
- {
- return object.getTransport();
- }
- };
-
- public static final LinkReadOnlyProperty<String> HOST_PROPERTY = new LinkReadOnlyProperty<String>("host")
- {
- public String getValue(LinkConfig object)
- {
- return object.getHost();
- }
- };
-
- public static final LinkReadOnlyProperty<Integer> PORT_PROPERTY = new LinkReadOnlyProperty<Integer>("port")
- {
- public Integer getValue(LinkConfig object)
- {
- return object.getPort();
- }
- };
-
- public static final LinkReadOnlyProperty<String> REMOTE_VHOST_PROPERTY = new LinkReadOnlyProperty<String>("remoteVhost")
- {
- public String getValue(LinkConfig object)
- {
- return object.getRemoteVhost();
- }
- };
-
- public static final LinkReadOnlyProperty<String> AUTH_MECHANISM_PROPERTY = new LinkReadOnlyProperty<String>("authMechanism")
- {
- public String getValue(LinkConfig object)
- {
- return object.getAuthMechanism();
- }
- };
-
- public static final LinkReadOnlyProperty<String> USERNAME_PROPERTY = new LinkReadOnlyProperty<String>("username")
- {
- public String getValue(LinkConfig object)
- {
- return object.getUsername();
- }
- };
-
- public static final LinkReadOnlyProperty<String> PASSWORD_PROPERTY = new LinkReadOnlyProperty<String>("password")
- {
- public String getValue(LinkConfig object)
- {
- return object.getPassword();
- }
- };
-
- private static final LinkConfigType INSTANCE = new LinkConfigType();
-
- private LinkConfigType()
- {
- }
-
- public Collection<LinkProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(LINK_PROPERTIES);
- }
-
- public static LinkConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfig.java
deleted file mode 100644
index 1ef5edeb51..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfig.java
+++ /dev/null
@@ -1,86 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import org.apache.qpid.AMQException;
-
-import java.util.Map;
-
-
-public interface QueueConfig extends ConfiguredObject<QueueConfigType, QueueConfig>
-{
- VirtualHostConfig getVirtualHost();
-
- String getName();
-
- boolean isExclusive();
-
- boolean isAutoDelete();
-
- ExchangeConfig getAlternateExchange();
-
- Map<String, Object> getArguments();
-
- long getReceivedMessageCount();
-
- int getMessageCount();
-
- long getQueueDepth();
-
- int getConsumerCount();
-
- int getConsumerCountHigh();
-
- int getBindingCount();
-
- int getBindingCountHigh();
-
- ConfigStore getConfigStore();
-
- long getMessageDequeueCount();
-
- long getTotalEnqueueSize();
-
- long getTotalDequeueSize();
-
- long getByteTxnEnqueues();
-
- long getByteTxnDequeues();
-
- long getMsgTxnEnqueues();
-
- long getMsgTxnDequeues();
-
- long getPersistentByteEnqueues();
-
- long getPersistentByteDequeues();
-
- long getPersistentMsgEnqueues();
-
- long getPersistentMsgDequeues();
-
- long getUnackedMessageCount();
-
- long getUnackedMessageCountHigh();
-
- void purge(long request) throws AMQException;
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfigType.java
deleted file mode 100644
index f958ef5350..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfigType.java
+++ /dev/null
@@ -1,123 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-public final class QueueConfigType extends ConfigObjectType<QueueConfigType, QueueConfig>
-{
- private static final List<QueueProperty<?>> QUEUE_PROPERTIES = new ArrayList<QueueProperty<?>>();
-
- public static interface QueueProperty<S> extends ConfigProperty<QueueConfigType, QueueConfig, S>
- {
- }
-
- private abstract static class QueueReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<QueueConfigType, QueueConfig, S> implements QueueProperty<S>
- {
- public QueueReadWriteProperty(String name)
- {
- super(name);
- QUEUE_PROPERTIES.add(this);
- }
- }
-
- private abstract static class QueueReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<QueueConfigType, QueueConfig, S> implements QueueProperty<S>
- {
- public QueueReadOnlyProperty(String name)
- {
- super(name);
- QUEUE_PROPERTIES.add(this);
- }
- }
-
- public static final QueueReadOnlyProperty<VirtualHostConfig> VISTUAL_HOST_PROPERTY = new QueueReadOnlyProperty<VirtualHostConfig>("virtualHost")
- {
- public VirtualHostConfig getValue(QueueConfig object)
- {
- return object.getVirtualHost();
- }
- };
-
- public static final QueueReadOnlyProperty<String> NAME_PROPERTY = new QueueReadOnlyProperty<String>("name")
- {
- public String getValue(QueueConfig object)
- {
- return object.getName();
- }
- };
-
- public static final QueueReadOnlyProperty<Boolean> AUTODELETE_PROPERTY = new QueueReadOnlyProperty<Boolean>("autodelete")
- {
- public Boolean getValue(QueueConfig object)
- {
- return object.isAutoDelete();
- }
- };
-
- public static final QueueReadOnlyProperty<Boolean> EXCLUSIVE_PROPERTY = new QueueReadOnlyProperty<Boolean>("exclusive")
- {
- public Boolean getValue(QueueConfig object)
- {
- return object.isExclusive();
- }
- };
-
- public static final QueueReadOnlyProperty<ExchangeConfig> ALTERNATE_EXCHANGE_PROPERTY = new QueueReadOnlyProperty<ExchangeConfig>("alternateExchange")
- {
- public ExchangeConfig getValue(QueueConfig object)
- {
- return object.getAlternateExchange();
- }
- };
-
- public static final QueueReadOnlyProperty<Map<String,Object>> ARGUMENTS = new QueueReadOnlyProperty<Map<String,Object>>("arguments")
- {
- public Map<String,Object> getValue(QueueConfig object)
- {
- return object.getArguments();
- }
- };
-
-
- private static final QueueConfigType INSTANCE = new QueueConfigType();
-
- private QueueConfigType()
- {
- }
-
- public Collection<QueueProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(QUEUE_PROPERTIES);
- }
-
- public static QueueConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java
index 8f03383777..06691d8659 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java
@@ -24,11 +24,11 @@ import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+import org.apache.qpid.server.configuration.plugins.AbstractConfiguration;
import java.util.List;
-public class QueueConfiguration extends ConfigurationPlugin
+public class QueueConfiguration extends AbstractConfiguration
{
private String _name;
private VirtualHostConfiguration _vHostConfig;
@@ -39,7 +39,7 @@ public class QueueConfiguration extends ConfigurationPlugin
_name = name;
CompositeConfiguration mungedConf = new CompositeConfiguration();
- mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + name));
+ mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + escapeTagName(name)));
mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues"));
setConfiguration("virtualhosts.virtualhost.queues.queue", mungedConf);
@@ -193,43 +193,4 @@ public class QueueConfiguration extends ConfigurationPlugin
{
return getBooleanValue("deadLetterQueues", _vHostConfig.isDeadLetterQueueEnabled());
}
-
- public static class QueueConfig extends ConfigurationPlugin
- {
- @Override
- public String[] getElementsProcessed()
- {
- return new String[]{"name"};
- }
-
- public String getName()
- {
- return getStringValue("name");
- }
-
-
- public void validateConfiguration() throws ConfigurationException
- {
- if (getConfig().isEmpty())
- {
- throw new ConfigurationException("Queue section cannot be empty.");
- }
-
- if (getName() == null)
- {
- throw new ConfigurationException("Queue section must have a 'name' element.");
- }
-
- }
-
-
- @Override
- public String formatToString()
- {
- return "Name:"+getName();
- }
-
-
- }
-
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java
new file mode 100644
index 0000000000..963d019ec3
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/RecovererProvider.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.configuration;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public interface RecovererProvider
+{
+ ConfiguredObjectRecoverer<? extends ConfiguredObject> getRecoverer(String type);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java
deleted file mode 100644
index f9e2d93cff..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java
+++ /dev/null
@@ -1,1031 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Map.Entry;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.TrustManagerFactory;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.ConfigurationFactory;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.commons.configuration.SystemConfiguration;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.exchange.DefaultExchangeFactory;
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.signal.SignalHandlerTask;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-
-import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
-
-public class ServerConfiguration extends ConfigurationPlugin
-{
- protected static final Logger _logger = Logger.getLogger(ServerConfiguration.class);
-
- // Default Configuration values
- public static final int DEFAULT_BUFFER_SIZE = 262144;
- public static final String DEFAULT_STATUS_UPDATES = "on";
- public static final String SECURITY_CONFIG_RELOADED = "SECURITY CONFIGURATION RELOADED";
-
- public static final int DEFAULT_FRAME_SIZE = 65536;
- public static final int DEFAULT_PORT = 5672;
- public static final int DEFAULT_SSL_PORT = 5671;
- public static final long DEFAULT_HOUSEKEEPING_PERIOD = 30000L;
- public static final int DEFAULT_JMXPORT_REGISTRYSERVER = 8999;
- public static final int JMXPORT_CONNECTORSERVER_OFFSET = 100;
- public static final int DEFAULT_HTTP_MANAGEMENT_PORT = 8080;
- public static final int DEFAULT_HTTPS_MANAGEMENT_PORT = 8443;
- public static final long DEFAULT_MINIMUM_ALERT_REPEAT_GAP = 30000l;
-
- public static final String QPID_HOME = "QPID_HOME";
- public static final String QPID_WORK = "QPID_WORK";
- public static final String LIB_DIR = "lib";
- public static final String PLUGIN_DIR = "plugins";
- public static final String CACHE_DIR = "cache";
-
- private Map<String, VirtualHostConfiguration> _virtualHosts = new HashMap<String, VirtualHostConfiguration>();
-
- private File _configFile;
- private File _vhostsFile;
- private String _qpidWork;
- private String _qpidHome;
-
- // Map of environment variables to config items
- private static final Map<String, String> envVarMap = new HashMap<String, String>();
-
- // Configuration values to be read from the configuration file
- //todo Move all properties to static values to ensure system testing can be performed.
- public static final String MGMT_CUSTOM_REGISTRY_SOCKET = "management.custom-registry-socket";
- public static final String MGMT_JMXPORT_REGISTRYSERVER = "management.jmxport.registryServer";
- public static final String MGMT_JMXPORT_CONNECTORSERVER = "management.jmxport.connectorServer";
- public static final String SECURITY_DEFAULT_AUTH_MANAGER = "security.default-auth-manager";
- public static final String SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER = "security.port-mappings.port-mapping.auth-manager";
- public static final String SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT = "security.port-mappings.port-mapping.port";
- public static final String STATUS_UPDATES = "status-updates";
- public static final String ADVANCED_LOCALE = "advanced.locale";
- public static final String CONNECTOR_AMQP10ENABLED = "connector.amqp10enabled";
- public static final String CONNECTOR_AMQP010ENABLED = "connector.amqp010enabled";
- public static final String CONNECTOR_AMQP091ENABLED = "connector.amqp091enabled";
- public static final String CONNECTOR_AMQP09ENABLED = "connector.amqp09enabled";
- public static final String CONNECTOR_AMQP08ENABLED = "connector.amqp08enabled";
- public static final String CONNECTOR_AMQP_SUPPORTED_REPLY = "connector.amqpDefaultSupportedProtocolReply";
- public static final String CONNECTOR_INCLUDE_10 = "connector.include10";
- public static final String CONNECTOR_INCLUDE_010 = "connector.include010";
- public static final String CONNECTOR_INCLUDE_091 = "connector.include091";
- public static final String CONNECTOR_INCLUDE_09 = "connector.include09";
- public static final String CONNECTOR_INCLUDE_08 = "connector.include08";
-
- {
- envVarMap.put("QPID_PORT", "connector.port");
- envVarMap.put("QPID_SSLPORT", "connector.ssl.port");
- envVarMap.put("QPID_JMXPORT_REGISTRYSERVER", MGMT_JMXPORT_REGISTRYSERVER);
- envVarMap.put("QPID_JMXPORT_CONNECTORSERVER", MGMT_JMXPORT_CONNECTORSERVER);
- envVarMap.put("QPID_FRAMESIZE", "advanced.framesize");
- envVarMap.put("QPID_MSGAUTH", "security.msg-auth");
- envVarMap.put("QPID_AUTOREGISTER", "auto_register");
- envVarMap.put("QPID_MANAGEMENTENABLED", "management.enabled");
- envVarMap.put("QPID_HTTPMANAGEMENTENABLED", "management.http.enabled");
- envVarMap.put("QPID_HTTPMANAGEMENTPORT", "management.http.port");
- envVarMap.put("QPID_HEARTBEATDELAY", "heartbeat.delay");
- envVarMap.put("QPID_HEARTBEATTIMEOUTFACTOR", "heartbeat.timeoutFactor");
- envVarMap.put("QPID_MAXIMUMMESSAGEAGE", "maximumMessageAge");
- envVarMap.put("QPID_MAXIMUMMESSAGECOUNT", "maximumMessageCount");
- envVarMap.put("QPID_MAXIMUMQUEUEDEPTH", "maximumQueueDepth");
- envVarMap.put("QPID_MAXIMUMMESSAGESIZE", "maximumMessageSize");
- envVarMap.put("QPID_MAXIMUMCHANNELCOUNT", "maximumChannelCount");
- envVarMap.put("QPID_MINIMUMALERTREPEATGAP", "minimumAlertRepeatGap");
- envVarMap.put("QPID_QUEUECAPACITY", "capacity");
- envVarMap.put("QPID_FLOWRESUMECAPACITY", "flowResumeCapacity");
- envVarMap.put("QPID_SOCKETRECEIVEBUFFER", "connector.socketReceiveBuffer");
- envVarMap.put("QPID_SOCKETWRITEBUFFER", "connector.socketWriteBuffer");
- envVarMap.put("QPID_TCPNODELAY", "connector.tcpNoDelay");
- envVarMap.put("QPID_STATUS-UPDATES", "status-updates");
- }
-
- /**
- * Loads the given file and sets up the HUP signal handler.
- *
- * This will load the file and present the root level properties but will
- * not perform any virtualhost configuration.
- * <p>
- * To perform this {@link #initialise()} must be called.
- * <p>
- * This has been made a two step process to allow the Plugin Manager and
- * Configuration Manager to be initialised in the Application Registry.
- * <p>
- * If using this ServerConfiguration via an ApplicationRegistry there is no
- * need to explicitly call {@link #initialise()} as this is done via the
- * {@link ApplicationRegistry#initialise()} method.
- *
- * @param configurationURL
- * @throws org.apache.commons.configuration.ConfigurationException
- */
- public ServerConfiguration(File configurationURL) throws ConfigurationException
- {
- this(parseConfig(configurationURL));
- _configFile = configurationURL;
-
- SignalHandlerTask hupReparseTask = new SignalHandlerTask()
- {
- public void handle()
- {
- try
- {
- reparseConfigFileSecuritySections();
- }
- catch (ConfigurationException e)
- {
- _logger.error("Could not reload configuration file security sections", e);
- }
- }
- };
-
- if(!hupReparseTask.register("HUP"))
- {
- _logger.info("Unable to register Signal HUP handler to reload security configuration.");
- _logger.info("Signal HUP not supported for this OS / JVM combination - " + SignalHandlerTask.getPlatformDescription());
- }
- }
-
- /**
- * Wraps the given Commons Configuration as a ServerConfiguration.
- *
- * Mainly used during testing and in locations where configuration is not
- * desired but the interface requires configuration.
- * <p>
- * If the given configuration has VirtualHost configuration then
- * {@link #initialise()} must be called to perform the required setup.
- * <p>
- * This has been made a two step process to allow the Plugin Manager and
- * Configuration Manager to be initialised in the Application Registry.
- * <p>
- * If using this ServerConfiguration via an ApplicationRegistry there is no
- * need to explicitly call {@link #initialise()} as this is done via the
- * {@link ApplicationRegistry#initialise()} method.
- *
- * @param conf
- */
- public ServerConfiguration(Configuration conf)
- {
- setConfig(conf);
- }
-
- /**
- * Processes this configuration and setups any VirtualHosts defined in the
- * configuration.
- *
- * This has been separated from the constructor to allow the PluginManager
- * time to be created and provide plugins to the ConfigurationManager for
- * processing here.
- * <p>
- * Called by {@link ApplicationRegistry#initialise()}.
- * <p>
- * NOTE: A DEFAULT ApplicationRegistry must exist when using this method
- * or a new ApplicationRegistry will be created.
- *
- * @throws ConfigurationException
- */
- public void initialise() throws ConfigurationException
- {
- setConfiguration("", getConfig());
- setupVirtualHosts(getConfig());
- }
-
- public String[] getElementsProcessed()
- {
- return new String[] { "" };
- }
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- // Support for security.jmx.access was removed when JMX access rights were incorporated into the main ACL.
- // This ensure that users remove the element from their configuration file.
-
- if (getListValue("security.jmx.access").size() > 0)
- {
- String message = "Validation error : security/jmx/access is no longer a supported element within the configuration xml."
- + (_configFile == null ? "" : " Configuration file : " + _configFile);
- throw new ConfigurationException(message);
- }
-
- if (getListValue("security.jmx.principal-database").size() > 0)
- {
- String message = "Validation error : security/jmx/principal-database is no longer a supported element within the configuration xml."
- + (_configFile == null ? "" : " Configuration file : " + _configFile);
- throw new ConfigurationException(message);
- }
-
- if (getListValue("security.principal-databases.principal-database(0).class").size() > 0)
- {
- String message = "Validation error : security/principal-databases is no longer supported within the configuration xml."
- + (_configFile == null ? "" : " Configuration file : " + _configFile);
- throw new ConfigurationException(message);
- }
-
- // QPID-3266. Tidy up housekeeping configuration option for scheduling frequency
- if (contains("housekeeping.expiredMessageCheckPeriod"))
- {
- String message = "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod."
- + (_configFile == null ? "" : " Configuration file : " + _configFile);
- throw new ConfigurationException(message);
- }
-
- String[] ports = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT);
- String[] authManagers = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER);
- if (ports.length != authManagers.length)
- {
- throw new ConfigurationException("Validation error: Each port-mapping must have exactly one port and exactly one auth-manager.");
- }
-
- // QPID-3517: Inconsistency in capitalisation in the SSL configuration keys used within the connector and management configuration
- // sections. For the moment, continue to understand both but generate a deprecated warning if the less preferred keystore is used.
- for (String key : new String[] {"management.ssl.keystorePath",
- "management.ssl.keystorePassword," +
- "connector.ssl.keystorePath",
- "connector.ssl.keystorePassword"})
- {
- if (contains(key))
- {
- final String deprecatedXpath = key.replaceAll("\\.", "/");
- final String preferredXpath = deprecatedXpath.replaceAll("keystore", "keyStore");
- _logger.warn("Validation warning: " + deprecatedXpath + " is deprecated and must be replaced by " + preferredXpath
- + (_configFile == null ? "" : " Configuration file : " + _configFile));
- }
- }
-
- // QPID-3739 certType was a misleading name.
- if (contains("connector.ssl.certType"))
- {
- _logger.warn("Validation warning: connector/ssl/certType is deprecated and must be replaced by connector/ssl/keyManagerFactoryAlgorithm"
- + (_configFile == null ? "" : " Configuration file : " + _configFile));
- }
- }
-
- /*
- * Modified to enforce virtualhosts configuration in external file or main file, but not
- * both, as a fix for QPID-2360 and QPID-2361.
- */
- @SuppressWarnings("unchecked")
- protected void setupVirtualHosts(Configuration conf) throws ConfigurationException
- {
- List<String> vhostFiles = (List) conf.getList("virtualhosts");
- Configuration vhostConfig = conf.subset("virtualhosts");
-
- // Only one configuration mechanism allowed
- if (!vhostFiles.isEmpty() && !vhostConfig.subset("virtualhost").isEmpty())
- {
- throw new ConfigurationException("Only one of external or embedded virtualhosts configuration allowed.");
- }
-
- // We can only have one vhosts XML file included
- if (vhostFiles.size() > 1)
- {
- throw new ConfigurationException("Only one external virtualhosts configuration file allowed, multiple filenames found.");
- }
-
- // Virtualhost configuration object
- Configuration vhostConfiguration = new HierarchicalConfiguration();
-
- // Load from embedded configuration if possible
- if (!vhostConfig.subset("virtualhost").isEmpty())
- {
- vhostConfiguration = vhostConfig;
- }
- else
- {
- // Load from the external configuration if possible
- for (String fileName : vhostFiles)
- {
- // Open the vhosts XML file and copy values from it to our config
- _vhostsFile = new File(fileName);
- if (!_vhostsFile.exists())
- {
- throw new ConfigurationException("Virtualhosts file does not exist");
- }
- vhostConfiguration = parseConfig(new File(fileName));
-
- // save the default virtualhost name
- String defaultVirtualHost = vhostConfiguration.getString("default");
- getConfig().setProperty("virtualhosts.default", defaultVirtualHost);
- }
- }
-
- // Now extract the virtual host names from the configuration object
- List hosts = vhostConfiguration.getList("virtualhost.name");
- for (int j = 0; j < hosts.size(); j++)
- {
- String name = (String) hosts.get(j);
-
- // Add the virtual hosts to the server configuration
- VirtualHostConfiguration virtualhost = new VirtualHostConfiguration(name, vhostConfiguration.subset("virtualhost." + name));
- _virtualHosts.put(virtualhost.getName(), virtualhost);
- }
- }
-
- private static void substituteEnvironmentVariables(Configuration conf)
- {
- for (Entry<String, String> var : envVarMap.entrySet())
- {
- String val = System.getenv(var.getKey());
- if (val != null)
- {
- conf.setProperty(var.getValue(), val);
- }
- }
- }
-
- private static Configuration parseConfig(File file) throws ConfigurationException
- {
- ConfigurationFactory factory = new ConfigurationFactory();
- factory.setConfigurationFileName(file.getAbsolutePath());
- Configuration conf = factory.getConfiguration();
-
- Iterator<?> keys = conf.getKeys();
- if (!keys.hasNext())
- {
- keys = null;
- conf = flatConfig(file);
- }
-
- substituteEnvironmentVariables(conf);
-
- return conf;
- }
-
- /**
- * Check the configuration file to see if status updates are enabled.
- *
- * @return true if status updates are enabled
- */
- public boolean getStatusUpdatesEnabled()
- {
- // Retrieve the setting from configuration but default to on.
- String value = getStringValue(STATUS_UPDATES, DEFAULT_STATUS_UPDATES);
-
- return value.equalsIgnoreCase("on");
- }
-
- /**
- * The currently defined {@see Locale} for this broker
- *
- * @return the configuration defined locale
- */
- public Locale getLocale()
- {
- String localeString = getStringValue(ADVANCED_LOCALE);
- // Expecting locale of format langauge_country_variant
-
- // If the configuration does not have a defined locale use the JVM default
- if (localeString == null)
- {
- return Locale.getDefault();
- }
-
- String[] parts = localeString.split("_");
-
- Locale locale;
- switch (parts.length)
- {
- case 1:
- locale = new Locale(localeString);
- break;
- case 2:
- locale = new Locale(parts[0], parts[1]);
- break;
- default:
- StringBuilder variant = new StringBuilder(parts[2]);
- // If we have a variant such as the Java doc suggests for Spanish
- // Traditional_WIN we may end up with more than 3 parts on a
- // split with '_'. So we should recombine the variant.
- if (parts.length > 3)
- {
- for (int index = 3; index < parts.length; index++)
- {
- variant.append('_').append(parts[index]);
- }
- }
-
- locale = new Locale(parts[0], parts[1], variant.toString());
- }
-
- return locale;
- }
-
- // Our configuration class needs to make the interpolate method
- // public so it can be called below from the config method.
- public static class MyConfiguration extends CompositeConfiguration
- {
- public String interpolate(String obj)
- {
- return super.interpolate(obj);
- }
- }
-
- public final static Configuration flatConfig(File file) throws ConfigurationException
- {
- // We have to override the interpolate methods so that
- // interpolation takes place across the entirety of the
- // composite configuration. Without doing this each
- // configuration object only interpolates variables defined
- // inside itself.
- final MyConfiguration conf = new MyConfiguration();
- conf.addConfiguration(new SystemConfiguration()
- {
- protected String interpolate(String o)
- {
- return conf.interpolate(o);
- }
- });
- conf.addConfiguration(new XMLConfiguration(file)
- {
- protected String interpolate(String o)
- {
- return conf.interpolate(o);
- }
- });
- return conf;
- }
-
- public String getConfigurationURL()
- {
- return _configFile == null ? "" : _configFile.getAbsolutePath();
- }
-
- public void reparseConfigFileSecuritySections() throws ConfigurationException
- {
- if (_configFile != null)
- {
- Configuration newConfig = parseConfig(_configFile);
- setConfiguration("", newConfig);
- ApplicationRegistry.getInstance().getSecurityManager().configureHostPlugins(this);
-
- // Reload virtualhosts from correct location
- Configuration newVhosts;
- if (_vhostsFile == null)
- {
- newVhosts = newConfig.subset("virtualhosts");
- }
- else
- {
- newVhosts = parseConfig(_vhostsFile);
- }
-
- VirtualHostRegistry vhostRegistry = ApplicationRegistry.getInstance().getVirtualHostRegistry();
- for (String hostName : _virtualHosts.keySet())
- {
- VirtualHost vhost = vhostRegistry.getVirtualHost(hostName);
- Configuration vhostConfig = newVhosts.subset("virtualhost." + hostName);
- vhost.getConfiguration().setConfiguration("virtualhosts.virtualhost", vhostConfig);
- vhost.getSecurityManager().configureGlobalPlugins(this);
- vhost.getSecurityManager().configureHostPlugins(vhost.getConfiguration());
- }
-
- _logger.warn(SECURITY_CONFIG_RELOADED);
- }
- }
-
- public String getQpidWork()
- {
- if ( _qpidWork == null )
- {
- return System.getProperty(QPID_WORK, System.getProperty("java.io.tmpdir"));
- }
- else
- {
- return _qpidWork;
- }
- }
-
- public String getQpidHome()
- {
- if ( _qpidHome == null )
- {
- return System.getProperty(QPID_HOME);
- }
- else
- {
- return _qpidHome;
- }
- }
-
- public void setJMXPortRegistryServer(int registryServerPort)
- {
- getConfig().setProperty(MGMT_JMXPORT_REGISTRYSERVER, registryServerPort);
- }
-
- public int getJMXPortRegistryServer()
- {
- return getIntValue(MGMT_JMXPORT_REGISTRYSERVER, DEFAULT_JMXPORT_REGISTRYSERVER);
- }
-
- public void setJMXPortConnectorServer(int connectorServerPort)
- {
- getConfig().setProperty(MGMT_JMXPORT_CONNECTORSERVER, connectorServerPort);
- }
-
- public int getJMXConnectorServerPort()
- {
- return getIntValue(MGMT_JMXPORT_CONNECTORSERVER, getJMXPortRegistryServer() + JMXPORT_CONNECTORSERVER_OFFSET);
- }
-
- public boolean getUseCustomRMISocketFactory()
- {
- return getBooleanValue(MGMT_CUSTOM_REGISTRY_SOCKET, true);
- }
-
- public void setUseCustomRMISocketFactory(boolean bool)
- {
- getConfig().setProperty(MGMT_CUSTOM_REGISTRY_SOCKET, bool);
- }
-
- public boolean getPlatformMbeanserver()
- {
- return getBooleanValue("management.platform-mbeanserver", true);
- }
-
- public boolean getHTTPManagementEnabled()
- {
- return getBooleanValue("management.http.enabled", true);
- }
-
- public int getHTTPManagementPort()
- {
- return getIntValue("management.http.port", DEFAULT_HTTP_MANAGEMENT_PORT);
- }
-
- public boolean getHTTPSManagementEnabled()
- {
- return getBooleanValue("management.https.enabled", false);
- }
-
- public int getHTTPSManagementPort()
- {
- return getIntValue("management.https.port", DEFAULT_HTTPS_MANAGEMENT_PORT);
- }
-
- public String[] getVirtualHosts()
- {
- return _virtualHosts.keySet().toArray(new String[_virtualHosts.size()]);
- }
-
- public String getPluginDirectory()
- {
- return getStringValue("plugin-directory");
- }
-
- public String getCacheDirectory()
- {
- return getStringValue("cache-directory");
- }
-
- public VirtualHostConfiguration getVirtualHostConfig(String name)
- {
- return _virtualHosts.get(name);
- }
-
- public void setVirtualHostConfig(VirtualHostConfiguration config)
- {
- _virtualHosts.put(config.getName(), config);
- }
-
- public int getFrameSize()
- {
- return getIntValue("advanced.framesize", DEFAULT_FRAME_SIZE);
- }
-
- public boolean getSynchedClocks()
- {
- return getBooleanValue("advanced.synced-clocks");
- }
-
- public boolean getMsgAuth()
- {
- return getBooleanValue("security.msg-auth");
- }
-
- public String getDefaultAuthenticationManager()
- {
- return getStringValue(SECURITY_DEFAULT_AUTH_MANAGER);
- }
-
- public Map<Integer, String> getPortAuthenticationMappings()
- {
- String[] ports = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_PORT);
- String[] authManagers = getConfig().getStringArray(SECURITY_PORT_MAPPINGS_PORT_MAPPING_AUTH_MANAGER);
-
- Map<Integer,String> portMappings = new HashMap<Integer, String>();
- for(int i = 0; i < ports.length; i++)
- {
- portMappings.put(Integer.valueOf(ports[i]), authManagers[i]);
- }
-
- return portMappings;
- }
-
-
- public String getManagementKeyStorePath()
- {
- final String fallback = getStringValue("management.ssl.keystorePath");
- return getStringValue("management.ssl.keyStorePath", fallback);
- }
-
- public boolean getManagementSSLEnabled()
- {
- return getBooleanValue("management.ssl.enabled", false);
- }
-
- public String getManagementKeyStorePassword()
- {
- final String fallback = getStringValue("management.ssl.keystorePassword");
- return getStringValue("management.ssl.keyStorePassword", fallback);
- }
-
- public boolean getQueueAutoRegister()
- {
- return getBooleanValue("queue.auto_register", true);
- }
-
- public boolean getJMXManagementEnabled()
- {
- return getBooleanValue("management.enabled", true);
- }
-
- public int getHeartBeatDelay()
- {
- return getIntValue("heartbeat.delay", 5);
- }
-
- public double getHeartBeatTimeout()
- {
- return getDoubleValue("heartbeat.timeoutFactor", 2.0);
- }
-
- public long getMaximumMessageAge()
- {
- return getLongValue("maximumMessageAge");
- }
-
- public long getMaximumMessageCount()
- {
- return getLongValue("maximumMessageCount");
- }
-
- public long getMaximumQueueDepth()
- {
- return getLongValue("maximumQueueDepth");
- }
-
- public long getMaximumMessageSize()
- {
- return getLongValue("maximumMessageSize");
- }
-
- public long getMinimumAlertRepeatGap()
- {
- return getLongValue("minimumAlertRepeatGap", DEFAULT_MINIMUM_ALERT_REPEAT_GAP);
- }
-
- public long getCapacity()
- {
- return getLongValue("capacity");
- }
-
- public long getFlowResumeCapacity()
- {
- return getLongValue("flowResumeCapacity", getCapacity());
- }
-
- public int getConnectorProcessors()
- {
- return getIntValue("connector.processors", 4);
- }
-
- public List getPorts()
- {
- return getListValue("connector.port", Collections.<Integer>singletonList(DEFAULT_PORT));
- }
-
- public List getPortExclude10()
- {
- return getListValue("connector.non10port");
- }
-
- public List getPortExclude010()
- {
- return getListValue("connector.non010port");
- }
-
- public List getPortExclude091()
- {
- return getListValue("connector.non091port");
- }
-
- public List getPortExclude09()
- {
- return getListValue("connector.non09port");
- }
-
- public List getPortExclude08()
- {
- return getListValue("connector.non08port");
- }
-
- public List getPortInclude08()
- {
- return getListValue(CONNECTOR_INCLUDE_08);
- }
-
- public List getPortInclude09()
- {
- return getListValue(CONNECTOR_INCLUDE_09);
- }
-
- public List getPortInclude091()
- {
- return getListValue(CONNECTOR_INCLUDE_091);
- }
-
- public List getPortInclude010()
- {
- return getListValue(CONNECTOR_INCLUDE_010);
- }
-
- public List getPortInclude10()
- {
- return getListValue(CONNECTOR_INCLUDE_10);
- }
-
- public String getBind()
- {
- return getStringValue("connector.bind", WILDCARD_ADDRESS);
- }
-
- public int getReceiveBufferSize()
- {
- return getIntValue("connector.socketReceiveBuffer", DEFAULT_BUFFER_SIZE);
- }
-
- public int getWriteBufferSize()
- {
- return getIntValue("connector.socketWriteBuffer", DEFAULT_BUFFER_SIZE);
- }
-
- public boolean getTcpNoDelay()
- {
- return getBooleanValue("connector.tcpNoDelay", true);
- }
-
- public boolean getEnableSSL()
- {
- return getBooleanValue("connector.ssl.enabled");
- }
-
- public boolean getSSLOnly()
- {
- return getBooleanValue("connector.ssl.sslOnly");
- }
-
- public List getSSLPorts()
- {
- return getListValue("connector.ssl.port", Collections.<Integer>singletonList(DEFAULT_SSL_PORT));
- }
-
- public String getConnectorKeyStorePath()
- {
- final String fallback = getStringValue("connector.ssl.keystorePath"); // pre-0.13 broker supported this name.
- return getStringValue("connector.ssl.keyStorePath", fallback);
- }
-
- public String getConnectorKeyStorePassword()
- {
- final String fallback = getStringValue("connector.ssl.keystorePassword"); // pre-0.13 brokers supported this name.
- return getStringValue("connector.ssl.keyStorePassword", fallback);
- }
-
- public String getConnectorKeyStoreType()
- {
- return getStringValue("connector.ssl.keyStoreType", "JKS");
- }
-
- public String getConnectorKeyManagerFactoryAlgorithm()
- {
- final String systemFallback = KeyManagerFactory.getDefaultAlgorithm();
- // deprecated, pre-0.17 brokers supported this name.
- final String fallback = getStringValue("connector.ssl.certType", systemFallback);
- return getStringValue("connector.ssl.keyManagerFactoryAlgorithm", fallback);
- }
-
- public String getConnectorTrustStorePath()
- {
- return getStringValue("connector.ssl.trustStorePath", null);
- }
-
- public String getConnectorTrustStorePassword()
- {
- return getStringValue("connector.ssl.trustStorePassword", null);
- }
-
- public String getConnectorTrustStoreType()
- {
- return getStringValue("connector.ssl.trustStoreType", "JKS");
- }
-
- public String getConnectorTrustManagerFactoryAlgorithm()
- {
- return getStringValue("connector.ssl.trustManagerFactoryAlgorithm", TrustManagerFactory.getDefaultAlgorithm());
- }
-
- public String getCertAlias()
- {
- return getStringValue("connector.ssl.certAlias", null);
- }
-
- public boolean needClientAuth()
- {
- return getConfig().getBoolean("connector.ssl.needClientAuth", false);
- }
-
- public boolean wantClientAuth()
- {
- return getConfig().getBoolean("connector.ssl.wantClientAuth", false);
- }
-
- public String getDefaultVirtualHost()
- {
- return getStringValue("virtualhosts.default");
- }
-
- public void setDefaultVirtualHost(String vhost)
- {
- getConfig().setProperty("virtualhosts.default", vhost);
- }
-
- public void setHousekeepingCheckPeriod(long value)
- {
- getConfig().setProperty("housekeeping.checkPeriod", value);
- }
-
- public long getHousekeepingCheckPeriod()
- {
- return getLongValue("housekeeping.checkPeriod", DEFAULT_HOUSEKEEPING_PERIOD);
- }
-
- public long getStatisticsSamplePeriod()
- {
- return getConfig().getLong("statistics.sample.period", 5000L);
- }
-
- public boolean isStatisticsGenerationBrokerEnabled()
- {
- return getConfig().getBoolean("statistics.generation.broker", false);
- }
-
- public boolean isStatisticsGenerationVirtualhostsEnabled()
- {
- return getConfig().getBoolean("statistics.generation.virtualhosts", false);
- }
-
- public boolean isStatisticsGenerationConnectionsEnabled()
- {
- return getConfig().getBoolean("statistics.generation.connections", false);
- }
-
- public long getStatisticsReportingPeriod()
- {
- return getConfig().getLong("statistics.reporting.period", 0L);
- }
-
- public boolean isStatisticsReportResetEnabled()
- {
- return getConfig().getBoolean("statistics.reporting.reset", false);
- }
-
- public int getMaxChannelCount()
- {
- return getIntValue("maximumChannelCount", 256);
- }
-
- /**
- * List of Broker features that have been disabled within configuration. Disabled
- * features won't be advertised to the clients on connection.
- *
- * @return list of disabled features, or empty list if no features are disabled.
- */
- public List<String> getDisabledFeatures()
- {
- final List<String> disabledFeatures = getListValue("disabledFeatures", Collections.emptyList());
- return disabledFeatures;
- }
-
- public boolean getManagementRightsInferAllAccess()
- {
- return getBooleanValue("management.managementRightsInferAllAccess", true);
- }
-
- public int getMaxDeliveryCount()
- {
- return getConfig().getInt("maximumDeliveryCount", 0);
- }
-
- /**
- * Check if dead letter queue delivery is enabled, defaults to disabled if not set.
- */
- public boolean isDeadLetterQueueEnabled()
- {
- return getConfig().getBoolean("deadLetterQueues", false);
- }
-
- /**
- * String to affix to end of queue name when generating an alternate exchange for DLQ purposes.
- */
- public String getDeadLetterExchangeSuffix()
- {
- return getConfig().getString("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
- }
-
- /**
- * String to affix to end of queue name when generating a queue for DLQ purposes.
- */
- public String getDeadLetterQueueSuffix()
- {
- return getConfig().getString("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
- }
-
- public boolean isAmqp10enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP10ENABLED, true);
- }
-
- public boolean isAmqp010enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP010ENABLED, true);
- }
-
- public boolean isAmqp091enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP091ENABLED, true);
- }
-
- public boolean isAmqp09enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP09ENABLED, true);
- }
-
- public boolean isAmqp08enabled()
- {
- return getConfig().getBoolean(CONNECTOR_AMQP08ENABLED, true);
- }
-
- /**
- * Returns the configured default reply to an unsupported AMQP protocol initiation, or null if there is none
- */
- public AmqpProtocolVersion getDefaultSupportedProtocolReply()
- {
- String reply = getConfig().getString(CONNECTOR_AMQP_SUPPORTED_REPLY, null);
-
- return reply == null ? null : AmqpProtocolVersion.valueOf(reply);
- }
-
- public void setQpidWork(String path)
- {
- _qpidWork = path;
- }
-
- public void setQpidHome(String path)
- {
- _qpidHome = path;
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java
deleted file mode 100644
index 51dcc38c47..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerNetworkTransportConfiguration.java
+++ /dev/null
@@ -1,90 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import java.net.InetSocketAddress;
-import org.apache.qpid.transport.NetworkTransportConfiguration;
-
-public class ServerNetworkTransportConfiguration implements NetworkTransportConfiguration
-{
- private final ServerConfiguration _serverConfig;
- private final String _transport;
- private InetSocketAddress _address;
-
- public ServerNetworkTransportConfiguration(final ServerConfiguration serverConfig,
- final InetSocketAddress address,
- final String transport)
- {
- _serverConfig = serverConfig;
- _address = address;
- _transport = transport;
- }
-
- public Boolean getTcpNoDelay()
- {
- return _serverConfig.getTcpNoDelay();
- }
-
- public Integer getSendBufferSize()
- {
- return _serverConfig.getWriteBufferSize();
- }
-
- public Integer getReceiveBufferSize()
- {
- return _serverConfig.getReceiveBufferSize();
- }
-
- public Integer getPort()
- {
- return _address.getPort();
- }
-
- public String getHost()
- {
- return _address.getHostName();
- }
-
- public String getTransport()
- {
- return _transport;
- }
-
- public Integer getConnectorProcessors()
- {
- return _serverConfig.getConnectorProcessors();
- }
-
- public InetSocketAddress getAddress()
- {
- return _address;
- }
-
- public boolean needClientAuth()
- {
- return _serverConfig.needClientAuth();
- }
-
- @Override
- public boolean wantClientAuth()
- {
- return _serverConfig.wantClientAuth();
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfig.java
deleted file mode 100644
index 8fef642eff..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfig.java
+++ /dev/null
@@ -1,55 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import org.apache.qpid.AMQException;
-
-public interface SessionConfig extends ConfiguredObject<SessionConfigType, SessionConfig>
-{
- VirtualHostConfig getVirtualHost();
-
- String getSessionName();
-
- int getChannel();
-
- ConnectionConfig getConnectionConfig();
-
- boolean isAttached();
-
- long getDetachedLifespan();
-
- Long getExpiryTime();
-
- Long getMaxClientRate();
-
- Long getTxnStarts();
-
- Long getTxnCommits();
-
- Long getTxnRejects();
-
- Long getTxnCount();
-
- boolean isTransactional();
-
- void mgmtClose() throws AMQException;
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfigType.java
deleted file mode 100644
index 1685cfab60..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SessionConfigType.java
+++ /dev/null
@@ -1,137 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public final class SessionConfigType extends ConfigObjectType<SessionConfigType, SessionConfig>
-{
- private static final List<SessionProperty<?>> SESSION_PROPERTIES = new ArrayList<SessionProperty<?>>();
-
- public static interface SessionProperty<S> extends ConfigProperty<SessionConfigType, SessionConfig, S>
- {
- }
-
- private abstract static class SessionReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<SessionConfigType, SessionConfig, S> implements SessionProperty<S>
- {
- public SessionReadWriteProperty(String name)
- {
- super(name);
- SESSION_PROPERTIES.add(this);
- }
- }
-
- private abstract static class SessionReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<SessionConfigType, SessionConfig, S> implements SessionProperty<S>
- {
- public SessionReadOnlyProperty(String name)
- {
- super(name);
- SESSION_PROPERTIES.add(this);
- }
- }
-
- public static final SessionReadOnlyProperty<VirtualHostConfig> VIRTUAL_HOST_PROPERTY = new SessionReadOnlyProperty<VirtualHostConfig>("virtualHost")
- {
- public VirtualHostConfig getValue(SessionConfig object)
- {
- return object.getVirtualHost();
- }
- };
-
- public static final SessionReadOnlyProperty<String> NAME_PROPERTY = new SessionReadOnlyProperty<String>("name")
- {
- public String getValue(SessionConfig object)
- {
- return object.getSessionName();
- }
- };
-
- public static final SessionReadOnlyProperty<Integer> CHANNEL_ID_PROPERTY = new SessionReadOnlyProperty<Integer>("channelId")
- {
- public Integer getValue(SessionConfig object)
- {
- return object.getChannel();
- }
- };
-
- public static final SessionReadOnlyProperty<ConnectionConfig> CONNECTION_PROPERTY = new SessionReadOnlyProperty<ConnectionConfig>("connection")
- {
- public ConnectionConfig getValue(SessionConfig object)
- {
- return object.getConnectionConfig();
- }
- };
-
- public static final SessionReadOnlyProperty<Boolean> ATTACHED_PROPERTY = new SessionReadOnlyProperty<Boolean>("attached")
- {
- public Boolean getValue(SessionConfig object)
- {
- return object.isAttached();
- }
- };
-
- public static final SessionReadOnlyProperty<Long> DETACHED_LIFESPAN_PROPERTY = new SessionReadOnlyProperty<Long>("detachedLifespan")
- {
- public Long getValue(SessionConfig object)
- {
- return object.getDetachedLifespan();
- }
- };
-
- public static final SessionReadOnlyProperty<Long> EXPIRE_TIME_PROPERTY = new SessionReadOnlyProperty<Long>("expireTime")
- {
- public Long getValue(SessionConfig object)
- {
- return object.getExpiryTime();
- }
- };
-
- public static final SessionReadOnlyProperty<Long> MAX_CLIENT_RATE_PROPERTY = new SessionReadOnlyProperty<Long>("maxClientRate")
- {
- public Long getValue(SessionConfig object)
- {
- return object.getMaxClientRate();
- }
- };
-
- private static final SessionConfigType INSTANCE = new SessionConfigType();
-
- private SessionConfigType()
- {
- }
-
- public Collection<SessionProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(SESSION_PROPERTIES);
- }
-
- public static SessionConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfig.java
deleted file mode 100644
index b101d70553..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfig.java
+++ /dev/null
@@ -1,47 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.Map;
-
-
-public interface SubscriptionConfig extends ConfiguredObject<SubscriptionConfigType, SubscriptionConfig>
-{
-
- SessionConfig getSessionConfig();
-
- QueueConfig getQueue();
-
- String getName();
-
- Map<String, Object> getArguments();
-
- String getCreditMode();
-
- boolean isBrowsing();
-
- boolean isExclusive();
-
- boolean isExplicitAcknowledge();
-
- Long getDelivered();
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfigType.java
deleted file mode 100644
index 7b7848dd87..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SubscriptionConfigType.java
+++ /dev/null
@@ -1,140 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-public final class SubscriptionConfigType extends ConfigObjectType<SubscriptionConfigType, SubscriptionConfig>
-{
- private static final List<SubscriptionProperty<?>> SUBSCRIPTION_PROPERTIES = new ArrayList<SubscriptionProperty<?>>();
-
- public static interface SubscriptionProperty<S> extends ConfigProperty<SubscriptionConfigType, SubscriptionConfig, S>
- {
- }
-
- private abstract static class SubscriptionReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<SubscriptionConfigType, SubscriptionConfig, S> implements SubscriptionProperty<S>
- {
- public SubscriptionReadWriteProperty(String name)
- {
- super(name);
- SUBSCRIPTION_PROPERTIES.add(this);
- }
- }
-
- private abstract static class SubscriptionReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<SubscriptionConfigType, SubscriptionConfig, S> implements SubscriptionProperty<S>
- {
- public SubscriptionReadOnlyProperty(String name)
- {
- super(name);
- SUBSCRIPTION_PROPERTIES.add(this);
- }
- }
-
- public static final SubscriptionReadOnlyProperty<SessionConfig> SESSION_PROPERTY = new SubscriptionReadOnlyProperty<SessionConfig>("session")
- {
- public SessionConfig getValue(SubscriptionConfig object)
- {
- return object.getSessionConfig();
- }
- };
-
- public static final SubscriptionReadOnlyProperty<QueueConfig> QUEUE_PROPERTY = new SubscriptionReadOnlyProperty<QueueConfig>("queue")
- {
- public QueueConfig getValue(SubscriptionConfig object)
- {
- return object.getQueue();
- }
- };
-
- public static final SubscriptionReadOnlyProperty<String> NAME_PROPERTY = new SubscriptionReadOnlyProperty<String>("name")
- {
- public String getValue(SubscriptionConfig object)
- {
- return object.getName();
- }
- };
-
- public static final SubscriptionReadOnlyProperty<Map<String,Object>> ARGUMENTS = new SubscriptionReadOnlyProperty<Map<String,Object>>("arguments")
- {
- public Map<String,Object> getValue(SubscriptionConfig object)
- {
- return object.getArguments();
- }
- };
-
- public static final SubscriptionReadOnlyProperty<String> CREDIT_MODE_PROPERTY = new SubscriptionReadOnlyProperty<String>("creditMode")
- {
- public String getValue(SubscriptionConfig object)
- {
- return object.getCreditMode();
- }
- };
-
- public static final SubscriptionReadOnlyProperty<Boolean> BROWSING_PROPERTY = new SubscriptionReadOnlyProperty<Boolean>("browsing")
- {
- public Boolean getValue(SubscriptionConfig object)
- {
- return object.isBrowsing();
- }
- };
-
- public static final SubscriptionReadOnlyProperty<Boolean> EXCLUSIVE_PROPERTY = new SubscriptionReadOnlyProperty<Boolean>("exclusive")
- {
- public Boolean getValue(SubscriptionConfig object)
- {
- return object.isExclusive();
- }
- };
-
- public static final SubscriptionReadOnlyProperty<Boolean> EXPLICIT_ACK_PROPERTY = new SubscriptionReadOnlyProperty<Boolean>("explicitAck")
- {
- public Boolean getValue(SubscriptionConfig object)
- {
- return object.isExplicitAcknowledge();
- }
- };
-
- private static final SubscriptionConfigType INSTANCE = new SubscriptionConfigType();
-
- private SubscriptionConfigType()
- {
- }
-
- public Collection<SubscriptionProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(SUBSCRIPTION_PROPERTIES);
- }
-
-
- public static SubscriptionConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfig.java
deleted file mode 100644
index 8a9029fbfd..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfig.java
+++ /dev/null
@@ -1,42 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-public interface SystemConfig extends ConfiguredObject<SystemConfigType,SystemConfig>
-{
- String getName();
-
- String getOperatingSystemName();
-
- String getNodeName();
-
-
- String getOSRelease();
-
- String getOSVersion();
-
- String getOSArchitecture();
-
- void addBroker(BrokerConfig broker);
-
- void removeBroker(BrokerConfig broker);
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigImpl.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigImpl.java
deleted file mode 100644
index 80c2e8b2f1..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigImpl.java
+++ /dev/null
@@ -1,137 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class SystemConfigImpl implements SystemConfig
-{
- private static final String OS_NAME = System.getProperty("os.name");
- private static final String OS_ARCH = System.getProperty("os.arch");
- private static final String OS_VERSION = System.getProperty("os.version");
-
- private final UUID _qmfId;
- private String _name;
-
- private final String _host;
-
- private final Map<UUID, BrokerConfig> _brokers = new ConcurrentHashMap<UUID, BrokerConfig>();
-
- private final long _createTime = System.currentTimeMillis();
- private final ConfigStore _store;
-
- public SystemConfigImpl(ConfigStore store)
- {
- this(store.createId(), store);
- }
-
- public SystemConfigImpl(UUID qmfId, ConfigStore store)
- {
- _qmfId = qmfId;
- _store = store;
- String host;
- try
- {
- InetAddress addr = InetAddress.getLocalHost();
- host = addr.getHostName();
- }
- catch (UnknownHostException e)
- {
- host="localhost";
- }
- _host = host;
- }
-
- public String getName()
- {
- return _name;
- }
-
- public String getOperatingSystemName()
- {
- return OS_NAME;
- }
-
- public String getNodeName()
- {
- return _host;
- }
-
- public String getOSRelease()
- {
- return OS_VERSION;
- }
-
- public String getOSVersion()
- {
- return "";
- }
-
- public String getOSArchitecture()
- {
- return OS_ARCH;
- }
-
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public SystemConfigType getConfigType()
- {
- return SystemConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return null;
- }
-
- public boolean isDurable()
- {
- return false;
- }
-
- public void addBroker(final BrokerConfig broker)
- {
- broker.setSystem(this);
- _store.addConfiguredObject(broker);
- _brokers.put(broker.getQMFId(), broker);
- }
-
- public void removeBroker(final BrokerConfig broker)
- {
- _brokers.remove(broker.getQMFId());
- _store.removeConfiguredObject(broker);
- }
-
- public long getCreateTime()
- {
- return _createTime;
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigType.java
deleted file mode 100644
index 4a383cce7a..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/SystemConfigType.java
+++ /dev/null
@@ -1,132 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
-public final class SystemConfigType extends ConfigObjectType<SystemConfigType, SystemConfig>
-{
- private static final List<SystemProperty<?>> SYSTEM_PROPERTIES = new ArrayList<SystemProperty<?>>();
-
- public static interface SystemProperty<S> extends ConfigProperty<SystemConfigType, SystemConfig, S>
- {
- }
-
- private abstract static class SystemReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<SystemConfigType, SystemConfig, S> implements SystemProperty<S>
- {
- public SystemReadWriteProperty(String name)
- {
- super(name);
- SYSTEM_PROPERTIES.add(this);
- }
- }
-
- private abstract static class SystemReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<SystemConfigType, SystemConfig, S> implements SystemProperty<S>
- {
- public SystemReadOnlyProperty(String name)
- {
- super(name);
- SYSTEM_PROPERTIES.add(this);
- }
- }
-
- public static final SystemReadOnlyProperty<String> NAME_PROPERTY = new SystemReadOnlyProperty<String>("name")
- {
- public String getValue(SystemConfig object)
- {
- return object.getName();
- }
- };
-
- public static final SystemReadOnlyProperty<UUID> ID_PROPERTY = new SystemReadOnlyProperty<UUID>("id")
- {
- public UUID getValue(SystemConfig object)
- {
- return object.getQMFId();
- }
- };
-
- public static final SystemReadOnlyProperty<String> OS_NAME_PROPERTY = new SystemReadOnlyProperty<String>("osName")
- {
- public String getValue(SystemConfig object)
- {
- return object.getOperatingSystemName();
- }
- };
-
- public static final SystemReadOnlyProperty<String> NODE_NAME_PROPERTY = new SystemReadOnlyProperty<String>("nodeName")
- {
- public String getValue(SystemConfig object)
- {
- return object.getNodeName();
- }
- };
-
- public static final SystemReadOnlyProperty<String> RELEASE_PROPERTY = new SystemReadOnlyProperty<String>("release")
- {
- public String getValue(SystemConfig object)
- {
- return object.getOSRelease();
- }
- };
-
- public static final SystemReadOnlyProperty<String> VERSION_PROPERTY = new SystemReadOnlyProperty<String>("version")
- {
- public String getValue(SystemConfig object)
- {
- return object.getOSVersion();
- }
- };
-
- public static final SystemReadOnlyProperty<String> MACHINE_PROPERTY = new SystemReadOnlyProperty<String>("machine")
- {
- public String getValue(SystemConfig object)
- {
- return object.getOSArchitecture();
- }
- };
-
- private static final SystemConfigType INSTANCE = new SystemConfigType();
-
- private SystemConfigType()
- {
- }
-
- public Collection<SystemProperty<?>> getProperties()
- {
- return Collections.unmodifiableList(SYSTEM_PROPERTIES);
- }
-
-
-
- public static SystemConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfig.java
deleted file mode 100644
index aaa1766489..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfig.java
+++ /dev/null
@@ -1,78 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-
-public class TopicConfig extends ConfigurationPlugin
-{
- public TopicConfig()
- {
- setConfig(new PropertiesConfiguration());
- }
-
- @Override
- public String[] getElementsProcessed()
- {
- return new String[]{"name", "subscriptionName"};
- }
-
- public String getName()
- {
- // If we don't have a specific topic then this config is for all topics.
- return getStringValue("name", "#");
- }
-
- public String getSubscriptionName()
- {
- return getStringValue("subscriptionName");
- }
-
- public void validateConfiguration() throws ConfigurationException
- {
- if (getConfig().isEmpty())
- {
- throw new ConfigurationException("Topic section cannot be empty.");
- }
-
- if (getStringValue("name") == null && getSubscriptionName() == null)
- {
- throw new ConfigurationException("Topic section must have a 'name' or 'subscriptionName' element.");
- }
-
- }
-
-
- @Override
- public String formatToString()
- {
- String response = "Topic:"+getName();
- if (getSubscriptionName() != null)
- {
- response += ", SubscriptionName:"+getSubscriptionName();
- }
-
- return response;
- }
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfiguration.java
deleted file mode 100644
index feafd3de1d..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/TopicConfiguration.java
+++ /dev/null
@@ -1,270 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.exchange.TopicExchange;
-import org.apache.qpid.server.queue.AMQQueue;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-public class TopicConfiguration extends ConfigurationPlugin implements ExchangeConfigurationPlugin
-{
- public static final ConfigurationPluginFactory FACTORY = new TopicConfigurationFactory();
-
- private static final String VIRTUALHOSTS_VIRTUALHOST_TOPICS = "virtualhosts.virtualhost.topics";
-
- public static class TopicConfigurationFactory implements ConfigurationPluginFactory
- {
-
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- TopicConfiguration topicsConfig = new TopicConfiguration();
- topicsConfig.setConfiguration(path, config);
- return topicsConfig;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList(VIRTUALHOSTS_VIRTUALHOST_TOPICS);
- }
- }
-
- private Map<String, TopicConfig> _topics = new HashMap<String, TopicConfig>();
- private Map<String, Map<String, TopicConfig>> _subscriptions = new HashMap<String, Map<String, TopicConfig>>();
-
- public String[] getElementsProcessed()
- {
- return new String[]{"topic"};
- }
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- if (getConfig().isEmpty())
- {
- throw new ConfigurationException("Topics section cannot be empty.");
- }
-
- int topics = getConfig().getList("topic.name").size() +
- getConfig().getList("topic.subscriptionName").size();
-
- for (int index = 0; index < topics; index++)
- {
- Configuration topicSubset = getConfig().subset("topic(" + index + ")");
-
- // This will occur when we have a subscriptionName that is bound to a
- // topic.
- if (topicSubset.isEmpty())
- {
- break;
- }
-
- TopicConfig topic = new TopicConfig();
-
- topic.setConfiguration(VIRTUALHOSTS_VIRTUALHOST_TOPICS + ".topic", topicSubset );
-
- String name = getConfig().getString("topic(" + index + ").name");
- String subscriptionName = getConfig().getString("topic(" + index + ").subscriptionName");
-
- // Record config if subscriptionName is there
- if (subscriptionName != null)
- {
- processSubscription(subscriptionName, topic);
- }
- else
- {
- // Otherwise record config as topic if we have the name
- if (name != null)
- {
- processTopic(name, topic);
- }
- }
- }
- }
-
- /**
- * @param name
- * @param topic
- *
- * @throws org.apache.commons.configuration.ConfigurationException
- *
- */
- private void processTopic(String name, TopicConfig topic) throws ConfigurationException
- {
- if (_topics.containsKey(name))
- {
- throw new ConfigurationException("Topics section cannot contain two entries for the same topic.");
- }
- else
- {
- _topics.put(name, topic);
- }
- }
-
-
- private void processSubscription(String name, TopicConfig topic) throws ConfigurationException
- {
- Map<String,TopicConfig> topics;
- if (_subscriptions.containsKey(name))
- {
- topics = _subscriptions.get(name);
-
- if (topics.containsKey(topic.getName()))
- {
- throw new ConfigurationException("Subcription cannot contain two entries for the same topic.");
- }
- }
- else
- {
- topics = new HashMap<String,TopicConfig>();
- }
-
- topics.put(topic.getName(),topic);
- _subscriptions.put(name, topics);
-
- }
-
- @Override
- public String formatToString()
- {
- return "Topics:" + _topics + ", Subscriptions:" + _subscriptions;
- }
-
- /**
- * This processes the given queue and apply configuration in the following
- * order:
- *
- * Global Topic Values -> Topic Values -> Subscription Values
- *
- * @param queue
- *
- * @return
- */
- public ConfigurationPlugin getConfiguration(AMQQueue queue)
- {
- //Create config with global topic configuration
- TopicConfig config = new TopicConfig();
-
- // Add global topic configuration
- config.addConfiguration(this);
-
- // Process Topic Bindings as these are more generic than subscriptions
- List<TopicConfig> boundToTopics = new LinkedList<TopicConfig>();
-
- //Merge the configuration in the order that they are bound
- for (Binding binding : queue.getBindings())
- {
- if (binding.getExchange().getType().equals(TopicExchange.TYPE))
- {
- // Identify topic for the binding key
- TopicConfig topicConfig = getTopicConfigForRoutingKey(binding.getBindingKey());
- if (topicConfig != null)
- {
- boundToTopics.add(topicConfig);
- }
- }
- }
-
- // If the Queue is bound to a number of topics then only use the global
- // topic configuration.
- // todo - What does it mean in terms of configuration to be bound to a
- // number of topics? Do we try and merge?
- // YES - right thing to do would be to merge from generic to specific.
- // Means we need to be able to get an ordered list of topics for this
- // binding.
- if (boundToTopics.size() == 1)
- {
- config.addConfiguration(boundToTopics.get(0));
- }
-
- // If we have a subscription then attempt to look it up.
- String subscriptionName = queue.getName();
-
- // Apply subscription configurations
- if (_subscriptions.containsKey(subscriptionName))
- {
-
- //Get all the Configuration that this subscription is bound to.
- Map<String, TopicConfig> topics = _subscriptions.get(subscriptionName);
-
- TopicConfig subscriptionSpecificConfig = null;
-
- // See if we have a TopicConfig in topics for a topic we are bound to.
- for (Binding binding : queue.getBindings())
- {
- if (binding.getExchange().getType().equals(TopicExchange.TYPE))
- {
- //todo - What does it mean to have multiple matches?
- // Take the first match we get
- if (subscriptionSpecificConfig == null)
- {
- // lookup the binding to see if we have a match in the subscription configs
- subscriptionSpecificConfig = topics.get(binding.getBindingKey());
- }
- }
- }
-
- //todo we don't account for wild cards here. only explicit matching and all subscriptions
- if (subscriptionSpecificConfig == null)
- {
- // lookup the binding to see if we have a match in the subscription configs
- subscriptionSpecificConfig = topics.get("#");
- }
-
- // Apply subscription specific config.
- if (subscriptionSpecificConfig != null)
- {
- config.addConfiguration(subscriptionSpecificConfig);
- }
- }
- return config;
- }
-
- /**
- * This method should perform the same heuristics as the TopicExchange
- * to attempt to identify a piece of configuration for the give routingKey.
- *
- * i.e. If we have 'stocks.*' defined in the config
- * and we bind 'stocks.appl' then we should return the 'stocks.*'
- * configuration.
- *
- * @param routingkey the key to lookup
- *
- * @return the TopicConfig if found.
- */
- private TopicConfig getTopicConfigForRoutingKey(String routingkey)
- {
- //todo actually perform TopicExchange style lookup not just straight
- // lookup as we are just now.
- return _topics.get(routingkey);
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfig.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfig.java
deleted file mode 100644
index b96ddc56c6..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfig.java
+++ /dev/null
@@ -1,32 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-public interface VirtualHostConfig extends ConfiguredObject<VirtualHostConfigType, VirtualHostConfig>
-{
- String getName();
-
- BrokerConfig getBroker();
-
- String getFederationTag();
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfigType.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfigType.java
deleted file mode 100644
index 16e08e3934..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfigType.java
+++ /dev/null
@@ -1,99 +0,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.
- *
- */
-
-package org.apache.qpid.server.configuration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-public class VirtualHostConfigType extends ConfigObjectType<VirtualHostConfigType, VirtualHostConfig>
-{
- private static final List<VirtualHostProperty<?>> VIRTUAL_HOST_PROPERTIES = new ArrayList<VirtualHostProperty<?>>();
- private static final VirtualHostConfigType INSTANCE = new VirtualHostConfigType();
-public static interface VirtualHostProperty<S> extends ConfigProperty<VirtualHostConfigType, VirtualHostConfig, S>
- {
- }
-
- private abstract static class VirtualHostReadWriteProperty<S> extends ConfigProperty.ReadWriteConfigProperty<VirtualHostConfigType, VirtualHostConfig, S> implements VirtualHostProperty<S>
- {
- public VirtualHostReadWriteProperty(String name)
- {
- super(name);
- VIRTUAL_HOST_PROPERTIES.add(this);
- }
- }
-
- private abstract static class VirtualHostReadOnlyProperty<S> extends ConfigProperty.ReadOnlyConfigProperty<VirtualHostConfigType, VirtualHostConfig, S> implements VirtualHostProperty<S>
- {
- public VirtualHostReadOnlyProperty(String name)
- {
- super(name);
- VIRTUAL_HOST_PROPERTIES.add(this);
- }
- }
-
-
- public static final VirtualHostReadOnlyProperty<String> NAME_PROPERTY = new VirtualHostReadOnlyProperty<String>("name")
- {
- public String getValue(VirtualHostConfig object)
- {
- return object.getName();
- }
- };
-
-
- public static final VirtualHostReadOnlyProperty<BrokerConfig> BROKER_PROPERTY = new VirtualHostReadOnlyProperty<BrokerConfig>("broker")
- {
- public BrokerConfig getValue(VirtualHostConfig object)
- {
- return object.getBroker();
- }
- };
-
- public static final VirtualHostReadOnlyProperty<String> FEDERATION_TAG_PROPERTY = new VirtualHostReadOnlyProperty<String>("federationTag")
- {
- public String getValue(VirtualHostConfig object)
- {
- return object.getFederationTag();
- }
- };
-
-
-
- public Collection<? extends ConfigProperty<VirtualHostConfigType, VirtualHostConfig, ?>> getProperties()
- {
- return Collections.unmodifiableList(VIRTUAL_HOST_PROPERTIES);
- }
-
-
- private VirtualHostConfigType()
- {
- }
-
- public static VirtualHostConfigType getInstance()
- {
- return INSTANCE;
- }
-
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java
index e557085631..eada676b65 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/VirtualHostConfiguration.java
@@ -23,35 +23,66 @@ package org.apache.qpid.server.configuration;
import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+
+import org.apache.qpid.server.configuration.plugins.AbstractConfiguration;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.store.MemoryMessageStore;
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-public class VirtualHostConfiguration extends ConfigurationPlugin
+public class VirtualHostConfiguration extends AbstractConfiguration
{
private final String _name;
private final Map<String, QueueConfiguration> _queues = new HashMap<String, QueueConfiguration>();
private final Map<String, ExchangeConfiguration> _exchanges = new HashMap<String, ExchangeConfiguration>();
+ private final Broker _broker;
+ private final long _defaultHouseKeepingCheckPeriod;
- public VirtualHostConfiguration(String name, Configuration config) throws ConfigurationException
+ public VirtualHostConfiguration(String name, Configuration config, Broker broker) throws ConfigurationException
{
_name = name;
+ _broker = broker;
+
+ // store value of this attribute for running life of virtual host since updating of this value has no run-time effect
+ _defaultHouseKeepingCheckPeriod = ((Number)_broker.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).longValue();
setConfiguration(config);
}
+ public VirtualHostConfiguration(String name, File configurationFile, Broker broker) throws ConfigurationException
+ {
+ this(name, loadConfiguration(name, configurationFile), broker);
+ }
+
+ private static Configuration loadConfiguration(String name, File configurationFile) throws ConfigurationException
+ {
+ Configuration configuration = null;
+ if (configurationFile == null)
+ {
+ throw new IllegalConfigurationException("Virtualhost configuration file must be supplied!");
+ }
+ else
+ {
+ Configuration virtualHostConfig = XmlConfigurationUtilities.parseConfig(configurationFile, null);
+
+ // check if it is an old virtual host configuration file which has an element of the same name as virtual host
+ Configuration config = virtualHostConfig.subset("virtualhost." + XmlConfigurationUtilities.escapeTagName(name));
+ if (config.isEmpty())
+ {
+ // assume it is a new configuration which does not have an element of the same name as the virtual host
+ configuration = virtualHostConfig;
+ }
+ else
+ {
+ configuration = config;
+ }
+ }
+ return configuration;
+ }
+
/**
* Apply the given configuration to this VirtualHostConfiguration
*
@@ -89,12 +120,7 @@ public class VirtualHostConfiguration extends ConfigurationPlugin
public long getHousekeepingCheckPeriod()
{
- return getLongValue("housekeeping.checkPeriod", ApplicationRegistry.getInstance().getConfiguration().getHousekeepingCheckPeriod());
- }
-
- public List getCustomExchanges()
- {
- return getListValue("custom-exchanges.class-name");
+ return getLongValue("housekeeping.checkPeriod", _defaultHouseKeepingCheckPeriod);
}
public Configuration getStoreConfiguration()
@@ -149,138 +175,39 @@ public class VirtualHostConfiguration extends ConfigurationPlugin
}
}
- public ConfigurationPlugin getQueueConfiguration(AMQQueue queue)
- {
- VirtualHostConfiguration hostConfig = queue.getVirtualHost().getConfiguration();
-
- // First check if we have a named queue configuration (the easy case)
- if (Arrays.asList(hostConfig.getQueueNames()).contains(queue.getName()))
- {
- return null;
- }
-
- // We don't have an explicit queue config we must find out what we need.
- ArrayList<Binding> bindings = new ArrayList<Binding>(queue.getBindings());
-
- List<AMQShortString> exchangeClasses = new ArrayList<AMQShortString>(bindings.size());
-
- //Remove default exchange
- for (int index = 0; index < bindings.size(); index++)
- {
- // Ignore the DEFAULT Exchange binding
- if (bindings.get(index).getExchange().getNameShortString().equals(ExchangeDefaults.DEFAULT_EXCHANGE_NAME))
- {
- bindings.remove(index);
- }
- else
- {
- exchangeClasses.add(bindings.get(index).getExchange().getType().getName());
-
- if (exchangeClasses.size() > 1)
- {
- // If we have more than 1 class of exchange then we can only use the global queue configuration.
- // and this will be returned from the default getQueueConfiguration
- return null;
- }
- }
- }
-
- // If we are just bound the the default exchange then use the default.
- if (bindings.isEmpty())
- {
- return null;
- }
-
- // If we are bound to only one type of exchange then we are going
- // to have to resolve the configuration for that exchange.
-
- String exchangeName = bindings.get(0).getExchange().getType().getName().toString();
-
- // Lookup a Configuration handler for this Exchange.
-
- // Build the expected class name. <Exchangename>sConfiguration
- // i.e. TopicConfiguration or HeadersConfiguration
- String exchangeClass = "org.apache.qpid.server.configuration."
- + exchangeName.substring(0, 1).toUpperCase()
- + exchangeName.substring(1) + "Configuration";
-
- ExchangeConfigurationPlugin exchangeConfiguration
- = (ExchangeConfigurationPlugin) queue.getVirtualHost().getConfiguration().getConfiguration(exchangeClass);
-
- // now need to perform the queue-topic-topics-queues magic.
- // So make a new ConfigurationObject that will hold all the configuration for this queue.
- ConfigurationPlugin queueConfig = new QueueConfiguration.QueueConfig();
-
- // Initialise the queue with any Global values we may have
- PropertiesConfiguration newQueueConfig = new PropertiesConfiguration();
- newQueueConfig.setProperty("name", queue.getName());
-
- try
- {
- //Set the queue name
- CompositeConfiguration mungedConf = new CompositeConfiguration();
- //Set the queue name
- mungedConf.addConfiguration(newQueueConfig);
- //Set the global queue configuration
- mungedConf.addConfiguration(getConfig().subset("queues"));
-
- // Set configuration
- queueConfig.setConfiguration("virtualhosts.virtualhost.queues", mungedConf);
- }
- catch (ConfigurationException e)
- {
- // This will not occur as queues only require a name.
- _logger.error("QueueConfiguration requirements have changed.");
- }
-
- // Merge any configuration the Exchange wishes to apply
- if (exchangeConfiguration != null)
- {
- queueConfig.addConfiguration(exchangeConfiguration.getConfiguration(queue));
- }
-
- //Finally merge in any specific queue configuration we have.
- if (_queues.containsKey(queue.getName()))
- {
- queueConfig.addConfiguration(_queues.get(queue.getName()));
- }
-
- return queueConfig;
- }
-
public int getMaximumMessageAge()
{
- return getIntValue("queues.maximumMessageAge");
+ return getIntValue("queues.maximumMessageAge", getBrokerAttributeAsInt(Broker.ALERT_THRESHOLD_MESSAGE_AGE));
}
public Long getMaximumQueueDepth()
{
- return getLongValue("queues.maximumQueueDepth");
+ return getLongValue("queues.maximumQueueDepth", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_QUEUE_DEPTH));
}
public Long getMaximumMessageSize()
{
- return getLongValue("queues.maximumMessageSize");
+ return getLongValue("queues.maximumMessageSize", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_MESSAGE_SIZE));
}
public Long getMaximumMessageCount()
{
- return getLongValue("queues.maximumMessageCount");
+ return getLongValue("queues.maximumMessageCount", getBrokerAttributeAsLong(Broker.ALERT_THRESHOLD_MESSAGE_COUNT));
}
public Long getMinimumAlertRepeatGap()
{
- return getLongValue("queues.minimumAlertRepeatGap", ApplicationRegistry.getInstance().getConfiguration().getMinimumAlertRepeatGap());
+ return getLongValue("queues.minimumAlertRepeatGap", getBrokerAttributeAsLong(Broker.ALERT_REPEAT_GAP));
}
public long getCapacity()
{
- return getLongValue("queues.capacity");
+ return getLongValue("queues.capacity", getBrokerAttributeAsLong(Broker.FLOW_CONTROL_SIZE_BYTES));
}
public long getFlowResumeCapacity()
{
- return getLongValue("queues.flowResumeCapacity", getCapacity());
+ return getLongValue("queues.flowResumeCapacity", getBrokerAttributeAsLong(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES));
}
public String[] getElementsProcessed()
@@ -336,7 +263,7 @@ public class VirtualHostConfiguration extends ConfigurationPlugin
public int getMaxDeliveryCount()
{
- return getIntValue("queues.maximumDeliveryCount", ApplicationRegistry.getInstance().getConfiguration().getMaxDeliveryCount());
+ return getIntValue("queues.maximumDeliveryCount", getBrokerAttributeAsInt(Broker.MAXIMUM_DELIVERY_ATTEMPTS));
}
/**
@@ -344,7 +271,25 @@ public class VirtualHostConfiguration extends ConfigurationPlugin
*/
public boolean isDeadLetterQueueEnabled()
{
- return getBooleanValue("queues.deadLetterQueues", ApplicationRegistry.getInstance().getConfiguration().isDeadLetterQueueEnabled());
+ return getBooleanValue("queues.deadLetterQueues", getBrokerAttributeAsBoolean(Broker.DEAD_LETTER_QUEUE_ENABLED));
+ }
+
+ private long getBrokerAttributeAsLong(String name)
+ {
+ Number brokerValue = (Number)_broker.getAttribute(name);
+ return brokerValue == null? 0 : brokerValue.longValue();
+ }
+
+ private int getBrokerAttributeAsInt(String name)
+ {
+ Number brokerValue = (Number)_broker.getAttribute(name);
+ return brokerValue == null? 0 : brokerValue.intValue();
+ }
+
+ private boolean getBrokerAttributeAsBoolean(String name)
+ {
+ Boolean brokerValue = (Boolean)_broker.getAttribute(name);
+ return brokerValue == null? false : brokerValue.booleanValue();
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java
new file mode 100644
index 0000000000..c0cff2c109
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/XmlConfigurationUtilities.java
@@ -0,0 +1,111 @@
+/*
+ *
+ * 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.configuration;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.ConfigurationFactory;
+import org.apache.commons.configuration.SystemConfiguration;
+import org.apache.commons.configuration.XMLConfiguration;
+
+public class XmlConfigurationUtilities
+{
+
+ // Our configuration class needs to make the interpolate method
+ // public so it can be called below from the config method.
+ public static class MyConfiguration extends CompositeConfiguration
+ {
+ public String interpolate(String obj)
+ {
+ return super.interpolate(obj);
+ }
+ }
+
+ public static Configuration parseConfig(File file, Map<String, String> envVarMap) throws ConfigurationException
+ {
+ ConfigurationFactory factory = new ConfigurationFactory();
+ factory.setConfigurationFileName(file.getAbsolutePath());
+ Configuration conf = factory.getConfiguration();
+
+ Iterator<?> keys = conf.getKeys();
+ if (!keys.hasNext())
+ {
+ keys = null;
+ conf = flatConfig(file);
+ }
+
+ XmlConfigurationUtilities.substituteEnvironmentVariables(conf, envVarMap);
+ return conf;
+ }
+
+ public final static Configuration flatConfig(File file) throws ConfigurationException
+ {
+ // We have to override the interpolate methods so that
+ // interpolation takes place across the entirety of the
+ // composite configuration. Without doing this each
+ // configuration object only interpolates variables defined
+ // inside itself.
+ final MyConfiguration conf = new MyConfiguration();
+ conf.addConfiguration(new SystemConfiguration()
+ {
+ protected String interpolate(String o)
+ {
+ return conf.interpolate(o);
+ }
+ });
+ conf.addConfiguration(new XMLConfiguration(file)
+ {
+ protected String interpolate(String o)
+ {
+ return conf.interpolate(o);
+ }
+ });
+ return conf;
+ }
+
+ static void substituteEnvironmentVariables(Configuration conf, Map<String, String> envVarMap)
+ {
+ if (envVarMap == null || envVarMap.isEmpty())
+ {
+ return;
+ }
+ for (Entry<String, String> var : envVarMap.entrySet())
+ {
+ String val = System.getenv(var.getKey());
+ if (val != null)
+ {
+ conf.setProperty(var.getValue(), val);
+ }
+ }
+ }
+
+
+ public static String escapeTagName(String name)
+ {
+ return name.replaceAll("\\.", "\\.\\.");
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java
new file mode 100644
index 0000000000..3c17faef75
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/AbstractConfiguration.java
@@ -0,0 +1,329 @@
+/*
+ * 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.configuration.plugins;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.ConversionException;
+import org.apache.log4j.Logger;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+public abstract class AbstractConfiguration
+{
+ protected static final Logger _logger = Logger.getLogger(AbstractConfiguration.class);
+
+ private Configuration _config;
+
+ /**
+ * The Elements that this Plugin can process.
+ *
+ * For a Queues plugin that would be a list containing:
+ * <ul>
+ * <li>queue - the queue entries
+ * <li>the alerting values for defaults
+ * <li>exchange - the default exchange
+ * <li>durable - set the default durablity
+ * </ul>
+ */
+ abstract public String[] getElementsProcessed();
+
+ /** Performs configuration validation. */
+ public void validateConfiguration() throws ConfigurationException
+ {
+ // Override in sub-classes
+ }
+
+ public Configuration getConfig()
+ {
+ return _config;
+ }
+
+ /**
+ * Sets the configuration for this plugin
+ *
+ * @param path
+ * @param configuration the configuration for this plugin.
+ */
+ public void setConfiguration(String path, Configuration configuration) throws ConfigurationException
+ {
+ _config = configuration;
+
+ // Extract a list of elements for processing
+ Iterator<?> keys = configuration.getKeys();
+
+ Set<String> elements = new HashSet<String>();
+ while (keys.hasNext())
+ {
+ String key = (String) keys.next();
+
+ int elementNameIndex = key.indexOf(".");
+
+ String element = key.trim();
+ if (elementNameIndex != -1)
+ {
+ element = key.substring(0, elementNameIndex).trim();
+ }
+
+ // Trim any element properties
+ elementNameIndex = element.indexOf("[");
+ if (elementNameIndex > 0)
+ {
+ element = element.substring(0, elementNameIndex).trim();
+ }
+
+ elements.add(element);
+ }
+
+ //Remove the items we already expect in the configuration
+ for (String tag : getElementsProcessed())
+ {
+
+ // Work round the issue with Commons configuration.
+ // With an XMLConfiguration the key will be [@property]
+ // but with a CompositeConfiguration it will be @property].
+ // Hide this issue from our users so when/if we change the
+ // configuration they don't have to.
+ int bracketIndex = tag.indexOf("[");
+ if (bracketIndex != -1)
+ {
+ tag = tag.substring(bracketIndex + 1, tag.length());
+ }
+
+ elements.remove(tag);
+ }
+
+ if (_logger.isInfoEnabled())
+ {
+ if (!elements.isEmpty())
+ {
+ _logger.info("Elements to lookup:" + path);
+ for (String tag : elements)
+ {
+ _logger.info("Tag:'" + tag + "'");
+ }
+ }
+ }
+
+ validateConfiguration();
+ }
+
+ /** Helper method to print out list of keys in a {@link Configuration}. */
+ public static final void showKeys(Configuration config)
+ {
+ if (config.isEmpty())
+ {
+ _logger.info("Configuration is empty");
+ }
+ else
+ {
+ Iterator<?> keys = config.getKeys();
+ while (keys.hasNext())
+ {
+ String key = (String) keys.next();
+ _logger.info("Configuration key: " + key);
+ }
+ }
+ }
+
+ protected boolean hasConfiguration()
+ {
+ return _config != null;
+ }
+
+ /// Getters
+
+ protected double getDoubleValue(String property)
+ {
+ return getDoubleValue(property, 0.0);
+ }
+
+ protected double getDoubleValue(String property, double defaultValue)
+ {
+ return _config.getDouble(property, defaultValue);
+ }
+
+ protected long getLongValue(String property)
+ {
+ return getLongValue(property, 0);
+ }
+
+ protected long getLongValue(String property, long defaultValue)
+ {
+ return _config.getLong(property, defaultValue);
+ }
+
+ protected int getIntValue(String property)
+ {
+ return getIntValue(property, 0);
+ }
+
+ protected int getIntValue(String property, int defaultValue)
+ {
+ return _config.getInt(property, defaultValue);
+ }
+
+ protected String getStringValue(String property)
+ {
+ return getStringValue(property, null);
+ }
+
+ protected String getStringValue(String property, String defaultValue)
+ {
+ return _config.getString(property, defaultValue);
+ }
+
+ protected boolean getBooleanValue(String property)
+ {
+ return getBooleanValue(property, false);
+ }
+
+ protected boolean getBooleanValue(String property, boolean defaultValue)
+ {
+ return _config.getBoolean(property, defaultValue);
+ }
+
+ protected List getListValue(String property)
+ {
+ return getListValue(property, Collections.EMPTY_LIST);
+ }
+
+ protected List getListValue(String property, List defaultValue)
+ {
+ return _config.getList(property, defaultValue);
+ }
+
+ /// Validation Helpers
+
+ protected boolean contains(String property)
+ {
+ return _config.getProperty(property) != null;
+ }
+
+ /**
+ * Provide mechanism to validate Configuration contains a Postiive Long Value
+ *
+ * @param property
+ *
+ * @throws ConfigurationException
+ */
+ protected void validatePositiveLong(String property) throws ConfigurationException
+ {
+ try
+ {
+ if (!containsPositiveLong(property))
+ {
+ throw new ConfigurationException(this.getClass().getSimpleName()
+ + ": '" + property +
+ "' must be a Positive Long value.");
+ }
+ }
+ catch (Exception e)
+ {
+ Throwable last = e;
+
+ // Find the first cause
+ if (e instanceof ConversionException)
+ {
+ Throwable t = e.getCause();
+ while (t != null)
+ {
+ last = t;
+ t = last.getCause();
+ }
+ }
+
+ throw new ConfigurationException(this.getClass().getSimpleName() +
+ ": unable to configure invalid " +
+ property + ":" +
+ _config.getString(property),
+ last);
+ }
+ }
+
+ protected boolean containsLong(String property)
+ {
+ try
+ {
+ _config.getLong(property);
+ return true;
+ }
+ catch (NoSuchElementException e)
+ {
+ return false;
+ }
+ }
+
+ protected boolean containsPositiveLong(String property)
+ {
+ try
+ {
+ long value = _config.getLong(property);
+ return value > 0;
+ }
+ catch (NoSuchElementException e)
+ {
+ return false;
+ }
+
+ }
+
+ protected boolean containsInt(String property)
+ {
+ try
+ {
+ _config.getInt(property);
+ return true;
+ }
+ catch (NoSuchElementException e)
+ {
+ return false;
+ }
+ }
+
+ protected boolean containsBoolean(String property)
+ {
+ try
+ {
+ _config.getBoolean(property);
+ return true;
+ }
+ catch (NoSuchElementException e)
+ {
+ return false;
+ }
+ }
+
+ public static String escapeTagName(String name)
+ {
+ return name.replaceAll("\\.", "\\.\\.");
+ }
+
+ protected void setConfig(Configuration config)
+ {
+ _config = config;
+ }
+}
+
+
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java
deleted file mode 100644
index d08e3bc806..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java
+++ /dev/null
@@ -1,488 +0,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.
- */
-package org.apache.qpid.server.configuration.plugins;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.ConversionException;
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.server.configuration.ConfigurationManager;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-public abstract class ConfigurationPlugin
-{
- protected static final Logger _logger = Logger.getLogger(ConfigurationPlugin.class);
-
- private Map<String, ConfigurationPlugin>
- _pluginConfiguration = new HashMap<String, ConfigurationPlugin>();
-
- private Configuration _config;
-
- /**
- * The Elements that this Plugin can process.
- *
- * For a Queues plugin that would be a list containing:
- * <ul>
- * <li>queue - the queue entries
- * <li>the alerting values for defaults
- * <li>exchange - the default exchange
- * <li>durable - set the default durablity
- * </ul>
- */
- abstract public String[] getElementsProcessed();
-
- /** Performs configuration validation. */
- public void validateConfiguration() throws ConfigurationException
- {
- // Override in sub-classes
- }
-
- public Configuration getConfig()
- {
- return _config;
- }
-
- public <C extends ConfigurationPlugin> C getConfiguration(String plugin)
- {
- return (C) _pluginConfiguration.get(plugin);
- }
-
- /**
- * Sets the configuration for this plugin
- *
- * @param path
- * @param configuration the configuration for this plugin.
- */
- public void setConfiguration(String path, Configuration configuration) throws ConfigurationException
- {
- _config = configuration;
-
- // Extract a list of elements for processing
- Iterator<?> keys = configuration.getKeys();
-
- Set<String> elements = new HashSet<String>();
- while (keys.hasNext())
- {
- String key = (String) keys.next();
-
- int elementNameIndex = key.indexOf(".");
-
- String element = key.trim();
- if (elementNameIndex != -1)
- {
- element = key.substring(0, elementNameIndex).trim();
- }
-
- // Trim any element properties
- elementNameIndex = element.indexOf("[");
- if (elementNameIndex > 0)
- {
- element = element.substring(0, elementNameIndex).trim();
- }
-
- elements.add(element);
- }
-
- //Remove the items we already expect in the configuration
- for (String tag : getElementsProcessed())
- {
-
- // Work round the issue with Commons configuration.
- // With an XMLConfiguration the key will be [@property]
- // but with a CompositeConfiguration it will be @property].
- // Hide this issue from our users so when/if we change the
- // configuration they don't have to.
- int bracketIndex = tag.indexOf("[");
- if (bracketIndex != -1)
- {
- tag = tag.substring(bracketIndex + 1, tag.length());
- }
-
- elements.remove(tag);
- }
-
- if (_logger.isInfoEnabled())
- {
- if (!elements.isEmpty())
- {
- _logger.info("Elements to lookup:" + path);
- for (String tag : elements)
- {
- _logger.info("Tag:'" + tag + "'");
- }
- }
- }
-
- offerRemainingConfigurationToOtherPlugins(path, configuration, elements);
-
- validateConfiguration();
- }
-
- private void offerRemainingConfigurationToOtherPlugins(String path,
- Configuration configuration, Set<String> elements) throws ConfigurationException
- {
- final IApplicationRegistry appRegistry = safeGetApplicationRegistryInstance();
-
- if (appRegistry == null)
- {
- // We see this happen during shutdown due to asynchronous reconfig using IO threads.
- // Need to remove the responsibility for offering configuration to other class.
- _logger.info("Cannot offer remaining config to other plugins, can't find app registry");
- return;
- }
-
- final ConfigurationManager configurationManager = appRegistry.getConfigurationManager();
- // Process the elements in the configuration
- for (String element : elements)
- {
- Configuration handled = element.length() == 0 ? configuration : configuration.subset(element);
-
- String configurationElement = element;
- if (path.length() > 0)
- {
- configurationElement = path + "." + configurationElement;
- }
-
- List<ConfigurationPlugin> handlers = configurationManager.getConfigurationPlugins(configurationElement, handled);
-
- if(_logger.isDebugEnabled())
- {
- _logger.debug("For '" + element + "' found handlers (" + handlers.size() + "):" + handlers);
- }
-
- for (ConfigurationPlugin plugin : handlers)
- {
- _pluginConfiguration.put(plugin.getClass().getName(), plugin);
- }
- }
- }
-
- private IApplicationRegistry safeGetApplicationRegistryInstance()
- {
- try
- {
- return ApplicationRegistry.getInstance();
- }
- catch (IllegalStateException ise)
- {
- return null;
- }
- }
-
- /** Helper method to print out list of keys in a {@link Configuration}. */
- public static final void showKeys(Configuration config)
- {
- if (config.isEmpty())
- {
- _logger.info("Configuration is empty");
- }
- else
- {
- Iterator<?> keys = config.getKeys();
- while (keys.hasNext())
- {
- String key = (String) keys.next();
- _logger.info("Configuration key: " + key);
- }
- }
- }
-
- protected boolean hasConfiguration()
- {
- return _config != null;
- }
-
- /// Getters
-
- protected double getDoubleValue(String property)
- {
- return getDoubleValue(property, 0.0);
- }
-
- protected double getDoubleValue(String property, double defaultValue)
- {
- return _config.getDouble(property, defaultValue);
- }
-
- protected long getLongValue(String property)
- {
- return getLongValue(property, 0);
- }
-
- protected long getLongValue(String property, long defaultValue)
- {
- return _config.getLong(property, defaultValue);
- }
-
- protected int getIntValue(String property)
- {
- return getIntValue(property, 0);
- }
-
- protected int getIntValue(String property, int defaultValue)
- {
- return _config.getInt(property, defaultValue);
- }
-
- protected String getStringValue(String property)
- {
- return getStringValue(property, null);
- }
-
- protected String getStringValue(String property, String defaultValue)
- {
- return _config.getString(property, defaultValue);
- }
-
- protected boolean getBooleanValue(String property)
- {
- return getBooleanValue(property, false);
- }
-
- protected boolean getBooleanValue(String property, boolean defaultValue)
- {
- return _config.getBoolean(property, defaultValue);
- }
-
- protected List getListValue(String property)
- {
- return getListValue(property, Collections.EMPTY_LIST);
- }
-
- protected List getListValue(String property, List defaultValue)
- {
- return _config.getList(property, defaultValue);
- }
-
- /// Validation Helpers
-
- protected boolean contains(String property)
- {
- return _config.getProperty(property) != null;
- }
-
- /**
- * Provide mechanism to validate Configuration contains a Postiive Long Value
- *
- * @param property
- *
- * @throws ConfigurationException
- */
- protected void validatePositiveLong(String property) throws ConfigurationException
- {
- try
- {
- if (!containsPositiveLong(property))
- {
- throw new ConfigurationException(this.getClass().getSimpleName()
- + ": '" + property +
- "' must be a Positive Long value.");
- }
- }
- catch (Exception e)
- {
- Throwable last = e;
-
- // Find the first cause
- if (e instanceof ConversionException)
- {
- Throwable t = e.getCause();
- while (t != null)
- {
- last = t;
- t = last.getCause();
- }
- }
-
- throw new ConfigurationException(this.getClass().getSimpleName() +
- ": unable to configure invalid " +
- property + ":" +
- _config.getString(property),
- last);
- }
- }
-
- protected boolean containsLong(String property)
- {
- try
- {
- _config.getLong(property);
- return true;
- }
- catch (NoSuchElementException e)
- {
- return false;
- }
- }
-
- protected boolean containsPositiveLong(String property)
- {
- try
- {
- long value = _config.getLong(property);
- return value > 0;
- }
- catch (NoSuchElementException e)
- {
- return false;
- }
-
- }
-
- protected boolean containsInt(String property)
- {
- try
- {
- _config.getInt(property);
- return true;
- }
- catch (NoSuchElementException e)
- {
- return false;
- }
- }
-
- protected boolean containsBoolean(String property)
- {
- try
- {
- _config.getBoolean(property);
- return true;
- }
- catch (NoSuchElementException e)
- {
- return false;
- }
- }
-
- /**
- * Given another configuration merge the configuration into our own config
- *
- * The new values being merged in will take precedence over existing values.
- *
- * In the simplistic case this means something like:
- *
- * So if we have configuration set
- * name = 'fooo'
- *
- * And the new configuration contains a name then that will be reset.
- * name = 'new'
- *
- * However this plugin will simply contain other plugins so the merge will
- * be called until we end up at a base plugin that understand how to merge
- * items. i.e Alerting values. Where the provided configuration will take
- * precedence.
- *
- * @param configuration the config to merge in to our own.
- */
- public void addConfiguration(ConfigurationPlugin configuration)
- {
- // If given configuration is null then there is nothing to process.
- if (configuration == null)
- {
- return;
- }
-
- // Merge all the sub configuration items
- for (Map.Entry<String, ConfigurationPlugin> newPlugins : configuration._pluginConfiguration.entrySet())
- {
- String key = newPlugins.getKey();
- ConfigurationPlugin config = newPlugins.getValue();
-
- if (_pluginConfiguration.containsKey(key))
- {
- //Merge the configuration if we already have this type of config
- _pluginConfiguration.get(key).mergeConfiguration(config);
- }
- else
- {
- //otherwise just add it to our config.
- _pluginConfiguration.put(key, config);
- }
- }
-
- //Merge the configuration itself
- String key = configuration.getClass().getName();
- if (_pluginConfiguration.containsKey(key))
- {
- //Merge the configuration if we already have this type of config
- _pluginConfiguration.get(key).mergeConfiguration(configuration);
- }
- else
- {
- //If we are adding a configuration of our own type then merge
- if (configuration.getClass() == this.getClass())
- {
- mergeConfiguration(configuration);
- }
- else
- {
- // just store this in case someone else needs it.
- _pluginConfiguration.put(key, configuration);
- }
-
- }
-
- }
-
- protected void mergeConfiguration(ConfigurationPlugin configuration)
- {
- _config = configuration.getConfig();
- }
-
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
-
- sb.append("\n").append(getClass().getSimpleName());
- sb.append("=[ (").append(formatToString()).append(")");
-
- for(Map.Entry<String,ConfigurationPlugin> item : _pluginConfiguration.entrySet())
- {
- sb.append("\n").append(item.getValue());
- }
-
- sb.append("]\n");
-
- return sb.toString();
- }
-
- public String formatToString()
- {
- return super.toString();
- }
-
- protected void setConfig(Configuration config)
- {
- _config = config;
- }
-}
-
-
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java
deleted file mode 100644
index fa41f3ef06..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginFactory.java
+++ /dev/null
@@ -1,38 +0,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.
- *
- */
-package org.apache.qpid.server.configuration.plugins;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import java.util.List;
-
-public interface ConfigurationPluginFactory
-{
- /**
- * The Parent paths of the configuration that this plugin supports.
- *
- * For example, {@code queue} elements have a parent path of {@code virtualhosts.virtualhost}.
- */
- public List<String> getParentPaths();
-
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException;
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionConfiguration.java
deleted file mode 100644
index a90b1d514f..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionConfiguration.java
+++ /dev/null
@@ -1,86 +0,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.
- *
- */
-package org.apache.qpid.server.configuration.plugins;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-public class SlowConsumerDetectionConfiguration extends ConfigurationPlugin
-{
- public static class SlowConsumerDetectionConfigurationFactory implements ConfigurationPluginFactory
- {
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- SlowConsumerDetectionConfiguration slowConsumerConfig = new SlowConsumerDetectionConfiguration();
- slowConsumerConfig.setConfiguration(path, config);
- return slowConsumerConfig;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList("virtualhosts.virtualhost.slow-consumer-detection");
- }
- }
-
- //Set Default time unit to seconds
- private TimeUnit _timeUnit = TimeUnit.SECONDS;
-
- public String[] getElementsProcessed()
- {
- return new String[]{"delay",
- "timeunit"};
- }
-
- public long getDelay()
- {
- return getLongValue("delay", 10);
- }
-
- public TimeUnit getTimeUnit()
- {
- return _timeUnit;
- }
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- validatePositiveLong("delay");
-
- String timeUnit = getStringValue("timeunit");
-
- if (timeUnit != null)
- {
- try
- {
- _timeUnit = TimeUnit.valueOf(timeUnit.toUpperCase());
- }
- catch (IllegalArgumentException iae)
- {
- throw new ConfigurationException("Unable to configure Slow Consumer Detection invalid TimeUnit:" + timeUnit);
- }
- }
-
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionPolicyConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionPolicyConfiguration.java
deleted file mode 100644
index a9026c6164..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionPolicyConfiguration.java
+++ /dev/null
@@ -1,74 +0,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.
- *
- */
-package org.apache.qpid.server.configuration.plugins;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class SlowConsumerDetectionPolicyConfiguration extends ConfigurationPlugin
-{
- public static class SlowConsumerDetectionPolicyConfigurationFactory implements ConfigurationPluginFactory
- {
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- SlowConsumerDetectionPolicyConfiguration slowConsumerConfig = new SlowConsumerDetectionPolicyConfiguration();
- slowConsumerConfig.setConfiguration(path, config);
- return slowConsumerConfig;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList(
- "virtualhosts.virtualhost.queues.slow-consumer-detection.policy",
- "virtualhosts.virtualhost.queues.queue.slow-consumer-detection.policy",
- "virtualhosts.virtualhost.topics.slow-consumer-detection.policy",
- "virtualhosts.virtualhost.topics.topic.slow-consumer-detection.policy");
- }
- }
-
- public String[] getElementsProcessed()
- {
- return new String[]{"name"};
- }
-
- public String getPolicyName()
- {
- return getStringValue("name");
- }
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- if (getPolicyName() == null)
- {
- throw new ConfigurationException("No Slow consumer policy defined.");
- }
- }
-
- @Override
- public String formatToString()
- {
- return "Policy:"+getPolicyName();
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionQueueConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionQueueConfiguration.java
deleted file mode 100644
index cb3bb5a77f..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/SlowConsumerDetectionQueueConfiguration.java
+++ /dev/null
@@ -1,163 +0,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.
- *
- */
-package org.apache.qpid.server.configuration.plugins;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.plugins.PluginManager;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPlugin;
-import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPluginFactory;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-public class SlowConsumerDetectionQueueConfiguration extends ConfigurationPlugin
-{
- private SlowConsumerPolicyPlugin _policyPlugin;
-
- public static class SlowConsumerDetectionQueueConfigurationFactory implements ConfigurationPluginFactory
- {
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- SlowConsumerDetectionQueueConfiguration slowConsumerConfig = new SlowConsumerDetectionQueueConfiguration();
- slowConsumerConfig.setConfiguration(path, config);
- return slowConsumerConfig;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList(
- "virtualhosts.virtualhost.queues.slow-consumer-detection",
- "virtualhosts.virtualhost.queues.queue.slow-consumer-detection",
- "virtualhosts.virtualhost.topics.slow-consumer-detection",
- "virtualhosts.virtualhost.topics.topic.slow-consumer-detection");
- }
- }
-
- public String[] getElementsProcessed()
- {
- return new String[]{"messageAge",
- "depth",
- "messageCount"};
- }
-
- public long getMessageAge()
- {
- return getLongValue("messageAge");
- }
-
- public long getDepth()
- {
- return getLongValue("depth");
- }
-
- public long getMessageCount()
- {
- return getLongValue("messageCount");
- }
-
- public SlowConsumerPolicyPlugin getPolicy()
- {
- return _policyPlugin;
- }
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- PluginManager pluginManager;
- try
- {
- pluginManager = ApplicationRegistry.getInstance().getPluginManager();
- }
- catch (IllegalStateException ise)
- {
- // We see this happen during shutdown due to asynchronous reconfig performed IO threads
- // running at the same time as the shutdown handler.
- _policyPlugin = null;
- return;
- }
-
- if (!containsPositiveLong("messageAge") &&
- !containsPositiveLong("depth") &&
- !containsPositiveLong("messageCount"))
- {
- throw new ConfigurationException("At least one configuration property" +
- "('messageAge','depth' or 'messageCount') must be specified.");
- }
-
- SlowConsumerDetectionPolicyConfiguration policyConfig = getConfiguration(SlowConsumerDetectionPolicyConfiguration.class.getName());
- Map<String, SlowConsumerPolicyPluginFactory> factories = pluginManager.getSlowConsumerPlugins();
-
- if (policyConfig == null)
- {
- throw new ConfigurationException("No Slow Consumer Policy specified. Known Policies:" + factories.keySet());
- }
-
- if (_logger.isDebugEnabled())
- {
- Iterator<?> keys = policyConfig.getConfig().getKeys();
-
- while (keys.hasNext())
- {
- String key = (String) keys.next();
-
- _logger.debug("Policy Keys:" + key);
- }
-
- }
-
- SlowConsumerPolicyPluginFactory<SlowConsumerPolicyPlugin> pluginFactory = factories.get(policyConfig.getPolicyName().toLowerCase());
-
- if (pluginFactory == null)
- {
- throw new ConfigurationException("Unknown Slow Consumer Policy specified:" + policyConfig.getPolicyName() + " Known Policies:" + factories.keySet());
- }
-
- _policyPlugin = pluginFactory.newInstance(policyConfig);
-
- // Debug the creation of this Config
- _logger.debug(this);
- }
-
- public String formatToString()
- {
- StringBuilder sb = new StringBuilder();
- if (getMessageAge() > 0)
- {
- sb.append("Age:").append(getMessageAge()).append(":");
- }
- if (getDepth() > 0)
- {
- sb.append("Depth:").append(getDepth()).append(":");
- }
- if (getMessageCount() > 0)
- {
- sb.append("Count:").append(getMessageCount()).append(":");
- }
-
- sb.append("Policy[").append(getPolicy()).append("]");
- return sb.toString();
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java
new file mode 100644
index 0000000000..9b06a2b499
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/AuthenticationProviderRecoverer.java
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+
+public class AuthenticationProviderRecoverer implements ConfiguredObjectRecoverer<AuthenticationProvider>
+{
+ private final AuthenticationProviderFactory _authenticationProviderFactory;
+
+ public AuthenticationProviderRecoverer(AuthenticationProviderFactory authenticationProviderFactory)
+ {
+ _authenticationProviderFactory = authenticationProviderFactory;
+ }
+
+ @Override
+ public AuthenticationProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ Map<String, Object> attributes = configurationEntry.getAttributes();
+ AuthenticationProvider authenticationProvider = _authenticationProviderFactory.create(
+ configurationEntry.getId(),
+ broker,
+ attributes, null);
+
+ return authenticationProvider;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java
new file mode 100644
index 0000000000..4bfa0ca7a3
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java
@@ -0,0 +1,139 @@
+package org.apache.qpid.server.configuration.startup;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+import org.apache.qpid.server.model.adapter.BrokerAdapter;
+import org.apache.qpid.server.model.adapter.PortFactory;
+import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker>
+{
+ private final StatisticsGatherer _statisticsGatherer;
+ private final VirtualHostRegistry _virtualHostRegistry;
+ private final LogRecorder _logRecorder;
+ private final RootMessageLogger _rootMessageLogger;
+ private final AuthenticationProviderFactory _authenticationProviderFactory;
+ private final PortFactory _portFactory;
+ private final TaskExecutor _taskExecutor;
+
+ public BrokerRecoverer(AuthenticationProviderFactory authenticationProviderFactory, PortFactory portFactory,
+ StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry, LogRecorder logRecorder,
+ RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor)
+ {
+ _portFactory = portFactory;
+ _authenticationProviderFactory = authenticationProviderFactory;
+ _statisticsGatherer = statisticsGatherer;
+ _virtualHostRegistry = virtualHostRegistry;
+ _logRecorder = logRecorder;
+ _rootMessageLogger = rootMessageLogger;
+ _taskExecutor = taskExecutor;
+ }
+
+ @Override
+ public Broker create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ StoreConfigurationChangeListener storeChangeListener = new StoreConfigurationChangeListener(entry.getStore());
+ BrokerAdapter broker = new BrokerAdapter(entry.getId(), entry.getAttributes(), _statisticsGatherer, _virtualHostRegistry,
+ _logRecorder, _rootMessageLogger, _authenticationProviderFactory, _portFactory, _taskExecutor);
+ broker.addChangeListener(storeChangeListener);
+ Map<String, Collection<ConfigurationEntry>> childEntries = entry.getChildren();
+ for (String type : childEntries.keySet())
+ {
+ ConfiguredObjectRecoverer<?> recoverer = recovererProvider.getRecoverer(type);
+ if (recoverer == null)
+ {
+ throw new IllegalConfigurationException("Cannot recover entry for the type '" + type + "' from broker");
+ }
+ Collection<ConfigurationEntry> entries = childEntries.get(type);
+ for (ConfigurationEntry childEntry : entries)
+ {
+ ConfiguredObject object = recoverer.create(recovererProvider, childEntry, broker);
+ if (object == null)
+ {
+ throw new IllegalConfigurationException("Cannot create configured object for the entry " + childEntry);
+ }
+ broker.recoverChild(object);
+ object.addChangeListener(storeChangeListener);
+ }
+ }
+ wireUpConfiguredObjects(broker, entry.getAttributes());
+
+ return broker;
+ }
+
+ private void wireUpConfiguredObjects(BrokerAdapter broker, Map<String, Object> brokerAttributes)
+ {
+ AuthenticationProvider defaultAuthenticationProvider = null;
+ Collection<AuthenticationProvider> authenticationProviders = broker.getAuthenticationProviders();
+ int numberOfAuthenticationProviders = authenticationProviders.size();
+ if (numberOfAuthenticationProviders == 0)
+ {
+ throw new IllegalConfigurationException("No authentication provider was configured");
+ }
+ else if (numberOfAuthenticationProviders == 1)
+ {
+ defaultAuthenticationProvider = authenticationProviders.iterator().next();
+ }
+ else
+ {
+ String name = (String) brokerAttributes.get(Broker.DEFAULT_AUTHENTICATION_PROVIDER);
+ if (name == null)
+ {
+ throw new IllegalConfigurationException("Multiple authentication providers defined, but no default was configured.");
+ }
+
+ defaultAuthenticationProvider = getAuthenticationProviderByName(broker, name);
+ }
+ broker.setDefaultAuthenticationProvider(defaultAuthenticationProvider);
+
+ GroupPrincipalAccessor groupPrincipalAccessor = new GroupPrincipalAccessor(broker.getGroupProviders());
+ for (AuthenticationProvider authenticationProvider : authenticationProviders)
+ {
+ authenticationProvider.setGroupAccessor(groupPrincipalAccessor);
+ }
+
+ Collection<Port> ports = broker.getPorts();
+ for (Port port : ports)
+ {
+ String authenticationProviderName = (String) port.getAttribute(Port.AUTHENTICATION_MANAGER);
+ AuthenticationProvider provider = null;
+ if (authenticationProviderName != null)
+ {
+ provider = getAuthenticationProviderByName(broker, authenticationProviderName);
+ }
+ else
+ {
+ provider = defaultAuthenticationProvider;
+ }
+ port.setAuthenticationProvider(provider);
+ }
+ }
+
+ private AuthenticationProvider getAuthenticationProviderByName(BrokerAdapter broker, String authenticationProviderName)
+ {
+ AuthenticationProvider provider = broker.getAuthenticationProviderByName(authenticationProviderName);
+ if (provider == null)
+ {
+ throw new IllegalConfigurationException("Cannot find the authentication provider with name: "
+ + authenticationProviderName);
+ }
+ return provider;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.java
new file mode 100644
index 0000000000..15cb229d8a
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProvider.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.server.configuration.startup;
+
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+import org.apache.qpid.server.model.adapter.PortFactory;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.plugin.GroupManagerFactory;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class DefaultRecovererProvider implements RecovererProvider
+{
+
+ private final StatisticsGatherer _brokerStatisticsGatherer;
+ private final VirtualHostRegistry _virtualHostRegistry;
+ private final LogRecorder _logRecorder;
+ private final RootMessageLogger _rootMessageLogger;
+ private final AuthenticationProviderFactory _authenticationProviderFactory;
+ private final PortFactory _portFactory;
+ private final QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader;
+ private final QpidServiceLoader<PluginFactory> _pluginFactoryServiceLoader;
+ private final TaskExecutor _taskExecutor;
+
+ public DefaultRecovererProvider(StatisticsGatherer brokerStatisticsGatherer, VirtualHostRegistry virtualHostRegistry,
+ LogRecorder logRecorder, RootMessageLogger rootMessageLogger, TaskExecutor taskExecutor)
+ {
+ _authenticationProviderFactory = new AuthenticationProviderFactory(new QpidServiceLoader<AuthenticationManagerFactory>());
+ _portFactory = new PortFactory();
+ _brokerStatisticsGatherer = brokerStatisticsGatherer;
+ _virtualHostRegistry = virtualHostRegistry;
+ _logRecorder = logRecorder;
+ _rootMessageLogger = rootMessageLogger;
+ _groupManagerServiceLoader = new QpidServiceLoader<GroupManagerFactory>();
+ _pluginFactoryServiceLoader = new QpidServiceLoader<PluginFactory>();
+ _taskExecutor = taskExecutor;
+ }
+
+ @Override
+ public ConfiguredObjectRecoverer<?> getRecoverer(String type)
+ {
+ if (Broker.class.getSimpleName().equals(type))
+ {
+ return new BrokerRecoverer(_authenticationProviderFactory, _portFactory, _brokerStatisticsGatherer, _virtualHostRegistry,
+ _logRecorder, _rootMessageLogger, _taskExecutor);
+ }
+ else if(VirtualHost.class.getSimpleName().equals(type))
+ {
+ return new VirtualHostRecoverer(_brokerStatisticsGatherer);
+ }
+ else if(AuthenticationProvider.class.getSimpleName().equals(type))
+ {
+ return new AuthenticationProviderRecoverer(_authenticationProviderFactory);
+ }
+ else if(Port.class.getSimpleName().equals(type))
+ {
+ return new PortRecoverer(_portFactory);
+ }
+ else if(GroupProvider.class.getSimpleName().equals(type))
+ {
+ return new GroupProviderRecoverer(_groupManagerServiceLoader);
+ }
+ else if(KeyStore.class.getSimpleName().equals(type))
+ {
+ return new KeyStoreRecoverer();
+ }
+ else if(TrustStore.class.getSimpleName().equals(type))
+ {
+ return new TrustStoreRecoverer();
+ }
+ else if(Plugin.class.getSimpleName().equals(type))
+ {
+ return new PluginRecoverer(_pluginFactoryServiceLoader);
+ }
+
+ return null;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java
new file mode 100644
index 0000000000..275a0c736c
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/GroupProviderRecoverer.java
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.adapter.GroupProviderAdapter;
+import org.apache.qpid.server.plugin.GroupManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.group.GroupManager;
+
+public class GroupProviderRecoverer implements ConfiguredObjectRecoverer<GroupProvider>
+{
+ private QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader;
+
+ public GroupProviderRecoverer(QpidServiceLoader<GroupManagerFactory> groupManagerServiceLoader)
+ {
+ super();
+ _groupManagerServiceLoader = groupManagerServiceLoader;
+ }
+
+ @Override
+ public GroupProvider create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ Map<String, Object> attributes = configurationEntry.getAttributes();
+ GroupManager groupManager = createGroupManager(attributes);
+ if (groupManager == null)
+ {
+ throw new IllegalConfigurationException("Cannot create GroupManager from attributes : " + attributes);
+ }
+ GroupProviderAdapter groupProviderAdapter = new GroupProviderAdapter(configurationEntry.getId(), groupManager, broker);
+ return groupProviderAdapter;
+ }
+
+ private GroupManager createGroupManager(Map<String, Object> attributes)
+ {
+ for(GroupManagerFactory factory : _groupManagerServiceLoader.instancesOf(GroupManagerFactory.class))
+ {
+ GroupManager groupManager = factory.createInstance(attributes);
+ if (groupManager != null)
+ {
+ return groupManager;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java
new file mode 100644
index 0000000000..8efedd37b5
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/KeyStoreRecoverer.java
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.adapter.KeyStoreAdapter;
+
+public class KeyStoreRecoverer implements ConfiguredObjectRecoverer<KeyStore>
+{
+ @Override
+ public KeyStore create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ return new KeyStoreAdapter(entry.getId(), broker, entry.getAttributes());
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.java
new file mode 100644
index 0000000000..ddc4482953
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PluginRecoverer.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.server.configuration.startup;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class PluginRecoverer implements ConfiguredObjectRecoverer<ConfiguredObject>
+{
+ private QpidServiceLoader<PluginFactory> _serviceLoader;
+
+ public PluginRecoverer(QpidServiceLoader<PluginFactory> serviceLoader)
+ {
+ _serviceLoader = serviceLoader;
+ }
+
+ @Override
+ public ConfiguredObject create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ Map<String, Object> attributes = configurationEntry.getAttributes();
+ Iterable<PluginFactory> factories = _serviceLoader.instancesOf(PluginFactory.class);
+ for (PluginFactory pluginFactory : factories)
+ {
+ UUID configurationId = configurationEntry.getId();
+ ConfiguredObject pluginObject = pluginFactory.createInstance(configurationId, attributes, broker);
+ if (pluginObject != null)
+ {
+ UUID pluginId = pluginObject.getId();
+ if (!configurationId.equals(pluginId))
+ {
+ throw new IllegalStateException("Plugin object id '" + pluginId + "' does not equal expected id " + configurationId);
+ }
+ return pluginObject;
+ }
+ }
+ throw new IllegalConfigurationException("Cannot create a plugin object for " + attributes + " with factories " + factories);
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java
new file mode 100644
index 0000000000..147e835a8d
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/PortRecoverer.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.adapter.BrokerAdapter;
+import org.apache.qpid.server.model.adapter.PortFactory;
+
+public class PortRecoverer implements ConfiguredObjectRecoverer<Port>
+{
+ /**
+ * delegates to a {@link PortFactory} so that the logic can be shared by
+ * {@link BrokerAdapter}
+ */
+ private final PortFactory _portFactory;
+
+ public PortRecoverer(PortFactory portFactory)
+ {
+ _portFactory = portFactory;
+ }
+
+ @Override
+ public Port create(RecovererProvider recovererProvider, ConfigurationEntry configurationEntry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ return _portFactory.createPort(configurationEntry.getId(), broker, configurationEntry.getAttributes());
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java
new file mode 100644
index 0000000000..b60c9c289f
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/RecovererHelper.java
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public class RecovererHelper
+{
+ public static Broker verifyOnlyBrokerIsParent(ConfiguredObject... parents)
+ {
+ if (parents == null || parents.length == 0)
+ {
+ throw new IllegalArgumentException("Broker parent is not passed!");
+ }
+ if (parents.length != 1)
+ {
+ throw new IllegalArgumentException("Only one parent is expected!");
+ }
+ if (!(parents[0] instanceof Broker))
+ {
+ throw new IllegalArgumentException("Parent is not a broker");
+ }
+ return (Broker)parents[0];
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java
new file mode 100644
index 0000000000..7e9428a4d6
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/TrustStoreRecoverer.java
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.adapter.TrustStoreAdapter;
+
+public class TrustStoreRecoverer implements ConfiguredObjectRecoverer<TrustStore>
+{
+ @Override
+ public TrustStore create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+ return new TrustStoreAdapter(entry.getId(), broker, entry.getAttributes());
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.java
new file mode 100644
index 0000000000..4f863adfb5
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/VirtualHostRecoverer.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.server.configuration.startup;
+
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.VirtualHostAdapter;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+
+public class VirtualHostRecoverer implements ConfiguredObjectRecoverer<VirtualHost>
+{
+ private StatisticsGatherer _brokerStatisticsGatherer;
+
+ public VirtualHostRecoverer(StatisticsGatherer brokerStatisticsGatherer)
+ {
+ super();
+ _brokerStatisticsGatherer = brokerStatisticsGatherer;
+ }
+
+ @Override
+ public VirtualHost create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ Broker broker = RecovererHelper.verifyOnlyBrokerIsParent(parents);
+
+ return new VirtualHostAdapter(entry.getId(), entry.getAttributes(), broker, _brokerStatisticsGatherer, broker.getTaskExecutor());
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
new file mode 100644
index 0000000000..e11b63001a
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
@@ -0,0 +1,711 @@
+package org.apache.qpid.server.configuration.store;
+
+import static org.apache.qpid.server.configuration.ConfigurationEntry.ATTRIBUTE_NAME;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.util.FileUtils;
+import org.apache.qpid.util.Strings;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+import org.codehaus.jackson.node.ArrayNode;
+
+public class JsonConfigurationEntryStore implements ConfigurationEntryStore
+{
+ public static final String STORE_TYPE = "json";
+ public static final String IN_MEMORY = ":memory:";
+
+ private static final String DEFAULT_BROKER_NAME = "Broker";
+ private static final String ID = "id";
+ private static final String TYPE = "@type";
+
+ private ObjectMapper _objectMapper;
+ private Map<UUID, ConfigurationEntry> _entries;
+ private File _storeFile;
+ private UUID _rootId;
+ private Map<String, Class<? extends ConfiguredObject>> _relationshipClasses;
+
+ public JsonConfigurationEntryStore()
+ {
+ _objectMapper = new ObjectMapper();
+ _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ _objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
+ _entries = new HashMap<UUID, ConfigurationEntry>();
+ _relationshipClasses = buildRelationshipClassMap();
+ }
+
+ @Override
+ public void open(String storeLocation)
+ {
+ if (_rootId != null)
+ {
+ throw new IllegalConfigurationException("The store has been opened alread");
+ }
+ if (!IN_MEMORY.equals(storeLocation))
+ {
+ _storeFile = new File(storeLocation);
+ }
+ createOrLoadStore();
+ }
+
+ @Override
+ public void open(String storeLocation, String initialStoreLocation)
+ {
+ if (_rootId != null)
+ {
+ throw new IllegalConfigurationException("The store has been opened already");
+ }
+ if (!IN_MEMORY.equals(storeLocation))
+ {
+ _storeFile = new File(storeLocation);
+ if ((!_storeFile.exists() || _storeFile.length() == 0) && initialStoreLocation != null)
+ {
+ copyInitialStoreFile(initialStoreLocation);
+ }
+ createOrLoadStore();
+ }
+ else
+ {
+ if (initialStoreLocation == null)
+ {
+ createRootEntryIfNotExists();
+ }
+ else
+ {
+ load(toURL(initialStoreLocation));
+ }
+ }
+ }
+
+ @Override
+ public void open(String storeLocation, ConfigurationEntryStore initialStore)
+ {
+ if (_rootId != null)
+ {
+ throw new IllegalConfigurationException("The store has been opened already");
+ }
+ boolean copyStore = false;
+ if (IN_MEMORY.equals(storeLocation))
+ {
+ copyStore = initialStore != null;
+ }
+ else
+ {
+ _storeFile = new File(storeLocation);
+ if ((!_storeFile.exists() || _storeFile.length() == 0) && initialStore != null)
+ {
+ createStoreFileIfNotExist(_storeFile);
+ copyStore = true;
+ }
+ }
+ if (copyStore)
+ {
+ ConfigurationEntry rootEntry = initialStore.getRootEntry();
+ _rootId = rootEntry.getId();
+ copyEntry(rootEntry.getId(), initialStore);
+ saveAsTree();
+ }
+ else
+ {
+ createOrLoadStore();
+ }
+ }
+
+ @Override
+ public synchronized UUID[] remove(UUID... entryIds)
+ {
+ List<UUID> removedIds = new ArrayList<UUID>();
+ boolean anyRemoved = false;
+ for (UUID uuid : entryIds)
+ {
+ if (_rootId.equals(uuid))
+ {
+ throw new IllegalConfigurationException("Cannot remove root entry");
+ }
+ }
+ for (UUID uuid : entryIds)
+ {
+ if (removeInternal(uuid))
+ {
+ anyRemoved = true;
+
+ // remove references to the entry from parent entries
+ for (ConfigurationEntry entry : _entries.values())
+ {
+ if (entry.hasChild(uuid))
+ {
+ Set<UUID> children = new HashSet<UUID>(entry.getChildrenIds());
+ children.remove(uuid);
+ ConfigurationEntry referal = new ConfigurationEntry(entry.getId(), entry.getType(),
+ entry.getAttributes(), children, this);
+ _entries.put(entry.getId(), referal);
+ }
+ }
+ removedIds.add(uuid);
+ }
+ }
+ if (anyRemoved)
+ {
+ saveAsTree();
+ }
+ return removedIds.toArray(new UUID[removedIds.size()]);
+ }
+
+ @Override
+ public synchronized void save(ConfigurationEntry... entries)
+ {
+ boolean anySaved = false;
+ for (ConfigurationEntry entry : entries)
+ {
+ ConfigurationEntry oldEntry = _entries.put(entry.getId(), entry);
+ if (!entry.equals(oldEntry))
+ {
+ anySaved = true;
+ }
+ }
+ if (anySaved)
+ {
+ saveAsTree();
+ }
+ }
+
+ @Override
+ public ConfigurationEntry getRootEntry()
+ {
+ return getEntry(_rootId);
+ }
+
+ @Override
+ public synchronized ConfigurationEntry getEntry(UUID id)
+ {
+ return _entries.get(id);
+ }
+
+ @Override
+ public void copyTo(String copyLocation)
+ {
+ if (_rootId == null)
+ {
+ throw new IllegalConfigurationException("The store has not been opened");
+ }
+ File file = new File(copyLocation);
+ if (!file.exists())
+ {
+ createStoreFileIfNotExist(file);
+ }
+ saveAsTree(_rootId, _entries, _objectMapper, file);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "JsonConfigurationEntryStore [_storeFile=" + _storeFile + ", _rootId=" + _rootId + "]";
+ }
+
+ private Map<String, Class<? extends ConfiguredObject>> buildRelationshipClassMap()
+ {
+ Map<String, Class<? extends ConfiguredObject>> relationships = new HashMap<String, Class<? extends ConfiguredObject>>();
+
+ Collection<Class<? extends ConfiguredObject>> children = Model.getInstance().getChildTypes(Broker.class);
+ for (Class<? extends ConfiguredObject> childClass : children)
+ {
+ String name = childClass.getSimpleName().toLowerCase();
+ String relationshipName = name + (name.endsWith("s") ? "es" : "s");
+ relationships.put(relationshipName, childClass);
+ }
+ return relationships;
+ }
+
+ private void createOrLoadStore()
+ {
+ if (_storeFile != null)
+ {
+ if (!_storeFile.exists() || _storeFile.length() == 0)
+ {
+ createStoreFileIfNotExist(_storeFile);
+ }
+ else
+ {
+ load(fileToURL(_storeFile));
+ }
+ }
+
+ createRootEntryIfNotExists();
+ }
+
+ private void createRootEntryIfNotExists()
+ {
+ if (_rootId == null)
+ {
+ // create a root entry for an empty store
+ ConfigurationEntry brokerEntry = new ConfigurationEntry(UUIDGenerator.generateRandomUUID(),
+ Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), this);
+ _rootId = brokerEntry.getId();
+ _entries.put(_rootId, brokerEntry);
+ }
+ }
+
+ private void load(URL url)
+ {
+ InputStream is = null;
+ try
+ {
+ is = url.openStream();
+ JsonNode node = loadJsonNodes(is, _objectMapper);
+ ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries);
+ _rootId = brokerEntry.getId();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot load store from: " + url, e);
+ }
+ finally
+ {
+ if (is != null)
+ {
+ if (is != null)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot close input stream for: " + url, e);
+ }
+ }
+ }
+ }
+ }
+
+ private void copyInitialStoreFile(String initialStoreLocation)
+ {
+ createStoreFileIfNotExist(_storeFile);
+ URL initialStoreURL = toURL(initialStoreLocation);
+ InputStream in = null;
+ try
+ {
+ in = initialStoreURL.openStream();
+ FileUtils.copy(in, _storeFile);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot create store file " + _storeFile + " by copying initial store from " + initialStoreLocation , e);
+ }
+ finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot close initial store input stream: " + initialStoreLocation , e);
+ }
+ }
+ }
+ }
+
+ private URL fileToURL(File storeFile)
+ {
+ URL storeURL = null;
+ try
+ {
+ storeURL = storeFile.toURI().toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalConfigurationException("Cannot create URL for file " + storeFile, e);
+ }
+ return storeURL;
+ }
+
+ private boolean removeInternal(UUID entryId)
+ {
+ ConfigurationEntry oldEntry = _entries.remove(entryId);
+ if (oldEntry != null)
+ {
+ Set<UUID> children = oldEntry.getChildrenIds();
+ if (children != null && !children.isEmpty())
+ {
+ for (UUID childId : children)
+ {
+ removeInternal(childId);
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private void saveAsTree()
+ {
+ if (_storeFile != null)
+ {
+ saveAsTree(_rootId, _entries, _objectMapper, _storeFile);
+ }
+ }
+
+ private void saveAsTree(UUID rootId, Map<UUID, ConfigurationEntry> entries, ObjectMapper mapper, File file)
+ {
+ Map<String, Object> tree = toTree(rootId, entries);
+ try
+ {
+ mapper.writeValue(file, tree);
+ }
+ catch (JsonGenerationException e)
+ {
+ throw new IllegalConfigurationException("Cannot generate json!", e);
+ }
+ catch (JsonMappingException e)
+ {
+ throw new IllegalConfigurationException("Cannot map objects for json serialization!", e);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot save configuration into " + file + "!", e);
+ }
+ }
+
+ private Map<String, Object> toTree(UUID rootId, Map<UUID, ConfigurationEntry> entries)
+ {
+ ConfigurationEntry entry = entries.get(rootId);
+ if (entry == null || !entry.getId().equals(rootId))
+ {
+ throw new IllegalConfigurationException("Cannot find entry with id " + rootId + "!");
+ }
+ Map<String, Object> tree = new TreeMap<String, Object>();
+ Map<String, Object> attributes = entry.getAttributes();
+ if (attributes != null)
+ {
+ tree.putAll(attributes);
+ }
+ tree.put(ID, entry.getId());
+ tree.put(TYPE, entry.getType());
+ Set<UUID> childrenIds = entry.getChildrenIds();
+ if (childrenIds != null && !childrenIds.isEmpty())
+ {
+ for (UUID relationship : childrenIds)
+ {
+ ConfigurationEntry child = entries.get(relationship);
+ if (child != null)
+ {
+ String relationshipName = child.getType().toLowerCase() + "s";
+
+ @SuppressWarnings("unchecked")
+ Collection<Map<String, Object>> children = (Collection<Map<String, Object>>) tree.get(relationshipName);
+ if (children == null)
+ {
+ children = new ArrayList<Map<String, Object>>();
+ tree.put(relationshipName, children);
+ }
+ Map<String, Object> childAsMap = toTree(relationship, entries);
+ children.add(childAsMap);
+ }
+ }
+ }
+ return tree;
+ }
+
+ private JsonNode loadJsonNodes(InputStream is, ObjectMapper mapper)
+ {
+ JsonNode root = null;
+ try
+ {
+ root = mapper.readTree(is);
+ }
+ catch (JsonProcessingException e)
+ {
+ throw new IllegalConfigurationException("Cannot parse json", e);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot read json", e);
+ }
+ return root;
+ }
+
+ private ConfigurationEntry toEntry(JsonNode parent, Class<? extends ConfiguredObject> expectedConfiguredObjectClass, Map<UUID, ConfigurationEntry> entries)
+ {
+ Map<String, Object> attributes = null;
+ Set<UUID> childrenIds = new TreeSet<UUID>();
+ Iterator<String> fieldNames = parent.getFieldNames();
+ String type = null;
+ String idAsString = null;
+ while (fieldNames.hasNext())
+ {
+ String fieldName = fieldNames.next();
+ JsonNode fieldNode = parent.get(fieldName);
+ if (fieldName.equals(ID))
+ {
+ idAsString = fieldNode.asText();
+ }
+ else if (fieldName.equals(TYPE))
+ {
+ type = fieldNode.asText();
+ }
+ else if (fieldNode.isArray())
+ {
+ // array containing either broker children or attribute values
+ Iterator<JsonNode> elements = fieldNode.getElements();
+ List<Object> fieldValues = null;
+ while (elements.hasNext())
+ {
+ JsonNode element = elements.next();
+ if (element.isObject())
+ {
+ Class<? extends ConfiguredObject> expectedChildConfiguredObjectClass = _relationshipClasses.get(fieldName);
+ // assuming it is a child node
+ ConfigurationEntry entry = toEntry(element, expectedChildConfiguredObjectClass, entries);
+ childrenIds.add(entry.getId());
+ }
+ else
+ {
+ if (fieldValues == null)
+ {
+ fieldValues = new ArrayList<Object>();
+ }
+ fieldValues.add(toObject(element));
+ }
+ }
+ if (fieldValues != null)
+ {
+ Object[] array = fieldValues.toArray(new Object[fieldValues.size()]);
+ attributes.put(fieldName, array);
+ }
+ }
+ else if (fieldNode.isObject())
+ {
+ // ignore, in-line objects are not supported yet
+ }
+ else
+ {
+ // primitive attribute
+ Object value = toObject(fieldNode);
+ if (attributes == null)
+ {
+ attributes = new HashMap<String, Object>();
+ }
+ attributes.put(fieldName, value);
+ }
+ }
+
+ if (type == null)
+ {
+ if (expectedConfiguredObjectClass == null)
+ {
+ throw new IllegalConfigurationException("Type attribute is not provided for configuration entry " + parent);
+ }
+ else
+ {
+ type = expectedConfiguredObjectClass.getSimpleName();
+ }
+ }
+ String name = null;
+ if (attributes != null)
+ {
+ name = (String) attributes.get(ATTRIBUTE_NAME);
+ }
+ if ((name == null || "".equals(name)))
+ {
+ if (expectedConfiguredObjectClass == Broker.class)
+ {
+ name = DEFAULT_BROKER_NAME;
+ }
+ else
+ {
+ throw new IllegalConfigurationException("Name attribute is not provided for configuration entry " + parent);
+ }
+ }
+ UUID id = null;
+ if (idAsString == null)
+ {
+ if (expectedConfiguredObjectClass == Broker.class)
+ {
+ id = UUIDGenerator.generateRandomUUID();
+ }
+ else
+ {
+ id = UUIDGenerator.generateBrokerChildUUID(type, name);
+ }
+ }
+ else
+ {
+ try
+ {
+ id = UUID.fromString(idAsString);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalConfigurationException(
+ "ID attribute value does not conform to UUID format for configuration entry " + parent);
+ }
+ }
+ ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, childrenIds, this);
+ if (entries.containsKey(id))
+ {
+ throw new IllegalConfigurationException("Duplicate id is found: " + id
+ + "! The following configuration entries have the same id: " + entries.get(id) + ", " + entry);
+ }
+ entries.put(id, entry);
+ return entry;
+ }
+
+ private Object toObject(JsonNode node)
+ {
+ if (node.isValueNode())
+ {
+ if (node.isBoolean())
+ {
+ return node.asBoolean();
+ }
+ else if (node.isDouble())
+ {
+ return node.asDouble();
+ }
+ else if (node.isInt())
+ {
+ return node.asInt();
+ }
+ else if (node.isLong())
+ {
+ return node.asLong();
+ }
+ else if (node.isNull())
+ {
+ return null;
+ }
+ else
+ {
+ return Strings.expand(node.asText());
+ }
+ }
+ else if (node.isArray())
+ {
+ return toArray(node);
+ }
+ else if (node.isObject())
+ {
+ return toMap(node);
+ }
+ else
+ {
+ throw new IllegalConfigurationException("Unexpected node: " + node);
+ }
+ }
+
+ private Map<String, Object> toMap(JsonNode node)
+ {
+ Map<String, Object> object = new TreeMap<String, Object>();
+ Iterator<String> fieldNames = node.getFieldNames();
+ while (fieldNames.hasNext())
+ {
+ String name = fieldNames.next();
+ Object value = toObject(node.get(name));
+ object.put(name, value);
+ }
+ return object;
+ }
+
+ private Object toArray(JsonNode node)
+ {
+ ArrayNode arrayNode = (ArrayNode) node;
+ Object[] array = new Object[arrayNode.size()];
+ Iterator<JsonNode> elements = arrayNode.getElements();
+ for (int i = 0; i < array.length; i++)
+ {
+ array[i] = toObject(elements.next());
+ }
+ return array;
+ }
+
+ /*
+ * Initial store location can be URL or absolute path
+ */
+ private URL toURL(String location)
+ {
+ URL url = null;
+ try
+ {
+ url = new URL(location);
+ }
+ catch (MalformedURLException e)
+ {
+ File locationFile = new File(location);
+ url = fileToURL(locationFile);
+ }
+ return url;
+ }
+
+ private void createStoreFileIfNotExist(File file)
+ {
+ File parent = file.getParentFile();
+ if (!parent.exists())
+ {
+ if (!parent.mkdirs())
+ {
+ throw new IllegalConfigurationException("Cannot create folders " + parent);
+ }
+ }
+ try
+ {
+ file.createNewFile();
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot create file " + file, e);
+ }
+ }
+
+ private void copyEntry(UUID entryId, ConfigurationEntryStore initialStore)
+ {
+ ConfigurationEntry entry = initialStore.getEntry(entryId);
+ if (entry != null)
+ {
+ if (_entries.containsKey(entryId))
+ {
+ throw new IllegalConfigurationException("Duplicate id is found: " + entryId
+ + "! The following configuration entries have the same id: " + _entries.get(entryId) + ", " + entry);
+ }
+ _entries.put(entryId, entry);
+ Set<UUID> children = entry.getChildrenIds();
+ if (children != null)
+ {
+ for (UUID uuid : children)
+ {
+ copyEntry(uuid, initialStore);
+ }
+ }
+ }
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java
new file mode 100644
index 0000000000..e7c474bf55
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java
@@ -0,0 +1,327 @@
+package org.apache.qpid.server.configuration.store;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.util.MapValueConverter;
+
+public class ManagementModeStoreHandler implements ConfigurationEntryStore
+{
+ private static final Logger LOGGER = Logger.getLogger(ManagementModeStoreHandler.class);
+
+ private static final String MANAGEMENT_MODE_PORT_PREFIX = "MANAGEMENT-MODE-PORT-";
+ private static final String PORT_TYPE = Port.class.getSimpleName();
+ private static final String VIRTUAL_HOST_TYPE = VirtualHost.class.getSimpleName();
+ private static final String ATTRIBUTE_STATE = VirtualHost.STATE;
+
+ private final ConfigurationEntryStore _store;
+ private final Map<UUID, ConfigurationEntry> _cliEntries;
+ private final Map<UUID, Object> _quiescedEntries;
+ private final UUID _rootId;
+
+ public ManagementModeStoreHandler(ConfigurationEntryStore store, BrokerOptions options)
+ {
+ ConfigurationEntry storeRoot = store.getRootEntry();
+ _store = store;
+ _rootId = storeRoot.getId();
+ _cliEntries = createPortsFromCommadLineOptions(options);
+ _quiescedEntries = quiesceEntries(storeRoot, options);
+ }
+
+ @Override
+ public void open(String storeLocation)
+ {
+ throw new IllegalStateException("The store should be already opened");
+ }
+
+ @Override
+ public void open(String storeLocation, String initialStoreLocation)
+ {
+ throw new IllegalStateException("The store should be already opened");
+ }
+
+ @Override
+ public void open(String storeLocation, ConfigurationEntryStore initialStore)
+ {
+ throw new IllegalStateException("The store should be already opened");
+ }
+
+ @Override
+ public ConfigurationEntry getRootEntry()
+ {
+ return getEntry(_rootId);
+ }
+
+ @Override
+ public ConfigurationEntry getEntry(UUID id)
+ {
+ synchronized (_store)
+ {
+ if (_cliEntries.containsKey(id))
+ {
+ return _cliEntries.get(id);
+ }
+
+ ConfigurationEntry entry = _store.getEntry(id);
+ if (_quiescedEntries.containsKey(id))
+ {
+ entry = createEntryWithState(entry, State.QUIESCED);
+ }
+ else if (id == _rootId)
+ {
+ entry = createRootWithCLIEntries(entry);
+ }
+ return entry;
+ }
+ }
+
+ @Override
+ public void save(ConfigurationEntry... entries)
+ {
+ synchronized (_store)
+ {
+ ConfigurationEntry[] entriesToSave = new ConfigurationEntry[entries.length];
+
+ for (int i = 0; i < entries.length; i++)
+ {
+ ConfigurationEntry entry = entries[i];
+ UUID id = entry.getId();
+ if (_cliEntries.containsKey(id))
+ {
+ throw new IllegalConfigurationException("Cannot save configuration provided as command line argument:"
+ + entry);
+ }
+ else if (_quiescedEntries.containsKey(id))
+ {
+ // save entry with the original state
+ entry = createEntryWithState(entry, _quiescedEntries.get(ATTRIBUTE_STATE));
+ }
+ else if (_rootId.equals(id))
+ {
+ // save root without command line entries
+ Set<UUID> childrenIds = new HashSet<UUID>(entry.getChildrenIds());
+ if (!_cliEntries.isEmpty())
+ {
+ childrenIds.removeAll(_cliEntries.entrySet());
+ }
+ HashMap<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes());
+ entry = new ConfigurationEntry(entry.getId(), entry.getType(), attributes, childrenIds, this);
+ }
+ entriesToSave[i] = entry;
+ }
+
+ _store.save(entriesToSave);
+ }
+ }
+
+ @Override
+ public UUID[] remove(UUID... entryIds)
+ {
+ synchronized (_store)
+ {
+ for (UUID id : entryIds)
+ {
+ if (_cliEntries.containsKey(id))
+ {
+ throw new IllegalConfigurationException("Cannot change configuration for command line entry:"
+ + _cliEntries.get(id));
+ }
+ }
+ UUID[] result = _store.remove(entryIds);
+ for (UUID id : entryIds)
+ {
+ if (_quiescedEntries.containsKey(id))
+ {
+ _quiescedEntries.remove(id);
+ }
+ }
+ return result;
+ }
+ }
+
+ @Override
+ public void copyTo(String copyLocation)
+ {
+ synchronized (_store)
+ {
+ _store.copyTo(copyLocation);
+ }
+ }
+
+ private Map<UUID, ConfigurationEntry> createPortsFromCommadLineOptions(BrokerOptions options)
+ {
+ int managementModeRmiPort = options.getManagementModeRmiPort();
+ if (managementModeRmiPort < 0)
+ {
+ throw new IllegalConfigurationException("Invalid rmi port is specified: " + managementModeRmiPort);
+ }
+ int managementModeConnectorPort = options.getManagementModeConnectorPort();
+ if (managementModeConnectorPort < 0)
+ {
+ throw new IllegalConfigurationException("Invalid connector port is specified: " + managementModeConnectorPort);
+ }
+ int managementModeHttpPort = options.getManagementModeHttpPort();
+ if (managementModeHttpPort < 0)
+ {
+ throw new IllegalConfigurationException("Invalid http port is specified: " + managementModeHttpPort);
+ }
+ Map<UUID, ConfigurationEntry> cliEntries = new HashMap<UUID, ConfigurationEntry>();
+ if (managementModeRmiPort != 0)
+ {
+ ConfigurationEntry entry = createCLIPortEntry(managementModeRmiPort, Protocol.RMI);
+ cliEntries.put(entry.getId(), entry);
+ if (managementModeConnectorPort == 0)
+ {
+ ConfigurationEntry connectorEntry = createCLIPortEntry(managementModeRmiPort + 100, Protocol.JMX_RMI);
+ cliEntries.put(connectorEntry.getId(), connectorEntry);
+ }
+ }
+ if (managementModeConnectorPort != 0)
+ {
+ ConfigurationEntry entry = createCLIPortEntry(managementModeConnectorPort, Protocol.JMX_RMI);
+ cliEntries.put(entry.getId(), entry);
+ }
+ if (managementModeHttpPort != 0)
+ {
+ ConfigurationEntry entry = createCLIPortEntry(managementModeHttpPort, Protocol.HTTP);
+ cliEntries.put(entry.getId(), entry);
+ }
+ return cliEntries;
+ }
+
+ private ConfigurationEntry createCLIPortEntry(int port, Protocol protocol)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PORT, port);
+ attributes.put(Port.PROTOCOLS, Collections.singleton(protocol));
+ attributes.put(Port.NAME, MANAGEMENT_MODE_PORT_PREFIX + protocol.name());
+ ConfigurationEntry portEntry = new ConfigurationEntry(UUID.randomUUID(), PORT_TYPE, attributes,
+ Collections.<UUID> emptySet(), this);
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Add management mode port configuration " + portEntry + " for port " + port + " and protocol "
+ + protocol);
+ }
+ return portEntry;
+ }
+
+ private ConfigurationEntry createRootWithCLIEntries(ConfigurationEntry storeRoot)
+ {
+ Set<UUID> childrenIds = new HashSet<UUID>(storeRoot.getChildrenIds());
+ if (!_cliEntries.isEmpty())
+ {
+ childrenIds.addAll(_cliEntries.keySet());
+ }
+ ConfigurationEntry root = new ConfigurationEntry(storeRoot.getId(), storeRoot.getType(), new HashMap<String, Object>(
+ storeRoot.getAttributes()), childrenIds, this);
+ return root;
+ }
+
+ private Map<UUID, Object> quiesceEntries(ConfigurationEntry storeRoot, BrokerOptions options)
+ {
+ Map<UUID, Object> quiescedEntries = new HashMap<UUID, Object>();
+ Set<UUID> childrenIds;
+ int managementModeRmiPort = options.getManagementModeRmiPort();
+ int managementModeConnectorPort = options.getManagementModeConnectorPort();
+ int managementModeHttpPort = options.getManagementModeHttpPort();
+ childrenIds = storeRoot.getChildrenIds();
+ for (UUID id : childrenIds)
+ {
+ ConfigurationEntry entry = _store.getEntry(id);
+ String entryType = entry.getType();
+ Map<String, Object> attributes = entry.getAttributes();
+ boolean quiesce = false;
+ if (VIRTUAL_HOST_TYPE.equals(entryType))
+ {
+ quiesce = true;
+ }
+ else if (PORT_TYPE.equalsIgnoreCase(entryType))
+ {
+ if (attributes == null)
+ {
+ throw new IllegalConfigurationException("Port attributes are not set in " + entry);
+ }
+ Set<Protocol> protocols = getPortProtocolsAttribute(attributes);
+ if (protocols == null)
+ {
+ quiesce = true;
+ }
+ else
+ {
+ for (Protocol protocol : protocols)
+ {
+ switch (protocol)
+ {
+ case JMX_RMI:
+ quiesce = managementModeConnectorPort > 0 || managementModeRmiPort > 0;
+ break;
+ case RMI:
+ quiesce = managementModeRmiPort > 0;
+ break;
+ case HTTP:
+ case HTTPS:
+ quiesce = managementModeHttpPort > 0;
+ break;
+ default:
+ quiesce = true;
+ }
+ }
+ }
+ }
+ if (quiesce)
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Management mode quiescing entry " + entry);
+ }
+
+ // save original state
+ quiescedEntries.put(entry.getId(), attributes.get(ATTRIBUTE_STATE));
+ }
+ }
+ return quiescedEntries;
+ }
+
+ private Set<Protocol> getPortProtocolsAttribute(Map<String, Object> attributes)
+ {
+ Object object = attributes.get(Port.PROTOCOLS);
+ if (object == null)
+ {
+ return null;
+ }
+ return MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, attributes, Protocol.class);
+ }
+
+ private ConfigurationEntry createEntryWithState(ConfigurationEntry entry, Object state)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes());
+ if (state == null)
+ {
+ attributes.remove(ATTRIBUTE_STATE);
+ }
+ else
+ {
+ attributes.put(ATTRIBUTE_STATE, state);
+ }
+ Set<UUID> originalChildren = entry.getChildrenIds();
+ Set<UUID> children = null;
+ if (originalChildren != null)
+ {
+ children = new HashSet<UUID>(originalChildren);
+ }
+ return new ConfigurationEntry(entry.getId(), entry.getType(), attributes, children, entry.getStore());
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java
new file mode 100644
index 0000000000..813702d0a6
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListener.java
@@ -0,0 +1,205 @@
+/*
+ *
+ * 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.configuration.store;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+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.Model;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+
+public class StoreConfigurationChangeListener implements ConfigurationChangeListener
+{
+ private ConfigurationEntryStore _store;
+
+ public StoreConfigurationChangeListener(ConfigurationEntryStore store)
+ {
+ super();
+ _store = store;
+ }
+
+ @Override
+ public void stateChanged(ConfiguredObject object, State oldState, State newState)
+ {
+ if (newState == State.DELETED)
+ {
+ _store.remove(object.getId());
+ object.removeChangeListener(this);
+ }
+ }
+
+ @Override
+ public void childAdded(ConfiguredObject object, ConfiguredObject child)
+ {
+ // exclude VirtualHost children from storing in broker store
+ if (!(object instanceof VirtualHost))
+ {
+ child.addChangeListener(this);
+ ConfigurationEntry parentEntry = toConfigurationEntry(object);
+ ConfigurationEntry childEntry = toConfigurationEntry(child);
+ _store.save(parentEntry, childEntry);
+ }
+
+ }
+
+ @Override
+ public void childRemoved(ConfiguredObject object, ConfiguredObject child)
+ {
+ _store.save(toConfigurationEntry(object));
+ }
+
+ @Override
+ public void attributeSet(ConfiguredObject object, String attrinuteName, Object oldAttributeValue, Object newAttributeValue)
+ {
+ _store.save(toConfigurationEntry(object));
+ }
+
+ private ConfigurationEntry toConfigurationEntry(ConfiguredObject object)
+ {
+ Class<? extends ConfiguredObject> objectType = getConfiguredObjectType(object);
+ Set<UUID> childrenIds = getChildernIds(object, objectType);
+ ConfigurationEntry entry = new ConfigurationEntry(object.getId(), objectType.getSimpleName(),
+ object.getActualAttributes(), childrenIds, _store);
+ return entry;
+ }
+
+ private Set<UUID> getChildernIds(ConfiguredObject object, Class<? extends ConfiguredObject> objectType)
+ {
+ // Virtual Host children's IDs should not be stored in broker store
+ if (object instanceof VirtualHost)
+ {
+ return Collections.emptySet();
+ }
+ Set<UUID> childrenIds = new TreeSet<UUID>();
+ Collection<Class<? extends ConfiguredObject>> childClasses = Model.getInstance().getChildTypes(objectType);
+ if (childClasses != null)
+ {
+ for (Class<? extends ConfiguredObject> childClass : childClasses)
+ {
+ Collection<? extends ConfiguredObject> children = object.getChildren(childClass);
+ if (children != null)
+ {
+ for (ConfiguredObject childObject : children)
+ {
+ childrenIds.add(childObject.getId());
+ }
+ }
+ }
+ }
+ return childrenIds;
+ }
+
+ private Class<? extends ConfiguredObject> getConfiguredObjectType(ConfiguredObject object)
+ {
+ if (object instanceof Broker)
+ {
+ return Broker.class;
+ }
+ return getConfiguredObjectTypeFromImplementedInterfaces(object.getClass());
+ }
+
+ @SuppressWarnings("unchecked")
+ private Class<? extends ConfiguredObject> getConfiguredObjectTypeFromImplementedInterfaces(Class<?> objectClass)
+ {
+ // get all implemented interfaces extending ConfiguredObject
+ Set<Class<?>> interfaces = getImplementedInterfacesExtendingSuper(objectClass, ConfiguredObject.class);
+
+ if (interfaces.size() == 0)
+ {
+ throw new RuntimeException("Can not identify the configured object type");
+ }
+
+ if (interfaces.size() == 1)
+ {
+ return (Class<? extends ConfiguredObject>)interfaces.iterator().next();
+ }
+
+ Set<Class<?>> superInterfaces = new HashSet<Class<?>>();
+
+ // find all super interfaces
+ for (Class<?> interfaceClass : interfaces)
+ {
+ for (Class<?> interfaceClass2 : interfaces)
+ {
+ if (interfaceClass != interfaceClass2)
+ {
+ if (interfaceClass.isAssignableFrom(interfaceClass2))
+ {
+ superInterfaces.add(interfaceClass);
+ }
+ }
+ }
+ }
+
+ // remove super interfaces
+ for (Class<?> superInterface : superInterfaces)
+ {
+ interfaces.remove(superInterface);
+ }
+
+ if (interfaces.size() == 1)
+ {
+ return (Class<? extends ConfiguredObject>)interfaces.iterator().next();
+ }
+ else
+ {
+ throw new RuntimeException("Can not identify the configured object type as an it implements"
+ + " more than one configured object interfaces: " + interfaces);
+ }
+
+ }
+
+ private Set<Class<?>> getImplementedInterfacesExtendingSuper(Class<?> classInstance, Class<?> superInterface)
+ {
+ Set<Class<?>> interfaces = new HashSet<Class<?>>();
+ Class<?>[] classInterfaces = classInstance.getInterfaces();
+ for (Class<?> interfaceClass : classInterfaces)
+ {
+ if (interfaceClass!= superInterface && superInterface.isAssignableFrom(interfaceClass))
+ {
+ interfaces.add(interfaceClass);
+ }
+ }
+ Class<?> superClass = classInstance.getSuperclass();
+ if (superClass != null)
+ {
+ Set<Class<?>> superClassInterfaces = getImplementedInterfacesExtendingSuper(superClass, superInterface);
+ interfaces.addAll(superClassInterfaces);
+ }
+ return interfaces;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "StoreConfigurationChangeListener [store=" + _store + "]";
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java
new file mode 100644
index 0000000000..e37e58b840
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/store/factory/JsonConfigurationStoreFactory.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.configuration.store.factory;
+
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.ConfigurationStoreFactory;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+
+public class JsonConfigurationStoreFactory implements ConfigurationStoreFactory
+{
+ @Override
+ public ConfigurationEntryStore createStore()
+ {
+ return new JsonConfigurationEntryStore();
+ }
+
+ @Override
+ public String getStoreType()
+ {
+ return JsonConfigurationEntryStore.STORE_TYPE;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java
new file mode 100644
index 0000000000..b6de1e136a
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.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.server.configuration.updater;
+
+import java.util.concurrent.Callable;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.State;
+
+public final class ChangeStateTask implements Callable<State>
+{
+ private ConfiguredObject _object;
+ private State _expectedState;
+ private State _desiredState;
+
+ public ChangeStateTask(ConfiguredObject object, State expectedState, State desiredState)
+ {
+ _object = object;
+ _expectedState = expectedState;
+ _desiredState = desiredState;
+ }
+
+ public ConfiguredObject getObject()
+ {
+ return _object;
+ }
+
+ public State getExpectedState()
+ {
+ return _expectedState;
+ }
+
+ public State getDesiredState()
+ {
+ return _desiredState;
+ }
+
+ @Override
+ public State call()
+ {
+ return _object.setDesiredState(_expectedState, _desiredState);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ChangeStateTask [object=" + _object + ", expectedState=" + _expectedState + ", desiredState=" + _desiredState + "]";
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java
new file mode 100644
index 0000000000..d3a8f5b797
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.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.server.configuration.updater;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public final class CreateChildTask implements Callable<ConfiguredObject>
+{
+ private ConfiguredObject _object;
+ private Class<? extends ConfiguredObject> _childClass;
+ private Map<String, Object> _attributes;
+ private ConfiguredObject[] _otherParents;
+
+ public CreateChildTask(ConfiguredObject object, Class<? extends ConfiguredObject> childClass, Map<String, Object> attributes,
+ ConfiguredObject... otherParents)
+ {
+ _object = object;
+ _childClass = childClass;
+ _attributes = attributes;
+ _otherParents = otherParents;
+ }
+
+ public ConfiguredObject getObject()
+ {
+ return _object;
+ }
+
+ public Class<? extends ConfiguredObject> getChildClass()
+ {
+ return _childClass;
+ }
+
+ public Map<String, Object> getAttributes()
+ {
+ return _attributes;
+ }
+
+ public ConfiguredObject[] getOtherParents()
+ {
+ return _otherParents;
+ }
+
+ @Override
+ public ConfiguredObject call()
+ {
+ return _object.createChild(_childClass, _attributes, _otherParents);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "CreateChildTask [object=" + _object + ", childClass=" + _childClass + ", attributes=" + _attributes
+ + ", otherParents=" + Arrays.toString(_otherParents) + "]";
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java
new file mode 100644
index 0000000000..94649434e6
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.configuration.updater;
+
+import java.util.concurrent.Callable;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public final class SetAttributeTask implements Callable<Object>
+{
+ private ConfiguredObject _object;
+ private String _attributeName;
+ private Object _expectedValue;
+ private Object _desiredValue;
+
+ public SetAttributeTask(ConfiguredObject object, String attributeName, Object expectedValue, Object desiredValue)
+ {
+ _object = object;
+ _attributeName = attributeName;
+ _expectedValue = expectedValue;
+ _desiredValue = desiredValue;
+ }
+
+ public ConfiguredObject getObject()
+ {
+ return _object;
+ }
+
+ public String getAttributeName()
+ {
+ return _attributeName;
+ }
+
+ public Object getExpectedValue()
+ {
+ return _expectedValue;
+ }
+
+ public Object getDesiredValue()
+ {
+ return _desiredValue;
+ }
+
+ @Override
+ public Object call()
+ {
+ return _object.setAttribute(_attributeName, _expectedValue, _desiredValue);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SetAttributeTask [object=" + _object + ", attributeName=" + _attributeName + ", expectedValue=" + _expectedValue
+ + ", desiredValue=" + _desiredValue + "]";
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java
new file mode 100644
index 0000000000..671104d413
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java
@@ -0,0 +1,324 @@
+/*
+ *
+ * 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.configuration.updater;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.RunnableFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.security.auth.Subject;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.security.SecurityManager;
+
+public class TaskExecutor
+{
+ private static final String TASK_EXECUTION_THREAD_NAME = "Broker-Configuration-Thread";
+ private static final Logger LOGGER = Logger.getLogger(TaskExecutor.class);
+
+ private volatile Thread _taskThread;
+ private final AtomicReference<State> _state;
+ private volatile ExecutorService _executor;
+
+ public TaskExecutor()
+ {
+ _state = new AtomicReference<State>(State.INITIALISING);
+ }
+
+ public State getState()
+ {
+ return _state.get();
+ }
+
+ public void start()
+ {
+ if (_state.compareAndSet(State.INITIALISING, State.ACTIVE))
+ {
+ LOGGER.debug("Starting task executor");
+ _executor = Executors.newFixedThreadPool(1, new ThreadFactory()
+ {
+ @Override
+ public Thread newThread(Runnable r)
+ {
+ _taskThread = new Thread(r, TASK_EXECUTION_THREAD_NAME);
+ return _taskThread;
+ }
+ });
+ LOGGER.debug("Task executor is started");
+ }
+ }
+
+ public void stopImmediately()
+ {
+ if (_state.compareAndSet(State.ACTIVE, State.STOPPED))
+ {
+ ExecutorService executor = _executor;
+ if (executor != null)
+ {
+ LOGGER.debug("Stopping task executor immediately");
+ List<Runnable> cancelledTasks = executor.shutdownNow();
+ if (cancelledTasks != null)
+ {
+ for (Runnable runnable : cancelledTasks)
+ {
+ if (runnable instanceof RunnableFuture<?>)
+ {
+ ((RunnableFuture<?>) runnable).cancel(true);
+ }
+ }
+ }
+ _executor = null;
+ _taskThread = null;
+ LOGGER.debug("Task executor was stopped immediately. Number of unfinished tasks: " + cancelledTasks.size());
+ }
+ }
+ }
+
+ public void stop()
+ {
+ if (_state.compareAndSet(State.ACTIVE, State.STOPPED))
+ {
+ ExecutorService executor = _executor;
+ if (executor != null)
+ {
+ LOGGER.debug("Stopping task executor");
+ executor.shutdown();
+ _executor = null;
+ _taskThread = null;
+ LOGGER.debug("Task executor is stopped");
+ }
+ }
+ }
+
+ Future<?> submit(Callable<?> task)
+ {
+ checkState();
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Submitting task: " + task);
+ }
+ Future<?> future = null;
+ if (isTaskExecutorThread())
+ {
+ Object result = executeTaskAndHandleExceptions(task);
+ return new ImmediateFuture(result);
+ }
+ else
+ {
+ future = _executor.submit(new CallableWrapper(task));
+ }
+ return future;
+ }
+
+ public Object submitAndWait(Callable<?> task) throws CancellationException
+ {
+ try
+ {
+ Future<?> future = submit(task);
+ return future.get();
+ }
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException("Task execution was interrupted: " + task, e);
+ }
+ catch (ExecutionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException) cause;
+ }
+ else if (cause instanceof Exception)
+ {
+ throw new RuntimeException("Failed to execute user task: " + task, cause);
+ }
+ else if (cause instanceof Error)
+ {
+ throw (Error) cause;
+ }
+ else
+ {
+ throw new RuntimeException("Failed to execute user task: " + task, cause);
+ }
+ }
+ }
+
+ public boolean isTaskExecutorThread()
+ {
+ return Thread.currentThread() == _taskThread;
+ }
+
+ private void checkState()
+ {
+ if (_state.get() != State.ACTIVE)
+ {
+ throw new IllegalStateException("Task executor is not in ACTIVE state");
+ }
+ }
+
+ private Object executeTaskAndHandleExceptions(Callable<?> userTask)
+ {
+ try
+ {
+ return executeTask(userTask);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof RuntimeException)
+ {
+ throw (RuntimeException) e;
+ }
+ throw new RuntimeException("Failed to execute user task: " + userTask, e);
+ }
+ }
+
+ private Object executeTask(Callable<?> userTask) throws Exception
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Performing task " + userTask);
+ }
+ Object result = userTask.call();
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Task " + userTask + " is performed successfully with result:" + result);
+ }
+ return result;
+ }
+
+ private class CallableWrapper implements Callable<Object>
+ {
+ private Callable<?> _userTask;
+ private Subject _securityManagerSubject;
+ private LogActor _actor;
+ private Subject _contextSubject;
+
+ public CallableWrapper(Callable<?> userWork)
+ {
+ _userTask = userWork;
+ _securityManagerSubject = SecurityManager.getThreadSubject();
+ _actor = CurrentActor.get();
+ _contextSubject = Subject.getSubject(AccessController.getContext());
+ }
+
+ @Override
+ public Object call() throws Exception
+ {
+ SecurityManager.setThreadSubject(_securityManagerSubject);
+ CurrentActor.set(_actor);
+
+ try
+ {
+ Object result = null;
+ try
+ {
+ result = Subject.doAs(_contextSubject, new PrivilegedExceptionAction<Object>()
+ {
+ @Override
+ public Object run() throws Exception
+ {
+ return executeTask(_userTask);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ return result;
+ }
+ finally
+ {
+ try
+ {
+ CurrentActor.remove();
+ }
+ catch (Exception e)
+ {
+ LOGGER.warn("Unxpected exception on current actor removal", e);
+ }
+ try
+ {
+ SecurityManager.setThreadSubject(null);
+ }
+ catch (Exception e)
+ {
+ LOGGER.warn("Unxpected exception on nullifying of subject for a security manager", e);
+ }
+ }
+ }
+ }
+
+ private class ImmediateFuture implements Future<Object>
+ {
+ private Object _result;
+
+ public ImmediateFuture(Object result)
+ {
+ super();
+ this._result = result;
+ }
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isDone()
+ {
+ return true;
+ }
+
+ @Override
+ public Object get()
+ {
+ return _result;
+ }
+
+ @Override
+ public Object get(long timeout, TimeUnit unit)
+ {
+ return get();
+ }
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
index 512a8c6996..246e056f0b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
@@ -23,14 +23,12 @@ package org.apache.qpid.server.exchange;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.ExchangeConfigType;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.messages.ExchangeMessages;
import org.apache.qpid.server.logging.subjects.ExchangeLogSubject;
import org.apache.qpid.server.message.InboundMessage;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.QueueRegistry;
@@ -86,8 +84,6 @@ public abstract class AbstractExchange implements Exchange
//TODO : persist creation time
private long _createTime = System.currentTimeMillis();
- private UUID _qmfId;
-
public AbstractExchange(final ExchangeType<? extends Exchange> type)
{
_type = type;
@@ -113,19 +109,12 @@ public abstract class AbstractExchange implements Exchange
_ticket = ticket;
_id = id;
- _qmfId = getConfigStore().createId();
- getConfigStore().addConfiguredObject(this);
_logSubject = new ExchangeLogSubject(this, this.getVirtualHost());
// Log Exchange creation
CurrentActor.get().message(ExchangeMessages.CREATED(String.valueOf(getTypeShortString()), String.valueOf(name), durable));
}
- public ConfigStore getConfigStore()
- {
- return getVirtualHost().getConfigStore();
- }
-
public boolean isDurable()
{
return _durable;
@@ -146,7 +135,6 @@ public abstract class AbstractExchange implements Exchange
if(_closed.compareAndSet(false,true))
{
- getConfigStore().removeConfiguredObject(this);
if(_alternateExchange != null)
{
_alternateExchange.removeReference(this);
@@ -298,29 +286,11 @@ public abstract class AbstractExchange implements Exchange
return _id;
}
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public ExchangeConfigType getConfigType()
- {
- return ExchangeConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return _virtualHost;
- }
-
public long getBindingCount()
{
return getBindings().size();
}
-
-
public final List<? extends BaseQueue> route(final InboundMessage message)
{
_receivedMessageCount.incrementAndGet();
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java
index 5058f91995..5e6e36d330 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeFactory.java
@@ -27,10 +27,9 @@ import org.apache.qpid.AMQSecurityException;
import org.apache.qpid.AMQUnknownExchangeType;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.qmf.ManagementExchange;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.plugin.ExchangeType;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
import org.apache.qpid.server.virtualhost.VirtualHost;
import java.util.ArrayList;
@@ -41,42 +40,72 @@ import java.util.UUID;
public class DefaultExchangeFactory implements ExchangeFactory
{
- private static final Logger _logger = Logger.getLogger(DefaultExchangeFactory.class);
public static final String DEFAULT_DLE_NAME_SUFFIX = "_DLE";
- private Map<AMQShortString, ExchangeType<? extends Exchange>> _exchangeClassMap = new HashMap<AMQShortString, ExchangeType<? extends Exchange>>();
+ private static final Logger LOGGER = Logger.getLogger(DefaultExchangeFactory.class);
+
+ private static final AMQShortString[] BASE_EXCHANGE_TYPES =
+ new AMQShortString[]{ExchangeDefaults.DIRECT_EXCHANGE_CLASS,
+ ExchangeDefaults.FANOUT_EXCHANGE_CLASS,
+ ExchangeDefaults.HEADERS_EXCHANGE_CLASS,
+ ExchangeDefaults.TOPIC_EXCHANGE_CLASS};
+
private final VirtualHost _host;
+ private Map<AMQShortString, ExchangeType<? extends Exchange>> _exchangeClassMap = new HashMap<AMQShortString, ExchangeType<? extends Exchange>>();
public DefaultExchangeFactory(VirtualHost host)
{
_host = host;
- registerExchangeType(DirectExchange.TYPE);
- registerExchangeType(TopicExchange.TYPE);
- registerExchangeType(HeadersExchange.TYPE);
- registerExchangeType(FanoutExchange.TYPE);
- registerExchangeType(ManagementExchange.TYPE);
+
+ @SuppressWarnings("rawtypes")
+ Iterable<ExchangeType> exchangeTypes = loadExchangeTypes();
+ for (ExchangeType<?> exchangeType : exchangeTypes)
+ {
+ AMQShortString typeName = exchangeType.getName();
+
+ if(LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Registering exchange type '" + typeName + "' using class '" + exchangeType.getClass().getName() + "'");
+ }
+
+ if(_exchangeClassMap.containsKey(typeName))
+ {
+ ExchangeType<?> existingType = _exchangeClassMap.get(typeName);
+
+ throw new IllegalStateException("ExchangeType with type name '" + typeName + "' is already registered using class '"
+ + existingType.getClass().getName() + "', can not register class '"
+ + exchangeType.getClass().getName() + "'");
+ }
+
+ _exchangeClassMap.put(typeName, exchangeType);
+ }
+
+ for(AMQShortString type : BASE_EXCHANGE_TYPES)
+ {
+ if(!_exchangeClassMap.containsKey(type))
+ {
+ throw new IllegalStateException("Did not find expected exchange type: " + type.asString());
+ }
+ }
}
- public void registerExchangeType(ExchangeType<? extends Exchange> type)
+ @SuppressWarnings("rawtypes")
+ protected Iterable<ExchangeType> loadExchangeTypes()
{
- _exchangeClassMap.put(type.getName(), type);
+ return new QpidServiceLoader<ExchangeType>().atLeastOneInstanceOf(ExchangeType.class);
}
public Collection<ExchangeType<? extends Exchange>> getRegisteredTypes()
{
return _exchangeClassMap.values();
}
-
+
public Collection<ExchangeType<? extends Exchange>> getPublicCreatableTypes()
{
Collection<ExchangeType<? extends Exchange>> publicTypes =
new ArrayList<ExchangeType<? extends Exchange>>();
publicTypes.addAll(_exchangeClassMap.values());
- //Remove the ManagementExchange type if present, as these
- //are private and cannot be created by external means
- publicTypes.remove(ManagementExchange.TYPE);
-
return publicTypes;
}
@@ -120,42 +149,4 @@ public class DefaultExchangeFactory implements ExchangeFactory
Exchange e = exchType.newInstance(id, _host, exchange, durable, ticket, autoDelete);
return e;
}
-
- public void initialise(VirtualHostConfiguration hostConfig)
- {
-
- if (hostConfig == null)
- {
- return;
- }
-
- for(Object className : hostConfig.getCustomExchanges())
- {
- try
- {
- ExchangeType<?> exchangeType = ApplicationRegistry.getInstance().getPluginManager().getExchanges().get(String.valueOf(className));
- if (exchangeType == null)
- {
- _logger.error("No such custom exchange class found: \""+String.valueOf(className)+"\"");
- continue;
- }
- Class<? extends ExchangeType> exchangeTypeClass = exchangeType.getClass();
- ExchangeType<? extends ExchangeType> type = exchangeTypeClass.newInstance();
- registerExchangeType(type);
- }
- catch (ClassCastException classCastEx)
- {
- _logger.error("No custom exchange class: \""+String.valueOf(className)+"\" cannot be registered as it does not extend class \""+ExchangeType.class+"\"");
- }
- catch (IllegalAccessException e)
- {
- _logger.error("Cannot create custom exchange class: \""+String.valueOf(className)+"\"",e);
- }
- catch (InstantiationException e)
- {
- _logger.error("Cannot create custom exchange class: \""+String.valueOf(className)+"\"",e);
- }
- }
-
- }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java
index 07813b073b..9cce8d640b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/DefaultExchangeRegistry.java
@@ -26,6 +26,7 @@ import org.apache.qpid.AMQSecurityException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.virtualhost.VirtualHost;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java
index 92326412c1..fc6ce15bc4 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchange.java
@@ -20,30 +20,22 @@
*/
package org.apache.qpid.server.exchange;
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.message.InboundMessage;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import javax.management.JMException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
public class DirectExchange extends AbstractExchange
{
- private static final Logger _logger = Logger.getLogger(DirectExchange.class);
-
private static final class BindingSet
{
private CopyOnWriteArraySet<Binding> _bindings = new CopyOnWriteArraySet<Binding>();
@@ -55,7 +47,6 @@ public class DirectExchange extends AbstractExchange
recalculateQueues();
}
-
public synchronized void removeBinding(Binding binding)
{
_bindings.remove(binding);
@@ -91,36 +82,7 @@ public class DirectExchange extends AbstractExchange
private final ConcurrentHashMap<String, BindingSet> _bindingsByKey =
new ConcurrentHashMap<String, BindingSet>();
- public static final ExchangeType<DirectExchange> TYPE = new ExchangeType<DirectExchange>()
- {
-
- public AMQShortString getName()
- {
- return ExchangeDefaults.DIRECT_EXCHANGE_CLASS;
- }
-
- public Class<DirectExchange> getExchangeClass()
- {
- return DirectExchange.class;
- }
-
- public DirectExchange newInstance(UUID id, VirtualHost host,
- AMQShortString name,
- boolean durable,
- int ticket,
- boolean autoDelete) throws AMQException
- {
- DirectExchange exch = new DirectExchange();
- exch.initialise(id, host,name,durable,ticket,autoDelete);
- return exch;
- }
-
- public AMQShortString getDefaultExchangeName()
- {
- return ExchangeDefaults.DIRECT_EXCHANGE_NAME;
- }
- };
-
+ public static final ExchangeType<DirectExchange> TYPE = new DirectExchangeType();
public DirectExchange()
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java
new file mode 100644
index 0000000000..096d5265ed
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/DirectExchangeType.java
@@ -0,0 +1,53 @@
+/*
+ *
+ * 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.exchange;
+
+import java.util.UUID;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.exchange.ExchangeDefaults;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.plugin.ExchangeType;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+
+public class DirectExchangeType implements ExchangeType<DirectExchange>
+{
+ public AMQShortString getName()
+ {
+ return ExchangeDefaults.DIRECT_EXCHANGE_CLASS;
+ }
+
+ public DirectExchange newInstance(UUID id, VirtualHost host,
+ AMQShortString name,
+ boolean durable,
+ int ticket,
+ boolean autoDelete) throws AMQException
+ {
+ DirectExchange exch = new DirectExchange();
+ exch.initialise(id, host,name,durable,ticket,autoDelete);
+ return exch;
+ }
+
+ public AMQShortString getDefaultExchangeName()
+ {
+ return ExchangeDefaults.DIRECT_EXCHANGE_NAME;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java
index 762686e68d..4bafb04c33 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/Exchange.java
@@ -26,8 +26,8 @@ import org.apache.qpid.AMQSecurityException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.ExchangeConfig;
import org.apache.qpid.server.message.InboundMessage;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -38,9 +38,23 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
-public interface Exchange extends ExchangeReferrer, ExchangeConfig
+public interface Exchange extends ExchangeReferrer
{
+ String getName();
+
+ ExchangeType getType();
+
+ long getBindingCount();
+
+ long getByteDrops();
+
+ long getByteReceives();
+
+ long getMsgDrops();
+
+ long getMsgReceives();
+
public interface BindingListener
{
void bindingAdded(Exchange exchange, Binding binding);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java
index aae4ae89bb..e602d476d9 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeFactory.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.exchange;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.plugin.ExchangeType;
import java.util.Collection;
import java.util.UUID;
@@ -34,8 +34,6 @@ public interface ExchangeFactory
int ticket)
throws AMQException;
- void initialise(VirtualHostConfiguration hostConfig);
-
Collection<ExchangeType<? extends Exchange>> getRegisteredTypes();
Collection<ExchangeType<? extends Exchange>> getPublicCreatableTypes();
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java
index ba4f57a8e0..edb476f3aa 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeInitialiser.java
@@ -24,6 +24,7 @@ package org.apache.qpid.server.exchange;
import org.apache.qpid.AMQException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.store.DurableConfigurationStore;
public class ExchangeInitialiser
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java
deleted file mode 100644
index a01e41f039..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/ExchangeType.java
+++ /dev/null
@@ -1,37 +0,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.
- *
- */
-package org.apache.qpid.server.exchange;
-
-import java.util.UUID;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-
-
-public interface ExchangeType<T extends Exchange>
-{
- public AMQShortString getName();
- public Class<T> getExchangeClass();
- public T newInstance(UUID id, VirtualHost host, AMQShortString name,
- boolean durable, int ticket, boolean autoDelete) throws AMQException;
- public AMQShortString getDefaultExchangeName();
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java
index 5f4998f77f..8c433ce985 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchange.java
@@ -22,19 +22,15 @@ package org.apache.qpid.server.exchange;
import org.apache.log4j.Logger;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.message.InboundMessage;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import javax.management.JMException;
import java.util.ArrayList;
-import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class FanoutExchange extends AbstractExchange
@@ -48,35 +44,7 @@ public class FanoutExchange extends AbstractExchange
*/
private final ConcurrentHashMap<AMQQueue,Integer> _queues = new ConcurrentHashMap<AMQQueue,Integer>();
- public static final ExchangeType<FanoutExchange> TYPE = new ExchangeType<FanoutExchange>()
- {
-
- public AMQShortString getName()
- {
- return ExchangeDefaults.FANOUT_EXCHANGE_CLASS;
- }
-
- public Class<FanoutExchange> getExchangeClass()
- {
- return FanoutExchange.class;
- }
-
- public FanoutExchange newInstance(UUID id, VirtualHost host,
- AMQShortString name,
- boolean durable,
- int ticket,
- boolean autoDelete) throws AMQException
- {
- FanoutExchange exch = new FanoutExchange();
- exch.initialise(id, host, name, durable, ticket, autoDelete);
- return exch;
- }
-
- public AMQShortString getDefaultExchangeName()
- {
- return ExchangeDefaults.FANOUT_EXCHANGE_NAME;
- }
- };
+ public static final ExchangeType<FanoutExchange> TYPE = new FanoutExchangeType();
public FanoutExchange()
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.java
new file mode 100644
index 0000000000..0371a363de
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/FanoutExchangeType.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.server.exchange;
+
+import java.util.UUID;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.exchange.ExchangeDefaults;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.plugin.ExchangeType;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+
+public class FanoutExchangeType implements ExchangeType<FanoutExchange>
+{
+ public AMQShortString getName()
+ {
+ return ExchangeDefaults.FANOUT_EXCHANGE_CLASS;
+ }
+
+ public FanoutExchange newInstance(UUID id, VirtualHost host, AMQShortString name,
+ boolean durable, int ticket, boolean autoDelete)
+ throws AMQException
+ {
+ FanoutExchange exch = new FanoutExchange();
+ exch.initialise(id, host, name, durable, ticket, autoDelete);
+ return exch;
+ }
+
+ public AMQShortString getDefaultExchangeName()
+ {
+ return ExchangeDefaults.FANOUT_EXCHANGE_NAME;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java
index 6bad59c2ae..746c8ac6bc 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchange.java
@@ -22,22 +22,18 @@ package org.apache.qpid.server.exchange;
import org.apache.log4j.Logger;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.message.AMQMessageHeader;
import org.apache.qpid.server.message.InboundMessage;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import javax.management.JMException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Map;
-import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -81,40 +77,12 @@ public class HeadersExchange extends AbstractExchange
new CopyOnWriteArrayList<HeadersBinding>();
- public static final ExchangeType<HeadersExchange> TYPE = new ExchangeType<HeadersExchange>()
- {
-
- public AMQShortString getName()
- {
- return ExchangeDefaults.HEADERS_EXCHANGE_CLASS;
- }
-
- public Class<HeadersExchange> getExchangeClass()
- {
- return HeadersExchange.class;
- }
-
- public HeadersExchange newInstance(UUID id, VirtualHost host, AMQShortString name, boolean durable, int ticket,
- boolean autoDelete) throws AMQException
- {
- HeadersExchange exch = new HeadersExchange();
-
- exch.initialise(id, host, name, durable, ticket, autoDelete);
- return exch;
- }
-
- public AMQShortString getDefaultExchangeName()
- {
-
- return ExchangeDefaults.HEADERS_EXCHANGE_NAME;
- }
- };
+ public static final ExchangeType<HeadersExchange> TYPE = new HeadersExchangeType();
public HeadersExchange()
{
super(TYPE);
}
-
public ArrayList<BaseQueue> doRoute(InboundMessage payload)
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java
new file mode 100644
index 0000000000..ed4d57d0f8
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/HeadersExchangeType.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.exchange;
+
+import java.util.UUID;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.exchange.ExchangeDefaults;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.plugin.ExchangeType;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+
+public class HeadersExchangeType implements ExchangeType<HeadersExchange>
+{
+ public AMQShortString getName()
+ {
+ return ExchangeDefaults.HEADERS_EXCHANGE_CLASS;
+ }
+
+ public HeadersExchange newInstance(UUID id, VirtualHost host, AMQShortString name, boolean durable, int ticket,
+ boolean autoDelete) throws AMQException
+ {
+ HeadersExchange exch = new HeadersExchange();
+
+ exch.initialise(id, host, name, durable, ticket, autoDelete);
+ return exch;
+ }
+
+ public AMQShortString getDefaultExchangeName()
+ {
+
+ return ExchangeDefaults.HEADERS_EXCHANGE_NAME;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java
index 0ce16bd3f7..6d548be508 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java
@@ -27,15 +27,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
-import javax.management.JMException;
import org.apache.log4j.Logger;
-import org.apache.qpid.AMQException;
import org.apache.qpid.AMQInvalidArgumentException;
import org.apache.qpid.common.AMQPFilterTypes;
-import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.filter.SelectorParsingException;
import org.apache.qpid.filter.selector.ParseException;
import org.apache.qpid.filter.selector.TokenMgrError;
@@ -49,44 +45,15 @@ import org.apache.qpid.server.exchange.topic.TopicParser;
import org.apache.qpid.server.filter.JMSSelectorFilter;
import org.apache.qpid.server.filter.MessageFilter;
import org.apache.qpid.server.message.InboundMessage;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.Filterable;
-import org.apache.qpid.server.virtualhost.VirtualHost;
public class TopicExchange extends AbstractExchange
{
-
- public static final ExchangeType<TopicExchange> TYPE = new ExchangeType<TopicExchange>()
- {
-
- public AMQShortString getName()
- {
- return ExchangeDefaults.TOPIC_EXCHANGE_CLASS;
- }
-
- public Class<TopicExchange> getExchangeClass()
- {
- return TopicExchange.class;
- }
-
- public TopicExchange newInstance(UUID id, VirtualHost host,
- AMQShortString name,
- boolean durable,
- int ticket,
- boolean autoDelete) throws AMQException
- {
- TopicExchange exch = new TopicExchange();
- exch.initialise(id, host, name, durable, ticket, autoDelete);
- return exch;
- }
-
- public AMQShortString getDefaultExchangeName()
- {
- return ExchangeDefaults.TOPIC_EXCHANGE_NAME;
- }
- };
+ public static final ExchangeType<TopicExchange> TYPE = new TopicExchangeType();
private static final Logger _logger = Logger.getLogger(TopicExchange.class);
@@ -291,7 +258,7 @@ public class TopicExchange extends AbstractExchange
public boolean isBound(AMQShortString routingKey, FieldTable arguments, AMQQueue queue)
{
- Binding binding = new Binding(null, null, routingKey.toString(), queue, this, FieldTable.convertToMap(arguments));
+ Binding binding = new Binding(null, routingKey.toString(), queue, this, FieldTable.convertToMap(arguments));
if (arguments == null)
{
@@ -314,7 +281,7 @@ public class TopicExchange extends AbstractExchange
public boolean isBound(String bindingKey, Map<String, Object> arguments, AMQQueue queue)
{
- Binding binding = new Binding(null, null, bindingKey, queue, this, arguments);
+ Binding binding = new Binding(null, bindingKey, queue, this, arguments);
if (arguments == null)
{
return _bindings.containsKey(binding);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java
new file mode 100644
index 0000000000..25a3549e61
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchangeType.java
@@ -0,0 +1,53 @@
+/*
+ *
+ * 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.exchange;
+
+import java.util.UUID;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.exchange.ExchangeDefaults;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.plugin.ExchangeType;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+
+public class TopicExchangeType implements ExchangeType<TopicExchange>
+{
+ public AMQShortString getName()
+ {
+ return ExchangeDefaults.TOPIC_EXCHANGE_CLASS;
+ }
+
+ public TopicExchange newInstance(UUID id, VirtualHost host,
+ AMQShortString name,
+ boolean durable,
+ int ticket,
+ boolean autoDelete) throws AMQException
+ {
+ TopicExchange exch = new TopicExchange();
+ exch.initialise(id, host, name, durable, ticket, autoDelete);
+ return exch;
+ }
+
+ public AMQShortString getDefaultExchangeName()
+ {
+ return ExchangeDefaults.TOPIC_EXCHANGE_NAME;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/federation/Bridge.java b/java/broker/src/main/java/org/apache/qpid/server/federation/Bridge.java
deleted file mode 100644
index 7eb476b15a..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/federation/Bridge.java
+++ /dev/null
@@ -1,913 +0,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.
- *
- */
-package org.apache.qpid.server.federation;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.AMQStoreException;
-import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.BridgeConfig;
-import org.apache.qpid.server.configuration.BridgeConfigType;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.flow.FlowCreditManager_0_10;
-import org.apache.qpid.server.flow.WindowCreditManager;
-import org.apache.qpid.server.message.MessageMetaData_0_10;
-import org.apache.qpid.server.message.MessageTransferMessage;
-import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.queue.BaseQueue;
-import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.StoredMessage;
-import org.apache.qpid.server.subscription.SubscriptionFactoryImpl;
-import org.apache.qpid.server.subscription.Subscription_0_10;
-import org.apache.qpid.server.transport.ServerSession;
-import org.apache.qpid.server.txn.AutoCommitTransaction;
-import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.DeliveryProperties;
-import org.apache.qpid.transport.MessageAcceptMode;
-import org.apache.qpid.transport.MessageAcquireMode;
-import org.apache.qpid.transport.MessageCreditUnit;
-import org.apache.qpid.transport.MessageFlowMode;
-import org.apache.qpid.transport.MessageReject;
-import org.apache.qpid.transport.MessageRejectCode;
-import org.apache.qpid.transport.MessageTransfer;
-import org.apache.qpid.transport.Option;
-import org.apache.qpid.transport.RangeSet;
-import org.apache.qpid.transport.RangeSetFactory;
-import org.apache.qpid.transport.Session;
-import org.apache.qpid.transport.SessionException;
-import org.apache.qpid.transport.SessionListener;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-public class Bridge implements BridgeConfig
-{
- private static final String DURABLE = "durable";
- private static final String DYNAMIC = "dynamic";
- private static final String SRC_IS_QUEUE = "srcIsQueue";
- private static final String SRC_IS_LOCAL = "srcIsLocal";
- private static final String SOURCE = "source";
- private static final String DESTINATION = "destination";
- private static final String KEY = "key";
- private static final String TAG = "tag";
- private static final String EXCLUDES = "excludes";
- private final boolean _durable;
- private final boolean _dynamic;
- private final boolean _queueBridge;
- private final boolean _localSource;
- private final String _source;
- private final String _destination;
- private final String _key;
- private final String _tag;
- private final String _excludes;
- private final BrokerLink _link;
- private UUID _qmfId;
- private long _createTime = System.currentTimeMillis();
-
- private Session _session;
-
- private BridgeImpl _delegate;
-
- private final int _bridgeNo;
- private AutoCommitTransaction _transaction;
-
- public Bridge(final BrokerLink brokerLink,
- final int bridgeNo,
- final boolean durable,
- final boolean dynamic,
- final boolean srcIsQueue,
- final boolean srcIsLocal,
- final String src,
- final String dest,
- final String key,
- final String tag,
- final String excludes)
- {
- _link = brokerLink;
- _bridgeNo = bridgeNo;
- _durable = durable;
- _dynamic = dynamic;
- _queueBridge = srcIsQueue;
- _localSource = srcIsLocal;
- _source = src;
- _destination = dest;
- _key = key;
- _tag = tag;
- _excludes = excludes;
- _qmfId = durable ? brokerLink.getConfigStore().createPersistentId() : brokerLink.getConfigStore().createId();
-
- _transaction = new AutoCommitTransaction(getVirtualHost().getMessageStore());
-
- if(durable)
- {
- try
- {
- brokerLink.getVirtualHost().getMessageStore().createBridge(this);
- }
- catch (AMQStoreException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- createDelegate();
- }
-
- private void createDelegate()
- {
- if(_dynamic)
- {
- if(_localSource)
- {
- // TODO
- }
- else
- {
- if(_queueBridge)
- {
- // TODO
- }
- else
- {
- _delegate = new DynamicExchangeBridge();
- }
- }
- }
- else
- {
- if(_localSource)
- {
- if(_queueBridge)
- {
- _delegate = new StaticQueuePushBridge();
- }
- else
- {
- _delegate = new StaticExchangePushBridge();
- }
- }
- else
- {
- if(_queueBridge)
- {
- _delegate = new StaticQueuePullBridge();
- }
- else
- {
- _delegate = new StaticExchangePullBridge();
- }
- }
- }
- }
-
- public Bridge(final BrokerLink brokerLink,
- final int bridgeNo,
- final UUID id,
- final long createTime,
- final Map<String, String> arguments)
- {
- _link = brokerLink;
- _bridgeNo = bridgeNo;
- _qmfId = id;
- brokerLink.getConfigStore().persistentIdInUse(id);
- _createTime = createTime;
-
- _durable = Boolean.valueOf(arguments.get(DURABLE));
- _dynamic = Boolean.valueOf(arguments.get(DYNAMIC));
- _queueBridge = Boolean.valueOf(arguments.get(SRC_IS_QUEUE));
- _localSource = Boolean.valueOf(arguments.get(SRC_IS_LOCAL));
- _source = arguments.get(SOURCE);
- _destination = arguments.get(DESTINATION);
- _key = arguments.get(KEY);
- _tag = arguments.get(TAG);
- _excludes = arguments.get(EXCLUDES);
-
- //TODO.
- _transaction = new AutoCommitTransaction(getVirtualHost().getMessageStore());
-
-
- if(_durable)
- {
- try
- {
- brokerLink.getVirtualHost().getMessageStore().createBridge(this);
- }
- catch (AMQStoreException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- createDelegate();
- }
-
-
- public Map<String,String> getArguments()
- {
- Map<String,String> arguments = new HashMap<String, String>();
-
- arguments.put(DURABLE, String.valueOf(_durable));
- arguments.put(DYNAMIC, String.valueOf(_dynamic));
- arguments.put(SRC_IS_QUEUE, String.valueOf(_queueBridge));
- arguments.put(SRC_IS_LOCAL, String.valueOf(_localSource));
- arguments.put(SOURCE, _source);
- arguments.put(DESTINATION, _destination);
- arguments.put(KEY, _key);
- arguments.put(TAG, _tag);
- arguments.put(EXCLUDES, _excludes);
-
- return Collections.unmodifiableMap(arguments);
- }
-
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public BridgeConfigType getConfigType()
- {
- return BridgeConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return getLink();
- }
-
- public boolean isDurable()
- {
- return _durable;
- }
-
- public boolean isDynamic()
- {
- return _dynamic;
- }
-
- public boolean isQueueBridge()
- {
- return _queueBridge;
- }
-
- public boolean isLocalSource()
- {
- return _localSource;
- }
-
- public String getSource()
- {
- return _source;
- }
-
- public String getDestination()
- {
- return _destination;
- }
-
- public String getKey()
- {
- return _key;
- }
-
- public String getTag()
- {
- return _tag;
- }
-
- public String getExcludes()
- {
- return _excludes;
- }
-
- public BrokerLink getLink()
- {
- return _link;
- }
-
- public Integer getChannelId()
- {
- return (_session == null) ? 0 : _session.getChannel();
- }
-
- public int getAckBatching()
- {
- return 0;
- }
-
- public long getCreateTime()
- {
- return _createTime;
- }
-
- @Override
- public boolean equals(final Object o)
- {
- if (this == o)
- {
- return true;
- }
- if (o == null || getClass() != o.getClass())
- {
- return false;
- }
-
- final Bridge bridge = (Bridge) o;
-
- if (_durable != bridge._durable)
- {
- return false;
- }
- if (_dynamic != bridge._dynamic)
- {
- return false;
- }
- if (_localSource != bridge._localSource)
- {
- return false;
- }
- if (_queueBridge != bridge._queueBridge)
- {
- return false;
- }
- if (_destination != null ? !_destination.equals(bridge._destination) : bridge._destination != null)
- {
- return false;
- }
- if (_excludes != null ? !_excludes.equals(bridge._excludes) : bridge._excludes != null)
- {
- return false;
- }
- if (_key != null ? !_key.equals(bridge._key) : bridge._key != null)
- {
- return false;
- }
- if (_source != null ? !_source.equals(bridge._source) : bridge._source != null)
- {
- return false;
- }
- if (_tag != null ? !_tag.equals(bridge._tag) : bridge._tag != null)
- {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = (_durable ? 1 : 0);
- result = 31 * result + (_dynamic ? 1 : 0);
- result = 31 * result + (_queueBridge ? 1 : 0);
- result = 31 * result + (_localSource ? 1 : 0);
- result = 31 * result + (_source != null ? _source.hashCode() : 0);
- result = 31 * result + (_destination != null ? _destination.hashCode() : 0);
- result = 31 * result + (_key != null ? _key.hashCode() : 0);
- result = 31 * result + (_tag != null ? _tag.hashCode() : 0);
- result = 31 * result + (_excludes != null ? _excludes.hashCode() : 0);
- return result;
- }
-
- public void setSession(final Session session)
- {
- _session = session;
- _delegate.setSession(session);
- }
-
- private long getMessageWindowSize()
- {
- return 10l;
- }
-
-
- VirtualHost getVirtualHost()
- {
- return _link.getVirtualHost();
- }
-
- public void close()
- {
- // TODO
- _delegate.close();
- _session = null;
- }
-
-
-
- private interface BridgeImpl
- {
- void setSession(Session session);
-
- void close();
- }
-
- private abstract class AbstractPullBridge implements BridgeImpl, SessionListener
- {
- public final void setSession(final Session session)
- {
- session.setSessionListener(this);
- onSession();
-
- }
-
- abstract void onSession();
-
-
-
- public void message(final Session ssn, final MessageTransfer xfr)
- {
- ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry();
-
- Exchange exchange = exchangeRegistry.getExchange(_destination);
-
- // TODO - deal with exchange not existing
-
- DeliveryProperties delvProps = null;
- if(xfr.getHeader() != null && (delvProps = xfr.getHeader().getDeliveryProperties()) != null && delvProps.hasTtl() &&
- !delvProps.hasExpiration())
- {
- delvProps.setExpiration(System.currentTimeMillis() + delvProps.getTtl());
- }
-
- MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(xfr);
- final MessageStore store = getVirtualHost().getMessageStore();
- StoredMessage<MessageMetaData_0_10> storeMessage = store.addMessage(messageMetaData);
- storeMessage.addContent(0,xfr.getBody());
- storeMessage.flushToStore();
- MessageTransferMessage message = new MessageTransferMessage(storeMessage, ((ServerSession)_session).getReference());
-
- List<? extends BaseQueue> queues = exchange.route(message);
-
-
-
- if(queues != null && queues.size() != 0)
- {
- enqueue(message, queues);
- }
- else
- {
- if(delvProps == null || !delvProps.hasDiscardUnroutable() || !delvProps.getDiscardUnroutable())
- {
- if(xfr.getAcceptMode() == MessageAcceptMode.EXPLICIT)
- {
- RangeSet rejects = RangeSetFactory.createRangeSet();
- rejects.add(xfr.getId());
- MessageReject reject = new MessageReject(rejects, MessageRejectCode.UNROUTABLE, "Unroutable");
- ssn.invoke(reject);
- }
- else
- {
- Exchange alternate = exchange.getAlternateExchange();
- if(alternate != null)
- {
- queues = alternate.route(message);
- if(queues != null && queues.size() != 0)
- {
- enqueue(message, queues);
- }
- else
- {
- //TODO - log the message discard
- }
- }
- else
- {
- //TODO - log the message discard
- }
-
-
- }
- }
-
-
- }
-
- ssn.processed(xfr);
-
- }
-
-
- private void enqueue(final ServerMessage message, final List<? extends BaseQueue> queues)
- {
- _transaction.enqueue(queues,message, new ServerTransaction.Action()
- {
-
- private BaseQueue[] _queues = queues.toArray(new BaseQueue[queues.size()]);
-
- public void postCommit()
- {
- for(int i = 0; i < _queues.length; i++)
- {
- try
- {
- _queues[i].enqueue(message);
- }
- catch (AMQException e)
- {
- // TODO
-
- throw new RuntimeException(e);
- }
- }
- }
-
- public void onRollback()
- {
- // NO-OP
- }
- }, 0L);
- }
-
- public void exception(final Session session, final SessionException exception)
- {
- // TODO - Handle exceptions
- }
-
- public void closed(final Session session)
- {
- // TODO - handle close
- }
-
- public void opened(final Session session)
- {
- // this method never called
- }
-
- public void resumed(final Session session)
- {
- // will never resume these sessions
- }
-
-
-
- }
-
- private final class StaticExchangePullBridge extends AbstractPullBridge
- {
- private final String _tmpQueueName = "bridge_queue_" + _bridgeNo + "_" + _link.getFederationTag();;
-
- public void onSession()
- {
-
- final HashMap<String, Object> options = new HashMap<String, Object>();
- options.put("qpid.trace.exclude", _link.getFederationTag());
- options.put("qpid.trace.id",_link.getRemoteFederationTag());
- _session.queueDeclare(_tmpQueueName,null, options, Option.AUTO_DELETE, Option.EXCLUSIVE);
- _session.sync();
- // todo check exception
- final Map<String,Object> bindingArgs = new HashMap<String,Object>();
- _session.exchangeBind(_tmpQueueName, _source, _key, bindingArgs);
- _session.sync();
- // todo check exception
-
- final Map<String,Object> subscribeOptions = Collections.EMPTY_MAP;
- final String subName = String.valueOf(_bridgeNo);
- _session.messageSubscribe(_tmpQueueName,
- subName,MessageAcceptMode.NONE,MessageAcquireMode.PRE_ACQUIRED,null,0l, subscribeOptions);
- _session.sync();
- // todo check exception
-
- _session.messageSetFlowMode(subName,MessageFlowMode.WINDOW);
- _session.messageFlow(subName, MessageCreditUnit.MESSAGE, getMessageWindowSize());
- _session.messageFlow(subName, MessageCreditUnit.BYTE, 0xFFFFFFFF);
-
- }
-
- public void close()
- {
- // TODO
- }
- }
-
- private final class StaticQueuePullBridge extends AbstractPullBridge
- {
-
- public void onSession()
- {
-
- final Map<String,Object> subscribeOptions = Collections.EMPTY_MAP;
- final String subName = String.valueOf(_bridgeNo);
- _session.messageSubscribe(_source,
- subName,MessageAcceptMode.NONE,MessageAcquireMode.PRE_ACQUIRED,null,0l, subscribeOptions);
- _session.sync();
- // todo check exception
-
- _session.messageSetFlowMode(subName,MessageFlowMode.WINDOW);
- _session.messageFlow(subName, MessageCreditUnit.MESSAGE, getMessageWindowSize());
- _session.messageFlow(subName, MessageCreditUnit.BYTE, 0xFFFFFFFF);
-
- }
-
- public void close()
- {
- // TODO
- }
- }
-
- private final class DynamicExchangeBridge extends AbstractPullBridge implements Exchange.BindingListener
- {
- private final String _tmpQueueName = "bridge_queue_" + _bridgeNo + "_" + _link.getFederationTag();
-
- private final ConcurrentMap<Binding,Binding> _bindings = new ConcurrentHashMap<Binding,Binding>();
-
-
- void onSession()
- {
-
-
- final HashMap<String, Object> options = new HashMap<String, Object>();
- options.put("qpid.trace.exclude", _link.getFederationTag());
- options.put("qpid.trace.id",_link.getRemoteFederationTag());
- _session.queueDeclare(_tmpQueueName,null, options, Option.AUTO_DELETE, Option.EXCLUSIVE);
- _session.sync();
- // todo - check exception
-
- final Map<String,Object> subscribeOptions = Collections.EMPTY_MAP;
- final String subName = String.valueOf(_bridgeNo);
- _session.messageSubscribe(_tmpQueueName,
- subName,MessageAcceptMode.NONE,MessageAcquireMode.PRE_ACQUIRED,null,0l, subscribeOptions);
- _session.sync();
- // todo check exception
- _session.messageSetFlowMode(subName,MessageFlowMode.WINDOW);
- _session.messageFlow(subName, MessageCreditUnit.MESSAGE, getMessageWindowSize());
- _session.messageFlow(subName, MessageCreditUnit.BYTE, 0xFFFFFFFF);
- _session.sync();
- // todo check exception
-
-
- ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry();
-
- Exchange exchange = exchangeRegistry.getExchange(_destination);
-
- // TODO - check null
-
- exchange.addBindingListener(this);
-
- Collection<Binding> bindings = exchange.getBindings();
- for(Binding binding : bindings)
- {
- propogateBinding(binding);
- }
-
- }
-
- private void propogateBinding(final Binding binding)
- {
- if(_bindings.putIfAbsent(binding,binding)== null)
- {
- Map<String,Object> arguments = new HashMap<String,Object>(binding.getArguments());
-
- if(arguments.get("qpid.fed.origin") == null)
- {
- arguments.put("qpid.fed.op","");
- arguments.put("qpid.fed.origin",_link.getFederationTag());
- arguments.put("qpid.fed.tags",_link.getFederationTag());
- }
- else
- {
- String tags = (String) arguments.get("qpid.fed.tags");
- if(tags == null)
- {
- tags = _link.getFederationTag();
- }
- else
- {
- if(Arrays.asList(tags.split(",")).contains(_link.getFederationTag()))
- {
- return;
- }
- tags += "," + _link.getFederationTag();
- }
- arguments.put("qpid.fed.tags", tags);
- }
-
- _session.exchangeBind(_tmpQueueName, _source, binding.getBindingKey(), arguments);
- _session.sync();
- // TODO - check exception?
-
- }
- }
-
- private void propogateBindingRemoval(final Binding binding)
- {
- if(_bindings.remove(binding) != null)
- {
- // TODO - this is wrong!!!!
- _session.exchangeUnbind(_tmpQueueName, _source, binding.getBindingKey());
- }
- }
-
-
- public void bindingAdded(final Exchange exchange, final Binding binding)
- {
- propogateBinding(binding);
- }
-
- public void bindingRemoved(final Exchange exchange, final Binding binding)
- {
- propogateBindingRemoval(binding);
- }
-
- public void close()
- {
- // TODO
- }
- }
-
- private class StaticExchangePushBridge implements BridgeImpl, SessionListener
- {
- private final String _tmpQueueName = "bridge_queue_" + _bridgeNo + "_" + _link.getFederationTag();
- private AMQQueue _queue;
-
- public void setSession(final Session session)
- {
- assert session instanceof ServerSession;
-
- session.setSessionListener(this);
-
- ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry();
-
- Exchange exchange = exchangeRegistry.getExchange(_source);
-
- // TODO - Check null
-
- final HashMap<String, Object> options = new HashMap<String, Object>();
- options.put("qpid.trace.exclude", _link.getFederationTag());
- options.put("qpid.trace.id",_link.getRemoteFederationTag());
-
- try
- {
- _queue = AMQQueueFactory.createAMQQueueImpl(null,
- _tmpQueueName,
- isDurable(),
- _link.getFederationTag(),
- false,
- false,
- getVirtualHost(), options);
- }
- catch (AMQException e)
- {
- // TODO
- throw new RuntimeException(e);
- }
-
- FlowCreditManager_0_10 creditManager = new WindowCreditManager(0xFFFFFFFF,getMessageWindowSize());
-
- //TODO Handle the passing of non-null Filters and Arguments here
-
- Subscription_0_10 sub = SubscriptionFactoryImpl.INSTANCE.createSubscription((ServerSession)session,
- _destination,
- MessageAcceptMode.NONE,
- MessageAcquireMode.PRE_ACQUIRED,
- MessageFlowMode.WINDOW,
- creditManager, null,null);
-
- ((ServerSession)session).register(_destination, sub);
-
- try
- {
- _queue.registerSubscription(sub, true);
- getVirtualHost().getBindingFactory().addBinding(_key, _queue, exchange, Collections.<String, Object>emptyMap());
- }
- catch (AMQException e)
- {
- // TODO
- throw new RuntimeException(e);
- }
- }
-
- public void close()
- {
- // TODO
- }
-
- public void opened(final Session session)
- {
- // this method never called
- }
-
- public void resumed(final Session session)
- {
- // this session will never be resumed
- }
-
- public void message(final Session ssn, final MessageTransfer xfr)
- {
- // messages should not be sent ... should probably log error
- }
-
- public void exception(final Session session, final SessionException exception)
- {
- // TODO
- }
-
- public void closed(final Session session)
- {
- // TODO
- }
- }
-
- private class StaticQueuePushBridge implements BridgeImpl, SessionListener
- {
- private AMQQueue _queue;
-
- public void setSession(final Session session)
- {
- assert session instanceof ServerSession;
-
- session.setSessionListener(this);
-
- QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry();
-
- _queue = queueRegistry.getQueue(_source);
-
- // TODO - null check
-
- FlowCreditManager_0_10 creditManager = new WindowCreditManager(0xFFFFFFFF,getMessageWindowSize());
-
- //TODO Handle the passing of non-null Filters and Arguments here
-
- Subscription_0_10 sub = SubscriptionFactoryImpl.INSTANCE.createSubscription((ServerSession)session,
- _destination,
- MessageAcceptMode.NONE,
- MessageAcquireMode.PRE_ACQUIRED,
- MessageFlowMode.WINDOW,
- creditManager, null,null);
-
- ((ServerSession)session).register(_destination, sub);
-
- try
- {
- _queue.registerSubscription(sub, false);
- }
- catch (AMQException e)
- {
- // TODO
- throw new RuntimeException(e);
- }
-
- }
-
- public void close()
- {
- // TODO
- }
-
- public void opened(final Session session)
- {
- // never called
- }
-
- public void resumed(final Session session)
- {
- // session will not resume
- }
-
- public void message(final Session ssn, final MessageTransfer xfr)
- {
- // should never be called ... should probably log error
- }
-
- public void exception(final Session session, final SessionException exception)
- {
- // TODO
- }
-
- public void closed(final Session session)
- {
- // TODO
- }
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/federation/BrokerLink.java b/java/broker/src/main/java/org/apache/qpid/server/federation/BrokerLink.java
deleted file mode 100644
index 1ef57c53cb..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/federation/BrokerLink.java
+++ /dev/null
@@ -1,692 +0,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.
- *
- */
-package org.apache.qpid.server.federation;
-
-import org.apache.qpid.AMQStoreException;
-import org.apache.qpid.common.ServerPropertyNames;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.ConnectionConfig;
-import org.apache.qpid.server.configuration.ConnectionConfigType;
-import org.apache.qpid.server.configuration.LinkConfig;
-import org.apache.qpid.server.configuration.LinkConfigType;
-import org.apache.qpid.server.transport.ServerSession;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.transport.Binary;
-import org.apache.qpid.transport.ClientDelegate;
-import org.apache.qpid.transport.Connection;
-import org.apache.qpid.transport.ConnectionException;
-import org.apache.qpid.transport.ConnectionListener;
-import org.apache.qpid.transport.ConnectionSettings;
-import org.apache.qpid.transport.Session;
-import org.apache.qpid.transport.SessionDelegate;
-import org.apache.qpid.transport.TransportException;
-
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.sasl.Sasl;
-import javax.security.sasl.SaslClient;
-import javax.security.sasl.SaslException;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
-
-public class BrokerLink implements LinkConfig, ConnectionListener
-{
-
- private static final int CORE_POOL_SIZE = 4;
-
- private static final ScheduledThreadPoolExecutor _threadPool =
- new ScheduledThreadPoolExecutor(CORE_POOL_SIZE);
- private static final String TRANSPORT = "transport";
- private static final String HOST = "host";
- private static final String PORT = "port";
- private static final String REMOTE_VHOST = "remoteVhost";
- private static final String DURABLE = "durable";
- private static final String AUTH_MECHANISM = "authMechanism";
- private static final String USERNAME = "username";
- private static final String PASSWORD = "password";
-
-
- private final String _transport;
- private final String _host;
- private final int _port;
- private final String _remoteVhost;
- private final boolean _durable;
- private final String _authMechanism;
- private final String _username;
- private final String _password;
- private final VirtualHost _virtualHost;
- private UUID _qmfId;
- private AtomicBoolean _closing = new AtomicBoolean();
- private final long _createTime;
- private Connection _qpidConnection;
- private AtomicReference<Thread> _executor = new AtomicReference<Thread>();
- private AtomicInteger _bridgeId = new AtomicInteger();
-
- private final ConcurrentHashMap<Bridge,Bridge> _bridges = new ConcurrentHashMap<Bridge,Bridge>();
- private final ConcurrentHashMap<Bridge,Bridge> _activeBridges = new ConcurrentHashMap<Bridge,Bridge>();
- private final ConcurrentLinkedQueue<Bridge> _pendingBridges = new ConcurrentLinkedQueue<Bridge>();
- private String _remoteFederationTag;
-
- private ConnectionConfig _connectionConfig;
- private ConnectionException _exception;
- private String _lastErrorMessage;
- private int _retryDelay = 1;
- private final Runnable _makeConnectionTask = new Runnable()
- {
- public void run()
- {
- doMakeConnection();
- }
- };
-
-
-
-
- public static enum State
- {
- OPERATIONAL,
- DOWN,
- ESTABLISHING,
- DELETED
- }
-
-
- private volatile State _state = State.DOWN;
-
- private static final AtomicReferenceFieldUpdater<BrokerLink, State> _stateUpdater =
- AtomicReferenceFieldUpdater.newUpdater(BrokerLink.class, State.class, "_state");
-
- private class ConnectionConfigAdapter implements ConnectionConfig
- {
- private long _adapterCreateTime = System.currentTimeMillis();
- private UUID _qmfId = BrokerLink.this.getConfigStore().createId();
-
- public VirtualHost getVirtualHost()
- {
- return BrokerLink.this.getVirtualHost();
- }
-
- public String getAddress()
- {
- return _host+":"+_port;
- }
-
- public Boolean isIncoming()
- {
- return false;
- }
-
- public Boolean isSystemConnection()
- {
- return true;
- }
-
- public Boolean isFederationLink()
- {
- return true;
- }
-
- public String getAuthId()
- {
- return _username;
- }
-
- public String getRemoteProcessName()
- {
- return null;
- }
-
- public Integer getRemotePID()
- {
- return null;
- }
-
- public Integer getRemoteParentPID()
- {
- return null;
- }
-
- public ConfigStore getConfigStore()
- {
- return getVirtualHost().getConfigStore();
- }
-
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public ConnectionConfigType getConfigType()
- {
- return ConnectionConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return getVirtualHost();
- }
-
- public boolean isDurable()
- {
- return false;
- }
-
- public long getCreateTime()
- {
- return _adapterCreateTime;
- }
-
- public Boolean isShadow()
- {
- return false;
- }
-
- public void mgmtClose()
- {
- _connectionConfig.mgmtClose();
- }
- }
-
- private class SessionFactory implements Connection.SessionFactory
- {
-
- public Session newSession(final Connection conn, final Binary name, final long expiry)
- {
- return new ServerSession(conn, new SessionDelegate(), name, expiry, _connectionConfig);
- }
- };
-
- public BrokerLink(final VirtualHost virtualHost, UUID qmfId, long createTime, Map<String, String> arguments)
- {
- _virtualHost = virtualHost;
- _qmfId = qmfId;
- virtualHost.getConfigStore().persistentIdInUse(qmfId);
- _createTime = createTime;
- _transport = arguments.get(TRANSPORT);
-
- _host = arguments.get(HOST);
- _port = Integer.parseInt(arguments.get(PORT));
- _remoteVhost = arguments.get(REMOTE_VHOST);
- _durable = Boolean.parseBoolean(arguments.get(DURABLE));
- _authMechanism = arguments.get("authMechanism");
- _username = arguments.get("username");
- _password = arguments.get("password");
-
- if(_durable)
- {
- try
- {
- _virtualHost.getMessageStore().createBrokerLink(this);
- }
- catch (AMQStoreException e)
- {
- throw new RuntimeException(e);
- }
- }
-
-
- _qpidConnection = new Connection();
- _connectionConfig = new ConnectionConfigAdapter();
- _qpidConnection.addConnectionListener(this);
-
-
- makeConnection();
-
- }
-
-
- public BrokerLink(final VirtualHost virtualHost,
- final String transport,
- final String host,
- final int port,
- final String remoteVhost,
- final boolean durable,
- final String authMechanism,
- final String username,
- final String password)
- {
- _virtualHost = virtualHost;
- _transport = transport;
- _createTime = System.currentTimeMillis();
- _host = host;
- _port = port;
- _remoteVhost = remoteVhost;
- _durable = durable;
- _authMechanism = authMechanism;
- _username = username;
- _password = password;
- _qmfId = durable ? virtualHost.getConfigStore().createPersistentId() : virtualHost.getConfigStore().createId();
-
- if(durable)
- {
- try
- {
- _virtualHost.getMessageStore().createBrokerLink(this);
- }
- catch (AMQStoreException e)
- {
- throw new RuntimeException(e);
- }
- }
- _qpidConnection = new Connection();
- _connectionConfig = new ConnectionConfigAdapter();
- _qpidConnection.addConnectionListener(this);
-
- makeConnection();
- }
-
- public Map<String,String> getArguments()
- {
- Map<String,String> arguments = new HashMap<String, String>();
-
- arguments.put(TRANSPORT, _transport);
- arguments.put(HOST, _host);
- arguments.put(PORT, String.valueOf(_port));
- arguments.put(REMOTE_VHOST, _remoteVhost);
- arguments.put(DURABLE, String.valueOf(_durable));
- arguments.put(AUTH_MECHANISM, _authMechanism);
- arguments.put(USERNAME, _username);
- arguments.put(PASSWORD, _password);
-
- return Collections.unmodifiableMap(arguments);
- }
-
- private final boolean updateState(State expected, State newState)
- {
- return _stateUpdater.compareAndSet(this,expected,newState);
- }
-
- private void makeConnection()
- {
- _threadPool.execute(_makeConnectionTask);
- }
-
-
-
- private void doMakeConnection()
- {
- if(updateState(State.DOWN, State.ESTABLISHING))
- {
- try
- {
- _qpidConnection.setConnectionDelegate(new ClientDelegate(new ConnectionSettings())
- {
- protected SaslClient createSaslClient(List<Object> brokerMechs) throws ConnectionException,
- SaslException
- {
- Map<String,Object> saslProps = new HashMap<String,Object>();
-
-
- CallbackHandler cbh = new CallbackHandler()
- {
- public void handle(final Callback[] callbacks)
- throws IOException, UnsupportedCallbackException
- {
- for (int i = 0; i < callbacks.length; i++)
- {
- Callback cb = callbacks[i];
- if (cb instanceof NameCallback)
- {
- ((NameCallback)cb).setName(_username);
- }
- else if (cb instanceof PasswordCallback)
- {
- ((PasswordCallback)cb).setPassword(_password.toCharArray());
- }
- else
- {
- throw new UnsupportedCallbackException(cb);
- }
- }
-
- }
- };
- final SaslClient sc = Sasl.createSaslClient(new String[] {"PLAIN"}, null,
- getConnectionSettings().getSaslProtocol(),
- getConnectionSettings().getSaslServerName(),
- saslProps, cbh);
-
- return sc;
- }});
-
- _qpidConnection.connect(_host, _port, _remoteVhost, _username, _password, "ssl".equals(_transport), _authMechanism);
-
- final Map<String,Object> serverProps = _qpidConnection.getServerProperties();
-
- _remoteFederationTag = (String) serverProps.get(ServerPropertyNames.FEDERATION_TAG);
- if(_remoteFederationTag == null)
- {
- _remoteFederationTag = UUID.fromString(_transport+":"+_host+":"+_port).toString();
- }
- _qpidConnection.setSessionFactory(new SessionFactory());
-
- updateState(State.ESTABLISHING, State.OPERATIONAL);
-
- _retryDelay = 1;
-
- for(Bridge bridge : _bridges.values())
- {
- if(_state != State.OPERATIONAL)
- {
- break;
- }
- addBridge(bridge);
- }
-
-
- }
- catch (TransportException e)
- {
- _lastErrorMessage = e.getMessage();
- if(_retryDelay < 60)
- {
- _retryDelay <<= 1;
- }
-
- updateState(State.ESTABLISHING, State.DOWN);
- _activeBridges.clear();
- scheduleConnectionRetry();
- }
- }
- }
-
- private void scheduleConnectionRetry()
- {
- if(_state != State.DELETED)
- {
- _threadPool.schedule(_makeConnectionTask, _retryDelay, TimeUnit.SECONDS);
- }
- }
-
- public VirtualHost getVirtualHost()
- {
- return _virtualHost;
- }
-
- public String getTransport()
- {
- return _transport;
- }
-
- public String getHost()
- {
- return _host;
- }
-
- public int getPort()
- {
- return _port;
- }
-
- public String getRemoteVhost()
- {
- return _remoteVhost;
- }
-
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public LinkConfigType getConfigType()
- {
- return LinkConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return getVirtualHost();
- }
-
- public boolean isDurable()
- {
- return _durable;
- }
-
- public String getAuthMechanism()
- {
- return _authMechanism;
- }
-
- public String getUsername()
- {
- return _username;
- }
-
- public String getPassword()
- {
- return _password;
- }
-
- @Override
- public boolean equals(final Object o)
- {
- if (this == o)
- {
- return true;
- }
- if (o == null || getClass() != o.getClass())
- {
- return false;
- }
-
- final BrokerLink that = (BrokerLink) o;
-
- if (_port != that._port)
- {
- return false;
- }
- if (_host != null ? !_host.equals(that._host) : that._host != null)
- {
- return false;
- }
- if (_remoteVhost != null ? !_remoteVhost.equals(that._remoteVhost) : that._remoteVhost != null)
- {
- return false;
- }
- if (_transport != null ? !_transport.equals(that._transport) : that._transport != null)
- {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = _transport != null ? _transport.hashCode() : 0;
- result = 31 * result + (_host != null ? _host.hashCode() : 0);
- result = 31 * result + _port;
- result = 31 * result + (_remoteVhost != null ? _remoteVhost.hashCode() : 0);
- return result;
- }
-
- public void close()
- {
- if(_closing.compareAndSet(false,true))
- {
- // TODO - close connection
- for(Bridge bridge : _bridges.values())
- {
- bridge.close();
- }
- _bridges.clear();
-
- _virtualHost.removeBrokerConnection(this);
- }
- }
-
- public long getCreateTime()
- {
- return _createTime;
- }
-
- public void createBridge(final boolean durable,
- final boolean dynamic,
- final boolean srcIsQueue,
- final boolean srcIsLocal,
- final String src,
- final String dest,
- final String key,
- final String tag,
- final String excludes)
- {
- if(!_closing.get())
- {
- Bridge bridge = new Bridge(this, _bridgeId.incrementAndGet(), durable,dynamic,srcIsQueue,srcIsLocal,src,dest,key,tag,excludes);
- if(_bridges.putIfAbsent(bridge, bridge) == null)
- {
-
- addBridge(bridge);
- }
- }
-
-
- }
-
- public void createBridge(final UUID id, final long createTime, final Map<String, String> arguments)
- {
- if(!_closing.get())
- {
- Bridge bridge = new Bridge(this, _bridgeId.incrementAndGet(), id, createTime, arguments);
- if(_bridges.putIfAbsent(bridge, bridge) == null)
- {
-
- addBridge(bridge);
- }
- }
- }
-
-
- private void addBridge(final Bridge bridge)
- {
- getConfigStore().addConfiguredObject(bridge);
-
- if(_state == State.OPERATIONAL && (_activeBridges.putIfAbsent(bridge,bridge) == null))
- {
-
-
- Session session = _qpidConnection.createSession("Bridge("
- + (bridge.isDurable() ? "durable" : "transient")
- + "," + (bridge.isDynamic() ? "dynamic" : "static")
- + "," + (bridge.isQueueBridge() ? "queue" : "exchange")
- + "," + (bridge.isLocalSource() ? "local-src" : "remote-src")
- + ",[Source: '" + bridge.getSource() + "']"
- + ",[Destination: '" + bridge.getDestination() + "']"
- + ",[Key: '" + bridge.getKey() + "']"
- + ",[Tag: '" + bridge.getTag() + "']"
- + ".[Excludes: '" + bridge.getExcludes() + "'])");
- bridge.setSession(session);
-
-
- if(_closing.get())
- {
- bridge.close();
- }
- }
-
- }
-
- public void opened(final Connection connection)
- {
- // this method not called
- }
-
- public void exception(final Connection connection, final ConnectionException exception)
- {
- _exception = exception;
- _lastErrorMessage = exception.getMessage();
-
- }
-
- public void closed(final Connection connection)
- {
- State currentState = _state;
- if(currentState != State.DOWN && currentState != State.DELETED && updateState(currentState, State.DOWN))
- {
- scheduleConnectionRetry();
- }
- }
-
- public ConfigStore getConfigStore()
- {
- return getVirtualHost().getConfigStore();
- }
-
- public String getFederationTag()
- {
- return getVirtualHost().getFederationTag();
- }
-
- public String getRemoteFederationTag()
- {
- return _remoteFederationTag;
- }
-
- public String getState()
- {
- return _state.name();
- }
-
- public String getLastError()
- {
- return _lastErrorMessage;
- }
-
- @Override
- public String toString()
- {
- return "BrokerLink{" +
- " _id=" + _qmfId +
- ", _transport='" + _transport + '\'' +
- ", _host='" + _host + '\'' +
- ", _port=" + _port +
- ", _remoteVhost='" + _remoteVhost + '\'' +
- ", _durable=" + _durable +
- ", _authMechanism='" + _authMechanism + '\'' +
- ", _username='" + _username + '\'' +
- ", _password='" + _password + '\'' +
- ", _virtualHost=" + _virtualHost +
- ", _createTime=" + _createTime +
- ", _remoteFederationTag='" + _remoteFederationTag + '\'' +
- ", _state=" + _state +
- '}';
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
index b8c8411c5d..0339287e38 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java
@@ -30,11 +30,11 @@ import org.apache.qpid.framing.ConnectionSecureOkBody;
import org.apache.qpid.framing.ConnectionTuneBody;
import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
import org.apache.qpid.server.state.AMQState;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
@@ -59,9 +59,10 @@ public class ConnectionSecureOkMethodHandler implements StateAwareMethodListener
public void methodReceived(AMQStateManager stateManager, ConnectionSecureOkBody body, int channelId) throws AMQException
{
+ Broker broker = stateManager.getBroker();
AMQProtocolSession session = stateManager.getProtocolSession();
- AuthenticationManager authMgr = stateManager.getAuthenticationManager();
+ SubjectCreator subjectCreator = stateManager.getSubjectCreator();
SaslServer ss = session.getSaslServer();
if (ss == null)
@@ -69,7 +70,7 @@ public class ConnectionSecureOkMethodHandler implements StateAwareMethodListener
throw new AMQException("No SASL context set up in session");
}
MethodRegistry methodRegistry = session.getMethodRegistry();
- AuthenticationResult authResult = authMgr.authenticate(ss, body.getResponse());
+ SubjectAuthenticationResult authResult = subjectCreator.authenticate(ss, body.getResponse());
switch (authResult.getStatus())
{
case ERROR:
@@ -97,9 +98,9 @@ public class ConnectionSecureOkMethodHandler implements StateAwareMethodListener
stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
ConnectionTuneBody tuneBody =
- methodRegistry.createConnectionTuneBody(ApplicationRegistry.getInstance().getConfiguration().getMaxChannelCount(),
- ConnectionStartOkMethodHandler.getConfiguredFrameSize(),
- ApplicationRegistry.getInstance().getConfiguration().getHeartBeatDelay());
+ methodRegistry.createConnectionTuneBody((Integer)broker.getAttribute(Broker.SESSION_COUNT_LIMIT),
+ BrokerProperties.DEFAULT_FRAME_SIZE,
+ (Integer)broker.getAttribute(Broker.HEART_BEAT_DELAY));
session.writeFrame(tuneBody.generateFrame(0));
session.setAuthorizedSubject(authResult.getSubject());
disposeSaslServer(session);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
index a522b9f60f..e70fa6a37b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java
@@ -29,12 +29,11 @@ import org.apache.qpid.framing.ConnectionStartOkBody;
import org.apache.qpid.framing.ConnectionTuneBody;
import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
import org.apache.qpid.server.state.AMQState;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
@@ -60,16 +59,17 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
public void methodReceived(AMQStateManager stateManager, ConnectionStartOkBody body, int channelId) throws AMQException
{
+ Broker broker = stateManager.getBroker();
AMQProtocolSession session = stateManager.getProtocolSession();
_logger.info("SASL Mechanism selected: " + body.getMechanism());
_logger.info("Locale selected: " + body.getLocale());
- AuthenticationManager authMgr = stateManager.getAuthenticationManager();
+ SubjectCreator subjectCreator = stateManager.getSubjectCreator();
SaslServer ss = null;
try
{
- ss = authMgr.createSaslServer(String.valueOf(body.getMechanism()), session.getLocalFQDN(), session.getPeerPrincipal());
+ ss = subjectCreator.createSaslServer(String.valueOf(body.getMechanism()), session.getLocalFQDN(), session.getPeerPrincipal());
if (ss == null)
{
@@ -78,7 +78,7 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
session.setSaslServer(ss);
- final AuthenticationResult authResult = authMgr.authenticate(ss, body.getResponse());
+ final SubjectAuthenticationResult authResult = subjectCreator.authenticate(ss, body.getResponse());
//save clientProperties
session.setClientProperties(body.getClientProperties());
@@ -112,9 +112,9 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
stateManager.changeState(AMQState.CONNECTION_NOT_TUNED);
- ConnectionTuneBody tuneBody = methodRegistry.createConnectionTuneBody(ApplicationRegistry.getInstance().getConfiguration().getMaxChannelCount(),
- getConfiguredFrameSize(),
- ApplicationRegistry.getInstance().getConfiguration().getHeartBeatDelay());
+ ConnectionTuneBody tuneBody = methodRegistry.createConnectionTuneBody((Integer)broker.getAttribute(Broker.SESSION_COUNT_LIMIT),
+ BrokerProperties.DEFAULT_FRAME_SIZE,
+ (Integer)broker.getAttribute(Broker.HEART_BEAT_DELAY));
session.writeFrame(tuneBody.generateFrame(0));
break;
case CONTINUE:
@@ -148,13 +148,6 @@ public class ConnectionStartOkMethodHandler implements StateAwareMethodListener<
}
}
- static int getConfiguredFrameSize()
- {
- final ServerConfiguration config = ApplicationRegistry.getInstance().getConfiguration();
- final int framesize = config.getFrameSize();
- _logger.info("Framesize set to " + framesize);
- return framesize;
- }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java
index 8756409f64..eed0cd6020 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/ExchangeDeclareHandler.java
@@ -101,7 +101,7 @@ public class ExchangeDeclareHandler implements StateAwareMethodListener<Exchange
exchange = exchangeFactory.createExchange(exchangeName == null ? null : exchangeName.intern(),
body.getType() == null ? null : body.getType().intern(),
body.getDurable(),
- body.getPassive(), body.getTicket());
+ body.getAutoDelete(), body.getTicket());
exchangeRegistry.registerExchange(exchange);
if (exchange.isDurable())
diff --git a/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java b/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
index ae725b9ec1..194c3d6351 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/handler/QueueDeclareHandler.java
@@ -38,7 +38,6 @@ import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.state.StateAwareMethodListener;
import org.apache.qpid.server.store.DurableConfigurationStore;
@@ -59,8 +58,6 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
return _instance;
}
- private boolean autoRegister = ApplicationRegistry.getInstance().getConfiguration().getQueueAutoRegister();
-
public void methodReceived(AMQStateManager stateManager, QueueDeclareBody body, int channelId) throws AMQException
{
final AMQProtocolSession protocolConnection = stateManager.getProtocolSession();
@@ -148,13 +145,11 @@ public class QueueDeclareHandler implements StateAwareMethodListener<QueueDeclar
});
}
}
- if (autoRegister)
- {
- Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
+ Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
- virtualHost.getBindingFactory().addBinding(String.valueOf(queueName), queue, defaultExchange, Collections.EMPTY_MAP);
- _logger.info("Queue " + queueName + " bound to default exchange(" + defaultExchange.getNameShortString() + ")");
- }
+ virtualHost.getBindingFactory().addBinding(String.valueOf(queueName), queue, defaultExchange,
+ Collections.<String, Object> emptyMap());
+ _logger.info("Queue " + queueName + " bound to default exchange(" + defaultExchange.getNameShortString() + ")");
}
}
else if (queue.isExclusive() && !queue.isDurable() && (owningSession == null || owningSession.getConnectionModel() != protocolConnection))
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java b/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java
index 545f2adea2..98da9074ef 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/AbstractRootMessageLogger.java
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.server.logging;
-import org.apache.qpid.server.configuration.ServerConfiguration;
public abstract class AbstractRootMessageLogger implements RootMessageLogger
{
@@ -33,9 +32,9 @@ public abstract class AbstractRootMessageLogger implements RootMessageLogger
}
- public AbstractRootMessageLogger(ServerConfiguration config)
+ public AbstractRootMessageLogger(boolean statusUpdatesEnabled)
{
- _enabled = config.getStatusUpdatesEnabled();
+ _enabled = statusUpdatesEnabled;
}
public boolean isEnabled()
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java b/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java
index ec506ab51c..b4e9f2f333 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/Log4jMessageLogger.java
@@ -20,23 +20,18 @@
*/
package org.apache.qpid.server.logging;
-import org.apache.log4j.Level;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-
public class Log4jMessageLogger extends AbstractRootMessageLogger
{
- public static final Level LEVEL = Level.toLevel("INFO");
-
public Log4jMessageLogger()
{
super();
}
- public Log4jMessageLogger(ServerConfiguration config)
+ public Log4jMessageLogger(boolean statusUpdatesEnabled)
{
- super(config);
+ super(statusUpdatesEnabled);
}
@Override
@@ -51,7 +46,7 @@ public class Log4jMessageLogger extends AbstractRootMessageLogger
if(isEnabled())
{
Logger logger = Logger.getLogger(logHierarchy);
- return logger.isEnabledFor(LEVEL);
+ return logger.isInfoEnabled();
}
else
{
@@ -69,7 +64,6 @@ public class Log4jMessageLogger extends AbstractRootMessageLogger
public void rawMessage(String message, Throwable throwable, String logHierarchy)
{
Logger logger = Logger.getLogger(logHierarchy);
-
- logger.log(LEVEL, message, throwable);
+ logger.info(message, throwable);
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java b/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java
index a1065319d3..d053dd3fe2 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java
@@ -90,7 +90,6 @@ public class LogRecorder implements Appender, Iterable<LogRecorder.Record>
public LogRecorder()
{
-
Logger.getRootLogger().addAppender(this);
}
@@ -109,7 +108,11 @@ public class LogRecorder implements Appender, Iterable<LogRecorder.Record>
@Override
public void close()
{
- //TODO - Implement
+ }
+
+ public void closeLogRecorder()
+ {
+ Logger.getRootLogger().removeAppender(this);
}
@Override
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java
new file mode 100644
index 0000000000..8cf121b3d9
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/AbstractManagementActor.java
@@ -0,0 +1,68 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.logging.actors;
+
+import java.security.AccessController;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+
+public abstract class AbstractManagementActor extends AbstractActor
+{
+ /**
+ * Holds the principal name to display when principal subject is not available.
+ * <p>
+ * This is useful for cases when users invoke JMX operation over JConsole
+ * attached to the local JVM.
+ */
+ protected static final String UNKNOWN_PRINCIPAL = "N/A";
+
+ /** used when the principal name cannot be discovered from the Subject */
+ private final String _fallbackPrincipalName;
+
+ public AbstractManagementActor(RootMessageLogger rootLogger, String fallbackPrincipalName)
+ {
+ super(rootLogger);
+ _fallbackPrincipalName = fallbackPrincipalName;
+ }
+
+ /**
+ * Returns current {@link AuthenticatedPrincipal} name or {@link #_fallbackPrincipalName}
+ * if it can't be found.
+ */
+ protected String getPrincipalName()
+ {
+ String identity = _fallbackPrincipalName;
+
+ final Subject subject = Subject.getSubject(AccessController.getContext());
+ if (subject != null)
+ {
+ AuthenticatedPrincipal authenticatedPrincipal = AuthenticatedPrincipal.getOptionalAuthenticatedPrincipalFromSubject(subject);
+ if(authenticatedPrincipal != null)
+ {
+ identity = authenticatedPrincipal.getName();
+ }
+ }
+ return identity;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java
index 97134515a0..6251471139 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/CurrentActor.java
@@ -105,6 +105,11 @@ public class CurrentActor
{
Stack<LogActor> stack = _currentActor.get();
stack.pop();
+
+ if (stack.isEmpty())
+ {
+ _currentActor.remove();
+ }
}
/**
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.java
new file mode 100644
index 0000000000..9b445c2bd9
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/HttpManagementActor.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.server.logging.actors;
+
+import java.text.MessageFormat;
+
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.subjects.LogSubjectFormat;
+
+/**
+ * HttpManagement actor to use in {@link AbstractServlet} to log all http management operational logging.
+ *
+ * An instance is required per http Session.
+ */
+public class HttpManagementActor extends AbstractManagementActor
+{
+ private String _cachedLogString;
+ private String _lastPrincipalName;
+ private String _address;
+
+ public HttpManagementActor(RootMessageLogger rootLogger, String ip, int port)
+ {
+ super(rootLogger, UNKNOWN_PRINCIPAL);
+ _address = ip + ":" + port;
+ }
+
+ private synchronized String getAndCacheLogString()
+ {
+ String principalName = getPrincipalName();
+
+ if(!principalName.equals(_lastPrincipalName))
+ {
+ _lastPrincipalName = principalName;
+ _cachedLogString = "[" + MessageFormat.format(LogSubjectFormat.MANAGEMENT_FORMAT, principalName, _address) + "] ";
+ }
+
+ return _cachedLogString;
+ }
+
+ public String getLogMessage()
+ {
+ return getAndCacheLogString();
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java
index a2f3506502..ba5ea47fc1 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/actors/ManagementActor.java
@@ -21,58 +21,31 @@
package org.apache.qpid.server.logging.actors;
import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.subjects.LogSubjectFormat;
-import javax.management.remote.JMXPrincipal;
-import javax.security.auth.Subject;
-import java.security.AccessController;
-import java.security.Principal;
import java.text.MessageFormat;
-import java.util.Set;
/**
* Management actor to use in {@link MBeanInvocationHandlerImpl} to log all management operational logging.
*/
-public class ManagementActor extends AbstractActor
+public class ManagementActor extends AbstractManagementActor
{
- /**
- * Holds the principal name to display when principal subject is not available.
- * <p>
- * This is useful for cases when users invoke JMX operation over JConsole
- * attached to the local JVM.
- */
- private static final String UNKNOWN_PRINCIPAL = "N/A";
-
private String _lastThreadName = null;
/**
- * LOG FORMAT for the ManagementActor,
- * Uses a MessageFormat call to insert the required values according to
- * these indices:
- *
- * 0 - User ID
- * 1 - IP
- */
- public static final String MANAGEMENT_FORMAT = "mng:{0}({1})";
-
- /**
* The logString to be used for logging
*/
private String _logStringContainingPrincipal;
- /** used when the principal name cannot be discovered from the Subject */
- private final String _fallbackPrincipalName;
-
/** @param rootLogger The RootLogger to use for this Actor */
public ManagementActor(RootMessageLogger rootLogger)
{
- super(rootLogger);
- _fallbackPrincipalName = UNKNOWN_PRINCIPAL;
+ super(rootLogger, UNKNOWN_PRINCIPAL);
}
public ManagementActor(RootMessageLogger rootLogger, String principalName)
{
- super(rootLogger);
- _fallbackPrincipalName = principalName;
+ super(rootLogger, principalName);
}
private synchronized String getAndCacheLogString()
@@ -96,7 +69,7 @@ public class ManagementActor extends AbstractActor
if (split.length == 2)
{
String ip = currentName.split("-")[1];
- actor = MessageFormat.format(MANAGEMENT_FORMAT, principalName, ip);
+ actor = MessageFormat.format(LogSubjectFormat.MANAGEMENT_FORMAT, principalName, ip);
}
else
{
@@ -119,33 +92,8 @@ public class ManagementActor extends AbstractActor
return logString;
}
- /**
- * Returns current JMX principal name.
- *
- * @return principal name or null if principal can not be found
- */
- private String getPrincipalName()
- {
- String identity = _fallbackPrincipalName;
-
- // retrieve Subject from current AccessControlContext
- final Subject subject = Subject.getSubject(AccessController.getContext());
- if (subject != null)
- {
- // retrieve JMXPrincipal from Subject
- final Set<JMXPrincipal> principals = subject.getPrincipals(JMXPrincipal.class);
- if (principals != null && !principals.isEmpty())
- {
- final Principal principal = principals.iterator().next();
- identity = principal.getName();
- }
- }
- return identity;
- }
-
public String getLogMessage()
{
return getAndCacheLogString();
}
-
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingFacade.java b/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingFacade.java
deleted file mode 100644
index 931171b175..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingFacade.java
+++ /dev/null
@@ -1,579 +0,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.
- *
- */
-package org.apache.qpid.server.logging.log4j;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.apache.log4j.xml.Log4jEntityResolver;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-
-/**
- * A facade over log4j that allows both the control of the runtime logging behaviour (that is, the ability to
- * turn {@link Logger} on, off and control their {@link Level}, and the manipulation and reload
- * of the log4j configuration file.
- */
-public class LoggingFacade
-{
- private static Logger LOGGER;
- private static transient LoggingFacade _instance;
- private final String _filename;
- private final int _delay;
-
- public static LoggingFacade configure(String filename) throws LoggingFacadeException
- {
- _instance = new LoggingFacade(filename);
- return _instance;
- }
-
- public static LoggingFacade configureAndWatch(String filename, int delay) throws LoggingFacadeException
- {
- _instance = new LoggingFacade(filename, delay);
- return _instance;
- }
-
- public static LoggingFacade getCurrentInstance()
- {
- return _instance;
- }
-
- private LoggingFacade(String filename)
- {
- DOMConfigurator.configure(filename);
-
- if(LOGGER == null)
- {
- LOGGER = Logger.getLogger(LoggingFacade.class);
- }
- _filename = filename;
- _delay = 0;
- }
-
- private LoggingFacade(String filename, int delay)
- {
- DOMConfigurator.configureAndWatch(filename, delay);
-
- if(LOGGER == null)
- {
- LOGGER = Logger.getLogger(LoggingFacade.class);
- }
-
- _filename = filename;
- _delay = delay;
- }
-
- public int getLog4jLogWatchInterval()
- {
- return _delay;
- }
-
- public synchronized void reload() throws LoggingFacadeException
- {
- DOMConfigurator.configure(_filename);
- }
-
- /** The log4j XML configuration file DTD defines three possible element
- * combinations for specifying optional logger+level settings.
- * Must account for the following:
- *
- * <category name="x"> <priority value="y"/> </category> OR
- * <category name="x"> <level value="y"/> </category> OR
- * <logger name="x"> <level value="y"/> </logger>
- *
- * Noting also that the level/priority child element is optional too,
- * and not the only possible child element.
- */
- public synchronized Map<String,String> retrieveConfigFileLoggersLevels() throws LoggingFacadeException
- {
- try
- {
- Map<String,String> loggerLevelList = new HashMap<String,String>();
- LOGGER.info("Getting logger levels from log4j configuration file");
-
- Document doc = parseConfigFile(_filename);
- List<Element> categoryOrLoggerElements = buildListOfCategoryOrLoggerElements(doc);
-
- for (Element categoryOrLogger : categoryOrLoggerElements)
- {
-
- Element priorityOrLevelElement;
- try
- {
- priorityOrLevelElement = getPriorityOrLevelElement(categoryOrLogger);
- }
- catch (LoggingFacadeException lfe)
- {
- //there is no exiting priority or level to view, move onto next category/logger
- continue;
- }
-
- String categoryName = categoryOrLogger.getAttribute("name");
- String priorityOrLevelValue = priorityOrLevelElement.getAttribute("value");
- loggerLevelList.put(categoryName, priorityOrLevelValue);
- }
-
- return loggerLevelList;
- }
- catch (IOException e)
- {
- throw new LoggingFacadeException(e);
- }
- }
-
- /**
- * The log4j XML configuration file DTD defines 2 possible element
- * combinations for specifying the optional root logger level settings
- * Must account for the following:
- *
- * <root> <priority value="y"/> </root> OR
- * <root> <level value="y"/> </root>
- *
- * Noting also that the level/priority child element is optional too,
- * and not the only possible child element.
- */
- public synchronized String retrieveConfigFileRootLoggerLevel() throws LoggingFacadeException
- {
- try
- {
- Document doc = parseConfigFile(_filename);
-
- //retrieve the optional 'root' element node
- NodeList rootElements = doc.getElementsByTagName("root");
-
- if (rootElements.getLength() == 0)
- {
- //there is no root logger definition
- return "N/A";
- }
-
- Element rootElement = (Element) rootElements.item(0);
- Element levelElement = getPriorityOrLevelElement(rootElement);
-
- if(levelElement != null)
- {
- return levelElement.getAttribute("value");
- }
- else
- {
- return "N/A";
- }
- }
- catch (IOException e)
- {
- throw new LoggingFacadeException(e);
- }
- }
-
- public synchronized void setConfigFileLoggerLevel(String logger, String level) throws LoggingFacadeException
- {
- LOGGER.info("Setting level to " + level + " for logger '" + logger
- + "' in log4j xml configuration file: " + _filename);
-
- try
- {
- Document doc = parseConfigFile(_filename);
-
- List<Element> logElements = buildListOfCategoryOrLoggerElements(doc);
-
- //try to locate the specified logger/category in the elements retrieved
- Element logElement = null;
- for (Element e : logElements)
- {
- if (e.getAttribute("name").equals(logger))
- {
- logElement = e;
- break;
- }
- }
-
- if (logElement == null)
- {
- throw new LoggingFacadeException("Can't find logger " + logger);
- }
-
- Element levelElement = getPriorityOrLevelElement(logElement);
-
- //update the element with the new level/priority
- levelElement.setAttribute("value", level);
-
- //output the new file
- writeUpdatedConfigFile(_filename, doc);
- }
- catch (IOException ioe)
- {
- throw new LoggingFacadeException(ioe);
- }
- catch (TransformerConfigurationException e)
- {
- throw new LoggingFacadeException(e);
- }
- }
-
- public synchronized void setConfigFileRootLoggerLevel(String level) throws LoggingFacadeException
- {
- try
- {
- LOGGER.info("Setting level to " + level + " for the Root logger in " +
- "log4j xml configuration file: " + _filename);
-
- Document doc = parseConfigFile(_filename);
-
- //retrieve the optional 'root' element node
- NodeList rootElements = doc.getElementsByTagName("root");
-
- if (rootElements.getLength() == 0)
- {
- throw new LoggingFacadeException("Configuration contains no root element");
- }
-
- Element rootElement = (Element) rootElements.item(0);
- Element levelElement = getPriorityOrLevelElement(rootElement);
-
- //update the element with the new level/priority
- levelElement.setAttribute("value", level);
-
- //output the new file
- writeUpdatedConfigFile(_filename, doc);
- }
- catch (IOException e)
- {
- throw new LoggingFacadeException(e);
- }
- catch (TransformerConfigurationException e)
- {
- throw new LoggingFacadeException(e);
- }
- }
-
- public List<String> getAvailableLoggerLevels()
- {
- return new ArrayList<String>()
- {{
- add(Level.ALL.toString());
- add(Level.TRACE.toString());
- add(Level.DEBUG.toString());
- add(Level.INFO.toString());
- add(Level.WARN.toString());
- add(Level.ERROR.toString());
- add(Level.FATAL.toString());
- add(Level.OFF.toString());
- }};
- }
-
- public String retrieveRuntimeRootLoggerLevel()
- {
- Logger rootLogger = Logger.getRootLogger();
- return rootLogger.getLevel().toString();
- }
-
- public void setRuntimeRootLoggerLevel(String level)
- {
- Level newLevel = Level.toLevel(level);
-
- LOGGER.info("Setting RootLogger level to " + level);
-
- Logger log = Logger.getRootLogger();
- log.setLevel(newLevel);
- }
-
- public void setRuntimeLoggerLevel(String loggerName, String level) throws LoggingFacadeException
- {
- Level newLevel = level == null ? null : Level.toLevel(level);
-
- Logger targetLogger = findRuntimeLogger(loggerName);
-
- if(targetLogger == null)
- {
- throw new LoggingFacadeException("Can't find logger " + loggerName);
- }
-
- LOGGER.info("Setting level to " + newLevel + " for logger '" + targetLogger.getName() + "'");
-
- targetLogger.setLevel(newLevel);
- }
-
- public Map<String,String> retrieveRuntimeLoggersLevels()
- {
- LOGGER.info("Getting levels for currently active log4j loggers");
-
- Map<String, String> levels = new HashMap<String, String>();
- @SuppressWarnings("unchecked")
- Enumeration<Logger> loggers = LogManager.getCurrentLoggers();
-
- while (loggers.hasMoreElements())
- {
- Logger logger = loggers.nextElement();
- levels.put(logger.getName(), logger.getEffectiveLevel().toString());
- }
-
- return levels;
- }
-
- private void writeUpdatedConfigFile(String log4jConfigFileName, Document doc) throws IOException, TransformerConfigurationException
- {
- File log4jConfigFile = new File(log4jConfigFileName);
-
- if (!log4jConfigFile.canWrite())
- {
- LOGGER.warn("Specified log4j XML configuration file is not writable: " + log4jConfigFile);
- throw new IOException("Specified log4j XML configuration file is not writable");
- }
-
- Transformer transformer = null;
- transformer = TransformerFactory.newInstance().newTransformer();
-
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "log4j.dtd");
- DOMSource source = new DOMSource(doc);
-
- File tmp;
- Random r = new Random();
-
- do
- {
- tmp = new File(log4jConfigFile.getAbsolutePath() + r.nextInt() + ".tmp");
- }
- while(tmp.exists());
-
- tmp.deleteOnExit();
-
- try
- {
- StreamResult result = new StreamResult(new FileOutputStream(tmp));
- transformer.transform(source, result);
- }
- catch (TransformerException e)
- {
- LOGGER.warn("Could not transform the XML into new file: ", e);
- throw new IOException("Could not transform the XML into new file: ", e);
- }
-
- // Swap temp file in to replace existing configuration file.
- File old = new File(log4jConfigFile.getAbsoluteFile() + ".old");
- if (old.exists())
- {
- old.delete();
- }
-
- if(!log4jConfigFile.renameTo(old))
- {
- //unable to rename the existing file to the backup name
- LOGGER.error("Could not backup the existing log4j XML file");
- throw new IOException("Could not backup the existing log4j XML file");
- }
-
- if(!tmp.renameTo(log4jConfigFile))
- {
- //failed to rename the new file to the required filename
-
- if(!old.renameTo(log4jConfigFile))
- {
- //unable to return the backup to required filename
- LOGGER.error("Could not rename the new log4j configuration file into place, and unable to restore original file");
- throw new IOException("Could not rename the new log4j configuration file into place, and unable to restore original file");
- }
-
- LOGGER.error("Could not rename the new log4j configuration file into place");
- throw new IOException("Could not rename the new log4j configuration file into place");
- }
- }
-
- //method to parse the XML configuration file, validating it in the process, and returning a DOM Document of the content.
- private static Document parseConfigFile(String fileName) throws IOException
- {
- //check file was specified, exists, and is readable
- if(fileName == null)
- {
- LOGGER.warn("Provided log4j XML configuration filename is null");
- throw new IOException("Provided log4j XML configuration filename is null");
- }
-
- File configFile = new File(fileName);
-
- if (!configFile.exists())
- {
- LOGGER.warn("The log4j XML configuration file could not be found: " + fileName);
- throw new IOException("The log4j XML configuration file could not be found");
- }
- else if (!configFile.canRead())
- {
- LOGGER.warn("The log4j XML configuration file is not readable: " + fileName);
- throw new IOException("The log4j XML configuration file is not readable");
- }
-
- //parse it
- DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder;
- Document doc;
-
- ErrorHandler errHandler = new QpidLog4JSaxErrorHandler();
- try
- {
- docFactory.setValidating(true);
- docBuilder = docFactory.newDocumentBuilder();
- docBuilder.setErrorHandler(errHandler);
- docBuilder.setEntityResolver(new Log4jEntityResolver());
- doc = docBuilder.parse(fileName);
- }
- catch (ParserConfigurationException e)
- {
- LOGGER.warn("Unable to parse the log4j XML file due to possible configuration error: ", e);
- throw new IOException("Unable to parse the log4j XML file due to possible configuration error: ", e);
- }
- catch (SAXException e)
- {
- LOGGER.warn("The specified log4j XML file is invalid: ", e);
- throw new IOException("The specified log4j XML file is invalid: ", e);
- }
- catch (IOException e)
- {
- LOGGER.warn("Unable to parse the specified log4j XML file", e);
- throw new IOException("Unable to parse the specified log4j XML file: ", e);
- }
-
- return doc;
- }
-
- private Logger findRuntimeLogger(String loggerName)
- {
- Logger targetLogger = null;
- @SuppressWarnings("unchecked")
- Enumeration<Logger> loggers = LogManager.getCurrentLoggers();
- while(loggers.hasMoreElements())
- {
- targetLogger = loggers.nextElement();
- if (targetLogger.getName().equals(loggerName))
- {
- return targetLogger;
- }
- }
- return null;
- }
-
- private List<Element> buildListOfCategoryOrLoggerElements(Document doc)
- {
- //retrieve the 'category' and 'logger' element nodes
- NodeList categoryElements = doc.getElementsByTagName("category");
- NodeList loggerElements = doc.getElementsByTagName("logger");
-
- //collect them into a single elements list
- List<Element> logElements = new ArrayList<Element>();
-
- for (int i = 0; i < categoryElements.getLength(); i++)
- {
- logElements.add((Element) categoryElements.item(i));
- }
- for (int i = 0; i < loggerElements.getLength(); i++)
- {
- logElements.add((Element) loggerElements.item(i));
- }
- return logElements;
- }
-
- private Element getPriorityOrLevelElement(Element categoryOrLogger) throws LoggingFacadeException
- {
- //retrieve the optional 'priority' or 'level' sub-element value.
- //It may not be the only child node, so request by tag name.
- NodeList priorityElements = categoryOrLogger.getElementsByTagName("priority");
- NodeList levelElements = categoryOrLogger.getElementsByTagName("level");
-
- Element levelElement = null;
- if (priorityElements.getLength() != 0)
- {
- levelElement = (Element) priorityElements.item(0);
- }
- else if (levelElements.getLength() != 0)
- {
- levelElement = (Element) levelElements.item(0);
- }
- else
- {
- throw new LoggingFacadeException("Configuration " + categoryOrLogger.getNodeName()
- + " element contains neither priority nor level child");
- }
- return levelElement;
- }
-
- private static class QpidLog4JSaxErrorHandler implements ErrorHandler
- {
- public void error(SAXParseException e) throws SAXException
- {
- if(LOGGER != null)
- {
- LOGGER.warn(constructMessage("Error parsing XML file", e));
- }
- else
- {
- System.err.println(constructMessage("Error parsing XML file", e));
- }
- }
-
- public void fatalError(SAXParseException e) throws SAXException
- {
- throw new SAXException(constructMessage("Fatal error parsing XML file", e));
- }
-
- public void warning(SAXParseException e) throws SAXException
- {
- if(LOGGER != null)
- {
- LOGGER.warn(constructMessage("Warning parsing XML file", e));
- }
- else
- {
- System.err.println(constructMessage("Warning parsing XML file", e));
- }
- }
-
- private static String constructMessage(final String msg, final SAXParseException ex)
- {
- return msg + ": Line " + ex.getLineNumber()+" column " +ex.getColumnNumber() + ": " + ex.getMessage();
- }
- }
-}
-
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java b/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java
new file mode 100644
index 0000000000..6a961c8fa4
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java
@@ -0,0 +1,579 @@
+/*
+ *
+ * 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.logging.log4j;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.apache.log4j.xml.Log4jEntityResolver;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * A facade over log4j that allows both the control of the runtime logging behaviour (that is, the ability to
+ * turn {@link Logger} on, off and control their {@link Level}, and the manipulation and reload
+ * of the log4j configuration file.
+ */
+public class LoggingManagementFacade
+{
+ private static Logger LOGGER;
+ private static transient LoggingManagementFacade _instance;
+ private final String _filename;
+ private final int _delay;
+
+ public static LoggingManagementFacade configure(String filename) throws LoggingFacadeException
+ {
+ _instance = new LoggingManagementFacade(filename);
+ return _instance;
+ }
+
+ public static LoggingManagementFacade configureAndWatch(String filename, int delay) throws LoggingFacadeException
+ {
+ _instance = new LoggingManagementFacade(filename, delay);
+ return _instance;
+ }
+
+ public static LoggingManagementFacade getCurrentInstance()
+ {
+ return _instance;
+ }
+
+ private LoggingManagementFacade(String filename)
+ {
+ DOMConfigurator.configure(filename);
+
+ if(LOGGER == null)
+ {
+ LOGGER = Logger.getLogger(LoggingManagementFacade.class);
+ }
+ _filename = filename;
+ _delay = 0;
+ }
+
+ private LoggingManagementFacade(String filename, int delay)
+ {
+ DOMConfigurator.configureAndWatch(filename, delay);
+
+ if(LOGGER == null)
+ {
+ LOGGER = Logger.getLogger(LoggingManagementFacade.class);
+ }
+
+ _filename = filename;
+ _delay = delay;
+ }
+
+ public int getLog4jLogWatchInterval()
+ {
+ return _delay;
+ }
+
+ public synchronized void reload() throws LoggingFacadeException
+ {
+ DOMConfigurator.configure(_filename);
+ }
+
+ /** The log4j XML configuration file DTD defines three possible element
+ * combinations for specifying optional logger+level settings.
+ * Must account for the following:
+ *
+ * <category name="x"> <priority value="y"/> </category> OR
+ * <category name="x"> <level value="y"/> </category> OR
+ * <logger name="x"> <level value="y"/> </logger>
+ *
+ * Noting also that the level/priority child element is optional too,
+ * and not the only possible child element.
+ */
+ public synchronized Map<String,String> retrieveConfigFileLoggersLevels() throws LoggingFacadeException
+ {
+ try
+ {
+ Map<String,String> loggerLevelList = new HashMap<String,String>();
+ LOGGER.info("Getting logger levels from log4j configuration file");
+
+ Document doc = parseConfigFile(_filename);
+ List<Element> categoryOrLoggerElements = buildListOfCategoryOrLoggerElements(doc);
+
+ for (Element categoryOrLogger : categoryOrLoggerElements)
+ {
+
+ Element priorityOrLevelElement;
+ try
+ {
+ priorityOrLevelElement = getPriorityOrLevelElement(categoryOrLogger);
+ }
+ catch (LoggingFacadeException lfe)
+ {
+ //there is no exiting priority or level to view, move onto next category/logger
+ continue;
+ }
+
+ String categoryName = categoryOrLogger.getAttribute("name");
+ String priorityOrLevelValue = priorityOrLevelElement.getAttribute("value");
+ loggerLevelList.put(categoryName, priorityOrLevelValue);
+ }
+
+ return loggerLevelList;
+ }
+ catch (IOException e)
+ {
+ throw new LoggingFacadeException(e);
+ }
+ }
+
+ /**
+ * The log4j XML configuration file DTD defines 2 possible element
+ * combinations for specifying the optional root logger level settings
+ * Must account for the following:
+ *
+ * <root> <priority value="y"/> </root> OR
+ * <root> <level value="y"/> </root>
+ *
+ * Noting also that the level/priority child element is optional too,
+ * and not the only possible child element.
+ */
+ public synchronized String retrieveConfigFileRootLoggerLevel() throws LoggingFacadeException
+ {
+ try
+ {
+ Document doc = parseConfigFile(_filename);
+
+ //retrieve the optional 'root' element node
+ NodeList rootElements = doc.getElementsByTagName("root");
+
+ if (rootElements.getLength() == 0)
+ {
+ //there is no root logger definition
+ return "N/A";
+ }
+
+ Element rootElement = (Element) rootElements.item(0);
+ Element levelElement = getPriorityOrLevelElement(rootElement);
+
+ if(levelElement != null)
+ {
+ return levelElement.getAttribute("value");
+ }
+ else
+ {
+ return "N/A";
+ }
+ }
+ catch (IOException e)
+ {
+ throw new LoggingFacadeException(e);
+ }
+ }
+
+ public synchronized void setConfigFileLoggerLevel(String logger, String level) throws LoggingFacadeException
+ {
+ LOGGER.info("Setting level to " + level + " for logger '" + logger
+ + "' in log4j xml configuration file: " + _filename);
+
+ try
+ {
+ Document doc = parseConfigFile(_filename);
+
+ List<Element> logElements = buildListOfCategoryOrLoggerElements(doc);
+
+ //try to locate the specified logger/category in the elements retrieved
+ Element logElement = null;
+ for (Element e : logElements)
+ {
+ if (e.getAttribute("name").equals(logger))
+ {
+ logElement = e;
+ break;
+ }
+ }
+
+ if (logElement == null)
+ {
+ throw new LoggingFacadeException("Can't find logger " + logger);
+ }
+
+ Element levelElement = getPriorityOrLevelElement(logElement);
+
+ //update the element with the new level/priority
+ levelElement.setAttribute("value", level);
+
+ //output the new file
+ writeUpdatedConfigFile(_filename, doc);
+ }
+ catch (IOException ioe)
+ {
+ throw new LoggingFacadeException(ioe);
+ }
+ catch (TransformerConfigurationException e)
+ {
+ throw new LoggingFacadeException(e);
+ }
+ }
+
+ public synchronized void setConfigFileRootLoggerLevel(String level) throws LoggingFacadeException
+ {
+ try
+ {
+ LOGGER.info("Setting level to " + level + " for the Root logger in " +
+ "log4j xml configuration file: " + _filename);
+
+ Document doc = parseConfigFile(_filename);
+
+ //retrieve the optional 'root' element node
+ NodeList rootElements = doc.getElementsByTagName("root");
+
+ if (rootElements.getLength() == 0)
+ {
+ throw new LoggingFacadeException("Configuration contains no root element");
+ }
+
+ Element rootElement = (Element) rootElements.item(0);
+ Element levelElement = getPriorityOrLevelElement(rootElement);
+
+ //update the element with the new level/priority
+ levelElement.setAttribute("value", level);
+
+ //output the new file
+ writeUpdatedConfigFile(_filename, doc);
+ }
+ catch (IOException e)
+ {
+ throw new LoggingFacadeException(e);
+ }
+ catch (TransformerConfigurationException e)
+ {
+ throw new LoggingFacadeException(e);
+ }
+ }
+
+ public List<String> getAvailableLoggerLevels()
+ {
+ return new ArrayList<String>()
+ {{
+ add(Level.ALL.toString());
+ add(Level.TRACE.toString());
+ add(Level.DEBUG.toString());
+ add(Level.INFO.toString());
+ add(Level.WARN.toString());
+ add(Level.ERROR.toString());
+ add(Level.FATAL.toString());
+ add(Level.OFF.toString());
+ }};
+ }
+
+ public String retrieveRuntimeRootLoggerLevel()
+ {
+ Logger rootLogger = Logger.getRootLogger();
+ return rootLogger.getLevel().toString();
+ }
+
+ public void setRuntimeRootLoggerLevel(String level)
+ {
+ Level newLevel = Level.toLevel(level);
+
+ LOGGER.info("Setting RootLogger level to " + level);
+
+ Logger log = Logger.getRootLogger();
+ log.setLevel(newLevel);
+ }
+
+ public void setRuntimeLoggerLevel(String loggerName, String level) throws LoggingFacadeException
+ {
+ Level newLevel = level == null ? null : Level.toLevel(level);
+
+ Logger targetLogger = findRuntimeLogger(loggerName);
+
+ if(targetLogger == null)
+ {
+ throw new LoggingFacadeException("Can't find logger " + loggerName);
+ }
+
+ LOGGER.info("Setting level to " + newLevel + " for logger '" + targetLogger.getName() + "'");
+
+ targetLogger.setLevel(newLevel);
+ }
+
+ public Map<String,String> retrieveRuntimeLoggersLevels()
+ {
+ LOGGER.info("Getting levels for currently active log4j loggers");
+
+ Map<String, String> levels = new HashMap<String, String>();
+ @SuppressWarnings("unchecked")
+ Enumeration<Logger> loggers = LogManager.getCurrentLoggers();
+
+ while (loggers.hasMoreElements())
+ {
+ Logger logger = loggers.nextElement();
+ levels.put(logger.getName(), logger.getEffectiveLevel().toString());
+ }
+
+ return levels;
+ }
+
+ private void writeUpdatedConfigFile(String log4jConfigFileName, Document doc) throws IOException, TransformerConfigurationException
+ {
+ File log4jConfigFile = new File(log4jConfigFileName);
+
+ if (!log4jConfigFile.canWrite())
+ {
+ LOGGER.warn("Specified log4j XML configuration file is not writable: " + log4jConfigFile);
+ throw new IOException("Specified log4j XML configuration file is not writable");
+ }
+
+ Transformer transformer = null;
+ transformer = TransformerFactory.newInstance().newTransformer();
+
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "log4j.dtd");
+ DOMSource source = new DOMSource(doc);
+
+ File tmp;
+ Random r = new Random();
+
+ do
+ {
+ tmp = new File(log4jConfigFile.getAbsolutePath() + r.nextInt() + ".tmp");
+ }
+ while(tmp.exists());
+
+ tmp.deleteOnExit();
+
+ try
+ {
+ StreamResult result = new StreamResult(new FileOutputStream(tmp));
+ transformer.transform(source, result);
+ }
+ catch (TransformerException e)
+ {
+ LOGGER.warn("Could not transform the XML into new file: ", e);
+ throw new IOException("Could not transform the XML into new file: ", e);
+ }
+
+ // Swap temp file in to replace existing configuration file.
+ File old = new File(log4jConfigFile.getAbsoluteFile() + ".old");
+ if (old.exists())
+ {
+ old.delete();
+ }
+
+ if(!log4jConfigFile.renameTo(old))
+ {
+ //unable to rename the existing file to the backup name
+ LOGGER.error("Could not backup the existing log4j XML file");
+ throw new IOException("Could not backup the existing log4j XML file");
+ }
+
+ if(!tmp.renameTo(log4jConfigFile))
+ {
+ //failed to rename the new file to the required filename
+
+ if(!old.renameTo(log4jConfigFile))
+ {
+ //unable to return the backup to required filename
+ LOGGER.error("Could not rename the new log4j configuration file into place, and unable to restore original file");
+ throw new IOException("Could not rename the new log4j configuration file into place, and unable to restore original file");
+ }
+
+ LOGGER.error("Could not rename the new log4j configuration file into place");
+ throw new IOException("Could not rename the new log4j configuration file into place");
+ }
+ }
+
+ //method to parse the XML configuration file, validating it in the process, and returning a DOM Document of the content.
+ private static Document parseConfigFile(String fileName) throws IOException
+ {
+ //check file was specified, exists, and is readable
+ if(fileName == null)
+ {
+ LOGGER.warn("Provided log4j XML configuration filename is null");
+ throw new IOException("Provided log4j XML configuration filename is null");
+ }
+
+ File configFile = new File(fileName);
+
+ if (!configFile.exists())
+ {
+ LOGGER.warn("The log4j XML configuration file could not be found: " + fileName);
+ throw new IOException("The log4j XML configuration file could not be found");
+ }
+ else if (!configFile.canRead())
+ {
+ LOGGER.warn("The log4j XML configuration file is not readable: " + fileName);
+ throw new IOException("The log4j XML configuration file is not readable");
+ }
+
+ //parse it
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder;
+ Document doc;
+
+ ErrorHandler errHandler = new QpidLog4JSaxErrorHandler();
+ try
+ {
+ docFactory.setValidating(true);
+ docBuilder = docFactory.newDocumentBuilder();
+ docBuilder.setErrorHandler(errHandler);
+ docBuilder.setEntityResolver(new Log4jEntityResolver());
+ doc = docBuilder.parse(fileName);
+ }
+ catch (ParserConfigurationException e)
+ {
+ LOGGER.warn("Unable to parse the log4j XML file due to possible configuration error: ", e);
+ throw new IOException("Unable to parse the log4j XML file due to possible configuration error: ", e);
+ }
+ catch (SAXException e)
+ {
+ LOGGER.warn("The specified log4j XML file is invalid: ", e);
+ throw new IOException("The specified log4j XML file is invalid: ", e);
+ }
+ catch (IOException e)
+ {
+ LOGGER.warn("Unable to parse the specified log4j XML file", e);
+ throw new IOException("Unable to parse the specified log4j XML file: ", e);
+ }
+
+ return doc;
+ }
+
+ private Logger findRuntimeLogger(String loggerName)
+ {
+ Logger targetLogger = null;
+ @SuppressWarnings("unchecked")
+ Enumeration<Logger> loggers = LogManager.getCurrentLoggers();
+ while(loggers.hasMoreElements())
+ {
+ targetLogger = loggers.nextElement();
+ if (targetLogger.getName().equals(loggerName))
+ {
+ return targetLogger;
+ }
+ }
+ return null;
+ }
+
+ private List<Element> buildListOfCategoryOrLoggerElements(Document doc)
+ {
+ //retrieve the 'category' and 'logger' element nodes
+ NodeList categoryElements = doc.getElementsByTagName("category");
+ NodeList loggerElements = doc.getElementsByTagName("logger");
+
+ //collect them into a single elements list
+ List<Element> logElements = new ArrayList<Element>();
+
+ for (int i = 0; i < categoryElements.getLength(); i++)
+ {
+ logElements.add((Element) categoryElements.item(i));
+ }
+ for (int i = 0; i < loggerElements.getLength(); i++)
+ {
+ logElements.add((Element) loggerElements.item(i));
+ }
+ return logElements;
+ }
+
+ private Element getPriorityOrLevelElement(Element categoryOrLogger) throws LoggingFacadeException
+ {
+ //retrieve the optional 'priority' or 'level' sub-element value.
+ //It may not be the only child node, so request by tag name.
+ NodeList priorityElements = categoryOrLogger.getElementsByTagName("priority");
+ NodeList levelElements = categoryOrLogger.getElementsByTagName("level");
+
+ Element levelElement = null;
+ if (priorityElements.getLength() != 0)
+ {
+ levelElement = (Element) priorityElements.item(0);
+ }
+ else if (levelElements.getLength() != 0)
+ {
+ levelElement = (Element) levelElements.item(0);
+ }
+ else
+ {
+ throw new LoggingFacadeException("Configuration " + categoryOrLogger.getNodeName()
+ + " element contains neither priority nor level child");
+ }
+ return levelElement;
+ }
+
+ private static class QpidLog4JSaxErrorHandler implements ErrorHandler
+ {
+ public void error(SAXParseException e) throws SAXException
+ {
+ if(LOGGER != null)
+ {
+ LOGGER.warn(constructMessage("Error parsing XML file", e));
+ }
+ else
+ {
+ System.err.println(constructMessage("Error parsing XML file", e));
+ }
+ }
+
+ public void fatalError(SAXParseException e) throws SAXException
+ {
+ throw new SAXException(constructMessage("Fatal error parsing XML file", e));
+ }
+
+ public void warning(SAXParseException e) throws SAXException
+ {
+ if(LOGGER != null)
+ {
+ LOGGER.warn(constructMessage("Warning parsing XML file", e));
+ }
+ else
+ {
+ System.err.println(constructMessage("Warning parsing XML file", e));
+ }
+ }
+
+ private static String constructMessage(final String msg, final SAXParseException ex)
+ {
+ return msg + ": Line " + ex.getLineNumber()+" column " +ex.getColumnNumber() + ": " + ex.getMessage();
+ }
+ }
+}
+
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties b/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties
index ac77f674f2..7924be28d3 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/messages/ManagementConsole_logmessages.properties
@@ -18,16 +18,21 @@
#
# Default File used for all non-defined locales.
#
-STARTUP = MNG-1001 : Startup
+# 0 - Management Type
+STARTUP = MNG-1001 : {0} Management Startup
# 0 - Service
# 1 - Port
LISTENING = MNG-1002 : Starting : {0} : Listening on port {1,number,#}
# 0 - Service
# 1 - Port
SHUTTING_DOWN = MNG-1003 : Shutting down : {0} : port {1,number,#}
-READY = MNG-1004 : Ready[ : Using the platform JMX Agent]
-STOPPED = MNG-1005 : Stopped
+# 0 - Management Type
+READY = MNG-1004 : {0} Management Ready
+# 0 - Management Type
+STOPPED = MNG-1005 : {0} Management Stopped
# 0 - Path
SSL_KEYSTORE = MNG-1006 : Using SSL Keystore : {0}
+# 0 - Username
OPEN = MNG-1007 : Open : User {0}
+# 0 - Username
CLOSE = MNG-1008 : Close : User {0} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java b/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java
index 859d7e2a27..bcb9cb2ac4 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java
@@ -76,7 +76,7 @@ public class ChannelLogSubject extends AbstractLogSubject
setLogStringWithFormat(CHANNEL_FORMAT,
connection == null ? -1L : connection.getConnectionId(),
session.getAuthorizedPrincipal() == null ? "?" : session.getAuthorizedPrincipal().getName(),
- (connection == null || connection.getConfig() == null) ? "?" : connection.getConfig().getAddress(),
+ (connection == null || connection.getRemoteAddressString() == null) ? "?" : connection.getRemoteAddressString(),
session.getVirtualHost().getName(),
session.getChannel());
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/LogSubjectFormat.java b/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/LogSubjectFormat.java
index 28c4f0d52a..7611ee1a88 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/LogSubjectFormat.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/LogSubjectFormat.java
@@ -32,11 +32,19 @@ package org.apache.qpid.server.logging.subjects;
public class LogSubjectFormat
{
+
private LogSubjectFormat()
{
}
/**
+ * LOG FORMAT for the ManagementActors,
+ * 0 - User ID
+ * 1 - IP[:Port]
+ */
+ public static final String MANAGEMENT_FORMAT = "mng:{0}({1})";
+
+ /**
* LOG FORMAT for the Subscription Log Subject
* 0 - Subscription ID
*/
diff --git a/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java b/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java
index 2cc1a92853..e01f20d54f 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java
@@ -342,6 +342,14 @@ public class MessageMetaData_1_0 implements StorableMessageMetaData
{
private final AMQPDescribedTypeRegistry _typeRegistry = AMQPDescribedTypeRegistry.newInstance();
+ private MetaDataFactory()
+ {
+ _typeRegistry.registerTransportLayer();
+ _typeRegistry.registerMessagingLayer();
+ _typeRegistry.registerTransactionLayer();
+ _typeRegistry.registerSecurityLayer();
+ }
+
public MessageMetaData_1_0 createMetaData(ByteBuffer buf)
{
ValueHandler valueHandler = new ValueHandler(_typeRegistry);
@@ -354,7 +362,8 @@ public class MessageMetaData_1_0 implements StorableMessageMetaData
try
{
ByteBuffer encodedBuf = buf.duplicate();
- sections.add((Section) valueHandler.parse(buf));
+ Object parse = valueHandler.parse(buf);
+ sections.add((Section) parse);
encodedBuf.limit(buf.position());
encodedSections.add(encodedBuf);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java b/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java
index 6000886956..417f6036ab 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/AuthenticationProvider.java
@@ -24,6 +24,9 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+
public interface AuthenticationProvider extends ConfiguredObject
{
@@ -52,4 +55,15 @@ public interface AuthenticationProvider extends ConfiguredObject
TYPE));
//children
Collection<VirtualHostAlias> getVirtualHostPortBindings();
+
+ String getName();
+
+ /**
+ * A temporary method to create SubjectCreator.
+ *
+ * TODO: move all the functionality from SubjectCreator into AuthenticationProvider
+ */
+ SubjectCreator getSubjectCreator();
+
+ void setGroupAccessor(GroupPrincipalAccessor groupPrincipalAccessor);
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java b/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java
index 08b01a1b65..fbecf1965b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java
@@ -20,12 +20,20 @@
*/
package org.apache.qpid.server.model;
+import java.net.SocketAddress;
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
public interface Broker extends ConfiguredObject
{
@@ -44,9 +52,49 @@ public interface Broker extends ConfiguredObject
String STATE = "state";
String TIME_TO_LIVE = "timeToLive";
String UPDATED = "updated";
+ String DEFAULT_AUTHENTICATION_PROVIDER = "defaultAuthenticationProvider";
+ String DEFAULT_VIRTUAL_HOST = "defaultVirtualHost";
+
+ String ALERT_THRESHOLD_MESSAGE_AGE = "alertThresholdMessageAge";
+ String ALERT_THRESHOLD_MESSAGE_COUNT = "alertThresholdMessageCount";
+ String ALERT_THRESHOLD_QUEUE_DEPTH = "alertThresholdQueueDepth";
+ String ALERT_THRESHOLD_MESSAGE_SIZE = "alertThresholdMessageSize";
+ String ALERT_REPEAT_GAP = "alertRepeatGap";
+ String FLOW_CONTROL_SIZE_BYTES = "queueFlowControlSizeBytes";
+ String FLOW_CONTROL_RESUME_SIZE_BYTES = "queueFlowResumeSizeBytes";
+ String MAXIMUM_DELIVERY_ATTEMPTS = "maximumDeliveryAttempts";
+ String DEAD_LETTER_QUEUE_ENABLED = "deadLetterQueueEnabled";
+ String HOUSEKEEPING_CHECK_PERIOD = "housekeepingCheckPeriod";
+
+ String SESSION_COUNT_LIMIT = "sessionCountLimit";
+ String HEART_BEAT_DELAY = "heartBeatDelay";
+ String STATISTICS_REPORTING_PERIOD = "statisticsReportingPeriod";
+ String STATISTICS_REPORTING_RESET_ENABLED = "statisticsReportingResetEnabled";
+
+ /*
+ * A temporary attribute to pass the path to ACL file.
+ * TODO: It should be a part of AuthorizationProvider.
+ */
+ String ACL_FILE = "aclFile";
+
+ /*
+ * A temporary attributes to set the broker default key/trust stores.
+ * TODO: Remove them after adding a full support to configure KeyStore/TrustStore via management layers.
+ */
+ String KEY_STORE_PATH = "keyStorePath";
+ String KEY_STORE_PASSWORD = "keyStorePassword";
+ String KEY_STORE_CERT_ALIAS = "keyStoreCertAlias";
+ String TRUST_STORE_PATH = "trustStorePath";
+ String TRUST_STORE_PASSWORD = "trustStorePassword";
+
+ /*
+ * A temporary attributes to set the broker group file.
+ * TODO: Remove them after adding a full support to configure authorization providers via management layers.
+ */
+ String GROUP_FILE = "groupFile";
// Attributes
- public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collection<String> AVAILABLE_ATTRIBUTES =
Collections.unmodifiableList(
Arrays.asList(BUILD_VERSION,
BYTES_RETAINED,
@@ -62,7 +110,32 @@ public interface Broker extends ConfiguredObject
NAME,
STATE,
TIME_TO_LIVE,
- UPDATED));
+ UPDATED,
+ DEFAULT_AUTHENTICATION_PROVIDER,
+ DEFAULT_VIRTUAL_HOST,
+ ALERT_THRESHOLD_MESSAGE_AGE,
+ ALERT_THRESHOLD_MESSAGE_COUNT,
+ ALERT_THRESHOLD_QUEUE_DEPTH,
+ ALERT_THRESHOLD_MESSAGE_SIZE,
+ ALERT_REPEAT_GAP,
+ FLOW_CONTROL_SIZE_BYTES,
+ FLOW_CONTROL_RESUME_SIZE_BYTES,
+ MAXIMUM_DELIVERY_ATTEMPTS,
+ DEAD_LETTER_QUEUE_ENABLED,
+ HOUSEKEEPING_CHECK_PERIOD,
+ SESSION_COUNT_LIMIT,
+ HEART_BEAT_DELAY,
+ STATISTICS_REPORTING_PERIOD,
+ STATISTICS_REPORTING_RESET_ENABLED,
+
+ ACL_FILE,
+ KEY_STORE_PATH,
+ KEY_STORE_PASSWORD,
+ KEY_STORE_CERT_ALIAS,
+ TRUST_STORE_PATH,
+ TRUST_STORE_PASSWORD,
+ GROUP_FILE
+ ));
//children
Collection < VirtualHost > getVirtualHosts();
@@ -75,6 +148,49 @@ public interface Broker extends ConfiguredObject
LifetimePolicy lifetime, long ttl, Map<String, Object> attributes)
throws AccessControlException, IllegalArgumentException;
- void deleteVirtualHost(VirtualHost virtualHost)
- throws AccessControlException, IllegalStateException;
+ AuthenticationProvider getDefaultAuthenticationProvider();
+
+ Collection<GroupProvider> getGroupProviders();
+
+ /**
+ * A temporary hack to expose root message logger via broker instance.
+ * TODO We need a better way to do operational logging, for example, via logging listeners
+ */
+ RootMessageLogger getRootMessageLogger();
+
+ /**
+ * A temporary hack to expose security manager via broker instance.
+ * TODO We need to add and implement an authorization provider configured object instead
+ */
+ SecurityManager getSecurityManager();
+
+ /**
+ * TODO: A temporary hack to expose log recorder via broker instance.
+ */
+ LogRecorder getLogRecorder();
+
+ VirtualHost findVirtualHostByName(String name);
+
+ /**
+ * Get the SubjectCreator for the given socket address.
+ * TODO: move the authentication related functionality into host aliases and AuthenticationProviders
+ *
+ * @param address The (listening) socket address for which the AuthenticationManager is required
+ */
+ SubjectCreator getSubjectCreator(SocketAddress localAddress);
+
+ Collection<KeyStore> getKeyStores();
+
+ Collection<TrustStore> getTrustStores();
+
+ /*
+ * TODO: Remove this method. Eventually the broker will become a registry.
+ */
+ VirtualHostRegistry getVirtualHostRegistry();
+
+ KeyStore getDefaultKeyStore();
+
+ TrustStore getDefaultTrustStore();
+
+ TaskExecutor getTaskExecutor();
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java b/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java
index 78b98faffe..bd7da962ba 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/ConfigurationChangeListener.java
@@ -36,4 +36,5 @@ public interface ConfigurationChangeListener
void childRemoved(ConfiguredObject object, ConfiguredObject child);
+ void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue);
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java b/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
index 414b2d083a..d567a3aa44 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
@@ -25,6 +25,9 @@ import java.util.Collection;
import java.util.Map;
import java.util.UUID;
+/**
+ * An object that can be "managed" (eg via the web interface) and usually read from configuration.
+ */
public interface ConfiguredObject
{
@@ -47,7 +50,7 @@ public interface ConfiguredObject
* Attempt to change the name of the object
*
* Request a change to the name of the object. The caller must pass in the name it believes the object currently
- * has. If the current name differes from this expected value, then no name change will occur
+ * has. If the current name differs from this expected value, then no name change will occur
*
* @param currentName the name the caller believes the object to have
* @param desiredName the name the caller would like the object to have
@@ -198,14 +201,25 @@ public interface ConfiguredObject
/**
- * Return the value for the given attribute
+ * Return the value for the given attribute name. The actual attribute value
+ * is returned if the configured object has such attribute set. If not, the
+ * value is looked default attributes.
*
- * @param name the name of the attribute
- * @return the value of the attribute at the object (or null if the attribute is not set
+ * @param name
+ * the name of the attribute
+ * @return the value of the attribute at the object (or null if the
+ * attribute value is set neither on object itself no in defaults)
*/
Object getAttribute(String name);
/**
+ * Return the map containing only explicitly set attributes
+ *
+ * @return the map with the attributes
+ */
+ Map<String, Object> getActualAttributes();
+
+ /**
* Set the value of an attribute
*
* @param name the name of the attribute to be set
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/Group.java b/java/broker/src/main/java/org/apache/qpid/server/model/Group.java
new file mode 100644
index 0000000000..aacd515107
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/Group.java
@@ -0,0 +1,52 @@
+/*
+ * 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.model;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+public interface Group extends ConfiguredObject
+{
+ String CREATED = "created";
+ String DURABLE = "durable";
+ String ID = "id";
+ String LIFETIME_POLICY = "lifetimePolicy";
+ String NAME = "name";
+ String STATE = "state";
+ String TIME_TO_LIVE = "timeToLive";
+ String UPDATED = "updated";
+
+ // Attributes
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ ID,
+ NAME,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED
+ ));
+
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/GroupMember.java b/java/broker/src/main/java/org/apache/qpid/server/model/GroupMember.java
new file mode 100644
index 0000000000..6832cc6fa6
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/GroupMember.java
@@ -0,0 +1,52 @@
+/*
+ * 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.model;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+public interface GroupMember extends ConfiguredObject
+{
+ String CREATED = "created";
+ String DURABLE = "durable";
+ String ID = "id";
+ String LIFETIME_POLICY = "lifetimePolicy";
+ String NAME = "name";
+ String STATE = "state";
+ String TIME_TO_LIVE = "timeToLive";
+ String UPDATED = "updated";
+
+ // Attributes
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ ID,
+ NAME,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED
+ ));
+
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java b/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java
new file mode 100644
index 0000000000..9016f97927
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/GroupProvider.java
@@ -0,0 +1,55 @@
+/*
+ * 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.model;
+
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+public interface GroupProvider extends ConfiguredObject
+{
+ public static final String ID = "id";
+ public static final String DESCRIPTION = "description";
+ public static final String NAME = "name";
+ public static final String STATE = "state";
+ public static final String DURABLE = "durable";
+ public static final String LIFETIME_POLICY = "lifetimePolicy";
+ public static final String TIME_TO_LIVE = "timeToLive";
+ public static final String CREATED = "created";
+ public static final String UPDATED = "updated";
+ public static final String TYPE = "type";
+
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(ID,
+ NAME,
+ DESCRIPTION,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED,
+ TYPE));
+
+ Set<Principal> getGroupPrincipalsForUser(String username);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java b/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.java
new file mode 100644
index 0000000000..959714656b
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/KeyStore.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.server.model;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+public interface KeyStore extends TrustStore
+{
+
+ String CERTIFICATE_ALIAS = "certificateAlias";
+
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ ID,
+ NAME,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED,
+ DESCRIPTION,
+ PATH,
+ PASSWORD,
+ TYPE,
+ KEY_MANAGER_FACTORY_ALGORITHM,
+ CERTIFICATE_ALIAS
+ ));
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/Model.java b/java/broker/src/main/java/org/apache/qpid/server/model/Model.java
index 36179fc105..2c05dce9cb 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/Model.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/Model.java
@@ -47,6 +47,10 @@ public class Model
addRelationship(Broker.class, VirtualHost.class);
addRelationship(Broker.class, Port.class);
addRelationship(Broker.class, AuthenticationProvider.class);
+ addRelationship(Broker.class, GroupProvider.class);
+ addRelationship(Broker.class, TrustStore.class);
+ addRelationship(Broker.class, KeyStore.class);
+ addRelationship(Broker.class, Plugin.class);
addRelationship(VirtualHost.class, Exchange.class);
addRelationship(VirtualHost.class, Queue.class);
@@ -54,6 +58,10 @@ public class Model
addRelationship(VirtualHost.class, VirtualHostAlias.class);
addRelationship(AuthenticationProvider.class, User.class);
+ addRelationship(User.class, GroupMember.class);
+
+ addRelationship(GroupProvider.class, Group.class);
+ addRelationship(Group.class, GroupMember.class);
addRelationship(Connection.class, Session.class);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java b/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java
new file mode 100644
index 0000000000..b9503a5841
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/Plugin.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.model;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+public interface Plugin extends ConfiguredObject
+{
+ //Hack, using it for the class name only for consistency with the other things.
+ String CREATED = "created";
+ String DURABLE = "durable";
+ String ID = "id";
+ String LIFETIME_POLICY = "lifetimePolicy";
+ String NAME = "name";
+ String STATE = "state";
+ String TIME_TO_LIVE = "timeToLive";
+ String UPDATED = "updated";
+
+ // Attributes
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ ID,
+ NAME,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED
+ ));
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/Port.java b/java/broker/src/main/java/org/apache/qpid/server/model/Port.java
index 50c0ebcd14..2f94c3cab7 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/Port.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/Port.java
@@ -39,6 +39,16 @@ public interface Port extends ConfiguredObject
String PORT = "port";
String PROTOCOLS = "protocols";
String TRANSPORTS = "transports";
+ String TCP_NO_DELAY = "tcpNoDelay";
+ String SEND_BUFFER_SIZE = "sendBufferSize";
+ String RECEIVE_BUFFER_SIZE = "receiveBufferSize";
+ String NEED_CLIENT_AUTH = "needClientAuth";
+ String WANT_CLIENT_AUTH = "wantClientAuth";
+
+ /**
+ * TODO: rename it to AUTHENTICATION_MANAGER_ID or introduce relationships
+ */
+ String AUTHENTICATION_MANAGER = "authenticationManager";
// Attributes
public static final Collection<String> AVAILABLE_ATTRIBUTES =
@@ -55,7 +65,13 @@ public interface Port extends ConfiguredObject
BINDING_ADDRESS,
PORT,
PROTOCOLS,
- TRANSPORTS
+ TRANSPORTS,
+ TCP_NO_DELAY,
+ SEND_BUFFER_SIZE,
+ RECEIVE_BUFFER_SIZE,
+ NEED_CLIENT_AUTH,
+ WANT_CLIENT_AUTH,
+ AUTHENTICATION_MANAGER
));
@@ -88,4 +104,8 @@ public interface Port extends ConfiguredObject
//children
Collection<VirtualHostAlias> getVirtualHostBindings();
Collection<Connection> getConnections();
+
+ AuthenticationProvider getAuthenticationProvider();
+
+ void setAuthenticationProvider(AuthenticationProvider authenticationProvider);
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java b/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java
index 5d9de69f9a..6cd5eb23a4 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/Protocol.java
@@ -20,14 +20,95 @@
*/
package org.apache.qpid.server.model;
+import java.util.Collection;
+import java.util.EnumSet;
+
+import org.apache.qpid.server.protocol.AmqpProtocolVersion;
+
public enum Protocol
{
- AMQP_0_8,
- AMQP_0_9,
- AMQP_0_9_1,
- AMQP_0_10,
- AMQP_1_0,
- JMX,
- HTTP,
- HTTPS
+ AMQP_0_8(ProtocolType.AMQP),
+ AMQP_0_9(ProtocolType.AMQP),
+ AMQP_0_9_1(ProtocolType.AMQP),
+ AMQP_0_10(ProtocolType.AMQP),
+ AMQP_1_0(ProtocolType.AMQP),
+ JMX_RMI(ProtocolType.JMX),
+ HTTP(ProtocolType.HTTP),
+ HTTPS(ProtocolType.HTTP),
+ RMI(ProtocolType.RMI);
+
+ private final ProtocolType _protocolType;
+
+ private Protocol(ProtocolType type)
+ {
+ _protocolType = type;
+ }
+
+ public ProtocolType getProtocolType()
+ {
+ return _protocolType;
+ }
+
+ public boolean isAMQP()
+ {
+ return _protocolType == ProtocolType.AMQP;
+ }
+
+ public AmqpProtocolVersion toAmqpProtocolVersion()
+ {
+ switch(this)
+ {
+ case AMQP_0_8:
+ return AmqpProtocolVersion.v0_8;
+ case AMQP_0_9:
+ return AmqpProtocolVersion.v0_9;
+ case AMQP_0_9_1:
+ return AmqpProtocolVersion.v0_9_1;
+ case AMQP_0_10:
+ return AmqpProtocolVersion.v0_10;
+ case AMQP_1_0:
+ return AmqpProtocolVersion.v1_0_0;
+ default:
+ throw new IllegalArgumentException(this + " is not an known AMQP protocol");
+ }
+ }
+
+ public static Protocol valueOfObject(Object protocolObject)
+ {
+ Protocol protocol;
+ if (protocolObject instanceof Protocol)
+ {
+ protocol = (Protocol) protocolObject;
+ }
+ else
+ {
+ try
+ {
+ protocol = Protocol.valueOf(String.valueOf(protocolObject));
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Can't convert '" + protocolObject
+ + "' to one of the supported protocols: " + EnumSet.allOf(Protocol.class), e);
+ }
+ }
+ return protocol;
+ }
+
+ public static boolean hasAmqpProtocol(Collection<Protocol> protocols)
+ {
+ for (Protocol protocol : protocols)
+ {
+ if (protocol.isAMQP())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static enum ProtocolType
+ {
+ AMQP, HTTP, JMX, RMI;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java b/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java
index 03cd46be01..ae6e5ac43a 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/Transport.java
@@ -20,8 +20,32 @@
*/
package org.apache.qpid.server.model;
+import java.util.EnumSet;
+
public enum Transport
{
TCP,
- SSL
+ SSL;
+
+ public static Transport valueOfObject(Object transportObject)
+ {
+ Transport transport;
+ if (transportObject instanceof Transport)
+ {
+ transport = (Transport) transportObject;
+ }
+ else
+ {
+ try
+ {
+ transport = Transport.valueOf(String.valueOf(transportObject));
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Can't convert '" + transportObject
+ + "' to one of the supported transports: " + EnumSet.allOf(Transport.class), e);
+ }
+ }
+ return transport;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java b/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.java
new file mode 100644
index 0000000000..0c322ae02f
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/TrustStore.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.server.model;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+public interface TrustStore extends ConfiguredObject
+{
+ String ID = "id";
+ String NAME = "name";
+ String DURABLE = "durable";
+ String LIFETIME_POLICY = "lifetimePolicy";
+ String STATE = "state";
+ String TIME_TO_LIVE = "timeToLive";
+ String CREATED = "created";
+ String UPDATED = "updated";
+ String DESCRIPTION = "description";
+
+ String PATH = "path";
+ String PASSWORD = "password";
+ String TYPE = "type";
+ String KEY_MANAGER_FACTORY_ALGORITHM = "keyManagerFactoryAlgorithm";
+
+ public static final Collection<String> AVAILABLE_ATTRIBUTES =
+ Collections.unmodifiableList(
+ Arrays.asList(
+ ID,
+ NAME,
+ STATE,
+ DURABLE,
+ LIFETIME_POLICY,
+ TIME_TO_LIVE,
+ CREATED,
+ UPDATED,
+ DESCRIPTION,
+ PATH,
+ PASSWORD,
+ TYPE,
+ KEY_MANAGER_FACTORY_ALGORITHM
+ ));
+
+ public String getPassword();
+
+ public void setPassword(String password);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java b/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java
index 36b6a454dc..bcedd91596 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/UUIDGenerator.java
@@ -63,6 +63,11 @@ public class UUIDGenerator
return createUUID(User.class.getName(), authenticationProviderName, userName);
}
+ public static UUID generateGroupUUID(String groupProviderName, String groupName)
+ {
+ return createUUID(Group.class.getName(), groupProviderName, groupName);
+ }
+
public static UUID generateVhostUUID(String virtualHostName)
{
return createUUID(VirtualHost.class.getName(), virtualHostName);
@@ -77,4 +82,14 @@ public class UUIDGenerator
{
return createUUID(Consumer.class.getName(), virtualHostName, queueName, connectionRemoteAddress, channelNumber, consumerName);
}
+
+ public static UUID generateGroupMemberUUID(String groupProviderName, String groupName, String groupMemberName)
+ {
+ return createUUID(GroupMember.class.getName(), groupProviderName, groupName, groupMemberName);
+ }
+
+ public static UUID generateBrokerChildUUID(String type, String childName)
+ {
+ return createUUID(type, childName);
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/User.java b/java/broker/src/main/java/org/apache/qpid/server/model/User.java
index d97bf46d31..675dc8f0d3 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/User.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/User.java
@@ -52,8 +52,6 @@ public interface User extends ConfiguredObject
PASSWORD
));
- public String getPassword();
-
public void setPassword(String password);
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java b/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java
index 24a3d43386..5f4ec1d3a8 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/VirtualHost.java
@@ -21,6 +21,9 @@
package org.apache.qpid.server.model;
import org.apache.qpid.server.queue.QueueEntry;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.store.MessageStore;
+
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.Collection;
@@ -60,17 +63,16 @@ public interface VirtualHost extends ConfiguredObject
String ALERT_THRESHOLD_QUEUE_DEPTH_BYTES = "alertThresholdQueueDepthBytes";
String ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES = "alertThresholdQueueDepthMessages";
String DEAD_LETTER_QUEUE_ENABLED = "deadLetterQueueEnabled";
- String FEDERATION_TAG = "federationTag";
String HOUSEKEEPING_CHECK_PERIOD = "housekeepingCheckPeriod";
String MAXIMUM_DELIVERY_ATTEMPTS = "maximumDeliveryAttempts";
String QUEUE_FLOW_CONTROL_SIZE_BYTES = "queueFlowControlSizeBytes";
String QUEUE_FLOW_RESUME_SIZE_BYTES = "queueFlowResumeSizeBytes";
- String STORE_CONFIGURATION = "storeConfiguration";
String STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE = "storeTransactionIdleTimeoutClose";
String STORE_TRANSACTION_IDLE_TIMEOUT_WARN = "storeTransactionIdleTimeoutWarn";
String STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE = "storeTransactionOpenTimeoutClose";
String STORE_TRANSACTION_OPEN_TIMEOUT_WARN = "storeTransactionOpenTimeoutWarn";
String STORE_TYPE = "storeType";
+ String STORE_PATH = "storePath";
String SUPPORTED_EXCHANGE_TYPES = "supportedExchangeTypes";
String SUPPORTED_QUEUE_TYPES = "supportedQueueTypes";
String CREATED = "created";
@@ -81,6 +83,8 @@ public interface VirtualHost extends ConfiguredObject
String STATE = "state";
String TIME_TO_LIVE = "timeToLive";
String UPDATED = "updated";
+ String CONFIG_PATH = "configPath";
+
// Attributes
public static final Collection<String> AVAILABLE_ATTRIBUTES =
Collections.unmodifiableList(
@@ -96,13 +100,12 @@ public interface VirtualHost extends ConfiguredObject
SUPPORTED_EXCHANGE_TYPES,
SUPPORTED_QUEUE_TYPES,
DEAD_LETTER_QUEUE_ENABLED,
- FEDERATION_TAG,
HOUSEKEEPING_CHECK_PERIOD,
MAXIMUM_DELIVERY_ATTEMPTS,
QUEUE_FLOW_CONTROL_SIZE_BYTES,
QUEUE_FLOW_RESUME_SIZE_BYTES,
STORE_TYPE,
- STORE_CONFIGURATION,
+ STORE_PATH,
STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE,
STORE_TRANSACTION_IDLE_TIMEOUT_WARN,
STORE_TRANSACTION_OPEN_TIMEOUT_CLOSE,
@@ -111,7 +114,8 @@ public interface VirtualHost extends ConfiguredObject
ALERT_THRESHOLD_MESSAGE_AGE,
ALERT_THRESHOLD_MESSAGE_SIZE,
ALERT_THRESHOLD_QUEUE_DEPTH_BYTES,
- ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES));
+ ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES,
+ CONFIG_PATH));
@@ -149,4 +153,12 @@ public interface VirtualHost extends ConfiguredObject
}
void executeTransaction(TransactionalOperation op);
+
+ /**
+ * A temporary hack to expose host security manager.
+ * TODO We need to add and implement an authorization provider configured object instead
+ */
+ SecurityManager getSecurityManager();
+
+ MessageStore getMessageStore();
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java
index 7d6aa9b2cb..73e1f1e970 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractAdapter.java
@@ -24,12 +24,18 @@ import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
+
import org.apache.qpid.server.model.ConfigurationChangeListener;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.IllegalStateTransitionException;
import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.configuration.updater.ChangeStateTask;
+import org.apache.qpid.server.configuration.updater.CreateChildTask;
+import org.apache.qpid.server.configuration.updater.SetAttributeTask;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
abstract class AbstractAdapter implements ConfiguredObject
{
@@ -40,134 +46,78 @@ abstract class AbstractAdapter implements ConfiguredObject
new ArrayList<ConfigurationChangeListener>();
private final UUID _id;
+ private final Map<String, Object> _defaultAttributes = new HashMap<String, Object>();
+ private final TaskExecutor _taskExecutor;
- protected AbstractAdapter(UUID id)
+ protected AbstractAdapter(UUID id, Map<String, Object> defaults, Map<String, Object> attributes, TaskExecutor taskExecutor)
{
+ _taskExecutor = taskExecutor;
_id = id;
- }
-
- static String getStringAttribute(String name, Map<String,Object> attributes, String defaultVal)
- {
- final Object value = attributes.get(name);
- return value == null ? defaultVal : String.valueOf(value);
- }
-
- static Map getMapAttribute(String name, Map<String,Object> attributes, Map defaultVal)
- {
- final Object value = attributes.get(name);
- if(value == null)
- {
- return defaultVal;
- }
- else if(value instanceof Map)
+ if (attributes != null)
{
- return (Map) value;
+ Collection<String> names = getAttributeNames();
+ for (String name : names)
+ {
+ if (attributes.containsKey(name))
+ {
+ _attributes.put(name, attributes.get(name));
+ }
+ }
}
- else
+ if (defaults != null)
{
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Map");
+ _defaultAttributes.putAll(defaults);
}
}
-
- static <E extends Enum> E getEnumAttribute(Class<E> clazz, String name, Map<String,Object> attributes, E defaultVal)
+ protected AbstractAdapter(UUID id, TaskExecutor taskExecutor)
{
- Object obj = attributes.get(name);
- if(obj == null)
- {
- return defaultVal;
- }
- else if(clazz.isInstance(obj))
- {
- return (E) obj;
- }
- else if(obj instanceof String)
- {
- return (E) Enum.valueOf(clazz, (String)obj);
- }
- else
- {
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type " + clazz.getSimpleName());
- }
+ this(id, null, null, taskExecutor);
}
- static Boolean getBooleanAttribute(String name, Map<String,Object> attributes, Boolean defaultValue)
+ public final UUID getId()
{
- Object obj = attributes.get(name);
- if(obj == null)
- {
- return defaultValue;
- }
- else if(obj instanceof Boolean)
- {
- return (Boolean) obj;
- }
- else if(obj instanceof String)
- {
- return Boolean.parseBoolean((String) obj);
- }
- else
- {
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Boolean");
- }
+ return _id;
}
- static Integer getIntegerAttribute(String name, Map<String,Object> attributes, Integer defaultValue)
+ public State getDesiredState()
{
- Object obj = attributes.get(name);
- if(obj == null)
- {
- return defaultValue;
- }
- else if(obj instanceof Number)
- {
- return ((Number) obj).intValue();
- }
- else if(obj instanceof String)
- {
- return Integer.valueOf((String) obj);
- }
- else
- {
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Integer");
- }
+ return null; //TODO
}
- static Long getLongAttribute(String name, Map<String,Object> attributes, Long defaultValue)
+ @Override
+ public final State setDesiredState(final State currentState, final State desiredState)
+ throws IllegalStateTransitionException, AccessControlException
{
- Object obj = attributes.get(name);
- if(obj == null)
- {
- return defaultValue;
- }
- else if(obj instanceof Number)
+ if (_taskExecutor.isTaskExecutorThread())
{
- return ((Number) obj).longValue();
- }
- else if(obj instanceof String)
- {
- return Long.valueOf((String) obj);
+ if (setState(currentState, desiredState))
+ {
+ notifyStateChanged(currentState, desiredState);
+ }
}
else
{
- throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Long");
+ _taskExecutor.submitAndWait(new ChangeStateTask(this, currentState, desiredState));
}
+ return getActualState();
}
- public final UUID getId()
- {
- return _id;
- }
+ /**
+ * @return true when the state has been successfully updated to desiredState or false otherwise
+ */
+ protected abstract boolean setState(State currentState, State desiredState);
- public State getDesiredState()
+ protected void notifyStateChanged(final State currentState, final State desiredState)
{
- return null; //TODO
- }
-
- public State setDesiredState(final State currentState, final State desiredState)
- throws IllegalStateTransitionException, AccessControlException
- {
- return null; //TODO
+ synchronized (_changeListeners)
+ {
+ List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners);
+ for(ConfigurationChangeListener listener : copy)
+ {
+ listener.stateChanged(this, currentState, desiredState);
+ }
+ }
}
public void addChangeListener(final ConfigurationChangeListener listener)
@@ -176,7 +126,7 @@ abstract class AbstractAdapter implements ConfiguredObject
{
throw new NullPointerException("Cannot add a null listener");
}
- synchronized (this)
+ synchronized (_changeListeners)
{
if(!_changeListeners.contains(listener))
{
@@ -191,39 +141,76 @@ abstract class AbstractAdapter implements ConfiguredObject
{
throw new NullPointerException("Cannot remove a null listener");
}
- synchronized (this)
+ synchronized (_changeListeners)
{
return _changeListeners.remove(listener);
}
}
-
protected void childAdded(ConfiguredObject child)
{
- synchronized (this)
+ synchronized (_changeListeners)
{
- for(ConfigurationChangeListener listener : _changeListeners)
+ List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners);
+ for(ConfigurationChangeListener listener : copy)
{
listener.childAdded(this, child);
}
}
}
-
protected void childRemoved(ConfiguredObject child)
{
- synchronized (this)
+ synchronized (_changeListeners)
{
- for(ConfigurationChangeListener listener : _changeListeners)
+ List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners);
+ for(ConfigurationChangeListener listener : copy)
{
listener.childRemoved(this, child);
}
}
}
- public Object getAttribute(final String name)
+ protected void attributeSet(String attrinuteName, Object oldAttributeValue, Object newAttributeValue)
{
- synchronized (this)
+ synchronized (_changeListeners)
+ {
+ List<ConfigurationChangeListener> copy = new ArrayList<ConfigurationChangeListener>(_changeListeners);
+ for(ConfigurationChangeListener listener : copy)
+ {
+ listener.attributeSet(this, attrinuteName, oldAttributeValue, newAttributeValue);
+ }
+ }
+ }
+
+ private final Object getDefaultAttribute(String name)
+ {
+ return _defaultAttributes.get(name);
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ Object value = getActualAttribute(name);
+ if (value == null)
+ {
+ value = getDefaultAttribute(name);
+ }
+ return value;
+ }
+
+ @Override
+ public final Map<String, Object> getActualAttributes()
+ {
+ synchronized (_attributes)
+ {
+ return new HashMap<String, Object>(_attributes);
+ }
+ }
+
+ private Object getActualAttribute(final String name)
+ {
+ synchronized (_attributes)
{
return _attributes.get(name);
}
@@ -232,25 +219,41 @@ abstract class AbstractAdapter implements ConfiguredObject
public Object setAttribute(final String name, final Object expected, final Object desired)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- synchronized (this)
+ if (_taskExecutor.isTaskExecutorThread())
{
- Object currentValue = _attributes.get(name);
+ if (changeAttribute(name, expected, desired))
+ {
+ attributeSet(name, expected, desired);
+ }
+ }
+ else
+ {
+ _taskExecutor.submitAndWait(new SetAttributeTask(this, name, expected, desired));
+ }
+ return getAttribute(name);
+ }
+
+ protected boolean changeAttribute(final String name, final Object expected, final Object desired)
+ {
+ synchronized (_attributes)
+ {
+ Object currentValue = getAttribute(name);
if((currentValue == null && expected == null)
|| (currentValue != null && currentValue.equals(expected)))
{
_attributes.put(name, desired);
- return desired;
+ return true;
}
else
{
- return currentValue;
+ return false;
}
}
}
public <T extends ConfiguredObject> T getParent(final Class<T> clazz)
{
- synchronized (this)
+ synchronized (_parents)
{
return (T) _parents.get(clazz);
}
@@ -258,7 +261,7 @@ abstract class AbstractAdapter implements ConfiguredObject
protected <T extends ConfiguredObject> void addParent(Class<T> clazz, T parent)
{
- synchronized (this)
+ synchronized (_parents)
{
_parents.put(clazz, parent);
}
@@ -280,4 +283,40 @@ abstract class AbstractAdapter implements ConfiguredObject
}
}
+ @Override
+ public String toString()
+ {
+ return getClass().getSimpleName() + " [id=" + _id + ", name=" + getName() + "]";
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ {
+ if (_taskExecutor.isTaskExecutorThread())
+ {
+ C child = addChild(childClass, attributes, otherParents);
+ if (child != null)
+ {
+ childAdded(child);
+ }
+ return child;
+ }
+ else
+ {
+ return (C)_taskExecutor.submitAndWait(new CreateChildTask(this, childClass, attributes, otherParents));
+ }
+ }
+
+ protected <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ protected TaskExecutor getTaskExecutor()
+ {
+ return _taskExecutor;
+ }
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java
new file mode 100644
index 0000000000..ebd98f915d
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractKeyStoreAdapter.java
@@ -0,0 +1,198 @@
+/*
+ *
+ * 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.model.adapter;
+
+import java.security.AccessControlException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.Statistics;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.util.MapValueConverter;
+
+public abstract class AbstractKeyStoreAdapter extends AbstractAdapter
+{
+ private String _name;
+ private String _password;
+
+ protected AbstractKeyStoreAdapter(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, broker.getTaskExecutor());
+ addParent(Broker.class, broker);
+ _name = MapValueConverter.getStringAttribute(TrustStore.NAME, attributes);
+ _password = MapValueConverter.getStringAttribute(TrustStore.PASSWORD, attributes);
+ setMandatoryAttribute(TrustStore.PATH, attributes);
+ setOptionalAttribute(TrustStore.TYPE, attributes);
+ setOptionalAttribute(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, attributes);
+ setOptionalAttribute(TrustStore.DESCRIPTION, attributes);
+ }
+
+ @Override
+ public String getName()
+ {
+ return _name;
+ }
+
+ @Override
+ public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException
+ {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public State getActualState()
+ {
+ return State.ACTIVE;
+ }
+
+ @Override
+ public boolean isDurable()
+ {
+ return true;
+ }
+
+ @Override
+ public void setDurable(boolean durable) throws IllegalStateException, AccessControlException, IllegalArgumentException
+ {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public LifetimePolicy getLifetimePolicy()
+ {
+ return LifetimePolicy.PERMANENT;
+ }
+
+ @Override
+ public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) throws IllegalStateException, AccessControlException,
+ IllegalArgumentException
+ {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public long getTimeToLive()
+ {
+ return 0;
+ }
+
+ @Override
+ public long setTimeToLive(long expected, long desired) throws IllegalStateException, AccessControlException, IllegalArgumentException
+ {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public Statistics getStatistics()
+ {
+ return NoStatistics.getInstance();
+ }
+
+ @Override
+ public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
+ {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ if(KeyStore.ID.equals(name))
+ {
+ return getId();
+ }
+ else if(KeyStore.NAME.equals(name))
+ {
+ return getName();
+ }
+ else if(KeyStore.STATE.equals(name))
+ {
+ return getActualState();
+ }
+ else if(KeyStore.DURABLE.equals(name))
+ {
+ return isDurable();
+ }
+ else if(KeyStore.LIFETIME_POLICY.equals(name))
+ {
+ return getLifetimePolicy();
+ }
+ else if(KeyStore.TIME_TO_LIVE.equals(name))
+ {
+ return getTimeToLive();
+ }
+ else if(KeyStore.CREATED.equals(name))
+ {
+
+ }
+ else if(KeyStore.UPDATED.equals(name))
+ {
+
+ }
+ else if(KeyStore.PASSWORD.equals(name))
+ {
+ return null; // for security reasons we don't expose the password
+ }
+ return super.getAttribute(name);
+ }
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ return false;
+ }
+
+ public String getPassword()
+ {
+ return _password;
+ }
+
+ public void setPassword(String password)
+ {
+ _password = password;
+ }
+
+ private void setMandatoryAttribute(String name, Map<String, Object> attributeValues)
+ {
+ changeAttribute(name, null, MapValueConverter.getStringAttribute(name, attributeValues));
+ }
+
+ private void setOptionalAttribute(String name, Map<String, Object> attributeValues)
+ {
+ if (attributeValues.get(name) != null)
+ {
+ changeAttribute(name, null, MapValueConverter.getStringAttribute(name, attributeValues));
+ }
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java
new file mode 100644
index 0000000000..ed4af9881f
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java
@@ -0,0 +1,152 @@
+/*
+ *
+ * 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.model.adapter;
+
+import java.security.AccessControlException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.model.ConfiguredObject;
+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.Statistics;
+
+public abstract class AbstractPluginAdapter extends AbstractAdapter implements Plugin
+{
+
+ protected AbstractPluginAdapter(UUID id, Map<String, Object> defaults, Map<String, Object> attributes, TaskExecutor taskExecutor)
+ {
+ super(id, defaults, attributes, taskExecutor);
+ }
+
+ @Override
+ public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public State getActualState()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isDurable()
+ {
+ return true;
+ }
+
+ @Override
+ public void setDurable(boolean durable) throws IllegalStateException, AccessControlException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public LifetimePolicy getLifetimePolicy()
+ {
+ return LifetimePolicy.PERMANENT;
+ }
+
+ @Override
+ public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired) throws IllegalStateException,
+ AccessControlException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getTimeToLive()
+ {
+ return 0;
+ }
+
+ @Override
+ public long setTimeToLive(long expected, long desired) throws IllegalStateException, AccessControlException,
+ IllegalArgumentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Statistics getStatistics()
+ {
+ return null;
+ }
+
+ @Override
+ public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
+ {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes,
+ ConfiguredObject... otherParents)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ if (ID.equals(name))
+ {
+ return getId();
+ }
+ else if (STATE.equals(name))
+ {
+ return getActualState();
+ }
+ else if (DURABLE.equals(name))
+ {
+ return isDurable();
+ }
+ else if (LIFETIME_POLICY.equals(name))
+ {
+ return getLifetimePolicy();
+ }
+ else if (TIME_TO_LIVE.equals(name))
+ {
+ return getTimeToLive();
+ }
+ else if (CREATED.equals(name))
+ {
+
+ }
+ else if (UPDATED.equals(name))
+ {
+
+ }
+ return super.getAttribute(name);
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java
new file mode 100644
index 0000000000..2f7e89bb2b
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AmqpPortAdapter.java
@@ -0,0 +1,251 @@
+/*
+ * 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.model.adapter;
+
+import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.security.GeneralSecurityException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.messages.BrokerMessages;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.protocol.AmqpProtocolVersion;
+import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory;
+import org.apache.qpid.ssl.SSLContextFactory;
+import org.apache.qpid.transport.NetworkTransportConfiguration;
+import org.apache.qpid.transport.network.IncomingNetworkTransport;
+
+public class AmqpPortAdapter extends PortAdapter
+{
+ private final Broker _broker;
+ private IncomingNetworkTransport _transport;
+
+ public AmqpPortAdapter(UUID id, Broker broker, Map<String, Object> attributes, Map<String, Object> defaultAttributes, TaskExecutor taskExecutor)
+ {
+ super(id, broker, attributes, defaultAttributes, taskExecutor);
+ _broker = broker;
+ }
+
+ @Override
+ protected void onActivate()
+ {
+ Collection<Transport> transports = getTransports();
+ Set<AmqpProtocolVersion> supported = convertFromModelProtocolsToAmqp(getProtocols());
+
+ SSLContext sslContext = null;
+ if (transports.contains(Transport.SSL))
+ {
+ sslContext = createSslContext();
+ }
+
+ AmqpProtocolVersion defaultSupportedProtocolReply = getDefaultAmqpSupportedReply();
+
+ String bindingAddress = (String) getAttribute(Port.BINDING_ADDRESS);
+ if (WILDCARD_ADDRESS.equals(bindingAddress))
+ {
+ bindingAddress = null;
+ }
+ Integer port = (Integer) getAttribute(Port.PORT);
+ InetSocketAddress bindingSocketAddress = null;
+ if ( bindingAddress == null )
+ {
+ bindingSocketAddress = new InetSocketAddress(port);
+ }
+ else
+ {
+ bindingSocketAddress = new InetSocketAddress(bindingAddress, port);
+ }
+
+ final NetworkTransportConfiguration settings = new ServerNetworkTransportConfiguration(
+ bindingSocketAddress, (Boolean)getAttribute(TCP_NO_DELAY),
+ (Integer)getAttribute(SEND_BUFFER_SIZE), (Integer)getAttribute(RECEIVE_BUFFER_SIZE),
+ (Boolean)getAttribute(NEED_CLIENT_AUTH), (Boolean)getAttribute(WANT_CLIENT_AUTH));
+
+ _transport = org.apache.qpid.transport.network.Transport.getIncomingTransportInstance();
+ final MultiVersionProtocolEngineFactory protocolEngineFactory = new MultiVersionProtocolEngineFactory(
+ _broker, supported, defaultSupportedProtocolReply);
+
+ _transport.accept(settings, protocolEngineFactory, sslContext);
+ CurrentActor.get().message(BrokerMessages.LISTENING(getTransports().toString(), getPort()));
+ }
+
+ @Override
+ protected void onStop()
+ {
+ if (_transport != null)
+ {
+ CurrentActor.get().message(BrokerMessages.SHUTTING_DOWN(getTransports().toString(), getPort()));
+ _transport.close();
+ }
+ }
+
+ private Set<AmqpProtocolVersion> convertFromModelProtocolsToAmqp(Collection<Protocol> modelProtocols)
+ {
+ Set<AmqpProtocolVersion> amqpProtocols = new HashSet<AmqpProtocolVersion>();
+ for (Protocol protocol : modelProtocols)
+ {
+ amqpProtocols.add(protocol.toAmqpProtocolVersion());
+ }
+ return amqpProtocols;
+ }
+
+ private SSLContext createSslContext()
+ {
+ KeyStore keyStore = _broker.getDefaultKeyStore();
+ if (keyStore == null)
+ {
+ throw new IllegalConfigurationException("SSL was requested on AMQP port '"
+ + this.getName() + "' but no key store defined");
+ }
+
+ TrustStore trustStore = _broker.getDefaultTrustStore();
+ if (((Boolean)getAttribute(NEED_CLIENT_AUTH) || (Boolean)getAttribute(WANT_CLIENT_AUTH)) && trustStore == null)
+ {
+ throw new IllegalConfigurationException("Client certificate authentication is enabled on AMQP port '"
+ + this.getName() + "' but no trust store defined");
+ }
+
+ String keystorePath = (String)keyStore.getAttribute(KeyStore.PATH);
+ String keystorePassword = keyStore.getPassword();
+ String keystoreType = (String)keyStore.getAttribute(KeyStore.TYPE);
+ String keyManagerFactoryAlgorithm = (String)keyStore.getAttribute(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM);
+ String certAlias = (String)keyStore.getAttribute(KeyStore.CERTIFICATE_ALIAS);
+
+ final SSLContext sslContext;
+ try
+ {
+ if(trustStore != null)
+ {
+ String trustStorePassword = trustStore.getPassword();
+ String trustStoreType = (String)trustStore.getAttribute(TrustStore.TYPE);
+ String trustManagerFactoryAlgorithm = (String)trustStore.getAttribute(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM);
+ String trustStorePath = (String)trustStore.getAttribute(TrustStore.PATH);
+
+ sslContext = SSLContextFactory.buildClientContext(trustStorePath,
+ trustStorePassword,
+ trustStoreType,
+ trustManagerFactoryAlgorithm,
+ keystorePath,
+ keystorePassword, keystoreType, keyManagerFactoryAlgorithm,
+ certAlias);
+ }
+ else
+ {
+ sslContext = SSLContextFactory.buildServerContext(keystorePath, keystorePassword, keystoreType, keyManagerFactoryAlgorithm);
+ }
+ }
+ catch (GeneralSecurityException e)
+ {
+ throw new RuntimeException("Unable to create SSLContext for key or trust store", e);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable to create SSLContext - unable to load key/trust store", e);
+ }
+ return sslContext;
+ }
+
+ private AmqpProtocolVersion getDefaultAmqpSupportedReply()
+ {
+ String defaultAmqpSupportedReply = System.getProperty(BrokerProperties.PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY);
+ if (defaultAmqpSupportedReply != null)
+ {
+ return AmqpProtocolVersion.valueOf(defaultAmqpSupportedReply);
+ }
+ return null;
+ }
+
+
+ class ServerNetworkTransportConfiguration implements NetworkTransportConfiguration
+ {
+ private final InetSocketAddress _bindingSocketAddress;
+ private final Boolean _tcpNoDelay;
+ private final Integer _sendBufferSize;
+ private final Integer _receiveBufferSize;
+ private final boolean _needClientAuth;
+ private final boolean _wantClientAuth;
+
+ public ServerNetworkTransportConfiguration(
+ InetSocketAddress bindingSocketAddress, boolean tcpNoDelay,
+ int sendBufferSize, int receiveBufferSize,
+ boolean needClientAuth, boolean wantClientAuth)
+ {
+ _bindingSocketAddress = bindingSocketAddress;
+ _tcpNoDelay = tcpNoDelay;
+ _sendBufferSize = sendBufferSize;
+ _receiveBufferSize = receiveBufferSize;
+ _needClientAuth = needClientAuth;
+ _wantClientAuth = wantClientAuth;
+ }
+
+ @Override
+ public boolean wantClientAuth()
+ {
+ return _wantClientAuth;
+ }
+
+ @Override
+ public boolean needClientAuth()
+ {
+ return _needClientAuth;
+ }
+
+ @Override
+ public Boolean getTcpNoDelay()
+ {
+ return _tcpNoDelay;
+ }
+
+ @Override
+ public Integer getSendBufferSize()
+ {
+ return _sendBufferSize;
+ }
+
+ @Override
+ public Integer getReceiveBufferSize()
+ {
+ return _receiveBufferSize;
+ }
+
+ @Override
+ public InetSocketAddress getAddress()
+ {
+ return _bindingSocketAddress;
+ }
+ };
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java
index 8c2bc98ba7..ac4b0255d5 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderAdapter.java
@@ -29,38 +29,50 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
import javax.security.auth.login.AccountNotFoundException;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.model.*;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.IllegalStateTransitionException;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.Statistics;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.model.User;
+import org.apache.qpid.server.model.VirtualHostAlias;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.security.SecurityManager;
public abstract class AuthenticationProviderAdapter<T extends AuthenticationManager> extends AbstractAdapter implements AuthenticationProvider
{
private static final Logger LOGGER = Logger.getLogger(AuthenticationProviderAdapter.class);
- private final BrokerAdapter _broker;
private final T _authManager;
+ protected final Broker _broker;
- private AuthenticationProviderAdapter(BrokerAdapter brokerAdapter,
- final T authManager)
- {
- super(UUIDGenerator.generateRandomUUID());
- _broker = brokerAdapter;
- _authManager = authManager;
- }
+ private GroupPrincipalAccessor _groupAccessor;
- public static AuthenticationProviderAdapter createAuthenticationProviderAdapter(BrokerAdapter brokerAdapter,
- final AuthenticationManager authManager)
+ private Object _type;
+
+ private AuthenticationProviderAdapter(UUID id, Broker broker, final T authManager, Map<String, Object> attributes)
{
- return authManager instanceof PrincipalDatabaseAuthenticationManager
- ? new PrincipalDatabaseAuthenticationManagerAdapter(brokerAdapter, (PrincipalDatabaseAuthenticationManager) authManager)
- : new SimpleAuthenticationProviderAdapter(brokerAdapter, authManager);
+ super(id, null, attributes, broker.getTaskExecutor());
+ _authManager = authManager;
+ _broker = broker;
+ _type = authManager instanceof PrincipalDatabaseAuthenticationManager? PrincipalDatabaseAuthenticationManager.class.getSimpleName() : AuthenticationManager.class.getSimpleName() ;
+ addParent(Broker.class, broker);
}
T getAuthManager()
@@ -77,7 +89,7 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
@Override
public String getName()
{
- return _authManager.getClass().getSimpleName();
+ return (String)getAttribute(AuthenticationProvider.NAME);
}
@Override
@@ -147,7 +159,7 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
{
if(TYPE.equals(name))
{
- return _authManager.getClass().getSimpleName();
+ return _type;
}
else if(CREATED.equals(name))
{
@@ -165,10 +177,6 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
{
return LifetimePolicy.PERMANENT;
}
- else if(NAME.equals(name))
- {
- return getName();
- }
else if(STATE.equals(name))
{
return State.ACTIVE; // TODO
@@ -191,44 +199,86 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass,
- Map<String, Object> attributes,
- ConfiguredObject... otherParents)
+ public boolean setState(State currentState, State desiredState)
+ throws IllegalStateTransitionException, AccessControlException
{
- return null;
+ if(desiredState == State.DELETED)
+ {
+ return true;
+ }
+ else if(desiredState == State.ACTIVE)
+ {
+ if (_groupAccessor == null)
+ {
+ throw new IllegalStateTransitionException("Cannot transit into ACTIVE state with null group accessor!");
+ }
+ _authManager.initialise();
+ return true;
+ }
+ else if(desiredState == State.STOPPED)
+ {
+ _authManager.close();
+ return true;
+ }
+ return false;
}
- private static class SimpleAuthenticationProviderAdapter extends AuthenticationProviderAdapter<AuthenticationManager>
+ @Override
+ public SubjectCreator getSubjectCreator()
{
+ return new SubjectCreator(_authManager, _groupAccessor);
+ }
+
+ public void setGroupAccessor(GroupPrincipalAccessor groupAccessor)
+ {
+ _groupAccessor = groupAccessor;
+ }
+
+ public static class SimpleAuthenticationProviderAdapter extends AuthenticationProviderAdapter<AuthenticationManager>
+ {
+
public SimpleAuthenticationProviderAdapter(
- BrokerAdapter brokerAdapter, AuthenticationManager authManager)
+ UUID id, Broker broker, AuthenticationManager authManager, Map<String, Object> attributes)
+ {
+ super(id, broker,authManager, attributes);
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C createChild(Class<C> childClass,
+ Map<String, Object> attributes,
+ ConfiguredObject... otherParents)
{
- super(brokerAdapter,authManager);
+ throw new UnsupportedOperationException();
}
}
- private static class PrincipalDatabaseAuthenticationManagerAdapter
+ public static class PrincipalDatabaseAuthenticationManagerAdapter
extends AuthenticationProviderAdapter<PrincipalDatabaseAuthenticationManager>
implements PasswordCredentialManagingAuthenticationProvider
{
public PrincipalDatabaseAuthenticationManagerAdapter(
- BrokerAdapter brokerAdapter, PrincipalDatabaseAuthenticationManager authManager)
+ UUID id, Broker broker, PrincipalDatabaseAuthenticationManager authManager, Map<String, Object> attributes)
{
- super(brokerAdapter, authManager);
+ super(id, broker, authManager, attributes);
}
@Override
public boolean createUser(String username, String password, Map<String, String> attributes)
{
- return getPrincipalDatabase().createPrincipal(new UsernamePrincipal(username), password.toCharArray());
+ if(getSecurityManager().authoriseUserOperation(Operation.CREATE, username))
+ {
+ return getPrincipalDatabase().createPrincipal(new UsernamePrincipal(username), password.toCharArray());
+ }
+ else
+ {
+ throw new AccessControlException("Do not have permission to create new user");
+ }
}
@Override
public void deleteUser(String username) throws AccountNotFoundException
{
- if(getSecurityManager().authoriseMethod(Operation.DELETE,
- "UserManagement",
- "deleteUser"))
+ if(getSecurityManager().authoriseUserOperation(Operation.DELETE, username))
{
getPrincipalDatabase().deletePrincipal(new UsernamePrincipal(username));
@@ -239,9 +289,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
}
}
- private org.apache.qpid.server.security.SecurityManager getSecurityManager()
+ private SecurityManager getSecurityManager()
{
- return ApplicationRegistry.getInstance().getSecurityManager();
+ return _broker.getSecurityManager();
}
private PrincipalDatabase getPrincipalDatabase()
@@ -252,18 +302,13 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
@Override
public void setPassword(String username, String password) throws AccountNotFoundException
{
- getPrincipalDatabase().updatePassword(new UsernamePrincipal(username), password.toCharArray());
- }
-
- public void reload() throws IOException
- {
- if(getSecurityManager().authoriseMethod(Operation.UPDATE, "UserManagement", "reload"))
+ if(getSecurityManager().authoriseUserOperation(Operation.UPDATE, username))
{
- getPrincipalDatabase().reload();
+ getPrincipalDatabase().updatePassword(new UsernamePrincipal(username), password.toCharArray());
}
else
{
- throw new AccessControlException("Do not have permission to reload principal database");
+ throw new AccessControlException("Do not have permission to set password");
}
}
@@ -274,34 +319,41 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
Map<String, Map<String,String>> users = new HashMap<String, Map<String, String>>();
for(Principal principal : getPrincipalDatabase().getUsers())
{
- users.put(principal.getName(), Collections.EMPTY_MAP);
+ users.put(principal.getName(), Collections.<String, String>emptyMap());
}
return users;
}
+ public void reload() throws IOException
+ {
+ getPrincipalDatabase().reload();
+ }
+
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass,
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass,
Map<String, Object> attributes,
ConfiguredObject... otherParents)
{
if(childClass == User.class)
{
- Principal p = new UsernamePrincipal((String) attributes.get("name"));
- if(getSecurityManager().authoriseMethod(Operation.UPDATE, "UserManagement", "createUser"))
+ String username = (String) attributes.get("name");
+ String password = (String) attributes.get("password");
+ Principal p = new UsernamePrincipal(username);
+
+ if(createUser(username, password,null))
{
- if(getPrincipalDatabase().createPrincipal(p, ((String)attributes.get("password")).toCharArray()))
- {
- return (C) new PrincipalAdapter(p);
- }
+ @SuppressWarnings("unchecked")
+ C pricipalAdapter = (C) new PrincipalAdapter(p, getTaskExecutor());
+ return pricipalAdapter;
}
else
{
- throw new AccessControlException("Do not have permission to create a new user");
+ //TODO? Silly interface on the PrincipalDatabase at fault
+ throw new RuntimeException("Failed to create user");
}
-
}
- return super.createChild(childClass, attributes, otherParents);
+ return super.addChild(childClass, attributes, otherParents);
}
@Override
@@ -313,9 +365,11 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
Collection<User> principals = new ArrayList<User>(users.size());
for(Principal user : users)
{
- principals.add(new PrincipalAdapter(user));
+ principals.add(new PrincipalAdapter(user, getTaskExecutor()));
}
- return (Collection<C>) Collections.unmodifiableCollection(principals);
+ @SuppressWarnings("unchecked")
+ Collection<C> unmodifiablePrincipals = (Collection<C>) Collections.unmodifiableCollection(principals);
+ return unmodifiablePrincipals;
}
else
{
@@ -328,20 +382,14 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
private final Principal _user;
- public PrincipalAdapter(Principal user)
+ public PrincipalAdapter(Principal user, TaskExecutor taskExecutor)
{
- super(UUIDGenerator.generateUserUUID(PrincipalDatabaseAuthenticationManagerAdapter.this.getName(), user.getName()));
+ super(UUIDGenerator.generateUserUUID(PrincipalDatabaseAuthenticationManagerAdapter.this.getName(), user.getName()), taskExecutor);
_user = user;
}
@Override
- public String getPassword()
- {
- return null;
- }
-
- @Override
public void setPassword(String password)
{
try
@@ -445,6 +493,10 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
{
return getId();
}
+ else if(PASSWORD.equals(name))
+ {
+ return null; // for security reasons we don't expose the password
+ }
else if(NAME.equals(name))
{
return getName();
@@ -453,20 +505,19 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
+ public boolean changeAttribute(String name, Object expected, Object desired)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
if(name.equals(PASSWORD))
{
setPassword((String)desired);
+ return true;
}
- return super.setAttribute(name,
- expected,
- desired);
+ return super.changeAttribute(name, expected, desired);
}
@Override
- public State setDesiredState(State currentState, State desiredState)
+ protected boolean setState(State currentState, State desiredState)
throws IllegalStateTransitionException, AccessControlException
{
if(desiredState == State.DELETED)
@@ -479,9 +530,9 @@ public abstract class AuthenticationProviderAdapter<T extends AuthenticationMana
{
LOGGER.warn("Failed to delete user " + _user, e);
}
- return State.DELETED;
+ return true;
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.java
new file mode 100644
index 0000000000..e5108ebbcf
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactory.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.server.model.adapter;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderAdapter.PrincipalDatabaseAuthenticationManagerAdapter;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderAdapter.SimpleAuthenticationProviderAdapter;
+
+public class AuthenticationProviderFactory
+{
+ private final Iterable<AuthenticationManagerFactory> _factories;
+
+ public AuthenticationProviderFactory(QpidServiceLoader<AuthenticationManagerFactory> authManagerFactoryServiceLoader)
+ {
+ _factories = authManagerFactoryServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class);
+ }
+
+ /**
+ * Creates {@link AuthenticationProvider} for given ID, {@link Broker} and attributes.
+ * <p>
+ * The configured {@link AuthenticationManagerFactory}'s are used to try to create the {@link AuthenticationProvider}.
+ * The first non-null instance is returned. The factories are used in non-deterministic order.
+ * @param groupPrincipalAccessor TODO
+ */
+ public AuthenticationProvider create(UUID id, Broker broker, Map<String, Object> attributes, GroupPrincipalAccessor groupPrincipalAccessor)
+ {
+ for (AuthenticationManagerFactory factory : _factories)
+ {
+ AuthenticationManager manager = factory.createInstance(attributes);
+ if (manager != null)
+ {
+ AuthenticationProviderAdapter<?> authenticationProvider;
+ if (manager instanceof PrincipalDatabaseAuthenticationManager)
+ {
+ authenticationProvider = new PrincipalDatabaseAuthenticationManagerAdapter(id, broker,
+ (PrincipalDatabaseAuthenticationManager) manager, attributes);
+ }
+ else
+ {
+ authenticationProvider = new SimpleAuthenticationProviderAdapter(id, broker, manager, attributes);
+ }
+ authenticationProvider.setGroupAccessor(groupPrincipalAccessor);
+ return authenticationProvider;
+ }
+ }
+
+ throw new IllegalArgumentException("No authentication provider factory found for configuration attributes " + attributes);
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java
index abd3160686..eb2d0dd7e2 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BindingAdapter.java
@@ -48,7 +48,7 @@ final class BindingAdapter extends AbstractAdapter implements Binding
ExchangeAdapter exchangeAdapter,
QueueAdapter queueAdapter)
{
- super(binding.getId());
+ super(binding.getId(), queueAdapter.getTaskExecutor());
_binding = binding;
_exchange = exchangeAdapter;
_queue = queueAdapter;
@@ -206,27 +206,20 @@ final class BindingAdapter extends AbstractAdapter implements Binding
}
@Override
- public Object setAttribute(final String name, final Object expected, final Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO
- }
-
- @Override
public Collection<String> getAttributeNames()
{
return Binding.AVAILABLE_ATTRIBUTES;
}
@Override
- public State setDesiredState(State currentState, State desiredState) throws IllegalStateTransitionException,
+ protected boolean setState(State currentState, State desiredState) throws IllegalStateTransitionException,
AccessControlException
{
if (desiredState == State.DELETED)
{
delete();
- return State.DELETED;
+ return true;
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
index f1cce2d45c..533ecfe937 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
@@ -21,82 +21,211 @@
package org.apache.qpid.server.model.adapter;
import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
+import javax.net.ssl.KeyManagerFactory;
+
+import org.apache.log4j.Logger;
import org.apache.qpid.common.QpidProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.actors.BrokerActor;
+import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.model.AuthenticationProvider;
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.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Plugin;
import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
-import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.TrustStore;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry;
-import org.apache.qpid.server.transport.QpidAcceptor;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.group.FileGroupManager;
+import org.apache.qpid.server.security.group.GroupManager;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.util.MapValueConverter;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHostRegistry.RegistryChangeListener,
- IApplicationRegistry.PortBindingListener,
- IAuthenticationManagerRegistry.RegistryChangeListener
+public class BrokerAdapter extends AbstractAdapter implements Broker, ConfigurationChangeListener
{
-
- private final IApplicationRegistry _applicationRegistry;
- private String _name;
- private final Map<org.apache.qpid.server.virtualhost.VirtualHost, VirtualHostAdapter> _vhostAdapters =
- new HashMap<org.apache.qpid.server.virtualhost.VirtualHost, VirtualHostAdapter>();
- private final StatisticsAdapter _statistics;
- private final Map<QpidAcceptor, PortAdapter> _portAdapters = new HashMap<QpidAcceptor, PortAdapter>();
- private Collection<HTTPPortAdapter> _httpManagementPorts;
-
- private final Map<AuthenticationManager, AuthenticationProviderAdapter> _authManagerAdapters =
- new HashMap<AuthenticationManager, AuthenticationProviderAdapter>();
-
-
- public BrokerAdapter(final IApplicationRegistry instance)
- {
- super(UUIDGenerator.generateRandomUUID());
- _applicationRegistry = instance;
- _name = "Broker";
- _statistics = new StatisticsAdapter(instance);
-
- instance.getVirtualHostRegistry().addRegistryChangeListener(this);
- populateVhosts();
- instance.addPortBindingListener(this);
- populatePorts();
- instance.addRegistryChangeListener(this);
- populateAuthenticationManagers();
- }
-
- private void populateVhosts()
- {
- synchronized(_vhostAdapters)
- {
- Collection<org.apache.qpid.server.virtualhost.VirtualHost> actualVhosts =
- _applicationRegistry.getVirtualHostRegistry().getVirtualHosts();
- for(org.apache.qpid.server.virtualhost.VirtualHost vh : actualVhosts)
- {
- if(!_vhostAdapters.containsKey(vh))
- {
- _vhostAdapters.put(vh, new VirtualHostAdapter(this, vh));
- }
- }
-
+ private static final Logger LOGGER = Logger.getLogger(BrokerAdapter.class);
+
+ @SuppressWarnings("serial")
+ public static final Map<String, Class<?>> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Class<?>>(){{
+ put(ALERT_THRESHOLD_MESSAGE_AGE, Long.class);
+ put(ALERT_THRESHOLD_MESSAGE_COUNT, Long.class);
+ put(ALERT_THRESHOLD_QUEUE_DEPTH, Long.class);
+ put(ALERT_THRESHOLD_MESSAGE_SIZE, Long.class);
+ put(ALERT_REPEAT_GAP, Long.class);
+ put(FLOW_CONTROL_SIZE_BYTES, Long.class);
+ put(FLOW_CONTROL_RESUME_SIZE_BYTES, Long.class);
+ put(HOUSEKEEPING_CHECK_PERIOD, Long.class);
+
+ put(DEAD_LETTER_QUEUE_ENABLED, Boolean.class);
+ put(STATISTICS_REPORTING_RESET_ENABLED, Boolean.class);
+
+ put(MAXIMUM_DELIVERY_ATTEMPTS, Integer.class);
+ put(SESSION_COUNT_LIMIT, Integer.class);
+ put(HEART_BEAT_DELAY, Integer.class);
+ put(STATISTICS_REPORTING_PERIOD, Integer.class);
+
+ put(ACL_FILE, String.class);
+ put(NAME, String.class);
+ put(DEFAULT_VIRTUAL_HOST, String.class);
+ put(DEFAULT_AUTHENTICATION_PROVIDER, String.class);
+
+ put(KEY_STORE_PATH, String.class);
+ put(KEY_STORE_PASSWORD, String.class);
+ put(KEY_STORE_CERT_ALIAS, String.class);
+ put(TRUST_STORE_PATH, String.class);
+ put(TRUST_STORE_PASSWORD, String.class);
+ put(GROUP_FILE, String.class);
+ }});
+
+ public static final int DEFAULT_STATISTICS_REPORTING_PERIOD = 0;
+ public static final boolean DEFAULT_STATISTICS_REPORTING_RESET_ENABLED = false;
+ public static final long DEFAULT_ALERT_REPEAT_GAP = 30000l;
+ public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_AGE = 0l;
+ public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_COUNT = 0l;
+ public static final long DEFAULT_ALERT_THRESHOLD_MESSAGE_SIZE = 0l;
+ public static final long DEFAULT_ALERT_THRESHOLD_QUEUE_DEPTH = 0l;
+ public static final boolean DEFAULT_DEAD_LETTER_QUEUE_ENABLED = false;
+ public static final int DEFAULT_MAXIMUM_DELIVERY_ATTEMPTS = 0;
+ public static final long DEFAULT_FLOW_CONTROL_RESUME_SIZE_BYTES = 0l;
+ public static final long DEFAULT_FLOW_CONTROL_SIZE_BYTES = 0l;
+ public static final long DEFAULT_HOUSEKEEPING_CHECK_PERIOD = 30000l;
+ public static final int DEFAULT_HEART_BEAT_DELAY = 0;
+ public static final int DEFAULT_SESSION_COUNT_LIMIT = 256;
+ public static final String DEFAULT_NAME = "QpidBroker";
+ private static final String DEFAULT_KEY_STORE_NAME = "defaultKeyStore";
+ private static final String DEFAULT_TRUST_STORE_NAME = "defaultTrustStore";
+ private static final String DEFAULT_GROUP_PROFIDER_NAME = "defaultGroupProvider";
+
+ private static final String DUMMY_PASSWORD_MASK = "********";
+
+ @SuppressWarnings("serial")
+ private static final Map<String, Object> DEFAULTS = Collections.unmodifiableMap(new HashMap<String, Object>(){{
+ put(Broker.STATISTICS_REPORTING_PERIOD, DEFAULT_STATISTICS_REPORTING_PERIOD);
+ put(Broker.STATISTICS_REPORTING_RESET_ENABLED, DEFAULT_STATISTICS_REPORTING_RESET_ENABLED);
+ put(Broker.ALERT_REPEAT_GAP, DEFAULT_ALERT_REPEAT_GAP);
+ put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, DEFAULT_ALERT_THRESHOLD_MESSAGE_AGE);
+ put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, DEFAULT_ALERT_THRESHOLD_MESSAGE_COUNT);
+ put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, DEFAULT_ALERT_THRESHOLD_MESSAGE_SIZE);
+ put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, DEFAULT_ALERT_THRESHOLD_QUEUE_DEPTH);
+ put(Broker.DEAD_LETTER_QUEUE_ENABLED, DEFAULT_DEAD_LETTER_QUEUE_ENABLED);
+ put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, DEFAULT_MAXIMUM_DELIVERY_ATTEMPTS);
+ put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, DEFAULT_FLOW_CONTROL_RESUME_SIZE_BYTES);
+ put(Broker.FLOW_CONTROL_SIZE_BYTES, DEFAULT_FLOW_CONTROL_SIZE_BYTES);
+ put(Broker.HOUSEKEEPING_CHECK_PERIOD, DEFAULT_HOUSEKEEPING_CHECK_PERIOD);
+ put(Broker.HEART_BEAT_DELAY, DEFAULT_HEART_BEAT_DELAY);
+ put(Broker.SESSION_COUNT_LIMIT, DEFAULT_SESSION_COUNT_LIMIT);
+ put(Broker.NAME, DEFAULT_NAME);
+ }});
+
+
+
+
+ private final StatisticsGatherer _statisticsGatherer;
+ private final VirtualHostRegistry _virtualHostRegistry;
+ private final LogRecorder _logRecorder;
+ private final RootMessageLogger _rootMessageLogger;
+ private StatisticsAdapter _statistics;
+
+ private final Map<String, VirtualHost> _vhostAdapters = new HashMap<String, VirtualHost>();
+ private final Map<Integer, Port> _portAdapters = new HashMap<Integer, Port>();
+ private final Map<String, AuthenticationProvider> _authenticationProviders = new HashMap<String, AuthenticationProvider>();
+ private final Map<String, GroupProvider> _groupProviders = new HashMap<String, GroupProvider>();
+ private final Map<UUID, ConfiguredObject> _plugins = new HashMap<UUID, ConfiguredObject>();
+ private final Map<UUID, KeyStore> _keyStores = new HashMap<UUID, KeyStore>();
+ private final Map<UUID, TrustStore> _trustStores = new HashMap<UUID, TrustStore>();
+
+ private final AuthenticationProviderFactory _authenticationProviderFactory;
+ private AuthenticationProvider _defaultAuthenticationProvider;
+
+ private final PortFactory _portFactory;
+ private final SecurityManager _securityManager;
+ private final UUID _defaultKeyStoreId;
+ private final UUID _defaultTrustStoreId;
+
+ public BrokerAdapter(UUID id, Map<String, Object> attributes, StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry,
+ LogRecorder logRecorder, RootMessageLogger rootMessageLogger, AuthenticationProviderFactory authenticationProviderFactory,
+ PortFactory portFactory, TaskExecutor taskExecutor)
+ {
+ super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor);
+ _statisticsGatherer = statisticsGatherer;
+ _virtualHostRegistry = virtualHostRegistry;
+ _logRecorder = logRecorder;
+ _rootMessageLogger = rootMessageLogger;
+ _statistics = new StatisticsAdapter(statisticsGatherer);
+ _authenticationProviderFactory = authenticationProviderFactory;
+ _portFactory = portFactory;
+ _securityManager = new SecurityManager((String)getAttribute(ACL_FILE));
+
+ _defaultKeyStoreId = UUIDGenerator.generateBrokerChildUUID(KeyStore.class.getSimpleName(), DEFAULT_KEY_STORE_NAME);
+ _defaultTrustStoreId = UUIDGenerator.generateBrokerChildUUID(TrustStore.class.getSimpleName(), DEFAULT_TRUST_STORE_NAME);
+ createBrokerChildrenFromAttributes();
+ }
+
+ /*
+ * A temporary method to create broker children that can be only configured via broker attributes
+ */
+ private void createBrokerChildrenFromAttributes()
+ {
+ String groupFile = (String) getAttribute(GROUP_FILE);
+ if (groupFile != null)
+ {
+ GroupManager groupManager = new FileGroupManager(groupFile);
+ UUID groupProviderId = UUIDGenerator.generateBrokerChildUUID(GroupProvider.class.getSimpleName(),
+ DEFAULT_GROUP_PROFIDER_NAME);
+ GroupProviderAdapter groupProviderAdapter = new GroupProviderAdapter(groupProviderId, groupManager, this);
+ addGroupProvider(groupProviderAdapter);
+ }
+ Map<String, Object> actualAttributes = getActualAttributes();
+ String keyStorePath = (String) getAttribute(KEY_STORE_PATH);
+ if (keyStorePath != null)
+ {
+ Map<String, Object> keyStoreAttributes = new HashMap<String, Object>();
+ keyStoreAttributes.put(KeyStore.NAME, DEFAULT_KEY_STORE_NAME);
+ keyStoreAttributes.put(KeyStore.PATH, keyStorePath);
+ keyStoreAttributes.put(KeyStore.PASSWORD, (String) actualAttributes.get(KEY_STORE_PASSWORD));
+ keyStoreAttributes.put(KeyStore.TYPE, java.security.KeyStore.getDefaultType());
+ keyStoreAttributes.put(KeyStore.CERTIFICATE_ALIAS, getAttribute(KEY_STORE_CERT_ALIAS));
+ keyStoreAttributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, KeyManagerFactory.getDefaultAlgorithm());
+ KeyStoreAdapter KeyStoreAdapter = new KeyStoreAdapter(_defaultKeyStoreId, this, keyStoreAttributes);
+ addKeyStore(KeyStoreAdapter);
+ }
+ String trustStorePath = (String) getAttribute(TRUST_STORE_PATH);
+ if (trustStorePath != null)
+ {
+ Map<String, Object> trsustStoreAttributes = new HashMap<String, Object>();
+ trsustStoreAttributes.put(TrustStore.NAME, DEFAULT_TRUST_STORE_NAME);
+ trsustStoreAttributes.put(TrustStore.PATH, trustStorePath);
+ trsustStoreAttributes.put(TrustStore.PASSWORD, (String) actualAttributes.get(TRUST_STORE_PASSWORD));
+ trsustStoreAttributes.put(TrustStore.TYPE, java.security.KeyStore.getDefaultType());
+ trsustStoreAttributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, KeyManagerFactory.getDefaultAlgorithm());
+ TrustStoreAdapter trustStore = new TrustStoreAdapter(_defaultTrustStoreId, this, trsustStoreAttributes);
+ addTrustStore(trustStore);
}
}
-
public Collection<VirtualHost> getVirtualHosts()
{
synchronized(_vhostAdapters)
@@ -105,81 +234,57 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
}
}
- private void populatePorts()
+
+ public Collection<Port> getPorts()
{
synchronized (_portAdapters)
{
- Map<InetSocketAddress, QpidAcceptor> acceptors = _applicationRegistry.getAcceptors();
-
- for(Map.Entry<InetSocketAddress, QpidAcceptor> entry : acceptors.entrySet())
- {
- if(!_portAdapters.containsKey(entry.getValue()))
- {
- _portAdapters.put(entry.getValue(), new PortAdapter(this, entry.getValue(), entry.getKey()));
- }
- }
- if(_applicationRegistry.useHTTPManagement() || _applicationRegistry.useHTTPSManagement())
- {
- ArrayList<HTTPPortAdapter> httpPorts = new ArrayList<HTTPPortAdapter>();
- if (_applicationRegistry.useHTTPManagement())
- {
- httpPorts.add(new HTTPPortAdapter(this, _applicationRegistry.getHTTPManagementPort()));
- }
- if (_applicationRegistry.useHTTPSManagement())
- {
- httpPorts.add(new HTTPPortAdapter(this, _applicationRegistry.getHTTPSManagementPort(), Protocol.HTTPS, Transport.SSL));
- }
- _httpManagementPorts = Collections.unmodifiableCollection(httpPorts);
- }
+ final ArrayList<Port> ports = new ArrayList<Port>(_portAdapters.values());
+ return ports;
}
}
- public Collection<Port> getPorts()
+ public Collection<AuthenticationProvider> getAuthenticationProviders()
{
- synchronized (_portAdapters)
+ synchronized (_authenticationProviders)
{
- final ArrayList<Port> ports = new ArrayList<Port>(_portAdapters.values());
- if(_httpManagementPorts != null)
- {
- ports.addAll(_httpManagementPorts);
- }
- return ports;
+ return new ArrayList<AuthenticationProvider>(_authenticationProviders.values());
}
}
- private void populateAuthenticationManagers()
+ public AuthenticationProvider getAuthenticationProviderByName(String authenticationProviderName)
{
- synchronized (_authManagerAdapters)
+ Collection<AuthenticationProvider> providers = getAuthenticationProviders();
+ for (AuthenticationProvider authenticationProvider : providers)
{
- IAuthenticationManagerRegistry authenticationManagerRegistry =
- _applicationRegistry.getAuthenticationManagerRegistry();
- if(authenticationManagerRegistry != null)
+ if (authenticationProvider.getName().equals(authenticationProviderName))
{
- Map<String, AuthenticationManager> authenticationManagers =
- authenticationManagerRegistry.getAvailableAuthenticationManagers();
-
- for(Map.Entry<String, AuthenticationManager> entry : authenticationManagers.entrySet())
- {
- if(!_authManagerAdapters.containsKey(entry.getValue()))
- {
- _authManagerAdapters.put(entry.getValue(),
- AuthenticationProviderAdapter.createAuthenticationProviderAdapter(this,
- entry.getValue()));
- }
- }
+ return authenticationProvider;
}
}
+ return null;
}
- public Collection<AuthenticationProvider> getAuthenticationProviders()
+ @Override
+ public AuthenticationProvider getDefaultAuthenticationProvider()
+ {
+ return _defaultAuthenticationProvider;
+ }
+
+ public void setDefaultAuthenticationProvider(AuthenticationProvider provider)
+ {
+ _defaultAuthenticationProvider = provider;
+ }
+
+ @Override
+ public Collection<GroupProvider> getGroupProviders()
{
- synchronized (_authManagerAdapters)
+ synchronized (_groupProviders)
{
- final ArrayList<AuthenticationProvider> authManagers =
- new ArrayList<AuthenticationProvider>(_authManagerAdapters.values());
- return authManagers;
+ final ArrayList<GroupProvider> groupManagers =
+ new ArrayList<GroupProvider>(_groupProviders.values());
+ return groupManagers;
}
-
}
public VirtualHost createVirtualHost(final String name,
@@ -193,22 +298,29 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
return null; //TODO
}
- public VirtualHost createVirtualHost(final Map<String, Object> attributes)
+ private VirtualHost createVirtualHost(final Map<String, Object> attributes)
throws AccessControlException, IllegalArgumentException
{
- return null; //TODO
+ final VirtualHostAdapter virtualHostAdapter = new VirtualHostAdapter(UUID.randomUUID(), attributes, this,
+ _statisticsGatherer, getTaskExecutor());
+ addVirtualHost(virtualHostAdapter);
+ virtualHostAdapter.setDesiredState(State.INITIALISING, State.ACTIVE);
+ return virtualHostAdapter;
}
- public void deleteVirtualHost(final VirtualHost vhost)
- throws AccessControlException, IllegalStateException
+ private boolean deleteVirtualHost(final VirtualHost vhost) throws AccessControlException, IllegalStateException
{
- //TODO
- throw new UnsupportedOperationException("Not yet implemented");
+ synchronized (_vhostAdapters)
+ {
+ _vhostAdapters.remove(vhost);
+ }
+ vhost.removeChangeListener(this);
+ return true;
}
public String getName()
{
- return _name;
+ return (String)getAttribute(NAME);
}
public String setName(final String currentName, final String desiredName)
@@ -262,6 +374,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
return _statistics;
}
+ @SuppressWarnings("unchecked")
@Override
public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
{
@@ -277,12 +390,30 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
{
return (Collection<C>) getAuthenticationProviders();
}
+ else if(clazz == GroupProvider.class)
+ {
+ return (Collection<C>) getGroupProviders();
+ }
+ else if(clazz == KeyStore.class)
+ {
+ return (Collection<C>) getKeyStores();
+ }
+ else if(clazz == TrustStore.class)
+ {
+ return (Collection<C>) getTrustStores();
+ }
+ else if(clazz == Plugin.class)
+ {
+ return (Collection<C>) getPlugins();
+ }
return Collections.emptySet();
}
+ //TODO: ACL
+ @SuppressWarnings("unchecked")
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == VirtualHost.class)
{
@@ -302,111 +433,107 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
}
}
- private Port createPort(Map<String, Object> attributes)
+ private void addPort(Port port)
{
- // TODO
- return null;
+ synchronized (_portAdapters)
+ {
+ int portNumber = port.getPort();
+ if(_portAdapters.containsKey(portNumber))
+ {
+ throw new IllegalArgumentException("Cannot add port " + port + " because port number " + portNumber + " already configured");
+ }
+ _portAdapters.put(portNumber, port);
+ }
+ port.addChangeListener(this);
}
- private AuthenticationProvider createAuthenticationProvider(Map<String,Object> attributes)
+ private Port createPort(Map<String, Object> attributes)
{
- // TODO
- return null;
+ Port port = _portFactory.createPort(UUID.randomUUID(), this, attributes);
+ addPort(port);
+ return port;
}
+ private AuthenticationProvider createAuthenticationProvider(Map<String, Object> attributes)
+ {
+ // it's cheap to create the groupPrincipalAccessor on the fly
+ GroupPrincipalAccessor groupPrincipalAccessor = new GroupPrincipalAccessor(_groupProviders.values());
+
+ AuthenticationProvider authenticationProvider = _authenticationProviderFactory.create(UUID.randomUUID(), this, attributes, groupPrincipalAccessor);
+ addAuthenticationProvider(authenticationProvider);
+ return authenticationProvider;
+ }
- public void virtualHostRegistered(org.apache.qpid.server.virtualhost.VirtualHost virtualHost)
+ /**
+ * @throws IllegalConfigurationException if an AuthenticationProvider with the same name already exists
+ */
+ private void addAuthenticationProvider(AuthenticationProvider authenticationProvider)
{
- VirtualHostAdapter adapter = null;
- synchronized (_vhostAdapters)
+ String name = authenticationProvider.getName();
+ synchronized (_authenticationProviders)
{
- if(!_vhostAdapters.containsKey(virtualHost))
+ if(_authenticationProviders.containsKey(name))
{
- adapter = new VirtualHostAdapter(this, virtualHost);
- _vhostAdapters.put(virtualHost, adapter);
+ throw new IllegalConfigurationException("Cannot add AuthenticationProvider because one with name " + name + " already exists");
}
+ _authenticationProviders.put(name, authenticationProvider);
}
- if(adapter != null)
- {
- childAdded(adapter);
- }
+ authenticationProvider.addChangeListener(this);
}
- public void virtualHostUnregistered(org.apache.qpid.server.virtualhost.VirtualHost virtualHost)
+ private void addGroupProvider(GroupProvider groupProvider)
{
- VirtualHostAdapter adapter = null;
-
- synchronized (_vhostAdapters)
- {
- adapter = _vhostAdapters.remove(virtualHost);
- }
- if(adapter != null)
+ synchronized (_groupProviders)
{
- childRemoved(adapter);
+ String name = groupProvider.getName();
+ if(_groupProviders.containsKey(name))
+ {
+ throw new IllegalConfigurationException("Cannot add GroupProvider because one with name " + name + " already exists");
+ }
+ _groupProviders.put(name, groupProvider);
}
+ groupProvider.addChangeListener(this);
}
- @Override
- public void authenticationManagerRegistered(AuthenticationManager authenticationManager)
+ private boolean deleteGroupProvider(GroupProvider object)
+ {
+ throw new UnsupportedOperationException("Not implemented yet!");
+ }
+
+ private void addKeyStore(KeyStore keyStore)
{
- AuthenticationProviderAdapter adapter = null;
- synchronized (_authManagerAdapters)
+ synchronized (_keyStores)
{
- if(!_authManagerAdapters.containsKey(authenticationManager))
+ if(_keyStores.containsKey(keyStore.getId()))
{
- adapter =
- AuthenticationProviderAdapter.createAuthenticationProviderAdapter(this, authenticationManager);
- _authManagerAdapters.put(authenticationManager, adapter);
+ throw new IllegalConfigurationException("Cannot add KeyStore because one with id " + keyStore.getId() + " already exists");
}
+ _keyStores.put(keyStore.getId(), keyStore);
}
- if(adapter != null)
- {
- childAdded(adapter);
- }
+ keyStore.addChangeListener(this);
}
- @Override
- public void authenticationManagerUnregistered(AuthenticationManager authenticationManager)
+ private boolean deleteKeyStore(KeyStore object)
{
- AuthenticationProviderAdapter adapter;
- synchronized (_authManagerAdapters)
- {
- adapter = _authManagerAdapters.remove(authenticationManager);
- }
- if(adapter != null)
- {
- childRemoved(adapter);
- }
+ throw new UnsupportedOperationException("Not implemented yet!");
}
-
- @Override
- public void bound(QpidAcceptor acceptor, InetSocketAddress bindAddress)
+ private void addTrustStore(TrustStore trustStore)
{
- synchronized (_portAdapters)
+ synchronized (_trustStores)
{
- if(!_portAdapters.containsKey(acceptor))
+ if(_trustStores.containsKey(trustStore.getId()))
{
- PortAdapter adapter = new PortAdapter(this, acceptor, bindAddress);
- _portAdapters.put(acceptor, adapter);
- childAdded(adapter);
+ throw new IllegalConfigurationException("Cannot add TrustStore because one with id " + trustStore.getId() + " already exists");
}
+ _trustStores.put(trustStore.getId(), trustStore);
}
+ trustStore.addChangeListener(this);
}
- @Override
- public void unbound(QpidAcceptor acceptor)
+ private boolean deleteTrustStore(TrustStore object)
{
- PortAdapter adapter = null;
-
- synchronized (_portAdapters)
- {
- adapter = _portAdapters.remove(acceptor);
- }
- if(adapter != null)
- {
- childRemoved(adapter);
- }
+ throw new UnsupportedOperationException("Not implemented yet!");
}
@Override
@@ -422,10 +549,6 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
{
return getId();
}
- else if(NAME.equals(name))
- {
- return getName();
- }
else if(STATE.equals(name))
{
return State.ACTIVE;
@@ -481,14 +604,316 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, VirtualHos
{
// TODO
}
+ else if (DEFAULT_AUTHENTICATION_PROVIDER.equals(name))
+ {
+ return _defaultAuthenticationProvider == null ? null : _defaultAuthenticationProvider.getName();
+ }
+ else if (KEY_STORE_PASSWORD.equals(name))
+ {
+ return DUMMY_PASSWORD_MASK;
+ }
+ else if (TRUST_STORE_PASSWORD.equals(name))
+ {
+ return DUMMY_PASSWORD_MASK;
+ }
+ return super.getAttribute(name);
+ }
- return super.getAttribute(name); //TODO - Implement.
+ private boolean deletePort(Port portAdapter)
+ {
+ Port removedPort = null;
+ synchronized (_portAdapters)
+ {
+ removedPort = _portAdapters.remove(portAdapter.getPort());
+ }
+ return removedPort != null;
+ }
+
+ private boolean deleteAuthenticationProvider(AuthenticationProvider authenticationProvider)
+ {
+ AuthenticationProvider removedAuthenticationProvider = null;
+ synchronized (_authenticationProviders)
+ {
+ removedAuthenticationProvider = _authenticationProviders.remove(authenticationProvider.getName());
+ }
+ return removedAuthenticationProvider != null;
+ }
+
+ private void addVirtualHost(VirtualHost virtualHost)
+ {
+ synchronized (_vhostAdapters)
+ {
+ String name = virtualHost.getName();
+ if (_vhostAdapters.containsKey(name))
+ {
+ throw new IllegalConfigurationException("Virtual host with name " + name + " is already specified!");
+ }
+ _vhostAdapters.put(name, virtualHost);
+ }
+ virtualHost.addChangeListener(this);
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
+ public boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.ACTIVE)
+ {
+ changeState(_groupProviders, currentState, State.ACTIVE, false);
+ changeState(_authenticationProviders, currentState, State.ACTIVE, false);
+
+ CurrentActor.set(new BrokerActor(getRootMessageLogger()));
+ try
+ {
+ changeState(_vhostAdapters, currentState, State.ACTIVE, false);
+ }
+ finally
+ {
+ CurrentActor.remove();
+ }
+
+ changeState(_portAdapters, currentState,State.ACTIVE, false);
+ changeState(_plugins, currentState,State.ACTIVE, false);
+ return true;
+ }
+ else if (desiredState == State.STOPPED)
+ {
+ changeState(_plugins, currentState,State.STOPPED, true);
+ changeState(_portAdapters, currentState, State.STOPPED, true);
+ changeState(_vhostAdapters,currentState, State.STOPPED, true);
+ changeState(_authenticationProviders, currentState, State.STOPPED, true);
+ changeState(_groupProviders, currentState, State.STOPPED, true);
+ return true;
+ }
+ return false;
+ }
+
+ private void changeState(Map<?, ? extends ConfiguredObject> configuredObjectMap, State currentState, State desiredState, boolean swallowException)
+ {
+ synchronized(configuredObjectMap)
+ {
+ Collection<? extends ConfiguredObject> adapters = configuredObjectMap.values();
+ for (ConfiguredObject configuredObject : adapters)
+ {
+ if (State.ACTIVE.equals(desiredState) && State.QUIESCED.equals(configuredObject.getActualState()))
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug(configuredObject + " cannot be activated as it is " +State.QUIESCED);
+ }
+ continue;
+ }
+ try
+ {
+ configuredObject.setDesiredState(currentState, desiredState);
+ }
+ catch(RuntimeException e)
+ {
+ if (swallowException)
+ {
+ LOGGER.error("Failed to stop " + configuredObject, e);
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void stateChanged(ConfiguredObject object, State oldState, State newState)
+ {
+ if(newState == State.DELETED)
+ {
+ boolean childDeleted = false;
+ if(object instanceof AuthenticationProvider)
+ {
+ childDeleted = deleteAuthenticationProvider((AuthenticationProvider)object);
+ }
+ else if(object instanceof Port)
+ {
+ childDeleted = deletePort((Port)object);
+ }
+ else if(object instanceof VirtualHost)
+ {
+ childDeleted = deleteVirtualHost((VirtualHost)object);
+ }
+ else if(object instanceof GroupProvider)
+ {
+ childDeleted = deleteGroupProvider((GroupProvider)object);
+ }
+ else if(object instanceof KeyStore)
+ {
+ childDeleted = deleteKeyStore((KeyStore)object);
+ }
+ else if(object instanceof TrustStore)
+ {
+ childDeleted = deleteTrustStore((TrustStore)object);
+ }
+ if(childDeleted)
+ {
+ childRemoved(object);
+ }
+ }
+ }
+
+ @Override
+ public void childAdded(ConfiguredObject object, ConfiguredObject child)
+ {
+ // no-op
+ }
+
+ @Override
+ public void childRemoved(ConfiguredObject object, ConfiguredObject child)
+ {
+ // no-op
+ }
+
+ @Override
+ public void attributeSet(ConfiguredObject object, String attributeName, Object oldAttributeValue, Object newAttributeValue)
+ {
+ // no-op
+ }
+
+ private void addPlugin(ConfiguredObject plugin)
+ {
+ synchronized(_plugins)
+ {
+ if (_plugins.containsKey(plugin.getId()))
+ {
+ throw new IllegalConfigurationException("Plugin with id '" + plugin.getId() + "' is already registered!");
+ }
+ _plugins.put(plugin.getId(), plugin);
+ }
+ plugin.addChangeListener(this);
+ }
+
+
+ private Collection<ConfiguredObject> getPlugins()
+ {
+ synchronized(_plugins)
+ {
+ return Collections.unmodifiableCollection(_plugins.values());
+ }
+ }
+
+ public void recoverChild(ConfiguredObject object)
+ {
+ if(object instanceof AuthenticationProvider)
+ {
+ addAuthenticationProvider((AuthenticationProvider)object);
+ }
+ else if(object instanceof Port)
+ {
+ addPort((Port)object);
+ }
+ else if(object instanceof VirtualHost)
+ {
+ addVirtualHost((VirtualHost)object);
+ }
+ else if(object instanceof GroupProvider)
+ {
+ addGroupProvider((GroupProvider)object);
+ }
+ else if(object instanceof KeyStore)
+ {
+ addKeyStore((KeyStore)object);
+ }
+ else if(object instanceof TrustStore)
+ {
+ addTrustStore((TrustStore)object);
+ }
+ else if(object instanceof Plugin)
+ {
+ addPlugin(object);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Attempted to recover unexpected type of configured object: " + object.getClass().getName());
+ }
+ }
+
+ @Override
+ public RootMessageLogger getRootMessageLogger()
+ {
+ return _rootMessageLogger;
+ }
+
+ @Override
+ public SecurityManager getSecurityManager()
+ {
+ return _securityManager;
+ }
+
+ @Override
+ public LogRecorder getLogRecorder()
+ {
+ return _logRecorder;
+ }
+
+ @Override
+ public VirtualHost findVirtualHostByName(String name)
+ {
+ return _vhostAdapters.get(name);
+ }
+
+ @Override
+ public SubjectCreator getSubjectCreator(SocketAddress localAddress)
+ {
+ InetSocketAddress inetSocketAddress = (InetSocketAddress)localAddress;
+ AuthenticationProvider provider = _defaultAuthenticationProvider;
+ Collection<Port> ports = getPorts();
+ for (Port p : ports)
+ {
+ if (inetSocketAddress.getPort() == p.getPort())
+ {
+ provider = p.getAuthenticationProvider();
+ break;
+ }
+ }
+ return provider.getSubjectCreator();
+ }
+
+ @Override
+ public Collection<KeyStore> getKeyStores()
+ {
+ synchronized(_trustStores)
+ {
+ return Collections.unmodifiableCollection(_keyStores.values());
+ }
+ }
+
+ @Override
+ public Collection<TrustStore> getTrustStores()
+ {
+ synchronized(_trustStores)
+ {
+ return Collections.unmodifiableCollection(_trustStores.values());
+ }
+ }
+
+ @Override
+ public VirtualHostRegistry getVirtualHostRegistry()
+ {
+ return _virtualHostRegistry;
+ }
+
+ @Override
+ public KeyStore getDefaultKeyStore()
+ {
+ return _keyStores.get(_defaultKeyStoreId);
+ }
+
+ @Override
+ public TrustStore getDefaultTrustStore()
+ {
+ return _trustStores.get(_defaultTrustStoreId);
+ }
+
+ @Override
+ public TaskExecutor getTaskExecutor()
{
- return super.setAttribute(name, expected, desired); //TODO - Implement.
+ return super.getTaskExecutor();
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
index 5439f6a560..84f99e1f17 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
@@ -38,6 +38,7 @@ import org.apache.qpid.server.model.Session;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.stats.StatisticsGatherer;
@@ -50,9 +51,9 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
new HashMap<AMQSessionModel, SessionAdapter>();
private final Statistics _statistics;
- public ConnectionAdapter(final AMQConnectionModel conn)
+ public ConnectionAdapter(final AMQConnectionModel conn, TaskExecutor taskExecutor)
{
- super(UUIDGenerator.generateRandomUUID());
+ super(UUIDGenerator.generateRandomUUID(), taskExecutor);
_connection = conn;
_statistics = new ConnectionStatisticsAdapter(conn);
}
@@ -74,7 +75,7 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
{
if(!_sessionAdapters.containsKey(session))
{
- _sessionAdapters.put(session, new SessionAdapter(session));
+ _sessionAdapters.put(session, new SessionAdapter(session, getTaskExecutor()));
}
}
return new ArrayList<Session>(_sessionAdapters.values());
@@ -199,52 +200,6 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
}
@Override
- public Object setAttribute(String name, Object expected, Object desired) throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- if(name.equals(CLIENT_ID))
- {
-
- }
- else if(name.equals(CLIENT_VERSION))
- {
-
- }
- else if(name.equals(INCOMING))
- {
-
- }
- else if(name.equals(LOCAL_ADDRESS))
- {
-
- }
- else if(name.equals(PRINCIPAL))
- {
-
- }
- else if(name.equals(PROPERTIES))
- {
-
- }
- else if(name.equals(REMOTE_ADDRESS))
- {
-
- }
- else if(name.equals(REMOTE_PROCESS_NAME))
- {
-
- }
- else if(name.equals(REMOTE_PROCESS_PID))
- {
-
- }
- else if(name.equals(SESSION_COUNT_LIMIT))
- {
-
- }
- return super.setAttribute(name, expected, desired);
- }
-
- @Override
public Collection<String> getAttributeNames()
{
final HashSet<String> attrNames = new HashSet<String>(super.getAttributeNames());
@@ -270,7 +225,8 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
}
}
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ @Override
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == Session.class)
{
@@ -310,4 +266,11 @@ final class ConnectionAdapter extends AbstractAdapter implements Connection
return super.getStatistic(name);
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ // TODO: add state management
+ return false;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java
index 031d518670..e6d3fab2f8 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ConsumerAdapter.java
@@ -45,7 +45,7 @@ public class ConsumerAdapter extends AbstractAdapter implements Consumer
queueAdapter.getName(),
subscription.getSessionModel().getConnectionModel().getRemoteAddressString(),
String.valueOf(subscription.getSessionModel().getChannelId()),
- subscription.getConsumerName()));
+ subscription.getConsumerName()), queueAdapter.getTaskExecutor());
_subscription = subscription;
_queue = queueAdapter;
_statistics = new ConsumerStatistics();
@@ -108,13 +108,6 @@ public class ConsumerAdapter extends AbstractAdapter implements Consumer
}
@Override
- public Object setAttribute(final String name, final Object expected, final Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO
- }
-
- @Override
public Object getAttribute(final String name)
{
if(ID.equals(name))
@@ -222,4 +215,11 @@ public class ConsumerAdapter extends AbstractAdapter implements Consumer
return null; // TODO - Implement
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ // TODO : Add state management
+ return false;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java
index df0f29fbc3..5d5f3f7378 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/ExchangeAdapter.java
@@ -33,16 +33,15 @@ import org.apache.qpid.AMQSecurityException;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.exchange.ExchangeType;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Exchange;
-import org.apache.qpid.server.model.IllegalStateTransitionException;
import org.apache.qpid.server.model.LifetimePolicy;
import org.apache.qpid.server.model.Publisher;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.util.MapValueConverter;
import org.apache.qpid.server.virtualhost.VirtualHost;
final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apache.qpid.server.exchange.Exchange.BindingListener
@@ -57,7 +56,7 @@ final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apa
public ExchangeAdapter(final VirtualHostAdapter virtualHostAdapter,
final org.apache.qpid.server.exchange.Exchange exchange)
{
- super(exchange.getId());
+ super(exchange.getId(), virtualHostAdapter.getTaskExecutor());
_statistics = new ExchangeStatistics();
_vhost = virtualHostAdapter;
_exchange = exchange;
@@ -113,8 +112,8 @@ final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apa
throws AccessControlException, IllegalStateException
{
attributes = new HashMap<String, Object>(attributes);
- String bindingKey = getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, "");
- Map<String, Object> bindingArgs = getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.EMPTY_MAP);
+ String bindingKey = MapValueConverter.getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, "");
+ Map<String, Object> bindingArgs = MapValueConverter.getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.<String,Object>emptyMap());
attributes.remove(org.apache.qpid.server.model.Binding.NAME);
attributes.remove(org.apache.qpid.server.model.Binding.ARGUMENTS);
@@ -257,7 +256,7 @@ final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apa
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == org.apache.qpid.server.model.Binding.class)
{
@@ -369,28 +368,20 @@ final class ExchangeAdapter extends AbstractAdapter implements Exchange, org.apa
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO - Implement
- }
-
- @Override
public Collection<String> getAttributeNames()
{
return AVAILABLE_ATTRIBUTES;
}
@Override
- public State setDesiredState(State currentState, State desiredState) throws IllegalStateTransitionException,
- AccessControlException
+ protected boolean setState(State currentState, State desiredState)
{
if (desiredState == State.DELETED)
{
delete();
- return State.DELETED;
+ return true;
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
private class ExchangeStatistics implements Statistics
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java
new file mode 100644
index 0000000000..0fa834bc28
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/GroupProviderAdapter.java
@@ -0,0 +1,550 @@
+/*
+ * 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.model.adapter;
+
+import java.security.AccessControlException;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Group;
+import org.apache.qpid.server.model.GroupMember;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.IllegalStateTransitionException;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.Statistics;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.security.group.GroupManager;
+import org.apache.qpid.server.security.SecurityManager;
+
+public class GroupProviderAdapter extends AbstractAdapter implements
+ GroupProvider
+{
+ private final GroupManager _groupManager;
+ private final Broker _broker;
+ public GroupProviderAdapter(UUID id, GroupManager groupManager, Broker broker)
+ {
+ super(id, broker.getTaskExecutor());
+
+ if (groupManager == null)
+ {
+ throw new IllegalArgumentException("GroupManager must not be null");
+ }
+ _groupManager = groupManager;
+ _broker = broker;
+ addParent(Broker.class, broker);
+ }
+
+ @Override
+ public String getName()
+ {
+ return _groupManager.getClass().getSimpleName();
+ }
+
+ @Override
+ public String setName(String currentName, String desiredName)
+ throws IllegalStateException, AccessControlException
+ {
+ return null;
+ }
+
+ @Override
+ public State getActualState()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isDurable()
+ {
+ return true;
+ }
+
+ @Override
+ public void setDurable(boolean durable) throws IllegalStateException,
+ AccessControlException, IllegalArgumentException
+ {
+ }
+
+ @Override
+ public LifetimePolicy getLifetimePolicy()
+ {
+ return LifetimePolicy.PERMANENT;
+ }
+
+ @Override
+ public LifetimePolicy setLifetimePolicy(LifetimePolicy expected,
+ LifetimePolicy desired) throws IllegalStateException,
+ AccessControlException, IllegalArgumentException
+ {
+ return null;
+ }
+
+ @Override
+ public long getTimeToLive()
+ {
+ return 0;
+ }
+
+ @Override
+ public long setTimeToLive(long expected, long desired)
+ throws IllegalStateException, AccessControlException,
+ IllegalArgumentException
+ {
+ return 0;
+ }
+
+ @Override
+ public Statistics getStatistics()
+ {
+ return NoStatistics.getInstance();
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return GroupProvider.AVAILABLE_ATTRIBUTES;
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ if (TYPE.equals(name))
+ {
+ return getName();
+ }
+ else if (CREATED.equals(name))
+ {
+ // TODO
+ }
+ else if (DURABLE.equals(name))
+ {
+ return true;
+ }
+ else if (ID.equals(name))
+ {
+ return getId();
+ }
+ else if (LIFETIME_POLICY.equals(name))
+ {
+ return LifetimePolicy.PERMANENT;
+ }
+ else if (NAME.equals(name))
+ {
+ return getName();
+ }
+ else if (STATE.equals(name))
+ {
+ return State.ACTIVE; // TODO
+ }
+ else if (TIME_TO_LIVE.equals(name))
+ {
+ // TODO
+ }
+ else if (UPDATED.equals(name))
+ {
+ // TODO
+ }
+ return super.getAttribute(name);
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass,
+ Map<String, Object> attributes, ConfiguredObject... otherParents)
+ {
+ if (childClass == Group.class)
+ {
+ String groupName = (String) attributes.get(Group.NAME);
+
+ if (getSecurityManager().authoriseGroupOperation(Operation.CREATE, groupName))
+ {
+ _groupManager.createGroup(groupName);
+ return (C) new GroupAdapter(groupName, getTaskExecutor());
+ }
+ else
+ {
+ throw new AccessControlException("Do not have permission" +
+ " to create new group");
+ }
+ }
+
+ throw new IllegalArgumentException(
+ "This group provider does not support creating children of type: "
+ + childClass);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
+ {
+ if (clazz == Group.class)
+ {
+ Set<Principal> groups = _groupManager.getGroupPrincipals();
+ Collection<Group> principals = new ArrayList<Group>(groups.size());
+ for (Principal group : groups)
+ {
+ principals.add(new GroupAdapter(group.getName(), getTaskExecutor()));
+ }
+ return (Collection<C>) Collections
+ .unmodifiableCollection(principals);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private SecurityManager getSecurityManager()
+ {
+ return _broker.getSecurityManager();
+ }
+
+ private class GroupAdapter extends AbstractAdapter implements Group
+ {
+ private final String _group;
+
+ public GroupAdapter(String group, TaskExecutor taskExecutor)
+ {
+ super(UUIDGenerator.generateGroupUUID(GroupProviderAdapter.this.getName(), group), taskExecutor);
+ _group = group;
+
+ }
+
+ @Override
+ public String getName()
+ {
+ return _group;
+ }
+
+ @Override
+ public String setName(String currentName, String desiredName)
+ throws IllegalStateException, AccessControlException
+ {
+ throw new IllegalStateException("Names cannot be updated");
+ }
+
+ @Override
+ public State getActualState()
+ {
+ return State.ACTIVE;
+ }
+
+ @Override
+ public boolean isDurable()
+ {
+ return true;
+ }
+
+ @Override
+ public void setDurable(boolean durable) throws IllegalStateException,
+ AccessControlException, IllegalArgumentException
+ {
+ throw new IllegalStateException("Durability cannot be updated");
+ }
+
+ @Override
+ public LifetimePolicy getLifetimePolicy()
+ {
+ return LifetimePolicy.PERMANENT;
+ }
+
+ @Override
+ public LifetimePolicy setLifetimePolicy(LifetimePolicy expected,
+ LifetimePolicy desired) throws IllegalStateException,
+ AccessControlException, IllegalArgumentException
+ {
+ throw new IllegalStateException("LifetimePolicy cannot be updated");
+ }
+
+ @Override
+ public long getTimeToLive()
+ {
+ return 0;
+ }
+
+ @Override
+ public long setTimeToLive(long expected, long desired)
+ throws IllegalStateException, AccessControlException,
+ IllegalArgumentException
+ {
+ throw new IllegalStateException("ttl cannot be updated");
+ }
+
+ @Override
+ public Statistics getStatistics()
+ {
+ return NoStatistics.getInstance();
+ }
+
+ @Override
+ public <C extends ConfiguredObject> Collection<C> getChildren(
+ Class<C> clazz)
+ {
+ if (clazz == GroupMember.class)
+ {
+ Set<Principal> usersInGroup = _groupManager
+ .getUserPrincipalsForGroup(_group);
+ Collection<GroupMember> members = new ArrayList<GroupMember>();
+ for (Principal principal : usersInGroup)
+ {
+ members.add(new GroupMemberAdapter(principal.getName(), getTaskExecutor()));
+ }
+ return (Collection<C>) Collections
+ .unmodifiableCollection(members);
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass,
+ Map<String, Object> attributes,
+ ConfiguredObject... otherParents)
+ {
+ if (childClass == GroupMember.class)
+ {
+ String memberName = (String) attributes.get(GroupMember.NAME);
+
+ if (getSecurityManager().authoriseGroupOperation(Operation.UPDATE, _group))
+ {
+ _groupManager.addUserToGroup(memberName, _group);
+ return (C) new GroupMemberAdapter(memberName, getTaskExecutor());
+ }
+ else
+ {
+ throw new AccessControlException("Do not have permission" +
+ " to add new group member");
+ }
+ }
+
+ throw new IllegalArgumentException(
+ "This group provider does not support creating children of type: "
+ + childClass);
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return Group.AVAILABLE_ATTRIBUTES;
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ if (ID.equals(name))
+ {
+ return getId();
+ }
+ else if (NAME.equals(name))
+ {
+ return getName();
+ }
+ return super.getAttribute(name);
+ }
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ throws IllegalStateTransitionException, AccessControlException
+ {
+ if (desiredState == State.DELETED)
+ {
+ if (getSecurityManager().authoriseGroupOperation(Operation.DELETE, _group))
+ {
+ _groupManager.removeGroup(_group);
+ return true;
+ }
+ else
+ {
+ throw new AccessControlException("Do not have permission to delete group");
+ }
+ }
+
+ return false;
+ }
+
+ private class GroupMemberAdapter extends AbstractAdapter implements
+ GroupMember
+ {
+ private String _memberName;
+
+ public GroupMemberAdapter(String memberName, TaskExecutor taskExecutor)
+ {
+ super(UUIDGenerator.generateGroupMemberUUID(GroupProviderAdapter.this.getName(), _group, memberName), taskExecutor);
+ _memberName = memberName;
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return GroupMember.AVAILABLE_ATTRIBUTES;
+ }
+
+ @Override
+ public Object getAttribute(String name)
+ {
+ if (ID.equals(name))
+ {
+ return getId();
+ }
+ else if (NAME.equals(name))
+ {
+ return getName();
+ }
+ return super.getAttribute(name);
+ }
+
+ @Override
+ public String getName()
+ {
+ return _memberName;
+ }
+
+ @Override
+ public String setName(String currentName, String desiredName)
+ throws IllegalStateException, AccessControlException
+ {
+ return null;
+ }
+
+ @Override
+ public State getActualState()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isDurable()
+ {
+ return false;
+ }
+
+ @Override
+ public void setDurable(boolean durable)
+ throws IllegalStateException, AccessControlException,
+ IllegalArgumentException
+ {
+ }
+
+ @Override
+ public LifetimePolicy getLifetimePolicy()
+ {
+ return null;
+ }
+
+ @Override
+ public LifetimePolicy setLifetimePolicy(LifetimePolicy expected,
+ LifetimePolicy desired) throws IllegalStateException,
+ AccessControlException, IllegalArgumentException
+ {
+ return null;
+ }
+
+ @Override
+ public long getTimeToLive()
+ {
+ return 0;
+ }
+
+ @Override
+ public long setTimeToLive(long expected, long desired)
+ throws IllegalStateException, AccessControlException,
+ IllegalArgumentException
+ {
+ return 0;
+ }
+
+ @Override
+ public Statistics getStatistics()
+ {
+ return NoStatistics.getInstance();
+ }
+
+ @Override
+ public <C extends ConfiguredObject> Collection<C> getChildren(
+ Class<C> clazz)
+ {
+ return null;
+ }
+
+ @Override
+ public <C extends ConfiguredObject> C createChild(
+ Class<C> childClass, Map<String, Object> attributes,
+ ConfiguredObject... otherParents)
+ {
+ return null;
+ }
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ throws IllegalStateTransitionException,
+ AccessControlException
+ {
+ if (desiredState == State.DELETED)
+ {
+ if (getSecurityManager().authoriseGroupOperation(Operation.UPDATE, _group))
+ {
+ _groupManager.removeUserFromGroup(_memberName, _group);
+ return true;
+ }
+ else
+ {
+ throw new AccessControlException("Do not have permission to remove group member");
+ }
+ }
+ return false;
+ }
+
+ }
+ }
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.ACTIVE)
+ {
+ return true;
+ }
+ else if (desiredState == State.STOPPED)
+ {
+ return true;
+ }
+ // TODO: DELETE state is ignored for now
+ // in case if we need to delete group provider, then we need AuthenticationProvider to be a change listener of it
+ // in order to remove deleted group provider from its group provider list
+ return false;
+ }
+
+ public Set<Principal> getGroupPrincipalsForUser(String username)
+ {
+ return _groupManager.getGroupPrincipalsForUser(username);
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/HTTPPortAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/HTTPPortAdapter.java
deleted file mode 100644
index 823d27160b..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/HTTPPortAdapter.java
+++ /dev/null
@@ -1,273 +0,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.
- *
- */
-
-package org.apache.qpid.server.model.adapter;
-
-import java.security.AccessControlException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.Connection;
-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.State;
-import org.apache.qpid.server.model.Statistics;
-import org.apache.qpid.server.model.Transport;
-import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.model.VirtualHostAlias;
-
-public class HTTPPortAdapter extends AbstractAdapter implements Port
-{
- private final BrokerAdapter _broker;
- private final int _port;
- private final Protocol _protocol;
- private final Transport _transport;
-
- public HTTPPortAdapter(BrokerAdapter brokerAdapter, int port)
- {
- this(brokerAdapter, port, Protocol.HTTP, Transport.TCP);
- }
-
- public HTTPPortAdapter(BrokerAdapter brokerAdapter, int port, Protocol protocol, Transport transport)
- {
- super(UUIDGenerator.generateRandomUUID());
- _broker = brokerAdapter;
- _port = port;
- _protocol = protocol;
- _transport = transport;
- }
-
- @Override
- public String getBindingAddress()
- {
- return "0.0.0.0";
- }
-
- @Override
- public int getPort()
- {
- return _port;
- }
-
- @Override
- public Collection<Transport> getTransports()
- {
- return Collections.singleton(_transport);
- }
-
- @Override
- public void addTransport(Transport transport)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Transport removeTransport(Transport transport)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Collection<Protocol> getProtocols()
- {
- return Collections.singleton(_protocol);
- }
-
- @Override
- public void addProtocol(Protocol protocol)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Protocol removeProtocol(Protocol protocol)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Collection<VirtualHostAlias> getVirtualHostBindings()
- {
- return Collections.emptySet();
- }
-
- @Override
- public Collection<Connection> getConnections()
- {
- return Collections.emptySet(); // TODO - Implement
- }
-
- @Override
- public String getName()
- {
- return getBindingAddress() + ":" + getPort(); // TODO - Implement
- }
-
- @Override
- public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public State getActualState()
- {
- return State.ACTIVE;
- }
-
- @Override
- public boolean isDurable()
- {
- return false; // TODO - Implement
- }
-
- @Override
- public void setDurable(boolean durable)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException();
- }
-
- @Override
- public LifetimePolicy getLifetimePolicy()
- {
- return LifetimePolicy.PERMANENT;
- }
-
- @Override
- public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public long getTimeToLive()
- {
- return 0; // TODO - Implement
- }
-
- @Override
- public long setTimeToLive(long expected, long desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- throw new IllegalStateException(); // TODO - Implement
- }
-
- @Override
- public Statistics getStatistics()
- {
- return NoStatistics.getInstance();
- }
-
- @Override
- public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
- {
- if(clazz == Connection.class)
- {
- return (Collection<C>) getConnections();
- }
- else
- {
- return Collections.emptySet();
- }
- }
-
- @Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Object getAttribute(String name)
- {
- if(ID.equals(name))
- {
- return getId();
- }
- else if(NAME.equals(name))
- {
- return getName();
- }
- else if(STATE.equals(name))
- {
- return getActualState();
- }
- else if(DURABLE.equals(name))
- {
- return isDurable();
- }
- else if(LIFETIME_POLICY.equals(name))
- {
- return getLifetimePolicy();
- }
- else if(TIME_TO_LIVE.equals(name))
- {
- return getTimeToLive();
- }
- else if(CREATED.equals(name))
- {
-
- }
- else if(UPDATED.equals(name))
- {
-
- }
- else if(BINDING_ADDRESS.equals(name))
- {
- return getBindingAddress();
- }
- else if(PORT.equals(name))
- {
- return getPort();
- }
- else if(PROTOCOLS.equals(name))
- {
- return getProtocols();
- }
- else if(TRANSPORTS.equals(name))
- {
- return getTransports();
- }
-
- return super.getAttribute(name); //TODO - Implement
- }
-
- @Override
- public Collection<String> getAttributeNames()
- {
- return AVAILABLE_ATTRIBUTES;
- }
-
- @Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO - Implement
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.java
new file mode 100644
index 0000000000..113d895e62
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/KeyStoreAdapter.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.server.model.adapter;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.KeyStore;
+
+public class KeyStoreAdapter extends AbstractKeyStoreAdapter implements KeyStore
+{
+
+ public KeyStoreAdapter(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, broker, attributes);
+ if (attributes.get(CERTIFICATE_ALIAS) != null)
+ {
+ changeAttribute(CERTIFICATE_ALIAS, null, attributes.get(CERTIFICATE_ALIAS));
+ }
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java
index 7653fcc9b9..c4a531c923 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAdapter.java
@@ -21,7 +21,16 @@
package org.apache.qpid.server.model.adapter;
+import java.security.AccessControlException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Connection;
import org.apache.qpid.server.model.LifetimePolicy;
@@ -30,119 +39,82 @@ import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.Transport;
-import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostAlias;
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.server.transport.QpidAcceptor;
-
-import java.net.InetSocketAddress;
-import java.security.AccessControlException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
public class PortAdapter extends AbstractAdapter implements Port
{
- private final BrokerAdapter _broker;
- private final QpidAcceptor _acceptor;
- private final InetSocketAddress _address;
- private final Collection<Protocol> _protocols;
-
- public PortAdapter(BrokerAdapter brokerAdapter, QpidAcceptor acceptor, InetSocketAddress address)
- {
- super(UUIDGenerator.generateRandomUUID());
- _broker = brokerAdapter;
- _acceptor = acceptor;
- _address = address;
- List<Protocol> protocols = new ArrayList<Protocol>();
+ private final Broker _broker;
+ private AuthenticationProvider _authenticationProvider;
- for(AmqpProtocolVersion pv : _acceptor.getSupported())
- {
- switch(pv)
- {
- case v0_8:
- protocols.add(Protocol.AMQP_0_8);
- break;
- case v0_9:
- protocols.add(Protocol.AMQP_0_9);
- break;
- case v0_9_1:
- protocols.add(Protocol.AMQP_0_9_1);
- break;
- case v0_10:
- protocols.add(Protocol.AMQP_0_10);
- break;
- case v1_0_0:
- protocols.add(Protocol.AMQP_1_0);
- break;
- }
- }
+ /*
+ * TODO register PortAceptor as a listener. For supporting multiple
+ * protocols on the same port we need to introduce a special entity like
+ * PortAceptor which will be responsible for port binding/unbinding
+ */
+ public PortAdapter(UUID id, Broker broker, Map<String, Object> attributes, Map<String, Object> defaults, TaskExecutor taskExecutor)
+ {
+ super(id, defaults, attributes, taskExecutor);
+ _broker = broker;
- _protocols = Collections.unmodifiableCollection(protocols);
+ addParent(Broker.class, broker);
}
@Override
public String getBindingAddress()
{
- return _address.getHostName();
+ return (String)getAttribute(BINDING_ADDRESS);
}
@Override
public int getPort()
{
- return _address.getPort();
+ return (Integer)getAttribute(PORT);
}
+ @SuppressWarnings("unchecked")
@Override
public Collection<Transport> getTransports()
{
- switch (_acceptor.getTransport())
- {
- case TCP:
- return Collections.singleton(Transport.TCP);
- case SSL:
- return Collections.singleton(Transport.SSL);
- }
-
- return null; // TODO - Implement
+ return (Collection<Transport>)getAttribute(TRANSPORTS);
}
@Override
public void addTransport(Transport transport)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
public Transport removeTransport(Transport transport)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
+ @SuppressWarnings("unchecked")
@Override
public Collection<Protocol> getProtocols()
{
- return _protocols;
+ return (Collection<Protocol>)getAttribute(PROTOCOLS);
}
@Override
public void addProtocol(Protocol protocol)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
public Protocol removeProtocol(Protocol protocol)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
@@ -165,31 +137,36 @@ public class PortAdapter extends AbstractAdapter implements Port
@Override
public Collection<Connection> getConnections()
{
- return null; // TODO - Implement
+ return null;
}
@Override
public String getName()
{
- return getBindingAddress() + ":" + getPort(); // TODO - Implement
+ return (String)getAttribute(NAME);
}
@Override
public String setName(String currentName, String desiredName) throws IllegalStateException, AccessControlException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
public State getActualState()
{
- return State.ACTIVE;
+ State state = (State)super.getAttribute(STATE);
+ if (state == null)
+ {
+ return State.ACTIVE;
+ }
+ return state;
}
@Override
public boolean isDurable()
{
- return false; // TODO - Implement
+ return false;
}
@Override
@@ -209,20 +186,20 @@ public class PortAdapter extends AbstractAdapter implements Port
public LifetimePolicy setLifetimePolicy(LifetimePolicy expected, LifetimePolicy desired)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
public long getTimeToLive()
{
- return 0; // TODO - Implement
+ return 0;
}
@Override
public long setTimeToLive(long expected, long desired)
throws IllegalStateException, AccessControlException, IllegalArgumentException
{
- throw new IllegalStateException(); // TODO - Implement
+ throw new IllegalStateException();
}
@Override
@@ -257,10 +234,6 @@ public class PortAdapter extends AbstractAdapter implements Port
{
return getId();
}
- else if(NAME.equals(name))
- {
- return getName();
- }
else if(STATE.equals(name))
{
return getActualState();
@@ -285,36 +258,54 @@ public class PortAdapter extends AbstractAdapter implements Port
{
}
- else if(BINDING_ADDRESS.equals(name))
- {
- return getBindingAddress();
- }
- else if(PORT.equals(name))
+ return super.getAttribute(name);
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+ @Override
+ public boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.DELETED)
{
- return getPort();
+ return true;
}
- else if(PROTOCOLS.equals(name))
+ else if (desiredState == State.ACTIVE)
{
- return getProtocols();
+ onActivate();
+ return true;
}
- else if(TRANSPORTS.equals(name))
+ else if (desiredState == State.STOPPED)
{
- return getTransports();
+ onStop();
+ return true;
}
+ return false;
+ }
- return super.getAttribute(name); //TODO - Implement
+ protected void onActivate()
+ {
+ // no-op: expected to be overridden by subclass
}
- @Override
- public Collection<String> getAttributeNames()
+ protected void onStop()
{
- return AVAILABLE_ATTRIBUTES;
+ // no-op: expected to be overridden by subclass
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
+ public AuthenticationProvider getAuthenticationProvider()
+ {
+ return _authenticationProvider;
+ }
+
+ public void setAuthenticationProvider(AuthenticationProvider authenticationProvider)
{
- return super.setAttribute(name, expected, desired); //TODO - Implement
+ _authenticationProvider = authenticationProvider;
}
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java
new file mode 100644
index 0000000000..b7441b9f3b
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortFactory.java
@@ -0,0 +1,222 @@
+/*
+ *
+ * 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.model.adapter;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Protocol.ProtocolType;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.util.MapValueConverter;
+
+public class PortFactory
+{
+ public static final int DEFAULT_AMQP_SEND_BUFFER_SIZE = 262144;
+ public static final int DEFAULT_AMQP_RECEIVE_BUFFER_SIZE = 262144;
+ public static final boolean DEFAULT_AMQP_NEED_CLIENT_AUTH = false;
+ public static final boolean DEFAULT_AMQP_WANT_CLIENT_AUTH = false;
+ public static final boolean DEFAULT_AMQP_TCP_NO_DELAY = true;
+ public static final String DEFAULT_AMQP_BINDING = "*";
+ public static final Transport DEFAULT_TRANSPORT = Transport.TCP;
+
+ private final Collection<Protocol> _defaultProtocols;
+
+ public PortFactory()
+ {
+ Set<Protocol> defaultProtocols = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1,
+ Protocol.AMQP_0_10, Protocol.AMQP_1_0);
+ String excludedProtocols = System.getProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES);
+ if (excludedProtocols != null)
+ {
+ String[] excludes = excludedProtocols.split(",");
+ for (String exclude : excludes)
+ {
+ Protocol protocol = Protocol.valueOf(exclude);
+ defaultProtocols.remove(protocol);
+ }
+ }
+ String includedProtocols = System.getProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES);
+ if (includedProtocols != null)
+ {
+ String[] includes = includedProtocols.split(",");
+ for (String include : includes)
+ {
+ Protocol protocol = Protocol.valueOf(include);
+ defaultProtocols.add(protocol);
+ }
+ }
+ _defaultProtocols = Collections.unmodifiableCollection(defaultProtocols);
+ }
+
+ public Port createPort(UUID id, Broker broker, Map<String, Object> objectAttributes)
+ {
+ Map<String, Object> attributes = retrieveAttributes(objectAttributes);
+
+ final Port port;
+ Map<String, Object> defaults = new HashMap<String, Object>();
+ defaults.put(Port.TRANSPORTS, Collections.singleton(DEFAULT_TRANSPORT));
+ Object portValue = attributes.get(Port.PORT);
+ if (portValue == null)
+ {
+ throw new IllegalConfigurationException("Port attribute is not specified for port: " + attributes);
+ }
+ if (isAmqpProtocol(attributes))
+ {
+ Object binding = attributes.get(Port.BINDING_ADDRESS);
+ if (binding == null)
+ {
+ binding = DEFAULT_AMQP_BINDING;
+ defaults.put(Port.BINDING_ADDRESS, DEFAULT_AMQP_BINDING);
+ }
+ defaults.put(Port.NAME, binding + ":" + portValue);
+ defaults.put(Port.PROTOCOLS, _defaultProtocols);
+ defaults.put(Port.TCP_NO_DELAY, DEFAULT_AMQP_TCP_NO_DELAY);
+ defaults.put(Port.WANT_CLIENT_AUTH, DEFAULT_AMQP_WANT_CLIENT_AUTH);
+ defaults.put(Port.NEED_CLIENT_AUTH, DEFAULT_AMQP_NEED_CLIENT_AUTH);
+ defaults.put(Port.RECEIVE_BUFFER_SIZE, DEFAULT_AMQP_RECEIVE_BUFFER_SIZE);
+ defaults.put(Port.SEND_BUFFER_SIZE, DEFAULT_AMQP_SEND_BUFFER_SIZE);
+ port = new AmqpPortAdapter(id, broker, attributes, defaults, broker.getTaskExecutor());
+ }
+ else
+ {
+ @SuppressWarnings("unchecked")
+ Collection<Protocol> protocols = (Collection<Protocol>)attributes.get(Port.PROTOCOLS);
+ if (protocols.size() > 1)
+ {
+ throw new IllegalConfigurationException("Only one protocol can be used on non AMQP port");
+ }
+ Protocol protocol = protocols.iterator().next();
+ defaults.put(Port.NAME, portValue + "-" + protocol.name());
+ port = new PortAdapter(id, broker, attributes, defaults, broker.getTaskExecutor());
+ }
+ return port;
+ }
+
+ private Map<String, Object> retrieveAttributes(Map<String, Object> objectAttributes)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>(objectAttributes);
+
+ if (objectAttributes.containsKey(Port.PROTOCOLS))
+ {
+ final Set<Protocol> protocolSet = MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, objectAttributes, Protocol.class);
+ attributes.put(Port.PROTOCOLS, protocolSet);
+ }
+
+ if (objectAttributes.containsKey(Port.TRANSPORTS))
+ {
+ final Set<Transport> transportSet = MapValueConverter.getEnumSetAttribute(Port.TRANSPORTS, objectAttributes,
+ Transport.class);
+ attributes.put(Port.TRANSPORTS, transportSet);
+ }
+
+ if (objectAttributes.containsKey(Port.PORT))
+ {
+ Integer port = MapValueConverter.getIntegerAttribute(Port.PORT, objectAttributes);
+ attributes.put(Port.PORT, port);
+ }
+
+ if (objectAttributes.containsKey(Port.TCP_NO_DELAY))
+ {
+ boolean tcpNoDelay = MapValueConverter.getBooleanAttribute(Port.TCP_NO_DELAY, objectAttributes);
+ attributes.put(Port.TCP_NO_DELAY, tcpNoDelay);
+ }
+
+ if (objectAttributes.containsKey(Port.RECEIVE_BUFFER_SIZE))
+ {
+ int receiveBufferSize = MapValueConverter.getIntegerAttribute(Port.RECEIVE_BUFFER_SIZE, objectAttributes);
+ attributes.put(Port.RECEIVE_BUFFER_SIZE, receiveBufferSize);
+ }
+
+ if (objectAttributes.containsKey(Port.SEND_BUFFER_SIZE))
+ {
+ int sendBufferSize = MapValueConverter.getIntegerAttribute(Port.SEND_BUFFER_SIZE, objectAttributes);
+ attributes.put(Port.SEND_BUFFER_SIZE, sendBufferSize);
+ }
+
+ if (objectAttributes.containsKey(Port.NEED_CLIENT_AUTH))
+ {
+ boolean needClientAuth = MapValueConverter.getBooleanAttribute(Port.NEED_CLIENT_AUTH, objectAttributes);
+ attributes.put(Port.NEED_CLIENT_AUTH, needClientAuth);
+ }
+
+ if (objectAttributes.containsKey(Port.WANT_CLIENT_AUTH))
+ {
+ boolean wantClientAuth = MapValueConverter.getBooleanAttribute(Port.WANT_CLIENT_AUTH, objectAttributes);
+ attributes.put(Port.WANT_CLIENT_AUTH, wantClientAuth);
+ }
+
+ if (objectAttributes.containsKey(Port.BINDING_ADDRESS))
+ {
+ String binding = MapValueConverter.getStringAttribute(Port.BINDING_ADDRESS, objectAttributes);
+ attributes.put(Port.BINDING_ADDRESS, binding);
+ }
+
+ if (objectAttributes.containsKey(Port.STATE))
+ {
+ State state = MapValueConverter.getEnumAttribute(State.class, Port.STATE, objectAttributes);
+ attributes.put(Port.STATE, state);
+ }
+ return attributes;
+ }
+
+ private boolean isAmqpProtocol(Map<String, Object> portAttributes)
+ {
+ @SuppressWarnings("unchecked")
+ Set<Protocol> protocols = (Set<Protocol>) portAttributes.get(Port.PROTOCOLS);
+ if (protocols == null || protocols.isEmpty())
+ {
+ // defaulting to AMQP if protocol is not specified
+ return true;
+ }
+
+ Set<ProtocolType> protocolTypes = new HashSet<ProtocolType>();
+ for (Protocol protocolObject : protocols)
+ {
+ protocolTypes.add(protocolObject.getProtocolType());
+ }
+
+ if (protocolTypes.size() > 1)
+ {
+ throw new IllegalConfigurationException("Found different protocol types '" + protocolTypes
+ + "' on port configuration: " + portAttributes);
+ }
+
+ return protocolTypes.contains(ProtocolType.AMQP);
+ }
+
+ public Collection<Protocol> getDefaultProtocols()
+ {
+ return _defaultProtocols;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java
index 78f6d38d93..f3ddf32e5a 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java
@@ -43,6 +43,7 @@ import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.queue.*;
import org.apache.qpid.server.subscription.Subscription;
+import org.apache.qpid.server.util.MapValueConverter;
final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.SubscriptionRegistrationListener, AMQQueue.NotificationListener
{
@@ -50,15 +51,16 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
static final Map<String, String> ATTRIBUTE_MAPPINGS = new HashMap<String, String>();
static
{
- QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_REPEAT_GAP, "x-qpid-minimum-alert-repeat-gap");
- QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_THRESHOLD_MESSAGE_AGE, "x-qpid-maximum-message-age");
- QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_THRESHOLD_MESSAGE_SIZE, "x-qpid-maximum-message-size");
- QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, "x-qpid-maximum-message-count");
+ QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_REPEAT_GAP, AMQQueueFactory.X_QPID_MINIMUM_ALERT_REPEAT_GAP);
+ QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_THRESHOLD_MESSAGE_AGE, AMQQueueFactory.X_QPID_MAXIMUM_MESSAGE_AGE);
+ QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_THRESHOLD_MESSAGE_SIZE, AMQQueueFactory.X_QPID_MAXIMUM_MESSAGE_SIZE);
+ QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, AMQQueueFactory.X_QPID_MAXIMUM_MESSAGE_COUNT);
+ QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.ALERT_THRESHOLD_QUEUE_DEPTH_BYTES, AMQQueueFactory.X_QPID_MAXIMUM_QUEUE_DEPTH);
- QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.MAXIMUM_DELIVERY_ATTEMPTS, "x-qpid-maximum-delivery-count");
+ QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.MAXIMUM_DELIVERY_ATTEMPTS, AMQQueueFactory.X_QPID_MAXIMUM_DELIVERY_COUNT);
- QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES, "x-qpid-capacity");
- QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.QUEUE_FLOW_RESUME_SIZE_BYTES, "x-qpid-flow-resume-capacity");
+ QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES, AMQQueueFactory.X_QPID_CAPACITY);
+ QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.QUEUE_FLOW_RESUME_SIZE_BYTES, AMQQueueFactory.X_QPID_FLOW_RESUME_CAPACITY);
QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.SORT_KEY, AMQQueueFactory.QPID_QUEUE_SORT_KEY);
QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.LVQ_KEY, AMQQueueFactory.QPID_LAST_VALUE_QUEUE_KEY);
@@ -78,7 +80,7 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
public QueueAdapter(final VirtualHostAdapter virtualHostAdapter, final AMQQueue queue)
{
- super(queue.getId());
+ super(queue.getId(), virtualHostAdapter.getTaskExecutor());
_vhost = virtualHostAdapter;
addParent(org.apache.qpid.server.model.VirtualHost.class, virtualHostAdapter);
@@ -205,47 +207,47 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
}
@Override
- public Object setAttribute(String name, Object expected, Object desired) throws IllegalStateException, AccessControlException, IllegalArgumentException
+ public boolean changeAttribute(String name, Object expected, Object desired) throws IllegalStateException, AccessControlException, IllegalArgumentException
{
try
{
if(ALERT_REPEAT_GAP.equals(name))
{
_queue.setMinimumAlertRepeatGap((Long)desired);
- return desired;
+ return true;
}
else if(ALERT_THRESHOLD_MESSAGE_AGE.equals(name))
{
_queue.setMaximumMessageAge((Long)desired);
- return desired;
+ return true;
}
else if(ALERT_THRESHOLD_MESSAGE_SIZE.equals(name))
{
_queue.setMaximumMessageSize((Long)desired);
- return desired;
+ return true;
}
else if(ALERT_THRESHOLD_QUEUE_DEPTH_BYTES.equals(name))
{
_queue.setMaximumQueueDepth((Long)desired);
- return desired;
+ return true;
}
else if(ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES.equals(name))
{
_queue.setMaximumMessageCount((Long)desired);
- return desired;
+ return true;
}
else if(ALTERNATE_EXCHANGE.equals(name))
{
// In future we may want to accept a UUID as an alternative way to identifying the exchange
ExchangeAdapter alternateExchange = (ExchangeAdapter) desired;
_queue.setAlternateExchange(alternateExchange == null ? null : alternateExchange.getExchange());
- return desired;
+ return true;
}
else if(EXCLUSIVE.equals(name))
{
Boolean exclusiveFlag = (Boolean) desired;
_queue.setExclusive(exclusiveFlag);
- return desired;
+ return true;
}
else if(MESSAGE_GROUP_KEY.equals(name))
{
@@ -266,7 +268,7 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
else if(MAXIMUM_DELIVERY_ATTEMPTS.equals(name))
{
_queue.setMaximumDeliveryCount((Integer)desired);
- return desired;
+ return true;
}
else if(NO_LOCAL.equals(name))
{
@@ -279,12 +281,12 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
else if(QUEUE_FLOW_CONTROL_SIZE_BYTES.equals(name))
{
_queue.setCapacity((Long)desired);
- return desired;
+ return true;
}
else if(QUEUE_FLOW_RESUME_SIZE_BYTES.equals(name))
{
_queue.setFlowResumeCapacity((Long)desired);
- return desired;
+ return true;
}
else if(QUEUE_FLOW_STOPPED.equals(name))
{
@@ -301,10 +303,10 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
else if (DESCRIPTION.equals(name))
{
_queue.setDescription((String) desired);
- return desired;
+ return true;
}
- return super.setAttribute(name, expected, desired);
+ return super.changeAttribute(name, expected, desired);
}
finally
{
@@ -495,8 +497,8 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
throws AccessControlException, IllegalStateException
{
attributes = new HashMap<String, Object>(attributes);
- String bindingKey = getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, "");
- Map<String, Object> bindingArgs = getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.EMPTY_MAP);
+ String bindingKey = MapValueConverter.getStringAttribute(org.apache.qpid.server.model.Binding.NAME, attributes, "");
+ Map<String, Object> bindingArgs = MapValueConverter.getMapAttribute(org.apache.qpid.server.model.Binding.ARGUMENTS, attributes, Collections.<String,Object>emptyMap());
attributes.remove(org.apache.qpid.server.model.Binding.NAME);
attributes.remove(org.apache.qpid.server.model.Binding.ARGUMENTS);
@@ -508,7 +510,7 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == org.apache.qpid.server.model.Binding.class)
{
@@ -712,15 +714,15 @@ final class QueueAdapter extends AbstractAdapter implements Queue, AMQQueue.Subs
}
@Override
- public State setDesiredState(State currentState, State desiredState) throws IllegalStateTransitionException,
+ protected boolean setState(State currentState, State desiredState) throws IllegalStateTransitionException,
AccessControlException
{
if (desiredState == State.DELETED)
{
delete();
- return State.DELETED;
+ return true;
}
- return super.setDesiredState(currentState, desiredState);
+ return false;
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
index d802697d67..2fffdb32f8 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
@@ -34,6 +34,7 @@ import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.Consumer;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.protocol.AMQSessionModel;
final class SessionAdapter extends AbstractAdapter implements Session
@@ -44,9 +45,9 @@ final class SessionAdapter extends AbstractAdapter implements Session
private AMQSessionModel _session;
private SessionStatistics _statistics;
- public SessionAdapter(final AMQSessionModel session)
+ public SessionAdapter(final AMQSessionModel session, TaskExecutor taskExecutor)
{
- super(UUIDGenerator.generateRandomUUID());
+ super(UUIDGenerator.generateRandomUUID(), taskExecutor);
_session = session;
_statistics = new SessionStatistics();
}
@@ -141,13 +142,6 @@ final class SessionAdapter extends AbstractAdapter implements Session
return super.getAttribute(name); //TODO - Implement
}
- @Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO - Implement
- }
-
public Statistics getStatistics()
{
return _statistics;
@@ -237,4 +231,11 @@ final class SessionAdapter extends AbstractAdapter implements Session
return null; // TODO - Implement
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ // TODO : add state management
+ return false;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.java
new file mode 100644
index 0000000000..bdffe605ec
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/TrustStoreAdapter.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.server.model.adapter;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.TrustStore;
+
+public class TrustStoreAdapter extends AbstractKeyStoreAdapter implements TrustStore
+{
+ public TrustStoreAdapter(UUID id, Broker broker, Map<String, Object> attributes)
+ {
+ super(id, broker, attributes);
+ }
+
+ @Override
+ public Collection<String> getAttributeNames()
+ {
+ return AVAILABLE_ATTRIBUTES;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
index 35838e51d2..1d50be279f 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.server.model.adapter;
+import java.io.File;
import java.security.AccessControlException;
import java.security.Principal;
import java.util.ArrayList;
@@ -31,17 +32,27 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
+
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration.SystemConfiguration;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.configuration.XmlConfigurationUtilities.MyConfiguration;
import org.apache.qpid.server.connection.IConnectionRegistry;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.exchange.ExchangeType;
import org.apache.qpid.server.message.ServerMessage;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Connection;
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.QueueType;
import org.apache.qpid.server.model.State;
@@ -49,22 +60,38 @@ import org.apache.qpid.server.model.Statistics;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostAlias;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.QueueEntry;
import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.txn.LocalTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
+import org.apache.qpid.server.util.MapValueConverter;
+import org.apache.qpid.server.virtualhost.VirtualHostImpl;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, ExchangeRegistry.RegistryChangeListener,
+public final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, ExchangeRegistry.RegistryChangeListener,
QueueRegistry.RegistryChangeListener,
IConnectionRegistry.RegistryChangeListener
{
- private final org.apache.qpid.server.virtualhost.VirtualHost _virtualHost;
+ @SuppressWarnings("serial")
+ public static final Map<String, Class<?>> ATTRIBUTE_TYPES = Collections.unmodifiableMap(new HashMap<String, Class<?>>(){{
+ put(NAME, String.class);
+ put(STORE_PATH, String.class);
+ put(STORE_TYPE, String.class);
+ put(CONFIG_PATH, String.class);
+ put(STATE, State.class);
+ }});
+
+ private org.apache.qpid.server.virtualhost.VirtualHost _virtualHost;
private final Map<AMQConnectionModel, ConnectionAdapter> _connectionAdapters =
new HashMap<AMQConnectionModel, ConnectionAdapter>();
@@ -74,37 +101,52 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
private final Map<org.apache.qpid.server.exchange.Exchange, ExchangeAdapter> _exchangeAdapters =
new HashMap<org.apache.qpid.server.exchange.Exchange, ExchangeAdapter>();
-
- private final StatisticsAdapter _statistics;
-
- private final BrokerAdapter _broker;
-
+ private StatisticsAdapter _statistics;
+ private final Broker _broker;
private final List<VirtualHostAlias> _aliases = new ArrayList<VirtualHostAlias>();
+ private StatisticsGatherer _brokerStatisticsGatherer;
-
- VirtualHostAdapter(BrokerAdapter brokerAdapter,
- final org.apache.qpid.server.virtualhost.VirtualHost virtualHost)
+ public VirtualHostAdapter(UUID id, Map<String, Object> attributes, Broker broker, StatisticsGatherer brokerStatisticsGatherer, TaskExecutor taskExecutor)
{
- super(virtualHost.getId());
- _broker = brokerAdapter;
- _virtualHost = virtualHost;
- _statistics = new VirtualHostStatisticsAdapter(virtualHost);
- virtualHost.getQueueRegistry().addRegistryChangeListener(this);
- populateQueues();
- virtualHost.getExchangeRegistry().addRegistryChangeListener(this);
- populateExchanges();
- virtualHost.getConnectionRegistry().addRegistryChangeListener(this);
- populateConnections();
-
+ super(id, null, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor);
+ validateAttributes();
+ _broker = broker;
+ _brokerStatisticsGatherer = brokerStatisticsGatherer;
+ addParent(Broker.class, broker);
+ }
+ private void validateAttributes()
+ {
+ String name = getName();
+ if (name == null || "".equals(name.trim()))
+ {
+ throw new IllegalConfigurationException("Virtual host name must be specified");
+ }
- for(Port port :_broker.getPorts())
+ String configurationFile = (String) getAttribute(CONFIG_PATH);
+ String storePath = (String) getAttribute(STORE_PATH);
+ String storeType = (String) getAttribute(STORE_TYPE);
+ boolean invalidAttributes = false;
+ if (configurationFile == null)
+ {
+ if (storePath == null || storeType == null)
+ {
+ invalidAttributes = true;
+ }
+ }
+ else
+ {
+ if (storePath != null || storeType != null)
+ {
+ invalidAttributes = true;
+ }
+ }
+ if (invalidAttributes)
{
- _aliases.add(new VirtualHostAliasAdapter(this, port));
+ throw new IllegalConfigurationException("Please specify either the 'configPath' attribute or both 'storePath' and 'storeType' attributes");
}
}
-
private void populateExchanges()
{
Collection<org.apache.qpid.server.exchange.Exchange> actualExchanges =
@@ -126,37 +168,22 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
private void populateQueues()
{
Collection<AMQQueue> actualQueues = _virtualHost.getQueueRegistry().getQueues();
-
- synchronized(_queueAdapters)
- {
- for(AMQQueue queue : actualQueues)
- {
- if(!_queueAdapters.containsKey(queue))
- {
- _queueAdapters.put(queue, new QueueAdapter(this,queue));
- }
- }
- }
- }
-
- private void populateConnections()
- {
-
- List<AMQConnectionModel> actualConnections = _virtualHost.getConnectionRegistry().getConnections();
-
- synchronized(_connectionAdapters)
+ if ( actualQueues != null )
{
- for(AMQConnectionModel conn : actualConnections)
+ synchronized(_queueAdapters)
{
- if(!_connectionAdapters.containsKey(conn))
+ for(AMQQueue queue : actualQueues)
{
- _connectionAdapters.put(conn, new ConnectionAdapter(conn));
+ if(!_queueAdapters.containsKey(queue))
+ {
+ _queueAdapters.put(queue, new QueueAdapter(this, queue));
+ }
}
}
}
-
}
+ @Override
public String getReplicationGroupName()
{
return null; //TODO
@@ -198,12 +225,12 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
attributes = new HashMap<String, Object>(attributes);
- String name = getStringAttribute(Exchange.NAME, attributes, null);
- State state = getEnumAttribute(State.class, Exchange.STATE, attributes, State.ACTIVE);
- boolean durable = getBooleanAttribute(Exchange.DURABLE, attributes, false);
- LifetimePolicy lifetime = getEnumAttribute(LifetimePolicy.class, Exchange.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT);
- String type = getStringAttribute(Exchange.TYPE, attributes, null);
- long ttl = getLongAttribute(Exchange.TIME_TO_LIVE, attributes, 0l);
+ String name = MapValueConverter.getStringAttribute(Exchange.NAME, attributes, null);
+ State state = MapValueConverter.getEnumAttribute(State.class, Exchange.STATE, attributes, State.ACTIVE);
+ boolean durable = MapValueConverter.getBooleanAttribute(Exchange.DURABLE, attributes, false);
+ LifetimePolicy lifetime = MapValueConverter.getEnumAttribute(LifetimePolicy.class, Exchange.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT);
+ String type = MapValueConverter.getStringAttribute(Exchange.TYPE, attributes, null);
+ long ttl = MapValueConverter.getLongAttribute(Exchange.TIME_TO_LIVE, attributes, 0l);
attributes.remove(Exchange.NAME);
attributes.remove(Exchange.STATE);
@@ -266,7 +293,7 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
if (attributes.containsKey(Queue.TYPE))
{
- String typeAttribute = getStringAttribute(Queue.TYPE, attributes, null);
+ String typeAttribute = MapValueConverter.getStringAttribute(Queue.TYPE, attributes, null);
QueueType queueType = null;
try
{
@@ -289,12 +316,12 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
throw new IllegalArgumentException("Sort key is not specified for sorted queue");
}
}
- String name = getStringAttribute(Queue.NAME, attributes, null);
- State state = getEnumAttribute(State.class, Queue.STATE, attributes, State.ACTIVE);
- boolean durable = getBooleanAttribute(Queue.DURABLE, attributes, false);
- LifetimePolicy lifetime = getEnumAttribute(LifetimePolicy.class, Queue.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT);
- long ttl = getLongAttribute(Queue.TIME_TO_LIVE, attributes, 0l);
- boolean exclusive= getBooleanAttribute(Queue.EXCLUSIVE, attributes, false);
+ String name = MapValueConverter.getStringAttribute(Queue.NAME, attributes, null);
+ State state = MapValueConverter.getEnumAttribute(State.class, Queue.STATE, attributes, State.ACTIVE);
+ boolean durable = MapValueConverter.getBooleanAttribute(Queue.DURABLE, attributes, false);
+ LifetimePolicy lifetime = MapValueConverter.getEnumAttribute(LifetimePolicy.class, Queue.LIFETIME_POLICY, attributes, LifetimePolicy.PERMANENT);
+ long ttl = MapValueConverter.getLongAttribute(Queue.TIME_TO_LIVE, attributes, 0l);
+ boolean exclusive= MapValueConverter.getBooleanAttribute(Queue.EXCLUSIVE, attributes, false);
attributes.remove(Queue.NAME);
attributes.remove(Queue.STATE);
@@ -328,11 +355,10 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
String owner = null;
if(exclusive)
{
- Set<Principal> principals =
- SecurityManager.getThreadSubject().getPrincipals();
- if(principals != null && !principals.isEmpty())
+ Principal authenticatedPrincipal = AuthenticatedPrincipal.getOptionalAuthenticatedPrincipalFromSubject(SecurityManager.getThreadSubject());
+ if(authenticatedPrincipal != null)
{
- owner = principals.iterator().next().getName();
+ owner = authenticatedPrincipal.getName();
}
}
try
@@ -370,7 +396,7 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
public String getName()
{
- return _virtualHost.getName();
+ return (String)getAttribute(NAME);
}
public String setName(final String currentName, final String desiredName)
@@ -379,9 +405,36 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
throw new IllegalStateException();
}
+ @Override
public State getActualState()
{
- return getDesiredState();
+ if (_virtualHost == null)
+ {
+ State state = (State)super.getAttribute(STATE);
+ if (state == null)
+ {
+ return State.INITIALISING;
+ }
+ return state;
+ }
+ else
+ {
+ org.apache.qpid.server.virtualhost.State implementationState = _virtualHost.getState();
+ switch(implementationState)
+ {
+ case INITIALISING:
+ return State.INITIALISING;
+ case ACTIVE:
+ return State.ACTIVE;
+ case PASSIVE:
+ return State.QUIESCED;
+ case STOPPED:
+ return State.STOPPED;
+ default:
+ // unexpected state
+ return null;
+ }
+ }
}
public boolean isDurable()
@@ -448,7 +501,7 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
}
@Override
- public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+ public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
{
if(childClass == Exchange.class)
{
@@ -548,7 +601,7 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
if(!_connectionAdapters.containsKey(connection))
{
- adapter = new ConnectionAdapter(connection);
+ adapter = new ConnectionAdapter(connection, getTaskExecutor());
_connectionAdapters.put(connection, adapter);
}
@@ -709,13 +762,9 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
return getId();
}
- else if(NAME.equals(name))
- {
- return getName();
- }
else if(STATE.equals(name))
{
- return State.ACTIVE;
+ return getActualState();
}
else if(DURABLE.equals(name))
{
@@ -737,10 +786,19 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
// TODO
}
- else if(SUPPORTED_EXCHANGE_TYPES.equals(name))
+ else if (_virtualHost != null)
+ {
+ return getAttributeFromVirtualHostImplementation(name);
+ }
+ return super.getAttribute(name);
+ }
+
+ private Object getAttributeFromVirtualHostImplementation(String name)
+ {
+ if(SUPPORTED_EXCHANGE_TYPES.equals(name))
{
List<String> types = new ArrayList<String>();
- for(ExchangeType type : _virtualHost.getExchangeFactory().getRegisteredTypes())
+ for(@SuppressWarnings("rawtypes") ExchangeType type : _virtualHost.getExchangeFactory().getRegisteredTypes())
{
types.add(type.getName().asString());
}
@@ -754,10 +812,6 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
return _virtualHost.getConfiguration().isDeadLetterQueueEnabled();
}
- else if(FEDERATION_TAG.equals(name))
- {
- return _virtualHost.getFederationTag();
- }
else if(HOUSEKEEPING_CHECK_PERIOD.equals(name))
{
return _virtualHost.getConfiguration().getHousekeepingCheckPeriod();
@@ -778,9 +832,9 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
{
return _virtualHost.getMessageStore().getStoreType();
}
- else if(STORE_CONFIGURATION.equals(name))
+ else if(STORE_PATH.equals(name))
{
- // TODO
+ return _virtualHost.getMessageStore().getStoreLocation();
}
else if(STORE_TRANSACTION_IDLE_TIMEOUT_CLOSE.equals(name))
{
@@ -822,13 +876,6 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
}
@Override
- public Object setAttribute(String name, Object expected, Object desired)
- throws IllegalStateException, AccessControlException, IllegalArgumentException
- {
- return super.setAttribute(name, expected, desired); //TODO - Implement
- }
-
- @Override
public Collection<String> getAttributeNames()
{
return AVAILABLE_ATTRIBUTES;
@@ -889,4 +936,111 @@ final class VirtualHostAdapter extends AbstractAdapter implements VirtualHost, E
}
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ if (desiredState == State.ACTIVE)
+ {
+ activate();
+ return true;
+ }
+ else if (desiredState == State.STOPPED)
+ {
+ if (_virtualHost != null)
+ {
+ try
+ {
+ _virtualHost.close();
+ }
+ finally
+ {
+ _broker.getVirtualHostRegistry().unregisterVirtualHost(_virtualHost);
+ }
+ }
+ return true;
+ }
+ else if (desiredState == State.DELETED)
+ {
+ //TODO: add ACL check to authorize the operation
+ if (_virtualHost != null && _virtualHost.getState() == org.apache.qpid.server.virtualhost.State.ACTIVE)
+ {
+ setDesiredState(currentState, State.STOPPED);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private void activate()
+ {
+ VirtualHostRegistry virtualHostRegistry = _broker.getVirtualHostRegistry();
+ String virtualHostName = getName();
+ try
+ {
+ VirtualHostConfiguration configuration = createVirtualHostConfiguration(virtualHostName);
+ _virtualHost = new VirtualHostImpl(_broker.getVirtualHostRegistry(), _brokerStatisticsGatherer, _broker.getSecurityManager(), configuration);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to create virtual host " + virtualHostName, e);
+ }
+
+ virtualHostRegistry.registerVirtualHost(_virtualHost);
+
+ _statistics = new VirtualHostStatisticsAdapter(_virtualHost);
+ _virtualHost.getQueueRegistry().addRegistryChangeListener(this);
+ populateQueues();
+ _virtualHost.getExchangeRegistry().addRegistryChangeListener(this);
+ populateExchanges();
+ _virtualHost.getConnectionRegistry().addRegistryChangeListener(this);
+
+ synchronized(_aliases)
+ {
+ for(Port port :_broker.getPorts())
+ {
+ if (Protocol.hasAmqpProtocol(port.getProtocols()))
+ {
+ _aliases.add(new VirtualHostAliasAdapter(this, port));
+ }
+ }
+ }
+ }
+
+ private VirtualHostConfiguration createVirtualHostConfiguration(String virtualHostName) throws ConfigurationException
+ {
+ VirtualHostConfiguration configuration;
+ String configurationFile = (String)getAttribute(CONFIG_PATH);
+ if (configurationFile == null)
+ {
+ final MyConfiguration basicConfiguration = new MyConfiguration();
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ config.addProperty("store.type", (String)getAttribute(STORE_TYPE));
+ config.addProperty("store.environment-path", (String)getAttribute(STORE_PATH));
+ basicConfiguration.addConfiguration(config);
+
+ CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
+ compositeConfiguration.addConfiguration(new SystemConfiguration());
+ compositeConfiguration.addConfiguration(basicConfiguration);
+ configuration = new VirtualHostConfiguration(virtualHostName, compositeConfiguration , _broker);
+ }
+ else
+ {
+ configuration = new VirtualHostConfiguration(virtualHostName, new File(configurationFile) , _broker);
+ }
+ return configuration;
+ }
+
+ @Override
+ public SecurityManager getSecurityManager()
+ {
+ return _virtualHost.getSecurityManager();
+ }
+
+ @Override
+ public MessageStore getMessageStore()
+ {
+ return _virtualHost.getMessageStore();
+ }
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
index 367d1ff518..91b705b004 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
@@ -43,7 +43,7 @@ public class VirtualHostAliasAdapter extends AbstractAdapter implements Virtual
public VirtualHostAliasAdapter(VirtualHostAdapter virtualHostAdapter, Port port)
{
- super(UUIDGenerator.generateVhostAliasUUID(virtualHostAdapter.getName(), port.getName()));
+ super(UUIDGenerator.generateVhostAliasUUID(virtualHostAdapter.getName(), port.getName()), virtualHostAdapter.getTaskExecutor());
_vhost = virtualHostAdapter;
_port = port;
}
@@ -140,4 +140,11 @@ public class VirtualHostAliasAdapter extends AbstractAdapter implements Virtual
{
throw new UnsupportedOperationException();
}
+
+ @Override
+ protected boolean setState(State currentState, State desiredState)
+ {
+ // TODO: state is not supported at the moment
+ return false;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterImpl.java b/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterImpl.java
index a68ac5439c..917215a42f 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterImpl.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/output/ProtocolOutputConverterImpl.java
@@ -218,55 +218,71 @@ class ProtocolOutputConverterImpl implements ProtocolOutputConverter
final boolean isRedelivered = entry.isRedelivered();
- final AMQBody returnBlock = new AMQBody()
- {
-
- private AMQBody _underlyingBody;
-
- public AMQBody createAMQBody()
- {
- return _methodRegistry.createBasicDeliverBody(consumerTag,
- deliveryTag,
- isRedelivered,
- exchangeName,
- routingKey);
-
-
+ final AMQBody returnBlock = new EncodedDeliveryBody(deliveryTag, routingKey, exchangeName, consumerTag, isRedelivered);
+ return returnBlock;
+ }
+ private class EncodedDeliveryBody implements AMQBody
+ {
+ private final long _deliveryTag;
+ private final AMQShortString _routingKey;
+ private final AMQShortString _exchangeName;
+ private final AMQShortString _consumerTag;
+ private final boolean _isRedelivered;
+ private AMQBody _underlyingBody;
+
+ private EncodedDeliveryBody(long deliveryTag, AMQShortString routingKey, AMQShortString exchangeName, AMQShortString consumerTag, boolean isRedelivered)
+ {
+ _deliveryTag = deliveryTag;
+ _routingKey = routingKey;
+ _exchangeName = exchangeName;
+ _consumerTag = consumerTag;
+ _isRedelivered = isRedelivered;
+ }
+ public AMQBody createAMQBody()
+ {
+ return _methodRegistry.createBasicDeliverBody(_consumerTag,
+ _deliveryTag,
+ _isRedelivered,
+ _exchangeName,
+ _routingKey);
+ }
- }
+ public byte getFrameType()
+ {
+ return AMQMethodBody.TYPE;
+ }
- public byte getFrameType()
+ public int getSize()
+ {
+ if(_underlyingBody == null)
{
- return AMQMethodBody.TYPE;
+ _underlyingBody = createAMQBody();
}
+ return _underlyingBody.getSize();
+ }
- public int getSize()
+ public void writePayload(DataOutput buffer) throws IOException
+ {
+ if(_underlyingBody == null)
{
- if(_underlyingBody == null)
- {
- _underlyingBody = createAMQBody();
- }
- return _underlyingBody.getSize();
+ _underlyingBody = createAMQBody();
}
+ _underlyingBody.writePayload(buffer);
+ }
- public void writePayload(DataOutput buffer) throws IOException
- {
- if(_underlyingBody == null)
- {
- _underlyingBody = createAMQBody();
- }
- _underlyingBody.writePayload(buffer);
- }
+ public void handle(final int channelId, final AMQVersionAwareProtocolSession amqMinaProtocolSession)
+ throws AMQException
+ {
+ throw new AMQException("This block should never be dispatched!");
+ }
- public void handle(final int channelId, final AMQVersionAwareProtocolSession amqMinaProtocolSession)
- throws AMQException
- {
- throw new AMQException("This block should never be dispatched!");
- }
- };
- return returnBlock;
+ @Override
+ public String toString()
+ {
+ return "[" + getClass().getSimpleName() + " underlyingBody: " + String.valueOf(_underlyingBody) + "]";
+ }
}
private AMQBody createEncodedGetOkBody(QueueEntry entry, long deliveryTag, int queueSize)
@@ -368,7 +384,6 @@ class ProtocolOutputConverterImpl implements ProtocolOutputConverter
_methodBody = methodBody;
_headerBody = headerBody;
_contentBody = contentBody;
-
}
public long getSize()
@@ -380,6 +395,19 @@ class ProtocolOutputConverterImpl implements ProtocolOutputConverter
{
AMQFrame.writeFrames(buffer, _channel, _methodBody, _headerBody, _contentBody);
}
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("[").append(getClass().getSimpleName())
+ .append(" methodBody=").append(_methodBody)
+ .append(", headerBody=").append(_headerBody)
+ .append(", contentBody=").append(_contentBody)
+ .append(", channel=").append(_channel).append("]");
+ return builder.toString();
+ }
+
}
public static final class SmallCompositeAMQBodyBlock extends AMQDataBlock
@@ -408,6 +436,17 @@ class ProtocolOutputConverterImpl implements ProtocolOutputConverter
{
AMQFrame.writeFrames(buffer, _channel, _methodBody, _headerBody);
}
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(getClass().getSimpleName())
+ .append("methodBody=").append(_methodBody)
+ .append(", headerBody=").append(_headerBody)
+ .append(", channel=").append(_channel).append("]");
+ return builder.toString();
+ }
}
} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java b/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
new file mode 100644
index 0000000000..7708b90efc
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
@@ -0,0 +1,28 @@
+/*
+ * 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.plugin;
+
+import java.util.Map;
+
+import org.apache.qpid.server.security.AccessControl;
+
+public interface AccessControlFactory
+{
+ AccessControl createInstance(Map<String, Object> attributes);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java
new file mode 100644
index 0000000000..95e6b4feb0
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/plugin/AuthenticationManagerFactory.java
@@ -0,0 +1,31 @@
+/*
+ * 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.plugin;
+
+import java.util.Map;
+
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+
+
+public interface AuthenticationManagerFactory
+{
+ public static final String ATTRIBUTE_TYPE = "authenticationProviderType";
+
+ AuthenticationManager createInstance(Map<String, Object> attributes);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java b/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.java
new file mode 100644
index 0000000000..40ef6ad6a2
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/plugin/ExchangeType.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.server.plugin;
+
+import java.util.UUID;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+
+public interface ExchangeType<T extends Exchange>
+{
+ public AMQShortString getName();
+ public T newInstance(UUID id, VirtualHost host, AMQShortString name,
+ boolean durable, int ticket, boolean autoDelete) throws AMQException;
+ public AMQShortString getDefaultExchangeName();
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java
new file mode 100644
index 0000000000..5d80ca24fd
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/plugin/GroupManagerFactory.java
@@ -0,0 +1,28 @@
+/*
+ * 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.plugin;
+
+import java.util.Map;
+
+import org.apache.qpid.server.security.group.GroupManager;
+
+public interface GroupManagerFactory
+{
+ GroupManager createInstance(Map<String, Object> attributes);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java
new file mode 100644
index 0000000000..af24f62e28
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java
@@ -0,0 +1,32 @@
+/*
+ * 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.plugin;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Plugin;
+
+public interface PluginFactory
+{
+ static final String PLUGIN_TYPE = "pluginType";
+
+ Plugin createInstance(UUID id, Map<String, Object> attributes, Broker broker);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java b/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.java
new file mode 100644
index 0000000000..a0e0346ce0
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/plugin/QpidServiceLoader.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.server.plugin;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Simple facade over a {@link ServiceLoader} to instantiate all configured implementations of an interface.
+ */
+public class QpidServiceLoader<C>
+{
+ private static final Logger _logger = Logger.getLogger(QpidServiceLoader.class);
+
+ public Iterable<C> instancesOf(Class<C> clazz)
+ {
+ return instancesOf(clazz, false);
+ }
+
+ /**
+ * @throws RuntimeException if at least one implementation is not found.
+ */
+ public Iterable<C> atLeastOneInstanceOf(Class<C> clazz)
+ {
+ return instancesOf(clazz, true);
+ }
+
+ private Iterable<C> instancesOf(Class<C> clazz, boolean atLeastOne)
+ {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ Iterator<C> serviceLoaderIterator = ServiceLoader.load(clazz, classLoader).iterator();
+
+ // create a new list so we can log the count
+ List<C> serviceImplementations = new ArrayList<C>();
+ while(serviceLoaderIterator.hasNext())
+ {
+ serviceImplementations.add(serviceLoaderIterator.next());
+ }
+
+ if(atLeastOne && serviceImplementations.isEmpty())
+ {
+ throw new RuntimeException("At least one implementation of " + clazz + " expected");
+ }
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Found " + serviceImplementations.size() + " implementations of " + clazz);
+ }
+
+ return serviceImplementations;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java
deleted file mode 100644
index 12e1eee9ca..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/plugins/Activator.java
+++ /dev/null
@@ -1,51 +0,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.
- */
-package org.apache.qpid.server.plugins;
-
-import org.apache.log4j.Logger;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-public class Activator implements BundleActivator
-{
- private static final Logger _logger = Logger.getLogger(Activator.class);
-
- private BundleContext _context = null;
-
- public void start(BundleContext ctx) throws Exception
- {
- _context = ctx;
- _logger.info("Registering bundle: " + _context.getBundle().getSymbolicName());
- ctx.registerService(ServerConfiguration.class.getName(), ApplicationRegistry.getInstance().getConfiguration(), null);
- }
-
- public void stop(BundleContext ctx) throws Exception
- {
- _logger.info("Stopping bundle: " + _context.getBundle().getSymbolicName());
- _context = null;
- }
-
- public BundleContext getContext()
- {
- return _context;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java
deleted file mode 100644
index d2bb3e037c..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java
+++ /dev/null
@@ -1,91 +0,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.
- */
-package org.apache.qpid.server.plugins;
-
-import org.osgi.framework.Version;
-
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Utility class to convert a map of package name to version numbers into the string
- * with the format expected of a OSGi system package declaration:
- *
- * <code>
- * org.xyz; version=1.0.0, org.xyz.xyz; version=1.0.0,...
- * </code>
- *
- * Additionally, if the caller has provided a qpidPackageReleaseNumber and the package
- * begins org.apache.qpid, this release number will be used, in preference to the one
- * found in the Map.
- *
- * @see org.osgi.framework.Constants#FRAMEWORK_SYSTEMPACKAGES
- *
- */
-public class OsgiSystemPackageUtil
-{
- private static final String APACHE_QPID_PKG_PREFIX = "org.apache.qpid";
-
- private final Map<String, String> _packageNameVersionMap;
- private final Version _qpidPackageReleaseNumber;
-
- public OsgiSystemPackageUtil(final Version qpidPackageReleaseNumber, final Map<String, String> packageNameVersionMap)
- {
- _qpidPackageReleaseNumber = qpidPackageReleaseNumber;
- _packageNameVersionMap = packageNameVersionMap;
- }
-
- public String getFormattedSystemPackageString()
- {
- if (_packageNameVersionMap == null || _packageNameVersionMap.size() == 0)
- {
- return null;
- }
-
- final StringBuilder packages = new StringBuilder();
-
- for(Iterator<String> itr = _packageNameVersionMap.keySet().iterator(); itr.hasNext();)
- {
- final String packageName = itr.next();
- final String packageVersion;
-
- if (_qpidPackageReleaseNumber != null && packageName.startsWith(APACHE_QPID_PKG_PREFIX))
- {
- packageVersion = _qpidPackageReleaseNumber.toString();
- }
- else
- {
- packageVersion = _packageNameVersionMap.get(packageName);
- }
-
- packages.append(packageName);
- packages.append("; ");
- packages.append("version=");
- packages.append(packageVersion);
-
- if (itr.hasNext())
- {
- packages.append(", ");
- }
- }
-
- return packages.toString();
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties b/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties
deleted file mode 100644
index 6479546355..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties
+++ /dev/null
@@ -1,135 +0,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.
-#
-
-#
-# OSGi framework system package list
-#
-# PluginManager uses these properties to construct the FRAMEWORK_SYSTEMPACKAGES list
-#
-
-# Format is:
-# <package>=<version>
-# and PluginManager will convert this into:
-# <package>; version=<version>
-# e.g. org.osgi.framework; version=1.3.0
-
-javax.management.openmbean=1.0.0
-javax.management=1.0.0
-javax.management.remote.rmi=1.0.0
-javax.management.remote=1.0.0
-javax.management.monitor=1.0.0
-
-javax.crypto=1
-javax.crypto.spec=1
-
-javax.servlet=2
-javax.servlet.http=2
-
-javax.security.auth=1.0.0
-javax.security.auth.callback=1.0.0
-javax.security.auth.login=1.0.0
-javax.security.sasl=1.0.0
-javax.security=1.0.0
-
-javax.rmi.ssl=1.0.0
-
-org.xml.sax=1.0.0
-org.xml.sax.helpers=1.0.0
-
-org.osgi.framework=1.3.0
-org.osgi.service.packageadmin=1.2.0
-org.osgi.service.startlevel=1.0.0
-org.osgi.service.url=1.0.0
-org.osgi.util.tracker=1.0.0
-
-org.apache.commons.codec=1.3.0
-org.apache.commons.codec.binary=1.3.0
-
-org.apache.commons.configuration=1.0.0
-
-org.apache.commons.lang=1.0.0
-org.apache.commons.lang.builder=1.0.0
-org.apache.commons.lang.time=1.0.0
-org.apache.commons.logging=1.0.0
-
-org.apache.log4j=1.2.16
-
-org.slf4j=1.6.1
-
-org.eclipse.jetty=7.6.3
-org.eclipse.jetty.http=7.6.3
-org.eclipse.jetty.io=7.6.3
-org.eclipse.jetty.io.nio=7.6.3
-org.eclipse.jetty.security=7.6.3
-org.eclipse.jetty.server=7.6.3
-org.eclipse.jetty.server.session=7.6.3
-org.eclipse.jetty.server.ssl=7.6.3
-org.eclipse.jetty.server.nio=7.6.3
-org.eclipse.jetty.servlet=7.6.3
-org.eclipse.jetty.util.ssl=7.6.3
-
-org.codehaus.jackson=1.9.0
-org.codehaus.jackson.map=1.9.0
-
-# For Qpid packages (org.apache.qpid), the version number is automatically overridden by QpidPropertis#getReleaseVersion()
-
-org.apache.qpid=0.0.0
-org.apache.qpid.common=0.0.0
-org.apache.qpid.exchange=0.0.0
-org.apache.qpid.framing=0.0.0
-org.apache.qpid.management.common.mbeans.annotations=0.0.0
-org.apache.qpid.management.common.mbeans=0.0.0
-org.apache.qpid.protocol=0.0.0
-org.apache.qpid.transport=0.0.0
-org.apache.qpid.transport.codec=0.0.0
-org.apache.qpid.server.binding=0.0.0
-org.apache.qpid.server.model=0.0.0
-org.apache.qpid.server.model.adapter=0.0.0
-org.apache.qpid.server.model.impl=0.0.0
-org.apache.qpid.server.configuration=0.0.0
-org.apache.qpid.server.configuration.plugins=0.0.0
-org.apache.qpid.server.configuration.management=0.0.0
-org.apache.qpid.server.connection=0.0.0
-org.apache.qpid.server.exchange=0.0.0
-org.apache.qpid.server.logging=0.0.0
-org.apache.qpid.server.logging.log4j=0.0.0
-org.apache.qpid.server.logging.actors=0.0.0
-org.apache.qpid.server.logging.messages=0.0.0
-org.apache.qpid.server.logging.subjects=0.0.0
-org.apache.qpid.server.message=0.0.0
-org.apache.qpid.server.persistent=0.0.0
-org.apache.qpid.server.plugins=0.0.0
-org.apache.qpid.server.protocol=0.0.0
-org.apache.qpid.server.queue=0.0.0
-org.apache.qpid.server.subscription=0.0.0
-org.apache.qpid.server.registry=0.0.0
-org.apache.qpid.server.security=0.0.0
-org.apache.qpid.server.security.access=0.0.0
-org.apache.qpid.server.security.access.plugins=0.0.0
-org.apache.qpid.server.security.auth=0.0.0
-org.apache.qpid.server.security.auth.sasl=0.0.0
-org.apache.qpid.server.security.auth.manager=0.0.0
-org.apache.qpid.server.security.auth.rmi=0.0.0
-org.apache.qpid.server.stats=0.0.0
-org.apache.qpid.server.virtualhost=0.0.0
-org.apache.qpid.server.virtualhost.plugins=0.0.0
-org.apache.qpid.util=0.0.0
-
-org.apache.qpid.server.store.berkeleydb=0.0.0
-
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java
deleted file mode 100644
index 6dcf688f2a..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/plugins/Plugin.java
+++ /dev/null
@@ -1,32 +0,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.
- */
-package org.apache.qpid.server.plugins;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-
-public interface Plugin
-{
-
- /**
- * Provide Configuration to this plugin
- */
- public void configure(ConfigurationPlugin config) throws ConfigurationException;
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java
deleted file mode 100644
index 7ea2b95b89..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginFactory.java
+++ /dev/null
@@ -1,32 +0,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.
- */
-package org.apache.qpid.server.plugins;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-
-public interface PluginFactory<P extends Plugin>
-{
- public Class<P> getPluginClass();
-
- public String getPluginName();
-
- public P newInstance(ConfigurationPlugin config) throws ConfigurationException;
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java
deleted file mode 100644
index 74abbccd2b..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java
+++ /dev/null
@@ -1,403 +0,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.
- */
-package org.apache.qpid.server.plugins;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.felix.framework.Felix;
-import org.apache.felix.framework.util.StringMap;
-import org.apache.log4j.Logger;
-import org.apache.qpid.common.Closeable;
-import org.apache.qpid.common.QpidProperties;
-import org.apache.qpid.server.configuration.TopicConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionConfiguration.SlowConsumerDetectionConfigurationFactory;
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionPolicyConfiguration.SlowConsumerDetectionPolicyConfigurationFactory;
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionQueueConfiguration.SlowConsumerDetectionQueueConfigurationFactory;
-import org.apache.qpid.server.exchange.ExchangeType;
-import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.SecurityPluginFactory;
-import org.apache.qpid.server.security.access.plugins.LegacyAccess;
-import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManagerPluginFactory;
-import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.KerberosAuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.SimpleLDAPAuthenticationManager;
-import org.apache.qpid.server.virtualhost.plugins.SlowConsumerDetection;
-import org.apache.qpid.server.virtualhost.plugins.VirtualHostPluginFactory;
-import org.apache.qpid.server.virtualhost.plugins.policies.TopicDeletePolicy;
-import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPluginFactory;
-import org.apache.qpid.util.FileUtils;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Version;
-import org.osgi.framework.launch.Framework;
-import org.osgi.util.tracker.ServiceTracker;
-
-import static org.apache.felix.framework.util.FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP;
-import static org.apache.felix.main.AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY;
-import static org.apache.felix.main.AutoProcessor.AUTO_DEPLOY_DIR_PROPERY;
-import static org.apache.felix.main.AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE;
-import static org.apache.felix.main.AutoProcessor.AUTO_DEPLOY_START_VALUE;
-import static org.apache.felix.main.AutoProcessor.process;
-import static org.osgi.framework.Constants.FRAMEWORK_STORAGE;
-import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN;
-import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT;
-import static org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES;
-
-/**
- * Provides access to pluggable elements, such as exchanges
- */
-@SuppressWarnings("unchecked")
-public class PluginManager implements Closeable
-{
- private static final Logger _logger = Logger.getLogger(PluginManager.class);
-
- private static final int FELIX_STOP_TIMEOUT = 30000;
-
- private Framework _felix;
-
- private ServiceTracker _exchangeTracker = null;
- private ServiceTracker _securityTracker = null;
- private ServiceTracker _configTracker = null;
- private ServiceTracker _virtualHostTracker = null;
- private ServiceTracker _policyTracker = null;
- private ServiceTracker _authenticationManagerTracker = null;
-
- private Activator _activator;
-
- private final List<ServiceTracker> _trackers = new ArrayList<ServiceTracker>();
- private Map<String, SecurityPluginFactory> _securityPlugins = new HashMap<String, SecurityPluginFactory>();
- private Map<List<String>, ConfigurationPluginFactory> _configPlugins = new IdentityHashMap<List<String>, ConfigurationPluginFactory>();
- private Map<String, VirtualHostPluginFactory> _vhostPlugins = new HashMap<String, VirtualHostPluginFactory>();
- private Map<String, SlowConsumerPolicyPluginFactory> _policyPlugins = new HashMap<String, SlowConsumerPolicyPluginFactory>();
- private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> _authenticationManagerPlugins = new HashMap<String, AuthenticationManagerPluginFactory<? extends Plugin>>();
-
- /** The default name of the OSGI system package list. */
- private static final String DEFAULT_RESOURCE_NAME = "org/apache/qpid/server/plugins/OsgiSystemPackages.properties";
-
- /** The name of the override system property that holds the name of the OSGI system package list. */
- private static final String FILE_PROPERTY = "qpid.osgisystempackages.properties";
-
- private static final String OSGI_SYSTEM_PACKAGES;
-
- static
- {
- final String filename = System.getProperty(FILE_PROPERTY);
- final InputStream is = FileUtils.openFileOrDefaultResource(filename, DEFAULT_RESOURCE_NAME,
- PluginManager.class.getClassLoader());
-
- try
- {
- Version qpidReleaseVersion;
- try
- {
- qpidReleaseVersion = Version.parseVersion(QpidProperties.getReleaseVersion());
- }
- catch (IllegalArgumentException iae)
- {
- qpidReleaseVersion = null;
- }
-
- final Properties p = new Properties();
- p.load(is);
-
- final OsgiSystemPackageUtil osgiSystemPackageUtil = new OsgiSystemPackageUtil(qpidReleaseVersion, (Map)p);
-
- OSGI_SYSTEM_PACKAGES = osgiSystemPackageUtil.getFormattedSystemPackageString();
-
- _logger.debug("List of OSGi system packages to be added: " + OSGI_SYSTEM_PACKAGES);
- }
- catch (IOException e)
- {
- _logger.error("Error reading OSGI system package list", e);
- throw new ExceptionInInitializerError(e);
- }
- }
-
-
- public PluginManager(String pluginPath, String cachePath, BundleContext bundleContext) throws Exception
- {
- // Store all non-OSGi plugins
- // A little gross that we have to add them here, but not all the plugins are OSGIfied
- for (SecurityPluginFactory<?> pluginFactory : Arrays.asList(LegacyAccess.FACTORY))
- {
- _securityPlugins.put(pluginFactory.getPluginName(), pluginFactory);
- }
- for (ConfigurationPluginFactory configFactory : Arrays.asList(
- TopicConfiguration.FACTORY,
- SecurityManager.SecurityConfiguration.FACTORY,
- LegacyAccess.LegacyAccessConfiguration.FACTORY,
- new SlowConsumerDetectionConfigurationFactory(),
- new SlowConsumerDetectionPolicyConfigurationFactory(),
- new SlowConsumerDetectionQueueConfigurationFactory(),
- PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration.FACTORY,
- AnonymousAuthenticationManager.AnonymousAuthenticationManagerConfiguration.FACTORY,
- KerberosAuthenticationManager.KerberosAuthenticationManagerConfiguration.FACTORY,
- SimpleLDAPAuthenticationManager.SimpleLDAPAuthenticationManagerConfiguration.FACTORY,
- ExternalAuthenticationManager.ExternalAuthenticationManagerConfiguration.FACTORY
- ))
- {
- _configPlugins.put(configFactory.getParentPaths(), configFactory);
- }
- for (SlowConsumerPolicyPluginFactory pluginFactory : Arrays.asList(
- new TopicDeletePolicy.TopicDeletePolicyFactory()))
- {
- _policyPlugins.put(pluginFactory.getPluginName(), pluginFactory);
- }
- for (VirtualHostPluginFactory pluginFactory : Arrays.asList(
- new SlowConsumerDetection.SlowConsumerFactory()))
- {
- _vhostPlugins.put(pluginFactory.getClass().getName(), pluginFactory);
- }
-
- for (AuthenticationManagerPluginFactory<? extends Plugin> pluginFactory : Arrays.asList(
- PrincipalDatabaseAuthenticationManager.FACTORY, AnonymousAuthenticationManager.FACTORY,
- KerberosAuthenticationManager.FACTORY, SimpleLDAPAuthenticationManager.FACTORY,
- ExternalAuthenticationManager.FACTORY))
- {
- _authenticationManagerPlugins.put(pluginFactory.getPluginName(), pluginFactory);
- }
-
- if(bundleContext == null)
- {
- // Check the plugin directory path is set and exist
- if (pluginPath == null)
- {
- _logger.info("No plugin path specified, no plugins will be loaded.");
- return;
- }
- File pluginDir = new File(pluginPath);
- if (!pluginDir.exists())
- {
- _logger.warn("Plugin dir : " + pluginDir + " does not exist.");
- return;
- }
-
- // Add the bundle provided service interface package and the core OSGi
- // packages to be exported from the class path via the system bundle.
-
- // Setup OSGi configuration property map
- final StringMap configMap = new StringMap(false);
- configMap.put(FRAMEWORK_SYSTEMPACKAGES, OSGI_SYSTEM_PACKAGES);
-
- // No automatic shutdown hook
- configMap.put("felix.shutdown.hook", "false");
-
- // Add system activator
- List<BundleActivator> activators = new ArrayList<BundleActivator>();
- _activator = new Activator();
- activators.add(_activator);
- configMap.put(SYSTEMBUNDLE_ACTIVATORS_PROP, activators);
-
- if (cachePath != null)
- {
- File cacheDir = new File(cachePath);
- if (!cacheDir.exists() && cacheDir.canWrite())
- {
- _logger.info("Creating plugin cache directory: " + cachePath);
- cacheDir.mkdir();
- }
-
- // Set plugin cache directory and empty it
- _logger.info("Cache bundles in directory " + cachePath);
- configMap.put(FRAMEWORK_STORAGE, cachePath);
- }
- configMap.put(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
-
- // Set directory with plugins to auto-deploy
- _logger.info("Auto deploying bundles from directory " + pluginPath);
- configMap.put(AUTO_DEPLOY_DIR_PROPERY, pluginPath);
- configMap.put(AUTO_DEPLOY_ACTION_PROPERY, AUTO_DEPLOY_INSTALL_VALUE + "," + AUTO_DEPLOY_START_VALUE);
-
- // Start plugin manager
- _felix = new Felix(configMap);
- try
- {
- _logger.info("Starting plugin manager framework");
- _felix.init();
- process(configMap, _felix.getBundleContext());
- _felix.start();
- _logger.info("Started plugin manager framework");
- }
- catch (BundleException e)
- {
- throw new ConfigurationException("Could not start plugin manager: " + e.getMessage(), e);
- }
-
- bundleContext = _activator.getContext();
- }
- else
- {
- _logger.info("Using the specified external BundleContext");
- }
-
- _exchangeTracker = new ServiceTracker(bundleContext, ExchangeType.class.getName(), null);
- _exchangeTracker.open();
- _trackers.add(_exchangeTracker);
-
- _securityTracker = new ServiceTracker(bundleContext, SecurityPluginFactory.class.getName(), null);
- _securityTracker.open();
- _trackers.add(_securityTracker);
-
- _configTracker = new ServiceTracker(bundleContext, ConfigurationPluginFactory.class.getName(), null);
- _configTracker.open();
- _trackers.add(_configTracker);
-
- _virtualHostTracker = new ServiceTracker(bundleContext, VirtualHostPluginFactory.class.getName(), null);
- _virtualHostTracker.open();
- _trackers.add(_virtualHostTracker);
-
- _policyTracker = new ServiceTracker(bundleContext, SlowConsumerPolicyPluginFactory.class.getName(), null);
- _policyTracker.open();
- _trackers.add(_policyTracker);
-
- _authenticationManagerTracker = new ServiceTracker(bundleContext, AuthenticationManagerPluginFactory.class.getName(), null);
- _authenticationManagerTracker.open();
- _trackers.add(_authenticationManagerTracker);
-
- _logger.info("Opened service trackers");
- }
-
- private static <T> Map<String, T> getServices(ServiceTracker tracker)
- {
- Map<String, T> services = new HashMap<String, T>();
-
- if ((tracker != null) && (tracker.getServices() != null))
- {
- for (Object service : tracker.getServices())
- {
- if (service instanceof PluginFactory<?>)
- {
- services.put(((PluginFactory<?>) service).getPluginName(), (T) service);
- }
- else
- {
- services.put(service.getClass().getName(), (T) service);
- }
- }
- }
-
- return services;
- }
-
- public static <T> Map<String, T> getServices(ServiceTracker tracker, Map<String, T> plugins)
- {
- Map<String, T> services = getServices(tracker);
- services.putAll(plugins);
- return services;
- }
-
- public Map<List<String>, ConfigurationPluginFactory> getConfigurationPlugins()
- {
- Map<List<String>, ConfigurationPluginFactory> services = new IdentityHashMap<List<String>, ConfigurationPluginFactory>();
-
- if (_configTracker != null && _configTracker.getServices() != null)
- {
- for (Object service : _configTracker.getServices())
- {
- ConfigurationPluginFactory factory = (ConfigurationPluginFactory) service;
- services.put(factory.getParentPaths(), factory);
- }
- }
-
- services.putAll(_configPlugins);
-
- return services;
- }
-
- public Map<String, VirtualHostPluginFactory> getVirtualHostPlugins()
- {
- return getServices(_virtualHostTracker, _vhostPlugins);
- }
-
- public Map<String, SlowConsumerPolicyPluginFactory> getSlowConsumerPlugins()
- {
- return getServices(_policyTracker, _policyPlugins);
- }
-
- public Map<String, ExchangeType<?>> getExchanges()
- {
- return getServices(_exchangeTracker);
- }
-
- public Map<String, SecurityPluginFactory> getSecurityPlugins()
- {
- return getServices(_securityTracker, _securityPlugins);
- }
-
- public Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> getAuthenticationManagerPlugins()
- {
- return getServices(_authenticationManagerTracker, _authenticationManagerPlugins);
- }
-
- public void close()
- {
- try
- {
- // Close all bundle trackers
- for(ServiceTracker tracker : _trackers)
- {
- tracker.close();
- }
- }
- finally
- {
- if (_felix != null)
- {
- _logger.info("Stopping plugin manager framework");
- try
- {
- // FIXME should be stopAndWait() but hangs VM, need upgrade in felix
- _felix.stop();
- }
- catch (BundleException e)
- {
- // Ignore
- }
-
- try
- {
- _felix.waitForStop(FELIX_STOP_TIMEOUT);
- }
- catch (InterruptedException e)
- {
- // Ignore
- }
- _logger.info("Stopped plugin manager framework");
- }
- else
- {
- _logger.info("Plugin manager was started with an external BundleContext, " +
- "skipping remaining shutdown tasks");
- }
- }
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java
index 1e649c3cb7..ee1ef2418a 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java
@@ -29,11 +29,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -52,10 +52,7 @@ import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
import org.apache.qpid.protocol.ServerProtocolEngine;
import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.ConnectionConfig;
-import org.apache.qpid.server.configuration.ConnectionConfigType;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.handler.ServerMethodDispatcherImpl;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogSubject;
@@ -64,10 +61,11 @@ import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.ManagementActor;
import org.apache.qpid.server.logging.messages.ConnectionMessages;
import org.apache.qpid.server.logging.subjects.ConnectionLogSubject;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.output.ProtocolOutputConverter;
import org.apache.qpid.server.output.ProtocolOutputConverterRegistry;
import org.apache.qpid.server.queue.QueueEntry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
import org.apache.qpid.server.state.AMQState;
import org.apache.qpid.server.state.AMQStateManager;
import org.apache.qpid.server.stats.StatisticsCounter;
@@ -75,13 +73,12 @@ import org.apache.qpid.server.subscription.ClientDeliveryMethod;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.subscription.SubscriptionImpl;
import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.TransportException;
import org.apache.qpid.transport.network.NetworkConnection;
import org.apache.qpid.util.BytesDataOutput;
-public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSession, ConnectionConfig
+public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSession
{
private static final Logger _logger = Logger.getLogger(AMQProtocolEngine.class);
@@ -115,7 +112,7 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
private volatile boolean _closed;
// maximum number of channels this session should have
- private long _maxNoOfChannels = ApplicationRegistry.getInstance().getConfiguration().getMaxChannelCount();
+ private long _maxNoOfChannels;
/* AMQP Version for this session */
private ProtocolVersion _protocolVersion = ProtocolVersion.getLatestSupportedVersion();
@@ -142,8 +139,6 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
private long _maxFrameSize;
private final AtomicBoolean _closing = new AtomicBoolean(false);
- private final UUID _qmfId;
- private final ConfigStore _configStore;
private long _createTime = System.currentTimeMillis();
private StatisticsCounter _messagesDelivered, _dataDelivered, _messagesReceived, _dataReceived;
@@ -156,23 +151,25 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
private boolean _blocking;
private final Lock _receivedLock;
+ private AtomicLong _lastWriteTime = new AtomicLong(System.currentTimeMillis());
+ private final Broker _broker;
- public AMQProtocolEngine(VirtualHostRegistry virtualHostRegistry, NetworkConnection network, final long connectionId)
+
+ public AMQProtocolEngine(Broker broker, NetworkConnection network, final long connectionId)
{
+ _broker = broker;
+ _maxNoOfChannels = (Integer)broker.getAttribute(Broker.SESSION_COUNT_LIMIT);
_receivedLock = new ReentrantLock();
- _stateManager = new AMQStateManager(virtualHostRegistry, this);
+ _stateManager = new AMQStateManager(broker, this);
_codecFactory = new AMQCodecFactory(true, this);
setNetworkConnection(network);
_connectionID = connectionId;
- _actor = new AMQPConnectionActor(this, virtualHostRegistry.getApplicationRegistry().getRootMessageLogger());
+ _actor = new AMQPConnectionActor(this, _broker.getRootMessageLogger());
_logSubject = new ConnectionLogSubject(this);
- _configStore = virtualHostRegistry.getConfigStore();
- _qmfId = _configStore.createId();
-
_actor.message(ConnectionMessages.OPEN(null, null, null, false, false, false));
initialiseStatistics();
@@ -309,9 +306,13 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
try
{
+ long startTime = 0;
+ String frameToString = null;
if (_logger.isDebugEnabled())
{
- _logger.debug("Frame Received: " + frame);
+ startTime = System.currentTimeMillis();
+ frameToString = frame.toString();
+ _logger.debug("RECV: " + frame);
}
// Check that this channel is not closing
@@ -346,6 +347,11 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
closeChannel(channelId);
throw e;
}
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Frame handled in " + (System.currentTimeMillis() - startTime) + " ms. Frame: " + frameToString);
+ }
}
finally
{
@@ -367,7 +373,7 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
// This sets the protocol version (and hence framing classes) for this session.
setProtocolVersion(pv);
- String mechanisms = ApplicationRegistry.getInstance().getAuthenticationManager(getLocalAddress()).getMechanisms();
+ String mechanisms = _broker.getSubjectCreator(getLocalAddress()).getMechanisms();
String locales = "en_US";
@@ -549,8 +555,17 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
final ByteBuffer buf = asByteBuffer(frame);
_writtenBytes += buf.remaining();
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("SEND: " + frame);
+ }
+
_sender.send(buf);
- _lastIoTime = System.currentTimeMillis();
+ final long time = System.currentTimeMillis();
+ _lastIoTime = time;
+ _lastWriteTime.set(time);
+
if(!_deferFlush)
{
_sender.flush();
@@ -749,7 +764,7 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
if (delay > 0)
{
_network.setMaxWriteIdle(delay);
- _network.setMaxReadIdle((int) (ApplicationRegistry.getInstance().getConfiguration().getHeartBeatTimeout() * delay));
+ _network.setMaxReadIdle(BrokerProperties.DEFAULT_HEART_BEAT_TIMEOUT_FACTOR * delay);
}
}
@@ -796,8 +811,6 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
closeAllChannels();
- getConfigStore().removeConfiguredObject(this);
-
for (Task task : _taskList)
{
task.doTask(this);
@@ -983,7 +996,6 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
_virtualHost.getConnectionRegistry().registerConnection(this);
- _configStore.addConfiguredObject(this);
}
public void addSessionCloseTask(Task task)
@@ -1017,7 +1029,7 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
public Principal getAuthorizedPrincipal()
{
- return _authorizedSubject == null ? null : _authorizedSubject.getPrincipals().iterator().next();
+ return _authorizedSubject == null ? null : AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(_authorizedSubject);
}
public SocketAddress getRemoteAddress()
@@ -1070,12 +1082,12 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
public void readerIdle()
{
- // Nothing
+ // TODO - enforce disconnect on lack of inbound data
}
public synchronized void writerIdle()
{
- _sender.send(asByteBuffer(HeartbeatBody.FRAME));
+ writeFrame(HeartbeatBody.FRAME);
}
public void exception(Throwable throwable)
@@ -1185,32 +1197,11 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
return null;
}
- public ConfigStore getConfigStore()
- {
- return _configStore;
- }
-
- public ConnectionConfigType getConfigType()
- {
- return ConnectionConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return getVirtualHost();
- }
-
public boolean isDurable()
{
return false;
}
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
public long getConnectionId()
{
return getSessionID();
@@ -1494,4 +1485,16 @@ public class AMQProtocolEngine implements ServerProtocolEngine, AMQProtocolSessi
{
return _receivedLock;
}
+
+ @Override
+ public long getLastReadTime()
+ {
+ return _lastReceivedTime;
+ }
+
+ @Override
+ public long getLastWriteTime()
+ {
+ return _lastWriteTime.get();
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java
index a8f62b0fa2..9d9bbe807b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java
@@ -36,8 +36,7 @@ import org.apache.qpid.server.queue.SimpleAMQQueue;
*/
public interface AMQSessionModel extends Comparable<AMQSessionModel>
{
- /** Unique session ID across entire broker*/
- public UUID getQMFId();
+ public UUID getId();
public AMQConnectionModel getConnectionModel();
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java
index 5c92aa95b6..d9e5e1c473 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java
@@ -28,7 +28,7 @@ import java.util.Set;
import org.apache.log4j.Logger;
import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.transport.ServerConnection;
import org.apache.qpid.transport.ConnectionDelegate;
import org.apache.qpid.transport.Sender;
@@ -42,24 +42,24 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
private Set<AmqpProtocolVersion> _supported;
private String _fqdn;
- private IApplicationRegistry _appRegistry;
+ private final Broker _broker;
private NetworkConnection _network;
private Sender<ByteBuffer> _sender;
private final AmqpProtocolVersion _defaultSupportedReply;
private volatile ServerProtocolEngine _delegate = new SelfDelegateProtocolEngine();
- public MultiVersionProtocolEngine(final IApplicationRegistry appRegistry,
+ public MultiVersionProtocolEngine(final Broker broker,
final Set<AmqpProtocolVersion> supported,
final AmqpProtocolVersion defaultSupportedReply,
final long id,
final NetworkConnection network)
{
- this(appRegistry, supported, defaultSupportedReply, id);
+ this(broker, supported, defaultSupportedReply, id);
setNetworkConnection(network);
}
- public MultiVersionProtocolEngine(final IApplicationRegistry appRegistry,
+ public MultiVersionProtocolEngine(final Broker broker,
final Set<AmqpProtocolVersion> supported,
final AmqpProtocolVersion defaultSupportedReply,
final long id)
@@ -71,7 +71,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
}
_id = id;
- _appRegistry = appRegistry;
+ _broker = broker;
_supported = supported;
_defaultSupportedReply = defaultSupportedReply;
}
@@ -217,6 +217,18 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
_sender = sender;
}
+ @Override
+ public long getLastReadTime()
+ {
+ return _delegate.getLastReadTime();
+ }
+
+ @Override
+ public long getLastWriteTime()
+ {
+ return _delegate.getLastWriteTime();
+ }
+
private static interface DelegateCreator
{
@@ -240,7 +252,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new AMQProtocolEngine(_appRegistry.getVirtualHostRegistry(), _network, _id);
+ return new AMQProtocolEngine(_broker, _network, _id);
}
};
@@ -260,7 +272,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new AMQProtocolEngine(_appRegistry.getVirtualHostRegistry(), _network, _id);
+ return new AMQProtocolEngine(_broker, _network, _id);
}
};
@@ -280,7 +292,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new AMQProtocolEngine(_appRegistry.getVirtualHostRegistry(), _network, _id);
+ return new AMQProtocolEngine(_broker, _network, _id);
}
};
@@ -301,13 +313,15 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- final ConnectionDelegate connDelegate =
- new org.apache.qpid.server.transport.ServerConnectionDelegate(_appRegistry, _fqdn, _appRegistry.getAuthenticationManager(getLocalAddress()));
+ final ConnectionDelegate connDelegate = new org.apache.qpid.server.transport.ServerConnectionDelegate(_broker,
+ _fqdn, _broker.getSubjectCreator(getLocalAddress()));
ServerConnection conn = new ServerConnection(_id);
- conn.setConnectionDelegate(connDelegate);
- return new ProtocolEngine_0_10( conn, _network, _appRegistry);
+ conn.setConnectionDelegate(connDelegate);
+ conn.setRemoteAddress(_network.getRemoteAddress());
+ conn.setLocalAddress(_network.getLocalAddress());
+ return new ProtocolEngine_0_10( conn, _network);
}
};
@@ -327,7 +341,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new ProtocolEngine_1_0_0(_appRegistry,_id);
+ return new ProtocolEngine_1_0_0(_network, _broker, _id);
}
};
@@ -347,7 +361,7 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public ServerProtocolEngine getProtocolEngine()
{
- return new ProtocolEngine_1_0_0_SASL(_network, _appRegistry, _id);
+ return new ProtocolEngine_1_0_0_SASL(_network, _broker, _id);
}
};
@@ -407,6 +421,18 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
}
+ @Override
+ public long getLastReadTime()
+ {
+ return 0;
+ }
+
+ @Override
+ public long getLastWriteTime()
+ {
+ return 0;
+ }
+
public long getConnectionId()
{
return _id;
@@ -547,7 +573,29 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
public void closed()
{
-
+ try
+ {
+ _delegate = new ClosedDelegateProtocolEngine();
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Connection from " + getRemoteAddress() + " was closed before any protocol version was established.");
+ }
+ }
+ catch(Exception e)
+ {
+ //ignore
+ }
+ finally
+ {
+ try
+ {
+ _network.close();
+ }
+ catch(Exception e)
+ {
+ //ignore
+ }
+ }
}
public void writerIdle()
@@ -564,5 +612,17 @@ public class MultiVersionProtocolEngine implements ServerProtocolEngine
{
}
+
+ @Override
+ public long getLastReadTime()
+ {
+ return 0;
+ }
+
+ @Override
+ public long getLastWriteTime()
+ {
+ return 0;
+ }
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
index 552b1c7054..9f078c8999 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
@@ -22,8 +22,7 @@ package org.apache.qpid.server.protocol;
import org.apache.qpid.protocol.ProtocolEngineFactory;
import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
@@ -32,11 +31,12 @@ public class MultiVersionProtocolEngineFactory implements ProtocolEngineFactory
{
private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
- private final IApplicationRegistry _appRegistry;
+ private final Broker _broker;
private final Set<AmqpProtocolVersion> _supported;
private final AmqpProtocolVersion _defaultSupportedReply;
- public MultiVersionProtocolEngineFactory(final Set<AmqpProtocolVersion> supportedVersions, final AmqpProtocolVersion defaultSupportedReply)
+ public MultiVersionProtocolEngineFactory(Broker broker,
+ final Set<AmqpProtocolVersion> supportedVersions, final AmqpProtocolVersion defaultSupportedReply)
{
if(defaultSupportedReply != null && !supportedVersions.contains(defaultSupportedReply))
{
@@ -44,14 +44,14 @@ public class MultiVersionProtocolEngineFactory implements ProtocolEngineFactory
+ ") to an unsupported protocol version initiation is itself not supported!");
}
- _appRegistry = ApplicationRegistry.getInstance();
+ _broker = broker;
_supported = supportedVersions;
_defaultSupportedReply = defaultSupportedReply;
}
public ServerProtocolEngine newProtocolEngine()
{
- return new MultiVersionProtocolEngine(_appRegistry, _supported, _defaultSupportedReply, ID_GENERATOR.getAndIncrement());
+ return new MultiVersionProtocolEngine(_broker, _supported, _defaultSupportedReply, ID_GENERATOR.getAndIncrement());
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java
index fd6e9300ec..d5f7fe486c 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java
@@ -21,13 +21,7 @@
package org.apache.qpid.server.protocol;
import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.ConnectionConfig;
-import org.apache.qpid.server.configuration.ConnectionConfigType;
-import org.apache.qpid.server.configuration.VirtualHostConfig;
import org.apache.qpid.server.logging.messages.ConnectionMessages;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.transport.ServerConnection;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.network.Assembler;
@@ -37,9 +31,9 @@ import org.apache.qpid.transport.network.NetworkConnection;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
-import java.util.UUID;
-public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocolEngine, ConnectionConfig
+
+public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocolEngine
{
public static final int MAX_FRAME_SIZE = 64 * 1024 - 1;
@@ -47,20 +41,17 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
private long _readBytes;
private long _writtenBytes;
private ServerConnection _connection;
- private final UUID _qmfId;
- private final IApplicationRegistry _appRegistry;
+
private long _createTime = System.currentTimeMillis();
+ private long _lastReadTime;
+ private long _lastWriteTime;
public ProtocolEngine_0_10(ServerConnection conn,
- NetworkConnection network,
- final IApplicationRegistry appRegistry)
+ NetworkConnection network)
{
super(new Assembler(conn));
_connection = conn;
- _connection.setConnectionConfig(this);
- _qmfId = appRegistry.getConfigStore().createId();
- _appRegistry = appRegistry;
if(network != null)
{
@@ -68,14 +59,6 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
}
- _connection.onOpen(new Runnable()
- {
- public void run()
- {
- getConfigStore().addConfiguredObject(ProtocolEngine_0_10.this);
- }
- });
-
}
public void setNetworkConnection(NetworkConnection network)
@@ -87,13 +70,61 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
{
_network = network;
- _connection.setSender(new Disassembler(sender, MAX_FRAME_SIZE));
+ _connection.setNetworkConnection(network);
+ _connection.setSender(new Disassembler(wrapSender(sender), MAX_FRAME_SIZE));
_connection.setPeerPrincipal(_network.getPeerPrincipal());
// FIXME Two log messages to maintain compatibility with earlier protocol versions
_connection.getLogActor().message(ConnectionMessages.OPEN(null, null, null, false, false, false));
_connection.getLogActor().message(ConnectionMessages.OPEN(null, "0-10", null, false, true, false));
}
+ private Sender<ByteBuffer> wrapSender(final Sender<ByteBuffer> sender)
+ {
+ return new Sender<ByteBuffer>()
+ {
+ @Override
+ public void setIdleTimeout(int i)
+ {
+ sender.setIdleTimeout(i);
+
+ }
+
+ @Override
+ public void send(ByteBuffer msg)
+ {
+ _lastWriteTime = System.currentTimeMillis();
+ sender.send(msg);
+
+ }
+
+ @Override
+ public void flush()
+ {
+ sender.flush();
+
+ }
+
+ @Override
+ public void close()
+ {
+ sender.close();
+
+ }
+ };
+ }
+
+ @Override
+ public long getLastReadTime()
+ {
+ return _lastReadTime;
+ }
+
+ @Override
+ public long getLastWriteTime()
+ {
+ return _lastWriteTime;
+ }
+
public SocketAddress getRemoteAddress()
{
return _network.getRemoteAddress();
@@ -106,6 +137,7 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
public void received(final ByteBuffer buf)
{
+ _lastReadTime = System.currentTimeMillis();
super.received(buf);
_connection.receivedComplete();
}
@@ -122,7 +154,7 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
public void writerIdle()
{
- //Todo
+ _connection.doHeartbeat();
}
public void readerIdle()
@@ -130,72 +162,16 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
//Todo
}
- public VirtualHostConfig getVirtualHost()
- {
- return _connection.getVirtualHost();
- }
-
public String getAddress()
{
return getRemoteAddress().toString();
}
- public Boolean isIncoming()
- {
- return true;
- }
-
- public Boolean isSystemConnection()
- {
- return false;
- }
-
- public Boolean isFederationLink()
- {
- return false;
- }
-
public String getAuthId()
{
return _connection.getAuthorizedPrincipal() == null ? null : _connection.getAuthorizedPrincipal().getName();
}
- public String getRemoteProcessName()
- {
- return null;
- }
-
- public Integer getRemotePID()
- {
- return null;
- }
-
- public Integer getRemoteParentPID()
- {
- return null;
- }
-
- public ConfigStore getConfigStore()
- {
- return _appRegistry.getConfigStore();
- }
-
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public ConnectionConfigType getConfigType()
- {
- return ConnectionConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return getVirtualHost();
- }
-
public boolean isDurable()
{
return false;
@@ -205,7 +181,6 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
public void closed()
{
super.closed();
- getConfigStore().removeConfiguredObject(this);
}
public long getCreateTime()
@@ -213,16 +188,6 @@ public class ProtocolEngine_0_10 extends InputHandler implements ServerProtocol
return _createTime;
}
- public Boolean isShadow()
- {
- return false;
- }
-
- public void mgmtClose()
- {
- _connection.mgmtClose();
- }
-
public long getConnectionId()
{
return _connection.getConnectionId();
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java
index e6282315c6..f6b8e1e5c9 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java
@@ -22,7 +22,6 @@ package org.apache.qpid.server.protocol;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
-import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -39,11 +38,10 @@ import org.apache.qpid.amqp_1_0.transport.FrameOutputHandler;
import org.apache.qpid.amqp_1_0.type.Binary;
import org.apache.qpid.amqp_1_0.type.FrameBody;
import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConnectionConfigType;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.v1_0.Connection_1_0;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.network.NetworkConnection;
@@ -54,8 +52,9 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
//private NetworkConnection _networkDriver;
private long _readBytes;
private long _writtenBytes;
- private final UUID _id;
- private final IApplicationRegistry _appRegistry;
+ private long _lastReadTime;
+ private long _lastWriteTime;
+ private final Broker _broker;
private long _createTime = System.currentTimeMillis();
private ConnectionEndpoint _conn;
private final long _connectionId;
@@ -99,11 +98,14 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
- public ProtocolEngine_1_0_0(final IApplicationRegistry appRegistry, long id)
+ public ProtocolEngine_1_0_0(final NetworkConnection networkDriver, final Broker broker, long id)
{
- _id = appRegistry.getConfigStore().createId();
- _appRegistry = appRegistry;
+ _broker = broker;
_connectionId = id;
+ if(networkDriver != null)
+ {
+ setNetworkConnection(networkDriver, networkDriver.getSender());
+ }
}
@@ -142,13 +144,15 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
_network = network;
_sender = sender;
- Container container = new Container(_appRegistry.getBrokerId().toString());
+ Container container = new Container(_broker.getId().toString());
+
+ VirtualHost virtualHost = _broker.getVirtualHostRegistry().getVirtualHost((String)_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST));
- _conn = new ConnectionEndpoint(container, asSaslServerProvider(_appRegistry.getAuthenticationManager(
+ _conn = new ConnectionEndpoint(container, asSaslServerProvider(_broker.getSubjectCreator(
getLocalAddress())));
- _conn.setConnectionEventListener(new Connection_1_0(_appRegistry, _conn, _connectionId));
- _conn.setFrameOutputHandler(this);
_conn.setRemoteAddress(_network.getRemoteAddress());
+ _conn.setConnectionEventListener(new Connection_1_0(virtualHost, _conn, _connectionId));
+ _conn.setFrameOutputHandler(this);
_frameWriter = new FrameWriter(_conn.getDescribedTypeRegistry());
_frameHandler = new FrameHandler(_conn);
@@ -157,14 +161,14 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
_sender.flush();
}
- private SaslServerProvider asSaslServerProvider(final AuthenticationManager authenticationManager)
+ private SaslServerProvider asSaslServerProvider(final SubjectCreator subjectCreator)
{
return new SaslServerProvider()
{
@Override
public SaslServer getSaslServer(String mechanism, String fqdn) throws SaslException
{
- return authenticationManager.createSaslServer(mechanism, fqdn, null);
+ return subjectCreator.createSaslServer(mechanism, fqdn, null);
}
};
}
@@ -174,22 +178,6 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
return getRemoteAddress().toString();
}
-
- public ConfigStore getConfigStore()
- {
- return _appRegistry.getConfigStore();
- }
-
- public UUID getId()
- {
- return _id;
- }
-
- public ConnectionConfigType getConfigType()
- {
- return ConnectionConfigType.getInstance();
- }
-
public boolean isDurable()
{
return false;
@@ -197,6 +185,7 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
public synchronized void received(ByteBuffer msg)
{
+ _lastReadTime = System.currentTimeMillis();
if(RAW_LOGGER.isLoggable(Level.FINE))
{
ByteBuffer dup = msg.duplicate();
@@ -339,6 +328,7 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
synchronized(_sendLock)
{
+ _lastWriteTime = System.currentTimeMillis();
if(FRAME_LOGGER.isLoggable(Level.FINE))
{
FRAME_LOGGER.fine("SEND[" + getRemoteAddress() + "|" + amqFrame.getChannel() + "] : " + amqFrame.getFrameBody());
@@ -393,4 +383,13 @@ public class ProtocolEngine_1_0_0 implements ServerProtocolEngine, FrameOutputHa
return _connectionId;
}
+ public long getLastReadTime()
+ {
+ return _lastReadTime;
+ }
+
+ public long getLastWriteTime()
+ {
+ return _lastWriteTime;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java
index a48441bf30..3b02ef2e5b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java
@@ -23,7 +23,6 @@ package org.apache.qpid.server.protocol;
import java.io.PrintWriter;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
-import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.security.sasl.SaslException;
@@ -40,12 +39,10 @@ import org.apache.qpid.amqp_1_0.transport.FrameOutputHandler;
import org.apache.qpid.amqp_1_0.type.Binary;
import org.apache.qpid.amqp_1_0.type.FrameBody;
import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConnectionConfigType;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.v1_0.Connection_1_0;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.network.NetworkConnection;
@@ -53,8 +50,10 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
{
private long _readBytes;
private long _writtenBytes;
- private final UUID _id;
- private final IApplicationRegistry _appRegistry;
+
+ private long _lastReadTime;
+ private long _lastWriteTime;
+ private final Broker _broker;
private long _createTime = System.currentTimeMillis();
private ConnectionEndpoint _conn;
private long _connectionId;
@@ -113,13 +112,11 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
private State _state = State.A;
- public ProtocolEngine_1_0_0_SASL(final NetworkConnection networkDriver, final IApplicationRegistry appRegistry,
+ public ProtocolEngine_1_0_0_SASL(final NetworkConnection networkDriver, final Broker broker,
long id)
{
- _id = appRegistry.getConfigStore().createId();
_connectionId = id;
- _appRegistry = appRegistry;
-
+ _broker = broker;
if(networkDriver != null)
{
setNetworkConnection(networkDriver, networkDriver.getSender());
@@ -162,21 +159,17 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
_network = network;
_sender = sender;
- Container container = new Container(_appRegistry.getBrokerId().toString());
+ Container container = new Container(_broker.getId().toString());
- _conn = new ConnectionEndpoint(container, asSaslServerProvider(ApplicationRegistry.getInstance()
- .getAuthenticationManager(getLocalAddress())));
- _conn.setConnectionEventListener(new Connection_1_0(_appRegistry, _conn, _connectionId));
+ VirtualHost virtualHost = _broker.getVirtualHostRegistry().getVirtualHost((String)_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST));
+ _conn = new ConnectionEndpoint(container, asSaslServerProvider(_broker.getSubjectCreator(getLocalAddress())));
_conn.setRemoteAddress(getRemoteAddress());
-
-
+ _conn.setConnectionEventListener(new Connection_1_0(virtualHost, _conn, _connectionId));
_conn.setFrameOutputHandler(this);
_conn.setSaslFrameOutput(this);
_conn.setOnSaslComplete(new Runnable()
{
-
-
public void run()
{
if(_conn.isAuthenticated())
@@ -201,14 +194,14 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
}
- private SaslServerProvider asSaslServerProvider(final AuthenticationManager authenticationManager)
+ private SaslServerProvider asSaslServerProvider(final SubjectCreator subjectCreator)
{
return new SaslServerProvider()
{
@Override
public SaslServer getSaslServer(String mechanism, String fqdn) throws SaslException
{
- return authenticationManager.createSaslServer(mechanism, fqdn, null);
+ return subjectCreator.createSaslServer(mechanism, fqdn, null);
}
};
}
@@ -218,22 +211,6 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
return getRemoteAddress().toString();
}
-
- public ConfigStore getConfigStore()
- {
- return _appRegistry.getConfigStore();
- }
-
- public UUID getId()
- {
- return _id;
- }
-
- public ConnectionConfigType getConfigType()
- {
- return ConnectionConfigType.getInstance();
- }
-
public boolean isDurable()
{
return false;
@@ -244,6 +221,7 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
public synchronized void received(ByteBuffer msg)
{
+ _lastReadTime = System.currentTimeMillis();
if(RAW_LOGGER.isLoggable(Level.FINE))
{
ByteBuffer dup = msg.duplicate();
@@ -386,17 +364,14 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
synchronized(_sendLock)
{
-
+ _lastWriteTime = System.currentTimeMillis();
if(FRAME_LOGGER.isLoggable(Level.FINE))
{
FRAME_LOGGER.fine("SEND[" + getRemoteAddress() + "|" + amqFrame.getChannel() + "] : " + amqFrame.getFrameBody());
}
-
_frameWriter.setValue(amqFrame);
-
-
ByteBuffer dup = ByteBuffer.allocate(_conn.getMaxFrameSize());
int size = _frameWriter.writeToBuffer(dup);
@@ -447,4 +422,13 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut
return _connectionId;
}
+ public long getLastReadTime()
+ {
+ return _lastReadTime;
+ }
+
+ public long getLastWriteTime()
+ {
+ return _lastWriteTime;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
index f429d8ba9f..cf4164c244 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
@@ -31,7 +31,6 @@ import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -44,7 +43,6 @@ import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.CONNECTIO
public class Connection_1_0 implements ConnectionEventListener
{
- private IApplicationRegistry _appRegistry;
private VirtualHost _vhost;
private final ConnectionEndpoint _conn;
private final long _connectionId;
@@ -62,10 +60,9 @@ public class Connection_1_0 implements ConnectionEventListener
- public Connection_1_0(IApplicationRegistry appRegistry, ConnectionEndpoint conn, long connectionId)
+ public Connection_1_0(VirtualHost virtualHost, ConnectionEndpoint conn, long connectionId)
{
- _appRegistry = appRegistry;
- _vhost = _appRegistry.getVirtualHostRegistry().getDefaultVirtualHost();
+ _vhost = virtualHost;
_conn = conn;
_connectionId = connectionId;
_vhost.getConnectionRegistry().registerConnection(_model);
@@ -74,7 +71,7 @@ public class Connection_1_0 implements ConnectionEventListener
public void remoteSessionCreation(SessionEndpoint endpoint)
{
- Session_1_0 session = new Session_1_0(_vhost, _appRegistry, this);
+ Session_1_0 session = new Session_1_0(_vhost, this);
_sessions.add(session);
endpoint.setSessionEventListener(session);
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java
index ba1a1ca45c..2cef27267b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java
@@ -80,7 +80,7 @@ public class ExchangeDestination implements ReceivingDestination, SendingDestina
{
// NO-OP
}
- }, System.currentTimeMillis());
+ });
return ACCEPTED;
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java
index 140a815f57..fbce1666b7 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java
@@ -23,9 +23,10 @@ package org.apache.qpid.server.protocol.v1_0;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
+import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.SessionConfig;
import org.apache.qpid.server.message.InboundMessage;
import org.apache.qpid.server.message.MessageMetaData_1_0;
import org.apache.qpid.server.message.MessageReference;
@@ -34,11 +35,45 @@ import org.apache.qpid.server.store.StoredMessage;
public class Message_1_0 implements ServerMessage, InboundMessage
{
+
+
+ private static final AtomicIntegerFieldUpdater<Message_1_0> _refCountUpdater =
+ AtomicIntegerFieldUpdater.newUpdater(Message_1_0.class, "_referenceCount");
+
+ private volatile int _referenceCount = 0;
+
private final StoredMessage<MessageMetaData_1_0> _storedMessage;
private List<ByteBuffer> _fragments;
private WeakReference<Session_1_0> _session;
+ public Message_1_0(final StoredMessage<MessageMetaData_1_0> storedMessage)
+ {
+ _storedMessage = storedMessage;
+ _session = null;
+ _fragments = restoreFragments(storedMessage);
+ }
+
+ private static List<ByteBuffer> restoreFragments(StoredMessage<MessageMetaData_1_0> storedMessage)
+ {
+ ArrayList<ByteBuffer> fragments = new ArrayList<ByteBuffer>();
+ final int FRAGMENT_SIZE = 2048;
+ int offset = 0;
+ ByteBuffer b;
+ do
+ {
+
+ b = storedMessage.getContent(offset,FRAGMENT_SIZE);
+ if(b.hasRemaining())
+ {
+ fragments.add(b);
+ offset+= b.remaining();
+ }
+ }
+ while(b.hasRemaining());
+ return fragments;
+ }
+
public Message_1_0(final StoredMessage<MessageMetaData_1_0> storedMessage,
final List<ByteBuffer> fragments,
final Session_1_0 session)
@@ -136,11 +171,6 @@ public class Message_1_0 implements ServerMessage, InboundMessage
return buf;
}
- public SessionConfig getSessionConfig()
- {
- return null; //TODO
- }
-
public List<ByteBuffer> getFragments()
{
return _fragments;
@@ -148,7 +178,61 @@ public class Message_1_0 implements ServerMessage, InboundMessage
public Session_1_0 getSession()
{
- return _session.get();
+ return _session == null ? null : _session.get();
+ }
+
+
+ public boolean incrementReference()
+ {
+ if(_refCountUpdater.incrementAndGet(this) <= 0)
+ {
+ _refCountUpdater.decrementAndGet(this);
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ /**
+ * Threadsafe. This will decrement the reference count and when it reaches zero will remove the message from the
+ * message store.
+ *
+ *
+ * @throws org.apache.qpid.server.queue.MessageCleanupException when an attempt was made to remove the message from the message store and that
+ * failed
+ */
+ public void decrementReference()
+ {
+ int count = _refCountUpdater.decrementAndGet(this);
+
+ // note that the operation of decrementing the reference count and then removing the message does not
+ // have to be atomic since the ref count starts at 1 and the exchange itself decrements that after
+ // the message has been passed to all queues. i.e. we are
+ // not relying on the all the increments having taken place before the delivery manager decrements.
+ if (count == 0)
+ {
+ // set the reference count way below 0 so that we can detect that the message has been deleted
+ // this is to guard against the message being spontaneously recreated (from the mgmt console)
+ // by copying from other queues at the same time as it is being removed.
+ _refCountUpdater.set(this,Integer.MIN_VALUE/2);
+
+ // must check if the handle is null since there may be cases where we decide to throw away a message
+ // and the handle has not yet been constructed
+ if (_storedMessage != null)
+ {
+ _storedMessage.remove();
+ }
+ }
+ else
+ {
+ if (count < 0)
+ {
+ throw new RuntimeException("Reference count for message id " + getMessageNumber()
+ + " has gone below 0.");
+ }
+ }
}
public static class Reference extends MessageReference<Message_1_0>
@@ -160,13 +244,13 @@ public class Message_1_0 implements ServerMessage, InboundMessage
protected void onReference(Message_1_0 message)
{
-
+ message.incrementReference();
}
protected void onRelease(Message_1_0 message)
{
-
+ message.decrementReference();
}
-}
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java
index 999ffc55e5..a0ed824c58 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Session_1_0.java
@@ -36,7 +36,6 @@ import org.apache.qpid.amqp_1_0.type.transport.*;
import org.apache.qpid.amqp_1_0.type.transport.Error;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQSecurityException;
-import org.apache.qpid.protocol.ProtocolEngine;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.message.InboundMessage;
@@ -45,8 +44,6 @@ import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.transport.ServerConnection;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -58,7 +55,6 @@ import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.CHANNEL_F
public class Session_1_0 implements SessionEventListener, AMQSessionModel, LogSubject
{
private static final Symbol LIFETIME_POLICY = Symbol.valueOf("lifetime-policy");
- private IApplicationRegistry _appRegistry;
private VirtualHost _vhost;
private AutoCommitTransaction _transaction;
@@ -68,9 +64,8 @@ public class Session_1_0 implements SessionEventListener, AMQSessionModel, LogSu
private UUID _id = UUID.randomUUID();
- public Session_1_0(VirtualHost vhost, IApplicationRegistry appRegistry, final Connection_1_0 connection)
+ public Session_1_0(VirtualHost vhost, final Connection_1_0 connection)
{
- _appRegistry = appRegistry;
_vhost = vhost;
_transaction = new AutoCommitTransaction(vhost.getMessageStore());
_connection = connection;
@@ -456,8 +451,9 @@ public class Session_1_0 implements SessionEventListener, AMQSessionModel, LogSu
{
}
+
@Override
- public UUID getQMFId()
+ public UUID getId()
{
return _id;
}
@@ -580,13 +576,6 @@ public class Session_1_0 implements SessionEventListener, AMQSessionModel, LogSu
return 0;
}
- @Override
- public int compareTo(AMQSessionModel o)
- {
- return getQMFId().compareTo(o.getQMFId());
- }
-
-
public String toLogString()
{
@@ -604,4 +593,9 @@ public class Session_1_0 implements SessionEventListener, AMQSessionModel, LogSu
+ "] ";
}
+ @Override
+ public int compareTo(AMQSessionModel o)
+ {
+ return getId().compareTo(o.getId());
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java
index d3efd63ee0..4f610cc925 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java
@@ -23,8 +23,7 @@ package org.apache.qpid.server.queue;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.QueueConfig;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+import org.apache.qpid.server.configuration.QueueConfiguration;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeReferrer;
import org.apache.qpid.server.logging.LogSubject;
@@ -39,9 +38,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-public interface AMQQueue extends Comparable<AMQQueue>, ExchangeReferrer, TransactionLogResource, BaseQueue,
- QueueConfig
+public interface AMQQueue extends Comparable<AMQQueue>, ExchangeReferrer, TransactionLogResource, BaseQueue
{
+ String getName();
+
public interface NotificationListener
{
void notifyClients(NotificationCheck notification, AMQQueue queue, String notificationMsg);
@@ -277,9 +277,7 @@ public interface AMQQueue extends Comparable<AMQQueue>, ExchangeReferrer, Transa
public void doTask(AMQQueue queue) throws AMQException;
}
- void configure(ConfigurationPlugin config);
-
- ConfigurationPlugin getConfiguration();
+ void configure(QueueConfiguration config);
void setExclusive(boolean exclusive);
@@ -315,4 +313,18 @@ public interface AMQQueue extends Comparable<AMQQueue>, ExchangeReferrer, Transa
*/
String getDescription();
+ long getPersistentByteDequeues();
+
+ long getPersistentMsgDequeues();
+
+ long getPersistentByteEnqueues();
+
+ long getPersistentMsgEnqueues();
+
+ long getTotalDequeueSize();
+
+ long getTotalEnqueueSize();
+
+ long getUnackedMessageCount();
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
index 3a18fae2ec..a65a6a8eb2 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java
@@ -30,17 +30,25 @@ import org.apache.qpid.AMQSecurityException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.configuration.QueueConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.exchange.DefaultExchangeFactory;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeFactory;
import org.apache.qpid.server.exchange.ExchangeRegistry;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.virtualhost.VirtualHost;
public class AMQQueueFactory
{
+ public static final String X_QPID_FLOW_RESUME_CAPACITY = "x-qpid-flow-resume-capacity";
+ public static final String X_QPID_CAPACITY = "x-qpid-capacity";
+ public static final String X_QPID_MINIMUM_ALERT_REPEAT_GAP = "x-qpid-minimum-alert-repeat-gap";
+ public static final String X_QPID_MAXIMUM_MESSAGE_COUNT = "x-qpid-maximum-message-count";
+ public static final String X_QPID_MAXIMUM_MESSAGE_SIZE = "x-qpid-maximum-message-size";
+ public static final String X_QPID_MAXIMUM_MESSAGE_AGE = "x-qpid-maximum-message-age";
+ public static final String X_QPID_MAXIMUM_QUEUE_DEPTH = "x-qpid-maximum-queue-depth";
+
public static final String X_QPID_PRIORITIES = "x-qpid-priorities";
public static final String X_QPID_DESCRIPTION = "x-qpid-description";
public static final String QPID_LVQ_KEY = "qpid.LVQ_key";
@@ -119,42 +127,49 @@ public class AMQQueueFactory
}
private static final QueueProperty[] DECLAREABLE_PROPERTIES = {
- new QueueLongProperty("x-qpid-maximum-message-age")
+ new QueueLongProperty(X_QPID_MAXIMUM_MESSAGE_AGE)
{
public void setPropertyValue(AMQQueue queue, long value)
{
queue.setMaximumMessageAge(value);
}
},
- new QueueLongProperty("x-qpid-maximum-message-size")
+ new QueueLongProperty(X_QPID_MAXIMUM_MESSAGE_SIZE)
{
public void setPropertyValue(AMQQueue queue, long value)
{
queue.setMaximumMessageSize(value);
}
},
- new QueueLongProperty("x-qpid-maximum-message-count")
+ new QueueLongProperty(X_QPID_MAXIMUM_MESSAGE_COUNT)
{
public void setPropertyValue(AMQQueue queue, long value)
{
queue.setMaximumMessageCount(value);
}
},
- new QueueLongProperty("x-qpid-minimum-alert-repeat-gap")
+ new QueueLongProperty(X_QPID_MAXIMUM_QUEUE_DEPTH)
+ {
+ public void setPropertyValue(AMQQueue queue, long value)
+ {
+ queue.setMaximumQueueDepth(value);
+ }
+ },
+ new QueueLongProperty(X_QPID_MINIMUM_ALERT_REPEAT_GAP)
{
public void setPropertyValue(AMQQueue queue, long value)
{
queue.setMinimumAlertRepeatGap(value);
}
},
- new QueueLongProperty("x-qpid-capacity")
+ new QueueLongProperty(X_QPID_CAPACITY)
{
public void setPropertyValue(AMQQueue queue, long value)
{
queue.setCapacity(value);
}
},
- new QueueLongProperty("x-qpid-flow-resume-capacity")
+ new QueueLongProperty(X_QPID_FLOW_RESUME_CAPACITY)
{
public void setPropertyValue(AMQQueue queue, long value)
{
@@ -411,9 +426,7 @@ public class AMQQueueFactory
*/
protected static String getDeadLetterQueueName(String name)
{
- ServerConfiguration serverConfig = ApplicationRegistry.getInstance().getConfiguration();
- String dlQueueName = name + serverConfig.getDeadLetterQueueSuffix();
- return dlQueueName;
+ return name + System.getProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, DEFAULT_DLQ_NAME_SUFFIX);
}
/**
@@ -425,9 +438,7 @@ public class AMQQueueFactory
*/
protected static String getDeadLetterExchangeName(String name)
{
- ServerConfiguration serverConfig = ApplicationRegistry.getInstance().getConfiguration();
- String dlExchangeName = name + serverConfig.getDeadLetterExchangeSuffix();
- return dlExchangeName;
+ return name + System.getProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
}
private static Map<String, Object> createQueueArgumentsFromConfig(QueueConfiguration config)
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/InboundMessageAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/queue/InboundMessageAdapter.java
index bbc33ca846..d7dbd58537 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/InboundMessageAdapter.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/InboundMessageAdapter.java
@@ -47,7 +47,7 @@ public class InboundMessageAdapter implements InboundMessage
public AMQShortString getRoutingKeyShortString()
{
- return AMQShortString.valueOf(_entry.getMessage());
+ return AMQShortString.valueOf(_entry.getMessage().getRoutingKey());
}
public String getRoutingKey()
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java b/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java
index c5a610c7b6..18affc7161 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/IncomingMessage.java
@@ -34,7 +34,6 @@ import org.apache.qpid.server.message.EnqueableMessage;
import org.apache.qpid.server.message.InboundMessage;
import org.apache.qpid.server.message.MessageContentSource;
import org.apache.qpid.server.message.MessageMetaData;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.StoredMessage;
import java.nio.ByteBuffer;
@@ -47,9 +46,6 @@ public class IncomingMessage implements Filterable, InboundMessage, EnqueableMes
/** Used for debugging purposes. */
private static final Logger _logger = Logger.getLogger(IncomingMessage.class);
- private static final boolean SYNCHED_CLOCKS =
- ApplicationRegistry.getInstance().getConfiguration().getSynchedClocks();
-
private final MessagePublishInfo _messagePublishInfo;
private ContentHeaderBody _contentHeaderBody;
@@ -101,33 +97,7 @@ public class IncomingMessage implements Filterable, InboundMessage, EnqueableMes
public void setExpiration()
{
- long expiration =
- ((BasicContentHeaderProperties) _contentHeaderBody.getProperties()).getExpiration();
- long timestamp =
- ((BasicContentHeaderProperties) _contentHeaderBody.getProperties()).getTimestamp();
-
- if (SYNCHED_CLOCKS)
- {
- _expiration = expiration;
- }
- else
- {
- // Update TTL to be in broker time.
- if (expiration != 0L)
- {
- if (timestamp != 0L)
- {
- // todo perhaps use arrival time
- long diff = (System.currentTimeMillis() - timestamp);
-
- if ((diff > 1000L) || (diff < 1000L))
- {
- _expiration = expiration + diff;
- }
- }
- }
- }
-
+ _expiration = ((BasicContentHeaderProperties) _contentHeaderBody.getProperties()).getExpiration();
}
public MessageMetaData headersReceived(long currentTime)
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryImpl.java b/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryImpl.java
index 25e771a9cf..9aa8d1da83 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryImpl.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntryImpl.java
@@ -454,7 +454,7 @@ public abstract class QueueEntryImpl implements QueueEntry
{
}
- }, 0L);
+ });
txn.dequeue(currentQueue, message, new ServerTransaction.Action()
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java
index d42bd6cf03..73c2870b9b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java
@@ -41,11 +41,8 @@ import org.apache.qpid.AMQSecurityException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.pool.ReferenceCountingExecutorService;
import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.QueueConfigType;
import org.apache.qpid.server.configuration.QueueConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+import org.apache.qpid.server.configuration.plugins.AbstractConfiguration;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogSubject;
@@ -55,7 +52,6 @@ import org.apache.qpid.server.logging.messages.QueueMessages;
import org.apache.qpid.server.logging.subjects.QueueLogSubject;
import org.apache.qpid.server.message.ServerMessage;
import org.apache.qpid.server.protocol.AMQSessionModel;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.AuthorizationHolder;
import org.apache.qpid.server.subscription.AssignedSubscriptionMessageGroupManager;
import org.apache.qpid.server.subscription.DefinedGroupMessageGroupManager;
@@ -135,23 +131,23 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
private final AtomicInteger _bindingCountHigh = new AtomicInteger();
/** max allowed size(KB) of a single message */
- private long _maximumMessageSize = ApplicationRegistry.getInstance().getConfiguration().getMaximumMessageSize();
+ private long _maximumMessageSize;
/** max allowed number of messages on a queue. */
- private long _maximumMessageCount = ApplicationRegistry.getInstance().getConfiguration().getMaximumMessageCount();
+ private long _maximumMessageCount;
/** max queue depth for the queue */
- private long _maximumQueueDepth = ApplicationRegistry.getInstance().getConfiguration().getMaximumQueueDepth();
+ private long _maximumQueueDepth;
/** maximum message age before alerts occur */
- private long _maximumMessageAge = ApplicationRegistry.getInstance().getConfiguration().getMaximumMessageAge();
+ private long _maximumMessageAge;
/** the minimum interval between sending out consecutive alerts of the same type */
- private long _minimumAlertRepeatGap = ApplicationRegistry.getInstance().getConfiguration().getMinimumAlertRepeatGap();
+ private long _minimumAlertRepeatGap;
- private long _capacity = ApplicationRegistry.getInstance().getConfiguration().getCapacity();
+ private long _capacity;
- private long _flowResumeCapacity = ApplicationRegistry.getInstance().getConfiguration().getFlowResumeCapacity();
+ private long _flowResumeCapacity;
private final Set<NotificationCheck> _notificationChecks = EnumSet.noneOf(NotificationCheck.class);
@@ -185,11 +181,10 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
//TODO : persist creation time
private long _createTime = System.currentTimeMillis();
- private UUID _qmfId;
- private ConfigurationPlugin _queueConfiguration;
+ private AbstractConfiguration _queueConfiguration;
/** the maximum delivery count for each message on this queue or 0 if maximum delivery count is not to be enforced. */
- private int _maximumDeliveryCount = ApplicationRegistry.getInstance().getConfiguration().getMaxDeliveryCount();
+ private int _maximumDeliveryCount;
private final MessageGroupManager _messageGroupManager;
private final Collection<SubscriptionRegistrationListener> _subscriptionListeners =
@@ -243,7 +238,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
_arguments = arguments == null ? new HashMap<String, Object>() : new HashMap<String, Object>(arguments);
_id = id;
- _qmfId = getConfigStore().createId();
_asyncDelivery = ReferenceCountingExecutorService.getInstance().acquireExecutorService();
_logSubject = new QueueLogSubject(this);
@@ -259,8 +253,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
durable, !durable,
_entries.getPriorities() > 0));
- getConfigStore().addConfiguredObject(this);
-
if(arguments != null && arguments.containsKey(QPID_GROUP_HEADER_KEY))
{
if(arguments.containsKey(QPID_SHARED_MSG_GROUP) && String.valueOf(arguments.get(QPID_SHARED_MSG_GROUP)).equals("1"))
@@ -331,22 +323,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
return _id;
}
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public QueueConfigType getConfigType()
- {
- return QueueConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return getVirtualHost();
- }
-
public boolean isDurable()
{
return _durable;
@@ -621,24 +597,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
break;
}
}
-
- reconfigure();
- }
-
- private void reconfigure()
- {
- //Reconfigure the queue for to reflect this new binding.
- ConfigurationPlugin config = getVirtualHost().getConfiguration().getQueueConfiguration(this);
-
- if (config != null)
- {
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Reconfiguring queue(" + this + ") with config:" + config + " was "+ _queueConfiguration);
- }
- // Reconfigure with new config.
- configure(config);
- }
}
public int getBindingCountHigh()
@@ -649,8 +607,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
public void removeBinding(final Binding binding)
{
_bindings.remove(binding);
-
- reconfigure();
}
public List<Binding> getBindings()
@@ -1383,7 +1339,6 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
}
_virtualHost.getQueueRegistry().unregisterQueue(_name);
- getConfigStore().removeConfiguredObject(this);
List<QueueEntry> entries = getMessagesOnTheQueue(new QueueEntryFilter()
{
@@ -1442,7 +1397,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
{
}
- }, 0L);
+ });
txn.dequeue(this, entry.getMessage(),
new ServerTransaction.Action()
{
@@ -2161,39 +2116,21 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener, Mes
}
- public void configure(ConfigurationPlugin config)
+ public void configure(QueueConfiguration config)
{
if (config != null)
{
- if (config instanceof QueueConfiguration)
- {
-
- setMaximumMessageAge(((QueueConfiguration)config).getMaximumMessageAge());
- setMaximumQueueDepth(((QueueConfiguration)config).getMaximumQueueDepth());
- setMaximumMessageSize(((QueueConfiguration)config).getMaximumMessageSize());
- setMaximumMessageCount(((QueueConfiguration)config).getMaximumMessageCount());
- setMinimumAlertRepeatGap(((QueueConfiguration)config).getMinimumAlertRepeatGap());
- setMaximumDeliveryCount(((QueueConfiguration)config).getMaxDeliveryCount());
- _capacity = ((QueueConfiguration)config).getCapacity();
- _flowResumeCapacity = ((QueueConfiguration)config).getFlowResumeCapacity();
- }
-
- _queueConfiguration = config;
-
+ setMaximumMessageAge(config.getMaximumMessageAge());
+ setMaximumQueueDepth(config.getMaximumQueueDepth());
+ setMaximumMessageSize(config.getMaximumMessageSize());
+ setMaximumMessageCount(config.getMaximumMessageCount());
+ setMinimumAlertRepeatGap(config.getMinimumAlertRepeatGap());
+ setMaximumDeliveryCount(config.getMaxDeliveryCount());
+ _capacity = config.getCapacity();
+ _flowResumeCapacity = config.getFlowResumeCapacity();
}
}
-
- public ConfigurationPlugin getConfiguration()
- {
- return _queueConfiguration;
- }
-
- public ConfigStore getConfigStore()
- {
- return getVirtualHost().getConfigStore();
- }
-
public long getMessageDequeueCount()
{
return _dequeueCount.get();
diff --git a/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
index e0e317f75d..1379b375cf 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
@@ -20,44 +20,39 @@
*/
package org.apache.qpid.server.registry;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.logging.*;
-import org.osgi.framework.BundleContext;
+import java.util.Collection;
+import java.util.Timer;
+import java.util.TimerTask;
+import org.apache.log4j.Logger;
import org.apache.qpid.common.Closeable;
import org.apache.qpid.common.QpidProperties;
-import org.apache.qpid.qmf.QMFService;
-import org.apache.qpid.server.configuration.BrokerConfig;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfigurationManager;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.SystemConfig;
-import org.apache.qpid.server.configuration.SystemConfigImpl;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.configuration.startup.DefaultRecovererProvider;
+import org.apache.qpid.server.logging.CompositeStartupMessageLogger;
+import org.apache.qpid.server.logging.Log4jMessageLogger;
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.SystemOutMessageLogger;
import org.apache.qpid.server.logging.actors.AbstractActor;
import org.apache.qpid.server.logging.actors.BrokerActor;
import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.GenericActor;
import org.apache.qpid.server.logging.messages.BrokerMessages;
import org.apache.qpid.server.logging.messages.VirtualHostMessages;
import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.adapter.BrokerAdapter;
-import org.apache.qpid.server.plugins.PluginManager;
-import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManagerRegistry;
-import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.stats.StatisticsCounter;
-import org.apache.qpid.server.transport.QpidAcceptor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostImpl;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicReference;
-
/**
* An abstract application registry that provides access to configuration information and handles the
@@ -65,321 +60,90 @@ import java.util.concurrent.atomic.AtomicReference;
* <p/>
* Subclasses should handle the construction of the "registered objects" such as the exchange registry.
*/
-public abstract class ApplicationRegistry implements IApplicationRegistry
+public class ApplicationRegistry implements IApplicationRegistry
{
-
private static final Logger _logger = Logger.getLogger(ApplicationRegistry.class);
- private static AtomicReference<IApplicationRegistry> _instance = new AtomicReference<IApplicationRegistry>(null);
-
- private final ServerConfiguration _configuration;
-
- private final Map<InetSocketAddress, QpidAcceptor> _acceptors =
- Collections.synchronizedMap(new HashMap<InetSocketAddress, QpidAcceptor>());
-
- private IAuthenticationManagerRegistry _authenticationManagerRegistry;
-
- private final VirtualHostRegistry _virtualHostRegistry = new VirtualHostRegistry(this);
-
- private SecurityManager _securityManager;
+ private final VirtualHostRegistry _virtualHostRegistry = new VirtualHostRegistry();
- private PluginManager _pluginManager;
-
- private ConfigurationManager _configurationManager;
-
- private RootMessageLogger _rootMessageLogger;
-
- private CompositeStartupMessageLogger _startupMessageLogger;
-
- private UUID _brokerId = UUID.randomUUID();
-
- private QMFService _qmfService;
-
- private BrokerConfig _brokerConfig;
+ private volatile RootMessageLogger _rootMessageLogger;
private Broker _broker;
- private ConfigStore _configStore;
-
private Timer _reportingTimer;
private StatisticsCounter _messagesDelivered, _dataDelivered, _messagesReceived, _dataReceived;
- private BundleContext _bundleContext;
-
- private final List<PortBindingListener> _portBindingListeners = new ArrayList<PortBindingListener>();
-
- private int _httpManagementPort = -1, _httpsManagementPort = -1;
-
private LogRecorder _logRecorder;
- private List<IAuthenticationManagerRegistry.RegistryChangeListener> _authManagerChangeListeners =
- new ArrayList<IAuthenticationManagerRegistry.RegistryChangeListener>();
-
- public Map<InetSocketAddress, QpidAcceptor> getAcceptors()
- {
- synchronized (_acceptors)
- {
- return new HashMap<InetSocketAddress, QpidAcceptor>(_acceptors);
- }
- }
-
- protected void setSecurityManager(SecurityManager securityManager)
- {
- _securityManager = securityManager;
- }
-
- protected void setPluginManager(PluginManager pluginManager)
- {
- _pluginManager = pluginManager;
- }
-
- protected void setConfigurationManager(ConfigurationManager configurationManager)
- {
- _configurationManager = configurationManager;
- }
+ private ConfigurationEntryStore _store;
+ private TaskExecutor _taskExecutor;
protected void setRootMessageLogger(RootMessageLogger rootMessageLogger)
{
_rootMessageLogger = rootMessageLogger;
}
- protected CompositeStartupMessageLogger getStartupMessageLogger()
- {
- return _startupMessageLogger;
- }
-
- protected void setStartupMessageLogger(CompositeStartupMessageLogger startupMessageLogger)
+ public ApplicationRegistry(ConfigurationEntryStore store)
{
- _startupMessageLogger = startupMessageLogger;
- }
-
- protected void setBrokerId(UUID brokerId)
- {
- _brokerId = brokerId;
- }
-
- protected QMFService getQmfService()
- {
- return _qmfService;
- }
-
- protected void setQmfService(QMFService qmfService)
- {
- _qmfService = qmfService;
- }
-
- public static void initialise(IApplicationRegistry instance) throws Exception
- {
- if(instance == null)
- {
- throw new IllegalArgumentException("ApplicationRegistry instance must not be null");
- }
-
- if(!_instance.compareAndSet(null, instance))
- {
- throw new IllegalStateException("An ApplicationRegistry is already initialised");
- }
-
- _logger.info("Initialising Application Registry(" + instance + ")");
-
-
- final ConfigStore store = ConfigStore.newInstance();
- store.setRoot(new SystemConfigImpl(store));
- instance.setConfigStore(store);
-
- final BrokerConfig brokerConfig = new BrokerConfigAdapter(instance);
-
- final SystemConfig system = store.getRoot();
- system.addBroker(brokerConfig);
- instance.setBrokerConfig(brokerConfig);
-
- try
- {
- instance.initialise();
- }
- catch (Exception e)
- {
- _instance.set(null);
-
- //remove the Broker instance, then re-throw
- try
- {
- system.removeBroker(brokerConfig);
- }
- catch(Throwable t)
- {
- //ignore
- }
-
- throw e;
- }
- }
-
- public ConfigStore getConfigStore()
- {
- return _configStore;
- }
-
- public void setConfigStore(final ConfigStore configStore)
- {
- _configStore = configStore;
- }
-
- public static boolean isConfigured()
- {
- return _instance.get() != null;
- }
-
- public static void remove()
- {
- IApplicationRegistry instance = _instance.getAndSet(null);
- try
- {
- if (instance != null)
- {
- if (_logger.isInfoEnabled())
- {
- _logger.info("Shutting down ApplicationRegistry(" + instance + ")");
- }
- instance.close();
- }
- }
- catch (Exception e)
- {
- _logger.error("Error shutting down Application Registry(" + instance + "): " + e, e);
- }
- }
-
- protected ApplicationRegistry(ServerConfiguration configuration)
- {
- this(configuration, null);
- }
-
- protected ApplicationRegistry(ServerConfiguration configuration, BundleContext bundleContext)
- {
- _configuration = configuration;
- _bundleContext = bundleContext;
- }
-
- public void configure() throws ConfigurationException
- {
- _configurationManager = new ConfigurationManager();
-
- try
- {
- _pluginManager = new PluginManager(_configuration.getPluginDirectory(), _configuration.getCacheDirectory(), _bundleContext);
- }
- catch (Exception e)
- {
- throw new ConfigurationException(e);
- }
-
- _configuration.initialise();
+ _store = store;
+ initialiseStatistics();
}
public void initialise() throws Exception
{
+ // Create the RootLogger to be used during broker operation
+ boolean statusUpdatesEnabled = Boolean.parseBoolean(System.getProperty(BrokerProperties.PROPERTY_STATUS_UPDATES, "true"));
+ _rootMessageLogger = new Log4jMessageLogger(statusUpdatesEnabled);
+
_logRecorder = new LogRecorder();
- //Create the RootLogger to be used during broker operation
- _rootMessageLogger = new Log4jMessageLogger(_configuration);
//Create the composite (log4j+SystemOut MessageLogger to be used during startup
RootMessageLogger[] messageLoggers = {new SystemOutMessageLogger(), _rootMessageLogger};
- _startupMessageLogger = new CompositeStartupMessageLogger(messageLoggers);
+ CompositeStartupMessageLogger startupMessageLogger = new CompositeStartupMessageLogger(messageLoggers);
- BrokerActor actor = new BrokerActor(_startupMessageLogger);
- CurrentActor.setDefault(actor);
+ BrokerActor actor = new BrokerActor(startupMessageLogger);
CurrentActor.set(actor);
-
+ CurrentActor.setDefault(actor);
+ GenericActor.setDefaultMessageLogger(_rootMessageLogger);
try
{
- initialiseStatistics();
-
- if(_configuration.getHTTPManagementEnabled())
- {
- _httpManagementPort = _configuration.getHTTPManagementPort();
- }
- if (_configuration.getHTTPSManagementEnabled())
- {
- _httpsManagementPort = _configuration.getHTTPSManagementPort();
- }
-
- _broker = new BrokerAdapter(this);
-
- configure();
-
- _qmfService = new QMFService(getConfigStore(), this);
-
logStartupMessages(CurrentActor.get());
- _securityManager = new SecurityManager(_configuration, _pluginManager);
+ _taskExecutor = new TaskExecutor();
+ _taskExecutor.start();
- _authenticationManagerRegistry = createAuthenticationManagerRegistry(_configuration, _pluginManager);
+ RecovererProvider provider = new DefaultRecovererProvider((StatisticsGatherer)this, _virtualHostRegistry, _logRecorder, _rootMessageLogger, _taskExecutor);
+ ConfiguredObjectRecoverer<? extends ConfiguredObject> brokerRecoverer = provider.getRecoverer(Broker.class.getSimpleName());
+ _broker = (Broker) brokerRecoverer.create(provider, _store.getRootEntry());
- if(!_authManagerChangeListeners.isEmpty())
- {
- for(IAuthenticationManagerRegistry.RegistryChangeListener listener : _authManagerChangeListeners)
- {
+ _virtualHostRegistry.setDefaultVirtualHostName((String)_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST));
- _authenticationManagerRegistry.addRegistryChangeListener(listener);
- for(AuthenticationManager authMgr : _authenticationManagerRegistry.getAvailableAuthenticationManagers().values())
- {
- listener.authenticationManagerRegistered(authMgr);
- }
- }
- _authManagerChangeListeners.clear();
- }
- }
- finally
- {
- CurrentActor.remove();
- }
-
- CurrentActor.set(new BrokerActor(_rootMessageLogger));
- try
- {
- initialiseVirtualHosts();
initialiseStatisticsReporting();
+
+ // starting the broker
+ _broker.setDesiredState(State.INITIALISING, State.ACTIVE);
+
+ CurrentActor.get().message(BrokerMessages.READY());
}
finally
{
- // Startup complete, so pop the current actor
CurrentActor.remove();
}
- }
- protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry(ServerConfiguration _configuration, PluginManager _pluginManager)
- throws ConfigurationException
- {
- return new AuthenticationManagerRegistry(_configuration, _pluginManager);
+ CurrentActor.setDefault(new BrokerActor(_rootMessageLogger));
}
- protected void initialiseVirtualHosts() throws Exception
+ private void initialiseStatisticsReporting()
{
- for (String name : _configuration.getVirtualHosts())
- {
- createVirtualHost(_configuration.getVirtualHostConfig(name));
- }
- getVirtualHostRegistry().setDefaultVirtualHostName(_configuration.getDefaultVirtualHost());
- }
-
- public void initialiseStatisticsReporting()
- {
- long report = _configuration.getStatisticsReportingPeriod() * 1000; // convert to ms
- final boolean broker = _configuration.isStatisticsGenerationBrokerEnabled();
- final boolean virtualhost = _configuration.isStatisticsGenerationVirtualhostsEnabled();
- final boolean reset = _configuration.isStatisticsReportResetEnabled();
+ long report = ((Number)_broker.getAttribute(Broker.STATISTICS_REPORTING_PERIOD)).intValue() * 1000; // convert to ms
+ final boolean reset = (Boolean)_broker.getAttribute(Broker.STATISTICS_REPORTING_RESET_ENABLED);
/* add a timer task to report statistics if generation is enabled for broker or virtualhosts */
- if (report > 0L && (broker || virtualhost))
+ if (report > 0L)
{
_reportingTimer = new Timer("Statistics-Reporting", true);
-
-
-
- _reportingTimer.scheduleAtFixedRate(new StatisticsReportingTask(broker, virtualhost, reset),
- report / 2,
- report);
+ StatisticsReportingTask task = new StatisticsReportingTask(reset, _rootMessageLogger);
+ _reportingTimer.scheduleAtFixedRate(task, report / 2, report);
}
}
@@ -388,76 +152,62 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
private final int DELIVERED = 0;
private final int RECEIVED = 1;
- private boolean _broker;
- private boolean _virtualhost;
- private boolean _reset;
+ private final boolean _reset;
+ private final RootMessageLogger _logger;
-
- public StatisticsReportingTask(boolean broker, boolean virtualhost, boolean reset)
+ public StatisticsReportingTask(boolean reset, RootMessageLogger logger)
{
- _broker = broker;
- _virtualhost = virtualhost;
_reset = reset;
+ _logger = logger;
}
public void run()
{
- CurrentActor.set(new AbstractActor(ApplicationRegistry.getInstance().getRootMessageLogger()) {
+ CurrentActor.set(new AbstractActor(_logger)
+ {
public String getLogMessage()
{
return "[" + Thread.currentThread().getName() + "] ";
}
});
-
- if (_broker)
+ try
{
CurrentActor.get().message(BrokerMessages.STATS_DATA(DELIVERED, _dataDelivered.getPeak() / 1024.0, _dataDelivered.getTotal()));
CurrentActor.get().message(BrokerMessages.STATS_MSGS(DELIVERED, _messagesDelivered.getPeak(), _messagesDelivered.getTotal()));
CurrentActor.get().message(BrokerMessages.STATS_DATA(RECEIVED, _dataReceived.getPeak() / 1024.0, _dataReceived.getTotal()));
CurrentActor.get().message(BrokerMessages.STATS_MSGS(RECEIVED, _messagesReceived.getPeak(), _messagesReceived.getTotal()));
- }
+ Collection<VirtualHost> hosts = _virtualHostRegistry.getVirtualHosts();
- if (_virtualhost)
- {
- for (VirtualHost vhost : getVirtualHostRegistry().getVirtualHosts())
+ if (hosts.size() > 1)
{
- String name = vhost.getName();
- StatisticsCounter dataDelivered = vhost.getDataDeliveryStatistics();
- StatisticsCounter messagesDelivered = vhost.getMessageDeliveryStatistics();
- StatisticsCounter dataReceived = vhost.getDataReceiptStatistics();
- StatisticsCounter messagesReceived = vhost.getMessageReceiptStatistics();
-
- CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, DELIVERED, dataDelivered.getPeak() / 1024.0, dataDelivered.getTotal()));
- CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, DELIVERED, messagesDelivered.getPeak(), messagesDelivered.getTotal()));
- CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, RECEIVED, dataReceived.getPeak() / 1024.0, dataReceived.getTotal()));
- CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, RECEIVED, messagesReceived.getPeak(), messagesReceived.getTotal()));
+ for (VirtualHost vhost : hosts)
+ {
+ String name = vhost.getName();
+ StatisticsCounter dataDelivered = vhost.getDataDeliveryStatistics();
+ StatisticsCounter messagesDelivered = vhost.getMessageDeliveryStatistics();
+ StatisticsCounter dataReceived = vhost.getDataReceiptStatistics();
+ StatisticsCounter messagesReceived = vhost.getMessageReceiptStatistics();
+
+ CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, DELIVERED, dataDelivered.getPeak() / 1024.0, dataDelivered.getTotal()));
+ CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, DELIVERED, messagesDelivered.getPeak(), messagesDelivered.getTotal()));
+ CurrentActor.get().message(VirtualHostMessages.STATS_DATA(name, RECEIVED, dataReceived.getPeak() / 1024.0, dataReceived.getTotal()));
+ CurrentActor.get().message(VirtualHostMessages.STATS_MSGS(name, RECEIVED, messagesReceived.getPeak(), messagesReceived.getTotal()));
+ }
}
- }
- if (_reset)
+ if (_reset)
+ {
+ resetStatistics();
+ }
+ }
+ catch(Exception e)
{
- resetStatistics();
+ ApplicationRegistry._logger.warn("Unexpected exception occured while reporting the statistics", e);
+ }
+ finally
+ {
+ CurrentActor.remove();
}
-
- CurrentActor.remove();
- }
- }
-
- /**
- * Get the ApplicationRegistry
- * @return the IApplicationRegistry instance
- * @throws IllegalStateException if no registry instance has been initialised.
- */
- public static IApplicationRegistry getInstance() throws IllegalStateException
- {
- IApplicationRegistry iApplicationRegistry = _instance.get();
- if (iApplicationRegistry == null)
- {
- throw new IllegalStateException("No ApplicationRegistry has been initialised");
- }
- else
- {
- return iApplicationRegistry;
}
}
@@ -488,7 +238,7 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
}
//Set the Actor for Broker Shutdown
- CurrentActor.set(new BrokerActor(getRootMessageLogger()));
+ CurrentActor.set(new BrokerActor(_rootMessageLogger));
try
{
//Stop Statistics Reporting
@@ -497,154 +247,34 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
_reportingTimer.cancel();
}
- //Stop incoming connections
- unbind();
+ if (_broker != null)
+ {
+ _broker.setDesiredState(_broker.getActualState(), State.STOPPED);
+ }
//Shutdown virtualhosts
close(_virtualHostRegistry);
- close(_authenticationManagerRegistry);
-
- close(_qmfService);
-
- close(_pluginManager);
-
- BrokerConfig broker = getBrokerConfig();
- if(broker != null)
+ if (_taskExecutor != null)
{
- broker.getSystem().removeBroker(broker);
+ _taskExecutor.stop();
}
CurrentActor.get().message(BrokerMessages.STOPPED());
- }
- finally
- {
- CurrentActor.remove();
- }
- }
-
- private void unbind()
- {
- List<QpidAcceptor> removedAcceptors = new ArrayList<QpidAcceptor>();
- synchronized (_acceptors)
- {
- for (InetSocketAddress bindAddress : _acceptors.keySet())
- {
- QpidAcceptor acceptor = _acceptors.get(bindAddress);
- removedAcceptors.add(acceptor);
- try
- {
- acceptor.getNetworkTransport().close();
- }
- catch (Throwable e)
- {
- _logger.error("Unable to close network driver due to:" + e.getMessage());
- }
+ _logRecorder.closeLogRecorder();
- CurrentActor.get().message(BrokerMessages.SHUTTING_DOWN(acceptor.toString(), bindAddress.getPort()));
- }
}
- synchronized (_portBindingListeners)
- {
- for(QpidAcceptor acceptor : removedAcceptors)
- {
- for(PortBindingListener listener : _portBindingListeners)
- {
- listener.unbound(acceptor);
- }
- }
- }
- }
-
- public ServerConfiguration getConfiguration()
- {
- return _configuration;
- }
-
- public void addAcceptor(InetSocketAddress bindAddress, QpidAcceptor acceptor)
- {
- synchronized (_acceptors)
- {
- _acceptors.put(bindAddress, acceptor);
- }
- synchronized (_portBindingListeners)
+ finally
{
- for(PortBindingListener listener : _portBindingListeners)
+ if (_taskExecutor != null)
{
- listener.bound(acceptor, bindAddress);
+ _taskExecutor.stopImmediately();
}
+ CurrentActor.remove();
}
- }
-
- public VirtualHostRegistry getVirtualHostRegistry()
- {
- return _virtualHostRegistry;
- }
-
- public SecurityManager getSecurityManager()
- {
- return _securityManager;
- }
-
- @Override
- public AuthenticationManager getAuthenticationManager(SocketAddress address)
- {
- return _authenticationManagerRegistry.getAuthenticationManager(address);
- }
-
- @Override
- public IAuthenticationManagerRegistry getAuthenticationManagerRegistry()
- {
- return _authenticationManagerRegistry;
- }
-
- public PluginManager getPluginManager()
- {
- return _pluginManager;
- }
-
- public ConfigurationManager getConfigurationManager()
- {
- return _configurationManager;
- }
-
- public RootMessageLogger getRootMessageLogger()
- {
- return _rootMessageLogger;
- }
-
- public RootMessageLogger getCompositeStartupMessageLogger()
- {
- return _startupMessageLogger;
- }
-
- public UUID getBrokerId()
- {
- return _brokerId;
- }
-
- public QMFService getQMFService()
- {
- return _qmfService;
- }
-
- public BrokerConfig getBrokerConfig()
- {
- return _brokerConfig;
- }
-
- public void setBrokerConfig(final BrokerConfig broker)
- {
- _brokerConfig = broker;
- }
-
- public VirtualHost createVirtualHost(final VirtualHostConfiguration vhostConfig) throws Exception
- {
- VirtualHostImpl virtualHost = new VirtualHostImpl(this, vhostConfig);
- _virtualHostRegistry.registerVirtualHost(virtualHost);
- getBrokerConfig().addVirtualHost(virtualHost);
- return virtualHost;
+ _store = null;
+ _broker = null;
}
public void registerMessageDelivered(long messageSize)
@@ -713,60 +343,10 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
logActor.message(BrokerMessages.MAX_MEMORY(Runtime.getRuntime().maxMemory()));
}
+ @Override
public Broker getBroker()
{
return _broker;
}
- @Override
- public void addPortBindingListener(PortBindingListener listener)
- {
- synchronized (_portBindingListeners)
- {
- _portBindingListeners.add(listener);
- }
- }
-
-
- @Override
- public boolean useHTTPManagement()
- {
- return _httpManagementPort != -1;
- }
-
- @Override
- public int getHTTPManagementPort()
- {
- return _httpManagementPort;
- }
-
- @Override
- public boolean useHTTPSManagement()
- {
- return _httpsManagementPort != -1;
- }
-
- @Override
- public int getHTTPSManagementPort()
- {
- return _httpsManagementPort;
- }
-
- public LogRecorder getLogRecorder()
- {
- return _logRecorder;
- }
-
- @Override
- public void addRegistryChangeListener(IAuthenticationManagerRegistry.RegistryChangeListener registryChangeListener)
- {
- if(_authenticationManagerRegistry == null)
- {
- _authManagerChangeListeners.add(registryChangeListener);
- }
- else
- {
- _authenticationManagerRegistry.addRegistryChangeListener(registryChangeListener);
- }
- }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/registry/BrokerConfigAdapter.java b/java/broker/src/main/java/org/apache/qpid/server/registry/BrokerConfigAdapter.java
deleted file mode 100644
index 950a090b43..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/registry/BrokerConfigAdapter.java
+++ /dev/null
@@ -1,195 +0,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.
- *
- */
-package org.apache.qpid.server.registry;
-
-import org.apache.qpid.common.QpidProperties;
-import org.apache.qpid.common.ServerPropertyNames;
-import org.apache.qpid.server.configuration.BrokerConfig;
-import org.apache.qpid.server.configuration.BrokerConfigType;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.SystemConfig;
-import org.apache.qpid.server.configuration.VirtualHostConfig;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class BrokerConfigAdapter implements BrokerConfig
-{
- private final IApplicationRegistry _instance;
- private SystemConfig _system;
-
- private final Map<UUID, VirtualHostConfig> _vhosts = new ConcurrentHashMap<UUID, VirtualHostConfig>();
- private final long _createTime = System.currentTimeMillis();
- private UUID _qmfId;
- private String _federationTag;
-
- public BrokerConfigAdapter(final IApplicationRegistry instance)
- {
- _instance = instance;
- _qmfId = instance.getConfigStore().createId();
- _federationTag = UUID.randomUUID().toString();
- }
-
- public void setSystem(final SystemConfig system)
- {
- _system = system;
- }
-
- public SystemConfig getSystem()
- {
- return _system;
- }
-
- public Integer getPort()
- {
- List ports = _instance.getConfiguration().getPorts();
- if(ports.size() > 0)
- {
- return Integer.valueOf(ports.get(0).toString());
- }
- else
- {
- return 0;
- }
- }
-
- public Integer getWorkerThreads()
- {
- return _instance.getConfiguration().getConnectorProcessors();
- }
-
- public Integer getMaxConnections()
- {
- return 0;
- }
-
- public Integer getConnectionBacklogLimit()
- {
- return 0;
- }
-
- public Long getStagingThreshold()
- {
- return 0L;
- }
-
- public Integer getManagementPublishInterval()
- {
- return 10000;
- }
-
- public String getVersion()
- {
- return QpidProperties.getReleaseVersion() + " [Build: " + QpidProperties.getBuildVersion() + "]";
- }
-
- public String getDataDirectory()
- {
- return _instance.getConfiguration().getQpidWork();
- }
-
- public void addVirtualHost(final VirtualHostConfig virtualHost)
- {
- _vhosts.put(virtualHost.getQMFId(), virtualHost);
- getConfigStore().addConfiguredObject(virtualHost);
-
- }
-
- private ConfigStore getConfigStore()
- {
- return _instance.getConfigStore();
- }
-
- public long getCreateTime()
- {
- return _createTime;
- }
-
- public void createBrokerConnection(final String transport,
- final String host,
- final int port,
- final boolean durable,
- final String authMechanism,
- final String username,
- final String password)
- {
- VirtualHost vhost = _instance.getVirtualHostRegistry().getDefaultVirtualHost();
- vhost.createBrokerConnection(transport, host, port, "", durable, authMechanism, username, password);
- }
-
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public BrokerConfigType getConfigType()
- {
- return BrokerConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return _system;
- }
-
- public boolean isDurable()
- {
- return false;
- }
-
- public String getFederationTag()
- {
- return _federationTag;
- }
-
- /**
- * @see org.apache.qpid.server.configuration.BrokerConfig#getFeatures()
- */
- public List<String> getFeatures()
- {
- final List<String> features = new ArrayList<String>();
- if (!_instance.getConfiguration().getDisabledFeatures().contains(ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR))
- {
- features.add(ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR);
- }
-
- return Collections.unmodifiableList(features);
- }
-
- @Override
- public String toString()
- {
- return "BrokerConfigAdapter{" +
- "_id=" + _qmfId +
- ", _system=" + _system +
- ", _vhosts=" + _vhosts +
- ", _createTime=" + _createTime +
- ", _federationTag='" + _federationTag + '\'' +
- '}';
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java
deleted file mode 100644
index 774d0338ef..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java
+++ /dev/null
@@ -1,42 +0,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.
- *
- */
-package org.apache.qpid.server.registry;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.osgi.framework.BundleContext;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-
-import java.io.File;
-
-public class ConfigurationFileApplicationRegistry extends ApplicationRegistry
-{
- public ConfigurationFileApplicationRegistry(File configurationURL) throws ConfigurationException
- {
- this(configurationURL, null);
- }
-
- public ConfigurationFileApplicationRegistry(File configurationURL, BundleContext bundleContext) throws ConfigurationException
- {
- super(new ServerConfiguration(configurationURL), bundleContext);
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java
index 88c3c93156..d12258d194 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java
@@ -20,27 +20,8 @@
*/
package org.apache.qpid.server.registry;
-import org.apache.qpid.qmf.QMFService;
-import org.apache.qpid.server.configuration.BrokerConfig;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfigurationManager;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
-import org.apache.qpid.server.logging.RootMessageLogger;
import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.plugins.PluginManager;
-import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry;
import org.apache.qpid.server.stats.StatisticsGatherer;
-import org.apache.qpid.server.transport.QpidAcceptor;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.Map;
-import java.util.UUID;
public interface IApplicationRegistry extends StatisticsGatherer
{
@@ -56,80 +37,5 @@ public interface IApplicationRegistry extends StatisticsGatherer
*/
void close();
- /**
- * Get the low level configuration. For use cases where the configured object approach is not required
- * you can get the complete configuration information.
- * @return a Commons Configuration instance
- */
- ServerConfiguration getConfiguration();
-
- /**
- * Get the AuthenticationManager for the given socket address
- *
- * If no AuthenticationManager has been specifically set for the given address, then use the default
- * AuthenticationManager
- *
- * @param address The (listening) socket address for which the AuthenticationManager is required
- * @return the AuthenticationManager
- */
- AuthenticationManager getAuthenticationManager(SocketAddress address);
-
- IAuthenticationManagerRegistry getAuthenticationManagerRegistry();
-
- VirtualHostRegistry getVirtualHostRegistry();
-
- SecurityManager getSecurityManager();
-
- PluginManager getPluginManager();
-
- ConfigurationManager getConfigurationManager();
-
- RootMessageLogger getRootMessageLogger();
-
- /**
- * Register any acceptors for this registry
- * @param bindAddress The address that the acceptor has been bound with
- * @param acceptor The acceptor in use
- */
- void addAcceptor(InetSocketAddress bindAddress, QpidAcceptor acceptor);
-
- public UUID getBrokerId();
-
- QMFService getQMFService();
-
- void setBrokerConfig(BrokerConfig broker);
-
- BrokerConfig getBrokerConfig();
-
Broker getBroker();
-
- VirtualHost createVirtualHost(VirtualHostConfiguration vhostConfig) throws Exception;
-
- ConfigStore getConfigStore();
-
- void setConfigStore(ConfigStore store);
-
- void initialiseStatisticsReporting();
-
- Map<InetSocketAddress, QpidAcceptor> getAcceptors();
-
- void addPortBindingListener(PortBindingListener listener);
-
- boolean useHTTPManagement();
-
- int getHTTPManagementPort();
-
- boolean useHTTPSManagement();
-
- int getHTTPSManagementPort();
-
- void addRegistryChangeListener(IAuthenticationManagerRegistry.RegistryChangeListener registryChangeListener);
-
- public interface PortBindingListener
- {
- public void bound(QpidAcceptor acceptor, InetSocketAddress bindAddress);
- public void unbound(QpidAcceptor acceptor);
-
- }
-
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java
deleted file mode 100644
index 704e50da5c..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/AbstractPlugin.java
+++ /dev/null
@@ -1,57 +0,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.
- *
- */
-package org.apache.qpid.server.security;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-
-/**
- * This is intended as the parent for all simple plugins.
- */
-public abstract class AbstractPlugin implements SecurityPlugin
-{
- private final Logger _logger = Logger.getLogger(getClass());
-
- private ConfigurationPlugin _config;
-
- public Result getDefault()
- {
- return Result.ABSTAIN;
- }
-
- public abstract Result access(ObjectType object, Object instance);
-
- public abstract Result authorise(Operation operation, ObjectType object, ObjectProperties properties);
-
- public void configure(ConfigurationPlugin config)
- {
- _config = config;
- }
-
- public ConfigurationPlugin getConfig()
- {
- return _config;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java
deleted file mode 100644
index 236931e8cd..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/AbstractProxyPlugin.java
+++ /dev/null
@@ -1,122 +0,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.
- *
- */
-package org.apache.qpid.server.security;
-
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-
-/**
- * This {@link SecurityPlugin} proxies the authorise calls to a serries of methods, one per {@link Operation}.
- *
- */
-public abstract class AbstractProxyPlugin extends AbstractPlugin
-{
- public Result authoriseConsume(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result authorisePublish(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result authoriseCreate(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result authoriseAccess(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result authoriseBind(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result authoriseUnbind(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result authoriseDelete(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result authorisePurge(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result authoriseUpdate(ObjectType object, ObjectProperties properties)
- {
- return getDefault();
- }
-
- public Result accessVirtualhost(Object instance)
- {
- return getDefault();
- }
-
- @Override
- public Result access(ObjectType objectType, Object instance)
- {
- switch (objectType)
- {
- case VIRTUALHOST:
- return accessVirtualhost(instance);
- }
-
- return getDefault();
- }
-
- @Override
- public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties)
- {
- switch (operation)
- {
- case CONSUME:
- return authoriseConsume(objectType, properties);
- case PUBLISH:
- return authorisePublish(objectType, properties);
- case CREATE:
- return authoriseCreate(objectType, properties);
- case ACCESS:
- return authoriseAccess(objectType, properties);
- case BIND:
- return authoriseBind(objectType, properties);
- case UNBIND:
- return authoriseUnbind(objectType, properties);
- case DELETE:
- return authoriseDelete(objectType, properties);
- case PURGE:
- return authorisePurge(objectType, properties);
- case UPDATE:
- return authoriseUpdate(objectType, properties);
- }
-
- return getDefault();
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java b/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java
new file mode 100644
index 0000000000..b4831f83e5
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/AccessControl.java
@@ -0,0 +1,45 @@
+/*
+ * 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.security;
+
+import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectType;
+import org.apache.qpid.server.security.access.Operation;
+
+/**
+ * The two methods, {@link #access(ObjectType, Object)} and {@link #authorise(Operation, ObjectType, ObjectProperties)},
+ * return the {@link Result} of the security decision, which may be to {@link Result#ABSTAIN} if no decision is made.
+ */
+public interface AccessControl
+{
+ /**
+ * Default result for {@link #access(ObjectType, Object)} or {@link #authorise(Operation, ObjectType, ObjectProperties)}.
+ */
+ Result getDefault();
+
+ /**
+ * Authorise access granted to an object instance.
+ */
+ Result access(ObjectType objectType, Object instance);
+
+ /**
+ * Authorise an operation on an object defined by a set of properties.
+ */
+ Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/AuthorizationHolder.java b/java/broker/src/main/java/org/apache/qpid/server/security/AuthorizationHolder.java
index 8f3bdf7738..8243fc3f75 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/security/AuthorizationHolder.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/AuthorizationHolder.java
@@ -24,14 +24,14 @@ import javax.security.auth.Subject;
import java.security.Principal;
/**
- * Represents the authorization of the logged on user.
- *
+ * Represents the authorization of the logged on user.
+ *
*/
public interface AuthorizationHolder
{
- /**
+ /**
* Returns the {@link Subject} of the authorized user. This is guaranteed to
- * contain at least one {@link org.apache.qpid.server.security.auth.sasl.UsernamePrincipal}, representing the the identity
+ * contain at least one {@link org.apache.qpid.server.security.auth.UsernamePrincipal}, representing the the identity
* used when the user logged on to the application, and zero or more {@link org.apache.qpid.server.security.auth.sasl.GroupPrincipal}
* representing the group(s) to which the user belongs.
*
@@ -39,10 +39,10 @@ public interface AuthorizationHolder
*/
Subject getAuthorizedSubject();
- /**
+ /**
* Returns the {@link Principal} representing the the identity
* used when the user logged on to the application.
- *
+ *
* @return a Principal
*/
Principal getAuthorizedPrincipal();
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
index 436660cfaf..1a1cce171b 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
@@ -18,22 +18,23 @@
*/
package org.apache.qpid.server.security;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.plugins.PluginManager;
+
+import org.apache.qpid.server.plugin.AccessControlFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.security.access.ObjectProperties;
+import org.apache.qpid.server.security.access.ObjectType;
import org.apache.qpid.server.security.access.Operation;
import static org.apache.qpid.server.security.access.ObjectType.EXCHANGE;
+import static org.apache.qpid.server.security.access.ObjectType.GROUP;
import static org.apache.qpid.server.security.access.ObjectType.METHOD;
import static org.apache.qpid.server.security.access.ObjectType.QUEUE;
+import static org.apache.qpid.server.security.access.ObjectType.USER;
import static org.apache.qpid.server.security.access.ObjectType.VIRTUALHOST;
import static org.apache.qpid.server.security.access.Operation.BIND;
import static org.apache.qpid.server.security.access.Operation.CONSUME;
@@ -45,103 +46,105 @@ import static org.apache.qpid.server.security.access.Operation.UNBIND;
import javax.security.auth.Subject;
import java.net.SocketAddress;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
/**
- * The security manager contains references to all loaded {@link SecurityPlugin}s and delegates security decisions to them based
+ * The security manager contains references to all loaded {@link AccessControl}s and delegates security decisions to them based
* on virtual host name. The plugins can be external <em>OSGi</em> .jar files that export the required classes or just internal
* objects for simpler plugins.
- *
- * @see SecurityPlugin
+ *
+ * @see AccessControl
*/
public class SecurityManager
{
private static final Logger _logger = Logger.getLogger(SecurityManager.class);
-
+
/** Container for the {@link java.security.Principal} that is using to this thread. */
private static final ThreadLocal<Subject> _subject = new ThreadLocal<Subject>();
- private static final ThreadLocal<Boolean> _accessChecksDisabled = new ThreadLocal<Boolean>()
+
+ public static final ThreadLocal<Boolean> _accessChecksDisabled = new ClearingThreadLocal(false);
+
+ private Map<String, AccessControl> _globalPlugins = new HashMap<String, AccessControl>();
+ private Map<String, AccessControl> _hostPlugins = new HashMap<String, AccessControl>();
+
+ /**
+ * A special ThreadLocal, which calls remove() on itself whenever the value is
+ * the default, to avoid leaving a default value set after its use has passed.
+ */
+ private static final class ClearingThreadLocal extends ThreadLocal<Boolean>
{
- protected Boolean initialValue()
+ private Boolean _defaultValue;
+
+ public ClearingThreadLocal(Boolean defaultValue)
{
- return false;
+ super();
+ _defaultValue = defaultValue;
}
- };
- private PluginManager _pluginManager;
- private Map<String, SecurityPluginFactory> _pluginFactories = new HashMap<String, SecurityPluginFactory>();
- private Map<String, SecurityPlugin> _globalPlugins = new HashMap<String, SecurityPlugin>();
- private Map<String, SecurityPlugin> _hostPlugins = new HashMap<String, SecurityPlugin>();
+ @Override
+ protected Boolean initialValue()
+ {
+ return _defaultValue;
+ }
- public static class SecurityConfiguration extends ConfigurationPlugin
- {
- public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory()
+ @Override
+ public void set(Boolean value)
{
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
+ if (value == _defaultValue)
{
- ConfigurationPlugin instance = new SecurityConfiguration();
- instance.setConfiguration(path, config);
- return instance;
+ super.remove();
}
-
- public List<String> getParentPaths()
+ else
{
- return Arrays.asList("security", "virtualhosts.virtualhost.security");
+ super.set(value);
}
- };
-
- @Override
- public String[] getElementsProcessed()
- {
- return new String[]{"security"};
}
- public void validateConfiguration() throws ConfigurationException
+ @Override
+ public Boolean get()
{
- if (getConfig().isEmpty())
+ Boolean value = super.get();
+ if (value == _defaultValue)
{
- throw new ConfigurationException("security section is incomplete, no elements found.");
+ super.remove();
}
+ return value;
}
}
-
- public SecurityManager(SecurityManager parent) throws ConfigurationException
+ /*
+ * Used by the VirtualHost to allow deferring to the broker level security plugins if required.
+ */
+ public SecurityManager(SecurityManager parent, String aclFile)
{
- _pluginManager = parent._pluginManager;
- _pluginFactories = parent._pluginFactories;
-
+ this(aclFile);
+
// our global plugins are the parent's host plugins
_globalPlugins = parent._hostPlugins;
}
- public SecurityManager(ConfigurationPlugin configuration, PluginManager manager) throws ConfigurationException
+ public SecurityManager(String aclFile)
{
- this(configuration, manager, null);
- }
-
- public SecurityManager(ConfigurationPlugin configuration, PluginManager manager, SecurityPluginFactory plugin) throws ConfigurationException
- {
- _pluginManager = manager;
- if (manager == null) // No plugin manager, no plugins
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put("aclFile", aclFile);
+ for (AccessControlFactory provider : (new QpidServiceLoader<AccessControlFactory>()).instancesOf(AccessControlFactory.class))
{
- return;
+ AccessControl accessControl = provider.createInstance(attributes);
+ if(accessControl != null)
+ {
+ addHostPlugin(accessControl);
+ }
}
- _pluginFactories = _pluginManager.getSecurityPlugins();
- if (plugin != null)
+ if(_logger.isDebugEnabled())
{
- _pluginFactories.put(plugin.getPluginName(), plugin);
+ _logger.debug("Configured " + _hostPlugins.size() + " access control plugins");
}
-
- configureHostPlugins(configuration);
}
public static Subject getThreadSubject()
@@ -154,41 +157,6 @@ public class SecurityManager
_subject.set(subject);
}
- public void configureHostPlugins(ConfigurationPlugin hostConfig) throws ConfigurationException
- {
- _hostPlugins = configurePlugins(hostConfig);
- }
-
- public void configureGlobalPlugins(ConfigurationPlugin configuration) throws ConfigurationException
- {
- _globalPlugins = configurePlugins(configuration);
- }
-
- public Map<String, SecurityPlugin> configurePlugins(ConfigurationPlugin hostConfig) throws ConfigurationException
- {
- Map<String, SecurityPlugin> plugins = new HashMap<String, SecurityPlugin>();
- SecurityConfiguration securityConfig = hostConfig.getConfiguration(SecurityConfiguration.class.getName());
-
- // If we have no security Configuration then there is nothing to configure.
- if (securityConfig != null)
- {
- for (SecurityPluginFactory<?> factory : _pluginFactories.values())
- {
- SecurityPlugin plugin = factory.newInstance(securityConfig);
- if (plugin != null)
- {
- plugins.put(factory.getPluginName(), plugin);
- }
- }
- }
- return plugins;
- }
-
- public void addHostPlugin(SecurityPlugin plugin)
- {
- _hostPlugins.put(plugin.getClass().getName(), plugin);
- }
-
public static Logger getLogger()
{
return _logger;
@@ -205,7 +173,7 @@ public class SecurityManager
private abstract class AccessCheck
{
- abstract Result allowed(SecurityPlugin plugin);
+ abstract Result allowed(AccessControl plugin);
}
private boolean checkAllPlugins(AccessCheck checker)
@@ -215,16 +183,16 @@ public class SecurityManager
return true;
}
- Map<String, SecurityPlugin> remainingPlugins = _globalPlugins.isEmpty()
- ? Collections.<String, SecurityPlugin>emptyMap()
- : _hostPlugins.isEmpty() ? _globalPlugins : new HashMap<String, SecurityPlugin>(_globalPlugins);
-
- if(!_hostPlugins.isEmpty())
+ Map<String, AccessControl> remainingPlugins = _globalPlugins.isEmpty()
+ ? Collections.<String, AccessControl>emptyMap()
+ : _hostPlugins.isEmpty() ? _globalPlugins : new HashMap<String, AccessControl>(_globalPlugins);
+
+ if(!_hostPlugins.isEmpty())
{
- for (Entry<String, SecurityPlugin> hostEntry : _hostPlugins.entrySet())
+ for (Entry<String, AccessControl> hostEntry : _hostPlugins.entrySet())
{
// Create set of global only plugins
- SecurityPlugin globalPlugin = remainingPlugins.get(hostEntry.getKey());
+ AccessControl globalPlugin = remainingPlugins.get(hostEntry.getKey());
if (globalPlugin != null)
{
remainingPlugins.remove(hostEntry.getKey());
@@ -272,7 +240,7 @@ public class SecurityManager
}
}
- for (SecurityPlugin plugin : remainingPlugins.values())
+ for (AccessControl plugin : remainingPlugins.values())
{
Result remaining = checker.allowed(plugin);
if (remaining == Result.DEFER)
@@ -284,16 +252,16 @@ public class SecurityManager
return false;
}
}
-
+
// getting here means either allowed or abstained from all plugins
return true;
}
-
+
public boolean authoriseBind(final Exchange exch, final AMQQueue queue, final AMQShortString routingKey)
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(BIND, EXCHANGE, new ObjectProperties(exch, queue, routingKey));
}
@@ -304,7 +272,7 @@ public class SecurityManager
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
ObjectProperties properties = new ObjectProperties();
properties.setName(methodName);
@@ -318,11 +286,22 @@ public class SecurityManager
});
}
+ public boolean accessManagement()
+ {
+ return checkAllPlugins(new AccessCheck()
+ {
+ Result allowed(AccessControl plugin)
+ {
+ return plugin.access(ObjectType.MANAGEMENT, null);
+ }
+ });
+ }
+
public boolean accessVirtualhost(final String vhostname, final SocketAddress remoteAddress)
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.access(VIRTUALHOST, remoteAddress);
}
@@ -333,7 +312,7 @@ public class SecurityManager
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(CONSUME, QUEUE, new ObjectProperties(queue));
}
@@ -345,7 +324,7 @@ public class SecurityManager
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(CREATE, EXCHANGE, new ObjectProperties(autoDelete, durable, exchangeName,
internal, nowait, passive, exchangeType));
@@ -358,7 +337,7 @@ public class SecurityManager
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(CREATE, QUEUE, new ObjectProperties(autoDelete, durable, exclusive, nowait, passive, queueName, owner));
}
@@ -369,7 +348,7 @@ public class SecurityManager
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(DELETE, QUEUE, new ObjectProperties(queue));
}
@@ -380,13 +359,34 @@ public class SecurityManager
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(DELETE, EXCHANGE, new ObjectProperties(exchange.getName()));
}
});
}
+ public boolean authoriseGroupOperation(final Operation operation, final String groupName)
+ {
+ return checkAllPlugins(new AccessCheck()
+ {
+ Result allowed(AccessControl plugin)
+ {
+ return plugin.authorise(operation, GROUP, new ObjectProperties(groupName));
+ }
+ });
+ }
+
+ public boolean authoriseUserOperation(final Operation operation, final String userName)
+ {
+ return checkAllPlugins(new AccessCheck()
+ {
+ Result allowed(AccessControl plugin)
+ {
+ return plugin.authorise(operation, USER, new ObjectProperties(userName));
+ }
+ });
+ }
private ConcurrentHashMap<String, ConcurrentHashMap<String, PublishAccessCheck>> _immediatePublishPropsCache
= new ConcurrentHashMap<String, ConcurrentHashMap<String, PublishAccessCheck>>();
@@ -428,7 +428,7 @@ public class SecurityManager
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(PURGE, QUEUE, new ObjectProperties(queue));
}
@@ -439,7 +439,7 @@ public class SecurityManager
{
return checkAllPlugins(new AccessCheck()
{
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(UNBIND, EXCHANGE, new ObjectProperties(exch, queue, routingKey));
}
@@ -465,9 +465,16 @@ public class SecurityManager
_props = props;
}
- Result allowed(SecurityPlugin plugin)
+ Result allowed(AccessControl plugin)
{
return plugin.authorise(PUBLISH, EXCHANGE, _props);
}
}
+
+
+ public void addHostPlugin(AccessControl plugin)
+ {
+ _hostPlugins.put(plugin.getClass().getName(), plugin);
+ }
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java
deleted file mode 100644
index c3c06bf206..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPlugin.java
+++ /dev/null
@@ -1,47 +0,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.
- */
-package org.apache.qpid.server.security;
-
-import org.apache.qpid.server.plugins.Plugin;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-
-/**
- * The two methods, {@link #access(ObjectType, Object)} and {@link #authorise(Operation, ObjectType, ObjectProperties)},
- * return the {@link Result} of the security decision, which may be to {@link Result#ABSTAIN} if no decision is made
- * by this plugin.
- */
-public interface SecurityPlugin extends Plugin
-{
- /**
- * Default result for {@link #access(ObjectType, Object)} or {@link #authorise(Operation, ObjectType, ObjectProperties)}.
- */
- Result getDefault();
-
- /**
- * Authorise access granted to an object instance.
- */
- Result access(ObjectType objectType, Object instance);
-
- /**
- * Authorise an operation on an object defined by a set of properties.
- */
- Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties);
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java b/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java
deleted file mode 100644
index 21c2d1cda5..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginActivator.java
+++ /dev/null
@@ -1,75 +0,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.
- *
- */
-package org.apache.qpid.server.security;
-
-import org.apache.log4j.Logger;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-
-/**
- * An OSGi {@link BundleActivator} that loads a {@link SecurityPluginFactory}.
- */
-public abstract class SecurityPluginActivator implements BundleActivator
-{
- private static final Logger _logger = Logger.getLogger(SecurityPluginActivator.class);
-
- private SecurityPluginFactory _factory;
- private ConfigurationPluginFactory _config;
- private BundleContext _ctx;
- private String _bundleName;
-
- /** Implement this to return the factory this plugin activates. */
- public abstract SecurityPluginFactory getFactory();
-
- /** Implement this to return the factory this plugin activates. */
- public abstract ConfigurationPluginFactory getConfigurationFactory();
-
- /**
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext ctx) throws Exception
- {
- _ctx = ctx;
- _factory = getFactory();
- _config = getConfigurationFactory();
- _bundleName = ctx.getBundle().getSymbolicName();
-
- // register the service
- _logger.info("Registering security plugin: " + _bundleName);
- _ctx.registerService(SecurityPluginFactory.class.getName(), _factory, null);
- _ctx.registerService(ConfigurationPluginFactory.class.getName(), _config, null);
- }
-
- /**
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception
- {
- _logger.info("Stopping security plugin: " + _bundleName);
-
- // null object references
- _factory = null;
- _config = null;
- _ctx = null;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java
deleted file mode 100644
index fe81cba282..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/SecurityPluginFactory.java
+++ /dev/null
@@ -1,30 +0,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.
- *
- */
-package org.apache.qpid.server.security;
-
-import org.apache.qpid.server.plugins.PluginFactory;
-
-/**
- * The factory that generates instances of security plugins. Usually implemented as a static member class in the plugin itself.
- */
-public interface SecurityPluginFactory<S extends SecurityPlugin> extends PluginFactory<S>
-{
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/SubjectCreator.java b/java/broker/src/main/java/org/apache/qpid/server/security/SubjectCreator.java
new file mode 100644
index 0000000000..8138745486
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/SubjectCreator.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.server.security;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+import javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
+
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+
+/**
+ * Creates a {@link Subject} formed by the {@link Principal}'s returned from:
+ * <ol>
+ * <li>Authenticating using an {@link AuthenticationManager}</li>
+ * <li>A {@link GroupPrincipalAccessor}</li>
+ * </ol>
+ *
+ * <p>
+ * SubjectCreator is a facade to the {@link AuthenticationManager}, and is intended to be
+ * the single place that {@link Subject}'s are created in the broker.
+ * </p>
+ */
+public class SubjectCreator
+{
+ private AuthenticationManager _authenticationManager;
+ private GroupPrincipalAccessor _groupAccessor;
+
+ public SubjectCreator(AuthenticationManager authenticationManager, GroupPrincipalAccessor groupAccessor)
+ {
+ _authenticationManager = authenticationManager;
+ _groupAccessor = groupAccessor;
+ }
+
+ /**
+ * Gets the known SASL mechanisms
+ *
+ * @return SASL mechanism names, space separated.
+ */
+ public String getMechanisms()
+ {
+ return _authenticationManager.getMechanisms();
+ }
+
+ /**
+ * @see AuthenticationManager#createSaslServer(String, String, Principal)
+ */
+ public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException
+ {
+ return _authenticationManager.createSaslServer(mechanism, localFQDN, externalPrincipal);
+ }
+
+ /**
+ * Authenticates a user using SASL negotiation.
+ *
+ * @param server SASL server
+ * @param response SASL response to process
+ */
+ public SubjectAuthenticationResult authenticate(SaslServer server, byte[] response)
+ {
+ AuthenticationResult authenticationResult = _authenticationManager.authenticate(server, response);
+ if(server.isComplete())
+ {
+ String username = server.getAuthorizationID();
+
+ return createResultWithGroups(username, authenticationResult);
+ }
+ else
+ {
+ return new SubjectAuthenticationResult(authenticationResult);
+ }
+ }
+
+ /**
+ * Authenticates a user using their username and password.
+ */
+ public SubjectAuthenticationResult authenticate(String username, String password)
+ {
+ final AuthenticationResult authenticationResult = _authenticationManager.authenticate(username, password);
+
+ return createResultWithGroups(username, authenticationResult);
+ }
+
+ private SubjectAuthenticationResult createResultWithGroups(String username, final AuthenticationResult authenticationResult)
+ {
+ if(authenticationResult.getStatus() == AuthenticationStatus.SUCCESS)
+ {
+ final Subject authenticationSubject = new Subject();
+
+ authenticationSubject.getPrincipals().addAll(authenticationResult.getPrincipals());
+ authenticationSubject.getPrincipals().addAll(_groupAccessor.getGroupPrincipals(username));
+
+ authenticationSubject.setReadOnly();
+
+ return new SubjectAuthenticationResult(authenticationResult, authenticationSubject);
+ }
+ else
+ {
+ return new SubjectAuthenticationResult(authenticationResult);
+ }
+ }
+
+ public Subject createSubjectWithGroups(String username)
+ {
+ Subject authenticationSubject = new Subject();
+
+ authenticationSubject.getPrincipals().add(new AuthenticatedPrincipal(username));
+ authenticationSubject.getPrincipals().addAll(_groupAccessor.getGroupPrincipals(username));
+ authenticationSubject.setReadOnly();
+
+ return authenticationSubject;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java b/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java
index a9ec4d1647..8e38681e68 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java
@@ -18,33 +18,31 @@
*/
package org.apache.qpid.server.security.access;
-import org.apache.commons.lang.StringUtils;
-
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.queue.AMQQueue;
-
import java.util.ArrayList;
import java.util.EnumMap;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.queue.AMQQueue;
+
/**
* An set of properties for an access control v2 rule {@link ObjectType}.
- *
+ *
* The {@link #matches(ObjectProperties)} method is intended to be used when determining precedence of rules, and
* {@link #equals(Object)} and {@link #hashCode()} are intended for use in maps. This is due to the wildcard matching
* described above.
*/
public class ObjectProperties
{
- /** serialVersionUID */
- private static final long serialVersionUID = -1356019341374170495L;
-
public static final String STAR= "*";
public static final ObjectProperties EMPTY = new ObjectProperties();
-
+
public enum Property
{
ROUTING_KEY,
@@ -65,81 +63,89 @@ public class ObjectProperties
AUTO_DELETE,
COMPONENT,
PACKAGE,
- CLASS;
-
- public static Property parse(String text)
+ CLASS,
+ FROM_NETWORK,
+ FROM_HOSTNAME;
+
+ private static final Map<String, Property> _canonicalNameToPropertyMap = new HashMap<String, ObjectProperties.Property>();
+
+ static
{
for (Property property : values())
{
- if (property.getName().equalsIgnoreCase(text))
- {
- return property;
- }
+ _canonicalNameToPropertyMap.put(getCanonicalName(property.name()), property);
+ }
+ }
+
+ /**
+ * Properties are parsed using their canonical name (see {@link #getCanonicalName(String)})
+ * so that, for the sake of user-friendliness, the ACL file parses is insensitive to
+ * case and underscores.
+ */
+ public static Property parse(String text)
+ {
+ String propertyName = getCanonicalName(text);
+ Property property = _canonicalNameToPropertyMap.get(propertyName);
+
+ if(property == null)
+ {
+ throw new IllegalArgumentException("Not a valid property: " + text
+ + " because " + propertyName
+ + " is not in " + _canonicalNameToPropertyMap.keySet());
+ }
+ else
+ {
+ return property;
}
- throw new IllegalArgumentException("Not a valid property: " + text);
}
-
- public String getName()
+
+ private static String getCanonicalName(String name)
{
- return StringUtils.remove(name(), '_').toLowerCase();
+ return StringUtils.remove(name, '_').toLowerCase();
}
-
- public static List<String> getPropertyNames()
- {
- List<String> properties = new ArrayList<String>();
- for (Property property : values())
- {
- properties.add(property.getName());
- }
- return properties;
- }
}
private final EnumMap<Property, String> _properties = new EnumMap<Property, String>(Property.class);
- public static List<String> getAllPropertyNames()
+ public static List<String> getAllPropertyNames()
{
- List<String> properties = new ArrayList<String>();
- for (Property property : Property.values())
- {
- properties.add(StringUtils.remove(property.name(), '_').toLowerCase());
- }
- return properties;
- }
-
+ List<String> properties = new ArrayList<String>();
+ for (Property property : Property.values())
+ {
+ properties.add(StringUtils.remove(property.name(), '_').toLowerCase());
+ }
+ return properties;
+ }
+
public ObjectProperties()
{
- super();
}
-
+
+ public ObjectProperties(Property property, String value)
+ {
+ _properties.put(property, value);
+ }
+
public ObjectProperties(ObjectProperties copy)
{
- super();
-
_properties.putAll(copy._properties);
}
-
+
public ObjectProperties(String name)
{
- super();
-
setName(name);
}
-
+
public ObjectProperties(AMQShortString name)
{
- super();
-
setName(name);
}
-
+
public ObjectProperties(AMQQueue queue)
{
- super();
-
setName(queue.getName());
-
+
put(Property.AUTO_DELETE, queue.isAutoDelete());
put(Property.TEMPORARY, queue.isAutoDelete());
put(Property.DURABLE, queue.isDurable());
@@ -157,45 +163,45 @@ public class ObjectProperties
put(Property.OWNER, queue.getAuthorizationHolder().getAuthorizedPrincipal().getName());
}
}
-
+
public ObjectProperties(Exchange exch, AMQQueue queue, AMQShortString routingKey)
{
this(queue);
-
- setName(exch.getName());
-
+
+ setName(exch.getName());
+
put(Property.QUEUE_NAME, queue.getName());
put(Property.ROUTING_KEY, routingKey);
}
-
+
public ObjectProperties(Exchange exch, AMQShortString routingKey)
{
this(exch.getName(), routingKey.asString());
}
-
+
public ObjectProperties(String exchangeName, String routingKey, Boolean immediate)
{
this(exchangeName, routingKey);
-
+
put(Property.IMMEDIATE, immediate);
}
-
+
public ObjectProperties(String exchangeName, String routingKey)
{
super();
-
+
setName(exchangeName);
-
+
put(Property.ROUTING_KEY, routingKey);
}
-
+
public ObjectProperties(Boolean autoDelete, Boolean durable, AMQShortString exchangeName,
Boolean internal, Boolean nowait, Boolean passive, AMQShortString exchangeType)
{
super();
-
+
setName(exchangeName);
-
+
put(Property.AUTO_DELETE, autoDelete);
put(Property.TEMPORARY, autoDelete);
put(Property.DURABLE, durable);
@@ -204,14 +210,14 @@ public class ObjectProperties
put(Property.PASSIVE, passive);
put(Property.TYPE, exchangeType);
}
-
+
public ObjectProperties(Boolean autoDelete, Boolean durable, Boolean exclusive, Boolean nowait, Boolean passive,
AMQShortString queueName, String owner)
{
super();
-
+
setName(queueName);
-
+
put(Property.AUTO_DELETE, autoDelete);
put(Property.TEMPORARY, autoDelete);
put(Property.DURABLE, durable);
@@ -220,7 +226,7 @@ public class ObjectProperties
put(Property.PASSIVE, passive);
put(Property.OWNER, owner);
}
-
+
public ObjectProperties(Boolean exclusive, Boolean noAck, Boolean noLocal, Boolean nowait, AMQQueue queue)
{
this(queue);
@@ -230,17 +236,7 @@ public class ObjectProperties
put(Property.EXCLUSIVE, exclusive);
put(Property.NO_WAIT, nowait);
}
-
- public List<String> getPropertyNames()
- {
- List<String> properties = new ArrayList<String>();
- for (Property property : _properties.keySet())
- {
- properties.add(property.getName());
- }
- return properties;
- }
-
+
public Boolean isSet(Property key)
{
return _properties.containsKey(key) && Boolean.valueOf(_properties.get(key));
@@ -255,17 +251,17 @@ public class ObjectProperties
{
return _properties.get(Property.NAME);
}
-
+
public void setName(String name)
{
_properties.put(Property.NAME, name);
}
-
+
public void setName(AMQShortString name)
{
put(Property.NAME, name);
}
-
+
public String put(Property key, AMQShortString value)
{
return put(key, value == null ? "" : value.asString());
@@ -275,7 +271,7 @@ public class ObjectProperties
{
return _properties.put(key, value == null ? "" : value.trim());
}
-
+
public void put(Property key, Boolean value)
{
if (value != null)
@@ -283,66 +279,64 @@ public class ObjectProperties
_properties.put(key, Boolean.toString(value));
}
}
-
+
public boolean matches(ObjectProperties properties)
{
if (properties._properties.keySet().isEmpty())
{
return true;
}
-
+
if (!_properties.keySet().containsAll(properties._properties.keySet()))
{
return false;
}
-
+
for (Map.Entry<Property,String> entry : properties._properties.entrySet())
{
Property key = entry.getKey();
String ruleValue = entry.getValue();
-
+
String thisValue = _properties.get(key);
- if (!valueMatches(thisValue, ruleValue))
+ if (!valueMatches(thisValue, ruleValue))
{
return false;
}
}
-
+
return true;
}
-
+
private boolean valueMatches(String thisValue, String ruleValue)
{
return (StringUtils.isEmpty(ruleValue)
|| StringUtils.equals(thisValue, ruleValue))
|| ruleValue.equals(STAR)
- || (ruleValue.endsWith(STAR)
+ || (ruleValue.endsWith(STAR)
&& thisValue != null
&& thisValue.length() >= ruleValue.length() - 1
&& thisValue.startsWith(ruleValue.substring(0, ruleValue.length() - 1)));
}
@Override
- public boolean equals(Object o)
+ public boolean equals(Object obj)
{
- if (this == o)
+ if (obj == null)
{
- return true;
+ return false;
}
- if (o == null || getClass() != o.getClass())
+ if (obj == this)
{
- return false;
+ return true;
}
-
- ObjectProperties that = (ObjectProperties) o;
-
- if (_properties != null ? !_properties.equals(that._properties) : that._properties != null)
+ if (obj.getClass() != getClass())
{
return false;
}
-
- return true;
+ ObjectProperties rhs = (ObjectProperties) obj;
+ return new EqualsBuilder()
+ .append(_properties, rhs._properties).isEquals();
}
@Override
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectType.java b/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectType.java
index 90ecd1dd17..8bc4b9d278 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectType.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectType.java
@@ -41,12 +41,15 @@ public enum ObjectType
{
ALL(Operation.ALL),
VIRTUALHOST(Operation.ALL, ACCESS),
+ MANAGEMENT(Operation.ALL, ACCESS),
QUEUE(Operation.ALL, CREATE, DELETE, PURGE, CONSUME),
EXCHANGE(Operation.ALL, ACCESS, CREATE, DELETE, BIND, UNBIND, PUBLISH),
LINK, // Not allowed in the Java broker
ROUTE, // Not allowed in the Java broker
- METHOD(Operation.ALL, ACCESS, UPDATE);
-
+ METHOD(Operation.ALL, ACCESS, UPDATE),
+ USER(Operation.ALL, CREATE, DELETE, UPDATE),
+ GROUP(Operation.ALL, CREATE, DELETE, UPDATE);
+
private EnumSet<Operation> _actions;
private ObjectType()
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java
deleted file mode 100644
index 4df135a4ca..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/BasicPlugin.java
+++ /dev/null
@@ -1,43 +0,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.
- *
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import org.apache.qpid.server.security.AbstractPlugin;
-import org.apache.qpid.server.security.Result;
-import org.apache.qpid.server.security.access.ObjectProperties;
-import org.apache.qpid.server.security.access.ObjectType;
-import org.apache.qpid.server.security.access.Operation;
-
-/**
- * This {@link org.apache.qpid.server.security.SecurityPlugin} simply abstains from all authorisation requests and ignores configuration.
- */
-public abstract class BasicPlugin extends AbstractPlugin
-{
- public Result access(ObjectType objectType, Object instance)
- {
- return getDefault();
- }
-
- public Result authorise(Operation operation, ObjectType objectType, ObjectProperties properties)
- {
- return getDefault();
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java b/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java
deleted file mode 100644
index 4b7a2fb457..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/access/plugins/LegacyAccess.java
+++ /dev/null
@@ -1,86 +0,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.
- */
-package org.apache.qpid.server.security.access.plugins;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.security.SecurityPluginFactory;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * The <code>LegacyAccess</code> plugin is used internally and simply ignores legacy elements of the configuration file.
- */
-public class LegacyAccess extends BasicPlugin
-{
- public static class LegacyAccessConfiguration extends ConfigurationPlugin {
- public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory()
- {
- public List<String> getParentPaths()
- {
- return Arrays.asList("security.msg-auth", "virtualhosts.virtualhost.security.msg-auth");
- }
-
- public ConfigurationPlugin newInstance(String path, Configuration config) throws ConfigurationException
- {
- ConfigurationPlugin instance = new LegacyAccessConfiguration();
- instance.setConfiguration(path, config);
- return instance;
- }
- };
-
- public String[] getElementsProcessed()
- {
- return new String[] { "" };
- }
- }
-
- public static final SecurityPluginFactory<LegacyAccess> FACTORY = new SecurityPluginFactory<LegacyAccess>()
- {
- public LegacyAccess newInstance(ConfigurationPlugin config) throws ConfigurationException
- {
- LegacyAccessConfiguration configuration = config.getConfiguration(LegacyAccessConfiguration.class.getName());
-
- // If there is no configuration for this plugin then don't load it.
- if (configuration == null)
- {
- return null;
- }
-
- LegacyAccess plugin = new LegacyAccess();
- plugin.configure(configuration);
- return plugin;
- }
-
- public String getPluginName()
- {
- return LegacyAccess.class.getName();
- }
-
- public Class<LegacyAccess> getPluginClass()
- {
- return LegacyAccess.class;
- }
- };
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipal.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipal.java
new file mode 100644
index 0000000000..fb31132514
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipal.java
@@ -0,0 +1,127 @@
+/*
+ * 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.security.auth;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
+
+/**
+ * A simple Principal wrapper. Exists to allow us to identify the "primary" principal
+ * by calling {@link Subject#getPrincipals(Class)}, passing in {@link AuthenticatedPrincipal}.class,
+ * e.g. when logging.
+ */
+public final class AuthenticatedPrincipal implements Principal, Serializable
+{
+ private final Principal _wrappedPrincipal;
+
+ /** convenience constructor for the common case where we're wrapping a {@link UsernamePrincipal} */
+ public AuthenticatedPrincipal(String userPrincipalName)
+ {
+ this(new UsernamePrincipal(userPrincipalName));
+ }
+
+ public AuthenticatedPrincipal(Principal wrappedPrincipal)
+ {
+ if(wrappedPrincipal == null)
+ {
+ throw new IllegalArgumentException("Wrapped principal is null");
+ }
+
+ _wrappedPrincipal = wrappedPrincipal;
+ }
+
+ @Override
+ public String getName()
+ {
+ return _wrappedPrincipal.getName();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _wrappedPrincipal.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (!(obj instanceof AuthenticatedPrincipal))
+ {
+ return false;
+ }
+
+ AuthenticatedPrincipal other = (AuthenticatedPrincipal) obj;
+
+ return _wrappedPrincipal.equals(other._wrappedPrincipal);
+ }
+
+ public static AuthenticatedPrincipal getOptionalAuthenticatedPrincipalFromSubject(final Subject authSubject)
+ {
+ return getAuthenticatedPrincipalFromSubject(authSubject, true);
+ }
+
+ public static AuthenticatedPrincipal getAuthenticatedPrincipalFromSubject(final Subject authSubject)
+ {
+ return getAuthenticatedPrincipalFromSubject(authSubject, false);
+ }
+
+ private static AuthenticatedPrincipal getAuthenticatedPrincipalFromSubject(final Subject authSubject, boolean isPrincipalOptional)
+ {
+ if (authSubject == null)
+ {
+ throw new IllegalArgumentException("No authenticated subject.");
+ }
+
+ final Set<AuthenticatedPrincipal> principals = authSubject.getPrincipals(AuthenticatedPrincipal.class);
+ int numberOfAuthenticatedPrincipals = principals.size();
+
+ if(numberOfAuthenticatedPrincipals == 0 && isPrincipalOptional)
+ {
+ return null;
+ }
+ else
+ {
+ if (numberOfAuthenticatedPrincipals != 1)
+ {
+ throw new IllegalArgumentException(
+ "Can't find single AuthenticatedPrincipal in authenticated subject. There were "
+ + numberOfAuthenticatedPrincipals
+ + " authenticated principals out of a total number of principals of: " + authSubject.getPrincipals());
+ }
+ return principals.iterator().next();
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return getName();
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticationResult.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticationResult.java
index 949c0f2b89..09bf6cf3b1 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticationResult.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/AuthenticationResult.java
@@ -7,9 +7,9 @@
* 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
@@ -20,15 +20,20 @@
*/
package org.apache.qpid.server.security.auth;
-import javax.security.auth.Subject;
+import java.security.Principal;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
/**
- * Encapsulates the result of an attempt to authenticate.
+ * Encapsulates the result of an attempt to authenticate using an {@link AuthenticationManager}.
* <p>
* The authentication status describes the overall outcome.
* <p>
* <ol>
- * <li>If authentication status is SUCCESS, the subject will be populated.
+ * <li>If authentication status is SUCCESS, at least one {@link Principal} will be populated.
* </li>
* <li>If authentication status is CONTINUE, the authentication has failed because the user
* supplied incorrect credentials (etc). If the authentication requires it, the next challenge
@@ -40,6 +45,8 @@ import javax.security.auth.Subject;
* </li>
* </ol>
*
+ * The main principal provided to the constructor is wrapped in an {@link AuthenticatedPrincipal}
+ * to make it easier for the rest of the application to identify it among the set of other principals.
*/
public class AuthenticationResult
{
@@ -56,37 +63,59 @@ public class AuthenticationResult
private final AuthenticationStatus _status;
private final byte[] _challenge;
private final Exception _cause;
- private final Subject _subject;
+ private final Set<Principal> _principals = new HashSet<Principal>();
+ private final Principal _mainPrincipal;
public AuthenticationResult(final AuthenticationStatus status)
{
this(null, status, null);
}
+ public AuthenticationResult(Principal mainPrincipal)
+ {
+ this(mainPrincipal, Collections.<Principal>emptySet());
+ }
+
+ public AuthenticationResult(Principal mainPrincipal, Set<Principal> otherPrincipals)
+ {
+ AuthenticatedPrincipal specialQpidAuthenticatedPrincipal = new AuthenticatedPrincipal(mainPrincipal);
+ _principals.addAll(otherPrincipals);
+ _principals.remove(mainPrincipal);
+ _principals.add(specialQpidAuthenticatedPrincipal);
+ _mainPrincipal = mainPrincipal;
+
+ _status = AuthenticationStatus.SUCCESS;
+ _challenge = null;
+ _cause = null;
+ }
+
public AuthenticationResult(final byte[] challenge, final AuthenticationStatus status)
{
- this(challenge, status, null);
+ _challenge = challenge;
+ _status = status;
+ _cause = null;
+ _mainPrincipal = null;
}
public AuthenticationResult(final AuthenticationStatus error, final Exception cause)
{
- this(null, error, cause);
+ _status = error;
+ _challenge = null;
+ _cause = cause;
+ _mainPrincipal = null;
}
public AuthenticationResult(final byte[] challenge, final AuthenticationStatus status, final Exception cause)
{
- this._status = status;
- this._challenge = challenge;
- this._cause = cause;
- this._subject = null;
- }
+ if(status == AuthenticationStatus.SUCCESS)
+ {
+ throw new IllegalArgumentException("Successful authentication requires at least one principal");
+ }
- public AuthenticationResult(final Subject subject)
- {
- this._status = AuthenticationStatus.SUCCESS;
- this._challenge = null;
- this._cause = null;
- this._subject = subject;
+ _status = status;
+ _challenge = challenge;
+ _cause = cause;
+ _mainPrincipal = null;
}
public Exception getCause()
@@ -104,9 +133,13 @@ public class AuthenticationResult
return _challenge;
}
- public Subject getSubject()
+ public Set<Principal> getPrincipals()
{
- return _subject;
+ return _principals;
}
+ public Principal getMainPrincipal()
+ {
+ return _mainPrincipal;
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/SubjectAuthenticationResult.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/SubjectAuthenticationResult.java
new file mode 100644
index 0000000000..3be96b87eb
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/SubjectAuthenticationResult.java
@@ -0,0 +1,76 @@
+/*
+ *
+ * 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.security.auth;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.security.SubjectCreator;
+
+/**
+ * Encapsulates the result of an attempt to authenticate using a {@link SubjectCreator}.
+ *
+ * <p>
+ * iff authentication was successful, {@link #getSubject()} will return a non-null value and
+ * {@link #getStatus()} will return {@link AuthenticationResult.AuthenticationStatus#SUCCESS}.
+ *
+ * In this case, the {@link Subject} will contain the user {@link Principal} and zero or more other principals
+ * representing groups.
+ * </p>
+ * @see SubjectCreator
+ */
+public class SubjectAuthenticationResult
+{
+ private final AuthenticationResult _authenticationResult;
+ private final Subject _subject;
+
+ public SubjectAuthenticationResult(AuthenticationResult authenticationResult, Subject subject)
+ {
+ _authenticationResult = authenticationResult;
+ _subject = subject;
+ }
+
+ public SubjectAuthenticationResult(AuthenticationResult unsuccessfulAuthenticationResult)
+ {
+ this(unsuccessfulAuthenticationResult, null);
+ }
+
+ public Exception getCause()
+ {
+ return _authenticationResult.getCause();
+ }
+
+ public AuthenticationResult.AuthenticationStatus getStatus()
+ {
+ return _authenticationResult.getStatus();
+ }
+
+ public byte[] getChallenge()
+ {
+ return _authenticationResult.getChallenge();
+ }
+
+ public Subject getSubject()
+ {
+ return _subject;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/UsernamePrincipal.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/UsernamePrincipal.java
new file mode 100644
index 0000000000..5b3c1d59cf
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/UsernamePrincipal.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.server.security.auth;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+/** A principal that is just a wrapper for a simple username. */
+public class UsernamePrincipal implements Principal, Serializable
+{
+ private final String _name;
+
+ public UsernamePrincipal(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+ _name = name;
+ }
+
+ public String getName()
+ {
+ return _name;
+ }
+
+ public String toString()
+ {
+ return _name;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ return prime * _name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ else
+ {
+ if (obj instanceof UsernamePrincipal)
+ {
+ UsernamePrincipal other = (UsernamePrincipal) obj;
+ return _name.equals(other._name);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java
index cac60a5283..578bb96efa 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/AbstractPasswordFilePrincipalDatabase.java
@@ -21,9 +21,9 @@
package org.apache.qpid.server.security.auth.database;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser;
import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.login.AccountNotFoundException;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java
index 67f4b7344a..605d2d019d 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PrincipalDatabase.java
@@ -32,6 +32,8 @@ import java.util.Map;
/** Represents a "user database" which is really a way of storing principals (i.e. usernames) and passwords. */
public interface PrincipalDatabase
{
+ void setPasswordFile(String passwordFile) throws IOException;
+
/**
* Set the password for a given principal in the specified callback. This is used for certain SASL providers. The
* user database implementation should look up the password in any way it chooses and set it in the callback by
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java
deleted file mode 100644
index 4203cb0e07..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java
+++ /dev/null
@@ -1,169 +0,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.
- *
- *
- */
-package org.apache.qpid.server.security.auth.database;
-
-import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
-import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5Initialiser;
-import org.apache.qpid.server.security.auth.sasl.plain.PlainInitialiser;
-
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.login.AccountNotFoundException;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.Principal;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-public class PropertiesPrincipalDatabase implements PrincipalDatabase
-{
- private Properties _users;
-
- private Map<String, AuthenticationProviderInitialiser> _saslServers;
-
- public PropertiesPrincipalDatabase(Properties users)
- {
- _users = users;
-
- _saslServers = new HashMap<String, AuthenticationProviderInitialiser>();
-
- /**
- * Create Authenticators for Properties Principal Database.
- */
-
- // Accept MD5 incomming and use plain comparison with the file
- PlainInitialiser cram = new PlainInitialiser();
- cram.initialise(this);
- // Accept Plain incomming and hash it for comparison to the file.
- CRAMMD5Initialiser plain = new CRAMMD5Initialiser();
- plain.initialise(this, CRAMMD5Initialiser.HashDirection.INCOMMING);
-
- _saslServers.put(plain.getMechanismName(), cram);
- _saslServers.put(cram.getMechanismName(), plain);
- }
-
- public void setPassword(Principal principal, PasswordCallback callback) throws IOException, AccountNotFoundException
- {
- if (principal == null)
- {
- throw new IllegalArgumentException("principal must not be null");
- }
-
-
-
- final String pwd = _users.getProperty(principal.getName());
-
- if (pwd != null)
- {
- callback.setPassword(pwd.toCharArray());
- }
- else
- {
- throw new AccountNotFoundException("No account found for principal " + principal);
- }
- }
-
- public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException
- {
- //fixme this is not correct as toCharArray is not safe based on the type of string.
- char[] pwd = _users.getProperty(principal).toCharArray();
-
- return compareCharArray(pwd, password);
- }
-
- public boolean updatePassword(Principal principal, char[] password) throws AccountNotFoundException
- {
- return false; // updates denied
- }
-
- public boolean createPrincipal(Principal principal, char[] password)
- {
- return false; // updates denied
- }
-
- public boolean deletePrincipal(Principal principal) throws AccountNotFoundException
- {
- return false; // updates denied
- }
-
- private boolean compareCharArray(char[] a, char[] b)
- {
- boolean equal = false;
- if (a.length == b.length)
- {
- equal = true;
- int index = 0;
- while (equal && index < a.length)
- {
- equal = a[index] == b[index];
- index++;
- }
- }
- return equal;
- }
-
- private char[] convertPassword(String password) throws UnsupportedEncodingException
- {
- byte[] passwdBytes = password.getBytes("utf-8");
-
- char[] passwd = new char[passwdBytes.length];
-
- int index = 0;
-
- for (byte b : passwdBytes)
- {
- passwd[index++] = (char) b;
- }
-
- return passwd;
- }
-
-
- public Map<String, AuthenticationProviderInitialiser> getMechanisms()
- {
- return _saslServers;
- }
-
- public List<Principal> getUsers()
- {
- return new LinkedList<Principal>(); //todo
- }
-
- public Principal getUser(String username)
- {
- if (_users.getProperty(username) != null)
- {
- return new UsernamePrincipal(username);
- }
- else
- {
- return null;
- }
- }
-
- public void reload() throws IOException
- {
- //No file to update from, so do nothing.
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java
new file mode 100644
index 0000000000..ff21d63c87
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractPrincipalDatabaseAuthManagerFactory.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.security.auth.manager;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+
+/**
+ * Factory for {@link PrincipalDatabaseAuthenticationManager} objects configured
+ * with either the Plain or Base64MD5 digest {@link PrincipalDatabase}
+ * implementation.
+ */
+public abstract class AbstractPrincipalDatabaseAuthManagerFactory implements AuthenticationManagerFactory
+{
+ public static final String ATTRIBUTE_PATH = "path";
+
+ private static final Logger LOGGER = Logger.getLogger(AbstractPrincipalDatabaseAuthManagerFactory.class);
+
+ @Override
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
+ {
+ if (attributes == null || !getType().equals(attributes.get(ATTRIBUTE_TYPE)))
+ {
+ return null;
+ }
+
+ String passwordFile = (String) attributes.get(ATTRIBUTE_PATH);
+ if (passwordFile == null)
+ {
+ LOGGER.warn("Password file path must not be null");
+ return null;
+ }
+
+ PrincipalDatabase principalDatabase = createPrincipalDatabase();
+ try
+ {
+ principalDatabase.setPasswordFile(passwordFile);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+
+ return new PrincipalDatabaseAuthenticationManager(principalDatabase);
+ }
+
+ abstract String getType();
+
+ abstract PrincipalDatabase createPrincipalDatabase();
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java
index 5676c43754..dd4c2e717a 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManager.java
@@ -21,31 +21,25 @@
package org.apache.qpid.server.security.auth.manager;
import java.security.Principal;
-import java.util.Arrays;
-import java.util.List;
+
import javax.security.auth.Subject;
-import javax.security.auth.callback.CallbackHandler;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
+
import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.security.auth.sasl.anonymous.AnonymousInitialiser;
import org.apache.qpid.server.security.auth.sasl.anonymous.AnonymousSaslServer;
public class AnonymousAuthenticationManager implements AuthenticationManager
{
- private static final Logger _logger = Logger.getLogger(AnonymousAuthenticationManager.class);
-
private static final AnonymousInitialiser SASL_INITIALISER = new AnonymousInitialiser();
private static final String ANONYMOUS = SASL_INITIALISER.getMechanismName();
- private static final Principal ANONYMOUS_PRINCIPAL = new UsernamePrincipal("ANONYMOUS");
+ public static final String ANONYMOUS_USERNAME = "ANONYMOUS";
+
+ public static final Principal ANONYMOUS_PRINCIPAL = new UsernamePrincipal(ANONYMOUS_USERNAME);
public static final Subject ANONYMOUS_SUBJECT = new Subject();
static
@@ -53,76 +47,11 @@ public class AnonymousAuthenticationManager implements AuthenticationManager
ANONYMOUS_SUBJECT.getPrincipals().add(ANONYMOUS_PRINCIPAL);
}
- private static final AuthenticationResult ANONYMOUS_AUTHENTICATION = new AuthenticationResult(ANONYMOUS_SUBJECT);
-
-
- private static CallbackHandler _callbackHandler = SASL_INITIALISER.getCallbackHandler();
+ private static final AuthenticationResult ANONYMOUS_AUTHENTICATION = new AuthenticationResult(ANONYMOUS_PRINCIPAL);
static final AnonymousAuthenticationManager INSTANCE = new AnonymousAuthenticationManager();
- public static class AnonymousAuthenticationManagerConfiguration extends ConfigurationPlugin
- {
-
- public static final ConfigurationPluginFactory FACTORY =
- new ConfigurationPluginFactory()
- {
- public List<String> getParentPaths()
- {
- return Arrays.asList("security.anonymous-auth-manager");
- }
-
- public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException
- {
- final ConfigurationPlugin instance = new AnonymousAuthenticationManagerConfiguration();
-
- instance.setConfiguration(path, config);
- return instance;
- }
- };
-
- public String[] getElementsProcessed()
- {
- return new String[0];
- }
-
- public void validateConfiguration() throws ConfigurationException
- {
- }
-
- }
-
-
- public static final AuthenticationManagerPluginFactory<AnonymousAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<AnonymousAuthenticationManager>()
- {
- public AnonymousAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException
- {
- AnonymousAuthenticationManagerConfiguration configuration =
- config == null
- ? null
- : (AnonymousAuthenticationManagerConfiguration) config.getConfiguration(AnonymousAuthenticationManagerConfiguration.class.getName());
-
- // If there is no configuration for this plugin then don't load it.
- if (configuration == null)
- {
- _logger.info("No authentication-manager configuration found for AnonymousAuthenticationManager");
- return null;
- }
- return INSTANCE;
- }
-
- public Class<AnonymousAuthenticationManager> getPluginClass()
- {
- return AnonymousAuthenticationManager.class;
- }
-
- public String getPluginName()
- {
- return AnonymousAuthenticationManager.class.getName();
- }
- };
-
-
- private AnonymousAuthenticationManager()
+ AnonymousAuthenticationManager()
{
}
@@ -184,9 +113,4 @@ public class AnonymousAuthenticationManager implements AuthenticationManager
public void close()
{
}
-
- @Override
- public void configure(ConfigurationPlugin config) throws ConfigurationException
- {
- }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java
new file mode 100644
index 0000000000..1b1995500c
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerFactory.java
@@ -0,0 +1,40 @@
+/*
+ * 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.security.auth.manager;
+
+import java.util.Map;
+
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+
+public class AnonymousAuthenticationManagerFactory implements AuthenticationManagerFactory
+{
+ public static final String PROVIDER_TYPE = AnonymousAuthenticationManager.class.getSimpleName();
+
+ @Override
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
+ {
+ if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE)))
+ {
+ return new AnonymousAuthenticationManager();
+ }
+ return null;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java
index ccddcb7669..c1a694f148 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManager.java
@@ -24,22 +24,22 @@ import java.security.Principal;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
import org.apache.qpid.common.Closeable;
-import org.apache.qpid.server.plugins.Plugin;
import org.apache.qpid.server.security.auth.AuthenticationResult;
/**
* Implementations of the AuthenticationManager are responsible for determining
* the authenticity of a user's credentials.
- *
- * If the authentication is successful, the manager is responsible for producing a populated
- * {@link javax.security.auth.Subject} containing the user's identity and zero or more principals representing
- * groups to which the user belongs.
+ * <p>
+ * If the authentication is successful, the manager is responsible for producing an
+ * {@link AuthenticationResult} containing the user's main {@link Principal} and zero or
+ * more other implementation-specific principals.
+ * </p>
* <p>
* The {@link #initialise()} method is responsible for registering SASL mechanisms required by
* the manager. The {@link #close()} method must reverse this registration.
- *
+ * </p>
*/
-public interface AuthenticationManager extends Closeable, Plugin
+public interface AuthenticationManager extends Closeable
{
/** The name for the required SASL Server mechanisms */
public static final String PROVIDER_NAME= "AMQSASLProvider-Server";
@@ -88,5 +88,4 @@ public interface AuthenticationManager extends Closeable, Plugin
* @return authentication result
*/
AuthenticationResult authenticate(String username, String password);
-
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java
deleted file mode 100644
index a51f195761..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerPluginFactory.java
+++ /dev/null
@@ -1,32 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.manager;
-
-import org.apache.qpid.server.plugins.PluginFactory;
-
-/**
- * Factory producing authentication producing configured, initialised authentication
- * managers.
- */
-public interface AuthenticationManagerPluginFactory<S extends AuthenticationManager> extends PluginFactory<S>
-{
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java
deleted file mode 100644
index 89a4d8ae66..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistry.java
+++ /dev/null
@@ -1,203 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.manager;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.common.Closeable;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.plugins.Plugin;
-import org.apache.qpid.server.plugins.PluginManager;
-import org.apache.qpid.server.security.SecurityManager.SecurityConfiguration;
-
-/**
- * A concrete implementation of {@link IAuthenticationManagerRegistry} that registers all {@link AuthenticationManager}
- * instances defined in the configuration, building an optional mapping between port number and AuthenticationManager.
- *
- * <p>The default AuthenticationManager is either the one nominated as default within the configuration with
- * {@link ServerConfiguration#getDefaultAuthenticationManager()}, or if there is only one, it is implicitly
- * the default.</p>
- *
- * <p>It is important to {@link #close()} the registry after use and this allows the AuthenticationManagers
- * to reverse any security registrations they have performed.</p>
- */
-public class AuthenticationManagerRegistry implements Closeable, IAuthenticationManagerRegistry
-{
- private final Map<String,AuthenticationManager> _classToAuthManagerMap = new HashMap<String,AuthenticationManager>();
- private final AuthenticationManager _defaultAuthenticationManager;
- private final Map<Integer,AuthenticationManager> _portToAuthenticationManagerMap;
- private final List<RegistryChangeListener> _listeners =
- Collections.synchronizedList(new ArrayList<RegistryChangeListener>());
-
- public AuthenticationManagerRegistry(ServerConfiguration serverConfiguration, PluginManager _pluginManager)
- throws ConfigurationException
- {
- final Collection<AuthenticationManagerPluginFactory<? extends Plugin>> factories = _pluginManager.getAuthenticationManagerPlugins().values();
-
- if (factories.size() == 0)
- {
- throw new ConfigurationException("No authentication manager factory plugins found. Check the desired authentication" +
- " manager plugin has been placed in the plugins directory.");
- }
-
- final SecurityConfiguration securityConfiguration = serverConfiguration.getConfiguration(SecurityConfiguration.class.getName());
-
- boolean willClose = true;
- try
- {
- createAuthenticationManagersRejectingDuplicates(factories, securityConfiguration);
-
- if(_classToAuthManagerMap.isEmpty())
- {
- throw new ConfigurationException("No authentication managers configured within the configuration file.");
- }
-
- _defaultAuthenticationManager = getDefaultAuthenticationManager(serverConfiguration);
-
- _portToAuthenticationManagerMap = getPortToAuthenticationManagerMap(serverConfiguration);
- willClose = false;
- }
- finally
- {
- // if anything went wrong whilst configuring the registry, try to close all the AuthentcationManagers instantiated so far.
- // This is done to allow the AuthenticationManager to undo any security registrations that they have performed.
- if (willClose)
- {
- close();
- }
- }
- }
-
- @Override
- public AuthenticationManager getAuthenticationManager(SocketAddress address)
- {
- AuthenticationManager authManager =
- address instanceof InetSocketAddress
- ? _portToAuthenticationManagerMap.get(((InetSocketAddress)address).getPort())
- : null;
-
- return authManager == null ? _defaultAuthenticationManager : authManager;
- }
-
- @Override
- public void close()
- {
- for (AuthenticationManager authManager : _classToAuthManagerMap.values())
- {
- authManager.close();
- }
- }
-
- private void createAuthenticationManagersRejectingDuplicates(
- final Collection<AuthenticationManagerPluginFactory<? extends Plugin>> factories,
- final SecurityConfiguration securityConfiguration)
- throws ConfigurationException
- {
- for(AuthenticationManagerPluginFactory<? extends Plugin> factory : factories)
- {
- final AuthenticationManager tmp = factory.newInstance(securityConfiguration);
- if (tmp != null)
- {
- if(_classToAuthManagerMap.containsKey(tmp.getClass().getSimpleName()))
- {
- throw new ConfigurationException("Cannot configure more than one authentication manager of type "
- + tmp.getClass().getSimpleName() + "."
- + " Remove configuration for one of the authentication managers.");
- }
- _classToAuthManagerMap.put(tmp.getClass().getSimpleName(),tmp);
-
- for(RegistryChangeListener listener : _listeners)
- {
- listener.authenticationManagerRegistered(tmp);
- }
- }
- }
- }
-
- private AuthenticationManager getDefaultAuthenticationManager(
- ServerConfiguration serverConfiguration)
- throws ConfigurationException
- {
- final AuthenticationManager defaultAuthenticationManager;
- if(_classToAuthManagerMap.size() == 1)
- {
- defaultAuthenticationManager = _classToAuthManagerMap.values().iterator().next();
- }
- else if(serverConfiguration.getDefaultAuthenticationManager() != null)
- {
- defaultAuthenticationManager = _classToAuthManagerMap.get(serverConfiguration.getDefaultAuthenticationManager());
- if(defaultAuthenticationManager == null)
- {
- throw new ConfigurationException("No authentication managers configured of type "
- + serverConfiguration.getDefaultAuthenticationManager()
- + " which is specified as the default. Available managers are: "
- + _classToAuthManagerMap.keySet());
- }
- }
- else
- {
- throw new ConfigurationException("If more than one authentication manager is configured a default MUST be specified.");
- }
- return defaultAuthenticationManager;
- }
-
- private Map<Integer,AuthenticationManager> getPortToAuthenticationManagerMap(
- ServerConfiguration serverConfiguration)
- throws ConfigurationException
- {
- Map<Integer,AuthenticationManager> portToAuthenticationManagerMap = new HashMap<Integer, AuthenticationManager>();
-
- for(Map.Entry<Integer,String> portMapping : serverConfiguration.getPortAuthenticationMappings().entrySet())
- {
-
- AuthenticationManager authenticationManager = _classToAuthManagerMap.get(portMapping.getValue());
- if(authenticationManager == null)
- {
- throw new ConfigurationException("Unknown authentication manager class " + portMapping.getValue() +
- " configured for port " + portMapping.getKey());
- }
- portToAuthenticationManagerMap.put(portMapping.getKey(), authenticationManager);
- }
-
- return portToAuthenticationManagerMap;
- }
-
- @Override
- public Map<String, AuthenticationManager> getAvailableAuthenticationManagers()
- {
- return Collections.unmodifiableMap(new HashMap<String, AuthenticationManager>(_classToAuthManagerMap));
- }
-
- @Override
- public void addRegistryChangeListener(RegistryChangeListener listener)
- {
- _listeners.add(listener);
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.java
new file mode 100644
index 0000000000..c61567ef77
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactory.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.server.security.auth.manager;
+
+import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+
+public class Base64MD5PasswordFileAuthenticationManagerFactory extends AbstractPrincipalDatabaseAuthManagerFactory
+{
+ public static final String PROVIDER_TYPE = "Base64MD5PasswordFileAuthenticationProvider";
+
+ @Override
+ String getType()
+ {
+ return PROVIDER_TYPE;
+ }
+
+ @Override
+ PrincipalDatabase createPrincipalDatabase()
+ {
+ return new Base64MD5PasswordFilePrincipalDatabase();
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java
index 2d6866b657..9ed8cf7fed 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManager.java
@@ -19,90 +19,19 @@
package org.apache.qpid.server.security.auth.manager;
import java.security.Principal;
-import java.util.Arrays;
-import java.util.List;
-import javax.security.auth.Subject;
+
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
+
import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.security.auth.sasl.external.ExternalSaslServer;
public class ExternalAuthenticationManager implements AuthenticationManager
{
- private static final Logger _logger = Logger.getLogger(ExternalAuthenticationManager.class);
-
private static final String EXTERNAL = "EXTERNAL";
- static final ExternalAuthenticationManager INSTANCE = new ExternalAuthenticationManager();
-
- public static class ExternalAuthenticationManagerConfiguration extends ConfigurationPlugin
- {
-
- public static final ConfigurationPluginFactory FACTORY =
- new ConfigurationPluginFactory()
- {
- public List<String> getParentPaths()
- {
- return Arrays.asList("security.external-auth-manager");
- }
-
- public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException
- {
- final ConfigurationPlugin instance = new ExternalAuthenticationManagerConfiguration();
-
- instance.setConfiguration(path, config);
- return instance;
- }
- };
-
- public String[] getElementsProcessed()
- {
- return new String[0];
- }
-
- public void validateConfiguration() throws ConfigurationException
- {
- }
-
- }
-
-
- public static final AuthenticationManagerPluginFactory<ExternalAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<ExternalAuthenticationManager>()
- {
- public ExternalAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException
- {
- ExternalAuthenticationManagerConfiguration configuration =
- config == null
- ? null
- : (ExternalAuthenticationManagerConfiguration) config.getConfiguration(ExternalAuthenticationManagerConfiguration.class.getName());
-
- // If there is no configuration for this plugin then don't load it.
- if (configuration == null)
- {
- _logger.info("No authentication-manager configuration found for ExternalAuthenticationManager");
- return null;
- }
- return INSTANCE;
- }
-
- public Class<ExternalAuthenticationManager> getPluginClass()
- {
- return ExternalAuthenticationManager.class;
- }
-
- public String getPluginName()
- {
- return ExternalAuthenticationManager.class.getName();
- }
- };
-
-
- private ExternalAuthenticationManager()
+ ExternalAuthenticationManager()
{
}
@@ -137,15 +66,13 @@ public class ExternalAuthenticationManager implements AuthenticationManager
// Process response from the client
try
{
- byte[] challenge = server.evaluateResponse(response != null ? response : new byte[0]);
+ server.evaluateResponse(response != null ? response : new byte[0]);
Principal principal = ((ExternalSaslServer)server).getAuthenticatedPrincipal();
if(principal != null)
{
- final Subject subject = new Subject();
- subject.getPrincipals().add(principal);
- return new AuthenticationResult(subject);
+ return new AuthenticationResult(principal);
}
else
{
@@ -162,16 +89,11 @@ public class ExternalAuthenticationManager implements AuthenticationManager
@Override
public AuthenticationResult authenticate(String username, String password)
{
- return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR);
+ return new AuthenticationResult(new UsernamePrincipal(username));
}
@Override
public void close()
{
}
-
- @Override
- public void configure(ConfigurationPlugin config) throws ConfigurationException
- {
- }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java
new file mode 100644
index 0000000000..3c3628e9db
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerFactory.java
@@ -0,0 +1,40 @@
+/*
+ * 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.security.auth.manager;
+
+import java.util.Map;
+
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+
+public class ExternalAuthenticationManagerFactory implements AuthenticationManagerFactory
+{
+ public static final String PROVIDER_TYPE = ExternalAuthenticationManager.class.getSimpleName();
+
+ @Override
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
+ {
+ if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE)))
+ {
+ return new ExternalAuthenticationManager();
+ }
+ return null;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/IAuthenticationManagerRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/IAuthenticationManagerRegistry.java
deleted file mode 100644
index 485ca2e1e9..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/IAuthenticationManagerRegistry.java
+++ /dev/null
@@ -1,59 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.manager;
-
-import java.net.SocketAddress;
-
-import java.util.Map;
-import org.apache.qpid.common.Closeable;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-
-/**
- * Registry for {@link AuthenticationManager} instances.
- *
- * <p>A lookup method {@link #getAuthenticationManager(SocketAddress)} allows a caller to determine
- * the AuthenticationManager associated with a particular port number.</p>
- *
- * <p>It is important to {@link #close()} the registry after use and this allows the AuthenticationManagers
- * to reverse any security registrations they have performed.</p>
- */
-public interface IAuthenticationManagerRegistry extends Closeable
-{
- /**
- * Returns the {@link AuthenticationManager} associated with a particular {@link SocketAddress}.
- * If no authentication manager is associated with this address, a default authentication manager will be
- * returned. Null is never returned.
- *
- * @param address
- * @return authentication manager.
- */
- public AuthenticationManager getAuthenticationManager(SocketAddress address);
-
- Map<String, AuthenticationManager> getAvailableAuthenticationManagers();
-
- public static interface RegistryChangeListener
- {
- void authenticationManagerRegistered(AuthenticationManager authenticationManager);
- void authenticationManagerUnregistered(AuthenticationManager authenticationManager);
- }
-
- public void addRegistryChangeListener(RegistryChangeListener listener);
-
-} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java
index d735ecb1d4..3c1b709648 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManager.java
@@ -20,10 +20,7 @@ package org.apache.qpid.server.security.auth.manager;
import java.io.IOException;
import java.security.Principal;
-import java.util.Arrays;
import java.util.HashMap;
-import java.util.List;
-import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
@@ -31,86 +28,15 @@ import javax.security.sasl.AuthorizeCallback;
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
public class KerberosAuthenticationManager implements AuthenticationManager
{
- private static final Logger _logger = Logger.getLogger(KerberosAuthenticationManager.class);
-
private static final String GSSAPI_MECHANISM = "GSSAPI";
private final CallbackHandler _callbackHandler = new GssApiCallbackHandler();
- public static class KerberosAuthenticationManagerConfiguration extends ConfigurationPlugin
- {
-
- public static final ConfigurationPluginFactory FACTORY =
- new ConfigurationPluginFactory()
- {
- public List<String> getParentPaths()
- {
- return Arrays.asList("security.kerberos-auth-manager");
- }
-
- public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException
- {
- final ConfigurationPlugin instance = new KerberosAuthenticationManagerConfiguration();
-
- instance.setConfiguration(path, config);
- return instance;
- }
- };
-
- public String[] getElementsProcessed()
- {
- return new String[0];
- }
-
- public void validateConfiguration() throws ConfigurationException
- {
- }
-
- }
-
-
- public static final AuthenticationManagerPluginFactory<KerberosAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<KerberosAuthenticationManager>()
- {
- public KerberosAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException
- {
- KerberosAuthenticationManagerConfiguration configuration =
- config == null
- ? null
- : (KerberosAuthenticationManagerConfiguration) config.getConfiguration(KerberosAuthenticationManagerConfiguration.class.getName());
-
- // If there is no configuration for this plugin then don't load it.
- if (configuration == null)
- {
- _logger.info("No authentication-manager configuration found for KerberosAuthenticationManager");
- return null;
- }
- KerberosAuthenticationManager kerberosAuthenticationManager = new KerberosAuthenticationManager();
- kerberosAuthenticationManager.configure(configuration);
- return kerberosAuthenticationManager;
- }
-
- public Class<KerberosAuthenticationManager> getPluginClass()
- {
- return KerberosAuthenticationManager.class;
- }
-
- public String getPluginName()
- {
- return KerberosAuthenticationManager.class.getName();
- }
- };
-
-
- private KerberosAuthenticationManager()
+ KerberosAuthenticationManager()
{
}
@@ -158,10 +84,7 @@ public class KerberosAuthenticationManager implements AuthenticationManager
if (server.isComplete())
{
- final Subject subject = new Subject();
- _logger.debug("Authenticated as " + server.getAuthorizationID());
- subject.getPrincipals().add(new UsernamePrincipal(server.getAuthorizationID()));
- return new AuthenticationResult(subject);
+ return new AuthenticationResult(new UsernamePrincipal(server.getAuthorizationID()));
}
else
{
@@ -186,11 +109,6 @@ public class KerberosAuthenticationManager implements AuthenticationManager
{
}
- @Override
- public void configure(ConfigurationPlugin config) throws ConfigurationException
- {
- }
-
private static class GssApiCallbackHandler implements CallbackHandler
{
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.java
new file mode 100644
index 0000000000..7af6727280
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/KerberosAuthenticationManagerFactory.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.server.security.auth.manager;
+
+import java.util.Map;
+
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+
+public class KerberosAuthenticationManagerFactory implements AuthenticationManagerFactory
+{
+ public static final String PROVIDER_TYPE = KerberosAuthenticationManager.class.getSimpleName();
+
+ @Override
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
+ {
+ if (attributes != null && PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE)))
+ {
+ return new KerberosAuthenticationManager();
+ }
+ return null;
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.java
new file mode 100644
index 0000000000..43b92735f1
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactory.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.server.security.auth.manager;
+
+import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+
+public class PlainPasswordFileAuthenticationManagerFactory extends AbstractPrincipalDatabaseAuthManagerFactory
+{
+ public static final String PROVIDER_TYPE = "PlainPasswordFileAuthenticationProvider";
+
+ @Override
+ String getType()
+ {
+ return PROVIDER_TYPE;
+ }
+
+ @Override
+ PrincipalDatabase createPrincipalDatabase()
+ {
+ return new PlainPasswordFilePrincipalDatabase();
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
index e6498919a1..f4c834810d 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
@@ -21,38 +21,25 @@
package org.apache.qpid.server.security.auth.manager;
import java.security.Principal;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
-import org.apache.qpid.configuration.PropertyException;
-import org.apache.qpid.configuration.PropertyUtils;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
import org.apache.qpid.server.security.auth.AuthenticationResult;
import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser;
import org.apache.qpid.server.security.auth.sasl.JCAProvider;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
-import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.AccountNotFoundException;
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
import javax.security.sasl.SaslServerFactory;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+
import java.security.Security;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.TreeMap;
@@ -60,27 +47,10 @@ import java.util.TreeMap;
* Concrete implementation of the AuthenticationManager that determines if supplied
* user credentials match those appearing in a PrincipalDatabase. The implementation
* of the PrincipalDatabase is determined from the configuration.
- *
- * This implementation also registers the JMX UserManagemement MBean.
- *
- * This plugin expects configuration such as:
- *
- * <pre>
- * &lt;pd-auth-manager&gt;
- * &lt;principal-database&gt;
- * &lt;class&gt;org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase&lt;/class&gt;
- * &lt;attributes&gt;
- * &lt;attribute&gt;
- * &lt;name>passwordFile&lt;/name&gt;
- * &lt;value>${conf}/passwd&lt;/value&gt;
- * &lt;/attribute&gt;
- * &lt;/attributes&gt;
- * &lt;/principal-database&gt;
- * &lt;/pd-auth-manager&gt;
- * </pre>
*/
public class PrincipalDatabaseAuthenticationManager implements AuthenticationManager
{
+
private static final Logger _logger = Logger.getLogger(PrincipalDatabaseAuthenticationManager.class);
/** The list of mechanisms, in the order in which they are configured (i.e. preferred order) */
@@ -95,95 +65,11 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan
*/
private final Map<String, Map<String, ?>> _serverCreationProperties = new HashMap<String, Map<String, ?>>();
- private PrincipalDatabase _principalDatabase = null;
+ private final PrincipalDatabase _principalDatabase;
- public static final AuthenticationManagerPluginFactory<PrincipalDatabaseAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<PrincipalDatabaseAuthenticationManager>()
- {
- public PrincipalDatabaseAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException
- {
- final PrincipalDatabaseAuthenticationManagerConfiguration configuration =
- config == null
- ? null
- : (PrincipalDatabaseAuthenticationManagerConfiguration) config.getConfiguration(PrincipalDatabaseAuthenticationManagerConfiguration.class.getName());
-
- // If there is no configuration for this plugin then don't load it.
- if (configuration == null)
- {
- _logger.info("No authentication-manager configuration found for PrincipalDatabaseAuthenticationManager");
- return null;
- }
-
- final PrincipalDatabaseAuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager();
- pdam.configure(configuration);
- pdam.initialise();
- return pdam;
- }
-
- public Class<PrincipalDatabaseAuthenticationManager> getPluginClass()
- {
- return PrincipalDatabaseAuthenticationManager.class;
- }
-
- public String getPluginName()
- {
- return PrincipalDatabaseAuthenticationManager.class.getName();
- }
- };
-
- public static class PrincipalDatabaseAuthenticationManagerConfiguration extends ConfigurationPlugin {
-
- public static final ConfigurationPluginFactory FACTORY = new ConfigurationPluginFactory()
- {
- public List<String> getParentPaths()
- {
- return Arrays.asList("security.pd-auth-manager");
- }
-
- public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException
- {
- final ConfigurationPlugin instance = new PrincipalDatabaseAuthenticationManagerConfiguration();
-
- instance.setConfiguration(path, config);
- return instance;
- }
- };
-
- public String[] getElementsProcessed()
- {
- return new String[] {"principal-database.class",
- "principal-database.attributes.attribute.name",
- "principal-database.attributes.attribute.value"};
- }
-
- public void validateConfiguration() throws ConfigurationException
- {
- }
-
- public String getPrincipalDatabaseClass()
- {
- return getConfig().getString("principal-database.class");
- }
-
- public Map<String,String> getPdClassAttributeMap() throws ConfigurationException
- {
- final List<String> argumentNames = (List) getConfig().getList("principal-database.attributes.attribute.name");
- final List<String> argumentValues = (List) getConfig().getList("principal-database.attributes.attribute.value");
- final Map<String,String> attributes = new HashMap<String,String>(argumentNames.size());
-
- for (int i = 0; i < argumentNames.size(); i++)
- {
- final String argName = argumentNames.get(i);
- final String argValue = argumentValues.get(i);
-
- attributes.put(argName, argValue);
- }
-
- return Collections.unmodifiableMap(attributes);
- }
- }
-
- protected PrincipalDatabaseAuthenticationManager()
+ public PrincipalDatabaseAuthenticationManager(PrincipalDatabase pd)
{
+ _principalDatabase = pd;
}
public void initialise()
@@ -246,21 +132,6 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan
_logger.info("Initialised " + mechanism + " SASL provider successfully");
}
- /**
- * @see org.apache.qpid.server.plugins.Plugin#configure(org.apache.qpid.server.configuration.plugins.ConfigurationPlugin)
- */
- public void configure(final ConfigurationPlugin config) throws ConfigurationException
- {
- final PrincipalDatabaseAuthenticationManagerConfiguration pdamConfig = (PrincipalDatabaseAuthenticationManagerConfiguration) config;
- final String pdClazz = pdamConfig.getPrincipalDatabaseClass();
-
- _logger.info("PrincipalDatabase concrete implementation : " + pdClazz);
-
- _principalDatabase = createPrincipalDatabaseImpl(pdClazz);
-
- configPrincipalDatabase(_principalDatabase, pdamConfig);
- }
-
public String getMechanisms()
{
return _mechanisms;
@@ -268,8 +139,11 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan
public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException
{
- return Sasl.createSaslServer(mechanism, "AMQP", localFQDN, _serverCreationProperties.get(mechanism),
- _callbackHandlerMap.get(mechanism));
+ Map<String, ?> properties = _serverCreationProperties.get(mechanism);
+ CallbackHandler callbackHandler = _callbackHandlerMap.get(mechanism);
+
+ return Sasl.createSaslServer(mechanism, "AMQP", localFQDN, properties,
+ callbackHandler);
}
/**
@@ -284,9 +158,8 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan
if (server.isComplete())
{
- final Subject subject = new Subject();
- subject.getPrincipals().add(new UsernamePrincipal(server.getAuthorizationID()));
- return new AuthenticationResult(subject);
+ final String userId = server.getAuthorizationID();
+ return new AuthenticationResult(new UsernamePrincipal(userId));
}
else
{
@@ -308,9 +181,7 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan
{
if (_principalDatabase.verifyPassword(username, password.toCharArray()))
{
- final Subject subject = new Subject();
- subject.getPrincipals().add(new UsernamePrincipal(username));
- return new AuthenticationResult(subject);
+ return new AuthenticationResult(new UsernamePrincipal(username));
}
else
{
@@ -329,100 +200,8 @@ public class PrincipalDatabaseAuthenticationManager implements AuthenticationMan
Security.removeProvider(PROVIDER_NAME);
}
- private PrincipalDatabase createPrincipalDatabaseImpl(final String pdClazz) throws ConfigurationException
- {
- try
- {
- return (PrincipalDatabase) Class.forName(pdClazz).newInstance();
- }
- catch (InstantiationException ie)
- {
- throw new ConfigurationException("Cannot instantiate " + pdClazz, ie);
- }
- catch (IllegalAccessException iae)
- {
- throw new ConfigurationException("Cannot access " + pdClazz, iae);
- }
- catch (ClassNotFoundException cnfe)
- {
- throw new ConfigurationException("Cannot load " + pdClazz + " implementation", cnfe);
- }
- catch (ClassCastException cce)
- {
- throw new ConfigurationException("Expecting a " + PrincipalDatabase.class + " implementation", cce);
- }
- }
-
- private void configPrincipalDatabase(final PrincipalDatabase principalDatabase, final PrincipalDatabaseAuthenticationManagerConfiguration config)
- throws ConfigurationException
- {
-
- final Map<String,String> attributes = config.getPdClassAttributeMap();
-
- for (Iterator<Entry<String, String>> iterator = attributes.entrySet().iterator(); iterator.hasNext();)
- {
- final Entry<String, String> nameValuePair = iterator.next();
- final String methodName = generateSetterName(nameValuePair.getKey());
- final Method method;
- try
- {
- method = principalDatabase.getClass().getMethod(methodName, String.class);
- }
- catch (Exception e)
- {
- throw new ConfigurationException("No method " + methodName + " found in class "
- + principalDatabase.getClass()
- + " hence unable to configure principal database. The method must be public and "
- + "have a single String argument with a void return type", e);
- }
- try
- {
- method.invoke(principalDatabase, PropertyUtils.replaceProperties(nameValuePair.getValue()));
- }
- catch (IllegalArgumentException e)
- {
- throw new ConfigurationException(e.getMessage(), e);
- }
- catch (PropertyException e)
- {
- throw new ConfigurationException(e.getMessage(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new ConfigurationException(e.getMessage(), e);
- }
- catch (InvocationTargetException e)
- {
- // QPID-1347.. InvocationTargetException wraps the checked exception thrown from the reflective
- // method call. Pull out the underlying message and cause to make these more apparent to the user.
- throw new ConfigurationException(e.getCause().getMessage(), e.getCause());
- }
- }
- }
-
public PrincipalDatabase getPrincipalDatabase()
{
return _principalDatabase;
}
-
- private String generateSetterName(String argName) throws ConfigurationException
- {
- if ((argName == null) || (argName.length() == 0))
- {
- throw new ConfigurationException("Argument names must have length >= 1 character");
- }
-
- if (Character.isLowerCase(argName.charAt(0)))
- {
- argName = Character.toUpperCase(argName.charAt(0)) + argName.substring(1);
- }
-
- final String methodName = "set" + argName;
- return methodName;
- }
-
- protected void setPrincipalDatabase(final PrincipalDatabase principalDatabase)
- {
- _principalDatabase = principalDatabase;
- }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java
index 64b24e28bc..7891ef8cf5 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManager.java
@@ -21,10 +21,10 @@ package org.apache.qpid.server.security.auth.manager;
import java.io.IOException;
import java.security.Principal;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
-import java.util.List;
+
+import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -32,7 +32,6 @@ import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
-import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
@@ -41,13 +40,10 @@ import javax.security.sasl.AuthorizeCallback;
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.security.auth.sasl.plain.PlainPasswordCallback;
public class SimpleLDAPAuthenticationManager implements AuthenticationManager
@@ -55,123 +51,25 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
private static final Logger _logger = Logger.getLogger(SimpleLDAPAuthenticationManager.class);
private static final String PLAIN_MECHANISM = "PLAIN";
- private static final String DEFAULT_LDAP_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
- private String _providerSearchURL;
- private String _searchContext;
- private String _searchFilter;
- private String _providerAuthURL;
- private String _ldapContextFactory;
-
- public static class SimpleLDAPAuthenticationManagerConfiguration extends ConfigurationPlugin
- {
-
- public static final ConfigurationPluginFactory FACTORY =
- new ConfigurationPluginFactory()
- {
- public List<String> getParentPaths()
- {
- return Arrays.asList("security.simple-ldap-auth-manager");
- }
-
- public ConfigurationPlugin newInstance(final String path, final Configuration config) throws ConfigurationException
- {
- final ConfigurationPlugin instance = new SimpleLDAPAuthenticationManagerConfiguration();
-
- instance.setConfiguration(path, config);
- return instance;
- }
- };
-
- private static final String PROVIDER_URL = "provider-url";
- private static final String PROVIDER_SEARCH_URL = "provider-search-url";
- private static final String PROVIDER_AUTH_URL = "provider-auth-url";
- private static final String SEARCH_CONTEXT = "search-context";
- private static final String SEARCH_FILTER = "search-filter";
- private static final String LDAP_CONTEXT_FACTORY = "ldap-context-factory";
-
- public String[] getElementsProcessed()
- {
- return new String[] {PROVIDER_URL, PROVIDER_SEARCH_URL, PROVIDER_AUTH_URL, SEARCH_CONTEXT, SEARCH_FILTER,
- LDAP_CONTEXT_FACTORY};
- }
-
- public void validateConfiguration() throws ConfigurationException
- {
- }
-
- public String getLDAPContextFactory()
- {
- return getConfig().getString(LDAP_CONTEXT_FACTORY, DEFAULT_LDAP_CONTEXT_FACTORY);
- }
-
-
- public String getProviderURL()
- {
- return getConfig().getString(PROVIDER_URL);
- }
-
- public String getProviderSearchURL()
- {
- return getConfig().getString(PROVIDER_SEARCH_URL, getProviderURL());
- }
-
- public String getSearchContext()
- {
- return getConfig().getString(SEARCH_CONTEXT);
- }
-
- public String getSearchFilter()
- {
- return getConfig().getString(SEARCH_FILTER);
- }
-
- public String getProviderAuthURL()
- {
- return getConfig().getString(PROVIDER_AUTH_URL, getProviderURL());
- }
- }
-
-
- public static final AuthenticationManagerPluginFactory<SimpleLDAPAuthenticationManager> FACTORY = new AuthenticationManagerPluginFactory<SimpleLDAPAuthenticationManager>()
- {
- public SimpleLDAPAuthenticationManager newInstance(final ConfigurationPlugin config) throws ConfigurationException
- {
- SimpleLDAPAuthenticationManagerConfiguration configuration =
- config == null
- ? null
- : (SimpleLDAPAuthenticationManagerConfiguration) config.getConfiguration(SimpleLDAPAuthenticationManagerConfiguration.class.getName());
-
- // If there is no configuration for this plugin then don't load it.
- if (configuration == null)
- {
- _logger.info("No authentication-manager configuration found for SimpleLDAPAuthenticationManager");
- return null;
- }
- SimpleLDAPAuthenticationManager simpleLDAPAuthenticationManager = new SimpleLDAPAuthenticationManager();
- simpleLDAPAuthenticationManager.configure(configuration);
- return simpleLDAPAuthenticationManager;
- }
-
- public Class<SimpleLDAPAuthenticationManager> getPluginClass()
- {
- return SimpleLDAPAuthenticationManager.class;
- }
-
- public String getPluginName()
- {
- return SimpleLDAPAuthenticationManager.class.getName();
- }
- };
-
+ private final String _providerSearchURL;
+ private final String _providerAuthURL;
+ private final String _searchContext;
+ private final String _searchFilter;
+ private final String _ldapContextFactory;
- private SimpleLDAPAuthenticationManager()
+ SimpleLDAPAuthenticationManager(String providerSearchUrl, String providerAuthUrl, String searchContext, String searchFilter, String ldapContextFactory)
{
+ _providerSearchURL = providerSearchUrl;
+ _providerAuthURL = providerAuthUrl;
+ _searchContext = searchContext;
+ _searchFilter = searchFilter;
+ _ldapContextFactory = ldapContextFactory;
}
@Override
public void initialise()
{
-
+ validateInitialDirContext();
}
@Override
@@ -205,10 +103,10 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
if (server.isComplete())
{
- final Subject subject = new Subject();
- _logger.debug("Authenticated as " + server.getAuthorizationID());
- subject.getPrincipals().add(new UsernamePrincipal(server.getAuthorizationID()));
- return new AuthenticationResult(subject);
+ String authorizationID = server.getAuthorizationID();
+ _logger.debug("Authenticated as " + authorizationID);
+
+ return new AuthenticationResult(new UsernamePrincipal(authorizationID));
}
else
{
@@ -224,34 +122,74 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
@Override
public AuthenticationResult authenticate(String username, String password)
{
-
try
{
- return doLDAPNameAuthentication(getNameFromId(username), password);
+ AuthenticationResult result = doLDAPNameAuthentication(getNameFromId(username), password);
+ if(result.getStatus() == AuthenticationStatus.SUCCESS)
+ {
+ //Return a result based on the supplied username rather than the search name
+ return new AuthenticationResult(new UsernamePrincipal(username));
+ }
+ else
+ {
+ return result;
+ }
}
catch (NamingException e)
{
-
return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
-
}
}
- private AuthenticationResult doLDAPNameAuthentication(String username, String password) throws NamingException
+ private AuthenticationResult doLDAPNameAuthentication(String name, String password)
{
+ if(name == null)
+ {
+ //The search didn't return anything, class as not-authenticated before it NPEs below
+ return new AuthenticationResult(AuthenticationStatus.CONTINUE);
+ }
+
Hashtable<Object,Object> env = new Hashtable<Object,Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, _ldapContextFactory);
env.put(Context.PROVIDER_URL, _providerAuthURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, username);
+ env.put(Context.SECURITY_PRINCIPAL, name);
env.put(Context.SECURITY_CREDENTIALS, password);
- DirContext ctx = new InitialDirContext(env);
- ctx.close();
- final Subject subject = new Subject();
- subject.getPrincipals().add(new UsernamePrincipal(username));
- return new AuthenticationResult(subject);
+
+ DirContext ctx = null;
+ try
+ {
+ ctx = new InitialDirContext(env);
+
+ //Authentication succeeded
+ return new AuthenticationResult(new UsernamePrincipal(name));
+ }
+ catch(AuthenticationException ae)
+ {
+ //Authentication failed
+ return new AuthenticationResult(AuthenticationStatus.CONTINUE);
+ }
+ catch (NamingException e)
+ {
+ //Some other failure
+ return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
+ }
+ finally
+ {
+ if(ctx != null)
+ {
+ try
+ {
+ ctx.close();
+ }
+ catch (Exception e)
+ {
+ _logger.warn("Exception closing InitialDirContext", e);
+ }
+ }
+ }
}
@Override
@@ -259,17 +197,8 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
{
}
- @Override
- public void configure(ConfigurationPlugin config) throws ConfigurationException
+ private void validateInitialDirContext()
{
- SimpleLDAPAuthenticationManagerConfiguration ldapConfig = (SimpleLDAPAuthenticationManagerConfiguration) config;
-
- _ldapContextFactory = ldapConfig.getLDAPContextFactory();
- _providerSearchURL = ldapConfig.getProviderSearchURL();
- _providerAuthURL = ldapConfig.getProviderAuthURL();
- _searchContext = ldapConfig.getSearchContext();
- _searchFilter = ldapConfig.getSearchFilter();
-
Hashtable<String,Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, _ldapContextFactory);
env.put(Context.PROVIDER_URL, _providerSearchURL);
@@ -277,11 +206,11 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
try
{
- new InitialDirContext(env);
+ new InitialDirContext(env).close();
}
catch (NamingException e)
{
- throw new ConfigurationException("Unable to establish anonymous connection to the ldap server at " + _providerSearchURL, e);
+ throw new RuntimeException("Unable to establish anonymous connection to the ldap server at " + _providerSearchURL, e);
}
}
@@ -305,19 +234,11 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
}
catch (NamingException e)
{
- _logger.info("SASL Authentication Error", e);
+ _logger.warn("SASL Authentication Exception", e);
}
if(password != null)
{
- try
- {
- authenticated = doLDAPNameAuthentication(name, password);
-
- }
- catch (NamingException e)
- {
- authenticated = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
- }
+ authenticated = doLDAPNameAuthentication(name, password);
}
}
else if (callback instanceof PlainPasswordCallback)
@@ -325,17 +246,10 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
password = ((PlainPasswordCallback)callback).getPlainPassword();
if(name != null)
{
- try
- {
- authenticated = doLDAPNameAuthentication(name, password);
- if(authenticated.getStatus()== AuthenticationResult.AuthenticationStatus.SUCCESS)
- {
- ((PlainPasswordCallback)callback).setAuthenticated(true);
- }
- }
- catch (NamingException e)
+ authenticated = doLDAPNameAuthentication(name, password);
+ if(authenticated.getStatus()== AuthenticationResult.AuthenticationStatus.SUCCESS)
{
- authenticated = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
+ ((PlainPasswordCallback)callback).setAuthenticated(true);
}
}
}
@@ -357,7 +271,6 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
env.put(Context.INITIAL_CONTEXT_FACTORY, _ldapContextFactory);
env.put(Context.PROVIDER_URL, _providerSearchURL);
-
env.put(Context.SECURITY_AUTHENTICATION, "none");
DirContext ctx = null;
@@ -382,7 +295,14 @@ public class SimpleLDAPAuthenticationManager implements AuthenticationManager
}
finally
{
- ctx.close();
+ try
+ {
+ ctx.close();
+ }
+ catch (Exception e)
+ {
+ _logger.warn("Exception closing InitialDirContext", e);
+ }
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.java
new file mode 100644
index 0000000000..05a692fb0e
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactory.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.server.security.auth.manager;
+
+import java.util.Map;
+
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+
+public class SimpleLDAPAuthenticationManagerFactory implements AuthenticationManagerFactory
+{
+ private static final String DEFAULT_LDAP_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
+
+ public static final String PROVIDER_TYPE = SimpleLDAPAuthenticationManager.class.getSimpleName();
+
+ public static final String ATTRIBUTE_LDAP_CONTEXT_FACTORY = "ldapContextFactory";
+ public static final String ATTRIBUTE_SEARCH_FILTER = "searchFilter";
+ public static final String ATTRIBUTE_SEARCH_CONTEXT = "searchContext";
+ public static final String ATTRIBUTE_PROVIDER_AUTH_URL = "providerAuthUrl";
+ public static final String ATTRIBUTE_PROVIDER_SEARCH_URL = "providerSearchUrl";
+ public static final String ATTRIBUTE_PROVIDER_URL = "providerUrl";
+
+ @Override
+ public AuthenticationManager createInstance(Map<String, Object> attributes)
+ {
+ if (attributes == null || !PROVIDER_TYPE.equals(attributes.get(ATTRIBUTE_TYPE)))
+ {
+ return null;
+ }
+ String providerUrl = (String) attributes.get(ATTRIBUTE_PROVIDER_URL);
+ String providerSearchUrl = (String) attributes.get(ATTRIBUTE_PROVIDER_SEARCH_URL);
+ if (providerSearchUrl == null)
+ {
+ providerSearchUrl = providerUrl;
+ }
+ String providerAuthUrl = (String) attributes.get(ATTRIBUTE_PROVIDER_AUTH_URL);
+ if (providerAuthUrl == null)
+ {
+ providerAuthUrl = providerUrl;
+ }
+ String searchContext = (String) attributes.get(ATTRIBUTE_SEARCH_CONTEXT);
+ String searchFilter = (String) attributes.get(ATTRIBUTE_SEARCH_FILTER);
+ String ldapContextFactory = (String) attributes.get(ATTRIBUTE_LDAP_CONTEXT_FACTORY);
+ if (ldapContextFactory == null)
+ {
+ ldapContextFactory = DEFAULT_LDAP_CONTEXT_FACTORY;
+ }
+
+ return new SimpleLDAPAuthenticationManager(providerSearchUrl, providerAuthUrl, searchContext, searchFilter,
+ ldapContextFactory);
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java
index 2e21cfbb07..abb8677e90 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticator.java
@@ -22,13 +22,13 @@ package org.apache.qpid.server.security.auth.rmi;
import java.net.SocketAddress;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
import javax.management.remote.JMXAuthenticator;
-import javax.management.remote.JMXPrincipal;
import javax.security.auth.Subject;
public class RMIPasswordAuthenticator implements JMXAuthenticator
@@ -38,23 +38,33 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator
static final String SHOULD_HAVE_2_ELEMENTS = "User details should have 2 elements, username, password";
static final String SHOULD_BE_NON_NULL = "Supplied username and password should be non-null";
static final String INVALID_CREDENTIALS = "Invalid user details supplied";
+ static final String USER_NOT_AUTHORISED_FOR_MANAGEMENT = "User not authorised for management";
static final String CREDENTIALS_REQUIRED = "User details are required. " +
- "Please ensure you are using an up to date management console to connect.";
+ "Please ensure you are using an up to date management console to connect.";
- private AuthenticationManager _authenticationManager = null;
- private SocketAddress _socketAddress;
+ private final Broker _broker;
+ private final SocketAddress _address;
- public RMIPasswordAuthenticator(SocketAddress socketAddress)
+ public RMIPasswordAuthenticator(Broker broker, SocketAddress address)
{
- _socketAddress = socketAddress;
+ _broker = broker;
+ _address = address;
}
- public void setAuthenticationManager(final AuthenticationManager authenticationManager)
+ public Subject authenticate(Object credentials) throws SecurityException
{
- _authenticationManager = authenticationManager;
+ validateCredentials(credentials);
+
+ final String[] userCredentials = (String[]) credentials;
+ final String username = (String) userCredentials[0];
+ final String password = (String) userCredentials[1];
+
+ final Subject authenticatedSubject = doAuthentication(username, password);
+ doManagementAuthorisation(authenticatedSubject);
+ return authenticatedSubject;
}
- public Subject authenticate(Object credentials) throws SecurityException
+ private void validateCredentials(Object credentials)
{
// Verify that credential's are of type String[].
if (!(credentials instanceof String[]))
@@ -70,41 +80,27 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator
}
// Verify that required number of credentials.
- final String[] userCredentials = (String[]) credentials;
- if (userCredentials.length != 2)
+ if (((String[])credentials).length != 2)
{
throw new SecurityException(SHOULD_HAVE_2_ELEMENTS);
}
+ }
- final String username = (String) userCredentials[0];
- final String password = (String) userCredentials[1];
-
+ private Subject doAuthentication(final String username, final String password)
+ {
// Verify that all required credentials are actually present.
if (username == null || password == null)
{
throw new SecurityException(SHOULD_BE_NON_NULL);
}
- // Verify that an AuthenticationManager has been set.
- if (_authenticationManager == null)
+ SubjectCreator subjectCreator = _broker.getSubjectCreator(_address);
+ if (subjectCreator == null)
{
- try
- {
- if(ApplicationRegistry.getInstance().getAuthenticationManager(_socketAddress) != null)
- {
- _authenticationManager = ApplicationRegistry.getInstance().getAuthenticationManager(_socketAddress);
- }
- else
- {
- throw new SecurityException(UNABLE_TO_LOOKUP);
- }
- }
- catch(IllegalStateException e)
- {
- throw new SecurityException(UNABLE_TO_LOOKUP);
- }
+ throw new SecurityException("Can't get subject creator for " + _address);
}
- final AuthenticationResult result = _authenticationManager.authenticate(username, password);
+
+ final SubjectAuthenticationResult result = subjectCreator.authenticate(username, password);
if (AuthenticationStatus.ERROR.equals(result.getStatus()))
{
@@ -112,10 +108,7 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator
}
else if (AuthenticationStatus.SUCCESS.equals(result.getStatus()))
{
- final Subject subject = result.getSubject();
- subject.getPrincipals().add(new JMXPrincipal(username));
- subject.setReadOnly();
- return subject;
+ return result.getSubject();
}
else
{
@@ -123,4 +116,21 @@ public class RMIPasswordAuthenticator implements JMXAuthenticator
}
}
+ private void doManagementAuthorisation(Subject authenticatedSubject)
+ {
+ SecurityManager.setThreadSubject(authenticatedSubject);
+ try
+ {
+ if (!_broker.getSecurityManager().accessManagement())
+ {
+ throw new SecurityException(USER_NOT_AUTHORISED_FOR_MANAGEMENT);
+ }
+ }
+ finally
+ {
+ SecurityManager.setThreadSubject(null);
+ }
+ }
+
+
} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipal.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipal.java
deleted file mode 100644
index 30a503c769..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipal.java
+++ /dev/null
@@ -1,99 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.sasl;
-
-import java.security.Principal;
-import java.security.acl.Group;
-import java.util.Enumeration;
-
-/**
- * Immutable representation of a user group. In Qpid, groups do <b>not</b> know
- * about their membership, and therefore the {@link #addMember(Principal)}
- * methods etc throw {@link UnsupportedOperationException}.
- *
- */
-public class GroupPrincipal implements Group
-{
- /** Name of the group */
- private final String _groupName;
-
- public GroupPrincipal(final String groupName)
- {
- _groupName = groupName;
- }
-
- public String getName()
- {
- return _groupName;
- }
-
- public boolean addMember(Principal user)
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- public boolean removeMember(Principal user)
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- public boolean isMember(Principal member)
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- public Enumeration<? extends Principal> members()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- /**
- * @see java.lang.Object#hashCode()
- */
- public int hashCode()
- {
- final int prime = 37;
- return prime * _groupName.hashCode();
- }
-
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- else
- {
- if (obj instanceof GroupPrincipal)
- {
- GroupPrincipal other = (GroupPrincipal) obj;
- return _groupName.equals(other._groupName);
- }
- else
- {
- return false;
- }
- }
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java
index f4e8f800c6..b70a987107 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java
@@ -23,6 +23,7 @@ package org.apache.qpid.server.security.auth.sasl;
import org.apache.commons.configuration.Configuration;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
import javax.security.auth.callback.Callback;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipal.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipal.java
deleted file mode 100644
index 9e7db94216..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipal.java
+++ /dev/null
@@ -1,99 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.sasl;
-
-import javax.security.auth.Subject;
-import java.security.Principal;
-import java.util.Set;
-
-/** A principal that is just a wrapper for a simple username. */
-public class UsernamePrincipal implements Principal
-{
- private final String _name;
-
- public UsernamePrincipal(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("name cannot be null");
- }
- _name = name;
- }
-
- public String getName()
- {
- return _name;
- }
-
- public String toString()
- {
- return _name;
- }
-
- /**
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode()
- {
- final int prime = 31;
- return prime * _name.hashCode();
- }
-
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- else
- {
- if (obj instanceof UsernamePrincipal)
- {
- UsernamePrincipal other = (UsernamePrincipal) obj;
- return _name.equals(other._name);
- }
- else
- {
- return false;
- }
- }
- }
-
- public static UsernamePrincipal getUsernamePrincipalFromSubject(final Subject authSubject)
- {
- if (authSubject == null)
- {
- throw new IllegalArgumentException("No authenticated subject.");
- }
-
- final Set<UsernamePrincipal> principals = authSubject.getPrincipals(UsernamePrincipal.class);
- if (principals.size() != 1)
- {
- throw new IllegalArgumentException("Can't find single UsernamePrincipal in authenticated subject");
- }
- return principals.iterator().next();
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServer.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServer.java
index 52d36023c2..d10193e743 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServer.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/anonymous/AnonymousSaslServer.java
@@ -23,6 +23,8 @@ package org.apache.qpid.server.security.auth.sasl.anonymous;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
+import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
+
public class AnonymousSaslServer implements SaslServer
{
@@ -52,7 +54,7 @@ public class AnonymousSaslServer implements SaslServer
public String getAuthorizationID()
{
- return null;
+ return AnonymousAuthenticationManager.ANONYMOUS_PRINCIPAL.getName();
}
public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java b/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java
index 478f195530..4e12ac0750 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java
@@ -139,6 +139,12 @@ public class CRAMMD5HexInitialiser extends UsernamePasswordInitialiser
{
_realPricipalDatabase.reload();
}
+
+ @Override
+ public void setPasswordFile(String passwordFile) throws IOException
+ {
+ throw new UnsupportedOperationException();
+ }
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java b/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.java
new file mode 100644
index 0000000000..c66e7fd4e4
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupDatabase.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.security.group;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+
+/**
+ * A group database that reads/writes the following file format:
+ *
+ * group1.users=user1,user2
+ * group2.users=user2,user3
+ */
+public class FileGroupDatabase implements GroupDatabase
+{
+ private static final Logger LOGGER = Logger.getLogger(FileGroupDatabase.class);
+
+ private Map<String, Set<String>> _groupToUserMap = new ConcurrentHashMap<String, Set<String>>();
+ private Map<String, Set<String>> _userToGroupMap = new ConcurrentHashMap<String, Set<String>>();
+ private String _groupFile;
+
+ @Override
+ public Set<String> getAllGroups()
+ {
+ return Collections.unmodifiableSet(_groupToUserMap.keySet());
+ }
+
+ public synchronized void setGroupFile(String groupFile) throws IOException
+ {
+ File file = new File(groupFile);
+
+ if (!file.canRead())
+ {
+ throw new FileNotFoundException(groupFile
+ + " cannot be found or is not readable");
+ }
+
+ readGroupFile(groupFile);
+ }
+
+ @Override
+ public Set<String> getUsersInGroup(String group)
+ {
+ if (group == null)
+ {
+ LOGGER.warn("Requested user set for null group. Returning empty set.");
+ return Collections.emptySet();
+ }
+
+ Set<String> set = _groupToUserMap.get(group);
+ if (set == null)
+ {
+ return Collections.emptySet();
+ }
+ else
+ {
+ return Collections.unmodifiableSet(set);
+ }
+ }
+
+ @Override
+ public synchronized void addUserToGroup(String user, String group)
+ {
+ Set<String> users = _groupToUserMap.get(group);
+ if (users == null)
+ {
+ throw new IllegalArgumentException("Group " + group + " does not exist so could not add " + user + " to it");
+ }
+
+ users.add(user);
+
+ Set<String> groups = _userToGroupMap.get(user);
+ if (groups == null)
+ {
+ groups = new ConcurrentSkipListSet<String>();
+ _userToGroupMap.put(user, groups);
+ }
+ groups.add(group);
+
+ update();
+ }
+
+ @Override
+ public synchronized void removeUserFromGroup(String user, String group)
+ {
+ Set<String> users = _groupToUserMap.get(group);
+ if (users == null)
+ {
+ throw new IllegalArgumentException("Group " + group + " does not exist so could not remove " + user + " from it");
+ }
+
+ users.remove(user);
+
+ Set<String> groups = _userToGroupMap.get(user);
+ if (groups != null)
+ {
+ groups.remove(group);
+ }
+
+ update();
+ }
+
+ @Override
+ public Set<String> getGroupsForUser(String user)
+ {
+ if(user == null)
+ {
+ LOGGER.warn("Requested group set for null user. Returning empty set.");
+ return Collections.emptySet();
+ }
+
+ Set<String> groups = _userToGroupMap.get(user);
+ if (groups == null)
+ {
+ return Collections.emptySet();
+ }
+ else
+ {
+ return Collections.unmodifiableSet(groups);
+ }
+ }
+
+ @Override
+ public synchronized void createGroup(String group)
+ {
+ Set<String> users = new ConcurrentSkipListSet<String>();
+ _groupToUserMap.put(group, users);
+
+ update();
+ }
+
+ @Override
+ public synchronized void removeGroup(String group)
+ {
+ _groupToUserMap.remove(group);
+ for (Set<String> groupsForUser : _userToGroupMap.values())
+ {
+ groupsForUser.remove(group);
+ }
+
+ update();
+ }
+
+ private synchronized void update()
+ {
+ if (_groupFile != null)
+ {
+ try
+ {
+ writeGroupFile(_groupFile);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable to persist change to file " + _groupFile);
+ }
+ }
+ }
+
+ private synchronized void readGroupFile(String groupFile) throws IOException
+ {
+ _groupFile = groupFile;
+ _groupToUserMap.clear();
+ _userToGroupMap.clear();
+ Properties propertiesFile = new Properties();
+ FileInputStream fileInputStream = new FileInputStream(groupFile);
+ try
+ {
+ propertiesFile.load(fileInputStream);
+ }
+ finally
+ {
+ if(fileInputStream != null)
+ {
+ fileInputStream.close();
+ }
+ }
+
+ for (String propertyName : propertiesFile.stringPropertyNames())
+ {
+ validatePropertyNameIsGroupName(propertyName);
+
+ String groupName = propertyName.replaceAll("\\.users$", "");
+ String userString = propertiesFile.getProperty(propertyName);
+
+ final Set<String> userSet = buildUserSetFromCommaSeparateValue(userString);
+
+ _groupToUserMap.put(groupName, userSet);
+
+ for (String userName : userSet)
+ {
+ Set<String> groupsForThisUser = _userToGroupMap.get(userName);
+
+ if (groupsForThisUser == null)
+ {
+ groupsForThisUser = new ConcurrentSkipListSet<String>();
+ _userToGroupMap.put(userName, groupsForThisUser);
+ }
+
+ groupsForThisUser.add(groupName);
+ }
+ }
+ }
+
+ private synchronized void writeGroupFile(String groupFile) throws IOException
+ {
+ Properties propertiesFile = new Properties();
+
+ for (String group : _groupToUserMap.keySet())
+ {
+ Set<String> users = _groupToUserMap.get(group);
+ String userList = StringUtils.join(users, ",");
+
+ propertiesFile.setProperty(group + ".users", userList);
+ }
+
+ String comment = "Written " + new Date();
+ FileOutputStream fileOutputStream = new FileOutputStream(groupFile);
+ try
+ {
+ propertiesFile.store(fileOutputStream, comment);
+ }
+ finally
+ {
+ if(fileOutputStream != null)
+ {
+ fileOutputStream.close();
+ }
+ }
+ }
+
+ private void validatePropertyNameIsGroupName(String propertyName)
+ {
+ if (!propertyName.endsWith(".users"))
+ {
+ throw new IllegalArgumentException(
+ "Invalid definition with name '"
+ + propertyName
+ + "'. Group definitions must end with suffix '.users'");
+ }
+ }
+
+ private ConcurrentSkipListSet<String> buildUserSetFromCommaSeparateValue(String userString)
+ {
+ String[] users = userString.split(",");
+ final ConcurrentSkipListSet<String> userSet = new ConcurrentSkipListSet<String>();
+ for (String user : users)
+ {
+ final String trimmed = user.trim();
+ if (!trimmed.isEmpty())
+ {
+ userSet.add(trimmed);
+ }
+ }
+ return userSet;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java
new file mode 100644
index 0000000000..8295f28f9e
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManager.java
@@ -0,0 +1,147 @@
+/*
+ * 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.security.group;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
+
+/**
+ * Implementation of a group manager whose implementation is backed by a flat group file.
+ * <p>
+ * This plugin is configured in the following manner:
+ * </p>
+ * <pre>
+ * &lt;file-group-manager&gt;
+ * &lt;attributes&gt;
+ * &lt;attribute&gt;
+ * &lt;name>groupFile&lt;/name&gt;
+ * &lt;value>${conf}/groups&lt;/value&gt;
+ * &lt;/attribute&gt;
+ * &lt;/attributes&gt;
+ * &lt;/file-group-manager&gt;
+ * </pre>
+ */
+public class FileGroupManager implements GroupManager
+{
+ private final FileGroupDatabase _groupDatabase;
+
+
+ public FileGroupManager(String groupFile)
+ {
+ _groupDatabase = new FileGroupDatabase();
+ try
+ {
+ _groupDatabase.setGroupFile(groupFile);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Unable to set group file " + groupFile, e);
+ }
+ }
+
+ @Override
+ public Set<Principal> getGroupPrincipalsForUser(String userId)
+ {
+ Set<String> groups = _groupDatabase.getGroupsForUser(userId);
+ if (groups.isEmpty())
+ {
+ return Collections.emptySet();
+ }
+ else
+ {
+ Set<Principal> principals = new HashSet<Principal>();
+ for (String groupName : groups)
+ {
+ principals.add(new GroupPrincipal(groupName));
+ }
+ return principals;
+ }
+ }
+
+ @Override
+ public Set<Principal> getUserPrincipalsForGroup(String group)
+ {
+ Set<String> users = _groupDatabase.getUsersInGroup(group);
+ if (users.isEmpty())
+ {
+ return Collections.emptySet();
+ }
+ else
+ {
+ Set<Principal> principals = new HashSet<Principal>();
+ for (String user : users)
+ {
+ principals.add(new UsernamePrincipal(user));
+ }
+ return principals;
+ }
+ }
+
+ @Override
+ public Set<Principal> getGroupPrincipals()
+ {
+ Set<String> groups = _groupDatabase.getAllGroups();
+ if (groups.isEmpty())
+ {
+ return Collections.emptySet();
+ }
+ else
+ {
+ Set<Principal> principals = new HashSet<Principal>();
+ for (String groupName : groups)
+ {
+ principals.add(new GroupPrincipal(groupName));
+ }
+ return principals;
+ }
+ }
+
+ @Override
+ public void createGroup(String group)
+ {
+ _groupDatabase.createGroup(group);
+ }
+
+ @Override
+ public void removeGroup(String group)
+ {
+ _groupDatabase.removeGroup(group);
+ }
+
+ @Override
+ public void addUserToGroup(String user, String group)
+ {
+ _groupDatabase.addUserToGroup(user, group);
+ }
+
+ @Override
+ public void removeUserFromGroup(String user, String group)
+ {
+ _groupDatabase.removeUserFromGroup(user, group);
+
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java b/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.java
new file mode 100644
index 0000000000..5c4730a9c8
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/group/FileGroupManagerFactory.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.server.security.group;
+
+import static org.apache.qpid.server.util.MapValueConverter.getStringAttribute;
+
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.plugin.GroupManagerFactory;
+
+public class FileGroupManagerFactory implements GroupManagerFactory
+{
+ static final String FILE_GROUP_MANAGER_TYPE = "file-group-manager";
+ static final String FILE = "file";
+
+ @Override
+ public GroupManager createInstance(Map<String, Object> attributes)
+ {
+ if(!FILE_GROUP_MANAGER_TYPE.equals(getStringAttribute(GroupProvider.TYPE, attributes, null)))
+ {
+ return null;
+ }
+
+ String groupFile = getStringAttribute(FILE, attributes, null);
+ if (StringUtils.isBlank(groupFile))
+ {
+ throw new IllegalConfigurationException("Path to file containing groups is not specified!");
+ }
+ return new FileGroupManager(groupFile);
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupDatabase.java b/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupDatabase.java
new file mode 100644
index 0000000000..98c12782d8
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupDatabase.java
@@ -0,0 +1,34 @@
+/*
+ * 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.security.group;
+
+import java.util.Set;
+
+public interface GroupDatabase
+{
+ Set<String> getAllGroups();
+ Set<String> getUsersInGroup(String group);
+
+ void addUserToGroup(String user, String group);
+ void removeUserFromGroup(String user, String group);
+ Set<String> getGroupsForUser(String user);
+ void createGroup(String group);
+ void removeGroup(String group);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java b/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java
new file mode 100644
index 0000000000..6d2df86919
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupManager.java
@@ -0,0 +1,40 @@
+/*
+ * 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.security.group;
+
+import java.security.Principal;
+import java.util.Set;
+
+public interface GroupManager
+{
+ Set<Principal> getGroupPrincipalsForUser(String user);
+
+ Set<Principal> getGroupPrincipals();
+
+ Set<Principal> getUserPrincipalsForGroup(String group);
+
+ void createGroup(String group);
+
+ void removeGroup(String group);
+
+ void addUserToGroup(String user, String group);
+
+ void removeUserFromGroup(String user, String group);
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipal.java b/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipal.java
new file mode 100644
index 0000000000..a9590bb964
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipal.java
@@ -0,0 +1,100 @@
+/*
+ *
+ * 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.security.group;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Enumeration;
+
+/**
+ * Immutable representation of a user group. In Qpid, groups do <b>not</b> know
+ * about their membership, and therefore the {@link #addMember(Principal)}
+ * methods etc throw {@link UnsupportedOperationException}.
+ *
+ */
+public class GroupPrincipal implements Group, Serializable
+{
+ /** Name of the group */
+ private final String _groupName;
+
+ public GroupPrincipal(final String groupName)
+ {
+ _groupName = groupName;
+ }
+
+ public String getName()
+ {
+ return _groupName;
+ }
+
+ public boolean addMember(Principal user)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ public boolean removeMember(Principal user)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ public boolean isMember(Principal member)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ public Enumeration<? extends Principal> members()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ final int prime = 37;
+ return prime * _groupName.hashCode();
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ else
+ {
+ if (obj instanceof GroupPrincipal)
+ {
+ GroupPrincipal other = (GroupPrincipal) obj;
+ return _groupName.equals(other._groupName);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java b/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java
new file mode 100644
index 0000000000..d549b76aab
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/security/group/GroupPrincipalAccessor.java
@@ -0,0 +1,54 @@
+/*
+ * 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.security.group;
+
+import java.security.Principal;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.adapter.GroupProviderAdapter;
+
+
+public class GroupPrincipalAccessor
+{
+ private final Collection<GroupProvider> _groupProviders;
+
+ public GroupPrincipalAccessor(Collection<GroupProvider> groupProviders)
+ {
+ _groupProviders = groupProviders;
+ }
+
+ public Set<Principal> getGroupPrincipals(String username)
+ {
+ Set<Principal> principals = new HashSet<Principal>();
+ for (GroupProvider groupProvider : _groupProviders)
+ {
+ Set<Principal> groups = groupProvider.getGroupPrincipalsForUser(username);
+ if (groups != null)
+ {
+ principals.addAll(groups);
+ }
+ }
+
+ return Collections.unmodifiableSet(principals);
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java b/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java
deleted file mode 100644
index bdcfd86f82..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java
+++ /dev/null
@@ -1,89 +0,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.
- *
- */
-package org.apache.qpid.server.signal;
-
-import org.apache.log4j.Logger;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-public abstract class SignalHandlerTask
-{
- private static final Logger LOGGER = Logger.getLogger(SignalHandlerTask.class);
-
- private static final String HANDLE_METHOD = "handle";
- private static final String SUN_MISC_SIGNAL_CLASS = "sun.misc.Signal";
- private static final String SUN_MISC_SIGNAL_HANDLER_CLASS = "sun.misc.SignalHandler";
-
- public boolean register(final String signalName)
- {
- try
- {
- //try to load the signal handling classes
- Class<?> signalClazz = Class.forName(SUN_MISC_SIGNAL_CLASS);
- Class<?> handlerClazz = Class.forName(SUN_MISC_SIGNAL_HANDLER_CLASS);
-
- //create an InvocationHandler that just executes the SignalHandlerTask
- InvocationHandler invoker = new InvocationHandler()
- {
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- handle();
-
- return null;
- }
- };
-
- //create a dynamic proxy implementing SignalHandler
- Object handler = Proxy.newProxyInstance(handlerClazz.getClassLoader(), new Class[]{handlerClazz}, invoker);
-
- //create the Signal to handle
- Constructor<?> signalConstructor = signalClazz.getConstructor(String.class);
- Object signal = signalConstructor.newInstance(signalName);
-
- //invoke the Signal.handle(signal, handler) method
- Method handleMethod = signalClazz.getMethod(HANDLE_METHOD, signalClazz, handlerClazz);
- handleMethod.invoke(null, signal, handler);
- }
- catch (Exception e)
- {
- LOGGER.debug("Unable to register handler for Signal " + signalName + " due to exception: " + e, e);
- return false;
- }
-
- return true;
- }
-
- public abstract void handle();
-
- public static String getPlatformDescription()
- {
- String name = System.getProperty("os.name");
- String osVer = System.getProperty("os.version");
- String jvmVendor = System.getProperty("java.vm.vendor");
- String jvmName = System.getProperty("java.vm.name");
- String javaRuntimeVer = System.getProperty("java.runtime.version");
-
- return "OS: " + name + " " + osVer + ", JVM:" + jvmVendor + " " + jvmName + " " + javaRuntimeVer;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java b/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
index f352bbdd2c..ff41536a23 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java
@@ -31,10 +31,10 @@ import org.apache.qpid.framing.MethodDispatcher;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.protocol.AMQMethodEvent;
import org.apache.qpid.protocol.AMQMethodListener;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -47,32 +47,29 @@ public class AMQStateManager implements AMQMethodListener
{
private static final Logger _logger = Logger.getLogger(AMQStateManager.class);
- private final VirtualHostRegistry _virtualHostRegistry;
+ private final Broker _broker;
private final AMQProtocolSession _protocolSession;
/** The current state */
private AMQState _currentState;
private CopyOnWriteArraySet<StateListener> _stateListeners = new CopyOnWriteArraySet<StateListener>();
- public AMQStateManager(VirtualHostRegistry virtualHostRegistry, AMQProtocolSession protocolSession)
+ public AMQStateManager(Broker broker, AMQProtocolSession protocolSession)
{
-
- _virtualHostRegistry = virtualHostRegistry;
+ _broker = broker;
_protocolSession = protocolSession;
_currentState = AMQState.CONNECTION_NOT_STARTED;
}
/**
- * Get the ApplicationRegistry associated with this AMQStateManager
- *
- * returns the application registry associated with the VirtualHostRegistry of the AMQStateManager
+ * Get the Broker instance
*
- * @return the ApplicationRegistry
+ * @return the Broker
*/
- public IApplicationRegistry getApplicationRegistry()
+ public Broker getBroker()
{
- return _virtualHostRegistry.getApplicationRegistry();
+ return _broker;
}
public AMQState getCurrentState()
@@ -148,7 +145,7 @@ public class AMQStateManager implements AMQMethodListener
public VirtualHostRegistry getVirtualHostRegistry()
{
- return _virtualHostRegistry;
+ return _broker.getVirtualHostRegistry();
}
public AMQProtocolSession getProtocolSession()
@@ -157,13 +154,9 @@ public class AMQStateManager implements AMQMethodListener
return _protocolSession;
}
- /**
- * Get the AuthenticationManager associated with the ProtocolSession of the AMQStateManager
- *
- * @return the AuthenticationManager
- */
- public AuthenticationManager getAuthenticationManager()
+
+ public SubjectCreator getSubjectCreator()
{
- return getApplicationRegistry().getAuthenticationManager(getProtocolSession().getLocalAddress());
+ return _broker.getSubjectCreator(getProtocolSession().getLocalAddress());
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/ConfigurationRecoveryHandler.java b/java/broker/src/main/java/org/apache/qpid/server/store/ConfigurationRecoveryHandler.java
index ede01d247e..ab7ef3f55b 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/store/ConfigurationRecoveryHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/ConfigurationRecoveryHandler.java
@@ -46,19 +46,7 @@ public interface ConfigurationRecoveryHandler
public static interface BindingRecoveryHandler
{
void binding(UUID bindingId, UUID exchangeId, UUID queueId, String bindingName, ByteBuffer buf);
- BrokerLinkRecoveryHandler completeBindingRecovery();
- }
-
- public static interface BrokerLinkRecoveryHandler
- {
- BridgeRecoveryHandler brokerLink(UUID id, long createTime, Map<String,String> arguments);
- void completeBrokerLinkRecovery();
- }
-
- public static interface BridgeRecoveryHandler
- {
- void bridge(UUID id, long createTime, Map<String,String> arguments);
- void completeBridgeRecoveryForLink();
+ void completeBindingRecovery();
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStore.java b/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStore.java
index 655887e5c2..4e7bbf04a6 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStore.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/DurableConfigurationStore.java
@@ -26,8 +26,6 @@ import org.apache.qpid.AMQStoreException;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.federation.Bridge;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.queue.AMQQueue;
public interface DurableConfigurationStore
@@ -122,12 +120,5 @@ public interface DurableConfigurationStore
* @throws AMQStoreException If the operation fails for any reason.
*/
void updateQueue(AMQQueue queue) throws AMQStoreException;
-
- void createBrokerLink(BrokerLink link) throws AMQStoreException;
-
- void deleteBrokerLink(BrokerLink link) throws AMQStoreException;
-
- void createBridge(Bridge bridge) throws AMQStoreException;
-
- void deleteBridge(Bridge bridge) throws AMQStoreException;
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java b/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java
index 262d7d0213..3f1d1b9530 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStore.java
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicLong;
/** A simple message store that stores the messages in a thread-safe structure in memory. */
public class MemoryMessageStore extends NullMessageStore
{
+ public static final String TYPE = "Memory";
private final AtomicLong _messageId = new AtomicLong(1);
private final AtomicBoolean _closed = new AtomicBoolean(false);
@@ -138,6 +139,6 @@ public class MemoryMessageStore extends NullMessageStore
@Override
public String getStoreType()
{
- return "Memory";
+ return TYPE;
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStoreFactory.java b/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStoreFactory.java
new file mode 100644
index 0000000000..20b6b7a8a6
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/MemoryMessageStoreFactory.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.server.store;
+
+
+public class MemoryMessageStoreFactory implements MessageStoreFactory
+{
+
+ @Override
+ public String getType()
+ {
+ return MemoryMessageStore.TYPE;
+ }
+
+ @Override
+ public MessageStore createMessageStore()
+ {
+ return new MemoryMessageStore();
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java b/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java
new file mode 100644
index 0000000000..0d5a4850f6
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.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.server.store;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class MessageStoreCreator
+{
+ private Map<String, MessageStoreFactory> _factories = new HashMap<String, MessageStoreFactory>();
+
+ public MessageStoreCreator()
+ {
+ QpidServiceLoader<MessageStoreFactory> qpidServiceLoader = new QpidServiceLoader<MessageStoreFactory>();
+ Iterable<MessageStoreFactory> factories = qpidServiceLoader.atLeastOneInstanceOf(MessageStoreFactory.class);
+ for (MessageStoreFactory messageStoreFactory : factories)
+ {
+ String type = messageStoreFactory.getType();
+ MessageStoreFactory factory = _factories.put(type.toLowerCase(), messageStoreFactory);
+ if (factory != null)
+ {
+ throw new IllegalStateException("MessageStoreFactory with type name '" + type
+ + "' is already registered using class '" + factory.getClass().getName() + "', can not register class '"
+ + messageStoreFactory.getClass().getName() + "'");
+ }
+ }
+ }
+
+ public MessageStore createMessageStore(String storeType)
+ {
+ MessageStoreFactory factory = _factories.get(storeType.toLowerCase());
+ if (factory == null)
+ {
+ throw new IllegalConfigurationException("Unknown store type: " + storeType);
+ }
+ return factory.createMessageStore();
+ }
+
+ public Collection<MessageStoreFactory> getFactories()
+ {
+ return Collections.unmodifiableCollection(_factories.values());
+ }
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreFactory.java b/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreFactory.java
new file mode 100644
index 0000000000..a1afd02f12
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreFactory.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.store;
+
+public interface MessageStoreFactory
+{
+ String getType();
+
+ MessageStore createMessageStore();
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/NullMessageStore.java b/java/broker/src/main/java/org/apache/qpid/server/store/NullMessageStore.java
index be08e309e6..c6bffbc1de 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/store/NullMessageStore.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/NullMessageStore.java
@@ -24,8 +24,6 @@ import org.apache.qpid.AMQStoreException;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.federation.Bridge;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.queue.AMQQueue;
public abstract class NullMessageStore implements MessageStore
@@ -78,26 +76,6 @@ public abstract class NullMessageStore implements MessageStore
}
@Override
- public void createBrokerLink(final BrokerLink link) throws AMQStoreException
- {
- }
-
- @Override
- public void deleteBrokerLink(final BrokerLink link) throws AMQStoreException
- {
- }
-
- @Override
- public void createBridge(final Bridge bridge) throws AMQStoreException
- {
- }
-
- @Override
- public void deleteBridge(final Bridge bridge) throws AMQStoreException
- {
- }
-
- @Override
public void configureMessageStore(String name,
MessageStoreRecoveryHandler recoveryHandler,
TransactionLogRecoveryHandler tlogRecoveryHandler, Configuration config) throws Exception
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/State.java b/java/broker/src/main/java/org/apache/qpid/server/store/State.java
index 2783637b2a..1d0936cec4 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/store/State.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/State.java
@@ -20,8 +20,6 @@
*/
package org.apache.qpid.server.store;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-
public enum State
{
/** The initial state of the store. In practice, the store immediately transitions to the subsequent states. */
@@ -30,7 +28,7 @@ public enum State
INITIALISING,
/**
* The initial set-up of the store has completed.
- * If the store is persistent, it has not yet loaded configuration for {@link ConfiguredObject}'s from disk.
+ * If the store is persistent, it has not yet loaded configuration from disk.
*
* From the point of view of the user, the store is essentially stopped.
*/
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java b/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java
index 154d7e6535..e9946d1860 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStore.java
@@ -23,7 +23,6 @@ package org.apache.qpid.server.store.derby;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
@@ -41,7 +40,6 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -55,12 +53,9 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.federation.Bridge;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.message.EnqueableMessage;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler;
-import org.apache.qpid.server.store.ConfigurationRecoveryHandler.BrokerLinkRecoveryHandler;
import org.apache.qpid.server.store.ConfiguredObjectHelper;
import org.apache.qpid.server.store.ConfiguredObjectRecord;
import org.apache.qpid.server.store.Event;
@@ -236,7 +231,7 @@ public class DerbyMessageStore implements MessageStore
private static final String DERBY_SINGLE_DB_SHUTDOWN_CODE = "08006";
- private static final String DERBY_STORE_TYPE = "DERBY";
+ public static final String TYPE = "DERBY";
private final StateManager _stateManager;
@@ -572,8 +567,7 @@ public class DerbyMessageStore implements MessageStore
BindingRecoveryHandler brh = qrh.completeQueueRecovery();
_configuredObjectHelper.recoverBindings(brh, configuredObjects);
- BrokerLinkRecoveryHandler lrh = brh.completeBindingRecovery();
- recoverBrokerLinks(lrh);
+ brh.completeBindingRecovery();
}
catch (SQLException e)
{
@@ -581,144 +575,6 @@ public class DerbyMessageStore implements MessageStore
}
}
- private void recoverBrokerLinks(final ConfigurationRecoveryHandler.BrokerLinkRecoveryHandler lrh)
- throws SQLException
- {
- _logger.info("Recovering broker links...");
-
- Connection conn = null;
- try
- {
- conn = newAutoCommitConnection();
-
- PreparedStatement stmt = conn.prepareStatement(SELECT_ALL_FROM_LINKS);
-
- try
- {
- ResultSet rs = stmt.executeQuery();
-
- try
- {
-
- while(rs.next())
- {
- UUID id = new UUID(rs.getLong(2), rs.getLong(1));
- long createTime = rs.getLong(3);
- Blob argumentsAsBlob = rs.getBlob(4);
-
- byte[] dataAsBytes = argumentsAsBlob.getBytes(1,(int) argumentsAsBlob.length());
-
- DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dataAsBytes));
- int size = dis.readInt();
-
- Map<String,String> arguments = new HashMap<String, String>();
-
- for(int i = 0; i < size; i++)
- {
- arguments.put(dis.readUTF(), dis.readUTF());
- }
-
- ConfigurationRecoveryHandler.BridgeRecoveryHandler brh = lrh.brokerLink(id, createTime, arguments);
-
- recoverBridges(brh, id);
-
- }
- }
- catch (IOException e)
- {
- throw new SQLException(e.getMessage(), e);
- }
- finally
- {
- rs.close();
- }
- }
- finally
- {
- stmt.close();
- }
-
- }
- finally
- {
- if(conn != null)
- {
- conn.close();
- }
- }
-
- }
-
- private void recoverBridges(final ConfigurationRecoveryHandler.BridgeRecoveryHandler brh, final UUID linkId)
- throws SQLException
- {
- _logger.info("Recovering bridges for link " + linkId + "...");
-
- Connection conn = null;
- try
- {
- conn = newAutoCommitConnection();
-
- PreparedStatement stmt = conn.prepareStatement(SELECT_ALL_FROM_BRIDGES);
-
- try
- {
- stmt.setLong(1, linkId.getLeastSignificantBits());
- stmt.setLong(2, linkId.getMostSignificantBits());
-
- ResultSet rs = stmt.executeQuery();
-
- try
- {
-
- while(rs.next())
- {
- UUID id = new UUID(rs.getLong(2), rs.getLong(1));
- long createTime = rs.getLong(3);
- Blob argumentsAsBlob = rs.getBlob(6);
-
- byte[] dataAsBytes = argumentsAsBlob.getBytes(1,(int) argumentsAsBlob.length());
-
- DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dataAsBytes));
- int size = dis.readInt();
-
- Map<String,String> arguments = new HashMap<String, String>();
-
- for(int i = 0; i < size; i++)
- {
- arguments.put(dis.readUTF(), dis.readUTF());
- }
-
- brh.bridge(id, createTime, arguments);
-
- }
- brh.completeBridgeRecoveryForLink();
- }
- catch (IOException e)
- {
- throw new SQLException(e.getMessage(), e);
- }
- finally
- {
- rs.close();
- }
- }
- finally
- {
- stmt.close();
- }
-
- }
- finally
- {
- if(conn != null)
- {
- conn.close();
- }
- }
-
- }
-
@Override
public void close() throws Exception
{
@@ -975,71 +831,6 @@ public class DerbyMessageStore implements MessageStore
}
}
- @Override
- public void createBrokerLink(final BrokerLink link) throws AMQStoreException
- {
- _logger.debug("public void createBrokerLink(BrokerLink = " + link + "): called");
-
- if (_stateManager.isInState(State.ACTIVE))
- {
- try
- {
- Connection conn = newAutoCommitConnection();
-
- PreparedStatement stmt = conn.prepareStatement(FIND_LINK);
- try
- {
-
- stmt.setLong(1, link.getQMFId().getLeastSignificantBits());
- stmt.setLong(2, link.getQMFId().getMostSignificantBits());
- ResultSet rs = stmt.executeQuery();
- try
- {
-
- // If we don't have any data in the result set then we can add this queue
- if (!rs.next())
- {
- PreparedStatement insertStmt = conn.prepareStatement(INSERT_INTO_LINKS);
-
- try
- {
-
- insertStmt.setLong(1, link.getQMFId().getLeastSignificantBits());
- insertStmt.setLong(2, link.getQMFId().getMostSignificantBits());
- insertStmt.setLong(3, link.getCreateTime());
-
- byte[] argumentBytes = convertStringMapToBytes(link.getArguments());
- ByteArrayInputStream bis = new ByteArrayInputStream(argumentBytes);
-
- insertStmt.setBinaryStream(4,bis,argumentBytes.length);
-
- insertStmt.execute();
- }
- finally
- {
- insertStmt.close();
- }
- }
- }
- finally
- {
- rs.close();
- }
- }
- finally
- {
- stmt.close();
- }
- conn.close();
-
- }
- catch (SQLException e)
- {
- throw new AMQStoreException("Error writing " + link + " to database: " + e.getMessage(), e);
- }
- }
- }
-
private byte[] convertStringMapToBytes(final Map<String, String> arguments) throws AMQStoreException
{
byte[] argumentBytes;
@@ -1072,139 +863,7 @@ public class DerbyMessageStore implements MessageStore
return argumentBytes;
}
- @Override
- public void deleteBrokerLink(final BrokerLink link) throws AMQStoreException
- {
- _logger.debug("public void deleteBrokerLink( " + link + "): called");
- Connection conn = null;
- PreparedStatement stmt = null;
- try
- {
- conn = newAutoCommitConnection();
- stmt = conn.prepareStatement(DELETE_FROM_LINKS);
- stmt.setLong(1, link.getQMFId().getLeastSignificantBits());
- stmt.setLong(2, link.getQMFId().getMostSignificantBits());
- int results = stmt.executeUpdate();
-
- if (results == 0)
- {
- throw new AMQStoreException("Link " + link + " not found");
- }
- }
- catch (SQLException e)
- {
- throw new AMQStoreException("Error deleting Link " + link + " from database: " + e.getMessage(), e);
- }
- finally
- {
- closePreparedStatement(stmt);
- closeConnection(conn);
- }
-
-
- }
-
- @Override
- public void createBridge(final Bridge bridge) throws AMQStoreException
- {
- _logger.debug("public void createBridge(BrokerLink = " + bridge + "): called");
- if (_stateManager.isInState(State.ACTIVE))
- {
- try
- {
- Connection conn = newAutoCommitConnection();
-
- PreparedStatement stmt = conn.prepareStatement(FIND_BRIDGE);
- try
- {
-
- UUID id = bridge.getQMFId();
- stmt.setLong(1, id.getLeastSignificantBits());
- stmt.setLong(2, id.getMostSignificantBits());
- ResultSet rs = stmt.executeQuery();
- try
- {
-
- // If we don't have any data in the result set then we can add this queue
- if (!rs.next())
- {
- PreparedStatement insertStmt = conn.prepareStatement(INSERT_INTO_BRIDGES);
-
- try
- {
-
- insertStmt.setLong(1, id.getLeastSignificantBits());
- insertStmt.setLong(2, id.getMostSignificantBits());
-
- insertStmt.setLong(3, bridge.getCreateTime());
-
- UUID linkId = bridge.getLink().getQMFId();
- insertStmt.setLong(4, linkId.getLeastSignificantBits());
- insertStmt.setLong(5, linkId.getMostSignificantBits());
-
- byte[] argumentBytes = convertStringMapToBytes(bridge.getArguments());
- ByteArrayInputStream bis = new ByteArrayInputStream(argumentBytes);
-
- insertStmt.setBinaryStream(6,bis,argumentBytes.length);
-
- insertStmt.execute();
- }
- finally
- {
- insertStmt.close();
- }
- }
- }
- finally
- {
- rs.close();
- }
- }
- finally
- {
- stmt.close();
- }
- conn.close();
-
- }
- catch (SQLException e)
- {
- throw new AMQStoreException("Error writing " + bridge + " to database: " + e.getMessage(), e);
- }
- }
- }
-
- @Override
- public void deleteBridge(final Bridge bridge) throws AMQStoreException
- {
- _logger.debug("public void deleteBridge( " + bridge + "): called");
- Connection conn = null;
- PreparedStatement stmt = null;
- try
- {
- conn = newAutoCommitConnection();
- stmt = conn.prepareStatement(DELETE_FROM_BRIDGES);
- stmt.setLong(1, bridge.getQMFId().getLeastSignificantBits());
- stmt.setLong(2, bridge.getQMFId().getMostSignificantBits());
- int results = stmt.executeUpdate();
-
- if (results == 0)
- {
- throw new AMQStoreException("Bridge " + bridge + " not found");
- }
- }
- catch (SQLException e)
- {
- throw new AMQStoreException("Error deleting bridge " + bridge + " from database: " + e.getMessage(), e);
- }
- finally
- {
- closePreparedStatement(stmt);
- closeConnection(conn);
- }
-
- }
@Override
public Transaction newTransaction()
@@ -2134,8 +1793,9 @@ public class DerbyMessageStore implements MessageStore
public ByteBuffer getContent(int offsetInMessage, int size)
{
ByteBuffer buf = ByteBuffer.allocate(size);
- getContent(offsetInMessage, buf);
+ int length = getContent(offsetInMessage, buf);
buf.position(0);
+ buf.limit(length);
return buf;
}
@@ -2673,7 +2333,7 @@ public class DerbyMessageStore implements MessageStore
@Override
public String getStoreType()
{
- return DERBY_STORE_TYPE;
+ return TYPE;
}
} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java b/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java
new file mode 100644
index 0000000000..046b503d8a
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/store/derby/DerbyMessageStoreFactory.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.store.derby;
+
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreFactory;
+
+public class DerbyMessageStoreFactory implements MessageStoreFactory
+{
+
+ @Override
+ public String getType()
+ {
+ return DerbyMessageStore.TYPE;
+ }
+
+ @Override
+ public MessageStore createMessageStore()
+ {
+ return new DerbyMessageStore();
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java b/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java
index c92853e400..6c5cb2e721 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionImpl.java
@@ -27,11 +27,6 @@ import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.SessionConfig;
-import org.apache.qpid.server.configuration.SubscriptionConfig;
-import org.apache.qpid.server.configuration.SubscriptionConfigType;
import org.apache.qpid.server.filter.FilterManager;
import org.apache.qpid.server.filter.FilterManagerFactory;
import org.apache.qpid.server.flow.FlowCreditManager;
@@ -61,8 +56,7 @@ import java.util.concurrent.locks.ReentrantLock;
* Encapsulation of a supscription to a queue. <p/> Ties together the protocol session of a subscriber, the consumer tag
* that was given out by the broker and the channel id. <p/>
*/
-public abstract class SubscriptionImpl implements Subscription, FlowCreditManager.FlowCreditManagerListener,
- SubscriptionConfig
+public abstract class SubscriptionImpl implements Subscription, FlowCreditManager.FlowCreditManagerListener
{
private StateListener _stateListener = new StateListener()
@@ -91,7 +85,6 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage
private final long _subscriptionID;
private LogSubject _logSubject;
private LogActor _logActor;
- private UUID _qmfId;
private final AtomicLong _deliveredCount = new AtomicLong(0);
private final AtomicLong _deliveredBytes = new AtomicLong(0);
@@ -373,11 +366,6 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage
return _channel;
}
- public ConfigStore getConfigStore()
- {
- return getQueue().getConfigStore();
- }
-
public Long getDelivered()
{
return _deliveredCount.get();
@@ -391,9 +379,6 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage
}
_queue = queue;
- _qmfId = getConfigStore().createId();
- getConfigStore().addConfiguredObject(this);
-
_logSubject = new SubscriptionLogSubject(this);
_logActor = new SubscriptionActor(CurrentActor.get().getRootMessageLogger(), this);
@@ -547,8 +532,6 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage
{
_stateChangeLock.unlock();
}
- getConfigStore().removeConfiguredObject(this);
-
//Log Subscription closed
CurrentActor.get().message(_logSubject, SubscriptionMessages.CLOSE());
}
@@ -752,11 +735,6 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage
return "WINDOW";
}
- public SessionConfig getSessionConfig()
- {
- return getChannel();
- }
-
public boolean isBrowsing()
{
return isBrowser();
@@ -767,32 +745,16 @@ public abstract class SubscriptionImpl implements Subscription, FlowCreditManage
return true;
}
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
public boolean isDurable()
{
return false;
}
- public SubscriptionConfigType getConfigType()
- {
- return SubscriptionConfigType.getInstance();
- }
-
public boolean isExclusive()
{
return getQueue().hasExclusiveSubscriber();
}
- public ConfiguredObject getParent()
- {
- return getSessionConfig();
- }
-
public String getName()
{
return String.valueOf(_consumerTag);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java b/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java
index dfd9315226..b9bba49fab 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java
@@ -24,11 +24,6 @@ import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.BasicContentHeaderProperties;
import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.SessionConfig;
-import org.apache.qpid.server.configuration.SubscriptionConfig;
-import org.apache.qpid.server.configuration.SubscriptionConfigType;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.filter.FilterManager;
import org.apache.qpid.server.flow.CreditCreditManager;
@@ -86,7 +81,7 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
-public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCreditManagerListener, SubscriptionConfig, LogSubject
+public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCreditManagerListener, LogSubject
{
private final long _subscriptionID;
@@ -125,7 +120,6 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
private LogActor _logActor;
private final Map<String, Object> _properties = new ConcurrentHashMap<String, Object>();
- private UUID _qmfId;
private String _traceExclude;
private String _trace;
private final long _createTime = System.currentTimeMillis();
@@ -192,8 +186,6 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
Map<String, Object> arguments = queue.getArguments();
_traceExclude = (String) arguments.get("qpid.trace.exclude");
_trace = (String) arguments.get("qpid.trace.id");
- _qmfId = getConfigStore().createId();
- getConfigStore().addConfiguredObject(this);
String filterLogString = null;
_logActor = GenericActor.getInstance(this);
@@ -283,7 +275,6 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
}
}
_creditManager.removeListener(this);
- getConfigStore().removeConfiguredObject(this);
CurrentActor.get().message(getLogSubject(), SubscriptionMessages.CLOSE());
}
finally
@@ -295,11 +286,6 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
}
- public ConfigStore getConfigStore()
- {
- return getQueue().getConfigStore();
- }
-
public Long getDelivered()
{
return _deliveredCount.get();
@@ -970,12 +956,6 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
return _session;
}
-
- public SessionConfig getSessionConfig()
- {
- return getSessionModel();
- }
-
public boolean isBrowsing()
{
return _acquireMode == MessageAcquireMode.NOT_ACQUIRED;
@@ -986,20 +966,11 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
return getQueue().hasExclusiveSubscriber();
}
- public ConfiguredObject getParent()
- {
- return getSessionConfig();
- }
-
public boolean isDurable()
{
return false;
}
- public SubscriptionConfigType getConfigType()
- {
- return SubscriptionConfigType.getInstance();
- }
public boolean isExplicitAcknowledge()
{
@@ -1011,12 +982,6 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
return _flowMode.toString();
}
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
public String getName()
{
return _destination;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java b/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java
deleted file mode 100644
index 7c4188bfcd..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java
+++ /dev/null
@@ -1,81 +0,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.
- *
- */
-package org.apache.qpid.server.transport;
-
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.transport.network.NetworkTransport;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-public class QpidAcceptor
-{
- public enum Transport
- {
- TCP("TCP"),
- SSL("TCP/SSL");
-
- private final String _asString;
-
- Transport(String asString)
- {
- _asString = asString;
- }
-
- public String toString()
- {
- return _asString;
- }
- }
-
- private NetworkTransport _networkTransport;
- private Transport _transport;
- private Set<AmqpProtocolVersion> _supported;
-
-
- public QpidAcceptor(NetworkTransport transport, Transport protocol, Set<AmqpProtocolVersion> supported)
- {
- _networkTransport = transport;
- _transport = protocol;
- _supported = Collections.unmodifiableSet(new HashSet<AmqpProtocolVersion>(supported));
- }
-
- public NetworkTransport getNetworkTransport()
- {
- return _networkTransport;
- }
-
- public Transport getTransport()
- {
- return _transport;
- }
-
- public Set<AmqpProtocolVersion> getSupported()
- {
- return _supported;
- }
-
- public String toString()
- {
- return _transport.toString();
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java b/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java
index f21026794f..58de6a0cdf 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnection.java
@@ -20,17 +20,16 @@
*/
package org.apache.qpid.server.transport;
+import java.net.SocketAddress;
import java.security.Principal;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
-import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import javax.security.auth.Subject;
import org.apache.qpid.AMQException;
import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.server.configuration.ConnectionConfig;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.actors.CurrentActor;
@@ -39,6 +38,7 @@ import org.apache.qpid.server.logging.messages.ConnectionMessages;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.security.AuthorizationHolder;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.Connection;
@@ -48,6 +48,7 @@ import org.apache.qpid.transport.ExecutionException;
import org.apache.qpid.transport.Method;
import org.apache.qpid.transport.ProtocolEvent;
import org.apache.qpid.transport.Session;
+import org.apache.qpid.transport.network.NetworkConnection;
import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.CONNECTION_FORMAT;
import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.SOCKET_FORMAT;
@@ -55,7 +56,6 @@ import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.USER_FORM
public class ServerConnection extends Connection implements AMQConnectionModel, LogSubject, AuthorizationHolder
{
- private ConnectionConfig _config;
private Runnable _onOpenTask;
private AtomicBoolean _logClosed = new AtomicBoolean(false);
private LogActor _actor = GenericActor.getInstance(this);
@@ -69,6 +69,7 @@ public class ServerConnection extends Connection implements AMQConnectionModel,
private AtomicLong _lastIoTime = new AtomicLong();
private boolean _blocking;
private Principal _peerPrincipal;
+ private NetworkConnection _networkConnection;
public ServerConnection(final long connectionId)
{
@@ -147,16 +148,6 @@ public class ServerConnection extends Connection implements AMQConnectionModel,
initialiseStatistics();
}
- public void setConnectionConfig(final ConnectionConfig config)
- {
- _config = config;
- }
-
- public ConnectionConfig getConfig()
- {
- return _config;
- }
-
public void onOpen(final Runnable task)
{
_onOpenTask = task;
@@ -228,7 +219,7 @@ public class ServerConnection extends Connection implements AMQConnectionModel,
MessageFormat.format(CONNECTION_FORMAT,
getConnectionId(),
getClientId(),
- getConfig().getAddress(),
+ getRemoteAddressString(),
getVirtualHost().getName())
+ "] ";
}
@@ -238,7 +229,7 @@ public class ServerConnection extends Connection implements AMQConnectionModel,
MessageFormat.format(USER_FORMAT,
getConnectionId(),
getClientId(),
- getConfig().getAddress())
+ getRemoteAddressString())
+ "] ";
}
@@ -247,7 +238,7 @@ public class ServerConnection extends Connection implements AMQConnectionModel,
return "[" +
MessageFormat.format(SOCKET_FORMAT,
getConnectionId(),
- getConfig().getAddress())
+ getRemoteAddressString())
+ "] ";
}
}
@@ -396,7 +387,7 @@ public class ServerConnection extends Connection implements AMQConnectionModel,
else
{
_authorizedSubject = authorizedSubject;
- _authorizedPrincipal = authorizedSubject.getPrincipals().iterator().next();
+ _authorizedPrincipal = AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(authorizedSubject);
}
}
@@ -417,7 +408,7 @@ public class ServerConnection extends Connection implements AMQConnectionModel,
public String getRemoteAddressString()
{
- return getConfig().getAddress();
+ return String.valueOf(getRemoteAddress());
}
public String getUserName()
@@ -489,4 +480,32 @@ public class ServerConnection extends Connection implements AMQConnectionModel,
{
_peerPrincipal = peerPrincipal;
}
+
+ @Override
+ public void setRemoteAddress(SocketAddress remoteAddress)
+ {
+ super.setRemoteAddress(remoteAddress);
+ }
+
+ @Override
+ public void setLocalAddress(SocketAddress localAddress)
+ {
+ super.setLocalAddress(localAddress);
+ }
+
+ public void setNetworkConnection(NetworkConnection network)
+ {
+ _networkConnection = network;
+ }
+
+ public NetworkConnection getNetworkConnection()
+ {
+ return _networkConnection;
+ }
+
+ public void doHeartbeat()
+ {
+ super.doHeartBeat();
+
+ }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java b/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java
index c13f63b44d..f3153fde62 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java
@@ -32,18 +32,19 @@ import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
import org.apache.qpid.common.ServerPropertyNames;
import org.apache.qpid.properties.ConnectionStartProperties;
-import org.apache.qpid.protocol.ProtocolEngine;
-import org.apache.qpid.server.configuration.BrokerConfig;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQConnectionModel;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
-import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
import org.apache.qpid.server.subscription.Subscription_0_10;
import org.apache.qpid.server.virtualhost.State;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.*;
+import org.apache.qpid.transport.network.NetworkConnection;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,36 +54,49 @@ public class ServerConnectionDelegate extends ServerDelegate
{
private static final Logger LOGGER = LoggerFactory.getLogger(ServerConnectionDelegate.class);
+ private final Broker _broker;
private final String _localFQDN;
- private final IApplicationRegistry _appRegistry;
private int _maxNoOfChannels;
private Map<String,Object> _clientProperties;
- private final AuthenticationManager _authManager;
+ private final SubjectCreator _subjectCreator;
- public ServerConnectionDelegate(IApplicationRegistry appRegistry, String localFQDN, AuthenticationManager authManager)
+ public ServerConnectionDelegate(Broker broker, String localFQDN, SubjectCreator subjectCreator)
{
- this(createConnectionProperties(appRegistry.getBrokerConfig()), Collections.singletonList((Object)"en_US"), appRegistry, localFQDN, authManager);
+ this(createConnectionProperties(broker), Collections.singletonList((Object)"en_US"), broker, localFQDN, subjectCreator);
}
private ServerConnectionDelegate(Map<String, Object> properties,
List<Object> locales,
- IApplicationRegistry appRegistry,
+ Broker broker,
String localFQDN,
- AuthenticationManager authManager)
+ SubjectCreator subjectCreator)
{
- super(properties, parseToList(authManager.getMechanisms()), locales);
+ super(properties, parseToList(subjectCreator.getMechanisms()), locales);
- _appRegistry = appRegistry;
+ _broker = broker;
_localFQDN = localFQDN;
- _maxNoOfChannels = appRegistry.getConfiguration().getMaxChannelCount();
- _authManager = authManager;
+ _maxNoOfChannels = (Integer)broker.getAttribute(Broker.SESSION_COUNT_LIMIT);
+ _subjectCreator = subjectCreator;
+ }
+
+ private static List<String> getFeatures(Broker broker)
+ {
+ String brokerDisabledFeatures = System.getProperty(BrokerProperties.PROPERTY_DISABLED_FEATURES);
+ final List<String> features = new ArrayList<String>();
+ if (brokerDisabledFeatures == null || !brokerDisabledFeatures.contains(ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR))
+ {
+ features.add(ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR);
+ }
+
+ return Collections.unmodifiableList(features);
}
- private static Map<String, Object> createConnectionProperties(final BrokerConfig brokerConfig)
+ private static Map<String, Object> createConnectionProperties(final Broker broker)
{
final Map<String,Object> map = new HashMap<String,Object>(2);
- map.put(ServerPropertyNames.FEDERATION_TAG, brokerConfig.getFederationTag());
- final List<String> features = brokerConfig.getFeatures();
+ // Federation tag is used by the client to identify the broker instance
+ map.put(ServerPropertyNames.FEDERATION_TAG, broker.getId().toString());
+ final List<String> features = getFeatures(broker);
if (features != null && features.size() > 0)
{
map.put(ServerPropertyNames.QPID_FEATURES, features);
@@ -112,14 +126,14 @@ public class ServerConnectionDelegate extends ServerDelegate
protected SaslServer createSaslServer(Connection conn, String mechanism) throws SaslException
{
- return _authManager.createSaslServer(mechanism, _localFQDN, ((ServerConnection) conn).getPeerPrincipal());
+ return _subjectCreator.createSaslServer(mechanism, _localFQDN, ((ServerConnection) conn).getPeerPrincipal());
}
protected void secure(final SaslServer ss, final Connection conn, final byte[] response)
{
final ServerConnection sconn = (ServerConnection) conn;
- final AuthenticationResult authResult = _authManager.authenticate(ss, response);
+ final SubjectAuthenticationResult authResult = _subjectCreator.authenticate(ss, response);
if (AuthenticationStatus.SUCCESS.equals(authResult.getStatus()))
{
@@ -166,7 +180,7 @@ public class ServerConnectionDelegate extends ServerDelegate
{
vhostName = "";
}
- vhost = _appRegistry.getVirtualHostRegistry().getVirtualHost(vhostName);
+ vhost = _broker.getVirtualHostRegistry().getVirtualHost(vhostName);
SecurityManager.setThreadSubject(sconn.getAuthorizedSubject());
@@ -174,7 +188,7 @@ public class ServerConnectionDelegate extends ServerDelegate
{
sconn.setVirtualHost(vhost);
- if (!vhost.getSecurityManager().accessVirtualhost(vhostName, ((ProtocolEngine) sconn.getConfig()).getRemoteAddress()))
+ if (!vhost.getSecurityManager().accessVirtualhost(vhostName, sconn.getRemoteAddress()))
{
sconn.setState(Connection.State.CLOSING);
sconn.invoke(new ConnectionClose(ConnectionCloseCode.CONNECTION_FORCED, "Permission denied '"+vhostName+"'"));
@@ -215,14 +229,18 @@ public class ServerConnectionDelegate extends ServerDelegate
return;
}
- setConnectionTuneOkChannelMax(sconn, okChannelMax);
- }
+ if(ok.hasHeartbeat())
+ {
+ final int heartbeat = ok.getHeartbeat();
+ if(heartbeat > 0)
+ {
+ final NetworkConnection networkConnection = sconn.getNetworkConnection();
+ networkConnection.setMaxReadIdle(2 * heartbeat);
+ networkConnection.setMaxWriteIdle(heartbeat);
+ }
+ }
- @Override
- protected int getHeartbeatMax()
- {
- //TODO: implement broker support for actually sending heartbeats
- return 0;
+ setConnectionTuneOkChannelMax(sconn, okChannelMax);
}
@Override
diff --git a/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java b/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java
index f82b25b3d6..6152ddd228 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java
@@ -42,13 +42,8 @@ import javax.security.auth.Subject;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQStoreException;
import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.protocol.ProtocolEngine;
import org.apache.qpid.server.TransactionTimeoutHelper;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.ConnectionConfig;
-import org.apache.qpid.server.configuration.SessionConfig;
-import org.apache.qpid.server.configuration.SessionConfigType;
+import org.apache.qpid.server.TransactionTimeoutHelper.CloseAction;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.actors.CurrentActor;
@@ -91,7 +86,7 @@ import static org.apache.qpid.server.logging.subjects.LogSubjectFormat.CHANNEL_F
import static org.apache.qpid.util.Serial.gt;
public class ServerSession extends Session
- implements AuthorizationHolder, SessionConfig,
+ implements AuthorizationHolder,
AMQSessionModel, LogSubject, AsyncAutoCommitTransaction.FutureRecorder
{
private static final Logger _logger = LoggerFactory.getLogger(ServerSession.class);
@@ -100,8 +95,7 @@ public class ServerSession extends Session
private static final int PRODUCER_CREDIT_TOPUP_THRESHOLD = 1 << 30;
private static final int UNFINISHED_COMMAND_QUEUE_THRESHOLD = 500;
- private final UUID _id;
- private ConnectionConfig _connectionConfig;
+ private final UUID _id = UUID.randomUUID();
private long _createTime = System.currentTimeMillis();
private LogActor _actor = GenericActor.getInstance(this);
@@ -139,7 +133,6 @@ public class ServerSession extends Session
private final AtomicLong _txnCommits = new AtomicLong(0);
private final AtomicLong _txnRejects = new AtomicLong(0);
private final AtomicLong _txnCount = new AtomicLong(0);
- private final AtomicLong _txnUpdateTime = new AtomicLong(0);
private Map<String, Subscription_0_10> _subscriptions = new ConcurrentHashMap<String, Subscription_0_10>();
@@ -147,21 +140,21 @@ public class ServerSession extends Session
private final TransactionTimeoutHelper _transactionTimeoutHelper;
- ServerSession(Connection connection, SessionDelegate delegate, Binary name, long expiry)
- {
- this(connection, delegate, name, expiry, ((ServerConnection)connection).getConfig());
- }
- public ServerSession(Connection connection, SessionDelegate delegate, Binary name, long expiry, ConnectionConfig connConfig)
+ public ServerSession(Connection connection, SessionDelegate delegate, Binary name, long expiry)
{
super(connection, delegate, name, expiry);
- _connectionConfig = connConfig;
_transaction = new AsyncAutoCommitTransaction(this.getMessageStore(),this);
_logSubject = new ChannelLogSubject(this);
- _id = getConfigStore().createId();
- getConfigStore().addConfiguredObject(this);
- _transactionTimeoutHelper = new TransactionTimeoutHelper(_logSubject);
+ _transactionTimeoutHelper = new TransactionTimeoutHelper(_logSubject, new CloseAction()
+ {
+ @Override
+ public void doTimeoutAction(String reason) throws AMQException
+ {
+ getConnectionModel().closeSession(ServerSession.this, AMQConstant.RESOURCE_ERROR, reason);
+ }
+ });
}
protected void setState(State state)
@@ -184,12 +177,6 @@ public class ServerSession extends Session
invoke(new MessageStop(""));
}
- private ConfigStore getConfigStore()
- {
- return getConnectionConfig().getConfigStore();
- }
-
-
@Override
protected boolean isFull(int id)
{
@@ -206,9 +193,8 @@ public class ServerSession extends Session
}
getConnectionModel().registerMessageReceived(message.getSize(), message.getArrivalTime());
PostEnqueueAction postTransactionAction = new PostEnqueueAction(queues, message, isTransactional()) ;
- _transaction.enqueue(queues,message, postTransactionAction, 0L);
+ _transaction.enqueue(queues,message, postTransactionAction);
incrementOutstandingTxnsIfNecessary();
- updateTransactionalActivity();
}
@@ -389,8 +375,6 @@ public class ServerSession extends Session
}
_messageDispositionListenerMap.clear();
- getConfigStore().removeConfiguredObject(this);
-
for (Task task : _taskList)
{
task.doTask(this);
@@ -424,7 +408,6 @@ public class ServerSession extends Session
entry.release();
}
});
- updateTransactionalActivity();
}
public Collection<Subscription_0_10> getSubscriptions()
@@ -470,11 +453,6 @@ public class ServerSession extends Session
return _transaction.isTransactional();
}
- public boolean inTransaction()
- {
- return isTransactional() && _txnUpdateTime.get() > 0 && _transaction.getTransactionStartTime() > 0;
- }
-
public void selectTx()
{
_transaction = new LocalTransaction(this.getMessageStore());
@@ -609,22 +587,6 @@ public class ServerSession extends Session
}
}
- /**
- * Update last transaction activity timestamp
- */
- public void updateTransactionalActivity()
- {
- if (isTransactional())
- {
- _txnUpdateTime.set(System.currentTimeMillis());
- }
- }
-
- public Long getTxnStarts()
- {
- return _txnStarts.get();
- }
-
public Long getTxnCommits()
{
return _txnCommits.get();
@@ -682,23 +644,7 @@ public class ServerSession extends Session
public VirtualHost getVirtualHost()
{
- return (VirtualHost) _connectionConfig.getVirtualHost();
- }
-
- @Override
- public UUID getQMFId()
- {
- return _id;
- }
-
- public SessionConfigType getConfigType()
- {
- return SessionConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return getVirtualHost();
+ return getConnection().getVirtualHost();
}
public boolean isDurable()
@@ -706,44 +652,16 @@ public class ServerSession extends Session
return false;
}
- public boolean isAttached()
- {
- return true;
- }
-
- public long getDetachedLifespan()
- {
- return 0;
- }
-
- public Long getExpiryTime()
- {
- return null;
- }
-
- public Long getMaxClientRate()
- {
- return null;
- }
-
- public ConnectionConfig getConnectionConfig()
- {
- return _connectionConfig;
- }
-
- public String getSessionName()
- {
- return getName().toString();
- }
public long getCreateTime()
{
return _createTime;
}
- public void mgmtClose()
+ @Override
+ public UUID getId()
{
- close();
+ return _id;
}
public AMQConnectionModel getConnectionModel()
@@ -774,28 +692,7 @@ public class ServerSession extends Session
public void checkTransactionStatus(long openWarn, long openClose, long idleWarn, long idleClose) throws AMQException
{
- if (inTransaction())
- {
- long currentTime = System.currentTimeMillis();
- long openTime = currentTime - _transaction.getTransactionStartTime();
- long idleTime = currentTime - _txnUpdateTime.get();
-
- _transactionTimeoutHelper.logIfNecessary(idleTime, idleWarn, ChannelMessages.IDLE_TXN(idleTime),
- TransactionTimeoutHelper.IDLE_TRANSACTION_ALERT);
- if (_transactionTimeoutHelper.isTimedOut(idleTime, idleClose))
- {
- getConnectionModel().closeSession(this, AMQConstant.RESOURCE_ERROR, "Idle transaction timed out");
- return;
- }
-
- _transactionTimeoutHelper.logIfNecessary(openTime, openWarn, ChannelMessages.OPEN_TXN(openTime),
- TransactionTimeoutHelper.OPEN_TRANSACTION_ALERT);
- if (_transactionTimeoutHelper.isTimedOut(openTime, openClose))
- {
- getConnectionModel().closeSession(this, AMQConstant.RESOURCE_ERROR, "Open transaction timed out");
- return;
- }
- }
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, openWarn, openClose, idleWarn, idleClose);
}
public void block(AMQQueue queue)
@@ -878,9 +775,7 @@ public class ServerSession extends Session
? getConnection().getConnectionId()
: -1;
- String remoteAddress = _connectionConfig instanceof ProtocolEngine
- ? ((ProtocolEngine) _connectionConfig).getRemoteAddress().toString()
- : "";
+ String remoteAddress = String.valueOf(getConnection().getRemoteAddress());
return "[" +
MessageFormat.format(CHANNEL_FORMAT,
connectionId,
@@ -1065,14 +960,16 @@ public class ServerSession extends Session
super.setClose(close);
}
- public int compareTo(AMQSessionModel session)
+ @Override
+ public int getConsumerCount()
{
- return getQMFId().compareTo(session.getQMFId());
+ return _subscriptions.values().size();
}
@Override
- public int getConsumerCount()
+ public int compareTo(AMQSessionModel o)
{
- return _subscriptions.values().size();
+ return getId().compareTo(o.getId());
}
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java b/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java
index 05963ee874..d83bd1c4dc 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java
@@ -31,7 +31,6 @@ import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeFactory;
import org.apache.qpid.server.exchange.ExchangeInUseException;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.exchange.ExchangeType;
import org.apache.qpid.server.exchange.HeadersExchange;
import org.apache.qpid.server.filter.FilterManager;
import org.apache.qpid.server.filter.FilterManagerFactory;
@@ -41,11 +40,11 @@ import org.apache.qpid.server.logging.messages.ExchangeMessages;
import org.apache.qpid.server.message.MessageMetaData_0_10;
import org.apache.qpid.server.message.MessageTransferMessage;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.store.MessageStore;
@@ -1266,18 +1265,12 @@ public class ServerSessionDelegate extends SessionDelegate
}
}
queueRegistry.registerQueue(queue);
- boolean autoRegister = ApplicationRegistry.getInstance().getConfiguration().getQueueAutoRegister();
- if (autoRegister)
- {
-
- ExchangeRegistry exchangeRegistry = getExchangeRegistry(session);
+ ExchangeRegistry exchangeRegistry = getExchangeRegistry(session);
- Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
+ Exchange defaultExchange = exchangeRegistry.getDefaultExchange();
- virtualHost.getBindingFactory().addBinding(queueName, queue, defaultExchange, null);
-
- }
+ virtualHost.getBindingFactory().addBinding(queueName, queue, defaultExchange, null);
if (method.hasAutoDelete()
&& method.getAutoDelete()
diff --git a/java/broker/src/main/java/org/apache/qpid/server/txn/AsyncAutoCommitTransaction.java b/java/broker/src/main/java/org/apache/qpid/server/txn/AsyncAutoCommitTransaction.java
index efd7850a49..43e60c8e13 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/txn/AsyncAutoCommitTransaction.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/txn/AsyncAutoCommitTransaction.java
@@ -66,11 +66,18 @@ public class AsyncAutoCommitTransaction implements ServerTransaction
_futureRecorder = recorder;
}
+ @Override
public long getTransactionStartTime()
{
return 0L;
}
+ @Override
+ public long getTransactionUpdateTime()
+ {
+ return 0L;
+ }
+
/**
* Since AutoCommitTransaction have no concept of a long lived transaction, any Actions registered
* by the caller are executed immediately.
@@ -241,7 +248,7 @@ public class AsyncAutoCommitTransaction implements ServerTransaction
}
- public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction, long currentTime)
+ public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction)
{
Transaction txn = null;
try
diff --git a/java/broker/src/main/java/org/apache/qpid/server/txn/AutoCommitTransaction.java b/java/broker/src/main/java/org/apache/qpid/server/txn/AutoCommitTransaction.java
index e5a7df6880..8a9479a2d4 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/txn/AutoCommitTransaction.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/txn/AutoCommitTransaction.java
@@ -52,11 +52,18 @@ public class AutoCommitTransaction implements ServerTransaction
_messageStore = transactionLog;
}
+ @Override
public long getTransactionStartTime()
{
return 0L;
}
+ @Override
+ public long getTransactionUpdateTime()
+ {
+ return 0L;
+ }
+
/**
* Since AutoCommitTransaction have no concept of a long lived transaction, any Actions registered
* by the caller are executed immediately.
@@ -178,7 +185,7 @@ public class AutoCommitTransaction implements ServerTransaction
}
- public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction, long currentTime)
+ public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction)
{
Transaction txn = null;
try
@@ -270,4 +277,6 @@ public class AutoCommitTransaction implements ServerTransaction
}
}
+
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/txn/DistributedTransaction.java b/java/broker/src/main/java/org/apache/qpid/server/txn/DistributedTransaction.java
index 05d0110e9b..ab987f0fb9 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/txn/DistributedTransaction.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/txn/DistributedTransaction.java
@@ -26,7 +26,6 @@ import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.QueueEntry;
import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.Transaction;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.Xid;
@@ -39,10 +38,6 @@ public class DistributedTransaction implements ServerTransaction
private final AutoCommitTransaction _autoCommitTransaction;
- private volatile Transaction _transaction;
-
- private long _txnStartTime = 0L;
-
private DtxBranch _branch;
private AMQSessionModel _session;
private VirtualHost _vhost;
@@ -55,9 +50,16 @@ public class DistributedTransaction implements ServerTransaction
_autoCommitTransaction = new AutoCommitTransaction(vhost.getMessageStore());
}
+ @Override
public long getTransactionStartTime()
{
- return _txnStartTime;
+ return 0;
+ }
+
+ @Override
+ public long getTransactionUpdateTime()
+ {
+ return 0;
}
public void addPostTransactionAction(Action postTransactionAction)
@@ -107,7 +109,7 @@ public class DistributedTransaction implements ServerTransaction
{
_branch.enqueue(queue, message);
_branch.addPostTransactionAcion(postTransactionAction);
- enqueue(Collections.singletonList(queue), message, postTransactionAction, System.currentTimeMillis());
+ enqueue(Collections.singletonList(queue), message, postTransactionAction);
}
else
{
@@ -116,7 +118,7 @@ public class DistributedTransaction implements ServerTransaction
}
public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message,
- Action postTransactionAction, long currentTime)
+ Action postTransactionAction)
{
if(_branch != null)
{
@@ -128,7 +130,7 @@ public class DistributedTransaction implements ServerTransaction
}
else
{
- _autoCommitTransaction.enqueue(queues, message, postTransactionAction, currentTime);
+ _autoCommitTransaction.enqueue(queues, message, postTransactionAction);
}
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/txn/LocalTransaction.java b/java/broker/src/main/java/org/apache/qpid/server/txn/LocalTransaction.java
index 3fbcff7e2c..afa7cb0fb4 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/txn/LocalTransaction.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/txn/LocalTransaction.java
@@ -49,25 +49,42 @@ public class LocalTransaction implements ServerTransaction
private final List<Action> _postTransactionActions = new ArrayList<Action>();
private volatile Transaction _transaction;
- private MessageStore _transactionLog;
- private long _txnStartTime = 0L;
+ private final ActivityTimeAccessor _activityTime;
+ private final MessageStore _transactionLog;
+ private volatile long _txnStartTime = 0L;
+ private volatile long _txnUpdateTime = 0l;
private StoreFuture _asyncTran;
public LocalTransaction(MessageStore transactionLog)
{
- _transactionLog = transactionLog;
+ this(transactionLog, new ActivityTimeAccessor()
+ {
+ @Override
+ public long getActivityTime()
+ {
+ return System.currentTimeMillis();
+ }
+ });
}
-
- public boolean inTransaction()
+
+ public LocalTransaction(MessageStore transactionLog, ActivityTimeAccessor activityTime)
{
- return _transaction != null;
+ _transactionLog = transactionLog;
+ _activityTime = activityTime;
}
+ @Override
public long getTransactionStartTime()
{
return _txnStartTime;
}
+ @Override
+ public long getTransactionUpdateTime()
+ {
+ return _txnUpdateTime;
+ }
+
public void addPostTransactionAction(Action postTransactionAction)
{
sync();
@@ -78,6 +95,7 @@ public class LocalTransaction implements ServerTransaction
{
sync();
_postTransactionActions.add(postTransactionAction);
+ initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();
if(message.isPersistent() && queue.isDurable())
{
@@ -104,6 +122,7 @@ public class LocalTransaction implements ServerTransaction
{
sync();
_postTransactionActions.add(postTransactionAction);
+ initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();
try
{
@@ -180,6 +199,7 @@ public class LocalTransaction implements ServerTransaction
{
sync();
_postTransactionActions.add(postTransactionAction);
+ initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();
if(message.isPersistent() && queue.isDurable())
{
@@ -189,7 +209,7 @@ public class LocalTransaction implements ServerTransaction
{
_logger.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getNameShortString());
}
-
+
beginTranIfNecessary();
_transaction.enqueueMessage(queue, message);
}
@@ -202,15 +222,11 @@ public class LocalTransaction implements ServerTransaction
}
}
- public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction, long currentTime)
+ public void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction)
{
sync();
_postTransactionActions.add(postTransactionAction);
-
- if (_txnStartTime == 0L)
- {
- _txnStartTime = currentTime == 0L ? System.currentTimeMillis() : currentTime;
- }
+ initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();
if(message.isPersistent())
{
@@ -224,8 +240,7 @@ public class LocalTransaction implements ServerTransaction
{
_logger.debug("Enqueue of message number " + message.getMessageNumber() + " to transaction log. Queue : " + queue.getNameShortString() );
}
-
-
+
beginTranIfNecessary();
_transaction.enqueueMessage(queue, message);
}
@@ -378,16 +393,24 @@ public class LocalTransaction implements ServerTransaction
}
throw new RuntimeException("Failed to commit transaction", e);
}
-
-
}
private void doPostTransactionActions()
{
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Beginning " + _postTransactionActions.size() + " post transaction actions");
+ }
+
for(int i = 0; i < _postTransactionActions.size(); i++)
{
_postTransactionActions.get(i).postCommit();
}
+
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Completed post transaction actions");
+ }
}
public void rollback()
@@ -427,16 +450,34 @@ public class LocalTransaction implements ServerTransaction
}
}
+ private void initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime()
+ {
+ long currentTime = _activityTime.getActivityTime();
+
+ if (_txnStartTime == 0)
+ {
+ _txnStartTime = currentTime;
+ }
+ _txnUpdateTime = currentTime;
+ }
+
private void resetDetails()
{
_asyncTran = null;
_transaction = null;
- _postTransactionActions.clear();
+ _postTransactionActions.clear();
_txnStartTime = 0L;
+ _txnUpdateTime = 0;
}
public boolean isTransactional()
{
return true;
}
+
+ public interface ActivityTimeAccessor
+ {
+ long getActivityTime();
+ }
+
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java b/java/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java
index c568ae67aa..8acac00479 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java
@@ -55,11 +55,18 @@ public interface ServerTransaction
/**
* Return the time the current transaction started.
- *
+ *
* @return the time this transaction started or 0 if not in a transaction
*/
long getTransactionStartTime();
+ /**
+ * Return the time of the last activity on the current transaction.
+ *
+ * @return the time of the last activity or 0 if not in a transaction
+ */
+ long getTransactionUpdateTime();
+
/**
* Register an Action for execution after transaction commit or rollback. Actions
* will be executed in the order in which they are registered.
@@ -92,7 +99,7 @@ public interface ServerTransaction
*
* Store operations will result only for a persistent messages on durable queues.
*/
- void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction, long currentTime);
+ void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction);
/**
* Commit the transaction represented by this object.
diff --git a/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java b/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
new file mode 100644
index 0000000000..aa7b4afcae
--- /dev/null
+++ b/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
@@ -0,0 +1,361 @@
+/*
+ *
+ * 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.util;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class MapValueConverter
+{
+
+ public static String getStringAttribute(String name, Map<String,Object> attributes, String defaultVal)
+ {
+ final Object value = attributes.get(name);
+ return toString(value, defaultVal);
+ }
+
+ public static String toString(final Object value)
+ {
+ return toString(value, null);
+ }
+
+ public static String toString(final Object value, String defaultVal)
+ {
+ if (value == null)
+ {
+ return defaultVal;
+ }
+ else if (value instanceof String)
+ {
+ return (String)value;
+ }
+ return String.valueOf(value);
+ }
+
+ public static String getStringAttribute(String name, Map<String, Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getStringAttribute(name, attributes, null);
+ }
+
+ private static void assertMandatoryAttribute(String name, Map<String, Object> attributes)
+ {
+ if (!attributes.containsKey(name))
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not found");
+ }
+ }
+
+ public static Map<String,Object> getMapAttribute(String name, Map<String,Object> attributes, Map<String,Object> defaultVal)
+ {
+ final Object value = attributes.get(name);
+ if(value == null)
+ {
+ return defaultVal;
+ }
+ else if(value instanceof Map)
+ {
+ @SuppressWarnings("unchecked")
+ Map<String,Object> retVal = (Map<String,Object>) value;
+ return retVal;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Map");
+ }
+ }
+
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static <E extends Enum> E getEnumAttribute(Class<E> clazz, String name, Map<String,Object> attributes, E defaultVal)
+ {
+ Object obj = attributes.get(name);
+ if(obj == null)
+ {
+ return defaultVal;
+ }
+ else if(clazz.isInstance(obj))
+ {
+ return (E) obj;
+ }
+ else if(obj instanceof String)
+ {
+ return (E) Enum.valueOf(clazz, (String)obj);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type " + clazz.getSimpleName());
+ }
+ }
+
+ public static <E extends Enum<?>> E getEnumAttribute(Class<E> clazz, String name, Map<String,Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getEnumAttribute(clazz, name, attributes, null);
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public static <T extends Enum<T>> T toEnum(String name, Object rawValue, Class<T> enumType)
+ {
+ if (enumType.isInstance(rawValue))
+ {
+ return (T) rawValue;
+ }
+ else if (rawValue instanceof String)
+ {
+ return (T) Enum.valueOf(enumType, (String) rawValue);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type "
+ + enumType.getSimpleName());
+ }
+ }
+
+ public static Boolean getBooleanAttribute(String name, Map<String,Object> attributes, Boolean defaultValue)
+ {
+ Object obj = attributes.get(name);
+ return toBoolean(name, obj, defaultValue);
+ }
+
+ public static Boolean toBoolean(String name, Object obj)
+ {
+ return toBoolean(name, obj, null);
+ }
+
+ public static Boolean toBoolean(String name, Object obj, Boolean defaultValue)
+ {
+ if(obj == null)
+ {
+ return defaultValue;
+ }
+ else if(obj instanceof Boolean)
+ {
+ return (Boolean) obj;
+ }
+ else if(obj instanceof String)
+ {
+ return Boolean.parseBoolean((String) obj);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Boolean");
+ }
+ }
+
+
+ public static boolean getBooleanAttribute(String name, Map<String, Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getBooleanAttribute(name, attributes, null);
+ }
+
+ public static Integer getIntegerAttribute(String name, Map<String,Object> attributes, Integer defaultValue)
+ {
+ Object obj = attributes.get(name);
+ return toInteger(name, obj, defaultValue);
+ }
+
+ public static Integer toInteger(String name, Object obj)
+ {
+ return toInteger(name, obj, null);
+ }
+
+ public static Integer toInteger(String name, Object obj, Integer defaultValue)
+ {
+ if(obj == null)
+ {
+ return defaultValue;
+ }
+ else if(obj instanceof Number)
+ {
+ return ((Number) obj).intValue();
+ }
+ else if(obj instanceof String)
+ {
+ return Integer.valueOf((String) obj);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Integer");
+ }
+ }
+
+ public static Integer getIntegerAttribute(String name, Map<String,Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getIntegerAttribute(name, attributes, null);
+ }
+
+ public static Long getLongAttribute(String name, Map<String,Object> attributes, Long defaultValue)
+ {
+ Object obj = attributes.get(name);
+ return toLong(name, obj, defaultValue);
+ }
+
+ public static Long toLong(String name, Object obj)
+ {
+ return toLong(name, obj, null);
+ }
+
+ public static Long toLong(String name, Object obj, Long defaultValue)
+ {
+ if(obj == null)
+ {
+ return defaultValue;
+ }
+ else if(obj instanceof Number)
+ {
+ return ((Number) obj).longValue();
+ }
+ else if(obj instanceof String)
+ {
+ return Long.valueOf((String) obj);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Long");
+ }
+ }
+
+ public static <T> Set<T> getSetAttribute(String name, Map<String,Object> attributes)
+ {
+ assertMandatoryAttribute(name, attributes);
+ return getSetAttribute(name, attributes, Collections.<T>emptySet());
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> Set<T> getSetAttribute(String name, Map<String,Object> attributes, Set<T> defaultValue)
+ {
+ Object obj = attributes.get(name);
+ if(obj == null)
+ {
+ return defaultValue;
+ }
+ else if(obj instanceof Set)
+ {
+ return (Set<T>) obj;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + " is not of required type Set");
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends Enum<T>> Set<T> getEnumSetAttribute(String name, Map<String, Object> attributes, Class<T> clazz)
+ {
+ Object obj = attributes.get(name);
+ Object[] items = null;
+ if (obj == null)
+ {
+ return null;
+ }
+ else if (obj instanceof Collection)
+ {
+ Collection<?> data = (Collection<?>) obj;
+ items = data.toArray(new Object[data.size()]);
+ }
+ else if (obj instanceof String[])
+ {
+ items = (String[]) obj;
+ }
+ else if (obj instanceof Object[])
+ {
+ items = (Object[]) obj;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + "[" + obj
+ + "] cannot be converted into set of enum of " + clazz);
+ }
+ Set<T> set = new HashSet<T>();
+ for (int i = 0; i < items.length; i++)
+ {
+ T item = null;
+ Object value = items[i];
+ if (value instanceof String)
+ {
+ item = (T) Enum.valueOf(clazz, (String) value);
+ }
+ else if (clazz.isInstance(value))
+ {
+ item = (T) value;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert " + value + " from [" + obj + "] into enum of " + clazz
+ + " for attribute " + name);
+ }
+ set.add(item);
+ }
+ return set;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Map<String, Object> convert(Map<String, Object> configurationAttributes, Map<String, Class<?>> attributeTypes)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ for (Map.Entry<String, Class<?>> attributeEntry : attributeTypes.entrySet())
+ {
+ String attributeName = attributeEntry.getKey();
+ if (configurationAttributes.containsKey(attributeName))
+ {
+ Class<?> classObject = attributeEntry.getValue();
+ Object rawValue = configurationAttributes.get(attributeName);
+ Object value = null;
+ if (classObject == Long.class || classObject == long.class)
+ {
+ value = toLong(attributeName, rawValue);
+ }
+ else if (classObject == Integer.class || classObject == int.class)
+ {
+ value = toInteger(attributeName, rawValue);
+ }
+ else if (classObject == Boolean.class || classObject == boolean.class)
+ {
+ value = toBoolean(attributeName, rawValue);
+ }
+ else if (classObject == String.class)
+ {
+ value = toString(rawValue);
+ }
+ else if (Enum.class.isAssignableFrom(classObject))
+ {
+ @SuppressWarnings("rawtypes")
+ Class<Enum> enumType = (Class<Enum>)classObject;
+ value = toEnum(attributeName, rawValue, enumType);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert '" + rawValue + "' into " + classObject);
+ }
+ attributes.put(attributeName, value);
+ }
+ }
+ return attributes;
+ }
+
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java
index f810360662..d24f79c56c 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHost.java
@@ -25,13 +25,10 @@ import java.util.UUID;
import java.util.concurrent.ScheduledFuture;
import org.apache.qpid.common.Closeable;
import org.apache.qpid.server.binding.BindingFactory;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.VirtualHostConfig;
import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.connection.IConnectionRegistry;
import org.apache.qpid.server.exchange.ExchangeFactory;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.protocol.v1_0.LinkRegistry;
import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.registry.IApplicationRegistry;
@@ -41,7 +38,7 @@ import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.txn.DtxRegistry;
-public interface VirtualHost extends DurableConfigurationStore.Source, VirtualHostConfig, Closeable, StatisticsGatherer
+public interface VirtualHost extends DurableConfigurationStore.Source, Closeable, StatisticsGatherer
{
IConnectionRegistry getConnectionRegistry();
@@ -61,8 +58,6 @@ public interface VirtualHost extends DurableConfigurationStore.Source, VirtualHo
void close();
- UUID getBrokerId();
-
UUID getId();
void scheduleHouseKeepingTask(long period, HouseKeepingTask task);
@@ -77,25 +72,12 @@ public interface VirtualHost extends DurableConfigurationStore.Source, VirtualHo
int getHouseKeepingActiveCount();
- IApplicationRegistry getApplicationRegistry();
+ VirtualHostRegistry getVirtualHostRegistry();
BindingFactory getBindingFactory();
- void createBrokerConnection(String transport,
- String host,
- int port,
- String vhost,
- boolean durable,
- String authMechanism, String username, String password);
-
- public BrokerLink createBrokerConnection(UUID id, long createTime, Map<String,String> arguments);
-
- ConfigStore getConfigStore();
-
DtxRegistry getDtxRegistry();
- void removeBrokerConnection(BrokerLink brokerLink);
-
LinkRegistry getLinkRegistry(String remoteContainerId);
ScheduledFuture<?> scheduleTask(long delay, Runnable timeoutTask);
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java
index ea2f0f15e4..ae88e3e9f7 100755
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostConfigRecoveryHandler.java
@@ -35,15 +35,16 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.BindingFactory;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.messages.TransactionLogMessages;
import org.apache.qpid.server.logging.subjects.MessageStoreLogSubject;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.AbstractServerMessageImpl;
import org.apache.qpid.server.message.EnqueableMessage;
+import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.server.message.MessageTransferMessage;
import org.apache.qpid.server.message.ServerMessage;
+import org.apache.qpid.server.protocol.v1_0.Message_1_0;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.QueueEntry;
@@ -65,7 +66,6 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
ConfigurationRecoveryHandler.QueueRecoveryHandler,
ConfigurationRecoveryHandler.ExchangeRecoveryHandler,
ConfigurationRecoveryHandler.BindingRecoveryHandler,
- ConfigurationRecoveryHandler.BrokerLinkRecoveryHandler,
MessageStoreRecoveryHandler,
MessageStoreRecoveryHandler.StoredMessageRecoveryHandler,
TransactionLogRecoveryHandler,
@@ -77,7 +77,7 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
private final VirtualHost _virtualHost;
private final Map<String, Integer> _queueRecoveries = new TreeMap<String, Integer>();
- private final Map<Long, AbstractServerMessageImpl> _recoveredMessages = new HashMap<Long, AbstractServerMessageImpl>();
+ private final Map<Long, ServerMessage> _recoveredMessages = new HashMap<Long, ServerMessage>();
private final Map<Long, StoredMessage> _unusedMessages = new HashMap<Long, StoredMessage>();
private MessageStoreLogSubject _logSubject;
@@ -169,7 +169,7 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
public void message(StoredMessage message)
{
- AbstractServerMessageImpl serverMessage;
+ ServerMessage serverMessage;
switch(message.getMetaData().getType())
{
case META_DATA_0_8:
@@ -178,6 +178,9 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
case META_DATA_0_10:
serverMessage = new MessageTransferMessage(message, null);
break;
+ case META_DATA_1_0:
+ serverMessage = new Message_1_0(message);
+ break;
default:
throw new RuntimeException("Unknown message type retrieved from store " + message.getMetaData().getClass());
}
@@ -190,19 +193,6 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
{
}
- public BridgeRecoveryHandler brokerLink(final UUID id,
- final long createTime,
- final Map<String, String> arguments)
- {
- BrokerLink blink = _virtualHost.createBrokerConnection(id, createTime, arguments);
- return new BridgeRecoveryHandlerImpl(blink);
-
- }
-
- public void completeBrokerLinkRecovery()
- {
- }
-
public void dtxRecord(long format, byte[] globalId, byte[] branchId,
Transaction.Record[] enqueues,
Transaction.Record[] dequeues)
@@ -221,12 +211,13 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
if(queue != null)
{
final long messageId = record.getMessage().getMessageNumber();
- final AbstractServerMessageImpl message = _recoveredMessages.get(messageId);
+ final ServerMessage message = _recoveredMessages.get(messageId);
_unusedMessages.remove(messageId);
if(message != null)
{
- message.incrementReference();
+ final MessageReference ref = message.newReference();
+
branch.enqueue(queue,message);
@@ -239,7 +230,7 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
{
queue.enqueue(message, true, null);
- message.decrementReference();
+ ref.release();
}
catch (AMQException e)
{
@@ -251,7 +242,7 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
public void onRollback()
{
- message.decrementReference();
+ ref.release();
}
});
}
@@ -280,7 +271,7 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
if(queue != null)
{
final long messageId = record.getMessage().getMessageNumber();
- final AbstractServerMessageImpl message = _recoveredMessages.get(messageId);
+ final ServerMessage message = _recoveredMessages.get(messageId);
_unusedMessages.remove(messageId);
if(message != null)
@@ -412,9 +403,8 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
}
- public BrokerLinkRecoveryHandler completeBindingRecovery()
+ public void completeBindingRecovery()
{
- return this;
}
public void complete()
@@ -529,22 +519,4 @@ public class VirtualHostConfigRecoveryHandler implements ConfigurationRecoveryHa
}
}
- private class BridgeRecoveryHandlerImpl implements BridgeRecoveryHandler
- {
- private final BrokerLink _blink;
-
- public BridgeRecoveryHandlerImpl(final BrokerLink blink)
- {
- _blink = blink;
- }
-
- public void bridge(final UUID id, final long createTime, final Map<String, String> arguments)
- {
- _blink.createBridge(id, createTime, arguments);
- }
-
- public void completeBridgeRecoveryForLink()
- {
- }
- }
}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
index d9dc0aa64e..dd3610373f 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
@@ -25,7 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -35,12 +34,8 @@ import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.binding.BindingFactory;
-import org.apache.qpid.server.configuration.BrokerConfig;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
import org.apache.qpid.server.configuration.ExchangeConfiguration;
import org.apache.qpid.server.configuration.QueueConfiguration;
-import org.apache.qpid.server.configuration.VirtualHostConfigType;
import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.connection.ConnectionRegistry;
import org.apache.qpid.server.connection.IConnectionRegistry;
@@ -49,7 +44,6 @@ import org.apache.qpid.server.exchange.DefaultExchangeRegistry;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeFactory;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.messages.VirtualHostMessages;
import org.apache.qpid.server.logging.subjects.MessageStoreLogSubject;
@@ -61,17 +55,16 @@ import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.DefaultQueueRegistry;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.stats.StatisticsCounter;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.Event;
import org.apache.qpid.server.store.EventListener;
import org.apache.qpid.server.store.HAMessageStore;
import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreCreator;
import org.apache.qpid.server.store.OperationalLoggingListener;
import org.apache.qpid.server.txn.DtxRegistry;
-import org.apache.qpid.server.virtualhost.plugins.VirtualHostPlugin;
-import org.apache.qpid.server.virtualhost.plugins.VirtualHostPluginFactory;
public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.RegistryChangeListener, EventListener
{
@@ -79,23 +72,19 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
private static final int HOUSEKEEPING_SHUTDOWN_TIMEOUT = 5;
- private final UUID _qmfId;
-
private final String _name;
private final UUID _id;
private final long _createTime = System.currentTimeMillis();
- private final ConcurrentHashMap<BrokerLink,BrokerLink> _links = new ConcurrentHashMap<BrokerLink, BrokerLink>();
-
private final ScheduledThreadPoolExecutor _houseKeepingTasks;
- private final IApplicationRegistry _appRegistry;
+ private final VirtualHostRegistry _virtualHostRegistry;
- private final SecurityManager _securityManager;
+ private final StatisticsGatherer _brokerStatisticsGatherer;
- private final BrokerConfig _brokerConfig;
+ private final SecurityManager _securityManager;
private final VirtualHostConfiguration _vhostConfig;
@@ -120,7 +109,7 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
private final Map<String, LinkRegistry> _linkRegistry = new HashMap<String, LinkRegistry>();
private boolean _blocked;
- public VirtualHostImpl(IApplicationRegistry appRegistry, VirtualHostConfiguration hostConfig) throws Exception
+ public VirtualHostImpl(VirtualHostRegistry virtualHostRegistry, StatisticsGatherer brokerStatisticsGatherer, SecurityManager parentSecurityManager, VirtualHostConfiguration hostConfig) throws Exception
{
if (hostConfig == null)
{
@@ -132,19 +121,17 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
throw new IllegalArgumentException("Illegal name (" + hostConfig.getName() + ") for virtualhost.");
}
- _appRegistry = appRegistry;
- _brokerConfig = _appRegistry.getBrokerConfig();
+ _virtualHostRegistry = virtualHostRegistry;
+ _brokerStatisticsGatherer = brokerStatisticsGatherer;
_vhostConfig = hostConfig;
_name = _vhostConfig.getName();
_dtxRegistry = new DtxRegistry();
- _qmfId = _appRegistry.getConfigStore().createId();
_id = UUIDGenerator.generateVhostUUID(_name);
CurrentActor.get().message(VirtualHostMessages.CREATED(_name));
- _securityManager = new SecurityManager(_appRegistry.getSecurityManager());
- _securityManager.configureHostPlugins(_vhostConfig);
+ _securityManager = new SecurityManager(parentSecurityManager, _vhostConfig.getConfig().getString("security.acl"));
_connectionRegistry = new ConnectionRegistry();
_connectionRegistry.addRegistryChangeListener(this);
@@ -154,13 +141,12 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
_queueRegistry = new DefaultQueueRegistry(this);
_exchangeFactory = new DefaultExchangeFactory(this);
- _exchangeFactory.initialise(_vhostConfig);
_exchangeRegistry = new DefaultExchangeRegistry(this);
_bindingFactory = new BindingFactory(this);
- _messageStore = initialiseMessageStore(hostConfig.getMessageStoreClass());
+ _messageStore = initialiseMessageStore(hostConfig);
configureMessageStore(hostConfig);
@@ -187,22 +173,6 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
return _id;
}
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- public VirtualHostConfigType getConfigType()
- {
- return VirtualHostConfigType.getInstance();
- }
-
- public ConfiguredObject getParent()
- {
- return getBroker();
- }
-
public boolean isDurable()
{
return false;
@@ -216,38 +186,9 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
*/
private void initialiseHouseKeeping(long period)
{
-
if (period != 0L)
{
scheduleHouseKeepingTask(period, new VirtualHostHouseKeepingTask());
-
- Map<String, VirtualHostPluginFactory> plugins = _appRegistry.getPluginManager().getVirtualHostPlugins();
-
- if (plugins != null)
- {
- for (Map.Entry<String, VirtualHostPluginFactory> entry : plugins.entrySet())
- {
- String pluginName = entry.getKey();
- VirtualHostPluginFactory factory = entry.getValue();
- try
- {
- VirtualHostPlugin plugin = factory.newInstance(this);
-
- // If we had configuration for the plugin the schedule it.
- if (plugin != null)
- {
- _houseKeepingTasks.scheduleAtFixedRate(plugin, plugin.getDelay() / 2,
- plugin.getDelay(), plugin.getTimeUnit());
-
- _logger.info("Loaded VirtualHostPlugin:" + plugin);
- }
- }
- catch (RuntimeException e)
- {
- _logger.error("Unable to load VirtualHostPlugin:" + pluginName + " due to:" + e.getMessage(), e);
- }
- }
- }
}
}
@@ -329,19 +270,34 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
if (!(o instanceof MessageStore))
{
- throw new ClassCastException("Message store factory class must implement " + MessageStore.class +
+ throw new ClassCastException("Message store class must implement " + MessageStore.class +
". Class " + clazz + " does not.");
}
final MessageStore messageStore = (MessageStore) o;
- final MessageStoreLogSubject storeLogSubject = new MessageStoreLogSubject(this, clazz.getSimpleName());
+ return messageStore;
+ }
+
+ private MessageStore initialiseMessageStore(VirtualHostConfiguration hostConfig) throws Exception
+ {
+ String storeType = hostConfig.getConfig().getString("store.type");
+ MessageStore messageStore = null;
+ if (storeType == null)
+ {
+ messageStore = initialiseMessageStore(hostConfig.getMessageStoreClass());
+ }
+ else
+ {
+ messageStore = new MessageStoreCreator().createMessageStore(storeType);
+ }
+
+ final MessageStoreLogSubject storeLogSubject = new MessageStoreLogSubject(this, messageStore.getClass().getSimpleName());
OperationalLoggingListener.listen(messageStore, storeLogSubject);
messageStore.addEventListener(new BeforeActivationListener(), Event.BEFORE_ACTIVATE);
messageStore.addEventListener(new AfterActivationListener(), Event.AFTER_ACTIVATE);
messageStore.addEventListener(new BeforeCloseListener(), Event.BEFORE_CLOSE);
messageStore.addEventListener(new BeforePassivationListener(), Event.BEFORE_PASSIVATE);
-
return messageStore;
}
@@ -468,16 +424,6 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
return _name;
}
- public BrokerConfig getBroker()
- {
- return _brokerConfig;
- }
-
- public String getFederationTag()
- {
- return _brokerConfig.getFederationTag();
- }
-
public long getCreateTime()
{
return _createTime;
@@ -534,14 +480,9 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
CurrentActor.get().message(VirtualHostMessages.CLOSED());
}
- public UUID getBrokerId()
- {
- return _appRegistry.getBrokerId();
- }
-
- public IApplicationRegistry getApplicationRegistry()
+ public VirtualHostRegistry getVirtualHostRegistry()
{
- return _appRegistry;
+ return _virtualHostRegistry;
}
public BindingFactory getBindingFactory()
@@ -553,14 +494,14 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
{
_messagesDelivered.registerEvent(1L);
_dataDelivered.registerEvent(messageSize);
- _appRegistry.registerMessageDelivered(messageSize);
+ _brokerStatisticsGatherer.registerMessageDelivered(messageSize);
}
public void registerMessageReceived(long messageSize, long timestamp)
{
_messagesReceived.registerEvent(1L, timestamp);
_dataReceived.registerEvent(messageSize, timestamp);
- _appRegistry.registerMessageReceived(messageSize, timestamp);
+ _brokerStatisticsGatherer.registerMessageReceived(messageSize, timestamp);
}
public StatisticsCounter getMessageReceiptStatistics()
@@ -604,51 +545,6 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
_dataReceived = new StatisticsCounter("bytes-received-" + getName());
}
- public BrokerLink createBrokerConnection(UUID id, long createTime, Map<String,String> arguments)
- {
- BrokerLink blink = new BrokerLink(this, id, createTime, arguments);
- // TODO - cope with duplicate broker link creation requests
- _links.putIfAbsent(blink,blink);
- getConfigStore().addConfiguredObject(blink);
- return blink;
- }
-
- public void createBrokerConnection(final String transport,
- final String host,
- final int port,
- final String vhost,
- final boolean durable,
- final String authMechanism,
- final String username,
- final String password)
- {
- BrokerLink blink = new BrokerLink(this, transport, host, port, vhost, durable, authMechanism, username, password);
-
- // TODO - cope with duplicate broker link creation requests
- _links.putIfAbsent(blink,blink);
- getConfigStore().addConfiguredObject(blink);
-
- }
-
- public void removeBrokerConnection(final String transport,
- final String host,
- final int port,
- final String vhost)
- {
- removeBrokerConnection(new BrokerLink(this, transport, host, port, vhost, false, null,null,null));
-
- }
-
- public void removeBrokerConnection(BrokerLink blink)
- {
- blink = _links.get(blink);
- if(blink != null)
- {
- blink.close();
- getConfigStore().removeConfiguredObject(blink);
- }
- }
-
public synchronized LinkRegistry getLinkRegistry(String remoteContainerId)
{
LinkRegistry linkRegistry = _linkRegistry.get(remoteContainerId);
@@ -660,11 +556,6 @@ public class VirtualHostImpl implements VirtualHost, IConnectionRegistry.Registr
return linkRegistry;
}
- public ConfigStore getConfigStore()
- {
- return getApplicationRegistry().getConfigStore();
- }
-
public DtxRegistry getDtxRegistry()
{
return _dtxRegistry;
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java
index 1be472844a..483e11942b 100644
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java
+++ b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java
@@ -1,140 +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.server.virtualhost;
-
-import org.apache.qpid.common.Closeable;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-
-public class VirtualHostRegistry implements Closeable
-{
- private final Map<String, VirtualHost> _registry = new ConcurrentHashMap<String, VirtualHost>();
-
-
- private String _defaultVirtualHostName;
- private ApplicationRegistry _applicationRegistry;
- private final Collection<RegistryChangeListener> _listeners =
- Collections.synchronizedCollection(new ArrayList<RegistryChangeListener>());
-
- public VirtualHostRegistry(ApplicationRegistry applicationRegistry)
- {
- _applicationRegistry = applicationRegistry;
- }
-
- public synchronized void registerVirtualHost(VirtualHost host) throws Exception
- {
- if(_registry.containsKey(host.getName()))
- {
- throw new Exception("Virtual Host with name " + host.getName() + " already registered.");
- }
- _registry.put(host.getName(),host);
- synchronized (_listeners)
+/*
+ *
+ * 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.virtualhost;
+
+import org.apache.qpid.common.Closeable;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+public class VirtualHostRegistry implements Closeable
+{
+ private final Map<String, VirtualHost> _registry = new ConcurrentHashMap<String, VirtualHost>();
+ private String _defaultVirtualHostName;
+
+
+ public VirtualHostRegistry()
+ {
+ super();
+ }
+
+ public synchronized void registerVirtualHost(VirtualHost host)
+ {
+ if(_registry.containsKey(host.getName()))
{
- for(RegistryChangeListener listener : _listeners)
- {
- listener.virtualHostRegistered(host);
- }
+ throw new IllegalArgumentException("Virtual Host with name " + host.getName() + " already registered.");
}
- }
-
- public synchronized void unregisterVirtualHost(VirtualHost host)
- {
- _registry.remove(host.getName());
- synchronized (_listeners)
+ _registry.put(host.getName(),host);
+ }
+
+ public synchronized void unregisterVirtualHost(VirtualHost host)
+ {
+ _registry.remove(host.getName());
+ }
+
+ public VirtualHost getVirtualHost(String name)
+ {
+ if(name == null || name.trim().length() == 0 || "/".equals(name.trim()))
{
- for(RegistryChangeListener listener : _listeners)
- {
- listener.virtualHostUnregistered(host);
- }
+ name = getDefaultVirtualHostName();
}
- }
-
- public VirtualHost getVirtualHost(String name)
- {
- if(name == null || name.trim().length() == 0 || "/".equals(name.trim()))
- {
- name = getDefaultVirtualHostName();
- }
-
- return _registry.get(name);
- }
-
- public VirtualHost getDefaultVirtualHost()
- {
- return getVirtualHost(getDefaultVirtualHostName());
- }
-
- private String getDefaultVirtualHostName()
- {
- return _defaultVirtualHostName;
- }
-
- public void setDefaultVirtualHostName(String defaultVirtualHostName)
- {
- _defaultVirtualHostName = defaultVirtualHostName;
- }
-
-
- public Collection<VirtualHost> getVirtualHosts()
- {
- return new ArrayList<VirtualHost>(_registry.values());
- }
-
- public ApplicationRegistry getApplicationRegistry()
- {
- return _applicationRegistry;
- }
-
- public ConfigStore getConfigStore()
- {
- return _applicationRegistry.getConfigStore();
- }
-
- public void close()
- {
- for (VirtualHost virtualHost : getVirtualHosts())
- {
- virtualHost.close();
- }
-
- }
-
- public static interface RegistryChangeListener
+
+ return _registry.get(name);
+ }
+
+ public VirtualHost getDefaultVirtualHost()
{
- void virtualHostRegistered(VirtualHost virtualHost);
- void virtualHostUnregistered(VirtualHost virtualHost);
+ return getVirtualHost(getDefaultVirtualHostName());
+ }
+ private String getDefaultVirtualHostName()
+ {
+ return _defaultVirtualHostName;
}
- public void addRegistryChangeListener(RegistryChangeListener listener)
+ public void setDefaultVirtualHostName(String defaultVirtualHostName)
{
- _listeners.add(listener);
+ _defaultVirtualHostName = defaultVirtualHostName;
+ }
+
+
+ public Collection<VirtualHost> getVirtualHosts()
+ {
+ return new ArrayList<VirtualHost>(_registry.values());
+ }
+
+ public void close()
+ {
+ for (VirtualHost virtualHost : getVirtualHosts())
+ {
+ virtualHost.close();
+ }
}
-}
+}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/ConfiguredQueueBindingListener.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/ConfiguredQueueBindingListener.java
deleted file mode 100644
index 12886f400a..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/ConfiguredQueueBindingListener.java
+++ /dev/null
@@ -1,105 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionQueueConfiguration;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.exchange.Exchange.BindingListener;
-import org.apache.qpid.server.queue.AMQQueue;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * This is a listener that caches queues that are configured for slow consumer disconnection.
- *
- * There should be one listener per virtual host, which can be added to all exchanges on
- * that host.
- *
- * TODO In future, it will be possible to configure the policy at runtime, so only the queue
- * itself is cached, and the configuration looked up by the housekeeping thread. This means
- * that there may be occasions where the copy of the cache contents retrieved by the thread
- * does not contain queues that are configured, or that configured queues are not present.
- *
- * @see BindingListener
- */
-public class ConfiguredQueueBindingListener implements BindingListener
-{
- private static final Logger _log = Logger.getLogger(ConfiguredQueueBindingListener.class);
-
- private String _vhostName;
- private Set<AMQQueue> _cache = Collections.synchronizedSet(new HashSet<AMQQueue>());
-
- public ConfiguredQueueBindingListener(String vhostName)
- {
- _vhostName = vhostName;
- }
-
- /**
- * @see BindingListener#bindingAdded(Exchange, Binding)
- */
- public void bindingAdded(Exchange exchange, Binding binding)
- {
- processBinding(binding);
- }
-
- /**
- * @see BindingListener#bindingRemoved(Exchange, Binding)
- */
- public void bindingRemoved(Exchange exchange, Binding binding)
- {
- processBinding(binding);
- }
-
- private void processBinding(Binding binding)
- {
- AMQQueue queue = binding.getQueue();
-
- SlowConsumerDetectionQueueConfiguration config =
- queue.getConfiguration().getConfiguration(SlowConsumerDetectionQueueConfiguration.class.getName());
- if (config != null)
- {
- _cache.add(queue);
- }
- else
- {
- _cache.remove(queue);
- }
- }
-
- /**
- * Lookup and return the cache of configured {@link AMQQueue}s.
- *
- * Note that when accessing the cached queues, the {@link java.util.Iterator} is not thread safe
- * (see the {@link Collections#synchronizedSet(Set)} documentation) so a copy of the
- * cache is returned.
- *
- * @return a copy of the cached {@link java.util.Set} of queues
- */
- public Set<AMQQueue> getQueueCache()
- {
- return new HashSet<AMQQueue>(_cache);
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetection.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetection.java
deleted file mode 100644
index bd2e30449a..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetection.java
+++ /dev/null
@@ -1,174 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionConfiguration;
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionQueueConfiguration;
-import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.plugins.logging.SlowConsumerDetectionMessages;
-import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPlugin;
-
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-public class SlowConsumerDetection extends VirtualHostHouseKeepingPlugin
-{
- private SlowConsumerDetectionConfiguration _config;
- private ConfiguredQueueBindingListener _listener;
-
- public static class SlowConsumerFactory implements VirtualHostPluginFactory
- {
- public SlowConsumerDetection newInstance(VirtualHost vhost)
- {
- SlowConsumerDetectionConfiguration config = vhost.getConfiguration().getConfiguration(SlowConsumerDetectionConfiguration.class.getName());
-
- if (config == null)
- {
- return null;
- }
-
- SlowConsumerDetection plugin = new SlowConsumerDetection(vhost);
- plugin.configure(config);
- return plugin;
- }
- }
-
- /**
- * Configures the slow consumer disconnect plugin by adding a listener to each exchange on this
- * virtual host to record all the configured queues in a cache for processing by the housekeeping
- * thread.
- *
- * @see org.apache.qpid.server.plugins.Plugin#configure(ConfigurationPlugin)
- */
- public void configure(ConfigurationPlugin config)
- {
- _config = (SlowConsumerDetectionConfiguration) config;
- _listener = new ConfiguredQueueBindingListener(getVirtualHost().getName());
- final ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry();
- for (AMQShortString exchangeName : exchangeRegistry.getExchangeNames())
- {
- exchangeRegistry.getExchange(exchangeName).addBindingListener(_listener);
- }
- }
-
- public SlowConsumerDetection(VirtualHost vhost)
- {
- super(vhost);
- }
-
- public void execute()
- {
- CurrentActor.get().message(SlowConsumerDetectionMessages.RUNNING());
-
- Set<AMQQueue> cache = _listener.getQueueCache();
- for (AMQQueue q : cache)
- {
- CurrentActor.get().message(SlowConsumerDetectionMessages.CHECKING_QUEUE(q.getName()));
-
- try
- {
- final SlowConsumerDetectionQueueConfiguration config =
- q.getConfiguration().getConfiguration(SlowConsumerDetectionQueueConfiguration.class.getName());
- if (checkQueueStatus(q, config))
- {
- final SlowConsumerPolicyPlugin policy = config.getPolicy();
- if (policy == null)
- {
- // We would only expect to see this during shutdown
- getLogger().warn("No slow consumer policy for queue " + q.getName());
- }
- else
- {
- policy.performPolicy(q);
- }
-
- }
- }
- catch (Exception e)
- {
- // Don't throw exceptions as this will stop the house keeping task from running.
- getLogger().error("Exception in SlowConsumersDetection for queue: " + q.getName(), e);
- }
- }
-
- CurrentActor.get().message(SlowConsumerDetectionMessages.COMPLETE());
- }
-
- public long getDelay()
- {
- return _config.getDelay();
- }
-
- public TimeUnit getTimeUnit()
- {
- return _config.getTimeUnit();
- }
-
- /**
- * Check the depth,messageSize,messageAge,messageCount values for this q
- *
- * @param q the queue to check
- * @param config the queue configuration to compare against the queue state
- *
- * @return true if the queue has reached a threshold.
- */
- private boolean checkQueueStatus(AMQQueue q, SlowConsumerDetectionQueueConfiguration config)
- {
- if (config != null)
- {
- if (getLogger().isInfoEnabled())
- {
- getLogger().info("Retrieved Queue(" + q.getName() + ") Config:" + config);
- }
-
- int count = q.getMessageCount();
-
- // First Check message counts
- if ((config.getMessageCount() != 0 && count >= config.getMessageCount()) ||
- // The check queue depth
- (config.getDepth() != 0 && q.getQueueDepth() >= config.getDepth()) ||
- // finally if we have messages on the queue check Arrival time.
- // We must check count as OldestArrival time is Long.MAX_LONG when
- // there are no messages.
- (config.getMessageAge() != 0 &&
- ((count > 0) && q.getOldestMessageArrivalTime() >= config.getMessageAge())))
- {
-
- if (getLogger().isDebugEnabled())
- {
- getLogger().debug("Detected Slow Consumer on Queue(" + q.getName() + ")");
- getLogger().debug("Queue Count:" + q.getMessageCount() + ":" + config.getMessageCount());
- getLogger().debug("Queue Depth:" + q.getQueueDepth() + ":" + config.getDepth());
- getLogger().debug("Queue Arrival:" + q.getOldestMessageArrivalTime() + ":" + config.getMessageAge());
- }
-
- return true;
- }
- }
- return false;
- }
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java
deleted file mode 100644
index 191f8041d2..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java
+++ /dev/null
@@ -1,61 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.server.virtualhost.HouseKeepingTask;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-
-import java.util.concurrent.TimeUnit;
-
-public abstract class VirtualHostHouseKeepingPlugin extends HouseKeepingTask implements VirtualHostPlugin
-{
- private final Logger _logger = Logger.getLogger(getClass());
-
- public VirtualHostHouseKeepingPlugin(VirtualHost vhost)
- {
- super(vhost);
- }
-
-
- /**
- * Long value representing the delay between repeats
- *
- * @return
- */
- public abstract long getDelay();
-
- /**
- * Option to specify what the delay value represents
- *
- * @return
- *
- * @see java.util.concurrent.TimeUnit for valid value.
- */
- public abstract TimeUnit getTimeUnit();
-
-
- protected Logger getLogger()
- {
- return _logger;
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java
deleted file mode 100644
index 35f6228ab9..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java
+++ /dev/null
@@ -1,42 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.qpid.server.plugins.Plugin;
-
-import java.util.concurrent.TimeUnit;
-
-public interface VirtualHostPlugin extends Runnable, Plugin
-{
- /**
- * Long value representing the delay between repeats
- *
- * @return
- */
- public long getDelay();
-
- /**
- * Option to specify what the delay value represents
- * @see java.util.concurrent.TimeUnit for valid value.
- * @return
- */
- public TimeUnit getTimeUnit();
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java
deleted file mode 100644
index c8bea18444..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPluginFactory.java
+++ /dev/null
@@ -1,28 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.qpid.server.virtualhost.VirtualHost;
-
-public interface VirtualHostPluginFactory
-{
- public VirtualHostHouseKeepingPlugin newInstance(VirtualHost vhost);
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/logging/SlowConsumerDetection_logmessages.properties b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/logging/SlowConsumerDetection_logmessages.properties
deleted file mode 100644
index 03c56910c2..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/logging/SlowConsumerDetection_logmessages.properties
+++ /dev/null
@@ -1,23 +0,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.
-#
-# Default File used for all non-defined locales.
-
-RUNNING = SCD-1001 : Running
-COMPLETE = SCD-1002 : Complete
-CHECKING_QUEUE = SCD-1003 : Checking Status of Queue {0} \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/logging/TopicDeletePolicy_logmessages.properties b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/logging/TopicDeletePolicy_logmessages.properties
deleted file mode 100644
index ed4fb1d45a..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/logging/TopicDeletePolicy_logmessages.properties
+++ /dev/null
@@ -1,22 +0,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.
-#
-# Default File used for all non-defined locales.
-
-DELETING_QUEUE = TDP-1001 : Deleting Queue
-DISCONNECTING = TDP-1002 : Disconnecting Session \ No newline at end of file
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicy.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicy.java
deleted file mode 100644
index f2f61f204e..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicy.java
+++ /dev/null
@@ -1,141 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins.policies;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.exchange.TopicExchange;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.protocol.AMQSessionModel;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.virtualhost.plugins.logging.TopicDeletePolicyMessages;
-import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPlugin;
-import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPluginFactory;
-
-public class TopicDeletePolicy implements SlowConsumerPolicyPlugin
-{
- private Logger _logger = Logger.getLogger(TopicDeletePolicy.class);
- private TopicDeletePolicyConfiguration _configuration;
-
- public static class TopicDeletePolicyFactory implements SlowConsumerPolicyPluginFactory
- {
- public TopicDeletePolicy newInstance(ConfigurationPlugin configuration) throws ConfigurationException
- {
- TopicDeletePolicyConfiguration config =
- configuration.getConfiguration(TopicDeletePolicyConfiguration.class.getName());
-
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(config);
- return policy;
- }
-
- public String getPluginName()
- {
- return "topicdelete";
- }
-
- public Class<TopicDeletePolicy> getPluginClass()
- {
- return TopicDeletePolicy.class;
- }
- }
-
- public void performPolicy(AMQQueue q)
- {
- if (q == null)
- {
- return;
- }
-
- AMQSessionModel owner = q.getExclusiveOwningSession();
-
- // Only process exclusive queues
- if (owner == null)
- {
- return;
- }
-
- //Only process Topics
- if (!validateQueueIsATopic(q))
- {
- return;
- }
-
- try
- {
- CurrentActor.get().message(owner.getLogSubject(),TopicDeletePolicyMessages.DISCONNECTING());
- // Close the consumer . this will cause autoDelete Queues to be purged
- owner.getConnectionModel().
- closeSession(owner, AMQConstant.RESOURCE_ERROR,
- "Consuming to slow.");
-
- // Actively delete non autoDelete queues if deletePersistent is set
- if (!q.isAutoDelete() && (_configuration != null && _configuration.deletePersistent()))
- {
- CurrentActor.get().message(q.getLogSubject(), TopicDeletePolicyMessages.DELETING_QUEUE());
- q.delete();
- }
-
- }
- catch (AMQException e)
- {
- _logger.warn("Unable to close consumer:" + owner + ", on queue:" + q.getName());
- }
-
- }
-
- /**
- * Check the queue bindings to validate the queue is bound to the
- * topic exchange.
- *
- * @param q the Queue
- *
- * @return true iff Q is bound to a TopicExchange
- */
- private boolean validateQueueIsATopic(AMQQueue q)
- {
- for (Binding binding : q.getBindings())
- {
- if (binding.getExchange() instanceof TopicExchange)
- {
- return true;
- }
- }
-
- return false;
- }
-
- public void configure(ConfigurationPlugin config)
- {
- _configuration = (TopicDeletePolicyConfiguration) config;
- }
-
- @Override
- public String toString()
- {
- return "TopicDelete" + (_configuration == null ? "" : "[" + _configuration + "]");
- }
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfiguration.java b/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfiguration.java
deleted file mode 100644
index 48158b7dff..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfiguration.java
+++ /dev/null
@@ -1,82 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins.policies;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class TopicDeletePolicyConfiguration extends ConfigurationPlugin
-{
-
- public static class TopicDeletePolicyConfigurationFactory
- implements ConfigurationPluginFactory
- {
- public ConfigurationPlugin newInstance(String path,
- Configuration config)
- throws ConfigurationException
- {
- TopicDeletePolicyConfiguration slowConsumerConfig =
- new TopicDeletePolicyConfiguration();
- slowConsumerConfig.setConfiguration(path, config);
- return slowConsumerConfig;
- }
-
- public List<String> getParentPaths()
- {
- return Arrays.asList(
- "virtualhosts.virtualhost.queues.slow-consumer-detection.policy.topicDelete",
- "virtualhosts.virtualhost.queues.queue.slow-consumer-detection.policy.topicDelete",
- "virtualhosts.virtualhost.topics.slow-consumer-detection.policy.topicDelete",
- "virtualhosts.virtualhost.topics.topic.slow-consumer-detection.policy.topicDelete");
- }
- }
-
- public String[] getElementsProcessed()
- {
- return new String[]{"delete-persistent"};
- }
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- // No validation required.
- }
-
- public boolean deletePersistent()
- {
- // If we don't have configuration then we don't deletePersistent Queues
- return (hasConfiguration() && contains("delete-persistent"));
- }
-
- @Override
- public String formatToString()
- {
- return (deletePersistent()?"delete-durable":"");
- }
-
-
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/slowconsumerdetection/policies/SlowConsumerPolicyPlugin.java b/java/broker/src/main/java/org/apache/qpid/slowconsumerdetection/policies/SlowConsumerPolicyPlugin.java
deleted file mode 100644
index 7f600abdc9..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/slowconsumerdetection/policies/SlowConsumerPolicyPlugin.java
+++ /dev/null
@@ -1,29 +0,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.
- *
- */
-package org.apache.qpid.slowconsumerdetection.policies;
-
-import org.apache.qpid.server.plugins.Plugin;
-import org.apache.qpid.server.queue.AMQQueue;
-
-public interface SlowConsumerPolicyPlugin extends Plugin
-{
- public void performPolicy(AMQQueue Queue);
-}
diff --git a/java/broker/src/main/java/org/apache/qpid/slowconsumerdetection/policies/SlowConsumerPolicyPluginFactory.java b/java/broker/src/main/java/org/apache/qpid/slowconsumerdetection/policies/SlowConsumerPolicyPluginFactory.java
deleted file mode 100644
index b2fe6766a6..0000000000
--- a/java/broker/src/main/java/org/apache/qpid/slowconsumerdetection/policies/SlowConsumerPolicyPluginFactory.java
+++ /dev/null
@@ -1,27 +0,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.
- *
- */
-package org.apache.qpid.slowconsumerdetection.policies;
-
-import org.apache.qpid.server.plugins.PluginFactory;
-
-public interface SlowConsumerPolicyPluginFactory<P extends SlowConsumerPolicyPlugin> extends PluginFactory<P>
-{
-}
diff --git a/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory
new file mode 100644
index 0000000000..5f75a8c4c9
--- /dev/null
+++ b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.configuration.ConfigurationStoreFactory
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.qpid.server.configuration.store.factory.JsonConfigurationStoreFactory
diff --git a/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory
new file mode 100644
index 0000000000..8ff67030ef
--- /dev/null
+++ b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.AuthenticationManagerFactory
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory
+org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory
+org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManagerFactory
+org.apache.qpid.server.security.auth.manager.KerberosAuthenticationManagerFactory
+org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory
+org.apache.qpid.server.security.auth.manager.SimpleLDAPAuthenticationManagerFactory
diff --git a/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType
new file mode 100644
index 0000000000..4ad646b7a0
--- /dev/null
+++ b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ExchangeType
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+org.apache.qpid.server.exchange.DirectExchangeType
+org.apache.qpid.server.exchange.TopicExchangeType
+org.apache.qpid.server.exchange.FanoutExchangeType
+org.apache.qpid.server.exchange.HeadersExchangeType
diff --git a/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory
new file mode 100644
index 0000000000..6bfb55ff18
--- /dev/null
+++ b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.GroupManagerFactory
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.qpid.server.security.group.FileGroupManagerFactory
diff --git a/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory
new file mode 100644
index 0000000000..1357f816b7
--- /dev/null
+++ b/java/broker/src/main/resources/META-INF/services/org.apache.qpid.server.store.MessageStoreFactory
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+org.apache.qpid.server.store.MemoryMessageStoreFactory \ No newline at end of file
diff --git a/java/broker/src/main/resources/initial-store.json b/java/broker/src/main/resources/initial-store.json
new file mode 100644
index 0000000000..a80ad95bd4
--- /dev/null
+++ b/java/broker/src/main/resources/initial-store.json
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.
+ *
+ */
+{
+ "name": "QpidBroker",
+ "defaultAuthenticationProvider" : "defaultAuthenticationProvider",
+ "defaultVirtualHost" : "default",
+ "authenticationproviders" : [ {
+ "name" : "defaultAuthenticationProvider",
+ "authenticationProviderType" : "PlainPasswordFileAuthenticationProvider",
+ "path" : "${QPID_HOME}/etc/passwd"
+ } ],
+ "ports" : [ {
+ "name" : "5672-AMQP",
+ "port" : 5672
+ }, {
+ "name" : "8080-HTTP",
+ "port" : 8080,
+ "protocols" : [ "HTTP" ]
+ }, {
+ "name" : "8999-RMI",
+ "port" : 8999,
+ "protocols" : [ "RMI" ]
+ }, {
+ "name" : "9099-JMX_RMI",
+ "port" : 9099,
+ "protocols" : [ "JMX_RMI" ]
+ }],
+ "virtualhosts" : [ {
+ "name" : "default",
+ "storeType" : "DERBY",
+ "storePath" : "${QPID_WORK}/store"
+ } ],
+ "plugins" : [ {
+ "pluginType" : "MANAGEMENT-HTTP",
+ "name" : "httpManagement"
+ }, {
+ "pluginType" : "MANAGEMENT-JMX",
+ "name" : "jmxManagement"
+ } ]
+} \ No newline at end of file
diff --git a/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java b/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java
index fc6cbcb248..e10bdbbb35 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/AMQChannelTest.java
@@ -20,23 +20,69 @@
*/
package org.apache.qpid.server;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.abstraction.MessagePublishInfo;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.message.MessageContentSource;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class AMQChannelTest extends InternalBrokerBaseCase
+public class AMQChannelTest extends QpidTestCase
{
private VirtualHost _virtualHost;
private AMQProtocolSession _protocolSession;
+ private Map<Integer,String> _replies;
+ private Broker _broker;
@Override
public void setUp() throws Exception
{
super.setUp();
- _virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts().iterator().next();
- _protocolSession = new InternalTestProtocolSession(_virtualHost);
+ BrokerTestHelper.setUp();
+ _virtualHost = BrokerTestHelper.createVirtualHost(getTestName());
+ _broker = BrokerTestHelper.createBrokerMock();
+ _protocolSession = new InternalTestProtocolSession(_virtualHost, _broker)
+ {
+ @Override
+ public void writeReturn(MessagePublishInfo messagePublishInfo,
+ ContentHeaderBody header,
+ MessageContentSource msgContent,
+ int channelId,
+ int replyCode,
+ AMQShortString replyText) throws AMQException
+ {
+ _replies.put(replyCode, replyText.asString());
+ }
+ };
+ _replies = new HashMap<Integer, String>();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ _virtualHost.close();
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testCompareTo() throws Exception
@@ -44,9 +90,54 @@ public class AMQChannelTest extends InternalBrokerBaseCase
AMQChannel channel1 = new AMQChannel(_protocolSession, 1, _virtualHost.getMessageStore());
// create a channel with the same channelId but on a different session
- AMQChannel channel2 = new AMQChannel(new InternalTestProtocolSession(_virtualHost), 1, _virtualHost.getMessageStore());
+ AMQChannel channel2 = new AMQChannel(new InternalTestProtocolSession(_virtualHost, _broker), 1, _virtualHost.getMessageStore());
assertFalse("Unexpected compare result", channel1.compareTo(channel2) == 0);
assertEquals("Unexpected compare result", 0, channel1.compareTo(channel1));
}
+ public void testPublishContentHeaderWhenMessageAuthorizationFails() throws Exception
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_MSG_AUTH, "true");
+ AMQChannel channel = new AMQChannel(_protocolSession, 1, _virtualHost.getMessageStore());
+ channel.setLocalTransactional();
+
+ MessagePublishInfo info = mock(MessagePublishInfo.class);
+ Exchange e = mock(Exchange.class);
+ ContentHeaderBody contentHeaderBody= mock(ContentHeaderBody.class);
+ BasicContentHeaderProperties properties = mock(BasicContentHeaderProperties.class);
+
+ when(contentHeaderBody.getProperties()).thenReturn(properties);
+ when(info.getExchange()).thenReturn(new AMQShortString("test"));
+ when(properties.getUserId()).thenReturn(new AMQShortString(_protocolSession.getAuthorizedPrincipal().getName() + "_incorrect"));
+
+ channel.setPublishFrame(info, e);
+ channel.publishContentHeader(contentHeaderBody);
+ channel.commit();
+
+ assertEquals("Unexpected number of replies", 1, _replies.size());
+ assertEquals("Message authorization passed", "Access Refused", _replies.get(403));
+ }
+
+ public void testPublishContentHeaderWhenMessageAuthorizationPasses() throws Exception
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_MSG_AUTH, "true");
+ AMQChannel channel = new AMQChannel(_protocolSession, 1, _virtualHost.getMessageStore());
+ channel.setLocalTransactional();
+
+ MessagePublishInfo info = mock(MessagePublishInfo.class);
+ Exchange e = mock(Exchange.class);
+ ContentHeaderBody contentHeaderBody= mock(ContentHeaderBody.class);
+ BasicContentHeaderProperties properties = mock(BasicContentHeaderProperties.class);
+
+ when(contentHeaderBody.getProperties()).thenReturn(properties);
+ when(info.getExchange()).thenReturn(new AMQShortString("test"));
+ when(properties.getUserId()).thenReturn(new AMQShortString(_protocolSession.getAuthorizedPrincipal().getName()));
+
+ channel.setPublishFrame(info, e);
+ channel.publishContentHeader(contentHeaderBody);
+ channel.commit();
+
+ assertEquals("Unexpected number of replies", 0, _replies.size());
+ }
+
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java b/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
index 43824e713f..16b459b5d4 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
@@ -22,91 +22,36 @@ package org.apache.qpid.server;
import org.apache.qpid.test.utils.QpidTestCase;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-
public class BrokerOptionsTest extends QpidTestCase
{
private BrokerOptions _options;
-
- private static final int TEST_PORT1 = 6789;
- private static final int TEST_PORT2 = 6790;
-
protected void setUp()
{
_options = new BrokerOptions();
}
-
- public void testDefaultPort()
- {
- assertEquals(Collections.<Integer>emptySet(), _options.getPorts());
- }
- public void testOverriddenPort()
+ public void testDefaultConfigurationStoreType()
{
- _options.addPort(TEST_PORT1);
- assertEquals(Collections.singleton(TEST_PORT1), _options.getPorts());
+ assertEquals("json", _options.getConfigurationStoreType());
}
- public void testManyOverriddenPorts()
+ public void testOverriddenConfigurationStoreType()
{
- _options.addPort(TEST_PORT1);
- _options.addPort(TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getPorts());
+ _options.setConfigurationStoreType("dby");
+ assertEquals("dby", _options.getConfigurationStoreType());
}
- public void testDuplicateOverriddenPortsAreSilentlyIgnored()
+ public void testDefaultConfigurationStoreLocation()
{
- _options.addPort(TEST_PORT1);
- _options.addPort(TEST_PORT2);
- _options.addPort(TEST_PORT1); // duplicate - should be silently ignored
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getPorts());
+ assertNull(_options.getConfigurationStoreLocation());
}
- public void testDefaultSSLPort()
- {
- assertEquals(Collections.<Integer>emptySet(), _options.getSSLPorts());
- }
-
- public void testOverriddenSSLPort()
- {
- _options.addSSLPort(TEST_PORT1);
- assertEquals(Collections.singleton(TEST_PORT1), _options.getSSLPorts());
- }
-
- public void testManyOverriddenSSLPorts()
- {
- _options.addSSLPort(TEST_PORT1);
- _options.addSSLPort(TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getSSLPorts());
- }
-
- public void testDuplicateOverriddenSSLPortsAreSilentlyIgnored()
- {
- _options.addSSLPort(TEST_PORT1);
- _options.addSSLPort(TEST_PORT2);
- _options.addSSLPort(TEST_PORT1); // duplicate - should be silently ignored
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getSSLPorts());
- }
-
- public void testDefaultConfigFile()
- {
- assertNull(_options.getConfigFile());
- }
-
- public void testOverriddenConfigFile()
+ public void testOverriddenConfigurationStoreLocation()
{
final String testConfigFile = "etc/mytestconfig.xml";
- _options.setConfigFile(testConfigFile);
- assertEquals(testConfigFile, _options.getConfigFile());
+ _options.setConfigurationStoreLocation(testConfigFile);
+ assertEquals(testConfigFile, _options.getConfigurationStoreLocation());
}
public void testDefaultLogConfigFile()
@@ -121,109 +66,85 @@ public class BrokerOptionsTest extends QpidTestCase
assertEquals(testLogConfigFile, _options.getLogConfigFile());
}
- public void testDefaultJmxPortRegistryServer()
+ public void testDefaultLogWatchFrequency()
{
- assertNull(_options.getJmxPortRegistryServer());
+ assertEquals(0L, _options.getLogWatchFrequency());
}
- public void testJmxPortRegistryServer()
+ public void testOverridenLogWatchFrequency()
{
- _options.setJmxPortRegistryServer(TEST_PORT1);
- assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPortRegistryServer());
+ final int myFreq = 10 * 1000;
+
+ _options.setLogWatchFrequency(myFreq);
+ assertEquals(myFreq, _options.getLogWatchFrequency());
}
- public void testDefaultJmxPortConnectorServer()
- {
- assertNull(_options.getJmxPortConnectorServer());
- }
- public void testJmxPortConnectorServer()
+ public void testDefaultInitialConfigurationStoreType()
{
- _options.setJmxPortConnectorServer(TEST_PORT1);
- assertEquals(Integer.valueOf(TEST_PORT1), _options.getJmxPortConnectorServer());
+ assertEquals("json", _options.getInitialConfigurationStoreType());
}
- public void testQpidHomeExposesSysProperty()
+ public void testOverriddenInitialConfigurationStoreType()
{
- assertEquals(System.getProperty("QPID_HOME"), _options.getQpidHome());
- }
-
- public void testDefaultExcludesPortFor0_10()
- {
- assertEquals(Collections.EMPTY_SET, _options.getExcludedPorts(ProtocolExclusion.v0_10));
- }
-
- public void testOverriddenExcludesPortFor0_10()
- {
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1);
- assertEquals(Collections.singleton(TEST_PORT1), _options.getExcludedPorts(ProtocolExclusion.v0_10));
+ _options.setInitialConfigurationStoreType("dby");
+ assertEquals("dby", _options.getInitialConfigurationStoreType());
}
- public void testManyOverriddenExcludedPortFor0_10()
+ public void testDefaultInitialConfigurationStoreLocation()
{
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1);
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getExcludedPorts(ProtocolExclusion.v0_10));
+ assertNull(_options.getInitialConfigurationStoreLocation());
}
- public void testDuplicatedOverriddenExcludedPortFor0_10AreSilentlyIgnored()
+ public void testOverriddenInitialConfigurationStoreLocation()
{
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT1);
- _options.addExcludedPort(ProtocolExclusion.v0_10, TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getExcludedPorts(ProtocolExclusion.v0_10));
+ final String testConfigFile = "etc/mytestconfig.xml";
+ _options.setInitialConfigurationStoreLocation(testConfigFile);
+ assertEquals(testConfigFile, _options.getInitialConfigurationStoreLocation());
}
-
- public void testDefaultBind()
+
+ public void testDefaultManagementMode()
{
- assertNull(_options.getBind());
+ assertEquals(false, _options.isManagementMode());
}
-
- public void testOverriddenBind()
+
+ public void testOverriddenDefaultManagementMode()
{
- final String bind = "192.168.0.1";
- _options.setBind(bind);
- assertEquals(bind, _options.getBind());
+ _options.setManagementMode(true);
+ assertEquals(true, _options.isManagementMode());
}
- public void testDefaultLogWatchFrequency()
+ public void testDefaultManagementModeRmiPort()
{
- assertEquals(0L, _options.getLogWatchFrequency());
+ assertEquals(0, _options.getManagementModeRmiPort());
}
- public void testOverridenLogWatchFrequency()
+ public void testOverriddenDefaultManagementModeRmiPort()
{
- final int myFreq = 10 * 1000;
-
- _options.setLogWatchFrequency(myFreq);
- assertEquals(myFreq, _options.getLogWatchFrequency());
+ _options.setManagementModeRmiPort(5555);
+ assertEquals(5555, _options.getManagementModeRmiPort());
}
- public void testDefaultIncludesPortFor0_10()
+ public void testDefaultManagementModeConnectorPort()
{
- assertEquals(Collections.EMPTY_SET, _options.getIncludedPorts(ProtocolInclusion.v0_10));
+ assertEquals(0, _options.getManagementModeConnectorPort());
}
- public void testOverriddenIncludesPortFor0_10()
+ public void testOverriddenDefaultManagementModeConnectorPort()
{
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT1);
- assertEquals(Collections.singleton(TEST_PORT1), _options.getIncludedPorts(ProtocolInclusion.v0_10));
+ _options.setManagementModeConnectorPort(5555);
+ assertEquals(5555, _options.getManagementModeConnectorPort());
}
- public void testManyOverriddenIncludedPortFor0_10()
+ public void testDefaultManagementModeHttpPort()
{
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT1);
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getIncludedPorts(ProtocolInclusion.v0_10));
+ assertEquals(0, _options.getManagementModeHttpPort());
}
- public void testDuplicatedOverriddenIncludedPortFor0_10AreSilentlyIgnored()
+ public void testOverriddenDefaultManagementModeHttpPort()
{
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT1);
- _options.addIncludedPort(ProtocolInclusion.v0_10, TEST_PORT2);
- final Set<Integer> expectedPorts = new HashSet<Integer>(Arrays.asList(new Integer[] {TEST_PORT1, TEST_PORT2}));
- assertEquals(expectedPorts, _options.getIncludedPorts(ProtocolInclusion.v0_10));
+ _options.setManagementModeHttpPort(5555);
+ assertEquals(5555, _options.getManagementModeHttpPort());
}
+
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/MainTest.java b/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
index ffd607574e..cab54b1310 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
@@ -23,8 +23,6 @@ package org.apache.qpid.server;
import org.apache.commons.cli.CommandLine;
import org.apache.qpid.test.utils.QpidTestCase;
-import java.util.EnumSet;
-
/**
* Test to verify the command line parsing within the Main class, by
* providing it a series of command line arguments and verifying the
@@ -36,149 +34,135 @@ public class MainTest extends QpidTestCase
{
BrokerOptions options = startDummyMain("");
- assertTrue(options.getPorts().isEmpty());
- assertTrue(options.getSSLPorts().isEmpty());
- assertEquals(null, options.getJmxPortRegistryServer());
- assertEquals(null, options.getConfigFile());
+ assertEquals("json", options.getConfigurationStoreType());
+ assertEquals(null, options.getConfigurationStoreLocation());
assertEquals(null, options.getLogConfigFile());
- assertEquals(null, options.getBind());
-
- for(ProtocolExclusion pe : EnumSet.allOf(ProtocolExclusion.class))
- {
- assertEquals(0, options.getExcludedPorts(pe).size());
- }
+ assertEquals(0, options.getLogWatchFrequency());
+ assertEquals("json", options.getInitialConfigurationStoreType());
+ assertEquals(null, options.getInitialConfigurationStoreLocation());
- for(ProtocolInclusion pe : EnumSet.allOf(ProtocolInclusion.class))
- {
- assertEquals(0, options.getIncludedPorts(pe).size());
- }
+ assertFalse(options.isManagementMode());
+ assertEquals(0, options.getManagementModeConnectorPort());
+ assertEquals(0, options.getManagementModeRmiPort());
+ assertEquals(0, options.getManagementModeHttpPort());
}
- public void testPortOverriddenSingle()
+ public void testConfigurationStoreLocation()
{
- BrokerOptions options = startDummyMain("-p 1234");
+ BrokerOptions options = startDummyMain("-sp abcd/config.xml");
+ assertEquals("abcd/config.xml", options.getConfigurationStoreLocation());
- assertTrue(options.getPorts().contains(1234));
- assertEquals(1, options.getPorts().size());
- assertTrue(options.getSSLPorts().isEmpty());
+ options = startDummyMain("-store-path abcd/config2.xml");
+ assertEquals("abcd/config2.xml", options.getConfigurationStoreLocation());
}
- public void testPortOverriddenMultiple()
+ public void testConfigurationStoreType()
{
- BrokerOptions options = startDummyMain("-p 1234 -p 4321");
+ BrokerOptions options = startDummyMain("-st dby");
+ assertEquals("dby", options.getConfigurationStoreType());
- assertTrue(options.getPorts().contains(1234));
- assertTrue(options.getPorts().contains(4321));
- assertEquals(2, options.getPorts().size());
- assertTrue(options.getSSLPorts().isEmpty());
+ options = startDummyMain("-store-type bdb");
+ assertEquals("bdb", options.getConfigurationStoreType());
}
- public void testSSLPortOverriddenSingle()
+ public void testLogConfig()
{
- BrokerOptions options = startDummyMain("-s 5678");
+ BrokerOptions options = startDummyMain("-l wxyz/log4j.xml");
- assertTrue(options.getSSLPorts().contains(5678));
- assertEquals(1, options.getSSLPorts().size());
- assertTrue(options.getPorts().isEmpty());
+ assertEquals("wxyz/log4j.xml", options.getLogConfigFile());
}
- public void testSSLPortOverriddenMultiple()
+ public void testLogWatch()
{
- BrokerOptions options = startDummyMain("-s 5678 -s 8765");
+ BrokerOptions options = startDummyMain("-w 9");
- assertTrue(options.getSSLPorts().contains(5678));
- assertTrue(options.getSSLPorts().contains(8765));
- assertEquals(2, options.getSSLPorts().size());
- assertTrue(options.getPorts().isEmpty());
+ assertEquals(9, options.getLogWatchFrequency());
}
- public void testNonSSLandSSLPortsOverridden()
+ public void testVersion()
{
- BrokerOptions options = startDummyMain("-p 5678 -s 8765");
+ final TestMain main = new TestMain("-v".split("\\s"));
- assertTrue(options.getPorts().contains(5678));
- assertTrue(options.getSSLPorts().contains(8765));
- assertEquals(1, options.getPorts().size());
- assertEquals(1, options.getSSLPorts().size());
+ assertNotNull("Command line not parsed correctly", main.getCommandLine());
+ assertTrue("Parsed command line didnt pick up version option", main.getCommandLine().hasOption("v"));
}
- public void testJmxPortRegistryServerOverridden()
+ public void testHelp()
{
- BrokerOptions options = startDummyMain("--jmxregistryport 3456");
-
- assertEquals(Integer.valueOf(3456), options.getJmxPortRegistryServer());
+ final TestMain main = new TestMain("-h".split("\\s"));
- options = startDummyMain("-m 3457");
- assertEquals(Integer.valueOf(3457), options.getJmxPortRegistryServer());
+ assertNotNull("Command line not parsed correctly", main.getCommandLine());
+ assertTrue("Parsed command line didnt pick up help option", main.getCommandLine().hasOption("h"));
}
- public void testJmxPortConnectorServerOverridden()
+ public void testInitailConfigurationStoreLocation()
{
- BrokerOptions options = startDummyMain("--jmxconnectorport 3456");
+ BrokerOptions options = startDummyMain("-isp abcd/config.xml");
+ assertEquals("abcd/config.xml", options.getInitialConfigurationStoreLocation());
- assertEquals(Integer.valueOf(3456), options.getJmxPortConnectorServer());
+ options = startDummyMain("-initial-store-path abcd/config.xml");
+ assertEquals("abcd/config.xml", options.getInitialConfigurationStoreLocation());
}
- public void testExclude0_10()
+ public void testInitialConfigurationStoreType()
{
- BrokerOptions options = startDummyMain("-p 3456 --exclude-0-10 3456");
+ BrokerOptions options = startDummyMain("-ist dby");
+ assertEquals("dby", options.getInitialConfigurationStoreType());
- assertTrue(options.getPorts().contains(3456));
- assertEquals(1, options.getPorts().size());
- assertTrue(options.getExcludedPorts(ProtocolExclusion.v0_10).contains(3456));
- assertEquals(1, options.getExcludedPorts(ProtocolExclusion.v0_10).size());
- assertEquals(0, options.getExcludedPorts(ProtocolExclusion.v0_9_1).size());
- }
-
- public void testConfig()
- {
- BrokerOptions options = startDummyMain("-c abcd/config.xml");
+ options = startDummyMain("-initial-store-type bdb");
+ assertEquals("bdb", options.getInitialConfigurationStoreType());
- assertEquals("abcd/config.xml", options.getConfigFile());
}
- public void testLogConfig()
+ public void testManagementMode()
{
- BrokerOptions options = startDummyMain("-l wxyz/log4j.xml");
+ BrokerOptions options = startDummyMain("-mm");
+ assertTrue(options.isManagementMode());
- assertEquals("wxyz/log4j.xml", options.getLogConfigFile());
+ options = startDummyMain("--management-mode");
+ assertTrue(options.isManagementMode());
}
- public void testLogWatch()
+ public void testManagementModeRmiPort()
{
- BrokerOptions options = startDummyMain("-w 9");
+ BrokerOptions options = startDummyMain("-mm -rmi 7777");
+ assertTrue(options.isManagementMode());
+ assertEquals(7777, options.getManagementModeRmiPort());
- assertEquals(9, options.getLogWatchFrequency());
+ options = startDummyMain("-mm --jmxregistryport 7777");
+ assertTrue(options.isManagementMode());
+ assertEquals(7777, options.getManagementModeRmiPort());
+
+ options = startDummyMain("-rmi 7777");
+ assertEquals(0, options.getManagementModeRmiPort());
}
- public void testVersion()
+ public void testManagementModeConnectorPort()
{
- final TestMain main = new TestMain("-v".split("\\s"));
+ BrokerOptions options = startDummyMain("-mm -jmxrmi 8888");
+ assertTrue(options.isManagementMode());
+ assertEquals(8888, options.getManagementModeConnectorPort());
- assertNotNull("Command line not parsed correctly", main.getCommandLine());
- assertTrue("Parsed command line didnt pick up version option", main.getCommandLine().hasOption("v"));
+ options = startDummyMain("-mm --jmxconnectorport 8888");
+ assertTrue(options.isManagementMode());
+ assertEquals(8888, options.getManagementModeConnectorPort());
+
+ options = startDummyMain("-jmxrmi 8888");
+ assertEquals(0, options.getManagementModeConnectorPort());
}
- public void testHelp()
+ public void testManagementModeHttpPort()
{
- final TestMain main = new TestMain("-h".split("\\s"));
+ BrokerOptions options = startDummyMain("-mm -http 9999");
+ assertTrue(options.isManagementMode());
+ assertEquals(9999, options.getManagementModeHttpPort());
- assertNotNull("Command line not parsed correctly", main.getCommandLine());
- assertTrue("Parsed command line didnt pick up help option", main.getCommandLine().hasOption("h"));
- }
+ options = startDummyMain("-mm --httpport 9999");
+ assertTrue(options.isManagementMode());
+ assertEquals(9999, options.getManagementModeHttpPort());
- public void testInclude010()
- {
- BrokerOptions options = startDummyMain("-p 5678 --include-0-10 5678");
-
- assertTrue(options.getPorts().contains(5678));
- assertEquals(1, options.getPorts().size());
- assertTrue(options.getIncludedPorts(ProtocolInclusion.v0_10).contains(5678));
- assertEquals(1, options.getIncludedPorts(ProtocolInclusion.v0_10).size());
- assertEquals(0, options.getIncludedPorts(ProtocolInclusion.v0_9_1).size());
- assertEquals(0, options.getIncludedPorts(ProtocolInclusion.v0_9).size());
- assertEquals(0, options.getIncludedPorts(ProtocolInclusion.v0_8).size());
- assertEquals(0, options.getIncludedPorts(ProtocolInclusion.v1_0).size());
+ options = startDummyMain("-http 9999");
+ assertEquals(0, options.getManagementModeHttpPort());
}
private BrokerOptions startDummyMain(String commandLine)
diff --git a/java/broker/src/test/java/org/apache/qpid/server/TransactionTimeoutHelperTest.java b/java/broker/src/test/java/org/apache/qpid/server/TransactionTimeoutHelperTest.java
index 9081dc49d6..96078d766c 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/TransactionTimeoutHelperTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/TransactionTimeoutHelperTest.java
@@ -18,67 +18,131 @@
*/
package org.apache.qpid.server;
-import static org.mockito.Matchers.any;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.qpid.server.logging.messages.ChannelMessages.IDLE_TXN_LOG_HIERARCHY;
+import static org.apache.qpid.server.logging.messages.ChannelMessages.OPEN_TXN_LOG_HIERARCHY;
+import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
+import org.apache.qpid.server.TransactionTimeoutHelper.CloseAction;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogMessage;
import org.apache.qpid.server.logging.LogSubject;
-import org.apache.qpid.server.logging.RootMessageLogger;
import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.txn.ServerTransaction;
import org.apache.qpid.test.utils.QpidTestCase;
+import org.hamcrest.Description;
+import org.mockito.ArgumentMatcher;
public class TransactionTimeoutHelperTest extends QpidTestCase
{
- private final LogMessage _logMessage = mock(LogMessage.class);
private final LogActor _logActor = mock(LogActor.class);
private final LogSubject _logSubject = mock(LogSubject.class);
+ private final ServerTransaction _transaction = mock(ServerTransaction.class);
+ private final CloseAction _closeAction = mock(CloseAction.class);
private TransactionTimeoutHelper _transactionTimeoutHelper;
- private RootMessageLogger _rootMessageLogger;
+ private long _now;
- public void testLogIfNecessary()
+ public void testNotTransactional() throws Exception
{
- _transactionTimeoutHelper.logIfNecessary(99, 100, _logMessage, "");
- verifyZeroInteractions(_logActor, _logMessage);
+ when(_transaction.isTransactional()).thenReturn(false);
- _transactionTimeoutHelper.logIfNecessary(101, 100, _logMessage, "");
- verify(_logActor).message(_logSubject, _logMessage);
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, 5, 10, 5, 10);
+
+ verifyZeroInteractions(_logActor, _closeAction);
+ }
+
+ public void testOpenTransactionProducesWarningOnly() throws Exception
+ {
+ final long sixtyOneSecondsAgo = _now - SECONDS.toMillis(61);
+
+ configureMockTransaction(sixtyOneSecondsAgo, sixtyOneSecondsAgo);
+
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, SECONDS.toMillis(30), 0, 0, 0);
+
+ verify(_logActor).message(same(_logSubject), isLogMessage(OPEN_TXN_LOG_HIERARCHY, "CHN-1007 : Open Transaction : 61,\\d{3} ms"));
+ verifyZeroInteractions(_closeAction);
+ }
+
+ public void testOpenTransactionProducesTimeoutActionOnly() throws Exception
+ {
+ final long sixtyOneSecondsAgo = _now - SECONDS.toMillis(61);
+
+ configureMockTransaction(sixtyOneSecondsAgo, sixtyOneSecondsAgo);
+
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, 0, SECONDS.toMillis(30), 0, 0);
+
+ verify(_closeAction).doTimeoutAction("Open transaction timed out");
+ verifyZeroInteractions(_logActor);
}
- public void testLogIfNecessaryWhenOperationalLoggingDisabled()
+ public void testOpenTransactionProducesWarningAndTimeoutAction() throws Exception
{
- //disable the operational logging
- when(_rootMessageLogger.isMessageEnabled(
- same(_logActor), any(LogSubject.class), any(String.class)))
- .thenReturn(false);
-
- //verify the actor is never asked to log a message
- _transactionTimeoutHelper.logIfNecessary(101, 100, _logMessage, "");
- verify(_logActor, never()).message(any(LogMessage.class));
- verify(_logActor, never()).message(any(LogSubject.class), any(LogMessage.class));
+ final long sixtyOneSecondsAgo = _now - SECONDS.toMillis(61);
+
+ configureMockTransaction(sixtyOneSecondsAgo, sixtyOneSecondsAgo);
+
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, SECONDS.toMillis(15), SECONDS.toMillis(30), 0, 0);
+
+ verify(_logActor).message(same(_logSubject), isLogMessage(OPEN_TXN_LOG_HIERARCHY, "CHN-1007 : Open Transaction : 61,\\d{3} ms"));
+ verify(_closeAction).doTimeoutAction("Open transaction timed out");
}
- public void testIsTimedOut()
+ public void testIdleTransactionProducesWarningOnly() throws Exception
{
- assertFalse("Shouldn't have timed out", _transactionTimeoutHelper.isTimedOut(199,200));
- assertTrue("Should have timed out", _transactionTimeoutHelper.isTimedOut(201,200));
+ final long sixtyOneSecondsAgo = _now - SECONDS.toMillis(61);
+ final long thrityOneSecondsAgo = _now - SECONDS.toMillis(31);
+
+ configureMockTransaction(sixtyOneSecondsAgo, thrityOneSecondsAgo);
+
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, 0, 0, SECONDS.toMillis(30), 0);
+
+ verify(_logActor).message(same(_logSubject), isLogMessage(IDLE_TXN_LOG_HIERARCHY, "CHN-1008 : Idle Transaction : 31,\\d{3} ms"));
+ verifyZeroInteractions(_closeAction);
}
- /**
- * If TransactionTimeout is disabled, the timeout will be 0. This test verifies
- * that the helper methods respond negatively in this scenario.
- */
- public void testTransactionTimeoutDisabled()
+ public void testIdleTransactionProducesTimeoutActionOnly() throws Exception
{
- assertFalse("Shouldn't have timed out", _transactionTimeoutHelper.isTimedOut(201,0));
+ final long sixtyOneSecondsAgo = _now - SECONDS.toMillis(61);
+ final long thrityOneSecondsAgo = _now - SECONDS.toMillis(31);
+
+ configureMockTransaction(sixtyOneSecondsAgo, thrityOneSecondsAgo);
- _transactionTimeoutHelper.logIfNecessary(99, 0, _logMessage, "");
- verifyZeroInteractions(_logActor, _logMessage);
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, 0, 0, 0, SECONDS.toMillis(30));
+
+ verify(_closeAction).doTimeoutAction("Idle transaction timed out");
+ verifyZeroInteractions(_logActor);
+ }
+
+ public void testIdleTransactionProducesWarningAndTimeoutAction() throws Exception
+ {
+ final long sixtyOneSecondsAgo = _now - SECONDS.toMillis(61);
+ final long thrityOneSecondsAgo = _now - SECONDS.toMillis(31);
+
+ configureMockTransaction(sixtyOneSecondsAgo, thrityOneSecondsAgo);
+
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, 0, 0, SECONDS.toMillis(15), SECONDS.toMillis(30));
+
+ verify(_logActor).message(same(_logSubject), isLogMessage(IDLE_TXN_LOG_HIERARCHY, "CHN-1008 : Idle Transaction : 31,\\d{3} ms"));
+ verify(_closeAction).doTimeoutAction("Idle transaction timed out");
+ }
+
+ public void testIdleAndOpenWarnings() throws Exception
+ {
+ final long sixtyOneSecondsAgo = _now - SECONDS.toMillis(61);
+ final long thirtyOneSecondsAgo = _now - SECONDS.toMillis(31);
+
+ configureMockTransaction(sixtyOneSecondsAgo, thirtyOneSecondsAgo);
+
+ _transactionTimeoutHelper.checkIdleOrOpenTimes(_transaction, SECONDS.toMillis(60), 0, SECONDS.toMillis(30), 0);
+
+ verify(_logActor).message(same(_logSubject), isLogMessage(IDLE_TXN_LOG_HIERARCHY, "CHN-1008 : Idle Transaction : 31,\\d{3} ms"));
+ verify(_logActor).message(same(_logSubject), isLogMessage(OPEN_TXN_LOG_HIERARCHY, "CHN-1007 : Open Transaction : 61,\\d{3} ms"));
+ verifyZeroInteractions(_closeAction);
}
@Override
@@ -88,14 +152,79 @@ public class TransactionTimeoutHelperTest extends QpidTestCase
CurrentActor.set(_logActor);
- _rootMessageLogger = mock(RootMessageLogger.class);
- when(_logActor.getRootMessageLogger()).thenReturn(_rootMessageLogger);
+ _transactionTimeoutHelper = new TransactionTimeoutHelper(_logSubject, _closeAction);
+ _now = System.currentTimeMillis();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ CurrentActor.remove();
+ }
+ }
- when(_rootMessageLogger.isMessageEnabled(
- same(_logActor), any(LogSubject.class), any(String.class)))
- .thenReturn(true);
+ private void configureMockTransaction(final long startTime, final long updateTime)
+ {
+ when(_transaction.isTransactional()).thenReturn(true);
+ when(_transaction.getTransactionStartTime()).thenReturn(startTime);
+ when(_transaction.getTransactionUpdateTime()).thenReturn(updateTime);
+ }
- _transactionTimeoutHelper = new TransactionTimeoutHelper(_logSubject);
+ private LogMessage isLogMessage(String expectedlogHierarchy, String expectedText)
+ {
+ return argThat(new IsLogMessage(expectedlogHierarchy, expectedText));
}
+ class IsLogMessage extends ArgumentMatcher<LogMessage>
+ {
+ private final String _expectedLogHierarchy;
+ private final String _expectedLogMessageMatches;
+ private String _hierarchyMatchesFailure;
+ private String _logMessageMatchesFailure;
+
+ public IsLogMessage(String expectedlogHierarchy, String expectedLogMessageMatches)
+ {
+ _expectedLogHierarchy = expectedlogHierarchy;
+ _expectedLogMessageMatches = expectedLogMessageMatches;
+ }
+
+ public boolean matches(Object arg)
+ {
+ LogMessage logMessage = (LogMessage)arg;
+
+ boolean hierarchyMatches = logMessage.getLogHierarchy().equals(_expectedLogHierarchy);
+ boolean logMessageMatches = logMessage.toString().matches(_expectedLogMessageMatches);
+
+ if (!hierarchyMatches)
+ {
+ _hierarchyMatchesFailure = "LogHierarchy does not match. Expected " + _expectedLogHierarchy + " actual " + logMessage.getLogHierarchy();
+ }
+
+ if (!logMessageMatches)
+ {
+ _logMessageMatchesFailure = "LogMessage does not match. Expected " + _expectedLogMessageMatches + " actual " + logMessage.toString();
+ }
+
+ return hierarchyMatches && logMessageMatches;
+ }
+
+ @Override
+ public void describeTo(Description description)
+ {
+ if (_hierarchyMatchesFailure != null)
+ {
+ description.appendText(_hierarchyMatchesFailure);
+ }
+ if (_logMessageMatchesFailure != null)
+ {
+ description.appendText(_logMessageMatchesFailure);
+ }
+ }
+ }
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java b/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java
index b3223f16c4..4d6d60906d 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java
@@ -22,14 +22,72 @@ package org.apache.qpid.server.ack;
import org.apache.qpid.AMQException;
+import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.queue.SimpleAMQQueue;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.TestableMemoryMessageStore;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
-public class AcknowledgeTest extends InternalBrokerBaseCase
+public class AcknowledgeTest extends QpidTestCase
{
+ private AMQChannel _channel;
+ private SimpleAMQQueue _queue;
+ private MessageStore _messageStore;
+ private String _queueName;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel();
+ VirtualHost virtualHost = _channel.getVirtualHost();
+ _queueName = getTestName();
+ _queue = BrokerTestHelper.createQueue(_queueName, virtualHost);
+ _messageStore = virtualHost.getMessageStore();
+ Exchange defaultExchange = virtualHost.getExchangeRegistry().getDefaultExchange();
+ virtualHost.getBindingFactory().addBinding(_queueName, _queue, defaultExchange, null);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_channel != null)
+ {
+ _channel.getVirtualHost().close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ private AMQChannel getChannel()
+ {
+ return _channel;
+ }
+
+ private InternalTestProtocolSession getSession()
+ {
+ return (InternalTestProtocolSession)_channel.getProtocolSession();
+ }
+
+ private SimpleAMQQueue getQueue()
+ {
+ return _queue;
+ }
public void testTransactionalSingleAck() throws AMQException
{
@@ -70,7 +128,7 @@ public class AcknowledgeTest extends InternalBrokerBaseCase
checkStoreContents(0);
//Send required messsages to the queue
- publishMessages(getSession(), getChannel(), sendMessageCount);
+ BrokerTestHelper.publishMessages(getChannel(), sendMessageCount, _queueName, ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString());
if (getChannel().isTransactional())
{
@@ -84,7 +142,7 @@ public class AcknowledgeTest extends InternalBrokerBaseCase
assertEquals("Channel should have no unacked msgs ", 0, getChannel().getUnacknowledgedMessageMap().size());
//Subscribe to the queue
- AMQShortString subscriber = subscribe(getSession(), getChannel(), getQueue());
+ AMQShortString subscriber = _channel.subscribeToQueue(null, _queue, true, null, false, true);
getQueue().deliverAsync();
@@ -117,4 +175,9 @@ public class AcknowledgeTest extends InternalBrokerBaseCase
checkStoreContents(remainingUnackedMessages);
}
+ private void checkStoreContents(int messageCount)
+ {
+ assertEquals("Message header count incorrect in the MetaDataMap", messageCount, ((TestableMemoryMessageStore) _messageStore).getMessageCount());
+ }
+
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
new file mode 100644
index 0000000000..fa1bd966a7
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
@@ -0,0 +1,144 @@
+/*
+ *
+ * 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.configuration;
+
+import java.io.File;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.apache.qpid.util.FileUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class BrokerConfigurationStoreCreatorTest extends QpidTestCase
+{
+ private File _userStoreLocation;
+ private BrokerConfigurationStoreCreator _storeCreator;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ // check whether QPID_HOME JVM system property is set
+ if (QPID_HOME == null)
+ {
+ // set the properties in order to resolve the defaults store settings
+ setTestSystemProperty("QPID_HOME", TMP_FOLDER);
+ }
+ _storeCreator = new BrokerConfigurationStoreCreator();
+ _userStoreLocation = new File(TMP_FOLDER, "_store_" + System.currentTimeMillis() + "_" + getTestName());
+ }
+
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ if (_userStoreLocation != null)
+ {
+ FileUtils.delete(_userStoreLocation, true);
+ }
+ }
+ }
+
+ public void testCreateJsonStore()
+ {
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", null, null);
+ assertNotNull("Store was not created", store);
+ assertTrue("File should exists", _userStoreLocation.exists());
+ assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0);
+ JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore();
+ jsonStore.open(_userStoreLocation.getAbsolutePath());
+ Set<UUID> childrenIds = jsonStore.getRootEntry().getChildrenIds();
+ assertFalse("Unexpected children: " + childrenIds, childrenIds.isEmpty());
+ }
+
+ public void testCreateJsonStoreFromInitialStore() throws Exception
+ {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+
+ Map<String, Object> brokerObjectMap = new HashMap<String, Object>();
+ UUID brokerId = UUID.randomUUID();
+ brokerObjectMap.put(Broker.ID, brokerId);
+ brokerObjectMap.put("name", "Test");
+
+ StringWriter sw = new StringWriter();
+ objectMapper.writeValue(sw, brokerObjectMap);
+
+ String brokerJson = sw.toString();
+
+ File _storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
+
+ ConfigurationEntryStore store = _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "json", _storeFile.getAbsolutePath(), "json");
+ assertNotNull("Store was not created", store);
+ assertTrue("File should exists", _userStoreLocation.exists());
+ assertTrue("File size should be greater than 0", _userStoreLocation.length() > 0);
+ JsonConfigurationEntryStore jsonStore = new JsonConfigurationEntryStore();
+ jsonStore.open(_userStoreLocation.getAbsolutePath());
+ ConfigurationEntry entry = jsonStore.getRootEntry();
+ assertEquals("Unexpected root id", brokerId, entry.getId());
+ Map<String, Object> attributes = entry.getAttributes();
+ assertNotNull("Unexpected attributes: " + attributes, attributes);
+ assertEquals("Unexpected attributes size: " + attributes.size(), 1, attributes.size());
+ assertEquals("Unexpected attribute name: " + attributes.get("name"), "Test", attributes.get("name"));
+ Set<UUID> childrenIds = entry.getChildrenIds();
+ assertTrue("Unexpected children: " + childrenIds, childrenIds.isEmpty());
+ }
+
+ public void testCreateDerbyStore()
+ {
+ //TODO: Implement DERBY store
+ try
+ {
+ _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "derby", null, null);
+ fail("Store is not yet supported");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+ public void testCreateXmlStore() throws Exception
+ {
+ try
+ {
+ _storeCreator.createStore(_userStoreLocation.getAbsolutePath(), "xml", null, null);
+ fail("Store is not yet supported");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerPropertiesTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerPropertiesTest.java
new file mode 100644
index 0000000000..5e9e19ffaf
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/BrokerPropertiesTest.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.server.configuration;
+
+import java.util.Locale;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class BrokerPropertiesTest extends QpidTestCase
+{
+ public void testGetLocaleDefault()
+ {
+ Locale locale = BrokerProperties.getLocale();
+ assertEquals("Unexpected locale", Locale.US, locale);
+ }
+
+ public void testGetLocaleSetWithJVMProperty()
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_LOCALE, "en_GB");
+ Locale locale = BrokerProperties.getLocale();
+ assertEquals("Unexpected locale", Locale.UK, locale);
+ }
+
+ public void testGetLocaleSetWithJVMPropertyInUnexpectedFormat()
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_LOCALE, "penguins_ANTARCTIC_Moubray_Bay");
+ Locale locale = BrokerProperties.getLocale();
+ assertEquals("Unexpected locale language", "penguins", locale.getLanguage());
+ assertEquals("Unexpected locale country", "ANTARCTIC", locale.getCountry());
+ assertEquals("Unexpected locale country", "Moubray_Bay", locale.getVariant());
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/MockConnectionConfig.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/MockConnectionConfig.java
deleted file mode 100644
index 00e5cd1222..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/configuration/MockConnectionConfig.java
+++ /dev/null
@@ -1,171 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import java.util.UUID;
-
-public class MockConnectionConfig implements ConnectionConfig
-{
-
- public MockConnectionConfig(UUID _qmfId, ConnectionConfigType _configType,
- ConfiguredObject<ConnectionConfigType, ConnectionConfig> _parent, boolean _durable,
- long _createTime, VirtualHostConfig _virtualHost, String _address, Boolean _incoming,
- Boolean _systemConnection, Boolean _federationLink, String _authId, String _remoteProcessName,
- Integer _remotePID, Integer _remoteParentPID, ConfigStore _configStore, Boolean _shadow)
- {
- super();
- this._qmfId = _qmfId;
- this._configType = _configType;
- this._parent = _parent;
- this._durable = _durable;
- this._createTime = _createTime;
- this._virtualHost = _virtualHost;
- this._address = _address;
- this._incoming = _incoming;
- this._systemConnection = _systemConnection;
- this._federationLink = _federationLink;
- this._authId = _authId;
- this._remoteProcessName = _remoteProcessName;
- this._remotePID = _remotePID;
- this._remoteParentPID = _remoteParentPID;
- this._configStore = _configStore;
- this._shadow = _shadow;
- }
-
- private UUID _qmfId;
- private ConnectionConfigType _configType;
- private ConfiguredObject<ConnectionConfigType, ConnectionConfig> _parent;
- private boolean _durable;
- private long _createTime;
- private VirtualHostConfig _virtualHost;
- private String _address;
- private Boolean _incoming;
- private Boolean _systemConnection;
- private Boolean _federationLink;
- private String _authId;
- private String _remoteProcessName;
- private Integer _remotePID;
- private Integer _remoteParentPID;
- private ConfigStore _configStore;
- private Boolean _shadow;
-
- @Override
- public UUID getQMFId()
- {
- return _qmfId;
- }
-
- @Override
- public ConnectionConfigType getConfigType()
- {
- return _configType;
- }
-
- @Override
- public ConfiguredObject<ConnectionConfigType, ConnectionConfig> getParent()
- {
- return _parent;
- }
-
- @Override
- public boolean isDurable()
- {
- return _durable;
- }
-
- @Override
- public long getCreateTime()
- {
- return _createTime;
- }
-
- @Override
- public VirtualHostConfig getVirtualHost()
- {
- return _virtualHost;
- }
-
- @Override
- public String getAddress()
- {
- return _address;
- }
-
- @Override
- public Boolean isIncoming()
- {
- return _incoming;
- }
-
- @Override
- public Boolean isSystemConnection()
- {
- return _systemConnection;
- }
-
- @Override
- public Boolean isFederationLink()
- {
- return _federationLink;
- }
-
- @Override
- public String getAuthId()
- {
- return _authId;
- }
-
- @Override
- public String getRemoteProcessName()
- {
- return _remoteProcessName;
- }
-
- @Override
- public Integer getRemotePID()
- {
- return _remotePID;
- }
-
- @Override
- public Integer getRemoteParentPID()
- {
- return _remoteParentPID;
- }
-
- @Override
- public ConfigStore getConfigStore()
- {
- return _configStore;
- }
-
- @Override
- public Boolean isShadow()
- {
- return _shadow;
- }
-
- @Override
- public void mgmtClose()
- {
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java
index 3c5b85cd90..0bb65479ce 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/QueueConfigurationTest.java
@@ -20,25 +20,31 @@
*/
package org.apache.qpid.server.configuration;
+import static org.mockito.Mockito.when;
+
import junit.framework.TestCase;
import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.util.BrokerTestHelper;
public class QueueConfigurationTest extends TestCase
{
-
private VirtualHostConfiguration _emptyConf;
private PropertiesConfiguration _env;
private VirtualHostConfiguration _fullHostConf;
+ private Broker _broker;
+ @Override
public void setUp() throws Exception
{
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _broker = BrokerTestHelper.createBrokerMock();
_env = new PropertiesConfiguration();
- _emptyConf = new VirtualHostConfiguration("test", _env);
+ _emptyConf = new VirtualHostConfiguration("test", _env, _broker);
PropertiesConfiguration fullEnv = new PropertiesConfiguration();
fullEnv.setProperty("queues.maximumMessageAge", 1);
@@ -49,35 +55,41 @@ public class QueueConfigurationTest extends TestCase
fullEnv.setProperty("queues.deadLetterQueues", true);
fullEnv.setProperty("queues.maximumDeliveryCount", 5);
- _fullHostConf = new VirtualHostConfiguration("test", fullEnv);
+ _fullHostConf = new VirtualHostConfiguration("test", fullEnv, _broker);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+
public void testMaxDeliveryCount() throws Exception
{
- try
- {
- ApplicationRegistry registry = new TestApplicationRegistry(new ServerConfiguration(_env));
- ApplicationRegistry.initialise(registry);
-
- // Check default value
- QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
- assertEquals("Unexpected default server configuration for max delivery count ", 0, qConf.getMaxDeliveryCount());
-
- // Check explicit value
- VirtualHostConfiguration vhostConfig = overrideConfiguration("maximumDeliveryCount", 7);
- qConf = new QueueConfiguration("test", vhostConfig);
- assertEquals("Unexpected host configuration for max delivery count", 7, qConf.getMaxDeliveryCount());
-
- // Check inherited value
- qConf = new QueueConfiguration("test", _fullHostConf);
- assertEquals("Unexpected queue configuration for max delivery count", 5, qConf.getMaxDeliveryCount());
-
- }
- finally
- {
- ApplicationRegistry.remove();
- }
+ // broker MAXIMUM_DELIVERY_ATTEMPTS attribute is not set
+ when(_broker.getAttribute(Broker.MAXIMUM_DELIVERY_ATTEMPTS)).thenReturn(null);
+
+ // Check default value
+ QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
+ assertEquals("Unexpected default server configuration for max delivery count ", 0, qConf.getMaxDeliveryCount());
+
+ // set broker MAXIMUM_DELIVERY_ATTEMPTS attribute to 2
+ when(_broker.getAttribute(Broker.MAXIMUM_DELIVERY_ATTEMPTS)).thenReturn(2);
+
+ // Check that queue inherits the MAXIMUM_DELIVERY_ATTEMPTS value from broker
+ qConf = new QueueConfiguration("test", _emptyConf);
+ assertEquals("Unexpected default server configuration for max delivery count ", 2, qConf.getMaxDeliveryCount());
+
+ // Check explicit value
+ VirtualHostConfiguration vhostConfig = overrideConfiguration("maximumDeliveryCount", 7);
+ qConf = new QueueConfiguration("test", vhostConfig);
+ assertEquals("Unexpected host configuration for max delivery count", 7, qConf.getMaxDeliveryCount());
+
+ // Check inherited value
+ qConf = new QueueConfiguration("test", _fullHostConf);
+ assertEquals("Unexpected queue configuration for max delivery count", 5, qConf.getMaxDeliveryCount());
}
/**
@@ -87,28 +99,28 @@ public class QueueConfigurationTest extends TestCase
*/
public void testIsDeadLetterQueueEnabled() throws Exception
{
- try
- {
- ApplicationRegistry registry = new TestApplicationRegistry(new ServerConfiguration(_env));
- ApplicationRegistry.initialise(registry);
-
- // Check default value
- QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
- assertFalse("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
-
- // Check explicit value
- VirtualHostConfiguration vhostConfig = overrideConfiguration("deadLetterQueues", true);
- qConf = new QueueConfiguration("test", vhostConfig);
- assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
-
- // Check inherited value
- qConf = new QueueConfiguration("test", _fullHostConf);
- assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
- }
- finally
- {
- ApplicationRegistry.remove();
- }
+ // enable dead letter queues broker wide
+ when(_broker.getAttribute(Broker.DEAD_LETTER_QUEUE_ENABLED)).thenReturn(true);
+
+ // Check that queue inherits the broker setting
+ QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
+ assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
+
+ // broker DEAD_LETTER_QUEUE_ENABLED is not set
+ when(_broker.getAttribute(Broker.DEAD_LETTER_QUEUE_ENABLED)).thenReturn(null);
+
+ // Check that queue dead letter queue is not enabled
+ qConf = new QueueConfiguration("test", _emptyConf);
+ assertFalse("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
+
+ // Check explicit value
+ VirtualHostConfiguration vhostConfig = overrideConfiguration("deadLetterQueues", true);
+ qConf = new QueueConfiguration("test", vhostConfig);
+ assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
+
+ // Check inherited value
+ qConf = new QueueConfiguration("test", _fullHostConf);
+ assertTrue("Unexpected queue configuration for dead letter enabled attribute", qConf.isDeadLetterQueueEnabled());
}
public void testGetMaximumMessageAge() throws ConfigurationException
@@ -178,27 +190,28 @@ public class QueueConfigurationTest extends TestCase
public void testGetMinimumAlertRepeatGap() throws Exception
{
- try
- {
- ApplicationRegistry registry = new TestApplicationRegistry(new ServerConfiguration(_env));
- ApplicationRegistry.initialise(registry);
- // Check default value
- QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
- assertEquals(ServerConfiguration.DEFAULT_MINIMUM_ALERT_REPEAT_GAP, qConf.getMinimumAlertRepeatGap());
-
- // Check explicit value
- VirtualHostConfiguration vhostConfig = overrideConfiguration("minimumAlertRepeatGap", 2);
- qConf = new QueueConfiguration("test", vhostConfig);
- assertEquals(2, qConf.getMinimumAlertRepeatGap());
-
- // Check inherited value
- qConf = new QueueConfiguration("test", _fullHostConf);
- assertEquals(1, qConf.getMinimumAlertRepeatGap());
- }
- finally
- {
- ApplicationRegistry.remove();
- }
+ // set broker attribute ALERT_REPEAT_GAP to 10
+ when(_broker.getAttribute(Broker.ALERT_REPEAT_GAP)).thenReturn(10);
+
+ // check that broker level setting is available on queue configuration
+ QueueConfiguration qConf = new QueueConfiguration("test", _emptyConf);
+ assertEquals(10, qConf.getMinimumAlertRepeatGap());
+
+ // remove configuration for ALERT_REPEAT_GAP on broker level
+ when(_broker.getAttribute(Broker.ALERT_REPEAT_GAP)).thenReturn(null);
+
+ // Check default value
+ qConf = new QueueConfiguration("test", _emptyConf);
+ assertEquals(0, qConf.getMinimumAlertRepeatGap());
+
+ // Check explicit value
+ VirtualHostConfiguration vhostConfig = overrideConfiguration("minimumAlertRepeatGap", 2);
+ qConf = new QueueConfiguration("test", vhostConfig);
+ assertEquals(2, qConf.getMinimumAlertRepeatGap());
+
+ // Check inherited value
+ qConf = new QueueConfiguration("test", _fullHostConf);
+ assertEquals(1, qConf.getMinimumAlertRepeatGap());
}
public void testSortQueueConfiguration() throws ConfigurationException
@@ -235,6 +248,6 @@ public class QueueConfigurationTest extends TestCase
config.addConfiguration(_fullHostConf.getConfig());
config.addConfiguration(queueConfig);
- return new VirtualHostConfiguration("test", config);
+ return new VirtualHostConfiguration("test", config, _broker);
}
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
deleted file mode 100644
index 660ff5e7d4..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
+++ /dev/null
@@ -1,1766 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.protocol.AmqpProtocolVersion;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-import static org.apache.qpid.transport.ConnectionSettings.WILDCARD_ADDRESS;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Locale;
-
-import javax.net.ssl.KeyManagerFactory;
-
-public class ServerConfigurationTest extends QpidTestCase
-{
- private XMLConfiguration _config = new XMLConfiguration();
- private ServerConfiguration _serverConfig = null;
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- _serverConfig = new ServerConfiguration(_config);
- ApplicationRegistry.initialise(new TestApplicationRegistry(_serverConfig));
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- ApplicationRegistry.remove();
- }
-
- public void testSetJMXPortRegistryServer() throws ConfigurationException
- {
- _serverConfig.initialise();
- _serverConfig.setJMXPortRegistryServer(23);
- assertEquals(23, _serverConfig.getJMXPortRegistryServer());
- }
-
- public void testGetJMXPortRegistryServer() throws ConfigurationException
- {
- _config.setProperty(ServerConfiguration.MGMT_JMXPORT_REGISTRYSERVER, 42);
- _serverConfig.initialise();
- assertEquals(42, _serverConfig.getJMXPortRegistryServer());
- }
-
- public void testDefaultJMXPortRegistryServer() throws ConfigurationException
- {
- _serverConfig.initialise();
- assertEquals(8999, _serverConfig.getJMXPortRegistryServer());
- }
-
- public void testSetJMXPortConnectorServer() throws ConfigurationException
- {
- ServerConfiguration serverConfig = new ServerConfiguration(_config);
- serverConfig.setJMXPortConnectorServer(67);
- assertEquals(67, serverConfig.getJMXConnectorServerPort());
- }
-
- public void testGetJMXPortConnectorServer() throws ConfigurationException
- {
- _config.setProperty(ServerConfiguration.MGMT_JMXPORT_CONNECTORSERVER, 67);
- ServerConfiguration serverConfig = new ServerConfiguration(_config);
- assertEquals(67, serverConfig.getJMXConnectorServerPort());
- }
-
- public void testDefaultJMXPortConnectorServer() throws ConfigurationException
- {
- ServerConfiguration serverConfig = new ServerConfiguration(_config);
- assertEquals(ServerConfiguration.DEFAULT_JMXPORT_REGISTRYSERVER + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET,
- serverConfig.getJMXConnectorServerPort());
- }
-
- public void testGetPlatformMbeanserver() throws ConfigurationException
- {
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPlatformMbeanserver());
-
- // Check value we set
- _config.setProperty("management.platform-mbeanserver", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getPlatformMbeanserver());
- }
-
- public void testGetPluginDirectory() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(null, _serverConfig.getPluginDirectory());
-
- // Check value we set
- _config.setProperty("plugin-directory", "/path/to/plugins");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("/path/to/plugins", _serverConfig.getPluginDirectory());
- }
-
- public void testGetCacheDirectory() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(null, _serverConfig.getCacheDirectory());
-
- // Check value we set
- _config.setProperty("cache-directory", "/path/to/cache");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("/path/to/cache", _serverConfig.getCacheDirectory());
- }
-
- public void testGetFrameSize() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(65536, _serverConfig.getFrameSize());
-
- // Check value we set
- _config.setProperty("advanced.framesize", "23");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(23, _serverConfig.getFrameSize());
- }
-
- public void testGetStatusEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(ServerConfiguration.DEFAULT_STATUS_UPDATES.equalsIgnoreCase("on"),
- _serverConfig.getStatusUpdatesEnabled());
-
- // Check disabling we set
- _config.setProperty(ServerConfiguration.STATUS_UPDATES, "off");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getStatusUpdatesEnabled());
-
- // Check invalid values don't cause error but result in disabled
- _config.setProperty(ServerConfiguration.STATUS_UPDATES, "Yes Please");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getStatusUpdatesEnabled());
-
- }
- public void testGetSynchedClocks() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getSynchedClocks());
-
- // Check value we set
- _config.setProperty("advanced.synced-clocks", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getSynchedClocks());
- }
-
- public void testGetLocale() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
-
- // The Default is what ever the VMs default is
- Locale defaultLocale = Locale.getDefault();
-
- assertEquals(defaultLocale, _serverConfig.getLocale());
-
-
- //Test Language only
- Locale update = new Locale("es");
- _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(update, _serverConfig.getLocale());
-
- //Test Language and Country
- update = new Locale("es","ES");
- _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es_ES");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(update, _serverConfig.getLocale());
-
- //Test Language and Country and Variant
- update = new Locale("es","ES", "Traditional_WIN");
- _config.setProperty(ServerConfiguration.ADVANCED_LOCALE, "es_ES_Traditional_WIN");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(update, _serverConfig.getLocale());
- }
-
-
- public void testGetMsgAuth() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getMsgAuth());
-
- // Check value we set
- _config.setProperty("security.msg-auth", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getMsgAuth());
- }
-
- public void testGetManagementKeyStorePath() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(null, _serverConfig.getManagementKeyStorePath());
-
- // Check value we set
- _config.setProperty("management.ssl.keyStorePath", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getManagementKeyStorePath());
- }
-
- public void testGetManagementSSLEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getManagementSSLEnabled());
-
- // Check value we set
- _config.setProperty("management.ssl.enabled", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getManagementSSLEnabled());
- }
-
- public void testGetManagementKeystorePassword() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(null, _serverConfig.getManagementKeyStorePassword());
-
- // Check value we set
- _config.setProperty("management.ssl.keyStorePassword", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getManagementKeyStorePassword());
- }
-
- public void testGetQueueAutoRegister() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getQueueAutoRegister());
-
- // Check value we set
- _config.setProperty("queue.auto_register", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getQueueAutoRegister());
- }
-
- public void testGetJMXManagementEnabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getJMXManagementEnabled());
-
- // Check value we set
- _config.setProperty("management.enabled", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getJMXManagementEnabled());
- }
-
- public void testGetManagementRightsInferAllAccess() throws Exception
- {
- _serverConfig.initialise();
-
- //check default
- assertTrue("default should be true", _serverConfig.getManagementRightsInferAllAccess());
-
- //update it
- _config.setProperty("management.managementRightsInferAllAccess", "false");
- assertFalse("New value should be false", _serverConfig.getManagementRightsInferAllAccess());
- }
-
- public void testGetHeartBeatDelay() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(5, _serverConfig.getHeartBeatDelay());
-
- // Check value we set
- _config.setProperty("heartbeat.delay", 23);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(23, _serverConfig.getHeartBeatDelay());
- }
-
- public void testGetHeartBeatTimeout() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(2.0, _serverConfig.getHeartBeatTimeout());
-
- // Check value we set
- _config.setProperty("heartbeat.timeoutFactor", 2.3);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2.3, _serverConfig.getHeartBeatTimeout());
- }
-
- public void testGetMaximumMessageAge() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(0, _serverConfig.getMaximumMessageAge());
-
- // Check value we set
- _config.setProperty("maximumMessageAge", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMaximumMessageAge());
- }
-
- public void testGetMaximumMessageCount() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(0, _serverConfig.getMaximumMessageCount());
-
- // Check value we set
- _config.setProperty("maximumMessageCount", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMaximumMessageCount());
- }
-
- public void testGetMaximumQueueDepth() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(0, _serverConfig.getMaximumQueueDepth());
-
- // Check value we set
- _config.setProperty("maximumQueueDepth", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMaximumQueueDepth());
- }
-
- public void testGetMaximumMessageSize() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(0, _serverConfig.getMaximumMessageSize());
-
- // Check value we set
- _config.setProperty("maximumMessageSize", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMaximumMessageSize());
- }
-
- public void testGetMinimumAlertRepeatGap() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(30000l, _serverConfig.getMinimumAlertRepeatGap());
-
- // Check value we set
- _config.setProperty("minimumAlertRepeatGap", 10L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getMinimumAlertRepeatGap());
- }
-
- public void testGetProcessors() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(4, _serverConfig.getConnectorProcessors());
-
- // Check value we set
- _config.setProperty("connector.processors", 10);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(10, _serverConfig.getConnectorProcessors());
- }
-
- public void testGetPorts() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertNotNull(_serverConfig.getPorts());
- assertEquals(1, _serverConfig.getPorts().size());
- assertEquals(5672, _serverConfig.getPorts().get(0));
-
-
- // Check value we set
- _config.setProperty("connector.port", "10");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertNotNull(_serverConfig.getPorts());
- assertEquals(1, _serverConfig.getPorts().size());
- assertEquals("10", _serverConfig.getPorts().get(0));
- }
-
- public void testGetBind() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(WILDCARD_ADDRESS, _serverConfig.getBind());
-
- // Check value we set
- _config.setProperty("connector.bind", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getBind());
- }
-
- public void testGetReceiveBufferSize() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(ServerConfiguration.DEFAULT_BUFFER_SIZE, _serverConfig.getReceiveBufferSize());
-
- // Check value we set
- _config.setProperty("connector.socketReceiveBuffer", "23");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(23, _serverConfig.getReceiveBufferSize());
- }
-
- public void testGetWriteBufferSize() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(ServerConfiguration.DEFAULT_BUFFER_SIZE, _serverConfig.getWriteBufferSize());
-
- // Check value we set
- _config.setProperty("connector.socketWriteBuffer", "23");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(23, _serverConfig.getWriteBufferSize());
- }
-
- public void testGetTcpNoDelay() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getTcpNoDelay());
-
- // Check value we set
- _config.setProperty("connector.tcpNoDelay", false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getTcpNoDelay());
- }
-
- public void testGetEnableSSL() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getEnableSSL());
-
- // Check value we set
- _config.setProperty("connector.ssl.enabled", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getEnableSSL());
- }
-
- public void testGetSSLOnly() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.getSSLOnly());
-
- // Check value we set
- _config.setProperty("connector.ssl.sslOnly", true);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getSSLOnly());
- }
-
- public void testGetSSLPorts() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertNotNull(_serverConfig.getSSLPorts());
- assertEquals(1, _serverConfig.getSSLPorts().size());
- assertEquals(ServerConfiguration.DEFAULT_SSL_PORT, _serverConfig.getSSLPorts().get(0));
-
-
- // Check value we set
- _config.setProperty("connector.ssl.port", "10");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertNotNull(_serverConfig.getSSLPorts());
- assertEquals(1, _serverConfig.getSSLPorts().size());
- assertEquals("10", _serverConfig.getSSLPorts().get(0));
- }
-
- public void testGetConnectorKeystorePath() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertNull(_serverConfig.getConnectorKeyStorePath());
-
- // Check value we set
- _config.setProperty("connector.ssl.keyStorePath", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getConnectorKeyStorePath());
-
- // Ensure we continue to support the old name keystorePath
- _config.clearProperty("connector.ssl.keyStorePath");
- _config.setProperty("connector.ssl.keystorePath", "b");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("b", _serverConfig.getConnectorKeyStorePath());
- }
-
- public void testGetConnectorKeystorePassword() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertNull(_serverConfig.getConnectorKeyStorePassword());
-
- // Check value we set
- _config.setProperty("connector.ssl.keyStorePassword", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getConnectorKeyStorePassword());
-
- // Ensure we continue to support the old name keystorePassword
- _config.clearProperty("connector.ssl.keyStorePassword");
- _config.setProperty("connector.ssl.keystorePassword", "b");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("b", _serverConfig.getConnectorKeyStorePassword());
- }
-
- public void testConnectorGetKeyManagerAlgorithm() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(KeyManagerFactory.getDefaultAlgorithm(), _serverConfig.getConnectorKeyManagerFactoryAlgorithm());
-
- // Check value we set
- _config.setProperty("connector.ssl.keyManagerFactoryAlgorithm", "a");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("a", _serverConfig.getConnectorKeyManagerFactoryAlgorithm());
-
- // Ensure we continue to support the old name certType
- _config.clearProperty("connector.ssl.keyManagerFactoryAlgorithm");
- _config.setProperty("connector.ssl.certType", "b");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("b", _serverConfig.getConnectorKeyManagerFactoryAlgorithm());
- }
-
- public void testGetHousekeepingCheckPeriod() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(30000, _serverConfig.getHousekeepingCheckPeriod());
-
- // Check value we set
- _config.setProperty("housekeeping.checkPeriod", 23L);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- _serverConfig.setHousekeepingCheckPeriod(42L);
- assertEquals(42, _serverConfig.getHousekeepingCheckPeriod());
- }
-
- public void testSingleConfiguration() throws IOException, ConfigurationException
- {
- File fileA = File.createTempFile(getClass().getName(), null);
- fileA.deleteOnExit();
- FileWriter out = new FileWriter(fileA);
- out.write("<broker><connector><port>2342</port><ssl><port>4235</port></ssl></connector></broker>");
- out.close();
- ServerConfiguration conf = new ServerConfiguration(fileA);
- conf.initialise();
- assertEquals("4235", conf.getSSLPorts().get(0));
- }
-
- public void testCombinedConfiguration() throws IOException, ConfigurationException
- {
- File mainFile = File.createTempFile(getClass().getName(), null);
- File fileA = File.createTempFile(getClass().getName(), null);
- File fileB = File.createTempFile(getClass().getName(), null);
-
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
-
- FileWriter out = new FileWriter(mainFile);
- out.write("<configuration><system/>");
- out.write("<xml fileName=\"" + fileA.getAbsolutePath() + "\"/>");
- out.write("<xml fileName=\"" + fileB.getAbsolutePath() + "\"/>");
- out.write("</configuration>");
- out.close();
-
- out = new FileWriter(fileA);
- out.write("<broker><connector><port>2342</port><ssl><port>4235</port></ssl></connector></broker>");
- out.close();
-
- out = new FileWriter(fileB);
- out.write("<broker><connector><ssl><port>2345</port></ssl></connector></broker>");
- out.close();
-
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
- assertEquals("4235", config.getSSLPorts().get(0)); // From first file, not
- // overriden by second
- assertNotNull(config.getPorts());
- assertEquals(1, config.getPorts().size());
- assertEquals("2342", config.getPorts().get(0)); // From the first file, not
- // present in the second
- }
-
- public void testVariableInterpolation() throws Exception
- {
- File mainFile = File.createTempFile(getClass().getName(), null);
-
- mainFile.deleteOnExit();
-
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<work>foo</work>\n");
- out.write("\t<management><ssl><keyStorePath>${work}</keyStorePath></ssl></management>\n");
- out.write("</broker>\n");
- out.close();
-
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
- assertEquals("Did not get correct interpolated value",
- "foo", config.getManagementKeyStorePath());
- }
-
- private void writeConfigFile(File mainFile, boolean allow) throws IOException {
- writeConfigFile(mainFile, allow, true, null, "test");
- }
-
- private void writeConfigFile(File mainFile, boolean allow, boolean includeVhosts, File vhostsFile, String name) throws IOException {
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<rule access=\""+ ((allow) ? "allow" : "deny") +"\" network=\"127.0.0.1\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- if (includeVhosts)
- {
- out.write("\t<virtualhosts>\n");
- out.write("\t\t<default>test</default>\n");
- out.write("\t\t<virtualhost>\n");
- out.write(String.format("\t\t\t<name>%s</name>\n", name));
- out.write(String.format("\t\t<%s> \n", name));
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write(String.format("\t\t\t\t\t<name>%s.topic</name>\n", name));
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write(String.format("\t\t</%s> \n", name));
- out.write("\t\t</virtualhost>\n");
- out.write("\t</virtualhosts>\n");
- }
- if (vhostsFile != null)
- {
- out.write("\t<virtualhosts>"+vhostsFile.getAbsolutePath()+"</virtualhosts>\n");
- }
- out.write("</broker>\n");
- out.close();
- }
-
- private void writeTestFishConfigFile(File mainFile) throws IOException {
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<rule access=\"allow\" network=\"127.0.0.1\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- out.write("\t<virtualhosts>\n");
- out.write("\t\t<virtualhost>\n");
- out.write("\t\t\t<name>test</name>\n");
- out.write("\t\t<test> \n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write("\t\t\t\t\t<name>test.topic</name>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</test> \n");
- out.write("\t\t</virtualhost>\n");
- out.write("\t\t<virtualhost>\n");
- out.write("\t\t\t<name>fish</name>\n");
- out.write("\t\t<fish> \n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write("\t\t\t\t\t<name>fish.topic</name>\n");
- out.write("\t\t\t\t\t<durable>false</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</fish> \n");
- out.write("\t\t</virtualhost>\n");
- out.write("\t</virtualhosts>\n");
- out.write("</broker>\n");
- out.close();
- }
-
- private void writeVirtualHostsFile(File vhostsFile, String name) throws IOException {
- FileWriter out = new FileWriter(vhostsFile);
- out.write("<virtualhosts>\n");
- out.write(String.format("\t\t<default>%s</default>\n", name));
- out.write("\t<virtualhost>\n");
- out.write(String.format("\t\t<name>%s</name>\n", name));
- out.write(String.format("\t\t<%s>\n", name));
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write("\t\t\t\t\t<name>test.topic</name>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write(String.format("\t\t</%s>\n", name));
- out.write("\t</virtualhost>\n");
- out.write("</virtualhosts>\n");
- out.close();
- }
-
- private void writeMultiVirtualHostsFile(File vhostsFile) throws IOException {
- FileWriter out = new FileWriter(vhostsFile);
- out.write("<virtualhosts>\n");
- out.write("\t<virtualhost>\n");
- out.write("\t\t<name>topic</name>\n");
- out.write("\t\t<topic>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>topic</type>\n");
- out.write("\t\t\t\t\t<name>test.topic</name>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</topic>\n");
- out.write("\t</virtualhost>\n");
- out.write("\t<virtualhost>\n");
- out.write("\t\t<name>fanout</name>\n");
- out.write("\t\t<fanout>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<type>fanout</type>\n");
- out.write("\t\t\t\t\t<name>test.fanout</name>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</fanout>\n");
- out.write("\t</virtualhost>\n");
- out.write("</virtualhosts>\n");
- out.close();
- }
-
- private void writeMultipleVhostsConfigFile(File mainFile, File[] vhostsFileArray) throws IOException {
- FileWriter out = new FileWriter(mainFile);
- out.write("<broker>\n");
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t\t<firewall>\n");
- out.write("\t\t\t<rule access=\"allow\" network=\"127.0.0.1\"/>");
- out.write("\t\t</firewall>\n");
- out.write("\t</security>\n");
- for (File vhostsFile : vhostsFileArray)
- {
- out.write("\t<virtualhosts>"+vhostsFile.getAbsolutePath()+"</virtualhosts>\n");
- }
- out.write("</broker>\n");
- out.close();
- }
-
- private void writeCombinedConfigFile(File mainFile, File fileA, File fileB) throws Exception
- {
- FileWriter out = new FileWriter(mainFile);
- out.write("<configuration><system/>");
- out.write("<xml fileName=\"" + fileA.getAbsolutePath() + "\"/>");
- out.write("<xml fileName=\"" + fileB.getAbsolutePath() + "\"/>");
- out.write("</configuration>");
- out.close();
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in the main
- * configuration file only.
- * <p>
- * Test for QPID-2361
- */
- public void testInternalVirtualhostConfigFile() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, false, true, null, "test");
-
- // Load config
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
-
- // Test config
- VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry();
- String defaultVirtualHost = reg.getConfiguration().getDefaultVirtualHost();
- VirtualHost virtualHost = virtualHostRegistry.getVirtualHost("test");
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(new AMQShortString("test.topic"));
-
- assertEquals("Incorrect default host", "test", defaultVirtualHost);
- assertEquals("Incorrect virtualhost count", 1, virtualHostRegistry.getVirtualHosts().size());
- assertEquals("Incorrect virtualhost name", "test", virtualHost.getName());
- assertEquals("Incorrect exchange type", "topic", exchange.getType().getName().toString());
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in an external
- * configuration file only.
- * <p>
- * Test for QPID-2361
- */
- public void testExternalVirtualhostXMLFile() throws Exception
- {
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- vhostsFile.deleteOnExit();
- writeConfigFile(mainFile, false, false, vhostsFile, null);
- writeVirtualHostsFile(vhostsFile, "test");
-
- // Load config
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
-
- // Test config
- VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry();
- String defaultVirtualHost = reg.getConfiguration().getDefaultVirtualHost();
- VirtualHost virtualHost = virtualHostRegistry.getVirtualHost("test");
- Exchange exchange = virtualHost.getExchangeRegistry().getExchange(new AMQShortString("test.topic"));
-
- assertEquals("Incorrect default host", "test", defaultVirtualHost);
- assertEquals("Incorrect virtualhost count", 1, virtualHostRegistry.getVirtualHosts().size());
- assertEquals("Incorrect virtualhost name", "test", virtualHost.getName());
- assertEquals("Incorrect exchange type", "topic", exchange.getType().getName().toString());
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in an external
- * configuration file only, with two vhosts that have different properties.
- * <p>
- * Test for QPID-2361
- */
- public void testExternalMultiVirtualhostXMLFile() throws Exception
- {
- // Write out vhosts
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts-multi");
- vhostsFile.deleteOnExit();
- writeMultiVirtualHostsFile(vhostsFile);
-
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, false, false, vhostsFile, null);
-
- // Load config
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
-
- // Test config
- VirtualHostRegistry virtualHostRegistry = reg.getVirtualHostRegistry();
-
- assertEquals("Incorrect virtualhost count", 2, virtualHostRegistry.getVirtualHosts().size());
-
- // test topic host
- VirtualHost topicVirtualHost = virtualHostRegistry.getVirtualHost("topic");
- Exchange topicExchange = topicVirtualHost.getExchangeRegistry().getExchange(new AMQShortString("test.topic"));
-
- assertEquals("Incorrect topic virtualhost name", "topic", topicVirtualHost.getName());
- assertEquals("Incorrect topic exchange type", "topic", topicExchange.getType().getName().toString());
-
- // Test fanout host
- VirtualHost fanoutVirtualHost = virtualHostRegistry.getVirtualHost("fanout");
- Exchange fanoutExchange = fanoutVirtualHost.getExchangeRegistry().getExchange(new AMQShortString("test.fanout"));
-
- assertEquals("Incorrect fanout virtualhost name", "fanout", fanoutVirtualHost.getName());
- assertEquals("Incorrect fanout exchange type", "fanout", fanoutExchange.getType().getName().toString());
- }
-
- /**
- * Test that configuration does not load when virtual hosts are specified in both the main
- * configuration file and an external file. Should throw a {@link ConfigurationException}.
- * <p>
- * Test for QPID-2361
- */
- public void testInternalAndExternalVirtualhostXMLFile() throws Exception
- {
- // Write out vhosts
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- vhostsFile.deleteOnExit();
- writeVirtualHostsFile(vhostsFile, "test");
-
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, false, true, vhostsFile, "test");
-
- // Load config
- try
- {
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
- fail("Different virtualhost XML configurations not allowed");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message", "Only one of external or embedded virtualhosts configuration allowed.", ce.getMessage());
- }
- }
-
- /**
- * Test that configuration does not load when virtual hosts are specified in multiple external
- * files. Should throw a {@link ConfigurationException}.
- * <p>
- * Test for QPID-2361
- */
- public void testMultipleInternalVirtualhostXMLFile() throws Exception
- {
- // Write out vhosts
- File vhostsFileOne = File.createTempFile(getClass().getName(), "vhosts-one");
- vhostsFileOne.deleteOnExit();
- writeVirtualHostsFile(vhostsFileOne, "one");
- File vhostsFileTwo = File.createTempFile(getClass().getName(), "vhosts-two");
- vhostsFileTwo.deleteOnExit();
- writeVirtualHostsFile(vhostsFileTwo, "two");
-
- // Write out config
- File mainFile = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- writeMultipleVhostsConfigFile(mainFile, new File[] { vhostsFileOne, vhostsFileTwo });
-
- // Load config
- try
- {
- ApplicationRegistry.remove();
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(mainFile);
- ApplicationRegistry.initialise(reg);
- fail("Multiple virtualhost XML configurations not allowed");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Only one external virtualhosts configuration file allowed, multiple filenames found.",
- ce.getMessage());
- }
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified in an external
- * configuration file in the first of two configurations and embedded in the second. This
- * will throe a {@link ConfigurationException} since the configurations have different
- * types.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedDifferentVirtualhostConfig() throws Exception
- {
- // Write out vhosts config
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- vhostsFile.deleteOnExit();
- writeVirtualHostsFile(vhostsFile, "external");
-
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File fileA = File.createTempFile(getClass().getName(), "a");
- File fileB = File.createTempFile(getClass().getName(), "b");
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeCombinedConfigFile(mainFile, fileA, fileB);
- writeConfigFile(fileA, false, false, vhostsFile, null);
- writeConfigFile(fileB, false);
-
- // Load config
- try
- {
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
- fail("Different virtualhost XML configurations not allowed");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message", "Only one of external or embedded virtualhosts configuration allowed.", ce.getMessage());
- }
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified two overriding configurations
- * each with an embedded virtualhost section. The first configuration section should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedConfigEmbeddedVirtualhost() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File fileA = File.createTempFile(getClass().getName(), "a");
- File fileB = File.createTempFile(getClass().getName(), "b");
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeCombinedConfigFile(mainFile, fileA, fileB);
- writeConfigFile(fileA, false, true, null, "a");
- writeConfigFile(fileB, false, true, null, "b");
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration virtualHost = config.getVirtualHostConfig("a");
-
- assertEquals("Incorrect virtualhost count", 1, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "a", virtualHost.getName());
- }
-
- /**
- * Test that configuration loads correctly when virtual hosts are specified two overriding configurations
- * each with an external virtualhost XML file. The first configuration file should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedConfigExternalVirtualhost() throws Exception
- {
- // Write out vhosts config
- File vhostsOne = File.createTempFile(getClass().getName(), "vhosts-one");
- vhostsOne.deleteOnExit();
- writeVirtualHostsFile(vhostsOne, "one");
- File vhostsTwo = File.createTempFile(getClass().getName(), "vhosts-two");
- vhostsTwo.deleteOnExit();
- writeVirtualHostsFile(vhostsTwo, "two");
-
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File fileA = File.createTempFile(getClass().getName(), "a");
- File fileB = File.createTempFile(getClass().getName(), "b");
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeCombinedConfigFile(mainFile, fileA, fileB);
- writeConfigFile(fileA, false, false, vhostsOne, null);
- writeConfigFile(fileB, false, false, vhostsTwo, null);
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration virtualHost = config.getVirtualHostConfig("one");
-
- assertEquals("Incorrect virtualhost count", 1, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "one", virtualHost.getName());
- }
-
- /**
- * Test that configuration loads correctly when an overriding virtualhost configuration resets
- * a property of an embedded virtualhost section. The overriding configuration property value
- * should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedConfigEmbeddedVirtualhostOverride() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File fileA = File.createTempFile(getClass().getName(), "override");
- File fileB = File.createTempFile(getClass().getName(), "config");
- mainFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeCombinedConfigFile(mainFile, fileA, fileB);
- writeTestFishConfigFile(fileB);
-
- // Write out overriding virtualhosts section
- FileWriter out = new FileWriter(fileA);
- out.write("<broker>\n");
- out.write("<virtualhosts>\n");
- out.write("\t<virtualhost>\n");
- out.write("\t\t<test>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<durable>false</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</test>\n");
- out.write("\t\t<fish>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<durable>true</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</fish>\n");
- out.write("\t</virtualhost>\n");
- out.write("</virtualhosts>\n");
- out.write("</broker>\n");
- out.close();
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration testHost = config.getVirtualHostConfig("test");
- ExchangeConfiguration testExchange = testHost.getExchangeConfiguration("test.topic");
- VirtualHostConfiguration fishHost = config.getVirtualHostConfig("fish");
- ExchangeConfiguration fishExchange = fishHost.getExchangeConfiguration("fish.topic");
-
- assertEquals("Incorrect virtualhost count", 2, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "test", testHost.getName());
- assertFalse("Incorrect exchange durable property", testExchange.getDurable());
- assertEquals("Incorrect virtualhost name", "fish", fishHost.getName());
- assertTrue("Incorrect exchange durable property", fishExchange.getDurable());
- }
-
- /**
- * Test that configuration loads correctly when the virtualhost configuration is a set of overriding
- * configuration files that resets a property of a virtualhost. The opmost overriding configuration
- * property value should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedVirtualhostOverride() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- File fileA = File.createTempFile(getClass().getName(), "vhosts-override");
- File fileB = File.createTempFile(getClass().getName(), "vhosts-base");
- mainFile.deleteOnExit();
- vhostsFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeConfigFile(mainFile, true, false, vhostsFile, null);
- writeCombinedConfigFile(vhostsFile, fileA, fileB);
-
- // Write out overriding virtualhosts sections
- FileWriter out = new FileWriter(fileA);
- out.write("<virtualhosts>\n");
- out.write("\t<virtualhost>\n");
- out.write("\t\t<test>\n");
- out.write("\t\t\t<exchanges>\n");
- out.write("\t\t\t\t<exchange>\n");
- out.write("\t\t\t\t\t<durable>false</durable>\n");
- out.write("\t\t\t\t</exchange>\n");
- out.write("\t\tt</exchanges>\n");
- out.write("\t\t</test>\n");
- out.write("\t</virtualhost>\n");
- out.write("</virtualhosts>\n");
- out.close();
- writeVirtualHostsFile(fileB, "test");
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration testHost = config.getVirtualHostConfig("test");
- ExchangeConfiguration testExchange = testHost.getExchangeConfiguration("test.topic");
-
- assertEquals("Incorrect virtualhost count", 1, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "test", testHost.getName());
- assertFalse("Incorrect exchange durable property", testExchange.getDurable());
- }
-
- /**
- * Test that configuration loads correctly when the virtualhost configuration is a set of overriding
- * configuration files that define multiple virtualhosts, one per file. Only the virtualhosts defined in
- * the topmost file should be used.
- * <p>
- * Test for QPID-2361
- */
- public void testCombinedMultipleVirtualhosts() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File vhostsFile = File.createTempFile(getClass().getName(), "vhosts");
- File fileA = File.createTempFile(getClass().getName(), "vhosts-one");
- File fileB = File.createTempFile(getClass().getName(), "vhosts-two");
- mainFile.deleteOnExit();
- vhostsFile.deleteOnExit();
- fileA.deleteOnExit();
- fileB.deleteOnExit();
- writeConfigFile(mainFile, true, false, vhostsFile, null);
- writeCombinedConfigFile(vhostsFile, fileA, fileB);
-
- // Write both virtualhosts definitions
- writeVirtualHostsFile(fileA, "test-one");
- writeVirtualHostsFile(fileB, "test-two");
-
- // Load config
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
-
- // Test config
- VirtualHostConfiguration oneHost = config.getVirtualHostConfig("test-one");
-
- assertEquals("Incorrect virtualhost count", 1, config.getVirtualHosts().length);
- assertEquals("Incorrect virtualhost name", "test-one", oneHost.getName());
- }
-
- /**
- * Test that a non-existent virtualhost file throws a {@link ConfigurationException}.
- * <p>
- * Test for QPID-2624
- */
- public void testNonExistantVirtualhosts() throws Exception
- {
- // Write out combined config file
- File mainFile = File.createTempFile(getClass().getName(), "main");
- File vhostsFile = new File("doesnotexist");
- mainFile.deleteOnExit();
- writeConfigFile(mainFile, true, false, vhostsFile, null);
-
- // Load config
- try
- {
- ServerConfiguration config = new ServerConfiguration(mainFile.getAbsoluteFile());
- config.initialise();
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Virtualhosts file does not exist", ce.getMessage());
- }
- catch (Exception e)
- {
- fail("Should throw a ConfigurationException");
- }
- }
-
- /**
- * Tests that element disabledFeatures allows features that would
- * otherwise be advertised by the broker to be turned off.
- */
- public void testDisabledFeatures() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- _serverConfig = new ServerConfiguration(_config);
- assertEquals("Unexpected size", 0, _serverConfig.getDisabledFeatures().size());
-
- // Check value we set
- _config.addProperty("disabledFeatures", "qpid.feature1");
- _config.addProperty("disabledFeatures", "qpid.feature2");
- _serverConfig = new ServerConfiguration(_config);
-
- assertEquals("Unexpected size",2, _serverConfig.getDisabledFeatures().size());
- assertTrue("Unexpected contents", _serverConfig.getDisabledFeatures().contains("qpid.feature1"));
- }
-
- /**
- * Tests that the old element security.jmx.access (that used to be used
- * to define JMX access rights) is rejected.
- */
- public void testManagementAccessRejected() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
-
- // Check value we set
- _config.setProperty("security.jmx.access(0)", "jmxremote.access");
- _serverConfig = new ServerConfiguration(_config);
-
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Validation error : security/jmx/access is no longer a supported element within the configuration xml.",
- ce.getMessage());
- }
- }
-
- /**
- * Tests that the old element security.jmx.principal-database (that used to define the
- * principal database used for JMX authentication) is rejected.
- */
- public void testManagementPrincipalDatabaseRejected() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
-
- // Check value we set
- _config.setProperty("security.jmx.principal-database(0)", "mydb");
- _serverConfig = new ServerConfiguration(_config);
-
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Validation error : security/jmx/principal-database is no longer a supported element within the configuration xml.",
- ce.getMessage());
- }
- }
-
- /**
- * Tests that the old element security.principal-databases. ... (that used to define
- * principal databases) is rejected.
- */
- public void testPrincipalDatabasesRejected() throws ConfigurationException
- {
- _serverConfig.initialise();
-
- // Check value we set
- _config.setProperty("security.principal-databases.principal-database.class", "myclass");
- _serverConfig = new ServerConfiguration(_config);
-
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Validation error : security/principal-databases is no longer supported within the configuration xml.",
- ce.getMessage());
- }
- }
-
- /**
- * Tests that the old element housekeeping.expiredMessageCheckPeriod. ... (that was
- * replaced by housekeeping.checkPeriod) is rejected.
- */
- public void testExpiredMessageCheckPeriodRejected() throws ConfigurationException
- {
- _serverConfig.initialise();
-
- // Check value we set
- _config.setProperty("housekeeping.expiredMessageCheckPeriod", 23L);
- _serverConfig = new ServerConfiguration(_config);
-
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- assertEquals("Incorrect error message",
- "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod.",
- ce.getMessage());
- }
- }
-
- public void testMaxDeliveryCountDefault() throws Exception
- {
- final ServerConfiguration serverConfig = new ServerConfiguration(_config);
- assertEquals(0, serverConfig.getMaxDeliveryCount());
- }
-
- public void testMaxDeliveryCount() throws Exception
- {
- _config.setProperty("maximumDeliveryCount", 5);
- final ServerConfiguration serverConfig = new ServerConfiguration(_config);
- assertEquals(5, serverConfig.getMaxDeliveryCount());
- }
-
- /**
- * Test XML configuration file correctly enables dead letter queues
- */
- public void testDeadLetterQueueConfigurationFile() throws Exception
- {
- // Write config
- File xml = File.createTempFile(getClass().getName(), "xml");
- xml.deleteOnExit();
- FileWriter config = new FileWriter(xml);
- config.write("<broker>\n");
- writeSecurity(config);
- config.write("<deadLetterQueues>true</deadLetterQueues>\n");
- config.write("<virtualhosts>\n");
- config.write("<virtualhost>\n");
- config.write("<name>test</name>\n");
- config.write("<test>\n");
- config.write("<queues>\n");
- config.write("<deadLetterQueues>false</deadLetterQueues>\n");
- config.write("<queue>\n");
- config.write("<name>biggles</name>\n");
- config.write("<biggles>\n");
- config.write("<deadLetterQueues>true</deadLetterQueues>\n");
- config.write("</biggles>\n");
- config.write("</queue>\n");
- config.write("<queue>\n");
- config.write("<name>beetle</name>\n");
- config.write("<beetle />\n");
- config.write("</queue>\n");
- config.write("</queues>\n");
- config.write("</test>\n");
- config.write("</virtualhost>\n");
- config.write("<virtualhost>\n");
- config.write("<name>extra</name>\n");
- config.write("<extra>\n");
- config.write("<queues>\n");
- config.write("<queue>\n");
- config.write("<name>r2d2</name>\n");
- config.write("<r2d2>\n");
- config.write("<deadLetterQueues>false</deadLetterQueues>\n");
- config.write("</r2d2>\n");
- config.write("</queue>\n");
- config.write("<queue>\n");
- config.write("<name>c3p0</name>\n");
- config.write("<c3p0 />\n");
- config.write("</queue>\n");
- config.write("</queues>\n");
- config.write("</extra>\n");
- config.write("</virtualhost>\n");
- config.write("</virtualhosts>\n");
- config.write("</broker>\n");
- config.close();
-
- // Load config
- ApplicationRegistry.remove();
- ApplicationRegistry registry = new ConfigurationFileApplicationRegistry(xml);
- ApplicationRegistry.initialise(registry);
- ServerConfiguration serverConfiguration = ApplicationRegistry.getInstance().getConfiguration();
-
- VirtualHostConfiguration test = serverConfiguration.getVirtualHostConfig("test");
- assertNotNull("Host 'test' is not found", test);
- VirtualHostConfiguration extra = serverConfiguration.getVirtualHostConfig("extra");
- assertNotNull("Host 'extra' is not found", test);
-
- QueueConfiguration biggles = test.getQueueConfiguration("biggles");
- QueueConfiguration beetle = test.getQueueConfiguration("beetle");
- QueueConfiguration r2d2 = extra.getQueueConfiguration("r2d2");
- QueueConfiguration c3p0 = extra.getQueueConfiguration("c3p0");
-
- // Validate config
- assertTrue("Broker DLQ should be configured as enabled", serverConfiguration.isDeadLetterQueueEnabled());
- assertFalse("Test vhost DLQ should be configured as disabled", test.isDeadLetterQueueEnabled());
- assertTrue("Extra vhost DLQ should be enabled, using broker default", extra.isDeadLetterQueueEnabled());
- assertTrue("Biggles queue DLQ should be configured as enabled", biggles.isDeadLetterQueueEnabled());
- assertFalse("Beetle queue DLQ should be disabled, using test vhost default", beetle.isDeadLetterQueueEnabled());
- assertFalse("R2D2 queue DLQ should be configured as disabled", r2d2.isDeadLetterQueueEnabled());
- assertTrue("C3P0 queue DLQ should be enabled, using broker default", c3p0.isDeadLetterQueueEnabled());
- }
-
- public void testIsAmqp010enabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.isAmqp010enabled());
-
- // Check value we set
- _config.setProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.isAmqp010enabled());
- }
-
- public void testIsAmqp091enabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.isAmqp091enabled());
-
- // Check value we set
- _config.setProperty(ServerConfiguration.CONNECTOR_AMQP091ENABLED, false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.isAmqp091enabled());
- }
-
- public void testIsAmqp09enabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.isAmqp09enabled());
-
- // Check value we set
- _config.setProperty(ServerConfiguration.CONNECTOR_AMQP09ENABLED, false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.isAmqp09enabled());
- }
-
- public void testIsAmqp08enabled() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.isAmqp08enabled());
-
- // Check value we set
- _config.setProperty(ServerConfiguration.CONNECTOR_AMQP08ENABLED, false);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(false, _serverConfig.isAmqp08enabled());
- }
-
- public void testPortInclude08() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude08().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_08, "1");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_08, "2");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude08().size());
- assertTrue(_serverConfig.getPortInclude08().contains("1"));
- assertTrue(_serverConfig.getPortInclude08().contains("2"));
- }
-
- public void testPortInclude09() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude09().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_09, "3");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_09, "4");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude09().size());
- assertTrue(_serverConfig.getPortInclude09().contains("3"));
- assertTrue(_serverConfig.getPortInclude09().contains("4"));
- }
-
- public void testPortInclude091() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude091().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_091, "5");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_091, "6");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude091().size());
- assertTrue(_serverConfig.getPortInclude091().contains("5"));
- assertTrue(_serverConfig.getPortInclude091().contains("6"));
- }
-
- public void testPortInclude010() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude010().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, "7");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, "8");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude010().size());
- assertTrue(_serverConfig.getPortInclude010().contains("7"));
- assertTrue(_serverConfig.getPortInclude010().contains("8"));
- }
-
- public void testPortInclude10() throws ConfigurationException
- {
- // Check default
- _serverConfig.initialise();
- assertEquals(true, _serverConfig.getPortInclude10().isEmpty());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_10, "9");
- _config.addProperty(ServerConfiguration.CONNECTOR_INCLUDE_10, "10");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(2, _serverConfig.getPortInclude10().size());
- assertTrue(_serverConfig.getPortInclude10().contains("9"));
- assertTrue(_serverConfig.getPortInclude10().contains("10"));
- }
-
- public void testGetDefaultSupportedProtocolReply() throws Exception
- {
- // Check default
- _serverConfig.initialise();
- assertNull("unexpected default value", _serverConfig.getDefaultSupportedProtocolReply());
-
- // Check values we set
- _config.addProperty(ServerConfiguration.CONNECTOR_AMQP_SUPPORTED_REPLY, "v0_10");
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(AmqpProtocolVersion.v0_10, _serverConfig.getDefaultSupportedProtocolReply());
- }
-
- public void testDefaultAuthenticationManager() throws Exception
- {
- // Check default
- _serverConfig.initialise();
- assertNull("unexpected default value", _serverConfig.getDefaultAuthenticationManager());
-
- // Check values we set
- String testAuthManager = "myauthmanager";
- _config.addProperty("security.default-auth-manager", testAuthManager);
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals(testAuthManager, _serverConfig.getDefaultAuthenticationManager());
- }
-
- public void testPortAuthenticationMappingsDefault() throws Exception
- {
- _serverConfig.initialise();
- assertEquals("unexpected default number of port/authmanager mappings", 0, _serverConfig.getPortAuthenticationMappings().size());
- }
-
- public void testPortAuthenticationMappingsWithSingleMapping() throws Exception
- {
- String testAuthManager = "myauthmanager";
- _config.addProperty("security.port-mappings.port-mapping.port", 1234);
- _config.addProperty("security.port-mappings.port-mapping.auth-manager", testAuthManager);
-
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
- assertEquals("unexpected number of port/authmanager mappings", 1, _serverConfig.getPortAuthenticationMappings().size());
- assertEquals("unexpected mapping for port", testAuthManager, _serverConfig.getPortAuthenticationMappings().get(1234));
- }
-
- public void testPortAuthenticationMappingsWithManyMapping() throws Exception
- {
- String testAuthManager1 = "myauthmanager1";
- String testAuthManager2 = "myauthmanager2";
- _config.addProperty("security.port-mappings.port-mapping(-1).port", 1234);
- _config.addProperty("security.port-mappings.port-mapping.auth-manager", testAuthManager1);
-
- _config.addProperty("security.port-mappings.port-mapping(-1).port", 2345);
- _config.addProperty("security.port-mappings.port-mapping.auth-manager", testAuthManager2);
-
- _serverConfig = new ServerConfiguration(_config);
- _serverConfig.initialise();
-
- assertEquals("unexpected number of port/authmanager mappings", 2, _serverConfig.getPortAuthenticationMappings().size());
- assertEquals("unexpected mapping for port", testAuthManager1, _serverConfig.getPortAuthenticationMappings().get(1234));
- assertEquals("unexpected mapping for port", testAuthManager2, _serverConfig.getPortAuthenticationMappings().get(2345));
- }
-
- public void testPortAuthenticationMappingWithMissingAuthManager() throws Exception
- {
- _config.addProperty("security.port-mappings.port-mapping(-1).port", 1234);
- // no auth manager defined for port
- _serverConfig = new ServerConfiguration(_config);
- try
- {
- _serverConfig.initialise();
- fail("Exception not thrown");
- }
- catch(ConfigurationException ce)
- {
- // PASS
- assertEquals("Incorrect error message",
- "Validation error: Each port-mapping must have exactly one port and exactly one auth-manager.",
- ce.getMessage());
- }
- }
-
- /**
- * Convenience method to output required security preamble for broker config
- */
- private void writeSecurity(Writer out) throws Exception
- {
- out.write("\t<management><enabled>false</enabled></management>\n");
- out.write("\t<security>\n");
- out.write("\t\t<pd-auth-manager>\n");
- out.write("\t\t\t<principal-database>\n");
- out.write("\t\t\t\t<class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>\n");
- out.write("\t\t\t\t<attributes>\n");
- out.write("\t\t\t\t\t<attribute>\n");
- out.write("\t\t\t\t\t\t<name>passwordFile</name>\n");
- out.write("\t\t\t\t\t\t<value>/dev/null</value>\n");
- out.write("\t\t\t\t\t</attribute>\n");
- out.write("\t\t\t\t</attributes>\n");
- out.write("\t\t\t</principal-database>\n");
- out.write("\t\t</pd-auth-manager>\n");
- out.write("\t</security>\n");
- }
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/TopicConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/TopicConfigurationTest.java
deleted file mode 100644
index caf74a89ec..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/configuration/TopicConfigurationTest.java
+++ /dev/null
@@ -1,131 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.AMQInternalException;
-import org.apache.qpid.AMQSecurityException;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-/**
- * Test of the new Topic configuration processing
- */
-public class TopicConfigurationTest extends InternalBrokerBaseCase
-{
-
- @Override
- public void configure()
- {
- getConfigXml().addProperty("virtualhosts.virtualhost.test.topics.topic.name", "stocks.nyse.appl");
-
- getConfigXml().addProperty("virtualhosts.virtualhost.test.topics.topic(1).subscriptionName", getName()+":stockSubscription");
-
- getConfigXml().addProperty("virtualhosts.virtualhost.test.topics.topic(2).name", "stocks.nyse.orcl");
- getConfigXml().addProperty("virtualhosts.virtualhost.test.topics.topic(2).subscriptionName", getName()+":stockSubscription");
- }
-
- /**
- * Test that a TopicConfig object is created and attached to the queue when it is bound to the topic exchange.
- *
-
- * @throws ConfigurationException
- * @throws AMQSecurityException
- */
- public void testTopicCreation() throws ConfigurationException, AMQSecurityException, AMQInternalException
- {
- Exchange topicExchange = getVirtualHost().getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME);
- getVirtualHost().getBindingFactory().addBinding("stocks.nyse.appl", getQueue(), topicExchange, null);
-
- TopicConfig config = getQueue().getConfiguration().getConfiguration(TopicConfig.class.getName());
-
- assertNotNull("Queue should have topic configuration bound to it.", config);
- assertEquals("Configuration name not correct", "stocks.nyse.appl", config.getName());
- }
-
- /**
- * Test that a queue created for a subscription correctly has topic
- * configuration selected based on the subscription and topic name.
- *
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testSubscriptionWithTopicCreation() throws ConfigurationException, AMQException
- {
-
- AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), getName()+":stockSubscription", false, "testowner",
- false, false, getVirtualHost(), null);
-
- getVirtualHost().getQueueRegistry().registerQueue(queue);
- Exchange defaultExchange = getVirtualHost().getExchangeRegistry().getDefaultExchange();
- getVirtualHost().getBindingFactory().addBinding(getName(), queue, defaultExchange, null);
-
-
- Exchange topicExchange = getVirtualHost().getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME);
- getVirtualHost().getBindingFactory().addBinding("stocks.nyse.orcl", queue, topicExchange, null);
-
- TopicConfig config = queue.getConfiguration().getConfiguration(TopicConfig.class.getName());
-
- assertNotNull("Queue should have topic configuration bound to it.", config);
- assertEquals("Configuration subscription name not correct", getName() + ":stockSubscription", config.getSubscriptionName());
- assertEquals("Configuration name not correct", "stocks.nyse.orcl", config.getName());
-
- }
-
- /**
- * Test that a queue created for a subscription correctly has topic
- * configuration attached here this should be the generic topic section
- * with just the subscriptionName
- *
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testSubscriptionCreation() throws ConfigurationException, AMQException
- {
-
- AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID() ,getName()+":stockSubscription", false, "testowner",
- false, false, getVirtualHost(), null);
-
- getVirtualHost().getQueueRegistry().registerQueue(queue);
- Exchange defaultExchange = getVirtualHost().getExchangeRegistry().getDefaultExchange();
- getVirtualHost().getBindingFactory().addBinding(getName(), queue, defaultExchange, null);
-
-
- Exchange topicExchange = getVirtualHost().getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME);
- getVirtualHost().getBindingFactory().addBinding("stocks.nyse.ibm", queue, topicExchange, null);
-
- TopicConfig config = queue.getConfiguration().getConfiguration(TopicConfig.class.getName());
-
- assertNotNull("Queue should have topic configuration bound to it.", config);
- assertEquals("Configuration subscription name not correct", getName() + ":stockSubscription", config.getSubscriptionName());
- assertEquals("Configuration name not correct", "#", config.getName());
-
- }
-
-
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java
index 50e7f0588b..570bd004c5 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java
@@ -19,24 +19,69 @@
*/
package org.apache.qpid.server.configuration;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.queue.AMQPriorityQueue;
import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
+public class VirtualHostConfigurationTest extends QpidTestCase
{
+ private VirtualHostRegistry _virtualHostRegistry;
+ private XMLConfiguration _configXml;
+ private Broker _broker;
@Override
- public void createBroker()
+ public void setUp() throws Exception
{
- // Prevent auto broker startup
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _configXml = new XMLConfiguration();
+ _configXml.addProperty("virtualhosts.virtualhost(-1).name", getName());
+ _configXml.addProperty("virtualhosts.virtualhost(-1)."+getName()+".store.class", TestableMemoryMessageStore.class.getName());
+ _virtualHostRegistry = new VirtualHostRegistry();
+ _broker = mock(Broker.class);
+ when(_broker.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).thenReturn(30000l);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHostRegistry != null)
+ {
+ _virtualHostRegistry.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ private XMLConfiguration getConfigXml()
+ {
+ return _configXml;
+ }
+
+ private VirtualHost createVirtualHost(String hostName) throws Exception
+ {
+ Configuration config = getConfigXml().subset("virtualhosts.virtualhost." + XmlConfigurationUtilities.escapeTagName(hostName));
+ VirtualHostConfiguration virtualHostConfiguration = new VirtualHostConfiguration(hostName, config, _broker);
+ return BrokerTestHelper.createVirtualHost(virtualHostConfiguration, _virtualHostRegistry);
}
public void testQueuePriority() throws Exception
@@ -65,11 +110,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ntest.priority",
"false");
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost vhost = createVirtualHost(getName());
// Check that atest was a priority queue with 5 priorities
AMQQueue atest = vhost.getQueueRegistry().getQueue(new AMQShortString("atest"));
@@ -102,11 +143,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues(-1).queue(-1).name(-1)", "btest");
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost vhost = createVirtualHost(getName());
// Check specifically configured values
AMQQueue aTest = vhost.getQueueRegistry().getQueue(new AMQShortString("atest"));
@@ -129,11 +166,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + ".queues.queue.biggles.maximumDeliveryCount", 4);
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + ".queues(-1).queue(-1).name", "beetle");
- // Start the broker now.
- super.createBroker();
-
- // Get vhosts
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost test = createVirtualHost(getName());
// Enabled specifically
assertEquals("Test vhost MDC was configured as enabled", 5 ,test.getConfiguration().getMaxDeliveryCount());
@@ -163,12 +196,8 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + "Extra.queues(-1).queue(-1).name", "c3p0");
getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + "Extra.store.class", TestableMemoryMessageStore.class.getName());
- // Start the broker now.
- super.createBroker();
-
- // Get vhosts
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
- VirtualHost extra = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName() + "Extra");
+ VirtualHost test = createVirtualHost(getName());
+ VirtualHost extra = createVirtualHost(getName() + "Extra");
// Enabled specifically
assertTrue("Test vhost DLQ was configured as enabled", test.getConfiguration().isDeadLetterQueueEnabled());
@@ -215,38 +244,13 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost.testHouseKeepingThreadCount.housekeeping.poolSize",
initialPoolSize);
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost vhost = createVirtualHost(getName());
assertEquals("HouseKeeping PoolSize not set correctly.",
initialPoolSize, vhost.getHouseKeepingPoolSize());
}
/**
- * Test default house keeping tasks
- *
- * @throws Exception
- */
- public void testDefaultHouseKeepingTasks() throws Exception
- {
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
-
- assertEquals("Default houseKeeping task count incorrect.", 2,
- vhost.getHouseKeepingTaskCount());
-
- // Currently the two are tasks:
- // ExpiredMessageTask from VirtualHost
- // UpdateTask from the QMF ManagementExchange
- }
-
- /**
* Test that we can dynamically change the thread pool size
*
* @throws Exception
@@ -258,11 +262,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
getConfigXml().addProperty("virtualhosts.virtualhost.testDynamicHouseKeepingPoolSizeChange.housekeeping.poolSize",
initialPoolSize);
- // Start the broker now.
- super.createBroker();
-
- VirtualHost vhost =
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost(getName());
+ VirtualHost vhost = createVirtualHost(getName());
assertEquals("HouseKeeping PoolSize not set correctly.",
initialPoolSize, vhost.getHouseKeepingPoolSize());
@@ -286,7 +286,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
try
{
- super.createBroker();
+ createVirtualHost(getName());
fail("Exception not thrown");
}
catch(ConfigurationException ce)
@@ -309,7 +309,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
try
{
- super.createBroker();
+ createVirtualHost(getName());
fail("Exception not thrown");
}
catch (ConfigurationException ce)
@@ -320,4 +320,41 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase
ce.getMessage());
}
}
+
+ /*
+ * Tests that the queues with dots in the names are fully supported. The XML configuration
+ * had problems with handling the tags containing dots due to the design of the Apache Commons
+ * Configuration library. The dots need to be escaped when accessing the XML configuration.
+ */
+ public void testDotsInQueueName() throws Exception
+ {
+ // Set up vhosts and queue
+ getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + ".queues(-1).queue(-1).name", "dot.in.a.name");
+ // Add a single property which is inside the <dot.in.a.name> queue tag - the maximum delivery count
+ getConfigXml().addProperty("virtualhosts.virtualhost." + getName() + ".queues.queue.dot..in..a..name.maximumDeliveryCount", 5);
+
+ VirtualHost test = createVirtualHost(getName());
+
+ // Check, that the property stored within the <dot.in.a.name> tag has been properly loaded
+ assertEquals("queue with dots in its name has been properly loaded", 5, test.getConfiguration().getQueueConfiguration("dot.in.a.name").getMaxDeliveryCount());
+ }
+
+ /*
+ * Tests that the virtual hosts with dots in the names are fully supported. The XML
+ * configuration had problems with handling the tags containing dots due to the design
+ * of the Apache Commons Configuration library. The dots need to be escaped when
+ * accessing the XML configuration.
+ */
+ public void testDotsInVirtualHostName() throws Exception
+ {
+ // Set up vhosts
+ getConfigXml().addProperty("virtualhosts.virtualhost.name", "dot.in.a.name");
+ // Add a single property which is inside the <dot.in.a.name> virtual host tag - the message store
+ getConfigXml().addProperty("virtualhosts.virtualhost.dot..in..a..name.store.class", TestableMemoryMessageStore.class.getName());
+
+ VirtualHost test = createVirtualHost("dot.in.a.name");
+
+ // Check, that the property stored within the <dot.in.a.name> tag has been properly loaded
+ assertEquals("virtual host with dots in the name has been properly loaded", TestableMemoryMessageStore.class.getName(), test.getMessageStore().getClass().getName());
+ }
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.java
new file mode 100644
index 0000000000..674abbfeb7
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/AbstractConfigurationTest.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.server.configuration.plugins;
+
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+import java.util.List;
+
+/**
+ * Test that verifies that given a Configuration a ConfigurationPlugin can
+ * process and validate that data.
+ */
+public class AbstractConfigurationTest extends QpidTestCase
+{
+ private static final double DOUBLE = 3.14;
+ private static final long POSITIVE_LONG = 1000;
+ private static final long NEGATIVE_LONG = -1000;
+ private static final int LIST_SIZE = 3;
+
+ class TestConfigPlugin extends AbstractConfiguration
+ {
+ @Override
+ public String[] getElementsProcessed()
+ {
+ return new String[]{"[@property]", "name",
+ "positiveLong", "negativeLong",
+ "true", "list", "double"};
+ }
+
+ @Override
+ public void validateConfiguration() throws ConfigurationException
+ {
+ // no validation requried
+ }
+
+ public String getName()
+ {
+ return getStringValue("name");
+ }
+
+ public String getProperty()
+ {
+ return getStringValue("[@property]");
+ }
+
+
+ }
+
+ private TestConfigPlugin _plugin;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ // Test does not directly use the AppRegistry but the configured broker
+ // is required for the correct ConfigurationPlugin processing
+ super.setUp();
+ XMLConfiguration xmlconfig = new XMLConfiguration();
+ xmlconfig.addProperty("base.element[@property]", "property");
+ xmlconfig.addProperty("base.element.name", "name");
+ // We make these strings as that is how they will be read from the file.
+ xmlconfig.addProperty("base.element.positiveLong", String.valueOf(POSITIVE_LONG));
+ xmlconfig.addProperty("base.element.negativeLong", String.valueOf(NEGATIVE_LONG));
+ xmlconfig.addProperty("base.element.boolean", String.valueOf(true));
+ xmlconfig.addProperty("base.element.double", String.valueOf(DOUBLE));
+ for (int i = 0; i < LIST_SIZE; i++)
+ {
+ xmlconfig.addProperty("base.element.list", i);
+ }
+
+ //Use a composite configuration as this is what our broker code uses.
+ CompositeConfiguration composite = new CompositeConfiguration();
+ composite.addConfiguration(xmlconfig);
+
+ _plugin = new TestConfigPlugin();
+
+ try
+ {
+ _plugin.setConfiguration("base.element", composite.subset("base.element"));
+ }
+ catch (ConfigurationException e)
+ {
+ e.printStackTrace();
+ fail(e.toString());
+ }
+
+ }
+
+ public void testHasConfiguration()
+ {
+ assertTrue("Plugin has no configuration ", _plugin.hasConfiguration());
+ _plugin = new TestConfigPlugin();
+ assertFalse("Plugins has configuration", _plugin.hasConfiguration());
+ }
+
+ public void testValuesRetreived()
+ {
+ assertEquals("Name not correct", "name", _plugin.getName());
+ assertEquals("Property not correct", "property", _plugin.getProperty());
+ }
+
+ public void testContainsPositiveLong()
+ {
+ assertTrue("positiveLong is not positive", _plugin.containsPositiveLong("positiveLong"));
+ assertFalse("NonExistentValue was found", _plugin.containsPositiveLong("NonExistentValue"));
+
+ try
+ {
+ _plugin.validatePositiveLong("positiveLong");
+ }
+ catch (ConfigurationException e)
+ {
+ fail(e.getMessage());
+ }
+
+ try
+ {
+ _plugin.validatePositiveLong("negativeLong");
+ fail("negativeLong should not be positive");
+ }
+ catch (ConfigurationException e)
+ {
+ assertEquals("negativeLong should not be reported as positive",
+ "TestConfigPlugin: unable to configure invalid negativeLong:" + NEGATIVE_LONG, e.getMessage());
+ }
+
+ }
+
+ public void testDouble()
+ {
+ assertEquals("Double value not returned", DOUBLE, _plugin.getDoubleValue("double"));
+ assertEquals("default Double value not returned", 0.0, _plugin.getDoubleValue("NonExistent"));
+ assertEquals("set default Double value not returned", DOUBLE, _plugin.getDoubleValue("NonExistent", DOUBLE));
+ }
+
+ public void testLong()
+ {
+ assertTrue("Long value not returned", _plugin.containsLong("positiveLong"));
+ assertFalse("Long value returned", _plugin.containsLong("NonExistent"));
+ assertEquals("Long value not returned", POSITIVE_LONG, _plugin.getLongValue("positiveLong"));
+ assertEquals("default Long value not returned", 0, _plugin.getLongValue("NonExistent"));
+ assertEquals("set default Long value not returned", NEGATIVE_LONG, _plugin.getLongValue("NonExistent", NEGATIVE_LONG));
+ }
+
+ public void testInt()
+ {
+ assertTrue("Int value not returned", _plugin.containsInt("positiveLong"));
+ assertFalse("Int value returned", _plugin.containsInt("NonExistent"));
+ assertEquals("Int value not returned", (int) POSITIVE_LONG, _plugin.getIntValue("positiveLong"));
+ assertEquals("default Int value not returned", 0, _plugin.getIntValue("NonExistent"));
+ assertEquals("set default Int value not returned", (int) NEGATIVE_LONG, _plugin.getIntValue("NonExistent", (int) NEGATIVE_LONG));
+ }
+
+ public void testString()
+ {
+ assertEquals("String value not returned", "name", _plugin.getStringValue("name"));
+ assertNull("Null default String value not returned", _plugin.getStringValue("NonExistent", null));
+ assertNull("default String value not returned", _plugin.getStringValue("NonExistent"));
+ assertEquals("default String value not returned", "Default", _plugin.getStringValue("NonExistent", "Default"));
+ }
+
+ public void testBoolean()
+ {
+ assertTrue("Boolean value not returned", _plugin.containsBoolean("boolean"));
+ assertFalse("Boolean value not returned", _plugin.containsBoolean("NonExistent"));
+ assertTrue("Boolean value not returned", _plugin.getBooleanValue("boolean"));
+ assertFalse("default String value not returned", _plugin.getBooleanValue("NonExistent"));
+ assertTrue("set default String value not returned", _plugin.getBooleanValue("NonExistent", true));
+ }
+
+ public void testList()
+ {
+ assertTrue("list not found in plugin", _plugin.contains("list"));
+ List list = _plugin.getListValue("list");
+ assertNotNull("Returned list should not be null", list);
+ assertEquals("List should not be empty", LIST_SIZE, list.size());
+
+ list = _plugin.getListValue("NonExistent");
+ assertNotNull("Returned list should not be null", list);
+ assertEquals("List is not empty", 0, list.size());
+ }
+
+ public void testContains()
+ {
+ assertTrue("list not found in plugin", _plugin.contains("list"));
+ assertFalse("NonExistent found in plugin", _plugin.contains("NonExistent"));
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java
deleted file mode 100644
index 14c7b8cb20..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java
+++ /dev/null
@@ -1,210 +0,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.
- *
- */
-package org.apache.qpid.server.configuration.plugins;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-import java.util.List;
-
-/**
- * Test that verifies that given a Configuration a ConfigurationPlugin can
- * process and validate that data.
- */
-public class ConfigurationPluginTest extends InternalBrokerBaseCase
-{
- private static final double DOUBLE = 3.14;
- private static final long POSITIVE_LONG = 1000;
- private static final long NEGATIVE_LONG = -1000;
- private static final int LIST_SIZE = 3;
-
- class ConfigPlugin extends ConfigurationPlugin
- {
- @Override
- public String[] getElementsProcessed()
- {
- return new String[]{"[@property]", "name",
- "positiveLong", "negativeLong",
- "true", "list", "double"};
- }
-
- @Override
- public void validateConfiguration() throws ConfigurationException
- {
- // no validation requried
- }
-
- public String getName()
- {
- return getStringValue("name");
- }
-
- public String getProperty()
- {
- return getStringValue("[@property]");
- }
-
-
- }
-
- private ConfigPlugin _plugin;
-
- @Override
- public void setUp() throws Exception
- {
- // Test does not directly use the AppRegistry but the configured broker
- // is required for the correct ConfigurationPlugin processing
- super.setUp();
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("base.element[@property]", "property");
- xmlconfig.addProperty("base.element.name", "name");
- // We make these strings as that is how they will be read from the file.
- xmlconfig.addProperty("base.element.positiveLong", String.valueOf(POSITIVE_LONG));
- xmlconfig.addProperty("base.element.negativeLong", String.valueOf(NEGATIVE_LONG));
- xmlconfig.addProperty("base.element.boolean", String.valueOf(true));
- xmlconfig.addProperty("base.element.double", String.valueOf(DOUBLE));
- for (int i = 0; i < LIST_SIZE; i++)
- {
- xmlconfig.addProperty("base.element.list", i);
- }
-
- //Use a composite configuration as this is what our broker code uses.
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- _plugin = new ConfigPlugin();
-
- try
- {
- _plugin.setConfiguration("base.element", composite.subset("base.element"));
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.toString());
- }
-
- }
-
- public void testHasConfiguration()
- {
- assertTrue("Plugin has no configuration ", _plugin.hasConfiguration());
- _plugin = new ConfigPlugin();
- assertFalse("Plugins has configuration", _plugin.hasConfiguration());
- }
-
- public void testValuesRetreived()
- {
- assertEquals("Name not correct", "name", _plugin.getName());
- assertEquals("Property not correct", "property", _plugin.getProperty());
- }
-
- public void testContainsPositiveLong()
- {
- assertTrue("positiveLong is not positive", _plugin.containsPositiveLong("positiveLong"));
- assertFalse("NonExistentValue was found", _plugin.containsPositiveLong("NonExistentValue"));
-
- try
- {
- _plugin.validatePositiveLong("positiveLong");
- }
- catch (ConfigurationException e)
- {
- fail(e.getMessage());
- }
-
- try
- {
- _plugin.validatePositiveLong("negativeLong");
- fail("negativeLong should not be positive");
- }
- catch (ConfigurationException e)
- {
- assertEquals("negativeLong should not be reported as positive",
- "ConfigPlugin: unable to configure invalid negativeLong:" + NEGATIVE_LONG, e.getMessage());
- }
-
- }
-
- public void testDouble()
- {
- assertEquals("Double value not returned", DOUBLE, _plugin.getDoubleValue("double"));
- assertEquals("default Double value not returned", 0.0, _plugin.getDoubleValue("NonExistent"));
- assertEquals("set default Double value not returned", DOUBLE, _plugin.getDoubleValue("NonExistent", DOUBLE));
- }
-
- public void testLong()
- {
- assertTrue("Long value not returned", _plugin.containsLong("positiveLong"));
- assertFalse("Long value returned", _plugin.containsLong("NonExistent"));
- assertEquals("Long value not returned", POSITIVE_LONG, _plugin.getLongValue("positiveLong"));
- assertEquals("default Long value not returned", 0, _plugin.getLongValue("NonExistent"));
- assertEquals("set default Long value not returned", NEGATIVE_LONG, _plugin.getLongValue("NonExistent", NEGATIVE_LONG));
- }
-
- public void testInt()
- {
- assertTrue("Int value not returned", _plugin.containsInt("positiveLong"));
- assertFalse("Int value returned", _plugin.containsInt("NonExistent"));
- assertEquals("Int value not returned", (int) POSITIVE_LONG, _plugin.getIntValue("positiveLong"));
- assertEquals("default Int value not returned", 0, _plugin.getIntValue("NonExistent"));
- assertEquals("set default Int value not returned", (int) NEGATIVE_LONG, _plugin.getIntValue("NonExistent", (int) NEGATIVE_LONG));
- }
-
- public void testString()
- {
- assertEquals("String value not returned", "name", _plugin.getStringValue("name"));
- assertNull("Null default String value not returned", _plugin.getStringValue("NonExistent", null));
- assertNull("default String value not returned", _plugin.getStringValue("NonExistent"));
- assertEquals("default String value not returned", "Default", _plugin.getStringValue("NonExistent", "Default"));
- }
-
- public void testBoolean()
- {
- assertTrue("Boolean value not returned", _plugin.containsBoolean("boolean"));
- assertFalse("Boolean value not returned", _plugin.containsBoolean("NonExistent"));
- assertTrue("Boolean value not returned", _plugin.getBooleanValue("boolean"));
- assertFalse("default String value not returned", _plugin.getBooleanValue("NonExistent"));
- assertTrue("set default String value not returned", _plugin.getBooleanValue("NonExistent", true));
- }
-
- public void testList()
- {
- assertTrue("list not found in plugin", _plugin.contains("list"));
- List list = _plugin.getListValue("list");
- assertNotNull("Returned list should not be null", list);
- assertEquals("List should not be empty", LIST_SIZE, list.size());
-
- list = _plugin.getListValue("NonExistent");
- assertNotNull("Returned list should not be null", list);
- assertEquals("List is not empty", 0, list.size());
- }
-
- public void testContains()
- {
- assertTrue("list not found in plugin", _plugin.contains("list"));
- assertFalse("NonExistent found in plugin", _plugin.contains("NonExistent"));
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
new file mode 100644
index 0000000000..c1ebe26f52
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
@@ -0,0 +1,405 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.AuthenticationProviderFactory;
+import org.apache.qpid.server.model.adapter.PortFactory;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class BrokerRecovererTest extends TestCase
+{
+ private BrokerRecoverer _brokerRecoverer;
+ private ConfigurationEntry _brokerEntry = mock(ConfigurationEntry.class);
+
+ private UUID _brokerId = UUID.randomUUID();
+ private Map<String, Collection<ConfigurationEntry>> _brokerEntryChildren = new HashMap<String, Collection<ConfigurationEntry>>();
+ private ConfigurationEntry _authenticationProviderEntry1;
+ private AuthenticationProvider _authenticationProvider1;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ _brokerRecoverer = new BrokerRecoverer(mock(AuthenticationProviderFactory.class), mock(PortFactory.class), mock(StatisticsGatherer.class),
+ mock(VirtualHostRegistry.class), mock(LogRecorder.class), mock(RootMessageLogger.class), mock(TaskExecutor.class));
+ when(_brokerEntry.getId()).thenReturn(_brokerId);
+ when(_brokerEntry.getChildren()).thenReturn(_brokerEntryChildren);
+
+ //Add a base AuthenticationProvider for all tests
+ _authenticationProvider1 = mock(AuthenticationProvider.class);
+ when(_authenticationProvider1.getName()).thenReturn("authenticationProvider1");
+ _authenticationProviderEntry1 = mock(ConfigurationEntry.class);
+ _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1));
+ }
+
+ public void testCreateBrokerAttributes()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+ attributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 9l);
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 8l);
+ attributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 7l);
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 6l);
+ attributes.put(Broker.ALERT_REPEAT_GAP, 5l);
+ attributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 5l);
+ attributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 3l);
+ attributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 2);
+ attributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, true);
+ attributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 1l);
+ attributes.put(Broker.ACL_FILE, "/path/to/acl");
+ attributes.put(Broker.SESSION_COUNT_LIMIT, 1000);
+ attributes.put(Broker.HEART_BEAT_DELAY, 2000);
+ attributes.put(Broker.STATISTICS_REPORTING_PERIOD, 4000);
+ attributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, true);
+
+ Map<String, Object> entryAttributes = new HashMap<String, Object>();
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ String value = convertToString(attribute.getValue());
+ entryAttributes.put(attribute.getKey(), value);
+ }
+
+ when(_brokerEntry.getAttributes()).thenReturn(entryAttributes);
+
+ final ConfigurationEntry virtualHostEntry = mock(ConfigurationEntry.class);
+ String typeName = VirtualHost.class.getSimpleName();
+ when(virtualHostEntry.getType()).thenReturn(typeName);
+ _brokerEntryChildren.put(typeName, Arrays.asList(virtualHostEntry));
+ final VirtualHost virtualHost = mock(VirtualHost.class);
+ when(virtualHost.getName()).thenReturn("test");
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[] { virtualHostEntry, _authenticationProviderEntry1 },
+ new ConfiguredObject[] { virtualHost, _authenticationProvider1 });
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ Object attributeValue = broker.getAttribute(attribute.getKey());
+ assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+ }
+ }
+
+ public void testCreateBrokerWithVirtualHost()
+ {
+ final ConfigurationEntry virtualHostEntry = mock(ConfigurationEntry.class);
+
+ String typeName = VirtualHost.class.getSimpleName();
+ when(virtualHostEntry.getType()).thenReturn(typeName);
+ _brokerEntryChildren.put(typeName, Arrays.asList(virtualHostEntry));
+
+ final VirtualHost virtualHost = mock(VirtualHost.class);
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{virtualHostEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{virtualHost, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(1, broker.getVirtualHosts().size());
+ assertEquals(virtualHost, broker.getVirtualHosts().iterator().next());
+ }
+
+ public void testCreateBrokerWithPorts()
+ {
+ ConfigurationEntry portEntry = mock(ConfigurationEntry.class);
+ Port port = mock(Port.class);
+ _brokerEntryChildren.put(Port.class.getSimpleName(), Arrays.asList(portEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{portEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{port, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singletonList(port), broker.getPorts());
+ }
+
+ public void testCreateBrokerWithoutAuthenticationProviderThrowsException()
+ {
+ assertNotNull("expected to remove the base entry", _brokerEntryChildren.remove(AuthenticationProvider.class.getSimpleName()));
+ assertTrue("should be empty", _brokerEntryChildren.isEmpty());
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[0], new ConfiguredObject[0]);
+
+ try
+ {
+ _brokerRecoverer.create(recovererProvider, _brokerEntry);
+ fail("should have thrown an exception due to missing authentication provider configuration");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ //expected
+ }
+ }
+
+ public void testCreateBrokerWithOneAuthenticationProvider()
+ {
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{_authenticationProviderEntry1},
+ new ConfiguredObject[]{_authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singletonList(_authenticationProvider1), broker.getAuthenticationProviders());
+ }
+
+ public void testCreateBrokerWithMultipleAuthenticationProvidersAndNoDefaultThrowsException()
+ {
+ AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+ when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+ ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+ _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+ Map<String,Object> emptyBrokerAttributes = new HashMap<String,Object>();
+ when(_brokerEntry.getAttributes()).thenReturn(emptyBrokerAttributes);
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{authenticationProviderEntry2, _authenticationProviderEntry1},
+ new ConfiguredObject[]{authenticationProvider2, _authenticationProvider1});
+ try
+ {
+ _brokerRecoverer.create(recovererProvider, _brokerEntry);
+ fail("should have thrown an exception due to missing authentication provider default");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ //expected
+ }
+ }
+
+ public void testCreateBrokerWithMultipleAuthenticationProvidersAndPorts()
+ {
+ //Create a second authentication provider
+ AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+ when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+ ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+ _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+ //Set the default authentication provider
+ Map<String,Object> brokerAtttributes = new HashMap<String,Object>();
+ when(_brokerEntry.getAttributes()).thenReturn(brokerAtttributes);
+ brokerAtttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider2");
+
+ //Add a couple ports, one with a defined authentication provider and
+ //one without (which should then use the default)
+ ConfigurationEntry portEntry1 = mock(ConfigurationEntry.class);
+ Port port1 = mock(Port.class);
+ when(port1.getName()).thenReturn("port1");
+ when(port1.getPort()).thenReturn(5671);
+ when(port1.getAttribute(Port.AUTHENTICATION_MANAGER)).thenReturn("authenticationProvider1");
+ ConfigurationEntry portEntry2 = mock(ConfigurationEntry.class);
+ Port port2 = mock(Port.class);
+ when(port2.getName()).thenReturn("port2");
+ when(port2.getPort()).thenReturn(5672);
+ _brokerEntryChildren.put(Port.class.getSimpleName(), Arrays.asList(portEntry1, portEntry2));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(
+ new ConfigurationEntry[]{portEntry1, portEntry2, authenticationProviderEntry2, _authenticationProviderEntry1},
+ new ConfiguredObject[]{port1, port2, authenticationProvider2, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals("Unexpected number of authentication providers", 2,broker.getAuthenticationProviders().size());
+
+ Collection<Port> ports = broker.getPorts();
+ assertEquals("Unexpected number of ports", 2, ports.size());
+ assertTrue(ports.contains(port1));
+ assertTrue(ports.contains(port2));
+
+ verify(port1).setAuthenticationProvider(any(AuthenticationProvider.class));
+ verify(port1).setAuthenticationProvider(_authenticationProvider1);
+
+ verify(port2).setAuthenticationProvider(any(AuthenticationProvider.class));
+ verify(port2).setAuthenticationProvider(authenticationProvider2);
+ }
+
+ public void testCreateBrokerAssignsGroupAccessorToAuthenticationProviders()
+ {
+ //Create a second authentication provider
+ AuthenticationProvider authenticationProvider2 = mock(AuthenticationProvider.class);
+ when(authenticationProvider2.getName()).thenReturn("authenticationProvider2");
+ ConfigurationEntry authenticationProviderEntry2 = mock(ConfigurationEntry.class);
+ _brokerEntryChildren.put(AuthenticationProvider.class.getSimpleName(), Arrays.asList(_authenticationProviderEntry1, authenticationProviderEntry2));
+
+ //Set the default authentication provider
+ Map<String,Object> brokerAtttributes = new HashMap<String,Object>();
+ when(_brokerEntry.getAttributes()).thenReturn(brokerAtttributes);
+ brokerAtttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider2");
+
+ //Create a group provider
+ ConfigurationEntry groupProviderEntry = mock(ConfigurationEntry.class);
+ GroupProvider groupProvider = mock(GroupProvider.class);
+ _brokerEntryChildren.put(GroupProvider.class.getSimpleName(), Arrays.asList(groupProviderEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(
+ new ConfigurationEntry[]{groupProviderEntry, authenticationProviderEntry2, _authenticationProviderEntry1},
+ new ConfiguredObject[]{groupProvider, authenticationProvider2, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals("Unexpected number of authentication providers", 2, broker.getAuthenticationProviders().size());
+
+ //verify that a GroupAcessor was added to the AuthenticationProviders
+ verify(_authenticationProvider1).setGroupAccessor(any(GroupPrincipalAccessor.class));
+ verify(authenticationProvider2).setGroupAccessor(any(GroupPrincipalAccessor.class));
+ }
+
+ public void testCreateBrokerWithGroupProvider()
+ {
+ ConfigurationEntry groupProviderEntry = mock(ConfigurationEntry.class);
+ GroupProvider groupProvider = mock(GroupProvider.class);
+ _brokerEntryChildren.put(GroupProvider.class.getSimpleName(), Arrays.asList(groupProviderEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{groupProviderEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{groupProvider, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singletonList(groupProvider), broker.getGroupProviders());
+ }
+
+ public void testCreateBrokerWithPlugins()
+ {
+ ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+ Plugin plugin = mock(Plugin.class);
+ _brokerEntryChildren.put(Plugin.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{plugin, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singleton(plugin), new HashSet<ConfiguredObject>(broker.getChildren(Plugin.class)));
+ }
+
+ public void testCreateBrokerWithKeyStores()
+ {
+ ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+ KeyStore keyStore = mock(KeyStore.class);
+ _brokerEntryChildren.put(KeyStore.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{keyStore, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singleton(keyStore), new HashSet<ConfiguredObject>(broker.getChildren(KeyStore.class)));
+ }
+
+ public void testCreateBrokerWithTrustStores()
+ {
+ ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+ TrustStore trustStore = mock(TrustStore.class);
+ _brokerEntryChildren.put(TrustStore.class.getSimpleName(), Arrays.asList(pluginEntry));
+
+ RecovererProvider recovererProvider = createRecoveryProvider(new ConfigurationEntry[]{pluginEntry, _authenticationProviderEntry1},
+ new ConfiguredObject[]{trustStore, _authenticationProvider1});
+
+ Broker broker = _brokerRecoverer.create(recovererProvider, _brokerEntry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singleton(trustStore), new HashSet<ConfiguredObject>(broker.getChildren(TrustStore.class)));
+ }
+
+ private String convertToString(Object attributeValue)
+ {
+ return String.valueOf(attributeValue);
+ }
+
+ private RecovererProvider createRecoveryProvider(final ConfigurationEntry[] entries, final ConfiguredObject[] objectsToRecoverer)
+ {
+ RecovererProvider recovererProvider = new RecovererProvider()
+ {
+ @Override
+ public ConfiguredObjectRecoverer<? extends ConfiguredObject> getRecoverer(String type)
+ {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ final ConfiguredObjectRecoverer<? extends ConfiguredObject> recovever = new ConfiguredObjectRecoverer()
+ {
+ @Override
+ public ConfiguredObject create(RecovererProvider recovererProvider, ConfigurationEntry entry, ConfiguredObject... parents)
+ {
+ for (int i = 0; i < entries.length; i++)
+ {
+ ConfigurationEntry e = entries[i];
+ if (entry == e)
+ {
+ return objectsToRecoverer[i];
+ }
+ }
+ return null;
+ }
+ };
+
+ return recovever;
+ }
+ };
+ return recovererProvider;
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.java
new file mode 100644
index 0000000000..c95f67beb9
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/DefaultRecovererProviderTest.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.server.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class DefaultRecovererProviderTest extends TestCase
+{
+ public void testGetRecoverer()
+ {
+ String[] supportedTypes = {Broker.class.getSimpleName(),
+ VirtualHost.class.getSimpleName(), AuthenticationProvider.class.getSimpleName(),
+ GroupProvider.class.getSimpleName(), Plugin.class.getSimpleName(), Port.class.getSimpleName()};
+
+ // mocking the required object
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ VirtualHostRegistry virtualHostRegistry = mock(VirtualHostRegistry.class);
+ LogRecorder logRecorder = mock(LogRecorder.class);
+ RootMessageLogger rootMessageLogger = mock(RootMessageLogger.class);
+ TaskExecutor taskExecutor = mock(TaskExecutor.class);
+
+ DefaultRecovererProvider provider = new DefaultRecovererProvider(statisticsGatherer, virtualHostRegistry, logRecorder, rootMessageLogger, taskExecutor);
+ for (String configuredObjectType : supportedTypes)
+ {
+ ConfiguredObjectRecoverer<?> recovever = provider.getRecoverer(configuredObjectType);
+ assertNotNull("Null recoverer for type: " + configuredObjectType, recovever);
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java
new file mode 100644
index 0000000000..6713574e4b
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/GroupProviderRecovererTest.java
@@ -0,0 +1,97 @@
+/*
+ *
+ * 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.configuration.startup;
+import static org.mockito.Mockito.*;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.plugin.GroupManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.group.GroupManager;
+
+import junit.framework.TestCase;
+
+public class GroupProviderRecovererTest extends TestCase
+{
+
+ private UUID _id;
+ private Map<String, Object> _attributes;
+
+ private GroupManagerFactory _factory;
+ private QpidServiceLoader<GroupManagerFactory> _groupManagerServiceLoader;
+ private Broker _broker;
+ private ConfigurationEntry _configurationEntry;
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _id = UUID.randomUUID();
+ _attributes = new HashMap<String, Object>();
+
+ _factory = mock(GroupManagerFactory.class);
+
+ _groupManagerServiceLoader = mock(QpidServiceLoader.class);
+ when(_groupManagerServiceLoader.instancesOf(GroupManagerFactory.class)).thenReturn(Collections.singletonList(_factory ));
+
+ _broker = mock(Broker.class);
+
+ _configurationEntry = mock(ConfigurationEntry.class);
+ when(_configurationEntry.getId()).thenReturn(_id);
+ when(_configurationEntry.getAttributes()).thenReturn(_attributes);
+ }
+
+ public void testCreate()
+ {
+ GroupManager groupManager = mock(GroupManager.class);
+ String name = groupManager.getClass().getSimpleName();
+ when(_factory.createInstance(_attributes)).thenReturn(groupManager);
+ GroupProviderRecoverer groupProviderRecoverer = new GroupProviderRecoverer(_groupManagerServiceLoader);
+ GroupProvider groupProvider = groupProviderRecoverer.create(null, _configurationEntry, _broker);
+ assertNotNull("Null group provider", groupProvider);
+ assertEquals("Unexpected name", name, groupProvider.getName());
+ assertEquals("Unexpected ID", _id, groupProvider.getId());
+ }
+
+ public void testCreateThrowsExceptionWhenNoGroupManagerIsCreated()
+ {
+ when(_factory.createInstance(_attributes)).thenReturn(null);
+
+ GroupProviderRecoverer groupProviderRecoverer = new GroupProviderRecoverer(_groupManagerServiceLoader);
+ try
+ {
+ groupProviderRecoverer.create(null, _configurationEntry, _broker);
+ fail("Configuration exception should be thrown when group manager is not created");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java
new file mode 100644
index 0000000000..0d7dc1bb06
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/KeyStoreRecovererTest.java
@@ -0,0 +1,111 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.TrustStore;
+
+import junit.framework.TestCase;
+
+public class KeyStoreRecovererTest extends TestCase
+{
+
+ public void testCreateWithAllAttributesProvided()
+ {
+ Map<String, Object> attributes = getKeyStoreAttributes();
+
+ UUID id = UUID.randomUUID();
+ Broker broker = mock(Broker.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ when(entry.getAttributes()).thenReturn(attributes);
+ when(entry.getId()).thenReturn(id);
+
+ KeyStoreRecoverer recovever = new KeyStoreRecoverer();
+
+ KeyStore KeyStore = recovever.create(null, entry, broker);
+ assertNotNull("Key store configured object is not created", KeyStore);
+ assertEquals(id, KeyStore.getId());
+ assertEquals("my-secret-password", KeyStore.getPassword());
+
+ assertNull("Password was unexpectedly returned from configured object", KeyStore.getAttribute(TrustStore.PASSWORD));
+
+ // password attribute should not be exposed by a key store configured object
+ // so, we should set password value to null in the map being used to create the key store configured object
+ attributes.put(KeyStore.PASSWORD, null);
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ Object attributeValue = KeyStore.getAttribute(attribute.getKey());
+ assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+ }
+ }
+
+ private Map<String, Object> getKeyStoreAttributes()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(KeyStore.NAME, getName());
+ attributes.put(KeyStore.PATH, "/path/to/KeyStore");
+ attributes.put(KeyStore.PASSWORD, "my-secret-password");
+ attributes.put(KeyStore.TYPE, "NON-JKS");
+ attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(KeyStore.CERTIFICATE_ALIAS, "my-cert-alias");
+ attributes.put(KeyStore.DESCRIPTION, "description");
+ return attributes;
+ }
+
+ public void testCreateWithMissedRequiredAttributes()
+ {
+ Map<String, Object> attributes = getKeyStoreAttributes();
+
+ UUID id = UUID.randomUUID();
+ Broker broker = mock(Broker.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ when(entry.getId()).thenReturn(id);
+
+ KeyStoreRecoverer recovever = new KeyStoreRecoverer();
+
+ String[] mandatoryProperties = {KeyStore.NAME, KeyStore.PATH, KeyStore.PASSWORD};
+ for (int i = 0; i < mandatoryProperties.length; i++)
+ {
+ Map<String, Object> properties = new HashMap<String, Object>(attributes);
+ properties.remove(mandatoryProperties[i]);
+ when(entry.getAttributes()).thenReturn(properties);
+ try
+ {
+ recovever.create(null, entry, broker);
+ fail("Cannot create key store without a " + mandatoryProperties[i]);
+ }
+ catch(IllegalArgumentException e)
+ {
+ // pass
+ }
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java
new file mode 100644
index 0000000000..42fd742407
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class PluginRecovererTest extends TestCase
+{
+ private UUID _id;
+ private Map<String, Object> _attributes;
+
+ private PluginFactory _factory;
+ private QpidServiceLoader<PluginFactory> _pluginFactoryServiceLoader;
+ private Broker _broker;
+ private ConfigurationEntry _configurationEntry;
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _id = UUID.randomUUID();
+ _attributes = new HashMap<String, Object>();
+
+ _factory = mock(PluginFactory.class);
+
+ _pluginFactoryServiceLoader = mock(QpidServiceLoader.class);
+ when(_pluginFactoryServiceLoader.instancesOf(PluginFactory.class)).thenReturn(Collections.singletonList(_factory ));
+
+ _broker = mock(Broker.class);
+
+ _configurationEntry = mock(ConfigurationEntry.class);
+ when(_configurationEntry.getId()).thenReturn(_id);
+ when(_configurationEntry.getAttributes()).thenReturn(_attributes);
+ }
+
+ public void testCreate()
+ {
+ Plugin pluginFromFactory = mock(Plugin.class);
+ when(pluginFromFactory.getId()).thenReturn(_id);
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(pluginFromFactory);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ ConfiguredObject pluginFromRecoverer = pluginRecoverer.create(null, _configurationEntry, _broker);
+ assertNotNull("Null group provider", pluginFromRecoverer);
+ assertSame("Unexpected plugin", pluginFromFactory, pluginFromRecoverer);
+ assertEquals("Unexpected ID", _id, pluginFromRecoverer.getId());
+ }
+
+ public void testCreateThrowsExceptionForUnexpectedId()
+ {
+ Plugin pluginFromFactory = mock(Plugin.class);
+ when(pluginFromFactory.getId()).thenReturn(UUID.randomUUID());
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(pluginFromFactory);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ try
+ {
+ pluginRecoverer.create(null, _configurationEntry, _broker);
+ fail("An exception should be thrown for incorrect id");
+ }
+ catch(IllegalStateException e)
+ {
+ //pass
+ }
+ }
+
+ public void testCreateThrowsExceptionWhenNoPluginIsCreated()
+ {
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(null);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ try
+ {
+ pluginRecoverer.create(null, _configurationEntry, _broker);
+ fail("Configuration exception should be thrown when plugin is not created");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java
new file mode 100644
index 0000000000..3b64f45c80
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/TrustStoreRecovererTest.java
@@ -0,0 +1,108 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class TrustStoreRecovererTest extends QpidTestCase
+{
+ public void testCreateWithAllAttributesProvided()
+ {
+ Map<String, Object> attributes = getTrustStoreAttributes();
+
+ UUID id = UUID.randomUUID();
+ Broker broker = mock(Broker.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ when(entry.getAttributes()).thenReturn(attributes);
+ when(entry.getId()).thenReturn(id);
+
+ TrustStoreRecoverer recovever = new TrustStoreRecoverer();
+
+ TrustStore trustStore = recovever.create(null, entry, broker);
+ assertNotNull("Trust store configured object is not created", trustStore);
+ assertEquals(id, trustStore.getId());
+ assertEquals("my-secret-password", trustStore.getPassword());
+
+ assertNull("Password was unexpectedly returned from configured object", trustStore.getAttribute(TrustStore.PASSWORD));
+
+ // password attribute should not be exposed by a trust store configured object
+ // so, we should set password value to null in the map being used to create the trust store configured object
+ attributes.put(TrustStore.PASSWORD, null);
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ Object attributeValue = trustStore.getAttribute(attribute.getKey());
+ assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
+ }
+ }
+
+ private Map<String, Object> getTrustStoreAttributes()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(TrustStore.NAME, getName());
+ attributes.put(TrustStore.PATH, "/path/to/truststore");
+ attributes.put(TrustStore.PASSWORD, "my-secret-password");
+ attributes.put(TrustStore.TYPE, "NON-JKS");
+ attributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(TrustStore.DESCRIPTION, "Description");
+ return attributes;
+ }
+
+ public void testCreateWithMissedRequiredAttributes()
+ {
+ Map<String, Object> attributes = getTrustStoreAttributes();
+
+ UUID id = UUID.randomUUID();
+ Broker broker = mock(Broker.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ when(entry.getAttributes()).thenReturn(attributes);
+ when(entry.getId()).thenReturn(id);
+
+ TrustStoreRecoverer recovever = new TrustStoreRecoverer();
+
+ String[] mandatoryProperties = {TrustStore.NAME, TrustStore.PATH, TrustStore.PASSWORD};
+ for (int i = 0; i < mandatoryProperties.length; i++)
+ {
+ Map<String, Object> properties = new HashMap<String, Object>(attributes);
+ properties.remove(mandatoryProperties[i]);
+ when(entry.getAttributes()).thenReturn(properties);
+ try
+ {
+ recovever.create(null, entry, broker);
+ fail("Cannot create key store without a " + mandatoryProperties[i]);
+ }
+ catch(IllegalArgumentException e)
+ {
+ // pass
+ }
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
new file mode 100644
index 0000000000..57d219f85f
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
@@ -0,0 +1,124 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+
+public class VirtualHostRecovererTest extends TestCase
+{
+ public void testCreate()
+ {
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ SecurityManager securityManager = mock(SecurityManager.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ Broker parent = mock(Broker.class);
+ when(parent.getSecurityManager()).thenReturn(securityManager);
+
+ VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.CONFIG_PATH, "/path/to/virtualhost.xml");
+ when(entry.getAttributes()).thenReturn(attributes);
+
+ VirtualHost host = recoverer.create(null, entry, parent);
+
+ assertNotNull("Null is returned", host);
+ assertEquals("Unexpected name", getName(), host.getName());
+ }
+
+ public void testCreateVirtualHostFromStoreConfigAtrributes()
+ {
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ SecurityManager securityManager = mock(SecurityManager.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ Broker parent = mock(Broker.class);
+ when(parent.getSecurityManager()).thenReturn(securityManager);
+
+ VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.STORE_PATH, "/path/to/virtualhost/store");
+ attributes.put(VirtualHost.STORE_TYPE, "DERBY");
+ when(entry.getAttributes()).thenReturn(attributes);
+
+ VirtualHost host = recoverer.create(null, entry, parent);
+
+ assertNotNull("Null is returned", host);
+ assertEquals("Unexpected name", getName(), host.getName());
+ }
+
+ public void testCreateWithoutMandatoryAttributesResultsInException()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.CONFIG_PATH, "/path/to/virtualhost.xml");
+ String[] mandatoryAttributes = {VirtualHost.NAME, VirtualHost.CONFIG_PATH};
+
+ checkMandatoryAttributesAreValidated(mandatoryAttributes, attributes);
+
+ attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.STORE_PATH, "/path/to/store");
+ attributes.put(VirtualHost.STORE_TYPE, "DERBY");
+ mandatoryAttributes = new String[]{VirtualHost.NAME, VirtualHost.STORE_PATH, VirtualHost.STORE_TYPE};
+
+ checkMandatoryAttributesAreValidated(mandatoryAttributes, attributes);
+ }
+
+ public void checkMandatoryAttributesAreValidated(String[] mandatoryAttributes, Map<String, Object> attributes)
+ {
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ SecurityManager securityManager = mock(SecurityManager.class);
+ ConfigurationEntry entry = mock(ConfigurationEntry.class);
+ Broker parent = mock(Broker.class);
+ when(parent.getSecurityManager()).thenReturn(securityManager);
+ VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
+
+ for (String name : mandatoryAttributes)
+ {
+ Map<String, Object> copy = new HashMap<String, Object>(attributes);
+ copy.remove(name);
+ when(entry.getAttributes()).thenReturn(copy);
+ try
+ {
+ recoverer.create(null, entry, parent);
+ fail("Cannot create a virtual host without a manadatory attribute " + name);
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
new file mode 100644
index 0000000000..b357c0b8e9
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
@@ -0,0 +1,392 @@
+/*
+ *
+ * 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.configuration.store;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public abstract class ConfigurationEntryStoreTestCase extends QpidTestCase
+{
+ private ConfigurationEntryStore _store;
+
+ private UUID _brokerId;
+ private UUID _virtualHostId;
+ private UUID _authenticationProviderId;
+
+ private Map<String, Object> _brokerAttributes;
+ private Map<String, Object> _virtualHostAttributes;
+ private Map<String, Object> _authenticationProviderAttributes;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ _brokerId = UUID.randomUUID();
+ _brokerAttributes = new HashMap<String, Object>();
+ _brokerAttributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+ _brokerAttributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+ _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 9);
+ _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 8);
+ _brokerAttributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 7);
+ _brokerAttributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 6);
+ _brokerAttributes.put(Broker.ALERT_REPEAT_GAP, 5);
+ _brokerAttributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 5);
+ _brokerAttributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 3);
+ _brokerAttributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 2);
+ _brokerAttributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, true);
+ _brokerAttributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 1);
+ _brokerAttributes.put(Broker.ACL_FILE, "/path/to/acl");
+ _brokerAttributes.put(Broker.SESSION_COUNT_LIMIT, 1000);
+ _brokerAttributes.put(Broker.HEART_BEAT_DELAY, 2000);
+ _brokerAttributes.put(Broker.STATISTICS_REPORTING_PERIOD, 4000);
+ _brokerAttributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, true);
+
+ _virtualHostId = UUID.randomUUID();
+ _virtualHostAttributes = new HashMap<String, Object>();
+ _virtualHostAttributes.put(VirtualHost.NAME, "test");
+ _virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/test");
+
+ _authenticationProviderId = UUID.randomUUID();
+ _authenticationProviderAttributes = new HashMap<String, Object>();
+ _authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+ _authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, AnonymousAuthenticationManager.class.getSimpleName());
+
+ _store = createStore(_brokerId, _brokerAttributes);
+ addConfiguration(_virtualHostId, VirtualHost.class.getSimpleName(), _virtualHostAttributes);
+ addConfiguration(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(), _authenticationProviderAttributes);
+ }
+
+ // ??? perhaps it should not be abstract
+ protected abstract ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception;
+
+ protected abstract void addConfiguration(UUID id, String type, Map<String, Object> attributes);
+
+ protected ConfigurationEntryStore getStore()
+ {
+ return _store;
+ }
+
+ public void testGetRootEntry()
+ {
+ ConfigurationEntry brokerConfigEntry = _store.getRootEntry();
+ assertNotNull("Root entry does not exist", brokerConfigEntry);
+ assertEquals("Unexpected id", _brokerId, brokerConfigEntry.getId());
+ assertEquals("Unexpected type ", Broker.class.getSimpleName(), brokerConfigEntry.getType());
+ Map<String, Object> attributes = brokerConfigEntry.getAttributes();
+ assertNotNull("Attributes cannot be null", attributes);
+ assertEquals("Unexpected attributes", _brokerAttributes, attributes);
+ }
+
+ public void testGetEntry()
+ {
+ ConfigurationEntry authenticationProviderConfigEntry = _store.getEntry(_authenticationProviderId);
+ assertNotNull("Provider with id " + _authenticationProviderId + " should exist", authenticationProviderConfigEntry);
+ assertEquals("Unexpected id", _authenticationProviderId, authenticationProviderConfigEntry.getId());
+ assertEquals("Unexpected type ", AuthenticationProvider.class.getSimpleName(), authenticationProviderConfigEntry.getType());
+ Map<String, Object> attributes = authenticationProviderConfigEntry.getAttributes();
+ assertNotNull("Attributes cannot be null", attributes);
+ assertEquals("Unexpected attributes", _authenticationProviderAttributes, attributes);
+ }
+
+ public void testRemove()
+ {
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put(VirtualHost.NAME, getName());
+ virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config");
+ UUID virtualHostId = UUID.randomUUID();
+ addConfiguration(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes);
+
+ assertNotNull("Virtual host with id " + virtualHostId + " should exist", _store.getEntry(virtualHostId));
+
+ _store.remove(virtualHostId);
+ assertNull("Authentication provider configuration should be removed", _store.getEntry(virtualHostId));
+ }
+
+ public void testRemoveMultipleEntries()
+ {
+ Map<String, Object> virtualHost1Attributes = new HashMap<String, Object>();
+ virtualHost1Attributes.put(VirtualHost.NAME, "test1");
+ virtualHost1Attributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+ UUID virtualHost1Id = UUID.randomUUID();
+ addConfiguration(virtualHost1Id, VirtualHost.class.getSimpleName(), virtualHost1Attributes);
+
+ Map<String, Object> virtualHost2Attributes = new HashMap<String, Object>();
+ virtualHost2Attributes.put(VirtualHost.NAME, "test1");
+ virtualHost2Attributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config2");
+ UUID virtualHost2Id = UUID.randomUUID();
+ addConfiguration(virtualHost2Id, VirtualHost.class.getSimpleName(), virtualHost2Attributes);
+
+ assertNotNull("Virtual host with id " + virtualHost1Id + " should exist", _store.getEntry(virtualHost1Id));
+ assertNotNull("Virtual host with id " + virtualHost2Id + " should exist", _store.getEntry(virtualHost2Id));
+
+ UUID[] deletedIds = _store.remove(virtualHost1Id, virtualHost2Id);
+ assertNotNull("Unexpected deleted ids", deletedIds);
+ assertEquals("Unexpected id of first deleted virtual host", virtualHost1Id , deletedIds[0]);
+ assertEquals("Unexpected id of second deleted virtual host", virtualHost2Id , deletedIds[1]);
+ assertNull("First virtual host configuration should be removed", _store.getEntry(virtualHost1Id));
+ assertNull("Second virtual host configuration should be removed", _store.getEntry(virtualHost2Id));
+ }
+
+ public void testSaveBroker()
+ {
+ ConfigurationEntry brokerConfigEntry = _store.getRootEntry();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Broker.DEFAULT_VIRTUAL_HOST, "test");
+ attributes.put(Broker.DEFAULT_AUTHENTICATION_PROVIDER, "authenticationProvider1");
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_AGE, 19);
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_COUNT, 18);
+ attributes.put(Broker.ALERT_THRESHOLD_QUEUE_DEPTH, 17);
+ attributes.put(Broker.ALERT_THRESHOLD_MESSAGE_SIZE, 16);
+ attributes.put(Broker.ALERT_REPEAT_GAP, 15);
+ attributes.put(Broker.FLOW_CONTROL_SIZE_BYTES, 15);
+ attributes.put(Broker.FLOW_CONTROL_RESUME_SIZE_BYTES, 13);
+ attributes.put(Broker.MAXIMUM_DELIVERY_ATTEMPTS, 12);
+ attributes.put(Broker.DEAD_LETTER_QUEUE_ENABLED, false);
+ attributes.put(Broker.HOUSEKEEPING_CHECK_PERIOD, 11);
+ attributes.put(Broker.ACL_FILE, "/path/to/acl1");
+ attributes.put(Broker.SESSION_COUNT_LIMIT, 11000);
+ attributes.put(Broker.HEART_BEAT_DELAY, 12000);
+ attributes.put(Broker.STATISTICS_REPORTING_PERIOD, 14000);
+ attributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, false);
+ ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(_brokerId, Broker.class.getSimpleName(), attributes,
+ brokerConfigEntry.getChildrenIds(), _store);
+
+ _store.save(updatedBrokerEntry);
+
+ ConfigurationEntry newBrokerConfigEntry = _store.getRootEntry();
+ assertNotNull("Root entry does not exist", newBrokerConfigEntry);
+ assertEquals("Unexpected id", _brokerId, newBrokerConfigEntry.getId());
+ assertEquals("Unexpected type ", Broker.class.getSimpleName(), newBrokerConfigEntry.getType());
+ Map<String, Object> newBrokerattributes = newBrokerConfigEntry.getAttributes();
+ assertNotNull("Attributes cannot be null", newBrokerattributes);
+ assertEquals("Unexpected attributes", attributes, newBrokerattributes);
+ }
+
+ public void testSaveNewVirtualHost()
+ {
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put(VirtualHost.NAME, "test1");
+ virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+ UUID virtualHostId = UUID.randomUUID();
+ ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+ Collections.<UUID> emptySet(), _store);
+
+ _store.save(hostEntry);
+
+ ConfigurationEntry configurationEntry = _store.getEntry(virtualHostId);
+ assertEquals("Unexpected virtual host configuration", hostEntry, configurationEntry);
+ assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), configurationEntry.getType());
+ assertEquals("Unexpected virtual host attributes", hostEntry.getAttributes(), configurationEntry.getAttributes());
+ assertTrue("Unexpected virtual host children found", hostEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveExistingVirtualHost()
+ {
+ ConfigurationEntry hostEntry = _store.getEntry(_virtualHostId);
+ assertNotNull("Host configuration is not found", hostEntry);
+
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put(VirtualHost.NAME, "test");
+ virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/new/phantom/test/configuration");
+
+ ConfigurationEntry updatedEntry = new ConfigurationEntry(_virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+ hostEntry.getChildrenIds(), _store);
+ _store.save(updatedEntry);
+
+ ConfigurationEntry newHostEntry = _store.getEntry(_virtualHostId);
+ assertEquals("Unexpected virtual host configuration", updatedEntry, newHostEntry);
+ assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), newHostEntry.getType());
+ assertEquals("Unexpected virtual host attributes", updatedEntry.getAttributes(), newHostEntry.getAttributes());
+ assertEquals("Unexpected virtual host children found", updatedEntry.getChildrenIds(), newHostEntry.getChildrenIds());
+ }
+
+ public void testSaveNewAuthenticationProvider()
+ {
+ UUID authenticationProviderId = UUID.randomUUID();
+ Map<String, Object> authenticationProviderAttributes = new HashMap<String, Object>();
+ authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+ authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManager.class.getSimpleName());
+ ConfigurationEntry providerEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getSimpleName(),
+ authenticationProviderAttributes, Collections.<UUID> emptySet(), _store);
+
+ _store.save(providerEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(authenticationProviderId);
+ assertEquals("Unexpected provider configuration", providerEntry, storeEntry);
+ assertEquals("Unexpected type", AuthenticationProvider.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected provider attributes", providerEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveExistingAuthenticationProvider()
+ {
+ ConfigurationEntry providerEntry = _store.getEntry(_authenticationProviderId);
+ assertNotNull("provider configuration is not found", providerEntry);
+
+ Map<String, Object> authenticationProviderAttributes = new HashMap<String, Object>();
+ authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
+ authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManager.class.getSimpleName());
+ ConfigurationEntry updatedEntry = new ConfigurationEntry(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(),
+ authenticationProviderAttributes, Collections.<UUID> emptySet(), _store);
+ _store.save(updatedEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(_authenticationProviderId);
+ assertEquals("Unexpected provider configuration", updatedEntry, storeEntry);
+ assertEquals("Unexpected type", AuthenticationProvider.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected provider attributes", updatedEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveTrustStore()
+ {
+ UUID trustStoreId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(TrustStore.NAME, getName());
+ attributes.put(TrustStore.PATH, "/path/to/truststore");
+ attributes.put(TrustStore.PASSWORD, "my-secret-password");
+ attributes.put(TrustStore.TYPE, "NON-JKS");
+ attributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(TrustStore.DESCRIPTION, "Description");
+
+ ConfigurationEntry trustStoreEntry = new ConfigurationEntry(trustStoreId, TrustStore.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), _store);
+
+ _store.save(trustStoreEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(trustStoreId);
+ assertEquals("Unexpected trust store configuration", trustStoreEntry, storeEntry);
+ assertEquals("Unexpected type", TrustStore.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected provider attributes", trustStoreEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveKeyStore()
+ {
+ UUID keyStoreId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(KeyStore.NAME, getName());
+ attributes.put(KeyStore.PATH, "/path/to/truststore");
+ attributes.put(KeyStore.PASSWORD, "my-secret-password");
+ attributes.put(KeyStore.TYPE, "NON-JKS");
+ attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(KeyStore.DESCRIPTION, "Description");
+ attributes.put(KeyStore.CERTIFICATE_ALIAS, "Alias");
+
+ ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getSimpleName(), attributes, Collections.<UUID> emptySet(),
+ _store);
+
+ _store.save(keyStoreEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(keyStoreId);
+ assertEquals("Unexpected key store configuration", keyStoreEntry, storeEntry);
+ assertEquals("Unexpected type", KeyStore.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected provider attributes", keyStoreEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSaveGroupProvider()
+ {
+ UUID groupProviderId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(GroupProvider.NAME, getName());
+
+ ConfigurationEntry groupProviderEntry = new ConfigurationEntry(groupProviderId, GroupProvider.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), _store);
+
+ _store.save(groupProviderEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(groupProviderId);
+ assertEquals("Unexpected group provider configuration", groupProviderEntry, storeEntry);
+ assertEquals("Unexpected type", GroupProvider.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected group provider attributes", groupProviderEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testSavePort()
+ {
+ UUID portId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ Set<String> tcpTransportSet = Collections.singleton(Transport.TCP.name());
+ attributes.put(Port.PORT, 9999);
+ attributes.put(Port.TRANSPORTS, tcpTransportSet);
+ attributes.put(Port.TCP_NO_DELAY, true);
+ attributes.put(Port.RECEIVE_BUFFER_SIZE, 1);
+ attributes.put(Port.SEND_BUFFER_SIZE, 2);
+ attributes.put(Port.NEED_CLIENT_AUTH, true);
+ attributes.put(Port.WANT_CLIENT_AUTH, true);
+
+ ConfigurationEntry portEntry = new ConfigurationEntry(portId, Port.class.getSimpleName(), attributes, Collections.<UUID> emptySet(), _store);
+
+ _store.save(portEntry);
+
+ ConfigurationEntry storeEntry = _store.getEntry(portId);
+ assertEquals("Unexpected port configuration", portEntry, storeEntry);
+ assertEquals("Unexpected type", Port.class.getSimpleName(), storeEntry.getType());
+ assertEquals("Unexpected port attributes", portEntry.getAttributes(), storeEntry.getAttributes());
+ assertTrue("Unexpected port children found", storeEntry.getChildrenIds().isEmpty());
+ }
+
+ public void testMultipleSave()
+ {
+ UUID virtualHostId = UUID.randomUUID();
+ Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+ virtualHostAttributes.put(VirtualHost.NAME, "test1");
+ virtualHostAttributes.put(VirtualHost.CONFIG_PATH, "/path/to/phantom/virtualhost/config1");
+ ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
+ Collections.<UUID> emptySet(), _store);
+
+ UUID keyStoreId = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(KeyStore.NAME, getName());
+ attributes.put(KeyStore.PATH, "/path/to/truststore");
+ attributes.put(KeyStore.PASSWORD, "my-secret-password");
+ attributes.put(KeyStore.TYPE, "NON-JKS");
+ attributes.put(KeyStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
+ attributes.put(KeyStore.DESCRIPTION, "Description");
+ attributes.put(KeyStore.CERTIFICATE_ALIAS, "Alias");
+
+ ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getSimpleName(), attributes, Collections.<UUID> emptySet(),
+ _store);
+
+ _store.save(hostEntry, keyStoreEntry);
+
+ assertNotNull("Virtual host is not found", _store.getEntry(virtualHostId));
+ assertNotNull("Key store is not found", _store.getEntry(keyStoreId));
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
new file mode 100644
index 0000000000..7c9f4889f8
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
@@ -0,0 +1,216 @@
+package org.apache.qpid.server.configuration.store;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTestCase
+{
+ private File _storeFile;
+ private ObjectMapper _objectMapper;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ _objectMapper = new ObjectMapper();
+ _objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ _storeFile.delete();
+ super.tearDown();
+ }
+
+ @Override
+ protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception
+ {
+ _storeFile = createStoreFile(brokerId, brokerAttributes);
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(_storeFile.getAbsolutePath());
+ return store;
+ }
+
+ private File createStoreFile(UUID brokerId, Map<String, Object> brokerAttributes) throws IOException,
+ JsonGenerationException, JsonMappingException
+ {
+ Map<String, Object> brokerObjectMap = new HashMap<String, Object>();
+ brokerObjectMap.put(Broker.ID, brokerId);
+ brokerObjectMap.put("@type", Broker.class.getSimpleName());
+ brokerObjectMap.putAll(brokerAttributes);
+
+ StringWriter sw = new StringWriter();
+ _objectMapper.writeValue(sw, brokerObjectMap);
+
+ String brokerJson = sw.toString();
+
+ return TestFileUtils.createTempFile(this, ".json", brokerJson);
+ }
+
+ @Override
+ protected void addConfiguration(UUID id, String type, Map<String, Object> attributes)
+ {
+ ConfigurationEntryStore store = getStore();
+ store.save(new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store));
+ }
+
+ public void testAttributeIsResolvedFromSystemProperties()
+ {
+ String aclLocation = "path/to/acl/" + getTestName();
+ setTestSystemProperty("my.test.property", aclLocation);
+
+ ConfigurationEntryStore store = getStore();
+ ConfigurationEntry brokerConfigEntry = store.getRootEntry();
+ Map<String, Object> attributes = new HashMap<String, Object>(brokerConfigEntry.getAttributes());
+ attributes.put(Broker.ACL_FILE, "${my.test.property}");
+ ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(brokerConfigEntry.getId(), Broker.class.getSimpleName(),
+ attributes, brokerConfigEntry.getChildrenIds(), store);
+ store.save(updatedBrokerEntry);
+
+ JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore();
+ store2.open(_storeFile.getAbsolutePath());
+
+ assertEquals("Unresolved ACL value", aclLocation, store2.getRootEntry().getAttributes().get(Broker.ACL_FILE));
+ }
+
+ public void testOpenEmpty()
+ {
+ File file = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(file.getAbsolutePath());
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ store.copyTo(file.getAbsolutePath());
+
+ JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore();
+ store2.open(file.getAbsolutePath());
+ ConfigurationEntry root2 = store.getRootEntry();
+ assertEquals("Unexpected root entry", root.getId(), root2.getId());
+ }
+
+ public void testOpenNotEmpty() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File file = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(file.getAbsolutePath());
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryEmpty()
+ {
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ }
+
+ public void testOpenWithInitialStoreLocation() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ File storeFile = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(storeFile.getAbsolutePath(), initialStoreFile.getAbsolutePath());
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryWithInitialStoreLocation() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY, initialStoreFile.getAbsolutePath());
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenWithInitialStore() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore();
+ initialStore.open(initialStoreFile.getAbsolutePath());
+
+ File storeFile = TestFileUtils.createTempFile(this, ".json");
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(storeFile.getAbsolutePath(), initialStore);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+
+ public void testOpenInMemoryWithInitialStore() throws Exception
+ {
+ UUID brokerId = UUID.randomUUID();
+ Map<String, Object> brokerAttributes = new HashMap<String, Object>();
+ brokerAttributes.put(Broker.NAME, getTestName());
+ File initialStoreFile = createStoreFile(brokerId, brokerAttributes);
+
+ JsonConfigurationEntryStore initialStore = new JsonConfigurationEntryStore();
+ initialStore.open(initialStoreFile.getAbsolutePath());
+
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore();
+ store.open(JsonConfigurationEntryStore.IN_MEMORY, initialStore);
+
+ ConfigurationEntry root = store.getRootEntry();
+ assertNotNull("Root entry is not found", root);
+ assertEquals("Unexpected root entry", brokerId, root.getId());
+ Map<String, Object> attributes = root.getAttributes();
+ assertNotNull("Attributes not found", attributes);
+ assertEquals("Unexpected number of attriburtes", 1, attributes.size());
+ assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME));
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
new file mode 100644
index 0000000000..a67daac610
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
@@ -0,0 +1,341 @@
+package org.apache.qpid.server.configuration.store;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.any;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator;
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class ManagementModeStoreHandlerTest extends QpidTestCase
+{
+ private ManagementModeStoreHandler _handler;
+ private BrokerOptions _options;
+ private ConfigurationEntryStore _store;
+ private ConfigurationEntry _root;
+ private ConfigurationEntry _portEntry;
+ private UUID _rootId, _portEntryId;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _rootId = UUID.randomUUID();
+ _portEntryId = UUID.randomUUID();
+ _store = mock(ConfigurationEntryStore.class);
+ _root = mock(ConfigurationEntry.class);
+ _portEntry = mock(ConfigurationEntry.class);
+ when(_store.getRootEntry()).thenReturn(_root);
+ when(_root.getId()).thenReturn(_rootId);
+ when(_portEntry.getId()).thenReturn(_portEntryId);
+ when(_store.getEntry(_portEntryId)).thenReturn(_portEntry);
+ when(_store.getEntry(_rootId)).thenReturn(_root);
+ when(_root.getChildrenIds()).thenReturn(Collections.singleton(_portEntryId));
+ when(_portEntry.getType()).thenReturn(Port.class.getSimpleName());
+ _options = new BrokerOptions();
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ }
+
+ public void testOpenString()
+ {
+ try
+ {
+ _handler.open(TMP_FOLDER + File.separator + getTestName());
+ fail("Exception should be thrown on attempt to call open method on a handler");
+ }
+ catch (IllegalStateException e)
+ {
+ // pass
+ }
+ }
+
+ public void testOpenStringString()
+ {
+ try
+ {
+ _handler.open(TMP_FOLDER + File.separator + getTestName(),
+ BrokerConfigurationStoreCreator.DEFAULT_INITIAL_STORE_LOCATION);
+ fail("Exception should be thrown on attempt to call open method on a handler");
+ }
+ catch (IllegalStateException e)
+ {
+ // pass
+ }
+ }
+
+ public void testOpenStringConfigurationEntryStore()
+ {
+ try
+ {
+ _handler.open(TMP_FOLDER + File.separator + getTestName(), _store);
+ fail("Exception should be thrown on attempt to call open method on a handler");
+ }
+ catch (IllegalStateException e)
+ {
+ // pass
+ }
+ }
+
+ public void testGetRootEntryWithEmptyOptions()
+ {
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ assertEquals("Unexpected children", Collections.singleton(_portEntryId), root.getChildrenIds());
+ }
+
+ public void testGetRootEntryWithHttpPortOverriden()
+ {
+ _options.setManagementModeHttpPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+ assertEquals("Unexpected children size", 2, childrenIds.size());
+ assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
+ }
+
+ public void testGetRootEntryWithRmiPortOverriden()
+ {
+ _options.setManagementModeRmiPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+ assertEquals("Unexpected children size", 3, childrenIds.size());
+ assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
+ }
+
+ public void testGetRootEntryWithConnectorPortOverriden()
+ {
+ _options.setManagementModeConnectorPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+ assertEquals("Unexpected children size", 2, childrenIds.size());
+ assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
+ }
+
+ public void testGetRootEntryWithManagementPortsOverriden()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _options.setManagementModeRmiPort(2000);
+ _options.setManagementModeConnectorPort(3000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+ assertEquals("Unexpected children size", 4, childrenIds.size());
+ assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
+ }
+
+ public void testGetEntryByRootId()
+ {
+ ConfigurationEntry root = _handler.getEntry(_rootId);
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ assertEquals("Unexpected children", Collections.singleton(_portEntryId), root.getChildrenIds());
+ }
+
+ public void testGetEntryByPortId()
+ {
+ ConfigurationEntry portEntry = _handler.getEntry(_portEntryId);
+ assertEquals("Unexpected entry id", _portEntryId, portEntry.getId());
+ assertTrue("Unexpected children", portEntry.getChildrenIds().isEmpty());
+ assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
+ }
+
+ public void testGetEntryByCLIConnectorPortId()
+ {
+ _options.setManagementModeConnectorPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ UUID optionsPort = getOptionsPortId();
+ ConfigurationEntry portEntry = _handler.getEntry(optionsPort);
+ assertCLIPortEntry(portEntry, optionsPort, Protocol.JMX_RMI);
+ }
+
+ public void testGetEntryByCLIHttpPortId()
+ {
+ _options.setManagementModeHttpPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ UUID optionsPort = getOptionsPortId();
+ ConfigurationEntry portEntry = _handler.getEntry(optionsPort);
+ assertCLIPortEntry(portEntry, optionsPort, Protocol.HTTP);
+ }
+
+ public void testHttpPortEntryIsQuiesced()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTP));
+ when(_portEntry.getAttributes()).thenReturn(attributes);
+ _options.setManagementModeHttpPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry portEntry = _handler.getEntry(_portEntryId);
+ assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
+ }
+
+ public void testRmiPortEntryIsQuiesced()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.RMI));
+ when(_portEntry.getAttributes()).thenReturn(attributes);
+ _options.setManagementModeRmiPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry portEntry = _handler.getEntry(_portEntryId);
+ assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
+ }
+
+ public void testConnectorPortEntryIsQuiesced()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.JMX_RMI));
+ when(_portEntry.getAttributes()).thenReturn(attributes);
+ _options.setManagementModeRmiPort(9090);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry portEntry = _handler.getEntry(_portEntryId);
+ assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
+ }
+
+ public void testVirtualHostEntryIsQuiesced()
+ {
+ UUID virtualHostId = UUID.randomUUID();
+ ConfigurationEntry virtualHost = mock(ConfigurationEntry.class);
+ when(virtualHost.getId()).thenReturn(virtualHostId);
+ when(virtualHost.getType()).thenReturn(VirtualHost.class.getSimpleName());
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.CONFIG_PATH, "/path/to/host.xml");
+ when(virtualHost.getAttributes()).thenReturn(attributes);
+ when(_store.getEntry(virtualHostId)).thenReturn(virtualHost);
+ when(_root.getChildrenIds()).thenReturn(new HashSet<UUID>(Arrays.asList(_portEntryId, virtualHostId)));
+
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry hostEntry = _handler.getEntry(virtualHostId);
+ Map<String, Object> hostAttributes = hostEntry.getAttributes();
+ assertEquals("Unexpected state", State.QUIESCED, hostAttributes.get(VirtualHost.STATE));
+ hostAttributes.remove(VirtualHost.STATE);
+ assertEquals("Unexpected attributes", attributes, hostAttributes);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void assertCLIPortEntry(ConfigurationEntry portEntry, UUID optionsPort, Protocol protocol)
+ {
+ assertEquals("Unexpected entry id", optionsPort, portEntry.getId());
+ assertTrue("Unexpected children", portEntry.getChildrenIds().isEmpty());
+ Map<String, Object> attributes = portEntry.getAttributes();
+ assertEquals("Unexpected name", "MANAGEMENT-MODE-PORT-" + protocol.name(), attributes.get(Port.NAME));
+ assertEquals("Unexpected protocol", Collections.singleton(protocol), new HashSet<Protocol>(
+ (Collection<Protocol>) attributes.get(Port.PROTOCOLS)));
+ }
+
+ public void testSavePort()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _options.setManagementModeRmiPort(2000);
+ _options.setManagementModeConnectorPort(3000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.NAME, "TEST");
+ ConfigurationEntry configurationEntry = new ConfigurationEntry(_portEntryId, Port.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), null);
+ _handler.save(configurationEntry);
+ verify(_store).save(any(ConfigurationEntry.class));
+ }
+
+ public void testSaveRoot()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _options.setManagementModeRmiPort(2000);
+ _options.setManagementModeConnectorPort(3000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ ConfigurationEntry root = _handler.getRootEntry();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Broker.NAME, "TEST");
+ ConfigurationEntry configurationEntry = new ConfigurationEntry(_rootId, Broker.class.getSimpleName(), attributes,
+ root.getChildrenIds(), null);
+ _handler.save(configurationEntry);
+ verify(_store).save(any(ConfigurationEntry.class));
+ }
+
+ public void testSaveCLIHttpPort()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ UUID portId = getOptionsPortId();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.NAME, "TEST");
+ ConfigurationEntry configurationEntry = new ConfigurationEntry(portId, Port.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), null);
+ try
+ {
+ _handler.save(configurationEntry);
+ fail("Exception should be thrown on trying to save CLI port");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+ public void testRemove()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+
+ _handler.remove(_portEntryId);
+ verify(_store).remove(_portEntryId);
+ }
+
+ public void testRemoveCLIPort()
+ {
+ _options.setManagementModeHttpPort(1000);
+ _handler = new ManagementModeStoreHandler(_store, _options);
+ UUID portId = getOptionsPortId();
+ try
+ {
+ _handler.remove(portId);
+ fail("Exception should be thrown on trying to remove CLI port");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+ private UUID getOptionsPortId()
+ {
+ ConfigurationEntry root = _handler.getRootEntry();
+ assertEquals("Unexpected root id", _rootId, root.getId());
+ Collection<UUID> childrenIds = root.getChildrenIds();
+
+ childrenIds.remove(_portEntryId);
+ UUID optionsPort = childrenIds.iterator().next();
+ return optionsPort;
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
new file mode 100644
index 0000000000..a77a0e9fcc
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
@@ -0,0 +1,83 @@
+package org.apache.qpid.server.configuration.store;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.when;
+
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class StoreConfigurationChangeListenerTest extends QpidTestCase
+{
+ private ConfigurationEntryStore _store;
+ private StoreConfigurationChangeListener _listener;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _store = mock(ConfigurationEntryStore.class);
+ _listener = new StoreConfigurationChangeListener(_store);
+ }
+
+ public void testStateChanged()
+ {
+ notifyBrokerStarted();
+ UUID id = UUID.randomUUID();
+ ConfiguredObject object = mock(VirtualHost.class);
+ when(object.getId()).thenReturn(id);
+ _listener.stateChanged(object, State.ACTIVE, State.DELETED);
+ verify(_store).remove(id);
+ }
+
+ public void testChildAdded()
+ {
+ notifyBrokerStarted();
+ Broker broker = mock(Broker.class);
+ VirtualHost child = mock(VirtualHost.class);
+ _listener.childAdded(broker, child);
+ verify(_store).save(any(ConfigurationEntry.class), any(ConfigurationEntry.class));
+ }
+
+ public void testChildRemoved()
+ {
+ notifyBrokerStarted();
+ Broker broker = mock(Broker.class);
+ VirtualHost child = mock(VirtualHost.class);
+ _listener.childRemoved(broker, child);
+ verify(_store).save(any(ConfigurationEntry.class));
+ }
+
+ public void testAttributeSet()
+ {
+ notifyBrokerStarted();
+ Broker broker = mock(Broker.class);
+ _listener.attributeSet(broker, Broker.FLOW_CONTROL_SIZE_BYTES, null, 1);
+ verify(_store).save(any(ConfigurationEntry.class));
+ }
+
+ public void testChildAddedForVirtualHost()
+ {
+ notifyBrokerStarted();
+
+ VirtualHost object = mock(VirtualHost.class);
+ Queue queue = mock(Queue.class);
+ _listener.childAdded(object, queue);
+ verifyNoMoreInteractions(_store);
+ }
+
+ private void notifyBrokerStarted()
+ {
+ Broker broker = mock(Broker.class);
+ _listener.stateChanged(broker, State.INITIALISING, State.ACTIVE);
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java b/java/broker/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
new file mode 100644
index 0000000000..cd6302d55b
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
@@ -0,0 +1,296 @@
+/*
+ *
+ * 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.configuration.updater;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.security.auth.Subject;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.logging.LogActor;
+import org.apache.qpid.server.logging.NullRootMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.security.SecurityManager;
+
+public class TaskExecutorTest extends TestCase
+{
+ private TaskExecutor _executor;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _executor = new TaskExecutor();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ _executor.stopImmediately();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ public void testGetState()
+ {
+ assertEquals("Unxpected initial state", State.INITIALISING, _executor.getState());
+ }
+
+ public void testStart()
+ {
+ _executor.start();
+ assertEquals("Unxpected started state", State.ACTIVE, _executor.getState());
+ }
+
+ public void testStopImmediately() throws Exception
+ {
+ _executor.start();
+ final CountDownLatch submitLatch = new CountDownLatch(2);
+ final CountDownLatch waitForCallLatch = new CountDownLatch(1);
+ final BlockingQueue<Exception> submitExceptions = new LinkedBlockingQueue<Exception>();
+
+ Runnable runnable = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ Future<?> f = _executor.submit(new NeverEndingCallable(waitForCallLatch));
+ submitLatch.countDown();
+ f.get();
+ }
+ catch (Exception e)
+ {
+ if (e instanceof ExecutionException)
+ {
+ e = (Exception) e.getCause();
+ }
+ submitExceptions.add(e);
+ }
+ }
+ };
+ new Thread(runnable).start();
+ new Thread(runnable).start();
+ assertTrue("Tasks have not been submitted", submitLatch.await(1000, TimeUnit.MILLISECONDS));
+ assertTrue("The first task has not been triggered", waitForCallLatch.await(1000, TimeUnit.MILLISECONDS));
+
+ _executor.stopImmediately();
+ assertEquals("Unxpected stopped state", State.STOPPED, _executor.getState());
+
+ Exception e = submitExceptions.poll(1000l, TimeUnit.MILLISECONDS);
+ assertNotNull("The task execution was not interrupted or cancelled", e);
+ Exception e2 = submitExceptions.poll(1000l, TimeUnit.MILLISECONDS);
+ assertNotNull("The task execution was not interrupted or cancelled", e2);
+
+ assertTrue("One of the exceptions should be CancellationException:", e2 instanceof CancellationException
+ || e instanceof CancellationException);
+ assertTrue("One of the exceptions should be InterruptedException:", e2 instanceof InterruptedException
+ || e instanceof InterruptedException);
+ }
+
+ public void testStop()
+ {
+ _executor.start();
+ _executor.stop();
+ assertEquals("Unxpected stopped state", State.STOPPED, _executor.getState());
+ }
+
+ public void testSubmitAndWait() throws Exception
+ {
+ _executor.start();
+ Object result = _executor.submitAndWait(new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ return "DONE";
+ }
+ });
+ assertEquals("Unexpected task execution result", "DONE", result);
+ }
+
+ public void testSubmitAndWaitInNotAuthorizedContext()
+ {
+ _executor.start();
+ Object subject = _executor.submitAndWait(new SubjectRetriever());
+ assertNull("Subject must be null", subject);
+ }
+
+ public void testSubmitAndWaitInAuthorizedContext()
+ {
+ _executor.start();
+ Subject subject = new Subject();
+ Object result = Subject.doAs(subject, new PrivilegedAction<Object>()
+ {
+ @Override
+ public Object run()
+ {
+ return _executor.submitAndWait(new SubjectRetriever());
+ }
+ });
+ assertEquals("Unexpected subject", subject, result);
+ }
+
+ public void testSubmitAndWaitInAuthorizedContextWithNullSubject()
+ {
+ _executor.start();
+ Object result = Subject.doAs(null, new PrivilegedAction<Object>()
+ {
+ @Override
+ public Object run()
+ {
+ return _executor.submitAndWait(new SubjectRetriever());
+ }
+ });
+ assertEquals("Unexpected subject", null, result);
+ }
+
+ public void testSubmitAndWaitReThrowsOriginalRuntimeException()
+ {
+ final RuntimeException exception = new RuntimeException();
+ _executor.start();
+ try
+ {
+ _executor.submitAndWait(new Callable<Void>()
+ {
+
+ @Override
+ public Void call() throws Exception
+ {
+ throw exception;
+ }
+ });
+ fail("Exception is expected");
+ }
+ catch (Exception e)
+ {
+ assertEquals("Unexpected exception", exception, e);
+ }
+ }
+
+ public void testSubmitAndWaitPassesOriginalCheckedException()
+ {
+ final Exception exception = new Exception();
+ _executor.start();
+ try
+ {
+ _executor.submitAndWait(new Callable<Void>()
+ {
+
+ @Override
+ public Void call() throws Exception
+ {
+ throw exception;
+ }
+ });
+ fail("Exception is expected");
+ }
+ catch (Exception e)
+ {
+ assertEquals("Unexpected exception", exception, e.getCause());
+ }
+ }
+
+ public void testSubmitAndWaitCurrentActorAndSecurityManagerSubjectAreRespected() throws Exception
+ {
+ _executor.start();
+ LogActor actor = new TestLogActor(new NullRootMessageLogger());
+ Subject subject = new Subject();
+ Subject currentSecurityManagerSubject = SecurityManager.getThreadSubject();
+ final AtomicReference<LogActor> taskLogActor = new AtomicReference<LogActor>();
+ final AtomicReference<Subject> taskSubject = new AtomicReference<Subject>();
+ try
+ {
+ CurrentActor.set(actor);
+ SecurityManager.setThreadSubject(subject);
+ _executor.submitAndWait(new Callable<Void>()
+ {
+ @Override
+ public Void call() throws Exception
+ {
+ taskLogActor.set(CurrentActor.get());
+ taskSubject.set(SecurityManager.getThreadSubject());
+ return null;
+ }
+ });
+ }
+ finally
+ {
+ SecurityManager.setThreadSubject(currentSecurityManagerSubject);
+ CurrentActor.remove();
+ }
+ assertEquals("Unexpected task log actor", actor, taskLogActor.get());
+ assertEquals("Unexpected security manager subject", subject, taskSubject.get());
+ }
+
+ private class SubjectRetriever implements Callable<Subject>
+ {
+ @Override
+ public Subject call() throws Exception
+ {
+ return Subject.getSubject(AccessController.getContext());
+ }
+ }
+
+ private class NeverEndingCallable implements Callable<Void>
+ {
+ private CountDownLatch _waitLatch;
+
+ public NeverEndingCallable(CountDownLatch waitLatch)
+ {
+ super();
+ _waitLatch = waitLatch;
+ }
+
+ @Override
+ public Void call() throws Exception
+ {
+ if (_waitLatch != null)
+ {
+ _waitLatch.countDown();
+ }
+
+ // wait forever
+ synchronized (this)
+ {
+ this.wait();
+ }
+ return null;
+ }
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java b/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java
index 4befd26ece..0bb698a46c 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java
@@ -29,7 +29,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.log4j.Logger;
@@ -54,25 +53,56 @@ import org.apache.qpid.server.queue.IncomingMessage;
import org.apache.qpid.server.queue.MockStoredMessage;
import org.apache.qpid.server.queue.QueueEntry;
import org.apache.qpid.server.queue.SimpleAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.server.subscription.Subscription;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase
+public class AbstractHeadersExchangeTestBase extends QpidTestCase
{
private static final Logger _log = Logger.getLogger(AbstractHeadersExchangeTestBase.class);
private final HeadersExchange exchange = new HeadersExchange();
- protected final Set<TestQueue> queues = new HashSet<TestQueue>();
-
+ private final Set<TestQueue> queues = new HashSet<TestQueue>();
+ private VirtualHost _virtualHost;
private int count;
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _virtualHost = BrokerTestHelper.createVirtualHost(getClass().getName());
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
public void testDoNothing()
{
// this is here only to make junit under Eclipse happy
}
+ public VirtualHost getVirtualHost()
+ {
+ return _virtualHost;
+ }
+
protected TestQueue bindDefault(String... bindings) throws AMQException
{
String queueName = "Queue" + (++count);
@@ -83,7 +113,7 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase
protected void unbind(TestQueue queue, String... bindings) throws AMQException
{
String queueName = queue.getName();
- exchange.onUnbind(new Binding(null, null, queueName, queue, exchange, getHeadersMap(bindings)));
+ exchange.onUnbind(new Binding(null, queueName, queue, exchange, getHeadersMap(bindings)));
}
protected int getCount()
@@ -93,9 +123,9 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase
private TestQueue bind(String key, String queueName, Map<String,Object> args) throws AMQException
{
- TestQueue queue = new TestQueue(new AMQShortString(queueName));
+ TestQueue queue = new TestQueue(new AMQShortString(queueName), _virtualHost);
queues.add(queue);
- exchange.onBind(new Binding(null, null, key, queue, exchange, args));
+ exchange.onBind(new Binding(null, key, queue, exchange, args));
return queue;
}
@@ -274,10 +304,10 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase
return getNameShortString().toString();
}
- public TestQueue(AMQShortString name) throws AMQException
+ public TestQueue(AMQShortString name, VirtualHost host) throws AMQException
{
- super(UUIDGenerator.generateRandomUUID(), name, false, new AMQShortString("test"), true, false,ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test"), Collections.EMPTY_MAP);
- ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test").getQueueRegistry().registerQueue(this);
+ super(UUIDGenerator.generateRandomUUID(), name, false, new AMQShortString("test"), true, false, host, Collections.EMPTY_MAP);
+ host.getQueueRegistry().registerQueue(this);
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java
new file mode 100644
index 0000000000..341ab1b372
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/exchange/DefaultExchangeFactoryTest.java
@@ -0,0 +1,226 @@
+/*
+ *
+ * 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.exchange;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.plugin.ExchangeType;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+@SuppressWarnings("rawtypes")
+public class DefaultExchangeFactoryTest extends QpidTestCase
+{
+ private DirectExchangeType _directExchangeType;
+ private TopicExchangeType _topicExchangeType;
+ private FanoutExchangeType _fanoutExchangeType;
+ private HeadersExchangeType _headersExchangeType;
+
+ private List<ExchangeType> _stubbedExchangeTypes;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ _directExchangeType = new DirectExchangeType();
+ _topicExchangeType = new TopicExchangeType();
+ _fanoutExchangeType = new FanoutExchangeType();
+ _headersExchangeType = new HeadersExchangeType();
+ _stubbedExchangeTypes = new ArrayList<ExchangeType>();
+ }
+
+ public void testCreateDefaultExchangeFactory()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ DefaultExchangeFactory factory = new TestExchangeFactory();
+
+ Collection<ExchangeType<? extends Exchange>> registeredTypes = factory.getRegisteredTypes();
+ assertEquals("Unexpected number of exchange types", _stubbedExchangeTypes.size(), registeredTypes.size());
+ assertTrue("Direct exchange type is not found", registeredTypes.contains(_directExchangeType));
+ assertTrue("Fanout exchange type is not found", registeredTypes.contains(_fanoutExchangeType));
+ assertTrue("Topic exchange type is not found", registeredTypes.contains(_topicExchangeType));
+ assertTrue("Headers exchange type is not found", registeredTypes.contains(_headersExchangeType));
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutAllBaseExchangeTypes()
+ {
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ // pass
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutDireactExchangeType()
+ {
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _directExchangeType.getName(), e.getMessage());
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutTopicExchangeType()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _topicExchangeType.getName(), e.getMessage());
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutFanoutExchangeType()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _fanoutExchangeType.getName(), e.getMessage());
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithoutHeadersExchangeType()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory without all base classes");
+ }
+ catch (IllegalStateException e)
+ {
+ assertEquals("Unexpected exception message", "Did not find expected exchange type: " + _headersExchangeType.getName(), e.getMessage());
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithDuplicateExchangeTypeName()
+ {
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_directExchangeType);
+
+ try
+ {
+ new TestExchangeFactory();
+ fail("Cannot create factory with duplicate exchange type names");
+ }
+ catch (IllegalStateException e)
+ {
+ assertTrue( "Unexpected exception message", e.getMessage().contains("ExchangeType with type name '"
+ + _directExchangeType.getName() + "' is already registered using class '"
+ + DirectExchangeType.class.getName()));
+ }
+ }
+
+ public void testCreateDefaultExchangeFactoryWithCustomExchangeType()
+ {
+ ExchangeType<?> customeExchangeType = new ExchangeType<Exchange>()
+ {
+ @Override
+ public AMQShortString getName()
+ {
+ return new AMQShortString("my-custom-exchange");
+ }
+
+ @Override
+ public Exchange newInstance(UUID id, VirtualHost host, AMQShortString name, boolean durable, int ticket,
+ boolean autoDelete) throws AMQException
+ {
+ return null;
+ }
+
+ @Override
+ public AMQShortString getDefaultExchangeName()
+ {
+ return null;
+ }
+ };
+
+ _stubbedExchangeTypes.add(customeExchangeType);
+ _stubbedExchangeTypes.add(_directExchangeType);
+ _stubbedExchangeTypes.add(_topicExchangeType);
+ _stubbedExchangeTypes.add(_fanoutExchangeType);
+ _stubbedExchangeTypes.add(_headersExchangeType);
+
+ DefaultExchangeFactory factory = new TestExchangeFactory();
+
+ Collection<ExchangeType<? extends Exchange>> registeredTypes = factory.getRegisteredTypes();
+ assertEquals("Unexpected number of exchange types", _stubbedExchangeTypes.size(), registeredTypes.size());
+ assertTrue("Direct exchange type is not found", registeredTypes.contains(_directExchangeType));
+ assertTrue("Fanout exchange type is not found", registeredTypes.contains(_fanoutExchangeType));
+ assertTrue("Topic exchange type is not found", registeredTypes.contains(_topicExchangeType));
+ assertTrue("Headers exchange type is not found", registeredTypes.contains(_headersExchangeType));
+ assertTrue("Custom exchange type is not found", registeredTypes.contains(customeExchangeType));
+ }
+
+ private final class TestExchangeFactory extends DefaultExchangeFactory
+ {
+ private TestExchangeFactory()
+ {
+ super(null);
+ }
+
+ @Override
+ protected Iterable<ExchangeType> loadExchangeTypes()
+ {
+ return _stubbedExchangeTypes;
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersBindingTest.java b/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersBindingTest.java
index 3988edcb3c..833df34fd8 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersBindingTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersBindingTest.java
@@ -160,7 +160,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Value of A");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -171,7 +171,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Value of A");
matchHeaders.setString("B", "Value of B");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -181,7 +181,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Altered value of A");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertFalse(new HeadersBinding(b).matches(matchHeaders));
}
@@ -192,7 +192,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Value of A");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -204,7 +204,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Value of A");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertFalse(new HeadersBinding(b).matches(matchHeaders));
}
@@ -217,7 +217,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Value of A");
matchHeaders.setString("B", "Value of B");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -231,7 +231,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("B", "Value of B");
matchHeaders.setString("C", "Value of C");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -245,7 +245,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("B", "Altered value of B");
matchHeaders.setString("C", "Value of C");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertFalse(new HeadersBinding(b).matches(matchHeaders));
}
@@ -256,7 +256,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Value of A");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -268,7 +268,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Value of A");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -281,7 +281,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("A", "Value of A");
matchHeaders.setString("B", "Value of B");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -295,7 +295,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("B", "Value of B");
matchHeaders.setString("C", "Value of C");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -309,7 +309,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("B", "Altered value of B");
matchHeaders.setString("C", "Value of C");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertTrue(new HeadersBinding(b).matches(matchHeaders));
}
@@ -323,7 +323,7 @@ public class HeadersBindingTest extends TestCase
matchHeaders.setString("B", "Altered value of B");
matchHeaders.setString("C", "Value of C");
- Binding b = new Binding(null, null, getQueueName(), _queue, null, bindHeaders);
+ Binding b = new Binding(null, getQueueName(), _queue, null, bindHeaders);
assertFalse(new HeadersBinding(b).matches(matchHeaders));
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java b/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java
index 326d36df05..bd6a02d69b 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/exchange/HeadersExchangeTest.java
@@ -23,8 +23,7 @@ package org.apache.qpid.server.exchange;
import org.apache.qpid.AMQException;
import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.util.BrokerTestHelper;
public class HeadersExchangeTest extends AbstractHeadersExchangeTestBase
{
@@ -34,10 +33,15 @@ public class HeadersExchangeTest extends AbstractHeadersExchangeTestBase
public void setUp() throws Exception
{
super.setUp();
- // Just use the first vhost.
- VirtualHost
- virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts().iterator().next();
- _protocolSession = new InternalTestProtocolSession(virtualHost);
+ BrokerTestHelper.setUp();
+ _protocolSession = new InternalTestProtocolSession(getVirtualHost(), BrokerTestHelper.createBrokerMock());
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
public void testSimple() throws AMQException
diff --git a/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java b/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
index 92274afece..f1bf632235 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
@@ -31,42 +31,55 @@ import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.IncomingMessage;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.MemoryMessageStore;
import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class TopicExchangeTest extends InternalBrokerBaseCase
+public class TopicExchangeTest extends QpidTestCase
{
private TopicExchange _exchange;
-
private VirtualHost _vhost;
private MessageStore _store;
- private InternalTestProtocolSession _protocolSession;
-
@Override
public void setUp() throws Exception
{
super.setUp();
+ BrokerTestHelper.setUp();
_exchange = new TopicExchange();
- _vhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts().iterator().next();
+ _vhost = BrokerTestHelper.createVirtualHost(getName());
_store = new MemoryMessageStore();
- _protocolSession = new InternalTestProtocolSession(_vhost);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_vhost != null)
+ {
+ _vhost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testNoRoute() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a*#b", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.*.#.b",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.*.#.b",queue, _exchange, null));
IncomingMessage message = createMessage("a.b");
@@ -78,7 +91,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testDirectMatch() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "ab", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.b",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.b",queue, _exchange, null));
IncomingMessage message = createMessage("a.b");
@@ -105,7 +118,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testStarMatch() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a*", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.*",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.*",queue, _exchange, null));
IncomingMessage message = createMessage("a.b");
@@ -144,7 +157,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testHashMatch() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a#", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.#",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.#",queue, _exchange, null));
IncomingMessage message = createMessage("a.b.c");
@@ -207,7 +220,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testMidHash() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.*.#.b",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.*.#.b",queue, _exchange, null));
IncomingMessage message = createMessage("a.c.d.b");
@@ -237,7 +250,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testMatchafterHash() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a#", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.*.#.b.c",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.*.#.b.c",queue, _exchange, null));
IncomingMessage message = createMessage("a.c.b.b");
@@ -283,7 +296,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testHashAfterHash() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a#", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.*.#.b.c.#.d",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.*.#.b.c.#.d",queue, _exchange, null));
IncomingMessage message = createMessage("a.c.b.b.c");
@@ -310,7 +323,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testHashHash() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a#", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.#.*.#.d",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.#.*.#.d",queue, _exchange, null));
IncomingMessage message = createMessage("a.c.b.b.c");
@@ -336,7 +349,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testSubMatchFails() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.b.c.d",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.b.c.d",queue, _exchange, null));
IncomingMessage message = createMessage("a.b.c");
@@ -366,7 +379,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testMoreRouting() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.b",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.b",queue, _exchange, null));
IncomingMessage message = createMessage("a.b.c");
@@ -381,7 +394,7 @@ public class TopicExchangeTest extends InternalBrokerBaseCase
public void testMoreQueue() throws AMQException
{
AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "a", false, null, false, false, _vhost, null);
- _exchange.registerQueue(new Binding(null, null, "a.b",queue, _exchange, null));
+ _exchange.registerQueue(new Binding(null, "a.b",queue, _exchange, null));
IncomingMessage message = createMessage("a");
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java b/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java
index fabbe8640e..be31f3d039 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/UnitTestMessageLogger.java
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.server.logging;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import java.util.LinkedList;
import java.util.List;
@@ -34,9 +33,9 @@ public class UnitTestMessageLogger extends AbstractRootMessageLogger
}
- public UnitTestMessageLogger(ServerConfiguration config)
+ public UnitTestMessageLogger(boolean statusUpdatesEnabled)
{
- super(config);
+ super(statusUpdatesEnabled);
}
public void rawMessage(String message, String logHierarchy)
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java
index f739d3fcb9..e2472dbf01 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java
@@ -20,9 +20,8 @@
*/
package org.apache.qpid.server.logging.actors;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.AMQException;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.util.BrokerTestHelper;
import java.util.List;
@@ -38,24 +37,17 @@ import java.util.List;
public class AMQPChannelActorTest extends BaseConnectionActorTestCase
{
- @Override
- public void configure()
+ public void setUp()
{
- // Prevent defaulting Logging to ON
+ // do nothing
}
-
- @Override
- public void createBroker() throws Exception
+ private void setUpNow() throws Exception
{
- //prevent auto-broker startup
- }
+ super.setUp();
+ AMQChannel channel = BrokerTestHelper.createChannel(1, getSession());
- private void startBrokerNow() throws Exception
- {
- super.createBroker();
-
- _amqpActor = new AMQPChannelActor(getChannel(), _rootLogger);
+ setAmqpActor(new AMQPChannelActor(channel, getRootLogger()));
}
@@ -68,13 +60,11 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase
*/
public void testChannel() throws Exception
{
- getConfigXml().setProperty("status-updates", "ON");
-
- startBrokerNow();
+ setUpNow();
- final String message = sendTestLogMessage(_amqpActor);
+ final String message = sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
@@ -95,128 +85,22 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase
// Verify that the logged message contains the 'ch:1' marker
assertTrue("Message was not logged as part of channel 1" + logs.get(0),
logs.get(0).toString().contains("/ch:1"));
-
- }
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingOFF() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "OFF");
-
- // Start the broker now.
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
- }
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingOfF() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "OfF");
-
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
- }
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingOff() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "Off");
-
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
}
/**
- * Test that if logging is configured to be off in the configuration that
+ * Test that if logging is configured to be off via system property that
* no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
*/
- public void testChannelLoggingofF() throws Exception, AMQException
+ public void testChannelLoggingOFF() throws Exception
{
- getConfigXml().setProperty("status-updates", "ofF");
+ setStatusUpdatesEnabled(false);
- startBrokerNow();
+ setUpNow();
- sendTestLogMessage(_amqpActor);
+ sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 0, logs.size());
-
}
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingoff() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "off");
-
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
- }
-
- /**
- * Test that if logging is configured to be off in the configuration that
- * no logging is presented
- * @throws ConfigurationException
- * @throws AMQException
- */
- public void testChannelLoggingoFf() throws Exception, AMQException
- {
- getConfigXml().setProperty("status-updates", "oFf");
-
- startBrokerNow();
-
- sendTestLogMessage(_amqpActor);
-
- List<Object> logs = _rawLogger.getLogMessages();
-
- assertEquals("Message log size not as expected.", 0, logs.size());
-
- }
-
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java
index 4eda9e9da1..d1cf256563 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java
@@ -38,16 +38,9 @@ import java.util.List;
public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
{
@Override
- public void configure()
+ public void setUp()
{
- // Prevent defaulting Logging to ON
- }
-
-
- @Override
- public void createBroker()
- {
- //Prevent auto-broker startup
+ //Prevent logger creation
}
/**
@@ -60,13 +53,11 @@ public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
*/
public void testConnection() throws Exception
{
- getConfigXml().setProperty("status-updates", "ON");
-
- super.createBroker();
+ super.setUp();
final String message = sendLogMessage();
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
@@ -90,14 +81,13 @@ public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
public void testConnectionLoggingOff() throws Exception, AMQException
{
- getConfigXml().setProperty("status-updates", "OFF");
+ setStatusUpdatesEnabled(false);
- // Start the broker now.
- super.createBroker();
+ super.setUp();
sendLogMessage();
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 0, logs.size());
@@ -107,7 +97,7 @@ public class AMQPConnectionActorTest extends BaseConnectionActorTestCase
{
final String message = "test logging";
- _amqpActor.message(new LogSubject()
+ getAmqpActor().message(new LogSubject()
{
public String toLogString()
{
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AbstractManagementActorTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AbstractManagementActorTest.java
new file mode 100644
index 0000000000..bf38bb64bf
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AbstractManagementActorTest.java
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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.logging.actors;
+
+import java.security.Principal;
+import java.security.PrivilegedAction;
+import java.util.Collections;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.logging.NullRootMessageLogger;
+import org.apache.qpid.server.security.auth.TestPrincipalUtils;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class AbstractManagementActorTest extends QpidTestCase
+{
+ private AbstractManagementActor _logActor;
+
+ @Override
+ public void setUp()
+ {
+ _logActor = new AbstractManagementActor(new NullRootMessageLogger(), AbstractManagementActor.UNKNOWN_PRINCIPAL)
+ {
+ @Override
+ public String getLogMessage()
+ {
+ return null;
+ }
+ };
+ }
+
+ public void testGetPrincipalName()
+ {
+ Subject subject = TestPrincipalUtils.createTestSubject("guest");
+
+ final String principalName = Subject.doAs(subject,
+ new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return _logActor.getPrincipalName();
+ }
+ });
+
+ assertEquals("guest", principalName);
+ }
+
+ public void testGetPrincipalNameUsingSubjectWithoutAuthenticatedPrincipal()
+ {
+ Subject subject = new Subject(true, Collections.<Principal>emptySet(), Collections.emptySet(), Collections.emptySet());
+
+ final String principalName = Subject.doAs(subject,
+ new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return _logActor.getPrincipalName();
+ }
+ });
+
+ assertEquals(AbstractManagementActor.UNKNOWN_PRINCIPAL, principalName);
+ }
+
+ public void testGetPrincipalWithoutSubject()
+ {
+ assertEquals(AbstractManagementActor.UNKNOWN_PRINCIPAL, _logActor.getPrincipalName());
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java
index ec2cdd5585..30c3a51604 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java
@@ -20,39 +20,39 @@
*/
package org.apache.qpid.server.logging.actors;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogMessage;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.RootMessageLogger;
import org.apache.qpid.server.logging.UnitTestMessageLogger;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class BaseActorTestCase extends InternalBrokerBaseCase
+public class BaseActorTestCase extends QpidTestCase
{
- protected LogActor _amqpActor;
- protected UnitTestMessageLogger _rawLogger;
- protected RootMessageLogger _rootLogger;
+ private boolean _statusUpdatesEnabled = true;
+ private LogActor _amqpActor;
+ private UnitTestMessageLogger _rawLogger;
+ private RootMessageLogger _rootLogger;
@Override
- public void configure()
+ public void setUp() throws Exception
{
- getConfiguration().getConfig().setProperty(ServerConfiguration.STATUS_UPDATES, "on");
- }
-
- @Override
- public void createBroker() throws Exception
- {
- super.createBroker();
-
- _rawLogger = new UnitTestMessageLogger(getConfiguration());
+ super.setUp();
+ CurrentActor.removeAll();
+ CurrentActor.setDefault(null);
+ _rawLogger = new UnitTestMessageLogger(_statusUpdatesEnabled);
_rootLogger = _rawLogger;
}
+ @Override
public void tearDown() throws Exception
{
- _rawLogger.clearLogMessages();
-
+ if(_rawLogger != null)
+ {
+ _rawLogger.clearLogMessages();
+ }
+ CurrentActor.removeAll();
+ CurrentActor.setDefault(null);
super.tearDown();
}
@@ -87,4 +87,34 @@ public class BaseActorTestCase extends InternalBrokerBaseCase
});
}
+ public boolean isStatusUpdatesEnabled()
+ {
+ return _statusUpdatesEnabled;
+ }
+
+ public void setStatusUpdatesEnabled(boolean statusUpdatesEnabled)
+ {
+ _statusUpdatesEnabled = statusUpdatesEnabled;
+ }
+
+ public LogActor getAmqpActor()
+ {
+ return _amqpActor;
+ }
+
+ public void setAmqpActor(LogActor amqpActor)
+ {
+ _amqpActor = amqpActor;
+ }
+
+ public UnitTestMessageLogger getRawLogger()
+ {
+ return _rawLogger;
+ }
+
+ public RootMessageLogger getRootLogger()
+ {
+ return _rootLogger;
+ }
+
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java
index 956d296dce..09dd48e4d3 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java
@@ -20,14 +20,43 @@
*/
package org.apache.qpid.server.logging.actors;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.server.util.BrokerTestHelper;
+
public class BaseConnectionActorTestCase extends BaseActorTestCase
{
+ private AMQProtocolSession _session;
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _session = BrokerTestHelper.createSession();
+
+ setAmqpActor(new AMQPConnectionActor(_session, getRootLogger()));
+ }
- _amqpActor = new AMQPConnectionActor(getSession(), _rootLogger);
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_session != null)
+ {
+ _session.getVirtualHost().close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
+
+ public AMQProtocolSession getSession()
+ {
+ return _session;
+ }
+
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java
index f73765f5aa..8ea5510ce6 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java
@@ -70,12 +70,7 @@ public class CurrentActorTest extends BaseConnectionActorTestCase
*/
public void testLIFO() throws AMQException, ConfigurationException
{
- // This test only needs the local objects created, _session etc.
- // So stopping the broker and making them useless will not affect the
- // test, but the extra actors the test broker adds will so by stopping
- // we remove the session actor and so all is good.
- stopBroker();
-
+ assertTrue("Unexpected actor: " + CurrentActor.get(), CurrentActor.get() instanceof TestLogActor);
AMQPConnectionActor connectionActor = new AMQPConnectionActor(getSession(),
new NullRootMessageLogger());
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java
new file mode 100644
index 0000000000..905de4b639
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/HttpManagementActorTest.java
@@ -0,0 +1,94 @@
+/*
+ *
+ * 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.logging.actors;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.security.auth.TestPrincipalUtils;
+
+import java.security.PrivilegedAction;
+import java.util.List;
+
+public class HttpManagementActorTest extends BaseActorTestCase
+{
+ private static final String IP = "127.0.0.1";
+ private static final int PORT = 1;
+ private static final String SUFFIX = "(" + IP + ":" + PORT + ")] ";
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ setAmqpActor(new HttpManagementActor(getRootLogger(), IP, PORT));
+ }
+
+ public void testSubjectPrincipalNameAppearance()
+ {
+ Subject subject = TestPrincipalUtils.createTestSubject("guest");
+
+ final String message = Subject.doAs(subject, new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return sendTestLogMessage(getAmqpActor());
+ }
+ });
+
+ assertNotNull("Test log message is not created!", message);
+
+ List<Object> logs = getRawLogger().getLogMessages();
+ assertEquals("Message log size not as expected.", 1, logs.size());
+
+ String logMessage = logs.get(0).toString();
+ assertTrue("Message was not found in log message", logMessage.contains(message));
+ assertTrue("Message does not contain expected value: " + logMessage, logMessage.contains("[mng:guest" + SUFFIX));
+ }
+
+ /** It's necessary to test successive calls because HttpManagementActor caches
+ * its log message based on principal name */
+ public void testGetLogMessageCaching()
+ {
+ assertLogMessageWithoutPrincipal();
+ assertLogMessageWithPrincipal("my_principal");
+ assertLogMessageWithPrincipal("my_principal2");
+ assertLogMessageWithoutPrincipal();
+ }
+
+ private void assertLogMessageWithoutPrincipal()
+ {
+ String message = getAmqpActor().getLogMessage();
+ assertEquals("Unexpected log message", "[mng:" + AbstractManagementActor.UNKNOWN_PRINCIPAL + SUFFIX, message);
+ }
+
+ private void assertLogMessageWithPrincipal(String principalName)
+ {
+ Subject subject = TestPrincipalUtils.createTestSubject(principalName);
+ final String message = Subject.doAs(subject, new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return getAmqpActor().getLogMessage();
+ }
+ });
+
+ assertEquals("Unexpected log message", "[mng:" + principalName + SUFFIX, message);
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
index cb866245f0..a0bfa592db 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/ManagementActorTest.java
@@ -20,10 +20,11 @@
*/
package org.apache.qpid.server.logging.actors;
-import javax.management.remote.JMXPrincipal;
import javax.security.auth.Subject;
+
+import org.apache.qpid.server.security.auth.TestPrincipalUtils;
+
import java.security.PrivilegedAction;
-import java.util.Collections;
import java.util.List;
public class ManagementActorTest extends BaseActorTestCase
@@ -34,10 +35,10 @@ public class ManagementActorTest extends BaseActorTestCase
private String _threadName;
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
- _amqpActor = new ManagementActor(_rootLogger);
+ super.setUp();
+ setAmqpActor(new ManagementActor(getRootLogger()));
// Set the thread name to be the same as a RMI JMX Connection would use
_threadName = Thread.currentThread().getName();
@@ -56,14 +57,14 @@ public class ManagementActorTest extends BaseActorTestCase
*
* The test sends a message then verifies that it entered the logs.
*
- * The log message should be fully repalaced (no '{n}' values) and should
+ * The log message should be fully replaced (no '{n}' values) and should
* not contain any channel identification.
*/
public void testConnection()
{
- final String message = sendTestLogMessage(_amqpActor);
+ final String message = sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
@@ -94,21 +95,20 @@ public class ManagementActorTest extends BaseActorTestCase
*/
public void testSubjectPrincipalNameAppearance()
{
- Subject subject = new Subject(true, Collections.singleton(new JMXPrincipal("guest")), Collections.EMPTY_SET,
- Collections.EMPTY_SET);
+ Subject subject = TestPrincipalUtils.createTestSubject("guest");
final String message = Subject.doAs(subject, new PrivilegedAction<String>()
{
public String run()
{
- return sendTestLogMessage(_amqpActor);
+ return sendTestLogMessage(getAmqpActor());
}
});
// Verify that the log message was created
assertNotNull("Test log message is not created!", message);
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
// Verify that at least one log message was added to log
assertEquals("Message log size not as expected.", 1, logs.size());
@@ -130,8 +130,8 @@ public class ManagementActorTest extends BaseActorTestCase
public void testGetLogMessageWithoutSubjectButWithActorPrincipal()
{
String principalName = "my_principal";
- _amqpActor = new ManagementActor(_rootLogger, principalName);
- String message = _amqpActor.getLogMessage();
+ setAmqpActor(new ManagementActor(getRootLogger(), principalName));
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[mng:" + principalName + "(" + IP + ")] ", message);
}
@@ -149,7 +149,7 @@ public class ManagementActorTest extends BaseActorTestCase
assertLogMessageInRMIThreadWithPrincipal("RMI TCP Connection(1)-" + IP, "my_principal");
Thread.currentThread().setName("RMI TCP Connection(2)-" + IP );
- String message = _amqpActor.getLogMessage();
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[mng:N/A(" + IP + ")] ", message);
assertLogMessageWithoutPrincipal("TEST");
@@ -158,28 +158,26 @@ public class ManagementActorTest extends BaseActorTestCase
private void assertLogMessageInRMIThreadWithoutPrincipal(String threadName)
{
Thread.currentThread().setName(threadName );
- String message = _amqpActor.getLogMessage();
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[mng:N/A(" + IP + ")] ", message);
}
private void assertLogMessageWithoutPrincipal(String threadName)
{
Thread.currentThread().setName(threadName );
- String message = _amqpActor.getLogMessage();
+ String message = getAmqpActor().getLogMessage();
assertEquals("Unexpected log message", "[" + threadName +"] ", message);
}
private void assertLogMessageInRMIThreadWithPrincipal(String threadName, String principalName)
{
Thread.currentThread().setName(threadName);
- Subject subject = new Subject(true, Collections.singleton(new JMXPrincipal(principalName)), Collections.EMPTY_SET,
- Collections.EMPTY_SET);
-
+ Subject subject = TestPrincipalUtils.createTestSubject(principalName);
final String message = Subject.doAs(subject, new PrivilegedAction<String>()
{
public String run()
{
- return _amqpActor.getLogMessage();
+ return getAmqpActor().getLogMessage();
}
});
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java
index 409f7c84b7..2dc44c58ce 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java
@@ -22,14 +22,16 @@ package org.apache.qpid.server.logging.actors;
import java.util.List;
+import org.apache.qpid.server.util.BrokerTestHelper;
+
public class QueueActorTest extends BaseConnectionActorTestCase
{
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
- _amqpActor = new QueueActor(getQueue(), _rootLogger);
+ super.setUp();
+ setAmqpActor(new QueueActor(BrokerTestHelper.createQueue(getName(), getSession().getVirtualHost()), getRootLogger()));
}
/**
@@ -42,9 +44,9 @@ public class QueueActorTest extends BaseConnectionActorTestCase
*/
public void testQueueActor()
{
- final String message = sendTestLogMessage(_amqpActor);
+ final String message = sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java
index 8eaa165853..58fca488c4 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java
@@ -21,6 +21,7 @@
package org.apache.qpid.server.logging.actors;
import org.apache.qpid.server.subscription.MockSubscription;
+import org.apache.qpid.server.util.BrokerTestHelper;
import java.util.List;
@@ -37,15 +38,15 @@ public class SubscriptionActorTest extends BaseConnectionActorTestCase
{
@Override
- public void createBroker() throws Exception
+ public void setUp() throws Exception
{
- super.createBroker();
+ super.setUp();
MockSubscription mockSubscription = new MockSubscription();
- mockSubscription.setQueue(getQueue(), false);
+ mockSubscription.setQueue(BrokerTestHelper.createQueue(getName(), getSession().getVirtualHost()), false);
- _amqpActor = new SubscriptionActor(_rootLogger, mockSubscription);
+ setAmqpActor(new SubscriptionActor(getRootLogger(), mockSubscription));
}
/**
@@ -58,9 +59,9 @@ public class SubscriptionActorTest extends BaseConnectionActorTestCase
*/
public void testSubscription()
{
- final String message = sendTestLogMessage(_amqpActor);
+ final String message = sendTestLogMessage(getAmqpActor());
- List<Object> logs = _rawLogger.getLogMessages();
+ List<Object> logs = getRawLogger().getLogMessages();
assertEquals("Message log size not as expected.", 1, logs.size());
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingFacadeTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingFacadeTest.java
deleted file mode 100644
index f871baffe6..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingFacadeTest.java
+++ /dev/null
@@ -1,245 +0,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.
- *
- */
-package org.apache.qpid.server.logging.log4j;
-
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Level;
-import org.apache.qpid.util.FileUtils;
-
-import junit.framework.TestCase;
-
-public class LoggingFacadeTest extends TestCase
-{
- private LoggingFacade _loggingFacade;
- private String _log4jXmlFile;
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- _log4jXmlFile = createTestLog4jXml();
- _loggingFacade = LoggingFacade.configure(_log4jXmlFile);
- }
-
- public void testGetAvailableLoggerLevels() throws Exception
- {
- List<String> levels = _loggingFacade.getAvailableLoggerLevels();
- assertTrue(levels.contains("ALL"));
- assertTrue(levels.contains("TRACE"));
- assertTrue(levels.contains("DEBUG"));
- assertTrue(levels.contains("INFO"));
- assertTrue(levels.contains("WARN"));
- assertTrue(levels.contains("ERROR"));
- assertTrue(levels.contains("FATAL"));
- assertTrue(levels.contains("OFF"));
- assertEquals(8, levels.size());
- }
-
- public void testRetrieveConfigFileRootLoggerLevel() throws Exception
- {
- String level = _loggingFacade.retrieveConfigFileRootLoggerLevel();
- assertEquals(Level.WARN.toString(), level);
- }
-
- public void testSetConfigFileRootLoggerLevel() throws Exception
- {
- String oldLevel = _loggingFacade.retrieveConfigFileRootLoggerLevel();
- assertEquals("WARN", oldLevel);
-
- _loggingFacade.setConfigFileRootLoggerLevel("INFO");
-
- String level = _loggingFacade.retrieveConfigFileRootLoggerLevel();
- assertEquals("INFO", level);
- }
-
- public void testRetrieveConfigFileLoggerLevels() throws Exception
- {
- Map<String, String> levels = _loggingFacade.retrieveConfigFileLoggersLevels();
- assertEquals(3, levels.size());
- String abcLevel = levels.get("a.b.c");
- String abc1Level = levels.get("a.b.c.1");
- String abc2Level = levels.get("a.b.c.2");
- assertEquals("INFO", abcLevel);
- assertEquals("DEBUG", abc1Level);
- assertEquals("TRACE", abc2Level);
- }
-
- public void testSetConfigFileLoggerLevels() throws Exception
- {
- final String loggerName = "a.b.c";
-
- assertConfigFileLoggingLevel(loggerName, "INFO");
-
- _loggingFacade.setConfigFileLoggerLevel(loggerName, "WARN");
-
- Map<String, String> levels = _loggingFacade.retrieveConfigFileLoggersLevels();
- String abcLevel = levels.get(loggerName);
- assertEquals("WARN", abcLevel);
- }
-
- public void testSetConfigFileLoggerLevelsWhereLoggerDoesNotExist() throws Exception
- {
- try
- {
- _loggingFacade.setConfigFileLoggerLevel("does.not.exist", "WARN");
- fail("Exception not thrown");
- }
- catch (LoggingFacadeException lfe)
- {
- // PASS
- assertEquals("Can't find logger does.not.exist", lfe.getMessage());
- }
- }
-
- public void testRetrieveRuntimeRootLoggerLevel() throws Exception
- {
- String level = _loggingFacade.retrieveRuntimeRootLoggerLevel();
- assertEquals(Level.WARN.toString(), level);
- }
-
- public void testSetRuntimeRootLoggerLevel() throws Exception
- {
- String oldLevel = _loggingFacade.retrieveRuntimeRootLoggerLevel();
- assertEquals("WARN", oldLevel);
-
- _loggingFacade.setRuntimeRootLoggerLevel("INFO");
-
- String level = _loggingFacade.retrieveRuntimeRootLoggerLevel();
- assertEquals("INFO", level);
- }
-
- public void testRetrieveRuntimeLoggersLevels() throws Exception
- {
- Map<String, String> levels = _loggingFacade.retrieveRuntimeLoggersLevels();
- // Don't assert size as implementation itself uses logging and we'd count its loggers too
- String abcLevel = levels.get("a.b.c");
- String abc1Level = levels.get("a.b.c.1");
- String abc2Level = levels.get("a.b.c.2");
- assertEquals("INFO", abcLevel);
- assertEquals("DEBUG", abc1Level);
- assertEquals("TRACE", abc2Level);
- }
-
- public void testSetRuntimeLoggerLevel() throws Exception
- {
- final String loggerName = "a.b.c";
-
- assertRuntimeLoggingLevel(loggerName, "INFO");
-
- _loggingFacade.setRuntimeLoggerLevel(loggerName, "WARN");
-
- assertRuntimeLoggingLevel(loggerName, "WARN");
- }
-
- public void testSetRuntimeLoggerToInheritFromParent() throws Exception
- {
- final String parentLoggerName = "a.b.c";
- final String childLoggerName = "a.b.c.1";
-
- assertRuntimeLoggingLevel(parentLoggerName, "INFO");
- assertRuntimeLoggingLevel(childLoggerName, "DEBUG");
-
- _loggingFacade.setRuntimeLoggerLevel(childLoggerName, null);
-
- assertRuntimeLoggingLevel(parentLoggerName, "INFO");
- assertRuntimeLoggingLevel(childLoggerName, "INFO");
- }
-
- public void testSetRuntimeLoggerLevelsWhereLoggerDoesNotExist() throws Exception
- {
- final String loggerName = "does.not.exist2";
-
- Map<String, String> oldLevels = _loggingFacade.retrieveRuntimeLoggersLevels();
- assertFalse(oldLevels.containsKey(loggerName));
-
- try
- {
- _loggingFacade.setRuntimeLoggerLevel(loggerName, "WARN");
- fail("Exception not thrown");
- }
- catch (LoggingFacadeException lfe)
- {
- // PASS
- assertEquals("Can't find logger " + loggerName, lfe.getMessage());
- }
-
- Map<String, String> levels = _loggingFacade.retrieveRuntimeLoggersLevels();
- assertFalse(levels.containsKey(loggerName));
- }
-
- public void testReloadOfChangedLog4JFileUpdatesRuntimeLogLevel() throws Exception
- {
- final String loggerName = "a.b.c";
-
- assertRuntimeLoggingLevel(loggerName, "INFO");
- assertConfigFileLoggingLevel(loggerName, "INFO");
-
- _loggingFacade.setConfigFileLoggerLevel(loggerName, "WARN");
-
- assertRuntimeLoggingLevel(loggerName, "INFO");
-
- _loggingFacade.reload();
-
- assertRuntimeLoggingLevel(loggerName, "WARN");
- }
-
-
- public void testReloadOfLog4JFileRevertsRuntimeChanges() throws Exception
- {
- final String loggerName = "a.b.c";
-
- assertRuntimeLoggingLevel(loggerName, "INFO");
- assertConfigFileLoggingLevel(loggerName, "INFO");
-
- _loggingFacade.setRuntimeLoggerLevel(loggerName, "WARN");
-
- assertRuntimeLoggingLevel(loggerName, "WARN");
-
- _loggingFacade.reload();
-
- assertRuntimeLoggingLevel(loggerName, "INFO");
- }
-
- private void assertConfigFileLoggingLevel(final String loggerName, String expectedLevel) throws Exception
- {
- Map<String, String> levels = _loggingFacade.retrieveConfigFileLoggersLevels();
- String actualLevel = levels.get(loggerName);
- assertEquals(expectedLevel, actualLevel);
- }
-
- private void assertRuntimeLoggingLevel(final String loggerName, String expectedLevel) throws Exception
- {
- Map<String, String> levels = _loggingFacade.retrieveRuntimeLoggersLevels();
- String actualLevel = levels.get(loggerName);
- assertEquals(expectedLevel, actualLevel);
- }
-
- private String createTestLog4jXml() throws Exception
- {
- File dst = File.createTempFile("log4j." + getName(), "xml");
- File filename = new File(getClass().getResource("LoggingFacadeTest.log4j.xml").toURI());
- FileUtils.copy(filename, dst);
- dst.deleteOnExit();
- return dst.getAbsolutePath();
- }
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
new file mode 100644
index 0000000000..72b34868ba
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
@@ -0,0 +1,243 @@
+/*
+ * 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.logging.log4j;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Level;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.apache.qpid.util.FileUtils;
+
+import junit.framework.TestCase;
+
+public class LoggingManagementFacadeTest extends TestCase
+{
+ private LoggingManagementFacade _loggingFacade;
+ private String _log4jXmlFile;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _log4jXmlFile = createTestLog4jXml();
+ _loggingFacade = LoggingManagementFacade.configure(_log4jXmlFile);
+ }
+
+ public void testGetAvailableLoggerLevels() throws Exception
+ {
+ List<String> levels = _loggingFacade.getAvailableLoggerLevels();
+ assertTrue(levels.contains("ALL"));
+ assertTrue(levels.contains("TRACE"));
+ assertTrue(levels.contains("DEBUG"));
+ assertTrue(levels.contains("INFO"));
+ assertTrue(levels.contains("WARN"));
+ assertTrue(levels.contains("ERROR"));
+ assertTrue(levels.contains("FATAL"));
+ assertTrue(levels.contains("OFF"));
+ assertEquals(8, levels.size());
+ }
+
+ public void testRetrieveConfigFileRootLoggerLevel() throws Exception
+ {
+ String level = _loggingFacade.retrieveConfigFileRootLoggerLevel();
+ assertEquals(Level.WARN.toString(), level);
+ }
+
+ public void testSetConfigFileRootLoggerLevel() throws Exception
+ {
+ String oldLevel = _loggingFacade.retrieveConfigFileRootLoggerLevel();
+ assertEquals("WARN", oldLevel);
+
+ _loggingFacade.setConfigFileRootLoggerLevel("INFO");
+
+ String level = _loggingFacade.retrieveConfigFileRootLoggerLevel();
+ assertEquals("INFO", level);
+ }
+
+ public void testRetrieveConfigFileLoggerLevels() throws Exception
+ {
+ Map<String, String> levels = _loggingFacade.retrieveConfigFileLoggersLevels();
+ assertEquals(3, levels.size());
+ String abcLevel = levels.get("a.b.c");
+ String abc1Level = levels.get("a.b.c.1");
+ String abc2Level = levels.get("a.b.c.2");
+ assertEquals("INFO", abcLevel);
+ assertEquals("DEBUG", abc1Level);
+ assertEquals("TRACE", abc2Level);
+ }
+
+ public void testSetConfigFileLoggerLevels() throws Exception
+ {
+ final String loggerName = "a.b.c";
+
+ assertConfigFileLoggingLevel(loggerName, "INFO");
+
+ _loggingFacade.setConfigFileLoggerLevel(loggerName, "WARN");
+
+ Map<String, String> levels = _loggingFacade.retrieveConfigFileLoggersLevels();
+ String abcLevel = levels.get(loggerName);
+ assertEquals("WARN", abcLevel);
+ }
+
+ public void testSetConfigFileLoggerLevelsWhereLoggerDoesNotExist() throws Exception
+ {
+ try
+ {
+ _loggingFacade.setConfigFileLoggerLevel("does.not.exist", "WARN");
+ fail("Exception not thrown");
+ }
+ catch (LoggingFacadeException lfe)
+ {
+ // PASS
+ assertEquals("Can't find logger does.not.exist", lfe.getMessage());
+ }
+ }
+
+ public void testRetrieveRuntimeRootLoggerLevel() throws Exception
+ {
+ String level = _loggingFacade.retrieveRuntimeRootLoggerLevel();
+ assertEquals(Level.WARN.toString(), level);
+ }
+
+ public void testSetRuntimeRootLoggerLevel() throws Exception
+ {
+ String oldLevel = _loggingFacade.retrieveRuntimeRootLoggerLevel();
+ assertEquals("WARN", oldLevel);
+
+ _loggingFacade.setRuntimeRootLoggerLevel("INFO");
+
+ String level = _loggingFacade.retrieveRuntimeRootLoggerLevel();
+ assertEquals("INFO", level);
+ }
+
+ public void testRetrieveRuntimeLoggersLevels() throws Exception
+ {
+ Map<String, String> levels = _loggingFacade.retrieveRuntimeLoggersLevels();
+ // Don't assert size as implementation itself uses logging and we'd count its loggers too
+ String abcLevel = levels.get("a.b.c");
+ String abc1Level = levels.get("a.b.c.1");
+ String abc2Level = levels.get("a.b.c.2");
+ assertEquals("INFO", abcLevel);
+ assertEquals("DEBUG", abc1Level);
+ assertEquals("TRACE", abc2Level);
+ }
+
+ public void testSetRuntimeLoggerLevel() throws Exception
+ {
+ final String loggerName = "a.b.c";
+
+ assertRuntimeLoggingLevel(loggerName, "INFO");
+
+ _loggingFacade.setRuntimeLoggerLevel(loggerName, "WARN");
+
+ assertRuntimeLoggingLevel(loggerName, "WARN");
+ }
+
+ public void testSetRuntimeLoggerToInheritFromParent() throws Exception
+ {
+ final String parentLoggerName = "a.b.c";
+ final String childLoggerName = "a.b.c.1";
+
+ assertRuntimeLoggingLevel(parentLoggerName, "INFO");
+ assertRuntimeLoggingLevel(childLoggerName, "DEBUG");
+
+ _loggingFacade.setRuntimeLoggerLevel(childLoggerName, null);
+
+ assertRuntimeLoggingLevel(parentLoggerName, "INFO");
+ assertRuntimeLoggingLevel(childLoggerName, "INFO");
+ }
+
+ public void testSetRuntimeLoggerLevelsWhereLoggerDoesNotExist() throws Exception
+ {
+ final String loggerName = "does.not.exist2";
+
+ Map<String, String> oldLevels = _loggingFacade.retrieveRuntimeLoggersLevels();
+ assertFalse(oldLevels.containsKey(loggerName));
+
+ try
+ {
+ _loggingFacade.setRuntimeLoggerLevel(loggerName, "WARN");
+ fail("Exception not thrown");
+ }
+ catch (LoggingFacadeException lfe)
+ {
+ // PASS
+ assertEquals("Can't find logger " + loggerName, lfe.getMessage());
+ }
+
+ Map<String, String> levels = _loggingFacade.retrieveRuntimeLoggersLevels();
+ assertFalse(levels.containsKey(loggerName));
+ }
+
+ public void testReloadOfChangedLog4JFileUpdatesRuntimeLogLevel() throws Exception
+ {
+ final String loggerName = "a.b.c";
+
+ assertRuntimeLoggingLevel(loggerName, "INFO");
+ assertConfigFileLoggingLevel(loggerName, "INFO");
+
+ _loggingFacade.setConfigFileLoggerLevel(loggerName, "WARN");
+
+ assertRuntimeLoggingLevel(loggerName, "INFO");
+
+ _loggingFacade.reload();
+
+ assertRuntimeLoggingLevel(loggerName, "WARN");
+ }
+
+
+ public void testReloadOfLog4JFileRevertsRuntimeChanges() throws Exception
+ {
+ final String loggerName = "a.b.c";
+
+ assertRuntimeLoggingLevel(loggerName, "INFO");
+ assertConfigFileLoggingLevel(loggerName, "INFO");
+
+ _loggingFacade.setRuntimeLoggerLevel(loggerName, "WARN");
+
+ assertRuntimeLoggingLevel(loggerName, "WARN");
+
+ _loggingFacade.reload();
+
+ assertRuntimeLoggingLevel(loggerName, "INFO");
+ }
+
+ private void assertConfigFileLoggingLevel(final String loggerName, String expectedLevel) throws Exception
+ {
+ Map<String, String> levels = _loggingFacade.retrieveConfigFileLoggersLevels();
+ String actualLevel = levels.get(loggerName);
+ assertEquals(expectedLevel, actualLevel);
+ }
+
+ private void assertRuntimeLoggingLevel(final String loggerName, String expectedLevel) throws Exception
+ {
+ Map<String, String> levels = _loggingFacade.retrieveRuntimeLoggersLevels();
+ String actualLevel = levels.get(loggerName);
+ assertEquals(expectedLevel, actualLevel);
+ }
+
+ private String createTestLog4jXml() throws Exception
+ {
+ return TestFileUtils.createTempFileFromResource(this, "LoggingFacadeTest.log4j.xml").getAbsolutePath();
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java b/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java
index 24e7225d82..229d75c69f 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/messages/AbstractTestMessages.java
@@ -29,11 +29,12 @@ import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.UnitTestMessageLogger;
import org.apache.qpid.server.logging.actors.TestLogActor;
import org.apache.qpid.server.logging.subjects.TestBlankSubject;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
-public abstract class AbstractTestMessages extends InternalBrokerBaseCase
+public abstract class AbstractTestMessages extends QpidTestCase
{
protected Configuration _config = new PropertiesConfiguration();
protected LogMessage _logMessage = null;
@@ -49,6 +50,14 @@ public abstract class AbstractTestMessages extends InternalBrokerBaseCase
_logger = new UnitTestMessageLogger();
_actor = new TestLogActor(_logger);
+ BrokerTestHelper.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
protected List<Object> performLog()
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java
index 4364376000..1cb4da55c3 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ExchangeMessagesTest.java
@@ -21,7 +21,7 @@
package org.apache.qpid.server.logging.messages;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import java.util.List;
@@ -30,12 +30,9 @@ import java.util.List;
*/
public class ExchangeMessagesTest extends AbstractTestMessages
{
- public void testExchangeCreated_Transient()
+ public void testExchangeCreated_Transient() throws Exception
{
- // Get the Default Exchange on the Test Vhost for testing
- Exchange exchange = ApplicationRegistry.getInstance().
- getVirtualHostRegistry().getVirtualHost("test").
- getExchangeRegistry().getDefaultExchange();
+ Exchange exchange = BrokerTestHelper.createExchange("test");
String type = exchange.getTypeShortString().toString();
String name = exchange.getNameShortString().toString();
@@ -48,12 +45,9 @@ public class ExchangeMessagesTest extends AbstractTestMessages
validateLogMessage(log, "EXH-1001", expected);
}
- public void testExchangeCreated_Persistent()
+ public void testExchangeCreated_Persistent() throws Exception
{
- // Get the Default Exchange on the Test Vhost for testing
- Exchange exchange = ApplicationRegistry.getInstance().
- getVirtualHostRegistry().getVirtualHost("test").
- getExchangeRegistry().getDefaultExchange();
+ Exchange exchange = BrokerTestHelper.createExchange("test");
String type = exchange.getTypeShortString().toString();
String name = exchange.getNameShortString().toString();
@@ -76,12 +70,9 @@ public class ExchangeMessagesTest extends AbstractTestMessages
validateLogMessage(log, "EXH-1002", expected);
}
- public void testExchangeDiscardedMessage()
+ public void testExchangeDiscardedMessage() throws Exception
{
- // Get the Default Exchange on the Test Vhost for testing
- final Exchange exchange = ApplicationRegistry.getInstance().
- getVirtualHostRegistry().getVirtualHost("test").
- getExchangeRegistry().getDefaultExchange();
+ Exchange exchange = BrokerTestHelper.createExchange("test");
final String name = exchange.getNameShortString().toString();
final String routingKey = "routingKey";
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ManagementConsoleMessagesTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ManagementConsoleMessagesTest.java
index 4bfbae44ac..dfc9357402 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ManagementConsoleMessagesTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/messages/ManagementConsoleMessagesTest.java
@@ -29,10 +29,10 @@ public class ManagementConsoleMessagesTest extends AbstractTestMessages
{
public void testManagementStartup()
{
- _logMessage = ManagementConsoleMessages.STARTUP();
+ _logMessage = ManagementConsoleMessages.STARTUP("My");
List<Object> log = performLog();
- String[] expected = {"Startup"};
+ String[] expected = {"My Management Startup"};
validateLogMessage(log, "MNG-1001", expected);
}
@@ -65,29 +65,20 @@ public class ManagementConsoleMessagesTest extends AbstractTestMessages
public void testManagementReady()
{
- _logMessage = ManagementConsoleMessages.READY(false);
+ _logMessage = ManagementConsoleMessages.READY("My");
List<Object> log = performLog();
- String[] expected = {"Ready"};
-
- validateLogMessage(log, "MNG-1004", expected);
-
- _logger.clearLogMessages();
-
- _logMessage = ManagementConsoleMessages.READY(true);
- log = performLog();
-
- expected = new String[]{"Ready : Using the platform JMX Agent"};
+ String[] expected = {"My Management Ready"};
validateLogMessage(log, "MNG-1004", expected);
}
public void testManagementStopped()
{
- _logMessage = ManagementConsoleMessages.STOPPED();
+ _logMessage = ManagementConsoleMessages.STOPPED("My");
List<Object> log = performLog();
- String[] expected = {"Stopped"};
+ String[] expected = {"My Management Stopped"};
validateLogMessage(log, "MNG-1005", expected);
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java
index c2558d2d1b..193e8a490d 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java
@@ -20,21 +20,19 @@
*/
package org.apache.qpid.server.logging.subjects;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.logging.LogActor;
import org.apache.qpid.server.logging.LogMessage;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.logging.UnitTestMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.TestLogActor;
import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
@@ -49,29 +47,39 @@ import java.util.List;
* The resulting log file is then validated.
*
*/
-public abstract class AbstractTestLogSubject extends InternalBrokerBaseCase
+public abstract class AbstractTestLogSubject extends QpidTestCase
{
- protected Configuration _config = new PropertiesConfiguration();
protected LogSubject _subject = null;
@Override
public void setUp() throws Exception
{
super.setUp();
-
- _config.setProperty(ServerConfiguration.STATUS_UPDATES, "ON");
+ BrokerTestHelper.setUp();
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ try
+ {
+ CurrentActor.removeAll();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
- protected List<Object> performLog() throws ConfigurationException
+ protected List<Object> performLog(boolean statusUpdatesEnabled)
{
if (_subject == null)
{
throw new NullPointerException("LogSubject has not been set");
}
- ServerConfiguration serverConfig = new ServerConfiguration(_config);
- UnitTestMessageLogger logger = new UnitTestMessageLogger(serverConfig);
+ UnitTestMessageLogger logger = new UnitTestMessageLogger(statusUpdatesEnabled);
LogActor actor = new TestLogActor(logger);
@@ -247,11 +255,10 @@ public abstract class AbstractTestLogSubject extends InternalBrokerBaseCase
/**
* Test that when Logging occurs a single log statement is provided
*
- * @throws ConfigurationException
*/
- public void testEnabled() throws ConfigurationException
+ public void testEnabled()
{
- List<Object> logs = performLog();
+ List<Object> logs = performLog(true);
assertEquals("Log has incorrect message count", 1, logs.size());
@@ -267,15 +274,11 @@ public abstract class AbstractTestLogSubject extends InternalBrokerBaseCase
protected abstract void validateLogStatement(String message);
/**
- * Ensure that when status-updates are off this does not perform logging
- *
- * @throws ConfigurationException
+ * Ensure that when status updates are off this does not perform logging
*/
- public void testDisabled() throws ConfigurationException
+ public void testDisabled()
{
- _config.setProperty(ServerConfiguration.STATUS_UPDATES, "OFF");
-
- List<Object> logs = performLog();
+ List<Object> logs = performLog(false);
assertEquals("Log has incorrect message count", 0, logs.size());
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java
index e80c4c4679..dd8d28e836 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java
@@ -24,7 +24,7 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.MockAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
/**
@@ -38,13 +38,12 @@ public class BindingLogSubjectTest extends AbstractTestLogSubject
private Exchange _exchange;
private VirtualHost _testVhost;
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
- // Configure items for subjectCreation
+ _testVhost = BrokerTestHelper.createVirtualHost("test");
_routingKey = new AMQShortString("RoutingKey");
_exchange = _testVhost.getExchangeRegistry().getDefaultExchange();
_queue = new MockAMQQueue("BindingLogSubjectTest");
@@ -53,6 +52,16 @@ public class BindingLogSubjectTest extends AbstractTestLogSubject
_subject = new BindingLogSubject(String.valueOf(_routingKey), _exchange, _queue);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][vh(/test)/ex(direct/<<default>>)/qu(BindingLogSubjectTest)/rk(RoutingKey)] <Log Message>
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java
index 6bc5effa05..d75e033739 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java
@@ -34,6 +34,7 @@ public class ChannelLogSubjectTest extends ConnectionLogSubjectTest
{
super.setUp();
+
AMQChannel channel = new AMQChannel(getSession(), _channelID, getSession().getVirtualHost().getMessageStore());
_subject = new ChannelLogSubject(channel);
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java
index c246fff2a8..7dc4c443ba 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java
@@ -20,17 +20,34 @@
*/
package org.apache.qpid.server.logging.subjects;
+import org.apache.qpid.server.protocol.InternalTestProtocolSession;
+import org.apache.qpid.server.util.BrokerTestHelper;
+
/**
* Validate ConnectionLogSubjects are logged as expected
*/
public class ConnectionLogSubjectTest extends AbstractTestLogSubject
{
+ private InternalTestProtocolSession _session;
+
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _subject = new ConnectionLogSubject(getSession());
+ _session = BrokerTestHelper.createSession("test");
+ _subject = new ConnectionLogSubject(_session);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_session != null)
+ {
+ _session.getVirtualHost().close();
+ }
+ super.tearDown();
}
/**
@@ -40,7 +57,12 @@ public class ConnectionLogSubjectTest extends AbstractTestLogSubject
*/
protected void validateLogStatement(String message)
{
- verifyConnection(getSession().getSessionID(), "InternalTestProtocolSession", "127.0.0.1:1", "test", message);
+ verifyConnection(_session.getSessionID(), "InternalTestProtocolSession", "127.0.0.1:1", "test", message);
+ }
+
+ public InternalTestProtocolSession getSession()
+ {
+ return _session;
}
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java
index cc06b05bf6..8d1b89bf3c 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubjectTest.java
@@ -21,7 +21,7 @@
package org.apache.qpid.server.logging.subjects;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -33,17 +33,27 @@ public class ExchangeLogSubjectTest extends AbstractTestLogSubject
private Exchange _exchange;
private VirtualHost _testVhost;
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
+ _testVhost = BrokerTestHelper.createVirtualHost("test");
_exchange = _testVhost.getExchangeRegistry().getDefaultExchange();
_subject = new ExchangeLogSubject(_exchange,_testVhost);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][vh(/test)/ex(direct/<<default>>)] <Log Message>
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java
index c62b24c3b9..65fd249d03 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubjectTest.java
@@ -20,7 +20,7 @@
*/
package org.apache.qpid.server.logging.subjects;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
/**
@@ -30,16 +30,26 @@ public class MessageStoreLogSubjectTest extends AbstractTestLogSubject
{
private VirtualHost _testVhost;
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
+ _testVhost = BrokerTestHelper.createVirtualHost("test");
_subject = new MessageStoreLogSubject(_testVhost, _testVhost.getMessageStore().getClass().getSimpleName());
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][vh(/test)/ms(MemoryMessageStore)] <Log Message>
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java
index 1f432be57a..e2765f338b 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.logging.subjects;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.MockAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
/**
@@ -39,8 +39,7 @@ public class QueueLogSubjectTest extends AbstractTestLogSubject
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
+ _testVhost = BrokerTestHelper.createVirtualHost("test");
_queue = new MockAMQQueue("QueueLogSubjectTest");
((MockAMQQueue) _queue).setVirtualHost(_testVhost);
@@ -48,6 +47,16 @@ public class QueueLogSubjectTest extends AbstractTestLogSubject
_subject = new QueueLogSubject(_queue);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][vh(/test)/qu(QueueLogSubjectTest)] <Log Message>
diff --git a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java
index 0c356e1838..153d01f355 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java
@@ -23,12 +23,13 @@ package org.apache.qpid.server.logging.subjects;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.flow.LimitlessCreditManager;
+import org.apache.qpid.server.protocol.InternalTestProtocolSession;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.MockAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.subscription.SubscriptionFactory;
import org.apache.qpid.server.subscription.SubscriptionFactoryImpl;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
/**
@@ -42,23 +43,24 @@ public class SubscriptionLogSubjectTest extends AbstractTestLogSubject
private int _channelID = 1;
private Subscription _subscription;
+ @Override
public void setUp() throws Exception
{
super.setUp();
- _testVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost("test");
+ InternalTestProtocolSession session = BrokerTestHelper.createSession();
+ _testVhost = session.getVirtualHost();
_queue = new MockAMQQueue("SubscriptionLogSubjectTest");
((MockAMQQueue) _queue).setVirtualHost(_testVhost);
- AMQChannel channel = new AMQChannel(getSession(), _channelID, getSession().getVirtualHost().getMessageStore());
+ AMQChannel channel = new AMQChannel(session, _channelID, _testVhost.getMessageStore());
- getSession().addChannel(channel);
+ session.addChannel(channel);
SubscriptionFactory factory = new SubscriptionFactoryImpl();
- _subscription = factory.createSubscription(_channelID, getSession(), new AMQShortString("cTag"),
+ _subscription = factory.createSubscription(_channelID, session, new AMQShortString("cTag"),
false, null, false,
new LimitlessCreditManager());
@@ -67,6 +69,16 @@ public class SubscriptionLogSubjectTest extends AbstractTestLogSubject
_subject = new SubscriptionLogSubject(_subscription);
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (_testVhost != null)
+ {
+ _testVhost.close();
+ }
+ super.tearDown();
+ }
+
/**
* Validate that the logged Subject message is as expected:
* MESSAGE [Blank][sub:0(vh(/test)/qu(SubscriptionLogSubjectTest))] <Log Message>
diff --git a/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java b/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
new file mode 100644
index 0000000000..7c1db6348b
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/model/BrokerShutdownTest.java
@@ -0,0 +1,189 @@
+/*
+ *
+ * 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.model;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
+import org.apache.qpid.server.configuration.RecovererProvider;
+import org.apache.qpid.server.configuration.startup.DefaultRecovererProvider;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+import java.io.File;
+import java.security.Provider;
+import java.security.Security;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * QPID-1390 : Test to validate that the AuthenticationManger can successfully unregister any new SASL providers when
+ * the broker is stopped.
+ */
+public class BrokerShutdownTest extends QpidTestCase
+{
+ private Provider[] _defaultProviders;
+ private Broker _broker;
+ private TaskExecutor _taskExecutor;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ // Get default providers
+ _defaultProviders = Security.getProviders();
+
+ super.setUp();
+
+ _taskExecutor = new TaskExecutor();
+ _taskExecutor.start();
+
+ // Startup the new broker and register the new providers
+ _broker = startBroker();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ if (_taskExecutor != null)
+ {
+ _taskExecutor.stopImmediately();
+ }
+ }
+
+ }
+
+ private Broker startBroker() throws Exception
+ {
+ ConfigurationEntryStore store = mock(ConfigurationEntryStore.class);
+ UUID brokerId = UUID.randomUUID();
+ UUID authenticationProviderId = UUID.randomUUID();
+
+ ConfigurationEntry root = new ConfigurationEntry(brokerId, Broker.class.getSimpleName(), Collections.<String, Object> emptyMap(),
+ Collections.singleton(authenticationProviderId), store);
+
+ File file = TestFileUtils.createTempFile(BrokerShutdownTest.this, ".db.users");
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsolutePath());
+ ConfigurationEntry authenticationProviderEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getSimpleName(), attributes,
+ Collections.<UUID> emptySet(), store);
+
+ when(store.getRootEntry()).thenReturn(root);
+ when(store.getEntry(brokerId)).thenReturn(root);
+ when(store.getEntry(authenticationProviderId)).thenReturn(authenticationProviderEntry);
+
+ // mocking the required object
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ VirtualHostRegistry virtualHostRegistry = mock(VirtualHostRegistry.class);
+ LogRecorder logRecorder = mock(LogRecorder.class);
+ RootMessageLogger rootMessageLogger = mock(RootMessageLogger.class);
+
+ // recover the broker from the store
+ RecovererProvider provider = new DefaultRecovererProvider(statisticsGatherer, virtualHostRegistry, logRecorder, rootMessageLogger, _taskExecutor);
+ ConfiguredObjectRecoverer<? extends ConfiguredObject> brokerRecoverer = provider.getRecoverer(Broker.class.getSimpleName());
+
+ Broker broker = (Broker) brokerRecoverer.create(provider, store.getRootEntry());
+
+ // start broker
+ broker.setDesiredState(State.INITIALISING, State.ACTIVE);
+ return broker;
+ }
+
+ private void stopBroker()
+ {
+ _broker.setDesiredState(State.ACTIVE, State.STOPPED);
+ }
+
+ /**
+ * QPID-1399 : Ensure that the Authentication manager unregisters any SASL providers created during
+ * broker start-up.
+ *
+ */
+ public void testAuthenticationMangerCleansUp() throws Exception
+ {
+
+ // Get the providers after initialisation
+ Provider[] providersAfterInitialisation = Security.getProviders();
+
+ // Find the additions
+ List<Provider> additions = new LinkedList<Provider>();
+ for (Provider afterInit : providersAfterInitialisation)
+ {
+ boolean found = false;
+ for (Provider defaultProvider : _defaultProviders)
+ {
+ if (defaultProvider == afterInit)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ // Record added registies
+ if (!found)
+ {
+ additions.add(afterInit);
+ }
+ }
+
+ assertFalse("No new SASL mechanisms added by initialisation.", additions.isEmpty());
+
+ // Close the registry which will perform the close the
+ // AuthenticationManager
+ stopBroker();
+
+ // Validate that the SASL plugins have been removed.
+ Provider[] providersAfterClose = Security.getProviders();
+
+ assertTrue("No providers unregistered", providersAfterInitialisation.length > providersAfterClose.length);
+
+ // Ensure that the additions are not still present after close().
+ for (Provider afterClose : providersAfterClose)
+ {
+ assertFalse("Added provider not unregistered", additions.contains(afterClose));
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/model/UUIDGeneratorTest.java b/java/broker/src/test/java/org/apache/qpid/server/model/UUIDGeneratorTest.java
index 643132d371..c686a24e99 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/model/UUIDGeneratorTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/model/UUIDGeneratorTest.java
@@ -70,8 +70,12 @@ public class UUIDGeneratorTest extends QpidTestCase
idSet.add(id6);
UUID id7 = UUIDGenerator.generateVhostAliasUUID(value, value);
idSet.add(id7);
+ UUID id8 = UUIDGenerator.generateGroupUUID(value, value);
+ idSet.add(id8);
+ UUID id9 = UUIDGenerator.generateGroupMemberUUID(value, value, value);
+ idSet.add(id9);
- assertEquals("The produced UUIDs were not all unique", 7, idSet.size());
+ assertEquals("The produced UUIDs were not all unique", 9, idSet.size());
}
public void testQueueIdGeneration() throws Exception
diff --git a/java/broker/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.java
new file mode 100644
index 0000000000..585fecae83
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/model/adapter/AuthenticationProviderFactoryTest.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.server.model.adapter;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
+
+public class AuthenticationProviderFactoryTest extends TestCase
+{
+
+ public void testCreatePasswordCredentialManagingAuthenticationProvider()
+ {
+ AuthenticationProvider provider = testForFactory(mock(PrincipalDatabaseAuthenticationManager.class));
+ assertTrue("The created provider should match the factory's AuthenticationManager type",
+ provider instanceof PasswordCredentialManagingAuthenticationProvider);
+ }
+
+ public void testCreateNonPasswordCredentialManagingAuthenticationProvider()
+ {
+ AuthenticationProvider provider = testForFactory(mock(AuthenticationManager.class));
+ assertFalse("The created provider should match the factory's AuthenticationManager type",
+ provider instanceof PasswordCredentialManagingAuthenticationProvider);
+ }
+
+ @SuppressWarnings("unchecked")
+ private AuthenticationProvider testForFactory(AuthenticationManager authenticationManager)
+ {
+ UUID id = UUID.randomUUID();
+ Map<String, Object> attributes = new HashMap<String, Object>();
+
+ QpidServiceLoader<AuthenticationManagerFactory> authManagerFactoryServiceLoader = mock(QpidServiceLoader.class);
+ AuthenticationManagerFactory authenticationManagerFactory = mock(AuthenticationManagerFactory.class);
+ ConfigurationEntry configurationEntry = mock(ConfigurationEntry.class);
+
+ when(configurationEntry.getId()).thenReturn(id);
+ Broker broker = mock(Broker.class);
+
+ when(authManagerFactoryServiceLoader.atLeastOneInstanceOf(AuthenticationManagerFactory.class)).thenReturn(
+ Collections.singleton(authenticationManagerFactory));
+ when(authenticationManagerFactory.createInstance(attributes)).thenReturn(authenticationManager);
+
+ AuthenticationProviderFactory providerFactory = new AuthenticationProviderFactory(authManagerFactoryServiceLoader);
+ AuthenticationProvider provider = providerFactory.create(id, broker, attributes, null);
+
+ assertNotNull("Provider is not created", provider);
+ assertEquals("Unexpected ID", id, provider.getId());
+
+ return provider;
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
new file mode 100644
index 0000000000..14c5c265c9
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
@@ -0,0 +1,212 @@
+/*
+ *
+ * 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.model.adapter;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class PortFactoryTest extends QpidTestCase
+{
+ private UUID _portId = UUID.randomUUID();
+ private int _portNumber = 123;
+ private Set<String> _tcpStringSet = Collections.singleton(Transport.SSL.name());
+ private Set<Transport> _tcpTransportSet = Collections.singleton(Transport.SSL);
+
+ private Map<String, Object> _attributes = new HashMap<String, Object>();
+
+ private Broker _broker = mock(Broker.class);
+ private PortFactory _portFactory;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, null);
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, null);
+ _portFactory = new PortFactory();
+
+ _attributes.put(Port.PORT, _portNumber);
+ _attributes.put(Port.TRANSPORTS, _tcpStringSet);
+
+ _attributes.put(Port.TCP_NO_DELAY, "true");
+ _attributes.put(Port.RECEIVE_BUFFER_SIZE, "1");
+ _attributes.put(Port.SEND_BUFFER_SIZE, "2");
+ _attributes.put(Port.NEED_CLIENT_AUTH, "true");
+ _attributes.put(Port.WANT_CLIENT_AUTH, "true");
+ _attributes.put(Port.BINDING_ADDRESS, "127.0.0.1");
+ }
+
+ public void testDefaultProtocols()
+ {
+ Collection<Protocol> protocols = _portFactory.getDefaultProtocols();
+ EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, Protocol.AMQP_0_10,
+ Protocol.AMQP_1_0);
+ assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols));
+ }
+
+ public void testDefaultProtocolsWhenProtocolExcludeSystemPropertyIsSet()
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, Protocol.AMQP_1_0.name() + ","
+ + Protocol.AMQP_0_10.name());
+ _portFactory = new PortFactory();
+ Collection<Protocol> protocols = _portFactory.getDefaultProtocols();
+ EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1);
+ assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols));
+ }
+
+ public void testDefaultProtocolsWhenProtocolIncludeSystemPropertyIsSet()
+ {
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, Protocol.AMQP_1_0.name() + ","
+ + Protocol.AMQP_0_10.name() + "," + Protocol.AMQP_0_9_1.name());
+ setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, Protocol.AMQP_0_10.name() + ","
+ + Protocol.AMQP_0_9_1.name());
+ _portFactory = new PortFactory();
+ Collection<Protocol> protocols = _portFactory.getDefaultProtocols();
+ EnumSet<Protocol> expected = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, Protocol.AMQP_0_10);
+ assertEquals("Unexpected protocols", new HashSet<Protocol>(expected), new HashSet<Protocol>(protocols));
+ }
+
+ public void testCreatePortWithMinimumAttributes()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PORT, 1);
+ Port port = _portFactory.createPort(_portId, _broker, attributes);
+
+ assertNotNull(port);
+ assertTrue(port instanceof AmqpPortAdapter);
+ assertEquals("Unexpected port", 1, port.getPort());
+ assertEquals("Unexpected transports", Collections.singleton(PortFactory.DEFAULT_TRANSPORT), port.getTransports());
+ assertEquals("Unexpected protocols", _portFactory.getDefaultProtocols(), port.getProtocols());
+ assertEquals("Unexpected send buffer size", PortFactory.DEFAULT_AMQP_SEND_BUFFER_SIZE,
+ port.getAttribute(Port.SEND_BUFFER_SIZE));
+ assertEquals("Unexpected receive buffer size", PortFactory.DEFAULT_AMQP_RECEIVE_BUFFER_SIZE,
+ port.getAttribute(Port.RECEIVE_BUFFER_SIZE));
+ assertEquals("Unexpected need client auth", PortFactory.DEFAULT_AMQP_NEED_CLIENT_AUTH,
+ port.getAttribute(Port.NEED_CLIENT_AUTH));
+ assertEquals("Unexpected want client auth", PortFactory.DEFAULT_AMQP_WANT_CLIENT_AUTH,
+ port.getAttribute(Port.WANT_CLIENT_AUTH));
+ assertEquals("Unexpected tcp no delay", PortFactory.DEFAULT_AMQP_TCP_NO_DELAY, port.getAttribute(Port.TCP_NO_DELAY));
+ assertEquals("Unexpected binding", PortFactory.DEFAULT_AMQP_BINDING, port.getAttribute(Port.BINDING_ADDRESS));
+ }
+
+ public void testCreateAmqpPort()
+ {
+ Set<Protocol> amqp010ProtocolSet = Collections.singleton(Protocol.AMQP_0_10);
+ Set<String> amqp010StringSet = Collections.singleton(Protocol.AMQP_0_10.name());
+ _attributes.put(Port.PROTOCOLS, amqp010StringSet);
+
+ Port port = _portFactory.createPort(_portId, _broker, _attributes);
+
+ assertNotNull(port);
+ assertTrue(port instanceof AmqpPortAdapter);
+ assertEquals(_portId, port.getId());
+ assertEquals(_portNumber, port.getPort());
+ assertEquals(_tcpTransportSet, port.getTransports());
+ assertEquals(amqp010ProtocolSet, port.getProtocols());
+ assertEquals("Unexpected send buffer size", 2, port.getAttribute(Port.SEND_BUFFER_SIZE));
+ assertEquals("Unexpected receive buffer size", 1, port.getAttribute(Port.RECEIVE_BUFFER_SIZE));
+ assertEquals("Unexpected need client auth", true, port.getAttribute(Port.NEED_CLIENT_AUTH));
+ assertEquals("Unexpected want client auth", true, port.getAttribute(Port.WANT_CLIENT_AUTH));
+ assertEquals("Unexpected tcp no delay", true, port.getAttribute(Port.TCP_NO_DELAY));
+ assertEquals("Unexpected binding", "127.0.0.1", port.getAttribute(Port.BINDING_ADDRESS));
+ }
+
+ public void testCreateNonAmqpPort()
+ {
+ Set<Protocol> nonAmqpProtocolSet = Collections.singleton(Protocol.JMX_RMI);
+ Set<String> nonAmqpStringSet = Collections.singleton(Protocol.JMX_RMI.name());
+ _attributes = new HashMap<String, Object>();
+ _attributes.put(Port.PROTOCOLS, nonAmqpStringSet);
+ _attributes.put(Port.PORT, _portNumber);
+ _attributes.put(Port.TRANSPORTS, _tcpStringSet);
+
+ Port port = _portFactory.createPort(_portId, _broker, _attributes);
+
+ assertNotNull(port);
+ assertFalse("Port should be a PortAdapter, not its AMQP-specific subclass", port instanceof AmqpPortAdapter);
+ assertEquals(_portId, port.getId());
+ assertEquals(_portNumber, port.getPort());
+ assertEquals(_tcpTransportSet, port.getTransports());
+ assertEquals(nonAmqpProtocolSet, port.getProtocols());
+ assertNull("Unexpected send buffer size", port.getAttribute(Port.SEND_BUFFER_SIZE));
+ assertNull("Unexpected receive buffer size", port.getAttribute(Port.RECEIVE_BUFFER_SIZE));
+ assertNull("Unexpected need client auth", port.getAttribute(Port.NEED_CLIENT_AUTH));
+ assertNull("Unexpected want client auth", port.getAttribute(Port.WANT_CLIENT_AUTH));
+ assertNull("Unexpected tcp no delay", port.getAttribute(Port.TCP_NO_DELAY));
+ assertNull("Unexpected binding", port.getAttribute(Port.BINDING_ADDRESS));
+ }
+
+ public void testCreateNonAmqpPortWithPartiallySetAttributes()
+ {
+ Set<Protocol> nonAmqpProtocolSet = Collections.singleton(Protocol.JMX_RMI);
+ Set<String> nonAmqpStringSet = Collections.singleton(Protocol.JMX_RMI.name());
+ _attributes = new HashMap<String, Object>();
+ _attributes.put(Port.PROTOCOLS, nonAmqpStringSet);
+ _attributes.put(Port.PORT, _portNumber);
+
+ Port port = _portFactory.createPort(_portId, _broker, _attributes);
+
+ assertNotNull(port);
+ assertFalse("Port should be a PortAdapter, not its AMQP-specific subclass", port instanceof AmqpPortAdapter);
+ assertEquals(_portId, port.getId());
+ assertEquals(_portNumber, port.getPort());
+ assertEquals(Collections.singleton(PortFactory.DEFAULT_TRANSPORT), port.getTransports());
+ assertEquals(nonAmqpProtocolSet, port.getProtocols());
+ assertNull("Unexpected send buffer size", port.getAttribute(Port.SEND_BUFFER_SIZE));
+ assertNull("Unexpected receive buffer size", port.getAttribute(Port.RECEIVE_BUFFER_SIZE));
+ assertNull("Unexpected need client auth", port.getAttribute(Port.NEED_CLIENT_AUTH));
+ assertNull("Unexpected want client auth", port.getAttribute(Port.WANT_CLIENT_AUTH));
+ assertNull("Unexpected tcp no delay", port.getAttribute(Port.TCP_NO_DELAY));
+ assertNull("Unexpected binding", port.getAttribute(Port.BINDING_ADDRESS));
+ }
+
+ public void testCreateMixedAmqpAndNonAmqpThrowsException()
+ {
+ Set<String> mixedProtocolSet = new HashSet<String>(Arrays.asList(Protocol.AMQP_0_10.name(), Protocol.JMX_RMI.name()));
+ _attributes.put(Port.PROTOCOLS, mixedProtocolSet);
+
+ try
+ {
+ _portFactory.createPort(_portId, _broker, _attributes);
+ fail("Exception not thrown");
+ }
+ catch (IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java b/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java
new file mode 100644
index 0000000000..dd48d7b56d
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java
@@ -0,0 +1,129 @@
+/*
+ *
+ * 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.model.configuration;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
+
+public class ConfigurationEntryTest extends TestCase
+{
+ public void testGetChildren()
+ {
+ ConfigurationEntryStore store = mock(ConfigurationEntryStore.class);
+
+ ConfigurationEntry virtualHostEntry1 = new ConfigurationEntry(UUID.randomUUID(), VirtualHost.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), store);
+ ConfigurationEntry virtualHostEntry2 = new ConfigurationEntry(UUID.randomUUID(), VirtualHost.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), store);
+ ConfigurationEntry portEntry = new ConfigurationEntry(UUID.randomUUID(), Port.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), store);
+
+ when(store.getEntry(virtualHostEntry1.getId())).thenReturn(virtualHostEntry1);
+ when(store.getEntry(virtualHostEntry2.getId())).thenReturn(virtualHostEntry2);
+ when(store.getEntry(portEntry.getId())).thenReturn(portEntry);
+
+ Set<UUID> childrenIds = new HashSet<UUID>();
+ childrenIds.add(virtualHostEntry1.getId());
+ childrenIds.add(virtualHostEntry2.getId());
+ childrenIds.add(portEntry.getId());
+ ConfigurationEntry parentEntry = new ConfigurationEntry(UUID.randomUUID(), Broker.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), childrenIds, store);
+
+ Map<String, Collection<ConfigurationEntry>> children = parentEntry.getChildren();
+ assertNotNull("Null is returned for children", children);
+ assertEquals("Unexpected size", 2, children.size());
+ Collection<ConfigurationEntry> virtualHosts = children.get(VirtualHost.class.getSimpleName());
+ Collection<ConfigurationEntry> ports = children.get(Port.class.getSimpleName());
+ assertEquals("Unexpected virtual hosts",
+ new HashSet<ConfigurationEntry>(Arrays.asList(virtualHostEntry1, virtualHostEntry2)),
+ new HashSet<ConfigurationEntry>(virtualHosts));
+ assertEquals("Unexpected ports", new HashSet<ConfigurationEntry>(Arrays.asList(portEntry)),
+ new HashSet<ConfigurationEntry>(ports));
+ }
+
+ public void testHashCode()
+ {
+ ConfigurationEntryStore store = mock(ConfigurationEntryStore.class);
+
+ UUID id = UUID.randomUUID();
+ ConfigurationEntry entry1 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
+ ConfigurationEntry entry2 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(),
+ Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
+ ConfigurationEntry entryWithDifferentId = new ConfigurationEntry(UUID.randomUUID(),
+ VirtualHost.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
+
+ assertTrue(entry1.hashCode() == entry2.hashCode());
+ assertFalse(entry1.hashCode() == entryWithDifferentId.hashCode());
+ }
+
+ public void testEqualsObject()
+ {
+ ConfigurationEntryStore store = mock(ConfigurationEntryStore.class);
+
+ UUID id = UUID.randomUUID();
+ Map<String, Object> attributes1 = new HashMap<String, Object>();
+ attributes1.put(VirtualHost.NAME, "name1");
+ Set<UUID> childrenIds = Collections.singleton(UUID.randomUUID());
+ ConfigurationEntry entry1 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(), attributes1,
+ childrenIds, store);
+
+ Map<String, Object> attributes2 = new HashMap<String, Object>();
+ attributes2.put(VirtualHost.NAME, "name2");
+
+ ConfigurationEntry entry2 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(), attributes1,
+ childrenIds, store);
+ ConfigurationEntry entryWithDifferentId = new ConfigurationEntry(UUID.randomUUID(),
+ VirtualHost.class.getSimpleName(), attributes1, childrenIds, store);
+
+ assertTrue(entry1.equals(entry2));
+ assertFalse("Entries should be diferrent because of diferrent IDs", entry1.equals(entryWithDifferentId));
+
+ ConfigurationEntry entryWithDifferentChildId = new ConfigurationEntry(id,
+ VirtualHost.class.getSimpleName(), attributes1, Collections.singleton(UUID.randomUUID()), store);
+ assertFalse("Entries should be diferrent because of diferrent children", entry1.equals(entryWithDifferentChildId));
+
+ ConfigurationEntry entryWithDifferentName = new ConfigurationEntry(id,
+ VirtualHost.class.getSimpleName(), attributes2, childrenIds, store);
+ assertFalse("Entries should be diferrent because of diferrent attributes", entry1.equals(entryWithDifferentName));
+
+ ConfigurationEntry entryWithDifferentType = new ConfigurationEntry(id,
+ Broker.class.getSimpleName(), attributes1, childrenIds, store);
+ assertFalse("Entries should be diferrent because of diferrent types", entry1.equals(entryWithDifferentType));
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java b/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java
deleted file mode 100644
index 20abdd48cd..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java
+++ /dev/null
@@ -1,94 +0,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.
- *
- */
-package org.apache.qpid.server.plugins;
-
-import org.osgi.framework.Version;
-
-import org.apache.qpid.test.utils.QpidTestCase;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- *
- */
-public class OsgiSystemPackageUtilTest extends QpidTestCase
-{
- private OsgiSystemPackageUtil _util = null; // Object under test
-
- private Map<String, String> _map = new TreeMap<String, String>(); // Use a TreeMap for unit test in order for determinstic results.
-
- public void testWithOnePackage() throws Exception
- {
- _map.put("org.xyz", "1.0.0");
-
- _util = new OsgiSystemPackageUtil(null, _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertEquals("org.xyz; version=1.0.0", systemPackageString);
- }
-
- public void testWithTwoPackages() throws Exception
- {
- _map.put("org.xyz", "1.0.0");
- _map.put("org.abc", "1.2.3");
-
- _util = new OsgiSystemPackageUtil(null, _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertEquals("org.abc; version=1.2.3, org.xyz; version=1.0.0", systemPackageString);
- }
-
- public void testWithNoPackages() throws Exception
- {
- _util = new OsgiSystemPackageUtil(null, _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertNull(systemPackageString);
- }
-
- public void testWithQpidPackageWithQpidReleaseNumberSet() throws Exception
- {
- _map.put("org.apache.qpid.xyz", "1.0.0");
- _map.put("org.abc", "1.2.3");
-
- _util = new OsgiSystemPackageUtil(new Version("0.19"), _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=0.19.0", systemPackageString);
- }
-
- public void testWithQpidPackageWithoutQpidReleaseNumberSet() throws Exception
- {
- _map.put("org.apache.qpid.xyz", "1.0.0");
- _map.put("org.abc", "1.2.3");
-
- _util = new OsgiSystemPackageUtil(null, _map);
-
- final String systemPackageString = _util.getFormattedSystemPackageString();
-
- assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=1.0.0", systemPackageString);
- }
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java b/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java
deleted file mode 100644
index b4bda9a032..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java
+++ /dev/null
@@ -1,55 +0,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.
- */
-package org.apache.qpid.server.plugins;
-
-import org.apache.qpid.server.exchange.ExchangeType;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-import java.util.Map;
-
-public class PluginTest extends InternalBrokerBaseCase
-{
- private static final String TEST_EXCHANGE_CLASS = "org.apache.qpid.extras.exchanges.example.TestExchangeType";
-
- private static final String PLUGIN_DIRECTORY = System.getProperty("example.plugin.target");
- private static final String CACHE_DIRECTORY = System.getProperty("example.cache.target");
-
- @Override
- public void configure()
- {
- getConfiguration().getConfig().addProperty("plugin-directory", PLUGIN_DIRECTORY);
- getConfiguration().getConfig().addProperty("cache-directory", CACHE_DIRECTORY);
- }
-
- public void disabled_testLoadExchanges() throws Exception
- {
- PluginManager manager = getRegistry().getPluginManager();
- Map<String, ExchangeType<?>> exchanges = manager.getExchanges();
- assertNotNull("No exchanges found in " + PLUGIN_DIRECTORY, exchanges);
- assertEquals("Wrong number of exchanges found in " + PLUGIN_DIRECTORY, 2, exchanges.size());
- assertNotNull("Wrong exchange found in " + PLUGIN_DIRECTORY, exchanges.get(TEST_EXCHANGE_CLASS));
- }
-
- public void testNoExchanges() throws Exception
- {
- PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp", null);
- Map<String, ExchangeType<?>> exchanges = manager.getExchanges();
- assertTrue("Exchanges found", exchanges.isEmpty());
- }
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java b/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java
index 96c67941f9..3216f8886a 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java
@@ -28,10 +28,11 @@ import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageContentSource;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.output.ProtocolOutputConverter;
import org.apache.qpid.server.queue.QueueEntry;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import org.apache.qpid.server.subscription.ClientDeliveryMethod;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.subscription.SubscriptionImpl;
@@ -39,6 +40,8 @@ import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.transport.TestNetworkConnection;
import javax.security.auth.Subject;
+
+import java.security.Principal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -55,19 +58,28 @@ public class InternalTestProtocolSession extends AMQProtocolEngine implements Pr
private AtomicInteger _deliveryCount = new AtomicInteger(0);
private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
- public InternalTestProtocolSession(VirtualHost virtualHost) throws AMQException
+ public InternalTestProtocolSession(VirtualHost virtualHost, Broker broker) throws AMQException
{
- super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkConnection(), ID_GENERATOR.getAndIncrement());
+ super(broker, new TestNetworkConnection(), ID_GENERATOR.getAndIncrement());
_channelDelivers = new HashMap<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>>();
- // Need to authenticate session for it to be representative testing.
- setAuthorizedSubject(new Subject(true, Collections.singleton(new UsernamePrincipal("InternalTestProtocolSession")),
- Collections.EMPTY_SET, Collections.EMPTY_SET));
-
+ setTestAuthorizedSubject();
setVirtualHost(virtualHost);
}
+ private void setTestAuthorizedSubject()
+ {
+ Principal principal = new AuthenticatedPrincipal(new UsernamePrincipal("InternalTestProtocolSession"));
+ Subject authorizedSubject = new Subject(
+ true,
+ Collections.singleton(principal),
+ Collections.emptySet(),
+ Collections.emptySet());
+
+ setAuthorizedSubject(authorizedSubject);
+ }
+
public ProtocolOutputConverter getProtocolOutputConverter()
{
return this;
diff --git a/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java b/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java
index e8ee2c4d0b..99dd42e179 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java
@@ -23,20 +23,24 @@ package org.apache.qpid.server.protocol;
import org.apache.qpid.AMQException;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
/** Test class to test MBean operations for AMQMinaProtocolSession. */
-public class MaxChannelsTest extends InternalBrokerBaseCase
+public class MaxChannelsTest extends QpidTestCase
{
- private AMQProtocolEngine _session;
+ private AMQProtocolEngine _session;
- public void testChannels() throws Exception
+ @Override
+ public void setUp() throws Exception
{
- VirtualHost vhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
- _session = new InternalTestProtocolSession(vhost);
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _session = BrokerTestHelper.createSession();
+ }
+ public void testChannels() throws Exception
+ {
// check the channel count is correct
int channelCount = _session.getChannels().size();
assertEquals("Initial channel count wrong", 0, channelCount);
@@ -45,13 +49,15 @@ public class MaxChannelsTest extends InternalBrokerBaseCase
_session.setMaximumNumberOfChannels(maxChannels);
assertEquals("Number of channels not correctly set.", new Long(maxChannels), _session.getMaximumNumberOfChannels());
+ for (long currentChannel = 0L; currentChannel < maxChannels; currentChannel++)
+ {
+ _session.addChannel(new AMQChannel(_session, (int) currentChannel, null));
+ }
try
{
- for (long currentChannel = 0L; currentChannel < maxChannels; currentChannel++)
- {
- _session.addChannel(new AMQChannel(_session, (int) currentChannel, null));
- }
+ _session.addChannel(new AMQChannel(_session, (int) maxChannels, null));
+ fail("Cannot create more channels then maximum");
}
catch (AMQException e)
{
@@ -63,14 +69,14 @@ public class MaxChannelsTest extends InternalBrokerBaseCase
@Override
public void tearDown() throws Exception
{
- try {
- _session.closeSession();
- } catch (AMQException e) {
- // Yikes
- fail(e.getMessage());
- }
+ try
+ {
+ _session.getVirtualHost().close();
+ _session.closeSession();
+ }
finally
{
+ BrokerTestHelper.tearDown();
super.tearDown();
}
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java
index 6081be8efd..02b8c74feb 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java
@@ -20,36 +20,52 @@
*/
package org.apache.qpid.server.protocol;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
-import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.transport.TestNetworkConnection;
+import static org.mockito.Mockito.when;
import java.nio.ByteBuffer;
import java.util.EnumSet;
import java.util.Set;
+import org.apache.qpid.protocol.ServerProtocolEngine;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.transport.TestNetworkConnection;
+
public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
{
+ private VirtualHost _virtualHost;
+ private Broker _broker;
+ @Override
protected void setUp() throws Exception
{
super.setUp();
+ BrokerTestHelper.setUp();
+ _broker = BrokerTestHelper.createBrokerMock();
+ VirtualHostRegistry virtualHostRegistry = _broker.getVirtualHostRegistry();
+ when(_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST)).thenReturn("default");
- //the factory needs a registry instance
- ApplicationRegistry.initialise(new TestApplicationRegistry(new ServerConfiguration(new XMLConfiguration())));
+ // AMQP 1-0 connection needs default vhost to be present
+ _virtualHost = BrokerTestHelper.createVirtualHost("default", virtualHostRegistry);
}
- protected void tearDown()
+ @Override
+ protected void tearDown() throws Exception
{
- //the factory opens a registry instance
- ApplicationRegistry.remove();
+ try
+ {
+ _virtualHost.close();
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
-
+
private static final byte[] AMQP_0_8_HEADER =
new byte[] { (byte) 'A',
(byte) 'M',
@@ -108,6 +124,7 @@ public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
(byte) 0
};
+
private byte[] getAmqpHeader(final AmqpProtocolVersion version)
{
switch(version)
@@ -137,7 +154,7 @@ public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
Set<AmqpProtocolVersion> versions = EnumSet.allOf(AmqpProtocolVersion.class);
MultiVersionProtocolEngineFactory factory =
- new MultiVersionProtocolEngineFactory(versions, null);
+ new MultiVersionProtocolEngineFactory(_broker, versions, null);
//create a dummy to retrieve the 'current' ID number
long previousId = factory.newProtocolEngine().getConnectionId();
@@ -160,6 +177,7 @@ public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
assertEquals("ID was not as expected following receipt of the AMQP version header", expectedID, engine.getConnectionId());
previousId = expectedID;
+ engine.closed();
}
}
@@ -174,7 +192,7 @@ public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
try
{
- new MultiVersionProtocolEngineFactory(versions, AmqpProtocolVersion.v0_9);
+ new MultiVersionProtocolEngineFactory(_broker, versions, AmqpProtocolVersion.v0_9);
fail("should not have been allowed to create the factory");
}
catch(IllegalArgumentException iae)
diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java
index c3d58f3bdc..81ad57c040 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java
@@ -36,8 +36,9 @@ public class AMQPriorityQueueTest extends SimpleAMQQueueTest
@Override
public void setUp() throws Exception
{
- _arguments = new FieldTable();
- _arguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 3);
+ FieldTable arguments = new FieldTable();
+ arguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 3);
+ setArguments(arguments);
super.setUp();
}
@@ -45,25 +46,26 @@ public class AMQPriorityQueueTest extends SimpleAMQQueueTest
{
// Enqueue messages in order
- _queue.enqueue(createMessage(1L, (byte) 10));
- _queue.enqueue(createMessage(2L, (byte) 4));
- _queue.enqueue(createMessage(3L, (byte) 0));
+ SimpleAMQQueue queue = getQueue();
+ queue.enqueue(createMessage(1L, (byte) 10));
+ queue.enqueue(createMessage(2L, (byte) 4));
+ queue.enqueue(createMessage(3L, (byte) 0));
// Enqueue messages in reverse order
- _queue.enqueue(createMessage(4L, (byte) 0));
- _queue.enqueue(createMessage(5L, (byte) 4));
- _queue.enqueue(createMessage(6L, (byte) 10));
+ queue.enqueue(createMessage(4L, (byte) 0));
+ queue.enqueue(createMessage(5L, (byte) 4));
+ queue.enqueue(createMessage(6L, (byte) 10));
// Enqueue messages out of order
- _queue.enqueue(createMessage(7L, (byte) 4));
- _queue.enqueue(createMessage(8L, (byte) 10));
- _queue.enqueue(createMessage(9L, (byte) 0));
+ queue.enqueue(createMessage(7L, (byte) 4));
+ queue.enqueue(createMessage(8L, (byte) 10));
+ queue.enqueue(createMessage(9L, (byte) 0));
// Register subscriber
- _queue.registerSubscription(_subscription, false);
+ queue.registerSubscription(getSubscription(), false);
Thread.sleep(150);
- ArrayList<QueueEntry> msgs = _subscription.getMessages();
+ ArrayList<QueueEntry> msgs = getSubscription().getMessages();
try
{
assertEquals(1L, msgs.get(0).getMessage().getMessageNumber());
diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
index 186be4dff7..0f82345271 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
@@ -20,23 +20,23 @@
*/
package org.apache.qpid.server.queue;
+import static org.mockito.Mockito.when;
+
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.qpid.AMQException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DefaultExchangeFactory;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.logging.SystemOutMessageLogger;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.test.utils.QpidTestCase;
@@ -50,19 +50,19 @@ public class AMQQueueFactoryTest extends QpidTestCase
{
super.setUp();
- CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
-
+ BrokerTestHelper.setUp();
XMLConfiguration configXml = new XMLConfiguration();
- configXml.addProperty("virtualhosts.virtualhost(-1).name", getName());
- configXml.addProperty("virtualhosts.virtualhost(-1)."+getName()+".store.class", TestableMemoryMessageStore.class.getName());
+ configXml.addProperty("store.class", TestableMemoryMessageStore.class.getName());
- ServerConfiguration configuration = new ServerConfiguration(configXml);
- ApplicationRegistry registry = new TestApplicationRegistry(configuration);
- ApplicationRegistry.initialise(registry);
- registry.getVirtualHostRegistry().setDefaultVirtualHostName(getName());
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ if (getName().equals("testDeadLetterQueueDoesNotInheritDLQorMDCSettings"))
+ {
+ when(broker.getAttribute(Broker.MAXIMUM_DELIVERY_ATTEMPTS)).thenReturn(5);
+ when(broker.getAttribute(Broker.DEAD_LETTER_QUEUE_ENABLED)).thenReturn(true);
+ }
- _virtualHost = registry.getVirtualHostRegistry().getVirtualHost(getName());
+ _virtualHost = BrokerTestHelper.createVirtualHost(new VirtualHostConfiguration(getName(), configXml, broker));
_queueRegistry = _virtualHost.getQueueRegistry();
@@ -73,11 +73,12 @@ public class AMQQueueFactoryTest extends QpidTestCase
{
try
{
- super.tearDown();
+ _virtualHost.close();
}
finally
{
- ApplicationRegistry.remove();
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
}
@@ -172,11 +173,8 @@ public class AMQQueueFactoryTest extends QpidTestCase
* are not applied to the DLQ itself.
* @throws AMQException
*/
- public void testDeadLetterQueueDoesNotInheritDLQorMDCSettings() throws AMQException
+ public void testDeadLetterQueueDoesNotInheritDLQorMDCSettings() throws Exception
{
- ApplicationRegistry.getInstance().getConfiguration().getConfig().addProperty("deadLetterQueues","true");
- ApplicationRegistry.getInstance().getConfiguration().getConfig().addProperty("maximumDeliveryCount","5");
-
String queueName = "testDeadLetterQueueEnabled";
AMQShortString dlExchangeName = new AMQShortString(queueName + DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
AMQShortString dlQueueName = new AMQShortString(queueName + AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
@@ -336,11 +334,8 @@ public class AMQQueueFactoryTest extends QpidTestCase
try
{
// change DLQ name to make its length bigger than exchange name
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", "_DLE");
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", "_DLQUEUE");
-
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, "_DLE");
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, "_DLQUEUE");
FieldTable fieldTable = new FieldTable();
fieldTable.setBoolean(AMQQueueFactory.X_QPID_DLQ_ENABLED, true);
AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), queueName, false, "owner",
@@ -353,13 +348,6 @@ public class AMQQueueFactoryTest extends QpidTestCase
assertTrue("Unexpected exception message!", e.getMessage().contains("DLQ queue name")
&& e.getMessage().contains("length exceeds limit of 255"));
}
- finally
- {
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
- }
}
/**
@@ -372,11 +360,8 @@ public class AMQQueueFactoryTest extends QpidTestCase
try
{
// change DLQ name to make its length bigger than exchange name
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", "_DLEXCHANGE");
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", "_DLQ");
-
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, "_DLEXCHANGE");
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, "_DLQ");
FieldTable fieldTable = new FieldTable();
fieldTable.setBoolean(AMQQueueFactory.X_QPID_DLQ_ENABLED, true);
AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), queueName, false, "owner",
@@ -389,13 +374,6 @@ public class AMQQueueFactoryTest extends QpidTestCase
assertTrue("Unexpected exception message!", e.getMessage().contains("DL exchange name")
&& e.getMessage().contains("length exceeds limit of 255"));
}
- finally
- {
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
- }
}
private String generateStringWithLength(char ch, int length)
diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java
index 190d5c777b..cbbf183232 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java
@@ -32,18 +32,16 @@ import org.apache.qpid.server.flow.LimitlessCreditManager;
import org.apache.qpid.server.flow.Pre0_10CreditManager;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
-import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.subscription.SubscriptionFactoryImpl;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.ArrayList;
import java.util.Set;
@@ -51,7 +49,7 @@ import java.util.Set;
/**
* Tests that acknowledgements are handled correctly.
*/
-public class AckTest extends InternalBrokerBaseCase
+public class AckTest extends QpidTestCase
{
private Subscription _subscription;
@@ -70,15 +68,19 @@ public class AckTest extends InternalBrokerBaseCase
public void setUp() throws Exception
{
super.setUp();
- _virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
- _messageStore = new TestableMemoryMessageStore();
- _protocolSession = new InternalTestProtocolSession(_virtualHost);
- _channel = new AMQChannel(_protocolSession,5, _messageStore /*dont need exchange registry*/);
-
- _protocolSession.addChannel(_channel);
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel(5);
+ _protocolSession = _channel.getProtocolSession();
+ _virtualHost = _protocolSession.getVirtualHost();
+ _queue = BrokerTestHelper.createQueue(getTestName(), _virtualHost);
+ _messageStore = (TestableMemoryMessageStore)_virtualHost.getMessageStore();
+ }
- _queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "myQ", false, "guest", true, false,
- _virtualHost, null);
+ @Override
+ protected void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
private void publishMessages(int count) throws AMQException
diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/InboundMessageAdapterTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/InboundMessageAdapterTest.java
new file mode 100644
index 0000000000..2f160678ba
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/queue/InboundMessageAdapterTest.java
@@ -0,0 +1,97 @@
+/*
+ *
+ * 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.queue;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.message.AMQMessageHeader;
+import org.apache.qpid.server.message.ServerMessage;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class InboundMessageAdapterTest extends QpidTestCase
+{
+ private ServerMessage<?> _mockMessage;
+ private QueueEntry _mockQueueEntry;
+ private InboundMessageAdapter _inboundMessageAdapter;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _mockMessage = mock(ServerMessage.class);
+ _mockQueueEntry = mock(QueueEntry.class);
+ when(_mockQueueEntry.getMessage()).thenReturn(_mockMessage);
+
+ _inboundMessageAdapter = new InboundMessageAdapter(_mockQueueEntry);
+ }
+
+ public void testGetRoutingKey() throws Exception
+ {
+ String routingKey = getTestName();
+ when(_mockMessage.getRoutingKey()).thenReturn(routingKey);
+
+ assertEquals("Unexpected value for routing key", routingKey, _inboundMessageAdapter.getRoutingKey());
+ }
+
+ public void testGetRoutingKeyShortString() throws Exception
+ {
+ String routingKey = getTestName();
+ when(_mockMessage.getRoutingKey()).thenReturn(routingKey);
+
+ AMQShortString routingKeyShortString = AMQShortString.valueOf(routingKey);
+ assertEquals("Unexpected value for routing key short string", routingKeyShortString, _inboundMessageAdapter.getRoutingKeyShortString());
+ }
+
+ public void testGetMessageHeader() throws Exception
+ {
+ AMQMessageHeader mockMessageHeader = mock(AMQMessageHeader.class);
+ when(_mockQueueEntry.getMessageHeader()).thenReturn(mockMessageHeader);
+
+ assertSame("unexpected message header", mockMessageHeader, _inboundMessageAdapter.getMessageHeader());
+ }
+
+ public void testIsRedelivered() throws Exception
+ {
+ when(_mockQueueEntry.isRedelivered()).thenReturn(true);
+ assertTrue("unexpected isRedelivered value", _inboundMessageAdapter.isRedelivered());
+
+ when(_mockQueueEntry.isRedelivered()).thenReturn(false);
+ assertFalse("unexpected isRedelivered value", _inboundMessageAdapter.isRedelivered());
+ }
+
+ public void testIsPersistent() throws Exception
+ {
+ when(_mockQueueEntry.isPersistent()).thenReturn(true);
+ assertTrue("unexpected isPersistent value", _inboundMessageAdapter.isPersistent());
+
+ when(_mockQueueEntry.isPersistent()).thenReturn(false);
+ assertFalse("unexpected isPersistent value", _inboundMessageAdapter.isPersistent());
+ }
+
+ public void testGetSize() throws Exception
+ {
+ long size = 32526215;
+ when(_mockQueueEntry.getSize()).thenReturn(size);
+ assertEquals("unexpected getSize value", size, _inboundMessageAdapter.getSize());
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java b/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
index bcb8d54636..358246330a 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
@@ -23,10 +23,8 @@ package org.apache.qpid.server.queue;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.QueueConfigType;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+import org.apache.qpid.server.configuration.QueueConfiguration;
+import org.apache.qpid.server.configuration.plugins.AbstractConfiguration;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.message.ServerMessage;
@@ -106,11 +104,6 @@ public class MockAMQQueue implements AMQQueue
return 0;
}
- public ConfigStore getConfigStore()
- {
- return getVirtualHost().getConfigStore();
- }
-
public long getMessageDequeueCount()
{
return 0;
@@ -186,22 +179,6 @@ public class MockAMQQueue implements AMQQueue
return null;
}
- @Override
- public UUID getQMFId()
- {
- return null;
- }
-
- public QueueConfigType getConfigType()
- {
- return null;
- }
-
- public ConfiguredObject getParent()
- {
- return null;
- }
-
public boolean isDurable()
{
return false;
@@ -532,16 +509,11 @@ public class MockAMQQueue implements AMQQueue
}
- public void configure(ConfigurationPlugin config)
+ public void configure(QueueConfiguration config)
{
}
- public ConfigurationPlugin getConfiguration()
- {
- return null;
- }
-
public AuthorizationHolder getAuthorizationHolder()
{
return _authorizationHolder;
diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
index 2cd423d4c9..ece42f7de3 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
@@ -28,8 +28,6 @@ import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Matchers.contains;
import static org.mockito.Matchers.eq;
-import org.apache.commons.configuration.PropertiesConfiguration;
-
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQInternalException;
import org.apache.qpid.AMQSecurityException;
@@ -39,7 +37,6 @@ import org.apache.qpid.framing.BasicContentHeaderProperties;
import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.abstraction.MessagePublishInfo;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DirectExchange;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
@@ -47,16 +44,15 @@ import org.apache.qpid.server.message.ServerMessage;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.queue.BaseQueue.PostEnqueueAction;
import org.apache.qpid.server.queue.SimpleAMQQueue.QueueEntryFilter;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
import org.apache.qpid.server.subscription.MockSubscription;
import org.apache.qpid.server.subscription.Subscription;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostImpl;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.ArrayList;
import java.util.Collections;
@@ -64,17 +60,17 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-public class SimpleAMQQueueTest extends InternalBrokerBaseCase
+public class SimpleAMQQueueTest extends QpidTestCase
{
- protected SimpleAMQQueue _queue;
- protected VirtualHost _virtualHost;
- protected AMQShortString _qname = new AMQShortString("qname");
- protected AMQShortString _owner = new AMQShortString("owner");
- protected AMQShortString _routingKey = new AMQShortString("routing key");
- protected DirectExchange _exchange;
- protected MockSubscription _subscription = new MockSubscription();
- protected FieldTable _arguments = null;
+ private SimpleAMQQueue _queue;
+ private VirtualHost _virtualHost;
+ private AMQShortString _qname = new AMQShortString("qname");
+ private AMQShortString _owner = new AMQShortString("owner");
+ private AMQShortString _routingKey = new AMQShortString("routing key");
+ private DirectExchange _exchange;
+ private MockSubscription _subscription = new MockSubscription();
+ private FieldTable _arguments = null;
private MessagePublishInfo info = new MessagePublishInfo()
{
@@ -108,25 +104,29 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase
public void setUp() throws Exception
{
super.setUp();
- //Create Application Registry for test
- ApplicationRegistry applicationRegistry = (ApplicationRegistry)ApplicationRegistry.getInstance();
+ BrokerTestHelper.setUp();
- PropertiesConfiguration env = new PropertiesConfiguration();
- final VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(getClass().getName(), env);
- vhostConfig.setMessageStoreClass(TestableMemoryMessageStore.class.getName());
- _virtualHost = new VirtualHostImpl(ApplicationRegistry.getInstance(), vhostConfig);
- applicationRegistry.getVirtualHostRegistry().registerVirtualHost(_virtualHost);
+ _virtualHost = BrokerTestHelper.createVirtualHost(getClass().getName());
- _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), _qname.asString(), false, _owner.asString(), false, false, _virtualHost, FieldTable.convertToMap(_arguments));
+ _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), _qname.asString(), false, _owner.asString(),
+ false, false, _virtualHost, FieldTable.convertToMap(_arguments));
- _exchange = (DirectExchange)_virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME);
+ _exchange = (DirectExchange) _virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME);
}
@Override
public void tearDown() throws Exception
{
- _queue.stop();
- super.tearDown();
+ try
+ {
+ _queue.stop();
+ _virtualHost.close();
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testCreateQueue() throws AMQException
@@ -659,7 +659,7 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase
public void onRollback()
{
}
- }, 0L);
+ });
// Check that it is enqueued
AMQQueue data = store.getMessages().get(1L);
@@ -1269,6 +1269,26 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase
}
}
+ public SimpleAMQQueue getQueue()
+ {
+ return _queue;
+ }
+
+ public MockSubscription getSubscription()
+ {
+ return _subscription;
+ }
+
+ public FieldTable getArguments()
+ {
+ return _arguments;
+ }
+
+ public void setArguments(FieldTable arguments)
+ {
+ _arguments = arguments;
+ }
+
public class TestMessage extends AMQMessage
{
private final long _tag;
diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java
index 6b82cd361a..4abb7233dc 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java
@@ -20,20 +20,33 @@
*/
package org.apache.qpid.server.queue;
-import org.apache.qpid.AMQException;
import org.apache.qpid.pool.ReferenceCountingExecutorService;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class SimpleAMQQueueThreadPoolTest extends InternalBrokerBaseCase
+public class SimpleAMQQueueThreadPoolTest extends QpidTestCase
{
- public void test() throws AMQException
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+
+ public void test() throws Exception
{
int initialCount = ReferenceCountingExecutorService.getInstance().getReferenceCount();
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
+ VirtualHost test = BrokerTestHelper.createVirtualHost("test");
try
{
@@ -50,7 +63,7 @@ public class SimpleAMQQueueThreadPoolTest extends InternalBrokerBaseCase
}
finally
{
- ApplicationRegistry.remove();
+ test.close();
}
}
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java b/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java
deleted file mode 100644
index 9af950d385..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java
+++ /dev/null
@@ -1,104 +0,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.
- *
- */
-package org.apache.qpid.server.registry;
-
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-import java.security.Provider;
-import java.security.Security;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * QPID-1390 : Test to validate that the AuthenticationManger can successfully unregister any new SASL providers when
- * The ApplicationRegistry is closed.
- *
- * This should be expanded as QPID-1399 is implemented.
- */
-public class ApplicationRegistryShutdownTest extends InternalBrokerBaseCase
-{
-
- private Provider[] _defaultProviders;
- @Override
- public void setUp() throws Exception
- {
- // Get default providers
- _defaultProviders = Security.getProviders();
-
- //Startup the new broker and register the new providers
- super.setUp();
- }
-
-
- /**
- * QPID-1399 : Ensure that the Authentication manager unregisters any SASL providers created during
- * ApplicationRegistry initialisation.
- *
- */
- public void testAuthenticationMangerCleansUp() throws Exception
- {
-
- // Get the providers after initialisation
- Provider[] providersAfterInitialisation = Security.getProviders();
-
- // Find the additions
- List additions = new LinkedList();
- for (Provider afterInit : providersAfterInitialisation)
- {
- boolean found = false;
- for (Provider defaultProvider : _defaultProviders)
- {
- if (defaultProvider == afterInit)
- {
- found=true;
- break;
- }
- }
-
- // Record added registies
- if (!found)
- {
- additions.add(afterInit);
- }
- }
-
- assertFalse("No new SASL mechanisms added by initialisation.", additions.isEmpty());
-
- //Close the registry which will perform the close the AuthenticationManager
- stopBroker();
-
- //Validate that the SASL plugFins have been removed.
- Provider[] providersAfterClose = Security.getProviders();
-
- assertTrue("No providers unregistered", providersAfterInitialisation.length > providersAfterClose.length);
-
- //Ensure that the additions are not still present after close().
- for (Provider afterClose : providersAfterClose)
- {
- assertFalse("Added provider not unregistered", additions.contains(afterClose));
- }
- }
-
-
-
-
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/SubjectCreatorTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/SubjectCreatorTest.java
new file mode 100644
index 0000000000..b1bc9bea68
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/SubjectCreatorTest.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.server.security;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.HashSet;
+
+import javax.security.auth.Subject;
+import javax.security.sasl.SaslServer;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
+import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
+
+public class SubjectCreatorTest extends TestCase
+{
+ private static final String USERNAME = "username";
+ private static final String PASSWORD = "password";
+
+ private AuthenticationManager _authenticationManager = mock(AuthenticationManager.class);
+ private GroupPrincipalAccessor _groupPrincipalAccessor = mock(GroupPrincipalAccessor.class);
+ private SubjectCreator _subjectCreator = new SubjectCreator(_authenticationManager, _groupPrincipalAccessor);
+
+ private Principal _userPrincipal = mock(Principal.class);
+ private Principal _group1 = mock(Principal.class);
+ private Principal _group2 = mock(Principal.class);
+
+ private AuthenticationResult _authenticationResult;
+ private SaslServer _testSaslServer = mock(SaslServer.class);
+ private byte[] _saslResponseBytes = PASSWORD.getBytes();
+
+ @Override
+ public void setUp()
+ {
+ _authenticationResult = new AuthenticationResult(_userPrincipal);
+ when(_authenticationManager.authenticate(USERNAME, PASSWORD)).thenReturn(_authenticationResult);
+
+ when(_groupPrincipalAccessor.getGroupPrincipals(USERNAME))
+ .thenReturn(new HashSet<Principal>(Arrays.asList(_group1, _group2)));
+ }
+
+ public void testAuthenticateUsernameAndPasswordReturnsSubjectWithUserAndGroupPrincipals()
+ {
+ final SubjectAuthenticationResult actualResult = _subjectCreator.authenticate(USERNAME, PASSWORD);
+
+ assertEquals(AuthenticationStatus.SUCCESS, actualResult.getStatus());
+
+ final Subject actualSubject = actualResult.getSubject();
+
+ assertEquals("Should contain one user principal and two groups ", 3, actualSubject.getPrincipals().size());
+
+ assertTrue(actualSubject.getPrincipals().contains(new AuthenticatedPrincipal(_userPrincipal)));
+ assertTrue(actualSubject.getPrincipals().contains(_group1));
+ assertTrue(actualSubject.getPrincipals().contains(_group2));
+
+ assertTrue(actualSubject.isReadOnly());
+ }
+
+ public void testSaslAuthenticationSuccessReturnsSubjectWithUserAndGroupPrincipals() throws Exception
+ {
+ when(_authenticationManager.authenticate(_testSaslServer, _saslResponseBytes)).thenReturn(_authenticationResult);
+ when(_testSaslServer.isComplete()).thenReturn(true);
+ when(_testSaslServer.getAuthorizationID()).thenReturn(USERNAME);
+
+ SubjectAuthenticationResult result = _subjectCreator.authenticate(_testSaslServer, _saslResponseBytes);
+
+ final Subject actualSubject = result.getSubject();
+ assertEquals("Should contain one user principal and two groups ", 3, actualSubject.getPrincipals().size());
+
+ assertTrue(actualSubject.getPrincipals().contains(new AuthenticatedPrincipal(_userPrincipal)));
+ assertTrue(actualSubject.getPrincipals().contains(_group1));
+ assertTrue(actualSubject.getPrincipals().contains(_group2));
+
+ assertTrue(actualSubject.isReadOnly());
+ }
+
+ public void testAuthenticateUnsuccessfulWithUsernameReturnsNullSubjectAndCorrectStatus()
+ {
+ testUnsuccessfulAuthentication(AuthenticationResult.AuthenticationStatus.CONTINUE);
+ testUnsuccessfulAuthentication(AuthenticationResult.AuthenticationStatus.ERROR);
+ }
+
+ private void testUnsuccessfulAuthentication(AuthenticationStatus expectedStatus)
+ {
+ AuthenticationResult failedAuthenticationResult = new AuthenticationResult(expectedStatus);
+
+ when(_authenticationManager.authenticate(USERNAME, PASSWORD)).thenReturn(failedAuthenticationResult);
+
+ SubjectAuthenticationResult subjectAuthenticationResult = _subjectCreator.authenticate(USERNAME, PASSWORD);
+
+ assertSame(expectedStatus, subjectAuthenticationResult.getStatus());
+ assertNull(subjectAuthenticationResult.getSubject());
+ }
+
+ public void testAuthenticateUnsuccessfulWithSaslServerReturnsNullSubjectAndCorrectStatus()
+ {
+ testUnsuccessfulAuthenticationWithSaslServer(AuthenticationResult.AuthenticationStatus.CONTINUE);
+ testUnsuccessfulAuthenticationWithSaslServer(AuthenticationResult.AuthenticationStatus.ERROR);
+ }
+
+ private void testUnsuccessfulAuthenticationWithSaslServer(AuthenticationStatus expectedStatus)
+ {
+ AuthenticationResult failedAuthenticationResult = new AuthenticationResult(expectedStatus);
+
+ when(_authenticationManager.authenticate(_testSaslServer, _saslResponseBytes)).thenReturn(failedAuthenticationResult);
+ when(_testSaslServer.isComplete()).thenReturn(false);
+
+ SubjectAuthenticationResult subjectAuthenticationResult = _subjectCreator.authenticate(_testSaslServer, _saslResponseBytes);
+
+ assertSame(expectedStatus, subjectAuthenticationResult.getStatus());
+ assertNull(subjectAuthenticationResult.getSubject());
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipalTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipalTest.java
new file mode 100644
index 0000000000..cd5791952f
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipalTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.security.auth;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
+
+import junit.framework.TestCase;
+
+public class AuthenticatedPrincipalTest extends TestCase
+{
+
+ private AuthenticatedPrincipal _authenticatedPrincipal = new AuthenticatedPrincipal(new UsernamePrincipal("name"));
+
+ public void testGetAuthenticatedPrincipalFromSubject()
+ {
+ final Subject subject = createSubjectContainingAuthenticatedPrincipal();
+ final AuthenticatedPrincipal actual = AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(subject);
+ assertSame(_authenticatedPrincipal, actual);
+ }
+
+ public void testAuthenticatedPrincipalNotInSubject()
+ {
+ try
+ {
+ AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(new Subject());
+ fail("Exception not thrown");
+ }
+ catch (IllegalArgumentException iae)
+ {
+ // PASS
+ }
+ }
+
+ public void testGetOptionalAuthenticatedPrincipalFromSubject()
+ {
+ final Subject subject = createSubjectContainingAuthenticatedPrincipal();
+ final AuthenticatedPrincipal actual = AuthenticatedPrincipal.getOptionalAuthenticatedPrincipalFromSubject(subject);
+ assertSame(_authenticatedPrincipal, actual);
+ }
+
+ public void testGetOptionalAuthenticatedPrincipalFromSubjectReturnsNullIfMissing()
+ {
+ Subject subjectWithNoPrincipals = new Subject();
+ assertNull(AuthenticatedPrincipal.getOptionalAuthenticatedPrincipalFromSubject(subjectWithNoPrincipals));
+
+ Subject subjectWithoutAuthenticatedPrincipal = new Subject();
+ subjectWithoutAuthenticatedPrincipal.getPrincipals().add(new UsernamePrincipal("name1"));
+ assertNull("Should return null for a subject containing a principal that isn't an AuthenticatedPrincipal",
+ AuthenticatedPrincipal.getOptionalAuthenticatedPrincipalFromSubject(subjectWithoutAuthenticatedPrincipal));
+ }
+
+ public void testTooManyAuthenticatedPrincipalsInSubject()
+ {
+ final Subject subject = new Subject();
+ subject.getPrincipals().add(new AuthenticatedPrincipal(new UsernamePrincipal("name1")));
+ subject.getPrincipals().add(new AuthenticatedPrincipal(new UsernamePrincipal("name2")));
+
+ try
+ {
+ AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(subject);
+ fail("Exception not thrown");
+ }
+ catch (IllegalArgumentException iae)
+ {
+ // PASS
+ }
+ }
+
+ private Subject createSubjectContainingAuthenticatedPrincipal()
+ {
+ final Principal other = new Principal()
+ {
+ public String getName()
+ {
+ return "otherprincipal";
+ }
+ };
+
+ final Subject subject = new Subject();
+ subject.getPrincipals().add(_authenticatedPrincipal);
+ subject.getPrincipals().add(other);
+ return subject;
+ }
+
+ public void testEqualsAndHashcode()
+ {
+ AuthenticatedPrincipal user1principal1 = new AuthenticatedPrincipal(new UsernamePrincipal("user1"));
+ AuthenticatedPrincipal user1principal2 = new AuthenticatedPrincipal(new UsernamePrincipal("user1"));
+
+ assertTrue(user1principal1.equals(user1principal1));
+ assertTrue(user1principal1.equals(user1principal2));
+ assertTrue(user1principal2.equals(user1principal1));
+
+ assertEquals(user1principal1.hashCode(), user1principal2.hashCode());
+ }
+
+ public void testEqualsAndHashcodeWithSameWrappedObject()
+ {
+ UsernamePrincipal wrappedPrincipal = new UsernamePrincipal("user1");
+ AuthenticatedPrincipal user1principal1 = new AuthenticatedPrincipal(wrappedPrincipal);
+ AuthenticatedPrincipal user1principal2 = new AuthenticatedPrincipal(wrappedPrincipal);
+
+ assertTrue(user1principal1.equals(user1principal1));
+ assertTrue(user1principal1.equals(user1principal2));
+ assertTrue(user1principal2.equals(user1principal1));
+
+ assertEquals(user1principal1.hashCode(), user1principal2.hashCode());
+ }
+
+ public void testEqualsWithDifferentUsernames()
+ {
+ AuthenticatedPrincipal user1principal1 = new AuthenticatedPrincipal(new UsernamePrincipal("user1"));
+ AuthenticatedPrincipal user1principal2 = new AuthenticatedPrincipal(new UsernamePrincipal("user2"));
+
+ assertFalse(user1principal1.equals(user1principal2));
+ assertFalse(user1principal2.equals(user1principal1));
+ }
+
+ public void testEqualsWithDisimilarObjects()
+ {
+ UsernamePrincipal wrappedPrincipal = new UsernamePrincipal("user1");
+ AuthenticatedPrincipal authenticatedPrincipal = new AuthenticatedPrincipal(wrappedPrincipal);
+
+ assertFalse(authenticatedPrincipal.equals(wrappedPrincipal));
+ assertFalse(wrappedPrincipal.equals(authenticatedPrincipal));
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipalTestHelper.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipalTestHelper.java
new file mode 100644
index 0000000000..e9d8d16fce
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticatedPrincipalTestHelper.java
@@ -0,0 +1,54 @@
+/*
+ * 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.security.auth;
+
+import java.security.Principal;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+/**
+ * Helper class for testing that sets of principals contain {@link AuthenticatedPrincipal}'s that wrap
+ * expected {@link Principal}'s.
+ */
+public class AuthenticatedPrincipalTestHelper
+{
+ public static void assertOnlyContainsWrapped(Principal wrappedPrincipal, Set<Principal> principals)
+ {
+ assertOnlyContainsWrappedAndSecondaryPrincipals(wrappedPrincipal, Collections.<Principal>emptySet(), principals);
+ }
+
+
+ public static void assertOnlyContainsWrappedAndSecondaryPrincipals(
+ Principal expectedWrappedPrincipal,
+ Set<Principal> expectedSecondaryPrincipals,
+ Set<Principal> actualPrincipals)
+ {
+ Assert.assertEquals("Principal set should contain one principal " + "but the principal set is: " + actualPrincipals,
+ 1 + expectedSecondaryPrincipals.size(),
+ actualPrincipals.size());
+
+ Set<Principal> expectedSet = new HashSet<Principal>(expectedSecondaryPrincipals);
+ expectedSet.add(new AuthenticatedPrincipal(expectedWrappedPrincipal));
+
+ Assert.assertEquals(expectedSet, actualPrincipals);
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticationResultTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticationResultTest.java
new file mode 100644
index 0000000000..a023cbdbb2
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/AuthenticationResultTest.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.server.security.auth;
+
+import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped;
+import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrappedAndSecondaryPrincipals;
+import static org.mockito.Mockito.mock;
+
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+public class AuthenticationResultTest extends TestCase
+{
+ public void testConstructWithAuthenticationStatusContinue()
+ {
+ AuthenticationResult authenticationResult = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.CONTINUE);
+ assertSame(AuthenticationResult.AuthenticationStatus.CONTINUE, authenticationResult.getStatus());
+ assertTrue(authenticationResult.getPrincipals().isEmpty());
+ }
+
+ public void testConstructWithAuthenticationStatusError()
+ {
+ AuthenticationResult authenticationResult = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR);
+ assertSame(AuthenticationResult.AuthenticationStatus.ERROR, authenticationResult.getStatus());
+ assertTrue(authenticationResult.getPrincipals().isEmpty());
+ }
+
+ public void testConstructWithAuthenticationStatusSuccessThrowsException()
+ {
+ try
+ {
+ new AuthenticationResult(AuthenticationResult.AuthenticationStatus.SUCCESS);
+ fail("Exception not thrown");
+ }
+ catch(IllegalArgumentException e)
+ {
+ // PASS
+ }
+ }
+
+ public void testConstructWithPrincipal()
+ {
+ Principal mainPrincipal = mock(Principal.class);
+ AuthenticationResult authenticationResult = new AuthenticationResult(mainPrincipal);
+
+ assertOnlyContainsWrapped(mainPrincipal, authenticationResult.getPrincipals());
+ assertSame(AuthenticationResult.AuthenticationStatus.SUCCESS, authenticationResult.getStatus());
+ }
+
+ public void testConstructWithNullPrincipalThrowsException()
+ {
+ try
+ {
+ new AuthenticationResult((Principal)null);
+ fail("Exception not thrown");
+ }
+ catch(IllegalArgumentException e)
+ {
+ // pass
+ }
+ }
+
+ public void testConstructWithSetOfPrincipals()
+ {
+ Principal mainPrincipal = mock(Principal.class);
+ Principal secondaryPrincipal = mock(Principal.class);
+ Set<Principal> secondaryPrincipals = Collections.singleton(secondaryPrincipal);
+
+ AuthenticationResult authenticationResult = new AuthenticationResult(mainPrincipal, secondaryPrincipals);
+
+ assertOnlyContainsWrappedAndSecondaryPrincipals(mainPrincipal, secondaryPrincipals, authenticationResult.getPrincipals());
+ assertSame(AuthenticationResult.AuthenticationStatus.SUCCESS, authenticationResult.getStatus());
+ }
+
+ public void testConstructWithSetOfPrincipalsDeDuplicatesMainPrincipal()
+ {
+ Principal mainPrincipal = mock(Principal.class);
+ Principal secondaryPrincipal = mock(Principal.class);
+
+ Set<Principal> secondaryPrincipalsContainingDuplicateOfMainPrincipal = new HashSet<Principal>(
+ Arrays.asList(secondaryPrincipal, mainPrincipal));
+ Set<Principal> deDuplicatedSecondaryPrincipals = Collections.singleton(secondaryPrincipal);
+
+ AuthenticationResult authenticationResult = new AuthenticationResult(
+ mainPrincipal, secondaryPrincipalsContainingDuplicateOfMainPrincipal);
+
+ assertOnlyContainsWrappedAndSecondaryPrincipals(mainPrincipal, deDuplicatedSecondaryPrincipals, authenticationResult.getPrincipals());
+
+ assertSame(AuthenticationResult.AuthenticationStatus.SUCCESS, authenticationResult.getStatus());
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/TestPrincipalUtils.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/TestPrincipalUtils.java
new file mode 100644
index 0000000000..ea6b40e3de
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/TestPrincipalUtils.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.server.security.auth;
+
+import javax.security.auth.Subject;
+
+import org.apache.qpid.server.security.group.GroupPrincipal;
+
+import java.security.Principal;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class TestPrincipalUtils
+{
+ /**
+ * Creates a test subject, with exactly one {@link AuthenticatedPrincipal} and zero or more GroupPrincipals.
+ */
+ public static Subject createTestSubject(final String username, final String... groups)
+ {
+ final Set<Principal> principals = new HashSet<Principal>(1 + groups.length);
+ principals.add(new AuthenticatedPrincipal(username));
+ for (String group : groups)
+ {
+ principals.add(new GroupPrincipal(group));
+ }
+
+ return new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/UsernamePrincipalTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/UsernamePrincipalTest.java
new file mode 100644
index 0000000000..5e025d3ca8
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/UsernamePrincipalTest.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.server.security.auth;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the UsernamePrincipal.
+ *
+ */
+public class UsernamePrincipalTest extends TestCase
+{
+ public void testEqualitySameObject()
+ {
+ final UsernamePrincipal principal = new UsernamePrincipal("string");
+ assertTrue(principal.equals(principal));
+ }
+
+ public void testEqualitySameName()
+ {
+ final String string = "string";
+ final UsernamePrincipal principal1 = new UsernamePrincipal(string);
+ final UsernamePrincipal principal2 = new UsernamePrincipal(string);
+ assertTrue(principal1.equals(principal2));
+ }
+
+ public void testEqualityEqualName()
+ {
+ final UsernamePrincipal principal1 = new UsernamePrincipal(new String("string"));
+ final UsernamePrincipal principal2 = new UsernamePrincipal(new String("string"));
+ assertTrue(principal1.equals(principal2));
+ }
+
+ public void testInequalityDifferentUserPrincipals()
+ {
+ UsernamePrincipal principal1 = new UsernamePrincipal("string1");
+ UsernamePrincipal principal2 = new UsernamePrincipal("string2");
+ assertFalse(principal1.equals(principal2));
+ }
+
+ public void testInequalityNonUserPrincipal()
+ {
+ UsernamePrincipal principal = new UsernamePrincipal("string");
+ assertFalse(principal.equals(new String("string")));
+ }
+
+ public void testInequalityNull()
+ {
+ UsernamePrincipal principal = new UsernamePrincipal("string");
+ assertFalse(principal.equals(null));
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java
index 33740af1e7..7b244e219e 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java
@@ -23,7 +23,7 @@ package org.apache.qpid.server.security.auth.database;
import junit.framework.TestCase;
import org.apache.commons.codec.binary.Base64;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.login.AccountNotFoundException;
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java
index b8601f0e5c..8e62324f7d 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java
@@ -22,7 +22,7 @@ package org.apache.qpid.server.security.auth.database;
import junit.framework.TestCase;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import javax.security.auth.login.AccountNotFoundException;
import java.io.BufferedReader;
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java
new file mode 100644
index 0000000000..f670d80ae8
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PropertiesPrincipalDatabase.java
@@ -0,0 +1,158 @@
+/*
+ * 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.security.auth.database;
+
+import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.sasl.crammd5.CRAMMD5Initialiser;
+import org.apache.qpid.server.security.auth.sasl.plain.PlainInitialiser;
+
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.login.AccountNotFoundException;
+import java.io.IOException;
+import java.security.Principal;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class PropertiesPrincipalDatabase implements PrincipalDatabase
+{
+ private Properties _users;
+
+ private Map<String, AuthenticationProviderInitialiser> _saslServers;
+
+ public PropertiesPrincipalDatabase(Properties users)
+ {
+ _users = users;
+
+ _saslServers = new HashMap<String, AuthenticationProviderInitialiser>();
+
+ /**
+ * Create Authenticators for Properties Principal Database.
+ */
+
+ // Accept MD5 incomming and use plain comparison with the file
+ PlainInitialiser cram = new PlainInitialiser();
+ cram.initialise(this);
+ // Accept Plain incomming and hash it for comparison to the file.
+ CRAMMD5Initialiser plain = new CRAMMD5Initialiser();
+ plain.initialise(this, CRAMMD5Initialiser.HashDirection.INCOMMING);
+
+ _saslServers.put(plain.getMechanismName(), cram);
+ _saslServers.put(cram.getMechanismName(), plain);
+ }
+
+ public void setPassword(Principal principal, PasswordCallback callback) throws IOException, AccountNotFoundException
+ {
+ if (principal == null)
+ {
+ throw new IllegalArgumentException("principal must not be null");
+ }
+
+
+
+ final String pwd = _users.getProperty(principal.getName());
+
+ if (pwd != null)
+ {
+ callback.setPassword(pwd.toCharArray());
+ }
+ else
+ {
+ throw new AccountNotFoundException("No account found for principal " + principal);
+ }
+ }
+
+ public boolean verifyPassword(String principal, char[] password) throws AccountNotFoundException
+ {
+ //fixme this is not correct as toCharArray is not safe based on the type of string.
+ char[] pwd = _users.getProperty(principal).toCharArray();
+
+ return compareCharArray(pwd, password);
+ }
+
+ public boolean updatePassword(Principal principal, char[] password) throws AccountNotFoundException
+ {
+ return false; // updates denied
+ }
+
+ public boolean createPrincipal(Principal principal, char[] password)
+ {
+ return false; // updates denied
+ }
+
+ public boolean deletePrincipal(Principal principal) throws AccountNotFoundException
+ {
+ return false; // updates denied
+ }
+
+ private boolean compareCharArray(char[] a, char[] b)
+ {
+ boolean equal = false;
+ if (a.length == b.length)
+ {
+ equal = true;
+ int index = 0;
+ while (equal && index < a.length)
+ {
+ equal = a[index] == b[index];
+ index++;
+ }
+ }
+ return equal;
+ }
+
+
+ public Map<String, AuthenticationProviderInitialiser> getMechanisms()
+ {
+ return _saslServers;
+ }
+
+ public List<Principal> getUsers()
+ {
+ return new LinkedList<Principal>(); //todo
+ }
+
+ public Principal getUser(String username)
+ {
+ if (_users.getProperty(username) != null)
+ {
+ return new UsernamePrincipal(username);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void reload() throws IOException
+ {
+ //No file to update from, so do nothing.
+ }
+
+ @Override
+ public void setPasswordFile(String passwordFile)
+ {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
index 9dcd22c088..cfeb7c525b 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
@@ -20,26 +20,17 @@
*/
package org.apache.qpid.server.security.auth.manager;
+import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped;
+
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+
import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase
+public class AnonymousAuthenticationManagerTest extends QpidTestCase
{
-
- private AuthenticationManager _manager = null;
-
- public void setUp() throws Exception
- {
- _manager = AnonymousAuthenticationManager.INSTANCE;
- }
-
+ private AuthenticationManager _manager = new AnonymousAuthenticationManager();
public void tearDown() throws Exception
{
@@ -49,29 +40,6 @@ public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase
}
}
- private ConfigurationPlugin getPlainDatabaseConfig() throws ConfigurationException
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
- }
-
-
- public void testConfiguration() throws Exception
- {
- AuthenticationManager authenticationManager =
- AnonymousAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig());
-
- assertNull("AnonymousAuthenticationManager unexpectedly created when not in config", authenticationManager);
- }
-
public void testGetMechanisms() throws Exception
{
assertEquals("ANONYMOUS", _manager.getMechanisms());
@@ -102,7 +70,8 @@ public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase
assertEquals("Expected authentication to be successful",
AuthenticationResult.AuthenticationStatus.SUCCESS,
result.getStatus());
- assertNotNull("Subject should not be null", result.getSubject());
+
+ assertOnlyContainsWrapped(AnonymousAuthenticationManager.ANONYMOUS_PRINCIPAL, result.getPrincipals());
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java
deleted file mode 100644
index efb8df3a38..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AuthenticationManagerRegistryTest.java
+++ /dev/null
@@ -1,304 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.manager;
-
-import static org.mockito.Mockito.*;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-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 org.apache.commons.configuration.ConfigurationException;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.plugins.Plugin;
-import org.apache.qpid.server.plugins.PluginManager;
-import org.apache.qpid.server.security.SecurityManager.SecurityConfiguration;
-import org.mockito.Mockito;
-
-import junit.framework.TestCase;
-
-public class AuthenticationManagerRegistryTest extends TestCase
-{
- private static final Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> EMPTY_PLUGINMAP = Collections.emptyMap();
-
- private PluginManager _pluginManager = Mockito.mock(PluginManager.class);
- private ServerConfiguration _serverConfiguration = Mockito.mock(ServerConfiguration.class);
- private SecurityConfiguration _securityConfiguration = Mockito.mock(SecurityConfiguration.class);
-
- private List<AuthenticationManager> _allCreatedAuthManagers = new ArrayList<AuthenticationManager>();
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- // Setup server configuration to return mock security config.
- when(_serverConfiguration.getConfiguration(SecurityConfiguration.class.getName())).thenReturn(_securityConfiguration);
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- try
- {
- verifyAllCreatedAuthManagersClosed();
- }
- finally
- {
- super.tearDown();
- }
- }
-
- public void testNoAuthenticationManagerFactoryPluginsFound() throws Exception
- {
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(EMPTY_PLUGINMAP);
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertEquals("No authentication manager factory plugins found. Check the desired authentication manager plugin has been placed in the plugins directory.",
- ce.getMessage());
- }
- }
-
- public void testSameAuthenticationManagerSpecifiedTwice() throws Exception
- {
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
-
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory, myAuthManagerFactory);
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertEquals("Cannot configure more than one authentication manager of type " + myAuthManagerFactory.getPluginClass().getSimpleName() + ". Remove configuration for one of the authentication managers.",
- ce.getMessage());
- }
- }
-
- public void testMultipleAuthenticationManagersSpecifiedButNoDefaultSpecified() throws Exception
- {
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class);
-
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2);
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(null);
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertEquals("If more than one authentication manager is configured a default MUST be specified.",
- ce.getMessage());
- }
- }
-
- public void testDefaultAuthenticationManagerNotKnown() throws Exception
- {
- String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager";
-
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class);
-
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2);
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(myDefaultAuthManagerSimpleClassName);
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertTrue("Unexpected message " + ce.getMessage(),
- ce.getMessage().startsWith("No authentication managers configured of type " + myDefaultAuthManagerSimpleClassName + " which is specified as the default"));
- }
- }
-
- public void testPortMappedToUnknownAuthenticationManager() throws Exception
- {
- String myDefaultAuthManagerSimpleClassName = "UnknownAuthenticationManager";
- int portNumber = 1234;
-
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
-
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1);
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
- when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(portNumber, myDefaultAuthManagerSimpleClassName));
-
- try
- {
- new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- assertEquals("Unknown authentication manager class " + myDefaultAuthManagerSimpleClassName + " configured for port " + portNumber, ce.getMessage());
- }
- }
-
- public void testGetAuthenticationManagerForInetSocketAddress() throws Exception
- {
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1);
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
-
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
-
- AuthenticationManager authenticationManager = registry.getAuthenticationManager(new InetSocketAddress(1234));
- assertEquals("TestAuthenticationManager1", authenticationManager.getMechanisms());
-
- registry.close();
- }
-
- public void testGetAuthenticationManagerForNonInetSocketAddress() throws Exception
- {
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1);
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
-
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
-
- AuthenticationManager authenticationManager = registry.getAuthenticationManager(mock(SocketAddress.class));
- assertEquals("TestAuthenticationManager1", authenticationManager.getMechanisms());
-
- registry.close();
- }
-
- public void testGetAuthenticationManagerWithMultipleAuthenticationManager() throws Exception
- {
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2);
-
- String defaultAuthManger = myAuthManagerFactory1.getPluginName();
- int unmappedPortNumber = 1234;
- int mappedPortNumber = 1235;
- String mappedAuthManager = myAuthManagerFactory2.getPluginName();
-
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthManger);
- when(_serverConfiguration.getPortAuthenticationMappings()).thenReturn(Collections.singletonMap(mappedPortNumber, mappedAuthManager));
-
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
-
- AuthenticationManager authenticationManager1 = registry.getAuthenticationManager(new InetSocketAddress(unmappedPortNumber));
- assertEquals("TestAuthenticationManager1", authenticationManager1.getMechanisms());
-
- AuthenticationManager authenticationManager2 = registry.getAuthenticationManager(new InetSocketAddress(mappedPortNumber));
- assertEquals("TestAuthenticationManager2", authenticationManager2.getMechanisms());
-
- registry.close();
- }
-
- public void testAuthenticationManagersAreClosed() throws Exception
- {
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory1 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager1.class);
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory2 = newMockFactoryProducingMockAuthManagerImplementing(TestAuthenticationManager2.class);
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = createPluginMap(myAuthManagerFactory1, myAuthManagerFactory2);
-
- String defaultAuthManger = myAuthManagerFactory1.getPluginName();
- when(_pluginManager.getAuthenticationManagerPlugins()).thenReturn(pluginMap);
- when(_serverConfiguration.getDefaultAuthenticationManager()).thenReturn(defaultAuthManger);
-
- AuthenticationManagerRegistry registry = new AuthenticationManagerRegistry(_serverConfiguration, _pluginManager);
-
- registry.close();
- }
-
- private AuthenticationManagerPluginFactory<? extends Plugin> newMockFactoryProducingMockAuthManagerImplementing(Class<? extends AuthenticationManager> authManagerClazz)
- throws ConfigurationException
- {
- AuthenticationManager myAuthManager = mock(authManagerClazz);
- when(myAuthManager.getMechanisms()).thenReturn(authManagerClazz.getSimpleName()); // used to verify the getAuthenticationManagerFor returns expected impl.
-
- AuthenticationManagerPluginFactory myAuthManagerFactory = mock(AuthenticationManagerPluginFactory.class);
- when(myAuthManagerFactory.getPluginClass()).thenReturn(myAuthManager.getClass());
- when(myAuthManagerFactory.getPluginName()).thenReturn(myAuthManager.getClass().getSimpleName());
- when(myAuthManagerFactory.newInstance(_securityConfiguration)).thenReturn(myAuthManager);
-
- _allCreatedAuthManagers.add(myAuthManager);
- return myAuthManagerFactory;
- }
-
- private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> createPluginMap(
- AuthenticationManagerPluginFactory<? extends Plugin> myAuthManagerFactory)
- {
- return createPluginMap(myAuthManagerFactory, null);
- }
-
- private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> createPluginMap(
- AuthenticationManagerPluginFactory<? extends Plugin> authManagerFactory1,
- AuthenticationManagerPluginFactory<? extends Plugin> authManagerFactory2)
- {
- Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> pluginMap = new HashMap<String, AuthenticationManagerPluginFactory<? extends Plugin>>();
- pluginMap.put("config.path.unused1", authManagerFactory1);
- if (authManagerFactory2 != null)
- {
- pluginMap.put("config.path.unused2", authManagerFactory2);
- }
- return pluginMap;
- }
-
- private void verifyAllCreatedAuthManagersClosed()
- {
- for (Iterator<AuthenticationManager> iterator = _allCreatedAuthManagers.iterator(); iterator.hasNext();)
- {
- AuthenticationManager authenticationManager = (AuthenticationManager) iterator.next();
- verify(authenticationManager).close();
- }
- }
-
- private interface TestAuthenticationManager1 extends AuthenticationManager
- {
- }
-
- private interface TestAuthenticationManager2 extends AuthenticationManager
- {
- }
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactoryTest.java
new file mode 100644
index 0000000000..04e09e073f
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/Base64MD5PasswordFileAuthenticationManagerFactoryTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.security.auth.manager;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
+
+public class Base64MD5PasswordFileAuthenticationManagerFactoryTest extends TestCase
+{
+ AuthenticationManagerFactory _factory = new Base64MD5PasswordFileAuthenticationManagerFactory();
+ private Map<String, Object> _configuration = new HashMap<String, Object>();
+ private File _emptyPasswordFile;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _emptyPasswordFile = File.createTempFile(getName(), "passwd");
+ _emptyPasswordFile.deleteOnExit();
+ }
+
+ public void testBase64MD5InstanceCreated() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _emptyPasswordFile.getAbsolutePath());
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
+ assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof Base64MD5PasswordFilePrincipalDatabase);
+ }
+
+ public void testPasswordFileNotFound() throws Exception
+ {
+ //delete the file
+ _emptyPasswordFile.delete();
+
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _emptyPasswordFile.getAbsolutePath());
+
+ try
+ {
+ _factory.createInstance(_configuration);
+ }
+ catch (RuntimeException re)
+ {
+ assertTrue(re.getCause() instanceof FileNotFoundException);
+ }
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForOtherAuthManagerType() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, "other-auth-manager");
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ if (_emptyPasswordFile == null && _emptyPasswordFile.exists())
+ {
+ _emptyPasswordFile.delete();
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+} \ No newline at end of file
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
index c1a55ef2ad..a66d73c47d 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
@@ -18,58 +18,18 @@
*/
package org.apache.qpid.server.security.auth.manager;
+import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped;
+
import javax.security.auth.x500.X500Principal;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+
import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ExternalAuthenticationManagerTest extends InternalBrokerBaseCase
+public class ExternalAuthenticationManagerTest extends QpidTestCase
{
-
- private AuthenticationManager _manager = null;
-
- public void setUp() throws Exception
- {
- _manager = ExternalAuthenticationManager.INSTANCE;
- }
-
-
- public void tearDown() throws Exception
- {
- if(_manager != null)
- {
- _manager = null;
- }
- }
-
- private ConfigurationPlugin getPlainDatabaseConfig() throws ConfigurationException
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
- }
-
-
- public void testConfiguration() throws Exception
- {
- AuthenticationManager authenticationManager =
- ExternalAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig());
-
- assertNull("ExternalAuthenticationManager unexpectedly created when not in config", authenticationManager);
- }
+ private AuthenticationManager _manager = new ExternalAuthenticationManager();
public void testGetMechanisms() throws Exception
{
@@ -103,12 +63,12 @@ public class ExternalAuthenticationManagerTest extends InternalBrokerBaseCase
assertEquals("Expected authentication to be successful",
AuthenticationResult.AuthenticationStatus.SUCCESS,
result.getStatus());
- assertEquals("Expected principal to be unchanged",
- principal,
- result.getSubject().getPrincipals().iterator().next());
+
+ assertOnlyContainsWrapped(principal, result.getPrincipals());
saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", null);
result = _manager.authenticate(saslServer, new byte[0]);
+
assertNotNull(result);
assertEquals("Expected authentication to be unsuccessful",
AuthenticationResult.AuthenticationStatus.ERROR,
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactoryTest.java
new file mode 100644
index 0000000000..d428f8b211
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PlainPasswordFileAuthenticationManagerFactoryTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.security.auth.manager;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
+
+public class PlainPasswordFileAuthenticationManagerFactoryTest extends TestCase
+{
+ AuthenticationManagerFactory _factory = new PlainPasswordFileAuthenticationManagerFactory();
+ private Map<String, Object> _configuration = new HashMap<String, Object>();
+ private File _emptyPasswordFile;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _emptyPasswordFile = File.createTempFile(getName(), "passwd");
+ _emptyPasswordFile.deleteOnExit();
+ }
+
+ public void testPlainInstanceCreated() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _emptyPasswordFile.getAbsolutePath());
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ assertTrue(manager instanceof PrincipalDatabaseAuthenticationManager);
+ assertTrue(((PrincipalDatabaseAuthenticationManager)manager).getPrincipalDatabase() instanceof PlainPasswordFilePrincipalDatabase);
+ }
+
+ public void testPasswordFileNotFound() throws Exception
+ {
+ //delete the file
+ _emptyPasswordFile.delete();
+
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _emptyPasswordFile.getAbsolutePath());
+
+ try
+ {
+ _factory.createInstance(_configuration);
+ }
+ catch (RuntimeException re)
+ {
+ assertTrue(re.getCause() instanceof FileNotFoundException);
+ }
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForOtherAuthManagerType() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, "other-auth-manager");
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigForPlainPDImplementationNoPasswordFileValueSpecified() throws Exception
+ {
+ _configuration.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ if (_emptyPasswordFile == null && _emptyPasswordFile.exists())
+ {
+ _emptyPasswordFile.delete();
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java
index 47c189e4fa..1ae667804a 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java
@@ -20,132 +20,92 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
+import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.security.auth.AuthenticationResult;
-import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import java.security.Provider;
+import java.security.Security;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
-import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.security.Provider;
-import java.security.Security;
+import javax.security.sasl.SaslServerFactory;
+
+import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser;
+import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser;
+import org.apache.qpid.test.utils.QpidTestCase;
/**
- *
* Tests the public methods of PrincipalDatabaseAuthenticationManager.
*
*/
-public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBaseCase
+public class PrincipalDatabaseAuthenticationManagerTest extends QpidTestCase
{
+ private static final String MOCK_MECH_NAME = "MOCK-MECH-NAME";
+ private static final UsernamePrincipal PRINCIPAL = new UsernamePrincipal("guest");
+
private AuthenticationManager _manager = null; // Class under test
- private String TEST_USERNAME = "guest";
- private String TEST_PASSWORD = "guest";
+ private PrincipalDatabase _principalDatabase;
- /**
- * @see org.apache.qpid.server.util.InternalBrokerBaseCase#tearDown()
- */
@Override
public void tearDown() throws Exception
{
- super.tearDown();
if (_manager != null)
{
_manager.close();
}
+ super.tearDown();
}
- /**
- * @see org.apache.qpid.server.util.InternalBrokerBaseCase#setUp()
- */
- @Override
- public void setUp() throws Exception
+ private void setupMocks() throws Exception
{
- super.setUp();
-
- final String passwdFilename = createPasswordFile().getCanonicalPath();
- final ConfigurationPlugin config = getConfig(PlainPasswordFilePrincipalDatabase.class.getName(),
- "passwordFile", passwdFilename);
+ _principalDatabase = mock(PrincipalDatabase.class);
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(config);
- }
+ AuthenticationProviderInitialiser _mockMechInitialiser = mock(AuthenticationProviderInitialiser.class);
+ Map<String, AuthenticationProviderInitialiser> _initialisers = Collections.singletonMap(MOCK_MECH_NAME, _mockMechInitialiser);
- /**
- * Tests where the case where the config specifies a PD implementation
- * that is not found.
- */
- public void testPrincipalDatabaseImplementationNotFound() throws Exception
- {
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig("not.Found", null, null));
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- }
- }
+ when(_principalDatabase.getMechanisms()).thenReturn(_initialisers);
- /**
- * Tests where the case where the config specifies a PD implementation
- * of the wrong type.
- */
- public void testPrincipalDatabaseImplementationWrongType() throws Exception
- {
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(String.class.getName(), null, null)); // Not a PrincipalDatabase implementation
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- }
+ _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase);
+ _manager.initialise();
}
- /**
- * Tests the case where a setter with the desired name cannot be found.
- */
- public void testPrincipalDatabaseSetterNotFound() throws Exception
+ private void setupMocksWithInitialiser() throws Exception
{
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "noMethod", "test"));
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- }
- }
+ _principalDatabase = mock(PrincipalDatabase.class);
- /**
- * QPID-1347. Make sure the exception message and stack trace is reasonable for an absent password file.
- */
- public void testPrincipalDatabaseThrowsSetterFileNotFound() throws Exception
- {
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "passwordFile", "/not/found"));
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
+ UsernamePasswordInitialiser usernamePasswordInitialiser = new UsernamePasswordInitialiser()
{
- // PASS
- assertNotNull("Expected an underlying cause", ce.getCause());
- assertEquals(FileNotFoundException.class, ce.getCause().getClass());
- }
+ @Override
+ public Class<? extends SaslServerFactory> getServerFactoryClassForJCARegistration()
+ {
+ return MySaslServerFactory.class;
+ }
+
+ @Override
+ public String getMechanismName()
+ {
+ return MOCK_MECH_NAME;
+ }
+ };
+
+ Map<String,AuthenticationProviderInitialiser> initialisers = new HashMap<String, AuthenticationProviderInitialiser>();
+ initialisers.put(MOCK_MECH_NAME, usernamePasswordInitialiser);
+
+ when(_principalDatabase.getMechanisms()).thenReturn(initialisers);
+
+ usernamePasswordInitialiser.initialise(_principalDatabase);
+
+ _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase);
+ _manager.initialise();
}
/**
@@ -153,11 +113,16 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
public void testRegisteredMechanisms() throws Exception
{
+ //Ensure we haven't registered anything yet (though this would really indicate a prior test failure!)
+ Provider qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME);
+ assertNull(qpidProvider);
+
+ setupMocksWithInitialiser();
+
assertNotNull(_manager.getMechanisms());
- // relies on those mechanisms attached to PropertiesPrincipalDatabaseManager
- assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
+ assertEquals(MOCK_MECH_NAME, _manager.getMechanisms());
- Provider qpidProvider = Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME);
+ qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME);
assertNotNull(qpidProvider);
}
@@ -167,96 +132,103 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
public void testSaslMechanismCreation() throws Exception
{
- SaslServer server = _manager.createSaslServer("CRAM-MD5", "localhost", null);
+ setupMocksWithInitialiser();
+
+ SaslServer server = _manager.createSaslServer(MOCK_MECH_NAME, "localhost", null);
assertNotNull(server);
// Merely tests the creation of the mechanism. Mechanisms themselves are tested
// by their own tests.
}
-
+
/**
* Tests that the authenticate method correctly interprets an
* authentication success.
- *
+ *
*/
public void testSaslAuthenticationSuccess() throws Exception
{
+ setupMocks();
+
SaslServer testServer = createTestSaslServer(true, false);
-
+
AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes());
- final Subject subject = result.getSubject();
- assertTrue(subject.getPrincipals().contains(new UsernamePrincipal("guest")));
+
+ assertOnlyContainsWrapped(PRINCIPAL, result.getPrincipals());
assertEquals(AuthenticationStatus.SUCCESS, result.getStatus());
}
/**
- *
+ *
* Tests that the authenticate method correctly interprets an
* authentication not complete.
- *
+ *
*/
public void testSaslAuthenticationNotCompleted() throws Exception
{
+ setupMocks();
+
SaslServer testServer = createTestSaslServer(false, false);
-
+
AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes());
- assertNull(result.getSubject());
+ assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
+
assertEquals(AuthenticationStatus.CONTINUE, result.getStatus());
}
/**
- *
+ *
* Tests that the authenticate method correctly interprets an
* authentication error.
- *
+ *
*/
public void testSaslAuthenticationError() throws Exception
{
+ setupMocks();
+
SaslServer testServer = createTestSaslServer(false, true);
-
+
AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes());
- assertNull(result.getSubject());
+ assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
assertEquals(AuthenticationStatus.ERROR, result.getStatus());
}
- /**
- * Tests that the authenticate method correctly interprets an
- * authentication success.
- *
- */
public void testNonSaslAuthenticationSuccess() throws Exception
{
+ setupMocks();
+
+ when(_principalDatabase.verifyPassword("guest", "guest".toCharArray())).thenReturn(true);
+
AuthenticationResult result = _manager.authenticate("guest", "guest");
- final Subject subject = result.getSubject();
- assertFalse("Subject should not be set read-only", subject.isReadOnly());
- assertTrue(subject.getPrincipals().contains(new UsernamePrincipal("guest")));
+ assertOnlyContainsWrapped(PRINCIPAL, result.getPrincipals());
assertEquals(AuthenticationStatus.SUCCESS, result.getStatus());
}
- /**
- * Tests that the authenticate method correctly interprets an
- * authentication success.
- *
- */
public void testNonSaslAuthenticationNotCompleted() throws Exception
{
+ setupMocks();
+
+ when(_principalDatabase.verifyPassword("guest", "wrongpassword".toCharArray())).thenReturn(false);
+
AuthenticationResult result = _manager.authenticate("guest", "wrongpassword");
- assertNull(result.getSubject());
+ assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
assertEquals(AuthenticationStatus.CONTINUE, result.getStatus());
}
-
+
/**
* Tests the ability to de-register the provider.
*/
public void testClose() throws Exception
{
- assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
- assertNotNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME));
+ setupMocksWithInitialiser();
+
+ assertEquals(MOCK_MECH_NAME, _manager.getMechanisms());
+ assertNotNull(Security.getProvider(AuthenticationManager.PROVIDER_NAME));
_manager.close();
// Check provider has been removed.
assertNull(_manager.getMechanisms());
- assertNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME));
+ assertNull(Security.getProvider(AuthenticationManager.PROVIDER_NAME));
_manager = null;
}
@@ -265,94 +237,90 @@ public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBa
*/
private SaslServer createTestSaslServer(final boolean complete, final boolean throwSaslException)
{
- return new SaslServer()
- {
- public String getMechanismName()
- {
- return null;
- }
+ return new MySaslServer(throwSaslException, complete);
+ }
- public byte[] evaluateResponse(byte[] response) throws SaslException
- {
- if (throwSaslException)
- {
- throw new SaslException("Mocked exception");
- }
- return null;
- }
+ public static final class MySaslServer implements SaslServer
+ {
+ private final boolean _throwSaslException;
+ private final boolean _complete;
- public boolean isComplete()
- {
- return complete;
- }
+ public MySaslServer()
+ {
+ this(false, true);
+ }
- public String getAuthorizationID()
- {
- return complete ? "guest" : null;
- }
+ private MySaslServer(boolean throwSaslException, boolean complete)
+ {
+ _throwSaslException = throwSaslException;
+ _complete = complete;
+ }
- public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
- {
- return null;
- }
+ public String getMechanismName()
+ {
+ return null;
+ }
- public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
+ public byte[] evaluateResponse(byte[] response) throws SaslException
+ {
+ if (_throwSaslException)
{
- return null;
+ throw new SaslException("Mocked exception");
}
+ return null;
+ }
- public Object getNegotiatedProperty(String propName)
- {
- return null;
- }
+ public boolean isComplete()
+ {
+ return _complete;
+ }
- public void dispose() throws SaslException
- {
- }
- };
- }
+ public String getAuthorizationID()
+ {
+ return _complete ? "guest" : null;
+ }
- private ConfigurationPlugin getConfig(final String clazz, final String argName, final String argValue) throws Exception
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
+ public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
+ {
+ return null;
+ }
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", clazz);
+ public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
+ {
+ return null;
+ }
- if (argName != null)
+ public Object getNegotiatedProperty(String propName)
{
- xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.name", argName);
- xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.value", argValue);
+ return null;
}
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
+ public void dispose() throws SaslException
+ {
+ }
}
- private File createPasswordFile() throws Exception
+ public static class MySaslServerFactory implements SaslServerFactory
{
- BufferedWriter writer = null;
- try
- {
- File testFile = File.createTempFile(this.getClass().getName(),"tmp");
- testFile.deleteOnExit();
-
- writer = new BufferedWriter(new FileWriter(testFile));
- writer.write(TEST_USERNAME + ":" + TEST_PASSWORD);
- writer.newLine();
-
- return testFile;
-
- }
- finally
+ @Override
+ public SaslServer createSaslServer(String mechanism, String protocol,
+ String serverName, Map<String, ?> props, CallbackHandler cbh)
+ throws SaslException
{
- if (writer != null)
+ if (MOCK_MECH_NAME.equals(mechanism))
{
- writer.close();
+ return new MySaslServer();
}
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public String[] getMechanismNames(Map<String, ?> props)
+ {
+ return new String[]{MOCK_MECH_NAME};
}
}
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
new file mode 100644
index 0000000000..1424bee611
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.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.server.security.auth.manager;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+import junit.framework.TestCase;
+
+public class SimpleLDAPAuthenticationManagerFactoryTest extends TestCase
+{
+ private SimpleLDAPAuthenticationManagerFactory _factory = new SimpleLDAPAuthenticationManagerFactory();
+ private Map<String, Object> _configuration = new HashMap<String, Object>();
+
+ public void testInstanceCreated() throws Exception
+ {
+ _configuration.put(SimpleLDAPAuthenticationManagerFactory.ATTRIBUTE_TYPE, SimpleLDAPAuthenticationManagerFactory.PROVIDER_TYPE);
+ _configuration.put("providerUrl", "ldaps://example.com:636/");
+ _configuration.put("searchContext", "dc=example");
+
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ AuthenticationManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
index c0c55de92a..52b525dd80 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
@@ -20,20 +20,26 @@
*/
package org.apache.qpid.server.security.auth.rmi;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.security.Principal;
+import java.util.regex.Pattern;
+
+import javax.security.auth.Subject;
+
import junit.framework.TestCase;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.security.auth.AuthenticationResult;
import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-
-import javax.management.remote.JMXPrincipal;
-import javax.security.auth.Subject;
-import javax.security.sasl.SaslException;
-import javax.security.sasl.SaslServer;
-import java.net.InetSocketAddress;
-import java.util.Collections;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
+import org.apache.qpid.server.security.SecurityManager;
/**
* Tests the RMIPasswordAuthenticator and its collaboration with the AuthenticationManager.
@@ -41,36 +47,35 @@ import java.util.Collections;
*/
public class RMIPasswordAuthenticatorTest extends TestCase
{
- private final String USERNAME = "guest";
- private final String PASSWORD = "guest";
+ private static final String USERNAME = "guest";
+ private static final String PASSWORD = "password";
+
+ private final Broker _broker = mock(Broker.class);
+ private final SecurityManager _securityManager = mock(SecurityManager.class);
+ private final Subject _loginSubject = new Subject();
+ private final String[] _credentials = new String[] {USERNAME, PASSWORD};
+
private RMIPasswordAuthenticator _rmipa;
- private String[] _credentials;
+
+ private SubjectCreator _usernamePasswordOkaySuvjectCreator = createMockSubjectCreator(true, null);
+ private SubjectCreator _badPasswordSubjectCreator = createMockSubjectCreator(false, null);
protected void setUp() throws Exception
{
- _rmipa = new RMIPasswordAuthenticator(new InetSocketAddress(5672));
-
- _credentials = new String[] {USERNAME, PASSWORD};
+ when(_broker.getSecurityManager()).thenReturn(_securityManager);
+ _rmipa = new RMIPasswordAuthenticator(_broker, new InetSocketAddress(8999));
}
/**
- * Tests a successful authentication. Ensures that a populated read-only subject it returned.
+ * Tests a successful authentication. Ensures that the expected subject is returned.
*/
public void testAuthenticationSuccess()
{
- final Subject expectedSubject = new Subject(true,
- Collections.singleton(new JMXPrincipal(USERNAME)),
- Collections.EMPTY_SET,
- Collections.EMPTY_SET);
-
- _rmipa.setAuthenticationManager(createTestAuthenticationManager(true, null));
-
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_usernamePasswordOkaySuvjectCreator);
+ when(_securityManager.accessManagement()).thenReturn(true);
Subject newSubject = _rmipa.authenticate(_credentials);
- assertTrue("Subject must be readonly", newSubject.isReadOnly());
- assertTrue("Returned subject does not equal expected value",
- newSubject.equals(expectedSubject));
-
+ assertSame("Subject must be unchanged", _loginSubject, newSubject);
}
/**
@@ -78,7 +83,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase
*/
public void testUsernameOrPasswordInvalid()
{
- _rmipa.setAuthenticationManager(createTestAuthenticationManager(false, null));
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_badPasswordSubjectCreator);
try
{
@@ -89,17 +94,31 @@ public class RMIPasswordAuthenticatorTest extends TestCase
{
assertEquals("Unexpected exception message",
RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage());
+ }
+ }
+
+ public void testAuthorisationFailure()
+ {
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_usernamePasswordOkaySuvjectCreator);
+ when(_securityManager.accessManagement()).thenReturn(false);
+ try
+ {
+ _rmipa.authenticate(_credentials);
+ fail("Exception not thrown");
+ }
+ catch (SecurityException se)
+ {
+ assertEquals("Unexpected exception message",
+ RMIPasswordAuthenticator.USER_NOT_AUTHORISED_FOR_MANAGEMENT, se.getMessage());
}
}
- /**
- * Tests case where authentication system itself fails.
- */
- public void testAuthenticationFailure()
+ public void testSubjectCreatorInternalFailure()
{
final Exception mockAuthException = new Exception("Mock Auth system failure");
- _rmipa.setAuthenticationManager(createTestAuthenticationManager(false, mockAuthException));
+ SubjectCreator subjectCreator = createMockSubjectCreator(false, mockAuthException);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(subjectCreator);
try
{
@@ -112,13 +131,13 @@ public class RMIPasswordAuthenticatorTest extends TestCase
}
}
-
/**
* Tests case where authentication manager is not set.
*/
- public void testNullAuthenticationManager() throws Exception
+ public void testNullSubjectCreator() throws Exception
{
- _rmipa.setAuthenticationManager(null);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(null);
+
try
{
_rmipa.authenticate(_credentials);
@@ -126,8 +145,7 @@ public class RMIPasswordAuthenticatorTest extends TestCase
}
catch (SecurityException se)
{
- assertEquals("Unexpected exception message",
- RMIPasswordAuthenticator.UNABLE_TO_LOOKUP, se.getMessage());
+ assertTrue("Unexpected exception message", Pattern.matches("Can't get subject creator for .*:8999", se.getMessage()));
}
}
@@ -155,11 +173,13 @@ public class RMIPasswordAuthenticatorTest extends TestCase
*/
public void testWithIllegalNumberOfArguments()
{
+ String[] credentials;
+
// Test handling of incorrect number of credentials
try
{
- _credentials = new String[]{USERNAME, PASSWORD, PASSWORD};
- _rmipa.authenticate(_credentials);
+ credentials = new String[]{USERNAME, PASSWORD, PASSWORD};
+ _rmipa.authenticate(credentials);
fail("SecurityException expected due to supplying wrong number of credentials");
}
catch (SecurityException se)
@@ -172,8 +192,8 @@ public class RMIPasswordAuthenticatorTest extends TestCase
try
{
//send a null array
- _credentials = null;
- _rmipa.authenticate(_credentials);
+ credentials = null;
+ _rmipa.authenticate(credentials);
fail("SecurityException expected due to not supplying an array of credentials");
}
catch (SecurityException se)
@@ -185,8 +205,8 @@ public class RMIPasswordAuthenticatorTest extends TestCase
try
{
//send a null password
- _credentials = new String[]{USERNAME, null};
- _rmipa.authenticate(_credentials);
+ credentials = new String[]{USERNAME, null};
+ _rmipa.authenticate(credentials);
fail("SecurityException expected due to sending a null password");
}
catch (SecurityException se)
@@ -198,8 +218,8 @@ public class RMIPasswordAuthenticatorTest extends TestCase
try
{
//send a null username
- _credentials = new String[]{null, PASSWORD};
- _rmipa.authenticate(_credentials);
+ credentials = new String[]{null, PASSWORD};
+ _rmipa.authenticate(credentials);
fail("SecurityException expected due to sending a null username");
}
catch (SecurityException se)
@@ -209,55 +229,30 @@ public class RMIPasswordAuthenticatorTest extends TestCase
}
}
- private AuthenticationManager createTestAuthenticationManager(final boolean successfulAuth, final Exception exception)
+ private SubjectCreator createMockSubjectCreator(final boolean successfulAuth, final Exception exception)
{
- return new AuthenticationManager()
+ SubjectCreator subjectCreator = mock(SubjectCreator.class);
+
+ SubjectAuthenticationResult subjectAuthenticationResult;
+
+ if (exception != null) {
+
+ subjectAuthenticationResult = new SubjectAuthenticationResult(
+ new AuthenticationResult(AuthenticationStatus.ERROR, exception));
+ }
+ else if (successfulAuth)
{
- public void configure(ConfigurationPlugin config)
- {
- throw new UnsupportedOperationException();
- }
-
- public void initialise()
- {
- throw new UnsupportedOperationException();
- }
-
- public void close()
- {
- throw new UnsupportedOperationException();
- }
-
- public String getMechanisms()
- {
- throw new UnsupportedOperationException();
- }
-
- public SaslServer createSaslServer(String mechanism, String localFQDN, Principal externalPrincipal) throws SaslException
- {
- throw new UnsupportedOperationException();
- }
-
- public AuthenticationResult authenticate(SaslServer server, byte[] response)
- {
- throw new UnsupportedOperationException();
- }
-
- public AuthenticationResult authenticate(String username, String password)
- {
- if (exception != null) {
- return new AuthenticationResult(AuthenticationStatus.ERROR, exception);
- }
- else if (successfulAuth)
- {
- return new AuthenticationResult(new Subject());
- }
- else
- {
- return new AuthenticationResult(AuthenticationStatus.CONTINUE);
- }
- }
-
- };
+
+ subjectAuthenticationResult = new SubjectAuthenticationResult(
+ new AuthenticationResult(mock(Principal.class)), _loginSubject);
+ }
+ else
+ {
+ subjectAuthenticationResult = new SubjectAuthenticationResult(new AuthenticationResult(AuthenticationStatus.CONTINUE));
+ }
+
+ when(subjectCreator.authenticate(anyString(), anyString())).thenReturn(subjectAuthenticationResult);
+
+ return subjectCreator;
}
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipalTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipalTest.java
deleted file mode 100644
index 076b7c9248..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/GroupPrincipalTest.java
+++ /dev/null
@@ -1,86 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.sasl;
-
-import junit.framework.TestCase;
-
-public class GroupPrincipalTest extends TestCase
-{
- public void testGetName()
- {
- final GroupPrincipal principal = new GroupPrincipal("group");
- assertEquals("group", principal.getName());
- }
-
- public void testAddRejected()
- {
- final GroupPrincipal principal = new GroupPrincipal("group");
- final UsernamePrincipal user = new UsernamePrincipal("name");
-
- try
- {
- principal.addMember(user);
- fail("Exception not thrown");
- }
- catch (UnsupportedOperationException uso)
- {
- // PASS
- }
- }
-
- public void testEqualitySameName()
- {
- final String string = "string";
- final GroupPrincipal principal1 = new GroupPrincipal(string);
- final GroupPrincipal principal2 = new GroupPrincipal(string);
- assertTrue(principal1.equals(principal2));
- }
-
- public void testEqualityEqualName()
- {
- final GroupPrincipal principal1 = new GroupPrincipal(new String("string"));
- final GroupPrincipal principal2 = new GroupPrincipal(new String("string"));
- assertTrue(principal1.equals(principal2));
- }
-
- public void testInequalityDifferentGroupPrincipals()
- {
- GroupPrincipal principal1 = new GroupPrincipal("string1");
- GroupPrincipal principal2 = new GroupPrincipal("string2");
- assertFalse(principal1.equals(principal2));
- }
-
- public void testInequalityNonGroupPrincipal()
- {
- GroupPrincipal principal = new GroupPrincipal("string");
- assertFalse(principal.equals(new UsernamePrincipal("string")));
- }
-
- public void testInequalityNull()
- {
- GroupPrincipal principal = new GroupPrincipal("string");
- assertFalse(principal.equals(null));
- }
-
-
-
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java
index 8c7f3ad6ef..f94d8ddfc3 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java
@@ -86,4 +86,10 @@ public class TestPrincipalDatabase implements PrincipalDatabase
// TODO Auto-generated method stub
}
+ @Override
+ public void setPasswordFile(String passwordFile) throws IOException
+ {
+ // TODO Auto-generated method stub
+ }
+
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalUtils.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalUtils.java
deleted file mode 100644
index 7ce03eaa79..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalUtils.java
+++ /dev/null
@@ -1,48 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.sasl;
-
-import javax.security.auth.Subject;
-import java.security.Principal;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-public class TestPrincipalUtils
-{
-
- /**
- * Creates a test subject, with exactly one UsernamePrincipal and zero or more GroupPrincipals.
- */
- public static Subject createTestSubject(final String username, final String... groups)
- {
- final Set<Principal> principals = new HashSet<Principal>(1 + groups.length);
- principals.add(new UsernamePrincipal(username));
- for (String group : groups)
- {
- principals.add(new GroupPrincipal(group));
- }
-
- final Subject subject = new Subject(true, principals, Collections.EMPTY_SET, Collections.EMPTY_SET);
- return subject;
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java
deleted file mode 100644
index 75bc76c688..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java
+++ /dev/null
@@ -1,123 +0,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.
- *
- */
-package org.apache.qpid.server.security.auth.sasl;
-
-import junit.framework.TestCase;
-
-import javax.security.auth.Subject;
-import java.security.Principal;
-
-/**
- * Tests the UsernamePrincipal.
- *
- */
-public class UsernamePrincipalTest extends TestCase
-{
- public void testEqualitySameObject()
- {
- final UsernamePrincipal principal = new UsernamePrincipal("string");
- assertTrue(principal.equals(principal));
- }
-
- public void testEqualitySameName()
- {
- final String string = "string";
- final UsernamePrincipal principal1 = new UsernamePrincipal(string);
- final UsernamePrincipal principal2 = new UsernamePrincipal(string);
- assertTrue(principal1.equals(principal2));
- }
-
- public void testEqualityEqualName()
- {
- final UsernamePrincipal principal1 = new UsernamePrincipal(new String("string"));
- final UsernamePrincipal principal2 = new UsernamePrincipal(new String("string"));
- assertTrue(principal1.equals(principal2));
- }
-
- public void testInequalityDifferentUserPrincipals()
- {
- UsernamePrincipal principal1 = new UsernamePrincipal("string1");
- UsernamePrincipal principal2 = new UsernamePrincipal("string2");
- assertFalse(principal1.equals(principal2));
- }
-
- public void testInequalityNonUserPrincipal()
- {
- UsernamePrincipal principal = new UsernamePrincipal("string");
- assertFalse(principal.equals(new String("string")));
- }
-
- public void testInequalityNull()
- {
- UsernamePrincipal principal = new UsernamePrincipal("string");
- assertFalse(principal.equals(null));
- }
-
- public void testGetUsernamePrincipalFromSubject()
- {
- final UsernamePrincipal expected = new UsernamePrincipal("name");
- final Principal other = new Principal()
- {
- public String getName()
- {
- return "otherprincipal";
- }
- };
-
- final Subject subject = new Subject();
- subject.getPrincipals().add(expected);
- subject.getPrincipals().add(other);
-
- final UsernamePrincipal actual = UsernamePrincipal.getUsernamePrincipalFromSubject(subject);
- assertSame(expected, actual);
- }
-
- public void testUsernamePrincipalNotInSubject()
- {
- try
- {
- UsernamePrincipal.getUsernamePrincipalFromSubject(new Subject());
- fail("Exception not thrown");
- }
- catch (IllegalArgumentException iae)
- {
- // PASS
- }
- }
-
- public void testTooManyUsernamePrincipalInSubject()
- {
- final Subject subject = new Subject();
- subject.getPrincipals().add(new UsernamePrincipal("name1"));
- subject.getPrincipals().add(new UsernamePrincipal("name2"));
- try
- {
-
- UsernamePrincipal.getUsernamePrincipalFromSubject(subject);
- fail("Exception not thrown");
- }
- catch (IllegalArgumentException iae)
- {
- // PASS
- }
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupDatabaseTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupDatabaseTest.java
new file mode 100644
index 0000000000..b020c1655a
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupDatabaseTest.java
@@ -0,0 +1,456 @@
+/*
+ * 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.security.group;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.qpid.server.security.group.FileGroupDatabase;
+
+import junit.framework.TestCase;
+
+public class FileGroupDatabaseTest extends TestCase
+{
+ private static final String USER1 = "user1";
+ private static final String USER2 = "user2";
+ private static final String USER3 = "user3";
+
+ private static final String MY_GROUP = "myGroup";
+ private static final String MY_GROUP2 = "myGroup2";
+ private static final String MY_GROUP1 = "myGroup1";
+
+ private FileGroupDatabase _groupDatabase = new FileGroupDatabase();
+ private String _groupFile;
+
+ public void testGetAllGroups() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", USER1);
+
+ Set<String> groups = _groupDatabase.getAllGroups();
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(MY_GROUP));
+ }
+
+ public void testGetAllGroupsWhenGroupFileEmpty() throws Exception
+ {
+ _groupDatabase.setGroupFile(_groupFile);
+
+ Set<String> groups = _groupDatabase.getAllGroups();
+ assertEquals(0, groups.size());
+ }
+
+ public void testMissingGroupFile() throws Exception
+ {
+ try
+ {
+ _groupDatabase.setGroupFile("/not/a/file");
+ fail("Exception not thrown");
+ }
+ catch (FileNotFoundException fnfe)
+ {
+ // PASS
+ }
+ }
+
+ public void testInvalidFormat() throws Exception
+ {
+ writeGroupFile("name.notvalid", USER1);
+
+ try
+ {
+ _groupDatabase.setGroupFile(_groupFile);
+ fail("Exception not thrown");
+ }
+ catch (IllegalArgumentException gde)
+ {
+ // PASS
+ }
+ }
+
+ public void testGetUsersInGroup() throws Exception
+ {
+ writeGroupFile("myGroup.users", "user1,user2,user3");
+
+ _groupDatabase.setGroupFile(_groupFile);
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(3, users.size());
+ }
+
+ public void testDuplicateUsersInGroupAreConflated() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "user1,user1,user3,user1");
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(2, users.size());
+ }
+
+ public void testGetUsersWithEmptyGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "");
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertTrue(users.isEmpty());
+ }
+
+ public void testGetUsersInNonExistentGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "user1,user2,user3");
+
+ Set<String> users = _groupDatabase.getUsersInGroup("groupDoesntExist");
+ assertNotNull(users);
+ assertTrue(users.isEmpty());
+ }
+
+ public void testGetUsersInNullGroup() throws Exception
+ {
+ writeAndSetGroupFile();
+ assertTrue(_groupDatabase.getUsersInGroup(null).isEmpty());
+ }
+
+ public void testGetGroupPrincipalsForUserWhenUserBelongsToOneGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "user1,user2");
+ Set<String> groups = _groupDatabase.getGroupsForUser(USER1);
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(MY_GROUP));
+ }
+
+ public void testGetGroupPrincipalsForUserWhenUserBelongsToTwoGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup1.users", "user1,user2",
+ "myGroup2.users", "user1,user3");
+ Set<String> groups = _groupDatabase.getGroupsForUser(USER1);
+ assertEquals(2, groups.size());
+ assertTrue(groups.contains(MY_GROUP1));
+ assertTrue(groups.contains(MY_GROUP2));
+ }
+
+ public void testGetGroupPrincipalsForUserWhenUserAddedToGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup1.users", "user1,user2",
+ "myGroup2.users", USER2);
+ Set<String> groups = _groupDatabase.getGroupsForUser(USER1);
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(MY_GROUP1));
+
+ _groupDatabase.addUserToGroup(USER1, MY_GROUP2);
+
+ groups = _groupDatabase.getGroupsForUser(USER1);
+ assertEquals(2, groups.size());
+ assertTrue(groups.contains(MY_GROUP1));
+ assertTrue(groups.contains(MY_GROUP2));
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP2);
+ assertEquals(2, users.size());
+ assertTrue(users.contains(USER1));
+ assertTrue(users.contains(USER2));
+ }
+
+ public void testGetGroupPrincipalsForUserWhenUserRemovedFromGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup1.users", "user1,user2",
+ "myGroup2.users", "user1,user2");
+ Set<String> groups = _groupDatabase.getGroupsForUser(USER1);
+ assertEquals(2, groups.size());
+ assertTrue(groups.contains(MY_GROUP1));
+ assertTrue(groups.contains(MY_GROUP2));
+
+ _groupDatabase.removeUserFromGroup(USER1, MY_GROUP2);
+
+ groups = _groupDatabase.getGroupsForUser(USER1);
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(MY_GROUP1));
+ }
+
+ public void testGetGroupPrincipalsForUserWhenUserAdddedToGroupTheyAreAlreadyIn() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", USER1);
+ _groupDatabase.addUserToGroup(USER1, MY_GROUP);
+
+ Set<String> groups = _groupDatabase.getGroupsForUser(USER1);
+
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(MY_GROUP));
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertEquals(1, users.size());
+ assertTrue(users.contains(USER1));
+ }
+
+ public void testGetGroupPrincipalsForUserWhenUserNotKnown() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "user1,user2");
+ Set<String> groups = _groupDatabase.getGroupsForUser(USER3);
+ assertEquals(0, groups.size());
+ }
+
+ public void testGetGroupPrincipalsForNullUser() throws Exception
+ {
+ writeAndSetGroupFile();
+ assertTrue(_groupDatabase.getGroupsForUser(null).isEmpty());
+ }
+
+ public void testAddUserToExistingGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "user1,user2");
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(2, users.size());
+
+ _groupDatabase.addUserToGroup(USER3, MY_GROUP);
+
+ users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(3, users.size());
+ }
+
+ public void testAddUserToEmptyGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "");
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(0, users.size());
+
+ _groupDatabase.addUserToGroup(USER3, MY_GROUP);
+
+ users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(1, users.size());
+ }
+
+ public void testAddUserToNonExistentGroup() throws Exception
+ {
+ writeAndSetGroupFile();
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(0, users.size());
+
+ try
+ {
+ _groupDatabase.addUserToGroup(USER3, MY_GROUP);
+ fail("Expected exception not thrown");
+ }
+ catch(IllegalArgumentException e)
+ {
+ // pass
+ }
+
+ users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(0, users.size());
+ }
+
+ public void testRemoveUserFromExistingGroup() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "user1,user2");
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(2, users.size());
+
+ _groupDatabase.removeUserFromGroup(USER2, MY_GROUP);
+
+ users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertNotNull(users);
+ assertEquals(1, users.size());
+ }
+
+ public void testRemoveUserFromNonexistentGroup() throws Exception
+ {
+ writeAndSetGroupFile();
+
+ try
+ {
+ _groupDatabase.removeUserFromGroup(USER1, MY_GROUP);
+ fail("Expected exception not thrown");
+ }
+ catch(IllegalArgumentException e)
+ {
+ // pass
+ }
+
+ assertTrue(_groupDatabase.getUsersInGroup(MY_GROUP).isEmpty());
+ }
+
+ public void testRemoveUserFromGroupTwice() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", USER1);
+ assertTrue(_groupDatabase.getUsersInGroup(MY_GROUP).contains(USER1));
+
+ _groupDatabase.removeUserFromGroup(USER1, MY_GROUP);
+ assertTrue(_groupDatabase.getUsersInGroup(MY_GROUP).isEmpty());
+
+ _groupDatabase.removeUserFromGroup(USER1, MY_GROUP);
+ assertTrue(_groupDatabase.getUsersInGroup(MY_GROUP).isEmpty());
+ }
+
+ public void testAddUserPersistedToFile() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "user1,user2");
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertEquals(2, users.size());
+
+ _groupDatabase.addUserToGroup(USER3, MY_GROUP);
+ assertEquals(3, users.size());
+
+ FileGroupDatabase newGroupDatabase = new FileGroupDatabase();
+ newGroupDatabase.setGroupFile(_groupFile);
+
+ Set<String> newUsers = newGroupDatabase.getUsersInGroup(MY_GROUP);
+ assertEquals(users.size(), newUsers.size());
+ }
+
+ public void testRemoveUserPersistedToFile() throws Exception
+ {
+ writeAndSetGroupFile("myGroup.users", "user1,user2");
+
+ Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
+ assertEquals(2, users.size());
+
+ _groupDatabase.removeUserFromGroup(USER2, MY_GROUP);
+ assertEquals(1, users.size());
+
+ FileGroupDatabase newGroupDatabase = new FileGroupDatabase();
+ newGroupDatabase.setGroupFile(_groupFile);
+
+ Set<String> newUsers = newGroupDatabase.getUsersInGroup(MY_GROUP);
+ assertEquals(users.size(), newUsers.size());
+ }
+
+ public void testCreateGroupPersistedToFile() throws Exception
+ {
+ writeAndSetGroupFile();
+
+ Set<String> groups = _groupDatabase.getAllGroups();
+ assertEquals(0, groups.size());
+
+ _groupDatabase.createGroup(MY_GROUP);
+
+ groups = _groupDatabase.getAllGroups();
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(MY_GROUP));
+
+ FileGroupDatabase newGroupDatabase = new FileGroupDatabase();
+ newGroupDatabase.setGroupFile(_groupFile);
+
+ Set<String> newGroups = newGroupDatabase.getAllGroups();
+ assertEquals(1, newGroups.size());
+ assertTrue(newGroups.contains(MY_GROUP));
+ }
+
+ public void testRemoveGroupPersistedToFile() throws Exception
+ {
+ writeAndSetGroupFile("myGroup1.users", "user1,user2",
+ "myGroup2.users", "user1,user2");
+
+ Set<String> groups = _groupDatabase.getAllGroups();
+ assertEquals(2, groups.size());
+
+ Set<String> groupsForUser1 = _groupDatabase.getGroupsForUser(USER1);
+ assertEquals(2, groupsForUser1.size());
+
+ _groupDatabase.removeGroup(MY_GROUP1);
+
+ groups = _groupDatabase.getAllGroups();
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(MY_GROUP2));
+
+ groupsForUser1 = _groupDatabase.getGroupsForUser(USER1);
+ assertEquals(1, groupsForUser1.size());
+
+ FileGroupDatabase newGroupDatabase = new FileGroupDatabase();
+ newGroupDatabase.setGroupFile(_groupFile);
+
+ Set<String> newGroups = newGroupDatabase.getAllGroups();
+ assertEquals(1, newGroups.size());
+ assertTrue(newGroups.contains(MY_GROUP2));
+
+ Set<String> newGroupsForUser1 = newGroupDatabase.getGroupsForUser(USER1);
+ assertEquals(1, newGroupsForUser1.size());
+ assertTrue(newGroupsForUser1.contains(MY_GROUP2));
+}
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _groupFile = createEmptyTestGroupFile();
+ }
+
+ private void writeAndSetGroupFile(String... groupAndUsers) throws Exception
+ {
+ writeGroupFile(groupAndUsers);
+ _groupDatabase.setGroupFile(_groupFile);
+ }
+
+ private void writeGroupFile(String... groupAndUsers) throws Exception
+ {
+ if (groupAndUsers.length % 2 != 0)
+ {
+ throw new IllegalArgumentException("Number of groupAndUsers must be even");
+ }
+
+ Properties props = new Properties();
+ for (int i = 0 ; i < groupAndUsers.length; i=i+2)
+ {
+ String group = groupAndUsers[i];
+ String users = groupAndUsers[i+1];
+ props.put(group, users);
+ }
+
+ props.store(new FileOutputStream(_groupFile), "test group file");
+ }
+
+ private String createEmptyTestGroupFile() throws IOException
+ {
+ File tmpGroupFile = File.createTempFile("groups", "grp");
+ tmpGroupFile.deleteOnExit();
+
+ return tmpGroupFile.getAbsolutePath();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (_groupFile != null)
+ {
+ File groupFile = new File(_groupFile);
+ if (groupFile.exists())
+ {
+ groupFile.delete();
+ }
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.java
new file mode 100644
index 0000000000..934c0082ea
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerFactoryTest.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.server.security.group;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+public class FileGroupManagerFactoryTest extends TestCase
+{
+
+ private FileGroupManagerFactory _factory = new FileGroupManagerFactory();
+ private Map<String, Object> _configuration = new HashMap<String, Object>();
+ private String _emptyButValidGroupFile = TestFileUtils.createTempFile(this).getAbsolutePath();
+
+ public void testInstanceCreated() throws Exception
+ {
+ _configuration.put(GroupProvider.TYPE, FileGroupManagerFactory.FILE_GROUP_MANAGER_TYPE);
+ _configuration.put(FileGroupManagerFactory.FILE, _emptyButValidGroupFile);
+
+ GroupManager manager = _factory.createInstance(_configuration);
+ assertNotNull(manager);
+ assertTrue(manager instanceof FileGroupManager);
+ }
+
+ public void testReturnsNullWhenNoConfig() throws Exception
+ {
+ GroupManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+ public void testReturnsNullWhenConfigNotForThisPlugin() throws Exception
+ {
+ _configuration.put(GroupProvider.TYPE, "other-group-manager");
+
+ GroupManager manager = _factory.createInstance(_configuration);
+ assertNull(manager);
+ }
+
+
+ public void testRejectsConfigThatIsMissingAttributeValue() throws Exception
+ {
+ _configuration.put(GroupProvider.TYPE, FileGroupManagerFactory.FILE_GROUP_MANAGER_TYPE);
+ _configuration.put(FileGroupManagerFactory.FILE, null);
+
+ try
+ {
+ _factory.createInstance(_configuration);
+ fail("Exception not thrown");
+ }
+ catch (RuntimeException re)
+ {
+ // PASS
+ }
+ }
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java
new file mode 100644
index 0000000000..b83d25b206
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/group/FileGroupManagerTest.java
@@ -0,0 +1,197 @@
+/*
+ * 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.security.group;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.security.Principal;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class FileGroupManagerTest extends QpidTestCase
+{
+ private static final String MYGROUP_USERS = "user1";
+ private static final String MY_GROUP = "myGroup.users";
+ private static final String MY_GROUP2 = "myGroup2.users";
+ private File _tmpGroupFile;
+ private FileGroupManager _manager;
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (_tmpGroupFile != null)
+ {
+ if (_tmpGroupFile.exists())
+ {
+ _tmpGroupFile.delete();
+ }
+ }
+ }
+
+ public void testValidGroupFile() throws Exception
+ {
+ final String groupFileName = writeGroupFile();
+
+ _manager = new FileGroupManager(groupFileName);
+ assertNotNull(_manager);
+ }
+
+ public void testNonExistentGroupFile() throws Exception
+ {
+ final String filePath = "/does.not.exist/";
+
+ try
+ {
+ _manager = new FileGroupManager(filePath);
+ fail("expected exception was not thrown");
+ }
+ catch(IllegalConfigurationException ce)
+ {
+ assertNotNull(ce.getCause());
+ assertTrue(ce.getCause() instanceof FileNotFoundException);
+ }
+ }
+
+ public void testGetGroupPrincipalsForUser() throws Exception
+ {
+ final String groupFileName = writeGroupFile();
+ _manager = new FileGroupManager(groupFileName);
+
+ Set<Principal> principals = _manager.getGroupPrincipalsForUser("user1");
+ assertEquals(1, principals.size());
+ assertTrue(principals.contains(new GroupPrincipal("myGroup")));
+ }
+
+ public void testGetUserPrincipalsForGroup() throws Exception
+ {
+ final String groupFileName = writeGroupFile();
+ _manager = new FileGroupManager(groupFileName);
+
+ Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup");
+ assertEquals(1, principals.size());
+ assertTrue(principals.contains(new UsernamePrincipal("user1")));
+ }
+
+ public void testGetGroupPrincipals() throws Exception
+ {
+ final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS, MY_GROUP2, MYGROUP_USERS);
+ _manager = new FileGroupManager(groupFileName);
+
+ Set<Principal> principals = _manager.getGroupPrincipals();
+ assertEquals(2, principals.size());
+ assertTrue(principals.contains(new GroupPrincipal("myGroup")));
+ assertTrue(principals.contains(new GroupPrincipal("myGroup2")));
+ }
+
+ public void testCreateGroup() throws Exception
+ {
+ final String groupFileName = writeGroupFile();
+ _manager = new FileGroupManager(groupFileName);
+
+ Set<Principal> principals = _manager.getGroupPrincipals();
+ assertEquals(1, principals.size());
+
+ _manager.createGroup("myGroup2");
+
+ principals = _manager.getGroupPrincipals();
+ assertEquals(2, principals.size());
+ assertTrue(principals.contains(new GroupPrincipal("myGroup2")));
+ }
+
+ public void testRemoveGroup() throws Exception
+ {
+ final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS);
+ _manager = new FileGroupManager(groupFileName);
+
+ Set<Principal> principals = _manager.getGroupPrincipals();
+ assertEquals(1, principals.size());
+
+ _manager.removeGroup("myGroup");
+
+ principals = _manager.getGroupPrincipals();
+ assertEquals(0, principals.size());
+ }
+
+ public void testAddUserToGroup() throws Exception
+ {
+ final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS);
+ _manager = new FileGroupManager(groupFileName);
+
+ Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup");
+ assertEquals(1, principals.size());
+ assertFalse(principals.contains(new UsernamePrincipal("user2")));
+
+ _manager.addUserToGroup("user2", "myGroup");
+
+ principals = _manager.getUserPrincipalsForGroup("myGroup");
+ assertEquals(2, principals.size());
+ assertTrue(principals.contains(new UsernamePrincipal("user2")));
+ }
+
+ public void testRemoveUserInGroup() throws Exception
+ {
+ final String groupFileName = writeGroupFile(MY_GROUP, MYGROUP_USERS);
+ _manager = new FileGroupManager(groupFileName);
+
+ Set<Principal> principals = _manager.getUserPrincipalsForGroup("myGroup");
+ assertEquals(1, principals.size());
+ assertTrue(principals.contains(new UsernamePrincipal("user1")));
+
+ _manager.removeUserFromGroup("user1", "myGroup");
+
+ principals = _manager.getUserPrincipalsForGroup("myGroup");
+ assertEquals(0, principals.size());
+ }
+
+ private String writeGroupFile() throws Exception
+ {
+ return writeGroupFile(MY_GROUP, MYGROUP_USERS);
+ }
+
+ private String writeGroupFile(String... groupAndUsers) throws Exception
+ {
+ if (groupAndUsers.length % 2 != 0)
+ {
+ throw new IllegalArgumentException("Number of groupAndUsers must be even");
+ }
+
+ _tmpGroupFile = File.createTempFile("groups", "grp");
+ _tmpGroupFile.deleteOnExit();
+
+ Properties props = new Properties();
+ for (int i = 0 ; i < groupAndUsers.length; i=i+2)
+ {
+ String group = groupAndUsers[i];
+ String users = groupAndUsers[i+1];
+ props.put(group, users);
+ }
+
+ props.store(new FileOutputStream(_tmpGroupFile), "test group file");
+
+ return _tmpGroupFile.getCanonicalPath();
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.java
new file mode 100644
index 0000000000..e58a1a01f8
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalAccessorTest.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.server.security.group;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.model.GroupProvider;
+
+public class GroupPrincipalAccessorTest extends TestCase
+{
+ private static final String USERNAME = "username";
+
+ private GroupProvider _groupManager1 = mock(GroupProvider.class);
+ private GroupProvider _groupManager2 = mock(GroupProvider.class);
+
+ private Principal _group1 = mock(Principal.class);
+ private Principal _group2 = mock(Principal.class);
+
+ @Override
+ public void setUp()
+ {
+ when(_groupManager1.getGroupPrincipalsForUser(USERNAME)).thenReturn(Collections.singleton(_group1));
+ when(_groupManager2.getGroupPrincipalsForUser(USERNAME)).thenReturn(Collections.singleton(_group2));
+ }
+
+ public void testGetGroupPrincipals()
+ {
+ getAndAssertGroupPrincipals(_group1, _group2);
+ }
+
+ public void testGetGroupPrincipalsWhenAGroupManagerReturnsNull()
+ {
+ when(_groupManager1.getGroupPrincipalsForUser(USERNAME)).thenReturn(null);
+
+ getAndAssertGroupPrincipals(_group2);
+ }
+
+ public void testGetGroupPrincipalsWhenAGroupManagerReturnsEmptySet()
+ {
+ when(_groupManager2.getGroupPrincipalsForUser(USERNAME)).thenReturn(new HashSet<Principal>());
+
+ getAndAssertGroupPrincipals(_group1);
+ }
+
+ private void getAndAssertGroupPrincipals(Principal... expectedGroups)
+ {
+ GroupPrincipalAccessor groupPrincipalAccessor = new GroupPrincipalAccessor(Arrays.asList(_groupManager1, _groupManager2));
+
+ Set<Principal> actualGroupPrincipals = groupPrincipalAccessor.getGroupPrincipals(USERNAME);
+
+ Set<Principal> expectedGroupPrincipals = new HashSet<Principal>(Arrays.asList(expectedGroups));
+
+ assertEquals(expectedGroupPrincipals, actualGroupPrincipals);
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalTest.java b/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalTest.java
new file mode 100644
index 0000000000..d285a0797a
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/security/group/GroupPrincipalTest.java
@@ -0,0 +1,88 @@
+/*
+ *
+ * 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.security.group;
+
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
+
+import junit.framework.TestCase;
+
+public class GroupPrincipalTest extends TestCase
+{
+ public void testGetName()
+ {
+ final GroupPrincipal principal = new GroupPrincipal("group");
+ assertEquals("group", principal.getName());
+ }
+
+ public void testAddRejected()
+ {
+ final GroupPrincipal principal = new GroupPrincipal("group");
+ final UsernamePrincipal user = new UsernamePrincipal("name");
+
+ try
+ {
+ principal.addMember(user);
+ fail("Exception not thrown");
+ }
+ catch (UnsupportedOperationException uso)
+ {
+ // PASS
+ }
+ }
+
+ public void testEqualitySameName()
+ {
+ final String string = "string";
+ final GroupPrincipal principal1 = new GroupPrincipal(string);
+ final GroupPrincipal principal2 = new GroupPrincipal(string);
+ assertTrue(principal1.equals(principal2));
+ }
+
+ public void testEqualityEqualName()
+ {
+ final GroupPrincipal principal1 = new GroupPrincipal(new String("string"));
+ final GroupPrincipal principal2 = new GroupPrincipal(new String("string"));
+ assertTrue(principal1.equals(principal2));
+ }
+
+ public void testInequalityDifferentGroupPrincipals()
+ {
+ GroupPrincipal principal1 = new GroupPrincipal("string1");
+ GroupPrincipal principal2 = new GroupPrincipal("string2");
+ assertFalse(principal1.equals(principal2));
+ }
+
+ public void testInequalityNonGroupPrincipal()
+ {
+ GroupPrincipal principal = new GroupPrincipal("string");
+ assertFalse(principal.equals(new UsernamePrincipal("string")));
+ }
+
+ public void testInequalityNull()
+ {
+ GroupPrincipal principal = new GroupPrincipal("string");
+ assertFalse(principal.equals(null));
+ }
+
+
+
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java b/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java
deleted file mode 100644
index 23ee82eae6..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java
+++ /dev/null
@@ -1,119 +0,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.
- *
- */
-package org.apache.qpid.server.signal;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.test.utils.QpidTestCase;
-
-import java.lang.management.ManagementFactory;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-public class SignalHandlerTaskTest extends QpidTestCase
-{
- private static final Logger LOGGER = Logger.getLogger(SignalHandlerTaskTest.class);
- private static final String SUN_MISC_SIGNAL_CLASS = "sun.misc.Signal";
- private static final String SUN_MISC_SIGNAL_HANDLER_CLASS = "sun.misc.SignalHandler";
-
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void testSignalHandlerTask() throws Exception
- {
- final boolean expectedResult = classifyExpectedRegistrationResult();
- final int pid = getPID();
- final CountDownLatch latch = new CountDownLatch(1);
-
- SignalHandlerTask hupReparseTask = new SignalHandlerTask()
- {
- public void handle()
- {
- latch.countDown();
- LOGGER.info("Signal handled, latch decremented");
- }
- };
-
- assertEquals("Unexpected result trying to register Signal handler",
- expectedResult, hupReparseTask.register("HUP"));
- LOGGER.info("Signal handler was registered");
-
- assertEquals("unexpected count for the latch", 1, latch.getCount());
-
- if(expectedResult)
- {
- //registration succeeded as expected, so now
- //send SIGHUP and verify the handler was run
- String cmd = "/bin/kill -SIGHUP " + pid;
-
- LOGGER.info("Sending SIGHUP");
- Runtime.getRuntime().exec(cmd);
-
- assertTrue("HUP Signal was not handled in the allowed timeframe",
- latch.await(5, TimeUnit.SECONDS));
- }
- }
-
- public void testGetPlatformDescription() throws Exception
- {
- assertNotNull(SignalHandlerTask.getPlatformDescription());
- }
-
- private boolean classifyExpectedRegistrationResult()
- {
- String os = System.getProperty("os.name");
- if(String.valueOf(os).toLowerCase().contains("windows"))
- {
- //Windows does not support SIGHUP so registration will fail
- LOGGER.info("Running on windows, so we expect SIGHUP handler registration to fail");
- return false;
- }
-
- //otherwise, if the signal handler classes are present we would expect
- //registration to succeed
- boolean classesPresent = true;
- try
- {
- Class.forName(SUN_MISC_SIGNAL_CLASS);
- Class.forName(SUN_MISC_SIGNAL_HANDLER_CLASS);
- LOGGER.info("Signal handling classes were present so we expect SIGHUP handler registration to succeed");
- }
- catch (ClassNotFoundException cnfe)
- {
- classesPresent = false;
- }
-
- return classesPresent;
- }
-
- private int getPID()
- {
- String processName = ManagementFactory.getRuntimeMXBean().getName();
-
- int pid = Integer.parseInt(processName.substring(0,processName.indexOf('@')));
- LOGGER.info("PID was determined to be " + pid);
-
- return pid;
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java b/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java
index cd8d91d835..f0ecfb6407 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java
@@ -51,10 +51,6 @@ import org.apache.qpid.server.message.EnqueableMessage;
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.MockStoredMessage;
-import org.apache.qpid.server.store.ConfigurationRecoveryHandler;
-import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.MessageStoreRecoveryHandler;
-import org.apache.qpid.server.store.TransactionLogRecoveryHandler;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.BindingRecoveryHandler;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.ExchangeRecoveryHandler;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.QueueRecoveryHandler;
@@ -76,7 +72,6 @@ public class DurableConfigurationStoreTest extends QpidTestCase
private QueueRecoveryHandler _queueRecoveryHandler;
private ExchangeRecoveryHandler _exchangeRecoveryHandler;
private BindingRecoveryHandler _bindingRecoveryHandler;
- private ConfigurationRecoveryHandler.BrokerLinkRecoveryHandler _linkRecoveryHandler;
private MessageStoreRecoveryHandler _messageStoreRecoveryHandler;
private StoredMessageRecoveryHandler _storedMessageRecoveryHandler;
private TransactionLogRecoveryHandler _logRecoveryHandler;
@@ -116,7 +111,6 @@ public class DurableConfigurationStoreTest extends QpidTestCase
when(_recoveryHandler.begin(isA(MessageStore.class))).thenReturn(_exchangeRecoveryHandler);
when(_exchangeRecoveryHandler.completeExchangeRecovery()).thenReturn(_queueRecoveryHandler);
when(_queueRecoveryHandler.completeQueueRecovery()).thenReturn(_bindingRecoveryHandler);
- when(_bindingRecoveryHandler.completeBindingRecovery()).thenReturn(_linkRecoveryHandler);
when(_logRecoveryHandler.begin(any(MessageStore.class))).thenReturn(_queueEntryRecoveryHandler);
when(_queueEntryRecoveryHandler.completeQueueEntryRecovery()).thenReturn(_dtxRecordRecoveryHandler);
when(_exchange.getNameShortString()).thenReturn(AMQShortString.valueOf(EXCHANGE_NAME));
@@ -161,7 +155,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase
public void testBindQueue() throws Exception
{
AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false);
- Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), null, ROUTING_KEY, queue,
+ Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), ROUTING_KEY, queue,
_exchange, FieldTable.convertToMap(_bindingArgs));
_store.bindQueue(binding);
@@ -175,7 +169,7 @@ public class DurableConfigurationStoreTest extends QpidTestCase
public void testUnbindQueue() throws Exception
{
AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false);
- Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), null, ROUTING_KEY, queue,
+ Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), ROUTING_KEY, queue,
_exchange, FieldTable.convertToMap(_bindingArgs));
_store.bindQueue(binding);
diff --git a/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreCreatorTest.java b/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreCreatorTest.java
new file mode 100644
index 0000000000..e74937dd1c
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreCreatorTest.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.server.store;
+
+import org.apache.qpid.server.store.derby.DerbyMessageStore;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class MessageStoreCreatorTest extends QpidTestCase
+{
+ private static final String[] STORE_TYPES = {MemoryMessageStore.TYPE, DerbyMessageStore.TYPE};
+
+ public void testMessageStoreCreator()
+ {
+ MessageStoreCreator messageStoreCreator = new MessageStoreCreator();
+ for (String type : STORE_TYPES)
+ {
+ MessageStore store = messageStoreCreator.createMessageStore(type);
+ assertNotNull("Store of type " + type + " is not created", store);
+ }
+ }
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java b/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
index a1536565ad..ffd777243b 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.server.store;
+
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.qpid.AMQException;
@@ -35,11 +36,12 @@ import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DirectExchange;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.exchange.ExchangeType;
import org.apache.qpid.server.exchange.TopicExchange;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQPriorityQueue;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
@@ -48,11 +50,11 @@ import org.apache.qpid.server.queue.ConflationQueue;
import org.apache.qpid.server.queue.IncomingMessage;
import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.queue.SimpleAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
import java.io.File;
@@ -66,7 +68,7 @@ import java.util.Map;
* For persistent stores, it validates that Exchanges, Queues, Bindings and
* Messages are persisted and recovered correctly.
*/
-public class MessageStoreTest extends InternalBrokerBaseCase
+public class MessageStoreTest extends QpidTestCase
{
public static final int DEFAULT_PRIORTY_LEVEL = 5;
public static final String SELECTOR_VALUE = "Test = 'MST'";
@@ -93,11 +95,15 @@ public class MessageStoreTest extends InternalBrokerBaseCase
private AMQShortString queueOwner = new AMQShortString("MST");
- protected PropertiesConfiguration _config;
+ private PropertiesConfiguration _config;
+
+ private VirtualHost _virtualHost;
+ private Broker _broker;
public void setUp() throws Exception
{
super.setUp();
+ BrokerTestHelper.setUp();
String storePath = System.getProperty("QPID_WORK") + File.separator + getName();
@@ -107,9 +113,38 @@ public class MessageStoreTest extends InternalBrokerBaseCase
cleanup(new File(storePath));
+ _broker = BrokerTestHelper.createBrokerMock();
+
reloadVirtualHost();
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ public VirtualHost getVirtualHost()
+ {
+ return _virtualHost;
+ }
+
+ public PropertiesConfiguration getConfig()
+ {
+ return _config;
+ }
+
protected void reloadVirtualHost()
{
VirtualHost original = getVirtualHost();
@@ -119,8 +154,6 @@ public class MessageStoreTest extends InternalBrokerBaseCase
try
{
getVirtualHost().close();
- getVirtualHost().getApplicationRegistry().
- getVirtualHostRegistry().unregisterVirtualHost(getVirtualHost());
}
catch (Exception e)
{
@@ -131,7 +164,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase
try
{
- setVirtualHost(ApplicationRegistry.getInstance().createVirtualHost(new VirtualHostConfiguration(getClass().getName(), _config)));
+ _virtualHost = BrokerTestHelper.createVirtualHost(new VirtualHostConfiguration(getClass().getName(), _config, _broker));
}
catch (Exception e)
{
@@ -628,7 +661,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase
{
//To change body of implemented methods use File | Settings | File Templates.
}
- }, 0L);
+ });
}
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java b/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java
index 4aa023a25c..7c6891da71 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java
@@ -27,6 +27,7 @@ import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.abstraction.MessagePublishInfo;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
+import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.test.utils.QpidTestCase;
/**
@@ -86,10 +87,12 @@ public class ReferenceCountingTest extends QpidTestCase
AMQMessage message = new AMQMessage(storedMessage);
- message.incrementReference();
+ MessageReference ref = message.newReference();
assertEquals(1, _store.getMessageCount());
- message.decrementReference();
+
+ ref.release();
+
assertEquals(0, _store.getMessageCount());
}
@@ -142,13 +145,13 @@ public class ReferenceCountingTest extends QpidTestCase
AMQMessage message = new AMQMessage(storedMessage);
- message.incrementReference();
+ MessageReference ref = message.newReference();
// we call routing complete to set up the handle
// message.routingComplete(_store, _storeContext, new MessageHandleFactory());
assertEquals(1, _store.getMessageCount());
- message.incrementReference();
- message.decrementReference();
+ MessageReference ref2 = message.newReference();
+ ref.release();
assertEquals(1, _store.getMessageCount());
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java b/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java
index 8c5d2684ff..a3552639d1 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java
@@ -294,17 +294,12 @@ public class MockSubscription implements Subscription
private static class MockSessionModel implements AMQSessionModel
{
+ private final UUID _id = UUID.randomUUID();
@Override
- public int compareTo(AMQSessionModel o)
- {
- return 0;
- }
-
- @Override
- public UUID getQMFId()
+ public UUID getId()
{
- return null;
+ return _id;
}
@Override
@@ -409,6 +404,12 @@ public class MockSubscription implements Subscription
{
return 0;
}
+
+ @Override
+ public int compareTo(AMQSessionModel o)
+ {
+ return getId().compareTo(o.getId());
+ }
}
private static class MockConnectionModel implements AMQConnectionModel
diff --git a/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java b/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java
index 3272bd5447..d35a90e3c8 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java
@@ -21,14 +21,75 @@
package org.apache.qpid.server.subscription;
import org.apache.qpid.AMQException;
+import org.apache.qpid.common.AMQPFilterTypes;
+import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.queue.SimpleAMQQueue;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.TestableMemoryMessageStore;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.List;
-public class QueueBrowserUsesNoAckTest extends InternalBrokerBaseCase
+public class QueueBrowserUsesNoAckTest extends QpidTestCase
{
+ private AMQChannel _channel;
+ private SimpleAMQQueue _queue;
+ private MessageStore _messageStore;
+ private String _queueName;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel();
+ VirtualHost virtualHost = _channel.getVirtualHost();
+ _queueName = getTestName();
+ _queue = BrokerTestHelper.createQueue(_queueName, virtualHost);
+ _messageStore = virtualHost.getMessageStore();
+ Exchange defaultExchange = virtualHost.getExchangeRegistry().getDefaultExchange();
+ virtualHost.getBindingFactory().addBinding(_queueName, _queue, defaultExchange, null);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_channel != null)
+ {
+ _channel.getVirtualHost().close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ private AMQChannel getChannel()
+ {
+ return _channel;
+ }
+
+ private InternalTestProtocolSession getSession()
+ {
+ return (InternalTestProtocolSession)_channel.getProtocolSession();
+ }
+
+ private SimpleAMQQueue getQueue()
+ {
+ return _queue;
+ }
public void testQueueBrowserUsesNoAck() throws AMQException
{
@@ -39,7 +100,7 @@ public class QueueBrowserUsesNoAckTest extends InternalBrokerBaseCase
checkStoreContents(0);
//Send required messsages to the queue
- publishMessages(getSession(), getChannel(), sendMessageCount);
+ BrokerTestHelper.publishMessages(getChannel(), sendMessageCount, _queueName, ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString());
//Ensure they are stored
checkStoreContents(sendMessageCount);
@@ -74,4 +135,16 @@ public class QueueBrowserUsesNoAckTest extends InternalBrokerBaseCase
.equals(Subscription.State.SUSPENDED));
}
+ private void checkStoreContents(int messageCount)
+ {
+ assertEquals("Message header count incorrect in the MetaDataMap", messageCount, ((TestableMemoryMessageStore) _messageStore).getMessageCount());
+ }
+
+ private AMQShortString browse(AMQChannel channel, AMQQueue queue) throws AMQException
+ {
+ FieldTable filters = new FieldTable();
+ filters.put(AMQPFilterTypes.NO_CONSUME.getValue(), true);
+
+ return channel.subscribeToQueue(null, queue, true, filters, false, true);
+ }
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java b/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java
index 29f45bf7f4..89d434e95d 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/subscription/SubscriptionFactoryImplTest.java
@@ -23,20 +23,55 @@ package org.apache.qpid.server.subscription;
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.server.AMQChannel;
import org.apache.qpid.server.flow.WindowCreditManager;
+import org.apache.qpid.server.logging.UnitTestMessageLogger;
+import org.apache.qpid.server.logging.actors.GenericActor;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
import org.apache.qpid.server.protocol.ProtocolEngine_0_10;
import org.apache.qpid.server.transport.ServerConnection;
import org.apache.qpid.server.transport.ServerSession;
import org.apache.qpid.server.transport.ServerSessionDelegate;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.transport.Binary;
import org.apache.qpid.transport.MessageAcceptMode;
import org.apache.qpid.transport.MessageAcquireMode;
import org.apache.qpid.transport.MessageFlowMode;
import org.apache.qpid.transport.TestNetworkConnection;
-public class SubscriptionFactoryImplTest extends InternalBrokerBaseCase
+public class SubscriptionFactoryImplTest extends QpidTestCase
{
+ private AMQChannel _channel;
+ private AMQProtocolSession _session;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel();
+ _session = _channel.getProtocolSession();
+ GenericActor.setDefaultMessageLogger(new UnitTestMessageLogger(false));
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_channel != null)
+ {
+ _channel.getVirtualHost().close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
/**
* Tests that while creating Subscriptions of various types, the
* ID numbers assigned are allocated from a common sequence
@@ -46,35 +81,34 @@ public class SubscriptionFactoryImplTest extends InternalBrokerBaseCase
{
//create a No-Ack subscription, get the first Subscription ID
long previousId = 0;
- Subscription noAckSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, getSession(), new AMQShortString("1"), false, null, false, getChannel().getCreditManager());
+ Subscription noAckSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, _session, new AMQShortString("1"), false, null, false, _channel.getCreditManager());
previousId = noAckSub.getSubscriptionID();
//create an ack subscription, verify the next Subscription ID is used
- Subscription ackSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, getSession(), new AMQShortString("1"), true, null, false, getChannel().getCreditManager());
+ Subscription ackSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, _session, new AMQShortString("1"), true, null, false, _channel.getCreditManager());
assertEquals("Unexpected Subscription ID allocated", previousId + 1, ackSub.getSubscriptionID());
previousId = ackSub.getSubscriptionID();
//create a browser subscription
FieldTable filters = new FieldTable();
filters.put(AMQPFilterTypes.NO_CONSUME.getValue(), true);
- Subscription browerSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, getSession(), new AMQShortString("1"), true, null, false, getChannel().getCreditManager());
+ Subscription browerSub = SubscriptionFactoryImpl.INSTANCE.createSubscription(1, _session, new AMQShortString("1"), true, null, false, _channel.getCreditManager());
assertEquals("Unexpected Subscription ID allocated", previousId + 1, browerSub.getSubscriptionID());
previousId = browerSub.getSubscriptionID();
//create an BasicGet NoAck subscription
- Subscription getNoAckSub = SubscriptionFactoryImpl.INSTANCE.createBasicGetNoAckSubscription(getChannel(), getSession(), new AMQShortString("1"), null, false,
- getChannel().getCreditManager(),getChannel().getClientDeliveryMethod(), getChannel().getRecordDeliveryMethod());
+ Subscription getNoAckSub = SubscriptionFactoryImpl.INSTANCE.createBasicGetNoAckSubscription(_channel, _session, new AMQShortString("1"), null, false,
+ _channel.getCreditManager(),_channel.getClientDeliveryMethod(), _channel.getRecordDeliveryMethod());
assertEquals("Unexpected Subscription ID allocated", previousId + 1, getNoAckSub.getSubscriptionID());
previousId = getNoAckSub.getSubscriptionID();
//create a 0-10 subscription
ServerConnection conn = new ServerConnection(1);
- ProtocolEngine_0_10 engine = new ProtocolEngine_0_10(conn, new TestNetworkConnection(), getRegistry());
- conn.setVirtualHost(getVirtualHost());
- conn.setConnectionConfig(engine);
+ ProtocolEngine_0_10 engine = new ProtocolEngine_0_10(conn, new TestNetworkConnection());
+ conn.setVirtualHost(_session.getVirtualHost());
ServerSessionDelegate sesDel = new ServerSessionDelegate();
Binary name = new Binary(new byte[]{new Byte("1")});
- ServerSession session = new ServerSession(conn, sesDel, name, 0, engine);
+ ServerSession session = new ServerSession(conn, sesDel, name, 0);
Subscription sub_0_10 = SubscriptionFactoryImpl.INSTANCE.createSubscription(session, "1", MessageAcceptMode.EXPLICIT,
MessageAcquireMode.PRE_ACQUIRED, MessageFlowMode.WINDOW, new WindowCreditManager(), null, null);
diff --git a/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java b/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java
index d775b0f2f8..3389773ff8 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/transport/ServerSessionTest.java
@@ -1,5 +1,4 @@
/*
- *
* 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
@@ -16,19 +15,17 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
*/
package org.apache.qpid.server.transport;
-import java.util.UUID;
-
-import org.apache.qpid.server.configuration.MockConnectionConfig;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.GenericActor;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.transport.Binary;
-public class ServerSessionTest extends InternalBrokerBaseCase
+public class ServerSessionTest extends QpidTestCase
{
private VirtualHost _virtualHost;
@@ -37,31 +34,44 @@ public class ServerSessionTest extends InternalBrokerBaseCase
public void setUp() throws Exception
{
super.setUp();
- _virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts().iterator().next();
+ BrokerTestHelper.setUp();
+ _virtualHost = BrokerTestHelper.createVirtualHost(getName());
+ GenericActor.setDefaultMessageLogger(CurrentActor.get().getRootMessageLogger());
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testCompareTo() throws Exception
{
ServerConnection connection = new ServerConnection(1);
- connection.setConnectionConfig(createConnectionConfig());
+ connection.setVirtualHost(_virtualHost);
ServerSession session1 = new ServerSession(connection, new ServerSessionDelegate(),
- new Binary(getName().getBytes()), 0 , connection.getConfig());
+ new Binary(getName().getBytes()), 0);
// create a session with the same name but on a different connection
ServerConnection connection2 = new ServerConnection(2);
- connection2.setConnectionConfig(createConnectionConfig());
+ connection2.setVirtualHost(_virtualHost);
ServerSession session2 = new ServerSession(connection2, new ServerSessionDelegate(),
- new Binary(getName().getBytes()), 0 , connection2.getConfig());
+ new Binary(getName().getBytes()), 0);
assertFalse("Unexpected compare result", session1.compareTo(session2) == 0);
assertEquals("Unexpected compare result", 0, session1.compareTo(session1));
}
- private MockConnectionConfig createConnectionConfig()
- {
- return new MockConnectionConfig(UUID.randomUUID(), null, null,
- false, 1, _virtualHost, "address", Boolean.TRUE, Boolean.TRUE, Boolean.TRUE,
- "authid", "remoteProcessName", new Integer(1967), new Integer(1970), _virtualHost.getConfigStore(), Boolean.FALSE);
- }
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/txn/AsyncAutoCommitTransactionTest.java b/java/broker/src/test/java/org/apache/qpid/server/txn/AsyncAutoCommitTransactionTest.java
index 1aa91fa98a..5c1012d50b 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/txn/AsyncAutoCommitTransactionTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/txn/AsyncAutoCommitTransactionTest.java
@@ -82,7 +82,7 @@ public class AsyncAutoCommitTransactionTest extends QpidTestCase
AsyncAutoCommitTransaction asyncAutoCommitTransaction =
new AsyncAutoCommitTransaction(_messageStore, _futureRecorder);
- asyncAutoCommitTransaction.enqueue(Collections.singletonList(_queue), _message, _postTransactionAction, System.currentTimeMillis());
+ asyncAutoCommitTransaction.enqueue(Collections.singletonList(_queue), _message, _postTransactionAction);
verify(_storeTransaction).enqueueMessage(_queue, _message);
verify(_futureRecorder).recordFuture(_future, _postTransactionAction);
diff --git a/java/broker/src/test/java/org/apache/qpid/server/txn/AutoCommitTransactionTest.java b/java/broker/src/test/java/org/apache/qpid/server/txn/AutoCommitTransactionTest.java
index cd3fe3c473..06b8539eb1 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/txn/AutoCommitTransactionTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/txn/AutoCommitTransactionTest.java
@@ -137,7 +137,7 @@ public class AutoCommitTransactionTest extends QpidTestCase
_message = createTestMessage(false);
_queues = createTestBaseQueues(new boolean[] {false, false, false});
- _transaction.enqueue(_queues, _message, _action, 0L);
+ _transaction.enqueue(_queues, _message, _action);
assertEquals("Enqueue of non-persistent message must not cause message to be enqueued", 0, _storeTransaction.getNumberOfEnqueuedMessages());
assertEquals("Unexpected transaction state", TransactionState.NOT_STARTED, _storeTransaction.getState());
@@ -157,7 +157,7 @@ public class AutoCommitTransactionTest extends QpidTestCase
_message = createTestMessage(true);
_queues = createTestBaseQueues(new boolean[] {false, false, false});
- _transaction.enqueue(_queues, _message, _action, 0L);
+ _transaction.enqueue(_queues, _message, _action);
assertEquals("Enqueue of persistent message to non-durable queues must not cause message to be enqueued", 0, _storeTransaction.getNumberOfEnqueuedMessages());
assertEquals("Unexpected transaction state", TransactionState.NOT_STARTED, _storeTransaction.getState());
@@ -175,7 +175,7 @@ public class AutoCommitTransactionTest extends QpidTestCase
_message = createTestMessage(true);
_queues = createTestBaseQueues(new boolean[] {false, true, false, true});
- _transaction.enqueue(_queues, _message, _action, 0L);
+ _transaction.enqueue(_queues, _message, _action);
assertEquals("Enqueue of persistent message to durable/non-durable queues must cause messages to be enqueued", 2, _storeTransaction.getNumberOfEnqueuedMessages());
assertEquals("Unexpected transaction state", TransactionState.COMMITTED, _storeTransaction.getState());
@@ -198,7 +198,7 @@ public class AutoCommitTransactionTest extends QpidTestCase
try
{
- _transaction.enqueue(_queues, _message, _action, 0L);
+ _transaction.enqueue(_queues, _message, _action);
fail("Exception not thrown");
}
catch (RuntimeException re)
diff --git a/java/broker/src/test/java/org/apache/qpid/server/txn/LocalTransactionTest.java b/java/broker/src/test/java/org/apache/qpid/server/txn/LocalTransactionTest.java
index 5992829f37..4904cbc6fb 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/txn/LocalTransactionTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/txn/LocalTransactionTest.java
@@ -140,7 +140,7 @@ public class LocalTransactionTest extends QpidTestCase
_message = createTestMessage(false);
_queues = createTestBaseQueues(new boolean[] {false, false, false});
- _transaction.enqueue(_queues, _message, _action1, 0L);
+ _transaction.enqueue(_queues, _message, _action1);
assertEquals("Enqueue of non-persistent message must not cause message to be enqueued", 0, _storeTransaction.getNumberOfEnqueuedMessages());
assertEquals("Unexpected transaction state", TransactionState.NOT_STARTED, _storeTransaction.getState());
@@ -156,7 +156,7 @@ public class LocalTransactionTest extends QpidTestCase
_message = createTestMessage(true);
_queues = createTestBaseQueues(new boolean[] {false, false, false});
- _transaction.enqueue(_queues, _message, _action1, 0L);
+ _transaction.enqueue(_queues, _message, _action1);
assertEquals("Enqueue of persistent message to non-durable queues must not cause message to be enqueued", 0, _storeTransaction.getNumberOfEnqueuedMessages());
assertEquals("Unexpected transaction state", TransactionState.NOT_STARTED, _storeTransaction.getState());
@@ -173,7 +173,7 @@ public class LocalTransactionTest extends QpidTestCase
_message = createTestMessage(true);
_queues = createTestBaseQueues(new boolean[] {false, true, false, true});
- _transaction.enqueue(_queues, _message, _action1, 0L);
+ _transaction.enqueue(_queues, _message, _action1);
assertEquals("Enqueue of persistent message to durable/non-durable queues must cause messages to be enqueued", 2, _storeTransaction.getNumberOfEnqueuedMessages());
assertEquals("Unexpected transaction state", TransactionState.STARTED, _storeTransaction.getState());
@@ -196,7 +196,7 @@ public class LocalTransactionTest extends QpidTestCase
try
{
- _transaction.enqueue(_queues, _message, _action1, 0L);
+ _transaction.enqueue(_queues, _message, _action1);
fail("Exception not thrown");
}
catch (RuntimeException re)
@@ -217,7 +217,7 @@ public class LocalTransactionTest extends QpidTestCase
{
_message = createTestMessage(false);
_queue = createTestAMQQueue(false);
-
+
_transaction.dequeue(_queue, _message, _action1);
assertEquals("Dequeue of non-persistent message must not cause message to be enqueued", 0, _storeTransaction.getNumberOfEnqueuedMessages());
@@ -465,7 +465,6 @@ public class LocalTransactionTest extends QpidTestCase
*/
public void testRollbackWorkWithAdditionalPostAction() throws Exception
{
-
_message = createTestMessage(true);
_queue = createTestAMQQueue(true);
@@ -482,6 +481,122 @@ public class LocalTransactionTest extends QpidTestCase
assertTrue("Rollback action2 must be fired", _action1.isRollbackActionFired());
}
+ public void testFirstEnqueueRecordsTransactionStartAndUpdateTime() throws Exception
+ {
+ assertEquals("Unexpected transaction start time before test", 0, _transaction.getTransactionStartTime());
+ assertEquals("Unexpected transaction update time before test", 0, _transaction.getTransactionUpdateTime());
+
+ _message = createTestMessage(true);
+ _queue = createTestAMQQueue(true);
+
+ long startTime = System.currentTimeMillis();
+ _transaction.enqueue(_queue, _message, _action1);
+
+ assertTrue("Transaction start time should have been recorded", _transaction.getTransactionStartTime() >= startTime);
+ assertEquals("Transaction update time should be the same as transaction start time", _transaction.getTransactionStartTime(), _transaction.getTransactionUpdateTime());
+ }
+
+ public void testSubsequentEnqueueAdvancesTransactionUpdateTimeOnly() throws Exception
+ {
+ assertEquals("Unexpected transaction start time before test", 0, _transaction.getTransactionStartTime());
+ assertEquals("Unexpected transaction update time before test", 0, _transaction.getTransactionUpdateTime());
+
+ _message = createTestMessage(true);
+ _queue = createTestAMQQueue(true);
+
+ _transaction.enqueue(_queue, _message, _action1);
+
+ final long transactionStartTimeAfterFirstEnqueue = _transaction.getTransactionStartTime();
+ final long transactionUpdateTimeAfterFirstEnqueue = _transaction.getTransactionUpdateTime();
+
+ Thread.sleep(1);
+ _transaction.enqueue(_queue, _message, _action2);
+
+ final long transactionStartTimeAfterSecondEnqueue = _transaction.getTransactionStartTime();
+ final long transactionUpdateTimeAfterSecondEnqueue = _transaction.getTransactionUpdateTime();
+
+ assertEquals("Transaction start time after second enqueue should be unchanged", transactionStartTimeAfterFirstEnqueue, transactionStartTimeAfterSecondEnqueue);
+ assertTrue("Transaction update time after second enqueue should be greater than first update time", transactionUpdateTimeAfterSecondEnqueue > transactionUpdateTimeAfterFirstEnqueue);
+ }
+
+ public void testFirstDequeueRecordsTransactionStartAndUpdateTime() throws Exception
+ {
+ assertEquals("Unexpected transaction start time before test", 0, _transaction.getTransactionStartTime());
+ assertEquals("Unexpected transaction update time before test", 0, _transaction.getTransactionUpdateTime());
+
+ _message = createTestMessage(true);
+ _queue = createTestAMQQueue(true);
+
+ long startTime = System.currentTimeMillis();
+ _transaction.dequeue(_queue, _message, _action1);
+
+ assertTrue("Transaction start time should have been recorded", _transaction.getTransactionStartTime() >= startTime);
+ assertEquals("Transaction update time should be the same as transaction start time", _transaction.getTransactionStartTime(), _transaction.getTransactionUpdateTime());
+ }
+
+ public void testMixedEnqueuesAndDequeuesAdvancesTransactionUpdateTimeOnly() throws Exception
+ {
+ assertEquals("Unexpected transaction start time before test", 0, _transaction.getTransactionStartTime());
+ assertEquals("Unexpected transaction update time before test", 0, _transaction.getTransactionUpdateTime());
+
+ _message = createTestMessage(true);
+ _queue = createTestAMQQueue(true);
+
+ _transaction.enqueue(_queue, _message, _action1);
+
+ final long transactionStartTimeAfterFirstEnqueue = _transaction.getTransactionStartTime();
+ final long transactionUpdateTimeAfterFirstEnqueue = _transaction.getTransactionUpdateTime();
+
+ Thread.sleep(1);
+ _transaction.dequeue(_queue, _message, _action2);
+
+ final long transactionStartTimeAfterFirstDequeue = _transaction.getTransactionStartTime();
+ final long transactionUpdateTimeAfterFirstDequeue = _transaction.getTransactionUpdateTime();
+
+ assertEquals("Transaction start time after first dequeue should be unchanged", transactionStartTimeAfterFirstEnqueue, transactionStartTimeAfterFirstDequeue);
+ assertTrue("Transaction update time after first dequeue should be greater than first update time", transactionUpdateTimeAfterFirstDequeue > transactionUpdateTimeAfterFirstEnqueue);
+ }
+
+ public void testCommitResetsTransactionStartAndUpdateTime() throws Exception
+ {
+ assertEquals("Unexpected transaction start time before test", 0, _transaction.getTransactionStartTime());
+ assertEquals("Unexpected transaction update time before test", 0, _transaction.getTransactionUpdateTime());
+
+ _message = createTestMessage(true);
+ _queue = createTestAMQQueue(true);
+
+ long startTime = System.currentTimeMillis();
+ _transaction.enqueue(_queue, _message, _action1);
+
+ assertTrue(_transaction.getTransactionStartTime() >= startTime);
+ assertTrue(_transaction.getTransactionUpdateTime() >= startTime);
+
+ _transaction.commit();
+
+ assertEquals("Transaction start time should be reset after commit", 0, _transaction.getTransactionStartTime());
+ assertEquals("Transaction update time should be reset after commit", 0, _transaction.getTransactionUpdateTime());
+ }
+
+ public void testRollbackResetsTransactionStartAndUpdateTime() throws Exception
+ {
+ assertEquals("Unexpected transaction start time before test", 0, _transaction.getTransactionStartTime());
+ assertEquals("Unexpected transaction update time before test", 0, _transaction.getTransactionUpdateTime());
+
+ _message = createTestMessage(true);
+ _queue = createTestAMQQueue(true);
+
+ long startTime = System.currentTimeMillis();
+ _transaction.enqueue(_queue, _message, _action1);
+
+ assertTrue(_transaction.getTransactionStartTime() >= startTime);
+ assertTrue(_transaction.getTransactionUpdateTime() >= startTime);
+
+ _transaction.rollback();
+
+ assertEquals("Transaction start time should be reset after rollback", 0, _transaction.getTransactionStartTime());
+ assertEquals("Transaction update time should be reset after rollback", 0, _transaction.getTransactionUpdateTime());
+ }
+
private Collection<QueueEntry> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags)
{
Collection<QueueEntry> queueEntries = new ArrayList<QueueEntry>();
diff --git a/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java b/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java
index f3b6cab626..aa5b555b3b 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java
@@ -22,7 +22,6 @@ package org.apache.qpid.server.txn;
import org.apache.commons.lang.NotImplementedException;
-import org.apache.qpid.server.configuration.SessionConfig;
import org.apache.qpid.server.message.AMQMessageHeader;
import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.server.message.ServerMessage;
@@ -68,11 +67,6 @@ class MockServerMessage implements ServerMessage
throw new NotImplementedException();
}
- public SessionConfig getSessionConfig()
- {
- throw new NotImplementedException();
- }
-
public String getRoutingKey()
{
throw new NotImplementedException();
diff --git a/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java b/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
new file mode 100644
index 0000000000..3be8927224
--- /dev/null
+++ b/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
@@ -0,0 +1,209 @@
+/*
+ *
+ * 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.util;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.net.SocketAddress;
+import java.util.Collections;
+import java.util.UUID;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.abstraction.MessagePublishInfo;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.server.exchange.DefaultExchangeFactory;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.logging.RootMessageLogger;
+import org.apache.qpid.server.logging.SystemOutMessageLogger;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.GenericActor;
+import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.protocol.AMQProtocolSession;
+import org.apache.qpid.server.protocol.InternalTestProtocolSession;
+import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.apache.qpid.server.queue.SimpleAMQQueue;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.SubjectCreator;
+import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.store.TestableMemoryMessageStore;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.virtualhost.VirtualHostImpl;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+
+public class BrokerTestHelper
+{
+
+ protected static final String BROKER_STORE_CLASS_NAME_KEY = "brokerstore.class.name";
+ protected static final String JSON_BROKER_STORE_CLASS_NAME = JsonConfigurationEntryStore.class.getName();
+
+ public static Broker createBrokerMock()
+ {
+ SubjectCreator subjectCreator = mock(SubjectCreator.class);
+ when(subjectCreator.getMechanisms()).thenReturn("");
+ Broker broker = mock(Broker.class);
+ when(broker.getAttribute(Broker.SESSION_COUNT_LIMIT)).thenReturn(1);
+ when(broker.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).thenReturn(10000l);
+ when(broker.getId()).thenReturn(UUID.randomUUID());
+ when(broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(subjectCreator);
+ RootMessageLogger rootMessageLogger = CurrentActor.get().getRootMessageLogger();
+ when(broker.getRootMessageLogger()).thenReturn(rootMessageLogger);
+ when(broker.getVirtualHostRegistry()).thenReturn(new VirtualHostRegistry());
+ when(broker.getSecurityManager()).thenReturn(new SecurityManager(null));
+ GenericActor.setDefaultMessageLogger(rootMessageLogger);
+ return broker;
+ }
+
+ public static void setUp()
+ {
+ CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
+ }
+
+ public static void tearDown()
+ {
+ CurrentActor.remove();
+ }
+
+ public static VirtualHost createVirtualHost(VirtualHostConfiguration virtualHostConfiguration, VirtualHostRegistry virtualHostRegistry)
+ throws Exception
+ {
+ StatisticsGatherer statisticsGatherer = mock(StatisticsGatherer.class);
+ VirtualHost host = new VirtualHostImpl(virtualHostRegistry, statisticsGatherer, new SecurityManager(null), virtualHostConfiguration);
+ virtualHostRegistry.registerVirtualHost(host);
+ return host;
+ }
+
+ public static VirtualHost createVirtualHost(VirtualHostConfiguration virtualHostConfiguration) throws Exception
+ {
+ return new VirtualHostImpl(null, mock(StatisticsGatherer.class), new SecurityManager(null), virtualHostConfiguration);
+ }
+
+ public static VirtualHost createVirtualHost(String name, VirtualHostRegistry virtualHostRegistry) throws Exception
+ {
+ VirtualHostConfiguration vhostConfig = createVirtualHostConfiguration(name);
+ return createVirtualHost(vhostConfig, virtualHostRegistry);
+ }
+
+ public static VirtualHost createVirtualHost(String name) throws Exception
+ {
+ VirtualHostConfiguration configuration = createVirtualHostConfiguration(name);
+ return createVirtualHost(configuration);
+ }
+
+ private static VirtualHostConfiguration createVirtualHostConfiguration(String name) throws ConfigurationException
+ {
+ VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(name, new PropertiesConfiguration(), createBrokerMock());
+ vhostConfig.setMessageStoreClass(TestableMemoryMessageStore.class.getName());
+ return vhostConfig;
+ }
+
+ public static AMQChannel createChannel(int channelId, AMQProtocolSession session) throws AMQException
+ {
+ AMQChannel channel = new AMQChannel(session, channelId, session.getVirtualHost().getMessageStore());
+ session.addChannel(channel);
+ return channel;
+ }
+
+ public static AMQChannel createChannel(int channelId) throws Exception
+ {
+ InternalTestProtocolSession session = createSession();
+ return createChannel(channelId, session);
+ }
+
+ public static AMQChannel createChannel() throws Exception
+ {
+ return createChannel(1);
+ }
+
+ public static InternalTestProtocolSession createSession() throws Exception
+ {
+ return createSession("test");
+ }
+
+ public static InternalTestProtocolSession createSession(String hostName) throws Exception
+ {
+ VirtualHost virtualHost = createVirtualHost(hostName);
+ return new InternalTestProtocolSession(virtualHost, createBrokerMock());
+ }
+
+ public static Exchange createExchange(String hostName) throws Exception
+ {
+ SecurityManager securityManager = new SecurityManager(null);
+ VirtualHost virtualHost = mock(VirtualHost.class);
+ when(virtualHost.getName()).thenReturn(hostName);
+ when(virtualHost.getSecurityManager()).thenReturn(securityManager);
+ DefaultExchangeFactory factory = new DefaultExchangeFactory(virtualHost);
+ return factory.createExchange("amp.direct", "direct", false, false);
+ }
+
+ public static void publishMessages(AMQChannel channel, int numberOfMessages, String queueName, String exchangeName) throws AMQException
+ {
+ AMQShortString rouningKey = new AMQShortString(queueName);
+ AMQShortString exchangeNameAsShortString = new AMQShortString(exchangeName);
+ MessagePublishInfo info = mock(MessagePublishInfo.class);
+ when(info.getExchange()).thenReturn(exchangeNameAsShortString);
+ when(info.getRoutingKey()).thenReturn(rouningKey);
+
+ Exchange exchange = channel.getVirtualHost().getExchangeRegistry().getExchange(exchangeName);
+ for (int count = 0; count < numberOfMessages; count++)
+ {
+ channel.setPublishFrame(info, exchange);
+
+ // Set the body size
+ ContentHeaderBody _headerBody = new ContentHeaderBody();
+ _headerBody.setBodySize(0);
+
+ // Set Minimum properties
+ BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
+
+ properties.setExpiration(0L);
+ properties.setTimestamp(System.currentTimeMillis());
+
+ // Make Message Persistent
+ properties.setDeliveryMode((byte) 2);
+
+ _headerBody.setProperties(properties);
+
+ channel.publishContentHeader(_headerBody);
+ }
+ channel.sync();
+ }
+
+ public static SimpleAMQQueue createQueue(String queueName, VirtualHost virtualHost) throws AMQException
+ {
+ SimpleAMQQueue queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), queueName, false, null,
+ false, false, virtualHost, Collections.<String, Object>emptyMap());
+ virtualHost.getQueueRegistry().registerQueue(queue);
+ return queue;
+ }
+
+
+}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java b/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
deleted file mode 100644
index d7a9078412..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
+++ /dev/null
@@ -1,372 +0,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.
- *
- */
-package org.apache.qpid.server.util;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.common.AMQPFilterTypes;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.BasicContentHeaderProperties;
-import org.apache.qpid.framing.ContentHeaderBody;
-import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.framing.abstraction.MessagePublishInfo;
-import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.logging.SystemOutMessageLogger;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.TestLogActor;
-import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.queue.AMQQueueFactory;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
-import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.TestableMemoryMessageStore;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.test.utils.QpidTestCase;
-
-
-public class InternalBrokerBaseCase extends QpidTestCase
-{
- private IApplicationRegistry _registry;
- private MessageStore _messageStore;
- private AMQChannel _channel;
- private InternalTestProtocolSession _session;
- private VirtualHost _virtualHost;
- private AMQQueue _queue;
- private AMQShortString QUEUE_NAME;
- private ServerConfiguration _configuration;
- private XMLConfiguration _configXml = new XMLConfiguration();
- private boolean _started = false;
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- _configXml.addProperty("virtualhosts.virtualhost.name", "test");
- _configXml.addProperty("virtualhosts.virtualhost.test.store.class", TestableMemoryMessageStore.class.getName());
-
- _configXml.addProperty("virtualhosts.virtualhost(-1).name", getName());
- _configXml.addProperty("virtualhosts.virtualhost(-1)."+getName()+".store.class", TestableMemoryMessageStore.class.getName());
-
- createBroker();
- }
-
- protected void createBroker() throws Exception
- {
- _started = true;
- CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
-
- _configuration = new ServerConfiguration(_configXml);
-
- configure();
-
- _registry = createApplicationRegistry();
- ApplicationRegistry.initialise(_registry);
- _registry.getVirtualHostRegistry().setDefaultVirtualHostName(getName());
- _virtualHost = _registry.getVirtualHostRegistry().getVirtualHost(getName());
-
- QUEUE_NAME = new AMQShortString("test");
- // Create a queue on the test Vhost.. this will aid in diagnosing duff tests
- // as the ExpiredMessage Task will log with the test Name.
- _queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), QUEUE_NAME.asString(), false, "testowner",
- false, false, _virtualHost, null);
-
- Exchange defaultExchange = _virtualHost.getExchangeRegistry().getDefaultExchange();
- _virtualHost.getBindingFactory().addBinding(QUEUE_NAME.toString(), _queue, defaultExchange, null);
-
- _virtualHost = _registry.getVirtualHostRegistry().getVirtualHost("test");
- _messageStore = _virtualHost.getMessageStore();
-
- _queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), getName(), false, "testowner",
- false, false, _virtualHost, null);
-
- _virtualHost.getQueueRegistry().registerQueue(_queue);
-
- defaultExchange = _virtualHost.getExchangeRegistry().getDefaultExchange();
-
- _virtualHost.getBindingFactory().addBinding(getName(), _queue, defaultExchange, null);
-
- _session = new InternalTestProtocolSession(_virtualHost);
- CurrentActor.set(_session.getLogActor());
-
- _channel = new AMQChannel(_session, 1, _messageStore);
-
- _session.addChannel(_channel);
- }
-
- protected IApplicationRegistry createApplicationRegistry() throws ConfigurationException
- {
- return new TestApplicationRegistry(_configuration);
- }
-
- protected void configure()
- {
- // Allow other tests to override configuration
- }
-
- protected void stopBroker()
- {
- try
- {
- //Remove the ProtocolSession Actor added during createBroker
- CurrentActor.remove();
- }
- finally
- {
- ApplicationRegistry.remove();
- _started = false;
- }
- }
-
-
- public void tearDown() throws Exception
- {
- try
- {
- if (_started)
- {
- stopBroker();
- }
- }
- finally
- {
- super.tearDown();
- // Purge Any erroneously added actors
- CurrentActor.removeAll();
- }
- }
-
- protected void checkStoreContents(int messageCount)
- {
- assertEquals("Message header count incorrect in the MetaDataMap", messageCount, ((TestableMemoryMessageStore) _messageStore).getMessageCount());
-
- //The above publish message is sufficiently small not to fit in the header so no Body is required.
- //assertEquals("Message body count incorrect in the ContentBodyMap", messageCount, ((TestableMemoryMessageStore) _messageStore).getContentBodyMap().size());
- }
-
- protected AMQShortString subscribe(InternalTestProtocolSession session, AMQChannel channel, AMQQueue queue)
- {
- try
- {
- return channel.subscribeToQueue(null, queue, true, null, false, true);
- }
- catch (AMQException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- //Keep the compiler happy
- return null;
- }
-
- protected AMQShortString browse(AMQChannel channel, AMQQueue queue)
- {
- try
- {
- FieldTable filters = new FieldTable();
- filters.put(AMQPFilterTypes.NO_CONSUME.getValue(), true);
-
- return channel.subscribeToQueue(null, queue, true, filters, false, true);
- }
- catch (AMQException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- //Keep the compiler happy
- return null;
- }
-
- public void publishMessages(InternalTestProtocolSession session, AMQChannel channel, int messages) throws AMQException
- {
- MessagePublishInfo info = new MessagePublishInfo()
- {
- public AMQShortString getExchange()
- {
- return ExchangeDefaults.DEFAULT_EXCHANGE_NAME;
- }
-
- public void setExchange(AMQShortString exchange)
- {
-
- }
-
- public boolean isImmediate()
- {
- return false;
- }
-
- public boolean isMandatory()
- {
- return false;
- }
-
- public AMQShortString getRoutingKey()
- {
- return new AMQShortString(getName());
- }
- };
-
- for (int count = 0; count < messages; count++)
- {
- channel.setPublishFrame(info, _virtualHost.getExchangeRegistry().getExchange(info.getExchange()));
-
- //Set the body size
- ContentHeaderBody _headerBody = new ContentHeaderBody();
- _headerBody.setBodySize(0);
-
- //Set Minimum properties
- BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
-
- properties.setExpiration(0L);
- properties.setTimestamp(System.currentTimeMillis());
-
- //Make Message Persistent
- properties.setDeliveryMode((byte) 2);
-
- _headerBody.setProperties(properties);
-
- channel.publishContentHeader(_headerBody);
- }
- channel.sync();
- }
-
- public void acknowledge(AMQChannel channel, long deliveryTag)
- {
- try
- {
- channel.acknowledgeMessage(deliveryTag, false);
- }
- catch (AMQException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- public IApplicationRegistry getRegistry()
- {
- return _registry;
- }
-
- public void setRegistry(IApplicationRegistry registry)
- {
- _registry = registry;
- }
-
- public MessageStore getMessageStore()
- {
- return _messageStore;
- }
-
- public void setMessageStore(MessageStore messageStore)
- {
- _messageStore = messageStore;
- }
-
- public AMQChannel getChannel()
- {
- return _channel;
- }
-
- public void setChannel(AMQChannel channel)
- {
- _channel = channel;
- }
-
- public InternalTestProtocolSession getSession()
- {
- return _session;
- }
-
- public void setSession(InternalTestProtocolSession session)
- {
- _session = session;
- }
-
- public VirtualHost getVirtualHost()
- {
- return _virtualHost;
- }
-
- public void setVirtualHost(VirtualHost virtualHost)
- {
- _virtualHost = virtualHost;
- }
-
- public AMQQueue getQueue()
- {
- return _queue;
- }
-
- public void setQueue(AMQQueue queue)
- {
- _queue = queue;
- }
-
- public AMQShortString getQUEUE_NAME()
- {
- return QUEUE_NAME;
- }
-
- public void setQUEUE_NAME(AMQShortString QUEUE_NAME)
- {
- this.QUEUE_NAME = QUEUE_NAME;
- }
-
- public ServerConfiguration getConfiguration()
- {
- return _configuration;
- }
-
- public void setConfiguration(ServerConfiguration configuration)
- {
- _configuration = configuration;
- }
-
- public XMLConfiguration getConfigXml()
- {
- return _configXml;
- }
-
- public void setConfigXml(XMLConfiguration configXml)
- {
- _configXml = configXml;
- }
-
- public boolean isStarted()
- {
- return _started;
- }
-
- public void setStarted(boolean started)
- {
- _started = started;
- }
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java b/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
deleted file mode 100644
index a64ab620ab..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
+++ /dev/null
@@ -1,121 +0,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.
- *
- */
-package org.apache.qpid.server.util;
-
-import java.net.SocketAddress;
-import java.util.Collections;
-import java.util.Map;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
-import org.apache.qpid.server.logging.NullRootMessageLogger;
-import org.apache.qpid.server.logging.actors.BrokerActor;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.GenericActor;
-import org.apache.qpid.server.plugins.PluginManager;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabase;
-import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.IAuthenticationManagerRegistry;
-import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
-
-import java.util.Properties;
-
-public class TestApplicationRegistry extends ApplicationRegistry
-{
-
- public TestApplicationRegistry(ServerConfiguration config) throws ConfigurationException
- {
- super(config);
- }
-
- @Override
- public void initialise() throws Exception
- {
- CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger()));
- GenericActor.setDefaultMessageLogger(new NullRootMessageLogger());
- super.initialise();
- }
-
- @Override
- protected IAuthenticationManagerRegistry createAuthenticationManagerRegistry(
- ServerConfiguration _configuration, PluginManager _pluginManager)
- throws ConfigurationException
- {
- final Properties users = new Properties();
- users.put("guest","guest");
- users.put("admin","admin");
-
- final PropertiesPrincipalDatabase ppd = new PropertiesPrincipalDatabase(users);
-
- final AuthenticationManager pdam = new PrincipalDatabaseAuthenticationManager()
- {
-
- /**
- * @see org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager#configure(org.apache.qpid.server.configuration.plugins.ConfigurationPlugin)
- */
- @Override
- public void configure(ConfigurationPlugin config) throws ConfigurationException
- {
- // We don't pass configuration to this test instance.
- }
-
- @Override
- public void initialise()
- {
- setPrincipalDatabase(ppd);
-
- super.initialise();
- }
- };
- pdam.initialise();
-
- return new IAuthenticationManagerRegistry()
- {
- @Override
- public void close()
- {
- pdam.close();
- }
-
- @Override
- public AuthenticationManager getAuthenticationManager(
- SocketAddress address)
- {
- return pdam;
- }
-
- @Override
- public Map<String, AuthenticationManager> getAvailableAuthenticationManagers()
- {
- return Collections.singletonMap(pdam.getClass().getName(), pdam);
- }
-
- @Override
- public void addRegistryChangeListener(RegistryChangeListener listener)
- {
- }
- };
- }
-}
-
-
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
index 290c465785..1d99d99820 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
@@ -22,26 +22,18 @@ package org.apache.qpid.server.virtualhost;
import java.util.concurrent.ScheduledFuture;
import org.apache.qpid.server.binding.BindingFactory;
-import org.apache.qpid.server.configuration.BrokerConfig;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.VirtualHostConfig;
-import org.apache.qpid.server.configuration.VirtualHostConfigType;
import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.connection.IConnectionRegistry;
import org.apache.qpid.server.exchange.ExchangeFactory;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.protocol.v1_0.LinkRegistry;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.txn.DtxRegistry;
-import java.util.Map;
import java.util.UUID;
public class MockVirtualHost implements VirtualHost
@@ -58,19 +50,8 @@ public class MockVirtualHost implements VirtualHost
}
- public void createBrokerConnection(String transport, String host, int port,
- String vhost, boolean durable, String authMechanism,
- String username, String password)
- {
-
- }
-
- public BrokerLink createBrokerConnection(final UUID id, final long createTime, final Map<String, String> arguments)
- {
- return null;
- }
-
- public IApplicationRegistry getApplicationRegistry()
+ @Override
+ public VirtualHostRegistry getVirtualHostRegistry()
{
return null;
}
@@ -85,16 +66,6 @@ public class MockVirtualHost implements VirtualHost
return null;
}
- public UUID getBrokerId()
- {
- return null;
- }
-
- public ConfigStore getConfigStore()
- {
- return null;
- }
-
public DtxRegistry getDtxRegistry()
{
return null;
@@ -160,12 +131,6 @@ public class MockVirtualHost implements VirtualHost
return null;
}
-
- public void removeBrokerConnection(BrokerLink brokerLink)
- {
-
- }
-
public LinkRegistry getLinkRegistry(String remoteContainerId)
{
return null;
@@ -186,25 +151,6 @@ public class MockVirtualHost implements VirtualHost
}
- public BrokerConfig getBroker()
- {
- return null;
- }
-
- public String getFederationTag()
- {
- return null;
- }
-
- public void setBroker(BrokerConfig brokerConfig)
- {
-
- }
-
- public VirtualHostConfigType getConfigType()
- {
- return null;
- }
public long getCreateTime()
{
@@ -216,17 +162,6 @@ public class MockVirtualHost implements VirtualHost
return null;
}
- @Override
- public UUID getQMFId()
- {
- return null;
- }
-
- public ConfiguredObject<VirtualHostConfigType, VirtualHostConfig> getParent()
- {
- return null;
- }
-
public boolean isDurable()
{
return false;
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
index b8ba76e43d..559a7f8aaf 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
@@ -20,15 +20,21 @@
*/
package org.apache.qpid.server.virtualhost;
+import static org.mockito.Mockito.mock;
+
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.MemoryMessageStore;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.test.utils.QpidTestCase;
import java.io.BufferedWriter;
@@ -38,15 +44,31 @@ import java.io.IOException;
public class VirtualHostImplTest extends QpidTestCase
{
- private ServerConfiguration _configuration;
- private ApplicationRegistry _registry;
+ private VirtualHostRegistry _virtualHostRegistry;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ }
@Override
public void tearDown() throws Exception
{
- super.tearDown();
+ try
+ {
+ if (_virtualHostRegistry != null)
+ {
+ _virtualHostRegistry.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
- ApplicationRegistry.remove();
}
/**
@@ -74,17 +96,23 @@ public class VirtualHostImplTest extends QpidTestCase
*/
public void testSpecifyingCustomBindingForDefaultExchangeThrowsException() throws Exception
{
- File config = writeConfigFile(getName(), getName(), null, false, new String[]{"custom-binding"});
+ final String queueName = getName();
+ final String customBinding = "custom-binding";
+ File config = writeConfigFile(queueName, queueName, null, false, new String[]{customBinding});
try
{
- createVirtualHost(getName(), config);
+ createVirtualHost(queueName, config);
fail("virtualhost creation should have failed due to illegal configuration");
}
catch (RuntimeException e)
{
+ assertNotNull(e.getCause());
+
assertEquals(ConfigurationException.class, e.getCause().getClass());
- //expected
+
+ Throwable configException = e.getCause();
+ assertEquals("Illegal attempt to bind queue '" + queueName + "' to the default exchange with a key other than the queue name: " + customBinding, configException.getMessage());
}
}
@@ -96,6 +124,14 @@ public class VirtualHostImplTest extends QpidTestCase
assertEquals(State.ACTIVE, vhost.getState());
}
+ public void testVirtualHostHavingStoreSetAsTypeBecomesActive() throws Exception
+ {
+ String virtualHostName = getName();
+ VirtualHost host = createVirtualHostUsingStoreType(virtualHostName);
+ assertNotNull(host);
+ assertEquals(State.ACTIVE, host.getState());
+ }
+
public void testVirtualHostBecomesStoppedOnClose() throws Exception
{
File config = writeConfigFile(getName(), getName(), getName() +".direct", false, new String[0]);
@@ -107,22 +143,39 @@ public class VirtualHostImplTest extends QpidTestCase
assertEquals(0, vhost.getHouseKeepingActiveCount());
}
+ public void testVirtualHostHavingStoreSetAsTypeBecomesStoppedOnClose() throws Exception
+ {
+ String virtualHostName = getName();
+ VirtualHost host = createVirtualHostUsingStoreType(virtualHostName);
+ assertNotNull(host);
+ assertEquals(State.ACTIVE, host.getState());
+ host.close();
+ assertEquals(State.STOPPED, host.getState());
+ assertEquals(0, host.getHouseKeepingActiveCount());
+ }
+
/**
* Tests that specifying an unknown exchange to bind the queue to results in failure to create the vhost
*/
public void testSpecifyingUnknownExchangeThrowsException() throws Exception
{
- File config = writeConfigFile(getName(), getName(), "made-up-exchange", true, new String[0]);
+ final String queueName = getName();
+ final String exchangeName = "made-up-exchange";
+ File config = writeConfigFile(queueName, queueName, exchangeName, true, new String[0]);
try
{
- createVirtualHost(getName(), config);
+ createVirtualHost(queueName, config);
fail("virtualhost creation should have failed due to illegal configuration");
}
catch (RuntimeException e)
{
+ assertNotNull(e.getCause());
+
assertEquals(ConfigurationException.class, e.getCause().getClass());
- //expected
+
+ Throwable configException = e.getCause();
+ assertEquals("Attempt to bind queue '" + queueName + "' to unknown exchange:" + exchangeName, configException.getMessage());
}
}
@@ -154,12 +207,14 @@ public class VirtualHostImplTest extends QpidTestCase
private VirtualHost createVirtualHost(String vhostName, File config) throws Exception
{
- _configuration = new ServerConfiguration(new XMLConfiguration(config));
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ _virtualHostRegistry = broker.getVirtualHostRegistry();
- _registry = new TestApplicationRegistry(_configuration);
- ApplicationRegistry.initialise(_registry);
+ VirtualHostConfiguration configuration = new VirtualHostConfiguration(vhostName, config, broker);
+ VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(null), configuration);
+ _virtualHostRegistry.registerVirtualHost(host);
- return _registry.getVirtualHostRegistry().getVirtualHost(vhostName);
+ return host;
}
/**
@@ -184,7 +239,6 @@ public class VirtualHostImplTest extends QpidTestCase
BufferedWriter writer = new BufferedWriter(fstream);
//extra outer tag to please Commons Configuration
- writer.write("<configuration>");
writer.write("<virtualhosts>");
writer.write(" <default>" + vhostName + "</default>");
@@ -222,8 +276,6 @@ public class VirtualHostImplTest extends QpidTestCase
writer.write(" </virtualhost>");
writer.write("</virtualhosts>");
- writer.write("</configuration>");
-
writer.flush();
writer.close();
}
@@ -234,4 +286,17 @@ public class VirtualHostImplTest extends QpidTestCase
return tmpFile;
}
+
+ private VirtualHost createVirtualHostUsingStoreType(String virtualHostName) throws ConfigurationException, Exception
+ {
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ _virtualHostRegistry = broker.getVirtualHostRegistry();
+
+ Configuration config = new PropertiesConfiguration();
+ config.setProperty("store.type", MemoryMessageStore.TYPE);
+ VirtualHostConfiguration configuration = new VirtualHostConfiguration(virtualHostName, config, broker);
+ VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(null), configuration);
+ _virtualHostRegistry.registerVirtualHost(host);
+ return host;
+ }
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionConfigurationTest.java
deleted file mode 100644
index e2375c579b..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionConfigurationTest.java
+++ /dev/null
@@ -1,347 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionConfiguration;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Provide Unit Test coverage of the virtualhost SlowConsumer Configuration
- * This is what controls how often the plugin will execute
- */
-public class SlowConsumerDetectionConfigurationTest extends InternalBrokerBaseCase
-{
-
- /**
- * Default Testing:
- *
- * Provide a fully complete and valid configuration specifying 'delay' and
- * 'timeunit' and ensure that it is correctly processed.
- *
- * Ensure no exceptions are thrown and that we get the same values back that
- * were put into the configuration.
- */
- public void testConfigLoadingValidConfig()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- long DELAY=10;
- String TIMEUNIT=TimeUnit.MICROSECONDS.toString();
- xmlconfig.addProperty("delay", String.valueOf(DELAY));
- xmlconfig.addProperty("timeunit", TIMEUNIT);
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals("Delay not correctly returned.", DELAY, config.getDelay());
- assertEquals("TimeUnit not correctly returned.",
- TIMEUNIT, String.valueOf(config.getTimeUnit()));
- }
-
- /**
- * Default Testing:
- *
- * Test Missing TimeUnit value gets default.
- *
- * The TimeUnit value is optional and default to SECONDS.
- *
- * Test that if we do not specify a TimeUnit then we correctly get seconds.
- *
- * Also verify that relying on the default does not impact the setting of
- * the 'delay' value.
- *
- */
- public void testConfigLoadingMissingTimeUnitDefaults()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- long DELAY=10;
- xmlconfig.addProperty("delay", String.valueOf(DELAY));
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- try
- {
- config.setConfiguration("", composite);
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals("Delay not correctly returned.", DELAY, config.getDelay());
- assertEquals("Default TimeUnit incorrect", TimeUnit.SECONDS, config.getTimeUnit());
- }
-
- /**
- * Input Testing:
- *
- * TimeUnit parsing requires the String value be in UpperCase.
- * Ensure we can handle when the user doesn't know this.
- *
- * Same test as 'testConfigLoadingValidConfig' but checking that
- * the timeunit field is not case sensitive.
- * i.e. the toUpper is being correctly applied.
- */
- public void testConfigLoadingValidConfigStrangeTimeUnit()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- long DELAY=10;
-
- xmlconfig.addProperty("delay", DELAY);
- xmlconfig.addProperty("timeunit", "MiCrOsEcOnDs");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals("Delay not correctly returned.", DELAY, config.getDelay());
- assertEquals("TimeUnit not correctly returned.",
- TimeUnit.MICROSECONDS.toString(), String.valueOf(config.getTimeUnit()));
-
- }
-
- /**
- * Failure Testing:
- *
- * Test that delay must be long not a string value.
- * Provide a delay as a written value not a long. 'ten'.
- *
- * This should throw a configuration exception which is being trapped and
- * verified to be the right exception, a NumberFormatException.
- *
- */
- public void testConfigLoadingInValidDelayString()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delay", "ten");
- xmlconfig.addProperty("timeunit", TimeUnit.MICROSECONDS.toString());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- Throwable cause = e.getCause();
-
- assertEquals("Cause not correct", NumberFormatException.class, cause.getClass());
- }
- }
-
- /**
- * Failure Testing:
- *
- * Test that negative delays are invalid.
- *
- * Delay must be a positive value as negative delay means doesn't make sense.
- *
- * Configuration exception with a useful message should be thrown here.
- *
- */
- public void testConfigLoadingInValidDelayNegative()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delay", "-10");
- xmlconfig.addProperty("timeunit", TimeUnit.MICROSECONDS.toString());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- Throwable cause = e.getCause();
-
- assertNotNull("Configuration Exception must not be null.", cause);
- assertEquals("Cause not correct",
- ConfigurationException.class, cause.getClass());
- assertEquals("Incorrect message.",
- "SlowConsumerDetectionConfiguration: 'delay' must be a Positive Long value.",
- cause.getMessage());
- }
- }
-
- /**
- * Failure Testing:
- *
- * Test that delay cannot be 0.
- *
- * A zero delay means run constantly. This is not how VirtualHostTasks
- * are designed to be run so we dis-allow the use of 0 delay.
- *
- * Same test as 'testConfigLoadingInValidDelayNegative' but with a 0 value.
- *
- */
- public void testConfigLoadingInValidDelayZero()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delay", "0");
- xmlconfig.addProperty("timeunit", TimeUnit.MICROSECONDS.toString());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- Throwable cause = e.getCause();
-
- assertNotNull("Configuration Exception must not be null.", cause);
- assertEquals("Cause not correct",
- ConfigurationException.class, cause.getClass());
- assertEquals("Incorrect message.",
- "SlowConsumerDetectionConfiguration: 'delay' must be a Positive Long value.",
- cause.getMessage());
- }
- }
-
- /**
- * Failure Testing:
- *
- * Test that missing delay fails.
- * If we have no delay then we do not pick a default. So a Configuration
- * Exception is thrown.
- *
- * */
- public void testConfigLoadingInValidMissingDelay()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("timeunit", TimeUnit.SECONDS.toString());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- assertEquals("Incorrect message.", "SlowConsumerDetectionConfiguration: unable to configure invalid delay:null", e.getMessage());
- }
- }
-
- /**
- * Failure Testing:
- *
- * Test that erroneous TimeUnit fails.
- *
- * Valid TimeUnit values vary based on the JVM version i.e. 1.6 added HOURS/DAYS etc.
- *
- * We don't test the values for TimeUnit are accepted other than MILLISECONDS in the
- * positive testing at the start.
- *
- * Here we ensure that an erroneous for TimeUnit correctly throws an exception.
- *
- * We test with 'foo', which will never be a TimeUnit
- *
- */
- public void testConfigLoadingInValidTimeUnit()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- String TIMEUNIT = "foo";
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delay", "10");
- xmlconfig.addProperty("timeunit", TIMEUNIT);
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- assertEquals("Incorrect message.", "Unable to configure Slow Consumer Detection invalid TimeUnit:" + TIMEUNIT, e.getMessage());
- }
- }
-
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionPolicyConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionPolicyConfigurationTest.java
deleted file mode 100644
index ea07632873..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionPolicyConfigurationTest.java
+++ /dev/null
@@ -1,105 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionPolicyConfiguration;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-/**
- * Test class to ensure that the policy configuration can be processed.
- */
-public class SlowConsumerDetectionPolicyConfigurationTest extends InternalBrokerBaseCase
-{
-
- /**
- * Input Testing:
- *
- * Test that a given String can be set and retrieved through the configuration
- *
- * No validation is being performed to ensure that the policy exists. Only
- * that a value can be set for the policy.
- *
- */
- public void testConfigLoadingValidConfig()
- {
- SlowConsumerDetectionPolicyConfiguration config = new SlowConsumerDetectionPolicyConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- String policyName = "TestPolicy";
- xmlconfig.addProperty("name", policyName);
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals("Policy name not retrieved as expected.",
- policyName, config.getPolicyName());
- }
-
- /**
- * Failure Testing:
- *
- * Test that providing a configuration section without the 'name' field
- * causes an exception to be thrown.
- *
- * An empty configuration is provided and the thrown exception message
- * is checked to confirm the right reason.
- *
- */
- public void testConfigLoadingInValidConfig()
- {
- SlowConsumerDetectionPolicyConfiguration config = new SlowConsumerDetectionPolicyConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("Config is invalid so won't validate.");
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- assertEquals("Exception message not as expected.", "No Slow consumer policy defined.", e.getMessage());
- }
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionQueueConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionQueueConfigurationTest.java
deleted file mode 100644
index 96e524acf2..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionQueueConfigurationTest.java
+++ /dev/null
@@ -1,186 +0,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.
- */
-package org.apache.qpid.server.virtualhost.plugins;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionQueueConfiguration;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-/**
- * Unit test the QueueConfiguration processing.
- *
- * This is slightly awkward as the {@link SlowConsumerDetectionQueueConfiguration}
- * requries that a policy be available.
- * <p>
- * So all the Valid test much catch the ensuing {@link ConfigurationException} and
- * validate that the error is due to a lack of a valid policy.
- */
-public class SlowConsumerDetectionQueueConfigurationTest extends InternalBrokerBaseCase
-{
- /**
- * Test a fully loaded configuration file.
- *
- * It is not an error to have all control values specified.
- * <p>
- * Here we need to catch the {@link ConfigurationException} that ensues due to lack
- * of a policy plugin.
- */
- public void testConfigLoadingValidConfig()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("messageAge", "60000");
- xmlconfig.addProperty("depth", "1024");
- xmlconfig.addProperty("messageCount", "10");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
- assertTrue("Exception message incorrect, was: " + e.getMessage(),
- e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
- }
- }
-
- /**
- * When we do not specify any control value then a {@link ConfigurationException}
- * must be thrown to remind us.
- */
- public void testConfigLoadingMissingConfig()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
-
- assertEquals("At least one configuration property('messageAge','depth'" +
- " or 'messageCount') must be specified.", e.getMessage());
- }
- }
-
- /**
- * Setting messageAge on its own is enough to have a valid configuration
- *
- * Here we need to catch the {@link ConfigurationException} that ensues due to lack
- * of a policy plugin.
- */
- public void testConfigLoadingMessageAgeOk()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("messageAge", "60000");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
- assertTrue("Exception message incorrect, was: " + e.getMessage(),
- e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
- }
- }
-
- /**
- * Setting depth on its own is enough to have a valid configuration.
- *
- * Here we need to catch the {@link ConfigurationException} that ensues due to lack
- * of a policy plugin.
- */
- public void testConfigLoadingDepthOk()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("depth", "1024");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
- assertTrue("Exception message incorrect, was: " + e.getMessage(),
- e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
- }
- }
-
- /**
- * Setting messageCount on its own is enough to have a valid configuration.
- *
- * Here we need to catch the {@link ConfigurationException} that ensues due to lack
- * of a policy plugin.
- */
- public void testConfigLoadingMessageCountOk()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("messageCount", "10");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
- assertTrue("Exception message incorrect, was: " + e.getMessage(),
- e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
- }
- }
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfigurationTest.java
deleted file mode 100644
index f034d05c37..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfigurationTest.java
+++ /dev/null
@@ -1,89 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins.policies;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-/**
- * Test to ensure TopicDelete Policy configuration can be loaded.
- */
-public class TopicDeletePolicyConfigurationTest extends InternalBrokerBaseCase
-{
- /**
- * Test without any configuration being provided that the
- * deletePersistent option is disabled.
- */
- public void testNoConfigNoDeletePersistent()
- {
- TopicDeletePolicyConfiguration config = new TopicDeletePolicyConfiguration();
-
- assertFalse("TopicDelete Configuration with no config should not delete persistent queues.",
- config.deletePersistent());
- }
-
- /**
- * Test that with the correct configuration the deletePersistent option can
- * be enabled.
- *
- * Test creates a new Configuration object and passes in the xml snippet
- * that the ConfigurationPlugin would receive during normal execution.
- * This is the XML that would be matched for this plugin:
- * <topicdelete>
- * <delete-persistent>
- * <topicdelete>
- *
- * So it would be subset and passed in as just:
- * <delete-persistent>
- *
- *
- * The property should therefore be enabled.
- *
- */
- public void testConfigDeletePersistent()
- {
- TopicDeletePolicyConfiguration config = new TopicDeletePolicyConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delete-persistent","");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("",composite);
- }
- catch (ConfigurationException e)
- {
- fail(e.getMessage());
- }
-
- assertTrue("A configured TopicDelete should delete persistent queues.",
- config.deletePersistent());
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyTest.java
deleted file mode 100644
index aa8448b99d..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyTest.java
+++ /dev/null
@@ -1,294 +0,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.
- *
- */
-package org.apache.qpid.server.virtualhost.plugins.policies;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.exchange.DirectExchange;
-import org.apache.qpid.server.exchange.TopicExchange;
-import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.queue.MockAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-
-public class TopicDeletePolicyTest extends InternalBrokerBaseCase
-{
-
- private TopicDeletePolicyConfiguration _config;
-
- private VirtualHost _defaultVhost;
- private InternalTestProtocolSession _connection;
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- _defaultVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getDefaultVirtualHost();
-
- _connection = new InternalTestProtocolSession(_defaultVhost);
-
- _config = new TopicDeletePolicyConfiguration();
-
- XMLConfiguration config = new XMLConfiguration();
-
- _config.setConfiguration("", config);
- }
-
- private MockAMQQueue createOwnedQueue()
- {
- MockAMQQueue queue = new MockAMQQueue("testQueue");
-
- _defaultVhost.getQueueRegistry().registerQueue(queue);
-
- try
- {
- AMQChannel channel = new AMQChannel(_connection, 0, null);
- _connection.addChannel(channel);
-
- queue.setExclusiveOwningSession(channel);
- }
- catch (AMQException e)
- {
- fail("Unable to create Channel:" + e.getMessage());
- }
-
- return queue;
- }
-
- private void setQueueToAutoDelete(final AMQQueue queue)
- {
- ((MockAMQQueue) queue).setAutoDelete(true);
-
- queue.setDeleteOnNoConsumers(true);
- final AMQProtocolSession.Task deleteQueueTask =
- new AMQProtocolSession.Task()
- {
- public void doTask(AMQProtocolSession session) throws AMQException
- {
- queue.delete();
- }
- };
-
- ((AMQChannel) queue.getExclusiveOwningSession()).getProtocolSession().addSessionCloseTask(deleteQueueTask);
- }
-
- /** Check that a null queue passed in does not upset the policy. */
- public void testNullQueueParameter() throws ConfigurationException
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- try
- {
- policy.performPolicy(null);
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown:" + e.getMessage());
- }
-
- }
-
- /**
- * Set a owning Session to null which means this is not an exclusive queue
- * so the queue should not be deleted
- */
- public void testNonExclusiveQueue()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.setExclusiveOwningSession(null);
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertFalse("Connection should not be closed", _connection.isClosed());
- }
-
- /**
- * Test that exclusive JMS Queues are not deleted.
- * Bind the queue to the direct exchange (so it is a JMS Queue).
- *
- * JMS Queues are not to be processed so this should not delete the queue.
- */
- public void testQueuesAreNotProcessed()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new DirectExchange(), null));
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertFalse("Connection should not be closed", _connection.isClosed());
- }
-
- /**
- * Give a non auto-delete queue is bound to the topic exchange the
- * TopicDeletePolicy will close the connection and delete the queue,
- */
- public void testNonAutoDeleteTopicIsNotClosed()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- queue.setAutoDelete(false);
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- /**
- * Give a auto-delete queue bound to the topic exchange the TopicDeletePolicy will
- * close the connection and delete the queue
- */
- public void testTopicIsClosed()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- final MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- setQueueToAutoDelete(queue);
-
- policy.performPolicy(queue);
-
- assertTrue("Queue should be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- /**
- * Give a queue bound to the topic exchange the TopicDeletePolicy will
- * close the connection and NOT delete the queue
- */
- public void testNonAutoDeleteTopicIsClosedNotDeleted()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- /**
- * Give a queue bound to the topic exchange the TopicDeletePolicy suitably
- * configured with the delete-persistent tag will close the connection
- * and delete the queue
- */
- public void testPersistentTopicIsClosedAndDeleted()
- {
- //Set the config to delete persistent queues
- _config.getConfig().addProperty("delete-persistent", "");
-
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- assertTrue("Config was not updated to delete Persistent topics",
- _config.deletePersistent());
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- policy.performPolicy(queue);
-
- assertTrue("Queue should be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- /**
- * Give a queue bound to the topic exchange the TopicDeletePolicy not
- * configured to close a persistent queue
- */
- public void testPersistentTopicIsClosedAndDeletedNullConfig()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- // Explicity say we are not configuring the policy.
- policy.configure(null);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- public void testNonExclusiveQueueNullConfig()
- {
- _config = null;
- testNonExclusiveQueue();
- }
-
- public void testQueuesAreNotProcessedNullConfig()
- {
- _config = null;
- testQueuesAreNotProcessed();
- }
-
- public void testNonAutoDeleteTopicIsNotClosedNullConfig()
- {
- _config = null;
- testNonAutoDeleteTopicIsNotClosed();
- }
-
- public void testTopicIsClosedNullConfig()
- {
- _config = null;
- testTopicIsClosed();
- }
-
- public void testNonAutoDeleteTopicIsClosedNotDeletedNullConfig() throws AMQException
- {
- _config = null;
- testNonAutoDeleteTopicIsClosedNotDeleted();
- }
-
-}
diff --git a/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm b/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
index 02bf155c44..cddfcfb581 100644
--- a/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
+++ b/java/broker/src/velocity/templates/org/apache/qpid/server/logging/messages/LogMessages.vm
@@ -23,8 +23,8 @@ package ${package};
import static org.apache.qpid.server.logging.AbstractRootMessageLogger.DEFAULT_LOG_HIERARCHY_PREFIX;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.logging.LogMessage;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import java.text.MessageFormat;
import java.util.Locale;
@@ -44,7 +44,7 @@ import java.util.ResourceBundle;
public class ${type.name}Messages
{
private static ResourceBundle _messages;
- private static Locale _currentLocale;
+ private static Locale _currentLocale = BrokerProperties.getLocale();
public static final String ${type.name.toUpperCase()}_LOG_HIERARCHY = DEFAULT_LOG_HIERARCHY_PREFIX + "${type.name.toLowerCase()}";
#foreach( $message in ${type.list} )
@@ -58,24 +58,9 @@ public class ${type.name}Messages
Logger.getLogger(${message.methodName.toUpperCase()}_LOG_HIERARCHY);
#end
- reload();
- }
-
- public static void reload()
- {
- if (ApplicationRegistry.isConfigured())
- {
- _currentLocale = ApplicationRegistry.getInstance().getConfiguration().getLocale();
- }
- else
- {
- _currentLocale = Locale.getDefault();
- }
-
_messages = ResourceBundle.getBundle("${resource}", _currentLocale);
}
-
##
## The list stored under key 'list' in the 'type' HashMap contains all the
## log messages that this class should contain. So for each entry in the list
diff --git a/java/build.deps b/java/build.deps
index 4742ec1a8c..f60ffd8ff8 100644
--- a/java/build.deps
+++ b/java/build.deps
@@ -59,10 +59,6 @@ servlet-api=${geronimo-servlet}
dojo=lib/required/dojo-war-1.7.2.war
-felix-main=lib/required/org.apache.felix.main-2.0.5.jar
-
-felix.libs=${felix-main}
-
jackson-core=lib/required/jackson-core-asl-1.9.0.jar
jackson-mapper=lib/required/jackson-mapper-asl-1.9.0.jar
@@ -72,19 +68,20 @@ commons-configuration.libs = ${commons-beanutils-core} ${commons-digester} \
common.libs=${slf4j-api}
client.libs=${geronimo-jms}
amqp-1-0-common.libs=
-amqp-1-0-client.libs=${commons-cli}
+amqp-1-0-client.libs=
+amqp-1-0-client-example.libs=${commons-cli}
amqp-1-0-client-jms.libs=${geronimo-jms}
tools.libs=${commons-configuration.libs} ${log4j}
broker.libs=${commons-cli} ${commons-logging} ${log4j} ${slf4j-log4j} \
- ${xalan} ${felix.libs} ${derby-db} ${commons-configuration.libs} \
+ ${xalan} ${derby-db} ${commons-configuration.libs} \
${jackson-core} ${jackson-mapper} ${jetty} ${jetty-continuation} ${jetty-security} ${jetty-http} ${jetty-io} ${jetty-servlet} ${jetty-util} ${servlet-api} ${jetty-websocket}
broker-plugins-management-http.libs=${jetty} ${jetty-continuation} ${jetty-security} ${jetty-http} ${jetty-io} ${jetty-servlet} ${jetty-util} ${servlet-api} ${jackson-core} ${jackson-mapper}
-broker-plugins.libs=${felix.libs} ${log4j} ${commons-configuration.libs}
+broker-plugins.libs=${log4j} ${commons-configuration.libs}
test.libs=${slf4j-log4j} ${log4j} ${junit} ${slf4j-api} ${mockito-all}
-perftests.libs=${geronimo-jms} ${slf4j-api} ${log4j} ${slf4j-log4j} ${commons-logging} ${commons-collections} ${commons-beanutils-core} ${commons-lang} ${gson-all}
+perftests.libs=${geronimo-jms} ${slf4j-api} ${log4j} ${slf4j-log4j} ${commons-logging} ${commons-collections} ${commons-beanutils-core} ${commons-lang} ${gson-all} ${derby-db}
management-common.libs=
@@ -93,11 +90,12 @@ broker.test.libs=${test.libs}
client.test.libs=${test.libs}
client-example.test.libs=${test.libs}
tools.test.libs=
-testkit.test.libs=${test.libs}
systests.libs=${test.libs}
perftests.test.libs=${test.libs}
-broker-plugins.test.libs=${test.libs}
+broker-plugins-access-control.test.libs=${test.libs}
+broker-plugins-management-http.test.libs=${test.libs}
+broker-plugins-management-jmx.test.libs=${test.libs}
management-common.test.libs=${test.libs}
@@ -117,10 +115,12 @@ bdbstore-jmx.test.libs=${test.libs}
jfreechart.jar=lib/jfree/jfreechart-1.0.13.jar
jcommon.jar=lib/jfree/jcommon-1.0.16.jar
csvjdbc.jar=lib/csvjdbc/csvjdbc-1.0.8.jar
-perftests-visualisation-jfc.libs=${jfreechart.jar} ${jcommon.jar} ${csvjdbc.jar}
+perftests-visualisation-jfc.libs=${jfreechart.jar} ${jcommon.jar} ${csvjdbc.jar} ${derby-db}
perftests-visualisation-jfc.test.libs=${test.libs}
# Libraries used only within the build
bnd=lib/required/bnd-0.0.384.jar
jython=lib/required/jython-standalone-2.5.2.jar
maven-ant-tasks=lib/required/maven-ant-tasks-2.1.1.jar
+velocity.jar=lib/required/velocity-1.4.jar
+velocity-dep.jar=lib/required/velocity-dep-1.4.jar
diff --git a/java/build.xml b/java/build.xml
index 7f51cb64c0..e3726d1c3c 100644
--- a/java/build.xml
+++ b/java/build.xml
@@ -32,7 +32,7 @@
</condition>
<property name="modules.core" value="common management/common amqp-1-0-common broker client amqp-1-0-client amqp-1-0-client-jms tools"/>
- <property name="modules.examples" value="client/example management/example"/>
+ <property name="modules.examples" value="client/example management/example amqp-1-0-client/example amqp-1-0-client-jms/example"/>
<property name="modules.tests" value="systests perftests"/>
<property name="modules.plugin" value="${broker-plugins} ${client-plugins}"/>
<property name="modules.jca" value="jca"/>
@@ -77,6 +77,10 @@
<iterate target="release-mvn"/>
</target>
+ <target name="deploy-snapshot" description="deploy snapshot artifacts to nexus">
+ <iterate target="deploy-snapshot"/>
+ </target>
+
<target name="compile" description="compile sources">
<iterate target="compile"/>
</target>
diff --git a/java/client/build.xml b/java/client/build.xml
index a02500d8e4..707bfda024 100644
--- a/java/client/build.xml
+++ b/java/client/build.xml
@@ -21,7 +21,7 @@
<project name="AMQ Client" default="build">
<property name="module.depends" value="common"/>
- <property name="module.test.depends" value="common/test" />
+ <property name="module.test.depends" value="common/tests" />
<property name="module.genpom" value="true"/>
<property name="module.genpom.args" value="-Sgeronimo-jms_1.1_spec=provided"/>
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/Drain.java b/java/client/example/src/main/java/org/apache/qpid/example/Drain.java
index 28e1d5a87e..f0eb83ad24 100644
--- a/java/client/example/src/main/java/org/apache/qpid/example/Drain.java
+++ b/java/client/example/src/main/java/org/apache/qpid/example/Drain.java
@@ -88,7 +88,7 @@ public class Drain extends OptionParser
}
}
}
-
+ consumer.close();
ssn.close();
con.close();
}
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/ListReceiver.java b/java/client/example/src/main/java/org/apache/qpid/example/ListReceiver.java
new file mode 100644
index 0000000000..b12cfab9de
--- /dev/null
+++ b/java/client/example/src/main/java/org/apache/qpid/example/ListReceiver.java
@@ -0,0 +1,101 @@
+/*
+ *
+ * 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.example;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.MapMessage;
+import javax.jms.StreamMessage;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.MessageEOFException;
+
+import org.apache.qpid.client.AMQAnyDestination;
+import org.apache.qpid.client.AMQConnection;
+
+import org.apache.qpid.jms.ListMessage;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+public class ListReceiver {
+
+ public static void main(String[] args) throws Exception
+ {
+ if (args.length != 1) {
+ System.out.println("Usage: java org.apache.qpid.example.ListReceiver <-l | -m | -s>");
+ System.out.println("where:");
+ System.out.println("\t-l\tAccept ListMessage and print it");
+ System.out.println("\t-m\tAccept ListMessage as a MapMessage");
+ System.out.println("\t-s\tAccept ListMessage as a StreamMessage");
+ return;
+ }
+
+ Connection connection =
+ new AMQConnection("amqp://guest:guest@test/?brokerlist='tcp://localhost:5672'");
+
+ connection.start();
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Destination queue = new AMQAnyDestination("ADDR:message_queue; {create: always}");
+ MessageConsumer consumer = session.createConsumer(queue);
+
+ if (args[0].equals("-l")) {
+ System.out.println("Receiving as ListMessage");
+ ListMessage m = (ListMessage)consumer.receive();
+ System.out.println(m);
+ System.out.println("==========================================");
+ System.out.println("Printing list contents:");
+ Iterator i = m.iterator();
+ while(i.hasNext())
+ System.out.println(i.next());
+ }
+ else if (args[0].equals("-m")) {
+ System.out.println("Receiving as MapMessage");
+ MapMessage m = (MapMessage)consumer.receive();
+ System.out.println(m);
+ System.out.println("==========================================");
+ System.out.println("Printing map contents:");
+ Enumeration keys = m.getMapNames();
+ while(keys.hasMoreElements()) {
+ String key = (String)keys.nextElement();
+ System.out.println(key + " => " + m.getObject(key));
+ }
+ }
+ else if (args[0].equals("-s")) {
+ System.out.println("Receiving as StreamMessage");
+ StreamMessage m = (StreamMessage)consumer.receive();
+ System.out.println(m);
+ System.out.println("==========================================");
+ System.out.println("Printing stream contents:");
+ try {
+ while(true)
+ System.out.println(m.readObject());
+ }
+ catch (MessageEOFException e) {
+ // DONE
+ }
+ }
+
+ connection.close();
+ }
+}
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/ListSender.java b/java/client/example/src/main/java/org/apache/qpid/example/ListSender.java
new file mode 100644
index 0000000000..fe2c1ec472
--- /dev/null
+++ b/java/client/example/src/main/java/org/apache/qpid/example/ListSender.java
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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.example;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.apache.qpid.client.AMQAnyDestination;
+import org.apache.qpid.client.AMQConnection;
+
+import org.apache.qpid.jms.ListMessage;
+
+
+public class ListSender {
+
+ public static void main(String[] args) throws Exception
+ {
+ Connection connection =
+ new AMQConnection("amqp://guest:guest@test/?brokerlist='tcp://localhost:5672'");
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Destination queue = new AMQAnyDestination("ADDR:message_queue; {create: always}");
+ MessageProducer producer = session.createProducer(queue);
+
+ ListMessage m = ((org.apache.qpid.jms.Session)session).createListMessage();
+ m.setIntProperty("Id", 987654321);
+ m.setStringProperty("name", "Widget");
+ m.setDoubleProperty("price", 0.99);
+
+ List<String> colors = new ArrayList<String>();
+ colors.add("red");
+ colors.add("green");
+ colors.add("white");
+ m.add(colors);
+
+ Map<String,Double> dimensions = new HashMap<String,Double>();
+ dimensions.put("length",10.2);
+ dimensions.put("width",5.1);
+ dimensions.put("depth",2.0);
+ m.add(dimensions);
+
+ List<List<Integer>> parts = new ArrayList<List<Integer>>();
+ parts.add(Arrays.asList(new Integer[] {1,2,5}));
+ parts.add(Arrays.asList(new Integer[] {8,2,5}));
+ m.add(parts);
+
+ Map<String,Object> specs = new HashMap<String,Object>();
+ specs.put("colours", colors);
+ specs.put("dimensions", dimensions);
+ specs.put("parts", parts);
+ m.add(specs);
+
+ producer.send((Message)m);
+ System.out.println("Sent: " + m);
+ connection.close();
+ }
+
+}
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/Spout.java b/java/client/example/src/main/java/org/apache/qpid/example/Spout.java
index 61ff2dfc19..09e813f8c1 100644
--- a/java/client/example/src/main/java/org/apache/qpid/example/Spout.java
+++ b/java/client/example/src/main/java/org/apache/qpid/example/Spout.java
@@ -100,6 +100,7 @@ public class Spout extends OptionParser
System.out.println(msg);
System.out.println("-------------------------------\n");
}
+ producer.close();
ssn.close();
con.close();
}
diff --git a/java/client/src/main/java/client.bnd b/java/client/src/main/java/client.bnd
index 4b9b191520..0a47b30c72 100755
--- a/java/client/src/main/java/client.bnd
+++ b/java/client/src/main/java/client.bnd
@@ -17,7 +17,7 @@
# under the License.
#
-ver: 0.19.0
+ver: 0.21.0
Bundle-SymbolicName: qpid-client
Bundle-Version: ${ver}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java b/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
index 89273599b9..597096db57 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
@@ -344,7 +344,14 @@ public class AMQBrokerDetails implements BrokerDetails
optionsURL.append("='");
- optionsURL.append(_options.get(key));
+ if (OPTIONS_TRUST_STORE_PASSWORD.equals(key) || OPTIONS_KEY_STORE_PASSWORD.equals(key))
+ {
+ optionsURL.append("********");
+ }
+ else
+ {
+ optionsURL.append(_options.get(key));
+ }
optionsURL.append("'");
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
index d80858a7a1..9612417266 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
@@ -179,6 +179,13 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
// new amqp-0-10 encoded format.
private boolean _useLegacyMapMessageFormat;
+ // Indicates whether to use the old stream message format or the
+ // new amqp-0-10 list encoded format.
+ private boolean _useLegacyStreamMessageFormat;
+
+ // When sending to a Queue destination for the first time, check that the queue is bound
+ private final boolean _validateQueueOnSend;
+
//used to track the last failover time for
//Address resolution purposes
private volatile long _lastFailoverTime = 0;
@@ -294,6 +301,30 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
_useLegacyMapMessageFormat = Boolean.getBoolean(ClientProperties.USE_LEGACY_MAP_MESSAGE_FORMAT);
}
+ if (connectionURL.getOption(ConnectionURL.OPTIONS_USE_LEGACY_STREAM_MESSAGE_FORMAT) != null)
+ {
+ _useLegacyStreamMessageFormat = Boolean.parseBoolean(
+ connectionURL.getOption(ConnectionURL.OPTIONS_USE_LEGACY_STREAM_MESSAGE_FORMAT));
+ }
+ else
+ {
+ // use the default value set for all connections
+ _useLegacyStreamMessageFormat = System.getProperty(ClientProperties.USE_LEGACY_STREAM_MESSAGE_FORMAT) == null ?
+ true : Boolean.getBoolean(ClientProperties.USE_LEGACY_STREAM_MESSAGE_FORMAT);
+ }
+
+ if(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND) != null)
+ {
+ _validateQueueOnSend = Boolean.parseBoolean(
+ connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND));
+ }
+ else
+ {
+ _validateQueueOnSend =
+ Boolean.parseBoolean(System.getProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "false"));
+ }
+
+
String amqpVersion = System.getProperty((ClientProperties.AMQP_VERSION), "0-10");
if (_logger.isDebugEnabled())
{
@@ -1080,7 +1111,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
return _started;
}
- protected final boolean isConnected()
+ public final boolean isConnected()
{
return _connected;
}
@@ -1425,7 +1456,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
{
return _delegate.getProtocolVersion();
}
-
+
public String getBrokerUUID()
{
if(getProtocolVersion().equals(ProtocolVersion.v0_10))
@@ -1498,6 +1529,11 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
return _useLegacyMapMessageFormat;
}
+ public boolean isUseLegacyStreamMessageFormat()
+ {
+ return _useLegacyStreamMessageFormat;
+ }
+
private void verifyClientID() throws AMQException
{
if (Boolean.getBoolean(ClientProperties.QPID_VERIFY_CLIENT_ID))
@@ -1539,4 +1575,14 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
+ localAddress + " to " + remoteAddress);
}
}
+
+ void setHeartbeatListener(HeartbeatListener listener)
+ {
+ _delegate.setHeartbeatListener(listener);
+ }
+
+ public boolean validateQueueOnSend()
+ {
+ return _validateQueueOnSend;
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java
index b6f25a2cef..a8fdaeb65c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate.java
@@ -78,4 +78,6 @@ public interface AMQConnectionDelegate
* @return true if the feature is supported by the server
*/
boolean isSupportedServerFeature(final String featureName);
+
+ void setHeartbeatListener(HeartbeatListener listener);
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
index 51e7e4153d..69e79d42a0 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
@@ -33,6 +33,7 @@ import org.apache.qpid.configuration.ClientProperties;
import org.apache.qpid.framing.ProtocolVersion;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ChannelLimitReachedException;
+import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.jms.Session;
import org.apache.qpid.properties.ConnectionStartProperties;
import org.apache.qpid.protocol.AMQConstant;
@@ -214,7 +215,8 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec
+ "********");
}
- ConnectionSettings conSettings = retriveConnectionSettings(brokerDetail);
+ ConnectionSettings conSettings = retrieveConnectionSettings(brokerDetail);
+
_qpidConnection.setConnectionDelegate(new ClientConnectionDelegate(conSettings, _conn.getConnectionURL()));
_qpidConnection.connect(conSettings);
@@ -420,7 +422,13 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec
return featureSupported;
}
- private ConnectionSettings retriveConnectionSettings(BrokerDetails brokerDetail)
+ @Override
+ public void setHeartbeatListener(HeartbeatListener listener)
+ {
+ ((ClientConnectionDelegate)(_qpidConnection.getConnectionDelegate())).setHeartbeatListener(listener);
+ }
+
+ private ConnectionSettings retrieveConnectionSettings(BrokerDetails brokerDetail)
{
ConnectionSettings conSettings = brokerDetail.buildConnectionSettings();
@@ -442,6 +450,24 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec
conSettings.setHeartbeatInterval(getHeartbeatInterval(brokerDetail));
+ //Check connection-level ssl override setting
+ String connectionSslOption = _conn.getConnectionURL().getOption(ConnectionURL.OPTIONS_SSL);
+ if(connectionSslOption != null)
+ {
+ boolean connUseSsl = Boolean.parseBoolean(connectionSslOption);
+ boolean brokerlistUseSsl = conSettings.isUseSSL();
+
+ if( connUseSsl != brokerlistUseSsl)
+ {
+ conSettings.setUseSSL(connUseSsl);
+
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Applied connection ssl option override, setting UseSsl to: " + connUseSsl );
+ }
+ }
+ }
+
return conSettings;
}
@@ -464,10 +490,14 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec
heartbeat = Integer.getInteger(ClientProperties.IDLE_TIMEOUT_PROP_NAME)/1000;
_logger.warn("JVM arg -Didle_timeout=<mili_secs> is deprecated, please use -Dqpid.heartbeat=<secs>");
}
- else
+ else if(Integer.getInteger(ClientProperties.HEARTBEAT) != null)
{
heartbeat = Integer.getInteger(ClientProperties.HEARTBEAT,ClientProperties.HEARTBEAT_DEFAULT);
}
+ else
+ {
+ heartbeat = Integer.getInteger("amqj.heartbeat.delay", ClientProperties.HEARTBEAT_DEFAULT);
+ }
return heartbeat;
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
index e1bf007e83..67d7c2a78c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
@@ -40,6 +40,7 @@ import org.apache.qpid.framing.TxSelectBody;
import org.apache.qpid.framing.TxSelectOkBody;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ChannelLimitReachedException;
+import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.ssl.SSLContextFactory;
import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.transport.network.NetworkConnection;
@@ -90,42 +91,43 @@ public class AMQConnectionDelegate_8_0 implements AMQConnectionDelegate
public ProtocolVersion makeBrokerConnection(BrokerDetails brokerDetail) throws AMQException, IOException
{
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Connecting to broker:" + brokerDetail);
+ }
final Set<AMQState> openOrClosedStates =
EnumSet.of(AMQState.CONNECTION_OPEN, AMQState.CONNECTION_CLOSED);
-
- StateWaiter waiter = _conn.getProtocolHandler().createWaiter(openOrClosedStates);
-
ConnectionSettings settings = brokerDetail.buildConnectionSettings();
settings.setProtocol(brokerDetail.getTransport());
- SSLContext sslContext = null;
- if (settings.isUseSSL())
+ //Check connection-level ssl override setting
+ String connectionSslOption = _conn.getConnectionURL().getOption(ConnectionURL.OPTIONS_SSL);
+ if(connectionSslOption != null)
{
- try
- {
- sslContext = SSLContextFactory.buildClientContext(
- settings.getTrustStorePath(),
- settings.getTrustStorePassword(),
- settings.getTrustStoreType(),
- settings.getTrustManagerFactoryAlgorithm(),
- settings.getKeyStorePath(),
- settings.getKeyStorePassword(),
- settings.getKeyStoreType(),
- settings.getKeyManagerFactoryAlgorithm(),
- settings.getCertAlias());
- }
- catch (GeneralSecurityException e)
+ boolean connUseSsl = Boolean.parseBoolean(connectionSslOption);
+ boolean brokerlistUseSsl = settings.isUseSSL();
+
+ if( connUseSsl != brokerlistUseSsl)
{
- throw new AMQException("Unable to create SSLContext: " + e.getMessage(), e);
+ settings.setUseSSL(connUseSsl);
+
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Applied connection ssl option override, setting UseSsl to: " + connUseSsl );
+ }
}
}
SecurityLayer securityLayer = SecurityLayerFactory.newInstance(settings);
OutgoingNetworkTransport transport = Transport.getOutgoingTransportInstance(getProtocolVersion());
- NetworkConnection network = transport.connect(settings, securityLayer.receiver(_conn.getProtocolHandler()), sslContext);
+
+ NetworkConnection network = transport.connect(settings, securityLayer.receiver(_conn.getProtocolHandler()),
+ _conn.getProtocolHandler());
_conn.getProtocolHandler().setNetworkConnection(network, securityLayer.sender(network.getSender()));
+
+ StateWaiter waiter = _conn.getProtocolHandler().createWaiter(openOrClosedStates);
_conn.getProtocolHandler().getProtocolSession().init();
// this blocks until the connection has been set up or when an error
// has prevented the connection being set up
@@ -376,4 +378,10 @@ public class AMQConnectionDelegate_8_0 implements AMQConnectionDelegate
// we just hardcode JMS selectors as supported.
return ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR.equals(featureName);
}
+
+ @Override
+ public void setHeartbeatListener(HeartbeatListener listener)
+ {
+ _conn.getProtocolHandler().setHeartbeatListener(listener);
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
index 8bc815d98e..a2d4b5ee17 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
@@ -140,7 +140,7 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
{
try
{
- ConnectionURL connectionDetails = new AMQConnectionURL(_connectionDetails.toString());
+ ConnectionURL connectionDetails = new AMQConnectionURL(_connectionDetails.getURL());
connectionDetails.setUsername(userName);
connectionDetails.setPassword(password);
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java b/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
index 530186b1f9..f14b6d810b 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
@@ -52,6 +52,12 @@ public abstract class AMQDestination implements Destination, Referenceable
private AMQShortString _exchangeClass;
+ private boolean _exchangeAutoDelete;
+
+ private boolean _exchangeDurable;
+
+ private boolean _exchangeInternal;
+
private boolean _isDurable;
private boolean _isExclusive;
@@ -106,16 +112,6 @@ public abstract class AMQDestination implements Destination, Referenceable
_name = name;
}
- protected Link getTargetLink()
- {
- return _targetLink;
- }
-
- protected void setTargetLink(Link targetLink)
- {
- _targetLink = targetLink;
- }
-
// ----- Fields required to support new address syntax -------
public enum DestSyntax {
@@ -180,10 +176,9 @@ public abstract class AMQDestination implements Destination, Referenceable
private AddressOption _assert = AddressOption.NEVER;
private AddressOption _delete = AddressOption.NEVER;
- private Node _targetNode;
- private Node _sourceNode;
- private Link _targetLink;
+ private Node _node;
private Link _link;
+
// ----- / Fields required to support new address syntax -------
@@ -280,6 +275,9 @@ public abstract class AMQDestination implements Destination, Referenceable
{
_exchangeName = binding.getExchangeName();
_exchangeClass = binding.getExchangeClass();
+ _exchangeDurable = Boolean.parseBoolean(binding.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+ _exchangeAutoDelete = Boolean.parseBoolean(binding.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ _exchangeInternal = Boolean.parseBoolean(binding.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
_isExclusive = Boolean.parseBoolean(binding.getOption(BindingURL.OPTION_EXCLUSIVE));
_isAutoDelete = Boolean.parseBoolean(binding.getOption(BindingURL.OPTION_AUTODELETE));
@@ -358,6 +356,10 @@ public abstract class AMQDestination implements Destination, Referenceable
_destSyntax = DestSyntax.BURL;
_browseOnly = browseOnly;
_rejectBehaviour = null;
+ _exchangeAutoDelete = false;
+ _exchangeDurable = false;
+ _exchangeInternal = false;
+
if (_logger.isDebugEnabled())
{
_logger.debug("Based on " + toString() + " the selected destination syntax is " + _destSyntax);
@@ -412,6 +414,21 @@ public abstract class AMQDestination implements Destination, Referenceable
return _exchangeClass;
}
+ public boolean isExchangeDurable()
+ {
+ return _exchangeDurable;
+ }
+
+ public boolean isExchangeAutoDelete()
+ {
+ return _exchangeAutoDelete;
+ }
+
+ public boolean isExchangeInternal()
+ {
+ return _exchangeInternal;
+ }
+
public boolean isTopic()
{
return ExchangeDefaults.TOPIC_EXCHANGE_CLASS.equals(_exchangeClass);
@@ -579,6 +596,27 @@ public abstract class AMQDestination implements Destination, Referenceable
sb.append(URLHelper.DEFAULT_OPTION_SEPERATOR);
}
+ if (_exchangeDurable)
+ {
+ sb.append(BindingURL.OPTION_EXCHANGE_DURABLE);
+ sb.append("='true'");
+ sb.append(URLHelper.DEFAULT_OPTION_SEPERATOR);
+ }
+
+ if (_exchangeAutoDelete)
+ {
+ sb.append(BindingURL.OPTION_EXCHANGE_AUTODELETE);
+ sb.append("='true'");
+ sb.append(URLHelper.DEFAULT_OPTION_SEPERATOR);
+ }
+
+ if (_exchangeInternal)
+ {
+ sb.append(BindingURL.OPTION_EXCHANGE_INTERNAL);
+ sb.append("='true'");
+ sb.append(URLHelper.DEFAULT_OPTION_SEPERATOR);
+ }
+
//removeKey the last char '?' if there is no options , ',' if there are.
sb.deleteCharAt(sb.length() - 1);
url = sb.toString();
@@ -773,24 +811,14 @@ public abstract class AMQDestination implements Destination, Referenceable
_delete = option;
}
- public Node getTargetNode()
+ public Node getNode()
{
- return _targetNode;
+ return _node;
}
- public void setTargetNode(Node node)
+ public void setNode(Node node)
{
- _targetNode = node;
- }
-
- public Node getSourceNode()
- {
- return _sourceNode;
- }
-
- public void setSourceNode(Node node)
- {
- _sourceNode = node;
+ _node = node;
}
public Link getLink()
@@ -851,21 +879,11 @@ public abstract class AMQDestination implements Destination, Referenceable
_browseOnly = _addrHelper.isBrowseOnly();
- _addressType = _addrHelper.getTargetNodeType();
- _targetNode = _addrHelper.getTargetNode(_addressType);
- _sourceNode = _addrHelper.getSourceNode(_addressType);
+ _addressType = _addrHelper.getNodeType();
+ _node = _addrHelper.getNode();
_link = _addrHelper.getLink();
}
- // This method is needed if we didn't know the node type at the beginning.
- // Therefore we have to query the broker to figure out the type.
- // Once the type is known we look for the necessary properties.
- public void rebuildTargetAndSourceNodes(int addressType)
- {
- _targetNode = _addrHelper.getTargetNode(addressType);
- _sourceNode = _addrHelper.getSourceNode(addressType);
- }
-
// ----- / new address syntax -----------
public boolean isBrowseOnly()
@@ -900,8 +918,7 @@ public abstract class AMQDestination implements Destination, Referenceable
dest.setDelete(_delete);
dest.setBrowseOnly(_browseOnly);
dest.setAddressType(_addressType);
- dest.setTargetNode(_targetNode);
- dest.setSourceNode(_sourceNode);
+ dest.setNode(_node);
dest.setLink(_link);
dest.setAddressResolved(_addressResolved.get());
return dest;
@@ -935,6 +952,4 @@ public abstract class AMQDestination implements Destination, Referenceable
{
return _rejectBehaviour;
}
-
-
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
index 1468e90c4e..91a6389214 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
@@ -20,11 +20,6 @@
*/
package org.apache.qpid.client;
-import static org.apache.qpid.configuration.ClientProperties.DEFAULT_FLOW_CONTROL_WAIT_FAILURE;
-import static org.apache.qpid.configuration.ClientProperties.DEFAULT_FLOW_CONTROL_WAIT_NOTIFY_PERIOD;
-import static org.apache.qpid.configuration.ClientProperties.QPID_FLOW_CONTROL_WAIT_FAILURE;
-import static org.apache.qpid.configuration.ClientProperties.QPID_FLOW_CONTROL_WAIT_NOTIFY_PERIOD;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +35,7 @@ import org.apache.qpid.client.failover.FailoverProtectedOperation;
import org.apache.qpid.client.failover.FailoverRetrySupport;
import org.apache.qpid.client.message.AMQMessageDelegateFactory;
import org.apache.qpid.client.message.AMQPEncodedMapMessage;
+import org.apache.qpid.client.message.AMQPEncodedListMessage;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.CloseConsumerMessage;
import org.apache.qpid.client.message.JMSBytesMessage;
@@ -49,14 +45,13 @@ import org.apache.qpid.client.message.JMSStreamMessage;
import org.apache.qpid.client.message.JMSTextMessage;
import org.apache.qpid.client.message.MessageFactoryRegistry;
import org.apache.qpid.client.message.UnprocessedMessage;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.client.util.FlowControllingBlockingQueue;
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.configuration.ClientProperties;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.framing.MethodRegistry;
import org.apache.qpid.jms.Session;
+import org.apache.qpid.jms.ListMessage;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.thread.Threading;
import org.apache.qpid.transport.SessionException;
@@ -122,27 +117,16 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
/** Immediate message prefetch default. */
public static final String IMMEDIATE_PREFETCH_DEFAULT = "false";
- /**
- * The period to wait while flow controlled before sending a log message confirming that the session is still
- * waiting on flow control being revoked
- */
- private final long _flowControlWaitPeriod = Long.getLong(QPID_FLOW_CONTROL_WAIT_NOTIFY_PERIOD,
- DEFAULT_FLOW_CONTROL_WAIT_NOTIFY_PERIOD);
-
- /**
- * The period to wait while flow controlled before declaring a failure
- */
- private final long _flowControlWaitFailure = Long.getLong(QPID_FLOW_CONTROL_WAIT_FAILURE,
- DEFAULT_FLOW_CONTROL_WAIT_FAILURE);
-
private final boolean _delareQueues =
- Boolean.parseBoolean(System.getProperty("qpid.declare_queues", "true"));
+ Boolean.parseBoolean(System.getProperty(ClientProperties.QPID_DECLARE_QUEUES_PROP_NAME, "true"));
private final boolean _declareExchanges =
- Boolean.parseBoolean(System.getProperty("qpid.declare_exchanges", "true"));
+ Boolean.parseBoolean(System.getProperty(ClientProperties.QPID_DECLARE_EXCHANGES_PROP_NAME, "true"));
private final boolean _useAMQPEncodedMapMessage;
+ private final boolean _useAMQPEncodedStreamMessage;
+
/**
* Flag indicating to start dispatcher as a daemon thread
*/
@@ -265,11 +249,6 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
/** Has failover occured on this session with outstanding actions to commit? */
private boolean _failedOverDirty;
- /** Flow control */
- private FlowControlIndicator _flowControl = new FlowControlIndicator();
-
-
-
/** Holds the highest received delivery tag. */
protected AtomicLong getHighestDeliveryTag()
{
@@ -408,22 +387,6 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
}
}
- private static final class FlowControlIndicator
- {
- private volatile boolean _flowControl = true;
-
- public synchronized void setFlowControl(boolean flowControl)
- {
- _flowControl = flowControl;
- notify();
- }
-
- public boolean getFlowControl()
- {
- return _flowControl;
- }
- }
-
/**
* Creates a new session on a connection.
*
@@ -439,6 +402,7 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
MessageFactoryRegistry messageFactoryRegistry, int defaultPrefetchHighMark, int defaultPrefetchLowMark)
{
_useAMQPEncodedMapMessage = con == null ? true : !con.isUseLegacyMapMessageFormat();
+ _useAMQPEncodedStreamMessage = con == null ? false : !con.isUseLegacyStreamMessageFormat();
_strictAMQP = Boolean.parseBoolean(System.getProperties().getProperty(STRICT_AMQP, STRICT_AMQP_DEFAULT));
_strictAMQPFATAL =
Boolean.parseBoolean(System.getProperties().getProperty(STRICT_AMQP_FATAL, STRICT_AMQP_FATAL_DEFAULT));
@@ -649,12 +613,6 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
*/
public abstract void acknowledgeMessage(long deliveryTag, boolean multiple);
- public MethodRegistry getMethodRegistry()
- {
- MethodRegistry methodRegistry = getProtocolHandler().getMethodRegistry();
- return methodRegistry;
- }
-
/**
* Binds the named queue, with the specified routing key, to the named exchange.
*
@@ -1041,12 +999,11 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
{
try
{
- handleAddressBasedDestination(dest,false,noLocal,true);
+ resolveAddress(dest,false,noLocal);
if (dest.getAddressType() != AMQDestination.TOPIC_TYPE)
{
throw new JMSException("Durable subscribers can only be created for Topics");
}
- dest.getSourceNode().setDurable(true);
}
catch(AMQException e)
{
@@ -1158,6 +1115,14 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
}
}
+ public ListMessage createListMessage() throws JMSException
+ {
+ checkNotClosed();
+ AMQPEncodedListMessage msg = new AMQPEncodedListMessage(getMessageDelegateFactory());
+ msg.setAMQSession(this);
+ return msg;
+ }
+
public MapMessage createMapMessage() throws JMSException
{
checkNotClosed();
@@ -1400,17 +1365,15 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
public StreamMessage createStreamMessage() throws JMSException
{
- // This method needs to be improved. Throwables only arrive here from the mina : exceptionRecived
- // calls through connection.closeAllSessions which is also called by the public connection.close()
- // with a null cause
- // When we are closing the Session due to a protocol session error we simply create a new AMQException
- // with the correct error code and text this is cleary WRONG as the instanceof check below will fail.
- // We need to determin here if the connection should be
-
- synchronized (getFailoverMutex())
+ checkNotClosed();
+ if (_useAMQPEncodedStreamMessage)
+ {
+ AMQPEncodedListMessage msg = new AMQPEncodedListMessage(getMessageDelegateFactory());
+ msg.setAMQSession(this);
+ return msg;
+ }
+ else
{
- checkNotClosed();
-
JMSStreamMessage msg = new JMSStreamMessage(getMessageDelegateFactory());
msg.setAMQSession(this);
return msg;
@@ -1550,7 +1513,7 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
public void declareExchange(AMQShortString name, AMQShortString type, boolean nowait) throws AMQException
{
- declareExchange(name, type, getProtocolHandler(), nowait);
+ declareExchange(name, type, nowait, false, false, false);
}
abstract public void sync() throws AMQException;
@@ -1690,8 +1653,7 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
throws
AMQException
{
- AMQProtocolHandler protocolHandler = getProtocolHandler();
- declareExchange(amqd, protocolHandler, false);
+ declareExchange(amqd, false);
AMQShortString queueName = declareQueue(amqd, false);
bindQueue(queueName, amqd.getRoutingKey(), new FieldTable(), amqd.getExchangeName(), amqd);
}
@@ -2582,11 +2544,9 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
/**
* Register to consume from the queue.
- *
* @param queueName
*/
- private void consumeFromQueue(C consumer, AMQShortString queueName,
- AMQProtocolHandler protocolHandler, boolean nowait) throws AMQException, FailoverException
+ private void consumeFromQueue(C consumer, AMQShortString queueName, boolean nowait) throws AMQException, FailoverException
{
int tagId = _nextTag++;
@@ -2603,7 +2563,7 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
try
{
- sendConsume(consumer, queueName, protocolHandler, nowait, tagId);
+ sendConsume(consumer, queueName, nowait, tagId);
}
catch (AMQException e)
{
@@ -2614,7 +2574,7 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
}
public abstract void sendConsume(C consumer, AMQShortString queueName,
- AMQProtocolHandler protocolHandler, boolean nowait, int tag) throws AMQException, FailoverException;
+ boolean nowait, int tag) throws AMQException, FailoverException;
private P createProducerImpl(final Destination destination, final Boolean mandatory, final Boolean immediate)
throws JMSException
@@ -2648,9 +2608,10 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
public abstract P createMessageProducer(final Destination destination, final Boolean mandatory,
final Boolean immediate, final long producerId) throws JMSException;
- private void declareExchange(AMQDestination amqd, AMQProtocolHandler protocolHandler, boolean nowait) throws AMQException
+ private void declareExchange(AMQDestination amqd, boolean nowait) throws AMQException
{
- declareExchange(amqd.getExchangeName(), amqd.getExchangeClass(), protocolHandler, nowait);
+ declareExchange(amqd.getExchangeName(), amqd.getExchangeClass(), nowait, amqd.isExchangeDurable(),
+ amqd.isExchangeAutoDelete(), amqd.isExchangeInternal());
}
/**
@@ -2707,33 +2668,29 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
*
* @param name The name of the exchange to declare.
* @param type The type of the exchange to declare.
- * @param protocolHandler The protocol handler to process the communication through.
* @param nowait
- *
+ * @param durable
+ * @param autoDelete
+ * @param internal
* @throws AMQException If the exchange cannot be declared for any reason.
* @todo Be aware of possible changes to parameter order as versions change.
*/
private void declareExchange(final AMQShortString name, final AMQShortString type,
- final AMQProtocolHandler protocolHandler, final boolean nowait) throws AMQException
+ final boolean nowait, final boolean durable,
+ final boolean autoDelete, final boolean internal) throws AMQException
{
new FailoverNoopSupport<Object, AMQException>(new FailoverProtectedOperation<Object, AMQException>()
{
public Object execute() throws AMQException, FailoverException
{
- sendExchangeDeclare(name, type, protocolHandler, nowait);
+ sendExchangeDeclare(name, type, nowait, durable, autoDelete, internal);
return null;
}
}, _connection).execute();
}
- public abstract void sendExchangeDeclare(final AMQShortString name, final AMQShortString type, final AMQProtocolHandler protocolHandler,
- final boolean nowait) throws AMQException, FailoverException;
-
-
- void declareQueuePassive(AMQDestination queue) throws AMQException
- {
- declareQueue(queue,false,false,true);
- }
+ public abstract void sendExchangeDeclare(final AMQShortString name, final AMQShortString type, final boolean nowait,
+ boolean durable, boolean autoDelete, boolean internal) throws AMQException, FailoverException;
/**
* Declares a queue for a JMS destination.
@@ -2768,31 +2725,8 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
return declareQueue(amqd, noLocal, nowait, false);
}
- protected AMQShortString declareQueue(final AMQDestination amqd,
- final boolean noLocal, final boolean nowait, final boolean passive)
- throws AMQException
- {
- final AMQProtocolHandler protocolHandler = getProtocolHandler();
- return new FailoverNoopSupport<AMQShortString, AMQException>(
- new FailoverProtectedOperation<AMQShortString, AMQException>()
- {
- public AMQShortString execute() throws AMQException, FailoverException
- {
- // Generate the queue name if the destination indicates that a client generated name is to be used.
- if (amqd.isNameRequired())
- {
- amqd.setQueueName(protocolHandler.generateQueueName());
- }
-
- sendQueueDeclare(amqd, protocolHandler, nowait, passive);
-
- return amqd.getAMQQueueName();
- }
- }, _connection).execute();
- }
-
- public abstract void sendQueueDeclare(final AMQDestination amqd, final AMQProtocolHandler protocolHandler,
- final boolean nowait, boolean passive) throws AMQException, FailoverException;
+ protected abstract AMQShortString declareQueue(final AMQDestination amqd,
+ final boolean noLocal, final boolean nowait, final boolean passive) throws AMQException;
/**
* Undeclares the specified queue.
@@ -2845,21 +2779,6 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
return ++_nextProducerId;
}
- protected AMQProtocolHandler getProtocolHandler()
- {
- return _connection.getProtocolHandler();
- }
-
- public byte getProtocolMajorVersion()
- {
- return getProtocolHandler().getProtocolMajorVersion();
- }
-
- public byte getProtocolMinorVersion()
- {
- return getProtocolHandler().getProtocolMinorVersion();
- }
-
protected boolean hasMessageListeners()
{
return _hasMessageListeners;
@@ -2918,17 +2837,15 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
{
AMQDestination amqd = consumer.getDestination();
- AMQProtocolHandler protocolHandler = getProtocolHandler();
-
if (amqd.getDestSyntax() == DestSyntax.ADDR)
{
- handleAddressBasedDestination(amqd,true,consumer.isNoLocal(),nowait);
+ resolveAddress(amqd,true,consumer.isNoLocal());
}
else
{
if (_declareExchanges)
{
- declareExchange(amqd, protocolHandler, nowait);
+ declareExchange(amqd, nowait);
}
if (_delareQueues || amqd.isNameRequired())
@@ -2973,7 +2890,7 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
try
{
- consumeFromQueue(consumer, queueName, protocolHandler, nowait);
+ consumeFromQueue(consumer, queueName, nowait);
}
catch (FailoverException e)
{
@@ -2981,10 +2898,9 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
}
}
- public abstract void handleAddressBasedDestination(AMQDestination dest,
+ public abstract void resolveAddress(AMQDestination dest,
boolean isConsumer,
- boolean noLocal,
- boolean noWait) throws AMQException;
+ boolean noLocal) throws AMQException;
private void registerProducer(long producerId, MessageProducer producer)
{
@@ -3141,47 +3057,14 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
_ticket = ticket;
}
- public boolean isFlowBlocked()
- {
- synchronized (_flowControl)
- {
- return !_flowControl.getFlowControl();
- }
- }
-
- public void setFlowControl(final boolean active)
- {
- _flowControl.setFlowControl(active);
- if (_logger.isInfoEnabled())
- {
- _logger.info("Broker enforced flow control " + (active ? "no longer in effect" : "has been enforced"));
- }
- }
-
- public void checkFlowControl() throws InterruptedException, JMSException
- {
- long expiryTime = 0L;
- synchronized (_flowControl)
- {
- while (!_flowControl.getFlowControl() &&
- (expiryTime == 0L ? (expiryTime = System.currentTimeMillis() + _flowControlWaitFailure)
- : expiryTime) >= System.currentTimeMillis() )
- {
-
- _flowControl.wait(_flowControlWaitPeriod);
- if (_logger.isInfoEnabled())
- {
- _logger.info("Message send delayed by " + (System.currentTimeMillis() + _flowControlWaitFailure - expiryTime)/1000 + "s due to broker enforced flow control");
- }
- }
- if(!_flowControl.getFlowControl())
- {
- _logger.error("Message send failed due to timeout waiting on broker enforced flow control");
- throw new JMSException("Unable to send message for " + _flowControlWaitFailure /1000 + " seconds due to broker enforced flow control");
- }
- }
+ /**
+ * Tests whether flow to this session is blocked.
+ *
+ * @return true if flow is blocked or false otherwise.
+ */
+ public abstract boolean isFlowBlocked();
- }
+ public abstract void setFlowControl(final boolean active);
public interface Dispatchable
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
index 8a7c6b1a01..8490a724bf 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java
@@ -17,6 +17,11 @@
*/
package org.apache.qpid.client;
+import static org.apache.qpid.transport.Option.BATCH;
+import static org.apache.qpid.transport.Option.NONE;
+import static org.apache.qpid.transport.Option.SYNC;
+import static org.apache.qpid.transport.Option.UNRELIABLE;
+
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
@@ -29,8 +34,10 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
+
import javax.jms.Destination;
import javax.jms.JMSException;
+
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQDestination.AddressOption;
import org.apache.qpid.client.AMQDestination.Binding;
@@ -44,18 +51,32 @@ import org.apache.qpid.client.message.MessageFactoryRegistry;
import org.apache.qpid.client.message.UnprocessedMessage_0_10;
import org.apache.qpid.client.messaging.address.AddressHelper;
import org.apache.qpid.client.messaging.address.Link;
-import org.apache.qpid.client.messaging.address.Node.ExchangeNode;
-import org.apache.qpid.client.messaging.address.Node.QueueNode;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.messaging.address.Link.SubscriptionQueue;
+import org.apache.qpid.client.messaging.address.Node;
+import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.transport.*;
-import static org.apache.qpid.transport.Option.BATCH;
-import static org.apache.qpid.transport.Option.NONE;
-import static org.apache.qpid.transport.Option.SYNC;
-import static org.apache.qpid.transport.Option.UNRELIABLE;
+import org.apache.qpid.transport.Connection;
+import org.apache.qpid.transport.ExchangeBoundResult;
+import org.apache.qpid.transport.ExchangeQueryResult;
+import org.apache.qpid.transport.ExecutionErrorCode;
+import org.apache.qpid.transport.ExecutionException;
+import org.apache.qpid.transport.MessageAcceptMode;
+import org.apache.qpid.transport.MessageAcquireMode;
+import org.apache.qpid.transport.MessageCreditUnit;
+import org.apache.qpid.transport.MessageFlowMode;
+import org.apache.qpid.transport.MessageTransfer;
+import org.apache.qpid.transport.Option;
+import org.apache.qpid.transport.QueueQueryResult;
+import org.apache.qpid.transport.Range;
+import org.apache.qpid.transport.RangeSet;
+import org.apache.qpid.transport.RangeSetFactory;
+import org.apache.qpid.transport.Session;
+import org.apache.qpid.transport.SessionException;
+import org.apache.qpid.transport.SessionListener;
+import org.apache.qpid.transport.TransportException;
import org.apache.qpid.util.Serial;
import org.apache.qpid.util.Strings;
import org.slf4j.Logger;
@@ -347,15 +368,22 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
}
else
{
+ // Leaving this here to ensure the public method bindQueue in AMQSession.java works as expected.
List<Binding> bindings = new ArrayList<Binding>();
- bindings.addAll(destination.getSourceNode().getBindings());
- bindings.addAll(destination.getTargetNode().getBindings());
+ bindings.addAll(destination.getNode().getBindings());
String defaultExchange = destination.getAddressType() == AMQDestination.TOPIC_TYPE ?
destination.getAddressName(): "amq.topic";
for (Binding binding: bindings)
{
+ // Currently there is a bug (QPID-3317) with setting up and tearing down x-bindings for link.
+ // The null check below is a way to side step that issue while fixing QPID-4146
+ // Note this issue only affects producers.
+ if (binding.getQueue() == null && queueName == null)
+ {
+ continue;
+ }
String queue = binding.getQueue() == null?
queueName.asString(): binding.getQueue();
@@ -523,11 +551,9 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
final FieldTable rawSelector, final boolean noConsume,
final boolean autoClose) throws JMSException
{
-
- final AMQProtocolHandler protocolHandler = getProtocolHandler();
return new BasicMessageConsumer_0_10(getChannelId(), getAMQConnection(), destination, messageSelector, noLocal,
- getMessageFactoryRegistry(), this, protocolHandler, rawSelector, prefetchHigh,
- prefetchLow, exclusive, getAcknowledgeMode(), noConsume, autoClose);
+ getMessageFactoryRegistry(), this, rawSelector, prefetchHigh, prefetchLow,
+ exclusive, getAcknowledgeMode(), noConsume, autoClose);
}
/**
@@ -558,7 +584,7 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
rk = routingKey.toString();
}
- return isQueueBound(exchangeName.toString(),queueName.toString(),rk,null);
+ return isQueueBound(exchangeName == null ? null : exchangeName.toString(),queueName == null ? null : queueName.toString(),rk,null);
}
public boolean isQueueBound(final String exchangeName, final String queueName, final String bindingKey,Map<String,Object> args)
@@ -591,10 +617,22 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
* This method is invoked when a consumer is created
* Registers the consumer with the broker
*/
- public void sendConsume(BasicMessageConsumer_0_10 consumer, AMQShortString queueName, AMQProtocolHandler protocolHandler,
+ public void sendConsume(BasicMessageConsumer_0_10 consumer, AMQShortString queueName,
boolean nowait, int tag)
throws AMQException, FailoverException
- {
+ {
+ if (AMQDestination.DestSyntax.ADDR == consumer.getDestination().getDestSyntax())
+ {
+ if (AMQDestination.TOPIC_TYPE == consumer.getDestination().getAddressType())
+ {
+ String selector = consumer.getMessageSelectorFilter() == null? null : consumer.getMessageSelectorFilter().getSelector();
+
+ createSubscriptionQueue(consumer.getDestination(), consumer.isNoLocal(), selector);
+ queueName = consumer.getDestination().getAMQQueueName();
+ consumer.setQueuename(queueName);
+ }
+ handleLinkCreation(consumer.getDestination());
+ }
boolean preAcquire = consumer.isPreAcquire();
AMQDestination destination = consumer.getDestination();
@@ -637,11 +675,7 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
capacity,
Option.UNRELIABLE);
}
-
- if (!nowait)
- {
- sync();
- }
+ sync();
}
/**
@@ -653,7 +687,7 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
try
{
return new BasicMessageProducer_0_10(getAMQConnection(), (AMQDestination) destination, isTransacted(), getChannelId(), this,
- getProtocolHandler(), producerId, immediate, mandatory);
+ producerId, immediate, mandatory);
}
catch (AMQException e)
{
@@ -673,26 +707,25 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
/**
* creates an exchange if it does not already exist
*/
- public void sendExchangeDeclare(final AMQShortString name,
- final AMQShortString type,
- final AMQProtocolHandler protocolHandler, final boolean nowait)
- throws AMQException, FailoverException
+ public void sendExchangeDeclare(final AMQShortString name, final AMQShortString type, final boolean nowait,
+ boolean durable, boolean autoDelete, boolean internal) throws AMQException, FailoverException
{
- sendExchangeDeclare(name.asString(), type.asString(), null, null,
- nowait);
+ //The 'internal' parameter is ignored on the 0-10 path, the protocol does not support it
+ sendExchangeDeclare(name.asString(), type.asString(), null, null, nowait, durable, autoDelete);
}
public void sendExchangeDeclare(final String name, final String type,
final String alternateExchange, final Map<String, Object> args,
- final boolean nowait) throws AMQException
+ final boolean nowait, boolean durable, boolean autoDelete) throws AMQException
{
getQpidSession().exchangeDeclare(
name,
type,
alternateExchange,
args,
- name.toString().startsWith("amq.") ? Option.PASSIVE
- : Option.NONE);
+ name.toString().startsWith("amq.") ? Option.PASSIVE : Option.NONE,
+ durable ? Option.DURABLE : Option.NONE,
+ autoDelete ? Option.AUTO_DELETE : Option.NONE);
// We need to sync so that we get notify of an error.
if (!nowait)
{
@@ -717,18 +750,8 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
/**
* Declare a queue with the given queueName
*/
- public void sendQueueDeclare(final AMQDestination amqd, final AMQProtocolHandler protocolHandler,
- final boolean nowait, boolean passive)
- throws AMQException, FailoverException
- {
- // do nothing this is only used by 0_8
- }
-
- /**
- * Declare a queue with the given queueName
- */
- public AMQShortString send0_10QueueDeclare(final AMQDestination amqd, final AMQProtocolHandler protocolHandler,
- final boolean noLocal, final boolean nowait, boolean passive)
+ public AMQShortString send0_10QueueDeclare(final AMQDestination amqd, final boolean noLocal,
+ final boolean nowait, boolean passive)
throws AMQException
{
AMQShortString queueName;
@@ -759,7 +782,8 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
}
else
{
- QueueNode node = (QueueNode)amqd.getSourceNode();
+ // This code is here to ensure address based destination work with the declareQueue public method in AMQSession.java
+ Node node = amqd.getNode();
Map<String,Object> arguments = new HashMap<String,Object>();
arguments.putAll((Map<? extends String, ? extends Object>) node.getDeclareArgs());
if (arguments == null || arguments.get(AddressHelper.NO_LOCAL) == null)
@@ -925,12 +949,11 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
return getCurrentException();
}
+ @Override
protected AMQShortString declareQueue(final AMQDestination amqd,
final boolean noLocal, final boolean nowait, final boolean passive)
throws AMQException
{
- final AMQProtocolHandler protocolHandler = getProtocolHandler();
-
return new FailoverNoopSupport<AMQShortString, AMQException>(
new FailoverProtectedOperation<AMQShortString, AMQException>()
{
@@ -947,7 +970,7 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
amqd.setQueueName(new AMQShortString( binddingKey + "@"
+ amqd.getExchangeName().toString() + "_" + UUID.randomUUID()));
}
- return send0_10QueueDeclare(amqd, protocolHandler, noLocal, nowait, passive);
+ return send0_10QueueDeclare(amqd, noLocal, nowait, passive);
}
}, getAMQConnection()).execute();
}
@@ -1072,11 +1095,12 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
return AMQMessageDelegateFactory.FACTORY_0_10;
}
- public boolean isExchangeExist(AMQDestination dest,ExchangeNode node,boolean assertNode)
+ public boolean isExchangeExist(AMQDestination dest,boolean assertNode) throws AMQException
{
boolean match = true;
ExchangeQueryResult result = getQpidSession().exchangeQuery(dest.getAddressName(), Option.NONE).get();
match = !result.getNotFound();
+ Node node = dest.getNode();
if (match)
{
@@ -1086,16 +1110,6 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
(node.getExchangeType() != null &&
node.getExchangeType().equals(result.getType())) &&
(matchProps(result.getArguments(),node.getDeclareArgs()));
- }
- else if (node.getExchangeType() != null)
- {
- // even if assert is false, better to verify this
- match = node.getExchangeType().equals(result.getType());
- if (!match)
- {
- _logger.debug("Exchange type doesn't match. Expected : " + node.getExchangeType() +
- " actual " + result.getType());
- }
}
else
{
@@ -1104,18 +1118,27 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
dest.setExchangeClass(new AMQShortString(result.getType()));
}
}
-
+
+ if (assertNode)
+ {
+ if (!match)
+ {
+ throw new AMQException("Assert failed for address : " + dest +", Result was : " + result);
+ }
+ }
+
return match;
}
- public boolean isQueueExist(AMQDestination dest,QueueNode node,boolean assertNode) throws AMQException
+ public boolean isQueueExist(AMQDestination dest, boolean assertNode) throws AMQException
{
boolean match = true;
try
{
QueueQueryResult result = getQpidSession().queueQuery(dest.getAddressName(), Option.NONE).get();
match = dest.getAddressName().equals(result.getQueue());
-
+ Node node = dest.getNode();
+
if (match && assertNode)
{
match = (result.getDurable() == node.isDurable()) &&
@@ -1123,9 +1146,13 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
(result.getExclusive() == node.isExclusive()) &&
(matchProps(result.getArguments(),node.getDeclareArgs()));
}
- else if (match)
+
+ if (assertNode)
{
- // should I use the queried details to update the local data structure.
+ if (!match)
+ {
+ throw new AMQException("Assert failed for address : " + dest +", Result was : " + result);
+ }
}
}
catch(SessionException e)
@@ -1140,7 +1167,6 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
"Error querying queue",e);
}
}
-
return match;
}
@@ -1179,17 +1205,13 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
*/
@SuppressWarnings("deprecation")
- public void handleAddressBasedDestination(AMQDestination dest,
+ public void resolveAddress(AMQDestination dest,
boolean isConsumer,
- boolean noLocal,
- boolean noWait) throws AMQException
+ boolean noLocal) throws AMQException
{
if (dest.isAddressResolved() && dest.isResolvedAfter(getAMQConnection().getLastFailoverTime()))
{
- if (isConsumer && AMQDestination.TOPIC_TYPE == dest.getAddressType())
- {
- createSubscriptionQueue(dest,noLocal);
- }
+ return;
}
else
{
@@ -1209,46 +1231,32 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
{
case AMQDestination.QUEUE_TYPE:
{
- if (isQueueExist(dest,(QueueNode)dest.getSourceNode(),assertNode))
+ if(createNode)
{
- setLegacyFiledsForQueueType(dest);
+ setLegacyFieldsForQueueType(dest);
+ handleQueueNodeCreation(dest,noLocal);
break;
}
- else if(createNode)
+ else if (isQueueExist(dest,assertNode))
{
- setLegacyFiledsForQueueType(dest);
- send0_10QueueDeclare(dest,null,noLocal,noWait, false);
- sendQueueBind(dest.getAMQQueueName(), dest.getRoutingKey(),
- null,dest.getExchangeName(),dest, false);
+ setLegacyFieldsForQueueType(dest);
break;
- }
+ }
}
case AMQDestination.TOPIC_TYPE:
{
- if (isExchangeExist(dest,(ExchangeNode)dest.getTargetNode(),assertNode))
+ if(createNode)
{
setLegacyFiledsForTopicType(dest);
verifySubject(dest);
- if (isConsumer && !isQueueExist(dest,(QueueNode)dest.getSourceNode(),true))
- {
- createSubscriptionQueue(dest, noLocal);
- }
+ handleExchangeNodeCreation(dest);
break;
}
- else if(createNode)
+ else if (isExchangeExist(dest,assertNode))
{
setLegacyFiledsForTopicType(dest);
verifySubject(dest);
- sendExchangeDeclare(dest.getAddressName(),
- dest.getExchangeClass().asString(),
- dest.getTargetNode().getAlternateExchange(),
- dest.getTargetNode().getDeclareArgs(),
- false);
- if (isConsumer && !isQueueExist(dest,(QueueNode)dest.getSourceNode(),true))
- {
- createSubscriptionQueue(dest,noLocal);
- }
break;
}
}
@@ -1287,7 +1295,6 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
throw new AMQException("Ambiguous address, please specify queue or topic as node type");
}
dest.setAddressType(type);
- dest.rebuildTargetAndSourceNodes(type);
return type;
}
}
@@ -1309,30 +1316,45 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
}
}
}
-
- private void createSubscriptionQueue(AMQDestination dest, boolean noLocal) throws AMQException
+
+ void createSubscriptionQueue(AMQDestination dest, boolean noLocal, String messageSelector) throws AMQException
{
- QueueNode node = (QueueNode)dest.getSourceNode(); // source node is never null
-
- if (dest.getQueueName() == null)
+ Link link = dest.getLink();
+ String queueName = dest.getQueueName();
+
+ if (queueName == null)
{
- if (dest.getLink() != null && dest.getLink().getName() != null)
- {
- dest.setQueueName(new AMQShortString(dest.getLink().getName()));
- }
+ queueName = link.getName() == null ? "TempQueue" + UUID.randomUUID() : link.getName();
+ dest.setQueueName(new AMQShortString(queueName));
+ }
+
+ SubscriptionQueue queueProps = link.getSubscriptionQueue();
+ Map<String,Object> arguments = queueProps.getDeclareArgs();
+ if (!arguments.containsKey((AddressHelper.NO_LOCAL)))
+ {
+ arguments.put(AddressHelper.NO_LOCAL, noLocal);
+ }
+
+ if (link.isDurable() && queueName.startsWith("TempQueue"))
+ {
+ throw new AMQException("You cannot mark a subscription queue as durable without providing a name for the link.");
}
- node.setExclusive(true);
- node.setAutoDelete(!node.isDurable());
- send0_10QueueDeclare(dest,null,noLocal,true, false);
- getQpidSession().exchangeBind(dest.getQueueName(),
- dest.getAddressName(),
- dest.getSubject(),
- Collections.<String,Object>emptyMap());
- sendQueueBind(dest.getAMQQueueName(), dest.getRoutingKey(),
- null,dest.getExchangeName(),dest, false);
+
+ getQpidSession().queueDeclare(queueName,
+ queueProps.getAlternateExchange(), arguments,
+ queueProps.isAutoDelete() ? Option.AUTO_DELETE : Option.NONE,
+ link.isDurable() ? Option.DURABLE : Option.NONE,
+ queueProps.isExclusive() ? Option.EXCLUSIVE : Option.NONE);
+
+ Map<String,Object> bindingArguments = new HashMap<String, Object>();
+ bindingArguments.put(AMQPFilterTypes.JMS_SELECTOR.getValue().toString(), messageSelector == null ? "" : messageSelector);
+ getQpidSession().exchangeBind(queueName,
+ dest.getAddressName(),
+ dest.getSubject(),
+ bindingArguments);
}
-
- public void setLegacyFiledsForQueueType(AMQDestination dest)
+
+ public void setLegacyFieldsForQueueType(AMQDestination dest)
{
// legacy support
dest.setQueueName(new AMQShortString(dest.getAddressName()));
@@ -1345,7 +1367,7 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
{
// legacy support
dest.setExchangeName(new AMQShortString(dest.getAddressName()));
- ExchangeNode node = (ExchangeNode)dest.getTargetNode();
+ Node node = dest.getNode();
dest.setExchangeClass(node.getExchangeType() == null?
ExchangeDefaults.TOPIC_EXCHANGE_CLASS:
new AMQShortString(node.getExchangeType()));
@@ -1424,6 +1446,13 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
return _qpidSession.isFlowBlocked();
}
+ @Override
+ public void setFlowControl(boolean active)
+ {
+ // Supported by 0-8..0-9-1 only
+ throw new UnsupportedOperationException("Operation not supported by this protocol");
+ }
+
private void cancelTimerTask()
{
if (flushTask != null)
@@ -1432,5 +1461,148 @@ public class AMQSession_0_10 extends AMQSession<BasicMessageConsumer_0_10, Basic
flushTask = null;
}
}
-}
+ private void handleQueueNodeCreation(AMQDestination dest, boolean noLocal) throws AMQException
+ {
+ Node node = dest.getNode();
+ Map<String,Object> arguments = node.getDeclareArgs();
+ if (!arguments.containsKey((AddressHelper.NO_LOCAL)))
+ {
+ arguments.put(AddressHelper.NO_LOCAL, noLocal);
+ }
+ getQpidSession().queueDeclare(dest.getAddressName(),
+ node.getAlternateExchange(), arguments,
+ node.isAutoDelete() ? Option.AUTO_DELETE : Option.NONE,
+ node.isDurable() ? Option.DURABLE : Option.NONE,
+ node.isExclusive() ? Option.EXCLUSIVE : Option.NONE);
+
+ createBindings(dest, dest.getNode().getBindings());
+ sync();
+ }
+
+ void handleExchangeNodeCreation(AMQDestination dest) throws AMQException
+ {
+ Node node = dest.getNode();
+ sendExchangeDeclare(dest.getAddressName(),
+ node.getExchangeType(),
+ node.getAlternateExchange(),
+ node.getDeclareArgs(),
+ false,
+ node.isDurable(),
+ node.isAutoDelete());
+
+ // If bindings are specified without a queue name and is called by the producer,
+ // the broker will send an exception as expected.
+ createBindings(dest, dest.getNode().getBindings());
+ sync();
+ }
+
+ void handleLinkCreation(AMQDestination dest) throws AMQException
+ {
+ createBindings(dest, dest.getLink().getBindings());
+ }
+
+ void createBindings(AMQDestination dest, List<Binding> bindings)
+ {
+ String defaultExchangeForBinding = dest.getAddressType() == AMQDestination.TOPIC_TYPE ? dest
+ .getAddressName() : "amq.topic";
+
+ String defaultQueueName = null;
+ if (AMQDestination.QUEUE_TYPE == dest.getAddressType())
+ {
+ defaultQueueName = dest.getQueueName();
+ }
+ else
+ {
+ defaultQueueName = dest.getLink().getName() != null ? dest.getLink().getName() : dest.getQueueName();
+ }
+
+ for (Binding binding: bindings)
+ {
+ String queue = binding.getQueue() == null?
+ defaultQueueName: binding.getQueue();
+
+ String exchange = binding.getExchange() == null ?
+ defaultExchangeForBinding :
+ binding.getExchange();
+
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Binding queue : " + queue +
+ " exchange: " + exchange +
+ " using binding key " + binding.getBindingKey() +
+ " with args " + Strings.printMap(binding.getArgs()));
+ }
+ getQpidSession().exchangeBind(queue,
+ exchange,
+ binding.getBindingKey(),
+ binding.getArgs());
+ }
+ }
+
+ void handleLinkDelete(AMQDestination dest) throws AMQException
+ {
+ // We need to destroy link bindings
+ String defaultExchangeForBinding = dest.getAddressType() == AMQDestination.TOPIC_TYPE ? dest
+ .getAddressName() : "amq.topic";
+
+ String defaultQueueName = null;
+ if (AMQDestination.QUEUE_TYPE == dest.getAddressType())
+ {
+ defaultQueueName = dest.getQueueName();
+ }
+ else
+ {
+ defaultQueueName = dest.getLink().getName() != null ? dest.getLink().getName() : dest.getQueueName();
+ }
+
+ for (Binding binding: dest.getLink().getBindings())
+ {
+ String queue = binding.getQueue() == null?
+ defaultQueueName: binding.getQueue();
+
+ String exchange = binding.getExchange() == null ?
+ defaultExchangeForBinding :
+ binding.getExchange();
+
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Unbinding queue : " + queue +
+ " exchange: " + exchange +
+ " using binding key " + binding.getBindingKey() +
+ " with args " + Strings.printMap(binding.getArgs()));
+ }
+ getQpidSession().exchangeUnbind(queue, exchange,
+ binding.getBindingKey());
+ }
+ }
+
+ void deleteSubscriptionQueue(AMQDestination dest) throws AMQException
+ {
+ // We need to delete the subscription queue.
+ if (dest.getAddressType() == AMQDestination.TOPIC_TYPE &&
+ dest.getLink().getSubscriptionQueue().isExclusive() &&
+ isQueueExist(dest, false))
+ {
+ getQpidSession().queueDelete(dest.getQueueName());
+ }
+ }
+
+ void handleNodeDelete(AMQDestination dest) throws AMQException
+ {
+ if (AMQDestination.TOPIC_TYPE == dest.getAddressType())
+ {
+ if (isExchangeExist(dest,false))
+ {
+ getQpidSession().exchangeDelete(dest.getAddressName());
+ }
+ }
+ else
+ {
+ if (isQueueExist(dest,false))
+ {
+ getQpidSession().queueDelete(dest.getAddressName());
+ }
+ }
+ }
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
index 8ab23a240e..3097b33da3 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_8.java
@@ -21,12 +21,18 @@
package org.apache.qpid.client;
+import static org.apache.qpid.configuration.ClientProperties.DEFAULT_FLOW_CONTROL_WAIT_FAILURE;
+import static org.apache.qpid.configuration.ClientProperties.DEFAULT_FLOW_CONTROL_WAIT_NOTIFY_PERIOD;
+import static org.apache.qpid.configuration.ClientProperties.QPID_FLOW_CONTROL_WAIT_FAILURE;
+import static org.apache.qpid.configuration.ClientProperties.QPID_FLOW_CONTROL_WAIT_NOTIFY_PERIOD;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQUndeliveredException;
import org.apache.qpid.client.failover.FailoverException;
+import org.apache.qpid.client.failover.FailoverNoopSupport;
import org.apache.qpid.client.failover.FailoverProtectedOperation;
import org.apache.qpid.client.failover.FailoverRetrySupport;
import org.apache.qpid.client.message.AMQMessageDelegateFactory;
@@ -58,6 +64,27 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
/** Used for debugging. */
private static final Logger _logger = LoggerFactory.getLogger(AMQSession.class);
+ public static final String QPID_SYNC_AFTER_CLIENT_ACK = "qpid.sync_after_client.ack";
+
+ private final boolean _syncAfterClientAck =
+ Boolean.parseBoolean(System.getProperty(QPID_SYNC_AFTER_CLIENT_ACK, "true"));
+
+ /**
+ * The period to wait while flow controlled before sending a log message confirming that the session is still
+ * waiting on flow control being revoked
+ */
+ private final long _flowControlWaitPeriod = Long.getLong(QPID_FLOW_CONTROL_WAIT_NOTIFY_PERIOD,
+ DEFAULT_FLOW_CONTROL_WAIT_NOTIFY_PERIOD);
+
+ /**
+ * The period to wait while flow controlled before declaring a failure
+ */
+ private final long _flowControlWaitFailure = Long.getLong(QPID_FLOW_CONTROL_WAIT_FAILURE,
+ DEFAULT_FLOW_CONTROL_WAIT_FAILURE);
+
+ /** Flow control */
+ private FlowControlIndicator _flowControl = new FlowControlIndicator();
+
/**
* Creates a new session on a connection.
*
@@ -98,8 +125,9 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
return getProtocolHandler().getProtocolVersion();
}
- protected void acknowledgeImpl()
+ protected void acknowledgeImpl() throws JMSException
{
+ boolean syncRequired = false;
while (true)
{
Long tag = getUnacknowledgedMessageTags().poll();
@@ -109,6 +137,19 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
}
acknowledgeMessage(tag, false);
+ syncRequired = true;
+ }
+
+ try
+ {
+ if (syncRequired && _syncAfterClientAck)
+ {
+ sync();
+ }
+ }
+ catch (AMQException a)
+ {
+ throw new JMSAMQException("Failed to sync after acknowledge", a);
}
}
@@ -359,9 +400,9 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
}
}
- @Override public void sendConsume(BasicMessageConsumer_0_8 consumer,
+ @Override
+ public void sendConsume(BasicMessageConsumer_0_8 consumer,
AMQShortString queueName,
- AMQProtocolHandler protocolHandler,
boolean nowait,
int tag) throws AMQException, FailoverException
{
@@ -380,27 +421,29 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
if (nowait)
{
- protocolHandler.writeFrame(jmsConsume);
+ getProtocolHandler().writeFrame(jmsConsume);
}
else
{
- protocolHandler.syncWrite(jmsConsume, BasicConsumeOkBody.class);
+ getProtocolHandler().syncWrite(jmsConsume, BasicConsumeOkBody.class);
}
}
- public void sendExchangeDeclare(final AMQShortString name, final AMQShortString type, final AMQProtocolHandler protocolHandler,
- final boolean nowait) throws AMQException, FailoverException
+ @Override
+ public void sendExchangeDeclare(final AMQShortString name, final AMQShortString type, final boolean nowait,
+ boolean durable, boolean autoDelete, boolean internal) throws AMQException, FailoverException
{
+ //The 'noWait' parameter is only used on the 0-10 path, it is ignored on the 0-8/0-9/0-9-1 path
+
ExchangeDeclareBody body = getMethodRegistry().createExchangeDeclareBody(getTicket(),name,type,
name.toString().startsWith("amq."),
- false,false,false,false,null);
+ durable, autoDelete, internal, false, null);
AMQFrame exchangeDeclare = body.generateFrame(getChannelId());
- protocolHandler.syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class);
+ getProtocolHandler().syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class);
}
- public void sendQueueDeclare(final AMQDestination amqd, final AMQProtocolHandler protocolHandler,
- final boolean nowait, boolean passive) throws AMQException, FailoverException
+ private void sendQueueDeclare(final AMQDestination amqd, boolean passive) throws AMQException, FailoverException
{
QueueDeclareBody body =
getMethodRegistry().createQueueDeclareBody(getTicket(),
@@ -414,7 +457,32 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
AMQFrame queueDeclare = body.generateFrame(getChannelId());
- protocolHandler.syncWrite(queueDeclare, QueueDeclareOkBody.class);
+ getProtocolHandler().syncWrite(queueDeclare, QueueDeclareOkBody.class);
+ }
+
+ @Override
+ protected AMQShortString declareQueue(final AMQDestination amqd, final boolean noLocal,
+ final boolean nowait, final boolean passive) throws AMQException
+ {
+ //The 'noWait' parameter is only used on the 0-10 path, it is ignored on the 0-8/0-9/0-9-1 path
+
+ final AMQProtocolHandler protocolHandler = getProtocolHandler();
+ return new FailoverNoopSupport<AMQShortString, AMQException>(
+ new FailoverProtectedOperation<AMQShortString, AMQException>()
+ {
+ public AMQShortString execute() throws AMQException, FailoverException
+ {
+ // Generate the queue name if the destination indicates that a client generated name is to be used.
+ if (amqd.isNameRequired())
+ {
+ amqd.setQueueName(protocolHandler.generateQueueName());
+ }
+
+ sendQueueDeclare(amqd, passive);
+
+ return amqd.getAMQQueueName();
+ }
+ }, getAMQConnection()).execute();
}
public void sendQueueDelete(final AMQShortString queueName) throws AMQException, FailoverException
@@ -440,10 +508,8 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
final int prefetchLow, final boolean noLocal, final boolean exclusive, String messageSelector, final FieldTable arguments,
final boolean noConsume, final boolean autoClose) throws JMSException
{
-
- final AMQProtocolHandler protocolHandler = getProtocolHandler();
return new BasicMessageConsumer_0_8(getChannelId(), getAMQConnection(), destination, messageSelector, noLocal,
- getMessageFactoryRegistry(),this, protocolHandler, arguments, prefetchHigh, prefetchLow,
+ getMessageFactoryRegistry(),this, arguments, prefetchHigh, prefetchLow,
exclusive, getAcknowledgeMode(), noConsume, autoClose);
}
@@ -629,12 +695,11 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
declareExchange(new AMQShortString("amq.direct"), new AMQShortString("direct"), false);
}
- public void handleAddressBasedDestination(AMQDestination dest,
+ public void resolveAddress(AMQDestination dest,
boolean isConsumer,
- boolean noLocal,
- boolean noWait) throws AMQException
+ boolean noLocal) throws AMQException
{
- throw new UnsupportedOperationException("The new addressing based sytanx is "
+ throw new UnsupportedOperationException("The new addressing based syntax is "
+ "not supported for AMQP 0-8/0-9 versions");
}
@@ -662,14 +727,23 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
queueName == null ? null : new AMQShortString(queueName),
bindingKey == null ? null : new AMQShortString(bindingKey));
}
-
+
+ private AMQProtocolHandler getProtocolHandler()
+ {
+ return getAMQConnection().getProtocolHandler();
+ }
+
+ public MethodRegistry getMethodRegistry()
+ {
+ MethodRegistry methodRegistry = getProtocolHandler().getMethodRegistry();
+ return methodRegistry;
+ }
public AMQException getLastException()
{
// if the Connection has closed then we should throw any exception that
// has occurred that we were not waiting for
- AMQStateManager manager = getAMQConnection().getProtocolHandler()
- .getStateManager();
+ AMQStateManager manager = getProtocolHandler().getStateManager();
Exception e = manager.getLastException();
if (manager.getCurrentState().equals(AMQState.CONNECTION_CLOSED)
@@ -693,6 +767,49 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
}
}
+ public boolean isFlowBlocked()
+ {
+ synchronized (_flowControl)
+ {
+ return !_flowControl.getFlowControl();
+ }
+ }
+
+ public void setFlowControl(final boolean active)
+ {
+ _flowControl.setFlowControl(active);
+ if (_logger.isInfoEnabled())
+ {
+ _logger.info("Broker enforced flow control " + (active ? "no longer in effect" : "has been enforced"));
+ }
+ }
+
+ void checkFlowControl() throws InterruptedException, JMSException
+ {
+ long expiryTime = 0L;
+ synchronized (_flowControl)
+ {
+ while (!_flowControl.getFlowControl() &&
+ (expiryTime == 0L ? (expiryTime = System.currentTimeMillis() + _flowControlWaitFailure)
+ : expiryTime) >= System.currentTimeMillis() )
+ {
+
+ _flowControl.wait(_flowControlWaitPeriod);
+ if (_logger.isInfoEnabled())
+ {
+ _logger.info("Message send delayed by " + (System.currentTimeMillis() + _flowControlWaitFailure - expiryTime)/1000 + "s due to broker enforced flow control");
+ }
+ }
+ if(!_flowControl.getFlowControl())
+ {
+ _logger.error("Message send failed due to timeout waiting on broker enforced flow control");
+ throw new JMSException("Unable to send message for " + _flowControlWaitFailure /1000 + " seconds due to broker enforced flow control");
+ }
+ }
+ }
+
+
+
public abstract static class DestinationCache<T extends AMQDestination>
{
private final Map<AMQShortString, Map<AMQShortString, T>> cache = new HashMap<AMQShortString, Map<AMQShortString, T>>();
@@ -740,6 +857,22 @@ public class AMQSession_0_8 extends AMQSession<BasicMessageConsumer_0_8, BasicMe
}
}
+ private static final class FlowControlIndicator
+ {
+ private volatile boolean _flowControl = true;
+
+ public synchronized void setFlowControl(boolean flowControl)
+ {
+ _flowControl = flowControl;
+ notify();
+ }
+
+ public boolean getFlowControl()
+ {
+ return _flowControl;
+ }
+ }
+
private final TopicDestinationCache _topicDestinationCache = new TopicDestinationCache();
private final QueueDestinationCache _queueDestinationCache = new QueueDestinationCache();
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java b/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
index f09ef5e01d..51b6c7e478 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
@@ -114,8 +114,8 @@ public class AMQTopic extends AMQDestination implements Topic
AMQShortString queueName = getDurableTopicQueueName(subscriptionName, connection);
// link is never null if dest was created using an address string.
t.getLink().setName(queueName.asString());
- t.getSourceNode().setAutoDelete(false);
- t.getSourceNode().setDurable(true);
+ t.getLink().getSubscriptionQueue().setAutoDelete(false);
+ t.getLink().setDurable(true);
// The legacy fields are also populated just in case.
t.setQueueName(queueName);
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
index 0f8b5717d6..b5e008da5a 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer.java
@@ -31,7 +31,6 @@ import org.apache.qpid.client.message.AMQMessageDelegateFactory;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.CloseConsumerMessage;
import org.apache.qpid.client.message.MessageFactoryRegistry;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.client.filter.JMSSelectorFilter;
import org.apache.qpid.framing.AMQShortString;
@@ -87,8 +86,6 @@ public abstract class BasicMessageConsumer<U> extends Closeable implements Messa
private final AMQSession _session;
- private final AMQProtocolHandler _protocolHandler;
-
/**
* We need to store the "raw" field table so that we can resubscribe in the event of failover being required
*/
@@ -140,9 +137,9 @@ public abstract class BasicMessageConsumer<U> extends Closeable implements Messa
protected BasicMessageConsumer(int channelId, AMQConnection connection, AMQDestination destination,
String messageSelector, boolean noLocal, MessageFactoryRegistry messageFactory,
- AMQSession session, AMQProtocolHandler protocolHandler,
- FieldTable rawSelector, int prefetchHigh, int prefetchLow,
- boolean exclusive, int acknowledgeMode, boolean browseOnly, boolean autoClose) throws JMSException
+ AMQSession session, FieldTable rawSelector,
+ int prefetchHigh, int prefetchLow, boolean exclusive,
+ int acknowledgeMode, boolean browseOnly, boolean autoClose) throws JMSException
{
_channelId = channelId;
_connection = connection;
@@ -150,7 +147,6 @@ public abstract class BasicMessageConsumer<U> extends Closeable implements Messa
_destination = destination;
_messageFactory = messageFactory;
_session = session;
- _protocolHandler = protocolHandler;
_prefetchHigh = prefetchHigh;
_prefetchLow = prefetchLow;
_exclusive = exclusive;
@@ -597,7 +593,6 @@ public abstract class BasicMessageConsumer<U> extends Closeable implements Messa
{
sendCancel();
}
- cleanupQueue();
}
}
catch (AMQException e)
@@ -635,8 +630,6 @@ public abstract class BasicMessageConsumer<U> extends Closeable implements Messa
}
abstract void sendCancel() throws AMQException, FailoverException;
-
- abstract void cleanupQueue() throws AMQException, FailoverException;
/**
* Called when you need to invalidate a consumer. Used for example when failover has occurred and the client has
@@ -1042,10 +1035,4 @@ public abstract class BasicMessageConsumer<U> extends Closeable implements Messa
{
return _messageFactory;
}
-
- protected AMQProtocolHandler getProtocolHandler()
- {
- return _protocolHandler;
- }
-
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java
index 26bb51b821..ef7b8cc217 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_10.java
@@ -28,7 +28,6 @@ import org.apache.qpid.client.message.AMQMessageDelegate_0_10;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.MessageFactoryRegistry;
import org.apache.qpid.client.message.UnprocessedMessage_0_10;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.common.ServerPropertyNames;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.jms.Session;
@@ -82,13 +81,13 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer<UnprocessedM
protected BasicMessageConsumer_0_10(int channelId, AMQConnection connection, AMQDestination destination,
String messageSelector, boolean noLocal, MessageFactoryRegistry messageFactory,
- AMQSession<?,?> session, AMQProtocolHandler protocolHandler,
- FieldTable rawSelector, int prefetchHigh, int prefetchLow,
- boolean exclusive, int acknowledgeMode, boolean browseOnly, boolean autoClose)
+ AMQSession<?,?> session, FieldTable rawSelector,
+ int prefetchHigh, int prefetchLow, boolean exclusive,
+ int acknowledgeMode, boolean browseOnly, boolean autoClose)
throws JMSException
{
- super(channelId, connection, destination, messageSelector, noLocal, messageFactory, session, protocolHandler,
- rawSelector, prefetchHigh, prefetchLow, exclusive, acknowledgeMode, browseOnly, autoClose);
+ super(channelId, connection, destination, messageSelector, noLocal, messageFactory, session, rawSelector,
+ prefetchHigh, prefetchLow, exclusive, acknowledgeMode, browseOnly, autoClose);
_0_10session = (AMQSession_0_10) session;
_serverJmsSelectorSupport = connection.isSupportedServerFeature(ServerPropertyNames.FEATURE_QPID_JMS_SELECTOR);
@@ -96,6 +95,7 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer<UnprocessedM
_capacity = evaluateCapacity(destination);
+ // This is due to the Destination carrying the temporary subscription name which is incorrect.
if (destination.isAddressResolved() && AMQDestination.TOPIC_TYPE == destination.getAddressType())
{
boolean namedQueue = destination.getLink() != null && destination.getLink().getName() != null ;
@@ -164,6 +164,7 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer<UnprocessedM
@Override void sendCancel() throws AMQException
{
_0_10session.getQpidSession().messageCancel(getConsumerTagString());
+ postSubscription();
try
{
_0_10session.getQpidSession().sync();
@@ -500,7 +501,7 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer<UnprocessedM
}
}
- void cleanupQueue() throws AMQException, FailoverException
+ void postSubscription() throws AMQException
{
AMQDestination dest = this.getDestination();
if (dest != null && dest.getDestSyntax() == AMQDestination.DestSyntax.ADDR)
@@ -508,9 +509,11 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer<UnprocessedM
if (dest.getDelete() == AddressOption.ALWAYS ||
dest.getDelete() == AddressOption.RECEIVER )
{
- ((AMQSession_0_10) getSession()).getQpidSession().queueDelete(
- this.getDestination().getQueueName());
+ ((AMQSession_0_10) getSession()).handleNodeDelete(dest);
+ ((AMQSession_0_10) getSession()).deleteSubscriptionQueue(dest);
}
+ // Subscription queue is handled as part of linkDelete method.
+ ((AMQSession_0_10) getSession()).handleLinkDelete(dest);
}
}
@@ -560,4 +563,4 @@ public class BasicMessageConsumer_0_10 extends BasicMessageConsumer<UnprocessedM
return capacity;
}
-}
+} \ No newline at end of file
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java
index b00f9dd98a..f733e6bbca 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageConsumer_0_8.java
@@ -29,7 +29,6 @@ import org.apache.qpid.client.message.AMQMessageDelegateFactory;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.MessageFactoryRegistry;
import org.apache.qpid.client.message.UnprocessedMessage_0_8;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.configuration.ClientProperties;
import org.apache.qpid.framing.AMQFrame;
@@ -52,12 +51,12 @@ public class BasicMessageConsumer_0_8 extends BasicMessageConsumer<UnprocessedMe
protected BasicMessageConsumer_0_8(int channelId, AMQConnection connection, AMQDestination destination,
String messageSelector, boolean noLocal, MessageFactoryRegistry messageFactory, AMQSession_0_8 session,
- AMQProtocolHandler protocolHandler, FieldTable rawSelector, int prefetchHigh, int prefetchLow,
- boolean exclusive, int acknowledgeMode, boolean browseOnly, boolean autoClose) throws JMSException
+ FieldTable rawSelector, int prefetchHigh, int prefetchLow, boolean exclusive,
+ int acknowledgeMode, boolean browseOnly, boolean autoClose) throws JMSException
{
super(channelId, connection, destination,messageSelector,noLocal,messageFactory,session,
- protocolHandler, rawSelector, prefetchHigh, prefetchLow, exclusive,
- acknowledgeMode, browseOnly, autoClose);
+ rawSelector, prefetchHigh, prefetchLow, exclusive, acknowledgeMode,
+ browseOnly, autoClose);
final FieldTable consumerArguments = getArguments();
if (isAutoClose())
{
@@ -93,13 +92,19 @@ public class BasicMessageConsumer_0_8 extends BasicMessageConsumer<UnprocessedMe
}
}
+ @Override
+ public AMQSession_0_8 getSession()
+ {
+ return (AMQSession_0_8) super.getSession();
+ }
+
void sendCancel() throws AMQException, FailoverException
{
BasicCancelBody body = getSession().getMethodRegistry().createBasicCancelBody(new AMQShortString(String.valueOf(getConsumerTag())), false);
final AMQFrame cancelFrame = body.generateFrame(getChannelId());
- getProtocolHandler().syncWrite(cancelFrame, BasicCancelOkBody.class);
+ getConnection().getProtocolHandler().syncWrite(cancelFrame, BasicCancelOkBody.class);
if (_logger.isDebugEnabled())
{
@@ -122,11 +127,6 @@ public class BasicMessageConsumer_0_8 extends BasicMessageConsumer<UnprocessedMe
return receive();
}
- void cleanupQueue() throws AMQException, FailoverException
- {
-
- }
-
public RejectBehaviour getRejectBehaviour()
{
return _rejectBehaviour;
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
index 9b3b2ce0e9..98fa6de675 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.client;
-import java.io.UnsupportedEncodingException;
import java.util.UUID;
import javax.jms.BytesMessage;
import javax.jms.DeliveryMode;
@@ -36,15 +35,15 @@ import javax.jms.Topic;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.MessageConverter;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.transport.TransportException;
import org.apache.qpid.util.UUIDGen;
import org.apache.qpid.util.UUIDs;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public abstract class BasicMessageProducer extends Closeable implements org.apache.qpid.jms.MessageProducer
{
+
+
enum PublishMode { ASYNC_PUBLISH_ALL, SYNC_PUBLISH_PERSISTENT, SYNC_PUBLISH_ALL };
private final Logger _logger ;
@@ -71,18 +70,6 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
private AMQDestination _destination;
/**
- * Default encoding used for messages produced by this producer.
- */
- private String _encoding;
-
- /**
- * Default encoding used for message produced by this producer.
- */
- private String _mimeType;
-
- private AMQProtocolHandler _protocolHandler;
-
- /**
* True if this producer was created from a transacted session
*/
private boolean _transacted;
@@ -135,14 +122,12 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
private PublishMode publishMode = PublishMode.ASYNC_PUBLISH_ALL;
protected BasicMessageProducer(Logger logger,AMQConnection connection, AMQDestination destination, boolean transacted, int channelId,
- AMQSession session, AMQProtocolHandler protocolHandler, long producerId,
- Boolean immediate, Boolean mandatory) throws AMQException
+ AMQSession session, long producerId, Boolean immediate, Boolean mandatory) throws AMQException
{
_logger = logger;
_connection = connection;
_destination = destination;
_transacted = transacted;
- _protocolHandler = protocolHandler;
_channelId = channelId;
_session = session;
_producerId = producerId;
@@ -163,6 +148,11 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
setPublishMode();
}
+ protected AMQConnection getConnection()
+ {
+ return _connection;
+ }
+
void setPublishMode()
{
// Publish mode could be configured at destination level as well.
@@ -303,7 +293,6 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
checkPreConditions();
checkInitialDestination();
-
synchronized (_connection.getFailoverMutex())
{
sendImpl(_destination, message, _deliveryMode, _messagePriority, _timeToLive, _mandatory, _immediate);
@@ -467,7 +456,7 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
JMSException ex = new JMSException("Error validating destination");
ex.initCause(e);
ex.setLinkedException(e);
-
+
throw ex;
}
amqDestination.setExchangeExistsChecked(true);
@@ -558,19 +547,7 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
}
}
- public void setMimeType(String mimeType) throws JMSException
- {
- checkNotClosed();
- _mimeType = mimeType;
- }
-
- public void setEncoding(String encoding) throws JMSException, UnsupportedEncodingException
- {
- checkNotClosed();
- _encoding = encoding;
- }
-
- private void checkPreConditions() throws javax.jms.IllegalStateException, JMSException
+ private void checkPreConditions() throws JMSException
{
checkNotClosed();
@@ -584,15 +561,16 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
}
}
- private void checkInitialDestination()
+ private void checkInitialDestination() throws JMSException
{
if (_destination == null)
{
throw new UnsupportedOperationException("Destination is null");
}
+ checkValidQueue();
}
- private void checkDestination(Destination suppliedDestination) throws InvalidDestinationException
+ private void checkDestination(Destination suppliedDestination) throws JMSException
{
if ((_destination != null) && (suppliedDestination != null))
{
@@ -600,6 +578,11 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
"This message producer was created with a Destination, therefore you cannot use an unidentified Destination");
}
+ if(suppliedDestination instanceof AMQQueue)
+ {
+ AMQQueue destination = (AMQQueue) suppliedDestination;
+ checkValidQueue(destination);
+ }
if (suppliedDestination == null)
{
throw new InvalidDestinationException("Supplied Destination was invalid");
@@ -607,6 +590,43 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
}
+ private void checkValidQueue() throws JMSException
+ {
+ if(_destination instanceof AMQQueue)
+ {
+ checkValidQueue((AMQQueue) _destination);
+ }
+ }
+
+ private void checkValidQueue(AMQQueue destination) throws JMSException
+ {
+ if (!destination.isCheckedForQueueBinding() && validateQueueOnSend())
+ {
+ if (getSession().isStrictAMQP())
+ {
+ getLogger().warn("AMQP does not support destination validation before publish");
+ destination.setCheckedForQueueBinding(true);
+ }
+ else
+ {
+ if (isBound(destination))
+ {
+ destination.setCheckedForQueueBinding(true);
+ }
+ else
+ {
+ throw new InvalidDestinationException("Queue: " + destination.getQueueName()
+ + " is not a valid destination (no binding on server)");
+ }
+ }
+ }
+ }
+
+ private boolean validateQueueOnSend()
+ {
+ return _connection.validateQueueOnSend();
+ }
+
/**
* The session used to create this producer
*/
@@ -645,16 +665,6 @@ public abstract class BasicMessageProducer extends Closeable implements org.apac
_destination = destination;
}
- protected AMQProtocolHandler getProtocolHandler()
- {
- return _protocolHandler;
- }
-
- protected void setProtocolHandler(AMQProtocolHandler protocolHandler)
- {
- _protocolHandler = protocolHandler;
- }
-
protected int getChannelId()
{
return _channelId;
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
index a3a1e9c28b..f717ca4655 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
@@ -27,7 +27,6 @@ import org.apache.qpid.client.message.AMQMessageDelegate_0_10;
import org.apache.qpid.client.message.AbstractJMSMessage;
import org.apache.qpid.client.message.QpidMessageProperties;
import org.apache.qpid.client.messaging.address.Link.Reliability;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
import org.apache.qpid.transport.DeliveryProperties;
import org.apache.qpid.transport.Header;
import org.apache.qpid.transport.MessageAcceptMode;
@@ -60,10 +59,9 @@ public class BasicMessageProducer_0_10 extends BasicMessageProducer
private byte[] userIDBytes;
BasicMessageProducer_0_10(AMQConnection connection, AMQDestination destination, boolean transacted, int channelId,
- AMQSession session, AMQProtocolHandler protocolHandler, long producerId,
- Boolean immediate, Boolean mandatory) throws AMQException
+ AMQSession session, long producerId, Boolean immediate, Boolean mandatory) throws AMQException
{
- super(_logger, connection, destination, transacted, channelId, session, protocolHandler, producerId, immediate, mandatory);
+ super(_logger, connection, destination, transacted, channelId, session, producerId, immediate, mandatory);
userIDBytes = Strings.toUTF8(getUserID());
}
@@ -79,14 +77,18 @@ public class BasicMessageProducer_0_10 extends BasicMessageProducer
(name,
destination.getExchangeClass().toString(),
null, null,
- name.startsWith("amq.") ? Option.PASSIVE : Option.NONE);
+ name.startsWith("amq.") ? Option.PASSIVE : Option.NONE,
+ destination.isExchangeDurable() ? Option.DURABLE : Option.NONE,
+ destination.isExchangeAutoDelete() ? Option.AUTO_DELETE : Option.NONE);
}
}
else
{
try
{
- getSession().handleAddressBasedDestination(destination,false,false,false);
+ getSession().resolveAddress(destination,false,false);
+ ((AMQSession_0_10)getSession()).handleLinkCreation(destination);
+ ((AMQSession_0_10)getSession()).sync();
}
catch(Exception e)
{
@@ -251,25 +253,35 @@ public class BasicMessageProducer_0_10 extends BasicMessageProducer
return getSession().isQueueBound(destination);
}
+ // We should have a close and closed method to distinguish between normal close
+ // and a close due to session or connection error.
@Override
public void close() throws JMSException
{
super.close();
AMQDestination dest = getAMQDestination();
- if (dest != null && dest.getDestSyntax() == AMQDestination.DestSyntax.ADDR)
+ AMQSession_0_10 ssn = (AMQSession_0_10) getSession();
+ if (!ssn.isClosed() && dest != null && dest.getDestSyntax() == AMQDestination.DestSyntax.ADDR)
{
- if (dest.getDelete() == AddressOption.ALWAYS ||
- dest.getDelete() == AddressOption.SENDER )
+ try
{
- try
- {
- ((AMQSession_0_10) getSession()).getQpidSession().queueDelete(
- getAMQDestination().getQueueName());
- }
- catch(TransportException e)
+ if (dest.getDelete() == AddressOption.ALWAYS ||
+ dest.getDelete() == AddressOption.SENDER )
{
- throw getSession().toJMSException("Exception while closing producer:" + e.getMessage(), e);
+ ssn.handleNodeDelete(dest);
}
+ ssn.handleLinkDelete(dest);
+ }
+ catch(TransportException e)
+ {
+ throw getSession().toJMSException("Exception while closing producer:" + e.getMessage(), e);
+ }
+ catch (AMQException e)
+ {
+ JMSException ex = new JMSException("Exception while closing producer:" + e.getMessage());
+ ex.setLinkedException(e);
+ ex.initCause(e);
+ throw ex;
}
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java
index 21ff6c877a..bb270b0878 100644
--- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java
+++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_8.java
@@ -50,29 +50,28 @@ public class BasicMessageProducer_0_8 extends BasicMessageProducer
BasicMessageProducer_0_8(AMQConnection connection, AMQDestination destination, boolean transacted, int channelId,
AMQSession session, AMQProtocolHandler protocolHandler, long producerId, Boolean immediate, Boolean mandatory) throws AMQException
{
- super(_logger,connection, destination,transacted,channelId,session, protocolHandler, producerId, immediate, mandatory);
+ super(_logger,connection, destination,transacted,channelId,session, producerId, immediate, mandatory);
}
void declareDestination(AMQDestination destination)
{
-
- final MethodRegistry methodRegistry = getSession().getMethodRegistry();
- ExchangeDeclareBody body =
+ if(getSession().isDeclareExchanges())
+ {
+ final MethodRegistry methodRegistry = getSession().getMethodRegistry();
+ ExchangeDeclareBody body =
methodRegistry.createExchangeDeclareBody(getSession().getTicket(),
destination.getExchangeName(),
destination.getExchangeClass(),
destination.getExchangeName().toString().startsWith("amq."),
- false,
- false,
- false,
+ destination.isExchangeDurable(),
+ destination.isExchangeAutoDelete(),
+ destination.isExchangeInternal(),
true,
null);
- // Declare the exchange
- // Note that the durable and internal arguments are ignored since passive is set to false
-
- AMQFrame declare = body.generateFrame(getChannelId());
+ AMQFrame declare = body.generateFrame(getChannelId());
- getProtocolHandler().writeFrame(declare);
+ getConnection().getProtocolHandler().writeFrame(declare);
+ }
}
void sendMessage(AMQDestination destination, Message origMessage, AbstractJMSMessage message,
@@ -172,7 +171,7 @@ public class BasicMessageProducer_0_8 extends BasicMessageProducer
throw jmse;
}
- getProtocolHandler().writeFrame(compositeFrame);
+ getConnection().getProtocolHandler().writeFrame(compositeFrame);
}
/**
@@ -234,4 +233,9 @@ public class BasicMessageProducer_0_8 extends BasicMessageProducer
return frameCount;
}
+ @Override
+ public AMQSession_0_8 getSession()
+ {
+ return (AMQSession_0_8) super.getSession();
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/HeartbeatListener.java b/java/client/src/main/java/org/apache/qpid/client/HeartbeatListener.java
new file mode 100644
index 0000000000..32a7cb0b73
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/HeartbeatListener.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+public interface HeartbeatListener
+{
+ void heartbeatReceived();
+
+ void heartbeatSent();
+
+ static final HeartbeatListener DEFAULT = new HeartbeatListener()
+ {
+ public void heartbeatReceived()
+ {
+ }
+
+ public void heartbeatSent()
+ {
+ }
+ };
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/XASessionImpl.java b/java/client/src/main/java/org/apache/qpid/client/XASessionImpl.java
index 05bd121bbd..e01ec8578d 100644
--- a/java/client/src/main/java/org/apache/qpid/client/XASessionImpl.java
+++ b/java/client/src/main/java/org/apache/qpid/client/XASessionImpl.java
@@ -88,7 +88,7 @@ public class XASessionImpl extends AMQSession_0_10 implements XASession, XATopic
*/
public void createSession()
{
- _qpidDtxSession = getQpidConnection().createSession(0);
+ _qpidDtxSession = getQpidConnection().createSession(0,true);
_qpidDtxSession.setSessionListener(this);
_qpidDtxSession.dtxSelect();
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java
index 2cf7b089eb..f038fc6e4f 100644
--- a/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionCloseMethodHandler.java
@@ -20,6 +20,8 @@
*/
package org.apache.qpid.client.handler;
+import java.nio.ByteBuffer;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,6 +35,8 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ConnectionCloseBody;
import org.apache.qpid.framing.ConnectionCloseOkBody;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.transport.Sender;
+import org.apache.qpid.transport.TransportException;
public class ConnectionCloseMethodHandler implements StateAwareMethodListener<ConnectionCloseBody>
{
@@ -91,18 +95,24 @@ public class ConnectionCloseMethodHandler implements StateAwareMethodListener<Co
}
finally
{
+ Sender<ByteBuffer> sender = session.getSender();
if (error != null)
{
session.notifyError(error);
- }
-
- // Close the protocol Session, including any open TCP connections
- session.closeProtocolSession();
+ }
- // Closing the session should not introduce a race condition as this thread will continue to propgate any
- // exception in to the exceptionCaught method of the SessionHandler.
- // Any sessionClosed event should occur after this.
+ // Close the open TCP connection
+ try
+ {
+ sender.close();
+ }
+ catch(TransportException e)
+ {
+ //Ignore, they are already logged by the Sender and this
+ //is a connection-close being processed by the IoReceiver
+ //which will as it closes initiate failover if necessary.
+ }
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java
index a0c3914127..94b835dd1a 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java
@@ -91,6 +91,7 @@ public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate
private MessageProperties _messageProps;
private DeliveryProperties _deliveryProps;
+ private String _messageID;
protected AMQMessageDelegate_0_10()
{
@@ -171,8 +172,12 @@ public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate
public String getJMSMessageID() throws JMSException
{
- UUID id = _messageProps.getMessageId();
- return id == null ? null : "ID:" + id;
+ if (_messageID == null && _messageProps.getMessageId() != null)
+ {
+ UUID id = _messageProps.getMessageId();
+ _messageID = "ID:" + id;
+ }
+ return _messageID;
}
public void setJMSMessageID(String messageId) throws JMSException
@@ -185,14 +190,7 @@ public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate
{
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");
- }
+ _messageID = messageId;
}
else
{
@@ -201,6 +199,7 @@ public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate
}
}
+ /* Used by the internal implementation */
public void setJMSMessageID(UUID messageId) throws JMSException
{
if(messageId == null)
@@ -344,7 +343,7 @@ public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate
int type = ((AMQSession_0_10)getAMQSession()).resolveAddressType(amqd);
if (type == AMQDestination.QUEUE_TYPE)
{
- ((AMQSession_0_10)getAMQSession()).setLegacyFiledsForQueueType(amqd);
+ ((AMQSession_0_10)getAMQSession()).setLegacyFieldsForQueueType(amqd);
}
else
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedListMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedListMessage.java
new file mode 100644
index 0000000000..1d2cb43322
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedListMessage.java
@@ -0,0 +1,935 @@
+/*
+ * 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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.qpid.AMQException;
+
+import org.apache.qpid.transport.codec.BBDecoder;
+import org.apache.qpid.transport.codec.BBEncoder;
+
+import javax.jms.JMSException;
+import javax.jms.MessageFormatException;
+import javax.jms.MessageEOFException;
+import java.lang.NumberFormatException;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+public class AMQPEncodedListMessage extends JMSStreamMessage implements
+ org.apache.qpid.jms.ListMessage, javax.jms.MapMessage
+{
+ private static final Logger _logger = LoggerFactory
+ .getLogger(AMQPEncodedListMessage.class);
+
+ public static final String MIME_TYPE = "amqp/list";
+
+ private List<Object> _list = new ArrayList<Object>();
+
+ public AMQPEncodedListMessage(AMQMessageDelegateFactory delegateFactory) throws JMSException
+ {
+ super(delegateFactory);
+ currentIndex = 0;
+ }
+
+ AMQPEncodedListMessage(AMQMessageDelegate delegate, ByteBuffer data)
+ throws AMQException
+ {
+ super(delegate, data);
+ if (data != null)
+ {
+ try
+ {
+ populateListFromData(data);
+ }
+ catch (JMSException je)
+ {
+ throw new AMQException(null,
+ "Error populating ListMessage from ByteBuffer", je);
+ }
+ }
+ currentIndex = 0;
+ }
+
+ public String toBodyString() throws JMSException
+ {
+ return _list == null ? "" : _list.toString();
+ }
+
+ protected String getMimeType()
+ {
+ return MIME_TYPE;
+ }
+
+ /* ListMessage Implementation. */
+ public boolean add(Object a) throws JMSException
+ {
+ checkWritable();
+ checkAllowedValue(a);
+ try
+ {
+ return _list.add(a);
+ }
+ catch (Exception e)
+ {
+ MessageFormatException ex = new MessageFormatException("Error adding to ListMessage");
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+
+ }
+ }
+
+ public void add(int index, Object element) throws JMSException
+ {
+ checkWritable();
+ checkAllowedValue(element);
+ try
+ {
+ _list.add(index, element);
+ }
+ catch (Exception e)
+ {
+ MessageFormatException ex = new MessageFormatException("Error adding to ListMessage at "
+ + index);
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+ }
+
+ public boolean contains(Object o) throws JMSException
+ {
+ try
+ {
+ return _list.contains(o);
+ }
+ catch (Exception e)
+ {
+ JMSException ex = new JMSException("Error when looking up object");
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+ }
+
+ public Object get(int index) throws JMSException
+ {
+ try
+ {
+ return _list.get(index);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ MessageFormatException ex = new MessageFormatException(
+ "Error getting ListMessage element at " + index);
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+ }
+
+ public int indexOf(Object o)
+ {
+ return _list.indexOf(o);
+ }
+
+ public Iterator iterator()
+ {
+ return _list.iterator();
+ }
+
+ public Object remove(int index) throws JMSException
+ {
+ checkWritable();
+ try
+ {
+ return _list.remove(index);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ MessageFormatException ex = new MessageFormatException(
+ "Error removing ListMessage element at " + index);
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+ }
+
+ public boolean remove(Object o) throws JMSException
+ {
+ checkWritable();
+ return _list.remove(o);
+ }
+
+ public Object set(int index, Object element) throws JMSException
+ {
+ checkWritable();
+ checkAllowedValue(element);
+ try
+ {
+ return _list.set(index, element);
+ }
+ catch (Exception e)
+ {
+ MessageFormatException ex = new MessageFormatException(
+ "Error setting ListMessage element at " + index);
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+ }
+
+ public int size()
+ {
+ return _list.size();
+ }
+
+ public Object[] toArray()
+ {
+ return _list.toArray();
+ }
+
+ /* MapMessage Implementation */
+ private boolean isValidIndex(int index)
+ {
+ if (index >= 0 && index < size())
+ return true;
+
+ return false;
+ }
+
+ private int getValidIndex(String indexStr) throws JMSException
+ {
+ if ((indexStr == null) || indexStr.equals(""))
+ {
+ throw new IllegalArgumentException(
+ "Property name cannot be null, or the empty String.");
+ }
+
+ int index = 0;
+ try
+ {
+ index = Integer.parseInt(indexStr);
+ }
+ catch (NumberFormatException e)
+ {
+ JMSException ex = new JMSException("Invalid index string");
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+ if (isValidIndex(index))
+ return index;
+
+ throw new MessageFormatException("Property " + indexStr
+ + " should be a valid index into the list of size " + size());
+ }
+
+ private void setGenericForMap(String propName, Object o)
+ throws JMSException
+ {
+ checkWritable();
+ int index = 0;
+ try
+ {
+ index = Integer.parseInt(propName);
+ }
+ catch (NumberFormatException e)
+ {
+ JMSException ex = new JMSException("The property name should be a valid index");
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+
+ if (isValidIndex(index))
+ remove(index);
+ add(index, o);
+ }
+
+ public boolean getBoolean(String propName) throws JMSException
+ {
+ return getBooleanImpl(getValidIndex(propName));
+ }
+
+ public byte getByte(String propName) throws JMSException
+ {
+ return getByteImpl(getValidIndex(propName));
+ }
+
+ public short getShort(String propName) throws JMSException
+ {
+ return getShortImpl(getValidIndex(propName));
+ }
+
+ public int getInt(String propName) throws JMSException
+ {
+ return getIntImpl(getValidIndex(propName));
+ }
+
+ public long getLong(String propName) throws JMSException
+ {
+ return getLongImpl(getValidIndex(propName));
+ }
+
+ public char getChar(String propName) throws JMSException
+ {
+ return getCharImpl(getValidIndex(propName));
+
+ }
+
+ public float getFloat(String propName) throws JMSException
+ {
+ return getFloatImpl(getValidIndex(propName));
+ }
+
+ public double getDouble(String propName) throws JMSException
+ {
+ return getDoubleImpl(getValidIndex(propName));
+ }
+
+ public String getString(String propName) throws JMSException
+ {
+ return getStringImpl(getValidIndex(propName));
+ }
+
+ public byte[] getBytes(String propName) throws JMSException
+ {
+ return getBytesImpl(getValidIndex(propName));
+ }
+
+ public Object getObject(String propName) throws JMSException
+ {
+ return get(getValidIndex(propName));
+ }
+
+ public Enumeration getMapNames() throws JMSException
+ {
+ List<String> names = new ArrayList<String>();
+ int i = 0;
+
+ while (i < size())
+ names.add(Integer.toString(i++));
+
+ return Collections.enumeration(names);
+ }
+
+ public void setBoolean(String propName, boolean b) throws JMSException
+ {
+ setGenericForMap(propName, b);
+ }
+
+ public void setByte(String propName, byte b) throws JMSException
+ {
+ setGenericForMap(propName, b);
+ }
+
+ public void setShort(String propName, short i) throws JMSException
+ {
+ setGenericForMap(propName, i);
+ }
+
+ public void setChar(String propName, char c) throws JMSException
+ {
+ setGenericForMap(propName, c);
+ }
+
+ public void setInt(String propName, int i) throws JMSException
+ {
+ setGenericForMap(propName, i);
+ }
+
+ public void setLong(String propName, long l) throws JMSException
+ {
+ setGenericForMap(propName, l);
+ }
+
+ public void setFloat(String propName, float v) throws JMSException
+ {
+ setGenericForMap(propName, v);
+ }
+
+ public void setDouble(String propName, double v) throws JMSException
+ {
+ setGenericForMap(propName, v);
+ }
+
+ public void setString(String propName, String string1) throws JMSException
+ {
+ setGenericForMap(propName, string1);
+ }
+
+ public void setBytes(String propName, byte[] bytes) throws JMSException
+ {
+ setGenericForMap(propName, bytes);
+ }
+
+ public void setBytes(String propName, byte[] bytes, int offset, int length)
+ throws JMSException
+ {
+ if ((offset == 0) && (length == bytes.length))
+ {
+ setBytes(propName, bytes);
+ }
+ else
+ {
+ byte[] newBytes = new byte[length];
+ System.arraycopy(bytes, offset, newBytes, 0, length);
+ setBytes(propName, newBytes);
+ }
+ }
+
+ public void setObject(String propName, Object value) throws JMSException
+ {
+ checkAllowedValue(value);
+ setGenericForMap(propName, value);
+ }
+
+ public boolean itemExists(String propName) throws JMSException
+ {
+ return isValidIndex(Integer.parseInt(propName));
+ }
+
+ // StreamMessage methods
+
+ private int currentIndex;
+
+ private static final String MESSAGE_EOF_EXCEPTION = "End of Stream (ListMessage) at index: ";
+
+ private void setGenericForStream(Object o) throws JMSException
+ {
+ checkWritable();
+ add(o);
+ currentIndex++;
+ }
+
+ @Override
+ public boolean readBoolean() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getBooleanImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public byte readByte() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getByteImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public int readBytes(byte[] value) throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ {
+ ByteBuffer res = ByteBuffer.wrap(getBytesImpl(currentIndex++));
+ res.get(value);
+ return value.length;
+ }
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public char readChar() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getCharImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public double readDouble() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getDoubleImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public float readFloat() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getFloatImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public int readInt() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getIntImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public long readLong() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getLongImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public Object readObject() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return get(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public short readShort() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getShortImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public String readString() throws JMSException
+ {
+ checkReadable();
+ if (isValidIndex(currentIndex))
+ return getStringImpl(currentIndex++);
+
+ throw new MessageEOFException(MESSAGE_EOF_EXCEPTION + currentIndex);
+ }
+
+ @Override
+ public void writeBoolean(boolean value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeByte(byte value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeBytes(byte[] value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeBytes(byte[] value, int offset, int length)
+ throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeChar(char value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeDouble(double value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeFloat(float value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeInt(int value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeLong(long value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeObject(Object value) throws JMSException
+ {
+ checkAllowedValue(value);
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeShort(short value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ @Override
+ public void writeString(String value) throws JMSException
+ {
+ setGenericForStream(value);
+ }
+
+ // Common methods
+
+ private void checkAllowedValue(Object value) throws MessageFormatException
+ {
+ if (((value instanceof Boolean) || (value instanceof Byte)
+ || (value instanceof Short) || (value instanceof Integer)
+ || (value instanceof Long) || (value instanceof Character)
+ || (value instanceof Float) || (value instanceof Double)
+ || (value instanceof String) || (value instanceof byte[])
+ || (value instanceof List) || (value instanceof Map)
+ || (value instanceof UUID) || (value == null)) == false)
+ {
+ throw new MessageFormatException("Invalid value " + value
+ + "of type " + value.getClass().getName() + ".");
+ }
+ }
+
+ @Override
+ public void reset()
+ {
+ currentIndex = 0;
+ setReadable(true);
+ }
+
+ @Override
+ public void clearBody() throws JMSException
+ {
+ super.clearBody();
+ _list.clear();
+ currentIndex = 0;
+ setReadable(false);
+ }
+
+ private boolean getBooleanImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if (value instanceof Boolean)
+ {
+ return ((Boolean) value).booleanValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ try
+ {
+ return Boolean.valueOf((String) value);
+ }
+ catch (NumberFormatException e)
+ {
+ // FALLTHROUGH to exception
+ }
+ }
+
+ throw new MessageFormatException("Property at " + index + " of type "
+ + value.getClass().getName()
+ + " cannot be converted to boolean.");
+ }
+
+ private byte getByteImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if (value instanceof Byte)
+ {
+ return ((Byte) value).byteValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ try
+ {
+ return Byte.valueOf((String) value).byteValue();
+ } catch (NumberFormatException e)
+ {
+ // FALLTHROUGH to exception
+ }
+ }
+
+ throw new MessageFormatException("Property at " + index + " of type "
+ + value.getClass().getName() + " cannot be converted to byte.");
+ }
+
+ private short getShortImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if (value instanceof Short)
+ {
+ return ((Short) value).shortValue();
+ }
+ else if (value instanceof Byte)
+ {
+ return ((Byte) value).shortValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ try
+ {
+ return Short.valueOf((String) value).shortValue();
+ } catch (NumberFormatException e)
+ {
+ // FALLTHROUGH to exception
+ }
+ }
+
+ throw new MessageFormatException("Property at " + index + " of type "
+ + value.getClass().getName() + " cannot be converted to short.");
+ }
+
+ private int getIntImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if (value instanceof Integer)
+ {
+ return ((Integer) value).intValue();
+ }
+
+ if (value instanceof Short)
+ {
+ return ((Short) value).intValue();
+ }
+
+ if (value instanceof Byte)
+ {
+ return ((Byte) value).intValue();
+ }
+
+ if ((value instanceof String) || (value == null))
+ {
+ try
+ {
+ return Integer.valueOf((String) value).intValue();
+ }
+ catch (NumberFormatException e)
+ {
+ // FALLTHROUGH to exception
+ }
+ }
+
+ throw new MessageFormatException("Property at " + index + " of type "
+ + value.getClass().getName() + " cannot be converted to int.");
+ }
+
+ private long getLongImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if (value instanceof Long)
+ {
+ return ((Long) value).longValue();
+ } else if (value instanceof Integer)
+ {
+ return ((Integer) value).longValue();
+ }
+
+ if (value instanceof Short)
+ {
+ return ((Short) value).longValue();
+ }
+
+ if (value instanceof Byte)
+ {
+ return ((Byte) value).longValue();
+ } else if ((value instanceof String) || (value == null))
+ {
+ try
+ {
+ return Long.valueOf((String) value).longValue();
+ } catch (NumberFormatException e)
+ {
+ // FALLTHROUGH to exception
+ }
+ }
+
+ throw new MessageFormatException("Property at " + index + " of type "
+ + value.getClass().getName() + " cannot be converted to long.");
+ }
+
+ private char getCharImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if (value instanceof Character)
+ {
+ return ((Character) value).charValue();
+ } else if (value == null)
+ {
+ throw new NullPointerException("Property at " + index
+ + " has null value and therefore cannot "
+ + "be converted to char.");
+ } else
+ {
+ throw new MessageFormatException("Property at " + index
+ + " of type " + value.getClass().getName()
+ + " cannot be converted to a char.");
+ }
+ }
+
+ private float getFloatImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if (value instanceof Float)
+ {
+ return ((Float) value).floatValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ try
+ {
+ return Float.valueOf((String) value).floatValue();
+ }
+ catch (NumberFormatException e)
+ {
+ // FALLTHROUGH to exception
+ }
+ }
+
+ throw new MessageFormatException("Property at " + index + " of type "
+ + value.getClass().getName() + " cannot be converted to float.");
+ }
+
+ private double getDoubleImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if (value instanceof Double)
+ {
+ return ((Double) value).doubleValue();
+ }
+ else if (value instanceof Float)
+ {
+ return ((Float) value).doubleValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ try
+ {
+ return Double.valueOf((String) value).doubleValue();
+ }
+ catch (NumberFormatException e)
+ {
+ // FALLTHROUGH to exception
+ }
+ }
+
+ throw new MessageFormatException("Property at " + index + " of type "
+ + value.getClass().getName()
+ + " cannot be converted to double.");
+ }
+
+ private String getStringImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if ((value instanceof String) || (value == null))
+ {
+ return (String) value;
+ } else if (value instanceof byte[])
+ {
+ throw new MessageFormatException("Property at " + index
+ + " of type byte[] " + "cannot be converted to String.");
+ } else
+ {
+ return value.toString();
+ }
+ }
+
+ private byte[] getBytesImpl(int index) throws JMSException
+ {
+ Object value = get(index);
+
+ if ((value instanceof byte[]) || (value == null))
+ {
+ return (byte[]) value;
+ }
+ else
+ {
+ throw new MessageFormatException("Property at " + index
+ + " of type " + value.getClass().getName()
+ + " cannot be converted to byte[].");
+ }
+ }
+
+ protected void populateListFromData(ByteBuffer data) throws JMSException
+ {
+ if (data != null)
+ {
+ data.rewind();
+ BBDecoder decoder = new BBDecoder();
+ decoder.init(data);
+ _list = decoder.readList();
+ }
+ else
+ {
+ _list.clear();
+ }
+ }
+
+ public ByteBuffer getData() throws JMSException
+ {
+ BBEncoder encoder = new BBEncoder(1024);
+ encoder.writeList(_list);
+ return encoder.segment();
+ }
+
+ public void setList(List<Object> l)
+ {
+ _list = l;
+ }
+
+ public List<Object> asList()
+ {
+ return _list;
+ }
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedListMessageFactory.java b/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedListMessageFactory.java
new file mode 100644
index 0000000000..b503dccb91
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/client/message/AMQPEncodedListMessageFactory.java
@@ -0,0 +1,44 @@
+package org.apache.qpid.client.message;
+/*
+ *
+ * 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.
+ *
+ */
+
+
+import org.apache.qpid.AMQException;
+
+import javax.jms.JMSException;
+import java.nio.ByteBuffer;
+
+public class AMQPEncodedListMessageFactory extends AbstractJMSMessageFactory
+{
+ @Override
+ protected AbstractJMSMessage createMessage(AMQMessageDelegate delegate,
+ ByteBuffer data) throws AMQException
+ {
+ return new AMQPEncodedListMessage(delegate,data);
+ }
+
+
+ public AbstractJMSMessage createMessage(
+ AMQMessageDelegateFactory delegateFactory) throws JMSException
+ {
+ return new AMQPEncodedListMessage(delegateFactory);
+ }
+}
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java
index 509fc9f7f1..c2a919c1c5 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java
@@ -196,7 +196,14 @@ public class JMSObjectMessage extends AbstractJMSMessage implements ObjectMessag
if (data != null && data.hasRemaining())
{
ClassLoadingAwareObjectInputStream in = new ClassLoadingAwareObjectInputStream(new ByteBufferInputStream(data));
- result = (Serializable) in.readObject();
+ try
+ {
+ result = (Serializable) in.readObject();
+ }
+ finally
+ {
+ in.close();
+ }
}
return result;
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/JMSStreamMessage.java b/java/client/src/main/java/org/apache/qpid/client/message/JMSStreamMessage.java
index b958d89515..b1af262580 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/JMSStreamMessage.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/JMSStreamMessage.java
@@ -44,7 +44,12 @@ public class JMSStreamMessage extends AbstractBytesTypedMessage implements Strea
}
+ JMSStreamMessage(AMQMessageDelegateFactory delegateFactory, ByteBuffer data) throws AMQException
+ {
+ super(delegateFactory, data!=null);
+ _typedBytesContentWriter = new TypedBytesContentWriter();
+ }
JMSStreamMessage(AMQMessageDelegate delegate, ByteBuffer data) throws AMQException
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java b/java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java
index fa39b4c93c..4154003b23 100644
--- a/java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java
+++ b/java/client/src/main/java/org/apache/qpid/client/message/MessageFactoryRegistry.java
@@ -66,6 +66,7 @@ public class MessageFactoryRegistry
mf.registerFactory(JMSObjectMessage.MIME_TYPE, new JMSObjectMessageFactory());
mf.registerFactory(JMSStreamMessage.MIME_TYPE, new JMSStreamMessageFactory());
mf.registerFactory(AMQPEncodedMapMessage.MIME_TYPE, new AMQPEncodedMapMessageFactory());
+ mf.registerFactory(AMQPEncodedListMessage.MIME_TYPE, new AMQPEncodedListMessageFactory());
mf.registerFactory(null, mf._default);
return mf;
diff --git a/java/client/src/main/java/org/apache/qpid/client/messaging/address/AddressHelper.java b/java/client/src/main/java/org/apache/qpid/client/messaging/address/AddressHelper.java
index 318fe32d36..72fc74e19c 100644
--- a/java/client/src/main/java/org/apache/qpid/client/messaging/address/AddressHelper.java
+++ b/java/client/src/main/java/org/apache/qpid/client/messaging/address/AddressHelper.java
@@ -20,21 +20,20 @@
*/
package org.apache.qpid.client.messaging.address;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQDestination.Binding;
import org.apache.qpid.client.messaging.address.Link.Reliability;
import org.apache.qpid.client.messaging.address.Link.Subscription;
-import org.apache.qpid.client.messaging.address.Node.ExchangeNode;
-import org.apache.qpid.client.messaging.address.Node.QueueNode;
+import org.apache.qpid.client.messaging.address.Link.SubscriptionQueue;
import org.apache.qpid.configuration.Accessor;
import org.apache.qpid.configuration.Accessor.MapAccessor;
import org.apache.qpid.messaging.Address;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
/**
* Utility class for extracting information from the address class
*/
@@ -68,58 +67,56 @@ public class AddressHelper
public static final String ARGUMENTS = "arguments";
public static final String RELIABILITY = "reliability";
- private Address address;
- private Accessor addressProps;
- private Accessor nodeProps;
- private Accessor linkProps;
+ private Address _address;
+ private Accessor _addressPropAccess;
+ private Accessor _nodePropAccess;
+ private Accessor _linkPropAccess;
+ private Map _addressPropMap;
+ private Map _nodePropMap;
+ private Map _linkPropMap;
public AddressHelper(Address address)
{
- this.address = address;
- addressProps = new MapAccessor(address.getOptions());
- Map node_props = address.getOptions() == null
+ this._address = address;
+ this._addressPropMap = address.getOptions();
+ this._addressPropAccess = new MapAccessor(_addressPropMap);
+ this._nodePropMap = address.getOptions() == null
|| address.getOptions().get(NODE) == null ? null
: (Map) address.getOptions().get(NODE);
- if (node_props != null)
+ if (_nodePropMap != null)
{
- nodeProps = new MapAccessor(node_props);
+ _nodePropAccess = new MapAccessor(_nodePropMap);
}
- Map link_props = address.getOptions() == null
+ this._linkPropMap = address.getOptions() == null
|| address.getOptions().get(LINK) == null ? null
: (Map) address.getOptions().get(LINK);
- if (link_props != null)
+ if (_linkPropMap != null)
{
- linkProps = new MapAccessor(link_props);
+ _linkPropAccess = new MapAccessor(_linkPropMap);
}
}
public String getCreate()
{
- return addressProps.getString(CREATE);
+ return _addressPropAccess.getString(CREATE);
}
public String getAssert()
{
- return addressProps.getString(ASSERT);
+ return _addressPropAccess.getString(ASSERT);
}
public String getDelete()
{
- return addressProps.getString(DELETE);
- }
-
- public boolean isNoLocal()
- {
- Boolean b = nodeProps.getBoolean(NO_LOCAL);
- return b == null ? false : b;
+ return _addressPropAccess.getString(DELETE);
}
public boolean isBrowseOnly()
{
- String mode = addressProps.getString(MODE);
+ String mode = _addressPropAccess.getString(MODE);
return mode != null && mode.equals(BROWSE) ? true : false;
}
@@ -127,7 +124,7 @@ public class AddressHelper
public List<Binding> getBindings(Map props)
{
List<Binding> bindings = new ArrayList<Binding>();
- List<Map> bindingList = (List<Map>) props.get(X_BINDINGS);
+ List<Map> bindingList = (props == null) ? Collections.EMPTY_LIST : (List<Map>) props.get(X_BINDINGS);
if (bindingList != null)
{
for (Map bindingMap : bindingList)
@@ -157,117 +154,70 @@ public class AddressHelper
}
}
- public int getTargetNodeType() throws Exception
+ public int getNodeType() throws Exception
{
- if (nodeProps == null || nodeProps.getString(TYPE) == null)
+ if (_nodePropAccess == null || _nodePropAccess.getString(TYPE) == null)
{
// need to query and figure out
return AMQDestination.UNKNOWN_TYPE;
- } else if (nodeProps.getString(TYPE).equals("queue"))
+ }
+ else if (_nodePropAccess.getString(TYPE).equals("queue"))
{
return AMQDestination.QUEUE_TYPE;
- } else if (nodeProps.getString(TYPE).equals("topic"))
+ }
+ else if (_nodePropAccess.getString(TYPE).equals("topic"))
{
return AMQDestination.TOPIC_TYPE;
- } else
+ }
+ else
{
throw new Exception("unkown exchange type");
}
}
- public Node getTargetNode(int addressType)
+ public Node getNode()
{
- // target node here is the default exchange
- if (nodeProps == null || addressType == AMQDestination.QUEUE_TYPE)
- {
- return new ExchangeNode();
- } else if (addressType == AMQDestination.TOPIC_TYPE)
- {
- Map node = (Map) address.getOptions().get(NODE);
- return createExchangeNode(node);
- } else
+ Node node = new Node(_address.getName());
+ if (_nodePropAccess != null)
{
- // don't know yet
- return null;
- }
- }
-
- private Node createExchangeNode(Map parent)
- {
- Map declareArgs = getDeclareArgs(parent);
- MapAccessor argsMap = new MapAccessor(declareArgs);
- ExchangeNode node = new ExchangeNode();
- node.setExchangeType(argsMap.getString(TYPE) == null ? null : argsMap
- .getString(TYPE));
- fillInCommonNodeArgs(node, parent, argsMap);
- return node;
- }
+ Map xDeclareMap = getDeclareArgs(_nodePropMap);
+ MapAccessor xDeclareMapAccessor = new MapAccessor(xDeclareMap);
- private Node createQueueNode(Map parent)
- {
- Map declareArgs = getDeclareArgs(parent);
- MapAccessor argsMap = new MapAccessor(declareArgs);
- QueueNode node = new QueueNode();
- node.setAlternateExchange(argsMap.getString(ALT_EXCHANGE));
- node.setExclusive(argsMap.getBoolean(EXCLUSIVE) == null ? false
- : argsMap.getBoolean(EXCLUSIVE));
- fillInCommonNodeArgs(node, parent, argsMap);
-
- return node;
- }
-
- private void fillInCommonNodeArgs(Node node, Map parent, MapAccessor argsMap)
- {
- node.setDurable(getDurability(parent));
- node.setAutoDelete(argsMap.getBoolean(AUTO_DELETE) == null ? false
- : argsMap.getBoolean(AUTO_DELETE));
- node.setAlternateExchange(argsMap.getString(ALT_EXCHANGE));
- node.setBindings(getBindings(parent));
- if (getDeclareArgs(parent).containsKey(ARGUMENTS))
- {
- node.setDeclareArgs((Map<String,Object>)getDeclareArgs(parent).get(ARGUMENTS));
+ node.setDurable(getBooleanProperty(_nodePropAccess,DURABLE,false));
+ node.setAutoDelete(getBooleanProperty(xDeclareMapAccessor,AUTO_DELETE,false));
+ node.setExclusive(getBooleanProperty(xDeclareMapAccessor,EXCLUSIVE,false));
+ node.setAlternateExchange(xDeclareMapAccessor.getString(ALT_EXCHANGE));
+ if (xDeclareMapAccessor.getString(TYPE) != null)
+ {
+ node.setExchangeType(xDeclareMapAccessor.getString(TYPE));
+ }
+ node.setBindings(getBindings(_nodePropMap));
+ if (!xDeclareMap.isEmpty() && xDeclareMap.containsKey(ARGUMENTS))
+ {
+ node.setDeclareArgs((Map<String,Object>)xDeclareMap.get(ARGUMENTS));
+ }
}
- }
-
- private boolean getDurability(Map map)
- {
- Accessor access = new MapAccessor(map);
- Boolean result = access.getBoolean(DURABLE);
- return (result == null) ? false : result.booleanValue();
+ return node;
}
- /**
- * if the type == queue x-declare args from the node props is used. if the
- * type == exchange x-declare args from the link props is used else just
- * create a default temp queue.
- */
- public Node getSourceNode(int addressType)
+ // This should really be in the Accessor interface
+ private boolean getBooleanProperty(Accessor access, String propName, boolean defaultValue)
{
- if (addressType == AMQDestination.QUEUE_TYPE && nodeProps != null)
- {
- return createQueueNode((Map) address.getOptions().get(NODE));
- }
- if (addressType == AMQDestination.TOPIC_TYPE && linkProps != null)
- {
- return createQueueNode((Map) address.getOptions().get(LINK));
- } else
- {
- // need to query the info
- return new QueueNode();
- }
+ Boolean result = access.getBoolean(propName);
+ return (result == null) ? defaultValue : result.booleanValue();
}
public Link getLink() throws Exception
{
Link link = new Link();
link.setSubscription(new Subscription());
- if (linkProps != null)
+ link.setSubscriptionQueue(new SubscriptionQueue());
+ if (_linkPropAccess != null)
{
- link.setDurable(linkProps.getBoolean(DURABLE) == null ? false
- : linkProps.getBoolean(DURABLE));
- link.setName(linkProps.getString(NAME));
+ link.setDurable(getBooleanProperty(_linkPropAccess,DURABLE,false));
+ link.setName(_linkPropAccess.getString(NAME));
- String reliability = linkProps.getString(RELIABILITY);
+ String reliability = _linkPropAccess.getString(RELIABILITY);
if ( reliability != null)
{
if (reliability.equalsIgnoreCase("unreliable"))
@@ -283,13 +233,12 @@ public class AddressHelper
throw new Exception("The reliability mode '" +
reliability + "' is not yet supported");
}
-
}
- if (((Map) address.getOptions().get(LINK)).get(CAPACITY) instanceof Map)
+ if (((Map) _address.getOptions().get(LINK)).get(CAPACITY) instanceof Map)
{
MapAccessor capacityProps = new MapAccessor(
- (Map) ((Map) address.getOptions().get(LINK))
+ (Map) ((Map) _address.getOptions().get(LINK))
.get(CAPACITY));
link
.setConsumerCapacity(capacityProps
@@ -302,17 +251,19 @@ public class AddressHelper
}
else
{
- int cap = linkProps.getInt(CAPACITY) == null ? 0 : linkProps
+ int cap = _linkPropAccess.getInt(CAPACITY) == null ? 0 : _linkPropAccess
.getInt(CAPACITY);
link.setConsumerCapacity(cap);
link.setProducerCapacity(cap);
}
- link.setFilter(linkProps.getString(FILTER));
+ link.setFilter(_linkPropAccess.getString(FILTER));
// so far filter type not used
- if (((Map) address.getOptions().get(LINK)).containsKey(X_SUBSCRIBE))
+ Map linkMap = (Map) _address.getOptions().get(LINK);
+
+ if (linkMap != null && linkMap.containsKey(X_SUBSCRIBE))
{
- Map x_subscribe = (Map)((Map) address.getOptions().get(LINK)).get(X_SUBSCRIBE);
+ Map x_subscribe = (Map)((Map) _address.getOptions().get(LINK)).get(X_SUBSCRIBE);
if (x_subscribe.containsKey(ARGUMENTS))
{
@@ -324,6 +275,18 @@ public class AddressHelper
link.getSubscription().setExclusive(exclusive);
}
+
+ link.setBindings(getBindings(linkMap));
+ Map xDeclareMap = getDeclareArgs(linkMap);
+ SubscriptionQueue queue = link.getSubscriptionQueue();
+ if (!xDeclareMap.isEmpty() && xDeclareMap.containsKey(ARGUMENTS))
+ {
+ MapAccessor xDeclareMapAccessor = new MapAccessor(xDeclareMap);
+ queue.setAutoDelete(getBooleanProperty(xDeclareMapAccessor,AUTO_DELETE,true));
+ queue.setExclusive(getBooleanProperty(xDeclareMapAccessor,EXCLUSIVE,true));
+ queue.setAlternateExchange(xDeclareMapAccessor.getString(ALT_EXCHANGE));
+ queue.setDeclareArgs((Map<String,Object>)xDeclareMap.get(ARGUMENTS));
+ }
}
return link;
diff --git a/java/client/src/main/java/org/apache/qpid/client/messaging/address/Link.java b/java/client/src/main/java/org/apache/qpid/client/messaging/address/Link.java
index 41f6725c8f..40a84ebd02 100644
--- a/java/client/src/main/java/org/apache/qpid/client/messaging/address/Link.java
+++ b/java/client/src/main/java/org/apache/qpid/client/messaging/address/Link.java
@@ -20,9 +20,14 @@
*/
package org.apache.qpid.client.messaging.address;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import org.apache.qpid.client.AMQDestination.Binding;
+
public class Link
{
public enum FilterType { SQL92, XQUERY, SUBJECT }
@@ -36,10 +41,11 @@ public class Link
private boolean _isDurable;
private int _consumerCapacity = 0;
private int _producerCapacity = 0;
- private Node node;
private Subscription subscription;
private Reliability reliability = Reliability.AT_LEAST_ONCE;
-
+ private List<Binding> _bindings = new ArrayList<Binding>();
+ private SubscriptionQueue _subscriptionQueue;
+
public Reliability getReliability()
{
return reliability;
@@ -50,21 +56,11 @@ public class Link
this.reliability = reliability;
}
- public Node getNode()
- {
- return node;
- }
-
- public void setNode(Node node)
- {
- this.node = node;
- }
-
public boolean isDurable()
{
return _isDurable;
}
-
+
public void setDurable(boolean durable)
{
_isDurable = durable;
@@ -139,6 +135,74 @@ public class Link
{
this.subscription = subscription;
}
+
+ public List<Binding> getBindings()
+ {
+ return _bindings;
+ }
+
+ public void setBindings(List<Binding> bindings)
+ {
+ _bindings = bindings;
+ }
+
+ public SubscriptionQueue getSubscriptionQueue()
+ {
+ return _subscriptionQueue;
+ }
+
+ public void setSubscriptionQueue(SubscriptionQueue subscriptionQueue)
+ {
+ this._subscriptionQueue = subscriptionQueue;
+ }
+
+ public static class SubscriptionQueue
+ {
+ private Map<String,Object> _declareArgs = new HashMap<String,Object>();
+ private boolean _isAutoDelete = true;
+ private boolean _isExclusive = true;
+ private String _alternateExchange;
+
+ public Map<String,Object> getDeclareArgs()
+ {
+ return _declareArgs;
+ }
+
+ public void setDeclareArgs(Map<String,Object> options)
+ {
+ _declareArgs = options;
+ }
+
+ public boolean isAutoDelete()
+ {
+ return _isAutoDelete;
+ }
+
+ public void setAutoDelete(boolean autoDelete)
+ {
+ _isAutoDelete = autoDelete;
+ }
+
+ public boolean isExclusive()
+ {
+ return _isExclusive;
+ }
+
+ public void setExclusive(boolean exclusive)
+ {
+ _isExclusive = exclusive;
+ }
+
+ public String getAlternateExchange()
+ {
+ return _alternateExchange;
+ }
+
+ public void setAlternateExchange(String altExchange)
+ {
+ _alternateExchange = altExchange;
+ }
+ }
public static class Subscription
{
diff --git a/java/client/src/main/java/org/apache/qpid/client/messaging/address/Node.java b/java/client/src/main/java/org/apache/qpid/client/messaging/address/Node.java
index 0da0327885..005f98f344 100644
--- a/java/client/src/main/java/org/apache/qpid/client/messaging/address/Node.java
+++ b/java/client/src/main/java/org/apache/qpid/client/messaging/address/Node.java
@@ -26,19 +26,33 @@ import org.apache.qpid.client.AMQDestination.Binding;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public abstract class Node
+public class Node
{
private int _nodeType = AMQDestination.UNKNOWN_TYPE;
+ private String _name;
private boolean _isDurable;
private boolean _isAutoDelete;
+ private boolean _isExclusive;
private String _alternateExchange;
+ private String _exchangeType = "topic"; // used when node is an exchange instead of a queue.
private List<Binding> _bindings = new ArrayList<Binding>();
- private Map<String,Object> _declareArgs = Collections.emptyMap();
+ private Map<String,Object> _declareArgs = new HashMap<String,Object>();
- protected Node(int nodeType)
+ protected Node(String name)
+ {
+ _name = name;
+ }
+
+ public String getName()
+ {
+ return _name;
+ }
+
+ public void setNodeType(int nodeType)
{
_nodeType = nodeType;
}
@@ -58,6 +72,16 @@ public abstract class Node
_isDurable = durable;
}
+ public boolean isExclusive()
+ {
+ return _isExclusive;
+ }
+
+ public void setExclusive(boolean exclusive)
+ {
+ _isExclusive = exclusive;
+ }
+
public boolean isAutoDelete()
{
return _isAutoDelete;
@@ -100,56 +124,15 @@ public abstract class Node
public void setDeclareArgs(Map<String,Object> options)
{
_declareArgs = options;
- }
-
- public static class QueueNode extends Node
- {
- private boolean _isExclusive;
- private QpidQueueOptions _queueOptions = new QpidQueueOptions();
-
- public QueueNode()
- {
- super(AMQDestination.QUEUE_TYPE);
- }
-
- public boolean isExclusive()
- {
- return _isExclusive;
- }
-
- public void setExclusive(boolean exclusive)
- {
- _isExclusive = exclusive;
- }
}
-
- public static class ExchangeNode extends Node
- {
- private QpidExchangeOptions _exchangeOptions = new QpidExchangeOptions();
- private String _exchangeType;
-
- public ExchangeNode()
- {
- super(AMQDestination.TOPIC_TYPE);
- }
-
- public String getExchangeType()
- {
- return _exchangeType;
- }
-
- public void setExchangeType(String exchangeType)
- {
- _exchangeType = exchangeType;
- }
-
+
+ public void setExchangeType(String type)
+ {
+ _exchangeType = type;
}
-
- public static class UnknownNodeType extends Node
+
+ public String getExchangeType()
{
- public UnknownNodeType()
- {
- super(AMQDestination.UNKNOWN_TYPE);
- }
+ return _exchangeType;
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
index b314453e31..816caac824 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolHandler.java
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.client.protocol;
+import org.apache.qpid.client.HeartbeatListener;
import org.apache.qpid.util.BytesDataOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,6 +57,7 @@ import org.apache.qpid.protocol.AMQMethodListener;
import org.apache.qpid.protocol.ProtocolEngine;
import org.apache.qpid.thread.Threading;
import org.apache.qpid.transport.Sender;
+import org.apache.qpid.transport.TransportException;
import org.apache.qpid.transport.network.NetworkConnection;
import java.io.IOException;
@@ -177,6 +179,9 @@ public class AMQProtocolHandler implements ProtocolEngine
private NetworkConnection _network;
private Sender<ByteBuffer> _sender;
+ private long _lastReadTime = System.currentTimeMillis();
+ private long _lastWriteTime = System.currentTimeMillis();
+ private HeartbeatListener _heartbeatListener = HeartbeatListener.DEFAULT;
/**
* Creates a new protocol handler, associated with the specified client connection instance.
@@ -210,48 +215,67 @@ public class AMQProtocolHandler implements ProtocolEngine
}
else
{
- _logger.debug("Session closed called with failover state currently " + _failoverState);
-
- // reconnetablility was introduced here so as not to disturb the client as they have made their intentions
- // known through the policy settings.
-
- if ((_failoverState != FailoverState.IN_PROGRESS) && _connection.failoverAllowed())
+ // Use local variable to keep flag whether fail-over allowed or not,
+ // in order to execute AMQConnection#exceptionRecievedout out of synchronization block,
+ // otherwise it might deadlock with failover mutex
+ boolean failoverNotAllowed = false;
+ synchronized (this)
{
- _logger.debug("FAILOVER STARTING");
- if (_failoverState == FailoverState.NOT_STARTED)
- {
- _failoverState = FailoverState.IN_PROGRESS;
- startFailoverThread();
- }
- else
- {
- _logger.debug("Not starting failover as state currently " + _failoverState);
- }
- }
- else
- {
- _logger.debug("Failover not allowed by policy."); // or already in progress?
-
if (_logger.isDebugEnabled())
{
- _logger.debug(_connection.getFailoverPolicy().toString());
+ _logger.debug("Session closed called with failover state " + _failoverState);
}
- if (_failoverState != FailoverState.IN_PROGRESS)
+ // reconnetablility was introduced here so as not to disturb the client as they have made their intentions
+ // known through the policy settings.
+ if (_failoverState == FailoverState.NOT_STARTED)
{
- _logger.debug("sessionClose() not allowed to failover");
- _connection.exceptionReceived(new AMQDisconnectedException(
- "Server closed connection and reconnection " + "not permitted.",
- _stateManager.getLastException()));
+ // close the sender
+ try
+ {
+ _sender.close();
+ }
+ catch (Exception e)
+ {
+ _logger.warn("Exception occured on closing the sender", e);
+ }
+ if (_connection.failoverAllowed())
+ {
+ _failoverState = FailoverState.IN_PROGRESS;
+
+ _logger.debug("FAILOVER STARTING");
+ startFailoverThread();
+ }
+ else if (_connection.isConnected())
+ {
+ failoverNotAllowed = true;
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Failover not allowed by policy:" + _connection.getFailoverPolicy());
+ }
+ }
+ else
+ {
+ _logger.debug("We are in process of establishing the initial connection");
+ }
}
else
{
- _logger.debug("sessionClose() failover in progress");
+ _logger.debug("Not starting the failover thread as state currently " + _failoverState);
}
}
+
+ if (failoverNotAllowed)
+ {
+ _connection.exceptionReceived(new AMQDisconnectedException(
+ "Server closed connection and reconnection not permitted.", _stateManager.getLastException()));
+ }
}
- _logger.debug("Protocol Session [" + this + "] closed");
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Protocol Session [" + this + "] closed");
+ }
}
/** See {@link FailoverHandler} to see rationale for separate thread. */
@@ -280,7 +304,6 @@ public class AMQProtocolHandler implements ProtocolEngine
{
_logger.debug("Protocol Session [" + this + "] idle: reader");
// failover:
- HeartbeatDiagnostics.timeout();
_logger.warn("Timed out while waiting for heartbeat from peer.");
_network.close();
}
@@ -289,7 +312,7 @@ public class AMQProtocolHandler implements ProtocolEngine
{
_logger.debug("Protocol Session [" + this + "] idle: reader");
writeFrame(HeartbeatBody.FRAME);
- HeartbeatDiagnostics.sent();
+ _heartbeatListener.heartbeatSent();
}
/**
@@ -297,14 +320,29 @@ public class AMQProtocolHandler implements ProtocolEngine
*/
public void exception(Throwable cause)
{
- if (_failoverState == FailoverState.NOT_STARTED)
+ boolean causeIsAConnectionProblem =
+ cause instanceof AMQConnectionClosedException ||
+ cause instanceof IOException ||
+ cause instanceof TransportException;
+
+ if (causeIsAConnectionProblem)
{
- if ((cause instanceof AMQConnectionClosedException) || cause instanceof IOException)
+ //ensure the IoSender and IoReceiver are closed
+ try
{
- _logger.info("Exception caught therefore going to attempt failover: " + cause, cause);
- // this will attempt failover
_network.close();
- closed();
+ }
+ catch (Exception e)
+ {
+ //ignore
+ }
+ }
+ FailoverState state = getFailoverState();
+ if (state == FailoverState.NOT_STARTED)
+ {
+ if (causeIsAConnectionProblem)
+ {
+ _logger.info("Connection exception caught therefore going to attempt failover: " + cause, cause);
}
else
{
@@ -319,7 +357,7 @@ public class AMQProtocolHandler implements ProtocolEngine
}
// we reach this point if failover was attempted and failed therefore we need to let the calling app
// know since we cannot recover the situation
- else if (_failoverState == FailoverState.FAILED)
+ else if (state == FailoverState.FAILED)
{
_logger.error("Exception caught by protocol handler: " + cause, cause);
@@ -329,6 +367,10 @@ public class AMQProtocolHandler implements ProtocolEngine
propagateExceptionToAllWaiters(amqe);
_connection.exceptionReceived(cause);
}
+ else
+ {
+ _logger.warn("Exception caught by protocol handler: " + cause, cause);
+ }
}
/**
@@ -403,6 +445,7 @@ public class AMQProtocolHandler implements ProtocolEngine
public void received(ByteBuffer msg)
{
_readBytes += msg.remaining();
+ _lastReadTime = System.currentTimeMillis();
try
{
final ArrayList<AMQDataBlock> dataBlocks = _codecFactory.getDecoder().decodeBuffer(msg);
@@ -431,8 +474,6 @@ public class AMQProtocolHandler implements ProtocolEngine
final AMQBody bodyFrame = frame.getBodyFrame();
- HeartbeatDiagnostics.received(bodyFrame instanceof HeartbeatBody);
-
bodyFrame.handle(frame.getChannel(), _protocolSession);
_connection.bytesReceived(_readBytes);
@@ -521,6 +562,7 @@ public class AMQProtocolHandler implements ProtocolEngine
public synchronized void writeFrame(AMQDataBlock frame, boolean flush)
{
final ByteBuffer buf = asByteBuffer(frame);
+ _lastWriteTime = System.currentTimeMillis();
_writtenBytes += buf.remaining();
_sender.send(buf);
if(flush)
@@ -792,14 +834,14 @@ public class AMQProtocolHandler implements ProtocolEngine
return _protocolSession;
}
- FailoverState getFailoverState()
+ synchronized FailoverState getFailoverState()
{
return _failoverState;
}
- public void setFailoverState(FailoverState failoverState)
+ public synchronized void setFailoverState(FailoverState failoverState)
{
- _failoverState = failoverState;
+ _failoverState= failoverState;
}
public byte getProtocolMajorVersion()
@@ -843,6 +885,23 @@ public class AMQProtocolHandler implements ProtocolEngine
_sender = sender;
}
+ @Override
+ public long getLastReadTime()
+ {
+ return _lastReadTime;
+ }
+
+ @Override
+ public long getLastWriteTime()
+ {
+ return _lastWriteTime;
+ }
+
+ protected Sender<ByteBuffer> getSender()
+ {
+ return _sender;
+ }
+
/** @param delay delay in seconds (not ms) */
void initHeartbeats(int delay)
{
@@ -850,7 +909,6 @@ public class AMQProtocolHandler implements ProtocolEngine
{
_network.setMaxWriteIdle(delay);
_network.setMaxReadIdle(HeartbeatConfig.CONFIG.getTimeout(delay));
- HeartbeatDiagnostics.init(delay, HeartbeatConfig.CONFIG.getTimeout(delay));
}
}
@@ -865,5 +923,13 @@ public class AMQProtocolHandler implements ProtocolEngine
}
+ public void setHeartbeatListener(HeartbeatListener listener)
+ {
+ _heartbeatListener = listener == null ? HeartbeatListener.DEFAULT : listener;
+ }
+ public void heartbeatBodyReceived()
+ {
+ _heartbeatListener.heartbeatReceived();
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
index af57fd98fc..aed10cf15f 100644
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
+++ b/java/client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java
@@ -48,6 +48,8 @@ import org.apache.qpid.transport.TransportException;
import javax.jms.JMSException;
import javax.security.sasl.SaslClient;
+
+import java.nio.ByteBuffer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -265,7 +267,7 @@ public class AMQProtocolSession implements AMQVersionAwareProtocolSession
public void heartbeatBodyReceived(int channelId, HeartbeatBody body) throws AMQException
{
-
+ _protocolHandler.heartbeatBodyReceived();
}
/**
@@ -372,6 +374,11 @@ public class AMQProtocolSession implements AMQVersionAwareProtocolSession
}
}
+ public Sender<ByteBuffer> getSender()
+ {
+ return _protocolHandler.getSender();
+ }
+
public void failover(String host, int port)
{
_protocolHandler.failover(host, port);
diff --git a/java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatDiagnostics.java b/java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatDiagnostics.java
deleted file mode 100644
index d387a8ba93..0000000000
--- a/java/client/src/main/java/org/apache/qpid/client/protocol/HeartbeatDiagnostics.java
+++ /dev/null
@@ -1,125 +0,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.
- *
- */
-package org.apache.qpid.client.protocol;
-
-class HeartbeatDiagnostics
-{
- private static final Diagnostics _impl = init();
-
- private HeartbeatDiagnostics()
- {
- }
-
- private static Diagnostics init()
- {
- return Boolean.getBoolean("amqj.heartbeat.diagnostics") ? new On() : new Off();
- }
-
- static void sent()
- {
- _impl.sent();
- }
-
- static void timeout()
- {
- _impl.timeout();
- }
-
- static void received(boolean heartbeat)
- {
- _impl.received(heartbeat);
- }
-
- static void init(int delay, int timeout)
- {
- _impl.init(delay, timeout);
- }
-
- private static interface Diagnostics
- {
- void sent();
- void timeout();
- void received(boolean heartbeat);
- void init(int delay, int timeout);
- }
-
- private static class On implements Diagnostics
- {
- private final String[] messages = new String[50];
- private int i;
-
- private void save(String msg)
- {
- messages[i++] = msg;
- if(i >= messages.length){
- i = 0;//i.e. a circular buffer
- }
- }
-
- public void sent()
- {
- save(System.currentTimeMillis() + ": sent heartbeat");
- }
-
- public void timeout()
- {
- for(int i = 0; i < messages.length; i++)
- {
- if(messages[i] != null)
- {
- System.out.println(messages[i]);
- }
- }
- System.out.println(System.currentTimeMillis() + ": timed out");
- }
-
- public void received(boolean heartbeat)
- {
- save(System.currentTimeMillis() + ": received " + (heartbeat ? "heartbeat" : "data"));
- }
-
- public void init(int delay, int timeout)
- {
- System.out.println(System.currentTimeMillis() + ": initialised delay=" + delay + ", timeout=" + timeout);
- }
- }
-
- private static class Off implements Diagnostics
- {
- public void sent()
- {
-
- }
- public void timeout()
- {
-
- }
- public void received(boolean heartbeat)
- {
-
- }
-
- public void init(int delay, int timeout)
- {
-
- }
- }
-}
diff --git a/java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java b/java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java
index 9198903408..b43229292f 100644
--- a/java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java
+++ b/java/client/src/main/java/org/apache/qpid/client/security/DynamicSaslRegistrar.java
@@ -28,8 +28,10 @@ import org.apache.qpid.util.FileUtils;
import javax.security.sasl.SaslClientFactory;
import java.io.IOException;
import java.io.InputStream;
+import java.security.Provider;
import java.security.Security;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
@@ -67,10 +69,10 @@ public class DynamicSaslRegistrar
}
/** Reads the properties file, and creates a dynamic security provider to register the SASL implementations with. */
- public static void registerSaslProviders()
+ public static ProviderRegistrationResult registerSaslProviders()
{
_logger.debug("public static void registerSaslProviders(): called");
-
+ ProviderRegistrationResult result = ProviderRegistrationResult.FAILED;
// Open the SASL properties file, using the default name is one is not specified.
String filename = System.getProperty(FILE_PROPERTY);
InputStream is =
@@ -89,22 +91,45 @@ public class DynamicSaslRegistrar
if (factories.size() > 0)
{
// Ensure we are used before the defaults
- if (Security.insertProviderAt(new JCAProvider(factories), 1) == -1)
+ JCAProvider qpidProvider = new JCAProvider(factories);
+ if (Security.insertProviderAt(qpidProvider, 1) == -1)
{
- _logger.error("Unable to load custom SASL providers.");
+ Provider registeredProvider = findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME);
+ if (registeredProvider == null)
+ {
+ result = ProviderRegistrationResult.FAILED;
+ _logger.error("Unable to load custom SASL providers.");
+ }
+ else if (registeredProvider.equals(qpidProvider))
+ {
+ result = ProviderRegistrationResult.EQUAL_ALREADY_REGISTERED;
+ _logger.debug("Custom SASL provider is already registered with equal properties.");
+ }
+ else
+ {
+ result = ProviderRegistrationResult.DIFFERENT_ALREADY_REGISTERED;
+ _logger.warn("Custom SASL provider was already registered with different properties.");
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Custom SASL provider " + registeredProvider + " properties: " + new HashMap<Object, Object>(registeredProvider));
+ }
+ }
}
else
{
+ result = ProviderRegistrationResult.SUCCEEDED;
_logger.info("Additional SASL providers successfully registered.");
}
}
else
{
- _logger.warn("No additional SASL providers registered.");
+ result = ProviderRegistrationResult.NO_SASL_FACTORIES;
+ _logger.warn("No additional SASL factories found to register.");
}
}
catch (IOException e)
{
+ result = ProviderRegistrationResult.FAILED;
_logger.error("Error reading properties: " + e, e);
}
finally
@@ -122,6 +147,22 @@ public class DynamicSaslRegistrar
}
}
}
+ return result;
+ }
+
+ static Provider findProvider(String name)
+ {
+ Provider[] providers = Security.getProviders();
+ Provider registeredProvider = null;
+ for (Provider provider : providers)
+ {
+ if (name.equals(provider.getName()))
+ {
+ registeredProvider = provider;
+ break;
+ }
+ }
+ return registeredProvider;
}
/**
@@ -158,15 +199,24 @@ public class DynamicSaslRegistrar
continue;
}
- _logger.debug("Registering class "+ clazz.getName() +" for mechanism "+mechanism);
+ _logger.debug("Found class "+ clazz.getName() +" for mechanism "+mechanism);
factoriesToRegister.put(mechanism, (Class<? extends SaslClientFactory>) clazz);
}
catch (Exception ex)
{
- _logger.error("Error instantiating SaslClientFactory calss " + className + " - skipping");
+ _logger.error("Error instantiating SaslClientFactory class " + className + " - skipping");
}
}
return factoriesToRegister;
}
+
+ public static enum ProviderRegistrationResult
+ {
+ SUCCEEDED,
+ EQUAL_ALREADY_REGISTERED,
+ DIFFERENT_ALREADY_REGISTERED,
+ NO_SASL_FACTORIES,
+ FAILED;
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java b/java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java
index 4a91f805f6..c9bcaf0d15 100644
--- a/java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java
+++ b/java/client/src/main/java/org/apache/qpid/client/security/JCAProvider.java
@@ -39,6 +39,11 @@ import java.util.Map;
*/
public class JCAProvider extends Provider
{
+ static final String QPID_CLIENT_SASL_PROVIDER_NAME = "AMQSASLProvider-Client";
+ static final String QPID_CLIENT_SASL_PROVIDER_INFO = "A JCA provider that registers all "
+ + "AMQ SASL providers that want to be registered";
+ static final double QPID_CLIENT_SASL_PROVIDER_VERSION = 1.0;
+
private static final Logger log = LoggerFactory.getLogger(JCAProvider.class);
/**
@@ -48,8 +53,7 @@ public class JCAProvider extends Provider
*/
public JCAProvider(Map<String, Class<? extends SaslClientFactory>> providerMap)
{
- super("AMQSASLProvider-Client", 1.0, "A JCA provider that registers all "
- + "AMQ SASL providers that want to be registered");
+ super(QPID_CLIENT_SASL_PROVIDER_NAME, QPID_CLIENT_SASL_PROVIDER_VERSION, QPID_CLIENT_SASL_PROVIDER_INFO);
register(providerMap);
}
@@ -63,7 +67,7 @@ public class JCAProvider extends Provider
for (Map.Entry<String, Class<? extends SaslClientFactory>> me : providerMap.entrySet())
{
put( "SaslClientFactory."+me.getKey(), me.getValue().getName());
- log.debug("Registered SASL Client factory for " + me.getKey() + " as " + me.getValue().getName());
+ log.debug("Recording SASL Client factory for " + me.getKey() + " as " + me.getValue().getName());
}
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java b/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
index 0b6217ffce..ed75e1f4c3 100644
--- a/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
+++ b/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java
@@ -157,12 +157,15 @@ public class AMQStateManager implements AMQMethodListener
if (_waiters.size() == 0)
{
- _logger.error("No Waiters for error saving as last error:" + error.getMessage());
+ _logger.info("No Waiters for error. Saving as last error:" + error.getMessage());
_lastException = error;
}
for (StateWaiter waiter : _waiters)
{
- _logger.error("Notifying Waiters(" + _waiters + ") for error:" + error.getMessage());
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("Notifying waiter " + waiter + " for error:" + error.getMessage());
+ }
waiter.error(error);
}
}
diff --git a/java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java b/java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java
index 3c9a6e1500..4789dd0ed7 100644
--- a/java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java
+++ b/java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java
@@ -20,6 +20,8 @@
*/
package org.apache.qpid.client.transport;
+import org.apache.qpid.client.HeartbeatListener;
+import org.apache.qpid.transport.ConnectionHeartbeat;
import org.ietf.jgss.GSSContext;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.GSSManager;
@@ -70,6 +72,7 @@ public class ClientConnectionDelegate extends ClientDelegate
}
private final ConnectionURL _connectionURL;
+ private HeartbeatListener _heartbeatListener = HeartbeatListener.DEFAULT;
/**
* @param settings
@@ -165,4 +168,19 @@ public class ClientConnectionDelegate extends ClientDelegate
return null;
}
+
+ @Override
+ public void connectionHeartbeat(Connection conn, ConnectionHeartbeat hearbeat)
+ {
+ // ClientDelegate simply responds to heartbeats with heartbeats
+ _heartbeatListener.heartbeatReceived();
+ super.connectionHeartbeat(conn, hearbeat);
+ _heartbeatListener.heartbeatSent();
+ }
+
+
+ public void setHeartbeatListener(HeartbeatListener listener)
+ {
+ _heartbeatListener = listener == null ? HeartbeatListener.DEFAULT : listener;
+ }
}
diff --git a/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java b/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
index 8fd6ff6d33..c4fbeb5607 100644
--- a/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
+++ b/java/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
@@ -20,9 +20,8 @@
*/
package org.apache.qpid.jms;
-import org.apache.qpid.framing.AMQShortString;
-
import java.util.List;
+import org.apache.qpid.framing.AMQShortString;
/**
Connection URL format
@@ -35,14 +34,22 @@ public interface ConnectionURL
public static final String AMQ_PROTOCOL = "amqp";
public static final String OPTIONS_SYNC_PERSISTENCE = "sync_persistence";
public static final String OPTIONS_MAXPREFETCH = "maxprefetch";
- public static final String OPTIONS_SYNC_ACK = "sync_ack";
+ public static final String OPTIONS_SYNC_ACK = "sync_ack";
public static final String OPTIONS_SYNC_PUBLISH = "sync_publish";
public static final String OPTIONS_USE_LEGACY_MAP_MESSAGE_FORMAT = "use_legacy_map_msg_format";
+ public static final String OPTIONS_USE_LEGACY_STREAM_MESSAGE_FORMAT = "use_legacy_stream_msg_format";
public static final String OPTIONS_BROKERLIST = "brokerlist";
public static final String OPTIONS_FAILOVER = "failover";
public static final String OPTIONS_FAILOVER_CYCLE = "cyclecount";
/**
+ * This option is used to apply a connection level override of
+ * the {@value BrokerDetails#OPTIONS_SSL} option values in the
+ * {@value ConnectionURL#OPTIONS_BROKERLIST};
+ */
+ public static final String OPTIONS_SSL = "ssl";
+
+ /**
* This option is only applicable for 0-8/0-9/0-9-1 protocols connection
* <p>
* It tells the client to delegate the requeue/DLQ decision to the
@@ -54,9 +61,11 @@ public interface ConnectionURL
public static final String OPTIONS_DEFAULT_QUEUE_EXCHANGE = "defaultQueueExchange";
public static final String OPTIONS_TEMPORARY_TOPIC_EXCHANGE = "temporaryTopicExchange";
public static final String OPTIONS_TEMPORARY_QUEUE_EXCHANGE = "temporaryQueueExchange";
+ public static final String OPTIONS_VERIFY_QUEUE_ON_SEND = "verifyQueueOnSend";
+
public static final byte URL_0_8 = 1;
public static final byte URL_0_10 = 2;
-
+
String getURL();
String getFailoverMethod();
diff --git a/java/client/src/main/java/org/apache/qpid/jms/ListMessage.java b/java/client/src/main/java/org/apache/qpid/jms/ListMessage.java
new file mode 100644
index 0000000000..21dd2a89ee
--- /dev/null
+++ b/java/client/src/main/java/org/apache/qpid/jms/ListMessage.java
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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.jms;
+
+import javax.jms.JMSException;
+
+import java.util.Iterator;
+import java.util.List;
+
+public interface ListMessage extends javax.jms.StreamMessage
+{
+ boolean add(Object e) throws JMSException;
+
+ void add(int index, Object e) throws JMSException;
+
+ boolean contains(Object e) throws JMSException;
+
+ Object get(int index) throws JMSException;
+
+ int indexOf(Object e) throws JMSException;
+
+ Iterator<Object> iterator() throws JMSException;
+
+ Object remove(int index) throws JMSException;
+
+ boolean remove(Object e)throws JMSException;
+
+ Object set(int index, Object e) throws JMSException;
+
+ int size() throws JMSException;
+
+ Object[] toArray() throws JMSException;
+
+ List<Object> asList() throws JMSException;
+
+ void setList(List<Object> l) throws JMSException;
+}
diff --git a/java/client/src/main/java/org/apache/qpid/jms/MessageProducer.java b/java/client/src/main/java/org/apache/qpid/jms/MessageProducer.java
index bec8b0917d..82c2b88c30 100644
--- a/java/client/src/main/java/org/apache/qpid/jms/MessageProducer.java
+++ b/java/client/src/main/java/org/apache/qpid/jms/MessageProducer.java
@@ -23,25 +23,11 @@ package org.apache.qpid.jms;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
-import java.io.UnsupportedEncodingException;
/**
*/
public interface MessageProducer extends javax.jms.MessageProducer
{
- /**
- * Set the default MIME type for messages produced by this producer. This reduces the overhead of each message.
- * @param mimeType
- */
- void setMimeType(String mimeType) throws JMSException;
-
- /**
- * Set the default encoding for messages produced by this producer. This reduces the overhead of each message.
- * @param encoding the encoding as understood by XXXX how do I specify this?? RG
- * @throws UnsupportedEncodingException if the encoding is not understood
- */
- void setEncoding(String encoding) throws UnsupportedEncodingException, JMSException;
-
void send(Destination destination, Message message, int deliveryMode,
int priority, long timeToLive, boolean immediate)
throws JMSException;
diff --git a/java/client/src/main/java/org/apache/qpid/jms/Session.java b/java/client/src/main/java/org/apache/qpid/jms/Session.java
index b4bf2d1d85..4801f87295 100644
--- a/java/client/src/main/java/org/apache/qpid/jms/Session.java
+++ b/java/client/src/main/java/org/apache/qpid/jms/Session.java
@@ -21,6 +21,7 @@
package org.apache.qpid.jms;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.jms.ListMessage;
import javax.jms.Destination;
import javax.jms.JMSException;
@@ -100,4 +101,6 @@ public interface Session extends TopicSession, QueueSession
AMQShortString getDefaultTopicExchangeName();
AMQShortString getTemporaryQueueExchangeName();
+
+ ListMessage createListMessage() throws JMSException;
}
diff --git a/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java
index d186a440da..d309251b44 100644
--- a/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java
+++ b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java
@@ -20,25 +20,60 @@
*/
package org.apache.qpid.client;
-import junit.framework.TestCase;
-
-import org.apache.qpid.AMQInvalidArgumentException;
+import java.util.concurrent.atomic.AtomicReference;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
-import java.util.concurrent.atomic.AtomicReference;
-public class AMQConnectionUnitTest extends TestCase
+import org.apache.qpid.AMQInvalidArgumentException;
+import org.apache.qpid.configuration.ClientProperties;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class AMQConnectionUnitTest extends QpidTestCase
{
+ String _url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'";
+
+ public void testVerifyQueueOnSendDefault() throws Exception
+ {
+ MockAMQConnection connection = new MockAMQConnection(_url);
+ assertFalse(connection.validateQueueOnSend());
+ }
+
+ public void testVerifyQueueOnSendViaSystemProperty() throws Exception
+ {
+ setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "true");
+ MockAMQConnection connection = new MockAMQConnection(_url);
+ assertTrue(connection.validateQueueOnSend());
+
+ setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "false");
+ connection = new MockAMQConnection(_url);
+ assertFalse(connection.validateQueueOnSend());
+ }
+
+ public void testVerifyQueueOnSendViaURL() throws Exception
+ {
+ MockAMQConnection connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='true'");
+ assertTrue(connection.validateQueueOnSend());
+
+ connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='false'");
+ assertFalse(connection.validateQueueOnSend());
+ }
+
+ public void testVerifyQueueOnSendViaURLoverridesSystemProperty() throws Exception
+ {
+ setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "false");
+ MockAMQConnection connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='true'");
+ assertTrue(connection.validateQueueOnSend());
+ }
public void testExceptionReceived()
{
- String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'";
AMQInvalidArgumentException expectedException = new AMQInvalidArgumentException("Test", null);
final AtomicReference<JMSException> receivedException = new AtomicReference<JMSException>();
try
{
- MockAMQConnection connection = new MockAMQConnection(url);
+ MockAMQConnection connection = new MockAMQConnection(_url);
connection.setExceptionListener(new ExceptionListener()
{
@@ -62,4 +97,22 @@ public class AMQConnectionUnitTest extends TestCase
assertEquals("JMSException linked exception is incorrect", expectedException, exception.getLinkedException());
}
+ /**
+ * This should expand to test all the defaults.
+ */
+ public void testDefaultStreamMessageEncoding() throws Exception
+ {
+ MockAMQConnection connection = new MockAMQConnection(_url);
+ assertTrue("Legacy Stream message encoding should be the default",connection.isUseLegacyStreamMessageFormat());
+ }
+
+ /**
+ * This should expand to test all the connection properties.
+ */
+ public void testStreamMessageEncodingProperty() throws Exception
+ {
+ MockAMQConnection connection = new MockAMQConnection(_url + "&use_legacy_stream_msg_format='false'");
+ assertFalse("Stream message encoding should be amqp/list",connection.isUseLegacyStreamMessageFormat());
+ }
+
}
diff --git a/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_10Test.java b/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_10Test.java
index 028e2d5cc3..40ed9319f1 100644
--- a/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_10Test.java
+++ b/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_10Test.java
@@ -18,6 +18,7 @@
*/
package org.apache.qpid.client;
+import org.apache.qpid.client.message.AMQPEncodedListMessage;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.transport.*;
@@ -28,6 +29,8 @@ import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
+import javax.jms.StreamMessage;
+
import java.util.ArrayList;
import java.util.List;
@@ -276,7 +279,7 @@ public class AMQSession_0_10Test extends QpidTestCase
{
BasicMessageConsumer_0_10 consumer = session.createMessageConsumer(createDestination(), 1, 1, true, false,
null, null, false, true);
- session.sendConsume(consumer, new AMQShortString("test"), null, true, 1);
+ session.sendConsume(consumer, new AMQShortString("test"), true, 1);
}
catch (Exception e)
{
@@ -459,6 +462,13 @@ public class AMQSession_0_10Test extends QpidTestCase
assertNotNull("ExchangeDeclare event was not sent", event);
}
+ public void testCreateStreamMessage() throws Exception
+ {
+ AMQSession_0_10 session = createAMQSession_0_10();
+ StreamMessage m = session.createStreamMessage();
+ assertTrue("Legacy Stream message encoding should be the default" + m.getClass(),!(m instanceof AMQPEncodedListMessage));
+ }
+
public void testGetQueueDepthWithSync()
{
// slow down a flush thread
@@ -587,7 +597,7 @@ public class AMQSession_0_10Test extends QpidTestCase
connection.setSessionFactory(new SessionFactory()
{
- public Session newSession(Connection conn, Binary name, long expiry)
+ public Session newSession(Connection conn, Binary name, long expiry, boolean isNoReplay)
{
return new MockSession(conn, new SessionDelegate(), name, expiry, throwException);
}
@@ -660,7 +670,6 @@ public class AMQSession_0_10Test extends QpidTestCase
if (m instanceof ExchangeBound)
{
ExchangeBoundResult struc = new ExchangeBoundResult();
- struc.setQueueNotFound(true);
result.setValue(struc);
}
else if (m instanceof ExchangeQuery)
diff --git a/java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java b/java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java
index 722cbd0752..066ece7ed1 100644
--- a/java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java
+++ b/java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java
@@ -48,7 +48,7 @@ public class BasicMessageConsumer_0_8_Test extends TestCase
TestAMQSession testSession = new TestAMQSession(conn);
BasicMessageConsumer_0_8 consumer =
- new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);
+ new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);
assertEquals("Reject behaviour was was not as expected", RejectBehaviour.SERVER, consumer.getRejectBehaviour());
}
@@ -68,7 +68,7 @@ public class BasicMessageConsumer_0_8_Test extends TestCase
final TestAMQSession testSession = new TestAMQSession(conn);
final BasicMessageConsumer_0_8 consumer =
- new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);
+ new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);
assertEquals("Reject behaviour was was not as expected", RejectBehaviour.NORMAL, consumer.getRejectBehaviour());
}
@@ -94,7 +94,7 @@ public class BasicMessageConsumer_0_8_Test extends TestCase
TestAMQSession testSession = new TestAMQSession(conn);
BasicMessageConsumer_0_8 consumer =
- new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);
+ new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false);
assertEquals("Reject behaviour was was not as expected", RejectBehaviour.NORMAL, consumer.getRejectBehaviour());
}
diff --git a/java/client/src/test/java/org/apache/qpid/client/message/AMQPEncodedListMessageUnitTest.java b/java/client/src/test/java/org/apache/qpid/client/message/AMQPEncodedListMessageUnitTest.java
new file mode 100644
index 0000000000..e131ab3dd2
--- /dev/null
+++ b/java/client/src/test/java/org/apache/qpid/client/message/AMQPEncodedListMessageUnitTest.java
@@ -0,0 +1,153 @@
+/*
+ *
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.jms.MessageFormatException;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.transport.codec.BBEncoder;
+
+public class AMQPEncodedListMessageUnitTest extends QpidTestCase
+{
+
+ Map<String,String> _map = new HashMap<String,String>();
+ List<Object> _list = new ArrayList<Object>();
+ UUID _uuid = UUID.randomUUID();
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ _map.put("Key1","String1");
+ _map.put("Key2","String2");
+ _map.put("Key3","String3");
+
+ _list.add(1);
+ _list.add(2);
+ _list.add(3);
+ }
+
+ /**
+ * Test whether we accept the correct types while rejecting invalid types.
+ */
+ public void testAddObject() throws Exception
+ {
+ AMQPEncodedListMessage m = new AMQPEncodedListMessage(AMQMessageDelegateFactory.FACTORY_0_10);
+ m.add(true);
+ m.add((byte)256);
+ m.add(Short.MAX_VALUE);
+ m.add(Integer.MAX_VALUE);
+ m.add(Long.MAX_VALUE);
+ m.add(10.22);
+ m.add("Msg");
+ m.add("Msg".getBytes());
+ m.add(_list);
+ m.add(_map);
+ m.add(_uuid);
+
+ try
+ {
+ m.add(new Object());
+ fail("Validation for element type failed");
+ }
+ catch (MessageFormatException e)
+ {
+ }
+ }
+
+ public void testListBehaviorForIncommingMsg() throws Exception
+ {
+ BBEncoder encoder = new BBEncoder(1024);
+ encoder.writeList(_list);
+ AMQPEncodedListMessage m = new AMQPEncodedListMessage(new AMQMessageDelegate_0_10(),encoder.segment());
+
+ assertTrue("contains(Object) method did not return true as expected",m.contains(1));
+ assertFalse("contains(Object) method did not return false as expected",m.contains(5));
+ assertEquals("get(index) method returned incorrect value",((Integer)m.get(1)).intValue(),2);
+ assertEquals("indexOf(Object) method returned incorrect index",m.indexOf(2),1);
+ try
+ {
+ m.get(10);
+ }
+ catch (MessageFormatException e)
+ {
+ assertTrue("Incorrect exception type. Expected IndexOutOfBoundsException", e.getCause() instanceof IndexOutOfBoundsException);
+ }
+ }
+
+ public void testStreamMessageInterfaceForIncommingMsg() throws Exception
+ {
+ BBEncoder encoder = new BBEncoder(1024);
+ encoder.writeList(getList());
+ AMQPEncodedListMessage m = new AMQPEncodedListMessage(new AMQMessageDelegate_0_10(),encoder.segment());
+
+ assertEquals(true,m.readBoolean());
+ assertEquals((byte)256,m.readByte());
+ assertEquals(Short.MAX_VALUE,m.readShort());
+ assertEquals(Integer.MAX_VALUE,m.readInt());
+ assertEquals(Long.MAX_VALUE,m.readLong());
+ assertEquals(10.22,m.readDouble());
+ assertEquals("Msg",m.readString());
+ assertEquals(_list,(List)m.readObject());
+ assertEquals(_map,(Map)m.readObject());
+ assertEquals(_uuid,(UUID)m.readObject());
+ }
+
+ public void testMapMessageInterfaceForIncommingMsg() throws Exception
+ {
+ BBEncoder encoder = new BBEncoder(1024);
+ encoder.writeList(getList());
+ AMQPEncodedListMessage m = new AMQPEncodedListMessage(new AMQMessageDelegate_0_10(),encoder.segment());
+
+ assertEquals(true,m.getBoolean("0"));
+ assertEquals((byte)256,m.getByte("1"));
+ assertEquals(Short.MAX_VALUE,m.getShort("2"));
+ assertEquals(Integer.MAX_VALUE,m.getInt("3"));
+ assertEquals(Long.MAX_VALUE,m.getLong("4"));
+ assertEquals(10.22,m.getDouble("5"));
+ assertEquals("Msg",m.getString("6"));
+ assertEquals(_list,(List)m.getObject("7"));
+ assertEquals(_map,(Map)m.getObject("8"));
+ assertEquals(_uuid,(UUID)m.getObject("9"));
+ }
+
+ public List<Object> getList()
+ {
+ List<Object> myList = new ArrayList<Object>();
+ myList.add(true);
+ myList.add((byte)256);
+ myList.add(Short.MAX_VALUE);
+ myList.add(Integer.MAX_VALUE);
+ myList.add(Long.MAX_VALUE);
+ myList.add(10.22);
+ myList.add("Msg");
+ myList.add(_list);
+ myList.add(_map);
+ myList.add(_uuid);
+ return myList;
+ }
+}
diff --git a/java/client/src/test/java/org/apache/qpid/client/messaging/address/AddressHelperTest.java b/java/client/src/test/java/org/apache/qpid/client/messaging/address/AddressHelperTest.java
new file mode 100644
index 0000000000..7401168978
--- /dev/null
+++ b/java/client/src/test/java/org/apache/qpid/client/messaging/address/AddressHelperTest.java
@@ -0,0 +1,146 @@
+/*
+ *
+ * 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.messaging.address;
+
+import org.apache.qpid.client.AMQDestination;
+import org.apache.qpid.client.AMQDestination.AddressOption;
+import org.apache.qpid.client.AMQDestination.Binding;
+import org.apache.qpid.client.messaging.address.Link.Reliability;
+import org.apache.qpid.messaging.Address;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class AddressHelperTest extends QpidTestCase
+{
+ public void testAddressOptions() throws Exception
+ {
+ Address addr = Address.parse("queue/test;{create:sender, assert:always, delete:receiver, mode:browse}");
+ AddressHelper helper = new AddressHelper(addr);
+ assertEquals(AddressOption.SENDER,AddressOption.getOption(helper.getCreate()));
+ assertEquals(AddressOption.ALWAYS,AddressOption.getOption(helper.getAssert()));
+ assertEquals(AddressOption.RECEIVER,AddressOption.getOption(helper.getDelete()));
+ assertTrue("'mode' option wasn't read properly",helper.isBrowseOnly());
+ }
+
+ public void testNodeProperties() throws Exception
+ {
+ Address addr = Address.parse("my-queue;{" +
+ "node: " +
+ "{" +
+ "type: queue ," +
+ "durable: true ," +
+ "x-declare: " +
+ "{" +
+ "exclusive: true," +
+ "auto-delete: true," +
+ "alternate-exchange: 'amq.fanout'," +
+ "arguments: {" +
+ "'qpid.max_size': 1000," +
+ "'qpid.max_count': 100" +
+ "}" +
+ "}, " +
+ "x-bindings: [{exchange : 'amq.direct', queue:my-queue, key : test}, " +
+ "{exchange : 'amq.fanout', queue:my-queue}," +
+ "{exchange: 'amq.match', queue:my-queue, arguments: {x-match: any, dep: sales, loc: CA}}," +
+ "{exchange : 'amq.topic',queue:my-queue, key : 'a.#'}" +
+ "]" +
+
+ "}" +
+ "}");
+ AddressHelper helper = new AddressHelper(addr);
+ Node node = helper.getNode();
+ assertEquals("'type' property wasn't read properly",AMQDestination.QUEUE_TYPE,helper.getNodeType());
+ assertTrue("'durable' property wasn't read properly",node.isDurable());
+ assertTrue("'auto-delete' property wasn't read properly",node.isAutoDelete());
+ assertTrue("'exclusive' property wasn't read properly",node.isExclusive());
+ assertEquals("'alternate-exchange' property wasn't read properly","amq.fanout",node.getAlternateExchange());
+ assertEquals("'arguments' in 'x-declare' property wasn't read properly",2,node.getDeclareArgs().size());
+ assertEquals("'bindings' property wasn't read properly",4,node.getBindings().size());
+ for (Binding binding: node.getBindings())
+ {
+ assertTrue("property 'exchange' in bindings wasn't read properly",binding.getExchange().startsWith("amq."));
+ assertEquals("property 'queue' in bindings wasn't read properly","my-queue",binding.getQueue());
+ if (binding.getExchange().equals("amq.direct"))
+ {
+ assertEquals("'key' property in bindings wasn't read properly","test",binding.getBindingKey());
+ }
+ if (binding.getExchange().equals("amq.match"))
+ {
+ assertEquals("'arguments' property in bindings wasn't read properly",3,binding.getArgs().size());
+ }
+ }
+ }
+
+ public void testLinkProperties() throws Exception
+ {
+ Address addr = Address.parse("my-queue;{" +
+ "link: " +
+ "{" +
+ "name: my-queue ," +
+ "durable: true ," +
+ "reliability: at-least-once," +
+ "capacity: {source:10, target:15}," +
+ "x-declare: " +
+ "{" +
+ "exclusive: true," +
+ "auto-delete: true," +
+ "alternate-exchange: 'amq.fanout'," +
+ "arguments: {" +
+ "'qpid.max_size': 1000," +
+ "'qpid.max_count': 100" +
+ "}" +
+ "}, " +
+ "x-bindings: [{exchange : 'amq.direct', queue:my-queue, key : test}, " +
+ "{exchange : 'amq.fanout', queue:my-queue}," +
+ "{exchange: 'amq.match', queue:my-queue, arguments: {x-match: any, dep: sales, loc: CA}}," +
+ "{exchange : 'amq.topic',queue:my-queue, key : 'a.#'}" +
+ "]," +
+ "x-subscribes:{exclusive: true, arguments: {a:b,x:y}}" +
+ "}" +
+ "}");
+
+ AddressHelper helper = new AddressHelper(addr);
+ Link link = helper.getLink();
+ assertEquals("'name' property wasn't read properly","my-queue",link.getName());
+ assertTrue("'durable' property wasn't read properly",link.isDurable());
+ assertEquals("'reliability' property wasn't read properly",Reliability.AT_LEAST_ONCE,link.getReliability());
+ assertTrue("'auto-delete' property in 'x-declare' wasn't read properly",link.getSubscriptionQueue().isAutoDelete());
+ assertTrue("'exclusive' property in 'x-declare' wasn't read properly",link.getSubscriptionQueue().isExclusive());
+ assertEquals("'alternate-exchange' property in 'x-declare' wasn't read properly","amq.fanout",link.getSubscriptionQueue().getAlternateExchange());
+ assertEquals("'arguments' in 'x-declare' property wasn't read properly",2,link.getSubscriptionQueue().getDeclareArgs().size());
+ assertEquals("'bindings' property wasn't read properly",4,link.getBindings().size());
+ for (Binding binding: link.getBindings())
+ {
+ assertTrue("property 'exchange' in bindings wasn't read properly",binding.getExchange().startsWith("amq."));
+ assertEquals("property 'queue' in bindings wasn't read properly","my-queue",binding.getQueue());
+ if (binding.getExchange().equals("amq.direct"))
+ {
+ assertEquals("'key' property in bindings wasn't read properly","test",binding.getBindingKey());
+ }
+ if (binding.getExchange().equals("amq.match"))
+ {
+ assertEquals("'arguments' property in bindings wasn't read properly",3,binding.getArgs().size());
+ }
+ }
+ assertTrue("'exclusive' property in 'x-subscribe' wasn't read properly",link.getSubscription().isExclusive());
+ assertEquals("'arguments' in 'x-subscribe' property wasn't read properly",2,link.getSubscription().getArgs().size());
+ }
+
+}
diff --git a/java/client/src/test/java/org/apache/qpid/client/security/DynamicSaslRegistrarTest.java b/java/client/src/test/java/org/apache/qpid/client/security/DynamicSaslRegistrarTest.java
new file mode 100644
index 0000000000..4281984212
--- /dev/null
+++ b/java/client/src/test/java/org/apache/qpid/client/security/DynamicSaslRegistrarTest.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.client.security;
+
+import java.io.File;
+import java.security.Provider;
+import java.security.Security;
+
+import org.apache.qpid.client.security.DynamicSaslRegistrar.ProviderRegistrationResult;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+public class DynamicSaslRegistrarTest extends QpidTestCase
+{
+ private Provider _registeredProvider;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ //If the client provider is already registered, remove it for the duration of the test
+ _registeredProvider = DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME);
+ if (_registeredProvider != null)
+ {
+ Security.removeProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME);
+ }
+ }
+
+ public void tearDown() throws Exception
+ {
+ //Remove any provider left behind by the test.
+ Security.removeProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME);
+ try
+ {
+ //If the client provider was already registered before the test, restore it.
+ if (_registeredProvider != null)
+ {
+ Security.insertProviderAt(_registeredProvider, 1);
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ public void testRegisterDefaultProvider()
+ {
+ assertNull("Provider should not yet be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+
+ ProviderRegistrationResult firstRegistrationResult = DynamicSaslRegistrar.registerSaslProviders();
+ assertEquals("Unexpected registration result", ProviderRegistrationResult.SUCCEEDED, firstRegistrationResult);
+ assertNotNull("Providers should now be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+ }
+
+ public void testRegisterDefaultProviderTwice()
+ {
+ assertNull("Provider should not yet be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+
+ DynamicSaslRegistrar.registerSaslProviders();
+ assertNotNull("Providers should now be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+
+ ProviderRegistrationResult result = DynamicSaslRegistrar.registerSaslProviders();
+ assertEquals("Unexpected registration result when trying to re-register", ProviderRegistrationResult.EQUAL_ALREADY_REGISTERED, result);
+ assertNotNull("Providers should still be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+ }
+
+ @SuppressWarnings("serial")
+ public void testRegisterDefaultProviderWhenAnotherIsAlreadyPresentWithDifferentFactories()
+ {
+ assertNull("Provider should not be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+
+ //Add a test provider with the same name, version, info as the default client provider, but with different factory properties (none).
+ Provider testProvider = new Provider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME,
+ JCAProvider.QPID_CLIENT_SASL_PROVIDER_VERSION,
+ JCAProvider.QPID_CLIENT_SASL_PROVIDER_INFO){};
+ Security.addProvider(testProvider);
+ assertSame("Test provider should be registered", testProvider, DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+
+ //Try to register the default provider now that another with the same name etc (but different factories)
+ //is already registered, expect it not to be registered as a result.
+ ProviderRegistrationResult result = DynamicSaslRegistrar.registerSaslProviders();
+ assertEquals("Unexpected registration result", ProviderRegistrationResult.DIFFERENT_ALREADY_REGISTERED, result);
+
+ //Verify the test provider is still registered
+ assertSame("Test provider should still be registered", testProvider, DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+ }
+
+ public void testRegisterWithNoFactories()
+ {
+ File emptyTempFile = TestFileUtils.createTempFile(this);
+
+ assertNull("Provider should not be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+
+ //Adjust the location of the properties file to point at an empty file, so no factories are found to register.
+ setTestSystemProperty("amq.dynamicsaslregistrar.properties", emptyTempFile.getPath());
+
+ //Try to register the default provider, expect it it not to be registered because there were no factories.
+ ProviderRegistrationResult result = DynamicSaslRegistrar.registerSaslProviders();
+ assertEquals("Unexpected registration result", ProviderRegistrationResult.NO_SASL_FACTORIES, result);
+
+ assertNull("Provider should not be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+ }
+
+ public void testRegisterWithMissingFileGetsDefault()
+ {
+ //Create a temp file and then delete it, such that we get a path which doesn't exist
+ File tempFile = TestFileUtils.createTempFile(this);
+ assertTrue("Failed to delete file", tempFile.delete());
+
+ assertNull("Provider should not be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+
+ //Adjust the location of the properties file to point at non-existent file.
+ setTestSystemProperty("amq.dynamicsaslregistrar.properties", tempFile.getPath());
+
+ //Try to register the default provider, expect it to fall back to the default in the jar and succeed.
+ ProviderRegistrationResult result = DynamicSaslRegistrar.registerSaslProviders();
+ assertEquals("Unexpected registration result", ProviderRegistrationResult.SUCCEEDED, result);
+
+ assertNotNull("Provider should be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME));
+ }
+}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java
index 412c458247..1e9e5b00a5 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java
@@ -120,6 +120,48 @@ public class BrokerDetailsTest extends TestCase
{
assertTrue(urise.getReason().equals("Illegal character in port number"));
}
+ }
+
+ public void testToStringMasksKeyStorePassword() throws Exception
+ {
+ String url = "tcp://localhost:5672?key_store_password='password'";
+ BrokerDetails details = new AMQBrokerDetails(url);
+
+ String expectedToString = "tcp://localhost:5672?key_store_password='********'";
+ String actualToString = details.toString();
+
+ assertEquals("Unexpected toString", expectedToString, actualToString);
+ }
+
+ public void testToStringMasksTrustStorePassword() throws Exception
+ {
+ String url = "tcp://localhost:5672?trust_store_password='password'";
+ BrokerDetails details = new AMQBrokerDetails(url);
+
+ String expectedToString = "tcp://localhost:5672?trust_store_password='********'";
+ String actualToString = details.toString();
+
+ assertEquals("Unexpected toString", expectedToString, actualToString);
+ }
+
+ public void testDefaultSsl() throws URLSyntaxException
+ {
+ String brokerURL = "tcp://localhost:5672";
+ AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL);
+
+ assertNull("default value should be null", broker.getProperty(BrokerDetails.OPTIONS_SSL));
+ }
+
+ public void testOverridingSsl() throws URLSyntaxException
+ {
+ String brokerURL = "tcp://localhost:5672?ssl='true'";
+ AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL);
+
+ assertTrue("value should be true", Boolean.valueOf(broker.getProperty(BrokerDetails.OPTIONS_SSL)));
+
+ brokerURL = "tcp://localhost:5672?ssl='false''&maxprefetch='1'";
+ broker = new AMQBrokerDetails(brokerURL);
+ assertFalse("value should be false", Boolean.valueOf(broker.getProperty(BrokerDetails.OPTIONS_SSL)));
}
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
index 392ef1f29b..8c193622e3 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
@@ -30,7 +30,6 @@ import org.apache.qpid.url.URLSyntaxException;
public class ConnectionURLTest extends TestCase
{
-
public void testFailoverURL() throws URLSyntaxException
{
String url = "amqp://ritchiem:bob@/test?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin?cyclecount='100''";
@@ -252,55 +251,47 @@ public class ConnectionURLTest extends TestCase
assertTrue(service.getPort() == 5672);
}
- public void testSingleTransportDefaultedBrokerWithIPandPort() throws URLSyntaxException
+ public void testConnectionURLOptionToStringMasksPassword() throws URLSyntaxException
{
- String url = "amqp://guest:guest@/test?brokerlist='127.0.0.1:1234'";
+ String url = "amqp://guest:guest@client/localhost?brokerlist='tcp://localhost:1234'";
+ ConnectionURL connectionurl = new AMQConnectionURL(url);
+
+ String expectedToString = "amqp://guest:********@client/localhost?brokerlist='tcp://localhost:1234'";
+ String actualToString = connectionurl.toString();
+ assertEquals("Unexpected toString form", expectedToString, actualToString);
+ }
+
+ public void testConnectionURLOptionToStringMasksSslTrustStorePassword() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@client/vhost?brokerlist='tcp://host:1234?trust_store_password='truststorepassword''";
+ ConnectionURL connectionurl = new AMQConnectionURL(url);
-// ConnectionURL connectionurl = new AMQConnectionURL(url);
-//
-// assertTrue(connectionurl.getFailoverMethod() == null);
-// assertTrue(connectionurl.getUsername().equals("guest"));
-// assertTrue(connectionurl.getPassword().equals("guest"));
-// assertTrue(connectionurl.getVirtualHost().equals("/temp"));
-//
-//
-// assertTrue(connectionurl.getBrokerCount() == 1);
-//
-// BrokerDetails service = connectionurl.getBrokerDetails(0);
-//
-// assertTrue(service.getTransport().equals("tcp"));
-//
-// assertTrue(service.getHost().equals("127.0.0.1"));
-// assertTrue(service.getPort() == 1234);
+ String expectedToString = "amqp://guest:********@client/vhost?brokerlist='tcp://host:1234?trust_store_password='********''";
+ String actualToString = connectionurl.toString();
+ assertEquals("Unexpected toString form", expectedToString, actualToString);
+ }
+
+ public void testConnectionURLOptionToStringMasksSslKeyStorePassword() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@client/vhost?brokerlist='tcp://host:1234?key_store_password='keystorepassword1';tcp://host:1235?key_store_password='keystorepassword2''";
+ ConnectionURL connectionurl = new AMQConnectionURL(url);
+
+ String expectedToString = "amqp://guest:********@client/vhost?brokerlist='tcp://host:1234?key_store_password='********';tcp://host:1235?key_store_password='********''";
+ String actualToString = connectionurl.toString();
+ assertEquals("Unexpected toString form", expectedToString, actualToString);
}
/**
* Test for QPID-3662 to ensure the {@code toString()} representation is correct.
*/
- public void testConnectionURLOptionToString() throws URLSyntaxException
+ public void testConnectionURLOptionToStringWithMaxPreftech() throws URLSyntaxException
{
String url = "amqp://guest:guest@client/localhost?maxprefetch='1'&brokerlist='tcp://localhost:1234?tcp_nodelay='true''";
ConnectionURL connectionurl = new AMQConnectionURL(url);
- assertNull(connectionurl.getFailoverMethod());
- assertEquals("guest", connectionurl.getUsername());
- assertEquals("guest", connectionurl.getPassword());
- assertEquals("client", connectionurl.getClientName());
- assertEquals("/localhost", connectionurl.getVirtualHost());
- assertEquals("1", connectionurl.getOption("maxprefetch"));
- assertTrue(connectionurl.getBrokerCount() == 1);
-
- BrokerDetails service = connectionurl.getBrokerDetails(0);
- assertTrue(service.getTransport().equals("tcp"));
- assertTrue(service.getHost().equals("localhost"));
- assertTrue(service.getPort() == 1234);
- assertTrue(service.getProperties().containsKey("tcp_nodelay"));
- assertEquals("true", service.getProperties().get("tcp_nodelay"));
-
- String nopasswd = "amqp://guest:********@client/localhost?maxprefetch='1'&brokerlist='tcp://localhost:1234?tcp_nodelay='true''";
- String tostring = connectionurl.toString();
- assertEquals(tostring.indexOf("maxprefetch"), tostring.lastIndexOf("maxprefetch"));
- assertEquals(nopasswd, tostring);
+ String expectedToString = "amqp://guest:********@client/localhost?maxprefetch='1'&brokerlist='tcp://localhost:1234?tcp_nodelay='true''";
+ String actualToString = connectionurl.toString();
+ assertEquals("Unexpected toString form", expectedToString, actualToString);
}
public void testSingleTransportMultiOptionURL() throws URLSyntaxException
@@ -572,9 +563,64 @@ public class ConnectionURLTest extends TestCase
connectionurl.getOption(ConnectionURL.OPTIONS_REJECT_BEHAVIOUR));
}
- public static junit.framework.Test suite()
+ /**
+ * Verify that when the ssl option is not specified, asking for the option returns null,
+ * such that this can later be used to verify it wasnt specified.
+ */
+ public void testDefaultSsl() throws URLSyntaxException
{
- return new junit.framework.TestSuite(ConnectionURLTest.class);
+ String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&foo='bar'";
+ ConnectionURL connectionURL = new AMQConnectionURL(url);
+
+ assertNull("default ssl value should be null", connectionURL.getOption(ConnectionURL.OPTIONS_SSL));
+ }
+
+ /**
+ * Verify that when the ssl option is specified, asking for the option returns the value,
+ * such that this can later be used to verify what value it was specified as.
+ */
+ public void testOverridingSsl() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&ssl='true'";
+ ConnectionURL connectionURL = new AMQConnectionURL(url);
+
+ assertTrue("value should be true", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_SSL)));
+
+ url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&ssl='false'";
+ connectionURL = new AMQConnectionURL(url);
+
+ assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_SSL)));
+ }
+
+ /**
+ * Verify that when the {@value ConnectionURL#OPTIONS_VERIFY_QUEUE_ON_SEND} option is not
+ * specified, asking for the option returns null, such that this can later be used to
+ * verify it wasn't specified.
+ */
+ public void testDefaultVerifyQueueOnSend() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&foo='bar'";
+ ConnectionURL connectionURL = new AMQConnectionURL(url);
+
+ assertNull("default ssl value should be null", connectionURL.getOption(ConnectionURL.OPTIONS_SSL));
+ }
+
+ /**
+ * Verify that when the {@value ConnectionURL#OPTIONS_VERIFY_QUEUE_ON_SEND} option is
+ * specified, asking for the option returns the value, such that this can later be used
+ * to verify what value it was specified as.
+ */
+ public void testOverridingVerifyQueueOnSend() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&verifyQueueOnSend='true'";
+ ConnectionURL connectionURL = new AMQConnectionURL(url);
+
+ assertTrue("value should be true", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND)));
+
+ url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&verifyQueueOnSend='false'";
+ connectionURL = new AMQConnectionURL(url);
+
+ assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND)));
}
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java
index 9addb0ee71..8f578e6a2f 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java
@@ -193,6 +193,126 @@ public class DestinationURLTest extends TestCase
assertTrue(dest.getQueueName().equals("test:testQueueD"));
}
+ public void testExchangeOptionsNotPresent() throws URISyntaxException
+ {
+ String url = "exchangeClass://exchangeName/Destination/Queue";
+
+ AMQBindingURL burl = new AMQBindingURL(url);
+
+ assertTrue(url.equals(burl.toString()));
+
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
+
+ class MyTestAMQDestination extends AMQDestination
+ {
+ public MyTestAMQDestination(BindingURL url)
+ {
+ super(url);
+ }
+ public boolean isNameRequired()
+ {
+ return false;
+ }
+ };
+
+ AMQDestination dest = new MyTestAMQDestination(burl);
+ assertFalse(dest.isExchangeAutoDelete());
+ assertFalse(dest.isExchangeDurable());
+ assertFalse(dest.isExchangeInternal());
+ }
+
+ public void testExchangeAutoDeleteOptionPresent() throws URISyntaxException
+ {
+ String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_AUTODELETE + "='true'";
+
+ AMQBindingURL burl = new AMQBindingURL(url);
+
+ assertTrue(url.equals(burl.toString()));
+
+ assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
+
+ class MyTestAMQDestination extends AMQDestination
+ {
+ public MyTestAMQDestination(BindingURL url)
+ {
+ super(url);
+ }
+ public boolean isNameRequired()
+ {
+ return false;
+ }
+ };
+
+ AMQDestination dest = new MyTestAMQDestination(burl);
+ assertTrue(dest.isExchangeAutoDelete());
+ assertFalse(dest.isExchangeDurable());
+ assertFalse(dest.isExchangeInternal());
+ }
+
+ public void testExchangeDurableOptionPresent() throws URISyntaxException
+ {
+ String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_DURABLE + "='true'";
+
+ AMQBindingURL burl = new AMQBindingURL(url);
+
+ assertTrue(url.equals(burl.toString()));
+
+ assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
+
+ class MyTestAMQDestination extends AMQDestination
+ {
+ public MyTestAMQDestination(BindingURL url)
+ {
+ super(url);
+ }
+ public boolean isNameRequired()
+ {
+ return false;
+ }
+ };
+
+ AMQDestination dest = new MyTestAMQDestination(burl);
+ assertTrue(dest.isExchangeDurable());
+ assertFalse(dest.isExchangeAutoDelete());
+ assertFalse(dest.isExchangeInternal());
+ }
+
+ public void testExchangeInternalOptionPresent() throws URISyntaxException
+ {
+ String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_INTERNAL + "='true'";
+
+ AMQBindingURL burl = new AMQBindingURL(url);
+
+ assertTrue(url.equals(burl.toString()));
+
+ assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+
+ class MyTestAMQDestination extends AMQDestination
+ {
+ public MyTestAMQDestination(BindingURL url)
+ {
+ super(url);
+ }
+ public boolean isNameRequired()
+ {
+ return false;
+ }
+ };
+
+ AMQDestination dest = new MyTestAMQDestination(burl);
+ assertTrue(dest.isExchangeInternal());
+ assertFalse(dest.isExchangeDurable());
+ assertFalse(dest.isExchangeAutoDelete());
+ }
+
public void testRejectBehaviourPresent() throws URISyntaxException
{
String url = "exchangeClass://exchangeName/Destination/Queue?rejectbehaviour='server'";
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java b/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
index f199961b6f..4ad9069ba0 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
@@ -124,7 +124,7 @@ public class TestAMQSession extends AMQSession_0_8
return false;
}
- public void sendConsume(BasicMessageConsumer_0_8 consumer, AMQShortString queueName, AMQProtocolHandler protocolHandler, boolean nowait, int tag) throws AMQException, FailoverException
+ public void sendConsume(BasicMessageConsumer_0_8 consumer, AMQShortString queueName, boolean nowait, int tag) throws AMQException, FailoverException
{
}
@@ -139,13 +139,13 @@ public class TestAMQSession extends AMQSession_0_8
return null;
}
- public void sendExchangeDeclare(AMQShortString name, AMQShortString type, AMQProtocolHandler protocolHandler, boolean nowait) throws AMQException, FailoverException
+ public void sendExchangeDeclare(AMQShortString name, AMQShortString type, boolean nowait, boolean durable, boolean autoDelete, boolean internal) throws AMQException, FailoverException
{
}
public void sendQueueDeclare(AMQDestination amqd, AMQProtocolHandler protocolHandler,
- boolean nowait, boolean passive) throws AMQException, FailoverException
+ boolean passive) throws AMQException, FailoverException
{
}
@@ -189,14 +189,6 @@ public class TestAMQSession extends AMQSession_0_8
{
}
- public void handleAddressBasedDestination(AMQDestination dest,
- boolean isConsumer,
- boolean noWait) throws AMQException
- {
- throw new UnsupportedOperationException("The new addressing based sytanx is "
- + "not supported for AMQP 0-8/0-9 versions");
- }
-
@Override
protected void flushAcknowledgments()
{
diff --git a/java/common.xml b/java/common.xml
index 2b61ef08c2..ce5693fd28 100644
--- a/java/common.xml
+++ b/java/common.xml
@@ -23,7 +23,10 @@
<dirname property="project.root" file="${ant.file.common}"/>
<property name="project.name" value="qpid"/>
- <property name="project.version" value="0.19"/>
+ <!-- Version used for standard build output -->
+ <property name="project.version" value="0.21"/>
+ <!-- The release version used for maven output. SNAPSHOT added via maven.version.suffix -->
+ <property name="project.version.maven" value="0.22"/>
<property name="project.url" value="http://qpid.apache.org"/>
<property name="project.groupid" value="org.apache.qpid"/>
<property name="project.namever" value="${project.name}-${project.version}"/>
@@ -42,7 +45,7 @@
<property name="build.report" location="${build}/report"/>
<property name="build.release" location="${build}/release"/>
<property name="build.release.prepare" location="${build.release}/prepare"/>
- <property name="build.plugins" location="${build}/lib/plugins"/>
+ <property name="build.scratch.broker.plugins.lib" location="${build.scratch}/broker-plugins/lib"/>
<property name="build.coverage.report" location="${build}/coverage/report"/>
<property name="build.coverage.src" location="${build}/coverage/src"/>
<property name="build.findbugs" location="${build}/findbugs"/>
@@ -93,6 +96,10 @@
<property name="nexus.host" value="repository.apache.org"/>
<property name="nexus.upload.url" value="https://${nexus.host}/service/local/staging/deploy/maven2"/>
+ <!-- properties for deplying snapshot artifacts -->
+ <property name="maven.snapshots.repo.id" value="apache.snapshots.https"/>
+ <property name="maven.snapshots.repo.url" value="https://${nexus.host}/content/repositories/snapshots"/>
+
<!-- properties for downloading ivy, and then our dependencies -->
<property name="ivy.jar.dir" value="${project.root}/lib/ivy" />
<property name="ivy.install.version" value="2.2.0" />
diff --git a/java/common/bin/qpid-run b/java/common/bin/qpid-run
index 1e373340ce..a10766b37a 100755
--- a/java/common/bin/qpid-run
+++ b/java/common/bin/qpid-run
@@ -88,10 +88,10 @@ SYSTEM_PROPS[${#SYSTEM_PROPS[@]}]="-DQPID_WORK=$QPID_WORK"
if [ -n "$QPID_LOG_PREFIX" ]; then
if [ "X$QPID_LOG_PREFIX" = "XPID" ]; then
log $INFO Using pid in qpid log name prefix
- LOG_PREFIX=" -Dlogprefix=$$"
+ LOG_PREFIX="-Dlogprefix=$$"
else
log $INFO Using qpid logprefix property
- LOG_PREFIX=" -Dlogprefix=$QPID_LOG_PREFIX"
+ LOG_PREFIX="-Dlogprefix=$QPID_LOG_PREFIX"
fi
SYSTEM_PROPS[${#SYSTEM_PROPS[@]}]="${LOG_PREFIX}"
fi
@@ -99,10 +99,10 @@ fi
if [ -n "$QPID_LOG_SUFFIX" ]; then
if [ "X$QPID_LOG_SUFFIX" = "XPID" ]; then
log $INFO Using pid in qpid log name suffix
- LOG_SUFFIX=" -Dlogsuffix=$$"
+ LOG_SUFFIX="-Dlogsuffix=$$"
else
log $INFO Using qpig logsuffix property
- LOG_SUFFIX=" -Dlogsuffix=$QPID_LOG_SUFFIX"
+ LOG_SUFFIX="-Dlogsuffix=$QPID_LOG_SUFFIX"
fi
SYSTEM_PROPS[${#SYSTEM_PROPS[@]}]="${LOG_SUFFIX}"
fi
diff --git a/java/common/build.xml b/java/common/build.xml
index 9caf93c026..e599c840db 100644
--- a/java/common/build.xml
+++ b/java/common/build.xml
@@ -53,7 +53,15 @@
</target>
<target name="compile_gentools">
- <ant dir="${gentools.home}" />
+ <mkdir dir="${gentools.build}/classes"/>
+ <javac srcdir="${gentools.home}/src" destdir="${gentools.build}/classes" source="${java.source}" target="${java.target}" fork="true" includeantruntime="false">
+ <classpath>
+ <fileset dir="${project.root}">
+ <include name="${velocity.jar}"/>
+ <include name="${velocity-dep.jar}"/>
+ </fileset>
+ </classpath>
+ </javac>
</target>
<target name="check_gentool_deps">
@@ -64,15 +72,12 @@
<target name="gentools" depends="compile_gentools,check_gentool_deps" unless="gentools.notRequired">
<mkdir dir="${framing.generated.dir}"/>
- <java classname="org.apache.qpid.gentools.Main" fork="true" dir="${gentools.home}/src" failonerror="true">
+ <java classname="org.apache.qpid.gentools.Main" fork="true" dir="${gentools.build}/classes" failonerror="true">
<arg line='-j -o "${framing.generated.dir}" -t "${project.root}/common/templates" ${xml.spec.list}'/>
<classpath>
- <pathelement path="${gentools.home}/src" />
- <fileset dir="${gentools.home}/lib">
- <include name="**/*.jar"/>
- </fileset>
- <pathelement path="${gentools.home}/lib/velocity-1.4.jar" />
- <pathelement path="${gentools.home}/lib/velocity-dep-1.4.jar" />
+ <pathelement path="${gentools.build}/classes" />
+ <pathelement path="${project.root}/${velocity.jar}" />
+ <pathelement path="${project.root}/${velocity-dep.jar}" />
</classpath>
</java>
<touch file="${gentools.timestamp}" />
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpClass.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpClass.java
index 26195da2e3..26195da2e3 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpClass.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpClass.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java
index a27a50d07e..a27a50d07e 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpClassMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpConstant.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpConstant.java
index df5bc6c362..df5bc6c362 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpConstant.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpConstant.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java
index ab8b8be61e..ab8b8be61e 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpConstantSet.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpDomain.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpDomain.java
index ba8552a6a6..ba8552a6a6 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpDomain.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpDomain.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java
index 0cd9d214bd..0cd9d214bd 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpDomainMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java
index e39550b96f..e39550b96f 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpDomainVersionMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpField.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpField.java
index 7c721cf913..7c721cf913 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpField.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpField.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java
index 0bb5e03a61..0bb5e03a61 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpFieldMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java
index 5993a1b715..5993a1b715 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpFlagMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpMethod.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
index 4ec39b209e..4ec39b209e 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java
index d98dab4a39..d98dab4a39 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpMethodMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpModel.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpModel.java
index 45f0adb18d..45f0adb18d 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpModel.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpModel.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java
index 0633eff1e1..0633eff1e1 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpOrdinalFieldMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java
index fede88631a..fede88631a 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpOrdinalVersionMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java
index 10978d0e4a..10978d0e4a 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpOverloadedParameterMap.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpParseException.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpParseException.java
index 3f3d4611fc..3f3d4611fc 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpParseException.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpParseException.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java
index 1ac09ea453..1ac09ea453 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpTemplateException.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java
index 127a8835b0..127a8835b0 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpTypeMappingException.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpVersion.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpVersion.java
index dbeef1b895..dbeef1b895 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpVersion.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpVersion.java
diff --git a/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java b/java/common/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java
index 6419e23a1e..6419e23a1e 100644
--- a/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/AmqpVersionSet.java
diff --git a/gentools/src/org/apache/qpid/gentools/BitFieldGenerateMethod.java b/java/common/gentools/src/org/apache/qpid/gentools/BitFieldGenerateMethod.java
index d85510ee98..d85510ee98 100644
--- a/gentools/src/org/apache/qpid/gentools/BitFieldGenerateMethod.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/BitFieldGenerateMethod.java
diff --git a/gentools/src/org/apache/qpid/gentools/CommandGenerateMethod.java b/java/common/gentools/src/org/apache/qpid/gentools/CommandGenerateMethod.java
index 641f50c3f8..641f50c3f8 100644
--- a/gentools/src/org/apache/qpid/gentools/CommandGenerateMethod.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/CommandGenerateMethod.java
diff --git a/gentools/src/org/apache/qpid/gentools/ConsolidatedField.java b/java/common/gentools/src/org/apache/qpid/gentools/ConsolidatedField.java
index 9ab7eb178b..9ab7eb178b 100644
--- a/gentools/src/org/apache/qpid/gentools/ConsolidatedField.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/ConsolidatedField.java
diff --git a/gentools/src/org/apache/qpid/gentools/CppGenerator.java b/java/common/gentools/src/org/apache/qpid/gentools/CppGenerator.java
index 4f58cba34e..4f58cba34e 100644
--- a/gentools/src/org/apache/qpid/gentools/CppGenerator.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/CppGenerator.java
diff --git a/gentools/src/org/apache/qpid/gentools/DotnetGenerator.java b/java/common/gentools/src/org/apache/qpid/gentools/DotnetGenerator.java
index 9fc81dd428..9fc81dd428 100644
--- a/gentools/src/org/apache/qpid/gentools/DotnetGenerator.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/DotnetGenerator.java
diff --git a/gentools/src/org/apache/qpid/gentools/GenerateMethod.java b/java/common/gentools/src/org/apache/qpid/gentools/GenerateMethod.java
index 8b0bb99b41..8b0bb99b41 100644
--- a/gentools/src/org/apache/qpid/gentools/GenerateMethod.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/GenerateMethod.java
diff --git a/gentools/src/org/apache/qpid/gentools/Generator.java b/java/common/gentools/src/org/apache/qpid/gentools/Generator.java
index 5d6e7be527..5d6e7be527 100644
--- a/gentools/src/org/apache/qpid/gentools/Generator.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/Generator.java
diff --git a/gentools/src/org/apache/qpid/gentools/JavaGenerator.java b/java/common/gentools/src/org/apache/qpid/gentools/JavaGenerator.java
index 7730fca1bd..7730fca1bd 100644
--- a/gentools/src/org/apache/qpid/gentools/JavaGenerator.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/JavaGenerator.java
diff --git a/gentools/src/org/apache/qpid/gentools/LanguageConverter.java b/java/common/gentools/src/org/apache/qpid/gentools/LanguageConverter.java
index 5e692d86e7..5e692d86e7 100644
--- a/gentools/src/org/apache/qpid/gentools/LanguageConverter.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/LanguageConverter.java
diff --git a/gentools/src/org/apache/qpid/gentools/Main.java b/java/common/gentools/src/org/apache/qpid/gentools/Main.java
index c0584f7ca7..c0584f7ca7 100644
--- a/gentools/src/org/apache/qpid/gentools/Main.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/Main.java
diff --git a/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java b/java/common/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java
index ffeefed900..ffeefed900 100644
--- a/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/MangledGenerateMethod.java
diff --git a/gentools/src/org/apache/qpid/gentools/NodeAware.java b/java/common/gentools/src/org/apache/qpid/gentools/NodeAware.java
index f832da75ad..f832da75ad 100644
--- a/gentools/src/org/apache/qpid/gentools/NodeAware.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/NodeAware.java
diff --git a/gentools/src/org/apache/qpid/gentools/Printable.java b/java/common/gentools/src/org/apache/qpid/gentools/Printable.java
index aa13df7b68..aa13df7b68 100644
--- a/gentools/src/org/apache/qpid/gentools/Printable.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/Printable.java
diff --git a/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java b/java/common/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java
index 8e1af1c551..8e1af1c551 100644
--- a/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/SingleVersionClass.java
diff --git a/gentools/src/org/apache/qpid/gentools/SingleVersionField.java b/java/common/gentools/src/org/apache/qpid/gentools/SingleVersionField.java
index b795663d15..b795663d15 100644
--- a/gentools/src/org/apache/qpid/gentools/SingleVersionField.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/SingleVersionField.java
diff --git a/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java b/java/common/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java
index 59a6d9e28a..59a6d9e28a 100644
--- a/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/SingleVersionMethod.java
diff --git a/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java b/java/common/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java
index 22b416e45a..22b416e45a 100644
--- a/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/SingleVersionModel.java
diff --git a/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java b/java/common/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java
index 39ce666288..39ce666288 100644
--- a/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/TargetDirectoryException.java
diff --git a/gentools/src/org/apache/qpid/gentools/Utils.java b/java/common/gentools/src/org/apache/qpid/gentools/Utils.java
index 1cedaeea12..1cedaeea12 100644
--- a/gentools/src/org/apache/qpid/gentools/Utils.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/Utils.java
diff --git a/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java b/java/common/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java
index a9cdd56e88..a9cdd56e88 100644
--- a/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java
+++ b/java/common/gentools/src/org/apache/qpid/gentools/VersionConsistencyCheck.java
diff --git a/java/common/protocol-version.xml b/java/common/protocol-version.xml
deleted file mode 100644
index 5435a0a582..0000000000
--- a/java/common/protocol-version.xml
+++ /dev/null
@@ -1,70 +0,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="Qpid Common Protocol Versions" default="generate">
- <property name="topDirectoryLocation" location=".." />
- <property name="project.build.directory" location="target" />
- <property name="gentools.home" location="${topDirectoryLocation}/../gentools" />
- <property name="generated.path" location="${project.build.directory}/generated-sources/gentools" />
- <property name="generated.package" value="org/apache/qpid/framing" />
- <property name="generated.dir" location="${generated.path}/${generated.package}" />
- <property name="generated.timestamp" location="${generated.dir}/timestamp" />
- <property name="xml.spec.dir" location="${topDirectoryLocation}/../specs" />
- <property name="xml.spec.deps" value="amqp.0-8.xml amqp.0-9.xml amqp0-9-1.stripped.xml" />
- <property name="xml.spec.list" value="${xml.spec.dir}/amqp.0-8.xml ${xml.spec.dir}/amqp.0-9.xml ${xml.spec.dir}/amqp0-9-1.stripped.xml" />
- <property name="template.dir" value="${topDirectoryLocation}/common/templates" />
-
-
- <!--<target name="generate" depends="compile_generator,check_generate_deps" unless="generation.notRequired">-->
- <target name="generate" depends="compile_generator" unless="generation.notRequired">
- <mkdir dir="${generated.dir}"/>
- <java classname="org.apache.qpid.gentools.Main" fork="true" dir="${gentools.home}/src" failonerror="true">
- <arg line="-j -o ${generated.dir} -t ${template.dir} ${xml.spec.list}" />
- <classpath>
- <pathelement path="${gentools.home}/src" />
- <fileset dir="${gentools.home}/lib">
- <include name="**/*.jar"/>
- </fileset>
- <pathelement path="${gentools.home}/lib/velocity-1.4.jar" />
- <pathelement path="${gentools.home}/lib/velocity-dep-1.4.jar" />
- </classpath>
- </java>
- <touch file="${generated.timestamp}" />
- </target>
-
- <target name="check_generate_deps">
- <uptodate property="generation.notRequired" targetfile="${generated.timestamp}">
- <srcfiles dir="${xml.spec.dir}" includes="${xml.spec.deps}" />
- <srcfiles dir="${template.dir}" includes="**/*.vm **/*.tmpl" />
- </uptodate>
- </target>
-
- <target name="compile_generator">
- <ant dir="${gentools.home}" />
- </target>
-
- <target name="precompile" depends="generate"/>
-
- <target name="clean">
- <delete dir="${generated.path}" />
- </target>
-
-</project>
-
diff --git a/java/common/src/main/java/common.bnd b/java/common/src/main/java/common.bnd
index b34f8deacc..84350fdc75 100755
--- a/java/common/src/main/java/common.bnd
+++ b/java/common/src/main/java/common.bnd
@@ -17,7 +17,7 @@
# under the License.
#
-ver: 0.19.0
+ver: 0.21.0
Bundle-SymbolicName: qpid-common
Bundle-Version: ${ver}
diff --git a/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java b/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
index 5268ce9bc2..7aa280ce02 100644
--- a/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
+++ b/java/common/src/main/java/org/apache/qpid/configuration/ClientProperties.java
@@ -87,6 +87,8 @@ public class ClientProperties
public static final String USE_LEGACY_MAP_MESSAGE_FORMAT = "qpid.use_legacy_map_message";
+ public static final String USE_LEGACY_STREAM_MESSAGE_FORMAT = "qpid.use_legacy_stream_message";
+
public static final String AMQP_VERSION = "qpid.amqp.version";
public static final String QPID_VERIFY_CLIENT_ID = "qpid.verify_client_id";
@@ -190,6 +192,19 @@ public class ClientProperties
*/
public static final long DEFAULT_FLOW_CONTROL_WAIT_NOTIFY_PERIOD = 5000L;
+ /**
+ * System property to control whether the client will declare queues during
+ * consumer creation when using BindingURLs.
+ */
+ public static final String QPID_DECLARE_QUEUES_PROP_NAME = "qpid.declare_queues";
+
+ /**
+ * System property to control whether the client will declare exchanges during
+ * producer/consumer creation when using BindingURLs.
+ */
+ public static final String QPID_DECLARE_EXCHANGES_PROP_NAME = "qpid.declare_exchanges";
+ public static final String VERIFY_QUEUE_ON_SEND = "qpid.verify_queue_on_send";
+
private ClientProperties()
{
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java b/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java
index fdc71e31f9..1381390640 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQShortString.java
@@ -110,7 +110,7 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
{
return new LinkedHashMap<AMQShortString, AMQShortString>()
{
-
+ @Override
protected boolean removeEldestEntry(Map.Entry<AMQShortString, AMQShortString> eldest)
{
return size() > LOCAL_INTERN_CACHE_SIZE;
@@ -845,22 +845,15 @@ public final class AMQShortString implements CharSequence, Comparable<AMQShortSt
return internString;
}
-
- public static void main(String args[])
+ public static String toString(AMQShortString amqShortString)
{
- AMQShortString s = new AMQShortString("a.b.c.d.e.f.g.h.i.j.k");
- AMQShortString s2 = s.substring(2, 7);
-
- AMQShortStringTokenizer t = s2.tokenize((byte) '.');
- while(t.hasMoreTokens())
- {
- System.err.println(t.nextToken());
- }
+ return amqShortString == null ? null : amqShortString.asString();
}
- public static String toString(AMQShortString amqShortString)
+ public static void clearLocalCache()
{
- return amqShortString == null ? null : amqShortString.asString();
+ _localInternMap.remove();
+ _localStringMap.remove();
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
index 57f2c638a2..b9ed1b2154 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
@@ -855,6 +855,7 @@ public class FieldTable
public void addAll(FieldTable fieldTable)
{
initMapIfNecessary();
+ fieldTable.initMapIfNecessary();
if (fieldTable._properties != null)
{
_encodedForm = null;
diff --git a/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java b/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java
index 15c144b0eb..59a1b6c5b0 100644
--- a/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java
+++ b/java/common/src/main/java/org/apache/qpid/properties/ConnectionStartProperties.java
@@ -49,7 +49,11 @@ public class ConnectionStartProperties
public static final String SESSION_FLOW = "qpid.session_flow";
- public static int getPID()
+ public static int _pid;
+
+ public static final String _platformInfo;
+
+ static
{
RuntimeMXBean rtb = ManagementFactory.getRuntimeMXBean();
String processName = rtb.getName();
@@ -57,23 +61,20 @@ public class ConnectionStartProperties
{
try
{
- return Integer.parseInt(processName.substring(0,processName.indexOf('@')));
+ _pid = Integer.parseInt(processName.substring(0,processName.indexOf('@')));
}
catch(Exception e)
{
LOGGER.warn("Unable to get the PID due to error",e);
- return -1;
+ _pid = -1;
}
}
else
{
LOGGER.warn("Unable to get the PID due to unsupported format : " + processName);
- return -1;
+ _pid = -1;
}
- }
- public static String getPlatformInfo()
- {
StringBuilder fullSystemInfo = new StringBuilder(System.getProperty("java.runtime.name"));
fullSystemInfo.append(", ");
fullSystemInfo.append(System.getProperty("java.runtime.version"));
@@ -88,6 +89,16 @@ public class ConnectionStartProperties
fullSystemInfo.append(", ");
fullSystemInfo.append(System.getProperty("sun.os.patch.level"));
- return fullSystemInfo.toString();
+ _platformInfo = fullSystemInfo.toString();
+ }
+
+ public static int getPID()
+ {
+ return _pid;
+ }
+
+ public static String getPlatformInfo()
+ {
+ return _platformInfo;
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/protocol/ProtocolEngine.java b/java/common/src/main/java/org/apache/qpid/protocol/ProtocolEngine.java
index 7ca588946b..6774d0a45a 100644
--- a/java/common/src/main/java/org/apache/qpid/protocol/ProtocolEngine.java
+++ b/java/common/src/main/java/org/apache/qpid/protocol/ProtocolEngine.java
@@ -23,6 +23,7 @@ package org.apache.qpid.protocol;
import org.apache.qpid.transport.Receiver;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.network.NetworkConnection;
+import org.apache.qpid.transport.network.TransportActivity;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
@@ -31,7 +32,7 @@ import java.nio.ByteBuffer;
* A ProtocolEngine is a Receiver for java.nio.ByteBuffers. It takes the data passed to it in the received
* decodes it and then process the result.
*/
-public interface ProtocolEngine extends Receiver<java.nio.ByteBuffer>
+public interface ProtocolEngine extends Receiver<java.nio.ByteBuffer>, TransportActivity
{
// Returns the remote address of the NetworkDriver
SocketAddress getRemoteAddress();
@@ -56,6 +57,6 @@ public interface ProtocolEngine extends Receiver<java.nio.ByteBuffer>
void readerIdle();
- public void setNetworkConnection(NetworkConnection network, Sender<ByteBuffer> sender);
+ public void setNetworkConnection(NetworkConnection network, Sender<ByteBuffer> sender);
} \ No newline at end of file
diff --git a/java/common/src/main/java/org/apache/qpid/transport/Connection.java b/java/common/src/main/java/org/apache/qpid/transport/Connection.java
index e87851cf7d..cdca726148 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/Connection.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/Connection.java
@@ -21,12 +21,7 @@
package org.apache.qpid.transport;
import org.apache.qpid.framing.ProtocolVersion;
-import org.apache.qpid.transport.network.Assembler;
-import org.apache.qpid.transport.network.Disassembler;
-import org.apache.qpid.transport.network.InputHandler;
-import org.apache.qpid.transport.network.NetworkConnection;
-import org.apache.qpid.transport.network.OutgoingNetworkTransport;
-import org.apache.qpid.transport.network.Transport;
+import org.apache.qpid.transport.network.*;
import org.apache.qpid.transport.network.security.SecurityLayer;
import org.apache.qpid.transport.network.security.SecurityLayerFactory;
import org.apache.qpid.transport.util.Logger;
@@ -73,6 +68,8 @@ public class Connection extends ConnectionInvoker
//Usable channels are numbered 0 to <ChannelMax> - 1
public static final int MAX_CHANNEL_MAX = 0xFFFF;
public static final int MIN_USABLE_CHANNEL_NUM = 0;
+ private long _lastSendTime;
+ private long _lastReadTime;
public enum State { NEW, CLOSED, OPENING, OPEN, CLOSING, CLOSE_RCVD, RESUMING }
@@ -89,15 +86,15 @@ public class Connection extends ConnectionInvoker
public static interface SessionFactory
{
- Session newSession(Connection conn, Binary name, long expiry);
+ Session newSession(Connection conn, Binary name, long expiry, boolean isNoReplay);
}
private static final class DefaultSessionFactory implements SessionFactory
{
- public Session newSession(final Connection conn, final Binary name, final long expiry)
+ public Session newSession(final Connection conn, final Binary name, final long expiry, final boolean isNoReplay)
{
- return new Session(conn, name, expiry);
+ return new Session(conn, name, expiry, isNoReplay);
}
}
@@ -232,9 +229,10 @@ public class Connection extends ConnectionInvoker
addConnectionListener((ConnectionListener)secureReceiver);
}
- NetworkConnection network = transport.connect(settings, secureReceiver, null);
- _remoteAddress = network.getRemoteAddress();
- _localAddress = network.getLocalAddress();
+ NetworkConnection network = transport.connect(settings, secureReceiver, new ConnectionActivity());
+
+ setRemoteAddress(network.getRemoteAddress());
+ setLocalAddress(network.getLocalAddress());
final Sender<ByteBuffer> secureSender = securityLayer.sender(network.getSender());
if(secureSender instanceof ConnectionListener)
@@ -298,7 +296,12 @@ public class Connection extends ConnectionInvoker
public Session createSession(long expiry)
{
- return createSession(UUID.randomUUID().toString(), expiry);
+ return createSession(expiry, false);
+ }
+
+ public Session createSession(long expiry, boolean isNoReplay)
+ {
+ return createSession(UUID.randomUUID().toString(), expiry, isNoReplay);
}
public Session createSession(String name)
@@ -311,6 +314,11 @@ public class Connection extends ConnectionInvoker
return createSession(Strings.toUTF8(name), expiry);
}
+ public Session createSession(String name, long expiry,boolean isNoReplay)
+ {
+ return createSession(new Binary(Strings.toUTF8(name)), expiry, isNoReplay);
+ }
+
public Session createSession(byte[] name, long expiry)
{
return createSession(new Binary(name), expiry);
@@ -318,6 +326,11 @@ public class Connection extends ConnectionInvoker
public Session createSession(Binary name, long expiry)
{
+ return createSession(name, expiry, false);
+ }
+
+ public Session createSession(Binary name, long expiry, boolean isNoReplay)
+ {
synchronized (lock)
{
Waiter w = new Waiter(lock, timeout);
@@ -331,7 +344,7 @@ public class Connection extends ConnectionInvoker
throw new ConnectionException("Timed out waiting for connection to be ready. Current state is :" + state);
}
- Session ssn = _sessionFactory.newSession(this, name, expiry);
+ Session ssn = _sessionFactory.newSession(this, name, expiry, isNoReplay);
registerSession(ssn);
map(ssn);
ssn.attach();
@@ -369,6 +382,7 @@ public class Connection extends ConnectionInvoker
public void received(ProtocolEvent event)
{
+ _lastReadTime = System.currentTimeMillis();
if(log.isDebugEnabled())
{
log.debug("RECV: [%s] %s", this, event);
@@ -378,6 +392,7 @@ public class Connection extends ConnectionInvoker
public void send(ProtocolEvent event)
{
+ _lastSendTime = System.currentTimeMillis();
if(log.isDebugEnabled())
{
log.debug("SEND: [%s] %s", this, event);
@@ -728,6 +743,17 @@ public class Connection extends ConnectionInvoker
return _localAddress;
}
+ protected void setRemoteAddress(SocketAddress remoteAddress)
+ {
+ _remoteAddress = remoteAddress;
+ }
+
+ protected void setLocalAddress(SocketAddress localAddress)
+ {
+ _localAddress = localAddress;
+ }
+
+
private void invokeSessionDetached(int channel, SessionDetachCode sessionDetachCode)
{
SessionDetached sessionDetached = new SessionDetached();
@@ -735,4 +761,38 @@ public class Connection extends ConnectionInvoker
sessionDetached.setCode(sessionDetachCode);
invoke(sessionDetached);
}
+
+
+ protected void doHeartBeat()
+ {
+ connectionHeartbeat();
+ }
+
+ private class ConnectionActivity implements TransportActivity
+ {
+ @Override
+ public long getLastReadTime()
+ {
+ return _lastReadTime;
+ }
+
+ @Override
+ public long getLastWriteTime()
+ {
+ return _lastSendTime;
+ }
+
+ @Override
+ public void writerIdle()
+ {
+ connectionHeartbeat();
+ }
+
+ @Override
+ public void readerIdle()
+ {
+ // TODO
+
+ }
+ }
}
diff --git a/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java b/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java
index 20d6f98fa6..12f8d801dc 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/NetworkTransportConfiguration.java
@@ -38,14 +38,6 @@ public interface NetworkTransportConfiguration
// The amount of memory in bytes to allocate to the outgoing buffer
Integer getSendBufferSize();
- Integer getPort();
-
- String getHost();
-
- String getTransport();
-
- Integer getConnectorProcessors();
-
InetSocketAddress getAddress();
boolean needClientAuth();
diff --git a/java/common/src/main/java/org/apache/qpid/transport/ServerDelegate.java b/java/common/src/main/java/org/apache/qpid/transport/ServerDelegate.java
index e9a7d51456..1e0d5b9698 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/ServerDelegate.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/ServerDelegate.java
@@ -71,7 +71,8 @@ public class ServerDelegate extends ConnectionDelegate
if (mechanism == null || mechanism.length() == 0)
{
- tuneAuthorizedConnection(conn);
+ conn.connectionClose(ConnectionCloseCode.CONNECTION_FORCED,
+ "No Sasl mechanism was specified");
return;
}
@@ -82,7 +83,7 @@ public class ServerDelegate extends ConnectionDelegate
if (ss == null)
{
conn.connectionClose(ConnectionCloseCode.CONNECTION_FORCED,
- "null SASL mechanism: " + mechanism);
+ "No SaslServer could be created for mechanism: " + mechanism);
return;
}
conn.setSaslServer(ss);
diff --git a/java/common/src/main/java/org/apache/qpid/transport/Session.java b/java/common/src/main/java/org/apache/qpid/transport/Session.java
index 95c3e4669f..8b29d6e424 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/Session.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/Session.java
@@ -25,7 +25,6 @@ import org.apache.qpid.configuration.ClientProperties;
import org.apache.qpid.transport.network.Frame;
import org.apache.qpid.transport.util.Logger;
import org.apache.qpid.transport.util.Waiter;
-
import static org.apache.qpid.transport.Option.COMPLETED;
import static org.apache.qpid.transport.Option.SYNC;
import static org.apache.qpid.transport.Option.TIMELY_REPLY;
@@ -132,19 +131,31 @@ public class Session extends SessionInvoker
private final Object stateLock = new Object();
private final AtomicBoolean _failoverRequired = new AtomicBoolean(false);
+ private boolean _isNoReplay = false;
protected Session(Connection connection, Binary name, long expiry)
{
this(connection, new SessionDelegate(), name, expiry);
}
+ protected Session(Connection connection, Binary name, long expiry, boolean noReplay)
+ {
+ this(connection, new SessionDelegate(), name, expiry, noReplay);
+ }
+
protected Session(Connection connection, SessionDelegate delegate, Binary name, long expiry)
{
+ this(connection, delegate, name, expiry,false);
+ }
+
+ protected Session(Connection connection, SessionDelegate delegate, Binary name, long expiry, boolean noReplay)
+ {
this.connection = connection;
this.delegate = delegate;
this.name = name;
this.expiry = expiry;
this.closing = false;
+ this._isNoReplay = noReplay;
initReceiver();
}
@@ -282,6 +293,7 @@ public class Session extends SessionInvoker
void resume()
{
_failoverRequired.set(false);
+
synchronized (commandsLock)
{
attach();
@@ -414,7 +426,7 @@ public class Session extends SessionInvoker
if(log.isDebugEnabled())
{
- log.debug("ID: [%s] %s", this.channel, id);
+ log.debug("identify: ch=%s, commandId=%s", this.channel, id);
}
if ((id & 0xff) == 0)
@@ -443,7 +455,7 @@ public class Session extends SessionInvoker
{
if(log.isDebugEnabled())
{
- log.debug("%s processed([%d,%d]) %s %s", this, lower, upper, syncPoint, maxProcessed);
+ log.debug("%s ch=%s processed([%d,%d]) %s %s", this, channel, lower, upper, syncPoint, maxProcessed);
}
boolean flush;
@@ -451,7 +463,7 @@ public class Session extends SessionInvoker
{
if(log.isDebugEnabled())
{
- log.debug("%s", processed);
+ log.debug("%s processed: %s", this, processed);
}
if (ge(upper, commandsIn))
@@ -740,7 +752,7 @@ public class Session extends SessionInvoker
sessionCommandPoint(0, 0);
}
- boolean replayTransfer = !closing && !transacted &&
+ boolean replayTransfer = !_isNoReplay && !closing && !transacted &&
m instanceof MessageTransfer &&
! m.isUnreliable();
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java b/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java
index 4d4274278f..8437ef1a94 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java
@@ -27,5 +27,7 @@ import javax.net.ssl.SSLContext;
public interface IncomingNetworkTransport extends NetworkTransport
{
- public void accept(NetworkTransportConfiguration config, ProtocolEngineFactory factory, SSLContext sslContext);
+ public void accept(NetworkTransportConfiguration config,
+ ProtocolEngineFactory factory,
+ SSLContext sslContext);
} \ No newline at end of file
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/NetworkConnection.java b/java/common/src/main/java/org/apache/qpid/transport/network/NetworkConnection.java
index 12c42d6643..050d194c47 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/network/NetworkConnection.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/NetworkConnection.java
@@ -50,4 +50,8 @@ public interface NetworkConnection
void setPeerPrincipal(Principal principal);
Principal getPeerPrincipal();
+
+ int getMaxReadIdle();
+
+ int getMaxWriteIdle();
}
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java b/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java
index 854d76430b..45231aa05d 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java
@@ -23,12 +23,13 @@ package org.apache.qpid.transport.network;
import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.transport.Receiver;
-import javax.net.ssl.SSLContext;
import java.nio.ByteBuffer;
public interface OutgoingNetworkTransport extends NetworkTransport
{
public NetworkConnection getConnection();
- public NetworkConnection connect(ConnectionSettings settings, Receiver<ByteBuffer> delegate, SSLContext sslContext);
+ public NetworkConnection connect(ConnectionSettings settings,
+ Receiver<ByteBuffer> delegate,
+ TransportActivity transportActivity);
} \ No newline at end of file
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/Ticker.java b/java/common/src/main/java/org/apache/qpid/transport/network/Ticker.java
new file mode 100644
index 0000000000..210b014a57
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/Ticker.java
@@ -0,0 +1,29 @@
+/*
+ *
+ * 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.transport.network;
+
+public interface Ticker
+{
+ int getTimeToNextTick(long currentTime);
+
+ int tick(long currentTime);
+}
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/TransportActivity.java b/java/common/src/main/java/org/apache/qpid/transport/network/TransportActivity.java
new file mode 100644
index 0000000000..2ee336d9b2
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/TransportActivity.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.transport.network;
+
+public interface TransportActivity
+{
+ long getLastReadTime();
+
+ long getLastWriteTime();
+
+ void writerIdle();
+
+ void readerIdle();
+}
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/io/IdleTimeoutTicker.java b/java/common/src/main/java/org/apache/qpid/transport/network/io/IdleTimeoutTicker.java
new file mode 100644
index 0000000000..54a2a360bb
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/io/IdleTimeoutTicker.java
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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.transport.network.io;
+
+import org.apache.qpid.transport.network.NetworkConnection;
+import org.apache.qpid.transport.network.Ticker;
+import org.apache.qpid.transport.network.TransportActivity;
+
+class IdleTimeoutTicker implements Ticker
+{
+ private final TransportActivity _transport;
+ private final int _defaultTimeout;
+ private NetworkConnection _connection;
+
+ public IdleTimeoutTicker(TransportActivity transport, int defaultTimeout)
+ {
+ _transport = transport;
+ _defaultTimeout = defaultTimeout;
+ }
+
+ @Override
+ public int getTimeToNextTick(long currentTime)
+ {
+ long nextTime = -1;
+ final long maxReadIdle = 1000l * _connection.getMaxReadIdle();
+
+ if(maxReadIdle > 0)
+ {
+ nextTime = _transport.getLastReadTime() + maxReadIdle;
+ }
+
+ long maxWriteIdle = 1000l * _connection.getMaxWriteIdle();
+
+ if(maxWriteIdle > 0)
+ {
+ long writeTime = _transport.getLastWriteTime() + maxWriteIdle;
+ if(nextTime == -1l || writeTime < nextTime)
+ {
+ nextTime = writeTime;
+ }
+ }
+ return nextTime == -1 ? _defaultTimeout : (int) (nextTime - currentTime);
+ }
+
+ @Override
+ public int tick(long currentTime)
+ {
+ // writer Idle
+ long maxWriteIdle = 1000l * _connection.getMaxWriteIdle();
+ if(maxWriteIdle > 0 && maxWriteIdle+ _transport.getLastWriteTime() <= currentTime)
+ {
+ _transport.writerIdle();
+ }
+ // reader Idle
+ final long maxReadIdle = 1000l * _connection.getMaxReadIdle();
+ if(maxReadIdle > 0 && maxReadIdle+ _transport.getLastReadTime() <= currentTime)
+ {
+
+ _transport.readerIdle();
+ }
+ return getTimeToNextTick(currentTime);
+ }
+
+ public void setConnection(NetworkConnection connection)
+ {
+ _connection = connection;
+ }
+}
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkConnection.java b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkConnection.java
index 2658296c5f..f5c09ac2cc 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkConnection.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkConnection.java
@@ -26,7 +26,9 @@ import java.nio.ByteBuffer;
import java.security.Principal;
import org.apache.qpid.transport.Receiver;
import org.apache.qpid.transport.Sender;
+import org.apache.qpid.transport.network.Ticker;
import org.apache.qpid.transport.network.NetworkConnection;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,14 +40,23 @@ public class IoNetworkConnection implements NetworkConnection
private final IoSender _ioSender;
private final IoReceiver _ioReceiver;
private Principal _principal;
+ private int _maxReadIdle;
+ private int _maxWriteIdle;
public IoNetworkConnection(Socket socket, Receiver<ByteBuffer> delegate,
- int sendBufferSize, int receiveBufferSize, long timeout)
+ int sendBufferSize, int receiveBufferSize, long timeout)
+ {
+ this(socket,delegate,sendBufferSize,receiveBufferSize,timeout,null);
+ }
+
+ public IoNetworkConnection(Socket socket, Receiver<ByteBuffer> delegate,
+ int sendBufferSize, int receiveBufferSize, long timeout, Ticker ticker)
{
_socket = socket;
_timeout = timeout;
_ioReceiver = new IoReceiver(_socket, delegate, receiveBufferSize,_timeout);
+ _ioReceiver.setTicker(ticker);
_ioSender = new IoSender(_socket, 2 * sendBufferSize, _timeout);
@@ -88,14 +99,12 @@ public class IoNetworkConnection implements NetworkConnection
public void setMaxWriteIdle(int sec)
{
- // TODO implement support for setting heartbeating config in this way
- // Currently a socket timeout is used in IoSender
+ _maxWriteIdle = sec;
}
public void setMaxReadIdle(int sec)
{
- // TODO implement support for setting heartbeating config in this way
- // Currently a socket timeout is used in IoSender
+ _maxReadIdle = sec;
}
@Override
@@ -109,4 +118,16 @@ public class IoNetworkConnection implements NetworkConnection
{
return _principal;
}
+
+ @Override
+ public int getMaxReadIdle()
+ {
+ return _maxReadIdle;
+ }
+
+ @Override
+ public int getMaxWriteIdle()
+ {
+ return _maxWriteIdle;
+ }
}
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
index 9b6f0a0b1b..c8027e143e 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
@@ -41,9 +41,8 @@ import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.transport.NetworkTransportConfiguration;
import org.apache.qpid.transport.Receiver;
import org.apache.qpid.transport.TransportException;
-import org.apache.qpid.transport.network.IncomingNetworkTransport;
-import org.apache.qpid.transport.network.NetworkConnection;
-import org.apache.qpid.transport.network.OutgoingNetworkTransport;
+import org.apache.qpid.transport.network.*;
+
import org.slf4j.LoggerFactory;
public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNetworkTransport
@@ -56,7 +55,9 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
private IoNetworkConnection _connection;
private AcceptingThread _acceptor;
- public NetworkConnection connect(ConnectionSettings settings, Receiver<ByteBuffer> delegate, SSLContext sslContext)
+ public NetworkConnection connect(ConnectionSettings settings,
+ Receiver<ByteBuffer> delegate,
+ TransportActivity transportActivity)
{
int sendBufferSize = settings.getWriteBufferSize();
int receiveBufferSize = settings.getReadBufferSize();
@@ -91,7 +92,9 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
try
{
- _connection = new IoNetworkConnection(_socket, delegate, sendBufferSize, receiveBufferSize, TIMEOUT);
+ IdleTimeoutTicker ticker = new IdleTimeoutTicker(transportActivity, TIMEOUT);
+ _connection = new IoNetworkConnection(_socket, delegate, sendBufferSize, receiveBufferSize, TIMEOUT, ticker);
+ ticker.setConnection(_connection);
_connection.start();
}
catch(Exception e)
@@ -128,9 +131,10 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
return _connection;
}
- public void accept(NetworkTransportConfiguration config, ProtocolEngineFactory factory, SSLContext sslContext)
+ public void accept(NetworkTransportConfiguration config,
+ ProtocolEngineFactory factory,
+ SSLContext sslContext)
{
-
try
{
_acceptor = new AcceptingThread(config, factory, sslContext);
@@ -141,8 +145,6 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
{
throw new TransportException("Unable to start server socket", e);
}
-
-
}
private class AcceptingThread extends Thread
@@ -152,15 +154,16 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
private ProtocolEngineFactory _factory;
private SSLContext _sslContext;
private ServerSocket _serverSocket;
+ private int _timeout;
private AcceptingThread(NetworkTransportConfiguration config,
ProtocolEngineFactory factory,
- SSLContext sslContext)
- throws IOException
+ SSLContext sslContext) throws IOException
{
_config = config;
_factory = factory;
_sslContext = sslContext;
+ _timeout = TIMEOUT;
InetSocketAddress address = config.getAddress();
@@ -172,15 +175,19 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
{
SSLServerSocketFactory socketFactory = _sslContext.getServerSocketFactory();
_serverSocket = socketFactory.createServerSocket();
- ((SSLServerSocket)_serverSocket).setNeedClientAuth(config.needClientAuth());
- ((SSLServerSocket)_serverSocket).setWantClientAuth(config.wantClientAuth());
+ if(config.needClientAuth())
+ {
+ ((SSLServerSocket)_serverSocket).setNeedClientAuth(true);
+ }
+ else if(config.wantClientAuth())
+ {
+ ((SSLServerSocket)_serverSocket).setWantClientAuth(true);
+ }
}
_serverSocket.setReuseAddress(true);
_serverSocket.bind(address);
-
-
}
@@ -217,6 +224,7 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
{
socket = _serverSocket.accept();
socket.setTcpNoDelay(_config.getTcpNoDelay());
+ socket.setSoTimeout(_timeout);
final Integer sendBufferSize = _config.getSendBufferSize();
final Integer receiveBufferSize = _config.getReceiveBufferSize();
@@ -224,10 +232,12 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
socket.setSendBufferSize(sendBufferSize);
socket.setReceiveBufferSize(receiveBufferSize);
-
ProtocolEngine engine = _factory.newProtocolEngine();
- NetworkConnection connection = new IoNetworkConnection(socket, engine, sendBufferSize, receiveBufferSize, TIMEOUT);
+ final IdleTimeoutTicker ticker = new IdleTimeoutTicker(engine, TIMEOUT);
+ NetworkConnection connection = new IoNetworkConnection(socket, engine, sendBufferSize, receiveBufferSize, _timeout,
+ ticker);
+ ticker.setConnection(connection);
if(_sslContext != null)
{
@@ -248,14 +258,14 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
}
catch(RuntimeException e)
{
- LOGGER.error("Error in Acceptor thread on port " + _config.getPort(), e);
+ LOGGER.error("Error in Acceptor thread on address " + _config.getAddress(), e);
closeSocketIfNecessary(socket);
}
catch(IOException e)
{
if(!_closed)
{
- LOGGER.error("Error in Acceptor thread on port " + _config.getPort(), e);
+ LOGGER.error("Error in Acceptor thread on address " + _config.getAddress(), e);
closeSocketIfNecessary(socket);
try
{
@@ -275,7 +285,7 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
{
if(LOGGER.isDebugEnabled())
{
- LOGGER.debug("Acceptor exiting, no new connections will be accepted on port " + _config.getPort());
+ LOGGER.debug("Acceptor exiting, no new connections will be accepted on address " + _config.getAddress());
}
}
}
@@ -294,6 +304,7 @@ public class IoNetworkTransport implements OutgoingNetworkTransport, IncomingNet
}
}
}
+
}
}
diff --git a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java
index 7e63071c16..06a43e21c6 100644
--- a/java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java
+++ b/java/common/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java
@@ -24,6 +24,7 @@ import org.apache.qpid.common.Closeable;
import org.apache.qpid.thread.Threading;
import org.apache.qpid.transport.Receiver;
import org.apache.qpid.transport.TransportException;
+import org.apache.qpid.transport.network.Ticker;
import org.apache.qpid.transport.util.Logger;
import javax.net.ssl.SSLSocket;
@@ -31,6 +32,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketException;
+import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -51,6 +53,8 @@ final class IoReceiver implements Runnable, Closeable
private final AtomicBoolean closed = new AtomicBoolean(false);
private final Thread receiverThread;
private static final boolean shutdownBroken;
+
+ private Ticker _ticker;
static
{
String osName = System.getProperty("os.name");
@@ -136,7 +140,7 @@ final class IoReceiver implements Runnable, Closeable
{
final int threshold = bufferSize / 2;
- // I set the read buffer size simillar to SO_RCVBUF
+ // I set the read buffer size similar to SO_RCVBUF
// Haven't tested with a lower value to see if it's better or worse
byte[] buffer = new byte[bufferSize];
try
@@ -144,27 +148,71 @@ final class IoReceiver implements Runnable, Closeable
InputStream in = socket.getInputStream();
int read = 0;
int offset = 0;
- while ((read = in.read(buffer, offset, bufferSize-offset)) != -1)
+ long currentTime;
+ while(read != -1)
{
- if (read > 0)
+ try
+ {
+ while ((read = in.read(buffer, offset, bufferSize-offset)) != -1)
+ {
+ if (read > 0)
+ {
+ ByteBuffer b = ByteBuffer.wrap(buffer,offset,read);
+ receiver.received(b);
+ offset+=read;
+ if (offset > threshold)
+ {
+ offset = 0;
+ buffer = new byte[bufferSize];
+ }
+ }
+ currentTime = System.currentTimeMillis();
+
+ if(_ticker != null)
+ {
+ int tick = _ticker.getTimeToNextTick(currentTime);
+ if(tick <= 0)
+ {
+ tick = _ticker.tick(currentTime);
+ }
+ try
+ {
+ if(!socket.isClosed())
+ {
+ socket.setSoTimeout(tick <= 0 ? 1 : tick);
+ }
+ }
+ catch(SocketException e)
+ {
+ // ignore - closed socket
+ }
+ }
+ }
+ }
+ catch (SocketTimeoutException e)
{
- ByteBuffer b = ByteBuffer.wrap(buffer,offset,read);
- receiver.received(b);
- offset+=read;
- if (offset > threshold)
+ currentTime = System.currentTimeMillis();
+ if(_ticker != null)
{
- offset = 0;
- buffer = new byte[bufferSize];
+ final int tick = _ticker.tick(currentTime);
+ if(!socket.isClosed())
+ {
+ try
+ {
+ socket.setSoTimeout(tick <= 0 ? 1 : tick );
+ }
+ catch(SocketException ex)
+ {
+ // ignore - closed socket
+ }
+ }
}
}
}
}
catch (Throwable t)
{
- if (!(shutdownBroken &&
- t instanceof SocketException &&
- t.getMessage().equalsIgnoreCase("socket closed") &&
- closed.get()))
+ if (shouldReport(t))
{
receiver.exception(t);
}
@@ -183,4 +231,30 @@ final class IoReceiver implements Runnable, Closeable
}
}
+ private boolean shouldReport(Throwable t)
+ {
+ boolean brokenClose = closed.get() &&
+ shutdownBroken &&
+ t instanceof SocketException &&
+ "socket closed".equalsIgnoreCase(t.getMessage());
+
+ boolean sslSocketClosed = closed.get() &&
+ socket instanceof SSLSocket &&
+ t instanceof SocketException &&
+ "Socket is closed".equalsIgnoreCase(t.getMessage());
+
+ return !brokenClose && !sslSocketClosed;
+ }
+
+ public Ticker getTicker()
+ {
+ return _ticker;
+ }
+
+ public void setTicker(Ticker ticker)
+ {
+ _ticker = ticker;
+ }
+
+
}
diff --git a/java/common/src/main/java/org/apache/qpid/url/BindingURL.java b/java/common/src/main/java/org/apache/qpid/url/BindingURL.java
index 0e6c865a16..61585443b1 100644
--- a/java/common/src/main/java/org/apache/qpid/url/BindingURL.java
+++ b/java/common/src/main/java/org/apache/qpid/url/BindingURL.java
@@ -36,6 +36,9 @@ public interface BindingURL
public static final String OPTION_SUBSCRIPTION = "subscription";
public static final String OPTION_ROUTING_KEY = "routingkey";
public static final String OPTION_BINDING_KEY = "bindingkey";
+ public static final String OPTION_EXCHANGE_AUTODELETE = "exchangeautodelete";
+ public static final String OPTION_EXCHANGE_DURABLE = "exchangedurable";
+ public static final String OPTION_EXCHANGE_INTERNAL = "exchangeinternal";
/**
* This option is only applicable for 0-8/0-9/0-9-1 protocols connection
diff --git a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
index 2d3e321812..7362099070 100644
--- a/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
+++ b/java/common/src/main/java/org/apache/qpid/util/FileUtils.java
@@ -220,6 +220,19 @@ public class FileUtils
public static void copyCheckedEx(File src, File dst) throws IOException
{
InputStream in = new FileInputStream(src);
+ copy(in, dst);
+ }
+
+ /**
+ * Copies the specified InputStream to the specified destination file. If the destination file does not exist,
+ * it is created.
+ *
+ * @param in The InputStream
+ * @param dst The destination file name.
+ * @throws IOException
+ */
+ public static void copy(InputStream in, File dst) throws IOException
+ {
try
{
if (!dst.exists())
diff --git a/java/common/src/main/java/org/apache/qpid/util/NetMatcher.java b/java/common/src/main/java/org/apache/qpid/util/NetMatcher.java
deleted file mode 100644
index 971dd3fe2a..0000000000
--- a/java/common/src/main/java/org/apache/qpid/util/NetMatcher.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/***********************************************************************
- * Copyright (c) 2000-2006 The Apache Software Foundation. *
- * All rights reserved. *
- * ------------------------------------------------------------------- *
- * 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. *
- ***********************************************************************/
-
-package org.apache.qpid.util;
-
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-
-public class NetMatcher
-{
- private ArrayList networks;
-
- public void initInetNetworks(final Collection nets)
- {
- networks = new ArrayList();
- for (Iterator iter = nets.iterator(); iter.hasNext(); )
- {
- try
- {
- InetNetwork net = InetNetwork.getFromString((String) iter.next());
- if (!networks.contains(net))
- {
- networks.add(net);
- }
- }
- catch (java.net.UnknownHostException uhe)
- {
- log("Cannot resolve address: " + uhe.getMessage());
- }
- }
- networks.trimToSize();
- }
-
- public void initInetNetworks(final String[] nets)
- {
- networks = new ArrayList();
- for (int i = 0; i < nets.length; i++)
- {
- try
- {
- InetNetwork net = InetNetwork.getFromString(nets[i]);
- if (!networks.contains(net))
- {
- networks.add(net);
- }
- }
- catch (java.net.UnknownHostException uhe)
- {
- log("Cannot resolve address: " + uhe.getMessage());
- }
- }
- networks.trimToSize();
- }
-
- public boolean matchInetNetwork(final String hostIP)
- {
- InetAddress ip = null;
-
- try
- {
- ip = InetAddress.getByName(hostIP);
- }
- catch (java.net.UnknownHostException uhe)
- {
- log("Cannot resolve address for " + hostIP + ": " + uhe.getMessage());
- }
-
- boolean sameNet = false;
-
- if (ip != null)
- {
- for (Iterator iter = networks.iterator(); (!sameNet) && iter.hasNext(); )
- {
- InetNetwork network = (InetNetwork) iter.next();
- sameNet = network.contains(ip);
- }
- }
- return sameNet;
- }
-
- public boolean matchInetNetwork(final InetAddress ip)
- {
- boolean sameNet = false;
-
- for (Iterator iter = networks.iterator(); (!sameNet) && iter.hasNext(); )
- {
- InetNetwork network = (InetNetwork) iter.next();
- sameNet = network.contains(ip);
- }
- return sameNet;
- }
-
- public NetMatcher()
- {
- }
-
- public NetMatcher(final String[] nets)
- {
- initInetNetworks(nets);
- }
-
- public NetMatcher(final Collection nets)
- {
- initInetNetworks(nets);
- }
-
- public String toString() {
- return networks.toString();
- }
-
- protected void log(String s) { }
-}
-
-class InetNetwork
-{
- /*
- * Implements network masking, and is compatible with RFC 1518 and
- * RFC 1519, which describe CIDR: Classless Inter-Domain Routing.
- */
-
- private InetAddress network;
- private InetAddress netmask;
-
- public InetNetwork(InetAddress ip, InetAddress netmask)
- {
- network = maskIP(ip, netmask);
- this.netmask = netmask;
- }
-
- public boolean contains(final String name) throws java.net.UnknownHostException
- {
- return network.equals(maskIP(InetAddress.getByName(name), netmask));
- }
-
- public boolean contains(final InetAddress ip)
- {
- return network.equals(maskIP(ip, netmask));
- }
-
- public String toString()
- {
- return network.getHostAddress() + "/" + netmask.getHostAddress();
- }
-
- public int hashCode()
- {
- return maskIP(network, netmask).hashCode();
- }
-
- public boolean equals(Object obj)
- {
- return (obj != null) && (obj instanceof InetNetwork) &&
- ((((InetNetwork)obj).network.equals(network)) && (((InetNetwork)obj).netmask.equals(netmask)));
- }
-
- public static InetNetwork getFromString(String netspec) throws java.net.UnknownHostException
- {
- if (netspec.endsWith("*"))
- {
- netspec = normalizeFromAsterisk(netspec);
- }
- else
- {
- int iSlash = netspec.indexOf('/');
- if (iSlash == -1)
- {
- netspec += "/255.255.255.255";
- }
- else if (netspec.indexOf('.', iSlash) == -1)
- {
- netspec = normalizeFromCIDR(netspec);
- }
- }
-
- return new InetNetwork(InetAddress.getByName(netspec.substring(0, netspec.indexOf('/'))),
- InetAddress.getByName(netspec.substring(netspec.indexOf('/') + 1)));
- }
-
- public static InetAddress maskIP(final byte[] ip, final byte[] mask)
- {
- try
- {
- return getByAddress(new byte[]
- {
- (byte) (mask[0] & ip[0]),
- (byte) (mask[1] & ip[1]),
- (byte) (mask[2] & ip[2]),
- (byte) (mask[3] & ip[3])
- });
- }
- catch(Exception _) {}
- {
- return null;
- }
- }
-
- public static InetAddress maskIP(final InetAddress ip, final InetAddress mask)
- {
- return maskIP(ip.getAddress(), mask.getAddress());
- }
-
- /*
- * This converts from an uncommon "wildcard" CIDR format
- * to "address + mask" format:
- *
- * * => 000.000.000.0/000.000.000.0
- * xxx.* => xxx.000.000.0/255.000.000.0
- * xxx.xxx.* => xxx.xxx.000.0/255.255.000.0
- * xxx.xxx.xxx.* => xxx.xxx.xxx.0/255.255.255.0
- */
- static private String normalizeFromAsterisk(final String netspec)
- {
- String[] masks = { "0.0.0.0/0.0.0.0", "0.0.0/255.0.0.0", "0.0/255.255.0.0", "0/255.255.255.0" };
- char[] srcb = netspec.toCharArray();
- int octets = 0;
- for (int i = 1; i < netspec.length(); i++)
- {
- if (srcb[i] == '.')
- {
- octets++;
- }
- }
- return (octets == 0) ? masks[0] : netspec.substring(0, netspec.length() -1 ).concat(masks[octets]);
- }
-
- /*
- * RFC 1518, 1519 - Classless Inter-Domain Routing (CIDR)
- * This converts from "prefix + prefix-length" format to
- * "address + mask" format, e.g. from xxx.xxx.xxx.xxx/yy
- * to xxx.xxx.xxx.xxx/yyy.yyy.yyy.yyy.
- */
- static private String normalizeFromCIDR(final String netspec)
- {
- final int bits = 32 - Integer.parseInt(netspec.substring(netspec.indexOf('/')+1));
- final int mask = (bits == 32) ? 0 : 0xFFFFFFFF - ((1 << bits)-1);
-
- return netspec.substring(0, netspec.indexOf('/') + 1) +
- Integer.toString(mask >> 24 & 0xFF, 10) + "." +
- Integer.toString(mask >> 16 & 0xFF, 10) + "." +
- Integer.toString(mask >> 8 & 0xFF, 10) + "." +
- Integer.toString(mask >> 0 & 0xFF, 10);
- }
-
- private static java.lang.reflect.Method getByAddress = null;
-
- static {
- try {
- Class inetAddressClass = Class.forName("java.net.InetAddress");
- Class[] parameterTypes = { byte[].class };
- getByAddress = inetAddressClass.getMethod("getByAddress", parameterTypes);
- } catch (Exception e) {
- getByAddress = null;
- }
- }
-
- private static InetAddress getByAddress(byte[] ip) throws java.net.UnknownHostException
- {
- InetAddress addr = null;
- if (getByAddress != null)
- {
- try
- {
- addr = (InetAddress) getByAddress.invoke(null, new Object[] { ip });
- }
- catch (IllegalAccessException e)
- {
- }
- catch (java.lang.reflect.InvocationTargetException e)
- {
- }
- }
-
- if (addr == null) {
- addr = InetAddress.getByName
- (
- Integer.toString(ip[0] & 0xFF, 10) + "." +
- Integer.toString(ip[1] & 0xFF, 10) + "." +
- Integer.toString(ip[2] & 0xFF, 10) + "." +
- Integer.toString(ip[3] & 0xFF, 10)
- );
- }
- return addr;
- }
-}
diff --git a/java/common/src/test/java/org/apache/qpid/framing/FieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/FieldTableTest.java
new file mode 100644
index 0000000000..1ecf450551
--- /dev/null
+++ b/java/common/src/test/java/org/apache/qpid/framing/FieldTableTest.java
@@ -0,0 +1,938 @@
+/*
+ *
+ * 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.framing;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.qpid.AMQPInvalidClassException;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class FieldTableTest extends TestCase
+{
+ /**
+ * Test that setting a similar named value replaces any previous value set on that name
+ */
+ public void testReplacement()
+ {
+ FieldTable table1 = new FieldTable();
+ // Set a boolean value
+ table1.setBoolean("value", true);
+ // Check length of table is correct (<Value length> + <type> + <Boolean length>)
+ int size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedBooleanLength();
+ Assert.assertEquals(size, table1.getEncodedSize());
+
+ // reset value to an integer
+ table1.setInteger("value", Integer.MAX_VALUE);
+
+ // Check the length has changed accordingly (<Value length> + <type> + <Integer length>)
+ size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedIntegerLength();
+ Assert.assertEquals(size, table1.getEncodedSize());
+
+ // Check boolean value is null
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ // ... and integer value is good
+ Assert.assertEquals((Integer) Integer.MAX_VALUE, table1.getInteger("value"));
+ }
+
+ /**
+ * Set a boolean and check that we can only get it back as a boolean and a string
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testBoolean()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setBoolean("value", true);
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Test Getting right value back
+ Assert.assertEquals((Boolean) true, table1.getBoolean("value"));
+
+ // Check we don't get anything back for other gets
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+
+ // except value as a string
+ Assert.assertEquals("true", table1.getString("value"));
+
+ table1.remove("value");
+
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getBoolean("Rubbish"));
+ }
+
+ /**
+ * Set a byte and check that we can only get it back as a byte and a string
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testByte()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setByte("value", Byte.MAX_VALUE);
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Tests lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(Byte.MAX_VALUE, (byte) table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+
+ // ... and a the string value of it.
+ Assert.assertEquals("" + Byte.MAX_VALUE, table1.getString("value"));
+
+ table1.remove("value");
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getByte("Rubbish"));
+ }
+
+ /**
+ * Set a short and check that we can only get it back as a short and a string
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testShort()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setShort("value", Short.MAX_VALUE);
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Tests lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(Short.MAX_VALUE, (short) table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+
+ // ... and a the string value of it.
+ Assert.assertEquals("" + Short.MAX_VALUE, table1.getString("value"));
+
+ table1.remove("value");
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getShort("Rubbish"));
+ }
+
+ /**
+ * Set a char and check that we can only get it back as a char
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testChar()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setChar("value", 'c');
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Tests lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals('c', (char) table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+
+ // ... and a the string value of it.
+ Assert.assertEquals("c", table1.getString("value"));
+
+ table1.remove("value");
+
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getCharacter("Rubbish"));
+ }
+
+ /**
+ * Set a double and check that we can only get it back as a double
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testDouble()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setDouble("value", Double.MAX_VALUE);
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Tests lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(Double.MAX_VALUE, (double) table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+
+ // ... and a the string value of it.
+ Assert.assertEquals("" + Double.MAX_VALUE, table1.getString("value"));
+ table1.remove("value");
+ // but after a removeKey it doesn't
+ Assert.assertFalse(table1.containsKey("value"));
+
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getDouble("Rubbish"));
+ }
+
+ /**
+ * Set a float and check that we can only get it back as a float
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testFloat()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setFloat("value", Float.MAX_VALUE);
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Tests lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(Float.MAX_VALUE, (float) table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+
+ // ... and a the string value of it.
+ Assert.assertEquals("" + Float.MAX_VALUE, table1.getString("value"));
+
+ table1.remove("value");
+ // but after a removeKey it doesn't
+ Assert.assertFalse(table1.containsKey("value"));
+
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getFloat("Rubbish"));
+ }
+
+ /**
+ * Set an int and check that we can only get it back as an int
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testInt()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setInteger("value", Integer.MAX_VALUE);
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(Integer.MAX_VALUE, (int) table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+
+ // ... and a the string value of it.
+ Assert.assertEquals("" + Integer.MAX_VALUE, table1.getString("value"));
+
+ table1.remove("value");
+ // but after a removeKey it doesn't
+ Assert.assertFalse(table1.containsKey("value"));
+
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getInteger("Rubbish"));
+ }
+
+ /**
+ * Set a long and check that we can only get it back as a long
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testLong()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setLong("value", Long.MAX_VALUE);
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(Long.MAX_VALUE, (long) table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+
+ // ... and a the string value of it.
+ Assert.assertEquals("" + Long.MAX_VALUE, table1.getString("value"));
+
+ table1.remove("value");
+ // but after a removeKey it doesn't
+ Assert.assertFalse(table1.containsKey("value"));
+
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getLong("Rubbish"));
+ }
+
+ /**
+ * Set a double and check that we can only get it back as a double
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testBytes()
+ {
+ byte[] bytes = { 99, 98, 97, 96, 95 };
+
+ FieldTable table1 = new FieldTable();
+ table1.setBytes("value", bytes);
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Tets lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ assertBytesEqual(bytes, table1.getBytes("value"));
+
+ // ... and a the string value of it is null
+ Assert.assertEquals(null, table1.getString("value"));
+
+ table1.remove("value");
+ // but after a removeKey it doesn't
+ Assert.assertFalse(table1.containsKey("value"));
+
+ // Table should now have zero length for encoding
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getBytes("Rubbish"));
+ }
+
+ /**
+ * Calls all methods that can be used to check the table is empty
+ * - getEncodedSize
+ * - isEmpty
+ * - length
+ *
+ * @param table to check is empty
+ */
+ private void checkEmpty(FieldTable table)
+ {
+ Assert.assertEquals(0, table.getEncodedSize());
+ Assert.assertTrue(table.isEmpty());
+ Assert.assertEquals(0, table.size());
+
+ Assert.assertEquals(0, table.keySet().size());
+ }
+
+ /**
+ * Set a String and check that we can only get it back as a String
+ * Check that attempting to lookup a non existent value returns null
+ */
+ public void testString()
+ {
+ FieldTable table1 = new FieldTable();
+ table1.setString("value", "Hello");
+ Assert.assertTrue(table1.propertyExists("value"));
+
+ // Test lookups we shouldn't get anything back for other gets
+ // we should get right value back for this type ....
+ Assert.assertEquals(null, table1.getBoolean("value"));
+ Assert.assertEquals(null, table1.getByte("value"));
+ Assert.assertEquals(null, table1.getShort("value"));
+ Assert.assertEquals(null, table1.getCharacter("value"));
+ Assert.assertEquals(null, table1.getDouble("value"));
+ Assert.assertEquals(null, table1.getFloat("value"));
+ Assert.assertEquals(null, table1.getInteger("value"));
+ Assert.assertEquals(null, table1.getLong("value"));
+ Assert.assertEquals(null, table1.getBytes("value"));
+ Assert.assertEquals("Hello", table1.getString("value"));
+
+ // Try setting a null value and read it back
+ table1.setString("value", null);
+
+ Assert.assertEquals(null, table1.getString("value"));
+
+ // but still contains the value
+ Assert.assertTrue(table1.containsKey("value"));
+
+ table1.remove("value");
+ // but after a removeKey it doesn't
+ Assert.assertFalse(table1.containsKey("value"));
+
+ checkEmpty(table1);
+
+ // Looking up an invalid value returns null
+ Assert.assertEquals(null, table1.getString("Rubbish"));
+
+ // Additional Test that haven't been covered for string
+ table1.setObject("value", "Hello");
+ // Check that it was set correctly
+ Assert.assertEquals("Hello", table1.getString("value"));
+ }
+
+ /** Check that a nested field table parameter correctly encodes and decodes to a byte buffer. */
+ public void testNestedFieldTable() throws IOException
+ {
+ byte[] testBytes = new byte[] { 0, 1, 2, 3, 4, 5 };
+
+ FieldTable outerTable = new FieldTable();
+ FieldTable innerTable = new FieldTable();
+
+ // Put some stuff in the inner table.
+ innerTable.setBoolean("bool", true);
+ innerTable.setByte("byte", Byte.MAX_VALUE);
+ innerTable.setBytes("bytes", testBytes);
+ innerTable.setChar("char", 'c');
+ innerTable.setDouble("double", Double.MAX_VALUE);
+ innerTable.setFloat("float", Float.MAX_VALUE);
+ innerTable.setInteger("int", Integer.MAX_VALUE);
+ innerTable.setLong("long", Long.MAX_VALUE);
+ innerTable.setShort("short", Short.MAX_VALUE);
+ innerTable.setString("string", "hello");
+ innerTable.setString("null-string", null);
+
+ // Put the inner table in the outer one.
+ outerTable.setFieldTable("innerTable", innerTable);
+
+ // Write the outer table into the buffer.
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ outerTable.writeToBuffer(new DataOutputStream(baos));
+
+ byte[] data = baos.toByteArray();
+
+ // Extract the table back from the buffer again.
+ try
+ {
+ FieldTable extractedOuterTable = EncodingUtils.readFieldTable(new DataInputStream(new ByteArrayInputStream(data)));
+
+ FieldTable extractedTable = extractedOuterTable.getFieldTable("innerTable");
+
+ Assert.assertEquals((Boolean) true, extractedTable.getBoolean("bool"));
+ Assert.assertEquals((Byte) Byte.MAX_VALUE, extractedTable.getByte("byte"));
+ assertBytesEqual(testBytes, extractedTable.getBytes("bytes"));
+ Assert.assertEquals((Character) 'c', extractedTable.getCharacter("char"));
+ Assert.assertEquals(Double.MAX_VALUE, extractedTable.getDouble("double"));
+ Assert.assertEquals(Float.MAX_VALUE, extractedTable.getFloat("float"));
+ Assert.assertEquals((Integer) Integer.MAX_VALUE, extractedTable.getInteger("int"));
+ Assert.assertEquals((Long) Long.MAX_VALUE, extractedTable.getLong("long"));
+ Assert.assertEquals((Short) Short.MAX_VALUE, extractedTable.getShort("short"));
+ Assert.assertEquals("hello", extractedTable.getString("string"));
+ Assert.assertEquals(null, extractedTable.getString("null-string"));
+ }
+ catch (AMQFrameDecodingException e)
+ {
+ fail("Failed to decode field table with nested inner table.");
+ }
+ }
+
+ public void testValues()
+ {
+ FieldTable table = new FieldTable();
+ table.setBoolean("bool", true);
+ table.setByte("byte", Byte.MAX_VALUE);
+ byte[] bytes = { 99, 98, 97, 96, 95 };
+ table.setBytes("bytes", bytes);
+ table.setChar("char", 'c');
+ table.setDouble("double", Double.MAX_VALUE);
+ table.setFloat("float", Float.MAX_VALUE);
+ table.setInteger("int", Integer.MAX_VALUE);
+ table.setLong("long", Long.MAX_VALUE);
+ table.setShort("short", Short.MAX_VALUE);
+ table.setString("string", "Hello");
+ table.setString("null-string", null);
+
+ table.setObject("object-bool", true);
+ table.setObject("object-byte", Byte.MAX_VALUE);
+ table.setObject("object-bytes", bytes);
+ table.setObject("object-char", 'c');
+ table.setObject("object-double", Double.MAX_VALUE);
+ table.setObject("object-float", Float.MAX_VALUE);
+ table.setObject("object-int", Integer.MAX_VALUE);
+ table.setObject("object-long", Long.MAX_VALUE);
+ table.setObject("object-short", Short.MAX_VALUE);
+ table.setObject("object-string", "Hello");
+
+ try
+ {
+ table.setObject("Null-object", null);
+ fail("null values are not allowed");
+ }
+ catch (AMQPInvalidClassException aice)
+ {
+ assertEquals("Null values are not allowed to be set",
+ AMQPInvalidClassException.INVALID_OBJECT_MSG + "null", aice.getMessage());
+ }
+
+ try
+ {
+ table.setObject("Unsupported-object", new Exception());
+ fail("Non primitive values are not allowed");
+ }
+ catch (AMQPInvalidClassException aice)
+ {
+ assertEquals("Non primitive values are not allowed to be set",
+ AMQPInvalidClassException.INVALID_OBJECT_MSG + Exception.class, aice.getMessage());
+ }
+
+ Assert.assertEquals((Boolean) true, table.getBoolean("bool"));
+ Assert.assertEquals((Byte) Byte.MAX_VALUE, table.getByte("byte"));
+ assertBytesEqual(bytes, table.getBytes("bytes"));
+ Assert.assertEquals((Character) 'c', table.getCharacter("char"));
+ Assert.assertEquals(Double.MAX_VALUE, table.getDouble("double"));
+ Assert.assertEquals(Float.MAX_VALUE, table.getFloat("float"));
+ Assert.assertEquals((Integer) Integer.MAX_VALUE, table.getInteger("int"));
+ Assert.assertEquals((Long) Long.MAX_VALUE, table.getLong("long"));
+ Assert.assertEquals((Short) Short.MAX_VALUE, table.getShort("short"));
+ Assert.assertEquals("Hello", table.getString("string"));
+ Assert.assertEquals(null, table.getString("null-string"));
+
+ Assert.assertEquals(true, table.getObject("object-bool"));
+ Assert.assertEquals(Byte.MAX_VALUE, table.getObject("object-byte"));
+ assertBytesEqual(bytes, (byte[]) table.getObject("object-bytes"));
+ Assert.assertEquals('c', table.getObject("object-char"));
+ Assert.assertEquals(Double.MAX_VALUE, table.getObject("object-double"));
+ Assert.assertEquals(Float.MAX_VALUE, table.getObject("object-float"));
+ Assert.assertEquals(Integer.MAX_VALUE, table.getObject("object-int"));
+ Assert.assertEquals(Long.MAX_VALUE, table.getObject("object-long"));
+ Assert.assertEquals(Short.MAX_VALUE, table.getObject("object-short"));
+ Assert.assertEquals("Hello", table.getObject("object-string"));
+ }
+
+ public void testWriteBuffer() throws IOException
+ {
+ byte[] bytes = { 99, 98, 97, 96, 95 };
+
+ FieldTable table = new FieldTable();
+ table.setBoolean("bool", true);
+ table.setByte("byte", Byte.MAX_VALUE);
+
+ table.setBytes("bytes", bytes);
+ table.setChar("char", 'c');
+ table.setInteger("int", Integer.MAX_VALUE);
+ table.setLong("long", Long.MAX_VALUE);
+ table.setDouble("double", Double.MAX_VALUE);
+ table.setFloat("float", Float.MAX_VALUE);
+ table.setShort("short", Short.MAX_VALUE);
+ table.setString("string", "hello");
+ table.setString("null-string", null);
+
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream((int) table.getEncodedSize() + 4);
+ table.writeToBuffer(new DataOutputStream(baos));
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ DataInputStream dis = new DataInputStream(bais);
+
+
+ long length = dis.readInt() & 0xFFFFFFFFL;
+
+ FieldTable table2 = new FieldTable(dis, length);
+
+ Assert.assertEquals((Boolean) true, table2.getBoolean("bool"));
+ Assert.assertEquals((Byte) Byte.MAX_VALUE, table2.getByte("byte"));
+ assertBytesEqual(bytes, table2.getBytes("bytes"));
+ Assert.assertEquals((Character) 'c', table2.getCharacter("char"));
+ Assert.assertEquals(Double.MAX_VALUE, table2.getDouble("double"));
+ Assert.assertEquals(Float.MAX_VALUE, table2.getFloat("float"));
+ Assert.assertEquals((Integer) Integer.MAX_VALUE, table2.getInteger("int"));
+ Assert.assertEquals((Long) Long.MAX_VALUE, table2.getLong("long"));
+ Assert.assertEquals((Short) Short.MAX_VALUE, table2.getShort("short"));
+ Assert.assertEquals("hello", table2.getString("string"));
+ Assert.assertEquals(null, table2.getString("null-string"));
+ }
+
+ public void testEncodingSize()
+ {
+ FieldTable result = new FieldTable();
+ int size = 0;
+
+ result.setBoolean("boolean", true);
+ size += 1 + EncodingUtils.encodedShortStringLength("boolean") + EncodingUtils.encodedBooleanLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setByte("byte", (byte) Byte.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("byte") + EncodingUtils.encodedByteLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ byte[] _bytes = { 99, 98, 97, 96, 95 };
+
+ result.setBytes("bytes", _bytes);
+ size += 1 + EncodingUtils.encodedShortStringLength("bytes") + 4 + _bytes.length;
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setChar("char", (char) 'c');
+ size += 1 + EncodingUtils.encodedShortStringLength("char") + EncodingUtils.encodedCharLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setDouble("double", (double) Double.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("double") + EncodingUtils.encodedDoubleLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setFloat("float", (float) Float.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("float") + EncodingUtils.encodedFloatLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setInteger("int", (int) Integer.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("int") + EncodingUtils.encodedIntegerLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setLong("long", (long) Long.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("long") + EncodingUtils.encodedLongLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setShort("short", (short) Short.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("short") + EncodingUtils.encodedShortLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setString("result", "Hello");
+ size += 1 + EncodingUtils.encodedShortStringLength("result") + EncodingUtils.encodedLongStringLength("Hello");
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-bool", true);
+ size += 1 + EncodingUtils.encodedShortStringLength("object-bool") + EncodingUtils.encodedBooleanLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-byte", Byte.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("object-byte") + EncodingUtils.encodedByteLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-bytes", _bytes);
+ size += 1 + EncodingUtils.encodedShortStringLength("object-bytes") + 4 + _bytes.length;
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-char", 'c');
+ size += 1 + EncodingUtils.encodedShortStringLength("object-char") + EncodingUtils.encodedCharLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-double", Double.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("object-double") + EncodingUtils.encodedDoubleLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-float", Float.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("object-float") + EncodingUtils.encodedFloatLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-int", Integer.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("object-int") + EncodingUtils.encodedIntegerLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-long", Long.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("object-long") + EncodingUtils.encodedLongLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+
+ result.setObject("object-short", Short.MAX_VALUE);
+ size += 1 + EncodingUtils.encodedShortStringLength("object-short") + EncodingUtils.encodedShortLength();
+ Assert.assertEquals(size, result.getEncodedSize());
+ }
+
+ /**
+ * Additional test for setObject
+ */
+ public void testSetObject()
+ {
+ FieldTable table = new FieldTable();
+
+ // Try setting a non primative object
+
+ try
+ {
+ table.setObject("value", this);
+ fail("Only primative values allowed in setObject");
+ }
+ catch (AMQPInvalidClassException iae)
+ {
+ // normal path
+ }
+ // so length should be zero
+ Assert.assertEquals(0, table.getEncodedSize());
+ }
+
+ /**
+ * Additional test checkPropertyName doesn't accept Null
+ */
+ public void testCheckPropertyNameasNull()
+ {
+ FieldTable table = new FieldTable();
+
+ try
+ {
+ table.setObject((String) null, "String");
+ fail("Null property name is not allowed");
+ }
+ catch (IllegalArgumentException iae)
+ {
+ // normal path
+ }
+ // so length should be zero
+ Assert.assertEquals(0, table.getEncodedSize());
+ }
+
+ /**
+ * Additional test checkPropertyName doesn't accept an empty String
+ */
+ public void testCheckPropertyNameasEmptyString()
+ {
+ FieldTable table = new FieldTable();
+
+ try
+ {
+ table.setObject("", "String");
+ fail("empty property name is not allowed");
+ }
+ catch (IllegalArgumentException iae)
+ {
+ // normal path
+ }
+ // so length should be zero
+ Assert.assertEquals(0, table.getEncodedSize());
+ }
+
+ /**
+ * Additional test checkPropertyName doesn't accept an empty String
+ */
+ public void testCheckPropertyNamehasMaxLength()
+ {
+ FieldTable table = new FieldTable(true);
+
+ StringBuffer longPropertyName = new StringBuffer(129);
+
+ for (int i = 0; i < 129; i++)
+ {
+ longPropertyName.append("x");
+ }
+
+ try
+ {
+ table.setObject(longPropertyName.toString(), "String");
+ fail("property name must be < 128 characters");
+ }
+ catch (IllegalArgumentException iae)
+ {
+ // normal path
+ }
+ // so length should be zero
+ Assert.assertEquals(0, table.getEncodedSize());
+ }
+
+ /**
+ * Additional test checkPropertyName starts with a letter
+ */
+ public void testCheckPropertyNameStartCharacterIsLetter()
+ {
+ FieldTable table = new FieldTable(true);
+
+ // Try a name that starts with a number
+ try
+ {
+ table.setObject("1", "String");
+ fail("property name must start with a letter");
+ }
+ catch (IllegalArgumentException iae)
+ {
+ // normal path
+ }
+ // so length should be zero
+ Assert.assertEquals(0, table.getEncodedSize());
+ }
+
+ /**
+ * Additional test checkPropertyName starts with a hash or a dollar
+ */
+ public void testCheckPropertyNameStartCharacterIsHashorDollar()
+ {
+ FieldTable table = new FieldTable(true);
+
+ // Try a name that starts with a number
+ try
+ {
+ table.setObject("#", "String");
+ table.setObject("$", "String");
+ }
+ catch (IllegalArgumentException iae)
+ {
+ fail("property name are allowed to start with # and $s");
+ }
+ }
+
+ /**
+ * Additional test to test the contents of the table
+ */
+ public void testContents()
+ {
+ FieldTable table = new FieldTable();
+
+ table.setObject("StringProperty", "String");
+
+ Assert.assertEquals("String", table.getString("StringProperty"));
+
+ // Test Clear
+
+ table.clear();
+
+ checkEmpty(table);
+ }
+
+ /**
+ * Test the contents of the sets
+ */
+ public void testSets()
+ {
+
+ FieldTable table = new FieldTable();
+
+ table.setObject("n1", "1");
+ table.setObject("n2", "2");
+ table.setObject("n3", "3");
+
+ Assert.assertEquals("1", table.getObject("n1"));
+ Assert.assertEquals("2", table.getObject("n2"));
+ Assert.assertEquals("3", table.getObject("n3"));
+ }
+
+ public void testAddAll()
+ {
+ final FieldTable table1 = new FieldTable();
+ table1.setInteger("int1", 1);
+ table1.setInteger("int2", 2);
+ assertEquals("Unexpected number of entries in table1", 2, table1.size());
+
+ final FieldTable table2 = new FieldTable();
+ table2.setInteger("int3", 3);
+ table2.setInteger("int4", 4);
+ assertEquals("Unexpected number of entries in table2", 2, table2.size());
+
+ table1.addAll(table2);
+ assertEquals("Unexpected number of entries in table1 after addAll", 4, table1.size());
+ assertEquals(Integer.valueOf(3), table1.getInteger("int3"));
+ }
+
+ public void testAddAllWithEmptyFieldTable()
+ {
+ final FieldTable table1 = new FieldTable();
+ table1.setInteger("int1", 1);
+ table1.setInteger("int2", 2);
+ assertEquals("Unexpected number of entries in table1", 2, table1.size());
+
+ final FieldTable emptyFieldTable = new FieldTable();
+
+ table1.addAll(emptyFieldTable);
+ assertEquals("Unexpected number of entries in table1 after addAll", 2, table1.size());
+ }
+
+ /**
+ * Tests that when copying properties into a new FielTable using the addAll() method, the
+ * properties are successfully added to the destination table when the source FieldTable
+ * was created from encoded input bytes,
+ */
+ public void testAddingAllFromFieldTableCreatedUsingEncodedBytes() throws Exception
+ {
+ AMQShortString myBooleanTestProperty = new AMQShortString("myBooleanTestProperty");
+
+ //Create a new FieldTable and use it to encode data into a byte array.
+ FieldTable encodeTable = new FieldTable();
+ encodeTable.put(myBooleanTestProperty, true);
+ byte[] data = encodeTable.getDataAsBytes();
+ int length = data.length;
+
+ //Verify we got the expected mount of encoded data (1B type hdr + 21B for name + 1B type hdr + 1B for boolean)
+ assertEquals("unexpected data length", 24, length);
+
+ //Create a second FieldTable from the encoded bytes
+ FieldTable tableFromBytes = new FieldTable(new DataInputStream(new ByteArrayInputStream(data)), length);
+
+ //Create a final FieldTable and addAll() from the table created with encoded bytes
+ FieldTable destinationTable = new FieldTable();
+ assertTrue("unexpected size", destinationTable.isEmpty());
+ destinationTable.addAll(tableFromBytes);
+
+ //Verify that the destination table now contains the expected entry
+ assertEquals("unexpected size", 1, destinationTable.size());
+ assertTrue("expected property not present", destinationTable.containsKey(myBooleanTestProperty));
+ assertTrue("unexpected property value", destinationTable.getBoolean(myBooleanTestProperty));
+ }
+
+ private void assertBytesEqual(byte[] expected, byte[] actual)
+ {
+ Assert.assertEquals(expected.length, actual.length);
+
+ for (int index = 0; index < expected.length; index++)
+ {
+ Assert.assertEquals(expected[index], actual[index]);
+ }
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new junit.framework.TestSuite(FieldTableTest.class);
+ }
+
+}
diff --git a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
deleted file mode 100644
index 16f35613d8..0000000000
--- a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
+++ /dev/null
@@ -1,980 +0,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.
- *
- */
-package org.apache.qpid.framing;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.qpid.AMQPInvalidClassException;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-public class PropertyFieldTableTest extends TestCase
-{
- private static final Logger _logger = LoggerFactory.getLogger(PropertyFieldTableTest.class);
-
- /**
- * Test that setting a similar named value replaces any previous value set on that name
- */
- public void testReplacement()
- {
- FieldTable table1 = new FieldTable();
- // Set a boolean value
- table1.setBoolean("value", true);
- // Check length of table is correct (<Value length> + <type> + <Boolean length>)
- int size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedBooleanLength();
- Assert.assertEquals(size, table1.getEncodedSize());
-
- // reset value to an integer
- table1.setInteger("value", Integer.MAX_VALUE);
-
- // Check the length has changed accordingly (<Value length> + <type> + <Integer length>)
- size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedIntegerLength();
- Assert.assertEquals(size, table1.getEncodedSize());
-
- // Check boolean value is null
- Assert.assertEquals(null, table1.getBoolean("value"));
- // ... and integer value is good
- Assert.assertEquals((Integer) Integer.MAX_VALUE, table1.getInteger("value"));
- }
-
- /**
- * Set a boolean and check that we can only get it back as a boolean and a string
- * Check that attempting to lookup a non existent value returns null
- */
- public void testBoolean()
- {
- FieldTable table1 = new FieldTable();
- table1.setBoolean("value", true);
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Test Getting right value back
- Assert.assertEquals((Boolean) true, table1.getBoolean("value"));
-
- // Check we don't get anything back for other gets
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
-
- // except value as a string
- Assert.assertEquals("true", table1.getString("value"));
-
- table1.remove("value");
-
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getBoolean("Rubbish"));
- }
-
- /**
- * Set a byte and check that we can only get it back as a byte and a string
- * Check that attempting to lookup a non existent value returns null
- */
- public void testByte()
- {
- FieldTable table1 = new FieldTable();
- table1.setByte("value", Byte.MAX_VALUE);
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Tests lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(Byte.MAX_VALUE, (byte) table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
-
- // ... and a the string value of it.
- Assert.assertEquals("" + Byte.MAX_VALUE, table1.getString("value"));
-
- table1.remove("value");
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getByte("Rubbish"));
- }
-
- /**
- * Set a short and check that we can only get it back as a short and a string
- * Check that attempting to lookup a non existent value returns null
- */
- public void testShort()
- {
- FieldTable table1 = new FieldTable();
- table1.setShort("value", Short.MAX_VALUE);
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Tests lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(Short.MAX_VALUE, (short) table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
-
- // ... and a the string value of it.
- Assert.assertEquals("" + Short.MAX_VALUE, table1.getString("value"));
-
- table1.remove("value");
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getShort("Rubbish"));
- }
-
- /**
- * Set a char and check that we can only get it back as a char
- * Check that attempting to lookup a non existent value returns null
- */
- public void testChar()
- {
- FieldTable table1 = new FieldTable();
- table1.setChar("value", 'c');
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Tests lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals('c', (char) table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
-
- // ... and a the string value of it.
- Assert.assertEquals("c", table1.getString("value"));
-
- table1.remove("value");
-
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getCharacter("Rubbish"));
- }
-
- /**
- * Set a double and check that we can only get it back as a double
- * Check that attempting to lookup a non existent value returns null
- */
- public void testDouble()
- {
- FieldTable table1 = new FieldTable();
- table1.setDouble("value", Double.MAX_VALUE);
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Tests lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(Double.MAX_VALUE, (double) table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
-
- // ... and a the string value of it.
- Assert.assertEquals("" + Double.MAX_VALUE, table1.getString("value"));
- table1.remove("value");
- // but after a removeKey it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getDouble("Rubbish"));
- }
-
- /**
- * Set a float and check that we can only get it back as a float
- * Check that attempting to lookup a non existent value returns null
- */
- public void testFloat()
- {
- FieldTable table1 = new FieldTable();
- table1.setFloat("value", Float.MAX_VALUE);
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Tests lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(Float.MAX_VALUE, (float) table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
-
- // ... and a the string value of it.
- Assert.assertEquals("" + Float.MAX_VALUE, table1.getString("value"));
-
- table1.remove("value");
- // but after a removeKey it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getFloat("Rubbish"));
- }
-
- /**
- * Set an int and check that we can only get it back as an int
- * Check that attempting to lookup a non existent value returns null
- */
- public void testInt()
- {
- FieldTable table1 = new FieldTable();
- table1.setInteger("value", Integer.MAX_VALUE);
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Tets lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(Integer.MAX_VALUE, (int) table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
-
- // ... and a the string value of it.
- Assert.assertEquals("" + Integer.MAX_VALUE, table1.getString("value"));
-
- table1.remove("value");
- // but after a removeKey it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getInteger("Rubbish"));
- }
-
- /**
- * Set a long and check that we can only get it back as a long
- * Check that attempting to lookup a non existent value returns null
- */
- public void testLong()
- {
- FieldTable table1 = new FieldTable();
- table1.setLong("value", Long.MAX_VALUE);
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Tets lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(Long.MAX_VALUE, (long) table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
-
- // ... and a the string value of it.
- Assert.assertEquals("" + Long.MAX_VALUE, table1.getString("value"));
-
- table1.remove("value");
- // but after a removeKey it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getLong("Rubbish"));
- }
-
- /**
- * Set a double and check that we can only get it back as a double
- * Check that attempting to lookup a non existent value returns null
- */
- public void testBytes()
- {
- byte[] bytes = { 99, 98, 97, 96, 95 };
-
- FieldTable table1 = new FieldTable();
- table1.setBytes("value", bytes);
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Tets lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- assertBytesEqual(bytes, table1.getBytes("value"));
-
- // ... and a the string value of it is null
- Assert.assertEquals(null, table1.getString("value"));
-
- table1.remove("value");
- // but after a removeKey it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero length for encoding
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getBytes("Rubbish"));
- }
-
- /**
- * Calls all methods that can be used to check the table is empty
- * - getEncodedSize
- * - isEmpty
- * - length
- *
- * @param table to check is empty
- */
- private void checkEmpty(FieldTable table)
- {
- Assert.assertEquals(0, table.getEncodedSize());
- Assert.assertTrue(table.isEmpty());
- Assert.assertEquals(0, table.size());
-
- Assert.assertEquals(0, table.keySet().size());
- }
-
- /**
- * Set a String and check that we can only get it back as a String
- * Check that attempting to lookup a non existent value returns null
- */
- public void testString()
- {
- FieldTable table1 = new FieldTable();
- table1.setString("value", "Hello");
- Assert.assertTrue(table1.propertyExists("value"));
-
- // Test lookups we shouldn't get anything back for other gets
- // we should get right value back for this type ....
- Assert.assertEquals(null, table1.getBoolean("value"));
- Assert.assertEquals(null, table1.getByte("value"));
- Assert.assertEquals(null, table1.getShort("value"));
- Assert.assertEquals(null, table1.getCharacter("value"));
- Assert.assertEquals(null, table1.getDouble("value"));
- Assert.assertEquals(null, table1.getFloat("value"));
- Assert.assertEquals(null, table1.getInteger("value"));
- Assert.assertEquals(null, table1.getLong("value"));
- Assert.assertEquals(null, table1.getBytes("value"));
- Assert.assertEquals("Hello", table1.getString("value"));
-
- // Try setting a null value and read it back
- table1.setString("value", null);
-
- Assert.assertEquals(null, table1.getString("value"));
-
- // but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
- table1.remove("value");
- // but after a removeKey it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- checkEmpty(table1);
-
- // Looking up an invalid value returns null
- Assert.assertEquals(null, table1.getString("Rubbish"));
-
- // Additional Test that haven't been covered for string
- table1.setObject("value", "Hello");
- // Check that it was set correctly
- Assert.assertEquals("Hello", table1.getString("value"));
- }
-
- /** Check that a nested field table parameter correctly encodes and decodes to a byte buffer. */
- public void testNestedFieldTable() throws IOException
- {
- byte[] testBytes = new byte[] { 0, 1, 2, 3, 4, 5 };
-
- FieldTable outerTable = new FieldTable();
- FieldTable innerTable = new FieldTable();
-
- // Put some stuff in the inner table.
- innerTable.setBoolean("bool", true);
- innerTable.setByte("byte", Byte.MAX_VALUE);
- innerTable.setBytes("bytes", testBytes);
- innerTable.setChar("char", 'c');
- innerTable.setDouble("double", Double.MAX_VALUE);
- innerTable.setFloat("float", Float.MAX_VALUE);
- innerTable.setInteger("int", Integer.MAX_VALUE);
- innerTable.setLong("long", Long.MAX_VALUE);
- innerTable.setShort("short", Short.MAX_VALUE);
- innerTable.setString("string", "hello");
- innerTable.setString("null-string", null);
-
- // Put the inner table in the outer one.
- outerTable.setFieldTable("innerTable", innerTable);
-
- // Write the outer table into the buffer.
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- outerTable.writeToBuffer(new DataOutputStream(baos));
-
- byte[] data = baos.toByteArray();
-
- // Extract the table back from the buffer again.
- try
- {
- FieldTable extractedOuterTable = EncodingUtils.readFieldTable(new DataInputStream(new ByteArrayInputStream(data)));
-
- FieldTable extractedTable = extractedOuterTable.getFieldTable("innerTable");
-
- Assert.assertEquals((Boolean) true, extractedTable.getBoolean("bool"));
- Assert.assertEquals((Byte) Byte.MAX_VALUE, extractedTable.getByte("byte"));
- assertBytesEqual(testBytes, extractedTable.getBytes("bytes"));
- Assert.assertEquals((Character) 'c', extractedTable.getCharacter("char"));
- Assert.assertEquals(Double.MAX_VALUE, extractedTable.getDouble("double"));
- Assert.assertEquals(Float.MAX_VALUE, extractedTable.getFloat("float"));
- Assert.assertEquals((Integer) Integer.MAX_VALUE, extractedTable.getInteger("int"));
- Assert.assertEquals((Long) Long.MAX_VALUE, extractedTable.getLong("long"));
- Assert.assertEquals((Short) Short.MAX_VALUE, extractedTable.getShort("short"));
- Assert.assertEquals("hello", extractedTable.getString("string"));
- Assert.assertEquals(null, extractedTable.getString("null-string"));
- }
- catch (AMQFrameDecodingException e)
- {
- fail("Failed to decode field table with nested inner table.");
- }
- }
-
- public void testValues()
- {
- FieldTable table = new FieldTable();
- table.setBoolean("bool", true);
- table.setByte("byte", Byte.MAX_VALUE);
- byte[] bytes = { 99, 98, 97, 96, 95 };
- table.setBytes("bytes", bytes);
- table.setChar("char", 'c');
- table.setDouble("double", Double.MAX_VALUE);
- table.setFloat("float", Float.MAX_VALUE);
- table.setInteger("int", Integer.MAX_VALUE);
- table.setLong("long", Long.MAX_VALUE);
- table.setShort("short", Short.MAX_VALUE);
- table.setString("string", "Hello");
- table.setString("null-string", null);
-
- table.setObject("object-bool", true);
- table.setObject("object-byte", Byte.MAX_VALUE);
- table.setObject("object-bytes", bytes);
- table.setObject("object-char", 'c');
- table.setObject("object-double", Double.MAX_VALUE);
- table.setObject("object-float", Float.MAX_VALUE);
- table.setObject("object-int", Integer.MAX_VALUE);
- table.setObject("object-long", Long.MAX_VALUE);
- table.setObject("object-short", Short.MAX_VALUE);
- table.setObject("object-string", "Hello");
-
- try
- {
- table.setObject("Null-object", null);
- fail("null values are not allowed");
- }
- catch (AMQPInvalidClassException aice)
- {
- assertEquals("Null values are not allowed to be set",
- AMQPInvalidClassException.INVALID_OBJECT_MSG + "null", aice.getMessage());
- }
-
- try
- {
- table.setObject("Unsupported-object", new Exception());
- fail("Non primitive values are not allowed");
- }
- catch (AMQPInvalidClassException aice)
- {
- assertEquals("Non primitive values are not allowed to be set",
- AMQPInvalidClassException.INVALID_OBJECT_MSG + Exception.class, aice.getMessage());
- }
-
- Assert.assertEquals((Boolean) true, table.getBoolean("bool"));
- Assert.assertEquals((Byte) Byte.MAX_VALUE, table.getByte("byte"));
- assertBytesEqual(bytes, table.getBytes("bytes"));
- Assert.assertEquals((Character) 'c', table.getCharacter("char"));
- Assert.assertEquals(Double.MAX_VALUE, table.getDouble("double"));
- Assert.assertEquals(Float.MAX_VALUE, table.getFloat("float"));
- Assert.assertEquals((Integer) Integer.MAX_VALUE, table.getInteger("int"));
- Assert.assertEquals((Long) Long.MAX_VALUE, table.getLong("long"));
- Assert.assertEquals((Short) Short.MAX_VALUE, table.getShort("short"));
- Assert.assertEquals("Hello", table.getString("string"));
- Assert.assertEquals(null, table.getString("null-string"));
-
- Assert.assertEquals(true, table.getObject("object-bool"));
- Assert.assertEquals(Byte.MAX_VALUE, table.getObject("object-byte"));
- assertBytesEqual(bytes, (byte[]) table.getObject("object-bytes"));
- Assert.assertEquals('c', table.getObject("object-char"));
- Assert.assertEquals(Double.MAX_VALUE, table.getObject("object-double"));
- Assert.assertEquals(Float.MAX_VALUE, table.getObject("object-float"));
- Assert.assertEquals(Integer.MAX_VALUE, table.getObject("object-int"));
- Assert.assertEquals(Long.MAX_VALUE, table.getObject("object-long"));
- Assert.assertEquals(Short.MAX_VALUE, table.getObject("object-short"));
- Assert.assertEquals("Hello", table.getObject("object-string"));
- }
-
- public void testWriteBuffer() throws IOException
- {
- byte[] bytes = { 99, 98, 97, 96, 95 };
-
- FieldTable table = new FieldTable();
- table.setBoolean("bool", true);
- table.setByte("byte", Byte.MAX_VALUE);
-
- table.setBytes("bytes", bytes);
- table.setChar("char", 'c');
- table.setInteger("int", Integer.MAX_VALUE);
- table.setLong("long", Long.MAX_VALUE);
- table.setDouble("double", Double.MAX_VALUE);
- table.setFloat("float", Float.MAX_VALUE);
- table.setShort("short", Short.MAX_VALUE);
- table.setString("string", "hello");
- table.setString("null-string", null);
-
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream((int) table.getEncodedSize() + 4);
- table.writeToBuffer(new DataOutputStream(baos));
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- DataInputStream dis = new DataInputStream(bais);
-
-
- long length = dis.readInt() & 0xFFFFFFFFL;
-
- FieldTable table2 = new FieldTable(dis, length);
-
- Assert.assertEquals((Boolean) true, table2.getBoolean("bool"));
- Assert.assertEquals((Byte) Byte.MAX_VALUE, table2.getByte("byte"));
- assertBytesEqual(bytes, table2.getBytes("bytes"));
- Assert.assertEquals((Character) 'c', table2.getCharacter("char"));
- Assert.assertEquals(Double.MAX_VALUE, table2.getDouble("double"));
- Assert.assertEquals(Float.MAX_VALUE, table2.getFloat("float"));
- Assert.assertEquals((Integer) Integer.MAX_VALUE, table2.getInteger("int"));
- Assert.assertEquals((Long) Long.MAX_VALUE, table2.getLong("long"));
- Assert.assertEquals((Short) Short.MAX_VALUE, table2.getShort("short"));
- Assert.assertEquals("hello", table2.getString("string"));
- Assert.assertEquals(null, table2.getString("null-string"));
- }
-
- public void testEncodingSize()
- {
- FieldTable result = new FieldTable();
- int size = 0;
-
- result.setBoolean("boolean", true);
- size += 1 + EncodingUtils.encodedShortStringLength("boolean") + EncodingUtils.encodedBooleanLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setByte("byte", (byte) Byte.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("byte") + EncodingUtils.encodedByteLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- byte[] _bytes = { 99, 98, 97, 96, 95 };
-
- result.setBytes("bytes", _bytes);
- size += 1 + EncodingUtils.encodedShortStringLength("bytes") + 4 + _bytes.length;
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setChar("char", (char) 'c');
- size += 1 + EncodingUtils.encodedShortStringLength("char") + EncodingUtils.encodedCharLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setDouble("double", (double) Double.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("double") + EncodingUtils.encodedDoubleLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setFloat("float", (float) Float.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("float") + EncodingUtils.encodedFloatLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setInteger("int", (int) Integer.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("int") + EncodingUtils.encodedIntegerLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setLong("long", (long) Long.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("long") + EncodingUtils.encodedLongLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setShort("short", (short) Short.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("short") + EncodingUtils.encodedShortLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setString("result", "Hello");
- size += 1 + EncodingUtils.encodedShortStringLength("result") + EncodingUtils.encodedLongStringLength("Hello");
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-bool", true);
- size += 1 + EncodingUtils.encodedShortStringLength("object-bool") + EncodingUtils.encodedBooleanLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-byte", Byte.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("object-byte") + EncodingUtils.encodedByteLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-bytes", _bytes);
- size += 1 + EncodingUtils.encodedShortStringLength("object-bytes") + 4 + _bytes.length;
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-char", 'c');
- size += 1 + EncodingUtils.encodedShortStringLength("object-char") + EncodingUtils.encodedCharLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-double", Double.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("object-double") + EncodingUtils.encodedDoubleLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-float", Float.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("object-float") + EncodingUtils.encodedFloatLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-int", Integer.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("object-int") + EncodingUtils.encodedIntegerLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-long", Long.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("object-long") + EncodingUtils.encodedLongLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- result.setObject("object-short", Short.MAX_VALUE);
- size += 1 + EncodingUtils.encodedShortStringLength("object-short") + EncodingUtils.encodedShortLength();
- Assert.assertEquals(size, result.getEncodedSize());
-
- }
-
- // public void testEncodingSize1()
- // {
- // PropertyFieldTable table = new PropertyFieldTable();
- // int length = 0;
- // result.put("one", 1L);
- // length = EncodingUtils.encodedShortStringLength("one");
- // length += 1 + EncodingUtils.encodedLongLength();
- // assertEquals(length, result.getEncodedSize());
- //
- // result.put("two", 2L);
- // length += EncodingUtils.encodedShortStringLength("two");
- // length += 1 + EncodingUtils.encodedLongLength();
- // assertEquals(length, result.getEncodedSize());
- //
- // result.put("three", 3L);
- // length += EncodingUtils.encodedShortStringLength("three");
- // length += 1 + EncodingUtils.encodedLongLength();
- // assertEquals(length, result.getEncodedSize());
- //
- // result.put("four", 4L);
- // length += EncodingUtils.encodedShortStringLength("four");
- // length += 1 + EncodingUtils.encodedLongLength();
- // assertEquals(length, result.getEncodedSize());
- //
- // result.put("five", 5L);
- // length += EncodingUtils.encodedShortStringLength("five");
- // length += 1 + EncodingUtils.encodedLongLength();
- // assertEquals(length, result.getEncodedSize());
- //
- // //fixme should perhaps be expanded to incorporate all types.
- //
- // final ByteBuffer buffer = ByteBuffer.allocate((int) result.getEncodedSize()); // FIXME XXX: Is cast a problem?
- //
- // result.writeToBuffer(buffer);
- //
- // buffer.flip();
- //
- // long length = buffer.getUnsignedInt();
- //
- // try
- // {
- // PropertyFieldTable table2 = new PropertyFieldTable(buffer, length);
- //
- // Assert.assertEquals((Long) 1L, table2.getLong("one"));
- // Assert.assertEquals((Long) 2L, table2.getLong("two"));
- // Assert.assertEquals((Long) 3L, table2.getLong("three"));
- // Assert.assertEquals((Long) 4L, table2.getLong("four"));
- // Assert.assertEquals((Long) 5L, table2.getLong("five"));
- // }
- // catch (AMQFrameDecodingException e)
- // {
- // e.printStackTrace();
- // fail("PFT should be instantiated from bytes." + e.getCause());
- // }
- //
- // }
-
- /**
- * Additional test for setObject
- */
- public void testSetObject()
- {
- FieldTable table = new FieldTable();
-
- // Try setting a non primative object
-
- try
- {
- table.setObject("value", this);
- fail("Only primative values allowed in setObject");
- }
- catch (AMQPInvalidClassException iae)
- {
- // normal path
- }
- // so length should be zero
- Assert.assertEquals(0, table.getEncodedSize());
- }
-
- /**
- * Additional test checkPropertyName doesn't accept Null
- */
- public void testCheckPropertyNameasNull()
- {
- FieldTable table = new FieldTable();
-
- try
- {
- table.setObject((String) null, "String");
- fail("Null property name is not allowed");
- }
- catch (IllegalArgumentException iae)
- {
- // normal path
- }
- // so length should be zero
- Assert.assertEquals(0, table.getEncodedSize());
- }
-
- /**
- * Additional test checkPropertyName doesn't accept an empty String
- */
- public void testCheckPropertyNameasEmptyString()
- {
- FieldTable table = new FieldTable();
-
- try
- {
- table.setObject("", "String");
- fail("empty property name is not allowed");
- }
- catch (IllegalArgumentException iae)
- {
- // normal path
- }
- // so length should be zero
- Assert.assertEquals(0, table.getEncodedSize());
- }
-
- /**
- * Additional test checkPropertyName doesn't accept an empty String
- */
- public void testCheckPropertyNamehasMaxLength()
- {
- FieldTable table = new FieldTable(true);
-
- StringBuffer longPropertyName = new StringBuffer(129);
-
- for (int i = 0; i < 129; i++)
- {
- longPropertyName.append("x");
- }
-
- try
- {
- table.setObject(longPropertyName.toString(), "String");
- fail("property name must be < 128 characters");
- }
- catch (IllegalArgumentException iae)
- {
- // normal path
- }
- // so length should be zero
- Assert.assertEquals(0, table.getEncodedSize());
- }
-
- /**
- * Additional test checkPropertyName starts with a letter
- */
- public void testCheckPropertyNameStartCharacterIsLetter()
- {
- FieldTable table = new FieldTable(true);
-
- // Try a name that starts with a number
- try
- {
- table.setObject("1", "String");
- fail("property name must start with a letter");
- }
- catch (IllegalArgumentException iae)
- {
- // normal path
- }
- // so length should be zero
- Assert.assertEquals(0, table.getEncodedSize());
- }
-
- /**
- * Additional test checkPropertyName starts with a hash or a dollar
- */
- public void testCheckPropertyNameStartCharacterIsHashorDollar()
- {
- FieldTable table = new FieldTable(true);
-
- // Try a name that starts with a number
- try
- {
- table.setObject("#", "String");
- table.setObject("$", "String");
- }
- catch (IllegalArgumentException iae)
- {
- fail("property name are allowed to start with # and $s");
- }
-
- }
-
- /**
- * Additional test to test the contents of the table
- */
- public void testContents()
- {
- FieldTable table = new FieldTable();
-
- table.setObject("StringProperty", "String");
-
- Assert.assertEquals("String", table.getString("StringProperty"));
-
- // Test Clear
-
- table.clear();
-
- checkEmpty(table);
- }
-
- /**
- * Test the contents of the sets
- */
- public void testSets()
- {
-
- FieldTable table = new FieldTable();
-
- table.setObject("n1", "1");
- table.setObject("n2", "2");
- table.setObject("n3", "3");
-
- Assert.assertEquals("1", table.getObject("n1"));
- Assert.assertEquals("2", table.getObject("n2"));
- Assert.assertEquals("3", table.getObject("n3"));
-
- }
-
- public void testAddAll()
- {
- final FieldTable table1 = new FieldTable();
- table1.setInteger("int1", 1);
- table1.setInteger("int2", 2);
- assertEquals("Unexpected number of entries in table1", 2, table1.size());
-
- final FieldTable table2 = new FieldTable();
- table2.setInteger("int3", 3);
- table2.setInteger("int4", 4);
- assertEquals("Unexpected number of entries in table2", 2, table2.size());
-
- table1.addAll(table2);
- assertEquals("Unexpected number of entries in table1 after addAll", 4, table1.size());
- assertEquals(Integer.valueOf(3), table1.getInteger("int3"));
- }
-
- public void testAddAllWithEmptyFieldTable()
- {
- final FieldTable table1 = new FieldTable();
- table1.setInteger("int1", 1);
- table1.setInteger("int2", 2);
- assertEquals("Unexpected number of entries in table1", 2, table1.size());
-
- final FieldTable emptyFieldTable = new FieldTable();
-
- table1.addAll(emptyFieldTable);
- assertEquals("Unexpected number of entries in table1 after addAll", 2, table1.size());
- }
-
- private void assertBytesEqual(byte[] expected, byte[] actual)
- {
- Assert.assertEquals(expected.length, actual.length);
-
- for (int index = 0; index < expected.length; index++)
- {
- Assert.assertEquals(expected[index], actual[index]);
- }
- }
-
- private void assertBytesNotEqual(byte[] expected, byte[] actual)
- {
- Assert.assertEquals(expected.length, actual.length);
-
- for (int index = 0; index < expected.length; index++)
- {
- Assert.assertFalse(expected[index] == actual[index]);
- }
- }
-
- public static junit.framework.Test suite()
- {
- return new junit.framework.TestSuite(PropertyFieldTableTest.class);
- }
-
-}
diff --git a/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java b/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
index ec06400b7d..08f7387b75 100644
--- a/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
+++ b/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
@@ -41,6 +41,7 @@ public class QpidTestCase extends TestCase
public static final String QPID_HOME = System.getProperty("QPID_HOME");
public static final String TEST_RESOURCES_DIR = QPID_HOME + "/../test-profiles/test_resources/";
public static final String TMP_FOLDER = System.getProperty("java.io.tmpdir");
+ public static final String LOG4J_CONFIG_FILE_PATH = System.getProperty("log4j.configuration.file");
private static final Logger _logger = Logger.getLogger(QpidTestCase.class);
@@ -115,12 +116,7 @@ public class QpidTestCase extends TestCase
public QpidTestCase()
{
- this("QpidTestCase");
- }
-
- public QpidTestCase(String name)
- {
- super(name);
+ super();
}
public void run(TestResult testResult)
@@ -204,6 +200,8 @@ public class QpidTestCase extends TestCase
{
System.setProperty(property, value);
}
+
+ _logger.info("Set system property \"" + property + "\" to: \"" + value + "\"");
}
/**
diff --git a/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java b/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
index 056d11faaa..14dec8efad 100644
--- a/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
+++ b/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
@@ -21,6 +21,12 @@
package org.apache.qpid.test.utils;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.io.FileOutputStream;
+
+import junit.framework.TestCase;
import org.apache.qpid.util.FileUtils;
@@ -30,6 +36,7 @@ import org.apache.qpid.util.FileUtils;
public class TestFileUtils
{
private static final String SYSTEM_TMP_DIR = System.getProperty("java.io.tmpdir");
+ private static final String SUFFIX = "tmp";
/**
* Create and return a temporary directory that will be deleted on exit.
@@ -60,4 +67,87 @@ public class TestFileUtils
return testDir;
}
+
+ public static File createTempFile(TestCase testcase)
+ {
+ return createTempFile(testcase, SUFFIX);
+ }
+
+ public static File createTempFile(TestCase testcase, String suffix)
+ {
+ String prefix = testcase.getClass().getSimpleName() + "-" + testcase.getName();
+
+ File tmpFile;
+ try
+ {
+ tmpFile = File.createTempFile(prefix, suffix);
+ tmpFile.deleteOnExit();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Cannot create temporary file with prefix " + prefix + " and suffix " + SUFFIX, e);
+ }
+
+ return tmpFile;
+ }
+
+ /**
+ * Creates a temporary file from the resource name given, using the resource name as the file suffix.
+ *
+ * This is required because the tests use the jar files as their class path.
+ */
+ public static File createTempFileFromResource(TestCase testCase, String resourceName)
+ {
+ File dst = createTempFile(testCase, resourceName);
+ InputStream in = testCase.getClass().getResourceAsStream(resourceName);
+ try
+ {
+ FileUtils.copy(in, dst);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Cannot copy resource " + resourceName +
+ " to temp file " + dst.getAbsolutePath(), e);
+ }
+ dst.deleteOnExit();
+ return dst;
+ }
+
+ /**
+ * Creates a temporary file for given test with given suffix in file name.
+ * The given content is stored in the file using UTF-8 encoding.
+ */
+ public static File createTempFile(TestCase testcase, String suffix, String content)
+ {
+ File file = createTempFile(testcase, suffix);
+ if (content != null)
+ {
+ FileOutputStream fos = null;
+ try
+ {
+ fos = new FileOutputStream(file);
+ fos.write(content.getBytes("UTF-8"));
+ fos.flush();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Cannot add the content into temp file " + file.getAbsolutePath(), e);
+ }
+ finally
+ {
+ if (fos != null)
+ {
+ try
+ {
+ fos.close();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Cannot close output stream into temp file " + file.getAbsolutePath(), e);
+ }
+ }
+ }
+ }
+ return file;
+ }
}
diff --git a/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java b/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java
index f3715f351e..12bbd20228 100644
--- a/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java
+++ b/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java
@@ -155,6 +155,7 @@ public class ConnectionTest extends QpidTestCase implements SessionListener
{
final Connection conn = new Connection();
conn.setConnectionDelegate(new ClientDelegate(new ConnectionSettings()));
+
conn.addConnectionListener(new ConnectionListener()
{
public void opened(Connection conn) {}
@@ -225,6 +226,12 @@ public class ConnectionTest extends QpidTestCase implements SessionListener
ssn.setSessionListener(ConnectionTest.this);
return ssn;
}
+
+ @Override
+ public void connectionStartOk(Connection conn, ConnectionStartOk ok)
+ {
+ tuneAuthorizedConnection(conn);
+ }
};
try
diff --git a/java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java b/java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java
index 893f66c5ff..a19c2e7e43 100644
--- a/java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java
+++ b/java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java
@@ -83,6 +83,18 @@ public class TestNetworkConnection implements NetworkConnection
return null;
}
+ @Override
+ public int getMaxReadIdle()
+ {
+ return 0;
+ }
+
+ @Override
+ public int getMaxWriteIdle()
+ {
+ return 0;
+ }
+
public void setMaxWriteIdle(int idleTime)
{
diff --git a/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java b/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java
index c882d3437e..bf9a5843d6 100644
--- a/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java
+++ b/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java
@@ -128,7 +128,8 @@ public class TransportTest extends QpidTestCase
}
public NetworkConnection connect(ConnectionSettings settings,
- Receiver<ByteBuffer> delegate, SSLContext sslContext)
+ Receiver<ByteBuffer> delegate,
+ TransportActivity transportActivity)
{
throw new UnsupportedOperationException();
}
@@ -148,7 +149,7 @@ public class TransportTest extends QpidTestCase
}
public void accept(NetworkTransportConfiguration config,
- ProtocolEngineFactory factory, SSLContext sslContext)
+ ProtocolEngineFactory factory, SSLContext sslContext)
{
throw new UnsupportedOperationException();
}
diff --git a/java/common/src/test/java/org/apache/qpid/transport/network/io/IdleTimeoutTickerTest.java b/java/common/src/test/java/org/apache/qpid/transport/network/io/IdleTimeoutTickerTest.java
new file mode 100644
index 0000000000..5cdd7a8597
--- /dev/null
+++ b/java/common/src/test/java/org/apache/qpid/transport/network/io/IdleTimeoutTickerTest.java
@@ -0,0 +1,257 @@
+/*
+ *
+ * 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.transport.network.io;
+
+import junit.framework.TestCase;
+
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.security.Principal;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.transport.Sender;
+import org.apache.qpid.transport.network.NetworkConnection;
+import org.apache.qpid.transport.network.TransportActivity;
+
+public class IdleTimeoutTickerTest extends TestCase implements TransportActivity, NetworkConnection
+{
+ private IdleTimeoutTicker _ticker;
+ private static final int DEFAULT_TIMEOUT = 567890;
+ private long _lastReadTime;
+ private long _lastWriteTime;
+ private long _currentTime;
+ private int _maxWriteIdle;
+ private int _maxReadIdle;
+ private boolean _readerIdle;
+ private boolean _writerIdle;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ _ticker = new IdleTimeoutTicker(this, DEFAULT_TIMEOUT);
+ _ticker.setConnection(this);
+ _readerIdle = false;
+ _writerIdle = false;
+ _lastReadTime = 0l;
+ _lastWriteTime = 0l;
+ _maxReadIdle = 0;
+ _maxWriteIdle = 0;
+ }
+
+ public void testNoIdle() throws Exception
+ {
+ _maxReadIdle = 4;
+ _maxWriteIdle = 2;
+ _lastReadTime = 0;
+ _lastWriteTime = 1500;
+ _currentTime = 3000;
+ // Current time = 3s,
+ // last read = 0s, max read idle = 4s, should check in 1s
+ // last write = 1.5s, max write idle = 2s, should check in 0.5s
+ long nextTime = _ticker.tick(_currentTime);
+ assertEquals("Incorrect next tick calculation", 500l, nextTime);
+ assertFalse("Incorrectly caused reader idle", _readerIdle);
+ assertFalse("Incorrectly caused writer idle", _writerIdle);
+
+
+ // Current time = 3.4s,
+ // last read = 0s, max read idle = 4s, should check in 0.6s
+ // last write = 3.1s, max write idle = 2s, should check in 1.7s
+ _lastWriteTime = 3100;
+ _currentTime = 3400;
+ nextTime = _ticker.tick(_currentTime);
+ assertEquals("Incorrect next tick calculation", 600l, nextTime);
+ assertFalse("Incorrectly caused reader idle", _readerIdle);
+ assertFalse("Incorrectly caused writer idle", _writerIdle);
+
+ _maxReadIdle = 0;
+ nextTime = _ticker.tick(_currentTime);
+ assertEquals("Incorrect next tick calculation", 1700l, nextTime);
+ assertFalse("Incorrectly caused reader idle", _readerIdle);
+ assertFalse("Incorrectly caused writer idle", _writerIdle);
+
+ _maxWriteIdle = 0;
+ nextTime = _ticker.tick(_currentTime);
+ assertEquals("Incorrect next tick calculation", DEFAULT_TIMEOUT, nextTime);
+ assertFalse("Incorrectly caused reader idle", _readerIdle);
+ assertFalse("Incorrectly caused writer idle", _writerIdle);
+
+ }
+
+ public void testReaderIdle() throws Exception
+ {
+ _maxReadIdle = 4;
+ _maxWriteIdle = 0;
+ _lastReadTime = 0;
+ _lastWriteTime = 2500;
+ _currentTime = 4000;
+ // Current time = 4s,
+ // last read = 0s, max read idle = 4s, reader idle
+ long nextTime = _ticker.tick(_currentTime);
+
+ assertTrue(_readerIdle);
+ assertFalse(_writerIdle);
+
+ _readerIdle = false;
+
+ // last write = 2.5s, max write idle = 2s, should check in 0.5s
+ _maxWriteIdle = 2;
+ nextTime = _ticker.tick(_currentTime);
+ assertTrue(_readerIdle);
+ assertFalse(_writerIdle);
+
+ _readerIdle = false;
+ // last write = 1.5s, max write idle = 2s, should check in 0.5s
+
+ _lastWriteTime = 1500;
+ nextTime = _ticker.tick(_currentTime);
+
+ assertTrue(_readerIdle);
+ assertTrue(_writerIdle);
+
+ }
+
+ public void testWriterIdle() throws Exception
+ {
+ _maxReadIdle = 0;
+ _maxWriteIdle = 2;
+ _lastReadTime = 0;
+ _lastWriteTime = 1500;
+ _currentTime = 4000;
+ // Current time = 4s,
+ // last write = 1.5s, max write idle = 2s, writer idle
+ long nextTime = _ticker.tick(_currentTime);
+
+ assertTrue(_writerIdle);
+ assertFalse(_readerIdle);
+ assertEquals(2000l,nextTime);
+
+ _writerIdle = false;
+ _lastWriteTime = 1500;
+ _maxReadIdle = 5;
+
+ nextTime = _ticker.tick(_currentTime);
+
+ assertTrue(_writerIdle);
+ assertFalse(_readerIdle);
+ assertEquals(1000l,nextTime);
+
+ }
+
+ //-------------------------------------------------------------------------
+ // Implement TransportActivity methods
+ //-------------------------------------------------------------------------
+
+ @Override
+ public long getLastReadTime()
+ {
+ return _lastReadTime;
+ }
+
+ @Override
+ public long getLastWriteTime()
+ {
+ return _lastWriteTime;
+ }
+
+ @Override
+ public void writerIdle()
+ {
+ _writerIdle = true;
+ _lastWriteTime = _currentTime;
+ }
+
+ @Override
+ public void readerIdle()
+ {
+ _readerIdle = true;
+ }
+
+ //-------------------------------------------------------------------------
+ // Implement NetworkConnection methods
+ // Only actually use those relating to idle timeouts
+ //-------------------------------------------------------------------------
+
+ @Override
+ public Sender<ByteBuffer> getSender()
+ {
+ return null;
+ }
+
+ @Override
+ public void start()
+ {
+ }
+
+ @Override
+ public void close()
+ {
+ }
+
+ @Override
+ public SocketAddress getRemoteAddress()
+ {
+ return null;
+ }
+
+ @Override
+ public SocketAddress getLocalAddress()
+ {
+ return null;
+ }
+
+ @Override
+ public void setMaxWriteIdle(int sec)
+ {
+ _maxWriteIdle = sec;
+ }
+
+ @Override
+ public void setMaxReadIdle(int sec)
+ {
+ _maxReadIdle = sec;
+ }
+
+ @Override
+ public void setPeerPrincipal(Principal principal)
+ {
+ }
+
+ @Override
+ public Principal getPeerPrincipal()
+ {
+ return null;
+ }
+
+ @Override
+ public int getMaxReadIdle()
+ {
+ return _maxReadIdle;
+ }
+
+ @Override
+ public int getMaxWriteIdle()
+ {
+ return _maxWriteIdle;
+ }
+}
diff --git a/java/ivy.nexus.xml b/java/ivy.nexus.xml
index 61ae9f315b..c39f466da3 100644
--- a/java/ivy.nexus.xml
+++ b/java/ivy.nexus.xml
@@ -39,6 +39,42 @@
<artifact name="qpid-broker" type="jar.asc" ext="jar.asc"/>
<artifact name="qpid-broker" type="source" ext="jar" e:classifier="sources"/>
<artifact name="qpid-broker" type="source.asc" ext="jar.asc" e:classifier="sources"/>
+ <artifact name="qpid-broker-plugins-access-control" type="pom" ext="pom"/>
+ <artifact name="qpid-broker-plugins-access-control" type="pom.asc" ext="pom.asc"/>
+ <artifact name="qpid-broker-plugins-access-control" type="jar" ext="jar"/>
+ <artifact name="qpid-broker-plugins-access-control" type="jar.asc" ext="jar.asc"/>
+ <artifact name="qpid-broker-plugins-access-control" type="source" ext="jar" e:classifier="sources"/>
+ <artifact name="qpid-broker-plugins-access-control" type="source.asc" ext="jar.asc" e:classifier="sources"/>
+ <artifact name="qpid-broker-plugins-management-http" type="pom" ext="pom"/>
+ <artifact name="qpid-broker-plugins-management-http" type="pom.asc" ext="pom.asc"/>
+ <artifact name="qpid-broker-plugins-management-http" type="jar" ext="jar"/>
+ <artifact name="qpid-broker-plugins-management-http" type="jar.asc" ext="jar.asc"/>
+ <artifact name="qpid-broker-plugins-management-http" type="source" ext="jar" e:classifier="sources"/>
+ <artifact name="qpid-broker-plugins-management-http" type="source.asc" ext="jar.asc" e:classifier="sources"/>
+ <artifact name="qpid-broker-plugins-management-jmx" type="pom" ext="pom"/>
+ <artifact name="qpid-broker-plugins-management-jmx" type="pom.asc" ext="pom.asc"/>
+ <artifact name="qpid-broker-plugins-management-jmx" type="jar" ext="jar"/>
+ <artifact name="qpid-broker-plugins-management-jmx" type="jar.asc" ext="jar.asc"/>
+ <artifact name="qpid-broker-plugins-management-jmx" type="source" ext="jar" e:classifier="sources"/>
+ <artifact name="qpid-broker-plugins-management-jmx" type="source.asc" ext="jar.asc" e:classifier="sources"/>
+ <artifact name="qpid-amqp-1-0-common" type="pom" ext="pom"/>
+ <artifact name="qpid-amqp-1-0-common" type="pom.asc" ext="pom.asc"/>
+ <artifact name="qpid-amqp-1-0-common" type="jar" ext="jar"/>
+ <artifact name="qpid-amqp-1-0-common" type="jar.asc" ext="jar.asc"/>
+ <artifact name="qpid-amqp-1-0-common" type="source" ext="jar" e:classifier="sources"/>
+ <artifact name="qpid-amqp-1-0-common" type="source.asc" ext="jar.asc" e:classifier="sources"/>
+ <artifact name="qpid-amqp-1-0-client" type="pom" ext="pom"/>
+ <artifact name="qpid-amqp-1-0-client" type="pom.asc" ext="pom.asc"/>
+ <artifact name="qpid-amqp-1-0-client" type="jar" ext="jar"/>
+ <artifact name="qpid-amqp-1-0-client" type="jar.asc" ext="jar.asc"/>
+ <artifact name="qpid-amqp-1-0-client" type="source" ext="jar" e:classifier="sources"/>
+ <artifact name="qpid-amqp-1-0-client" type="source.asc" ext="jar.asc" e:classifier="sources"/>
+ <artifact name="qpid-amqp-1-0-client-jms" type="pom" ext="pom"/>
+ <artifact name="qpid-amqp-1-0-client-jms" type="pom.asc" ext="pom.asc"/>
+ <artifact name="qpid-amqp-1-0-client-jms" type="jar" ext="jar"/>
+ <artifact name="qpid-amqp-1-0-client-jms" type="jar.asc" ext="jar.asc"/>
+ <artifact name="qpid-amqp-1-0-client-jms" type="source" ext="jar" e:classifier="sources"/>
+ <artifact name="qpid-amqp-1-0-client-jms" type="source.asc" ext="jar.asc" e:classifier="sources"/>
<artifact name="qpid-management-common" type="pom" ext="pom"/>
<artifact name="qpid-management-common" type="pom.asc" ext="pom.asc"/>
<artifact name="qpid-management-common" type="jar" ext="jar"/>
@@ -51,6 +87,12 @@
<artifact name="qpid-bdbstore" type="jar.asc" ext="jar.asc"/>
<artifact name="qpid-bdbstore" type="source" ext="jar" e:classifier="sources"/>
<artifact name="qpid-bdbstore" type="source.asc" ext="jar.asc" e:classifier="sources"/>
+ <artifact name="qpid-bdbstore-jmx" type="pom" ext="pom"/>
+ <artifact name="qpid-bdbstore-jmx" type="pom.asc" ext="pom.asc"/>
+ <artifact name="qpid-bdbstore-jmx" type="jar" ext="jar"/>
+ <artifact name="qpid-bdbstore-jmx" type="jar.asc" ext="jar.asc"/>
+ <artifact name="qpid-bdbstore-jmx" type="source" ext="jar" e:classifier="sources"/>
+ <artifact name="qpid-bdbstore-jmx" type="source.asc" ext="jar.asc" e:classifier="sources"/>
</publications>
<dependencies/>
diff --git a/java/ivy.retrieve.xml b/java/ivy.retrieve.xml
index 3af847a48a..5998a3e78e 100644
--- a/java/ivy.retrieve.xml
+++ b/java/ivy.retrieve.xml
@@ -57,7 +57,6 @@
<dependency org="log4j" name="log4j" rev="1.2.16" transitive="false"/>
<dependency org="org.apache.maven" name="maven-ant-tasks" rev="2.1.1" transitive="false"/>
<dependency org="org.mockito" name="mockito-all" rev="1.9.0" transitive="false"/>
- <dependency org="org.apache.felix" name="org.apache.felix.main" rev="2.0.5" transitive="false"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.4" transitive="false"/>
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.4" transitive="false"/>
<dependency org="org.eclipse.jetty" name="jetty-server" rev="7.6.3.v20120416" transitive="false"/>
@@ -70,6 +69,8 @@
<dependency org="org.eclipse.jetty" name="jetty-util" rev="7.6.3.v20120416" transitive="false"/>
<dependency org="org.dojotoolkit" name="dojo-war" rev="1.7.2" transitive="false"/>
<dependency org="xalan" name="xalan" rev="2.7.0" transitive="false"/>
+ <dependency org="velocity" name="velocity" rev="1.4" transitive="false"/>
+ <dependency org="velocity" name="velocity-dep" rev="1.4" transitive="false"/>
<!-- The following are optional dependencies, for modules providing optional functionlity or
for use in optional build/test steps. Their optional status is usually indicative of licences
diff --git a/java/ivysettings.retrieve.xml b/java/ivysettings.retrieve.xml
index e31af1e5b5..cc50121821 100644
--- a/java/ivysettings.retrieve.xml
+++ b/java/ivysettings.retrieve.xml
@@ -16,7 +16,7 @@
-->
<ivysettings>
<property name="ivy.default.resolver" value="chain" override="false"/>
- <property name="ivy.localfs.root" value="${project.root}/localfs_repo" override="false"/>
+ <property name="ivy.localfs.root" value="${project.root}/lib/localfs_repo" override="false"/>
<property name="ivy.localfs.pattern" value="[artifact]-[revision](-[classifier]).[ext]" override="false"/>
<settings defaultResolver="${ivy.default.resolver}"/>
diff --git a/java/jca/README-JBOSS-EAP6.txt b/java/jca/README-JBOSS-EAP6.txt
new file mode 100644
index 0000000000..219bfb6468
--- /dev/null
+++ b/java/jca/README-JBOSS-EAP6.txt
@@ -0,0 +1,183 @@
+Qpid JCA Resource Adapter
+
+JBoss EAP 6.x Installation and Configuration Instructions
+
+Overview
+========
+The Qpid Resource Adapter is a JCA 1.5 compliant resource adapter that allows
+for JEE integration between EE applications and AMQP 0.10 message brokers.
+
+The adapter provides both outbound and inbound connectivity and
+exposes a variety of options to fine tune your messaging applications.
+Currently the adapter only supports C++ based brokers and has only been tested with Apache Qpid C++ broker.
+
+The following document explains how to configure the resource adapter for deployment in JBoss EAP 6.x.
+
+Deployment
+==========
+To deploy the Qpid JCA adapter in the JBoss EAP 6 environment, copy the qpid-ra-<version>.rar file
+to your JBoss deployment directory. By default this can be found at
+
+JBOSS_ROOT/<server-config>/deployments
+
+where JBOSS_ROOT denotes the root directory of your JBoss EAP 6.x installation and <server-config> denotes the
+particular server configuration for your applicationd development. Currently, JBoss EAP 6 provides two configurations
+by default standalone and domain. This documentation assumes the standalone server configuration, though the process
+to configure and deploy the Qpid JCA adapter is largely the same between the two. Assuming the standalone configuration
+the deployment location above would be
+
+JBOSS_ROOT/standalone/deployments
+
+Note, as opposed to prior versions of EAP, copying a RAR file to the deployment location does not automatically
+start and deploy the adapter. A separate manual configuration step is required which is explained in the following
+section.
+
+Configuration
+=============
+The EAP 6.x environment uses an XML based configuration scheme that is fundamentally different than prior versions
+of EAP. As previously mentioned, EAP 6.x provides two server configuration types, standalone and domain. Each come with
+a different set of configuration files that are tailored to varying types of server environments. Configuration locations
+can be found at
+
+JBOSS_ROOT/<server-config>/configuration
+
+The varying XML files are named
+
+<server-config>-full.xml
+<server-config>-full-ha.xml
+<server-config>.xml
+
+where each XML file denotes the capabilites of the server. This document assumes a minimal server configuration in
+the standalone server environment. While each configuration file provides a variety of options, this document is
+only concerned with the configuration of the JCA adapter. Please consult the EAP 6.x documentation for other
+options and configuration scenarios.
+
+The EAP 6.x infrastructure is built upon the notion of varying subsystem where subsystem generally corresponds
+to one particular piece of functionality. Typical examples are EJB, JAXR etc. In order to configure the Qpid JCA adapter
+we need to modify the ejb and resource-adapters subsystems in order to tell EAP 6.x about our RAR deployment as well
+as the RAR that will provide JMS provider functionality.
+
+Note, JCA in EAP 6.x involves two subsystems, jca and resource-adapters. The former subsytem provides capabilities for
+all JCA deployments (the JCA runtime environment) where the resource-adapters subsystem is particular to an invidual JCA
+deployment. Here we are only concerned with the latter. Please consult the EAP 6.x documentation for more general JCA
+configuration options as well as other subsystems.
+
+Each subsystem is configured in an XML fragment and is versioned separately. Subsystem versions will change over
+time so this document may not reflect the most current version, but the Qpid JCA configuration options remain
+unchanged across subsystem regardless of version or release date.
+
+The following XML fragment replaces the default messaging provider in the EAP 6.x environment
+
+ <subsystem xmlns="urn:jboss:domain:ejb3:1.2">
+ <session-bean>
+ <stateless>
+ <bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>
+ </stateless>
+ <stateful default-access-timeout="5000" cache-ref="simple"/>
+ <singleton default-access-timeout="5000"/>
+ </session-bean>
+ <mdb>
+ <resource-adapter-ref resource-adapter-name="qpid-ra-<rar-version>.rar"/>
+ <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
+ </mdb>
+ <pools>
+ <bean-instance-pools>
+ <strict-max-pool name="slsb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
+ <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
+ </bean-instance-pools>
+ </pools>
+ <caches>
+ <cache name="simple" aliases="NoPassivationCache"/>
+ <cache name="passivating" passivation-store-ref="file" aliases="SimpleStatefulCache"/>
+ </caches>
+ <passivation-stores>
+ <file-passivation-store name="file"/>
+ </passivation-stores>
+ <async thread-pool-name="default"/>
+ <timer-service thread-pool-name="default">
+ <data-store path="timer-service-data" relative-to="jboss.server.data.dir"/>
+ </timer-service>
+ <remote connector-ref="remoting-connector" thread-pool-name="default"/>
+ <thread-pools>
+ <thread-pool name="default">
+ <max-threads count="10"/>
+ <keepalive-time time="100" unit="milliseconds"/>
+ </thread-pool>
+ </thread-pools>
+ </subsystem>
+
+The only real lines we are concerned with are
+
+ <mdb>
+ <resource-adapter-ref resource-adapter-name="qpid-ra-<rar-version>.rar"/>
+ <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
+ </mdb>
+
+however, the complete fragment is provided for clarity.
+
+The following XML fragment provides a minimal example configuration in the EAP 6 environment. Here we are configuring
+an XA aware ManagedConnectionFactory and two JMS destinations (queue and topic)
+
+ <subsystem xmlns="urn:jboss:domain:resource-adapters:1.0">
+ <resource-adapters>
+ <resource-adapter>
+ <archive>
+ qpid-ra-<rar-version>.rar
+ </archive>
+ <transaction-support>
+ XATransaction
+ </transaction-support>
+ <config-property name="connectionURL">
+ amqp://anonymous:passwd@client/test?brokerlist='tcp://localhost?sasl_mechs='PLAIN''
+ </config-property>
+ <config-property name="TransactionManagerLocatorClass">
+ org.apache.qpid.ra.tm.JBoss7TransactionManagerLocator
+ </config-property>
+ <config-property name="TransactionManagerLocatorMethod">
+ getTm
+ </config-property>
+ <connection-definitions>
+ <connection-definition class-name="org.apache.qpid.ra.QpidRAManagedConnectionFactory" jndi-name="QpidJMSXA" pool-name="QpidJMSXA">
+ <config-property name="connectionURL">
+ amqp://anonymous:passwd@client/test?brokerlist='tcp://localhost?sasl_mechs='PLAIN''
+ </config-property>
+ <config-property name="SessionDefaultType">
+ javax.jms.Queue
+ </config-property>
+ </connection-definition>
+ </connection-definitions>
+ <admin-objects>
+ <admin-object class-name="org.apache.qpid.ra.admin.QpidTopicImpl" jndi-name="java:jboss/exported/GoodByeTopic" use-java-context="false" pool-name="GoodByeTopic">
+ <config-property name="DestinationAddress">
+ amq.topic/hello.Topic
+ </config-property>
+ </admin-object>
+ <admin-object class-name="org.apache.qpid.ra.admin.QpidQueueImpl" jndi-name="java:jboss/exported/HelloQueue" use-java-context="false" pool-name="HelloQueue">
+ <config-property name="DestinationAddress">
+ hello.Queue;{create:always, node:{type:queue, x-declare:{auto-delete:true}}}
+ </config-property>
+ </admin-object>
+ </admin-objects>
+ </resource-adapter>
+ </resource-adapters>
+ </subsystem>
+
+
+
+Note, while this document assumes that you are modifying the standalone.xml file directly, an alternative to this approach would be
+to make a copy of the file, apply the modifications above and start the EAP instance with the new configuration
+
+JBOSS_HOME/bin/standalone.sh -c your-modified-config.xml
+
+Regardless of the approach that you use, once the modifications have been made you can start your EAP 6.x instance and the Qpid JCA
+adapter will be deployed and ready for use. If property deployed and configured, you should see something in the log files or console
+resembling the following:
+
+INFO [org.apache.qpid.ra.QpidResourceAdapter] (MSC service thread 1-4) Qpid resource adapter started
+
+
+Notes
+=====
+While the differences between the EAP 5.x and 6.x environments may appear to be dramatic, the configuration options and functionality of the Qpid
+JCA adapter are not. The README.txt file outlines general configuration options that remain unchanged between the respective EAP environments.
+
diff --git a/java/jca/README-JBOSS.txt b/java/jca/README-JBOSS.txt
index 77bf91e6dd..e88643e0f2 100644
--- a/java/jca/README-JBOSS.txt
+++ b/java/jca/README-JBOSS.txt
@@ -61,7 +61,7 @@ XA ConnectionFactory
<xa-transaction/>
<rar-name>qpid-ra-<ra-version>.rar</rar-name>
<connection-definition>org.apache.qpid.ra.QpidRAConnectionFactory</connection-definition>
- <config-property name="connectionURL">amqp://guest:guest@/test?brokerlist='tcp://localhost:5672?sasl_mechs='ANONYMOUS''</config-property>
+ <config-property name="ConnectionURL">amqp://guest:guest@/test?brokerlist='tcp://localhost:5672?sasl_mechs='PLAIN''</config-property>
<max-pool-size>20</max-pool-size>
</tx-connection-factory>
@@ -79,11 +79,11 @@ Local ConnectionFactory
=======================
<tx-connection-factory>
<jndi-name>QpidJMS</jndi-name>
- <rar-name>qpid-ra-0.10.rar</rar-name>
+ <rar-name>qpid-ra-<ra-version>.rar</rar-name>
<local-transaction/>
- <config-property name="useLocalTx" type="java.lang.Boolean">true</config-property>
- <config-property name="connectionURL">amqp://anonymous:@client/test?brokerlist='tcp://localhost:5672?sasl_mechs='ANONYMOUS''</config-property>
- <connection-definition>org.apache.qpid.ra.QpidRAConnectionFactory</connection-definition>
+ <config-property name="UseLocalTx" type="java.lang.Boolean">true</config-property>
+ <config-property name="ConnectionURL">amqp://anonymous:@client/test?brokerlist='tcp://localhost:5672?sasl_mechs='PLAIN''
+ </config-property> <connection-definition>org.apache.qpid.ra.QpidRAConnectionFactory</connection-definition>
<max-pool-size>20</max-pool-size>
</tx-connection-factory>
@@ -100,11 +100,10 @@ provides two such objects
<mbean code="org.jboss.resource.deployment.AdminObject"
name="qpid.jca:name=HelloQueue">
<attribute name="JNDIName">Hello</attribute>
- <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='qpid-ra-0.10.rar'</depends>
+ <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='qpid-ra-<ra-version>.rar'</depends>
<attribute name="Type">javax.jms.Destination</attribute>
<attribute name="Properties">
- destinationType=QUEUE
- destinationAddress=amq.direct
+ DestinationAddress=amq.direct
</attribute>
</mbean>
@@ -113,16 +112,15 @@ The above XML defines a JMS Queue which is bound into JNDI as
queue/HelloQueue
This destination can be retrieved from JNDI and be used for the consumption or production of messages. The desinationAddress property
-can be customized for your environment. Please see the Qpid Java Client documentation for specific configuration options.
+can be customized for your environment. Please see the Qpid Java Client documentation for specific configuration options.
<mbean code="org.jboss.resource.deployment.AdminObject"
name="qpid.jca:name=HelloTopic">
<attribute name="JNDIName">HelloTopic</attribute>
- <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='qpid-ra-0.10.rar'</depends>
+ <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='qpid-ra-<ra-version>.rar'</depends>
<attribute name="Type">javax.jms.Destination</attribute>
<attribute name="Properties">
- destinationType=TOPIC
- destinationAddress=amq.topic
+ DestinationAddress=amq.topic
</attribute>
</mbean>
@@ -138,10 +136,10 @@ can be customized for your environment. Please see the Qpid Java Client document
<mbean code="org.jboss.resource.deployment.AdminObject"
name="qpid.jca:name=QpidConnectionFactory">
<attribute name="JNDIName">QpidConnectionFactory</attribute>
- <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='qpid-ra-0.10.rar'</depends>
+ <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='qpid-ra-<ra-version>.rar'</depends>
<attribute name="Type">javax.jms.ConnectionFactory</attribute>
<attribute name="Properties">
- connectionURL=amqp://anonymous:@client/test?brokerlist='tcp://localhost:5672?sasl_mechs='ANONYMOUS''
+ ConnectionURL=amqp://anonymous:@client/test?brokerlist='tcp://localhost:5672?sasl_mechs='PLAIN''
</attribute>
</mbean>
diff --git a/java/jca/build.xml b/java/jca/build.xml
index 934514aa52..42a19ff83a 100644
--- a/java/jca/build.xml
+++ b/java/jca/build.xml
@@ -22,18 +22,26 @@
<property name="module.depends" value="common client"/>
<property name="module.name" value="jca"/>
+ <!-- Hack to make the renamed module jars available on the module test classpath -->
+ <property name="module.test.depends" value="ra ra/tests"/>
+
+ <!-- Import common.xml to make the properties it defines available before importing module.xml -->
+ <import file="../common.xml"/>
+
+ <!-- Override the standard output jar names before importing module.xml, to produce
+ artifacts that use ra in the name instead of jca like the module should -->
+ <property name="module.test.jar" value="${build.lib}/${project.name}-ra-tests-${project.version}.jar"/>
+ <property name="module.jar" value="${build.lib}/${project.name}-ra-${project.version}.jar"/>
+ <property name="module.source.jar" value="${build.lib}/${project.name}-ra-${project.version}-sources.jar"/>
<import file="../module.xml"/>
<property name="module.rar" value="${build.lib}/${project.name}-ra-${project.version}.rar"/>
+ <property name="rar.resources" value="rar/src/main/resources"/>
- <property name="module.resources" value="src/main/resources"/>
-
- <target name="rar" depends="jar">
- <!--Note we need to do this as we need to keep the ra in the name of the artificats but we can't override the module.jar property which is based on the directory name-->
- <move file="${build.lib}/${project.name}-${module.name}-${project.version}.jar" tofile="${build.lib}/${project.name}-ra-${project.version}.jar"/>
+ <target name="rar" depends="jar" description="creates a rar file containing the module jar, client jars, etc">
<jar destfile="${module.rar}">
- <fileset dir="${module.resources}">
+ <fileset dir="${rar.resources}">
<include name="**/*.xml"/>
</fileset>
<fileset dir="${build.lib}">
@@ -67,6 +75,9 @@
<target name="examples" depends="example-properties-file, example-jars"/>
- <target name="build" depends="rar, examples"/>
+ <target name="postbuild" depends="rar, examples"/>
+ <!-- Override module.xml 'libs' target to avoid copying the jar files dependencies
+ into the 'build/lib' dir, since they will be supplied by the app server -->
+ <target name="libs"/>
</project>
diff --git a/java/jca/src/main/resources/META-INF/jboss-ra.xml b/java/jca/rar/src/main/resources/META-INF/jboss-ra.xml
index f459b1efc1..f459b1efc1 100644
--- a/java/jca/src/main/resources/META-INF/jboss-ra.xml
+++ b/java/jca/rar/src/main/resources/META-INF/jboss-ra.xml
diff --git a/java/jca/src/main/resources/META-INF/ra.xml b/java/jca/rar/src/main/resources/META-INF/ra.xml
index a9374f52d7..a9374f52d7 100755
--- a/java/jca/src/main/resources/META-INF/ra.xml
+++ b/java/jca/rar/src/main/resources/META-INF/ra.xml
diff --git a/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxy.java b/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxy.java
index a948948d6a..d7ca29e04a 100644
--- a/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxy.java
+++ b/java/jca/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxy.java
@@ -27,13 +27,17 @@ import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
-import javax.jms.ConnectionFactory;
import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.naming.NamingException;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.spi.ObjectFactory;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
import org.apache.qpid.client.AMQConnectionFactory;
@@ -44,7 +48,7 @@ import org.slf4j.LoggerFactory;
*
*
*/
-public class QpidConnectionFactoryProxy implements Externalizable, Referenceable, ConnectionFactory, Serializable
+public class QpidConnectionFactoryProxy implements QueueConnectionFactory, TopicConnectionFactory, Externalizable, Referenceable, Serializable
{
private static final Logger _log = LoggerFactory.getLogger(QpidDestinationProxy.class);
@@ -100,13 +104,6 @@ public class QpidConnectionFactoryProxy implements Externalizable, Referenceable
try
{
_delegate = new AMQConnectionFactory(getConnectionURL());
- /*
- QpidResourceAdapter ra = new QpidResourceAdapter();
- QpidRAManagedConnectionFactory mcf = new QpidRAManagedConnectionFactory();
- mcf.setResourceAdapter(ra);
- mcf.setConnectionURL(getConnectionURL());
- delegate = new QpidRAConnectionFactoryImpl(mcf, null);
- */
return ((Referenceable) _delegate).getReference();
}
catch(Exception e)
@@ -162,7 +159,63 @@ public class QpidConnectionFactoryProxy implements Externalizable, Referenceable
*/
public Connection createConnection(final String userName, final String password) throws JMSException
{
- return _delegate.createConnection(userName, password);
+ try
+ {
+ if(_delegate == null)
+ {
+ getReference();
+ }
+
+ return _delegate.createConnection(userName, password);
+ }
+ catch(Exception e)
+ {
+ throw new JMSException(e.getMessage());
+ }
+ }
+
+ /**
+ * Create a queue connection
+ * @return The queue connection
+ * @exception JMSException Thrown if the operation fails
+ */
+ public QueueConnection createQueueConnection() throws JMSException
+ {
+ return (QueueConnection)createConnection();
+ }
+
+ /**
+ * Create a queue connection
+ * @param userName The user name
+ * @param password The password
+ * @return The connection
+ * @exception JMSException Thrown if the operation fails
+ */
+ public QueueConnection createQueueConnection(final String userName, final String password) throws JMSException
+ {
+ return (QueueConnection)createConnection(userName, password);
+ }
+
+ /**
+ * Create a topic connection
+ * @return The topic connection
+ * @exception JMSException Thrown if the operation fails
+ */
+ public TopicConnection createTopicConnection() throws JMSException
+ {
+ return (TopicConnection)createConnection();
+ }
+
+ /**
+ * Create a topic connection
+ * @param userName The user name
+ * @param password The password
+ * @return The topic connection
+ * @exception JMSException Thrown if the operation fails
+ */
+ public TopicConnection createTopicConnection(final String userName, final String password) throws JMSException
+ {
+ return (TopicConnection)createConnection(userName, password);
}
}
diff --git a/java/management/common/src/main/java/management-common.bnd b/java/management/common/src/main/java/management-common.bnd
index 5a6be6bb15..5ae9791299 100644
--- a/java/management/common/src/main/java/management-common.bnd
+++ b/java/management/common/src/main/java/management-common.bnd
@@ -17,7 +17,7 @@
# under the License.
#
-ver: 0.19.0
+ver: 0.21.0
Bundle-SymbolicName: qpid-management-common
Bundle-Version: ${ver}
diff --git a/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ConfigurationManagement.java b/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ConfigurationManagement.java
deleted file mode 100644
index 4582dc4088..0000000000
--- a/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ConfigurationManagement.java
+++ /dev/null
@@ -1,41 +0,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.
- *
- */
-package org.apache.qpid.management.common.mbeans;
-
-import org.apache.qpid.management.common.mbeans.annotations.MBeanOperation;
-
-import javax.management.MBeanOperationInfo;
-
-public interface ConfigurationManagement
-{
-
- String TYPE = "ConfigurationManagement";
-
- /**
- * Reload the
- * @throws ConfigurationException
- */
- @MBeanOperation(name="reloadSecurityConfiguration",
- description = "Force a reload of the security configuration sections",
- impact = MBeanOperationInfo.ACTION)
- void reloadSecurityConfiguration() throws Exception;
-
-}
diff --git a/java/management/example/src/main/java/org/apache/qpid/example/jmxexample/AddQueue.java b/java/management/example/src/main/java/org/apache/qpid/example/jmxexample/AddQueue.java
index b858742c4e..f82408bd27 100644
--- a/java/management/example/src/main/java/org/apache/qpid/example/jmxexample/AddQueue.java
+++ b/java/management/example/src/main/java/org/apache/qpid/example/jmxexample/AddQueue.java
@@ -36,15 +36,14 @@ import org.apache.qpid.management.common.mbeans.ManagedExchange;
public class AddQueue
{
-
public static void main(String[] args)
{
//Example: add 'newqueue' to the 'test' virtualhost and bind to the 'amq.direct' exchange
//TODO: take these parameters as arguments
-
+
addQueue("test", "amq.direct", "newqueue");
}
-
+
private static JMXConnector getJMXConnection() throws Exception
{
//TODO: Take these parameters as main+method arguments
@@ -52,52 +51,55 @@ public class AddQueue
int port = 8999;
String username = "admin";
String password = "admin";
-
+
Map<String, Object> env = new HashMap<String, Object>();
JMXServiceURL jmxUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi");
//Add user credential's to environment map for RMIConnector startup.
env.put(JMXConnector.CREDENTIALS, new String[] {username,password});
-
+
return JMXConnectorFactory.connect(jmxUrl, env);
}
-
- public static boolean addQueue(String virHost, String exchName, String queueName) {
+ public static boolean addQueue(String virHost, String exchName, String queueName)
+ {
JMXConnector jmxc = null;
try
{
jmxc = getJMXConnection();
-
+
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName hostManagerObjectName = new ObjectName(
"org.apache.qpid:" +
"type=VirtualHost.VirtualHostManager," +
- "VirtualHost=" + virHost + ",*");
+ "VirtualHost=" + ObjectName.quote(virHost) + ",*");
Set<ObjectName> vhostManagers = mbsc.queryNames(hostManagerObjectName, null);
-
+
if(vhostManagers.size() == 0)
{
+ System.out.println("VirtualHostManager MBean wasnt found: " + virHost);
+
//The vhostManager MBean wasnt found, cant procede
return false;
}
-
+
ManagedBroker vhostManager = (ManagedBroker) MBeanServerInvocationHandler.newProxyInstance(
mbsc, (ObjectName) vhostManagers.toArray()[0], ManagedBroker.class, false);
ObjectName customExchangeObjectName = new ObjectName(
"org.apache.qpid:" +
"type=VirtualHost.Exchange," +
- "VirtualHost=" + virHost + "," +
- "name=" + exchName + "," +
- "ExchangeType=direct,*");
+ "VirtualHost=" + ObjectName.quote(virHost) + "," +
+ "name=" + ObjectName.quote(exchName) + ",*");
Set<ObjectName> exchanges = mbsc.queryNames(customExchangeObjectName, null);
-
+
if(exchanges.size() == 0)
{
+ System.out.println("Exchange wasnt found: " + exchName);
+
//The exchange doesnt exist, cant procede.
return false;
}
@@ -105,12 +107,14 @@ public class AddQueue
//create the MBean proxy
ManagedExchange managedExchange = (ManagedExchange) MBeanServerInvocationHandler.newProxyInstance(
mbsc, (ObjectName) exchanges.toArray()[0], ManagedExchange.class, false);
-
+
try
{
//create the new durable queue and bind it.
vhostManager.createNewQueue(queueName, null, true);
+ System.out.println("Created queue: " + queueName);
managedExchange.createNewBinding(queueName,queueName);
+ System.out.println("Bound queue to exchange: "+ exchName);
}
catch (Exception e)
{
@@ -126,7 +130,7 @@ public class AddQueue
{
System.out.println("Could not add queue due to error :" + e.getMessage());
e.printStackTrace();
- }
+ }
finally
{
if(jmxc != null)
@@ -141,9 +145,8 @@ public class AddQueue
}
}
}
-
+
return false;
-
}
}
diff --git a/java/module.xml b/java/module.xml
index af77d84e86..9146403d04 100644
--- a/java/module.xml
+++ b/java/module.xml
@@ -48,16 +48,19 @@
<property name="module.api" location="${build.api}/${module}/"/>
<property name="module.test.api" location="${build.test.api}/${module}"/>
<property name="module.test.classes" location="${module.build}/test/classes"/>
- <property name="module.test.resources" location="${module.build}/test/resources"/>
+ <property name="module.test.resources" location="src/test/resources"/>
<property name="module.results" location="${build.results}/${module}"/>
<property name="module.failed" location="${module.results}/FAILED"/>
<property name="module.src" location="src/main/java"/>
<property name="module.test.src" location="src/test/java"/>
<property name="module.bin" location="bin"/>
<property name="module.etc" location="etc"/>
- <property name="module.src.resources.metainf" location="src/main/resources/META-INF"/>
- <property name="module.metainf" location="${module.build}/META-INF"/>
-
+
+ <property name="module.src.resources" location="src/main/resources"/>
+ <property name="module.src.resources.metainf" location="${module.src.resources}/META-INF"/>
+ <property name="module.resources.dir" location="resources/"/>
+ <property name="module.metainf" location="${module.build}/META-INF"/>
+
<property name="module.namever" value="${project.name}-${module.name}-${project.version}"/>
<property name="module.namever.osgi" value="${project.name}-${module.name}_${project.version}.0.osgi"/>
<property name="module.release.base" value="${basedir}/release"/>
@@ -74,6 +77,7 @@
<property name="broker.log.prefix" value="BROKER: "/>
<property name="broker.log.interleave" value="true"/>
+ <property name="module.jar" location="${build.lib}/${project.name}-${module.name}-${project.version}.jar"/>
<property name="module.qpid.jar" location="${module.release.lib}/qpid-all.jar"/>
<basename property="qpid.jar.name" file="${module.qpid.jar}"/>
@@ -84,7 +88,10 @@
<available property="module.test.src.exists" file="${module.test.src}"/>
<available property="module.etc.exists" file="${module.etc}"/>
<available property="module.bin.exists" file="${module.bin}"/>
+ <available property="module.src.resources.exists" file="${module.src.resources}"/>
+ <available property="module.test.src.resources.exists" file="${module.test.resources}"/>
<available property="module.src.resources.metainf.exists" file="${module.src.resources.metainf}"/>
+ <available property="module.resources.dir.exists" file="${module.resources.dir}"/>
<property name="module.source.jar"
location="${build.lib}/${project.name}-${module.name}-${project.version}-sources.jar"/>
@@ -94,15 +101,6 @@
<property name="module.test.depends" value=""/>
<property name="module.test.excludes" value=""/>
- <map property="module.depends.path" value="${module.depends}" join="${path.separator}">
- <globmapper from="*" to="${build.scratch}/*/classes"/>
- </map>
-
- <map property="module.test.depends.path" value="${module.test.depends}" join="${path.separator}">
- <globmapper from="*" to="${build.scratch}/*/classes"/>
- </map>
-
-
<!-- Add depenencies dependencies to path -->
<map property="module.depends.libs" value="${module.depends}" join=" ">
<chainedmapper>
@@ -160,30 +158,57 @@
<pathelement location="${module.test.src}"/>
</path>
- <condition property="module.jar"
- value="${build.plugins}/${project.name}-${module.name}-${project.version}.jar"
- else="${build.lib}/${project.name}-${module.name}-${project.version}.jar">
- <and>
- <isset property="module.plugin"/>
- <istrue value="${module.plugin}"/>
- </and>
- </condition>
-
<property name="module.test.jar"
location="${build.lib}/${project.name}-${module.name}-tests-${project.version}.jar"/>
+ <map property="module.depends.jars" value="${module.depends}" join=",">
+ <globmapper from="*" to="${project.name}-*-${project.version}.jar"/>
+ <filtermapper>
+ <replacestring from="/" to="-"/>
+ </filtermapper>
+ </map>
+
+ <map property="module.depends.jars.path" value="${module.depends}" join="${path.separator}">
+ <filtermapper>
+ <replacestring from="/" to="-"/>
+ </filtermapper>
+
+ <globmapper from="*" to="${build.lib}/${project.name}-*-${project.version}.jar"/>
+ </map>
+
+ <map property="module.test.depends.jars.path" value="${module.test.depends}" join="${path.separator}">
+ <filtermapper>
+ <replacestring from="/" to="-"/>
+ </filtermapper>
+ <globmapper from="*" to="${build.lib}/${project.name}-*-${project.version}.jar"/>
+ </map>
+
+ <!-- used for building the module -->
<path id="module.class.path">
- <pathelement location="${module.classes}"/>
- <pathelement path="${module.depends.path}"/>
+ <pathelement path="${module.depends.jars.path}"/>
<path refid="module.libs"/>
</path>
+ <!-- used at runtime -->
+ <path id="module.runtime.class.path">
+ <pathelement location="${module.jar}"/>
+ <pathelement path="${module.depends.jars.path}"/>
+ <path refid="module.libs"/>
+ </path>
+
+ <!-- used to build the tests -->
<path id="module.test.path">
- <pathelement path="${module.test.classes}"/>
- <path refid="module.class.path"/>
- <pathelement path="${module.test.depends.path}"/>
+ <path refid="module.runtime.class.path"/>
+ <pathelement path="${module.test.depends.jars.path}"/>
+ <path refid="module.test.libs"/>
+ </path>
+
+ <!-- used to run the tests -->
+ <path id="module.test.runtime.path">
+ <pathelement path="${module.test.jar}"/>
+ <path refid="module.runtime.class.path"/>
+ <pathelement path="${module.test.depends.jars.path}"/>
<path refid="module.test.libs"/>
- <pathelement path="${module.test.resources}"/>
</path>
<property name="javac.deprecation" value="off"/>
@@ -197,14 +222,21 @@
<echo-prop name="module.name"/>
<echo-prop name="module.jar"/>
<echo-prop name="module.depends"/>
- <echo-prop name="module.depends.path"/>
+
<echo-prop name="module.test.depends"/>
- <echo-prop name="module.test.depends.path"/>
+
<echo-prop name="module.depends.libs"/>
<echo-prop name="module.test.depends.libs"/>
+
+ <echo-prop name="module.depends.jars"/>
+ <echo-prop name="module.depends.jars.path"/>
+ <echo-prop name="module.test.depends.jars.path"/>
+
<echo-path refid="module.src.path"/>
<echo-path refid="module.class.path"/>
+ <echo-path refid="module.runtime.class.path"/>
<echo-path refid="module.test.path"/>
+ <echo-path refid="module.test.runtime.path"/>
</target>
<target name="prepare">
@@ -212,7 +244,7 @@
<mkdir dir="${build.etc}"/>
<mkdir dir="${build.lib}"/>
<mkdir dir="${build.results}"/>
- <mkdir dir="${build.plugins}"/>
+ <mkdir dir="${build.scratch.broker.plugins.lib}"/>
<mkdir dir="${module.classes}"/>
<mkdir dir="${module.precompiled}"/>
<mkdir dir="${module.api}"/>
@@ -229,7 +261,7 @@
<arg line='-o "${build.scratch}/qpid-${module.name}.pom"'/>
<arg line="-u ${project.url}"/>
<arg line="-g ${project.groupid}"/>
- <arg line="-v ${project.version}${maven.version.suffix}"/>
+ <arg line="-v ${project.version.maven}${maven.version.suffix}"/>
<arg line="-p qpid"/>
<arg line='-m "${module.depends}"'/>
<arg line="-a ${module.name}"/>
@@ -239,9 +271,7 @@
</jython>
</target>
- <target name="release-mvn" depends="pom" if="module.genpom" description="Install the artifacts into the local repository and prepare the release">
- <antcall target="build"/>
-
+ <target name="release-mvn" depends="build,pom" if="module.genpom" description="Install the artifacts into the local repository and prepare the release artifacts">
<artifact:pom id="module.pom" file="${build.scratch}/qpid-${module.name}.pom"/>
<artifact:install file="${module.jar}" pomRefId="module.pom" settingsFile="${maven.settings.xml}">
@@ -255,6 +285,29 @@
</artifact:deploy>
</target>
+ <target name="deploy-snapshot" depends="build,pom" if="module.genpom" description="deploy a snapshot build to nexus">
+ <!-- In order to use this target you need to have predefined a username and password for the
+ server with id ${maven.snapshots.repo.id} in your m2 settings file, e.g ~/.m2/settings.xml -->
+ <artifact:pom id="module.pom" file="${build.scratch}/qpid-${module.name}.pom"/>
+
+ <fail message="The pom version must include -SNAPSHOT. Version found was: ${module.pom.version}">
+ <condition>
+ <not>
+ <contains substring="-SNAPSHOT" string="${module.pom.version}" />
+ </not>
+ </condition>
+ </fail>
+
+ <artifact:install file="${module.jar}" pomRefId="module.pom" settingsFile="${maven.settings.xml}">
+ <localRepository path="${maven.local.repo}"/>
+ </artifact:install>
+
+ <artifact:deploy file="${module.jar}" pomRefId="module.pom">
+ <localRepository path="${maven.local.repo}"/>
+ <remoteRepository id="${maven.snapshots.repo.id}" url="${maven.snapshots.repo.url}"/>
+ </artifact:deploy>
+ </target>
+
<target name="precompile"/>
<target name="compile" depends="prepare,precompile" description="compile sources">
@@ -280,6 +333,13 @@
<target name="precompile-tests" if="module.test.src.exists"/>
+ <target name="copy-test-resources" if="module.test.src.resources.exists">
+ <echo message="Copying test resources from ${module.test.resources} to ${module.test.classes}..."/>
+ <copy todir="${module.test.classes}" failonerror="true">
+ <fileset dir="${module.test.resources}"/>
+ </copy>
+ </target>
+
<target name="compile-tests" depends="compile,precompile-tests" if="module.test.src.exists"
description="compilte unit tests">
<javac target="${java.target}" source="${java.source}"
@@ -312,9 +372,8 @@
<map property="_profile_files" value="${profiles}" join=" ">
<globmapper from="*" to="*.testprofile"/>
</map>
-
- <delete file="${build.scratch}/test-${profile}.properties" quiet="true"/>
- <concat destfile="${build.scratch}/test-${profile}.properties" force="no" fixlastline="yes">
+
+ <concat destfile="${build.scratch}/test-${profile}.properties" force="yes" append="no" fixlastline="yes">
<filelist dir="${test.profiles}" files="testprofile.defaults"/>
<filelist dir="${test.profiles}" files="${_profile_files}"/>
</concat>
@@ -335,14 +394,13 @@
<property name="QPID_HOME" value="${qpid.home}"/>
<property name="QPID_WORK" value="${qpid.work}"/>
<property name="broker.existing.qpid.work" value=""/>
- <!-- Used by PluginTest -->
- <property name="example.plugin.target" value="${project.root}/build/lib/plugins"/>
<propertyset id="all.test.systemproperties">
<propertyref prefix="test"/>
<propertyref prefix="profile"/>
<propertyref prefix="javax.net.ssl"/>
<propertyref prefix="broker"/>
+ <propertyref prefix="qpid"/>
<propertyref name="amqj.logging.level"/>
<propertyref name="amqj.server.logging.level"/>
@@ -350,16 +408,14 @@
<propertyref name="log4j.debug"/>
<propertyref name="log4j.configuration"/>
+ <propertyref name="log4j.configuration.file"/>
<propertyref name="root.logging.level"/>
<propertyref name="java.naming.factory.initial"/>
<propertyref name="java.naming.provider.url"/>
<propertyref name="messagestore.class.name" />
- <propertyref name="qpid.amqp.version"/>
<propertyref name="max_prefetch"/>
- <propertyref name="qpid.dest_syntax"/>
- <propertyref name="test.output"/>
<propertyref name="QPID_HOME"/>
<propertyref name="QPID_WORK"/>
<propertyref name="example.plugin.target"/>
@@ -383,7 +439,7 @@
<formatter type="plain"/>
<formatter type="xml"/>
- <classpath refid="module.test.path"/>
+ <classpath refid="module.test.runtime.path"/>
<batchtest todir="${module.results}">
<fileset dir="${module.test.src}" excludes="${module.test.excludes}">
@@ -447,35 +503,54 @@
<target name="postbuild" description="run after a build"/>
- <target name="build" depends="jar,jar-tests,jar-sources,libs,copy-bin,copy-etc,postbuild" description="compile and copy resources into build tree"/>
+ <target name="build" depends="jar,jar-tests,jar-sources,libs,copy-bin,copy-etc,postbuild,copy-broker-plugin-jars" description="compile and copy resources into build tree"/>
- <target name="jar.manifest" depends="compile, copy-module-metainf" if="module.manifest">
+ <target name="jar.manifest" depends="compile,copy-resources,copy-files-to-module-metainf" if="module.manifest">
<jar destfile="${module.jar}" basedir="${module.classes}" manifest="${module.manifest}">
<metainf dir="${module.metainf}" />
</jar>
</target>
- <target name="jar.nomanifest" depends="compile, copy-module-metainf" unless="module.manifest">
+ <target name="jar.nomanifest" depends="compile,copy-resources,copy-files-to-module-metainf" unless="module.manifest">
<jar destfile="${module.jar}" basedir="${module.classes}">
<metainf dir="${module.metainf}" />
</jar>
</target>
- <target name="copy-module-metainf" depends="copy-metainf-resources" if="module.src.resources.metainf.exists">
+ <target name="copy-broker-plugin-jars" if="broker.plugin" description="copy broker plugins for use in release packaging">
+ <copy file="${module.jar}" todir="${build.scratch.broker.plugins.lib}" failonerror="true"/>
+ </target>
+
+ <target name="copy-files-to-module-metainf" depends="copy-project-resources-metainf, copy-module-resources-metainf, copy-module-src-resources-metainf"/>
+
+ <target name="copy-project-resources-metainf">
<copy todir="${module.metainf}" failonerror="true">
- <fileset dir="${module.src.resources.metainf}"/>
+ <fileset dir="${project.root}/resources/"/>
</copy>
</target>
- <target name="copy-metainf-resources">
+ <target name="copy-resources" if="module.src.resources.exists">
+ <echo message="Copying resources from ${module.src.resources} to ${module.classes}..."/>
+ <copy todir="${module.classes}" failonerror="true">
+ <fileset dir="${module.src.resources}" excludes="META-INF/**"/>
+ </copy>
+ </target>
+
+ <target name="copy-module-resources-metainf" if="module.resources.dir.exists">
+ <copy todir="${module.metainf}" failonerror="false" overwrite="true">
+ <fileset dir="${module.resources.dir}"/>
+ </copy>
+ </target>
+
+ <target name="copy-module-src-resources-metainf" if="module.src.resources.metainf.exists">
<copy todir="${module.metainf}" failonerror="true">
- <fileset dir="${project.root}/resources/"/>
+ <fileset dir="${module.src.resources.metainf}"/>
</copy>
</target>
<target name="jar" depends="jar.manifest,jar.nomanifest" description="create jar"/>
- <target name="jar-tests" depends="compile-tests" description="create unit test jar">
+ <target name="jar-tests" depends="compile-tests, copy-test-resources" description="create unit test jar">
<jar destfile="${module.test.jar}" basedir="${module.test.classes}"/>
</target>
@@ -494,14 +569,7 @@
<copylist todir="${build.lib}" dir="${project.root}" files="${module.libs}"/>
</target>
- <map property="module.depends.jars" value="${module.depends}" join=",">
- <globmapper from="*" to="${project.name}-*-${project.version}.jar"/>
- <filtermapper>
- <replacestring from="/" to="-"/>
- </filtermapper>
- </map>
-
<target name="libs-release" description="copy dependencies into module release">
<!-- Copy the module dependencies -->
<echo message="${module.libs}"/>
@@ -688,8 +756,7 @@
<syspropertyset refid="all.test.systemproperties"/>
- <sysproperty key="net.sourceforge.cobertura.datafile"
- file="${cobertura.datafile}" />
+ <sysproperty key="net.sourceforge.cobertura.datafile" file="${cobertura.datafile}" />
<formatter type="plain"/>
<formatter type="xml"/>
@@ -697,10 +764,10 @@
<classpath path="${module.instrumented}"/>
<classpath>
<fileset dir="${build}">
- <include name="**/classes-instrumented/*.class"/>
- </fileset>
+ <include name="**/classes-instrumented/*.class"/>
+ </fileset>
</classpath>
- <classpath refid="module.test.path"/>
+ <classpath refid="module.test.runtime.path"/>
<classpath refid="cobertura.classpath"/>
<batchtest todir="${module.results}">
@@ -713,8 +780,8 @@
<target name="coverage-report" depends="cobertura-init">
<cobertura-report format="html"
- destdir="${module.coverage}"
- datafile="${cobertura.datafile}">
+ destdir="${module.coverage}"
+ datafile="${cobertura.datafile}">
<fileset dir="${module.src}" includes="**/*.java" />
</cobertura-report>
</target>
@@ -750,7 +817,8 @@ qpid.name=${project.name}
-->
- <property name="gentools.home" location="${project.root}/../gentools" />
+ <property name="gentools.home" location="${project.root}/common/gentools" />
+ <property name="gentools.build" location="${build.scratch}/common/gentools" />
<property name="generated.dir" location="${module.precompiled}" />
<property name="velocity.compile.dir" value="${build.scratch}/broker/velocity"/>
<property name="velocity.timestamp" location="${generated.dir}/velocity.timestamp" />
@@ -763,7 +831,7 @@ qpid.name=${project.name}
deprecation="${javac.deprecation}"
srcdir="${project.root}/broker/src/velocity/java" >
<classpath>
- <pathelement path="${gentools.home}/lib/velocity-1.4.jar" />
+ <pathelement path="${project.root}/${velocity.jar}" />
</classpath>
<compilerarg line="${javac.compiler.args}"/>
</javac>
@@ -793,7 +861,7 @@ qpid.name=${project.name}
<echo message="logmessages is ${logmessages}"/>
- <java classname="org.apache.qpid.server.logging.GenerateLogMessages" fork="true" dir="${gentools.home}/src" failonerror="true">
+ <java classname="org.apache.qpid.server.logging.GenerateLogMessages" fork="true" dir="${gentools.build}/classes" failonerror="true">
<arg line="'${logmessages}'"/>
<arg value="-j"/>
<arg value="-o"/>
@@ -810,7 +878,7 @@ qpid.name=${project.name}
<fileset dir="${project.root}/lib/required">
<include name="**/*.jar"/>
</fileset>
- <pathelement path="${gentools.home}/lib/velocity-1.4.jar" />
+ <pathelement path="${project.root}/${velocity.jar}" />
</classpath>
</java>
<touch file="${velocity.timestamp}" />
diff --git a/java/perftests/build.xml b/java/perftests/build.xml
index c59986c06d..d29649ad68 100644
--- a/java/perftests/build.xml
+++ b/java/perftests/build.xml
@@ -33,7 +33,7 @@
</condition>
<property name="module.depends" value="client common"/>
- <property name="module.test.depends" value="systests broker common/test management/common ${perftests.optional.test.depends}"/>
+ <property name="module.test.depends" value="systests broker common/tests management/common ${perftests.optional.test.depends}"/>
<import file="../module.xml"/>
diff --git a/java/perftests/etc/chartdefs/1001-MessageSize-Transient-ByteSec.chartdef b/java/perftests/etc/chartdefs/1001-MessageSize-Transient-ByteSec.chartdef
new file mode 100644
index 0000000000..7559b5934e
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1001-MessageSize-Transient-ByteSec.chartdef
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Impact of Message Size Bytes/S
+chartSubtitle=Transient messages
+chartDescription=1P 1C, transient, auto-ack, with message payload between 256-262144 bytes.
+
+xAxisTitle=Message Size (B)
+yAxisTitle=Throughput (KB/s)
+
+series.1.statement=SELECT payloadSizeB, throughputKbPerS FROM MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All'
+series.1.legend=Current
+series.1.dir=${csvCurrentDir}
+series.1.colourName=red
+
+series.2.statement=SELECT payloadSizeB, throughputKbPerS FROM MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All'
+series.2.legend=Baseline
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1001-MessageSize-Transient.chartdef b/java/perftests/etc/chartdefs/1001-MessageSize-Transient.chartdef
deleted file mode 100644
index 757a396dff..0000000000
--- a/java/perftests/etc/chartdefs/1001-MessageSize-Transient.chartdef
+++ /dev/null
@@ -1,32 +0,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.
-#
-
-chartType=XYLINE
-chartTitle=Impact of Message Size
-chartSubtitle=Transient messages
-xAxisTitle=Message Size (B)
-yAxisTitle=Throughput (KB/s)
-
-series.1.statement=SELECT payloadSizeB, throughputKbPerS FROM MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All'
-series.1.legend=Current
-series.1.dir=${csvCurrentDir}
-
-series.2.statement=SELECT payloadSizeB, throughputKbPerS FROM MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All'
-series.2.legend=Baseline
-series.2.dir=${csvBaselineDir}
diff --git a/java/perftests/etc/chartdefs/1002-MessageSize-Persistent-ByteSec.chartdef b/java/perftests/etc/chartdefs/1002-MessageSize-Persistent-ByteSec.chartdef
new file mode 100644
index 0000000000..db8a5f3896
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1002-MessageSize-Persistent-ByteSec.chartdef
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Impact of Message Size Bytes/S
+chartSubtitle=Persistent messages
+chartDescription=1P 1C, persistent, auto-ack, with message payload between 256-262144 bytes.
+
+xAxisTitle=Message Size (B)
+yAxisTitle=Throughput (KB/s)
+
+series.1.statement=SELECT payloadSizeB, throughputKbPerS FROM MessageSize WHERE testName like '% PERSISTENT' AND participantName = 'All'
+series.1.legend=Current
+series.1.dir=${csvCurrentDir}
+series.1.colourName=red
+
+series.2.statement=SELECT payloadSizeB, throughputKbPerS FROM MessageSize WHERE testName like '% PERSISTENT' AND participantName = 'All'
+series.2.legend=Baseline
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1002-MessageSize-Persistent.chartdef b/java/perftests/etc/chartdefs/1002-MessageSize-Persistent.chartdef
deleted file mode 100644
index 58c280e227..0000000000
--- a/java/perftests/etc/chartdefs/1002-MessageSize-Persistent.chartdef
+++ /dev/null
@@ -1,32 +0,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.
-#
-
-chartType=XYLINE
-chartTitle=Impact of Message Size
-chartSubtitle=Persistent messages
-xAxisTitle=Message Size (B)
-yAxisTitle=Throughput (KB/s)
-
-series.1.statement=SELECT payloadSizeB, throughputKbPerS FROM MessageSize WHERE testName like '% PERSISTENT' AND participantName = 'All'
-series.1.legend=Current
-series.1.dir=${csvCurrentDir}
-
-series.2.statement=SELECT payloadSizeB, throughputKbPerS FROM MessageSize WHERE testName like '% PERSISTENT' AND participantName = 'All'
-series.2.legend=Baseline
-series.2.dir=${csvBaselineDir}
diff --git a/java/perftests/etc/chartdefs/1003-MessageSize-Transient-MsgSec.chartdef b/java/perftests/etc/chartdefs/1003-MessageSize-Transient-MsgSec.chartdef
new file mode 100644
index 0000000000..7f18fcc986
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1003-MessageSize-Transient-MsgSec.chartdef
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Impact of Message Size
+chartSubtitle=Transient messages
+chartDescription=1P 1C, transient, auto-ack, with message payload between 256-262144 bytes.
+
+xAxisTitle=Message Size (B)
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT payloadSizeB, throughputMessagesPerS FROM MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All'
+series.1.legend=Current
+series.1.dir=${csvCurrentDir}
+series.1.colourName=red
+
+series.2.statement=SELECT payloadSizeB, throughputMessagesPerS FROM MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All'
+series.2.legend=Baseline
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1004-MessageSize-Persistent-MsgSec.chartdef b/java/perftests/etc/chartdefs/1004-MessageSize-Persistent-MsgSec.chartdef
new file mode 100644
index 0000000000..667be044bc
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1004-MessageSize-Persistent-MsgSec.chartdef
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Impact of Message Size
+chartSubtitle=Persistent messages
+chartDescription=1P 1C, persistent, auto-ack, with message payload between 256-262144 bytes.
+
+xAxisTitle=Message Size (B)
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT payloadSizeB, throughputMessagesPerS FROM MessageSize WHERE testName like '% PERSISTENT' AND participantName = 'All'
+series.1.legend=Current
+series.1.dir=${csvCurrentDir}
+series.2.colourName=red
+
+series.2.statement=SELECT payloadSizeB, throughputMessagesPerS FROM MessageSize WHERE testName like '% PERSISTENT' AND participantName = 'All'
+series.2.legend=Baseline
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1011-VaryingNumberOfProducers-AutoAck.chartdef b/java/perftests/etc/chartdefs/1011-VaryingNumberOfProducers-AutoAck.chartdef
new file mode 100644
index 0000000000..b3038c1671
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1011-VaryingNumberOfProducers-AutoAck.chartdef
@@ -0,0 +1,47 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Varying number of producers - auto ack
+chartSubtitle=Persistent 1KB messages
+chartDescription=1,2,5,10 P/Cs, persistent, auto-ack, with message payload 1KB.
+
+xAxisTitle=Producers
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '1' and acknowledgeMode = '1'
+series.1.legend=1 Consumer
+series.1.dir=${csvCurrentDir}
+series.1.colourName=red
+
+series.2.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '5' and acknowledgeMode = '1'
+series.2.legend=5 Consumer
+series.2.dir=${csvCurrentDir}
+series.2.colourName=blue
+
+series.3.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '10' and acknowledgeMode = '1'
+series.3.legend=10 Consumer
+series.3.dir=${csvCurrentDir}
+series.3.colourName=green
+
+series.4.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '1' and acknowledgeMode = '1'
+series.4.legend=1 Consumer (baseline)
+series.4.dir=${csvBaselineDir}
+series.4.colourName=dark_red
+series.4.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1011-VaryingNumberOfProducers.chartdef b/java/perftests/etc/chartdefs/1011-VaryingNumberOfProducers.chartdef
deleted file mode 100644
index f39e7c3d0d..0000000000
--- a/java/perftests/etc/chartdefs/1011-VaryingNumberOfProducers.chartdef
+++ /dev/null
@@ -1,40 +0,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.
-#
-
-chartType=XYLINE
-chartTitle=Varying number of producers
-chartSubtitle=Persistent 1KB messages
-xAxisTitle=Producers
-yAxisTitle=Throughput (KB/s)
-
-series.1.statement=SELECT totalNumberOfProducers, throughputKbPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '1'
-series.1.legend=1 Consumer
-series.1.dir=${csvCurrentDir}
-
-series.2.statement=SELECT totalNumberOfProducers, throughputKbPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '5'
-series.2.legend=5 Consumer
-series.2.dir=${csvCurrentDir}
-
-series.3.statement=SELECT totalNumberOfProducers, throughputKbPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '10'
-series.3.legend=10 Consumer
-series.3.dir=${csvCurrentDir}
-
-series.4.statement=SELECT totalNumberOfProducers, throughputKbPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '1'
-series.4.legend=1 Consumer (baseline)
-series.4.dir=${csvBaselineDir}
diff --git a/java/perftests/etc/chartdefs/1012-VaryingNumberOfConsumers-AutoAck.chartdef b/java/perftests/etc/chartdefs/1012-VaryingNumberOfConsumers-AutoAck.chartdef
new file mode 100644
index 0000000000..d1f3d6e9a4
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1012-VaryingNumberOfConsumers-AutoAck.chartdef
@@ -0,0 +1,47 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Varying number of consumers - auto ack
+chartSubtitle=Persistent 1KB messages
+chartDescription=1,2,5,10 P/Cs, persistent, auto-ack, with message payload 1KB.
+
+xAxisTitle=Consumers
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '1' and acknowledgeMode = '1'
+series.1.legend=1 Producer
+series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
+
+series.2.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '5' and acknowledgeMode = '1'
+series.2.legend=5 Producers
+series.2.dir=${csvCurrentDir}
+series.2.colourName=green
+
+series.3.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '10' and acknowledgeMode = '1'
+series.3.legend=10 Producers
+series.3.dir=${csvCurrentDir}
+series.3.colourName=red
+
+series.4.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '10' and acknowledgeMode = '1'
+series.4.legend=10 Producers (baseline)
+series.4.dir=${csvBaselineDir}
+series.4.colourName=dark_red
+series.4.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1012-VaryingNumberOfConsumers.chartdef b/java/perftests/etc/chartdefs/1012-VaryingNumberOfConsumers.chartdef
deleted file mode 100644
index 0f0b35a7c8..0000000000
--- a/java/perftests/etc/chartdefs/1012-VaryingNumberOfConsumers.chartdef
+++ /dev/null
@@ -1,40 +0,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.
-#
-
-chartType=XYLINE
-chartTitle=Varying number of consumers
-chartSubtitle=Persistent 1KB messages
-xAxisTitle=Consumers
-yAxisTitle=Throughput (KB/s)
-
-series.1.statement=SELECT totalNumberOfConsumers, throughputKbPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '1'
-series.1.legend=1 Producer
-series.1.dir=${csvCurrentDir}
-
-series.2.statement=SELECT totalNumberOfConsumers, throughputKbPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '5'
-series.2.legend=5 Producers
-series.2.dir=${csvCurrentDir}
-
-series.3.statement=SELECT totalNumberOfConsumers, throughputKbPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '10'
-series.3.legend=10 Producers
-series.3.dir=${csvCurrentDir}
-
-series.4.statement=SELECT totalNumberOfConsumers, throughputKbPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '10'
-series.4.legend=10 Producers (baseline)
-series.4.dir=${csvBaselineDir}
diff --git a/java/perftests/etc/chartdefs/1015-VaryingNumberOfProducers-SessionTrans.chartdef b/java/perftests/etc/chartdefs/1015-VaryingNumberOfProducers-SessionTrans.chartdef
new file mode 100644
index 0000000000..42ba6f8f20
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1015-VaryingNumberOfProducers-SessionTrans.chartdef
@@ -0,0 +1,47 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Varying number of producers - transacted
+chartSubtitle=Persistent 1KB messages
+chartDescription=1,2,5,10 P/Cs, persistent, transacted, with message payload 1KB.
+
+xAxisTitle=Producers
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '1' and acknowledgeMode = '0'
+series.1.legend=1 Consumer
+series.1.dir=${csvCurrentDir}
+series.1.colourName=red
+
+series.2.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '5' and acknowledgeMode = '0'
+series.2.legend=5 Consumer
+series.2.dir=${csvCurrentDir}
+series.2.colourName=blue
+
+series.3.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '10' and acknowledgeMode = '0'
+series.3.legend=10 Consumer
+series.3.dir=${csvCurrentDir}
+series.3.colourName=green
+
+series.4.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfConsumers = '1' and acknowledgeMode = '0'
+series.4.legend=1 Consumer (baseline)
+series.4.dir=${csvBaselineDir}
+series.4.colourName=dark_red
+series.4.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1016-VaryingNumberOfConsumers-SessionTrans.chartdef b/java/perftests/etc/chartdefs/1016-VaryingNumberOfConsumers-SessionTrans.chartdef
new file mode 100644
index 0000000000..0afd162ad0
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1016-VaryingNumberOfConsumers-SessionTrans.chartdef
@@ -0,0 +1,47 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Varying number of consumers - transacted
+chartSubtitle=Persistent 1KB messages
+chartDescription=1,2,5,10 P/Cs, persistent, transacted, with message payload 1KB.
+
+xAxisTitle=Consumers
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '1' and acknowledgeMode = '0'
+series.1.legend=1 Producer
+series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
+
+series.2.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '5' and acknowledgeMode = '0'
+series.2.legend=5 Producers
+series.2.dir=${csvCurrentDir}
+series.2.colourName=green
+
+series.3.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '10' and acknowledgeMode = '0'
+series.3.legend=10 Producers
+series.3.dir=${csvCurrentDir}
+series.3.colourName=red
+
+series.4.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '10' and acknowledgeMode = '0'
+series.4.legend=10 Producers (baseline)
+series.4.dir=${csvBaselineDir}
+series.4.colourName=dark_red
+series.4.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1021-AcknowledgementModes-Persistent.chartdef b/java/perftests/etc/chartdefs/1021-AcknowledgementModes-Persistent.chartdef
index 30aee40c27..827f8b5567 100644
--- a/java/perftests/etc/chartdefs/1021-AcknowledgementModes-Persistent.chartdef
+++ b/java/perftests/etc/chartdefs/1021-AcknowledgementModes-Persistent.chartdef
@@ -19,17 +19,20 @@
chartType=BAR
chartTitle=Performance of acknowledgement modes
-chartSubtitle=Persistent messages (1024b)
+chartSubtitle=Persistent messages (1KB)
+chartDescription=1P 1C, persistent, with message payload 1KB.
+
xAxisTitle=Acknowledge mode (0=session transacted; 1=auto-acknowledge)
-yAxisTitle=Throughput (KB/s)
+yAxisTitle=Throughput (messages/s)
-series.1.statement=SELECT acknowledgeMode, throughputKbPerS FROM AcknowledgementModes WHERE testName like 'Persistent%' AND participantName = 'All' ORDER BY acknowledgeMode
+series.1.statement=SELECT acknowledgeMode, throughputMessagesPerS FROM AcknowledgementModes WHERE testName like 'Persistent%' AND participantName = 'All' ORDER BY acknowledgeMode
series.1.legend=Current
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
-
-series.2.statement=SELECT acknowledgeMode, throughputKbPerS FROM AcknowledgementModes WHERE testName like 'Persistent%' AND participantName = 'All' ORDER BY acknowledgeMode
+series.2.statement=SELECT acknowledgeMode, throughputMessagesPerS FROM AcknowledgementModes WHERE testName like 'Persistent%' AND participantName = 'All' ORDER BY acknowledgeMode
series.2.legend=Baseline
series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
diff --git a/java/perftests/etc/chartdefs/1022-AcknowledgementModes-Transient.chartdef b/java/perftests/etc/chartdefs/1022-AcknowledgementModes-Transient.chartdef
index 7a26391deb..8ca5d838e2 100644
--- a/java/perftests/etc/chartdefs/1022-AcknowledgementModes-Transient.chartdef
+++ b/java/perftests/etc/chartdefs/1022-AcknowledgementModes-Transient.chartdef
@@ -20,13 +20,17 @@
chartType=BAR
chartTitle=Performance of acknowledgement modes
chartSubtitle=Transient messages (1024b)
+chartDescription=1P 1C, transient, with message payload 1KB.
+
xAxisTitle=Acknowledge mode (0=session transacted; 1=auto-acknowledge)
-yAxisTitle=Throughput (KB/s)
+yAxisTitle=Throughput (messages/s)
-series.1.statement=SELECT acknowledgeMode, throughputKbPerS FROM AcknowledgementModes WHERE testName like 'Transient%' AND participantName = 'All' ORDER BY acknowledgeMode
+series.1.statement=SELECT acknowledgeMode, throughputMessagesPerS FROM AcknowledgementModes WHERE testName like 'Transient%' AND participantName = 'All' ORDER BY acknowledgeMode
series.1.legend=Current
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
-series.2.statement=SELECT acknowledgeMode, throughputKbPerS FROM AcknowledgementModes WHERE testName like 'Transient%' AND participantName = 'All' ORDER BY acknowledgeMode
+series.2.statement=SELECT acknowledgeMode, throughputMessagesPerS FROM AcknowledgementModes WHERE testName like 'Transient%' AND participantName = 'All' ORDER BY acknowledgeMode
series.2.legend=Baseline
series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
diff --git a/java/perftests/etc/chartdefs/1030-BatchSize-Equal.chartdef b/java/perftests/etc/chartdefs/1030-BatchSize-Equal.chartdef
new file mode 100644
index 0000000000..97b712e027
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1030-BatchSize-Equal.chartdef
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Transaction Batch Sizes Equal
+chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1C, persistent, transacted with message payload 1KB with producer/consumer batch size varying between 1-400 messages for both P and C
+
+xAxisTitle=Batch Size
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT batchSize, throughputMessagesPerS FROM BatchSize WHERE participantName = 'All'
+series.1.legend=Equal Producer/Consumer
+series.1.dir=${csvCurrentDir}
+series.1.colourName=red
+
+series.2.statement=SELECT batchSize, throughputMessagesPerS FROM BatchSize WHERE participantName = 'All'
+series.2.legend=Equal Producer/Consumer (Baseline)
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1030-BatchSize.chartdef b/java/perftests/etc/chartdefs/1030-BatchSize.chartdef
deleted file mode 100644
index 1f01aa85aa..0000000000
--- a/java/perftests/etc/chartdefs/1030-BatchSize.chartdef
+++ /dev/null
@@ -1,33 +0,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.
-#
-
-chartType=XYLINE
-chartTitle=Transaction Batch Size
-chartSubtitle=Persistent 1KB messages
-xAxisTitle=Batch Size
-yAxisTitle=Throughput (KB/s)
-
-series.1.statement=SELECT batchSize, throughputKbPerS FROM BatchSize WHERE participantName = 'All'
-series.1.legend=Current
-series.1.dir=${csvCurrentDir}
-
-series.2.statement=SELECT batchSize, throughputKbPerS FROM BatchSize WHERE participantName = 'All'
-series.2.legend=Baseline
-series.2.dir=${csvBaselineDir}
-
diff --git a/java/perftests/etc/chartdefs/1031-BatchSize-Unequal.chartdef b/java/perftests/etc/chartdefs/1031-BatchSize-Unequal.chartdef
new file mode 100644
index 0000000000..51b3bb2144
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1031-BatchSize-Unequal.chartdef
@@ -0,0 +1,53 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Transaction Batch Size Unequal
+chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1C, persistent, transacted with message payload 1KB with fixed batch size 1 for one party whilst other varies between 1-400 messages
+
+xAxisTitle=Batch Size
+yAxisTitle=Throughput (messages/s)
+
+#
+# If csvjdbc could do sub-selects (allowing us to extract the consumer/producer batch size from the All Consumers/All Producers rows),
+# we would not need the workaround where we have testdef place the consumer/producer batch size into testName field
+#
+
+series.1.statement=SELECT testName, throughputMessagesPerS FROM BatchSizeProducerVaries WHERE participantName = 'All'
+series.1.legend=Variable Producer, Fixed Consumer
+series.1.dir=${csvCurrentDir}
+series.1.colourName=red
+
+series.2.statement=SELECT testName, throughputMessagesPerS FROM BatchSizeProducerVaries WHERE participantName = 'All'
+series.2.legend=Variable Producer, Fixed Consumer (Baseline)
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.strokeWidth=-1
+
+series.3.statement=SELECT testName, throughputMessagesPerS FROM BatchSizeConsumerVaries WHERE participantName = 'All'
+series.3.legend=Fixed Producer, Variable Consumer
+series.3.dir=${csvCurrentDir}
+series.3.colourName=blue
+
+series.4.statement=SELECT testName, throughputMessagesPerS FROM BatchSizeConsumerVaries WHERE participantName = 'All'
+series.4.legend=Fixed Producer, Variable Consumer (Baseline)
+series.4.dir=${csvBaselineDir}
+series.4.colourName=dark_blue
+series.4.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1040-QueueTypes.chartdef b/java/perftests/etc/chartdefs/1040-QueueTypes.chartdef
index 42ed69c19d..aacedab421 100644
--- a/java/perftests/etc/chartdefs/1040-QueueTypes.chartdef
+++ b/java/perftests/etc/chartdefs/1040-QueueTypes.chartdef
@@ -20,13 +20,17 @@
chartType=BAR
chartTitle=Queue Types
chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1C, persistent, auto-ack with message payload 1KB. Sorted queue - 160,000 random keys, Priority - iteriates priority 0..9.
+
xAxisTitle=Queue Types
-yAxisTitle=Throughput (KB/s)
+yAxisTitle=Throughput (messages/s)
-series.1.statement=SELECT testName, throughputKbPerS FROM QueueTypes WHERE participantName = 'All'
+series.1.statement=SELECT testName, throughputMessagesPerS FROM QueueTypes WHERE participantName = 'All'
series.1.legend=Current
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
-series.2.statement=SELECT testName, throughputKbPerS FROM QueueTypes WHERE participantName = 'All'
+series.2.statement=SELECT testName, throughputMessagesPerS FROM QueueTypes WHERE participantName = 'All'
series.2.legend=Baseline
series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
diff --git a/java/perftests/etc/chartdefs/1050-VaryingNumberOfProducerSessionsSingleConnection.chartdef b/java/perftests/etc/chartdefs/1050-VaryingNumberOfProducerSessionsSingleConnection.chartdef
new file mode 100644
index 0000000000..46696bf942
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1050-VaryingNumberOfProducerSessionsSingleConnection.chartdef
@@ -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.
+#
+
+chartType=XYLINE
+chartTitle=Varying number of producer sessions on single connection
+chartSubtitle=Persistent messages (1024b)
+chartDescription=1-80P transacted on single connection, 20C transacted on separate connections, persistent, message payload 1KB.
+
+xAxisTitle=Number of producer sessions
+yAxisTitle=Throughput (KB/s)
+
+# testName contains the number of sessions
+series.1.statement=SELECT testName, throughputKbPerS FROM VaryingNumberOfProducerSessionsSingleConnection WHERE participantName = 'All'
+series.1.legend=Current - End-to-end throughput
+series.1.dir=${csvCurrentDir}
+series.1.colourName=red
+
+series.2.statement=SELECT testName, throughputKbPerS FROM VaryingNumberOfProducerSessionsSingleConnection WHERE participantName = 'All Producers'
+series.2.legend=Current - Producer only throughput
+series.2.dir=${csvCurrentDir}
+series.2.colourName=blue
+
+series.3.statement=SELECT testName, throughputKbPerS FROM VaryingNumberOfProducerSessionsSingleConnection WHERE participantName = 'All'
+series.3.legend=Baseline - End-to-end throughput
+series.3.dir=${csvBaselineDir}
+series.3.colourName=dark_red
+series.3.strokeWidth=-1
+
+series.4.statement=SELECT testName, throughputKbPerS FROM VaryingNumberOfProducerSessionsSingleConnection WHERE participantName = 'All Producers'
+series.4.legend=Baseline - Producer only throughput
+series.4.dir=${csvBaselineDir}
+series.4.colourName=dark_blue
+series.4.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1300-QueueConsumersWithNonOverlappingSelectors-Transient.chartdef b/java/perftests/etc/chartdefs/1300-QueueConsumersWithNonOverlappingSelectors-Transient.chartdef
new file mode 100644
index 0000000000..5081b379e7
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1300-QueueConsumersWithNonOverlappingSelectors-Transient.chartdef
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+chartType=XYLINE
+chartTitle=Impact of non-overlapping selectors on queue consumers with transient messages
+chartSubtitle=Transient 1KB messages
+xAxisTitle=Consumers
+yAxisTitle=Throughput (messages/s)
+chartDescription=Impact of non-overlapping selectors on queue consumers with transient messages, auto-ack, message payload of 1024 bytes, 1 producer, varying number of consumers from 1 to 32.
+
+series.1.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM QueueConsumersWithNonOverlappingSelectors WHERE participantName = 'All' and testName like '%non overlapping - NON_PERSISTENT%'
+series.1.legend=Current
+series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
+
+series.2.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM QueueConsumersWithNonOverlappingSelectors WHERE participantName = 'All' and testName like '%non overlapping - NON_PERSISTENT%'
+series.2.legend=Baseline
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.stokeWidth=-1
+
diff --git a/java/perftests/etc/chartdefs/1301-QueueConsumersWithNonOverlappingSelectors-Persistent.chartdef b/java/perftests/etc/chartdefs/1301-QueueConsumersWithNonOverlappingSelectors-Persistent.chartdef
new file mode 100644
index 0000000000..137f7bde36
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1301-QueueConsumersWithNonOverlappingSelectors-Persistent.chartdef
@@ -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.
+#
+
+chartType=XYLINE
+chartTitle=Impact of non-overlapping selectors on queue consumers with persistent messages
+chartSubtitle=Persistent 1KB messages
+xAxisTitle=Consumers
+yAxisTitle=Throughput (messages/s)
+chartDescription=Impact of non-overlapping selectors on queue consumers with persistent messages, auto-ack, message payload of 1024 bytes, 1 producer, varying number of consumers from 1 to 32..
+
+
+series.1.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM QueueConsumersWithNonOverlappingSelectors WHERE participantName = 'All' and testName like '%non overlapping - PERSISTENT'
+series.1.legend=Current
+series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
+
+series.2.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM QueueConsumersWithNonOverlappingSelectors WHERE participantName = 'All' and testName like '%non overlapping - PERSISTENT'
+series.2.legend=Baseline
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.stokeWidth=-1
+
+series.3.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '1' and acknowledgeMode = '1'
+series.3.legend=Current: no selectors
+series.3.dir=${csvCurrentDir}
+series.3.colourName=green
+
diff --git a/java/perftests/etc/chartdefs/1302-QueueConsumersWithOverlappingSelectors-Transient.chartdef b/java/perftests/etc/chartdefs/1302-QueueConsumersWithOverlappingSelectors-Transient.chartdef
new file mode 100644
index 0000000000..74f370317b
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1302-QueueConsumersWithOverlappingSelectors-Transient.chartdef
@@ -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.
+#
+
+chartType=XYLINE
+chartTitle=Impact of 50%-overlapping selectors in queue consumers with transient messages
+chartSubtitle=Transient 1KB messages
+xAxisTitle=Consumers
+yAxisTitle=Throughput (messages/s)
+chartDescription=Impact of 50%-overlapping selectors in queue consumers with transient messages, auto-ack, message payload 1KB, 1 producer, varying number of consumers from 2 to 32.
+
+series.1.statement=SELECT totalNumberOfConsumers,throughputMessagesPerS FROM QueueConsumersWithOverlappingSelectors WHERE participantName = 'All' and testName like '%50_ overlapping - NON_PERSISTENT%'
+series.1.legend=Current
+series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
+
+series.2.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM QueueConsumersWithOverlappingSelectors WHERE participantName = 'All' and testName like '%50_ overlapping - NON_PERSISTENT%'
+series.2.legend=Baseline
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.stokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1303-QueueConsumersWithOverlappingSelectors-Persistent.chartdef b/java/perftests/etc/chartdefs/1303-QueueConsumersWithOverlappingSelectors-Persistent.chartdef
new file mode 100644
index 0000000000..0dd78e02ef
--- /dev/null
+++ b/java/perftests/etc/chartdefs/1303-QueueConsumersWithOverlappingSelectors-Persistent.chartdef
@@ -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.
+#
+
+chartType=XYLINE
+chartTitle=Impact of 50%-overlapping selectors in queue consumers with persistent messages
+chartDescription=Impact of 50%-overlapping selectors in queue consumers with persistent messages, auto-ack, message payload of 1KB, 1 producer, varying number of consumers from 2 to 32.
+chartSubtitle=Persistent 1KB messages
+xAxisTitle=Consumers
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM QueueConsumersWithOverlappingSelectors WHERE participantName = 'All' and testName like '%50_ overlapping - PERSISTENT%'
+series.1.legend=Current
+series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
+
+series.2.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM QueueConsumersWithOverlappingSelectors WHERE participantName = 'All' and testName like '%50_ overlapping - PERSISTENT%'
+series.2.legend=Baseline
+series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.stokeWidth=-1
+
+series.3.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM VaryingNumberOfParticipants WHERE participantName = 'All' and totalNumberOfProducers = '1' and acknowledgeMode = '1'
+series.3.legend=Current: no selectors
+series.3.dir=${csvCurrentDir}
+series.3.colourName=green
+
diff --git a/java/perftests/etc/chartdefs/1500-Topic-NumberOfConsumers.chartdef b/java/perftests/etc/chartdefs/1500-Topic-NumberOfConsumers.chartdef
index 305c5009e2..073cee810d 100644
--- a/java/perftests/etc/chartdefs/1500-Topic-NumberOfConsumers.chartdef
+++ b/java/perftests/etc/chartdefs/1500-Topic-NumberOfConsumers.chartdef
@@ -20,13 +20,18 @@
chartType=XYLINE
chartTitle=Number of topic consumers
chartSubtitle=Transient 1KB messages
+chartDescription=1P 1-100C transient, transacted, with message payload 1KB.
+
xAxisTitle=Numer of consumers
-yAxisTitle=Throughput (KB/s)
+yAxisTitle=Throughput (messages/s)
-series.1.statement=SELECT testName, throughputKbPerS FROM Topic-NumberOfConsumers WHERE participantName = 'All'
+series.1.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM Topic-NumberOfConsumers WHERE participantName = 'All'
series.1.legend=Current
series.1.dir=${csvCurrentDir}
+series.1.colourName=red
-series.2.statement=SELECT testName, throughputKbPerS FROM Topic-NumberOfConsumers WHERE participantName = 'All'
+series.2.statement=SELECT totalNumberOfConsumers, throughputMessagesPerS FROM Topic-NumberOfConsumers WHERE participantName = 'All'
series.2.legend=Baseline
series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1501-Topic-NumberOfTopics.chartdef b/java/perftests/etc/chartdefs/1501-Topic-NumberOfTopics.chartdef
index 9bc53e5a9e..b32f43d0c2 100644
--- a/java/perftests/etc/chartdefs/1501-Topic-NumberOfTopics.chartdef
+++ b/java/perftests/etc/chartdefs/1501-Topic-NumberOfTopics.chartdef
@@ -20,13 +20,18 @@
chartType=XYLINE
chartTitle=Number of topics
chartSubtitle=Transient 1KB messages
+chartDescription=1,10,50,100 PC, transient, transacted, with each PC pair having own topic, message payload 1KB.
+
xAxisTitle=Numer of topics
-yAxisTitle=Throughput (KB/s)
+yAxisTitle=Throughput (messages/s)
-series.1.statement=SELECT testName, throughputKbPerS FROM Topic-NumberOfTopics WHERE participantName = 'All'
+series.1.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM Topic-NumberOfTopics WHERE participantName = 'All'
series.1.legend=Current
series.1.dir=${csvCurrentDir}
+series.1.colourName=red
-series.2.statement=SELECT testName, throughputKbPerS FROM Topic-NumberOfTopics WHERE participantName = 'All'
+series.2.statement=SELECT totalNumberOfProducers, throughputMessagesPerS FROM Topic-NumberOfTopics WHERE participantName = 'All'
series.2.legend=Baseline
series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.strokeWidth=-1
diff --git a/java/perftests/etc/chartdefs/1502-Topic-Persistence.chartdef b/java/perftests/etc/chartdefs/1502-Topic-Persistence.chartdef
index ce64d14ac4..5fd905ab4f 100644
--- a/java/perftests/etc/chartdefs/1502-Topic-Persistence.chartdef
+++ b/java/perftests/etc/chartdefs/1502-Topic-Persistence.chartdef
@@ -20,13 +20,18 @@
chartType=BAR
chartTitle=Topic transient/durable subscriptions
chartSubtitle=1KB messages
-xAxisTitle=Durable subscription
-yAxisTitle=Throughput (KB/s)
+chartDescription=1P 10C, transacted, message payload 1KB, transient messages on non-durable sub, persistent messages on durable sub
-series.1.statement=SELECT isDurableSubscription, throughputKbPerS FROM Topic-Persistence WHERE participantName = 'All Consumers'
+xAxisTitle=Subscription type (true durable, false non durable)
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT isDurableSubscription, throughputMessagesPerS FROM Topic-Persistence WHERE participantName = 'All Consumers'
series.1.legend=Current
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
-series.2.statement=SELECT isDurableSubscription, throughputKbPerS FROM Topic-Persistence WHERE participantName = 'All Consumers'
+series.2.statement=SELECT isDurableSubscription, throughputMessagesPerS FROM Topic-Persistence WHERE participantName = 'All Consumers'
series.2.legend=Baseline
series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.stokeWidth=2
diff --git a/java/perftests/etc/chartdefs/1503-Topic-AckModes.chartdef b/java/perftests/etc/chartdefs/1503-Topic-AckModes.chartdef
index 5ccc166fc8..9edb1950a4 100644
--- a/java/perftests/etc/chartdefs/1503-Topic-AckModes.chartdef
+++ b/java/perftests/etc/chartdefs/1503-Topic-AckModes.chartdef
@@ -20,13 +20,18 @@
chartType=BAR
chartTitle=Topic acknowledge modes
chartSubtitle=Transient 1KB messages
-xAxisTitle=Ack Mode
-yAxisTitle=Throughput (KB/s)
+chartDescription=1P 10C, transient, non-durable subscription, message payload 1KB
-series.1.statement=SELECT acknowledgeMode, throughputKbPerS FROM Topic-AckModes WHERE participantName = 'All'
+xAxisTitle=Ack Mode (0=transaction 1=auto-ack)
+yAxisTitle=Throughput (messages/s)
+
+series.1.statement=SELECT acknowledgeMode, throughputMessagesPerS FROM Topic-AckModes WHERE participantName = 'All'
series.1.legend=Current
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
-series.2.statement=SELECT acknowledgeMode, throughputKbPerS FROM Topic-AckModes WHERE participantName = 'All'
+series.2.statement=SELECT acknowledgeMode, throughputMessagesPerS FROM Topic-AckModes WHERE participantName = 'All'
series.2.legend=Baseline
series.2.dir=${csvBaselineDir}
+series.2.colourName=dark_red
+series.2.stokeWidth=2
diff --git a/java/perftests/etc/chartdefs/2001-Latency-MessageSize-Transient.chartdef b/java/perftests/etc/chartdefs/2001-Latency-MessageSize-Transient.chartdef
index c892ea16cf..67a0278bff 100644
--- a/java/perftests/etc/chartdefs/2001-Latency-MessageSize-Transient.chartdef
+++ b/java/perftests/etc/chartdefs/2001-Latency-MessageSize-Transient.chartdef
@@ -20,21 +20,27 @@
chartType=STATISTICAL_BAR
chartTitle=Impact of message size on latency
chartSubtitle=Transient messages
+chartDescription=1P 1C, transient, auto-ack, with message payload between 256-262144 bytes.
+
xAxisTitle=Message Size (B)
yAxisTitle=Latency (millis)
series.1.statement=SELECT payloadSizeB, maxLatency, 0 FROM Latency-MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All Consumers'
series.1.legend=Maximum latency
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
series.2.statement=SELECT payloadSizeB, averageLatency,latencyStandardDeviation FROM Latency-MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All Consumers'
series.2.legend=Average latency
series.2.dir=${csvCurrentDir}
+series.2.colourName=red
series.3.statement=SELECT payloadSizeB, averageLatency,latencyStandardDeviation FROM Latency-MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All Consumers'
series.3.legend=Average latency (baseline)
series.3.dir=${csvBaselineDir}
+series.3.colourName=dark_red
series.4.statement=SELECT payloadSizeB, minLatency,0 FROM Latency-MessageSize WHERE testName like '%TRANSIENT' AND participantName = 'All Consumers'
series.4.legend=Minimum latency
series.4.dir=${csvCurrentDir}
+series.4.colourName=green
diff --git a/java/perftests/etc/chartdefs/2002-Latency-MessageSize-Persistent.chartdef b/java/perftests/etc/chartdefs/2002-Latency-MessageSize-Persistent.chartdef
index 167e62603a..e9761f07d8 100644
--- a/java/perftests/etc/chartdefs/2002-Latency-MessageSize-Persistent.chartdef
+++ b/java/perftests/etc/chartdefs/2002-Latency-MessageSize-Persistent.chartdef
@@ -20,21 +20,27 @@
chartType=STATISTICAL_BAR
chartTitle=Impact of message size on latency
chartSubtitle=Persistent messages
+chartDescription=1P 1C, persistent, auto-ack, with message payload between 256-262144 bytes.
+
xAxisTitle=Message Size (B)
yAxisTitle=Latency (millis)
series.1.statement=SELECT payloadSizeB, maxLatency, 0 FROM Latency-MessageSize WHERE testName like '%PERSISTENT' AND participantName = 'All Consumers'
series.1.legend=Maximum latency
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
series.2.statement=SELECT payloadSizeB, averageLatency, latencyStandardDeviation FROM Latency-MessageSize WHERE testName like '%PERSISTENT' AND participantName = 'All Consumers'
series.2.legend=Average latency
series.2.dir=${csvCurrentDir}
+series.2.colourName=red
series.3.statement=SELECT payloadSizeB, averageLatency, latencyStandardDeviation FROM Latency-MessageSize WHERE testName like '%PERSISTENT' AND participantName = 'All Consumers'
series.3.legend=Average latency (baseline)
series.3.dir=${csvBaselineDir}
+series.3.colourName=dark_red
series.4.statement=SELECT payloadSizeB, minLatency, 0 FROM Latency-MessageSize WHERE testName like '%PERSISTENT' AND participantName = 'All Consumers'
series.4.legend=Minimum latency
series.4.dir=${csvCurrentDir}
+series.4.colourName=green
diff --git a/java/perftests/etc/chartdefs/2011-Latency-QueuesWithNonOverlappingSelectors-Transient.chartdef b/java/perftests/etc/chartdefs/2011-Latency-QueuesWithNonOverlappingSelectors-Transient.chartdef
index 45c6031b1e..663912b622 100644
--- a/java/perftests/etc/chartdefs/2011-Latency-QueuesWithNonOverlappingSelectors-Transient.chartdef
+++ b/java/perftests/etc/chartdefs/2011-Latency-QueuesWithNonOverlappingSelectors-Transient.chartdef
@@ -20,21 +20,27 @@
chartType=STATISTICAL_BAR
chartTitle=Latency with consumers having non-overlapping selectors
chartSubtitle=Transient 1KB messages
+chartDescription=1P 1-10C, transient, auto-ack, with message payload 1KB.
+
xAxisTitle=Consumers
yAxisTitle=Latency (millis)
series.1.statement=SELECT totalNumberOfConsumers, maxLatency, 0 FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%non overlapping - NON_PERSISTENT%'
series.1.legend=Max latency
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
series.2.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%non overlapping - NON_PERSISTENT%'
series.2.legend=Average latency
series.2.dir=${csvCurrentDir}
+series.2.colourName=red
series.3.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%non overlapping - NON_PERSISTENT%'
series.3.legend=Average latency (baseline)
series.3.dir=${csvBaselineDir}
+series.3.colourName=dark_red
series.4.statement=SELECT totalNumberOfConsumers, minLatency, 0 FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%non overlapping - NON_PERSISTENT%'
series.4.legend=Min latency
series.4.dir=${csvCurrentDir}
+series.4.colourName=green
diff --git a/java/perftests/etc/chartdefs/2012-Latency-QueuesWithOverlappingSelectors-Transient.chartdef b/java/perftests/etc/chartdefs/2012-Latency-QueuesWithOverlappingSelectors-Transient.chartdef
index 351a4639b1..3b9e207e10 100644
--- a/java/perftests/etc/chartdefs/2012-Latency-QueuesWithOverlappingSelectors-Transient.chartdef
+++ b/java/perftests/etc/chartdefs/2012-Latency-QueuesWithOverlappingSelectors-Transient.chartdef
@@ -20,21 +20,27 @@
chartType=STATISTICAL_BAR
chartTitle=Latency with consumers having 50%-overlapping selectors
chartSubtitle=Transient 1KB messages
+chartDescription=1P 1-10C, transient, auto-ack, with message payload 1KB.
+
xAxisTitle=Consumers
yAxisTitle=Latency (millis)
series.1.statement=SELECT totalNumberOfConsumers, maxLatency, 0 FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%overlapping 50% - NON_PERSISTENT%'
series.1.legend=Max latency
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
series.2.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%overlapping 50% - NON_PERSISTENT%'
series.2.legend=Average latency
series.2.dir=${csvCurrentDir}
+series.2.colourName=red
series.3.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%overlapping 50% - NON_PERSISTENT%'
series.3.legend=Average latency (baseline)
series.3.dir=${csvBaselineDir}
+series.3.colourName=dark_red
series.4.statement=SELECT totalNumberOfConsumers, minLatency, 0 FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%overlapping 50% - NON_PERSISTENT%'
series.4.legend=Min latency
series.4.dir=${csvCurrentDir}
+series.4.colourName=green
diff --git a/java/perftests/etc/chartdefs/2021-Latency-QueuesWithNonOverlappingSelectors-Persistent.chartdef b/java/perftests/etc/chartdefs/2021-Latency-QueuesWithNonOverlappingSelectors-Persistent.chartdef
index 9d95075b3d..296d115d3f 100644
--- a/java/perftests/etc/chartdefs/2021-Latency-QueuesWithNonOverlappingSelectors-Persistent.chartdef
+++ b/java/perftests/etc/chartdefs/2021-Latency-QueuesWithNonOverlappingSelectors-Persistent.chartdef
@@ -20,21 +20,27 @@
chartType=STATISTICAL_BAR
chartTitle=Latency with consumers having non-overlapping selectors
chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1-10C, persistent, auto-ack, with message payload 1KB.
+
xAxisTitle=Consumers
yAxisTitle=Latency (millis)
series.1.statement=SELECT totalNumberOfConsumers, maxLatency,0 FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%non overlapping - PERSISTENT'
series.1.legend=Max latency
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
series.2.statement=SELECT totalNumberOfConsumers, averageLatency, latencyStandardDeviation FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%non overlapping - PERSISTENT'
series.2.legend=Average latency
series.2.dir=${csvCurrentDir}
+series.2.colourName=red
series.3.statement=SELECT totalNumberOfConsumers, averageLatency, latencyStandardDeviation FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%non overlapping - PERSISTENT'
series.3.legend=Average latency (baseline)
series.3.dir=${csvBaselineDir}
+series.3.colourName=dark_red
series.4.statement=SELECT totalNumberOfConsumers, minLatency, 0 FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%non overlapping - PERSISTENT'
series.4.legend=Min latency
series.4.dir=${csvCurrentDir}
+series.4.colourName=green
diff --git a/java/perftests/etc/chartdefs/2022-Latency-QueuesWithOverlappingSelectors-Persistent.chartdef b/java/perftests/etc/chartdefs/2022-Latency-QueuesWithOverlappingSelectors-Persistent.chartdef
index 9a323d4044..65be60b5e5 100644
--- a/java/perftests/etc/chartdefs/2022-Latency-QueuesWithOverlappingSelectors-Persistent.chartdef
+++ b/java/perftests/etc/chartdefs/2022-Latency-QueuesWithOverlappingSelectors-Persistent.chartdef
@@ -20,21 +20,27 @@
chartType=STATISTICAL_BAR
chartTitle=Latency with consumers having 50%-overlapping selectors
chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1-10C, persistent, auto-ack, with message payload 1KB.
+
xAxisTitle=Consumers
yAxisTitle=Latency (millis)
series.1.statement=SELECT totalNumberOfConsumers, maxLatency, 0 FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%overlapping 50% - PERSISTENT%'
series.1.legend=Max latency
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
series.2.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%overlapping 50% - PERSISTENT%'
series.2.legend=Average latency
series.2.dir=${csvCurrentDir}
+series.2.colourName=red
series.3.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%overlapping 50% - PERSISTENT%'
series.3.legend=Average latency (baseline)
series.3.dir=${csvBaselineDir}
+series.3.colourName=dark_red
series.4.statement=SELECT totalNumberOfConsumers, minLatency, 0 FROM Latency-QueuesWithSelectors WHERE participantName = 'All Consumers' and testName like '%overlapping 50% - PERSISTENT%'
series.4.legend=Min latency
series.4.dir=${csvCurrentDir}
+series.4.colourName=green
diff --git a/java/perftests/etc/chartdefs/2031-Latency-VaryingNumberOfParticipants.chartdef b/java/perftests/etc/chartdefs/2031-Latency-VaryingNumberOfParticipants.chartdef
index 82cf1168ef..d52b05d870 100644
--- a/java/perftests/etc/chartdefs/2031-Latency-VaryingNumberOfParticipants.chartdef
+++ b/java/perftests/etc/chartdefs/2031-Latency-VaryingNumberOfParticipants.chartdef
@@ -20,25 +20,32 @@
chartType=STATISTICAL_BAR
chartTitle=Latency, varying number of participants
chartSubtitle=Persistent 1KB messages
+chartDescription=1,2,5,10 P/Cs, persistent, auto-ack, with message payload 1KB.
+
xAxisTitle=Consumers
yAxisTitle=Latency (millis)
series.1.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-VaryingNumberOfParticipants WHERE participantName = 'All Consumers' and testName like '% - 1 producer - PERSISTENT'
series.1.legend=1 producer
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
series.2.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-VaryingNumberOfParticipants WHERE participantName = 'All Consumers' and testName like '% - 2 producers - PERSISTENT'
series.2.legend=2 producers
series.2.dir=${csvCurrentDir}
+series.2.colourName=green
series.3.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-VaryingNumberOfParticipants WHERE participantName = 'All Consumers' and testName like '% - 5 producers - PERSISTENT'
series.3.legend=5 producers
series.3.dir=${csvCurrentDir}
+series.3.colourName=magenta
series.4.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-VaryingNumberOfParticipants WHERE participantName = 'All Consumers' and testName like '% - 10 producers - PERSISTENT'
series.4.legend=10 producers
series.4.dir=${csvCurrentDir}
+series.4.colourName=red
series.5.statement=SELECT totalNumberOfConsumers, averageLatency,latencyStandardDeviation FROM Latency-VaryingNumberOfParticipants WHERE participantName = 'All Consumers' and testName like '% - 10 producers - PERSISTENT'
series.5.legend=10 producers (baseline)
series.5.dir=${csvBaselineDir}
+series.5.colourName=dark_red
diff --git a/java/perftests/etc/chartdefs/2041-Latency-QueueTypes.chartdef b/java/perftests/etc/chartdefs/2041-Latency-QueueTypes.chartdef
index c1aae19376..dac8a52f89 100644
--- a/java/perftests/etc/chartdefs/2041-Latency-QueueTypes.chartdef
+++ b/java/perftests/etc/chartdefs/2041-Latency-QueueTypes.chartdef
@@ -20,21 +20,27 @@
chartType=STATISTICAL_BAR
chartTitle=Latency on different queues
chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1C, persistent, auto-ack with message payload 1KB. Sorted queue - 400 varied keys, Priority - 200 varied priorities.
+
xAxisTitle=Queue type
yAxisTitle=Latency (millis)
series.1.statement=SELECT testName, maxLatency,0 FROM Latency-QueueTypes WHERE participantName = 'All Consumers'
series.1.legend=Maximum latency
series.1.dir=${csvCurrentDir}
+series.1.colourName=blue
series.2.statement=SELECT testName, averageLatency,latencyStandardDeviation FROM Latency-QueueTypes WHERE participantName = 'All Consumers'
series.2.legend=Average Latency
series.2.dir=${csvCurrentDir}
+series.2.colourName=red
series.3.statement=SELECT testName, averageLatency,latencyStandardDeviation FROM Latency-QueueTypes WHERE participantName = 'All Consumers'
series.3.legend=Average Latency (baseline)
series.3.dir=${csvBaselineDir}
+series.3.colourName=dark_red
series.4.statement=SELECT testName, minLatency,0 FROM Latency-QueueTypes WHERE participantName = 'All Consumers'
series.4.legend=Minimum latency
series.4.dir=${csvCurrentDir}
+series.4.colourName=green
diff --git a/java/perftests/etc/chartdefs/timeseries/1001-Large-Messages-Transient.chartdef b/java/perftests/etc/chartdefs/timeseries/1001-Large-Messages-Transient.chartdef
new file mode 100644
index 0000000000..e77f7b4eff
--- /dev/null
+++ b/java/perftests/etc/chartdefs/timeseries/1001-Large-Messages-Transient.chartdef
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+chartType=TIMELINE
+chartTitle=Large transient messages
+chartDescription=1P 1C, transient, auto-ack, with message payload 65536 bytes.
+
+xAxisTitle=Date
+yAxisTitle=Throughput (KB/s)
+
+series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Message Size - 1P-1C - TRANSIENT' and payloadSizeB = 65536
+series.1.colourName=red
+series.1.legend=Throughput
diff --git a/java/perftests/etc/chartdefs/timeseries/1002-Large-Messages-Persistent.chartdef b/java/perftests/etc/chartdefs/timeseries/1002-Large-Messages-Persistent.chartdef
new file mode 100644
index 0000000000..ffcf8c26b8
--- /dev/null
+++ b/java/perftests/etc/chartdefs/timeseries/1002-Large-Messages-Persistent.chartdef
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+chartType=TIMELINE
+chartTitle=Large persistent messages
+chartDescription=1P 1C, persistent, auto-ack, with message payload 65536 bytes.
+
+xAxisTitle=Date
+yAxisTitle=Throughput (KB/s)
+
+series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Message Size - 1P-1C - PERSISTENT' and payloadSizeB = 65536
+series.1.colourName=red
+series.1.legend=Throughput
diff --git a/java/perftests/etc/chartdefs/timeseries/1011-MultipleProducersAndConsumers-Persistent.chartdef b/java/perftests/etc/chartdefs/timeseries/1011-MultipleProducersAndConsumers-Persistent.chartdef
new file mode 100644
index 0000000000..ba01d4b7ad
--- /dev/null
+++ b/java/perftests/etc/chartdefs/timeseries/1011-MultipleProducersAndConsumers-Persistent.chartdef
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+chartType=TIMELINE
+chartTitle=Multiple producers and consumers - auto ack
+chartSubtitle=Persistent 1KB messages
+chartDescription=10 P/Cs, persistent, auto-ack, with message payload 1KB.
+
+xAxisTitle=Date
+yAxisTitle=Throughput (KB/s)
+
+series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Varying number of participants: 10 consumers - 10 producers - PERSISTENT'
+series.1.colourName=red
+series.1.legend=Throughput \ No newline at end of file
diff --git a/java/perftests/etc/chartdefs/timeseries/1030-Batch-Size-Small.chartdef b/java/perftests/etc/chartdefs/timeseries/1030-Batch-Size-Small.chartdef
new file mode 100644
index 0000000000..f755bf4a5b
--- /dev/null
+++ b/java/perftests/etc/chartdefs/timeseries/1030-Batch-Size-Small.chartdef
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+chartType=TIMELINE
+chartTitle=Transactions
+chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1C, persistent, transacted with message payload 1KB with batch size 1 for both P and C
+
+xAxisTitle=Date
+yAxisTitle=Throughput (KB/s)
+
+series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Batch Size 1-1 - PERSISTENT'
+series.1.colourName=red
+series.1.legend=Throughput \ No newline at end of file
diff --git a/java/perftests/etc/chartdefs/timeseries/1031-Batch-Size-Large.chartdef b/java/perftests/etc/chartdefs/timeseries/1031-Batch-Size-Large.chartdef
new file mode 100644
index 0000000000..ca390f8226
--- /dev/null
+++ b/java/perftests/etc/chartdefs/timeseries/1031-Batch-Size-Large.chartdef
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+chartType=TIMELINE
+chartTitle=Transactions with large batches
+chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1C, persistent, transacted with message payload 1KB with batch size 100 for both P and C
+
+xAxisTitle=Date
+yAxisTitle=Throughput (KB/s)
+
+series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'Batch Size 100-100 - PERSISTENT'
+series.1.colourName=red
+series.1.legend=Throughput
diff --git a/java/perftests/etc/chartdefs/timeseries/1040-SortedQueue.chartdef b/java/perftests/etc/chartdefs/timeseries/1040-SortedQueue.chartdef
new file mode 100644
index 0000000000..6dce3a1a77
--- /dev/null
+++ b/java/perftests/etc/chartdefs/timeseries/1040-SortedQueue.chartdef
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+chartType=TIMELINE
+chartTitle=Sorted queue
+chartSubtitle=Persistent 1KB messages
+chartDescription=1P 1C, persistent, auto-ack with message payload 1KB. Sorted queue with 160,000 random keys
+
+xAxisTitle=Date
+yAxisTitle=Throughput (KB/s)
+
+series.1.statement=SELECT insertedTimestamp, throughputKbPerS FROM RESULTS WHERE participantName = 'All' AND testName = 'queue-type:sorted-queue'
+series.1.colourName=red
+series.1.legend=Throughput \ No newline at end of file
diff --git a/java/perftests/etc/perftests-jndi.properties b/java/perftests/etc/perftests-jndi.properties
index f33af6fdd5..ce6493b49a 100644
--- a/java/perftests/etc/perftests-jndi.properties
+++ b/java/perftests/etc/perftests-jndi.properties
@@ -20,3 +20,7 @@ java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextF
connectionfactory.connectionfactory = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
destination.controllerqueue = direct://amq.direct//controllerqueue?autodelete='true'
+
+jdbcDriverClass=org.apache.derby.jdbc.EmbeddedDriver
+# writes to a results database in ./perftestResultsDb by default.
+jdbcUrl=jdbc:derby:perftestResultsDb;create=true
diff --git a/java/perftests/etc/run-perftests.sh b/java/perftests/etc/run-perftests.sh
new file mode 100755
index 0000000000..f963879e7e
--- /dev/null
+++ b/java/perftests/etc/run-perftests.sh
@@ -0,0 +1,37 @@
+#!/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.
+#
+
+# Runs the perftests using a typical configuration.
+
+BASE_DIR=`dirname $0`
+DURATION=${1:-5000}
+AMQP_VERSION=${2:-0-91}
+
+echo Will run perftests using a maximum duration of ${DURATION}ms and AMQP protocol version ${AMQP_VERSION}.
+echo
+
+java -cp "${BASE_DIR}:${BASE_DIR}/../../build/lib/*" \
+ -Dqpid.amqp.version=${AMQP_VERSION} -Dqpid.dest_syntax=BURL \
+ -Dqpid.disttest.duration=$DURATION \
+ org.apache.qpid.disttest.ControllerRunner \
+ jndi-config=${BASE_DIR}/perftests-jndi.properties \
+ test-config=${BASE_DIR}/testdefs \
+ distributed=false \
+ writeToDb=true
diff --git a/java/perftests/etc/testdefs/BatchSize.js b/java/perftests/etc/testdefs/BatchSize.js
new file mode 100644
index 0000000000..f17751b7b5
--- /dev/null
+++ b/java/perftests/etc/testdefs/BatchSize.js
@@ -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.
+ *
+ */
+
+var jsonObject = {
+ _tests:[]
+};
+
+var duration = 30000;
+
+var txBatchSizes = [[1,1], [2,2], [5,5], [10,10], [20,20], [50,50], [100,100], [200,200], [400,400]];
+
+var acknowledgeMode = 0;
+var deliveryMode = 2;
+var messageSize = 1024;
+
+for(i=0; i < txBatchSizes.length ; i++)
+{
+ var producerBatchSize = txBatchSizes[i][0];
+ var consumerBatchSize = txBatchSizes[i][1];
+ var queueName = "txBatchSize" + producerBatchSize + "_" + consumerBatchSize;
+ var destination = "direct://amq.direct//" + queueName + "?durable='true'";
+
+ var test = {
+ "_name": "Batch Size " + producerBatchSize + "-" + consumerBatchSize + " - PERSISTENT",
+ "_queues":[
+ {
+ "_name": queueName,
+ "_durable": true
+ }
+ ],
+ "_clients":[
+ {
+ "_name": "producingClient",
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": acknowledgeMode,
+ "_producers": [
+ {
+ "_name": "Producer1",
+ "_destinationName": destination,
+ "_messageSize": messageSize,
+ "_deliveryMode": deliveryMode,
+ "_batchSize": producerBatchSize,
+ "_maximumDuration": duration
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "_name": "consumingClient",
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": acknowledgeMode,
+ "_consumers": [
+ {
+ "_name": "Consumer1",
+ "_destinationName": destination,
+ "_batchSize": consumerBatchSize,
+ "_maximumDuration": duration
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ };
+
+ jsonObject._tests= jsonObject._tests.concat(test);
+}
diff --git a/java/perftests/etc/testdefs/BatchSize.json b/java/perftests/etc/testdefs/BatchSize.json
deleted file mode 100644
index eeb446bad6..0000000000
--- a/java/perftests/etc/testdefs/BatchSize.json
+++ /dev/null
@@ -1,84 +0,0 @@
-{
- "_tests":[
- {
- "_name": "Batch Size- PERSISTENT";
- "_iterations":[
- {
- "_batchSize": 1
- },
- {
- "_batchSize": 2
- },
- {
- "_batchSize": 5
- },
- {
- "_batchSize": 10
- },
- {
- "_batchSize": 20
- },
- {
- "_batchSize": 50
- },
- {
- "_batchSize": 100
- }
- ],
- "_queues":[
- {
- "_name": "direct://amq.direct//batchSize?durable='true'",
- "_durable": true
- }
- ],
- "_clients":[
- {
- "_name": "producingClient",
- "_connections":[
- {
- "_name": "connection1",
- "_factory": "connectionfactory",
- "_sessions": [
- {
- "_sessionName": "session1",
- "_acknowledgeMode": 0,
- "_producers": [
- {
- "_name": "Producer1",
- "_destinationName": "direct://amq.direct//batchSize?durable='true'",
- "_messageSize": 1024,
- "_maximumDuration": 30000,
- "_deliveryMode": 2
- }
- ]
- }
- ]
- }
- ]
- },
- {
- "_name": "consumingClient",
- "_connections":[
- {
- "_name": "connection1",
- "_factory": "connectionfactory",
- "_sessions": [
- {
- "_sessionName": "session1",
- "_acknowledgeMode": 0,
- "_consumers": [
- {
- "_name": "Consumer1",
- "_destinationName": "direct://amq.direct//batchSize?durable='true'",
- "_maximumDuration": 30000
- }
- ]
- }
- ]
- }
- ]
- }
- ]
- }
- ]
-}
diff --git a/java/perftests/etc/testdefs/BatchSizeConsumerVaries.js b/java/perftests/etc/testdefs/BatchSizeConsumerVaries.js
new file mode 100644
index 0000000000..b491f431c9
--- /dev/null
+++ b/java/perftests/etc/testdefs/BatchSizeConsumerVaries.js
@@ -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.
+ *
+ */
+
+var jsonObject = {
+ _tests:[]
+};
+
+var duration = 30000;
+
+var txBatchSizes = [[1,1], [1,2], [1,5], [1,10], [1,20], [1,50], [1,100], [1,200], [1,400]];
+
+var acknowledgeMode = 0;
+var deliveryMode = 2;
+var messageSize = 1024;
+
+for(i=0; i < txBatchSizes.length ; i++)
+{
+ var producerBatchSize = txBatchSizes[i][0];
+ var consumerBatchSize = txBatchSizes[i][1];
+ var queueName = "txBatchSize" + producerBatchSize + "_" + consumerBatchSize;
+ var destination = "direct://amq.direct//" + queueName + "?durable='true'";
+
+ var test = {
+ "_name": consumerBatchSize,// hack - use test name to expose the consumer batch size on the All result rows
+ "_queues":[
+ {
+ "_name": queueName,
+ "_durable": true
+ }
+ ],
+ "_clients":[
+ {
+ "_name": "producingClient",
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": acknowledgeMode,
+ "_producers": [
+ {
+ "_name": "Producer1",
+ "_destinationName": destination,
+ "_messageSize": messageSize,
+ "_deliveryMode": deliveryMode,
+ "_batchSize": producerBatchSize,
+ "_maximumDuration": duration
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "_name": "consumingClient",
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": acknowledgeMode,
+ "_consumers": [
+ {
+ "_name": "Consumer1",
+ "_destinationName": destination,
+ "_batchSize": consumerBatchSize,
+ "_maximumDuration": duration
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ };
+
+ jsonObject._tests= jsonObject._tests.concat(test);
+}
diff --git a/java/perftests/etc/testdefs/BatchSizeProducerVaries.js b/java/perftests/etc/testdefs/BatchSizeProducerVaries.js
new file mode 100644
index 0000000000..ac23c52c9e
--- /dev/null
+++ b/java/perftests/etc/testdefs/BatchSizeProducerVaries.js
@@ -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.
+ *
+ */
+
+var jsonObject = {
+ _tests:[]
+};
+
+var duration = 30000;
+
+var txBatchSizes = [[1,1], [2,1], [5,1], [10,1], [20,1], [50,1], [100,1], [200,1], [400,1]];
+
+var acknowledgeMode = 0;
+var deliveryMode = 2;
+var messageSize = 1024;
+
+for(i=0; i < txBatchSizes.length ; i++)
+{
+ var producerBatchSize = txBatchSizes[i][0];
+ var consumerBatchSize = txBatchSizes[i][1];
+ var queueName = "txBatchSize" + producerBatchSize + "_" + consumerBatchSize;
+ var destination = "direct://amq.direct//" + queueName + "?durable='true'";
+
+ var test = {
+ "_name": producerBatchSize,// hack - use test name to expose the producer batch size on the All result rows
+ "_queues":[
+ {
+ "_name": queueName,
+ "_durable": true
+ }
+ ],
+ "_clients":[
+ {
+ "_name": "producingClient",
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": acknowledgeMode,
+ "_producers": [
+ {
+ "_name": "Producer1",
+ "_destinationName": destination,
+ "_messageSize": messageSize,
+ "_deliveryMode": deliveryMode,
+ "_batchSize": producerBatchSize,
+ "_maximumDuration": duration
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "_name": "consumingClient",
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": acknowledgeMode,
+ "_consumers": [
+ {
+ "_name": "Consumer1",
+ "_destinationName": destination,
+ "_batchSize": consumerBatchSize,
+ "_maximumDuration": duration
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ };
+
+ jsonObject._tests= jsonObject._tests.concat(test);
+}
diff --git a/java/perftests/etc/testdefs/QueueConsumersWithNonOverlappingSelectors.js b/java/perftests/etc/testdefs/QueueConsumersWithNonOverlappingSelectors.js
new file mode 100644
index 0000000000..0dd45b0392
--- /dev/null
+++ b/java/perftests/etc/testdefs/QueueConsumersWithNonOverlappingSelectors.js
@@ -0,0 +1,120 @@
+/*
+ *
+ * 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.
+ *
+ */
+var jsonObject = {
+ _tests:[]
+};
+
+for (var i=0; i<2; i++)
+{
+ var deliveryMode = i+1;
+ var durable = (deliveryMode == 2);
+ var suffix = durable ? "PERSISTENT" : "NON-PERSISTENT";
+ var queueName = "direct://amq.direct//queue-selectors-" + suffix + "?durable='" + durable + "'";
+ var consumerNumbers = [1, 2, 4, 8, 16, 32];
+ var consumerAcknowledgeMode = 1;
+ for (var j=0; j<consumerNumbers.length; j++)
+ {
+ var consumerNumber = consumerNumbers[j];
+ var testName = "Queues with selectors: " +consumerNumber + " consumers - 1 producer - non overlapping - " + suffix;
+ var test = {
+ "_name": testName,
+ "_queues":[
+ {
+ "_name": queueName,
+ "_durable": durable,
+ "_attributes":
+ {
+ "x-qpid-capacity": 10485760,
+ "x-qpid-flow-resume-capacity": 8388608
+ }
+ }
+ ],
+ "_clients":[
+ {
+ "_name": "producingClient",
+ "_messageProviders": [
+ {
+ "_name": "messageProvider",
+ "_messageProperties": {
+ "id": {
+ "@def": "range",
+ "_lower": 1,
+ "_upper": consumerNumber,
+ "_type": "int"
+ }
+ }
+ }
+ ],
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": 1,
+ "_producers": [
+ {
+ "_name": "Producer1",
+ "_destinationName": queueName,
+ "_maximumDuration": 60000,
+ "_deliveryMode": deliveryMode,
+ "_messageSize": 1024,
+ "_messageProviderName": "messageProvider"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "_name": "consumingClient",
+ "_connections":[]
+ }
+ ]
+ };
+ for(var n=0; n<consumerNumber; n++)
+ {
+ var consumerConnection = {
+ "_name": "connection" + n,
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session" + n,
+ "_acknowledgeMode": consumerAcknowledgeMode,
+ "_consumers": [
+ {
+ "_name": "Consumer" + n,
+ "_destinationName": queueName,
+ "_maximumDuration": 60000,
+ "_selector": "id=" + ( n + 1)
+ }
+ ]
+ }
+ ]
+ };
+ test._clients[1]._connections.push(consumerConnection);
+ }
+ jsonObject._tests.push(test);
+ }
+}
+
diff --git a/java/perftests/etc/testdefs/QueueConsumersWithOverlappingSelectors.js b/java/perftests/etc/testdefs/QueueConsumersWithOverlappingSelectors.js
new file mode 100644
index 0000000000..20cfb4ad45
--- /dev/null
+++ b/java/perftests/etc/testdefs/QueueConsumersWithOverlappingSelectors.js
@@ -0,0 +1,131 @@
+/*
+ *
+ * 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.
+ *
+ */
+var jsonObject = {
+ _tests:[]
+};
+
+for (var i=0; i<2; i++)
+{
+ var deliveryMode = i+1;
+ var durable = (deliveryMode == 2);
+ var suffix = durable ? "PERSISTENT" : "NON-PERSISTENT";
+ var queueName = "direct://amq.direct//queue-selectors-overlapping-" + suffix + "?durable='" + durable + "'";
+ var consumerNumbers = [2, 4, 8, 16, 32];
+ var consumerAcknowledgeMode = 1;
+ for (var j=0; j<consumerNumbers.length; j++)
+ {
+ var consumerNumber = consumerNumbers[j];
+ var testName = "Queues with selectors: " +consumerNumber + " consumers - 1 producer - 50% overlapping - " + suffix;
+ var test = {
+ "_name": testName,
+ "_queues":[
+ {
+ "_name": queueName,
+ "_durable": durable,
+ "_attributes":
+ {
+ "x-qpid-capacity": 10485760,
+ "x-qpid-flow-resume-capacity": 8388608
+ }
+ }
+ ],
+ "_clients":[
+ {
+ "_name": "producingClient",
+ "_messageProviders": [
+ {
+ "_name": "messageProvider",
+ "_messageProperties": {
+ "id": {
+ "@def": "range",
+ "_lower": 1,
+ "_upper": consumerNumber * 2,
+ "_type": "int"
+ }
+ }
+ }
+ ],
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": 1,
+ "_producers": [
+ {
+ "_name": "Producer1",
+ "_destinationName": queueName,
+ "_maximumDuration": 60000,
+ "_deliveryMode": deliveryMode,
+ "_messageSize": 1024,
+ "_messageProviderName": "messageProvider"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "_name": "consumingClient",
+ "_connections":[]
+ }
+ ]
+ };
+
+ var selectorBase = "";
+ var maxId = consumerNumber * 2;
+ // odd IDs overlaps in each selector expression
+ for (var m = 1; m <= maxId; m+=2)
+ {
+ selectorBase += " or id=" + m;
+ }
+ for(var n = 0, id = 0 ; n< consumerNumber; n++)
+ {
+ // even IDs are unique per each selector expression
+ id = id + 2;
+ selector = "id=" + id + selectorBase;
+ var consumerConnection = {
+ "_name": "connection" + n,
+ "_factory": "connectionfactory",
+ "_sessions": [
+ {
+ "_sessionName": "session" + n,
+ "_acknowledgeMode": consumerAcknowledgeMode,
+ "_consumers": [
+ {
+ "_name": "Consumer" + n,
+ "_destinationName": queueName,
+ "_maximumDuration": 60000,
+ "_selector": selector
+ }
+ ]
+ }
+ ]
+ };
+ test._clients[1]._connections.push(consumerConnection);
+ }
+ jsonObject._tests.push(test);
+ }
+}
+
diff --git a/java/perftests/etc/testdefs/Topic-AckModes.js b/java/perftests/etc/testdefs/Topic-AckModes.js
index 63c4b8646e..3f7eb5d3a7 100644
--- a/java/perftests/etc/testdefs/Topic-AckModes.js
+++ b/java/perftests/etc/testdefs/Topic-AckModes.js
@@ -27,13 +27,10 @@ var jsonObject = {
"_name": "Topic ack modes",
"_iterations": [
{
- "_acknowledgeMode": 1
- },
- {
- "_acknowledgeMode": 2
+ "_acknowledgeMode": 0
},
{
- "_acknowledgeMode": 3
+ "_acknowledgeMode": 1
}
],
"_clients": [
@@ -50,6 +47,7 @@ var jsonObject = {
{
"_name": "Producer",
"_destinationName": topicName,
+ "_isTopic": true,
"_deliveryMode": 1,
"_maximumDuration": duration,
"_startDelay": 2000 // gives the consumers time to implicitly create the topic
@@ -75,6 +73,7 @@ var jsonObject = {
{
"_name": "Consumer-__INDEX",
"_destinationName": topicName,
+ "_isTopic": true,
"_maximumDuration": duration,
}
]
diff --git a/java/perftests/etc/testdefs/Topic-NumberOfConsumers.js b/java/perftests/etc/testdefs/Topic-NumberOfConsumers.js
index 58ae2f5862..1d38ff08e5 100644
--- a/java/perftests/etc/testdefs/Topic-NumberOfConsumers.js
+++ b/java/perftests/etc/testdefs/Topic-NumberOfConsumers.js
@@ -42,10 +42,12 @@ for(i=0; i < numbersOfConsumers.length ; i++)
"_sessions": [
{
"_sessionName": "session1",
+ "_acknowledgeMode": 0,
"_producers": [
{
"_name": "Producer1",
"_destinationName": topicName,
+ "_isTopic": true,
"_deliveryMode": 1,
"_maximumDuration": duration,
"_startDelay": 2000 // gives the consumers time to implicitly create the topic
@@ -66,10 +68,12 @@ for(i=0; i < numbersOfConsumers.length ; i++)
"_sessions": [
{
"_sessionName": "session1",
+ "_acknowledgeMode": 0,
"_consumers": [
{
"_name": "Consumer-__INDEX",
"_destinationName": topicName,
+ "_isTopic": true,
"_maximumDuration": duration
}
]
diff --git a/java/perftests/etc/testdefs/Topic-NumberOfTopics.js b/java/perftests/etc/testdefs/Topic-NumberOfTopics.js
index d31dd36c76..811f8e3a07 100644
--- a/java/perftests/etc/testdefs/Topic-NumberOfTopics.js
+++ b/java/perftests/etc/testdefs/Topic-NumberOfTopics.js
@@ -45,10 +45,12 @@ for(i=0; i < numbersOfTopics.length ; i++)
"_sessions": [
{
"_sessionName": "session1",
+ "_acknowledgeMode": 0,
"_producers": [
{
"_name": "Producer-__INDEX",
"_destinationName": topicName,
+ "_isTopic": true,
"_deliveryMode": 1,
"_maximumDuration": duration,
"_startDelay": 2000 // gives the consumers time to implicitly create the topic
@@ -71,10 +73,12 @@ for(i=0; i < numbersOfTopics.length ; i++)
"_sessions": [
{
"_sessionName": "session1",
+ "_acknowledgeMode": 0,
"_consumers": [
{
"_name": "Consumer-__INDEX",
"_destinationName": topicName,
+ "_isTopic": true,
"_maximumDuration": duration
}
]
diff --git a/java/perftests/etc/testdefs/Topic-Persistence.js b/java/perftests/etc/testdefs/Topic-Persistence.js
index bbec7ab8ed..96872b6c55 100644
--- a/java/perftests/etc/testdefs/Topic-Persistence.js
+++ b/java/perftests/etc/testdefs/Topic-Persistence.js
@@ -26,8 +26,9 @@ var jsonObject = {
{
"_name": "Topic persistence",
"_iterations": [
- // note that we use _durableSubscription (the JaveBeans property name)
- // rather than _isDurableSubscription (the field name)
+ // Note that we use _durableSubscription (more like the JavaBeans property name)
+ // rather than _isDurableSubscription (the field name, which we use elsewhere).
+ // This convention is required within the _iterations definition.
{
"_deliveryMode": 1,
"_durableSubscription": false
@@ -47,10 +48,12 @@ var jsonObject = {
"_sessions": [
{
"_sessionName": "session1",
+ "_acknowledgeMode": 0,
"_producers": [
{
"_name": "Producer",
"_destinationName": topicName,
+ "_isTopic": true,
"_maximumDuration": duration,
"_startDelay": 2000 // gives the consumers time to implicitly create the topic
}
@@ -71,6 +74,7 @@ var jsonObject = {
"_sessions": [
{
"_sessionName": "session1",
+ "_acknowledgeMode": 0,
"_consumers": [
{
"_name": "Consumer-__INDEX",
diff --git a/java/perftests/etc/testdefs/VaryingNumberOfParticipants.json b/java/perftests/etc/testdefs/VaryingNumberOfParticipants.json
index 457b0bc348..03dd2848b6 100644
--- a/java/perftests/etc/testdefs/VaryingNumberOfParticipants.json
+++ b/java/perftests/etc/testdefs/VaryingNumberOfParticipants.json
@@ -8,6 +8,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -18,7 +26,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -42,7 +49,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -65,6 +71,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -75,7 +89,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -99,7 +112,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -116,7 +128,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -139,6 +150,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -149,7 +168,6 @@
"_sessions": [
{
"_sessionName": "session0",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -173,7 +191,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -190,7 +207,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -207,7 +223,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer3",
@@ -224,7 +239,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer4",
@@ -241,7 +255,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer5",
@@ -267,6 +280,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -277,7 +298,6 @@
"_sessions": [
{
"_sessionName": "session0",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -301,7 +321,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -318,7 +337,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -335,7 +353,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer3",
@@ -352,7 +369,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer4",
@@ -369,7 +385,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer5",
@@ -386,7 +401,6 @@
"_sessions": [
{
"_sessionName": "session6",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer6",
@@ -403,7 +417,6 @@
"_sessions": [
{
"_sessionName": "session7",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer7",
@@ -420,7 +433,6 @@
"_sessions": [
{
"_sessionName": "session8",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer8",
@@ -437,7 +449,6 @@
"_sessions": [
{
"_sessionName": "session9",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer9",
@@ -454,7 +465,6 @@
"_sessions": [
{
"_sessionName": "session10",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer10",
@@ -480,6 +490,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -490,7 +508,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -509,7 +526,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -533,7 +549,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -560,6 +575,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -570,7 +593,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -589,7 +611,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -613,7 +634,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -630,7 +650,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -657,6 +676,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -667,7 +694,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -686,7 +712,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -710,7 +735,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -727,7 +751,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -744,7 +767,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer3",
@@ -761,7 +783,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer4",
@@ -778,7 +799,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer5",
@@ -804,6 +824,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -814,7 +842,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -833,7 +860,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -857,7 +883,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -874,7 +899,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -891,7 +915,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer3",
@@ -908,7 +931,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer4",
@@ -925,7 +947,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer5",
@@ -942,7 +963,6 @@
"_sessions": [
{
"_sessionName": "session6",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer6",
@@ -959,7 +979,6 @@
"_sessions": [
{
"_sessionName": "session7",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer7",
@@ -976,7 +995,6 @@
"_sessions": [
{
"_sessionName": "session8",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer8",
@@ -993,7 +1011,6 @@
"_sessions": [
{
"_sessionName": "session9",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer9",
@@ -1010,7 +1027,6 @@
"_sessions": [
{
"_sessionName": "session10",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer10",
@@ -1036,6 +1052,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -1046,7 +1070,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -1065,7 +1088,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -1084,7 +1106,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer3",
@@ -1103,7 +1124,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer4",
@@ -1122,7 +1142,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer5",
@@ -1146,7 +1165,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -1173,6 +1191,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -1183,7 +1209,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -1202,7 +1227,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -1221,7 +1245,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer3",
@@ -1240,7 +1263,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer4",
@@ -1259,7 +1281,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer5",
@@ -1283,7 +1304,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -1300,7 +1320,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -1328,6 +1347,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -1338,7 +1365,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -1357,7 +1383,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -1376,7 +1401,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer3",
@@ -1395,7 +1419,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer4",
@@ -1414,7 +1437,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer5",
@@ -1438,7 +1460,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -1455,7 +1476,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -1472,7 +1492,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer3",
@@ -1489,7 +1508,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer4",
@@ -1506,7 +1524,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer5",
@@ -1532,6 +1549,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -1542,7 +1567,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -1561,7 +1585,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -1580,7 +1603,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer3",
@@ -1599,7 +1621,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer4",
@@ -1618,7 +1639,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer5",
@@ -1642,7 +1662,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -1659,7 +1678,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -1676,7 +1694,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer3",
@@ -1693,7 +1710,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer4",
@@ -1710,7 +1726,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer5",
@@ -1727,7 +1742,6 @@
"_sessions": [
{
"_sessionName": "session6",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer6",
@@ -1744,7 +1758,6 @@
"_sessions": [
{
"_sessionName": "session7",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer7",
@@ -1761,7 +1774,6 @@
"_sessions": [
{
"_sessionName": "session8",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer8",
@@ -1778,7 +1790,6 @@
"_sessions": [
{
"_sessionName": "session9",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer9",
@@ -1795,7 +1806,6 @@
"_sessions": [
{
"_sessionName": "session10",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer10",
@@ -1822,6 +1832,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -1832,7 +1850,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -1851,7 +1868,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -1870,7 +1886,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer3",
@@ -1889,7 +1904,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer4",
@@ -1908,7 +1922,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer5",
@@ -1927,7 +1940,6 @@
"_sessions": [
{
"_sessionName": "session6",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer6",
@@ -1946,7 +1958,6 @@
"_sessions": [
{
"_sessionName": "session7",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer7",
@@ -1965,7 +1976,6 @@
"_sessions": [
{
"_sessionName": "session8",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer8",
@@ -1984,7 +1994,6 @@
"_sessions": [
{
"_sessionName": "session9",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer9",
@@ -2003,7 +2012,6 @@
"_sessions": [
{
"_sessionName": "session10",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer10",
@@ -2027,7 +2035,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -2054,6 +2061,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -2064,7 +2079,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -2083,7 +2097,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -2102,7 +2115,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer3",
@@ -2121,7 +2133,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer4",
@@ -2140,7 +2151,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer5",
@@ -2159,7 +2169,6 @@
"_sessions": [
{
"_sessionName": "session6",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer6",
@@ -2178,7 +2187,6 @@
"_sessions": [
{
"_sessionName": "session7",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer7",
@@ -2197,7 +2205,6 @@
"_sessions": [
{
"_sessionName": "session8",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer8",
@@ -2216,7 +2223,6 @@
"_sessions": [
{
"_sessionName": "session9",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer9",
@@ -2235,7 +2241,6 @@
"_sessions": [
{
"_sessionName": "session10",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer10",
@@ -2259,7 +2264,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -2276,7 +2280,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -2304,6 +2307,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -2314,7 +2325,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -2333,7 +2343,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -2352,7 +2361,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer3",
@@ -2371,7 +2379,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer4",
@@ -2390,7 +2397,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer5",
@@ -2409,7 +2415,6 @@
"_sessions": [
{
"_sessionName": "session6",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer6",
@@ -2428,7 +2433,6 @@
"_sessions": [
{
"_sessionName": "session7",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer7",
@@ -2447,7 +2451,6 @@
"_sessions": [
{
"_sessionName": "session8",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer8",
@@ -2466,7 +2469,6 @@
"_sessions": [
{
"_sessionName": "session9",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer9",
@@ -2485,7 +2487,6 @@
"_sessions": [
{
"_sessionName": "session10",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer10",
@@ -2509,7 +2510,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -2526,7 +2526,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -2543,7 +2542,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer3",
@@ -2560,7 +2558,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer4",
@@ -2577,7 +2574,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer5",
@@ -2604,6 +2600,14 @@
"_durable": true
}
],
+ "_iterations":[
+ {
+ "_acknowledgeMode": 0
+ },
+ {
+ "_acknowledgeMode": 1
+ }
+ ],
"_clients":[
{
"_name": "producingClient",
@@ -2614,7 +2618,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer1",
@@ -2633,7 +2636,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer2",
@@ -2652,7 +2654,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer3",
@@ -2671,7 +2672,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer4",
@@ -2690,7 +2690,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer5",
@@ -2709,7 +2708,6 @@
"_sessions": [
{
"_sessionName": "session6",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer6",
@@ -2728,7 +2726,6 @@
"_sessions": [
{
"_sessionName": "session7",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer7",
@@ -2747,7 +2744,6 @@
"_sessions": [
{
"_sessionName": "session8",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer8",
@@ -2766,7 +2762,6 @@
"_sessions": [
{
"_sessionName": "session9",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer9",
@@ -2785,7 +2780,6 @@
"_sessions": [
{
"_sessionName": "session10",
- "_acknowledgeMode": 1,
"_producers": [
{
"_name": "Producer10",
@@ -2809,7 +2803,6 @@
"_sessions": [
{
"_sessionName": "session1",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer1",
@@ -2826,7 +2819,6 @@
"_sessions": [
{
"_sessionName": "session2",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer2",
@@ -2843,7 +2835,6 @@
"_sessions": [
{
"_sessionName": "session3",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer3",
@@ -2860,7 +2851,6 @@
"_sessions": [
{
"_sessionName": "session4",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer4",
@@ -2877,7 +2867,6 @@
"_sessions": [
{
"_sessionName": "session5",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer5",
@@ -2894,7 +2883,6 @@
"_sessions": [
{
"_sessionName": "session6",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer6",
@@ -2911,7 +2899,6 @@
"_sessions": [
{
"_sessionName": "session7",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer7",
@@ -2928,7 +2915,6 @@
"_sessions": [
{
"_sessionName": "session8",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer8",
@@ -2945,7 +2931,6 @@
"_sessions": [
{
"_sessionName": "session9",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer9",
@@ -2962,7 +2947,6 @@
"_sessions": [
{
"_sessionName": "session10",
- "_acknowledgeMode": 1,
"_consumers": [
{
"_name": "Consumer10",
diff --git a/java/perftests/etc/testdefs/VaryingNumberOfProducerSessionsSingleConnection.js b/java/perftests/etc/testdefs/VaryingNumberOfProducerSessionsSingleConnection.js
new file mode 100644
index 0000000000..c62a8344b1
--- /dev/null
+++ b/java/perftests/etc/testdefs/VaryingNumberOfProducerSessionsSingleConnection.js
@@ -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.
+ *
+ */
+var jsonObject = {
+ _tests:[]
+};
+
+var duration = 30000;
+var queueName = "direct://amq.direct//varNumOfSessions?durable='true'";
+
+var numbersOfSessions = [1, 2, 5, 10, 20, 40, 80];
+var numberOfConsumingClients = 20;
+
+for(i=0; i < numbersOfSessions.length ; i++)
+{
+ var sessionNumber = numbersOfSessions[i];
+ var test = {
+ "_name": sessionNumber,
+ "_queues":[
+ {
+ "_name": queueName,
+ "_durable": "true"
+ }
+ ],
+ "_clients":[
+ {
+ "_name": "producingClient",
+ "_connections":[
+ {
+ "_name": "connection1",
+ "_factory": "connectionfactory",
+ "_sessions": QPID.times(sessionNumber,
+ {
+ "_sessionName": "session__SESSION_INDEX",
+ "_producers": [
+ {
+ "_name": "Producer__SESSION_INDEX",
+ "_destinationName": queueName,
+ "_deliveryMode": 2,
+ "_acknowledgeMode": 0,
+ "_maximumDuration": duration
+ }
+ ]
+ },
+ "__SESSION_INDEX")
+ }
+ ]
+ },
+ ].concat(QPID.times(numberOfConsumingClients,
+ {
+ "_name": "consumingClient__CONSUMING_CLIENT_INDEX",
+ "_connections":[
+ {
+ "_name": "client__CONSUMING_CLIENT_INDEXconnection1",
+ "_factory": "connectionfactory",
+ "_sessions":
+ [
+ {
+ "_sessionName": "client__CONSUMING_CLIENT_INDEXsession1",
+ "_consumers": [
+ {
+ "_name": "client__CONSUMING_CLIENT_INDEXConsumer1Session1",
+ "_destinationName": queueName,
+ "_acknowledgeMode": 1,
+ "_maximumDuration": duration
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "__CONSUMING_CLIENT_INDEX"))
+ };
+
+ jsonObject._tests= jsonObject._tests.concat(test);
+}
+
diff --git a/java/perftests/etc/visualisation-timeseries.sh b/java/perftests/etc/visualisation-timeseries.sh
new file mode 100755
index 0000000000..32db2cb010
--- /dev/null
+++ b/java/perftests/etc/visualisation-timeseries.sh
@@ -0,0 +1,33 @@
+#!/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.
+#
+
+# Runs the visualisation tool against perftest output assumed to be in a Derby database in the current directory
+
+BASE_DIR=`dirname $0`
+
+# Uncomment to read perftest data from a Derby database
+JDBC_URL=jdbcUrl=jdbc:derby:perftestResultsDb
+JDBC_DRIVER=jdbcDriverClass=org.apache.derby.jdbc.EmbeddedDriver
+
+java -cp "${BASE_DIR}:${BASE_DIR}/../../build/lib/*" \
+ -Djava.awt.headless=true -Dlog4j.configuration=file:log4j.properties \
+ org.apache.qpid.disttest.charting.ChartingUtil \
+ chart-defs=chartdefs/timeseries \
+ ${JDBC_DRIVER} ${JDBC_URL}
diff --git a/java/perftests/etc/visualisation.sh b/java/perftests/etc/visualisation.sh
new file mode 100755
index 0000000000..53a3f94f9c
--- /dev/null
+++ b/java/perftests/etc/visualisation.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.
+#
+
+# Runs the visualisation tool against perftest CSV output assumed to be in the current directory
+
+BASE_DIR=`dirname $0`
+
+# Uncomment to read perftest data from a Derby database
+# JDBC_URL=jdbcUrl=jdbc:derby:perftestResultsDb
+# JDBC_DRIVER=jdbcDriverClass=org.apache.derby.jdbc.EmbeddedDriver
+
+java -cp "${BASE_DIR}:${BASE_DIR}/../../build/lib/*" \
+ -Djava.awt.headless=true -Dlog4j.configuration=file:log4j.properties \
+ -DcsvCurrentDir=. \
+ -DcsvBaselineDir=. \
+ org.apache.qpid.disttest.charting.ChartingUtil \
+ chart-defs=chartdefs \
+ ${JDBC_DRIVER} ${JDBC_URL}
diff --git a/java/perftests/example/brokerconfig/log4j.xml b/java/perftests/example/brokerconfig/log4j.xml
index 7dbb1bc87d..7e53d2667b 100644
--- a/java/perftests/example/brokerconfig/log4j.xml
+++ b/java/perftests/example/brokerconfig/log4j.xml
@@ -68,7 +68,7 @@
<param name="backupFilesToPath" value="${QPID_WORK}/backup/log"/>
<layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d %-5p [%t] (%F:%L) - %m%n"/>
+ <param name="ConversionPattern" value="%d %-5p [%t] (%c{2}) - %m%n"/>
</layout>
</appender>
diff --git a/java/perftests/example/perftests-jndi.properties b/java/perftests/example/perftests-jndi.properties
index 04a8ad9101..1c0fd57663 100644
--- a/java/perftests/example/perftests-jndi.properties
+++ b/java/perftests/example/perftests-jndi.properties
@@ -24,3 +24,6 @@ java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextF
connectionfactory.connectionfactory = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'
destination.controllerqueue = direct://amq.direct//controllerqueue?autodelete='true'
+
+driverName=org.apache.derby.jdbc.EmbeddedDriver
+jdbcUrl=jdbc:derby:/tmp/perftestResultsDb;create=true
diff --git a/java/perftests/example/run.sh b/java/perftests/example/run.sh
index cb68c52853..31124a060a 100755
--- a/java/perftests/example/run.sh
+++ b/java/perftests/example/run.sh
@@ -18,5 +18,5 @@
# under the License.
#
-java -cp ".:${QPID_HOME}/lib/*" -Dqpid.dest_syntax=BURL org.apache.qpid.disttest.ControllerRunner jndi-config=perftests-jndi.properties test-config=$1 distributed=false
+java -cp ".:${QPID_HOME}/lib/*" -Dqpid.dest_syntax=BURL org.apache.qpid.disttest.ControllerRunner jndi-config=perftests-jndi.properties test-config=$1 distributed=false writeToDb=true
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java b/java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java
index 8c1f8675e3..e962bfe799 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/ArgumentParser.java
@@ -34,10 +34,14 @@ public class ArgumentParser
throw new IllegalArgumentException("arguments must have format <name>=<value>: " + arg);
}
- if(initialValues.put(splitArg[0], splitArg[1]) == null)
+
+ String argumentKey = splitArg[0];
+ String argumentValue = splitArg[1];
+ if(!initialValues.containsKey(argumentKey))
{
throw new IllegalArgumentException("not a valid configuration property: " + arg);
}
+ initialValues.put(argumentKey, argumentValue);
}
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/ConfigFileHelper.java b/java/perftests/src/main/java/org/apache/qpid/disttest/ConfigFileHelper.java
index fb4c1b700b..ee374e180d 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/ConfigFileHelper.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/ConfigFileHelper.java
@@ -60,15 +60,4 @@ public class ConfigFileHelper
return testConfigFile;
}
-
- /**
- * generateOutputCsvNameFrom("/config/testConfigFile.js", "/output") returns /output/testConfigFile.csv
- */
- public String generateOutputCsvNameFrom(String testConfigFile, String outputDir)
- {
- final String filenameOnlyWithExtension = new File(testConfigFile).getName();
- final String cvsFile = filenameOnlyWithExtension.replaceFirst(".?\\w*$", ".csv");
-
- return new File(outputDir, cvsFile).getAbsolutePath();
- }
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/ControllerRunner.java b/java/perftests/src/main/java/org/apache/qpid/disttest/ControllerRunner.java
index aea0ea301a..449130a328 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/ControllerRunner.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/ControllerRunner.java
@@ -19,9 +19,9 @@
*/
package org.apache.qpid.disttest;
+import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
import javax.naming.Context;
@@ -30,9 +30,9 @@ import org.apache.qpid.disttest.controller.Controller;
import org.apache.qpid.disttest.controller.ResultsForAllTests;
import org.apache.qpid.disttest.controller.config.Config;
import org.apache.qpid.disttest.controller.config.ConfigReader;
+import org.apache.qpid.disttest.db.ResultsDbWriter;
import org.apache.qpid.disttest.jms.ControllerJmsDelegate;
import org.apache.qpid.disttest.results.aggregation.Aggregator;
-import org.apache.qpid.disttest.results.formatting.CSVFormater;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,20 +43,29 @@ public class ControllerRunner extends AbstractRunner
public static final String TEST_CONFIG_PROP = "test-config";
public static final String DISTRIBUTED_PROP = "distributed";
public static final String OUTPUT_DIR_PROP = "outputdir";
+ public static final String WRITE_TO_DB = "writeToDb";
+ public static final String RUN_ID = "runId";
private static final String TEST_CONFIG_DEFAULT = "perftests-config.json";
private static final String DISTRIBUTED_DEFAULT = "false";
private static final String OUTPUT_DIR_DEFAULT = ".";
+ public static final String WRITE_TO_DB_DEFAULT = "false";
private final Aggregator _aggregator = new Aggregator();
private final ConfigFileHelper _configFileHelper = new ConfigFileHelper();
+ private ResultsFileWriter _resultsFileWriter;
+
+ private ResultsDbWriter _resultsDbWriter;
+
public ControllerRunner()
{
getCliOptions().put(TEST_CONFIG_PROP, TEST_CONFIG_DEFAULT);
getCliOptions().put(DISTRIBUTED_PROP, DISTRIBUTED_DEFAULT);
getCliOptions().put(OUTPUT_DIR_PROP, OUTPUT_DIR_DEFAULT);
+ getCliOptions().put(WRITE_TO_DB, WRITE_TO_DB_DEFAULT);
+ getCliOptions().put(RUN_ID, null);
}
public static void main(String[] args) throws Exception
@@ -69,6 +78,8 @@ public class ControllerRunner extends AbstractRunner
public void runController() throws Exception
{
Context context = getContext();
+ setUpResultFilesWriter();
+ setUpResultsDbWriter();
ControllerJmsDelegate jmsDelegate = new ControllerJmsDelegate(context);
@@ -82,6 +93,24 @@ public class ControllerRunner extends AbstractRunner
}
}
+ private void setUpResultsDbWriter()
+ {
+ String writeToDbStr = getCliOptions().get(WRITE_TO_DB);
+ if(Boolean.valueOf(writeToDbStr))
+ {
+ String runId = getCliOptions().get(RUN_ID);
+ _resultsDbWriter = new ResultsDbWriter(getContext(), runId);
+ _resultsDbWriter.createResultsTableIfNecessary();
+ }
+ }
+
+ void setUpResultFilesWriter()
+ {
+ String outputDirString = getCliOptions().get(ControllerRunner.OUTPUT_DIR_PROP);
+ File outputDir = new File(outputDirString);
+ _resultsFileWriter = new ResultsFileWriter(outputDir);
+ }
+
private void runTests(ControllerJmsDelegate jmsDelegate)
{
Controller controller = new Controller(jmsDelegate, DistributedTestConstants.REGISTRATION_TIMEOUT, DistributedTestConstants.COMMAND_RESPONSE_TIMEOUT);
@@ -92,6 +121,8 @@ public class ControllerRunner extends AbstractRunner
try
{
+ List<ResultsForAllTests> results = new ArrayList<ResultsForAllTests>();
+
for (String testConfigFile : testConfigFiles)
{
final Config testConfig = buildTestConfigFrom(testConfigFile);
@@ -100,8 +131,11 @@ public class ControllerRunner extends AbstractRunner
controller.awaitClientRegistrations();
LOGGER.info("Running test : " + testConfigFile);
- runTest(controller, testConfigFile);
+ ResultsForAllTests testResult = runTest(controller, testConfigFile);
+ results.add(testResult);
}
+
+ _resultsFileWriter.writeResultsSummary(results);
}
catch(Exception e)
{
@@ -113,7 +147,7 @@ public class ControllerRunner extends AbstractRunner
}
}
- private void runTest(Controller controller, String testConfigFile)
+ private ResultsForAllTests runTest(Controller controller, String testConfigFile)
{
final Config testConfig = buildTestConfigFrom(testConfigFile);
controller.setConfig(testConfig);
@@ -121,9 +155,13 @@ public class ControllerRunner extends AbstractRunner
ResultsForAllTests rawResultsForAllTests = controller.runAllTests();
ResultsForAllTests resultsForAllTests = _aggregator.aggregateResults(rawResultsForAllTests);
- String outputDir = getCliOptions().get(ControllerRunner.OUTPUT_DIR_PROP);
- final String outputFile = _configFileHelper.generateOutputCsvNameFrom(testConfigFile, outputDir);
- writeResultsToFile(resultsForAllTests, outputFile);
+ _resultsFileWriter.writeResultsToFile(resultsForAllTests, testConfigFile);
+ if(_resultsDbWriter != null)
+ {
+ _resultsDbWriter.writeResults(resultsForAllTests);
+ }
+
+ return resultsForAllTests;
}
private void createClientsIfNotDistributed(final List<String> testConfigFiles)
@@ -148,36 +186,6 @@ public class ControllerRunner extends AbstractRunner
}
}
- private void writeResultsToFile(ResultsForAllTests resultsForAllTests, String outputFile)
- {
- FileWriter writer = null;
- try
- {
- final String outputCsv = new CSVFormater().format(resultsForAllTests);
- writer = new FileWriter(outputFile);
- writer.write(outputCsv);
- LOGGER.info("Wrote " + resultsForAllTests.getTestResults().size() + " test result(s) to output file " + outputFile);
- }
- catch (IOException e)
- {
- throw new DistributedTestException("Unable to write output file " + outputFile, e);
- }
- finally
- {
- if (writer != null)
- {
- try
- {
- writer.close();
- }
- catch (IOException e)
- {
- LOGGER.error("Failed to close stream for file " + outputFile, e);
- }
- }
- }
- }
-
private Config buildTestConfigFrom(String testConfigFile)
{
ConfigReader configReader = new ConfigReader();
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/ResultsFileWriter.java b/java/perftests/src/main/java/org/apache/qpid/disttest/ResultsFileWriter.java
new file mode 100644
index 0000000000..81b717403d
--- /dev/null
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/ResultsFileWriter.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.disttest;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
+import org.apache.qpid.disttest.results.aggregation.TestResultAggregator;
+import org.apache.qpid.disttest.results.formatting.CSVFormatter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ResultsFileWriter
+{
+ private static final Logger LOGGER = LoggerFactory.getLogger(ResultsFileWriter.class);
+
+ static final String TEST_SUMMARY_FILE_NAME = "test-summary.csv";
+
+ private final File _outputDir;
+
+ private CSVFormatter _csvFormater = new CSVFormatter();
+
+ private TestResultAggregator _testResultAggregator = new TestResultAggregator();
+
+ public ResultsFileWriter(File outputDir)
+ {
+ _outputDir = outputDir;
+ }
+
+ public void writeResultsToFile(ResultsForAllTests resultsForAllTests, String testConfigFile)
+ {
+ final String outputFile = generateOutputCsvNameFrom(testConfigFile);
+ writeResultsToOutputFile(resultsForAllTests, outputFile);
+ }
+
+ public void writeResultsSummary(List<ResultsForAllTests> allResultsList)
+ {
+ ResultsForAllTests combinedResults = _testResultAggregator.aggregateTestResults(allResultsList);
+ writeResultsToOutputFile(combinedResults, new File(_outputDir, TEST_SUMMARY_FILE_NAME).getAbsolutePath());
+ }
+
+ /**
+ * generateOutputCsvNameFrom("/config/testConfigFile.js", "/output") returns /output/testConfigFile.csv
+ */
+ private String generateOutputCsvNameFrom(String testConfigFile)
+ {
+ final String filenameOnlyWithExtension = new File(testConfigFile).getName();
+ final String cvsFile = filenameOnlyWithExtension.replaceFirst(".?\\w*$", ".csv");
+
+ return new File(_outputDir, cvsFile).getAbsolutePath();
+ }
+
+ private void writeResultsToOutputFile(ResultsForAllTests resultsForAllTests, String outputFile)
+ {
+ FileWriter writer = null;
+ try
+ {
+ final String outputCsv = _csvFormater.format(resultsForAllTests);
+ writer = new FileWriter(outputFile);
+ writer.write(outputCsv);
+ LOGGER.info("Wrote " + resultsForAllTests.getTestResults().size() + " test result(s) to output file " + outputFile);
+ }
+ catch (IOException e)
+ {
+ throw new DistributedTestException("Unable to write output file " + outputFile, e);
+ }
+ finally
+ {
+ if (writer != null)
+ {
+ try
+ {
+ writer.close();
+ }
+ catch (IOException e)
+ {
+ LOGGER.error("Failed to close stream for file " + outputFile, e);
+ }
+ }
+ }
+ }
+
+ void setCsvFormater(CSVFormatter csvFormater)
+ {
+ _csvFormater = csvFormater;
+ }
+
+ void setTestResultAggregator(TestResultAggregator testResultAggregator)
+ {
+ _testResultAggregator = testResultAggregator;
+ }
+
+}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/client/ConsumerParticipant.java b/java/perftests/src/main/java/org/apache/qpid/disttest/client/ConsumerParticipant.java
index f9d50e8e64..d3a5e30191 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/client/ConsumerParticipant.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/client/ConsumerParticipant.java
@@ -35,7 +35,6 @@ import javax.jms.MessageListener;
import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.jms.ClientJmsDelegate;
-import org.apache.qpid.disttest.message.ConsumerParticipantResult;
import org.apache.qpid.disttest.message.CreateConsumerCommand;
import org.apache.qpid.disttest.message.ParticipantResult;
import org.slf4j.Logger;
@@ -103,16 +102,22 @@ public class ConsumerParticipant implements Participant
}
Date end = new Date();
- int numberOfMessagesSent = _totalNumberOfMessagesReceived.get();
+ int numberOfMessagesReceived = _totalNumberOfMessagesReceived.get();
long totalPayloadSize = _totalPayloadSizeOfAllMessagesReceived.get();
int payloadSize = getPayloadSizeForResultIfConstantOrZeroOtherwise(_allConsumedPayloadSizes);
- ConsumerParticipantResult result = _resultFactory.createForConsumer(
+ if (LOGGER.isInfoEnabled())
+ {
+ LOGGER.info("Consumer {} finished consuming. Number of messages consumed: {}",
+ getName(), numberOfMessagesReceived);
+ }
+
+ ParticipantResult result = _resultFactory.createForConsumer(
getName(),
registeredClientName,
_command,
acknowledgeMode,
- numberOfMessagesSent,
+ numberOfMessagesReceived,
payloadSize,
totalPayloadSize,
start, end, _messageLatencies);
@@ -174,7 +179,7 @@ public class ConsumerParticipant implements Participant
{
LOGGER.trace("Committing: batch size " + _command.getBatchSize() );
}
- _jmsDelegate.commitOrAcknowledgeMessage(message, _command.getSessionName());
+ _jmsDelegate.commitOrAcknowledgeMessageIfNecessary(_command.getSessionName(), message);
}
}
@@ -199,7 +204,7 @@ public class ConsumerParticipant implements Participant
}
// commit/acknowledge remaining messages if necessary
- _jmsDelegate.commitOrAcknowledgeMessage(message, _command.getSessionName());
+ _jmsDelegate.commitOrAcknowledgeMessageIfNecessary(_command.getSessionName(), message);
}
return false;
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java b/java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java
index bb9ce26f7e..10f62708a4 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java
@@ -108,8 +108,16 @@ public class ParticipantExecutor
}
finally
{
+ try
+ {
+ _participant.releaseResources();
+ }
+ catch(Exception e)
+ {
+ LOGGER.error("Participant " + _participant + " unable to release resources", e);
+ }
+
_client.sendResults(result);
- _participant.releaseResources();
}
}
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java b/java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java
index 63cbe98b5c..a9da837dea 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/client/ProducerParticipant.java
@@ -58,17 +58,25 @@ public class ProducerParticipant implements Participant
@Override
public ParticipantResult doIt(String registeredClientName) throws Exception
{
- if (_command.getMaximumDuration() == 0 && _command.getNumberOfMessages() == 0)
+ long numberOfMessages = _command.getNumberOfMessages();
+ long maximumDuration = _command.getMaximumDuration();
+
+ if (maximumDuration == 0 && numberOfMessages == 0)
{
throw new DistributedTestException("number of messages and duration cannot both be zero");
}
- int acknowledgeMode = _jmsDelegate.getAcknowledgeMode(_command.getSessionName());
+ long duration = maximumDuration - _command.getStartDelay();
+ if (maximumDuration > 0 && duration <= 0)
+ {
+ throw new DistributedTestException("Start delay must be less than maximum test duration");
+ }
+ final long requiredDuration = duration > 0 ? duration : 0;
doSleepForStartDelay();
- final long requiredDuration = _command.getMaximumDuration() - _command.getStartDelay();
-
+ final int batchSize = _command.getBatchSize();
+ final int acknowledgeMode = _jmsDelegate.getAcknowledgeMode(_command.getSessionName());
final long startTime = System.currentTimeMillis();
Message lastPublishedMessage = null;
@@ -78,10 +86,20 @@ public class ProducerParticipant implements Participant
_limiter = ExecutorWithLimitsFactory.createExecutorWithLimit(startTime, requiredDuration);
- LOGGER.info("Producer {} about to send messages", getName());
+ if (LOGGER.isInfoEnabled())
+ {
+ LOGGER.info("Producer {} about to send messages. Duration limit: {} ms, Message limit: {}",
+ new Object[]{getName(), requiredDuration, numberOfMessages});
+ }
while (true)
{
+ if (numberOfMessages > 0 && numberOfMessagesSent >= numberOfMessages
+ || requiredDuration > 0 && System.currentTimeMillis() - startTime >= requiredDuration)
+ {
+ break;
+ }
+
try
{
lastPublishedMessage = _limiter.execute(new Callable<Message>()
@@ -110,35 +128,35 @@ public class ProducerParticipant implements Participant
LOGGER.trace("message " + numberOfMessagesSent + " sent by " + this);
}
- final boolean batchLimitReached = _command.getBatchSize() <= 0
- || numberOfMessagesSent % _command.getBatchSize() == 0;
+ final boolean batchLimitReached = batchSize <= 0
+ || numberOfMessagesSent % batchSize == 0;
if (batchLimitReached)
{
- if (LOGGER.isTraceEnabled() && _command.getBatchSize() > 0)
+ if (LOGGER.isTraceEnabled() && batchSize > 0)
{
- LOGGER.trace("Committing: batch size " + _command.getBatchSize() );
+ LOGGER.trace("Committing: batch size " + batchSize );
}
- _jmsDelegate.commitOrAcknowledgeMessage(lastPublishedMessage, _command.getSessionName());
+ _jmsDelegate.commitIfNecessary(_command.getSessionName());
doSleepForInterval();
}
-
- if (_command.getNumberOfMessages() > 0 && numberOfMessagesSent >= _command.getNumberOfMessages()
- || requiredDuration > 0 && System.currentTimeMillis() - startTime >= requiredDuration)
- {
- break;
- }
}
// commit the remaining batch messages
- if (_command.getBatchSize() > 0 && numberOfMessagesSent % _command.getBatchSize() != 0)
+ if (batchSize > 0 && numberOfMessagesSent % batchSize != 0)
{
if (LOGGER.isTraceEnabled())
{
- LOGGER.trace("Committing: batch size " + _command.getBatchSize() );
+ LOGGER.trace("Committing: batch size " + batchSize );
}
- _jmsDelegate.commitOrAcknowledgeMessage(lastPublishedMessage, _command.getSessionName());
+ _jmsDelegate.commitIfNecessary(_command.getSessionName());
+ }
+
+ if (LOGGER.isInfoEnabled())
+ {
+ LOGGER.info("Producer {} finished publishing. Number of messages published: {}",
+ getName(), numberOfMessagesSent);
}
Date start = new Date(startTime);
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java
index eaccb54f0e..5a726c50b4 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ClientRegistry.java
@@ -57,34 +57,54 @@ public class ClientRegistry
return Collections.unmodifiableSet(_registeredClientNames);
}
- public int awaitClients(int numberOfClientsToAwait, long timeout)
+ /**
+ * @return the number of clients that are still absent.
+ */
+ public int awaitClients(final int numberOfClientsToAwait, final long idleTimeout)
{
- final long endTime = System.currentTimeMillis() + timeout;
+ long deadlineForNextRegistration = deadline(idleTimeout);
- int numberOfClientsAbsent = numberOfClientsToAwait - _registeredClientNames.size();
- long remainingTimeout = endTime - System.currentTimeMillis();
+ int numberOfClientsAbsent = numberAbsent(numberOfClientsToAwait);
- while(numberOfClientsAbsent > 0 && remainingTimeout > 0)
+ while(numberOfClientsAbsent > 0 && System.currentTimeMillis() < deadlineForNextRegistration)
{
synchronized (_lock)
{
try
{
- _lock.wait(remainingTimeout);
+ _lock.wait(idleTimeout);
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();
+ return numberOfClientsAbsent;
}
}
- numberOfClientsAbsent = numberOfClientsToAwait - _registeredClientNames.size();
- remainingTimeout = endTime - System.currentTimeMillis();
+ int newNumberAbsent = numberAbsent(numberOfClientsToAwait);
+ if(newNumberAbsent < numberOfClientsAbsent)
+ {
+ // a registration was received since the last loop, so reset the timeout
+ deadlineForNextRegistration = deadline(idleTimeout);
+ }
+
+ numberOfClientsAbsent = newNumberAbsent;
}
return numberOfClientsAbsent < 0 ? 0 : numberOfClientsAbsent;
}
+
+ private long deadline(final long idleTimeout)
+ {
+ return System.currentTimeMillis() + idleTimeout;
+ }
+
+ private int numberAbsent(int numberOfClientsToAwait)
+ {
+ return numberOfClientsToAwait - _registeredClientNames.size();
+ }
+
private void notifyAllWaiters()
{
synchronized (_lock)
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ResultsForAllTests.java b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ResultsForAllTests.java
index 6c5ff3450c..d4474e2c12 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ResultsForAllTests.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/ResultsForAllTests.java
@@ -21,7 +21,9 @@ package org.apache.qpid.disttest.controller;
import java.util.ArrayList;
import java.util.List;
+import org.apache.qpid.disttest.message.ParticipantResult;
import org.apache.qpid.disttest.results.aggregation.ITestResult;
+import org.apache.qpid.disttest.results.aggregation.TestResultAggregator;
public class ResultsForAllTests
{
@@ -46,4 +48,23 @@ public class ResultsForAllTests
{
return _hasErrors;
}
+
+ public ResultsForAllTests getAllParticipantsResult()
+ {
+ ResultsForAllTests summaryResultsForAllTests = new ResultsForAllTests();
+
+ for (ITestResult testResult : _results)
+ {
+ for(ParticipantResult participantResult : testResult.getParticipantResults())
+ {
+ if(TestResultAggregator.ALL_CONSUMER_PARTICIPANTS_NAME.equals(participantResult.getParticipantName()))
+ {
+ TestResult summaryTestResult = new TestResult(testResult.getName());
+ summaryTestResult.addParticipantResult(participantResult);
+ summaryResultsForAllTests.add(summaryTestResult);
+ }
+ }
+ }
+ return summaryResultsForAllTests;
+ }
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ConsumerConfig.java b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ConsumerConfig.java
index 110de8a4ea..dcccccdd5f 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ConsumerConfig.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ConsumerConfig.java
@@ -24,7 +24,6 @@ import org.apache.qpid.disttest.message.CreateConsumerCommand;
public class ConsumerConfig extends ParticipantConfig
{
- private boolean _isTopic;
private boolean _isDurableSubscription;
private boolean _isBrowsingSubscription;
private String _selector;
@@ -35,7 +34,6 @@ public class ConsumerConfig extends ParticipantConfig
// For Gson
public ConsumerConfig()
{
- _isTopic = false;
_isDurableSubscription = false;
_isBrowsingSubscription = false;
_selector = null;
@@ -56,9 +54,8 @@ public class ConsumerConfig extends ParticipantConfig
boolean noLocal,
boolean synchronous)
{
- super(consumerName, destinationName, numberOfMessages, batchSize, maximumDuration);
+ super(consumerName, destinationName, isTopic, numberOfMessages, batchSize, maximumDuration);
- _isTopic = isTopic;
_isDurableSubscription = isDurableSubscription;
_isBrowsingSubscription = isBrowsingSubscription;
_selector = selector;
@@ -73,7 +70,6 @@ public class ConsumerConfig extends ParticipantConfig
setParticipantProperties(createConsumerCommand);
createConsumerCommand.setSessionName(sessionName);
- createConsumerCommand.setTopic(_isTopic);
createConsumerCommand.setDurableSubscription(_isDurableSubscription);
createConsumerCommand.setBrowsingSubscription(_isBrowsingSubscription);
createConsumerCommand.setSelector(_selector);
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ParticipantConfig.java b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ParticipantConfig.java
index 16f7b0d18d..99ae4b7426 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ParticipantConfig.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ParticipantConfig.java
@@ -33,6 +33,7 @@ public abstract class ParticipantConfig
private boolean _alreadyLoggedAboutOverriddenDuration;
private String _destinationName;
+ private boolean _isTopic;
private long _numberOfMessages;
private String _name;
private int _batchSize;
@@ -51,12 +52,14 @@ public abstract class ParticipantConfig
public ParticipantConfig(
String name,
String destinationName,
+ boolean isTopic,
long numberOfMessages,
int batchSize,
long maximumDuration)
{
_name = name;
_destinationName = destinationName;
+ _isTopic = isTopic;
_numberOfMessages = numberOfMessages;
_batchSize = batchSize;
_maximumDuration = maximumDuration;
@@ -66,6 +69,7 @@ public abstract class ParticipantConfig
{
createParticipantCommand.setParticipantName(_name);
createParticipantCommand.setDestinationName(_destinationName);
+ createParticipantCommand.setTopic(_isTopic);
createParticipantCommand.setNumberOfMessages(_numberOfMessages);
createParticipantCommand.setBatchSize(_batchSize);
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java
index f2369ed671..88c188d3ac 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/controller/config/ProducerConfig.java
@@ -59,7 +59,7 @@ public class ProducerConfig extends ParticipantConfig
long startDelay,
String messageProviderName)
{
- super(producerName, destinationName, numberOfMessages, batchSize, maximumDuration);
+ super(producerName, destinationName, false, numberOfMessages, batchSize, maximumDuration);
_deliveryMode = deliveryMode;
_messageSize = messageSize;
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/db/ResultsDbWriter.java b/java/perftests/src/main/java/org/apache/qpid/disttest/db/ResultsDbWriter.java
new file mode 100644
index 0000000000..fdea03ae5e
--- /dev/null
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/db/ResultsDbWriter.java
@@ -0,0 +1,467 @@
+/*
+ * 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.disttest.db;
+
+import static org.apache.qpid.disttest.message.ParticipantAttribute.ACKNOWLEDGE_MODE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.AVERAGE_LATENCY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.BATCH_SIZE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.CONFIGURED_CLIENT_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.DELIVERY_MODE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.ERROR_MESSAGE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_BROWSING_SUBSCRIPTION;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_DURABLE_SUBSCRIPTION;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_NO_LOCAL;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SELECTOR;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SYNCHRONOUS_CONSUMER;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_TOPIC;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.LATENCY_STANDARD_DEVIATION;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.MAXIMUM_DURATION;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.MAX_LATENCY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.MIN_LATENCY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PRIORITY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_INTERVAL;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_START_DELAY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TAKEN;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TO_LIVE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_CONSUMERS;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_PRODUCERS;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_PAYLOAD_PROCESSED;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.TimeZone;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.log4j.Logger;
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
+import org.apache.qpid.disttest.message.ParticipantResult;
+import org.apache.qpid.disttest.results.aggregation.ITestResult;
+
+/**
+ * Intended call sequence:
+ * <ul>
+ * <li>{@link #ResultsDbWriter(Context, String)}</li>
+ * <li>{@link #createResultsTableIfNecessary()}</li>
+ * <li>{@link #writeResults(ResultsForAllTests)} (usually multiple times)</li>
+ * </ul>
+ */
+public class ResultsDbWriter
+{
+ private static final Logger _logger = Logger.getLogger(ResultsDbWriter.class);
+
+ private static final String RESULTS_TABLE_NAME = "RESULTS";
+
+ /** column name */
+ static final String INSERTED_TIMESTAMP = "insertedTimestamp";
+ /** column name */
+ static final String RUN_ID = "runId";
+
+ private static final String TABLE_EXISTENCE_QUERY = "SELECT 1 FROM SYS.SYSTABLES WHERE TABLENAME = ?";
+
+ private static final String CREATE_RESULTS_TABLE = String.format(
+ "CREATE TABLE %1$s (" +
+ "%2$s varchar(200) not null" + // TEST_NAME
+ ", %3$s bigint not null" + // ITERATION_NUMBER
+ ", %4$s varchar(200) not null" + // PARTICIPANT_NAME
+ ", %5$s double not null" + // THROUGHPUT
+ ", %6$s double" + // AVERAGE_LATENCY
+ ", %7$s varchar(200)" + // CONFIGURED_CLIENT_NAME
+ ", %8$s bigint" + // NUMBER_OF_MESSAGES_PROCESSED
+ ", %9$s bigint" + // PAYLOAD_SIZE
+ ", %10$s bigint" + // PRIORITY
+ ", %11$s bigint" + // TIME_TO_LIVE
+ ", %12$s bigint" + // ACKNOWLEDGE_MODE
+ ", %13$s bigint" + // DELIVERY_MODE
+ ", %14$s bigint" + // BATCH_SIZE
+ ", %15$s bigint" + // MAXIMUM_DURATION
+ ", %16$s bigint" + // PRODUCER_START_DELAY
+ ", %17$s bigint" + // PRODUCER_INTERVAL
+ ", %18$s bigint" + // IS_TOPIC
+ ", %19$s bigint" + // IS_DURABLE_SUBSCRIPTION
+ ", %20$s bigint" + // IS_BROWSING_SUBSCRIPTION
+ ", %21$s bigint" + // IS_SELECTOR
+ ", %22$s bigint" + // IS_NO_LOCAL
+ ", %23$s bigint" + // IS_SYNCHRONOUS_CONSUMER
+ ", %24$s bigint" + // TOTAL_NUMBER_OF_CONSUMERS
+ ", %25$s bigint" + // TOTAL_NUMBER_OF_PRODUCERS
+ ", %26$s bigint" + // TOTAL_PAYLOAD_PROCESSED
+ ", %27$s bigint" + // TIME_TAKEN
+ ", %28$s varchar(2000)" + // ERROR_MESSAGE
+ ", %29$s bigint" + // MIN_LATENCY
+ ", %30$s bigint" + // MAX_LATENCY
+ ", %31$s double" + // LATENCY_STANDARD_DEVIATION
+ ", %32$s varchar(200) not null" +
+ ", %33$s timestamp not null" +
+ ")",
+ RESULTS_TABLE_NAME,
+ TEST_NAME.getDisplayName(),
+ ITERATION_NUMBER.getDisplayName(),
+ PARTICIPANT_NAME.getDisplayName(),
+ THROUGHPUT.getDisplayName(),
+ AVERAGE_LATENCY.getDisplayName(),
+ CONFIGURED_CLIENT_NAME.getDisplayName(),
+ NUMBER_OF_MESSAGES_PROCESSED.getDisplayName(),
+ PAYLOAD_SIZE.getDisplayName(),
+ PRIORITY.getDisplayName(),
+ TIME_TO_LIVE.getDisplayName(),
+ ACKNOWLEDGE_MODE.getDisplayName(),
+ DELIVERY_MODE.getDisplayName(),
+ BATCH_SIZE.getDisplayName(),
+ MAXIMUM_DURATION.getDisplayName(),
+ PRODUCER_START_DELAY.getDisplayName(),
+ PRODUCER_INTERVAL.getDisplayName(),
+ IS_TOPIC.getDisplayName(),
+ IS_DURABLE_SUBSCRIPTION.getDisplayName(),
+ IS_BROWSING_SUBSCRIPTION.getDisplayName(),
+ IS_SELECTOR.getDisplayName(),
+ IS_NO_LOCAL.getDisplayName(),
+ IS_SYNCHRONOUS_CONSUMER.getDisplayName(),
+ TOTAL_NUMBER_OF_CONSUMERS.getDisplayName(),
+ TOTAL_NUMBER_OF_PRODUCERS.getDisplayName(),
+ TOTAL_PAYLOAD_PROCESSED.getDisplayName(),
+ TIME_TAKEN.getDisplayName(),
+ ERROR_MESSAGE.getDisplayName(),
+ MIN_LATENCY.getDisplayName(),
+ MAX_LATENCY.getDisplayName(),
+ LATENCY_STANDARD_DEVIATION.getDisplayName(),
+ RUN_ID,
+ INSERTED_TIMESTAMP
+ );
+
+ public static final String DRIVER_NAME = "jdbcDriverClass";
+ public static final String URL = "jdbcUrl";
+
+ private final String _url;
+ private final String _runId;
+
+ private final Clock _clock;
+
+ /**
+ * @param runId may be null, in which case a default value is chosen based on current GMT time
+ * @param context must contain environment entries {@value #DRIVER_NAME} and {@value #URL}.
+ */
+ public ResultsDbWriter(Context context, String runId)
+ {
+ this(context, runId, new Clock());
+ }
+
+ /** only call directly from tests */
+ ResultsDbWriter(Context context, String runId, Clock clock)
+ {
+ _clock = clock;
+ _runId = defaultIfNullRunId(runId);
+
+ _url = initialiseJdbc(context);
+ }
+
+ private String defaultIfNullRunId(String runId)
+ {
+ if(runId == null)
+ {
+ Date dateNow = new Date(_clock.currentTimeMillis());
+ Calendar calNow = Calendar.getInstance(TimeZone.getTimeZone("GMT+00:00"));
+ calNow.setTime(dateNow);
+ return String.format("run %1$tF %1$tT.%tL", calNow);
+ }
+ else
+ {
+ return runId;
+ }
+ }
+
+ public String getRunId()
+ {
+ return _runId;
+ }
+
+ /**
+ * Uses the context's environment to load the JDBC driver class and return the
+ * JDBC URL specified therein.
+ * @return the JDBC URL
+ */
+ private String initialiseJdbc(Context context)
+ {
+ Hashtable<?, ?> environment = null;
+ try
+ {
+ environment = context.getEnvironment();
+
+ String driverName = (String) environment.get(DRIVER_NAME);
+ if(driverName == null)
+ {
+ throw new IllegalArgumentException("JDBC driver name " + DRIVER_NAME
+ + " missing from context environment: " + environment);
+ }
+
+ Class.forName(driverName);
+
+ Object url = environment.get(URL);
+ if(url == null)
+ {
+ throw new IllegalArgumentException("JDBC URL " + URL + " missing from context environment: " + environment);
+ }
+ return (String) url;
+ }
+ catch (NamingException e)
+ {
+ throw constructorRethrow(e, environment);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw constructorRethrow(e, environment);
+ }
+ }
+
+ private RuntimeException constructorRethrow(Exception e, Hashtable<?, ?> environment)
+ {
+ return new RuntimeException("Couldn't initialise ResultsDbWriter from context with environment" + environment, e);
+ }
+
+ public void createResultsTableIfNecessary()
+ {
+ try
+ {
+ Connection connection = null;
+ try
+ {
+ connection = DriverManager.getConnection(_url);
+ if(!tableExists(RESULTS_TABLE_NAME, connection))
+ {
+ Statement statement = connection.createStatement();
+ try
+ {
+ _logger.info("About to create results table using SQL: " + CREATE_RESULTS_TABLE);
+ statement.execute(CREATE_RESULTS_TABLE);
+ }
+ finally
+ {
+ statement.close();
+ }
+ }
+ }
+ finally
+ {
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException("Couldn't create results table", e);
+ }
+
+ }
+
+ private boolean tableExists(final String tableName, final Connection conn) throws SQLException
+ {
+ PreparedStatement stmt = conn.prepareStatement(TABLE_EXISTENCE_QUERY);
+ try
+ {
+ stmt.setString(1, tableName);
+ ResultSet rs = stmt.executeQuery();
+ try
+ {
+ return rs.next();
+ }
+ finally
+ {
+ rs.close();
+ }
+ }
+ finally
+ {
+ stmt.close();
+ }
+ }
+
+ public void writeResults(ResultsForAllTests results)
+ {
+ try
+ {
+ writeResultsThrowingException(results);
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException("Couldn't write results " + results, e);
+ }
+ _logger.info(this + " wrote " + results.getTestResults().size() + " results to database");
+ }
+
+ private void writeResultsThrowingException(ResultsForAllTests results) throws SQLException
+ {
+ Connection connection = null;
+ try
+ {
+ connection = DriverManager.getConnection(_url);
+
+ for (ITestResult testResult : results.getTestResults())
+ {
+ for (ParticipantResult participantResult : testResult.getParticipantResults())
+ {
+ writeParticipantResult(connection, participantResult);
+ }
+ }
+ }
+ finally
+ {
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+
+ private void writeParticipantResult(Connection connection, ParticipantResult participantResult) throws SQLException
+ {
+ if(_logger.isDebugEnabled())
+ {
+ _logger.debug("About to write to DB the following participant result: " + participantResult);
+ }
+
+ PreparedStatement statement = null;
+ try
+ {
+ String sqlTemplate = String.format(
+ "INSERT INTO %s (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) " +
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ RESULTS_TABLE_NAME,
+ TEST_NAME.getDisplayName(),
+ ITERATION_NUMBER.getDisplayName(),
+ PARTICIPANT_NAME.getDisplayName(),
+ THROUGHPUT.getDisplayName(),
+ AVERAGE_LATENCY.getDisplayName(),
+ CONFIGURED_CLIENT_NAME.getDisplayName(),
+ NUMBER_OF_MESSAGES_PROCESSED.getDisplayName(),
+ PAYLOAD_SIZE.getDisplayName(),
+ PRIORITY.getDisplayName(),
+ TIME_TO_LIVE.getDisplayName(),
+ ACKNOWLEDGE_MODE.getDisplayName(),
+ DELIVERY_MODE.getDisplayName(),
+ BATCH_SIZE.getDisplayName(),
+ MAXIMUM_DURATION.getDisplayName(),
+ PRODUCER_START_DELAY.getDisplayName(),
+ PRODUCER_INTERVAL.getDisplayName(),
+ IS_TOPIC.getDisplayName(),
+ IS_DURABLE_SUBSCRIPTION.getDisplayName(),
+ IS_BROWSING_SUBSCRIPTION.getDisplayName(),
+ IS_SELECTOR.getDisplayName(),
+ IS_NO_LOCAL.getDisplayName(),
+ IS_SYNCHRONOUS_CONSUMER.getDisplayName(),
+ TOTAL_NUMBER_OF_CONSUMERS.getDisplayName(),
+ TOTAL_NUMBER_OF_PRODUCERS.getDisplayName(),
+ TOTAL_PAYLOAD_PROCESSED.getDisplayName(),
+ TIME_TAKEN.getDisplayName(),
+ ERROR_MESSAGE.getDisplayName(),
+ MIN_LATENCY.getDisplayName(),
+ MAX_LATENCY.getDisplayName(),
+ LATENCY_STANDARD_DEVIATION.getDisplayName(),
+ RUN_ID,
+ INSERTED_TIMESTAMP
+ );
+ statement = connection.prepareStatement(sqlTemplate);
+
+ int columnIndex = 1;
+ statement.setString(columnIndex++, participantResult.getTestName());
+ statement.setInt(columnIndex++, participantResult.getIterationNumber());
+ statement.setString(columnIndex++, participantResult.getParticipantName());
+ statement.setDouble(columnIndex++, participantResult.getThroughput());
+ statement.setDouble(columnIndex++, participantResult.getAverageLatency());
+ statement.setString(columnIndex++, participantResult.getConfiguredClientName());
+ statement.setLong(columnIndex++, participantResult.getNumberOfMessagesProcessed());
+ statement.setLong(columnIndex++, participantResult.getPayloadSize());
+ statement.setLong(columnIndex++, participantResult.getPriority());
+ statement.setLong(columnIndex++, participantResult.getTimeToLive());
+ statement.setLong(columnIndex++, participantResult.getAcknowledgeMode());
+ statement.setLong(columnIndex++, participantResult.getDeliveryMode());
+ statement.setLong(columnIndex++, participantResult.getBatchSize());
+ statement.setLong(columnIndex++, participantResult.getMaximumDuration());
+ statement.setLong(columnIndex++, 0 /* TODO PRODUCER_START_DELAY*/);
+ statement.setLong(columnIndex++, 0 /* TODO PRODUCER_INTERVAL*/);
+ statement.setLong(columnIndex++, 0 /* TODO IS_TOPIC*/);
+ statement.setLong(columnIndex++, 0 /* TODO IS_DURABLE_SUBSCRIPTION*/);
+ statement.setLong(columnIndex++, 0 /* TODO IS_BROWSING_SUBSCRIPTION*/);
+ statement.setLong(columnIndex++, 0 /* TODO IS_SELECTOR*/);
+ statement.setLong(columnIndex++, 0 /* TODO IS_NO_LOCAL*/);
+ statement.setLong(columnIndex++, 0 /* TODO IS_SYNCHRONOUS_CONSUMER*/);
+ statement.setLong(columnIndex++, participantResult.getTotalNumberOfConsumers());
+ statement.setLong(columnIndex++, participantResult.getTotalNumberOfProducers());
+ statement.setLong(columnIndex++, participantResult.getTotalPayloadProcessed());
+ statement.setLong(columnIndex++, participantResult.getTimeTaken());
+ statement.setString(columnIndex++, participantResult.getErrorMessage());
+ statement.setLong(columnIndex++, participantResult.getMinLatency());
+ statement.setLong(columnIndex++, participantResult.getMaxLatency());
+ statement.setDouble(columnIndex++, participantResult.getLatencyStandardDeviation());
+
+ statement.setString(columnIndex++, _runId);
+ statement.setTimestamp(columnIndex++, new Timestamp(_clock.currentTimeMillis()));
+
+ statement.execute();
+ connection.commit();
+ }
+ catch(SQLException e)
+ {
+ _logger.error("Couldn't write " + participantResult, e);
+ }
+ finally
+ {
+ if (statement != null)
+ {
+ statement.close();
+ }
+ }
+ }
+
+ public static class Clock
+ {
+ public long currentTimeMillis()
+ {
+ return System.currentTimeMillis();
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("runId", _runId)
+ .append("url", _url)
+ .toString();
+ }
+}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java
index 3f8afc9a9a..f242111dc5 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java
@@ -218,7 +218,15 @@ public class ClientJmsDelegate
synchronized(session)
{
- final Destination destination = session.createQueue(command.getDestinationName());
+ final Destination destination;
+ if(command.isTopic())
+ {
+ destination = session.createTopic(command.getDestinationName());
+ }
+ else
+ {
+ destination = session.createQueue(command.getDestinationName());
+ }
final MessageProducer jmsProducer = session.createProducer(destination);
@@ -373,30 +381,6 @@ public class ClientJmsDelegate
}
}
- public void commitOrAcknowledgeMessage(final Message message, final String sessionName)
- {
- try
- {
- final Session session = _testSessions.get(sessionName);
- if (session.getTransacted())
- {
- synchronized(session)
- {
- session.commit();
- }
- }
- else if (message != null && session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
- {
- message.acknowledge();
- }
- }
- catch (final JMSException jmse)
- {
- throw new DistributedTestException("Unable to commit or acknowledge message on session: " +
- sessionName, jmse);
- }
- }
-
public int getAcknowledgeMode(final String sessionName)
{
try
@@ -493,31 +477,36 @@ public class ClientJmsDelegate
}
}
- public void rollbackOrRecover(String sessionName)
+ public void commitOrAcknowledgeMessageIfNecessary(final String sessionName, final Message message)
{
try
{
final Session session = _testSessions.get(sessionName);
- synchronized(session)
+ if (session.getTransacted())
{
- if (session.getTransacted())
- {
- session.rollback();
- }
- else if (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
+ synchronized(session)
{
- session.recover();
+ session.commit();
}
}
+ else if (message != null && session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
+ {
+ message.acknowledge();
+ }
}
catch (final JMSException jmse)
{
- throw new DistributedTestException("Unable to rollback or recover on session: " +
+ throw new DistributedTestException("Unable to commit or acknowledge message on session: " +
sessionName, jmse);
}
}
- public void releaseMessage(String sessionName)
+ public void commitIfNecessary(final String sessionName)
+ {
+ commitOrAcknowledgeMessageIfNecessary(sessionName, null);
+ }
+
+ public void rollbackOrRecoverIfNecessary(String sessionName)
{
try
{
@@ -528,7 +517,7 @@ public class ClientJmsDelegate
{
session.rollback();
}
- else
+ else if (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
{
session.recover();
}
@@ -536,7 +525,8 @@ public class ClientJmsDelegate
}
catch (final JMSException jmse)
{
- LOGGER.warn("Unable to rollback or recover on session: " + sessionName, jmse);
+ throw new DistributedTestException("Unable to rollback or recover on session: " +
+ sessionName, jmse);
}
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java
index c80e641e5c..782f7ae2fd 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java
@@ -224,12 +224,12 @@ public class ControllerJmsDelegate
public void createQueues(List<QueueConfig> queues)
{
- _queueCreator.createQueues(_session, queues);
+ _queueCreator.createQueues(_connection, _session, queues);
}
public void deleteQueues(List<QueueConfig> queues)
{
- _queueCreator.deleteQueues(_session, queues);
+ _queueCreator.deleteQueues(_connection, _session, queues);
}
public void addCommandListener(CommandListener commandListener)
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java
index 4d4850eccf..d7e0007b28 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java
@@ -20,18 +20,19 @@ package org.apache.qpid.disttest.jms;
import java.util.List;
+import javax.jms.Connection;
import javax.jms.Session;
import org.apache.qpid.disttest.controller.config.QueueConfig;
public class NoOpQueueCreator implements QueueCreator
{
@Override
- public void createQueues(Session session, List<QueueConfig> configs)
+ public void createQueues(Connection connection, Session session, List<QueueConfig> configs)
{
}
@Override
- public void deleteQueues(Session session, List<QueueConfig> configs)
+ public void deleteQueues(Connection connection, Session session, List<QueueConfig> configs)
{
}
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java
index 6874abe7d4..ef2cfb6cd4 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java
@@ -20,21 +20,29 @@ package org.apache.qpid.disttest.jms;
import java.util.List;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
import javax.jms.Session;
+
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.controller.config.QueueConfig;
+import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
public class QpidQueueCreator implements QueueCreator
{
private static final Logger LOGGER = LoggerFactory.getLogger(QpidQueueCreator.class);
private static final FieldTable EMPTY_QUEUE_BIND_ARGUMENTS = new FieldTable();
+ private static final String QUEUE_CREATOR_DRAIN_POLL_TIMEOUT = "qpid.disttest.queue.creator.drainPollTime";
+ private static int _drainPollTimeout = Integer.getInteger(QUEUE_CREATOR_DRAIN_POLL_TIMEOUT, 500);
@Override
- public void createQueues(Session session, List<QueueConfig> configs)
+ public void createQueues(Connection connection, Session session, List<QueueConfig> configs)
{
AMQSession<?, ?> amqSession = (AMQSession<?, ?>)session;
for (QueueConfig queueConfig : configs)
@@ -44,12 +52,88 @@ public class QpidQueueCreator implements QueueCreator
}
@Override
- public void deleteQueues(Session session, List<QueueConfig> configs)
+ public void deleteQueues(Connection connection, Session session, List<QueueConfig> configs)
{
AMQSession<?, ?> amqSession = (AMQSession<?, ?>)session;
for (QueueConfig queueConfig : configs)
{
- deleteQueue(amqSession, queueConfig);
+ AMQDestination destination = createAMQDestination(amqSession, queueConfig);
+
+ // drainQueue method is added because deletion of queue with a lot
+ // of messages takes time and might cause the timeout exception
+ drainQueue(connection, destination);
+
+ deleteQueue(amqSession, destination.getAMQQueueName());
+ }
+ }
+
+ private AMQDestination createAMQDestination(AMQSession<?, ?> amqSession, QueueConfig queueConfig)
+ {
+ try
+ {
+ return (AMQDestination) amqSession.createQueue(queueConfig.getName());
+ }
+ catch (Exception e)
+ {
+ throw new DistributedTestException("Failed to create amq destionation object:" + queueConfig, e);
+ }
+ }
+
+ private long getQueueDepth(AMQSession<?, ?> amqSession, AMQDestination destination)
+ {
+ try
+ {
+ long queueDepth = amqSession.getQueueDepth(destination);
+ return queueDepth;
+ }
+ catch (Exception e)
+ {
+ throw new DistributedTestException("Failed to query queue depth:" + destination, e);
+ }
+ }
+
+ private void drainQueue(Connection connection, AMQDestination destination)
+ {
+ Session noAckSession = null;
+ try
+ {
+ LOGGER.debug("About to drain the queue {}", destination.getQueueName());
+ noAckSession = connection.createSession(false, org.apache.qpid.jms.Session.NO_ACKNOWLEDGE);
+ MessageConsumer messageConsumer = noAckSession.createConsumer(destination);
+
+ long currentQueueDepth = getQueueDepth((AMQSession<?,?>)noAckSession, destination);
+ int counter = 0;
+ while (currentQueueDepth > 0)
+ {
+ LOGGER.info("Queue {} has {} message(s)", destination.getQueueName(), currentQueueDepth);
+
+ while(messageConsumer.receive(_drainPollTimeout) != null)
+ {
+ counter++;
+ }
+
+ currentQueueDepth = getQueueDepth((AMQSession<?,?>)noAckSession, destination);
+ }
+ LOGGER.info("Drained {} message(s) from queue {} ", counter, destination.getQueueName());
+ messageConsumer.close();
+ }
+ catch (Exception e)
+ {
+ throw new DistributedTestException("Failed to drain queue:" + destination, e);
+ }
+ finally
+ {
+ if (noAckSession != null)
+ {
+ try
+ {
+ noAckSession.close();
+ }
+ catch (JMSException e)
+ {
+ throw new DistributedTestException("Failed to close n/a session:" + noAckSession, e);
+ }
+ }
}
}
@@ -66,7 +150,7 @@ public class QpidQueueCreator implements QueueCreator
EMPTY_QUEUE_BIND_ARGUMENTS, destination.getExchangeName(),
destination, autoDelete);
- LOGGER.debug("Created queue " + queueConfig);
+ LOGGER.debug("Created queue {}", queueConfig);
}
catch (Exception e)
{
@@ -74,20 +158,19 @@ public class QpidQueueCreator implements QueueCreator
}
}
- private void deleteQueue(AMQSession<?, ?> session, QueueConfig queueConfig)
+ private void deleteQueue(AMQSession<?, ?> session, AMQShortString queueName)
{
try
{
// The Qpid AMQSession API currently makes the #deleteQueue method protected and the
// raw protocol method public. This should be changed then we should switch the below to
// use #deleteQueue.
- AMQDestination destination = (AMQDestination) session.createQueue(queueConfig.getName());
- session.sendQueueDelete(destination.getAMQQueueName());
- LOGGER.debug("Deleted queue " + queueConfig.getName());
+ session.sendQueueDelete(queueName);
+ LOGGER.debug("Deleted queue {}", queueName);
}
catch (Exception e)
{
- throw new DistributedTestException("Failed to delete queue:" + queueConfig.getName(), e);
+ throw new DistributedTestException("Failed to delete queue:" + queueName, e);
}
}
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java
index 0947dd53cb..a37cd7888c 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java
@@ -20,12 +20,13 @@ package org.apache.qpid.disttest.jms;
import java.util.List;
+import javax.jms.Connection;
import javax.jms.Session;
import org.apache.qpid.disttest.controller.config.QueueConfig;
public interface QueueCreator
{
- public void createQueues(final Session session, final List<QueueConfig> configs);
- public void deleteQueues(final Session session, final List<QueueConfig> configs);
+ void createQueues(Connection connection, Session session, List<QueueConfig> configs);
+ void deleteQueues(Connection connection, Session session, List<QueueConfig> configs);
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/message/ConsumerParticipantResult.java b/java/perftests/src/main/java/org/apache/qpid/disttest/message/ConsumerParticipantResult.java
index ad9aa31472..e78f6965d2 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/message/ConsumerParticipantResult.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/message/ConsumerParticipantResult.java
@@ -134,6 +134,7 @@ public class ConsumerParticipantResult extends ParticipantResult
_messageLatencies = messageLatencies;
}
+ @Override
@OutputAttribute(attribute=ParticipantAttribute.MIN_LATENCY)
public long getMinLatency()
{
@@ -145,6 +146,7 @@ public class ConsumerParticipantResult extends ParticipantResult
_minLatency = minLatency;
}
+ @Override
@OutputAttribute(attribute=ParticipantAttribute.MAX_LATENCY)
public long getMaxLatency()
{
@@ -156,6 +158,7 @@ public class ConsumerParticipantResult extends ParticipantResult
_maxLatency = maxLatency;
}
+ @Override
@OutputAttribute(attribute=ParticipantAttribute.AVERAGE_LATENCY)
public double getAverageLatency()
{
@@ -167,6 +170,7 @@ public class ConsumerParticipantResult extends ParticipantResult
_averageLatency = averageLatency;
}
+ @Override
@OutputAttribute(attribute=ParticipantAttribute.LATENCY_STANDARD_DEVIATION)
public double getLatencyStandardDeviation()
{
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateConsumerCommand.java b/java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateConsumerCommand.java
index 68c21fbf83..07a60504c8 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateConsumerCommand.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateConsumerCommand.java
@@ -21,7 +21,6 @@ package org.apache.qpid.disttest.message;
public class CreateConsumerCommand extends CreateParticpantCommand
{
- private boolean _isTopic;
private boolean _isDurableSubscription;
private boolean _isBrowsingSubscription;
private String _selector;
@@ -75,16 +74,6 @@ public class CreateConsumerCommand extends CreateParticpantCommand
this._noLocal = noLocal;
}
- public boolean isTopic()
- {
- return _isTopic;
- }
-
- public void setTopic(boolean isTopic)
- {
- this._isTopic = isTopic;
- }
-
public boolean isSynchronous()
{
return _synchronous;
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateParticpantCommand.java b/java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateParticpantCommand.java
index b1caa6ef75..e7349bf795 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateParticpantCommand.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/message/CreateParticpantCommand.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang.builder.ToStringBuilder;
public abstract class CreateParticpantCommand extends Command
{
+ private boolean _isTopic;
private String _participantName;
private String _sessionName;
private String _destinationName;
@@ -65,6 +66,16 @@ public abstract class CreateParticpantCommand extends Command
_destinationName = destinationName;
}
+ public boolean isTopic()
+ {
+ return _isTopic;
+ }
+
+ public void setTopic(boolean isTopic)
+ {
+ _isTopic = isTopic;
+ }
+
public long getNumberOfMessages()
{
return _numberOfMessages;
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttribute.java b/java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttribute.java
index 0418562a2d..1154ff306c 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttribute.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttribute.java
@@ -18,6 +18,8 @@
*/
package org.apache.qpid.disttest.message;
+import java.text.DecimalFormat;
+
import org.apache.qpid.disttest.client.Participant;
/**
@@ -31,6 +33,8 @@ public enum ParticipantAttribute
{
TEST_NAME("testName"),
ITERATION_NUMBER("iterationNumber"),
+ THROUGHPUT("throughputKbPerS", "#"),
+ AVERAGE_LATENCY("averageLatency", "#"),
CONFIGURED_CLIENT_NAME("clientName"),
PARTICIPANT_NAME("participantName"),
NUMBER_OF_MESSAGES_PROCESSED("numberOfMessages"),
@@ -52,24 +56,56 @@ public enum ParticipantAttribute
TOTAL_NUMBER_OF_CONSUMERS("totalNumberOfConsumers"),
TOTAL_NUMBER_OF_PRODUCERS("totalNumberOfProducers"),
TOTAL_PAYLOAD_PROCESSED("totalPayloadProcessedB"),
- THROUGHPUT("throughputKbPerS"),
TIME_TAKEN("timeTakenMs"),
ERROR_MESSAGE("errorMessage"),
MIN_LATENCY("minLatency"),
MAX_LATENCY("maxLatency"),
- AVERAGE_LATENCY("averageLatency"),
- LATENCY_STANDARD_DEVIATION("latencyStandardDeviation")
+ LATENCY_STANDARD_DEVIATION("latencyStandardDeviation"),
+ MESSAGE_THROUGHPUT("throughputMessagesPerS")
;
private String _displayName;
+ private String _decimalFormat;
ParticipantAttribute(String displayName)
{
_displayName = displayName;
}
+ ParticipantAttribute(String displayName, String decimalFormat)
+ {
+ _displayName = displayName;
+ _decimalFormat = decimalFormat;
+ }
+
+ public String getDecimalFormat()
+ {
+ return _decimalFormat;
+ }
+
public String getDisplayName()
{
return _displayName;
}
+
+ public String format(Object attributeValue)
+ {
+ if(attributeValue == null)
+ {
+ return null;
+ }
+
+ String attributeAsString = String.valueOf(attributeValue);
+
+ if(_decimalFormat != null)
+ {
+ DecimalFormat decimalFormat = new DecimalFormat(_decimalFormat);
+ double attributeAsDoule = Double.valueOf(attributeAsString);
+ return decimalFormat.format(attributeAsDoule);
+ }
+ else
+ {
+ return attributeAsString;
+ }
+ }
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantResult.java b/java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantResult.java
index a6d3d91bae..0a824a316b 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantResult.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantResult.java
@@ -22,11 +22,12 @@ import static org.apache.qpid.disttest.message.ParticipantAttribute.BATCH_SIZE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.CONFIGURED_CLIENT_NAME;
import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER;
import static org.apache.qpid.disttest.message.ParticipantAttribute.MAXIMUM_DURATION;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.MESSAGE_THROUGHPUT;
import static org.apache.qpid.disttest.message.ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT;
import java.util.Comparator;
import java.util.Date;
@@ -49,6 +50,7 @@ public class ParticipantResult extends Response
private long _totalPayloadProcessed;
private int _payloadSize;
private double _throughput;
+ private int _messageThroughput;
private int _totalNumberOfConsumers;
private int _totalNumberOfProducers;
@@ -236,6 +238,17 @@ public class ParticipantResult extends Response
_throughput = throughput;
}
+ @OutputAttribute(attribute=MESSAGE_THROUGHPUT)
+ public int getMessageThroughput()
+ {
+ return _messageThroughput;
+ }
+
+ public void setMessageThroughput(int throughput)
+ {
+ _messageThroughput = throughput;
+ }
+
public void setTotalNumberOfConsumers(int totalNumberOfConsumers)
{
_totalNumberOfConsumers = totalNumberOfConsumers;
@@ -269,4 +282,41 @@ public class ParticipantResult extends Response
_acknowledgeMode = acknowledgeMode;
}
+ public double getLatencyStandardDeviation()
+ {
+ return 0.0;
+ }
+
+ @OutputAttribute(attribute = ParticipantAttribute.MIN_LATENCY)
+ public long getMinLatency()
+ {
+ return 0;
+ }
+
+ @OutputAttribute(attribute = ParticipantAttribute.MAX_LATENCY)
+ public long getMaxLatency()
+ {
+ return 0;
+ }
+
+ @OutputAttribute(attribute = ParticipantAttribute.AVERAGE_LATENCY)
+ public double getAverageLatency()
+ {
+ return 0;
+ }
+
+ public int getPriority()
+ {
+ return 0;
+ }
+
+ public long getTimeToLive()
+ {
+ return 0;
+ }
+
+ public int getDeliveryMode()
+ {
+ return 0;
+ }
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/message/ProducerParticipantResult.java b/java/perftests/src/main/java/org/apache/qpid/disttest/message/ProducerParticipantResult.java
index 766c90eec8..2d9399a3d3 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/message/ProducerParticipantResult.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/message/ProducerParticipantResult.java
@@ -42,6 +42,7 @@ public class ProducerParticipantResult extends ParticipantResult
setParticipantName(participantName);
}
+ @Override
@OutputAttribute(attribute=PRIORITY)
public int getPriority()
{
@@ -53,6 +54,7 @@ public class ProducerParticipantResult extends ParticipantResult
_priority = priority;
}
+ @Override
@OutputAttribute(attribute=TIME_TO_LIVE)
public long getTimeToLive()
{
@@ -86,6 +88,7 @@ public class ProducerParticipantResult extends ParticipantResult
_interval = producerInterval;
}
+ @Override
@OutputAttribute(attribute=DELIVERY_MODE)
public int getDeliveryMode()
{
@@ -96,5 +99,4 @@ public class ProducerParticipantResult extends ParticipantResult
{
this._deliveryMode = deliveryMode;
}
-
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ITestResult.java b/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ITestResult.java
index 3f9cdff69d..6230067486 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ITestResult.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ITestResult.java
@@ -22,10 +22,8 @@ import java.util.List;
import org.apache.qpid.disttest.message.ParticipantResult;
-// TODO rename me!!
public interface ITestResult
{
-
// TODO should weaken to Collection
List<ParticipantResult> getParticipantResults();
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregator.java b/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregator.java
index 4dcabe6c7b..c21a78d359 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregator.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregator.java
@@ -142,6 +142,7 @@ public class ParticipantResultAggregator
aggregatedResult.setStartDate(new Date(_minStartDate));
aggregatedResult.setEndDate(new Date(_maxEndDate));
aggregatedResult.setThroughput(calculateThroughputInKiloBytesPerSecond());
+ aggregatedResult.setMessageThroughput(calculateThroughputInMessagesPerSecond());
}
private void setRolledUpConstantAttributes(ParticipantResult aggregatedResult)
@@ -197,4 +198,14 @@ public class ParticipantResultAggregator
return totalPayloadProcessedInKiloBytes/durationInSeconds;
}
+ private int calculateThroughputInMessagesPerSecond()
+ {
+ double durationInMillis = _maxEndDate - _minStartDate;
+ if (durationInMillis == 0 )
+ {
+ return 0;
+ }
+
+ return (int)Math.round((_numberOfMessagesProcessed * 1000.0d)/durationInMillis);
+ }
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregator.java b/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregator.java
index 5934e0e997..954828b043 100644
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregator.java
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregator.java
@@ -18,6 +18,9 @@
*/
package org.apache.qpid.disttest.results.aggregation;
+import java.util.List;
+
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
import org.apache.qpid.disttest.message.ConsumerParticipantResult;
import org.apache.qpid.disttest.message.ParticipantResult;
import org.apache.qpid.disttest.message.ProducerParticipantResult;
@@ -102,5 +105,26 @@ public class TestResultAggregator
aggregatedAllResult.setNumberOfMessagesProcessed(aggregatedConsumerResult.getNumberOfMessagesProcessed());
aggregatedAllResult.setTotalPayloadProcessed(aggregatedConsumerResult.getTotalPayloadProcessed());
aggregatedAllResult.setThroughput(aggregatedConsumerResult.getThroughput());
+ aggregatedAllResult.setMessageThroughput(aggregatedConsumerResult.getMessageThroughput());
+ }
+
+ /**
+ * Produces a single {@link ResultsForAllTests} from the supplied list, only containing
+ * the "All participants" results.
+ */
+ public ResultsForAllTests aggregateTestResults(List<ResultsForAllTests> allResultsList)
+ {
+ ResultsForAllTests retVal = new ResultsForAllTests();
+
+ for (ResultsForAllTests resultsForAllTests : allResultsList)
+ {
+ ResultsForAllTests allParticipantsResult = resultsForAllTests.getAllParticipantsResult();
+ for (ITestResult testResult : allParticipantsResult.getTestResults())
+ {
+ retVal.add(testResult);
+ }
+ }
+
+ return retVal;
}
}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/results/formatting/CSVFormater.java b/java/perftests/src/main/java/org/apache/qpid/disttest/results/formatting/CSVFormater.java
deleted file mode 100644
index 52e53ca624..0000000000
--- a/java/perftests/src/main/java/org/apache/qpid/disttest/results/formatting/CSVFormater.java
+++ /dev/null
@@ -1,89 +0,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.
- */
-package org.apache.qpid.disttest.results.formatting;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.qpid.disttest.controller.ResultsForAllTests;
-import org.apache.qpid.disttest.message.ParticipantAttribute;
-import org.apache.qpid.disttest.message.ParticipantResult;
-import org.apache.qpid.disttest.results.aggregation.ITestResult;
-
-/**
- * produces CSV output using the ordered enums in {@link ParticipantAttribute}
- */
-public class CSVFormater
-{
- public String format(ResultsForAllTests results)
- {
- StringBuilder builder = new StringBuilder();
-
- builder.append(header());
-
- List<ITestResult> testResults = results.getTestResults();
-
- for (ITestResult testResult : testResults)
- {
-
- List<ParticipantResult> participantResults = new ArrayList<ParticipantResult>(testResult.getParticipantResults());
- Collections.sort(participantResults, new CSVOrderParticipantResultComparator());
-
- for (ParticipantResult participantResult : participantResults)
- {
- Map<ParticipantAttribute, Object> attributes = participantResult.getAttributes();
- builder.append(row(attributes));
- }
- }
-
- return builder.toString();
- }
-
- /**
- * return a row, including a newline character at the end
- */
- private String row(Map<ParticipantAttribute, Object> attributeValueMap)
- {
- List<Object> attributeValues = new ArrayList<Object>();
- for (ParticipantAttribute attribute : ParticipantAttribute.values())
- {
- attributeValues.add(attributeValueMap.get(attribute));
- }
-
- String row = StringUtils.join(attributeValues.toArray(), ",");
- return row + "\n";
- }
-
- /** return the header row, including a newline at the end */
- private String header()
- {
- List<String> displayNames = new ArrayList<String>();
- for (ParticipantAttribute attribute : ParticipantAttribute.values())
- {
- displayNames.add(attribute.getDisplayName());
- }
-
- String header = StringUtils.join(displayNames.toArray(), ",");
- return header + "\n";
- }
-
-}
diff --git a/java/perftests/src/main/java/org/apache/qpid/disttest/results/formatting/CSVFormatter.java b/java/perftests/src/main/java/org/apache/qpid/disttest/results/formatting/CSVFormatter.java
new file mode 100644
index 0000000000..ea7a3f78c7
--- /dev/null
+++ b/java/perftests/src/main/java/org/apache/qpid/disttest/results/formatting/CSVFormatter.java
@@ -0,0 +1,91 @@
+/*
+ * 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.disttest.results.formatting;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
+import org.apache.qpid.disttest.message.ParticipantAttribute;
+import org.apache.qpid.disttest.message.ParticipantResult;
+import org.apache.qpid.disttest.results.aggregation.ITestResult;
+
+/**
+ * produces CSV output using the ordered enums in {@link ParticipantAttribute}
+ */
+public class CSVFormatter
+{
+ public String format(ResultsForAllTests results)
+ {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append(header());
+
+ List<ITestResult> testResults = results.getTestResults();
+
+ for (ITestResult testResult : testResults)
+ {
+
+ List<ParticipantResult> participantResults = new ArrayList<ParticipantResult>(testResult.getParticipantResults());
+ Collections.sort(participantResults, new CSVOrderParticipantResultComparator());
+
+ for (ParticipantResult participantResult : participantResults)
+ {
+ Map<ParticipantAttribute, Object> attributes = participantResult.getAttributes();
+ builder.append(row(attributes));
+ }
+ }
+
+ return builder.toString();
+ }
+
+ /**
+ * return a row, including a newline character at the end
+ */
+ private String row(Map<ParticipantAttribute, Object> attributeValueMap)
+ {
+ List<Object> attributeValues = new ArrayList<Object>();
+ for (ParticipantAttribute attribute : ParticipantAttribute.values())
+ {
+ Object attributeValue = attributeValueMap.get(attribute);
+ String attributeValueFormatted = attribute.format(attributeValue);
+ attributeValues.add(attributeValueFormatted);
+ }
+
+ String row = StringUtils.join(attributeValues.toArray(), ",");
+ return row + "\n";
+ }
+
+ /** return the header row, including a newline at the end */
+ private String header()
+ {
+ List<String> displayNames = new ArrayList<String>();
+ for (ParticipantAttribute attribute : ParticipantAttribute.values())
+ {
+ displayNames.add(attribute.getDisplayName());
+ }
+
+ String header = StringUtils.join(displayNames.toArray(), ",");
+ return header + "\n";
+ }
+
+}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java
index a10b3b359e..629442d86c 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/ConfigFileHelperTest.java
@@ -39,14 +39,6 @@ public class ConfigFileHelperTest extends QpidTestCase
_testDir = TestFileUtils.createTestDirectory();
}
- public void testGenerateOutputCsvNameFrom()
- {
- String outputDir = "/tmp/outputDir";
-
- assertEquals("/tmp/outputDir/my.json.file.csv", _configFileHelper.generateOutputCsvNameFrom("/tmp/my.json.file.json", outputDir));
- assertEquals("/tmp/outputDir/my.js.file.csv", _configFileHelper.generateOutputCsvNameFrom("/tmp/my.js.file.js", outputDir));
- }
-
public void testGetTestConfigFilesForDirectory() throws Exception
{
String jsFile = createFile("file1.js");
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.java
new file mode 100644
index 0000000000..ab55e8003d
--- /dev/null
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/ResultsFileWriterTest.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.disttest;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.Arrays;
+
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
+import org.apache.qpid.disttest.results.aggregation.TestResultAggregator;
+import org.apache.qpid.disttest.results.formatting.CSVFormatter;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.apache.qpid.util.FileUtils;
+
+public class ResultsFileWriterTest extends QpidTestCase
+{
+ private CSVFormatter _csvFormater = mock(CSVFormatter.class);
+ private TestResultAggregator _testResultAggregator = mock(TestResultAggregator.class);
+
+ private File _outputDir = TestFileUtils.createTestDirectory();
+
+ private ResultsFileWriter _resultsFileWriter = new ResultsFileWriter(_outputDir);
+
+ @Override
+ public void setUp()
+ {
+ _resultsFileWriter.setCsvFormater(_csvFormater);
+ _resultsFileWriter.setTestResultAggregator(_testResultAggregator);
+ }
+
+ public void testWriteResultsToFile()
+ {
+ ResultsForAllTests resultsForAllTests = mock(ResultsForAllTests.class);
+
+ String expectedCsvContents = "expected-csv-contents";
+ when(_csvFormater.format(resultsForAllTests)).thenReturn(expectedCsvContents);
+
+ _resultsFileWriter.writeResultsToFile(resultsForAllTests, "config.json");
+
+ File resultsFile = new File(_outputDir, "config.csv");
+
+ assertEquals(expectedCsvContents, FileUtils.readFileAsString(resultsFile));
+ }
+
+ public void testWriteResultsSummary()
+ {
+ ResultsForAllTests results1 = mock(ResultsForAllTests.class);
+ ResultsForAllTests results2 = mock(ResultsForAllTests.class);
+ ResultsForAllTests summaryResults = mock(ResultsForAllTests.class);
+
+ when(_testResultAggregator.aggregateTestResults(Arrays.asList(results1, results2)))
+ .thenReturn(summaryResults);
+
+ String expectedSummaryFileContents = "expected-summary-file";
+
+ when(_csvFormater.format(summaryResults))
+ .thenReturn(expectedSummaryFileContents);
+
+ _resultsFileWriter.writeResultsSummary(Arrays.asList(results1, results2));
+
+ File summaryFile = new File(_outputDir, ResultsFileWriter.TEST_SUMMARY_FILE_NAME);
+
+ assertEquals(expectedSummaryFileContents, FileUtils.readFileAsString(summaryFile));
+ }
+
+}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java
index 320e7d8c9d..09f7da4efb 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/VisitorTest.java
@@ -19,12 +19,11 @@
*/
package org.apache.qpid.disttest;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.message.Command;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class VisitorTest extends TestCase
+public class VisitorTest extends QpidTestCase
{
public void testStringVisited() throws Exception
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java
index 4a82f6719f..2b29471558 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientCommandVisitorTest.java
@@ -21,7 +21,6 @@ package org.apache.qpid.disttest.client;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import junit.framework.TestCase;
import org.apache.qpid.disttest.jms.ClientJmsDelegate;
import org.apache.qpid.disttest.message.CreateConnectionCommand;
@@ -32,8 +31,9 @@ import org.apache.qpid.disttest.message.CreateSessionCommand;
import org.apache.qpid.disttest.message.StartTestCommand;
import org.apache.qpid.disttest.message.StopClientCommand;
import org.apache.qpid.disttest.message.TearDownTestCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ClientCommandVisitorTest extends TestCase
+public class ClientCommandVisitorTest extends QpidTestCase
{
private Client _client;
private ClientCommandVisitor _visitor;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java
index dd50766918..8139961fa4 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ClientTest.java
@@ -29,17 +29,16 @@ import java.util.Collections;
import java.util.Timer;
import java.util.TimerTask;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.jms.ClientJmsDelegate;
import org.apache.qpid.disttest.message.Command;
import org.apache.qpid.disttest.message.ParticipantResult;
import org.apache.qpid.disttest.message.Response;
import org.apache.qpid.disttest.message.StopClientCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.mockito.InOrder;
import org.mockito.Mockito;
-public class ClientTest extends TestCase
+public class ClientTest extends QpidTestCase
{
private Client _client;
private ClientJmsDelegate _delegate;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java
index 58589d36f4..f75415a2bf 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ConsumerParticipantTest.java
@@ -34,16 +34,15 @@ import java.util.Collection;
import javax.jms.Message;
import javax.jms.Session;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.jms.ClientJmsDelegate;
import org.apache.qpid.disttest.message.ConsumerParticipantResult;
import org.apache.qpid.disttest.message.CreateConsumerCommand;
import org.apache.qpid.disttest.message.ParticipantResult;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.mockito.InOrder;
-public class ConsumerParticipantTest extends TestCase
+public class ConsumerParticipantTest extends QpidTestCase
{
private static final String SESSION_NAME1 = "SESSION1";
private static final String PARTICIPANT_NAME1 = "PARTICIPANT_NAME1";
@@ -114,7 +113,7 @@ public class ConsumerParticipantTest extends TestCase
_inOrder.verify(_delegate).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT);
_inOrder.verify(_delegate).calculatePayloadSizeFrom(_mockMessage);
- _inOrder.verify(_delegate).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ _inOrder.verify(_delegate).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage);
}
public void testReceiveMessagesForDurationSynch() throws Exception
@@ -129,7 +128,7 @@ public class ConsumerParticipantTest extends TestCase
verify(_delegate, atLeastOnce()).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT);
verify(_delegate, atLeastOnce()).calculatePayloadSizeFrom(_mockMessage);
- verify(_delegate, atLeastOnce()).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ verify(_delegate, atLeastOnce()).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage);
}
public void testReceiveMessagesBatchedSynch() throws Exception
@@ -147,7 +146,7 @@ public class ConsumerParticipantTest extends TestCase
verify(_delegate, times(numberOfMessages)).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT);
verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage);
- verify(_delegate, times(4)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ verify(_delegate, times(4)).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage);
}
public void testReceiveMessagesWithVaryingPayloadSize() throws Exception
@@ -171,7 +170,7 @@ public class ConsumerParticipantTest extends TestCase
verify(_delegate, times(numberOfMessages)).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT);
verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage);
- verify(_delegate, times(numberOfMessages)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ verify(_delegate, times(numberOfMessages)).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage);
}
public void testReleaseResources()
@@ -194,7 +193,7 @@ public class ConsumerParticipantTest extends TestCase
_inOrder.verify(_delegate).consumeMessage(PARTICIPANT_NAME1, RECEIVE_TIMEOUT);
_inOrder.verify(_delegate).calculatePayloadSizeFrom(_mockMessage);
- _inOrder.verify(_delegate).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ _inOrder.verify(_delegate).commitOrAcknowledgeMessageIfNecessary(SESSION_NAME1, _mockMessage);
assertTrue("Unexpected consuemr results", result instanceof ConsumerParticipantResult);
Collection<Long> latencies = ((ConsumerParticipantResult)result).getMessageLatencies();
assertNotNull("Message latency is not cllected", latencies);
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java
index 1ff8d3e5d7..8863e0f289 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/MessageProviderTest.java
@@ -33,14 +33,13 @@ import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.client.property.ListPropertyValue;
import org.apache.qpid.disttest.client.property.PropertyValue;
import org.apache.qpid.disttest.client.property.SimplePropertyValue;
import org.apache.qpid.disttest.message.CreateProducerCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class MessageProviderTest extends TestCase
+public class MessageProviderTest extends QpidTestCase
{
private Session _session;
private TextMessage _message;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java
index f30e4664ff..6720047cd1 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java
@@ -20,6 +20,7 @@
package org.apache.qpid.disttest.client;
import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -28,14 +29,13 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.message.ParticipantResult;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.mockito.ArgumentMatcher;
import org.mockito.InOrder;
-public class ParticipantExecutorTest extends TestCase
+public class ParticipantExecutorTest extends QpidTestCase
{
private static final ResultHasError HAS_ERROR = new ResultHasError();
private static final String CLIENT_NAME = "CLIENT_NAME";
@@ -69,8 +69,8 @@ public class ParticipantExecutorTest extends TestCase
InOrder inOrder = inOrder(_participant, _client);
inOrder.verify(_participant).doIt(CLIENT_NAME);
- inOrder.verify(_client).sendResults(_mockResult);
inOrder.verify(_participant).releaseResources();
+ inOrder.verify(_client).sendResults(_mockResult);
}
public void testParticipantThrowsException() throws Exception
@@ -82,13 +82,28 @@ public class ParticipantExecutorTest extends TestCase
InOrder inOrder = inOrder(_participant, _client);
inOrder.verify(_participant).doIt(CLIENT_NAME);
+ inOrder.verify(_participant).releaseResources();
inOrder.verify(_client).sendResults(argThat(HAS_ERROR));
+ }
+
+ public void testReleaseResourcesThrowsException() throws Exception
+ {
+ when(_participant.doIt(CLIENT_NAME)).thenReturn(_mockResult);
+ doThrow(DistributedTestException.class).when(_participant).releaseResources();
+
+ _participantExecutor.start(_client);
+
+ InOrder inOrder = inOrder(_participant, _client);
+
+ inOrder.verify(_participant).doIt(CLIENT_NAME);
inOrder.verify(_participant).releaseResources();
+
+ // check that sendResults is called even though releaseResources threw an exception
+ inOrder.verify(_client).sendResults(_mockResult);
}
public void testThreadNameAndDaemonness() throws Exception
{
-
ThreadPropertyReportingParticipant participant = new ThreadPropertyReportingParticipant(PARTICIPANT_NAME);
_participantExecutor = new ParticipantExecutor(participant);
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java
index bd0d5a39c8..5cc8d2f30a 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantRegistryTest.java
@@ -20,9 +20,10 @@
package org.apache.qpid.disttest.client;
import static org.mockito.Mockito.mock;
-import junit.framework.TestCase;
-public class ParticipantRegistryTest extends TestCase
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class ParticipantRegistryTest extends QpidTestCase
{
private ParticipantExecutorRegistry _participantRegistry = new ParticipantExecutorRegistry();
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java
index 3b21834a5c..9eab459443 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantResultFactoryTest.java
@@ -22,16 +22,15 @@ import java.util.Date;
import javax.jms.DeliveryMode;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.message.ConsumerParticipantResult;
import org.apache.qpid.disttest.message.CreateConsumerCommand;
import org.apache.qpid.disttest.message.CreateParticpantCommand;
import org.apache.qpid.disttest.message.CreateProducerCommand;
import org.apache.qpid.disttest.message.ParticipantResult;
import org.apache.qpid.disttest.message.ProducerParticipantResult;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ParticipantResultFactoryTest extends TestCase
+public class ParticipantResultFactoryTest extends QpidTestCase
{
private static final String PARTICIPANT_NAME = "participantName";
private static final String REGISTERED_CLIENT_NAME = "registeredClientName";
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java
index a3ac11b756..08ee8715fd 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/ProducerParticipantTest.java
@@ -31,15 +31,14 @@ import javax.jms.DeliveryMode;
import javax.jms.Message;
import javax.jms.Session;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.jms.ClientJmsDelegate;
import org.apache.qpid.disttest.message.CreateProducerCommand;
import org.apache.qpid.disttest.message.ParticipantResult;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.mockito.InOrder;
-public class ProducerParticipantTest extends TestCase
+public class ProducerParticipantTest extends QpidTestCase
{
private ProducerParticipant _producer;
@@ -127,13 +126,13 @@ public class ProducerParticipantTest extends TestCase
_inOrder.verify(_delegate).sendNextMessage(isA(CreateProducerCommand.class));
_inOrder.verify(_delegate).calculatePayloadSizeFrom(_mockMessage);
- _inOrder.verify(_delegate).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ _inOrder.verify(_delegate).commitIfNecessary(SESSION_NAME1);
}
public void testSendMessagesForDuration() throws Exception
{
- final long duration = 100;
+ final long duration = 1000;
_command.setMaximumDuration(duration);
ParticipantResult result = _producer.doIt(CLIENT_NAME);
@@ -142,7 +141,24 @@ public class ProducerParticipantTest extends TestCase
verify(_delegate, atLeastOnce()).sendNextMessage(isA(CreateProducerCommand.class));
verify(_delegate, atLeastOnce()).calculatePayloadSizeFrom(_mockMessage);
- verify(_delegate, atLeastOnce()).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ verify(_delegate, atLeastOnce()).commitIfNecessary(SESSION_NAME1);
+ }
+
+ public void testSendMessagesForDurationWithDelayExceedingDuration() throws Exception
+ {
+ final long duration = 100;
+ _command.setMaximumDuration(duration);
+ _command.setStartDelay(150);
+
+ try
+ {
+ _producer.doIt(CLIENT_NAME);
+ fail("Exception should be thrown indicating configuration error");
+ }
+ catch(DistributedTestException e)
+ {
+ assertEquals("Start delay must be less than maximum test duration", e.getMessage());
+ }
}
public void testSendMessageBatches() throws Exception
@@ -161,7 +177,7 @@ public class ProducerParticipantTest extends TestCase
verify(_delegate, times(numberOfMessages)).sendNextMessage(isA(CreateProducerCommand.class));
verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage);
- verify(_delegate, times(expectedNumberOfCommits)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ verify(_delegate, times(expectedNumberOfCommits)).commitIfNecessary(SESSION_NAME1);
}
public void testSendMessageWithPublishInterval() throws Exception
@@ -183,7 +199,7 @@ public class ProducerParticipantTest extends TestCase
verify(_delegate, times(numberOfMessages)).sendNextMessage(isA(CreateProducerCommand.class));
verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage);
- verify(_delegate, times(4)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ verify(_delegate, times(4)).commitIfNecessary(SESSION_NAME1);
}
public void testSendMessageWithVaryingPayloadSize() throws Exception
@@ -208,7 +224,7 @@ public class ProducerParticipantTest extends TestCase
verify(_delegate, times(numberOfMessages)).sendNextMessage(isA(CreateProducerCommand.class));
verify(_delegate, times(numberOfMessages)).calculatePayloadSizeFrom(_mockMessage);
- verify(_delegate, times(numberOfMessages)).commitOrAcknowledgeMessage(_mockMessage, SESSION_NAME1);
+ verify(_delegate, times(numberOfMessages)).commitIfNecessary(SESSION_NAME1);
}
public void testReleaseResources()
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java
index c54355bc76..3172eb07ed 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/ListPropertyValueTest.java
@@ -21,13 +21,9 @@ package org.apache.qpid.disttest.client.property;
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.disttest.client.property.ListPropertyValue;
-import org.apache.qpid.disttest.client.property.PropertyValue;
-import org.apache.qpid.disttest.client.property.SimplePropertyValue;
-
-public class ListPropertyValueTest extends TestCase
+public class ListPropertyValueTest extends QpidTestCase
{
private ListPropertyValue _generator;
private List<PropertyValue> _items;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java
index 17397db5b8..eba1bcc435 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/PropertyValueFactoryTest.java
@@ -18,9 +18,9 @@
*/
package org.apache.qpid.disttest.client.property;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class PropertyValueFactoryTest extends TestCase
+public class PropertyValueFactoryTest extends QpidTestCase
{
private PropertyValueFactory _factory;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java
index 878141895c..9651dd95ce 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RandomPropertyValueTest.java
@@ -18,11 +18,9 @@
*/
package org.apache.qpid.disttest.client.property;
-import org.apache.qpid.disttest.client.property.RandomPropertyValue;
+import org.apache.qpid.test.utils.QpidTestCase;
-import junit.framework.TestCase;
-
-public class RandomPropertyValueTest extends TestCase
+public class RandomPropertyValueTest extends QpidTestCase
{
private RandomPropertyValue _generator;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java
index 6932919bed..b0649a49ae 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/RangePropertyValueTest.java
@@ -18,11 +18,9 @@
*/
package org.apache.qpid.disttest.client.property;
-import org.apache.qpid.disttest.client.property.RangePropertyValue;
+import org.apache.qpid.test.utils.QpidTestCase;
-import junit.framework.TestCase;
-
-public class RangePropertyValueTest extends TestCase
+public class RangePropertyValueTest extends QpidTestCase
{
private RangePropertyValue _generator;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java
index a347d866c7..f1977015fe 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/property/SimplePropertyValueTest.java
@@ -18,9 +18,9 @@
*/
package org.apache.qpid.disttest.client.property;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class SimplePropertyValueTest extends TestCase
+public class SimplePropertyValueTest extends QpidTestCase
{
public void testGetValue()
{
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java
index 37820d2582..0880512333 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithNoLimitsTest.java
@@ -25,9 +25,9 @@ import static org.mockito.Mockito.when;
import java.util.concurrent.Callable;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ExecutorWithNoLimitsTest extends TestCase
+public class ExecutorWithNoLimitsTest extends QpidTestCase
{
private final static Object RESULT = new Object();
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java
index a201a7bacf..2abdba2446 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/client/utils/ExecutorWithTimeLimitTest.java
@@ -20,16 +20,16 @@
package org.apache.qpid.disttest.client.utils;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.never;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ExecutorWithTimeLimitTest extends TestCase
+public class ExecutorWithTimeLimitTest extends QpidTestCase
{
private static final int TIMEOUT = 500;
private static final Object RESULT = new Object();
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java
index cc969e1ef2..c07d9fcb81 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ClientRegistryTest.java
@@ -21,14 +21,15 @@ package org.apache.qpid.disttest.controller;
import java.util.Timer;
import java.util.TimerTask;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.DistributedTestException;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ClientRegistryTest extends TestCase
+public class ClientRegistryTest extends QpidTestCase
{
private static final String CLIENT1_REGISTERED_NAME = "CLIENT1_REGISTERED_NAME";
private static final String CLIENT2_REGISTERED_NAME = "CLIENT2_REGISTERED_NAME";
+ private static final String CLIENT3_REGISTERED_NAME = "CLIENT3_REGISTERED_NAME";
+
private static final int AWAIT_DELAY = 100;
private ClientRegistry _clientRegistry = new ClientRegistry();
@@ -70,7 +71,7 @@ public class ClientRegistryTest extends TestCase
assertEquals(0, numberOfClientsAbsent);
}
- public void testAwaitTwoClientWhenClientRegistersWhilstWaiting()
+ public void testAwaitTwoClientsWhenClientRegistersWhilstWaiting()
{
_clientRegistry.registerClient(CLIENT1_REGISTERED_NAME);
registerClientLater(CLIENT2_REGISTERED_NAME, 50);
@@ -79,6 +80,41 @@ public class ClientRegistryTest extends TestCase
assertEquals(0, numberOfClientsAbsent);
}
+ public void testAwaitTimeoutForPromptRegistrations()
+ {
+ registerClientsLaterAndAssertResult("Clients registering every 100ms should be within 600ms timeout",
+ new int[] {300, 400, 500},
+ 600,
+ 0);
+ }
+
+ public void testAwaitTimeoutForWhenThirdRegistrationIsLate()
+ {
+ registerClientsLaterAndAssertResult("Third client registering tardily should exceed timeout",
+ new int[] {300, 400, 1500},
+ 600,
+ 1);
+ }
+
+ public void testAwaitTimeoutWhenSecondAndThirdRegistrationsAreLate()
+ {
+ registerClientsLaterAndAssertResult("Second and third clients registering tardily should exceed timeout",
+ new int[] {300, 1500, 1500},
+ 600,
+ 2);
+ }
+
+ private void registerClientsLaterAndAssertResult(String message, int[] registrationDelays, int timeout, int expectedNumberOfAbsentees)
+ {
+ registerClientLater(CLIENT1_REGISTERED_NAME, registrationDelays[0]);
+ registerClientLater(CLIENT2_REGISTERED_NAME, registrationDelays[1]);
+ registerClientLater(CLIENT3_REGISTERED_NAME, registrationDelays[2]);
+
+ int numberOfClientsAbsent = _clientRegistry.awaitClients(3, timeout);
+
+ assertEquals(message, expectedNumberOfAbsentees, numberOfClientsAbsent);
+ }
+
private void registerClientLater(final String clientName, long delayInMillis)
{
doLater(new TimerTask()
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java
index bc58ea41c5..f773c727a1 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ControllerTest.java
@@ -19,6 +19,8 @@
*/
package org.apache.qpid.disttest.controller;
+import static org.apache.qpid.systest.disttest.SystemTestConstants.COMMAND_RESPONSE_TIMEOUT;
+import static org.apache.qpid.systest.disttest.SystemTestConstants.REGISTRATION_TIMEOUT;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
@@ -31,8 +33,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.controller.config.Config;
import org.apache.qpid.disttest.controller.config.TestInstance;
@@ -42,16 +42,14 @@ import org.apache.qpid.disttest.message.RegisterClientCommand;
import org.apache.qpid.disttest.message.Response;
import org.apache.qpid.disttest.message.StopClientCommand;
import org.apache.qpid.disttest.results.aggregation.ITestResult;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-public class ControllerTest extends TestCase
+public class ControllerTest extends QpidTestCase
{
private static final String CLIENT1_REGISTERED_NAME = "client-uid1";
- private static final long COMMAND_RESPONSE_TIMEOUT = 1000;
- private static final long REGISTRATION_TIMEOUT = 1000;
-
private Controller _controller;
private ControllerJmsDelegate _respondingJmsDelegate;
private TestRunner _testRunner;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java
index 284db38f44..da180f328f 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/ParticipatingClientsTest.java
@@ -25,9 +25,9 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ParticipatingClientsTest extends TestCase
+public class ParticipatingClientsTest extends QpidTestCase
{
private static final String CLIENT1_CONFIGURED_NAME = "CLIENT1_CONFIGURED_NAME";
private static final String CLIENT2_CONFIGURED_NAME = "CLIENT2_CONFIGURED_NAME";
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java
index 983da299b9..d8b25e76fa 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/TestRunnerTest.java
@@ -32,8 +32,6 @@ import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.controller.config.QueueConfig;
import org.apache.qpid.disttest.controller.config.TestInstance;
@@ -45,10 +43,11 @@ import org.apache.qpid.disttest.message.ParticipantResult;
import org.apache.qpid.disttest.message.Response;
import org.apache.qpid.disttest.message.StartTestCommand;
import org.apache.qpid.disttest.message.TearDownTestCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-public class TestRunnerTest extends TestCase
+public class TestRunnerTest extends QpidTestCase
{
private static final String TEST_NAME = "TEST_NAME";
private static final String PARTICIPANT_NAME = "TEST_PARTICIPANT_NAME";
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java
index d4af439dea..4bf4307eaf 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java
@@ -29,16 +29,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.client.property.PropertyValue;
import org.apache.qpid.disttest.client.property.SimplePropertyValue;
import org.apache.qpid.disttest.controller.CommandForClient;
import org.apache.qpid.disttest.message.Command;
import org.apache.qpid.disttest.message.CreateMessageProviderCommand;
import org.apache.qpid.disttest.message.NoOpCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ClientConfigTest extends TestCase
+public class ClientConfigTest extends QpidTestCase
{
private static final String CLIENT1 = "client1";
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js
index 07f8bf9d92..527300eff4 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js
@@ -1,3 +1,23 @@
+/*
+ *
+ * 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.
+ *
+ */
jsonObject = {
"_tests":
QPID.iterations( { "__ACK_MODE": [ 0, 1 ] },
@@ -31,4 +51,4 @@ jsonObject = {
)
})
-} \ No newline at end of file
+}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
index 257f139849..e208945901 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
@@ -23,12 +23,12 @@ import java.io.Reader;
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.ConfigFileTestHelper;
import org.apache.qpid.disttest.client.property.PropertyValue;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
-public class ConfigReaderTest extends TestCase
+public class ConfigReaderTest extends QpidTestCase
{
private Config _config;
@@ -111,8 +111,9 @@ public class ConfigReaderTest extends TestCase
public void testReadsJS() throws Exception
{
ConfigReader configReader = new ConfigReader();
- String path = getClass().getResource("ConfigReaderTest-test-config.js").toURI().getPath();
+ String path = TestFileUtils.createTempFileFromResource(this, "ConfigReaderTest-test-config.js").getAbsolutePath();
_config = configReader.getConfigFromFile(path);
+
List<TestConfig> testConfigs = _config.getTestConfigs();
assertEquals("Unexpected number of tests", 2, testConfigs.size());
TestConfig testConfig1 = _config.getTestConfigs().get(0);
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java
index 88750b9737..291ce2af78 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigTest.java
@@ -24,9 +24,9 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ConfigTest extends TestCase
+public class ConfigTest extends QpidTestCase
{
public void testGetTestsForTestWithIteratingMessageSizes()
{
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java
index 7c839ed462..0eee80e425 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConnectionConfigTest.java
@@ -27,13 +27,12 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.message.Command;
import org.apache.qpid.disttest.message.CreateConnectionCommand;
import org.apache.qpid.disttest.message.NoOpCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ConnectionConfigTest extends TestCase
+public class ConnectionConfigTest extends QpidTestCase
{
private static final String CONNECTION_FACTORY_NAME = "ConnectionFactoryName";
private static final String CONNECTION_NAME = "ConnectionName";
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java
index c011ff4711..0aa05a176e 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConsumerConfigTest.java
@@ -19,11 +19,10 @@
*/
package org.apache.qpid.disttest.controller.config;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.message.CreateConsumerCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ConsumerConfigTest extends TestCase
+public class ConsumerConfigTest extends QpidTestCase
{
public void testConsumerHasZeroArgConstructorForGson()
{
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js
index f64af82feb..eab98e8bd7 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js
@@ -1,3 +1,23 @@
+/*
+ *
+ * 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.
+ *
+ */
jsonObject = {
"_countries":
QPID.iterations( { "__ITERATING_VALUE": [ 0, 1 ] },
@@ -20,4 +40,4 @@ jsonObject = {
)
})
-} \ No newline at end of file
+}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
index eb4063888b..55c1d4a7bd 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
@@ -25,15 +25,16 @@ import static org.apache.commons.beanutils.PropertyUtils.getProperty;
import java.util.List;
import java.util.TreeMap;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
import com.google.gson.Gson;
-public class JavaScriptConfigEvaluatorTest extends TestCase
+public class JavaScriptConfigEvaluatorTest extends QpidTestCase
{
public void testEvaluateJavaScript() throws Exception
{
- String jsFilePath = getClass().getResource("JavaScriptConfigEvaluatorTest-test-config.js").toURI().getPath();
+ String jsFilePath = TestFileUtils.createTempFileFromResource(this, "JavaScriptConfigEvaluatorTest-test-config.js").getAbsolutePath();
String rawConfig = new JavaScriptConfigEvaluator().evaluateJavaScript(jsFilePath);
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java
index a3b367a4b4..148c07b1ca 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/MessageProviderConfigTest.java
@@ -21,13 +21,12 @@ package org.apache.qpid.disttest.controller.config;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.client.property.PropertyValue;
import org.apache.qpid.disttest.client.property.SimplePropertyValue;
import org.apache.qpid.disttest.message.CreateMessageProviderCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class MessageProviderConfigTest extends TestCase
+public class MessageProviderConfigTest extends QpidTestCase
{
public void testCreateCommandsForMessageProvider()
{
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java
index f58cc628a4..b6efd68cbd 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ParticipantConfigTest.java
@@ -32,7 +32,7 @@ public class ParticipantConfigTest extends QpidTestCase
setTestSystemProperty(ParticipantConfig.DURATION_OVERRIDE_SYSTEM_PROPERTY, String.valueOf(overriddenDuration));
CreateParticpantCommand createParticipantCommand = mock(CreateParticpantCommand.class);
- ParticipantConfig participantConfig = new ParticipantConfig("name", "destinationName", 1, 2, 5000)
+ ParticipantConfig participantConfig = new ParticipantConfig("name", "destinationName", false, 1, 2, 5000)
{
};
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java
index b9e591f113..44fca4bb7c 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ProducerConfigTest.java
@@ -22,11 +22,10 @@ package org.apache.qpid.disttest.controller.config;
import javax.jms.DeliveryMode;
import javax.jms.Message;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.message.CreateProducerCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ProducerConfigTest extends TestCase
+public class ProducerConfigTest extends QpidTestCase
{
public void testProducerHasZeroArgConstructorForGson()
{
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java
index 8775e4064d..02cdbb8fca 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/SessionConfigTest.java
@@ -29,14 +29,13 @@ import java.util.List;
import javax.jms.Session;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.message.Command;
import org.apache.qpid.disttest.message.CreateConsumerCommand;
import org.apache.qpid.disttest.message.CreateProducerCommand;
import org.apache.qpid.disttest.message.CreateSessionCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class SessionConfigTest extends TestCase
+public class SessionConfigTest extends QpidTestCase
{
private static final String CONNECTION_NAME = "conn1";
private static final String SESSION = "session1";
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java
index 1212a57606..be7c7a7c8c 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestConfigTest.java
@@ -26,12 +26,11 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.controller.CommandForClient;
import org.apache.qpid.disttest.message.NoOpCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class TestConfigTest extends TestCase
+public class TestConfigTest extends QpidTestCase
{
private static final QueueConfig[] EMPTY_QUEUES_ARRAY = new QueueConfig[0];
private static final String CLIENT1 = "client1";
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java
index 928fbe58cf..187b57c399 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/TestInstanceTest.java
@@ -26,14 +26,13 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.controller.CommandForClient;
import org.apache.qpid.disttest.message.CreateConsumerCommand;
import org.apache.qpid.disttest.message.CreateProducerCommand;
import org.apache.qpid.disttest.message.NoOpCommand;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class TestInstanceTest extends TestCase
+public class TestInstanceTest extends QpidTestCase
{
private static final String CLIENT_NAME = "CLIENT_NAME";
private static final int ITERATION_NUMBER = 0;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java
new file mode 100644
index 0000000000..abc6b44493
--- /dev/null
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/db/ResultsDbWriterTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.disttest.db;
+
+import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT;
+import static org.apache.qpid.test.utils.TestFileUtils.createTestDirectory;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.Hashtable;
+import java.util.TimeZone;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
+import org.apache.qpid.disttest.db.ResultsDbWriter.Clock;
+import org.apache.qpid.disttest.message.ParticipantResult;
+import org.apache.qpid.disttest.results.ResultsTestFixture;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.util.FileUtils;
+
+public class ResultsDbWriterTest extends QpidTestCase
+{
+ private static final long _dummyTimestamp = 1234;
+
+ private File _tempDbDirectory;
+ private Clock _clock = mock(Clock.class);
+ private ResultsTestFixture _resultsTestFixture = new ResultsTestFixture();
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _tempDbDirectory = createTestDirectory();
+ when(_clock.currentTimeMillis()).thenReturn(_dummyTimestamp);
+ }
+
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ FileUtils.deleteDirectory(_tempDbDirectory.getAbsolutePath());
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+
+ public void testWriteResults() throws Exception
+ {
+ Context context = getContext();
+ ResultsForAllTests results = _resultsTestFixture.createResultsForAllTests();
+ String runId = "myRunId";
+
+ ResultsDbWriter resultsDbWriter = new ResultsDbWriter(context, runId, _clock);
+ resultsDbWriter.createResultsTableIfNecessary();
+
+ resultsDbWriter.writeResults(results);
+
+ ParticipantResult expectedResult = _resultsTestFixture.getFirstParticipantResult(results);
+ assertResultsAreInDb(context, expectedResult, runId);
+ }
+
+ public void testDefaultRunId() throws Exception
+ {
+ TimeZone defaultTimeZone = TimeZone.getDefault();
+ try
+ {
+ // set non-GMT timezone to make the test more rigorous.
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT-05:00"));
+ ResultsDbWriter resultsDbWriter = new ResultsDbWriter(getContext(), null, _clock);
+ String runId = resultsDbWriter.getRunId();
+ assertEquals(
+ "Default run id '" + runId + "' should correspond to dummy timestamp " + _clock.currentTimeMillis(),
+ "run 1970-01-01 00:00:01.234",
+ runId);
+ }
+ finally
+ {
+ TimeZone.setDefault(defaultTimeZone);
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private Context getContext() throws NamingException
+ {
+ Context context = mock(Context.class);
+ Hashtable environment = new Hashtable();
+
+ environment.put(ResultsDbWriter.DRIVER_NAME, "org.apache.derby.jdbc.EmbeddedDriver");
+ environment.put(ResultsDbWriter.URL, "jdbc:derby:" + _tempDbDirectory + "perftestResultsDb;create=true");
+
+ when(context.getEnvironment()).thenReturn(environment);
+ return context;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void assertResultsAreInDb(Context context, ParticipantResult participantResult, String expectedRunId) throws Exception
+ {
+ String driverName = (String) context.getEnvironment().get(ResultsDbWriter.DRIVER_NAME);
+ Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(driverName);
+ driverClass.newInstance();
+ String url = (String) context.getEnvironment().get(ResultsDbWriter.URL);
+
+ Connection connection = DriverManager.getConnection(url);
+ Statement statement = connection.createStatement();
+ ResultSet rs = statement.executeQuery(
+ "SELECT * FROM results WHERE testName='" + participantResult.getTestName() +
+ "' AND runId='" + expectedRunId + "'");
+
+ try
+ {
+ rs.next();
+ assertEquals(participantResult.getTestName(), rs.getString(TEST_NAME.getDisplayName()));
+ assertEquals(participantResult.getIterationNumber(), rs.getInt(ITERATION_NUMBER.getDisplayName()));
+ assertEquals(participantResult.getParticipantName(), rs.getString(PARTICIPANT_NAME.getDisplayName()));
+ assertEquals(participantResult.getThroughput(), rs.getDouble(THROUGHPUT.getDisplayName()));
+ assertEquals(expectedRunId, rs.getString(ResultsDbWriter.RUN_ID));
+ assertEquals(new Timestamp(_dummyTimestamp), rs.getTimestamp(ResultsDbWriter.INSERTED_TIMESTAMP));
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java
index ab0f52263b..d4f0cb1f22 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/jms/JmsMessageAdaptorTest.java
@@ -18,12 +18,11 @@
*/
package org.apache.qpid.disttest.jms;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.message.Command;
import org.apache.qpid.disttest.message.CommandType;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class JmsMessageAdaptorTest extends TestCase
+public class JmsMessageAdaptorTest extends QpidTestCase
{
public void testCheckAllCommandTypes()
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java
index 4a56fff8fe..2e0c2e1ecd 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/message/JsonHandlerTest.java
@@ -24,14 +24,13 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.qpid.disttest.client.property.ListPropertyValue;
import org.apache.qpid.disttest.client.property.PropertyValue;
import org.apache.qpid.disttest.json.JsonHandler;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class JsonHandlerTest extends TestCase
+public class JsonHandlerTest extends QpidTestCase
{
private JsonHandler _jsonHandler = null;
private SendChristmasCards _testCommand = null;
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java
index 34727a7b8d..e9d444d59c 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/message/ParticipantResultTest.java
@@ -18,7 +18,8 @@
*/
package org.apache.qpid.disttest.message;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.*;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.ACKNOWLEDGE_MODE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.BATCH_SIZE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.CONFIGURED_CLIENT_NAME;
import static org.apache.qpid.disttest.message.ParticipantAttribute.DELIVERY_MODE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.ERROR_MESSAGE;
@@ -30,23 +31,25 @@ import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SYNCHRONO
import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_TOPIC;
import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER;
import static org.apache.qpid.disttest.message.ParticipantAttribute.MAXIMUM_DURATION;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PRIORITY;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_INTERVAL;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_START_DELAY;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TAKEN;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TO_LIVE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_CONSUMERS;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_PRODUCERS;
import java.util.Date;
import javax.jms.DeliveryMode;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ParticipantResultTest extends TestCase
+public class ParticipantResultTest extends QpidTestCase
{
public void testSharedParticipantResultAttributes() throws Exception
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsTestFixture.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsTestFixture.java
new file mode 100644
index 0000000000..1edef031bf
--- /dev/null
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/ResultsTestFixture.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.disttest.results;
+
+import static org.apache.qpid.disttest.message.ParticipantAttribute.ACKNOWLEDGE_MODE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.AVERAGE_LATENCY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.BATCH_SIZE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.CONFIGURED_CLIENT_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.DELIVERY_MODE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.ERROR_MESSAGE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_BROWSING_SUBSCRIPTION;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_DURABLE_SUBSCRIPTION;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_NO_LOCAL;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SELECTOR;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SYNCHRONOUS_CONSUMER;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_TOPIC;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.LATENCY_STANDARD_DEVIATION;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.MAXIMUM_DURATION;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.MAX_LATENCY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.MESSAGE_THROUGHPUT;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.MIN_LATENCY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PRIORITY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_INTERVAL;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_START_DELAY;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TAKEN;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TO_LIVE;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_CONSUMERS;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_PRODUCERS;
+import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_PAYLOAD_PROCESSED;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
+import org.apache.qpid.disttest.controller.TestResult;
+import org.apache.qpid.disttest.message.ParticipantAttribute;
+import org.apache.qpid.disttest.message.ParticipantResult;
+import org.apache.qpid.disttest.results.aggregation.ITestResult;
+
+public class ResultsTestFixture
+{
+ public static final double THROUGHPUT_VALUE = 2048.49;
+
+ private static final String TEST1 = "TEST1";
+ private static final String PARTICIPANT = "PARTICIPANT";
+ private static final String CONFIGURED_CLIENT1 = "CONFIGURED_CLIENT1";
+
+ public ResultsForAllTests createResultsForAllTests()
+ {
+ ParticipantResult participantResult = mock(ParticipantResult.class);
+ Map<ParticipantAttribute, Object> participantAttributes = getParticipantAttributes();
+
+ when(participantResult.getAttributes()).thenReturn(participantAttributes);
+ when(participantResult.getParticipantName()).thenReturn(PARTICIPANT);
+ when(participantResult.getTestName()).thenReturn(TEST1);
+ when(participantResult.getIterationNumber()).thenReturn(0);
+ when(participantResult.getThroughput()).thenReturn(THROUGHPUT_VALUE);
+
+ TestResult testResult = new TestResult(TEST1);
+ testResult.addParticipantResult(participantResult);
+
+ ResultsForAllTests resultsForAllTests = new ResultsForAllTests();
+ resultsForAllTests.add(testResult);
+ return resultsForAllTests;
+ }
+
+ private Map<ParticipantAttribute, Object> getParticipantAttributes()
+ {
+ Map<ParticipantAttribute, Object> participantAttributes = new HashMap<ParticipantAttribute, Object>();
+
+ participantAttributes.put(TEST_NAME, TEST1);
+ participantAttributes.put(ITERATION_NUMBER, 0);
+ participantAttributes.put(CONFIGURED_CLIENT_NAME, CONFIGURED_CLIENT1);
+ participantAttributes.put(PARTICIPANT_NAME, PARTICIPANT);
+ participantAttributes.put(NUMBER_OF_MESSAGES_PROCESSED, 2);
+ participantAttributes.put(PAYLOAD_SIZE, 1);
+ participantAttributes.put(PRIORITY, 2);
+ participantAttributes.put(TIME_TO_LIVE, 3);
+ participantAttributes.put(ACKNOWLEDGE_MODE, 4);
+ participantAttributes.put(DELIVERY_MODE, 5);
+ participantAttributes.put(BATCH_SIZE, 6);
+ participantAttributes.put(MAXIMUM_DURATION, 7);
+ participantAttributes.put(PRODUCER_START_DELAY, 8);
+ participantAttributes.put(PRODUCER_INTERVAL, 9);
+ participantAttributes.put(IS_TOPIC, true);
+ participantAttributes.put(IS_DURABLE_SUBSCRIPTION, false);
+ participantAttributes.put(IS_BROWSING_SUBSCRIPTION, true);
+ participantAttributes.put(IS_SELECTOR, false);
+ participantAttributes.put(IS_NO_LOCAL, true);
+ participantAttributes.put(IS_SYNCHRONOUS_CONSUMER, false);
+ participantAttributes.put(TOTAL_NUMBER_OF_CONSUMERS, 1);
+ participantAttributes.put(TOTAL_NUMBER_OF_PRODUCERS, 2);
+ participantAttributes.put(TOTAL_PAYLOAD_PROCESSED, 1024);
+ participantAttributes.put(THROUGHPUT, THROUGHPUT_VALUE);
+ participantAttributes.put(TIME_TAKEN, 1000);
+ participantAttributes.put(ERROR_MESSAGE, "error");
+ participantAttributes.put(MIN_LATENCY, 2l);
+ participantAttributes.put(MAX_LATENCY, 9l);
+ participantAttributes.put(AVERAGE_LATENCY, 4.6f);
+ participantAttributes.put(LATENCY_STANDARD_DEVIATION, 2.0f);
+ participantAttributes.put(MESSAGE_THROUGHPUT, 2);
+ return participantAttributes;
+ }
+
+ public ParticipantResult getFirstParticipantResult(ResultsForAllTests results)
+ {
+ List<ITestResult> testResults = results.getTestResults();
+ ITestResult testResult = testResults.iterator().next();
+ List<ParticipantResult> participantResults = testResult.getParticipantResults();
+ return participantResults.iterator().next();
+ }
+}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java
index 393837b4d5..011eb4e68b 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/AggregatorTest.java
@@ -24,11 +24,10 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.controller.ResultsForAllTests;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class AggregatorTest extends TestCase
+public class AggregatorTest extends QpidTestCase
{
private Aggregator _aggregator = new Aggregator();
private TestResultAggregator _testResultAggregator = mock(TestResultAggregator.class);
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java
index 72743be1d1..41da1edb33 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java
@@ -24,11 +24,9 @@ import java.util.Date;
import javax.jms.Session;
import org.apache.qpid.disttest.message.ParticipantResult;
-import org.apache.qpid.disttest.results.aggregation.ParticipantResultAggregator;
+import org.apache.qpid.test.utils.QpidTestCase;
-import junit.framework.TestCase;
-
-public class ParticipantResultAggregatorTest extends TestCase
+public class ParticipantResultAggregatorTest extends QpidTestCase
{
private ParticipantResultAggregator _aggregator = new ParticipantResultAggregator(ParticipantResult.class, AGGREGATED_RESULT_NAME);
@@ -39,15 +37,19 @@ public class ParticipantResultAggregatorTest extends TestCase
private static final long PARTICIPANT1_STARTDATE = 50;
private static final long PARTICIPANT1_ENDDATE = 20000;
private static final long PARTICIPANT1_TOTAL_PROCESSED = 1024;
+ private static final int PARTICIPANT1_NUMBER_OF_MESSAGES_PROCESSED = 20000;
private static final long PARTICIPANT2_STARTDATE = 100;
private static final long PARTICIPANT2_ENDDATE = 21000;
private static final long PARTICIPANT2_TOTAL_PROCESSED = 2048;
+ private static final int PARTICIPANT2_NUMBER_OF_MESSAGES_PROCESSED = 950;
private static final long OVERALL_PROCESSED = PARTICIPANT1_TOTAL_PROCESSED + PARTICIPANT2_TOTAL_PROCESSED;
private static final double OVERALL_TIMETAKEN = PARTICIPANT2_ENDDATE - PARTICIPANT1_STARTDATE;
+ private static final long OVERALL_NUMBER_OF_MESSAGES_PROCESSED = PARTICIPANT1_NUMBER_OF_MESSAGES_PROCESSED + PARTICIPANT2_NUMBER_OF_MESSAGES_PROCESSED;
private static final double EXPECTED_AGGREGATED_ALL_THROUGHPUT = ((OVERALL_PROCESSED)/1024)/((OVERALL_TIMETAKEN)/1000);
+ private static final int EXPECTED_AGGREGATED_MESSAGE_THROUGHPUT = (int)(OVERALL_NUMBER_OF_MESSAGES_PROCESSED * 1000.0d/OVERALL_TIMETAKEN);
public void testStartAndEndDateForOneParticipantResult()
{
@@ -128,6 +130,26 @@ public class ParticipantResultAggregatorTest extends TestCase
assertEquals(EXPECTED_AGGREGATED_ALL_THROUGHPUT, aggregratedResult.getThroughput(), 0.1);
}
+ public void testComputeMessageThroughput()
+ {
+ ParticipantResult result1 = new ParticipantResult();
+ result1.setStartDate(new Date(PARTICIPANT1_STARTDATE));
+ result1.setEndDate(new Date(PARTICIPANT1_ENDDATE));
+ result1.setNumberOfMessagesProcessed(PARTICIPANT1_NUMBER_OF_MESSAGES_PROCESSED);
+
+ ParticipantResult result2 = new ParticipantResult();
+ result2.setStartDate(new Date(PARTICIPANT2_STARTDATE));
+ result2.setEndDate(new Date(PARTICIPANT2_ENDDATE));
+ result2.setNumberOfMessagesProcessed(PARTICIPANT2_NUMBER_OF_MESSAGES_PROCESSED);
+
+ _aggregator.aggregate(result1);
+ _aggregator.aggregate(result2);
+
+ ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
+ assertEquals(EXPECTED_AGGREGATED_MESSAGE_THROUGHPUT, aggregratedResult.getMessageThroughput());
+
+ }
+
public void testConstantTestNameAndIterationNumberRolledUp() throws Exception
{
ParticipantResult result1 = new ParticipantResult();
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java
index ec8da8418f..7417dddc4f 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/SeriesStatisticsTest.java
@@ -23,9 +23,9 @@ package org.apache.qpid.disttest.results.aggregation;
import java.util.Arrays;
import java.util.Collection;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class SeriesStatisticsTest extends TestCase
+public class SeriesStatisticsTest extends QpidTestCase
{
public static Collection<Long> SERIES = Arrays.asList(new Long[] { 2l, 4l, 4l, 4l, 5l, 5l, 7l, 9l, 5l });
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java
index 9c00e7cf1c..b254a0e3bf 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/TestResultAggregatorTest.java
@@ -18,29 +18,30 @@
*/
package org.apache.qpid.disttest.results.aggregation;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import junit.framework.TestCase;
-
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
import org.apache.qpid.disttest.controller.TestResult;
import org.apache.qpid.disttest.message.ConsumerParticipantResult;
import org.apache.qpid.disttest.message.ParticipantResult;
import org.apache.qpid.disttest.message.ProducerParticipantResult;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class TestResultAggregatorTest extends TestCase
+public class TestResultAggregatorTest extends QpidTestCase
{
-
private static final String TEST1_NAME = "TEST1_NAME";
private static final int TEST1_ITERATION_NUMBER = 1;
-
private static final String CONSUMER_PARTICIPANT_NAME1 = "CONSUMER_PARTICIPANT_NAME1";
private static final String CONSUMER_PARTICIPANT_NAME2 = "CONSUMER_PARTICIPANT_NAME2";
private static final String PRODUCER_PARTICIPANT_NAME = "PRODUCER_PARTICIPANT_NAME";
-
private static final long CONSUMER1_STARTDATE = 50;
private static final long CONSUMER1_ENDDATE = 20000;
@@ -64,6 +65,33 @@ public class TestResultAggregatorTest extends TestCase
private TestResultAggregator _aggregator = new TestResultAggregator();
+ public void testAggregateTestResults()
+ {
+ ResultsForAllTests resultsForAllTests1 = mock(ResultsForAllTests.class);
+ ResultsForAllTests resultsForAllTests2 = mock(ResultsForAllTests.class);
+
+ ResultsForAllTests summaryResult1 = mock(ResultsForAllTests.class);
+ ResultsForAllTests summaryResult2 = mock(ResultsForAllTests.class);
+
+ when(resultsForAllTests1.getAllParticipantsResult()).thenReturn(summaryResult1);
+ when(resultsForAllTests2.getAllParticipantsResult()).thenReturn(summaryResult2);
+
+ ITestResult testResult1 = mock(ITestResult.class);
+ ITestResult testResult2 = mock(ITestResult.class);
+
+ when(summaryResult1.getTestResults()).thenReturn(Arrays.asList(testResult1));
+ when(summaryResult2.getTestResults()).thenReturn(Arrays.asList(testResult2));
+
+ ResultsForAllTests actualSummaryResults = _aggregator.aggregateTestResults(Arrays.asList(
+ resultsForAllTests1,
+ resultsForAllTests2));
+
+ assertEquals(
+ "Summary results should contain the all the 'all participants' test results",
+ Arrays.asList(testResult1, testResult2),
+ actualSummaryResults.getTestResults());
+ }
+
public void testAggregateResultsForTwoConsumerAndOneProducer() throws Exception
{
TestResult originalTestResult = createResultsFromTest();
@@ -141,6 +169,10 @@ public class TestResultAggregatorTest extends TestCase
aggregatedTestResult.getAllParticipantResult(),
TEST1_NAME, TEST1_ITERATION_NUMBER,
BATCH_SIZE, NUMBER_OF_MESSAGES_CONSUMED_IN_TOTAL, 2, 1);
+
+ int expectedThroughtput = (int)Math.round(NUMBER_OF_MESSAGES_PRODUCED * 1000.0d /(CONSUMER2_ENDDATE - PRODUCER_STARTDATE));
+ ParticipantResult result = aggregatedTestResult.getAllParticipantResult();
+ assertEquals("Unexpected message throughtput", expectedThroughtput, result.getMessageThroughput());
}
private void assertLatencyAggregatedResults(ParticipantResult allConsumerParticipantResult)
@@ -197,4 +229,5 @@ public class TestResultAggregatorTest extends TestCase
participantResult.setEndDate(new Date(end));
participantResult.setBatchSize(batchSize);
}
+
}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormaterTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormaterTest.java
deleted file mode 100644
index 565f59d25b..0000000000
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormaterTest.java
+++ /dev/null
@@ -1,146 +0,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.
- */
-package org.apache.qpid.disttest.results.formatting;
-
-import static org.apache.qpid.disttest.message.ParticipantAttribute.BATCH_SIZE;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.CONFIGURED_CLIENT_NAME;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.*;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.ERROR_MESSAGE;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_BROWSING_SUBSCRIPTION;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_DURABLE_SUBSCRIPTION;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_NO_LOCAL;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SELECTOR;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SYNCHRONOUS_CONSUMER;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_TOPIC;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.MAXIMUM_DURATION;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.PRIORITY;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_INTERVAL;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_START_DELAY;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TAKEN;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TO_LIVE;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_CONSUMERS;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_PRODUCERS;
-import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_PAYLOAD_PROCESSED;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.apache.qpid.disttest.controller.ResultsForAllTests;
-import org.apache.qpid.disttest.controller.TestResult;
-import org.apache.qpid.disttest.message.ParticipantAttribute;
-import org.apache.qpid.disttest.message.ParticipantResult;
-
-public class CSVFormaterTest extends TestCase
-{
- private static final String TEST1 = "TEST1";
- private static final String PARTICIPANT = "PARTICIPANT";
- private static final String CONFIGURED_CLIENT1 = "CONFIGURED_CLIENT1";
-
- private CSVFormater _formatter = new CSVFormater();
-
- public void testResultsFileWithWithOneRow() throws Exception
- {
- ParticipantResult participantResult = mock(ParticipantResult.class);
- Map<ParticipantAttribute, Object> participantAttributes = getParticipantAttributes();
-
- when(participantResult.getAttributes()).thenReturn(participantAttributes);
- when(participantResult.getParticipantName()).thenReturn(PARTICIPANT);
-
- TestResult testResult = new TestResult(TEST1);
- testResult.addParticipantResult(participantResult);
-
- ResultsForAllTests resultsForAllTests = new ResultsForAllTests();
- resultsForAllTests.add(testResult);
-
- String output = _formatter.format(resultsForAllTests);
-
- String expectedOutput = readCsvOutputFileAsString("expectedOutput.csv");
-
- assertEquals(expectedOutput, output);
- }
-
- private Map<ParticipantAttribute, Object> getParticipantAttributes()
- {
- Map<ParticipantAttribute, Object> participantAttributes = new HashMap<ParticipantAttribute, Object>();
-
- participantAttributes.put(TEST_NAME, TEST1);
- participantAttributes.put(ITERATION_NUMBER, 0);
- participantAttributes.put(CONFIGURED_CLIENT_NAME, CONFIGURED_CLIENT1);
- participantAttributes.put(PARTICIPANT_NAME, PARTICIPANT);
- participantAttributes.put(NUMBER_OF_MESSAGES_PROCESSED, 0);
- participantAttributes.put(PAYLOAD_SIZE, 1);
- participantAttributes.put(PRIORITY, 2);
- participantAttributes.put(TIME_TO_LIVE, 3);
- participantAttributes.put(ACKNOWLEDGE_MODE, 4);
- participantAttributes.put(DELIVERY_MODE, 5);
- participantAttributes.put(BATCH_SIZE, 6);
- participantAttributes.put(MAXIMUM_DURATION, 7);
- participantAttributes.put(PRODUCER_START_DELAY, 8);
- participantAttributes.put(PRODUCER_INTERVAL, 9);
- participantAttributes.put(IS_TOPIC, true);
- participantAttributes.put(IS_DURABLE_SUBSCRIPTION, false);
- participantAttributes.put(IS_BROWSING_SUBSCRIPTION, true);
- participantAttributes.put(IS_SELECTOR, false);
- participantAttributes.put(IS_NO_LOCAL, true);
- participantAttributes.put(IS_SYNCHRONOUS_CONSUMER, false);
- participantAttributes.put(TOTAL_NUMBER_OF_CONSUMERS, 1);
- participantAttributes.put(TOTAL_NUMBER_OF_PRODUCERS, 2);
- participantAttributes.put(TOTAL_PAYLOAD_PROCESSED, 1024);
- participantAttributes.put(THROUGHPUT, 2048);
- participantAttributes.put(TIME_TAKEN, 1000);
- participantAttributes.put(ERROR_MESSAGE, "error");
- participantAttributes.put(MIN_LATENCY, 2l);
- participantAttributes.put(MAX_LATENCY, 9l);
- participantAttributes.put(AVERAGE_LATENCY, 5.0f);
- participantAttributes.put(LATENCY_STANDARD_DEVIATION, 2.0f);
- return participantAttributes;
- }
-
- private String readCsvOutputFileAsString(String filename) throws Exception
- {
- InputStream is = getClass().getResourceAsStream(filename);
- assertNotNull(is);
-
- StringBuilder output = new StringBuilder();
-
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
- String line = null;
- while((line = br.readLine()) != null)
- {
- output.append(line);
- output.append("\n");
- }
-
- return output.toString();
- }
-
-}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormatterTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormatterTest.java
new file mode 100644
index 0000000000..bbf73b23d2
--- /dev/null
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormatterTest.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.disttest.results.formatting;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.apache.qpid.disttest.controller.ResultsForAllTests;
+import org.apache.qpid.disttest.results.ResultsTestFixture;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class CSVFormatterTest extends QpidTestCase
+{
+ private CSVFormatter _formatter = new CSVFormatter();
+
+ public void testResultsFileWithWithOneRow() throws Exception
+ {
+ ResultsTestFixture resultsTestFixture = new ResultsTestFixture();
+ ResultsForAllTests resultsForAllTests = resultsTestFixture.createResultsForAllTests();
+
+ String output = _formatter.format(resultsForAllTests);
+
+ String expectedOutput = readCsvOutputFileAsString("expectedOutput.csv");
+
+ assertEquals(expectedOutput, output);
+ }
+
+ private String readCsvOutputFileAsString(String filename) throws Exception
+ {
+ InputStream is = getClass().getResourceAsStream(filename);
+ assertNotNull(is);
+
+ StringBuilder output = new StringBuilder();
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ String line = null;
+ while((line = br.readLine()) != null)
+ {
+ output.append(line);
+ output.append("\n");
+ }
+
+ return output.toString();
+ }
+}
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java
index 6cec4b5245..ed109a2e27 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVOrderParticipantResultComparatorTest.java
@@ -19,15 +19,13 @@
package org.apache.qpid.disttest.results.formatting;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.message.ConsumerParticipantResult;
import org.apache.qpid.disttest.message.ParticipantResult;
import org.apache.qpid.disttest.message.ProducerParticipantResult;
import org.apache.qpid.disttest.results.aggregation.TestResultAggregator;
-import org.apache.qpid.disttest.results.formatting.CSVOrderParticipantResultComparator;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class CSVOrderParticipantResultComparatorTest extends TestCase
+public class CSVOrderParticipantResultComparatorTest extends QpidTestCase
{
CSVOrderParticipantResultComparator _comparator = new CSVOrderParticipantResultComparator();
diff --git a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv
index ada2303d46..02ea67d56d 100644
--- a/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv
+++ b/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/expectedOutput.csv
@@ -1,2 +1,2 @@
-testName,iterationNumber,clientName,participantName,numberOfMessages,payloadSizeB,priority,timeToLiveMs,acknowledgeMode,deliveryMode,batchSize,maximumDurationMs,producerStartDelayMs,producerIntervalMs,isTopic,isDurableSubscription,isBrowsingSubscription,isSelector,isNoLocal,isSynchronousConsumer,totalNumberOfConsumers,totalNumberOfProducers,totalPayloadProcessedB,throughputKbPerS,timeTakenMs,errorMessage,minLatency,maxLatency,averageLatency,latencyStandardDeviation
-TEST1,0,CONFIGURED_CLIENT1,PARTICIPANT,0,1,2,3,4,5,6,7,8,9,true,false,true,false,true,false,1,2,1024,2048,1000,error,2,9,5.0,2.0
+testName,iterationNumber,throughputKbPerS,averageLatency,clientName,participantName,numberOfMessages,payloadSizeB,priority,timeToLiveMs,acknowledgeMode,deliveryMode,batchSize,maximumDurationMs,producerStartDelayMs,producerIntervalMs,isTopic,isDurableSubscription,isBrowsingSubscription,isSelector,isNoLocal,isSynchronousConsumer,totalNumberOfConsumers,totalNumberOfProducers,totalPayloadProcessedB,timeTakenMs,errorMessage,minLatency,maxLatency,latencyStandardDeviation,throughputMessagesPerS
+TEST1,0,2048,5,CONFIGURED_CLIENT1,PARTICIPANT,2,1,2,3,4,5,6,7,8,9,true,false,true,false,true,false,1,2,1024,1000,error,2,9,2.0,2
diff --git a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java
index 784e43469e..59396d46c0 100644
--- a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/QpidQueueCreatorTest.java
@@ -29,7 +29,6 @@ import javax.jms.Session;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.controller.config.QueueConfig;
import org.apache.qpid.disttest.jms.QpidQueueCreator;
@@ -37,6 +36,9 @@ public class QpidQueueCreatorTest extends DistributedTestSystemTestBase
{
private static final Map<String, Object> EMPTY_ATTRIBUTES = Collections.emptyMap();
+ private static final boolean QUEUE_DURABILITY = true;
+
+ private Connection _connection;
private QpidQueueCreator _creator;
private Session _session;
private List<QueueConfig> _configs;
@@ -46,20 +48,20 @@ public class QpidQueueCreatorTest extends DistributedTestSystemTestBase
public void setUp() throws Exception
{
super.setUp();
- Connection connection = getConnection();
- _session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ _connection = getConnection();
+ _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
_creator = new QpidQueueCreator();
_configs = new ArrayList<QueueConfig>();
- _queueName = "direct://amq.direct//" + getTestQueueName();
+ _queueName = "direct://amq.direct//" + getTestQueueName() + "?durable='" + QUEUE_DURABILITY + "'";
}
public void testCreateQueueWithoutAttributes() throws Exception
{
- _configs.add(new QueueConfig(_queueName, true, EMPTY_ATTRIBUTES));
+ _configs.add(new QueueConfig(_queueName, QUEUE_DURABILITY, EMPTY_ATTRIBUTES));
assertQueueBound(_queueName, false);
- _creator.createQueues(_session, _configs);
+ _creator.createQueues(_connection, _session, _configs);
assertQueueBound(_queueName, true);
}
@@ -68,46 +70,28 @@ public class QpidQueueCreatorTest extends DistributedTestSystemTestBase
{
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("x-qpid-priorities", Integer.valueOf(5));
- _configs.add(new QueueConfig(_queueName, true, attributes));
+ _configs.add(new QueueConfig(_queueName, QUEUE_DURABILITY, attributes));
assertQueueBound(_queueName, false);
- _creator.createQueues(_session, _configs);
+ _creator.createQueues(_connection, _session, _configs);
assertQueueBound(_queueName, true);
}
public void testDeleteQueues() throws Exception
{
- _configs.add(new QueueConfig(_queueName, true, EMPTY_ATTRIBUTES));
+ _configs.add(new QueueConfig(_queueName, QUEUE_DURABILITY, EMPTY_ATTRIBUTES));
assertQueueBound(_queueName, false);
- _creator.createQueues(_session, _configs);
+ _creator.createQueues(_connection, _session, _configs);
assertQueueBound(_queueName, true);
- _creator.deleteQueues(_session, _configs);
+ _creator.deleteQueues(_connection, _session, _configs);
assertQueueBound(_queueName, false);
}
- public void testDeleteQueueThatDoesNotExist() throws Exception
- {
- String queueThatDoesNotExist = _queueName;
- List<QueueConfig> configs = new ArrayList<QueueConfig>();
- Map<String, Object> attributes = Collections.emptyMap();
- configs.add(new QueueConfig(queueThatDoesNotExist, true, attributes));
-
- try
- {
- _creator.deleteQueues(_session, configs);
- fail("Exception not thrown");
- }
- catch (DistributedTestException e)
- {
- // PASS
- }
- }
-
private void assertQueueBound(String queueName, boolean isBound) throws Exception
{
AMQDestination destination = (AMQDestination)_session.createQueue(queueName);
diff --git a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java
index 808b428bc9..b06ab0c735 100644
--- a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java
+++ b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/SystemTestConstants.java
@@ -21,8 +21,8 @@ package org.apache.qpid.systest.disttest;
public abstract class SystemTestConstants
{
- public static final long REGISTRATION_TIMEOUT = 5000;
- public static final long COMMAND_RESPONSE_TIMEOUT = 10000;
- public static final long TEST_RESULT_TIMEOUT = 5000;
+ public static final long REGISTRATION_TIMEOUT = 20000;
+ public static final long COMMAND_RESPONSE_TIMEOUT = 30000;
+ public static final long TEST_RESULT_TIMEOUT = 20000;
}
diff --git a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java
index 7e58e1b5b1..a0c2a4b342 100644
--- a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java
+++ b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/EndToEndTest.java
@@ -20,7 +20,9 @@ package org.apache.qpid.systest.disttest.endtoend;
import static org.apache.qpid.disttest.AbstractRunner.JNDI_CONFIG_PROP;
import static org.apache.qpid.disttest.ControllerRunner.OUTPUT_DIR_PROP;
+import static org.apache.qpid.disttest.ControllerRunner.RUN_ID;
import static org.apache.qpid.disttest.ControllerRunner.TEST_CONFIG_PROP;
+import static org.apache.qpid.disttest.ControllerRunner.WRITE_TO_DB;
import java.io.File;
import java.io.IOException;
@@ -36,6 +38,7 @@ public class EndToEndTest extends QpidBrokerTestCase
private ControllerRunner _runner;
private static final String TEST_CONFIG = "perftests/src/test/java/org/apache/qpid/systest/disttest/endtoend/endtoend.json";
private static final String JNDI_CONFIG_FILE = "perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties";
+ private static final String RUN1 = "run1";
public void testRunner() throws Exception
{
@@ -44,6 +47,8 @@ public class EndToEndTest extends QpidBrokerTestCase
final String[] args = new String[] {TEST_CONFIG_PROP + "=" + TEST_CONFIG,
JNDI_CONFIG_PROP + "=" + JNDI_CONFIG_FILE,
+ WRITE_TO_DB + "=true",
+ RUN_ID + "=" + RUN1,
OUTPUT_DIR_PROP + "=" + csvOutputDir.getAbsolutePath()};
_runner = new ControllerRunner();
_runner.parseArgumentsIntoConfig(args);
@@ -76,10 +81,10 @@ public class EndToEndTest extends QpidBrokerTestCase
String[] cells = csvLine.split(",", DONT_STRIP_EMPTY_LAST_FIELD_FLAG);
// All attributes become cells in the CSV, so this will be true
assertEquals("Unexpected number of cells in CSV line " + csvLine, ParticipantAttribute.values().length, cells.length);
- assertEquals("Unexpected test name in CSV line " + csvLine, testName, cells[0]);
- assertEquals("Unexpected client name in CSV line " + csvLine, clientName, cells[2]);
- assertEquals("Unexpected participant name in CSV line " + csvLine, participantName, cells[3]);
- assertEquals("Unexpected number of messages processed in CSV line " + csvLine, String.valueOf(expectedNumberOfMessagesProcessed), cells[4]);
+ assertEquals("Unexpected test name in CSV line " + csvLine, testName, cells[ParticipantAttribute.TEST_NAME.ordinal()]);
+ assertEquals("Unexpected client name in CSV line " + csvLine, clientName, cells[ParticipantAttribute.CONFIGURED_CLIENT_NAME.ordinal()]);
+ assertEquals("Unexpected participant name in CSV line " + csvLine, participantName, cells[ParticipantAttribute.PARTICIPANT_NAME.ordinal()]);
+ assertEquals("Unexpected number of messages processed in CSV line " + csvLine, String.valueOf(expectedNumberOfMessagesProcessed), cells[ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED.ordinal()]);
}
diff --git a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties
index b5d053227c..149e632048 100644
--- a/java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties
+++ b/java/perftests/src/test/java/org/apache/qpid/systest/disttest/perftests.systests.properties
@@ -24,3 +24,6 @@ java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextF
connectionfactory.connectionfactory = amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:15672'
destination.controllerqueue = direct://amq.direct//controllerqueue
+
+jdbcDriverClass=org.apache.derby.jdbc.EmbeddedDriver
+jdbcUrl=jdbc:derby:/tmp/tempDbDirectory/perftestResultsDb;create=true
diff --git a/java/perftests/visualisation-jfc/build.xml b/java/perftests/visualisation-jfc/build.xml
index 02c9f5dcbd..04deb39d36 100644
--- a/java/perftests/visualisation-jfc/build.xml
+++ b/java/perftests/visualisation-jfc/build.xml
@@ -17,8 +17,8 @@
- under the License.
-->
<project name="visualisation-jfc" xmlns:ivy="antlib:org.apache.ivy.ant" default="build">
- <property name="module.depends" value="common perftests" />
- <property name="module.test.depends" value="test common/test" />
+ <property name="module.depends" value="perftests" />
+ <property name="module.test.depends" value="common common/tests" />
<property name="module.manifest" value="true" />
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java
index ed09f4a77e..5a77f22148 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java
@@ -21,5 +21,5 @@ package org.apache.qpid.disttest.charting;
public enum ChartType
{
- LINE, LINE3D, BAR, BAR3D, XYLINE, STATISTICAL_BAR
+ LINE, LINE3D, BAR, BAR3D, XYLINE, TIMELINE, STATISTICAL_BAR
}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java
index e00859855e..91eafe324b 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java
@@ -30,7 +30,8 @@ import org.apache.qpid.disttest.charting.chartbuilder.ChartBuilder;
import org.apache.qpid.disttest.charting.chartbuilder.ChartBuilderFactory;
import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
import org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator;
-import org.apache.qpid.disttest.charting.seriesbuilder.JdbcCsvSeriesBuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.JdbcSeriesBuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.JdbcUrlGenerator;
import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
import org.apache.qpid.disttest.charting.writer.ChartWriter;
import org.jfree.chart.JFreeChart;
@@ -44,24 +45,46 @@ import org.slf4j.LoggerFactory;
* The following arguments are understood:
* </p>
* <ol>
- * <li>chart-defs=<i>directory contain chartdef file(s)</i></li>
- * <li>output-dir=<i>directory in which to produce the PNGs</i></li>
+ * <li>{@link #OUTPUT_DIR_PROP}</li>
+ * <li>{@link #CHART_DEFINITIONS_PROP}</li>
+ * <li>{@link #SUMMARY_TITLE_PROP}</li>
+ * <li>{@link #JDBC_DRIVER_NAME_PROP}</li>
+ * <li>{@link #JDBC_URL_PROP}</li>
* </ol>
+ * Default values are indicated by the similarly named constants in this class.
*/
public class ChartingUtil
{
private static final Logger LOGGER = LoggerFactory.getLogger(ChartingUtil.class);
+ /** directory in which to produce the PNGs */
public static final String OUTPUT_DIR_PROP = "outputdir";
public static final String OUTPUT_DIR_DEFAULT = ".";
+ /** the path to the directory containing the chart definition files */
public static final String CHART_DEFINITIONS_PROP = "chart-defs";
public static final String CHART_DEFINITIONS_DEFAULT = ".";
+ public static final String SUMMARY_TITLE_PROP = "summary-title";
+ public static final String SUMMARY_TITLE_DEFAULT = "Performance Charts";
+
+ /** the class name of the JDBC driver to use for reading the chart data */
+ public static final String JDBC_DRIVER_NAME_PROP = "jdbcDriverClass";
+ public static final String JDBC_DRIVER_NAME_DEFAULT = JdbcUrlGenerator.DEFAULT_JDBC_DRIVER_NAME;
+
+ /** the JDBC URL of the data to be charted */
+ public static final String JDBC_URL_PROP = "jdbcUrl";
+ public static final String JDBC_URL_DEFAULT = null;
+
+
private Map<String,String> _cliOptions = new HashMap<String, String>();
+
{
_cliOptions.put(OUTPUT_DIR_PROP, OUTPUT_DIR_DEFAULT);
_cliOptions.put(CHART_DEFINITIONS_PROP, CHART_DEFINITIONS_DEFAULT);
+ _cliOptions.put(SUMMARY_TITLE_PROP, SUMMARY_TITLE_DEFAULT);
+ _cliOptions.put(JDBC_DRIVER_NAME_PROP, JDBC_DRIVER_NAME_DEFAULT);
+ _cliOptions.put(JDBC_URL_PROP, JDBC_URL_DEFAULT);
}
public static void main(String[] args) throws Exception
@@ -82,26 +105,38 @@ public class ChartingUtil
private void produceAllCharts()
{
- final String chartingDefsDir = _cliOptions.get(CHART_DEFINITIONS_PROP);
- final File chartDirectory = new File(_cliOptions.get(OUTPUT_DIR_PROP));
- LOGGER.info("Chart chartdef directory/file: {} output directory : {}", chartingDefsDir, chartDirectory);
-
- List<ChartingDefinition> definitions = loadChartDefinitions(chartingDefsDir);
-
- LOGGER.info("There are {} chart(s) to produce", definitions.size());
final ChartWriter writer = new ChartWriter();
- writer.setOutputDirectory(chartDirectory);
+ writer.setOutputDirectory(new File(_cliOptions.get(OUTPUT_DIR_PROP)));
+
+ SeriesBuilder seriesBuilder = new JdbcSeriesBuilder(
+ _cliOptions.get(JDBC_DRIVER_NAME_PROP),
+ _cliOptions.get(JDBC_URL_PROP));
- final SeriesBuilder seriesBuilder = new JdbcCsvSeriesBuilder();
- for (ChartingDefinition chartingDefinition : definitions)
+ for (ChartingDefinition chartingDefinition : loadChartDefinitions())
{
- ChartBuilder chartBuilder = ChartBuilderFactory.createChartBuilder(chartingDefinition.getChartType(), seriesBuilder);
+ ChartBuilder chartBuilder = ChartBuilderFactory.createChartBuilder(
+ chartingDefinition.getChartType(),
+ seriesBuilder);
+
JFreeChart chart = chartBuilder.buildChart(chartingDefinition);
- writer.writeChartToFileSystem(chart, chartingDefinition.getChartStemName());
+ writer.writeChartToFileSystem(chart, chartingDefinition);
}
- writer.writeHtmlSummaryToFileSystem();
+ final String summaryChartTitle = _cliOptions.get(SUMMARY_TITLE_PROP);
+ writer.writeHtmlSummaryToFileSystem(summaryChartTitle);
+ }
+
+ private List<ChartingDefinition> loadChartDefinitions()
+ {
+ final String chartingDefsDir = _cliOptions.get(CHART_DEFINITIONS_PROP);
+
+ LOGGER.info("Chart chartdef directory/file: {}", chartingDefsDir);
+
+ List<ChartingDefinition> definitions = loadChartDefinitions(chartingDefsDir);
+
+ LOGGER.info("There are {} chart(s) to produce", definitions.size());
+ return definitions;
}
private List<ChartingDefinition> loadChartDefinitions(String chartingDefsDir)
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java
index 491bb1c67d..b10fd477ed 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java
@@ -36,7 +36,7 @@ public class BarChart3DBuilder extends CategoryDataSetBasedChartBuilder
}
@Override
- public JFreeChart createChartImpl(String title, String xAxisTitle,
+ protected JFreeChart createCategoryChart(String title, String xAxisTitle,
String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
boolean showLegend, boolean showToolTips, boolean showUrls)
{
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java
index b5c6a38067..7705ef5d3a 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java
@@ -35,7 +35,7 @@ public class BarChartBuilder extends CategoryDataSetBasedChartBuilder
}
@Override
- public JFreeChart createChartImpl(String title, String xAxisTitle,
+ protected JFreeChart createCategoryChart(String title, String xAxisTitle,
String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
boolean showLegend, boolean showToolTips, boolean showUrls)
{
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java
index def87f5840..9cadf0ec3c 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java
@@ -23,6 +23,9 @@ import java.awt.Color;
import java.awt.GradientPaint;
import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.ShortTextTitle;
@@ -30,12 +33,67 @@ import org.jfree.data.general.Dataset;
public abstract class BaseChartBuilder implements ChartBuilder
{
- private static final GradientPaint BLUE_GRADIENT = new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue);
+ static final GradientPaint BLUE_GRADIENT = new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue);
- public void addCommonChartAttributes(JFreeChart chart, ChartingDefinition chartingDefinition)
+ private SeriesPainter _seriesPainter = new SeriesPainter();
+
+ private final SeriesBuilder _seriesBuilder;
+
+ protected BaseChartBuilder(SeriesBuilder seriesBuilder)
+ {
+ _seriesBuilder = seriesBuilder;
+ }
+
+ @Override
+ public JFreeChart buildChart(ChartingDefinition chartingDefinition)
+ {
+ _seriesBuilder.setDatasetHolder(newDatasetHolder());
+ Dataset dataset = _seriesBuilder.build(chartingDefinition.getSeriesDefinitions());
+
+ JFreeChart chart = createChart(chartingDefinition, dataset);
+ return chart;
+ }
+
+
+ /**
+ * return a holder of an empty dataset suitable for use with the chart type
+ * returned by {@link #createChartImpl(String, String, String, Dataset, PlotOrientation, boolean, boolean, boolean)}.
+ */
+ protected abstract DatasetHolder newDatasetHolder();
+
+ /**
+ * Create a chart with the supplied parameters.
+ *
+ * For ease of implementation, the signature is intentionally similar
+ * to {@link ChartFactory}'s factory methods.
+ */
+ protected abstract JFreeChart createChartImpl(
+ String title, String xAxisTitle, String yAxisTitle,
+ final Dataset dataset,
+ PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls);
+
+ /**
+ * Create a {@link SeriesStrokeAndPaintApplier} that will be used to format a chart
+ */
+ protected abstract SeriesStrokeAndPaintApplier newStrokeAndPaintApplier();
+
+
+ private JFreeChart createChart(ChartingDefinition chartingDefinition, final Dataset dataset)
{
+ String title = chartingDefinition.getChartTitle();
+ String xAxisTitle = chartingDefinition.getXAxisTitle();
+ String yAxisTitle = chartingDefinition.getYAxisTitle();
+
+ final JFreeChart chart = createChartImpl(
+ title, xAxisTitle, yAxisTitle,
+ dataset,
+ PLOT_ORIENTATION, SHOW_LEGEND, SHOW_TOOL_TIPS, SHOW_URLS);
+
addSubtitle(chart, chartingDefinition);
- setBackgroundColour(chart);
+ chart.setBackgroundPaint(BLUE_GRADIENT);
+ _seriesPainter.applySeriesAppearance(chart, chartingDefinition.getSeriesDefinitions(), newStrokeAndPaintApplier());
+
+ return chart;
}
private void addSubtitle(JFreeChart chart, ChartingDefinition chartingDefinition)
@@ -46,13 +104,9 @@ public abstract class BaseChartBuilder implements ChartBuilder
}
}
- private void setBackgroundColour(JFreeChart chart)
+ void setSeriesPainter(SeriesPainter seriesPainter)
{
- chart.setBackgroundPaint(BLUE_GRADIENT);
+ _seriesPainter = seriesPainter;
}
- public abstract JFreeChart createChartImpl(String title, String xAxisTitle,
- String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips,
- boolean showUrls);
-
}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java
index a6c63f4560..0d08fd8ad1 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java
@@ -20,40 +20,36 @@
package org.apache.qpid.disttest.charting.chartbuilder;
-import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback;
+import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder;
import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryLabelPositions;
+import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.data.general.Dataset;
public abstract class CategoryDataSetBasedChartBuilder extends BaseChartBuilder
{
- private final SeriesBuilder _seriesBuilder;
-
public CategoryDataSetBasedChartBuilder(SeriesBuilder seriesBuilder)
{
- _seriesBuilder = seriesBuilder;
+ super(seriesBuilder);
}
@Override
- public JFreeChart buildChart(ChartingDefinition chartingDefinition)
+ protected DatasetHolder newDatasetHolder()
{
- String title = chartingDefinition.getChartTitle();
- String xAxisTitle = chartingDefinition.getXAxisTitle();
- String yAxisTitle = chartingDefinition.getYAxisTitle();
-
- final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
-
- _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback()
+ return new DatasetHolder()
{
+ final private DefaultCategoryDataset _dataset = new DefaultCategoryDataset();
+
@Override
- public void addDataPointToSeries(SeriesDefinition seriesDefinition, Object[] row)
+ public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row)
{
- String x = String.valueOf(row[0]);
- double y = Double.parseDouble(row[1].toString());
- dataset.addValue( y, seriesDefinition.getSeriesLegend(), x);
+ String x = row.dimensionAsString(0);
+ double y = row.dimensionAsDouble(1);
+ _dataset.addValue(y, seriesDefinition.getSeriesLegend(), x);
}
@Override
@@ -68,17 +64,33 @@ public abstract class CategoryDataSetBasedChartBuilder extends BaseChartBuilder
// unused
}
- });
+ @Override
+ public int getNumberOfDimensions()
+ {
+ return 2;
+ }
- _seriesBuilder.build(chartingDefinition.getSeries());
+ @Override
+ public Dataset getPopulatedDataset()
+ {
+ return _dataset;
+ }
+ };
+ }
- JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle,
- dataset, PLOT_ORIENTATION, SHOW_LEGEND, SHOW_TOOL_TIPS, SHOW_URLS);
+ @Override
+ protected SeriesStrokeAndPaintApplier newStrokeAndPaintApplier()
+ {
+ return new CategoryStrokeAndPaintApplier();
+ }
+ @Override
+ protected final JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ JFreeChart chart = createCategoryChart(title, xAxisTitle, yAxisTitle, dataset, plotOrientation, showLegend, showToolTips, showUrls);
chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
-
- addCommonChartAttributes(chart, chartingDefinition);
-
return chart;
}
+
+ protected abstract JFreeChart createCategoryChart(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls);
}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryStrokeAndPaintApplier.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryStrokeAndPaintApplier.java
new file mode 100644
index 0000000000..cbf5cbe515
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryStrokeAndPaintApplier.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.disttest.charting.chartbuilder;
+
+import java.awt.Color;
+import java.awt.Stroke;
+
+import org.jfree.chart.JFreeChart;
+
+class CategoryStrokeAndPaintApplier implements SeriesStrokeAndPaintApplier
+{
+ @Override
+ public void setSeriesStroke(int seriesIndex, Stroke stroke, JFreeChart targetChart)
+ {
+ targetChart.getCategoryPlot().getRenderer().setSeriesStroke(seriesIndex, stroke);
+ }
+
+ @Override
+ public void setSeriesPaint(int seriesIndex, Color colour, JFreeChart targetChart)
+ {
+ targetChart.getCategoryPlot().getRenderer().setSeriesPaint(seriesIndex, colour);
+ }
+} \ No newline at end of file
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java
index f4e11a2c4d..63a0573676 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java
@@ -39,8 +39,10 @@ public class ChartBuilderFactory
return new BarChart3DBuilder(seriesBuilder);
case XYLINE:
return new XYLineChartBuilder(seriesBuilder);
+ case TIMELINE:
+ return new TimeSeriesLineChartBuilder(seriesBuilder);
case STATISTICAL_BAR:
- return new StatisticalBarCharBuilder(seriesBuilder);
+ return new StatisticalBarChartBuilder(seriesBuilder);
default:
throw new IllegalArgumentException("Unknown chart type " + chartType);
}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ColorFactory.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ColorFactory.java
new file mode 100644
index 0000000000..49d777c506
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ColorFactory.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.disttest.charting.chartbuilder;
+
+import java.awt.Color;
+
+public class ColorFactory
+{
+ /**
+ * Converts a colour name known to the JDK into a {@link Color} instance. Additionally,
+ * if the work dark_ is prepended to the colour, a darker shade of the same colour is
+ * produced.
+ *
+ * @param colourName
+ * @return colour instance
+ */
+ public static Color toColour(String colourName)
+ {
+ boolean darkVersion = false;
+ if (colourName.toLowerCase().startsWith("dark_"))
+ {
+ colourName = colourName.replaceFirst("(?i)dark_", "");
+ darkVersion = true;
+ }
+
+ Color colour = getColourFromStaticField(colourName);
+ if (darkVersion)
+ {
+ return colour.darker();
+ }
+ else
+ {
+ return colour;
+ }
+ }
+
+ private static Color getColourFromStaticField(String colourName)
+ {
+ try
+ {
+ return (Color) Color.class.getField(colourName.toLowerCase()).get(null);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not find colour for " + colourName, e);
+ }
+ }
+
+}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java
index 27fff12da0..b92a25f5ac 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java
@@ -34,7 +34,7 @@ public class LineChart3DBuilder extends CategoryDataSetBasedChartBuilder
}
@Override
- public JFreeChart createChartImpl(String title, String xAxisTitle,
+ protected JFreeChart createCategoryChart(String title, String xAxisTitle,
String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
boolean showLegend, boolean showToolTips, boolean showUrls)
{
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java
index 40f3a09b6b..3f5b18acda 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java
@@ -35,7 +35,7 @@ public class LineChartBuilder extends CategoryDataSetBasedChartBuilder
}
@Override
- public JFreeChart createChartImpl(String title, String xAxisTitle,
+ protected JFreeChart createCategoryChart(String title, String xAxisTitle,
String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
boolean showLegend, boolean showToolTips, boolean showUrls)
{
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesPainter.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesPainter.java
new file mode 100644
index 0000000000..854635dc87
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesPainter.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.disttest.charting.chartbuilder;
+
+import java.awt.BasicStroke;
+import java.util.List;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.jfree.chart.JFreeChart;
+
+public class SeriesPainter
+{
+ public void applySeriesAppearance(JFreeChart chart, List<SeriesDefinition> seriesDefinitions, SeriesStrokeAndPaintApplier strokeAndPaintApplier)
+ {
+ for (int i = 0; i < seriesDefinitions.size(); i++)
+ {
+ SeriesDefinition seriesDefinition = seriesDefinitions.get(i);
+ if (seriesDefinition.getSeriesColourName() != null)
+ {
+ strokeAndPaintApplier.setSeriesPaint(i, ColorFactory.toColour(seriesDefinition.getSeriesColourName()), chart);
+ }
+ if (seriesDefinition.getStrokeWidth() != null)
+ {
+ // Negative width used to signify dashed
+ boolean dashed = seriesDefinition.getStrokeWidth() < 0;
+ float width = Math.abs(seriesDefinition.getStrokeWidth());
+ BasicStroke stroke = buildStrokeOfWidth(width, dashed);
+ strokeAndPaintApplier.setSeriesStroke(i, stroke, chart);
+ }
+ }
+ }
+
+ private BasicStroke buildStrokeOfWidth(float width, boolean dashed)
+ {
+ final BasicStroke stroke;
+ if (dashed)
+ {
+ stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {5.0f, 3.0f}, 0.0f);
+ }
+ else
+ {
+ stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
+ }
+ return stroke;
+ }
+}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesStrokeAndPaintApplier.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesStrokeAndPaintApplier.java
new file mode 100644
index 0000000000..4d6c37a9f4
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesStrokeAndPaintApplier.java
@@ -0,0 +1,35 @@
+/*
+ * 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.disttest.charting.chartbuilder;
+
+import java.awt.Color;
+import java.awt.Stroke;
+
+import org.jfree.chart.JFreeChart;
+
+/**
+ * Applies the supplied stroke and color to a series in the target chart.
+ * Multiple implementations exist to because of the various chart types.
+ */
+public interface SeriesStrokeAndPaintApplier
+{
+ void setSeriesStroke(int seriesIndex, Stroke stroke, JFreeChart targetChart);
+ void setSeriesPaint(int seriesIndex, Color color, JFreeChart targetChart);
+}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java
deleted file mode 100644
index 86c3f62e09..0000000000
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java
+++ /dev/null
@@ -1,111 +0,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.
- *
- */
-package org.apache.qpid.disttest.charting.chartbuilder;
-
-import java.awt.Font;
-
-import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
-import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
-import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.axis.CategoryAxis;
-import org.jfree.chart.axis.CategoryLabelPositions;
-import org.jfree.chart.axis.NumberAxis;
-import org.jfree.chart.axis.ValueAxis;
-import org.jfree.chart.plot.CategoryPlot;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.renderer.category.CategoryItemRenderer;
-import org.jfree.chart.renderer.category.StatisticalBarRenderer;
-import org.jfree.data.general.Dataset;
-import org.jfree.data.statistics.DefaultStatisticalCategoryDataset;
-import org.jfree.data.statistics.StatisticalCategoryDataset;
-
-public class StatisticalBarCharBuilder extends BaseChartBuilder
-{
- private final SeriesBuilder _seriesBuilder;
-
- public StatisticalBarCharBuilder(SeriesBuilder seriesBuilder)
- {
- _seriesBuilder = seriesBuilder;
- }
-
- @Override
- public JFreeChart buildChart(ChartingDefinition chartingDefinition)
- {
- String title = chartingDefinition.getChartTitle();
- String xAxisTitle = chartingDefinition.getXAxisTitle();
- String yAxisTitle = chartingDefinition.getYAxisTitle();
-
- final DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset();
-
- _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback()
- {
- @Override
- public void addDataPointToSeries(SeriesDefinition seriesDefinition, Object[] row)
- {
- String x = String.valueOf(row[0]);
- double mean = Double.parseDouble(row[1].toString());
- double stdDev = Double.parseDouble(row[2].toString());
- dataset.add(mean, stdDev, seriesDefinition.getSeriesLegend(), x);
- }
-
- @Override
- public void beginSeries(SeriesDefinition seriesDefinition)
- {
- // unused
- }
-
- @Override
- public void endSeries(SeriesDefinition seriesDefinition)
- {
- // unused
- }
-
- });
-
- _seriesBuilder.build(chartingDefinition.getSeries());
-
- JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle, dataset, PLOT_ORIENTATION, SHOW_LEGEND,
- SHOW_TOOL_TIPS, SHOW_URLS);
-
- chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
-
- addCommonChartAttributes(chart, chartingDefinition);
-
- return chart;
- }
-
- @Override
- public JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset,
- PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls)
- {
- CategoryAxis xAxis = new CategoryAxis(xAxisTitle);
- ValueAxis yAxis = new NumberAxis(yAxisTitle);
- CategoryItemRenderer renderer = new StatisticalBarRenderer();
-
- CategoryPlot plot = new CategoryPlot((StatisticalCategoryDataset) dataset, xAxis, yAxis, renderer);
-
- JFreeChart chart = new JFreeChart(title, new Font("Arial", Font.PLAIN, 10), plot, true);
- return chart;
- }
-
-}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarChartBuilder.java
new file mode 100644
index 0000000000..c5ad2d7dad
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarChartBuilder.java
@@ -0,0 +1,114 @@
+/*
+ *
+ * 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.disttest.charting.chartbuilder;
+
+import java.awt.Font;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.CategoryAxis;
+import org.jfree.chart.axis.CategoryLabelPositions;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.plot.CategoryPlot;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.chart.renderer.category.CategoryItemRenderer;
+import org.jfree.chart.renderer.category.StatisticalBarRenderer;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.statistics.DefaultStatisticalCategoryDataset;
+import org.jfree.data.statistics.StatisticalCategoryDataset;
+
+public class StatisticalBarChartBuilder extends BaseChartBuilder
+{
+ public StatisticalBarChartBuilder(SeriesBuilder seriesBuilder)
+ {
+ super(seriesBuilder);
+ }
+
+ @Override
+ protected DatasetHolder newDatasetHolder()
+ {
+ return new DatasetHolder()
+ {
+ private final DefaultStatisticalCategoryDataset _dataset = new DefaultStatisticalCategoryDataset();
+
+ @Override
+ public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row)
+ {
+ String x = row.dimensionAsString(0);
+ double mean = row.dimensionAsDouble(1);
+ double stdDev = row.dimensionAsDouble(2);
+ _dataset.add(mean, stdDev, seriesDefinition.getSeriesLegend(), x);
+ }
+
+ @Override
+ public void beginSeries(SeriesDefinition seriesDefinition)
+ {
+ // unused
+ }
+
+ @Override
+ public void endSeries(SeriesDefinition seriesDefinition)
+ {
+ // unused
+ }
+
+ @Override
+ public int getNumberOfDimensions()
+ {
+ return 3;
+ }
+
+ @Override
+ public Dataset getPopulatedDataset()
+ {
+ return _dataset;
+ }
+ };
+ }
+
+ @Override
+ protected SeriesStrokeAndPaintApplier newStrokeAndPaintApplier()
+ {
+ return new CategoryStrokeAndPaintApplier();
+ }
+
+ @Override
+ public JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset,
+ PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ CategoryAxis xAxis = new CategoryAxis(xAxisTitle);
+ ValueAxis yAxis = new NumberAxis(yAxisTitle);
+ CategoryItemRenderer renderer = new StatisticalBarRenderer();
+
+ CategoryPlot plot = new CategoryPlot((StatisticalCategoryDataset) dataset, xAxis, yAxis, renderer);
+
+ JFreeChart chart = new JFreeChart(title, new Font("Arial", Font.PLAIN, 10), plot, true);
+
+ chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
+
+ return chart;
+ }
+
+}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesHolder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesHolder.java
new file mode 100644
index 0000000000..803a098dfa
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesHolder.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.disttest.charting.chartbuilder;
+
+import java.util.Date;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.time.Millisecond;
+import org.jfree.data.time.RegularTimePeriod;
+import org.jfree.data.time.TimeSeries;
+import org.jfree.data.time.TimeSeriesCollection;
+
+class TimeSeriesHolder implements DatasetHolder
+{
+ private final TimeSeriesCollection _timeSeriesCollection = new TimeSeriesCollection();
+ private TimeSeries _timeSeries;
+
+ @Override
+ public void beginSeries(SeriesDefinition seriesDefinition)
+ {
+ _timeSeries = new TimeSeries(seriesDefinition.getSeriesLegend());
+ }
+
+ @Override
+ public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row)
+ {
+ Date x = row.dimensionAsDate(0);
+ double y = row.dimensionAsDouble(1);
+ RegularTimePeriod jfreeChartDate = new Millisecond(x);
+ _timeSeries.add(jfreeChartDate, y);
+ }
+
+ @Override
+ public void endSeries(SeriesDefinition seriesDefinition)
+ {
+ _timeSeriesCollection.addSeries(_timeSeries);
+ }
+
+ @Override
+ public int getNumberOfDimensions()
+ {
+ return 2;
+ }
+
+ @Override
+ public Dataset getPopulatedDataset()
+ {
+ return _timeSeriesCollection;
+ }
+} \ No newline at end of file
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesLineChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesLineChartBuilder.java
new file mode 100644
index 0000000000..7249ae6332
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesLineChartBuilder.java
@@ -0,0 +1,59 @@
+/*
+ * 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.disttest.charting.chartbuilder;
+
+import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.xy.XYDataset;
+
+public class TimeSeriesLineChartBuilder extends XYDataSetBasedChartBuilder
+{
+ public TimeSeriesLineChartBuilder(SeriesBuilder seriesBuilder)
+ {
+ super(seriesBuilder);
+ }
+
+ @Override
+ protected DatasetHolder newDatasetHolder()
+ {
+ return new TimeSeriesHolder();
+ }
+
+ @Override
+ public JFreeChart createChartImpl(String title, String xAxisTitle,
+ String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
+ boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ JFreeChart chart = ChartFactory.createTimeSeriesChart(
+ title,
+ xAxisTitle,
+ yAxisTitle,
+ (XYDataset)dataset,
+ showLegend,
+ showToolTips,
+ showUrls);
+
+ return chart;
+ }
+}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java
index 87d61ca2ee..575712f06c 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java
@@ -19,38 +19,34 @@
*/
package org.apache.qpid.disttest.charting.chartbuilder;
+import java.awt.Color;
+import java.awt.Stroke;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback;
+import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder;
import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow;
import org.jfree.chart.JFreeChart;
-import org.jfree.chart.axis.CategoryLabelPositions;
+import org.jfree.data.general.Dataset;
import org.jfree.data.xy.DefaultXYDataset;
public abstract class XYDataSetBasedChartBuilder extends BaseChartBuilder
{
- private final SeriesBuilder _seriesBuilder;
-
public XYDataSetBasedChartBuilder(SeriesBuilder seriesBuilder)
{
- this._seriesBuilder = seriesBuilder;
+ super(seriesBuilder);
}
@Override
- public JFreeChart buildChart(ChartingDefinition chartingDefinition)
+ protected DatasetHolder newDatasetHolder()
{
- String title = chartingDefinition.getChartTitle();
- String xAxisTitle = chartingDefinition.getXAxisTitle();
- String yAxisTitle = chartingDefinition.getYAxisTitle();
-
- final DefaultXYDataset dataset = new DefaultXYDataset();
- _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback()
+ return new DatasetHolder()
{
+ private final DefaultXYDataset _dataset = new DefaultXYDataset();
private List<Double[]> _xyPairs = null;
@Override
@@ -60,20 +56,24 @@ public abstract class XYDataSetBasedChartBuilder extends BaseChartBuilder
}
@Override
- public void addDataPointToSeries(SeriesDefinition seriesDefinition,
- Object[] row)
+ public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row)
{
- double x = Double.parseDouble(row[0].toString());
- double y = Double.parseDouble(row[1].toString());
+ double x = row.dimensionAsDouble(0);
+ double y = row.dimensionAsDouble(1);
_xyPairs.add(new Double[] {x, y});
}
-
@Override
public void endSeries(SeriesDefinition seriesDefinition)
{
double[][] seriesData = listToSeriesDataArray();
- dataset.addSeries(seriesDefinition.getSeriesLegend(), seriesData);
+ _dataset.addSeries(seriesDefinition.getSeriesLegend(), seriesData);
+ }
+
+ @Override
+ public int getNumberOfDimensions()
+ {
+ return 2;
}
private double[][] listToSeriesDataArray()
@@ -86,18 +86,34 @@ public abstract class XYDataSetBasedChartBuilder extends BaseChartBuilder
seriesData[0][i] = xyPair[0];
seriesData[1][i] = xyPair[1];
i++;
- }
+ }
return seriesData;
}
- });
-
- _seriesBuilder.build(chartingDefinition.getSeries());
- JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle,
- dataset, PLOT_ORIENTATION, SHOW_LEGEND, SHOW_TOOL_TIPS, SHOW_URLS);
+ @Override
+ public Dataset getPopulatedDataset()
+ {
+ return _dataset;
+ }
+ };
+ }
- addCommonChartAttributes(chart, chartingDefinition);
+ @Override
+ protected SeriesStrokeAndPaintApplier newStrokeAndPaintApplier()
+ {
+ return new SeriesStrokeAndPaintApplier()
+ {
+ @Override
+ public void setSeriesStroke(int seriesIndex, Stroke stroke, JFreeChart targetChart)
+ {
+ targetChart.getXYPlot().getRenderer().setSeriesStroke(seriesIndex, stroke);
+ }
- return chart;
+ @Override
+ public void setSeriesPaint(int seriesIndex, Color colour, JFreeChart targetChart)
+ {
+ targetChart.getXYPlot().getRenderer().setSeriesPaint(seriesIndex, colour);
+ }
+ };
}
}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java
index 04b3f7ed3b..bfe47e598e 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java
@@ -30,6 +30,7 @@ public class ChartingDefinition
private final ChartType _chartType;
private final String _chartTitle;
private final String _chartSubtitle;
+ private final String _chartDescription;
private final String _xaxisTitle;
private final String _yaxisTitle;
private final List<SeriesDefinition> _seriesDefinitions;
@@ -39,12 +40,14 @@ public class ChartingDefinition
final ChartType chartType,
final String chartTitle,
final String chartSubtitle,
+ final String chartDescription,
final String xaxisTitle, final String yaxisTitle, List<SeriesDefinition> seriesDefinitions)
{
_chartStemName = chartStemName;
_chartType = chartType;
_chartTitle = chartTitle;
_chartSubtitle = chartSubtitle;
+ _chartDescription = chartDescription;
_xaxisTitle = xaxisTitle;
_yaxisTitle = yaxisTitle;
_seriesDefinitions = seriesDefinitions;
@@ -65,6 +68,10 @@ public class ChartingDefinition
return _chartSubtitle;
}
+ public String getChartDescription()
+ {
+ return _chartDescription;
+ }
public String getXAxisTitle()
{
@@ -77,17 +84,14 @@ public class ChartingDefinition
return _yaxisTitle;
}
-
-
public ChartType getChartType()
{
return _chartType;
}
- public List<SeriesDefinition> getSeries()
+ public List<SeriesDefinition> getSeriesDefinitions()
{
return Collections.unmodifiableList(_seriesDefinitions);
}
-
}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java
index 4cbc9318a9..1988f561b6 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java
@@ -39,6 +39,7 @@ public class ChartingDefinitionCreator
public static final String CHART_TYPE_KEY = "chartType";
public static final String CHART_TITLE_KEY = "chartTitle";
public static final String CHART_SUBTITLE_KEY = "chartSubtitle";
+ public static final String CHART_DESCRIPTION_KEY = "chartDescription";
public static final String XAXIS_TITLE_KEY = "xAxisTitle";
public static final String YAXIS_TITLE_KEY = "yAxisTitle";
@@ -82,6 +83,7 @@ public class ChartingDefinitionCreator
final ChartType chartType = ChartType.valueOf(props.getProperty(CHART_TYPE_KEY));
final String chartTitle = props.getProperty(CHART_TITLE_KEY);
final String chartSubtitle = props.getProperty(CHART_SUBTITLE_KEY);
+ final String chartDescription = props.getProperty(CHART_DESCRIPTION_KEY);
final String xAxisTitle = props.getProperty(XAXIS_TITLE_KEY);
final String yAxisTitle = props.getProperty(YAXIS_TITLE_KEY);
@@ -91,8 +93,8 @@ public class ChartingDefinitionCreator
chartType,
chartTitle,
chartSubtitle,
- xAxisTitle,
- yAxisTitle, seriesDefinitions);
+ chartDescription,
+ xAxisTitle, yAxisTitle, seriesDefinitions);
return chartDefinition;
}
catch (IOException e)
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java
index a39e906957..d89ff855e2 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinition.java
@@ -19,17 +19,24 @@
*/
package org.apache.qpid.disttest.charting.definition;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
public class SeriesDefinition
{
private final String _seriesStatement;
private final String _seriesLegend;
private final String _seriesDirectory;
+ private final String _seriesColourName;
+ private final Integer _seriesStrokeWidth;
- public SeriesDefinition(String seriesStatement, String seriesLegend, String seriesDirectory)
+ public SeriesDefinition(String seriesStatement, String seriesLegend, String seriesDirectory, String seriesColourName, Integer seriesStrokeWidth)
{
_seriesStatement = seriesStatement;
_seriesLegend = seriesLegend;
_seriesDirectory = seriesDirectory;
+ _seriesColourName = seriesColourName;
+ _seriesStrokeWidth = seriesStrokeWidth;
}
public String getSeriesStatement()
@@ -47,4 +54,22 @@ public class SeriesDefinition
return _seriesDirectory;
}
+ public String getSeriesColourName()
+ {
+ return _seriesColourName;
+ }
+
+ public Integer getStrokeWidth()
+ {
+ return _seriesStrokeWidth;
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("seriesLegend", _seriesLegend)
+ .append("seriesStatement", _seriesStatement)
+ .append("seriesDirectory", _seriesDirectory).toString();
+ }
}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java
index fcc11807c8..d47e7488e1 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreator.java
@@ -30,6 +30,8 @@ public class SeriesDefinitionCreator
public static final String SERIES_STATEMENT_KEY_FORMAT = "series.%d.statement";
public static final String SERIES_LEGEND_KEY_FORMAT = "series.%d.legend";
public static final String SERIES_DIRECTORY_KEY_FORMAT = "series.%d.dir";
+ public static final String SERIES_COLOUR_NAME_FORMAT = "series.%d.colourName";
+ public static final String SERIES_STROKE_WIDTH_FORMAT = "series.%d.strokeWidth";
public List<SeriesDefinition> createFromProperties(Properties properties)
{
@@ -42,10 +44,13 @@ public class SeriesDefinitionCreator
String seriesStatement = properties.getProperty(String.format(SERIES_STATEMENT_KEY_FORMAT, index));
String seriesLegend = properties.getProperty(String.format(SERIES_LEGEND_KEY_FORMAT, index));
String seriesDir = StrSubstitutor.replaceSystemProperties(properties.getProperty(String.format(SERIES_DIRECTORY_KEY_FORMAT, index)));
+ String seriesColourName = properties.getProperty(String.format(SERIES_COLOUR_NAME_FORMAT, index));
+ Integer seriesStrokeWidth = properties.getProperty(String.format(SERIES_STROKE_WIDTH_FORMAT, index)) == null
+ ? null : Integer.parseInt(properties.getProperty(String.format(SERIES_STROKE_WIDTH_FORMAT, index)));
if (seriesStatement != null)
{
- final SeriesDefinition seriesDefinition = new SeriesDefinition(seriesStatement, seriesLegend, seriesDir);
+ final SeriesDefinition seriesDefinition = new SeriesDefinition(seriesStatement, seriesLegend, seriesDir, seriesColourName, seriesStrokeWidth);
seriesDefinitions.add(seriesDefinition);
}
else
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/DatasetHolder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/DatasetHolder.java
new file mode 100644
index 0000000000..14fd50facc
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/DatasetHolder.java
@@ -0,0 +1,37 @@
+/*
+ * 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.disttest.charting.seriesbuilder;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.jfree.data.general.Dataset;
+
+/**
+ * Accepts data in the form of {@link SeriesDefinition}s and {@link SeriesRow}s,
+ * and returns it as a {@link Dataset} for use by a JFreeChart chart.
+ */
+public interface DatasetHolder
+{
+ int getNumberOfDimensions();
+ void beginSeries(SeriesDefinition seriesDefinition);
+ void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row);
+ void endSeries(SeriesDefinition seriesDefinition);
+
+ Dataset getPopulatedDataset();
+}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilder.java
deleted file mode 100644
index a9adce0afc..0000000000
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilder.java
+++ /dev/null
@@ -1,141 +0,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.
- *
- */
-package org.apache.qpid.disttest.charting.seriesbuilder;
-
-import java.io.File;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.qpid.disttest.charting.ChartingException;
-import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-
-public class JdbcCsvSeriesBuilder implements SeriesBuilder
-{
-
- static
- {
- registerCsvDriver();
- }
-
- private SeriesBuilderCallback _callback;
-
- @Override
- public void setSeriesBuilderCallback(SeriesBuilderCallback callback)
- {
- this._callback = callback;
- }
-
- @Override
- public void build(List<SeriesDefinition> seriesDefinitions)
- {
- for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();)
- {
- SeriesDefinition series = iterator.next();
- buildDataSetForSingleSeries(series);
- }
- }
-
- private void buildDataSetForSingleSeries(SeriesDefinition seriesDefinition)
- {
- Connection conn = null;
- Statement stmt = null;
- try
- {
- File seriesDir = getValidatedSeriesDirectory(seriesDefinition);
-
- conn = DriverManager.getConnection("jdbc:relique:csv:" + seriesDir.getAbsolutePath());
-
- final String seriesStatement = seriesDefinition.getSeriesStatement();
-
- stmt = conn.createStatement();
- ResultSet results = stmt.executeQuery(seriesStatement);
- int columnCount = results.getMetaData().getColumnCount();
- _callback.beginSeries(seriesDefinition);
- while (results.next())
- {
- Object[] row = new Object[columnCount];
- for (int i = 0; i < row.length; i++)
- {
- row[i] = results.getObject(i+1);
- }
-
- _callback.addDataPointToSeries(seriesDefinition, row);
- }
- _callback.endSeries(seriesDefinition);
- }
- catch (SQLException e)
- {
- throw new ChartingException("Failed to create chart dataset", e);
- }
- finally
- {
- if (stmt != null)
- {
- try
- {
- stmt.close();
- }
- catch (SQLException e)
- {
- throw new RuntimeException("Failed to close statement", e);
- }
- }
- if (conn != null)
- {
- try
- {
- conn.close();
- }
- catch (SQLException e)
- {
- throw new RuntimeException("Failed to close connection", e);
- }
- }
- }
- }
-
- private File getValidatedSeriesDirectory(SeriesDefinition series)
- {
- File seriesDir = new File(series.getSeriesDirectory());
- if (!seriesDir.isDirectory())
- {
- throw new ChartingException("seriesDirectory must be a directory : " + seriesDir);
- }
- return seriesDir;
- }
-
- private static void registerCsvDriver() throws ExceptionInInitializerError
- {
- try
- {
- Class.forName("org.relique.jdbc.csv.CsvDriver");
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException("Could not load CSV/JDBC driver", e);
- }
- }
-
-}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java
new file mode 100644
index 0000000000..180aa54c6d
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilder.java
@@ -0,0 +1,157 @@
+/*
+ * 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.disttest.charting.seriesbuilder;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.qpid.disttest.charting.ChartingException;
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.jfree.data.general.Dataset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A {@link SeriesBuilder} that uses JDBC to read series data.
+ * The actual JDBC URL used is determined by my {@link JdbcUrlGenerator}.
+ */
+public class JdbcSeriesBuilder implements SeriesBuilder
+{
+ private static final Logger LOGGER = LoggerFactory.getLogger(JdbcSeriesBuilder.class);
+
+ private DatasetHolder _datasetHolder;
+
+ private final JdbcUrlGenerator _jdbcUrlGenerator;
+
+ /**
+ * @param providedJdbcUrl the JDBC URL. Provide null if the value should be
+ * inferred by {@link #_jdbcUrlGenerator}.
+ */
+ public JdbcSeriesBuilder(String jdbcDriverClass, String providedJdbcUrl)
+ {
+ registerDriver(jdbcDriverClass);
+ _jdbcUrlGenerator = new JdbcUrlGenerator(providedJdbcUrl);
+ LOGGER.info("Created: " + this);
+ }
+
+ @Override
+ public void setDatasetHolder(DatasetHolder callback)
+ {
+ _datasetHolder = callback;
+ }
+
+ @Override
+ public Dataset build(List<SeriesDefinition> seriesDefinitions)
+ {
+ for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();)
+ {
+ SeriesDefinition series = iterator.next();
+ buildDataSetForSingleSeries(series);
+ }
+ return _datasetHolder.getPopulatedDataset();
+ }
+
+ private void buildDataSetForSingleSeries(SeriesDefinition seriesDefinition)
+ {
+ Connection conn = null;
+ Statement stmt = null;
+ try
+ {
+ String jdbcUrl = _jdbcUrlGenerator.getJdbcUrl(seriesDefinition);
+ conn = DriverManager.getConnection(jdbcUrl);
+
+ final String seriesStatement = seriesDefinition.getSeriesStatement();
+
+ stmt = conn.createStatement();
+ ResultSet results = stmt.executeQuery(seriesStatement);
+ int columnCount = results.getMetaData().getColumnCount();
+ _datasetHolder.beginSeries(seriesDefinition);
+ while (results.next())
+ {
+ Object[] row = new Object[columnCount];
+ for (int i = 0; i < row.length; i++)
+ {
+ row[i] = results.getObject(i+1);
+ }
+
+ SeriesRow seriesRow = SeriesRow.createValidSeriesRow(_datasetHolder.getNumberOfDimensions(), row);
+ _datasetHolder.addDataPointToSeries(seriesDefinition, seriesRow);
+ }
+ _datasetHolder.endSeries(seriesDefinition);
+ }
+ catch (SQLException e)
+ {
+ throw new ChartingException("Failed to create chart dataset", e);
+ }
+ finally
+ {
+ if (stmt != null)
+ {
+ try
+ {
+ stmt.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException("Failed to close statement", e);
+ }
+ }
+ if (conn != null)
+ {
+ try
+ {
+ conn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RuntimeException("Failed to close connection", e);
+ }
+ }
+ }
+ }
+
+ private void registerDriver(String driverClassName) throws ExceptionInInitializerError
+ {
+ try
+ {
+ Class.forName(driverClassName);
+ LOGGER.info("Loaded JDBC driver class " + driverClassName);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Could not load JDBC driver " + driverClassName, e);
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("jdbcUrlGenerator", _jdbcUrlGenerator)
+ .toString();
+ }
+}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGenerator.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGenerator.java
new file mode 100644
index 0000000000..77f367b0f1
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGenerator.java
@@ -0,0 +1,81 @@
+/*
+ * 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.disttest.charting.seriesbuilder;
+
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+
+public class JdbcUrlGenerator
+{
+ private String _providedJdbdUrl;
+
+ public static final String DEFAULT_JDBC_DRIVER_NAME = "org.relique.jdbc.csv.CsvDriver";
+
+ /**
+ * Used to create the JDBC URL if one has not been passed in.
+ */
+ private static final String CSV_JDBC_URL_BASE = "jdbc:relique:csv:";
+
+ /**
+ * @param providedJdbcUrl the JDBC URL. Provide null if the value should be
+ * inferred.
+ */
+ public JdbcUrlGenerator(String providedJdbcUrl)
+ {
+ _providedJdbdUrl = providedJdbcUrl;
+ }
+
+ /**
+ * Returns either the provided value ({@link #_providedJdbdUrl})
+ * or a CSV JDBC URL pointing at {@link SeriesDefinition#getSeriesDirectory()} value.
+ */
+ public String getJdbcUrl(SeriesDefinition seriesDefinition)
+ {
+ String seriesDir = seriesDefinition.getSeriesDirectory();
+
+ if(_providedJdbdUrl == null)
+ {
+ if(isBlank(seriesDir))
+ {
+ throw new IllegalArgumentException("Neither a series directory nor a JDBC url have been specified. Series definition: " + seriesDefinition);
+ }
+ return CSV_JDBC_URL_BASE + seriesDir;
+ }
+ else
+ {
+ if(isNotBlank(seriesDir))
+ {
+ throw new IllegalArgumentException("Both a series directory '" + seriesDir + "' and a JDBC url have been specified. Series definition: " + seriesDefinition);
+ }
+ return _providedJdbdUrl;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("providedJdbdUrl", _providedJdbdUrl)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java
index 86e471efaf..a865c838c6 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java
@@ -22,11 +22,20 @@ package org.apache.qpid.disttest.charting.seriesbuilder;
import java.util.List;
import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.jfree.data.general.Dataset;
public interface SeriesBuilder
{
- void build(List<SeriesDefinition> seriesDefinitions);
-
- void setSeriesBuilderCallback(SeriesBuilderCallback seriesBuilderCallback);
+ /**
+ * Uses the supplied {@link SeriesDefinition}s to read the series data
+ * and pass it to the dataset holder set up in {@link #setDatasetHolder(DatasetHolder)}.
+ *
+ * @return the populated dataset
+ */
+ Dataset build(List<SeriesDefinition> seriesDefinitions);
+ /**
+ * Stores the supplied dataset holder so it can be populated in {@link #build(List)}.
+ */
+ void setDatasetHolder(DatasetHolder datasetHolder);
} \ No newline at end of file
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java
deleted file mode 100644
index 7e23953fdb..0000000000
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java
+++ /dev/null
@@ -1,30 +0,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.
- *
- */
-package org.apache.qpid.disttest.charting.seriesbuilder;
-
-import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-
-public interface SeriesBuilderCallback
-{
- public void beginSeries(SeriesDefinition seriesDefinition);
- public void addDataPointToSeries(SeriesDefinition seriesDefinition, Object[] row);
- public void endSeries(SeriesDefinition seriesDefinition);
-
-}
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRow.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRow.java
new file mode 100644
index 0000000000..9c16866939
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRow.java
@@ -0,0 +1,98 @@
+/*
+ * 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.disttest.charting.seriesbuilder;
+
+import java.util.Arrays;
+import java.util.Date;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+/**
+ * A data point in a chart. Thinly wraps an array to provide a convenient place to validate the number of dimensions,
+ * and to access dimensions in a typesafe manner.
+ */
+public class SeriesRow
+{
+ private final Object[] _dimensions;
+
+ public static SeriesRow createValidSeriesRow(int expectedNumberOfDimensions, Object[] dimensions)
+ {
+ int actualNumberOfDimensions = dimensions.length;
+ if(expectedNumberOfDimensions != actualNumberOfDimensions)
+ {
+ throw new IllegalArgumentException("Expected " + expectedNumberOfDimensions
+ + " dimensions but found " + actualNumberOfDimensions
+ + " in: " + Arrays.asList(dimensions));
+ }
+ return new SeriesRow(dimensions);
+ }
+
+ public SeriesRow(Object... dimensions)
+ {
+ _dimensions = dimensions;
+ }
+
+ public Object dimension(int dimension)
+ {
+ return _dimensions[dimension];
+ }
+
+ public String dimensionAsString(int dimension)
+ {
+ return String.valueOf(dimension(dimension));
+ }
+
+ public double dimensionAsDouble(int dimension)
+ {
+ return Double.parseDouble(dimensionAsString(dimension));
+ }
+
+ public Date dimensionAsDate(int dimension)
+ {
+ return (Date) dimension(dimension);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder().append(_dimensions).toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj.getClass() != getClass())
+ {
+ return false;
+ }
+ SeriesRow rhs = (SeriesRow) obj;
+ return new EqualsBuilder().append(_dimensions, rhs._dimensions).isEquals();
+ }
+
+
+} \ No newline at end of file
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java
index 5d4a9b6b7e..341f01ccd1 100644
--- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java
+++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java
@@ -26,10 +26,11 @@ import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.SortedMap;
+import java.util.TreeMap;
import org.apache.qpid.disttest.charting.ChartingException;
+import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.slf4j.Logger;
@@ -42,19 +43,19 @@ public class ChartWriter
static final String SUMMARY_FILE_NAME = "chart-summary.html";
private File _chartDirectory = new File(".");
- private SortedSet<File> _chartFiles = new TreeSet<File>();
+ private SortedMap<File,ChartingDefinition> _chartFilesToChartDef = new TreeMap<File, ChartingDefinition>();
- public void writeChartToFileSystem(JFreeChart chart, String chartStemName)
+ public void writeChartToFileSystem(JFreeChart chart, ChartingDefinition chartDef)
{
OutputStream pngOutputStream = null;
try
{
- File pngFile = new File(_chartDirectory, chartStemName + ".png");
+ File pngFile = new File(_chartDirectory, chartDef.getChartStemName() + ".png");
pngOutputStream = new BufferedOutputStream(new FileOutputStream(pngFile));
ChartUtilities.writeChartAsPNG(pngOutputStream, chart, 600, 400, true, 0);
pngOutputStream.close();
- _chartFiles.add(pngFile);
+ _chartFilesToChartDef.put(pngFile, chartDef);
LOGGER.info("Written {} chart", pngFile);
}
@@ -78,20 +79,21 @@ public class ChartWriter
}
}
- public void writeHtmlSummaryToFileSystem()
+ public void writeHtmlSummaryToFileSystem(String summaryPageTitle)
{
- if(_chartFiles.size() < 2)
+ if(_chartFilesToChartDef.size() < 2)
{
- LOGGER.info("Only " + _chartFiles.size() + " chart image(s) have been written so no HTML summary file will be produced");
+ LOGGER.info("Only {} chart image(s) have been written so no HTML summary file will be produced", _chartFilesToChartDef.size());
return;
}
- String htmlHeader =
+ String htmlHeader = String.format(
"<html>\n" +
" <head>\n" +
- " <title>Performance Charts</title>\n" +
+ " <title>%s</title>\n" +
+ " <style type='text/css'>figure { float: left; display: table; width: 87px;}</style>\n" +
" </head>\n" +
- " <body>\n";
+ " <body>\n", summaryPageTitle);
String htmlFooter =
" </body>\n" +
@@ -101,22 +103,29 @@ public class ChartWriter
try
{
File summaryFile = new File(_chartDirectory, SUMMARY_FILE_NAME);
- LOGGER.debug("About to produce HTML summary file " + summaryFile.getAbsolutePath() + " from charts " + _chartFiles);
+ LOGGER.debug("About to produce HTML summary file " + summaryFile.getAbsolutePath() + " from charts " + _chartFilesToChartDef);
writer = new BufferedWriter(new FileWriter(summaryFile));
writer.write(htmlHeader);
writer.write(" <ul>\n");
- for (File chartFile : _chartFiles)
+ for (File chartFile : _chartFilesToChartDef.keySet())
{
writer.write(" <li><a href='#"+ chartFile.getName() +"'>" + chartFile.getName() + "</a></li>\n");
}
writer.write(" </ul>\n");
- for (File chartFile : _chartFiles)
+ for (File chartFile : _chartFilesToChartDef.keySet())
{
- writer.write(" <a name='" + chartFile.getName() + "'/>\n");
- writer.write(" <img src='" + chartFile.getName() + "'/>\n");
+ ChartingDefinition def = _chartFilesToChartDef.get(chartFile);
+ writer.write(" <figure>\n");
+ writer.write(" <a name='" + chartFile.getName() + "'/>\n");
+ writer.write(" <img src='" + chartFile.getName() + "'/>\n");
+ if (def.getChartDescription() != null)
+ {
+ writer.write(" <figcaption>" + def.getChartDescription() + "</figcaption>\n");
+ }
+ writer.write(" </figure>\n");
}
writer.write(htmlFooter);
writer.close();
@@ -144,5 +153,6 @@ public class ChartWriter
public void setOutputDirectory(final File chartDirectory)
{
_chartDirectory = chartDirectory;
+ LOGGER.info("Set chart directory: {}", chartDirectory);
}
}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilderTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilderTest.java
new file mode 100644
index 0000000000..c8a98aafa0
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilderTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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.disttest.charting.chartbuilder;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.CategoryPlot;
+import org.jfree.chart.plot.Plot;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.chart.title.TextTitle;
+import org.jfree.data.general.Dataset;
+
+public class BaseChartBuilderTest extends QpidTestCase
+{
+ private static final String CHART_TITLE = "CHART_TITLE";
+ private static final String CHART_SUB_TITLE = "CHART_SUB_TITLE";
+ private static final String X_TITLE = "X_TITLE";
+ private static final String Y_TITLE = "Y_TITLE";
+
+ @SuppressWarnings("unchecked")
+ private List<SeriesDefinition> _seriesDefinitions = mock(List.class);
+
+ private ChartingDefinition _chartingDefinition = mock(ChartingDefinition.class);
+ private SeriesStrokeAndPaintApplier _strokeAndPaintApplier = mock(SeriesStrokeAndPaintApplier.class);
+ private DatasetHolder _datasetHolder = mock(DatasetHolder.class);
+ private SeriesPainter _seriesPainter = mock(SeriesPainter.class);
+
+ private SeriesBuilder _seriesBuilder = mock(SeriesBuilder.class);
+
+ private JFreeChart _jFreeChart;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ Plot plot = new CategoryPlot();
+ _jFreeChart = new JFreeChart(plot);
+
+ when(_chartingDefinition.getChartTitle()).thenReturn(CHART_TITLE);
+ when(_chartingDefinition.getChartSubtitle()).thenReturn(CHART_SUB_TITLE);
+ when(_chartingDefinition.getXAxisTitle()).thenReturn(X_TITLE);
+ when(_chartingDefinition.getYAxisTitle()).thenReturn(Y_TITLE);
+ when(_chartingDefinition.getSeriesDefinitions()).thenReturn(_seriesDefinitions );
+ }
+
+ public void testBuildChart()
+ {
+ BaseChartBuilder chartBuilder = new ChartBuilder(_seriesBuilder, _strokeAndPaintApplier, _datasetHolder)
+ {
+ @Override
+ protected JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ assertEquals(CHART_TITLE, title);
+ assertEquals(X_TITLE, xAxisTitle);
+ assertEquals(Y_TITLE, yAxisTitle);
+
+ return _jFreeChart;
+ }
+ };
+
+ JFreeChart chart = chartBuilder.buildChart(_chartingDefinition);
+
+ assertEquals(BaseChartBuilder.BLUE_GRADIENT, chart.getBackgroundPaint());
+ assertEquals("The *second* subtitle of the generated chart should have the text from the chart definition",
+ CHART_SUB_TITLE, ((TextTitle)chart.getSubtitle(1)).getText());
+ verify(_seriesPainter).applySeriesAppearance(_jFreeChart, _seriesDefinitions, _strokeAndPaintApplier);
+ }
+
+ /**
+ * Extends BaseChartBuilder to allow us to plug in in mock dependencies
+ */
+ private abstract class ChartBuilder extends BaseChartBuilder
+ {
+ private SeriesStrokeAndPaintApplier _seriesStrokeAndPaintApplier;
+ private DatasetHolder _datasetHolder;
+
+ private ChartBuilder(SeriesBuilder seriesBuilder, SeriesStrokeAndPaintApplier seriesStrokeAndPaintApplier, DatasetHolder datasetHolder)
+ {
+ super(seriesBuilder);
+ _seriesStrokeAndPaintApplier = seriesStrokeAndPaintApplier;
+ _datasetHolder = datasetHolder;
+ setSeriesPainter(_seriesPainter);
+ }
+
+ @Override
+ protected SeriesStrokeAndPaintApplier newStrokeAndPaintApplier()
+ {
+ return _seriesStrokeAndPaintApplier;
+ }
+
+ @Override
+ protected DatasetHolder newDatasetHolder()
+ {
+ return _datasetHolder;
+ }
+ }
+}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java
index e735fb58c6..14f81566a6 100644
--- a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java
@@ -19,14 +19,13 @@
*/
package org.apache.qpid.disttest.charting.chartbuilder;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
import org.apache.qpid.disttest.charting.ChartType;
import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.apache.qpid.test.utils.QpidTestCase;
-import junit.framework.TestCase;
-
-public class ChartBuilderFactoryTest extends TestCase
+public class ChartBuilderFactoryTest extends QpidTestCase
{
private SeriesBuilder _seriesBuilder = mock(SeriesBuilder.class);
@@ -59,4 +58,10 @@ public class ChartBuilderFactoryTest extends TestCase
ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.XYLINE, _seriesBuilder);
assertTrue(builder instanceof XYLineChartBuilder);
}
+
+ public void testTimeSeriesLineChart()
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.TIMELINE, _seriesBuilder);
+ assertTrue(builder instanceof TimeSeriesLineChartBuilder);
+ }
}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java
index 2744e17404..7af3a6b35e 100644
--- a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java
@@ -19,33 +19,35 @@
*/
package org.apache.qpid.disttest.charting.chartbuilder;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.File;
import java.util.Collections;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.apache.qpid.disttest.charting.ChartType;
import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback;
+import org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder;
import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow;
import org.apache.qpid.disttest.charting.writer.ChartWriter;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.test.utils.TestFileUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.title.ShortTextTitle;
-
-import junit.framework.TestCase;
+import org.jfree.data.general.Dataset;
/**
* Tests the production of the different chart types. To manually
* verify the generated output, set the system property {@link #RETAIN_TEST_CHARTS}
* to prevent the automatic deletion of the test chart directory.
- *
*/
-public class ChartProductionTest extends TestCase
+public class ChartProductionTest extends QpidTestCase
{
private static final String TEST_CHARTTITLE = "TEST_CHARTTITLE";
private static final String TEST_CHARTSUBTITLE = "TEST_CHARTSUBTITLE";
@@ -54,6 +56,16 @@ public class ChartProductionTest extends TestCase
private static final String TEST_SERIESLEGEND = "TEST_SERIESLEGEND";
+ private static final SeriesRow[] SIMPLE_SERIES_ROWS = new SeriesRow[]
+ {
+ new SeriesRow(1d, 1d),
+ new SeriesRow(2d, 2d),
+ new SeriesRow(3d, 3d),
+ new SeriesRow(4d, 4d),
+ new SeriesRow(5d, 5d),
+ new SeriesRow(6d, 6d),
+ };
+
private static final String RETAIN_TEST_CHARTS = "retainTestCharts";
private SeriesDefinition _seriesDefinition = mock(SeriesDefinition.class);
@@ -66,12 +78,15 @@ public class ChartProductionTest extends TestCase
super.setUp();
when(_seriesDefinition.getSeriesLegend()).thenReturn(TEST_SERIESLEGEND);
+ when(_seriesDefinition.getStrokeWidth()).thenReturn(null);
+ when(_seriesDefinition.getSeriesColourName()).thenReturn(null);
+ when(_chartingDefinition.getChartStemName()).thenReturn(getName());
when(_chartingDefinition.getChartTitle()).thenReturn(TEST_CHARTTITLE);
when(_chartingDefinition.getChartSubtitle()).thenReturn(TEST_CHARTSUBTITLE);
when(_chartingDefinition.getXAxisTitle()).thenReturn(TEST_XAXIS);
when(_chartingDefinition.getYAxisTitle()).thenReturn(TEST_YAXIS);
- when(_chartingDefinition.getSeries()).thenReturn(Collections.singletonList(_seriesDefinition));
+ when(_chartingDefinition.getSeriesDefinitions()).thenReturn(Collections.singletonList(_seriesDefinition));
File chartDir = TestFileUtils.createTestDirectory("charts", false);
if (!System.getProperties().containsKey(RETAIN_TEST_CHARTS))
@@ -88,7 +103,7 @@ public class ChartProductionTest extends TestCase
public void testBarChart() throws Exception
{
- ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR, new SampleSeriesBuilder());
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR, new SampleSeriesBuilder(SIMPLE_SERIES_ROWS));
assertChartTitlesAndWriteToFile(builder);
}
@@ -116,36 +131,47 @@ public class ChartProductionTest extends TestCase
assertChartTitlesAndWriteToFile(builder);
}
- public void testStatiscticalBarChart() throws Exception
+ public void testXYLineChartWithColourAndWidth() throws Exception
+ {
+ when(_seriesDefinition.getStrokeWidth()).thenReturn(3);
+ when(_seriesDefinition.getSeriesColourName()).thenReturn("dark_orange");
+
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.XYLINE, new SampleSeriesBuilder());
+ assertChartTitlesAndWriteToFile(builder);
+ }
+
+ public void testTimeSeriesLineChart() throws Exception
{
+ SeriesRow[] timelineSeriesRows = new SeriesRow[]
+ {
+ new SeriesRow(new Date(1), 1d),
+ new SeriesRow(new Date(2), 2d),
+ new SeriesRow(new Date(3), 3d),
+ new SeriesRow(new Date(4), 4d),
+ new SeriesRow(new Date(5), 5d),
+ new SeriesRow(new Date(6), 6d),
+ };
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(
+ ChartType.TIMELINE,
+ new SampleSeriesBuilder(timelineSeriesRows));
+
+ assertChartTitlesAndWriteToFile(builder);
+ }
+
+ public void testStatisticalBarChart() throws Exception
+ {
+ SeriesRow[] statisticalSeriesRows = new SeriesRow[]
+ {
+ new SeriesRow(1d, 1d, 0.5d),
+ new SeriesRow(2d, 2d, 0.4d),
+ new SeriesRow(4d, 4d, 0.3d),
+ new SeriesRow(5d, 5d, 0.2d),
+ new SeriesRow(6d, 6d, 0.1d)
+ };
+
ChartBuilder builder = ChartBuilderFactory.createChartBuilder(
ChartType.STATISTICAL_BAR,
- new SeriesBuilder()
- {
- private SeriesBuilderCallback _dataPointCallback;
-
- @Override
- public void build(List<SeriesDefinition> seriesDefinitions)
- {
- for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();)
- {
- SeriesDefinition seriesDefinition = iterator.next();
- _dataPointCallback.beginSeries(seriesDefinition);
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{1d, 1d, 0.5d});
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{2d, 2d, 0.4d});
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{4d, 4d, 0.3d});
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{5d, 5d, 0.2d});
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{6d, 3d, 0.1d});
- _dataPointCallback.endSeries(seriesDefinition);
- }
- }
-
- @Override
- public void setSeriesBuilderCallback(SeriesBuilderCallback dataPointCallback)
- {
- _dataPointCallback = dataPointCallback;
- }
- });
+ new SampleSeriesBuilder(statisticalSeriesRows));
assertChartTitlesAndWriteToFile(builder);
}
@@ -166,33 +192,43 @@ public class ChartProductionTest extends TestCase
assertEquals(1, chart.getCategoryPlot().getDatasetCount());
}
- _writer.writeChartToFileSystem(chart, getName());
+ _writer.writeChartToFileSystem(chart, _chartingDefinition);
}
private class SampleSeriesBuilder implements SeriesBuilder
{
- private SeriesBuilderCallback _dataPointCallback;
+ private DatasetHolder _datasetHolder;
+ private SeriesRow[] _sampleSeriesRows = SIMPLE_SERIES_ROWS;
+
+ public SampleSeriesBuilder()
+ {
+ }
+
+ public SampleSeriesBuilder(SeriesRow[] sampleSeriesRows)
+ {
+ _sampleSeriesRows = sampleSeriesRows;
+ }
@Override
- public void build(List<SeriesDefinition> seriesDefinitions)
+ public Dataset build(List<SeriesDefinition> seriesDefinitions)
{
for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();)
{
SeriesDefinition seriesDefinition = iterator.next();
- _dataPointCallback.beginSeries(seriesDefinition);
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{1d, 1d});
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{2d, 2d});
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{4d, 4d});
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{5d, 5d});
- _dataPointCallback.addDataPointToSeries(seriesDefinition, new Object[]{6d, 3d});
- _dataPointCallback.endSeries(seriesDefinition);
+ _datasetHolder.beginSeries(seriesDefinition);
+ for(SeriesRow seriesRow : _sampleSeriesRows)
+ {
+ _datasetHolder.addDataPointToSeries(seriesDefinition, seriesRow);
+ }
+ _datasetHolder.endSeries(seriesDefinition);
}
+ return _datasetHolder.getPopulatedDataset();
}
@Override
- public void setSeriesBuilderCallback(SeriesBuilderCallback dataPointCallback)
+ public void setDatasetHolder(DatasetHolder dataPointCallback)
{
- _dataPointCallback = dataPointCallback;
+ _datasetHolder = dataPointCallback;
}
}
}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ColorFactoryTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ColorFactoryTest.java
new file mode 100644
index 0000000000..2656c780bb
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ColorFactoryTest.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.disttest.charting.chartbuilder;
+
+import java.awt.Color;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class ColorFactoryTest extends QpidTestCase
+{
+ public void testBlue()
+ {
+ assertEquals(Color.blue, ColorFactory.toColour("blue"));
+ assertEquals(Color.blue, ColorFactory.toColour("BLUE"));
+ assertEquals(Color.blue, ColorFactory.toColour("Blue"));
+ }
+
+ public void testDarkBlue()
+ {
+ assertEquals(Color.blue.darker(), ColorFactory.toColour("dark_blue"));
+ assertEquals(Color.blue.darker(), ColorFactory.toColour("DARK_BLUE"));
+ assertEquals(Color.blue.darker(), ColorFactory.toColour("Dark_Blue"));
+ }
+
+} \ No newline at end of file
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesBuilderCallbackTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesBuilderCallbackTest.java
new file mode 100644
index 0000000000..cb89511389
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/TimeSeriesBuilderCallbackTest.java
@@ -0,0 +1,72 @@
+package org.apache.qpid.disttest.charting.chartbuilder;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.jfree.data.time.TimeSeries;
+import org.jfree.data.time.TimeSeriesCollection;
+import org.jfree.data.time.TimeSeriesDataItem;
+
+public class TimeSeriesBuilderCallbackTest extends QpidTestCase
+{
+ private static final String SERIES_LEGEND = "mySeriesLegend";
+
+ private static final int NUMBER_OF_DATA_POINTS = 3;
+
+ private Date[] _dates;
+ private double[] _values;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+00:00"));
+
+ calendar.set(2013, Calendar.JANUARY, 1);
+ Date jan1 = calendar.getTime();
+
+ calendar.set(2013, Calendar.JANUARY, 2);
+ Date jan2 = calendar.getTime();
+
+ calendar.set(2013, Calendar.JANUARY, 3);
+ Date jan3 = calendar.getTime();
+
+ _dates = new Date[] {jan1, jan2, jan3};
+ _values = new double[] {2.0, 4.0, 8.0};
+ }
+
+
+ public void testAddPointToSeries()
+ {
+ TimeSeriesHolder timeSeriesHolder = new TimeSeriesHolder();
+
+ SeriesDefinition seriesDefinition = mock(SeriesDefinition.class);
+ when(seriesDefinition.getSeriesLegend()).thenReturn(SERIES_LEGEND);
+
+ timeSeriesHolder.beginSeries(seriesDefinition);
+
+ timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[0], _values[0]));
+ timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[1], _values[1]));
+ timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[2], _values[2]));
+
+ timeSeriesHolder.endSeries(seriesDefinition);
+
+ TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) timeSeriesHolder.getPopulatedDataset();
+
+ TimeSeries actualTimeSeries = timeSeriesCollection.getSeries(SERIES_LEGEND);
+ for(int i = 0; i < NUMBER_OF_DATA_POINTS; i++)
+ {
+ TimeSeriesDataItem dataItem0 = actualTimeSeries.getDataItem(i);
+ assertEquals(_dates[i].getTime(), dataItem0.getPeriod().getMiddleMillisecond());
+ assertEquals(_values[i], dataItem0.getValue());
+ }
+ }
+
+}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java
index 5371f3df45..e4b4d4d272 100644
--- a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java
@@ -19,8 +19,9 @@
*/
package org.apache.qpid.disttest.charting.definition;
-import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TITLE_KEY;
+import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_DESCRIPTION_KEY;
import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_SUBTITLE_KEY;
+import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TITLE_KEY;
import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TYPE_KEY;
import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.XAXIS_TITLE_KEY;
import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.YAXIS_TITLE_KEY;
@@ -31,15 +32,15 @@ import java.io.FileWriter;
import java.util.List;
import java.util.Properties;
-import junit.framework.TestCase;
-
import org.apache.qpid.disttest.charting.ChartType;
import org.apache.qpid.disttest.charting.ChartingException;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ChartingDefinitionCreatorTest extends TestCase
+public class ChartingDefinitionCreatorTest extends QpidTestCase
{
private static final String TEST_CHART_TITLE = "CHART_TITLE";
private static final String TEST_CHART_SUBTITLE = "CHART_SUBTITLE";
+ private static final String TEST_CHART_DESCRIPTION = "CHART_DESCRIPTION";
private static final String TEST_XAXIS_TITLE = "XAXIS_TITLE";
private static final String TEST_YAXIS_TITLE = "YAXIS_TITLE";
private static final ChartType TEST_CHART_TYPE = ChartType.LINE;
@@ -86,6 +87,7 @@ public class ChartingDefinitionCreatorTest extends TestCase
ChartingDefinition definition1 = definitions.get(0);
assertEquals(TEST_CHART_TITLE, definition1.getChartTitle());
assertEquals(TEST_CHART_SUBTITLE, definition1.getChartSubtitle());
+ assertEquals(TEST_CHART_DESCRIPTION, definition1.getChartDescription());
assertEquals(TEST_XAXIS_TITLE, definition1.getXAxisTitle());
assertEquals(TEST_YAXIS_TITLE, definition1.getYAxisTitle());
assertEquals(TEST_CHART_TYPE, definition1.getChartType());
@@ -93,7 +95,7 @@ public class ChartingDefinitionCreatorTest extends TestCase
String stemOnly = testDefFile.getName().replaceFirst("\\.chartdef", "");
assertEquals(stemOnly, definition1.getChartStemName());
- final List<SeriesDefinition> seriesDefinitions = definition1.getSeries();
+ final List<SeriesDefinition> seriesDefinitions = definition1.getSeriesDefinitions();
assertEquals(1, seriesDefinitions.size());
SeriesDefinition seriesDefinition = seriesDefinitions.get(0);
assertEquals(TEST_SERIES_SELECT_STATEMENT, seriesDefinition.getSeriesStatement());
@@ -125,6 +127,7 @@ public class ChartingDefinitionCreatorTest extends TestCase
props.setProperty(CHART_TYPE_KEY, TEST_CHART_TYPE.name());
props.setProperty(CHART_TITLE_KEY, TEST_CHART_TITLE);
props.setProperty(CHART_SUBTITLE_KEY, TEST_CHART_SUBTITLE);
+ props.setProperty(CHART_DESCRIPTION_KEY, TEST_CHART_DESCRIPTION);
props.setProperty(XAXIS_TITLE_KEY, TEST_XAXIS_TITLE);
props.setProperty(YAXIS_TITLE_KEY, TEST_YAXIS_TITLE);
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java
index 2187793c53..ef605024cc 100644
--- a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java
@@ -19,20 +19,24 @@
*/
package org.apache.qpid.disttest.charting.definition;
+import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_COLOUR_NAME_FORMAT;
import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_DIRECTORY_KEY_FORMAT;
import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_LEGEND_KEY_FORMAT;
import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_STATEMENT_KEY_FORMAT;
+import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_STROKE_WIDTH_FORMAT;
import java.util.List;
import java.util.Properties;
-import junit.framework.TestCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class SeriesDefinitionCreatorTest extends TestCase
+public class SeriesDefinitionCreatorTest extends QpidTestCase
{
private static final String TEST_SERIES_1_SELECT_STATEMENT = "SERIES_1_SELECT_STATEMENT";
private static final String TEST_SERIES_1_LEGEND = "SERIES_1_LEGEND";
private static final String TEST_SERIES_1_DIR = "SERIES_1_DIR";
+ private static final String TEST_SERIES_1_COLOUR_NAME = "seriesColourName";
+ private static final Integer TEST_SERIES_1_STROKE_WIDTH = 1;;
private static final String TEST_SERIES_1_DIR_WITH_SYSPROP = "${java.io.tmpdir}/mydir";
@@ -52,7 +56,7 @@ public class SeriesDefinitionCreatorTest extends TestCase
public void testOneSeriesDefinition() throws Exception
{
- createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR);
+ createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR, TEST_SERIES_1_COLOUR_NAME, TEST_SERIES_1_STROKE_WIDTH);
List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties);
assertEquals(1, definitions.size());
@@ -61,12 +65,14 @@ public class SeriesDefinitionCreatorTest extends TestCase
assertEquals(TEST_SERIES_1_SELECT_STATEMENT, definition.getSeriesStatement());
assertEquals(TEST_SERIES_1_LEGEND, definition.getSeriesLegend());
assertEquals(TEST_SERIES_1_DIR, definition.getSeriesDirectory());
+ assertEquals(TEST_SERIES_1_COLOUR_NAME, definition.getSeriesColourName());
+ assertEquals(TEST_SERIES_1_STROKE_WIDTH, definition.getStrokeWidth());
}
public void testTwoSeriesDefinitions() throws Exception
{
- createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR);
- createTestProperties(2, TEST_SERIES_2_SELECT_STATEMENT, TEST_SERIES_2_LEGEND, TEST_SERIES_2_DIR);
+ createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR, TEST_SERIES_1_COLOUR_NAME, TEST_SERIES_1_STROKE_WIDTH);
+ createTestProperties(2, TEST_SERIES_2_SELECT_STATEMENT, TEST_SERIES_2_LEGEND, TEST_SERIES_2_DIR, null, null);
List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties);
assertEquals(2, definitions.size());
@@ -84,8 +90,8 @@ public class SeriesDefinitionCreatorTest extends TestCase
public void testNonSequentialSeriesDefinitionsIgnored() throws Exception
{
- createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR);
- createTestProperties(3, TEST_SERIES_2_SELECT_STATEMENT, TEST_SERIES_2_LEGEND, TEST_SERIES_2_DIR);
+ createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR, TEST_SERIES_1_COLOUR_NAME, TEST_SERIES_1_STROKE_WIDTH);
+ createTestProperties(3, TEST_SERIES_2_SELECT_STATEMENT, TEST_SERIES_2_LEGEND, TEST_SERIES_2_DIR, null, null);
List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties);
assertEquals(1, definitions.size());
@@ -94,7 +100,7 @@ public class SeriesDefinitionCreatorTest extends TestCase
public void testSeriesDirectorySubstitution() throws Exception
{
final String tmpDir = System.getProperty("java.io.tmpdir");
- createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR_WITH_SYSPROP);
+ createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR_WITH_SYSPROP, null, null);
List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties);
assertEquals(1, definitions.size());
@@ -103,11 +109,19 @@ public class SeriesDefinitionCreatorTest extends TestCase
assertTrue(seriesDefinition1.getSeriesDirectory().startsWith(tmpDir));
}
- private void createTestProperties(int index, String selectStatement, String seriesLegend, String seriesDir) throws Exception
+ private void createTestProperties(int index, String selectStatement, String seriesLegend, String seriesDir, String seriesColourName, Integer seriesStrokeWidth) throws Exception
{
_properties.setProperty(String.format(SERIES_STATEMENT_KEY_FORMAT, index), selectStatement);
_properties.setProperty(String.format(SERIES_LEGEND_KEY_FORMAT, index), seriesLegend);
_properties.setProperty(String.format(SERIES_DIRECTORY_KEY_FORMAT, index), seriesDir);
+ if (seriesColourName != null)
+ {
+ _properties.setProperty(String.format(SERIES_COLOUR_NAME_FORMAT, index), seriesColourName);
+ }
+ if (seriesStrokeWidth != null)
+ {
+ _properties.setProperty(String.format(SERIES_STROKE_WIDTH_FORMAT, index), seriesStrokeWidth.toString());
+ }
}
}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilderTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilderTest.java
deleted file mode 100644
index 5148a25bec..0000000000
--- a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilderTest.java
+++ /dev/null
@@ -1,94 +0,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.
- *
- */
-package org.apache.qpid.disttest.charting.seriesbuilder;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.util.Collections;
-
-import junit.framework.TestCase;
-
-import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-import org.apache.qpid.disttest.charting.seriesbuilder.JdbcCsvSeriesBuilder;
-
-public class JdbcCsvSeriesBuilderTest extends TestCase
-{
- private static final String TEST_SERIES_1_SELECT_STATEMENT = "SELECT A, B FROM test";
- private static final String TEST_SERIES_1_LEGEND = "SERIES_1_LEGEND";
-
- private SeriesBuilderCallback _seriesWalkerCallback = mock(SeriesBuilderCallback.class);
- private JdbcCsvSeriesBuilder _seriesBuilder = new JdbcCsvSeriesBuilder();
-
- private File _testTempDir;
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- _seriesBuilder.setSeriesBuilderCallback(_seriesWalkerCallback);
- _testTempDir = createTestTemporaryDirectory();
- }
-
- public void testBuildOneSeries() throws Exception
- {
- createTestCsvIn(_testTempDir);
- SeriesDefinition seriesDefinition = createTestSeriesDefinition();
-
- _seriesBuilder.build(Collections.singletonList(seriesDefinition));
-
- verify(_seriesWalkerCallback).beginSeries(seriesDefinition);
- verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, new Object[]{"elephant", "2"});
- verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, new Object[]{"lion", "3"});
- verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, new Object[]{"tiger", "4"});
- verify(_seriesWalkerCallback).endSeries(seriesDefinition);
- }
-
- private void createTestCsvIn(File testDir) throws Exception
- {
- File csv = new File(_testTempDir, "test.csv");
-
- PrintWriter csvWriter = new PrintWriter(new BufferedWriter(new FileWriter(csv)));
- csvWriter.println("A,B");
- csvWriter.println("elephant,2");
- csvWriter.println("lion,3");
- csvWriter.println("tiger,4");
- csvWriter.close();
- }
-
- private SeriesDefinition createTestSeriesDefinition()
- {
- SeriesDefinition definition = new SeriesDefinition(TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, _testTempDir.getAbsolutePath());
- return definition;
- }
-
- private File createTestTemporaryDirectory() throws Exception
- {
- File tmpDir = new File(System.getProperty("java.io.tmpdir"), "testdef" + System.nanoTime());
- tmpDir.mkdirs();
- tmpDir.deleteOnExit();
- return tmpDir;
- }
-
-}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java
new file mode 100644
index 0000000000..b6b4dbe56b
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcSeriesBuilderTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.seriesbuilder;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.Collections;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class JdbcSeriesBuilderTest extends QpidTestCase
+{
+ private static final String TEST_SERIES_1_SELECT_STATEMENT = "SELECT A, B FROM test";
+ private static final String TEST_SERIES_1_LEGEND = "SERIES_1_LEGEND";
+ private static final String TEST_SERIES1_COLOUR_NAME = "blue";
+ private static final Integer TEST_SERIES1_STROKE_WIDTH = 3;
+
+ private DatasetHolder _seriesWalkerCallback = mock(DatasetHolder.class);
+
+ private File _testTempDir;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ when(_seriesWalkerCallback.getNumberOfDimensions()).thenReturn(2);
+ _testTempDir = createTestTemporaryDirectory();
+ createTestCsvIn(_testTempDir);
+ }
+
+ public void testBuildOneSeries() throws Exception
+ {
+ SeriesDefinition seriesDefinition = createTestSeriesDefinition();
+
+ JdbcSeriesBuilder seriesBuilder = new JdbcSeriesBuilder("org.relique.jdbc.csv.CsvDriver", null);
+
+ seriesBuilder.setDatasetHolder(_seriesWalkerCallback);
+
+ seriesBuilder.build(Collections.singletonList(seriesDefinition));
+
+ verify(_seriesWalkerCallback).beginSeries(seriesDefinition);
+ verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, new SeriesRow("elephant", "2"));
+ verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, new SeriesRow("lion", "3"));
+ verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, new SeriesRow("tiger", "4"));
+ verify(_seriesWalkerCallback).endSeries(seriesDefinition);
+ }
+
+ private void createTestCsvIn(File testDir) throws Exception
+ {
+ File csv = new File(_testTempDir, "test.csv");
+
+ PrintWriter csvWriter = new PrintWriter(new BufferedWriter(new FileWriter(csv)));
+ csvWriter.println("A,B");
+ csvWriter.println("elephant,2");
+ csvWriter.println("lion,3");
+ csvWriter.println("tiger,4");
+ csvWriter.close();
+ }
+
+ private SeriesDefinition createTestSeriesDefinition()
+ {
+ SeriesDefinition definition = new SeriesDefinition(
+ TEST_SERIES_1_SELECT_STATEMENT,
+ TEST_SERIES_1_LEGEND,
+ _testTempDir.getAbsolutePath(),
+ TEST_SERIES1_COLOUR_NAME,
+ TEST_SERIES1_STROKE_WIDTH);
+ return definition;
+ }
+
+ private File createTestTemporaryDirectory() throws Exception
+ {
+ File tmpDir = new File(System.getProperty("java.io.tmpdir"), "testdef" + System.nanoTime());
+ tmpDir.mkdirs();
+ tmpDir.deleteOnExit();
+ return tmpDir;
+ }
+
+}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGeneratorTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGeneratorTest.java
new file mode 100644
index 0000000000..d53d0ccfe1
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcUrlGeneratorTest.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.disttest.charting.seriesbuilder;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class JdbcUrlGeneratorTest extends QpidTestCase
+{
+ public void testGetJdbcUrlWithoutProvidingAUrlReturnsCsvUrlWithCorrectDirectory()
+ {
+ JdbcUrlGenerator jdbcUrlGenerator = new JdbcUrlGenerator(null);
+ SeriesDefinition seriesDefinition = mock(SeriesDefinition.class);
+ when(seriesDefinition.getSeriesDirectory()).thenReturn("mydir");
+
+ String jdbcUrl = jdbcUrlGenerator.getJdbcUrl(seriesDefinition);
+
+ assertEquals("jdbc:relique:csv:mydir", jdbcUrl);
+ }
+
+ public void testGetJdbcUrlReturnsProvidedUrl()
+ {
+ String urlTemplate = "urlTemplate";
+ JdbcUrlGenerator jdbcUrlGenerator = new JdbcUrlGenerator(urlTemplate);
+ SeriesDefinition seriesDefinition = mock(SeriesDefinition.class);
+
+ String jdbcUrl = jdbcUrlGenerator.getJdbcUrl(seriesDefinition);
+
+ assertEquals(urlTemplate, jdbcUrl);
+ }
+
+ public void testGetJdbcUrlThrowsExceptionIfUrlProvidedAndSeriesDirectorySpecified()
+ {
+ String urlTemplate = "urlTemplate";
+ JdbcUrlGenerator jdbcUrlGenerator = new JdbcUrlGenerator(urlTemplate);
+ SeriesDefinition seriesDefinition = mock(SeriesDefinition.class);
+ when(seriesDefinition.getSeriesDirectory()).thenReturn("mydir");
+
+ try
+ {
+ jdbcUrlGenerator.getJdbcUrl(seriesDefinition);
+ fail("Expected exception not thrown");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // pass
+ }
+ }
+
+ public void testGetJdbcUrlThrowsExceptionWithoutAProvidedUrlOrSeriesDirectory()
+ {
+ JdbcUrlGenerator jdbcUrlGenerator = new JdbcUrlGenerator(null);
+ SeriesDefinition seriesDefinition = mock(SeriesDefinition.class);
+ when(seriesDefinition.getSeriesDirectory()).thenReturn(null);
+
+ try
+ {
+ jdbcUrlGenerator.getJdbcUrl(seriesDefinition);
+ fail("Expected exception not thrown");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // pass
+ }
+ }
+}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRowTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRowTest.java
new file mode 100644
index 0000000000..064971aa35
--- /dev/null
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesRowTest.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.disttest.charting.seriesbuilder;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class SeriesRowTest extends QpidTestCase
+{
+ private static final Integer[] PAIR = new Integer[] {10, 11};
+
+ public void testValidSeriesRow()
+ {
+ assertEquals(11, SeriesRow.createValidSeriesRow(2, PAIR).dimension(1));
+ }
+
+ public void testValidSeriesRowThrowsExceptionIfArrayTooSmall()
+ {
+ try
+ {
+ SeriesRow.createValidSeriesRow(1, PAIR);
+ fail("Expected exception not thrown");
+ }
+ catch(IllegalArgumentException e)
+ {
+ // pass
+ }
+ }
+
+ public void testDimension()
+ {
+ SeriesRow seriesRow = new SeriesRow(10, 11);
+ assertEquals(10, seriesRow.dimension(0));
+ assertEquals(11, seriesRow.dimension(1));
+ }
+
+ public void testDimensionAsString()
+ {
+ SeriesRow seriesRow = new SeriesRow(10);
+ assertEquals("10", seriesRow.dimensionAsString(0));
+ }
+
+ public void testDimensionAsDouble()
+ {
+ SeriesRow seriesRow = new SeriesRow(10.1);
+ assertEquals(10.1, seriesRow.dimensionAsDouble(0), 0.0);
+ }
+
+}
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/ChartWriterTest.java b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/ChartWriterTest.java
index 0e176d326b..9703c66e1f 100644
--- a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/ChartWriterTest.java
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/ChartWriterTest.java
@@ -20,20 +20,23 @@
*/
package org.apache.qpid.disttest.charting.writer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;
import java.util.Scanner;
-import junit.framework.TestCase;
-
+import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.test.utils.TestFileUtils;
import org.apache.qpid.util.FileUtils;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
-public class ChartWriterTest extends TestCase
+public class ChartWriterTest extends QpidTestCase
{
private JFreeChart _chart1;
private JFreeChart _chart2;
@@ -59,24 +62,34 @@ public class ChartWriterTest extends TestCase
public void testWriteChartToFileSystem()
{
+ ChartingDefinition chartDef1 = mock(ChartingDefinition.class);
+ when(chartDef1.getChartStemName()).thenReturn("chart1");
+
File chart1File = new File(_chartDir, "chart1.png");
assertFalse("chart1 png should not exist yet", chart1File.exists());
- _writer.writeChartToFileSystem(_chart1, "chart1");
+ _writer.writeChartToFileSystem(_chart1, chartDef1);
assertTrue("chart1 png does not exist", chart1File.exists());
}
public void testWriteHtmlSummaryToFileSystemOverwritingExistingFile() throws Exception
{
+ ChartingDefinition chartDef1 = mock(ChartingDefinition.class);
+ when(chartDef1.getChartStemName()).thenReturn("chart1");
+ when(chartDef1.getChartDescription()).thenReturn("chart description1");
+
+ ChartingDefinition chartDef2 = mock(ChartingDefinition.class);
+ when(chartDef2.getChartStemName()).thenReturn("chart2");
+
File summaryFile = new File(_chartDir, ChartWriter.SUMMARY_FILE_NAME);
writeDummyContentToSummaryFileToEnsureItGetsOverwritten(summaryFile);
- _writer.writeChartToFileSystem(_chart2, "chart2");
- _writer.writeChartToFileSystem(_chart1, "chart1");
+ _writer.writeChartToFileSystem(_chart2, chartDef2);
+ _writer.writeChartToFileSystem(_chart1, chartDef1);
- _writer.writeHtmlSummaryToFileSystem();
+ _writer.writeHtmlSummaryToFileSystem("Performance Charts");
InputStream expectedSummaryFileInputStream = getClass().getResourceAsStream("expected-chart-summary.html");
String expectedSummaryContent = new Scanner(expectedSummaryFileInputStream).useDelimiter("\\A").next();
@@ -87,11 +100,15 @@ public class ChartWriterTest extends TestCase
public void testWriteHtmlSummaryToFileSystemDoesNothingIfLessThanTwoCharts()
{
+ ChartingDefinition chartDef1 = mock(ChartingDefinition.class);
+ when(chartDef1.getChartStemName()).thenReturn("chart1");
+ when(chartDef1.getChartDescription()).thenReturn("chart description1");
+
File summaryFile = new File(_chartDir, ChartWriter.SUMMARY_FILE_NAME);
- _writer.writeChartToFileSystem(_chart1, "chart1");
+ _writer.writeChartToFileSystem(_chart1, chartDef1);
- _writer.writeHtmlSummaryToFileSystem();
+ _writer.writeHtmlSummaryToFileSystem("Performance Charts");
assertFalse("Only one chart generated so no summary file should have been written",
summaryFile.exists());
diff --git a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/expected-chart-summary.html b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/expected-chart-summary.html
index 89c508a77e..e7dadcb05b 100755
--- a/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/expected-chart-summary.html
+++ b/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/expected-chart-summary.html
@@ -1,15 +1,21 @@
<html>
<head>
<title>Performance Charts</title>
+ <style type='text/css'>figure { float: left; display: table; width: 87px;}</style>
</head>
<body>
<ul>
<li><a href='#chart1.png'>chart1.png</a></li>
<li><a href='#chart2.png'>chart2.png</a></li>
</ul>
- <a name='chart1.png'/>
- <img src='chart1.png'/>
- <a name='chart2.png'/>
- <img src='chart2.png'/>
+ <figure>
+ <a name='chart1.png'/>
+ <img src='chart1.png'/>
+ <figcaption>chart description1</figcaption>
+ </figure>
+ <figure>
+ <a name='chart2.png'/>
+ <img src='chart2.png'/>
+ </figure>
</body>
</html> \ No newline at end of file
diff --git a/java/systests/build.xml b/java/systests/build.xml
index 57337bdc55..dee73b2e1e 100644
--- a/java/systests/build.xml
+++ b/java/systests/build.xml
@@ -32,7 +32,9 @@ nn - or more contributor license agreements. See the NOTICE file
</or>
</condition>
- <property name="module.depends" value="client management/common broker broker/test common amqp-1-0-common common/test jca ${systests.optional.depends}"/>
+ <!-- The jca module is unusual in that it produces a jar with the name ra rather than jca. Unfortunately this means we
+ need to add both jca (finds jca's jar dependencies) and ra (to find the qpid-ra jar file itself). -->
+ <property name="module.depends" value="client management/common broker broker/tests common amqp-1-0-common common/tests jca ra broker-plugins/access-control broker-plugins/management-http broker-plugins/management-jmx ${systests.optional.depends}"/>
<property name="module.test.src" location="src/main/java"/>
<property name="module.test.excludes"
value="**/DropInTest.java,**/TestClientControlledTest.java"/>
diff --git a/java/systests/etc/config-systests-bdb-settings.xml b/java/systests/etc/config-systests-bdb-settings.xml
deleted file mode 100644
index 4fa69d0abc..0000000000
--- a/java/systests/etc/config-systests-bdb-settings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests-bdb.xml</virtualhosts>
-</broker>
-
-
diff --git a/java/systests/etc/config-systests-bdb.xml b/java/systests/etc/config-systests-bdb.xml
deleted file mode 100644
index 6b17b564a8..0000000000
--- a/java/systests/etc/config-systests-bdb.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<configuration>
- <system/>
- <override>
- <xml fileName="${QPID_HOME}/${test.config}" optional="true"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-bdb-settings.xml"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-settings.xml"/>
- </override>
-</configuration>
diff --git a/java/systests/etc/config-systests-derby-mem-settings.xml b/java/systests/etc/config-systests-derby-mem-settings.xml
deleted file mode 100644
index 69369d9ac9..0000000000
--- a/java/systests/etc/config-systests-derby-mem-settings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml</virtualhosts>
-</broker>
-
-
diff --git a/java/systests/etc/config-systests-derby-mem.xml b/java/systests/etc/config-systests-derby-mem.xml
deleted file mode 100644
index 8e40df986e..0000000000
--- a/java/systests/etc/config-systests-derby-mem.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<configuration>
- <system/>
- <override>
- <xml fileName="${QPID_HOME}/${test.config}" optional="true"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-derby-mem-settings.xml"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-settings.xml"/>
- </override>
-</configuration>
diff --git a/java/systests/etc/config-systests-derby-settings.xml b/java/systests/etc/config-systests-derby-settings.xml
deleted file mode 100644
index 3ed3a9e33b..0000000000
--- a/java/systests/etc/config-systests-derby-settings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests-derby.xml</virtualhosts>
-</broker>
-
-
diff --git a/java/systests/etc/config-systests-derby.xml b/java/systests/etc/config-systests-derby.xml
deleted file mode 100644
index 21a7a8cabe..0000000000
--- a/java/systests/etc/config-systests-derby.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<configuration>
- <system/>
- <override>
- <xml fileName="${QPID_HOME}/${test.config}" optional="true"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-derby-settings.xml"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-settings.xml"/>
- </override>
-</configuration>
diff --git a/java/systests/etc/config-systests-firewall-2.xml b/java/systests/etc/config-systests-firewall-2.xml
deleted file mode 100644
index 5167d88f12..0000000000
--- a/java/systests/etc/config-systests-firewall-2.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <prefix>${QPID_HOME}</prefix>
- <work>${QPID_WORK}</work>
- <conf>${prefix}/etc</conf>
- <plugin-directory>${QPID_HOME}/lib/plugins</plugin-directory>
- <cache-directory>${QPID_WORK}/cache</cache-directory>
- <connector>
- <!-- To enable SSL edit the keystorePath and keystorePassword
- and set enabled to true.
- To disasble Non-SSL port set sslOnly to true -->
- <ssl>
- <enabled>false</enabled>
- <port>8672</port>
- <sslOnly>false</sslOnly>
- <keyStorePath>/path/to/keystore.ks</keyStorePath>
- <keyStorePassword>keystorepass</keyStorePassword>
- </ssl>
- <port>5672</port>
- <socketReceiveBuffer>262144</socketReceiveBuffer>
- <socketSendBuffer>262144</socketSendBuffer>
- </connector>
- <management>
- <enabled>false</enabled>
- </management>
- <advanced>
- <framesize>65535</framesize>
- <locale>en_US</locale>
- </advanced>
-
- <security>
- <pd-auth-manager>
- <principal-database>
- <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
- <attributes>
- <attribute>
- <name>passwordFile</name>
- <value>${conf}/passwd</value>
- </attribute>
- </attributes>
- </principal-database>
- </pd-auth-manager>
-
- <msg-auth>false</msg-auth>
-
- <firewall default-action="deny"/>
- </security>
-
- <virtualhosts>${conf}/virtualhosts-systests-firewall-2.xml</virtualhosts>
-
- <heartbeat>
- <delay>0</delay>
- <timeoutFactor>2.0</timeoutFactor>
- </heartbeat>
- <queue>
- <auto_register>true</auto_register>
- </queue>
-
- <status-updates>ON</status-updates>
-
-</broker>
-
-
diff --git a/java/systests/etc/config-systests-firewall-3.xml b/java/systests/etc/config-systests-firewall-3.xml
deleted file mode 100644
index 2bcbf53a39..0000000000
--- a/java/systests/etc/config-systests-firewall-3.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <prefix>${QPID_HOME}</prefix>
- <work>${QPID_WORK}</work>
- <conf>${prefix}/etc</conf>
- <plugin-directory>${QPID_HOME}/lib/plugins</plugin-directory>
- <cache-directory>${QPID_WORK}/cache</cache-directory>
- <connector>
- <!-- To enable SSL edit the keystorePath and keystorePassword
- and set enabled to true.
- To disable Non-SSL port set sslOnly to true -->
- <ssl>
- <enabled>false</enabled>
- <port>8672</port>
- <sslOnly>false</sslOnly>
- <keyStorePath>/path/to/keystore.ks</keyStorePath>
- <keyStorePassword>keystorepass</keyStorePassword>
- </ssl>
- <port>5672</port>
- <socketReceiveBuffer>262144</socketReceiveBuffer>
- <socketSendBuffer>262144</socketSendBuffer>
- </connector>
- <management>
- <enabled>false</enabled>
- </management>
- <advanced>
- <framesize>65535</framesize>
- <locale>en_US</locale>
- </advanced>
-
- <security>
- <pd-auth-manager>
- <principal-database>
- <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
- <attributes>
- <attribute>
- <name>passwordFile</name>
- <value>${conf}/passwd</value>
- </attribute>
- </attributes>
- </principal-database>
- </pd-auth-manager>
-
- <msg-auth>false</msg-auth>
-
- <firewall default-action="deny">
- <rule access="allow" network="127.0.0.1"/>
- </firewall>
- </security>
-
- <virtualhosts>${conf}/virtualhosts-systests-firewall-3.xml</virtualhosts>
-
- <heartbeat>
- <delay>0</delay>
- <timeoutFactor>2.0</timeoutFactor>
- </heartbeat>
- <queue>
- <auto_register>true</auto_register>
- </queue>
-
- <status-updates>ON</status-updates>
-
-</broker>
-
-
diff --git a/java/systests/etc/config-systests-firewall-settings.xml b/java/systests/etc/config-systests-firewall-settings.xml
deleted file mode 100644
index aa73be0646..0000000000
--- a/java/systests/etc/config-systests-firewall-settings.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <security>
- <firewall>
- <rule access="allow" network="127.0.0.1"/>
- </firewall>
- </security>
-
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests-firewall.xml</virtualhosts>
-</broker>
diff --git a/java/systests/etc/config-systests-firewall.xml b/java/systests/etc/config-systests-firewall.xml
deleted file mode 100644
index a884a39614..0000000000
--- a/java/systests/etc/config-systests-firewall.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<configuration>
- <system/>
- <override>
- <xml fileName="${QPID_HOME}/${test.config}" optional="true"/>
- <xml fileName="${QPID_FIREWALL_CONFIG_SETTINGS}" optional="true"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-firewall-settings.xml"/>
- <xml fileName="${QPID_HOME}/etc/config-systests-settings.xml"/>
- </override>
-</configuration>
diff --git a/java/systests/etc/config-systests-settings.xml b/java/systests/etc/config-systests-settings.xml
deleted file mode 100644
index 0b65ad83c3..0000000000
--- a/java/systests/etc/config-systests-settings.xml
+++ /dev/null
@@ -1,103 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- -
- - 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.
- -
- -->
-<broker>
- <prefix>${QPID_HOME}</prefix>
- <work>${QPID_WORK}</work>
- <conf>${prefix}/etc</conf>
-
- <plugin-directory>${QPID_HOME}/lib/plugins</plugin-directory>
- <cache-directory>${QPID_WORK}/cache</cache-directory>
-
- <connector>
- <!-- To enable SSL edit the keystorePath and keystorePassword
- and set enabled to true.
- To disable Non-SSL port set sslOnly to true -->
- <ssl>
- <port>15671</port>
- <enabled>false</enabled>
- <sslOnly>false</sslOnly>
- <keyStorePath>${QPID_HOME}/../test-profiles/test_resources/ssl/java_broker_keystore.jks</keyStorePath>
- <keyStorePassword>password</keyStorePassword>
- </ssl>
- <port>5672</port>
- <socketReceiveBuffer>262144</socketReceiveBuffer>
- <socketSendBuffer>262144</socketSendBuffer>
- </connector>
- <management>
- <enabled>false</enabled>
- <jmxport>
- <registryServer>8999</registryServer>
- <!--
- If unspecified, connectorServer defaults to 100 + registryServer port.
- <connectorServer>9099</connectionServer>
- -->
- </jmxport>
- <ssl>
- <enabled>false</enabled>
- <keyStorePath>${QPID_HOME}/../test-profiles/test_resources/ssl/java_broker_keystore.jks</keyStorePath>
- <keyStorePassword>password</keyStorePassword>
- </ssl>
- <http>
- <enabled>false</enabled>
- </http>
- </management>
- <advanced>
- <framesize>65535</framesize>
- <locale>en_US</locale>
- </advanced>
-
- <security>
- <pd-auth-manager>
- <principal-database>
- <class>org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase</class>
- <attributes>
- <attribute>
- <name>passwordFile</name>
- <value>${conf}/passwd</value>
- </attribute>
- </attributes>
- </principal-database>
- </pd-auth-manager>
-
- <!-- By default, all authenticated users have permissions to perform all actions -->
-
- <!-- ACL Example
- This example illustrates securing the both Management (JMX) and Messaging.
- <acl>${conf}/broker_example.acl</acl>
- -->
-
- <msg-auth>false</msg-auth>
- </security>
-
- <virtualhosts>${QPID_HOME}/etc/virtualhosts-systests.xml</virtualhosts>
-
- <heartbeat>
- <delay>0</delay>
- <timeoutFactor>2.0</timeoutFactor>
- </heartbeat>
- <queue>
- <auto_register>true</auto_register>
- </queue>
-
- <status-updates>ON</status-updates>
-
-</broker>
diff --git a/java/systests/etc/config-systests.json b/java/systests/etc/config-systests.json
new file mode 100644
index 0000000000..a5b85a2050
--- /dev/null
+++ b/java/systests/etc/config-systests.json
@@ -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.
+ *
+ */
+{
+ "name": "QpidBroker",
+ "defaultAuthenticationProvider" : "plain",
+ "defaultVirtualHost" : "test",
+ "keyStorePath": "${QPID_HOME}/../test-profiles/test_resources/ssl/java_broker_keystore.jks",
+ "keyStorePassword": "password",
+ "trustStorePath": "${QPID_HOME}/../test-profiles/test_resources/ssl/java_client_truststore.jks",
+ "trustStorePassword": "password",
+ "authenticationproviders" : [ {
+ "name" : "plain",
+ "authenticationProviderType" : "PlainPasswordFileAuthenticationProvider",
+ "path" : "${QPID_HOME}/etc/passwd"
+ } ],
+ "ports" : [ {
+ "name" : "amqp",
+ "port" : "${test.port}"
+ }, {
+ "name" : "http",
+ "port" : "${test.hport}",
+ "protocols" : [ "HTTP" ]
+ }, {
+ "name" : "rmi",
+ "port" : "${test.mport}",
+ "protocols" : [ "RMI" ]
+ }, {
+ "name" : "jmx",
+ "port" : "${test.cport}",
+ "protocols" : [ "JMX_RMI" ]
+ }],
+ "virtualhosts" : [ {
+ "name" : "test",
+ "configPath" : "${broker.virtualhosts-config}"
+ } ]
+ /*
+,
+ "plugins" : [ {
+ "pluginType" : "MANAGEMENT-HTTP",
+ "name" : "httpManagement"
+ }, {
+ "pluginType" : "MANAGEMENT-JMX",
+ "name" : "jmxManagement"
+ } ]
+ */
+} \ No newline at end of file
diff --git a/java/systests/etc/groups-systests b/java/systests/etc/groups-systests
new file mode 100644
index 0000000000..e3912ece99
--- /dev/null
+++ b/java/systests/etc/groups-systests
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+#
+# To define a group, use the format:
+#
+# <groupname>.users=<user1>,<user2>,...,<usern>
+#
+
+messaging-users.users=guest,client,server
+administrators.users=admin
+webadmins.users=webadmin
+
diff --git a/java/systests/etc/virtualhosts-systests-bdb-settings.xml b/java/systests/etc/virtualhosts-systests-bdb-settings.xml
index ce16523f13..350f05c178 100644
--- a/java/systests/etc/virtualhosts-systests-bdb-settings.xml
+++ b/java/systests/etc/virtualhosts-systests-bdb-settings.xml
@@ -20,37 +20,13 @@
-
-->
<virtualhosts>
- <work>${QPID_WORK}</work>
-
- <virtualhost>
- <name>localhost</name>
- <localhost>
- <store>
- <class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>
- <environment-path>${work}/bdbstore/localhost-store</environment-path>
- </store>
- </localhost>
- </virtualhost>
-
- <virtualhost>
- <name>development</name>
- <development>
- <store>
- <class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>
- <environment-path>${work}/bdbstore/development-store</environment-path>
- </store>
- </development>
- </virtualhost>
-
<virtualhost>
<name>test</name>
<test>
<store>
<class>org.apache.qpid.server.store.berkeleydb.BDBMessageStore</class>
- <environment-path>${work}/bdbstore/test-store</environment-path>
+ <environment-path>${QPID_WORK}/test-store</environment-path>
</store>
</test>
</virtualhost>
</virtualhosts>
-
-
diff --git a/java/systests/etc/virtualhosts-systests-derby-mem-settings.xml b/java/systests/etc/virtualhosts-systests-derby-mem-settings.xml
index 74189ad5e9..4e28f6d330 100644
--- a/java/systests/etc/virtualhosts-systests-derby-mem-settings.xml
+++ b/java/systests/etc/virtualhosts-systests-derby-mem-settings.xml
@@ -20,35 +20,12 @@
-
-->
<virtualhosts>
- <directory>${QPID_HOME}/virtualhosts</directory>
- <default>test</default>
-
- <virtualhost>
- <localhost>
- <store>
- <factoryclass>org.apache.qpid.server.store.derby.DerbyMessageStoreFactory</factoryclass>
- <environment-path>:memory:</environment-path>
- </store>
- </localhost>
- </virtualhost>
-
- <virtualhost>
- <development>
- <store>
- <factoryclass>org.apache.qpid.server.store.derby.DerbyMessageStoreFactory</factoryclass>
- <environment-path>:memory:</environment-path>
- </store>
- </development>
- </virtualhost>
-
<virtualhost>
<test>
<store>
- <factoryclass>org.apache.qpid.server.store.derby.DerbyMessageStoreFactory</factoryclass>
+ <class>org.apache.qpid.server.store.derby.DerbyMessageStore</class>
<environment-path>:memory:</environment-path>
</store>
</test>
</virtualhost>
</virtualhosts>
-
-
diff --git a/java/systests/etc/virtualhosts-systests-derby-settings.xml b/java/systests/etc/virtualhosts-systests-derby-settings.xml
index 08a40ca812..f9cc3d2336 100644
--- a/java/systests/etc/virtualhosts-systests-derby-settings.xml
+++ b/java/systests/etc/virtualhosts-systests-derby-settings.xml
@@ -20,35 +20,12 @@
-
-->
<virtualhosts>
- <directory>${QPID_HOME}/virtualhosts</directory>
- <default>test</default>
-
- <virtualhost>
- <localhost>
- <store>
- <class>org.apache.qpid.server.store.derby.DerbyMessageStore</class>
- <environment-path>${QPID_WORK}/derbyDB/localhost-store</environment-path>
- </store>
- </localhost>
- </virtualhost>
-
- <virtualhost>
- <development>
- <store>
- <class>org.apache.qpid.server.store.derby.DerbyMessageStore</class>
- <environment-path>${QPID_WORK}/derbyDB/development-store</environment-path>
- </store>
- </development>
- </virtualhost>
-
<virtualhost>
<test>
<store>
<class>org.apache.qpid.server.store.derby.DerbyMessageStore</class>
- <environment-path>${QPID_WORK}/derbyDB/test-store</environment-path>
+ <environment-path>${QPID_WORK}/test-store</environment-path>
</store>
</test>
</virtualhost>
</virtualhosts>
-
-
diff --git a/java/systests/etc/virtualhosts-systests-settings.xml b/java/systests/etc/virtualhosts-systests-settings.xml
index 0ec16b31ef..5d4ec28b71 100644
--- a/java/systests/etc/virtualhosts-systests-settings.xml
+++ b/java/systests/etc/virtualhosts-systests-settings.xml
@@ -22,136 +22,11 @@
<virtualhosts>
<default>test</default>
<virtualhost>
- <name>localhost</name>
- <localhost>
- <store>
- <class>org.apache.qpid.server.store.MemoryMessageStore</class>
- </store>
-
- <housekeeping>
- <threadCount>2</threadCount>
- <checkPeriod>20000</checkPeriod>
- </housekeeping>
-
- <exchanges>
- <exchange>
- <type>direct</type>
- <name>test.direct</name>
- <durable>true</durable>
- </exchange>
- <exchange>
- <type>topic</type>
- <name>test.topic</name>
- </exchange>
- </exchanges>
- <queues>
- <exchange>amq.direct</exchange>
- <maximumQueueDepth>4235264</maximumQueueDepth>
- <!-- 4Mb -->
- <maximumMessageSize>2117632</maximumMessageSize>
- <!-- 2Mb -->
- <maximumMessageAge>600000</maximumMessageAge>
- <!-- 10 mins -->
- <maximumMessageCount>50</maximumMessageCount>
- <!-- 50 messages -->
-
- <queue>
- <name>queue</name>
- </queue>
- <queue>
- <name>ping</name>
- </queue>
- <queue>
- <name>test-queue</name>
- <test-queue>
- <exchange>test.direct</exchange>
- <durable>true</durable>
- </test-queue>
- </queue>
- <queue>
- <name>test-ping</name>
- <test-ping>
- <exchange>test.direct</exchange>
- </test-ping>
- </queue>
-
- </queues>
- </localhost>
- </virtualhost>
-
-
- <virtualhost>
- <name>development</name>
- <development>
- <store>
- <class>org.apache.qpid.server.store.MemoryMessageStore</class>
- </store>
-
- <queues>
- <minimumAlertRepeatGap>30000</minimumAlertRepeatGap>
- <maximumMessageCount>50</maximumMessageCount>
- <queue>
- <name>queue</name>
- <queue>
- <exchange>amq.direct</exchange>
- <maximumQueueDepth>4235264</maximumQueueDepth>
- <!-- 4Mb -->
- <maximumMessageSize>2117632</maximumMessageSize>
- <!-- 2Mb -->
- <maximumMessageAge>600000</maximumMessageAge>
- <!-- 10 mins -->
- </queue>
- </queue>
- <queue>
- <name>ping</name>
- <ping>
- <exchange>amq.direct</exchange>
- <maximumQueueDepth>4235264</maximumQueueDepth>
- <!-- 4Mb -->
- <maximumMessageSize>2117632</maximumMessageSize>
- <!-- 2Mb -->
- <maximumMessageAge>600000</maximumMessageAge>
- <!-- 10 mins -->
- </ping>
- </queue>
- </queues>
- </development>
- </virtualhost>
- <virtualhost>
<name>test</name>
<test>
<store>
<class>org.apache.qpid.server.store.MemoryMessageStore</class>
</store>
-
- <queues>
- <minimumAlertRepeatGap>30000</minimumAlertRepeatGap>
- <maximumMessageCount>50</maximumMessageCount>
- <queue>
- <name>queue</name>
- <queue>
- <exchange>amq.direct</exchange>
- <maximumQueueDepth>4235264</maximumQueueDepth>
- <!-- 4Mb -->
- <maximumMessageSize>2117632</maximumMessageSize>
- <!-- 2Mb -->
- <maximumMessageAge>600000</maximumMessageAge>
- <!-- 10 mins -->
- </queue>
- </queue>
- <queue>
- <name>ping</name>
- <ping>
- <exchange>amq.direct</exchange>
- <maximumQueueDepth>4235264</maximumQueueDepth>
- <!-- 4Mb -->
- <maximumMessageSize>2117632</maximumMessageSize>
- <!-- 2Mb -->
- <maximumMessageAge>600000</maximumMessageAge>
- <!-- 10 mins -->
- </ping>
- </queue>
- </queues>
</test>
</virtualhost>
</virtualhosts>
diff --git a/java/systests/src/main/java/org/apache/qpid/client/AMQQueueDeferredOrderingTest.java b/java/systests/src/main/java/org/apache/qpid/client/AMQQueueDeferredOrderingTest.java
index 6655202067..3025414e4a 100644
--- a/java/systests/src/main/java/org/apache/qpid/client/AMQQueueDeferredOrderingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/client/AMQQueueDeferredOrderingTest.java
@@ -27,7 +27,6 @@ import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import javax.jms.Connection;
-import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
@@ -72,10 +71,11 @@ public class AMQQueueDeferredOrderingTest extends QpidBrokerTestCase
for (int i = start; i < end && !interrupted(); i++)
{
producer.send(session.createTextMessage(Integer.toString(i)));
+ ((AMQSession<?, ?>)session).sync();
}
this._logger.info("Sent " + (end - start) + " messages");
}
- catch (JMSException e)
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -101,7 +101,7 @@ public class AMQQueueDeferredOrderingTest extends QpidBrokerTestCase
con.start();
}
- public void testPausedOrder() throws Exception
+ public void testMessagesSentByTwoThreadsAreDeliveredInOrder() throws Exception
{
// Setup initial messages
@@ -121,9 +121,9 @@ public class AMQQueueDeferredOrderingTest extends QpidBrokerTestCase
for (int i = 0; i < numMessages; i++)
{
Message msg = consumer.receive(3000);
- assertNotNull("Message should not be null", msg);
- assertTrue("Message should be a text message", msg instanceof TextMessage);
- assertEquals("Message content does not match expected", Integer.toString(i), ((TextMessage) msg).getText());
+ assertNotNull("Message " + i + " should not be null", msg);
+ assertTrue("Message " + i + " should be a text message", msg instanceof TextMessage);
+ assertEquals("Message content " + i + "does not match expected", Integer.toString(i), ((TextMessage) msg).getText());
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/client/HeartbeatTest.java b/java/systests/src/main/java/org/apache/qpid/client/HeartbeatTest.java
new file mode 100644
index 0000000000..0e01bda8d0
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/client/HeartbeatTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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;
+
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+
+public class HeartbeatTest extends QpidBrokerTestCase
+{
+ public void testHeartbeats() throws Exception
+ {
+ setTestSystemProperty("amqj.heartbeat.delay", "1");
+ AMQConnection conn = (AMQConnection) getConnection();
+ TestListener listener = new TestListener();
+ conn.setHeartbeatListener(listener);
+ conn.start();
+
+ Thread.sleep(2500);
+
+ assertTrue("Too few heartbeats received: "+listener._heartbeatsReceived+" (expected at least 2)", listener._heartbeatsReceived>=2);
+ assertTrue("Too few heartbeats sent "+listener._heartbeatsSent+" (expected at least 2)", listener._heartbeatsSent>=2);
+
+ conn.close();
+ }
+
+ public void testNoHeartbeats() throws Exception
+ {
+ setTestSystemProperty("amqj.heartbeat.delay", "0");
+ AMQConnection conn = (AMQConnection) getConnection();
+ TestListener listener = new TestListener();
+ conn.setHeartbeatListener(listener);
+ conn.start();
+
+ Thread.sleep(2500);
+
+ assertEquals("Heartbeats unexpectedly received", 0, listener._heartbeatsReceived);
+ assertEquals("Heartbeats unexpectedly sent ", 0, listener._heartbeatsSent);
+
+ conn.close();
+ }
+
+ public void testReadOnlyConnectionHeartbeats() throws Exception
+ {
+ setTestSystemProperty("amqj.heartbeat.delay","1");
+ AMQConnection receiveConn = (AMQConnection) getConnection();
+ AMQConnection sendConn = (AMQConnection) getConnection();
+ Destination destination = getTestQueue();
+ TestListener receiveListener = new TestListener();
+ TestListener sendListener = new TestListener();
+
+
+ Session receiveSession = receiveConn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ Session senderSession = sendConn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ MessageConsumer consumer = receiveSession.createConsumer(destination);
+ MessageProducer producer = senderSession.createProducer(destination);
+
+ receiveConn.setHeartbeatListener(receiveListener);
+ sendConn.setHeartbeatListener(sendListener);
+ receiveConn.start();
+
+ for(int i = 0; i < 5; i++)
+ {
+ producer.send(senderSession.createTextMessage("Msg " + i));
+ Thread.sleep(500);
+ assertNotNull("Expected to received message", consumer.receive(500));
+ }
+
+
+
+ assertTrue("Too few heartbeats sent "+receiveListener._heartbeatsSent+" (expected at least 2)", receiveListener._heartbeatsSent>=2);
+ assertEquals("Unexpected sent at the sender: ",0,sendListener._heartbeatsSent);
+
+ assertTrue("Too few heartbeats received at the sender "+sendListener._heartbeatsReceived+" (expected at least 2)", sendListener._heartbeatsReceived>=2);
+ assertEquals("Unexpected received at the receiver: ",0,receiveListener._heartbeatsReceived);
+
+ receiveConn.close();
+ sendConn.close();
+ }
+
+ private class TestListener implements HeartbeatListener
+ {
+ int _heartbeatsReceived;
+ int _heartbeatsSent;
+ @Override
+ public void heartbeatReceived()
+ {
+ _heartbeatsReceived++;
+ }
+
+ @Override
+ public void heartbeatSent()
+ {
+ _heartbeatsSent++;
+ }
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java b/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java
index 4b766864b4..4f8a6ee54a 100644
--- a/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java
@@ -25,11 +25,12 @@ import org.apache.qpid.client.AMQSession;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ConnectionListener;
-import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.jms.FailoverPolicy;
import org.apache.qpid.test.utils.FailoverBaseCase;
+import org.apache.qpid.url.URLSyntaxException;
import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
@@ -929,18 +930,22 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
return queue;
}
- private AMQConnection createConnectionWithFailover() throws NamingException, JMSException
+ private AMQConnection createConnectionWithFailover() throws NamingException, JMSException, URLSyntaxException
{
- AMQConnection connection;
- AMQConnectionFactory connectionFactory = (AMQConnectionFactory)getConnectionFactory("default");
- ConnectionURL connectionURL = connectionFactory.getConnectionURL();
- connectionURL.setOption(ConnectionURL.OPTIONS_FAILOVER, "singlebroker");
- connectionURL.setOption(ConnectionURL.OPTIONS_FAILOVER_CYCLE, "2");
- BrokerDetails details = connectionURL.getBrokerDetails(0);
- details.setProperty(BrokerDetails.OPTIONS_RETRY, "200");
- details.setProperty(BrokerDetails.OPTIONS_CONNECT_DELAY, "1000");
+ BrokerDetails origBrokerDetails = ((AMQConnectionFactory) getConnectionFactory("default")).getConnectionURL().getBrokerDetails(0);
- connection = (AMQConnection)connectionFactory.createConnection("admin", "admin");
+ String retries = "200";
+ String connectdelay = "1000";
+ String cycleCount = "2";
+
+ String newUrlFormat="amqp://username:password@clientid/test?brokerlist=" +
+ "'tcp://%s:%s?retries='%s'&connectdelay='%s''&failover='singlebroker?cyclecount='%s''";
+
+ String newUrl = String.format(newUrlFormat, origBrokerDetails.getHost(), origBrokerDetails.getPort(),
+ retries, connectdelay, cycleCount);
+
+ ConnectionFactory connectionFactory = new AMQConnectionFactory(newUrl);
+ AMQConnection connection = (AMQConnection) connectionFactory.createConnection("admin", "admin");
connection.setConnectionListener(this);
return connection;
}
@@ -1313,7 +1318,7 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
* @param acknowledgeMode session acknowledge mode
* @throws JMSException
*/
- private void sessionCloseWhileFailoverImpl(int acknowledgeMode) throws JMSException
+ private void sessionCloseWhileFailoverImpl(int acknowledgeMode) throws Exception
{
initDelayedFailover(acknowledgeMode);
@@ -1324,9 +1329,14 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
failBroker(getFailingPort());
+ // wait until failover is started
+ _failoverStarted.await(5, TimeUnit.SECONDS);
+
// test whether session#close blocks while failover is in progress
_consumerSession.close();
+ assertTrue("Failover has not completed yet but session was closed", _failoverComplete.await(5, TimeUnit.SECONDS));
+
assertFailoverException();
}
@@ -1360,10 +1370,8 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
* @param acknowledgeMode session acknowledge mode
* @throws JMSException
*/
- private void browserCloseWhileFailoverImpl(int acknowledgeMode) throws JMSException
+ private void browserCloseWhileFailoverImpl(int acknowledgeMode) throws Exception
{
- setDelayedFailoverPolicy();
-
QueueBrowser browser = prepareQueueBrowser(acknowledgeMode);
@SuppressWarnings("unchecked")
@@ -1373,8 +1381,13 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
failBroker(getFailingPort());
+ // wait until failover is started
+ _failoverStarted.await(5, TimeUnit.SECONDS);
+
browser.close();
+ assertTrue("Failover has not completed yet but browser was closed", _failoverComplete.await(5, TimeUnit.SECONDS));
+
assertFailoverException();
}
@@ -1402,5 +1415,11 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
((AMQConnection) _connection).setFailoverPolicy(failoverPolicy);
return failoverPolicy;
}
-
+
+ @Override
+ public void failBroker(int port)
+ {
+ killBroker(port);
+ }
+
}
diff --git a/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java b/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java
new file mode 100644
index 0000000000..a0fd093bfe
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java
@@ -0,0 +1,285 @@
+/*
+ *
+ * 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.failover;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionURL;
+import org.apache.qpid.jms.ConnectionListener;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestUtils;
+import org.apache.qpid.util.FileUtils;
+
+public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements ConnectionListener
+{
+ private static final Logger _logger = Logger.getLogger(MultipleBrokersFailoverTest.class);
+
+ private static final String FAILOVER_VIRTUAL_HOST = "failover";
+ private static final String NON_FAILOVER_VIRTUAL_HOST = "nonfailover";
+ private static final String BROKER_PORTION_FORMAT = "tcp://localhost:%d?connectdelay='%d',retries='%d'";
+ private static final int FAILOVER_RETRIES = 1;
+ private static final int FAILOVER_CONNECTDELAY = 1000;
+ private int[] _brokerPorts;
+ private AMQConnectionURL _connectionURL;
+ private Connection _connection;
+ private CountDownLatch _failoverComplete;
+ private CountDownLatch _failoverStarted;
+ private Session _consumerSession;
+ private Destination _destination;
+ private MessageConsumer _consumer;
+ private Session _producerSession;
+ private MessageProducer _producer;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ int numBrokers = 4;
+ int port = findFreePort();
+ _brokerPorts = new int[numBrokers];
+
+ // we need to create 4 brokers:
+ // 1st broker will be running in test JVM and will not have failover host (only tcp connection will established, amqp connection will be closed)
+ // 2d broker will be spawn in separate JVM and should have a failover host (amqp connection should be established)
+ // 3d broker will be spawn in separate JVM and should not have a failover host (only tcp connection will established, amqp connection will be closed)
+ // 4d broker will be spawn in separate JVM and should have a failover host (amqp connection should be established)
+
+ // the test should connect to the second broker first and fail over to the forth broker
+ // after unsuccessful try to establish the connection to the 3d broker
+ for (int i = 0; i < numBrokers; i++)
+ {
+ if (i > 0)
+ {
+ port = getNextAvailable(port + 1);
+ }
+ _brokerPorts[i] = port;
+
+ createBrokerConfiguration(port);
+ String host = null;
+ if (i == 1 || i == _brokerPorts.length - 1)
+ {
+ host = FAILOVER_VIRTUAL_HOST;
+ }
+ else
+ {
+ host = NON_FAILOVER_VIRTUAL_HOST;
+ }
+ createTestVirtualHost(port, host);
+
+ startBroker(port);
+ revertSystemProperties();
+ }
+
+ _connectionURL = new AMQConnectionURL(generateUrlString(numBrokers));
+
+ _connection = getConnection(_connectionURL);
+ ((AMQConnection) _connection).setConnectionListener(this);
+ _failoverComplete = new CountDownLatch(1);
+ _failoverStarted = new CountDownLatch(1);
+ }
+
+ public void startBroker() throws Exception
+ {
+ // noop, prevent the broker startup in super.setUp()
+ }
+
+ private String generateUrlString(int numBrokers)
+ {
+ String baseString = "amqp://guest:guest@test/" + FAILOVER_VIRTUAL_HOST
+ + "?&failover='roundrobin?cyclecount='1''&brokerlist='";
+ StringBuffer buffer = new StringBuffer(baseString);
+
+ for(int i = 0; i< numBrokers ; i++)
+ {
+ if(i != 0)
+ {
+ buffer.append(";");
+ }
+
+ String broker = String.format(BROKER_PORTION_FORMAT, _brokerPorts[i],
+ FAILOVER_CONNECTDELAY, FAILOVER_RETRIES);
+ buffer.append(broker);
+ }
+ buffer.append("'");
+
+ return buffer.toString();
+ }
+
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ for (int i = 0; i < _brokerPorts.length; i++)
+ {
+ if (_brokerPorts[i] > 0)
+ {
+ stopBrokerSafely(_brokerPorts[i]);
+ FileUtils.deleteDirectory(System.getProperty("QPID_WORK") + "/" + getFailingPort());
+ }
+ }
+
+ }
+ }
+
+
+ public void testFailoverOnBrokerKill() throws Exception
+ {
+ init(Session.SESSION_TRANSACTED, true);
+ assertConnectionPort(_brokerPorts[1]);
+
+ assertSendReceive(0);
+
+ killBroker(_brokerPorts[1]);
+
+ awaitForFailoverCompletion(FAILOVER_CONNECTDELAY * _brokerPorts.length * 2);
+ assertEquals("Failover is not started as expected", 0, _failoverStarted.getCount());
+
+ assertSendReceive(2);
+ assertConnectionPort(_brokerPorts[_brokerPorts.length - 1]);
+ }
+
+ public void testFailoverOnBrokerStop() throws Exception
+ {
+ init(Session.SESSION_TRANSACTED, true);
+ assertConnectionPort(_brokerPorts[1]);
+
+ assertSendReceive(0);
+
+ stopBroker(_brokerPorts[1]);
+
+ awaitForFailoverCompletion(FAILOVER_CONNECTDELAY * _brokerPorts.length * 2);
+ assertEquals("Failover is not started as expected", 0, _failoverStarted.getCount());
+
+ assertSendReceive(1);
+ assertConnectionPort(_brokerPorts[_brokerPorts.length - 1]);
+ }
+
+ private void assertConnectionPort(int brokerPort)
+ {
+ int connectionPort = ((AMQConnection)_connection).getActiveBrokerDetails().getPort();
+ assertEquals("Unexpected broker port", brokerPort, connectionPort);
+ }
+
+ private void assertSendReceive(int index) throws JMSException
+ {
+ Message message = createNextMessage(_producerSession, index);
+ _producer.send(message);
+ if (_producerSession.getTransacted())
+ {
+ _producerSession.commit();
+ }
+ Message receivedMessage = _consumer.receive(1000l);
+ assertReceivedMessage(receivedMessage, index);
+ if (_consumerSession.getTransacted())
+ {
+ _consumerSession.commit();
+ }
+ }
+
+ private void awaitForFailoverCompletion(long delay)
+ {
+ _logger.info("Awaiting Failover completion..");
+ try
+ {
+ if (!_failoverComplete.await(delay, TimeUnit.MILLISECONDS))
+ {
+ _logger.warn("Test thread stack:\n\n" + TestUtils.dumpThreads());
+ fail("Failover did not complete");
+ }
+ }
+ catch (InterruptedException e)
+ {
+ fail("Test was interrupted:" + e.getMessage());
+ }
+ }
+
+ private void assertReceivedMessage(Message receivedMessage, int messageIndex)
+ {
+ assertNotNull("Expected message [" + messageIndex + "] is not received!", receivedMessage);
+ assertTrue(
+ "Failure to receive message [" + messageIndex + "], expected TextMessage but received " + receivedMessage,
+ receivedMessage instanceof TextMessage);
+ }
+
+ private void init(int acknowledgeMode, boolean startConnection) throws JMSException
+ {
+ boolean isTransacted = acknowledgeMode == Session.SESSION_TRANSACTED ? true : false;
+
+ _consumerSession = _connection.createSession(isTransacted, acknowledgeMode);
+ _destination = _consumerSession.createQueue(getTestQueueName());
+ _consumer = _consumerSession.createConsumer(_destination);
+
+ if (startConnection)
+ {
+ _connection.start();
+ }
+
+ _producerSession = _connection.createSession(isTransacted, acknowledgeMode);
+ _producer = _producerSession.createProducer(_destination);
+
+ }
+
+ @Override
+ public void bytesSent(long count)
+ {
+ }
+
+ @Override
+ public void bytesReceived(long count)
+ {
+ }
+
+ @Override
+ public boolean preFailover(boolean redirect)
+ {
+ _failoverStarted.countDown();
+ return true;
+ }
+
+ @Override
+ public boolean preResubscribe()
+ {
+ return true;
+ }
+
+ @Override
+ public void failoverComplete()
+ {
+ _failoverComplete.countDown();
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java b/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
index 39689f5096..884e89fb65 100644
--- a/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
@@ -20,54 +20,55 @@
*/
package org.apache.qpid.client.ssl;
-import org.apache.qpid.client.AMQConnection;
+import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE_PASSWORD;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.client.AMQTestConnection_0_10;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
-import org.apache.qpid.transport.Connection;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+import javax.jms.Connection;
+import javax.jms.JMSException;
import javax.jms.Session;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
public class SSLTest extends QpidBrokerTestCase
{
- private static final String KEYSTORE = "test-profiles/test_resources/ssl/java_client_keystore.jks";
- private static final String KEYSTORE_PASSWORD = "password";
- private static final String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks";
- private static final String TRUSTSTORE_PASSWORD = "password";
private static final String CERT_ALIAS_APP1 = "app1";
private static final String CERT_ALIAS_APP2 = "app2";
@Override
protected void setUp() throws Exception
{
- if(isJavaBroker())
- {
- setTestClientSystemProperty("profile.use_ssl", "true");
- setConfigurationProperty("connector.ssl.enabled", "true");
- setConfigurationProperty("connector.ssl.sslOnly", "true");
- setConfigurationProperty("connector.ssl.wantClientAuth", "true");
- }
-
- // set the ssl system properties
- setSystemProperty("javax.net.ssl.keyStore", KEYSTORE);
- setSystemProperty("javax.net.ssl.keyStorePassword", KEYSTORE_PASSWORD);
- setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
- setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
setSystemProperty("javax.net.debug", "ssl");
- super.setUp();
+
+ setSslStoreSystemProperties();
+
+ //We dont call super.setUp, the tests start the broker after deciding
+ //whether to run and then configuring it appropriately
}
public void testCreateSSLConnectionUsingConnectionURLParams() throws Exception
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (shouldPerformTest())
{
- // Clear the ssl system properties
- setSystemProperty("javax.net.ssl.keyStore", null);
- setSystemProperty("javax.net.ssl.keyStorePassword", null);
- setSystemProperty("javax.net.ssl.trustStore", null);
- setSystemProperty("javax.net.ssl.trustStorePassword", null);
+ clearSslStoreSystemProperties();
+ //Start the broker (NEEDing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, true, false);
+ super.setUp();
+
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" +
"?ssl='true'&ssl_verify_hostname='true'" +
"&key_store='%s'&key_store_password='%s'" +
@@ -76,24 +77,75 @@ public class SSLTest extends QpidBrokerTestCase
url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT,
KEYSTORE,KEYSTORE_PASSWORD,TRUSTSTORE,TRUSTSTORE_PASSWORD);
-
- AMQConnection con = new AMQConnection(url);
+
+ Connection con = getConnection(new AMQConnectionURL(url));
assertNotNull("connection should be successful", con);
Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
assertNotNull("create session should be successful", ssn);
- }
+ }
+ }
+
+ /**
+ * Create an SSL connection using the SSL system properties for the trust and key store, but using
+ * the {@link ConnectionURL} ssl='true' option to indicate use of SSL at a Connection level,
+ * without specifying anything at the {@link ConnectionURL#OPTIONS_BROKERLIST} level.
+ */
+ public void testSslConnectionOption() throws Exception
+ {
+ if (shouldPerformTest())
+ {
+ //Start the broker (NEEDing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, true, false);
+ super.setUp();
+
+ //Create URL enabling SSL at the connection rather than brokerlist level
+ String url = "amqp://guest:guest@test/?ssl='true'&brokerlist='tcp://localhost:%s'";
+ url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT);
+
+ Connection con = getConnection(new AMQConnectionURL(url));
+ assertNotNull("connection should be successful", con);
+ Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
+ assertNotNull("create session should be successful", ssn);
+ }
+ }
+
+ /**
+ * Create an SSL connection using the SSL system properties for the trust and key store, but using
+ * the {@link ConnectionURL} ssl='true' option to indicate use of SSL at a Connection level,
+ * overriding the false setting at the {@link ConnectionURL#OPTIONS_BROKERLIST} level.
+ */
+ public void testSslConnectionOptionOverridesBrokerlistOption() throws Exception
+ {
+ if (shouldPerformTest())
+ {
+ //Start the broker (NEEDing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, true, false);
+ super.setUp();
+
+ //Create URL enabling SSL at the connection, overriding the false at the brokerlist level
+ String url = "amqp://guest:guest@test/?ssl='true'&brokerlist='tcp://localhost:%s?ssl='false''";
+ url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT);
+
+ Connection con = getConnection(new AMQConnectionURL(url));
+ assertNotNull("connection should be successful", con);
+ Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
+ assertNotNull("create session should be successful", ssn);
+ }
}
public void testCreateSSLConnectionUsingSystemProperties() throws Exception
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (shouldPerformTest())
{
+ //Start the broker (NEEDing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, true, false);
+ super.setUp();
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s?ssl='true''";
url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT);
- AMQConnection con = new AMQConnection(url);
+ Connection con = getConnection(new AMQConnectionURL(url));
assertNotNull("connection should be successful", con);
Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
assertNotNull("create session should be successful", ssn);
@@ -102,14 +154,18 @@ public class SSLTest extends QpidBrokerTestCase
public void testMultipleCertsInSingleStore() throws Exception
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (shouldPerformTest())
{
+ //Start the broker (NEEDing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, true, false);
+ super.setUp();
+
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:" +
QpidBrokerTestCase.DEFAULT_SSL_PORT +
"?ssl='true'&ssl_cert_alias='" + CERT_ALIAS_APP1 + "''";
AMQTestConnection_0_10 con = new AMQTestConnection_0_10(url);
- Connection transportCon = con.getConnection();
+ org.apache.qpid.transport.Connection transportCon = con.getConnection();
String userID = transportCon.getSecurityLayer().getUserID();
assertEquals("The correct certificate was not choosen","app1@acme.org",userID);
con.close();
@@ -126,65 +182,82 @@ public class SSLTest extends QpidBrokerTestCase
}
}
- public void testVerifyHostNameWithIncorrectHostname()
+ public void testVerifyHostNameWithIncorrectHostname() throws Exception
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (shouldPerformTest())
{
+ //Start the broker (WANTing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, false, true);
+ super.setUp();
+
String url = "amqp://guest:guest@test/?brokerlist='tcp://127.0.0.1:" +
QpidBrokerTestCase.DEFAULT_SSL_PORT +
"?ssl='true'&ssl_verify_hostname='true''";
try
{
- AMQConnection con = new AMQConnection(url);
+ getConnection(new AMQConnectionURL(url));
fail("Hostname verification failed. No exception was thrown");
}
catch (Exception e)
{
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- e.printStackTrace(new PrintStream(bout));
- String strace = bout.toString();
- assertTrue("Correct exception not thrown",strace.contains("SSL hostname verification failed"));
+ verifyExceptionCausesContains(e, "SSL hostname verification failed");
}
-
}
}
+
+ private void verifyExceptionCausesContains(Exception e, String expectedString)
+ {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ e.printStackTrace(new PrintStream(bout));
+ String strace = bout.toString();
+ assertTrue("Correct exception not thrown", strace.contains(expectedString));
+ }
public void testVerifyLocalHost() throws Exception
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (shouldPerformTest())
{
+ //Start the broker (WANTing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, false, true);
+ super.setUp();
+
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:" +
QpidBrokerTestCase.DEFAULT_SSL_PORT +
"?ssl='true'&ssl_verify_hostname='true''";
- AMQConnection con = new AMQConnection(url);
- assertNotNull("connection should have been created", con);
+ Connection con = getConnection(new AMQConnectionURL(url));
+ assertNotNull("connection should have been created", con);
}
}
public void testVerifyLocalHostLocalDomain() throws Exception
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (shouldPerformTest())
{
+ //Start the broker (WANTing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, false, true);
+ super.setUp();
+
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost.localdomain:" +
QpidBrokerTestCase.DEFAULT_SSL_PORT +
"?ssl='true'&ssl_verify_hostname='true''";
- AMQConnection con = new AMQConnection(url);
+ Connection con = getConnection(new AMQConnectionURL(url));
assertNotNull("connection should have been created", con);
}
}
public void testCreateSSLConnectionUsingConnectionURLParamsTrustStoreOnly() throws Exception
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (shouldPerformTest())
{
- // Clear the ssl system properties
- setSystemProperty("javax.net.ssl.keyStore", null);
- setSystemProperty("javax.net.ssl.keyStorePassword", null);
- setSystemProperty("javax.net.ssl.trustStore", null);
- setSystemProperty("javax.net.ssl.trustStorePassword", null);
+ clearSslStoreSystemProperties();
+
+ //Start the broker (WANTing client certificate authentication)
+ configureJavaBrokerIfNecessary(true, true, false, true);
+ super.setUp();
+
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" +
"?ssl='true'&ssl_verify_hostname='true'" +
@@ -193,10 +266,122 @@ public class SSLTest extends QpidBrokerTestCase
url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT, TRUSTSTORE,TRUSTSTORE_PASSWORD);
- AMQConnection con = new AMQConnection(url);
+ Connection con = getConnection(new AMQConnectionURL(url));
assertNotNull("connection should be successful", con);
Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
assertNotNull("create session should be successful", ssn);
}
}
+
+ /**
+ * Verifies that when the broker is configured to NEED client certificates,
+ * a client which doesn't supply one fails to connect.
+ */
+ public void testClientCertMissingWhilstNeeding() throws Exception
+ {
+ missingClientCertWhileNeedingOrWantingTestImpl(true, false, false);
+ }
+
+ /**
+ * Verifies that when the broker is configured to WANT client certificates,
+ * a client which doesn't supply one succeeds in connecting.
+ */
+ public void testClientCertMissingWhilstWanting() throws Exception
+ {
+ missingClientCertWhileNeedingOrWantingTestImpl(false, true, true);
+ }
+
+ /**
+ * Verifies that when the broker is configured to WANT and NEED client certificates
+ * that a client which doesn't supply one fails to connect.
+ */
+ public void testClientCertMissingWhilstWantingAndNeeding() throws Exception
+ {
+ missingClientCertWhileNeedingOrWantingTestImpl(true, true, false);
+ }
+
+ private void missingClientCertWhileNeedingOrWantingTestImpl(boolean needClientCerts,
+ boolean wantClientCerts, boolean shouldSucceed) throws Exception
+ {
+ if (shouldPerformTest())
+ {
+ clearSslStoreSystemProperties();
+
+ //Start the broker
+ configureJavaBrokerIfNecessary(true, true, needClientCerts, wantClientCerts);
+ super.setUp();
+
+ String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" +
+ "?ssl='true'&trust_store='%s'&trust_store_password='%s''";
+
+ url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT,TRUSTSTORE,TRUSTSTORE_PASSWORD);
+ try
+ {
+ Connection con = getConnection(new AMQConnectionURL(url));
+ if(!shouldSucceed)
+ {
+ fail("Connection succeeded, expected exception was not thrown");
+ }
+ else
+ {
+ //Use the connection to verify it works
+ con.createSession(true, Session.SESSION_TRANSACTED);
+ }
+ }
+ catch(JMSException e)
+ {
+ if(shouldSucceed)
+ {
+ _logger.error("Caught unexpected exception",e);
+ fail("Connection failed, unexpected exception thrown");
+ }
+ else
+ {
+ //expected
+ verifyExceptionCausesContains(e, "Caused by: javax.net.ssl.SSLException:");
+ }
+ }
+ }
+ }
+
+ private boolean shouldPerformTest()
+ {
+ // We run the SSL tests on all the Java broker profiles
+ if(isJavaBroker())
+ {
+ setTestClientSystemProperty(PROFILE_USE_SSL, "true");
+ }
+
+ return Boolean.getBoolean(PROFILE_USE_SSL);
+ }
+
+ private void configureJavaBrokerIfNecessary(boolean sslEnabled, boolean sslOnly, boolean needClientAuth, boolean wantClientAuth) throws ConfigurationException
+ {
+ if(isJavaBroker())
+ {
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NEED_CLIENT_AUTH, needClientAuth);
+ sslPortAttributes.put(Port.WANT_CLIENT_AUTH, wantClientAuth);
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ getBrokerConfiguration().addPortConfiguration(sslPortAttributes);
+ }
+ }
+
+ private void setSslStoreSystemProperties()
+ {
+ setSystemProperty("javax.net.ssl.keyStore", KEYSTORE);
+ setSystemProperty("javax.net.ssl.keyStorePassword", KEYSTORE_PASSWORD);
+ setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
+ setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
+ }
+
+ private void clearSslStoreSystemProperties()
+ {
+ setSystemProperty("javax.net.ssl.keyStore", null);
+ setSystemProperty("javax.net.ssl.keyStorePassword", null);
+ setSystemProperty("javax.net.ssl.trustStore", null);
+ setSystemProperty("javax.net.ssl.trustStorePassword", null);
+ }
}
diff --git a/java/systests/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxyTest.java b/java/systests/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxyTest.java
new file mode 100644
index 0000000000..80001099a8
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/ra/admin/QpidConnectionFactoryProxyTest.java
@@ -0,0 +1,120 @@
+/*
+ *
+ * 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.ra.admin;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.naming.NamingException;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.spi.ObjectFactory;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+
+public class QpidConnectionFactoryProxyTest extends QpidBrokerTestCase
+{
+ private static final String BROKER_PORT = "15672";
+
+ private static final String URL = "amqp://guest:guest@client/test?brokerlist='tcp://localhost:" + BROKER_PORT + "?sasl_mechs='PLAIN''";
+
+ public void testQueueConnectionFactory() throws Exception
+ {
+ QueueConnectionFactory cf = null;
+ QueueConnection c = null;
+
+ try
+ {
+ cf = new QpidConnectionFactoryProxy();
+ ((QpidConnectionFactoryProxy)cf).setConnectionURL(URL);
+ c = cf.createQueueConnection();
+ assertTrue(c instanceof QueueConnection);
+
+ }
+ finally
+ {
+ if(c != null)
+ {
+ c.close();
+ }
+ }
+ }
+
+ public void testTopicConnectionFactory() throws Exception
+ {
+ TopicConnectionFactory cf = null;
+ TopicConnection c = null;
+
+ try
+ {
+ cf = new QpidConnectionFactoryProxy();
+ ((QpidConnectionFactoryProxy)cf).setConnectionURL(URL);
+ c = cf.createTopicConnection();
+ assertTrue(c instanceof TopicConnection);
+
+ }
+ finally
+ {
+ if(c != null)
+ {
+ c.close();
+ }
+ }
+ try
+ {
+
+ }
+ finally
+ {
+
+ }
+ }
+
+ public void testConnectionFactory() throws Exception
+ {
+ ConnectionFactory cf = null;
+ Connection c = null;
+
+ try
+ {
+ cf = new QpidConnectionFactoryProxy();
+ ((QpidConnectionFactoryProxy)cf).setConnectionURL(URL);
+ c = cf.createConnection();
+ assertTrue(c instanceof Connection);
+
+ }
+ finally
+ {
+ if(c != null)
+ {
+ c.close();
+ }
+
+ }
+ }
+}
+
diff --git a/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java b/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java
index 9f3994fc91..eba2a638c0 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java
@@ -30,6 +30,7 @@ import org.apache.qpid.util.LogMonitor;
import javax.jms.Connection;
import javax.jms.Queue;
import javax.jms.Session;
+import java.io.File;
import java.util.List;
/**
@@ -72,10 +73,7 @@ public class BrokerStartupTest extends AbstractTestLogging
if (isJavaBroker() && isExternalBroker() && !isInternalBroker())
{
//Remove test Log4j config from the commandline
- _brokerCommand = _brokerCommand.substring(0, _brokerCommand.indexOf("-l"));
-
- // Add an invalid value
- _brokerCommand += " -l invalid";
+ setBrokerCommandLog4JFile(new File("invalid file"));
// The broker has a built in default log4j configuration set up
// so if the the broker cannot load the -l value it will use default
@@ -145,4 +143,4 @@ public class BrokerStartupTest extends AbstractTestLogging
}
}
-} \ No newline at end of file
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java b/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java
index e8d72c13bd..23a00431d1 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java
@@ -23,13 +23,17 @@ package org.apache.qpid.server;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.configuration.ClientProperties;
import org.apache.qpid.framing.ProtocolVersion;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.adapter.PortFactoryTest;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
/**
* Tests to validate it is possible to disable support for particular protocol
* versions entirely, rather than selectively excluding them on particular ports,
* and it is possible to configure the reply to an unsupported protocol initiation.
+ *<p>
+ * Protocol exclusion/inclusion are unit tested as part of {@link PortFactoryTest}
*/
public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
{
@@ -41,8 +45,8 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
private void clearProtocolSupportManipulations()
{
//Remove the QBTC provided protocol manipulations, giving only the protocols which default to enabled
- setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_EXCLUDES, null);
- setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_INCLUDES, null);
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, null);
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, null);
}
/**
@@ -87,8 +91,8 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
clearProtocolSupportManipulations();
//disable 0-10 and 1-0 support
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false");
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES,
+ Protocol.AMQP_1_0 + "," + Protocol.AMQP_0_10);
super.setUp();
@@ -100,52 +104,14 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
connection.close();
}
- public void testDisabling091and010and10() throws Exception
- {
- clearProtocolSupportManipulations();
-
- //disable 0-91 and 0-10 and 1-0 support
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP091ENABLED, "false");
-
- super.setUp();
-
- //Verify initially requesting a 0-10 connection now negotiates a 0-9
- //connection as the broker should reply with its highest supported protocol
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- AMQConnection connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_9, connection.getProtocolVersion());
- connection.close();
- }
-
- public void testDisabling09and091and010and10() throws Exception
- {
- clearProtocolSupportManipulations();
-
- //disable 0-9, 0-91, 0-10 and 1-0 support
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP09ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP091ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false");
-
- super.setUp();
-
- //Verify initially requesting a 0-10 connection now negotiates a 0-8
- //connection as the broker should reply with its highest supported protocol
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- AMQConnection connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v8_0, connection.getProtocolVersion());
- connection.close();
- }
-
public void testConfiguringReplyingToUnsupported010ProtocolInitiationWith09insteadOf091() throws Exception
{
clearProtocolSupportManipulations();
//disable 0-10 support, and set the default unsupported protocol initiation reply to 0-9
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP_SUPPORTED_REPLY, "v0_9");
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES,
+ Protocol.AMQP_1_0 + "," + Protocol.AMQP_0_10);
+ setSystemProperty(BrokerProperties.PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY, "v0_9");
super.setUp();
@@ -164,71 +130,5 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase
connection.close();
}
- public void testProtocolInclusionThroughQBTCSystemPropertiesOverridesProtocolExclusion() throws Exception
- {
- testProtocolInclusionOverridesProtocolExclusion(false);
- }
-
- public void testProtocolInclusionThroughConfigOverridesProtocolExclusion() throws Exception
- {
- testProtocolInclusionOverridesProtocolExclusion(true);
- }
-
- private void testProtocolInclusionOverridesProtocolExclusion(boolean useConfig) throws Exception
- {
- clearProtocolSupportManipulations();
-
- //selectively exclude 0-10 and 1-0 on the test port
- setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_EXCLUDES,"--exclude-0-10 @PORT --exclude-1-0 @PORT");
-
- super.setUp();
-
- //Verify initially requesting a 0-10 connection negotiates a 0-9-1 connection
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- AMQConnection connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_91, connection.getProtocolVersion());
- connection.close();
-
- stopBroker();
-
- if(useConfig)
- {
- //selectively include 0-10 support again on the test port through config
- setConfigurationProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, String.valueOf(getPort()));
- }
- else
- {
- //selectively include 0-10 support again on the test port through QBTC sys props
- setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_INCLUDES,"--include-0-10 @PORT");
- }
-
- startBroker();
-
- //Verify requesting a 0-10 connection now returns one
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_10, connection.getProtocolVersion());
- connection.close();
- }
-
- public void testProtocolInclusionOverridesProtocolDisabling() throws Exception
- {
- clearProtocolSupportManipulations();
-
- //disable 0-10 and 1-0
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false");
- setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false");
-
- //selectively include 0-10 support again on the test port
- setConfigurationProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, String.valueOf(getPort()));
-
- super.setUp();
-
- //Verify initially requesting a 0-10 connection still works
- setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10");
- AMQConnection connection = (AMQConnection) getConnection();
- assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_10, connection.getProtocolVersion());
- connection.close();
- }
} \ No newline at end of file
diff --git a/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java b/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java
deleted file mode 100644
index 6f54a56e93..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java
+++ /dev/null
@@ -1,75 +0,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.
- *
- */
-package org.apache.qpid.server.configuration;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-/**
- * This system test ensures that when loading our default system-test
- * configuration file the configuration is correctly loaded.
- *
- * All configuration values should be set in the systest config file so that
- * the ability to load them can be validated.
- */
-public class ServerConfigurationFileTest extends QpidBrokerTestCase
-{
- private ServerConfiguration _serverConfig;
-
- public void setUp() throws ConfigurationException
- {
- if (!_configFile.exists())
- {
- fail("Unable to test without config file:" + _configFile);
- }
-
- saveTestConfiguration();
- saveTestVirtualhosts();
-
- _serverConfig = new ServerConfiguration(_configFile);
- }
-
- /**
- * This helper method ensures that when we attempt to read a value that is
- * set in the configuration file we do actualy read a value and not
- * simply get a defaulted value from the ServerConfiguration.get*() methods.
- *
- * @param property the propert to test
- */
- private void validatePropertyDefinedInFile(String property)
- {
- //Verify that we are not just picking up the the default value from the getBoolean
- assertNotNull("The value set in the configuration file is not being read for property:" + property,
- _serverConfig.getConfig().getProperty(property));
- }
-
- public void testStatusUpdates() throws ConfigurationException
- {
- validatePropertyDefinedInFile(ServerConfiguration.STATUS_UPDATES);
- }
-
- public void testLocale() throws ConfigurationException
- {
- validatePropertyDefinedInFile(ServerConfiguration.ADVANCED_LOCALE);
- }
-
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java b/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java
deleted file mode 100644
index 87a53a0765..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java
+++ /dev/null
@@ -1,237 +0,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.
- *
- */
-
-package org.apache.qpid.server.failure;
-
-import junit.framework.TestCase;
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.client.failover.FailoverException;
-import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.test.utils.QpidClientConnectionHelper;
-
-import javax.jms.DeliveryMode;
-import javax.jms.JMSException;
-import java.io.IOException;
-
-
-/** Test Case provided by client Non-functional Test NF101: heap exhaustion behaviour */
-public class HeapExhaustion extends TestCase
-{
- private static final Logger _logger = Logger.getLogger(HeapExhaustion.class);
-
- protected QpidClientConnectionHelper conn;
- protected final String BROKER = "localhost";
- protected final String vhost = "/test";
- protected final String queue = "direct://amq.direct//queue";
-
- protected String hundredK;
- protected String megabyte;
-
- protected String generatePayloadOfSize(Integer numBytes)
- {
- return new String(new byte[numBytes]);
- }
-
- protected void setUp() throws Exception
- {
- conn = new QpidClientConnectionHelper(BROKER);
- conn.setVirtualHost(vhost);
-
- try
- {
- conn.connect();
- } catch (JMSException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- // clear queue
- _logger.debug("setup: clearing test queue");
- conn.consume(queue, 2000);
-
- hundredK = generatePayloadOfSize(1024 * 100);
- megabyte = generatePayloadOfSize(1024 * 1024);
- }
-
- protected void tearDown() throws Exception
- {
- conn.disconnect();
- }
-
-
- /**
- * PUT at maximum rate (although we commit after each PUT) until failure
- *
- * @throws Exception on error
- */
- public void testUntilFailureTransient() throws Exception
- {
- int copies = 0;
- int total = 0;
- String payload = hundredK;
- int size = payload.getBytes().length;
- while (true)
- {
- conn.put(queue, payload, 1, DeliveryMode.NON_PERSISTENT);
- copies++;
- total += size;
- System.out.println("put copy " + copies + " OK for total bytes: " + total);
- }
- }
-
- /**
- * PUT at lower rate (5 per second) until failure
- *
- * @throws Exception on error
- */
- public void testUntilFailureWithDelaysTransient() throws Exception
- {
- int copies = 0;
- int total = 0;
- String payload = hundredK;
- int size = payload.getBytes().length;
- while (true)
- {
- conn.put(queue, payload, 1, DeliveryMode.NON_PERSISTENT);
- copies++;
- total += size;
- System.out.println("put copy " + copies + " OK for total bytes: " + total);
- Thread.sleep(200);
- }
- }
-
- public static void noDelay()
- {
- HeapExhaustion he = new HeapExhaustion();
-
- try
- {
- he.setUp();
- }
- catch (Exception e)
- {
- _logger.info("Unable to connect");
- System.exit(0);
- }
-
- try
- {
- _logger.info("Running testUntilFailure");
- try
- {
- he.testUntilFailureTransient();
- }
- catch (FailoverException fe)
- {
- _logger.error("Caught failover:" + fe);
- }
- _logger.info("Finishing Connection ");
-
- try
- {
- he.tearDown();
- }
- catch (JMSException jmse)
- {
- if (((AMQException) jmse.getLinkedException()).getErrorCode() == AMQConstant.REQUEST_TIMEOUT)
- {
- _logger.info("Successful test of testUntilFailure");
- }
- else
- {
- _logger.error("Test Failed due to:" + jmse);
- }
- }
- }
- catch (Exception e)
- {
- _logger.error("Test Failed due to:" + e);
- }
- }
-
- public static void withDelay()
- {
- HeapExhaustion he = new HeapExhaustion();
-
- try
- {
- he.setUp();
- }
- catch (Exception e)
- {
- _logger.info("Unable to connect");
- System.exit(0);
- }
-
- try
- {
- _logger.info("Running testUntilFailure");
- try
- {
- he.testUntilFailureWithDelaysTransient();
- }
- catch (FailoverException fe)
- {
- _logger.error("Caught failover:" + fe);
- }
- _logger.info("Finishing Connection ");
-
- try
- {
- he.tearDown();
- }
- catch (JMSException jmse)
- {
- if (((AMQException) jmse.getLinkedException()).getErrorCode() == AMQConstant.REQUEST_TIMEOUT)
- {
- _logger.info("Successful test of testUntilFailure");
- }
- else
- {
- _logger.error("Test Failed due to:" + jmse);
- }
- }
- }
- catch (Exception e)
- {
- _logger.error("Test Failed due to:" + e);
- }
- }
-
- public static void main(String args[])
- {
- noDelay();
-
-
- try
- {
- System.out.println("Restart failed broker now to retest broker with delays in send.");
- System.in.read();
- }
- catch (IOException e)
- {
- _logger.info("Continuing");
- }
-
- withDelay();
- }
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java b/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
index b666b1f424..84017b6850 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
@@ -20,12 +20,7 @@
*/
package org.apache.qpid.server.logging;
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.util.LogMonitor;
@@ -47,8 +42,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase
public static final String TEST_LOG_PREFIX = "MESSAGE";
protected LogMonitor _monitor;
- private InternalBrokerBaseCase _configLoader;
-
@Override
public void setUp() throws Exception
{
@@ -58,32 +51,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase
_monitor = new LogMonitor(_outputFile);
}
- protected ServerConfiguration getServerConfig() throws ConfigurationException
- {
- ServerConfiguration _serverConfiguration;
- if (isExternalBroker())
- {
- _serverConfiguration = new ServerConfiguration(_configFile)
- {
- @Override
- public void initialise() throws ConfigurationException
- {
- //Overriding initialise to only setup the vhosts and not
- //perform the ConfigurationPlugin setup, removing need for
- //an ApplicationRegistry to be loaded.
- setupVirtualHosts(getConfig());
- }
- };
- _serverConfiguration.initialise();
- }
- else
- {
- _serverConfiguration = ApplicationRegistry.getInstance().getConfiguration();
- }
-
- return _serverConfiguration;
- }
-
protected void setLogMessagePrefix()
{
//set the message prefix to facilitate scraping from the munged test output.
@@ -94,10 +61,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase
public void tearDown() throws Exception
{
_monitor.close();
- if (isExternalBroker() && _configLoader != null)
- {
- _configLoader.tearDown();
- }
super.tearDown();
}
@@ -159,7 +122,7 @@ public class AbstractTestLogging extends QpidBrokerTestCase
}
protected String fromMessage(String log)
- {
+ {;
int startSubject = log.indexOf("]") + 1;
int start = log.indexOf("]", startSubject) + 1;
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java b/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java
index 4b7b3f0cf0..37f960a65a 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java
@@ -31,10 +31,10 @@ import java.util.List;
/**
* ACL version 2/3 file testing to verify that ACL actor logging works correctly.
- *
+ *
* This suite of tests validate that the AccessControl messages occur correctly
* and according to the following format:
- *
+ *
* <pre>
* ACL-1001 : Allowed Operation Object {PROPERTIES}
* ACL-1002 : Denied Operation Object {PROPERTIES}
@@ -83,12 +83,12 @@ public class AccessControlLoggingTest extends AbstractTestLogging
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
((AMQSession<?, ?>) sess).createQueue(new AMQShortString("allow"), false, false, false);
-
+
List<String> matches = findMatches(ACL_LOG_PREFIX);
-
+
assertTrue("Should be no ACL log messages", matches.isEmpty());
}
-
+
/**
* Test that {@code allow-log} ACL entries log correctly.
*/
@@ -98,25 +98,25 @@ public class AccessControlLoggingTest extends AbstractTestLogging
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
((AMQSession<?, ?>) sess).createQueue(new AMQShortString("allow-log"), false, false, false);
-
+
List<String> matches = findMatches(ACL_LOG_PREFIX);
-
+
assertEquals("Should only be one ACL log message", 1, matches.size());
-
+
String log = getLogMessage(matches, 0);
String actor = fromActor(log);
String subject = fromSubject(log);
String message = getMessageString(fromMessage(log));
-
+
validateMessageID(ACL_LOG_PREFIX + 1001, log);
-
- assertTrue("Actor should contain the user identity", actor.contains(USER));
+
+ assertTrue("Actor " + actor + " should contain the user identity: " + USER, actor.contains(USER));
assertTrue("Subject should be empty", subject.length() == 0);
assertTrue("Message should start with 'Allowed'", message.startsWith("Allowed"));
assertTrue("Message should contain 'Create Queue'", message.contains("Create Queue"));
assertTrue("Message should have contained the queue name", message.contains("allow-log"));
}
-
+
/**
* Test that {@code deny-log} ACL entries log correctly.
*/
@@ -134,25 +134,25 @@ public class AccessControlLoggingTest extends AbstractTestLogging
// Denied, so exception thrown
assertEquals("Expected ACCESS_REFUSED error code", AMQConstant.ACCESS_REFUSED, amqe.getErrorCode());
}
-
+
List<String> matches = findMatches(ACL_LOG_PREFIX);
-
+
assertEquals("Should only be one ACL log message", 1, matches.size());
-
+
String log = getLogMessage(matches, 0);
String actor = fromActor(log);
String subject = fromSubject(log);
String message = getMessageString(fromMessage(log));
-
+
validateMessageID(ACL_LOG_PREFIX + 1002, log);
-
- assertTrue("Actor should contain the user identity", actor.contains(USER));
+
+ assertTrue("Actor " + actor + " should contain the user identity: " + USER, actor.contains(USER));
assertTrue("Subject should be empty", subject.length() == 0);
assertTrue("Message should start with 'Denied'", message.startsWith("Denied"));
assertTrue("Message should contain 'Create Queue'", message.contains("Create Queue"));
assertTrue("Message should have contained the queue name", message.contains("deny-log"));
}
-
+
/**
* Test that {@code deny} ACL entries do not log anything.
*/
@@ -170,9 +170,9 @@ public class AccessControlLoggingTest extends AbstractTestLogging
// Denied, so exception thrown
assertEquals("Expected ACCESS_REFUSED error code", AMQConstant.ACCESS_REFUSED, amqe.getErrorCode());
}
-
+
List<String> matches = findMatches(ACL_LOG_PREFIX);
-
+
assertTrue("Should be no ACL log messages", matches.isEmpty());
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java b/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
index 02c41e14c0..68ec101245 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
@@ -22,10 +22,6 @@ package org.apache.qpid.server.logging;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.util.FileUtils;
import javax.jms.Connection;
import javax.jms.Queue;
@@ -44,29 +40,19 @@ public class AlertingTest extends AbstractTestLogging
public void setUp() throws Exception
{
- // Update the configuration to make our virtualhost Persistent.
- makeVirtualHostPersistent(VIRTUALHOST);
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "5000");
-
_numMessages = 50;
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", String.valueOf(ALERT_LOG_WAIT_PERIOD));
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", String.valueOf(_numMessages));
+
// Then we do the normal setup stuff like starting the broker, getting a connection etc.
super.setUp();
setupConnection();
}
- @Override
- public void tearDown() throws Exception
- {
- // Ensure queue is clean for next run.
- drainQueue(_destination);
- super.tearDown();
- }
-
-
/**
- * Create a new connection and ensure taht our destination queue is created
+ * Create a new connection and ensure that our destination queue is created
* and bound.
*
* Note that the tests here that restart the broker rely on persistence.
@@ -102,20 +88,6 @@ public class AlertingTest extends AbstractTestLogging
if (!waitForMessage(MESSAGE_COUNT_ALERT, ALERT_LOG_WAIT_PERIOD))
{
StringBuffer message = new StringBuffer("Could not find 'MESSAGE_COUNT_ALERT' in log file: " + _monitor.getMonitoredFile().getAbsolutePath());
- message.append("\n");
-
- // Add the current contents of the log file to test output
- message.append(_monitor.readFile());
-
- // Write the test config file to test output
- message.append("Server configuration overrides in use:\n");
- message.append(FileUtils.readFileAsString(getTestConfigFile()));
-
- message.append("\nVirtualhost maxMessageCount:\n");
- ServerConfiguration config = new ServerConfiguration(_configFile);
- config.initialise();
- message.append(config.getVirtualHostConfig(VIRTUALHOST).getMaximumMessageCount());
-
fail(message.toString());
}
}
@@ -148,9 +120,6 @@ public class AlertingTest extends AbstractTestLogging
* Test sends two messages to the broker then restarts the broker with new
* configuration.
*
- * If the test is running inVM the test validates that the new configuration
- * has been applied.
- *
* Validates that we only have two messages on the queue and then sends
* enough messages to trigger the alert.
*
@@ -172,31 +141,24 @@ public class AlertingTest extends AbstractTestLogging
_monitor.markDiscardPoint();
// Change max message count to 5, start broker and make sure that that's triggered at the right time
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", "5");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", "5");
startBroker();
- if (isInternalBroker())
- {
- assertEquals("Alert Max Msg Count is not correct", 5, ApplicationRegistry.getInstance().getVirtualHostRegistry().
- getVirtualHost(VIRTUALHOST).getQueueRegistry().getQueue(new AMQShortString(_destination.getQueueName())).
- getMaximumMessageCount());
- }
-
setupConnection();
// Validate the queue depth is as expected
long messageCount = ((AMQSession<?, ?>) _session).getQueueDepth((AMQDestination) _destination);
assertEquals("Broker has invalid message count for test", 2, messageCount);
- // Ensure the alert has not occured yet
+ // Ensure the alert has not occurred yet
assertLoggingNotYetOccured(MESSAGE_COUNT_ALERT);
// Trigger the new value
sendMessage(_session, _destination, 3);
_session.commit();
- // Validate that the alert occured.
+ // Validate that the alert occurred.
wasAlertFired();
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
index dee593b12b..c5f5e06ae1 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
@@ -23,12 +23,20 @@ package org.apache.qpid.server.logging;
import junit.framework.AssertionFailedError;
import org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.transport.ConnectionException;
import org.apache.qpid.util.LogMonitor;
import java.io.IOException;
import java.net.Socket;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Broker Test Suite
@@ -47,6 +55,8 @@ import java.util.List;
*/
public class BrokerLoggingTest extends AbstractTestLogging
{
+ private static final String BROKER_MESSAGE_LOG_REG_EXP = ".*\\[\\w*\\] (BRK\\-\\d*) .*";
+ private static final Pattern BROKER_MESSAGE_LOG_PATTERN = Pattern.compile(BROKER_MESSAGE_LOG_REG_EXP);
private static final String BRK_LOG_PREFIX = "BRK-";
public void setUp() throws Exception
@@ -95,7 +105,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
_monitor = new LogMonitor(_outputFile);
- String configFilePath = _configFile.toString();
+ String configFilePath = getConfigPath();
// Ensure we wait for TESTID to be logged
waitAndFindMatches(TESTID);
@@ -118,8 +128,9 @@ public class BrokerLoggingTest extends AbstractTestLogging
1, results.size());
//3
- assertTrue("Config file details not correctly logged",
- log.endsWith(configFilePath));
+ assertTrue("Config file details not correctly logged, got "
+ + log + " but expected it to end with " + configFilePath,
+ log.endsWith(configFilePath));
}
catch (AssertionFailedError afe)
{
@@ -130,6 +141,11 @@ public class BrokerLoggingTest extends AbstractTestLogging
}
}
+ private String getConfigPath()
+ {
+ return getPathRelativeToWorkingDirectory(getTestConfigFile(DEFAULT_PORT));
+ }
+
/**
* Description:
* On startup the broker must report correctly report the log4j file in use. This is important as it can help diagnose why logging messages are not being reported.
@@ -155,8 +171,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
{
String TESTID = "BRK-1007";
- //Remove test Log4j config from the commandline
- _brokerCommand = _brokerCommand.substring(0, _brokerCommand.indexOf("-l"));
+ _brokerCommandHelper.removeBrokerCommandLog4JFile();
startBroker();
@@ -243,8 +258,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
// This logging startup code only occurs when you run a Java broker
if (isJavaBroker() && isExternalBroker())
{
- // Get custom -l value used during testing for the broker startup
- String customLog4j = _brokerCommand.substring(_brokerCommand.indexOf("-l") + 2).trim();
+ String customLog4j = getBrokerCommandLog4JFile().getAbsolutePath();
String TESTID = "BRK-1007";
@@ -293,8 +307,10 @@ public class BrokerLoggingTest extends AbstractTestLogging
1, findMatches(TESTID).size());
//3
- assertTrue("Log4j file details not correctly logged:" + getMessageString(log),
- getMessageString(log).endsWith(customLog4j));
+ String messageString = getMessageString(log);
+ assertTrue("Log4j file details not correctly logged. Message '"
+ + messageString + "' should contain '" +customLog4j + "'",
+ messageString.endsWith(customLog4j));
validation = true;
}
@@ -442,10 +458,13 @@ public class BrokerLoggingTest extends AbstractTestLogging
{
String log = getLog(rawLog);
+ // using custom method to get id as getMessageId() fails to correctly identify id
+ // because of using brackets for protocols
+ String id = getBrokerLogId(log);
// Ensure we do not have a BRK-1002 message
- if (!getMessageID(log).equals(TESTID))
+ if (!id.equals(TESTID))
{
- if (getMessageID(log).equals("BRK-1001"))
+ if (id.equals("BRK-1001"))
{
foundBRK1001 = true;
}
@@ -455,7 +474,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
assertTrue("BRK-1001 not logged before this message", foundBRK1001);
//1
- validateMessageID(TESTID, log);
+ assertEquals("Incorrect message", TESTID, id);
//2
//There will be 2 copies of the startup message (one via SystemOut, and one via Log4J)
@@ -465,7 +484,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
//3
String message = getMessageString(log);
assertTrue("Expected Listen log not correct" + message,
- message.endsWith("Listening on TCP port " + getPort()));
+ message.endsWith("Listening on [TCP] port " + getPort()));
validation = true;
}
@@ -481,6 +500,16 @@ public class BrokerLoggingTest extends AbstractTestLogging
}
}
+ private String getBrokerLogId(String log)
+ {
+ Matcher m = BROKER_MESSAGE_LOG_PATTERN.matcher(log);
+ if (m.matches())
+ {
+ return m.group(1);
+ }
+ return getMessageID(log);
+ }
+
/**
* Description:
* On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available.
@@ -498,8 +527,8 @@ public class BrokerLoggingTest extends AbstractTestLogging
* 1. The BRK ID is correct
* 2. This occurs after the BRK-1001 startup message
* 3. With SSL enabled in the configuration two BRK-1002 will be printed (order is not specified)
- * 1. One showing values TCP / 5672
- * 2. One showing values TCP/SSL / 5672
+ * 1. One showing values [TCP] 5672
+ * 2. One showing values [SSL] 5671
*
* @throws Exception caused by broker startup
*/
@@ -512,12 +541,11 @@ public class BrokerLoggingTest extends AbstractTestLogging
String TESTID = "BRK-1002";
// Enable SSL on the connection
- setConfigurationProperty("connector.ssl.enabled", "true");
- setConfigurationProperty("connector.ssl.sslOnly", "false");
- setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath"));
- setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword"));
-
- Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.ssl.port"));
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ getBrokerConfiguration().addPortConfiguration(sslPortAttributes);
startBroker();
@@ -545,10 +573,11 @@ public class BrokerLoggingTest extends AbstractTestLogging
{
String log = getLog(rawLog);
+ String id = getBrokerLogId(log);
// Ensure we do not have a BRK-1002 message
- if (!getMessageID(log).equals(TESTID))
+ if (!id.equals(TESTID))
{
- if (getMessageID(log).equals("BRK-1001"))
+ if (id.equals("BRK-1001"))
{
foundBRK1001 = true;
}
@@ -558,7 +587,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
assertTrue("BRK-1001 not logged before this message", foundBRK1001);
//1
- validateMessageID(TESTID, log);
+ assertEquals("Incorrect message", TESTID, id);
//2
//There will be 4 copies of the startup message (two via SystemOut, and two via Log4J)
@@ -570,16 +599,16 @@ public class BrokerLoggingTest extends AbstractTestLogging
//Check the first
String message = getMessageString(getLog(listenMessages .get(0)));
assertTrue("Expected Listen log not correct" + message,
- message.endsWith("Listening on TCP port " + getPort()));
+ message.endsWith("Listening on [TCP] port " + getPort()));
// Check the third, ssl listen.
message = getMessageString(getLog(listenMessages .get(2)));
assertTrue("Expected Listen log not correct" + message,
- message.endsWith("Listening on TCP/SSL port " + sslPort));
+ message.endsWith("Listening on [SSL] port " + DEFAULT_SSL_PORT));
//4 Test ports open
testSocketOpen(getPort());
- testSocketOpen(sslPort);
+ testSocketOpen(DEFAULT_SSL_PORT);
validation = true;
}
@@ -803,11 +832,11 @@ public class BrokerLoggingTest extends AbstractTestLogging
String TESTID = "BRK-1003";
// Enable SSL on the connection
- setConfigurationProperty("connector.ssl.enabled", "true");
- setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath"));
- setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword"));
-
- Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.ssl.port"));
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ getBrokerConfiguration().addPortConfiguration(sslPortAttributes);
startBroker();
@@ -848,13 +877,13 @@ public class BrokerLoggingTest extends AbstractTestLogging
// Check second, ssl, listen.
message = getMessageString(getLog(listenMessages.get(1)));
assertTrue("Expected shutdown log not correct" + message,
- message.endsWith("TCP/SSL port " + sslPort));
+ message.endsWith("TCP/SSL port " + DEFAULT_SSL_PORT));
//4
//Test Port closed
checkSocketClosed(getPort());
//Test SSL Port closed
- checkSocketClosed(sslPort);
+ checkSocketClosed(DEFAULT_SSL_PORT);
}
catch (AssertionFailedError afe)
{
@@ -999,4 +1028,5 @@ public class BrokerLoggingTest extends AbstractTestLogging
+ ". Due to:" + e.getMessage());
}
}
+
}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java b/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java
index 236202f323..9f532ec5f7 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java
@@ -66,8 +66,8 @@ public class SubscriptionLoggingTest extends AbstractTestLogging
_session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- _queue = (Queue) getInitialContext().lookup(QUEUE);
- _topic = (Topic) getInitialContext().lookup(TOPIC);
+ _queue = _session.createQueue(getTestQueueName() + "Queue");
+ _topic = _session.createTopic(getTestQueueName() + "Topic");
}
/**
@@ -434,10 +434,6 @@ public class SubscriptionLoggingTest extends AbstractTestLogging
throw afe;
}
_connection.close();
-
- //Ensure the queue is drained before the test ends
- drainQueue(_queue);
-
}
/**
diff --git a/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java b/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java
index 5f96215269..1ea105ae1a 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java
@@ -23,7 +23,6 @@ package org.apache.qpid.server.logging;
import junit.framework.AssertionFailedError;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import java.util.Arrays;
import java.util.List;
@@ -68,7 +67,7 @@ public class VirtualHostLoggingTest extends AbstractTestLogging
try
{
- List<String> vhosts = Arrays.asList(getServerConfig().getVirtualHosts());
+ List<String> vhosts = Arrays.asList("test");
assertEquals("Each vhost did not create a store.", vhosts.size(), results.size());
@@ -110,23 +109,17 @@ public class VirtualHostLoggingTest extends AbstractTestLogging
// Wait for the correct VHT message to arrive.
waitForMessage(VHT_PREFIX + "1002");
-
+
// Validate each vhost logs a closure
List<String> results = findMatches(VHT_PREFIX + "1002");
-
+
try
{
- // Load VirtualHost list from file.
- ServerConfiguration configuration = new ServerConfiguration(_configFile);
- configuration.initialise();
- List<String> vhosts = Arrays.asList(configuration.getVirtualHosts());
-
- assertEquals("Each vhost did not close their store.", vhosts.size(), results.size());
+ assertEquals("Each vhost did not close their store.", 1, results.size());
}
catch (AssertionFailedError afe)
{
dumpLogs(results, _monitor);
-
throw afe;
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java b/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java
index bcad59a1fa..82b421a531 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java
@@ -39,7 +39,7 @@ import org.apache.qpid.test.utils.QpidBrokerTestCase;
*/
public class NoLocalAfterRecoveryTest extends QpidBrokerTestCase
{
- protected final String MY_TOPIC_SUBSCRIPTION_NAME = this.getName();
+ protected final String MY_TOPIC_SUBSCRIPTION_NAME = getTestQueueName();
protected static final int SEND_COUNT = 10;
public void testNoLocalNotQueued() throws Exception
diff --git a/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java b/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java
index 8536651ffb..cbf4e032db 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java
@@ -30,6 +30,7 @@ import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
+
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -54,7 +55,9 @@ public class MultipleTransactedBatchProducerTest extends QpidBrokerTestCase
//debug level logging often makes this test pass artificially, turn the level down to info.
setSystemProperty("amqj.server.logging.level", "INFO");
_receivedLatch = new CountDownLatch(MESSAGE_COUNT * NUM_PRODUCERS);
- setConfigurationProperty("management.enabled", "true");
+
+ getBrokerConfiguration().addJmxManagementConfiguration();
+
super.setUp();
_queueName = getTestQueueName();
_failMsg = null;
diff --git a/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java b/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
index 8ccf74a22b..814936f342 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
@@ -26,6 +26,7 @@ import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.jms.ConnectionListener;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.url.URLSyntaxException;
@@ -45,7 +46,7 @@ import java.util.concurrent.TimeUnit;
/**
* Abstract test case for ACLs.
*
- * This base class contains convenience methods to mange ACL files and implements a mechanism that allows each
+ * This base class contains convenience methods to manage ACL files and implements a mechanism that allows each
* test method to run its own setup code before the broker starts.
*
* TODO move the pre broker-startup setup method invocation code to {@link QpidBrokerTestCase}
@@ -58,25 +59,11 @@ public abstract class AbstractACLTestCase extends QpidBrokerTestCase implements
{
/** Used to synchronise {@link #tearDown()} when exceptions are thrown */
protected CountDownLatch _exceptionReceived;
-
- /** Override this to return the name of the configuration XML file. */
- public String getConfig()
- {
- return "config-systests.xml";
- }
- /**
- * This setup method checks {@link #getConfig()} and {@link #getHostList()} to initialise the broker with specific
- * ACL configurations and then runs an optional per-test setup method, which is simply a method with the same name
- * as the test, but starting with {@code setUp} rather than {@code test}.
- *
- * @see org.apache.qpid.test.utils.QpidBrokerTestCase#setUp()
- */
@Override
public void setUp() throws Exception
{
- // Initialise ACLs.
- _configFile = new File("build" + File.separator + "etc" + File.separator + getConfig());
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, System.getProperty(QPID_HOME) + "/etc/groups-systests");
// run test specific setup
String testSetup = StringUtils.replace(getName(), "test", "setUp");
@@ -123,11 +110,11 @@ public abstract class AbstractACLTestCase extends QpidBrokerTestCase implements
if (vhost == null)
{
- testcase.setConfigurationProperty("security.acl", aclFile.getAbsolutePath());
+ testcase.getBrokerConfiguration().setBrokerAttribute(Broker.ACL_FILE, aclFile.getAbsolutePath());
}
else
{
- testcase.setConfigurationProperty("virtualhosts.virtualhost." + vhost + ".security.acl", aclFile.getAbsolutePath());
+ testcase.setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + vhost + ".security.acl", aclFile.getAbsolutePath());
}
PrintWriter out = new PrintWriter(new FileWriter(aclFile));
diff --git a/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java b/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java
index ceff2b998a..1830040007 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java
@@ -33,14 +33,19 @@ import java.lang.management.RuntimeMXBean;
*/
public class ExternalACLJMXTest extends AbstractACLTestCase
{
+
private JMXTestUtils _jmx;
private static final String TEST_QUEUE_OWNER = "admin";
private static final String TEST_VHOST = "test";
+ private static final String TEST2_VHOST = "test2";
@Override
public void setUp() throws Exception
{
+ createTestVirtualHost(0, TEST_VHOST);
+ createTestVirtualHost(0, TEST2_VHOST);
+
_jmx = new JMXTestUtils(this);
_jmx.setUp();
super.setUp();
@@ -54,15 +59,14 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
super.tearDown();
}
- /**
- * Ensure an empty ACL defaults to DENY ALL.
- */
- public void setUpDenyAllIsDefault() throws Exception
+ public void setUpDenyAllIsCatchAllRule() throws Exception
{
- writeACLFile(null, "#Empty ACL file");
+ writeACLFile(null,
+ "ACL ALLOW admin ACCESS MANAGEMENT",
+ "#No more rules, default catch all (deny all) should apply");
}
- public void testDenyAllIsDefault() throws Exception
+ public void testDenyAllIsCatchAllRule() throws Exception
{
//try a broker-level method
ServerInformation info = _jmx.getServerInformation();
@@ -115,6 +119,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
public void setUpVhostAllowOverridesGlobalDeny() throws Exception
{
writeACLFile(null,
+ "ACL ALLOW admin ACCESS MANAGEMENT",
"ACL DENY admin UPDATE METHOD component='VirtualHost.VirtualHostManager' name='createNewQueue'");
writeACLFile(TEST_VHOST,
"ACL ALLOW admin UPDATE METHOD component='VirtualHost.VirtualHostManager' name='createNewQueue'");
@@ -128,7 +133,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
//try a vhost-level method on a different vhost
try
{
- _jmx.createQueue("development", getTestQueueName(), TEST_QUEUE_OWNER, true);
+ _jmx.createQueue(TEST2_VHOST, getTestQueueName(), TEST_QUEUE_OWNER, true);
fail("Exception not thrown");
}
catch (SecurityException e)
@@ -144,6 +149,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
public void setUpUpdateComponentOnlyAllow() throws Exception
{
writeACLFile(null,
+ "ACL ALLOW admin ACCESS MANAGEMENT",
"ACL ALLOW admin UPDATE METHOD component='VirtualHost.VirtualHostManager'");
}
@@ -162,6 +168,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
public void setUpUpdateMethodOnlyAllow() throws Exception
{
writeACLFile(null,
+ "ACL ALLOW admin ACCESS MANAGEMENT",
"ACL ALLOW admin UPDATE METHOD");
}
@@ -179,8 +186,8 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
*/
public void setUpCreateQueueSuccess() throws Exception
{
- writeACLFile(TEST_VHOST,
- "ACL ALLOW admin UPDATE METHOD component='VirtualHost.VirtualHostManager' name='createNewQueue'");
+ writeACLFile(null, "ACL ALLOW admin ACCESS MANAGEMENT");
+ writeACLFile(TEST_VHOST, "ACL ALLOW admin UPDATE METHOD component='VirtualHost.VirtualHostManager' name='createNewQueue'");
}
public void testCreateQueueSuccess() throws Exception
@@ -194,6 +201,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
*/
public void setUpCreateQueueSuccessNoAMQPRights() throws Exception
{
+ writeACLFile(null, "ACL ALLOW admin ACCESS MANAGEMENT");
writeACLFile(TEST_VHOST,
"ACL ALLOW admin UPDATE METHOD component='VirtualHost.VirtualHostManager' name='createNewQueue'",
"ACL DENY admin CREATE QUEUE");
@@ -210,6 +218,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
*/
public void setUpCreateQueueDenied() throws Exception
{
+ writeACLFile(null, "ACL ALLOW admin ACCESS MANAGEMENT");
writeACLFile(TEST_VHOST,
"ACL DENY admin UPDATE METHOD component='VirtualHost.VirtualHostManager' name='createNewQueue'");
}
@@ -234,6 +243,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
public void setUpServerInformationUpdateDenied() throws Exception
{
writeACLFile(null,
+ "ACL ALLOW admin ACCESS MANAGEMENT",
"ACL DENY admin UPDATE METHOD component='ServerInformation' name='resetStatistics'");
}
@@ -258,6 +268,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
public void setUpServerInformationAccessGranted() throws Exception
{
writeACLFile(null,
+ "ACL ALLOW admin ACCESS MANAGEMENT",
"ACL ALLOW-LOG admin ACCESS METHOD component='ServerInformation' name='getManagementApiMajorVersion'");
}
@@ -284,6 +295,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
public void setUpServerInformationUpdateMethodPermission() throws Exception
{
writeACLFile(null,
+ "ACL ALLOW admin ACCESS MANAGEMENT",
"ACL ALLOW admin UPDATE METHOD component='ServerInformation' name='resetStatistics'");
}
@@ -300,7 +312,9 @@ public class ExternalACLJMXTest extends AbstractACLTestCase
*/
public void setUpServerInformationAllMethodPermissions() throws Exception
{
- writeACLFile(null, "ACL ALLOW admin ALL METHOD component='ServerInformation'");
+ writeACLFile(null,
+ "ACL ALLOW admin ACCESS MANAGEMENT",
+ "ACL ALLOW admin ALL METHOD component='ServerInformation'");
}
public void testServerInformationAllMethodPermissions() throws Exception
diff --git a/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLTest.java b/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLTest.java
index 0e45ca9493..8324ac74a5 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLTest.java
@@ -319,8 +319,12 @@ public class ExternalACLTest extends AbstractACLTestCase
public void setUpRequestResponseSuccess() throws Exception
{
- writeACLFile("test", "GROUP messaging-users client server",
- "ACL ALLOW-LOG messaging-users ACCESS VIRTUALHOST",
+ // The group "messaging-users", referenced in the ACL below, is currently defined
+ // in broker/etc/groups-systests.
+ // We tolerate a dependency from this test to that file because its
+ // contents are expected to change rarely.
+
+ writeACLFile("test", "ACL ALLOW-LOG messaging-users ACCESS VIRTUALHOST",
"# Server side",
"ACL ALLOW-LOG server CREATE QUEUE name=\"example.RequestQueue\"" ,
"ACL ALLOW-LOG server BIND EXCHANGE",
@@ -389,14 +393,44 @@ public class ExternalACLTest extends AbstractACLTestCase
conn.start();
// create kipper
- Topic kipper = sess.createTopic("kipper");
- TopicSubscriber subscriber = sess.createDurableSubscriber(kipper, "kipper");
+ String topicName = "kipper";
+ Topic topic = sess.createTopic(topicName);
+ TopicSubscriber subscriber = sess.createDurableSubscriber(topic, topicName);
subscriber.close();
- sess.unsubscribe("kipper");
+ sess.unsubscribe(topicName);
//Do something to show connection is active.
sess.rollback();
conn.close();
}
+
+ public void setUpFirewallAllow() throws Exception
+ {
+ writeACLFile("test", "ACL ALLOW client ACCESS VIRTUALHOST from_network=\"127.0.0.1\"");
+ }
+
+ public void testFirewallAllow() throws Exception
+ {
+ getConnection("test", "client", "guest");
+ // test pass because we successfully connected
+ }
+
+ public void setUpFirewallDeny() throws Exception
+ {
+ writeACLFile("test", "ACL DENY client ACCESS VIRTUALHOST from_network=\"127.0.0.1\"");
+ }
+
+ public void testFirewallDeny() throws Exception
+ {
+ try
+ {
+ getConnection("test", "client", "guest");
+ fail("We expected the connection to fail");
+ }
+ catch(JMSException e)
+ {
+ // pass
+ }
+ }
}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java b/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java
new file mode 100644
index 0000000000..c7a43a292b
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java
@@ -0,0 +1,184 @@
+/*
+ * 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.security.auth.manager;
+
+import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE_PASSWORD;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.client.AMQConnectionURL;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
+public class ExternalAuthenticationTest extends QpidBrokerTestCase
+{
+ @Override
+ protected void setUp() throws Exception
+ {
+ // not calling super.setUp() to avoid broker start-up
+ }
+
+ /**
+ * Tests that when EXTERNAL authentication is used on the SSL port, clients presenting certificates are able to connect.
+ * Also, checks that default authentication manager PrincipalDatabaseAuthenticationManager is used on non SSL port.
+ */
+ public void testExternalAuthenticationManagerOnSSLPort() throws Exception
+ {
+ setCommonBrokerSSLProperties(true);
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_SSL_PORT, Port.AUTHENTICATION_MANAGER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER);
+ super.setUp();
+
+ setClientKeystoreProperties();
+ setClientTrustoreProperties();
+
+ try
+ {
+ getExternalSSLConnection(false);
+ }
+ catch (JMSException e)
+ {
+ fail("Should be able to create a connection to the SSL port: " + e.getMessage());
+ }
+
+ try
+ {
+ getConnection();
+ }
+ catch (JMSException e)
+ {
+ fail("Should be able to create a connection with credentials to the standard port: " + e.getMessage());
+ }
+
+ }
+
+ /**
+ * Tests that when EXTERNAL authentication manager is set as the default, clients presenting certificates are able to connect.
+ * Also, checks a client with valid username and password but not using ssl is unable to connect to the non SSL port.
+ */
+ public void testExternalAuthenticationManagerAsDefault() throws Exception
+ {
+ setCommonBrokerSSLProperties(true);
+ getBrokerConfiguration().setBrokerAttribute(Broker.DEFAULT_AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER);
+ super.setUp();
+
+ setClientKeystoreProperties();
+ setClientTrustoreProperties();
+
+ try
+ {
+ getConnection();
+ fail("Connection should not succeed");
+ }
+ catch (JMSException e)
+ {
+ // pass
+ }
+
+ try
+ {
+ getExternalSSLConnection(false);
+ }
+ catch (JMSException e)
+ {
+ fail("Should be able to create a connection to the SSL port. " + e.getMessage());
+ }
+ }
+
+ /**
+ * Tests that when EXTERNAL authentication manager is set as the default, clients without certificates are unable to connect to the SSL port
+ * even with valid username and password.
+ */
+ public void testExternalAuthenticationManagerWithoutClientKeyStore() throws Exception
+ {
+ setCommonBrokerSSLProperties(false);
+ getBrokerConfiguration().setBrokerAttribute(Broker.DEFAULT_AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER);
+ super.setUp();
+
+ setClientTrustoreProperties();
+
+ try
+ {
+ getExternalSSLConnection(true);
+ fail("Connection should not succeed");
+ }
+ catch (JMSException e)
+ {
+ // pass
+ }
+ }
+
+ private Connection getExternalSSLConnection(boolean includeUserNameAndPassword) throws Exception
+ {
+ String url = "amqp://%s@test/?brokerlist='tcp://localhost:%s?ssl='true'&sasl_mechs='EXTERNAL''";
+ if (includeUserNameAndPassword)
+ {
+ url = String.format(url, "guest:guest", String.valueOf(QpidBrokerTestCase.DEFAULT_SSL_PORT));
+ }
+ else
+ {
+ url = String.format(url, ":", String.valueOf(QpidBrokerTestCase.DEFAULT_SSL_PORT));
+ }
+ return getConnection(new AMQConnectionURL(url));
+ }
+
+ private void setCommonBrokerSSLProperties(boolean needClientAuth) throws ConfigurationException
+ {
+ TestBrokerConfiguration config = getBrokerConfiguration();
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NEED_CLIENT_AUTH, String.valueOf(needClientAuth));
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ config.addPortConfiguration(sslPortAttributes);
+
+ Map<String, Object> externalAuthProviderAttributes = new HashMap<String, Object>();
+ externalAuthProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManagerFactory.PROVIDER_TYPE);
+ externalAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER);
+ config.addAuthenticationProviderConfiguration(externalAuthProviderAttributes);
+ }
+
+ private void setClientKeystoreProperties()
+ {
+ setSystemProperty("javax.net.ssl.keyStore", KEYSTORE);
+ setSystemProperty("javax.net.ssl.keyStorePassword", KEYSTORE_PASSWORD);
+ }
+
+ private void setClientTrustoreProperties()
+ {
+ setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
+ setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
+ setSystemProperty("javax.net.debug", "ssl");
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java b/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java
index 858b32c24c..f41f1159ab 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java
@@ -20,28 +20,44 @@
*/
package org.apache.qpid.server.security.auth.manager;
+import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE_PASSWORD;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.jms.Connection;
import javax.jms.JMSException;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
public class MultipleAuthenticationManagersTest extends QpidBrokerTestCase
{
- private static final String KEYSTORE = "test-profiles/test_resources/ssl/java_client_keystore.jks";
- private static final String KEYSTORE_PASSWORD = "password";
- private static final String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks";
- private static final String TRUSTSTORE_PASSWORD = "password";
-
@Override
protected void setUp() throws Exception
{
- setConfigurationProperty("connector.ssl.enabled", "true");
- setConfigurationProperty("connector.ssl.sslOnly", "false");
- setConfigurationProperty("security.anonymous-auth-manager", "");
- setConfigurationProperty("security.default-auth-manager", "PrincipalDatabaseAuthenticationManager");
- setConfigurationProperty("security.port-mappings.port-mapping.port", String.valueOf(QpidBrokerTestCase.DEFAULT_SSL_PORT));
- setConfigurationProperty("security.port-mappings.port-mapping.auth-manager", "AnonymousAuthenticationManager");
+ TestBrokerConfiguration config = getBrokerConfiguration();
+
+ Map<String, Object> externalAuthProviderAttributes = new HashMap<String, Object>();
+ externalAuthProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, AnonymousAuthenticationManagerFactory.PROVIDER_TYPE);
+ externalAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER);
+ config.addAuthenticationProviderConfiguration(externalAuthProviderAttributes);
+
+ Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
+ sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
+ sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
+ sslPortAttributes.put(Port.AUTHENTICATION_MANAGER, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER);
+ config.addPortConfiguration(sslPortAttributes);
// set the ssl system properties
setSystemProperty("javax.net.ssl.keyStore", KEYSTORE);
diff --git a/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java b/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
deleted file mode 100644
index f5adf815aa..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
+++ /dev/null
@@ -1,283 +0,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.
- */
-package org.apache.qpid.server.security.firewall;
-
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-public class FirewallConfigTest extends QpidBrokerTestCase
-{
- private File _tmpConfig, _tmpVirtualhosts;
- private String _ipAddressOfBrokerHost;
-
- @Override
- protected void setUp() throws Exception
- {
- // Setup initial config file.
- _configFile = new File("build/etc/config-systests-firewall.xml");
-
- // Setup temporary config file
- _tmpConfig = File.createTempFile("config-systests-firewall", ".xml");
- setSystemProperty("QPID_FIREWALL_CONFIG_SETTINGS", _tmpConfig.getAbsolutePath());
- _tmpConfig.deleteOnExit();
-
- // Setup temporary virtualhosts file
- _tmpVirtualhosts = File.createTempFile("virtualhosts-systests-firewall", ".xml");
- setSystemProperty("QPID_FIREWALL_VIRTUALHOSTS_SETTINGS", _tmpVirtualhosts.getAbsolutePath());
- _tmpVirtualhosts.deleteOnExit();
-
- _ipAddressOfBrokerHost = getIpAddressOfBrokerHost();
- }
-
- private void writeFirewallFile(boolean allow, boolean inVhost) throws IOException
- {
- FileWriter out = new FileWriter(inVhost ? _tmpVirtualhosts : _tmpConfig);
- if (inVhost)
- {
- out.write("<virtualhosts><virtualhost><test>");
- }
- else
- {
- out.write("<broker>");
- }
- out.write("<security><firewall>");
- out.write("<rule access=\""+((allow) ? "allow" : "deny")+"\" network=\"" + _ipAddressOfBrokerHost + "\"/>");
- out.write("</firewall></security>");
- if (inVhost)
- {
- out.write("</test></virtualhost></virtualhosts>");
- }
- else
- {
- out.write("</broker>");
- }
- out.close();
- }
-
- public void testVhostAllowBrokerDeny() throws Exception
- {
-
- _configFile = new File("build/etc/config-systests-firewall-2.xml");
-
- super.setUp();
- try
- {
- //Try to get a connection to the 'test2' vhost
- //This is expected to succeed as it is allowed at the vhost level
- getConnection(new AMQConnectionURL("amqp://guest:guest@clientid/test2?brokerlist='" + getBroker() + "'"));
- }
- catch (JMSException e)
- {
- e.getLinkedException().printStackTrace();
- fail("The connection was expected to succeed: " + e.getMessage());
- }
-
- try
- {
- //Try to get a connection to the 'test' vhost
- //This is expected to fail as it is denied at the broker level
- getConnection();
- fail("We expected the connection to fail");
- }
- catch (JMSException e)
- {
- //ignore
- }
- }
-
- public void testVhostDenyBrokerAllow() throws Exception
- {
- _configFile = new File("build/etc/config-systests-firewall-3.xml");
-
- super.setUp();
- try
- {
- //Try to get a connection to the 'test2' vhost
- //This is expected to fail as it is denied at the vhost level
- getConnection(new AMQConnectionURL("amqp://guest:guest@clientid/test2?brokerlist='" + getBroker() + "'"));
- fail("The connection was expected to fail");
- }
- catch (JMSException e)
- {
- //ignore
- }
-
- try
- {
- //Try to get a connection to the 'test' vhost
- //This is expected to succeed as it is allowed at the broker level
- getConnection();
- }
- catch (JMSException e)
- {
- e.getLinkedException().printStackTrace();
- fail("The connection was expected to succeed: " + e.getMessage());
- }
- }
-
- public void testDenyOnRestart() throws Exception
- {
- testDeny(false, new Runnable() {
-
- public void run()
- {
- try
- {
- restartBroker();
- } catch (Exception e)
- {
- fail(e.getMessage());
- }
- }
- });
- }
-
- public void testDenyOnRestartInVhost() throws Exception
- {
- testDeny(true, new Runnable() {
-
- public void run()
- {
- try
- {
- restartBroker();
- } catch (Exception e)
- {
- fail(e.getMessage());
- }
- }
- });
- }
-
- public void testAllowOnReloadInVhost() throws Exception
- {
- testFirewall(false, true, new Runnable() {
-
- public void run()
- {
- try
- {
- reloadBrokerSecurityConfig();
- } catch (Exception e)
- {
- fail(e.getMessage());
- }
- }
- });
- }
-
- public void testDenyOnReload() throws Exception
- {
- testDeny(false, new Runnable() {
-
- public void run()
- {
- try
- {
- reloadBrokerSecurityConfig();
- } catch (Exception e)
- {
- fail(e.getMessage());
- }
- }
- }
- );
- }
-
- public void testDenyOnReloadInVhost() throws Exception
- {
- testDeny(true, new Runnable() {
-
- public void run()
- {
- try
- {
- reloadBrokerSecurityConfig();
- } catch (Exception e)
- {
- fail(e.getMessage());
- }
- }
- }
- );
-
- }
-
- private void testDeny(boolean inVhost, Runnable restartOrReload) throws Exception
- {
- testFirewall(true, inVhost, restartOrReload);
- }
-
- /*
- * Check we can get a connection
- */
- private boolean checkConnection() throws Exception
- {
- Exception exception = null;
- Connection conn = null;
- try
- {
- conn = getConnection();
- }
- catch (JMSException e)
- {
- exception = e;
- }
-
- return conn != null;
- }
-
- private void testFirewall(boolean initial, boolean inVhost, Runnable restartOrReload) throws Exception
- {
-
- writeFirewallFile(initial, inVhost);
- setConfigurationProperty("management.enabled", String.valueOf(true));
- super.setUp();
-
- assertEquals("Initial connection check failed", initial, checkConnection());
-
- // Reload changed firewall file after restart or reload
- writeFirewallFile(!initial, inVhost);
- restartOrReload.run();
-
- assertEquals("Second connection check failed", !initial, checkConnection());
- }
-
- private String getIpAddressOfBrokerHost()
- {
- String brokerHost = getBroker().getHost();
- try
- {
- return InetAddress.getByName(brokerHost).getHostAddress();
- }
- catch (UnknownHostException e)
- {
- throw new RuntimeException("Could not determine IP address of host : " + brokerHost, e);
- }
-
- }
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java b/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java
index c38fcd9199..6d53896371 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java
@@ -27,10 +27,13 @@ import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.util.LogMonitor;
import java.util.List;
+import java.util.Map;
import javax.jms.Connection;
import javax.jms.Destination;
@@ -45,46 +48,55 @@ import javax.jms.TextMessage;
*/
public class StatisticsReportingTest extends QpidBrokerTestCase
{
+ private static final String VHOST_NAME1 = "vhost1";
+ private static final String VHOST_NAME2 = "vhost2";
+ private static final String VHOST_NAME3 = "vhost3";
+ private static long STATISTICS_REPORTING_PERIOD_IN_SECONDS = 10l;
+
protected LogMonitor _monitor;
protected static final String USER = "admin";
- protected Connection _test, _dev, _local;
+ protected Connection _conToVhost1, _conToVhost2, _conToVhost3;
protected String _queueName = "statistics";
protected Destination _queue;
protected String _brokerUrl;
+ private long _startTestTime;
@Override
public void setUp() throws Exception
{
- setConfigurationProperty("statistics.generation.broker", "true");
- setConfigurationProperty("statistics.generation.virtualhosts", "true");
+ createTestVirtualHost(0, VHOST_NAME1);
+ createTestVirtualHost(0, VHOST_NAME2);
+ createTestVirtualHost(0, VHOST_NAME3);
if (getName().equals("testEnabledStatisticsReporting"))
{
- setConfigurationProperty("statistics.reporting.period", "10");
+ TestBrokerConfiguration config = getBrokerConfiguration();
+ config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST);
+ config.setBrokerAttribute(Broker.STATISTICS_REPORTING_PERIOD, STATISTICS_REPORTING_PERIOD_IN_SECONDS);
}
_monitor = new LogMonitor(_outputFile);
+ _startTestTime = System.currentTimeMillis();
super.setUp();
_brokerUrl = getBroker().toString();
- _test = new AMQConnection(_brokerUrl, USER, USER, "clientid", "test");
- _dev = new AMQConnection(_brokerUrl, USER, USER, "clientid", "development");
- _local = new AMQConnection(_brokerUrl, USER, USER, "clientid", "localhost");
-
- _test.start();
- _dev.start();
- _local.start();
+ _conToVhost1 = new AMQConnection(_brokerUrl, USER, USER, "clientid", VHOST_NAME1);
+ _conToVhost2 = new AMQConnection(_brokerUrl, USER, USER, "clientid", VHOST_NAME2);
+ _conToVhost3 = new AMQConnection(_brokerUrl, USER, USER, "clientid", VHOST_NAME3);
+ _conToVhost1.start();
+ _conToVhost2.start();
+ _conToVhost3.start();
}
@Override
public void tearDown() throws Exception
{
- _test.close();
- _dev.close();
- _local.close();
+ _conToVhost1.close();
+ _conToVhost2.close();
+ _conToVhost3.close();
super.tearDown();
}
@@ -94,21 +106,30 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
*/
public void testEnabledStatisticsReporting() throws Exception
{
- sendUsing(_test, 10, 100);
- sendUsing(_dev, 20, 100);
- sendUsing(_local, 15, 100);
-
- Thread.sleep(10 * 1000); // 15s
-
- List<String> brokerStatsData = _monitor.findMatches("BRK-1008");
- List<String> brokerStatsMessages = _monitor.findMatches("BRK-1009");
- List<String> vhostStatsData = _monitor.findMatches("VHT-1003");
- List<String> vhostStatsMessages = _monitor.findMatches("VHT-1004");
-
- assertEquals("Incorrect number of broker data stats log messages", 2, brokerStatsData.size());
- assertEquals("Incorrect number of broker message stats log messages", 2, brokerStatsMessages.size());
- assertEquals("Incorrect number of virtualhost data stats log messages", 6, vhostStatsData.size());
- assertEquals("Incorrect number of virtualhost message stats log messages", 6, vhostStatsMessages.size());
+ sendUsing(_conToVhost1, 10, 100);
+ sendUsing(_conToVhost2, 20, 100);
+ sendUsing(_conToVhost3, 15, 100);
+
+ Thread.sleep(STATISTICS_REPORTING_PERIOD_IN_SECONDS * 1000);
+
+ Map<String, List<String>> brokerStatsData = _monitor.findMatches("BRK-1008", "BRK-1009", "VHT-1003", "VHT-1004");
+ long endTestTime = System.currentTimeMillis();
+
+ int maxNumberOfReports = (int)((endTestTime - _startTestTime)/STATISTICS_REPORTING_PERIOD_IN_SECONDS);
+
+ int brk1008LinesNumber = brokerStatsData.get("BRK-1008").size();
+ int brk1009LinesNumber = brokerStatsData.get("BRK-1009").size();
+ int vht1003LinesNumber = brokerStatsData.get("VHT-1003").size();
+ int vht1004LinesNumber = brokerStatsData.get("VHT-1004").size();
+
+ assertTrue("Incorrect number of broker data stats log messages:" + brk1008LinesNumber, 2 <= brk1008LinesNumber
+ && brk1008LinesNumber <= maxNumberOfReports * 2);
+ assertTrue("Incorrect number of broker message stats log messages:" + brk1009LinesNumber, 2 <= brk1009LinesNumber
+ && brk1009LinesNumber <= maxNumberOfReports * 2);
+ assertTrue("Incorrect number of virtualhost data stats log messages:" + vht1003LinesNumber, 6 <= vht1003LinesNumber
+ && vht1003LinesNumber <= maxNumberOfReports * 6);
+ assertTrue("Incorrect number of virtualhost message stats log messages: " + vht1004LinesNumber, 6 <= vht1004LinesNumber
+ && vht1004LinesNumber <= maxNumberOfReports * 6);
}
/**
@@ -116,9 +137,9 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
*/
public void testNotEnabledStatisticsReporting() throws Exception
{
- sendUsing(_test, 10, 100);
- sendUsing(_dev, 20, 100);
- sendUsing(_local, 15, 100);
+ sendUsing(_conToVhost1, 10, 100);
+ sendUsing(_conToVhost2, 20, 100);
+ sendUsing(_conToVhost3, 15, 100);
Thread.sleep(10 * 1000); // 15s
@@ -135,7 +156,7 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
private void sendUsing(Connection con, int number, int size) throws Exception
{
- Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session session = con.createSession(true, Session.SESSION_TRANSACTED);
createQueue(session);
MessageProducer producer = session.createProducer(_queue);
String content = new String(new byte[size]);
@@ -144,6 +165,8 @@ public class StatisticsReportingTest extends QpidBrokerTestCase
{
producer.send(msg);
}
+ session.commit();
+ session.close();
}
private void createQueue(Session session) throws AMQException, JMSException
diff --git a/java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java b/java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java
index 9db04b64b3..6d38004451 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/store/SlowMessageStore.java
@@ -27,8 +27,6 @@ import org.apache.qpid.AMQStoreException;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.server.binding.Binding;
import org.apache.qpid.server.exchange.Exchange;
-import org.apache.qpid.server.federation.Bridge;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.message.EnqueableMessage;
import org.apache.qpid.server.message.ServerMessage;
import org.apache.qpid.server.queue.AMQQueue;
@@ -322,35 +320,6 @@ public class SlowMessageStore implements MessageStore
doPostDelay("updateQueue");
}
-
- public void createBrokerLink(final BrokerLink link) throws AMQStoreException
- {
- doPreDelay("createBrokerLink");
- _durableConfigurationStore.createBrokerLink(link);
- doPostDelay("createBrokerLink");
- }
-
- public void deleteBrokerLink(final BrokerLink link) throws AMQStoreException
- {
- doPreDelay("deleteBrokerLink");
- _durableConfigurationStore.deleteBrokerLink(link);
- doPostDelay("deleteBrokerLink");
- }
-
- public void createBridge(final Bridge bridge) throws AMQStoreException
- {
- doPreDelay("createBridge");
- _durableConfigurationStore.createBridge(bridge);
- doPostDelay("createBridge");
- }
-
- public void deleteBridge(final Bridge bridge) throws AMQStoreException
- {
- doPreDelay("deleteBridge");
- _durableConfigurationStore.deleteBridge(bridge);
- doPostDelay("deleteBridge");
- }
-
@Override
public void activate() throws Exception
{
diff --git a/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java b/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java
index 9fb1db3a4f..61ca6d9c28 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java
@@ -60,9 +60,9 @@ public class StoreOverfullTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
- setConfigurationProperty("virtualhosts.virtualhost.test.store.class", QuotaMessageStore.class.getName());
- setConfigurationProperty("virtualhosts.virtualhost.test.store.overfull-size", String.valueOf(OVERFULL_SIZE));
- setConfigurationProperty("virtualhosts.virtualhost.test.store.underfull-size", String.valueOf(UNDERFULL_SIZE));
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.class", QuotaMessageStore.class.getName());
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.overfull-size", String.valueOf(OVERFULL_SIZE));
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.underfull-size", String.valueOf(UNDERFULL_SIZE));
super.setUp();
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/GlobalQueuesTest.java b/java/systests/src/main/java/org/apache/qpid/systest/GlobalQueuesTest.java
deleted file mode 100644
index 9ff143daf3..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/systest/GlobalQueuesTest.java
+++ /dev/null
@@ -1,223 +0,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.
- *
- */
-package org.apache.qpid.systest;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import javax.jms.Session;
-import javax.naming.NamingException;
-import java.io.IOException;
-
-/**
- * QPID-1447 : Add slow consumer detection and disconnection.
- *
- * Slow consumers should on a topic should expect to receive a
- * 506 : Resource Error if the hit a predefined threshold.
- */
-public class GlobalQueuesTest extends TestingBaseCase
-{
-
- protected String CONFIG_SECTION = ".queues";
-
- /**
- * Queue Configuration
-
- <slow-consumer-detection>
- <!-- The depth before which the policy will be applied-->
- <depth>4235264</depth>
-
- <!-- The message age before which the policy will be applied-->
- <messageAge>600000</messageAge>
-
- <!-- The number of message before which the policy will be applied-->
- <messageCount>50</messageCount>
-
- <!-- Policies configuration -->
- <policy>
- <name>TopicDelete</name>
- <topicDelete>
- <delete-persistent/>
- </topicDelete>
- </policy>
- </slow-consumer-detection>
-
- */
-
-
- /**
- * VirtualHost Plugin Configuration
-
- <slow-consumer-detection>
- <delay>1</delay>
- <timeunit>MINUTES</timeunit>
- </slow-consumer-detection>
-
- */
-
- public void setConfig(String property, String value, boolean deleteDurable) throws NamingException, IOException, ConfigurationException
- {
- setProperty(CONFIG_SECTION + ".slow-consumer-detection." +
- "policy.name", "TopicDelete");
-
- setProperty(CONFIG_SECTION + ".slow-consumer-detection." +
- property, value);
-
- if (deleteDurable)
- {
- setProperty(CONFIG_SECTION + ".slow-consumer-detection." +
- "policy.topicdelete.delete-persistent", "");
- }
- }
-
- /**
- * Test that setting messageCount takes affect on topics
- *
- * We send 10 messages and disconnect at 9
- *
- * @throws Exception
- */
- public void testTopicConsumerMessageCount() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("messageCount", String.valueOf(MAX_QUEUE_MESSAGE_COUNT - 1), false);
-
- //Start the broker
- startBroker();
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, false);
- }
-
- /**
- * Test that setting depth has an effect on topics
- *
- * Sets the message size for the test
- * Sets the depth to be 9 * the depth
- * Ensure that sending 10 messages causes the disconnection
- *
- * @throws Exception
- */
- public void testTopicConsumerMessageSize() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("depth", String.valueOf(MESSAGE_SIZE * 9), false);
-
- //Start the broker
- startBroker();
-
- setMessageSize(MESSAGE_SIZE);
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, false);
- }
-
- /**
- * Test that setting messageAge has an effect on topics
- *
- * Sets the messageAge to be half the disconnection wait timeout
- * Send 10 messages and then ensure that we get disconnected as we will
- * wait for the full timeout.
- *
- * @throws Exception
- */
- public void testTopicConsumerMessageAge() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("messageAge", String.valueOf(DISCONNECTION_WAIT / 2), false);
-
- //Start the broker
- startBroker();
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, false);
- }
-
- /**
- * Test that setting messageCount takes affect on a durable Consumer
- *
- * Ensure we set the delete-persistent option
- *
- * We send 10 messages and disconnect at 9
- *
- * @throws Exception
- */
-
- public void testTopicDurableConsumerMessageCount() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("messageCount", String.valueOf(MAX_QUEUE_MESSAGE_COUNT - 1), true);
-
- //Start the broker
- startBroker();
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, true);
- }
-
- /**
- * Test that setting depth has an effect on durable consumer topics
- *
- * Ensure we set the delete-persistent option
- *
- * Sets the message size for the test
- * Sets the depth to be 9 * the depth
- * Ensure that sending 10 messages causes the disconnection
- *
- * @throws Exception
- */
- public void testTopicDurableConsumerMessageSize() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("depth", String.valueOf(MESSAGE_SIZE * 9), true);
-
- //Start the broker
- startBroker();
-
- setMessageSize(MESSAGE_SIZE);
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, true);
- }
-
- /**
- * Test that setting messageAge has an effect on topics
- *
- * Ensure we set the delete-persistent option
- *
- * Sets the messageAge to be 1/5 the disconnection wait timeout (or 1sec)
- * Send 10 messages and then ensure that we get disconnected as we will
- * wait for the full timeout.
- *
- * @throws Exception
- */
- public void testTopicDurableConsumerMessageAge() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("messageAge", String.valueOf(DISCONNECTION_WAIT / 5), true);
-
- //Start the broker
- startBroker();
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, true);
- }
-
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/GlobalTopicsTest.java b/java/systests/src/main/java/org/apache/qpid/systest/GlobalTopicsTest.java
deleted file mode 100644
index 6297478883..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/systest/GlobalTopicsTest.java
+++ /dev/null
@@ -1,31 +0,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.
- *
- */
-package org.apache.qpid.systest;
-
-public class GlobalTopicsTest extends GlobalQueuesTest
-{
- @Override
- public void setUp() throws Exception
- {
- CONFIG_SECTION = ".topics";
- super.setUp();
- }
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/MergeConfigurationTest.java b/java/systests/src/main/java/org/apache/qpid/systest/MergeConfigurationTest.java
deleted file mode 100644
index 993d71ea34..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/systest/MergeConfigurationTest.java
+++ /dev/null
@@ -1,109 +0,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.
- *
- */
-package org.apache.qpid.systest;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import javax.jms.Session;
-import javax.naming.NamingException;
-import java.io.IOException;
-
-public class MergeConfigurationTest extends TestingBaseCase
-{
-
- protected int topicCount = 0;
-
-
- public void configureTopic(String topic, int msgCount) throws NamingException, IOException, ConfigurationException
- {
-
- setProperty(".topics.topic("+topicCount+").name", topic);
- setProperty(".topics.topic("+topicCount+").slow-consumer-detection.messageCount", String.valueOf(msgCount));
- setProperty(".topics.topic("+topicCount+").slow-consumer-detection.policy.name", "TopicDelete");
- topicCount++;
- }
-
-
- /**
- * Test that setting messageCount takes affect on topics
- *
- * We send 10 messages and disconnect at 9
- *
- * @throws Exception
- */
- public void testTopicConsumerMessageCount() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- configureTopic(getName(), (MAX_QUEUE_MESSAGE_COUNT * 4) - 1);
-
- //Configure topic as a subscription
- setProperty(".topics.topic("+topicCount+").subscriptionName", "clientid:"+getTestQueueName());
- configureTopic(getName(), (MAX_QUEUE_MESSAGE_COUNT - 1));
-
-
-
- //Start the broker
- startBroker();
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, true);
- }
-
-
-//
-// public void testMerge() throws ConfigurationException, AMQException
-// {
-//
-// AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString(getName()+":stockSubscription"), false, new AMQShortString("testowner"),
-// false, false, _virtualHost, null);
-//
-// _virtualHost.getQueueRegistry().registerQueue(queue);
-// Exchange defaultExchange = _virtualHost.getExchangeRegistry().getDefaultExchange();
-// _virtualHost.getBindingFactory().addBinding(getName(), queue, defaultExchange, null);
-//
-//
-// Exchange topicExchange = _virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME);
-// _virtualHost.getBindingFactory().addBinding("stocks.nyse.orcl", queue, topicExchange, null);
-//
-// TopicConfig config = queue.getConfiguration().getConfiguration(TopicConfig.class.getName());
-//
-// assertNotNull("Queue should have topic configuration bound to it.", config);
-// assertEquals("Configuration name not correct", getName() + ":stockSubscription", config.getSubscriptionName());
-//
-// ConfigurationPlugin scdConfig = queue.getConfiguration().getConfiguration(SlowConsumerDetectionQueueConfiguration.class.getName());
-// if (scdConfig instanceof org.apache.qpid.server.configuration.plugin.SlowConsumerDetectionQueueConfiguration)
-// {
-// System.err.println("********************** scd is a SlowConsumerDetectionQueueConfiguration.");
-// }
-// else
-// {
-// System.err.println("********************** Test SCD "+SlowConsumerDetectionQueueConfiguration.class.getClassLoader());
-// System.err.println("********************** Broker SCD "+scdConfig.getClass().getClassLoader());
-// System.err.println("********************** Broker SCD "+scdConfig.getClass().isAssignableFrom(SlowConsumerDetectionQueueConfiguration.class));
-// System.err.println("********************** is a "+scdConfig.getClass());
-// }
-//
-// assertNotNull("Queue should have scd configuration bound to it.", scdConfig);
-// assertEquals("MessageCount is not correct", 10 , ((SlowConsumerDetectionQueueConfiguration)scdConfig).getMessageCount());
-// assertEquals("Policy is not correct", TopicDeletePolicy.class.getName() , ((SlowConsumerDetectionQueueConfiguration)scdConfig).getPolicy().getClass().getName());
-// }
-
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/SubscriptionTest.java b/java/systests/src/main/java/org/apache/qpid/systest/SubscriptionTest.java
deleted file mode 100644
index 9e9375fd44..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/systest/SubscriptionTest.java
+++ /dev/null
@@ -1,146 +0,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.
- *
- */
-package org.apache.qpid.systest;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import javax.jms.Session;
-import javax.naming.NamingException;
-import java.io.IOException;
-
-/**
- * Test SCD when configured with Subscription details.
- *
- * We run the subscription based tests here to validate that the
- * subscriptionname value is correctly associated with the subscription.
- *
- *
- */
-public class SubscriptionTest extends TestingBaseCase
-{
- private int _count=0;
- protected String CONFIG_SECTION = ".topics.topic";
-
- /**
- * Add configuration for the queue that relates just to this test.
- * We use the getTestQueueName() as our subscription. To ensure the
- * config sections do not overlap we identify each section with a _count
- * value.
- *
- * This would allow each test to configure more than one section.
- *
- * @param property to set
- * @param value the value to set
- * @param deleteDurable should deleteDurable be set.
- * @throws NamingException
- * @throws IOException
- * @throws ConfigurationException
- */
- public void setConfig(String property, String value, boolean deleteDurable) throws NamingException, IOException, ConfigurationException
- {
- setProperty(CONFIG_SECTION + "("+_count+").subscriptionName", "clientid:"+getTestQueueName());
-
- setProperty(CONFIG_SECTION + "("+_count+").slow-consumer-detection." +
- "policy.name", "TopicDelete");
-
- setProperty(CONFIG_SECTION + "("+_count+").slow-consumer-detection." +
- property, value);
-
- if (deleteDurable)
- {
- setProperty(CONFIG_SECTION + "("+_count+").slow-consumer-detection." +
- "policy.topicdelete.delete-persistent", "");
- }
- _count++;
- }
-
-
- /**
- * Test that setting messageCount takes affect on a durable Consumer
- *
- * Ensure we set the delete-persistent option
- *
- * We send 10 messages and disconnect at 9
- *
- * @throws Exception
- */
-
- public void testTopicDurableConsumerMessageCount() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("messageCount", String.valueOf(MAX_QUEUE_MESSAGE_COUNT - 1), true);
-
- //Start the broker
- startBroker();
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, true);
- }
-
- /**
- * Test that setting depth has an effect on durable consumer topics
- *
- * Ensure we set the delete-persistent option
- *
- * Sets the message size for the test
- * Sets the depth to be 9 * the depth
- * Ensure that sending 10 messages causes the disconnection
- *
- * @throws Exception
- */
- public void testTopicDurableConsumerMessageSize() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("depth", String.valueOf(MESSAGE_SIZE * 9), true);
-
- //Start the broker
- startBroker();
-
- setMessageSize(MESSAGE_SIZE);
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, true);
- }
-
- /**
- * Test that setting messageAge has an effect on topics
- *
- * Ensure we set the delete-persistent option
- *
- * Sets the messageAge to be 1/5 the disconnection wait timeout (or 1sec)
- * Send 10 messages and then ensure that we get disconnected as we will
- * wait for the full timeout.
- *
- * @throws Exception
- */
- public void testTopicDurableConsumerMessageAge() throws Exception
- {
- MAX_QUEUE_MESSAGE_COUNT = 10;
-
- setConfig("messageAge", String.valueOf(DISCONNECTION_WAIT / 5), true);
-
- //Start the broker
- startBroker();
-
- topicConsumer(Session.AUTO_ACKNOWLEDGE, true);
- }
-
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/TestingBaseCase.java b/java/systests/src/main/java/org/apache/qpid/systest/TestingBaseCase.java
deleted file mode 100644
index 86c9462fc9..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/systest/TestingBaseCase.java
+++ /dev/null
@@ -1,240 +0,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.
- *
- */
-package org.apache.qpid.systest;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.jms.ConnectionListener;
-import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.naming.NamingException;
-import java.io.IOException;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-public class TestingBaseCase extends QpidBrokerTestCase implements ExceptionListener, ConnectionListener
-{
-
- private Topic _destination;
- protected CountDownLatch _disconnectionLatch = new CountDownLatch(1);
- protected int MAX_QUEUE_MESSAGE_COUNT;
- protected int MESSAGE_SIZE = DEFAULT_MESSAGE_SIZE;
-
- private Thread _publisher;
- protected static final long DISCONNECTION_WAIT = 5;
- protected Exception _publisherError = null;
- protected JMSException _connectionException = null;
- private static final long JOIN_WAIT = 5000;
-
- @Override
- public void setUp() throws Exception
- {
-
- setConfigurationProperty("virtualhosts.virtualhost."
- + getConnectionURL().getVirtualHost().substring(1) +
- ".slow-consumer-detection.delay", "1");
-
- setConfigurationProperty("virtualhosts.virtualhost."
- + getConnectionURL().getVirtualHost().substring(1) +
- ".slow-consumer-detection.timeunit", "SECONDS");
-
- }
-
-
- protected void setProperty(String property, String value) throws NamingException, IOException, ConfigurationException
- {
- setConfigurationProperty("virtualhosts.virtualhost." +
- getConnectionURL().getVirtualHost().substring(1) +
- property, value);
- }
-
-
- /**
- * Create and start an asynchrounous publisher that will send MAX_QUEUE_MESSAGE_COUNT
- * messages to the provided destination. Messages are sent in a new connection
- * on a transaction. Any error is captured and the test is signalled to exit.
- *
- * @param destination
- */
- private void startPublisher(final Destination destination)
- {
- _publisher = new Thread(new Runnable()
- {
-
- public void run()
- {
- try
- {
- Connection connection = getConnection();
- Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-
- MessageProducer publisher = session.createProducer(destination);
-
- for (int count = 0; count < MAX_QUEUE_MESSAGE_COUNT; count++)
- {
- publisher.send(createNextMessage(session, count));
- session.commit();
- }
- }
- catch (Exception e)
- {
- _publisherError = e;
- _disconnectionLatch.countDown();
- }
- }
- });
-
- _publisher.start();
- }
-
-
-
- /**
- * Perform the Main test of a topic Consumer with the given AckMode.
- *
- * Test creates a new connection and sets up the connection to prevent
- * failover
- *
- * A new consumer is connected and started so that it will prefetch msgs.
- *
- * An asynchrounous publisher is started to fill the broker with messages.
- *
- * We then wait to be notified of the disconnection via the ExceptionListener
- *
- * 0-10 does not have the same notification paths but sync() apparently should
- * give us the exception, currently it doesn't, so the test is excluded from 0-10
- *
- * We should ensure that this test has the same path for all protocol versions.
- *
- * Clients should not have to modify their code based on the protocol in use.
- *
- * @param ackMode @see javax.jms.Session
- *
- * @throws Exception
- */
- protected void topicConsumer(int ackMode, boolean durable) throws Exception
- {
- Connection connection = getConnection();
-
- connection.setExceptionListener(this);
-
- Session session = connection.createSession(ackMode == Session.SESSION_TRANSACTED, ackMode);
-
- _destination = session.createTopic(getName());
-
- MessageConsumer consumer;
-
- if (durable)
- {
- consumer = session.createDurableSubscriber(_destination, getTestQueueName());
- }
- else
- {
- consumer = session.createConsumer(_destination);
- }
-
- connection.start();
-
- // Start the consumer pre-fetching
- // Don't care about response as we will fill the broker up with messages
- // after this point and ensure that the client is disconnected at the
- // right point.
- consumer.receiveNoWait();
- startPublisher(_destination);
-
- boolean disconnected = _disconnectionLatch.await(DISCONNECTION_WAIT, TimeUnit.SECONDS);
-
- assertTrue("Client was not disconnected", disconnected);
- assertTrue("Client was not disconnected.", _connectionException != null);
-
- Exception linked = _connectionException.getLinkedException();
-
- _publisher.join(JOIN_WAIT);
-
- assertFalse("Publisher still running", _publisher.isAlive());
-
- //Validate publishing occurred ok
- if (_publisherError != null)
- {
- throw _publisherError;
- }
-
- // NOTE these exceptions will need to be modeled so that they are not
- // 0-8 specific. e.g. JMSSessionClosedException
-
- assertNotNull("No error received onException listener.", _connectionException);
-
- assertNotNull("No linked exception set on:" + _connectionException.getMessage(), linked);
-
- assertTrue("Incorrect linked exception received.", linked instanceof AMQException);
-
- AMQException amqException = (AMQException) linked;
-
- assertEquals("Channel was not closed with correct code.", AMQConstant.RESOURCE_ERROR, amqException.getErrorCode());
- }
-
-
- // Exception Listener
-
- public void onException(JMSException e)
- {
- _connectionException = e;
-
- e.printStackTrace();
-
- _disconnectionLatch.countDown();
- }
-
- /// Connection Listener
-
- public void bytesSent(long count)
- {
- }
-
- public void bytesReceived(long count)
- {
- }
-
- public boolean preFailover(boolean redirect)
- {
- // Prevent Failover
- return false;
- }
-
- public boolean preResubscribe()
- {
- return false;
- }
-
- public void failoverComplete()
- {
- }
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/TopicTest.java b/java/systests/src/main/java/org/apache/qpid/systest/TopicTest.java
deleted file mode 100644
index 09c849cfde..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/systest/TopicTest.java
+++ /dev/null
@@ -1,85 +0,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.
- *
- */
-package org.apache.qpid.systest;
-
-import org.apache.commons.configuration.ConfigurationException;
-
-import javax.naming.NamingException;
-import java.io.IOException;
-
-/**
- * This Topic test extends the Global queue test so it will run all the topic
- * and subscription tests.
- *
- * We redefine the CONFIG_SECTION here so that the configuration is written
- * against a topic element.
- *
- * To complete the migration to testing 'topic' elements we also override
- * the setConfig to use the test name as the topic name.
- *
- */
-public class TopicTest extends GlobalQueuesTest
-{
- private int _count=0;
-
- @Override
- public void setUp() throws Exception
- {
- CONFIG_SECTION = ".topics.topic";
- super.setUp();
- }
-
- /**
- * Add configuration for the queue that relates just to this test.
- * We use the getTestQueueName() as our subscription. To ensure the
- * config sections do not overlap we identify each section with a _count
- * value.
- *
- * This would allow each test to configure more than one section.
- *
- * @param property to set
- * @param value the value to set
- * @param deleteDurable should deleteDurable be set.
- * @throws NamingException
- * @throws IOException
- * @throws ConfigurationException
- */
- @Override
- public void setConfig(String property, String value, boolean deleteDurable) throws NamingException, IOException, ConfigurationException
- {
- setProperty(CONFIG_SECTION + "("+_count+").name", getName());
-
- setProperty(CONFIG_SECTION + "("+_count+").slow-consumer-detection." +
- "policy.name", "TopicDelete");
-
- setProperty(CONFIG_SECTION + "("+_count+").slow-consumer-detection." +
- property, value);
-
- if (deleteDurable)
- {
- setProperty(CONFIG_SECTION + "("+_count+").slow-consumer-detection." +
- "policy.topicdelete.delete-persistent", "");
- }
- _count++;
- }
-
-
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java
new file mode 100644
index 0000000000..954208e78e
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.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.systest.management.jmx;
+
+import org.apache.qpid.exchange.ExchangeDefaults;
+import org.apache.qpid.management.common.mbeans.ManagedBroker;
+import org.apache.qpid.management.common.mbeans.ManagedExchange;
+import org.apache.qpid.test.utils.JMXTestUtils;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+
+/**
+ * Tests the JMX API for the Managed Broker.
+ *
+ */
+public class BrokerManagementTest extends QpidBrokerTestCase
+{
+ private static final String VIRTUAL_HOST = "test";
+
+ /**
+ * JMX helper.
+ */
+ private JMXTestUtils _jmxUtils;
+ private ManagedBroker _managedBroker;
+
+ public void setUp() throws Exception
+ {
+ _jmxUtils = new JMXTestUtils(this);
+ _jmxUtils.setUp();
+ super.setUp();
+ _jmxUtils.open();
+ _managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST);
+ }
+
+ public void tearDown() throws Exception
+ {
+ if (_jmxUtils != null)
+ {
+ _jmxUtils.close();
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Tests queue creation/deletion also verifying the automatic binding to the default exchange.
+ */
+ public void testCreateQueueAndDeletion() throws Exception
+ {
+ final String queueName = getTestQueueName();
+ final ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString());
+
+ // Check that bind does not exist before queue creation
+ assertFalse("Binding to " + queueName + " should not exist in default exchange before queue creation",
+ defaultExchange.bindings().containsKey(new String[] {queueName}));
+
+ _managedBroker.createNewQueue(queueName, "testowner", true);
+
+ // Ensure the queue exists
+ assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName));
+ assertNotNull("Manager queue expected to be available", _jmxUtils.getManagedQueue(queueName));
+
+ // Now verify that the default exchange has been bound.
+ assertTrue("Binding to " + queueName + " should exist in default exchange after queue creation",
+ defaultExchange.bindings().containsKey(new String[] {queueName}));
+
+ // Now delete the queue
+ _managedBroker.deleteQueue(queueName);
+
+ // Finally ensure that the binding has been removed.
+ assertFalse("Binding to " + queueName + " should not exist in default exchange after queue deletion",
+ defaultExchange.bindings().containsKey(new String[] {queueName}));
+ }
+
+ /**
+ * Tests exchange creation/deletion via JMX API.
+ */
+ public void testCreateExchangeAndUnregister() throws Exception
+ {
+ String exchangeName = getTestName();
+ _managedBroker.createNewExchange(exchangeName, "topic", true);
+
+ ManagedExchange exchange = _jmxUtils.getManagedExchange(exchangeName);
+ assertNotNull("Exchange should exist", exchange);
+
+ _managedBroker.unregisterExchange(exchangeName);
+ }
+
+ /**
+ * Tests that it is disallowed to unregister the default exchange.
+ */
+ public void testUnregisterOfDefaultExchangeDisallowed() throws Exception
+ {
+ String defaultExchangeName = ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString();
+
+ ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName);
+ assertNotNull("Exchange should exist", defaultExchange);
+ try
+ {
+ _managedBroker.unregisterExchange(defaultExchangeName);
+ fail("Exception not thrown");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ // PASS
+ assertEquals("'<<default>>' is a reserved exchange and can't be deleted", e.getMessage());
+ }
+ defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName);
+ assertNotNull("Exchange should exist", defaultExchange);
+ }
+
+}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java
index 28d7bf4aed..28d7bf4aed 100644
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ConnectionManagementTest.java
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java
new file mode 100644
index 0000000000..3c3bbdca41
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.systest.management.jmx;
+
+import java.io.File;
+import java.util.List;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+import org.apache.qpid.management.common.mbeans.LoggingManagement;
+import org.apache.qpid.server.logging.log4j.LoggingManagementFacadeTest;
+import org.apache.qpid.test.utils.JMXTestUtils;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.util.FileUtils;
+import org.apache.qpid.util.LogMonitor;
+
+/**
+ * System test for Logging Management. <b>These tests rely on value set within
+ * test-profiles/log4j-test.xml</b>.
+ *
+ * @see LoggingManagementMBeanTest
+ * @see LoggingManagementFacadeTest
+ *
+ */
+public class LoggingManagementTest extends QpidBrokerTestCase
+{
+ private JMXTestUtils _jmxUtils;
+ private LoggingManagement _loggingManagement;
+ private LogMonitor _monitor;
+
+ public void setUp() throws Exception
+ {
+ _jmxUtils = new JMXTestUtils(this);
+ _jmxUtils.setUp();
+
+ // System test normally run with log for4j test config from beneath test-profiles. We need to
+ // copy it as some of our tests write to this file.
+
+ File tmpLogFile = File.createTempFile("log4j" + "." + getName(), ".xml");
+ tmpLogFile.deleteOnExit();
+ FileUtils.copy(getBrokerCommandLog4JFile(), tmpLogFile);
+ setBrokerCommandLog4JFile(tmpLogFile);
+
+ super.setUp();
+ _jmxUtils.open();
+
+ _loggingManagement = _jmxUtils.getLoggingManagement();
+ _monitor = new LogMonitor(_outputFile);
+ }
+
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_jmxUtils != null)
+ {
+ _jmxUtils.close();
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ public void testViewEffectiveRuntimeLoggerLevels() throws Exception
+ {
+ final String qpidMainLogger = "org.apache.qpid";
+
+ TabularData table = _loggingManagement.viewEffectiveRuntimeLoggerLevels();
+ final CompositeData row = table.get(new String[] {qpidMainLogger} );
+ assertChannelRow(row, qpidMainLogger, "DEBUG");
+ }
+
+ public void testViewConfigFileLoggerLevels() throws Exception
+ {
+ final String operationalLoggingLogger = "qpid.message";
+
+ TabularData table = _loggingManagement.viewConfigFileLoggerLevels();
+ final CompositeData row = table.get(new String[] {operationalLoggingLogger} );
+ assertChannelRow(row, operationalLoggingLogger, "INFO");
+ }
+
+ public void testTurnOffOrgApacheQpidAtRuntime() throws Exception
+ {
+ final String logger = "org.apache.qpid";
+ _monitor.markDiscardPoint();
+ _loggingManagement.setRuntimeLoggerLevel(logger, "OFF");
+
+ List<String> matches = _monitor.waitAndFindMatches("Setting level to OFF for logger 'org.apache.qpid'", 5000);
+ assertEquals(1, matches.size());
+
+ TabularData table = _loggingManagement.viewEffectiveRuntimeLoggerLevels();
+ final CompositeData row1 = table.get(new String[] {logger} );
+ assertChannelRow(row1, logger, "OFF");
+ }
+
+ public void testChangesToConfigFileBecomeEffectiveAfterReload() throws Exception
+ {
+ final String operationalLoggingLogger = "qpid.message";
+ assertEffectiveLoggingLevel(operationalLoggingLogger, "INFO");
+
+ _monitor.markDiscardPoint();
+ _loggingManagement.setConfigFileLoggerLevel(operationalLoggingLogger, "OFF");
+
+ List<String> matches = _monitor.waitAndFindMatches("Setting level to OFF for logger 'qpid.message'", 5000);
+ assertEquals(1, matches.size());
+
+ assertEffectiveLoggingLevel(operationalLoggingLogger, "INFO");
+
+ _loggingManagement.reloadConfigFile();
+
+ assertEffectiveLoggingLevel(operationalLoggingLogger, "OFF");
+ }
+
+ private void assertEffectiveLoggingLevel(String operationalLoggingLogger, String expectedLevel)
+ {
+ TabularData table = _loggingManagement.viewEffectiveRuntimeLoggerLevels();
+ final CompositeData row1 = table.get(new String[] {operationalLoggingLogger} );
+ assertChannelRow(row1, operationalLoggingLogger, expectedLevel);
+ }
+
+ private void assertChannelRow(final CompositeData row, String logger, String level)
+ {
+ assertNotNull("No row for " + logger, row);
+ assertEquals("Unexpected logger name", logger, row.get(LoggingManagement.LOGGER_NAME));
+ assertEquals("Unexpected level", level, row.get(LoggingManagement.LOGGER_LEVEL));
+ }
+
+}
diff --git a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java
index 47b38381c5..47b38381c5 100644
--- a/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementActorLoggingTest.java
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
new file mode 100644
index 0000000000..950b002b87
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
@@ -0,0 +1,330 @@
+/*
+ *
+ * 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.systest.management.jmx;
+
+
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.logging.AbstractTestLogging;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.test.utils.JMXTestUtils;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+import org.apache.qpid.test.utils.TestSSLConstants;
+import org.apache.qpid.util.LogMonitor;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Management Console Test Suite
+ *
+ * The Management Console test suite validates that the follow log messages as specified in the Functional Specification.
+ *
+ * This suite of tests validate that the management console messages occur correctly and according to the following format:
+ *
+ * MNG-1001 : <type> Management Startup
+ * MNG-1002 : Starting : <service> : Listening on port <Port>
+ * MNG-1003 : Shutting down : <service> : port <Port>
+ * MNG-1004 : <type> Management Ready
+ * MNG-1005 : <type> Management Stopped
+ * MNG-1006 : Using SSL Keystore : <path>
+ * MNG-1007 : Open : User <username>
+ * MNG-1008 : Close : User <username>
+ */
+public class ManagementLoggingTest extends AbstractTestLogging
+{
+ private static final String MNG_PREFIX = "MNG-";
+
+ public void setUp() throws Exception
+ {
+ setLogMessagePrefix();
+
+ // We either do this here or have a null check in tearDown.
+ // As when this test is run against profiles other than java it will NPE
+ _monitor = new LogMonitor(_outputFile);
+ //We explicitly do not call super.setUp as starting up the broker is
+ //part of the test case.
+
+ }
+
+ /**
+ * Description:
+ * Using the startup configuration validate that the management startup
+ * message is logged correctly.
+ * Input:
+ * Standard configuration with management enabled
+ * Output:
+ *
+ * <date> MNG-1001 : Startup
+ *
+ * Constraints:
+ * This is the FIRST message logged by MNG
+ * Validation Steps:
+ *
+ * 1. The BRK ID is correct
+ * 2. This is the FIRST message logged by MNG
+ */
+ public void testManagementStartupEnabled() throws Exception
+ {
+ // This test only works on java brokers
+ if (isJavaBroker())
+ {
+ startBrokerAndCreateMonitor(true, false);
+
+ // Ensure we have received the MNG log msg.
+ waitForMessage("MNG-1001");
+
+ List<String> results = findMatches(MNG_PREFIX);
+ // Validation
+
+ assertTrue("MNGer message not logged", results.size() > 0);
+
+ String log = getLogMessage(results, 0);
+
+ //1
+ validateMessageID("MNG-1001", log);
+
+ //2
+ //There will be 2 copies of the startup message (one via SystemOut, and one via Log4J)
+ results = findMatches("MNG-1001");
+ assertEquals("Unexpected startup message count.",
+ 2, results.size());
+
+ //3
+ assertEquals("Startup log message is not 'Startup'.", "JMX Management Startup",
+ getMessageString(log));
+ }
+ }
+
+ /**
+ * Description:
+ * Verify that when management is disabled in the configuration file the
+ * startup message is not logged.
+ * Input:
+ * Standard configuration with management disabled
+ * Output:
+ * NO MNG messages
+ * Validation Steps:
+ *
+ * 1. Validate that no MNG messages are produced.
+ */
+ public void testManagementStartupDisabled() throws Exception
+ {
+ if (isJavaBroker())
+ {
+ startBrokerAndCreateMonitor(false, false);
+
+ List<String> results = findMatches(MNG_PREFIX);
+ // Validation
+
+ assertEquals("MNGer messages logged", 0, results.size());
+ }
+ }
+
+ /**
+ * The two MNG-1002 messages are logged at the same time so lets test them
+ * at the same time.
+ *
+ * Description:
+ * Using the default configuration validate that the RMI Registry socket is
+ * correctly reported as being opened
+ *
+ * Input:
+ * The default configuration file
+ * Output:
+ *
+ * <date> MESSAGE MNG-1002 : Starting : RMI Registry : Listening on port 8999
+ *
+ * Constraints:
+ * The RMI ConnectorServer and Registry log messages do not have a prescribed order
+ * Validation Steps:
+ *
+ * 1. The MNG ID is correct
+ * 2. The specified port is the correct '8999'
+ *
+ * Description:
+ * Using the default configuration validate that the RMI ConnectorServer
+ * socket is correctly reported as being opened
+ *
+ * Input:
+ * The default configuration file
+ * Output:
+ *
+ * <date> MESSAGE MNG-1002 : Starting : RMI ConnectorServer : Listening on port 9099
+ *
+ * Constraints:
+ * The RMI ConnectorServer and Registry log messages do not have a prescribed order
+ * Validation Steps:
+ *
+ * 1. The MNG ID is correct
+ * 2. The specified port is the correct '9099'
+ */
+ public void testManagementStartupRMIEntries() throws Exception
+ {
+ if (isJavaBroker())
+ {
+ startBrokerAndCreateMonitor(true, false);
+
+ List<String> results = waitAndFindMatches("MNG-1002");
+ // Validation
+
+ //There will be 4 startup messages (two via SystemOut, and two via Log4J)
+ assertEquals("Unexpected MNG-1002 message count", 4, results.size());
+
+ String log = getLogMessage(results, 0);
+
+ //1
+ validateMessageID("MNG-1002", log);
+
+ //Check the RMI Registry port is as expected
+ int mPort = getManagementPort(getPort());
+ assertTrue("RMI Registry port not as expected(" + mPort + ").:" + getMessageString(log),
+ getMessageString(log).endsWith(String.valueOf(mPort)));
+
+ log = getLogMessage(results, 2);
+
+ //1
+ validateMessageID("MNG-1002", log);
+
+ // We expect the RMI Registry port (the defined 'management port') to be
+ // 100 lower than the JMX RMIConnector Server Port (the actual JMX server)
+ int jmxPort = mPort + JMXPORT_CONNECTORSERVER_OFFSET;
+ assertTrue("JMX RMIConnectorServer port not as expected(" + jmxPort + ").:" + getMessageString(log),
+ getMessageString(log).endsWith(String.valueOf(jmxPort)));
+ }
+ }
+
+ /**
+ * Description:
+ * Using the default configuration with SSL enabled for the management port the SSL Keystore path should be reported via MNG-1006
+ * Input:
+ * Management SSL enabled default configuration.
+ * Output:
+ *
+ * <date> MESSAGE MNG-1006 : Using SSL Keystore : test_resources/ssl/keystore.jks
+ *
+ * Validation Steps:
+ *
+ * 1. The MNG ID is correct
+ * 2. The keystore path is as specified in the configuration
+ */
+ public void testManagementStartupSSLKeystore() throws Exception
+ {
+ if (isJavaBroker())
+ {
+ setSystemProperty("javax.net.debug", "ssl");
+ startBrokerAndCreateMonitor(true, true);
+
+ List<String> results = waitAndFindMatches("MNG-1006");
+
+ assertTrue("MNGer message not logged", results.size() > 0);
+
+ String log = getLogMessage(results, 0);
+
+ //1
+ validateMessageID("MNG-1006", log);
+
+ // Validate we only have two MNG-1002 (one via stdout, one via log4j)
+ results = findMatches("MNG-1006");
+ assertEquals("Upexpected SSL Keystore message count",
+ 2, results.size());
+
+ // Validate the keystore path is as expected
+ assertTrue("SSL Keystore entry expected.:" + getMessageString(log),
+ getMessageString(log).endsWith(TestSSLConstants.BROKER_KEYSTORE));
+ }
+ }
+
+ /**
+ * Description: Tests the management connection open/close are logged correctly.
+ *
+ * Output:
+ *
+ * <date> MESSAGE MNG-1007 : Open : User <username>
+ * <date> MESSAGE MNG-1008 : Close : User <username>
+ *
+ * Validation Steps:
+ *
+ * 1. The MNG ID is correct
+ * 2. The message and username are correct
+ */
+ public void testManagementUserOpenClose() throws Exception
+ {
+ if (isJavaBroker())
+ {
+ setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, "false");
+ startBrokerAndCreateMonitor(true, false);
+
+ final JMXTestUtils jmxUtils = new JMXTestUtils(this);
+ List<String> openResults = null;
+ List<String> closeResults = null;
+ try
+ {
+ jmxUtils.setUp();
+ jmxUtils.open();
+ openResults = waitAndFindMatches("MNG-1007");
+ }
+ finally
+ {
+ if (jmxUtils != null)
+ {
+ jmxUtils.close();
+ closeResults = waitAndFindMatches("MNG-1008");
+ }
+ }
+
+ assertNotNull("Management Open results null", openResults.size());
+ assertEquals("Management Open logged unexpected number of times", 1, openResults.size());
+
+ assertNotNull("Management Close results null", closeResults.size());
+ assertEquals("Management Close logged unexpected number of times", 1, closeResults.size());
+
+ final String openMessage = getMessageString(getLogMessage(openResults, 0));
+ assertTrue("Unexpected open message " + openMessage, openMessage.endsWith("Open : User admin"));
+ final String closeMessage = getMessageString(getLogMessage(closeResults, 0));
+ assertTrue("Unexpected close message " + closeMessage, closeMessage.endsWith("Close : User admin"));
+ }
+ }
+
+ private void startBrokerAndCreateMonitor(boolean managementEnabled, boolean useManagementSSL) throws Exception
+ {
+ TestBrokerConfiguration config = getBrokerConfiguration();
+
+ if (managementEnabled)
+ {
+ config.addJmxManagementConfiguration();
+ }
+
+ if(useManagementSSL)
+ {
+ // This test requires we have an ssl connection
+ config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+
+ setSystemProperty("javax.net.ssl.keyStore", "test-profiles/test_resources/ssl/java_broker_keystore.jks");
+ setSystemProperty("javax.net.ssl.keyStorePassword", "password");
+ }
+
+ startBroker();
+
+ // Now we can create the monitor as _outputFile will now be defined
+ _monitor = new LogMonitor(_outputFile);
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/QueueManagementTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/QueueManagementTest.java
new file mode 100644
index 0000000000..0d3289d1bd
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/QueueManagementTest.java
@@ -0,0 +1,778 @@
+/*
+ * 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.systest.management.jmx;
+
+import org.apache.commons.lang.time.FastDateFormat;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.configuration.ClientProperties;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.management.common.mbeans.ManagedBroker;
+import org.apache.qpid.management.common.mbeans.ManagedQueue;
+import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.apache.qpid.server.queue.NotificationCheckTest;
+import org.apache.qpid.server.queue.SimpleAMQQueueTest;
+import org.apache.qpid.test.client.destination.AddressBasedDestinationTest;
+import org.apache.qpid.test.utils.JMXTestUtils;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+import javax.naming.NamingException;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Tests the JMX API for the Managed Queue.
+ *
+ */
+public class QueueManagementTest extends QpidBrokerTestCase
+{
+
+ private static final Logger LOGGER = Logger.getLogger(QueueManagementTest.class);
+
+ private static final String VIRTUAL_HOST = "test";
+ private static final String TEST_QUEUE_DESCRIPTION = "my description";
+
+ private JMXTestUtils _jmxUtils;
+ private Connection _connection;
+ private Session _session;
+
+ private String _sourceQueueName;
+ private String _destinationQueueName;
+ private Destination _sourceQueue;
+ private Destination _destinationQueue;
+ private ManagedQueue _managedSourceQueue;
+ private ManagedQueue _managedDestinationQueue;
+
+ public void setUp() throws Exception
+ {
+ _jmxUtils = new JMXTestUtils(this);
+ _jmxUtils.setUp();
+
+ super.setUp();
+ _sourceQueueName = getTestQueueName() + "_src";
+ _destinationQueueName = getTestQueueName() + "_dest";
+
+ createConnectionAndSession();
+
+ _sourceQueue = _session.createQueue(_sourceQueueName);
+ _destinationQueue = _session.createQueue(_destinationQueueName);
+ createQueueOnBroker(_sourceQueue);
+ createQueueOnBroker(_destinationQueue);
+
+ _jmxUtils.open();
+
+ createManagementInterfacesForQueues();
+ }
+
+ public void tearDown() throws Exception
+ {
+ if (_jmxUtils != null)
+ {
+ _jmxUtils.close();
+ }
+ super.tearDown();
+ }
+
+ public void testQueueAttributes() throws Exception
+ {
+ Queue queue = _session.createQueue(getTestQueueName());
+ createQueueOnBroker(queue);
+
+ final String queueName = queue.getQueueName();
+
+ final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertEquals("Unexpected name", queueName, managedQueue.getName());
+ assertEquals("Unexpected queue type", "standard", managedQueue.getQueueType());
+ }
+
+ public void testExclusiveQueueHasJmsClientIdAsOwner() throws Exception
+ {
+ Queue tmpQueue = _session.createTemporaryQueue();
+
+ final String queueName = tmpQueue.getQueueName();
+
+ final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertNotNull(_connection.getClientID());
+ assertEquals("Unexpected owner", _connection.getClientID(), managedQueue.getOwner());
+ }
+
+ public void testNonExclusiveQueueHasNoOwner() throws Exception
+ {
+ Queue nonExclusiveQueue = _session.createQueue(getTestQueueName());
+ createQueueOnBroker(nonExclusiveQueue);
+
+ final String queueName = nonExclusiveQueue.getQueueName();
+
+ final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertNull("Unexpected owner", managedQueue.getOwner());
+ }
+
+ public void testSetNewQueueDescriptionOnExistingQueue() throws Exception
+ {
+ Queue queue = _session.createQueue(getTestQueueName());
+ createQueueOnBroker(queue);
+
+ final String queueName = queue.getQueueName();
+
+ final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertNull("Unexpected description", managedQueue.getDescription());
+
+ managedQueue.setDescription(TEST_QUEUE_DESCRIPTION);
+ assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription());
+ }
+
+ public void testNewQueueWithDescription() throws Exception
+ {
+ String queueName = getTestQueueName();
+ Map<String, Object> arguments = Collections.singletonMap(AMQQueueFactory.X_QPID_DESCRIPTION, (Object)TEST_QUEUE_DESCRIPTION);
+ ((AMQSession<?, ?>)_session).createQueue(AMQShortString.valueOf(queueName), false, true, false, arguments);
+
+ final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription());
+ }
+
+ /**
+ * Requires persistent store.
+ */
+ public void testQueueDescriptionSurvivesRestart() throws Exception
+ {
+ String queueName = getTestQueueName();
+ Map<String, Object> arguments = Collections.singletonMap(AMQQueueFactory.X_QPID_DESCRIPTION, (Object)TEST_QUEUE_DESCRIPTION);
+
+ ((AMQSession<?, ?>)_session).createQueue(AMQShortString.valueOf(queueName), false, true, false, arguments);
+
+ ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription());
+
+ restartBroker();
+
+ managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertEquals(TEST_QUEUE_DESCRIPTION, managedQueue.getDescription());
+ }
+
+ /**
+ * Tests queue creation with {@link AMQQueueFactory#X_QPID_MAXIMUM_DELIVERY_COUNT} argument. Also tests
+ * that the attribute is exposed correctly through {@link ManagedQueue#getMaximumDeliveryCount()}.
+ */
+ public void testCreateQueueWithMaximumDeliveryCountSet() throws Exception
+ {
+ final String queueName = getName();
+ final ManagedBroker managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST);
+
+ final Integer deliveryCount = 1;
+ final Map<String, Object> arguments = Collections.singletonMap(AMQQueueFactory.X_QPID_MAXIMUM_DELIVERY_COUNT, (Object)deliveryCount);
+ managedBroker.createNewQueue(queueName, null, true, arguments);
+
+ // Ensure the queue exists
+ assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName));
+ assertNotNull("Manager queue expected to be available", _jmxUtils.getManagedQueue(queueName));
+
+ final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertEquals("Unexpected maximum delivery count", deliveryCount, managedQueue.getMaximumDeliveryCount());
+ }
+
+ public void testCreateQueueWithAlertingThresholdsSet() throws Exception
+ {
+ final String queueName = getName();
+ final ManagedBroker managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST);
+
+ final Long maximumMessageCount = 100l;
+ final Long maximumMessageSize = 200l;
+ final Long maximumQueueDepth = 300l;
+ final Long maximumMessageAge = 400l;
+ final Map<String, Object> arguments = new HashMap<String, Object>();
+ arguments.put(AMQQueueFactory.X_QPID_MAXIMUM_MESSAGE_COUNT, maximumMessageCount);
+ arguments.put(AMQQueueFactory.X_QPID_MAXIMUM_MESSAGE_SIZE, maximumMessageSize);
+ arguments.put(AMQQueueFactory.X_QPID_MAXIMUM_QUEUE_DEPTH, maximumQueueDepth);
+ arguments.put(AMQQueueFactory.X_QPID_MAXIMUM_MESSAGE_AGE, maximumMessageAge);
+
+ managedBroker.createNewQueue(queueName, null, true, arguments);
+
+ // Ensure the queue exists
+ assertNotNull("Queue object name expected to exist", _jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName));
+ assertNotNull("Manager queue expected to be available", _jmxUtils.getManagedQueue(queueName));
+
+ ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertEquals("Unexpected maximum message count", maximumMessageCount, managedQueue.getMaximumMessageCount());
+ assertEquals("Unexpected maximum message size", maximumMessageSize, managedQueue.getMaximumMessageSize());
+ assertEquals("Unexpected maximum queue depth", maximumQueueDepth, managedQueue.getMaximumQueueDepth());
+ assertEquals("Unexpected maximum message age", maximumMessageAge, managedQueue.getMaximumMessageAge());
+ }
+
+ /**
+ * Requires 0-10 as relies on ADDR addresses.
+ * @see AddressBasedDestinationTest for the testing of message routing to the alternate exchange
+ */
+ public void testGetSetAlternateExchange() throws Exception
+ {
+ String queueName = getTestQueueName();
+ String altExchange = "amq.fanout";
+ String addrWithAltExch = String.format("ADDR:%s;{create:always,node:{type:queue,x-declare:{alternate-exchange:'%s'}}}", queueName, altExchange);
+ Queue queue = _session.createQueue(addrWithAltExch);
+
+ createQueueOnBroker(queue);
+
+ final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertEquals("Newly created queue does not have expected alternate exchange", altExchange, managedQueue.getAlternateExchange());
+
+ String newAltExch = "amq.topic";
+ managedQueue.setAlternateExchange(newAltExch);
+ assertEquals("Unexpected alternate exchange after set", newAltExch, managedQueue.getAlternateExchange());
+ }
+
+ /**
+ * Requires 0-10 as relies on ADDR addresses.
+ */
+ public void testRemoveAlternateExchange() throws Exception
+ {
+ String queueName = getTestQueueName();
+ String altExchange = "amq.fanout";
+ String addrWithAltExch = String.format("ADDR:%s;{create:always,node:{type:queue,x-declare:{alternate-exchange:'%s'}}}", queueName, altExchange);
+ Queue queue = _session.createQueue(addrWithAltExch);
+
+ createQueueOnBroker(queue);
+
+ final ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ assertEquals("Newly created queue does not have expected alternate exchange", altExchange, managedQueue.getAlternateExchange());
+
+ managedQueue.setAlternateExchange("");
+ assertNull("Unexpected alternate exchange after set", managedQueue.getAlternateExchange());
+ }
+
+ /**
+ * Requires persistent store
+ * Requires 0-10 as relies on ADDR addresses.
+ */
+ public void testAlternateExchangeSurvivesRestart() throws Exception
+ {
+ String nonMandatoryExchangeName = "exch" + getName();
+
+ final ManagedBroker managedBroker = _jmxUtils.getManagedBroker(VIRTUAL_HOST);
+ managedBroker.createNewExchange(nonMandatoryExchangeName, "fanout", true);
+
+ String queueName1 = getTestQueueName() + "1";
+ String altExchange1 = "amq.fanout";
+ String addr1WithAltExch = String.format("ADDR:%s;{create:always,node:{durable: true,type:queue,x-declare:{alternate-exchange:'%s'}}}", queueName1, altExchange1);
+ Queue queue1 = _session.createQueue(addr1WithAltExch);
+
+ String queueName2 = getTestQueueName() + "2";
+ String addr2WithoutAltExch = String.format("ADDR:%s;{create:always,node:{durable: true,type:queue}}", queueName2);
+ Queue queue2 = _session.createQueue(addr2WithoutAltExch);
+
+ createQueueOnBroker(queue1);
+ createQueueOnBroker(queue2);
+
+ ManagedQueue managedQueue1 = _jmxUtils.getManagedQueue(queueName1);
+ assertEquals("Newly created queue1 does not have expected alternate exchange", altExchange1, managedQueue1.getAlternateExchange());
+
+ ManagedQueue managedQueue2 = _jmxUtils.getManagedQueue(queueName2);
+ assertNull("Newly created queue2 does not have expected alternate exchange", managedQueue2.getAlternateExchange());
+
+ String altExchange2 = nonMandatoryExchangeName;
+ managedQueue2.setAlternateExchange(altExchange2);
+
+ restartBroker();
+
+ managedQueue1 = _jmxUtils.getManagedQueue(queueName1);
+ assertEquals("Queue1 does not have expected alternate exchange after restart", altExchange1, managedQueue1.getAlternateExchange());
+
+ managedQueue2 = _jmxUtils.getManagedQueue(queueName2);
+ assertEquals("Queue2 does not have expected updated alternate exchange after restart", altExchange2, managedQueue2.getAlternateExchange());
+ }
+
+ /**
+ * Tests the ability to receive queue alerts as JMX notifications.
+ *
+ * @see NotificationCheckTest
+ * @see SimpleAMQQueueTest#testNotificationFiredAsync()
+ * @see SimpleAMQQueueTest#testNotificationFiredOnEnqueue()
+ */
+ public void testQueueNotification() throws Exception
+ {
+ final String queueName = getName();
+ final long maximumMessageCount = 3;
+
+ Queue queue = _session.createQueue(queueName);
+ createQueueOnBroker(queue);
+
+ ManagedQueue managedQueue = _jmxUtils.getManagedQueue(queueName);
+ managedQueue.setMaximumMessageCount(maximumMessageCount);
+
+ RecordingNotificationListener listener = new RecordingNotificationListener(1);
+
+ _jmxUtils.addNotificationListener(_jmxUtils.getQueueObjectName(VIRTUAL_HOST, queueName), listener, null, null);
+
+ // Send two messages - this should *not* trigger the notification
+ sendMessage(_session, queue, 2);
+
+ assertEquals("Premature notification received", 0, listener.getNumberOfNotificationsReceived());
+
+ // A further message should trigger the message count alert
+ sendMessage(_session, queue, 1);
+
+ listener.awaitExpectedNotifications(5, TimeUnit.SECONDS);
+
+ assertEquals("Unexpected number of JMX notifications received", 1, listener.getNumberOfNotificationsReceived());
+
+ Notification notification = listener.getLastNotification();
+ assertEquals("Unexpected notification message", "MESSAGE_COUNT_ALERT 3: Maximum count on queue threshold (3) breached.", notification.getMessage());
+ }
+
+ /**
+ * Tests {@link ManagedQueue#viewMessages(long, long)} interface.
+ */
+ public void testViewSingleMessage() throws Exception
+ {
+ final List<Message> sentMessages = sendMessage(_session, _sourceQueue, 1);
+ syncSession(_session);
+ final Message sentMessage = sentMessages.get(0);
+
+ assertEquals("Unexpected queue depth", 1, _managedSourceQueue.getMessageCount().intValue());
+
+ // Check the contents of the message
+ final TabularData tab = _managedSourceQueue.viewMessages(1l, 1l);
+ assertEquals("Unexpected number of rows in table", 1, tab.size());
+ final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator();
+
+ final CompositeData row1 = rowItr.next();
+ assertNotNull("Message should have AMQ message id", row1.get(ManagedQueue.MSG_AMQ_ID));
+ assertEquals("Unexpected queue position", 1l, row1.get(ManagedQueue.MSG_QUEUE_POS));
+ assertEquals("Unexpected redelivered flag", Boolean.FALSE, row1.get(ManagedQueue.MSG_REDELIVERED));
+
+ // Check the contents of header (encoded in a string array)
+ final String[] headerArray = (String[]) row1.get(ManagedQueue.MSG_HEADER);
+ assertNotNull("Expected message header array", headerArray);
+ final Map<String, String> headers = headerArrayToMap(headerArray);
+
+ final String expectedJMSMessageID = isBroker010() ? sentMessage.getJMSMessageID().replace("ID:", "") : sentMessage.getJMSMessageID();
+ final String expectedFormattedJMSTimestamp = FastDateFormat.getInstance(ManagedQueue.JMSTIMESTAMP_DATETIME_FORMAT).format(sentMessage.getJMSTimestamp());
+ assertEquals("Unexpected JMSMessageID within header", expectedJMSMessageID, headers.get("JMSMessageID"));
+ assertEquals("Unexpected JMSPriority within header", String.valueOf(sentMessage.getJMSPriority()), headers.get("JMSPriority"));
+ assertEquals("Unexpected JMSTimestamp within header", expectedFormattedJMSTimestamp, headers.get("JMSTimestamp"));
+ }
+
+ /**
+ * Tests {@link ManagedQueue#moveMessages(long, long, String)} interface.
+ */
+ public void testMoveMessagesBetweenQueues() throws Exception
+ {
+ final int numberOfMessagesToSend = 10;
+
+ sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
+ syncSession(_session);
+ assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+
+ List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
+
+ // Move first three messages to destination
+ long fromMessageId = amqMessagesIds.get(0);
+ long toMessageId = amqMessagesIds.get(2);
+ _managedSourceQueue.moveMessages(fromMessageId, toMessageId, _destinationQueueName);
+
+ assertEquals("Unexpected queue depth on destination queue after first move", 3, _managedDestinationQueue.getMessageCount().intValue());
+ assertEquals("Unexpected queue depth on source queue after first move", 7, _managedSourceQueue.getMessageCount().intValue());
+
+ // Now move a further two messages to destination
+ fromMessageId = amqMessagesIds.get(7);
+ toMessageId = amqMessagesIds.get(8);
+ _managedSourceQueue.moveMessages(fromMessageId, toMessageId, _destinationQueueName);
+ assertEquals("Unexpected queue depth on destination queue after second move", 5, _managedDestinationQueue.getMessageCount().intValue());
+ assertEquals("Unexpected queue depth on source queue after second move", 5, _managedSourceQueue.getMessageCount().intValue());
+
+ assertMessageIndicesOn(_destinationQueue, 0, 1, 2, 7, 8);
+ }
+
+ /**
+ * Tests {@link ManagedQueue#copyMessages(long, long, String)} interface.
+ */
+ public void testCopyMessagesBetweenQueues() throws Exception
+ {
+ final int numberOfMessagesToSend = 10;
+ sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
+ syncSession(_session);
+ assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+
+ List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
+
+ // Copy first three messages to destination
+ long fromMessageId = amqMessagesIds.get(0);
+ long toMessageId = amqMessagesIds.get(2);
+ _managedSourceQueue.copyMessages(fromMessageId, toMessageId, _destinationQueueName);
+
+ assertEquals("Unexpected queue depth on destination queue after first copy", 3, _managedDestinationQueue.getMessageCount().intValue());
+ assertEquals("Unexpected queue depth on source queue after first copy", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+
+ // Now copy a further two messages to destination
+ fromMessageId = amqMessagesIds.get(7);
+ toMessageId = amqMessagesIds.get(8);
+ _managedSourceQueue.copyMessages(fromMessageId, toMessageId, _destinationQueueName);
+ assertEquals("Unexpected queue depth on destination queue after second copy", 5, _managedDestinationQueue.getMessageCount().intValue());
+ assertEquals("Unexpected queue depth on source queue after second copy", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+
+ assertMessageIndicesOn(_destinationQueue, 0, 1, 2, 7, 8);
+ }
+
+ public void testMoveMessagesBetweenQueuesWithActiveConsumerOnSourceQueue() throws Exception
+ {
+ setTestClientSystemProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, new Integer(1).toString());
+ Connection asyncConnection = getConnection();
+ asyncConnection.start();
+
+ final int numberOfMessagesToSend = 50;
+ sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
+ syncSession(_session);
+ assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+
+ List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
+
+ long fromMessageId = amqMessagesIds.get(0);
+ long toMessageId = amqMessagesIds.get(numberOfMessagesToSend - 1);
+
+ CountDownLatch consumerReadToHalfwayLatch = new CountDownLatch(numberOfMessagesToSend / 2);
+ AtomicInteger totalConsumed = new AtomicInteger(0);
+ startAsyncConsumerOn(_sourceQueue, asyncConnection, consumerReadToHalfwayLatch, totalConsumed);
+
+ boolean halfwayPointReached = consumerReadToHalfwayLatch.await(5000, TimeUnit.MILLISECONDS);
+ assertTrue("Did not read half of messages within time allowed", halfwayPointReached);
+
+ _managedSourceQueue.moveMessages(fromMessageId, toMessageId, _destinationQueueName);
+
+ asyncConnection.stop();
+
+ // The exact number of messages moved will be non deterministic, as the number of messages processed
+ // by the consumer cannot be predicted. There is also the possibility that a message can remain
+ // on the source queue. This situation will arise if a message has been acquired by the consumer, but not
+ // yet delivered to the client application (i.e. MessageListener#onMessage()) when the Connection#stop() occurs.
+ //
+ // The number of messages moved + the number consumed + any messages remaining on source should
+ // *always* be equal to the number we originally sent.
+
+ int numberOfMessagesReadByConsumer = totalConsumed.intValue();
+ int numberOfMessagesOnDestinationQueue = _managedDestinationQueue.getMessageCount().intValue();
+ int numberOfMessagesRemainingOnSourceQueue = _managedSourceQueue.getMessageCount().intValue();
+
+ LOGGER.debug("Async consumer read : " + numberOfMessagesReadByConsumer
+ + " Number of messages moved to destination : " + numberOfMessagesOnDestinationQueue
+ + " Number of messages remaining on source : " + numberOfMessagesRemainingOnSourceQueue);
+ assertEquals("Unexpected number of messages after move", numberOfMessagesToSend, numberOfMessagesReadByConsumer + numberOfMessagesOnDestinationQueue + numberOfMessagesRemainingOnSourceQueue);
+ }
+
+ public void testMoveMessagesBetweenQueuesWithActiveConsumerOnDestinationQueue() throws Exception
+ {
+ setTestClientSystemProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, new Integer(1).toString());
+ Connection asyncConnection = getConnection();
+ asyncConnection.start();
+
+ final int numberOfMessagesToSend = 50;
+ sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
+ syncSession(_session);
+ assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+
+ List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
+ long fromMessageId = amqMessagesIds.get(0);
+ long toMessageId = amqMessagesIds.get(numberOfMessagesToSend - 1);
+
+ AtomicInteger totalConsumed = new AtomicInteger(0);
+ CountDownLatch allMessagesConsumedLatch = new CountDownLatch(numberOfMessagesToSend);
+ startAsyncConsumerOn(_destinationQueue, asyncConnection, allMessagesConsumedLatch, totalConsumed);
+
+ _managedSourceQueue.moveMessages(fromMessageId, toMessageId, _destinationQueueName);
+
+ allMessagesConsumedLatch.await(5000, TimeUnit.MILLISECONDS);
+ assertEquals("Did not consume all messages from destination queue", numberOfMessagesToSend, totalConsumed.intValue());
+ }
+
+ /**
+ * Tests {@link ManagedQueue#moveMessages(long, long, String)} interface.
+ */
+ public void testMoveMessageBetweenQueuesWithBrokerRestart() throws Exception
+ {
+ final int numberOfMessagesToSend = 1;
+
+ sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
+ syncSession(_session);
+ assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+
+ restartBroker();
+
+ createManagementInterfacesForQueues();
+ createConnectionAndSession();
+
+ List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
+
+ // Move messages to destination
+ long messageId = amqMessagesIds.get(0);
+ _managedSourceQueue.moveMessages(messageId, messageId, _destinationQueueName);
+
+ assertEquals("Unexpected queue depth on destination queue after move", 1, _managedDestinationQueue.getMessageCount().intValue());
+ assertEquals("Unexpected queue depth on source queue after move", 0, _managedSourceQueue.getMessageCount().intValue());
+
+ assertMessageIndicesOn(_destinationQueue, 0);
+ }
+
+ /**
+ * Tests {@link ManagedQueue#copyMessages(long, long, String)} interface.
+ */
+ public void testCopyMessageBetweenQueuesWithBrokerRestart() throws Exception
+ {
+ final int numberOfMessagesToSend = 1;
+
+ sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
+ syncSession(_session);
+ assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+
+ restartBroker();
+
+ createManagementInterfacesForQueues();
+ createConnectionAndSession();
+
+ List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
+
+ // Move messages to destination
+ long messageId = amqMessagesIds.get(0);
+ _managedSourceQueue.copyMessages(messageId, messageId, _destinationQueueName);
+
+ assertEquals("Unexpected queue depth on destination queue after copy", 1, _managedDestinationQueue.getMessageCount().intValue());
+ assertEquals("Unexpected queue depth on source queue after copy", 1, _managedSourceQueue.getMessageCount().intValue());
+
+ assertMessageIndicesOn(_destinationQueue, 0);
+ }
+
+ /**
+ * Tests {@link ManagedQueue#deleteMessages(long, long)} interface.
+ */
+ public void testDeleteMessages() throws Exception
+ {
+ final int numberOfMessagesToSend = 15;
+
+ sendMessage(_session, _sourceQueue, numberOfMessagesToSend);
+ syncSession(_session);
+ assertEquals("Unexpected queue depth after send", numberOfMessagesToSend, _managedSourceQueue.getMessageCount().intValue());
+ List<Long> amqMessagesIds = getAMQMessageIdsOn(_managedSourceQueue, 1, numberOfMessagesToSend);
+ // Current expected queue state, in terms of message header indices: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
+
+ // Delete the first message (Remember the amqMessagesIds list, and the message indices added as a property when sending, are both 0-based index)
+ long fromMessageId = amqMessagesIds.get(0);
+ long toMessageId = fromMessageId;
+ _managedSourceQueue.deleteMessages(fromMessageId, toMessageId);
+ assertEquals("Unexpected message count after first deletion", numberOfMessagesToSend - 1, _managedSourceQueue.getMessageCount().intValue());
+ // Current expected queue state, in terms of message header indices: [X,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
+
+ // Delete the 9th-10th messages, in the middle of the queue
+ fromMessageId = amqMessagesIds.get(8);
+ toMessageId = amqMessagesIds.get(9);
+ _managedSourceQueue.deleteMessages(fromMessageId, toMessageId);
+ assertEquals("Unexpected message count after third deletion", numberOfMessagesToSend - 3, _managedSourceQueue.getMessageCount().intValue());
+ // Current expected queue state, in terms of message header indices: [X,1,2,3,4,5,6,7,X,X,10,11,12,13,14]
+
+ // Delete the 11th and 12th messages, but still include the IDs for the 9th and 10th messages in the
+ // range to ensure their IDs are 'skipped' until the matching messages are found
+ fromMessageId = amqMessagesIds.get(8);
+ toMessageId = amqMessagesIds.get(11);
+ _managedSourceQueue.deleteMessages(fromMessageId, toMessageId);
+ assertEquals("Unexpected message count after fourth deletion", numberOfMessagesToSend - 5, _managedSourceQueue.getMessageCount().intValue());
+ // Current expected queue state, in terms of message header indices: [X,1,2,3,4,5,6,7,X,X,X,X,12,13,14]
+
+ // Delete the 8th message and the 13th message, including the IDs for the 9th-12th messages in the
+ // range to ensure their IDs are 'skipped' and the other matching message is found
+ fromMessageId = amqMessagesIds.get(7);
+ toMessageId = amqMessagesIds.get(12);
+ _managedSourceQueue.deleteMessages(fromMessageId, toMessageId);
+ assertEquals("Unexpected message count after fourth deletion", numberOfMessagesToSend - 7, _managedSourceQueue.getMessageCount().intValue());
+ // Current expected queue state, in terms of message header indices: [X,1,2,3,4,5,6,X,X,X,X,X,X,13,14]
+
+ // Delete the last message message
+ fromMessageId = amqMessagesIds.get(numberOfMessagesToSend -1);
+ toMessageId = fromMessageId;
+ _managedSourceQueue.deleteMessages(fromMessageId, toMessageId);
+ assertEquals("Unexpected message count after second deletion", numberOfMessagesToSend - 8, _managedSourceQueue.getMessageCount().intValue());
+ // Current expected queue state, in terms of message header indices: [X,1,2,3,4,5,6,X,X,X,X,X,X,13,X]
+
+ // Verify the message indices with a consumer
+ assertMessageIndicesOn(_sourceQueue, 1,2,3,4,5,6,13);
+ }
+
+ @Override
+ public Message createNextMessage(Session session, int messageNumber) throws JMSException
+ {
+ Message message = session.createTextMessage(getContentForMessageNumber(messageNumber));
+ message.setIntProperty(INDEX, messageNumber);
+ return message;
+ }
+
+ private void startAsyncConsumerOn(Destination queue, Connection asyncConnection,
+ final CountDownLatch requiredNumberOfMessagesRead, final AtomicInteger totalConsumed) throws Exception
+ {
+ Session session = asyncConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+ consumer.setMessageListener(new MessageListener()
+ {
+
+ @Override
+ public void onMessage(Message arg0)
+ {
+ totalConsumed.incrementAndGet();
+ requiredNumberOfMessagesRead.countDown();
+ }
+ });
+ }
+
+ private void assertMessageIndicesOn(Destination queue, int... expectedIndices) throws Exception
+ {
+ MessageConsumer consumer = _session.createConsumer(queue);
+
+ for (int i : expectedIndices)
+ {
+ TextMessage message = (TextMessage)consumer.receive(1000);
+ assertNotNull("Expected message with index " + i, message);
+ assertEquals("Expected message with index " + i, i, message.getIntProperty(INDEX));
+ assertEquals("Expected message content", getContentForMessageNumber(i), message.getText());
+ }
+
+ assertNull("Unexpected message encountered", consumer.receive(1000));
+ }
+
+ private List<Long> getAMQMessageIdsOn(ManagedQueue managedQueue, long startIndex, long endIndex) throws Exception
+ {
+ final SortedSet<Long> messageIds = new TreeSet<Long>();
+
+ final TabularData tab = managedQueue.viewMessages(startIndex, endIndex);
+ final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator();
+ while(rowItr.hasNext())
+ {
+ final CompositeData row = rowItr.next();
+ long amqMessageId = (Long)row.get(ManagedQueue.MSG_AMQ_ID);
+ messageIds.add(amqMessageId);
+ }
+
+ return new ArrayList<Long>(messageIds);
+ }
+
+ /**
+ *
+ * Utility method to convert array of Strings in the form x = y into a
+ * map with key/value x =&gt; y.
+ *
+ */
+ private Map<String,String> headerArrayToMap(final String[] headerArray)
+ {
+ final Map<String, String> headerMap = new HashMap<String, String>();
+ final List<String> headerList = Arrays.asList(headerArray);
+ for (Iterator<String> iterator = headerList.iterator(); iterator.hasNext();)
+ {
+ final String nameValuePair = iterator.next();
+ final String[] nameValue = nameValuePair.split(" *= *", 2);
+ headerMap.put(nameValue[0], nameValue[1]);
+ }
+ return headerMap;
+ }
+
+ private void createQueueOnBroker(Destination destination) throws JMSException
+ {
+ _session.createConsumer(destination).close(); // Create a consumer only to cause queue creation
+ }
+
+ private void syncSession(Session session) throws Exception
+ {
+ ((AMQSession<?,?>)session).sync();
+ }
+
+ private void createConnectionAndSession() throws JMSException,
+ NamingException
+ {
+ _connection = getConnection();
+ _connection.start();
+ _session = _connection.createSession(true, Session.SESSION_TRANSACTED);
+ }
+
+ private void createManagementInterfacesForQueues()
+ {
+ _managedSourceQueue = _jmxUtils.getManagedQueue(_sourceQueueName);
+ _managedDestinationQueue = _jmxUtils.getManagedQueue(_destinationQueueName);
+ }
+
+ private String getContentForMessageNumber(int msgCount)
+ {
+ return "Message count " + msgCount;
+ }
+
+ private final class RecordingNotificationListener implements NotificationListener
+ {
+ private final CountDownLatch _notificationReceivedLatch;
+ private final AtomicInteger _numberOfNotifications;
+ private final AtomicReference<Notification> _lastNotification;
+
+ private RecordingNotificationListener(int expectedNumberOfNotifications)
+ {
+ _notificationReceivedLatch = new CountDownLatch(expectedNumberOfNotifications);
+ _numberOfNotifications = new AtomicInteger(0);
+ _lastNotification = new AtomicReference<Notification>();
+ }
+
+ @Override
+ public void handleNotification(Notification notification, Object handback)
+ {
+ _lastNotification.set(notification);
+ _numberOfNotifications.incrementAndGet();
+ _notificationReceivedLatch.countDown();
+ }
+
+ public int getNumberOfNotificationsReceived()
+ {
+ return _numberOfNotifications.get();
+ }
+
+ public Notification getLastNotification()
+ {
+ return _lastNotification.get();
+ }
+
+ public void awaitExpectedNotifications(long timeout, TimeUnit timeunit) throws InterruptedException
+ {
+ _notificationReceivedLatch.await(timeout, timeunit);
+ }
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java
new file mode 100644
index 0000000000..72fbd65acc
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.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.systest.management.jmx;
+
+import java.util.List;
+
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.management.common.mbeans.ManagedBroker;
+import org.apache.qpid.management.common.mbeans.ManagedConnection;
+import org.apache.qpid.management.common.mbeans.ServerInformation;
+import org.apache.qpid.test.utils.JMXTestUtils;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+
+public class StatisticsTest extends QpidBrokerTestCase
+{
+ private static final String TEST_VIRTUALHOST1 = "test1";
+ private static final String TEST_VIRTUALHOST2 = "test2";
+
+ private static final String TEST_USER = "admin";
+ private static final String TEST_PASSWORD = "admin";
+ private static final int MESSAGE_COUNT_TEST = 5;
+ private static final int MESSAGE_COUNT_DEV = 9;
+
+ private JMXTestUtils _jmxUtils;
+ private Connection _vhost1Connection, _vhost2Connection;
+ private Session _vhost1Session, _vhost2Session;
+ private Queue _vhost1Queue, _vhost2Queue;
+ protected String _brokerUrl;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ createTestVirtualHost(0, TEST_VIRTUALHOST1);
+ createTestVirtualHost(0, TEST_VIRTUALHOST2);
+
+ _jmxUtils = new JMXTestUtils(this, TEST_USER, TEST_PASSWORD);
+ _jmxUtils.setUp();
+
+ super.setUp();
+
+ _brokerUrl = getBroker().toString();
+ _vhost1Connection = new AMQConnection(_brokerUrl, TEST_USER, TEST_PASSWORD, "clientid", TEST_VIRTUALHOST1);
+ _vhost2Connection = new AMQConnection(_brokerUrl, TEST_USER, TEST_PASSWORD, "clientid", TEST_VIRTUALHOST2);
+ _vhost1Connection.start();
+ _vhost2Connection.start();
+
+ _vhost1Session = _vhost1Connection.createSession(true, Session.SESSION_TRANSACTED);
+ _vhost2Session = _vhost2Connection.createSession(true, Session.SESSION_TRANSACTED);
+
+ _vhost1Queue = _vhost2Session.createQueue(getTestQueueName());
+ _vhost2Queue = _vhost1Session.createQueue(getTestQueueName());
+
+ //Create queues by opening and closing consumers
+ final MessageConsumer vhost1Consumer = _vhost1Session.createConsumer(_vhost2Queue);
+ vhost1Consumer.close();
+ final MessageConsumer vhost2Consumer = _vhost2Session.createConsumer(_vhost1Queue);
+ vhost2Consumer.close();
+
+ _jmxUtils.open();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ _jmxUtils.close();
+
+ super.tearDown();
+ }
+
+ public void testInitialStatisticValues() throws Exception
+ {
+ //Check initial values
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST1, 0, 0, 0, 0);
+ checkVHostStatistics(TEST_VIRTUALHOST1, 0, 0, 0, 0);
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST2, 0, 0, 0, 0);
+ checkVHostStatistics(TEST_VIRTUALHOST2, 0, 0, 0, 0);
+ checkBrokerStatistics(0, 0, 0, 0);
+ }
+
+ public void testSendOnSingleVHost() throws Exception
+ {
+ sendMessagesAndSync(_vhost1Session, _vhost2Queue, MESSAGE_COUNT_TEST);
+
+ //Check values
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST1, MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
+ checkVHostStatistics(TEST_VIRTUALHOST1, MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST2, 0, 0, 0, 0);
+ checkVHostStatistics(TEST_VIRTUALHOST2, 0, 0, 0, 0);
+ checkBrokerStatistics(MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
+ }
+
+ public void testSendOnTwoVHosts() throws Exception
+ {
+ sendMessagesAndSync(_vhost1Session, _vhost2Queue, MESSAGE_COUNT_TEST);
+ sendMessagesAndSync(_vhost2Session, _vhost1Queue, MESSAGE_COUNT_DEV);
+
+ //Check values
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST1, MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
+ checkVHostStatistics(TEST_VIRTUALHOST1, MESSAGE_COUNT_TEST, 0, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, 0);
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST2, MESSAGE_COUNT_DEV, 0, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE, 0);
+ checkVHostStatistics(TEST_VIRTUALHOST2, MESSAGE_COUNT_DEV, 0, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE, 0);
+ checkBrokerStatistics(MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV, 0, (MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV) * DEFAULT_MESSAGE_SIZE, 0);
+ }
+
+ public void testSendAndConsumeOnSingleVHost() throws Exception
+ {
+ sendMessagesAndSync(_vhost1Session, _vhost2Queue, MESSAGE_COUNT_TEST);
+ consumeMessages(_vhost1Session, _vhost2Queue, MESSAGE_COUNT_TEST);
+
+ //Check values
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST1, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
+ checkVHostStatistics(TEST_VIRTUALHOST1, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST2, 0, 0, 0, 0);
+ checkVHostStatistics(TEST_VIRTUALHOST2, 0, 0, 0, 0);
+ checkBrokerStatistics(MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
+ }
+
+ public void testSendAndConsumeOnTwoVHosts() throws Exception
+ {
+ sendMessagesAndSync(_vhost1Session, _vhost2Queue, MESSAGE_COUNT_TEST);
+ sendMessagesAndSync(_vhost2Session, _vhost1Queue, MESSAGE_COUNT_DEV);
+ consumeMessages(_vhost1Session, _vhost2Queue, MESSAGE_COUNT_TEST);
+ consumeMessages(_vhost2Session, _vhost1Queue, MESSAGE_COUNT_DEV);
+
+ //Check values
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST1, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
+ checkVHostStatistics(TEST_VIRTUALHOST1, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_TEST * DEFAULT_MESSAGE_SIZE);
+ checkSingleConnectionOnVHostStatistics(TEST_VIRTUALHOST2, MESSAGE_COUNT_DEV, MESSAGE_COUNT_DEV, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE);
+ checkVHostStatistics(TEST_VIRTUALHOST2, MESSAGE_COUNT_DEV, MESSAGE_COUNT_DEV, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE, MESSAGE_COUNT_DEV * DEFAULT_MESSAGE_SIZE);
+ checkBrokerStatistics(MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV, MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV, (MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV) * DEFAULT_MESSAGE_SIZE, (MESSAGE_COUNT_TEST + MESSAGE_COUNT_DEV) * DEFAULT_MESSAGE_SIZE);
+ }
+
+ private void sendMessagesAndSync(Session session, Queue queue, int numberOfMessages) throws Exception
+ {
+ //Send messages via connection on and sync
+ sendMessage(session, queue, numberOfMessages);
+ ((AMQSession<?,?>)session).sync();
+ }
+
+ private void consumeMessages(Session session, Queue queue, int numberOfMessages) throws Exception
+ {
+ //consume the messages on the virtual host
+ final MessageConsumer consumer = session.createConsumer(queue);
+ for (int i = 0 ; i < numberOfMessages ; i++)
+ {
+ assertNotNull("an expected message was not received", consumer.receive(1500));
+ }
+ session.commit();
+ consumer.close();
+ }
+
+ private void checkSingleConnectionOnVHostStatistics(String vHostName, long messagesSent, long messagesReceived, long dataSent, long dataReceived)
+ {
+ List<ManagedConnection> managedConnections = _jmxUtils.getManagedConnections(vHostName);
+ assertEquals(1, managedConnections.size());
+
+ ManagedConnection managedConnection = managedConnections.get(0);
+
+ assertEquals(messagesSent, managedConnection.getTotalMessagesReceived());
+ assertEquals(messagesReceived, managedConnection.getTotalMessagesDelivered());
+
+ assertEquals(dataSent, managedConnection.getTotalDataReceived());
+ assertEquals(dataReceived, managedConnection.getTotalDataDelivered());
+ }
+
+ private void checkVHostStatistics(String vHostName, long messagesSent, long messagesReceived, long dataSent, long dataReceived)
+ {
+ ManagedBroker vhost = _jmxUtils.getManagedBroker(vHostName);
+
+ assertEquals(messagesSent, vhost.getTotalMessagesReceived());
+ assertEquals(messagesReceived, vhost.getTotalMessagesDelivered());
+
+ assertEquals(dataSent, vhost.getTotalDataReceived());
+ assertEquals(dataReceived, vhost.getTotalDataDelivered());
+ }
+
+ private void checkBrokerStatistics(long messagesSent, long messagesReceived, long dataSent, long dataReceived)
+ {
+ ServerInformation broker = _jmxUtils.getServerInformation();
+
+ assertEquals(messagesSent, broker.getTotalMessagesReceived());
+ assertEquals(messagesReceived, broker.getTotalMessagesDelivered());
+
+ assertEquals(dataSent, broker.getTotalDataReceived());
+ assertEquals(dataReceived, broker.getTotalDataDelivered());
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java
new file mode 100644
index 0000000000..7eff1c89ee
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java
@@ -0,0 +1,260 @@
+/*
+ * 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.systest.management.jmx;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+
+import org.apache.qpid.management.common.mbeans.UserManagement;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory;
+import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory;
+import org.apache.qpid.test.utils.JMXTestUtils;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+import org.apache.qpid.tools.security.Passwd;
+
+/**
+ * System test for User Management.
+ *
+ */
+public class UserManagementTest extends QpidBrokerTestCase
+{
+ private static final String TEST_NEWPASSWORD = "newpassword";
+ private static final String TEST_PASSWORD = "password";
+ private JMXTestUtils _jmxUtils;
+ private String _testUserName;
+ private File _passwordFile;
+ private UserManagement _userManagement;
+ private Passwd _passwd;
+
+ public void setUp() throws Exception
+ {
+ _passwd = createPasswordEncodingUtility();
+ _passwordFile = createTemporaryPasswordFileWithJmxAdminUser();
+
+ Map<String, Object> newAttributes = new HashMap<String, Object>();
+ newAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, getAuthenticationManagerType());
+ newAttributes.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _passwordFile.getAbsolutePath());
+ getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes);
+
+ _jmxUtils = new JMXTestUtils(this);
+ _jmxUtils.setUp();
+
+ super.setUp();
+ _jmxUtils.open();
+
+ _testUserName = getTestName() + System.currentTimeMillis();
+
+ _userManagement = _jmxUtils.getUserManagement();
+ }
+
+
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_jmxUtils != null)
+ {
+ _jmxUtils.close();
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ public void testCreateUser() throws Exception
+ {
+ final int initialNumberOfUsers = _userManagement.viewUsers().size();
+ assertFileDoesNotContainsPasswordForUser(_testUserName);
+
+ boolean success = _userManagement.createUser(_testUserName, TEST_PASSWORD);
+ assertTrue("Should have been able to create new user " + _testUserName, success);
+ assertEquals("Unexpected number of users after add", initialNumberOfUsers + 1, _userManagement.viewUsers().size());
+
+ assertFileContainsPasswordForUser(_testUserName);
+ }
+
+ public void testJmsLoginForNewUser() throws Exception
+ {
+ assertJmsConnectionFails(_testUserName, TEST_PASSWORD);
+ testCreateUser();
+
+ assertJmsConnectionSucceeds(_testUserName, TEST_PASSWORD);
+ }
+
+ public void testDeleteUser() throws Exception
+ {
+ final int initialNumberOfUsers = _userManagement.viewUsers().size();
+
+ testCreateUser();
+
+ boolean success = _userManagement.deleteUser(_testUserName);
+ assertTrue("Should have been able to delete new user " + _testUserName, success);
+ assertEquals("Unexpected number of users after delete", initialNumberOfUsers, _userManagement.viewUsers().size());
+ assertFileDoesNotContainsPasswordForUser(_testUserName);
+ }
+
+ public void testJmsLoginNotPossibleForDeletedUser() throws Exception
+ {
+ testDeleteUser();
+
+ assertJmsConnectionFails(_testUserName, TEST_PASSWORD);
+ }
+
+ public void testSetPassword() throws Exception
+ {
+ testCreateUser();
+
+ _userManagement.setPassword(_testUserName, TEST_NEWPASSWORD);
+
+ assertFileContainsPasswordForUser(_testUserName);
+ }
+
+ public void testJmsLoginForPasswordChangedUser() throws Exception
+ {
+ testSetPassword();
+
+ assertJmsConnectionSucceeds(_testUserName, TEST_NEWPASSWORD);
+ assertJmsConnectionFails(_testUserName, TEST_PASSWORD);
+ }
+
+ public void testReload() throws Exception
+ {
+ writePasswordFile(_passwordFile, JMXTestUtils.DEFAULT_USERID, JMXTestUtils.DEFAULT_PASSWORD, _testUserName, TEST_PASSWORD);
+
+ assertJmsConnectionFails(_testUserName, TEST_PASSWORD);
+
+ _userManagement.reloadData();
+
+ assertJmsConnectionSucceeds(_testUserName, TEST_PASSWORD);
+ }
+
+ protected Passwd createPasswordEncodingUtility()
+ {
+ return new Passwd()
+ {
+ @Override
+ public String getOutput(String username, String password)
+ {
+ return username + ":" + password;
+ }
+ };
+ }
+
+ protected String getAuthenticationManagerType()
+ {
+ return PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE;
+ }
+
+ private File createTemporaryPasswordFileWithJmxAdminUser() throws Exception
+ {
+ File passwordFile = File.createTempFile("passwd", "pwd");
+ passwordFile.deleteOnExit();
+ writePasswordFile(passwordFile, JMXTestUtils.DEFAULT_USERID, JMXTestUtils.DEFAULT_PASSWORD);
+ return passwordFile;
+ }
+
+ private void writePasswordFile(File passwordFile, String... userNamePasswordPairs) throws Exception
+ {
+ FileWriter writer = null;
+ try
+ {
+ writer = new FileWriter(passwordFile);
+ for (int i = 0; i < userNamePasswordPairs.length; i=i+2)
+ {
+ String username = userNamePasswordPairs[i];
+ String password = userNamePasswordPairs[i+1];
+ writer.append(_passwd.getOutput(username, password) + "\n");
+ }
+ }
+ finally
+ {
+ writer.close();
+ }
+ }
+
+
+ private void assertFileContainsPasswordForUser(String username) throws IOException
+ {
+ assertTrue("Could not find password for user " + username + " within " + _passwordFile, passwordFileContainsUser(username));
+ }
+
+ private void assertFileDoesNotContainsPasswordForUser(String username) throws IOException
+ {
+ assertFalse("Could not find password for user " + username + " within " + _passwordFile, passwordFileContainsUser(username));
+ }
+
+ private boolean passwordFileContainsUser(String username) throws IOException
+ {
+ BufferedReader reader = null;
+ try
+ {
+ reader = new BufferedReader(new FileReader(_passwordFile));
+ String line = reader.readLine();
+ while(line != null)
+ {
+ if (line.startsWith(username))
+ {
+ return true;
+ }
+ line = reader.readLine();
+ }
+
+ return false;
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+
+ private void assertJmsConnectionSucceeds(String username, String password) throws Exception
+ {
+ Connection connection = getConnection(username, password);
+ assertNotNull(connection);
+ }
+
+ private void assertJmsConnectionFails(String username, String password) throws Exception
+ {
+ try
+ {
+ getConnection(username, password);
+ fail("Exception not thrown");
+ }
+ catch (JMSException e)
+ {
+ // PASS
+ }
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java
new file mode 100644
index 0000000000..1423bc557e
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.systest.management.jmx;
+
+import org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory;
+import org.apache.qpid.tools.security.Passwd;
+
+public class UserManagementWithBase64MD5PasswordsTest extends UserManagementTest
+{
+ @Override
+ protected Passwd createPasswordEncodingUtility()
+ {
+ return new Passwd();
+ }
+
+ @Override
+ protected String getAuthenticationManagerType()
+ {
+ return Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE;
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java
new file mode 100644
index 0000000000..16253139ce
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java
@@ -0,0 +1,270 @@
+/*
+ *
+ * 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.systest.rest;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.jms.JMSException;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Connection;
+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;
+
+public class Asserts
+{
+ public static final String STATISTICS_ATTRIBUTE = "statistics";
+
+ public static void assertVirtualHost(String virtualHostName, Map<String, Object> virtualHost)
+ {
+ assertNotNull("Virtualhost " + virtualHostName + " data are not found", virtualHost);
+ assertAttributesPresent(virtualHost, VirtualHost.AVAILABLE_ATTRIBUTES, VirtualHost.TIME_TO_LIVE,
+ VirtualHost.CREATED, VirtualHost.UPDATED, VirtualHost.SUPPORTED_QUEUE_TYPES, VirtualHost.STORE_PATH, VirtualHost.CONFIG_PATH);
+
+ assertEquals("Unexpected value of attribute " + VirtualHost.NAME, virtualHostName, virtualHost.get(VirtualHost.NAME));
+ assertNotNull("Unexpected value of attribute " + VirtualHost.ID, virtualHost.get(VirtualHost.ID));
+ assertEquals("Unexpected value of attribute " + VirtualHost.STATE, State.ACTIVE.name(),
+ virtualHost.get(VirtualHost.STATE));
+ assertEquals("Unexpected value of attribute " + VirtualHost.DURABLE, Boolean.TRUE,
+ virtualHost.get(VirtualHost.DURABLE));
+ assertEquals("Unexpected value of attribute " + VirtualHost.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
+ virtualHost.get(VirtualHost.LIFETIME_POLICY));
+ assertEquals("Unexpected value of attribute " + VirtualHost.DEAD_LETTER_QUEUE_ENABLED, Boolean.FALSE,
+ virtualHost.get(VirtualHost.DEAD_LETTER_QUEUE_ENABLED));
+
+ @SuppressWarnings("unchecked")
+ Collection<String> exchangeTypes = (Collection<String>) virtualHost.get(VirtualHost.SUPPORTED_EXCHANGE_TYPES);
+ assertEquals("Unexpected value of attribute " + VirtualHost.SUPPORTED_EXCHANGE_TYPES,
+ new HashSet<String>(Arrays.asList("headers", "topic", "direct", "fanout")),
+ new HashSet<String>(exchangeTypes));
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) virtualHost.get(STATISTICS_ATTRIBUTE);
+ Asserts.assertAttributesPresent(statistics, VirtualHost.AVAILABLE_STATISTICS, VirtualHost.BYTES_RETAINED,
+ VirtualHost.LOCAL_TRANSACTION_BEGINS, VirtualHost.LOCAL_TRANSACTION_ROLLBACKS,
+ VirtualHost.MESSAGES_RETAINED, VirtualHost.STATE_CHANGED, VirtualHost.XA_TRANSACTION_BRANCH_ENDS,
+ VirtualHost.XA_TRANSACTION_BRANCH_STARTS, VirtualHost.XA_TRANSACTION_BRANCH_SUSPENDS);
+
+ }
+
+ public static void assertQueue(String queueName, String queueType, Map<String, Object> queueData)
+ {
+ assertQueue(queueName, queueType, queueData, null);
+ }
+
+ public static void assertQueue(String queueName, String queueType, Map<String, Object> queueData, Map<String, Object> expectedAttributes)
+ {
+ assertNotNull("Queue " + queueName + " is not found!", queueData);
+ Asserts.assertAttributesPresent(queueData, Queue.AVAILABLE_ATTRIBUTES, Queue.CREATED, Queue.UPDATED,
+ Queue.DESCRIPTION, Queue.TIME_TO_LIVE, Queue.ALTERNATE_EXCHANGE, Queue.OWNER, Queue.NO_LOCAL, Queue.LVQ_KEY,
+ Queue.SORT_KEY, Queue.MESSAGE_GROUP_KEY, Queue.MESSAGE_GROUP_DEFAULT_GROUP,
+ Queue.MESSAGE_GROUP_SHARED_GROUPS, Queue.PRIORITIES);
+
+ assertEquals("Unexpected value of queue attribute " + Queue.NAME, queueName, queueData.get(Queue.NAME));
+ assertNotNull("Unexpected value of queue attribute " + Queue.ID, queueData.get(Queue.ID));
+ assertEquals("Unexpected value of queue attribute " + Queue.STATE, State.ACTIVE.name(), queueData.get(Queue.STATE));
+ assertEquals("Unexpected value of queue attribute " + Queue.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
+ queueData.get(Queue.LIFETIME_POLICY));
+ assertEquals("Unexpected value of queue attribute " + Queue.TYPE, queueType, queueData.get(Queue.TYPE));
+ if (expectedAttributes == null)
+ {
+ assertEquals("Unexpected value of queue attribute " + Queue.EXCLUSIVE, Boolean.FALSE, queueData.get(Queue.EXCLUSIVE));
+ assertEquals("Unexpected value of queue attribute " + Queue.MAXIMUM_DELIVERY_ATTEMPTS, 0,
+ queueData.get(Queue.MAXIMUM_DELIVERY_ATTEMPTS));
+ assertEquals("Unexpected value of queue attribute " + Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES, 0,
+ queueData.get(Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES));
+ assertEquals("Unexpected value of queue attribute " + Queue.QUEUE_FLOW_RESUME_SIZE_BYTES, 0,
+ queueData.get(Queue.QUEUE_FLOW_RESUME_SIZE_BYTES));
+ assertEquals("Unexpected value of queue attribute " + Queue.QUEUE_FLOW_STOPPED, Boolean.FALSE,
+ queueData.get(Queue.QUEUE_FLOW_STOPPED));
+ }
+ else
+ {
+ for (Map.Entry<String, Object> attribute : expectedAttributes.entrySet())
+ {
+ assertEquals("Unexpected value of " + queueName + " queue attribute " + attribute.getKey(),
+ attribute.getValue(), queueData.get(attribute.getKey()));
+ }
+ }
+
+ assertNotNull("Unexpected value of queue attribute statistics", queueData.get(Asserts.STATISTICS_ATTRIBUTE));
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) queueData.get(Asserts.STATISTICS_ATTRIBUTE);
+ Asserts.assertAttributesPresent(statistics, Queue.AVAILABLE_STATISTICS, Queue.DISCARDS_TTL_BYTES,
+ Queue.DISCARDS_TTL_MESSAGES, Queue.STATE_CHANGED);
+ }
+
+ public static void assertAttributesPresent(Map<String, Object> data, String[] attributes)
+ {
+ for (String name : attributes)
+ {
+ assertNotNull("Attribute " + name + " is not present", data.get(name));
+ }
+ }
+
+ public static void assertAttributesPresent(Map<String, Object> data, Collection<String> attributes,
+ String... unsupportedAttributes)
+ {
+ for (String name : attributes)
+ {
+ boolean unsupported = false;
+ for (String unsupportedAttribute : unsupportedAttributes)
+ {
+ if (unsupportedAttribute.equals(name))
+ {
+ unsupported = true;
+ break;
+ }
+ }
+ if (unsupported)
+ {
+ continue;
+ }
+ assertNotNull("Attribute " + name + " is not present", data.get(name));
+ }
+ }
+
+ public static void assertConnection(Map<String, Object> connectionData, AMQConnection connection) throws JMSException
+ {
+ assertNotNull("Unexpected connection data", connectionData);
+ assertAttributesPresent(connectionData, Connection.AVAILABLE_ATTRIBUTES, Connection.STATE, Connection.DURABLE,
+ Connection.LIFETIME_POLICY, Connection.TIME_TO_LIVE, Connection.CREATED, Connection.UPDATED,
+ Connection.INCOMING, Connection.REMOTE_PROCESS_NAME, Connection.REMOTE_PROCESS_PID,
+ Connection.LOCAL_ADDRESS, Connection.PROPERTIES);
+
+ assertEquals("Unexpected value of connection attribute " + Connection.SESSION_COUNT_LIMIT,
+ (int) connection.getMaximumChannelCount(), connectionData.get(Connection.SESSION_COUNT_LIMIT));
+ assertEquals("Unexpected value of connection attribute " + Connection.CLIENT_ID, "clientid",
+ connectionData.get(Connection.CLIENT_ID));
+ assertEquals("Unexpected value of connection attribute " + Connection.PRINCIPAL, "guest",
+ connectionData.get(Connection.PRINCIPAL));
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) connectionData.get(STATISTICS_ATTRIBUTE);
+ assertAttributesPresent(statistics, Connection.AVAILABLE_STATISTICS, Connection.LOCAL_TRANSACTION_BEGINS,
+ Connection.LOCAL_TRANSACTION_ROLLBACKS, Connection.STATE_CHANGED, Connection.XA_TRANSACTION_BRANCH_ENDS,
+ Connection.XA_TRANSACTION_BRANCH_STARTS, Connection.XA_TRANSACTION_BRANCH_SUSPENDS);
+ assertEquals("Unexpected value of connection statistics attribute " + Connection.SESSION_COUNT, 1,
+ statistics.get(Connection.SESSION_COUNT));
+ }
+
+ public static void assertPortAttributes(Map<String, Object> port)
+ {
+
+ assertNotNull("Unexpected value of attribute " + Port.ID, port.get(Port.ID));
+ assertEquals("Unexpected value of attribute " + Port.DURABLE, Boolean.FALSE, port.get(Port.DURABLE));
+ assertEquals("Unexpected value of attribute " + Port.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
+ port.get(Broker.LIFETIME_POLICY));
+ assertEquals("Unexpected value of attribute " + Port.STATE, State.ACTIVE.name(), port.get(Port.STATE));
+ assertEquals("Unexpected value of attribute " + Port.TIME_TO_LIVE, 0, port.get(Port.TIME_TO_LIVE));
+
+ @SuppressWarnings("unchecked")
+ Collection<String> protocols = (Collection<String>) port.get(Port.PROTOCOLS);
+ assertNotNull("Unexpected value of attribute " + Port.PROTOCOLS, protocols);
+ boolean isAMQPPort = false;
+ for (String protocolName : protocols)
+ {
+ if (Protocol.valueOf(protocolName).isAMQP())
+ {
+ isAMQPPort = true;
+ break;
+ }
+ }
+ if (isAMQPPort)
+ {
+ assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER);
+ assertNotNull("Unexpected value of attribute " + Port.BINDING_ADDRESS, port.get(Port.BINDING_ADDRESS));
+ }
+ else
+ {
+ assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER,
+ Port.BINDING_ADDRESS, Port.TCP_NO_DELAY, Port.SEND_BUFFER_SIZE, Port.RECEIVE_BUFFER_SIZE,
+ Port.NEED_CLIENT_AUTH, Port.WANT_CLIENT_AUTH);
+ }
+
+ @SuppressWarnings("unchecked")
+ Collection<String> transports = (Collection<String>) port.get(Port.TRANSPORTS);
+ assertEquals("Unexpected value of attribute " + Port.TRANSPORTS, new HashSet<String>(Arrays.asList("TCP")),
+ new HashSet<String>(transports));
+ }
+
+ public static void assertDurableExchange(String exchangeName, String type, Map<String, Object> exchangeData)
+ {
+ assertExchange(exchangeName, type, exchangeData);
+
+ assertEquals("Unexpected value of exchange attribute " + Exchange.DURABLE, Boolean.TRUE,
+ exchangeData.get(Exchange.DURABLE));
+ }
+
+ public static void assertExchange(String exchangeName, String type, Map<String, Object> exchangeData)
+ {
+ assertNotNull("Exchange " + exchangeName + " is not found!", exchangeData);
+ assertAttributesPresent(exchangeData, Exchange.AVAILABLE_ATTRIBUTES, Exchange.CREATED, Exchange.UPDATED,
+ Exchange.ALTERNATE_EXCHANGE, Exchange.TIME_TO_LIVE);
+
+ assertEquals("Unexpected value of exchange attribute " + Exchange.NAME, exchangeName,
+ exchangeData.get(Exchange.NAME));
+ assertNotNull("Unexpected value of exchange attribute " + Exchange.ID, exchangeData.get(VirtualHost.ID));
+ assertEquals("Unexpected value of exchange attribute " + Exchange.STATE, State.ACTIVE.name(),
+ exchangeData.get(Exchange.STATE));
+
+ assertEquals("Unexpected value of exchange attribute " + Exchange.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
+ exchangeData.get(Exchange.LIFETIME_POLICY));
+ assertEquals("Unexpected value of exchange attribute " + Exchange.TYPE, type, exchangeData.get(Exchange.TYPE));
+ assertNotNull("Unexpected value of exchange attribute statistics", exchangeData.get(STATISTICS_ATTRIBUTE));
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) exchangeData.get(STATISTICS_ATTRIBUTE);
+ assertAttributesPresent(statistics, Exchange.AVAILABLE_STATISTICS, Exchange.STATE_CHANGED, Exchange.PRODUCER_COUNT);
+ }
+
+ public static void assertBinding(String bindingName, String queueName, String exchange, Map<String, Object> binding)
+ {
+ assertNotNull("Binding map should not be null", binding);
+ assertAttributesPresent(binding, Binding.AVAILABLE_ATTRIBUTES, Binding.STATE, Binding.TIME_TO_LIVE,
+ Binding.CREATED, Binding.UPDATED);
+
+ assertEquals("Unexpected binding attribute " + Binding.NAME, bindingName, binding.get(Binding.NAME));
+ assertEquals("Unexpected binding attribute " + Binding.QUEUE, queueName, binding.get(Binding.QUEUE));
+ assertEquals("Unexpected binding attribute " + Binding.EXCHANGE, exchange, binding.get(Binding.EXCHANGE));
+ assertEquals("Unexpected binding attribute " + Binding.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
+ binding.get(Binding.LIFETIME_POLICY));
+ }
+
+ public static void assertBinding(String queueName, String exchange, Map<String, Object> binding)
+ {
+ assertBinding(queueName, queueName, exchange, binding);
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java
new file mode 100644
index 0000000000..a171b4459b
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java
@@ -0,0 +1,73 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.User;
+
+public class AuthenticationProviderRestTest extends QpidRestTestCase
+{
+
+ public void testGet() throws Exception
+ {
+ List<Map<String, Object>> providerDetails = getRestTestHelper().getJsonAsList("/rest/authenticationprovider");
+ assertNotNull("Providers details cannot be null", providerDetails);
+ assertEquals("Unexpected number of providers", 1, providerDetails.size());
+ for (Map<String, Object> provider : providerDetails)
+ {
+ assertProvider("PrincipalDatabaseAuthenticationManager", provider);
+ Map<String, Object> data = getRestTestHelper().getJsonAsSingletonList("/rest/authenticationprovider/"
+ + provider.get(AuthenticationProvider.NAME));
+ assertNotNull("Cannot load data for " + provider.get(AuthenticationProvider.NAME), data);
+ assertProvider("PrincipalDatabaseAuthenticationManager", data);
+ }
+ }
+
+ private void assertProvider(String type, Map<String, Object> provider)
+ {
+ Asserts.assertAttributesPresent(provider, AuthenticationProvider.AVAILABLE_ATTRIBUTES,
+ AuthenticationProvider.CREATED, AuthenticationProvider.UPDATED, AuthenticationProvider.DESCRIPTION,
+ AuthenticationProvider.TIME_TO_LIVE);
+ assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.STATE, State.ACTIVE.name(),
+ provider.get(AuthenticationProvider.STATE));
+ assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.LIFETIME_POLICY,
+ LifetimePolicy.PERMANENT.name(), provider.get(AuthenticationProvider.LIFETIME_POLICY));
+ assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.DURABLE, Boolean.TRUE,
+ provider.get(AuthenticationProvider.DURABLE));
+ assertEquals("Unexpected value of provider attribute " + AuthenticationProvider.TYPE, type,
+ provider.get(AuthenticationProvider.TYPE));
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> users = (List<Map<String, Object>>) provider.get("users");
+ assertNotNull("Users are not found", users);
+ assertTrue("Unexpected number of users", users.size() > 1);
+ for (Map<String, Object> user : users)
+ {
+ assertNotNull("Attribute " + User.ID, user.get(User.ID));
+ assertNotNull("Attribute " + User.NAME, user.get(User.NAME));
+ }
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java
new file mode 100644
index 0000000000..0574b6cc24
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.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.systest.rest;
+
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.Collections;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
+public class BasicAuthRestTest extends QpidRestTestCase
+{
+ private static final String USERNAME = "admin";
+
+ @Override
+ public void setUp() throws Exception
+ {
+ setSystemProperty("javax.net.debug", "ssl");
+
+ //don't call super method, we will configure the broker in the test before doing so
+ }
+
+ @Override
+ protected void customizeConfiguration() throws ConfigurationException, IOException
+ {
+ //do nothing, we will configure this locally
+ }
+
+ private void configure(boolean useSsl) throws ConfigurationException, IOException
+ {
+ getRestTestHelper().setUseSsl(useSsl);
+ if (useSsl)
+ {
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PROTOCOLS, Collections.singleton(Protocol.HTTPS));
+ }
+ super.customizeConfiguration();
+ }
+
+ private void verifyGetBrokerAttempt(int responseCode) throws IOException
+ {
+ HttpURLConnection conn = getRestTestHelper().openManagementConnection("/rest/broker", "GET");
+ assertEquals(responseCode, conn.getResponseCode());
+ }
+
+ public void testDefaultEnabledWithHttps() throws Exception
+ {
+ configure(true);
+ super.setUp();
+ setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
+ setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
+
+ // Try the attempt with authentication, it should succeed because
+ // BASIC auth is enabled by default on secure connections.
+ getRestTestHelper().setUsernameAndPassword(USERNAME, USERNAME);
+ verifyGetBrokerAttempt(HttpServletResponse.SC_OK);
+ }
+
+ public void testDefaultDisabledWithHttp() throws Exception
+ {
+ configure(false);
+ super.setUp();
+
+ // Try the attempt with authentication, it should fail because
+ // BASIC auth is disabled by default on non-secure connections.
+ getRestTestHelper().setUsernameAndPassword(USERNAME, USERNAME);
+ verifyGetBrokerAttempt(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ public void testEnablingForHttp() throws Exception
+ {
+ configure(false);
+
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true);
+ super.setUp();
+
+ // Try the attempt with authentication, it should succeed because
+ // BASIC auth is now enabled on non-secure connections.
+ getRestTestHelper().setUsernameAndPassword(USERNAME, USERNAME);
+ verifyGetBrokerAttempt(HttpServletResponse.SC_OK);
+ }
+
+ public void testDisablingForHttps() throws Exception
+ {
+ configure(true);
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpsBasicAuthenticationEnabled", false);
+ super.setUp();
+ setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
+ setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
+
+ // Try the attempt with authentication, it should fail because
+ // BASIC auth is now disabled on secure connections.
+ getRestTestHelper().setUsernameAndPassword(USERNAME, USERNAME);
+ verifyGetBrokerAttempt(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java
new file mode 100644
index 0000000000..372db8f560
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.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.systest.rest;
+
+import java.net.HttpURLConnection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.server.model.Binding;
+
+public class BindingRestTest extends QpidRestTestCase
+{
+
+ public void testGetAllBindings() throws Exception
+ {
+ List<Map<String, Object>> bindings = getRestTestHelper().getJsonAsList("/rest/binding");
+ assertNotNull("Bindings cannot be null", bindings);
+ assertTrue("Unexpected number of bindings: " + bindings.size(),
+ bindings.size() >= EXPECTED_VIRTUALHOSTS.length * EXPECTED_QUEUES.length);
+ for (Map<String, Object> binding : bindings)
+ {
+ Asserts.assertBinding((String) binding.get(Binding.NAME), (String) binding.get(Binding.EXCHANGE), binding);
+ }
+ }
+
+ public void testGetVirtualHostBindings() throws Exception
+ {
+ List<Map<String, Object>> bindings = getRestTestHelper().getJsonAsList("/rest/binding/test");
+ assertNotNull("Bindings cannot be null", bindings);
+ assertEquals("Unexpected number of bindings", EXPECTED_QUEUES.length * 2, bindings.size());
+ for (String queueName : EXPECTED_QUEUES)
+ {
+ Map<String, Object> searchAttributes = new HashMap<String, Object>();
+ searchAttributes.put(Binding.NAME, queueName);
+ searchAttributes.put(Binding.EXCHANGE, "amq.direct");
+
+ Map<String, Object> binding = getRestTestHelper().find(searchAttributes, bindings);
+ Asserts.assertBinding(queueName, "amq.direct", binding);
+
+ searchAttributes.put(Binding.EXCHANGE, "<<default>>");
+
+ binding = getRestTestHelper().find(searchAttributes, bindings);
+ Asserts.assertBinding(queueName, "<<default>>", binding);
+ }
+ }
+
+ public void testGetVirtualHostExchangeBindings() throws Exception
+ {
+ List<Map<String, Object>> bindings = getRestTestHelper().getJsonAsList("/rest/binding/test/amq.direct");
+ assertNotNull("Bindings cannot be null", bindings);
+ assertEquals("Unexpected number of bindings", EXPECTED_QUEUES.length, bindings.size());
+ for (String queueName : EXPECTED_QUEUES)
+ {
+ Map<String, Object> binding = getRestTestHelper().find(Binding.NAME, queueName, bindings);
+ Asserts.assertBinding(queueName, "amq.direct", binding);
+ }
+ }
+
+ public void testGetVirtualHostExchangeQueueBindings() throws Exception
+ {
+ List<Map<String, Object>> bindings = getRestTestHelper().getJsonAsList("/rest/binding/test/amq.direct/queue");
+ assertNotNull("Bindings cannot be null", bindings);
+ assertEquals("Unexpected number of bindings", 1, bindings.size());
+ Asserts.assertBinding("queue", "amq.direct", bindings.get(0));
+ }
+
+
+ public void testDeleteBinding() throws Exception
+ {
+ List<Map<String, Object>> bindings = getRestTestHelper().getJsonAsList("/rest/binding/test/amq.direct/queue/queue");
+ assertEquals("Unexpected number of bindings", 1, bindings.size());
+ Asserts.assertBinding("queue", "amq.direct", bindings.get(0));
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/binding/test/amq.direct/queue/queue", "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+
+ bindings = getRestTestHelper().getJsonAsList("/rest/binding/test/amq.direct/queue/queue");
+ assertEquals("Binding should be deleted", 0, bindings.size());
+ }
+
+ public void testDeleteBindingById() throws Exception
+ {
+ Map<String, Object> binding = getRestTestHelper().getJsonAsSingletonList("/rest/binding/test/amq.direct/queue");
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/binding/test/amq.direct?id=" + binding.get(Binding.ID), "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+ List<Map<String, Object>> bindings = getRestTestHelper().getJsonAsList("/rest/binding/test/amq.direct/queue");
+ assertEquals("Binding should be deleted", 0, bindings.size());
+ }
+
+ public void testCreateBinding() throws Exception
+ {
+ String bindingName = getTestName();
+ Map<String, Object> bindingData = new HashMap<String, Object>();
+ bindingData.put(Binding.NAME, bindingName);
+ bindingData.put(Binding.QUEUE, "queue");
+ bindingData.put(Binding.EXCHANGE, "amq.direct");
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/binding/test/amq.direct/queue/" + bindingName, "PUT");
+ connection.connect();
+ getRestTestHelper().writeJsonRequest(connection, bindingData);
+ int responseCode = connection.getResponseCode();
+ connection.disconnect();
+ assertEquals("Unexpected response code", 201, responseCode);
+ Map<String, Object> binding = getRestTestHelper().getJsonAsSingletonList("/rest/binding/test/amq.direct/queue/" + bindingName);
+
+ Asserts.assertBinding(bindingName, "queue", "amq.direct", binding);
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java
new file mode 100644
index 0000000000..13e0c1e819
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.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.systest.rest;
+
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
+public class BrokerRestHttpsTest extends QpidRestTestCase
+{
+ @Override
+ public void setUp() throws Exception
+ {
+ setSystemProperty("javax.net.debug", "ssl");
+ super.setUp();
+ setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
+ setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
+ }
+
+ @Override
+ protected void customizeConfiguration() throws ConfigurationException, IOException
+ {
+ super.customizeConfiguration();
+ getRestTestHelper().setUseSsl(true);
+ Map<String, Object> newAttributes = new HashMap<String, Object>();
+ newAttributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTPS));
+ newAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT,newAttributes);
+ }
+
+ public void testGetWithHttps() throws Exception
+ {
+ Map<String, Object> brokerDetails = getRestTestHelper().getJsonAsSingletonList("/rest/broker");
+
+ Asserts.assertAttributesPresent(brokerDetails, Broker.AVAILABLE_ATTRIBUTES, Broker.BYTES_RETAINED,
+ Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES, Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED,
+ Broker.ACL_FILE, Broker.KEY_STORE_CERT_ALIAS, Broker.TRUST_STORE_PATH, Broker.TRUST_STORE_PASSWORD,
+ Broker.GROUP_FILE);
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java
new file mode 100644
index 0000000000..d479d39287
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java
@@ -0,0 +1,120 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.common.QpidProperties;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
+public class BrokerRestTest extends QpidRestTestCase
+{
+
+ private static final String BROKER_AUTHENTICATIONPROVIDERS_ATTRIBUTE = "authenticationproviders";
+ private static final String BROKER_PORTS_ATTRIBUTE = "ports";
+ private static final String BROKER_VIRTUALHOSTS_ATTRIBUTE = "virtualhosts";
+ private static final String BROKER_STATISTICS_ATTRIBUTE = "statistics";
+
+ public void testGet() throws Exception
+ {
+ Map<String, Object> brokerDetails = getRestTestHelper().getJsonAsSingletonList("/rest/broker");
+
+ assertBrokerAttributes(brokerDetails);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) brokerDetails.get(BROKER_STATISTICS_ATTRIBUTE);
+ Asserts.assertAttributesPresent(statistics, new String[]{ "bytesIn", "messagesOut", "bytesOut", "messagesIn" });
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) brokerDetails.get(BROKER_VIRTUALHOSTS_ATTRIBUTE);
+ assertEquals("Unexpected number of virtual hosts", 3, virtualhosts.size());
+
+ Asserts.assertVirtualHost(TEST3_VIRTUALHOST, getRestTestHelper().find(VirtualHost.NAME, TEST3_VIRTUALHOST, virtualhosts));
+ Asserts.assertVirtualHost(TEST2_VIRTUALHOST, getRestTestHelper().find(VirtualHost.NAME, TEST2_VIRTUALHOST, virtualhosts));
+ Asserts.assertVirtualHost(TEST1_VIRTUALHOST, getRestTestHelper().find(VirtualHost.NAME, TEST1_VIRTUALHOST, virtualhosts));
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> ports = (List<Map<String, Object>>) brokerDetails.get(BROKER_PORTS_ATTRIBUTE);
+ assertEquals("Unexpected number of ports", 4, ports.size());
+
+ for (Map<String, Object> port : ports)
+ {
+ Asserts.assertPortAttributes(port);
+ }
+
+ Map<String, Object> amqpPort = getRestTestHelper().find(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, ports);
+ Map<String, Object> httpPort = getRestTestHelper().find(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, ports);
+
+ assertEquals("Unexpected binding address", "*", amqpPort.get(Port.BINDING_ADDRESS));
+ assertNotNull("Cannot find AMQP port", amqpPort);
+ assertNotNull("Cannot find HTTP port", httpPort);
+
+ @SuppressWarnings("unchecked")
+ Collection<String> port1Protocols = (Collection<String>) amqpPort.get(Port.PROTOCOLS);
+ assertFalse("AMQP protocol list cannot contain HTTP", port1Protocols.contains("HTTP"));
+
+ @SuppressWarnings("unchecked")
+ Collection<String> port2Protocols = (Collection<String>) httpPort.get(Port.PROTOCOLS);
+ assertEquals("Unexpected value of attribute " + Port.PROTOCOLS, new HashSet<String>(Arrays.asList("HTTP")),
+ new HashSet<String>(port2Protocols));
+ }
+
+ protected void assertBrokerAttributes(Map<String, Object> brokerDetails)
+ {
+ Asserts.assertAttributesPresent(brokerDetails, Broker.AVAILABLE_ATTRIBUTES,
+ Broker.BYTES_RETAINED, Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES,
+ Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED, Broker.ACL_FILE,
+ Broker.KEY_STORE_PATH, Broker.KEY_STORE_PASSWORD, Broker.KEY_STORE_CERT_ALIAS,
+ Broker.TRUST_STORE_PATH, Broker.TRUST_STORE_PASSWORD, Broker.GROUP_FILE);
+
+ assertEquals("Unexpected value of attribute " + Broker.BUILD_VERSION, QpidProperties.getBuildVersion(),
+ brokerDetails.get(Broker.BUILD_VERSION));
+ assertEquals("Unexpected value of attribute " + Broker.OPERATING_SYSTEM, System.getProperty("os.name") + " "
+ + System.getProperty("os.version") + " " + System.getProperty("os.arch"),
+ brokerDetails.get(Broker.OPERATING_SYSTEM));
+ assertEquals(
+ "Unexpected value of attribute " + Broker.PLATFORM,
+ System.getProperty("java.vendor") + " "
+ + System.getProperty("java.runtime.version", System.getProperty("java.version")),
+ brokerDetails.get(Broker.PLATFORM));
+ assertEquals("Unexpected value of attribute " + Broker.DURABLE, Boolean.TRUE, brokerDetails.get(Broker.DURABLE));
+ assertEquals("Unexpected value of attribute " + Broker.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(),
+ brokerDetails.get(Broker.LIFETIME_POLICY));
+ assertEquals("Unexpected value of attribute " + Broker.NAME, "QpidBroker", brokerDetails.get(Broker.NAME));
+ assertEquals("Unexpected value of attribute " + Broker.STATE, State.ACTIVE.name(), brokerDetails.get(Broker.STATE));
+
+ assertNotNull("Unexpected value of attribute " + Broker.ID, brokerDetails.get(Broker.ID));
+ assertNotNull("Unexpected value of attribute statistics", brokerDetails.get(BROKER_STATISTICS_ATTRIBUTE));
+ assertNotNull("Unexpected value of attribute virtualhosts", brokerDetails.get(BROKER_VIRTUALHOSTS_ATTRIBUTE));
+ assertNotNull("Unexpected value of attribute ports", brokerDetails.get(BROKER_PORTS_ATTRIBUTE));
+ assertNotNull("Unexpected value of attribute authenticationproviders", brokerDetails.get(BROKER_AUTHENTICATIONPROVIDERS_ATTRIBUTE));
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/ConnectionRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/ConnectionRestTest.java
new file mode 100644
index 0000000000..05c8e362a1
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/ConnectionRestTest.java
@@ -0,0 +1,213 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.io.IOException;
+import java.net.URLDecoder;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.server.model.Connection;
+import org.apache.qpid.server.model.Session;
+
+public class ConnectionRestTest extends QpidRestTestCase
+{
+ /**
+ * Message number to publish into queue
+ */
+ private static final int MESSAGE_NUMBER = 5;
+ private static final int MESSAGE_SIZE = 6;
+
+ private static final String SESSIONS_ATTRIBUTE = "sessions";
+
+ private javax.jms.Connection _connection;
+ private javax.jms.Session _session;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ _connection = getConnection();
+ _session = _connection.createSession(true, javax.jms.Session.SESSION_TRANSACTED);
+ String queueName = getTestQueueName();
+ Destination queue = _session.createQueue(queueName);
+ MessageConsumer consumer = _session.createConsumer(queue);
+ MessageProducer producer = _session.createProducer(queue);
+ _connection.start();
+
+ // send messages
+ for (int i = 0; i < MESSAGE_NUMBER; i++)
+ {
+ producer.send(_session.createTextMessage("Test-" + i));
+ }
+ _session.commit();
+
+ Message m = consumer.receive(1000l);
+ assertNotNull("Message was not received", m);
+ _session.commit();
+
+ // receive the rest of messages for rollback
+ for (int i = 0; i < MESSAGE_NUMBER - 1; i++)
+ {
+ m = consumer.receive(1000l);
+ assertNotNull("Message was not received", m);
+ }
+ _session.rollback();
+
+ // receive them again
+ for (int i = 0; i < MESSAGE_NUMBER - 1; i++)
+ {
+ m = consumer.receive(1000l);
+ assertNotNull("Message was not received", m);
+ }
+ }
+
+ public void testGetAllConnections() throws Exception
+ {
+ List<Map<String, Object>> connections = getRestTestHelper().getJsonAsList("/rest/connection");
+ assertEquals("Unexpected number of connections", 1, connections.size());
+ Asserts.assertConnection(connections.get(0), (AMQConnection) _connection);
+ }
+
+ public void testGetVirtualHostConnections() throws Exception
+ {
+ List<Map<String, Object>> connections = getRestTestHelper().getJsonAsList("/rest/connection/test");
+ assertEquals("Unexpected number of connections", 1, connections.size());
+ Asserts.assertConnection(connections.get(0), (AMQConnection) _connection);
+ }
+
+ public void testGetConnectionByName() throws Exception
+ {
+ // get connection name
+ String connectionName = getConnectionName();
+
+ Map<String, Object> connectionDetails = getRestTestHelper().getJsonAsSingletonList("/rest/connection/test/"
+ + URLDecoder.decode(connectionName, "UTF-8"));
+ assertConnection(connectionDetails);
+ }
+
+ public void testGetAllSessions() throws Exception
+ {
+ List<Map<String, Object>> sessions = getRestTestHelper().getJsonAsList("/rest/session");
+ assertEquals("Unexpected number of sessions", 1, sessions.size());
+ assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
+ }
+
+ public void testGetVirtualHostSessions() throws Exception
+ {
+ List<Map<String, Object>> sessions = getRestTestHelper().getJsonAsList("/rest/session/test");
+ assertEquals("Unexpected number of sessions", 1, sessions.size());
+ assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
+ }
+
+ public void testGetConnectionSessions() throws Exception
+ {
+ // get connection name
+ String connectionName = getConnectionName();
+
+ List<Map<String, Object>> sessions = getRestTestHelper().getJsonAsList("/rest/session/test/"
+ + URLDecoder.decode(connectionName, "UTF-8"));
+ assertEquals("Unexpected number of sessions", 1, sessions.size());
+ assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
+ }
+
+ public void testGetSessionByName() throws Exception
+ {
+ // get connection name
+ String connectionName = getConnectionName();
+
+ List<Map<String, Object>> sessions = getRestTestHelper().getJsonAsList("/rest/session/test/"
+ + URLDecoder.decode(connectionName, "UTF-8") + "/" + ((AMQSession<?, ?>) _session).getChannelId());
+ assertEquals("Unexpected number of sessions", 1, sessions.size());
+ assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
+ }
+
+ private void assertConnection(Map<String, Object> connectionDetails) throws JMSException
+ {
+ Asserts.assertConnection(connectionDetails, (AMQConnection) _connection);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) connectionDetails.get(Asserts.STATISTICS_ATTRIBUTE);
+ assertEquals("Unexpected value of connection statistics attribute " + Connection.BYTES_IN, MESSAGE_NUMBER
+ * MESSAGE_SIZE, statistics.get(Connection.BYTES_IN));
+ assertEquals("Unexpected value of connection statistics attribute " + Connection.BYTES_OUT, MESSAGE_SIZE
+ + ((MESSAGE_NUMBER - 1) * MESSAGE_SIZE) * 2, statistics.get(Connection.BYTES_OUT));
+ assertEquals("Unexpected value of connection statistics attribute " + Connection.MESSAGES_IN, MESSAGE_NUMBER,
+ statistics.get(Connection.MESSAGES_IN));
+ assertEquals("Unexpected value of connection statistics attribute " + Connection.MESSAGES_OUT,
+ MESSAGE_NUMBER * 2 - 1, statistics.get(Connection.MESSAGES_OUT));
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> sessions = (List<Map<String, Object>>) connectionDetails.get(SESSIONS_ATTRIBUTE);
+ assertNotNull("Sessions cannot be found", sessions);
+ assertEquals("Unexpected number of sessions", 1, sessions.size());
+ assertSession(sessions.get(0), (AMQSession<?, ?>) _session);
+ }
+
+ private void assertSession(Map<String, Object> sessionData, AMQSession<?, ?> session)
+ {
+ assertNotNull("Session map cannot be null", sessionData);
+ Asserts.assertAttributesPresent(sessionData, Session.AVAILABLE_ATTRIBUTES, Session.STATE, Session.DURABLE,
+ Session.LIFETIME_POLICY, Session.TIME_TO_LIVE, Session.CREATED, Session.UPDATED);
+ assertEquals("Unexpecte value of attribute " + Session.NAME, session.getChannelId() + "",
+ sessionData.get(Session.NAME));
+ assertEquals("Unexpecte value of attribute " + Session.PRODUCER_FLOW_BLOCKED, Boolean.FALSE,
+ sessionData.get(Session.PRODUCER_FLOW_BLOCKED));
+ assertEquals("Unexpecte value of attribute " + Session.CHANNEL_ID, session.getChannelId(),
+ sessionData.get(Session.CHANNEL_ID));
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) sessionData.get(Asserts.STATISTICS_ATTRIBUTE);
+ Asserts.assertAttributesPresent(statistics, Session.AVAILABLE_STATISTICS, Session.BYTES_IN, Session.BYTES_OUT,
+ Session.STATE_CHANGED, Session.UNACKNOWLEDGED_BYTES, Session.LOCAL_TRANSACTION_OPEN,
+ Session.XA_TRANSACTION_BRANCH_ENDS, Session.XA_TRANSACTION_BRANCH_STARTS,
+ Session.XA_TRANSACTION_BRANCH_SUSPENDS);
+
+ assertEquals("Unexpecte value of statistic attribute " + Session.UNACKNOWLEDGED_MESSAGES, MESSAGE_NUMBER - 1,
+ statistics.get(Session.UNACKNOWLEDGED_MESSAGES));
+ assertEquals("Unexpecte value of statistic attribute " + Session.LOCAL_TRANSACTION_BEGINS, 4,
+ statistics.get(Session.LOCAL_TRANSACTION_BEGINS));
+ assertEquals("Unexpecte value of statistic attribute " + Session.LOCAL_TRANSACTION_ROLLBACKS, 1,
+ statistics.get(Session.LOCAL_TRANSACTION_ROLLBACKS));
+ assertEquals("Unexpecte value of statistic attribute " + Session.CONSUMER_COUNT, 1,
+ statistics.get(Session.CONSUMER_COUNT));
+ }
+
+ private String getConnectionName() throws IOException
+ {
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> connections = (List<Map<String, Object>>) hostDetails
+ .get(VirtualHostRestTest.VIRTUALHOST_CONNECTIONS_ATTRIBUTE);
+ assertEquals("Unexpected number of connections", 1, connections.size());
+ Map<String, Object> connection = connections.get(0);
+ String connectionName = (String) connection.get(Connection.NAME);
+ return connectionName;
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/ExchangeRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/ExchangeRestTest.java
new file mode 100644
index 0000000000..ec9791db13
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/ExchangeRestTest.java
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.net.URLDecoder;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.Exchange;
+
+public class ExchangeRestTest extends QpidRestTestCase
+{
+ public void testGet() throws Exception
+ {
+ List<Map<String, Object>> exchanges = getRestTestHelper().getJsonAsList("/rest/exchange");
+ assertNotNull("Exchanges cannot be null", exchanges);
+ assertTrue("Unexpected number of exchanges", exchanges.size() >= EXPECTED_VIRTUALHOSTS.length * EXPECTED_EXCHANGES.length);
+ for (Map<String, Object> exchange : exchanges)
+ {
+ Asserts.assertExchange((String) exchange.get(Exchange.NAME), (String) exchange.get(Exchange.TYPE), exchange);
+ }
+ }
+
+ public void testGetHostExchanges() throws Exception
+ {
+ List<Map<String, Object>> exchanges = getRestTestHelper().getJsonAsList("/rest/exchange/test");
+ assertNotNull("Users cannot be null", exchanges);
+ assertEquals("Unexpected number of exchanges", exchanges.size(), EXPECTED_EXCHANGES.length);
+ for (String exchangeName : EXPECTED_EXCHANGES)
+ {
+ Map<String, Object> exchange = getRestTestHelper().find(Exchange.NAME, exchangeName, exchanges);
+ assertExchange(exchangeName, exchange);
+ }
+ }
+
+ public void testGetHostExchangeByName() throws Exception
+ {
+ for (String exchangeName : EXPECTED_EXCHANGES)
+ {
+ Map<String, Object> exchange = getRestTestHelper().getJsonAsSingletonList("/rest/exchange/test/"
+ + URLDecoder.decode(exchangeName, "UTF-8"));
+ assertExchange(exchangeName, exchange);
+ }
+ }
+
+ private void assertExchange(String exchangeName, Map<String, Object> exchange)
+ {
+ assertNotNull("Exchange with name " + exchangeName + " is not found", exchange);
+ String type = (String) exchange.get(Exchange.TYPE);
+ Asserts.assertExchange(exchangeName, type, exchange);
+ if ("direct".equals(type))
+ {
+ assertBindings(exchange);
+ }
+ }
+
+ private void assertBindings(Map<String, Object> exchange)
+ {
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> bindings = (List<Map<String, Object>>) exchange.get("bindings");
+ for (String queueName : EXPECTED_QUEUES)
+ {
+ Map<String, Object> binding = getRestTestHelper().find(Binding.NAME, queueName, bindings);
+ Asserts.assertBinding(queueName, (String) exchange.get(Exchange.NAME), binding);
+ }
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
new file mode 100644
index 0000000000..861bf8cb71
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java
@@ -0,0 +1,160 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Group;
+import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.UUIDGenerator;
+
+public class GroupProviderRestTest extends QpidRestTestCase
+{
+ private static final String FILE_GROUP_MANAGER = "FileGroupManager";
+ private File _groupFile;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ _groupFile = createTemporaryGroupFile();
+
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath());
+
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (_groupFile != null)
+ {
+ if (_groupFile.exists())
+ {
+ _groupFile.delete();
+ }
+ }
+ }
+
+ public void testGet() throws Exception
+ {
+ List<Map<String, Object>> providerDetails = getRestTestHelper().getJsonAsList("/rest/groupprovider");
+ assertNotNull("Providers details cannot be null", providerDetails);
+ assertEquals("Unexpected number of providers", 1, providerDetails.size());
+ for (Map<String, Object> provider : providerDetails)
+ {
+ assertProvider(FILE_GROUP_MANAGER, provider);
+ Map<String, Object> data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/"
+ + provider.get(GroupProvider.NAME));
+ assertNotNull("Cannot load data for " + provider.get(GroupProvider.NAME), data);
+ assertProvider(FILE_GROUP_MANAGER, data);
+ }
+ }
+
+ public void testCreateNewGroup() throws Exception
+ {
+ String groupName = "newGroup";
+
+ Map<String, Object> data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ assertNotNull("Cannot load data for provider", data);
+
+ getRestTestHelper().assertNumberOfGroups(data, 1);
+
+ getRestTestHelper().createGroup(groupName, FILE_GROUP_MANAGER);
+
+ data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ assertNotNull("Cannot load data for provider", data);
+
+ getRestTestHelper().assertNumberOfGroups(data, 2);
+ }
+
+ public void testRemoveGroup() throws Exception
+ {
+ String groupName = "myGroup";
+
+ Map<String, Object> data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ assertNotNull("Cannot load data for provider", data);
+
+ getRestTestHelper().assertNumberOfGroups(data, 1);
+
+ getRestTestHelper().removeGroup(groupName, FILE_GROUP_MANAGER);
+
+ data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ assertNotNull("Cannot load data for provider", data);
+
+ getRestTestHelper().assertNumberOfGroups(data, 0);
+ }
+
+
+ private void assertProvider(String type, Map<String, Object> provider)
+ {
+ Asserts.assertAttributesPresent(provider, GroupProvider.AVAILABLE_ATTRIBUTES,
+ GroupProvider.CREATED, GroupProvider.UPDATED, GroupProvider.DESCRIPTION,
+ GroupProvider.TIME_TO_LIVE);
+ assertEquals("Unexpected value of provider attribute " + GroupProvider.STATE, State.ACTIVE.name(),
+ provider.get(GroupProvider.STATE));
+ assertEquals("Unexpected value of provider attribute " + GroupProvider.LIFETIME_POLICY,
+ LifetimePolicy.PERMANENT.name(), provider.get(GroupProvider.LIFETIME_POLICY));
+ assertEquals("Unexpected value of provider attribute " + GroupProvider.DURABLE, Boolean.TRUE,
+ provider.get(GroupProvider.DURABLE));
+ assertEquals("Unexpected value of provider attribute " + GroupProvider.TYPE, type,
+ provider.get(GroupProvider.TYPE));
+
+ final String name = (String) provider.get(GroupProvider.NAME);
+ assertEquals("Unexpected value of provider attribute " + GroupProvider.NAME, type,
+ name);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> groups = (List<Map<String, Object>>) provider.get("groups");
+ assertNotNull("Groups were not found", groups);
+ assertEquals("Unexpected number of groups", 1, groups.size());
+ for (Map<String, Object> group : groups)
+ {
+
+ final String groupName = (String) group.get(Group.NAME);
+ assertNotNull("Attribute " + Group.NAME, groupName);
+
+ assertNotNull("Attribute " + Group.ID, group.get(Group.ID));
+ assertEquals("Attribute " + Group.ID, UUIDGenerator.generateGroupUUID(name, groupName).toString(), group.get(Group.ID));
+ }
+ }
+
+ private File createTemporaryGroupFile() throws Exception
+ {
+ File groupFile = File.createTempFile("group", "grp");
+ groupFile.deleteOnExit();
+
+ Properties props = new Properties();
+ props.put("myGroup.users", "guest");
+
+ props.store(new FileOutputStream(groupFile), "test group file");
+
+ return groupFile;
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java
new file mode 100644
index 0000000000..d3f93cc0fe
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java
@@ -0,0 +1,109 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.GroupMember;
+
+public class GroupRestTest extends QpidRestTestCase
+{
+ private static final String GROUP_NAME = "myGroup";
+ private static final String FILE_GROUP_MANAGER = "FileGroupManager";
+ private static final String EXISTING_MEMBER = "user1";
+ private static final String NEW_MEMBER = "user2";
+
+ private File _groupFile;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ _groupFile = createTemporaryGroupFile();
+
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath());
+
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (_groupFile != null)
+ {
+ if (_groupFile.exists())
+ {
+ _groupFile.delete();
+ }
+ }
+ }
+
+ public void testGet() throws Exception
+ {
+ Map<String, Object> group = getRestTestHelper().getJsonAsSingletonList("/rest/group/FileGroupManager/myGroup");
+ List<Map<String, Object>> groupmembers = (List<Map<String, Object>>) group.get("groupmembers");
+ assertEquals(1, groupmembers.size());
+
+ Map<String, Object> member1 = groupmembers.get(0);
+ assertEquals(EXISTING_MEMBER, (String)member1.get(GroupMember.NAME));
+ }
+
+ public void testCreateNewMemberOfGroup() throws Exception
+ {
+ Map<String, Object> group = getRestTestHelper().getJsonAsSingletonList("/rest/group/FileGroupManager/myGroup");
+ getRestTestHelper().assertNumberOfGroupMembers(group, 1);
+
+ getRestTestHelper().createNewGroupMember(FILE_GROUP_MANAGER, GROUP_NAME, NEW_MEMBER);
+
+ group = getRestTestHelper().getJsonAsSingletonList("/rest/group/FileGroupManager/myGroup");
+ getRestTestHelper().assertNumberOfGroupMembers(group, 2);
+ }
+
+ public void testRemoveMemberFromGroup() throws Exception
+ {
+ Map<String, Object> group = getRestTestHelper().getJsonAsSingletonList("/rest/group/FileGroupManager/myGroup");
+ getRestTestHelper().assertNumberOfGroupMembers(group, 1);
+
+ getRestTestHelper().removeMemberFromGroup(FILE_GROUP_MANAGER, GROUP_NAME, EXISTING_MEMBER);
+
+ group = getRestTestHelper().getJsonAsSingletonList("/rest/group/FileGroupManager/myGroup");
+ getRestTestHelper().assertNumberOfGroupMembers(group, 0);
+ }
+
+ private File createTemporaryGroupFile() throws Exception
+ {
+ File groupFile = File.createTempFile("group", "grp");
+ groupFile.deleteOnExit();
+
+ Properties props = new Properties();
+ props.put(GROUP_NAME + ".users", EXISTING_MEMBER);
+
+ props.store(new FileOutputStream(groupFile), "test group file");
+
+ return groupFile;
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/LogRecordsRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/LogRecordsRestTest.java
new file mode 100644
index 0000000000..a2f9d3189c
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/LogRecordsRestTest.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.systest.rest;
+
+import java.util.List;
+import java.util.Map;
+
+public class LogRecordsRestTest extends QpidRestTestCase
+{
+ public void testGet() throws Exception
+ {
+ List<Map<String, Object>> logs = getRestTestHelper().getJsonAsList("/rest/logrecords");
+ assertNotNull("Logs data cannot be null", logs);
+ assertTrue("Logs are not found", logs.size() > 0);
+ Map<String, Object> record = getRestTestHelper().find("message", "[Broker] BRK-1004 : Qpid Broker Ready", logs);
+
+ assertNotNull("BRK-1004 message is not found", record);
+ assertNotNull("Message id cannot be null", record.get("id"));
+ assertNotNull("Message timestamp cannot be null", record.get("timestamp"));
+ assertEquals("Unexpected log level", "INFO", record.get("level"));
+ assertEquals("Unexpected thread", "main", record.get("thread"));
+ assertEquals("Unexpected logger", "qpid.message.broker.ready", record.get("logger"));
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/MessagesRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/MessagesRestTest.java
new file mode 100644
index 0000000000..fb6bfca1d8
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/MessagesRestTest.java
@@ -0,0 +1,354 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+
+public class MessagesRestTest extends QpidRestTestCase
+{
+
+ /**
+ * Message number to publish into queue
+ */
+ private static final int MESSAGE_NUMBER = 12;
+
+ private Connection _connection;
+ private Session _session;
+ private MessageProducer _producer;
+ private long _startTime;
+ private long _ttl;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ _startTime = System.currentTimeMillis();
+ _connection = getConnection();
+ _session = _connection.createSession(true, Session.SESSION_TRANSACTED);
+ String queueName = getTestQueueName();
+ Destination queue = _session.createQueue(queueName);
+ _session.createConsumer(queue);
+ _producer = _session.createProducer(queue);
+
+ _ttl = TimeUnit.DAYS.toMillis(1);
+ for (int i = 0; i < MESSAGE_NUMBER; i++)
+ {
+ Message m = _session.createTextMessage("Test-" + i);
+ m.setIntProperty("index", i);
+ if (i % 2 == 0)
+ {
+ _producer.send(m);
+ }
+ else
+ {
+ _producer.send(m, DeliveryMode.NON_PERSISTENT, 5, _ttl);
+ }
+ }
+ _session.commit();
+ }
+
+ public void testGet() throws Exception
+ {
+ String queueName = getTestQueueName();
+ List<Map<String, Object>> messages = getRestTestHelper().getJsonAsList("/rest/message/test/" + queueName);
+ assertNotNull("Messages are not found", messages);
+ assertEquals("Unexpected number of messages", MESSAGE_NUMBER, messages.size());
+ int position = 0;
+ for (Map<String, Object> message : messages)
+ {
+ assertMessage(position, message);
+ position++;
+ }
+ }
+
+ public void testGetMessageContent() throws Exception
+ {
+ String queueName = getTestQueueName();
+
+ // add bytes message
+ BytesMessage byteMessage = _session.createBytesMessage();
+ byte[] messageBytes = "Test".getBytes();
+ byteMessage.writeBytes(messageBytes);
+ byteMessage.setStringProperty("test", "value");
+ _producer.send(byteMessage);
+ _session.commit();
+
+ // get message IDs
+ List<Long> ids = getMesssageIds(queueName);
+
+ Map<String, Object> message = getRestTestHelper().getJsonAsMap("/rest/message/test/" + queueName + "/" + ids.get(0));
+ assertMessageAttributes(message);
+ assertMessageAttributeValues(message, true);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> headers = (Map<String, Object>) message.get("headers");
+ assertNotNull("Message headers are not found", headers);
+ assertEquals("Unexpected message header", 0, headers.get("index"));
+
+ Long lastMessageId = ids.get(ids.size() - 1);
+ message = getRestTestHelper().getJsonAsMap("/rest/message/test/" + queueName + "/" + lastMessageId);
+ assertMessageAttributes(message);
+ assertEquals("Unexpected message attribute mimeType", "application/octet-stream", message.get("mimeType"));
+ assertEquals("Unexpected message attribute size", 4, message.get("size"));
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> bytesMessageHeader = (Map<String, Object>) message.get("headers");
+ assertNotNull("Message headers are not found", bytesMessageHeader);
+ assertEquals("Unexpected message header", "value", bytesMessageHeader.get("test"));
+
+ // get content
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/message-content/test/" + queueName + "/"
+ + lastMessageId, "GET");
+ connection.connect();
+ byte[] data = getRestTestHelper().readConnectionInputStream(connection);
+ assertTrue("Unexpected message", Arrays.equals(messageBytes, data));
+
+ }
+
+ public void testPostMoveMessages() throws Exception
+ {
+ String queueName = getTestQueueName();
+ String queueName2 = queueName + "_2";
+ Destination queue2 = _session.createQueue(queueName2);
+ _session.createConsumer(queue2);
+
+ // get message IDs
+ List<Long> ids = getMesssageIds(queueName);
+
+ // move half of the messages
+ int movedNumber = ids.size() / 2;
+ List<Long> movedMessageIds = new ArrayList<Long>();
+ for (int i = 0; i < movedNumber; i++)
+ {
+ movedMessageIds.add(ids.remove(i));
+ }
+
+ // move messages
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/message/test/" + queueName, "POST");
+
+ Map<String, Object> messagesData = new HashMap<String, Object>();
+ messagesData.put("messages", movedMessageIds);
+ messagesData.put("destinationQueue", queueName2);
+ messagesData.put("move", Boolean.TRUE);
+
+ getRestTestHelper().writeJsonRequest(connection, messagesData);
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+
+ // check messages on target queue
+ List<Map<String, Object>> messages = getRestTestHelper().getJsonAsList("/rest/message/test/" + queueName2);
+ assertNotNull("Messages are not found", messages);
+ assertEquals("Unexpected number of messages", movedMessageIds.size(), messages.size());
+ for (Long id : movedMessageIds)
+ {
+ Map<String, Object> message = getRestTestHelper().find("id", id.intValue(), messages);
+ assertMessageAttributes(message);
+ }
+
+ // check messages on original queue
+ messages = getRestTestHelper().getJsonAsList("/rest/message/test/" + queueName);
+ assertNotNull("Messages are not found", messages);
+ assertEquals("Unexpected number of messages", ids.size(), messages.size());
+ for (Long id : ids)
+ {
+ Map<String, Object> message = getRestTestHelper().find("id", id.intValue(), messages);
+ assertMessageAttributes(message);
+ }
+ for (Long id : movedMessageIds)
+ {
+ Map<String, Object> message = getRestTestHelper().find("id", id.intValue(), messages);
+ assertNull("Moved message " + id + " is found on original queue", message);
+ }
+ }
+
+ public void testPostCopyMessages() throws Exception
+ {
+ String queueName = getTestQueueName();
+ String queueName2 = queueName + "_2";
+ Destination queue2 = _session.createQueue(queueName2);
+ _session.createConsumer(queue2);
+
+ // get message IDs
+ List<Long> ids = getMesssageIds(queueName);
+
+ // copy half of the messages
+ int copyNumber = ids.size() / 2;
+ List<Long> copyMessageIds = new ArrayList<Long>();
+ for (int i = 0; i < copyNumber; i++)
+ {
+ copyMessageIds.add(ids.remove(i));
+ }
+
+ // copy messages
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/message/test/" + queueName, "POST");
+
+ Map<String, Object> messagesData = new HashMap<String, Object>();
+ messagesData.put("messages", copyMessageIds);
+ messagesData.put("destinationQueue", queueName2);
+
+ getRestTestHelper().writeJsonRequest(connection, messagesData);
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+
+ // check messages on target queue
+ List<Map<String, Object>> messages = getRestTestHelper().getJsonAsList("/rest/message/test/" + queueName2);
+ assertNotNull("Messages are not found", messages);
+ assertEquals("Unexpected number of messages", copyMessageIds.size(), messages.size());
+ for (Long id : copyMessageIds)
+ {
+ Map<String, Object> message = getRestTestHelper().find("id", id.intValue(), messages);
+ assertMessageAttributes(message);
+ }
+
+ // check messages on original queue
+ messages = getRestTestHelper().getJsonAsList("/rest/message/test/" + queueName);
+ assertNotNull("Messages are not found", messages);
+ assertEquals("Unexpected number of messages", MESSAGE_NUMBER, messages.size());
+ for (Long id : ids)
+ {
+ Map<String, Object> message = getRestTestHelper().find("id", id.intValue(), messages);
+ assertMessageAttributes(message);
+ }
+ for (Long id : copyMessageIds)
+ {
+ Map<String, Object> message = getRestTestHelper().find("id", id.intValue(), messages);
+ assertMessageAttributes(message);
+ }
+ }
+
+ public void testDeleteMessages() throws Exception
+ {
+ String queueName = getTestQueueName();
+
+ // get message IDs
+ List<Long> ids = getMesssageIds(queueName);
+
+ // delete half of the messages
+ int deleteNumber = ids.size() / 2;
+ StringBuilder queryString = new StringBuilder();
+ List<Long> deleteMessageIds = new ArrayList<Long>();
+ for (int i = 0; i < deleteNumber; i++)
+ {
+ Long id = ids.remove(i);
+ deleteMessageIds.add(id);
+ if (queryString.length() > 0)
+ {
+ queryString.append("&");
+ }
+ queryString.append("id=").append(id);
+ }
+
+ // delete messages
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection(
+ "/rest/message/test/" + queueName + "?" + queryString.toString(), "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+
+ // check messages on queue
+ List<Map<String, Object>> messages = getRestTestHelper().getJsonAsList("/rest/message/test/" + queueName);
+ assertNotNull("Messages are not found", messages);
+ assertEquals("Unexpected number of messages", ids.size(), messages.size());
+ for (Long id : ids)
+ {
+ Map<String, Object> message = getRestTestHelper().find("id", id.intValue(), messages);
+ assertMessageAttributes(message);
+ }
+ for (Long id : deleteMessageIds)
+ {
+ Map<String, Object> message = getRestTestHelper().find("id", id.intValue(), messages);
+ assertNull("Message with id " + id + " was not deleted", message);
+ }
+ }
+
+ private List<Long> getMesssageIds(String queueName) throws IOException, JsonParseException, JsonMappingException
+ {
+ List<Map<String, Object>> messages = getRestTestHelper().getJsonAsList("/rest/message/test/" + queueName);
+ List<Long> ids = new ArrayList<Long>();
+ for (Map<String, Object> message : messages)
+ {
+ ids.add(((Number) message.get("id")).longValue());
+ }
+ return ids;
+ }
+
+ private void assertMessage(int position, Map<String, Object> message)
+ {
+ assertMessageAttributes(message);
+
+ assertEquals("Unexpected message attribute position", position, message.get("position"));
+ assertEquals("Unexpected message attribute size", position < 10 ? 6 : 7, message.get("size"));
+ boolean even = position % 2 == 0;
+ assertMessageAttributeValues(message, even);
+ }
+
+ private void assertMessageAttributeValues(Map<String, Object> message, boolean even)
+ {
+ if (even)
+ {
+ assertEquals("Unexpected message attribute expirationTime", 0, message.get("expirationTime"));
+ assertEquals("Unexpected message attribute priority", 4, message.get("priority"));
+ assertEquals("Unexpected message attribute persistent", Boolean.TRUE, message.get("persistent"));
+ }
+ else
+ {
+ assertEquals("Unexpected message attribute expirationTime", ((Number) message.get("timestamp")).longValue()
+ + _ttl, message.get("expirationTime"));
+ assertEquals("Unexpected message attribute priority", 5, message.get("priority"));
+ assertEquals("Unexpected message attribute persistent", Boolean.FALSE, message.get("persistent"));
+ }
+ assertEquals("Unexpected message attribute mimeType", "text/plain", message.get("mimeType"));
+ assertEquals("Unexpected message attribute userId", "guest", message.get("userId"));
+ assertEquals("Unexpected message attribute deliveryCount", 0, message.get("deliveryCount"));
+ assertEquals("Unexpected message attribute state", "Available", message.get("state"));
+ }
+
+ private void assertMessageAttributes(Map<String, Object> message)
+ {
+ assertNotNull("Message map cannot be null", message);
+ assertNotNull("Unexpected message attribute deliveryCount", message.get("deliveryCount"));
+ assertNotNull("Unexpected message attribute state", message.get("state"));
+ assertNotNull("Unexpected message attribute id", message.get("id"));
+ assertNotNull("Message arrivalTime cannot be null", message.get("arrivalTime"));
+ assertNotNull("Message timestamp cannot be null", message.get("timestamp"));
+ assertTrue("Message arrivalTime cannot be null", ((Number) message.get("arrivalTime")).longValue() > _startTime);
+ assertNotNull("Message messageId cannot be null", message.get("messageId"));
+ assertNotNull("Unexpected message attribute mimeType", message.get("mimeType"));
+ assertNotNull("Unexpected message attribute userId", message.get("userId"));
+ assertNotNull("Message priority cannot be null", message.get("priority"));
+ assertNotNull("Message expirationTime cannot be null", message.get("expirationTime"));
+ assertNotNull("Message persistent cannot be null", message.get("persistent"));
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java
new file mode 100644
index 0000000000..578565be05
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.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.systest.rest;
+
+import java.net.URLDecoder;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
+public class PortRestTest extends QpidRestTestCase
+{
+ public void testGet() throws Exception
+ {
+ List<Map<String, Object>> ports = getRestTestHelper().getJsonAsList("/rest/port/");
+ assertNotNull("Port data cannot be null", ports);
+ assertEquals("Unexpected number of ports", 4, ports.size());
+
+ String httpPortName = TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT;
+ Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports);
+ assertNotNull("Http port " + httpPortName + " is not found", portData);
+ Asserts.assertPortAttributes(portData);
+
+ String amqpPortName = TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT;
+ Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports);
+ assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData);
+ Asserts.assertPortAttributes(amqpPortData);
+ }
+
+ public void testGetPort() throws Exception
+ {
+ List<Map<String, Object>> ports = getRestTestHelper().getJsonAsList("/rest/port/");
+ assertNotNull("Ports data cannot be null", ports);
+ assertEquals("Unexpected number of ports", 4, ports.size());
+ for (Map<String, Object> portMap : ports)
+ {
+ String portName = (String) portMap.get(Port.NAME);
+ assertNotNull("Port name attribute is not found", portName);
+ Map<String, Object> portData = getRestTestHelper().getJsonAsSingletonList("/rest/port/" + URLDecoder.decode(portName, "UTF-8"));
+ assertNotNull("Port " + portName + " is not found", portData);
+ Asserts.assertPortAttributes(portData);
+ }
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java
new file mode 100644
index 0000000000..671bdd7eb8
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.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.systest.rest;
+
+import java.io.IOException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+
+public class QpidRestTestCase extends QpidBrokerTestCase
+{
+ public static final String TEST1_VIRTUALHOST = "test";
+ public static final String TEST2_VIRTUALHOST = "test2";
+ public static final String TEST3_VIRTUALHOST = "test3";
+
+ public static final String[] EXPECTED_VIRTUALHOSTS = { TEST1_VIRTUALHOST, TEST2_VIRTUALHOST, TEST3_VIRTUALHOST};
+ public static final String[] EXPECTED_QUEUES = { "queue", "ping" };
+ public static final String[] EXPECTED_EXCHANGES = { "amq.fanout", "amq.match", "amq.direct","amq.topic","<<default>>" };
+
+ private RestTestHelper _restTestHelper = new RestTestHelper(findFreePort());
+
+ @Override
+ public void setUp() throws Exception
+ {
+ // Set up virtualhost config with queues and bindings to the amq.direct
+ for (String virtualhost : EXPECTED_VIRTUALHOSTS)
+ {
+ createTestVirtualHost(0, virtualhost);
+ for (String queue : EXPECTED_QUEUES)
+ {
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.exchange", "amq.direct");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.queue(-1).name", queue);
+ }
+ }
+
+ customizeConfiguration();
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ getRestTestHelper().tearDown();
+ }
+ }
+
+ protected void customizeConfiguration() throws ConfigurationException, IOException
+ {
+ TestBrokerConfiguration config = getBrokerConfiguration();
+ config.addHttpManagementConfiguration();
+ config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, _restTestHelper.getHttpPort());
+ }
+
+ public RestTestHelper getRestTestHelper()
+ {
+ return _restTestHelper;
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/QueueRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/QueueRestTest.java
new file mode 100644
index 0000000000..1f441e7cbb
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/QueueRestTest.java
@@ -0,0 +1,225 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URLDecoder;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.Consumer;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Queue;
+
+public class QueueRestTest extends QpidRestTestCase
+{
+ private static final String QUEUE_ATTRIBUTE_CONSUMERS = "consumers";
+ private static final String QUEUE_ATTRIBUTE_BINDINGS = "bindings";
+
+ /**
+ * Message number to publish into queue
+ */
+ private static final int MESSAGE_NUMBER = 2;
+ private static final int MESSAGE_PAYLOAD_SIZE = 6;
+ private static final int ENQUEUED_MESSAGES = 1;
+ private static final int DEQUEUED_MESSAGES = 1;
+ private static final int ENQUEUED_BYTES = MESSAGE_PAYLOAD_SIZE;
+ private static final int DEQUEUED_BYTES = MESSAGE_PAYLOAD_SIZE;
+
+ private Connection _connection;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ _connection = getConnection();
+ Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
+ String queueName = getTestQueueName();
+ Destination queue = session.createQueue(queueName);
+ MessageConsumer consumer = session.createConsumer(queue);
+ MessageProducer producer = session.createProducer(queue);
+
+ for (int i = 0; i < MESSAGE_NUMBER; i++)
+ {
+ producer.send(session.createTextMessage("Test-" + i));
+ }
+ session.commit();
+ _connection.start();
+ Message m = consumer.receive(1000l);
+ assertNotNull("Message is not received", m);
+ session.commit();
+ }
+
+ public void testGetVirtualHostQueues() throws Exception
+ {
+ String queueName = getTestQueueName();
+ List<Map<String, Object>> queues = getRestTestHelper().getJsonAsList("/rest/queue/test");
+ assertEquals("Unexpected number of queues", EXPECTED_QUEUES.length + 1, queues.size());
+ String[] expectedQueues = new String[EXPECTED_QUEUES.length + 1];
+ System.arraycopy(EXPECTED_QUEUES, 0, expectedQueues, 0, EXPECTED_QUEUES.length);
+ expectedQueues[EXPECTED_QUEUES.length] = queueName;
+
+ for (String name : expectedQueues)
+ {
+ Map<String, Object> queueDetails = getRestTestHelper().find(Queue.NAME, name, queues);
+ Asserts.assertQueue(name, "standard", queueDetails);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
+ assertNotNull("Queue bindings are not found", bindings);
+ assertEquals("Unexpected number of bindings", 2, bindings.size());
+
+ Map<String, Object> defaultExchangeBinding = getRestTestHelper().find(Binding.EXCHANGE, "<<default>>", bindings);
+ Map<String, Object> directExchangeBinding = getRestTestHelper().find(Binding.EXCHANGE, "amq.direct", bindings);
+ Asserts.assertBinding(name, "<<default>>", defaultExchangeBinding);
+ Asserts.assertBinding(name, "amq.direct", directExchangeBinding);
+ }
+ }
+
+ public void testGetByName() throws Exception
+ {
+ String queueName = getTestQueueName();
+ Map<String, Object> queueDetails = getRestTestHelper().getJsonAsSingletonList("/rest/queue/test/" + queueName);
+ Asserts.assertQueue(queueName, "standard", queueDetails);
+ assertStatistics(queueDetails);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
+ assertNotNull("Queue bindings are not found", bindings);
+ assertEquals("Unexpected number of bindings", 2, bindings.size());
+
+ Map<String, Object> defaultExchangeBinding = getRestTestHelper().find(Binding.EXCHANGE, "<<default>>", bindings);
+ Map<String, Object> directExchangeBinding = getRestTestHelper().find(Binding.EXCHANGE, "amq.direct", bindings);
+ Asserts.assertBinding(queueName, "<<default>>", defaultExchangeBinding);
+ Asserts.assertBinding(queueName, "amq.direct", directExchangeBinding);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> consumers = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_CONSUMERS);
+ assertNotNull("Queue consumers are not found", consumers);
+ assertEquals("Unexpected number of consumers", 1, consumers.size());
+ assertConsumer(consumers.get(0));
+ }
+
+ public void testPutCreateBinding() throws Exception
+ {
+ String queueName = getTestQueueName();
+ String bindingName = queueName + 2;
+ String[] exchanges = { "amq.direct", "amq.fanout", "amq.topic", "amq.match", "<<default>>" };
+
+ for (int i = 0; i < exchanges.length; i++)
+ {
+ createBinding(bindingName, exchanges[i], queueName);
+ }
+
+ Map<String, Object> queueDetails = getRestTestHelper().getJsonAsSingletonList("/rest/queue/test/" + queueName);
+ Asserts.assertQueue(queueName, "standard", queueDetails);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
+ assertNotNull("Queue bindings are not found", bindings);
+ assertEquals("Unexpected number of bindings", exchanges.length + 2, bindings.size());
+
+ Map<String, Object> searchAttributes = new HashMap<String, Object>();
+ searchAttributes.put(Binding.NAME, bindingName);
+
+ for (int i = 0; i < exchanges.length; i++)
+ {
+ searchAttributes.put(Binding.EXCHANGE, exchanges[i]);
+ Map<String, Object> binding = getRestTestHelper().find(searchAttributes, bindings);
+ Asserts.assertBinding(bindingName, queueName, exchanges[i], binding);
+ }
+ }
+
+ private void createBinding(String bindingName, String exchangeName, String queueName) throws IOException
+ {
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection(
+ "/rest/binding/test/" + URLDecoder.decode(exchangeName, "UTF-8") + "/" + queueName + "/" + bindingName,
+ "PUT");
+
+ Map<String, Object> bindingData = new HashMap<String, Object>();
+ bindingData.put(Binding.NAME, bindingName);
+ bindingData.put(Binding.EXCHANGE, exchangeName);
+ bindingData.put(Binding.QUEUE, queueName);
+
+ getRestTestHelper().writeJsonRequest(connection, bindingData);
+ assertEquals("Unexpected response code", 201, connection.getResponseCode());
+
+ connection.disconnect();
+ }
+
+ private void assertConsumer(Map<String, Object> consumer)
+ {
+ assertNotNull("Consumer map should not be null", consumer);
+ Asserts.assertAttributesPresent(consumer, Consumer.AVAILABLE_ATTRIBUTES, Consumer.STATE, Consumer.TIME_TO_LIVE,
+ Consumer.CREATED, Consumer.UPDATED, Consumer.SETTLEMENT_MODE, Consumer.EXCLUSIVE, Consumer.SELECTOR,
+ Consumer.NO_LOCAL);
+
+ assertEquals("Unexpected binding attribute " + Consumer.NAME, "1", consumer.get(Consumer.NAME));
+ assertEquals("Unexpected binding attribute " + Consumer.DURABLE, Boolean.FALSE, consumer.get(Consumer.DURABLE));
+ assertEquals("Unexpected binding attribute " + Consumer.LIFETIME_POLICY, LifetimePolicy.AUTO_DELETE.name(),
+ consumer.get(Consumer.LIFETIME_POLICY));
+ assertEquals("Unexpected binding attribute " + Consumer.DISTRIBUTION_MODE, "MOVE",
+ consumer.get(Consumer.DISTRIBUTION_MODE));
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) consumer.get(Asserts.STATISTICS_ATTRIBUTE);
+ assertNotNull("Consumer statistics is not present", statistics);
+ Asserts.assertAttributesPresent(statistics, Consumer.AVAILABLE_STATISTICS, Consumer.STATE_CHANGED);
+ }
+
+ private void assertStatistics(Map<String, Object> queueDetails)
+ {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) queueDetails.get(Asserts.STATISTICS_ATTRIBUTE);
+ assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
+ statistics.get(Queue.PERSISTENT_DEQUEUED_MESSAGES));
+ assertEquals("Unexpected queue statistics attribute " + Queue.QUEUE_DEPTH_MESSAGES, ENQUEUED_MESSAGES,
+ statistics.get(Queue.QUEUE_DEPTH_MESSAGES));
+ assertEquals("Unexpected queue statistics attribute " + Queue.CONSUMER_COUNT, 1,
+ statistics.get(Queue.CONSUMER_COUNT));
+ assertEquals("Unexpected queue statistics attribute " + Queue.CONSUMER_COUNT_WITH_CREDIT, 1,
+ statistics.get(Queue.CONSUMER_COUNT_WITH_CREDIT));
+ assertEquals("Unexpected queue statistics attribute " + Queue.BINDING_COUNT, 2, statistics.get(Queue.BINDING_COUNT));
+ assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
+ statistics.get(Queue.PERSISTENT_DEQUEUED_MESSAGES));
+ assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
+ statistics.get(Queue.TOTAL_DEQUEUED_MESSAGES));
+ assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_DEQUEUED_BYTES, DEQUEUED_BYTES,
+ statistics.get(Queue.TOTAL_DEQUEUED_BYTES));
+ assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_BYTES, DEQUEUED_BYTES,
+ statistics.get(Queue.TOTAL_DEQUEUED_BYTES));
+ assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_ENQUEUED_BYTES, ENQUEUED_BYTES
+ + DEQUEUED_BYTES, statistics.get(Queue.PERSISTENT_ENQUEUED_BYTES));
+ assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_ENQUEUED_BYTES, ENQUEUED_BYTES + DEQUEUED_BYTES,
+ statistics.get(Queue.TOTAL_ENQUEUED_BYTES));
+ assertEquals("Unexpected queue statistics attribute " + Queue.QUEUE_DEPTH_BYTES, ENQUEUED_BYTES,
+ statistics.get(Queue.QUEUE_DEPTH_BYTES));
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
new file mode 100644
index 0000000000..0db1f7e50d
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
@@ -0,0 +1,452 @@
+/*
+ * 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.systest.rest;
+
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE;
+import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManagerFactory;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.Assert;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory;
+import org.apache.qpid.ssl.SSLContextFactory;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+
+public class RestTestHelper
+{
+ private static final Logger LOGGER = Logger.getLogger(RestTestHelper.class);
+
+ private int _httpPort;
+
+ private boolean _useSsl;
+
+ private String _username;
+
+ private String _password;
+
+ private File _passwdFile;
+
+ public RestTestHelper(int httpPort)
+ {
+ _httpPort = httpPort;
+ }
+
+ public int getHttpPort()
+ {
+ return _httpPort;
+ }
+
+ private String getHostName()
+ {
+ return "localhost";
+ }
+
+ private String getProtocol()
+ {
+ return _useSsl ? "https" : "http";
+ }
+
+ public String getManagementURL()
+ {
+ return getProtocol() + "://" + getHostName() + ":" + getHttpPort();
+ }
+
+ public URL getManagementURL(String path) throws MalformedURLException
+ {
+ return new URL(getManagementURL() + path);
+ }
+
+ public HttpURLConnection openManagementConnection(String path, String method) throws IOException
+ {
+ URL url = getManagementURL(path);
+ HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
+ if(_useSsl)
+ {
+ try
+ {
+ // We have to use a SSLSocketFactory from a new SSLContext so that we don't re-use
+ // the JVM's defaults that may have been initialised in previous tests.
+
+ SSLContext sslContext = SSLContextFactory.buildClientContext(
+ TRUSTSTORE, TRUSTSTORE_PASSWORD,
+ KeyStore.getDefaultType(),
+ TrustManagerFactory.getDefaultAlgorithm(),
+ null, null, null, null, null);
+
+ SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
+
+ ((HttpsURLConnection) httpCon).setSSLSocketFactory(sslSocketFactory);
+ }
+ catch (GeneralSecurityException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ if(_username != null)
+ {
+ String encoded = new String(new Base64().encode((_username + ":" + _password).getBytes()));
+ httpCon.setRequestProperty("Authorization", "Basic " + encoded);
+ }
+
+ httpCon.setDoOutput(true);
+ httpCon.setRequestMethod(method);
+ return httpCon;
+ }
+
+ public List<Map<String, Object>> readJsonResponseAsList(HttpURLConnection connection) throws IOException,
+ JsonParseException, JsonMappingException
+ {
+ byte[] data = readConnectionInputStream(connection);
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ TypeReference<List<LinkedHashMap<String, Object>>> typeReference = new TypeReference<List<LinkedHashMap<String, Object>>>()
+ {
+ };
+ List<Map<String, Object>> providedObject = mapper.readValue(new ByteArrayInputStream(data), typeReference);
+ return providedObject;
+ }
+
+ public Map<String, Object> readJsonResponseAsMap(HttpURLConnection connection) throws IOException,
+ JsonParseException, JsonMappingException
+ {
+ byte[] data = readConnectionInputStream(connection);
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ TypeReference<LinkedHashMap<String, Object>> typeReference = new TypeReference<LinkedHashMap<String, Object>>()
+ {
+ };
+ Map<String, Object> providedObject = mapper.readValue(new ByteArrayInputStream(data), typeReference);
+ return providedObject;
+ }
+
+ public byte[] readConnectionInputStream(HttpURLConnection connection) throws IOException
+ {
+ InputStream is = connection.getInputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int len = -1;
+ while ((len = is.read(buffer)) != -1)
+ {
+ baos.write(buffer, 0, len);
+ }
+ if (LOGGER.isTraceEnabled())
+ {
+ LOGGER.trace("RESPONSE:" + new String(baos.toByteArray()));
+ }
+ return baos.toByteArray();
+ }
+
+ public void writeJsonRequest(HttpURLConnection connection, Map<String, Object> data) throws JsonGenerationException,
+ JsonMappingException, IOException
+ {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.writeValue(connection.getOutputStream(), data);
+ }
+
+ public Map<String, Object> find(String name, Object value, List<Map<String, Object>> data)
+ {
+ for (Map<String, Object> map : data)
+ {
+ Object mapValue = map.get(name);
+ if (value.equals(mapValue))
+ {
+ return map;
+ }
+ }
+ return null;
+ }
+
+ public Map<String, Object> find(Map<String, Object> searchAttributes, List<Map<String, Object>> data)
+ {
+ for (Map<String, Object> map : data)
+ {
+ boolean equals = true;
+ for (Map.Entry<String, Object> entry : searchAttributes.entrySet())
+ {
+ Object mapValue = map.get(entry.getKey());
+ if (!entry.getValue().equals(mapValue))
+ {
+ equals = false;
+ break;
+ }
+ }
+ if (equals)
+ {
+ return map;
+ }
+ }
+ return null;
+ }
+
+ public Map<String, Object> getJsonAsSingletonList(String path) throws IOException
+ {
+ List<Map<String, Object>> response = getJsonAsList(path);
+
+ Assert.assertNotNull("Response cannot be null", response);
+ Assert.assertEquals("Unexpected response", 1, response.size());
+ return response.get(0);
+ }
+
+ public List<Map<String, Object>> getJsonAsList(String path) throws IOException, JsonParseException,
+ JsonMappingException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "GET");
+ connection.connect();
+ List<Map<String, Object>> response = readJsonResponseAsList(connection);
+ return response;
+ }
+
+ public Map<String, Object> getJsonAsMap(String path) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "GET");
+ connection.connect();
+ Map<String, Object> response = readJsonResponseAsMap(connection);
+ return response;
+ }
+
+ public void createNewGroupMember(String groupProviderName, String groupName, String memberName, int responseCode) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(
+ "/rest/groupmember/" + URLDecoder.decode(groupProviderName, "UTF-8") + "/"+ URLDecoder.decode(groupName, "UTF-8") + "/" + URLDecoder.decode(memberName, "UTF-8"),
+ "PUT");
+
+ Map<String, Object> groupMemberData = new HashMap<String, Object>();
+ // TODO add type
+ writeJsonRequest(connection, groupMemberData);
+
+ Assert.assertEquals("Unexpected response code", responseCode, connection.getResponseCode());
+
+ connection.disconnect();
+ }
+
+ public void createNewGroupMember(String groupProviderName, String groupName, String memberName) throws IOException
+ {
+ createNewGroupMember(groupProviderName, groupName, memberName, HttpServletResponse.SC_CREATED);
+ }
+
+ public void removeMemberFromGroup(String groupProviderName, String groupName, String memberName, int responseCode) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(
+ "/rest/groupmember/" + URLDecoder.decode(groupProviderName, "UTF-8") + "/"+ URLDecoder.decode(groupName, "UTF-8") + "/" + URLDecoder.decode(memberName, "UTF-8"),
+ "DELETE");
+
+ Assert.assertEquals("Unexpected response code", responseCode, connection.getResponseCode());
+
+ connection.disconnect();
+ }
+
+ public void removeMemberFromGroup(String groupProviderName, String groupName, String memberName) throws IOException
+ {
+ removeMemberFromGroup(groupProviderName, groupName, memberName, HttpServletResponse.SC_OK);
+ }
+
+ public void assertNumberOfGroupMembers(Map<String, Object> data, int expectedNumberOfGroupMembers)
+ {
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> groups = (List<Map<String, Object>>) data.get("groupmembers");
+ if (groups == null)
+ {
+ groups = Collections.emptyList();
+ }
+
+ Assert.assertEquals("Unexpected number of group members", expectedNumberOfGroupMembers, groups.size());
+ }
+
+ public void createGroup(String groupName, String groupProviderName) throws IOException
+ {
+ createGroup(groupName, groupProviderName, HttpServletResponse.SC_CREATED);
+ }
+
+ public void createGroup(String groupName, String groupProviderName, int responseCode) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(
+ "/rest/group/" + URLDecoder.decode(groupProviderName, "UTF-8") + "/"+ URLDecoder.decode(groupName, "UTF-8"),
+ "PUT");
+
+ Map<String, Object> groupData = new HashMap<String, Object>();
+ writeJsonRequest(connection, groupData);
+
+ Assert.assertEquals("Unexpected response code", responseCode, connection.getResponseCode());
+
+ connection.disconnect();
+ }
+
+ public void createOrUpdateUser(String username, String password) throws IOException
+ {
+ createOrUpdateUser(username, password, HttpServletResponse.SC_CREATED);
+ }
+
+ public void createOrUpdateUser(String username, String password, int responseCode) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username, "PUT");
+
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("password", password);
+ writeJsonRequest(connection, data);
+
+ Assert.assertEquals("Unexpected response code", responseCode, connection.getResponseCode());
+
+ connection.disconnect();
+ }
+
+ public void removeGroup(String groupName, String groupProviderName, int responseCode) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(
+ "/rest/group/" + URLDecoder.decode(groupProviderName, "UTF-8") + "/"+ URLDecoder.decode(groupName, "UTF-8"),
+ "DELETE");
+
+ Assert.assertEquals("Unexpected response code", responseCode, connection.getResponseCode());
+ connection.disconnect();
+ }
+
+ public void removeGroup(String groupName, String groupProviderName) throws IOException
+ {
+ removeGroup(groupName, groupProviderName, HttpServletResponse.SC_OK);
+ }
+
+ public void removeUserById(String id) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "?id=" + id, "DELETE");
+ Assert.assertEquals("Unexpected response code", HttpServletResponse.SC_OK, connection.getResponseCode());
+ connection.disconnect();
+ }
+
+ public void removeUser(String username, int responseCode) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username, "DELETE");
+ Assert.assertEquals("Unexpected response code", responseCode, connection.getResponseCode());
+ connection.disconnect();
+ }
+
+ public void removeUser(String username) throws IOException
+ {
+ removeUser(username, HttpServletResponse.SC_OK);
+ }
+
+ public void assertNumberOfGroups(Map<String, Object> data, int expectedNumberOfGroups)
+ {
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> groups = (List<Map<String, Object>>) data.get("groups");
+ if (groups == null)
+ {
+ groups = Collections.emptyList();
+ }
+ Assert.assertEquals("Unexpected number of groups", expectedNumberOfGroups, groups.size());
+ }
+
+ public void setUseSsl(boolean useSsl)
+ {
+ _useSsl = useSsl;
+ }
+
+ public void setUsernameAndPassword(String username, String password)
+ {
+ _username = username;
+ _password = password;
+ }
+
+ /**
+ * Create password file that follows the convention username=password, which is deleted by {@link #tearDown()}
+ */
+ public void configureTemporaryPasswordFile(QpidBrokerTestCase testCase, String... users) throws ConfigurationException, IOException
+ {
+ _passwdFile = createTemporaryPasswdFile(users);
+
+ testCase.getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER,
+ AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _passwdFile.getAbsolutePath());
+ }
+
+ public void tearDown()
+ {
+ if (_passwdFile != null)
+ {
+ if (_passwdFile.exists())
+ {
+ _passwdFile.delete();
+ }
+ }
+ }
+
+ private File createTemporaryPasswdFile(String[] users) throws IOException
+ {
+ BufferedWriter writer = null;
+ try
+ {
+ File testFile = File.createTempFile(this.getClass().getName(),"tmp");
+ testFile.deleteOnExit();
+
+ writer = new BufferedWriter(new FileWriter(testFile));
+ for (int i = 0; i < users.length; i++)
+ {
+ String username = users[i];
+ writer.write(username + ":" + username);
+ writer.newLine();
+ }
+
+ return testFile;
+
+ }
+ finally
+ {
+ if (writer != null)
+ {
+ writer.close();
+ }
+ }
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java
new file mode 100644
index 0000000000..856fda9419
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java
@@ -0,0 +1,435 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory;
+import org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+import org.apache.qpid.tools.security.Passwd;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+
+public class SaslRestTest extends QpidRestTestCase
+{
+ @Override
+ public void startBroker()
+ {
+ // prevent broker from starting in setUp
+ }
+
+ public void startBrokerNow() throws Exception
+ {
+ super.startBroker();
+ }
+
+ public void testGetMechanismsWithBrokerPlainPasswordPrincipalDatabase() throws Exception
+ {
+ startBrokerNow();
+
+ Map<String, Object> saslData = getRestTestHelper().getJsonAsMap("/rest/sasl");
+ assertNotNull("mechanisms attribute is not found", saslData.get("mechanisms"));
+
+ @SuppressWarnings("unchecked")
+ List<String> mechanisms = (List<String>) saslData.get("mechanisms");
+ String[] expectedMechanisms = { "AMQPLAIN", "PLAIN", "CRAM-MD5" };
+ for (String mechanism : expectedMechanisms)
+ {
+ assertTrue("Mechanism " + mechanism + " is not found", mechanisms.contains(mechanism));
+ }
+ assertNull("Unexpected user was returned", saslData.get("user"));
+ }
+
+ public void testGetMechanismsWithBrokerBase64MD5FilePrincipalDatabase() throws Exception
+ {
+ configureBase64MD5FilePrincipalDatabase();
+ startBrokerNow();
+
+ Map<String, Object> saslData = getRestTestHelper().getJsonAsMap("/rest/sasl");
+ assertNotNull("mechanisms attribute is not found", saslData.get("mechanisms"));
+
+ @SuppressWarnings("unchecked")
+ List<String> mechanisms = (List<String>) saslData.get("mechanisms");
+ String[] expectedMechanisms = { "CRAM-MD5-HEX", "CRAM-MD5-HASHED" };
+ for (String mechanism : expectedMechanisms)
+ {
+ assertTrue("Mechanism " + mechanism + " is not found", mechanisms.contains(mechanism));
+ }
+ assertNull("Unexpected user was returned", saslData.get("user"));
+ }
+
+ public void testPlainSaslAuthenticationForValidCredentials() throws Exception
+ {
+ startBrokerNow();
+
+ byte[] responseBytes = generatePlainClientResponse("admin", "admin");
+ String responseData = Base64.encodeBase64String(responseBytes);
+ String parameters= "mechanism=PLAIN&response=" + responseData;
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/sasl", "POST");
+ OutputStream os = connection.getOutputStream();
+ os.write(parameters.getBytes());
+ os.flush();
+
+ int code = connection.getResponseCode();
+ assertEquals("Unexpected response code", 200, code);
+
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertEquals("Unexpected user", "admin", response2.get("user"));
+ }
+
+ public void testPlainSaslAuthenticationForIncorrectPassword() throws Exception
+ {
+ startBrokerNow();
+
+ byte[] responseBytes = generatePlainClientResponse("admin", "incorrect");
+ String responseData = Base64.encodeBase64String(responseBytes);
+ String parameters= "mechanism=PLAIN&response=" + responseData;
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/sasl", "POST");
+ OutputStream os = connection.getOutputStream();
+ os.write(parameters.getBytes());
+ os.flush();
+
+ int code = connection.getResponseCode();
+ assertEquals("Unexpected response code", 403, code);
+
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertNull("Unexpected user", response2.get("user"));
+ }
+
+ public void testPlainSaslAuthenticationForNonExistingUser() throws Exception
+ {
+ startBrokerNow();
+
+ byte[] responseBytes = generatePlainClientResponse("nonexisting", "admin");
+ String responseData = Base64.encodeBase64String(responseBytes);
+ String parameters= "mechanism=PLAIN&response=" + responseData;
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/sasl", "POST");
+ OutputStream os = connection.getOutputStream();
+ os.write(parameters.getBytes());
+ os.flush();
+
+ int code = connection.getResponseCode();
+ assertEquals("Unexpected response code", 403, code);
+
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertNull("Unexpected user", response2.get("user"));
+ }
+
+ public void testCramMD5SaslAuthenticationForValidCredentials() throws Exception
+ {
+ startBrokerNow();
+
+ // request the challenge for CRAM-MD5
+ HttpURLConnection connection = requestSasServerChallenge("CRAM-MD5");
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // authenticate user with correct credentials
+ int code = authenticateUser(connection, "admin", "admin", "CRAM-MD5");
+ assertEquals("Unexpected response code", 200, code);
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertEquals("Unexpected user", "admin", response2.get("user"));
+ }
+
+ public void testCramMD5SaslAuthenticationForIncorrectPassword() throws Exception
+ {
+ startBrokerNow();
+
+ // request the challenge for CRAM-MD5
+ HttpURLConnection connection = requestSasServerChallenge("CRAM-MD5");
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // authenticate user with correct credentials
+ int code = authenticateUser(connection, "admin", "incorrect", "CRAM-MD5");
+ assertEquals("Unexpected response code", 403, code);
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertNull("Unexpected user", response2.get("user"));
+ }
+
+ public void testCramMD5SaslAuthenticationForNonExistingUser() throws Exception
+ {
+ startBrokerNow();
+
+ // request the challenge for CRAM-MD5
+ HttpURLConnection connection = requestSasServerChallenge("CRAM-MD5");
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // authenticate user with correct credentials
+ int code = authenticateUser(connection, "nonexisting", "admin", "CRAM-MD5");
+ assertEquals("Unexpected response code", 403, code);
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertNull("Unexpected user", response2.get("user"));
+ }
+
+ public void testCramMD5HexSaslAuthenticationForValidCredentials() throws Exception
+ {
+ configureBase64MD5FilePrincipalDatabase();
+ startBrokerNow();
+
+ // request the challenge for CRAM-MD5-HEX
+ HttpURLConnection connection = requestSasServerChallenge("CRAM-MD5-HEX");
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // authenticate user with correct credentials
+ int code = authenticateUser(connection, "admin", "admin", "CRAM-MD5-HEX");
+ assertEquals("Unexpected response code", 200, code);
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertEquals("Unexpected user", "admin", response2.get("user"));
+ }
+
+ public void testCramMD5HexSaslAuthenticationForIncorrectPassword() throws Exception
+ {
+ configureBase64MD5FilePrincipalDatabase();
+ startBrokerNow();
+
+ HttpURLConnection connection = requestSasServerChallenge("CRAM-MD5-HEX");
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // try to authenticate user with incorrect passowrd
+ int code = authenticateUser(connection, "admin", "incorrect", "CRAM-MD5-HEX");
+ assertEquals("Unexpected response code", 403, code);
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertNull("Unexpected user", response2.get("user"));
+ }
+
+ public void testCramMD5HexSaslAuthenticationForNonExistingUser() throws Exception
+ {
+ configureBase64MD5FilePrincipalDatabase();
+ startBrokerNow();
+
+ HttpURLConnection connection = requestSasServerChallenge("CRAM-MD5-HEX");
+ List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
+
+ // try to authenticate non-existing user
+ int code = authenticateUser(connection, "nonexisting", "admin", "CRAM-MD5-HEX");
+ assertEquals("Unexpected response code", 403, code);
+
+ // request authenticated user details
+ connection = getRestTestHelper().openManagementConnection("/rest/sasl", "GET");
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response2 = getRestTestHelper().readJsonResponseAsMap(connection);
+ assertNull("Unexpected user", response2.get("user"));
+ }
+
+ private HttpURLConnection requestSasServerChallenge(String mechanism) throws IOException
+ {
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/sasl", "POST");
+ OutputStream os = connection.getOutputStream();
+ os.write(("mechanism=" + mechanism).getBytes());
+ os.flush();
+ return connection;
+ }
+
+ private int authenticateUser(HttpURLConnection requestChallengeConnection, String userName, String userPassword, String mechanism)
+ throws IOException, JsonParseException, JsonMappingException, Exception
+ {
+ // get the response
+ Map<String, Object> response = getRestTestHelper().readJsonResponseAsMap(requestChallengeConnection);
+ String challenge = (String) response.get("challenge");
+ assertNotNull("Challenge is not found", challenge);
+
+ // preserve cookies to have the same server session
+ List<String> cookies = requestChallengeConnection.getHeaderFields().get("Set-Cookie");
+
+ // generate the authentication response for the challenge received
+ byte[] challengeBytes = Base64.decodeBase64(challenge);
+ byte[] responseBytes = generateClientResponse(mechanism, userName, userPassword, challengeBytes);
+ String responseData = Base64.encodeBase64String(responseBytes);
+ String requestParameters = ("id=" + response.get("id") + "&response=" + responseData);
+
+ // re-open connection
+ HttpURLConnection authenticateConnection = getRestTestHelper().openManagementConnection("/rest/sasl", "POST");
+
+ // set cookies to use the same server session
+ applyCookiesToConnection(cookies, authenticateConnection);
+ OutputStream os = authenticateConnection.getOutputStream();
+ os.write(requestParameters.getBytes());
+ os.flush();
+ return authenticateConnection.getResponseCode();
+ }
+
+ private byte[] generateClientResponse(String mechanism, String userName, String userPassword, byte[] challengeBytes) throws Exception
+ {
+ byte[] responseBytes = null;
+ if ("CRAM-MD5-HEX".equalsIgnoreCase(mechanism))
+ {
+ responseBytes = generateCramMD5HexClientResponse(userName, userPassword, challengeBytes);
+ }
+ else if ("CRAM-MD5".equalsIgnoreCase(mechanism))
+ {
+ responseBytes = generateCramMD5ClientResponse(userName, userPassword, challengeBytes);
+ }
+ else
+ {
+ throw new RuntimeException("Not implemented test mechanism " + mechanism);
+ }
+ return responseBytes;
+ }
+
+ private void applyCookiesToConnection(List<String> cookies, HttpURLConnection connection)
+ {
+ for (String cookie : cookies)
+ {
+ connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
+ }
+ }
+
+ private static byte SEPARATOR = 0;
+
+ private byte[] generatePlainClientResponse(String userName, String userPassword) throws Exception
+ {
+ byte[] password = userPassword.getBytes("UTF8");
+ byte user[] = userName.getBytes("UTF8");
+ byte response[] = new byte[password.length + user.length + 2 ];
+ int size = 0;
+ response[size++] = SEPARATOR;
+ System.arraycopy(user, 0, response, size, user.length);
+ size += user.length;
+ response[size++] = SEPARATOR;
+ System.arraycopy(password, 0, response, size, password.length);
+ return response;
+ }
+
+ private byte[] generateCramMD5HexClientResponse(String userName, String userPassword, byte[] challengeBytes) throws Exception
+ {
+ String macAlgorithm = "HmacMD5";
+ byte[] digestedPasswordBytes = MessageDigest.getInstance("MD5").digest(userPassword.getBytes("UTF-8"));
+ byte[] hexEncodedDigestedPasswordBytes = toHex(digestedPasswordBytes).getBytes("UTF-8");
+ Mac mac = Mac.getInstance(macAlgorithm);
+ mac.init(new SecretKeySpec(hexEncodedDigestedPasswordBytes, macAlgorithm));
+ final byte[] messageAuthenticationCode = mac.doFinal(challengeBytes);
+ String responseAsString = userName + " " + toHex(messageAuthenticationCode);
+ return responseAsString.getBytes();
+ }
+
+ private byte[] generateCramMD5ClientResponse(String userName, String userPassword, byte[] challengeBytes) throws Exception
+ {
+ String macAlgorithm = "HmacMD5";
+ Mac mac = Mac.getInstance(macAlgorithm);
+ mac.init(new SecretKeySpec(userPassword.getBytes("UTF-8"), macAlgorithm));
+ final byte[] messageAuthenticationCode = mac.doFinal(challengeBytes);
+ String responseAsString = userName + " " + toHex(messageAuthenticationCode);
+ return responseAsString.getBytes();
+ }
+
+ private String toHex(byte[] data)
+ {
+ StringBuffer hash = new StringBuffer();
+ for (int i = 0; i < data.length; i++)
+ {
+ String hex = Integer.toHexString(0xFF & data[i]);
+ if (hex.length() == 1)
+ {
+ hash.append('0');
+ }
+ hash.append(hex);
+ }
+ return hash.toString();
+ }
+
+ private void configureBase64MD5FilePrincipalDatabase() throws IOException, ConfigurationException
+ {
+ // generate user password entry
+ String passwordFileEntry;
+ try
+ {
+ passwordFileEntry = new Passwd().getOutput("admin", "admin");
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ throw new ConfigurationException(e);
+ }
+
+ // store the entry in the file
+ File passwordFile = File.createTempFile("passwd", "pwd");
+ passwordFile.deleteOnExit();
+
+ FileWriter writer = null;
+ try
+ {
+ writer = new FileWriter(passwordFile);
+ writer.write(passwordFileEntry);
+ }
+ finally
+ {
+ writer.close();
+ }
+
+ // configure broker to use Base64MD5PasswordFilePrincipalDatabase
+ Map<String, Object> newAttributes = new HashMap<String, Object>();
+ newAttributes.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, passwordFile.getAbsolutePath());
+ newAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
+ getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes);
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java
new file mode 100644
index 0000000000..427934fac2
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java
@@ -0,0 +1,114 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
+public class StructureRestTest extends QpidRestTestCase
+{
+
+ public void testGet() throws Exception
+ {
+ Map<String, Object> structure = getRestTestHelper().getJsonAsMap("/rest/structure");
+ assertNotNull("Structure data cannot be null", structure);
+ assertNode(structure, "QpidBroker");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) structure.get("virtualhosts");
+ assertEquals("Unexpected number of virtual hosts", 3, virtualhosts.size());
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> ports = (List<Map<String, Object>>) structure.get("ports");
+ assertEquals("Unexpected number of ports", 4, ports.size());
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> providers = (List<Map<String, Object>>) structure.get("authenticationproviders");
+ assertEquals("Unexpected number of authentication providers", 1, providers.size());
+
+ for (String hostName : EXPECTED_VIRTUALHOSTS)
+ {
+ Map<String, Object> host = getRestTestHelper().find("name", hostName, virtualhosts);
+ assertNotNull("Host " + hostName + " is not found ", host);
+ assertNode(host, hostName);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) host.get("queues");
+ assertNotNull("Host " + hostName + " queues are not found ", queues);
+ for (String queueName : EXPECTED_QUEUES)
+ {
+ Map<String, Object> queue = getRestTestHelper().find("name", queueName, queues);
+ assertNotNull(hostName + " queue " + queueName + " is not found ", queue);
+ assertNode(queue, queueName);
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> bindings = (List<Map<String, Object>>) queue.get("bindings");
+ assertNotNull(hostName + " queue " + queueName + " bindings are not found ", queues);
+ for (Map<String, Object> binding : bindings)
+ {
+ assertNode(binding, queueName);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> exchanges = (List<Map<String, Object>>) host.get("exchanges");
+ assertNotNull("Host " + hostName + " exchanges are not found ", exchanges);
+ for (String exchangeName : EXPECTED_EXCHANGES)
+ {
+ Map<String, Object> exchange = getRestTestHelper().find("name", exchangeName, exchanges);
+ assertNotNull("Exchange " + exchangeName + " is not found ", exchange);
+ assertNode(exchange, exchangeName);
+ if ("amq.direct".equalsIgnoreCase(exchangeName) || "<<default>>".equalsIgnoreCase(exchangeName))
+ {
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> bindings = (List<Map<String, Object>>) exchange.get("bindings");
+ assertNotNull(hostName + " exchange " + exchangeName + " bindings are not found ", bindings);
+ for (String queueName : EXPECTED_QUEUES)
+ {
+ Map<String, Object> binding = getRestTestHelper().find("name", queueName, bindings);
+ assertNotNull(hostName + " exchange " + exchangeName + " binding " + queueName + " is not found", binding);
+ assertNode(binding, queueName);
+ }
+ }
+ }
+ }
+
+
+ String httpPortName = TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT;
+ Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports);
+ assertNotNull("Http Port " + httpPortName + " is not found", portData);
+ assertNode(portData, httpPortName);
+
+ String amqpPortName = TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT;
+ Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports);
+ assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData);
+ assertNode(amqpPortData, amqpPortName);
+ }
+
+ private void assertNode(Map<String, Object> node, String name)
+ {
+ assertEquals("Unexpected name", name, node.get("name"));
+ assertNotNull("Unexpected id", node.get("id"));
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java
new file mode 100644
index 0000000000..017467a8be
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java
@@ -0,0 +1,99 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.server.model.User;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
+public class UserRestTest extends QpidRestTestCase
+{
+ @Override
+ public void setUp() throws Exception
+ {
+ getRestTestHelper().configureTemporaryPasswordFile(this, "user1", "user2");
+
+ super.setUp(); // do this last because it starts the broker, using the modified config
+ }
+
+ public void testGet() throws Exception
+ {
+ List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/rest/user");
+ assertNotNull("Users cannot be null", users);
+ assertTrue("Unexpected number of users", users.size() > 1);
+ for (Map<String, Object> user : users)
+ {
+ assertUser(user);
+ }
+ }
+
+ public void testGetUserByName() throws Exception
+ {
+ List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/rest/user");
+ assertNotNull("Users cannot be null", users);
+ assertTrue("Unexpected number of users", users.size() > 1);
+ for (Map<String, Object> user : users)
+ {
+ assertNotNull("Attribute " + User.ID, user.get(User.ID));
+ String userName = (String) user.get(User.NAME);
+ assertNotNull("Attribute " + User.NAME, userName);
+ Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName);
+ assertUser(userDetails);
+ assertEquals("Unexpected user name", userName, userDetails.get(User.NAME));
+ }
+ }
+
+ public void testPut() throws Exception
+ {
+ String userName = getTestName();
+ getRestTestHelper().createOrUpdateUser(userName, "newPassword");
+
+ Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName);
+ assertUser(userDetails);
+ assertEquals("Unexpected user name", userName, userDetails.get(User.NAME));
+ }
+
+ public void testDelete() throws Exception
+ {
+ String userName = getTestName();
+ getRestTestHelper().createOrUpdateUser(userName, "newPassword");
+
+ Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName);
+ String id = (String) userDetails.get(User.ID);
+
+ getRestTestHelper().removeUserById(id);
+
+ List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName);
+ assertEquals("User should be deleted", 0, users.size());
+ }
+
+ private void assertUser(Map<String, Object> user)
+ {
+ assertNotNull("Attribute " + User.ID, user.get(User.ID));
+ assertNotNull("Attribute " + User.NAME, user.get(User.NAME));
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java
new file mode 100644
index 0000000000..fb2c941203
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java
@@ -0,0 +1,576 @@
+/*
+ *
+ * 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.systest.rest;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.Session;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.apache.qpid.util.FileUtils;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+
+public class VirtualHostRestTest extends QpidRestTestCase
+{
+ private static final String VIRTUALHOST_EXCHANGES_ATTRIBUTE = "exchanges";
+ public static final String VIRTUALHOST_QUEUES_ATTRIBUTE = "queues";
+ public static final String VIRTUALHOST_CONNECTIONS_ATTRIBUTE = "connections";
+
+ private AMQConnection _connection;
+
+ public void testGet() throws Exception
+ {
+ List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("/rest/virtualhost/");
+ assertNotNull("Hosts data cannot be null", hosts);
+ assertEquals("Unexpected number of hosts", EXPECTED_VIRTUALHOSTS.length, hosts.size());
+ for (String hostName : EXPECTED_VIRTUALHOSTS)
+ {
+ Map<String, Object> host = getRestTestHelper().find("name", hostName, hosts);
+ Asserts.assertVirtualHost(hostName, host);
+ }
+ }
+
+ public void testGetHost() throws Exception
+ {
+ // create AMQP connection to get connection JSON details
+ _connection = (AMQConnection) getConnection();
+ _connection.createSession(true, Session.SESSION_TRANSACTED);
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+ Asserts.assertVirtualHost("test", hostDetails);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) hostDetails.get(Asserts.STATISTICS_ATTRIBUTE);
+ assertEquals("Unexpected number of exchanges in statistics", EXPECTED_EXCHANGES.length, statistics.get(VirtualHost.EXCHANGE_COUNT));
+ assertEquals("Unexpected number of queues in statistics", EXPECTED_QUEUES.length, statistics.get(VirtualHost.QUEUE_COUNT));
+ assertEquals("Unexpected number of connections in statistics", 1, statistics.get(VirtualHost.CONNECTION_COUNT));
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_EXCHANGES_ATTRIBUTE);
+ assertEquals("Unexpected number of exchanges", EXPECTED_EXCHANGES.length, exchanges.size());
+ Asserts.assertDurableExchange("amq.fanout", "fanout", getRestTestHelper().find(Exchange.NAME, "amq.fanout", exchanges));
+ Asserts.assertDurableExchange("amq.topic", "topic", getRestTestHelper().find(Exchange.NAME, "amq.topic", exchanges));
+ Asserts.assertDurableExchange("amq.direct", "direct", getRestTestHelper().find(Exchange.NAME, "amq.direct", exchanges));
+ Asserts.assertDurableExchange("amq.match", "headers", getRestTestHelper().find(Exchange.NAME, "amq.match", exchanges));
+ Asserts.assertDurableExchange("<<default>>", "direct", getRestTestHelper().find(Exchange.NAME, "<<default>>", exchanges));
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_QUEUES_ATTRIBUTE);
+ assertEquals("Unexpected number of queues", EXPECTED_QUEUES.length, queues.size());
+ Map<String, Object> queue = getRestTestHelper().find(Queue.NAME, "queue", queues);
+ Map<String, Object> ping = getRestTestHelper().find(Queue.NAME, "ping", queues);
+ Asserts.assertQueue("queue", "standard", queue);
+ Asserts.assertQueue("ping", "standard", ping);
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.FALSE, queue.get(Queue.DURABLE));
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.FALSE, ping.get(Queue.DURABLE));
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> connections = (List<Map<String, Object>>) hostDetails
+ .get(VIRTUALHOST_CONNECTIONS_ATTRIBUTE);
+ assertEquals("Unexpected number of connections", 1, connections.size());
+ Asserts.assertConnection(connections.get(0), _connection);
+ }
+
+ public void testPutCreateVirtualHostUsingStoreType() throws Exception
+ {
+ String hostName = getTestName();
+ String storeType = getTestProfileMessageStoreType();
+ String storeLocation = createHost(hostName, storeType, null);
+ try
+ {
+ // make sure that the host is saved in the broker store
+ restartBroker();
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostName);
+ Asserts.assertVirtualHost(hostName, hostDetails);
+ assertEquals("Unexpected store type", storeType, hostDetails.get(VirtualHost.STORE_TYPE));
+
+ assertNewVirtualHost(hostDetails);
+ }
+ finally
+ {
+ if (storeLocation != null)
+ {
+ FileUtils.delete(new File(storeLocation), true);
+ }
+ }
+ }
+
+ public void testPutCreateVirtualHostUsingConfigPath() throws Exception
+ {
+ String hostName = getTestName();
+ File configFile = TestFileUtils.createTempFile(this, hostName + "-config.xml");
+ String configPath = configFile.getAbsolutePath();
+ String storeLocation = getStoreLocation(hostName);
+ createAndSaveVirtualHostConfiguration(hostName, configFile, storeLocation);
+ createHost(hostName, null, configPath);
+ try
+ {
+ // make sure that the host is saved in the broker store
+ restartBroker();
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostName);
+ Asserts.assertVirtualHost(hostName, hostDetails);
+ assertEquals("Unexpected config path", configPath, hostDetails.get(VirtualHost.CONFIG_PATH));
+
+ assertNewVirtualHost(hostDetails);
+ }
+ finally
+ {
+ if (storeLocation != null)
+ {
+ FileUtils.delete(new File(storeLocation), true);
+ }
+ configFile.delete();
+ }
+ }
+
+ public void testDeleteHost() throws Exception
+ {
+ String hostToDelete = TEST3_VIRTUALHOST;
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/virtualhost/" + hostToDelete, "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+
+ // make sure that changes are saved in the broker store
+ restartBroker();
+
+ List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("/rest/virtualhost/" + hostToDelete);
+ assertEquals("Host should be deleted", 0, hosts.size());
+ }
+
+ public void testPutCreateQueue() throws Exception
+ {
+ String queueName = getTestQueueName();
+
+ createQueue(queueName + "-standard", "standard", null);
+
+ Map<String, Object> sortedQueueAttributes = new HashMap<String, Object>();
+ sortedQueueAttributes.put(Queue.SORT_KEY, "sortme");
+ createQueue(queueName + "-sorted", "sorted", sortedQueueAttributes);
+
+ Map<String, Object> priorityQueueAttributes = new HashMap<String, Object>();
+ priorityQueueAttributes.put(Queue.PRIORITIES, 10);
+ createQueue(queueName + "-priority", "priority", priorityQueueAttributes);
+
+ Map<String, Object> lvqQueueAttributes = new HashMap<String, Object>();
+ lvqQueueAttributes.put(Queue.LVQ_KEY, "LVQ");
+ createQueue(queueName + "-lvq", "lvq", lvqQueueAttributes);
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ Map<String, Object> standardQueue = getRestTestHelper().find(Queue.NAME, queueName + "-standard" , queues);
+ Map<String, Object> sortedQueue = getRestTestHelper().find(Queue.NAME, queueName + "-sorted" , queues);
+ Map<String, Object> priorityQueue = getRestTestHelper().find(Queue.NAME, queueName + "-priority" , queues);
+ Map<String, Object> lvqQueue = getRestTestHelper().find(Queue.NAME, queueName + "-lvq" , queues);
+
+ Asserts.assertQueue(queueName + "-standard", "standard", standardQueue);
+ Asserts.assertQueue(queueName + "-sorted", "sorted", sortedQueue);
+ Asserts.assertQueue(queueName + "-priority", "priority", priorityQueue);
+ Asserts.assertQueue(queueName + "-lvq", "lvq", lvqQueue);
+
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, standardQueue.get(Queue.DURABLE));
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, sortedQueue.get(Queue.DURABLE));
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, priorityQueue.get(Queue.DURABLE));
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, lvqQueue.get(Queue.DURABLE));
+
+ assertEquals("Unexpected sorted key attribute", "sortme", sortedQueue.get(Queue.SORT_KEY));
+ assertEquals("Unexpected lvq key attribute", "LVQ", lvqQueue.get(Queue.LVQ_KEY));
+ assertEquals("Unexpected priorities key attribute", 10, priorityQueue.get(Queue.PRIORITIES));
+ }
+
+ public void testPutCreateExchange() throws Exception
+ {
+ String exchangeName = getTestName();
+
+ createExchange(exchangeName + "-direct", "direct");
+ createExchange(exchangeName + "-topic", "topic");
+ createExchange(exchangeName + "-headers", "headers");
+ createExchange(exchangeName + "-fanout", "fanout");
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_EXCHANGES_ATTRIBUTE);
+ Map<String, Object> directExchange = getRestTestHelper().find(Queue.NAME, exchangeName + "-direct" , exchanges);
+ Map<String, Object> topicExchange = getRestTestHelper().find(Queue.NAME, exchangeName + "-topic" , exchanges);
+ Map<String, Object> headersExchange = getRestTestHelper().find(Queue.NAME, exchangeName + "-headers" , exchanges);
+ Map<String, Object> fanoutExchange = getRestTestHelper().find(Queue.NAME, exchangeName + "-fanout" , exchanges);
+
+ Asserts.assertDurableExchange(exchangeName + "-direct", "direct", directExchange);
+ Asserts.assertDurableExchange(exchangeName + "-topic", "topic", topicExchange);
+ Asserts.assertDurableExchange(exchangeName + "-headers", "headers", headersExchange);
+ Asserts.assertDurableExchange(exchangeName + "-fanout", "fanout", fanoutExchange);
+
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, directExchange.get(Queue.DURABLE));
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, topicExchange.get(Queue.DURABLE));
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, headersExchange.get(Queue.DURABLE));
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, fanoutExchange.get(Queue.DURABLE));
+
+ }
+
+ public void testPutCreateLVQWithoutKey() throws Exception
+ {
+ String queueName = getTestQueueName()+ "-lvq";
+ createQueue(queueName, "lvq", null);
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ Map<String, Object> lvqQueue = getRestTestHelper().find(Queue.NAME, queueName , queues);
+
+ Asserts.assertQueue(queueName , "lvq", lvqQueue);
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, lvqQueue.get(Queue.DURABLE));
+ assertEquals("Unexpected lvq key attribute", AMQQueueFactory.QPID_LVQ_KEY, lvqQueue.get(Queue.LVQ_KEY));
+ }
+
+ public void testPutCreateSortedQueueWithoutKey() throws Exception
+ {
+ String queueName = getTestQueueName() + "-sorted";
+ int responseCode = tryCreateQueue(queueName, "sorted", null);
+ assertEquals("Unexpected response code", HttpServletResponse.SC_CONFLICT, responseCode);
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ Map<String, Object> testQueue = getRestTestHelper().find(Queue.NAME, queueName , queues);
+
+ assertNull("Sorted queue without a key was created ", testQueue);
+ }
+
+ public void testPutCreatePriorityQueueWithoutKey() throws Exception
+ {
+ String queueName = getTestQueueName()+ "-priority";
+ createQueue(queueName, "priority", null);
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ Map<String, Object> priorityQueue = getRestTestHelper().find(Queue.NAME, queueName , queues);
+
+ Asserts.assertQueue(queueName , "priority", priorityQueue);
+ assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, priorityQueue.get(Queue.DURABLE));
+ assertEquals("Unexpected number of priorities", 10, priorityQueue.get(Queue.PRIORITIES));
+ }
+
+ public void testPutCreateStandardQueueWithoutType() throws Exception
+ {
+ String queueName = getTestQueueName();
+ createQueue(queueName, null, null);
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ Map<String, Object> queue = getRestTestHelper().find(Queue.NAME, queueName , queues);
+
+ Asserts.assertQueue(queueName , "standard", queue);
+ }
+
+ public void testPutCreateQueueOfUnsupportedType() throws Exception
+ {
+ String queueName = getTestQueueName();
+ int responseCode = tryCreateQueue(queueName, "unsupported", null);
+ assertEquals("Unexpected response code", HttpServletResponse.SC_CONFLICT, responseCode);
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ Map<String, Object> queue = getRestTestHelper().find(Queue.NAME, queueName , queues);
+
+ assertNull("Queue of unsupported type was created", queue);
+ }
+
+ public void testDeleteQueue() throws Exception
+ {
+ String queueName = getTestQueueName();
+ createQueue(queueName, null, null);
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/queue/test/" + queueName, "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+ List<Map<String, Object>> queues = getRestTestHelper().getJsonAsList("/rest/queue/test/" + queueName);
+ assertEquals("Queue should be deleted", 0, queues.size());
+ }
+
+ public void testDeleteQueueById() throws Exception
+ {
+ String queueName = getTestQueueName();
+ createQueue(queueName, null, null);
+ Map<String, Object> queueDetails = getRestTestHelper().getJsonAsSingletonList("/rest/queue/test/" + queueName);
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/queue/test?id=" + queueDetails.get(Queue.ID), "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+ List<Map<String, Object>> queues = getRestTestHelper().getJsonAsList("/rest/queue/test/" + queueName);
+ assertEquals("Queue should be deleted", 0, queues.size());
+ }
+
+ public void testDeleteExchange() throws Exception
+ {
+ String exchangeName = getTestName();
+ createExchange(exchangeName, "direct");
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/exchange/test/" + exchangeName, "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+ List<Map<String, Object>> queues = getRestTestHelper().getJsonAsList("/rest/exchange/test/" + exchangeName);
+ assertEquals("Exchange should be deleted", 0, queues.size());
+ }
+
+ public void testDeleteExchangeById() throws Exception
+ {
+ String exchangeName = getTestName();
+ createExchange(exchangeName, "direct");
+ Map<String, Object> echangeDetails = getRestTestHelper().getJsonAsSingletonList("/rest/exchange/test/" + exchangeName);
+
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/exchange/test?id=" + echangeDetails.get(Exchange.ID), "DELETE");
+ connection.connect();
+ assertEquals("Unexpected response code", 200, connection.getResponseCode());
+ List<Map<String, Object>> queues = getRestTestHelper().getJsonAsList("/rest/exchange/test/" + exchangeName);
+ assertEquals("Exchange should be deleted", 0, queues.size());
+ }
+
+ public void testPutCreateQueueWithAttributes() throws Exception
+ {
+ String queueName = getTestQueueName();
+
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Queue.ALERT_REPEAT_GAP, 1000);
+ attributes.put(Queue.ALERT_THRESHOLD_MESSAGE_AGE, 3600000);
+ attributes.put(Queue.ALERT_THRESHOLD_MESSAGE_SIZE, 1000000000);
+ attributes.put(Queue.ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, 800);
+ attributes.put(Queue.MAXIMUM_DELIVERY_ATTEMPTS, 15);
+ attributes.put(Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES, 2000000000);
+ attributes.put(Queue.QUEUE_FLOW_RESUME_SIZE_BYTES, 1500000000);
+
+ createQueue(queueName + "-standard", "standard", attributes);
+
+ Map<String, Object> sortedQueueAttributes = new HashMap<String, Object>();
+ sortedQueueAttributes.putAll(attributes);
+ sortedQueueAttributes.put(Queue.SORT_KEY, "sortme");
+ createQueue(queueName + "-sorted", "sorted", sortedQueueAttributes);
+
+ Map<String, Object> priorityQueueAttributes = new HashMap<String, Object>();
+ priorityQueueAttributes.putAll(attributes);
+ priorityQueueAttributes.put(Queue.PRIORITIES, 10);
+ createQueue(queueName + "-priority", "priority", priorityQueueAttributes);
+
+ Map<String, Object> lvqQueueAttributes = new HashMap<String, Object>();
+ lvqQueueAttributes.putAll(attributes);
+ lvqQueueAttributes.put(Queue.LVQ_KEY, "LVQ");
+ createQueue(queueName + "-lvq", "lvq", lvqQueueAttributes);
+
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ Map<String, Object> standardQueue = getRestTestHelper().find(Queue.NAME, queueName + "-standard" , queues);
+ Map<String, Object> sortedQueue = getRestTestHelper().find(Queue.NAME, queueName + "-sorted" , queues);
+ Map<String, Object> priorityQueue = getRestTestHelper().find(Queue.NAME, queueName + "-priority" , queues);
+ Map<String, Object> lvqQueue = getRestTestHelper().find(Queue.NAME, queueName + "-lvq" , queues);
+
+ attributes.put(Queue.DURABLE, Boolean.TRUE);
+ Asserts.assertQueue(queueName + "-standard", "standard", standardQueue, attributes);
+ Asserts.assertQueue(queueName + "-sorted", "sorted", sortedQueue, attributes);
+ Asserts.assertQueue(queueName + "-priority", "priority", priorityQueue, attributes);
+ Asserts.assertQueue(queueName + "-lvq", "lvq", lvqQueue, attributes);
+
+ assertEquals("Unexpected sorted key attribute", "sortme", sortedQueue.get(Queue.SORT_KEY));
+ assertEquals("Unexpected lvq key attribute", "LVQ", lvqQueue.get(Queue.LVQ_KEY));
+ assertEquals("Unexpected priorities key attribute", 10, priorityQueue.get(Queue.PRIORITIES));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testCreateQueueWithDLQEnabled() throws Exception
+ {
+ String queueName = getTestQueueName();
+
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(AMQQueueFactory.X_QPID_DLQ_ENABLED, true);
+
+ //verify the starting state
+ Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+ List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_EXCHANGES_ATTRIBUTE);
+
+ assertNull("queue should not have already been present", getRestTestHelper().find(Queue.NAME, queueName , queues));
+ assertNull("queue should not have already been present", getRestTestHelper().find(Queue.NAME, queueName + "_DLQ" , queues));
+ assertNull("exchange should not have already been present", getRestTestHelper().find(Exchange.NAME, queueName + "_DLE" , exchanges));
+
+ //create the queue
+ createQueue(queueName, "standard", attributes);
+
+ //verify the new queue, as well as the DLQueue and DLExchange have been created
+ hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/test");
+ queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+ exchanges = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_EXCHANGES_ATTRIBUTE);
+
+ Map<String, Object> queue = getRestTestHelper().find(Queue.NAME, queueName , queues);
+ Map<String, Object> dlqQueue = getRestTestHelper().find(Queue.NAME, queueName + "_DLQ" , queues);
+ Map<String, Object> dlExchange = getRestTestHelper().find(Exchange.NAME, queueName + "_DLE" , exchanges);
+ assertNotNull("queue should not have been present", queue);
+ assertNotNull("queue should not have been present", dlqQueue);
+ assertNotNull("exchange should not have been present", dlExchange);
+
+ //verify that the alternate exchange is set as expected on the new queue
+ Map<String, Object> queueAttributes = new HashMap<String, Object>();
+ queueAttributes.put(Queue.ALTERNATE_EXCHANGE, queueName + "_DLE");
+
+ Asserts.assertQueue(queueName, "standard", queue, queueAttributes);
+ Asserts.assertQueue(queueName, "standard", queue, null);
+ }
+
+ private void createExchange(String exchangeName, String exchangeType) throws IOException
+ {
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/exchange/test/" + exchangeName, "PUT");
+
+ Map<String, Object> queueData = new HashMap<String, Object>();
+ queueData.put(Exchange.NAME, exchangeName);
+ queueData.put(Exchange.DURABLE, Boolean.TRUE);
+ queueData.put(Exchange.TYPE, exchangeType);
+
+ getRestTestHelper().writeJsonRequest(connection, queueData);
+ assertEquals("Unexpected response code", 201, connection.getResponseCode());
+
+ connection.disconnect();
+ }
+
+ private void createQueue(String queueName, String queueType, Map<String, Object> attributes) throws IOException,
+ JsonGenerationException, JsonMappingException
+ {
+ int responseCode = tryCreateQueue(queueName, queueType, attributes);
+ assertEquals("Unexpected response code", 201, responseCode);
+ }
+
+ private int tryCreateQueue(String queueName, String queueType, Map<String, Object> attributes) throws IOException,
+ JsonGenerationException, JsonMappingException
+ {
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/queue/test/" + queueName, "PUT");
+
+ Map<String, Object> queueData = new HashMap<String, Object>();
+ queueData.put(Queue.NAME, queueName);
+ queueData.put(Queue.DURABLE, Boolean.TRUE);
+ if (queueType != null)
+ {
+ queueData.put(Queue.TYPE, queueType);
+ }
+ if (attributes != null)
+ {
+ queueData.putAll(attributes);
+ }
+
+ getRestTestHelper().writeJsonRequest(connection, queueData);
+ int responseCode = connection.getResponseCode();
+ connection.disconnect();
+ return responseCode;
+ }
+
+ private String createHost(String hostName, String storeType, String configPath) throws IOException, JsonGenerationException,
+ JsonMappingException
+ {
+ String storePath = getStoreLocation(hostName);
+ int responseCode = tryCreateVirtualHost(hostName, storeType, storePath, configPath);
+ assertEquals("Unexpected response code", 201, responseCode);
+ return storePath;
+ }
+
+ private String getStoreLocation(String hostName)
+ {
+ return new File(TMP_FOLDER, "store-" + hostName + "-" + System.currentTimeMillis()).getAbsolutePath();
+ }
+
+ private int tryCreateVirtualHost(String hostName, String storeType, String storePath, String configPath) throws IOException,
+ JsonGenerationException, JsonMappingException
+ {
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/virtualhost/" + hostName, "PUT");
+
+ Map<String, Object> hostData = new HashMap<String, Object>();
+ hostData.put(VirtualHost.NAME, hostName);
+ if (storeType == null)
+ {
+ hostData.put(VirtualHost.CONFIG_PATH, configPath);
+ }
+ else
+ {
+ hostData.put(VirtualHost.STORE_PATH, storePath);
+ hostData.put(VirtualHost.STORE_TYPE, storeType);
+ }
+
+ getRestTestHelper().writeJsonRequest(connection, hostData);
+ int responseCode = connection.getResponseCode();
+ connection.disconnect();
+ return responseCode;
+ }
+
+ private XMLConfiguration createAndSaveVirtualHostConfiguration(String hostName, File configFile, String storeLocation)
+ throws ConfigurationException
+ {
+ XMLConfiguration testConfiguration = new XMLConfiguration();
+ testConfiguration.setProperty("virtualhosts.virtualhost." + hostName + ".store.class",
+ getTestProfileMessageStoreClassName());
+ testConfiguration.setProperty("virtualhosts.virtualhost." + hostName + ".store.environment-path", storeLocation);
+ testConfiguration.save(configFile);
+ return testConfiguration;
+ }
+
+ private void assertNewVirtualHost(Map<String, Object> hostDetails)
+ {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> statistics = (Map<String, Object>) hostDetails.get(Asserts.STATISTICS_ATTRIBUTE);
+ assertEquals("Unexpected number of exchanges in statistics", EXPECTED_EXCHANGES.length,
+ statistics.get(VirtualHost.EXCHANGE_COUNT));
+ assertEquals("Unexpected number of queues in statistics", 0, statistics.get(VirtualHost.QUEUE_COUNT));
+ assertEquals("Unexpected number of connections in statistics", 0, statistics.get(VirtualHost.CONNECTION_COUNT));
+
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_EXCHANGES_ATTRIBUTE);
+ assertEquals("Unexpected number of exchanges", EXPECTED_EXCHANGES.length, exchanges.size());
+ RestTestHelper restTestHelper = getRestTestHelper();
+ Asserts.assertDurableExchange("amq.fanout", "fanout", restTestHelper.find(Exchange.NAME, "amq.fanout", exchanges));
+ Asserts.assertDurableExchange("amq.topic", "topic", restTestHelper.find(Exchange.NAME, "amq.topic", exchanges));
+ Asserts.assertDurableExchange("amq.direct", "direct", restTestHelper.find(Exchange.NAME, "amq.direct", exchanges));
+ Asserts.assertDurableExchange("amq.match", "headers", restTestHelper.find(Exchange.NAME, "amq.match", exchanges));
+ Asserts.assertDurableExchange("<<default>>", "direct", restTestHelper.find(Exchange.NAME, "<<default>>", exchanges));
+
+ assertNull("Unexpected queues", hostDetails.get(VIRTUALHOST_QUEUES_ATTRIBUTE));
+ assertNull("Unexpected connections", hostDetails.get(VIRTUALHOST_CONNECTIONS_ATTRIBUTE));
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java
new file mode 100644
index 0000000000..40ea723b1e
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java
@@ -0,0 +1,197 @@
+/*
+ *
+ * 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.systest.rest.acl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.security.acl.AbstractACLTestCase;
+import org.apache.qpid.systest.rest.QpidRestTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+
+public class GroupRestACLTest extends QpidRestTestCase
+{
+ private static final String FILE_GROUP_MANAGER = "FileGroupManager";
+
+ private static final String ALLOWED_GROUP = "allowedGroup";
+ private static final String DENIED_GROUP = "deniedGroup";
+ private static final String OTHER_GROUP = "otherGroup";
+
+ private static final String ALLOWED_USER = "webadmin";
+ private static final String DENIED_USER = "admin";
+ private static final String OTHER_USER = "admin";
+
+ private File _groupFile;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ _groupFile = createTemporaryGroupFile();
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath());
+
+ //DONT call super.setUp(), the tests will start the broker after configuring it
+ }
+
+ @Override
+ protected void customizeConfiguration() throws ConfigurationException, IOException
+ {
+ super.customizeConfiguration();
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (_groupFile != null)
+ {
+ if (_groupFile.exists())
+ {
+ _groupFile.delete();
+ }
+ }
+ }
+
+ private File createTemporaryGroupFile() throws Exception
+ {
+ File groupFile = File.createTempFile("group", "grp");
+ groupFile.deleteOnExit();
+
+ Properties props = new Properties();
+ props.put(ALLOWED_GROUP + ".users", ALLOWED_USER);
+ props.put(DENIED_GROUP + ".users", DENIED_USER);
+ props.put(OTHER_GROUP + ".users", OTHER_USER);
+
+ props.store(new FileOutputStream(groupFile), "test group file");
+
+ return groupFile;
+ }
+
+ public void testCreateGroup() throws Exception
+ {
+ AbstractACLTestCase.writeACLFileUtil(this, null,
+ "ACL ALLOW-LOG ALL ACCESS MANAGEMENT",
+ "ACL ALLOW-LOG " + ALLOWED_GROUP + " CREATE GROUP",
+ "ACL DENY-LOG " + DENIED_GROUP + " CREATE GROUP");
+
+ //Start the broker with the custom config
+ super.setUp();
+ getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
+
+ Map<String, Object> data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ getRestTestHelper().assertNumberOfGroups(data, 3);
+
+ getRestTestHelper().createGroup("newGroup", FILE_GROUP_MANAGER);
+
+ data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ getRestTestHelper().assertNumberOfGroups(data, 4);
+
+ getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
+
+ getRestTestHelper().createGroup("anotherNewGroup", FILE_GROUP_MANAGER, HttpServletResponse.SC_FORBIDDEN);
+
+ data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ getRestTestHelper().assertNumberOfGroups(data, 4);
+ }
+
+ public void testDeleteGroup() throws Exception
+ {
+ AbstractACLTestCase.writeACLFileUtil(this, null,
+ "ACL ALLOW-LOG ALL ACCESS MANAGEMENT",
+ "ACL ALLOW-LOG " + ALLOWED_GROUP + " DELETE GROUP",
+ "ACL DENY-LOG " + DENIED_GROUP + " DELETE GROUP");
+
+ //Start the broker with the custom config
+ super.setUp();
+ getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
+
+ Map<String, Object> data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ getRestTestHelper().assertNumberOfGroups(data, 3);
+
+ getRestTestHelper().removeGroup(OTHER_GROUP, FILE_GROUP_MANAGER, HttpServletResponse.SC_FORBIDDEN);
+
+ data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ getRestTestHelper().assertNumberOfGroups(data, 3);
+
+ getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
+
+ getRestTestHelper().removeGroup(OTHER_GROUP, FILE_GROUP_MANAGER);
+
+ data = getRestTestHelper().getJsonAsSingletonList("/rest/groupprovider/" + FILE_GROUP_MANAGER);
+ getRestTestHelper().assertNumberOfGroups(data, 2);
+ }
+
+ public void testUpdateGroupAddMember() throws Exception
+ {
+ AbstractACLTestCase.writeACLFileUtil(this, null,
+ "ACL ALLOW-LOG ALL ACCESS MANAGEMENT",
+ "ACL ALLOW-LOG " + ALLOWED_GROUP + " UPDATE GROUP",
+ "ACL DENY-LOG " + DENIED_GROUP + " UPDATE GROUP");
+
+ //Start the broker with the custom config
+ super.setUp();
+ getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
+
+ assertNumberOfGroupMembers(OTHER_GROUP, 1);
+
+ getRestTestHelper().createNewGroupMember(FILE_GROUP_MANAGER, OTHER_GROUP, "newGroupMember", HttpServletResponse.SC_FORBIDDEN);
+ assertNumberOfGroupMembers(OTHER_GROUP, 1);
+
+ getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
+ getRestTestHelper().createNewGroupMember(FILE_GROUP_MANAGER, OTHER_GROUP, "newGroupMember");
+ assertNumberOfGroupMembers(OTHER_GROUP, 2);
+ }
+
+ public void testUpdateGroupDeleteMember() throws Exception
+ {
+ AbstractACLTestCase.writeACLFileUtil(this, null,
+ "ACL ALLOW-LOG ALL ACCESS MANAGEMENT",
+ "ACL ALLOW-LOG " + ALLOWED_GROUP + " UPDATE GROUP",
+ "ACL DENY-LOG " + DENIED_GROUP + " UPDATE GROUP");
+
+ //Start the broker with the custom config
+ super.setUp();
+ getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
+
+ assertNumberOfGroupMembers(OTHER_GROUP, 1);
+
+ getRestTestHelper().removeMemberFromGroup(FILE_GROUP_MANAGER, OTHER_GROUP, OTHER_USER, HttpServletResponse.SC_FORBIDDEN);
+ assertNumberOfGroupMembers(OTHER_GROUP, 1);
+
+ getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
+ getRestTestHelper().removeMemberFromGroup(FILE_GROUP_MANAGER, OTHER_GROUP, OTHER_USER);
+ assertNumberOfGroupMembers(OTHER_GROUP, 0);
+ }
+
+ private void assertNumberOfGroupMembers(String groupName, int expectedNumberOfMembers) throws IOException
+ {
+ Map<String, Object> group = getRestTestHelper().getJsonAsSingletonList("/rest/group/FileGroupManager/" + groupName);
+ getRestTestHelper().assertNumberOfGroupMembers(group, expectedNumberOfMembers);
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java b/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java
new file mode 100644
index 0000000000..12973113d8
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java
@@ -0,0 +1,200 @@
+/*
+ * 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.systest.rest.acl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.security.acl.AbstractACLTestCase;
+import org.apache.qpid.systest.rest.QpidRestTestCase;
+import org.apache.qpid.test.utils.TestBrokerConfiguration;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+
+public class UserRestACLTest extends QpidRestTestCase
+{
+ private static final String ALLOWED_GROUP = "allowedGroup";
+ private static final String DENIED_GROUP = "deniedGroup";
+ private static final String OTHER_GROUP = "otherGroup";
+
+ private static final String ALLOWED_USER = "webadmin";
+ private static final String DENIED_USER = "admin";
+ private static final String OTHER_USER = "other";
+
+ private File _groupFile;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ _groupFile = createTemporaryGroupFile();
+ getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath());
+
+ getRestTestHelper().configureTemporaryPasswordFile(this, ALLOWED_USER, DENIED_USER, OTHER_USER);
+
+ //DONT call super.setUp(), the tests will start the broker after configuring it
+ }
+
+ @Override
+ protected void customizeConfiguration() throws ConfigurationException, IOException
+ {
+ super.customizeConfiguration();
+ getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ if (_groupFile != null)
+ {
+ if (_groupFile.exists())
+ {
+ _groupFile.delete();
+ }
+ }
+ }
+
+ private File createTemporaryGroupFile() throws Exception
+ {
+ File groupFile = File.createTempFile("group", "grp");
+ groupFile.deleteOnExit();
+
+ Properties props = new Properties();
+ props.put(ALLOWED_GROUP + ".users", ALLOWED_USER);
+ props.put(DENIED_GROUP + ".users", DENIED_USER);
+ props.put(OTHER_GROUP + ".users", OTHER_USER);
+
+ props.store(new FileOutputStream(groupFile), "test group file");
+
+ return groupFile;
+ }
+
+ public void testAddUser() throws Exception
+ {
+ AbstractACLTestCase.writeACLFileUtil(this, null,
+ "ACL ALLOW-LOG ALL ACCESS MANAGEMENT",
+ "ACL ALLOW-LOG " + ALLOWED_GROUP + " CREATE USER",
+ "ACL DENY-LOG " + DENIED_GROUP + " CREATE USER");
+
+ //Start the broker with the custom config
+ super.setUp();
+
+ String newUser = "newUser";
+ String password = "password";
+
+ assertUserDoesNotExist(newUser);
+
+ getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
+
+ getRestTestHelper().createOrUpdateUser(newUser, password, HttpServletResponse.SC_FORBIDDEN);
+ assertUserDoesNotExist(newUser);
+
+ getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
+ getRestTestHelper().createOrUpdateUser(newUser, password);
+ assertUserExists(newUser);
+ }
+
+ public void testDeleteUser() throws Exception
+ {
+ AbstractACLTestCase.writeACLFileUtil(this, null,
+ "ACL ALLOW-LOG ALL ACCESS MANAGEMENT",
+ "ACL ALLOW-LOG " + ALLOWED_GROUP + " DELETE USER",
+ "ACL DENY-LOG " + DENIED_GROUP + " DELETE USER");
+
+ //Start the broker with the custom config
+ super.setUp();
+
+ assertUserExists(OTHER_USER);
+
+ getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
+ getRestTestHelper().removeUser(OTHER_USER, HttpServletResponse.SC_FORBIDDEN);
+ assertUserExists(OTHER_USER);
+
+ getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
+ getRestTestHelper().removeUser(OTHER_USER);
+ assertUserDoesNotExist(OTHER_USER);
+ }
+
+ public void testUpdateUser() throws Exception
+ {
+ AbstractACLTestCase.writeACLFileUtil(this, null,
+ "ACL ALLOW-LOG ALL ACCESS MANAGEMENT",
+ "ACL ALLOW-LOG " + ALLOWED_GROUP + " UPDATE USER",
+ "ACL DENY-LOG " + DENIED_GROUP + " UPDATE USER");
+
+ //Start the broker with the custom config
+ super.setUp();
+
+ String newPassword = "newPassword";
+
+ checkPassword(OTHER_USER, OTHER_USER, true);
+
+ getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
+ getRestTestHelper().createOrUpdateUser(OTHER_USER, newPassword, HttpServletResponse.SC_FORBIDDEN);
+
+ checkPassword(OTHER_USER, newPassword, false);
+
+ getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
+ getRestTestHelper().createOrUpdateUser(OTHER_USER, newPassword, HttpServletResponse.SC_OK); // expect SC_OK rather than the default SC_CREATED
+
+ checkPassword(OTHER_USER, newPassword, true);
+ checkPassword(OTHER_USER, OTHER_USER, false);
+ }
+
+ private void checkPassword(String username, String password, boolean passwordExpectedToBeCorrect) throws IOException
+ {
+ getRestTestHelper().setUsernameAndPassword(username, password);
+ HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/user/"
+ + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/", "GET");
+
+ boolean passwordIsCorrect = connection.getResponseCode() == HttpServletResponse.SC_OK;
+
+ connection.disconnect();
+
+ assertEquals(passwordExpectedToBeCorrect, passwordIsCorrect);
+ }
+
+ private void assertUserDoesNotExist(String newUser) throws JsonParseException, JsonMappingException, IOException
+ {
+ String path = "/rest/user/" + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + newUser;
+ List<Map<String, Object>> userDetailsList = getRestTestHelper().getJsonAsList(path);
+ assertTrue(userDetailsList.isEmpty());
+ }
+
+ private void assertUserExists(String username) throws IOException
+ {
+ String path = "/rest/user/" + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username;
+ Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList(path);
+
+ assertEquals(
+ "User returned by " + path + " should have name=" + username + ". The returned JSON was: " + userDetails,
+ username,
+ userDetails.get("name"));
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/RollbackOrderTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/RollbackOrderTest.java
index a53c3d3ee0..2ed3f356d3 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/client/RollbackOrderTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/client/RollbackOrderTest.java
@@ -40,19 +40,19 @@ import java.util.concurrent.atomic.AtomicBoolean;
* Description:
*
* The problem that this test is exposing is that the dispatcher used to be capable
- * of holding on to a message when stopped. This ment that when the rollback was
+ * of holding on to a message when stopped. This meant that when the rollback was
* called and the dispatcher stopped it may have hold of a message. So after all
* the local queues(preDeliveryQueue, SynchronousQueue, PostDeliveryTagQueue)
* have been cleared the client still had a single message, the one the
* dispatcher was holding on to.
*
* As a result the TxRollback operation would run and then release the dispatcher.
- * Whilst the dispatcher would then proceed to reject the message it was holiding
+ * Whilst the dispatcher would then proceed to reject the message it was holding
* the Broker would already have resent that message so the rejection would silently
* fail.
*
- * And the client would receieve that single message 'early', depending on the
- * number of messages already recevied when rollback was called.
+ * And the client would receive that single message 'early', depending on the
+ * number of messages already received when rollback was called.
*
*
* Aims:
@@ -78,7 +78,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* as expected.
*
* We are testing a race condition here but we can check through the log file if
- * the race condition occured. However, performing that check will only validate
+ * the race condition occurred. However, performing that check will only validate
* the problem exists and will not be suitable as part of a system test.
*
*/
@@ -183,18 +183,8 @@ public class RollbackOrderTest extends QpidBrokerTestCase
}
}
-// _consumer.close();
_connection.close();
assertFalse("Exceptions thrown during test run, Check Std.err.", failed.get());
}
-
- @Override public void tearDown() throws Exception
- {
-
- drainQueue(_queue);
-
- super.tearDown();
- }
-
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java
index e1f93b975b..22a98b6f42 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java
@@ -29,8 +29,6 @@ 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.message.QpidMessageProperties;
-import org.apache.qpid.client.messaging.address.Node.ExchangeNode;
-import org.apache.qpid.client.messaging.address.Node.QueueNode;
import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
import org.apache.qpid.messaging.Address;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
@@ -98,7 +96,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
}
assertFalse("Queue should not be created",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest, (QueueNode)dest.getSourceNode() ,true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest,false));
// create always -------------------------------------------
@@ -107,10 +105,10 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
cons = jmsSession.createConsumer(dest);
assertTrue("Queue not created as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, true));
assertTrue("Queue not bound as expected",(
(AMQSession_0_10)jmsSession).isQueueBound("",
- dest.getAddressName(),dest.getAddressName(), dest.getSourceNode().getDeclareArgs()));
+ dest.getAddressName(),dest.getAddressName(), dest.getNode().getDeclareArgs()));
// create receiver -----------------------------------------
addr1 = "ADDR:testQueue2; { create: receiver }";
@@ -126,16 +124,16 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
}
assertFalse("Queue should not be created",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, false));
cons = jmsSession.createConsumer(dest);
assertTrue("Queue not created as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, true));
assertTrue("Queue not bound as expected",(
(AMQSession_0_10)jmsSession).isQueueBound("",
- dest.getAddressName(),dest.getAddressName(), dest.getSourceNode().getDeclareArgs()));
+ dest.getAddressName(),dest.getAddressName(), dest.getNode().getDeclareArgs()));
// create never --------------------------------------------
addr1 = "ADDR:testQueue3; { create: never }";
@@ -161,7 +159,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
}
assertFalse("Queue should not be created",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, false));
// create sender ------------------------------------------
addr1 = "ADDR:testQueue3; { create: sender }";
@@ -177,14 +175,14 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
"doesn't resolve to an exchange or a queue"));
}
assertFalse("Queue should not be created",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, false));
prod = jmsSession.createProducer(dest);
assertTrue("Queue not created as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, true));
assertTrue("Queue not bound as expected",(
(AMQSession_0_10)jmsSession).isQueueBound("",
- dest.getAddressName(),dest.getAddressName(), dest.getSourceNode().getDeclareArgs()));
+ dest.getAddressName(),dest.getAddressName(), dest.getNode().getDeclareArgs()));
}
@@ -221,7 +219,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
// Even if the consumer is closed the queue and the bindings should be intact.
assertTrue("Queue not created as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, true));
assertTrue("Queue not bound as expected",(
(AMQSession_0_10)jmsSession).isQueueBound("",
@@ -326,7 +324,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
}
assertTrue("Exchange not created as expected",(
- (AMQSession_0_10)jmsSession).isExchangeExist(dest, (ExchangeNode)dest.getTargetNode() , true));
+ (AMQSession_0_10)jmsSession).isExchangeExist(dest,true));
// The existence of the queue is implicitly tested here
assertTrue("Queue not bound as expected",(
@@ -367,7 +365,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
public void checkQueueForBindings(Session jmsSession, AMQDestination dest,String headersBinding) throws Exception
{
assertTrue("Queue not created as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, true));
assertTrue("Queue not bound as expected",(
(AMQSession_0_10)jmsSession).isQueueBound("",
@@ -506,14 +504,14 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
MessageConsumer cons3 = jmsSession.createConsumer(dest3);
assertTrue("Destination1 was not created as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest1,(QueueNode)dest1.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest1, true));
assertTrue("Destination1 was not bound as expected",(
(AMQSession_0_10)jmsSession).isQueueBound("",
dest1.getAddressName(),dest1.getAddressName(), null));
assertTrue("Destination2 was not created as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest2,(QueueNode)dest2.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest2,true));
assertTrue("Destination2 was not bound as expected",(
(AMQSession_0_10)jmsSession).isQueueBound("",
@@ -602,14 +600,14 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
cons.close();
// Using the ADDR method to create a more complicated queue
- String addr = "ADDR:amq.direct/x512; {create: receiver, " +
+ String addr = "ADDR:amq.direct/x512; {" +
"link : {name : 'MY.RESP.QUEUE', " +
"x-declare : { auto-delete: true, exclusive: true, " +
"arguments : {'qpid.max_size': 1000, 'qpid.policy_type': ring} } } }";
queue = ssn.createQueue(addr);
- prod = ssn.createProducer(queue);
cons = ssn.createConsumer(queue);
+ prod = ssn.createProducer(queue);
assertTrue("MY.RESP.QUEUE was not created as expected",(
(AMQSession_0_10)ssn).isQueueBound("amq.direct",
"MY.RESP.QUEUE","x512", null));
@@ -677,8 +675,8 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
// Using the ADDR method to create a more complicated topic
topic = ssn.createTopic(addr);
- prod = ssn.createProducer(topic);
cons = ssn.createConsumer(topic);
+ prod = ssn.createProducer(topic);
assertTrue("The queue was not bound to vehicle exchange using bus as the binding key",(
(AMQSession_0_10)ssn).isQueueBound("vehicles",
@@ -778,7 +776,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
public void testSubscriptionForSameDestination() throws Exception
{
Session ssn = _connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
- Destination dest = ssn.createTopic("ADDR:amq.topic/foo; {link:{durable:true}}");
+ Destination dest = ssn.createTopic("ADDR:amq.topic/foo");
MessageConsumer consumer1 = ssn.createConsumer(dest);
MessageConsumer consumer2 = ssn.createConsumer(dest);
MessageProducer prod = ssn.createProducer(dest);
@@ -840,7 +838,8 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
"}";
// Using the ADDR method to create a more complicated topic
- MessageConsumer cons = ssn.createConsumer(new AMQAnyDestination(addr));
+ Topic topic = ssn.createTopic(addr);
+ MessageConsumer cons = ssn.createConsumer(topic);
assertTrue("The queue was not bound to MRKT exchange using NYSE.# as the binding key",(
(AMQSession_0_10)ssn).isQueueBound("MRKT",
@@ -854,7 +853,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
(AMQSession_0_10)ssn).isQueueBound("MRKT",
"my-topic","CNTL.#", null));
- MessageProducer prod = ssn.createProducer(ssn.createTopic(addr));
+ MessageProducer prod = ssn.createProducer(topic);
Message msg = ssn.createTextMessage("test");
msg.setStringProperty("qpid.subject", "NASDAQ.ABCD");
prod.send(msg);
@@ -909,32 +908,31 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
{
Session ssn = _connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
+ String bindingStr = "x-bindings:[{key:'NYSE.#'},{key:'NASDAQ.#'},{key:'CNTL.#'}]}}";
+
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory");
- props.setProperty("destination.address1", "ADDR:amq.topic");
- props.setProperty("destination.address2", "ADDR:amq.direct/test");
- String addrStr = "ADDR:amq.topic/test; {link:{name: my-topic," +
- "x-bindings:[{key:'NYSE.#'},{key:'NASDAQ.#'},{key:'CNTL.#'}]}}";
- props.setProperty("destination.address3", addrStr);
- props.setProperty("topic.address4", "hello.world");
- addrStr = "ADDR:my_queue; {create:always,link: {x-subscribes:{exclusive: true, arguments: {a:b,x:y}}}}";
+ props.setProperty("destination.address1", "ADDR:amq.topic/test");
+ props.setProperty("destination.address2", "ADDR:amq.topic/test; {node:{" + bindingStr);
+ props.setProperty("destination.address3", "ADDR:amq.topic/test; {link:{" + bindingStr);
+ String addrStr = "ADDR:my_queue; {create:always,link: {x-subscribes:{exclusive: true, arguments: {a:b,x:y}}}}";
props.setProperty("destination.address5", addrStr);
Context ctx = new InitialContext(props);
- for (int i=1; i < 5; i++)
+ for (int i=1; i < 4; i++)
{
Topic topic = (Topic) ctx.lookup("address"+i);
- createDurableSubscriber(ctx,ssn,"address"+i,topic);
+ createDurableSubscriber(ctx,ssn,"address"+i,topic,"ADDR:amq.topic/test");
}
Topic topic = ssn.createTopic("ADDR:news.us");
- createDurableSubscriber(ctx,ssn,"my-dest",topic);
+ createDurableSubscriber(ctx,ssn,"my-dest",topic,"ADDR:news.us");
Topic namedQueue = (Topic) ctx.lookup("address5");
try
{
- createDurableSubscriber(ctx,ssn,"my-queue",namedQueue);
+ createDurableSubscriber(ctx,ssn,"my-queue",namedQueue,"ADDR:amq.topic/test");
fail("Exception should be thrown. Durable subscribers cannot be created for Queues");
}
catch(JMSException e)
@@ -943,16 +941,74 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
e.getMessage());
}
}
-
- private void createDurableSubscriber(Context ctx,Session ssn,String destName,Topic topic) throws Exception
+
+ public void testDurableSubscription() throws Exception
+ {
+ Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = session.createTopic("ADDR:amq.topic/" + getTestQueueName());
+ MessageProducer publisher = session.createProducer(topic);
+ MessageConsumer subscriber = session.createDurableSubscriber(topic, getTestQueueName());
+
+ TextMessage messageToSend = session.createTextMessage("Test0");
+ publisher.send(messageToSend);
+ ((AMQSession<?,?>)session).sync();
+
+ Message receivedMessage = subscriber.receive(1000);
+ assertNotNull("Message has not been received", receivedMessage);
+ assertEquals("Unexpected message", messageToSend.getText(), ((TextMessage)receivedMessage).getText());
+
+ subscriber.close();
+
+ messageToSend = session.createTextMessage("Test1");
+ publisher.send(messageToSend);
+ ((AMQSession<?,?>)session).sync();
+
+ subscriber = session.createDurableSubscriber(topic, getTestQueueName());
+ receivedMessage = subscriber.receive(1000);
+ assertNotNull("Message has not been received", receivedMessage);
+ assertEquals("Unexpected message", messageToSend.getText(), ((TextMessage)receivedMessage).getText());
+ }
+
+ public void testDurableSubscriptionnWithSelector() throws Exception
+ {
+ Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic topic = session.createTopic("ADDR:amq.topic/" + getTestQueueName());
+ MessageProducer publisher = session.createProducer(topic);
+ MessageConsumer subscriber = session.createDurableSubscriber(topic, getTestQueueName(), "id=1", false);
+
+ TextMessage messageToSend = session.createTextMessage("Test0");
+ messageToSend.setIntProperty("id", 1);
+ publisher.send(messageToSend);
+ ((AMQSession<?,?>)session).sync();
+
+ Message receivedMessage = subscriber.receive(1000);
+ assertNotNull("Message has not been received", receivedMessage);
+ assertEquals("Unexpected message", messageToSend.getText(), ((TextMessage)receivedMessage).getText());
+ assertEquals("Unexpected id", 1, receivedMessage.getIntProperty("id"));
+
+ subscriber.close();
+
+ messageToSend = session.createTextMessage("Test1");
+ messageToSend.setIntProperty("id", 1);
+ publisher.send(messageToSend);
+ ((AMQSession<?,?>)session).sync();
+
+ subscriber = session.createDurableSubscriber(topic, getTestQueueName(), "id=1", false);
+ receivedMessage = subscriber.receive(1000);
+ assertNotNull("Message has not been received", receivedMessage);
+ assertEquals("Unexpected message", messageToSend.getText(), ((TextMessage)receivedMessage).getText());
+ assertEquals("Unexpected id", 1, receivedMessage.getIntProperty("id"));
+ }
+
+ private void createDurableSubscriber(Context ctx,Session ssn,String destName,Topic topic, String producerAddr) throws Exception
{
MessageConsumer cons = ssn.createDurableSubscriber(topic, destName);
- MessageProducer prod = ssn.createProducer(topic);
+ MessageProducer prod = ssn.createProducer(ssn.createTopic(producerAddr));
Message m = ssn.createTextMessage(destName);
prod.send(m);
Message msg = cons.receive(1000);
- assertNotNull(msg);
+ assertNotNull("Message not received as expected when using Topic : " + topic,msg);
assertEquals(destName,((TextMessage)msg).getText());
ssn.unsubscribe(destName);
}
@@ -977,7 +1033,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
}
assertFalse("Queue not deleted as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, false));
String addr2 = "ADDR:testQueue2;{create: always, delete: receiver}";
@@ -993,7 +1049,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
}
assertFalse("Queue not deleted as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, false));
String addr3 = "ADDR:testQueue3;{create: always, delete: sender}";
@@ -1010,9 +1066,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
}
assertFalse("Queue not deleted as expected",(
- (AMQSession_0_10)jmsSession).isQueueExist(dest,(QueueNode)dest.getSourceNode(), true));
-
-
+ (AMQSession_0_10)jmsSession).isQueueExist(dest, false));
}
/**
@@ -1094,7 +1148,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
MessageConsumer cons = ssn.createConsumer(ssn.createTopic("ADDR:amq.topic/test"));
MessageProducer prod = ssn.createProducer(null);
- Queue queue = ssn.createQueue("ADDR:amq.topic/test");
+ Topic queue = ssn.createTopic("ADDR:amq.topic/test");
prod.send(queue,ssn.createTextMessage("A"));
Message msg = cons.receive(1000);
@@ -1307,4 +1361,62 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase
assertNotNull("message should be re-received by consumer after rollback", receivedMessage);
jmsSession.commit();
}
+
+ /**
+ * Test Goals :
+ *
+ * 1. Verify that link bindings are created and destroyed after creating and closing a subscriber.
+ * 2. Verify that link bindings are created and destroyed after creating and closing a subscriber.
+ */
+ public void testLinkBindingBehavior() throws Exception
+ {
+ Session jmsSession = _connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
+ String addr = "ADDR:my-queue; {create: always, " +
+ "link: " +
+ "{" +
+ "x-bindings: [{exchange : 'amq.direct', key : test}]," +
+ "}" +
+ "}";
+
+ AMQDestination dest = (AMQDestination)jmsSession.createQueue(addr);
+ MessageConsumer cons = jmsSession.createConsumer(dest);
+ AMQSession_0_10 ssn = (AMQSession_0_10)jmsSession;
+
+ assertTrue("Queue not created as expected",ssn.isQueueExist(dest, true));
+ assertTrue("Queue not bound as expected",ssn.isQueueBound("amq.direct","my-queue","test", null));
+
+ cons.close(); // closing consumer, link binding should be removed now.
+ assertTrue("Queue should still be there",ssn.isQueueExist(dest, true));
+ assertFalse("Binding should not exist anymore",ssn.isQueueBound("amq.direct","my-queue","test", null));
+
+ MessageProducer prod = jmsSession.createProducer(dest);
+ assertTrue("Queue not bound as expected",ssn.isQueueBound("amq.direct","my-queue","test", null));
+ prod.close();
+ assertFalse("Binding should not exist anymore",ssn.isQueueBound("amq.direct","my-queue","test", null));
+ }
+
+ /**
+ * Test Goals : Verifies that the subscription queue created is as specified under link properties.
+ */
+ public void testCustomizingSubscriptionQueue() throws Exception
+ {
+ Session ssn = _connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
+ String xDeclareArgs = "x-declare: { exclusive: false, auto-delete: false," +
+ "alternate-exchange: 'amq.fanout'," +
+ "arguments: {'qpid.max_size': 1000,'qpid.max_count': 100}" +
+ "}";
+
+ String addr = "ADDR:amq.topic/test; {link: {name:my-queue, durable:true," + xDeclareArgs + "}}";
+ Destination dest = ssn.createTopic(addr);
+ MessageConsumer cons = ssn.createConsumer(dest);
+
+ String verifyAddr = "ADDR:my-queue;{ node: {durable:true, " + xDeclareArgs + "}}";
+ AMQDestination verifyDest = (AMQDestination)ssn.createQueue(verifyAddr);
+ ((AMQSession_0_10)ssn).isQueueExist(verifyDest, true);
+
+ // Verify that the producer does not delete the subscription queue.
+ MessageProducer prod = ssn.createProducer(dest);
+ prod.close();
+ ((AMQSession_0_10)ssn).isQueueExist(verifyDest, true);
+ }
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
index b82c3756f2..2875e2c6b1 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
@@ -24,6 +24,7 @@ package org.apache.qpid.test.client.failover;
import org.apache.log4j.Logger;
import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQSession;
import org.apache.qpid.jms.ConnectionListener;
import org.apache.qpid.test.utils.FailoverBaseCase;
@@ -35,7 +36,6 @@ import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.NamingException;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -75,7 +75,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
failoverComplete = new CountDownLatch(1);
}
- protected void init(boolean transacted, int mode) throws JMSException, NamingException
+ private void init(boolean transacted, int mode) throws Exception
{
consumerSession = connection.createSession(transacted, mode);
queue = consumerSession.createQueue(getName()+System.currentTimeMillis());
@@ -125,7 +125,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
}
}
- private void sendMessages(int startIndex,int endIndex, boolean transacted) throws JMSException
+ private void sendMessages(int startIndex,int endIndex, boolean transacted) throws Exception
{
_logger.debug("**************** Send (Start: " + startIndex + ", End:" + endIndex + ")***********************");
@@ -144,6 +144,10 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
{
producerSession.commit();
}
+ else
+ {
+ ((AMQSession<?, ?>)producerSession).sync();
+ }
}
public void testP2PFailover() throws Exception
@@ -163,13 +167,13 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
{
if (CLUSTERED)
{
- testP2PFailover(numMessages, false,true, false);
+ testP2PFailover(numMessages, false, true, false);
}
}
public void testP2PFailoverTransacted() throws Exception
{
- testP2PFailover(numMessages, true,true, false);
+ testP2PFailover(numMessages, true,true, true);
}
public void testP2PFailoverTransactedWithMessagesLeftToConsumeAndProduce() throws Exception
@@ -177,17 +181,16 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
// Currently the cluster does not support transactions that span a failover
if (CLUSTERED)
{
- testP2PFailover(numMessages, false,false, false);
+ testP2PFailover(numMessages, false, false, false);
}
}
-
- private void testP2PFailover(int totalMessages, boolean consumeAll, boolean produceAll , boolean transacted) throws JMSException, NamingException
+ private void testP2PFailover(int totalMessages, boolean consumeAll, boolean produceAll , boolean transacted) throws Exception
{
init(transacted, Session.AUTO_ACKNOWLEDGE);
runP2PFailover(totalMessages,consumeAll, produceAll , transacted);
}
-
- protected void runP2PFailover(int totalMessages, boolean consumeAll, boolean produceAll , boolean transacted) throws JMSException, NamingException
+
+ private void runP2PFailover(int totalMessages, boolean consumeAll, boolean produceAll , boolean transacted) throws Exception
{
int toProduce = totalMessages;
@@ -254,7 +257,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
//evil ignore IE.
}
}
-
+
public void testClientAckFailover() throws Exception
{
init(false, Session.CLIENT_ACKNOWLEDGE);
diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java
index 5b350d2d89..3cc15d5e9d 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java
@@ -63,8 +63,7 @@ public class JMSDestinationTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
- //Ensure JMX management is enabled for MovedToQueue test
- setConfigurationProperty("management.enabled", "true");
+ getBrokerConfiguration().addJmxManagementConfiguration();
super.setUp();
diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
index ee81e7c372..9bf7dbd62a 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
@@ -54,11 +54,9 @@ public class SyncWaitDelayTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.class", "org.apache.qpid.server.store.SlowMessageStore");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.delays.commitTran.post", String.valueOf(POST_COMMIT_DELAY));
- setConfigurationProperty("management.enabled", "false");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.class", "org.apache.qpid.server.store.SlowMessageStore");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.delays.commitTran.post", String.valueOf(POST_COMMIT_DELAY));
-
super.setUp();
//Set the syncWrite timeout to be just larger than the delay on the commitTran.
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java
index 53f37cd915..8961574d1e 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/unit/basic/InvalidDestinationTest.java
@@ -21,16 +21,23 @@
package org.apache.qpid.test.unit.basic;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
+import java.util.Collections;
+import java.util.Map;
+import javax.jms.Connection;
import javax.jms.InvalidDestinationException;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
+import javax.jms.Topic;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.configuration.ClientProperties;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
public class InvalidDestinationTest extends QpidBrokerTestCase
{
@@ -48,21 +55,23 @@ public class InvalidDestinationTest extends QpidBrokerTestCase
super.tearDown();
}
-
-
public void testInvalidDestination() throws Exception
{
- Queue invalidDestination = new AMQQueue("amq.direct","unknownQ");
- AMQQueue validDestination = new AMQQueue("amq.direct","knownQ");
QueueSession queueSession = _connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ Queue invalidDestination = queueSession.createQueue("unknownQ");
+
+ Queue validDestination = queueSession.createQueue(getTestQueueName());
+
// This is the only easy way to create and bind a queue from the API :-(
queueSession.createConsumer(validDestination);
+ QueueSender sender;
+ TextMessage msg= queueSession.createTextMessage("Hello");
- QueueSender sender = queueSession.createSender(invalidDestination);
- TextMessage msg = queueSession.createTextMessage("Hello");
try
{
+ sender = queueSession.createSender(invalidDestination);
+
sender.send(msg);
fail("Expected InvalidDestinationException");
}
@@ -70,10 +79,8 @@ public class InvalidDestinationTest extends QpidBrokerTestCase
{
// pass
}
- sender.close();
sender = queueSession.createSender(null);
- invalidDestination = new AMQQueue("amq.direct","unknownQ");
try
{
@@ -86,19 +93,79 @@ public class InvalidDestinationTest extends QpidBrokerTestCase
}
sender.send(validDestination,msg);
sender.close();
- validDestination = new AMQQueue("amq.direct","knownQ");
sender = queueSession.createSender(validDestination);
sender.send(msg);
+ }
+ /**
+ * Tests that specifying the {@value ClientProperties#VERIFY_QUEUE_ON_SEND} system property
+ * results in an exception when sending to an invalid queue destination.
+ */
+ public void testInvalidDestinationOnMessageProducer() throws Exception
+ {
+ setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "true");
+ final AMQConnection connection = (AMQConnection) getConnection();
+ doInvalidDestinationOnMessageProducer(connection);
+ }
+ /**
+ * Tests that specifying the {@value ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND}
+ * connection URL option property results in an exception when sending to an
+ * invalid queue destination.
+ */
+ public void testInvalidDestinationOnMessageProducerURL() throws Exception
+ {
+ Map<String, String> options = Collections.singletonMap(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND, "true");
+ doInvalidDestinationOnMessageProducer(getConnectionWithOptions(options));
+ }
+ private void doInvalidDestinationOnMessageProducer(Connection connection) throws JMSException
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- }
+ String invalidQueueName = getTestQueueName() + "UnknownQ";
+ Queue invalidDestination = session.createQueue(invalidQueueName);
+ String validQueueName = getTestQueueName() + "KnownQ";
+ Queue validDestination = session.createQueue(validQueueName);
- public static junit.framework.Test suite()
- {
+ // This is the only easy way to create and bind a queue from the API :-(
+ session.createConsumer(validDestination);
+
+ MessageProducer sender;
+ TextMessage msg = session.createTextMessage("Hello");
+ try
+ {
+ sender = session.createProducer(invalidDestination);
+ sender.send(msg);
+ fail("Expected InvalidDestinationException");
+ }
+ catch (InvalidDestinationException ex)
+ {
+ // pass
+ }
- return new junit.framework.TestSuite(InvalidDestinationTest.class);
+ sender = session.createProducer(null);
+ invalidDestination = new AMQQueue("amq.direct",invalidQueueName);
+
+ try
+ {
+ sender.send(invalidDestination,msg);
+ fail("Expected InvalidDestinationException");
+ }
+ catch (InvalidDestinationException ex)
+ {
+ // pass
+ }
+ sender.send(validDestination, msg);
+ sender.close();
+ sender = session.createProducer(validDestination);
+ sender.send(msg);
+
+ //Verify sending to an 'invalid' Topic doesn't throw an exception
+ String invalidTopic = getTestQueueName() + "UnknownT";
+ Topic topic = session.createTopic(invalidTopic);
+ sender = session.createProducer(topic);
+ sender.send(msg);
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
index 8577fb5b6a..4e9477f4b6 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/unit/client/DynamicQueueExchangeCreateTest.java
@@ -20,26 +20,59 @@
*/
package org.apache.qpid.test.unit.client;
+import java.io.IOException;
+
import org.apache.qpid.AMQException;
+import org.apache.qpid.configuration.ClientProperties;
+import org.apache.qpid.management.common.mbeans.ManagedExchange;
import org.apache.qpid.protocol.AMQConstant;
+import org.apache.qpid.test.utils.JMXTestUtils;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.apache.qpid.url.BindingURL;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Session;
-/**
- * QPID-155
- *
- * Test to validate that setting the respective qpid.declare_queues,
- * qpid.declare_exchanges system properties functions as expected.
- */
public class DynamicQueueExchangeCreateTest extends QpidBrokerTestCase
{
- public void testQueueDeclare() throws Exception
+ private JMXTestUtils _jmxUtils;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ _jmxUtils = new JMXTestUtils(this);
+ _jmxUtils.setUp();
+
+ super.setUp();
+ _jmxUtils.open();
+ }
+
+ @Override
+ public void tearDown() throws Exception
{
- setSystemProperty("qpid.declare_queues", "false");
+ try
+ {
+ if (_jmxUtils != null)
+ {
+ _jmxUtils.close();
+ }
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ /*
+ * Tests to validate that setting the respective qpid.declare_queues,
+ * qpid.declare_exchanges system properties functions as expected.
+ */
+
+ public void testQueueNotDeclaredDuringConsumerCreation() throws Exception
+ {
+ setSystemProperty(ClientProperties.QPID_DECLARE_QUEUES_PROP_NAME, "false");
Connection connection = getConnection();
@@ -58,16 +91,16 @@ public class DynamicQueueExchangeCreateTest extends QpidBrokerTestCase
}
}
- public void testExchangeDeclare() throws Exception
+ public void testExchangeNotDeclaredDuringConsumerCreation() throws Exception
{
- setSystemProperty("qpid.declare_exchanges", "false");
+ setSystemProperty(ClientProperties.QPID_DECLARE_EXCHANGES_PROP_NAME, "false");
Connection connection = getConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- String EXCHANGE_TYPE = "test.direct";
- Queue queue = session.createQueue("direct://" + EXCHANGE_TYPE + "/queue/queue");
+ String exchangeName = getTestQueueName();
+ Queue queue = session.createQueue("direct://" + exchangeName + "/queue/queue");
try
{
@@ -78,6 +111,50 @@ public class DynamicQueueExchangeCreateTest extends QpidBrokerTestCase
{
checkExceptionErrorCode(e, AMQConstant.NOT_FOUND);
}
+
+ //verify the exchange was not declared
+ String exchangeObjectName = _jmxUtils.getExchangeObjectName("test", exchangeName);
+ assertFalse("exchange should not exist", _jmxUtils.doesManagedObjectExist(exchangeObjectName));
+ }
+
+ /**
+ * Checks that setting {@value ClientProperties#QPID_DECLARE_EXCHANGES_PROP_NAME} false results in
+ * disabling implicit ExchangeDeclares during producer creation when using a {@link BindingURL}
+ */
+ public void testExchangeNotDeclaredDuringProducerCreation() throws Exception
+ {
+ Connection connection = getConnection();
+ Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ String exchangeName1 = getTestQueueName() + "1";
+
+
+ Queue queue = session1.createQueue("direct://" + exchangeName1 + "/queue/queue");
+ session1.createProducer(queue);
+
+ //close the session to ensure any previous commands were fully processed by
+ //the broker before observing their effect
+ session1.close();
+
+ //verify the exchange was declared
+ String exchangeObjectName = _jmxUtils.getExchangeObjectName("test", exchangeName1);
+ assertTrue("exchange should exist", _jmxUtils.doesManagedObjectExist(exchangeObjectName));
+
+ //Now disable the implicit exchange declares and try again
+ setSystemProperty(ClientProperties.QPID_DECLARE_EXCHANGES_PROP_NAME, "false");
+
+ Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ String exchangeName2 = getTestQueueName() + "2";
+
+ Queue queue2 = session2.createQueue("direct://" + exchangeName2 + "/queue/queue");
+ session2.createProducer(queue2);
+
+ //close the session to ensure any previous commands were fully processed by
+ //the broker before observing their effect
+ session2.close();
+
+ //verify the exchange was not declared
+ String exchangeObjectName2 = _jmxUtils.getExchangeObjectName("test", exchangeName2);
+ assertFalse("exchange should not exist", _jmxUtils.doesManagedObjectExist(exchangeObjectName2));
}
private void checkExceptionErrorCode(JMSException original, AMQConstant code)
@@ -87,4 +164,71 @@ public class DynamicQueueExchangeCreateTest extends QpidBrokerTestCase
assertTrue("Linked exception should be an AMQException", linked instanceof AMQException);
assertEquals("Error code should be " + code.getCode(), code, ((AMQException) linked).getErrorCode());
}
+
+ /*
+ * Tests to validate that the custom exchanges declared by the client during
+ * consumer and producer creation have the expected properties.
+ */
+
+ public void testPropertiesOfCustomExchangeDeclaredDuringProducerCreation() throws Exception
+ {
+ implTestPropertiesOfCustomExchange(true, false);
+ }
+
+ public void testPropertiesOfCustomExchangeDeclaredDuringConsumerCreation() throws Exception
+ {
+ implTestPropertiesOfCustomExchange(false, true);
+ }
+
+ private void implTestPropertiesOfCustomExchange(boolean createProducer, boolean createConsumer) throws Exception
+ {
+ Connection connection = getConnection();
+
+ Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ String exchangeName1 = getTestQueueName() + "1";
+ String queueName1 = getTestQueueName() + "1";
+
+ Queue queue = session1.createQueue("direct://" + exchangeName1 + "/" + queueName1 + "/" + queueName1 + "?" + BindingURL.OPTION_EXCHANGE_AUTODELETE + "='true'");
+ if(createProducer)
+ {
+ session1.createProducer(queue);
+ }
+
+ if(createConsumer)
+ {
+ session1.createConsumer(queue);
+ }
+ session1.close();
+
+ //verify the exchange was declared to expectation
+ verifyDeclaredExchange(exchangeName1, true, false);
+
+ Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ String exchangeName2 = getTestQueueName() + "2";
+ String queueName2 = getTestQueueName() + "2";
+
+ Queue queue2 = session2.createQueue("direct://" + exchangeName2 + "/" + queueName2 + "/" + queueName2 + "?" + BindingURL.OPTION_EXCHANGE_DURABLE + "='true'");
+ if(createProducer)
+ {
+ session2.createProducer(queue2);
+ }
+
+ if(createConsumer)
+ {
+ session2.createConsumer(queue2);
+ }
+ session2.close();
+
+ //verify the exchange was declared to expectation
+ verifyDeclaredExchange(exchangeName2, false, true);
+ }
+
+ private void verifyDeclaredExchange(String exchangeName, boolean isAutoDelete, boolean isDurable) throws IOException
+ {
+ String exchangeObjectName = _jmxUtils.getExchangeObjectName("test", exchangeName);
+ assertTrue("exchange should exist", _jmxUtils.doesManagedObjectExist(exchangeObjectName));
+ ManagedExchange exchange = _jmxUtils.getManagedExchange(exchangeName);
+ assertEquals(isAutoDelete, exchange.isAutoDelete());
+ assertEquals(isDurable,exchange.isDurable());
+ }
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java
index bc1eead8b4..40db17f799 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java
@@ -74,19 +74,20 @@ public class MaxDeliveryCountTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
//enable DLQ/maximumDeliveryCount support for all queues at the vhost level
- setConfigurationProperty("virtualhosts.virtualhost.test.queues.maximumDeliveryCount",
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.queues.maximumDeliveryCount",
String.valueOf(MAX_DELIVERY_COUNT));
- setConfigurationProperty("virtualhosts.virtualhost.test.queues.deadLetterQueues",
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.queues.deadLetterQueues",
String.valueOf(true));
//Ensure management is on
- setConfigurationProperty("management.enabled", "true");
- setConfigurationProperty("management.ssl.enabled", "false");
+ getBrokerConfiguration().addJmxManagementConfiguration();
// Set client-side flag to allow the server to determine if messages
// dead-lettered or requeued.
- setTestClientSystemProperty(ClientProperties.REJECT_BEHAVIOUR_PROP_NAME, "server");
-
+ if (!isBroker010())
+ {
+ setTestClientSystemProperty(ClientProperties.REJECT_BEHAVIOUR_PROP_NAME, "server");
+ }
super.setUp();
boolean durableSub = isDurSubTest();
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java
deleted file mode 100644
index 1c9ee27b94..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java
+++ /dev/null
@@ -1,236 +0,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.
- *
- */
-package org.apache.qpid.test.unit.client.channelclose;
-
-import junit.textui.TestRunner;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-import javax.jms.Destination;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Due to bizarre exception handling all sessions are closed if you get
- * a channel close request and no exception listener is registered.
- * <p/>
- * JIRA issue IBTBLZ-10.
- * <p/>
- * Simulate by:
- * <p/>
- * 0. Create two sessions with no exception listener.
- * 1. Publish message to queue/topic that does not exist (wrong routing key).
- * 2. This will cause a channel close.
- * 3. Since client does not have an exception listener, currently all sessions are
- * closed.
- */
-public class ChannelCloseOkTest extends QpidBrokerTestCase
-{
- private AMQConnection _connection;
- private Destination _destination1;
- private Destination _destination2;
- private Session _session1;
- private Session _session2;
- private final List<Message> _received1 = new ArrayList<Message>();
- private final List<Message> _received2 = new ArrayList<Message>();
-
- private static final Logger _log = LoggerFactory.getLogger(ChannelCloseOkTest.class);
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- _connection = (AMQConnection) getConnection("guest", "guest");
-
- _destination1 = new AMQQueue(_connection, "q1", true);
- _destination2 = new AMQQueue(_connection, "q2", true);
- _session1 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- _session1.createConsumer(_destination1).setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
- {
- _log.debug("consumer 1 got message [" + getTextMessage(message) + "]");
- synchronized (_received1)
- {
- _received1.add(message);
- _received1.notify();
- }
- }
- });
- _session2 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- _session2.createConsumer(_destination2).setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
- {
- _log.debug("consumer 2 got message [" + getTextMessage(message) + "]");
- synchronized (_received2)
- {
- _received2.add(message);
- _received2.notify();
- }
- }
- });
-
- _connection.start();
- }
-
- private String getTextMessage(Message message)
- {
- TextMessage tm = (TextMessage) message;
- try
- {
- return tm.getText();
- }
- catch (JMSException e)
- {
- return "oops " + e;
- }
- }
-
- protected void tearDown() throws Exception
- {
- closeConnection();
- super.tearDown();
- }
-
- public void closeConnection() throws JMSException
- {
- if (_connection != null)
- {
- _log.info(">>>>>>>>>>>>>>.. closing");
- _connection.close();
- }
- }
-
- public void testWithoutExceptionListener() throws Exception
- {
- doTest();
- }
-
- public void testWithExceptionListener() throws Exception
- {
- _connection.setExceptionListener(new ExceptionListener()
- {
- public void onException(JMSException jmsException)
- {
- _log.warn("onException - " + jmsException.getMessage());
- }
- });
-
- doTest();
- }
-
- public void doTest() throws Exception
- {
- // Check both sessions are ok.
- sendAndWait(_session1, _destination1, "first", _received1, 1);
- sendAndWait(_session2, _destination2, "second", _received2, 1);
- assertEquals(1, _received1.size());
- assertEquals(1, _received2.size());
-
- // Now send message to incorrect destination on session 1.
- Destination destination = new AMQQueue(_connection, "incorrect");
- send(_session1, destination, "third"); // no point waiting as message will never be received.
-
- // Ensure both sessions are still ok.
- // Send a bunch of messages as this give time for the sessions to be erroneously closed.
- final int num = 300;
- for (int i = 0; i < num; ++i)
- {
- send(_session1, _destination1, "" + i);
- send(_session2, _destination2, "" + i);
- }
-
- waitFor(_received1, num + 1);
- waitFor(_received2, num + 1);
-
- // Note that the third message is never received as it is sent to an incorrect destination.
- assertEquals(num + 1, _received1.size());
- assertEquals(num + 1, _received2.size());
- }
-
- private void sendAndWait(Session session, Destination destination, String message, List<Message> received, int count)
- throws JMSException, InterruptedException
- {
- send(session, destination, message);
- waitFor(received, count);
- }
-
- private void send(Session session, Destination destination, String message) throws JMSException
- {
- _log.debug("sending message " + message);
- MessageProducer producer1 = session.createProducer(destination);
- producer1.send(session.createTextMessage(message));
- }
-
- private void waitFor(List<Message> received, int count) throws InterruptedException
- {
- long timeout = 20000;
-
- synchronized (received)
- {
- long start = System.currentTimeMillis();
- while (received.size() < count)
- {
- if (System.currentTimeMillis() - start > timeout)
- {
- fail("timeout expired waiting for messages");
- }
- try
- {
- received.wait(timeout);
- }
- catch (InterruptedException e)
- {
- _log.info("Interrupted: " + e);
- throw e;
- }
-
- }
- }
- }
-
- private static String randomize(String in)
- {
- return in + System.currentTimeMillis();
- }
-
- public static void main(String[] args)
- {
- TestRunner.run(ChannelCloseOkTest.class);
- }
-
- public static junit.framework.Test suite()
- {
- return new junit.framework.TestSuite(ChannelCloseOkTest.class);
- }
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java
deleted file mode 100644
index c20eefd987..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java
+++ /dev/null
@@ -1,399 +0,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.
- *
- *
- */
-package org.apache.qpid.test.unit.client.channelclose;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.failover.FailoverException;
-import org.apache.qpid.client.protocol.AMQProtocolHandler;
-import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.framing.ChannelCloseOkBody;
-import org.apache.qpid.framing.ChannelOpenBody;
-import org.apache.qpid.framing.ChannelOpenOkBody;
-import org.apache.qpid.framing.ExchangeDeclareBody;
-import org.apache.qpid.framing.ExchangeDeclareOkBody;
-import org.apache.qpid.jms.ConnectionListener;
-import org.apache.qpid.protocol.AMQConstant;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-import javax.jms.Connection;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-public class ChannelCloseTest extends QpidBrokerTestCase implements ExceptionListener, ConnectionListener
-{
- private static final Logger _logger = LoggerFactory.getLogger(ChannelCloseTest.class);
-
- private Connection _connection;
- private Session _session;
- private static final long SYNC_TIMEOUT = 500;
- private int TEST = 0;
-
- /**
- * Close channel, use chanel with same id ensure error.
- *
- * This test is only valid for non 0-10 connection .
- */
- public void testReusingChannelAfterFullClosure() throws Exception
- {
- _connection=newConnection();
-
- // Create Producer
- try
- {
- _connection.start();
-
- createChannelAndTest(1);
-
- // Cause it to close
- try
- {
- _logger.info("Testing invalid exchange");
- declareExchange(1, "", "name_that_will_lookup_to_null", false);
- fail("Exchange name is empty so this should fail ");
- }
- catch (AMQException e)
- {
- assertEquals("Exchange should not be found", AMQConstant.NOT_FOUND, e.getErrorCode());
- }
-
- // Check that
- try
- {
- _logger.info("Testing valid exchange should fail");
- declareExchange(1, "topic", "amq.topic", false);
- fail("This should not succeed as the channel should be closed ");
- }
- catch (AMQException e)
- {
- if (_logger.isInfoEnabled())
- {
- _logger.info("Exception occured was:" + e.getErrorCode());
- }
-
- assertEquals("Connection should be closed", AMQConstant.CHANNEL_ERROR, e.getErrorCode());
-
- _connection=newConnection();
- }
-
- checkSendingMessage();
-
- _session.close();
- _connection.close();
-
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- /*
- close channel and send guff then send ok no errors
- REMOVE TEST - The behaviour after server has sent close is undefined.
- the server should be free to fail as it may wish to reclaim its resources
- immediately after close.
- */
- /*public void testSendingMethodsAfterClose() throws Exception
- {
- // this is testing an 0.8 connection
- if(isBroker08())
- {
- try
- {
- _connection=new AMQConnection("amqp://guest:guest@CCTTest/test?brokerlist='" + _brokerlist + "'");
-
- ((AMQConnection) _connection).setConnectionListener(this);
-
- _connection.setExceptionListener(this);
-
- // Change the StateManager for one that doesn't respond with Close-OKs
- AMQStateManager oldStateManager=((AMQConnection) _connection).getProtocolHandler().getStateManager();
-
- _session=_connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- _connection.start();
-
- // Test connection
- checkSendingMessage();
-
- // Set StateManager to manager that ignores Close-oks
- AMQProtocolSession protocolSession=
- ((AMQConnection) _connection).getProtocolHandler().getProtocolSession();
-
- MethodDispatcher d = protocolSession.getMethodDispatcher();
-
- MethodDispatcher wrappedDispatcher = (MethodDispatcher)
- Proxy.newProxyInstance(d.getClass().getClassLoader(),
- d.getClass().getInterfaces(),
- new MethodDispatcherProxyHandler(
- (ClientMethodDispatcherImpl) d));
-
- protocolSession.setMethodDispatcher(wrappedDispatcher);
-
-
- AMQStateManager newStateManager=new NoCloseOKStateManager(protocolSession);
- newStateManager.changeState(oldStateManager.getCurrentState());
-
- ((AMQConnection) _connection).getProtocolHandler().setStateManager(newStateManager);
-
- final int TEST_CHANNEL=1;
- _logger.info("Testing Channel(" + TEST_CHANNEL + ") Creation");
-
- createChannelAndTest(TEST_CHANNEL);
-
- // Cause it to close
- try
- {
- _logger.info("Closing Channel - invalid exchange");
- declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", false);
- fail("Exchange name is empty so this should fail ");
- }
- catch (AMQException e)
- {
- assertEquals("Exchange should not be found", AMQConstant.NOT_FOUND, e.getErrorCode());
- }
-
- try
- {
- // Send other methods that should be ignored
- // send them no wait as server will ignore them
- _logger.info("Tested known exchange - should ignore");
- declareExchange(TEST_CHANNEL, "topic", "amq.topic", true);
-
- _logger.info("Tested known invalid exchange - should ignore");
- declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", true);
-
- _logger.info("Tested known invalid exchange - should ignore");
- declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", true);
-
- // Send sync .. server will igore and timy oue
- _logger.info("Tested known invalid exchange - should ignore");
- declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", false);
- }
- catch (AMQTimeoutException te)
- {
- assertEquals("Request should timeout", AMQConstant.REQUEST_TIMEOUT, te.getErrorCode());
- }
- catch (AMQException e)
- {
- fail("This should not fail as all requests should be ignored");
- }
-
- _logger.info("Sending Close");
- // Send Close-ok
- sendClose(TEST_CHANNEL);
-
- _logger.info("Re-opening channel");
-
- createChannelAndTest(TEST_CHANNEL);
-
- // Test connection is still ok
-
- checkSendingMessage();
-
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
- catch (AMQException e)
- {
- fail(e.getMessage());
-
- }
- catch (URLSyntaxException e)
- {
- fail(e.getMessage());
- }
- finally
- {
- try
- {
- _session.close();
- _connection.close();
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
- }
-*/
- private void createChannelAndTest(int channel) throws FailoverException
- {
- // Create A channel
- try
- {
- createChannel(channel);
- }
- catch (AMQException e)
- {
- fail(e.getMessage());
- }
-
- // Test it is ok
- try
- {
- declareExchange(channel, "topic", "amq.topic", false);
- _logger.info("Tested known exchange");
- }
- catch (AMQException e)
- {
- fail("This should not fail as this is the default exchange details");
- }
- }
-
- private void sendClose(int channel)
- {
- ChannelCloseOkBody body =
- ((AMQConnection) _connection).getProtocolHandler().getMethodRegistry().createChannelCloseOkBody();
- AMQFrame frame = body.generateFrame(channel);
-
- ((AMQConnection) _connection).getProtocolHandler().writeFrame(frame);
- }
-
- private void checkSendingMessage() throws JMSException
- {
- TEST++;
- _logger.info("Test creating producer which will use channel id 1");
-
- Queue queue = _session.createQueue("CCT_test_validation_queue" + TEST);
-
- MessageConsumer consumer = _session.createConsumer(queue);
-
- MessageProducer producer = _session.createProducer(queue);
-
- final String MESSAGE = "CCT_Test_Message";
- producer.send(_session.createTextMessage(MESSAGE));
-
- Message msg = consumer.receive(2000);
-
- assertNotNull("Received messages should not be null.", msg);
- assertEquals("Message received not what we sent", MESSAGE, ((TextMessage) msg).getText());
- }
-
- private Connection newConnection()
- {
- Connection connection = null;
- try
- {
- connection = getConnection();
-
- ((AMQConnection) connection).setConnectionListener(this);
-
- _session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- connection.start();
-
- }
- catch (Exception e)
- {
- fail("Creating new connection when:" + e.getMessage());
- }
-
- return connection;
- }
-
- private void declareExchange(int channelId, String _type, String _name, boolean nowait)
- throws AMQException, FailoverException
- {
- ExchangeDeclareBody body =
- ((AMQConnection) _connection).getProtocolHandler()
- .getMethodRegistry()
- .createExchangeDeclareBody(0,
- new AMQShortString(_name),
- new AMQShortString(_type),
- true,
- false,
- false,
- false,
- nowait,
- null);
- AMQFrame exchangeDeclare = body.generateFrame(channelId);
- AMQProtocolHandler protocolHandler = ((AMQConnection) _connection).getProtocolHandler();
-
-
- if (nowait)
- {
- protocolHandler.writeFrame(exchangeDeclare);
- }
- else
- {
- protocolHandler.syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class, SYNC_TIMEOUT);
- }
-
-// return null;
-// }
-// }, (AMQConnection)_connection).execute();
-
- }
-
- private void createChannel(int channelId) throws AMQException, FailoverException
- {
- ChannelOpenBody body =
- ((AMQConnection) _connection).getProtocolHandler().getMethodRegistry().createChannelOpenBody(null);
-
- ((AMQConnection) _connection).getProtocolHandler().syncWrite(body.generateFrame(channelId), // outOfBand
- ChannelOpenOkBody.class);
-
- }
-
- public void onException(JMSException jmsException)
- {
- // _logger.info("CCT" + jmsException);
- fail(jmsException.getMessage());
- }
-
- public void bytesSent(long count)
- { }
-
- public void bytesReceived(long count)
- { }
-
- public boolean preFailover(boolean redirect)
- {
- return false;
- }
-
- public boolean preResubscribe()
- {
- return false;
- }
-
- public void failoverComplete()
- { }
-
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java
index f2387fa99b..b43fe35a09 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java
@@ -21,7 +21,7 @@
package org.apache.qpid.test.unit.close;
import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.AMQSession_0_8;
import org.apache.qpid.framing.AMQFrame;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.ExchangeDeclareBody;
@@ -81,7 +81,7 @@ public class JavaServerCloseRaceConditionTest extends QpidBrokerTestCase
AMQConnection connection = (AMQConnection) getConnection();
- AMQSession session = (AMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ AMQSession_0_8 session = (AMQSession_0_8) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Set no wait true so that we block the connection
// Also set a different exchange class string so the attempt to declare
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
index a07e531b98..a9ac028af6 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
@@ -73,7 +73,7 @@ public class DurableSubscriptionTest extends QpidBrokerTestCase
public void setUp() throws Exception
{
- setConfigurationProperty("management.enabled", "true");
+ getBrokerConfiguration().addJmxManagementConfiguration();
_jmxConnected=false;
super.setUp();
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java
index fd8beffbe6..d93c7a2e71 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java
@@ -29,7 +29,7 @@ public class TransactionTimeoutDisabledTest extends TransactionTimeoutTestCase
protected void configure() throws Exception
{
// Setup housekeeping every second
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
// No transaction timeout configuration.
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java b/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java
index b11df5a2a0..4dc26847da 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java
@@ -39,29 +39,29 @@ public class TransactionTimeoutTest extends TransactionTimeoutTestCase
protected void configure() throws Exception
{
- // Setup housekeeping every second
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
+ // Setup housekeeping every 100ms
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100");
if (getName().contains("ProducerIdle"))
{
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "0");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "0");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1500");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "0");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "0");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1500");
}
else if (getName().contains("ProducerOpen"))
{
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "0");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "0");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "0");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "0");
}
else
{
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
- setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500");
+ setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1000");
}
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java
index e2b0f00ee4..721dc027c6 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTestCase.java
@@ -23,17 +23,13 @@ package org.apache.qpid.test.unit.transacted;
import junit.framework.TestCase;
import org.apache.qpid.AMQException;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.jms.ConnectionURL;
-import org.apache.qpid.jms.Session;
+import org.apache.qpid.configuration.ClientProperties;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.util.LogMonitor;
+import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
@@ -41,6 +37,7 @@ import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
+import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@@ -61,7 +58,7 @@ public abstract class TransactionTimeoutTestCase extends QpidBrokerTestCase impl
public static final String OPEN = "Open";
protected LogMonitor _monitor;
- protected AMQConnection _con;
+ protected Connection _con;
protected Session _psession, _csession;
protected Queue _queue;
protected MessageConsumer _consumer;
@@ -89,16 +86,14 @@ public abstract class TransactionTimeoutTestCase extends QpidBrokerTestCase impl
super.setUp();
// Connect to broker
- String broker = ("tcp://localhost:" + DEFAULT_PORT);
- ConnectionURL url = new AMQConnectionURL("amqp://guest:guest@clientid/test?brokerlist='" + broker + "'&maxprefetch='1'");
- _con = (AMQConnection) getConnection(url);
+ setTestClientSystemProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, String.valueOf(1));
+ _con = getConnection();
_con.setExceptionListener(this);
_con.start();
// Create queue
Session qsession = _con.createSession(true, Session.SESSION_TRANSACTED);
- AMQShortString queueName = new AMQShortString("test");
- _queue = new AMQQueue(qsession.getDefaultQueueExchangeName(), queueName, queueName, false, true);
+ _queue = qsession.createQueue(getTestQueueName());
qsession.close();
// Create producer and consumer
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java b/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java
new file mode 100644
index 0000000000..12d286f822
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.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.test.utils;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Generates the command to start a broker by substituting the tokens
+ * in the provided broker command.
+ *
+ * The command is returned as a list so that it can be easily used by a
+ * {@link java.lang.ProcessBuilder}.
+ */
+public class BrokerCommandHelper
+{
+ private final List<String> _brokerCommandTemplateAsList;
+
+ public BrokerCommandHelper(String brokerCommandTemplate)
+ {
+ _brokerCommandTemplateAsList = new LinkedList<String>(Arrays.asList(brokerCommandTemplate.split("\\s+")));
+ }
+
+ public String[] getBrokerCommand( int port, String storePath, String storeType, File logConfigFile)
+ {
+ String[] command = new String[_brokerCommandTemplateAsList.size()];
+ int i=0;
+ for (String commandPart : _brokerCommandTemplateAsList)
+ {
+ command[i] = commandPart
+ .replace("@PORT", "" + port)
+ .replace("@STORE_PATH", storePath)
+ .replace("@STORE_TYPE", storeType)
+ .replace("@LOG_CONFIG_FILE", '"' + logConfigFile.getAbsolutePath() + '"');
+ i++;
+ }
+ return command;
+ }
+
+ private int getBrokerCommandLogOptionIndex(String logOption)
+ {
+ int logOptionIndex = _brokerCommandTemplateAsList.indexOf(logOption);
+ if(logOptionIndex == -1)
+ {
+ throw new RuntimeException("Could not find option " + logOption + " in " + _brokerCommandTemplateAsList);
+ }
+ return logOptionIndex;
+ }
+
+
+ public void removeBrokerCommandLog4JFile()
+ {
+ String logOption = "-l";
+ int logOptionIndex = getBrokerCommandLogOptionIndex(logOption);
+ if (logOptionIndex + 1 >= _brokerCommandTemplateAsList.size())
+ {
+ throw new RuntimeException("Could not find log config location");
+ }
+ _brokerCommandTemplateAsList.remove(logOptionIndex);
+ _brokerCommandTemplateAsList.remove(logOptionIndex);
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java b/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java
new file mode 100644
index 0000000000..f0bcea8e6e
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java
@@ -0,0 +1,61 @@
+/* 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.test.utils;
+
+import static org.mockito.Mockito.*;
+
+import java.io.File;
+
+public class BrokerCommandHelperTest extends QpidTestCase
+{
+ private BrokerCommandHelper _brokerCommandHelper = new BrokerCommandHelper("qpid -p @PORT -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE");
+
+ private File logConfigFile = mock(File.class);
+
+ @Override
+ public void setUp()
+ {
+ when(logConfigFile.getAbsolutePath()).thenReturn("log Config File");
+ }
+
+ public void testGetBrokerCommand()
+ {
+ String[] brokerCommand = _brokerCommandHelper.getBrokerCommand(1, "configFile", "json", logConfigFile);
+
+ String[] expected = { "qpid", "-p", "1", "-sp", "configFile", "-st", "json", "-l", "\"log Config File\"" };
+ assertEquals("Unexpected broker command", 9, brokerCommand.length);
+ for (int i = 0; i < expected.length; i++)
+ {
+ assertEquals("Unexpected command part value at " + i,expected[i], brokerCommand[i] );
+ }
+ }
+
+ public void testRemoveBrokerCommandLog4JFile()
+ {
+ _brokerCommandHelper.removeBrokerCommandLog4JFile();
+ String[] brokerCommand = _brokerCommandHelper.getBrokerCommand(1, "configFile", "json", logConfigFile);
+
+ String[] expected = { "qpid", "-p", "1", "-sp", "configFile", "-st", "json" };
+ assertEquals("Unexpected broker command", 7, brokerCommand.length);
+ for (int i = 0; i < expected.length; i++)
+ {
+ assertEquals("Unexpected command part value at " + i,expected[i], brokerCommand[i] );
+ }
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java b/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
index a71a4ef517..8bad73d0ea 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java
@@ -20,9 +20,6 @@
*/
package org.apache.qpid.test.utils;
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-import java.lang.management.ThreadMXBean;
import java.util.Set;
import org.apache.log4j.Logger;
@@ -82,28 +79,7 @@ public class InternalBrokerHolder implements BrokerHolder
@Override
public String dumpThreads()
{
- ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
- ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true);
- StringBuilder dump = new StringBuilder();
- dump.append(String.format("%n"));
- for (ThreadInfo threadInfo : threadInfos)
- {
- dump.append(threadInfo);
- }
-
- long[] deadLocks = threadMXBean.findDeadlockedThreads();
- if (deadLocks != null && deadLocks.length > 0)
- {
- ThreadInfo[] deadlockedThreads = threadMXBean.getThreadInfo(deadLocks);
- dump.append(String.format("%n"));
- dump.append("Deadlock is detected!");
- dump.append(String.format("%n"));
- for (ThreadInfo threadInfo : deadlockedThreads)
- {
- dump.append(threadInfo);
- }
- }
- return dump.toString();
+ return TestUtils.dumpThreads();
}
@Override
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java b/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
index 43b80b45fb..6e6e3271f0 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java
@@ -24,7 +24,6 @@ import junit.framework.TestCase;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.qpid.management.common.JMXConnnectionFactory;
-import org.apache.qpid.management.common.mbeans.ConfigurationManagement;
import org.apache.qpid.management.common.mbeans.LoggingManagement;
import org.apache.qpid.management.common.mbeans.ManagedBroker;
import org.apache.qpid.management.common.mbeans.ManagedConnection;
@@ -32,6 +31,8 @@ import org.apache.qpid.management.common.mbeans.ManagedExchange;
import org.apache.qpid.management.common.mbeans.ManagedQueue;
import org.apache.qpid.management.common.mbeans.ServerInformation;
import org.apache.qpid.management.common.mbeans.UserManagement;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.plugin.PluginFactory;
import javax.management.InstanceNotFoundException;
import javax.management.JMException;
@@ -46,7 +47,9 @@ import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
/**
@@ -78,7 +81,7 @@ public class JMXTestUtils
public void setUp() throws IOException, ConfigurationException, Exception
{
- _test.setConfigurationProperty("management.enabled", "true");
+ _test.getBrokerConfiguration().addJmxManagementConfiguration();
}
public void open() throws Exception
@@ -287,9 +290,7 @@ public class JMXTestUtils
public ObjectName getQueueObjectName(String virtualHostName, String queue)
{
// Get the name of the test manager
- String query = "org.apache.qpid:type=VirtualHost.Queue,VirtualHost="
- + ObjectName.quote(virtualHostName) + ",name="
- + ObjectName.quote(queue) + ",*";
+ String query = getQueueObjectNameString(virtualHostName, queue);
Set<ObjectName> objectNames = queryObjects(query);
@@ -302,32 +303,20 @@ public class JMXTestUtils
return objectName;
}
+ public String getQueueObjectNameString(String virtualHostName, String queue) {
+ return "org.apache.qpid:type=VirtualHost.Queue,VirtualHost="
+ + ObjectName.quote(virtualHostName) + ",name="
+ + ObjectName.quote(queue) + ",*";
+ }
+
/**
- * Retrive the ObjectName for the given Exchange on a VirtualHost.
- *
- * This is then used to create a proxy to the ManagedExchange MBean.
- *
- * @param virtualHostName the VirtualHost the Exchange is on
- * @param exchange the Exchange to retireve e.g. 'direct'
- * @return the ObjectName for the given Exchange on the VirtualHost
+ * Generate the ObjectName for the given Exchange on a VirtualHost.
*/
- @SuppressWarnings("static-access")
- public ObjectName getExchangeObjectName(String virtualHostName, String exchange)
+ public String getExchangeObjectName(String virtualHostName, String exchange)
{
- // Get the name of the test manager
- String query = "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost="
+ return "org.apache.qpid:type=VirtualHost.Exchange,VirtualHost="
+ ObjectName.quote(virtualHostName) + ",name="
+ ObjectName.quote(exchange) + ",*";
-
- Set<ObjectName> objectNames = queryObjects(query);
-
- _test.assertNotNull("Null ObjectName Set returned", objectNames);
- _test.assertEquals("Incorrect number of exchange with name '" + exchange + "' returned", 1, objectNames.size());
-
- // We have verified we have only one value in objectNames so return it
- ObjectName objectName = objectNames.iterator().next();
- _test.getLogger().info("Loading: " + objectName);
- return objectName;
}
@SuppressWarnings("static-access")
@@ -343,7 +332,7 @@ public class JMXTestUtils
return getManagedObject(managedClass, objectName);
}
- public boolean isManagedObjectExist(String query)
+ public boolean doesManagedObjectExist(String query)
{
return !queryObjects(query).isEmpty();
}
@@ -373,9 +362,20 @@ public class JMXTestUtils
return getManagedObject(ManagedBroker.class, getVirtualHostManagerObjectName(virtualHost));
}
+ @SuppressWarnings("static-access")
public ManagedExchange getManagedExchange(String exchangeName)
{
- ObjectName objectName = getExchangeObjectName("test", exchangeName);
+ String query = getExchangeObjectName("test", exchangeName);
+
+ Set<ObjectName> objectNames = queryObjects(query);
+
+ _test.assertNotNull("Null ObjectName Set returned", objectNames);
+ _test.assertEquals("Incorrect number of exchange with name '" + exchangeName + "' returned", 1, objectNames.size());
+
+ // We have verified we have only one value in objectNames so return an mbean proxy for it
+ ObjectName objectName = objectNames.iterator().next();
+ _test.getLogger().info("Loading: " + objectName);
+
return MBeanServerInvocationHandler.newProxyInstance(_mbsc, objectName, ManagedExchange.class, false);
}
@@ -391,12 +391,6 @@ public class JMXTestUtils
return getManagedObject(LoggingManagement.class, objectName);
}
- public ConfigurationManagement getConfigurationManagement() throws MalformedObjectNameException
- {
- ObjectName objectName = new ObjectName("org.apache.qpid:type=ConfigurationManagement,name=ConfigurationManagement");
- return getManagedObject(ConfigurationManagement.class, objectName);
- }
-
public UserManagement getUserManagement() throws MalformedObjectNameException
{
ObjectName objectName = new ObjectName("org.apache.qpid:type=UserManagement,name=UserManagement");
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
index aa909a6674..d36f57171f 100644..100755
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
@@ -19,18 +19,17 @@ package org.apache.qpid.test.utils;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.PrintStream;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.Destination;
@@ -45,32 +44,34 @@ import javax.jms.Session;
import javax.jms.StreamMessage;
import javax.jms.TextMessage;
import javax.jms.Topic;
+import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQTopic;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ConnectionURL;
-import org.apache.qpid.management.common.mbeans.ConfigurationManagement;
import org.apache.qpid.server.Broker;
import org.apache.qpid.server.BrokerOptions;
-import org.apache.qpid.server.ProtocolExclusion;
-import org.apache.qpid.server.ProtocolInclusion;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.protocol.AmqpProtocolVersion;
+import org.apache.qpid.server.store.MemoryMessageStore;
import org.apache.qpid.server.store.MessageStoreConstants;
+import org.apache.qpid.server.store.MessageStoreCreator;
+import org.apache.qpid.server.store.MessageStoreFactory;
import org.apache.qpid.server.store.derby.DerbyMessageStore;
import org.apache.qpid.url.URLSyntaxException;
import org.apache.qpid.util.FileUtils;
-import org.apache.qpid.util.LogMonitor;
/**
* Qpid base class for system testing test cases.
@@ -80,7 +81,7 @@ public class QpidBrokerTestCase extends QpidTestCase
public enum BrokerType
{
EXTERNAL /** Test case relies on a Broker started independently of the test-suite */,
- INTERNAL /** Test case starts an embedded broker within this JVM */,
+ INTERNAL /** Test case starts an embedded broker within this JVM */,
SPAWNED /** Test case spawns a new broker as a separate process */
}
@@ -88,9 +89,9 @@ public class QpidBrokerTestCase extends QpidTestCase
public static final String GUEST_PASSWORD = "guest";
protected final static String QpidHome = System.getProperty("QPID_HOME");
- protected File _configFile = new File(System.getProperty("broker.config"));
- protected File _logConfigFile = new File(System.getProperty("log4j.configuration"));
-
+ private final File _configFile = new File(System.getProperty("broker.config"));
+ private File _logConfigFile;
+ protected final String _brokerStoreType = System.getProperty("broker.config-store-type", "json");
protected static final Logger _logger = Logger.getLogger(QpidBrokerTestCase.class);
protected static final int LOGMONITOR_TIMEOUT = 5000;
@@ -98,7 +99,7 @@ public class QpidBrokerTestCase extends QpidTestCase
private Map<String, String> _propertiesSetForBroker = new HashMap<String, String>();
- private XMLConfiguration _testConfiguration = new XMLConfiguration();
+ private Map<Integer, TestBrokerConfiguration> _brokerConfigurations;
private XMLConfiguration _testVirtualhosts = new XMLConfiguration();
protected static final String INDEX = "index";
@@ -106,24 +107,31 @@ public class QpidBrokerTestCase extends QpidTestCase
private static final String DEFAULT_INITIAL_CONTEXT = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory";
+ private static Map<String, String> supportedStoresClassToTypeMapping = new HashMap<String, String>();
+
static
{
- String initialContext = System.getProperty(InitialContext.INITIAL_CONTEXT_FACTORY);
+ String initialContext = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
if (initialContext == null || initialContext.length() == 0)
{
- System.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT);
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT);
+ }
+
+ MessageStoreCreator messageStoreCreator = new MessageStoreCreator();
+ Collection<MessageStoreFactory> factories = messageStoreCreator.getFactories();
+ for (MessageStoreFactory messageStoreFactory : factories)
+ {
+ supportedStoresClassToTypeMapping.put(messageStoreFactory.createMessageStore().getClass().getName(), messageStoreFactory.getType());
}
}
// system properties
private static final String TEST_VIRTUALHOSTS = "test.virtualhosts";
- private static final String TEST_CONFIG = "test.config";
private static final String BROKER_LANGUAGE = "broker.language";
protected static final String BROKER_TYPE = "broker.type";
private static final String BROKER_COMMAND = "broker.command";
private static final String BROKER_CLEAN_BETWEEN_TESTS = "broker.clean.between.tests";
- private static final String BROKER_EXISTING_QPID_WORK = "broker.existing.qpid.work";
private static final String BROKER_VERSION = "broker.version";
protected static final String BROKER_READY = "broker.ready";
private static final String BROKER_STOPPED = "broker.stopped";
@@ -131,8 +139,14 @@ public class QpidBrokerTestCase extends QpidTestCase
private static final String BROKER_LOG_INTERLEAVE = "broker.log.interleave";
private static final String BROKER_LOG_PREFIX = "broker.log.prefix";
private static final String BROKER_PERSITENT = "broker.persistent";
- public static final String BROKER_PROTOCOL_EXCLUDES = "broker.protocol.excludes";
- public static final String BROKER_PROTOCOL_INCLUDES = "broker.protocol.includes";
+ public static final String PROFILE_USE_SSL = "profile.use_ssl";
+
+ public static final int DEFAULT_PORT_VALUE = 5672;
+ public static final int DEFAULT_SSL_PORT_VALUE = 5671;
+ public static final int DEFAULT_JMXPORT_REGISTRYSERVER = 8999;
+ public static final int JMXPORT_CONNECTORSERVER_OFFSET = 100;
+ public static final int DEFAULT_HTTP_MANAGEMENT_PORT = 8080;
+ public static final int DEFAULT_HTTPS_MANAGEMENT_PORT = 8443;
// values
protected static final String JAVA = "java";
@@ -140,15 +154,15 @@ public class QpidBrokerTestCase extends QpidTestCase
protected static final String QPID_HOME = "QPID_HOME";
- public static final int DEFAULT_VM_PORT = 1;
- public static final int DEFAULT_PORT = Integer.getInteger("test.port", ServerConfiguration.DEFAULT_PORT);
+ public static final int DEFAULT_PORT = Integer.getInteger("test.port", DEFAULT_PORT_VALUE);
public static final int FAILING_PORT = Integer.parseInt(System.getProperty("test.port.alt"));
- public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", ServerConfiguration.DEFAULT_JMXPORT_REGISTRYSERVER);
- public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", ServerConfiguration.DEFAULT_SSL_PORT);
+ public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", DEFAULT_JMXPORT_REGISTRYSERVER);
+ public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", DEFAULT_SSL_PORT_VALUE);
protected String _brokerLanguage = System.getProperty(BROKER_LANGUAGE, JAVA);
protected BrokerType _brokerType = BrokerType.valueOf(System.getProperty(BROKER_TYPE, "").toUpperCase());
- protected String _brokerCommand = System.getProperty(BROKER_COMMAND);
+
+ protected BrokerCommandHelper _brokerCommandHelper = new BrokerCommandHelper(System.getProperty(BROKER_COMMAND));
private Boolean _brokerCleanBetweenTests = Boolean.getBoolean(BROKER_CLEAN_BETWEEN_TESTS);
private final AmqpProtocolVersion _brokerVersion = AmqpProtocolVersion.valueOf(System.getProperty(BROKER_VERSION, ""));
protected String _output = System.getProperty(TEST_OUTPUT, System.getProperty("java.io.tmpdir"));
@@ -190,14 +204,67 @@ public class QpidBrokerTestCase extends QpidTestCase
}
private MessageType _messageType = MessageType.TEXT;
- public QpidBrokerTestCase(String name)
- {
- super(name);
- }
-
public QpidBrokerTestCase()
{
super();
+ _brokerConfigurations = new HashMap<Integer, TestBrokerConfiguration>();
+ initialiseLogConfigFile();
+ }
+
+ public TestBrokerConfiguration getBrokerConfiguration(int port)
+ {
+ int actualPort = getPort(port);
+
+ synchronized (_brokerConfigurations)
+ {
+ TestBrokerConfiguration configuration = _brokerConfigurations.get(actualPort);
+ if (configuration == null)
+ {
+ configuration = createBrokerConfiguration(actualPort);
+ }
+ return configuration;
+ }
+ }
+
+ public TestBrokerConfiguration getBrokerConfiguration()
+ {
+ return getBrokerConfiguration(DEFAULT_PORT);
+ }
+
+ public TestBrokerConfiguration createBrokerConfiguration(int port)
+ {
+ int actualPort = getPort(port);
+ TestBrokerConfiguration configuration = new TestBrokerConfiguration(System.getProperty(_brokerStoreType), _configFile.getAbsolutePath());
+ synchronized (_brokerConfigurations)
+ {
+ _brokerConfigurations.put(actualPort, configuration);
+ }
+ if (actualPort != DEFAULT_PORT)
+ {
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.PORT, actualPort);
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_RMI_PORT, Port.PORT, getManagementPort(actualPort));
+ configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.PORT, getManagementPort(actualPort) + JMXPORT_CONNECTORSERVER_OFFSET);
+ }
+ return configuration;
+ }
+
+ private void initialiseLogConfigFile()
+ {
+ try
+ {
+ _logger.info("About to initialise log config file from system property: " + LOG4J_CONFIG_FILE_PATH);
+
+ URI uri = new URI("file", LOG4J_CONFIG_FILE_PATH, null);
+ _logConfigFile = new File(uri);
+ if(!_logConfigFile.exists())
+ {
+ throw new RuntimeException("Log config file " + _logConfigFile.getAbsolutePath() + " does not exist");
+ }
+ }
+ catch (URISyntaxException e)
+ {
+ throw new RuntimeException("Couldn't create URI from log4.configuration: " + LOG4J_CONFIG_FILE_PATH, e);
+ }
}
public Logger getLogger()
@@ -289,16 +356,6 @@ public class QpidBrokerTestCase extends QpidTestCase
fail("Unable to test without config file:" + _configFile);
}
- String existingQpidWorkPath = System.getProperty(BROKER_EXISTING_QPID_WORK);
- if(existingQpidWorkPath != null && !existingQpidWorkPath.equals(""))
- {
-
- String qpidWork = getQpidWork(_brokerType, getPort());
- File existing = new File(existingQpidWorkPath);
- cleanBrokerWork(qpidWork);
- FileUtils.copyRecursive(existing, new File(qpidWork));
- }
-
startBroker();
}
@@ -322,7 +379,7 @@ public class QpidBrokerTestCase extends QpidTestCase
{
Set<Integer> ports = new HashSet<Integer>();
int managementPort = getManagementPort(mainPort);
- int connectorServerPort = managementPort + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET;
+ int connectorServerPort = managementPort + JMXPORT_CONNECTORSERVER_OFFSET;
ports.add(mainPort);
ports.add(managementPort);
@@ -354,37 +411,33 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
- protected String getBrokerCommand(int port) throws MalformedURLException
+ public void startBroker() throws Exception
{
- final int sslPort = port-1;
- final String protocolExcludesList = getProtocolExcludesList(port, sslPort);
- final String protocolIncludesList = getProtocolIncludesList(port, sslPort);
+ startBroker(0);
+ }
- return _brokerCommand
- .replace("@PORT", "" + port)
- .replace("@SSL_PORT", "" + sslPort)
- .replace("@MPORT", "" + getManagementPort(port))
- .replace("@CONFIG_FILE", _configFile.toString())
- .replace("@LOG_CONFIG_FILE", _logConfigFile.toString())
- .replace("@EXCLUDES", protocolExcludesList)
- .replace("@INCLUDES", protocolIncludesList);
+ public void startBroker(int port) throws Exception
+ {
+ int actualPort = getPort(port);
+ TestBrokerConfiguration configuration = getBrokerConfiguration(actualPort);
+ startBroker(actualPort, configuration, _testVirtualhosts);
}
- public void startBroker() throws Exception
+
+ protected File getBrokerCommandLog4JFile()
{
- startBroker(0);
+ return _logConfigFile;
}
- public void startBroker(int port) throws Exception
+ protected void setBrokerCommandLog4JFile(File file)
{
- startBroker(port, _testConfiguration, _testVirtualhosts);
+ _logConfigFile = file;
+ _logger.info("Modified log config file to: " + file);
}
- public void startBroker(int port, XMLConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception
+ public void startBroker(int port, TestBrokerConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception
{
port = getPort(port);
-
- // Save any configuration changes that have been made
String testConfig = saveTestConfiguration(port, testConfiguration);
String virtualHostsConfig = saveTestVirtualhosts(port, virtualHosts);
@@ -397,28 +450,20 @@ public class QpidBrokerTestCase extends QpidTestCase
if (_brokerType.equals(BrokerType.INTERNAL) && !existingInternalBroker())
{
- setConfigurationProperty(ServerConfiguration.MGMT_CUSTOM_REGISTRY_SOCKET, String.valueOf(false));
- testConfig = saveTestConfiguration(port, testConfiguration);
- _logger.info("Set test.config property to: " + testConfig);
_logger.info("Set test.virtualhosts property to: " + virtualHostsConfig);
- setSystemProperty(TEST_CONFIG, testConfig);
setSystemProperty(TEST_VIRTUALHOSTS, virtualHostsConfig);
-
+ setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, "false");
BrokerOptions options = new BrokerOptions();
- options.setConfigFile(_configFile.getAbsolutePath());
- options.addPort(port);
-
- addExcludedPorts(port, DEFAULT_SSL_PORT, options);
- addIncludedPorts(port, DEFAULT_SSL_PORT, options);
- options.setJmxPortRegistryServer(getManagementPort(port));
+ options.setConfigurationStoreType(_brokerStoreType);
+ options.setConfigurationStoreLocation(testConfig);
//Set the log config file, relying on the log4j.configuration system property
//set on the JVM by the JUnit runner task in module.xml.
options.setLogConfigFile(_logConfigFile.getAbsolutePath());
Broker broker = new Broker();
- _logger.info("starting internal broker (same JVM)");
+ _logger.info("Starting internal broker (same JVM)");
broker.startup(options);
_brokers.put(port, new InternalBrokerHolder(broker, System.getProperty("QPID_WORK"), portsUsedByBroker));
@@ -427,9 +472,10 @@ public class QpidBrokerTestCase extends QpidTestCase
{
// Add the port to QPID_WORK to ensure unique working dirs for multi broker tests
final String qpidWork = getQpidWork(_brokerType, port);
- String cmd = getBrokerCommand(port);
- _logger.info("starting external broker: " + cmd);
- ProcessBuilder pb = new ProcessBuilder(cmd.split("\\s+"));
+
+ String[] cmd = _brokerCommandHelper.getBrokerCommand(port, testConfig, _brokerStoreType, _logConfigFile);
+ _logger.info("Starting spawn broker using command: " + StringUtils.join(cmd, ' '));
+ ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
Map<String, String> processEnv = pb.environment();
String qpidHome = System.getProperty(QPID_HOME);
@@ -459,28 +505,28 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
+ String qpidOpts = "";
- // Add default test logging levels that are used by the log4j-test
- // Use the convenience methods to push the current logging setting
- // in to the external broker's QPID_OPTS string.
- if (System.getProperty("amqj.protocol.logging.level") != null)
+ // a synchronized hack to avoid adding into QPID_OPTS the values
+ // of JVM properties "test.virtualhosts" and "test.config" set by a concurrent startup process
+ synchronized (_propertiesSetForBroker)
{
+ // Add default test logging levels that are used by the log4j-test
+ // Use the convenience methods to push the current logging setting
+ // in to the external broker's QPID_OPTS string.
setSystemProperty("amqj.protocol.logging.level");
- }
- if (System.getProperty("root.logging.level") != null)
- {
setSystemProperty("root.logging.level");
- }
-
- // set test.config and test.virtualhosts
- String qpidOpts = " -D" + TEST_CONFIG + "=" + testConfig + " -D" + TEST_VIRTUALHOSTS + "=" + virtualHostsConfig;
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES);
+ setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES);
+ setSystemProperty(TEST_VIRTUALHOSTS, virtualHostsConfig);
- // Add all the specified system properties to QPID_OPTS
- if (!_propertiesSetForBroker.isEmpty())
- {
- for (String key : _propertiesSetForBroker.keySet())
+ // Add all the specified system properties to QPID_OPTS
+ if (!_propertiesSetForBroker.isEmpty())
{
- qpidOpts += " -D" + key + "=" + _propertiesSetForBroker.get(key);
+ for (String key : _propertiesSetForBroker.keySet())
+ {
+ qpidOpts += " -D" + key + "=" + _propertiesSetForBroker.get(key);
+ }
}
}
if (processEnv.containsKey("QPID_OPTS"))
@@ -489,9 +535,6 @@ public class QpidBrokerTestCase extends QpidTestCase
}
processEnv.put("QPID_OPTS", qpidOpts);
- _logger.info("Set test.config property to: " + testConfig);
- _logger.info("Set test.virtualhosts property to: " + virtualHostsConfig);
-
// cpp broker requires that the work directory is created
createBrokerWork(qpidWork);
@@ -505,9 +548,15 @@ public class QpidBrokerTestCase extends QpidTestCase
p.start();
+ SpawnedBrokerHolder holder = new SpawnedBrokerHolder(process, qpidWork, portsUsedByBroker);
if (!p.await(30, TimeUnit.SECONDS))
{
_logger.info("broker failed to become ready (" + p.getReady() + "):" + p.getStopLine());
+ String threadDump = holder.dumpThreads();
+ if (!threadDump.isEmpty())
+ {
+ _logger.info("the result of a try to capture thread dump:" + threadDump);
+ }
//Ensure broker has stopped
process.destroy();
cleanBrokerWork(qpidWork);
@@ -528,65 +577,7 @@ public class QpidBrokerTestCase extends QpidTestCase
// this is expect if the broker started successfully
}
- _brokers.put(port, new SpawnedBrokerHolder(process, qpidWork, portsUsedByBroker));
- }
- }
-
- private void addExcludedPorts(int port, int sslPort, BrokerOptions options)
- {
- final String protocolExcludesList = getProtocolExcludesList(port, sslPort);
-
- if (protocolExcludesList.equals(""))
- {
- return;
- }
- final String[] toks = protocolExcludesList.split("\\s");
-
- if(toks.length % 2 != 0)
- {
- throw new IllegalArgumentException("Must be an even number of tokens in '" + protocolExcludesList + "'");
- }
- for (int i = 0; i < toks.length; i=i+2)
- {
- String excludeArg = toks[i];
- final int excludedPort = Integer.parseInt(toks[i+1]);
- options.addExcludedPort(ProtocolExclusion.lookup(excludeArg), excludedPort);
-
- _logger.info("Adding protocol exclusion " + excludeArg + " " + excludedPort);
- }
- }
-
- protected String getProtocolExcludesList(int port, int sslPort)
- {
- return System.getProperty(BROKER_PROTOCOL_EXCLUDES,"").replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort);
- }
-
- private String getProtocolIncludesList(int port, int sslPort)
- {
- return System.getProperty(BROKER_PROTOCOL_INCLUDES, "").replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort);
- }
-
- private void addIncludedPorts(int port, int sslPort, BrokerOptions options)
- {
- final String protocolIncludesList = getProtocolIncludesList(port, sslPort);
-
- if (protocolIncludesList.equals(""))
- {
- return;
- }
- final String[] toks = protocolIncludesList.split("\\s");
-
- if(toks.length % 2 != 0)
- {
- throw new IllegalArgumentException("Must be an even number of tokens in '" + protocolIncludesList + "'");
- }
- for (int i = 0; i < toks.length; i=i+2)
- {
- String includeArg = toks[i];
- final int includedPort = Integer.parseInt(toks[i+1]);
- options.addIncludedPort(ProtocolInclusion.lookup(includeArg), includedPort);
-
- _logger.info("Adding protocol inclusion " + includeArg + " " + includedPort);
+ _brokers.put(port, holder);
}
}
@@ -620,7 +611,7 @@ public class QpidBrokerTestCase extends QpidTestCase
public String getTestConfigFile(int port)
{
- return _output + "/" + getTestQueueName() + "-" + port + "-config.xml";
+ return _output + "/" + getTestQueueName() + "-" + port + "-config";
}
public String getTestVirtualhostsFile(int port)
@@ -633,44 +624,33 @@ public class QpidBrokerTestCase extends QpidTestCase
return file.replace(System.getProperty(QPID_HOME,"QPID_HOME") + "/","");
}
- protected void saveTestConfiguration() throws ConfigurationException
+ protected String getPathRelativeToWorkingDirectory(String file)
{
- String relative = saveTestConfiguration(getPort(), _testConfiguration);
- _logger.info("Set test.config property to: " + relative);
- setSystemProperty(TEST_CONFIG, relative);
+ File configLocation = new File(file);
+ File workingDirectory = new File(System.getProperty("user.dir"));
+ return configLocation.getAbsolutePath().replace(workingDirectory.getAbsolutePath(), "").substring(1);
}
- protected String saveTestConfiguration(int port, XMLConfiguration testConfiguration) throws ConfigurationException
+ protected String saveTestConfiguration(int port, TestBrokerConfiguration testConfiguration)
{
- // Specify the test config file
String testConfig = getTestConfigFile(port);
- String relative = relativeToQpidHome(testConfig);
-
- _logger.info("Saving test virtualhosts file at: " + testConfig);
-
- // Create the file if configuration does not exist
- if (testConfiguration.isEmpty())
+ String relative = getPathRelativeToWorkingDirectory(testConfig);
+ if (!testConfiguration.isSaved())
{
- testConfiguration.addProperty("__ignore", "true");
+ _logger.info("Saving test broker configuration at: " + testConfig);
+ testConfiguration.save(new File(testConfig));
+ testConfiguration.setSaved(true);
}
- testConfiguration.save(testConfig);
return relative;
}
- protected void saveTestVirtualhosts() throws ConfigurationException
- {
- String relative = saveTestVirtualhosts(getPort(), _testVirtualhosts);
- _logger.info("Set test.virtualhosts property to: " + relative);
- setSystemProperty(TEST_VIRTUALHOSTS, relative);
- }
-
protected String saveTestVirtualhosts(int port, XMLConfiguration virtualHostConfiguration) throws ConfigurationException
{
// Specify the test virtualhosts file
String testVirtualhosts = getTestVirtualhostsFile(port);
String relative = relativeToQpidHome(testVirtualhosts);
- _logger.info("Set test.virtualhosts property to: " + testVirtualhosts);
+ _logger.info("Path to virtualhosts configuration: " + testVirtualhosts);
// Create the file if configuration does not exist
if (virtualHostConfiguration.isEmpty())
@@ -818,57 +798,41 @@ public class QpidBrokerTestCase extends QpidTestCase
}
/**
- * Attempt to set the Java Broker to use the BDBMessageStore for persistence
- * Falling back to the DerbyMessageStore if
- *
- * @param virtualhost - The virtualhost to modify
+ * Creates a new virtual host within the test virtualhost file.
+ * @param brokerPort broker port
+ * @param virtualHostName virtual host name
*
- * @throws ConfigurationException - when reading/writing existing configuration
- * @throws IOException - When creating a temporary file.
+ * @throws ConfigurationException
*/
- protected void makeVirtualHostPersistent(String virtualhost)
- throws ConfigurationException, IOException
+ protected void createTestVirtualHost(int brokerPort, String virtualHostName) throws ConfigurationException
{
- Class<?> storeClass = null;
- try
+ String storeClassName = getTestProfileMessageStoreClassName();
+
+ _testVirtualhosts.setProperty("virtualhost.name(-1)", virtualHostName);
+ _testVirtualhosts.setProperty("virtualhost." + virtualHostName + ".store.class", storeClassName);
+
+ String storeDir = null;
+
+ if (System.getProperty("profile", "").startsWith("java-dby-mem"))
{
- // Try and lookup the BDB class
- storeClass = Class.forName("org.apache.qpid.server.store.berkeleydb.BDBMessageStore");
+ storeDir = DerbyMessageStore.MEMORY_STORE_LOCATION;
}
- catch (ClassNotFoundException e)
+ else if (!MEMORY_STORE_CLASS_NAME.equals(storeClassName))
{
- // No BDB store, we'll use Derby instead.
- storeClass = DerbyMessageStore.class;
+ storeDir = "${QPID_WORK}" + File.separator + virtualHostName + "-store";
}
+ if (storeDir != null)
+ {
+ _testVirtualhosts.setProperty("virtualhost." + virtualHostName + ".store." + MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY, storeDir);
+ }
- setConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".store.class",
- storeClass.getName());
- setConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".store." + MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY,
- "${QPID_WORK}/" + virtualhost);
- }
-
- /**
- * Get a property value from the current configuration file.
- *
- * @param property the property to lookup
- *
- * @return the requested String Value
- *
- * @throws org.apache.commons.configuration.ConfigurationException
- *
- */
- protected String getConfigurationStringProperty(String property) throws ConfigurationException
- {
- // Call save Configuration to be sure we have saved the test specific
- // file. As the optional status
- saveTestConfiguration();
- saveTestVirtualhosts();
-
- ServerConfiguration configuration = new ServerConfiguration(_configFile);
- // Don't need to configuration.configure() here as we are just pulling
- // values directly by String.
- return configuration.getConfig().getString(property);
+ // add new virtual host configuration to the broker store
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(VirtualHost.NAME, virtualHostName);
+ attributes.put(VirtualHost.CONFIG_PATH, System.getProperty("broker.virtualhosts-config"));
+ int port = getPort(brokerPort);
+ getBrokerConfiguration(port).addHostConfiguration(attributes);
}
/**
@@ -884,10 +848,8 @@ public class QpidBrokerTestCase extends QpidTestCase
* @param value the new value
*
* @throws ConfigurationException when loading the current config file
- * @throws IOException when writing the new config file
*/
- public void setConfigurationProperty(String property, String value)
- throws ConfigurationException, IOException
+ public void setVirtualHostConfigurationProperty(String property, String value) throws ConfigurationException
{
// Choose which file to write the property to based on prefix.
if (property.startsWith("virtualhosts"))
@@ -896,7 +858,7 @@ public class QpidBrokerTestCase extends QpidTestCase
}
else
{
- _testConfiguration.setProperty(property, value);
+ throw new ConfigurationException("Cannot set broker configuration as property");
}
}
@@ -914,11 +876,13 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setBrokerOnlySystemProperty(String property, String value)
{
- if (!_propertiesSetForBroker.containsKey(property))
+ synchronized (_propertiesSetForBroker)
{
- _propertiesSetForBroker.put(property, value);
+ if (!_propertiesSetForBroker.containsKey(property))
+ {
+ _propertiesSetForBroker.put(property, value);
+ }
}
-
}
/**
@@ -931,7 +895,11 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setSystemProperty(String property)
{
- setSystemProperty(property, System.getProperty(property));
+ String value = System.getProperty(property);
+ if (value != null)
+ {
+ setSystemProperty(property, value);
+ }
}
/**
@@ -939,7 +907,7 @@ public class QpidBrokerTestCase extends QpidTestCase
*
* When the test run is complete the value will be reverted.
*
- * The values set using this method will also be propogated to the external
+ * The values set using this method will also be propagated to the external
* Java Broker via a -D value defined in QPID_OPTS.
*
* If the value should not be set on the broker then use
@@ -950,9 +918,18 @@ public class QpidBrokerTestCase extends QpidTestCase
*/
protected void setSystemProperty(String property, String value)
{
- // Record the value for the external broker
- _propertiesSetForBroker.put(property, value);
-
+ synchronized(_propertiesSetForBroker)
+ {
+ // Record the value for the external broker
+ if (value == null)
+ {
+ _propertiesSetForBroker.remove(property);
+ }
+ else
+ {
+ _propertiesSetForBroker.put(property, value);
+ }
+ }
//Set the value for the test client vm aswell.
setTestClientSystemProperty(property, value);
}
@@ -1073,7 +1050,7 @@ public class QpidBrokerTestCase extends QpidTestCase
_logger.info("get ConnectionFactory");
if (_connectionFactory == null)
{
- if (Boolean.getBoolean("profile.use_ssl"))
+ if (Boolean.getBoolean(PROFILE_USE_SSL))
{
_connectionFactory = getConnectionFactory("default.ssl");
}
@@ -1092,7 +1069,7 @@ public class QpidBrokerTestCase extends QpidTestCase
*
* @return A connection factory
*
- * @throws Exception if there is an error getting the tactory
+ * @throws Exception if there is an error getting the factory
*/
public AMQConnectionFactory getConnectionFactory(String factoryName) throws NamingException
{
@@ -1104,6 +1081,22 @@ public class QpidBrokerTestCase extends QpidTestCase
return getConnection(GUEST_USERNAME, GUEST_PASSWORD);
}
+ public Connection getConnectionWithOptions(Map<String, String> options)
+ throws URLSyntaxException, NamingException, JMSException
+ {
+ ConnectionURL curl = new AMQConnectionURL(getConnectionFactory().getConnectionURLString());
+ for(Map.Entry<String,String> entry : options.entrySet())
+ {
+ curl.setOption(entry.getKey(), entry.getValue());
+ }
+ curl = new AMQConnectionURL(curl.toString());
+
+ curl.setUsername(GUEST_USERNAME);
+ curl.setPassword(GUEST_PASSWORD);
+ return getConnection(curl);
+ }
+
+
public Connection getConnection(ConnectionURL url) throws JMSException
{
_logger.info(url.getURL());
@@ -1363,11 +1356,6 @@ public class QpidBrokerTestCase extends QpidTestCase
_messageSize = byteSize;
}
- public ConnectionURL getConnectionURL() throws NamingException
- {
- return getConnectionFactory().getConnectionURL();
- }
-
public BrokerDetails getBroker()
{
try
@@ -1390,31 +1378,6 @@ public class QpidBrokerTestCase extends QpidTestCase
return null;
}
- /**
- * Reloads the broker security configuration using the ApplicationRegistry (InVM brokers) or the
- * ConfigurationManagementMBean via the JMX interface (Standalone brokers, management must be
- * enabled before calling the method).
- */
- public void reloadBrokerSecurityConfig() throws Exception
- {
- JMXTestUtils jmxu = new JMXTestUtils(this);
- jmxu.open();
-
- try
- {
- ConfigurationManagement configMBean = jmxu.getConfigurationManagement();
- configMBean.reloadSecurityConfiguration();
- }
- finally
- {
- jmxu.close();
- }
-
- LogMonitor _monitor = new LogMonitor(_outputFile);
- assertTrue("The expected server security configuration reload did not occur",
- _monitor.waitForMessage(ServerConfiguration.SECURITY_CONFIG_RELOADED, LOGMONITOR_TIMEOUT));
- }
-
protected int getFailingPort()
{
return FAILING_PORT;
@@ -1430,13 +1393,14 @@ public class QpidBrokerTestCase extends QpidTestCase
_testVirtualhosts = testVirtualhosts;
}
- public XMLConfiguration getTestConfiguration()
+ public String getTestProfileMessageStoreType()
{
- return _testConfiguration;
+ final String storeClass = getTestProfileMessageStoreClassName();
+ if (storeClass == null)
+ {
+ return MemoryMessageStore.TYPE;
+ }
+ return supportedStoresClassToTypeMapping.get(storeClass);
}
- public void setTestConfiguration(XMLConfiguration testConfiguration)
- {
- _testConfiguration = testConfiguration;
- }
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidClientConnectionHelper.java b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidClientConnectionHelper.java
deleted file mode 100644
index 72003ed7d7..0000000000
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidClientConnectionHelper.java
+++ /dev/null
@@ -1,295 +0,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.
- *
- */
-
-package org.apache.qpid.test.utils;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.client.JMSAMQException;
-import org.apache.qpid.url.URLSyntaxException;
-
-import javax.jms.Connection;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-/**
- * @todo This was originally cut and paste from the client module leading to a duplicate class, then altered very
- * slightly. To avoid the duplicate class the name was altered slightly to have 'Helper' on the end in order
- * to distinguish it from the original. Delete this class and use the original instead, just upgrade it to
- * provide the new features needed.
- */
-public class QpidClientConnectionHelper implements ExceptionListener
-{
-
- private static final Logger _logger = Logger.getLogger(QpidClientConnectionHelper.class);
-
- private boolean transacted = true;
- private int ackMode = Session.CLIENT_ACKNOWLEDGE;
- private Connection connection;
-
- private String virtualHost;
- private String brokerlist;
- private int prefetch;
- protected Session session;
- protected boolean connected;
-
- public QpidClientConnectionHelper(String broker)
- {
- super();
- setVirtualHost("/test");
- setBrokerList(broker);
- setPrefetch(5000);
- }
-
- public void connect() throws JMSException
- {
- if (!connected)
- {
- /*
- * amqp://[user:pass@][clientid]/virtualhost?
- * brokerlist='[transport://]host[:port][?option='value'[&option='value']];'
- * [&failover='method[?option='value'[&option='value']]']
- * [&option='value']"
- */
- String brokerUrl = "amqp://guest:guest@" + virtualHost + "?brokerlist='" + brokerlist + "'";
- try
- {
- AMQConnectionFactory factory = new AMQConnectionFactory(new AMQConnectionURL(brokerUrl));
- _logger.info("connecting to Qpid :" + brokerUrl);
- connection = factory.createConnection();
-
- // register exception listener
- connection.setExceptionListener(this);
-
- session = ((AMQConnection) connection).createSession(transacted, ackMode, prefetch);
-
- _logger.info("starting connection");
- connection.start();
-
- connected = true;
- }
- catch (URLSyntaxException e)
- {
- throw new JMSAMQException("URL syntax error in [" + brokerUrl + "]: " + e.getMessage(), e);
- }
- }
- }
-
- public void disconnect() throws JMSException
- {
- if (connected)
- {
- session.commit();
- session.close();
- connection.close();
- connected = false;
- _logger.info("disconnected");
- }
- }
-
- public void disconnectWithoutCommit() throws JMSException
- {
- if (connected)
- {
- session.close();
- connection.close();
- connected = false;
- _logger.info("disconnected without commit");
- }
- }
-
- public String getBrokerList()
- {
- return brokerlist;
- }
-
- public void setBrokerList(String brokerlist)
- {
- this.brokerlist = brokerlist;
- }
-
- public String getVirtualHost()
- {
- return virtualHost;
- }
-
- public void setVirtualHost(String virtualHost)
- {
- this.virtualHost = virtualHost;
- }
-
- public void setPrefetch(int prefetch)
- {
- this.prefetch = prefetch;
- }
-
- /** override as necessary */
- public void onException(JMSException exception)
- {
- _logger.info("ExceptionListener event: error " + exception.getErrorCode() + ", message: " + exception.getMessage());
- }
-
- public boolean isConnected()
- {
- return connected;
- }
-
- public Session getSession()
- {
- return session;
- }
-
- /**
- * Put a String as a text messages, repeat n times. A null payload will result in a null message.
- *
- * @param queueName The queue name to put to
- * @param payload the content of the payload
- * @param copies the number of messages to put
- *
- * @throws javax.jms.JMSException any exception that occurs
- */
- public void put(String queueName, String payload, int copies, int deliveryMode) throws JMSException
- {
- if (!connected)
- {
- connect();
- }
-
- _logger.info("putting to queue " + queueName);
- Queue queue = session.createQueue(queueName);
-
- final MessageProducer sender = session.createProducer(queue);
-
- sender.setDeliveryMode(deliveryMode);
-
- for (int i = 0; i < copies; i++)
- {
- Message m = session.createTextMessage(payload + i);
- m.setIntProperty("index", i + 1);
- sender.send(m);
- }
-
- session.commit();
- sender.close();
- _logger.info("put " + copies + " copies");
- }
-
- /**
- * GET the top message on a queue. Consumes the message. Accepts timeout value.
- *
- * @param queueName The quename to get from
- * @param readTimeout The timeout to use
- *
- * @return the content of the text message if any
- *
- * @throws javax.jms.JMSException any exception that occured
- */
- public Message getNextMessage(String queueName, long readTimeout) throws JMSException
- {
- if (!connected)
- {
- connect();
- }
-
- Queue queue = session.createQueue(queueName);
-
- final MessageConsumer consumer = session.createConsumer(queue);
-
- Message message = consumer.receive(readTimeout);
- session.commit();
- consumer.close();
-
- Message result;
-
- // all messages we consume should be TextMessages
- if (message instanceof TextMessage)
- {
- result = ((TextMessage) message);
- }
- else if (null == message)
- {
- result = null;
- }
- else
- {
- _logger.info("warning: received non-text message");
- result = message;
- }
-
- return result;
- }
-
- /**
- * GET the top message on a queue. Consumes the message.
- *
- * @param queueName The Queuename to get from
- *
- * @return The string content of the text message, if any received
- *
- * @throws javax.jms.JMSException any exception that occurs
- */
- public Message getNextMessage(String queueName) throws JMSException
- {
- return getNextMessage(queueName, 0);
- }
-
- /**
- * Completely clears a queue. For readTimeout behaviour see Javadocs for javax.jms.MessageConsumer.
- *
- * @param queueName The Queue name to consume from
- * @param readTimeout The timeout for each consume
- *
- * @throws javax.jms.JMSException Any exception that occurs during the consume
- * @throws InterruptedException If the consume thread was interrupted during a consume.
- */
- public void consume(String queueName, int readTimeout) throws JMSException, InterruptedException
- {
- if (!connected)
- {
- connect();
- }
-
- _logger.info("consuming queue " + queueName);
- Queue queue = session.createQueue(queueName);
-
- final MessageConsumer consumer = session.createConsumer(queue);
- int messagesReceived = 0;
-
- _logger.info("consuming...");
- while ((consumer.receive(readTimeout)) != null)
- {
- messagesReceived++;
- }
-
- session.commit();
- consumer.close();
- _logger.info("consumed: " + messagesReceived);
- }
-}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java b/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
new file mode 100644
index 0000000000..80f8010678
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
@@ -0,0 +1,219 @@
+/*
+ *
+ * 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.test.utils;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore;
+import org.apache.qpid.server.model.AuthenticationProvider;
+import org.apache.qpid.server.model.Plugin;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.plugin.PluginFactory;
+
+public class TestBrokerConfiguration
+{
+ public static final String ENTRY_NAME_HTTP_PORT = "http";
+ public static final String ENTRY_NAME_AMQP_PORT = "amqp";
+ public static final String ENTRY_NAME_RMI_PORT = "rmi";
+ public static final String ENTRY_NAME_JMX_PORT = "jmx";
+ public static final String ENTRY_NAME_VIRTUAL_HOST = "test";
+ public static final String ENTRY_NAME_AUTHENTICATION_PROVIDER = "plain";
+ public static final String ENTRY_NAME_EXTERNAL_PROVIDER = "external";
+ public static final String ENTRY_NAME_SSL_PORT = "sslPort";
+ public static final String ENTRY_NAME_HTTP_MANAGEMENT = "MANAGEMENT-HTTP";
+ public static final String MANAGEMENT_HTTP_PLUGIN_TYPE = "MANAGEMENT-HTTP";
+ public static final String ENTRY_NAME_JMX_MANAGEMENT = "MANAGEMENT-JMX";
+ public static final String MANAGEMENT_JMX_PLUGIN_TYPE = "MANAGEMENT-JMX";
+ public static final String ENTRY_NAME_ANONYMOUS_PROVIDER = "anonymous";
+
+ private JsonConfigurationEntryStore _store;
+ private boolean _saved;
+
+ public TestBrokerConfiguration(String storeType, String intialStoreLocation)
+ {
+ // TODO: add support for DERBY store
+ _store = new JsonConfigurationEntryStore();
+ _store.open(JsonConfigurationEntryStore.IN_MEMORY, intialStoreLocation);
+ }
+
+ public boolean setBrokerAttribute(String name, Object value)
+ {
+ return setObjectAttribute(_store.getRootEntry(), name, value);
+ }
+
+ public boolean setObjectAttribute(String objectName, String attributeName, Object value)
+ {
+ ConfigurationEntry entry = findObjectByName(objectName);
+ if (entry == null)
+ {
+ return false;
+ }
+ return setObjectAttribute(entry, attributeName, value);
+ }
+
+ public boolean setObjectAttributes(String objectName, Map<String, Object> attributes)
+ {
+ ConfigurationEntry entry = findObjectByName(objectName);
+ if (entry == null)
+ {
+ return false;
+ }
+ return setObjectAttributes(entry, attributes);
+ }
+
+ public boolean save(File configFile)
+ {
+ _store.copyTo(configFile.getAbsolutePath());
+ return true;
+ }
+
+ public UUID[] removeObjectConfiguration(String name)
+ {
+ ConfigurationEntry entry = findObjectByName(name);
+ if (entry != null)
+ {
+ return _store.remove(entry.getId());
+ }
+ return null;
+ }
+
+ public UUID addObjectConfiguration(String name, String type, Map<String, Object> attributes)
+ {
+ UUID id = UUIDGenerator.generateBrokerChildUUID(type, name);
+ addObjectConfiguration(id, type, attributes);
+ return id;
+ }
+
+ public UUID addJmxManagementConfiguration()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(PluginFactory.PLUGIN_TYPE, MANAGEMENT_JMX_PLUGIN_TYPE);
+ attributes.put(Plugin.NAME, ENTRY_NAME_JMX_MANAGEMENT);
+ return addObjectConfiguration(ENTRY_NAME_JMX_MANAGEMENT, Plugin.class.getSimpleName(), attributes);
+ }
+
+ public UUID addHttpManagementConfiguration()
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(PluginFactory.PLUGIN_TYPE, MANAGEMENT_HTTP_PLUGIN_TYPE);
+ attributes.put(Plugin.NAME, ENTRY_NAME_HTTP_MANAGEMENT);
+ return addObjectConfiguration(ENTRY_NAME_HTTP_MANAGEMENT, Plugin.class.getSimpleName(), attributes);
+ }
+
+ public UUID addPortConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(Port.NAME);
+ return addObjectConfiguration(name, Port.class.getSimpleName(), attributes);
+ }
+
+ public UUID addHostConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(VirtualHost.NAME);
+ return addObjectConfiguration(name, VirtualHost.class.getSimpleName(), attributes);
+ }
+
+ public UUID addAuthenticationProviderConfiguration(Map<String, Object> attributes)
+ {
+ String name = (String) attributes.get(AuthenticationProvider.NAME);
+ return addObjectConfiguration(name, AuthenticationProvider.class.getSimpleName(), attributes);
+ }
+
+ private boolean setObjectAttributes(ConfigurationEntry entry, Map<String, Object> attributes)
+ {
+ Map<String, Object> newAttributes = new HashMap<String, Object>(entry.getAttributes());
+ newAttributes.putAll(attributes);
+ ConfigurationEntry newEntry = new ConfigurationEntry(entry.getId(), entry.getType(), newAttributes,
+ entry.getChildrenIds(), _store);
+ _store.save(newEntry);
+ return true;
+ }
+
+ private ConfigurationEntry findObjectByName(String objectName)
+ {
+ ConfigurationEntry root = _store.getRootEntry();
+ return findObjectByName(root, objectName);
+ }
+
+ private ConfigurationEntry findObjectByName(ConfigurationEntry entry, String objectName)
+ {
+ Map<String, Object> attributes = entry.getAttributes();
+ if (attributes != null)
+ {
+ String name = (String) attributes.get("name");
+ if (objectName.equals(name))
+ {
+ return entry;
+ }
+ }
+ Set<UUID> childrenIds = entry.getChildrenIds();
+ for (UUID uuid : childrenIds)
+ {
+ ConfigurationEntry child = _store.getEntry(uuid);
+ ConfigurationEntry result = findObjectByName(child, objectName);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ private void addObjectConfiguration(UUID id, String type, Map<String, Object> attributes)
+ {
+ ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), _store);
+ ConfigurationEntry root = _store.getRootEntry();
+ Set<UUID> childrenIds = new HashSet<UUID>(root.getChildrenIds());
+ childrenIds.add(id);
+ ConfigurationEntry newRoot = new ConfigurationEntry(root.getId(), root.getType(), root.getAttributes(), childrenIds,
+ _store);
+ _store.save(newRoot, entry);
+ }
+
+ private boolean setObjectAttribute(ConfigurationEntry entry, String attributeName, Object value)
+ {
+ Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes());
+ attributes.put(attributeName, value);
+ ConfigurationEntry newEntry = new ConfigurationEntry(entry.getId(), entry.getType(), attributes, entry.getChildrenIds(),
+ _store);
+ _store.save(newEntry);
+ return true;
+ }
+
+ public boolean isSaved()
+ {
+ return _saved;
+ }
+
+ public void setSaved(boolean saved)
+ {
+ _saved = saved;
+ }
+
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java b/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java
new file mode 100644
index 0000000000..9d5be775dc
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java
@@ -0,0 +1,30 @@
+/*
+ * 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.test.utils;
+
+public interface TestSSLConstants
+{
+ String KEYSTORE = "test-profiles/test_resources/ssl/java_client_keystore.jks";
+ String KEYSTORE_PASSWORD = "password";
+ String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks";
+ String TRUSTSTORE_PASSWORD = "password";
+
+ String BROKER_KEYSTORE = "test-profiles/test_resources/ssl/java_broker_keystore.jks";
+ String BROKER_KEYSTORE_PASSWORD = "password";
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/TestUtils.java b/java/systests/src/main/java/org/apache/qpid/test/utils/TestUtils.java
new file mode 100644
index 0000000000..c651d3ec7f
--- /dev/null
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/TestUtils.java
@@ -0,0 +1,54 @@
+/*
+ *
+ * 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.test.utils;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+public class TestUtils
+{
+ public static String dumpThreads()
+ {
+ ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
+ ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true);
+ StringBuilder dump = new StringBuilder();
+ dump.append(String.format("%n"));
+ for (ThreadInfo threadInfo : threadInfos)
+ {
+ dump.append(threadInfo);
+ }
+
+ long[] deadLocks = threadMXBean.findDeadlockedThreads();
+ if (deadLocks != null && deadLocks.length > 0)
+ {
+ ThreadInfo[] deadlockedThreads = threadMXBean.getThreadInfo(deadLocks);
+ dump.append(String.format("%n"));
+ dump.append("Deadlock is detected!");
+ dump.append(String.format("%n"));
+ for (ThreadInfo threadInfo : deadlockedThreads)
+ {
+ dump.append(threadInfo);
+ }
+ }
+ return dump.toString();
+ }
+}
diff --git a/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java b/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
index 2b99289cd1..d77731d09f 100644
--- a/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
+++ b/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
@@ -30,8 +30,10 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
/**
* Utility to simplify the monitoring of Log4j file output
@@ -42,6 +44,8 @@ import java.util.List;
*/
public class LogMonitor
{
+ private static final Logger _logger = Logger.getLogger(LogMonitor.class);
+
// The file that the log statements will be written to.
private final File _logfile;
@@ -90,6 +94,8 @@ public class LogMonitor
_appender.setImmediateFlush(true);
Logger.getRootLogger().addAppender(_appender);
}
+
+ _logger.info("Created LogMonitor. Monitoring file: " + _logfile.getAbsolutePath());
}
/**
@@ -156,6 +162,39 @@ public class LogMonitor
return results;
}
+ public Map<String, List<String>> findMatches(String... pattern) throws IOException
+ {
+
+ Map<String, List<String>> results= new HashMap<String, List<String>>();
+ for (String p : pattern)
+ {
+ results.put(p, new LinkedList<String>());
+ }
+ LineNumberReader reader = new LineNumberReader(new FileReader(_logfile));
+ try
+ {
+ while (reader.ready())
+ {
+ String line = reader.readLine();
+ if (reader.getLineNumber() > _linesToSkip)
+ {
+ for (String p : pattern)
+ {
+ if (line.contains(p))
+ {
+ results.get(p).add(line);
+ }
+ }
+ }
+ }
+ }
+ finally
+ {
+ reader.close();
+ }
+
+ return results;
+ }
/**
* Checks the log file for a given message to appear. If the caller
* has previously called {@link #markDiscardPoint()}, lines up until the discard
diff --git a/java/test-profiles/CPPExcludes b/java/test-profiles/CPPExcludes
index 018ced4a68..8b74a19b8e 100755
--- a/java/test-profiles/CPPExcludes
+++ b/java/test-profiles/CPPExcludes
@@ -23,8 +23,6 @@ org.apache.qpid.test.client.destination.AddressBasedDestinationTest#testCreateEx
// QPID-3576: Java client issue. MessageConsumer#close() time-out.
org.apache.qpid.test.client.destination.AddressBasedDestinationTest#testDeleteOptions
-org.apache.qpid.test.unit.client.channelclose.ChannelCloseTest#*
-
// Those tests are testing 0.8 specific semantics
org.apache.qpid.test.client.ImmediateAndMandatoryPublishingTest#*
@@ -128,17 +126,8 @@ org.apache.qpid.client.failover.AddressBasedFailoverBehaviourTest#testFlowContro
org.apache.qpid.test.client.RollbackOrderTest#testOrderingAfterRollbackOnMessage#*
-//Excluded due to QPID-1447 : CPP broker does not have SlowConsumer Disconnection
-org.apache.qpid.systest.GlobalQueuesTest#*
-org.apache.qpid.systest.GlobalTopicsTest#*
-org.apache.qpid.systest.MergeConfigurationTest#*
-org.apache.qpid.systest.SubscriptionTest#*
-org.apache.qpid.systest.TopicTest#*
-
// Excluded because Java plugins not used in CPP broker
org.apache.qpid.server.virtualhost.plugin.*
-org.apache.qpid.server.virtualhost.plugin.policies.*
-org.apache.qpid.info.systest.InfoPluginTest#*
org.apache.qpid.info.test.*
org.apache.qpid.server.security.access.*
org.apache.qpid.server.security.access.plugins.*
@@ -182,4 +171,15 @@ org.apache.qpid.systest.disttest.*
org.apache.qpid.disttest.*
// Exclude java broker REST API tests
-org.apache.qpid.server.management.plugin.servlet.rest.*
+org.apache.qpid.systest.rest.*
+org.apache.qpid.systest.rest.acl.*
+
+// Exclude failover tests requiring virtual host functionality
+org.apache.qpid.client.failover.MultipleBrokersFailoverTest#*
+
+// Uses Java broker specific configuration
+org.apache.qpid.client.ssl.SSLTest#testClientCertMissingWhilstWanting
+
+// QPID-2796 : Java 0-10 client only sends heartbeats in response to heartbeats from the server, not timeout based
+org.apache.qpid.client.HeartbeatTest#testReadOnlyConnectionHeartbeats
+
diff --git a/java/test-profiles/Excludes b/java/test-profiles/Excludes
index c0532e0b97..9c07fea574 100644
--- a/java/test-profiles/Excludes
+++ b/java/test-profiles/Excludes
@@ -30,4 +30,3 @@ org.apache.qpid.server.logging.MemoryMessageStoreLoggingTest#testMessageStoreClo
org.apache.qpid.server.logging.DerbyMessageStoreLoggingTest#*
org.apache.qpid.client.ssl.SSLTest#testVerifyLocalHostLocalDomain
-
diff --git a/java/test-profiles/Java010Excludes b/java/test-profiles/Java010Excludes
index ca2383a8f3..c4b3ac8d66 100755
--- a/java/test-profiles/Java010Excludes
+++ b/java/test-profiles/Java010Excludes
@@ -37,9 +37,6 @@ org.apache.qpid.test.unit.close.JavaServerCloseRaceConditionTest#*
//QPID-1864: rollback with subscriptions does not work in 0-10 yet
org.apache.qpid.test.client.RollbackOrderTest#testOrderingAfterRollbackOnMessage
-// This test uses 0-8 channel frames
-org.apache.qpid.test.unit.client.channelclose.ChannelCloseTest#*
-
//QPID-3422: test fails because ring queue is not implemented on java broker
org.apache.qpid.test.client.destination.AddressBasedDestinationTest#testBrowseMode
@@ -64,3 +61,6 @@ org.apache.qpid.client.failover.AddressBasedFailoverBehaviourTest#testFlowContro
// QPID-3604: Immediate Prefetch no longer supported by 0-10
org.apache.qpid.client.AsynchMessageListenerTest#testImmediatePrefetchWithMessageListener
+
+// QPID-2796 : Java 0-10 client only sends heartbeats in response to heartbeats from the server, not timeout based
+org.apache.qpid.client.HeartbeatTest#testReadOnlyConnectionHeartbeats
diff --git a/java/test-profiles/JavaTransientExcludes b/java/test-profiles/JavaTransientExcludes
index e7b423ef34..2f96584589 100644
--- a/java/test-profiles/JavaTransientExcludes
+++ b/java/test-profiles/JavaTransientExcludes
@@ -20,6 +20,8 @@
//These tests require a persistent store
org.apache.qpid.server.persistent.NoLocalAfterRecoveryTest#*
org.apache.qpid.server.store.PersistentStoreTest#*
+org.apache.qpid.server.logging.AlertingTest#testAlertingReallyWorksWithRestart
+org.apache.qpid.server.logging.AlertingTest#testAlertingReallyWorksWithChanges
org.apache.qpid.test.unit.ack.ClientAcknowledgeTest#testClientAckWithLargeFlusherPeriod
org.apache.qpid.test.unit.ct.DurableSubscriberTest#*
diff --git a/java/test-profiles/cpp.ssl.excludes b/java/test-profiles/cpp.ssl.excludes
index 14c8ac2fe3..3d7b929831 100644
--- a/java/test-profiles/cpp.ssl.excludes
+++ b/java/test-profiles/cpp.ssl.excludes
@@ -17,8 +17,6 @@
// under the License.
//
-#org.apache.qpid.test.client.failover.FailoverTest#*
-
//This test does not supply a client keystore, therefore it cant login to the C++ broker
//in this test profile as it demands client certificate authentication
org.apache.qpid.client.ssl.SSLTest#testCreateSSLConnectionUsingConnectionURLParamsTrustStoreOnly
diff --git a/java/test-profiles/java-bdb-spawn.0-10.testprofile b/java/test-profiles/java-bdb-spawn.0-10.testprofile
index 35991645d8..78ab05a179 100644
--- a/java/test-profiles/java-bdb-spawn.0-10.testprofile
+++ b/java/test-profiles/java-bdb-spawn.0-10.testprofile
@@ -19,11 +19,11 @@
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes Java010Excludes JavaBDBExcludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-bdb-spawn.0-8.testprofile b/java/test-profiles/java-bdb-spawn.0-8.testprofile
index a4b74748e6..7f6efcbc3d 100644
--- a/java/test-profiles/java-bdb-spawn.0-8.testprofile
+++ b/java/test-profiles/java-bdb-spawn.0-8.testprofile
@@ -19,15 +19,15 @@
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
broker.version=v0_8
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/java/test-profiles/java-bdb-spawn.0-9-1.testprofile b/java/test-profiles/java-bdb-spawn.0-9-1.testprofile
index 9cd70a4ea7..28668b94f7 100644
--- a/java/test-profiles/java-bdb-spawn.0-9-1.testprofile
+++ b/java/test-profiles/java-bdb-spawn.0-9-1.testprofile
@@ -19,15 +19,15 @@
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
broker.version=v0_9_1
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/java/test-profiles/java-bdb-spawn.0-9.testprofile b/java/test-profiles/java-bdb-spawn.0-9.testprofile
index 5c0ad2baf3..aa8e6830d4 100644
--- a/java/test-profiles/java-bdb-spawn.0-9.testprofile
+++ b/java/test-profiles/java-bdb-spawn.0-9.testprofile
@@ -19,15 +19,15 @@
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
broker.version=v0_9
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/java/test-profiles/java-bdb.0-10.testprofile b/java/test-profiles/java-bdb.0-10.testprofile
index 892188aa24..8c4b145e0b 100644
--- a/java/test-profiles/java-bdb.0-10.testprofile
+++ b/java/test-profiles/java-bdb.0-10.testprofile
@@ -20,11 +20,11 @@
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes Java010Excludes JavaBDBExcludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-bdb.0-8.testprofile b/java/test-profiles/java-bdb.0-8.testprofile
index 87eea96dda..acf031040e 100644
--- a/java/test-profiles/java-bdb.0-8.testprofile
+++ b/java/test-profiles/java-bdb.0-8.testprofile
@@ -20,15 +20,15 @@
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
broker.version=v0_8
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/java/test-profiles/java-bdb.0-9-1.testprofile b/java/test-profiles/java-bdb.0-9-1.testprofile
index 1339dc1dc7..fa86720bbb 100644
--- a/java/test-profiles/java-bdb.0-9-1.testprofile
+++ b/java/test-profiles/java-bdb.0-9-1.testprofile
@@ -20,15 +20,15 @@
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
broker.version=v0_9_1
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/java/test-profiles/java-bdb.0-9.testprofile b/java/test-profiles/java-bdb.0-9.testprofile
index c097d53c85..ed3d7b2170 100644
--- a/java/test-profiles/java-bdb.0-9.testprofile
+++ b/java/test-profiles/java-bdb.0-9.testprofile
@@ -20,15 +20,15 @@
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-bdb.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-bdb.xml
messagestore.class.name=org.apache.qpid.server.store.berkeleydb.BDBMessageStore
profile.excludes=JavaExcludes JavaPersistentExcludes XAExcludes JavaPre010Excludes JavaBDBExcludes
broker.clean.between.tests=true
broker.persistent=true
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
broker.version=v0_9
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
diff --git a/java/test-profiles/java-dby-mem.0-10.testprofile b/java/test-profiles/java-dby-mem.0-10.testprofile
index 33f9527c86..bfe031b338 100644
--- a/java/test-profiles/java-dby-mem.0-10.testprofile
+++ b/java/test-profiles/java-dby-mem.0-10.testprofile
@@ -20,12 +20,12 @@ broker.language=java
broker.version=v0_10
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-derby-mem.xml
-messagestorefactory.class.name=org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml
+messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes Java010Excludes
broker.clean.between.tests=true
broker.persistent=true
diff --git a/java/test-profiles/java-dby-mem.0-8.testprofile b/java/test-profiles/java-dby-mem.0-8.testprofile
index 89bad84769..28bce8e434 100644
--- a/java/test-profiles/java-dby-mem.0-8.testprofile
+++ b/java/test-profiles/java-dby-mem.0-8.testprofile
@@ -20,12 +20,12 @@ broker.version=v0_8
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby-mem.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
-messagestorefactory.class.name=org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml
+messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
broker.persistent=true
diff --git a/java/test-profiles/java-dby-mem.0-9-1.testprofile b/java/test-profiles/java-dby-mem.0-9-1.testprofile
index 8deea281a4..0d2f82ebb5 100644
--- a/java/test-profiles/java-dby-mem.0-9-1.testprofile
+++ b/java/test-profiles/java-dby-mem.0-9-1.testprofile
@@ -20,12 +20,12 @@ broker.version=v0_9_1
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby-mem.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-messagestorefactory.class.name=org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml
+messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
broker.persistent=true
diff --git a/java/test-profiles/java-dby-mem.0-9.testprofile b/java/test-profiles/java-dby-mem.0-9.testprofile
index b691a7d153..4dd9fbb899 100644
--- a/java/test-profiles/java-dby-mem.0-9.testprofile
+++ b/java/test-profiles/java-dby-mem.0-9.testprofile
@@ -20,12 +20,12 @@ broker.version=v0_9
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby-mem.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
-messagestorefactory.class.name=org.apache.qpid.server.store.derby.DerbyMessageStoreFactory
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby-mem.xml
+messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
broker.persistent=true
diff --git a/java/test-profiles/java-dby-spawn.0-10.testprofile b/java/test-profiles/java-dby-spawn.0-10.testprofile
index e2e2b44dae..9795533b52 100644
--- a/java/test-profiles/java-dby-spawn.0-10.testprofile
+++ b/java/test-profiles/java-dby-spawn.0-10.testprofile
@@ -19,11 +19,11 @@
broker.language=java
broker.version=v0_10
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-derby.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes Java010Excludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-dby-spawn.0-8.testprofile b/java/test-profiles/java-dby-spawn.0-8.testprofile
index 3f609226e3..a980fd181d 100644
--- a/java/test-profiles/java-dby-spawn.0-8.testprofile
+++ b/java/test-profiles/java-dby-spawn.0-8.testprofile
@@ -19,11 +19,11 @@
broker.version=v0_8
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-dby-spawn.0-9-1.testprofile b/java/test-profiles/java-dby-spawn.0-9-1.testprofile
index 80d40458fd..04428b5021 100644
--- a/java/test-profiles/java-dby-spawn.0-9-1.testprofile
+++ b/java/test-profiles/java-dby-spawn.0-9-1.testprofile
@@ -19,11 +19,11 @@
broker.version=v0_9_1
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-dby-spawn.0-9.testprofile b/java/test-profiles/java-dby-spawn.0-9.testprofile
index 122eccdca1..4724eba660 100644
--- a/java/test-profiles/java-dby-spawn.0-9.testprofile
+++ b/java/test-profiles/java-dby-spawn.0-9.testprofile
@@ -19,11 +19,11 @@
broker.version=v0_9
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-dby.0-10.testprofile b/java/test-profiles/java-dby.0-10.testprofile
index d3b03054de..a2b1a41c31 100644
--- a/java/test-profiles/java-dby.0-10.testprofile
+++ b/java/test-profiles/java-dby.0-10.testprofile
@@ -20,11 +20,11 @@ broker.language=java
broker.version=v0_10
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
-broker.config=build/etc/config-systests-derby.xml
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes Java010Excludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-dby.0-8.testprofile b/java/test-profiles/java-dby.0-8.testprofile
index 51580e6c7a..509796331f 100644
--- a/java/test-profiles/java-dby.0-8.testprofile
+++ b/java/test-profiles/java-dby.0-8.testprofile
@@ -20,11 +20,11 @@ broker.version=v0_8
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-dby.0-9-1.testprofile b/java/test-profiles/java-dby.0-9-1.testprofile
index b92397eae7..be087a6344 100644
--- a/java/test-profiles/java-dby.0-9-1.testprofile
+++ b/java/test-profiles/java-dby.0-9-1.testprofile
@@ -20,11 +20,11 @@ broker.version=v0_9_1
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-dby.0-9.testprofile b/java/test-profiles/java-dby.0-9.testprofile
index 17363b7e47..3b5e586ba4 100644
--- a/java/test-profiles/java-dby.0-9.testprofile
+++ b/java/test-profiles/java-dby.0-9.testprofile
@@ -20,11 +20,11 @@ broker.version=v0_9
broker.language=java
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.config=build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests-derby.xml
messagestore.class.name=org.apache.qpid.server.store.derby.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaDerbyExcludes XAExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/java/test-profiles/java-mms-spawn.0-10.testprofile b/java/test-profiles/java-mms-spawn.0-10.testprofile
index 57af5c4a41..71aaf48562 100644
--- a/java/test-profiles/java-mms-spawn.0-10.testprofile
+++ b/java/test-profiles/java-mms-spawn.0-10.testprofile
@@ -19,10 +19,11 @@
broker.version=v0_10
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/java/test-profiles/java-mms-spawn.0-8.testprofile b/java/test-profiles/java-mms-spawn.0-8.testprofile
index 24f088e0c5..6365fa20f0 100644
--- a/java/test-profiles/java-mms-spawn.0-8.testprofile
+++ b/java/test-profiles/java-mms-spawn.0-8.testprofile
@@ -19,10 +19,11 @@
broker.version=v0_8
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/java/test-profiles/java-mms-spawn.0-9-1.testprofile b/java/test-profiles/java-mms-spawn.0-9-1.testprofile
index c1f6d10675..1eb4b00a1d 100644
--- a/java/test-profiles/java-mms-spawn.0-9-1.testprofile
+++ b/java/test-profiles/java-mms-spawn.0-9-1.testprofile
@@ -19,10 +19,11 @@
broker.version=v0_9_1
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/java/test-profiles/java-mms-spawn.0-9.testprofile b/java/test-profiles/java-mms-spawn.0-9.testprofile
index 421ae7476e..4ebce66c05 100644
--- a/java/test-profiles/java-mms-spawn.0-9.testprofile
+++ b/java/test-profiles/java-mms-spawn.0-9.testprofile
@@ -19,10 +19,11 @@
broker.version=v0_9
broker.language=java
broker.type=spawned
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/java/test-profiles/java-mms.0-10.testprofile b/java/test-profiles/java-mms.0-10.testprofile
index 6dd40cff47..0de5ffea09 100644
--- a/java/test-profiles/java-mms.0-10.testprofile
+++ b/java/test-profiles/java-mms.0-10.testprofile
@@ -20,9 +20,10 @@ broker.language=java
broker.version=v0_10
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
profile.excludes=JavaTransientExcludes Java010Excludes
diff --git a/java/test-profiles/java-mms.0-8.testprofile b/java/test-profiles/java-mms.0-8.testprofile
index f82bf8c473..dddad95157 100644
--- a/java/test-profiles/java-mms.0-8.testprofile
+++ b/java/test-profiles/java-mms.0-8.testprofile
@@ -20,10 +20,11 @@ broker.language=java
broker.version=v0_8
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT --exclude-0-9 @PORT --exclude-0-9 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1,AMQP_0_9
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/java/test-profiles/java-mms.0-9-1.testprofile b/java/test-profiles/java-mms.0-9-1.testprofile
index 9b8baaa5a3..3c2f68a2c9 100644
--- a/java/test-profiles/java-mms.0-9-1.testprofile
+++ b/java/test-profiles/java-mms.0-9-1.testprofile
@@ -20,10 +20,11 @@ broker.language=java
broker.version=v0_9_1
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/java/test-profiles/java-mms.0-9.testprofile b/java/test-profiles/java-mms.0-9.testprofile
index 56ace6d9e1..992168b044 100644
--- a/java/test-profiles/java-mms.0-9.testprofile
+++ b/java/test-profiles/java-mms.0-9.testprofile
@@ -20,10 +20,11 @@ broker.language=java
broker.version=v0_9
broker.type=internal
#broker.command only used for the second broker during failover tests in this profile
-broker.command=build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDES @INCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE
+broker.command=build/bin/qpid-server -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT --exclude-1-0 @PORT --exclude-1-0 @SSL_PORT --exclude-0-9-1 @PORT --exclude-0-9-1 @SSL_PORT
+qpid.broker_default_amqp_protocol_excludes=AMQP_1_0,AMQP_0_10,AMQP_0_9_1
+broker.virtualhosts-config=${QPID_HOME}/etc/virtualhosts-systests.xml
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/java/test-profiles/testprofile.defaults b/java/test-profiles/testprofile.defaults
index 47992b9334..033da12a97 100644
--- a/java/test-profiles/testprofile.defaults
+++ b/java/test-profiles/testprofile.defaults
@@ -20,7 +20,7 @@ java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFac
java.naming.provider.url=${test.profiles}/test-provider.properties
broker.ready=Listening on TCP
-broker.config=build/etc/config-systests.xml
+broker.config=build/etc/config-systests.json
messagestore.class.name=org.apache.qpid.server.store.MemoryMessageStore
broker.protocol.excludes=
broker.persistent=false
@@ -33,13 +33,20 @@ amqj.logging.level=${log}
amqj.server.logging.level=${log}
amqj.protocol.logging.level=${log}
root.logging.level=warn
-log4j.configuration=test-profiles/log4j-test.xml
+
+# System property log4j.configuration is used by log4j.
+# QpidBrokerTestCase uses log4j.configuration.file to construct a java.io.File, eg for log configuration of spawned brokers.
+log4j.configuration.file=${test.profiles}/log4j-test.xml
+log4j.configuration=file:///${log4j.configuration.file}
+
log4j.debug=false
# Note test-provider.properties also has variables of same name.
# Keep in sync
test.port=15672
test.mport=18999
+test.cport=19099
+test.hport=18080
#Note : Management will start open second port on: mport + 100 : 19099
test.port.ssl=15671
test.port.alt=25672
@@ -55,5 +62,7 @@ haltonerror=no
exclude.modules=none
profile.clustered=false
+broker.config-store-type=json
+broker.virtualhosts-config="${QPID_HOME}/etc/virtualhosts-systests.xml"
diff --git a/packaging/windows/INSTALL_NOTES.html b/packaging/windows/INSTALL_NOTES.html
index 66e8076767..54f427ed79 100644
--- a/packaging/windows/INSTALL_NOTES.html
+++ b/packaging/windows/INSTALL_NOTES.html
@@ -1,11 +1,11 @@
<html>
<head>
-<title>Apache Qpid C++ 0.19 Installation Notes</title>
+<title>Apache Qpid C++ 0.21 Installation Notes</title>
</head>
<body>
-<H1>Apache Qpid C++ 0.19 Installation Notes</H1>
+<H1>Apache Qpid C++ 0.21 Installation Notes</H1>
-<p>Thank you for installing Apache Qpid version 0.19 for Windows.
+<p>Thank you for installing Apache Qpid version 0.21 for Windows.
If the requisite features were installed, you can now run a broker,
use the example programs, and design your own messaging programs while
reading the Qpid C++ API reference documentation.</p>
@@ -83,7 +83,7 @@ default; therefore, to gain support for durable items the persistence plugin
must be loaded into the broker. This can be done using the
<code>--load-module</code> option to load the needed plugins. For example:
<pre>
-cd "C:\Program Files\Apache\qpidc-0.19"
+cd "C:\Program Files\Apache\qpidc-0.21"
qpidd.exe --load-module plugins\broker\store.dll --load-module plugins\broker\msclfs_store.dll
</pre>
The <code>--load-module</code> option can also take a full path. The option
diff --git a/packaging/windows/installer.proj b/packaging/windows/installer.proj
index 676205898f..b2d1d6fb2f 100644
--- a/packaging/windows/installer.proj
+++ b/packaging/windows/installer.proj
@@ -32,11 +32,11 @@
<source_root>$(MSBuildProjectDirectory)\..\..</source_root>
<staging_dir>$(MSBuildProjectDirectory)\stage</staging_dir>
<bits Condition="'$(bits)' == ''">32</bits>
- <qpid_version>0.19</qpid_version>
+ <qpid_version>0.21</qpid_version>
<OutputName>qpidc</OutputName>
<OutputType>Package</OutputType>
<WixToolPath>C:\Program Files (x86)\Windows Installer XML v3.5\bin</WixToolPath>
- <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.5\wix.targets</WixTargetsPath>
+ <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\wix.targets</WixTargetsPath>
</PropertyGroup>
<Choose>
@@ -175,10 +175,10 @@
<Target Name="BuildDotNetBindings"><!-- DependsOnTargets="BuildCpp;BuildCppDebug" -->
<MSBuild
- Projects="$(source_root)\cpp\bindings\qpid\dotnet\org.apache.qpid.messaging.sessionreceiver.sln"
+ Projects="$(source_root)\cpp\bindings\qpid\dotnet\msvc9\org.apache.qpid.messaging.sessionreceiver.sln"
Properties="Configuration=Debug;Platform=$(Architecture)" />
<MSBuild
- Projects="$(source_root)\cpp\bindings\qpid\dotnet\org.apache.qpid.messaging.sessionreceiver.sln"
+ Projects="$(source_root)\cpp\bindings\qpid\dotnet\msvc9\org.apache.qpid.messaging.sessionreceiver.sln"
Properties="Configuration=Release;Platform=$(Architecture)" />
</Target>
diff --git a/packaging/windows/qpidc.wxs b/packaging/windows/qpidc.wxs
index 7c07a14420..615ee04ed6 100644
--- a/packaging/windows/qpidc.wxs
+++ b/packaging/windows/qpidc.wxs
@@ -42,11 +42,18 @@
<PropertyRef Id="NETFRAMEWORK35"/>
<!-- Allow 64-bit builds to pick ProgramFiles64Folder instead -->
- <?Define ProgramFiles = "ProgramFilesFolder"?>
+ <?define ProgramFiles = "ProgramFilesFolder"?>
+
+ <!-- Pick up Program Files for 32-bit from the correct place -->
+ <?ifdef env.ProgramFiles(x86)?>
+ <?define ProgramFilesx86 = "$(env.ProgramFiles(x86))"?>
+ <?else?>
+ <?define ProgramFilesx86 = "$(env.ProgramFiles)"?>
+ <?endif?>
<Directory Id="TARGETDIR" Name="SourceDir">
- <Merge Id="VCRedist" SourceFile="C:\Program Files\Common Files\Merge Modules\Microsoft_VC90_CRT_x86.msm" DiskId="1" Language="0"/>
- <Merge Id="VCRedistPolicy" SourceFile="C:\Program Files\Common Files\Merge Modules\policy_9_0_Microsoft_VC90_CRT_x86.msm" DiskId="1" Language="0"/>
+ <Merge Id="VCRedist" SourceFile="$(var.ProgramFilesx86)\Common Files\Merge Modules\Microsoft_VC90_CRT_x86.msm" DiskId="1" Language="0"/>
+ <Merge Id="VCRedistPolicy" SourceFile="$(var.ProgramFilesx86)\Common Files\Merge Modules\policy_9_0_Microsoft_VC90_CRT_x86.msm" DiskId="1" Language="0"/>
<Directory Id="$(var.ProgramFiles)">
<Directory Id="ApacheTop" Name="Apache">
<Directory Id="INSTALLLOCATION" Name="qpidc-$(var.qpidc_version)">
@@ -105,8 +112,8 @@
<File Id="InstallNotesHTML" Source="INSTALL_NOTES.html"/>
</Component>
<Component Id="Legal" Guid="{D98B2A06-4A7E-488a-A7A9-BFB1B9D594A0}">
- <File Id="LICENSE" Source="$(var.staging_dir)\LICENSE"/>
- <File Id="NOTICE" Source="$(var.staging_dir)\NOTICE"/>
+ <File Id="LICENSE" Source="$(var.staging_dir)\docs\LICENSE"/>
+ <File Id="NOTICE" Source="$(var.staging_dir)\docs\NOTICE"/>
</Component>
</DirectoryRef>
@@ -269,7 +276,6 @@
<ComponentRef Id="TopStorePlugin"/>
<ComponentRef Id="SQLPersistence"/>
<ComponentRef Id="CLFSPersistence"/>
- <ComponentGroupRef Id="group_BoostDlls"/>
</Feature>
<Feature Id="ClientLib" Title="Client Libraries and Headers to develop and run programs" Level="1">
@@ -293,8 +299,6 @@
<ComponentRef Id="WCFInteropDLL"/>
<ComponentRef Id="WCFXADLL"/>
<ComponentGroupRef Id="group_QpidHeaders"/>
- <ComponentGroupRef Id="group_BoostHeaders"/>
- <ComponentGroupRef Id="group_BoostDlls"/>
<Feature Id="Examples" Title="Client Programming Examples" Level="1">
<ComponentGroupRef Id="group_Examples"/>
diff --git a/python/examples/README.txt b/python/examples/README.txt
index 4395160fec..3a3e421a1e 100644
--- a/python/examples/README.txt
+++ b/python/examples/README.txt
@@ -14,6 +14,11 @@ api/spout -- A simple messaging client that sends
messages to the target specified on the
command line.
+api/send -- Sends messages to a specified queue.
+
+api/receive -- Receives messages from a specified queue.
+ Use with the send example above.
+
api/server -- An example server that process incoming
messages and sends replies.
diff --git a/python/examples/api/receive b/python/examples/api/receive
new file mode 100755
index 0000000000..f14df277ac
--- /dev/null
+++ b/python/examples/api/receive
@@ -0,0 +1,194 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+import optparse, sys, time
+import statistics
+from qpid.messaging import *
+
+SECOND = 1000
+TIME_SEC = 1000000000
+
+op = optparse.OptionParser(usage="usage: %prog [options]", description="Drains messages from the specified address")
+op.add_option("-b", "--broker", default="localhost:5672", type="str", help="url of broker to connect to")
+op.add_option("-a", "--address", type="str", help="address to receive from")
+op.add_option("--connection-options", default={}, help="options for the connection")
+op.add_option("-m", "--messages", default=0, type="int", help="stop after N messages have been received, 0 means no limit")
+op.add_option("--timeout", default=0, type="int", help="timeout in seconds to wait before exiting")
+op.add_option("-f", "--forever", default=False, action="store_true", help="ignore timeout and wait forever")
+op.add_option("--ignore-duplicates", default=False, action="store_true", help="Detect and ignore duplicates (by checking 'sn' header)")
+op.add_option("--verify-sequence", default=False, action="store_true", help="Verify there are no gaps in the message sequence (by checking 'sn' header)")
+op.add_option("--check-redelivered", default=False, action="store_true", help="Fails with exception if a duplicate is not marked as redelivered (only relevant when ignore-duplicates is selected)")
+op.add_option("--capacity", default=1000, type="int", help="size of the senders outgoing message queue")
+op.add_option("--ack-frequency", default=100, type="int", help="Ack frequency (0 implies none of the messages will get accepted)")
+op.add_option("--tx", default=0, type="int", help="batch size for transactions (0 implies transaction are not used)")
+op.add_option("--rollback-frequency", default=0, type="int", help="rollback frequency (0 implies no transaction will be rolledback)")
+op.add_option("--print-content", type="str", default="yes", help="print out message content")
+op.add_option("--print-headers", type="str", default="no", help="print out message headers")
+op.add_option("--failover-updates", default=False, action="store_true", help="Listen for membership updates distributed via amq.failover")
+op.add_option("--report-total", default=False, action="store_true", help="Report total throughput statistics")
+op.add_option("--report-every", default=0, type="int", help="Report throughput statistics every N messages")
+op.add_option("--report-header", type="str", default="yes", help="Headers on report")
+op.add_option("--ready-address", type="str", help="send a message to this address when ready to receive")
+op.add_option("--receive-rate", default=0, type="int", help="Receive at rate of N messages/second. 0 means receive as fast as possible")
+#op.add_option("--help", default=False, action="store_true", help="print this usage statement")
+
+def getTimeout(timeout, forever):
+ if forever:
+ return None
+ else:
+ return SECOND*timeout
+
+
+EOS = "eos"
+SN = "sn"
+
+# Check for duplicate or dropped messages by sequence number
+class SequenceTracker:
+ def __init__(self, opts):
+ self.opts = opts
+ self.lastSn = 0
+
+ # Return True if the message should be procesed, false if it should be ignored.
+ def track(self, message):
+ if not(self.opts.verify_sequence) or (self.opts.ignore_duplicates):
+ return True
+ sn = message.properties[SN]
+ duplicate = (sn <= lastSn)
+ dropped = (sn > lastSn+1)
+ if self.opts.verify_sequence and dropped:
+ raise Exception("Gap in sequence numbers %s-%s" %(lastSn, sn))
+ ignore = (duplicate and self.opts.ignore_duplicates)
+ if ignore and self.opts.check_redelivered and (not msg.redelivered):
+ raise Exception("duplicate sequence number received, message not marked as redelivered!")
+ if not duplicate:
+ lastSn = sn
+ return (not(ignore))
+
+
+def main():
+ opts, args = op.parse_args()
+ if not opts.address:
+ raise Exception("Address must be specified!")
+
+ broker = opts.broker
+ address = opts.address
+ connection = Connection(opts.broker, **opts.connection_options)
+
+ try:
+ connection.open()
+ if opts.failover_updates:
+ auto_fetch_reconnect_urls(connection)
+ session = connection.session(transactional=(opts.tx))
+ receiver = session.receiver(opts.address)
+ if opts.capacity > 0:
+ receiver.capacity = opts.capacity
+ msg = Message()
+ count = 0
+ txCount = 0
+ sequenceTracker = SequenceTracker(opts)
+ timeout = getTimeout(opts.timeout, opts.forever)
+ done = False
+ stats = statistics.ThroughputAndLatency()
+ reporter = statistics.Reporter(opts.report_every, opts.report_header == "yes", stats)
+
+ if opts.ready_address is not None:
+ session.sender(opts.ready_address).send(msg)
+ if opts.tx > 0:
+ session.commit()
+ # For receive rate calculation
+ start = time.time()*TIME_SEC
+ interval = 0
+ if opts.receive_rate > 0:
+ interval = TIME_SEC / opts.receive_rate
+
+ replyTo = {} # a dictionary of reply-to address -> sender mapping
+
+ while (not done):
+ try:
+ msg = receiver.fetch(timeout=timeout)
+ reporter.message(msg)
+ if sequenceTracker.track(msg):
+ if msg.content == EOS:
+ done = True
+ else:
+ count+=1
+ if opts.print_headers == "yes":
+ if msg.subject is not None:
+ print "Subject: %s" %msg.subject
+ if msg.reply_to is not None:
+ print "ReplyTo: %s" %msg.reply_to
+ if msg.correlation_id is not None:
+ print "CorrelationId: %s" %msg.correlation_id
+ if msg.user_id is not None:
+ print "UserId: %s" %msg.user_id
+ if msg.ttl is not None:
+ print "TTL: %s" %msg.ttl
+ if msg.priority is not None:
+ print "Priority: %s" %msg.priority
+ if msg.durable:
+ print "Durable: true"
+ if msg.redelivered:
+ print "Redelivered: true"
+ print "Properties: %s" %msg.properties
+ print
+ if opts.print_content == "yes":
+ print msg.content
+ if (opts.messages > 0) and (count >= opts.messages):
+ done = True
+ # end of "if sequenceTracker.track(msg):"
+ if (opts.tx > 0) and (count % opts.tx == 0):
+ txCount+=1
+ if (opts.rollback_frequency > 0) and (txCount % opts.rollback_frequency == 0):
+ session.rollback()
+ else:
+ session.commit()
+ elif (opts.ack_frequency > 0) and (count % opts.ack_frequency == 0):
+ session.acknowledge()
+ if msg.reply_to is not None: # Echo message back to reply-to address.
+ if msg.reply_to not in replyTo:
+ replyTo[msg.reply_to] = session.sender(msg.reply_to)
+ replyTo[msg.reply_to].capacity = opts.capacity
+ replyTo[msg.reply_to].send(msg)
+ if opts.receive_rate > 0:
+ delay = start + count*interval - time.time()*TIME_SEC
+ if delay > 0:
+ time.sleep(delay)
+ # Clear out message properties & content for next iteration.
+ msg = Message()
+ except Empty: # no message fetched => break the while cycle
+ break
+ # end of while cycle
+ if opts.report_total:
+ reporter.report()
+ if opts.tx > 0:
+ txCount+=1
+ if opts.rollback_frequency and (txCount % opts.rollback_frequency == 0):
+ session.rollback()
+ else:
+ session.commit()
+ else:
+ session.acknowledge()
+ session.close()
+ connection.close()
+ except Exception,e:
+ print e
+ connection.close()
+
+if __name__ == "__main__": main()
diff --git a/python/examples/api/send b/python/examples/api/send
new file mode 100755
index 0000000000..b0105e41a6
--- /dev/null
+++ b/python/examples/api/send
@@ -0,0 +1,281 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+import optparse, random, os, time, uuid
+from qpid.messaging import *
+import statistics
+
+EOS = "eos"
+SN = "sn"
+TS = "ts"
+
+TIME_SEC = 1000000000
+SECOND = 1000
+
+def nameval(st):
+ idx = st.find("=")
+ if idx >= 0:
+ name = st[0:idx]
+ value = st[idx+1:]
+ else:
+ name = st
+ value = None
+ return name, value
+
+
+op = optparse.OptionParser(usage="usage: %prog [options]", description="Spouts messages to the specified address")
+op.add_option("-b", "--broker", default="localhost:5672", type="str", help="url of broker to connect to")
+op.add_option("-a", "--address", type="str", help="address to send to")
+op.add_option("--connection-options", default={}, help="options for the connection")
+op.add_option("-m", "--messages", default=1, type="int", help="stop after N messages have been sent, 0 means no limit")
+op.add_option("-i", "--id", type="str", help="use the supplied id instead of generating one")
+op.add_option("--reply-to", type="str", help="specify reply-to address")
+op.add_option("--send-eos", default=0, type="int", help="Send N EOS messages to mark end of input")
+op.add_option("--durable", default=False, action="store_true", help="Mark messages as durable")
+op.add_option("--ttl", default=0, type="int", help="Time-to-live for messages, in milliseconds")
+op.add_option("--priority", default=0, type="int", help="Priority for messages (higher value implies higher priority)")
+op.add_option("-P", "--property", default=[], action="append", type="str", help="specify message property")
+op.add_option("--correlation-id", type="str", help="correlation-id for message")
+op.add_option("--user-id", type="str", help="userid for message")
+op.add_option("--content-string", type="str", help="use CONTENT as message content")
+op.add_option("--content-size", default=0, type="int", help="create an N-byte message content")
+op.add_option("-M", "--content-map", default=[], action="append", type="str", help="specify entry for map content")
+op.add_option("--content-stdin", default=False, action="store_true", help="read message content from stdin, one line per message")
+op.add_option("--capacity", default=1000, type="int", help="size of the senders outgoing message queue")
+op.add_option("--tx", default=0, type="int", help="batch size for transactions (0 implies transaction are not used)")
+op.add_option("--rollback-frequency", default=0, type="int", help="rollback frequency (0 implies no transaction will be rolledback)")
+op.add_option("--failover-updates", default=False, action="store_true", help="Listen for membership updates distributed via amq.failover")
+op.add_option("--report-total", default=False, action="store_true", help="Report total throughput statistics")
+op.add_option("--report-every", default=0, type="int", help="Report throughput statistics every N messages")
+op.add_option("--report-header", type="str", default="yes", help="Headers on report")
+op.add_option("--send-rate", default=0, type="int", help="Send at rate of N messages/second. 0 means send as fast as possible")
+op.add_option("--flow-control", default=0, type="int", help="Do end to end flow control to limit queue depth to 2*N. 0 means no flow control.")
+op.add_option("--sequence", type="str", default="yes", help="Add a sequence number messages property (required for duplicate/lost message detection)")
+op.add_option("--timestamp", type="str", default="yes", help="Add a time stamp messages property (required for latency measurement)")
+op.add_option("--group-key", type="str", help="Generate groups of messages using message header 'KEY' to hold the group identifier")
+op.add_option("--group-prefix", default="GROUP-", type="str", help="Generate group identifers with 'STRING' prefix (if group-key specified)")
+op.add_option("--group-size", default=10, type="int", help="Number of messages per a group (if group-key specified)")
+op.add_option("--group-randomize-size", default=False, action="store_true", help="Randomize the number of messages per group to [1...group-size] (if group-key specified)")
+op.add_option("--group-interleave", default=1, type="int", help="Simultaineously interleave messages from N different groups (if group-key specified)")
+
+
+class ContentGenerator:
+ def setContent(self, msg):
+ return
+
+class GetlineContentGenerator(ContentGenerator):
+ def setContent(self, msg):
+ content = sys.stdin.readline()
+ got = (not line)
+ if (got):
+ msg.content = content
+ return got
+
+class FixedContentGenerator(ContentGenerator):
+ def __init__(self, content=None):
+ self.content = content
+
+ def setContent(self, msg):
+ msg.content = self.content
+ return True
+
+class MapContentGenerator(ContentGenerator):
+ def __init__(self, opts=None):
+ self.opts = opts
+
+ def setContent(self, msg):
+ self.content = {}
+ for e in self.opts.content_map:
+ name, val = nameval(p)
+ content[name] = val
+ msg.content = self.content
+ return True
+
+
+# tag each generated message with a group identifer
+class GroupGenerator:
+ def __init__(self, key, prefix, size, randomize, interleave):
+ groupKey = key
+ groupPrefix = prefix
+ groupSize = size
+ randomizeSize = randomize
+ groupSuffix = 0
+ if (randomize > 0):
+ random.seed(os.getpid())
+
+ for i in range(0, interleave):
+ self.newGroup()
+ current = 0
+
+ def setGroupInfo(self, msg):
+ if (current == len(groups)):
+ current = 0
+ my_group = groups[current]
+ msg.properties[groupKey] = my_group[id];
+ # print "SENDING GROUPID=[%s]\n" % my_group[id]
+ my_group[count]=my_group[count]+1
+ if (my_group[count] == my_group[size]):
+ self.newGroup()
+ del groups[current]
+ else:
+ current+=1
+
+ def newGroup(self):
+ groupId = "%s%s" % (groupPrefix, groupSuffix)
+ groupSuffix+=1
+ size = groupSize
+ if (randomizeSize == True):
+ size = random.randint(1,groupSize)
+ # print "New group: GROUPID=["%s] size=%s" % (groupId, size)
+ groups.append({'id':groupId, 'size':size, 'count':0})
+
+
+
+def main():
+ opts, args = op.parse_args()
+ if not opts.address:
+ raise Exception("Address must be specified!")
+
+ broker = opts.broker
+ address = opts.address
+ connection = Connection(opts.broker, **opts.connection_options)
+
+ try:
+ connection.open()
+ if (opts.failover_updates):
+ auto_fetch_reconnect_urls(connection)
+ session = connection.session(transactional=(opts.tx))
+ sender = session.sender(opts.address)
+ if (opts.capacity>0):
+ sender.capacity = opts.capacity
+ sent = 0
+ txCount = 0
+ stats = statistics.Throughput()
+ reporter = statistics.Reporter(opts.report_every, opts.report_header == "yes", stats)
+
+ contentGen = ContentGenerator()
+ content = "" # auxiliary variable for determining content type of message - needs to be changed to {} for Map message
+ if opts.content_stdin:
+ opts.messages = 0 # Don't limit number of messages sent.
+ contentGen = GetlineContentGenerator()
+ elif opts.content_map is not None:
+ contentGen = MapContentGenerator(opts)
+ content = {}
+ elif opts.content_size is not None:
+ contentGen = FixedContentGenerator('X' * opts.content_size)
+ else:
+ contentGen = FixedContentGenerator(opts.content_string)
+ if opts.group_key is not None:
+ groupGen = GroupGenerator(opts.group_key, opts.group_prefix, opts.group_size, opts.group_random_size, opts.group_interleave)
+
+ msg = Message(content=content)
+ msg.durable = opts.durable
+ if opts.ttl:
+ msg.ttl = opts.ttl/1000.0
+ if opts.priority:
+ msg.priority = opts.priority
+ if opts.reply_to is not None:
+ if opts.flow_control > 0:
+ raise Exception("Can't use reply-to and flow-control together")
+ msg.reply_to = opts.reply_to
+ if opts.user_id is not None:
+ msg.user_id = opts.user_id
+ if opts.correlation_id is not None:
+ msg.correlation_id = opts.correlation_id
+ for p in opts.property:
+ name, val = nameval(p)
+ msg.properties[name] = val
+
+ start = time.time()*TIME_SEC
+ interval = 0
+ if opts.send_rate > 0:
+ interval = TIME_SEC/opts.send_rate
+
+ flowControlAddress = "flow-" + str(uuid.uuid1()) + ";{create:always,delete:always}"
+ flowSent = 0
+ if opts.flow_control > 0:
+ flowControlReceiver = session.receiver(flowControlAddress)
+ flowControlReceiver.capacity = 2
+
+ while (contentGen.setContent(msg) == True):
+ sent+=1
+ if opts.sequence == "yes":
+ msg.properties[SN] = sent
+
+ if opts.flow_control > 0:
+ if (sent % opts.flow_control == 0):
+ msg.reply_to = flowControlAddress
+ flowSent+=1
+ else:
+ msg.reply_to = "" # Clear the reply address.
+
+ if 'groupGen' in vars():
+ groupGen.setGroupInfo(msg)
+
+ if (opts.timestamp == "yes"):
+ msg.properties[TS] = int(time.time()*TIME_SEC)
+ sender.send(msg)
+ reporter.message(msg)
+
+ if ((opts.tx > 0) and (sent % opts.tx == 0)):
+ txCount+=1
+ if ((opts.rollbackFrequency > 0) and (txCount % opts.rollbackFrequency == 0)):
+ session.rollback()
+ else:
+ session.commit()
+ if ((opts.messages > 0) and (sent >= opts.messages)):
+ break
+
+ if (opts.flow_control > 0) and (flowSent == 2):
+ flowControlReceiver.fetch(timeout=SECOND)
+ flowSent -= 1
+
+ if (opts.send_rate > 0):
+ delay = start + sent*interval - time.time()*TIME_SEC
+ if (delay > 0):
+ time.sleep(delay)
+ #end of while
+
+ while flowSent > 0:
+ flowControlReceiver.fetch(timeout=SECOND)
+ flowSent -= 1
+
+ if (opts.report_total):
+ reporter.report()
+ for i in reversed(range(1,opts.send_eos+1)):
+ if (opts.sequence == "yes"):
+ sent+=1
+ msg.properties[SN] = sent
+ msg.properties[EOS] = True #TODO (also in C++ client): add in ability to send digest or similar
+ sender.send(msg)
+ if ((opts.tx > 0) and (sent % opts.tx == 0)):
+ txCount+=1
+ if ((opts.rollback_frequency > 0) and (txCount % opts.rollback_frequency == 0)):
+ session.rollback()
+ else:
+ session.commit()
+ session.sync()
+ session.close()
+ connection.close()
+ except Exception,e:
+ print e
+ connection.close()
+
+if __name__ == "__main__": main()
diff --git a/python/examples/api/statistics.py b/python/examples/api/statistics.py
new file mode 100644
index 0000000000..e095920e90
--- /dev/null
+++ b/python/examples/api/statistics.py
@@ -0,0 +1,139 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+import time
+
+TS = "ts"
+TIME_SEC = 1000000000
+MILLISECOND = 1000
+
+class Statistic:
+ def message(self, msg):
+ return
+ def report(self):
+ return ""
+ def header(self):
+ return ""
+
+
+class Throughput(Statistic):
+ def __init__(self):
+ self.messages = 0
+ self.started = False
+
+ def message(self, m):
+ self.messages += 1
+ if not self.started:
+ self.start = time.time()
+ self.started = True
+
+ def header(self):
+ return "tp(m/s)"
+
+ def report(self):
+ if self.started:
+ elapsed = time.time() - self.start
+ return str(int(self.messages/elapsed))
+ else:
+ return "0"
+
+
+class ThroughputAndLatency(Throughput):
+ def __init__(self):
+ Throughput.__init__(self)
+ self.total = 0.0
+ self.min = float('inf')
+ self.max = -float('inf')
+ self.samples = 0
+
+ def message(self, m):
+ Throughput.message(self, m)
+ if TS in m.properties:
+ self.samples+=1
+ latency = MILLISECOND * (time.time() - float(m.properties[TS])/TIME_SEC)
+ if latency > 0:
+ self.total += latency
+ if latency < self.min:
+ self.min = latency
+ if latency > self.max:
+ self.max = latency
+
+ def header(self):
+# Throughput.header(self)
+ return "%s\tl-min\tl-max\tl-avg" % Throughput.header(self)
+
+ def report(self):
+ output = Throughput.report(self)
+ if (self.samples > 0):
+ output += "\t%.2f\t%.2f\t%.2f" %(self.min, self.max, self.total/self.samples)
+ return output
+
+
+# Report batch and overall statistics
+class ReporterBase:
+ def __init__(self, batch, wantHeader):
+ self.batchSize = batch
+ self.batchCount = 0
+ self.headerPrinted = not wantHeader
+ self.overall = None
+ self.batch = None
+
+ def create(self):
+ return
+
+ # Count message in the statistics
+ def message(self, m):
+ if self.overall == None:
+ self.overall = self.create()
+ self.overall.message(m)
+ if self.batchSize:
+ if self.batch == None:
+ self.batch = self.create()
+ self.batch.message(m)
+ self.batchCount+=1
+ if self.batchCount == self.batchSize:
+ self.header()
+ print self.batch.report()
+ self.create()
+ self.batchCount = 0
+
+ # Print overall report.
+ def report(self):
+ if self.overall == None:
+ self.overall = self.create()
+ self.header()
+ print self.overall.report()
+
+ def header(self):
+ if not self.headerPrinted:
+ if self.overall == None:
+ self.overall = self.create()
+ print self.overall.header()
+ self.headerPrinted = True
+
+
+class Reporter(ReporterBase):
+ def __init__(self, batchSize, wantHeader, Stats):
+ ReporterBase.__init__(self, batchSize, wantHeader)
+ self.__stats = Stats
+
+ def create(self):
+ ClassName = self.__stats.__class__
+ return ClassName()
diff --git a/python/qpid/client.py b/python/qpid/client.py
index 5a877bb8d6..4d42a8b20f 100644
--- a/python/qpid/client.py
+++ b/python/qpid/client.py
@@ -18,13 +18,14 @@
#
"""
-An AQMP client implementation that uses a custom delegate for
+An AMQP client implementation that uses a custom delegate for
interacting with the server.
"""
import os, threading
from peer import Peer, Channel, Closed
from delegate import Delegate
+from util import get_client_properties_with_defaults
from connection08 import Connection, Frame, connect
from spec08 import load
from queue import Queue
@@ -76,12 +77,12 @@ class Client:
self.lock.release()
return q
- def start(self, response, mechanism="AMQPLAIN", locale="en_US", tune_params=None):
+ def start(self, response, mechanism="AMQPLAIN", locale="en_US", tune_params=None, client_properties=None):
self.mechanism = mechanism
self.response = response
self.locale = locale
self.tune_params = tune_params
-
+ self.client_properties=get_client_properties_with_defaults(provided_client_properties=client_properties)
self.socket = connect(self.host, self.port)
self.conn = Connection(self.socket, self.spec)
self.peer = Peer(self.conn, ClientDelegate(self), Session)
@@ -128,7 +129,8 @@ class ClientDelegate(Delegate):
def connection_start(self, ch, msg):
msg.start_ok(mechanism=self.client.mechanism,
response=self.client.response,
- locale=self.client.locale)
+ locale=self.client.locale,
+ client_properties=self.client.client_properties)
def connection_tune(self, ch, msg):
if self.client.tune_params:
diff --git a/python/qpid/connection08.py b/python/qpid/connection08.py
index 654148dad2..0045e122ea 100644
--- a/python/qpid/connection08.py
+++ b/python/qpid/connection08.py
@@ -28,6 +28,9 @@ from cStringIO import StringIO
from codec import EOF
from compat import SHUT_RDWR
from exceptions import VersionError
+from logging import getLogger, DEBUG
+
+log = getLogger("qpid.connection08")
class SockIO:
@@ -35,7 +38,8 @@ class SockIO:
self.sock = sock
def write(self, buf):
-# print "OUT: %r" % buf
+ if log.isEnabledFor(DEBUG):
+ log.debug("OUT: %r", buf)
self.sock.sendall(buf)
def read(self, n):
@@ -47,8 +51,9 @@ class SockIO:
break
if len(s) == 0:
break
-# print "IN: %r" % s
data += s
+ if log.isEnabledFor(DEBUG):
+ log.debug("IN: %r", data)
return data
def flush(self):
@@ -120,19 +125,25 @@ class Connection:
(self.spec.major, self.spec.minor, major, minor))
else:
raise FramingError("unknown frame type: %s" % tid)
- channel = c.decode_short()
- body = c.decode_longstr()
- dec = codec.Codec(StringIO(body), self.spec)
- frame = Frame.DECODERS[type].decode(self.spec, dec, len(body))
- frame.channel = channel
- end = c.decode_octet()
- if end != self.FRAME_END:
- garbage = ""
- while end != self.FRAME_END:
- garbage += chr(end)
- end = c.decode_octet()
- raise "frame error: expected %r, got %r" % (self.FRAME_END, garbage)
- return frame
+ try:
+ channel = c.decode_short()
+ body = c.decode_longstr()
+ dec = codec.Codec(StringIO(body), self.spec)
+ frame = Frame.DECODERS[type].decode(self.spec, dec, len(body))
+ frame.channel = channel
+ end = c.decode_octet()
+ if end != self.FRAME_END:
+ garbage = ""
+ while end != self.FRAME_END:
+ garbage += chr(end)
+ end = c.decode_octet()
+ raise "frame error: expected %r, got %r" % (self.FRAME_END, garbage)
+ return frame
+ except EOF:
+ # An EOF caught here can indicate an error decoding the frame,
+ # rather than that a disconnection occurred,so it's worth logging it.
+ log.exception("Error occurred when reading frame with tid %s" % tid)
+ raise
def write_0_9(self, frame):
self.write_8_0(frame)
diff --git a/python/qpid/delegates.py b/python/qpid/delegates.py
index 5e44a3a6dc..ae7ed7f988 100644
--- a/python/qpid/delegates.py
+++ b/python/qpid/delegates.py
@@ -18,7 +18,7 @@
#
import os, connection, session
-from util import notify
+from util import notify, get_client_properties_with_defaults
from datatypes import RangedSet
from exceptions import VersionError, Closed
from logging import getLogger
@@ -137,24 +137,12 @@ class Server(Delegate):
class Client(Delegate):
- ppid = 0
- try:
- ppid = os.getppid()
- except:
- pass
-
- PROPERTIES = {"product": "qpid python client",
- "version": "development",
- "platform": os.name,
- "qpid.client_process": os.path.basename(sys.argv[0]),
- "qpid.client_pid": os.getpid(),
- "qpid.client_ppid": ppid}
-
def __init__(self, connection, username=None, password=None,
mechanism=None, heartbeat=None, **kwargs):
Delegate.__init__(self, connection)
- self.client_properties=Client.PROPERTIES.copy()
- self.client_properties.update(kwargs.get("client_properties",{}))
+ provided_client_properties = kwargs.get("client_properties")
+ self.client_properties=get_client_properties_with_defaults(provided_client_properties)
+
##
## self.acceptableMechanisms is the list of SASL mechanisms that the client is willing to
## use. If it's None, then any mechanism is acceptable.
diff --git a/python/qpid/messaging/driver.py b/python/qpid/messaging/driver.py
index 3cb62d75c9..2bd638f327 100644
--- a/python/qpid/messaging/driver.py
+++ b/python/qpid/messaging/driver.py
@@ -31,7 +31,7 @@ from qpid.messaging.exceptions import *
from qpid.messaging.message import get_codec, Disposition, Message
from qpid.ops import *
from qpid.selector import Selector
-from qpid.util import URL, default
+from qpid.util import URL, default,get_client_properties_with_defaults
from qpid.validator import And, Context, List, Map, Types, Values
from threading import Condition, Thread
@@ -90,20 +90,6 @@ SUBJECT_DEFAULTS = {
"topic": "#"
}
-# XXX
-ppid = 0
-try:
- ppid = os.getppid()
-except:
- pass
-
-CLIENT_PROPERTIES = {"product": "qpid python client",
- "version": "development",
- "platform": os.name,
- "qpid.client_process": os.path.basename(sys.argv[0]),
- "qpid.client_pid": os.getpid(),
- "qpid.client_ppid": ppid}
-
def noop(): pass
def sync_noop(): pass
@@ -710,8 +696,7 @@ class Engine:
except sasl.SASLError, e:
raise AuthenticationFailure(text=str(e))
- client_properties = CLIENT_PROPERTIES.copy()
- client_properties.update(self.connection.client_properties)
+ client_properties = get_client_properties_with_defaults(provided_client_properties=self.connection.client_properties);
self.write_op(ConnectionStartOk(client_properties=client_properties,
mechanism=mech, response=initial))
diff --git a/python/qpid/messaging/endpoints.py b/python/qpid/messaging/endpoints.py
index e632c0c5b8..95ff5516d0 100644
--- a/python/qpid/messaging/endpoints.py
+++ b/python/qpid/messaging/endpoints.py
@@ -871,7 +871,7 @@ class Sender(Endpoint):
self.queued += 1
if sync:
- self.sync()
+ self.sync(timeout=timeout)
assert message not in self.session.outgoing
else:
self._wakeup()
diff --git a/python/qpid/messaging/transports.py b/python/qpid/messaging/transports.py
index 532c365884..e901e98258 100644
--- a/python/qpid/messaging/transports.py
+++ b/python/qpid/messaging/transports.py
@@ -55,7 +55,41 @@ try:
from ssl import wrap_socket, SSLError, SSL_ERROR_WANT_READ, \
SSL_ERROR_WANT_WRITE
except ImportError:
- pass
+
+ ## try the older python SSL api:
+ from socket import ssl
+
+ class old_ssl(SocketTransport):
+ def __init__(self, conn, host, port):
+ SocketTransport.__init__(self, conn, host, port)
+ # Bug (QPID-4337): this is the "old" version of python SSL.
+ # The private key is required. If a certificate is given, but no
+ # keyfile, assume the key is contained in the certificate
+ ssl_keyfile = conn.ssl_keyfile
+ ssl_certfile = conn.ssl_certfile
+ if ssl_certfile and not ssl_keyfile:
+ ssl_keyfile = ssl_certfile
+ self.ssl = ssl(self.socket, keyfile=ssl_keyfile, certfile=ssl_certfile)
+ self.socket.setblocking(1)
+
+ def reading(self, reading):
+ return reading
+
+ def writing(self, writing):
+ return writing
+
+ def recv(self, n):
+ return self.ssl.read(n)
+
+ def send(self, s):
+ return self.ssl.write(s)
+
+ def close(self):
+ self.socket.close()
+
+ TRANSPORTS["ssl"] = old_ssl
+ TRANSPORTS["tcp+tls"] = old_ssl
+
else:
class tls(SocketTransport):
diff --git a/python/qpid/testlib.py b/python/qpid/testlib.py
index f9796982f5..2b283f3998 100644
--- a/python/qpid/testlib.py
+++ b/python/qpid/testlib.py
@@ -73,7 +73,7 @@ class TestBase(unittest.TestCase):
else:
self.client.close()
- def connect(self, host=None, port=None, user=None, password=None, tune_params=None):
+ def connect(self, host=None, port=None, user=None, password=None, tune_params=None, client_properties=None):
"""Create a new connction, return the Client object"""
host = host or self.config.broker.host
port = port or self.config.broker.port or 5672
@@ -82,9 +82,9 @@ class TestBase(unittest.TestCase):
client = qpid.client.Client(host, port)
try:
if client.spec.major == 8 and client.spec.minor == 0:
- client.start({"LOGIN": user, "PASSWORD": password}, tune_params=tune_params)
+ client.start({"LOGIN": user, "PASSWORD": password}, tune_params=tune_params, client_properties=client_properties)
else:
- client.start("\x00" + user + "\x00" + password, mechanism="PLAIN", tune_params=tune_params)
+ client.start("\x00" + user + "\x00" + password, mechanism="PLAIN", tune_params=tune_params, client_properties=client_properties)
except qpid.client.Closed, e:
if isinstance(e.args[0], VersionError):
raise Skipped(e.args[0])
diff --git a/python/qpid/tests/__init__.py b/python/qpid/tests/__init__.py
index 101a0c3759..dc9988515e 100644
--- a/python/qpid/tests/__init__.py
+++ b/python/qpid/tests/__init__.py
@@ -37,6 +37,7 @@ import qpid.tests.datatypes
import qpid.tests.connection
import qpid.tests.spec010
import qpid.tests.codec010
+import qpid.tests.util
class TestTestsXXX(Test):
diff --git a/python/qpid/tests/util.py b/python/qpid/tests/util.py
new file mode 100644
index 0000000000..9777443720
--- /dev/null
+++ b/python/qpid/tests/util.py
@@ -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.
+#
+from unittest import TestCase
+from qpid.util import get_client_properties_with_defaults
+
+class UtilTest (TestCase):
+
+ def test_get_spec_recommended_client_properties(self):
+ client_properties = get_client_properties_with_defaults(provided_client_properties={"mykey":"myvalue"})
+ self.assertTrue("product" in client_properties)
+ self.assertTrue("version" in client_properties)
+ self.assertTrue("platform" in client_properties)
+
+ def test_get_client_properties_with_provided_value(self):
+ client_properties = get_client_properties_with_defaults(provided_client_properties={"mykey":"myvalue"})
+ self.assertTrue("product" in client_properties)
+ self.assertTrue("mykey" in client_properties)
+ self.assertEqual("myvalue", client_properties["mykey"])
+
+ def test_get_client_properties_with_no_provided_values(self):
+ client_properties = get_client_properties_with_defaults(provided_client_properties=None)
+ self.assertTrue("product" in client_properties)
+
+ client_properties = get_client_properties_with_defaults()
+ self.assertTrue("product" in client_properties)
+
+ def test_get_client_properties_with_provided_value_that_overrides_default(self):
+ client_properties = get_client_properties_with_defaults(provided_client_properties={"version":"myversion"})
+ self.assertEqual("myversion", client_properties["version"])
+
diff --git a/python/qpid/util.py b/python/qpid/util.py
index 39ad1d830e..8da17ce0c6 100644
--- a/python/qpid/util.py
+++ b/python/qpid/util.py
@@ -17,15 +17,19 @@
# under the License.
#
-import os, socket, time, textwrap, re
+import os, socket, time, textwrap, re, sys
try:
from ssl import wrap_socket as ssl
except ImportError:
from socket import ssl as wrap_socket
class ssl:
-
def __init__(self, sock, keyfile=None, certfile=None, trustfile=None):
+ # Bug (QPID-4337): this is the "old" version of python SSL.
+ # The private key is required. If a certificate is given, but no
+ # keyfile, assume the key is contained in the certificate
+ if certfile and not keyfile:
+ keyfile = certfile
self.sock = sock
self.ssl = wrap_socket(sock, keyfile=keyfile, certfile=certfile)
@@ -38,6 +42,24 @@ except ImportError:
def close(self):
self.sock.close()
+def get_client_properties_with_defaults(provided_client_properties={}):
+ ppid = 0
+ try:
+ ppid = os.getppid()
+ except:
+ pass
+
+ client_properties = {"product": "qpid python client",
+ "version": "development",
+ "platform": os.name,
+ "qpid.client_process": os.path.basename(sys.argv[0]),
+ "qpid.client_pid": os.getpid(),
+ "qpid.client_ppid": ppid}
+
+ if provided_client_properties:
+ client_properties.update(provided_client_properties)
+ return client_properties
+
def connect(host, port):
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
diff --git a/python/setup.py b/python/setup.py
index 0b9d99a1af..56af530b43 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -298,7 +298,7 @@ class install_lib(_install_lib):
return outfiles + extra
setup(name="qpid-python",
- version="0.19",
+ version="0.21",
author="Apache Qpid",
author_email="dev@qpid.apache.org",
packages=["mllib", "qpid", "qpid.messaging", "qpid.tests",
diff --git a/specs/management-schema.xml b/specs/management-schema.xml
index 5d1fbe0110..678c1a6476 100644
--- a/specs/management-schema.xml
+++ b/specs/management-schema.xml
@@ -81,6 +81,7 @@
<property name="systemRef" type="objId" references="System" access="RO" desc="System ID" parentRef="y"/>
<property name="port" type="uint16" access="RO" desc="TCP Port for AMQP Service"/>
<property name="workerThreads" type="uint16" access="RO" desc="Thread pool size"/>
+ <property name="maxConns" type="uint16" access="RO" desc="Maximum allowed connections"/>
<property name="connBacklog" type="uint16" access="RO" desc="Connection backlog limit for listening socket"/>
<property name="stagingThreshold" type="uint32" access="RO" desc="Broker stages messages over this size to disk"/>
<property name="mgmtPublish" type="bool" access="RO" desc="Broker's management agent sends unsolicited data on the publish interval"/>
@@ -153,7 +154,7 @@
<arg name="level" dir="O" type="sstr"/>
</method>
- <method name="getTimestampConfig" desc="Get the message timestamping configuration">
+ <method name="getTimestampConfig" desc="Get the message timestamping configuration">
<arg name="receive" dir="O" type="bool" desc="True if received messages are timestamped."/>
</method>
@@ -180,6 +181,14 @@
<arg name="results" dir="O" type="map" desc="A snapshot of the object's state."/>
</method>
+ <method name="getLogHiresTimestamp" desc="Get the high resolution timestamp in logs">
+ <arg name="logHires" dir="O" type="bool" desc="True if high resolution timestamp in logs is enabled."/>
+ </method>
+
+ <method name="setLogHiresTimestamp" desc="Set the high resolution timestamp in logs">
+ <arg name="logHires" dir="I" type="bool" desc="True to enable enable high resolution timestamp in logs."/>
+ </method>
+
</class>
@@ -357,6 +366,8 @@
<property name="shadow" type="bool" access="RO" desc="True for shadow connections"/>
<property name="saslMechanism" type="sstr" access="RO" desc="SASL mechanism"/>
<property name="saslSsf" type="uint16" access="RO" desc="SASL security strength factor"/>
+ <property name="remoteProperties" type="map" access="RO" desc="optional map of identifying information sent by the remote"/>
+ <property name="protocol" type="sstr" access="RC" desc="protocol in use"/>
<statistic name="closing" type="bool" desc="This client is closing by management request"/>
<statistic name="framesFromClient" type="count64"/>
<statistic name="framesToClient" type="count64"/>
@@ -496,11 +507,12 @@
<arg name="user" type="sstr" desc="Authentication identity"/>
<arg name="msgDepth" type="count64" desc="Current size of queue in messages"/>
<arg name="byteDepth" type="count64" desc="Current size of queue in bytes"/>
+ <arg name="properties" type="map" desc="optional identifying information sent by the remote"/>
</eventArguments>
- <event name="clientConnect" sev="inform" args="rhost, user"/>
- <event name="clientConnectFail" sev="warn" args="rhost, user, reason"/>
- <event name="clientDisconnect" sev="inform" args="rhost, user"/>
+ <event name="clientConnect" sev="inform" args="rhost, user, properties"/>
+ <event name="clientConnectFail" sev="warn" args="rhost, user, reason, properties"/>
+ <event name="clientDisconnect" sev="inform" args="rhost, user, properties"/>
<event name="brokerLinkUp" sev="inform" args="rhost"/>
<event name="brokerLinkDown" sev="warn" args="rhost"/>
<event name="queueDeclare" sev="inform" args="rhost, user, qName, durable, excl, autoDel, altEx, args, disp"/>
diff --git a/tests/setup.py b/tests/setup.py
index 8d5345d56e..67d2c87ad9 100755
--- a/tests/setup.py
+++ b/tests/setup.py
@@ -20,7 +20,7 @@
from distutils.core import setup
setup(name="qpid-tests",
- version="0.19",
+ version="0.21",
author="Apache Qpid",
author_email="dev@qpid.apache.org",
packages=["qpid_tests", "qpid_tests.broker_0_10", "qpid_tests.broker_0_9",
diff --git a/tests/src/py/qpid_tests/broker_0_10/management.py b/tests/src/py/qpid_tests/broker_0_10/management.py
index 4ec3e0dd03..126b96853b 100644
--- a/tests/src/py/qpid_tests/broker_0_10/management.py
+++ b/tests/src/py/qpid_tests/broker_0_10/management.py
@@ -140,6 +140,30 @@ class ManagementTest (TestBase010):
return exchange
return None
+ def test_move_queued_messages_empty(self):
+ """
+ Test that moving messages from an empty queue does not cause an error.
+ """
+ self.startQmf()
+ session = self.session
+ "Set up source queue"
+ session.queue_declare(queue="src-queue-empty", exclusive=True, auto_delete=True)
+
+ "Set up destination queue"
+ session.queue_declare(queue="dest-queue-empty", exclusive=True, auto_delete=True)
+
+ queues = self.qmf.getObjects(_class="queue")
+
+ "Move all messages from src-queue-empty to dest-queue-empty"
+ result = self.qmf.getObjects(_class="broker")[0].queueMoveMessages("src-queue-empty", "dest-queue-empty", 0, {})
+ self.assertEqual (result.status, 0)
+
+ sq = self.qmf.getObjects(_class="queue", name="src-queue-empty")[0]
+ dq = self.qmf.getObjects(_class="queue", name="dest-queue-empty")[0]
+
+ self.assertEqual (sq.msgDepth,0)
+ self.assertEqual (dq.msgDepth,0)
+
def test_move_queued_messages(self):
"""
Test ability to move messages from the head of one queue to another.
diff --git a/tests/src/py/qpid_tests/broker_0_8/basic.py b/tests/src/py/qpid_tests/broker_0_8/basic.py
index d5837fc19c..606aad1293 100644
--- a/tests/src/py/qpid_tests/broker_0_8/basic.py
+++ b/tests/src/py/qpid_tests/broker_0_8/basic.py
@@ -79,6 +79,51 @@ class BasicTests(TestBase):
except Closed, e:
self.assertChannelException(403, e.args[0])
+ def test_reconnect_to_durable_subscription(self):
+ try:
+ publisherchannel = self.channel
+ my_id = "my_id"
+ consumer_connection_properties_with_instance = {"instance": my_id}
+ queue_for_subscription = "queue_for_subscription_%s" % my_id
+ topic_name = "my_topic_name"
+ test_message = self.uniqueString()
+
+ durable_subscription_client = self.connect(client_properties=consumer_connection_properties_with_instance)
+ consumerchannel = durable_subscription_client.channel(1)
+ consumerchannel.channel_open()
+
+ self._declare_and_bind_exclusive_queue_on_topic_exchange(consumerchannel, queue_for_subscription, topic_name)
+
+ # disconnect
+ durable_subscription_client.close()
+
+ # send message to topic
+ publisherchannel.basic_publish(routing_key=topic_name, exchange="amq.topic", content=Content(test_message))
+
+ # reconnect and consume message
+ durable_subscription_client = self.connect(client_properties=consumer_connection_properties_with_instance)
+ consumerchannel = durable_subscription_client.channel(1)
+ consumerchannel.channel_open()
+
+ self._declare_and_bind_exclusive_queue_on_topic_exchange(consumerchannel, queue_for_subscription, topic_name)
+
+ # Create consumer and consume the message that was sent whilst subscriber was disconnected. By convention we
+ # declare the consumer as exclusive to forbid concurrent access.
+ subscription = consumerchannel.basic_consume(queue=queue_for_subscription, exclusive=True)
+ queue = durable_subscription_client.queue(subscription.consumer_tag)
+
+ # consume and verify message content
+ msg = queue.get(timeout=1)
+ self.assertEqual(test_message, msg.content.body)
+ consumerchannel.basic_ack(delivery_tag=msg.delivery_tag)
+ finally:
+ publisherchannel.queue_delete(queue=queue_for_subscription)
+ durable_subscription_client.close()
+
+ def _declare_and_bind_exclusive_queue_on_topic_exchange(self, channel, queue, topic_name):
+ channel.queue_declare(queue=queue, exclusive=True, auto_delete=False, durable=True)
+ channel.queue_bind(exchange="amq.topic", queue=queue, routing_key=topic_name)
+
def test_consume_queue_errors(self):
"""
Test error conditions associated with the queue field of the consume method:
@@ -129,7 +174,7 @@ class BasicTests(TestBase):
myqueue = self.client.queue("my-consumer")
msg = myqueue.get(timeout=1)
self.assertEqual("One", msg.content.body)
-
+
#cancel should stop messages being delivered
channel.basic_cancel(consumer_tag="my-consumer")
channel.basic_publish(routing_key="test-queue-4", content=Content("Two"))
diff --git a/tests/src/py/qpid_tests/broker_0_9/__init__.py b/tests/src/py/qpid_tests/broker_0_9/__init__.py
index d9f2ed7dbb..6b46b96b1d 100644
--- a/tests/src/py/qpid_tests/broker_0_9/__init__.py
+++ b/tests/src/py/qpid_tests/broker_0_9/__init__.py
@@ -19,4 +19,4 @@
# under the License.
#
-import query, queue
+import query, queue, messageheader
diff --git a/tests/src/py/qpid_tests/broker_0_9/messageheader.py b/tests/src/py/qpid_tests/broker_0_9/messageheader.py
new file mode 100644
index 0000000000..3526cf37af
--- /dev/null
+++ b/tests/src/py/qpid_tests/broker_0_9/messageheader.py
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+from qpid.testlib import TestBase
+
+class MessageHeaderTests(TestBase):
+ """Verify that messages with headers work as expected"""
+
+ def test_message_with_integer_header(self):
+ props={"headers":{"one":1, "zero":0}}
+ self.queue_declare(queue="q")
+ q = self.consume("q")
+ self.assertPublishGet(q, routing_key="q", properties=props)
+
+ def test_message_with_string_header(self):
+ props={"headers":{"mystr":"hello world", "myempty":""}}
+ self.queue_declare(queue="q")
+ q = self.consume("q")
+ self.assertPublishGet(q, routing_key="q", properties=props)
diff --git a/tools/setup.py b/tools/setup.py
index c9dc21c620..438a2af14f 100755
--- a/tools/setup.py
+++ b/tools/setup.py
@@ -20,7 +20,7 @@
from distutils.core import setup
setup(name="qpid-tools",
- version="0.19",
+ version="0.21",
author="Apache Qpid",
author_email="dev@qpid.apache.org",
package_dir={'' : 'src/py'},
diff --git a/tools/src/py/qpid-cluster b/tools/src/py/qpid-cluster
index 7d800b52fb..d75a10f6e8 100755
--- a/tools/src/py/qpid-cluster
+++ b/tools/src/py/qpid-cluster
@@ -244,6 +244,7 @@ def main(argv=None):
parser.add_option("-t", "--timeout", action="store", type="int", default=10, metavar="SECS", help="Maximum time to wait for broker connection (in seconds)")
parser.add_option("--sasl-mechanism", action="store", type="string", metavar="<mech>", help="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.")
parser.add_option("--ssl-certificate", action="store", type="string", metavar="<cert>", help="Client SSL certificate (PEM Format)")
+ parser.add_option("--ssl-key", action="store", type="string", metavar="<key>", help="Client SSL private key (PEM Format)")
parser.add_option("-C", "--all-connections", action="store_true", default=False, help="View client connections to all cluster members")
parser.add_option("-c", "--connections", metavar="ID", help="View client connections to specified member")
parser.add_option("-d", "--del-connection", metavar="HOST:PORT", help="Disconnect a client connection")
@@ -280,6 +281,9 @@ def main(argv=None):
if len(config._stopId.split(":")) != 2:
parser.error("Member ID must be of form: <host or ip>:<number>")
+ if opts.ssl_key and not opts.ssl_certificate:
+ parser.error("missing '--ssl-certificate' (required by '--ssl-key')")
+
config._stopAll = opts.all_stop
config._force = opts.force
config._numeric = opts.numeric
@@ -289,6 +293,8 @@ def main(argv=None):
conn_options['mechanisms'] = opts.sasl_mechanism
if opts.ssl_certificate:
conn_options['ssl_certfile'] = opts.ssl_certificate
+ if opts.ssl_key:
+ conn_options['ssl_keyfile'] = opts.ssl_key
bm = BrokerManager(config, conn_options)
diff --git a/tools/src/py/qpid-config b/tools/src/py/qpid-config
index df43b7ea4e..2bab892c95 100755
--- a/tools/src/py/qpid-config
+++ b/tools/src/py/qpid-config
@@ -174,7 +174,8 @@ def OptionsAndArguments(argv):
group1 = OptionGroup(parser, "General Options")
group1.add_option("-t", "--timeout", action="store", type="int", default=10, metavar="<secs>", help="Maximum time to wait for broker connection (in seconds)")
group1.add_option("-r", "--recursive", action="store_true", help="Show bindings in queue or exchange list")
- group1.add_option("-b", "--broker", action="store", type="string", default="localhost:5672", metavar="<address>", help="Address of qpidd broker with syntax: [username/password@] hostname | ip-address [:<port>]")
+ group1.add_option("-b", "--broker", action="store", type="string", metavar="<address>", help="Address of qpidd broker with syntax: [username/password@] hostname | ip-address [:<port>]")
+ group1.add_option("-a", "--broker-addr", action="store", type="string", metavar="<address>")
group1.add_option("--sasl-mechanism", action="store", type="string", metavar="<mech>", help="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.")
group1.add_option("--ssl-certificate", action="store", type="string", metavar="<cert>", help="Client SSL certificate (PEM Format)")
group1.add_option("--ssl-key", action="store", type="string", metavar="<key>", help="Client SSL private key (PEM Format)")
@@ -245,6 +246,9 @@ def OptionsAndArguments(argv):
config._recursive = True
if opts.broker:
config._host = opts.broker
+ if opts.broker_addr:
+ config._host = opts.broker_addr
+ if config._host is None: config._host="localhost:5672"
if opts.timeout is not None:
config._connTimeout = opts.timeout
if config._connTimeout == 0:
@@ -313,7 +317,9 @@ def OptionsAndArguments(argv):
if opts.ssl_certificate:
conn_options['ssl_certfile'] = opts.ssl_certificate
if opts.ssl_key:
- conn_options['ssl_key'] = opts.ssl_key
+ if not opts.ssl_certificate:
+ parser.error("missing '--ssl-certificate' (required by '--ssl-key')")
+ conn_options['ssl_keyfile'] = opts.ssl_key
if opts.ha_admin:
conn_options['client_properties'] = {'qpid.ha-admin' : 1}
diff --git a/tools/src/py/qpid-ha b/tools/src/py/qpid-ha
index 5b701a1fb4..3d56f24fb8 100755
--- a/tools/src/py/qpid-ha
+++ b/tools/src/py/qpid-ha
@@ -61,7 +61,9 @@ class Command:
if opts.ssl_certificate:
conn_options['ssl_certfile'] = opts.ssl_certificate
if opts.ssl_key:
- conn_options['ssl_key'] = opts.ssl_key
+ if not opts.ssl_certificate:
+ self.op.error("missing '--ssl-certificate' (required by '--ssl-key')")
+ conn_options['ssl_keyfile'] = opts.ssl_key
conn_options['client_properties'] = {'qpid.ha-admin' : 1}
connection = Connection.establish(opts.broker, **conn_options)
@@ -86,8 +88,13 @@ class StatusCmd(Command):
Command.__init__(self, "status", "Print HA status")
self.op.add_option(
"--expect", type="string", metavar="<status>",
- help="Don't print status but return 0 if it matches <status>, 1 otherwise")
+ help="Don't print status. Return 0 if it matches <status>, 1 otherwise")
+ self.op.add_option(
+ "--is-primary", action="store_true", default=False,
+ help="Don't print status. Return 0 if the broker is primary, 1 otherwise")
def do_execute(self, qmf_broker, ha_broker, opts, args):
+ if opts.is_primary:
+ if not ha_broker.status in ["active", "recovering"]: raise ExitStatus(1)
if opts.expect:
if opts.expect != ha_broker.status: raise ExitStatus(1)
else:
diff --git a/tools/src/py/qpid-printevents b/tools/src/py/qpid-printevents
index 0d0f1a0782..71b5854f03 100755
--- a/tools/src/py/qpid-printevents
+++ b/tools/src/py/qpid-printevents
@@ -72,7 +72,7 @@ class EventReceiver(Thread):
isOpen = False
while self.running:
try:
- conn = Connection.establish(self.url, **options)
+ conn = Connection.establish(self.url, **self.options)
isOpen = True
self.printer.pr(strftime("%c", gmtime(time())) + " NOTIC qpid-printevents:brokerConnected broker=%s" % self.url)
@@ -150,7 +150,9 @@ def main(argv=None):
if options.ssl_certificate:
conn_options['ssl_certfile'] = options.ssl_certificate
if options.ssl_key:
- conn_options['ssl_key'] = options.ssl_key
+ if not options.ssl_certificate:
+ p.error("missing '--ssl-certificate' (required by '--ssl-key')")
+ conn_options['ssl_keyfile'] = options.ssl_key
if options.ha_admin:
props['qpid.ha-admin'] = 1
if options.heartbeats:
diff --git a/tools/src/py/qpid-queue-stats b/tools/src/py/qpid-queue-stats
index f68609aed8..5c5f60a816 100755
--- a/tools/src/py/qpid-queue-stats
+++ b/tools/src/py/qpid-queue-stats
@@ -127,6 +127,7 @@ def main(argv=None):
p.add_option('--filter','-f' ,default=None ,help='a list of comma separated queue names (regex are accepted) to show')
p.add_option("--sasl-mechanism", action="store", type="string", metavar="<mech>", help="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.")
p.add_option("--ssl-certificate", action="store", type="string", metavar="<cert>", help="Client SSL certificate (PEM Format)")
+ p.add_option("--ssl-key", action="store", type="string", metavar="<key>", help="Client SSL private key (PEM Format)")
options, arguments = p.parse_args(args=argv)
@@ -135,6 +136,10 @@ def main(argv=None):
conn_options['mechanisms'] = options.sasl_mechanism
if options.ssl_certificate:
conn_options['ssl_certfile'] = options.ssl_certificate
+ if options.ssl_key:
+ if not options.ssl_certificate:
+ p.error("missing '--ssl-certificate' (required by '--ssl-key')")
+ conn_options['ssl_keyfile'] = options.ssl_key
host = options.broker_address
filter = []
diff --git a/tools/src/py/qpid-route b/tools/src/py/qpid-route
index 00c7c59189..7cf52e0a67 100755
--- a/tools/src/py/qpid-route
+++ b/tools/src/py/qpid-route
@@ -97,6 +97,7 @@ def OptionsAndArguments(argv):
parser.add_option("--client-sasl-mechanism", action="store", type="string", metavar="<mech>", help="SASL mechanism for authentication (e.g. EXTERNAL, ANONYMOUS, PLAIN, CRAM-MD, DIGEST-MD5, GSSAPI). Used when the client connects to the destination broker (not for authentication between the source and destination brokers - that is specified using the [mechanisms] argument to 'add route'). SASL automatically picks the most secure available mechanism - use this option to override.")
parser.add_option("--ssl-certificate", action="store", type="string", metavar="<cert>", help="Client SSL certificate (PEM Format)")
+ parser.add_option("--ssl-key", action="store", type="string", metavar="<key>", help="Client SSL private key (PEM Format)")
parser.add_option("--ha-admin", action="store_true", help="Allow connection to a HA backup broker.")
opts, encArgs = parser.parse_args(args=argv)
@@ -141,6 +142,11 @@ def OptionsAndArguments(argv):
if opts.ssl_certificate:
config._conn_options['ssl_certfile'] = opts.ssl_certificate
+ if opts.ssl_key:
+ if not opts.ssl_certificate:
+ parser.error("missing '--ssl-certificate' (required by '--ssl-key')")
+ config._conn_options['ssl_keyfile'] = opts.ssl_key
+
return args
diff --git a/tools/src/py/qpid-stat b/tools/src/py/qpid-stat
index 458ae36182..00227a98b9 100755
--- a/tools/src/py/qpid-stat
+++ b/tools/src/py/qpid-stat
@@ -108,7 +108,9 @@ def OptionsAndArguments(argv):
if opts.ssl_certificate:
conn_options['ssl_certfile'] = opts.ssl_certificate
if opts.ssl_key:
- conn_options['ssl_key'] = opts.ssl_key
+ if not opts.ssl_certificate:
+ parser.error("missing '--ssl-certificate' (required by '--ssl-key')")
+ conn_options['ssl_keyfile'] = opts.ssl_key
if opts.ha_admin:
conn_options['client_properties'] = {'qpid.ha-admin' : 1}
@@ -156,7 +158,7 @@ class BrokerManager:
shutting down.
"""
try:
- connection.close()
+ self.connection.close()
except:
pass
@@ -200,17 +202,21 @@ class BrokerManager:
disp = Display(prefix=" ")
heads = []
heads.append(Header('uptime', Header.DURATION))
+ heads.append(Header('cluster', Header.NONE))
heads.append(Header('connections', Header.COMMAS))
heads.append(Header('sessions', Header.COMMAS))
heads.append(Header('exchanges', Header.COMMAS))
heads.append(Header('queues', Header.COMMAS))
rows = []
broker = self.broker.getBroker()
+ cluster = self.broker.getCluster()
+ clusterInfo = cluster and cluster.clusterName + "<" + cluster.status + ">" or "<standalone>"
connections = self.getConnectionMap()
sessions = self.getSessionMap()
exchanges = self.getExchangeMap()
queues = self.getQueueMap()
row = (broker.getUpdateTime() - broker.getCreateTime(),
+ clusterInfo,
len(connections), len(sessions),
len(exchanges), len(queues))
rows.append(row)
diff --git a/wcf/samples/Channel/HelloWorld/HelloWorld.cs b/wcf/samples/Channel/HelloWorld/HelloWorld.cs
index 0845e42c8a..88cb11038d 100644
--- a/wcf/samples/Channel/HelloWorld/HelloWorld.cs
+++ b/wcf/samples/Channel/HelloWorld/HelloWorld.cs
@@ -113,6 +113,7 @@ namespace Apache.Qpid.Samples.Channel.HelloWorld
byte[] binaryContent = Encoding.UTF8.GetBytes("Hello world!");
writer.WriteStartElement("Binary");
writer.WriteBase64(binaryContent, 0, binaryContent.Length);
+ writer.WriteEndElement();
}
}
}